一个Function的alv demo,使用键盘上的delete直接删除表数据,可以多行删除。
效果:
选中后点键盘上的delete
具体删除的什么,可以根据
er_data_changed ->mt_deleted_rows 里面的数据确定,里面有行号
此时 alv内表内数据没删除,直接根据行号即可得到删除的数据,如果有后续操作可以记录下来
code:
*&---------------------------------------------------------------------*
*& Report ZLM_ALV_013
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zlm_alv_014 .
TYPE-POOLS : slis .
* Data to be displayed
DATA : gt_sflight TYPE TABLE OF sflight .
DATA : gt_sflight1 TYPE TABLE OF sflight ,
gs_layout TYPE slis_layout_alv ,
l_deleted TYPE flag .
DATA : gv_delte_number TYPE int4 .
DATA : gs_delete TYPE sflight .
DATA : o_grid TYPE REF TO cl_gui_alv_grid .
*
*----------------------------------------------------------------------*
* Event Handler class for ALV Events
*----------------------------------------------------------------------*
CLASS lcl_event_handle DEFINITION .
PUBLIC SECTION .
METHODS handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed .
*
METHODS :
handle_changed_finished FOR EVENT data_changed_finished
OF cl_gui_alv_grid
IMPORTING e_modified
et_good_cells .
*
ENDCLASS . "lcl_event_handle DEFINITION
*
DATA : o_event_h TYPE REF TO lcl_event_handle .
*
START-OF-SELECTION .
*---------------------------------------------------------------------*
* Selection
SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE gt_sflight UP TO 10 ROWS .
*
* Edit
gs_layout - edit = 'X' .
*
* Event for Top-of-page
DATA : lt_events TYPE slis_t_event .
DATA : la_events LIKE LINE OF lt_events .
*
la_events -name = 'TOP_OF_PAGE' .
la_events - form = 'TOP_OF_PAGE' .
APPEND la_events TO lt_events .
*
* Call ABAP List Viewer (ALV)
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy -repid
i_callback_user_command = 'USER_COMMAND'
i_structure_name = 'SFLIGHT'
is_layout = gs_layout
it_events = lt_events
TABLES
t_outtab
*& Report ZLM_ALV_013
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zlm_alv_014 .
TYPE-POOLS : slis .
* Data to be displayed
DATA : gt_sflight TYPE TABLE OF sflight .
DATA : gt_sflight1 TYPE TABLE OF sflight ,
gs_layout TYPE slis_layout_alv ,
l_deleted TYPE flag .
DATA : gv_delte_number TYPE int4 .
DATA : gs_delete TYPE sflight .
DATA : o_grid TYPE REF TO cl_gui_alv_grid .
*
*----------------------------------------------------------------------*
* Event Handler class for ALV Events
*----------------------------------------------------------------------*
CLASS lcl_event_handle DEFINITION .
PUBLIC SECTION .
METHODS handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed .
*
METHODS :
handle_changed_finished FOR EVENT data_changed_finished
OF cl_gui_alv_grid
IMPORTING e_modified
et_good_cells .
*
ENDCLASS . "lcl_event_handle DEFINITION
*
DATA : o_event_h TYPE REF TO lcl_event_handle .
*
START-OF-SELECTION .
*---------------------------------------------------------------------*
* Selection
SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE gt_sflight UP TO 10 ROWS .
*
* Edit
gs_layout - edit = 'X' .
*
* Event for Top-of-page
DATA : lt_events TYPE slis_t_event .
DATA : la_events LIKE LINE OF lt_events .
*
la_events -name = 'TOP_OF_PAGE' .
la_events - form = 'TOP_OF_PAGE' .
APPEND la_events TO lt_events .
*
* Call ABAP List Viewer (ALV)
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy -repid
i_callback_user_command = 'USER_COMMAND'
i_structure_name = 'SFLIGHT'
is_layout = gs_layout
it_events = lt_events
TABLES
t_outtab