Skip to Content
Author's profile photo Thomas Fiedler

Create a new method in eclipse editor via the form-based method wizard

A very useful feature in ABAP development is the possibility to create a new method from the editor via the form-based method generation wizard. Here I will show you how you can do that with ABAP in Eclipse:

So let’s assume you are in the editor implementing your ABAP code in a class method.

Now you recognize that you need a new method that you want to call within your created code.

You can now navigate to the definition part of the class to add the method signature, implement the method and navigate back to the call position of the newly created method. That’s a bit cumbersome, isn’t it. 😕

Why not do the following:

You can create the new method by just typing the name of the non-existing method in the editor and use the Quick Fix functionality. You do this just via pressing CTRL-1 when the cursor is positioned on the method name:

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

   

On the upcoming Quick Fix popup you choose the option Create method ….

The editor now opens a wizard to define the signature of the new method:

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

 

You can now specify the most relevant details of the method like visibility, access scope and the name.

In addition you can specify the parameters of the method via the table control. You can define whether you need importing, exporting, changing or returning parameter and you can specify the parameter type with very nice value help in the editor cell. 

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

   

 

When you are ready with the declaration you press Finish and you’re done.

The editor now automatically generates out of this information the method declaration and the method implementation:

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

You can now directly go ahead with your implementation.

Kind Regards,

Thomas.

Assigned Tags

      14 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Hendrik Brandes
      Hendrik Brandes

      Hello Thomas,

      thank you for showing this. For me as an SE80-fanatic, it has been(and still sometimes is) hard to move to AiE. Especially, I like (...) the form-based class builder, because it/he makes the declarations for me;-)

      But: The key-features of the Eclipse-platform prevail the the effort for an experience developer to move from SE80 to AiE. Hopefully, more and more features are implemented! 

      Say a "Well done" to all members of the AiE-Team!

      Kind regards,

      Hendrik

      Author's profile photo Adam Krawczyk
      Adam Krawczyk

      Hi Thomas,

      Nice blog, thank you.

      I recommend to use this approach (CTRL + 1 method for method wizzard) also for unit tests, it is really simple to create new test case methods.

      Another useful feature here is types autosuggestion. So if you have types declaration before call:

      DATA l_carrid TYPE s_carrid.

      DATA l_connid TYPE s_conn_id.

      And enter new method name that does not exists yet:

      reserve_booking( i_carrid = l_carrid i_connid = l_connid ).

      wizard will automatically suggest these variables. That allows developer to write code even more efficiently and that is the power of AiE.

      Regards 🙂

      Adam

      Author's profile photo Luís Pérez Grau
      Luís Pérez Grau

      Nice tip Adam!

      Author's profile photo Luís Pérez Grau
      Luís Pérez Grau

      Hi Thomas,

      Is possible that quick fix doesn't work for global classes in 7.3 release?

      It gives me the following error:

      Invalid XML format of the response. Usually this is a programming error, but occasionally this is caused by an outdated client. Details: Value '' is not legal. (platform:/resource/project/emfresource.extractmethodrefactoring, 1, 715)

      Thanks!

      Luis

      Author's profile photo Thomas Fiedler
      Thomas Fiedler
      Blog Post Author

      Hi Luis,

      I have checked it with ADT 2.7 against NW 7.31 SP7 and it worked.

      Which version combination do you have?

      Regards,

      Thomas.

      Author's profile photo Luís Pérez Grau
      Luís Pérez Grau

      ADT 2.7 against NW 7.31 SP5. But, now is working...maybe is something about refreshing...

      Thanks!

      Luis

      Author's profile photo Thomas Fiedler
      Thomas Fiedler
      Blog Post Author

      Good news that it is working now.

      Regards,

      Thomas.

      Author's profile photo Ian MacLaren
      Ian MacLaren

      Hi Thomas

       

      I get this same error despite loading the latest Oxygen and addins ... any idea how to tackle this problem as the quick fix feature here looks to be a big win if I can get it to work.  Other quick fix functions seem to work ...

       

      regards

      Ian

      Author's profile photo Brian O'Neill
      Brian O'Neill

      Love this, thanks for sharing! It would be great to be able to do this for interfaces as well. With code like below:

      DATA: object_reference TYPE REF TO zif_some_interface.

      object_reference->new_method( ).

      Author's profile photo Florian Dornauer
      Florian Dornauer

      I am a real fan of the ADTs and yesterday I held a presentation to my collegues and one interesting question came up.

      Is this the only way to get the formular based method creation?

      Because it would be an awesome feature if you are on the CLASS DEFINITION and hit CTRL+1 and like creating the CONSTRUCTOR from there it would be a cool feature to create METHODS as well from there.

      Best regards,

      Florian

       

      Author's profile photo Thomas Fiedler
      Thomas Fiedler
      Blog Post Author

      Hi Florian,

      yes, this is definitely on our list of Quick fixes that we want to enable in future. I see also the option to offer this in outline and project explorer view as well in the context menu. But up to now the above described way is the only option to create methods in a from based approach.

      Regards,

      Thomas.

      Author's profile photo Phillip Eisenhauer
      Phillip Eisenhauer

      Hi Thomas,

      I really like to work with quick fixes, but I'm missing one feature in creation of methods from quick fix. If I take an existing class "ZCL_NEW_CLASS" and try to instatiate an object from it there is no quick fix to add a constructor from the given context. Is this planned or could it be added to the list of quick fixes to enable in future?

      Example:

      DATA(example) = NEW ZCL_NEW_CLASS(  
                        is_marc = ls_marc
                      ).

      CTRL+1 on "ZCL_NEW_CLASS" should give the suggestion "Create constructor" with parameter is_marc with type of the supplied ls_marc, as in the normal object->new_method( ) Quick fix.

      Regards,

      Phillip

      Author's profile photo Seokyeon Hong
      Seokyeon Hong

      Hi Thomas.

       

      is it possible to write description to the method we made in eclipse?.

       

      I prefer to develop the classes by eclipse and I made so many methods but all of them had no description about their methods.

       

      Thanks.

      Author's profile photo Thomas Fiedler
      Thomas Fiedler
      Blog Post Author

      You can use ABAP Doc to document your methods. There is even a special tag in ABAP Doc to edit the short description. See more about it in these blog posts:

      https://blogs.sap.com/2013/04/29/abap-doc/

      https://blogs.sap.com/2015/10/21/new-abap-doc-features-with-netweaver-75/

       

      Regards,

      Thomas.