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

OR condition in key while reading internal table..

Former Member
0 Likes
5,452

Hello,

I want to reading internal table as follows:

READ TABLE i_cust WITH KEY domvalue = it_kna1-NAME1.

I want to read the same table with or condition in key like

domvalue = it_kna1-name1 or domvalue = it_kna1-name2.

How can I do or condition for Keys ?

Regards,

Rajesh

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,677

You can only use READ TABLE statement with equality condition.

You can achieve the desired result in the following way:


READ TABLE i_cust WITH KEY domvalue = it_kna1-NAME1.
if sy-subrc ne 0.
READ TABLE i_cust WITH KEY domvalue = it_kna1-NAME2.
 if sy-subrc = 0.
    PERFORM subroutine1.
 endif.
else.
  PERFORM subroutine1.
endif.

5 REPLIES 5
Read only

Former Member
0 Likes
2,678

You can only use READ TABLE statement with equality condition.

You can achieve the desired result in the following way:


READ TABLE i_cust WITH KEY domvalue = it_kna1-NAME1.
if sy-subrc ne 0.
READ TABLE i_cust WITH KEY domvalue = it_kna1-NAME2.
 if sy-subrc = 0.
    PERFORM subroutine1.
 endif.
else.
  PERFORM subroutine1.
endif.

Read only

0 Likes
2,677

In my case I will have value in either of fields, so I want to read the table with that key which has the value..

Read only

0 Likes
2,677

You can achieve the desired result in the following way:



READ TABLE i_cust WITH KEY domvalue = it_kna1-NAME1.
if sy-subrc ne 0.
READ TABLE i_cust WITH KEY domvalue = it_kna1-NAME2.
 if sy-subrc = 0.
    PERFORM subroutine1.
 endif.
else.
  PERFORM subroutine1.
endif.
 

Read only

0 Likes
2,677

Ok, then you could use a field symbol.

field-symbols: <fs_name> type any.

if it_kna1-NAME1 is not initial.
 assign it_kna1-NAME1 to <fs_name>.
elseif it_kna1-NAME2 is not initial.
 assign it_kna1-NAME2 to <fs_name>.
endif.

READ TABLE i_cust WITH KEY domvalue = <fs_name>.
if sy-subrc = 0.

endif.

Regards,

Rich Heilman

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,677

You must use a LOOP in this case.

loop at i_cust 
        where domvalue = it_kna1-NAME1
             or  domvalue = it_kna1-name2.
* Do something
exit.  " now exit if at least one line has been read
endif.

Regards,

Rich Heilman