Null-capable fields using FMTOPT(*MAP) or FMTOPT(*NOCHK)
You can use FMTOPT(*MAP) or FMTOPT(*NOCHK) for null-capable fields. The copy operation is handled differently according to your settings. FMTOPT(*MAP) or FMTOPT(*NOCHK) must be specified on the CPYF command if:
- The from-file is a database data file.
- The to-file is a physical data file.
- The record formats are not identical.
For the record formats to be identical, corresponding fields in the from-file and to-file must both be null-capable or not null-capable. For the CPYFRMQRYF command, the same is true except that the open query file record format is used (rather than a from-file format). When you use FMTOPT(*MAP):
- Null values are copied from null-capable from-file fields to null-capable to-file fields that are named alike. This copying can only happen if the field attributes and lengths are compatible.
- Fields that are not null-capable can also be copied from and to null-capable fields, provided the field attributes and lengths are compatible. The results to expect in the to-file field are:
- Copying a null-capable field to a null-capable field
Null values in the from-file field are copied to the to-file field. Values that are not null in the from-file field are also copied to the to-file field. For values that are not null in the from-file field that cause conversion errors during the copy, the default value of the to-file field is placed into the to-file field.
- Copying a field that is not null capable to a null-capable field
Values that are not null in the from-file field are copied to the to-file field. For values in the from-file field that cause conversion errors during the copy operation, the default value of the to-file field is placed into the to-file field.
- Copying a null-capable field to a field that is not null capable
Values that are not null in the from-file field are copied to the to-file field. If a conversion error occurs when copying values that are not null or the from-file field value is null, the to-file field default value is placed into the to-file.
When you use FMTOPT(*NONE), the null values in the from-file are copied to the to-file when copying a database file to a physical data file with identical record formats.
When you use FMTOPT(*DROP), the null values are copied.
When you use FMTOPT(*NOCHK) or FMTOPT(*CVTSRC), the record data is copied directly from left to right into the to-file without any regard to field types. Null values are not copied if *NOCHK or *CVTSRC is specified, because the record formats need not be identical. Either a user-specified or default value is copied to the to-file rather than a null value.
Parent topic:
Specifying data for different field types and attributes