Copying files: Commands
You can copy records to and from files with commands discussed in this topic. To copy records to and from files, use the following commands:
- CPYF
- Copy File (CPYF) command copies all or part of a file from the database or external device to the database or external device.
- CPYFRMTAP
- Copy from Tape (CPYFRMTAP) command copies from a tape file to a database or device file. The from-file must be a tape file, but the to-file can be a physical file, diskette file, tape file, or program-described printer file. You can obtain a formatted listing of the records by using QSYSPRT.
- CPYTOTAP
- Copy to Tape (CPYTOTAP) command copies from a database or device file to a tape file. The to-file must be a tape file, but the from-file can be a physical, logical, diskette, tape, or inline data file.
- CPYSRCF
- Copy Source File (CPYSRCF) command copies a database source file to a source physical file and converts the data in the from-file to the to-file CCSID. You can create a formatted listing by using QSYSPRT (the file is changed for source records and is different from other copy command file formats). Record data is copied from the from-file to the to-file, disregarding differences in record formats (similar to the FMTOPT(*NOCHK) parameter option on the CPYF command, except for the CCSIDs.)
- CPYFRMQRYF
- Copy from Query File (CPYFRMQRYF) command copies an open query file to a database or device file.
The system does not reclaim DDM conversations for a job when a copy command produces an error.
If you specify a DDM file and a local file on the CPYF or CPYSRCF commands, the system does not verify that the remote and local files are not the same on the source system. If you specify one DDM file, you can potentially copy to and from the same file.
For information about how to copy DBCS-open fields to graphic fields (including the option of removing trailing single-byte blanks for the DBCS-open field first), see DBCS-graphic fields using FMTOPT(*MAP) or FMTOPT(*NOCHK).
Throughout this topic, unless the text specifies a specific command, the term copy commands refers to all the commands just described.
The device and database files where you can perform copy operations are shown in Table 1.
Table 1. Copy operations From-files To-files DDM DDM Diskette1 Diskette1 Logical Physical2 Open query3 Printer Physical *PRINT4 Inline data5 Tape Tape Notes:
- 1
- If the from-file and the to-file are both diskette files, the to-file must be spooled.
- 2
- If the to-file does not exist before the copy operation, the copy operation will create a physical file as the to-file if you specified:
- CRTFILE(*YES) on the CPYF command and the from-file is a physical or logical file.
- CRTFILE(*YES) on the CPYFRMQRYF command.
- 3
- Open query files can only be copied by using the CPYFRMQRYF command. CPYFRMQRYF is not allowed for open query files that use DDM files.
- 4
- If TOFILE(*PRINT) is specified, the from-file records are copied to the IBM-supplied printer device file QSYSPRT and formatted according to the OUTFMT parameter.
- 5
- An inline data file (which is handled like a device file) is included as part of a batch job when the job is read by a reader program.
While copying records, some of the copy commands can perform the following functions:
- Copy from or to the first file member, a particular file member, a generic set of members, or all file members (FROMMBR and TOMBR parameters).
- Add a member to a physical to-file if the member does not exist.
- Add records to an existing file member, replace the contents of an existing member (MBROPT parameter), or update duplicate key records in a to-file member.
- Select certain records to copy by one of the following methods:
- Selecting records by record format name when a multi-format logical file is copied (RCDFMT parameter).
- Specifying records by starting at a relative record number and ending at a relative record number (FROMRCD and TORCD parameters).
- Specifying records by starting with a specific record key value and ending with another specific record key value (FROMKEY and TOKEY parameters).
- Specifying the number of records that you want to copy (NBRRCDS parameter).
- Selecting records by the contents of one or more character positions in the record or in a field in the record (INCCHAR parameter).
- Selecting records according to the values that are contained in one or more fields in the record (INCREL parameter).
- Disregard or include deleted records in the from-file during the copy if processing the from-file in arrival sequence (COMPRESS parameter).
- Print copied records, excluded records, or error records (PRINT parameter) in a specified format (OUTFMT parameter).
- Copy records whose from-file and to-file record formats are different (FMTOPT parameter). When formats are different, you can perform any of the following actions:
- Map fields whose names are the same in the from-file and to-file record formats and whose field attributes are compatible (*MAP value).
- Drop fields in the from-file record format that do not exist in the to-file record format (*DROP value).
- Copy data directly (left to right) disregarding any differences (*NOCHK value).
- Copy from a source file to a data file or from a data file to a source file. If the from-file or to-file is a device file, this function is automatic. If both files are database files, specify FMTOPT(*CVTSRC).
- Change sequence numbers and zero dates in the sequence number and date source fields when copying to a source physical file (SRCOPT parameter). When renumbering is to be done, the starting sequence number and the increment value can be specified (SRCSEQ parameter).
- End the copy after a specified number of recoverable errors are encountered (ERRLVL parameter).
- Create the to-file as part of the copy operation (CRTFILE parameter).
Parent topic:
Copying files: Overview