09-28-2007 6:27 AM
Hi Folks
Can I put Read inside loop?
Performance wise is it acceptable?
Regards,
Sreeram
09-28-2007 6:29 AM
OF COURSE U CAN PUT READ IN THE LOOP.
for performance...
be sure for follwing things...
sort the table with the key fields on which u r putting read.
then write the following code.
READ TABLE IT INTO WA WITH KEY XYZ = ' ' BINARY SEARCH.
REWARD POINTS PLEASE...
09-28-2007 6:33 AM
ya sree ram.. it is absoulatelty fine to put read inside the loop..
just avoid nested loop for better performance..
reward if useful..
09-28-2007 6:41 AM
well ofcourse you can use it, however as far as performance is concerned, its better to use "FOR ALL ENTRIES".
Please reward the helpful entries.
Regards,
Raman.
09-28-2007 9:57 AM
sort itab2 by field.
LOOP at itab1.
itab_final-field2 = itab1-field2.
read table itab2 with key field = itab1-field binary search.
if sy-subrc = 0.
itab_final-field1 = itab2-field1.
endif.
append itab_final.
clear itab_final.
endloop.
This is how generally we populate final internal table with data from more than one internal tables. Performance wise this is better.
Sort and reading with binary search is effective.
And using read in loop is effective that loop inside a loop.
Regards
Vasu
09-28-2007 10:05 AM
Hi
there is no problem to put READ statement inside the LOOP
its a better way to put
to avoid SELECT in a LOOP
see this example
i had used that in my program
in the performance point of view it is a good method
LOOP AT IT_SOBID INTO WA_SOBID." where otype eq s_otype and objid eq s_objid.
READ TABLE IT_HRP1026 WITH KEY OBJID = WA_SOBID-SOBID OTYPE = WA_SOBID-SCLAS INTO WA_HRP1026.
IF SY-SUBRC EQ 0.
READ TABLE IT_HRP1000 WITH KEY OBJID = WA_SOBID-SOBID INTO WA_HRP1000.
WA_OUTPUT-OBJID = WA_HRP1026-OBJID.
WA_OUTPUT-BEGDA = WA_SOBID-BEGDA.
WA_OUTPUT-ENDDA = WA_SOBID-ENDDA.
WA_OUTPUT-AEDTM = WA_HRP1026-AEDTM.
WA_OUTPUT-UNAME = WA_HRP1026-UNAME.
WA_OUTPUT-STEXT = WA_HRP1000-STEXT.
READ TABLE IT_REASON WITH KEY CANCR = WA_HRP1026-CANCR INTO WA_REASON.
WA_OUTPUT-CANCRT = WA_REASON-CANCRT.
CLEAR WA_REASON-CANCRT.
READ TABLE IT_LOCATION1 WITH KEY OBJID = WA_HRP1026-OBJID INTO WA_LOCATION1..
READ TABLE IT_LSTEXT WITH KEY OBJID = WA_LOCATION1-SOBID OTYPE = 'F' INTO WA_LSTEXT.
WA_OUTPUT-LSTEXT = WA_LSTEXT-LSTEXT.
CLEAR WA_LSTEXT-LSTEXT.
APPEND WA_OUTPUT TO IT_OUTPUT.
CLEAR WA_OUTPUT.
CLEAR WA_OUTPUT-CANCRT.
ENDIF.
ENDLOOP.
<b>Reward if usefull</b>
09-28-2007 10:07 AM