Is it possible to process a file/records until a specific total is reached?
For example, I have a file that has 100 records but I need to stop processing when a specific total, e.g., $100, has been reached or exceeded. The next file could have 25 records but same requirement......need to stop processing after $100 has been reached or exceeded.
File layout:
DD000000000000000000010000000000011000075
DD000000000000000000020000000000089000075
DD000000000000000000030000000000100000075
In this case the total was reached after the first two records, so no need to continue processing.
Let me know.
Thanks!
// EXPORT SYMLIST=*
//*
// SET LIMIT=100
//*====================================================================
//SORTSUM EXEC PGM=SYNCTOOL
//*
//SSMSG DD SYSOUT=*
//TOOLMSG 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
//*
//NUM1 DD SPACE=(TRK,(20,20))
//NUM2 DD SPACE=(TRK,(20,20))
//NUM12 DD SPACE=(TRK,(20,20))
//*
//SORTOUT DD SYSOUT=*
//*....................................................................
//TOOLIN DD *
COPY FROM(SORTIN) TO(NUM1) USING(SEQ1)
COPY FROM(SORTIN) TO(NUM2) USING(SEQ2)
SORT JKFROM TO(NUM12) USING(JOIN)
COPY JKFROM TO(SORTOUT) USING(DROP)
//*....................................................................
//SEQ1CNTL DD *
INREC OVERLAY=(81:SEQNUM,8,ZD,START=1) record nums from 1
//*....................................................................
//SEQ2CNTL DD *
INREC OVERLAY=(81:SEQNUM,8,ZD,START=2) record nums from 2
//*....................................................................
//JOINCNTL DD *
JOINKEYS F1=NUM1,FIELDS=(81,8,A),SORTED
JOINKEYS F2=NUM2,FIELDS=(81,8,A),SORTED
JOIN UNPAIRED,F1
REFORMAT FIELDS=(F1:1,80, full input record
F1:81,8, SEQNUM1
F2:41,8) prev record amount
* Calculate running SUM
INREC BUILD=(81,8, SEQNUM1
10:41,08,ZD,ADD,89,8,ZD,TO=ZDF,LENGTH=8)
SORT FIELDS=(1,8,CH,A) - make sure JOIN did not change the order
//*....................................................................
//DROPCNTL DD *,SYMBOLS=EXECSYS
JOINKEYS F1=NUM1,FIELDS=(81,8,A),SORTED numbered input
JOINKEYS F2=NUM12,FIELDS=(1,8,A),SORTED,
INCLUDE=(10,8,ZD,LE,&LIMIT) allowed SEQNUMs
REFORMAT FIELDS=(F1:1,80) = initial record
//*
//*====================================================================