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
 

 

How to convert char to hex

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to convert char to hex
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: 7904
Location: Bellevue, IA

PostPosted: Mon Oct 26, 2015 11:00 pm    Post subject:
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    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Tue Oct 27, 2015 1:17 am    Post subject: Reply to: Convert char to hex
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    Post subject:
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    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
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am


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