SAP ABAP - Sample Program To Display Average Value In ALV Report.

This report program displays average value in ALV grid report.

SAMPLE PROGRAM:

REPORT ztest_avg_alv_report LINE-SIZE 80 LINE-COUNT 50 NO STANDARD PAGE HEADING.

TABLES: sflight.

TYPE-POOLS: slis.

* DATA DECLARATION
DATA: i_flight TYPE STANDARD TABLE OF sflight,
i_catalog TYPE slis_t_fieldcat_alv,
w_flight TYPE sflight,
w_catalog TYPE slis_fieldcat_alv.

DATA: v_repid TYPE syrepid.

* SELECTION SCREEN
SELECT-OPTIONS: s_carrid FOR sflight-carrid.

START-OF-SELECTION.

* FETCH DATA FROM SFLIGHT TABLE
SELECT *
FROM sflight
INTO TABLE i_flight
WHERE carrid IN s_carrid.

CHECK sy-subrc = 0.
v_repid = sy-repid.

* FIELD CATALOG FOR ALV REPORT
PERFORM build_catalog.

* DISPLAY ALV REPORT
PERFORM display_report.

*&---------------------------------------------------------------------*
*& Form build_catalog
*&---------------------------------------------------------------------*
* Build field catalog for ALV report
*----------------------------------------------------------------------

FORM build_catalog .

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = v_repid
i_structure_name = 'SFLIGHT'
CHANGING
ct_fieldcat = i_catalog
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.

IF sy-subrc = 0.

* FOR AVERAGE POPULATE "C" AS VALUE IN FIELD DO_SUM

w_catalog-do_sum = 'X'. " C = Average

MODIFY i_catalog FROM w_catalog TRANSPORTING do_sum WHERE fieldname = 'PRICE'.
ENDIF.
ENDFORM. " build_catalog

*&---------------------------------------------------------------------*
*& Form display_report
*&---------------------------------------------------------------------*
* Display ALV report
*----------------------------------------------------------------------*
FORM display_report .

DATA:l_layout TYPE slis_layout_alv.
DATA: sort TYPE slis_sortinfo_alv,
it_sort TYPE slis_t_sortinfo_alv.

sort-fieldname = 'CURRENCY'.
sort-up = 'X'.
APPEND sort TO it_sort.

* ALV LAYOUT SETTINGS
l_layout-zebra = 'X'.
l_layout-colwidth_optimize = 'X'.
l_layout-confirmation_prompt = 'X'. " This asks the confirmation before leaving the screen.
l_layout-totals_text = 'TL'.
l_layout-subtotals_text = 'SU'.

IF i_catalog[] IS NOT INITIAL.

* ALV GRID
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = v_repid
it_fieldcat = i_catalog
is_layout = l_layout
it_sort = it_sort
TABLES
t_outtab = i_flight
EXCEPTIONS
program_error = 1
OTHERS = 2.

IF sy-subrc = 0.
ENDIF.

ENDIF.
ENDFORM. " display_report



MORE PROGRAMS ON ALV DISPLAY:


- Dynamic ALV Grid/List Display.

- ALV Tree Display.

- Colors In ALV Grid Display.

- Making ALV Grid Fields Editable.

- ...Back To Sample Programs, Tips & Tricks On ALV Grid/List Display.


Your suggestions and comments are welcome in this section.

Please mail all your contributions to administrator@abapmadeeasy.com We request you to mention your Name, Designation, Experience & Organization you are working for. Your posts will be verified and posted in this site with your name.