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 with OR condition

Former Member
0 Kudos
43,578

how can i check "OR" condition in: Read table itab with key...

ie, Read Table itab With Key f1 = '1000' or f2 = '5000'.

pls give me the syntax............

1 ACCEPTED SOLUTION

Former Member
8,060

hiii

Read Table itab With Key f1 = '1000' .
 
if sy-subrc NE  0.
 
Read Table itab With Key f1 = '5000' 
endif.

reward if useful

thx

twinkal

9 REPLIES 9

Former Member
0 Kudos
8,060

hiiii

you can not use OR or AND in READ statement..

but you can do the same thing differently like below

Read Table itab With Key f1 = '1000' .

if sy-subrc <> 0.

Read Table itab With Key f1 = '5000' 
endif.

it will give you same result as you want to get.

reward if useful

thx

twinkal

Former Member
8,060

Hi

It can't do it, it needs to replace that statament with LOOP/ENDLOOP

LOOP AT ITAB WHERE F1 = '1000'
                               OR F2 = '5000'.
    EXIT.
ENDLOOP.

If you insert the EXIT into the loop, that statament will be like READ TABLE

Max

Former Member
0 Kudos
8,060

You cant use AND and OR operators in read statement

better to use if statement

Former Member
8,061

hiii

Read Table itab With Key f1 = '1000' .
 
if sy-subrc NE  0.
 
Read Table itab With Key f1 = '5000' 
endif.

reward if useful

thx

twinkal

0 Kudos
8,060

Solution is working

Former Member
0 Kudos
8,060

Hi,

You can use only '=' with read statement.

So it is best if you use two read statements to achieve your functionality like

Read Table itab With Key f1 = '1000' .

If sy-ssubrc eq 0.

  • continue with priocessing

else.

Read Table itab With Key f2 = '5000'

IF sy-subrc eq 0.

  • continue with priocessing

endif.

endif..

Former Member
0 Kudos
8,060

Hi,

you could use:

LOOP AT itab INTO wa WHERE f1 = '1000' OR f2 = '5000'.
* Do Something
ENDLOOP.

Regards

Mark-André

Former Member
0 Kudos
8,060

Hi Babu ,

I dont think that is possible when you use a read statement.

Regards

Arun

vishalshinde
Discoverer
0 Kudos
8,060

solution is working