04-17-2014 12:33 PM
I have two internal tables it_0008 and it_0035 and I have many records in first itab as well as second table
how to read the multiple records in second itab .
present code is
LOOP AT it_0008 INTO wa_0008.
endloop.
now I have to loop second itab (it_0035) based on condition pernr of first itab must match with pernr with second itab and also there are multiple records present in it_0035 with same perner number
condition should match wa_008-pernt = it_0035 pernr
if we use loop inside loop there will be performance issue
how to solve this.
04-17-2014 12:37 PM
04-17-2014 12:44 PM
04-17-2014 12:52 PM
Hi,
Parallel cursor is the technique to increase the performance of the program, when there are nested loops. A mandatory prerequisite before using the approach is that the internal tables are sorted by the respective key fields.
Please use the code mentioned below in the thread.
Regards
Gangadhar
04-17-2014 12:39 PM
Hi,
if it is possible to make it_0035 of type sorted table with a unique key, where PERNR is the 1st key field, or to make it of type sorted table with a non-unique key PERNR the performance will increase strongly.
Regards,
Klaus
04-17-2014 12:43 PM
i don't want to use loop inside the loop is there ant other solution . How to read the multiple records ?
04-17-2014 2:25 PM
Your mission should not be "avoid loop inside loop" but rather "avoid performance bottlenecks".
Try out Klaus' advice, if done correctly, it should solve the issue without complicating the code like a parallel cursor algorithm would.
Thomas
04-18-2014 10:20 AM
I'd use a HASHED table for preference over a SORTED table. (If the key is unique and you're not using an index - which might well be what you do with parallel cursor...)
04-18-2014 10:27 AM
Matthew Billingham wrote:
I'd use a HASHED table for preference over a SORTED table. (If the key is unique)
I have been using HASHED tables of late as well.
Sometimes i miss the index operations which i could do on SORTED tables, e.g., deleting inside the loop. I'm sure i'll get more comfortable as i continue to use them.
BR,
Suhas
04-17-2014 12:43 PM
i don't want to use loop inside the loop is there ant other solution . How to read the multiple records ?
04-18-2014 10:22 AM
Thomas Zloch wrote:
Your mission should not be "avoid loop inside loop" but rather "avoid performance bottlenecks".
Try out Klaus' advice, if done correctly, it should solve the issue without complicating the code like a parallel cursor algorithm would.
Do you understand that? It is entirely correct.
04-17-2014 12:46 PM
Hi,
Make use of parallel cursor technique. Sample code is below.
DATA : lv_tabix TYPE sy-tabix.
SORT IT_0008 by PERNR.
SORT IT_0035 by PERNR.
LOOP AT IT_0008 INTO WA_0008.
READ TABLE IT_0035 TRANSPORTING NO FIELDS WITH KEY
PERNR = WA_0008-PERNR BINARY SEARCH
IF sy-subrc EQ 0.
lv_tabix = sy-tabix.
LOOP AT it_0035 INTO wa_0035 FROM lv_tabix.
IF WA_0008-PERNR NE WA_0008-PERNR.
EXIT.
ENDIF.
Logial ABAP statements ………..
ENDLOOP.
ENDIF.
ENDLOOP.
Regards
Gangadhar
04-17-2014 2:01 PM
READ TABLE IT_0035 will read only one record but it has multiple records with same perner
like
8 SALY 2008.12.31 2008.01.01 2009.01.21
8 SALY 2009.12.31 2009.01.01 2009.08.27
04-17-2014 4:49 PM
Hi
that read statement used to get the index number where pernr = wa_008-pernt matches.
then the inside loop statement starts the loop from the respective pernr..
no problem if ur having multiple records in it_0035.
you can write ur Logial ABAP statements inside loop as gangadhar suggested.
04-18-2014 10:21 AM
Do not use SORT and BINARY SEARCH. Use a SORTED table.
Or a HASHED one.
These were introduced over FIFTEEN years ago. Why does everyone go on about BINARY SEARCH!
04-17-2014 1:29 PM
04-17-2014 5:04 PM
04-18-2014 8:50 AM