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

Reading internal tables

Former Member
0 Likes
1,436

Hi experts,

I have 2 internal tables i_sddoc, i_konv. In one internal table (i_sddoc) I have 10 rows with identical knumw and posnr.

I need to get the lines from the other internal table (i_konv), when 2 fields are the same (knumw and posnr). In i_konv there are multiply records with the same knumw and kposn.

I'm not allowed to use embedded loops because the table have a size category 4 with thousands of items. So have can I select the lines from i_konv?

If you have further question to be able to answer me, please let me know.

Hi experts,

I have 2 internal tables i_sddoc, i_konv. In one internal table (i_sddoc) I have 10 rows with identical knumw and posnr.

I need to get the lines from the other internal table (i_konv), when 2 fields are the same (knumw and posnr). In i_konv there are multiply records with the same knumw and kposn.

I'm not allowed to use embedded loops because the table have a size category 4 with thousands of items. So have can I select the lines from i_konv?

If you have further question to be able to answer me, please let me know.

12 REPLIES 12
Read only

former_member189629
Active Contributor
0 Likes
1,406

Hi,

Use this for ref...

loop at i_sddoc.

read table i_konv with key posnr = i_sddoc-posnr

knumv = i_sddoc-knumv.

if sy-subrc = 0.

      • do ur procvessing

endif.

endloop.

reward if helpful,

Karthik

Read only

0 Likes
1,406

It is not good, because it only get 1 row from i_konv when it founds the same kunmw and posnr. I would need all.

Read only

0 Likes
1,406

Do you mean to say like the header values are in i_sddoc and line item value are in i_konv

Read only

0 Likes
1,406

white,

in that case, you will have to use a nested loop on konv where posnr & knumv = i_sddoc posnr & knumv. I mean

loop at i_sddoc.

loop at i_konv where key posnr = i_sddoc-posnr

and knumv = i_sddoc-knumv.

      • do ur procvessing

endloop.

endloop.

Read only

0 Likes
1,406

Karthik it would be okay, but if I have a very large internal table then it would run for a very long time, so that's why I don't want to use embedded loops.

have you got any other idea?

Read only

0 Likes
1,406

Hello varalakshmi,

Yes it's similar. Because I have knumv and posnr in i_sddoc, and I have to find all the lines in the other table i_konv which fits to it. The key between my 2 internal table is knumw and posnr, but I have more than 1 records in konv with the same knumv and posnr.

Read only

0 Likes
1,406

Hi White Stripes,

Without embedded loop i do not think your requirement is possibel.

For better performance you can use INDEX in your inner loop.

SORT i_konv

BY knumw

posnr.

LOOP AT i_sddoc

INTO wa_sddoc.

READ TABLE i_konv

INTO wa_konv

with key knumw = wa_sddoc-knumw

AND posnr = wa_sddoc-posnr

BINARY SEARCH.

z_tabix = sy-tabix.

loop at i_konv

into wa_konv

from z_index.

APPEND wa_konv TO it_output.

endloop.

ENDLOOP.

Read only

Former Member
0 Likes
1,406

Hi

fetch the data from VBAK and VBAP into ITAB1

Take the VBAK-KNUMV and VBAP-POSNR and pass to

KONV-KNUMV and KONV-KPOSN and fetch the data from KONV

and separate the data based on the required KSCHL field

Regards

Anji

Read only

0 Likes
1,406

Hello Anji,

kschl is not obligatory in this case, so what should I do in this case?

Read only

Former Member
0 Likes
1,406

Refer the below code.

SORT i_konv

BY knumw

posnr.

LOOP AT i_sddoc

INTO wa_sddoc.

loop at i_konv

into wa_konv.

where knumw = wa_sddoc-knumw

AND posnr = wa_sddoc-posnr.

READ TABLE i_konv

INTO wa_konv.

APPEND wa_konv TO it_output.

endloop.

ENDLOOP.

Check this code

Regards,

Mukesh Kumar

Message was edited by:

mukesh kumar

Read only

Former Member
0 Likes
1,406

I am sorry but have to be a bit harsh, so many answers not one which is useful!

The last one is on the right track but still wrong:

SORT i_konv BY knumw posnr.

LOOP AT i_sddoc INTO wa_sddoc.

READ TABLE i_konv INTO wa_konv

with key knumw = wa_sddoc-knumw

AND posnr = wa_sddoc-posnr

BINARY SEARCH.

z_tabix = sy-tabix.

  • the loop from index is the trick for several hits !!!

loop at i_konv into wa_konv from z_index.

  • the exit is missing, then it will still loop half of the table !!!!!

IF NOT ( wa_konv-knumw = wa_sddoc-knumw

AND wa_konv-posnr = wa_sddoc-posnr ).

EXIT.

ENDIIF

  • there is a loop why another read ???

  • READ TABLE i_konv INTO wa_konv

APPEND wa_konv TO it_output.

ENDLOOP.

ENDLOOP.

For more information please read my recent blog:

/people/siegfried.boes/blog/2007/09/12/runtimes-of-reads-and-loops-on-internal-tables

> allowed to use embedded loops because the table have a size category 4

internal table don't have size categories, if you have a lot of data, more than

you can put into memory, then you must process in packages.

But then you must take care, that both packages contain the lines which belong together.

Siegfried

Read only

Former Member
0 Likes
1,406

The solution is the following. I have to sort all two tables according to knumv and posnr. Then I have to make a loop at konv, then read the table sddoc with key knumv and kposn. So Without sorting the 2 table it doesn't give right results.