OK, three OUTFILs.
The first outputs the first part of each record.
The second contains 40 IFTHEN=(WHEN=(logicalexpressions) testing the value of your count, and uses the slash-operator (/) to output the correct number of records.
The third also contains 40 IFTHEN=(WHEN=(logicalexpressions) also testing the value of your count and outputs the trailer from the correct location.
A variation on that, especially if you have DFSORT 2.1, would be to extend the record to maximum length and then use PARSE, where you can use a repetition. Your trailer-data would exist in two PARSEd fields. You'd still need the 80 IFTHENs to identify which PARSEd fields to use when and for what, but the negative influence of typos would be reduced.
You could look at using ICETOOL's RESIZE, but that would require another pass of the data to make the records fixed-length, then in a USING on the RESIZE you'd have to format each part to the maximum length (80 bytes, your main data). In three OUTFILs in the USING, you'd then do roughly my first suggestion, but you'd not be able to use SAVE as there will always be blank records to ignore completely. You'd need to be able to identify the record-types, so may require the addition of a marker (depending on your data).