Explicit and Implicit Transfers of Control COBOL

The mechanism that controls program flow transfers control from statement to statement in the sequence in which they were written in the source program unless an explicit transfer of control overrides this sequence or there is no next executable statement to which control can be passed.The transfer of control from statement to statement occurs without the writing of an explicit Procedure Division statement, and, therefore, is an implicit transfer of control.

RM/COBOL provides both explicit and implicit means of altering the implicit control transfer mechanism.

In addition to the implicit transfer 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.

RM/COBOL provides the following types of implicit control flow alterations that override the statement-to-statement transfers of control:

  • If a paragraph is being executed under control of another statement (PERFORM, USE, SORT or MERGE), and the paragraph 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 last-executed controlling statement.
  • If a paragraph is being executed under the control of a PERFORM statement that causes iterative execution, and that paragraph is the first paragraph in the range of that PERFORM statement, animplicit transfer of control occurs between the control mechanism associated with that PERFORM statement and the first statement in that paragraph for each iterative execution of the paragraph.
  • When a SORT or MERGE statement is executed, an implicit transfer of control occurs to any associated input or output procedures.
  • When any statement is executed that results in the execution of a declarative section, an implicit transfer of control to the declarative section occurs.Note that another implicit transfer of control occurs after execution of the declarative back to the statement that caused the execution of the declarative.

An explicit transfer of control consists of an alteration of the implicit control transfer mechanism by the execution of a procedure branching or conditional statement.An explicit transfer of control can be caused only by the execution of a procedure branching or conditional statement.The execution of the procedure branching ALTER statement does not in itself constitute an explicit transfer of control, but affects the explicit transfer of control that occurs when the associated GO TO statement is executed.The procedure branching statement EXIT PROGRAM causes an explicit transfer of control only when the statement is executed in a called program.

The term “next executable statement” refers to the next statement to which control is transferred according to the rules above and the rules associated with each language element in the Procedure Division.

There is no next executable statement 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 statement.
  • 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.
  • The last statement in a program when the paragraph in which it appears is not being executed under the control of some other statement in that program.
  • A STOP RUN statement or EXIT PROGRAM statement that transfers control outside the program.
  • The end program header.

There is also no next executable statement when the program contains no Procedure Division.

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



Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

COBOL Topics