cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic component usage of select options

Former Member
0 Kudos

Hi all,

I know, dynamic component usage as been discussed several times here, but it seems that I am not smart enough, to understand it.

Maybe somebody can help me.

During runtime, I generate a tabstrip with a various number of tabs.

Each tab should contain a select_option component.

In WDDOINIT of the View I implemented the following:

      
      DATA lo_componentcontroller TYPE REF TO ig_componentcontroller .
      lo_componentcontroller =   wd_this->get_componentcontroller_ctr( ).

      lo_componentcontroller->define_compusages_so( ).

      lo_componentcontroller->add_compusages_so(
          p_embpos    = lv_selopt_emb_pos    " string
          p_usagename = lv_selopt_node_name  " string
          p_used_comp = 'WDR_SELECT_OPTIONS' " string
        ).

LV_SELOPT_EMB_POS contains "V1.SEL_OPT1"

LV_SELOPT_NODE_NAME contains "SEL_OPT1"

The container SEL_OPT1 is getting created dynamically on View V1 in WDDOMODIFYVIEW.

In WDDOMODIFYVIEW of the View is this:

Create the


      DATA: lt_range_table  TYPE REF TO data,
            rt_range_table  TYPE REF TO data,
            read_only       TYPE abap_bool,
            typename        TYPE string,
            l_ref_cmp_usage TYPE REF TO if_wd_component_usage,
            L_VIEW_CONTROLLER_API type ref to IF_WD_VIEW_CONTROLLER.

      sel_opt_uielem = cl_wd_view_container_uielement=>new_view_container_uielement(
        id      = lv_elem_id
        visible = CL_WD_VIEW_CONTAINER_UIELEMENT=>E_VISIBLE-VISIBLE
      ).

      .......
      Embed it into the tab and so on
      .......

      cl_wd_matrix_head_data=>new_matrix_head_data( element = sel_opt_uielem ).
      lr_form_cont->add_child( sel_opt_uielem ).

      ......

      l_ref_cmp_usage = WD_COMP_CONTROLLER->CMP_USAGE_GROUP->get_component_usage(
                                                  name = lv_elem_id ).

      IF l_ref_cmp_usage->has_active_component( ) IS INITIAL.
        l_ref_cmp_usage->create_component( ).
      ENDIF.

      L_VIEW_CONTROLLER_API = WD_THIS->WD_GET_API( ).
      try.
        L_VIEW_CONTROLLER_API->PREPARE_DYNAMIC_NAVIGATION(
              source_window_name          = 'WD_SEL_OPT'        "Name of the Window
              source_vusage_name          = 'V1_USAGE_1'
              source_plug_name            = ''
              target_component_name       = 'WDR_SELECT_OPTIONS'
              target_component_usage      = l_ref_cmp_usage->NAME
              target_view_name            = 'SELECTION_SCREEN'
              target_plug_name            = 'DEFAULT'
              target_embedding_position   = lv_elem_embedd ).
         catch cx_wd_runtime_repository.
          raise exception type cx_wdr_rt_exception.
      endtry.

      L_INTF_CONTROLLER ?= l_ref_cmp_usage->GET_INTERFACE_CONTROLLER( ).
      wd_this->m_handle = L_INTF_CONTROLLER->init_selection_screen( ).

      lt_range_table =
        wd_this->m_handle->create_range_table(
              i_typename = 'S_CARRID' ).
*
      wd_this->m_handle->add_selection_field(
          i_id = 'S_CARR_ID'
          it_result = lt_range_table
          i_read_only = read_only ).

lv_elem_embedd contains V1/SEL_OPT1.

Currently I just try to add S_CARR_ID for testing of course I need to do this more than one time in a loop.

The coding doesn´t throw any error or exeption, but the selectoption is not getting displayed ! Any other dynamically created element is displayed as expected.

Does anybody have an Idea, where my mistake is ?

Any help would be appreciated.

Best regards, Matthias

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Solution found

raja_thangamani
Active Contributor
0 Kudos

Based on your code, looks like reference pointing to interface controller is wrong.

Here is the sample code which i use to create the dynamic selection screen. It may help you:

  DATA: lt_range_table TYPE REF TO data,
        rt_range_tablle TYPE REF TO data,
        read_only TYPE abap_bool,
        typename TYPE string.

  DATA: lr_componentcontroller TYPE REF TO ig_componentcontroller,
        l_ref_cmp_usage TYPE REF TO if_wd_component_usage.

* Create the used component

  l_ref_cmp_usage = wd_this->wd_cpuse_select_options( ).
  IF l_ref_cmp_usage->has_active_component( ) IS INITIAL.
    l_ref_cmp_usage->create_component( ).
  ENDIF.
* Get a pointer to the interface controller of the select options
*component
  wd_this->m_wd_select_options = wd_this->wd_cpifc_select_options( ).

* Init the select screen.
wd_this->m_handler = wd_this->m_wd_select_options->init_selection_screen( ).

* Create the Range table that consists of new data element
lt_range_table = wd_this->m_handler->create_range_table( i_typename = 'S_CARR_ID').

*Add new field to the selection

wd_this->m_handler->add_selection_field( i_id = 'S_CARR_ID'
                                         it_result = lt_range_table
                                         i_read_only = read_only ).
* Create the Range table that consists of this new data element
lt_range_table = wd_this->m_handler->create_range_table( i_typename = 'S_CONN_ID').

*Add new field to the selection

wd_this->m_handler->add_selection_field( i_id = 'S_CONN_ID'
                                         it_result = lt_range_table
                                         i_read_only = read_only ).

Raja T

Former Member
0 Kudos

Hi Raja,

I allready know this Coding ... that´s the coding from the video tutorial from Thomas Jung.

But this doesn´t help me out. I do not wann create a dynamic SelectOption with a various number of Inputfields, I wann create a various number component usages of the SelectOption Component

I allready tried this example an this one works, but only if you declare the componentusage from selectoptions statically.

I need to declare the component usage dynamically.

Are there any other hints ?

Best regards, Matthias

Former Member
0 Kudos

hi matthias....

make sure that when you are giving inside a loop, the id must be changed dynamicallly or it may throw an error.

--regards,

alex b justin

Former Member
0 Kudos

Thanks Alex. Thats clear.

currently I just try to do this only one time to make sure it works basically.

but it doesn´t so I do not need a loop

Any idea why it is not getting displayed ?

regards, Matthias