cl_salv_table

 

1、简单的CL_SALV_TABLE 的使用
REPORT ZALVOM_DEMO1.
data: ispfli type table of spfli.
data: gr_table type ref to cl_salv_table.

start-of-selection.
select * into table ispfli from spfli.
cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ).
gr_table->display( ).
运行结果

2、使用CL_SALV_FUNCTIONS添加工具栏(注意添加的红色代码)
REPORT ZALVOM_DEMO1.
data: ispfli type table of spfli.
data: gr_table type ref to cl_salv_table.
data: gr_functions type ref to cl_salv_functions.

start-of-selection.
select * into table ispfli from spfli.
cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ).
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).

gr_table->display( ).
运行结果

3、使用CL_SALV_DISPLAY_SETTINGS(注意添加的红色代码)
REPORT ZALVOM_DEMO1.
data: ispfli type table of spfli.
data: gr_table type ref to cl_salv_table.
data: gr_functions type ref to cl_salv_functions.
data: gr_display type ref to cl_salv_display_settings.

start-of-selection.
select * into table ispfli from spfli.
cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ).
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
gr_display = gr_table->get_display_settings( ).
gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
gr_display->set_list_header( 'This is the heading' ).
gr_table->display( ).

4、使用CL_SALV_COLUMNS_TABLE和CL_SALV_COLUMN_TABLE(注意添加的红色代码)
REPORT ZALVOM_DEMO1.
data: ispfli type table of spfli.
data: gr_table type ref to cl_salv_table.
data: gr_functions type ref to cl_salv_functions.
data: gr_display type ref to cl_salv_display_settings.
data: gr_columns type ref to cl_salv_columns_table.
data: gr_column type ref to cl_salv_column_table.

data: color type lvc_s_colo.
start-of-selection.
select * into table ispfli from spfli.
cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ).
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
gr_display = gr_table->get_display_settings( ).
gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
gr_display->set_list_header( 'This is the heading' ).
gr_columns = gr_table->get_columns( ).
gr_column ?= gr_columns->get_column( 'CITYTO' ).
gr_column->set_long_text( 'This is long text' ).
gr_column->set_medium_text( 'This is med text' ).
gr_column->set_short_text( 'This is sh' ).
gr_column ?= gr_columns->get_column( 'CITYFROM' ).
color-col = '6'.
color-int = '1'.
color-inv = '0'.
gr_column->set_color( color ).

gr_table->display( ).

5、使用CL_SALV_SORTS(注意添加的红色代码),增加排序
REPORT ZALVOM_DEMO1.
data: ispfli type table of spfli.
data: gr_table type ref to cl_salv_table.
data: gr_functions type ref to cl_salv_functions.
data: gr_display type ref to cl_salv_display_settings.
data: gr_columns type ref to cl_salv_columns_table.
data: gr_column type ref to cl_salv_column_table.
data: gr_sorts type ref to cl_salv_sorts.

data: color type lvc_s_colo.
start-of-selection.
select * into table ispfli from spfli.
cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ).
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
gr_display = gr_table->get_display_settings( ).
gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
gr_display->set_list_header( 'This is the heading' ).
gr_columns = gr_table->get_columns( ).
gr_column ?= gr_columns->get_column( 'CITYTO' ).
gr_column->set_long_text( 'This is long text' ).
gr_column->set_medium_text( 'This is med text' ).
gr_column->set_short_text( 'This is sh' ).
gr_column ?= gr_columns->get_column( 'CITYFROM' ).
color-col = '6'.
color-int = '1'.
color-inv = '0'.
gr_column->set_color( color ).
gr_sorts = gr_table->get_sorts( ).
gr_sorts->ADD_SORT( 'CITYTO' ).

gr_table->display( ).

6、使用CL_SALV_AGGREGATIONS(注意添加的红色代码),增加汇总
将DISTANCE字段按CITYTO字段进行汇总
REPORT ZALVOM_DEMO1.
data: ispfli type table of spfli.
data: gr_table type ref to cl_salv_table.
data: gr_functions type ref to cl_salv_functions.
data: gr_display type ref to cl_salv_display_settings.
data: gr_columns type ref to cl_salv_columns_table.
data: gr_column type ref to cl_salv_column_table.
data: gr_sorts type ref to cl_salv_sorts.
data: gr_agg type ref to cl_salv_aggregations.

data: color type lvc_s_colo.

start-of-selection.
select * into table ispfli from spfli.
cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ).
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
gr_display = gr_table->get_display_settings( ).
gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
gr_display->set_list_header( 'This is the heading' ).
gr_columns = gr_table->get_columns( ).
gr_column ?= gr_columns->get_column( 'CITYTO' ).
gr_column->set_long_text( 'This is long text' ).
gr_column->set_medium_text( 'This is med text' ).
gr_column->set_short_text( 'This is sh' ).
gr_column ?= gr_columns->get_column( 'CITYFROM' ).
color-col = '6'.
color-int = '1'.
color-inv = '0'.
gr_column->set_color( color ).
gr_sorts = gr_table->get_sorts( ).
* gr_sorts->ADD_SORT( 'CITYTO' ).
gr_sorts->add_sort( columnname = 'CITYTO' subtotal = abap_true ).
gr_agg = gr_table->get_aggregations( ).
gr_agg->add_aggregation( 'DISTANCE' ).
gr_table->display( ).

7、使用CL_SALV_FILTERS(注意添加的红色代码),增加过滤
只显示CARRID等于'LH'
REPORT ZALVOM_DEMO1.
data: ispfli type table of spfli.
data: gr_table type ref to cl_salv_table.
data: gr_functions type ref to cl_salv_functions.
data: gr_display type ref to cl_salv_display_settings.
data: gr_columns type ref to cl_salv_columns_table.
data: gr_column type ref to cl_salv_column_table.
data: gr_sorts type ref to cl_salv_sorts.
data: gr_agg type ref to cl_salv_aggregations.
data: gr_filter type ref to cl_salv_filters.

data: color type lvc_s_colo.

start-of-selection.
select * into table ispfli from spfli.
cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ).
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
gr_display = gr_table->get_display_settings( ).
gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
gr_display->set_list_header( 'This is the heading' ).
gr_columns = gr_table->get_columns( ).
gr_column ?= gr_columns->get_column( 'CITYTO' ).
gr_column->set_long_text( 'This is long text' ).
gr_column->set_medium_text( 'This is med text' ).
gr_column->set_short_text( 'This is sh' ).
gr_column ?= gr_columns->get_column( 'CITYFROM' ).
color-col = '6'.
color-int = '1'.
color-inv = '0'.
gr_column->set_color( color ).
gr_sorts = gr_table->get_sorts( ).
* gr_sorts->ADD_SORT( 'CITYTO' ).
gr_sorts->add_sort( columnname = 'CITYTO' subtotal = abap_true ).
gr_agg = gr_table->get_aggregations( ).
gr_agg->add_aggregation( 'DISTANCE' ).
gr_filter = gr_table->get_filters( ). 
gr_filter->add_filter( columnname = 'CARRID' low = 'LH' ).
gr_table->display( ).

8、使用CL_SALV_LAYOUT(注意添加的红色代码),增加变式保存
*&---------------------------------------------------------------------*
*& Report ZTEST4
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZALVOM_DEMO1.
data: ispfli type table of spfli.
data: gr_table type ref to cl_salv_table.
data: gr_functions type ref to cl_salv_functions.
data: gr_display type ref to cl_salv_display_settings.
data: gr_columns type ref to cl_salv_columns_table.
data: gr_column type ref to cl_salv_column_table.
data: gr_sorts type ref to cl_salv_sorts.
data: gr_agg type ref to cl_salv_aggregations.
data: gr_filter type ref to cl_salv_filters.
data: gr_layout type ref to cl_salv_layout.

data: key type salv_s_layout_key.
data: color type lvc_s_colo.

start-of-selection.
select * into table ispfli from spfli.
cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ).
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
gr_display = gr_table->get_display_settings( ).
gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
gr_display->set_list_header( 'This is the heading' ).
gr_columns = gr_table->get_columns( ).
gr_column ?= gr_columns->get_column( 'CITYTO' ).
gr_column->set_long_text( 'This is long text' ).
gr_column->set_medium_text( 'This is med text' ).
gr_column->set_short_text( 'This is sh' ).
gr_column ?= gr_columns->get_column( 'CITYFROM' ).
color-col = '6'.
color-int = '1'.
color-inv = '0'.
gr_column->set_color( color ).
gr_sorts = gr_table->get_sorts( ).
* gr_sorts->ADD_SORT( 'CITYTO' ).
gr_sorts->add_sort( columnname = 'CITYTO' subtotal = abap_true ).
gr_agg = gr_table->get_aggregations( ).
gr_agg->add_aggregation( 'DISTANCE' ).
gr_filter = gr_table->get_filters( ).
gr_filter->add_filter( columnname = 'CARRID' low = 'LH' ).
gr_layout = gr_table->get_layout( ).
key-report = sy-repid.
gr_layout->set_key( key ).
gr_layout->set_save_restriction( cl_salv_layout=>restrict_none ).
gr_table->display( ).

转载于:https://www.cnblogs.com/eric0701/p/4228730.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值