Application Development 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: 

LOOP Vs READ TABLE

0 Kudos

Hello All,

When there is a Sorted Internal Table, is Looping and Fetching a single record is better or to use a READ TABLE with BINARY SEARCH.

Kindly advice.

Best Regards,

Kasi Raaman.R

1 ACCEPTED SOLUTION

ThomasZloch
Active Contributor
0 Kudos

For single records -> READ TABLE.

BINARY SEARCH is not necessary for sorted tables (declared as such!), it is already implicit when using addition WITH TABLE KEY.

Thomas

3 REPLIES 3

ThomasZloch
Active Contributor
0 Kudos

For single records -> READ TABLE.

BINARY SEARCH is not necessary for sorted tables (declared as such!), it is already implicit when using addition WITH TABLE KEY.

Thomas

naimesh_patel
Active Contributor
0 Kudos

Read table with the Binary Key will be better.

You can try this in SE30. Create two small programs and run the performance test.

Regards,

Naimesh Patel

former_member194613
Active Contributor
0 Kudos

If you can you should use sorted tables, because you get automatically the BINARY SEARCH fast and always correct.

Runtime of READ with key (full table key or only first fields) will be similar to LOOP WHERE (same fields).

So if the key is non-unique or you have only a part of the key it is also o.k.

Stanard table with BINARY SEARCH is slightly faster, but we are talking about microseconds, so forgetr the difference.

There you must take about the sorting, either you do it too often and waste a lot of time or to rarely with incorrect results.

=> If possible, then you should always use sorted tables!

Siegfried