COBOL - Scope of names



Desenvolvido por DORNELLES Carlos Alberto - Analista de Sistemas - Brasília DF. - cad_cobol@hotmail.com

COBOL - Structuring complex applications - Scope of names

Enterprise COBOL for z/OS, Version 4.2, Programming Guide


Names in nested structures are divided into two classes: local and global.
The class determines whether a name is known beyond the scope of the program that declares it.
A specific search sequence locates the declaration of a name after it is referenced in a program.

Local names

Names (except the program-name) are local unless declared to be otherwise.
Local names are visible or accessible only within the program in which they are declared.
They are not visible or accessible to contained and containing programs.

Global names

A name that is global (indicated by using the GLOBAL clause) is visible and accessible to the program in which it is declared and to all the programs that are directly and indirectly contained in that program.
Therefore, the contained programs can share common data and files from the containing program simply by referencing the names of the items.

Any item that is subordinate to a global item (including condition-names and indexes) is automatically global.

You can declare the same name with the GLOBAL clause more than one time, provided that each declaration occurs in a different program.
Be aware that you can mask, or hide, a name in a nested structure by having the same name occur in different programs in the same containing structure.
However, such masking could cause problems during a search for a name declaration.

Searches for name declarations

When a name is referenced in a program, a search is made to locate the declaration for that name.
The search begins in the program that contains the reference and continues outward to the containing programs until a match is found.
The search follows this process:

  1. Declarations in the program are searched.
  2. If no match is found, only global declarations are searched in successive outer containing programs.
  3. The search ends when the first matching name is found.
    If no match is found, an error exists.

The search is for a global name, not for a particular type of object associated with the name such as a data item or file connector.
The search stops when any match is found, regardless of the type of object.
If the object declared is of a different type than that expected, an error condition exists.


© Copyright IBM Corp.