01 功能说明
本系列将通过模拟用户与开发者之间的对话场景,来逐步演示SALV的使用。在本篇中,我们将继续上一篇内容,以解决用户提出的另外两个需求:排序、过滤。让我们来看看是如何实现的吧。
赶快动手试一试,掌握它的用法。
02 功能效果
第6天 用户说:排序
需要按照航线降序。
IF p_day06 EQ 'X'.
DATA lo_sorts TYPE REF TO cl_salv_sorts.
lo_sorts = go_salv->get_sorts( ).
lo_sorts->add_sort(
EXPORTING
columnname = 'CARRID'
sequence = if_salv_c_sort=>sort_down
).
...
ENDIF.
第7天 用户说:过滤
不需要看到航线为JL的数据。
IF p_day07 EQ 'X'.
DATA lo_filters TYPE REF TO cl_salv_filters.
lo_filters = go_salv->get_filters( ).
lo_filters->add_filter(
EXPORTING
columnname = 'CARRID'
sign = 'I'
option = 'NE'
low = 'JL'
).
...
ENDIF.
03 源码分享
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE t1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(79) day01 .
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
...
SELECTION-SCREEN COMMENT 1(79) day06 .
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(79) day07 .
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE t2.
PARAMETERS p_day01 AS CHECKBOX DEFAULT 'X' . "01、基本展示
...
PARAMETERS p_day06 AS CHECKBOX DEFAULT 'X' . "06、添加排序
PARAMETERS p_day07 AS CHECKBOX DEFAULT 'X' . "07、添加过滤
SELECTION-SCREEN END OF BLOCK b2.
INITIALIZATION.
sy-title = 'ABAP SALV演示程序-公众号(ABAP猿)'.
t1 = '用户说'.
t2 = '你来做'.
day01 = '01、从表SPFLI获取数据,并进行基本展示。'.
...
day06 = '06、需要按照航线降序。'.
day07 = '07、不需要看到航线为JL的数据。'.
%_p_day01_%_app_%-text = '01、基本展示'.
...
%_p_day06_%_app_%-text = '06、添加排序'.
%_p_day07_%_app_%-text = '07、添加过滤'.
START-OF-SELECTION.
*------------------------------------*
CHECK p_day01 EQ 'X'.
DATA gt_spfli TYPE TABLE OF spfli.
SELECT * FROM spfli INTO TABLE gt_spfli UP TO 30 ROWS.
DATA go_salv TYPE REF TO cl_salv_table.
cl_salv_table=>factory(
IMPORTING
r_salv_table = go_salv
CHANGING
t_table = gt_spfli ).
*------------------------------------*
...
*------------------------------------*
IF p_day06 EQ 'X'.
DATA lo_sorts TYPE REF TO cl_salv_sorts.
lo_sorts = go_salv->get_sorts( ).
lo_sorts->add_sort(
EXPORTING
columnname = 'CARRID'
sequence = if_salv_c_sort=>sort_down
).
...
ENDIF.
*------------------------------------*
IF p_day07 EQ 'X'.
DATA lo_filters TYPE REF TO cl_salv_filters.
lo_filters = go_salv->get_filters( ).
lo_filters->add_filter(
EXPORTING
columnname = 'CARRID'
sign = 'I'
option = 'NE'
low = 'JL'
).
...
ENDIF.
*------------------------------------*
go_salv->display( ).
小贴士:
- 可使用BC_DATA_GEN生成数据,以便查看演示效果;
- 以上纯属个人总结,如有纰漏请联系我;
以上是今日分享,希望对你有所帮助~~
04 关注我
更多干货请扫码关注微信公众号:ABAP猿