Rule Definition
The SELECT ... ENDSELECT works as a loop fetching single record for every loop pause. Basically, it works like a client cursor which will generate too much traffic on the network and communications between the application server and the database server. When used on extremely large tables, this statement becomes a performance killer.
Remediation
Use preferably the "SELECT... INTO TABLE...+ LOOP AT Table" tatement.
Violation Code Sample
* violation
SELECT name
FROM dtab
WHERE typeno = 2.
...
ENDSELECT.
* no violation
SELECT prodid INTO lv_prodid
FROM prodlist
UP TO 1 ROWS
WHERE typeid = ps_alty-type_id.
ENDSELECT.
IF NOT lv_prodid IS INITIAL
...
ENDIF.
* no violation
SELECT prodid INTO lv_prodid
FROM prodlist
UP TO ONE ROWS
WHERE typeid = ps_alty-type_id.
ENDSELECT.
IF NOT lv_prodid IS INITIAL
...
ENDIF.
Fixed Code Sample
* remediation
SELECT name INTO TABLE itab
FROM dtab
WHERE typeno = 2.
IF sy-subrc = 0.
LOOP AT itab.
...
ENDLOOP.
ELSE.
MESSAGE e000 WITH text-117.
ENDIF.
Related Technologies
Technical Criterion
Efficiency - SQL and Data Handling Performance
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.