Additional Blogs by SAP
Showing results for 
Search instead for 
Did you mean: 
Active Participant

In this weblog I will show you step by step, in fact there are only a few steps, how easy it is to enhance the global class from our example. Surely you remember from the last weblog the larger context. We had added an additional column to a table element in a Web Dynpro ABAP view. It turned out that we needed quite a few enhancements to wire up our new column and to fill it with some data. In this weblog we will focus on the method that selects the data from the database.

In fact, the short step-by-step description is mainly intended to show you how easy it is to enhance a development object. It does not focus on all technical details of how you actually implement an enhancement option. If you are interested in the details of how to create an enhancement and how to find your way in the relevant tool read my weblog: How to implement a BAdI And How to Use a Filter - Part 4 of the Series on the New Enhancement Framew... and the weblog Source Code Enhancements - Part 5 of the Series on the New Enhancement Framework.

This weblog is part of the series on the three Use-Cases of the Enhancement- and Switch-Framework. In the The Three Use Cases of the Enhancement- and Switch-Framework - Part 1 of the series I gave an overview of the use cases I will present in the series and started an example in which I created an enhancement of a Web Dynpro ABAP user interface. In the The Three Use Cases of the Enhancement- and Switch-Framework - Part 2 I improved the example by developing all the other enhancements that are needed to populate the enhancement of our table in the UI. In the progressing presentation of the example this weblog is intended to give you a flavor of what it is like to write an enhancement. You find a list with links to all weblogs of this series at the bottom the SDN Wiki page on the Enhancement Framework. On the same page you find also links to all weblogs of my other series that goes more into the technical details of the Enhancement Framework.

Our Small Enhancement in Context

Before we begin to enhance a method let us recapitulate in brief the structure of the whole little enhancement project that we needed to fill our additional column with some life.

In the chain from the Web Dynpro ABAP table over the additional attribute in the context back to the Dictionary and database appends, we focus on how to make the relevant method select an additional column from the database. So

How Easy It Is to Exchange a Method of a Global Class – A Step-By-Step Description

Let us now start with the step-by-step description. The lesson you learn here is how you not only can enhance but even substitute a SAP development object without modifying it. There is a new mode for enhancing objects in the editor: The enhancement mode .

1. You change to this mode in an analogous way in which you switch to the change mode.

2. Next you must create or use an existing container for your enhancement. In fact, these containers are called Enhancement Implementation. I have introduced the structure of these containers in another The new Enhancement Framework Part 2 - What Else You Need to Know Before Building an Enhancement. Here I will not consider any details of these containers, since, from some perspective, they function only as a kind of useful coating for the enhancement proper.

By confirming this dialog window you make sure that everything you create now will be an enhancement and not change or even touch the underlying development object. The container serves as the transport- and administrative unit. So we can we neglect them here.

3. After closing the dialog window, you get to the following screen:


You see that you are in the enhancement mode of class CL_EXAMPLE_CLASS and in brackets you get the information in which container your enhancements are stored. For a method of a global class there are three kind of options where to attach an enhancement: a preexit, a postexit and an overwrite exit. An enhancement attached to a preexit is processed before the method, attached to a postexit after the method, and an enhancement at an overwrite exit replaces the implementation of the method at runtime. From a functional perspective we want to select one more column in our select statement. Because it is not possible to add an enhancement within a statement, we have to substitute the whole statement. So we substitute the whole method implementation.

4. To do this we select in the menu bar: Edit – Enhancement-Operations – Insert Overwrite-Method:

5. As a consequence we get an additional button in the row that represents the method.

6. By clicking the button Overwrite-Exit we navigate to the editor where we can implement the overwrite exit.

Step 6 shows you the method implementation in which the new select statement is already entered. The additional column is highlighted by me.

To complete the enhancement operation you have to save and activate. What happens there is another proof of the fact that the class we enhance is not touched. The object that is saved and activated is the container that contains our overwrite method.

When the method is called at runtime, the code of the overwrite method is executed instead of the original code.

All this is done by means of the Enhancement Framework without touching the class that is enhanced. In a way the framework knows: If an overwrite exit is implemented compile this instead of the implementation of the original method.

And it is here that you see the ancestors of the Enhancement Framework most clearly: It is a descendant of the customer exits. But the Enhancement Framework is a far more sophisticated version of this classic exit technology.

Summary: Enhancing a Method of a Global Class in Overview

Let me now just summarize how easy it is to overwrite an existing method implementation of a global class by using the Enhancement Framework.

  • Switch to the enhancement mode and create a container (enhancement implementation) for your enhancements.
  • Insert an overwrite method using the respective menu entry and navigate to this method.
  • Implement this method.
  • Save and activate.

Obviously this is a very simple process. As far as these basic steps are concerned every ABAP developer should have no problems to use the new enhancement technology.

Because we have substituted a whole method implementation, our new method implementation in the enhancement will substitute the original method at runtime. And all this is done without touching or modifying the class, while their behavior at runtime is changed. How is this possible? You surely remember from The Three Use Cases of the Enhancement- and Switch-Framework - Part 1 of this weblog series that enhancements are objects of their own from a transport perspective, but a merged in at the position they are assigned to at runtime.


What you have learned in this weblog quite naturally leads up to some other points I want to make about the enhancement framework in the next weblog. Surely you want to know where you can enhance an application. Can you just add enhancements where you want or only at particular positions? Can you just add what you want as an enhancement? Can you only enhance an application that its developer has prepared for later enhancement? The next weblog of this series will give an answer to all these questions.