Thanks for your reply. My requirement is not to print the trailer record.
If a matching record is found from the input file, then I will have to copy the matching record(s) from input to output file (for e.g. Here, I used INCLUDE COND to copy only the matching records).
If there are no matching records, then I will have to set a default value of '000' with a string.
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
TRAILERn can be used to add a final record at the end of the file. There is no magic that DFSORT knows about to distinguish between what you call a "trailer" and what you call the "matching record".
//**********************************************************************
//SPLITFLS EXEC PGM=ICETOOL
//**********************************************************************
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD *
LINE1
LINE2
NUMBER OF RECS: 100
NUMBER OF RECS: 200
/*
//OUT DD SYSOUT=*
//TOOLIN DD *
SUBSET FROM(IN) TO(OUT) INPUT KEEP LAST(1) USING(CTL1)
/*
//CTL1CNTL DD *
OUTFIL FNAMES=OUT,IFTHEN=(WHEN=(1,15,CH,EQ,C'NUMBER OF RECS:'),
BUILD=(1,80)),
IFTHEN=(WHEN=NONE,
OVERLAY=(1:C'NUMBER OF RECS: 000',61X))
/*
The above code works very well. However, if the input file has more than 1 matching record as shown above, then I am not able to copy all the matching records into output file as we had used LAST(1). How could we handle when there are more than 1 matching record?
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
Well, the first way to do it is to tell us that that situation can exist and include it in your sample data in your initial post. Otherwise we expend effort without reason, and the thing just goes back-and-forth like this.