Technical Articles
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
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.
Select Pull to copy all objects from the Git repository into your SAP system:
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
and by selecting all code pal for ABAP checks and clicking the Save button:
After that create a new global check variant, e.g. ZCLEAN_ABAP. Select the code pal for ABAP checks group and save it:
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…
and choose ZCLEAN_ABAP as a check variant:
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.
What is next?
Next topics on the roadmap:
- Cloud enablement: code pal checks will run on SAP BTP ABAP environment incl. their remote enablement
- Quick fixes to automate and thus speed up the adaptation to Clean ABAP
Note that it does not guarantee adherence to Clean ABAP, checks are both non-exhaustive and some not relevant for Clean ABAP
Hi Lars,
thanks, changed it!
Kind Regards,
Olga.
Hi Olga,
thank you for sharing that blog! We are actually using Code Pal for quite some time and I can also confirm that it allows some checks that are very helpful to introduce Clean Code rules to ABAP. 👍
I am wondering about status of Code Pal for ABAP project. There is hardly any activity in Code Pal on Github since release 1.17 was withdrawn in February and it looks like (from the outside..) that development only continues at SAP internally. 😟 Can you share some insights on that? -- Thank a lot!
Cheers,
Alej
Hi Alej,
Code Pal is open source, here you can see the commits, which have happened lately, e.g. in March 2022. This improvement for example was done by a non-SAP employee.
Kind Regards,
Olga.
Hi Olga,
thank you for yor response. I was aware of that improvement from community, but there were no commits from SAP since February - although being a very frequent contributor in the past.
That's why I was wondering whether SAP may have dropped that project (or does not make updates public on Github)?
Cheers,
Alej
Is the Code Pal really open source?
Open source implies if I find a bug and/or have an improvement I can submit this via GitHub?
Is this the case or can only SAP employees suggest changes?
Cheersy Cheers
Paul
Hi Paul,
yes, the Code Pal is really open source. Here you can see for example the small improvement, which was contributed recently by the non-SAP employee. Feel free to submit your improvements or detected bugs :-).
Kind Regards,
Olga.
Thanks for this helpful blog post, Olga!
I immediately followed the outlined steps (just used the ZIP-File option to grab the checks from Github) and successfully added the CodePal checks in one of our sandbox systems. But, when I then run ATC Checks with the new check variant I don't get any findings, just the message "The objects passed the chosen checks without any finding". Considering that I tried with a complex old procedural ABAP program which contains many MOVE-statements, it seems as if the checks haven't actually been executed as it should have found "something". The check also runs fairly quickly as it's not really doing much of anything. Other checks are running and produce results.
I'm working in a NW7.50 system with SP 22.
Do you have an idea what the issue could be and/or where I could look for the root cause?
Thanks much and cheers
Bärbel
Hi Bärbel,
if it's just about the Code Pal checks - other ATC checks returning results on the same objects - then the best way to get support for this is to open an issue in the CodePal repo. If other ATC checks do not deliver anything either, then a normal customer message is appropriate.
Best Regards,
Olga.
Thanks, Olga!
Other checks produce the expected results. It's just as if the CodePal checks are completely ignored which seems to be corroborated by SAT-checks I just ran: none of the new Y_CHECK-classes makes an appearance in the results if I either run the CodePal check variant or if I add the CodePal checks to an existing check-variant.
As I try this in a sandbox system I put the checks into a $-package. But this shouldn't have a bearing on them getting executed or not, I hope?
I'll open an issue in the repo to see what's what!
Cheers
Bärbel
Hi Bärbel,
just one idea: have you actually activated the Code Pal checks in SCI (as described in the blog)?
Thanks!
Olga.
Hi Olga,
yes, I checked all the boxes and saved the setting:
When I hit save, a transport request pop-up was displayed and I had to click <Enter> multiple times, i. e. once for each of the checks (which was a bit weird, to be quite frank!) and they now show up in the transport:
I can also include them in an existing check variant:
Really not sure what's "happening" here to make them not getting executed...
Cheers
Bärbel
Olga Dolinskaja
Hi Olga,
I think I narrowed down the reason why the checks don't find anything: it seems to have to do with when a program was created. Here is why I think that: the program I tried with was created several years ago and even though the checks seem to get accessed when I run it in debugging, no issues are found. I just now copied the whole program into a new local copy and ran the checks again and now it produces the expected long list of issues.
This "cut-off" date seems to be definied in the select-options for each check:
So, it can be manipulated there for each check which is just a wee bit tedious. Some questions:
I also headed over to Github to add this as an update to the issue I created on Github: https://github.com/SAP/code-pal-for-abap/issues/560
While there, I noticed an update from Björn pointing to the solution as well as the profile management tool where the settings like the cut-off date can be tweaked. How about adding this to your blog post to make others aware of it and to avoid them running into the same situation I did?
Thanks much and cheers
Bärbel
Hi Bärbel,
thanks for your investigations and effort! I've updated the blog according to your suggestion.
Best regards,
Olga.
Great post
Hi All,
thanks for sharing.The findings are cool, however I recognized reading the Clean ABAP/Code Pal reference docs in more detail is still a must. Some of the ATC finding descriptions are short, or at least not trivial what to do with them for the first time without background information / further searching.
I remember one of the great Paul Hardys books with a link to abapOpenChecks. Are the checks complementing or covering each other ? Should we use both ?
I am trialing this at the moment and noticed that the new variant is not showing up in ADT, but in case I manually input the name and execute, then it works fine actually. I am running the 1909 developer edition on docker, so no official SAP support is possible, but this can be a good hint for others.
Best regards, Attila
Hallo Olga,
as I saw all checks are for local scenario, not remote enabled.
Is it planned to add this checks to SAP Standard as remote enabled checks or will they only be available as Open Source on GitHub ?
Thanks a lot,
Volker
Hi Volker,
the code pal checks will stay Open Source, we don't have any plans to add them to SAP standard checks. Please address your improvement request about the remote enabling via GitHub.
Best regards,
Olga.