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

selecting records from itab1 with respect to itab2

Hi Friends,

i want to select all the matching records from itab2 with respect to one field in itab1.how can i do this... currently im using loop inside a loop.can v do the same with read statemant?is tr any thing similar to "for all entries in itab1 in select statement". or is tr any other way to do this?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Nov 23, 2007 at 01:05 PM

    Hi...

    try this.. it will work..

    define some extra flag field in itab2.

    loop at itab1.

    itab2-flag = 'X'.

    modify itab2 where field eq itab1-field transporting flag.

    endloop.

    delete itab2 where flag ne 'X'.

    Now itab2 contains only the required records..

    Please do remember to close the thread when ur problem is solved !!! reward for helpful answers !!

    Regards,

    Sai Ramesh

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 23, 2007 at 01:08 PM

    sort : iatb1,itab2.

    loop at itab1.

    read table itab2 with key val = itab1-val.

    if sy-subrc EQ 0.

    itab3 = itab1.

    append itab3.

    clear itab3.

    endif.

    endloop.

    now itab3 will contain only those records from itab1 where there is a match in itab2 with respect to field VAL

    reward if answered

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 23, 2007 at 01:14 PM

    There is no read for all entries for internal tables.

    You can use

    Loop at itab1.

    Loop at itab2 where field = itab1-field.

    <your code>

    Endloop.

    Endloop.

    Hope it helps.

    Lokesh

    Message was edited by:

    Lokesh Aggarwal

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 23, 2007 at 01:14 PM

    Hi Sasi,

    Do like this, This is how you should do to improve the performance for loop inside loop.

     sort itab2 by f1.
     loop at itab1 into wa1.
      read table itab2 into wa2 with key f1 = wa1-f1 binary search.
      if sy-subrc = 0.
       loop at itab2 into wa2 from sy-tabix.
         if wa2-f1 NE wa1-f1.
           Exit.
         endif.
        Move wa2 data to another internal table.
       endloop.
      endif.
     endloop.

    <b>Reward Points if this helps,</b>

    Satish

    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.