COBOL Manual for TNS and TNS/R Programs
Procedure Division
HP COBOL Manual for TNS and TNS/R Programs—522555-006
8-19
Section Execution
COBOL provides these types of implicit transfers of control that override the statement-
to-statement mechanism:
1. When a paragraph is being executed under control of another COBOL statement
(for example, MERGE, PERFORM, SORT, and USE), and it is the last paragraph
in the range of the controlling statement, an implied transfer of control occurs from
the last statement in the paragraph to the control mechanism of the controlling
statement. If several controlling statements are active, the transfer is to the last
statement executed. Furthermore, if a paragraph is being executed under the
control of a PERFORM statement that causes iterative execution and that
paragraph is the first one in the range of the PERFORM statement, an implicit
transfer of control occurs between the control mechanism associated with the
PERFORM statement and the first executable statement in the paragraph for each
iterative execution of the paragraph.
2. When a SORT or MERGE statement is executed, an implicit transfer of control
occurs to any associated input or output procedures. Another implicit transfer of
control occurs after the execution of such a procedure, as described in Item 1.
3. When the execution of any COBOL statement causes the condition described in
the USE statement of a declarative section, an implicit transfer of control occurs to
that section. Another implicit transfer of control occurs after the execution of the
declarative section, as described in Item 1.
The statement-to-statement transfers of control ignore the existence of COPY,
REPLACE, and USE statements. Although control never passes to a USE statement
itself, the existence of a USE statement generates the control mechanism for implicit
transfers of control to and from the section in which it appears.
The term next executable statement refers to the next COBOL statement to which a
process is to transfer control according to the rules given previously and the rules
associated with each language element in the Procedure Division. There is no next
executable statement in these situations:
1. The execution of the last statement in a program does not cause an explicit
transfer of control, and the paragraph in which it appears is not being executed
under the control of some other COBOL statement. Following the execution of
such a statement, execution of the program terminates. When it is a called
program, control reverts to the calling program as if an EXIT PROGRAM statement
were executed; otherwise, execution of the run unit terminates as if a STOP RUN
statement were executed.
2. The program contains no Procedure Division. Execution of such a program
proceeds as if it contained a Procedure Division with a single paragraph consisting
of a CONTINUE statement. Control then passes from the program as described in
Item 1.
3. An EXIT PROGRAM statement is executed within a called program. In this case,
control reverts to the calling program.