Download Digital Cobol Reference Manual

Transcript
VALUE OF ID Clause
6.2 Uniqueness of Reference
Every user-defined name in a COBOL program names a resource. (See the
section on User-Defined Words in Section 1.2.1.) To use a resource, however, a
statement in a COBOL program must contain a reference that uniquely identifies
that resource. Qualification, reference modification, and subscripting or indexing
allow unique and unambiguous references to that resource. Qualified procedurenames allow uniqueness of reference to procedures, and qualified condition-names
allow uniqueness of reference to condition-names.
When you assign the same name in separate (contained) programs to two or
more occurrences of a resource, certain conventions apply that limit the scope of
names. Name scoping and scope of names are COBOL language terms that
describe the methods for resolving references to user-defined words in a contained
program environment. (See Section 6.2.6, Scope of Names.)
Some user-defined words can be made available to every program in the run unit.
(See the EXTERNAL clause in Chapter 5.) These words are called external data.
Other user-defined words can be made available to programs contained within
the program that defines that resource. (See the GLOBAL clause in Chapter 5.)
These words are called global data.
6.2.1 Qualification
A reference to a user-defined word is unique if one or more of the following
conditions exists:
•
No other name has the same spelling, including hyphenation.
•
It is part of a REDEFINES clause. (The reference following the word
REDEFINES is unique because of the placement of the REDEFINES clause.)
See the Syntax Rules for the REDEFINES clause.
•
Scoping rules make it unique. (See Section 6.2.6, Scope of Names.)
A nonunique name within a hierarchy of names can be used in more than one
place in your program. Unless you are redefining it, you must refer to this
nonunique name using one or more higher-level names in the hierarchy. These
higher-level names are called qualifiers. Using them to achieve uniqueness of
reference is called qualification.
To make your reference unique, you need not specify all available qualifiers for a
name, only those necessary to eliminate ambiguity.
Consider the following two record descriptions:
01 REC1.
05 ITEMA
05 ITEMB
PIC XX.
PIC X(20).
01 REC2.
05 GROUP1.
10 ITEMA
10 ITEMB
05 GROUP2.
10 ITEMC
10 ITEMD
PIC 9(5).
PIC X(3).
PIC X(4).
PIC X(8).
ITEMA and ITEMB appear in both record descriptions. Therefore, you must
use qualifiers when you refer to these items in Procedure Division statements.
For example, all of the following references to ITEMA are unique: ITEMA OF
GROUP1, ITEMA OF REC1, ITEMA IN GROUP1 OF REC2.
Procedure Division 6–7