ABAP Cleaner: Streamline Your Code for Enhanced Quality and Productivity
Tags: sap, abap, sapabap, cleancode
Published: 2023-07-28 06:40:42

This blog is to guide all Abapers on how to achieve clean code using ABAP Cleaner and not only to understand the advantages of clean ABAP and also how to use ABAP Cleaner.

**ABAP Cleaner**
The ABAP Cleaner tool is used to clean up ABAP code by applying various clean-up rules.

Here are some reasons why you might want to use the ABAP Cleaner tool:

1. Automation: The ABAP Cleaner tool automates the process of cleaning up ABAP code, saving you time and effort.
2. Uniformity: By using the ABAP Cleaner tool, you can ensure that your code follows a consistent style and structure. This improves code readability and makes it easier for other developers to understand and maintain the code.
3. Error reduction: Following clean ABAP principles, which the ABAP Cleaner tool helps enforce, can reduce the number of errors and misunderstandings in your code. Clear and well-structured code is less prone to bugs and easier to debug.
4. Modernization: The ABAP Cleaner tool encourages the use of modern language features and coding techniques. This is important if your organization plans to migrate to newer technologies like S/4HANA or the Cloud.
5. Collective code ownership: Adopting clean ABAP practices fosters a culture of collective code ownership and feedback. It encourages collaboration and allows multiple developers to work on the same codebase more effectively.
6. Maintainability: Clean ABAP code is easier to maintain and modify. It follows best code organization and readability practices, making it easier to add new features or make changes without introducing bugs.

**What is ABAP Cleaner?**
ABAP cleaner is a configurable tool that aims to automate whatever can be automated concerning ABAP code style.

**What the ABAP Cleaner Tool Offers?**
ABAP cleaner offers 59 cleanup rules with a total of 186 configuration options. Whereas, previously it offered 57 cleanup rules with a total of 162 configuration options.

**Empty Lines**
[Standardize empty lines within methods](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/EmptyLinesWithinMethodsRule.md)
[Separate methods and classes with empty lines](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/EmptyLinesOutsideMethodsRule.md)
[Standardize empty lines in class definitions](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/EmptyLinesInClassDefinitionRule.md)

**Spaces**
[Standardize spaces next to parentheses](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/SpacesInEmptyBracketsRule.md)
[Close brackets at line end](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/ClosingBracketsPositionRule.md)
[Remove space before commas and period](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/SpaceBeforePeriodRule.md)
[Put spaces around “ comment sign](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/SpaceAroundCommentSignRule.md)
[Remove needless spaces](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/NeedlessSpacesRule.md)

**Declarations**
[Unchain into multiple statements](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/ChainRule.md)
[Rearrange local declarations](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/LocalDeclarationOrderRule.md)
[Delete unused variables](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/UnusedVariablesRule.md)
[Simplify a chain with one element](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/ChainOfOneRule.md)
[Make implicit type explicit](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/ImplicitTypeRule.md)
[Use FINAL for immutable variables](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/FinalVariableRule.md)
[Standardize escaping of !parameters](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/EscapeCharForParametersRule.md)
[Remove empty class definition SECTIONs](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/EmptySectionsInClassDefRule.md)
[Add missing parameters to ABAP Doc](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/AbapDocParametersRule.md)
[Remove lang=”en” from ABAP Doc](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/AbapDocLangRule.md)

**Syntax**
[Comment with “, not with * (for text)](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/CommentTypeRule.md)
[Replace obsolete pseudo comments with pragmas](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/PseudoCommentRule.md)
[Move pragmas to correct position](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/PragmaPositionRule.md)
[Correct frequent typos](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/TypoRule.md)
[Resolve equals sign chain into several commands](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/EqualsSignChainRule.md)
[Prefer calculation assignment operators (+=, -= etc.)](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/CalculationAssignmentRule.md)
[Prefer =, <>, <= etc. to EQ, NE, LE etc.](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/ComparisonOperatorRule.md)
[Prefer IS NOT to NOT IS](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/NotIsRule.md)
[Move AND/OR etc. from line end to next line start](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/LogicalOperatorPositionRule.md)
[Remove empty commands](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/EmptyCommandRule.md)
[Shorten VALUE statements](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/ValueStatementRule.md)
[Remove the self-reference me->](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/SelfReferenceMeRule.md)
[Omit RECEIVING](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/ReceivingKeywordRule.md)
[Omit optional EXPORTING](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/ExportingKeywordRule.md)

**Commands**
[Convert CHECK outside loop to IF NOT … RETURN](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/CheckOutsideLoopRule.md)
[Convert CHECK in loop to IF NOT … CONTINUE](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/CheckInLoopRule.md)
[Replace long IF blocks at loop end](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/IfBlockAtLoopEndRule.md)
[Replace long IF blocks at method end](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/IfBlockAtMethodEndRule.md)
[Replace CALL METHOD with functional call](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/CallMethodRule.md)
[Replace CREATE OBJECT with NEW constructor](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/CreateObjectRule.md)
[Replace RAISE … TYPE with RAISE … NEW](Replace RAISE … TYPE with RAISE … NEW)
[Replace obsolete ADD … TO etc. with += etc.](Replace obsolete ADD … TO etc. with += etc.)
[Replace obsolete MOVE … TO with =](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/MoveToRule.md)
[Replace TRANSLATE with string functions](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/TranslateRule.md)
[Use assert_true and assert_false](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/AssertEqualsBooleanRule.md)
[Use assert_subrc instead of assert_equals](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/AssertEqualsSubrcRule.md)
[Use assert class instead of ASSERT](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/AssertClassRule.md)

**Pretty Printer**
[Convert upper and lower case](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/UpperAndLowerCaseRule.md)
[Indent lines](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/IndentRule.md)

**Alignment**
[Align ABAP Doc](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/AlignAbapDocRule.md)
[Align METHODS declarations](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/AlignMethodsDeclarationRule.md)
[Align METHODS … FOR TESTING](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/AlignMethodsForTestingRule.md)
[Align METHODS … REDEFINITION](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/AlignMethodsRedefinitionRule.md)
[Align ALIASES … FOR …](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/AlignAliasesForRule.md)
[Align declarations](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/AlignDeclarationsRule.md)
[Align assignments to the same object](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/AlignAssignmentsRule.md)
[Align keywords with second word of first line](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/AlignWithSecondWordRule.md)
[Align CLEAR:, FREE: and SORT](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/AlignClearFreeAndSortRule.md)
[Align parameters and components](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/AlignParametersRule.md)
[Align logical expressions](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/AlignLogicalExpressionsRule.md)
[Align conditional expressions](https://github.com/SAP/abap-cleaner/blob/main/docs/rules/AlignCondExpressionsRule.md)


**Requirements and Installation**
To install and use the **ABAP cleaner plug-in for ABAP Development Tools** (ADT) on Windows or macOS,

1. 1. Install ABAP Development Tools as described in the [Install ADT Tutorial (Step 1)](https://developers.sap.com/tutorials/abap-install-adt.html), using an Eclipse installation that is [compatible with ADT](https://tools.hana.ondemand.com/).
2. Start ADT, select the menu ‘Help / Install New Software…’, copy the link [https://sap.github.io/abap-cleaner/updatesite](https://sap.github.io/abap-cleaner/updatesite) to the ‘Work with’ field, and follow the installation steps, confirming to install ABAP cleaner. [(Known issues)](https://github.com/SAP/abap-cleaner/blob/main/docs/installation-issues.md)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9l4jn91a46wqrwrwst73.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vud8wramajaq3eh9xfpc.png)

After restarting ADT, open an ABAP code document in an editor, and use the menu ‘Source Code / Clean Up With Interactive ABAP Cleaner…’ (shortcuts Ctrl + 4 or Ctrl + Shift + 4),

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7xyn9k1osua17zynha9h.png)

If you select the first option “Clean Up with Automated ABAP Cleaner” it will automatically clean up the code based on the profile we have set up.

If you select the second option “Clean Up with Interactive ABAP Cleaner” here we can select the rules that we want to reflect in our code and here we have many options.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dzn3ghu7vy30fe23cy79.png)

If we already created the profile, we can directly click on the “Save and Apply” button to apply the desired rules to be applied.

If we want to create a profile we need to click the configure button on the right corner.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1w48ylfnzm0sdnxz3jwy.png)

On the top left in the profiles section we can Create, Copy, Delete, Import, and Export profiles.

On the bottom left in the rules section, we can check the checkbox that should clean up our code.

If the selection of rules is completed then click on the _“save profiles and exit”_ button on the bottom right.

So, now we are set to give it a try.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uznkthhzup7g1162tu7v.png)

In summary, the ABAP Cleaner tool is a valuable tool for automating the clean-up of ABAP code, ensuring uniformity, reducing errors, promoting modernization, fostering collective code ownership, and improving maintainability.

Have you used the ABAP Cleaner tool before? What was your experience like? Do you have any questions about Clean ABAP or the ABAP Cleaner tool?

Please feel free to share your thoughts in the comments section below.