SAP在做报表开发中,不同公司对报表的风格往往各异,为此经常在使用OO方法做ALV报表中需要去掉自带的工具栏而自行添加一些工具按钮,下面将简单介绍一下添加按钮及如何响应的实现方法:
步骤一:创建一个事件处理类
CLASS lcl_event_receiver DEFINITION.
* public attributes and method
PUBLIC SECTION.
METHODS:
handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING
e_object,
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 toolbar handler
METHOD handle_toolbar.
PERFORM set_toolbar CHANGING e_object.
ENDMETHOD. "handle_toolbar
METHOD handle_user_command.
* Handle own functions defined in the toolbar
CASE e_ucomm.
WHEN 'ADD'.
PERFORM xyz. “这里你想干嘛就可以干嘛
ENDCASE.
ENDMETHOD. "handle_user_command
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
步骤三:在FORM-----set_toolbar 中添加button
FORM set_toolbar
CHANGING prf_object TYPE REF TO cl_alv_event_toolbar_set.
CLEAR prf_object->mt_toolbar.
CLEAR gs_toolbar.
MOVE 'ADD' TO gs_toolbar-function.
MOVE TO gs_toolbar-quickinfo.
MOVE TO gs_toolbar-text.
MOVE ' ' TO gs_toolbar-disabled.
INSERT gs_toolbar INTO prf_object->mt_toolbar INDEX 1.
ENDFORM. " set_toolbar1
步骤四:创建事件处理对象--这一步一般在
grf_grid->set_table_for_first_display 之后
SET HANDLER grf_event_receiver->handle_user_command FOR grf_grid.
SET HANDLER grf_event_receiver->handle_toolbar FOR grf_grid.
CALL METHOD grf_grid->set_toolbar_interactive.
注意:STB_BUTTON结构包含的字段
FUNCTION UI_FUNC CHAR 70 0 Function Code
ICON ICONNAME CHAR 30 0 Name of an Icon
QUICKINFO ICONQUICK CHAR 30 0 Quickinfo for an icon
BUTN_TYPE TB_BTYPE INT4 10 0 Toolbar button type
DISABLED CHAR 1 0 Disabled
TEXT TEXT40 CHAR 40 0 Text, 40 Characters Long
CHECKED CHAR 1 0 Printed
TB_BTYPE 的可选择值 ,主要用来决定按钮的类型
0 Button (normal)
1 Menu and default button
2 Menu
3 Separator
4 Radio button
5 Checkbox
6 Menu entry
阅读(5745) | 评论(0) | 转发(1) |