Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
Showing results for 
Search instead for 
Did you mean: 
Active Contributor


This document helps how to Auto align UI elements if there are any hidden UI elements in Web Dynpro ABAP.

Here I will demonstrate a simple scenario to hide some UI elements for a particular user and then Reorder the alignment of UI elements.

Step by Step Process

Step 1: Create a Web Dynpro Component.

Go to the SE80 transaction and create a Web Dynpro Component.

Enter Description and click on OK.

Step 2: Data Binding

Go to the Context tab of Main View and create a node MATERIAL.

Enter dictionary structure MARA and click on 'Add attributes from structure'.

Select the required fields and click on OK.

Step 3: Layout Design.

   Now Go to Layout tab, and click on Web Dynpro Code Wizard( magic symbol button).

Double click on Form to create the input UI elements in Transparent container and bind them.

Click on context and select the MATERIAL Node.

Click on Continue.

Now we can see the all the input UI elements and labels are created automatically in a transparent container. Delete the unnecessary TEXT_VIEW UI element.

Now align the UI elements in the transparent container and select the label ERSDA_LBL, under properties click on bind button for Visible property.

Select the required attribute( ERSDA ), And select the radio button 'Bind to the property of selected Attribute' and select 'Visible' property. click on OK.

Similarly, select input field  ERSDA, under properties click on bind button for Visible property. Bind it to same attribute( ERSDA ), And select the radio button 'Bind to the property of selected Attribute' and select 'Visible' property. click on OK.

Now goto Methods tab, and enter below code in WDDOINIT method.

METHOD wddoinit .

   DATA lo_nd_material TYPE REF TO if_wd_context_node.
   DATA lo_el_material TYPE REF TO if_wd_context_element.

   lo_nd_material = wd_context->get_child_node( name = wd_this->wdctx_material ).

   lo_el_material = lo_nd_material->get_element( ).

   IF sy-uname = 'KIRAN_V'.
*   For this user hide the 'Created On' field
       attribute_name   `ERSDA`
         property       = lo_el_material->e_property-visible
         value          = abap_false ).


Now Save and Activate the Web Dynpro Component.

Create Application.

Create Web Dynpro Application and save it.

Enter description and save it.

Now right click on web dynpro application and click on Test.


Now you can see the output in browser with all the UI elements visible and neatly aligned for other users.


Suppose if the user 'KIRAN_V' ( to whom the 'Created on' UI has to be hidden) is logged on and execute the application, we can see the UI element 'Created On' is hidded and there is an empty gap in the layout which doesn't make it look good!


Write the below code in WDDOMODIFYVIEW method.

METHOD wddomodifyview .

   DATA: lr_container         TYPE REF TO cl_wd_transparent_container,
         lt_child                    TYPE cl_wd_uielement=>tt_uielement,
         lr_matrix_head_data TYPE REF TO cl_wd_matrix_head_data,
         lr_matrix_data          TYPE REF TO cl_wd_matrix_data,
         lv_visible                  TYPE wdui_visibility,
         lv_total_columns      TYPE i VALUE 4, " Change it based on your total columns
         lv_cur_col                TYPE i,
         lf_line_break            TYPE boole_d.

   FIELD-SYMBOLS: <lr_uielement> TYPE REF TO cl_wd_uielement.

*  Get the Transparent Container
   lr_container ?=  view->get_element( 'TRANSPARENT_CONTAINER ' ).
*  Get All UI elements in the Transparent container
   lt_child = lr_container->get_children( ).

   LOOP AT lt_child ASSIGNING <lr_uielement>.
*   Get Visibility of UI element
     lv_visible = <lr_uielement>->get_visible( ).
     IF lv_visible = '01'. " If UI Element is Hidden
*     Remove the UI element; To be used only for one time hidden UI element(s) scenario
       lr_container->remove_child( id = <lr_uielement>->id ).

*  Get the New Visible UI elements in the Transparent container
   lt_child = lr_container->get_children( ).

*  Align the Layout without empty spaces of hidden UI elements
   LOOP AT lt_child ASSIGNING <lr_uielement>.
     lv_cur_col = lv_cur_col + 1.
     IF lv_cur_col = 1.
       lf_line_break = abap_true.
       lf_line_break = abap_false.
     IF lf_line_break = abap_true.
       lr_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( <lr_uielement> ).
       <lr_uielement>->set_layout_data( lr_matrix_head_data ).
       lr_matrix_data = cl_wd_matrix_data=>new_matrix_data( <lr_uielement> ).
       <lr_uielement>->set_layout_data( lr_matrix_data ).
     IF lv_cur_col = lv_total_columns.
       CLEAR lv_cur_col.


Save and activate the component and test the application.

Now we can see that the UI elements are aligned in a proper order without the empty spaces left by Hidden UI elements.


This can be used according to yourrequirements by changing the total number of columns. Note that the above generic solution works for one time hidden UI elements scenario such as - Hide UI elements for particular user or based on some values. But not for hiding and showing UI elements(again) based on actions. In such cases, you have to add the child to the transparent container back dynamically in the corresponding action handler method.

Labels in this area