DFSORT is working on one record at a time. You know by the time the sixth arrives, that you need the previous five.
How would you do that in COBOL? You'd store the data in WORKING-STORAGE, and if an appropriate sixth record turned up, you'd have the other five ready.
DFSORT doesn't have any WORKING-STORAGE. If something needs storing, the only place is to store it on a record (extending, temporarily, your current record).
How do you get data from one record to another? Only possible with WHEN=GROUP and PUSH. You need five records, so you'll need five WHEN=GROUP and PUSH.
The first WHEN=GROUP has to mark your actual group of records, so you use BEGIN with a value that uniquely (for this type of group) defines the start of a group, which looks to be "***INPUT STATEMENT: ". For this you need to PUSH a sequence number (SEQ). You don't need to PUSH the data, because it is a literal value, which you can include later. You are interested in groups of six records, so use RECORDS=6 on the GROUP.
Your PUSH is PUSH=(onebyteafterrecord:SEQ=1). The "=1" is a length of one, so can hold 1-9m before flipping to zero, which is enough space for you.
Your second WHEN=GROUP uses the value of the SEQ established by the first PUSH. If it has a value of two, that defines the group. It needs to PUSH the data. There are only five records left in the group, so code RECORDS=5.
Your PUSH is PUSH=(nextavailablebyte:1,lengthofrecord).
Your third WHEN=GROUP uses the value of the SEQ established by the first PUSH. If it has a value of thee, that defines the group. It needs to PUSH the data. There are only four records left in the group, so code RECORDS=4.
See the pattern? Continue it, it finishes with RECORDS=2.
You now have a long record, the sixth of which in a group contains the previous four records, and one more that you can construct from a literal. You then need to be able to write multiple records from a single input record. This can only be done in OUTFIL, with the / (Slash Operator).
So, you code OUTFIL, You need to use INCLUDE= to identify the sixth record and use BUILD, like this:
... again you note, and continue, the pattern
1,length of input record)
OK. That is a lot to take in. Take it a bit at a time. Try with a very simple test file:
The idea is to extract the two groups of records which start with "1" and end in "6". The data is only one byte long, for ease of testing.
Do each line of code one at a time and see how it builds on the output.
Here's a start. Put the test file under //SORTIN DD * and use //SORTOUT DD SYSOUT=*, and look at the output you get in the spool.
Then add the next line, to define the group which starts with "2". Then the next.
By the time you've got through the test data, you'll have done something pretty complex, and learned a lot.