
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
69 lines
1.8 KiB
Plaintext
69 lines
1.8 KiB
Plaintext
== Why is this an issue?
|
|
|
|
SAP recommends to keep the result set of any request as small as possible for performance reasons.
|
|
|
|
|
|
A ``++SELECT...ENDSELECT++`` request will retrieve multiple records at the same time. Stopping immediately such a request with a ``++CHECK++``, ``++RETURN++`` or ``++EXIT++`` statement will not reduce the number of retrieved records. If the goal is to retrieve a single record, or check that at least one record exists, it is recommended to add ``++UP TO 1 ROWS++`` or to use ``++SELECT SINGLE++``.
|
|
|
|
|
|
Even if the request already retrieved only one record, adding ``++UP TO 1 ROWS++`` or to using ``++SELECT SINGLE++`` will make the code easier to read.
|
|
|
|
|
|
This rule raises an issue when a ``++SELECT...ENDSELECT++`` which has neither ``++SINGLE++`` nor ``++UP TO 1 ROWS++`` and:
|
|
|
|
* contains only one statement and it is a ``++CHECK++``, ``++RETURN++`` or ``++EXIT++``
|
|
* or when it is completely empty.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,abap]
|
|
----
|
|
SELECT * FROM sbook INTO ls_book WHERE carrid EQ l_carrid.
|
|
EXIT.
|
|
ENDSELECT.
|
|
IF sy-subrc NE 0.
|
|
WRITE:/ 'NO RECORD FOUND'.
|
|
ENDIF.
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,abap]
|
|
----
|
|
SELECT SINGLE * sbook INTO ls_book WHERE carrid EQ l_carrid.
|
|
IF sy-subrc NE 0.
|
|
WRITE:/ 'NO RECORD FOUND'.
|
|
ENDIF.
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
* https://help.sap.com/doc/saphelp_nw70/7.0.31/en-US/aa/4734940f1c11d295380000e8353423/content.htm?no_cache=true[SAP documentation - Keep the Result Set Small]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Add "SELECT SINGLE" or "Up to 1 ROW" to this query; it uses only one record.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
Primary: The SELECT keyword.
|
|
|
|
Secondary:
|
|
|
|
* The "RETURN", "CHECK" or "EXIT" statement.
|
|
* message: "XXX" stops the request at the first record.
|
|
(XXX is the command name)
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|