OO ALV 实现方式 ALV TABLE 之 标准工具栏
*&---------------------------------------------------------------------*
*& Report ZALV01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zalv01.
*变量定义
TYPES ty_spfli TYPE spfli OCCURS 0.
DATA: gr_table TYPE REF TO cl_salv_table.
*----------------------------------------------------------------------*
* CLASS lcl_handle_events DEFINITION
*----------------------------------------------------------------------*
* 事件处理类(定义)
*----------------------------------------------------------------------*
CLASS lcl_handle_events DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: on_user_command FOR EVENT added_function OF
cl_salv_events
IMPORTING e_salv_function.
ENDCLASS. "lcl_handle_events DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_handle_events IMPLEMENTATION
*----------------------------------------------------------------------*
* 事件处理类(实现)
*----------------------------------------------------------------------*
CLASS lcl_handle_events IMPLEMENTATION.
METHOD on_user_command.
DATA l_string TYPE string.
CONCATENATE 'Function is ' e_salv_function
INTO l_string
SEPARATED BY space.
MESSAGE i000(0k) WITH l_string.
ENDMETHOD. "on_user_command
ENDCLASS. "lcl_handle_events IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS lcl_alv DEFINITION
*----------------------------------------------------------------------*
* ALV操作类(定义)
*----------------------------------------------------------------------*
CLASS lcl_alv DEFINITION.
PUBLIC SECTION.
METHODS: getdata "取得要显示的数据
RETURNING value(lt_tab) TYPE ty_spfli,
alv_full "全屏Grid列表处理方法
IMPORTING value(lt_tab) TYPE ty_spfli,
main. "主方法
ENDCLASS. "lcl_alv DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_alv IMPLEMENTATION
*----------------------------------------------------------------------*
* ALV操作类(实现)
*----------------------------------------------------------------------*
CLASS lcl_alv IMPLEMENTATION.
*取得要显示的数据
METHOD getdata.
SELECT * INTO TABLE lt_tab FROM spfli.
ENDMETHOD. "getdata
*输出全屏网格列表的方法
METHOD alv_full.
DATA: lr_functions TYPE REF TO cl_salv_functions,
lr_events TYPE REF TO cl_salv_events.
"创建实例
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = lt_tab
).
CATCH cx_salv_msg.
ENDTRY.
lr_events = gr_table->get_event( ).
"设置ALV功能
gr_table->set_screen_status(
pfstatus = 'STA100'
report = sy-repid
set_functions = gr_table->c_functions_all ).
"注册事件
SET HANDLER lcl_handle_events=>on_user_command FOR lr_events.
"显示列表
gr_table->display( ).
ENDMETHOD. "alv_full
*主方法,整合数据
METHOD main.
DATA: lt_tab TYPE TABLE OF spfli.
"取得要显示的数据
lt_tab = me->getdata( ).
me->alv_full( lt_tab ).
ENDMETHOD. "main
ENDCLASS. "lcl_alv IMPLEMENTATION
*报表执行
START-OF-SELECTION.
DATA lr_alv TYPE REF TO lcl_alv.
CREATE OBJECT lr_alv.
lr_alv->main( ).