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

Sum based on a particular field


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

New User


Joined: 18 Apr 2008
Posts: 11
Location: Coimbatore

PostPosted: Thu Dec 03, 2009 5:53 pm
Reply with quote

Hi,

I've have a requirement like this...My input file contains records as shown below..

ABD10Y
ABD20Y
DEF10N
DEF30N
DEF30N
GEH40Y

And my output records are...

ABD30
DEF0
GEH40

That is if the sixth byte is 'Y', then i will be adding the amount fields(4,5) of that key.

Can anyone suggest any method in sort?

Regards,
Jithucse
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Thu Dec 03, 2009 7:21 pm
Reply with quote

Hi Jithucse,
Do you want sum to be left alligned?
Back to top
View user's profile Send private message
Jithucse

New User


Joined: 18 Apr 2008
Posts: 11
Location: Coimbatore

PostPosted: Thu Dec 03, 2009 7:22 pm
Reply with quote

Not required..I'm fine with

ABD30
DEF 0
FEH40
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Thu Dec 03, 2009 7:29 pm
Reply with quote

Hi below sortstep will give you desired result

Code:

//S1    EXEC  PGM=SORT                                                 
//SORTIN DD *                                                           
ABD10Y                                                                 
ABD20Y                                                                 
DEF10N                                                                 
DEF30N                                                                 
DEF30N                                                                 
GEH40Y                                                                 
//SORTOUT DD SYSOUT=*                                                   
//SYSOUT    DD  SYSOUT=*                                               
//SYSPRINT DD SYSOUT=*                                                 
//SYSIN    DD  *                                                       
  SORT FIELDS=(1,3,CH,A)                                               
  SUM FIELDS=(4,2,ZD)                                                   
  INREC IFTHEN=(WHEN=(6,1,CH,EQ,C'N'),OVERLAY=(4:C'00'))               
  OUTFIL BUILD=(1,3,4,2,ZD,EDIT=(IT))                                   
/*                                                                     
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Thu Dec 03, 2009 7:46 pm
Reply with quote

But I suggest you to use this so that sum fields will not overflow...
Code:

//S1    EXEC  PGM=SORT                                   
//SORTIN DD *                                             
ABD10Y                                                   
ABD20Y                                                   
DEF10N                                                   
DEF30N                                                   
DEF30N                                                   
GEH99Y                                                   
GEH99Y                                                   
GEH99Y                                                   
GEH99Y                                                   
//SORTOUT DD SYSOUT=*                                     
//SYSOUT    DD  SYSOUT=*                                 
//SYSPRINT DD SYSOUT=*                                   
//SYSIN    DD  *                                         
  SORT FIELDS=(1,3,CH,A)                                 
  SUM FIELDS=(4,8,ZD)                                     
  INREC IFTHEN=(WHEN=(6,1,CH,EQ,C'N'),BUILD=(1,3,8C'0')),
        IFTHEN=(WHEN=NONE,BUILD=(1,3,6C'0',4,2))         
  OUTFIL BUILD=(1,3,4,8,ZD,EDIT=(IIIIIIIT))             
/*                                                       

Output will be
Code:

ABD      30   
DEF       0   
GEH     396   
Back to top
View user's profile Send private message
Jithucse

New User


Joined: 18 Apr 2008
Posts: 11
Location: Coimbatore

PostPosted: Thu Dec 03, 2009 8:09 pm
Reply with quote

Thanks Sambhaji,

It worked...Thanks a lot...

Regards,
Jithucse
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Thu Dec 03, 2009 10:18 pm
Reply with quote

Jithucse,

Since your input is already sorted on the key, you can use COPY instead of sort and here is another way to get the desired results without worrying about the overflow and padding the records before summing

Code:

//SYSIN    DD *                                           
  SORT FIELDS=COPY                                       
  INREC IFTHEN=(WHEN=(6,1,CH,EQ,C'N'),OVERLAY=(4:C'00')) 
  OUTFIL REMOVECC,NODETAIL,                               
  SECTIONS=(1,3,TRAILER3=(1,3,TOT=(4,2,ZD,M10,LENGTH=8)))
//*
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Thu Dec 03, 2009 11:16 pm
Reply with quote

Sambhaji,

I'm curious. Why do you have

//SYSPRINT DD SYSOUT=*

in your DFSORT jobs? DFSORT does NOT use this ddname.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Thu Dec 03, 2009 11:51 pm
Reply with quote

Yeah... You are right Frank.

I copied STEP from existing JCL(calling some other program) and changed it for this example.
Missed to delete SYSPRINT
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 Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
No new posts To search DB2 table based on Conditio... DB2 1
This topic is locked: you cannot edit posts or make replies. Merge 2 input files based on the reco... JCL & VSAM 2
Search our Forums:

Back to Top