Improving Code Quality using ABAP Test Cockpit

Objectives

After completing this lesson, you will be able to:

  • Create ATC check variants
  • Perform static code checks with ATC

Static Code Checks

Syntax Check - Extended Check - ABAP Test Cockpit

ABAP Development has several tools to perform static code checks.

Syntax Check

Before you can activate ABAP code, a Syntax Check is mandatory. If you do not perform the syntax check manually, the development environment performs it implicitly during activation. If there are any syntax errors, activation is not possible. Originally, the ABAP syntax check only reported syntax errors. Nowadays, the syntax check also issues syntax warnings. The main difference between errors and warnings is the fact that warnings do not prevent activation. Despite that, you should not ignore warnings lightly. Doing so can lead to serious problems, including performance issues, data inconsistencies, and even runtime errors.

Extended Check

Since quite early in the history of ABAP, optional source code checks complemented the mandatory syntax checks. The Extended Check is not related to activation and has no influence on it. Developers decide freely whether they want to invoke the extended check and how they treat its findings.

Note
In ABAP development tools (ADT), extended check is not a tool of its own. It is only available as part of the ABAP Test Cockpit.

ABAP Test Cockpit

When Extended Check was found to be too restricted and inflexible for modern ABAP development, it was replaced by the ABAP Test Cockpit (ATC). ATC offers a large variety of checks ranging from performance checks and security checks, to checks for adherence, to guidelines and programming conventions. To offer the capabilities of Extended Check in the new check tool too, it is integrated into ATC as one of the many checks.

ATC Check Variants

ATC Check Variants

Each execution of an ATC check is controlled by an ATC Check Variant. The check variant determines which checks are performed and provides values for the parameters of the checks.

When you perform an ATC check run, you can either use the global default check variant of your system or you can specify the check variant that you want to use. This can be an existing check variant or a check variant that you created yourself.

From a technical point of view, ATC check variants are ABAP development objects. They belong to development packages and you can transport them to other systems.

How to Create an ATC Check Variant

In this demonstration, you will see how to create an ATC check variant to specify the checks that you want to perform.

Prerequisites

  • You have an ABAP (Cloud) Project in ADT (ABAP Development Tools in Eclipse).

  • Your user is assigned to a transport request for development in customer name space.

  • In your project, you already created package ZS4D401_00.

How to Run an ATC Check and Analyze the Result

In this demonstration, you will see how to execute an ATC check run on an ABAP class and analyze the result.

Prerequisites

  • You have an ABAP (Cloud) Project, a transport request, package ZS4D401_00.

  • Your package contains ATC check variant Z00_EXTENDED_CHECK.

  • Your package contains global class ZCL_00_ATC_UNUSED_VARIABLES, and the class is active.

  • You display the source code of global class ZCL_00_ATC_UNUSED_VARIABLES (tab Global Class).

Pseudo Comments and Pragmas

Pseudo Comments and Pragmas

Not all ATC findings are critical and you might decide to ignore them. Some others might turn out to be false alarms at a closer look. An example for such a false alarm is a dynamic usage of a variable, which is invisible for the static code check.

ATC has two techniques to suppress findings:

  • Pseudo Comments

    You can suppress certain ATC findings by adding a specific comment at the end of the source code line with the finding. In the example, the pseudo comment "#EC NEEDED is used. EC stands for Extended Check in this case.

    Like any other comment, a pseudo comment is not visible for the ABAP syntax check and the ABAP compiler. We call it a pseudo comment, because it has an influence on the Extended Check and ATC.

  • Pragmas

    Other findings you can suppress by adding a certain keyword starting with ## to the ABAP statement. These keywords are called Pragmas. It is very important that pragmas are placed inside the ABAP statement, not after it. In the example, pragma ##needed is used, and it is placed before the period sign that ends the DATA statement.

Note
Because pragmas are visible to the syntax check, they are also used to suppress certain warnings from the syntax check. This is not possible with pseudo comments.

If you want to know whether you can suppress a given ATC finding, refer to the finding details on the ATC Problems view. Here, you also find the information on which technique you should use.

Log in to track your progress & complete quizzes