Page 1 of 1

Get record count while using SUM FIELDS in SORT.

Posted: Sun Sep 04, 2016 10:16 pm
by saeedansari
Hi.

I ned a help in a SORT. Consider the input like this:

Code: Select all

XX 100 
XX 140 
YY 500 
YY 50 
YY 50 
I need the counts of duplicates in another column. Using SUM fields gives the follwoing output:

Code: Select all

XX 240 
YY 600 
But as I said before, I also need to add count of duplicate records in output like this:

Code: Select all

XX 240 2 
YY 600 3 
Please help me, how to do it.

Re: Get record count while using SUM FIELDS in SORT.

Posted: Mon Sep 05, 2016 3:21 am
by Magesh_j
Assuming input is in sorted order 1,2 and the value field is right aligned (4,3), in your example you are showing it as left aligned.

Here is the solution :

Code: Select all

OPTION COPY                                                         
OUTFIL REMOVECC,NODETAIL,                                           
SECTIONS=(1,2,                                                      
TRAILER3=(1,2,X,TOT=(4,3,ZD,TO=ZD,LENGTH=3),X,COUNT=(EDIT=(IT))))   
If left aligned then

Code: Select all

//SYSIN    DD *                                                     
  OPTION COPY                                                       
  INREC OVERLAY=(4:4,3,SQZ=(SHIFT=RIGHT))                           
  OUTFIL REMOVECC,NODETAIL,                                         
  SECTIONS=(1,2,                                                    
  TRAILER3=(1,2,X,TOT=(4,3,ZD,TO=ZD,LENGTH=4),X,COUNT=(EDIT=(IT)))) 
/*                                                                  
Note : the output sum value is of 4 bytes and count is of 2 bytes, you may need to adjust according to your requirements.