Page 2 of 2

Re: Process file/records until a specific total is reached.

PostPosted: Wed Mar 30, 2022 7:40 pm
by chillmo
Yes, and this works great....thanks for your assistance.

Furthermore, the business changed the requirement to "equal to BUT NOT exceeding the amount, e.g., $100". So, I changed the following code to achieve the desired result:

END=(81,8,ZD,LE,&LIMIT),
 


However, it only contained one record, so I'll continue to tweak the code until I reach the desired results.

You're the best!

Re: Process file/records until a specific total is reached.

PostPosted: Wed Mar 30, 2022 10:11 pm
by sergeyken
You can add extra output statements to print intermediate results, to help debugging your version of code.
This is a typical approach for any software engineer who tries to create his own code, not only copying existing code from others.

Like this sample
// 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                                               
//*                                                                    
//*====================================================================

Re: Process file/records until a specific total is reached.

PostPosted: Wed Mar 30, 2022 10:12 pm
by sergeyken
chillmo wrote:Yes, and this works great....thanks for your assistance.

Furthermore, the business changed the requirement to "equal to BUT NOT exceeding the amount, e.g., $100". So, I changed the following code to achieve the desired result:

END=(81,8,ZD,LE,&LIMIT),
 


However, it only contained one record, so I'll continue to tweak the code until I reach the desired results.

You're the best!


Try to think about the logic of this code.