File Management - IBM

File Management - IBM File Management - IBM

as400bks.rochester.ibm.com
from as400bks.rochester.ibm.com More from this publisher
30.06.2013 Views

94 File Management V4R5 Selecting records by record keys (FROMKEY and TOKEY Parameters) Note: You can use this parameter on the CPYF command only. You can specify record keys to copy only from a keyed database file. You can copy records: v From a specified key value (FROMKEY parameter) to a specified key value (TOKEY parameter) OR v Until a specified number of records (NBRRCDS parameter) is reached (see “Selecting a specified number of records (NBRRCDS Parameter)” on page 98 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). See “Example: build-key function” on page 96 and “Example: using FROMKEY and TOKEY” on page 96 for specific coding examples. It is also important to understand “Key string comparisons made by the copy operation” on page 95 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). See the following topics for more information about specifying data for: v “Variable-length fields used by record keys (FROMKEY and TOKEY)” on page 96 v “Date, time, and timestamp fields used by record keys (FROMKEY and TOKEY)” on page 97 v “Null-capable fields used by record keys (FROMKEY and TOKEY)” on page 97 v “Different CCSIDs used by record keys (FROMKEY and TOKEY)” on page 98 v “DBCS-graphic fields used by record keys (FROMKEY and TOKEY)” on page 98 Key string comparisons made by the copy operation The check made by the copy operation (when the TOKEY value is specified) is a logical character comparison between the key string for each record retrieved and the key string that is: v Specified explicitly (using the first TOKEY parameter format) OR v Built implicitly by the copy operation (that uses the list of values that are given) A warning message is sent (but the copy operation continues) if this comparison gives different results than the ordering in which the database identifies the records in the keyed access path. The order may be different if: v The key contains mixed ascending and descending fields v The key contains fields for which a sort sequence other than *HEX is in effect OR v The key contains any of the following DDS keywords: ABSVAL Absolute value ALTSEQ Alternative collating sequence ALWNULL Allow null DATFMT Date format (*MDY, *DMY, *YMD, *JUL, SAA *EUR, or SAA *USA) DIGIT Digit force SIGNED Signed numeric TIMFMT Time format (*USA) ZONE Zone force If there are both ascending and descending fields in the file key, the first (the far left) key field determines whether the copy operation uses an ascending or descending key test to look for the last record to copy. Using *BLDKEY is the easiest way to specify (and ensure correct padding) values for packed, binary, and floating-point fields. Chapter 4. Copying files 95

Because deleted records are canceled in a copy by this method, it is also possible<br />

that the relative record numbers have changed in the new file, even if you have<br />

specified MBROPT(*REPLACE).<br />

See the following topics for more information about specifying data for:<br />

v “Variable-length fields used by record keys (FROMKEY and TOKEY)” on<br />

page 96<br />

v “Date, time, and timestamp fields used by record keys (FROMKEY and<br />

TOKEY)” on page 97<br />

v “Null-capable fields used by record keys (FROMKEY and TOKEY)” on page 97<br />

v “Different CCSIDs used by record keys (FROMKEY and TOKEY)” on page 98<br />

v “DBCS-graphic fields used by record keys (FROMKEY and TOKEY)” on page 98<br />

Key string comparisons made by the copy operation<br />

The check made by the copy operation (when the TOKEY value is specified) is a<br />

logical character comparison between the key string for each record retrieved and<br />

the key string that is:<br />

v Specified explicitly (using the first TOKEY parameter format) OR<br />

v Built implicitly by the copy operation (that uses the list of values that are given)<br />

A warning message is sent (but the copy operation continues) if this comparison<br />

gives different results than the ordering in which the database identifies the<br />

records in the keyed access path. The order may be different if:<br />

v The key contains mixed ascending and descending fields<br />

v The key contains fields for which a sort sequence other than *HEX is in effect<br />

OR<br />

v The key contains any of the following DDS keywords:<br />

ABSVAL<br />

Absolute value<br />

ALTSEQ<br />

Alternative collating sequence<br />

ALWNULL<br />

Allow null<br />

DATFMT<br />

Date format (*MDY, *DMY, *YMD, *JUL, SAA *EUR, or SAA *USA)<br />

DIGIT<br />

Digit force<br />

SIGNED<br />

Signed numeric<br />

TIMFMT<br />

Time format (*USA)<br />

ZONE Zone force<br />

If there are both ascending and descending fields in the file key, the first (the far<br />

left) key field determines whether the copy operation uses an ascending or<br />

descending key test to look for the last record to copy.<br />

Using *BLDKEY is the easiest way to specify (and ensure correct padding) values<br />

for packed, binary, and floating-point fields.<br />

Chapter 4. Copying files 95

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!