on 09-05-2008 11:10 AM
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, I am bit new to this field.
Thanks
Basu
Thanks guys.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Follow below logic
1.Use simple select statement with join and move values into internal table1.
2. Again make select statement for target table and move all records to internal table2.
3. Make loop for internal table 1
under loop again put loop for internal table2
compare values, if exit skip record else execute insert statement.
finally update target table
Alternative way is no need to compare values under loop pass all values from source internal table to target table. Finally execute delete adjacent statement, this statement delete all duplicate 2nd record.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI,
In SAP as per my experience each table relation with another table through field, if no relation mean do below procedure
1. Take internal table for tab1
2. Take internal table for tab2
3. Take internal table for target structure
3. Move tab1,tab2 structure to target structure
after that execute delete adjacent duplicate statement, for delete duplicate record.
Where are you performing these queries?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you have to use joins or for all entries. search in abap forum
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.