SAP Enhancements, Exits and BAdIs Overview |

107
AB1012 - Enhancements, AB1012 - Enhancements, Exits and BADI's Exits and BADI's

description

download this document from http://sapdocs.info/sap/abap/sap-enhancements-and-modifications-exits-badis-overview-pdf-training-tutorial-document/Want to get more SAP Downloads ?Visit http://sapdocs.info

Transcript of SAP Enhancements, Exits and BAdIs Overview |

Page 1: SAP Enhancements, Exits and BAdIs Overview |

AB1012 - Enhancements, Exits AB1012 - Enhancements, Exits and BADI'sand BADI's

Page 2: SAP Enhancements, Exits and BAdIs Overview |

Enhancements, Exits and BADI'sEnhancements, Exits and BADI's

1 Introduction

2 Syntax Description

3 Demonstration

4 Exercises

5 HelpMe

Page 3: SAP Enhancements, Exits and BAdIs Overview |

Enhancements, Exits and BADI'sEnhancements, Exits and BADI's

1 Introduction

2 Syntax Description

3 Demonstration

4 Exercises

5 HelpMe

Page 4: SAP Enhancements, Exits and BAdIs Overview |

IntroductionIntroduction

• Purpose Purpose

• Use Use

• ChallengesChallenges

EXIT sEXIT s are nothing but the are nothing but the R/3 Enhancements R/3 Enhancements which allows you to which allows you to add your own functionality to SAP’s standard business applications add your own functionality to SAP’s standard business applications without having to modify the original applications.without having to modify the original applications.

Page 5: SAP Enhancements, Exits and BAdIs Overview |

Introduction Introduction

PurposePurpose

To introduce the techniques of enhancement in standard SAP To introduce the techniques of enhancement in standard SAP system. SAP creates customer exits for specific programs, system. SAP creates customer exits for specific programs, screens, and menus within standard R/3 applications. These screens, and menus within standard R/3 applications. These exits do not contain any functionality. Instead, the customer exits do not contain any functionality. Instead, the customer exits act as hooks. You can hang your own add-on exits act as hooks. You can hang your own add-on functionality onto these hooks.functionality onto these hooks.

Page 6: SAP Enhancements, Exits and BAdIs Overview |

IntroductionIntroductionUseUse

• They do not affect standard SAP source code.They do not affect standard SAP source code.When you add new functionality to your SAP System using SAP’s exits, you When you add new functionality to your SAP System using SAP’s exits, you do not alter the source code of standard SAP programs in any way. The code do not alter the source code of standard SAP programs in any way. The code and screens you create are encapsulated as separate objects. These customer and screens you create are encapsulated as separate objects. These customer objects are linked to standard applications, but exist separately from SAP’s objects are linked to standard applications, but exist separately from SAP’s standard software package.standard software package.

• They do not affect software updates.They do not affect software updates.When you add new functionality to your SAP System using SAP’s exits, your When you add new functionality to your SAP System using SAP’s exits, your objects (called customer objects) must adhere to strict naming conventions. objects (called customer objects) must adhere to strict naming conventions. When it comes time to upgrade a to a new software release, customer objects’ When it comes time to upgrade a to a new software release, customer objects’ names ensure that they will not be affected by any changes or new additions names ensure that they will not be affected by any changes or new additions to the standard software package. to the standard software package.

Page 7: SAP Enhancements, Exits and BAdIs Overview |

IntroductionIntroduction

ChallengesChallenges

• Customer exits are not available for all programs and screens found in the SAP System. .

Page 8: SAP Enhancements, Exits and BAdIs Overview |
Page 9: SAP Enhancements, Exits and BAdIs Overview |

• Any change made to an SAP object in a customer system is called a modification. Customers usually modify their systems for one of two reasons. Either they make changes to the SAP standard in order to adjust the R/3 System to their specific business needs (actual modifications), or they alter individual SAP objects in order to correct an error (as recommended in an SAP error note).

• You should only modify the SAP standard if the modifications you want to make are absolutely necessary for optimizing work flow in your company. Be aware that good background knowledge of application structure and flow are important prerequisites for deciding what kind of modifications to make and how these modifications should be designed.

Page 10: SAP Enhancements, Exits and BAdIs Overview |

1 3

4

2

Page 11: SAP Enhancements, Exits and BAdIs Overview |

Enhancements, Exits and BADI'sEnhancements, Exits and BADI's

1 PrepareMe

2 Syntax description

3 Demonstration

4 Exercises

5 HelpMe

Page 12: SAP Enhancements, Exits and BAdIs Overview |

ABAP DICTIONARYABAP DICTIONARY

Table Enhancements: Table Enhancements: There are two ways that you can add additional fields to tables There are two ways that you can add additional fields to tables without modifying your system.without modifying your system.

• Append Structures:Append Structures:o Append structures allow you to enhance tables by adding fields to them that are

not part of the standard. With append structures, customers can add their own fields to any table or structure they want.

o Append structures are created for use with a specific table. However, a table can have multiple append structures assigned to it.

• Customizing Includes:Customizing Includes:o If customers know in advance that one of the tables or structures delivered to

them by SAP needs to have customer-specific fields added to it, an SAP application developer can include these fields in the table using a Customizing include statement.

o The same Customizing include can be used in multiple tables or structures. This provides for consistency in these tables and structures whenever the itself include is altered.

Page 13: SAP Enhancements, Exits and BAdIs Overview |

ABAP DICTIONARYABAP DICTIONARY

Field Exits: Field Exits:

Field exits take you from a screen field with a data element reference to a function module. Field exits can be either global or local.

• Field exit function modules adhere to the following naming convention:

o prefix: FIELD_EXIT_

o name: <data element name>_

o suffix (optional): 0 to 9, A to Z

Page 14: SAP Enhancements, Exits and BAdIs Overview |

ABAP DICTIONARYABAP DICTIONARY

Text Enhancements:Text Enhancements:

• Possible text enhancements include customer keywords and customer documentation of data elements.

• Text enhancements differ from other application enhancements in that they take effect globally in all related SAP applications after activation (global enhancements).

Page 15: SAP Enhancements, Exits and BAdIs Overview |

SAP Application EnhancementSAP Application Enhancement

Page 16: SAP Enhancements, Exits and BAdIs Overview |

Customer Enhancement ProjectsCustomer Enhancement Projects

Page 17: SAP Enhancements, Exits and BAdIs Overview |

Customer ExitsCustomer Exits

• Function Module ExitsFunction Module Exits

• Menu ExitsMenu Exits

• Screen ExitsScreen Exits

Page 18: SAP Enhancements, Exits and BAdIs Overview |

Implementation of Enhancement in Customer Implementation of Enhancement in Customer SystemSystem

Page 19: SAP Enhancements, Exits and BAdIs Overview |

Creating Customer Enhancement ProjectsCreating Customer Enhancement Projects

Page 20: SAP Enhancements, Exits and BAdIs Overview |

Assigning SAP Enhancement to customer projectsAssigning SAP Enhancement to customer projects

Page 21: SAP Enhancements, Exits and BAdIs Overview |

Editing ComponentsEditing Components

Activating Enhancement ProjectsActivating Enhancement Projects

Page 22: SAP Enhancements, Exits and BAdIs Overview |

Business Transaction EventsBusiness Transaction Events

It is also called as Open FI enhancement technique which is based on It is also called as Open FI enhancement technique which is based on the following principle:the following principle:

• Application developers must define their interface in a function Application developers must define their interface in a function module. An assignment table is read in the corresponding (generated) module. An assignment table is read in the corresponding (generated) code, and the customer modules assigned are called dynamically.code, and the customer modules assigned are called dynamically.

• This technique differentiates between enhancements that are only This technique differentiates between enhancements that are only allowed to have one implementation and enhancements that can call allowed to have one implementation and enhancements that can call multiple implementations in any sequence desired. Both industry-multiple implementations in any sequence desired. Both industry-specific and country-specific enhancements may be definedspecific and country-specific enhancements may be defined . .

Page 23: SAP Enhancements, Exits and BAdIs Overview |

Enhancement FrameworkEnhancement Framework

• The new enhancement concept of the ABAP The new enhancement concept of the ABAP Workbench enables the integration of different Workbench enables the integration of different concepts for modifying and enhancing concepts for modifying and enhancing development objects. The enhancement development objects. The enhancement concept is supported by the Enhancement concept is supported by the Enhancement Builder tool and ABAP language elements. Builder tool and ABAP language elements.

• The objective of the Enhancement Framework The objective of the Enhancement Framework is to provide a technology to create is to provide a technology to create modification-free enhancements and to unify modification-free enhancements and to unify all possible ways of modifying or enhancing all possible ways of modifying or enhancing Repository objects.Repository objects.

Page 24: SAP Enhancements, Exits and BAdIs Overview |

Multilayer SupportMultilayer Support

Page 25: SAP Enhancements, Exits and BAdIs Overview |

Enhancement Spots

• Enhancement Spots can only be of type Enhancement Spots can only be of type source code Enhancement or BAdI.source code Enhancement or BAdI.

• Enhancement Spots manage explicit Enhancement Spots manage explicit Enhancement OptionsEnhancement Options– While implicit enhancement options always exist

and do not require any special management, explicit enhancement options created in an initial system must be made known to developers in target systems via Enhancement Spots.

Page 26: SAP Enhancements, Exits and BAdIs Overview |

Enhancement Implementations

• Enhancement implementations manage their enhancements.

• Enhancements made by developers in follow-on systems are managed as Enhancement Implementations. This applies to all enhancement options, both explicit and implicit.

Page 27: SAP Enhancements, Exits and BAdIs Overview |

Composite Enhancement Spots• Composite Enhancement Spots are used to organize Enhancements

Spots in a tree structure.

• Container Objects

• Can contain– Other Composite Enhancement Spots– [Simple] Enhancement Spots

• Container Objects

• Can contain Enhancement Elements

Page 28: SAP Enhancements, Exits and BAdIs Overview |

Composite Enhancement Implementation

• Composite Enhancement Implementations are used to organize Enhancement Implementations in a tree structure.

• Container Objects• Can contain

– Other Composite Enhancement Implementations– [Simple] Enhancement Implementations

• Can contain Enhancement Implementation Elements

Page 29: SAP Enhancements, Exits and BAdIs Overview |

Composite Enhancement Implementation

• The first tab displays which (Simple) Enhancement Implementations are contained.

• The second tab displays which other Composite Enhancement Implementations are contained.

Page 30: SAP Enhancements, Exits and BAdIs Overview |

Enhancement RelationsEnhancement Relations

Page 31: SAP Enhancements, Exits and BAdIs Overview |

Source Code EnhancementSource Code Enhancement• It is possible to enhance ABAP source code –

without modifications – using source code enhancements.

• You can insert enhancements at implicit and explicit enhancement options. The Enhancement Builder tools for defining explicit enhancement options and for implementing enhancements are integrated in the ABAP Editor.

Page 32: SAP Enhancements, Exits and BAdIs Overview |

Features of explicit & Implicit Features of explicit & Implicit enhancement optionsenhancement options

• Features of explicit enhancement options– More stable, pre-defined– 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

Page 33: SAP Enhancements, Exits and BAdIs Overview |

Difference: Explicit and Implicit OptionDifference: Explicit and Implicit Option

• Explicit Enhancement Options– In ABAP programs, developers can select

either a position or a program section as an explicit enhancement option. In follow-up systems (partners and customers) can implement source code plugins at such a position or they replace the selected section.

• Implicit Enhancement Options– Implicit enhancement options always exist.

Page 34: SAP Enhancements, Exits and BAdIs Overview |

Explicit Enhancement Options

• To mark a position in an ABAP program as an explicit enhancement option, the following ABAP statement is used:– ENHANCEMENT-POINT enh_id SPOTS spot1 spot2 ...

• To mark a section in an ABAP program as an explicit enhancement option, the following ABAP statement is used: – ENHANCEMENT-SECTION enh_id SPOTS spot1 spot2 ...– END-ENHANCEMENT-SECTION.

• Currently it is only possible to assign an enhancement point/section to one Enhancement spot.

Page 35: SAP Enhancements, Exits and BAdIs Overview |

Implicit Enhancement Options• Implicit enhancement options can be displayed in the ABAP Editor by

following the path Edit → Enhancement Operations → Show Implicit Enhancement Options and then implemented using source code enhancements.

• Implicit enhancement options always exist and no enhancement spot is assigned to them.

• In ABAP programs, implicit enhancement options are predefined at the following places:– End of an include (with exceptions, e.g. not at the end of a method include)– End of the PUBLIC-, PROTECTED-, PRIVATE-SECTION of a local class– End of the implementation part of a class (before the ENDCLASS, which

belongs to CLASS …IMPLEMENTATION)– End of a interface definition (before the ENDINTERFACE)– End of a structure definition (before TYPES END OF, DATA END OF,

CONSTANTS END OF and STATICS END OF)– Begin and End of a procedure (FORM, FUNCTION, METHOD), that is after

command FORM, FUNCTION und METHOD and before statement ENDFORM, ENDFUNCTION and ENDMETHOD.

– End of the CHANGING-, IMPORTING-, EXPORTING-parameter list of a method. These enhancement options are located in the middle of a statement.

Page 36: SAP Enhancements, Exits and BAdIs Overview |

Enhancement Type Enhancement Type • ENHANCEMENT-POINT <name> SPOTS <spot1> [<spot2>] ..

[STATIC]– Static: Additional data declaration– Dynamic: Additional source code

• ENHANCEMENT-SECTION <name> SPOTS <spot1> [<spot2>] ..[STATIC]– Static: Replace an existing data declaration– Dynamic: Replace source code

• Data declarations are always static, even if they are inside an implementation of a dynamic enhancement point.

• Form routines, methods and local classes can‘t be part of dynamic enhancement points/sections. Therefore it is necessary to place them into static enhancement points/sections.

• Static enhancement points/sections are marked with the addition “STATIC” in source code. Dynamic enhancement points/sections do not contain an addition.

Page 37: SAP Enhancements, Exits and BAdIs Overview |

Functional Module EnhancementFunctional Module Enhancement

• Function Module Enhancements allow– Adding new optional parameters to

existing function modules– Enhance the source code

Page 38: SAP Enhancements, Exits and BAdIs Overview |

Class/Interface EnhancementClass/Interface Enhancement• Class/Interface Enhancements allow

addition of:– Optional parameters to existing methods– Methods– Events and event handlers– References to interfaces– 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

Page 39: SAP Enhancements, Exits and BAdIs Overview |

Enhancements, Exits and BADI'sEnhancements, Exits and BADI's

1 PrepareMe

2 Syntax Description

3 Demonstration

4 Exercises

5 HelpMe

Page 40: SAP Enhancements, Exits and BAdIs Overview |

User ExitsUser Exits

Page 41: SAP Enhancements, Exits and BAdIs Overview |

DemonstrationDemonstration

Function Module ExitsFunction Module Exits

Page 42: SAP Enhancements, Exits and BAdIs Overview |

DemonstrationDemonstration

Menu ExitsMenu Exits

Page 43: SAP Enhancements, Exits and BAdIs Overview |

DemonstrationDemonstration

Screen Exits Screen Exits

Page 44: SAP Enhancements, Exits and BAdIs Overview |

DemonstrationDemonstration

Field Exits – It is triggered at field level.Field Exits – It is triggered at field level.

It is attached at data element It is attached at data element

Specific to one screen only or to all the screen where Specific to one screen only or to all the screen where field appears.field appears.

Field exit is not allowed in SAP version 4.7 and above . Field exit is not allowed in SAP version 4.7 and above .

Example with screen shots for consultants working in Example with screen shots for consultants working in

SAP V 4.6 below version.SAP V 4.6 below version.

Page 45: SAP Enhancements, Exits and BAdIs Overview |
Page 46: SAP Enhancements, Exits and BAdIs Overview |
Page 47: SAP Enhancements, Exits and BAdIs Overview |
Page 48: SAP Enhancements, Exits and BAdIs Overview |
Page 49: SAP Enhancements, Exits and BAdIs Overview |

Business Add-Ins (BAdI)

Page 50: SAP Enhancements, Exits and BAdIs Overview |

What are BAdIs?What are BAdIs?• is an anticipated point of extension – these points act like sockets and exist in the original source code

• based on ABAP Objects. BAdI defines an interface that can be implemented by BAdI-implementations that are transport objects of their own

• Important! There are 2 roles: Enhancement Option-provider & Implementer.

• In the above context, Enhancement Implementation can be done only if option (hook) is provided by the Option-provider. In simple words there are no implicit BAdIs.

Note: In the following slides, Definitions are created so as to understand the method of BAdI definition & for example purpose. As stated above this is the role of Enhancement Option-Provider.

Classic BAdIs already exist since SAP Release 4.6

BAdIs have been Re-implemented in ECC7.0 under the new Enhancement Framework & Switch Framework

Page 51: SAP Enhancements, Exits and BAdIs Overview |

Classic BAdIs• To understand what a powerful pattern a BAdI is, we will now define &

then implement a BAdI

BAdI Class (Proxy Class)

Uncheck the ‘Multiple Use’ checkbox. We want to allow only one implementation.

Function Code Enhancements

Screen Enhancements

SE18: BAdI Definition

Page 52: SAP Enhancements, Exits and BAdIs Overview |

Classic BAdIsDouble Click on the Interface

Name to define methods, parameters, exceptions for

that interface

Class Builder Screen will open up.

Page 53: SAP Enhancements, Exits and BAdIs Overview |

Classic BAdIs

Add a Method & specify it as Instance MethodClick on Parameters to add

Importing / Exporting Parameters

Click on ‘Exceptions’ to define exceptions that will be handled

Page 54: SAP Enhancements, Exits and BAdIs Overview |

Classic BAdIs

Add any Exception. For Class-based exceptions check the ‘Exception

Classes’ option

Add an Event Name

Add an Event Handler Method

Adding event handling & exception(s) is not a necessary step…

Page 55: SAP Enhancements, Exits and BAdIs Overview |

Classic BAdIs

Save and activate the BAdI definition!

Page 56: SAP Enhancements, Exits and BAdIs Overview |

BADI ImplementationBAdI Implementation (SE19)

Double Click on the Method to modify the Method code (Class Builder)

SE19: BAdI Implementation

Page 57: SAP Enhancements, Exits and BAdIs Overview |

BADI Implementation

Save and activate the BAdI implementation!

Page 58: SAP Enhancements, Exits and BAdIs Overview |

Using the BAdI…(Calling the BAdI)

Execute the Report Program.

Page 59: SAP Enhancements, Exits and BAdIs Overview |

Implementation for SAP provided BAdI…Roles: (BADI Definition & Implementation)• Developer: Enhancement (BAdI) Option-Implementer• SAP: Option-Provider

BAdI as a ‘controlled’ Enhancement Option:• Option-provider defines the interface and limits the implementer to

the class that the implements the BAdI• Assured that BAdI implementer can only change the parameters

handed over to the BAdI by the option provider

Steps:1. Search for the BAdI corresponding to the transaction2. Create a custom Implementation for the BAdI by adding code in the

appropriate method3. Test that the method with custom code is invoked on executing the

transaction.

Page 60: SAP Enhancements, Exits and BAdIs Overview |

BAdI ImplementationBAdI Implementation

Create Material using MM01. Copy from existing Material.

Select the required views.

Page 61: SAP Enhancements, Exits and BAdIs Overview |

BAdI ImplementationBAdI ImplementationEnter mandatory data and

click on Save.

Check the Exit Name ‘BADI_MATERIAL_CHECK’.

This is the BAdI we are going to implement.

Page 62: SAP Enhancements, Exits and BAdIs Overview |

Implementing the BAdI ‘BADI_MATERIAL_CHECK’

Go to SE18 & check the BAdI definition (Methods)

We will be using the ‘CHECK_DATA’ method. Double Click to see the

Method Parameters.

Page 63: SAP Enhancements, Exits and BAdIs Overview |

Implementing BADIImplementing BADIGo to SE19. Specify a name for the BAdI Implementation.

Enter the Definition Name.

Double-click the method ‘CHECK_DATA’ to enter the

source code

Page 64: SAP Enhancements, Exits and BAdIs Overview |

Implementing BADIImplementing BADI

Enter code inside the ‘Method…End

Method’

We are only showing an message in this case; if division in ‘Basic Data’ tab of Material Creation is not entered.The structure CMARA is defined as ‘Exporting Parameter’. Data can be modified using this.

Page 65: SAP Enhancements, Exits and BAdIs Overview |

BAdI ImplementationBAdI Implementation

Activate the Implementation

Page 66: SAP Enhancements, Exits and BAdIs Overview |

Testing the BAdI

MM01 / MM02 and create / change material and save. On clicking

Save, our BADI will trigger.

Testing the BAdI implementation (BADI_MATERIAL_CHECK)

Message is displayed (Division not entered)

Page 67: SAP Enhancements, Exits and BAdIs Overview |

BAdIs…in the new Enhancement Framework (ECC 6.0)

• How the new BAdIs differ from the Classic BAdI?• Good news is that…basic thing about the BAdI remains the

same!• Differ in the manner in which new BAdI is embedded in the

container-structure of the Enhancement Framework• Better performance & Lower Memory consumption • Evaluates as much information as possible during compile time• 40-600 times faster than Classic BAdIs• Internal handle-class integrated in the SAP Kernel• Provides ‘switchable’ implementation(s) through use of Switch

Framework• Special optimizations with ‘GET BADI’ & ‘CALL BADI’ (new

ABAP commands)• Implementation Inheritance

Page 68: SAP Enhancements, Exits and BAdIs Overview |

Usage of old (classic) BAdIs versus New BAdIs…

• Two new ABAP commands for the new BAdI:

• GET BADI <handle> : returns a handle to all ‘active’ instances of the implementations of the respective BAdI

• CALL BADI <handle> <method> : all active implementations are selected and the method of BAdI is called (amounts to a loop with different method calls in it)

Page 69: SAP Enhancements, Exits and BAdIs Overview |

Enhancement Spot as a container for BAdI…

• Enhancement Framework has containers for BAdI implementations as well

Page 70: SAP Enhancements, Exits and BAdIs Overview |

New BAdIs

Create a new Enhancement Spot

Page 71: SAP Enhancements, Exits and BAdIs Overview |

Defining & Implementing the new BAdI

Create BAdI Definition

SE18 (BAdI Definition) Screen has additional option (Enhancement Spot)

Page 72: SAP Enhancements, Exits and BAdIs Overview |

BAdI definition

Enter name for the Interface and click on

‘Change’

Create Method & it’s parameters

Page 73: SAP Enhancements, Exits and BAdIs Overview |

BAdI definitionClick on this to create

an Enhancement Implementation

Specify a ‘Fallback Class’ to be executed if no active Implementation is found

Page 74: SAP Enhancements, Exits and BAdIs Overview |

BAdI Implementation

Expand the Node for ‘Implementing Class’

Specify the ‘Implementing Class’ and click on Change

Report program to call BADI:DATA: handle type ref to <BAdI_Name><other data declarations…>GET BADI handleCALL BADI handle <method_name> EXPORTING … IMPORTING …

Page 75: SAP Enhancements, Exits and BAdIs Overview |

Filter-dependent BAdIWhat is a Filter-Dependent BAdI?What is a Filter-Dependent BAdI? • GET BADI <handle> FILTER <filter_name> = <filter_value>.

Implementations meeting the filter conditions are chosen• Example: GET_VAT (Country-Code Specific). Create 2

implementations for GB & US. It does not make sense to call both of them, hence the Definition is marked as Single-Use (only single active implementation can exist).

• We define a filter (remember this is the role of BAdI provider) say ‘COUNTRY’

• Add a filter value corresponding to the BADI Implementation, i.e. Implementation for GB has Filter Value = ‘GB’ & that for US has Filter value = ‘US’

Page 76: SAP Enhancements, Exits and BAdIs Overview |

Filter-dependent BAdI

Create a new Implementation for the same BADI definition we

created earlier.

Page 77: SAP Enhancements, Exits and BAdIs Overview |

Filter-dependent BAdI Implementation

Page 78: SAP Enhancements, Exits and BAdIs Overview |

Filter-dependent BAdI Implementation

Page 79: SAP Enhancements, Exits and BAdIs Overview |

Filter-dependent BAdI Implementation

Page 80: SAP Enhancements, Exits and BAdIs Overview |

Filter-dependent BAdI Implementation

Page 81: SAP Enhancements, Exits and BAdIs Overview |

Multiple-use BAdI

What are Multiple-use BAdI?• Multiple-use BAdIs can have more than one implementations• Option is provided by the Enhancement Option-provider (in the

BAdI definition)Example: BAdI that converts data for different output devices.

Hence, call of a method of a multiple-use BAdI is akin to sending a message. It does not matter how many services react to the message. It is similar to Publish & Subscribe mechanism.

Page 82: SAP Enhancements, Exits and BAdIs Overview |

Context Objects (new concept in Enhancement Framework)

How are they defined & used?DATA <context> TYPE REF TO <cl_myctx>GET BADI <handle> CONTEXT <context> Whenever ‘GET BADI’ is called with the same context & a filter

value which leads to the same implementation class, the already created instance is used.

Advantages of using Contexts:• Performance Improvement• Holds data over different method calls or even BAdI calls

What do you mean by Contexts?• Context Class is a class

implementing ‘if_badi_context’ (only a marker interface) & Context reference is reference to an instance of Context Class

• used to control the instantiation of BAdIs

Page 83: SAP Enhancements, Exits and BAdIs Overview |

Switch Implementations (new Switch Framework)

• Active implementations are evaluated at compile time and included in the load of BAdI handle

• only implementations that are switched on by the Switch Framework in at least one client are considered

Page 84: SAP Enhancements, Exits and BAdIs Overview |

Enhancement FrameworkEnhancement Framework

Page 85: SAP Enhancements, Exits and BAdIs Overview |

• 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

Editor Modes for Enhancements

Page 86: SAP Enhancements, Exits and BAdIs Overview |

Source Code plug-inSource Code plug-in

Transaction Code: SE18

Enter name of the enhancement spot and click

on display button

Page 87: SAP Enhancements, Exits and BAdIs Overview |

Source Code plug-inSource Code plug-in

On double clicking on any of the enhancement-point, system will display the code behind each of them

Page 88: SAP Enhancements, Exits and BAdIs Overview |

Source Code plug-inSource Code plug-in

To insert new implementation for enhancement point, click on the spiral button.

Page 89: SAP Enhancements, Exits and BAdIs Overview |

Source Code plug-inSource Code plug-in

In order to create an implementation for an enhancement point, right click on enhancement point and then select create option from

context menu.

Page 90: SAP Enhancements, Exits and BAdIs Overview |

Source Code plug-inSource Code plug-in

Click on create button to create enhancement

implementation

Page 91: SAP Enhancements, Exits and BAdIs Overview |

Source Code plug-inSource Code plug-in

Enter the name of the enhancement implementation

and short text, and then choose this option

Page 92: SAP Enhancements, Exits and BAdIs Overview |

Source Code plug-inSource Code plug-in

Select the newly created enhancement implementation

and then select this option

Page 93: SAP Enhancements, Exits and BAdIs Overview |

Source Code plug-inSource Code plug-in

You can include your source code here.

Page 94: SAP Enhancements, Exits and BAdIs Overview |

Function Module EnhancementFunction Module Enhancement

Specify Implementation name

and its short text

Inorder to enhance the functional module with new

parameter, choose this option

• You can enhance the parameter interface of a function module with new, optional formal parameters.• You cannot include an exceptions.

Page 95: SAP Enhancements, Exits and BAdIs Overview |

Function Module EnhancementFunction Module Enhancement

Before Activation

After Activation

Page 96: SAP Enhancements, Exits and BAdIs Overview |

Class/Interface EnhancementClass/Interface Enhancement

Page 97: SAP Enhancements, Exits and BAdIs Overview |

Class/Interface EnhancementClass/Interface Enhancement

• Importing, Exporting and Changing Parameter– For every existing method importing, exporting and changing parameters

can be additionally created inside a class enhancement.– It is not possible to add a returning parameter or an exception to an

existing method.• Optional

– Additional parameters are always optional.– Hint: The flag “optional“ is not checked for exporting parameters, because

they are always optional, even if they are not in an enhancement.

Page 98: SAP Enhancements, Exits and BAdIs Overview |

Class/Interface EnhancementClass/Interface Enhancement

• Add new methods– Constructor and Class-Constructor can not be created as class

enhancements.

Page 99: SAP Enhancements, Exits and BAdIs Overview |

Class/Interface Enhancement:Class/Interface Enhancement: Pre/Post Exits• Pre Exit

– A pre-method is called directly after the call of the existing method before the first statement.

• Post Exit– A post-method is called after the last statement of the existing

method before ENDMETHOD (only if the method is exited using ENDMETHOD).

• Access to attributes– The pre and the post method do only have access to the public

attributes/methods of the class.• Pre/Post Exits versus source code plugins

– Higher abstraction level due to a separate address space.– Less adjustment effort than source code enhancements during

upgrade. (only when parameters are changed).– All Exits are stored in a local enhancement class. The class can

have attributes to exchange data between the methods.

Page 100: SAP Enhancements, Exits and BAdIs Overview |

Enhancements, Exits and BADI'sEnhancements, Exits and BADI's

1 Introduction

2 Syntax Description

3 Demonstration

4 Exercises

5 HelpMe

Page 101: SAP Enhancements, Exits and BAdIs Overview |

ExercisesExercises

Table enhancement - Append structure (2 Char fields ) for Table enhancement - Append structure (2 Char fields ) for Table Table SFLIGHT****

To trigger all the customer exit (Function , Menu and To trigger all the customer exit (Function , Menu and Screen Exit) for Program SAPBC425_FLIGHT**Screen Exit) for Program SAPBC425_FLIGHT**

Create a project using following ComponentsCreate a project using following Components

SBC**E01(Function Exit)SBC**E01(Function Exit)

•SBC**E02(Menu Exit)SBC**E02(Menu Exit)

•SBC**E03 (Screen Exit)SBC**E03 (Screen Exit)

(** => ranges from 00 to 18)(** => ranges from 00 to 18)

Page 102: SAP Enhancements, Exits and BAdIs Overview |

Name of the FunctionalityName of the Functionality

1 Introduction

2 Syntax Description

3 Demonstration

4 Exercises

5 HelpMe

Page 103: SAP Enhancements, Exits and BAdIs Overview |

HelpMeHelpMe

• Tips and TricksTips and Tricks• Additional InfoAdditional Info

Page 104: SAP Enhancements, Exits and BAdIs Overview |

HelpMeHelpMe

Tips and TricksTips and TricksSAP application programmers use the ABAP statement CALL CUSTOMER-FUNCTION SAP application programmers use the ABAP statement CALL CUSTOMER-FUNCTION 'nnn' to call function modules (where 'nnn' is a three-digit number). They must also create the 'nnn' to call function modules (where 'nnn' is a three-digit number). They must also create the function module they want z CALL CUSTOMER-FUNCTION )function module they want z CALL CUSTOMER-FUNCTION )

These function modules are always belong to function groups whose names begin with X (X These function modules are always belong to function groups whose names begin with X (X function groups).function groups).

The following naming convention applies to these function modules:The following naming convention applies to these function modules:prefix: EXITprefix: EXITname of the program that calls the function modulename of the program that calls the function modulesuffix: three-digit numbersuffix: three-digit number

The three parts of the name are separated by two underscores.The three parts of the name are separated by two underscores.

The CALL CUSTOMER-FUNCTION statement is not executed until the corresponding The CALL CUSTOMER-FUNCTION statement is not executed until the corresponding enhancement project is activated. Multiple calls of the same function module are all activated enhancement project is activated. Multiple calls of the same function module are all activated at the same time.at the same time.

Page 105: SAP Enhancements, Exits and BAdIs Overview |

HelpMeHelpMeAdditional InfoAdditional Info

• SAP application programmers can declare global data in include program LxaaaTAP.SAP application programmers can declare global data in include program LxaaaTAP.

• You declare your own global data in include program ZXaaaTOP.You declare your own global data in include program ZXaaaTOP.

• Include program LXaaaTOP also contains the FUNCTION-POOL statement, which may not be changed. Therefore, you Include program LXaaaTOP also contains the FUNCTION-POOL statement, which may not be changed. Therefore, you must always include the message class in parentheses when outputting messages.must always include the message class in parentheses when outputting messages.

• SAP application programmers can supply customers with default subroutines in include LXaaaF00.

• Subroutines, modules, and interactive events (AT…) are created as include programs and included enhancements using include program ZXaaaZZZ.

• Additional includes must adhere to the following naming convention:

• ZXaaaFnn for subroutines,ZXaaaOnn for PBO modules,ZXaaaInn for PAI modules,ZXaaaEnn for events.

Page 106: SAP Enhancements, Exits and BAdIs Overview |

Searching BADI: Method 1Searching BADI: Method 1

Search for BAdI corresponding to the transaction:Method 1: Search for the CL_EXITHANDLER=>GET_INSTANCE in the

main program

Page 107: SAP Enhancements, Exits and BAdIs Overview |

Searching BADI: Method 2Searching BADI: Method 2

Put a breakpoint at the following code and execute the transaction (e.g.

MM01)We want to implement a BAdI on

Saving Material Data.