Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
ThFiedler
Product and Topic Expert
Product and Topic Expert
8,994

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:

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

  

The new template is created using a small template editor:

 

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.     

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.

   

11 Comments
ChristianGünter
Contributor
0 Kudos

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

0 Kudos

Hi Thomas,

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

Daniel

ThFiedler
Product and Topic Expert
Product and Topic Expert
0 Kudos

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. 

ChristianGünter
Contributor
0 Kudos

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

ThFiedler
Product and Topic Expert
Product and Topic Expert
0 Kudos

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

Regards,

Thomas.

0 Kudos

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

ThFiedler
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Matthias,

how should these variables work?

Which value should be used when the template is inserted?

Regards,

Thomas.

0 Kudos

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.

joachimrees1
Active Contributor
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
wiessman
Newcomer
0 Kudos
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

 
Volodymyr_S
Explorer
0 Kudos

@ThFiedler I understand that it's a bit outdated, but i have a question regarding code templates in Eclipse. In SAP GUI, there is a way to request user input and insert it into the code. This is useful, for example, when documenting a ticket number in the comments. I couldn't find such a capability in Eclipse. Am i missing something, or this wasn't implemented in ADT?

I found this post on stackoverflow that explains how to pop up a dialogue for a user input; there are other posts how to add custom variables to Eclipse. Is it technically possible to marry the 2 things and add user input to the ADT code templates? Asking as an ABAP developer - can't figure out the answer myself.

Thank you.

Labels in this area