cancel
Showing results for 
Search instead for 
Did you mean: 

Bind a complex structure

Former Member
0 Kudos

Hi,

I have a context node(cardinality 0:n) which has 5 attributes and one more node(also cardinality 0:n) below to model a table type which in turn has a table type below. When I bind values to the top node values are not getting filled in the child node. I use a internal table which has the same structure as the table type and use bind_table method to fill values for the top node. Can anyone please let me know how to fill the second level node from the internal table as well.

Regards

Nilanjan

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

I have solved this problem by the following way.

First node - i am not binding as table,i am looping through (while construct) and binding as element.

On every element i am binding the node as table.

see the below code

lv_index = 0.
  WHILE lv_index < lo_nd_pl->get_element_count( ).
    ADD 1 TO lv_index.
    lo_el_pl = lo_nd_pl->get_element( lv_index ).
    lo_el_pl->get_static_attributes( IMPORTING static_attributes = ls_pl ).
 
    lo_el_item = node->create_element( ).
    MOVE-CORRESPONDING ls_pl TO ls_item.
 
    lo_el_item->set_static_attributes( ls_item ).
    node->bind_element( new_item = lo_el_item set_initial_elements = abap_false ).

    lo_nd_pl_elm = lo_el_pl->get_child_node( 'PL_ELM' ).
    lo_nd_item_elm = lo_el_item->get_child_node( 'ELM' ).

    lo_nd_pl_elm->get_static_attributes_table( IMPORTING table = lt_pl_elm ).
    lo_nd_item_elm->bind_table(
      new_items            = lt_pl_elm
      set_initial_elements = abap_false ).

  ENDWHILE

.

******

PL -- (0..n) node has child node pl_elm (0 .. n) . This is my data node i am copying this data to

ITEM .. (0..n) node with child node ELM (0..n).

Same case as your.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

The other option is to populate the parent node with the normal bind_table and then use GET_ELEMENTS to return an internal table of context elements. You can then loop through all the parent elements and bind a child node for each element.

data element_set type wdr_context_element_set.
  field-symbols <wa_set> like line of element_set.
  element_set = lo_nd_sales_items->get_elements( ).
 loop at element_set assigning <wa_set>.

   data lo_nd_sales_item_text type ref to if_wd_context_node.
    data lt_sales_item_text type wd_this->elements_sales_item_text.
    lo_nd_sales_item_text = <wa_set>->get_child_node( name = if_componentcontroller=>wdctx_sales_item_text ).
  "Get data
   lo_nd_sales_item_text->bind_table( new_items = lt_sales_item_text set_initial_elements = abap_true ).
endloop.

In sort there is no way to directly fill multiple leves of nodes from a single internal table. You must break this down populate one level of the context nodes at a time.