‎2006 Nov 02 4:48 AM
Hi all,
I have to design a report where there are five inputs
wbs element, cost center no, purchasing group, plant no and po creation date. the data is taken from ekko, ekpo and ekkn. and all the inputs are optional. so the input can be in one field or any combination. My doubt is can I join the three tables for this requirement as below,
SELECT a~ebeln
a~bsart
a~lifnr
a~ekgrp
a~aedat
a~waers
b~werks
c~ps_psp_pnr
c~kostl
INTO CORRESPONDING FIELDS OF TABLE po_hdr
FROM ekko as a
JOIN ekpo as b ON aebeln = bebeln
JOIN ekkn as c ON aebeln = cebeln
WHERE a~bsart IN ('PO','EBP')
AND a~ekgrp IN pgrp_no
AND a~bedat IN po_dt
AND b~werks IN pl_no
AND c~ps_psp_pnr IN wbs_no
AND c~kostl IN cc_no.
v_chk2 = sy-subrc.
IF v_chk2 = 0.
SELECT ebeln
ebelp
txz01
werks
brtwr
INTO CORRESPONDING FIELDS OF TABLE po_det
FROM ekpo
FOR ALL ENTRIES IN po_hdr
WHERE ebeln = po_hdr-ebeln
AND loekz <> 'L'
AND werks IN pl_no.
IF sy-subrc = 0.
*Populating the internal table WBS_DET with the WBS Details from EKKN.
SELECT ebeln
ebelp
kostl
ps_psp_pnr
INTO CORRESPONDING FIELDS OF TABLE wbs_det
FROM ekkn
FOR ALL ENTRIES IN po_det
WHERE ebeln = po_det-ebeln
AND ps_psp_pnr IN wbs_no
AND kostl IN cc_no.
ENDIF.
ENDIF.
and proceed like this. Should I match the ebelp for the detail tables ekpo and ekkn?
‎2006 Nov 02 4:59 AM
Hi
Please try with below code to avoid other two select statements.
types: begin of t_data,
ebeln like ekko-ebeln,
bsart like ekko-bsart,
lifnr like ekko-lifnr,
ekgrp like ekko-ekgrp,
aedat like ekko-aedat,
waers like ekko-waers,
ebelp like ekpo-ebelp,
werks like ekpo-werks,
txz01 like ekpo-txz01,
ps_psp_pnr like ekkn-ps_psp_pnr,
kostl like ekkn-kostl,
end of t_data.
data: it_po type standard table of t_data,
wa_po type t_data.
SELECT a~ebeln a~bsart a~lifnr a~ekgrp a~aedat a~waers
b~ebelp b~werks b~txz01 c~ps_psp_pnr c~kostl
INTO CORRESPONDING FIELDS OF TABLE it_po
FROM ekko as a
JOIN ekpo as b ON a~ebeln = b~ebeln
JOIN ekkn as c ON a~ebeln = c~ebeln and b~ebelp = c~ebelp
WHERE a~bsart IN ('PO','EBP')
AND a~ekgrp IN pgrp_no
AND a~bedat IN po_dt
AND b~werks IN pl_no
AND b~loekz <> 'L'
AND c~ps_psp_pnr IN wbs_no
AND c~kostl IN cc_no.Kind Regards
Eswar