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: 

"OR" and "IN" queries extremely slow through RFC for COEP and STXH

albertino87
Explorer
0 Kudos

Hi all,

I'm using a python script to read the SAP tables through RFC. usually it works fine for most of the tables, however I found an issue with some of them.

for example when I'm trying to read the COEP table and in the WHERE clause I write:

BELNR = '0123456789'

or

BELNR = '9876543210'

it is very quick and returns the results, but if instead I write:

BELNR = '0123456789' OR BELNR = '9876543210'

it hangs for a very long time and when it "ends" the execution the program actually doesn't do anything anymore.

The same problem happens if I write:

BELNR IN ('0123456789', '9876543210')

and even more weird, it happens if I write:

BELNR = '0123456789' OR BELNR = '0123456789'

which is basically just one condition, or

BELNR IN ('0123456789', '0123456789')

The same thing happens if I try to query the STXH table by filtering with the TDNAME field.

Multiple OR clauses work just fine on all the other tables I encountered so far. I was wondering if this was a problem just due to the RFC connection or if it was present even in ABAP (I cannot test it myself), and if so, if there's a workaround.

Many thanks

Regards

1 ACCEPTED SOLUTION

gabmarian
Active Contributor

I don't know what database your SAP system uses but my feeling is that this is a DB optimizer issue. For both the tables you are missing the left-most key:

For

  • COEP this is KOKRS (controlling area)
  • STXH this is TDOBJECT (object type)

This increases the change the tables will be accessed according to their primary key.

8 REPLIES 8

gabmarian
Active Contributor

I don't know what database your SAP system uses but my feeling is that this is a DB optimizer issue. For both the tables you are missing the left-most key:

For

  • COEP this is KOKRS (controlling area)
  • STXH this is TDOBJECT (object type)

This increases the change the tables will be accessed according to their primary key.

gabmarian
Active Contributor
0 Kudos

albertino87

Regarding your question to query COEP by OBJNR:

As far as I can see it is not part of any index. You should try to find a selection criteria that matched to the left-most side of an index. Someone who have access to the SAP system you fetch the data from can help you to determine suitable fields.

gabmarian
Active Contributor
0 Kudos

albertino87

If you have no further questions please be so kind to accept the answer and close the thread, so it will be apparent to others that it has been answered.

Sandra_Rossi
Active Contributor
0 Kudos

You didn't explain how your program "read[s] the SAP tables through RFC", so it will be very difficult to answer anything...

albertino87
Explorer
0 Kudos

sandra.rossi ,

gabmarian answer was correct :).

Many thanks

kind regards

Alberto

albertino87
Explorer
0 Kudos

Thanks gabmarian ,

Interestingly now if I do:

(BELNR = '0123456789' OR BELNR = '9876543210') AND KOKRS = 'XYZ'

works, but

(OBJNR = 'OV01234567890001' OR OBJNR = 'OV93847289200023478') AND KOKRS = 'XYZ'

not, I cannot explain this performances, any idea on another filter that could fix this?

abo
Active Contributor
0 Kudos

so:

  • this isn't an answer and it should go in the question itself 🙂
  • gabmarian could convert the comment to answer and albertino87 may accept it

gabmarian
Active Contributor

albertino87

I converted my comment to an aswer, as this solved your initial problem.