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:

http://www.teamabap.com/2014/05/a-simple-alv-report.html

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.

clip_image001

Coding will be generated as below.

clip_image002

 

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.

clip_image003

Coding will be generated as below.

clip_image004

 

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.

clip_image005

 

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.

 

clip_image006

 

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.

 

Output:

clip_image007

 

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.

clip_image009

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.

 

 

clip_image011

Test the output.

 

 

About Arun

0 Comments:

Post a Comment

Powered by Blogger.