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: 

Copy Internal Table W/O Memory Problems

Former Member
0 Kudos

Hi Experts,

A hopefully simple ABAP question: I have a very large internal abap table of line type AA which shall be append to another internal table of line type BB.

Curret implementation is pretty straightforeward:

LOOP AT AA ASSINGING <FA>.

     MOVE-CORRESPONDING <FA> TO <FB>.

     APPEND <FB> TO BB.

ENDLOOP.

FREE AA.

Issue: AA is a very very big table (> 1.000.000 entries, with a pretty big column size). The table needs ~1.5GB RAM. When using the way above for a very short time ~3GB RAM will be required (which will finally put the process into private mode, causing big performance problems).

Sadly I do not know any way to free the memory of an internal table partially. I've tried to do the following code snipped (which does not work, because DELETE does not free memory).

WHILE AA[] IS NOT INITIAL.

     READ TABLE aa assinging <fa> INDEX 1.

     MOVE-CORRESPONDING <FA> TO <fB>.

     APPEND <FB> TO BB.

     DELETE aa INDEX 1.

ENDWHILE.

As I said, this does not work, because DELETE does not shrink the memory extension of a table.

Do you know ANY way to complete the described use case, without having the table two times in RAM?

REgards,
Timo

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Timo,

Good one

How the AA table is filled at the first place?

If possible what about splitting the AA data into smaller tables (AA1, .., AAn) and then processing & freeing them one by one ?

Br,

Manu.

10 REPLIES 10

Former Member
0 Kudos

Hi Timo,

Good one

How the AA table is filled at the first place?

If possible what about splitting the AA data into smaller tables (AA1, .., AAn) and then processing & freeing them one by one ?

Br,

Manu.

0 Kudos

Hello Manu D'Haeyer.

     If internal tables AA and BB have their fields declared in same order, then

          BB[] = AA[].

          REFRESH: AA.

Regards.

0 Kudos

This will double the memory exhaust directly after BB[] = AA[]. Of course the memory is directly cleared again afterwards - nevertheless for very big tables this can cause the process going into private mode.

Former Member
0 Kudos

If your AA and BB internal table have same structure, then you can directly use:

Append lines of AA to BB.

Vivek

0 Kudos

This will double the memory exhaust directly after BB[] = AA[]. Of course the memory is directly cleared again afterwards - nevertheless for very big tables this can cause the process going into private mode.

former_member186413
Participant
0 Kudos

Hi Timo Stark

Accounting to Manu D'Haeyer, here is how you restrict data from database.  for example

(note* Please notice the headline contents)

REPORT  z_test.

TABLES: mseg, mara, vbap.

TYPES: BEGIN OF s_matnr,

         vbeln LIKE vbap-vbeln,

         posnr LIKE vbap-posnr,

         matnr LIKE mseg-matnr,

         menge LIKE mseg-menge,

       END OF s_matnr,

DATA: it_mseg TYPE TABLE OF mseg WITH HEADER LINE,

      it_matnr TYPE TABLE OF s_matnr WITH HEADER LINE.

START-OF-SELECTION.
  SELECT *
  FROM mseg
  INTO TABLE it_mseg PACKAGE SIZE 50.
    LOOP AT it_mseg.

      MOVE-CORRESPONDING it_mseg TO it_matnr.

      SELECT SINGLE vp~vbeln vp~posnr

      FROM vbap AS vp INNER JOIN aufk AS ak ON vp~vbeln = ak~kdauf

                                           AND vp~posnr = ak~kdpos

                      INNER JOIN mseg AS ms ON ms~aufnr = ak~aufnr

      INTO ( it_matnr-vbeln it_matnr-posnr )

      WHERE ms~aufnr = it_mseg-aufnr.

      COLLECT it_matnr.

    ENDLOOP.
  ENDSELECT.

nabheetscn
Active Contributor
0 Kudos

How is the internal table AA filled?

0 Kudos

I think, Timo Stark is using the 'classical' way to get data, otherwise, it is impossible to cost that mush RAM. 

Former Member
0 Kudos

Hi,

I'm importing the data from a cluster table (IMPORT..), therefore i can not simply "chunk" the data of AA. Generally I can of course "chunk"/split the clusters in the DB, but

I really hoped that ABAP has any instruction to shrink the table memory exhaust to the value actually used.

Nevermind - Thank you very much for your help - especially for the PACKAGE SIZE instruction which I've never heard about before 🙂

Regards,

Timo

0 Kudos

Timo,

The PACKAGE SIZE addition is of no use in your case since you are doing an IMPORT not SELECT to fill the internal table.

Have you tried using LOOP AT itab with FROM idx addition? Basically its the same idea as the PACKAGE SIZE addition to a SELECT i.e. to do the processing in chunks rather than the entire table content.

In a loop, fill internal table BB say 5,000 rows at a time (using the FROM addition) -> In the same loop, do your all your business logic processing then FREE BB at the end of every 5000th iteration.

Hope this helps.

Sougata.