0% found this document useful (0 votes)
2K views7 pages

Display Subtotal and Total in ABAP ALV Grid

To calculate subtotals in an ABAP ALV grid, build a sort catalog and set the field SUBTOT of each sort catalog record to 'X' for the fields to include subtotals. Pass both the field catalog and sort catalog to the REUSE_ALV_GRID_DISPLAY function module when displaying the ALV grid.

Uploaded by

EmilS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views7 pages

Display Subtotal and Total in ABAP ALV Grid

To calculate subtotals in an ABAP ALV grid, build a sort catalog and set the field SUBTOT of each sort catalog record to 'X' for the fields to include subtotals. Pass both the field catalog and sort catalog to the REUSE_ALV_GRID_DISPLAY function module when displaying the ALV grid.

Uploaded by

EmilS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

Display Subtotal and Total in ABAP ALV Grid

1.

Build field catalog and set the field DO_SUM of field catalog to X for the field for which
you want calculate the totals.
2.
Pass field catalog to function module REUSE_ALV_GRID_DISPLAY.
TYPE-POOLS: slis.

" SLIS contains all the ALV data types

*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook
TYPE TABLE OF sbook.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*Fetch data from the database
SELECT * FROM sbook INTO TABLE it_sbook.
*Build field catalog
wa_fieldcat-fieldname = 'CARRID'.
wa_fieldcat-seltext_m = 'Airline'.
APPEND wa_fieldcat TO it_fieldcat.

" Fieldname in the data table


" Column description in the output

wa_fieldcat-fieldname = 'CONNID'.
wa_fieldcat-seltext_m = 'Con. No.'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'FLDATE'.
wa_fieldcat-seltext_m = 'Date'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'BOOKID'.
wa_fieldcat-seltext_m = 'Book. ID'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname
wa_fieldcat-seltext_m

= 'PASSNAME'.
= 'Passenger Name'.

APPEND wa_fieldcat TO it_fieldcat.


wa_fieldcat-fieldname = 'LOCCURAM'.
wa_fieldcat-seltext_m = 'Price'.
*Calculate Total for Price
wa_fieldcat-do_sum
= 'X'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'LOCCURKEY'.
wa_fieldcat-seltext_m = 'Currency'.
APPEND wa_fieldcat TO it_fieldcat.
*Pass data and field catalog to ALV function module to display ALV list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat
= it_fieldcat
TABLES
t_outtab
= it_sbook
EXCEPTIONS
program_error = 1
OTHERS
= 2.

Output

Subtotal in ABAP ALV


To calculate subtotal in ALV, build sort catalog and set the field SUBTOT of sort catalog to X.

TYPE-POOLS: slis.

" SLIS contains all the ALV data types

*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*

DATA: it_sbook
TYPE TABLE OF sbook.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
it_sort
TYPE slis_t_sortinfo_alv,
wa_sort
TYPE slis_sortinfo_alv..
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*Fetch data from the database
SELECT * FROM sbook INTO TABLE it_sbook.
*Build field catalog
wa_fieldcat-fieldname = 'CARRID'.
wa_fieldcat-seltext_m = 'Airline'.
APPEND wa_fieldcat TO it_fieldcat.

" Fieldname in the data table


" Column description in the output

wa_fieldcat-fieldname = 'CONNID'.
wa_fieldcat-seltext_m = 'Con. No.'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'FLDATE'.
wa_fieldcat-seltext_m = 'Date'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'BOOKID'.
wa_fieldcat-seltext_m = 'Book. ID'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'PASSNAME'.
wa_fieldcat-seltext_m = 'Passenger Name'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'LOCCURAM'.
wa_fieldcat-seltext_m = 'Price'.
wa_fieldcat-do_sum
= 'X'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'LOCCURKEY'.
wa_fieldcat-seltext_m = 'Currency'.
APPEND wa_fieldcat TO it_fieldcat.
*Build sort catalog
wa_sort-spos
= 1.

wa_sort-fieldname
wa_sort-up
wa_sort-subtot
APPEND wa_sort TO

= 'CARRID'.
= 'X'.
= 'X'.
it_sort.

*Pass data and field catalog to ALV function module to display ALV list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat
= it_fieldcat
it_sort
= it_sort
TABLES
t_outtab
= it_sbook
EXCEPTIONS
program_error = 1
OTHERS
= 2.

Output

If you want to calculate subtotals for more fields, just add a record in sort field catalog for each
field.

*Build sort catalog


wa_sort-spos
= 1.
wa_sort-fieldname = 'CARRID'.
wa_sort-up
= 'X'.

wa_sort-subtot
= 'X'.
APPEND wa_sort TO it_sort.
wa_sort-spos
wa_sort-fieldname
wa_sort-up
wa_sort-subtot
APPEND wa_sort TO
Output

= 2.
= 'CONNID'.
= 'X'.
= 'X'.
it_sort.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy