Page 1 of 1

Create a new line when a value changes in data

PostPosted: Fri May 17, 2019 9:20 pm
by speermb
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
 

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

PostPosted: Wed Jul 24, 2019 10:50 pm
by sergeyken
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 ******

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

PostPosted: Thu Jul 25, 2019 2:16 am
by NicC
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.