Page 1 of 1

ADD THE VALUES USING SUM

PostPosted: Wed Jul 15, 2009 11:25 pm
by MAINFRAME GURU
Hi guys,

I am trying to sum the prices of a particular book using "SUM". However, I am not getting the SUM... I am getting all the records.

Here are the details

Input file is :

1001 MATHS 200
1002 ENG   250
1002 ENG   235
1002 ENG   215


Expected Output:

1002 ENG   700


Current output :

1002 ENG  250
1002 ENG  235
1002 ENG  215


Code is below :

//STEP2    EXEC PGM=SORT                                     
//SYSOUT   DD SYSOUT=*                                       
//SORTIN   DD DSN=XYZ.TEST1.ISORT,DISP=SHR               
//SORTOUT  DD DSN=XYZ.TEST1.OSORT,DISP=(NEW,CATLG,DELETE),
//           SPACE=(CYL,(1,1),RLSE),                         
//           DCB=(BLKSIZE=8000,LRECL=80,RECFM=FB)             
//SYSIN    DD *                                               
    SORT FIELDS=(1,4,CH,A)                                   
    INCLUDE COND=(6,5,CH,EQ,C'ENG  ')                         
    SUM FIELDS=(12,4,BI)                                     
/*                           


I am using Z/OS DFSORT V1R5.

Can anyone please help me?

Re: ADD THE VALUES USING SUM

PostPosted: Thu Jul 16, 2009 12:50 am
by MAINFRAME GURU
I have also seen this message

ICE152I 0 OVERFLOW DURING SUMMATION - RC=0

and then I changed it from BI to ZD with the below code

SUM FIELDS=(12,2,ZD)


But I got wrong sum

which is 690 instead of 700.

PS :- I changed from (12,4,BI) to (12,2,ZD) {not (12,4,ZD) as its giving S0C7 error}.

Can you please help me?

Re: ADD THE VALUES USING SUM

PostPosted: Thu Jul 16, 2009 1:35 am
by Frank Yaeger
As far as I can tell, your amount field is in positions 12-14, so you should be using 12,3,ZD, not 12,4,BI or 12,3,ZD or 12,4,ZD. When I used this with DFSORT:

    SORT FIELDS=(1,4,CH,A)               
    INCLUDE COND=(6,5,CH,EQ,C'ENG')       
    SUM FIELDS=(12,3,ZD)                 


The output was:

1002 ENG   700     


You need to be careful to get the starting position and length right.

Alternatively, you could use 11,4,ZD which would give you the following and prevent overflow if you total is greater than 999:

1002 ENG  0700


If you want something else, state more clearly exactly what you want.

Re: ADD THE VALUES USING SUM

PostPosted: Thu Jul 16, 2009 2:12 am
by MAINFRAME GURU
Thanks Frank for your help!!!

Its working fine now...

Regards,
Guru