Skip to Content
author's profile photo
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 comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • author's profile photo
    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 comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    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 comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    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 comment
    10|10000 characters needed characters exceeded