10-29-2009 2:13 PM
Hi,
Is it possible to read multiple lines from an internal table using READ Table syntax.
Read statement suggest to select only one row.
My requirement is that I am looping around an internal table it1. Inside the loop I am looping once again over another table it2 since it2 can contain n entries for a particular value in it1.
Is thereway to avoid this nested looping.
Thanks.
Regards,
Sudharshan N A
10-29-2009 2:36 PM
Hello Sudharsan,
In some cases it may be impossible to do away with Nested Loops. In these cases, you need to reduce the ABAP processing time efficiently using parallel processing technique:
DATA: LV_INDX TYPE I.
SORT IT1 BY F1. "Here F1 is the common field
SORT IT2 BY F1.
LOOP AT IT1.
* Get the table index from which to loop
READ TABLE IT2 TRANSPORTING NO FIELDS
WITH KEY F1 = IT1-F1 BINARY SEARACH.
IF SY-SUBRC = 0.
LV_INDX = SY-TABIX.
LOOP AT IT2 FROM LV_INDX.
IF IT2-F1 NE IT1-F1. "If the value of F1 changes exit the loop
EXIT.
ENDIF.
" Do your processing for IT2 here
ENDLOOP.
ENDIF.
May be other SDNers have some better responses.
Hope this helps.
BR,
Suhas
10-29-2009 2:16 PM
READ statement will pick the first entry encountered in the internal table as per the match criteria
Since, you are having N entries associated with a particular one ,READ statement wont work correctly in this case.
So, youhave to use NESTED LOOP any wayz.
Regards,
Lakshman.
10-29-2009 2:20 PM
Hi,
Read statement would read only a single line at a time.
Why dont you use a key value to read from your internal table within the loop... instead of nested looping if it is possible
Thanks,
Harini
10-29-2009 2:36 PM
Hello Sudharsan,
In some cases it may be impossible to do away with Nested Loops. In these cases, you need to reduce the ABAP processing time efficiently using parallel processing technique:
DATA: LV_INDX TYPE I.
SORT IT1 BY F1. "Here F1 is the common field
SORT IT2 BY F1.
LOOP AT IT1.
* Get the table index from which to loop
READ TABLE IT2 TRANSPORTING NO FIELDS
WITH KEY F1 = IT1-F1 BINARY SEARACH.
IF SY-SUBRC = 0.
LV_INDX = SY-TABIX.
LOOP AT IT2 FROM LV_INDX.
IF IT2-F1 NE IT1-F1. "If the value of F1 changes exit the loop
EXIT.
ENDIF.
" Do your processing for IT2 here
ENDLOOP.
ENDIF.
May be other SDNers have some better responses.
Hope this helps.
BR,
Suhas
10-29-2009 2:45 PM
Hi,
It does seem possible to read multiple lines in a internal table using the READ statement with consecutive index. Have a look Rob's reply in this thread though not sure how much performace effective it is compared to nested loops.
Vikranth