Skip to Content

Surround your code using ABAP in Eclipse code templates

A very powerful feature in Eclipse is the usage of code templates. Few months ago I already described in my blogInsert Code Patterns and Templates within Eclipse how to use it. Just start typing the name of the template and use code code completion to insert it into the editor. But often you have the situation that you already have some code that you want to surround with some code. I give you some examples:

  • You call some ABAP methods in your code not taking care for exceptions in the first shot. Later on you want to catch the exceptions from this code block with a TRY/CATCH clause.
  • You have some code written and want to put this into a conditional clause. So you want to surround the code block with an IF/ELSE/ENDIF clause.
  • You have written some code and want to put this into a CASE/ENDCASE clause.
  • You have some code that you need to surround with a LOOP/ENDLOOP clause.

The code templates in eclipse helps you to do that job very quickly as you will see in the following section:

Here I have a coded a very simple “Hello World” application in SAP style:


Perfectly working. Next step is a small enhancement in case there are no flights selected.

So I want to check the SY-SUBRC of the select statement and only if there are flights I want to display them in the ALV.

With Eclipse I do this by marking the code that I want to put into the IF/ENDIF clause and press CTRL-SPACE – the magic shortcut to open the template selection.    


After selecting my template of choice the code is generated as you see here in the screenshot:


Also very helpful here is that the cursor is already positioned correctly so that I can directly go on with defining my expression.Try it out, this will really speed you up. 

ONE MORE THING: In case you have additonal requirements concerning new templates you can also create your own templates via the templates view in eclipse. This I will explain in my next blog.



You must be Logged on to comment or reply to a post.
    • Hi Uwe,

      there is a mechanism to import and export eclipse code templates to the file system. Ashwani describes this in his blog about WD templates. I can imagine that we can create an eclipse plugin that automatically syncs the local templates with the central template repository on code exchange. Can't we use your SAP Link infrastructure for that. What do you think: Another community project?



      • Hi Thomas,

        sorry for the late answer.

        Yes, this is a nice idea. Unfortunately currently we can't create new projects on Code Exchange (see announcement on Code Exchange ).

        Another showstopper atm is the availability of JAVA devs. We are still searching one for our "SAPlink for ADT" project.