Select records by record keys (FROMKEY and TOKEY Parameters)

You can specify record keys to copy only from a keyed database file. Note that you can use this parameter on the CPYF command only.

You can copy records: If the command reaches the end of the file before it reaches the specified ending key value or number of records, the copy completes normally.

If no record in the from-file member has a key that is a match with the FROMKEY value, but there is at least one record with a key greater than the specified value, the first record copied is the first record with a key greater than the FROMKEY value. If the specified key value is greater than any record in the member, the command sends an error message and does not copy the member.

You can specify *BLDKEY on the FROMKEY and TOKEY parameters to use a list of character and numeric values in their natural display form for the fields in a key. The command converts each element to the corresponding key field data type. The command then provides the composite key value (a key that is comprised of more than one field) to the database.

If you specify fewer values than the complete database key contains, the command builds a partial key and passes it to the database. If you specify more values than the database key contains, an ending error occurs. The command always applies values to the consecutive fields that are in the extreme left of the key so that it is impossible to skip key fields.

The command pads character fields on the right with blanks. The command adjusts numeric fields to the implied decimal point in the key field with the correct zero padding.

All regular rules for specifying numeric fields in an external character format apply. The command does not allow a floating-point value of *NAN (Not a Number).

It is also important to understand Key string comparisons made by the copy operation in order to interpret various warning messages.

Note: If you use record keys to select records, you cannot use relative record numbers (FROMRCD/TORCD parameters) to select records on the same CPYF command.

You should not specify COMPRESS(*NO) when selecting records by record key from a keyed physical file. Because the keyed access path of a file does not contain deleted records, the copy command never copies them, so the compression is automatic.

Because deleted records are canceled in a copy by this method, it is also possible that the relative record numbers have changed in the new file, even if you have specified MBROPT(*REPLACE).

The user has to input operand equal to the length of the fix field when specifying *BLDKEY on the FROMKEY and TOKEY parameters for fix length binary character keyfields.

Related concepts
Select a specified number of records (NBRRCDS parameter)