How to Hide UI Elements & Adjust View Layout Dynamically in Web Dynpro ABAP
Demonstrate the scenario of hiding view UI elements and aligning the elements in view layout dynamically by using recursive search
If we need to hide some view ui elements from layout dynamically, there is always the issue with the alignement of view ui elements.
In many of our applications, we need to have may UI element containers nested and deeply structured. Hence if we need to get one ui element by its ID dynamically, it is required to search in all available containers in the view layout. Hence, to search/ find the ui elements at any level, the recursive logic makes it so simple.
So, here I would like to explain the procedure to hide view ui elements and auto align them in view layout dynamically using recursive method call.
Key factor :
If we just set the visibility property of ui element to NONE, the element is hidden but the layout space still exists.
Hence we need to remove the element from view layout to make space for the following element.
Problem: We cannot get the removed element back again if we need to make it visible because its no more in the layout
Solution: We need to reset the view and build the view tree hierarchy by using standard view method VIEW->RESET_VIEW( )
Basic knowledge of Webdynpro ABAP & OO ABAP
Step by Step Process:
Create the WDA component by using T-Code SE80, and give the details as below and save the data.
Go to the context tab of view V_MAIN and create the context node FIELDS ( using table PA0001 ) and a context attribute HIDDEN_FIELD of type STRING as below
Create the view layout as below
Create a method SET_VISIBILITY( ) with parameters ID_FIELD_TO_BE_HIDDEN & IO_CONTAINER as below
Add the below code into SET_VISIBILITY( )
METHOD set_visibility .
DATA lo_container TYPE REF TO cl_wd_uielement_container.
FIELD-SYMBOLS: <fs_element> TYPE REF TO cl_wd_uielement.
lt_children = io_container->get_children( ).
LOOP AT lt_children ASSIGNING <fs_element>.
” Get the layout data of the first field to be hidden
” Remove the element from the container
” make the ui element visible
” Set the layout data of first removed ui elment
IF lo_view_elm->_is_ui_element_container EQ abap_true.
” Is container has any children ?
Add the below code in WDDOMODIFYVIEW( )
METHOD wddomodifyview .
DATA lv_hidden_fld TYPE wd_this->element_context–hidden_field.
CHECK FIRST_TIME = ABAP_FALSE.
TRANSLATE lv_hidden_fld TO UPPER CASE.
Initial output :
Now, we are going to hide the field “Personnel No.” as below
Final out put after hiding the field “Personnel No.” and End Date takes its position
Hope this helps for those who are looking for handling view ui elements & its layout dynamically.
Comments/suggestions are always welcome