SAP ALV报表中设置回车事件
ALV报表中,可编辑列输入数据后,回车,后台做相应的数据处理后重新刷新报表显示,如果可编辑列为P类型,则需要在ALV报表中设置该列的类型,GS_FIELDCAT-DATATYPE = 'P'。
设置回车事件方式如下:
1.设置相关参数
DATA:STBL TYPE LVC_S_STBL, G_GRID TYPE REF TO CL_GUI_ALV_GRID. *** 定义ALV结构及布局 DATA: gt_fieldcat TYPE lvc_t_fcat, gs_fieldcat TYPE lvc_s_fcat, gs_layout TYPE lvc_s_layo, LT_EVENTS TYPE slis_t_event, LS_EVENTS TYPE slis_alv_event. " Alv grid.
2.定义事件所使用的类
*----------------------------------------------------------------------* * CLASS lcl_event_handler DEFINITION *----------------------------------------------------------------------* * 类定义 *----------------------------------------------------------------------* CLASS LCL_EVENT_HANDLER DEFINITION."类定义 PUBLIC SECTION. METHODS: HANDLE_DATA_CHANGED FOR EVENT DATA_CHANGED_FINISHED OF CL_GUI_ALV_GRID IMPORTING E_MODIFIED ET_GOOD_CELLS. ENDCLASS. "lcl_event_handler DEFINITION *----------------------------------------------------------------------* * CLASS lcl_event_handler IMPLEMENTATION *----------------------------------------------------------------------* * 类实现 *----------------------------------------------------------------------* CLASS LCL_EVENT_HANDLER IMPLEMENTATION."类实现 METHOD HANDLE_DATA_CHANGED. PERFORM HANDLE_DATA_CHANGED ."具体处理数据事件 IF E_MODIFIED = 'X'. STBL-ROW = 'X'." 基于行的稳定刷新 STBL-COL = 'X'." 基于列稳定刷新 CALL METHOD G_GRID->REFRESH_TABLE_DISPLAY EXPORTING IS_STABLE = STBL. ENDIF. ENDMETHOD. ENDCLASS. "lcl_event_handler IMPLEMENTATION
3.注册回车事件及具体处理数据FORM
*&---------------------------------------------------------------------* *& Form register_events *&---------------------------------------------------------------------* * 注册回车事件 *---------------------------------------------------------------------- FORM FRM_REGISTER_EVENTS USING E_GRID TYPE SLIS_DATA_CALLER_EXIT. CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' IMPORTING E_GRID = G_GRID. * DATA: GR_EVENT_HANDLER TYPE REF TO LCL_EVENT_HANDLER. CREATE OBJECT GR_EVENT_HANDLER. * CALL METHOD G_GRID->REGISTER_EDIT_EVENT EXPORTING I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER EXCEPTIONS ERROR = 1 OTHERS = 2. SET HANDLER GR_EVENT_HANDLER->HANDLE_DATA_CHANGED FOR G_GRID. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ENDFORM. "register_events FORM HANDLE_DATA_CHANGED . ....... ENDFORM.
4.ALV报表增加事件
***ALV布局 gs_layout-zebra = 'X'. gs_layout-cwidth_opt = 'X'. gs_layout-edit = ''. gs_layout-edit_mode = 'X'. gs_layout-sel_mode = 'A'. gs_layout-box_fname = 'BOX'. **增加ALV事件 LS_EVENTS-NAME = 'CALLER_EXIT'. LS_EVENTS-FORM = 'FRM_REGISTER_EVENTS'. APPEND LS_EVENTS TO LT_EVENTS. ***显示ALV CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING i_callback_program = sy-repid i_callback_pf_status_set = 'PF_STATUS_SET' "用户自定义GUI状态 i_callback_user_command = 'USER_COMMAND' "用户命令 is_layout_lvc = gs_layout it_fieldcat_lvc = gt_fieldcat IT_EVENTS = LT_EVENTS TABLES t_outtab = gt_data EXCEPTIONS program_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.