Skip to Content
Technical Articles
Author's profile photo Thomas Weiss

Source Code Enhancements – Part 5 of the Series on the New Enhancement Framework

This is part 5 of a series on the new Enhancement Framework. You find the other weblogs of this series here:

What the New Enhancement Framework Is For – Its Basic Structure and Elements For Beginners

The new Enhancement Framework Part 2 – What Else You Need to Know Before Building an Enhancement

How To Define a New BAdI Within the Enhancement Framework – Part 3 of the Series

How to implement a BAdI And How to Use a Filter – Part 4 of the Series on the New Enhancement Framework

Source Code Enancements – Part 5 of the Series on the New Enhancement Framework

In this weblog I want to address several topics that center more or less around creating source code enhancements. At the beginning, I focus on the different use cases in which developers outside of SAP create an enhancement option. In a next step I narrow the scope and ask the question which type of enhancement option you should prefer as an option provider and in which cases a source code enhancement should be your first choice. As I have already stated in another weblog, in general SAP recommends the use of BAdIs. Still the BAdI is no all-purpose weapon. There are situations in which it is better to use source-code enhancements instead. After sketching these situations I will show you how to create an enhancement point, how to implement an enhancement point and how to overwrite an implementation created in another system without modifications.

Why to Define an Enhancement Option as a Developer Outside of SAP – the Different Use-Cases

Let us start by spending some thoughts as to when and why you might want to define an enhancement option as a non-SAP developer. Of course, it should be clear at the outset that in most cases you will implement enhancement options if you are a non-SAP developer. But as you will learn soon, there is one group of non-SAP developers that will take great advantage of defining enhancement options themselves. These are the ones developing solutions that should be enhanced by somebody else later. I will treat this group in the first use case. In contrast, the second use case is not confined to a particular group, but to any developer who is interested in keeping an unavoidable modification as small as possible.

1a.Imagine, you are an ISV, develop your product in ABAP and want to enable your customers to enhance your product at certain points. In this case, you provide enhancement options where you think they are useful.

1b. The same applies to the IT department of a multinational company. It develops some solution in ABAP and wants to make room for changes or enhancements that the different local subsidiaries can implement. Again using enhancement options are the suitable way to do this. Both cases are semantically and technically pretty the same, so that I decided to subsume them under the same use case.

2. The second use case is a bit more complex to describe: You are a SAP customer and need some enhancement of a SAP solution. Let us assume that the implicit enhancement options available in the relevant development objects do not suffice to accomplish this and that there are also no suitable explicit enhancement options. So you are left with the possibility to modify the relevant SAP development objects. But still there is room for using enhancement options. To reduce the effort necessary for adapting your modifications after an upgrade it is a good strategy to keep your modifications small. To minimize the size of your modification you create enhancement options within the modifications you insert. Then you add all further code to the implementation of these enhancement options. This way the modifications only contain these enhancement options and all the other additions are part of your namespace. In this use case modifications and enhancement cooperate in an interesting way.

The Limits of the Enhancement Framework

The very existence of this use case also helps to provide an answer to a question frequently asked: Namely, whether the new enhancement framework suffices to avoid all modifications. A realistic answer is: A clever use of enhancements enables you to do without modifications in many cases. On the one hand, there are explicit enhancement options provided by the developers of the respective solution. On the other hand, there are a huge number of implicit enhancement options. There are implicit enhancement points at the end of a function module, of a structure definition, of a report and of an include, in each defining section of a local class, and at the end of the implementation of a local class. Moreover, you can enhance a function module by additional parameter. A global class also offers a variety of implicit enhancement options: You can add methods, attributes, and interfaces to the class. Each method can be enhanced by a pre-exit, a post-exit and an overwrite-exit that substitutes the original implementation of the method.

Looking at the huge number of different implicit enhancement options it is probably possible to achieve your aim without modification very often. But still this is not always possible. Let us put it this way: What the new enhancement framework offers is intended to support modification-free enhancements to as large an extent as possible. But still, there is no guarantee that this is always possible. In case the enhancement options available for you do not suffice you should decide to create an enhancement option as a modification.

When to Use Source Code Enhancements

So much for the question when to create an enhancement option and the little excursus on the limits of the enhancement technology. The next question is what enhancement option you should prefer. In general, SAP recommends using a BAdI whenever it is possible. This is due to the reasons already named: A BAdI has a well defined interface and because of that the enhancement option provider has a firm control of the implementation. Moreover, the implementations can only access the data passed to them by the parameters of the respective methods. And again, it is you the BAdI provider, who determines which data should be passed to a BAdI method.

This great advantage of the BAdI is also a drawback in some situations. Thinking about this leads the way to understanding under which conditions a BAdI is not the suitable solution if you want to provide an enhancement option. This is, for example, a situation, in which you do not know which data the potential implementer of your enhancement options needs or provides. To put this point another way, if you do not know the interface, you cannot and, of course, should not use a BAdI. Given this condition, you should use the technology of enhancing the source code.

This enhancement technology comes in two flavors:

– At Enhancement points an implementer can add some lines of code which are executed at runtime when the line with the statement ENHANCEMENT POINT is reached. Then the control flows proceeds to the next line after the enhancement point. There can be none, one or many active source code plug-ins (as these enhancement implementation elements are called) assigned to an enhancement point. All these source code plug-ins are executed in addition to the code that is enhanced.

– An enhancement point cannot be part of another statement. This means a statement cannot be enhanced. And that fact sets a limit to the power of enhancement points. For example, there is no way to add a new condition to the where clause of a select statement by using an enhancement point. This is one prominent use case for an enhancement section. Imagine you have a select statement:

SELECT a b c FROM my_table INTO wa.

and want to leave it to the implementer to add a where-clause or select other fields from this table. So you mark the select-statement as an enhancement section, which looks like this:

select * from sflight into table struc.

Don’t worry here about the details of the syntax. At this stage, you should just note that the code marked as an enhancement section is substituted by a source code plug-in as soon as one is provided. Obviously it is required by the logic of enhancement sections that one enhancement section can have exactly one active implementation.

Let me just restate the main point about the use of source code enhancements: This enhancement technology is suitable if you want to provide an enhancement option and cannot or do not want to specify an interface.

Defining an Enhancement Point

Now that you know why and when to use source code enhancements you are probably eager to know just how you create an enhancement point and how you implement it. Before going into any details let me just remind you of the basic structure of the enhancement framework that applies to source code enhancements as well: When you define an enhancement point, this point has to be part of an enhancement spot. This means if you cannot use an existing enhancement spot you have to create one when creating an enhancement point. The same applies in an analogous way to source-code plug-ins: A source code plug-in is uniquely assigned to an (simple) enhancement implementation. But this structure should be pretty familiar to anybody who has read the weblog in which I show how to implement a BAdI. (Simple) enhancement implementations serve as container for enhancement implementation elements.

So enough with the background structure. Let us go into the details and create an enhancement point. We go to the source code that we want to enhance, open the respective unit in change mode, put the cursor on a line and choose the right mouse menu:


In the next dialogue window we enter the name of the enhancement point and the name of the spot plus the name of the relevant package as shown below.


As a result an enhancement point is inserted into the code before the line where the cursor was:


This is what an enhancement point looks like. An enhancement point has a name that is unique within the source code unit it belongs to and is uniquely assigned to an enhancement spot.

Implementing an Enhancement Point

Now we switch our role. For the sake of simplicity we provide here both the definition and the implementation of our enhancement point. Of course, you know by now that the provider of an enhancement option and the implementer are two different roles. To implement an existing enhancement point is not possible in the change mode for an obvious reason. Of course not. The one who implements an enhancement option does not want do modify the program. That is what the whole business of the enhancement framework is about. So we switch to the enhancement mode by selecting the relevant button:


There we are. We choose the right mouse menu on the line where the enhancement point is and select Create in the submenu:


We get to this dialog window:


As I have told you have first to provide a container for the source plug-in, that is an enhancement implementation. Let us call our enhancement implementation ei_my_implementation. Of course you should not forget the explanatory text. It is possible to create a composite enhancement implementation by using the Create icon. But it is not necessary, and so we do without this meta-container here. And there we are:


Before inserting some code just note that the source code plug-in itself is not named. It is by assigning an enhancement implementation to an enhancement point that a source code plug-in comes into being. We just enter the code: WRITE ‘implementation’.

After the code for the source code plug-in is supplied we should activate it by selecting the respective button:


Source Code Enhancements – The Structure of the Entities

For those who do not feel totally familiar with the structure of the entities, we have created so far let me just sketch the structure of entities we are concerned with:


Our enhancement point uniquely belongs to the (simple) enhancement spot es_my_spot. This spot is assigned to the (simple) enhancement implementation ei_my_implementation. (Simple) enhancement spots containing points or sections and the relevant (simple) enhancement implementations are in an n to m relationship. That means: Points belonging to one spot can be implemented by source code plug-ins belonging to different (simple) enhancement implementations. And source code plug-ins belonging to one (simple) enhancement implementation can implement points belonging to different (simple) enhancement spot. (This does of course not mean that one source code plug-in can implement different points) It is the compilation unit that holds the respective (simple) enhancement spots and (simple) enhancement implementations together: Spots containing points in one report cannot contain points in other programming units. The same is true for the enhancement implementations in an analogous way. An enhancement implementation cannot be assigned to points that belong to different programming units.

Source code plug-ins are unnamed. You create a source code plug-in by assigning a (simple) enhancement implementation to an enhancement point. In turn, this means that a (simple) enhancement implementation can only be assigned once to an enhancement point. Otherwise the identity of a source-code plug-in would be blurred. So much for the details of the structure of the entities involved when creating and implementing an enhancement point. By the way, the structure of the entities and the whole process of defining and implementing is pretty the same for an enhancement section. There is one notable difference: When implementing an enhancement section you have to make sure that there is not more than one active source code plug-in.

Replacing Source Code Plug-Ins

Now let us consider in brief how to handle a use case that is a bit more complex. Suppose you are a customer and want to change a source code plug-in created by a SAP industry solution. The background is that this code is specific to the industry solution and does not fit your needs totally though your company belongs to the respective industry. Changing the source code plug-in in the SAP namespace would, of course, mean modifying it. And this is no attractive move and should be avoided as much as possible. There is a better solution for this problem than modifying the source code plug-in in the SAP namespace.

The Enhancement Framework provides a nice feature to handle this situation. It enables you to overwrite an existing source code plug-in by using or creating a (simple) enhancement implementation that is an object of yours. This means you can substitute a source code plug-in without modifying the plug-in or the code unit it is plugged in. And this is how it works:

Position the cursor on the enhancement you want to replace, choose the right mouse button and select: Enhancement Implementation->Replace.

In the next dialogue window we have to enter the name of a new (simple) enhancement implementation. For reasons already given, it has to be a new one and has to be different from the enhancement implementation to which the source code plug-in to be substituted belongs:


What we do now is pretty the same procedure as when we originally implemented our enhancement point. We enter some code and activate it by selecting the button Activate Enhancements. This is what our enhancement point looks like now:


By using the respective entries in the context menu you can also change and delete source code plug-ins. But you should keep in mind: You should not touch source code plug-ins created by SAP as this would mean to modify a SAP object, in this case, the respective (simple) enhancement implementation. If a source code plug-in created by SAP does not meet your requirements, you should replace it in the way just shown in the last use case. So you should change and delete only the source code plug-ins you have created yourself. Instead of deleting an source code plug-in created by SAP you should replace it by an empty source code plug-in. Again, this is the way to avoid a modification.


By now you should have learned a lot of different things about the source code enhancement technology. Let us first consider the definition part or the role of the enhancement option provider. You know the use cases for this enhancement technology: As an option provider source code enhancements are the means of choice if you do not know the interface of the enhancements to be made. You can also create an enhancement point as a modification and add the rest of the code you need to a source code plug-in assigned to this enhancement point. This helps keeping unavoidable modifications small. Apart from these use cases, the enhancement technology recommended by SAP, in general, is to define a BAdI.

As to the implementing part, you know:

  • how to implement an enhancement point,
  • how to change or delete an source code plug-in of your own,
  • how to replace an existing source code plug-in in the SAP namespace.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member
      By the way, is there a way to deactivate a specific enhancement implementation?  Do we have to use the switch framework?
      Author's profile photo Former Member
      Former Member

      With reference to the following statement, I have a quick question.

      "We go to the source code that we want to enhance, open the respective unit in change mode, put the cursor on a line and choose the right mouse menu:"

      Do we need a modification here by getting the access key for the program? If this is the case, I was wondering how this framework is modification free.


      Author's profile photo Thomas Weiss
      Thomas Weiss
      Blog Post Author
      Obviously, there is some misunderstanding as to what it means that the Enhancement Framework allows modification free enhancements. Properly understood , this means:  You can enhance the source code at existing enhancement options without modifying the code. Or, to speak metaphorically, you can attach something to a hook for free, if there is a hook. But creating an explicit enhancement option, or to stay in the analogy, creating a hook, of course, is a modification. But given the implicit enhancement options that always exist, and the explicit ones provided by SAP there are many cases when a non-SAP developer can accomplish his specific requirements, by implementing the enhancement options that are available. Only if you have made sure that this does not enable you to adapt the code to your needs, you should think of modifying it. But even in this rare situation the Enhancement Framework helps to keeps the modification small. Just add an enhancement option and put all the other code you need in the respective implementation which is in your name space thereby taking advantage of all the features the framework offers.
      Author's profile photo Sachin Murab
      Sachin Murab

      In explict enhancement framework: Is it require SAP access key & How it's diffrent from normal access key .
      If yes than SAP won't support that object further ?I think it's simply change in standard code .Could you provide some details for that .

      Thanks & Regards,
      Sachin S M

      Author's profile photo Former Member
      Former Member
      In explict enhancement framework: Is it require SAP access key & How it's diffrent from normal access key .
      If yes than SAP won't support that object further ?I think it's simply change in standard code .Could you provide some details for that .

      Hi Thomas

      Ihave the same query
      could u plz clarify these statements

      Author's profile photo Former Member
      Former Member
      Hello Thomas,

      I need to implement an enhancement (ENHANCEMENT-SECTION     buchen_03 SPOTS es_mm06ef0b_buchen INCLUDE BOUND.) in an include (MM06EF0B_BUCHEN) that is used by 2 different main programs (SAPLMEPO & SAPMM06E).
      When I create an implementation, it is created for a specific main program.
      How can I create an implementation that is executed irrespective of which main program calls the include?

      Rajeev Natarajan

      Author's profile photo Former Member
      Former Member
      Hello Rajeev,

      I am facing similar situation what yo had asked for,by any chance you are able to resolve.
      Plz let me know if you have done so.


      Author's profile photo Former Member
      Former Member
      hi thomas ,
      what ever information you have provided uptil now is really helpful.
      thanks a lot.
      but i need to do screen enhancement and menu enhancemnet . the way in which u explained soure code and badi , can u explain me in the same way on screen and menu enhancement
      Author's profile photo Former Member
      Former Member
      Hello Thomas,
      I went through the complete web blog series on the enhancement framework.
      These blogs are really excellent.

      Thanks for the information.

      Thanks and Regards,

      Author's profile photo PIERRE LAFON
      Hi Thomas, thank's a lot for all these informations very usefull during an ECC updgrade.
      I have the following question.
      When we made a modification in a SAP abap source, we had an alert during application of a hot package or any upgrade that this source has been modified (thru SPAU). We were able to see if we had to change our additional code depending on the last SAP modification.
      If we now use the enhancement concept, will the system give us any information for exemple if SAP added some lines in a Enhancement section we have implemented ?
      Thanks and Regards
      Author's profile photo Former Member
      Former Member
      Thanks for all 5 blogs.
      They helped me a lot to understand the New Enhancement Framework.


      Author's profile photo Krishnendu Laha
      Krishnendu Laha
      Hi Thomas,

      this is really help full bolg...
      we have a requirement that in some condintions some fields of sales order's main screen should be non-editable...we were decided to change standard SAP code...but after reading ur blog..i as a technical lead thniking to implement any enhancement point (if any available)..

      thanks for this great document...


      Author's profile photo Former Member
      Former Member
      These series of 5 Weblogs by far have been the best amongst the others posted here. Real in depth knowledge. I really appreciate the effort and it has been a great read for me. Thanks
      Author's profile photo Former Member
      Former Member
      Good Post, Tom.

      I will need to enhance Purchasing (PO screens) to add additional elements to both the Header and Line DB and screen objects… and perhaps even add a subscreen with our company-specific data.

      Using old enhancement MM06E005 as a model, how does this get accomplished using the EF environment… examples sure would help.

      Author's profile photo Former Member
      Former Member
      Hi, can the enhancement be done on selection screen? When I tried to add a parameter after first selection-screen block or inside the block, always get error. The standard program i try to enhance is report LSO_RHXBUCH0 (Bookings per Participant). I am sure there is no syntax error on the codes I wrote.
      Author's profile photo Former Member
      Former Member
      Hello Thomas,

      Nice blog !

      It is there any option to change a Badi implementation created by a SAP industry solution, similar to the one you explain in your paper, replacing source code plug-ins ?

      The background is the same as replacing source code plug-ins. The industry solution ( badi implementation ) does not fit to our needs and we would like to change 'the source code-badi implementation' in the SAP namespace.

      Thanks & Regards,

      Victoria Albors

      Author's profile photo Former Member
      Former Member
      During the migration process problems have been reported for this blog. The blog content may look corrupt due to not supported HTML code on this platform. Please adjust the blog content manually before moving it to an official community.
      Author's profile photo ASIF IRFAN
      i am totally new to this and going thru all ur 5 blogs enhancement framework is pretty clear to me and i really liked the idea in last section of modification free enhancement by sustituing with blank instead of delete/change.

      Keep up the good work...
      waiting to read more from you !!


      Author's profile photo Paciello Raffaele
      Paciello Raffaele
      Hi Thomas,

      thanks for your blog, it is very nice.

      Thanks also from my colleague Daniele.


      Author's profile photo Former Member
      Former Member
      Great blog Thomas! This series was very helpful in learning Enhancement Framework. Keep up the good work.
      Author's profile photo Abhijeet Kulkarni
      Abhijeet Kulkarni
      This blog series is indeed good. The content is very good, extremely well illustrated and organised for the understanding of an average ABAP programmer. I was able to clarify a lot of doubts and fill lacuna about my knowledge of the Enhancement Framework. I look forward to use the same more effectively.
      Author's profile photo Sriram S
      Sriram S
      This is an excellent Blog...i got a clear picture on BADI after read this series..Thank you very much ..

      Keep it up.. 🙂