We continue our series of posts on ABAP code analysis with Sonar. Today: the extraction of code.
We have seen in our first article Sonar & ABAP – What you need to know, that the ABAP code is stored in the SAP Workbench, so that we’ll have to install a program in the Workbench to extract the code to analyze. Yes, we will have to connect to the Workbench to install and run this program.
If you are a SAP specialist and have decided to follow our series of posts to find out how Sonar can help you improve the quality of ABAP code, then you know how to access the SAP Workbench and perform the installation of this extractor.
If you already use Sonar but know nothing about SAP, do not worry: it is unlikely that you are given access to a Workbench, and a SAP administrator will take charge of this installation.
Later, no need for an administrator to perform extractions, anyone can make them easily and without any knowledge of the Workbench. Your client or the project team will do this extraction for you, as they have the knowledge of the objects (programs, includes, function-pools, etc..) to analyze.
Download the Sonar extractor
You can download it from the following page on the Sonar website, about the installation of the ABAP plugin.
In this page, you can find 2 links to download the code of the extractor, for different SAP releases: ‘Version 6.20 to 6.40’, ‘Version 7.00+’. These ABAP programs are based on Mass Download programs developped by Dalestech Consulting Ltd.
Retrieve the two programs, but it is very likely that you will use the extractor for release 7.00+ because the other versions are really old.
Installation of the Sonar extractor
Even if an administrator will perform the following tasks, better facilitate him the job and tell him what we want to do. And give him an overview as well (note: you can click on all the screenshots below to enlarge them for more details).
Once in SAP …
Enter the transaction SE38 to create a program and, in the corresponding screen, enter the name of the program (in this example ZTEST1000) of type ‘Source Code’. We have seen in the post Sonar & ABAP – The questions that your programs begin with the letter ‘Z’ or ‘Y’.
Then enter a description for this program, and its type ‘Executable’ (as opposed to module-pool, include, etc.)
Warning: the SAP administrator will then ask you in what package to “transport” the program. Without going into details, it should be noted that any new or modified ABAP code follows a validation workflow where it is “transported” from the development server to the production server. In this case, we do not need to validate our program as no local developer created it and we will be the only user to run it in the future.
We will therefore inform the administrator that the program will not be “transported” and for this reason, we will save it in the local package:
OK. We have done the most difficult. Now we have to enter the source code of our extractor in the ABAP program that we just created. A simple Copy / Paste in the Workbench’s editor will do:
Activate the program, which will check the syntax of the program, save it and make it available for execution.
Use of the Sonar extractor
It is possible to run our program using the same transaction SE38, which allows us to run it in different modes (directly, in debug mode or in background mode). In the following example, the administrator (user SE43737) has two ‘local’ programs that can be selected for execution.
It is also possible to use the transaction SA38 specifically dedicated to users. It is even possible to develop a specific screen that will call this program. Again, it all depends on your use case, who will perform the extraction, how often, on what scope (SAP areas, servers, etc.).
But in any case, you will need to make at least once the installation of the ABAP extractor ABAP and a first test.
Once the program is running, you can enter the first letters or the names of objects you want to download: classes, programs, etc. (regarding the types and classifications of object, see the post Sonar & ABAP – What y9u need to know). Again, your customer or the project teams will decide which code to analyze and how to extract it.
The Sonar extractor is able to fetch all objects used by the code that you want to extract. Here we see that our extraction also incorporate other objects as Include, Function, etc..
So, you can know exactly what there is in your extraction.
Just retrieve the code extracted locally on the machine from which you have completed all these operations, and transfer it on your Sonar platform.
In the next posts, we will see the analysis and its preparation, as well as ABAP rules and best practices. Do not hesitate to ask for any precision.
This post is also available in Leer este articulo en castellano and Lire cet article en français.