In this weblog I want to give you a short introduction to the refactoring browser for ABAP classes. Furthermore I present a simple example which gives you an idea how and when to use it.
So when you have no idea what the term refactoring means be sure to check out this excellent Refactoring : Reorganizing your code which serves as a wonderful introduction. Be sure to also read the comments. If you want to know more about the origins of refactoring take a look at the first thesis about this topic from Bill Opdyke (can be found at refactoring.com). But lets start with the fun part, now.
The refactoring browser
Since I started using eclipse to develop java code I am a big fan of automatic refactoring tools. This picture shows you the refactoring browser in eclipse:
As you can see there are a lot refactorings possible. The ones I use most are: Rename and Extract method. Unfortunately both are not supported by the ABAP refactoring browser.
When I started writing ABAP classes in the first place I was not aware that the SE80 has a refactoring browser, too. One day I accidently opened the MASSIVE right mouse button menu in the SE80. I red an entry called “Refactoring Assistent”. When I clicked on it the refactoring tool opened in a popup window:
To be honest I was not impressed by the tool because like I stated before my favourite refactorings were not available. So I closed the tool and was sure I will never open it again.
How it works
I was wrong. Last week I wrote a new method in a class which had an abstract super class. I knew that the method will be useful for all the classes in the class hierarchy. So I wanted to move it from the child class to the super class. This example illustrates the idea (the method howManyTires() can be used for all vehicles as a consequence it should be moved to the abstract super class):
Back to my real-life example. At first I wanted to cut and paste the method but then remembered that the SE80 has a refactoring tool:
1) I opened it
2) I realised that I can drag and drop a method to the super class
3) I saved the refactoring
4) I activated both classes
5) I ran my unit tests -> green bar
6) Finished 🙂
The whole procedure took only two minutes and because of the automation I could be sure that everything was still working. My unit tests confirmed this assumption.
Of course the tool can do a lot more. To get all the gory details be sure to check out the official documentation at help.sap.com.
Hopefully you learned a little bit about automatic refactoring of ABAP classes. So the next time when you have to restructure a class hierarchie or just move some methods around be sure to keep in mind that there is a small but powerful tool which can make your life a lot easier.