*激发双击事件 FORM f_alv_user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield. "先引用类型池 TYPE-POOLS: slis CASE r_ucomm. WHEN '&IC1'. PERFORM double_click USING rs_selfield-tabindex "双击显示明细 rs_selfield-fieldname . ENDCASE. FORM double_click USING p_tabindex "双击行号 p_fieldname. "双击列名 DATA:l_bewtp TYPE ekbe-bewtp. READ TABLE gt_output INTO wa_output INDEX p_tabindex. CHECK sy-subrc = 0. REFRESH:gt_ekbe_alv. IF p_fieldname = 'TOTAL'. l_bewtp = 'E'. ELSEIF p_fieldname = 'FP_TOTAL'. l_bewtp = 'Q'. ELSEIF p_fieldname = 'EBELN'. SET PARAMETER ID 'BES' FIELD wa_output-ebeln. "调用ME23N界面,详细可见CALL TRANSACTION小节一文 SET PARAMETER ID 'BSP' FIELD wa_output-ebelp. CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN. ELSE. EXIT. ENDIF. LOOP AT gt_ekbe INTO wa_ekbe WHERE ebeln = wa_output-ebeln AND ebelp = wa_output-ebelp AND bewtp = l_bewtp. APPEND wa_ekbe TO gt_ekbe_alv. ENDLOOP. IF gt_ekbe_alv IS INITIAL.. MESSAGE s398(00) WITH '无数据' . EXIT. ENDIF. g_fieldname = p_fieldname. CALL SCREEN 200. ENDFORM. *自定义工具栏,如果没有自定义的按钮不需要设置,系统会有标准的工具栏,如果设置了自定义工具栏,会替代标准工具栏, *系统标准ALV工具栏可以通过函数的REUSE_ALV_GRID_DISPLAY_LVC找到函数组SLVC_FULLSCREEN,在函数组下面的GUI状态名: *SAPLSLVC_FULLSCREEN就是标准的ALV工具栏,可以以拷贝使用。 FORM f_set_alv_status_00 USING i_extab TYPE slis_t_extab. SET PF-STATUS 'GUISTATUS_00'. ENDFORM. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING i_callback_program = sy-repid i_callback_pf_status_set = 'F_SET_ALV_STATUS_00' i_callback_user_command = 'F_ALV_USER_COMMAND' is_layout_lvc = gs_layout it_fieldcat_lvc = gt_field i_save = 'A' TABLES t_outtab = gt_output EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING. "ALV执行失败退回到选择界面 ENDIF.
.以上是函数模式的ALV和热点,下面介绍OO方式的
*---------------------------------------------------------------------* * CLASS 参数定义 *---------------------------------------------------------------------* CLASS lcl_alv_receiver DEFINITION DEFERRED. "预定义本地类 DATA: g_alv_application TYPE REF TO lcl_alv_receiver. "按钮处理 *----------------------------------------------------------------------* * CLASS lcl_alv_receiver DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS lcl_alv_receiver DEFINITION. "定义本地类 PUBLIC SECTION. METHODS: handle_double "执行双击事件 FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row e_column es_row_no. ENDCLASS. "lcl_event_receiver DEFINITION *----------------------------------------------------------------------* * CLASS lcl_alv_receiver IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS lcl_alv_receiver IMPLEMENTATION. METHOD handle_double . "双击事方法件的实现 PERFORM set_double_click_class USING e_row e_column. ENDMETHOD. "HANDLE_double ENDCLASS. "lcl_event_receiver IMPLEMENTATION FORM set_double_click_class USING p_row TYPE lvc_s_row p_column TYPE lvc_s_col. CHECK g_fieldname = 'TOTAL'. READ TABLE gt_ekbe_alv INTO wa_ekbe INDEX p_row-index. CHECK sy-subrc = 0. IF p_column-fieldname = 'BELNR'. SET PARAMETER ID 'MBN' FIELD wa_ekbe-belnr. SET PARAMETER ID 'MJA' FIELD wa_ekbe-gjahr. CALL TRANSACTION 'MB03' AND SKIP FIRST SCREEN. ELSEIF p_column-fieldname = 'EBELN'. SET PARAMETER ID 'BES' FIELD wa_ekbe-ebeln. SET PARAMETER ID 'BSP' FIELD wa_ekbe-ebelp. CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN. ENDIF. ENDFORM. DATA: g_grid TYPE REF TO cl_gui_alv_grid. "ALV类 DATA:g_custom_container TYPE REF TO cl_gui_custom_container, g_container TYPE scrfname VALUE 'CONTAINER', "界面绘制的ALV容器名称 'CONTAINER' gt_exclude TYPE ui_functions. "存放ALV排除工具栏功能按钮的内表 CREATE OBJECT g_custom_container EXPORTING container_name = g_container. "界面绘制的ALV容器名称 'CONTAINER' CREATE OBJECT g_grid EXPORTING i_parent = g_custom_container. 初始化ALV类 ***去除不需要的按钮 PERFORM exclude_tb_functions CHANGING gt_exclude. ***显示ALV PERFORM screen_alv. CREATE OBJECT g_alv_application. SET HANDLER g_alv_application->handle_double FOR g_grid. FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions. DATA ls_exclude TYPE ui_func. ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row. APPEND ls_exclude TO pt_exclude. ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row. APPEND ls_exclude TO pt_exclude. ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row. APPEND ls_exclude TO pt_exclude. ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row. APPEND ls_exclude TO pt_exclude. ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row. APPEND ls_exclude TO pt_exclude. ENDFORM. FORM screen_alv . gs_variant-report = sy-repid. CALL METHOD g_grid->set_table_for_first_display EXPORTING it_toolbar_excluding = gt_exclude is_layout = gs_layout is_variant = gs_variant i_save = 'A' CHANGING it_fieldcatalog = gt_fieldcat it_outtab = gt_ekbe_alv. ENDFORM.