COBOL - EXIT Statement
The EXIT statement provides a common end point for a series of procedures. The COBOL EXIT statement is a terminating flow control verb.
Syntax:
The EXIT statement enables you to assign a procedure-name to a given point in a program.
The EXIT statement is treated as a CONTINUE statement. Any statements following the EXIT statement are executed.
If an EXIT paragraph is specified as the last paragraph in a series of
performed paragraphs (i.e., PERFORM THRU), then it identifies the end
of the series of performed paragraphs. When control reaches an EXIT paragraph and such a PERFORM THRU is active, control is transferred
back to the statement following the PERFORM THRU.
When control reaches an EXIT paragraph that is not the end of a range
of paragraphs governed by an active PERFORM THRU, control passes
through the EXIT statement to the first statement of the following
paragraph.
The EXIT statement is also useful as an exit point for a single
performed paragraph, as shown below:
PERFORM 1000-CALCULATE-TOTALS THRU 1000-EXIT.
.......
1000-CALCULATE-TOTALS.
ADD 1 TO TOTAL-NUMBER-EMPS.
IF EMP-SALARY LESS THAN 25000
GO TO 1000-EXIT.
ADD 1 TO EMPS-MAKING-25K-AND-UP.
IF EMP-SALARY LESS THAN 50000
GO TO 1000-EXIT.
ADD 1 TO EMPS-MAKING-50K-AND-UP.
IF EMP-SALARY LESS THAN 75000
GO TO 1000-EXIT.
ADD 1 TO EMPS-MAKING-75K-AND-UP.
1000-EXIT. EXIT. |
After control reaches 1000-EXIT, Control is transferred back to PERFORM statement and execute the statements after PERFORM statement(PERFORM 1000-CALCULATE-TOTALS THRU 1000-EXIT).
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!