Example of Truncation

The TRUNC Compiler directive can change the results of some operations, as demonstrated in the following examples in which item A is described as PIC 99 COMP.

Operation Result
TRUNC NOTRUNC TRUNC"ANSI"
MOVE 163 TO A 63 163 63
MOVE 263 TO A 63 7 63
MOVE 13 TO A, ADD 150 TO A 63 163 undefined results
MOVE 13 TO A, ADD 250 TO A 63 undefined results undefined results
Note:
  1. This directive has no effect on the truncation of low-order digits in non-integer data. This always conforms with the behavior specified in ANSI COBOL.
  2. If the IBMCOMP Compiler directive is set, extra upper bytes may be allocated to a COMP item. These are counted in the space allocated. When IBMCOMP is on, padding bytes may be generated before a COMP item with a SYNC clause; these are not part of the item, and are never affected by data stored in the item.
  3. When a value being stored into a signed item is limited to the number of digits by the PICTURE clause, it can never be big enough to overwrite the sign bit. When the NOTRUNC directive is set this is not true, and the value, if large enough, overwrites the sign bit.