Skip to Content
Technical Articles
Author's profile photo Jörg Krause

ABAP editor code templates gallery

Code templates in ABAP backend editor

The ABAP (backend) editor has this nice feature of code completion. You find it clicking on the icon in the bottom right corner of the editor window, then going to “Code Template”. There are already many useful shortcuts there, but you can even create new ones.

What templates did you create?

I just thought of starting a blog where we present our awesome code templates so we can all get even quicker in coding!

I start with two little templates that help me create class frames:

  • name: class
    • purpose: create a new class definition
    • code:
      class | definition.
        public section.
          methods: 
            %first method%
              raising zcx_gens.
      endclass.​
  • name: clsi
    • purpose: create a new class implementation
    • code:
      class | implementation.
        method %first method:%.
      
        endmethod.
      endclass.​

One could merge also the two templates to one. I did not do it because usually I use different includes for class definitions and implementations.

Share your templates

If you have created helpful templates, put them into the comments.

 

 

Assigned tags

      8 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Andrea Clöß
      Andrea Clöß

      Name: tryitab

      try.
      ${cursor}
      catch cx_sy_itab_line_not_found.
      endtry.

       

      Name: salv

          try.
              cl_salv_table=>factory( exporting list_display   = if_salv_c_bool_sap=>false
                                      importing r_salv_table   = data(salv)
                                      changing t_table        =  ${cursor} ).
      
              salv->get_functions( )->set_all( ).
              salv->display( ).
            catch cx_salv_msg cx_salv_not_found.
          endtry.
      
      Author's profile photo Jörg Krause
      Jörg Krause
      Blog Post Author

      Added immediately to my settings!

      Author's profile photo Tomas Buryanek
      Tomas Buryanek

      Name: messages

      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      Author's profile photo Sandra Rossi
      Sandra Rossi

      Migrating to Eclipse? See also Sharpen your ABAP Editor for TDD - Part II., by Damir Majer, and Additional ADT code templates, by Fabian Lupa

      That would be wonderful to share a github repository.

      Note that the backend templates are here: C:\Users\<user name>\AppData\Roaming\SAP\SAP GUI\ABAP Editor\abap_user.xml

      Author's profile photo Jörg Krause
      Jörg Krause
      Blog Post Author
      begin of ty_%Name%,
        |
      end of ty_%Name%,
      ty_%Name%s type standard table of ty_%Name%
         with default key.

      Create a table type with structure

      Author's profile photo Mike Pokraka
      Mike Pokraka

      Avoid default key, use empty instead.

      https://blogs.sap.com/2013/06/27/abap-news-for-release-740-internal-tables-with-empty-key/

      Author's profile photo Jörg Krause
      Jörg Krause
      Blog Post Author

      Useful for refactoring and code inspector processing:

      " name: subrc
      if sy-subrc = 0.
        %Clipboard%
      endif.
      "name: forall
      "purpose: surround a select with "for all entries" with the 
      " check for an initial source table
      if | is not initial.
        %Clipboard%
      endif.

       

      Author's profile photo Jörg Krause
      Jörg Krause
      Blog Post Author

      template testclass

      class ct_test definition for testing
             risk level harmless duration short
             final.
      
        public section.
      
          methods adhoc for testing.
      
      endclass.
      
      class ct_test implementation.
        method adhoc.
          |
        endmethod.
      endclass.