Devtoberfest
Find out what's happening, and when, in the Devtoberfest schedule – don't miss out!
cancel
Showing results for 
Search instead for 
Did you mean: 

🟢 How to Clean your ABAP code in Seconds with ABAP Cleaner

Devtoberfest

ABAP cleaner executes 60+ cleanup rules on your ABAP code at a single keystroke – while giving you and your team full control over the selection and configuration of these rules. It was published in April 2023 as an Open-Source project with the ambition “to automate whatever can be automated” with respect to ABAP code style.

Join this session to see what ABAP cleaner offers, how it is installed, used and configured, and how it relates to other Open-Source projects like Code pal for ABAP and the Clean ABAP style guide.

Link to the presentation used in the session : https://dam.sap.com/mac/u/a/yPnDZ6e.htm?rc=10 

After watching the session, be sure to complete the validation tutorial to earn points for Devtoberfest!   https://developers.sap.com/tutorials/devtoberfest2023-week2-abap-cap-abapcleaner.html

Speaker : Joerg-Michael Grassau, SAP



Event has ended
You can no longer attend this event.

Starts:
Ends:
14 Comments
PrathapTelukutl
Explorer

Does these rules apply to CDS views and Fiori UI code as well?

sheenamk
Developer Advocate
Developer Advocate

No, unfortunately that's currently out of scope, so as of now, ABAP cleaner only cleans ABAP code.

babuilyas
Participant

Does it work with ABAP Cloud to-be exact RAP syntaxes.

 

sheenamk
Developer Advocate
Developer Advocate

Unfortunately, as of now, RAP is not covered by the cleanup rules.

babuilyas
Participant

The reason could be RAP syntaxes are already minimalistic. 😉 

kasithunuguntla
Participant

Very useful session. Thanks so much Joerg.

Somenath_WIN
Explorer

Thank you for the amazing session. Looking forward to use the ABAP cleaner.

LuisBenavidesA
Participant

An excellent session that enlightened us about ABAP Cleaner, shedding light on its functionality and how it operates. This tool proves highly beneficial for enhancing productivity and refining technical documentation. Great job!

TMNielsen
Contributor

Impressive thorough work put into this tool (and into the presentation).

Maybe I shouldn’t comment on this without actual experience using the tool, but these are my initial thoughts.

Some of the rules will really make code more readable.

Other of the rules seems more religious and will not really add value.

A few of the rules will make it more difficult to extend the code later. For example, I think the rule “Remove long IF blocks at method end” and “Use Final for immutable variables” could end up being contra-productive.

 



sheenamk
Developer Advocate
Developer Advocate

Thanks very much for the feedback! This underlines quite well why it makes sense to keep the tool configurable, because every situation is a bit different (new code / legacy code, requirements to downport, team preferences etc.). 

Regarding "religious" cleanup rules :-), even those could make the code more readable if they make its syntax and appearance more consistent; but nobody will be offended if you deactivate such rules! 

"Remove long IF blocks at method end" might depend on configuration ("Replace IF blocks with at least ### lines"). There are legacy code methods out there with IF blocks spanning hundreds of code lines… on the other hand, the cleanup rule somewhat goes against the principles of structured programming (which demands a method to have exactly one entry point and one exit point). 

"Use FINAL for immutable variables" is actually deactivated by default, because this keyword is rather new to ABAP, so it may only make sense on new code that does not need to be downported. Since this is always only local (inside of a method), it would be easy to change if the respective method needs to be enhanced later. And the rule has a careful approach, so, whenever a reference is created to a variable (which could be passed on to another method etc.), FINAL will not be introduced (see the examples of this rule). 

Anyway, thanks for your thoughts, and as you can see on the issues in the ABAP cleaner repository, new suggestions always come with some discussion until good defaults and configuration options are found to address the various needs!

guydebruyn
Discoverer

Very nice tool.

But why is CONTINUE considered clean ABAP? Like CHECK (and sometimes RETURN if not used as exception handling) it is a glorified GOTO statement. Over time I had run into so many bugs that were somehow caused by lack of readability because of those statements. Worst was maybe an infinite loop in DO. ... ENDDO with many EXIT statements inside. Maybe it is more pleasing the eye, but in reality, the same conditional logic is used that is now hidden. Indented IF statements show what it really is. And if too much clutter: simply break up the methods into smaller logical pieces.

TMNielsen
Contributor

Well I do not agree that a lot of spaghetti if statements are better than CONTINUE, CHECK and RETURN.

But abap editors could be improved. When we double click on one of the above statements, It would be great help if the cursor would actually jump ( GOTO 🙂 ) whatever statement will be next in the process.

Examples:

  • double click on CHECK inside a loop should move the curser to the line with the LOOP command
  • double click on continue inside a loop should move the curser to the line with the LOOP command
  • double click on CHECK inside a subroutine should move the curser to the line with the ENDFORM command
  • double click on EXIT inside a loop should move the curser to the line with the ENDLOOP command
  • double click on EXIT inside a subroutine should move the curser to the line with the ENDFORM command
  • and so on.

I know this suggestion has nothing to do with clean code, but the purpose is kind of the same. It should be easier to read and navigate existing code.

milusai
Participant

milusai_0-1695798401788.png

I'm unable to install in eclipse, can anyone help with above error ? 

martinc_mb
Participant

It may be that you are behind a corporate firewall and there is an SSL problem (because your company inserts its own certificates into the chain). I cannot really tell because you don't have the complete log there.

In this case (and if you are on Windows), follow the instructions here: java - Importing SSL Certificate into Eclipse - Stack Overflow