ABAP: continuous analysis with Kiuwan

In our last article on ABAP Series we saw the particularities of the SAP environment. The main difference between ABAP and other programming languages is that we need to extract the source code from SAP to text files.

In that post we explained in detail a manual process to extract the code. Now we are going to use the Kiuwan ABAP extractor utility for this task. This utility will allow us to automate the process and integrate the ABAP analysis in our cycle of continuous integration.

SAP JCO Connector

JCO SAP connector allows the extraction of the necessary elements for the ABAP static analysis. Using a script, several remote calls to SAP system are performed to generate source code and extra information files locally, and then to download all generated files.

You need to download from SAP site the sapJCO library Java Connector, which is available from SAP Service Marketplace Connectors. This is downloadable just for customers, so you need Service-Marketplace access.

Once you have downloaded the corresponding package for your operating system, install it.

You can find more details on how to download the SAP JCO library in our manual page.

Install Kiuwan code extractors on your SAP system

To extract ABAP code and useful additional information, we need to create some functions and programs in our SAP system.

Open SAP GUI and login



Create two RFC-enabled functions using SE37 transaction, and activate them. If you need to create a new function group, use transaction SE80, choosing Function Group as the object type.

The source code for these functions can be found in {KiuwanLocalAnalyzer_installation_dir}\resources\abap directory.

Here you have, step by step, the Z_OPTIMYTH_EXPORT_FILES function creation:

  1. Create the Function group if necessary (you do this Withthe SE80 transaction). You can name it ZKIUWAN, for example:create-function-module
  2. With the SE37 transaction create the Z_OPTIMYTH_EXPORT_FILES function module:function-builder-initial-screen
  3. Now you have to configure the new function. We start with the attributes as shown in the image:function-builder-change-attributes
  4. Then the import parameters as shown (click the image to see the details):function-builder-change-import
  5. Then the export parameters (click the image to see the details):function-builder-change-export
  6. Finally you have to paste the function source code from the Z_OPTIMYTH_EXPORT_FILE.abap file distributed with the Kiuwan Local Analyzerfunction-builder-change-source

For the Z_OPTIMYTH_DOWNLOAD_FILE function repeat steps 2 and 3 above, with the SE37 transaction, just using the right name of the function. Then go on configuring the function following these steps:

  1. After configuring the attributes, now the import parameters as shown (click the image to see the details):download-function-builder-change-import
  2. Then the export parameters (click the image to see the details):download-function-builder-change-export
  3. We go on defining the exceptions this function may throw (click the image to see the details):download-function-builder-change-exceptions
  4. Finally you have to paste the function source code from the Z_OPTIMYTH_DOWNLOAD_FILE.abap file distributed with the Kiuwan Local Analyzer:download-function-builder-change-source

Install Kiuwan metadata and WebDynPro extractors on your SAP system

Some ABAP Kiuwan rules require additional metadata from the SAP System to work and provide valuable information. If you need WebDynPro code exported as well, you need to install a pair of additional programs and associated transactions.

Create the Z_OPTIMYTH_TABLES_INFO program

For the SAP System metadata, you need to create this program.

Using the SE38 transaction you can create the Z_OPTIMYTH_TABLES_INFO program. Source code for this program is available in {KiuwanLocalAnalyzer_installation_dir}\resources\abap\Z_OPTIMYTH_TABLES_INFO.abap.

Indicate following options when SAP asks:

Type of program: executable program.

Status: SAP Standard Production Program and

Application: Basis.

When SAP asks you to Create Object Directory, entry push Local Object button.

This program only extracts ABAP code and puts it in the path store in DIR_HOME variable. (DIR_HOME variable value can be checked with AL11 transaction).

Do not forget to activate the program with CTRL + F3. If you do not activate it, you could not execute it.

Create an associated transaction

To use this program from JCOConnector you need to create an associated transaction to the newly created program. This can be easily done by using the se80 transaction. Look for the Z_OPTIMYTH_TABLES_INFO program, select it , right click on it and select Create -> Transaction from the contaxtual menu.



Now the ZAINFO transaction is created and JCOConnector can be used to extract SAP metadata.

Create the Z_OPTIMYTH_WEBDYNPRO program

To extract web dynpro files you also need to create another ABAP program, following the same steps as for Z_OPTIMYTH_TABLES_INFO program. The source code for the new program is available in {KiuwanLocalAnalyzer_installation_dir}\resources\abap\Z_OPTIMYTH_WEBDYNPRO.abap.

This program also needs an associated transaction. You can create it as explained above, with the name ZWDY.

Running SAP extractor utility.

Once you have created the above programs in your SAP system, you are ready to extract the source code to plain text files.

First of all, we need configure Kiuwan_local_analyzer. Edit the {KiuwanLocalAnalyzer_installation_dir}\conf\SAPConnector.properties file. In our installation:

Now, with a small command line script, we can run the extractor:

Running this script we get out ABAP source code in the directory specified in the configuration file (c:/abap_source_code), along with the SAP metadata files and WebDynPro programs if they were configured.

You are one step away from continuous integration

You can run the Kiuwan Local Analyzer from the above script, so in one simple command you get the latest version of your code from the ABAP system, and the kiuwan analysis.

Add the following line at the end of the script:


Finally, connect to KIUWAN and see the indicators, metrics and defects that Kiuwan found for you.