Skip to Content

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.

Concept

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.

  2. Then we have to assign a UI element for our self defined function. This could be an object of any of the following classes.
image

  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.

Implementation

Now let us enhance the example. The source code is as follows.

Method WDDOINIT

method wddoinit
...
...

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 ).

...
...
endmethod.

Method ONUSERFUNCTION

image

case r_param->id.
when 'SAVE'.
data: l_ref_interfacecontroller_alv type ref to iwci_salv_wd_table .
l_ref_interfacecontroller_alv = wd_this->wd_cpifc_alv( ).
l_ref_interfacecontroller_alv->data_check( ).
endcase.

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.

Final Output

The output looks likes below. We see the save button is integrated in the ALV toolbar

image

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

      1. Smita Purohit
        Hello KrishnaKumar,
        This is really a nice example.
        I wanted you to help me in this regards.

        I am making enhancements to a standard component.
        The ALV component is in a view say OPERATIONS_VIEW.
        The ‘Enter Confirmation’ button is what I m looking for which is created dynamically in post-exit method of WDDOINIT. It is placed on the toolbar of the ALV…also I have registered my event handler method ‘ON_SEARCH’ to the event of the ALV ‘ON_FUNTION’.
        The ON_SEARCH method needs to be declared and defined. I do not understand where do I do it…without disturbing the standard component.

        (0) 

Leave a Reply