将二进制文件转换为 comp -3 字段 Cobol
conversion of a binary put in a comp -3 field Cobol
我正在尝试转换其中存储有二进制文件的 pic S9 (9)V99 comp-3 字段。是这样显示的:6/PS X'000000002000'.
此金额应显示为 20.00。我正在尝试找到将其转换为 pic -9 (9)V99 字段的正确方法。
谢谢
我是这样解决的:
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 现在显示为 _00000020.00,其中 _ 是符号(这里的符号将始终为空白,因为它不在二进制数量字段中。
和基本一样
您创建了多 1 个小数位的 comp-3 并进行 'pic x' 次移动。
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
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.
我正在尝试转换其中存储有二进制文件的 pic S9 (9)V99 comp-3 字段。是这样显示的:6/PS X'000000002000'.
此金额应显示为 20.00。我正在尝试找到将其转换为 pic -9 (9)V99 字段的正确方法。
谢谢
我是这样解决的:
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 现在显示为 _00000020.00,其中 _ 是符号(这里的符号将始终为空白,因为它不在二进制数量字段中。
和
您创建了多 1 个小数位的 comp-3 并进行 'pic x' 次移动。
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
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.