Basic PERFORM statement

The procedures referenced in the basic PERFORM statement are executed once, and control then passes to the next executable statement following the PERFORM statement.

Attention: Start of changeA PERFORM statement must not cause itself to be executed. This constitutes a recursive PERFORM, which can cause unpredictable results. Therefore, you must not specify recursive PERFORM statements.End of change

An in-line PERFORM statement functions according to the same general rules as an otherwise identical out-of-line PERFORM statement, except that statements contained within the in-line PERFORM are executed in place of the statements contained within the range of procedure-name-1 (through procedure-name-2, if specified). Unless specifically qualified by the word in-line or the word out-of-line, all the rules that apply to the out-of-line PERFORM statement also apply to the in-line PERFORM.

Whenever an out-of-line PERFORM statement is executed, control is transferred to the first statement of the procedure named procedure-name-1. Control is always returned to the statement following the PERFORM statement. The point from which this control is returned is determined as follows:

  • If procedure-name-1 is a paragraph name and procedure-name-2 is not specified, the return is made after the execution of the last statement of the procedure-name-1 paragraph.
  • If procedure-name-1 is a section name and procedure-name-2 is not specified, the return is made after the execution of the last statement of the last paragraph in the procedure-name-1 section.
  • If procedure-name-2 is specified and it is a paragraph name, the return is made after the execution of the last statement of the procedure-name-2 paragraph.
  • If procedure-name-2 is specified and it is a section name, the return is made after the execution of the last statement of the last paragraph in the procedure-name-2 section.

The only necessary relationship between procedure-name-1 and procedure-name-2 is that a consecutive sequence of operations is executed, beginning at the procedure named by procedure-name-1 and ending with the execution of the procedure named by procedure-name-2.

PERFORM statements can be specified within the performed procedure. If there are two or more logical paths to the return point, then procedure-name-2 can name a paragraph that consists only of an EXIT statement; all the paths to the return point must then lead to this paragraph.

When the performed procedures include another PERFORM statement, the sequence of procedures associated with the embedded PERFORM statement must be totally included in or totally excluded from the performed procedures of the first PERFORM statement. That is, an active PERFORM statement whose execution point begins within the range of performed procedures of another active PERFORM statement must not allow control to pass through the exit point of the other active PERFORM statement. However, two or more active PERFORM statements can have a common exit.

When control passes to the sequence of procedures by means other than a PERFORM statement, control passes through the exit point to the next executable statement, as if no PERFORM statement referred to these procedures.

The following figures illustrate valid sequences of execution for PERFORM statements.

Start of changeExample 1
This is example 1 that shows the first execution.
End of change
Start of changeThe output for example 1 looks like this:

OUTPUT:
Start PERFORM example1 
a                      
d                      
f                      
j                      
f                      
j                      
m                      
End   PERFORM example1 
End of change
Start of changeExample 2
This is example 2 that shows the second execution.
End of change
Start of changeThe output for example 2 looks like this:

OUTPUT:
Start PERFORM example2 
a                      
d                      
f                      
j                      
h                      
m
End   PERFORM example2
End of change
Start of changeExample 3
This is example 3 that shows the third execution.
End of change
Start of changeThe output of example 3 looks like this:

OUTPUT:
Start PERFORM example3 
a                      
f                      
m
End   PERFORM example3 
End of change
Start of changeExample 4
This is example 4 that shows the fourth execution.
End of change
Start of changeThe output for example 4 looks like this:

OUTPUT:
Start PERFORM example4 
a                      
d
j  
m
f
j
m
End   PERFORM example4 
End of change