skip to Main Content

Dev Tip: ABAP Code Completion Template

To sign up and get your dev tips delivered to your inbox each week, click here!

Tip of the Week

ABAP Code Completion Template

Like ABAP code patterns, there is another handy tool tucked away in the corner of the ABAP editor that can speed up some aspects of your development. It’s called the ABAP Code Templates. Whenever you get code suggestions while typing keywords like ‘If’, or ‘Loop’ or ‘Case’, this is where it is coming from. When the suggestions appear, on press of the ‘TAB’ button, that template will be applied to your code.

But these templates can be dynamic too, although only to a certain extent. I will demonstrate that by using a very common scenario: tagging of modified code with a modification log or comment. Normally such a tag is to let other developers know when, why and by who has the code been last changed.
So, let’s say, we would want to surround any newer piece of code inside of an older code module with the following information:

  1. User Name of the person responsible
  2. Date and time of the change made
  3. Some change tracking number or some description of the change.
  4. A ‘BEGIN’ and an ‘END’ label.

We would also want to position the cursor in such a way that right after the template is applied you can start writing your code.

  1. Create a new report in SE38. Mine is called ZSS_DEMO_CODE_COMPLETION.
  2. In the right and bottom corner of the screen there is a small yellow button. Click on that.
3. From the list, go to ‘Code Completion’.
4. Click on the Add button and you will see the following popup
5. Now after giving it an appropriate name (this is the name you’d have to type to invoke the template on your editor), save it.
6. After you have saved the template, you will be provided with an area where you can write the content of the template. The ‘Insert Tag…’ button will bring up a menu of all the options that you have to dynamically supply information to the template.7. I chose to hardcode my username, use the Date Time and Interactive Tag. I also used the Cursor Position tag to set the cursor right between the BEGIN and the END markers so that I can immediately start coding there. It ends up looking like this:
8. Now save it and go back to the main editor screen. Start typing in ‘change’ and you will see a small tooltip appear above this text with the description that you had used before.
9. Press Tab now, and you will see a popup. This is for the Interactive Tag. You can add a description or a tracking number here.
10. Insert some value and press OK. The template will be inserted with the cursor focus on line 5.
Now you can keep using this whenever you need to modify an existing piece of code.

Shinjan has been in the SAP space for over 10 years. He has worked on all areas of SAP ABAP for various clients in Europe and in the US. He considers himself to be a fast learner who puts enormous importance towards looking at the bigger picture while simultaneously being details oriented. Coming from a computer science background, he has always been a technology enthusiast dabbling in various programming languages along with pushing the limits of SAP ABAP. Before joining Mindset Consulting, he was the solution architect for Microsoft’s Business Process Monitoring engagement. Now as a development lead at Mindset, he has been heading challenging projects and is focused on delivering solutions that reach beyond the expectations of the clients.

Back To Top