Skip to Content
author's profile photo
Former Member

read table issue

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.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • Best Answer
    author's profile photo
    Former Member
    Posted on Sep 28, 2007 at 08:45 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Sep 28, 2007 at 09:25 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Sep 28, 2007 at 08:50 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Sep 28, 2007 at 08:57 PM

    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

    Add comment
    10|10000 characters needed characters exceeded