January 14, 2007 SAP 2007 / Page 2 1. Enhancement Frame Work Overview
2. Source Code Plagin Technology
3. Function Group Enhancement Technology
4. Class/Interface Enhancement Technology
5. BADI Technology
4. Summary
Agenda SAP 2007 / Page 3 Enhancement Frame Work Overview
SAP 2007 / Page 4 Adapting SAP Software Reducing TCO Enhancing objects instead of modifying them reduces the effort for adjustment during SP import or upgrade. Disadvantages of modifications No support for multiple users or projects No grouping No support for parallel developments Will appear much more often in adjustment tools Higher adjustment effort
SAP 2007 / Page 5 Motivation: Goals of Enhancement Framework Integration of several enhancement types under one roof BAdIs Function group Enhancement Class/Interface Enhancement Source Code PlugIns WebDynpro Enhancement
into the Enhancement Framework Switchable by Switch Framework Enhancement Browser Upgrade support Possibility to document and group enhancements Multilayer support
SAP 2007 / Page 6 Modifications in an Upgrade (1) class ZCLHELLOWORLD definition public. public section. methods WRITE . endclass.
class ZCLHELLOWORLD implementation. method WRITE. ... select * from scarr into table it_scarr ... endmethod. endclass. SAP 2007 / Page 7 Modifications in an Upgrade (2) class ZCLHELLOWORLD definition public. public section. methods WRITE . endclass.
class ZCLHELLOWORLD implementation. method WRITE.
*{ REPLACE *\select * from scarr into table it_scarr select * from scarr into table it_scarr where carrid = XY. *} REPLACE
endmethod. endclass. SAP 2007 / Page 8 Modifications in an Upgrade (3) class ZCLHELLOWORLD definition public. public section. methods WRITE . endclass.
class ZCLHELLOWORLD implementation. method WRITE.
select * from scarr into table it_scarr order by carrid.
endmethod. endclass. U p g r a d e
SAP 2007 / Page 9 Modifications in an Upgrade (4) class ZCLHELLOWORLD definition public. public section. methods WRITE . endclass.
class ZCLHELLOWORLD implementation. method WRITE.
*{ REPLACE *\select * from scarr into table it_scarr *\ order by carrid. select * from scarr into table it_scarr where carrid = XY. *} REPLACE
endmethod. endclass. A d j u s t m e n t
SAP 2007 / Page 10 Enhancement in an Upgrade (1) class ZCLHELLOWORLD definition public. public section. methods WRITE . endclass.
class ZCLHELLOWORLD implementation. method WRITE. ... select * from scarr into table it_scarr ... endmethod. endclass.
method WRITE. ... select * from scarr into table it_scarr where carrid = XY. ... endmethod.
Overwrite-Enhancement SAP 2007 / Page 11 Enhancement in an Upgrade (2) class ZCLHELLOWORLD definition public. public section. methods WRITE . endclass.
class ZCLHELLOWORLD implementation. method WRITE. ... select * from scarr into table it_scarr ... endmethod. endclass.
method WRITE. ... select * from scarr into table it_scarr where carrid = XY. ... endmethod.
Overwrite-Enhancement U p g r a d e
SAP 2007 / Page 12 Different Kinds of Enhancement Options Enhancement Options for: Source Code Plug-Ins at Beginning/End of Method/Function Module/Form Routine End of a structure End of Private/Protected/Public Section of a local class End of Report and Include ...
Function Modules Enhancements Additional Methods of global Classes Overwrite-, Pre-, and Post-Methods of global classes Optional Parameters of Global Classes and Function Modules
SAP 2007 / Page 13 Different Kinds of Enhancement Options - Frontend Web Dynpro ABAP: Enhancement Options for UI-Elements Pre- and Post-Exits to Web Dynpro Standard Methods New Methods New Navigation Paths (Plugs) New Actions New Attributes New Nodes that hold the data for the UI Hiding of any existing UI-Element
SAP 2007 / Page 14 Multilayer Support Application Development Original Object Add On Development Customer Development Enhancement 1 Enhancement 2 Enhancement 11 Enhancement 11 Enhancement 01 SAP 2007 / Page 15 The Big Picture (1) Composite Enhancement Spot [Simple] Enhancement Spot Enhancement Elements: Such as a BAdI-Definition
Composite Enhancement Spots Container Objects Can contain Other Composite Enhancement Spots [Simple] Enhancement Spots [Simple] Enhancement Spots Container Objects Can contain Enhancement Elements Explicit Enhancement Options Enhancement Definitions
SAP 2007 / Page 16 The Big Picture (2) Composite Enhancement Implementation
[Simple] Enhancement Implementation Enhancement Implementation Elements: Such as a BAdI-Implementation
Composite Enhancement Implementation Container Objects Can contain Other Composite Enhancement Implementations [Simple] Enhancement Implementations [Simple] Enhancement Implementation Can contain Enhancement Implementation Elements Enhancement Implementation Elements Implementations
SAP 2007 / Page 17 Enhancements Relations [Simple] Enhancement Spot Composite Enhancement Spot [Simple] Enhancement Implementation Composite Enhancement Implementation 1 n 1 n
1 n
1 1 n Enhancement Option Enhancement Implementation Element * 1 n 1 n n * n : m for Source Code PlugIns SAP 2007 / Page 18 Differences: Implicit and Explicit Enhancement Options Features of explicit enhancement options More stable due to the fact that they are pre-defined by the object owner Few changes in definition to expect Only at valid source code locations Features of implicit enhancement options Enhancement of arbitrary objects No enhancement spots necessary
SAP 2007 / Page 19 Complexity of the Enhancement Framework Despite this simple structure the Enhancement Framework as a whole is pretty complex: You have different kind of enhancement technologies. At different kind of enhancement options you can attach different types of enhancement elements. The enhancement options are divided in two different classes: Implicit enhancement options which are provided by the framework and exist without any particular preparation by a developer. Explicit enhancement options have to be inserted explicitly in the source code. These explicit enhancement options must belong to a container. On the implementation side all implementation elements, regardless of whether they enhance implicit or explicit enhancement options, belong to other containers. The containers on the definition side and those on the implementation side are assigned to each other with a particular cardinality. SAP 2007 / Page 20 Enhancement Browser Search for Enhancements possibilities Existing Enhancement Implementations Enhancement Implementations to be adjusted after upgrade
SAP 2007 / Page 21 Enhancement Spot Editor Editor for Predefined Enhancement Possibilities (Source Code Enhancements & BAdIs) Integrated in Object Navigator (SE80) common tabs for all Enhancement Spots Tab 3 dependent on enhancement technology: BAdIs or Source Code Enhancements SAP 2007 / Page 22 Enhancement Implementation Editor
Editor for Enhancement Implementations Integrated in Object Navigator (SE80) Tab Properties & Objects common for all enhancement types Tab 3 dependent on enhancement technology: e.g. BAdI-Implementation or Source Code Enhancements SAP 2007 / Page 23 Composite Enhancement Implementation Contained Composite Enhancement Implementations contains [Simple] Enhancement Implementations SAP 2007 / Page 24 Source Code Plugin Technology SAP 2007 / Page 25 Source Code Enhancements Overview Modification-free enhancement of source code
Explicit Enhancement Option Predefined enhancement options can be defined in source code. They are additionally stored inside Enhancement Spots. Implicit Enhancement Option At common enhancement places, implicit Enhancement options are available. Examples: Beginning/End of Include Beginning/End of Method/Function Module/Form Routine End of a structure End of Private/Protected/Public Section of a local class ...
ENHANCEMENT-SECTION ep2 SPOTS s1. WRITE Original. END-ENHANCEMENT-SECTION. SAP 2007 / Page 27 Explicit Enhancement Options SAP 2007 / Page 28 Implicit Enhancement Options SAP 2007 / Page 29 Enhancement Types in Source Code ENHANCEMENT-POINT <name> SPOTS <spot1> [<spot2>] .. [STATIC] Static e.g. additional data declaration Dynamic e.g. additional source code
ENHANCEMENT-SECTION <name> SPOTS <spot1> [<spot2>] .. [STATIC] Static e.g. replace an existing data declaration Dynamic e.g. replace source code
SAP 2007 / Page 30 Enhancement Spots & Implementations Compilation unit SpotA Point A Section B Point C Point E Point F Spot Hugo Spot Flights Point D Physical Part of Compilation Unit Assigned to Compilation Unit SAP 2007 / Page 31 Physical Part of Compilation Unit Enhancement Spots & Implementations SpotA Point A Section B Point C [Simple] Enhancement Implementation 1 E3 Point E Point F Spot Hugo Spot Flights E2 E2 Compilation Unit Assigned to Compilation Unit Point D Physical Part of Compilation Unit SAP 2007 / Page 32 Enhancement Implementation Rules [Simple] Enhancement Implementation The [simple] enhancement implementation is a container or set of enhancement implementation elements. In the context of source code enhancements, explicit enhancement points can be enhancement points or - sections. Simple Assignment You can assign a [simple] enhancement implementation only to one enhancement point. This means that its not possible to have two implementations for one enhancement point inside the same [simple] enhancement implementation. Assignments You can assign many different enhancements to one point, but, as already told, each enhancement only once to one point. A point of one spot can be assigned to many enhancements, and one enhancement can be assigned to different points of one or different spots (m to n relation) All enhancements assigned to a point belong to the same compilation unit as the respective point. An enhancement cannot be assigned to spots of different compilation units. So it is the compilation unit which keeps the points and enhancements together. There are no spots or enhancements which have parts in different compilation units. SAP 2007 / Page 33 Physical Part of Compilation Unit Enhancement Spots & Implementations SpotA Point A Section B Point C [Simple] Enhancement Implementation 1 E3 [Simple] Enhancement Implementation 2 E1 E2 Point E Point F Spot Hugo Spot Flights E2 E2 E2 Compilation Unit Assigned to Compilation Unit Point D Physical Part of Compilation Unit SAP 2007 / Page 34 Multi implementations for enhancement points
Multi implementations for enhancement points It is possible to have more than one implementation for an enhancement point which belong to different [simple] enhancement implementations. For example Point D has a enhancement implementation in [Simple] Enhancement 1 and in [Simple] Enhancement 2.
A point of one spot can be assigned to many enhancements, and one [simple] enhancement can be assigned to different points of one or different spots (m to n relation).
If there are multiple implementations for an enhancement point, all implementations will be processed in an undefined order. (Currently the order is alphabetical, but this may change in the future)
SAP 2007 / Page 35 Enhancement Sections & Implementations SpotA Point A Section B Point C [Simple] Enhancement Implementation 1 E3 [Simple] Enhancement Implementation 2 E1 E2 Point E Point F Spot Hugo Spot Flights E2 E2 E2 [Simple] Enhancement Implementation 3 E1 Compilation Unit Point D E2 Physical Part of Compilation Unit Assigned to Compilation Unit SAP 2007 / Page 36 Overlay Enhancement Existing Enhancements must not be modified. Enhance the Enhancement instead!
Program Enhancement e.g. Industry Solution Enhancement e.g. Customer Example: An SAP Program is enhanced by an Industry Solution.
The source code of the Industry Solution enhancement is exchanged by a customer enhancement.
SAP 2007 / Page 37 Editor Modes for Enhancements Use Change Mode for creating enhancement points & sections. use button Display <-> Change to switch to change mode.
Use Enhancement Mode for creating enhancement implementations. use button Change Enhancements to switch to Enhancement mode use button Display <-> Change to leave Enhancement mode
SAP 2007 / Page 38 SAP 2007 / Page 39 Function Group Enhancement SAP 2007 / Page 40 Function Group Enhancements Function Group Enhancements allow: Adding new optional parameters to existing function modules SAP 2007 / Page 41 Additional Parameters Add optional parameters to existing function modules SAP 2007 / Page 42 SAP 2007 / Page 43 Class Enhancement SAP 2007 / Page 44 Class/Interface Enhancements Class/Interface Enhancements allow addition of: optional parameters to existing methods methods events and event handlers references to interfaces* types * exits to existing methods Pre-Exit Called at the beginning of a method Post-Exit Called at the end of a method Overwrite-Exit Replaces the original method access to private and protected attributes of the original class *
* Available with NetWeaver 7.1 SAP 2007 / Page 45 Additional Parameters in Methods Add optional parameters to existing methods SAP 2007 / Page 46 Additional Methods Add new methods SAP 2007 / Page 47 Pre/Post Exits Method Hugo.
Endmethod.
Call method instance->hugo( ).
Method Pre.
. Endmethod. Method Post. . . Endmethod. source code. source code. source code. SAP 2007 / Page 48 BADI Technology SAP 2007 / Page 49 What are Business Add-Ins A BAdI is an anticipated point of extension these points act like sockets and exist in the original source code is a predefined anchor for an Object PlugIn has a well-defined interface in contrast to source code plugIns and is therefore more stable to changes in the original source code has switchable implementation(s) (by switches introduced by the Switch Framework)
SAP 2007 / Page 50 BAdI Patterns (1) BAdI as a Service or Delegation
GET BADI mytaxbadi FILTERS LANGUAGE = sy- langu. ..
CALL BADI mybadi->add_tax FILTER country = mycountry EXPORTING value = my_value IMPORTING result = my_result. .. write / my_result.
METHOD if_mybadi~add_tax. result = value * 1.20. ENDMETHOD. METHOD if_mybadi~add_tax. result = value + myfunc(value). ENDMETHOD. The calculation depends on the filter value. Only one active implementation is allowed for one filter value. SAP 2007 / Page 51 BAdI Patterns (2) BAdI as Classical User Exit
GET BADI mybadi. .. CALL BADI mybadi->value_changed EXPORTING value = my_value
..
METHOD if_mybadi~value_changed. write value .. ENDMETHOD. METHOD if_mybadi~value_changed. insert value .. ENDMETHOD. The BAdI allows to perform an addional step in a standard process. The core functionality doesnt need any implementation, but the implemantation may react on a core event. Several implementations may be called in a sequence. SAP 2007 / Page 52 Comparison: Usage of Old BAdIs vs. New BAdIs With Classic BAdI
Selecting implementations and issuing calls is mixed. Calls are redirected over a proxy class.
With New BAdI
Selection occurs when the handle is requested. Implementations are called directly (without a proxy) DATA: bd TYPE REF TO if_intf. DATA: flt TYPE flt.
flt-lang = `D`. CALL METHOD bd->method EXPORTING x = 10 flt_val = flt. data bd type ref to badi_name. get badi bd filters lang = `D`. call badi bd->method exporting x = 10. SAP 2007 / Page 53 New Features Overview New BAdIs New Features Are integrated directly in the ABAP Language/Runtime Improved filter support allows non-character filter types (packed, numeric, string) and complex filter conditions Enable reusable implementation instances Different kinds of default implementations Control of the lifetime of implementations (BAdI-context) Allow for inheritance of implementations SAP 2007 / Page 54 Evaluation at Compile Time Better Performance/Lower Memory consumption Database access only at compile time No dynamic calls Internal handle-class integrated in SAP Kernel Special optimizations for BAdIs with No active implementations: GET BADI is ignored while compiling CALL BADI just takes the time for a simple if-statement. One active implementation Direct call of that implementation Only implementations, that are switched on are considered. Active Flag Only active implementations are considered
40-600 times faster than Classic BAdIs
SAP 2007 / Page 55 BAdI-Handle is No Proxy CALL BADI bd->m exporting ... importing ... Inst1 Inst2 Inst2 CALL BADI bd->m exporting ... importing ... Inst1 Inst2 Inst2 bd SAP 2007 / Page 56 Integration Into ABAP (1) BAdIs are represented by a reference to BAdI-Handles:
If there are two implementations of badi_name that are selected for the filter value f=5, this yields:
DATA bd type ref to badi_name. GET BADI bd FILTER f = 5. Inst1 Inst2 Cl_imp1 Cl_imp2 bd badi_name SAP 2007 / Page 57 BAdI-Definition and Enhancement Spot BAdI Definition A BAdI Implementation 1 BAdI Implementation 2 BAdI Implementation 3 Definition Implementation BAdI Definition B BAdI Definition C BAdI Implementation 2 BAdI Implementation 2 SAP 2007 / Page 58 BAdI-Definition and Enhancement Spot Simple Enhancement Spot Spot_1 BAdI Definition A BAdI Implementation 1 BAdI Implementation 2 BAdI Implementation 3 Definition Implementation BAdI Definition B BAdI Definition C BAdI Implementation 2 BAdI Implementation 2 SAP 2007 / Page 59
BAdI Implementation 3 Definition Implementation BAdI BADI_B BAdI BADI_C BAdI Implementation 4 BAdI Implementation 5 BAdI Implementation 6 Simple Enhancement Spot Spot_2 BAdI BADI_E SAP 2007 / Page 63 Default/Fallback Implementations Types of Implementations A BAdI-Definition may have an associated fallback class A BAdI-Implementation is either default or non-default Selection Procedure: (during GET BADI) 1. Apply selection to all non-default implementations. 2. If nothing has been selected, apply selection to all default implementations. 3. If still nothing has been selected, take the fallback class. SAP 2007 / Page 64 Example Implementation A BAdI can refer to example classes. A BAdI Implementation can be declared as an example implementation. During creation of a new BAdI implementation a popup allows to copy or inherit from the example implementation or class.
SAP 2007 / Page 65 Control the Lifetime of Implementations
Always new instances are created
Per implementation class there is one instance
Per context reference and implementation class there is one instance
ctx_a ctx_b ctx_c SAP 2007 / Page 66 DATA: bd1 TYPE ref to badi_name. GET BADI bd1.
Inst1 Inst2 Cl_imp1 Cl_imp2 bd1 Instantiation With Option Reuse SAP 2007 / Page 67 DATA: bd1 TYPE ref to badi_name, bd2 TYPE ref to badi_name. GET BADI bd1. GET BADI bd2.
Inst1 Inst2 Cl_imp1 Cl_imp2 bd1 bd2 Inst3 Inst4 Instantiation With Option No Reuse SAP 2007 / Page 68 DATA: bd1 TYPE ref to badi_name. GET BADI bd1.
Inst1 Inst2 Cl_imp1 Cl_imp2 bd1 Instantiation With Option Reuse SAP 2007 / Page 69 Instantiation With Option Reuse DATA: bd1 TYPE ref to badi_name, bd2 TYPE ref to badi_name. GET BADI bd1. GET BADI bd2.
Inst1 Inst2 Cl_imp1 Cl_imp2 bd1 bd2 SAP 2007 / Page 70 Instantiations and Contexts (1) A context class is a class implementing if_badi_context, a context reference is a reference to an instance of a context class
In ABAP: DATA ctx TYPE REF TO cl_myctx.
GET BADI bd CONTEXT ctx. With a context there is one instance per context reference and implementation class. Passing the same context yields identical implementation instances SAP 2007 / Page 71 DATA: bd1 TYPE ref to badi_name, bd2 TYPE ref to badi_name, bd3 TYPE ref to badi_name. GET BADI bd1 CONTEXT same_ctx. GET BADI bd2 CONTEXT same_ctx. GET BADI bd3 CONTEXT diff_ctx.
Inst1 Cl_imp1 bd1 bd2 bd3 Inst2 same_ctx diff_ctx Instantiations With Context SAP 2007 / Page 72 BAdI Migration Automatic migration by selecting utilitiesmigration from BAdI Builder (se18) Specify Enhancement Spot for BAdI Defintion Specify Enhancement Implementation for BAdI Implementation no special knowledge necessary effort: 5 minutes per BAdI (with some implementations). The migration can be automated.
Automatic migration by selecting utilitiesmigration from BAdI Builder (SE18) Specify an Enhancement Spot for the BAdI Definition Specify an Enhancement Implementation for every BAdI Implementation No special knowledge necessary
effort: 5 minutes per BAdI.
Attention: Migrate your own BAdIs only! Never ever migrate SAP BAdIs! SAP 2007 / Page 73 Implementation n Automatic (Partial) BAdI Migration CL_EXITHANDLER=> GET_INSTANCE
CALL METHOD if_ex_badi->m
Proxy Class CL_EX_<BAdI>
BAdI Contex t Implementation 2 Implementation 1
DATA mybadi type my_testbadi.
GET BADI mybadi FILTERS LANG = DE CONTEXT me.
CALL BADI mybadi->meth.
Classical Code is still used SAP 2007 / Page 74 BAdI Migration Complete migration: Delete the classic BAdI Find all calls of the classic BAdI by GET_INSTANCE and reprogram the BAdI call using the new commands GET BADI and CALL BADI. For BAdIs that are called more than once in one program the context settings may be changed to improve the performance. Expert knowledge of the application necessary
Effort: from some minutes up to some days per BAdI SAP 2007 / Page 75 Performance Comparison Classic BAdI Migrated BAdI New BAdI 1 2-27 x faster than classic BAdI 40-600 x faster than classic BAdI A BAdI call is ca. 7.5% slower than a method call!
The more implementations defined, the higher is the improvement on performance SAP 2007 / Page 76 BAdI Migration Automatic migration by selecting utilities migration from BAdI Builder (SE18)
SAP 2007 / Page 77 Best-practice recommendation Use a BADI; if there is no BADI to suite your need then, Try to solve it using Explicit Source code, Function and Class enhancements; and, Implicit Source code enhancement should be the last option to choose Of course, if none of the above could solve your adaptation needs and if your business demands it, modification should be the last option. SAP 2007 / Page 78 Summary The Enhancement Framework offers new possibilities to extend the SAP Standard instead of modifying it. Source Code PlugIns Function Group Enhancements Class Enhancements New BAdIs The new BAdIs are more flexible and faster than the classic ones. The Enhancements offered by Enhancement Framework and several other object types can be switched by the Switch Framework. SAP 2007 / Page 79 Frame Work Limitations It is probably possible to achieve your aim without modification very often. But still this is not always possible. 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. SAP 2007 / Page 80 Further Information
Related SAP Education and Certification Opportunities http://www.sap.com/education/ BC427 Enhancement Framework
SAP Public Web http://help.sap.com Documentation SAP Netweaver Application Platform ABAP technology ABAP Workbench Enhancement Framework http://sdn.sap.com Weblogs by author Thomas Weiss SAP 2007 / Page 81 Thank you!