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: 

read table issue

Former Member
0 Kudos

Hi Experts,

I have an issue with 'READ TABLE' statement in a program. I am reading an internal table "i_output". The issue here is, it is working fine with some

customers(kunnr) but not for others.

The code:

do.

clear i_output.

read line sy-index.

if sy-subrc <> 0.

exit.

endif.

check not i_output is initial.

read table i_output with key kunnr = i_output-kunnr

vbeln = i_output-vbeln

posnr = i_output-posnr binary search.

check sy-subrc = 0.

Here in 'sy-subrc' it's returning '0' for some customers and sometimes '8'.

Can anybody please let me know what is wrong with this.

Thanks much.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

SORT Table i_output first...since you are using binary search.

SORT i_output BY KUNNR VBELN POSNR.

read table i_output with key kunnr = i_output-kunnr

vbeln = i_output-vbeln

posnr = i_output-posnr binary search.

Sri

Message was edited by:

Sri Tayi

7 REPLIES 7

Former Member
0 Kudos

SORT Table i_output first...since you are using binary search.

SORT i_output BY KUNNR VBELN POSNR.

read table i_output with key kunnr = i_output-kunnr

vbeln = i_output-vbeln

posnr = i_output-posnr binary search.

Sri

Message was edited by:

Sri Tayi

Former Member
0 Kudos

Hi

SORTing of Internal is a must to use the BINARY search in read statement

So first SORT ITAB by KUNNR VBELN POSNR first

then use the READ statement as you wrote

then it will fetch the right records always

Regards

Anji

Former Member
0 Kudos

try this:

sort i_output by kunnr vbeln posnr.

read table i_output with key kunnr = i_output-kunnr

vbeln = i_output-vbeln

posnr = i_output-posnr .

check sy-subrc = 0.

This is something strange... how are you reading the same table with same conditions!!!!

Thanks,

SKJ

0 Kudos

I have already sorted the internal table. It's not working.

0 Kudos

Hi

Paste your code completely then it is easy to solve

Regards

Anji

0 Kudos

Thanks all. It works.

null

Former Member
0 Kudos

Other folks have coverd the need to sort.

Another issue can occur if the value you are using for kunnr is not properly formatted.

You may have to call

  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      input  = i_output-kunnr
    IMPORTING
      output = i_output-kunnr.

to ensure kunnr is properly formatted before doing the read.

As noted above, I think you need to post more of your code to put things in context.

Good luck

Brian