09-11-2016 5:21 AM
Hello Experts,
To begin with I have written a for all entries query in a way ( which is new to me ) and hence want to get opinion on the same.
Just to mention before judging, the RESULTS are correct with this syntax.
Scenario: Dealing with PO + MRP tables - EKPO, MDKP, MDTB
Lets say I have 1 internal table with T_PO_MRP wherein I have somehow collected data in 4 columns - MATNR,DISPO,DELNR,DELPS.
SELECT
mdkp~matnr
mdkp~plwrk
******
mdtb~delps
mdtb~umdat
mdtb~dat00
INTO TABLE t_mrpdetail
FROM mdkp
INNER JOIN mdtb
ON mdkp~dtnum = mdtb~dtnum
FOR ALL ENTRIES IN t_po_mrp
WHERE mdkp~dtart = c_dtart
AND ( ( mdkp~matnr = t_po_mrp-matnr AND mdkp~dispo = t_po_mrp-dispo ) )
OR
( mdtb~delnr = t_po_mrp-delnr
AND mdtb~delps = t_po_mrp-delps ) ) "from PO and MRP tables
AND mdkp~plwrk = p_plwrk
AND mdkp~plscn = c_plscn.
So basically, I am using 2 different key combination in FOR ALL entries syntax.
Question: is it expensive DB query? If yes, then i have to break it to 2 MDTB queries, wont that be more expensive?
Is this kind of query allowed in ABAP - plz remember, I am getting correct data from this query.
just fyi, I am taking care of the null COLUMNs in the internal table by passing '*' to them before for all entries.
ABAP Experts, plz let me know you inputs.
ags.
09-12-2016 1:39 PM
Query might be expensive because of the OR clause spanning across two tables.
What you can do is add secondary index to speed up on MDKP table in the order of DTART, MATNR, DISPO, PLWRK, PLSCN
09-12-2016 8:52 PM
Question: is it expensive DB query? If yes, then i have to break it to 2 MDTB queries, wont that be more expensive?
The best person to answer these questions is you.
Run a ST05(SQL) trace on both the statement variants and check the SQL explain plan. Most of the answers you'll get here will be guesses!