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

Read Table with OR condition

Former Member
0 Likes
53,709

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
Read only

Former Member
18,191

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
Read only

Former Member
0 Likes
18,191

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

Read only

Former Member
18,191

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

Read only

Former Member
0 Likes
18,191

You cant use AND and OR operators in read statement

better to use if statement

Read only

Former Member
18,192

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

Read only

0 Likes
18,191

Solution is working

Read only

Former Member
0 Likes
18,191

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..

Read only

Former Member
0 Likes
18,191

Hi,

you could use:

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

Regards

Mark-André

Read only

Former Member
0 Likes
18,191

Hi Babu ,

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

Regards

Arun

Read only

vishalshinde
Discoverer
0 Likes
18,191

solution is working