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 READ A PACKED "NEGATIVE" FI... jdesouza CA Products 3 Tue May 02, 2017 11:43 pm
No new posts Group Data based on a key Arun Raj DFSORT/ICETOOL 7 Thu Apr 27, 2017 11:29 pm
No new posts Alter &DATENS field in HEADER1 Angad DFSORT/ICETOOL 4 Mon Apr 24, 2017 11:49 am
No new posts SORT VSAM file with each field one by... maxsubrat DFSORT/ICETOOL 6 Tue Mar 14, 2017 1:07 pm
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm


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