Indexed Files

Indexed files can be read from the following device types:
  • DISK
  • DATABASE

Indexed files can be read in sequential, random, or dynamic access modes.

When an indexed file is read in sequential access mode, the record made available by the READ statement is determined as follows:
  • If the file position indicator was set by the processing of a START or OPEN statement, the record pointed to is made available if it is still accessible through the path indicated by the current record pointer. If the record is no longer accessible (due, for example, to deletion of the record), the file position indicator is updated to indicate the next existing record in the file. That record is then made available.
  • If the file position indicator was set by the processing of a previous READ statement, the file position indicator is updated to point to the next existing record in the file. That record is then made available.
    IBM Extension

    For a file that allows duplicate keys (the DUPLICATES phrase is specified in the file-control entry), the records with duplicate key values are made available in the order specified when the file was created. The system options are first-in first-out (FIFO), last-in first-out (LIFO), and no specific sequence (if neither LIFO not FIFO is specified).

    End of IBM Extension

When an indexed file is read in random access mode, the record in the file with a key value equal to that of the current key of reference is then made available. If the file does not contain such a record, the INVALID KEY condition exists, and READ statement processing is unsuccessful. If the FORMAT phrase is not specified on the I-O statement when indexed files are read in random access mode, the first format defined in the file is used. Note that if externally described keys are being used and no format is specified, the first format included in the program is the one used to build the key. This format may not necessarily be the first format in the file.

If the KEY phrase is not specified, the prime RECORD KEY becomes the key of reference for this request. When dynamic access is specified, the prime RECORD KEY is also used as the key of reference for subsequent executions of sequential READ statements, until a different key of reference is established.

When the KEY phrase is specified, data-name-1 becomes the key of reference for this request. When dynamic access is specified, this key of reference is used for subsequent executions of sequential READ statements, until a different key of reference is established.

For a file that allows duplicate keys (the DUPLICATES phrase is specified in the file-control entry), the first record with the specified key value is made available. The first record is determined by the order specified when the file was created. The system options are first-in first-out (FIFO), last-in first-out (LIFO), and no specific sequence (if neither LIFO not FIFO is specified).

To enable file status 02 for DUPLICATE KEY checking, you need:
  • The WITH DUPLICATES phrase in the SELECT clause
  • OPEN I-O or OPEN INPUT
  • The *DUPKEYCHK option of the OPTION parameter, or the DUPKEYCHK option of the PROCESS statement.