Application Development 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: 

Calculate ALV based on filtered lines

Former Member
0 Kudos

Hi all,

My requirement is to calculate some final values based on the lines displayed in a grid. I want to do this calculations sensitive to the filter used when displaying the ALV. That means that, when I change the filter, I want the final values to change as well.

Is that possible?

Thanks, Bogdan

1 REPLY 1

Vinod_Chandran
Active Contributor
0 Kudos

Hi Bogdan,

You can enable the subtotal function in the ALV. The code is as follows.

data: it_sort type slis_t_sortinfo_alv,

wa_sort type slis_sortinfo_alv.

clear wa_sort.

wa_sort-fieldname = 'MATNR'. <- Field Name for which you want subtotal and total

wa_sort-tabname = 'I_DATA'. <- Internal table name

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

append wa_sort to it_sort.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = w_repid

i_callback_top_of_page = 'ALV_TOP_OF_PAGE'

i_callback_html_top_of_page = 'ALV_HTML_TOP_OF_PAGE'

is_layout = wa_layout

it_fieldcat = it_fieldcat

it_events = i_events

it_sort = it_sort

i_default = 'X'

i_save = 'A'

is_variant = w_defvar

tables

t_outtab = it_output

exceptions

program_error = 1

others = 2.

Hope this is helpful.

Thanks

Vinod