Skip to Content
author's profile photo Former Member
Former Member

Compare Range with internal table

Hello Friends,

I need to compare an internal table with range , that in this internal table same value as in range, and if any value does not match-> has to do other functionality and if match other logic,

I was just curios to know , is there any elegant way of doing so, or that traditional coding means loops over internal table and then inside the loop again loop for range ??

if you guys have an alternative suggestion, would be really appreiciated.

Thanks in advance

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • Posted on Jun 08, 2006 at 12:17 PM

    YOu can do this way.

    loop at itab where field1 in range1.

    do what you want.

    endloop.

    loop at itab where not field1 in range1.

    do what you want.

    endloop.

    REgards,

    Ravi

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 08, 2006 at 12:20 PM

    hi

    u can do like this

    loop at itab where field1 in range

    //code

    endloop

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 08, 2006 at 12:20 PM

    I misundersttod to select first, check this oneo

    <b> LOOP AT IT_T001 WHERE BUKRS IN S_BUKRS.</b>

    IF SY-SUBRC = 0.

    IT_VBRK-BUTXT = IT_T001-BUTXT.

    MODIFY IT_VBRK INDEX CTAB.

    CLEAR CTAB.

    ENDIF.

    ENDLOOP.

    S_BUKRS is the range

    <b>

    please reward points if found helpful</b>

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 08, 2006 at 12:20 PM

    HII SHAH,

    i'm not sure if your query is with select options or ranges in particular ..

    select-options are explictly for selection-screen.

    If we dont want to display anything on screen,

    we can use RANGES having the same functionality ,same structure .

    Select options are displayed on the selection screen . Ranges are not displayed on the sel. screen.

    Be Careful with range table. The size of statement might exceed the limit depending on the size of the range table!

    Data: Ranges ran_field1 for dbtable1-field1.
    
    Select * from dbtab1 into table itab1.
    ran_field1-sign = ‘I’. 
    ran_field1-option = ‘EQ’.
    
    Loop at itable1 where itable1-field1 in ran_field1 .
    Move itable1-field1 To ran_field1-low.
    Append ran_field1.
    EndLoop.
    
    Loop at itable1 where not itable1-field1 in ran_field1 .
    Select * from dbtable2 where field2 in ran_field1.
    ... 
    EndSelect.


    endloop.

    </b>

    Reward points if helpful

    Revert back for more help.

    Regards

    Naresh

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Shah,

      If I understood your requirement correctly, then at least one loop is must.

      Loop at lt_itab into lw_itab.

      if lw_itab-rangefield IN Range1.

      • Do something here

      else.

      • Do else part

      endif.

      endloop.

  • Posted on Jun 08, 2006 at 12:29 PM
    LOOP AT ITAB WHERE FIELD IN S_FIELD.
    
    "Here you can do what ever you want..
    
    
    ENDLOOP.

    Regards

    vijay

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 08, 2006 at 12:45 PM

    Hi shah,

    1. Unfortunately we have to LOOP

    at every record,

    and check IN Range.

    2. Like this.

    LOOP AT ITAB.

    <b> IF FIELD NOT IN MYRANGE.</b>

    *---- CODE.

    ENDIF.

    ENDLOOP.

    regards,

    amit m.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      okey, friends many thanks for your kind inputs, actually I did now like following:

      delete lt_kna1 where not land1 in s_land. " RANGE

      Loop at lt_kna1 into ls_kna1.

      Loop at lt_vbpa into ls_vbpa where kunnr eq ls_kna1-kunnr.

      ls_c_vbpa-vbeln = ls_vbpa-vbeln.

      append ls_c_vbpa to lt_c_vbpa.

      Endloop.

      Endloop.

      So actually I want to delete not same entries from internal table and range,

      What about comapring the two internal tables, as the example i given above, is there any more efficient way of doing the same ?

      Thanks in advance,

      Regards.

  • author's profile photo Former Member
    Former Member
    Posted on Jun 08, 2006 at 02:19 PM

    hii shah,

    <b>delete lt_kna1 where not land1 in s_land. " RANGE
    
     Prepare for Binary Search
    sort IT_KNA1 by KUNNR.
    
    loop at IT_KNA1 .
    
    read table IT_VBAP with key kunnr = IT_KNA1-KUNNR binary search.
    
    if IT_VBAP-KUNNR <> IT_KNA1-KUNNR.
    
    DELETE IT_KNA1 .
    
    endif.
    
    Endloop.</b>

    REWARD POINTS IF HELPFUL

    Regards

    Naresh

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 08, 2006 at 02:22 PM

    Hi,

    Try this this works much faster,

    delete lt_kna1 where not land1 in s_land. " RANGE

    <b>sort lt_vbpa by kunnr</b>

    Loop at lt_kna1 into ls_kna1.

    read table lt_vbpa with key kunnr eq ls_kna1-kunnr binary serach.

    if sy-subrc = 0.

    Loop at lt_vbpa into ls_vbpa from sy-tabix

    if ls_vbpa-kunnr <> ls_kna1-kunnr.

    exit.

    endif.

    ls_c_vbpa-vbeln = ls_vbpa-vbeln.

    append ls_c_vbpa to lt_c_vbpa.

    Endloop.

    endif.

    Endloop.

    Sreedhar

    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.