How Calculate TOTALS,SUBTOTALS in ALV Reporting?

Answer Posted / gogo

1. You need 2 internal tables: FIELDCATALOG table and SORT table
DATA: gt_fieldcatalog TYPE lvc_t_fcat,
gt_fieldcatalog_sort TYPE lvc_t_sort,
lw_fcat TYPE lvc_s_fcat,
lw_fcat_sort TYPE lvc_s_sort.

2. Fill fieldcatalog table fields
lw_fcat-fieldname = 'YOUR FIELD NAME'.
* Subtotal for this field
lw_fcat-do_sum = 'X'.
APPEND lw_fcat TO gt_fieldcatalog.

3. Fill sort table fields
* Mark the fields that you want to make subtotals after
(e.g. VKORG KUNNR VBELN = keys ; NETWR = sum)
CASE 'YOUR FIELD NAME'.
WHEN 'VKORG' OR 'KUNNR'.
lw_fcat_sort-fieldname = u_fieldname.
lw_fcat_sort-up = 'X'.
lw_fcat_sort-subtot = 'X'.
APPEND lw_fcat_sort TO gt_fieldcatalog_sort.
WHEN OTHERS.
ENDCASE.

Risult
VKORG | KUNNR | VBELN |NETWR
1 a 001 10
1 a 002 20
1 a 003 30
----------------------------
subtotal 1 a 60
----------------------------
1 b 001 5
----------------------------
subtotal 1 b 5
----------------------------

Hope it helps!

Is This Answer Correct ?    25 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

hi experts,,, what is meant by documentation? test casr preparation? documentation and preparation and Tcode for this? quality and releasing? test case scenario?

1726


What is the use of the raising exception? : abap modularization

521


What do is landscape in sap project, I think its related to no. Of servers used, pls correct me if I am wrong, or what it is? : sap abap hr

557


What are the events used for logical database?

608


Why do we use events and actions in web dynpro?

595






What are advantages and disadvantages of logical data base

1765


How to load data from ms excel sheet to sap by using bdc method ? : abap bdc

730


Different between Interface and Abstract classes?

1121


What are the data types of the external layer? : abap data dictionary

798


Mention the various databases integrities?

618


What are the functional areas?

622


Explain sap abap 3-tier architecture?

737


what is the process of creating quotation using BAPIs.

1576


What is ole?

686


What are uses of foreign key?

574