cancel
Showing results for 
Search instead for 
Did you mean: 

Casting standard itab to sorted itab

rnb86
Participant
0 Kudos

Hi Experts,

Need your help with my issue.

I am trying to improve the performance of an old report program. There is a select query on GLPCA table which fetches 2400000 records into say it_glpca.

After the select, these records are moved into another internal table say it_glpca_temp.

Now, the it_glpca_temp itab is sorted by kunnr.

Before code change:

select on glpca into it_glpca.

it_glpca_temp[] = it_glpca[].

sort it_glpca_temp by kunnr.

After my code change:

i changed the declaration of it_glpca_temp as type sorted internal table. Earlier it was of type standard table. I did this to avoid using the sort command on the internal table with large number of records.

The program dumps saying 'No more memory available to add rows to an internal table' with 'TSV_TNEW_PAGE_ALLOC_FAILED'.

This is happening because the it_glpca table has huge data. This dump wont happen for less number of records. i checked.

There is no other way of limiting the selection criteria. This data is for a single company code and we cannot limit the selection criteria any further than what it already is.

My question;

How to avoid the runtime error that i am getting with the code --> it_glpca_temp[] = it_glpca[].

Am i doing the casting (moving data from itab type standard table to itab type sorted table) wrong?

Any suggestions would be most welcome.

Accepted Solutions (0)

Answers (2)

Answers (2)

rnb86
Participant
0 Kudos

Hello Thales,

Thanks a lot for replying.

The purpose of having it_glpca and it_glpca_temp is to update the customer data into the it_glpca_temp table. Originally, the it_glpca table has a different sort sequence. it_glpca is sorted by racct rassc locco rprctr kostl. This sort is for populating the final output table. Considering the huge data in it, we cannot declare it like you suggested, by KUNNR. I should have put this point in the issue description.

it_glpca_temp is sorted by Kunnr only for updating the customer fields LOCCO and VBUND into the it_glpca table from kNA1 table.

Please let me know your inputs.

thalesvb
Active Contributor
0 Kudos

Hello Raghu,

Instead of copying the entire internal table to another sorted table, you can simply declare the first standard table containing a secondary sorted key (it is available since ABAP 7.0 EhP2).

DATA it_glpca TYPE STANDARD TABLE OF glpca ... WITH NON-UNIQUE SORTED KEY key_kunnr COMPONENTS kunnr.

The standard table will behave like a sorted table when accessing it with the secondary key, and it consumes less memory than mantaining two internal tables in program with same data. Please check DEMO_SECONDARY_KEYS report for how to use it (if it doesn't exist in your system then this feature is unavailable).

Regards.