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 internal table with two keys on same field

Former Member
0 Kudos

Hi experts.

I'm trying to read an internal table to two values but apparently i can't use the keyword OR.

Here is what i tryed. Can anybody tell me what is the correct instruction to use ?

Thanks for your help.


* Test 1
  READ TABLE lt_status INTO wa_status 
    WITH KEY txt04 =  ( c_wait_exp OR c_expert ).

*Test 2
  READ TABLE lt_status INTO wa_status 
    WITH KEY txt04 =  c_wait_exp.
   OR txt04 = c_expert.

Both are incorrects.

1 ACCEPTED SOLUTION

ThomasZloch
Active Contributor

READ is supposed to return a single entry, so there is a logical problem with using OR conditions. That's why they are not allowed.

See if you can use LOOP AT ... WHERE ... instead.

Thomas

10 REPLIES 10

ThomasZloch
Active Contributor

READ is supposed to return a single entry, so there is a logical problem with using OR conditions. That's why they are not allowed.

See if you can use LOOP AT ... WHERE ... instead.

Thomas

Former Member
0 Kudos

HI,

neither of the syntax is supported by ABAP.

Former Member
0 Kudos

You cannot use "AND" or "OR" in READ TABLE.

You have to use "LOOP AT" to use the OR condition.

Former Member
0 Kudos

Hi

Use range , Firsttly declare oa variable of type range . Now pass both of your constants in ranhe as

Data ; l type range .

pass both of your constants in range (For help see SAP Help)

now

READ TABLE lt_status INTO wa_status

WITH KEY txt04 in l .

~hitesh

Former Member
0 Kudos

Hello,

You have to use READ statement twice.

Like

READ TABLE lt_status INTO wa_status

WITH KEY txt04 = c_wait_exp.

IF sy-subrc NE 0.

READ TABLE lt_status INTO wa_status

WITH KEY txt04 = c_expert.

IF sy-subrc NE 0.

Give u r error message here.

ENDIF.

ENDIF.

IF one of the statement is true , do u r processing after that.

Hope it solves u r problem.

Thanks,

Chandra.

Former Member
0 Kudos

Hi Helder,

Both of the syntax are wrong. No OR operator is not supported in READ Statement.

Try using LOOP AT <itab> WHERE <condition> where you can use OR condition.

Regards,

Chandra Sekhar

naveen_inuganti2
Active Contributor
0 Kudos

Hi ..

If fields are different don't use opertors...

do like this..,

> read table itab with key field1 = 'gfhg' field2 = 'fhbrsjf'.

But, for the same filed its not possible.!!

Thanks,

Naveen.I

Former Member
0 Kudos

Hi,

With READ table you can not use same field more than one time for comparison.

You can get this functionality using LOOP ....Endloop.

Like-

Data:itab like standard table of sflight,

wa like line of itab.

Loop at itab into wa where carrid = 'AA' or carrid = 'AB'.

endloop.

Former Member
0 Kudos

Hi Helder,

You can not use expression with logical operators and other relational operators except '=' in READ statement.

So you need to query with the first value then if it fail then query with second value.


  READ TABLE lt_status INTO wa_status 
    WITH KEY txt04 =  c_wait_exp.

  IF SY-SUBRC EQ 0.
     <<Required logic>>
  ELSE.
 
  READ TABLE lt_status INTO wa_status 
    WITH KEY txt04 = c_expert.
   IF SY-SUBRC EQ 0.
     <<Required logic>>
   ENDIF.
ENDIF.

Thanks,

Vinay

former_member212653
Active Contributor
0 Kudos

try this:


data: flag1 type c length 1,
        flag2 type c length 1.

READ TABLE lt_status INTO wa_status 
    WITH KEY txt04 =  c_wait_exp .
if sy-subrc = 0.
 flag1 = 'X'.
endif.
READ TABLE lt_status INTO wa_status 
    WITH KEY txt04 =  c_expert.
if sy-subrc = 0.
 flag2 = 'X'.
endif.

if flag1 = 'X' or flag2 = 'X'.
 " Write your code here
endif.