cancel
Showing results for 
Search instead for 
Did you mean: 

Filling nested nodes (tables)

former_member425121
Participant
0 Kudos

Hello experts

I'm working with nodes with have nested nodes because i have a header-detail tables.

When I try to fill the father table node with the internal table wich has the subtable, it fills the node but does not fills the nested node:

lo_nd_header->bind_table( lt_header )  " Does not fill the nested table nodes

So i need to fill the header node and then make a cycle to fill the subnode for each header record, something like this:

lo_nd_header->bind_table( lt_header )

LOOP AT lt_header INTO ls_header

      lo_nd_detail = lo_nd_header->get_child_node( name = 'DETAIL'    index = sy-tabix )   

      lo_nd_detail->bind_table( ls_header-detail )   "  ls_header-detail  is a table

ENDLOOP

My doubt is if there is a way to fill a node including its nested table nodes in one step without need to make a cycle.

I guess is not possible because how can we get the child node if there is not created yet the corresponding header node record; but i'm trying to check it because if we have a 3 levels nested tables i think then we need to have nested LOOPs , something like this:

lo_nd_header->bind_table( lt_header )

LOOP AT lt_header INTO ls_header

     lo_nd_detail = lo_nd_header->get_child_node( name = 'DETAIL'     index = sy-tabix )

     lo_nd_detail->bind_table( ls_header-detail )

     LOOP AT ls_header-detail INTO ls_detail

           lo_nd_subdetail = lo_nd_detail->get_child_node( name = 'SUBDETAIL'  index = sy-tabix )

           lo_nd_subdetail->bind_table( ls_detail-subdetail )

     ENDLOOP

ENDLOOP

Regards

Frank

Accepted Solutions (1)

Accepted Solutions (1)

Abhijeet-K
Active Participant
0 Kudos

Hi Frank,

The approach you are following is correct, and (unfortunately) the only way. The reason for it is the very thing you stated: a child (sub node) cannot be created, when the parent (node) is not present.

There is a minor variant to this approach, though, wherein you can follow a create_element-bind_element iteration. But here too, you can't escape the nested loops.

former_member425121
Participant
0 Kudos

Thanks Chengalarayulu, i got the variance in the code you provided by using lo_el_header and lo_el_detail.

Thanks Abhijeet, i got we need to use nested LOOPs ; could you explain please that variant with  create_element-bind_element iteration ?

I'm trying to explore these codes because in fact i'm going to use 4 level nested nodes so i will need to use 3 nested LOOPs.

Best Regards

Frank

Abhijeet-K
Active Participant
0 Kudos

Hi Frank,

The variant is simple. Follow these steps:

  1. Create the tables for all levels.
  2. Create the element of outermost node, say A.
  3. Then get the child node of sub-level node, say B.
  4. Create elements for this node, like step 2 and 3, till the innermost level.
  5. Bind the elements of innermost level first, going up to outermost level, setting all fields.

The idea is, loop less. This way, you will append the entire record just once, as against the existing procedure, where you bind once and then rebind a part in step. As I said, the variant is minor and more of performance improvement rather than process improvement.

chengalarayulu
Active Contributor
0 Kudos

Frank, is it solved?

Answers (1)

Answers (1)

chengalarayulu
Active Contributor
0 Kudos

Frank,

try with the below snippet. still the problem exists, just use the direct types for sub nodes( ls_header-detail &  ls_detail-subdetail) and try.

LOOP AT lt_header INTO ls_header.

lo_el_header = lo_nd_header->get_element( index = sy-tabix ).

lo_nd_detail = lo_el_header->get_child_node( name = 'DETAIL' ).

lo_nd_detail->bind_table( new_items = ls_header-detail set_initial_elements = abap_true ).

     LOOP AT ls_header-detail INTO ls_detail

               lo_el_detail = lo_nd_detail->get_element( index = sy-tabix ).

               lo_nd_subdetail = lo_el_detail->get_child_node( name = 'SUBDETAIL' ).

               lo_nd_subdetail->bind_table( new_items = ls_detail-subdetail

                                                       set_initial_elements = abap_true ).

     ENDLOOP

ENDLOOP