IFTRAIL

IFTRAIL parameter is used to update count and total values in an existing trailer (last) record to reflect the actual data records in the output data set using COUNT and TOTAL features of TRAILER1. TRAILER1 lets you build a new trailer record but IFTRAIL lets you update an existing trailer record. When you specify IFTRAIL in DFSORT, it means “If Trailing,” It controls the processing of trailing records in the input data. So, if your input data contains trailing records (records that do not conform to the standard length), the IFTRAIL parameter allows you to include them in the output.

The syntax for the IFTRAIL operand of the OUTFIL statement is:

Note: TRLID and TRLUPD are mandatory. HD=YES is optional.

IFTRAIL can’t be used with HEADER1, TRAILER1, HEADER2, TRAILER2, NODETAIL, SECTIONS, LINES, SPLIT, SPLITBY, SPLIT1R, REPEAT, FTOV, VTOF, VLTRIM or VLFILL in OUTFIL.

The criteria to be tested to determine if a record is the trailer record.

e.g. TRLID=(1,2,CH,EQ,C’99')

The position where each count or total is to be updated in the trailer record.

  • For VB records, input and output byte starts at position 5, as the RDW in positions 1-4. 
  • For FB records it will start at position 1. 
  • The original length of the trailer record will not be changed for output using TRLUPD. If an item beyond the end of the trailer record, it will not be updated.

c: specifies the output position (column) in the trailer record to be updated. If not specified it defaults to 1:

Any of the following count and total items can be used as described for TRAILER1

HD=YES:  The header (first) record will not be used to determine the count or totals. In IFTRAIL identified trailer record will not be used to determine the count or totals.

Note: For HD=YES, OUTFIL processing for INCLUDE, OMIT, BUILD, OVERLAY etc. will be bypassed for the header record. If HD=YES is specified, the TRLID test will not be applied to the first record.

  • Inclusive Processing: The ability to include trailing records ensures comprehensive processing, especially in scenarios where the dataset may contain non-standard records at the end.
  • Flexibility in Record Handling: By leveraging IFTRAIL, you have the flexibility to tailor the treatment of trailing records based on your specific sorting or merging requirements.

Example 1: FB file with Header & Trailer splitted into two output files.

OPTION COPY
OUTFIL FNAMES=OUTFIL1,
INCLUDE=(3,6,CH,EQ,C'Field1'), 
IFTRAIL=(HD=YES,TRLID=(1,1,CH,EQ,C'T'),
TRLUPD=(6:COUNT=(M11,LENGTH=4), 
                14:TOT=(10,4,ZD,TO=ZD,LENGTH=6)))
OUTFIL FNAMES=OUTFIL2, 
INCLUDE=(3,6,CH,EQ,C'Field2'), 
IFTRAIL=(HD=YES,TRLID=(1,1,CH,EQ,C'T'),
TRLUPD=(6:COUNT=(M11,LENGTH=4), 
                14:TOT=(10,4,ZD,TO=ZD,LENGTH=6)))
  • IFTRAIL tells DFSORT to update the trailer record.
  • INCLUDE includes the records with Field1 (for OUTFIL1) or Field2 (for OUTFIL2).
  • HD=YES indicates the first record is a header record. The header record will be output without change and its fields will not be used for the count or total. If the input data set has a header, you must use HD=YES to avoid treating the header record as a data record.
  • TRLID=(logexp) identifies the trailer record as having a ‘T’ in position 1. The identified trailer record is treated as the last record; it is not treated as a data record.
  • TRLUPD indicates the counts and totals to be updated.

Example 2: VB file with trailer and without header.

SORT FIELDS=(5,3,CH,A)
OUTFIL IFTRAIL=(TRLID=(5,3,CH,EQ,C'999'),
TRLUPD=(34:COUNT+1=(EDIT=(IIIT))))
 
Note: As IFTRAIL does not process the trailer record as a data record & as we want the trailer record included in the count, we use COUNT+1 in TRLUPD.

Example 3: Multiple FB files with header and trailer merged into one file.

SORT FIELDS=(1,1,CH,A,17,2,CH,A,3,12,CH,A) 
OUTFIL OMIT=(1,1,CH,EQ,C'0'),
IFTRAIL=(HD=YES,TRLID=(1,1,CH,EQ,C'9'), 
TRLUPD=(9:COUNT=(M11,LENGTH=4),
       22:TOT=(21,5,SFF,EDIT=(STT.TT),SIGNS=(+,-)), 
       37:TOT=(28,5,SFF,EDIT=(STT.TT),SIGNS=(+,-))))

Understanding and effectively using the IFTRAIL parameter in DFSORT is crucial for managing trailer records during data processing tasks. Whether you are sorting, merging, or performing other operations, incorporating IFTRAIL appropriately ensures that your processing is thorough and accurate.

Read Trailer & Header – Click Here     SyncSort Manual: Click Here

Scroll to Top