Вы находитесь на странице: 1из 107

AB1012 - Enhancements, Exits and BADI's

India SAP CoE, Slide 1

Enhancements, Exits and BADI's


1 2

Introduction Syntax Description


3

Demonstration
Exercises HelpMe

5
India SAP CoE, Slide 2

Enhancements, Exits and BADI's


1 2

Introduction Syntax Description


3

Demonstration
Exercises HelpMe

5
India SAP CoE, Slide 3

Introduction
EXIT s are nothing but the R/3 Enhancements which allows you to add your own functionality to SAPs standard business applications without having to modify the original applications. Purpose Use Challenges

India SAP CoE, Slide 4

Introduction
Purpose

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

India SAP CoE, Slide 5

Introduction
Use
They do not affect standard SAP source code. When you add new functionality to your SAP System using SAPs exits, you 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 objects are linked to standard applications, but exist separately from SAPs standard software package. They do not affect software updates. When you add new functionality to your SAP System using SAPs exits, your objects (called customer objects) must adhere to strict naming conventions. 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 to the standard software package.
India SAP CoE, Slide 6

Introduction

Challenges

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

India SAP CoE, Slide 7

India SAP CoE, Slide 8

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.

India SAP CoE, Slide 9

2 3 4

India SAP CoE, Slide 10

Enhancements, Exits and BADI's


1 2

PrepareMe Syntax description


3

Demonstration
Exercises HelpMe

5
India SAP CoE, Slide 11

ABAP DICTIONARY Table Enhancements: There are two ways that you can add additional fields to tables without modifying your system. o Append Structures: 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. Append structures are created for use with a specific table. However, a table can have multiple append structures assigned to it. Customizing Includes: 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. 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.
India SAP CoE, Slide 12

ABAP DICTIONARY 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

India SAP CoE, Slide 13

ABAP DICTIONARY 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).

India SAP CoE, Slide 14

SAP Application Enhancement

India SAP CoE, Slide 15

Customer Enhancement Projects

India SAP CoE, Slide 16

Customer Exits
Function Module Exits Menu Exits Screen Exits

India SAP CoE, Slide 17

Implementation of Enhancement in Customer System

India SAP CoE, Slide 18

Creating Customer Enhancement Projects

India SAP CoE, Slide 19

Assigning SAP Enhancement to customer projects

India SAP CoE, Slide 20

Editing Components

Activating Enhancement Projects

India SAP CoE, Slide 21

Business Transaction Events


It is also called as Open FI enhancement technique which is based on the following principle: Application developers must define their interface in a function module. An assignment table is read in the corresponding (generated) code, and the customer modules assigned are called dynamically. This technique differentiates between enhancements that are only allowed to have one implementation and enhancements that can call multiple implementations in any sequence desired. Both industryspecific and country-specific enhancements may be defined.

India SAP CoE, Slide 22

Enhancement Framework
The new enhancement concept of the ABAP Workbench enables the integration of different concepts for modifying and enhancing development objects. The enhancement concept is supported by the Enhancement Builder tool and ABAP language elements. The objective of the Enhancement Framework is to provide a technology to create modification-free enhancements and to unify all possible ways of modifying or enhancing Repository objects.
India SAP CoE, Slide 23

Multilayer Support

India SAP CoE, Slide 24

Enhancement Spots
Enhancement Spots can only be of type source code Enhancement or BAdI. Enhancement Spots manage explicit Enhancement 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.

India SAP CoE, Slide 25

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.

India SAP CoE, Slide 26

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

India SAP CoE, Slide 27

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

India SAP CoE, Slide 28

Composite Enhancement Implementation

The first tab displays which (Simple) Enhancement Implementations are contained. The second tab displays which other Composite Enhancement Implementations are contained.
India SAP CoE, Slide 29

Enhancement Relations

India SAP CoE, Slide 30

Source 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.

India SAP CoE, Slide 31

Features of explicit & Implicit enhancement 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

India SAP CoE, Slide 32

Difference: 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.

India SAP CoE, Slide 33

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.


India SAP CoE, Slide 34

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.
India SAP CoE, Slide 35

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 cant 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.

India SAP CoE, Slide 36

Functional Module Enhancement


Function Module Enhancements allow
Adding new optional parameters to existing function modules Enhance the source code

India SAP CoE, Slide 37

Class/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

India SAP CoE, Slide 38

Enhancements, Exits and BADI's


1 2

PrepareMe Syntax Description


3

Demonstration
Exercises HelpMe

5
India SAP CoE, Slide 39

User Exits

India SAP CoE, Slide 40

Demonstration

Function Module Exits

India SAP CoE, Slide 41

Demonstration Menu Exits

India SAP CoE, Slide 42

Demonstration Screen Exits

India SAP CoE, Slide 43

Demonstration

Field Exits It is triggered at field level. It is attached at data element Specific to one screen only or to all the screen where field appears. Field exit is not allowed in SAP version 4.7 and above . Example with screen shots for consultants working in SAP V 4.6 below version.

India SAP CoE, Slide 44

India SAP CoE, Slide 45

India SAP CoE, Slide 46

India SAP CoE, Slide 47

India SAP CoE, Slide 48

Business Add-Ins (BAdI)

India SAP CoE, Slide 49

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
India SAP CoE, Slide 50

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

SE18: BAdI Definition

BAdI Class (Proxy Class)


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

Function Code Enhancements

Screen Enhancements

India SAP CoE, Slide 51

Classic BAdIs
Double Click on the Interface Name to define methods, parameters, exceptions for that interface

Class Builder Screen will open up.

India SAP CoE, Slide 52

Classic BAdIs

Click on Parameters to add Importing / Exporting Parameters

Add a Method & specify it as Instance Method

Click on Exceptions to define exceptions that will be handled


India SAP CoE, Slide 53

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


India SAP CoE, Slide 54

Classic BAdIs

Save and activate the BAdI definition!


India SAP CoE, Slide 55

BADI Implementation
BAdI Implementation (SE19)
SE19: BAdI Implementation

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

India SAP CoE, Slide 56

BADI Implementation

Save and activate the BAdI implementation!


India SAP CoE, Slide 57

Using the BAdI(Calling the BAdI)


Execute the Report Program.

India SAP CoE, Slide 58

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 transaction 2. Create a custom Implementation for the BAdI by adding code in the appropriate method 3. Test that the method with custom code is invoked on executing the transaction.

India SAP CoE, Slide 59

BAdI Implementation

Select the required views.

Create Material using MM01. Copy from existing Material.

India SAP CoE, Slide 60

BAdI Implementation
Enter mandatory data and click on Save.

Check the Exit Name BADI_MATERIAL_CHECK. This is the BAdI we are going to implement.

India SAP CoE, Slide 61

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.

India SAP CoE, Slide 62

Implementing BADI
Go to SE19. Specify a name for the BAdI Implementation. Enter the Definition Name.

Double-click the method CHECK_DATA to enter the source code

India SAP CoE, Slide 63

Implementing BADI

Enter code inside the MethodEnd 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.
India SAP CoE, Slide 64

BAdI Implementation

Activate the Implementation

India SAP CoE, Slide 65

Testing the BAdI


Testing the BAdI implementation (BADI_MATERIAL_CHECK)
MM01 / MM02 and create / change material and save. On clicking Save, our BADI will trigger.

Message is displayed (Division not entered)

India SAP CoE, Slide 66

BAdIsin the new Enhancement Framework (ECC 6.0)


How the new BAdIs differ from the Classic BAdI? Good news is thatbasic 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

India SAP CoE, Slide 67

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)
India SAP CoE, Slide 68

Enhancement Spot as a container for BAdI

Enhancement Framework has containers for BAdI implementations as well

India SAP CoE, Slide 69

New BAdIs

Create a new Enhancement Spot

India SAP CoE, Slide 70

Defining & Implementing the new BAdI


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

Create BAdI Definition

India SAP CoE, Slide 71

BAdI definition
Enter name for the Interface and click on Change

Create Method & its parameters


India SAP CoE, Slide 72

BAdI definition
Click on this to create an Enhancement Implementation

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


India SAP CoE, Slide 73

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 handle CALL BADI handle <method_name> EXPORTING IMPORTING
India SAP CoE, Slide 74

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

India SAP CoE, Slide 75

Filter-dependent BAdI
Create a new Implementation for the same BADI definition we created earlier.

India SAP CoE, Slide 76

Filter-dependent BAdI Implementation

India SAP CoE, Slide 77

Filter-dependent BAdI Implementation

India SAP CoE, Slide 78

Filter-dependent BAdI Implementation

India SAP CoE, Slide 79

Filter-dependent BAdI Implementation

India SAP CoE, Slide 80

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.

India SAP CoE, Slide 81

Context Objects (new concept in Enhancement Framework)


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 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
India SAP CoE, Slide 82

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

India SAP CoE, Slide 83

Enhancement Framework

India SAP CoE, Slide 84

Editor Modes for Enhancements


Use Change Mode for creating enhancement points & sections.
use button Display <-> Change change mode. to switch to

Use Enhancement Mode for creating enhancement implementations.


use button Change Enhancements to switch to Enhancement mode use button Display <-> Change to leave Enhancement mode

India SAP CoE, Slide 85

Source Code plug-in


Transaction Code: SE18

Enter name of the enhancement spot and click on display button

India SAP CoE, Slide 86

Source Code plug-in

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

India SAP CoE, Slide 87

Source Code plug-in

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

India SAP CoE, Slide 88

Source 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.

India SAP CoE, Slide 89

Source Code plug-in

Click on create button to create enhancement implementation

India SAP CoE, Slide 90

Source Code plug-in

Enter the name of the enhancement implementation and short text, and then choose this option
India SAP CoE, Slide 91

Source Code plug-in

Select the newly created enhancement implementation and then select this option

India SAP CoE, Slide 92

Source Code plug-in

You can include your source code here.

India SAP CoE, Slide 93

Function Module Enhancement


Inorder to enhance the functional module with new parameter, choose this option

Specify Implementation name and its short text

You can enhance the parameter interface of a function module with new, optional formal parameters. You cannot include an exceptions.
India SAP CoE, Slide 94

Function Module Enhancement


Before Activation

After Activation

India SAP CoE, Slide 95

Class/Interface Enhancement

India SAP CoE, Slide 96

Class/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.
India SAP CoE, Slide 97

Class/Interface Enhancement

Add new methods


Constructor and Class-Constructor can not be created as class enhancements.
India SAP CoE, Slide 98

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.

India SAP CoE, Slide 99

Enhancements, Exits and BADI's


1 2

Introduction Syntax Description


3

Demonstration
Exercises HelpMe

5
India SAP CoE, Slide 100

Exercises

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


To trigger all the customer exit (Function , Menu and Screen Exit) for Program SAPBC425_FLIGHT** Create a project using following Components SBC**E01(Function Exit) SBC**E02(Menu Exit) SBC**E03 (Screen Exit) (** => ranges from 00 to 18)
India SAP CoE, Slide 101

Name of the Functionality 1 2

Introduction Syntax Description


3

Demonstration
Exercises HelpMe

5
India SAP CoE, Slide 102

HelpMe

Tips and Tricks Additional Info

India SAP CoE, Slide 103

HelpMe Tips and Tricks


SAP application programmers use the ABAP statement CALL CUSTOMERFUNCTION 'nnn' to call function modules (where 'nnn' is a three-digit number). They must also create the function module they want z CALL CUSTOMERFUNCTION ) These function modules are always belong to function groups whose names begin with X (X function groups). The following naming convention applies to these function modules: prefix: EXIT name of the program that calls the function module suffix: three-digit number The three parts of the name are separated by two underscores. 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 at the same time.

India SAP CoE, Slide 104

HelpMe Additional Info


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

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 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 ZXaaaOnn ZXaaaInn ZXaaaEnn

for subroutines, for PBO modules, for PAI modules, for events.

India SAP CoE, Slide 105

Searching BADI: Method 1


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

India SAP CoE, Slide 106

Searching 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.

India SAP CoE, Slide 107

Вам также может понравиться