Binary search for Sorted table ?

Question:
Hi,
If I have a sorted table, and use a read statement on the sorted table, does it by default use binary search ? Or do I have to explicitly speicify Binary search ?
Answer:
Dear SAP_KP:
My guess would be you still have to specify it, since you may want to read the table with a partial key, too. But to be sure, write a quick ABAP to fill an itab with a million records and do a few (say 10,000) reads with and without binary search specified. If the run time over a couple of executions is similar, it is implied. If not, it is not.
What a sorted table buys you is that you can rely on its sort without worrying about it explicitly, and - if I am not mistaken - you cannot have duplicates with the same key. Personally, I find the advantages so minimal that I rarely use this type.
Regards,
Wolfgang
Answer:
If your table is defined as a SORTED TABLE, then any read is automatically a binary search as long as you use the entire key and the syntax
READ TABLE itab WITH TABLE KEY ....
Sorted table is not necessarily unique, it depends if you define it as SORTED TABLE WITH UNIQUE KEY ...
I find sorted or hashed tables really useful where there are regular reads and inserts on the internal table (ie database buffering implemented in the program).
Sorted table also forces sorting, so if the program is changed later then there is no way that the sorting can change and inadvertently stuff up existing code.
Additionally, SAP is smart enough that if you do a SELECT... INTO TABLE itab ... and itab is type sorted table, then the resulting table is already sorted.
Michael
Answer:
Also..... if you LOOP ...WHERE with a Sorted table, the partial index is still used whereas with a standard table, LOOP... WHERE always uses a full table scan every time which is much slower on large data-sets.

More Articles:

call rfc from java, websphere?
Re: How to pass results from one program to another?
class?
Database field for release startegy(CEKKO_USRC1)?
getting message as Plant data for material locked by user?
How to retrieve data from SAP hierarchies.?