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

What is the difference between getting and get late?

585


Can we access static attribute from instance method

988


What are the table controls in bdc ? What is the difference between bdc and lsmw ?what is the difference between bdc and rfc ? : abap bdc

556


What is the difference between synchronous and asynchronous update? : abap bdc

638


What are base tables of an aggregate object? : abap data dictionary

606






What is view? Different types of view.

581


What are the different database integrities?

577


Difference between open sql and native sql? : abap data dictionary

605


What happens when you post goods issue after delivery? How does the inventory get reduced after the delivery?

559


What statement will be found in an sap application program that implements a function module exit?

546


What are the system table used in abap?

584


1/ How do u apprach if error occur in sending idocs ? 2/ where u assigned process code ?

1464


Define spool request?

664


What is structure?

568


Rp_provide_from_last contains how many parameters ? : abap hr

878