Please help me understand what is going on in the code below. Do you think the same results would appear on the mainframe or other dialects of COBOL? Thank you much.
This code was compiled and run on Windows 10 GNU COBOL 3.2.1
IDENTIFICATIONDIVISION.PROGRAM-ID.HELLO-WORLD.DATADIVISION.WORKING-STORAGESECTION.01CPICS9(4)COMP.01C5PICS9(4)COMP-5.01MSGPICX(100).PROCEDUREDIVISION.MOVE32767TOC,C5*>CASE1-IexpectedthatCOMPistoholdthevalue32767IFC=32767THENDISPLAY" C IS OK"ELSEDISPLAY"C NOT OK"END-IF*>CNOTOK*>CASE2okIFC5=32767THENDISPLAY" C5 IS OK"END-IF*>COK*>CASE3Iexpectedthevalue32767tobeshownatleastforthec5DISPLAY"LAST:"CSPACEC5*>LAST:27672767STOPRUN.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
if -fnotrunc is specified as a compile option the binary fields (comp (aka comp-4)) and comp-5 will support (2 ^ the number of bits -1) in the picture clause. Sans -fnotrunc the digits defined in the PIC clause dictate the maximum value. 9(4) COMP-5 is 16 bits wide - therefore the maximum value is 2 ^ 15th or 32768 in decimal. If the high order (most significant bit) is has value of one it indicates a negative number
Omitting -fnotrunc will do things like 2's complement when the value exceeds 9999. I don't know the exact behaviors.
-fnotrunc should make your example work correctly. I have no idea what COMP-X does to the axiom.
Normally Pic 9(01) thru Pic 9(04) will be 16 bits wide.
Pic 9(05) thru PIC 9(09) will be 32 bits wide
Pic 9(10) thru 9(18) will be 64 bits wide
S9(1) - S9(4) Binary halfword (2 bytes) -32768 through +32767
S9(5) - S9(9) Binary fullword (4 bytes) -2,147,483,648 through +2,147,483,647
S9(10) - S9(18) Binary doubleword (8 bytes) +-9,223,372,036,854,775,808
9(1) through 9(4) Binary halfword (2 bytes) 0 through 65535
9(5) through 9(9) Binary fullword (4 bytes) 0 through 4,294,967,295
9(10) through 9(18) Binary doubleword (8 bytes) 0 through 18,446,744,073,709,551,615
Ralph
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
Anonymous
-
2021-08-14
Thank you for the valuable information.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
Anonymous
-
2021-08-14
Would this flag -fnotrunc be equivelent to mainframe TRUNC(BIN)? I guess yes.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Please help me understand what is going on in the code below. Do you think the same results would appear on the mainframe or other dialects of COBOL? Thank you much.
This code was compiled and run on Windows 10 GNU COBOL 3.2.1
I believe this has to do with the compilation options. Not sure which options to use though.
Last edit: Emmad 2021-08-14
if -fnotrunc is specified as a compile option the binary fields (comp (aka comp-4)) and comp-5 will support (2 ^ the number of bits -1) in the picture clause. Sans -fnotrunc the digits defined in the PIC clause dictate the maximum value. 9(4) COMP-5 is 16 bits wide - therefore the maximum value is 2 ^ 15th or 32768 in decimal. If the high order (most significant bit) is has value of one it indicates a negative number
Omitting -fnotrunc will do things like 2's complement when the value exceeds 9999. I don't know the exact behaviors.
-fnotrunc should make your example work correctly. I have no idea what COMP-X does to the axiom.
Normally Pic 9(01) thru Pic 9(04) will be 16 bits wide.
Pic 9(05) thru PIC 9(09) will be 32 bits wide
Pic 9(10) thru 9(18) will be 64 bits wide
S9(1) - S9(4) Binary halfword (2 bytes) -32768 through +32767
S9(5) - S9(9) Binary fullword (4 bytes) -2,147,483,648 through +2,147,483,647
S9(10) - S9(18) Binary doubleword (8 bytes) +-9,223,372,036,854,775,808
9(1) through 9(4) Binary halfword (2 bytes) 0 through 65535
9(5) through 9(9) Binary fullword (4 bytes) 0 through 4,294,967,295
9(10) through 9(18) Binary doubleword (8 bytes) 0 through 18,446,744,073,709,551,615
Ralph
Thank you for the valuable information.
Would this flag -fnotrunc be equivelent to mainframe TRUNC(BIN)? I guess yes.