‎2011 Apr 13 1:30 PM
Hi all,
I am joining my three tables using the inner join..
here is code
Select aempid bdeptid
into corr fields of table lt_emp
from ( emp as a INNER JOIN dept as b
ON ( bdeptid = adeptid ) )
INNER JOIN loc as c
ON ( bdeptid = adeptid )
WHERE a~depid EQ lt_dept-deptid.
deptid is present in all three tables but still my lt_emp table is coming empty...
Can anyone suggest me any other way of joining three tables with only one select query..
Thanks n Regards,
Dhiraj B.
‎2011 Apr 13 2:33 PM
Hi
use this.
if it_dept is not initial.
Select aempid bdeptid
into corr fields of table lt_emp
from ( emp as a INNER JOIN dept as b
ON ( bdeptid = adeptid ) )
INNER JOIN loc as c
ON ( cdeptid = bdeptid )
for all entries in it_dept
WHERE a~depid EQ lt_dept-deptid.
endif.
because in your code you are checking deptit from table it_dept in where condition,
which will contain only the last values stored in the header of table it_dept.
this is why i have used for all entries here.
thi for all entries will fetch the data from all the table for all the values matches in table it_dept.
try this and i hope this will work for you.
thanks
LG
‎2011 Apr 13 4:15 PM
It should be something like this:
SELECT SINGLE amatnr cwerks
INTO (l_matnr , l_werks)
FROM mara AS a INNER JOIN makt AS b
ON ( amatnr = bmatnr )
INNER JOIN marc AS c
ON ( bmatnr = cmatnr )
WHERE a~matnr EQ l_matnr1.
IF sy-subrc = 0.
ENDIF.
For your query the second on condition is not correct.