OO ALV 实现方式 ALV TABLE 之 三合一
*&---------------------------------------------------------------------*
*& Report ZALV01
*& alv的三种形式
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zalv01.
*变量定义
TYPES ty_spfli TYPE spfli OCCURS 0.
DATA: gr_table TYPE REF TO cl_salv_table.
*选择屏幕设计
SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME.
PARAMETERS: p_full RADIOBUTTON GROUP rg,
p_list RADIOBUTTON GROUP rg,
p_grid RADIOBUTTON GROUP rg.
SELECTION-SCREEN END OF BLOCK blk.
*----------------------------------------------------------------------*
* 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,
alv_list "普通List处理方法
IMPORTING value(lt_tab) TYPE ty_spfli,
alv_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.
"创建实例
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_full
*输出全屏普通列表的方法
METHOD alv_list.
"创建实例
TRY.
cl_salv_table=>factory(
EXPORTING
list_display = 'X'
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = lt_tab
).
CATCH cx_salv_msg.
ENDTRY.
"显示列表
gr_table->display( ).
ENDMETHOD. "alv_list
*输出在自定义屏幕上的列表
METHOD alv_grid.
CALL SCREEN '0100'.
ENDMETHOD. "alv_grid
*主方法,整合数据
METHOD main.
DATA: lt_tab TYPE TABLE OF spfli.
"取得要显示的数据
lt_tab = me->getdata( ).
"判断选择屏幕的选择条件调用不同的方法
CASE 'X'.
WHEN p_full.
me->alv_full( lt_tab ).
WHEN p_list.
me->alv_list( lt_tab ).
WHEN p_grid.
me->alv_grid( lt_tab ).
ENDCASE.
ENDMETHOD. "main
ENDCLASS. "lcl_alv IMPLEMENTATION
*----------------------------------------------------------------------*
* MODULE status_0100
*----------------------------------------------------------------------*
* PBO 屏幕输出前执行
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
"定义变量
SET PF-STATUS 'STA100'.
DATA: lr_container TYPE REF TO cl_gui_custom_container,
lr_alv2 TYPE REF TO lcl_alv,
lt_tab TYPE TABLE OF spfli.
"创建容器实例
IF cl_salv_table=>is_offline( ) = ''.
CREATE OBJECT lr_container
EXPORTING
container_name = 'CONTAINER'.
ENDIF.
"创建类LCL_ALV实例
CREATE OBJECT lr_alv2.
"取得列表数据
lt_tab = lr_alv2->getdata( ).
"创建ALV实例
TRY.
cl_salv_table=>factory(
EXPORTING
r_container = lr_container
container_name = 'CONTAINER'
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = lt_tab
).
CATCH cx_salv_msg.
ENDTRY.
"显示ALV列表
gr_table->display( ).
"释放内存
FREE lt_tab.
ENDMODULE. "status_0100
*----------------------------------------------------------------------*
* MODULE user_command_0100
*----------------------------------------------------------------------*
* PAI 屏幕输出后的动作
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE SY-UCOMM.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. "user_command_0100
*报表执行
START-OF-SELECTION.
DATA lr_alv TYPE REF TO lcl_alv.
CREATE OBJECT lr_alv.
lr_alv->main( ).