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 text tooltip icon position ... ) |
Adds a custom button to the toolbar. Requires cl_gui_container=>default_screen (see below). Raises CX_SALV_EXISTING if name already exists, CX_SALV_WRONG_CALL if called on a truly fullscreen SALV. |
Example — standard buttons (fullscreen)¶
Enable all standard buttons and selectively hide layout save:
REPORT z_salv_functions_demo.
TYPES: BEGIN OF ty_user,
bname TYPE usr02-bname,
ustyp TYPE usr02-ustyp,
gltgv TYPE usr02-gltgv,
gltgb TYPE usr02-gltgb,
END OF ty_user.
DATA: lt_users TYPE STANDARD TABLE OF ty_user,
lo_alv TYPE REF TO cl_salv_table.
START-OF-SELECTION.
SELECT bname ustyp gltgv gltgb
FROM usr02
INTO CORRESPONDING FIELDS OF TABLE lt_users
UP TO 50 ROWS.
TRY.
cl_salv_table=>factory(
IMPORTING r_salv_table = lo_alv
CHANGING t_table = lt_users ).
DATA(lo_functions) = lo_alv->get_functions( ).
lo_functions->set_all( abap_true ).
lo_functions->set_layout_save( abap_false ). " hide layout save
lo_alv->display( ).
CATCH cx_salv_msg INTO DATA(lx_salv).
MESSAGE lx_salv->get_text( ) TYPE 'E'.
ENDTRY.
Example — custom button using default_screen¶
add_function requires the ALV to be embedded in a container. The simplest way to do this in a plain REPORT is cl_gui_container=>default_screen, which attaches the ALV to the standard list screen.
Important: you must issue at least one WRITE statement before the TRY block to activate the list screen. Without it, default_screen has no screen to attach to and the ALV will not display.
REPORT z_salv_functions_demo.
CLASS lcl_handler DEFINITION.
PUBLIC SECTION.
METHODS on_added_function
FOR EVENT added_function OF cl_salv_events_table
IMPORTING 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.
TYPES: BEGIN OF ty_user,
bname TYPE usr02-bname,
ustyp TYPE usr02-ustyp,
gltgv TYPE usr02-gltgv,
gltgb TYPE usr02-gltgb,
END OF ty_user.
DATA: lt_users TYPE STANDARD TABLE OF ty_user,
lo_alv TYPE REF TO cl_salv_table,
lo_handler TYPE REF TO lcl_handler.
START-OF-SELECTION.
SELECT bname ustyp gltgv gltgb
FROM usr02
INTO CORRESPONDING FIELDS OF TABLE lt_users
UP TO 50 ROWS.
WRITE: / space. " activate the list screen so default_screen exists
TRY.
cl_salv_table=>factory(
EXPORTING r_container = cl_gui_container=>default_screen
IMPORTING r_salv_table = lo_alv
CHANGING t_table = lt_users ).
" --- standard toolbar ---
DATA(lo_functions) = lo_alv->get_functions( ).
lo_functions->set_all( abap_true ).
" --- custom button ---
lo_functions->add_function(
name = 'MY_ACTION'
text = 'My Action'
tooltip = 'Run My Action'
icon = 'ICON_EXECUTE_OBJECT'
position = if_salv_c_function_position=>right_of_salv_functions ).
" --- event handler ---
lo_handler = NEW lcl_handler( ).
DATA(lo_events) = lo_alv->get_event( ).
SET HANDLER lo_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'.
CATCH cx_salv_wrong_call INTO DATA(lx_wrong).
MESSAGE lx_wrong->get_text( ) TYPE 'E'.
ENDTRY.
Common pitfalls¶
WRITE: / space. is mandatory before default_screen
cl_gui_container=>default_screen is a static reference to the SAP standard list screen. That screen only exists after the first WRITE (or WRITE: / space.) statement has executed. If you call factory() with default_screen before any WRITE, the container has no screen to attach to and the ALV will not appear.
add_function raises CX_SALV_WRONG_CALL without a container
Calling add_function on a fully fullscreen SALV — factory() called with no r_container at all — raises CX_SALV_WRONG_CALL (SALV_EXCEPTION027). Always pass cl_gui_container=>default_screen (or another container) when you need custom buttons.
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.
- The
iconparameter foradd_functiontakes the icon name as a plain string literal:'ICON_EXECUTE_OBJECT'. Do not useCONV string( icon_execute_object )from include<icon_d>here — that produces an@XX@encoded value which is not expected by this parameter. Browse available icon names in transactionICON. textis the short button label shown on the toolbar;tooltipis the quick-info text shown on hover.- 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