Joined: 06 Jun 2008 Posts: 8214 Location: Dubuque, Iowa, USA
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.
Joined: 14 Jan 2008 Posts: 2504 Location: Atlanta, Georgia, USA
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.