Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Sum based on a particular field

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
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    Post subject: Sum based on a particular field
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    Post subject:
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    Post subject: Reply to: Sum based on a particular field
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    Post subject:
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    Post subject:
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    Post subject: Reply to: Sum based on a particular field
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    Post subject: Reply to: Sum based on a particular field
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 Moderator


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

PostPosted: Thu Dec 03, 2009 11:16 pm    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts INVALID FIELD OR CONSTANT IN SORTOF ?? Ron Klop DFSORT/ICETOOL 8 Wed Jan 11, 2017 3:44 pm
No new posts Removing Duplicates based on certain ... chandracdac DFSORT/ICETOOL 8 Fri Dec 09, 2016 4:40 am
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 31 Tue Dec 06, 2016 8:04 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us