cancel
Showing results for 
Search instead for 
Did you mean: 

Difficulties to understand context nodes with child nodes

Former Member
0 Kudos

Hello Experts

I've the following requirement: Within a context node A (cardinality 0:n) contains information about let say person groups. Each person group consists of 0:n persons realized as child node B within A.

When I supply the context I do the following. I bind a structure to node A and when use the same node instance to bind a table with persons to node B:


[loop group 1 ..3]
  lo_nd_A->bind_structure( new_item = ls_A 
                                       set_initial_elements = abap_false ).

  lo_nd_B = lo_nd_A->get_child_node( name = `PERSON` ).
  lo_nd_B->bind_table( new_items = lt_person
                                 set_initial_elements = abap_false ).  
[endloop]

I'd expect that afterwards each element in A has several B elements. But unfortunately only the last element in A has elements in B.

What do I do wrong?

Regards,

Mathias

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> Hello Experts

>

> I've the following requirement: Within a context node A (cardinality 0:n) contains information about let say person groups. Each person group consists of 0:n persons realized as child node B within A.

>

> When I supply the context I do the following. I bind a structure to node A and when use the same node instance to bind a table with persons to node B:

>

>


> [loop group 1 ..3]
>   lo_nd_A->bind_structure( new_item = ls_A 
>                                        set_initial_elements = abap_false ).
> 
>   lo_nd_B = lo_nd_A->get_child_node( name = `PERSON` ).
>   lo_nd_B->bind_table( new_items = lt_person
>                                  set_initial_elements = abap_false ).  
> [endloop]
> 
> 

>

> I'd expect that afterwards each element in A has several B elements. But unfortunately only the last element in A has elements in B.

>

> What do I do wrong?

>

> Regards,

> Mathias

That is because you are only binding the "B" table you are always going back to the node A and not the new element you are inserting within the loop. I usually just bind my 'A' table, then loop through an Element Set to bind the Child 'B' table. See this example:

data:
    node_course_assign                  type ref to if_wd_context_node.
* navigate from <ZCOURSE_DETAILS> to <COURSE_ASSIGN> via lead selection
  node_course_assign = node_zcourse_details->get_child_node( name = if_componentcontroller=>wdctx_course_assign ).
  node_course_assign->bind_table( course_ass_att ).
  data: element_set type wdr_context_element_set.
  field-symbols: <wa_set> like line of element_set,
                 <wa_ass> like line of course_ass_att.
  element_set = node_course_assign->get_elements( ).
  data node_course_ass_att                 type ref to if_wd_context_node.
  loop at element_set assigning <wa_set>.
    read table course_ass_att index sy-tabix assigning <wa_ass>.
    node_course_ass_att = <wa_set>->get_child_node( name = if_componentcontroller=>wdctx_course_ass_att ).
    node_course_ass_att->bind_table( <wa_ass>-attachments ).
    data row_count type int4.
    row_count = lines( <wa_ass>-attachments ).
    if row_count = 0.
      row_count = 1.
    endif.
    <wa_set>->set_attribute(
      exporting
        name =  `ATTACHMENT_ROW_COUNT`
        value = row_count ).
  endloop.

Answers (0)