Show TOC

ABAP Code TemplatesLocate this document in the navigation structure

ABAP code templates are structured descriptions of coding patterns that can be used in the ABAP source code.

Code templates help the developer to reduce the time spent on routine editing activities and improve consistency when writing code. They allow for quick generation of commonly used ABAP code, as well as easy customization. ABAP code templates go beyond the functionality of simple code snippets. They include direct integration with code completion, the ability to use predefined and custom variables, and the ability to improve style uniformity and validity of ABAP code. When using code snippets, you basically get a shell that you can insert and edit manually.

ABAP Development Tools provides a number of predefined code templates for ABAP. In addition, you can create your own templates or edit existing ones. You can view, edit, or create new ABAP code templates using the Start of the navigation path ABAP Development Next navigation step Source Code Editor Next navigation step Templates End of the navigation path preferences page.

Templates are inserted into the ABAP source editor

  • Using code assist (Ctrl + Space)
  • Through Drag & Drop using the Templates view.
Example: LOOP AT statement

A common coding pattern in ABAP is to iterate over the rows of an internal table using a loop that reads the internal table in a loop, where each row is assigned to a field symbol. By using a template for this pattern, you can avoid typing in the complete code for the loop. Invoking code assist after typing the word loop will present you with a list of possible loop templates. Selecting this template will insert the code into the editor and position your cursor so that you can edit the details.

Inserted code in the ABAP Source Editor when using the loopAtAssign template
Figure 1: Inserted code in the ABAP Source Editor when using the loopAtAssign template