WDA – User defined functions in ALV
In WebDynpro-ALV, we can provide our own UI elements (buttons, drop-down list, input field, toggle button etc.) in the tool bar of the ALV, for performing application specific functions
Using the search term SAP List Viewer in Web Dynpro we find great articles (PDF files) contributed by Claudia Dangers for handling ALVs in WDA.
SAP List Viewer in Web Dynpro – Simple Example for Using ALV
SAP List Viewer in Web Dynpro – Programming the ALV Configuration Model
SAP List Viewer in Web Dynpro – Editing ALV
SAP List Viewer in Web Dynpro – Using Events with ALV Tables
SAP List Viewer in Web Dynpro – Using ALV with a Dynamic Context Node
Of special interest is the article SAP List Viewer in Web Dynpro – Editing ALV where the author has provided an example on how to make the ALV editable and save the changes after editing, by using a button UI element.
In this weblog, I will try to enhance this example by providing a user-defined function element for saving, which will be integrated in the ALV tool bar instead of a separate button element. I suggest you to go through the above documents before carrying on with this enhancement.
Let’s first look at the steps involved in enhancing the ALV with user defined functions and appropriate UI element.
1. First we have to create a function, which is an instance of class CL_SALV_WD_FUNCTION. This can be done by using the method
IF_SALV_WD_FUNCTION_SETTINGS~CREATE_FUNCTION of the ALV model. The created function is supplied with a unique ID for future event handling.
3.Now, when the user chooses this function, the event ON_FUNCTION of the ALV interface is triggered. We define a handler method for this event which has an importing parameter ‘R_PARAM’. This parameter contains the unique ID of the function key chosen by the user.
Now let us enhance the example. The source code is as follows.
data: lr_column_settings type ref to if_salv_wd_column_settings,
lr_column type ref to cl_salv_wd_column,
lr_input_field type ref to cl_salv_wd_uie_input_field.
lr_column_settings ?= l_value.
lr_column = lr_column_settings->get_column( 'PRICE' ).
create object lr_input_field exporting value_fieldname = 'PRICE'.
lr_column->set_cell_editor( lr_input_field ).
data: lr_table_settings type ref to if_salv_wd_table_settings.
lr_table_settings ?= l_value.
lr_table_settings->set_read_only( ABAP_FALSE ).
* Add our own functions
data: lr_user_function1 type ref to cl_salv_wd_function.
lr_user_function1 = l_value->if_salv_wd_function_settings~create_function_right( id = 'SAVE' ).
* The function is a button
data: lr_save_button type ref to cl_salv_wd_fe_button,
lv_button_text type string.
create object lr_save_button.
lv_button_text = cl_wd_utilities=>get_otr_text_by_alias( '$TMP/SAVE' ).
lr_save_button->set_text( lv_button_text ).
lr_user_function1->set_editor( lr_save_button ).
data: l_ref_interfacecontroller_alv type ref to iwci_salv_wd_table .
l_ref_interfacecontroller_alv = wd_this->wd_cpifc_alv( ).
In the above method, we call the data_check() method of ALV interface which will in turn trigger event ON_DATA_CHECK of the ALV interface. The event handler method ONDATACHECK is already explained in the original example.
The output looks likes below. We see the save button is integrated in the ALV toolbar