Are the the keys witing a group both unique across your data and solely contiguous within the group. Ie, when you SORT on 1,16, are any records from on group going to be mixed in with another. Is it possible?

Are the HEADERs for the groups on the two files always identical for a group?

Do the TRAILERs simply contain the word TRAILER, or some other "constant" value, or what?

to get unpaired records from file-1 (detail records) and matched records also from file-1 (header and trailer).

I'm sorry, but I didn't fully understand this part. Do you mean you need all the unpaired records from File1 with Header and Trailer. What if File1 and File2 have some matching records apart from Header and Trailer?

We can very well provide solutions to the example data provided, but most of the time, it may not be realistic. Say for example, the HEADER/TRAILER records may not exactly be the same in the real input files. So the solution provided should be based on realistic data capable of handling all input scenarios. That is the whole idea behind asking questions and nothing was answered here. Any solution provided without knowing the characteristics of real data would be solely based on assumptions and cannot be expected to work as intended.

This will extract the header and trailer records into output if you are doing a JOIN,UNPAIRED,F1. But you need to add logic to retain the order of header and trailer records. The 'solution' provided does not handle this.

Or if the header and trailer records have static data, we can have a JOIN UNPAIRED,F1,ONLY and hard-code the header and trailer records using OUTFIL HEADER1/TRAILER1.

But with the OP ignoring all the questions/details requested, one can only guess.

Bill/Arun, there are no multiple groups within this file. There is always one header and trailer with detail records in between. I wonder if it is still achievable if the starting letter is some B or P.