You have:
SORT FIELDS=COPY
OPTION COPY
OUTFIL REMOVECC,NODETAIL,
TRAILER1=(1,2,'ON',8,3,'=',COUNT=(M11,LENGTH=10)))
First problem is you have SORT FIELDS=COPY
and OPTION COPY
. These mean the same thing. Remove one or the other (I tend to use OPTION COPY).
Next, you have a spare right parenthesis.
Then you are using TRAILER1. There are three types of TRAILERn: 1 is "at the end of the report"; 2 is at the end of a page; 3 is at a control break.
You use TRAILER1, so at the end of your file you get one record, containing file totals.
After that, your positions for the TRAILER1 match the output, not the input file.
Which brings us to the fact that you are not running those Sort control cards with that data. The control cards have a syntax error which means they don't run. Correcting the cards and retaining the TRAILER1 gets AAON567=0000000007
.
Which brings us to the control break, which is what you have missing.
You define a control break with SECTIONS. TRAILER3 is part of SECTIONS.
Fixing everything except your output format:
OPTION COPY
OUTFIL REMOVECC,NODETAIL,
SECTIONS=(1,2,
15,3,
TRAILER3=(1,2,
'ON',
15,3,
'=',
COUNT=(M11,
LENGTH=10)))
Which gives you:
AAON123=0000000002
AAON456=0000000001
BBON123=0000000002
BBON789=0000000001
AAON567=0000000001
If you want column headings, look at how to use HEADER3 (HEADER1 and HEADER2 would also work in this simple case). If you want "page totals" look at TRAILER2. If you want file totals, use TRAILER1.