Choosing inline or out-of-line PERFORM
An inline PERFORM
is an imperative statement
that is executed in the normal flow of a program; an out-of-line PERFORM
entails
a branch to a named paragraph and an implicit return from that paragraph.
About this task
To determine whether to code an inline or out-of-line PERFORM
statement,
answer the following questions:
- Is the
PERFORM
statement used in several places?Use an out-of-line
PERFORM
when you want to use the same portion of code in several places in your program. - Which placement of the statement will be easier to read?
If the code to be performed is short, an inline
PERFORM
can be easier to read. But if the code extends over several screens, the logical flow of the program might be clearer if you use an out-of-linePERFORM
. (Each paragraph in structured programming should perform one logical function, however.) - What are the efficiency tradeoffs?
An inline
PERFORM
avoids the overhead of branching that occurs with an out-of-linePERFORM
. But even out-of-linePERFORM
coding can improve code optimization, so efficiency gains should not be overemphasized.
In the 1974 COBOL standard, the PERFORM
statement
is out-of-line and thus requires a branch to a separate procedure
and an implicit return. If the performed procedure is in the subsequent
sequential flow of your program, it is also executed in that logic
flow. To avoid this additional execution, place the procedure outside
the normal sequential flow (for example, after the GOBACK
)
or code a branch around it.
The subject of an
inline PERFORM
is an imperative statement. Therefore,
you must code statements (other than imperative statements) within
an inline PERFORM
with explicit scope terminators.