Reputation: 388
I am trying to convert a pic S9 (9)V99 comp-3 field which has been store with binary in it. It is display like this: 6/PS X'000000002000'.
This amount should show like this 20.00. I am trying to find the proper way to convert it to a pic -9 (9)V99 field.
Thanks
Upvotes: 0
Views: 1771
Reputation: 1
IDENTIFICATION DIVISION.
PROGRAM-ID. XYZ.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-BIN PIC 9(10).
01 TEMP PIC Z(10).
01 EXP PIC 9(2) VALUE 0.
01 R1 PIC 9(10).
01 C PIC 9(10).
PROCEDURE DIVISION.
DISPLAY " ENTER THE BINARY NUMBER ".
ACCEPT WS-BIN.
PARA1.
DIVIDE WS-BIN BY 10 GIVING WS-BIN REMAINDER R1.
COMPUTE C = C + R1 * 2 ** EXP
ADD 1 TO EXP.
IF WS-BIN NOT = 0
GO TO PARA1
ELSE GO TO PARA2.
PARA2.
MOVE C TO TEMP
DISPLAY " THE DECIMAL NUMBER IS " TEMP.
STOP RUN.
Upvotes: -2
Reputation: 10543
It is basically the same as Decode a Binary Coded Decimal
You create a comp-3 with 1 more decimal digit and do 'pic x' moves.
01 WS-AMT-IN PIC S9(009)V99 COMP-3.
01 WS-AMT-IN-X REDEFINES
WS-AMT-IN PIC X(006).
01 WS-AMT-OUT1 PIC S9(009)V999 COMP-3.
01 REDEFINES WS-AMT-OUT1
03 WS-AMT-OUT1-X PIC X(006).
03 PIC s9 comp-3 value zero.
01 WS-AMT-OUT-2 PIC S9(009)V99 COMP-3.
Move X'000000002000' to WS-AMT-IN-X
Move WS-AMT-IN-X to WS-AMT-OUT1-x
Move WS-AMT-OUT1 to WS-AMT-OUT-2
Upvotes: 1
Reputation: 388
Here is how I resolve it:
01 WS-ZONENUM11.
05 WS-ZONE9NUM PIC 9(009).
05 WS-ZONE2NUM PIC 9(002).
01 WS-ZONENUM11-RED REDEFINES WS-ZONENUM11
PIC 9(09)V99.
01 WS-AMT-OUT PIC -9(009).99.
01 WS0900-AMT-IN COMP-3 PIC S9(009)V99.
01 WS0900-AMT-IN-RED REDEFINES
WS0900-AMT-IN PIC X(006).
MOVE WS0900-AMT-IN-RED TO WS-WS0900-AMT-IN.
MOVE WS-ZONEX5NM TO WS-ZONE9NUM.
MOVE WS-ZONEX1NM TO WS-ZONE2NUM.
MOVE WS-ZONENUM11-RED TO WS-AMT-OUT.
WS-AMT-OUT now is displayed as _00000020.00 where _ is the sign (the sign here will be always a blank since it was not in the binary amount field.
Upvotes: 1