// EXPORT SYMLIST=*
//*
// SET LIMIT=100 desired limit for accumulated sum
//*====================================================================
//SORTSUM EXEC PGM=SYNCTOOL
//*
//TOOLMSG DD SYSOUT=*
//SSMSG DD SYSOUT=*
//SORTIN DD *
AAAAAAAA 1234567890 ZZZZZZZZ 9876543210 00000011 XXXXXXXX
QQQQQQQQ 2345678901 DDDDDDDD 8765432109 00000089 HHHHHHHH
CCCCCCCC 3456789012 NNNNNNNN 7654321098 00000100 KKKKKKKK
YYYYYYYY 4567890123 PPPPPPPP 6543210987 00000125 JJJJJJJJ
//*-+----1----+----2----+----3----+----4----+----5----+----6----+----7
//*
//SUB1 DD SPACE=(TRK,(20,20)) (update the size as per your data amounts)
//SUB1@ DD SYSOUT=* (replace with DUMMY after debugging)
//*
//SORTOUT DD SYSOUT=* (replace with real output dataset after debugging)
//SORTOUT@ DD SYSOUT=* (replace with DUMMY after debugging)
//*....................................................................
//TOOLIN DD *
COPY FROM(SORTIN) TO(SUB1) USING(SUBT)
COPY FROM(SUB1) TO(SORTOUT) USING(DROP)
//*....................................................................
//SUBTCNTL DD *
INREC OVERLAY=(81:SEQNUM,8,ZD, renumber for unique id
89:8X) space for trailer
OUTFIL FNAMES=(SUB1,SUB1@), parallel printing the log to debug
REMOVECC,NODETAIL,
SECTIONS=(81,8, unique num for each record
TRAILER3=(1,80, original record part
SUBTOTAL=(41,8,ZD,EDIT=(TTTTTTTT)))) running sum
//*....................................................................
//DROPCNTL DD *,SYMBOLS=EXECSYS
INREC IFTHEN=(WHEN=GROUP, detect the group of records needed
BEGIN=(81,8,ZD,EQ,41,8,ZD),
END=(81,8,ZD,GE,&LIMIT),
PUSH=(89:ID=4))
OUTFIL FNAMES=SORTOUT@ print row data to trace and debug
OUTFIL FNAMES=SORTOUT, reformat and filter real output data
INCLUDE=(89,4,CH,NE,C' '), select records from the marked group
BUILD=(1,80) truncate to original LRECL
//*
//*====================================================================