SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for SAP HANA and ABAP, HANA Database, SQLScript, SAP UI5, Screen Personas, Web Dynpro, Workflow

Add Button to ALV Table Header on SAP Web Dynpro

SAP ABAP programmer can add button in SALV_WD_TABLE ALV table header displayed on Web Dynpro page and code to trigger a custom event which is catched by the ALV code. Web Dynpro developer can complete adding custom button in three steps illustrated in this tutorial.

This Web Dynpro tutorial shows how to add a button on ALV table header and add custom functions to this button like "SELECT ALL", "CLEAR ALL" or "Download", etc. Below screenshot is displaying the added custom buttons besides default, standart ALV buttons on the ALV table header on a WebDynpro page.

add button in ALV table header on Web Dynpro view

ABAP programmers can expect to end up with an above result after implementing steps illustrated in this SAP tutorial. Let's start our tutorial.

Web Dynpro ABAP code to add Button on ALV Table Header

I assume that you have created an ALV table on a Web Dynpro view ViewContainerUIElement. The ALV table is being created using the SALV_WD_TABLE component.
I will not be telling how to use SALV_WD_TABLE ALV table on a Web Dynpro component in this tutorial. Instead I'll be focusing on adding buttons on ALV table header.

ABAP developers will be modifying the WDDOMODIFYVIEW method which is the method for modifying the Web Dynpro view before rendering it for the web browser users.

Within the WDDOMODIFYVIEW method, add following code block. If you have already enabled ALV events like ON_CELL_ACTION event, ON_SELECT event, etc. following code would be partially included in your ABAP development. Then Web Dynpro developer will be required to add the code blocks related with button and code related with attached funtion to this button.

* Data Declaration
DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table .
DATA lo_value TYPE REF TO cl_salv_wd_config_table.

lo_interfacecontroller = wd_this->wd_cpifc_alv_openitems( ).

* execute interface controller get_model() method for ALV configuration table
lo_value = lo_interfacecontroller->get_model( ).

* add BUTTON titled SELECT ALL
DATA bt_selectall TYPE REF TO cl_salv_wd_fe_button.
CREATE OBJECT bt_selectall.
bt_selectall->set_text( 'Select ALL' ).

DATA button1 TYPE REF TO cl_salv_wd_function.
button1 = lo_value->if_salv_wd_function_settings~create_function( id = 'SELECTALL' ).
button1->set_editor( bt_selectall ).

Only adding the above ABAP codes will not be enough to complete a successfully working button on ALV table header. Although it is enough to display the button within the SALV_WD_TABLE ALV table header beside standart buttons, to make it work ABAP programmers are required to configure the ALV to catch the ALV event triggered by the new button.

Web Dynpro developers can use ON_FUNCTION event of the ALV component use. In order to register the On_Function event, switch to Methods tab then add a new method in Event type as seen in below screenshot. Please note that, if you use F4 on Component Use you will be able to complete Event, Controller and Component Use by a single click.

Web Dynpro View methods for ALV table button function

As the third step, we need to code what we want to happen within the recently added method. If you look at the above screenshot, you will see that I named the method as SELECT_ALL. Double click on your method and switch to code view.

METHOD select_all .

DATA temp TYPE string.
temp = r_param->id.

* function id, I have to buttons one for SELECTALL and another for CLEARALL
IF temp = 'SELECTALL' OR temp = 'CLEARALL'.

DATA lo_componentcontroller TYPE REF TO ig_componentcontroller .
lo_componentcontroller = wd_this->get_componentcontroller_ctr( ).

CASE temp.
* execute your code here
  lo_componentcontroller->calculate_volume( p_select_all = 'X' ).
  lo_componentcontroller->calculate_volume( p_clear_all = 'X' ).



After applying the above 3 steps within the Web Dynpro component View, ABAP developers will complete to add buttons on ALV table header successfully. I hope it will be useful for SAP programmers who want to configure SALV_WD_TABLE ALV table component and add custom buttons on table header.


Install SAP Free
CRM Companies List
Web Based CRM Software

Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.