Page 1 of 1

how to write a aggregate sum function in dfsort

PostPosted: Tue Dec 06, 2011 4:33 pm
by mainframemunic
//STEP1 EXEC PGM=SORT                                         
//SYSOUT DD SYSOUT=*                                         
//SORTIN DD DSN=xxxxx.PANDS.PS1,DISP=SHR                     
//SORTOUT DD DSN=xxxxxx.PANDS.PS2,DISP=(,CATLG,DELETE),...             
//SYSIN DD *                                                   
     SORT FIELDS=(9,3,CH,A)                                   
     SUM FIELDS=(1,2,ZD)                                       
/*                                                             
// 


above this program in output file i did't get the sum values....
some one help me i have input file which contains 10 fields with 10 records.
i want the the output file with summed up the five amount fileds and control on five fields. when ever any change in the first five fields i wnat the sum for alll the similar records.
when it is summing up is there any truncation will happen in the oputput file or not.

Re: how to write a aggregate sum function in dfsort

PostPosted: Tue Dec 06, 2011 4:55 pm
by BillyBoyo
If you have five control fields, you need to put them all into the SORT card, in a logical order.

You can then SUM for each of the five fields.

If that is not what you want, you have to describe what you do want better.

Re: how to write a aggregate sum function in dfsort

PostPosted: Tue Dec 06, 2011 10:55 pm
by skolusu
mainframemunic,

use the following DFSORT control cards

//SYSIN DD *                                       
  OPTION EQUALS                                     
  SORT FIELDS=(P1,M1,F1,A,    $ CONTROL FIELD-1     
               P2,M2,F2,A,    $ CONTROL FIELD-2     
               P3,M3,F3,A,    $ CONTROL FIELD-3     
               P4,M4,F4,A,    $ CONTROL FIELD-4     
               P5,M5,F5,A)    $ CONTROL FIELD-5     
                                                   
   SUM FIELDS=(P1,M1,F1,      $ AMOUNT FIELD-1     
               P2,M2,F2,      $ AMOUNT FIELD-2     
               P3,M3,F3,      $ AMOUNT FIELD-3     
               P4,M4,F4,      $ AMOUNT FIELD-4     
               P5,M5,F5)      $ AMOUNT FIELD-5     
//*                                                 
 P = POSITION OF THE FIELD                         
 M = LENGTH OF THE FIELD                           
 F = FORMAT OF THE FIELD ( CH, ZD, PD .....)       


If you're not familiar with DFSORT and DFSORT's ICETOOL, I'd suggest reading through "z/OS DFSORT: Getting Started". It's an excellent tutorial, with lots of examples, that will show you how to use DFSORT, DFSORT's ICETOOL and DFSORT Symbols. You can access it online, along with all of the other DFSORT books, from:

http://www.ibm.com/support/docview.wss? ... g3T7000080

Re: how to write a aggregate sum function in dfsort

PostPosted: Fri Dec 09, 2011 12:38 pm
by mainframemunic
skolusu
i have used above the code my program runs succesfully. but the results in not coming correctly. i did't get the sum of the values in my output file...

Re: how to write a aggregate sum function in dfsort

PostPosted: Fri Dec 09, 2011 1:14 pm
by dick scherrer
Hello,

i have used above the code my program runs succesfully. but the results in not coming correctly
Then this would NOT be a successful run. . .

You need to post the jcl, control statements, and data that were used for the run and you need to post the informational messages (including messasge ids) generated by the run. Also show the output you generated as well as what you wanted.

Re: how to write a aggregate sum function in dfsort

PostPosted: Fri Dec 09, 2011 11:20 pm
by Frank Yaeger
i have used above the code my program runs succesfully. but the results in not coming correctly. i did't get the sum of the values in my output file...


Kolusu gave you a brief explanation of the general form of the DFSORT control statements (which you could have looked up in the DFSORT book). So you didn't use the "above code". You hopefully filled in your own position, length and format values. How do you expect anyone to know what you actually coded if you don't show it? You need to give us the appropriate information before we can help you. We can't read your mind or look over your shoulder.

If you want to learn how to code correct DFSORT statements yourself, I'd suggest reading through "z/OS DFSORT: Getting Started". It's an excellent tutorial, with lots of examples, that will show you how to use DFSORT, DFSORT's ICETOOL and DFSORT Symbols. You can access it online, along with all of the other DFSORT books, from:

http://www.ibm.com/support/docview.wss? ... g3T7000080

Re: how to write a aggregate sum function in dfsort

PostPosted: Sat Dec 10, 2011 1:58 pm
by mainframemunic
Frank Yaeger
u first see the first post. i have posted the coding....

Re: how to write a aggregate sum function in dfsort

PostPosted: Sat Dec 10, 2011 2:35 pm
by BillyBoyo
I'm thinking you are doing this deliberately or don't know enough to even recognise what you don't know.

The stuff you posted sorts on one field and sums on one field. If you want to sort on five and sum on five, you need to do it differently skolusu has shown you how.

If you can't understand even that, I don't think I'll be able to offer you anything further. It would be pointless.

Re: how to write a aggregate sum function in dfsort

PostPosted: Sat Dec 10, 2011 2:41 pm
by mainframemunic
in above my program i have added 1 and 2, but my output file i did't get any answer man

Re: how to write a aggregate sum function in dfsort

PostPosted: Sat Dec 10, 2011 8:53 pm
by enrico-sorichetti
You did not post anything useful to the people willing help You
the sort behavior of the SUM <command> is well described in the manuals
before complaining verify that the SUM You are expecting agrees with the SUM rules of SORT

if , for example, Your input is
 =COLS> ----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 000008 01      001                                                             
 000009 02      002                                                             
 000010 02      002                                                             
 000011 03      003                                                             
 000012 03      003                                                             
 000013 03      003                                                             


the result provided by SORT according to the SORT rules for the <Your SORT statements>
 000016 //SYSIN     DD *                                                       
 000017   SORT FIELDS=(9,3,CH,A)                                               
 000018   SUM FIELDS=(1,2,ZD)                                                   


is
01      001                                                                     
04      002                                                                     
09      003                                                                     


if You are expecting something else. do not whine it does not work, but rather explain better Your requirement

input ( a few records )
expected output ...