rspec/rules/S2240/abap/rule.adoc

36 lines
1.0 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
Using ``++EXIT++`` and ``++CHECK++`` in ``++SELECT++`` statements to stop the execution of ``++SELECT++`` loop is an expensive and ineffective way to filter data. Filtering should be part of the ``++SELECT++`` loop themselves. Most of the time conditions located in a ``++CHECK++`` statement should be moved to the ``++WHERE++`` clause, and the ``++EXIT++`` statement should typically be replaced by an ``++UP TO 1 ROW++`` clause.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,abap]
2021-04-28 16:49:39 +02:00
----
SELECT * FROM SBOOK INTO SBOOK_WA.
CHECK: SBOOK_WAS-CARRID = 'LH' AND SBOOK_WAS-CONNID = '0400'. "Noncompliant
ENDSELECT.
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,abap]
2021-04-28 16:49:39 +02:00
----
SELECT * FROM SBOOK INTO SBOOK_WA WHERE CARRID = 'LH' AND CONNID = '0400'.
ENDSELECT.
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Refactor this piece of code to not stop the execution of the nesting "SELECT" loop before having read all the elements
endif::env-github,rspecator-view[]