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: 

Aggregating fields in ALV (Urgent)

Former Member
0 Kudos

Hi friends

How can i do aggregate in ALV ?

eg:-

my report output luks like this:-

10C-NAME1 10 3 4

10C-NAME1 2 4 6

10C-NAME1 8 8 8

Now i want to sumup these records and display as one record.

Now..my rep output should be 10C-NAME1 20 15 18

The above is just an example.. I m using ALV Grid report.

Please help me

1 ACCEPTED SOLUTION

Former Member
0 Kudos

DATA wa LIKE itab OCCURS 0 WITH HEADER LINE.

LOOP AT itab.

AT LAST.

SUM.

wa-name = itab-name.

wa-f1 = itab-f1.

wa-f2 = itab-f2.

wa-f3 = itab-f3.

APPEND wa.

ENDAT.

ENDLOOP.

Now use table <b>wa</b> for displaying in ALV.

5 REPLIES 5

Former Member
0 Kudos

DATA wa LIKE itab OCCURS 0 WITH HEADER LINE.

LOOP AT itab.

AT LAST.

SUM.

wa-name = itab-name.

wa-f1 = itab-f1.

wa-f2 = itab-f2.

wa-f3 = itab-f3.

APPEND wa.

ENDAT.

ENDLOOP.

Now use table <b>wa</b> for displaying in ALV.

0 Kudos

Hai wen,

your logic is aggregating for all fields.

if my rep output luks llike

10C-NAME1 10 3 4

10C-NAME1 2 4 6

10C-NAME1 8 8 8

10H-NAME2 6 6 6

10H-NAME2 8 8 8

Then it should display

10C-NAME1 20 15 18

10H-NAME2 14 14 14

but its not displaying like that..it is aggreagating everything

0 Kudos

Then try this.

DATA wa LIKE itab OCCURS 0 WITH HEADER LINE.

LOOP AT itab.

AT LAST itab-name.

SUM.

wa-name = itab-name.

wa-f1 = itab-f1.

wa-f2 = itab-f2.

wa-f3 = itab-f3.

APPEND wa.

ENDAT.

ENDLOOP.

Former Member
0 Kudos

For the field that you want totals for, set DO_SUM = 'X' in IT_FIELDCAT. For IS_LAYOUT, set totals_only = 'X'.

Rob

Former Member
0 Kudos

Hi ,

Let me give u a simpler solution.

Use ABAP statement COLLECT <internal table>

this will sum up all the numerical fields in your internal table based on Name field (non numeric)

after sum operation all the records will be repalced wid the new summation record. thus u can used the same internal table to display your results

this statement is meant exactly for your requirement.

Kindly give me some points if this helps.

Look into the following link for more details

http://help.sap.com/saphelp_47x200/helpdata/en/87/56d00722c011d2954a0000e8353423/frameset.htm

regards,

Sumeet Mishra