2013 Feb 06 11:11 AM
Dear Experts,
I have developed a smartform. In that, I m facing one problem in calculating the average values of all columns without considering the zero values in columns.
The coding which I have done is given below:
CLEAR count.
LOOP AT it_final1 INTO wa_final1.
if ( wa_final1-difference9 ne '0.00'
or
wa_final1-difference8 ne '0.00'
or
wa_final1-difference7 ne '0.00'
or
wa_final1-difference6 ne '0.00'
or
wa_final1-difference5 ne '0.00'
or
wa_final1-difference4 ne '0.00'
or
wa_final1-difference3 ne '0.00' ).
count = count + 1.
endif.
wa_final1-avg_diff = wa_final1-diff_total / count.
MODIFY it_final1 FROM wa_final1.
ENDLOOP.
But I m not able to get the correct average value.
Can anybody suggest me where i m wrong.
Thanks and Regards,
Satvik
2013 Feb 06 11:34 AM
HI Satvik,
You have to increase count for every column.
I think following code will work!
LOOP AT it_final1 INTO wa_final1.
CLEAR count.
if wa_final1-difference9 <> '0.00'
count = count+1.
endif.
if wa_final1-difference8 <> '0.00'
count = count+1.
endif.
if wa_final1-difference7 <> '0.00'
count = count+1.
endif.
_
_
_
_
if count > 0.
wa_final1-avg_diff = wa_final1-diff_total / count.
MODIFY it_final1 FROM wa_final1.
endif.
ENDLOOP.
Thanks,
Sivaji.
2013 Feb 06 11:28 AM
HI,
The logic should be like this,
Inside loop,
clear count.
if ( wa_final1-difference9 ne '0.00' )
count = count +1.
elseif (wa_final1-difference8 ne '0.00' )
count = count +1.
elseif (wa_final1-difference7 ne '0.00')
count = count +1.
elseif (wa_final1-difference6 ne '0.00' )
count = count +1.
elseif (wa_final1-difference5 ne '0.00' )
count = count +1.
elseif (wa_final1-difference4 ne '0.00' )
count = count +1.
elseif (wa_final1-difference3 ne '0.00' ).
count = count +1.
endif.
Now calculate the average from the count.
Thanks,
Ben
2013 Feb 06 11:34 AM
HI Satvik,
You have to increase count for every column.
I think following code will work!
LOOP AT it_final1 INTO wa_final1.
CLEAR count.
if wa_final1-difference9 <> '0.00'
count = count+1.
endif.
if wa_final1-difference8 <> '0.00'
count = count+1.
endif.
if wa_final1-difference7 <> '0.00'
count = count+1.
endif.
_
_
_
_
if count > 0.
wa_final1-avg_diff = wa_final1-diff_total / count.
MODIFY it_final1 FROM wa_final1.
endif.
ENDLOOP.
Thanks,
Sivaji.
2013 Feb 06 11:49 AM