[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
Reference Manual


Previous Contents Index

6.2.6.1 Conventions for Resolving Program-Name References

The PROGRAM-ID paragraph of the Identification Division declares the program-name; a user-defined word to identify the program. Only the CALL and CANCEL statements and the END PROGRAM header can reference a program-name.

A run unit can contain multiple programs with duplicated program-names. However, when two programs have duplicate program-names, one of the two programs must directly or indirectly be contained within a separately compiled program that does not contain the program with the duplicated program-name.

The following rules regulate the scope of program-name:

  1. Within a run unit, any separately compiled program can reference any other separately compiled program.
  2. If a program-name does not have the COMMON attribute and it is contained directly within another program, the contained program can be referenced only by statements included in the directly containing program.
    For example, in the run unit consisting of the three separately compiled programs illustrated in Example 6-3, Example 6-4, and Example 6-5:
    • MAIN-PROGRAM (See (1) in Example 6-3) directly contains program PROG-NAME-A (3) and indirectly contains PROG-NAME-B (5), PROG-NAME-C (6), PROG-NAME-D (7), and PROG-NAME-F (9).
    • PROG-NAME-B (See (11) in Example 6-4.)
    • PROG-NAME-E (See (12) in Example 6-5.)

    The CALL "PROG-NAME-B" statement in PROG-NAME-A (See (4) in Example 6-3.) references PROG-NAME-B (5) in the same separately compiled program (MAIN-PROGRAM) because PROG-NAME-B (5) is directly contained in PROG-NAME-A. All other CALL "PROG-NAME-B" statements ((2) and (8) and (10) in Example 6-3 and (13) in Example 6-5) all reference PROG-NAME-B (11) in Example 6-4, the second separately compiled program.

Example 6-3 Separately Compiled Program 1

  IDENTIFICATION DIVISION.
  PROGRAM-ID. MAIN-PROGRAM. (1)
  .
  .
  .
       CALL "PROG-NAME-B".  (2)
  .
  .
  .
  IDENTIFICATION DIVISION.
  PROGRAM-ID. PROG-NAME-A.  (3)
  .
  .
  .
       CALL "PROG-NAME-B".  (4)
  .
  .
  .
  IDENTIFICATION DIVISION.
  PROGRAM-ID. PROG-NAME-B.  (5)
  .
  .
  .
  IDENTIFICATION DIVISION.
  PROGRAM-ID. PROG-NAME-C.  (6)
  .
  .
  .
  IDENTIFICATION DIVISION.
  PROGRAM-ID. PROG-NAME-D.  (7)
  .
  .
  .
       CALL "PROG-NAME-B".  (8)
  .
  .
  .
  END PROGRAM PROG-NAME-D.
  END PROGRAM PROG-NAME-C.
  END PROGRAM PROG-NAME-B.
  .
  .
  .
  IDENTIFICATION DIVISION.
  PROGRAM-ID. PROG-NAME-F.  (9)
  .
  .
  .
       CALL "PROG-NAME-B".  (10)
  .
  .
  .
  END PROGRAM PROG-NAME-F.
  END PROGRAM PROG-NAME-A.
  END PROGRAM MAIN-PROGRAM.

Example 6-4 Separately Compiled Program 2

  IDENTIFICATION DIVISION.
  PROGRAM-ID. PROG-NAME-B.  (11)
  .
  .
  .

Example 6-5 Separately Compiled Program 3

  IDENTIFICATION DIVISION.
  PROGRAM-ID. PROG-NAME-E.  (12)
  .
  .
  .
       CALL "PROG-NAME-B".  (13)
  .
  .
  .
  1. If a program-name has the COMMON attribute and it is contained directly within another program, the contained program can be referenced only by the following:
    • Statements in the directly containing program
    • Statements in any programs, directly or indirectly contained within the directly containing program, except statements in the program with the COMMON attribute and in any program it directly or indirectly contains

    For example, in the run unit consisting of the three separately compiled programs illustrated in Example 6-6, Example 6-7, and Example 6-8:
    • MAIN-PROGRAM (see (1) in Example 6-6) directly contains PROG-NAME-A (3), and indirectly contains PROG-NAME-B (IS COMMON) (5), PROG-NAME-C (6), PROG-NAME-D (7), PROG-NAME-F (9), and PROG-NAME-G (11).
    • PROG-NAME-B (See (13) in Example 6-7.)
    • PROG-NAME-E (See (14) in Example 6-8.)

    The CALL "PROG-NAME-B" statement in PROG-NAME-A (See in Example 6-6) references PROG-NAME-B IS COMMON (5) because it is directly contained in PROG-NAME-A. The CALL "PROG-NAME-B" statement in PROG-NAME-F (See (10) in Example 6-6) references PROG-NAME-B IS COMMON (5) because PROG-NAME-F is directly contained in PROG-NAME-A. The CALL "PROG-NAME-B" statement in PROG-NAME-G (See (12) in Example 6-6) references PROG-NAME-B IS COMMON (5) because PROG-NAME-G is indirectly contained in PROG-NAME-A. The remaining CALL "PROG-NAME-B" statements ((2) and (8) in MAIN-PROGRAM and (15) in PROG-NAME-E) all reference the separately compiled program, PROG-NAME-B (13).

Example 6-6 Separately Compiled Program 1

  IDENTIFICATION DIVISION.
  PROGRAM-ID. MAIN-PROGRAM. (1)
  .
  .
  .
       CALL "PROG-NAME-B".  (2)
  .
  .
  .
  IDENTIFICATION DIVISION.
  PROGRAM-ID. PROG-NAME-A.  (3)
  .
  .
  .
       CALL "PROG-NAME-B".  (4)
  .
  .
  .
  IDENTIFICATION DIVISION.
  PROGRAM-ID. PROG-NAME-B IS COMMON. (5)
  .
  .
  .
  IDENTIFICATION DIVISION.
  PROGRAM-ID. PROG-NAME-C.  (6)
  .
  .
  .
  IDENTIFICATION DIVISION.
  PROGRAM-ID. PROG-NAME-D.  (7)
  .
  .
  .
       CALL "PROG-NAME-B".  (8)
  .
  .
  .
  END PROGRAM PROG-NAME-D.
  END PROGRAM PROG-NAME-C.
  END PROGRAM PROG-NAME-B.
  .
  .
  .
  IDENTIFICATION DIVISION.
  PROGRAM-ID. PROG-NAME-F.  (9)
  .
  .
  .
       CALL "PROG-NAME-B".  (10)
  .
  .
  .
  IDENTIFICATION DIVISION.
  PROGRAM-ID. PROG-NAME-G.  (11)
  .
  .
  .
       CALL "PROG-NAME-B".  (12)
  .
  .
  .
  END PROGRAM PROG-NAME-G.
  END PROGRAM PROG-NAME-F.
  END PROGRAM PROG-NAME-A.
  END PROGRAM MAIN-PROGRAM.

Example 6-7 Separately Compiled Program 2

  IDENTIFICATION DIVISION.
  PROGRAM-ID. PROG-NAME-B.  (13)
  .
  .
  .

Example 6-8 Separately Compiled Program 3

  IDENTIFICATION DIVISION.
  PROGRAM-ID. PROG-NAME-E.  (14)
  .
  .
  .
       CALL "PROG-NAME-B".  (15)
  .
  .
  .


Previous Next Contents Index