COBOL Manual for TNS/E Programs (H06.08+, J06.03+)
key
is the key of reference. If file-name specifies a relative file, key must be an alternate key
for that file. If file name specifies an indexed file, key can be the prime key or an alternate
key. If file-name specifies a queue file, key must be the prime key for that file. Unlike the
START statement, the KEY clause provides only APPROXIMATE positioning—not GENERIC
positioning.
When the KEY phrase is absent, the relative key (for a relative file) or the prime record key
(for an indexed or queue file) is established as the key of reference.
imperative-stmt-1
is an imperative statement to be performed when an invalid key is encountered at the beginning
of the READ. It is required if no USE statement is applicable for the file. If both a USE statement
and an INVALID KEY phrase are present, only the INVALID KEY phrase is used.
imperative-stmt-2
is an imperative statement to be performed when no invalid key is encountered at the beginning
of the read operation.
END-READ
ends the scope of the READ statement, causing the READ to be a delimited-scope statement. If
the READ statement does not end with an END-READ phrase, the presence of the INVALID KEY
or the NOT INVALID KEY phrase causes the READ statement to be a conditional statement,
which ends at the next period separator.
Usage Considerations:
• Action of the READ Statement (Read According to Key Value)
The execution of this form of the READ statement proceeds:
◦ For a file with indexed organization, or a file being accessed according to an alternate
key, the run-time routines set the file position indicator to the first record in the file with a
key data item value that matches the value in the key of reference. This record is then
made available in the file’s record area.
◦ For a file with relative organization being accessed according to the relative record
number, the run-time routines set the file position indicator to the record whose relative
record number is contained in the data item named in the RELATIVE KEY clause for the
file. This record is then made available in the file’s record area.
◦ In either case, if no such record exists in the file, the invalid-key condition exists, and the
read operation is unsuccessful.
A successful execution of the READ statement for a relative file, when the key of reference is
an alternate record key, also assigns the relative record number of the retrieved record to the
file’s relative key data item.
When the execution of the READ statement is successful and the access mode is dynamic, the
key of reference established for the read operation is used for subsequent sequential-type
READ statements executed for the same file until the execution of some other statement explicitly
establishes a different key of reference.
• File-Status Data Item
If the file has an associated file-status data item, execution of the READ statement always
assigns an appropriate I-O status code.
420 Procedure Division Verbs










