PERFORM return mechanism
There is a difference in the way CMPR2 and NOCMPR2 handle out-of-line PERFORM statements that might require corrective action.
When a paragraph or a range of paragraphs is executed with a PERFORM statement ("out-of-line PERFORM"), a mechanism at the end of the range of paragraphs causes control to be returned to the point just after the PERFORM statement.
PERFORM A
STOP RUN.
A. DISPLAY "Hi".
B. DISPLAY "there".
After displaying the message "Hi," compiler-generated code will cause the flow of control to return to the STOP RUN statement after performing paragraph A. Without this, control would fall through into paragraph B.
This code mechanism is reset to an initial state the first time a program is called or when a program is cancelled. Under NOCMPR2, it is also reset every time a program is called. Under CMPR2, the mechanism retains its last-used state when a program is called twice in succession without having been cancelled. This can be important when the program issues an EXIT PROGRAM or GOBACK statement before all of the PERFORM statements have completed their execution.
IF FIRST-TIME-CALLED THEN
PERFORM A
MOVE ZERO TO N
ELSE
SUBTRACT 1 FROM N
GO TO A.
GOBACK.
A. IF N > 1 THEN
GOBACK.
B. DISPLAY "Processing continues...".
The program is passed a switch, FIRST-TIME-CALLED, which tells the program whether or not the program has been called without having been cancelled. It is also passed a variable, N.