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
EXITstatement must be the only statement in the paragraph. - The Format 1
EXITstatement 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 PROGRAMstatement terminates the execution of the subroutine, and returns control to theCALL’ing program on the next instruction after theCALLstatement. - In a Format 2
EXIT PROGRAM [RETURNING] identifier-1statement, theRETURNINGphrase is optional. - The Format 2
EXIT PROGRAM [RETURNING] identifier-1statementMOVE'sidentifier-1to the special return code register, and then executes anEXIT PROGRAMstatement. - If the currently running program is not a
CALL’ed subroutine, the Format 2EXIT PROGRAMstatement performs no operation. Control passes to the next line of executable code in the currently running program. - When the Format 2
EXIT PROGRAMstatement also contains aRETURNINGclause, the value of numeric data 1 is assigned to theRETURN CODEregister, where it can be accessed in theCALL’ing program. - The Format 3
EXIT PARAGRAPH/EXIT SECTIONstatement 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. InPERFORMloops 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.