1

I have ALV table and I made a custom button in the table toolbar. Whenever the button is pressed, I want to delete the selected row. Now there's just a message showing up so I could see if the custom button is working.

METHOD on_user_command.
CASE e_salv_function.
  WHEN 'MYFUNC1'.
    MESSAGE i301(z_global) WITH 'Function 1'.
    *Right here the row should be deleted.


  WHEN 'MYFUNC2'.
    MESSAGE i301(z_global) WITH 'Function 2'.
  WHEN OTHERS.
ENDCASE.
ENDMETHOD.
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Kevin Mueller
  • 628
  • 3
  • 10
  • 23
  • 3
    You haven't mentioned, which ALV technology you use, so I assume you use one of the OO ones :) First you have to identyify which line is selected, you can use method GET_SELECTED_ROWS for that. If you have it, you can identify the selected row and remove it from the internal table. After that you have to use method REFRESH, so the line is also removed from the display. – József Szikszai Feb 07 '18 at 15:44

1 Answers1

0

Here is the sample code for deleting selected row:

CASE e_salv_function.
 WHEN 'MYFUNC1'.
  PERFORM delete_lines.
  ...
 ENDCASE.   

form delete_lines.
  data: sav_tabix type lvc_index.
  clear row_table.
  call method grid1->get_selected_rows( et_index_rows = data(row_table) ).

      loop at gt_outtab.
        sav_tabix = sav_tabix + 1.
        read table row_table with key index = sav_tabix.
        if sy-subrc = 0.
          delete gt_outtab INDEX sav_tabix.
        endif.
      endloop.

  call method grid1->refresh_table_display.
  call method cl_gui_cfw=>flush.
endform.    
Suncatcher
  • 10,355
  • 10
  • 52
  • 90