Use the READ statement to retrieve records from a file. To read a record, you must have opened the file with OPEN INPUT or OPEN I-O (OPEN I-O is not valid for line-sequential files). Check the file status key after each READ.
Records in sequential and line-sequential files can be retrieved only in the sequence in which they were written.
Records in indexed and relative record files can be retrieved sequentially (according to the ascending order of the key you are using for indexed files, or according to ascending relative record locations for relative files), randomly, or dynamically.
With dynamic access, you can switch between reading a specific record directly and reading records sequentially by using READ NEXT and READ PREVIOUS for sequential retrieval, and READ for random retrieval (by key).
When you want to read sequentially beginning at a specific record, use START before the READ NEXT or the READ PREVIOUS statement to set the file position indicator to point to a particular record. When you code START followed by READ NEXT, the next record is read and the file position indicator is reset to the next record. When you code START followed by READ PREVIOUS, the previous record is read and the file position indicator is reset to the previous record. You can move the file position indicator randomly by using START, but all reading is done sequentially from that point.
You can continue to read records sequentially, or you can use the START statement to move the file position indicator. For example:
START file-name KEY IS EQUAL TO ALTERNATE-RECORD-KEY
When a direct READ is performed for an indexed file based on an alternate index for which duplicates exist, only the first record in the file (base cluster) with that alternate key value is retrieved. You need a series of READ NEXT statements to retrieve each of the data set records with the same alternate key. A file status value of 02 is returned if there are more records with the same alternate key value to be read. A value of 00 is returned when the last record with that key value has been read.
related concepts
Sequential access
Random access
Dynamic access
File organization and access mode
related tasks
Opening a file
Using file status keys
related references
File position indicator
FILE STATUS clause
(COBOL for Windows Language Reference)