COBOL Manual for TNS and TNS/R Programs
Source Program Organization and Format
HP COBOL Manual for TNS and TNS/R Programs—522555-006
2-13
Scope of User-Defined Names
Condition-Name, Data-Name, File-Name, and Record-Name
When condition-names, data-names, file-names, and record-names are declared in a
source program, only that program can refer to them except when one or more of the
names is global and the program contains other programs.
The requirements governing the uniqueness of the names allocated by a single
program as condition-names, data-names, file-names, and record-names are
explained in the topic COBOL Words.
A program cannot reference any condition-name, data-name, file-name, or record-
name declared in any program it contains.
A program P that declares a global name can reference that name. Any program
directly or indirectly contained in P can also reference the global name.
When program B is directly contained within program A, both programs can declare a
condition-name, data-name, file-name, or record-name using the same user-defined
word. When program B refers to such a duplicated name, the compiler uses this
sequence of rules to determine which object is being referenced:
•
The set of names the compiler uses to identify a referenced object consists of all
names that are defined in program B and all global names that are defined in
program A and in any programs that directly or indirectly contain program A. Using
this set of names, the compiler applies the normal rules of qualification and any
other rules for uniqueness of reference until it identifies one or more objects.
•
If the compiler identifies only one object, that object is the reference object.
•
If the compiler identifies more than one object, no more than one of them can have
a name local to program B. If zero or one of the objects has a name local to
program B, these rules apply:
°
If the name is declared in program B, the object in program B is the referenced
object.
°
If the name is not declared in program B, and if program A is directly contained
within another program, C, the referenced object is:
°
The object in program A if the name is declared in program A and is global.
°
The object in C if the name is not declared in program A or is not global in
A, and is declared in C and is global in C; otherwise, the compiler applies
this rule to further containing programs until it has found a single valid
name.