Menu

ABAP Workbench Tricks #1: Using Patterns to Speed Up Your Coding

2014-08-05       

Hi folks! Today marks the start of a new series, called ABAP Workbench Tricks, which is quite close to my original idea for this entire blog. As a first post, I’ll discuss the use of patterns to significantly speed up and simplify your development process.

What are patterns?

Instead of writing a call to a method or function module manually, you can have the ABAP Workbench (Transaction SE80) generate the necessary code for the call. This is called inserting a pattern. Patterns can not only be used to call methods, but for a multitude of ABAP operations and language constructs, including the definition of your own patterns.

How to insert ABAP patterns into your code

There are two ways to insert a pattern into your ABAP code. The easiest way to do it is via drag and drop and only works for method or function module calls. Open the function group or class you’re going to work with, then simply drag and drop the method or module to the place in your coding where your want your call code to be.

Drag and drop function modules to insert a call pattern.

With this easy and quick method, you can create method or function module calls in your ABAP coding much faster. You only need to provide values for the import parameters you want to fill and delete the rest.

The second way is more complex, but also more powerful. To insert any kind of pattern, open the pattern popup by clicking the Pattern button in the application tool bar, by selecting Edit > Pattern or by pressing Ctrl + F6 in the ABAP Workbench. The following popup will be shown.

Popup for Pattern Insertion

Here, you can do much more. As you can see, there is a variety of patterns available directly in the popup. You could for example have patterns generated for a select statement, a subroutine call or an authority check. By selecting Other Pattern, you can get access to even more patterns for most language constructs in ABAP. Try experimenting a little bit – some of these are more useful than others.

Define your own patterns

You can go even further and define your own patterns. This can be useful e.g. for governance reasons. A company I worked for used it to insert custom headers into all of their development objects. They contained a template where developers could then enter meta information, such as the name of the related technical documentation or a contact person. This way, it’s possible to easily improve the consistency of your system and adhere to coding standards.

Creating your own pattern couldn’t be simpler. In the ABAP Workbench, select the menu path Utilities > More Utilities > Edit Pattern > Create Pattern:

How to Create a Custom Pattern

After entering a name for the pattern, you can enter anything you like as the pattern content. It can be up to 100 lines long. In my example, I just created a simple test pattern. It can be inserted in the way you already know.

How to insert the test pattern

The pattern will then be added to your code.

The inserted test pattern.

Of course, you can edit or delete the pattern again in the same menu path.

That’s it for this post, I hope that this will help you write better code! You can do even cooler stuff with patterns, so stay tuned for the next part of this series.