‎2007 Jan 10 9:31 AM
can any one tell how to join bkpf ,rbkp ,ekbe,ekbz
by using bkpfbelnr = rbkpbelnr
bkpfbukrs = rbkpbukrs
rbkpbelnr = ekbebelnr
rbkpbenr = ekbzbelnr
‎2007 Jan 10 9:36 AM
Hi,
You cannot join the tables if it is pool or cluster.Just check the table attributes.
Otherwise,check the sample code using F1.
‎2007 Jan 10 9:38 AM
SELECT *
INTO TABLE i_output
FROM bkpf as a
INNER JOIN rbkp as B
ON a~belnr = b~belnr
AND a~gkahr = b~gjahr
INNER JOIN ekbe as c
ON c~belnr = b~belnr
AND c~gkahr = b~gjahr
INNER JOIN ekbz as d
ON d~belnr = c~belnr
AND d~gkahr = c~gjahr
WHERE ...............................This depends on the requirement.
U may have to use LEFT OUTER JOIN also.
‎2007 Jan 10 9:55 AM
hi murali thank u but the thing is i want to give the condition like this
and i want to print all the data contained in ekbe bkpf ekbz and rbkp
please check and rectify my mistake in this code
SELECT *
INTO TABLE i_main
FROM bkpf as a
INNER JOIN rbkp as B
ON axblnr = bxblnr
AND agjahr = bgjahr and
abudat = bbudat
INNER JOIN ekbe as c
ON cbelnr = bbelnr
AND cgjahr = bgjahr
INNER JOIN ekbz as d
ON dbelnr = cbelnr
AND dgjahr = cgjahr
WHERE abukrs in bukrs and abudat in budat and ablart in ('RD' , 'RE') AND CBEWTP = 'Q'
AND D~BEWTP = 'M'.
LOOP AT I_MAIN.
WRITE:/I_MAIN-BELNR.
ENDLOOP.
‎2007 Jan 10 10:07 AM
can u please tell me how to write those fields inside the loop
for eg: rbkp also contain belnr
bkpf also contains belnr
i want to write bothe rbkp and bkpf belnr how to write in loop
‎2007 Jan 10 9:39 AM
‎2007 Jan 10 9:40 AM
bettter go for a view or do like this.
select abelnr bbukrs c,f1> df2 into corresponding fields of table itab from rbkp as a inner join bkpf as b on abelnr = bbelnr and abukrs = bbukrs
inner join ekbe as c on abelnr = cbelnr
inner join ekbz as d on abelnr = dbelnr where<condn>.
performance will reduce for this code.
regards
shiba dutta
‎2007 Jan 10 9:44 AM
hi
better to use for all entries concept, instead of using inner join for 4 tables..
so that it can improve performace
‎2007 Jan 10 10:05 AM
please tell can u give me the code for this
the problem is is ekbe and ekbz may have multiple entries
please can u give me the code for this
‎2007 Jan 10 9:44 AM
arun,
see the code.Inner joins are not advisable .
SELECT BKPFBELNR BKPFBUKRS BKPFGJAHR RBKPBELNR RBKP~BUKRS
RBKPGJAHR EKBEBELNR EKBEBUZEI EKBEEBELN EKBE~EBELP
EKBEGJAHR EKBEVGABE EKBZBELNR EKBZBUZEI EKBZ~EBELN
EKBZEBELP EKBZGJAHR EKBZ~VGABE
INTO (BKPF-BELNR , BKPF-BUKRS , BKPF-GJAHR , RBKP-BELNR , RBKP-BUKRS
, RBKP-GJAHR , EKBE-BELNR , EKBE-BUZEI , EKBE-EBELN , EKBE-EBELP
, EKBE-GJAHR , EKBE-VGABE , EKBZ-BELNR , EKBZ-BUZEI , EKBZ-EBELN
, EKBZ-EBELP , EKBZ-GJAHR , EKBZ-VGABE )
FROM ( BKPF
INNER JOIN RBKP
ON RBKPBELNR = BKPFBELNR
AND RBKPBUKRS = BKPFBUKRS
AND RBKPGJAHR = BKPFGJAHR
INNER JOIN EKBE
ON EKBEBELNR = RBKPBELNR
AND EKBEGJAHR = RBKPGJAHR
INNER JOIN EKBZ
ON EKBZBELNR = EKBEBELNR
AND EKBZBUZEI = EKBEBUZEI
AND EKBZEBELN = EKBEEBELN
AND EKBZEBELP = EKBEEBELP
AND EKBZGJAHR = EKBEGJAHR
AND EKBZVGABE = EKBEVGABE ).
Pls. reward.
‎2007 Jan 10 10:16 AM
first of all i have to know how did you declare the internal table.
because if you use include structure means the field repetation must be there.
if you are using one by one means in your select query you cannot use *.
correct me if i am wrong.
regards
shiba dutta
‎2007 Jan 10 10:25 AM
thank u shiba for ur reply
the thing is ur correct
i will tell my requirement
i want to fetch bkpf and rbkp fields by matching budat and xblnr and bukrs
then wtih the use of rbkpf~belnr i want to fetch all details from ekbe and ekbz
ekbe and ekbz may contain multiple entries
this is the requirement
can u please give me the code for this
‎2007 Jan 10 10:36 AM
hi
i have included wat u told but the output is not coming its not fetching properly
can u please tell me the exact code according to this condition,if u know to use for all entries also it will b better
but please give me the code
*SELECT abelnr cebeln
INTO TABLE i_main
FROM bkpf as a
INNER JOIN rbkp as B
ON axblnr = bxblnr
AND agjahr = bgjahr and
abudat = bbudat
INNER JOIN ekbe as c
ON cbelnr = bbelnr
AND cgjahr = bgjahr
*INNER JOIN ekbz as d
*ON dbelnr = cbelnr
AND dgjahr = cgjahr
*WHERE abukrs in s_bukrs and abudat in s_budat and ablart in ('RD' , 'RE') AND CBEWTP = 'Q'.
**or D~BEWTP = 'M'.
**
*LOOP AT I_MAIN.
*WRITE:/02 I_MAIN-BELNR,10 i_main-ebeln.
*ENDLOOP.
‎2007 Jan 10 10:30 AM
my answer is just ommit * from the select query and give the fields name you required.
in your itab also define the field name.
in inner join only the matching values will come dont worry.
suppose in bkpf 1 belnr is there but in ekbe same 10 means it will fetch 10 data with same belnr no.
so try to do this tedious job and check whether your query is running or not.
if it is not working then reply with the error.
regards
shiba dutta
‎2007 Jan 10 10:59 AM
i hink you are not using the joins between ekbe and ekbz
SELECT abelnr cebeln
INTO TABLE i_main
FROM bkpf as a
INNER JOIN rbkp as B
ON axblnr = bxblnr
AND agjahr = bgjahr and
abudat = bbudat
INNER JOIN ekbe as c
ON cbelnr = bbelnr
AND cgjahr = bgjahr
*INNER JOIN ekbz as d
*ON dbelnr = cbelnr
AND dgjahr = cgjahr
<b>and cebeln = debeln and
cebelp = debelp</b>*WHERE abukrs in s_bukrs and abudat in s_budat and ablart in ('RD' , 'RE') AND CBEWTP = 'Q'.
**or D~BEWTP = 'M'.
**
try to join those two tables by primary key fields
if it also not works means let us check some other things.
regards
shiba dutta
‎2007 Jan 10 4:58 PM
Hi,
Writing a Join for 4 tables is not advisable, it will become a mojor performace issue. try writing 2 joins and then write a logic to populate in a single table.
Regards,
Aravind