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 statement with multiple key values

Former Member
0 Likes
4,405

How can we write in read statement with one field multiple key values ...

How to write the statement can any one help

I wrote like the below code but those are not working.

1.Read table itab into wa with key = 's' or 'n'.

2.read table itab into wa with key = (' s' or 'no' )

Thanks in advance,

Shivani.

4 REPLIES 4
Read only

nomssi
Active Contributor
3,180

you can't use a single READ TABLE for this task. Try

LOOP AT WHERE condition.  
  EXIT.
ENDLOOP.

you can check sy-subrc after the LOOP.

Also try to push this logic to your database query.

JNN

Read only

former_member1716
Active Contributor
0 Likes
3,180

Hello,

You cannot write a statement as such.

Instead you can prioritize your key values, for example if you feel reading the internal with Key value S is your first priority then you can read the same. If The read is successful then proceed else read the same table again with N. Below snippet is for reference.

Read itab into WA with key field = S.

If sy-subrc eq 0.

Proceed.

Else.

Read table into wa with key field = N.

End if.

In case your priority is reversed then use the vice versa of the same as given above.

Kindly note you cannot use OR condition in read statements.

Regards

Read only

Nawanandana
Active Contributor
3,180

Hi,

I think if you search in this forum you can find the answer.

Read only

Former Member
0 Likes
3,180

READ TABLE is used to process single record.

You may try with LOOP AT WHERE clause.

Previously it was done with

READ TABLE itab { { }               
| { WITH KEY dobj }
| { WITH KEY = dobj } } [BINARY SEARCH] result.

This is obsolete now. You can read more on Binary search and alternatives here.