The EXIT statement provides a common end point for a series of procedures.
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.
You can also return values to activating run-time system elements written in any language.
The EXIT METHOD statement marks the logical end of an invoked method.
The EXIT FUNCTION statement marks the logical end of the execution of a function.
General Formats for Format 1
General Formats for Format 2
General Formats for Format 4
General Formats for Format 6
Syntax Rules for Format 2
- A Format 2 EXIT statement can be used only within an inline PERFORM.
Syntax Rules for Format 5
- An EXIT METHOD statement may be specified only in a method Procedure Division.
Syntax Rules for Format 6
- An EXIT FUNCTION statement must be specified only in a function Procedure Division.
Syntax Rules for Formats 4, 5 and 6
- The EXIT statement must not be specified in a declarative procedure for which the GLOBAL phrase is specified in the associated
USE statement.
Syntax Rules for Format 7
- EXIT ITERATOR may only be specified in the context of an Iterator. See
Iterator-ID.
General Rules for Format 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 .
General Rules for Format 2
- 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.
- 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.
General Rules for Format3
- 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.
- 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
- 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.
- 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.
- 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.
- 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.
- 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.
- The RETURNING clause cannot return an object reference.
General Rules for Format 5
- 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.
General Rules for Format 6
- 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.