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.