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-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

problematic Select * statements: Select-statement can be transformed

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.

ABAP code optimization for HANA performance changing select * statements

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:

data LS_KNA1 type KNA1.
select single * into LS_KNA1 from KNA1 where KUNNR = LS_VBAK-KUNNR.
if SY-SUBRC = 0.
 clear LS_CONTENT.
 concatenate 'Customer:' LS_KNA1-KUNNR LS_KNA1-NAME1 LS_KNA1-NAME2 LS_KNA1-ORT01
   into LS_CONTENT separated by SPACE.
...
Code

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.

data LS_KNA1 type KNA1.
select single kunnr name1 name2 ort01 into CORRESPONDING FIELDS OF LS_KNA1
 from KNA1 where KUNNR = LS_VBAK-KUNNR.
if SY-SUBRC = 0.
 clear LS_CONTENT.
 concatenate 'Customer:' LS_KNA1-KUNNR LS_KNA1-NAME1 LS_KNA1-NAME2 LS_KNA1-ORT01
   into LS_CONTENT separated by SPACE.
...
Code

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.

TYPES:
BEGIN OF typ_kna1,
 kunnr TYPE kunnr,
 name1 TYPE name1_gp,
 name2 TYPE name2_gp,
 ort01 TYPE ort01_gp,
END OF typ_kna1.
DATA ls_kna1 TYPE typ_kna1.
select single kunnr name1 name2 ort01 into CORRESPONDING FIELDS OF LS_KNA1
 from KNA1 where KUNNR = LS_VBAK-KUNNR.
if SY-SUBRC = 0.
 clear LS_CONTENT.
 concatenate 'Customer:' LS_KNA1-KUNNR LS_KNA1-NAME1 LS_KNA1-NAME2 LS_KNA1-ORT01
   into LS_CONTENT separated by SPACE.
...
Code

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

check ABAP code using SAP Code Inspector



SAP HANA and ABAP

Install SAP Free
CRM Companies List
Web Based CRM Software


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