COBOL Manual for TNS and TNS/R Programs
Disk Input and Output
HP COBOL Manual for TNS and TNS/R Programs—522555-006
28-21
Key of Reference
Topics:
•
Key of Reference
•
Alternate Record Keys
•
Positioning
•
Repositioning to New Record With Same Alternate Key
Key of Reference
COBOL defines the “key of reference” as “the prime or alternate key currently being
used to access records within an indexed file.” HP COBOL extends that definition to
“the prime or alternate key currently being used to access records within an indexed or
relative file, or the alternate key currently being used to access records in an entry-
sequenced file.”
Enscribe uses the term “access path” for the sequence of records accessed by the key
of reference.
You establish the key of reference by executing a START statement or a READ
statement containing a KEY phrase. In a START statement, the key can specify the
identifier of an entire key field or the identifier of a leftmost subordinate of the key field.
For example, in the record in Example 28-10, if LAST-NAME, DEPARTMENT-
NUMBER, and JOB-TITLE are alternate keys, you can use LN5, LN10, LN15, DN3,
and J-T-PORTION as keys.
Example 28-10. Key of Reference
01 PERSONNEL-REC.
03 NAME-FIELDS.
05 LAST-NAME.
07 LN1ST. PIC X.
07 LN2ND. PIC X.
...
07 LN25TH. PIC X.
05 FIRST-NAME PIC X(25).
05 M-I-NAME PIC X.
03 DEPARTMENT-NUMBER PIC 9999.
03 DN REDEFINES DEPARTMENT-NUMBER.
05 DN3 PIC 999.
05 FILLER PIC X.
03 JOB-TITLE.
05 J-T-PORTION.
07 J-T PIC X OCCURS 1 TO 25 TIMES
DEPENDING ON J-T-LENGTH.
66 LN5 RENAMES LN1ST THRU LN5TH.
66 LN10 RENAMES LN1ST THRU LN10TH.
66 LN15 RENAMES LN1ST THRU LN15TH.