Skip to Content

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

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Suhas Saha

    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

    (1) 
    1. Suhas Saha

      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.

      (0) 

Leave a Reply