*&---------------------------------------------------------------------*
*& Report YGYTEST061
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT YGYTEST061.
*定义使用图标,按钮使用
INCLUDE .
*定义事件类型
CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED.
*功能码返回值
DATA:OK_CODE TYPE SY-UCOMM,
SAVE_OK LIKE OK_CODE.
*定义事件
DATA EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER.
*定义内表,变量需要传递,不加HEADER LINE.
DATA:WA_SPFLI TYPE TABLE OF SPFLI,
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 100.
*定义事件的属性和方法
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.
*PRIVATE SECTION.
ENDCLASS.
*实现方法
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.
*append an icon to show booking table
CLEAR LS_TOOLBAR.
*加入功能码
MOVE 'SHOW_DATA' 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.
*处理功能码事件
METHOD HANDLE_USER_COMMAND.
DATA:LT_ROWS TYPE LVC_T_ROW.
CASE E_UCOMM.
*定义的按钮事件
WHEN 'SHOW_DATA'.
*取得所有选择行
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 S005(YMESS) WITH '已选择行!'.
*调用子程序显示选择行内容
PERFORM MESSDETA TABLES LT_ROWS.
ENDIF.
ENDCASE.
ENDMETHOD.
ENDCLASS.
*用户交互
MODULE USER_COMMAND_0100 INPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
*退出按钮时退出程序
CASE SAVE_OK.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
*定义状态条,包括菜单、工具条按钮、系统按钮等
MODULE STATUS_0100 OUTPUT.
* SET PF-STATUS 'STATUS1'.
*如果窗口还没有创建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.
*显示选择内容模块
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(YMESS) WITH S1.
ENDLOOP.
ENDFORM.
阅读(2311) | 评论(0) | 转发(0) |