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
  • "I think Cobol should do an intelligent conversion" this may require a time machine to change the way standard COBOL operates :-)  And to answer a poster from above, yes, COBOL does it like this to save every byte as storage was very very expensive way back then.

    The DISPLAY verb merely dumps the data-item to the SYSOUT without and regards for data-type.  It will quite happily display the bytes from a BINARY (COMP) or PACKED-DECIMAL (COMP-3) data item.

    When handling numeric data in COBOL you always need to format numerics before any output whether with DISPLAY to SYSOUT, to a screen, a report file, an XML file, a CSV file, etc, etc.

    A data item defined as PIC S9(5)V99 takes up 7-bytes of storage with an implied decimal point and the sign stored in the trailing high-order half bytes unless defined with a SIGN SEPARATE clause.  E.g. -0.01 would be ASCII x30303030303071 (IIRC) and would display as such.  To get it to display formatted move it to a formatted data item first e.g. PIC -(4)9.99.

    Whilst a PIC S9(5)V99 does have an implied USAGE DISPLAY clause it should not be taken literally.

    Also, it should be noted that usage display data item shouldn't really be used in mathematical operations or as subscripts.  COBOL will quite happily let you do it but, to use a term from other languages, you will incur a type conversion upon each use of the data item (again this is from the old days when processor speed was at a premium and any assembler instructions you could save were worth it - but the principle still applies).  So the above data item would be better stored as PIC S9(5)V99 USAGE PACKED-DECIMAL which would be 4-bytes.  E.g. -0.01 would be ASCII x0000001D and should be moved to a formatted data item before output.

Reply
  • "I think Cobol should do an intelligent conversion" this may require a time machine to change the way standard COBOL operates :-)  And to answer a poster from above, yes, COBOL does it like this to save every byte as storage was very very expensive way back then.

    The DISPLAY verb merely dumps the data-item to the SYSOUT without and regards for data-type.  It will quite happily display the bytes from a BINARY (COMP) or PACKED-DECIMAL (COMP-3) data item.

    When handling numeric data in COBOL you always need to format numerics before any output whether with DISPLAY to SYSOUT, to a screen, a report file, an XML file, a CSV file, etc, etc.

    A data item defined as PIC S9(5)V99 takes up 7-bytes of storage with an implied decimal point and the sign stored in the trailing high-order half bytes unless defined with a SIGN SEPARATE clause.  E.g. -0.01 would be ASCII x30303030303071 (IIRC) and would display as such.  To get it to display formatted move it to a formatted data item first e.g. PIC -(4)9.99.

    Whilst a PIC S9(5)V99 does have an implied USAGE DISPLAY clause it should not be taken literally.

    Also, it should be noted that usage display data item shouldn't really be used in mathematical operations or as subscripts.  COBOL will quite happily let you do it but, to use a term from other languages, you will incur a type conversion upon each use of the data item (again this is from the old days when processor speed was at a premium and any assembler instructions you could save were worth it - but the principle still applies).  So the above data item would be better stored as PIC S9(5)V99 USAGE PACKED-DECIMAL which would be 4-bytes.  E.g. -0.01 would be ASCII x0000001D and should be moved to a formatted data item before output.

Children
No Data