Skip to Content
avatar image
Former Member

READ internal table with two keys on same field

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

10 Answers

  • Best Answer
    Sep 22, 2008 at 08:42 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 22, 2008 at 08:47 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 22, 2008 at 08:43 AM

    HI,

    neither of the syntax is supported by ABAP.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 22, 2008 at 08:44 AM

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

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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 22, 2008 at 08:47 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 22, 2008 at 08:49 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 22, 2008 at 08:49 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 22, 2008 at 08:50 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 22, 2008 at 08:51 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 22, 2008 at 08:56 AM

    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.
    

    Add comment
    10|10000 characters needed characters exceeded