前面的例子ALV列表都是直接输出在主窗口中,下面我们实现在弹出窗口中实现ALV。在弹出窗口中实现ALV也很简单,只要在实现类CL_SALV_TABLE的一个方法SET_SCREEN_POPUP就可以了。
gr_table->set_screen_popup(
start_column = 1
end_column = 120
start_line = 1
end_line = 20 ).
方法SET_SCREEN_POPUP的是弹出窗口的显示范围。
下面是效果图
下面是程序的所有代码:
REPORT y_xin_002.
*变量定义
TYPES: BEGIN OF gs_spfli,
mandt TYPE spfli-mandt,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
countryfr TYPE spfli-countryfr,
cityfrom TYPE spfli-cityfrom,
airpfrom TYPE spfli-airpfrom,
countryto TYPE spfli-countryto,
cityto TYPE spfli-cityto,
airpto TYPE spfli-airpto,
fltime TYPE spfli-fltime,
deptime TYPE spfli-deptime,
arrtime TYPE spfli-arrtime,
distance TYPE spfli-distance,
distid TYPE spfli-distid,
fltype TYPE spfli-fltype,
period TYPE spfli-period,
END OF gs_spfli.
TYPES ty_spfli TYPE gs_spfli OCCURS 0.
DATA: gr_table TYPE REF TO cl_salv_table.
*设置屏幕
SELECTION-SCREEN PUSHBUTTON 2(20) btn USER-COMMAND clk.
INITIALIZATION.
btn = '点击显示弹出alv窗口'.
*----------------------------------------------------------------------*
* 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 CORRESPONDING FIELDS OF TABLE lt_tab FROM spfli.
ENDMETHOD. "getdata
*输出全屏网格列表的方法
METHOD alv_full.
DATA: lr_functions TYPE REF TO cl_salv_functions.
"创建实例
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = lt_tab
).
CATCH cx_salv_msg.
ENDTRY.
"显示ALV的标准功能
lr_functions = gr_table->get_functions( ).
lr_functions->set_all( 'X' ).
"弹出窗口设置
gr_table->set_screen_popup(
start_column = 1
end_column = 120
start_line = 1
end_line = 20 ).
"显示列表
gr_table->display( ).
ENDMETHOD. "alv_full
*主方法,整合数据
METHOD main.
DATA: lt_tab TYPE ty_spfli.
"取得要显示的数据
lt_tab = me->getdata( ).
me->alv_full( lt_tab ).
ENDMETHOD. "main
ENDCLASS. "lcl_alv IMPLEMENTATION
*执行按钮点击动作
AT SELECTION-SCREEN.
CASE sy-ucomm.
WHEN 'CLK'.
DATA lr_alv TYPE REF TO lcl_alv.
CREATE OBJECT lr_alv.
lr_alv->main( ).
ENDCASE.