SIZE ERROR Phrase
SIZE ERROR Phrase
A size error condition can occur -
- When the result value of an arithmetic expression exceeds the largest value that can be stored in the result variable.
- When a value is divided by zero.
- When the result year of the arithmetic statement falls outside the century range.
- When zero is raised by zero or negative number or fractional number.
Syntax -
----+----1----+----2----+----3----+----4----+----5----+
ADD | SUBTRACT | DIVIDE | MULTIPLY
[ON SIZE ERROR statements-block1]
[NOT ON SIZE ERROR statements-block2].
Note! All statements coded in [ ] are optional.
Parameters -
- statements-block1 - specifies the set of statements that are executed when SIZE ERROR occurs.
- statements-block2 - specifies the set of statements that are executed when the arithmetic operation is successful.
Points to Note -
- The size error validation applies on the result.
- If ROUNDED phrase is coded with result variable, the rounding done first before size error checking.
Process -
When size error occurs -
- If no SIZE ERROR phrase is coded, the result value gets truncated and stores in the result variable.
- If SIZE ERROR phrase is coded, the result variable is not updated with result value, control transfers to the set of statements coded with ON SIZE ERROR phrase.
- If SIZE ERROR occurs while using ADD CORRESPONDING or SUBTRACT CORRESPONDING, the control is not transferred to the set of statements coded with ON SIZE ERROR phrase until all the arithmetic operations completed.
When no size error occurs -
- If NOT ON SIZE ERROR phrase is not coded, the control transferred to the next statement that is coded immediately after arithmetic statement.
- If NOT ON SIZE ERROR phrase is coded, the control transferred to the set of statements coded with NOT ON SIZE ERROR phrase.
Examples -
Scenario - No overflow
Input- WS-A = 700, WS-B = 200 Declaration- 05 WS-A PIC 9(03) VALUE 700. 05 WS-B PIC 9(03) VALUE 200. 05 WS-C PIC 9(03). Code- ADD WS-A, WS-B TO WS-C ON SIZE ERROR DISPLAY "OVERFLOW" NOT ON SIZE ERROR DISPLAY "WS-C: " WS-C. Result- WS-C = 900
In the above case, the result is 900. So, the NOT ON SIZE ERROR phrase gets executed and displays the the result 900.