Technical Articles
Clean code checks for ABAP – Cloud Edition
This blog is the follow-up on the blog How to enable clean code checks for ABAP, which describes how the code pal for ABAP checks can be used in the Code Inspector and ABAP test cockpit to check your code for the adherence to the Clean ABAP style guide.
Now there is a new free and open source version of code pal for ABAP cloud checks, which (as the name already states) is cloud-enabled, thus the checks can now be executed in SAP BTP ABAP Environment. Beyond this all checks are now remote-enabled and can be run in the remote ABAP test cockpit scenario. Additionally, to speed up your code adaptation to Clean ABAP for many findings quick fixes are provided in the ABAP development tools for Eclipse to automate your adjustment tasks.
Let’s take a look at how you can use code pal for ABAP cloud checks in your SAP BTP, ABAP environment system to check your code for Clean ABAP.
Technical Prerequisites
The code pal for ABAP cloud checks can be executed in SAP BTP, ABAP environment.
If you want to check your on-premise releases (or SAP S/4HANA Cloud, private edition systems) with code pal for ABAP cloud checks you can do it remotely from SAP BTP, ABAP environment, see also the blog ABAP Test Cockpit in the Cloud – What is already possible for more details.
You need abapGit to pull the checks from the Git repository into your system. For SAP BTP, ABAP environment systems install abapGit plugin for ABAP development tools for Eclipse.
Install code pal for ABAP cloud checks via abapGit
In the SAP BTP, ABAP environment system you will use ABAP development tools for Eclipse and abapGit plugin to install code pal for ABAP cloud checks.
Create a new package in the /CC4A/ namespace, and name it for example CODE_PAL. The source code of code pal for ABAP checks is located in the /CC4A/ (Clean Code for ABAP) namespace, so that collisions with Y*/Z* objects from other projects are avoided.
Open abapGit Repositories View in your ABAP development tools for Eclipse:
Click the „+“ button to link the new abapGit repository:
and enter the path to the GitHub repository https://github.com/SAP/code-pal-for-abap-cloud, containing the code pal for ABAP cloud checks:
In the next step enter the name of your newly created package /CC4A/CODE_PAL and check the Pull after link checkbox:
Finally, after completing the abapGit plugin wizard, the code pal for ABAP cloud checks repository will be linked:
and the source code of the check implementations pulled under your newly created package /CC4A/CODE_PAL:
Just activate all source code objects and the code pal for ABAP cloud checks are ready to use.
Execute code pal for ABAP cloud checks
The check variant /CC4A/CODE_PAL_FULL contains all available code pal for ABAP cloud checks:
There is also the package /CC4A/CODE_PAL_TEST_OBJECTS, which you can use to see how the code pal for ABAP cloud checks work. Just select this package and use the context menu Run ABAP Test Cockpit With…
Enter the ATC check variant /CC4A/CODE_PAL_FULL and click the OK button to execute the ATC run:
The ATC Problems View provides the check results concerning violations of the Clean ABAP rules in the source code objects of the test package:
Now you can select your own development package(s) or set(s) of the development objects which you want to check and execute the code pal for ABAP cloud checks over these objects.
Use quick fixes
If you take a look at the ATC results, the yellow bulb icons before the ATC findings indicate that for these ATC findings the quick fixes in ABAP development tools for Eclipse are available, which allow to fix these findings in an automated way.
By navigating from an ATC finding to the corresponding source code line you can see the examples of the violations of the Clean ABAP rules and can try out the corrections, which are provided by quick fixes using the Ctrl + 1 shortcut.
In the following example the code pal for ABAP cloud check detects the unnecessary self reference, which can be removed via the quick fix:
In the next example the check finds a chain declaration, which can be replaced with separate declarations of the variables involved using the quick fix:
In the last example the values are allocated more than once within one statement and the quick fix will break the assignment chain into multiple statements:
You can also use mass-enabled quick fixes (context menu Recommended Quick Fixes will start the wizard) to adapt all ATC findings at once:
Further information
Further information on code pal for ABAP cloud checks, including how to contribute to this open source project, provide feedback or get support, is provided on the GitHub under https://github.com/SAP/code-pal-for-abap-cloud/. Use “Watch” button to get notified about changes (you get it if you log in to GitHub).
The check migration list shows the current migration status of checks from the legacy version.
What is next
We also plan to offer the code pal for ABAP cloud checks in the upcoming releases of SAP S/4HANA Cloud, private edition and SAP S/4HANA on-premise.
Thanks. But I'm surprised to see that the first example of DATA is not Clean ABAP 😉
Clean ABAP: "No more than one statement per line".
Hi Sandra,
that is currently a gap in Quick fix infrastructure that line breaks are not supported yet. For sure it is not the idea to code all DATA declaration into one single code line 🙂
Regards,
Thomas.
Hi Olga!
I appreciate you sharing this solution.
I've been experimenting with ABAP Cleaner, and I must say I'm quite impressed with its customization options. It does indeed appear to align closely with your description.
I'm curious, do you have any thoughts or opinions on ABAP Cleaner?
Thanks,
Ruthiel
Hi Ruthiel,
it's great, that you are using ABAP Cleaner!
Both tools (code pal and ABAP Cleaner) follow the same rules from the Clean ABAP guide, the difference is in the use case. If you want to convert existing code to clean code, then the ABAP test cockpit test mass run with code pal checks and quick fixes (as in the blog) is the way to go. Íf you write a new code and want to immediately comply with the Clean ABAP rules, then you would save the source in the editor and run the ABAP Cleaner over it because it is more effective as activating the code first and then using ABAP test cockpit with code pal checks and quick fixes.
Kind Regards,
Olga.
Hello Olga!
Thank you for the detailed explanation!
I realize now that I can use both of them!
There is no excuses for "unclean" code nowadays!!!
All the best,
Ruthiel
Hi Olga,
Thank you for the information about this Eclipse tool for ABAP. When installing it, there is a warning that the content is unsigned and of unknown origin - is it safe to trust unsigned content -?
Regards, Shasank
Hi Shasank,
if it happens at installation of the abapGit plugin, then it is ok to ignore the warning, because abapGit is a popular, well-known and old enough plugin (in a sense that if there had been security problems, other users would have reported them long ago).
Kind Regards,
Olga.
Hello Olga
Our infrastructure is on prem but we intend to use Code Pal via Remote system (our existing ATC + CVA checks happen via Remote - central hub system). I read a line on your blog that says all checks are now Remote enabled which were not before. Could we install Code Pal via AbapGit on our remote system and use it for connected system by integrating the checks on existing variant?
Our developers have also found an attribute on the source code where they can change the checks from local to remote enabled but by then we didn't see this blog. Is it recommended to change the attribute on Source code?
Regards
Anuj
Hi Anuj,
currently the checks cannot be used on an-premise ATC system. The upcoming S/4HANA 2023 release will be supported.
Regards,
Thomas.
Hello Thomas
Just making sure I understand this correctly, we can use Code Pal locally on our S/4 HANA 2021 version locally as checks are not remote enabled but we won't be able to use them remotely.
Upcoming S/4 HANA 2023 release would bring support for Remote checks when Code Pal is installed.
Is the understanding correct?
Also, how about if we install the Code Pal on our ATC Remote check system and alter the attribute to have them remote enabled. Our developers have already done that and tested . Do you see any challenges with this approach?
Considering the program we are running we won't be looking at lastest upgrade for another couple of years.
Regards
Anuj
Hi Anuj,
if you want to use Code-PAL on S/4HANA 2021 you have to use this Github Repo: https://github.com/SAP/code-pal-for-abap/
But these checks are not remote enabled !
Just changing the flag does not mean that the checks are working remotely.
Regards,
Thomas.