View previous topic :: View next topic
|
Author |
Message |
dharmaraok
New User
Joined: 10 Mar 2011 Posts: 45 Location: india
|
|
|
|
I am having a field of type X(2).
input file:
02
06
I need to convert this field into equailavent hexa decimal value.
output file
01
0A
Could you please let me know how can we achieve this.
I tried by moving X(2) to comp-3 field but it is not getting desired value. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
This will add the sign-byte to your BCD, but not use anything except the sign from the value due to the V9 part of it.
Code: |
01 W-CONVERTED-TO-PACKED COMP-3 PIC 9(4)V9 VALUE ZERO.
01 FILLER REDEFINES W-CONVERTED-TO-PACKED.
05 W-BCD-VALUE PIC XX.
05 W-SIGN-WAITING-FROM-ABOVE PIC X.
MOVE your-source-BCD TO W-BCD-VALUE
MOVE W-CONVERTED-TO-PACKED TO your-target-binary |
|
|
Back to top |
|
|
dharmaraok
New User
Joined: 10 Mar 2011 Posts: 45 Location: india
|
|
|
|
Thanks Bill,
how to declare your-target-binary field in working storage section. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Just like any other:
01 target-binary COMP (or COMP-4 or BINARY) PIC 9(4).
If you need that somewhere where only a two-byte PIC X is, then REDEFINES this as PIC XX. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Code: |
03 WS-BCD PIC X(02) VALUE X'0026'.
03 WS-HEX PIC X(02).
03 WS-PACKED-V9 PIC 9(04)V9 PACKED-DECIMAL.
03 WS-PACKED-X REDEFINES WS-PACKED-V9
PIC X(03).
03 WS-HWORD PIC 9(04) BINARY.
03 WS-HWORD-X REDEFINES WS-HWORD
PIC X(02).
*
MOVE WS-BCD TO WS-PACKED-X (1:LENGTH OF WS-PACKED-X - 1)
MOVE X'0F' TO WS-PACKED-X (LENGTH OF WS-PACKED-X:).
MOVE WS-PACKED-V9 TO WS-HWORD.
MOVE WS-HWORD-X TO WS-HEX.
|
*
* AT THIS POINT, WS-HEX = X'001A'
* |
|
Back to top |
|
|
|