Skip to Content

How to use less or between as condition in read table clause ?

I have two internal tables IT_ITAB and IT_ZAFS_FI_01. In IT_ZAFS_FI_01 there are two range fields ZFIRAFR and ZFIRATO. I want to find for each RACCT and RFAREA in IT_ITAB whether exist in IT_ZAFS_FI_01 with RACCT in the range and RFAREA equal ZFIFUAR. I have code like below. But it has error. So in READ TABLE itab less or between as condition is not allowed? I have to use loop instead? Thx.

  SELECT
    RACCT  
    RFAREA  
    HSLVT 
   INTO  TABLE IT_ITAB
   FROM FAGLFLEXT
   WHERE RYEAR  = P_YEAR
   AND RLDNR  = '0L'
   AND RRCTY  = '0'
   AND RBUKRS = P_BUKRS.
SORT it_itab BY racct rfarea.

  SELECT
           BUKRS
           ZFIITEM
           ZFISUIT
           ZFITEXT
           ZFISIGN
           ZFITYPE
           ZFIRAFR
           ZFIRATO
           ZFIFUAR
           ZFIITFR
           ZFIITTO
   FROM ZTFI03
   INTO CORRESPONDING FIELDS OF TABLE IT_ZAFS_FI_01
   WHERE BUKRS = P_BUKRS .
LOOP AT IT_ITAB INTO data(IT_ITAB_l) group by ( key1 = IT_ITAB_l-racct  key2 =  IT_ITAB_l-rfarea ) .
     READ TABLE IT_ZAFS_FI_01 with key ZFIFUAR = IT_ITAB_l-rfarea ZFIRAFR < IT_ITAB_l-racct  ZFIRATO > IT_IT  AB_l-racct  . 
ENDLOOP.
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Posted on Jul 29, 2020 at 02:46 AM

    hi Ricky,

    yes, you can't use read along with operators like GE, LE. Better using Loop instead.

    WHILE and ENDWHILE is also supported, you can check this.

    regards,

    jimmy.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 29, 2020 at 04:27 AM

    ricky luo,

    You cannot use such logical operators in read statements. If you are reading the internal table with unique key field probably you can have IF Condition check after READ statement.

    Suggestion: Why don'y you use FOR ALL ENTRIES in your query and try using this less than condition using WHERE keyword.

    Regards!

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 29, 2020 at 06:28 AM

    You ask: READ TABLE itab less or between as condition is not allowed?

    YES

    You ask: I have to use loop instead?

    YES

    EDIT: instead of LOOP AT, if your internal table is of type SORTED (or is standard + sort + BINARY SEARCH), you may do an approximate positioning.

    Example:

    KEY   FR   TO  VAL
    FR    B    D   1
    FR    E    G   2
    FR    H    J   3
    GB    A    Z   4 

    Code:

    DATA itab TYPE SORTED TABLE OF ty_line WITH UNIQUE KEY key fr.
    ...
    READ TABLE itab WITH KEY key = 'FR' fr = 'F' TRANSPORTING NO FIELDS.
    DATA(index) = COND i( WHEN sy-subrc <> 0 THEN sy-tabix - 1 ELSE sy-tabix ).
    ASSERT index = 2. " just to demonstrate what is expected for F
    IF index > 0.
      DATA(line) = itab[ index ].
      IF line-key = 'FR'. " Important to test again the first part of the key
        " Right line is found
      ENDIF.
    ENDIF.
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 29, 2020 at 06:35 AM

    Try this.

      SELECT
        RACCT  
        RFAREA  
        HSLVT 
       INTO  TABLE IT_ITAB
       FROM FAGLFLEXT
       WHERE RYEAR  = P_YEAR
       AND RLDNR  = '0L'
       AND RRCTY  = '0'
       AND RBUKRS = P_BUKRS.
    SORT it_itab BY racct rfarea.
    
      SELECT
               BUKRS
               ZFIITEM
               ZFISUIT
               ZFITEXT
               ZFISIGN
               ZFITYPE
               ZFIRAFR
               ZFIRATO
               ZFIFUAR
               ZFIITFR
               ZFIITTO
       FROM ZTFI03
       INTO CORRESPONDING FIELDS OF TABLE IT_ZAFS_FI_01
       WHERE BUKRS = P_BUKRS .
    LOOP AT IT_ITAB INTO data(IT_ITAB_l) group by ( key1 = IT_ITAB_l-racct  key2 =  IT_ITAB_l-rfarea ) .
    LOOP AT IT_ZAFS_FI_01 WHERE ZFIFUAR = IT_ITAB_1-rfaera
                            AND ZFIRAFR < IT_ITAB_1-racct
                            AND ZFIRATO > IT_ITAB_1-racc.
    "Fill what you need
    EXIT. ENDLOOP. ENDLOOP.
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.