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

SELECT statement

Former Member
0 Likes
687

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
660

Hi Sachin,

Ya, it will work. But in this you are not using XYZ table anywhere. Why you put that one.

regards,

Chandra.

7 REPLIES 7
Read only

Former Member
0 Likes
660

Yes, each select statement would retrieve one (or zero) record per loop pass.

Read only

Former Member
0 Likes
661

Hi Sachin,

Ya, it will work. But in this you are not using XYZ table anywhere. Why you put that one.

regards,

Chandra.

Read only

Former Member
0 Likes
660

hi Sachin,

Yes it retrieves only i record in each loop.

Regards,

Santosh

Read only

Former Member
0 Likes
660

Hey,

WHERE is U r WHERE condition ??

Sunanda

Read only

Former Member
0 Likes
660

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

Read only

Former Member
0 Likes
660

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.

Read only

former_member184495
Active Contributor
0 Likes
660

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.