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

Sum only certain fields that have an indicator using DFSORT


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

New User


Joined: 03 Mar 2008
Posts: 32
Location: India

PostPosted: Thu Mar 06, 2008 9:53 am
Reply with quote

Hi! I need a bit of help on this:

Say I have a file, which contains the following:

f1 f2 f3
------------------
AA SR1789 123
BB SR1678 123
AA SR1789 456
AA SR1234 789

I need to add the f3 fields of all the records with f1=AA and the same f2 field. So my output should be

f1 f2 f3
------------------
AA SR1789 579
BB SR1678 123
AA SR1234 789

Is it possible to do this without splitting the file?

Actually my file is of length 80 and the field coressponding to f3 is present at 61st position in it with length 13. the field f2 is of length 12 at 3rd position and f1 is of length 2 at 1st position. I tried the following:

OPTION EQUALS,ZDPRINT
INREC OVERLAY=(81:61,15,UFF,TO=ZD,LENGTH=13)
INCLUDE COND=(1,2,CH,EQ,C'AA')
SORT FIELDS=(3,12,CH,A)
SUM FIELDS=(81,13,ZD)
OUTREC BUILD=(1,60,61:81,13,ZD)

but this ways, as is obvious, i am losing the BB records, which i need in the output. Can anyone pls help??
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Thu Mar 06, 2008 2:57 pm
Reply with quote

Have you considered using the IFTHEN operand to preserve the BB records?
Back to top
View user's profile Send private message
niks_jude
Warnings : 1

Active User


Joined: 01 Dec 2006
Posts: 144
Location: Mumbai

PostPosted: Thu Mar 06, 2008 5:57 pm
Reply with quote

This should work

SORT FIELDS =(1,12,CH,A)
SUM FIELDS = (61,13,ZD)

This is because fields f1 and f2 are contiguous. So it will SUM all the f3 fields with same f1 and f2 fields.
Back to top
View user's profile Send private message
niks_jude
Warnings : 1

Active User


Joined: 01 Dec 2006
Posts: 144
Location: Mumbai

PostPosted: Thu Mar 06, 2008 5:58 pm
Reply with quote

Oh sorry !! I missed the requirement regarding 'AA'.
Back to top
View user's profile Send private message
darakhshan

New User


Joined: 03 Mar 2008
Posts: 32
Location: India

PostPosted: Thu Mar 06, 2008 6:04 pm
Reply with quote

No i hadn't.. Not very sure as to where it would fit, but will this serve the purpose?
OPTION EQUALS,ZDPRINT
INREC OVERLAY=(81:61,15,UFF,TO=ZD,LENGTH=13)
INCLUDE COND=(1,2,CH,EQ,C'AA')
SORT FIELDS=(3,12,CH,A)
SUM FIELDS=(81,13,ZD)
OUTREC IFTHEN=(WHEN=(1,2,CH,EQ,C'AA'),
BUILD=(1,60,61:131,15,ZD),
IFTHEN=(WHEN=(1,2,CH,EQ,C'BB'),
BUILD=(1,60,61:131,15)

Pls correct me if i'm wrong.. icon_redface.gif
Back to top
View user's profile Send private message
Ajay Baghel

Active User


Joined: 25 Apr 2007
Posts: 206
Location: Bangalore

PostPosted: Thu Mar 06, 2008 6:12 pm
Reply with quote

SORT FIELDS
Quote:
=(1,12,CH,A)


It needs to be:
Quote:

SORT FIELDS =(1,14,CH,A)
,
SUM FIELDS = (61,13,ZD)


-Ajay
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 Mar 06, 2008 10:20 pm
Reply with quote

darakhshan,

The INCLUDE is only keeping the 'AA' fields. You shouldn't be using it.

Your posts are confusing. Are you trying to add just the records with f1='AA' and the same f2 field, or are you trying to add all of the records that have the same f1 and f2 field. To illustrate, what output would you expect for these input records?

Code:

AA SR1789 123
BB SR1678 123
AA SR1789 456
AA SR1234 789
FF SR3333 100
FF SR3333 200
FF SR3333 300
EE SR1234 100
EE SR1234 200


Once you answer this question and I know what you want to do, I can show you how to do it with DFSORT.
Back to top
View user's profile Send private message
niks_jude
Warnings : 1

Active User


Joined: 01 Dec 2006
Posts: 144
Location: Mumbai

PostPosted: Thu Mar 06, 2008 10:35 pm
Reply with quote

AA SR1789 579
BB SR1678 123
AA SR1234 789
FF SR3333 600
EE SR1234 300


I believe he wanted this from his post.
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 Mar 06, 2008 10:44 pm
Reply with quote

Maybe. Maybe not. I'll wait until darakhshan tells me that.
Back to top
View user's profile Send private message
darakhshan

New User


Joined: 03 Mar 2008
Posts: 32
Location: India

PostPosted: Fri Mar 07, 2008 9:30 am
Reply with quote

actually i want to sum up only the AA records and have the rest as it is.. and i have only two kinds of records, AA and BB. So eliminating the EE and FF records, output shud be:

so the output wud be:

AA SR1789 579
BB SR1678 123
AA SR1234 789
Back to top
View user's profile Send private message
darakhshan

New User


Joined: 03 Mar 2008
Posts: 32
Location: India

PostPosted: Fri Mar 07, 2008 9:33 am
Reply with quote

That is the AA records with the same F2 field.
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: Fri Mar 07, 2008 10:00 pm
Reply with quote

You can use a DFSORT/ICETOOL job like the following to do what you asked for. I added a few more records for a better test.

Code:

//S1    EXEC  PGM=ICETOOL
//TOOLMSG   DD  SYSOUT=*
//DFSMSG    DD  SYSOUT=*
//IN DD *
AASR1789                                                              123
BBSR1678                                                              123
BBSR1678                                                              345
AASR1789                                                              456
AASR1234                                                              789
AASR2000                                                              999
BBSR1520                                                              222
AASR2000                                                              432
/*
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//OUT DD SYSOUT=*
//TOOLIN   DD    *
SORT FROM(IN) TO(T1) USING(CTL1)
SORT FROM(T1) TO(OUT) USING(CTL2)
/*
//CTL1CNTL DD *
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(89:SEQNUM,8,ZD)),
        IFTHEN=(WHEN=(1,2,CH,EQ,C'BB'),OVERLAY=(81:SEQNUM,8,ZD))
  SORT FIELDS=(1,14,CH,A,81,8,ZD,A)
  OPTION ZDPRINT,EQUALS
  SUM FIELDS=(61,13,ZD)
/*
//CTL2CNTL DD *
  SORT FIELDS=(89,8,ZD,A)
  OUTREC BUILD=(1,60,61,13,ZD,M10,LENGTH=13,80:X)
/*


OUT would have:

Code:

AASR1789                                                              579 
BBSR1678                                                              123 
BBSR1678                                                              345 
AASR1234                                                              789 
AASR2000                                                             1431 
BBSR1520                                                              222 
Back to top
View user's profile Send private message
darakhshan

New User


Joined: 03 Mar 2008
Posts: 32
Location: India

PostPosted: Mon Mar 10, 2008 10:58 am
Reply with quote

thanks a lot! icon_smile.gif
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 Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts DFsort help with SUM() DFSORT/ICETOOL 12
No new posts DFSORT - VB file RDW getting overridden DFSORT/ICETOOL 3
Search our Forums:

Back to Top