OUTFIL


The OUTFIL statement is a powerful feature used to control the formatting, filtering, and output of records after they have been processed by SORT, MERGE, or COPY operations. OUTFIL statements can be used with different INCLUDE or OMIT and OUTREC, OVERLAY, or IFTHEN parameters to create different OUTFIL files.

Purpose -

  • Splitting output datasets: we can split a dataset into multiple output files based on conditions.
  • Reformatting records: we can manipulate the layout of the records, add constants, or change data formats.
  • Summarization and reporting: OUTFIL can generate summary data, totals, and formatted reports.
  • Filtering: we can apply conditions to include or omit specific records in the output.

Processing Steps -

The following tasks are performed in the order they specified with each OUTFIL statement -

  1. Repeating records with the REPEAT parameter.
  2. Creating detailed reports using the BUILD, OUTREC, OVERLAY, IFTHEN, HEADERn, TRAILERn, SECTIONS, LINES, NODETAIL, BLKCCH1, BLKCCH2, BLKCCT1, and REMOVECC parameters.
  3. Selecting a sequential subset of records with the STARTREC and ENDREC parameters.
  4. Limit the number of records selected with the ACCEPT parameter.
  5. Selecting a sample of records with the SAMPLE parameter.
  6. Selecting "discarded" records with the SAVE parameter saves any records that are not selected as a result of STARTREC, ENDREC, SAMPLE, INCLUDE, OMIT, or ACCEPT parameters.
  7. Selecting a subset of records with the INCLUDE and OMIT parameters.
  8. Reformat records with fixed position/length fields or variable position/length fields using the PARSE, BUILD, OUTREC, OVERLAY, or IFTHEN parameters.
  9. Splitting records between output files using the SPLIT, SPLITBY, and SPLIT1R parameters.
  10. Converting the records FB to VB with the FTOV parameter, or VB to FB with the VTOF parameter.
  11. Update count and total values in an existing trailer (last) record with the IFTRAIL parameter.

Syntax -

//SYSIN DD * 
OUTFIL FNAMES=ddname,INCLUDE=cond,OMIT=cond,
       BUILD=(fields_to_build record),
       OUTREC=(fields_to_build record),
       NODETAIL,REMOVECC,
       TRAILER1=constant_value,
       HEADER1=constant_value,
       SECTIONS=(key_start,key_length,FORMAT=type),
       SPLITBY=(n),
       OVERLAY=(modifies_specific_fields_data)
/*
  • FNAMES=ddname: Specifies the output file (corresponding to a DD statement) where the records will be written.
  • INCLUDE=cond or OMIT=cond: Specifies conditions to include or omit records in the output.
  • BUILD or OUTREC: Specifies how the fields in the input records should be arranged in the output.
  • REMOVECC: Removes carriage control characters from the output.
  • HEADER1 or TRAILER1: Used to add header or trailer lines to the output.
  • SECTIONS: Allows us to create sections based on key fields, each section with its own totals or headers.
  • SPLITBY: Allows us to split the output into multiple files based on record count.
  • OVERLAY: Modifies specific parts of the output record.

Examples -


Scenario1 - Basic OUTFIL with Filtering

//SYSIN   DD  *
  SORT FIELDS=(1,10,CH,A)
  OUTFIL FNAMES=SORTOUT,INCLUDE=(1,3,CH,EQ,C'XYZ')
/*

The records are sorted based on the first 10 bytes in ascending order. Only records where the first 3 characters are equal to 'XYZ' are written to the output dataset (SORTOUT).

Scenario2 - OUTFIL with BUILD for Reformatting

//SYSIN   DD  *
  SORT FIELDS=(1,10,CH,A)
  OUTFIL FNAMES=SORTOUT,BUILD=(1,5,15,10,40:C'FIXED')
/*

Copies the first 5 bytes from the input record starting at position 1, the 10 bytes starting from position 15 and inserts the constant 'FIXED' starting at position 40 in the output.

Scenario3 - OUTFIL with SPLITBY

//SYSIN   DD  *
  SORT FIELDS=(1,10,CH,A)
  OUTFIL FNAMES=OUT1,SPLITBY=1000
  OUTFIL FNAMES=OUT2
/*

The first 1000 records are written to the dataset MATEPK.OUTPUT.FILE1. The remaining records are written to the dataset MATEPK.OUTPUT.FILE2.