Create a new line when a value changes in data

Support for NetApp SyncSort for z/OS, Visual SyncSort, SYNCINIT, SYNCLIST and SYNCTOOL
speermb
Posts: 7
Joined: Thu Nov 05, 2009 9:01 pm
Skillset: cobol, cics, db2, jcl
Referer: google

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

Code: Select all


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

Code: Select all


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
 

User avatar
sergeyken
Posts: 458
Joined: Wed Jul 24, 2019 10:12 pm
Skillset: Assembler, JCL, Utilities, PL/I, C/C++, DB2, SQL, REXX, COBOL, etc. etc. etc.
Referer: Internet search

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?

Code: Select all

//*=====================================================================
//* 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                                                                    
//*

Code: Select all

********************************* 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.

NicC
Global moderator
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Skillset: JCL, PL/1, Rexx, Utilities and to a lesser extent (i.e. I have programmed using them) COBOL,DB2,IMS
Referer: Google
Location: Pushing up the daisies (almost)

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


  • Similar Topics
    Replies
    Views
    Last post