Previous | Contents | Index |
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:
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.
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.
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:
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) . . . |
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) . . . |
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:
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:
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:
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 |