View previous topic :: View next topic
|
Author |
Message |
aji.rao
New User
Joined: 19 Jun 2007 Posts: 4 Location: UK
|
|
|
|
Hi All,
I have searched the forum for a similar requirement, however was unable to spot one which could guide me with mine.
My requirement is that I have a 32 byte alphanumeric string (X(32) say value is 820D89D5F44ADEBB82ED78EAF77D198B) which I would like to convert to Hex as X(16) with value X'820D89D5F44ADEBB82ED78EAF77D198B'.
Please help/guide me as to how I can do this using COBOL or direct me to a link which will provide some clue on such a conversion.
Thanking in advance, |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You can try this as a starting point.
A simple search in the forum will provide other possibilities as well. |
|
Back to top |
|
|
aji.rao
New User
Joined: 19 Jun 2007 Posts: 4 Location: UK
|
|
|
|
Thanks Bill. I shall check the post linked by you and also re-check the forum again for similar posts.
Appreciate the quick response. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
Back to top |
|
|
aji.rao
New User
Joined: 19 Jun 2007 Posts: 4 Location: UK
|
|
|
|
Many Thanks to both of you in taking time to respond back.
I defintely took cue from the link and wrote the below logic as a PD copybook as my installation is not allowing me to compile the code with "Extend" option:
Working Storage:
Code: |
03 WS-INPUT-VAR-1 PIC X(32) VALUE
'820D89D5F44ADEBB82ED78EAF77D198B'.
03 WS-INPUT-VAR PIC X(34).
03 WS-INPUT-VAR-R REDEFINES WS-INPUT-VAR.
05 WS-INPUT-VAR-R-1 PIC X(17).
05 WS-INPUT-VAR-R-2 PIC X(17).
03 WS-OUT-VAL.
05 WS-OUT-VAL-1 PIC S9(17) COMP-3.
05 WS-OUT-VAL-2 PIC S9(17) COMP-3.
03 WS-OUT-VAL-FINAL PIC X(16). |
Procedure Division:
Code: |
MOVE WS-INPUT-VAR-1 (1:16) TO WS-INPUT-VAR (1:16)
MOVE ZEROS TO WS-INPUT-VAR (17:1)
MOVE WS-INPUT-VAR-1 (17:16) TO WS-INPUT-VAR (18:16)
MOVE ZEROS TO WS-INPUT-VAR (34:1)
INSPECT WS-INPUT-VAR CONVERTING 'ABCDEF'
TO X'FAFBFCFDFEFF'
MOVE WS-INPUT-VAR-R-1 TO WS-OUT-VAL-1
MOVE WS-INPUT-VAR-R-2 TO WS-OUT-VAL-2
MOVE WS-OUT-VAL (1:8) TO WS-OUT-VAL-FINAL (1:8)
MOVE WS-OUT-VAL (10:8) TO WS-OUT-VAL-FINAL (9:8) |
This is tested and works fine.
Code'd |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
All NUMERIC fields must be defined as UNSIGNED. Change your packed-decimal picture's from S9(17) to 9(16)V9 and your Display-Numeric to 9(16)V9. The compiler does some funny stuff with packed-signed, such as ZAPPING itself to ensure a valid sign-nibble and when you have a packed-decimal field that contains non packed-decimal data, a S0C7 will be raised after a ZAP.
When the compiler deals with UNSIGNED, with one explicit decimal position (V9), the ZAPPING is eliminated and so is the potential of a S0C7.
I would encourage you to use the exact field definitions and logic in CHAR2HEX as this sub-program has worked without a hitch for the last 25+ years since I wrote it as well as it was amended for ARITH(EXTEND) with the introduction of OS/390 COBOL 2.2, some 15 years ago.;
As far as not being able to use the EXTEND option, then use CHAR2HEX as a Called Sub-Program, changing the numeric definitions from PIC 9(30)V9 to PIC 9(16)V9. Then, you'll be able to convert up to 16-Bytes Display to 8-Bytes Packed for each Call. |
|
Back to top |
|
|
aji.rao
New User
Joined: 19 Jun 2007 Posts: 4 Location: UK
|
|
|
|
Thanks Bill, I will try and make use of the sub routine with a shorter picture clause and pad the outputs for my requirement.
Thanks for your help, much appreciated. |
|
Back to top |
|
|
|