Display wrong format in micro focus visual cobol.

Hi.

Recently, i code a test program as below :

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-TEST PIC 9(5)V9(2) VALUE 13.5.
01 WS-NUM3 PIC S9(3)V9(2) VALUE -123.45.

PROCEDURE DIVISION.
DISPLAY WS-TEST.
DISPLAY WS-NUM3.
STOP RUN.

When i run by ctrl f11 then the result in console command is :

0001350
12345-

But when i run this project on OpenCobolIDE then result is correct : 

00013.50

-123.45

Plz help me.

Parents
  • The reason is simple: Any numeric variable with a virtual decimal sign "v" is for calculations only. The data is stored without any decimal point position. So the value 12345 is stored just like that. The actual value depends on the programmer who determines the position of decimal point. You can define a variable as 999v99 in one program and as 99v999 in another program. When you read the data from a file in the first case it will be 123.45 in the second 12.345. THE DECIMAL POINT POSITION IS DYNAMIC AND FOR CALCULATION ONLY.

    However declarations such as 9(3).9(2) or ----.99 are formatted and for display purposes. Here is the decimal point position STATIC, i.e. it is fixed.

    I do strongly believe that back in 1950's and 1960's, when the cost of storage devices were extremely high, COBOL developers wanted to save every byte possible. With dynamic decimal point positioning, on every decimal value they saved one Byte. I think thats the reason why it is working this odd way.

Reply
  • The reason is simple: Any numeric variable with a virtual decimal sign "v" is for calculations only. The data is stored without any decimal point position. So the value 12345 is stored just like that. The actual value depends on the programmer who determines the position of decimal point. You can define a variable as 999v99 in one program and as 99v999 in another program. When you read the data from a file in the first case it will be 123.45 in the second 12.345. THE DECIMAL POINT POSITION IS DYNAMIC AND FOR CALCULATION ONLY.

    However declarations such as 9(3).9(2) or ----.99 are formatted and for display purposes. Here is the decimal point position STATIC, i.e. it is fixed.

    I do strongly believe that back in 1950's and 1960's, when the cost of storage devices were extremely high, COBOL developers wanted to save every byte possible. With dynamic decimal point positioning, on every decimal value they saved one Byte. I think thats the reason why it is working this odd way.

Children
No Data