Several of the I/O statements can take an optional AT END phrase and NOT AT END phrase. Both of these phrases are followed by a statement that is conditionally executed, depending on the result of the I/O statement. The discussion of each I/O statement that can take the AT END phrase specifies the conditions that cause the at-end condition to be in effect. If the at-end condition is in effect, one of the following happens:

  1. If the AT END phrase is present, the statement it contains is executed; otherwise
  2. If an appropriate Declarative section exists, it is executed; otherwise
  3. The program prints a message and halts. Note, however, that the runtime can be configured to ignore the error and keep running. See the configuration variables ERRORS_OK and EOF_ABORTS in Appendix H for more information. See also the additional information on ERRORS_OK in File Handling Options in the ACUCOBOL-GT User's Guide.

If the NOT AT END phrase is present, it is executed if the I/O statement is successful. Note that it is possible to execute neither the AT END nor NOT AT END phrases if an I/O error occurs that does not set the at-end condition. In this case, the AT END phrase is not executed (because the at-end condition is not in effect) and the NOT AT END phrase does not execute (because the I/O statement is not successful).

All of the preceding comments about the AT END and NOT AT END phrases also apply to the INVALID KEY and NOT INVALID KEY phrases (except that the invalid-key condition is tested instead of the at-end condition).