SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for SAP HANA and ABAP, HANA Database, SQLScript, SAP UI5, Screen Personas, Web Dynpro, Workflow

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

SAP Code Inspector error: Select for cluster table 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:

SELECT kwert FROM konv INTO CORRESPONDING FIELDS OF gs_konv
WHERE knumv EQ gv_knumv
 AND kposn EQ gs_vbap-posnr
 AND kschl EQ 'KDYZ'.
Code

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:

SELECT kwert FROM konv INTO CORRESPONDING FIELDS OF gs_konv
WHERE knumv EQ gv_knumv
 AND kposn EQ gs_vbap-posnr
 AND kschl EQ 'KDYZ'
 ORDER BY PRIMARY KEY.
Code

ABAP programmers can re-run the Code Inspector and check if the problematic case on SELECT statement is corrected or not.



SAP HANA and ABAP

Install SAP Free
CRM Companies List
Web Based CRM Software


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.