View previous topic :: View next topic
|
Author |
Message |
shanudarling Warnings : 1 New User
Joined: 20 Dec 2006 Posts: 55 Location: noida
|
|
|
|
Hi,
I have an existing file which has a x(4) field which contains date in hex format.
Sample values -
I want to to move this x(4) value into 9(8). For example, for the above sample the final expected value is 20130723.
I tried moving this value to s9(4) comp-3 but the value which moved was 0373.
Request you to please provide me some inputs to resolve this.
Thanks. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
You cannot do this with a MOVE statement -- you MUST write code to convert the hexadecimal values to decimal digits. Your code will take each hex character (the X'20', X'13', X'07' and X'23' in your example) and convert to decimal, accumulating the results as you go. The conversion can be done by a table or by EVALUATE or by arithmetic -- your choice -- but you will be converting base 16 values to base 10 values. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Although I'm repeating what Anuj has posted, perhaps this is somewhat clearer -
Code: |
*
* NOTE: ALL NUMERIC FIELDS MUST BE UNSIGNED
*
03 WS-PACKED PIC 9(09) PACKED-DECIMAL.
03 WS-PACKED-V9 REDEFINES WS-PACKED
PIC 9(08)V9 PACKED-DECIMAL.
03 WS-PACKED-X REDEFINES WS-PACKED
PIC X(05).
03 WS-DISPLAY PIC 9(09).
03 WS-DISPLAY-V9 REDEFINES WS-DISPLAY
PIC 9(08)V9.
03 WS-DISPLAY-X REDEFINES WS-DISPLAY
PIC X(09).
*
MOVE X'20130723' TO WS-PACKED-X (1:4).
MOVE X'0F' TO WS-PACKED-X (5:).
MOVE WS-PACKED-V9 TO WS-DISPLAY-V9.
*
INSPECT WS-DISPLAY-X CONVERTING X'FAFBFCFDFEFF'
TO 'ABCDEF'.
*
* WS-DISPLAY-X CONTAINS C'201307230'
*
DISPLAY 'WS-DISPLAY-X = ', WS-DISPLAY-X.
|
Leave the INSPECT, in case there's another value you need to convert from HEX to CHARACTER, that may contain 4-Bit nibbles of "A" through "F", which you currently don't have in your example.
If your HEX value (for example) were X'20BF72A' then the INSPECT would be necessary to convert the unpacked nibbles of X'FB', X'FF' and X'FA, to 'B', 'F' and 'A', respectively. |
|
Back to top |
|
|
ApexNC
New User
Joined: 10 Feb 2006 Posts: 19 Location: USA
|
|
|
|
Based on the sample value given, I'd wager this is actually a YYYYMMDD field in Binary Coded Decimal format. In which case, the conversion to decimal is actually quite simple:
Code: |
01 FILLER.
05 PIC-X-4 PIC X(4) VALUE X'20130723'.
05 PIC-9-8 PIC 9(8).
LINKAGE SECTION.
01 BCD-CONV PIC 9(8)V9 COMP-3.
PROCEDURE DIVISION.
SET ADDRESS OF BCD-CONV TO ADDRESS OF PIC-X-4
MOVE BCD-CONV TO PIC-9-8
|
If you don't mind RC=4 and a redefines length warning (IGYDS1154-W) on the compile, it can be made even simpler:
Code: |
01 FILLER.
05 PIC-X-4 PIC X(4) VALUE X'20130723'.
05 BCD-CONV REDEFINES PIC-X-4 PIC 9(8)V9 COMP-3.
05 PIC-9-8 PIC 9(8).
PROCEDURE DIVISION.
MOVE BCD-CONV TO PIC-9-8
|
Putting BCD-CONV in LINKAGE and using SET ADDRESS gives RC=0 on the compile and avoids the redefines length warning. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Requires documenting if used.
The definition overlaps the first byte of the following field, However, it doesn't matter, because nothing from that final byte is used.
The MOVE is to an integer, so the decimal part (V9), which is only there to allow the field to be defined as COMP-3/PACKED-DECIMAL, is not used.
The receiving field is unsigned, so the compiler will not use the sign from the source field, it will simply make the sign-nybble in the receiving field F.
So, it works.
However,
Code: |
01 FILLER.
05 BCD-VALUE-PLUS-ONE-BYTE.
10 PIC-X-4 PIC X(4) VALUE X'20130723'
10 FILLER PIC 9 COMP-3 VALUE ZERO.
05 BCD-CONV REDEFINES BCD-VALUE-PLUS-ONE-BYTE PIC 9(8)V9 COMP-3.
05 PIC-9-8 PIC 9(8).
PROCEDURE DIVISION.
MOVE BCD-CONV TO PIC-9-8 |
No messages, no wondering, no change of behaviour with a signed final receiver. |
|
Back to top |
|
|
|