The EXIT Statement

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

MF The 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.

MF You can also return values to activating run-time system elements written in any language.

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

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

General Formats for Format 1


Syntax for General Formats for Format 1 for the EXIT statement

MF 

General Formats for Format 2


Syntax for General Formats for Format 2 for the EXIT statement

ISO2002MF 

General Formats for Format 3


Syntax for General Formats for Format 3 for the EXIT statement

General Formats for Format 4


Syntax for General Formats for Format 4 for the EXIT statement

ISO2002MF 

General Formats for Format 5


Syntax for General Formats for Format 5 for the EXIT statement

ISO2002 

General Formats for Format 6


Syntax for General Formats for Format 6 for the EXIT statement

NETJVM 

General Formats for Format 7

Syntax for General Formats for Format 7 for the EXIT statement

Syntax Rules for Format 1

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

    VSC2MF This rule is not enforced.

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

    VSC2MF This rule is not enforced.

MF 

Syntax Rules for Format 2

  1. MF A Format 2 EXIT statement can be used only within an inline PERFORM.

Syntax Rules for Format4

  1. 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.

    VSC2MF This rule is not enforced.

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

    ANS85 This rule is not enforced.

  3. MF Integer-1 may be signed.
  4. MF GIVING and RETURNING are equivalent.
  5. MF  Identifier-1 must be no larger than 8 bytes in size.
ISO2002MF 

Syntax Rules for Format 5

  1. ISO2002MF An EXIT METHOD statement may be specified only in a method Procedure Division.
ISO2002 

Syntax Rules for Format 6

  1. ISO2002 An EXIT FUNCTION statement must be specified only in a function Procedure Division.

Syntax Rules for Formats 4, 5 and 6

  1. The EXIT statement must not be specified in a declarative procedure for which the GLOBAL phrase is specified in the associated USE statement.
NETJVM 

Syntax Rules for Format 7

  1. NETJVM EXIT ITERATOR may only be specified in the context of an Iterator. See Iterator-ID.

General Rules for 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 .
MF 

General Rules for Format 2

  1. MF The 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.
  2. MF The 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.
MF 

General Rules for Format3

  1. MF The 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.
  2. MF The execution of an EXIT SECTION statement causes control to be passed to an unnamed empty paragraph immediately following the last paragraph of the current section, preceding any return mechanisms for that section.

General Rules for Format 4

  1. ANS85 If the EXIT PROGRAM statement is executed in a program which is not under the control of a calling run-time system element, the EXIT PROGRAM statement causes execution of the program to continue with the next executable statement.
  2. ANS85 The 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 run-time system element. The state of the calling run-time system 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 run-time system 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.
  3. ANS85 Besides 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.
  4. ANS85 An 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.
  5. MF Execution of an EXIT PROGRAM statement in a program that is under the control of a calling run-time system 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-2 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 run-time system 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.

    When compiling procedural COBOL code to .NET COBOL, if there is no RETURNING phrase on the PROCEDURE DIVISION header, the Compiler generates a method that returns a 32 or 64-bit integer depending on the setting of the RTNCODE-SIZE directive. Statements of the form EXIT PROGRAM RETURNING identifier-1 attempt to convert identier-1 into the correct integer type, according to the rules of the MOVE statement, before returning the value to the calling program.

ISO2002MF 

General Rules for Format 5

  1. ISO2002MF The 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.
ISO2002 

General Rules for Format 6

  1. ISO2002 The 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.