by BillyBoyo » Sat Nov 01, 2014 4:38 pm
There are two types of binary available in Enterprise COBOL. One is the standard binary which does base-10 truncation to the PICture definition. These have a USAGE of COMP, COMP-4 or BINARY.
PIC 9 COMP, maximum value 9.
PIC 99 COMP-4, maximum value 99.
PIC 9(4) BINARY, maximum value 999.
The other type is "native binary" whose value is only limited to field-size and which truncates to field-size. This has USAGE of COMP-5.
PIC 9 COMP-5, maxumum value ((2^16)-1) = 32767
PIC 99 COMP-5, maxumum value ((2^16)-1) = 32767
PIC 9(4) COMP-5, maxumum value ((2^16)-1) = 32767
With COMP-5 the PICture just defines the field-size. 1-4 is two bytes, 5-9 is four bytes, 10+ is eight bytes.
To hold your value with COMP, COMP-4 or BINARY, you'd need PIC 9(5) at least, which would be four bytes of storage.
To hold your value with COMP-5, you'd need PIC 9 -9(4) at least, which would be two bytes of storage.
Compiler option TRUNC can also be involved. TRUNC(BIN) will treat all binary definitions (COMP, COMP-4 and BINARY) the same as it treats COMP-5. COMP-5 typically causes the compiler to generate more instructions, so is "slower". Some sites have TRUNC(BIN) as their compiler setting. If so, you're stuck with that.