How do I export data using a copybook that describes a different data format to that used by the FM/Db2 Export Utility?

Scenario: I have data in a Db2® table. I want to export data using a copybook that I have defined, but the copybook describes a different data format to that used by the FM/Db2 Export Utility.

You need to code the copybook in either COBOL, HLASM, or PL/I. When you perform the export with the FM/Db2 Export Utility (3.7), enter the name of the data set that contains the copybook in the To Copybook or Template section on the Export To panel. Set the Template usage processing option to 1 (Above). If you specify 4 (Generate and save), your copybook will be overwritten. If you have renamed the fields in the copybook, or if data type conversions are required, use template re-mapping to map columns in the source table to fields in the target data set.

If the Db2® data contains one or more nullable columns, you are restricted in the processing for the Db2® null indicator. If you need the Db2® null indicator in the exported data, you must include a 2-byte binary field immediately after the definition for the field in the template that corresponds to the column.

For example, for a CHAR(10) field that allows for the Db2® null value, you would code:
* CHARACTER DATA TYPE
     10 COL7                 PIC X(10).
     10 COL7-NULL            PIC S9(4) USAGE COMP.

In addition, the 2-byte field must be un-mapped when the export begins. In other words, you must not map a column of the table to this field using template re-mapping; if you do, the FM/Db2 Export Utility does not include the null indicator for the column in the exported data set.

If you want the Db2® null indicator mapped to a different position in the export data set, or you want the Db2® null indicator converted into a different data type, you can:

  1. Export the data using either the default mapping, or using a user-defined copybook that includes fields defined for the Db2® null indicators as described above.
  2. Create a template that describes the final data format.
  3. Use File Manager base to copy the data from the export data set into the final format. You may need to use REXX to convert the Db2® null indicators (and possibly other data values) as part of the copy process.

Related tasks

Related references