首页 > 其他分享 >ALV demo 03:cl_salv_table :Add Header (Top of page)

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

时间:2022-10-16 17:01:47浏览次数:52  
标签:03 SET cl demo CREATE FLOW LO ALV SALV


以下是纯顾问群~

QQ群 :SAP干货铺,  群号:775662808
所有群管理严格,严格禁止一切外来链接、招聘、广告等垃圾信息!

直接上干货了。


效果图:

ALV demo 03:cl_salv_table :Add Header (Top of page)_微信


code:
*&---------------------------------------------------------------------*
*& Report ZLM_ALV002
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZLM_ALV002.

*----------------------------------------------------------------------*
* Code to Apply Filters to SALV Table Display
*& sapliumeng SAP干货铺
*----------------------------------------------------------------------*
* 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

标签:03,SET,cl,demo,CREATE,FLOW,LO,ALV,SALV
From: https://blog.51cto.com/u_15680210/5760447

相关文章