Command reference / db
CPYF
Copy File
Copies all or part of a file between database files, device files (diskette, tape, printer) and inline data files, in any combination. Records can be copied from physical or logical files but only into physical files. It also copies source and data files to and from external devices.
Allowed environments: *ALL.
Positional parameters: 6.
Restrictions
- The To file may be locked for the duration of the copy, similar to an *EXCL lock with no timeout.
- With CRTFILE(*YES), triggers on the from-file are not carried to the created file; ADDPFTRG must be used to add one.
- Conditionally threadsafe: not threadsafe in multithreaded jobs when copying multiple members, device files (except SPOOL(*YES) print files), distributed files, or SNA DDM files. Fails for SNA distributed files and SNA DDM files.
Parameters
FROMFILE
From file
The database or device file that holds the records to copy. A database file may be physical or logical; a device file may be diskette or tape. This parameter is required.
*LIBL- Searches the user and system portions of the job's library list until the first match.
*CURLIB- Uses the job's current library, or QGPL if none is set.
Qualified parts (object, then library; write LIBRARY/OBJECT)
From file
From file
Library
Library
Suggested / special values:
*LIBL, *CURLIB
TOFILE
To file
The file that receives the copied records: a physical or device file, or *PRINT to send output to the system printer file QSYSPRT. This parameter is required.
*PRINT- Copies data to QSYSPRT, formatted according to OUTFMT.
*LIBL- Searches the user and system portions of the job's library list until the first match.
*CURLIB- Uses the job's current library, or QGPL if none is set.
Qualified parts (object, then library; write LIBRARY/OBJECT)
To file
To file
Library
Library
Suggested / special values:
*LIBL, *CURLIB
FROMMBR
From member
The from-file member (or diskette or tape label) to copy. A generic name selects all members sharing a prefix. Optional.
Suggested / special values:
*FIRST, *ALL
*FIRST- Copies the first member; the only value allowed for an inline from-file.
*ALL- Copies all members (or all diskette labels); not valid for tape or inline files.
TOMBR
To member or label
The to-file member or label that receives the data. Must be *FIRST or *FROMMBR when TOFILE(*PRINT) is specified.
Suggested / special values:
*FIRST, *FROMMBR, *ALL
*FIRST- Uses the first member of the to-file.
*FROMMBR- Uses the to-file member whose name matches the from-file member.
*ALL- Copies to the correct to-member of a partitioned table; valid only for partitioned tables.
MBROPT
Replace or add records
Whether new records replace or are added to existing records in the to-file. Must be *ADD, *UPDADD or *REPLACE when copying into an existing physical file.
Allowed values:
*NONE, *ADD, *REPLACE, *UPDADD
*NONE- Does not apply; not allowed when the to-file is an existing physical file.
*ADD- Adds the new records to the end of the existing records.
*REPLACE- Clears the existing member, then adds the new records.
*UPDADD- Updates records with duplicate keys and adds the remaining records to the end.
CRTFILE
Create file
Whether a physical file is created to receive the data when the to-file does not exist. When *YES, the created file takes the from-file's record format and access path.
Allowed values:
*NO, *YES
*NO- The to-file must already exist.
*YES- Creates the to-file if it does not exist.
OUTFMT
Print format
Whether printed records appear in character format or in both character and hexadecimal format. Used only when printing.
Allowed values:
*CHAR, *HEX
*CHAR- Records are printed in character format.
*HEX- Records are printed in both character and hexadecimal format.
PRINT
Which records to print
Which copied, excluded or error records are printed.
Allowed values:
*NONE, *EXCLD, *COPIED, *ERROR
*NONE- No copied, excluded or error records are printed.
*EXCLD- Records excluded by INCCHAR or INCREL are printed.
*COPIED- Copied records are printed.
*ERROR- The recoverable error records allowed by ERRLVL are printed.
RCDFMT
Record format of logical file
Names the record format copied from a logical or physical from-file. A format name is optional for a single-format file; a name or *ALL is required for a multi-format file.
Suggested / special values:
*ONLY, *ALL
*ONLY- Copies the only record format; allowed only when the logical file has a single format.
*ALL- Uses all record formats of the logical from-file.
FROMRCD
Copy from record number
Record number at which copying starts. Not valid with FROMKEY or TOKEY, or for a keyed logical file.
Suggested / special values:
*START
*START- Starts with the first record in the file.
TORCD
Copy to record number
Record number of the last record copied. Not valid with FROMKEY or TOKEY, with NBRRCDS other than *END, or for a keyed logical file.
Suggested / special values:
*END
*END- Copies until end-of-file is reached.
FROMKEY
Copy from record key
Key value of the first record to copy, for a keyed from-file. Not allowed with FROMRCD or TORCD.
*NONE- The first record copied is not selected by key.
*BLDKEY- Key values are given as a list, one value per key field, instead of one string.
Elements in order
Number of key fields
Number of key fields
Suggested / special values:
*BLDKEY
Key value
Key value
TOKEY
Copy to record key
Key value of the last record to copy, for a keyed from-file. Not allowed with FROMRCD, TORCD or NBRRCDS.
*NONE- The last record copied is not selected by key.
*BLDKEY- Key values are given as a list, one value per key field, instead of one string.
Elements in order
Number of key fields
Number of key fields
Suggested / special values:
*BLDKEY
Key value
Key value
NBRRCDS
Number of records to copy
How many records are copied to the to-file.
Suggested / special values:
*END
*END- Copies until end-of-file, unless TOKEY or TORCD is specified.
INCCHAR
Include records by char test
Selects records by comparing a character string with data at a starting position in a field or the whole record. The four values are field (or *RCD), starting position, operator and value.
*NONE- No character comparison is used.
*RCD- Compares against the record data at the starting position.
*FLD- Same as *RCD.
*EQ- Equal.
*GT- Greater than.
*LT- Less than.
*NE- Not equal.
*GE- Greater than or equal.
*NL- Not less than.
*LE- Less than or equal.
*NG- Not greater than.
*CT- Contains; scans from the starting position to the end of the field or record.
Elements in order
Field
Field
Suggested / special values:
*RCD, *FLD
Character position
Character position
Relational operator
Relational operator
Allowed values:
*EQ, *GT, *LT, *NE, *GE, *NL, *LE, *NG, *CT
Value
Value
INCREL
Include records by field test
Selects records by testing whether fields satisfy relationships. Up to 50 sets of four values: logical relationship, field name, relational operator and value.
*NONE- No field value relationships are used.
*IF- Must be the first value of a set of comparisons.
*AND- Both groups on either side must be satisfied.
*OR- Either group on either side satisfied is enough.
*NULL- Tests whether the field is null (*EQ) or not null (*NE); only those two operators are allowed with it.
Elements in order
Relationship
Relationship
Allowed values:
*IF, *AND, *OR
Field
Field
Relational operator
Relational operator
Allowed values:
*EQ, *GT, *LT, *NE, *GE, *NL, *LE, *NG
Value
Value
Suggested / special values:
*NULL
FMTOPT
Record format field mapping
When copying a physical or logical from-file to a physical to-file, selects field-level mapping or dropping of fields.
Allowed values:
*NONE, *NOCHK, *CVTSRC, *MAP, *DROP, *CVTFLOAT, *NULLFLAGS
*NONE- No field mapping or dropping; valid when formats match or the files are not both database files.
*NOCHK- Copies data left to right despite format differences, without conversion; required to copy all formats of a multi-format logical file.
*CVTSRC- Converts between source and data file types; valid only when the types differ.
*MAP- Copies same-named fields and sets to-file fields absent from the from-file to defaults.
*DROP- Drops from-file fields that do not exist in the to-file; required when names do not all match.
*CVTFLOAT- Converts floating point fields from System/390 format to IEEE format.
*NULLFLAGS- Uses the byte after each null-capable field as a null flag.
SRCOPT
Source update options
For copying to a source physical file only: whether new sequence numbers are inserted and whether date fields are set to zero.
Allowed values:
*SAME, *SEQNBR, *DATE
*SAME- No new sequence numbers and no date zeroing; required when the to-file is not a source physical file.
*SEQNBR- Inserts new sequence numbers, controlled by SRCSEQ.
*DATE- Sets the source date field to zero.
SRCSEQ
Source sequence numbering
Used only with SRCOPT(*SEQNBR). Element 1 is the sequence number of the first copied record and element 2 the increment for the rest; both default to 1.00.
Elements in order
Starting sequence number
Starting sequence number
Increment number
Increment number
ERRLVL
Errors allowed
Maximum recoverable read or write errors tolerated per from-file member or tape label. The default of 0 ends the copy at the member where the first error occurs.
Suggested / special values:
*NOMAX
*NOMAX- No limit; all recoverable errors are tolerated.
COMPRESS
Compress out deleted records
Whether deleted records in the from-file are left out of the to-file. Must be *YES when the from-file is delete-capable and the to-file is not.
Allowed values:
*YES, *NO
*YES- Deleted records are not copied, so the to-file is compressed. Default.
*NO- Both deleted and non-deleted records are copied.
Examples
CPYF FROMFILE(PERSONNEL/PAYROLL) TOFILE(TESTPAY/PAYROLL) MBROPT(*ADD) CRTFILE(*YES) ERRLVL(10)
Copies all records of PAYROLL in PERSONNEL into TESTPAY/PAYROLL, creating the to-file if needed and adding to any existing records. The operation ends after more than ten recoverable errors.
CPYF FROMFILE(MYLIB/DATAFILE) TOFILE(QIDU/QTXTSRC) FROMMBR(A1) TOMBR(*FROMMBR) MBROPT(*REPLACE) FMTOPT(*CVTSRC)
Copies a data file into a source file, converting between the two file types. Sequence numbers start at 1.00 and increment by 1.00, and the source date field is set to zero.
Generated from os/cl/catalog/CPYF.json and os/cl/help/CPYF.json.