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

Reading the internal table

Former Member
0 Likes
800

Hi Abapers ,

I have an internal table it_bsak .I have to read the internal table with the condition xragl field in it_bsak table should not be equal to 'X'.

READ TABLE it_bsak1 WITH KEY

lifnr = it_disb_output-fi_lifnr

xragl NE 'X'

BINARY SEARCH.

This statement is not working .

What is the correct statement to read from it_bsak table condition as xragl field not equal to 'X'.

Please help .

Jaga

8 REPLIES 8
Read only

Former Member
0 Likes
774

Hi

READ accepts only equality condition.

so use loop condition.

Loop at it_bsak where lifnr = it_disb_output-fi_lifnr 
                                   and xragl NE 'X' 

endloop.

regards,

madhu

Read only

former_member195383
Active Contributor
0 Likes
774

use the following

loop at it_bsak1 where lifnr = it_disb_output-fi_lifnr

and xragl NE 'X' .

:

:

:

endloop.

inside the loop u can make use of it_bsak1 for ur requirement...

Read only

Former Member
0 Likes
774

hi check this....

before loop use the sort table by the field used in the read statement ...and check

Read only

Former Member
0 Likes
774

Hi,

It appears you want to "code" this READ because you are already within a LOOP on table it_disb_output, hence trying to avoid loop within loop.

For this purpose, create another internal table of identical structure as it_bsak1 say it_bsak1_tmp.

Then before loop at it_disb_output do the following:


REFRESH it_bsak1_tmp.
APPEND LINES OF it_bsak1 TO it_bsak1_tmp.
DELETE it_bsak1_tmp WHERE xragl EQ 'X'.
SORT it_bsak1_tmp BY LIFNR.

Now within your loop, you can

READ TABLE it_bsak1_tmp WITH KEY lifnr = it_disb_output-fi_lifnr . because, the new table it_bsak1_tmp does not have any entries with xragl as 'X'.

Cheers,

Aditya

Read only

Former Member
0 Likes
774

Hi,

Which ever statement you use( Read or Loop ) depends on the records you have in the internal table. Moreover when you are using binary search to the read statement always " SORT the internal table with the fields given in the where condition ", otherwise the binary search will work in a wrong way.

ex:

sort it_tab by field1 field2.

read table it_tab into is_tab with key field1 = 'value'

field2 = 'value'

binary search.

Read only

Former Member
0 Likes
774

Hi Jagdish,

"NE" Not Equal Operator doesn't work in Read Statement.

Instead of doing this type use the Loop statement Logic.


Loop at it_bsak1  where lifnr = it_disb_output-fi_lifnr 
                                    xragl NE 'X' .

    <Play with your data>  

EndLoop.

&*******************Reward Point if helpful******************&

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
774

Try This

Sort it_bsak1 by lifnr ascending.

loop at it_disb_output.

READ TABLE it_bsak1 WITH KEY

lifnr = it_disb_output-fi_lifnr BINARY SEARCH.

if sy-subrc = 0.

if it_bsak1-xragl NE 'X'.

____________

endif.

endif.

Read only

Former Member
0 Likes
774

Hi,

First you should not use EQ, NE etc in read statement.

Sort it_bsak1 by lifnr ascending.

READ TABLE it_bsak1 WITH KEY lifnr = it_disb_output-fi_lifnr

*NOT xragl = 'X' *

BINARY SEARCH.

OR

Sort it_bsak1 by lifnr ascending.

READ TABLE it_bsak1 WITH KEY lifnr = it_disb_output-fi_lifnr

  • xragl <> 'X' *

BINARY SEARCH.