cancel
Showing results for 
Search instead for 
Did you mean: 

Change view in ALV by code

Former Member
0 Kudos

Hi Experts,

do you know if it is possible to change the value in the standard dropdownlist in the header area for the available views by code? I debugged and checked the forum but i didn't found an answer. Or is there another way to change the view or at least reset the view to the standard view?

Background is that in case a custom view is set the excel export only contains the columns shown in the grid and I want to avoid to implement a custom excel export having all columns independent from UI.

Thanks,

Gerd

Accepted Solutions (1)

Accepted Solutions (1)

guillaume-hrc
Active Contributor
0 Kudos

Hi,

Check this code:

DATA: lt_alv_views        TYPE wdr_pers_variants,
      ls_param_out        TYPE if_salv_wd_table=>s_type_param_config_out,
      ls_param_in         TYPE if_salv_wd_table=>s_type_param_config_in.

FIELD-SYMBOLS: <ls_alv_view>            TYPE wdr_pers_variant.

ls_param_in-action = if_salv_wd_table=>list.
ls_param_out       = lo_comp_if_alv->get_config_data( ls_param_in ).

lt_alv_views[]     = ls_param_out-t_view_list[].

READ TABLE lt_alv_views ASSIGNING <ls_alv_view> WITH KEY description = 'FULL'.
IF sy-subrc = 0.
  ls_param_in-action = if_salv_wd_table=>set.
  ls_param_in-view   = <ls_alv_view>.
  MOVE-CORRESPONDING <ls_alv_view> TO ls_param_in-config_key.
  ls_param_out       = lo_comp_if_alv->get_config_data( ls_param_in ).
ENDIF.

Best regards,

Guillaume

Former Member
0 Kudos

Hi Guillaume,

many thanks! This works perfect! I already tried this method but unfortunately not hard enough. Do you know how to identify which view is the current one? It would be great to set back the original view after the export.The returned list doesnt contain a flag for this.

Best regards,

Gerd

guillaume-hrc
Active Contributor
0 Kudos

Hi,

Try this for the initial view:

   ls_param_in-action = if_salv_wd_table=>default.

   ls_param_out       = lo_comp_if_alv->get_config_data( ls_param_in ).

And this for the current one:

   ls_param_in-action = if_salv_wd_table=>actual.

   ls_param_out       = lo_comp_if_alv->get_config_data( ls_param_in ).

Best regards,

Guillaume

Former Member
0 Kudos

That seems to work, I just need to figure out some details.

Thank you!

Answers (0)