COBOL Manual for TNS/E Programs (H06.08+, J06.03+)
These rules regulate the scope of a program-name:
• If the program-name, X, is that of a program that does not have the common attribute and is
directly contained within another program, Y, then only statements included in Y can refer to
X.
• If the program-name, V, is that of a program that does have the common attribute and is
directly contained within another program, W, then any programs directly or indirectly
contained within W can reference V; however, program V and any programs contained within
V cannot refer to V (because V calling V is recursion, and because V cannot cancel itself).
• If the program-name, U, is that of a separately compiled program, then U can be referenced
by statements included in any other program in the run unit, except programs it directly or
indirectly contains. HP COBOL programs that are compiled at the same time but separated
by the ENDUNIT directive or by an END PROGRAM statement are called separately compiled,
as if they had been compiled by different executions of the compiler.
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 (page 63).
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.
50 Source Program Organization and Format










