cancel
Showing results for 
Search instead for 
Did you mean: 

Help with inserting row in table

Former Member
0 Kudos

Hello Gurus,

I want to create a method to insert a row into a table wich works for any table, like the insert fuction in ALV for example.

Does anybody have a sample code or knows wich class/method ALV uses to insert rows?

Regards,

Rafael

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hallo Rafael,

Table UI is binded to the Context node, if you want to insert a row, you need the line type data and Index where you would like to insert.

So for your generic usage. You could create a class with a static method with importing

io_node type ref to if_wd_context_node

io_item type data

iv_index type i

you can use if_wd_context_node->bind_element or if_wd_context_node->bind_structure

Answers (2)

Answers (2)

gill367
Active Contributor
0 Kudos

create a method with

three paramters

name type associted type

node changing if_wd_context_node

rslt exporting WDY_BOOLEAN

index importing i

then write the follwong code and call this method whenever you want to create element.


method INSERT_TABLE .
  data el type ref to if_wd_context_element.
  el = node->create_element( ).
  data cnt type i.
  cnt = node->get_element_count( ) + 1.
  if cnt GE index.
  node->bind_element(
  new_item = el
  index = index
  set_initial_elements = abap_false

   ).
  rslt = abap_true.
  else.

      rslt = abap_false.


    endif.

endmethod.
    

thanks

sarbjeet singh

Former Member
0 Kudos

Hi Rafael,

If you want to reuse any method, create assistance class and follow as baskaran said above..

And this is the general code to insert any row to a table.. change this according to your requirement..

DATA lo_nd_segment1 TYPE REF TO if_wd_context_node.

DATA lo_el_segment1 TYPE REF TO if_wd_context_element.

DATA ls_segment1 TYPE wd_this->Element_segment1.

data lt_segment1 type wd_this->Elements_segment1.

  • navigate from <CONTEXT> to <SEGMENT1> via lead selection

lo_nd_segment1 = wd_context->get_child_node( name = wd_this->wdctx_segment1 ).

lo_el_segment1 = lo_nd_segment1->bind_structure( new_item = ls_segment1

set_initial_elements = abap_false ).

Thanks,

Kris.