Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Peter_Inotai
Active Contributor

Introduction

I always felt excited when I read about new ABAP related tools. One of the first such tool I fell in love was the Code Inspector. Around in 2001-2002 we were on 46C, and in one for the Code inspector presentation I saw a note about, that there is a down port for 46C with some limitation. I got green light from my manager to import it to our development system and I could play around with this tool ... and fun begun.

I found very useful to perform static checks on the code. From that point I always used Code Inspector instead of the Extended syntax check.

About the Code inspector framework

The Code Inspector is a tool for the static analysis of ABAP programs and other SAP repository objects. It’s available as of basis release 6.10 as part of SAP standard delivery and a down port is available for 46C with some limitations.

Code inspector is a framework, where all the categories and checks are based on ABAP classes. SAP continuously delivers new build-in checks for new tools (e.g.: ABAP Unit) and new objects (e.g.: BSP Applications).

It’s also possible to add customer-built checks within this framework.

Main steps for creating a new check

  • Create new category
  • Create new check
  • Create documentation
  • Activate new category/check

In this example we will build a very simple check for searching string ‘SDN’. This example is based on SAP standard check CL_CI_TEST_FREE_SEARCH.

I believe standard checks are covers most of the customer needs, however new checks can be useful for checking customer specific programming conventions.

The goal of this example is to show how the code inspector checks are built.

Creating a new category

Copy CL_CI_CATEGORY_TEMPLATE to ZCL_CI_CATEGORY_SDN.

Select the package in the popup (e.g.: $TMP)

Change the CONSTRUCTOR method to the following:

Create the text elements and activate your class.

This method sets the attributes of this category in the code inspector check tree.

Creating a new check

Copy CL_CI_TEST_SCAN_TEMPLATE to ZCL_CI_SCAN_SDN.

Select the package in the popup (e.g.: $TMP)

Add the following attributes to the class:

C_MY_NAME  Constant  Private  Type  SEOCLSNAME  'ZCL_CI_SCAN_SDN'

C_PROGRAM  Constant  Private  Type  SCI_ERRC  Code Inspector: ID for Message Code  'PROG'

C_SDN  Constant  Private  Type  CHAR03  Three-digit character field for Idocs  'SDN'

Method constructor sets the attributes of this check in the code inspector check tree.

Method run to search for string SDN and pass the parameters to method INFORM

Method get_message_text is to generate explanation text in the check tree.

Documentation

Via transaction SE61 you can add documentation to the categories/checks.

Create the follwing documentations:

ZCL_CI_CATEGORY_SDN/000       New Category for SDN

ZCL_CI_SCAN_SDN/000     Search for SDN

Activate new categories and checks

Start transaction SCI. Navigate to Goto-> Test Administration in the menu. Set the flag for the new category and check in order to make them available in the framework.

Testing our new check

Create a simple test program containing string ‘SDN’.

Start transaction SCII, where you can test the code without saving the inspection.

In the Object selection block set Single, select Program and enter program name.

In the Check variant block select Temporary Definition and make sure that you flag ‘New Category for SDN’ category and ‘Seach for SDN’ check. Remember, these texts were defined in the constructors.

Press execute and when you got the message ‘The inspection was carried out successfully’ go to the results.

Remarks

·        There are some changes between releases in the mentioned menu path and also in the available techniques.

·        This example was created on a SAP R/3 Enterprise 4.70x200 /WAS 6.20/ system.

·        Although suppress message is possible via method INFORM parameter p_suppress, somehow I couldn’t manage to make it work.

·        If you import the package in 46C, you can expect some extra work during the next upgrade SPAU, however all of these object can be reset to SAP standard

Reference documents

OSS note 543359        Code Inspector for SAP R/3 Release 4.6C

Improving the Quality of Your ABAP Code Using the Code Inspector

Evaluating the Quality of Your ABAP Programs and Other Repository Objects with the Code Inspector

ABAP Troubleshooting

75 Comments