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 endselect

Former Member
0 Likes
502

hi experts,

i wanted to know what exactly the below stmt does, i have an idea, but its vague, i am not sure about it. can some one tell me wat it does.

SELECT * FROM tvswz WHERE vstel = vbdkl-vstel.

SELECT SINGLE * FROM t001w WHERE werks = tvswz-werks.

EXIT.

ENDSELECT.

i think the first select stmt brings in all teh rows which satisfy the condition, the seconf select stmt brings in 1 row for each row selected above, but why is exit put there.

why is there end select for first stmt, not for the second select stmt.

thanks and regards.

sanju

2 REPLIES 2
Read only

Former Member
0 Likes
473

Hi,

Your understanding is almost right.

The pair;

SELECT * FROM tvswz WHERE vstel = vbdkl-vstel.

....

ENDSELECT.

act like a loop, processing each record from the database table that satisfies the WHERE condition, one record at a time.

SELECT SINGLE * FROM t001w WHERE werks = tvswz-werks.

then reads one row for the current row from the first table.

Regards,

Nick

Read only

matt
Active Contributor
0 Likes
473

The select... endselect begins a loop through the rows of the table that satisfy the condition. But the loop is only actually gone through once, because of the exit immediately after the select single. You get the first record from TVSWZ that has VSTEL eq VBDKL-VSTEK, then you get the t001w record that matches the ZVSWT-WERKS. Then the loop is exited - you don't go back into it and get the next record - that's what EXIT means.

So the program has exactly the same effect as:

SELECT SINGLE * FROM tvswz WHERE vstel = vbdkl-vstel.
SELECT SINGLE * FROM t001w WHERE werks = tvswz-werks.

matt