30.06.2013 Views

File Management - IBM

File Management - IBM

File Management - IBM

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

This example shows how you can use the copy command to copy 1000 records in<br />

the file EMP1 to the file EMP1T. The command copies records from the first<br />

member in EMP1 and replace the records in the first member in EMP1T.<br />

CPYF FROMFILE(PERSONNEL/EMP1) +<br />

TOFILE(TESTLIB1/EMP1T) MBROPT(*REPLACE) +<br />

NBRRCDS(1000)<br />

You can also use the NBRRCDS parameter to examine a subset of records on a list:<br />

CPYF FROMFILE(PERSONNEL/EMP1) TOFILE(*PRINT) +<br />

FROMRCD(250) NBRRCDS(10) OUTFMT(*HEX)<br />

When you successfully copy an open query file, the file position is unpredictable.<br />

If you want to run a different program with the same files or run another<br />

CPYFRMQRYF, you must position the file or close the file and open it with the<br />

same OPNQRYF command. You may position the file with the Position Database<br />

<strong>File</strong> (POSDBF) command. In some cases, you can use a high-level language<br />

program statement.<br />

Selecting records based on character content (INCCHAR<br />

Parameter)<br />

Note: You can use this parameter on the CPYF command only.<br />

You can select records on the basis of the content of characters that start in a<br />

specific position in the record or field. You can use the INCCHAR parameter with<br />

the FROMKEY or FROMRCD parameter. You can select records first by their key<br />

value or relative record number, and then by characters in some position in the<br />

record or field.<br />

You can test for any character string of 1 through 256 bytes. If the character string<br />

contains any special characters or blanks, you must enclose the entire string in<br />

apostrophes.<br />

You can also specify *CT (contains) as the operator for the INCCHAR parameter.<br />

This specifies that the copy command should scan each record in the from-file for<br />

the selection character string. You can specify any valid starting position in the<br />

field or record for the start of the scan. The data will then be scanned from that<br />

position to the byte to the extreme right of the field or record.<br />

If you specify both the INCCHAR and INCREL parameters, the copy command<br />

copies a record only if it satisfies both the INCCHAR and INCREL conditions.<br />

This example shows how you can test for all records in the file DBIN that have an<br />

XXX starting in position 80. It then shows how you can copy these records to the<br />

file DKTOUT. Because this example includes testing for positions relative to the<br />

length of the whole record, you must specify *RCD on the INCCHAR parameter.<br />

CPYF FROMFILE(DBIN) TOFILE(DKTOUT) +<br />

INCCHAR(*RCD 80 *EQ XXX)<br />

If you were testing for an XXX in a position in a particular field in the record, you<br />

would specify the field name instead of *RCD, and the starting position of the<br />

character relative to the start of the field.<br />

CPYF FROMFILE(DBIN) TOFILE(DKTOUT) +<br />

INCCHAR(FLDA 6 *EQ XXX)<br />

Chapter 4. Copying files 99

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

Saved successfully!

Ooh no, something went wrong!