IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Convert Hex String to its Hex Value


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
aji.rao

New User


Joined: 19 Jun 2007
Posts: 4
Location: UK

PostPosted: Wed Apr 16, 2014 12:04 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Apr 16, 2014 12:15 pm
Reply with quote

You can try this as a starting point.

A simple search in the forum will provide other possibilities as well.
Back to top
View user's profile Send private message
aji.rao

New User


Joined: 19 Jun 2007
Posts: 4
Location: UK

PostPosted: Wed Apr 16, 2014 12:25 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Apr 16, 2014 4:42 pm
Reply with quote

Click on link below. I think this will do the trick -

www.ibmmainframes.com/viewtopic.php?p=319828&highlight=#319828

The sub-program is re-entrant and can be used in both a Batch and CICS environment.

HTH....
Back to top
View user's profile Send private message
aji.rao

New User


Joined: 19 Jun 2007
Posts: 4
Location: UK

PostPosted: Wed Apr 16, 2014 4:55 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Apr 16, 2014 5:32 pm
Reply with quote

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
View user's profile Send private message
aji.rao

New User


Joined: 19 Jun 2007
Posts: 4
Location: UK

PostPosted: Thu Apr 17, 2014 7:39 am
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
Search our Forums:

Back to Top