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: 

Amount calculation in internal table....

Former Member
0 Kudos
117


HI,

I have an internal table ITAB with fields HKONT, BELNR, BUZEI & DMBTR. I want a sum of DMBTR for the same HKONT. Is it possible to do thi without looping ?...or Please suggest a better way to do this ?

I will have millions of records in this internal table.

Thanks.

4 REPLIES 4

former_member183607
Contributor
0 Kudos
54

Hi,

     When u volume of data is large & u want sum of dmbtr for individual HKONT, then why u re populating ur ITAB with belnr and buzei,

     Use Aggregate function SUM to retrieve data.

Regards

yogendra_bhaskar
Contributor
0 Kudos
54

Hi ,

Use Collect statement..............

or while selecting from database table you can use SUM aggregate function

Regards

Yogendra Bhaskar

Former Member
0 Kudos
54

sort the internal table by HKONT and loop at internal table,

in loop u can use

at end of HKONT.

sum.

i don't know if it is possible without using loop.

former_member201285
Active Participant
0 Kudos
54

Hi,

I guess you will get a problem when populating your internal table with "millions of records" because of the restriction of the main memory. So, I would also suggest using an aggregate function.

If you need the data in the internal table absolutely, you should read the data in packages by using a cursor:

DATA: g_cursor TYPE cursor,

  OPEN CURSOR WITH HOLD g_cursor FOR
       SELECT ... FROM ...

  DO.

    FETCH NEXT CURSOR g_cursor
          INTO TABLE gt_internal_table
          PACKAGE SIZE 1000.


*  do something with the internal table

  ......


    IF sy-subrc <> 0.
      CLOSE CURSOR g_cursor.
      EXIT.
    ENDIF.

  ENDDO.