Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

SELECT Query with NOT EQUAL TO Condition in WHERE Clause

Hi,

I have this curiosity regarding the performance impact of having a NOT EQUAL TO condition in the WHERE clause of a SELECT query. Please provide your inputs and reasoning on the performance impact on the below 2 scenarios.

1. SELECT knumv kposn kbetr

     FROM konv

     INTO TABLE it_konv

     FOR ALL ENTRIES IN it_ekko

     WHERE knumv = it_ekko-knumv.

IF sy-subrc = 0.

     DELETE it_konv WHERE kbetr IS INITIAL.

ENDIF.

2. SELECT knumv kposn kbetr

     FROM konv

     INTO TABLE it_konv

     FOR ALL ENTRIES IN it_ekko

     WHERE knumv = it_ekko-knumv AND

                    kbetr <> lv_zero. "Initial or 0 value.

Between the two of the above scenarios, can you please help me evaluate which would have a better overall performance and why.
I am more interested in knowing the reason for the difference in performance probably with respect to index and DB optimizer than a direct answer that scenario 1 or 2 would work faster.

Appreciate the help.

Thanks in advance.

-Justine.

Tags:
Former Member replied

Find the answer here:

Negative conditions in WHERE clause (but not over indexed fields)

I have just done a small report with your select and tested in SE30, the selection without <> in where clause took 9.328 microsec. With '<>' operator the program took 51.086 microsec.

As you can see in the link above, if you use the table index in the selection, use the '<>' operator in a non-index field could help the selection, otherwise better not to use.

Regards,

Felipe

Message was edited by: Felipe Simionatto

1 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question