Page 1 of 2

SUM in DFSORT

PostPosted: Mon Jan 09, 2012 5:15 pm
by fornanthakumar
Hi,

My requirement is sumup the values based on the key fields. when i do that i am getting only one record which gives me the summed up value for each key field but i want like,

Importantly : I should not do SORT, just copy.

I/P:

1234510
1234520
1234640
1234640
1234613
1234110

O/P:

1234510
1234520
1234530
1234640
1234640
1234613
1234693
1234110
1234110

My SYSIN Card is,

SORT FILEDS = (1,5,CH,A)
SUM FIELDS = (6,2,ZD)

Note : Here i could mention fields only with SORT. i am not sure about using Fields with OPTION COPY statements. My objectives are two
1. Do not Sort the records.
2. I want all the individual records and the sum value should be added after each key records finished.

Please help me out.

Re: SUM in DFSORT

PostPosted: Mon Jan 09, 2012 5:18 pm
by BillyBoyo
First, drop the e-mail address from your signature. You were warned about this in the set-up stuff. Your e-mail address will be found by some "web bot" and you will get all sorts of rubbish arriving.

Re: SUM in DFSORT

PostPosted: Tue Jan 10, 2012 2:07 am
by Frank Yaeger
Here's a DFSORT job that will do what you asked for (presumably you're not concerned about overflowing 2 digits for the total):

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
1234510
1234520
1234640
1234640
1234613
1234110
//SORTOUT DD SYSOUT=*
//SYSIN DD *
  OPTION COPY
  OUTFIL REMOVECC,
    SECTIONS=(1,5,
      TRAILER3=(1,5,TOT=(6,2,ZD,TO=ZD,LENGTH=2)))
/*

Re: SUM in DFSORT

PostPosted: Tue Jan 10, 2012 2:52 pm
by fornanthakumar
Hi Frank Yaeger ,

Thank you very much indeed for your great assistance.

To add more into it, i want the output to be like below,
1234510
1234520
1234530
1234640
1234640
1234613
1234693
1234110

If you see the condition will be COND = (1,5,ZD,GT,12342).. but still i want the last record (omit by the cond) to be in output file.

can i sections in IFTHEN clause.. please advise..

Re: SUM in DFSORT

PostPosted: Tue Jan 10, 2012 3:20 pm
by BillyBoyo
Can you look at what you wrote, and then re-write so that it is clearer.

The output from Frank's code gives the output you requested originally.

1234510
1234520
1234530
1234640
1234640
1234613
1234693
1234110
1234110


Where does the COND come into it? Are you saying that when there is only one record, you don't want a new summed record generated?

I'd be concerned that there is nothing on the file to indicate which records have been generated. You are generating trailers, but can't tell that it is a trailer (except by change of key). If you run the sort again, it'll just add up the total, including the already-generated total record. As Frank has said, you don't have much space with just two digits for the summing. Are you happy with that?

Re: SUM in DFSORT

PostPosted: Tue Jan 10, 2012 3:25 pm
by fornanthakumar
Hi Billy,

I am very much happy with Frank's Code.. Now the situation here is, i should generate the trailers like above only for particular type of keys from the files and rest of the records i do not want the trailers.

Just say .. i want to generate trailer for the key which is greater than 12342. hence i want the output like below,
1234510
1234520
1234530
1234640
1234640
1234613
1234693
1234110

Are you clear with my question ?

Re: SUM in DFSORT

PostPosted: Tue Jan 10, 2012 4:08 pm
by BillyBoyo
Let's see.

You have a range of numbers you want to generate a trailer for (greater than 12342).

You are otherwise happy with all other points raised.

You can't get the IFTHEN into the SECTIONS.

There is a solution with JOINKEYS. If you want to try it yourself, let us know. I'm short of time at the moment, but I'm sure you'll have one by tommorow morning otherwise.

Please make sure that you have the requirement exactly described now.

Re: SUM in DFSORT

PostPosted: Tue Jan 10, 2012 4:25 pm
by fornanthakumar
Hi billy,

Thanks. My requirement is what i described above.. i have given you the how the output records should look like,

I will in try using JOINKEY now... but please help me out if you have any such idea...

thanks in advance.

Re: SUM in DFSORT

PostPosted: Tue Jan 10, 2012 5:24 pm
by BillyBoyo
See if this one can give you some ideas. dfsort-icetool-icegener/topic6793.html#p29910

Re: SUM in DFSORT

PostPosted: Tue Jan 10, 2012 11:35 pm
by Frank Yaeger
You can use a DFSORT/ICETOOL job like the following for your 'changed' requirement:

//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD *
1234510
1234520
1234640
1234640
1234613
1234110
1234008
1234007
1234006
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//OUT DD SYSOUT=*
//TOOLIN DD *
COPY FROM(IN) TO(T1) USING(CTL1)
COPY FROM(T1) TO(OUT) USING(CTL2)
//CTL1CNTL DD *
  OUTFIL REMOVECC,FNAMES=T1,
    SECTIONS=(1,5,
      TRAILER3=(1,5,TOT=(6,2,ZD,TO=ZD,LENGTH=2),C'T'))
//CTL2CNTL DD *
  OMIT COND=(8,1,CH,EQ,C'T',AND,1,5,ZD,LE,12342)
  INREC OVERLAY=(8:X)
/*