Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ALV average calculation without zero values

Former Member
0 Likes
1,073

Hi Experts,

I am using the ALV grid for report output, able to get the average values and it's working fine.

User wants the average calculation only for non-zero values, meaning...

1st row = 50.00

2nd row = 20.00

3rd row = 0.00

4th row = 40.00

5th row = 0.00

In this case current output is '110.00 / 5 = 22. it's working fine.

User requriement is 110 / 3 = 36.67. Is this functionallity possible in ALV ?.

Let me know your valueable suggestion.

Thanks

Raj

6 REPLIES 6
Read only

Former Member
0 Likes
832

Hi raj,

Do not go for the standard totalling or average function in the ALV.

instead do the math in your internal table only and have it as a the last line/

like

loop at itab.
if itab-value <> 0.00.
v_total = v_total + itab-value.
count = count + 1.
endif.
at last.
v_average = v_total / count.
clear itab.
itab-value = v_average.
append itab.
endat.
endloop.

Read only

Former Member
0 Likes
832

>In this case current output is '110.00 / 5 = 22. it's working fine.

>User requriement is 110 / 3 = 36.67. Is this functionallity possible in ALV ?.

It is not possible. you need to do that manually and show it at the end.

Read only

Former Member
0 Likes
832

From ALV you cannot do this.

Instead you need to calculate the average using the values in tables.

And then use it to display.;

Regards,

Lalit Mohan Gupta.

Read only

Former Member
0 Likes
832

Hi,

I want calculate the percentage of subtotal values in the same row in alv grid report.

Is this functionality is possible...

Plz let me your suggestion.

Read only

0 Likes
832

Hi,

Did you find the solution for this request (ALV average calculation without zero values). If so, can you please send the details.

Read only

0 Likes
832

Hi,

Please check this below logic.

clear count.

loop at itab.

if not itab-value = '0.00'.

count = count + 1.

endif.

at last.

v_average = v_total / count.

itab-value = v_average.

append itab.

endat.

endloop.