cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete a particular row in ALV table

Former Member
0 Kudos

Hi,

How to delete a particular row in ALV table based on some condition(by checking value for one of the columns in a row)

Thanks

Bala Duvvuri

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Hello Bala,

Can you please be a bit more clear as to how you intend to delete the rows from your ALV? By the way deleting rows from an ALV is no different from deleting rows from a normal table. Suppose you have enabled selection property in ALV & then select multiple rows and click up on a button to delete the rows then below would be the coding: (Also keep in mind that you would have to maintain the Selection property of the context node that you are binding to your ALV to 0..n)

data : lr_table_settings  TYPE REF TO if_salv_wd_table_settings,
             lr_config          TYPE REF TO cl_salv_wd_config_table.

  lr_table_settings  ?= lr_config.

** Setting the ALV selection to multiple selection with no lead selection
  lr_table_settings->set_selection_mode( value = cl_wd_table=>e_selection_mode-multi_no_lead ).

Next delete the selected rows in the action triggered by the button:

METHOD onactiondelete_rows .
  DATA:  wd_node TYPE REF TO if_wd_context_node,
         lt_node1 TYPE ig_componentcontroller=>elements_node,
         wa_temp  TYPE REF TO if_wd_context_element,
         lt_temp  TYPE wdr_context_element_set,
         row_number TYPE i VALUE 0.


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

  CALL METHOD wd_node->get_selected_elements
    RECEIVING
      set = lt_temp.

  LOOP AT lt_temp INTO wa_temp.
    wd_node->remove_element( EXPORTING element = wa_temp ).
  ENDLOOP.

  CALL METHOD wd_node->get_static_attributes_table
    EXPORTING
      from  = 1
      to    = 2147483647
    IMPORTING
      table = lt_node1.

  wd_node->bind_table( new_items = lt_node1 ).
ENDMETHOD.

If in case this isn't your requirement please do let me know so that I can try come up with another analysis.

Regards,

Uday

Former Member
0 Kudos

Hi Uday,

Thanks for the reply.

let me explain the scenario

When i click on search button i will get results

My Results list looks like this

Ename Corp Band

1 A

2 B

3 A

From the above result set i want to delete the rows where Corp Band is A and display the result list with remaining rows

Hope my explanation is clear now

Thanks

Bala Duvvuri

Former Member
0 Kudos

Try this code.

CALL METHOD wd_node->get_static_attributes_table
    IMPORTING
      table = lt_node.


  LOOP AT lt_node INTO wa_node where ename = 'A'. " Your condition
    wd_node->remove_element( EXPORTING element = wa_temp ).
  ENDLOOP.

 
  wd_node->bind_table( new_items = lt_node ).

Hope it works.

uday_gubbala2
Active Contributor
0 Kudos

Hi Bala,

If its always going to be automatic deletion of rows which come up with a value 'A' in the Corp Band then you needn't even go this far as how 'WD ABAP' was suggesting. Once you get your search results into your internal table. Just delete the rows which satisfy that criteria using the normal DELETE keyword. Then finally bind the desired correct entries to your context node. So this way you would be filling your table with correct values at the outset itself. You dont need to fill it with invalid values, then read the entire context & delete the invalid values & re-bind them to the context node.

Regards,

Uday

Former Member
0 Kudos

Hi,

Thanks for the replies .

I found out the way of not attaching the unwanted rows to the context based on the condition .

so my problem is solved

Thanks

Bala Duvvuri

Answers (0)