Home The Company Publications Products Links Tips

Tips, Tricks, and Techniques

Last update: 30 April 2004

Hexadecimal

Question

Is there a Natural statement that will convert the hex representation of a string to the string itself? In the program below, I tried the reverse of line 70 but got a "NAT0320 Edit mask permitted for output elements only", i.e., 0070 MOVE EDITED #EDITED TO #DB-FIELD(EM=H(10)).
0010 DEFINE DATA LOCAL
0020 1 #DB-FIELD (A10)
0030 1 #EDITED   (A20)
0040 END-DEFINE
0050 *
0060 #DB-FIELD := 'AB'
0070 MOVE EDITED #DB-FIELD(EM=H(10)) TO #EDITED
0080 DISPLAY #DB-FIELD #EDITED
0090 *
0100 *
0110 MOVE ALL '40' TO #EDITED
0120 COMPRESS 'C3C4' #EDITED TO #EDITED LEAVING NO
0130 ** ????? What command should I issue at this point  ?????
0140 ** ????? to get a "CD" for #DB-FIELD?               ?????
0150 DISPLAY #DB-FIELD #EDITED
0160 *
0170 END

+ + + + + + + 

MORE                                                            Page      1

#DB-FIELD        #EDITED
---------- --------------------

AB         C1C24040404040404040
AB         C3C44040404040404040

+ + + + + + +
 
DEFINE DATA LOCAL
1 #ALPHA(A5) INIT<'ABCDE'>
1 REDEFINE #ALPHA
  2 #BINARY (B5)
1 #ALPHA2 (A10)
1 #LONG-B (B10)
1 REDEFINE #LONG-B
  2 #LONG-A (A10)
1 #ALPHA3 (A10)
END-DEFINE
MOVE EDITED #BINARY (EM=HHHHH) TO #ALPHA2
MOVE #BINARY TO #LONG-B
MOVE LEFT JUSTIFIED #LONG-A TO #ALPHA3
DISPLAY #ALPHA #BINARY #ALPHA2 #LONG-A #LONG-B #ALPHA3
END

+ + + + + 

Page      1                                                  97-09-24

#ALPHA  #BINARY    #ALPHA2    #LONG-A         #LONG-B         #ALPHA3
------ ---------- ---------- ---------- -------------------- ----------

ABCDE  C1C2C3C4C5 C1C2C3C4C5      ABCDE 0000000000C1C2C3C4C5 ABCDE

Thanks a lot to those who responded. Great list! Theuns' reply answered the question. My tentative solution to the problem was a very long decide on first statement wherein there's a translation between hex represention and the value itself but there's SAG-L! brute force solution:
DEFINE DATA LOCAL
  1 #DB-FIELD (A10)
  1 REDEFINE #DB-FIELD
    2 #DB     (A1/10)
  1 #EDITED   (A20)
  1 REDEFINE #EDITED
    2 #ED     (A2/10)
  1 #CTR      (I1)
END-DEFINE
*
*  to be inserted in the original program
*
FOR #CTR 1 10
  DECIDE ON FIRST #ED(#CTR)
    VALUE '00'  #DB(#CTR) := H'00'
*     etc., etc.,
*     etc., etc.
    VALUE 'FF'  #DB(#CTR) := H'FF'
    NONE  IGNORE
  END-DECIDE
END-FOR

Here's the "solved" program:
0010 DEFINE DATA LOCAL
0020   1 #DB-FIELD      (A10)
0030   1 REDEFINE #DB-FIELD
0040     2 #DB-FIELD-B5 (B10)
0050   1 #EDITED        (A20)
0060 END-DEFINE
0070 *
0080 #DB-FIELD := 'AB'
0090 MOVE EDITED #DB-FIELD(EM=H(10)) TO #EDITED
0100 DISPLAY #DB-FIELD #EDITED
0110 *
0120 *
0130 MOVE ALL '40' TO #EDITED
0140 COMPRESS 'C3C4' #EDITED TO #EDITED LEAVING NO
0150 MOVE EDITED #EDITED TO #DB-FIELD-B5(EM=H(10))
0160 DISPLAY #DB-FIELD #EDITED
0170 *
0180 END

MORE
Page      1                                         09/25/97  10:36:35

#DB-FIELD        #EDITED
---------- --------------------

AB         C1C24040404040404040
CD         C3C44040404040404040
-------------


+ + + + +

Solution

I must be missing the point of this request. I saw all the responses and I cannot understand exactly what is at stake for you. You don't need 'MOVED EDITED' or anythnig complicated. I thought PATRICK ONEILL asnwered it corectly, although not with any explanation. Remember that all data is binary by nature, all you have to do is ask the computer to give to you in the format you want. So for alphanumeric/binary: *
DEFINE DATA LOCAL
1 #A-FLD (A80)
1 REDEFINE #A-FLD
  2 #B-FLD (B80)
END-DEFINE
*
FORMAT LS=180
MOVE H'C3C4' TO #B-FLD
WRITE '=' #A-FLD '=' #B-FLD
END
Output:
Page      1

#A-FLD: CD

C3C440404040404040404040404040404040404040404040404040404040404040404040404040.....
*
Likewise, vice-versa:
DEFINE DATA LOCAL
1 #A-FLD (A80)
1 REDEFINE #A-FLD
  2 #B-FLD (B80)
END-DEFINE
*
FORMAT LS=180
MOVE 'CD' TO #A-FLD
WRITE '=' #A-FLD '=' #B-FLD
END
Output:
Page      1

#A-FLD: CD

C3C440404040404040404040404040404040404040404040404040404040404040404040404040.....
So what am I missing in the question? INquring minds like to know..
Jim Wisdom, Boston University

-----
Jim,
If you could validate a B80 field so that it could contain only hexadecimal strings then I would accept your solution. For example:
  1. your database field of, say, A50 contains printer escape sequences.
  2. you want to modify these escape sequences because the printer went down and has to be replaced or the printer has to be upgraded, etc. you cannot enter/update non-printable characters in the A50 database field; you can only enter/update hex strings (C1C24040, etc.) in a A100 user-defined field.
  3. in your update program, you have a redefine to the A50 database field which is a B50 user-defined field.
  4. someone would have to change the escape sequences which means there must be some sort of validation on the B50 field. (or you could do a MOVE EDITED on the B50 to an A100 user-defined field and do your validation there!).

Leo Isip
lisip@state.de.us
-----
My second response:
I seem to begin having a feeling you think there is a difference between an A50 field and a B50 field. They are the same length, you just need twice the number of display characters when you visualize a binary field. You said: "If you could validate a B80 field so that it could contain only hexadecimal strings then I would accept your solution..". Natural does this for you. If you try to enter non-hex nybbles into a binary field, it will give you an NAT1102, which you can allow to display or trap with ON ERROR.
* Here's another idea based on items 2 - 4 you wrote above - why not create a table of printers, types, locales and sequences and allow the user not to type in sequences which they could easily get wrong, but choose a printer based on info they recognize (name, make, location, etc.) and have someone who knows the printer(s) create and maintain the table with accurate binary sequences. Just a thought.
DEFINE DATA LOCAL
1 #A-FIELD (A20)
1 REDEFINE #A-FIELD
  2 #B-FIELD (B20)
END-DEFINE
*
#A-FIELD := H'4D3C8F' /* A MADE UP ORIGINAL HEX SEQUENCE
/* ORIGINAL SOURCE MAY BE AN ADABAS FIELD!
/* YOU NEXT WISH TO REPLACE IT WITH A HEX SEQUENCE '4BD36C'
INPUT 'ORIGINAL FIELD VALUE:'  #A-FIELD (AD=O)
/     'ORIGINAL HEX SEQUENCE:' #B-FIELD (AD=O)
/     'TYPE IN NEW HEX SEQUENCE:' #B-FIELD (AD=M)
WRITE '=' #A-FIELD / '=' #B-FIELD
/* YOU CAN STORE THE MODIFIED VALUE IF YOU LIKE, SEND DOWN A NEW
/* TEMPORARILY AND NOT STORE IT, WHATEVER.
END
I hope some of this helps. If I have misunderstood your question, my apologies.
Jim Wisdom, Boston University

Top Page


Back to NATURAL Tips, Tricks, Techniques -- Overview