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

inner join inside a internal table loop

Former Member
0 Likes
1,802

Hello to all,

I have this internal table in which i have selected some records for particular coulms. For the rest of the colums i need to join 3 tables for the data. I had in mind, of looping the internal table and then having a inner join query and modifying the internal table(all inside the loop) Just wanted to know, whether its a qood practice performance wise ? IF not, what are the alternatives ..

Thanks,

Shehryar Dahar

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,156

Hi Shehryar,

Having a select query that too a join on three tables inside a loop is not a good idea at all. This way you will be querying your database as many times as you have rows in the internal table. This will be a big performance issue. To avoid this you can use a single select statement and use the addition FOR ALL ENTRIES IN <i><internal table>.</i> This way you will have only one query to the database. Also dont forget to check if your internal table contains any entries before doing the select.

Hope this help!

Regards,

Saurabh

6 REPLIES 6
Read only

Former Member
0 Likes
1,156

Hi,

Doing joins on tables is not a good practice as it slow down ur program execution in the production server.Better u use internal tables for that.Their is no restriction as how many internal tables u are using for that.But before using loop at internal table always write<b> check not itab[] is initial.</b> where <b>itab</b> is ur internal table name upon which u want to loop at.

plz reward points if helpful.

Thanks

Chinmay

Read only

Former Member
0 Likes
1,157

Hi Shehryar,

Having a select query that too a join on three tables inside a loop is not a good idea at all. This way you will be querying your database as many times as you have rows in the internal table. This will be a big performance issue. To avoid this you can use a single select statement and use the addition FOR ALL ENTRIES IN <i><internal table>.</i> This way you will have only one query to the database. Also dont forget to check if your internal table contains any entries before doing the select.

Hope this help!

Regards,

Saurabh

Read only

0 Likes
1,156

Hello,

But then i will have to use 'SELECT SINGLE' and 'FOR ALL ENTRIES' twice for retrieving data from 3 tables....right ?

Regards,

Shehryar Dahar

Read only

Former Member
0 Likes
1,156

hi

good

i dont think there is any need to loop the internal table,if you want to join the internal tables than you can directly join those three tables using the JOIN statement.

thanks

mrutyun^

Read only

Former Member
0 Likes
1,156

hi,

first use an single select stm for that particular column in the table after that use an inner join on the 3 table using for all enteries this wil solve ur prob i guess

reward if helpful

ravi

Read only

Former Member
0 Likes
1,156

shehryar,

say You have internal table ITAB.Already some columns are updated in internal table.say A,B,C,D.

To fill rest of the columns(E,F,G) you need inter join.

write the inner join of the table for all entries of itab where A eq itab-A.

LOOP ITAB.

READ TABLE ITAB1 WITH KEY X = ITAB-X.

IF SY-SUBRC EQ 0.

move ITAB record to I_FINAL.

move itab1 records to i_final.

append i_final.

clear i_final.

ENDIF.

ENDLOOP.

Don't forget to reward if useful...