View previous topic :: View next topic |
Author |
Message |
vijay Beginner
Joined: 09 May 2003 Posts: 131 Topics: 64
|
Posted: Thu Jul 15, 2004 1:43 pm Post subject: COBOL hex value interpretation |
|
|
Hi ,
I've a field defined as x(2) and hex value is 1234 in the file.I want to convert to numeric 1234 in working storage.How can I do that?
Here is the hex dump (first 2 bytes)
..
134444444
240000000
Thanks,
Vijay |
|
Back to top |
|
|
Bithead Advanced
Joined: 03 Jan 2003 Posts: 550 Topics: 23 Location: Michigan, USA
|
Posted: Thu Jul 15, 2004 2:05 pm Post subject: |
|
|
To dump a file in hex, use the following JCL:
//DEFINE EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//FILE1 DD DSN=MY.FILE,DISP=SHR
//SYSIN DD *
PRINT INFILE(FILE1) HEX
/*
If it must be in COBOL, try this:
Code: |
01 WS-CONVERSION-FIELDS.
05 WS-CONV-CHAR.
10 WS-CONV-CHAR-A PIC X(01)
VALUE LOW-VALUES.
10 WS-CONV-CHAR-B PIC X(01) VALUE SPACE.
05 WS-HEX-VALUE REDEFINES WS-CONV-CHAR
PIC 9(04) COMP.
05 WS-HOLD-HEX-VALUE-1 PIC 9(04) COMP.
05 WS-HOLD-HEX-VALUE-2 PIC 9(04) COMP.
01 HEX-TABLE PIC X(16)
VALUE '0123456789ABCDEF'.
01 FILLER REDEFINES HEX-TABLE.
05 HEX-ENTRY PIC X(01)
OCCURS 16 TIMES.
*
* REPORT LINES
*
01 WS-DATA-LINE.
05 WS-DATA-CHAR PIC X(01)
OCCURS 100 TIMES.
01 WS-HEX-VALUE-LINE-1.
05 WS-HVL1-CHAR PIC X(01)
OCCURS 100 TIMES.
01 WS-HEX-VALUE-LINE-2.
05 WS-HVL2-CHAR PIC X(01)
OCCURS 100 TIMES.
(This is using a 100 character line)
PERFORM VARYING SUB1 FROM +1 BY +1 UNTIL SUB > +100
MOVE WS-DATA-CHAR (SUB1) TO WS-CONV-CHAR-B
WS-HOLD-HEX-VALUE-2 = WS-HEX-VALUE
- (WS-HOLD-HEX-VALUE-1 * 16)
MOVE HEX-ENTRY (WS-HOLD-HEX-VALUE-1 + 1)
TO WS-HVL1-CHAR (SUB1)
MOVE HEX-ENTRY (WS-HOLD-HEX-VALUE-2 + 1)
TO WS-HVL2-CHAR (SUB1)
END-PERFORM.
DISPLAY WS-DATA-LINE.
DISPLAY WS-HEX-VALUE-LINE-1.
DISPLAY WS-HEX-VALUE-LINE-2.
|
|
|
Back to top |
|
|
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Fri Jul 16, 2004 12:11 pm Post subject: |
|
|
You can also try something like this. You may want to change the field lengths to fit your reqs.
Regards, Jack
[code:1:f8e1fe8c2f]
05 WS-WORK-PACKED PIC 9(009) COMP-3.
05 REDEFINES WS-WORK-PACKED.
10 WS-WORK-X5.
20 WS-WORK-X1 PIC X(002).
20 WS-WORK-X2 PIC X(002).
05 REDEFINES WS-WORK-PACKED.
10 WS-WORK-BIN4 PIC 9(009) COMP.
05 WS-WORK-UNPACKED PIC 9(009).
05 REDEFINES WS-WORK-UNPACKED.
10 WS-WORK-UNPACKED-8 PIC 9(008).
05 WS-YOUR-2-BYTE-DISPLAY PIC X(004).
MOVE ZEROS TO WS-WORK-PACKED
MOVE YOUR-2-BYTES TO WS-WORK-X2
PERFORM 100-CONVERT-HEX-DATA
MOVE WS-WORK-UNPACKED-8(5:4) TO WS-YOUR-2-BYTE-DISPLAY
DISPLAY |
|
Back to top |
|
|
vijay Beginner
Joined: 09 May 2003 Posts: 131 Topics: 64
|
Posted: Wed Jul 21, 2004 7:17 am Post subject: |
|
|
Thanks Slade.Actually It works fine.
VIjay |
|
Back to top |
|
|
Meg Beginner
Joined: 08 Jul 2003 Posts: 44 Topics: 16
|
Posted: Wed Jul 28, 2004 9:19 am Post subject: |
|
|
Hi Slade,
We have also used your code in our program and it is working perfectly fine. But I am not sure what the following line in the code means. Your reply would be greatly appreciated:
Quote: |
INSPECT WS-WORK-UNPACKED CONVERTING
X"FAFBFCFDFEFF" TO "ABCDEF"
|
Thanks,
Meg |
|
Back to top |
|
|
vivek Beginner
Joined: 15 Jul 2004 Posts: 95 Topics: 11 Location: Edison,NJ
|
Posted: Wed Jul 28, 2004 9:32 am Post subject: |
|
|
Quote: |
Hi Slade,
We have also used your code in our program and it is working perfectly fine. But I am not sure what the following line in the code means. Your reply would be greatly appreciated:
|
Meg, Inspect verb will inspect a variable and can replace a string with another string. _________________ Vivek,NJ
Db2,IDMS |
|
Back to top |
|
|
Meg Beginner
Joined: 08 Jul 2003 Posts: 44 Topics: 16
|
Posted: Wed Jul 28, 2004 9:41 am Post subject: |
|
|
Hi VIjay,
Quote: |
INSPECT WS-WORK-UNPACKED CONVERTING
X"FAFBFCFDFEFF" TO "ABCDEF"
|
For e.g: WS-WORK-UNPACKED is FDFE, it should replace FDFE with DE.
But from above it looks like the entire hexa value of "FAFBFCFDFEFF" will be searched in WS-WORK-UNPACKED.
Regards,
Meg |
|
Back to top |
|
|
vivek Beginner
Joined: 15 Jul 2004 Posts: 95 Topics: 11 Location: Edison,NJ
|
Posted: Wed Jul 28, 2004 6:01 pm Post subject: |
|
|
Meg, you are right. it will look for entire string and replace it. not corresponding . You got me ? _________________ Vivek,NJ
Db2,IDMS |
|
Back to top |
|
|
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Fri Jul 30, 2004 11:17 am Post subject: |
|
|
Hi Meg,
Sorry for the delay in responding. Haven't been paying attention.
When you move a comp-3 field to a display field, it is unpacked. That is, each 4 bits in the field (nibble) is expanded to Fn, where n is the value of the 4 bits.
This works well for bit values 0-9. They yield F0 - F9. Bit values A - F, unfortunately yield FA - FF. How to convert them to C1 (A) - C7(F)?
The INSPECT does this: it replaces FA - FF (X"FAFBFCFDFEFF") with
C1 - C7 (ABCDEF).
Regards, Jack. |
|
Back to top |
|
|
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Mon Aug 02, 2004 1:36 pm Post subject: |
|
|
Hi Meg,
Please replace "The INSPECT does this: it replaces FA - FF (X"FAFBFCFDFEFF") with
C1 - C7 (ABCDEF). " with the following:
The INSPECT does this: it replaces any byte in the range FA - FF (X"FAFBFCFDFEFF") with its corresponding byte in the range C1 - C7 (ABCDEF).
Thanx, Jack. |
|
Back to top |
|
|
|
|