Skip to Content
author's profile photo Former Member
Former Member

Copy Internal Table W/O Memory Problems

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 28, 2013 at 12:06 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 28, 2013 at 05:43 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 28, 2013 at 04:39 AM

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

    Append lines of AA to BB.

    Vivek

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 28, 2013 at 06:25 AM

    How is the internal table AA filled?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 28, 2013 at 08:51 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.