Hi, I provide training in SAP UI5. Also feel free to checkout my new web page https://saptechblog.com
Webdynpro ABAP

Creating a custom button in ALV Toolbar


This tutorial explains creating a custom button in the ALV toolbar and handling it.

For creating the ALV report refer to the link:


Assuming that you have already created an ALV report, we are going to develop coding further to add a custom button and handle it.

This coding can be written in any controller where the ALV controller usage is defined.  

In the above reference ALV I have declared the ALV controller usage in the view (Step 3) and hence I am writing this coding in the DOINIT method of the view controller.


Step 1: Instantiate the used component to ensure that the component usage is active.


Coding will be generated as below.



Step 2: Call the GET_MODEL method of the ALV component. This method returns us the reference to the ALV configuration class CL_SALV_WD_CONFIG_TABLE.  This class contains different types of interfaces that are used for configuring the ALV table.


Coding will be generated as below.



Step 3: If you go through the class CL_SALV_WD_CONFIG_TABLE, you will be able to find an interface called IF_SALV_WD_FUNCTION_SETTINGS. This interface contains different function which we can use to modify the tool bar settings. This interface contains a method called CREATE_FUNCTION which is used to define a function in the toolbar. However, the type of function is not defined. The function needs to be mapped to an UI element say you may either want a button in the tool bar or link to action. Hence we need to define the type of UI element and provide it to the function.

First let us create the UI element type before creating the function. In transaction SE24 (Class builder) search with CL_SALV_WD_*FE*, you will get a list of class for creating different type of UI elements.

Create an object for the class CL_SALV_WD_FE_BUTTON to create a button.



Then create a custom function in the ALV tool bar by calling the Create function method of the above mentioned function settings interface and assign the button to the function.




Note: There is a standard function for Delete in the ALV which will delete the lead selected values. This example is just for demo purposes.





Handling the Custom button created.

In the methods tab of the view controller, create an Event handler method and assign it to the event ON_FUNCTION. On function is the event that is triggered by the ALV component while the custom button is being triggered.


The ID of the importing parameter R_PARAM will contain the ID which we have given while creating the Function. Using that ID we can differentiate the function and write out logic.




Test the output.



About Arun


Post a Comment

Powered by Blogger.