GLOBAL clause
The GLOBAL clause specifies that a data-name or a constant-name is available to every program contained within the program that defines it, as long as the contained program does not itself have a definition for that name. All data-names or constant-names subordinate to or condition-names or indexes associated with a global name are global names.
A data-name or a constant-name is global if the GLOBAL clause is specified either in the data description entry by which the data-name or the constant-name is defined or in another entry to which that data description entry is subordinate. The GLOBAL clause can be specified in the WORKING-STORAGE SECTION, the FILE SECTION, the LINKAGE SECTION, and the LOCAL-STORAGE SECTION, but only in data description entries whose level-number is 01.
In the same DATA DIVISION, the data description entries for any two data items for which the same data-name or constant-name is specified must not include the GLOBAL clause.
A statement in a program contained directly or indirectly within a program that describes a global name can reference that name without describing it again.
If the TYPEDEF clause is specified with the GLOBAL clause, the scope of the GLOBAL clause applies to the type-name, and to any data items subordinate to the type-name. The global attribute is not acquired by a data item that is defined by using a global type-name within a TYPE clause.
Two programs in a run unit can reference common data in the following circumstances:
- The data content of an external data record can be referenced from any program that describes the data record as external.
- If a program is contained within another program, both programs can refer to data that possesses the global attribute either in the containing program or in any program that directly or indirectly contains the containing program.