cancel
Showing results for 
Search instead for 
Did you mean: 

passing values from one table to another

former_member575017
Participant
0 Kudos

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

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member575017
Participant
0 Kudos

Thanks guys.

former_member192295
Active Contributor
0 Kudos

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.

former_member575017
Participant
0 Kudos

Hi,

Actually the tables tab1 and tab2 are not related with any common field to use join condition. If u provide an example with code that will be helpfull for me.

Thanks

Basu

former_member192295
Active Contributor
0 Kudos

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.

hemant_chahal
Contributor
0 Kudos

Where are you performing these queries?

Former Member
0 Kudos

you have to use joins or for all entries. search in abap forum