‎2008 Mar 06 4:59 PM
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
‎2008 Mar 06 5:08 PM
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
‎2008 Mar 06 5:35 PM
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