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.
- The prime RECORD KEY itself
- Any ALTERNATE RECORD KEY
- An alphanumeric data item within a record description for the file with
a leftmost character position that corresponds to the leftmost character position
of the key field in the record area. This data item must be less than or
equal to the length of the record key for the file.
This data item can be qualified or reference modified. If the key itself is not used, the leftmost character position plus the reference modification starting position must correspond to the leftmost character position of the key field.
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.
- The reserved word EXTERNALLY-DESCRIBED-KEY can be specified. This indicates that the complete key in the record area should be used in the comparison.
- A series of data names can be specified. This allows a partial key field
in the record area to be used (generic START). These data names must follow
the following rules:
- All except the last of the data names specified must be a record key for a single format that was copied in for the file. The record format in which they are contained does not have to be the one that can be specified by the FORMAT phrase.
- The order of these data names (key fields) must match the order of the keys as defined in DDS; that is, they must be specified from most significant field to least significant.
- The total number of data names cannot exceed the number of key fields defined for that record format.
- If the last data name specified in the series is not a key field in the record area, it must have its left byte occupy the same space as the key field that is defined at that relative position. If the key field in the record area at this position is a COMP, COMP-3, COMP-4, or COMP-5 field, only the key field itself can be used as the data name.
- Only the last key can be reference modified, and the reference modification starting position must equal 1.
- Table 1 shows the action between the KEY IS phrase and the FORMAT phrase:
| 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.
- data-name-1
- Can be any of the following:
- The prime RECORD KEY.
- An alphanumeric data item within a record description for a file whose leftmost character position corresponds to the leftmost character position of that record key; it may be qualified. The data item must be less than or equal to the length of the record key for the file.
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.
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