Skip to Content
-3

FIELD SUM IN ABAP

May 16, 2017 at 08:53 AM

108

avatar image

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, 
10 |10000 characters needed characters left characters exceeded

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

0
Further commenting has been locked.
* Please Login or Register to Answer, Follow or Comment.

6 Answers

Richard Harper May 16, 2017 at 10:01 AM
-1

Use object ALV.

Share
10 |10000 characters needed characters left characters exceeded
Venkata Jaya Sameera Sistla Jun 20, 2017 at 04:46 PM
-1

In ALV use both subtotal and total options

Share
10 |10000 characters needed characters left characters exceeded
Mangesh Parihar Jun 21, 2017 at 06:45 AM
-1

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

Share
10 |10000 characters needed characters left characters exceeded
Elzkie La Jun 21, 2017 at 05:27 AM
-2

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

Option 2: Use ALV standard Total/Subtotal function.

Share
10 |10000 characters needed characters left characters exceeded
Elzkie La Jun 21, 2017 at 05:27 AM
-2

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

Option 2: Use ALV standard Total/Subtotal function.

Share
10 |10000 characters needed characters left characters exceeded
Raymond Giuseppi
Jun 21, 2017 at 05:29 AM
0

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...

Share
10 |10000 characters needed characters left characters exceeded