ALTERNATE RECORD KEY

The ALTERNATE RECORD KEY clause specifies the data item within the record that is an alternate record key for an indexed file. These alternate keys allow the ILE COBOL program to access the file using a different logical ordering of the file records.

Read syntax diagramSkip visual syntax diagramALTERNATE RECORDKEYISdata-name-3withDUPLICATES
data-name-3

Data-name-3 is the ALTERNATE RECORD KEY data item. It must be described as a fixed length alphanumeric item within a record description entry associated with the file. It must not reference a group item that contains a variable occurrence data item. Data-name-3 may be qualified, but it must not be subscripted.

The length of the alternate record key is restricted; the alternate key length, in bytes, cannot exceed 2000. If the indexed file contains variable-length records, data-name-3 must be contained within the first "x" positions of the record, where "x" equals the minimum record size specified for the file.

For EXTERNAL files, all file description entries in the run unit that are associated with the EXTERNAL file must specify:
  • the same data description entry for data-name-3
  • the same relative location within the associated record
  • the same number of alternate record keys
  • the same DUPLICATES phrase.
IBM Extension

IBM Extension The ALTERNATE RECORD KEY data item, data-name-3, can be a date-time item or numeric item when the file is assigned to a DATABASE device type. The numeric item can have a usage of DISPLAY, COMP-1, COMP-2, COMP (COMP-3), COMP-4, COMP-5, PACKED-DECIMAL, or BINARY. The numeric item can also be an external floating-point data item. ILE COBOL supports a wide range of date and time data item formats. Many of these formats are not supported by DDS; in this case, the underlying DDS field must be defined as a character or numeric field. In cases where ILE COBOL defines a date-time item, but the underlying DDS field is not a date-time, retrieving records will be in the order determined by the underlying DDS data type. End of IBM Extension

End of IBM Extension
IBM Extension

IBM Extension The keys are ordered within the collating sequence used when the file was created. The data description of data-name-3, its relative location within the record and its length must be the same as those used when the file was defined in DDS. The leftmost character position of data-name-3 must not be the same as the leftmost character position of the RECORD KEY or of any other ALTERNATE RECORD KEY. If the DUPLICATES phrase is not specified, the values contained in the ALTERNATE RECORD KEY data item must be unique among records in the file. If the alternate key index is temporary, the order of retrieval of duplicate records is not guaranteed to be in any specific order. If the alternate key index is permanent, the DDS file level keywords, LIFO, FIFO, FCFO can be used to specify the order of retrieval of duplicate records. For more information on alternate key indexes, refer to the IBM Rational Development Studio for i: ILE COBOL Programmer's Guide. End of IBM Extension

End of IBM Extension