Select For Cluster Table Without Order By
When I execute Code Inspector check on ABAP program I got SELECT ... FOR cluster table KONV without ORDER BY found error in "Internal Checks" category. Since I was optimizing ABAP codes for HANA migration, although this error is not failing the execution of the ABAP program I had to optimize such warnings for future execution performance of the report on HANA.
Here is the error displayed by SAP Code Inspector using main menu "Check > Code Inspector" options. A more general Code Inspector for a set of ABAP programs can be managed by using the SAP SCI tcode which is the main Code Inspector transaction
Intern. Tests
Depooling/Declustering: Search SELECT for Pool/Cluster-Tables w/o ORDER BY
Message Code SEL_CLUST
SELECT ... FOR cluster table KONV without ORDER BY found
On Code Inspector results double click on the reported error item to launch the code line directly from the current transaction.
When I display the ABAP program, the error is reported for the following ABAP SELECT statement on cluster table KONV:
Code Inspector provides the following information about this code check:
Search for SELECT and OPEN CURSOR statements for pool or cluster tables where no ORDER BY clause is specified.
This situation is problematic because the order of the returned database entries changes if the data base table is modified into a transparent table.
Remark: SELECT SINGLE statement are not analyzed since they are not problematic.
Remark: If the result of the SELECT statement is moved into a sorted internal table, a special message is raised
Messages of the test can be suppressed via the pseudo comment
"#EC CI_NOORDER
ABAP Help suggests to use SELECT SINGLE if possible or to use an Order By clause to prevent problems in case cluster table is converted into a transparent table in future.
Another option is to suppress the error message by using "#EC CI_NOORDER as comment for the Code Inspector to ignore this statement.
I simply solve this problem by adding "ORDER BY PRIMARY KEY" at the end of the ABAP SELECT statement as follows:
ABAP programmers can re-run the Code Inspector and check if the problematic case on SELECT statement is corrected or not.