SAP code inspector is a SAP delivered tool to quickly inspect your custom built ABAP code.
This blog will anser following questions:
- Why use SAP code inspector?
- SAP code insptector versus other source code scanner tools
- How to setup SAP code inspector?
- Which SCI checks are recommended in general?
- Which SCI checks are must do for S/4 HANA readiness?
Why use SAP code inspector?
SAP code inspector can be used by both ABAP developer or customer who has outsourced ABAP development. The SAP code inspector will check custom ABAP code for:
- Potential performance issues
- Potential usability restrictions
- Robust programming checks
- Use of ABAP code naming conventions
- Scan for certain statements if wanted
The code inspector has been given big boost last few years by SAP, since has become primary tool to prepare custom ABAP code for S/4 HANA.
SAP code inspector versus other source code tool scanners?
Several major IT parties have setup their own custom build source code inspector tool. In the past these tools could deliver souce code scanning functions that SAP did not provide in SCI.
With the improvements done last years on preparing ABAP code for S/4 HANA the SCI tool is now so mature that there are almost no checks missing any more.
The setback of other source code tool scanners is their lack of integration with the SAP development tools (SE38, SE80, SE24, SE37, Eclipse ADT, etc).
How to setup SAP code inspector?
Setting up SAP code inspector is quite straightforward. Start transaction SCI and you come to the main SCI screen.
In this main screen goto the part for Check Variant. Give it a name and make sure that the icon next to Name is switched to global variant as is shown in the screenshot:
Now press create and the empty variant screen is shown.
By clicking on the i icon you can get detailed information on the checks.
By default no checks are active and you have to select which checks are relevant for you.
Let’s go over a few important ones.
Make sure the performance checks are on:
Under Syntax Check make sure the classical SLIN extended program checks is switched on:
In the robust programming section switch on the SY-SUBRC handling. Here you have to take care (as do some other checks) to fill out the details (click on the green multiple selection symbol):
Finally (this is optional) you can also set the ABAP naming conventions:
Setting the variant as DEFAULT SCI variant
If we want to run the SCI tool from code editor the variant DEFAULT is used. This is different variant then we just created. To set the variant for SCI tooling for our own created variant, goto tcode SE16 and edit the contents of table SCICHKV_ALTER:
In the CHECKVNAME_NEW enter the name of the created SCI variant.
Running the SCI tool
The SCI tool can be run from different places. You can run it from tcode SCI itself by entering object or transport there. Or you can run it from code editor and selecting the menu Program/Check/Code Inspector.
Let’s use this sample program:
REPORT zscidemo. DATA: zlt_vbak TYPE TABLE OF vbak. DATA: zls_vbak TYPE vbak. SELECT * FROM vbak INTO TABLE zlt_vbak. LOOP AT zlt_vbak INTO zls_vbak. WRITE: / zls_vbak-vbeln. ENDLOOP.
And now we run code inspector. Results:
The result shows 3 aspects:
- Use of SELECT * on large table
- SY-SUBRC is not handled after the read: this is correct and should have been done
- Naming conventions of variables are not according to settings
After the run the developer can repair the items and rerun as much as needed.
SAP SCI will determine the severity of the found issue into Critical (error/red), Warnings (yellow) and Information (green).
Fine-tuning the SCI message priority
For several reasons you want to fine-tune the SCI message priority. Some check you regard as less important than SAP and some check you regard as more important then SAP is rating them in the SCI standard settings.
If you are in the main SCI screen choose the menu entry Code Inspector/Management Of/ Message Priorities, you come to the screen to adjust and fine-tune the priorities:
The example show is the increase of the check from warning to error (yes, it is still the German Fehler) for the omission of SY-SUBRC check after direct database update.
SCI tool and S/4 HANA migration
Intermediate SAP knowledge required
When you are in the process of migrating or thinking to migrate to S/4 HANA, then the SCI tool checks play a central role in preparing the custom ABAP code.
In oss note 1912445 – “ABAP custom code migration for SAP HANA – recommendations and Code Inspector variants for SAP HANA migration” SAP explains the details in the 2 newly delivered SCI variants.
You can run these new variants specifically, but it is best to already incorporate these checks into your existing SCI main variant. Even if you don’t plan to upgrade, the checks are good anyhow.
Most important highlights:
- Mandatory use of ORDER BY or SORT BY (this check is vital: if not done it can even cause functionality issues!)
- Unsecure use of FOR ALL ENTRIES (if not checked if table has entries, ALL database entries will be read, which causes both functional issues and kills performance)
- Don’t use SELECT * (code will work, but in HANA this is a performance killer)
- Checking for database hints (you rarely see this in custom code, but if done code will not properly work after migration)
This last check is bit hidden: open the multiple selection and in the details make sure Native SQL and DB hints are checked on.
Checking your complete Z code base
If you want to check your complete Z code base or a larger block for a project, you can use the ATC tool. The ATC tool uses the SCI checks to analyze large blocks of Z code.