CRITICAL
Rule Definition
For systems running on HANA, SAP recommends to keep the result sets small. Test executed by statements like CHECK are done locally to the client code and unnecessary data is transferred by the SELECT..ENDSELECT loop.
Very often, you may want to determine in a program whether at least one record exists in a database table for a particular WHERE condition. For this purpose, however, empty SELECT...ENDSELECT loops (or those that only have one EXIT statement) should not be used.
Particularly in the case of non-buffered tables or wherever the statement bypasses the buffering, this is a very low-performing solution. The reason is that, in the case of a SELECT...ENDSELECT statement, the data is not read from the database record by record, but is read in larger blocks.
Also, the use of EXIT or RETURN in a SELECT...ENDSELECT loop for another purpose is often questionable since the processing sequence of the database records in a SELECT...ENDSELECT loop without the addition ORDER BY is accidental.
In both cases much too much data is read from the database!
Remediation
If only the existence (at least) of one record is to be checked, it is recommended to use the addition 'UP TO 1 ROWS', or reading the database with 'SELECT SINGLE'. Both solutions have the effect that only one record is read from the database. This also applies if only some subfields instead of the entire record need to be read.
Violation Code Sample
SELECT *
FROM sflight
INTO ls_flight
WHERE carrid EQ lv_carrid AND connid EQ lv_connid AND fldate EQ lv_fldate.
EXIT.
ENDSELECT.
IF sy-subrc NE 0.
WRITE:/ 'NOT FOUND'.
ENDIF.
Fixed Code Sample
SELECT SINGLE *
FROM sflight
INTO ls_flight
WHERE carrid EQ lv_carrid AND connid EQ lv_connid AND fldate EQ lv_fldate.
IF sy-subrc NE 0.
WRITE:/ 'NOT FOUND'.
ENDIF.
Reference
SAP - Considerations for Custom ABAP Code When Migrating to SAP HANA - Best Practices and Recommendations
Related Technologies
Technical Criterion
CWE-1050 - Excessive Platform Resource Consumption within a Loop
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.