Skip to Content
Author's profile photo Andreas Gautsch

Automatic source code formatting with ABAP in Eclipse

With ABAP in Eclipse it is very easy to format the source code of  ABAP objects. Pressing Shift + F1 before saving or activating a development object gets your written source code in a pretty format.

But even though it is not a lot of work pressing two buttons before each saving or activation step I think to a certain degree this repetitive task should be automated. I do not worry about the time needed for this manual tasks but more about the situations where the unsteady source code formatting obfuscates the build-in version database or the abapGit history.

Pretty printer is cool, so why not perform it automatically? 

Therefore I added a functionality to ABAP in Eclipse to enable automatic source code formatting of ABAP objects (currently classes, function modules and CDS views are supported). The feature is part of the free abapCI Plugin.

One important characteristic of this feature is that it does not format all objects by default, but only that ones that start with a configurable starting source code comment. This comment is configurable and if not changed the default values to be added as first line of your development object are:

  •  “#autoformat … for classes, testclasses
  •  *#autoformat … for function modules
  • //#autoformat … for CDS views

In the Eclipse preferences there is the possibility to configure and even remove this mandatory comment. But I think this could lead to unwanted formatted development objects (eg. generated data provider classes, legacy source code items with a non SAP conform style,…). Thus I decided to take the defensive path by introducing the mandatory comment …  at least for the first release.

To get the automatic ABAP source code formatting feature up and running three steps are necessary.

1. Installing the abapCi Plugin from the Eclipse Marketplace, if not already done.

2. Enabling the corresponding checkbox in the Eclipse Preferences (Window->Preferences)

 

3. Adding the above mentioned comment as first line of the development objects which should be autoformatted when saved

Starting from this point it is ensured that on each save or activation of the development object the source code formatting is automatically performed.

Hope that helps to save at least some keystrokes or even better to clear up your abapGit or transport history.

Greetings, Andreas

Assigned Tags

      15 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Christian Tapia
      Christian Tapia

      Great contribution! Is this on GitHub?

      Author's profile photo Andreas Gautsch
      Andreas Gautsch
      Blog Post Author

      Yes, the whole project for the eclipse plugin can be found at:
      https://github.com/andau/abapCI

      Author's profile photo Jacek Wozniczak
      Jacek Wozniczak

      A virtual beer goes to you ;). And dear SAP, please port this option to the good, old SAP GUI.

      Author's profile photo Andreas Gautsch
      Andreas Gautsch
      Blog Post Author

      Thanks and Cheers  🙂

      Author's profile photo Marcel Gäbe
      Marcel Gäbe

      I installed the plug-in, but i get an error. Eclipse Oxygen 3a.

       

      Author's profile photo Andreas Gautsch
      Andreas Gautsch
      Blog Post Author

      Hi Marcel. The eclipse version seems to be ok. Have you installed the latest ADT?

      But lets take a closer look next week on the details of the errormessage. This week I am on vacancies without access to my personal computer.

      Greetings, Andreas

      Author's profile photo Marcel Gäbe
      Marcel Gäbe

      Yes, i have the latest ADT installed. But more, next week =)

      Author's profile photo Andreas Gautsch
      Andreas Gautsch
      Blog Post Author

      Hmm, this error I see the first time, but well I am sure its solveable

      I made a new version today - 0.3.4, can you please update on this. If this does not solve your issue please post the stack trace of the error (should be in the error log or in the details) then I take a deeper look into this strange behaviour.

      Author's profile photo Changxing Bu
      Changxing Bu

      Thank you for sharing. I tried but the tool will affect the colors of coding. I am currently using Dark theme. Uninstall of the tool will solve the issue.

       

      before:

       

      after

      Author's profile photo Andreas Gautsch
      Andreas Gautsch
      Blog Post Author

      Hi!

      Yes, with the dark theme the color changes are not full supported. If you deactivate the following two checkboxes everything else should work like expected.

      • Change Theme layout on failed tests
      • Change color of tab header for colored projects

      Neither of the two are related to the automatic source code formatting.

      Greetings, Andreas

      Author's profile photo Changxing Bu
      Changxing Bu

      Thanks for the information. I will have a try.

       

       

      Author's profile photo Srikanth Peri
      Srikanth Peri

      Nice Tip! Great feature.

      Author's profile photo Yellappa Madigonde
      Yellappa Madigonde

      Great feature.

      Regards,

      Yellappa.

      Author's profile photo Pramod Kumar
      Pramod Kumar

      Thanks for sharing this one !!

      I was able to add this plugin and #autoformat works.

       

      Thanks,

      Pramod

       

       

      Author's profile photo Wilbert Karremans
      Wilbert Karremans

      Is this still available?