Skip to Content
Author's profile photo Thomas Fiedler

Creating new Code Templates with ABAP in Eclipse

As described in my previous blog Surround your code using ABAP in Eclipse code templates you can also create your own templates and use it to surround your code with predefined patterns. Let’s have a look on how you can do that.

First you have to open the templates view in your eclipse installation. You do this by just enter ‘Template’ in the eclipse ‘Quick Access’ input field:

/wp-content/uploads/2013/05/temple1_221917.png

This opens the Templates view where you can create a new template just by clicking the marked icon:

/wp-content/uploads/2013/05/temple2_221919.png  

The new template is created using a small template editor:

/wp-content/uploads/2013/05/temple3_221920.png 

You first give it a name and a description and define it for the context ABAP which is the default when working in the ABAP perspective. After that you can define the template within the “Pattern” text-edit field. There a lot of predefined variables that you can use within your template. A list of available variables you can see when you click on the “Insert Variable” button on the buttom of the editor.     

/wp-content/uploads/2013/05/temple4_221922.png

There are really useful variables available like the logged-on user, the current date, the system-ID or the word_selection that you need to surround your code with the template. The “cursor” variable is used to define where the cursor will be positioned after choosing the template within the editor.

After you have created the template you can see it in the Templates view and also in the code completion the next time you trigger it in your ABAP editor.

So that’s it for today. Have fun with your ABAP code templates.

Next time I will start a series of blogs concerning the new ABAP in Eclipse debugger.

Also interested things inside there. So stay tuned.

Regards,

Thomas.

   

Assigned Tags

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

      Hi Thomas,

      is there a way to export existing code templates from SAPGui based ABAP editor to AiE? I already compared the two xml files where the appropriate templates are stored but they are very different. Is there a migration tool or something else?

      Regards Christian

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

      Hi Christian,

      actually this is not part of our plannings. But sounds like a good idea.

      There is the possibility to import templates into eclipse. I will check with my colleagies whether the export of ABAP templates into the format of eclipse is feasible.

      Do you want to engange here? Would be a good exercise to learn more about the plugin capabilities of ABAP in Eclipse.

      Kind Regards,

      Thomas. 

      Author's profile photo Christian Guenter
      Christian Guenter

      Hi Thomas,

      sounds good.

      Do you want to engange here? Would be a good exercise to learn more about the plugin capabilities of ABAP in Eclipse.

      Why not? I already put this to my leisure projects list.

      Regards, Christian

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

      Hi Christian,

      there are few examples available how you can contribute to AIE. One very good example is from Martin Steinberg

        http://scn.sap.com/community/abap/eclipse/blog/2014/06/11/starting-with-adt-sdk-is-easy--create-your-own-transaction-launcher-pt2

      Regards,

      Thomas.

      Author's profile photo Daniel Herrera Marmolejo
      Daniel Herrera Marmolejo

      Hi Thomas,

      There is any way to format the date variable on the template?

      Daniel

      Author's profile photo Mattias Johansson
      Mattias Johansson

      Hi Thomas,

      Are there any plans on making some abap specific variables availble in the template editor, i.e. the transport number and title?

      /Regards

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

      Hi Matthias,

      how should these variables work?

      Which value should be used when the template is inserted?

      Regards,

      Thomas.

      Author's profile photo Mattias Johansson
      Mattias Johansson

      For example this is one of our templates (never mind the formatting)

      ************************************************************************

      * RIDEPOS / Title           : ${tasktitle}

      * Creation Date                : ${date}

      * Author                    : ${user}

      * Project rel./Problem Id.  : ${}

      * Transport no              : ${transportnumber}

      * Transport title           : ${transporttitle}

      * Description               : ${transportdescription}

      ************************************************************************

      ${cursor}

      The tasktitle is populated from Mylyn, date and user are build in variables. But what would be great is if somehow transportnumber and titile would also be available. I'm not sure if that's possible, if variables could be file dependand, or are "global" for the wholo of eclipse.

      Author's profile photo Roland Wiessmann
      Roland Wiessmann

      Hi,

      I have the same idea with the transportnumber and transporttitle. Do you got already an idea how to do define the new variable?

       

      Regards

       

      Author's profile photo Joachim Rees
      Joachim Rees

      Oh, this was a tricky one when I was just trying this:

      Apparently, at least 1 development object hast to be open, otherwise the template view is completely empty.

      ...took me a while to find out it works fine once you open any object!

      best
      Joachim