ILE COBOL Language Reference

Indexed Files

When the KEY phrase is specified, the key data item used for the comparison is data-name.

When the KEY phrase is not specified, the file position indicator is set to the record with a key equal to the value contained in the RECORD KEY data item.

When START statement execution is successful, the RECORD KEY or ALTERNATE RECORD KEY with which data-name-1 is associated becomes the key of reference for subsequent READ statements.

When the KEY phrase is specified, the search argument used for the comparison is data-name-1, which can be:

Note:
If the RECORD KEY is defined as COMP, COMP-3, or COMP-4, the key data item must be the RECORD KEY itself. A partial key field in the record area cannot be used.

The file position indicator is positioned to the first record in the file with a record key for a format that satisfies the comparison. If the operands in the comparison are of unequal length, the comparison proceeds as if the longer field were truncated on the right to the length of the shorter field. All other numeric and nonnumeric comparison rules apply, except that the PROGRAM COLLATING SEQUENCE, if specified, has no effect.

+-------------------------------IBM Extension--------------------------------+

For a file that specified RECORD KEY IS EXTERNALLY-DESCRIBED-KEY, the following additional considerations apply:


Table 33. Relationship between KEY IS and FORMAT Phrases

FORMAT Phrase specified KEY Phrase
Data-Name Series Omitted EXTERNALLY-DESCRIBED-KEY
Yes A, B C, D C, B
No A, E F, G F, E

A
The search argument is built using the specified data items.

B
The file position indicator is set to the first record in the file of the format specified with a record key that satisfies the comparison specified in the key phrase.

C
The search argument is built using the key fields in the record area for the format specified in the FORMAT phrase.

D
The file position indicator is set to the first record in the file of the specified format with a record key equal to the search argument.

E
The file position indicator is set to the first record in the file with a common key for the file that satisfies the comparison specified in the KEY phrase. If there is no common key, the file position indicator is set to the first record in the file.

F
The search argument is built using the key fields in the record area for the first record format for the file as defined in the program.

G
The file position indicator is set to the first record in the file with a common key for the file that is equal to the search argument. If there is no common key, the file position indicator is set to the first record in the file.

+----------------------------End of IBM Extension----------------------------+

When the KEY phrase is not specified, the key data item used for the EQUAL TO comparison is the prime RECORD KEY.

data-name-1
Can be any of the following:

The file position indicator points to the first record in the file whose key field satisfies the comparison. If the operands in the comparison are of unequal lengths, the comparison proceeds as if the longer field were truncated on the right to the length of the shorter field. All other numeric and nonnumeric comparison rules apply, except that the PROGRAM COLLATING SEQUENCE clause, if specified, has no effect.

When START statement execution is successful, the RECORD KEY with which data-name-1 is associated becomes the key of reference for subsequent READ statements.

When START statement execution is unsuccessful, the key of reference is undefined.

+-------------------------------IBM Extension--------------------------------+

For indexed files of device type DATABASE, the meaning of the comparison can be affected by the type of key fields in the record area defined for the file. Key fields on this system can be defined as multiple fields, each of which can be in ascending or descending sequence. The system establishes a sequence (keyed sequence access path) for the records based on the values contained in the record key for the format and the sequencing specified in DDS. When a START statement is processed, the request is interpreted as follows:

COBOL Comparison System Result
GREATER THAN AFTER
NOT LESS THAN EQUAL TO or AFTER

For example, when a statement is processed using the comparison of GREATER THAN, a search is made of these sequenced records for the first record after the search argument specified by the START statement. If the file was sequenced using descending keys, the file position indicator would point to a record with a key less than the one specified and not greater than that specified in the START statement.

+----------------------------End of IBM Extension----------------------------+


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]