COBOL Manual for TNS and TNS/R Programs
Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs—522555-006
9-187
READ for Sequential or Dynamic Access
•
GUARDIAN-ERR Special Register
The GUARDIAN-ERR special register is updated each time a file-manipulating
statement is executed. The value of GUARDIAN-ERR usually provides more
specific information about the cause of an unsuccessful completion signaled by the
file-status data item. For example, if the file status is “30” (permanent error),
GUARDIAN-ERR contains the file system error number identifying the cause. See
Diagnosing Input-Output Errors.
•
Handling Exception Conditions
The READ statement enables you to specify explicitly that when an at-end
condition occurs, a particular statement is to be executed.
For general exception handling, a group of statements called declaratives can be
placed at the beginning of the Procedure Division to respond to error conditions
arising for a single file or for all files open in the same input mode (INPUT,
OUTPUT, I-O, or EXTEND). See USE AFTER EXCEPTION.
The USE AFTER EXCEPTION statement specifies what to do when a file-
manipulating statement encounters an exception condition. Declaratives can be
called for at-end, invalid key, and other exception conditions.
If, for example, the program includes a USE statement referring to the file being
read, and a read operation is attempted when no next logical record exists, then
the process executes either an AT END phrase or the USE statement:
°
If an AT END phrase is present, it is executed.
°
If no AT END phrase is present, the USE statement is executed.
If a READ operation encounters a recoverable permanent error (Status Key 1
equals 3, or Status Key 1 equals 9 but Status Key 2 does not equal 7), no at-end
condition occurs; however, if a declarative is present for the file, that declarative is
activated, then any NOT AT END phrase is executed. Either the declarative or the
NOT AT END phrase can then determine the nature of the error (usually by
checking GUARDIAN-ERR) and take appropriate action. See Recovering from
Input-Output Errors.
After an at-end condition for a sequentially accessed file (other than $RECEIVE),
you must close and reopen or reposition the file before any further operations can
be done on it. You can reposition the file with the START statement, the routine
COBOL85^REWIND or COBOL_REWIND_.