Scope of Names

117 Views


This section contains a brief description of the types of COBOL names, followed by the rules for name scoping.

Types of Names

alphabet-name

An alphabet-name assigns a name to a specific character set and/or collating sequence in the SPECIAL-NAMES paragraph of the Environment Division.

class-name

A class-name assigns a name to the preposition in the SPECIAL-NAMES paragraph of the Environment Division for which a truth value can be defined.

condition-name

A condition-name associates a value with a conditional variable. constant-name A constant-name identifies a constant, which is defined in the data division.

data-name

A data-name names a data item. file-name A file-name names a file connector. index-name An index-name names an index associated with a specific table.

library-name

A library-name names a COBOL library that is to be used by the compiler for a given source program compilation.

mnemonic-name

A mnemonic-name assigns a user-defined word to an implementer-name.

paragraph-name

A paragraph-name names a paragraph in the Procedure Division.

program-name

A program-name names a program, either external or internal (nested).

record-name

A record-name names a record. section-name A section-name names a section in the Procedure Division.

symbolic-character

A symbolic-character specifies a user-defined figurative constant.

text-name

A text-name names a library containing source members to be used by the COPY directive statements.

 

Nested Programs

A COBOL program may contain other COBOL programs. The contained (or nested) programs may themselves contain yet other programs. A contained program may be directly or indirectly contained within a program.

Figure describes a program structure with directly and indirectly contained programs.

The same user-defined word may be used in different programs to define different objects. In a particular program, a reference to an object always refers to the object defined in that program.

 

Global and Local Names

Names can have global or local attributes. Some names are always global; other names are always local; and some names are either local or global depending upon specifications in the program in which the names are declared.

A program cannot reference any condition-name, data-name, file-name, index-name, paragraph-name, record-name, section-name, or type-name declared in any program it contains.

A global name may be used to refer to the object with which it is associated either from within the program in which the global name is declared or from within any other program which is contained in the program which declares the global name.

A local name, however, may be used only to refer to the object with which it is associated from within the program in which the local name is declared.

If a data-name, record-name, condition-name, type-name, or file-name is not declared to be global, the name is local.

Note: Specific rules sometimes prohibit specification of the GLOBAL clause for certain data description, file description, or record description entries.

constant-name

A constant-name is global if the GLOBAL clause is specified.

data-name

A data-name is global if the GLOBAL clause is specified either in the data description entry by which the data-name is declared or in another entry to which that data description entry is subordinate.

file-name

A file-name is global if the GLOBAL clause is specified in the file description entry for that file-name.

Two programs in a run unit can reference common file connectors in the following circumstances:

1. An external file connector can be referenced from any program that describes that file connector.

2. If a program is contained within another program, both programs can refer to a common file connector by referring to an associated global file-name declared either in the containing program or in any program that directly or indirectly contains the containing program.

record-name

A record-name is global if the GLOBAL clause is specified in the record description entry by which the record-name is declared or, in the case of record description entries in the File Section, if the GLOBAL clause is specified in the file description entry for the file-name associated with the record description entry.

condition-name

A condition-name, when declared in the data description entry, is global if that entry is subordinate to another entry in which the GLOBAL clause is specified. A condition-name, when declared within the Configuration Section, is always global. program-name A program-name is neither local nor global.

section-name and paragraph-name

These names are always local. library-name and text-name These names are external to the program and can be referenced by any COBOL program, provided that the compiler system supports the associated library and the entities referenced are known to that system.

alphabet-name

An alphabet-name is always global. class-name A class-name is always global.

mnemonic-name

A mnemonic-name is always global.

index-name

If a data item possessing the global attribute includes a table accessed with an index, that index also possesses the global attribute. Therefore, the scope of an index-name is identical to that of the data-name which names the table whose index is named by that index-name and the scope of name rules for data-names apply. Index-names cannot be qualified.

type-name

A type name is global if the GLOBAL clause is specified in the data description entry by which the type-name is declared. The GLOBAL attribute of a type-name is restricted to the type-name, and is not acquired by a data item that is defined using the type-name in a TYPE clause.

 

External and Internal Objects

Accessible data items usually require that certain representations of data be stored. File connectors usually require that certain information concerning files be stored. The storage associated with a data item or a file connector may be external or internal to the program in which the object is declared.

A data item or file connector is external if the storage associated with that object is associated with the run unit rather than with any particular program within the run unit.

An external object may be referenced by any program in the run unit which describes the object. References to an external object from different programs using separate descriptions of the object with the same name are always to the same object.

In a run unit, there is only one representative of an external object. An object is internal if the storage associated with that object is associated only with the program which describes the object.

External and internal objects may have either global or local names.

A data record described in the Working-Storage Section is given the external attribute by the presence of the EXTERNAL clause in its data description entry.

Data Attribute Specification

Explicit data attributes are those you specify in actual COBOL coding.

Implicit data attributes are default values. If you do not explicitly code a data attribute, the compiler assumes a default value.
For example, you need not specify the USAGE of a data item. If it is omitted, the default is USAGE DISPLAY, which is the implicit data attribute. If, however, you specify USAGE DISPLAY in COBOL coding, it becomes an explicit data attribute.

Conventions for Program-Names

The program-name of a program is specified in the PROGRAM-ID paragraph of the program's Identification Division. A program-name can be referenced only by the:

  • CALL statement
  • CANCEL statement
  • END PROGRAM header
  • SET statement

Rules Regulating the Scope of Program Names

The following rules apply to referencing a program-name of a program that is contained within another program. For this discussion, we will say that Program-A directly contains Program-B and Program-C, Program-C directly contains Program-D and Program-F, and Program-D directly contains Program-E.

If Program-D does not possess the COMMON attribute, then Program-D can only be referenced by the program that directly contains Program-D, that is, Program-C.

If Program-D does possess the COMMON attribute, then Program-D can be referenced by Program-C since it contains Program-D, and by any programs contained in Program-C except for Program-D and programs contained in Program-D. In other words, if Program-D possesses the COMMON attribute, Program-D can be referenced in Program-C and Program-F, but not by statements in Program-E, Program-A, Program-B, or Program-D.

 

Post Comments