Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

ON SIZE ERROR phrase

A size error condition exists if, after decimal point alignment, the integer digits in the computed result exceed the number of places provided for them and thus cause an overflow.

Syntax rules

  1. Violation of the rules for evaluation of exponentiation always terminates the arithmetic operation and always causes a size error condition (see section "Arithmetic statements" et seq.).

  2. The ON SIZE ERROR phrase contains an imperative-statement which specifies what actions are to be taken in the event of a size error.

  3. The size error condition applies only to the final results of an arithmetic operation and not to intermediate results, except in the case of the MULTIPLY and DIVIDE statements.

  4. If the ROUNDED phrase is specified, rounding takes place before the size error check.

  5. If the ON SIZE ERROR phrase is specified and a size error condition exists after the execution of the arithmetic statement, the values of the affected resultant identifiers remain unchanged from the values they had before execution of the arithmetic statement. The values of resultant identifiers for which no size error condition exists are the same as they would have been if the size error condition had not resulted for any of the resultant identifiers. After completion of the arithmetic operations, control is transferred to the imperative-statement specified in the ON SIZE ERROR phrase and execution continues according to the rules for each statement specified in that imperative-statement. If a procedure branching or conditional statement which causes explicit transfer of control is executed, control is transferred in accordance with the rules for that statement; otherwise, upon completion of the execution of the imperativestatement specified in the ON SIZE ERROR phrase, control is transferred to the end of the arithmetic statement and the NOT ON SIZE ERROR phrase, if specified, is ignored.

  6. If ON SIZE ERROR is not specified and a size error condition exists after the execution of the arithmetic operations specified by an arithmetic statement, the values of the affected resultant identifiers are undefined. The values of resultant identifiers for which no size error condition exists are the same as they would have been if the size error condition had not resulted for any of the resultant identifiers. After completion of the arithmetic operations, control is transferred to the end of the arithmetic statement, and the NOT ON SIZE ERROR phrase, if present, is ignored.

  7. If the size error condition does not exist, control is transferred to the end of the arithmetic statement or to the imperative-statement specified in the NOT ON SIZE ERROR phrase if it is specified. In the latter case, execution continues according to the rules for each statement specified in that imperative-statement. If a procedure branching or conditional statement which causes explicit transfer of control is executed, control is transferred in accordance with the rules for that statement; otherwise, upon completion of the execution of the imperative-statement specified in the NOT ON SIZE ERROR phrase, control is transferred to the end of the arithmetic statement.

  8. For an ADD statement with the CORRESPONDING phrase or a SUBTRACT statement with the CORRESPONDING phrase, if any of the individual operations produces a size error condition, the imperative-statement specified in the ON SIZE ERROR phrase is not executed until all of the individual additions or subtractions are completed.

  9. Division by zero always causes a size error condition.

    For COMPUTATIONAL-1 or COMPUTATIONAL-2 data items, division by zero will cause the imperative-statement in the ON SIZE ERROR phrase to be executed.

Example 8-19

    IDENTIFICATION DIVISION.
    PROGRAM-ID. SE.
    ENVIRONMENT DIVISION.
    CONFIGURATION SECTION.
    SPECIAL-NAMES.
        TERMINAL IS T.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    77  A PIC 99 VALUE ZERO.
    77  B PIC 99 VALUE ZERO.
    PROCEDURE DIVISION.
    MAIN SECTION.
    P1.
        MOVE 44 TO A.
        MOVE 72 TO B.
        ADD A TO B 
        ON SIZE ERROR 
          PERFORM PROC-A
        END-ADD
        STOP RUN.
    PROC-A.
        DISPLAY "Size error!" UPON T.
        DISPLAY A UPON T.
        DISPLAY B UPON T.


Current value of A:    44
Current value of B:    72
Calculated result:      116

The result item B is too small to accommodate the calculated result and a size error condition occurs. Since ON SIZE ERROR is specified, the statement PERFORM PROC-A is executed. Result item B is unchanged.