AS400 table is a *FILE object, the CPYF command is used to copy all or part of the table structure in the database to another table. The following is the copy file command that I usually use:
Member Option > MBROPT
# MBROPT(*ADD) - Copy all record source files to the target file # MBROPT(*REPLACE) - Copy all the record source files to the target file starting with delete member files first
Create File > CRTFILE
# CRTFILE(*YES) - Create a new file in the target library # CRTFILE(*NO) - If file is already available in the target library
Copy From – To Record Number > FROMRCD – TORCD
# FROMRCD (*START/<rrn>) - *START if you want to copy the first record from the source file, or <rrn> relative record number if you want from a specific record number # TORCD (*END/<rrn>) - *END if you want to copy until the last record from the source file, or <rrn> relative record number if you want to reach a certain record number
Record Format Field Mapping – FMTOPT
This parameter is used if the source file format is different from the target file format # FMTOPT (*NOCHK) - Copy files based on the length of the existing records # FMTOPT (*MAP *DROP) - Copy files based on existing field names (*MAP) and ignore non-existent fields (*DROP)
Examples:
# CPYF FROMFILE(SRCLIB/SRCFILE) TOFILE(TGTLIB/TGTFILE) MBROPT(*ADD) CRTFILE(*YES) # CPYF FROMFILE(SRCLIB/SRCFILE) TOFILE(TGTLIB/TGTFILE) MBROPT(*ADD) # CPYF FROMFILE(SRCLIB/SRCFILE) TOFILE(TGTLIB/TGTFILE) MBROPT(*REPLACE) # CPYF FROMFILE(SRCLIB/SRCFILE) TOFILE(TGTLIB/TGTFILE) MBROPT(*ADD) FROMRCD(*START) TORCD(*END) # CPYF FROMFILE(SRCLIB/SRCFILE) TOFILE(TGTLIB/TGTFILE) MBROPT(*ADD) FROMRCD(10) TORCD(*END) # CPYF FROMFILE(SRCLIB/SRCFILE) TOFILE(TGTLIB/TGTFILE) MBROPT(*ADD) FMTOPT(*NOCHK) # CPYF FROMFILE(SRCLIB/SRCFILE) TOFILE(TGTLIB/TGTFILE) MBROPT(*ADD) FMTOPT(*MAP *DROP)