Sort only detail records



Support for NetApp SyncSort for z/OS, Visual SyncSort, SYNCINIT, SYNCLIST and SYNCTOOL

Sort only detail records

Postby Papya013 » Fri Nov 04, 2016 9:25 am

Hi Team,

I have an input file as mentioned below

HD HEADER 1234567
LN TRAILER 1111
LN TRAILER 3333
LN TRAILER 5555
LN TRAILER 4444
LN TRAILER 2222
HD HEADER 2345678
LN TRAILER 2111
LN TRAILER 2333
LN TRAILER 2555
LN TRAILER 2444
LN TRAILER 2221


I would need the output as mentioned below.

HD HEADER 1234567
LN TRAILER 1111
LN TRAILER 2222
LN TRAILER 3333
LN TRAILER 4444
LN TRAILER 5555
HD HEADER 2345678
LN TRAILER 2111
LN TRAILER 2221
LN TRAILER 2333
LN TRAILER 2444
LN TRAILER 2555


I used below mentioned SORT card but its working if there is only one header but my input file can contain more than one header.

INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,2,CH,EQ,C'LN'),PUSH=(168:12,4))
SORT FIELDS=(168,4,CH,A),EQUALS        


Could anyone please assign me with this?
Papya013
 
Posts: 35
Joined: Wed Nov 06, 2013 6:53 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Sort only detail records

Postby Aki88 » Fri Nov 04, 2016 11:43 am

Hello,

With your current SORT card, after the 'INREC IFTHEN' operation, the data changes to (I've rearranged the OVERLAY column from 168 to 60):


HD HEADER 1234567                                              
LN TRAILER 1111                                            1111
LN TRAILER 3333                                            3333
LN TRAILER 5555                                            5555
LN TRAILER 4444                                            4444
LN TRAILER 2222                                            2222
HD HEADER 2345678                                          2222
LN TRAILER 2111                                            2111
LN TRAILER 2333                                            2333
LN TRAILER 2555                                            2555
LN TRAILER 2444                                            2444
LN TRAILER 2221                                            2221
 


Since you do not have an identifier to GROUP your HEADER record, the second header is actually treated a part of the GROUP - LN, which is immediately before the second HEADER record. Which is why you have '2222' instead of 4 bytes of space when the second HEADER is encountered.


LN TRAILER 4444                                            4444
LN TRAILER 2222                                            2222 ---> Clean OVERLAY
HD HEADER 2345678                                          2222  --> Since GROUP remains same, hence OVERLAYd value
LN TRAILER 2111                                            2111
 


Now when you perform a SORT on the OVERLAY'd 4 bytes of data, with EQUALS, it changes to (EQUALS simply shuffles the order of the two '2222' group records):


HD HEADER 1234567                                              
LN TRAILER 1111                                            1111
LN TRAILER 2111                                            2111
LN TRAILER 2221                                            2221
LN TRAILER 2222                                            2222
HD HEADER 2345678                                          2222
LN TRAILER 2333                                            2333
LN TRAILER 2444                                            2444
LN TRAILER 2555                                            2555
LN TRAILER 3333                                            3333
LN TRAILER 4444                                            4444
LN TRAILER 5555                                            5555 


One of the multiple possible solutions would be GROUPing on the basis of HEADER, and padding the detail records individually:


*                                                                      
* GROUP THE DATA ON THE BASIS OF HEADER RECORD, AND PAD THE HEADER VALUE
* TO EACH RECORD OF THIS GROUP; THIS HELPS IN UNIQUELY IDENTIFYING THE  
* RECORDS AT THE TIME OF SORTING.                                      
*                                                                      
 INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,2,CH,EQ,C'HD'),PUSH=(81:11,7)),      
*                                                                      
* PAD THE DETAIL RECORDS WITH 4 BYTES OF IDENTIFIER FOR EACH RECORD.    
*                                                                      
       IFTHEN=(WHEN=(1,2,CH,EQ,C'LN'),OVERLAY=(88:12,4))                
*                                                                      
* SORT THE DATA ON THE BASIS OF EXTENDED RECORD'S VALUE.                
*                                                                      
 SORT FIELDS=(81,11,CH,A)                                              
*                                                                      
* REMOVE THE PADDED DATA.                                              
*                                                                      
 OUTFIL REMOVECC,BUILD=(1,80)                                          
 


Gives:


HD HEADER 1234567  
LN TRAILER 1111    
LN TRAILER 2222    
LN TRAILER 3333    
LN TRAILER 4444    
LN TRAILER 5555    
HD HEADER 2345678  
LN TRAILER 2111    
LN TRAILER 2221    
LN TRAILER 2333    
LN TRAILER 2444    
LN TRAILER 2555    
 
Aki88
 
Posts: 381
Joined: Tue Jan 28, 2014 1:52 pm
Has thanked: 33 times
Been thanked: 36 times

Re: Sort only detail records

Postby Papya013 » Fri Nov 04, 2016 11:56 am

Thanks a lot for your quick response. It worked:)
Papya013
 
Posts: 35
Joined: Wed Nov 06, 2013 6:53 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Sort only detail records

Postby BillyBoyo » Fri Nov 04, 2016 12:09 pm

Identify the header and PUSH from that. If the header values are ascending order, use that, if not, use the ID.

From the detail records, temporarily extend so that you can have the key you want to sort on in a position which doesn't clash with any data on the header. Use IFOUTLEN for the maximum lengths. Sort with the two sort keys, that of the header first, followed by what you want to sequence on within the header (which you'lll find will be space on the header). Use BUILD on OUTREC to drop off the extended data.

Turns out Aki88 was doing about the same thing at the same time :-)

Pay attention to the IFOUTLEN and the ID if the headers are not in sequence.

And by now there's even a response...
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Sort only detail records

Postby Papya013 » Fri Nov 04, 2016 3:14 pm

Hi,

I have modified the code as below.

INREC IFTHEN=(WHEN=INIT,OVERLAY=(184:1,2)),                
IFTHEN=(WHEN=GROUP,BEGIN=(1,2,CH,EQ,C'HD'),PUSH=(176:ID=8)),
IFTHEN=(WHEN=(1,2,CH,EQ,C'LN'),OVERLAY=(186:9,7))          
SORT FIELDS=(176,17,CH,A),EQUALS                            
OUTREC BUILD=(1,175)
Papya013
 
Posts: 35
Joined: Wed Nov 06, 2013 6:53 pm
Has thanked: 0 time
Been thanked: 0 time


Return to Syncsort/Synctool

 


  • Related topics
    Replies
    Views
    Last post