*&---------------------------------------------------------------------**& Report YTEST028*&*&---------------------------------------------------------------------**&*&*&---------------------------------------------------------------------*REPORT ytest028.*定义使用图标,按钮使用INCLUDE.*定义事件类型CLASS lcl_event_receiver DEFINITION DEFERRED.*功能码返回值DATA: ok_code TYPE sy-ucomm, save_ok TYPE sy-ucomm.*定义事件DATA event_receiver TYPE REF TO lcl_event_receiver.*定义内表,变量需要传递,不加header lineDATA: wa_spfli TYPE TABLE OF spfli ,"WITH HEADER LINE. a_spfli LIKE spfli.*内表赋值SELECT * INTO TABLE wa_spfli FROM spfli.*定义窗口定制控制,定义ALV对象DATA: wa_container TYPE scrfname VALUE 'ALVDATA', alv_grid TYPE REF TO cl_gui_alv_grid, wa_custom_container TYPE REF TO cl_gui_custom_container.*直接调用窗口CALL SCREEN 300.*定义是件的属性和方法CLASS lcl_event_receiver DEFINITION.*公共事件 PUBLIC SECTION. METHODS:*按钮处理方法 handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object e_interactive,*用户交互是件处理 handle_user_command FOR EVENT user_command OF cl_gui_alv_grid IMPORTING e_ucomm.ENDCLASS. "lcl_event_receiver DEFINITION*实现方法CLASS lcl_event_receiver IMPLEMENTATION .*处理按钮事件 METHOD handle_toolbar. DATA:ls_toolbar TYPE stb_button. CLEAR ls_toolbar. MOVE 3 TO ls_toolbar-butn_type.*取工具条接口 APPEND ls_toolbar TO e_object->mt_toolbar. CLEAR ls_toolbar.*加入功能码 MOVE ' SHOW_DETA' TO ls_toolbar-function.*图标,可以用SHOWICON系统程序查阅需使用的图标 MOVE icon_ppe_vnode TO ls_toolbar-icon.*按钮文本和提示 MOVE '航班明细显示' TO ls_toolbar-quickinfo. MOVE '航班明细显示'(112) TO ls_toolbar-text. MOVE '' TO ls_toolbar-disabled. APPEND ls_toolbar TO e_object->mt_toolbar. ENDMETHOD. "handle_toolbar*处理功能码事件 METHOD handle_user_command. DATA:lt_rows TYPE lvc_t_row. CASE e_ucomm.*定义的按钮事件 WHEN 'SHOW_DETA'.*取得所有选择 CALL METHOD alv_grid->get_selected_rows IMPORTING et_index_rows = lt_rows. CALL METHOD cl_gui_cfw=>flush. IF sy-subrc EQ 0.*提示成功 MESSAGE '已选择行' TYPE 'S'.*调用子程序显示选择行内容 PERFORM messdeta TABLES lt_rows. ENDIF. ENDCASE. ENDMETHOD. "handle_user_commandENDCLASS. "clc_event_receiver IMPLEMENTATION*&---------------------------------------------------------------------**& Module STATUS_0300 OUTPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------**用户交互MODULE status_0300 OUTPUT. SET PF-STATUS 'STATUS1'.* SET TITLEBAR 'xxx'.*如果窗口还没有创建ALV对象则它 IF wa_custom_container IS INITIAL. CREATE OBJECT wa_custom_container EXPORTING container_name = wa_container. CREATE OBJECT alv_grid EXPORTING i_parent = wa_custom_container. CALL METHOD alv_grid->set_table_for_first_display EXPORTING i_structure_name = 'SPFLI' CHANGING it_outtab = wa_spfli.*创建事件 CREATE OBJECT event_receiver.*将用户交互事件分配ALV SET HANDLER event_receiver->handle_user_command FOR alv_grid.*将按钮相关事件分配ALV SET HANDLER event_receiver->handle_toolbar FOR alv_grid.*调用处理工具条处理方法,使自定义工具条生效 CALL METHOD alv_grid->set_toolbar_interactive. ENDIF.ENDMODULE. " STATUS_0300 OUTPUT*显示选择行内容模块FORM messdeta TABLES p_et_index_rows STRUCTURE lvc_s_row.*定义选择行 DATA:ls_selected_line LIKE lvc_s_row, lf_row_index TYPE lvc_index.*定义合并字段及分隔字段 DATA:s1(200) TYPE c, s2(3) TYPE c. s2 = '-'.*读取所有选择行 LOOP AT p_et_index_rows INTO ls_selected_line. lf_row_index = ls_selected_line-index.*从内表中按序号读取内容 READ TABLE wa_spfli INDEX lf_row_index INTO a_spfli.*合并 s1 = '选择行内容'. CONCATENATE s1 a_spfli-connid a_spfli-carrid a_spfli-cityfrom INTO s1 SEPARATED BY s2.*弹出窗口提示 MESSAGE i005(ymes) WITH s1. ENDLOOP.ENDFORM. "messdeta*&---------------------------------------------------------------------**& Module EXIT INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE exit INPUT. save_ok = ok_code. CLEAR ok_code. CASE save_ok. WHEN 'EXIT'. LEAVE PROGRAM. ENDCASE.ENDMODULE. " EXIT INPUT*&---------------------------------------------------------------------**& Module USER_COMMAND_0300 INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE user_command_0300 INPUT.ENDMODULE. " USER_COMMAND_0300 INPUT
效果: