Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

FIELD SUM IN ABAP

Former Member
0 Kudos

I have to write a code with summarizes a field....So I have a data on report like this

AAA BBB CCC 1
AAA BBB CCC 2
        SUM 3
-------------
DDD EEE FFF 3
GGG HHH III 4
        SUM 7
-------------
     TOTAL 10
So i have to summarize fields SUM into one SUM, but the problem is that those are not two variables, it a one variable, and the code loop trough the table and fills the field SUM called G_SUM, so how to make a total sum, 
7 REPLIES 7

former_member182550
Active Contributor
0 Kudos

Use object ALV.

Former Member
0 Kudos

In ALV use both subtotal and total options

Former Member
0 Kudos

Option 1: Insert in your internal table (last line) the total sum of all line items.

Option 2: Use ALV standard Total/Subtotal function.

Former Member
0 Kudos

Option 1: Insert in your internal table (last line) the total sum of all line items.

Option 2: Use ALV standard Total/Subtotal function.

raymond_giuseppi
Active Contributor
0 Kudos

The current answer is use ALV, and better use OO ALV (e.g. CL_SALV_TABLE and look for aggregation subclass) many guides/samples are already available in this forum.

The (very) old way was: read documentation of LOOP AT, AT...ENDAT, and SUM statements...

Sandra_Rossi
Active Contributor
0 Kudos

Please provide the context, and the relevant part of your code.

mangesh_parihar
Explorer
0 Kudos

Hi,

I assume you are using same variable to calculate subtotal and clearing it after every loop pass.

You can use another variable to store subtotal value before clearing it and increment it after each loop pass.

Loop at i_tab into w_tab.
clear sub_total.
subtotal = subtotal + w_tab-field1.
grand_total = grand_total + w_tab-field1.
endloop.

In that way, grand_total will have total of all sub_totals.

Regards,

Mangesh Parihar