Copying files: Basic functions
You can copy from a physical or logical database file, open query file, diskette file, tape file, or inline data file. The to-file can be a physical database file, diskette file, tape file, program-described printer file, or *PRINT.
When you specify TOFILE(*PRINT), the Copy Source File (CPYSRCF) command uses a different format from the other copy commands. This format shows source information in a more readable format, and, for multiple member copies, the members are copied and listed in alphabetical order.
If you are copying from a database file and the to-file does not exist, specify CRTFILE(*YES) and identify the file name and library name on the TOFILE parameter in order to create the to-file. You cannot copy from a diskette to a diskette unless the to-file is spooled and a diskette spooling writer is not active.
The from-file (not including the Copy From Query File (CPYFRMQRYF) command where the from-file is not opened), to-file, and the QSYSPRT printer file (if TOFILE(*PRINT), PRINT(*COPIED), PRINT(*EXCLD), or PRINT(*ERROR) is specified) are opened with the SHARE(*NO) attribute. Because the copy might not function correctly with a shared file, it will end with an error message if the from-file, to-file, or QSYSPRT printer file is overridden to SHARE(*YES) and the file has already been opened in the job.
If you specify TOFILE(*PRINT), the records are copied to the IBM-supplied printer file QSYSPRT, and the OUTFMT parameter formats the list.
If you do not want a formatted list or if you want to use first-character forms control (CTLCHAR(*FCFC) on the Create Printer File (CRTPRTF) or Override with Printer File (OVRPRTF) command), you should specify a program-described printer file name (such as QSYSPRT) instead of *PRINT on the TOFILE parameter.
- File types and copying
There are considerations when you copy files of one type to files of another type.
- Record sequence and copying
The access path is the sequence in which records are organized in a database file. There are two types of access paths: keyed sequence and arrival sequence. With the copy function, you can process records in a database file in either arrival sequence or keyed sequence.
- Resending copy file completion message
If you run a COPY command from a CL program, the completion message indicating the number of records that are copied is not sent directly to the system operator. You can direct this message to the system operator by resending it.
- Monitoring for copy errors
When an error occurs, the escape message CPF2817 is sent to indicate many different error conditions.
- Monitoring for zero records in the from-file
There are some special considerations for copy when the from-file is a physical or logical file and one or more members to be copied are empty.
- Creating a duplicate to-file member
You can create duplicates to-file members without doing the copy file action again.
- CPYFRMQRYF command support for CCSIDs
The Copy from Query File (CPYFRMQRYF) command provides coded character set identifier (CCSID) conversions for character and double-byte character sets (DBCS) fields.
- CPYSRCF command support for CCSIDs
Using the Copy Source File (CPYSRCF) command automatically converts data in the from-file to the to-file CCSID. If you do not want the character data converted, use the CPYF command with FMTOPT(*NOCHK).
- Copy commands support for null values
You can copy files that contain null-capable fields by using the CPYF and CPYFRMQRYF commands. The FMTOPT parameter allows mapping of null-capable fields.
Parent topic:
Copying files: Overview
Related information
Copy Source File (CPYSRCF) command
Copy From Query File (CPYFRMQRYF) command
Create Printer File (CRTPRTF) command
Override with Printer File (OVRPRTF) command