Transfer of Control

151 Views


In the Procedure Division, unless there is an explicit control transfer or there is no next executable statement, program flow transfers control from statement to statement in the order in which the statements are written. (See Note below.) This normal program flow is an implicit transfer of control.

In addition to the implicit transfers of control between consecutive statements, implicit transfer of control also occurs when the normal flow is altered without the execution of a procedure branching statement. The following examples show implicit transfers of control, overriding statement-to-statement transfer of control:

  • After execution of the last statement of a COBOL procedure being executed under control of another COBOL statement, control implicitly transfers. (COBOL statements that control COBOL procedure execution are, for example: MERGE, PERFORM, SORT, and USE.)
  • During SORT or MERGE statement execution, when control is implicitly transferred to an INPUT or OUTPUT procedure. During execution of any COBOL statement that causes execution of a declarative procedure, control is implicitly transferred to that procedure.
  • At the end of execution of any declarative procedure, control is implicitly transferred back to the control mechanism associated with the statement that caused its execution.
  • When a program that has no procedure division or any nondeclarative sections is called, the calling program issues an implicit EXIT PROGRAM.

COBOL provides explicit control transfers through the execution of any procedure branching or conditional statement.

 

Next Executable Statement

The term “next executable statement” refers to the next COBOL statement to which control is transferred, according to the rules given above. There is no next executable statement under these circumstances:

  • When the program contains no Procedure Division.
  • Following the last statement in a declarative section when the paragraph in which it appears is not being executed under the control of some other COBOL statement.
  • Following the last statement in a program when the paragraph in which it appears is not being executed under the control of some other COBOL statement in that program.
  • Following the last statement in a declarative section when the statement is in the range of an active PERFORM statement executed in a different section and this last statement of the declarative section is not also the last statement of the procedure that is the exit of the active PERFORM statement.
  • Following a STOP RUN, EXIT PROGRAM, or GOBACK statement that transfers control outside the COBOL program. Following the END PROGRAM header.

When there is no next executable statement and control isnot transferred outside the COBOL program, the program flow of control is undefined unless the program execution is in the nondeclarative procedures portion of a program under control of a CALL statement, in which case an implicit EXIT PROGRAM statement is executed.

Post Comments