转换为comp -3字段Cobol中的二进制文件

时间:2016-05-09 14:57:30

标签: binary hex cobol comp-3

我正在尝试转换已存储二进制的pic S9(9)V99 comp-3字段。它显示如下:6 / PS X&00; 000000002000'。

此金额应显示为20.00。我试图找到将其转换为pic -9(9)V99字段的正确方法。

由于

3 个答案:

答案 0 :(得分:1)

以下是我如何解决它:

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 :(得分:1)

它基本上与Decode a Binary Coded Decimal

相同

你创建了一个带有1个十进制数字的comp-3,并且做了#x; 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 

答案 2 :(得分:-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.