OO ALV 实现方式 ALV TABLE 之factory
*&---------------------------------------------------------------------*
*& Report ZALV01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zalv01.
*变量定义
TYPES ty_spfli TYPE spfli OCCURS 0.
*----------------------------------------------------------------------*
* CLASS lcl_alv DEFINITION
*----------------------------------------------------------------------*
* ALV操作类(定义)
*----------------------------------------------------------------------*
CLASS lcl_alv DEFINITION.
PUBLIC SECTION.
METHODS: getdata "取得要显示的数据
RETURNING value(lt_tab) TYPE ty_spfli,
alv_process "ALV处理方法
IMPORTING value(lt_tab) TYPE ty_spfli,
main. "主方法
PRIVATE SECTION.
DATA gr_table TYPE REF TO cl_salv_table.
ENDCLASS. "lcl_alv DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_alv IMPLEMENTATION
*----------------------------------------------------------------------*
* ALV操作类(实现)
*----------------------------------------------------------------------*
CLASS lcl_alv IMPLEMENTATION.
*取得要显示的数据
METHOD getdata.
SELECT * INTO TABLE lt_tab FROM spfli.
ENDMETHOD. "getdata
*ALV处理方法
METHOD alv_process.
"创建实例
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = lt_tab
).
CATCH cx_salv_msg.
ENDTRY.
"显示列表
gr_table->display( ).
ENDMETHOD. "alv_process
*主方法,整合数据
METHOD main.
DATA: lt_tab TYPE TABLE OF spfli.
"取得要显示的数据
lt_tab = me->getdata( ).
"处理数据
me->alv_process( 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( ).