Вы находитесь на странице: 1из 3

[Select all]

REPORT ztest_oo_alv_aggr.
*
*----------------------------------------------------------------------*
* Code to apply Aggregations to SALV Table display
*----------------------------------------------------------------------*
* CLASS lcl_report DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_report DEFINITION.
*
PUBLIC SECTION.
*
* Final output table
TYPES: BEGIN OF ty_vbak,
vbeln TYPE vbak-vbeln,
erdat TYPE erdat,
auart TYPE auart,
kunnr TYPE kunnr,
netwr TYPE netwr,
END OF ty_vbak.
TYPES: ty_t_vbak TYPE STANDARD TABLE OF ty_vbak.
*
DATA: t_vbak TYPE STANDARD TABLE OF ty_vbak.
*
* 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_aggregations
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 vbeln erdat auart kunnr netwr
INTO CORRESPONDING FIELDS OF TABLE t_vbak
FROM vbak
UP TO 20 ROWS.
*
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 = t_vbak ).
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 the colors to ALV display
CALL METHOD set_aggregations
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_aggregations.
*
DATA: lo_aggrs TYPE REF TO cl_salv_aggregations.
*
lo_aggrs = co_alv->get_aggregations( ).
*
* Add TOTAL for COLUMN NETWR
TRY.
CALL METHOD lo_aggrs->add_aggregation
EXPORTING
columnname = 'NETWR'
aggregation = if_salv_c_aggregation=>total.
CATCH cx_salv_data_error . "#EC NO_HANDLER
CATCH cx_salv_not_found . "#EC NO_HANDLER
CATCH cx_salv_existing . "#EC NO_HANDLER
ENDTRY.
*
* Bring the total line to top
lo_aggrs->set_aggregation_before_items( ).
*
ENDMETHOD. "set_aggregations
*
*
*
*$*$*.....CODE_ADD_3 - End....................................3..*$*$*
ENDCLASS. "lcl_report IMPLEMENTATION