‎2006 Nov 03 2:56 PM
Hi All,
If I have a code as follows:
LOOP AT XYZ.
SELECT SINGLE Field1 INTO temp_field1 FROM table1.
SELECT SINGLE field2 field3 INTO (temp_field2,temp_field3) FROM table2
WHERE field4 = temp_field1.
ENDLOOP.
Does both the SELECT statements retrieve 1 record for each loop?
Thanks
‎2006 Nov 03 2:59 PM
Hi Sachin,
Ya, it will work. But in this you are not using XYZ table anywhere. Why you put that one.
regards,
Chandra.
‎2006 Nov 03 2:59 PM
Yes, each select statement would retrieve one (or zero) record per loop pass.
‎2006 Nov 03 2:59 PM
Hi Sachin,
Ya, it will work. But in this you are not using XYZ table anywhere. Why you put that one.
regards,
Chandra.
‎2006 Nov 03 3:02 PM
hi Sachin,
Yes it retrieves only i record in each loop.
Regards,
Santosh
‎2006 Nov 03 3:03 PM
‎2006 Nov 03 3:10 PM
Hi Guptha,
Yes it will retrieve only one record for each loop.
First thing dont write select statement in the loop.avoide select statement in the loop. try to read the internal table but dont select the internal table in the loop.its a performance issue.
Thanks
Vikranth Khimavath
‎2006 Nov 03 3:21 PM
The first SELECT statment does not have a WHERE condition. Supposing you do, then you may have to use a IF SY-SUBRC = 0 to perform the second SELECT statment.
If there is a common field in both tables, there is another way of doing the same is....
SELECT SINGLE t1Field1 t2field2 t2~field3
FROM table1 AS t1 LEFT JOIN table2 AS t2
ON t1Field1 = t2field4 <AND t2~fieldx = xxx>
INTO (temp_field1,temp_field2,temp_field3)
<WHERE t1~fieldX = XXX>.
Hope this helps you.
‎2006 Nov 03 4:10 PM
hi Sachin,
say for instance you XYZ internal table has a field say XYZ-f1,
then there is point in looping XYZ, so code would look like this :
-
LOOP AT XYZ.
SELECT SINGLE Field1 INTO temp_field1 FROM table1
where <table-field> = XYZ-f1.
SELECT SINGLE field2 field3 INTO (temp_field2,temp_field3) FROM table2
WHERE field4 = temp_field1.
CLEAR temp_field1.
ENDLOOP.
-
code could change if you could explain the complete requirement.
cheers anyways,
Aditya.