COBOL Manual for TNS and TNS/R Programs
Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs—522555-006
9-199
READ for Random or Dynamic Access
For other possible I-O status codes representing successful and unsuccessful
operations, see File-Status Data Item.
•
Key of Reference to Specify a Record
The program specifies which record is to be read by assigning the appropriate
value to the data item established as the key of reference, before the READ
statement is to be executed.
•
Handling Exception Conditions
For general exception handling, put declaratives at the beginning of the Procedure
Division. They can respond to error conditions arising for a single file or for all files
open in the same mode (INPUT, OUTPUT, I-O, or EXTEND). (See USE.)
The USE AFTER STANDARD ERROR PROCEDURE statement specifies what to
do when a file-manipulating statement encounters an error. Declaratives can be
called for AT END, INVALID KEY, and other error conditions.
If an invalid-key condition is encountered at the beginning of a read, and the READ
statement contains the INVALID KEY phrase, control passes to imperative-
stmt-1 and no USE procedure is executed. If the READ statement does not
contain an INVALID KEY phrase, but an applicable USE procedure exists, that
procedure is executed.
After an invalid-key condition arises for a relative, indexed, or queue file, sequential
read operatons cannot be done on the file until you either:
°
Close and reopen the file
°
Execute a successful START statement on the file
°
Execute a successful random READ statement on the file
•
Timed Input-Output Errors
If a READ statement includes the TIME LIMIT phrase, and the I-O request exceeds
the time interval indicated, the codes FILE STATUS 30 and GUARDIAN-ERR 40
are returned. For information about the special register GUARDIAN-ERR, see
Diagnosing Input-Output Errors.
Note. After an unsuccessful execution of a READ statement, these values are
unpredictable:
•
The value of the file position indicator
•
The contents of the current record area
•
The key of reference
Any key value found in the current record area: that is, the value of the current key for
indexed files or the value of the alternate key for any type of file-system file, because in
HP COBOL, sequential and relative files can have alternate keys.