ALV demo:cl_salv_table :Add Header (Top of page)

效果图:

28a5bd6ac39b8014d7d7bf960c46a2a8.jpeg

code:

*&---------------------------------------------------------------------*
*& Report  ZLM_ALV_007
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zlm_alv_007.
*----------------------------------------------------------------------*
*       Code to Apply Filters to SALV Table Display
*----------------------------------------------------------------------*
*       CLASS lcl_report DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_report DEFINITION.
*
  PUBLIC SECTION.
*

*
    DATA: gt_spfli TYPE STANDARD TABLE OF spfli.
*
*   ALV reference
    DATA: o_alv TYPE REF TO cl_salv_table.
*
    METHODS:
*     data selection
      get_data,
*
*     Generating output
      generate_output.
*
*$*$*.....CODE_ADD_1 - Begin..................................1..*$*$*
*
*    In this section we will define the private methods which can
*      be implemented to set the properties of the ALV and can be
*      called in the
*
  PRIVATE SECTION.
    METHODS:
      set_pf_status
        CHANGING
          co_alv TYPE REF TO cl_salv_table.
*
    METHODS:
      set_filters
        CHANGING
          co_alv TYPE REF TO cl_salv_table.


*   Set Top of page
    METHODS:
      set_top_of_page
        CHANGING
          co_alv TYPE REF TO cl_salv_table.
*
*   Set End of page
    METHODS:
      set_end_of_page
        CHANGING
          co_alv TYPE REF TO cl_salv_table.

*$*$*.....CODE_ADD_1 - End....................................1..*$*$*
*
ENDCLASS.                    "lcl_report DEFINITION
*
*
START-OF-SELECTION.
  DATA: lo_report TYPE REF TO lcl_report.
*
  CREATE OBJECT lo_report.
*
  lo_report->get_data( ).
*
  lo_report->generate_output( ).
*
*----------------------------------------------------------------------*
*       CLASS lcl_report IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_report IMPLEMENTATION.
*
  METHOD get_data.
*   data selection
    SELECT * INTO TABLE gt_spfli
           FROM  spfli.
*
  ENDMETHOD.                    "get_data
*
*.......................................................................
  METHOD generate_output.
* New ALV instance
*   We are calling the static Factory method which will give back
*   the ALV object reference.
*
* exception class
    DATA: lx_msg TYPE REF TO cx_salv_msg.
    TRY.
        cl_salv_table=>factory(
          IMPORTING
            r_salv_table = o_alv
          CHANGING
            t_table      = gt_spfli ).
      CATCH cx_salv_msg INTO lx_msg.
    ENDTRY.
*
*$*$*.....CODE_ADD_2 - Begin..................................2..*$*$*
*
*    In this area we will call the methods which will set the
*      different properties to the ALV
*
*   Set default PF status
    CALL METHOD set_pf_status
      CHANGING
        co_alv = o_alv.
*
*   Set Filters
    CALL METHOD set_filters
      CHANGING
        co_alv = o_alv.

*   Calling the top of page method
    CALL METHOD me->set_top_of_page
      CHANGING
        co_alv = o_alv.
*
*   Calling the End of Page method
    CALL METHOD me->set_end_of_page
      CHANGING
        co_alv = o_alv.


*$*$*.....CODE_ADD_2 - End....................................2..*$*$*
*
*
* Displaying the ALV
*   Here we will call the DISPLAY method to get the output on the screen
    o_alv->display( ).
*
  ENDMETHOD.                    "generate_output
*
*$*$*.....CODE_ADD_3 - Begin..................................3..*$*$*
*
*    In this area we will implement the methods which are defined in
*      the class definition
*
*
  METHOD set_pf_status.
*
    DATA: lo_functions TYPE REF TO cl_salv_functions_list.
*
    lo_functions = co_alv->get_functions( ).
    lo_functions->set_default( abap_true ).
*
  ENDMETHOD.                    "set_pf_status
*
  METHOD set_filters.
*
    DATA: lo_filters TYPE REF TO cl_salv_filters.
*
    lo_filters = co_alv->get_filters( ).
*
*   Set the filter for the column ERDAT
*     the filter criteria works exactly same as any
*     RANGE or SELECT-OPTIONS works.
    TRY.
        CALL METHOD lo_filters->add_filter
          EXPORTING
            columnname = 'CARRID'
            sign       = 'I'
            option     = 'EQ'
            low        = 'LH'
*           high       =
          .
      CATCH cx_salv_not_found .                         "#EC NO_HANDLER
      CATCH cx_salv_data_error .                        "#EC NO_HANDLER
      CATCH cx_salv_existing .                          "#EC NO_HANDLER
    ENDTRY.
*
*
  ENDMETHOD.                    "set_filters
*
  METHOD set_top_of_page.
*
    DATA: lo_header  TYPE REF TO cl_salv_form_layout_grid,
          lo_h_label TYPE REF TO cl_salv_form_label,
          lo_h_flow  TYPE REF TO cl_salv_form_layout_flow.
*
*   header object
    CREATE OBJECT lo_header.
*
*   To create a Lable or Flow we have to specify the target
*     row and column number where we need to set up the output
*     text.
*
*   information in Bold
    lo_h_label = lo_header->create_label( row = 1 column = 1 ).
    lo_h_label->set_text( 'Header in Bold' ).
*
*   information in tabular format
    lo_h_flow = lo_header->create_flow( row = 2  column = 1 ).
    lo_h_flow->create_text( text = 'This is text of flow' ).
*
    lo_h_flow = lo_header->create_flow( row = 3  column = 1 ).
    lo_h_flow->create_text( text = 'Number of Records in the output' ).
*
    lo_h_flow = lo_header->create_flow( row = 3  column = 2 ).
    lo_h_flow->create_text( text = 5 ).
*
*   set the top of list using the header for Online.
    co_alv->set_top_of_list( lo_header ).
*
*   set the top of list using the header for Print.
    co_alv->set_top_of_list_print( lo_header ).
*
  ENDMETHOD.                    "set_top_of_page
*
  METHOD set_end_of_page.
*
    DATA: lo_footer  TYPE REF TO cl_salv_form_layout_grid,
          lo_f_label TYPE REF TO cl_salv_form_label,
          lo_f_flow  TYPE REF TO cl_salv_form_layout_flow.
*
*   footer object
    CREATE OBJECT lo_footer.
*
*   information in bold
    lo_f_label = lo_footer->create_label( row = 1 column = 1 ).
    lo_f_label->set_text( 'Footer .. here it goes' ).
*
*   tabular information
    lo_f_flow = lo_footer->create_flow( row = 2  column = 1 ).
    lo_f_flow->create_text( text = 'This is text of flow in footer' ).
*
    lo_f_flow = lo_footer->create_flow( row = 3  column = 1 ).
    lo_f_flow->create_text( text = 'Footer number' ).
*
    lo_f_flow = lo_footer->create_flow( row = 3  column = 2 ).
    lo_f_flow->create_text( text = 1 ).
*
*   Online footer
    co_alv->set_end_of_list( lo_footer ).
*
*   Footer in print
    co_alv->set_end_of_list_print( lo_footer ).
*
  ENDMETHOD.                    "set_end_of_page

*
*$*$*.....CODE_ADD_3 - End....................................3..*$*$*
ENDCLASS.                    "lcl_report IMPLEMENTATIO

cc1045ddd3180689438fea3485cd2930.gif

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值