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

How to convert char to hex


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

New User


Joined: 23 Oct 2015
Posts: 12
Location: canada

PostPosted: Mon Oct 26, 2015 10:50 pm
Reply with quote

Hi How to convert char to hex

my requirement
example
Input
Pic x(10) value '99999' (Leading spaces)

Output in Hex leading spaces to be converted to X'AA'

AAAA99
AAA999

I can move it to a packed and remove the sign nibble, but how to handle the leading spaces as AAAAA?
Thanks,
krrp
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Oct 26, 2015 11:00 pm
Reply with quote

I think you need to explain a LOT more before you start getting answers that make sense. Questions that popped up as I was reading your post:
1. PIC X(10) VALUE '99999' will have trailing spaces -- not leading spaces. How do you get leading spaces into it?
2. PIC X(10) VALUE '99999' will not have a hex value of 99 or 999 -- the precise hex value will be F9F9F9F9F94040404040. So why the incorrect hex data?
3. Your variable is 10 bytes but your examples only have 6 (or 3 if those are supposed to be hex characters) bytes -- why?
4. You mention moving the data to "a packed" (presumably a packed decimal variable but who knows the way you wrote your post?) -- what does packed decimal have to do with anything?
5. If you are wanting a packed decimal variable at some point, X'AA' is not valid packed decimal data so you're going to have problems. How are you going to deal with them?
6. Why not use reference modification (or a REDEFINES of the 10-byte PIC X variable into 10 1-byte PIC X variables) and look at each byte? If the byte is a space, change it -- otherwise, stop the loop.
Back to top
View user's profile Send private message
krrp

New User


Joined: 23 Oct 2015
Posts: 12
Location: canada

PostPosted: Mon Oct 26, 2015 11:44 pm
Reply with quote

Okay Robert...please see my requirement...I need the leading spaces as AA when converted to hex.
Code:

******************************************************* Top of Data **
INPUT                                                                 
01 WS-FLD1 PIC X(10).                                                 
01 WS-FLD2 PIC X(08).                                                 
                                                                     
OUTPUT                                                               
01 WS-OUT1 PIC X(05).                                                 
01 WS-OUT2 PIC X(04).                                                 
                                                                     
INPUT FILE                                                           
----+----1----+----2----+----3----+----4----+----5----+----6----+----7
     2345612345678                                                   
                                                                     
OUTPUT FILE (HEX FORMAT)                                             
----+----1----+----2----+----3----+----4----+----5----+----6----+----7
¡¡S î  îÌ                                                             
AAA3513574444444444444444444444444444444444444444444444444444444444444
AA24624680000000000000000000000000000000000000000000000000000000000000
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: Tue Oct 27, 2015 1:17 am
Reply with quote

Search the Mainframe COBOL forum for CHAR2HEX and you will find what you need.

You'll need to adapt the sample program to accommodate for a X'40' to be represented as a 4-Bit X'A'. The easiest way to do this is to issue an INSPECT CONVERTING SPACE TO 'A' and then proceed with the conversion loop.

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

New User


Joined: 23 Oct 2015
Posts: 12
Location: canada

PostPosted: Tue Oct 27, 2015 6:13 pm
Reply with quote

Wow...Thanks Bill
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 SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
No new posts Convert single row multi cols to sing... DFSORT/ICETOOL 6
Search our Forums:

Back to Top