1.类定义 CLASS lcl_event_handler DEFINITION. PUBLIC SECTION. METHODS: handle_data_changed_finished FOR EVENT data_changed_finished OF cl_gui_alv_grid IMPORTING e_modified et_good_cells, handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object e_interactive. ENDCLASS. "lcl_event_handler DEFINITION DATA gs_toolbar TYPE stb_button. *----------------------------------------------------------------------* * CLASS lcl_event_handler IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS lcl_event_handler IMPLEMENTATION. METHOD handle_data_changed_finished. PERFORM f_data_changed_finished USING e_modified et_good_cells. ENDMETHOD. "handle_data_changed_finished METHOD handle_toolbar. ENDMETHOD. ENDCLASS. 2。data_changed_finished 所响应的事件 FORM f_data_changed_finished USING p_modified TYPE char1 pt_good_cells TYPE lvc_t_modi. DATA: w_ih_modi TYPE lvc_s_modi, w_ih_output TYPE typ_output. DATA: w_pernr TYPE zwmt036-pernr, w_zwmt036 TYPE zwmt036, w_zwmt035 TYPE zwmt035, w_zwmt126 TYPE zwmt126, w_t300t TYPE t300t, w_t30at TYPE t30at. CHECK pt_good_cells IS NOT INITIAL. CALL METHOD g_grid_9021->check_changed_data * IMPORTING * e_valid = * CHANGING * c_refresh = 'X' . CLEAR flg_error. LOOP AT pt_good_cells INTO w_ih_modi. CLEAR w_ih_output. READ TABLE g_it_output_show INTO w_ih_output INDEX w_ih_modi-row_id. CASE w_ih_modi-fieldname. WHEN 'PERNR'. IF w_ih_modi-value IS INITIAL. IF w_ih_output-perna IS NOT INITIAL. CLEAR w_ih_output-perna. MODIFY g_it_output_show[] FROM w_ih_output INDEX w_ih_modi-row_id. ENDIF. ELSE. CLEAR: w_pernr,w_zwmt036. SELECT SINGLE * FROM zwmt036 INTO w_zwmt036 WHERE pernr = w_ih_modi-value. IF sy-subrc IS INITIAL. w_ih_output-perna = w_zwmt036-perna. w_ih_output-werks = w_zwmt036-werks. w_ih_output-lgnum = w_zwmt036-lgnum. w_ih_output-kqbsf = w_zwmt036-kqbsf. w_ih_output-kqtxt = w_zwmt036-kqtxt. IF w_ih_output-werks NE p_werks. flg_error = '1'. ENDIF. CLEAR w_t300t. SELECT SINGLE * FROM t300t INTO w_t300t WHERE spras = '1' AND lgnum = w_zwmt036-lgnum. w_ih_output-lnumt = w_t300t-lnumt. MODIFY g_it_output_show[] FROM w_ih_output INDEX w_ih_modi-row_id. ELSE. flg_error = '2'. ENDIF. ENDIF. ENDCASE. ENDLOOP. CALL METHOD g_grid_9021->refresh_table_display * EXPORTING * is_stable = * i_soft_refresh = EXCEPTIONS finished = 1 OTHERS = 2 . IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. 3.注册事件 这一步放在,pbo创建alv的时候。 CREATE OBJECT gcl_event_handler. SET HANDLER gcl_event_handler->handle_data_changed_finished FOR g_grid_9021. CALL METHOD g_grid_9021->register_edit_event EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified EXCEPTIONS error = 1 OTHERS = 2. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.