• ABAP如何使用CL_SALV_TABLE 的代码样例(2004以后版本)


    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( ).

  • 相关阅读:
    ASP.NET WebForm Best Practice 之ViewState
    我会为开源和自由学习,使用JAVA.但我决不会为了开源和自由放弃.NET
    EXT调用ASP.NET AJAX WebService
    我的2007
    博客园迎新春对联
    NBear.Mapping使用教程(2):NBear.Mapping的配置系统
    NBear.Mapping使用教程(3):第一个简单例子
    使用LumaQQ来开发QQ机器人
    解决方案迁移到Visual Studio 2008的一些相关问题
    NBear.Mapping使用教程(4):实体对象与ADO.NET对象的转换
  • 原文地址:https://www.cnblogs.com/xiaomaohai/p/6157163.html
Copyright © 2020-2023  润新知