05-16-2017 9:53 AM
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,
05-16-2017 11:01 AM
06-20-2017 5:46 PM
06-21-2017 6:27 AM
Option 1: Insert in your internal table (last line) the total sum of all line items.
Option 2: Use ALV standard Total/Subtotal function.
06-21-2017 6:27 AM
Option 1: Insert in your internal table (last line) the total sum of all line items.
Option 2: Use ALV standard Total/Subtotal function.
06-21-2017 6:29 AM
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...
06-21-2017 6:56 AM
06-21-2017 7:45 AM
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