When you copy from a database file to a database file, you must use the FMTOPT parameter if the record formats are not identical or if the files are different types (source or data). If either file is a device file or inline data file, the FMTOPT parameter does not apply. The records are truncated or padded with blanks or zeros when record lengths are different. A message is sent if the records are truncated.
For database files, when either FMTOPT(*CVTSRC) or FMTOPT(*NOCHK) is specified and the record data copied from any from-file record is not long enough to fill a to-file record, the extra bytes in the to-file record are set to a default value. If a default value other than *NULL is specified in the DDS (DFT keyword) for a field, that field is initialized to the specified default; otherwise, all numeric fields are initialized to zeros, all character fields are initialized to blanks, all date, time, and timestamp fields are initialized to the current server date and time. If *NULL is specified on the DFT keyword, only the default buffer value is used. A *NULL default is ignored.
If the from-file or to-file is a device file or an inline data file, copy automatically adds or deletes the source sequence number and date fields for each record copied.
If one file is a data file and the other a source file, you must specify FMTOPT(*CVTSRC) to perform the copy. The sequence number and date fields are added or deleted as appropriate and the data part of each record is copied without regard to the other field definitions in the file record formats. The SRCSEQ parameter can be used to control how the sequence numbers are created, provided SRCOPT(*SEQNBR) is also specified.
Binary character fields are padded with zeros when using FMTOPT *MAP.
Dropping and mapping fields are based on a comparison of field names. Unless all the fields in the from-file have the same name in the to-file, you must specify *DROP. If the names are the same, but the attributes or position in the record is different, you must specify *MAP. Dropped fields are not copied. There must be at least one like-named field in both record formats to do mapping.
When *MAP is specified, fields in the to-file record format that do not exist in the from-file record format are filled with their default values, as described earlier in this section. For fields that have the same name and attributes, the field in the from-file record format is mapped to the field with the same name in the to-file record format, even if their positions in the formats are different.
For example, the field CUSNO is the first field in the record format ORDHD, but it is the second field in record format ORDHD1. When the CUSNO field is copied with *MAP, it is mapped to the second field of ORDHD1.
Table 1 summarizes the database-to-database copy operations for each value on the FMTOPT parameter.
FMTOPT parameter values (see note 4) | Database file record formats | ||||
---|---|---|---|---|---|
All field names in From-and To-Files are the same (like-named) | Some field names in From-and To-Files are the same | No field names in either file are the same | |||
Attributes and relative order also the same (see note 1) | Attributes and relative order not the same (see note 1) | Like-named fields have identical attributes and relative order (see note 1) | Not all like-named fields have identical attributes and relative order (see note 1) | ||
*NONE | Complete copy | Command ends | Command ends | Command ends | Command ends |
*DROP | Complete copy (value ignored) | Command ends | If there are extra fields in the from-file, they are dropped, all others are copied. If there are extra fields in the to-file, the command ends. If there are extra fields in the from-file and in the to-file, the command ends. | Command ends | Command ends |
*MAP (see note 2) | Complete copy (value ignored) | Complete copy (corresponding fields are mapped) | If there are extra fields in the from-file, the command ends. If there are extra fields in the to-file, they are filled, and the like-named fields are mapped. If there are extra fields in the to-file and the from-file, the command ends. | Command ends | |
*MAP and *DROP (see note 2) | Complete copy (value ignored) | Complete copy (corresponding fields are mapped) | Extra fields in the from-file are dropped; like-named fields are mapped; extra fields in the to-file are filled. | Command ends | |
*NOCHK | Complete copy (value ignored) | Complete copy (direct data transfer disregarding fields) (see note 3) | |||
Notes:
|