Application Development 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: 

passing values from one table to another

former_member575017
Participant
0 Kudos

<Has nothing to do with ABAP Objects - moved to ABAP General. Please choose your forums more carefully in future>

Hi Experts,

I am using three tables in my program. From two table single field from each I need to pass into third table but before inserting the field values in third table i need to check if its present no need to insert else I need to insert. Even the two tables are not related at all. I used bellow code but I think its not efficient.. So plz any body help me and taking performance into an account.

select lifnr from tab1 into table it_tab1.

loop at it_tab1.

select zlifnr from tab3 into table it_tab3 where zlifnr = it_tab1-lifnr.

if sy-subrc = 0.

continue.

else.

tab3-zlifnr = tab1-lifnr.

insert tab3.

endif.

endloop.

select distinct sri from tab2 into table it_tab2.

loop at it_tab1.

select zsri from tab3 into table it_tab3 where zsri = it_tab2-sri.

if sy-subrc = 0.

continue.

else.

tab3-zsri = tab2-sri.

insert tab3.

endif.

endloop.

Is there any chance to combine both statements or quiry into one . plz help me.

Thanks

Basu

Edited by: Mike Pokraka on Sep 5, 2008 12:16 PM

1 ACCEPTED SOLUTION

former_member69765
Contributor
0 Kudos

Hi..

I will not give you the code... I will give you only hints on how to do it in better way...

1. The 2 tables ITAB1 and ITAB2 are different ... not related... so it can not be done in 1 loop for sure...

2. You are selecting inside a loop !! This is a heinous crime !! Its a major blow in performance.. because if you have 100 rows in a table.. then you are hitting DB 100 times !

Instead... Use SELECT FOR ALL ENTRIES and select in one shot all (related) entries into an internal table..

3. Now in side the loop... read internal table to check if the entry is already there or not !

IF not ... populate data into a new Internal table...

4. In the end .. from this new internal table... update data into DB in one shot !

3 REPLIES 3

Former Member
0 Kudos

Pls change your approach !!!! Select using for allentries instead od hitting the DB everytime , that would improve performance.

former_member69765
Contributor
0 Kudos

Hi..

I will not give you the code... I will give you only hints on how to do it in better way...

1. The 2 tables ITAB1 and ITAB2 are different ... not related... so it can not be done in 1 loop for sure...

2. You are selecting inside a loop !! This is a heinous crime !! Its a major blow in performance.. because if you have 100 rows in a table.. then you are hitting DB 100 times !

Instead... Use SELECT FOR ALL ENTRIES and select in one shot all (related) entries into an internal table..

3. Now in side the loop... read internal table to check if the entry is already there or not !

IF not ... populate data into a new Internal table...

4. In the end .. from this new internal table... update data into DB in one shot !

former_member575017
Participant
0 Kudos

thanks Varun