Can you look at what you wrote, and then re-write so that it is clearer.
The output from Frank's code gives the output you requested originally.
Where does the COND come into it? Are you saying that when there is only one record, you don't want a new summed record generated?
I'd be concerned that there is nothing on the file to indicate which records have been generated. You are generating trailers, but can't tell that it is a trailer (except by change of key). If you run the sort again, it'll just add up the total, including the already-generated total record. As Frank has said, you don't have much space with just two digits for the summing. Are you happy with that?