Skip to Content

Scharpen your ABAP Editor for Test-Driven-Development (TDD) – Part II.

How to optimize your Performance by using the new ABAP Editor

[image from http://static.supernifty.com.au/images/comic-mastery.png – copyright Supernifty.com.au]

In my previous Blog (http://scn.sap.com/community/abap/blog/2013/01/05/sharpen-your-abap-editor-for-tdd) I described what is necessary for sharpen your ABAP Editor to use successful TDD. In this Blog I will show you:

  • my own Templates
  • what kind of Philosophy is behind some created templates

Creating user specific Templates in the new ABAP Editor

For following commands we will create Templates:

  • local Classes
  • local Test-Classes
  • Testmethod definition
  • Method implementation
  • assert_equals Statements
  • fail Statements

so, let us begin…

First you have to verify if you use the New Front-End Editor. Call the Transaction SE80, and then choose the Menu Utilities->Settings.

Go to the ABAP Editor Tab and check that the New Editor is activated:

If the displayed Dialog looks a littlte diffrent in your System, don´t worry maybe you have an newer System then I used (Trial-Version NW7.00) for this Blog 😉

Now it is possible to go into the Object-Navigator (Transaction SE80), open an ABAP Report and Click on the

to open the Front-End Editor Options click the Button on the lower right side.

The Options Dialog opens. Here is the starting Point to create your own Templates. Select on the left-hand side the Entry “Code Templates”

By clicking on the  Add... Button, you can add your own Code-Templates. These Templates are only available for your currsten SAP-User.

In the now opend Dialog-Box you enter in the Name-Form the Keyboard-Shortcut you will create and in the Description-Form a short Description what this Template will offer:

I use the Prefix ‘#‘ for all my Keyboard-Shortcuts. So it´s easy for me to know what are SAP-Standard-Templates and what are my Customn-Templates.

local Classes

Shortcut-Name: #lcl      Description: local Class Creation

    class %local Classname% definition.

      public section.

      |

    endclass.

    class %local Classname%  implementation.

    endclass.

With the Button Insert Tag... you got some little helpers:

It is possible to insert some Variables this happens with the Percent-Sign.

The Pattern is: %<any_kind_of_useful_text>%

After Saving your Entry you can choose your Code-Templates in the ABAP Editor:

When you Type the Shortcut #lcl The Autocompletion suggest you the new created Template.

Hit CTRL + SPACE and you got the Template-Parameter Dialog to enter your local Classname:

And here is the result:

local Test-Classes

SAP suggest to name your normal local Tesclasses with the Prefix LTC_ 

Shortcut-Name: #ltc      Description: local Testclass till NW 7.00

    class ltc_%local Test-Classname% definition for testing.

      “#AU Risk_Level       Harmless

      “#AU Duration         Short

      public section.

      |

      endclass.

    class ltc_%local Test-Classname% implementation.

    endclass.

Please remember, that if you have an System above NetWeaver 7.00 your Testclass Definition will look a little diffrent:

Shortcut-Name: #ltc      Description: local Testclass above NW 7.00

    class ltc_%local Test-Classname% definition for testing

       risk level harmless duration short.

      public section.

      |

      endclass.

    class ltc_%local Test-Classname% implementation.

    endclass.

Again, after filling the Input-Parameter the Code is generated.

Testmethod Definition

Naming Conventions in every programming language is a philosophy of his own.

I recommand that you should use one style in your Company/Team.

I like the Standard which Roy Osherove explains on his homepage http://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html .

The Point is, that I could easiliy understand the purpose of my written Tests if I described the intention in the Testmethodname by using the Pattern [MethodName_StateUnderTest_ExpectedBehavior]

Shortcut-Name: #tmdl      Description: Testmethod Definition long Version with Pattern [MethodName_StateUnderTest_ExpectedBehavior]

      %MethodName%_%StateUnderTest%_%ExpectedBehavior% for testing.


I think, now you are familiar with creating own Code-Templates. The following statements will only display my own used Templates 😉

Testmethod Implementation

If you create an Template for normal Methods or Testmethods it looks the same. So I use a more general Template for Implementing Methods:

Shortcut-Name: #mi      Description: Implementation-Part of a Method

     method %Method Name%.

        |

     endmethod.


The Problem in ABAP is that you have only can name your Objects (local classes, Testmethods, Fields) with a maximum length of 30 characters.

I found it useful when naming the objects to have an info how much characters are left till 30.

So I also created an Template for this:

Shortcut-Name: #line      Description: Displays 30 Char length

      “+++5+++10++++++++20++++++++30

assert_equals Statements

Please remember, that if you have an System above NetWeaver 7.00 SAP suggest to use the new Assertion-Class: CL_ABAP_UNIT_ASSERT.


Shortcut-Name: #ae      Description: Assert_Equals Statement

    cl_aunit_assert=>assert_equals(

          exp = exp

          act = act ).

Shortcut-Name: #aem      Description: Assert_Equals with Message

    cl_aunit_assert=>assert_equals(

          exp = exp

          act = act

          msg = msg ).


fail Statement

Shortcut-Name: #fail      Description: ABAP Unit fail Statement

    cl_aunit_assert=>fail(

    msg    = ” ).

  My experience is..

It took some time to figure out, which templates are working for me.

As a programmer you have your style, and every programming style is a little diffrent…

Try out other templates / commands. Look if it speed up your work.

Your experience is?

What is your experience with using the above Templates?

What was good and what could be implemented better?

Have you something diffrent that works for you?

  Further Information

Editors in the ABAP World

Blogs in this Series:

To report this post you need to login first.

7 Comments

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

  1. Dirk Wittenberg

    Hi Damir,

    great blog!

    I’m using only a template to create local test classes and it works quite well. The templates for the test methods are a idea worth trying. Nice would be a feature that inserts the method definition and the empty method body at once.

    Didn’t read the first part of your blog so far, so here my comment on this:

    Navigating between the productive code and the test code is the biggest inconvenience when doing TDD. So I got the idea to put the productive code ( form, function module ) and the corresponding tests into the same include. That would make the ways a bit shorter.

    The class builder for global classes would make an exception here – though I never tried to write the tests into the same include as the implementation of a method and even if it works it would surely confuse other developers.

    Regards

    Dirk

    (0) 
    1. Damir Majer Post author

      Hi Dirk,

      it´s pleasant that you like this blog 🙂

      Organizing Testclasses is a big topic and the answer is… It depends on your context… like should the Testcode be available for others, or should I deploy only the Application Package etc…

      At least you have the options to put the Testcode near the production code, for example in one include or to use the predefined local Testclasses (available for global classes, Function Modules) or you define an own Package whick includes all your Test-Classes, but for this solution your Application need to have global accesseblility.

      Does this give you an good hint?

      Cheers,

      Damir

      (0) 
  2. Rainer Hübenthal

    Hi,

    templates are nice, i only have one problems creating them this way: they are local and distributed to the development team. Or do i miss something here? Is there a way to distribute these templates to others around?

    //Rainer

    (0) 
    1. Damir Majer Post author

      Hi Rainer,

      the Distribution of Team-Templates is a important Topic. Normally you have an Process in your company which proves if all the created Templates are necessary etc…

      For global available Templates you coud use the Pattern-Functionality:

      Here it is possible to Define global available Coding-Templates.

      This Patterns are available with the Insert Statment Popup in the Editor (Press CTRL + F6) then choose the Radiobutton Other Pattern and Select your own created Templates.

      My Intention with this Series is, that every Developer should Sharpen his “own” Editor. Maybe for one Developer some Templates don´t work as here described.

      So, the Templates are only User-Specific.

      Cheers,

      Damir

      (0) 
      1. Rainer Hübenthal

        Thanks Damit,

        but i pimped the pattern already by using the user exit to have a complete workflow of creating reports by asking the description, change reason, type of module, alv yes/no and special perform to build a whole report skeleton from scratch where only the business tasks need to implemented.

        But for smaller templates it would be nice to have a deployment of the editor templates as well. I’m always looking for new techniques to have standard way of creating code.

        //rainer

        (0) 
        1. Damir Majer Post author

          Hi Rainer,

          yes more options in the deployment of the editor would be great. Maybe this will be available in future Releases 😉

          It would be really interesting to see your pimped version…

          What do you think?

          Maybe you could write a Blog with this Topic?

          Cheers,

          Damir

          (0) 
          1. Rainer Hübenthal

            Well, that would be too much for a single blogpost 🙂

            We have implemented the creation of patterns on a central instance. Every development instance is using the editor-user-exits to call the functions/methods from via RFC. You can choose what type of report you want to create (FI;CO,MM,SD,HR where HR is has lot of differences to the other modules), if you wanna have an alv grid, download/upload to local, download/upload to server, send data to XI via webservice as XLM and so on and son. You are enforced to enter a suitable description generating out abap header automtically and choose from several from routines like sending email/fax or just having a progress indicator.

            Besides that you can create type defintions by just piciking up components from other ddic data generating the alvf fieldcatalog in addition. Or you can create SQL statements on thy fly by picking up ddic data, everything is automaticvally commented inserting the comments from ddic.

            To be able that your report can be compiled and run after being created you need to have several classes available in each system where “outsourced” all that technical stuff.

            This only works together when you strictly follow our development guidelines…

            So i only can tell you the very basics of having source code dynamically generated if wanted,

            //Rainer

            (0) 

Leave a Reply