CL Command Reference - CPYFRMQRYF
CL Command List > CPYFRMQRYF Reference
Description:
The Copy From Query File (CPYFRMQRYF) command copies either all or part of a file that is opened with the Open Query File (OPNQRYF) command to a physical program-described printer, diskette, a DDM file, or tape file, or *PRINT can be specified on the TOFILE parameter to print the records by using the IBM-supplied printer file, QSYSPRT.
This command can:
. Add records to an existing physical file member or replace contents of a receiving physical file member by using the MBROPT parameter.
. Copy records from an open query file format that is different than the to-file record format and convert records when copying to a source physical file. When the formats are different, the copy operation can:
¨C Map fields that have the same name in the open query file format and the to-file record format
¨C Drop fields from the open query file format that do not exist in the to-file record format
¨C Copy the records directly, disregarding the differences between the open query file format and the to-file record formatv Select a printout format when TOFILE(*PRINT) is specified. The records can be listed in character format, or in both character and hexadecimal format (OUTFMT parameter).
. If the to-file does not exist before the copy operation, create the file (CRTFILE parameter) so that it has the same format as the open query file. Only the name, type, length, and decimal positions of each field in the open query format are used.
. Copy a specified number or all of the records from an open query file depending if NBRRCDS(*END) was used or if a specific number was specified on the NBRRCDS parameter.
Restrictions:
1. The open query file used by the CPYFRMQRYF command must not use any DDM files (specified on the FILE parameter of the OPNQRYF command).
2. A member cannot be copied to itself. This restriction means that a member specified by the TOFILE and TOMBR parameters of the CPYFRMQRYF command cannot have the same name as any member specified on the FILE parameter of the OPNQRYF command, nor can the member have the same qualified name as any physical file members used by logical files that are on the FILE parameter of the OPNQRYF command.
3. When the CRTFILE(*YES) parameter is specified and the FROMOPNID parameter identifies a query file that has an associated trigger, the file created (TOFILE parameter) does not have the associated trigger. The Add Physical File Trigger (ADDPFTRG) command must be used to add a trigger to the file.
4. In multithreaded jobs, this command is not threadsafe if the OPNQRYF command is not run in a threadsafe manner, or if copying to multiple database members, device files (except SPOOL(*YES) print files), distributed files, or DDM files of type *SNA. This command fails for distributed files that use relational databases of type *SNA and DDM files of type *SNA. It is threadsafe ONLY when copying to single database file members (local or DDM of type *IP) or SPOOL(*YES) print files provided the OPNQRYF command is run in a threadsafe manner.
Examples:
Example 1: Building a File with a Subset of Records
OPNQRYF FILE(CUSTOMER/ADDRESS) QRYSLT(¡¯STATE *EQ "TEXAS"¡¯)
:
CPYFRMQRYF FROMOPNID(ADDRESS) TOFILE(TEXAS/ADDRESS)
CRTFILE(*YES)
These commands create a file from the CUSTOMER/ADDRESS file containing records that have a value of Texas in the STATE field.
Example 2: Printing Records Based on Selection
OPNQRYF FILE(FILEA) QRYSLT(¡¯CITY *EQ "CHICAGO"¡¯)
:
CPYFRMQRYF FROMOPNID(FILEA) TOFILE(*PRINT)
These commands print all records from FILEA where the value of the CITY field is Chicago.
Example 3: Copying a Subset of Records to a Diskette
OPNQRYF FILE(FILEB) QRYSLT(¡¯FIELDB *EQ "10"¡¯) OPNID(MYID)
:
CPYFRMQRYF FROMOPNID(MYID) TOFILE(DISK1)
These commands copy to a diskette file all records from FILEB where the value of FIELDB is 10.