CL_SALV_FUNCTIONS_LIST¶
Controls the toolbar buttons (functions) shown on a CL_SALV_TABLE grid.
Purpose¶
CL_SALV_FUNCTIONS_LIST lets you enable or disable the standard SAP toolbar buttons (sort, filter, export, layout management, etc.) and add your own custom buttons. Obtain it via lo_alv->get_functions( ) — do not instantiate it directly.
Key methods¶
| Method | Signature | Effect |
|---|---|---|
set_all |
( value = abap_true ) |
Enables the full set of standard SAP toolbar buttons |
set_default |
( value = abap_true ) |
Enables a minimal default set (sort, filter, print) |
set_sort_asc |
( value = abap_true/false ) |
Show/hide ascending-sort button |
set_sort_desc |
( value = abap_true/false ) |
Show/hide descending-sort button |
set_filter |
( value = abap_true/false ) |
Show/hide filter button |
set_export |
( value = abap_true/false ) |
Show/hide spreadsheet export button |
set_layout_save |
( value = abap_true/false ) |
Show/hide layout save button |
set_print |
( value = abap_true/false ) |
Show/hide print button |
add_function |
( name saltext icon ) |
Adds a custom button to the toolbar |
Example¶
Enable all standard buttons and add one custom button:
REPORT z_salv_functions_demo.
CLASS lcl_handler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS on_added_function
FOR EVENT added_function OF cl_salv_events_table
IMPORTING sender e_salv_function.
ENDCLASS.
CLASS lcl_handler IMPLEMENTATION.
METHOD on_added_function.
CASE e_salv_function.
WHEN 'MY_ACTION'.
MESSAGE 'Custom button clicked!' TYPE 'I'.
ENDCASE.
ENDMETHOD.
ENDCLASS.
DATA: lt_users TYPE STANDARD TABLE OF usr02,
lo_alv TYPE REF TO cl_salv_table.
START-OF-SELECTION.
SELECT bname, ustyp, gltgv, gltgb
FROM usr02
INTO TABLE @lt_users
UP TO 50 ROWS.
TRY.
cl_salv_table=>factory(
IMPORTING r_salv_table = lo_alv
CHANGING t_table = lt_users ).
" --- toolbar configuration ---
DATA(lo_functions) = lo_alv->get_functions( ).
lo_functions->set_all( abap_true ). " all standard buttons
" add a custom button
lo_functions->add_function(
name = 'MY_ACTION'
saltext = VALUE saltext(
text = 'My Action'
qutext = 'Run My Action' )
icon = CONV string( icon_execute ) ).
" register event handler for the custom button
DATA(lo_events) = lo_alv->get_event( ).
SET HANDLER lcl_handler=>on_added_function FOR lo_events.
lo_alv->display( ).
CATCH cx_salv_msg INTO DATA(lx_salv).
MESSAGE lx_salv->get_text( ) TYPE 'E'.
CATCH cx_salv_existing INTO DATA(lx_exist).
MESSAGE lx_exist->get_text( ) TYPE 'E'.
ENDTRY.
Common pitfalls¶
add_function raises CX_SALV_EXISTING on duplicate names
The function name must be unique within the toolbar. If you call add_function with the same name twice, the exception CX_SALV_EXISTING is raised. Guard against this when building toolbars dynamically.
Custom button clicks are silent without an event handler
Adding a button with add_function does nothing on its own. You must register a handler for the ADDED_FUNCTION event on the CL_SALV_EVENTS_TABLE object, otherwise clicks are swallowed silently.
set_all vs set_default
set_all( abap_true ) enables every standard button SAP provides, including layout management, sum, and subtotals. set_default( abap_true ) enables only a minimal subset. Start with set_all and hide individual buttons with the specific set_*( abap_false ) calls if needed.
- Icon constants come from include
<icon_d>. Use the value directly:CONV string( icon_execute ). saltexthas two subfields:text(short button label) andqutext(quick-info tooltip).- Standard function names like
SORT_ASC,FILTER,EXPORTare reserved — do not reuse them as custom function names.
See also¶
CL_SALV_TABLE— the parent ALV objectCL_SALV_EVENTS_TABLE— handlingADDED_FUNCTIONand other eventsCL_SALV_COLUMNS_TABLE— column configuration- Demo program:
SALV_DEMO_TABLE_FUNCTIONS