‎2012 Nov 12 5:50 PM
Hi all,
Could you tell me please that what is the difference between select and endselect.
1- select a b c from table xy into itab where a = 1.
2 select a b c from table xy into itab where a = 2.
endselect.
Moderator message: FAQ, please search for information before posting.
Message was edited by: Thomas Zloch
‎2012 Nov 12 6:26 PM
Select
Endselect
it work's like a Loop and Endloop.
Where as Select will retrive all the values at once.
‎2012 Nov 12 7:32 PM
As Naresh stated, SELECT ... ENDSELECT works like LOOP ... ENDLOOP, whereas SELECT retrieves all values at once. There are some important considerations though.
- In your examples, statement 1 will not compile. When using the Select statement without EndSelect, you need to either specify SELECT SINGLE ... INTO ... (meaning that only one record from the database will be returned, and it will be populated into the structure you provide) or, you need to specify SELECT ... INTO TABLE ... (meaning that all records are returned, and populated into the internal table you provide.) You can also use APPENDING TABLE instead of INTO TABLE if you don't want to overwrite the internal table.
- SELECT ... ENDSELECT uses a database cursor to interate through the rows that match your query. Because of this, you cannot use the COMMIT WORK or ROLLBACK WORK statements, because they would close the database cursor.
In general I think using the SELECT without the ENDSELECT is the better practice. I never use SELECT ... ENDSELECT in my code.
‎2012 Nov 13 3:54 AM
Select * into ITAB is faster. Select Endselect is slower.
Also, Select Endselect locks table for the entire processing time. Hence, it is better to use Select Into ITAB.
You can go to SE30 -> Utilities -> Tips and Tricks for more details.