Skip to Content
Technical Articles
Author's profile photo Fabian Lupa

Additional ADT code templates

In the ABAP Development Tools for Eclipse one useful feature is code templates. With them you can easily insert boilerplate template code and adjust it as necessary. ADT already comes with many available, but you can also define your own, some of which I want to share as others might find them useful too.

 

Exception class

"! ${descr}
CLASS ${enclosing_object} DEFINITION
  PUBLIC
  INHERITING FROM ${base}
  FINAL
  CREATE PUBLIC.

  PUBLIC SECTION.
    CONSTANTS:
      BEGIN OF gc_no_arguments,
        msgid TYPE symsgid VALUE '${msgid}',
        msgno TYPE symsgno VALUE '${msgno}',
        attr1 TYPE scx_attrname VALUE '',
        attr2 TYPE scx_attrname VALUE '',
        attr3 TYPE scx_attrname VALUE '',
        attr4 TYPE scx_attrname VALUE '',
      END OF gc_no_arguments.
    INTERFACES:
      if_t100_message.
    METHODS:
      "! @parameter is_textid | Textid
      "! @parameter ix_previous | Previous exception
      constructor IMPORTING is_textid    LIKE if_t100_message=>t100key OPTIONAL
                            ix_previous  LIKE previous OPTIONAL.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.



CLASS ${enclosing_object} IMPLEMENTATION.
  METHOD constructor.
    super->constructor( previous = ix_previous ).

    CLEAR me->textid.
    IF is_textid IS INITIAL.
      if_t100_message~t100key = gc_no_arguments.
    ELSE.
      if_t100_message~t100key = is_textid.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

Include file header

*----------------------------------------------------------------------*
***INCLUDE ${enclosing_object}.
*----------------------------------------------------------------------*

Message dummy

MESSAGE ${msgtyno}(${msgid}) WITH ${msgv} INTO DATA(${lv_dummy}) ##NEEDED.

Message to text

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
        INTO DATA(${lv_msg_text}).

Initialize object services

cl_os_system=>init_and_set_modes( i_external_commit = ${oscon_false}
                                  i_update_mode     = ${oscon_dmode_update_task} ).

Report header

*&--------------------------------------------------------------------*
*& Program               ${enclosing_object}
*& Author                ${author}
*& Short description     ${shortText}
*&--------------------------------------------------------------------*
*& Date                  ${year}-${month}-${day}
*& Last change           ${year}-${month}-${day}
*&--------------------------------------------------------------------*
*& Change protocol
*& Date       User         Description
*& ____-__-__ ____________ ______________________________________
*&--------------------------------------------------------------------*

Installation

If you want to install all of them you can Right Click -> Save as… on the following link and import the xml file in the code template settings (Preferences -> ABAP Development -> Editors -> Source Code Editors -> ABAP Templates -> Import…).
Download link

Further reading:

Insert Code Patterns and Templates within Eclipse

Creating new Code Templates with ABAP in Eclipse

Assigned Tags

      7 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi Fabian ,

      nice one. I was missing the template for exception class & was lazy enough to create one myself ?

      In my company we have defined the report header and change log using ABAPDoc. Looks intimidating, but works just fine.

      Thanks & best,

      Suhas

      Author's profile photo Fabian Lupa
      Fabian Lupa
      Blog Post Author

      Oh I never thought of trying that. Does it get exported to HTML as well / does quick info work?

      Author's profile photo Former Member
      Former Member

      Does it get exported to HTML as well / does quick info work?

      Yes, business as usual. Idea is not to write any additional tech specs and use the power of ABAPDoc.

      Author's profile photo Michelle Crapo
      Michelle Crapo

      Thank you!  I went and googled ABAPDoc.  Very cool feature.  Yes - I'm a step behind on Eclipse.  OK - 20 steps behind 🙂

      Author's profile photo Michelle Crapo
      Michelle Crapo

      Nice.  We have all kinds of patterns in the ABAP editor.  It is cool that we can use them in Eclipse.

      Michelle

      Author's profile photo Karthikeyan Balashanmugam
      Karthikeyan Balashanmugam

      Hi Fabian
      The download link is not working. Please look into it.

      Author's profile photo Fabian Lupa
      Fabian Lupa
      Blog Post Author

      Hi Karthikeyan,

      thanks for the heads up, I updated the link.