SIZE ERROR phrases

A size error condition can occur in different ways.

  • When the absolute value of the result of an arithmetic evaluation, after decimal point alignment, exceeds the largest value that can be contained in the result field.
  • When division by zero occurs.
  • When the result of an arithmetic statement is stored in a windowed date field and the year of the result falls outside the century window. For example, given YEARWINDOW(1940) (which specifies a century window of 19402039), the following SUBTRACT statement causes a size error:
    
    01  WINDOWED-YEAR  DATE FORMAT YY PICTURE 99
                       VALUE IS 50.
        ...
        SUBTRACT 20 FROM WINDOWED-YEAR
                 ON SIZE ERROR imperative-statement
    

    The size error occurs because the result of the subtraction, a windowed date field, has an effective year value of 1930, which falls outside the century window. For details on how windowed date fields are treated as if they were converted to expanded date format, see Subtraction that involves date fields.

    For more information about how size errors can occur when using date fields, see Storing arithmetic results that involve date fields.

  • In an exponential expression, as indicated in the following table:

Table 1. Exponentiation size error conditions
Size error Action taken when a SIZE ERROR clause is present Action taken when a SIZE ERROR clause is not present
Zero raised to zero power The SIZE ERROR imperative is executed. The value returned is 1, and a message is issued.
Zero raised to a negative number The SIZE ERROR imperative is executed. The program is terminated abnormally.
A negative number raised to a fractional power The SIZE ERROR imperative is executed. The absolute value of the base is used, and a message is issued.

The size error condition applies only to final results, not to any intermediate results.

If the resultant identifier is defined with usage BINARY, COMPUTATIONAL, COMPUTATIONAL-4, or COMPUTATIONAL-5, the largest value that the resultant data item can contain is the value implied by the item's decimal PICTURE character-string, regardless of the TRUNC compiler option in effect.

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

When a size error occurs, the subsequent action of the program depends on whether the ON SIZE ERROR phrase is specified.

If the ON SIZE ERROR phrase is not specified and a size error condition occurs, truncation rules apply and the value of the affected resultant identifier is computed.

If the ON SIZE ERROR phrase is specified and a size error condition occurs, the value of the resultant identifier affected by the size error is not altered; that is, the error results are not placed in the receiving identifier. After completion of the execution of the arithmetic operation, the imperative statement in the ON SIZE ERROR phrase is executed, control is transferred to the end of the arithmetic statement, and the NOT ON SIZE ERROR phrase, if specified, is ignored.

For ADD CORRESPONDING and SUBTRACT CORRESPONDING statements, if an individual arithmetic operation causes a size error condition, the ON SIZE ERROR imperative statement is not executed until all the individual additions or subtractions have been completed.

If the NOT ON SIZE ERROR phrase has been specified and, after execution of an arithmetic operation, a size error condition does not exist, the NOT ON SIZE ERROR phrase is executed.

When both the ON SIZE ERROR and NOT ON SIZE ERROR phrases are specified, and the statement in the phrase that is executed does not contain any explicit transfer of control, then if necessary an implicit transfer of control is made after execution of the phrase to the end of the arithmetic statement.