Compaq COBOL
Reference Manual


Previous Contents Index

6.2.4 Identifiers

In Procedure Division rules, the term identifier means the complete specification of a data item. The term refers to all words required to make your reference to the item unique.

To reference a data item that is a function, a function-identifier is used. For information on functions, see Chapter 7.

The general formats for identifiers are as follows:


For more information on the methods of uniquely specifying data items, see the following:

6.2.5 Ensuring Unique Condition-Names

If the name you use as a condition-name appears in more than one place in your program, it can be made unique through qualification, indexing, or subscripting. Your condition-name also is unique when the scope of names conventions by themselves ensure this as described in Section 6.2.6, Scope of Names.

The first qualifier for a condition-name can be the name of the item with which it is associated (the conditional variable). When qualifying condition-names, you must use the name of the conditional variable itself or the names of items that contain it.

References to a condition-name must have the same combination of subscripting or indexing that you use for the conditional variable.

The formats you use to ensure unique condition-names are the same as those used for an identifier, except condition-name replaces data-name.

In Procedure Division rules the term condition-name refers to a condition-name along with any qualification and subscripting or indexing needed to avoid ambiguity.

6.2.6 Scope of Names

A contained COBOL program can refer to a user-defined word in its containing program if the user-defined word has the global attribute. (See Section 1.2.1.1 in Section 1.2.1.) Some user-defined words always have the global attribute, some never have the attribute (that is, they are local), and some might or might not, depending on the use of the GLOBAL clause. The following rules explain how to use different kinds of user-defined words and what kinds of local and global name scoping to expect.

  1. The following types of user-defined words are always local and can be referenced only by statements and entries in the program declaring them:
  2. These user-defined words are always local when you define them in the Report Section. Only those statements and entries in the program containing the entries can reference them:
  3. The following user-defined word is always local when you define it in the Screen Section. Only those statements and entries in the program containing the entries can reference it:
  4. Because you cannot specify a Configuration Section for a program contained within another program, the following types of user-defined words are always global when declared in the Configuration Section. You can reference them only by statements and entries either in the program that contains the Configuration Section or in any program contained within that program:
  5. The following user-defined words are global if you specify the GLOBAL clause:

Specific conventions for declarations and references apply to these types of user-defined words whenever the previous conditions do not apply.

Whenever duplicate names exist, a program always references the resource in its own program. If the resource is not in the referencing program, the following two conventions are used:

The next two sections describe these conventions.

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:
    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:

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:

The CALL "PROG-NAME-B" statement in PROG-NAME-A (See (4) 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)
  .
  .
  .

6.2.6.1 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:
  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:

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:

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:

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:

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

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:

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.

6.3.3 Explicit and Implicit Attributes

An explicit attribute is an attribute the program explicitly specifies. If the program does not explicitly specify an attribute, the attribute assumes a default; it is then an implicit attribute.

For example, a program need not specify USAGE for a data item. If it does not, the data item's implicit usage is DISPLAY.


Previous Next Contents Index