09-18-2008 11:45 AM
i m having the following scenario
loop at lit_hr into ls_hr .
select single pernr begda endda department from
pa9001 into ls_9001
where begda <= ls_hr-enda
and enda >= ls_hr-enda .
endloop .
as i cant get all the data outside the loop with for all enteries as read doesnot work with LE and GE only equal to works.
please let me know some possibility reagarding this .
Thanks
09-18-2008 11:49 AM
hiiiii
whatever u r doing is not prefer performance wise .
use for all entries ......wht kind of problen u r facing with for all entries...tell me?
09-18-2008 11:54 AM
Hi,
How can you now ensure that there will be only one record for this condition?
Anyway you can try in this way which is an alternative
select pernr begda endda department from
pa9001 into table lt_9001
for all entries in lt_hr
where begda le ls_hr-enda
and enda ge ls_hr-enda .
loop at lit_hr into ls_hr .
loop at lt_9001 where begde le ls_hr-begda
and enda ge ls_hr-enda.
endloop.
endloop.
This will give multiple or single entry satisfying that condition.
Cheers,
Kothand
09-18-2008 12:58 PM
thanks kothand but loop inside loop doesnot effect performance do let me know
thanks
09-18-2008 1:06 PM
Hi,
Definitely No for your case. 2 reasons for this,
1) Using a LOOP inside LOOP is much better than SELECT inside a LOOP.
2) The second loop has 2 conditions. so it will not go through all the records in that table. It will go into that loop only if it satisfies these conditions.
Cheers,
Kothand
09-18-2008 11:55 AM
loop at lit_hr into ls_hr .
select single pernr begda endda department from
pa9001 into ls_9001
where begda <= ls_hr-enda
and enda >= ls_hr-enda .
***************
append ls_9001 to <itab>.
*********
endloop .
hope so it will eork
09-18-2008 1:40 PM
Select within a loop will not visibily affect performance initially if only dealing with small amounts of data, but it is not good practice as often your system grows more data over time which gradually introduces performance issues. Especially when dealing with transactional data.
Also if you do a SELECT SINGLE ensure you use the full table key, otherwise you are not guaranteed a consistent & unique set of data being returned. Plus only the EQ operator will guarantee a single record as there could be many other values LT, GT, etc.
Just a few tips
09-19-2008 8:24 AM
so is it ok if i use loop inside loop as it will select only one record .
10-06-2008 8:36 AM