Skip to Content

Introduction

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.

Refactor… what?

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:

image

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:

image

image

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):

Before After
image image

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

image

3) I saved the refactoring

image

4) I activated both classes

image

5) I ran my unit tests -> green bar

image

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.

Conclusion

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.

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Peter Inotai
    Hi Thomas,
    Thanks for this weblog. I didn’t know this tool before, but it’s quite useful … and it’s called “Refcatoring Assistant” in WAS 6.20 🙂
    Peter
    (0) 
    1. Community User
      Hi Peter,

      I am glad you like the tool, too. Btw you can see the typo “Refcatoring Assistant” in the screenshots and it is in the WebAS 620 and 640. But the german translation is without the typo 🙂

      regards
      Thomas

      (0) 

Leave a Reply