COBOL Manual for TNS and TNS/R Programs

Procedure Division
HP COBOL Manual for TNS and TNS/R Programs—522555-006
8-25
SIZE ERROR Phrase
•
COMPUTATIONAL Data Items
If an arithmetic computation stores a value in a COMPUTATIONAL data item, and
the decimal representation of that value exceeds the number of decimal places in
the item’s PICTURE clause (as in C = A + B in the preceding example), a later
attempt to use that value (as in D = C - B in the preceding example) can cause
arithmetic overflow.
HP COBOL can retrieve a number larger than 9,999 from a PICTURE S9(4)
COMPUTATIONAL field (even though the storage unit is 2 bytes and can therefore
accommodate values from -32,767 through +32,767), but arithmetic overflow is
likely.
The largest value HP COBOL can use in a 4-byte COMPUTATIONAL item is
999,999,999 (not 2,147,483,647).
The largest value HP COBOL can use in an 8-byte COMPUTATIONAL item is
999,999,999,999,999,999 (not 9,223,372,036,854,775,807).
If you need the full capacity of 2-byte, 4-byte, and 8-byte storage, describe the item
as USAGE NATIVE-2, NATIVE-4, or NATIVE-8 (with no PICTURE) or
COMPUTATIONAL-5.
•
SIZE ERROR and Multiple Results
When a statement includes more than one receiving item, the decision to assign a
result value or cause a size error condition is determined independently for each
such item; therefore, if the size error condition does not occur for a particular
receiving item, that item is assigned its correct result value even when the size
error condition exists for one or more other receiving items of the same statement
(unless the run terminates abnormally because of an arithmetic overflow).
Example 8-10. SIZE ERROR Phrase and TRAP2 Directive
WORKING-STORAGE SECTION.
77 A PIC 99 COMP VALUE 99.
77 B PIC 99 COMP VALUE 88.
77 C PIC 99 COMP.
77 D PIC 99 COMP.
PROCEDURE DIVISION.
...
* TRAP2 directive does not catch this size error:
COMPUTE C = A + B.
COMPUTE D = C - B.
DISPLAY D.
* ON SIZE ERROR phrase catches this size error:
COMPUTE C = A + B
ON SIZE ERROR DISPLAY "Too Big"
NOT ON SIZE ERROR DISPLAY "Acceptable".
...