Does anyone have a routine (COBOL preferable) that converts a standard text
field into its HEX values?
For example, if I have a field 'BEFORE,' I want to be able to translate it
to
CCCDDC
256695
or to C2C5C6D6D9C5.
My ultimate goal is the first choice (vertical format), but I can deal with
either. I will code this in my COBOL program, so that is why COBOL...I can
do it in other places easily, but I am trying to create a model program that
is self contained.
Thanks in advance!
* Don *
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to list...@bama.ua.edu with the message: GET IBM-MAIN INFO
Search the archives at http://bama.ua.edu/archives/ibm-main.html
I found two examples for your enjoyment (o;
http://searchdatacenter.techtarget.com/tip/0,289483,sid%2010_gci757615,00.html
http://www.simotime.com/simhex01.htm
Cheers,
Alan
01 WK-NDX PIC S9(04) COMP.
01 WK-ZONE PIC S9(04) COMP.
01 WK-DIGIT PIC S9(04) COMP.
01 TEXT-LENGTH PIC S9(04) COMP.
01 TEXT-FIELD.
05 TEXT-CHAR PIC X(01)
OCCURS DEPENDING ON TEXT-LENGTH.
01 TEXT-CONVERTER.
05 FILLER PIC X(01) VALUE LOW-VALUES.
05 TEXT-TO-CNVT PIC X(01).
01 NUMERIC-TEXT REDEFINES TEXT-CONVERTER
PIC S9(04) COMP.
01 CONVERTED-TEXT.
05 CONVERTED-CHARS
OCCURS TEXT-LENGTH TIMES.
10 CONVERTED-ZONE PIC X(01).
10 CONVERTED-DIGIT PIC X(01).
01 HEX-CHARACTERS PIC X(16) VALUE '0123456789ABCDEF'.
01 HEX-CHARS REDEFINES HEX-CHARACTERS.
05 HEX-CHAR OCCURS 16 TIMES
PIC X(01).
MOVE 6 TO TEXT-LENGTH.
MOVE 'BEFORE' TO TEXT-FIELD.
MOVE 1 TO WK-NDX.
PERFORM CONVERT-TEXT 5 TIMES.
CONVERT-TEXT.
MOVE TEXT-CHAR (WK-NDX)
TO TEXT-TO-CNVT.
DIVIDE NUMERIC-TEXT BY 16
GIVING WK-ZONE
REMAINDER WK-DIGIT.
MOVE HEX-CHAR(WK-ZONE)
TO CONVERTED-ZONE (WK-NDX).
MOVE HEX-CHAR(WK-DIGIT)
TO CONVERTED-DIGIT (WK-NDX).
CONVERT-TEXT-END.
MOVE CONVERTED-TEXT
TO anywhere-you want-to-move-it.
Does this work for you?
Chuck
Charles Hardee
CA technologies
Sr Sustaining Engineer
Tel: +1-952-838-1039
Charles...@ca.com
-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-...@bama.ua.edu] On Behalf Of Donald Johnson
Sent: Wednesday, June 09, 2010 3:37 PM
To: IBM-...@bama.ua.edu
Subject: Cobol routine to convert TEXT to displayable HEX
*******01 HEXNUM PIC X(04) VALUE X'0000CA84'.
*******01 HEXNUM PIC X(04) VALUE Z'ABC'.
01 HEXNUM PIC X(04) VALUE z'abc'.
01 DECNUM REDEFINES HEXNUM PIC S9(8) COMP.
01 HEXVAL PIC X(08).
01 HEXSTR PIC X(16) VALUE '0123456789ABCDEF'.
01 DEC PIC S9(04) COMP.
01 FILLER REDEFINES DEC.
05 FILLER PIC X.
05 DECBYTE PIC X.
01 I PIC S9(8) COMP.
01 J PIC S9(8) COMP.
01 Q PIC S9(8) COMP.
01 R PIC S9(8) COMP.
01 J1 PIC S9(8) COMP.
01 Q1 PIC S9(8) COMP.
01 R1 PIC S9(8) COMP.
/
PROCEDURE DIVISION.
0000-MAIN-ROUTINE.
DISPLAY 'Hex ' HEXNUM.
DISPLAY 'Dec ' DECNUM.
PERFORM 0100-CONVERT.
DISPLAY 'Printable ' HEXVAL.
DISPLAY ' '.
DISPLAY HEXVAL(1:1) HEXVAL(3:1) HEXVAL(5:1) HEXVAL(7:1).
DISPLAY HEXVAL(2:1) HEXVAL(4:1) HEXVAL(6:1) HEXVAL(8:1).
GOBACK.
/
0100-CONVERT.
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 4
COMPUTE J = 2 * I - 1
MOVE HEXNUM(I:1) TO DECBYTE
DIVIDE DEC BY 16 GIVING Q REMAINDER R
COMPUTE J1 = J + 1
COMPUTE Q1 = Q + 1
COMPUTE R1 = R + 1
MOVE HEXSTR(Q1:1) TO HEXVAL(J:1)
MOVE HEXSTR(R1:1) TO HEXVAL(J1:1)
END-PERFORM.
"Donald Johnson" <dej...@GMAIL.COM> wrote in message
news:AANLkTim2-2yXPstDNZjwy...@mail.gmail.com...
http://www.thenightland.co.uk/MYWEB/mvsxmitmail.html
Ddownload it, and look for
~~~~~~~~~~~~ Andy Robertson telephone mobile 0777 214 9545 home 01308 420797
-----IBM Mainframe Discussion List <IBM-...@bama.ua.edu> wrote: -----
To: IBM-...@bama.ua.edu
From: Donald Johnson <dej...@GMAIL.COM>
Sent by: IBM Mainframe Discussion List <IBM-...@bama.ua.edu>
Date: 06/09/2010 09:36PM
Subject: Cobol routine to convert TEXT to displayable HEX
Hi guys and gals!
or to C2C5C6D6D9C5.
**********************************************************************
This email is confidential and may contain copyright material of the John Lewis Partnership.
If you are not the intended recipient, please notify us immediately and delete all copies of this message.
(Please note that it is your responsibility to scan this message for viruses). Email to and from the
John Lewis Partnership is automatically monitored for operational and lawful business reasons.
**********************************************************************
John Lewis plc
Registered in England 233462
Registered office 171 Victoria Street London SW1E 5NN
Websites: http://www.johnlewis.com
http://www.waitrose.com
http://www.greenbee.com
http://www.johnlewispartnership.co.uk
**********************************************************************
> From: Donald Johnson <dej...@GMAIL.COM <http://gmail.com/>>
Here is the code snippet (working-storage section fields (other than the
input text), and the Procedure statements:
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -7-+
* CONVERT TEXT TO HEX WORK FIELDS
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -7-+
05 WS-TXT-SUB PIC S9(04) VALUE ZERO COMP.
05 WS-ZON-SUB PIC S9(04) VALUE ZERO COMP.
05 WS-DIG-SUB PIC S9(04) VALUE ZERO COMP.
05 WS-CONV-BYTE-NUM.
10 FILLER PIC X(01) VALUE LOW-VALUES.
10 WS-CONV-BYTE PIC X(01).
05 WS-CONV-NUM REDEFINES WS-CONV-BYTE-NUM
PIC 9(04) COMP.
05 WS-CONV-ZONE PIC X(100) VALUE SPACE.
05 WS-CONV-DIGT PIC X(100) VALUE SPACE.
05 WS-HEX-CHARS PIC X(16) VALUE '0123456789ABCDEF'.
05 FILLER REDEFINES WS-HEX-CHARS.
10 WS-X PIC X(01) OCCURS 16 TIMES.
* CONVERT TEXT TO HEX FROM DETAIL LINE DATA
INITIALIZE WS-CONV-ZONES
WS-CONV-DIGTS
PERFORM VARYING WS-TXT-SUB FROM 1 BY 1
UNTIL WS-TXT-SUB GREATER 100
MOVE <<SOURCE FIELD>> (WS-TXT-SUB : 1) TO WS-CONV-BYTE
COMPUTE WS-DIVIDE-RESULT = WS-CONV-NUM / 16
COMPUTE WS-REMAINDER = WS-REMAINDER * 16
COMPUTE WS-ZON-SUB = WS-QUOTIENT
COMPUTE WS-DIG-SUB =
WS-REMAINDER
MOVE WS-X(WS-ZON-SUB + 1) TO WS-CONV-ZONE(WS-TXT-SUB:1)
MOVE WS-X(WS-DIG-SUB + 1) TO WS-CONV-DIGT(WS-TXT-SUB:1)
END-PERFORM.
An alternate to the four COMPUTE statements is:
COMPUTE WS-ZON-SUB =
FUNCTION INTEGER-PART (WS-CONV-NUM / 16)
COMPUTE WS-DIG-SUB =
FUNCTION REM (WS-CONV-NUM 16)
Howvever, multiple runs of a test program running between 100,000 and
1,000,000 iterations of a process to convert all 256 possibilities showed
the FUNCTION calls took between 25 and 30% more TCB time, while they used
virtually the same amount of memory.
I hope others can benefit from this and can use this process.
Thanks to all for your help!
DCL STR CHAR(13);
DCL HEXV CHAR(99)VAR;
DCL # BIN(31)FIXED;
STR = 'IBM MAIN LIST'; PUT SKIP DATA(STR);
HEXV = HEX2(STR); /* top line concatenated left of bottom line */
# = LENGTH(HEXV)/2; /* always even */
PUT SKIP LIST(SUBSTR(HEXV,1,#)); /* upper */
PUT SKIP LIST(SUBSTR(HEXV,#+1)); /* lower */
HEX2: /* display hex in double-line (dump) format */
PROCEDURE(STR@) RETURNS(CHAR(99)VAR); /* 99? */
DCL STR@ CHAR(*) NONASGN;
DCL(ADDR,*HEXIMAGE*,LENGTH,STRING)BUILTIN;
DCL HEXIMAGE_STR CHAR(LENGTH(STR@)*2)
,1 HEX_STR(LENGTH(STR@)) DEFINED(HEXIMAGE_STR)
,2 HEX_STR1 CHAR(1)
,2 HEX_STR2 CHAR(1);
HEXIMAGE_STR = *HEXIMAGE*(ADDR(STR@),LENGTH(STR@));
RETURN(STRING(HEX_STR(*).HEX_STR1)|| /* must split afterwards */
STRING(HEX_STR(*).HEX_STR2));
END HEX2;
Result:
STR='IBM MAIN LIST';
CCD4DCCD4DCEE
9240419503923
Walter Rue