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 statement not working inspite Internal tables having data

0 Kudos

Hi all,

I have two select queries on QBEW and PRPS table and both the selects have data.

QBEW - matnr,bwkey,bwtar,sobkz,pspnr

PRPS - pspnr,objnr,psphi

Now do a read statement:

READ TABLE lt_qbew INTO DATA(lw_qbew) WITH KEY pspnr = lw_prps-pspnr
bwkey = so_werks BINARY SEARCH.

I have sorted lt_qbew with both pspnr and bwkey.

Yet my read statement is failing. Pls Help.

1 ACCEPTED SOLUTION

FredericGirod
Active Contributor
READ TABLE lt_qbew INTO DATA(lw_qbew) 
     WITH KEY pspnr = lw_prps-pspnr
              bwkey = so_werks 
     BINARY SEARCH

Next time use the [CODE] button to put ABAP Code.

It is a non-sens to make a single read, with binary access, and to specify a range of plant (werks). Because you could have several value in plant, the binary reading is not possible.

Change the way of doing it with a LOOP and and EXIT:

LOOP AT lt_qbew 
     INTO DATA(lw_qbew)
     WHERE pspnr EQ lw_prps-pspnr
     AND   bwkey IN so_werks.
  EXIT.
ENDLOOP.
4 REPLIES 4

satvik_panchal
Participant
0 Kudos

Please refer the below link :

Read Statement with Select Options

0 Kudos

That is a link with the right answer, but that makes the forum a jungle for future search https://blogs.sap.com/2013/11/08/posting-links-and-the-jungle-you-end-up-in/

FredericGirod
Active Contributor
READ TABLE lt_qbew INTO DATA(lw_qbew) 
     WITH KEY pspnr = lw_prps-pspnr
              bwkey = so_werks 
     BINARY SEARCH

Next time use the [CODE] button to put ABAP Code.

It is a non-sens to make a single read, with binary access, and to specify a range of plant (werks). Because you could have several value in plant, the binary reading is not possible.

Change the way of doing it with a LOOP and and EXIT:

LOOP AT lt_qbew 
     INTO DATA(lw_qbew)
     WHERE pspnr EQ lw_prps-pspnr
     AND   bwkey IN so_werks.
  EXIT.
ENDLOOP.

matt
Active Contributor
0 Kudos

1. Use a SORTED table.

2. Use ORDER BY in the select.