My requirement is to rewrite the count in the last/trailer record.
In my input file, there is a header, trailer and detail records.
first 3 characters specify if it is a header/trailer/detail.
001 - header record
002 - detail records
003 - trailer record
In my trailer record which would be the last record in the file, i have a count (8 digits from 7th position). I'm removing the duplicates in the jcl and sum certain fields. So, i need to rewrite the count now with correct count.
My sort card now looks like this..
Can we have the COUNT function with OVERLAY? Please comment...
Instead of using COUNT parameter, Can we do it in a single step by giving sequence number to each detail row and use the maximum of sequence number to overwrite in the last record? Is it possible?
Yes, it's possible but it does require adding a sequence number and then removing it. I'll leave it to you to code it up and test it. But here are some thoughts on how I think it could be done: You would have to add the sequence number with the OUTREC statement since you want the count of records after summing. The seqnum for the '003' (last) record will be equal to the count of the summed records. So you can use OUTFIL with IFTHEN for the '003' record to do the OVERLAY of the last seqnum, and finally remove the seqnum (you could do that with IFOUTLEN).
I need the count of detail records only. If i had used the seqnum, i would have got the count including header and trailer record. I should have started the SEQNUM with -1 so that i get the correct detail count in the last record. But the seqnum, seems can start only from 0.
I have used COUNT-2=(M11,LENGTH=8) to the existing step and used OVERLAY with IFTHEN as you have mentioned in the second step to rewrite the second step. Thanks.
Can we have the sequence number/count for a given condition?
For example, can we give sequence number/count only for records with first 3 characters as '002'?