The EXIT Statement

The EXIT statement provides a common end point for a series of procedures.

MFThe EXIT statement can also exit an inline PERFORM, a paragraph or a section.

The EXIT PROGRAM statement marks the logical end of a called program.

MFYou can also return values to activating runtime elements written in any language.

ISO2002MFThe EXIT METHOD statement marks the logical end of an invoked method.

ISO2002The EXIT FUNCTION statement marks the logical end of the execution of a function.

General Formats
Format 1

MFFormat 2

MF

MFFormat 3

MF

Format 4

ISO2002MFFormat 5

ISO2002MF

ISO2002Format 6

ISO2002

Syntax Rules
    Format 1
  1. The EXIT statement should appear in a sentence by itself.

    VSC2MFThis rule is not enforced.

  2. The EXIT sentence should be the only sentence in the paragraph.

    VSC2MFThis rule is not enforced.

  3. MFFormat 2
  4. MFA Format 2 EXIT statement can be used only within an inline PERFORM.
  5. Format 4
  6. If an EXIT PROGRAM statement appears in a consecutive sequence of imperative statements within a sentence, it must appear as the last statement in that sequence.

    VSC2MFThis rule is not enforced.

  7. There must be no sentence other than the EXIT PROGRAM sentence in the paragraph.

    ANS85This rule is not enforced.

  8. MFInteger-1 may be signed.
  9. MFGIVING and RETURNING are equivalent.
  10. MFIf the ADDRESS OF clause is not specified, identifier-1 must be no larger than 8 bytes in size.
  11. ISO2002MFFormat 5
  12. ISO2002MFAn EXIT METHOD statement may be specified only in a method Procedure Division.
  13. ISO2002Format 6
  14. ISO2002An EXIT FUNCTION statement must be specified only in a function Procedure Division.
  15. Formats 4, 5 and 6
  16. The EXIT statement must not be specified in a declarative procedure for which the GLOBAL phrase is specified in the associated USE statement.
General Rules
    Format 1
  1. An EXIT statement serves only to enable you to assign a procedure-name to a given point in a Procedure Division. Such an EXIT statement has no other effect on the compilation or execution .
  2. MFFormat 2
  3. MFThe execution of an EXIT PERFORM statement without a CYCLE phrase causes control to be passed to an implicit CONTINUE statement, immediately following the END-PERFORM associated with the nearest inline PERFORM statement.
  4. MFThe execution of an EXIT PERFORM statement with a CYCLE phrase causes control to be passed to an implicit CONTINUE statement, immediately preceding the END-PERFORM associated with the nearest inline PERFORM statement.
  5. MFFormat 3
  6. MFThe execution of a Format 3 EXIT statement with the PARAGRAPH phrase causes control to pass to an implicit CONTINUE statement immediately following the last statement in the paragraph.
  7. MFThe execution of a Format 3 EXIT statement with the SECTION phrase causes control to pass to an implicit CONTINUE statement immediately following the last statement in the last paragraph in the topic.
  8. Format 4
  9. ANS85If the EXIT PROGRAM statement is executed in a program which is not under the control of a calling runtime element, the EXIT PROGRAM statement causes execution of the program to continue with the next executable statement.
  10. ANS85The execution of an EXIT PROGRAM statement in a called program which does not possess the initial attribute causes execution to continue with the next executable statement following the CALL statement in the calling runtime element. The state of the calling runtime element is not altered and is identical to that which existed at the time it executed the CALL statement except that the contents of data items and the contents of data files shared between the calling and called runtime elements may have been changed. The program state of the called program is not altered except that the ends of the ranges of all PERFORM statements executed by that called program are considered to have been reached.
  11. ANS85Besides the actions specified in General Rule 7, the execution of an EXIT PROGRAM statement in a called program which possesses the initial attribute is equivalent to also executing a CANCEL statement referencing that program except that the statement does not free any memory. See the topic The CANCEL Statement in the chapter Procedure Division - ACCEPT - DIVIDE.
  12. ANS85An EXIT PROGRAM statement must not be executed while executing a declarative procedure in which the GLOBAL phrase is specified except in a program called while executing that declarative procedure.
  13. MFExecution of an EXIT PROGRAM statement in a program that is under the control of a calling runtime element, causes a return value to be set in the system area generally available for non-COBOL programs to return a value. This system area is never smaller than 4 bytes in size but may be larger in some environments.

    If the GIVING phrase is not specified and the calling convention specifies updating the RETURN-CODE special-register (see the rules for the CALL CONVENTION clause in the topic The Special-Names Paragraph) then the object program operates as if the system area were declared as a COBOL numeric data item with USAGE COMP-5 and with a size determined by the operating environment external to the COBOL system and as if a MOVE statement had been executed with the RETURN-CODE as the sending item and the system area as the receiving item. (See the topic Special Registers in the chapter Concepts of the COBOL Language for details of RETURN-CODE.)

    If the GIVING ADDRESS OF phrase is specified, the object program operates as if the system area were declared as a COBOL data item with USAGE POINTER and as if a SET statement had been executed with TO ADDRESS OF identifier-1 as the first operand and the system area as the second operand. The ADDRESS OF phrase may be used to indirectly pass a value that is larger than the system area.

    If the GIVING identifier-1 phrase is specified, identifier-1 must describe the same number of character positions as is required to hold the return value in the system area and must be of the type and usage that is expected by the calling runtime element. The object program operates as if a MOVE statement had been executed with identifier-1 as the sending item and the system area as the receiving item.

    If the GIVING integer-1 phrase is specified, integer-1 must not be larger than the value that can be held in the system area. The object program operates as if the system area were declared as a COBOL numeric data item with USAGE COMP-5 and with a size determined by the operating environment external to the COBOL system and as if a MOVE statement had been executed with integer-1 as the sending item and the system area as the receiving item.

  14. ISO2002MFFormat 5
  15. ISO2002MFThe execution of an EXIT METHOD statement causes the executing method to terminate, and control to return to the invoking statement. If a RETURNING phrase is present in the containing method definition, the value in the data item referenced by the RETURNING phrase becomes the result of the method invocation.
  16. ISO2002Format 6
  17. ISO2002The execution of an EXIT FUNCTION causes the executing function to terminate, and control to return to the activating statement. The value in the data item referenced by the RETURNING phrase in the containing function definition becomes the result of the function activation.