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

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.

Type
*QUAL
Required
Yes
Case
Uppercase
*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

Type
*NAME
Required
No
Length
10
Case
Uppercase

Library Library

Type
*NAME
Required
No
Default
*LIBL
Length
10
Case
Uppercase

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.

Type
*QUAL
Required
Yes
Case
Uppercase
*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

Type
*NAME
Required
No
Length
10
Case
Uppercase

Library Library

Type
*NAME
Required
No
Default
*LIBL
Length
10
Case
Uppercase

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.

Type
*GENERIC
Required
No
Default
*FIRST
Length
10
Case
Uppercase

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.

Type
*NAME
Required
No
Default
*FIRST
Length
10
Case
Uppercase

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.

Type
*CHAR
Required
No
Default
*NONE
Length
8
Case
Uppercase

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.

Type
*CHAR
Required
No
Default
*NO
Length
4
Case
Uppercase

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.

Type
*CHAR
Required
No
Default
*CHAR
Length
5
Case
Uppercase

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.

Type
*CHAR
Required
No
Default
*NONE
Length
7
List limit
3
Case
Uppercase

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.

Type
*NAME
Required
No
Default
*ONLY
Length
10
Case
Uppercase

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.

Type
*UINT4
Required
No
Default
*START
Case
Uppercase

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.

Type
*UINT4
Required
No
Default
*END
Case
Uppercase

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.

Type
*ELEM
Required
No
Case
Uppercase
*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

Type
*INT4
Required
No
Case
Uppercase

Suggested / special values: *BLDKEY

Key value Key value

Type
*CHAR
Required
No
Length
50
List limit
50
Case
Uppercase

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.

Type
*ELEM
Required
No
Case
Uppercase
*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

Type
*INT4
Required
No
Case
Uppercase

Suggested / special values: *BLDKEY

Key value Key value

Type
*CHAR
Required
No
Length
50
List limit
50
Case
Uppercase

NBRRCDS Number of records to copy

How many records are copied to the to-file.

Type
*UINT4
Required
No
Default
*END
Case
Uppercase

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.

Type
*ELEM
Required
No
Case
Uppercase
*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

Type
*NAME
Required
No
Length
10
Case
Uppercase

Suggested / special values: *RCD, *FLD

Character position Character position

Type
*INT4
Required
No
Case
Uppercase

Relational operator Relational operator

Type
*CHAR
Required
No
Length
3
Case
Uppercase

Allowed values: *EQ, *GT, *LT, *NE, *GE, *NL, *LE, *NG, *CT

Value Value

Type
*CHAR
Required
No
Length
50
Case
Uppercase

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.

Type
*ELEM
Required
No
Case
Uppercase
*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

Type
*CHAR
Required
No
Length
4
Case
Uppercase

Allowed values: *IF, *AND, *OR

Field Field

Type
*NAME
Required
No
Length
10
Case
Uppercase

Relational operator Relational operator

Type
*CHAR
Required
No
Length
3
Case
Uppercase

Allowed values: *EQ, *GT, *LT, *NE, *GE, *NL, *LE, *NG

Value Value

Type
*CHAR
Required
No
Length
50
Case
Uppercase

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.

Type
*CHAR
Required
No
Default
*NONE
Length
10
List limit
2
Case
Uppercase

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.

Type
*CHAR
Required
No
Default
*SAME
Length
7
List limit
2
Case
Uppercase

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.

Type
*ELEM
Required
No
Case
Uppercase
Elements in order

Starting sequence number Starting sequence number

Type
*DEC
Required
No
Default
1.00
Length
6, 2 decimals
Range
0.01 to 9999.99
Case
Uppercase

Increment number Increment number

Type
*DEC
Required
No
Default
1.00
Length
6, 2 decimals
Range
0.01 to 9999.99
Case
Uppercase

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.

Type
*UINT4
Required
No
Default
0
Case
Uppercase

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.

Type
*CHAR
Required
No
Default
*YES
Length
4
Case
Uppercase

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.

IBM command documentation

Generated from os/cl/catalog/CPYF.json and os/cl/help/CPYF.json.