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.
IFTRAIL Syntax
The syntax for the IFTRAIL operand of the OUTFIL statement is:
IFTRAIL=(TRLID=(logexp),TRLUPD=(c:item,…),HD=YES)
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.
TRLID=(logexp)
The criteria to be tested to determine if a record is the trailer record.
e.g. TRLID=(1,2,CH,EQ,C’99')
TRLUPD=(c:item,…)
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
COUNT=(edit) COUNT=(to) COUNT+n=(edit) COUNT+n=(to) COUNT-n=(edit) COUNT-n=(to) TOTAL=(p,m,f,edit) – TOTAL=(p,m,f,to) – TOT=(p,m,f,edit) TOT=(p,m,f,to)
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.
Benefits of IFTRAIL for Trailer Record Update
- 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.
INPUT: H 2020/01/06 D Field1 0100 D Field2 0200 D Field2 0118 D Field1 0150 D Field1 0025 D Field2 1000 D Field2 0310 T X 0007 QR 001903 D52-007-321-7526
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.
OUTPUT: OUTFIL1 H 2020/01/06 D Field1 0100 D Field1 0150 D Field1 0025 T X 0003 QR 000275 D52-007-321-7526 The trailer record has a count (0003) and total (000275) for the three included data records. OUTFIL2 H 2020/01/06 D Field2 0200 D Field2 0118 D Field2 1000 D Field2 0310 T X 0004 QR 001628 D52-007-321-7526 The trailer record has a count (0004) and total (001628) for the four included data records.
Example 2: VB file with trailer and without header.
INPUT Len|Data 14 D52 Frank 13 D51 Marc 16 E07 William 15 C21 Martin 17 H05 Sri Hari 37 999 2020-07-01 2020-07-06 3
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.
OUTPUT Len|Data 15 C21 Martin 13 D51 Marc 14 D52 Frank 16 E07 William 17 H05 Sri Hari 37 999 2020-07-01 2020-07-06 6
Example 3: Multiple FB files with header and trailer merged into one file.
INPUT FILE-1 0 27-80273-5218 1 MORGAN HILL CA -3.01 -1.07 1 ARMONK NY +6.22 +1.52 1 DETROIT MI +3.05 -5.61 9 COUNT=0003 TOTAL1=+06.26 TOTAL2=-05.16 FILE-2 0 27-80273-5218 1 BUFFALO NY -8.05 +3.83 1 GILROY CA +2.75 +1.97 9 COUNT=0002 TOTAL1=-05.30 TOTAL2=+05.80
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=(+,-))))
OUTPUT 0 27-80273-5218 1 GILROYÂ Â Â CA +2.75 +1.97 1 MORGAN HILL CA -3.01 -1.07 1 DETROIT Â Â MI +3.05 -5.61 1 ARMONKÂ Â Â NY +6.22 +1.52 1 BUFFALO Â Â NY -8.05 +3.83 9 COUNT=0005 TOTAL1=+00.96 TOTAL2=+00.64
Conclusion
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