Skip to Content

It’s sometimes useful to create nodes and attributes at runtime.  You may need to bind dynamically built controls to a context node or an attribute that is unknown until run time.  For example, you may want to build a checkbox or an input field and bind it to a specific attribute of a specific data element type.  Or, you may want to build a radio button group which is bound to a context node that is not known until runtime.  I’ll provide examples for several object types: InputField, RadioButtonGroup, and CheckBoxGroup.  Adding a Dynamic Table example per request.

I’ll work with the following example project:

/wp-content/uploads/2013/01/pic__178706.jpg

In the component controller, create the following method and parameters:

/wp-content/uploads/2013/01/pic__178706.jpg

In the WDDOMODIFYVIEW method of view V_MAIN, add the following code:

method wddomodifyview .

  data lo_componentcontroller type ref to ig_componentcontroller .
  data lr_container type ref to cl_wd_uielement_container.

  lo_componentcontroller = wd_this->get_componentcontroller_ctr( ).
  if first_time = abap_true.
    lr_container ?= view->get_element( ‘ROOTUIELEMENTCONTAINER’ ).
    lo_componentcontroller->build_web_controls( i_container = lr_container i_view = view i_view_context = wd_context ).
  endif.

endmethod.

Test 1:   Dynamic InputField and Context

Add the following code to the component controller BUILD_WEB_CONTROLS method:

method build_web_controls .

  data l_ui_input_field type ref to cl_wd_input_field.
  data l_ui_matrix_head_data type ref to cl_wd_matrix_head_data.
  data root_node_info type ref to if_wd_context_node_info.
  data lo_node_info type ref to if_wd_context_node_info.
  data lo_dyn_node_info type ref to if_wd_context_node_info.
  data wa_path type wdr_ctx_element_name.
  data tab_mapping_path type wdr_ctx_element_path_segments.
  data stru_mapping_info type wdr_context_mapping_info.
  data lv_attribute type wdr_context_attribute_info.

  root_node_info = wd_context->get_node_info( ).

  “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
  “Create a Single Context Attribute and an Input Field
  “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
  lv_attribute-name = ‘CONTEXTA’.
  lv_attribute-type_name = ‘CHAR30’.
  lv_attribute-value_help_mode = ‘0’.
  call method root_node_info->add_attribute( exporting attribute_info = lv_attribute ).
  clear tab_mapping_path.  refresh tab_mapping_path.
  concatenate ‘COMPONENTCONTROLLER.’ ‘CONTEXTA’ into wa_path.
  insert wa_path into table tab_mapping_path.
  stru_mapping_info-controller = ‘COMPONENTCONTROLLER’.
  stru_mapping_info-path = tab_mapping_path.
  lo_node_info = i_view_context->get_node_info( ).
  call method lo_node_info->add_new_mapped_child_node( exporting child_name = ‘CONTEXTA’ mapping_info = stru_mapping_info receiving child_node_info = lo_dyn_node_info ).
  call method cl_wd_input_field=>new_input_field( exporting id = ‘CONTROLA’ bind_value = ‘CONTEXTA.CONTEXTA’ receiving control = l_ui_input_field ).
  l_ui_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( l_ui_input_field ).
  l_ui_input_field->set_layout_data( l_ui_matrix_head_data ).
  call method i_container->add_child( exporting the_child = l_ui_input_field ).

endmethod.

Testing Results (Works Great!):

/wp-content/uploads/2013/01/pic__178706.jpg

Test 2:   Dynamic RadioButtonGroup and Context

Add the following code to the component controller BUILD_WEB_CONTROLS method:

method build_web_controls .

  data l_ui_radiobutton_group_by_idx type ref to cl_wd_radiobutton_group_by_idx.
  data l_ui_input_field type ref to cl_wd_input_field.
  data l_ui_matrix_head_data type ref to cl_wd_matrix_head_data.
  data root_node_info type ref to if_wd_context_node_info.
  data lo_node_info type ref to if_wd_context_node_info.
  data lo_dyn_node_info type ref to if_wd_context_node_info.
  data dyn_node type ref to if_wd_context_node.
  data wa_path type wdr_ctx_element_name.
  data tab_mapping_path type wdr_ctx_element_path_segments.
  data stru_mapping_info type wdr_context_mapping_info.
  data lv_attribute type wdr_context_attribute_info.
  data lt_valueset type standard table of wdr_context_attr_value.
  data ls_valueset type wdr_context_attr_value.

  root_node_info = wd_context->get_node_info( ).

   “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
   “Create a Single Context Attribute and an Input Field
   “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
  lv_attribute-name = ‘CONTEXTA’.
  lv_attribute-type_name = ‘CHAR30’.
  lv_attribute-value_help_mode = ‘0’.
  call method root_node_info->add_attribute( exporting attribute_info = lv_attribute ).
  clear tab_mapping_path.  refresh tab_mapping_path.
  concatenate ‘COMPONENTCONTROLLER.’ ‘CONTEXTA’ into wa_path.
  insert wa_path into table tab_mapping_path.
  stru_mapping_info-controller = ‘COMPONENTCONTROLLER’.
  stru_mapping_info-path = tab_mapping_path.
  lo_node_info = i_view_context->get_node_info( ).
  call method lo_node_info->add_new_mapped_child_node( exporting child_name = ‘CONTEXTA’ mapping_info = stru_mapping_info receiving child_node_info = lo_dyn_node_info ).
  call method cl_wd_input_field=>new_input_field( exporting id = ‘CONTROLA’ bind_value = ‘CONTEXTA.CONTEXTA’ receiving control = l_ui_input_field ).
  l_ui_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( l_ui_input_field ).
  l_ui_input_field->set_layout_data( l_ui_matrix_head_data ).
  call method i_container->add_child( exporting the_child = l_ui_input_field ).

  “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
  “Create a Context Node and a RadioButtonGroup
  “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
  call method root_node_info->add_new_child_node
    exporting
      static_element_type          = ‘WDR_CONTEXT_ATTR_VALUE’
      name                         = ‘CONTEXTB’
      is_mandatory                 = abap_true
      is_multiple                  = abap_true
      is_multiple_selection        = abap_false
      is_singleton                 = abap_false
      is_initialize_lead_selection = abap_false
      is_static                    = abap_true.
  clear tab_mapping_path.  refresh tab_mapping_path.
  concatenate ‘COMPONENTCONTROLLER.’ ‘CONTEXTB’ into wa_path.
  insert wa_path into table tab_mapping_path.
  stru_mapping_info-controller = ‘COMPONENTCONTROLLER’.
  stru_mapping_info-path = tab_mapping_path.
  lo_node_info = i_view_context->get_node_info( ).
  call method lo_node_info->add_new_mapped_child_node( exporting child_name = ‘CONTEXTB’ mapping_info = stru_mapping_info receiving child_node_info = lo_dyn_node_info ).
  ls_valueset-value = ‘VALUE1’.
  ls_valueset-text = ‘VALUE1TEXT’.
  append ls_valueset to lt_valueset.
  ls_valueset-value = ‘VALUE2’.
  ls_valueset-text = ‘VALUE2TEXT’.
  append ls_valueset to lt_valueset.
  ls_valueset-value = ‘VALUE3’.
  ls_valueset-text = ‘VALUE3TEXT’.
  append ls_valueset to lt_valueset.
  dyn_node = wd_context->get_child_node( name = ‘CONTEXTB’ ).
  dyn_node->bind_table( lt_valueset ).
  call method cl_wd_radiobutton_group_by_idx=>new_radiobutton_group_by_idx
    exporting
       bind_texts                 = ‘CONTEXTB.CONTEXTB.TEXT’
       id                         = ‘CONTROLB’
       on_select                  = ‘ONRBSELECT’
    receiving
       control                    = l_ui_radiobutton_group_by_idx.
  l_ui_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( l_ui_radiobutton_group_by_idx ).
  l_ui_radiobutton_group_by_idx->set_layout_data( l_ui_matrix_head_data ).
  call method i_container->add_child( exporting the_child = l_ui_radiobutton_group_by_idx ).

endmethod.

Testing Results (Works Great!):

/wp-content/uploads/2013/01/pic__178706.jpg

Test 3:   Dynamic CheckBoxGroup and Context

Add the following code to the component controller BUILD_WEB_CONTROLS method:

method build_web_controls .

  data l_ui_checkbox_group type ref to cl_wd_checkbox_group.
  data l_ui_radiobutton_group_by_idx type ref to cl_wd_radiobutton_group_by_idx.
  data l_ui_input_field type ref to cl_wd_input_field.
  data l_ui_matrix_head_data type ref to cl_wd_matrix_head_data.
  data root_node_info type ref to if_wd_context_node_info.
  data lo_node_info type ref to if_wd_context_node_info.
  data lo_dyn_node_info type ref to if_wd_context_node_info.
  data dyn_node type ref to if_wd_context_node.
  data wa_path type wdr_ctx_element_name.
  data tab_mapping_path type wdr_ctx_element_path_segments.
  data stru_mapping_info type wdr_context_mapping_info.
  data lv_attribute type wdr_context_attribute_info.
  data lt_valueset type standard table of wdr_context_attr_value.
  data ls_valueset type wdr_context_attr_value.

  root_node_info = wd_context->get_node_info( ).

  “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
  “Create a Single Context Attribute and an Input Field
  “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
  lv_attribute-name = ‘CONTEXTA’.
  lv_attribute-type_name = ‘CHAR30’.
  lv_attribute-value_help_mode = ‘0’.
  call method root_node_info->add_attribute( exporting attribute_info = lv_attribute ).
  clear tab_mapping_path.  refresh tab_mapping_path.
  concatenate ‘COMPONENTCONTROLLER.’ ‘CONTEXTA’ into wa_path.
  insert wa_path into table tab_mapping_path.
  stru_mapping_info-controller = ‘COMPONENTCONTROLLER’.
  stru_mapping_info-path = tab_mapping_path.
  lo_node_info = i_view_context->get_node_info( ).
  call method lo_node_info->add_new_mapped_child_node( exporting child_name = ‘CONTEXTA’ mapping_info = stru_mapping_info receiving child_node_info = lo_dyn_node_info ).
  call method cl_wd_input_field=>new_input_field( exporting id = ‘CONTROLA’ bind_value = ‘CONTEXTA.CONTEXTA’ receiving control = l_ui_input_field ).
  l_ui_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( l_ui_input_field ).
  l_ui_input_field->set_layout_data( l_ui_matrix_head_data ).
  call method i_container->add_child( exporting the_child = l_ui_input_field ).

  “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
  “Create a Context Node and a RadioButtonGroup
  “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
  call method root_node_info->add_new_child_node
    exporting
      static_element_type          = ‘WDR_CONTEXT_ATTR_VALUE’
      name                         = ‘CONTEXTB’
      is_mandatory                 = abap_true
      is_multiple                  = abap_true
      is_multiple_selection        = abap_false
      is_singleton                 = abap_false
      is_initialize_lead_selection = abap_false
      is_static                    = abap_true.
  clear tab_mapping_path.  refresh tab_mapping_path.
  concatenate ‘COMPONENTCONTROLLER.’ ‘CONTEXTB’ into wa_path.
  insert wa_path into table tab_mapping_path.
  stru_mapping_info-controller = ‘COMPONENTCONTROLLER’.
  stru_mapping_info-path = tab_mapping_path.
  lo_node_info = i_view_context->get_node_info( ).
  call method lo_node_info->add_new_mapped_child_node( exporting child_name = ‘CONTEXTB’ mapping_info = stru_mapping_info receiving child_node_info = lo_dyn_node_info ).
  ls_valueset-value = ‘VALUE1’.
  ls_valueset-text = ‘VALUE1TEXT’.
  append ls_valueset to lt_valueset.
  ls_valueset-value = ‘VALUE2’.
  ls_valueset-text = ‘VALUE2TEXT’.
  append ls_valueset to lt_valueset.
  ls_valueset-value = ‘VALUE3’.
  ls_valueset-text = ‘VALUE3TEXT’.
  append ls_valueset to lt_valueset.
  dyn_node = wd_context->get_child_node( name = ‘CONTEXTB’ ).
  dyn_node->bind_table( lt_valueset ).
  call method cl_wd_radiobutton_group_by_idx=>new_radiobutton_group_by_idx
    exporting
      bind_texts = ‘CONTEXTB.CONTEXTB.TEXT’
      id         = ‘CONTROLB’
      on_select  = ‘ONRBSELECT’
    receiving
      control    = l_ui_radiobutton_group_by_idx.
  l_ui_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( l_ui_radiobutton_group_by_idx ).
  l_ui_radiobutton_group_by_idx->set_layout_data( l_ui_matrix_head_data ).
  call method i_container->add_child( exporting the_child = l_ui_radiobutton_group_by_idx ).

  “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
  “Create a Context Node and a CheckBoxGroup
  “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
  call method root_node_info->add_new_child_node
    exporting
      static_element_type          = ‘WDR_CONTEXT_ATTR_VALUE’
      name                         = ‘CONTEXTC’
      is_mandatory                 = abap_true
      is_multiple                  = abap_true
      is_multiple_selection        = abap_false
      is_singleton                 = abap_false
      is_initialize_lead_selection = abap_false
      is_static                    = abap_true.
  clear tab_mapping_path.  refresh tab_mapping_path.
  concatenate ‘COMPONENTCONTROLLER.’ ‘CONTEXTC’ into wa_path.
  insert wa_path into table tab_mapping_path.
  stru_mapping_info-controller = ‘COMPONENTCONTROLLER’.
  stru_mapping_info-path = tab_mapping_path.
  lo_node_info = i_view_context->get_node_info( ).
  call method lo_node_info->add_new_mapped_child_node( exporting child_name = ‘CONTEXTC’ mapping_info = stru_mapping_info receiving child_node_info = lo_dyn_node_info ).
  clear lt_valueset.  refresh lt_valueset.
  ls_valueset-value = ‘VALUE1’.
  ls_valueset-text = ‘VALUE1CHKBXTEXT’.
  append ls_valueset to lt_valueset.
  ls_valueset-value = ‘VALUE2’.
  ls_valueset-text = ‘VALUE2CHKBXTEXT’.
  append ls_valueset to lt_valueset.
  ls_valueset-value = ‘VALUE3’.
  ls_valueset-text = ‘VALUE3CHKBXTEXT’.
  append ls_valueset to lt_valueset.
  dyn_node = wd_context->get_child_node( name = ‘CONTEXTC’ ).
  dyn_node->bind_table( lt_valueset ).
  call method cl_wd_checkbox_group=>new_checkbox_group
    exporting
      bind_texts = ‘CONTEXTC.CONTEXTC.TEXT’
      id         = ‘CONTROLC’
      on_toggle  = ‘ONCBSELECT’
    receiving
      control    = l_ui_checkbox_group.
  l_ui_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( l_ui_checkbox_group ).
  l_ui_checkbox_group->set_layout_data( l_ui_matrix_head_data ).
  call method i_container->add_child( exporting the_child = l_ui_checkbox_group ).

endmethod.

Testing Results (Works Great!):

/wp-content/uploads/2013/01/pic__178706.jpg

Test 4:   Dynamic Table and Context

method build_web_controls .

  data l_column_group type ref to cl_wd_table_column_group.
  data l_caption_1 type ref to cl_wd_caption.
  data l_table_column_1 type ref to cl_wd_table_column.
  data l_caption_2 type ref to cl_wd_caption.
  data l_table_column_2 type ref to cl_wd_table_column.
  data l_ui_col_input_field type ref to cl_wd_input_field.
  data l_ui_col_input_field2 type ref to cl_wd_input_field.
  data l_ui_table type ref to cl_wd_table.
  data l_ui_checkbox_group type ref to cl_wd_checkbox_group.
  data l_ui_radiobutton_group_by_idx type ref to cl_wd_radiobutton_group_by_idx.
  data l_ui_input_field type ref to cl_wd_input_field.
  data l_ui_matrix_head_data type ref to cl_wd_matrix_head_data.
  data root_node_info type ref to if_wd_context_node_info.
  data lo_node_info type ref to if_wd_context_node_info.
  data lo_dyn_node_info type ref to if_wd_context_node_info.
  data dyn_node type ref to if_wd_context_node.
  data wa_path type wdr_ctx_element_name.
  data tab_mapping_path type wdr_ctx_element_path_segments.
  data stru_mapping_info type wdr_context_mapping_info.
  data lv_attribute type wdr_context_attribute_info.
  data lt_valueset type standard table of wdr_context_attr_value.
  data ls_valueset type wdr_context_attr_value.

  root_node_info = wd_context->get_node_info( ).

*  “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
*  “Create a Single Context Attribute and an Input Field
*  “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
  lv_attributename = ‘CONTEXTA’.
  lv_attributetype_name = ‘CHAR30’.
  lv_attributevalue_help_mode = ‘0’.
  call method root_node_info->add_attribute( exporting attribute_info = lv_attribute ).
  clear tab_mapping_pathrefresh tab_mapping_path.
  concatenate ‘COMPONENTCONTROLLER.’ ‘CONTEXTA’ into wa_path.
  insert wa_path into table tab_mapping_path.
  stru_mapping_infocontroller = ‘COMPONENTCONTROLLER’.
  stru_mapping_infopath = tab_mapping_path.
  lo_node_info = i_view_context->get_node_info( ).
  call method lo_node_info->add_new_mapped_child_node( exporting child_name = ‘CONTEXTA’ mapping_info = stru_mapping_info receiving child_node_info = lo_dyn_node_info ).
  call method cl_wd_input_field=>new_input_field( exporting id = ‘CONTROLA’ bind_value = ‘CONTEXTA.CONTEXTA’ receiving control = l_ui_input_field ).
  l_ui_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( l_ui_input_field ).
  l_ui_input_field->set_layout_data( l_ui_matrix_head_data ).
  call method i_container->add_child( exporting the_child = l_ui_input_field ).

  “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
  “Create a Context Node and a RadioButtonGroup
  “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
  call method root_node_info->add_new_child_node
    exporting
      static_element_type          = ‘WDR_CONTEXT_ATTR_VALUE’
      name                         = ‘CONTEXTB’
      is_mandatory                 = abap_true
      is_multiple                  = abap_true
      is_multiple_selection        = abap_false
      is_singleton                 = abap_false
      is_initialize_lead_selection = abap_false
      is_static                    = abap_true.

  clear tab_mapping_pathrefresh tab_mapping_path.
  concatenate ‘COMPONENTCONTROLLER.’ ‘CONTEXTB’ into wa_path.
  insert wa_path into table tab_mapping_path.
  stru_mapping_infocontroller = ‘COMPONENTCONTROLLER’.
  stru_mapping_infopath = tab_mapping_path.
  lo_node_info = i_view_context->get_node_info( ).
  call method lo_node_info->add_new_mapped_child_node( exporting child_name = ‘CONTEXTB’ mapping_info = stru_mapping_info receiving child_node_info = lo_dyn_node_info ).
  ls_valuesetvalue = ‘VALUE1’.
  ls_valuesettext = ‘VALUE1TEXT’.
  append ls_valueset to lt_valueset.
  ls_valuesetvalue = ‘VALUE2’.
  ls_valuesettext = ‘VALUE2TEXT’.
  append ls_valueset to lt_valueset.
  ls_valuesetvalue = ‘VALUE3’.
  ls_valuesettext = ‘VALUE3TEXT’.
  append ls_valueset to lt_valueset.
  dyn_node = wd_context->get_child_node( name = ‘CONTEXTB’ ).
  dyn_node->bind_table( lt_valueset ).


  call method cl_wd_radiobutton_group_by_idx=>new_radiobutton_group_by_idx
    exporting
      bind_texts = ‘CONTEXTB.CONTEXTB.TEXT’
      id         = ‘CONTROLB’
      on_select  = ‘ONRBSELECT’
    receiving
      control    = l_ui_radiobutton_group_by_idx.

  l_ui_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( l_ui_radiobutton_group_by_idx ).
  l_ui_radiobutton_group_by_idx->set_layout_data( l_ui_matrix_head_data ).
  call method i_container->add_child( exporting the_child = l_ui_radiobutton_group_by_idx ).

  “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
  “Create a Context Node and a CheckBoxGroup
  “”””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
  call method root_node_info->add_new_child_node
    exporting
      static_element_type          = ‘WDR_CONTEXT_ATTR_VALUE’
      name                         = ‘CONTEXTC’
      is_mandatory                 = abap_true
      is_multiple                  = abap_true
      is_multiple_selection        = abap_false
      is_singleton                 = abap_false
      is_initialize_lead_selection = abap_false
      is_static                    = abap_true.

  clear tab_mapping_pathrefresh tab_mapping_path.

  concatenate ‘COMPONENTCONTROLLER.’ ‘CONTEXTC’ into wa_path.
  insert wa_path into table tab_mapping_path.
  stru_mapping_infocontroller = ‘COMPONENTCONTROLLER’.
  stru_mapping_infopath = tab_mapping_path.
  lo_node_info = i_view_context->get_node_info( ).

  call method lo_node_info->add_new_mapped_child_node( exporting child_name = ‘CONTEXTC’ mapping_info = stru_mapping_info receiving child_node_info = lo_dyn_node_info ).

  clear lt_valuesetrefresh lt_valueset.

  ls_valuesetvalue = ‘VALUE1’.
  ls_valuesettext = ‘VALUE1CHKBXTEXT’.
  append ls_valueset to lt_valueset.
  ls_valuesetvalue = ‘VALUE2’.
  ls_valuesettext = ‘VALUE2CHKBXTEXT’.
  append ls_valueset to lt_valueset.
  ls_valuesetvalue = ‘VALUE3’.
  ls_valuesettext = ‘VALUE3CHKBXTEXT’.

  append ls_valueset to lt_valueset.
  dyn_node = wd_context->get_child_node( name = ‘CONTEXTC’ ).
  dyn_node->bind_table( lt_valueset ).

  call method cl_wd_checkbox_group=>new_checkbox_group
    exporting
      bind_texts = ‘CONTEXTC.CONTEXTC.TEXT’
      id         = ‘CONTROLC’
      on_toggle  = ‘ONCBSELECT’
    receiving
      control    = l_ui_checkbox_group.

  l_ui_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( l_ui_checkbox_group ).
  l_ui_checkbox_group->set_layout_data( l_ui_matrix_head_data ).
  call method i_container->add_child( exporting the_child = l_ui_checkbox_group ).

  “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
  “Create a Context Node and a Table with two columns (one edit column
  “and one read only column.
  “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
  call method root_node_info->add_new_child_node
    exporting
      static_element_type          = ‘WDR_CONTEXT_ATTR_VALUE’
      name                         = ‘CONTEXTD’
      is_mandatory                 = abap_true
      is_multiple                  = abap_true
      is_multiple_selection        = abap_false
      is_singleton                 = abap_false
      is_initialize_lead_selection = abap_false
      is_static                    = abap_true.

  clear tab_mapping_pathrefresh tab_mapping_path.
  concatenate ‘COMPONENTCONTROLLER.’ ‘CONTEXTD’ into wa_path.
  insert wa_path into table tab_mapping_path.
  stru_mapping_infocontroller = ‘COMPONENTCONTROLLER’.
  stru_mapping_infopath = tab_mapping_path.
  lo_node_info = i_view_context->get_node_info( ).

  call method lo_node_info->add_new_mapped_child_node( exporting child_name = ‘CONTEXTD’ mapping_info = stru_mapping_info receiving child_node_info = lo_dyn_node_info ).

  clear lt_valuesetrefresh lt_valueset.
  ls_valuesetvalue = ‘VALUE1’.
  ls_valuesettext = ‘VALUE1TABLE’.
  append ls_valueset to lt_valueset.
  ls_valuesetvalue = ‘VALUE2’.
  ls_valuesettext = ‘VALUE2TABLE’.
  append ls_valueset to lt_valueset.
  ls_valuesetvalue = ‘VALUE3’.
  ls_valuesettext = ‘VALUE3TABLE’.
  append ls_valueset to lt_valueset.


  dyn_node = wd_context->get_child_node( name = ‘CONTEXTD’ ).
  dyn_node->bind_table( lt_valueset ).

  call method cl_wd_table=>new_table
    exporting
      bind_data_source = ‘CONTEXTD.CONTEXTD’
      id               = ‘CONTROLD’
    receiving
      control          = l_ui_table.

  l_column_group = cl_wd_table_column_group=>new_table_column_group( ).

  “Build a Table Column
  call method cl_wd_input_field=>new_input_field
    exporting
      bind_value = ‘CONTEXTD.CONTEXTD.TEXT’
      id         = ‘CONTROLE’
    receiving
      control    = l_ui_col_input_field.

  l_table_column_1 = cl_wd_table_column=>new_table_column( ).
  l_table_column_1->set_table_cell_editor( l_ui_col_input_field ).
  l_caption_1 = cl_wd_caption=>new_caption( ).
  l_caption_1->set_text( ‘TEXT’ ).
  l_table_column_1->set_header( l_caption_1 ).
  l_column_group->set_fixed_position( 1 ).
  l_column_group->add_column( l_table_column_1 ).

  “Build a Table Column
  call method cl_wd_input_field=>new_input_field
    exporting
      bind_value = ‘CONTEXTD.CONTEXTD.VALUE’
      id         = ‘CONTROLF’
      read_only  = ‘X’
    receiving
      control    = l_ui_col_input_field2.

  l_table_column_2 = cl_wd_table_column=>new_table_column( ).
  l_table_column_2->set_table_cell_editor( l_ui_col_input_field2 ).
  l_caption_2 = cl_wd_caption=>new_caption( ).
  l_caption_2->set_text( ‘VALUE’ ).
  l_table_column_1->set_header( l_caption_2 ).
  l_column_group->set_fixed_position( 2 ).
  l_column_group->add_column( l_table_column_2 ).

  l_ui_table->add_grouped_column( l_column_group ).

  l_ui_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( l_ui_table ).
  l_ui_table->set_layout_data( l_ui_matrix_head_data ).
  call method i_container->add_child( exporting the_child = l_ui_table ).
endmethod.

Testing Results (Works Great!):

/wp-content/uploads/2013/01/pic__178706.jpg

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. pu hui

    Dear Philip Johnston,

    I want to create a dynamic node(0,n) after a node in webdynpro program, and let some columns edit and read only.

    Could you please give me some ideas or sample source code.

    for example: I have defined a node name ‘A’ which have attributes ‘MATNR’ and ‘DATUM’.I want to create  dynamic node and have the following format.(Column3 to Column n base on the  table name create.)

    Colum 1   Column 2     Column3            Column4           Column5 ……. ColumnN

    MATNR    DATUM      dynamic create   dynamic create

                                       Editable             Read only

    Many thanks!

        

    (0) 
    1. Philip Johnston Post author

      So I fully understand your question, I have a question for you.  You said you want to create a dynamic node with columns read and edit.  Do you mean that you want a dynamic node that you intend to build a TABLE control and bind to the node?  And then have TABLE columns with read and edit? 

      (0) 
        1. Philip Johnston Post author

          You manage the edit and readonly attributes not at the context level but at the control level.  For each control you add to the table columns, you specify the read only attribute.  Here’s an example:  I build a dynamic node and table control with two columns.  One column is read only and the other is edit.  The code is below (I will also update the main post).

            “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
            “Create a Context Node and a Table with two columns (one edit column
            “and one read only column.
            “””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
            call method root_node_info->add_new_child_node
              exporting
                static_element_type          = ‘WDR_CONTEXT_ATTR_VALUE’
                name                         = ‘CONTEXTD’
                is_mandatory                 = abap_true
                is_multiple                  = abap_true
                is_multiple_selection        = abap_false
                is_singleton                 = abap_false
                is_initialize_lead_selection = abap_false
                is_static                    = abap_true.


            clear tab_mapping_pathrefresh tab_mapping_path.
            concatenate ‘COMPONENTCONTROLLER.’ ‘CONTEXTD’ into wa_path.
            insert wa_path into table tab_mapping_path.
            stru_mapping_infocontroller = ‘COMPONENTCONTROLLER’.
            stru_mapping_infopath = tab_mapping_path.
            lo_node_info = i_view_context->get_node_info( ).
            call method lo_node_info->add_new_mapped_child_node( exporting child_name = ‘CONTEXTD’ mapping_info = stru_mapping_info receiving child_node_info = lo_dyn_node_info ).
            clear lt_valuesetrefresh lt_valueset.
            ls_valuesetvalue = ‘VALUE1’.
            ls_valuesettext = ‘VALUE1TABLE’.
            append ls_valueset to lt_valueset.
            ls_valuesetvalue = ‘VALUE2’.
            ls_valuesettext = ‘VALUE2TABLE’.
            append ls_valueset to lt_valueset.
            ls_valuesetvalue = ‘VALUE3’.
            ls_valuesettext = ‘VALUE3TABLE’.
            append ls_valueset to lt_valueset.

            dyn_node = wd_context->get_child_node( name = ‘CONTEXTD’ ).
            dyn_node->bind_table( lt_valueset ).

            call method cl_wd_table=>new_table
              exporting
                bind_data_source = ‘CONTEXTD.CONTEXTD’
                id               = ‘CONTROLD’
              receiving
                control          = l_ui_table.

            l_column_group = cl_wd_table_column_group=>new_table_column_group( ).

            “Build a Table Column
            call method cl_wd_input_field=>new_input_field
              exporting
                bind_value = ‘CONTEXTD.CONTEXTD.TEXT’
                id         = ‘CONTROLE’
              receiving
                control    = l_ui_col_input_field.

            l_table_column_1 = cl_wd_table_column=>new_table_column( ).
            l_table_column_1->set_table_cell_editor( l_ui_col_input_field ).
            l_caption_1 = cl_wd_caption=>new_caption( ).
            l_caption_1->set_text( ‘TEXT’ ).
            l_table_column_1->set_header( l_caption_1 ).
            l_column_group->set_fixed_position( 1 ).
            l_column_group->add_column( l_table_column_1 ).

            “Build a Table Column
            call method cl_wd_input_field=>new_input_field
              exporting
                bind_value = ‘CONTEXTD.CONTEXTD.VALUE’
                id         = ‘CONTROLF’
                read_only  = ‘X’
              receiving
                control    = l_ui_col_input_field2.

            l_table_column_2 = cl_wd_table_column=>new_table_column( ).
            l_table_column_2->set_table_cell_editor( l_ui_col_input_field2 ).
            l_caption_2 = cl_wd_caption=>new_caption( ).
            l_caption_2->set_text( ‘VALUE’ ).
            l_table_column_1->set_header( l_caption_2 ).
            l_column_group->set_fixed_position( 2 ).
            l_column_group->add_column( l_table_column_2 ).
            l_ui_table->add_grouped_column( l_column_group ).
            l_ui_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( l_ui_table ).
            l_ui_table->set_layout_data( l_ui_matrix_head_data ).
            call method i_container->add_child( exporting the_child = l_ui_table ).

          (0) 

Leave a Reply