Application Development and Automation 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: 
Read only

quick table seacrh...

Former Member
0 Likes
483

Hi all. I'm looping over itab_1 into wa_itab_1. I want to select a single row of data from itab_2 based on a value in wa_itab_1. I don't need to llop over both tables do I? Isn't there a more terse way of selecting the record from itab_2?

regards,

Mat

4 REPLIES 4
Read only

Former Member
0 Likes
451

read table itab_2 with key field1 = wa_itab_1-field1
                           field2 = wa_itab_1-field2.

If your table is sorted by field1 and field2, you can add the BINARY SEARCH option to speed up the read.


read table itab_2 with key field1 = wa_itab_1-field1
                           field2 = wa_itab_1-field2
                           binary search.

Message was edited by: Michael Malvey

Read only

0 Likes
451

Just to add to Michael's solution, add the words BINARY SEARCH to the READ statement.

read table itab_2 with key field1 = itab_1-field1
                           field2 = itab_1-field2
                                 <b> BINARY SEARCH</b>.


Regards,

Rich Heilman

Read only

Former Member
0 Likes
451

hi,

loop at tb1 into struct

read tab2 into struct2with key keyparam = struct-value.

if sy-subrc = 0.

row found

endif.

endloop.

grtz

Koen

Read only

Former Member
0 Likes
451

Hi,

You can use the read statement to get the corresponding single record of the second table.

read table itab_2 into wa_itab_2 with key field1 = wa_itab_1-field1

...

binary search.

When you are using binary search make sure you are sorting the internal table by the order of the fields which are used in the read statement.

using binary search is the quicker than the nomal read statement.

Regards,

Satya,