Download Digital Cobol Reference Manual

Transcript
READ Statement
When the READ statement detects one of the above conditions, not including
the no valid next record condition:
•
It updates the FILE STATUS data item for the file to indicate the at end
condition.
•
If the READ statement has an AT END phrase, control transfers to
stment. No USE AFTER EXCEPTION procedure for the file executes.
•
If there is no AT END phrase, a USE AFTER EXCEPTION procedure
must be associated with the file. Control transfers to that procedure.
Control returns from the USE AFTER EXCEPTION procedure to the next
executable statement after the end of the READ statement.
When the at end condition occurs, execution of the READ statement is
unsuccessful.
11. After the unsuccessful execution of a READ statement, the contents of the
file’s record area are undefined. If an optional file is not present, the File
Position Indicator is unchanged; otherwise, it indicates that no valid next
record has been established. For indexed files, the Key of Reference is
undefined.
12. READ PRIOR retrieves a record from an Indexed file which logically precedes
the one which was made current by the previous file access operation, if such
a logically previous record exists.
13. For a relative or indexed file in dynamic access mode, a Format 1 READ
statement with the NEXT phrase retrieves the file’s next logical record. For
an indexed file, when the Key of Reference has ascending sort order, the next
logical record is the next record with a key value equal to or greater than the
previous key value. When the Key of Reference has descending sort order, the
next logical record is the next record with a key value equal to or less than
the previous key value.
14. For a relative file, a Format 1 READ statement updates the contents of the
file’s RELATIVE KEY data item. The data item contains the relative record
number of the available record.
15. For a relative file, a Format 2 READ statement sets the File Position
Indicator to the record whose relative record number is in the file’s
RELATIVE KEY data item. Execution then continues as specified in General
Rule 3.
If the record is not in the file, the invalid key condition exists, and READ
statement execution is unsuccessful.
16. When your program sequentially accesses an indexed file for records with
duplicate record key values in the Key of Reference, those records are made
available to your program in the same order in which they were created.
The duplicate values can be created by execution of WRITE or REWRITE
statements.
17. For an indexed file, a Format 2 READ statement with the KEY phrase
establishes key-name as the Key of Reference for the retrieval. For a dynamic
access mode file, the same Key of Reference applies to later retrievals by
Format 1 READ statement executions for the file. The Key of Reference
continues in effect until a new Key of Reference is established.
Procedure Division 6–189