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

Can we use to select over an internal table.

Hi folks,

I have a requirment where i have to write select queries with in a loop, so its taking so much time to execute the program (i used this method since i can;t use READ to write complex queries).

Is there any other alternative to access data from an internal table using complex queries.

Thanks in Advance,

Bharath.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on May 03, 2004 at 04:05 AM

    Hi Bharath,

    Most of the queries which are written within a loop can be avoided by proper "Select" queries and using either LOOP..ENDLOOP or READ statement. Since you haven't mentioned your scenario, I hope the below scenario would be helpful to you.

    for eg:

    if scenario is

    LOOP at i_itab.

    select single db_field1 db_field2

    from database_table

    into (var_field1, var_field2)

    where db_field3 = i_itab-field1

    and db_field4 = '45'.

    ENDLOOP.

    The above code can be written better as :

    select db_field1 db_field2

    from database_table

    into table i_itab2

    where db_field4 = '45'.

    LOOP at i_itab1.

    READ TABLE i_itab2 with key db_field3 = i_itab1-field1

    ENDLOOP.

    In case, it is not an equal to (=) scenario, then you can use, the loop..exit..endloop.

    LOOP at i_itab1.

    LOOP AT i_itab2 where db_field3 > i_itab1-field1.

    EXIT.

    ENDLOOP.

    ENDLOOP.

    I hope you find this useful.

    Regards,

    Subramanian V.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 03, 2004 at 09:04 PM

    If I understand correctly, you want to run a SELECT statement using several rows of an internal table as WHERE clause criteria?

    If so, use the "FOR ALL ENTRIES IN " keywords in SELECT statement. Refer to SELECT statement in help.sap.com for details.

    Regards,

    D.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 04, 2004 at 06:02 AM

    Thanks Guys,

    My problem is solved. I used three read statements instead of on select query.

    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.