Ending an ILE COBOL Program

An ILE COBOL program can be ended by the following:
  • A ILE COBOL statement (EXIT PROGRAM, STOP RUN, or GOBACK)
  • A reply to an inquiry message
  • An implicit STOP RUN or EXIT PROGRAM statement
  • Another ILE language's equivalent of the ILE COBOL STOP RUN statement. For example, ILE C's exit() function.
  • Another ILE language's equivalent of the ILE COBOL abnormal STOP RUN statement. For example, ILE C's abort() function.
  • An escape message that is sent past the calling ILE COBOL program by the called ILE procedure or program object.
  • Ending, by the called ILE procedure or program object, of the activation group in which the calling ILE COBOL program is running.

A STOP RUN statement is implied when a main ILE COBOL program has no next executable statement (implicit EXIT PROGRAM for a ILE COBOL subprogram), that is, when processing falls through the last statement of a program.

Inquiry messages can be issued in response to a ILE COBOL statement (namely a STOP literal), but they are usually issued when a severe error occurs in a program, or when a ILE COBOL operation does not complete successfully. (Examples are LNR7205, LNR7207, and LNR7208.) Inquiry messages allow you to determine what action to take after an exception error has occurred.

There are four common replies to a COBOL inquiry message: C, D, F, and G (cancel, cancel and dump, cancel and full dump, continue). The first three cause (as their final steps) an implicit abnormal STOP RUN.

An implicit or explicit STOP RUN statement, or a GOBACK statement in the main ILE COBOL program, causes the termination-imminent condition to be signalled to the nearest control boundary. The termination-imminent condition can be handled in two ways:
  • Through a registered error handler before it reached the control boundary, or
    Note: To register an exception handler, use the Register a User-Written Condition Handler (CEEHDLR) bindable API. Refer to ILE Concepts for more information on exception handlers.
  • If it reached the control boundary, then all programs after the control boundary are ended, and control returns to the program before the control boundary.
If this control boundary is a hard control boundary, then the activation group (run unit) will end.

If the STOP RUN is abnormal and a hard control boundary is reached, the CEE9901 escape message is issued to the program before the control boundary.