Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
COMP, or COMP-4 or BINARY (they are all the same, COMP-4 and BINARY are just aliases of COMP) has maximum values limited by the PICture.
COMP PIC 9 has a value 0-9, COMP PIC S9(4) has a value -9999-+9999.
The PICture also defines the amount of storage occupied. 0-4 digits, a halfword, 5-9 digits a fullword, any bigger a doubleword.
COMP, COMP-4 and BINARY do truncation to PICture, decimal truncation.
COMP-5 is "native binary". What this means is that the number of digits in the PICture define the amount of storage, but the value which can be contained is limited only by the bit-settings of the field (and whether signed or not), not by the PICture.
COMP-5 PIC 9 can hold a value 0-65535. COMP-5 PIC S99 can hold a value -32768-+32767.
COMP-5 does truncation to field-size, binary truncation.
Compiler option TRUNC with (BIN) will treat all binary fields (COMP, COMP-4, BINARY) as "native binary" (COMP-5).
Generally more instructions are generated for COMP-5 than for the others.
Use COMP-5 if the field can contain values beyond the PICture (CICS or SQL or JAVA fields).
Don't mess with the compiler option TRUNC, as it can change program behaviour. A change to that option has to be analysed and tested, just like any program change.
COMP, or COMP-4 or BINARY (they are all the same, COMP-4 and BINARY are just aliases of COMP) has maximum values limited by the PICture.
COMP PIC 9 has a value 0-9, COMP PIC S9(4) has a value -9999-+9999.
The PICture also defines the amount of storage occupied. 0-4 digits, a halfword, 5-9 digits a fullword, any bigger a doubleword.
COMP, COMP-4 and BINARY do truncation to PICture, decimal truncation.
COMP-5 is "native binary". What this means is that the number of digits in the PICture define the amount of storage, but the value which can be contained is limited only by the bit-settings of the field (and whether signed or not), not by the PICture.
COMP-5 PIC 9 can hold a value 0-65535. COMP-5 PIC S99 can hold a value -32768-+32767.
COMP-5 does truncation to field-size, binary truncation.
Compiler option TRUNC with (BIN) will treat all binary fields (COMP, COMP-4, BINARY) as "native binary" (COMP-5).
Generally more instructions are generated for COMP-5 than for the others.
Use COMP-5 if the field can contain values beyond the PICture (CICS or SQL or JAVA fields).
Don't mess with the compiler option TRUNC, as it can change program behaviour. A change to that option has to be analysed and tested, just like any program change.
Joined: 29 Oct 2010 Posts: 202 Location: Toronto, ON, Canada
I always use COMP-5 for binary fields. The compile will generate it as a 2 byte halfword or 4 byte fullword and treat it as native binary. Also this option is not affected by the TRUNC compiler option. I see no practical reason to use COMP or BINARY.
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
I only use COMP-5 when necessary :-)
The important thing is that one definition is not used in one place, and another definition in another place, whether within a program, across programs, across systems, or on files or other means of data transfer.
TRUNC(BIN) is a way to get everything treated as COMP-5. Generally, there is a performance degradation with COMP-5. The larger the field (half- faster than full- faster than double-word), the bigger the hit.
Remember that COMP-5 will do no decimal truncation: