Skip to Content
Author's profile photo Thomas Fiedler

Extracting source code using ABAP in Eclipse

In my last blog entry (http://scn.sap.com/community/abap/eclipse/blog/2013/03/05/create-a-new-method-in-eclipse-editor-via-the-form-based-method-wizard) I showed you how you can generate a new method using the Quick Fix functionality with ABAP in Eclipse.

Today I want to show you a cool refactoring feature of ABAP in Eclipse that helps you to extract parts of your existing source code into a new method.

So let’s assume you have the following code inside of one of your methods that you want to reuse in other scenarios. The idea is now that you want to create a new method and take over the code into that new method.

/wp-content/uploads/2013/03/extract1_193847.png

In order to execute that development task you just mark the source code and press ALT-SHIFT-M or use the menu Source->Extract Method.

/wp-content/uploads/2013/03/extract2_193849.png

The tool analyses the extracted source code concerning input and output behavior and calculates a proposal for the method signature. The new method including the proposed signature is now displayed in a wizard:

Extract2_1.png

On that wizard you can adjust the signature in case the proposal does not match your requirements. When you are done with your adjustments on the wizard you complete the step by pressing Finish. The tool generates the new method into your code and replaces the extracted source by the method call.

Extract3.png

Kind Regards,

Thomas.

  

Assigned Tags

      6 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Luís Pérez Grau
      Luís Pérez Grau

      Awesome!!! Thanks Thomas!

      I'm waiting for new features for ADT that makes it more compatible with the Web UI Framework...until then, for my daily work, use ADT is more a "caprice" than a productive tool 🙂

      Regards,

      Luis

      Author's profile photo Former Member
      Former Member

      Nice feature ..

      Author's profile photo Florian Henninger
      Florian Henninger

      That is so 😈 cool. Thank you!!!

      Oh, yeah, there are some words i shouldn't use.

      But it is that exciting....

      Regards

      Florian

      Author's profile photo Ebrahim Hatem
      Ebrahim Hatem

      1 (1).JPGHi,

      I got an error,

      Selection is not within a valid ABAP method implementation.

      Regards

      Ibrahim

      Author's profile photo Sebastian Wolf
      Sebastian Wolf

      Hi Ibrahim,

      extract method is only supported if you are working in classes. This error normally only comes up if the selected source code is not within such a class.

      Is this CALL FUNCTION statement in such a class?

      Best regards, Sebastian

      Author's profile photo Ebrahim Hatem
      Ebrahim Hatem

      Hi  Sebastian,

      thank you, you are right, I have tried it out with class and methods, and it does work 🙂

      Regards

      Ibrahim