View previous topic :: View next topic |
Author |
Message |
deepeshk79 Beginner
Joined: 20 Jun 2003 Posts: 112 Topics: 48 Location: Bangalore
|
Posted: Wed Jul 21, 2004 11:04 am Post subject: Hexadecimal format for an alphanumeric field |
|
|
Hi All,
I was trying to get the hexadecimal format of an alphanumeric field.
For eg, the hexadecimal format of
XCPTWD05
is
=========
ECDEECFF
73736405
========
as seen from a file (with hex as TSO command).
Now i need to get the hex value of XCPTWD05 in a variable X(16)..ie as
'E7C3D7E3E6C4F0F5'.
Any suggestion how this can be achieved in Cobol.
Thanks,
Deepesh |
|
Back to top |
|
|
ofer71 Intermediate
Joined: 12 Feb 2003 Posts: 358 Topics: 4 Location: Israel
|
Posted: Wed Jul 21, 2004 12:05 pm Post subject: |
|
|
Hi
Found the following code in Google Groups:
Code: | PROGRAM-ID. CHAR-TO-HEX.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 NUM PIC 999 COMP.
01 HIGH PIC 99 COMP.
01 LOW PIC 99 COMP.
01 HEX-DIGITS PIC X(16) VALUE "0123456789ABCDEF".
LINKAGE SECTION.
01 CHAR PIC X.
01 HEX PIC XX.
PROCEDURE DIVISION USING CHAR, HEX.
BEGIN.
COMPUTE NUM = FUNCTION ORD (CHAR), SUBTRACT 1 FROM NUM
DIVIDE NUM BY 16 GIVING HIGH REMAINDER LOW
ADD 1 TO HIGH, LOW
MOVE HEX-DIGITS (HIGH:1) TO HEX (1:1)
MOVE HEX-DIGITS (LOW:1) TO HEX (2:1)
EXIT PROGRAM.
END PROGRAM CHAR-TO-HEX.
|
By the way - the HEX command is an ISPF editor command.
O.
________
ultimate fighters
Last edited by ofer71 on Sat Feb 05, 2011 11:18 am; edited 1 time in total |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Wed Jul 21, 2004 12:31 pm Post subject: |
|
|
Deepesh,
Apart from Cobol example shown by ofer, there are many ways to do get the hex representation of character data.You can use utilities like IDCAMS, SORT to print the data in hex.
Code: |
//STEP0100 EXEC PGM=SORT
//SORTIN DD *
XCPTWD05
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(1,8,HEX)
/*
|
Code: |
//STEP0200 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//FILE1 DD *
XCPTWD05
//SYSIN DD *
PRINT INFILE(FILE1) HEX
/*
|
Ofer : Is there any special reason that you choose the conversion to be done in a subroutine?
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
ofer71 Intermediate
Joined: 12 Feb 2003 Posts: 358 Topics: 4 Location: Israel
|
Posted: Wed Jul 21, 2004 12:34 pm Post subject: |
|
|
Kolusu -
No, there is no special reason. I just copied the code from Google.
And what about REXX ?
O.
________
Fetish Video
Last edited by ofer71 on Thu Mar 17, 2011 10:39 am; edited 1 time in total |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Wed Jul 21, 2004 12:38 pm Post subject: |
|
|
Here is a simple revision of the code without calling a subroutine
Code: |
WORKING-STORAGE SECTION.
01 NUM PIC 999 COMP.
01 HIGH PIC 99 COMP.
01 LOW PIC 99 COMP.
01 HEX-DIGITS PIC X(16) VALUE '0123456789ABCDEF'.
01 CHAR PIC X.
01 HEX PIC XX.
01 W-INP-STRING PIC X(08) VALUE 'XCPTWD05'.
01 W-HEX-STRING PIC X(16).
01 W-SUB1 PIC S9(04) COMP.
01 W-SUB2 PIC S9(04) COMP VALUE 1.
PROCEDURE DIVISION.
PERFORM VARYING W-SUB1 FROM 1 BY 1 UNTIL W-SUB1 > 8
COMPUTE NUM = FUNCTION ORD
(W-INP-STRING(W-SUB1: 1))
SUBTRACT 1 FROM NUM
DIVIDE NUM BY 16 GIVING HIGH REMAINDER LOW
ADD 1 TO HIGH, LOW
MOVE HEX-DIGITS (HIGH:1) TO HEX (1:1)
MOVE HEX-DIGITS (LOW:1) TO HEX (2:1)
MOVE HEX TO W-HEX-STRING(W-SUB2 : 2)
ADD +2 TO W-SUB2
END-PERFORM
DISPLAY W-HEX-STRING
GOBACK.
|
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Wed Jul 21, 2004 3:46 pm Post subject: |
|
|
Hi Kolusu,
I'm surprised, no, **AMAZED**, that you didn't reply:
"Please search before posting. This topic has been discussed earlier. check this link"
http://www.mvsforums.com/helpboards/viewtopic.php?t=2564
Couldn't resist.
Regards, Jack. |
|
Back to top |
|
|
deepeshk79 Beginner
Joined: 20 Jun 2003 Posts: 112 Topics: 48 Location: Bangalore
|
Posted: Thu Jul 22, 2004 7:54 am Post subject: |
|
|
Hi All,
Thanks for your replies. All the codes worked fine.
Deepesh |
|
Back to top |
|
|
|
|