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

Read table mismatch

Former Member
0 Likes
952

Hi Experts,

I am looping at itab1 and then using read table itab2 as below:

sort itab1 by f1.

sort itab2.

loop at itab1 into wa1.

read table itab2 into wa2 with key f2 = wa1-f2 binary search. --> fails for matched entries

if sy-subrc eq 0.

...etc

endif.

endloop.

read table is showing sy-subrc ne 0 even when there are matched entries for field f2 in itab1 & itab2(when seen in debug mode) . f2 is not a primary field in the source table.

Can someone please help me?

Thanks

Dan

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
885
sort itab1 by f1.

sort itab2 by f2.  " add  F2 field here

loop at itab1 into wa1.
read table itab2 into wa2 with key f2 = wa1-f2 binary search. --> fails for matched entries
if sy-subrc eq 0.
...etc
endif.
endloop.

Hi Experts,

I am looping at itab1 and then using read table itab2 as below:

sort itab1 by f1.

sort itab2.

loop at itab1 into wa1.

read table itab2 into wa2 with key f2 = wa1-f2 binary search. --> fails for matched entries

if sy-subrc eq 0.

...etc

endif.

endloop.

read table is showing sy-subrc ne 0 even when there are matched entries for field f2 in itab1 & itab2(when seen in debug mode) . f2 is not a primary field in the source table.

Can someone please help me?

Thanks

Dan

6 REPLIES 6
Read only

Former Member
0 Likes
886
sort itab1 by f1.

sort itab2 by f2.  " add  F2 field here

loop at itab1 into wa1.
read table itab2 into wa2 with key f2 = wa1-f2 binary search. --> fails for matched entries
if sy-subrc eq 0.
...etc
endif.
endloop.
Read only

Former Member
0 Likes
885

Hi,

If you Binary search in read statement then Searching increase fast and efficiency will be increase.

Check your data once again.

Regards

Md.MahaboobKhan

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
885

Hi,

Try this.Before reading the table using binary search, it is advisable to sort the table.

sort itab1 by f2.

sort itab2 by f2.

loop at itab1 into wa1.

read table itab2 into wa2 with key f2 = wa1-f2 binary search.

if sy-subrc eq 0.

...etc

endif.

endloop.

Read only

Former Member
0 Likes
885

Hi,

Whenever a binary search is used in a Read statement, the internal table used in read statement should be sorted ascendingly based on the field which is used for matching.

In your case, sort the table itab2 using field F2.

Regards,

Prasana.

Read only

Former Member
0 Likes
885

done with sort itab2 by f2.

Read only

0 Likes
885

Dan - if Prashant solved your problem, maybe you should consider assigning him 'solved problem' rather than just 'helpful'.

Rob