DUPLICATES Option

The DUPLICATES option applies only to index random, index sequential, and ordered list subsets. The DUPLICATES option indicates whether two or more subset entries can have identical keys. If duplicates are allowed, this option also controls the order in which records with duplicate keys are returned. For automatic subsets, DUPLICATES is the default setting. For manual subsets, NO DUPLICATES is the default setting. Note that SETS and SUBSETS have different defaults.

The DUPLICATES option affects the space required by the subset and the time required to access it. If duplicates are allowed, but neither FIRST nor LAST is stipulated, a 1-word duplicate resolver is added to each subset entry. The duplicate resolver makes each subset entry unique and allows a binary search to be done to retrieve a particular record. If the DUPLICATES FIRST option or the DUPLICATES LAST option is specified, no duplicate resolver is allocated. When a particular record is required, the first record with the specified key is located and the remaining entries with equal keys are searched in linear fashion.

Thus, the DUPLICATES FIRST and DUPLICATES LAST options dictate that the data set entries be stored in chronological order. However, this ordering can be altered if transactions are aborted. When the INDEPENDENTTRANS option is set and either the DUPLICATES FIRST option or DUPLICATES LAST option is specified, only the current transaction for the aborting program is affected. The audit is processed in reverse order and performed operations are inverted. For example, a DELETE operation becomes a CREATE operation and a STORE operation. All other programs continue to process normally.

This reversal of operations can cause the chronological ordering of the records to change. The single abort process occurs concurrently with and is treated like any database application. Thus, from the perspective of a subset, when SINGLEABORT recovery inverts a DELETE, that action becomes a new entry and is inserted in the subset as the then most current FIRST or LAST entry. As such, the entries pointing to restored data set records can change their chronological position within a group of duplicates.

The DUPLICATES options for subsets are explained in DUPLICATES Options for Subsets.

Table 14. DUPLICATES Options for Subsets

Option

Description

NO DUPLICATES

When the NO DUPLICATES option is specified, all data set records must have unique keys. The key of an existing record cannot be changed when the NO DUPLICATES option is stipulated. The key can be changed only by deleting the record from the data set and then re-creating it with a new key.

DUPLICATES FIRST

The DUPLICATES FIRST option causes records with identical keys to be kept in reverse chronological order; that is, the first record returned is the one most recently added, the second record returned is the next most recently added, and so on.

DUPLICATES LAST

The DUPLICATES LAST option causes records with identical keys to be kept in chronological order; the first record returned is the first record added, the second record returned is the second record added, and so on.

DUPLICATES

If neither the FIRST nor the LAST keyword is specified, duplicates are not returned in any special order.

KEYCHANGEOK

The INDEPENDENTTRANS option must be set when the KEYCHANGEOK option is set. When the KEYCHANGEOK option is specified, the key of the existing record can be changed by a modify or store operation. The old record is deleted.

If a record already exists with the new key, a DUPLICATES exception is returned and the old record is retained.