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: 

about binary search in standard table

raffinkira
Participant
0 Kudos

To improve the performance, we usually sort a standard table and do binary search when READ TABLE.

Does this only work on key fields that are specified in the table definition.

If I sort the table by a non-key field and do binary search, is it also helpful in performance improvement?

4 REPLIES 4

Former Member
0 Kudos

Hi Ming,

If you sort a table by a non-key field and use the same field in binary search then it will improve the perfomance.

Regards,

Noufal P

Former Member
0 Kudos

Hi Ming,

You may also think about a DDIC table type. There you can specify a primary key and secondary keys. Use this table types as your internal tables. Now you can READ your internal table by different keys.

Regards

Ewald

former_member206650
Active Participant
0 Kudos

hi ming,

my believe is that binary search by sorting non unique key will make the performance less that sorting with unique key field in internal table..

Former Member
0 Kudos

Dear Ming,

If you  sort the table by a non-key field and do binary search,

it is also helpful to improve the performance.

but You have to use same keys in read statement which you have used in sorting internal table.(k1, k2)

Eg.

SORT itab BY k1 k2.

then you have to use same key in read statement other wise it returns wrong result.

READ TABLE itab INTO wa_itab

WITH KEY k1 = itab2-k1

                  k2 = itab2-k2

BINARY SEARCH.

Please find below more points:

1. Don't forget to SORT internal table.

2. Arrange the fields in WITH KEY same with sorting.

3. Put SORT right before READ with BINARY SEARCH or before the loop stament to optimize

Thanks,

Vikas.