MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to group records based on a change in particular field

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
SureshKumar
Intermediate


Joined: 23 Jan 2003
Posts: 211
Topics: 21

PostPosted: Fri May 02, 2003 7:46 am    Post subject: How to group records based on a change in particular field Reply with quote

Hi,
I want to get a summary report based on a change in name (which is between columns 79 and 111) in a 133 byte report. example, the name starts at position 79
A.E.E DE PUERTORICO
AEE DE PUERTO RICO
BANCO POPULAR DE P.R.
BANCO POPULAR DE PUERTO RICO
MAIL TRIBUNE
MAIL TRIBUNE
MAIL TRIBUNE
MAIL TRIBUNE
MAIL TRIBUNE
SANTA CRUZ SENTINEL
SANTA CRUZ COUNTY SENTINEL
SANTA CRUZ COUNTY SENTINEL
I want to group the records by change in name and have a sub-total for each group. a single record for each group would be fine. Thanks
! We use Syncsort !
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Fri May 02, 2003 1:13 pm    Post subject: Reply with quote

Suresh,

You can try the following 3 methods to obtain the desired results

Method1:

Code:

//STEP1   EXEC PGM=SORT                                       
//SYSOUT  DD SYSOUT=*                                         
//SORTIN  DD DSN=YOUR INPUT FILE,                           
//           DISP=SHR                                         
//SORTOUT DD SYSOUT=*                                         
//SYSIN   DD *                                                 
  SORT FIELDS=(79,32,CH,A)                                     
  OUTFIL NODETAIL,SECTIONS=(79,32,TRAILER3=(79,32,X,COUNT))     
/*


Output is :
Code:

A.E.E DE PUERTORICO                      1     
AEE DE PUERTO RICO                       1     
BANCO POPULAR DE P.R.                    1     
BANCO POPULAR DE PUERTO RICO             1     
MAIL TRIBUNE                             5     
SANTA CRUZ COUNTY SENTINEL               2     
SANTA CRUZ SENTINEL                      1     

Method:2
Code:
                                                             
//STEP2    EXEC  PGM=SYNCTOOL                                 
//TOOLMSG  DD SYSOUT=*                                         
//DFSMSG   DD SYSOUT=*                                         
//IN      DD DSN=YOUR INPUT FILE,                           
//           DISP=SHR                                         
//OUT      DD SYSOUT=*                                         
//TOOLIN    DD *                                               
  OCCURS FROM(IN) LIST(OUT) HEADER('NAME') HEADER('COUNT') -   
  ON(79,32,CH) ON(VALCNT) BLANK                               
/*

Code:

Output is :
NAME                                         COUNT 
--------------------------------   --------------- 
A.E.E DE PUERTORICO                              1 
AEE DE PUERTO RICO                               1 
BANCO POPULAR DE P.R.                            1 
BANCO POPULAR DE PUERTO RICO                     1 
MAIL TRIBUNE                                     5 
SANTA CRUZ COUNTY SENTINEL                       2 
SANTA CRUZ SENTINEL                              1 

Method3:
Code:
                                                             
//STEP3    EXEC  PGM=SORT                                     
//SYSOUT   DD SYSOUT=*                                         
//SORTIN  DD DSN=YOUR INPUT FILE,                           
//           DISP=SHR                                         
//SORTOUT  DD SYSOUT=*                                         
//SYSIN     DD *                                               
 INREC FIELDS=(1,133,X'000000001C')  * INCLUDE COUNTER         
 SORT  FIELDS=(79,32,CH,A)           * SORT ON CONTROL FIELD   
 SUM   FIELDS=(134,5,PD)             * SUMMARIZE IN COUNTER   
 OUTFIL OUTREC=(79,32,X,134,5,PD,EDIT=(IIIIIIIIT))             
/*


Output is same as method1

Hope this helps...

cheers

kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
SureshKumar
Intermediate


Joined: 23 Jan 2003
Posts: 211
Topics: 21

PostPosted: Fri May 02, 2003 1:21 pm    Post subject: Reply with quote

Thankyou very much. one more request - can i get the output(count) in descending order. Thanks
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Sun May 04, 2003 8:26 pm    Post subject: Reply with quote

Suresh,

you need another step to read in the output created above and sort on the count descending.The following Jcl will give you the desired results.
Code:

//STEP1    EXEC  PGM=SYNCTOOL
//TOOLMSG  DD SYSOUT=*
//DFSMSG   DD SYSOUT=*
//IN       DD DSN=USERID.GROUP.FILE,
//            DISP=SHR
//T1       DD DSN=&T1,DISP=(,PASS),SPACE=(CYL,(10,10),RLSE)
//OUT      DD SYSOUT=*
//TOOLIN    DD *
  SORT FROM(IN) TO(T1)  USING(CTL1)
  SORT FROM(T1) TO(OUT) USING(CTL2)
//CTL1CNTL  DD *
  INREC FIELDS=(1,133,X'000000001C')  * INCLUDE COUNTER
  SORT  FIELDS=(79,32,CH,A)           * SORT ON CONTROL FIELD
  SUM   FIELDS=(134,5,PD)             * SUMMARIZE IN COUNTER
  OUTREC FIELDS=(79,32,X,134,5,PD,EDIT=(IIIIIIIT))
//CTL2CNTL  DD *
  SORT  FIELDS=(34,8,CH,D)           * SORT ON COUNT DESC
/*


The output of this job is :
Code:

MAIL TRIBUNE                            5             
SANTA CRUZ COUNTY SENTINEL              2             
A.E.E DE PUERTORICO                     1             
AEE DE PUERTO RICO                      1             
BANCO POPULAR DE P.R.                   1             
BANCO POPULAR DE PUERTO RICO            1             
SANTA CRUZ SENTINEL                     1             


Hope this helps....

cheers

kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mf_user
Intermediate


Joined: 01 Jun 2003
Posts: 372
Topics: 105

PostPosted: Thu Oct 16, 2008 12:27 pm    Post subject: Trying with SEQNUM Reply with quote

Hi, Kolusu.

I was trying to modify the below solution given by you to use SEQNUM but getting non-sense output. Mad bonk

Code:

//STEP3    EXEC  PGM=SORT                             
//SYSOUT   DD SYSOUT=*                               
//SORTIN  DD *                                       
11111                                                 
22222                                                 
22222                                                 
22222                                                 
44444                                                 
//SORTOUT  DD SYSOUT=*                               
//SYSIN     DD *                                     
 INREC FIELDS=(1,20,X'000000001C')  * INCLUDE COUNTER
 SORT FIELDS=(1,5,CH,A)                               
 SUM FIELDS=(21,5,PD)                                 
 OUTFIL OUTREC=(1,5,X,21,5,PD,EDIT=(IIIIIIIIT))       
/*                                                   


Output:

Code:

11111         1
22222         3
44444         1



TO.........

Code:

//STEP3    EXEC  PGM=SORT         
//SYSOUT   DD SYSOUT=*             
//SORTIN  DD *                     
11111                             
22222                             
22222                             
22222                             
44444                             
//SORTOUT  DD SYSOUT=*             
//SYSIN     DD *                   
 INREC FIELDS=(1,20,25:SEQNUM,3,ZD)
 SORT FIELDS=(1,5,CH,A)           
 SUM FIELDS=(25,3,ZD)             
 OUTFIL OUTREC=(1,5,X,25,3,ZD)     
/*                                 


Output:

Code:

11111   1     - 001
22222   9     - (002+003+004)
44444   5     - 005


Can it be corrected? Please explain.

Thanks.
_________________
MF
==
Any training that does not include the emotions, mind and body is incomplete; knowledge fades without feeling.
==
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Thu Oct 16, 2008 12:41 pm    Post subject: Reply with quote

mf_user,

Quote:
I was trying to modify the below solution given by you to use SEQNUM but getting non-sense output


what makes it a non-sense output? you used ZD on the outrec and a default edit mask is used and removed the leading zeros. If you just want the leading zeros, just remove from ZD from outrec
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mf_user
Intermediate


Joined: 01 Jun 2003
Posts: 372
Topics: 105

PostPosted: Fri Oct 17, 2008 4:53 am    Post subject: Reply with quote

Kolusu, I don't have problem with leading zeroes. My problem is why I am not getting the output like below with SEQNUM used. Is it possible?

Code:

11111         1
22222         3
44444         1


Thanks.
_________________
MF
==
Any training that does not include the emotions, mind and body is incomplete; knowledge fades without feeling.
==
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Fri Oct 17, 2008 10:39 am    Post subject: Reply with quote

mf_user,

Quote:
My problem is why I am not getting the output like below with SEQNUM used. Is it possible?


Do you even know what seqnum does ? Seqnum is basically putting a relative record number on all records. The sequence numbers are assigned in the order in which the records are received. The first post is counting the duplicates for each key and I have no idea as to how you arrived that you can solve the same issue using the seqnum.
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mf_user
Intermediate


Joined: 01 Jun 2003
Posts: 372
Topics: 105

PostPosted: Fri Oct 17, 2008 11:31 am    Post subject: Reply with quote

Kolusu, thanks for clearning my doubts regarding SEQNUM.
_________________
MF
==
Any training that does not include the emotions, mind and body is incomplete; knowledge fades without feeling.
==
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group