‎2006 Mar 26 6:15 PM
Experts!!
The Read Table used in a loop make the same work like a SELECT SINGLE ?
Thanks!!
‎2006 Mar 26 6:24 PM
Carlos,
SELECT is from DATABASE and READ is for INTERNAL table.
Its not recommende to have a SELECT in the loop (even SELECT SINGLE). So, get all the data and do a READ TABLe.
Regards,
Ravi
note : please mark the helpful answers.
‎2006 Mar 26 6:31 PM
Yes I know that, but the Read table only read one line like the select single?
Thanks
‎2006 Mar 26 8:15 PM
That's correct; however, the READ statement can be used to retrieve data from the database. It's an obsolete form of the statement (doesn't work in OOP) and works like SELECT SINGLE. Do F1 on READ.
Rob
‎2006 Mar 27 7:39 AM
Hi Carlos,
To Add above:
<b>READ:</b>*
Read fetch one record from the internal table.
Using this reduces Database load and hence preffered.
Using read inside a loop is recommended due to avoid performance issues.
we can use the same read statement multiple times in the same program.
<b>SELECT SINGLE:</b>
This also retrieve one record but from Database table.
Using this increases Database load.
Using select inside a loop is not recommended due to performance issues.
we shouldn't use the same same select multiple times in the same program as this will increase the DB load.
Ideally we fill the internal table using select at the initial level and make use of the same in the program using the read statement.
Hope this will help you.
Cheers
Sunny
Rewrd points, if found helpful
‎2006 Mar 26 6:36 PM
select single is used to get data from a database table whereas READ is used to get data from an internal table.
yes , both of them read single value..whether inside a loop, or outside it..
Regards,
Bikash
‎2006 Mar 26 7:11 PM
Yes Carlos, you are right.. both the statements are comparable.. ie READ statement is to an itab what a SELECT SINGLE is to a database Table.
Regards,
Suresh Datti
‎2006 Mar 27 3:33 AM
Hello friend,
As you find in above answers, both the statements read table and select single does the same work
i.e. fetching one single record.
But here the difference arises.
read table fetches data from internal table which is stored in application server and performance wise its really good and added advantage if you use binary search along with read table.
select single also fetches single record but data is fetched from database and performance wise its bad as compared to read table. Your performance will deteoriate more if you dont specify the all primary keys with select single.
Hope, this clarifies your doubt.
Depending on your requirement,you have to choose whether to use select single or read table.
Regards,
Tarun
‎2006 Mar 27 7:37 AM
Hi,
Well most of the above messages explain about the difference between READ and SELECT SINGLE clearly.
READ is used to read from an internal table.
SELECT SINGLE is used to read a single record from a Database Table.
One of the situations where READ table is faster is shown below. This option is better and fast then using Nested loops.
loop at T_DATA into WA_DATA.
clear WA_LINES.
read table T_LINES into WA_LINES with key PLNNR = WA_DATA-PLNNR.
if sy-subrc eq 0.
append WA_LINES to T_FINAL.
endif.
endloop.
‎2006 Mar 27 11:13 AM
Hi Carlos,
READ statement is done aginst Internal table, wherein SELECT table is done against database.
If you use SELECT SINGLE / SELECT inside loop, every time databse operation would be done and the overhead goes to database server. So the performance becomes bad.
To aviod this we are just fetching the data from the database table using some conditions / for all entries, what ever it may be in to an internal table.
So that when you read this internal table insid a loop, everything would be processed in the application server. So thereby improving the performance.
Regs,
Venkat Ramanan