cancel
Showing results for 
Search instead for 
Did you mean: 

row deletion

Former Member
0 Kudos

HI all,

In my o/p i've created a button delete. if i delete the seleted row in a table it should get deleted.

but first record is getting deteled not the one which i've slected.

i'm using Lead screen check box for the selection.

Regards

Suprith

Accepted Solutions (1)

Accepted Solutions (1)

arjun_thakur
Active Contributor
0 Kudos

Hi,

Refer the solution provided by Uday in this thread:

Also refer this thread:

I hope it helps.

Regards

Arjun

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Suprith,

its actually fairly simple, all what you have to is:

1- read the context node

2- import the table which you stored your data in it.

3- get the lead selection

4- remove the selected row from your lcoal context

5- delete the row from your table

Here is what Im using in my WDA:

DATA lo_nd_test TYPE REF TO if_wd_context_node.

DATA lo_el_test TYPE REF TO if_wd_context_element.

DATA ls_test TYPE wd_this->element_test.

DATA wd_node TYPE REF TO if_wd_context_node.

DATA lr_element TYPE REF TO if_wd_context_element.

DATA lt_test TYPE wd_this->elements_test.

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

lo_nd_test = wd_context->get_child_node( name = wd_this->wdctx_test ).

lo_el_test= lo_nd_test->get_element( ).

lo_el_test->get_static_attributes(

IMPORTING

static_attributes = ls_test ).

  • import table

lo_nd_test= wd_context->get_child_node( name = wd_this->wdctx_test ).

CHECK NOT lo_nd_test IS INITIAL.

CALL METHOD lo_nd_test->get_static_attributes_table

IMPORTING

table = lt_test.

  • Get access to the desired context node

wd_node = wd_context->get_child_node( name = 'TEST' ).

  • Get the lead selection of the ALV

lr_element = wd_node->get_lead_selection( ).

  • Remove the element obtained through lead selection

wd_node->remove_element( EXPORTING element = lr_element ).

  • DELETE RECORD FROM THE TABLE

DELETE FROM ztest

where first_name = ls_test-first_name.

I hope this would solve your problem.

Regards,

Abdul

Former Member
0 Kudos

Please chk my code and suggest me... i'm not getting the row which i selected.

only first record is getting deleted

method ONACTIONA_DELETE_ROW .

  • wd_this->delete_pop_up( ).

DATA lo_nd_n_material TYPE REF TO if_wd_context_node.

DATA lo_el_n_material TYPE REF TO if_wd_context_element.

data elem_part type ref to if_wd_context_element.

DATA ls_n_material TYPE wd_this->element_n_material.

DATA item_no TYPE zmatreq-zitem.

DATA lt_n_material TYPE wd_this->elements_n_material.

data line_index type i.

data line_index_str type string.

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

lo_nd_n_material = wd_context->get_child_node( name = wd_this->wdctx_n_material ).

*data: lt_temp TYPE wdr_context_element_set,

  • row_number TYPE i VALUE 0.

  • get element via lead selection

lo_el_n_material = lo_nd_n_material->get_element( ).

IF lo_el_n_material IS INITIAL.

ENDIF.

CALL METHOD lo_el_n_material->get_static_attributes

IMPORTING

static_attributes = ls_n_material

.

*CALL METHOD lo_nd_n_material->get_selected_elements

  • RECEIVING

  • set = lt_temp.

*call method elem_part->get_index

*receiving

*my_index = line_index.

  • get all declared attributes

lo_nd_n_material->get_static_attributes_table(

EXPORTING

from = 1

to = 2147483647

importing

table = lt_n_material ).

loop at lt_n_material into ls_n_material.

if ls_n_material-a_req_type eq space or ls_n_material-a_matgrp eq space

or ls_n_material-a_dev_centre eq space.

*delete lt_n_material index line_index.

item_no = ls_n_material-itemno.

DELETE TABLE lt_n_material from ls_n_material.

exit.

endif.

endloop.

lo_nd_n_material->bind_table( lt_n_material ).

                    • Deleting a empty line from the node

*CALL METHOD lo_nd_n_material->get_lead_selection

  • receiving

  • element = lt_n_material

  • .

endmethod.

arjun_thakur
Active Contributor
0 Kudos

Hi Suprith,

Instead of re-binding the node, you should use the remove_element( ) method. It is performance wise more efficient. You can see the code given by Thomas for the same in this thread: . This will resolve your problem. If you still want to use the code which you are already using then use the get_selected_elements( ) method to get the selected row.

I hope it helps.

Regards

Arjun

Former Member
0 Kudos

Hi,

Refer this code :

data node type ref to if_wd_context_node.

data elem_part type ref to if_wd_context_element.

data table_data type if_tab_second=>elements_part_func.

data table_line type if_tab_second=>element_part_func.

data line_index type i.

data line_index_str type string.

node = wd_context->get_child_node( 'PART_FUNC' ).

elem_part = node->get_element( ).

if ( elem_part is initial ).

exit.

endif.

call method elem_part->get_index

receiving

my_index = line_index.

  • Delete selected record

call method node->get_static_attributes_table

importing

table = table_data.

delete table_data index line_index.

node->bind_table(

new_items = table_data

set_initial_elements = abap_true ).

i hope this will help you.

Thanx.

Former Member
0 Kudos

This message was moderated.