‎2007 Oct 03 10:21 AM
Hi,
As per my requirement I should use READ statement for 7 times in a loop ( loop at itab). In every read statement I have to use only one field in "with key" addition.
Is it efficient to use READ multiple times ? Is there any alternative to do the same task?
Regards,
Subbu.
‎2007 Oct 03 10:22 AM
No there will not be any problem.
Read will read only one line. so no harm.
Reward if useful!
‎2007 Oct 03 10:22 AM
No there will not be any problem.
Read will read only one line. so no harm.
Reward if useful!
‎2007 Oct 03 10:23 AM
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.
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.
Regards
vasu
‎2007 Oct 03 10:23 AM
If the fields are different in the WITH KEY clause then copy internal tables accordingly.
No affect on performance if using binary search & sorting tables before the loop.
move : itab to itab1,
itab to itab2,
itab to itab3.
sort : itab1 by field1,
itab2 by field2,
itab3 by field3.
loop at ioutput.
read table itab1 with key field1 binary search.
read table itab2 with key field2 binary search.
read table itab3 with key field3 binary search.
endloop.
‎2007 Oct 03 10:25 AM
Hi Subba,
It is ok, if the no of values in the internal table is quite large where you are reading from. There is no efficiency issue in that case.
Regards,
Sheron
‎2007 Oct 03 10:38 AM
hI
IN LOOP YOU CAN USE ANY NUMBER OF READ STATEMENTS
IT WON'T EFFECT THE PERFORMANCE OF THE PROGRAM
INFACT IT IS THE BEST WAY TO WRITE
IN MY PROGRAM I HAD WRITEN LIKE THIS
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 USEFUL</b>