Dynamically Create/Modify UI elements of Standard components without Enhancing
Introduction
Generally, when we need to modify the properties of UI elements of standard component, we go to the corresponding component, Enhance the component and change the properties of the UI element in the Layout( by removing the element and adding our element) Or, create a pre/post-exit for WDDOMODIFYVIEW method and then change the properties through code.
Instead of enhancing the Standard component(sometimes, customers don’t want to enhance the standard components, so..); we can use BAdI – WD_BADI_DOMODIFYVIEW
Here, I will just show a simple standard component and change the properties of UI elements without enhancing it.
Procedure
Let’s take a simple Standard WDA component, say., displaying Flight List.
Let’s say we need to restrict user not to enter the Depart.City or hide it.
For this, generally we go to the corresponding WDA component and enhance it and Remove the UI element or create a post-exit for WDDOMODIFYVIEW and hide the UI element via coding.
Now, here, without touching the standard component/enhancing the standard component, we will achieve this by just creating an implementation for BAdI – WD_BADI_DOMODIFYVIEW
** WD_BADI_DOMODIFYVIEW is a Filter dependent BAdI with filters COMPONENT_NAME and VIEW_NAME. We will create an implementation with filters values of the corresponding Component name and View Name.
Find the Component and View Name( by right click on the view -> Technical Help):
Find the ID of UI element: you can find it in the technical help -> view and View Elements tab:
Or, open the WDA component in SE80 and go to layout to find all the ID’s of UI elements.
Implementation
Go to SE18 transaction and open the BAdI.
Check if already an implementation available for the corresponding component(in filter value), if not, create an Implementation by right clicking on the Implementations.
Enter the Enhancement Implementation and description and click on Ok.
Enter the BAdI implementation name, description and Implementation Class.
Now, Create the Filter combination for the BAdI implementation(which is the Standard Component name and View Name).
Note: If you don’t create filter values, your implementation will be called for each Web Dynpro application( and may result in dump).
Finally, implement the method IF_WD_BADI_DOMODIFYVIEW~WDDOMODIFYVIEW of the BAdI implementation Class
Write your code in the method IF_WD_BADI_DOMODIFYVIEW~WDDOMODIFYVIEW of the implementation class.
if_wd_badi_domodifyview~wddomodifyview |
---|
METHOD if_wd_badi_domodifyview~wddomodifyview. DATA lr_ui_elem TYPE REF TO cl_wd_uielement. IF first_time = abap_true. * Hide Depart.City Label lr_ui_elem ?= view->get_element( ‘CITYFROM_LABEL_1_CP’ ). lr_ui_elem->set_visible( cl_wd_uielement=>e_visible–none ). * Hide Depart.City Input lr_ui_elem ?= view->get_element( ‘CITYFROM_INPUTFIELD_1_CP’ ). lr_ui_elem->set_visible( cl_wd_uielement=>e_visible–none ). ENDIF. ENDMETHOD. |
Save and activate the BAdI Implementation and Class.
Result
Execute the application and we can see that the label and input of Depart.City is hidden!.
Conclusion
Here I demonstrated a simple use case. You can also assign/change value help to UI elements or change the label texts or enable or disable UI elements without enhancing the Standard component and just creating an implementation for the BAdI with the filter values.
You can also remove the UI elements or change the order/alignment of UI elements without enhancing the Standard component. For coding you can check this document for reference: Auto Align UI Elements Dynamically in Web Dynpro ABAP
Also, you can create multiple implementations with the same filter values.
Limitation
With this you can also create UI elements and assign Actions to the UI elements(for ex: Inputs/Buttons) but you need to create the corresponding On_Action method in the Component. This is just the alternative for dynamically manipulating the UI elements instead of enhancing and creating Exit for the WDDOMODIFYVIEW of the standard component(s).
Hi,
Very useful info. Thanks for sharing!
Good one Kiran, Thanks..
Nice Document Kiran...
Hi Kiran,
Thanks for the wonderful blog.
Thanks
KH
Hi Kiran,
Excellent blog.
Cheers
Bhanu
Hi Kiran,
Very helpful document .
Thanks for writing.
Hi Kiran,
thank you for this blog.
I have used the BAdI WD_BADI_DOMODIFYVIEW to initialize the Canvas Manager for all views. (NWBC and Sidepanel: Initialize the Canvas Manager for all WebDynpro views)
HI,
I added on custom field in SRM (RFX Leve) and assigned DDIC field for search help, my custom field getting displayed with F4 help in editable mode but my req is i want to change that F4 help into read only mode so that user can select from F4 help only. Please help me how to solve this.
Very useful. Thanks for sharing.
Hello everyone.
I hope someone can help me. I need to change the label of an item in the output table. And add a column to the body of the alv. In the image it is possible to change the CLIENT label for another text. I already implemented this Badi but I have not achieved the result.
If someone can tell me something specific in the code that is in the Exit table in the ALV I would appreciate it.
Thanks for sharing