Application Development and Automation 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: 
Read only

Issue With Dynamic Internal Table Calculations

Former Member
0 Likes
372

Hi All,

I have a dynamic internal Table and i want to calculate the sum of QTY if MAT is same

Say ITAB is my dynamic internal table With below entries

MAT             QTY

    A            1
    A            2
    A            3
    B            4
    B            5
    C            6

I want my dynamic internal table to look like

A    6
B    9
C    6

1) I tried below code

LOOP AT <itab> INTO <WA>.
  assign <WA> TO <WA_TEMP>.
    assign component 'MAT' of structure <wa> to <fs>.

  at end of <fs>.
   SUM.  *" SUM Not allowed with in loop assigning*
   ENDAT.
ENDLOOP.

Would appreciate if anyone can comment on the issue

Thanks in advance

Hi All,

I have a dynamic internal Table and i want to calculate the sum of QTY if MAT is same

Say ITAB is my dynamic internal table With below entries

MAT             QTY

    A            1
    A            2
    A            3
    B            4
    B            5
    C            6

I want my dynamic internal table to look like

A    6
B    9
C    6

1) I tried below code

LOOP AT <itab> INTO <WA>.
  assign <WA> TO <WA_TEMP>.
    assign component 'MAT' of structure <wa> to <fs>.

  at end of <fs>.
   SUM.  *" SUM Not allowed with in loop assigning*
   ENDAT.
ENDLOOP.

Would appreciate if anyone can comment on the issue

Thanks in advance

1 REPLY 1
Read only

Sougata
Active Contributor
0 Likes
343

Hello David,

I would try to use COLLECT within the loop of itab instead of SUM.

Cheers,

Sougata.