Skip to content

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:

  1. The Format 1 EXIT statement must be the only statement in the paragraph.
  2. The Format 1 EXIT statement performs no operation. Control passes to the next line of executable code in the currently running program.
  3. If the currently running program is a CALL’ed subroutine, the Format 2 EXIT PROGRAM statement terminates the execution of the subroutine, and returns control to the CALL’ing program on the next instruction after the CALL statement.
  4. In a Format 2 EXIT PROGRAM [RETURNING] identifier-1 statement, the RETURNING phrase is optional.
  5. The Format 2 EXIT PROGRAM [RETURNING] identifier-1 statement MOVE's identifier-1 to the special return code register, and then executes an EXIT PROGRAM statement.
  6. If the currently running program is not a CALL’ed subroutine, the Format 2 EXIT PROGRAM statement performs no operation. Control passes to the next line of executable code in the currently running program.
  7. When the Format 2 EXIT PROGRAM statement also contains a RETURNING clause, the value of numeric data 1 is assigned to the RETURN CODE register, where it can be accessed in the CALL’ing program.
  8. The Format 3 EXIT PARAGRAPH/EXIT SECTION statement causes control to be transferred to the next executable statement after the end of the current PARAGRAPH SECTION.
  9. The Format 4 EXIT PERFORM [CYCLE] statement causes control to be transferred to the point just before the matching END PERFORM. In PERFORM 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.
Back to top