The ON SIZE ERROR Phrase

The ON SIZE ERROR phrase of the ADD, SUBTRACT, MULTIPLY, DIVIDE, and COMPUTE statement will:
  • Enable binary and decimal overflow messages to be issued. The binary and decimal overflow message is MCH1210. The decimal division by zero message is MCH1211.
  • Register a condition handler to catch the binary, decimal, and floating-point overflow messages, as well as other arithmetic MCH messages. Floating-point overflow messages include MCH1206 (overflow) and MCH1207 (underflow).

    Unlike binary and decimal overflow messages, floating-point overflow is not enabled by the existence of an ON SIZE ERROR phrase. Floating-point overflow is enabled or disabled at the job level. By default, floating-point overflow messages are always issued. Thus, ILE COBOL will ignore these messages, except when an ON SIZE ERROR phrase is coded. To enable or disable floating-point overflow, see the section Handling Errors in Floating-Point Computations.

ILE COBOL registers the above mentioned condition handler at priority level 85. A user condition handler, which is registered at priority level 165, will only receive control if the above mentioned condition handler does not handle the exception.

When no ON SIZE ERROR phrase is coded, the binary and decimal overflow messages will not be issued, and floating-point overflow messages will be ignored. All other arithmetic MCH messages will typically be handled by the function check condition handler unless a user condition handler has been registered using the CEEHDLR API.

A size error condition occurs in the following situations:
  • The result of the arithmetic operation is larger than the fixed-point field that is to hold it
  • Division by zero
  • Zero raised to the zero power
  • Zero raised to a negative number
  • A negative number raised to a fractional power
  • Floating-point overflow or underflow.

During arithmetic operations, typical errors are size errors (MCH1210) and decimal data errors (MCH1202). Most MCH errors are not directly detected by ILE COBOL; they are detected by the operating system and result in system messages. ILE COBOL then monitors for these messages, setting internal bits that determine whether to run a SIZE ERROR imperative statement or issue a runtime message (LNR7200) to end the program.

To prevent the LNR7200 message from being sent, a user condition handler can be registered using the CEEHDLR API to handle the MCH messages or an ILE COBOL error handler can be coded using the COBOL bindable APIs to handle the LNR72xx inquiry messages.

ILE COBOL does detect errors that result from division by zero during an arithmetic operation. If detected by ILE COBOL, these errors cause the SIZE ERROR imperative statement to run.

System message MCH1210 generally occurs when moving one binary or decimal numeric field to another, and the receiver is too small. This error is monitored by ILE COBOL, and also results in the running of the SIZE ERROR imperative statement.

LNR7200 is a run-time message that is usually issued when an unmonitored severe error occurs in your ILE COBOL program.

System message MCH1202 is a typical example of an unmonitored severe error. This kind of error results in the ILE COBOL run-time message LNR7200 (or LNR7204 if the error occurs in a program called by a ILE COBOL program). System messages MCH3601 and MCH0601 are other examples of unmonitored severe errors.