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

96 File Management V4R5 Example: build-key function An example of the build-key function is: Key Field Number Type Length Decimal Precision Value 1 CHAR 6 KEN 2 ZONED 6 2 54.25 3 BINARY 4 1 10.1 You could specify the FROMKEY (or TOKEY) parameter as follows: FROMKEY( 2 x'D2C5D5404040F0F0F5F4F2F50065') Or, you could use the *BLDKEY value and specify the FROMKEY as follows: FROMKEY(*BLDKEY (KEN 54.25 10.1)) Another example using key fields 1 and 2 is: FROMKEY(2 'KEN 005425') Or, you can specify the *BLDKEY value: FROMKEY(*BLDKEY (KEN 54.25)) Example: using FROMKEY and TOKEY In this example, the copy command copies records in the file EMP1 to the file EMP1T. EMP1T is a file in a test library. Because you only need a subset of the records, you specify a from-key value and a to-key value. Both are full key values. Note that a 1 specified in the FROMKEY and TOKEY parameters indicates the number of key fields to be used in searching the record keys, starting with the first key field. CPYF FROMFILE(PERSONNEL/EMP1) + TOFILE(TESTLIB1/EMP1T) MBROPT(*REPLACE) + FROMKEY(1 438872) TOKEY(1 810199) All positions in a key value should be specified. If the value is shorter than the key field length, it will be padded on the right with zeros. Thus, a 5-position key field specified as FROMKEY(1 8) causes a search for a key equal to hex F800000000. If the key value contains blanks or special characters, you must enclose them in apostrophes. Variable-length fields used by record keys (FROMKEY and TOKEY) When the number of key fields and a value are used to specify the FROMKEY or TOKEY parameter, the string should include the 2-byte length field for each variable-length key field. You must pad the variable-length key field with blanks so that keys following the variable-length key field are in the correct position. You can specify the data in hexadecimal format. When you specify *BLDKEY on the FROMKEY or TOKEY parameter for variable-length key fields, specify the character string without the 2-byte length field. Only the amount of data that is entered for the key value is used for key comparisons. You can specify a zero-length string for variable-length key fields.

Date, time, and timestamp fields used by record keys (FROMKEY and TOKEY) When the number of key fields and a value are used to specify the FROMKEY or TOKEY parameter, no conversion of data occurs if the corresponding key field in the from-file is a date, time, or timestamp field. The user input string that you specify (including the separators) must be in the same format as the date, time, or timestamp field. If it is not, a file open error may occur, or the records copied may not be the desired result. If *BLDKEY is specified for the FROMKEY or TOKEY parameter and the corresponding key field in the from-file is a date, time, or timestamp field, the system attempts to convert the user-input key field value to the format (and separators) of the from-file field. The following rules apply to the conversion: v If the from-field is a date key field, the system first determines if the user-input key value is in the same format and has the same separator as specified in the current job under which the copy command is running. This can be *MDY, *DMY, *YMD, or *JUL for the format and slash (/), hyphen (-), period (.), comma (,), or blank ( ) for the separator. If the user-input key value is not in the current job specified format and separator form, it determines if it is in one of the Systems Application Architecture (SAA) formats (*ISO, *USA, *EUR, or *JIS). It also determines if it is in a YYYYDDD form (no separator). If the system can determine the user-input key value is in one of these forms, the input string is converted to the actual format (and separator) of the from-file date field, which is used for the key comparison. If the user-input string format cannot be determined or the length or data value is not valid, the system issues a diagnostic message. You must left-justify the date portion of the user-input key value; it can contain trailing blanks. v If the from-field is a time key field, the system first determines if the user-input key value is in the same format and has the same separator as specified in the current job under which the copy command is running. This may be HHMMSS for the format and colon (:), comma (,), period (.), or blank ( ) for the separator. If the user-input key value is not in the current job specified format and separator form, the system determines if it is in one of the SAA formats (*ISO, *USA, *EUR, or *JIS). If the system can determine the user-input key value is in one of these forms, the input string is converted to the actual format (and separator) of the from-file time field, which is used for the key comparison. If the user-input string format cannot be determined, or the length or data value is not valid, the system issues a diagnostic message. You must left-justify the time portion of the user-input key value; it can contain trailing blanks. v If the from-field is a timestamp key field, the system first determines if the user-input key value is in the SAA format or YYYYMMDDHHMMSS form. If the system determines the user-input key value is in one of these forms, the input string is converted to the actual SAA timestamp format, which is used for the key comparison. If the user-input string format cannot be determined, or the length or data value is not valid, the system issues a diagnostic message. You must left-justify the timestamp portion of the user-input key value; it can contain trailing blanks. Null-capable fields used by record keys (FROMKEY and TOKEY) When you use the number of key fields and a value to specify the FROMKEY or TOKEY parameter, the copy command ignores the null values. The command uses only the buffer default values for values that are actually null for the comparison. Chapter 4. Copying files 97

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

and TOKEY)<br />

When the number of key fields and a value are used to specify the FROMKEY or<br />

TOKEY parameter, no conversion of data occurs if the corresponding key field in<br />

the from-file is a date, time, or timestamp field. The user input string that you<br />

specify (including the separators) must be in the same format as the date, time, or<br />

timestamp field. If it is not, a file open error may occur, or the records copied may<br />

not be the desired result.<br />

If *BLDKEY is specified for the FROMKEY or TOKEY parameter and the<br />

corresponding key field in the from-file is a date, time, or timestamp field, the<br />

system attempts to convert the user-input key field value to the format (and<br />

separators) of the from-file field. The following rules apply to the conversion:<br />

v If the from-field is a date key field, the system first determines if the<br />

user-input key value is in the same format and has the same separator as<br />

specified in the current job under which the copy command is running. This can<br />

be *MDY, *DMY, *YMD, or *JUL for the format and slash (/), hyphen (-), period<br />

(.), comma (,), or blank ( ) for the separator. If the user-input key value is not in<br />

the current job specified format and separator form, it determines if it is in one<br />

of the Systems Application Architecture (SAA) formats (*ISO, *USA, *EUR, or<br />

*JIS). It also determines if it is in a YYYYDDD form (no separator). If the system<br />

can determine the user-input key value is in one of these forms, the input string<br />

is converted to the actual format (and separator) of the from-file date field,<br />

which is used for the key comparison. If the user-input string format cannot be<br />

determined or the length or data value is not valid, the system issues a<br />

diagnostic message. You must left-justify the date portion of the user-input key<br />

value; it can contain trailing blanks.<br />

v If the from-field is a time key field, the system first determines if the<br />

user-input key value is in the same format and has the same separator as<br />

specified in the current job under which the copy command is running. This<br />

may be HHMMSS for the format and colon (:), comma (,), period (.), or blank ( )<br />

for the separator. If the user-input key value is not in the current job specified<br />

format and separator form, the system determines if it is in one of the SAA<br />

formats (*ISO, *USA, *EUR, or *JIS). If the system can determine the user-input<br />

key value is in one of these forms, the input string is converted to the actual<br />

format (and separator) of the from-file time field, which is used for the key<br />

comparison. If the user-input string format cannot be determined, or the length<br />

or data value is not valid, the system issues a diagnostic message. You must<br />

left-justify the time portion of the user-input key value; it can contain trailing<br />

blanks.<br />

v If the from-field is a timestamp key field, the system first determines if the<br />

user-input key value is in the SAA format or YYYYMMDDHHMMSS form. If<br />

the system determines the user-input key value is in one of these forms, the<br />

input string is converted to the actual SAA timestamp format, which is used for<br />

the key comparison. If the user-input string format cannot be determined, or the<br />

length or data value is not valid, the system issues a diagnostic message. You<br />

must left-justify the timestamp portion of the user-input key value; it can contain<br />

trailing blanks.<br />

Null-capable fields used by record keys (FROMKEY and TOKEY)<br />

When you use the number of key fields and a value to specify the FROMKEY or<br />

TOKEY parameter, the copy command ignores the null values. The command uses<br />

only the buffer default values for values that are actually null for the comparison.<br />

Chapter 4. Copying files 97

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

Saved successfully!

Ooh no, something went wrong!