How to Use TRLUPD in DFSORT

Here is the sample code on how to update trailer counts in a input file using DFSORT.

How can I update the count and total in the existing trailer record to reflect the
output data records?

Use TRLUPD to Update Counts and Totals

For example, my input file has these records:

H 10/12/2010
D key1 0100
D key1 0300
D key2 0200
D key2 0050
D key1 0625
D key1 0300
D key2 3000
T DEPT AXY COUNT=00000007 TOTAL=004575

The trailer record (identified by T in position 1) has the count of the D records in positions 18-25 and the total of the third field of the D records in positions 33-38. I want to keep only the key1 records and update the count and total in the existing trailer records accordingly. So the output I want is:
H 10/12/2010
D key1 0100
D key1 0300
D key1 0625
D key1 0300
T DEPT AXY COUNT=00000004 TOTAL=001325

Can I do this with DFSORT?

You can use DFSORT's IFTRAIL function to do this kind of thing quite easily like this:
 //S1 EXEC PGM=SORT
 //SYSOUT DD SYSOUT=*
 //SORTIN DD DSN=... input file (FB/40)
 //SORTOUT DD DSN=... output file (FB/40)
 //SYSIN DD *
 OPTION COPY
 OUTFIL INCLUDE=(3,4,CH,EQ,C'key1'),
 IFTRAIL=(HD=YES,TRLID=(1,1,CH,EQ,C'T'),
 TRLUPD=(18:COUNT=(M11,LENGTH=8),33:TOT=(8,4,ZD,M11,LENGTH=6)))
 /*

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.