| Copy File (CPYF) command in AS400 |
A Brief Introduction
The Copy file (CPYF) command copies all or some part of data from one database file to the other database file.
CPYF command parameters
Copy File (CPYF)
Type choices, press Enter.
From file . . . . . . . . . . . FROMFILE
Library . . . . . . . . . . . *LIBL
To file . . . . . . . . . . . . TOFILE
Library . . . . . . . . . . . *LIBL
From member . . . . . . . . . . FROMMBR *FIRST
To member or label . . . . . . . TOMBR *FIRST
Replace or add records . . . . . MBROPT *NONE
Create file . . . . . . . . . . CRTFILE *NO
Print format . . . . . . . . . . OUTFMT *CHAR
Additional Parameters
Which records to print . . . . . PRINT *NONE
+ for more values
Record format of logical file . RCDFMT *ONLY
Copy from record number . . . . FROMRCD *START
Copy to record number . . . . . TORCD *END
Copy from record key: FROMKEY
Number of key fields . . . . . *NONE
Key value . . . . . . . . . .
+ for more values
Copy to record key: TOKEY
Number of key fields . . . . . *NONE
Key value . . . . . . . . . .
+ for more values
Number of records to copy . . . NBRRCDS *END
Include records by char test: INCCHAR
Field . . . . . . . . . . . . *NONE
Character position . . . . . .
Relational operator . . . . .
Value . . . . . . . . . . . .
Include records by field test: INCREL
Relationship . . . . . . . . . *NONE
Field . . . . . . . . . . . .
Relational operator . . . . .
Value . . . . . . . . . . . .
+ for more values
Record format field mapping . . FMTOPT *NONE
Source update options . . . . . SRCOPT *SAME
Source sequence numbering: SRCSEQ
Starting sequence number . . . 1.00
Increment number . . . . . . . 1.00
Errors allowed . . . . . . . . . ERRLVL 0
Compress out deleted records . . COMPRESS *YES
Record format field mapping (FMTOPT)
We need to specify this option when we are copying physical files or logical files to the physical file or copying data between data file and source file.
*NONE
*NOCHK
*CVTSRC
*MAP
*DROP
Examples
Now we will see several examples to better understand how Copy File (CPYF) command actually works.
Copy Physical file to physical file with all records in the first member
The following command will be used:
CPYF FROMFILE(EASYCLASS1/FILE1)
TOFILE(EASYCLASS2/FILE1)
MBROPT(*ADD)
CRTFILE(*YES)
ERRLVL(5)
Copy Physical file to physical file with different Record Format
The following command will be used:
CPYF FROMFILE(EASYCLASS1/FILE1)
TOFILE(EASYCLASS2/FILE1)
FROMMBR(*ALL)
TOMBR(*ALL)
MBROPT(*ADD)
FMTOPT(*MAP *DROP)
ERRLVL(5)
Copy Physical data file to physical source file
The following command will be used:
CPYF FROMFILE(EASYCLASS1/FILE1)
TOFILE(EASYCLASS2/QDDSSRC)
FROMMBR(FILE1)
TOMBR(*FROMMBR)
MBROPT(*REPLACE)
FMTOPT(*CVTSRC)
Copy Logical file to physical file
The following command will be used:
CPYF FROMFILE(EASYCLASS1/FILE1LF)
TOFILE(EASYCLASS2/FILE1)
FROMMBR(FILE1)
TOMBR(FILE1)
RCDFMT(RFILE1)
MBROPT(*REPLACE)