COBOL Manual for TNS and TNS/R Programs

Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs522555-006
9-185
READ for Sequential or Dynamic Access
The execution of a START statement establishes a subset of the file’s records that
can be retrieved by subsequent sequential or dynamic READ statements. If the
current statement is one in a sequence of such READ statements executed after a
START statement for the same file (without the execution of an OPEN, START, or
Random READ having intervened), then the record (if any) selected for retrieval by
the preceding rules is tested to determine whether it is a member of the file subset
established by the START statement. If it is not, then the record is disqualified and
the effect is the same as if no record had been selected.
If the read operation is successful, the record selected by the file position indicator
is retrieved and placed into the record area associated with the file.
If the file is a multiple-reel tape file, and the end-of-reel condition occurs during the
retrieval operation, the run-time routines perform a reel-swap sequence, and the
first record of the next reel is retrieved. (For information on the reel-swap
sequence, see OPEN.) If there is no next reel, the at-end condition exists. In this
case, the read operation terminates, and execution of the READ statement is
unsuccessful.
The at-end condition exists because one of these conditions is true:
°
The file is present but there is no record at the position specified by the file
position indicator (such as the position immediately beyond the last record in
the file).
°
The file has an OPTIONAL phrase in its SELECT clause and, although open, is
not actually present.
°
The START GENERIC reached the end of a set of duplicates.
If the at-end condition exists, the read operation terminates, and execution of the
READ statement is unsuccessful.
When the at-end condition exists, the I-O status code of the read operation is set to
“10.” If the AT END phrase is specified, control passes to the imperative statement
in that phrase, and no USE procedure is executed. If neither the AT END nor the
NOT AT END phrase is specified, and an applicable USE procedure exists, that
procedure is executed.
Relative Key Data Item of Relative Files
A successful execution of the READ statement for a relative file also assigns the
relative record number of the retrieved record to the file’s relative key data item if
the file description defines one. The relative key data item is optional for relative
files being accessed sequentially.