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: 

compare 2 tables and write it to returen table

Former Member
0 Kudos

HI ,

I am using this select and i want to compare between the user that i got to the select

and the user that is found after the select .

i.e. if i got 10 employees in it_userid and from it in the table Zd_DB_dc i found just

7 employees i want to write the 3 employee to LT_returen table .

What is the best way to do that (performance is important since es_dev can have more than 1000

users)

IF NOT it_userid[] IS INITIAL .

SELECT *

FROM Zd_DB_dc

INTO CORRESPONDING FIELDS OF TABLE es_dev

FOR ALL ENTRIES IN it_userid

WHERE userid = it_userid-userid.

Regards

Joy

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

You are fetching data rightly.

Now only thing is to use a looo on table it_userid and read second table inside it and after comparing the userids, you can pass the data into third table, which is missing putting some right condtions.

Like sy-subrc <> 0.

sort Zd_DB_dc by userid.

LOOP AT IT_USERID.

READ TABLE Zd_DB_dc WITH KEY USERID = it_user_id-userid.

if sy-subrc = 0.

move data from it_user into third internal table.

append LT_returen.

endif.

ENDLOOP.

Regds,

Anil

4 REPLIES 4

Former Member
0 Kudos

use left outer join ..so when u go result u will found null value in those 3 coulms bcz its only in one table so u pick those whose value is null due to the result of LEFT outer join.

Former Member
0 Kudos

Hi,

You are fetching data rightly.

Now only thing is to use a looo on table it_userid and read second table inside it and after comparing the userids, you can pass the data into third table, which is missing putting some right condtions.

Like sy-subrc <> 0.

sort Zd_DB_dc by userid.

LOOP AT IT_USERID.

READ TABLE Zd_DB_dc WITH KEY USERID = it_user_id-userid.

if sy-subrc = 0.

move data from it_user into third internal table.

append LT_returen.

endif.

ENDLOOP.

Regds,

Anil

Former Member
0 Kudos

Hi joy,

for performance improvement you neeed to follow the below points:

1.don't take all the fields using select *, instead of that decleare one structure with all the necessary fields.

2.don't use move corresponding fields of table, use into table itab.

3. for all entries is good for performance wise.

types: begin of t_userid

f1

f2

end of t_userid.

data: i_userid type standard table of t_userid,

wa_userid type t_userid.

if i_userid is not initial.

SELECT *

FROM Zd_DB_dc

INTO TABLEs es_dev

FOR ALL ENTRIES IN i_userid

WHERE userid = i_userid-userid.

then finally decleare one final structure with all the final output fields.

transfer data from these two internal table into final internal table.

Regards,

Tutun

Former Member
0 Kudos

Hi,

If you are trying to fetch the values in internal tables then:

select f1 f2 f3 from table1 ""First select query where zd_db_bc is an internal table

into table zd_db_dc

where condition.

select f1 f2 f3 from table2 ""Second select query where it_userid is an internal table

into table it_userid

for all entries in zd_db_bc

where f1 = zd_db_bc-f1.

If you are fetching the entries in 2 internal tables and later trying it to move to 3rd tab with some conditions use the below code:

sort it_userid by userid. ""By default it is ascending

loop at zd_db_dc into wa_zd-zd_db_dc.

read table it_userid into wa_userid with key ""For read statements it is good to specify the key fields

userid = wa_zd-zd_db_dc ""All the key fields ahsould be sorted and binary search shld

binary search. ""be included

check sy-subrc = 0.

if (if you have any condition to give for data to move in 3rd tab)

wa_return-userid = wa_userid-userid. ""Third internal table updated

endif.

append wa_return into lt_return.

clear: wa_return.

endloop.