0
点赞
收藏
分享

微信扫一扫

Classical ALV Demo:&nb…

曾宝月 2022-06-17 阅读 41

一个Function的alv demo,使用键盘上的delete直接删除表数据,可以多行删除。

效果: ​Classical <wbr>ALV <wbr>Demo: <wbr>Disable <wbr>DELETE <wbr>key <wbr>on <wbr>Keyboard


选中后点键盘上的delete


Classical <wbr>ALV <wbr>Demo: <wbr>Disable <wbr>DELETE <wbr>key <wbr>on <wbr>Keyboard



具体删除的什么,可以根据

er_data_changed ->mt_deleted_rows    里面的数据确定,里面有行号 此时 alv内表内数据没删除,直接根据行号即可得到删除的数据,如果有后续操作可以记录下来

Classical <wbr>ALV <wbr>Demo: <wbr>Disable <wbr>DELETE <wbr>key <wbr>on <wbr>Keyboard



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                                = gt_sflight .


*


*&---------------------------------------------------------------------*


*      TOP-OF-PAGE. Also used to get the Object reference


*----------------------------------------------------------------------*


FORM top_of_page .


*

 

  DATA  : lt_comment  TYPE slis_t_listheader ,

 

                la_comment  TYPE slis_listheader .


*


* Top of page

 

  la_comment -typ    =  'H' .

 

  la_comment -info  =  'Disabled Delete Key' .

 

  APPEND la_comment  TO lt_comment .


*


* Commenty write

 

  CALL  FUNCTION  'REUSE_ALV_COMMENTARY_WRITE'

 

      EXPORTING

 

          it_list_commentary  = lt_comment .


*


* Get the ALV object

 

  CALL  FUNCTION  'GET_GLOBALS_FROM_SLVC_FULLSCR'

 

      IMPORTING

 

          e_grid  = o_grid .


*


* Register the Modified event ... Important

 

  CALL  METHOD o_grid ->register_edit_event

 

      EXPORTING

 

          i_event_id  = cl_gui_alv_grid =>mc_evt_modified .


*


* Set Event handler

 

  CREATE OBJECT  o_event_h .

 

  SET  HANDLER o_event_h ->handle_data_changed  FOR o_grid .

 

  SET  HANDLER o_event_h ->handle_changed_finished  FOR o_grid .


*


ENDFORM .                     "top_of_page


*


*&---------------------------------------------------------------------*


*       User Command


*----------------------------------------------------------------------*


FORM user_command  USING r_ucomm  TYPE sy -ucomm

 

                                              rs_selfield  TYPE slis_selfield .

 

  IF r_ucomm  =  '&DATA_SAVE' .

 

      MESSAGE  'You pressed the save button'  TYPE  'I' .

 

  ENDIF .


ENDFORM .                     "user_command


*


*----------------------------------------------------------------------*


* Event Handler Class implementation


*----------------------------------------------------------------------*


CLASS lcl_event_handle  IMPLEMENTATION .


*

 

  METHOD handle_data_changed .


*


*

 

      DATA : ls_deleted_rows  LIKE  LINE  OF er_data_changed ->mt_deleted_rows .


*


*   data is deleted or not. If yes, than fill the temporary table


*     to its copy

 

      DESCRIBE  TABLE er_data_changed ->mt_deleted_rows  LINES sy - index . "Gv_DELTE_NUMBER

 

      IF sy - index  IS  NOT  INITIAL .

 

          l_deleted  =  'X' .

 

          gv_delte_number  = sy - index .


*      gt_sflight1[] = gt_sflight[].


*      CLEAR er_data_changed->mt_deleted_rows.

 

      ENDIF .



*


*

 

  ENDMETHOD .                     "handle_data_changed


*

 

  METHOD  handle_changed_finished .


*


*   data has been deleted than set the temp data back to the main table


*   and refresh the table display

 

      IF l_deleted  =  'X' .


 

          MESSAGE  'YOU DELETE ' &&  '(' &&  gv_delte_number  &&  ')' &&  'LINES'  TYPE  'S' .


*      gt_sflight[] = gt_sflight1[].


*      CLEAR: l_deleted, gt_sflight1.

 

      ENDIF .


*   message


*    MESSAGE 'You can not delete any record' TYPE 'I'.


*   refresh the list display

 

      CALL  METHOD o_grid ->refresh_table_display

 

          EXCEPTIONS

 

              finished  =  1

 

              OTHERS    =  2 .

 

      IF sy -subrc  NE  0 .

 

          MESSAGE  ID sy -msgid  TYPE sy -msgty  NUMBER sy -msgno

 

                                WITH sy -msgv1  sy -msgv2  sy -msgv3  sy -msgv4 .

 

      ENDIF .


*

 

  ENDMETHOD .                     "handle_changed_finished


*


ENDCLASS .                     "lcl_event_handle IMPLEMENTATION



举报

相关推荐

0 条评论