Skip to Content

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.

   

10 Comments
You must be Logged on to comment or reply to a post.
  • 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

      • 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.

  • 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