Using a REXX procedure with the Import utility

You can specify an existing REXX procedure, or create a new one, to further enhance the way in which data is selected and imported.

You can code any number of REXX statements and functions to manipulate the output record, select specific records, print reports and tally numeric values. If you are coding a REXX procedure, be aware that:
  • The import procedure is run after input template record selection is performed. The import procedure can cause a record (which would have been selected by the template selection process, if there was one) to be deselected for copying using RETURN DROP.
  • The import procedure is run after any field mapping or conversion supplied by a template has been performed.
  • If the record has been reformatted as a result of the template processing, the variable INREC contains the input record value and the variable OUTREC contains the reformatted output record.
  • Changes made by the import procedure to INREC are ignored. Changes made to OUTREC are used in the import process to load the Db2® table.
  • If using the PRINT() function, the template is determined as follows:
    • If an input template without an output template has been specified, the input template is used.
    • If an output template is specified, and the record value specified to print is the input record, the input template is used. Otherwise the output template is used.
    • If a record cannot be matched against the selected printing template, it is not printed.

Example 1

Import records, inserting a new field after column 40 for a length of 4.
  outrec = fld(1,40)||'    '||fld(41)

Example 2

Import records with type A and print the first 10. The type value is in column 6.
  if fld(6,1) = 'A' then do                       /* Type A?  */
     If prtcount() <= 10 then print(inrec,'CHAR') /* Print 10 */
     RETURN                                       /* Copy     */
  end
  return 'DROP'                                   /* Drop the rest */

Example 3

Change the output records to uppercase while importing.
  upper outrec

Related tasks