Page 1 of 1

How get a count of records summed?

PostPosted: Thu Aug 16, 2012 12:55 am
by RockinRiles
Howdy ya'll!

I have an FB file which I'm sorting on cols 29-32.
I'm summing cols: 33-38, 39-44, 45-50.

I want output records to contain: sort value, each of 3 summed fields.

I'm able to do that with below:

//SYSIN DD *
SORT FIELDS=(29,4,PD,A)
SUM FIELDS=(33,6,39,6,45,6),FORMAT=PD
OUTREC FIELDS=(29,4,PD,
33,6,PD,
39,6,PD,
45,6,PD)
END

My question: How can I include a COUNT of the # of records that are included in the summing as the 5th column in my output record?

TIA!

Re: How get a count of records summed?

PostPosted: Thu Aug 16, 2012 1:23 am
by BillyBoyo
If you add a constant value of one to the end of each record, and include that in the SUM, that should do it.

Re: How get a count of records summed?

PostPosted: Thu Aug 16, 2012 1:29 am
by RockinRiles
Thanx but, I can't modify this file.

Re: How get a count of records summed?

PostPosted: Thu Aug 16, 2012 4:23 am
by BillyBoyo
Well, you can (to do what is needed) without any changes to the file itself.

You can amend records within Sort itself, and that is what you need here.

  INREC OVERLAY=(80:C'000001')


This assumes you lrecl is 80, change if necessary. It increases the length of each record, within the sort, by six bytes, which are set to that constant value.

SUM on the field as well.

The final output has to include the count anyway, doesn't it :-)

Re: How get a count of records summed?

PostPosted: Thu Aug 16, 2012 7:06 am
by RockinRiles
BillyBoyo wrote:Well, you can (to do what is needed) without any changes to the file itself.

You can amend records within Sort itself, and that is what you need here.

  INREC OVERLAY=(80:C'000001')


This assumes you lrecl is 80, change if necessary. It increases the length of each record, within the sort, by six bytes, which are set to that constant value.

SUM on the field as well.

The final output has to include the count anyway, doesn't it :-)


Billy,

This looks very doable. I will try it out when I get in the office tomorrow.

For my info, if the lrec is actually 80 chars, does this change the 80th byte to "000001", pos 80-85?, (in the virtual world natch) such that it's not available to me for evaluating in this process?
i.e. Say the 80th char is part of a field I'm sorting or summing on. Would I need to use positions in the record for the OVERLAY that I'm not currently using? Like an address field?

In this case, I'm not using the 80th byte so, your solution just may do the trick.

I'll let you know.

Thanx!

Re: How get a count of records summed?

PostPosted: Thu Aug 16, 2012 8:28 am
by dick scherrer
Hello and welcome to the forum,

Even if you are using pos 80 as real data, you should still do as BB suggests. Keep in mind that you are only using an intermediate set of data and the "extra" 1 will NOT be placed in the output file.

Re: How get a count of records summed?

PostPosted: Thu Aug 16, 2012 8:31 am
by NicC
This is NOT a JCL topic but a sort topic. Moved to DFSort. If SYNCSORT is used then it will be moved again.

Re: How get a count of records summed?

PostPosted: Thu Aug 16, 2012 11:04 am
by BillyBoyo
RockinRiles,

For an 80-byte record the OVERLAY should have been 81:

If you have bytes on your input record which are not used in your output file, then they can be utilised.

If you only want your Key, three amounts and the count, you can BUILD a record to reflect that in INREC, and only that data then goes into the actual sort, reducing run-time, work-file use.

If you need all the data from the input, you have to extend the record, even if only temporarily - although your count has to go "somewhere" :-)

Re: How get a count of records summed?

PostPosted: Thu Aug 16, 2012 7:38 pm
by RockinRiles
You guys are Da Bomb!!!
That worked great!

Here's my JCL:
//SYSIN    DD *
    SORT FIELDS=(29,4,PD,A)
    INREC OVERLAY=(81:C'000001')
    SUM FIELDS=(33,6,PD,39,6,PD,45,6,PD,81,6,ZD)
    OUTREC FIELDS=(29,4,PD,
                   33,6,PD,
                   39,6,PD,
                   45,6,PD,
                   81,6,ZD)
  END


Here's a sample of the output file records.
*Column names obviously not in output file. LOL!

  Julian
   Date ........ Amt1 ......  Amt2 .....  Amt3 .. Count
 2012170   670340109   344426809   309119158   1629 ,
 2012171  1126832318    72207780    43737541   9444 ,
 2012172  1302710541    48816247   100536950  18909 ,


You guys are now on my Christmas card list!

Thanks for this forum,

Rockin Riles

PS - This probably does belong in the Syncsort section. Sorry bout that.