cancel
Showing results for 
Search instead for 
Did you mean: 

How to add/delete the row of the table in the output by having two buttons

Former Member
0 Kudos

How can I add or delete the row for the table dynamically at runtime. Example : I have a table, it displays table correctly, I need to add/delete one row on selecting a button. If we need to delete the row from table, selecting the row and press the delete button. To increase the row, I use to other button. Please explain me to add/delete the row of the table at runtime.

Thanks,

Prasad

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi ,

to add the row u can use following code in the onaction of the button



method onactiononadd .

node_material type ref to if_wd_context_node.
elem_material type ref to if_wd_context_element.
stru_material type sflight.
node_material = wd_context->get_child_node( name = 'ANNA' ).

elem_material = node_material->get_element( ).

if ( elem_material is initial ).
call method node_material->create_element
receiving
element = elem_material.
endif.

call method elem_material->get_static_attributes
importing
static_attributes = stru_material .

call method node_material->bind_structure
exporting
new_item = stru_material
set_initial_elements = abap_false.
endmethod.

I hope it helps.

Regards,

Rohit

Answers (2)

Answers (2)

arjun_thakur
Active Contributor
0 Kudos

Hi Prasad,

To remove a row you can either use the method suggested by Thomas or you can refer the method suggested by Alex Justin in this [thread|].

I hope it helps.

Regards

Arjun

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> Hi Prasad,

> To remove a row you can either use the method suggested by Thomas or you can refer the method suggested by Alex Justin in this [thread|].

>

> I hope it helps.

>

> Regards

> Arjun

It is far more efficient from a performance standpoint to remove the element than to adjust the internal table and redo the bind_table.

arjun_thakur
Active Contributor
0 Kudos

Hi Thomas,

It is far more efficient from a performance standpoint to remove the element than to adjust the internal table and redo the bind_table.

Thanks for sharing.

Regards

Arjun

Former Member
0 Kudos

Yes, solved

Former Member
0 Kudos

Hi prasad,

i tried to update the db table as well .How can i do that?

please check the code and let me know any changes required.

Data ls_nd_exc_item type   wd_this->element_nd_exc_item.

* navigate from <CONTEXT> to <ND_EXC_ITEM> via lead selection

  lO_nd_nd_exc_item = wd_context->get_child_node( name = wd_this->wdctx_nd_exc_item ).

* @TODO handle non existant child

IF lo_nd_nd_exc_item IS INITIAL.

ENDIF.

* get element via lead selection

  lo_el_nd_exc_item = lo_nd_nd_exc_item->get_element( ).

* @TODO handle not set lead selection

  IF lo_el_nd_exc_item IS INITIAL.

  ENDIF.

* alternative access  via index

lo_el_nd_exc_item = lo_nd_nd_exc_item->get_element( index = 1 ).

* get all declared attributes

  lo_el_nd_exc_item->get_static_attributes(

    IMPORTING

      static_attributes = ls_nd_exc_item ).

data:  i type i.

data: it_tab type table of wd_this->element_nd_exc_item,

      wa_tab type  wd_this->element_nd_exc_item .

*     lo_el_nd_exc_item->GET_INDEX( i1 ).

lo_nd_nd_exc_item->get_static_attributes_table(

    IMPORTING

     table = it_tab ).

delete it_tab WHERE charg eq ls_nd_exc_item-charg.

lo_nd_nd_exc_item->bind_table( it_tab ).

READ TABLE it_tab INTO wa_tab INDEX i.

delete from ZTT_FQM_EXC_REQ where EXCEP_ID = wa_tab-EXCEP_ID.

endmethod.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You simply manipulate the bound context. You use the context APIs to add an element or delete an element. IF_WD_CONTENT_NODE methods BIND_ELEMENT and REMOVE_ELEMENT.