Skip to Content
author's profile photo Former Member
Former Member

Inclusion of MANDT in the SQL statement


My apologies if this is the incorrect forum to post this question in. Please feel free to direct me towards the correct one if needed. I am not an ABAP(er), so please bear with me.

My question is as follows-

What decides the inclusion of Mandt in the Where clause of the SQL Statement even if it is not specified in the ABAP code ? My problem is that MANDT makes the index very unselective.

Here is an example

ABAP Code :

Open cursor with hold wa_dbcur for

SELECT matnr bwkey lbkum salk3 verpr vksal BKLAS

FROM mbew

WHERE matnr in smatnr

AND bwkey in sbwkey



fetch next cursor wa_dbcur into corresponding fields of table it_collect

package size 10000.

if sy-subrc <> 0.



SQL statement :







Also, is there a way to avoid this ? If there isn't a way to avoid this, what would be a workaround.

Thank you everyone in advance.


Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • Best Answer
    Posted on Oct 25, 2010 at 09:32 PM

    Well, the MANDT field is always automatically added to your SQL query by the database interface (translating ABAP Open SQL to DBMS Native SQL), you can avoid it by adding CLIENT SPECIFIED to the ABAP statement, which is not recommended most of the time.

    What problem do you have with the statement, is it too slow?

    Did you get the SQL statement from ST05 trace? Then can also post the execution plan here to allow further analysis.


    Add a comment
    10|10000 characters needed characters exceeded

    • I think you can delete your two indexes again:

      MATNR and BWKEY is the primary key minus the MANDT field, but MANDT is always filled during selection, so no gain here.

      There is alreday index MBEW~ML1 with MANDT and KALN1, KALN1 seems very selective, so your own KALN1 and MATNR does not add value either.

      The question is how your selection range SMATNR is filled during selection, the narrower the selection is, the faster the query will run.


  • Posted on Oct 26, 2010 at 09:05 AM


    What do you have in smatnr and in sbwkey?


    Rui Dantas

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 26, 2010 at 01:18 PM

    There are a lot of tools you can use to determine the problem:


    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 28, 2010 at 12:02 PM

    >To be honest, I did not follow your suggestion ("what is in smatnr and in sbwkey") and did not want to waste any more time asking >for answers to simple straightforward questions. Besides, I don't see anything wrong with keeping the question open for another day

    > or two.

    I think he does not really want support, so better close this one!

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.