>>SOURCE FORMAT IS FREE *> gnucobol-std-dialects-ibm.cob - one program, compiled once per dialect, *> that prints how big four COMP items are, how DISPLAY shows them, and *> what an ADD that outgrows its PICTURE leaves behind *> Dialect: GnuCOBOL 3.x, free format; meant to be compiled three ways: *> cobc -x gnucobol-std-dialects-ibm.cob *> cobc -x -std=ibm gnucobol-std-dialects-ibm.cob *> cobc -x -std=ibm -fbinary-truncate gnucobol-std-dialects-ibm.cob *> Status : desk-checked against the GnuCOBOL 3.2 source and test suite; *> NOT compiled (no cobc on the authoring machine) *> Inputs : none *> Outputs: six lines on standard output *> Run : ./gnucobol-std-dialects-ibm *> (Windows: gnucobol-std-dialects-ibm.exe) IDENTIFICATION DIVISION. PROGRAM-ID. DIALECT-PROBE. DATA DIVISION. WORKING-STORAGE SECTION. *> Four binary items. USAGE COMP is USAGE BINARY in GnuCOBOL; how many *> bytes each one gets is the binary-size setting of the dialect. 01 WS-Tiny PIC 9(2) COMP VALUE 12. 01 WS-Count PIC 9(4) COMP VALUE 5000. 01 WS-Delta PIC S9(4) COMP VALUE -12. 01 WS-Total PIC 9(5) COMP VALUE 12345. *> A plain DISPLAY item to print the byte counts in. 01 WS-Bytes PIC 9(2). PROCEDURE DIVISION. MAIN-PARA. *> FUNCTION LENGTH of a non-national item is its size in bytes. MOVE FUNCTION LENGTH(WS-Tiny) TO WS-Bytes DISPLAY "WS-TINY PIC 9(2) COMP BYTES " WS-Bytes " SHOWS " WS-Tiny MOVE FUNCTION LENGTH(WS-Count) TO WS-Bytes DISPLAY "WS-COUNT PIC 9(4) COMP BYTES " WS-Bytes " SHOWS " WS-Count MOVE FUNCTION LENGTH(WS-Delta) TO WS-Bytes DISPLAY "WS-DELTA PIC S9(4) COMP BYTES " WS-Bytes " SHOWS " WS-Delta MOVE FUNCTION LENGTH(WS-Total) TO WS-Bytes DISPLAY "WS-TOTAL PIC 9(5) COMP BYTES " WS-Bytes " SHOWS " WS-Total *> 5000 + 7000 = 12000: five digits in a four-digit PICTURE. *> No ON SIZE ERROR, so binary-truncate decides what is stored. ADD 7000 TO WS-Count DISPLAY "ADD 7000 TO WS-COUNT SHOWS " WS-Count EVALUATE WS-Count WHEN 12000 DISPLAY "WS-COUNT IS 12000" WHEN 2000 DISPLAY "WS-COUNT IS 2000" WHEN OTHER DISPLAY "WS-COUNT IS SOMETHING ELSE" END-EVALUATE GOBACK.