If you do not specify the UNIQUE keyword in data description specifications (DDS), you can specify how the system stores records with duplicate key values, if duplicate key values occur.
|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 A* ORDERP2 A 1 LIFO A R ORDER2 A . A . A . A K ORDER A
When a simple- or multiple-format logical file is based on more than one physical file member, records with duplicate key values are read in the order in which the files and members are specified on the DTAMBRS parameter of the Create Logical File (CRTLF) or Add Logical File Member (ADDLFM) command. Examples of logical files with more than one record format can be found in DDS concepts.
The LIFO or FIFO order of records with duplicate key values is not determined by the sequence of the updates made to the contents of the key fields, but only by the physical sequence of the records in the file member. Assume that a physical file has the FIFO keyword specified (records with duplicate keys are in FIFO order), and that the following table shows the order in which records were added to the file.
|
The sequence of the access path is (FIFO, ascending key).
|
Records 3 and 4, which have duplicate key values, are in FIFO order. That is, because record 3 was added to the file before record 4, it is read before record 4. This would become apparent if the records were read in descending order. This can be done by creating a logical file based on this physical file, with the DESCEND keyword specified in the logical file.
The sequence of the access path is (FIFO, descending key).
|
If the key value of physical record 1 is changed to C, the sequence of the access path for the physical file is (FIFO, ascending key).
|
Finally, changing to descending order, the new sequence of the access path for the logical file is (FIFO, descending key).
|
After the change, record 1 does not appear after record 4, even though the contents of the key field were updated after record 4 was added.
The FCFO order of records with duplicate key values is determined by the sequence of updates made to the contents of the key fields. In the example above, after record 1 is changed such that the key value is C, the sequence of the access path (FCFO, ascending key only) is.
|
For FCFO, the duplicate key ordering can change when the FCFO access path is rebuilt or when a rollback operation is performed. In some cases, your key field can change but the physical key does not change. In these cases, the FCFO ordering does not change, even though the key field has changed. For example, when the index ordering is changed to be based on the absolute value of the key, the FCFO ordering does not change. The physical value of the key does not change even though your key changes from negative to positive. Because the physical key does not change, FCFO ordering does not change.
If the reuse deleted records attribute is specified for a physical file, the duplicate key ordering must be allowed to default or must be FCFO. The reuse deleted records attribute is not allowed for the physical file if either the key ordering for the file is FIFO or LIFO, or if any of the logical files defined over the physical file have duplicate key ordering of FIFO or LIFO.