Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Convert Hex String to its Hex Value

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Convert Hex String to its Hex Value
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Wed Apr 16, 2014 12:15 pm    Post subject: Reply to: Convert Hex String to its Hex Value
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    Post subject: Reply to: Convert Hex String to its Hex Value
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Apr 16, 2014 4:42 pm    Post subject: Reply to: Convert Hex String to its Hex Value
Reply with quote

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

http://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    Post subject: Reply to: Convert Hex String to its Hex Value
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Apr 16, 2014 5:32 pm    Post subject: Reply to: Convert Hex String to its Hex Value
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    Post subject: Reply to: Convert Hex String to its Hex Value
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts Convert +9999999999999.99 to S9(12)V9(3) vnktrrd DFSORT/ICETOOL 8 Thu Nov 17, 2016 8:15 pm
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts convert PD to ZD ram_vizag DFSORT/ICETOOL 5 Sat Nov 05, 2016 3:06 am
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us