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: 
Former Member
0 Kudos


This document will help to create Component Usage dynamically and control the position of the used Components.


We Create 2 Components.

  1. zaddr_cmp_main
  2. zaddr_cmp_sub

zaddr_cmp_main will have component usage at runtime and use zaddr_cmp_sub as component. We will have a Z table to store headings and Position number. Lets us name the table as zheadings.

First we will create zaddr_cmp_sub.

Create Context node TBL with Cardinality 1..N and attribute name email and phone.

Create Context node CAPTION with cardinality 1..1 ,attribute cap and make it as interface node for table caption from Z table

Create Interface Method SET_HEADING and create Importing parameter VALUE

Add following code in set_heading method

    DATA lo_nd_cap TYPE REF TO if_wd_context_node.
DATA lo_el_cap TYPE REF TO if_wd_context_element.
DATA ls_cap TYPE wd_this->element_caption.

  lo_nd_cap = wd_context->get_child_node( name = wd_this->wdctx_caption ).
  lo_el_cap = lo_nd_cap->get_element( ).
  lo_el_cap->set_attribute( name = 
`CAP` value = value ).

Create Table UI element and bind context

Code for Add Row

DATA lo_nd_tabl TYPE REF TO if_wd_context_node.

DATA lo_el_tabl type REF TO if_wd_context_element.

DATA is_tabl TYPE wd_this->element_tbl.

lo_nd_tabl = wd_context->get_child_node(
'TBL' ).
lo_el_tabl = lo_nd_tabl->bind_element( new_item = is_tabl
                                    set_initial_elements = abap_false ).

Now we create Z table and maintain fields and entries as below


POSNO field will help to control the position of the component


Now we create zaddr_cmp_main

We create ViewContainerUIElement dynamically to hold component zaddr_cmp_sub’s view based on Z table entries

Get all the entries in the Z table

SELECT * FROM zheadings INTO TABLE lt_tbl.

Get Component and create component usage group.

Loop thru the table entries and create viewcontaineruielement based on the position no set the layout data. Then add component usage to usage group. Depends on the requirement add the following code in init method or define the action and add the code

To pass the heading from Z table get the interface controller and call the method set_heading

select * from zheadings INTO TABLE lt_tbl.

  lo_cmp = wd_comp_controller->wd_get_api( ).
  lo_usg_grp = lo_cmp->create_cmp_usage_group( name =
                                               used_component =

  lo_view_cntrl = wd_this->wd_get_api( ).

CLEAR l_flag.
SORT lt_tbl ASCENDING BY posno.
LOOP AT lt_tbl INTO ls_tbl.
    lo_vcu = cl_wd_view_container_uielement=>new_view_container_uielement( ).
      lo_mhead_data = cl_wd_matrix_head_data=>new_matrix_head_data( lo_vcu ).
      l_flag = abap_true.
      lo_mdata = cl_wd_matrix_data=>new_matrix_data( lo_vcu ).
      l_flag = abap_false.
    wd_comp_controller->tcoref->add_child( lo_vcu ).
CLEAR: l_pos,l_usg.
    l_pos = lo_vcu->if_wd_view_element~get_id( ).
CONCATENATE 'MAIN' '/' l_pos INTO l_pos.
lo_cmp_usg = lo_usg_grp->add_component_usage( l_usg ).
                source_window_name          =
                source_vusage_name          =
                source_plug_name            =
                target_component_name       =
                target_component_usage      = l_usg
                target_view_name            =
                target_plug_name            =
                target_embedding_position   = l_pos ).
wd_this->fire_out_plg( ).

    lo_cif ?= lo_cmp_usg->get_interface_controller( ).
EXPORTING value = ls_tbl-ztext ).


Output will be like below

If we want to add another contact details maintainingthe Z table will be enough. By changing the position number we can control the position of the component.

Related Links

Labels in this area