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 

Group total depending on a field.

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


Joined: 04 Feb 2003
Posts: 113
Topics: 37

PostPosted: Fri Apr 23, 2004 11:53 am    Post subject: Group total depending on a field. Reply with quote

Hi,
I have to get the total number of a group depending on a field. But the tricky part is I need to have all the records which are present in the input file and the group total as part of the first record of the respective group.
For example
Input File
Code:

----+----1----+----2----+----3----+----4----+----#### -9----+----0----+----1----+
7323      53722     761_EATON REL                                               
7324      53722     761_EATON REL                                               
7326      53722     761_EATON REL                                               
8311      54275     9432_SULLIVAN REL                                           
8486      54377     975_DEBERRY REL                                             
8694      55199     13053_CROATTI REL                                           
9260      51946     1833_HAMEL REL                                             
9261      51946     1833_HAMEL REL                                             
9262      51946     1833_HAMEL REL                                             
9263      51946     1833_HAMEL REL                                             
9264      51946     1833_HAMEL REL 

Output File
Code:

----+----1----+----2----+----3----+----4----+----#### -9----+----0----+----1----+
7323      53722     761_EATON REL                                            03
7324      53722     761_EATON REL                                               
7326      53722     761_EATON REL                                               
8311      54275     9432_SULLIVAN REL                                        02
8311      54275     9432_SULLIVAN REL                                         
8486      54377     975_DEBERRY REL                                          01
8694      55199     13053_CROATTI REL                                        01
9260      51946     1833_HAMEL REL                                           05
9261      51946     1833_HAMEL REL                                             
9262      51946     1833_HAMEL REL                                             
9263      51946     1833_HAMEL REL                                             
9264      51946     1833_HAMEL REL                                             

Here the field I'm looking to group is at the position 11 and of length 10. The group total is at 112th position and is of length 3. For example If you see the field 53722 it has been repeated three times hence I have to put 03 at the 112th position of the first occurance.
Can I use SYNCSORT to solve this ?
_________________
Regds,
Somu
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


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

PostPosted: Fri Apr 23, 2004 12:19 pm    Post subject: Reply with quote

Somuk,

A couple of clarifications.

1.What is your LRECL and recfm of the file?

2. In your example , you spaced out the count field for the duplicates(ex: 7324 & 7326 for 53722 key). do you really need to space it out? can it contain a value of '001'?

3. You described the count field to be 3 bytes but you show only 2 bytes for the count. Do you want the count to be '003'?

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
somuk
Beginner


Joined: 04 Feb 2003
Posts: 113
Topics: 37

PostPosted: Fri Apr 23, 2004 1:19 pm    Post subject: Reply with quote

Hi Kolusu,

1. The file is FB and LRECL is 114.

2. Yes Kolusu. It should be spaces. Duplicates should not have a value '001'.

3. My apologies. It was a typo. It's '003'
_________________
Regds,
Somu
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


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

PostPosted: Fri Apr 23, 2004 2:02 pm    Post subject: Reply with quote

Somuk,

I wrote this on the fly as I was about to leave from work and was not able to test it.so excuse me for any syntax errors.

The following JCL will give you the desired results. A brief explanation of the job. I assumed that you wanted to retain the order of the records as is from the input.
A brief explanation of the job. we add a constant of 001 and seqnum to every record at position 115 using inrec at the end. Since you wanted a space for count field for duplicate we force a space in byte 112 thru 11 for all records.

Now we sort on the key field and sum on the constant we added. All duplicated records will routed to ctl1xsum file and summed up records to temp file T1.Using outrec on the temp file t1, we move the summed up total to bytes 112 thru 114.

The next step we concatenate the temp file t1 and ctl1xsum file and sort on the seqnum to retain the orginal sequence of records. Using outrec we strip the constant and seqnum which leaves you with the desired output.
Code:

//STEP0100 EXEC PGM=SYNCTOOL                               
//TOOLMSG  DD SYSOUT=*                                     
//DFSMSG   DD SYSOUT=*                                     
//IN       DD *                                             
7323      53722     761_EATON REL                           
7324      53722     761_EATON REL                           
7326      53722     761_EATON REL                           
8311      54275     9432_SULLIVAN REL                       
8486      54377     975_DEBERRY REL                         
8694      55199     13053_CROATTI REL                       
9260      51946     1833_HAMEL REL                         
9261      51946     1833_HAMEL REL                         
9262      51946     1833_HAMEL REL                         
9263      51946     1833_HAMEL REL                         
9264      51946     1833_HAMEL REL                         
//T1       DD DSN=&T1,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)   
//CTL1XSUM DD DSN=&T2,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)   
//CON      DD DSN=&T1,DISP=OLD,VOL=REF=*.T1                 
//         DD DSN=&T2,DISP=OLD,VOL=REF=*.CTL1XSUM           
//OUT      DD SYSOUT=*                                     
//TOOLIN   DD *                                             
  SORT FROM(IN) USING(CTL1)                                 
  SORT FROM(CON) USING(CTL2)                               
//CTL1CNTL DD *                                             
  INREC FIELDS=(1,111,3X,C'001',SEQNUM,8,ZD)               
  SORT FIELDS=(11,10,CH,A)                                 
  SUM FIELDS=(115,3,ZD),XSUM                               
  OUTFIL FNAMES=T1,OUTREC=(1,111,115,3,115,11)             
//CTL2CNTL DD *                                             
  SORT FIELDS=(118,8,CH,A)                                 
  OUTFIL FNAMES=OUT,OUTREC=(1,114)                         
/*   


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
somuk
Beginner


Joined: 04 Feb 2003
Posts: 113
Topics: 37

PostPosted: Fri Apr 23, 2004 3:40 pm    Post subject: Reply with quote

Great Kolusu. Thank you for the solution.
The only change I did was replacing the insteam data with my input file. Since for instream data it will assume a default LRECL of 80 the INREC statement will give us an out of range condition. Am I right?
_________________
Regds,
Somu
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Apr 27, 2004 3:04 pm    Post subject: Reply with quote

Somu,

Sorry for the late response. You are right that with instream data, sort will assume the lrecl to be 80 bytes which will result in a WER230A INREC FIELD OUTSIDE RANGE error.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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