Create a new line when a value changes in data



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

Create a new line when a value changes in data

Postby speermb » Fri May 17, 2019 9:20 pm

I have a file that contains details and id - when then id changes I want a different output line. Is this possible?

Iput looks like below

id        details
10       detail 1
10       detail 2
10       detail 3
10       detail 4
11       detail 1
11       detail 2
12       detail 99
12       detail 1        
 

Desired output is

For Id 10 we have:       Detail 1
                                  detail 2
                                  detail 3
                                  detail 4
For Id 11 we have:      Detail 1
                                 detail 2
For Id 12 we have:      Detail 1
                                 detail 99
 
speermb
 
Posts: 7
Joined: Thu Nov 05, 2009 9:01 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Create a new line when a value changes in data

Postby sergeyken » Wed Jul 24, 2019 10:50 pm

speermb wrote:I have a file that contains details and id - when then id changes I want a different output line. Is this possible?

//*=====================================================================
//* PROCESS GROUPS                                                      
//*=====================================================================
//GROUPS   EXEC PGM=SORT                                            
//*                                                                    
//SYSOUT   DD  SYSOUT=*                                                
//*                                                                    
//SORTIN   DD  *                                                        
ID       DETAILS                                                        
10       DETAIL 1                                                      
10       DETAIL 2                                                      
10       DETAIL 3                                                      
10       DETAIL 4                                                      
11       DETAIL 1                                                      
11       DETAIL 2                                                      
12       DETAIL 99                                                      
12       DETAIL 1                                                      
//*                                                                    
//SORTOUT  DD  SYSOUT=*                                                
//*                                                                    
//SYSIN    DD  *                                                        
 INCLUDE COND=(1,2,CH,NE,C'ID')                                        
*                                                                      
 INREC IFTHEN=(WHEN=GROUP,        DETECT THE GROUP                      
               KEYBEGIN=(1,2),    BASED ON KEY VALUE                    
               PUSH=(81:SEQ=6))   APPEND LINE NUM WITHIN GROUP          
*                                                                      
 SORT FIELDS=COPY                                                      
*                                                                      
 OUTREC IFTHEN=(WHEN=(81,6,ZD,EQ,+1),   IS THIS THE START OF THE GROUP?
*               LINE FORMAT #1                                          
                BUILD=(C'FOR ID ',1,2,C' WE HAVE: ', GROUP MARKER      
                       10,10,                        VALUE, FORMAT 1    
                       45X)),                                          
        IFTHEN=(WHEN=NONE,              ANY OTHER LINE?                
*               LINE FORMAT #2                                          
                BUILD=(C'                    ',      SHIFT RIGHT        
                       10X,                          PLACEHOLDER        
                       10,10,                        VALUE, FORMAT 2    
                       35X))                         FILL END OF LINE  
*                                                                      
 END                                                                    
//*

********************************* TOP OF DATA ********
FOR ID 10 WE HAVE: DETAIL 1                          
                              DETAIL 2                
                              DETAIL 3                
                              DETAIL 4                
FOR ID 11 WE HAVE: DETAIL 1                          
                              DETAIL 2                
FOR ID 12 WE HAVE: DETAIL 99                          
                              DETAIL 1                
******************************** BOTTOM OF DATA ******
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 408
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 6 times
Been thanked: 40 times

Re: Create a new line when a value changes in data

Postby NicC » Thu Jul 25, 2019 2:16 am

Assuming OUTFIL in Syncsort can do all that OUTFIL does in DFSort, read the DFSort manual chapter 3, the section on OUTFIL and in particular Example 3. It is worth staying late at work to play with all the samples so that when you need something, like you today, you can say to yourself: "I have something that may be able to do that". U used to do that - unfortunately, if my samples still survive, I do not know where they are.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times


Return to Syncsort/Synctool

 


  • Related topics
    Replies
    Views
    Last post