IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Joinkeys to Groupby and sum up


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
hiravibk
Warnings : 1

Active User


Joined: 14 Dec 2008
Posts: 107
Location: India

PostPosted: Thu Oct 22, 2015 1:55 am
Reply with quote

Hi,

I have Employee_No, City, Type and two amount fields in the input file as shown below. I want to sum the amount fields and do a group by on Emp_No and Type both as shown in the output.

Input
Code:

100 Chicago Food 010 003
100 NYC     Fuel 015 004
100 Chicago Food 020 005
200 Phoenix Food 015 006
200 Atlanta Food 020 001


Output
Code:

100 Food 030 008
100 Fuel 015 004
200 Food 035 007


My code:
Code:
//INPUTA DD DSN=..File-1
//INPUTB DD DSN=..File-1                                               
//F1OUT DD SYSOUT=*                                       
//SYSIN   DD    *                                         
  JOINKEYS F1=INPUTA,FIELDS=(1,3,A,13,4,A)                 
  JOINKEYS F2=INPUTB,FIELDS=(1,3,A,13,4,A)                 
  JOIN UNPAIRED,F1,F2                                     
  REFORMAT FIELDS=(F2:1,4,F2:13,12)               
  OPTION COPY                                             
  OUTFIL FNAMES=F1ONLY,BUILD=(1,80)                     
  END                                                     
/*                                                       
//JNF1CNTL DD *                   
  INREC OVERLAY=(81:SEQNUM,8,ZD)
/*                               
//JNF2CNTL DD *                   
  SUM FIELDS=(18,03,ZD,22,03,ZD)
/*


Please assist.
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Thu Oct 22, 2015 4:04 am
Reply with quote

I am not sure why you are doing a joinkeys. You could get your desired output by:
Code:
 SORT FIELDS=(1,3,CH,A,13,4,CH,A)
 SUM FIELDS=(18,3,ZD,22,3,ZD)
 OUTREC FIELDS=(1,4,13,14)

I assumed input length as 26 bytes and that is why 13,14 in outrec
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Oct 22, 2015 4:41 am
Reply with quote

I don't see a need for JOINKEYS either.

You have data on your input that you don't need on your output. So cut it down with INREC, to reduce the amount of data SORTed.

Because you have to SORT, the SUM is reasonable. You could also consider OUTFIL reporting features, REMOVECC, NODETAIL, SECTIONS with TRAILER3. An advantage of this approach is that you don't have to wonder whether you are going to bust your counts with SUM (if so, to continue to use SUM, you have to define extra space in INREC).

Although you could get the JOINKEYS to work for this task, it is extra resources in the use of JOINKEYS itself, requires two SORTs (implicit in the JOINKEYS) and, probably the problem you have (you haven't said) two SUMs (or another way to stop multiple outputs).

You're trying to use JOINKEYS as "SQL", and that on the basis that SQL can solve everything, and not be concerned with efficiency.

Is this a for a class, or a competition?
Back to top
View user's profile Send private message
hiravibk
Warnings : 1

Active User


Joined: 14 Dec 2008
Posts: 107
Location: India

PostPosted: Fri Oct 23, 2015 12:33 am
Reply with quote

RahulG31 wrote:
I am not sure why you are doing a joinkeys. You could get your desired output by:
Code:
 SORT FIELDS=(1,3,CH,A,13,4,CH,A)
 SUM FIELDS=(18,3,ZD,22,3,ZD)
 OUTREC FIELDS=(1,4,13,14)

I assumed input length as 26 bytes and that is why 13,14 in outrec


Thank you so much RahulG31. I was complicating things using Joinkeys.

@Bill: Thats right, i will include INREC to cut down the data. This isn't for a class or competition icon_smile.gif
I had a similar scenario, with many fields involved. So i thought i will simplify it here! Thanks Bill.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Joinkeys - 5 output files DFSORT/ICETOOL 7
No new posts PD not working for unsigned packed JO... DFSORT/ICETOOL 5
No new posts Def PD not working for unsigned packe... JCL & VSAM 3
No new posts Sort with JOINKEYS using two VB files DFSORT/ICETOOL 1
No new posts JOINKEYS, how to keep all occurrences? DFSORT/ICETOOL 2
Search our Forums:

Back to Top