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

Former Member
0 Likes
11,833

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

ThomasZloch
Active Contributor
4,457

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

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.

10 REPLIES 10
Read only

ThomasZloch
Active Contributor
4,458

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

Read only

Former Member
0 Likes
4,457

HI,

neither of the syntax is supported by ABAP.

Read only

Former Member
0 Likes
4,457

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

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

Read only

Former Member
0 Likes
4,457

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

Read only

Former Member
0 Likes
4,457

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.

Read only

Former Member
0 Likes
4,457

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

Read only

naveen_inuganti2
Active Contributor
0 Likes
4,457

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

Read only

Former Member
0 Likes
4,457

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.

Read only

Former Member
0 Likes
4,457

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

Read only

Former Member
0 Likes
4,457

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.