MaMu
MaMu

Reputation: 41

Sort group of records by year using dfsort

I am trying to sort group of records by year descending where the key field is the first 10 bytes and the year will be always occuring after '000010YY' as shown below,

I need to sort only the group with year and not to sort the records inside the group for a year.

Input and Ouput file is FB, LRECL 80

Input:

12345 5555 000010YY2021j020
12345 5555 000020AB
12345 5555 000130BC
12345 5555 000141BT01
12345 5555 000143BT05
12356 5555 000010YY2022j020
12356 5555 000020AB  
12356 5555 000130BC  
12356 5555 000141BT01
12367 5555 000010YY2023j020
12367 5555 000130AB
12367 5555 000020BC
12378 5555 000010YY2018j020
12378 5555 000020AB    
12378 5555 000130BC    
12378 5555 000141BT01  
12378 5555 000143BT05
12379 5555 000010YY2017j020
12379 5555 000020AB    
12379 5555 000130BC    

Output expected:

12367 5555 000010YY2023j020
12367 5555 000130AB
12367 5555 000020BC
12356 5555 000010YY2022j020
12356 5555 000020AB        
12356 5555 000130BC  
12356 5555 000141BT01
12345 5555 000010YY2021j020
12345 5555 000020AB
12345 5555 000130BC
12345 5555 000141BT01
12345 5555 000143BT05
12378 5555 000010YY2018j020
12378 5555 000020AB    
12378 5555 000130BC    
12378 5555 000141BT01  
12378 5555 000143BT05
12379 5555 000010YY2017j020
12379 5555 000020AB    
12379 5555 000130BC

I tried using ICEMAN the below sort

//SYSIN DD *                                             
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(12,8,CH,EQ,C'000010YY'),
  PUSH=(81:ID=8))                                       
  SORT FIELDS=(81,8,ZD,D,1,10,BI,A)
  OUTREC BUILD=(1,80)                                   
/*

But it does not provided the expected output.

Please provide any suggestions on how to get the above output.

Upvotes: 0

Views: 39

Answers (1)

Kolusu
Kolusu

Reputation: 566

Please refer to "Sort groups of records" in DFSORT smart tricks page which is available at https://www.ibm.com/support/pages/smart-dfsort-tricks

Here is a DFSORT JCL which would give you the desired results.

//STEP0100 EXEC PGM=SORT                           
//SYSOUT   DD SYSOUT=*                             
//SORTIN   DD *                                    
----+----1----+----2----+----3----+----4----+----5-
12345 5555 000010YY2021J020                        
12345 5555 000020AB                                
12345 5555 000130BC                                
12345 5555 000141BT01                              
12345 5555 000143BT05                              
12356 5555 000010YY2022J020                        
12356 5555 000020AB                                
12356 5555 000130BC                                
12356 5555 000141BT01                              
12367 5555 000010YY2023J020                        
12367 5555 000130AB                                
12367 5555 000020BC                                
12378 5555 000010YY2018J020                        
12378 5555 000020AB                                
12378 5555 000130BC                                
12378 5555 000141BT01                              
12378 5555 000143BT05                              
12379 5555 000010YY2017J020                        
12379 5555 000020AB                                
12379 5555 000130BC                                
//SORTOUT  DD SYSOUT=*                             
//SYSIN    DD *                                    
  INREC IFTHEN=(WHEN=GROUP,                        
               BEGIN=(12,08,CH,EQ,C'000010YY'),    
                PUSH=(81:20,04))                   
                                                   
  SORT FIELDS=(81,4,CH,D),EQUALS                   
                                                   
  OUTREC BUILD=(01,80)                             
/*                                                 

Upvotes: 0

Related Questions