Record sequence and copying
The access path is the sequence in which records are organized in a database file. There are two types of access paths: keyed sequence and arrival sequence. With the copy function, you can process records in a database file in either arrival sequence or keyed sequence.
An arrival sequence copy transfers records in the order in which they physically exist in the from-file. Relative record numbers represent this order. The relative record number is the position where the records physically exist in storage. Because records are always added to the end of the file, the relative record number represents the order in which records arrived in the file.
A keyed sequence copy selects and transfers records by key value from a keyed physical file. This might result in a different physical order in the to-file. The to-file will be a reorganized version of the from-file. The relative record number of a specific record might change when a file is copied by key value:
Relative record number Arrival sequence Keyed sequence 1 1011 0016 2 0762 0762 3 0810 0810 4 3729 1011 5 0016 3729
You can copy a keyed physical file in arrival sequence by specifying the FROMRCD or TORCD parameter on the COPY commands. When you do this, the keyed sequence access path is not used to retrieve the records in key sequence. The records are retrieved in arrival sequence. This is helpful when the physical relative record location in the file is significant and needs to remain the same as it is in the original file. Specifying FROMRCD(1) is a good way to copy all the records in arrival sequence. Copying a physical file in arrival sequence instead of keyed sequence is also faster.
The kind of copy you run is determined by the type of from-file and the method of selecting records to copy. In general, files are copied using their keyed sequence, if they have one, otherwise, their arrival sequence.
A copy from a keyed file to a keyed file typically places records at the end of the to-file in key field order, by the from-file key, regardless of their physical order in the from-file. But if you select records in the from-file by relative record number (using the FROMRCD or TORCD parameter), they are physically placed at the end of the to-file in relative record number order, regardless of their keyed sequence in the from-file. The following example shows the result of a COPY command that specifies from record 3 to record 5:
From-file To-file Relative record number Key Relative record number Key 1 1011 . — 2 0762 . — 3 0810 < Arrival
< Sequence
< Copy1401 0810 4 3729 1402 3729 5 0016 1403 0016 When the to-file has a keyed sequence, the records appear in correct order in the to-file when using the keyed sequence access path. A copy by relative record number always copies by arrival sequence.
Parent topic:
Copying files: Basic functions
Related concepts
Selecting the records to copy