Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Is it correct - For All Entries syntax

agnihotro_sinha2
Active Contributor
0 Kudos

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.

2 REPLIES 2

former_member226999
Contributor
0 Kudos

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

SuhaSaha
Advisor
Advisor
0 Kudos
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!