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

Read statement

Former Member
0 Likes
756

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
732

No there will not be any problem.

Read will read only one line. so no harm.

Reward if useful!

5 REPLIES 5
Read only

Former Member
0 Likes
733

No there will not be any problem.

Read will read only one line. so no harm.

Reward if useful!

Read only

Former Member
0 Likes
732

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

Read only

Former Member
0 Likes
732

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.

Read only

Former Member
0 Likes
732

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

Read only

Former Member
0 Likes
732

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>