Summary -

In this topic, we described about the SIZE ERROR Phrase with detailed example.

A size error condition can occur in four different ways -

  • When the result value of an arithmetic expression, exceeds the largest value that can be contained in the result field.
  • When division by zero occurs.
  • When the year of the arithmetic statement result falls outside the century window.
  • In an exponential expression, as indicated in the following table -
Size error Action taken when a SIZE ERROR clause is not present
Zero raised to zero power The value returned is 1, and a message is issued
Zero raised to a negative number The program is terminated abnormally
A negative number raised to a fractional power The absolute value of the base is used, and a message is issued

The size error condition applies to results, not to any intermediate results. 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 the action specified in ON SIZE ERROR phrase. If the ON SIZE ERROR phrase is not specified and a size error condition occurs, truncation rules applies and the resultant stores in the identifier.

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

If an individual arithmetic operation causes a size error condition (for ADD CORRESPONDING and SUBTRACT CORRESPONDING statements), 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 a size error condition does not exist, the NOT ON SIZE ERROR phrase is executed.