Page 1 of 1

Need help with WHEN=GROUP

PostPosted: Wed Sep 27, 2017 2:04 am
by rmd3003
This is something that I need help with:
Input data has group of records and I need to delete "orphan records" within this group.
Grouping is on position 1,10.
Position 12,3 is to identify record type.
If there is group where there is no record type "001" (only type "009") then I want them to be deleted and written to a new file.
In example below 2 records "0000001111" need to be deleted as they don't have type "001".


----+----1----+----2----+----3
0000000000 001                
0000000000 009                
0000000000 009                
0000001111 009                
0000001111 009                
0000333333 001                
0000333333 009                
0000333333 009                
0000333333 009                
0000333333 009                


So output files will look like this:
Original file:


----+----1----+----2----+----3
0000000000 001                
0000000000 009                
0000000000 009                
0000333333 001                
0000333333 009            
0000333333 009                
0000333333 009                    
0000333333 009                


File with deleted records:


----+----1----+----2----+----3
0000001111 009                
0000001111 009                

Re: Need help with WHEN=GROUP

PostPosted: Wed Oct 25, 2017 7:59 pm
by Aki88
Hello,

The trick here is to uniquely identify each set of records.

The below solution assumes that the input is sorted in ascending order of the keys.


//SORTIN   DD *                                          
0000000000 001                                          
0000000000 009                                          
0000000000 009                                          
0000001111 009                                          
0000001111 009                                          
0000333333 001                                          
0000333333 009                                          
0000333333 009                                          
0000333333 009                                          
0000333333 009                                          
/*                                                      
//CLEANGRP DD SYSOUT=*                                  
//OTHERS   DD SYSOUT=*                                  
//SYSIN    DD *                                          
 INREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,10),PUSH=(31:12,3))
 OPTION COPY                                            
 OUTFIL FNAMES=CLEANGRP,                                
        OMIT=(31,3,CH,NE,C'001'),                        
        BUILD=(1,30)                                    
 OUTFIL FNAMES=OTHERS,                                  
        SAVE,      
        BUILD=(1,30)
/*                  
 


Yields:

CLEANGRP-

0000000000 001
0000000000 009
0000000000 009
0000333333 001
0000333333 009
0000333333 009
0000333333 009
0000333333 009
 


OTHERS-

0000001111 009
0000001111 009