Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Reg: select statement

Former Member
0 Likes
459

Hi friends,

Iam getting a list of fields into internal table.

I have to fetch records from database using those fields, in where condition. How to put all those fields in where condition

from that internal table.

Performance wise we must not put that select statement in loop, then whats the solution.

Thankyou,

Ramesh.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
440

Hi Ramesh,

You can use FOR ALL ENTRIES.

Declare another internal table with the fields you want to select from database table, eg:, itab2.

Then select the fields from the database table say, dbtab, using for all entries from the first internal table eg: itab1.

Select field1,
          field2,
          --
          fieldn
from <dbtab>
into table <itab2>
for all entries in <itab1>
where field1 = itab1-field1
         field2 = itab1-field2
         --
         fieldn = itab1-fieldn.

Hope this helps you.

Any queries, get back to me.

Regards,

Chandra Sekhar

3 REPLIES 3
Read only

Former Member
0 Likes
441

Hi Ramesh,

You can use FOR ALL ENTRIES.

Declare another internal table with the fields you want to select from database table, eg:, itab2.

Then select the fields from the database table say, dbtab, using for all entries from the first internal table eg: itab1.

Select field1,
          field2,
          --
          fieldn
from <dbtab>
into table <itab2>
for all entries in <itab1>
where field1 = itab1-field1
         field2 = itab1-field2
         --
         fieldn = itab1-fieldn.

Hope this helps you.

Any queries, get back to me.

Regards,

Chandra Sekhar

Read only

Former Member
0 Likes
440

Hi pagidala Ramesh,

Get the all data from database into internal table.

Now loop the first internal table and read the second internal table by checking those fields. and populated the records in another table.

or delete the records if the condition is not met in the second internal table.

Fetching the data once from database is better then hitting the database several times.

Best regards,

raam

Read only

Former Member
0 Likes
440

Hi,

Use FOR ALL ENTRIES in this kind of scenario.

Use this type of select query


SELECT carrid
       connid
       fldate
  FROM sflight
  INTO TABLE t_flight
  FOR ALL ENTRIES IN t_spfli
 WHERE carrid = t_spfli-carrid
   AND connid = t_spfli-connid.

Regards

Abhijeet