Select-Statement can be Transformed
During Code Inspector check on ABAP programs I got Select-Statement can be transformed errors for Search problematic SELECT * statements check category. I was optimizing ABAP codes that I used during my SAP developments for HANA migration to clear problematic cases for expected performance increase introduced with HANA.
Thanks to SAP Code Inspector SCI transaction which is used to list problems within ABAP programs that will decrease HANA performance if they are not corrected. So I executed Code Inspector and try to solve problematic "Select * statements" as I illustrated in this ABAP tutorial.
After ABAP programmers execute SCI Code Inspector, they will see many cases listed with changing rates of field usages but same error identified as "Select-Statement can be transformed" Here is a sample error listed as a result of Code Inspector check which I will correct using the method I will explain in this ABAP tutorial.
Search problematic SELECT * statements
Select-Statement can be transformed. 2.0% of fields used
Double click on reported item
Code inspector results will dispay the details for the selected problematic case.
For example, following case illustrates where a SELECT statement is executed over SAP KNA1 table but only 4 fields of all existing from KNA1 table is used.
This shows that selecting all fields from KNA1 table is unnecessary and will cause unused memory usage for keeping other fields except the reported 4 fields on HANA.
On the same report, the ABAP Include where the SELECT statement or the problematic code exists is also provided for easy access of the developers. ABAP programmer can double click on a line to open the code editor directly from the Code Inspector result list.
When I check the ABAP code source, I see a sample usage of "SELECT * statement" as follows:
LS_KNA1 structure is populated with all data from KNA1 table for the related customer. But only 4 fields are used. So for the sake of memory optimizing we can only select related 4 columns and use within reported ABAP program.
One of the solution for this problematic SELECT statement is to use only necessary field names in the SELECT list and using INTO CORRESPONDING FIELDS OF to prevent storing column values in wrong fields within the target structure.
If you do not pay attention to this, especially in aggregate operations, you will get errors.
Even though you do not get an error while activating the ABAP program, it will cause wrong results.
Here is the updated ABAP code for HANA migration optimization.
Although above ABAP code optimization is enough to solve the problematic SELECT * statement case, a further change can be done for the local structure definition.
In order to check the affect of your code optimization efforts, you can use Code Inspector to Check your ABAP code directly from transactions like SE24, SE37 or SE38 using menu options as a cross-check.
For example, after optimization for HANA on problematic SELECT statements within the codes of an ABAP class, I run Code Inspector using the following menu options on SE24 Class Builder transaction screen.
SE24 > Object Type > Check > Code Inspector