09-12-2008 7:37 AM
Hi people,
I have a requirement where i have to fetch data from 2 table EKKO and EKPO for which the common field is EBELN. I want to use inner join for these tables. So, I have given EBELN field in the join condition. I also need to give a condition in the WHERE clause saying EBELN in EBELN value in the selection-screen parameter. Since we have 2 conditions given for the same field i.e., EBELN, it gives an error. How would I overcome this problem having in mind that both the conditions must be satisfied.
09-12-2008 7:49 AM
Hi,
use table name in where clause.
below is sample code.
TABLES: ekko,ekpo.
PARAMETERS: p_ebeln like ekko-ebeln.
data: begin of itab occurs 0,
ebeln like ekko-ebeln,
ebelp like ekpo-ebelp,
end of itab.
select ekkoebeln ekpoebelp into TABLE itab
from ekko INNER JOIN ekpo on
ekkoebeln = ekpoebeln
where ekko~ebeln = p_ebeln.
loop at itab.
write:/ itab-ebeln,itab-ebelp.
endloop.
09-12-2008 7:39 AM
HI,
In the where clause you can give condition for twice.
i hope it may not throw you error.
i did id once.
check it once.
09-12-2008 7:40 AM
HI,
YOUR SYNTAX WILL BE
SELECT (field list as EKKO~ OR EKPO~)
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( ( ekko
INNER JOIN EKPO ON ekko~VBELN = ekPo~VBELN )
WHERE FIELD NAME1 IN SELECTOPTION1
AND FIELD NAME2 IN SELECTOPTION2
For detail concept , check
http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb39c4358411d1829f0000e829fbfe/content.htm
Regards,
Anirban
09-12-2008 7:44 AM
Hi,
Try this.
select af1 bf2
into table itab
from EKKO as a inner join EKPO as b
on aEBELN eq bEBELN
where a~EBELN in EBELN.
Try your code by specifying a or b ebeln in the where condition.
Sharin.
09-12-2008 7:49 AM
Hi,
use table name in where clause.
below is sample code.
TABLES: ekko,ekpo.
PARAMETERS: p_ebeln like ekko-ebeln.
data: begin of itab occurs 0,
ebeln like ekko-ebeln,
ebelp like ekpo-ebelp,
end of itab.
select ekkoebeln ekpoebelp into TABLE itab
from ekko INNER JOIN ekpo on
ekkoebeln = ekpoebeln
where ekko~ebeln = p_ebeln.
loop at itab.
write:/ itab-ebeln,itab-ebelp.
endloop.
09-12-2008 7:56 AM
Mentioning EBELN both in join condition and in Where condition is giving an error.
Just take a look at what i have done:
SELECT a~ebeln
a~bsart
a~aedat
a~ekorg
a~ekgrp
a~inco1
a~ernam
a~knumv
a~exnum
b~ebelp
b~menge
b~txz01
FROM ekko AS a
INNER JOIN ekpo AS b
ON bebeln EQ aebeln
INTO TABLE gt_ekko
WHERE ebeln IN s_ebeln
AND bsart IN s_bsart
AND aedat IN s_aedat
AND ekorg IN s_ekorg
AND ekgrp IN s_ekgrp
AND ernam IN s_ernam
AND zdat01 IN s_zdat01
AND loekz = SPACE
AND elikz = SPACE.
This gives an error saying EBELN has 2 conditions.
09-12-2008 7:59 AM
In the where condition you did not mention which ebeln should be considered. that is from which table it should take and compare.
09-12-2008 8:13 AM
Hi Jean,
SELECT a~ebeln
a~bsart
a~aedat
a~ekorg
a~ekgrp
a~inco1
a~ernam
a~knumv
a~exnum
b~ebelp
b~menge
b~txz01
FROM ekko AS a
INNER JOIN ekpo AS b
ON bebeln EQ aebeln
INTO TABLE gt_ekko
WHERE a~ebeln IN s_ebeln
AND a~bsart IN s_bsart
AND a~aedat IN s_aedat
AND a~ekorg IN s_ekorg
AND a~ekgrp IN s_ekgrp
AND a~ernam IN s_ernam
AND zdat01 IN s_zdat01
AND loekz = SPACE
AND elikz = SPACE.
Similarly for other fields u hv to gove the table name....