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 With Key not working

Former Member
0 Likes
4,430

The code is:

READ TABLE gt_findpartners WITH KEY

z3isptrxtyp = wa_z3isp_inv_conv-z3isptrxtyp

z3ispordno = wa_z3isp_inv_conv-z3ispordno

BINARY SEARCH TRANSPORTING NO FIELDS.

Odd because at one time I believe the code was working fine, not sure vwhat I could have changed to stop this from working. But the rec is definitely in the tab it is reading and I get a sy-sub = 4.

Thank-You

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,167

Hi,

Remove the Binary Search.....

It will work...

Regards,

Kunjal

Hi,

Remove the Binary Search.....

It will work...

Regards,

Kunjal

9 REPLIES 9
Read only

Former Member
0 Likes
2,167

When using binary search you need to sort the table on the fields you are using as a key.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,167

check whether you have sorted gt_findpartners by z3isptrxtyp and

z3ispordno

if not sort it before reading it using binary search.

Read only

rainer_hbenthal
Active Contributor
0 Likes
2,167

The table is not sorted. Binary search is failing because of that.

Read only

Former Member
0 Likes
2,167

Hello,

To use the binary search you need to have a sorted table by the keys that you want to search.

Regards.

Read only

Former Member
0 Likes
2,167

Ignore, if you already used the SORT on the key fields.

It is always must to sort the table before binary search.

SORT gt_findpartners by z3isptrxtyp  z3ispordn.

READ TABLE gt_findpartners WITH KEY
z3isptrxtyp = wa_z3isp_inv_conv-z3isptrxtyp
z3ispordno = wa_z3isp_inv_conv-z3ispordno
BINARY SEARCH TRANSPORTING NO FIELDS.

Read only

Former Member
0 Likes
2,168

Hi,

Remove the Binary Search.....

It will work...

Regards,

Kunjal

Read only

Former Member
0 Likes
2,167

I hope your would have sorted the internal table if not sort it by the key fields.

If the addition TRANSPORTING NO FIELDS is used, the statement READ TABLE only checks whether the line that is being searched for exists, and fills the system field sy-subrc and sy-tabix. The system can then no longer access the content of the found fields.

So if you get sy-subrc eq 4 that record is not available in the internal table.

they record in the itab might have a prefix zero's or the value you r passing might have so it would result sy-subrc eq 4.

Thanks,

Karthik

Read only

Former Member
0 Likes
2,167

Hi,

READ TABLE gt_findpartners WITH KEY
z3isptrxtyp = wa_z3isp_inv_conv-z3isptrxtyp
z3ispordno = wa_z3isp_inv_conv-z3ispordno
BINARY SEARCH TRANSPORTING NO FIELDS.

Once remove binary search and check the sy-subrc value,

if sy-subrc value is 0 then sort the table before read as all said.

Regards

Adil

Read only

Former Member
0 Likes
2,167

Hi,

Binary Search can be used only once the sorting is performed in the internal table . sort the internal table or remove the binary search while reading.

Regards

Nanda Kishore