In Part V, we learnt how we can display the tabular output in ALV with Component Usage. In this post we would see how to add custom buttons programmatically to the ALV output tool bar/header.
It is a very common requirement as shown below (please note these buttons are not standard UI elements).
In the above figure: SELECTALL, DESELECTALL and RETRIEVEINFO are buttons which we have added at run time, programatically. They are not standard UI buttons.
How to achieve this functionality?
Once you have determined the data for the output, you bind it to the context node and call the method to SET the ALV Properties (for our example the method is “ALV_SET_AVAIL_PLANT”. This is the place where you define the button name and function code.
Let us check the important lines related to the custom buttons in this method.
Create object, provide the image source (optional), Set the text of the button (optional), provide the function code and add/set the button.
Please click the link for complete code snippet for the ALV_SET_AVAIL_PLANT. You can use this as your template for all ALV properties. Just change the field names of your table and you may or may not need the button parts (shown in the above figure).
Give special emphasis to the function code. Make sure of the case of the alphabets. You need to give the exact function code to the Event Handler method as stated below.
Once the ALV Property is set, we need to declare another Event Handler method to capture the clicks on the ALV; for our example it is SELECT_DESELECT method.
In this method we need to identify the function code and call corresponding method for action/activity you want to perform. Please see the function code in the event handler method and the ALV property method. They are exactly the same.
Say for action ‘DESELECTALL’ we want to call method deselectall( ) to deselect all the check boxes. Similarly ‘RETRIEVEINFO’ action would fetch you the plant details.
Please note, the method name can be different than the BUTTON or FUNCTION code name. In our example we have the same name for all three for simplicity.
Hope, with the above information, you would be able to add as many buttons you want and make your ALV more interactive. Please let us know, if we need to provide more information on this topic. We would be happy to add them in this post.
If you want to get such practical issues and resolutions straight to your inbox, please SUBSCRIBE. We respect your privacy and take protecting it seriously.
If you liked this post, please hit the share button at the left side of your screen.
Thank you very much for your time!!
Our series on Web Dynrpo ABAP
1. Let’s Web Dynpro. Part I : Overview of Web Dynrpo
2. Let’s Web Dynpro. Part II : Create your first Web Dynpro Application
3. Let’s Web Dynpro. Part II : Display a simple tabular output in Web Dynpro
4. Let’s Web Dynpro. Part IV : Show and hide UI elements dynamically in Web Dynpro
5. Let’s Web Dynpro. Part V : ALV display explaining Component Usage in Web Dynpro
6. Let’s Web Dynpro. Part VI : Add custom buttons programmatically to the ALV output tool bar/header
7. Let’s Web Dynpro. Part VII : Personalization and Customization in Web Dynpro
8. Let’s Web Dynpro. Part ZZ : Export an EXCEL file with data in cell formatted excel sheet with colors, borders, filters in Web Dynpro
9. Is data element WDY_BOOLEAN and Flag (Char1) same for Web Dynpro ALV? : Trick to create checkbox in ALV
10. Taking one step back after EhP7.4, does it make sense for Web Dynpro UI? : Getting back the old look and feel after EhP740 upgrade
11. Can we avoid Table Type declaration for Attributes section in Web Dynpro?
Image source: via Free Stock Photos foter.com