EXIT Statement
The EXIT
statement provides an end point within a PERFORM
statement, PARAGRAPH
, SECTION
, or PROGRAM
. When EXIT
'ing a PROGRAM
, control is returned to the calling program.
Format 1
EXIT
Format 2
EXIT PROGRAM {RETURNING} [identifier-1]
Format 3
EXIT {PARAGRAPH}
{SECTION }
Format 4
EXIT PERFORM [ CYCLE ]
Syntax:
Identifier-n
is a numeric or alphanumeric literal, or data item.
General Rules:
- The Format 1
EXIT
statement must be the only statement in the paragraph. - The Format 1
EXIT
statement performs no operation. Control passes to the next line of executable code in the currently running program. - If the currently running program is a
CALL
’ed subroutine, the Format 2EXIT PROGRAM
statement terminates the execution of the subroutine, and returns control to theCALL
’ing program on the next instruction after theCALL
statement. - In a Format 2
EXIT PROGRAM [RETURNING] identifier-1
statement, theRETURNING
phrase is optional. - The Format 2
EXIT PROGRAM [RETURNING] identifier-1
statementMOVE
'sidentifier-1
to the special return code register, and then executes anEXIT PROGRAM
statement. - If the currently running program is not a
CALL
’ed subroutine, the Format 2EXIT PROGRAM
statement performs no operation. Control passes to the next line of executable code in the currently running program. - When the Format 2
EXIT PROGRAM
statement also contains aRETURNING
clause, the value of numeric data 1 is assigned to theRETURN CODE
register, where it can be accessed in theCALL
’ing program. - The Format 3
EXIT PARAGRAPH
/EXIT SECTION
statement causes control to be transferred to the next executable statement after the end of the currentPARAGRAPH SECTION
. - The Format 4
EXIT PERFORM [CYCLE]
statement causes control to be transferred to the point just before the matchingEND PERFORM
. InPERFORM
loops with tests, this will allow for the next logical test to take place.
Code Sample:
IDENTIFICATION DIVISION.
PROGRAM-ID. EXIT-1.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 RTN-CODE PIC 9 VALUE 1.
77 DUMMY PIC X.
PROCEDURE DIVISION.
MAIN.
*FORMAT 1
* EXIT
*FORMAT 2
* EXIT PROGRAM [ RETURNING NUMERIC-ITEM ]
*FORMAT 3
* EXIT {PARAGRAPH}
* {SECTION }
*FORMAT 4
* EXIT PERFORM [ CYCLE ]
DISPLAY "EXIT-1 FINISHED!" LINE 11 COL 10.
ACCEPT DUMMY LINE 11 COL 30.
STOP RUN.
EXIT-THE-PROGRAM.
EXIT.
EXIT-PGM-RETURNING.
EXIT PROGRAM RETURNING RTN-CODE.
EXIT-PARA.
EXIT PARAGRAPH.
EXIT SECTION.
EXIT-SECT.
EXIT SECTION.
EXIT-PFRM.
PERFORM FOREVER
IF RTN-CODE = 1
EXIT PERFORM CYCLE
END-IF
END-PERFORM.