[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
Reference Manual


Previous Contents Index

6.2.6.2 Conventions for Resolving Other References

When a source program declares condition-names, data-names, file-names, record-names, report-names, and segmented-key-names, only the declaring source program can reference these names. The only exception is when names have the GLOBAL attribute and the program contains other programs.

For example, when a program such as PROG-NAME-A (See (1) in Example 6-9) contains other programs (PROG-NAME-B (10) and PROG-NAME-C (25)), each program can define the same user-defined word. When such duplicated names are referenced, the rules for qualification of names (see Section 6.2.1) apply; and, if necessary, the following three hierarchical rules resolve any ambiguity:

  1. References in a program to names defined in that program are resolved within the program. For example:
    • The following names: (2), (3), (4), and (5) are both defined and referenced within PROG-NAME-A.
    • The following names: (11), (12), (13), (14), and (15) are both defined and referenced within PROG-NAME-B.
    • The following names: (26) and (27) are both defined and referenced within PROG-NAME-C.
  2. A program cannot reference any condition-name, data-name, file-name, record-name, or report-name defined in a program it contains. For example, statements in PROG-NAME-A (See (6), (7), (8), and (9)) cannot reference items in either PROG-NAME-B or PROG-NAME-C. Statements in PROG-NAME-B (see (16) through (24)) cannot reference items in PROG-NAME-C.
  3. If a program contains another program, any GLOBAL names defined in the containing program can be referenced by the following:
    • Statements in a directly contained program, provided that the directly containing program does not declare the same user-defined word, in which case, rule 1 applies. For example, compare the Procedure Division statement MOVE EXAMPLE1 ... (21) with MOVE EXAMPLE2 ...(22) in the same contained program.
    • Statements in an indirectly contained program, provided that neither the indirectly containing program nor any program in between declare the same name as a GLOBAL name. For example, compare the Procedure Division statement MOVE EXAMPLE3 ...(29) with MOVE EXAMPLE2 ...(28) in the same contained program.

Example 6-9 Resolving References to Miscellaneous Names

     IDENTIFICATION DIVISION.
     PROGRAM-ID. PROG-NAME-A.      (1)
     DATA DIVISION.
     FILE SECTION.
     FD    FILE-NAME ...(2)
     01    RECORD-NAME ...(3)
     FD    GLOBAL-FILE-NAME... IS GLOBAL...
      WORKING-STORAGE SECTION.
     01    EXAMPLE1 ... IS GLOBAL...
     01    EXAMPLE2 ... IS GLOBAL...
     01    EXAMPLE3 ... IS GLOBAL...
     01    SWITCH-STATUS.          (4)
           88 ON   VALUE IS "1".
           88 OFF  VALUE IS "0".
     01    DATA-NAME ...(5)
     PROCEDURE DIVISION.
          MOVE DATA-NAME TO ...(6)
          IF SWITCH-STATUS IS ON ...(7)
          MOVE RECORD-NAME TO ...(8)
          OPEN INPUT FILE-NAME ...(9)


     IDENTIFICATION DIVISION.
     PROGRAM-ID. PROG-NAME-B.      (10)
     DATA DIVISION.
     FILE SECTION.
     FD    FILE-NAME ...(11)
     01    RECORD-NAME ...(12)
     WORKING-STORAGE SECTION.
     01    SWITCH-STATUS.          (13)
           88 ON   VALUE IS "1".
           88 OFF  VALUE IS "0".
     01    DATA-NAME ...(14)
     01    EXAMPLE2 ...(15)
     01    EXAMPLE3 ... IS GLOBAL...
     01    EXAMPLE4 ... IS GLOBAL...
     PROCEDURE DIVISION.
          MOVE DATA-NAME TO ...(16)
          IF SWITCH-STATUS IS ON ...(17)
          MOVE RECORD-NAME TO ...(18)
          OPEN INPUT FILE-NAME ...(19)
          OPEN OUTPUT GLOBAL-FILE-NAME.      (20)
          MOVE EXAMPLE1 ...(21)
          MOVE EXAMPLE2 ...(22)
          MOVE EXAMPLE3 ...(23)
          MOVE EXAMPLE4 ...(24)


     IDENTIFICATION DIVISION.
     PROGRAM-ID. PROG-NAME-C.   (25)
     WORKING-STORAGE SECTION.
     01    EXAMPLE2 ...(26)
     01    EXAMPLE4 ...(27)
     PROCEDURE DIVISION.
          OPEN OUTPUT GLOBAL-FILE-NAME.
          MOVE EXAMPLE1 ...
          MOVE EXAMPLE2 ...(28)
          MOVE EXAMPLE3 ...(29)
          MOVE EXAMPLE4 ...

END PROGRAM PROG-NAME-C.
END PROGRAM PROG-NAME-B.
END PROGRAM PROG-NAME-A.

If a data item possesses either or both the EXTERNAL or GLOBAL attributes and includes a table defining an index-name, that index-name also possesses either or both attributes.

If the file associated with a segmented key possesses either or both the EXTERNAL or GLOBAL attributes, that segmented key also possesses either or both attributes.

6.2.7 External and Internal Data

External data is associated with a run unit. Any program in the run unit describing the external data can reference that data. (See the Section 5.3.21 clause in Chapter 5.) There is only one representation of an external data object.

Internal data is associated with a specific program.

External and internal data can have global names. (See the Section 5.3.25 clause in Chapter 5.)

6.3 Explicit and Implicit Specifications

The four types of explicit and implicit specifications follow:

  • Procedure Division references
  • Control transfers
  • Attributes
  • Scope terminators

6.3.1 Explicit and Implicit Procedure Division References

A source program can refer to data items explicitly or implicitly in Procedure Division statements.

An explicit reference occurs when the name of the item is in a Procedure Division statement or copied into the Procedure Division by a COPY statement.

An implicit reference occurs under the following conditions:

  • When a Procedure Division statement refers to an item whose name does not appear in the statement.
  • During PERFORM statement execution. The PERFORM statement's control mechanism can initialize, change, and evaluate an index or data item referred to in the VARYING, AFTER, and UNTIL phrases. These implicit references occur only if the PERFORM statement execution involves the data item.

6.3.2 Explicit and Implicit Control Transfers

The mechanism that controls program flow implicitly transfers control from one statement to another in the order in which the statements appear in the source program. The transfer occurs in this sequence unless an explicit control transfer overrides it, or there is no next executable statement.

A program can contain both explicit and implicit changes to the control transfer mechanism.

Implicit control transfer can also occur when normal program flow changes without executing a procedure-branching statement. For example:

  • A paragraph can execute under the control of another COBOL statement (such as PERFORM, USE, SORT, and MERGE). If the paragraph is the last in the controlling statement's range, an implied control transfer occurs from the last statement in the paragraph to the controlling statement's control mechanism.
    An implicit control transfer occurs between the control mechanism of a PERFORM statement that causes iterative execution and the first paragraph in its range. The transfer occurs for each iterative execution of the paragraph.
  • When a SORT or MERGE statement executes, an implicit control transfer occurs to associated input or output procedures.
  • When the execution of a statement causes the execution of a Declaratives Section, the control transfer is implicit. Another implicit control transfer occurs after execution of the Declaratives Section.
  • If the Procedure Division does not have any Declaratives Sections, the program's first executable statement is the first executable statement in the Procedure Division. Otherwise, the program's first executable statement is the first executable statement after the declaratives part of the Procedure Division.

An explicit control transfer is a change to the implicit control transfer mechanism caused only by execution of either:

  • A procedure-branching statement
  • A conditional statement

The EXIT procedure-branching statement causes an explicit control transfer only when it has the PROGRAM phrase.

The Procedure Branching statement ALTER does not cause an explicit control transfer. However, it affects the explicit control transfer of the associated GO TO statement.

The term next executable statement refers to the next COBOL statement to which control transfers according to these rules and those associated with each language element.

There is no next executable statement when the program has no Procedure Division. This is also the case after:

  • The last statement in a Declaratives Section, when the paragraph in which it appears is not executing under the control of another COBOL statement
  • The last statement in a program, when the paragraph in which it appears is not executing under the control of another COBOL statement
  • A STOP RUN or EXIT PROGRAM statement, when execution control transfers outside of the COBOL program containing the statement
  • An END PROGRAM header

When there is no next executable statement and control does not transfer out of the program, program control flow is undefined. However, an EXIT PROGRAM statement implicitly executes when the program is under the control of a CALL statement.


Previous Next Contents Index