Removing Standard Toolbar Buttons in OO ALV Grid
Customizing the toolbar is a common requirement when developing OO ALV reports in SAP to align with specific business styles. To hide the standard buttons and replace them with custom ones, you need to populate an exclusion table and pass it to the display method.
First, define an internal table to store the function codes of the buttons you wish to suppress:
DATA: lt_hidden_funcs TYPE ui_functions.
Next, create a routine that fills this table with the specific constants representing the standard ALV functions. In this example, we identify buttons by their class cnostants and append them to the exclusion list:
FORM remove_standard_buttons TABLES pt_func_list TYPE ui_functions.
DATA: ls_func_code TYPE ui_func.
ls_func_code = cl_gui_alv_grid=>mc_fc_maximum.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_fc_minimum.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_fc_subtot.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_fc_sum.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_fc_average.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_mb_sum.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_mb_subtot.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_fc_sort_asc.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_fc_sort_dsc.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_fc_find.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_fc_filter.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_fc_print.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_fc_print_prev.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_mb_export.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_fc_graph.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_mb_view.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_fc_detail.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_fc_help.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_fc_info.
APPEND ls_func_code TO pt_func_list.
ls_func_code = cl_gui_alv_grid=>mc_mb_variant.
APPEND ls_func_code TO pt_func_list.
ENDFORM.
Finally, invoke the routine to populate the exclusion table and pass it to the set_table_for_first_display method using the it_toolbar_excluding parameter:
PERFORM remove_standard_buttons TABLES lt_hidden_funcs.
CALL METHOD grf_alv_grid->set_table_for_first_display
EXPORTING
is_variant = gs_variant_config
i_save = 'A'
is_layout = gs_layout_config
it_toolbar_excluding = lt_hidden_funcs
CHANGING
it_outtab = gt_output_data
it_fieldcatalog = gt_field_catalog.