Saturday, 28 May 2022

How to enable clean code checks for ABAP

The Open Source contribution Clean ABAP style guide for ABAP coding offers best practices and set of rules for you as developers to enable you to write more efficient, easier to understand and maintainable code. Having a common understanding of the code style enhances consistency of the code base and thus significantly improves your developer experience enforcing to work more quickly with even unfamiliar code and speed up the ramp up of new developers in your environment.

The style guide allows to enforce rules with static code checks. Based on the Clean ABAP, the free and Open Source code pal for ABAP tool contains a set of checks to support the Clean ABAP adherence. Code pal for ABAP checks can be used in Code Inspector and ABAP Test Cockpit.

Install code pal for ABAP via abapGit

In order to install code pal for ABAP you need to pull the Git repository using abapGit. If you don’t have abapGIT in your system then just install standalone abapGIT version.

Start abapGIT

SAP ABAP Career, SAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP News, SAP ABAP Tutorial and Materials, SAP ABAP Preparations

and select New Online:

SAP ABAP Career, SAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP News, SAP ABAP Tutorial and Materials, SAP ABAP Preparations

Enter the link to the code pal Git repository https://github.com/SAP/code-pal-for-abap.git  along with a package name e.g. ZCODE_PAL_FOR_ABAP. This package will be created automatically when pulling from the Git repository. Alternatively, you can select Create Package to create the package manually with your own settings. Use Folder Logic Prefix and enter Display Name e.g. code-pal-for-abap. Select Create Online Repo.

SAP ABAP Career, SAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP News, SAP ABAP Tutorial and Materials, SAP ABAP Preparations

Select Pull to copy all objects from the Git repository into your SAP system:

SAP ABAP Career, SAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP News, SAP ABAP Tutorial and Materials, SAP ABAP Preparations

Configure code pal for ABAP checks


Start Code Inspector (transaction SCI)  and activate code pal for ABAP by using the menu Code Inspector->Management of->Checks

SAP ABAP Career, SAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP News, SAP ABAP Tutorial and Materials, SAP ABAP Preparations

and by selecting all code pal for ABAP checks and clicking the Save button:

SAP ABAP Career, SAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP News, SAP ABAP Tutorial and Materials, SAP ABAP Preparations

After that create a new global check variant, e.g. ZCLEAN_ABAP. Select the code pal for ABAP checks group and save it:

SAP ABAP Career, SAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP News, SAP ABAP Tutorial and Materials, SAP ABAP Preparations

You can also use the „Attributes“ button

SAP ABAP Career, SAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP News, SAP ABAP Tutorial and Materials, SAP ABAP Preparations

to configure the applicability of a check for example according to the object‘s creation date or severity of an ATC message:

SAP ABAP Career, SAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP News, SAP ABAP Tutorial and Materials, SAP ABAP Preparations

For advanced users: You can also use the code pal profile management tool to configure the code pal checks behavior for your individual needs (e.g. check filter on object creation date, validity period etc.). But please be aware, that if you assign a profile to your user, it will overwrite the Code Inspector variant.

Execute clean code ABAP checks


Congratulations! Now you are able to execute your clean ABAP (abap code pal) checks over your code. Just select the package in your project in the ADT in Eclipse (ZCLEAN_ABAP_DEMO in our example), use the context menu Run As -> ABAP Test Cockpit With…

SAP ABAP Career, SAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP News, SAP ABAP Tutorial and Materials, SAP ABAP Preparations

and choose ZCLEAN_ABAP as a check variant:

SAP ABAP Career, SAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP News, SAP ABAP Tutorial and Materials, SAP ABAP Preparations

The result list with the ATC findings from clean code checks will be displayed in the ATC Problems View and you can navigate to the details of each finding and process the list to fix the issues in order to make your code adherent to Clean ABAP.

SAP ABAP Career, SAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP News, SAP ABAP Tutorial and Materials, SAP ABAP Preparations

No comments:

Post a Comment