The names used in nested programs may be classified as "local" and "global" names.
Local names
Local names are valid only within the program in which the associated data is described. Most of the names that are local as standard can be declared as global. The following names are always local:
paragraph-names
section-names
Global names
Global names are valid not only in the program in which they are defined but also in that program’s contained programs.
The following name types are always global:
Names defined in the CONFIGURATION SECTION:
computer-name
alphabet-names
class-names
condition-names (SPECIAL NAMES paragraph)
mnemonic-names
symbolic characters
CURRENCY SIGN character
DECIMAL-POINTCOBOL special registers:
TALLY
PRINT-SWITCH
SORT registers
RETURN-CODE
The following name types are local as standard and can be explicitly defined as global in nested programs:
condition-names
data-names
file-names
index-names
record-names
report-names
type-names
Definition of a name as global is performed using the GLOBAL clause (see section "GLOBAL clause" of chapter "File description" and section "GLOBAL clause" of chapter "Data description entry").
In the case of type names the GLOBAL phrase refers to the definition of the type and not to the data description generated with the aid of the type definition.
Determining the valid name
When a name is referenced, the valid name is selected from the sum total of all the names defined in the nested program, in accordance with the following rules of precedence:
The referenced name is defined in the same program.
If 1) does not apply, the referenced name is defined as a global name in the directly superordinate (next outer) program.
If neither 1) nor 2) applies, the referenced name is defined as a global name in the indirectly superordinate program.
Condition 3) is checked until the data description entry of the referenced name is found in one of the other indirectly superordinate programs, possibly in the outermost containing program.
Example 12-6
Example 12-7
PROGRAM-ID. A-PROG. ... 01 T1 TYPEDEF STRONG GLOBAL. 02 NAME PIC X(30). 02 STREET PIC X(80). ... 01 A1 TYPE T1. 1) 01 B1 TYPE T1 GLOBAL. ... PROGRAM-ID. B-PROG. ... 01 T1 TYPEDEF STRONG. 2) 02 SUBSTRUKTUR. 05 NAME-3 PIC X(30). 05 STREET-3 PIC X(80). ... 01 C1 TYPE T1. 3) ... MOVE B1 TO C1. 4) ... END PROGRAM B-PROG. END PROGRAM A-PROG.
- Uses type definition T1 from A-PROG;
Definition A1 is local in A-Prog, definition B1 is global - Type T1 is local in B-PROG
- Uses type definition T1 from B-PROG
- Allocation is permissible as T1 in A-PROG is equivalent to T1 in B-PROG