DUPLICATES Phrase

IBM Extension
IBM Extension

The DUPLICATES phrase can only be specified for files assigned duplicate record keys. This allows the file to have keys with the same values. If the file has multiple formats, two keys in different formats have the same values only when the key lengths and the contents of the keys are the same.

For example, given a file with the following two formats:
  • Format F1 with keys A, B, C
  • Format F2 with keys A, B, D.

If fields C and D are the same length, have the same data type, and have the same values, the file would contain two records with a duplicate key. The term duplicate key applies only to a complete record key for the format. A record key for the format consists of the key field(s) defined for a DDS format for records residing on the database. The term does not apply to the common key for the file (only fields A and B in the above example).

Users can indicate DUPLICATES on the RECORD KEY clause. A file status of 95 is returned after a successful open when:
  • The DUPLICATES phrase is specified in the COBOL program and the file was created with UNIQUE specified in DDS.
  • The DUPLICATES phrase is not specified in the COBOL program and the file was created allowing nonunique keys.

Processing files when either of these conditions exist can cause unpredictable results.

In a file that allows duplicates and is processed randomly or dynamically, the duplicate record that is updated or deleted must be the proper one. To ensure this, the last input/output statement processed prior to the REWRITE or DELETE operation must be a successfully processed READ statement without the NO LOCK phrase.

If the DDS file level keyword LIFO (last-in-first-out) is specified, the duplicate records within a physical file are retrieved in a last-in-first-out order.

End of IBM Extension
End of IBM Extension
data-name-2
Data-name-2 is the 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-2 may be qualified, but it must not be subscripted.

The length of the record key is restricted; the key length, in bytes, cannot exceed 2 000. For more information, see the DB2® for i section of the Database and File Systems category in the IBM® i Information Center at this Web site - http://www.ibm.com/systems/i/infocenter/.

If the indexed file contains variable-length records, data-name-2 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-2 with the same relative location within the associated record; otherwise the results are undefined.

IBM Extension

IBM Extension The RECORD KEY data item, data-name-2, 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. End of IBM Extension

End of IBM Extension
IBM Extension

IBM Extension 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 COBOL defines a date-time item, but the underlying DDS field is not date-time, retrieving or writing records to the database will be in the order determined by the underlying DDS data type. End of IBM Extension

End of IBM Extension

The keys are ordered within the collating sequence used when the file was created.

The data description of data-name-2 and its relative location within the record must be the same as the ones used when the file was defined in DDS.

The record description that defines data-name-2 will always be used to access the record key field for the I-O operation.