EXIT Statement

The EXIT statement returns control to a calling program or provides a common logical end point for a series of procedures.

Format 1

EXIT

Format 2

EXIT PROGRAM [ {RETURNING} return-value ]
               {GIVING   }

Format 3

EXIT PERFORM [ CYCLE ]

Format 4

EXIT  {PARAGRAPH}
      {SECTION  }

Syntax Rules

  1. A Format 1 EXIT statement must be in a sentence by itself, and that sentence must be the only sentence in its paragraph.
  2. return-value must be a numeric literal or data item.
  3. An EXIT PERFORM statement must occur within the scope of an in-line PERFORM statement.
  4. An EXIT SECTION statement must be contained within a section.

Format 1 General Rules

A Format 1 EXIT statement associates a paragraph name with a point in the program. It has no effect on program execution. A paragraph containing a Format 1 EXIT statement is equivalent to an empty paragraph.

Format 2 General Rules

  1. An EXIT PROGRAM statement has no effect if executed in a program that is the first program of a thread or any program that was not called by another. Neither does it have any effect if it is executed within the scope of an EVENT procedure, unless the return point is also within the scope of the EVENT procedure.
  2. In a called program, the EXIT PROGRAM statement causes the current program to exit, and execution resumes at the next executable statement after the CALL statement in the calling program.
  3. If the exiting program has the initial attribute, it is immediately canceled. If it does not have the initial attribute, it retains its current state the next time it is called.
  4. If return-value is specified, then it is assigned to the special register RETURN-CODE before the program is exited. This special register is defined as:
    77  RETURN-CODE SIGNED-LONG, EXTERNAL.

    It is implicitly shared by all programs of a run unit and is automatically created by the compiler. The final value of RETURN-CODE is returned to the host operating system when the run unit completes. The compiler also creates an unsigned version of the return code called RETURN-UNSIGNED. It has the following implied definition:

      
    77  RETURN-UNSIGNED
              REDEFINES RETURN-CODE UNSIGNED-LONG, EXTERNAL.

Format 3 General Rules

  1. An EXIT PERFORM statement causes control to pass to a point just past the END-PERFORM that matches the innermost PERFORM statement containing the EXIT PERFORM. This causes the program to jump out of the innermost in-line PERFORM.
  2. If the CYCLE option is given, then control is passed to a point just prior to the matching END-PERFORM instead. For PERFORM constructs that imply looping, this will cause control to pass to the next iteration of the loop (note that the loop-terminating condition will be tested).

Format 4 General Rules

  1. An EXIT PARAGRAPH statement causes control to pass to an imaginary CONTINUE statement placed at the end of the current paragraph.
  2. An EXIT SECTION statement causes control to pass to an imaginary CONTINUE statement placed at the end of the last paragraph in the current section.