Resolution of names
The rules for resolution of names depend on whether the names are specified in a program or in a class definition.
Names within programs
When a program, program B, is directly contained within another program, program A, both programs can define a condition-name, a data-name, a file-name, or a record-name using the same user-defined word. When such a duplicated name is referenced in program B, the following steps determine the referenced resource (these rules also apply to classes and contained methods):
- The referenced resource is identified from the set of all names that are defined in program B and all global names defined in program A and in any programs that directly or indirectly contain program A. The normal rules for qualification and any other rules for uniqueness of reference are applied to this set of names until one or more resources is identified.
- If only one resource is identified, it is the referenced resource.
- If more than one resource is identified, no more than one resource
can have a name local to program B. If zero or one of the resources
has a name local to program B, the following rules apply:
- If the name is declared in program B, the resource in program B is the referenced resource.
- If the name is not declared in program B, the referenced resource
is:
- The resource in program A if the name is declared in program A
- The resource in the containing program if the name is declared in the program that contains program A
This rule is applied to further containing programs until a valid resource is found.
Names within a class definition
Within a class definition, resources can be defined within the following units:
- The factory data division
- The object data division
- A method data division
If a resource is defined with a given name in the DATA DIVISION of an object definition, and there is no resource defined with the same name in an instance method of that object definition, a reference to that name from an instance method is a reference to the resource in the object DATA DIVISION.
If a resource is defined with a given name in the DATA DIVISION of a factory definition, and there is no resource defined with the same name in a factory method of that factory definition, a reference to that name from a factory method is a reference to the resource in the factory data division.
If a resource is defined within a method, any reference within the method to that resource name is always a reference to the resource in the method.
The normal rules for qualification and uniqueness of reference apply when the same name is associated with more than one resource within a given method data division, object data division, or factory data division.