rspec/rules/S5768/abap/rule.adoc
2022-02-04 16:28:24 +00:00

56 lines
1.7 KiB
Plaintext

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.
----
== See
* https://archive.sap.com/documents/docs/DOC-46714[Best Practice Guide - Considerations for Custom ABAP Code During a Migration to SAP HANA]
* 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)
include::message.adoc[]
include::highlighting.adoc[]
endif::env-github,rspecator-view[]