SAP code inspector is a SAP delivered tool to quickly inspect your custom built ABAP code.
This blog will answer following questions:
- Why use SAP code inspector?
- SAP code inspector versus other source code scanner tools
- How to setup SAP code inspector?
- Which SCI checks are recommended in general?
- Which SCI checks are a 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 source 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
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.
Check variant update
In SCI use the menu option Utilities and Import Check Variants to update your check variants. More background in OSS note 2948146 – SCI/ATC check variant is different between systems.
Checking addons and standard SAP
To check standard SAP code or addon ABAP code, follow the instructions in this blog.
Extra custom checks
If you need extra checks in SCI, you can use ABAP code to build your own custom checks. Please follow the instructions in this blog.
Running SCI on standard SAP and addons
If you need to run SCI on standard SAP and/or addons, you will find this is not possible (see OSS note 1986391 – Using SLIN/SCI to check SAP standard objects)
. Follow the trick in this blog to have it done anyhow.
Explanation OSS notes
Notes with extra hints and explanation:
- 2360080 – SCI/ATC false positive messages in SAP standard code which is included in customer program
- 2403798 – Missing ATC and SCI check variants
- 2539725 – “Export of Program Information” missing when creating a SCI check variant
- 2867608 – How to search specific ABAP statements or string in custom developed Z/Y programs
- 2953541 – ATC/CI: Navigation in developer scenario
- 3118312 – Code Inspector Check for restricted ABAP Language Version 5 (ABAP for Cloud Development) – Update 2108
Bug fix OSS notes
List of bug fix OSS notes:
- 2899381 – Cannot deactivate custom Code Inspector category
- 3051657 – Improvement of rs_ci_compare
- 3085789 – Object sets by creation date
- 3136206 – Code inspector checks on st05 Traces
- 3137752 – Error for method of tree model when displaying results in SCI
- 3142466 – Cannot perform inspection: The check YCL_CI_ADDITIONAL_CHECK does not exist in the check system.