Está en la página 1de 107

AB1012 - Enhancements, Exits

and BADI's
Enhancements, Exits and BADI's
1 Introduction

2 Syntax Description

3 Demonstration

4 Exercises

5 HelpMe
Enhancements, Exits and BADI's
1 Introduction

2 Syntax Description

3 Demonstration

4 Exercises

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

• Purpose
• Use
• Challenges
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.
Introduction
Use
• They do not affect standard SAP source code.
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 and screens you create are
encapsulated as separate objects. These customer objects are
linked to standard applications, but exist separately from
SAP’s standard software package.

• They do not affect software updates.


When you add new functionality to your SAP System using
SAP’s 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.
Introduction

Challenges

• Customer exits are not available for all programs and


screens found in the SAP System.
• 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.
2

3
1

4
Enhancements, Exits and BADI's
1 PrepareMe

2 Syntax description

3 Demonstration

4 Exercises

5 HelpMe
ABAP DICTIONARY

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

• 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:
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.
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
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).
SAP Application Enhancement
Customer Enhancement Projects
Customer Exits

• Function Module Exits


• Menu Exits
• Screen Exits
Implementation of Enhancement in Customer
System
Creating Customer Enhancement Projects
Assigning SAP Enhancement to customer projects
Editing Components

Activating Enhancement Projects


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 industry-
specific and country-specific enhancements may be defined.
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.
Multilayer Support
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.
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.
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
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
Composite Enhancement Implementation

• The first tab displays which (Simple) Enhancement


Implementations are contained.
• The second tab displays which other Composite Enhancement
Implementations are contained.
Enhancement Relations
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.
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
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.
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.
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.
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.
Functional Module Enhancement

• Function Module Enhancements allow


– Adding new optional parameters to
existing function modules
– Enhance the source code
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
Enhancements, Exits and BADI's
1 PrepareMe

2 Syntax Description

3 Demonstration

4 Exercises

5 HelpMe
User Exits
Demonstration
Function Module Exits
Demonstration
Menu Exits
Demonstration
Screen Exits
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.
Business Add-Ins (BAdI)
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
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 Screen


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

Class Builder Screen will


open up.
Classic BAdIs

Add a Method & specify it


Click on Parameters to add as Instance Method
Importing / Exporting
Parameters

Click on ‘Exceptions’ to define


exceptions that will be handled
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…


Classic BAdIs

Save and activate the BAdI definition!


BADI Implementation
BAdI Implementation (SE19)

SE19: BAdI
Implementation

Double Click on the Method to modify


the Method code (Class Builder)
BADI Implementation

Save and activate the BAdI implementation!


Using the BAdI…(Calling the BAdI)
Execute the Report Program.
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.
BAdI Implementation

Select the required views.

Create Material using MM01.


Copy from existing Material.
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.
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.
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
Implementing 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.
BAdI Implementation

Activate the Implementation


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)
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
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)
Enhancement Spot as a container
for BAdI…

• Enhancement Framework has containers for BAdI implementations as


well
New BAdIs

Create a new Enhancement


Spot
Defining & Implementing the new
BAdI

SE18 (BAdI Definition) Screen has


additional option (Enhancement Spot)

Create BAdI Definition


BAdI definition

Enter name for the


Interface and click on
‘Change’

Create Method & it’s


parameters
BAdI definition
Click on this to create
an Enhancement
Implementation

Specify a ‘Fallback Class’


to be executed if no active
Implementation is found
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 …
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’
Filter-dependent BAdI

Create a new Implementation for


the same BADI definition we
created earlier.
Filter-dependent BAdI Implementation
Filter-dependent BAdI Implementation
Filter-dependent BAdI Implementation
Filter-dependent BAdI Implementation
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.
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
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
Enhancement Framework
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
Source Code plug-in
Transaction Code: SE18

Enter name of the


enhancement spot and click on
display button
Source Code plug-in

On double clicking on any of the


enhancement-point, system will
display the code behind each of
them
Source Code plug-in

To insert new implementation


for enhancement point, click on
the spiral button.
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.
Source Code plug-in

Click on create button


to create enhancement
implementation
Source Code plug-in

Enter the name of the


enhancement implementation
and short text, and then choose
this option
Source Code plug-in

Select the newly created


enhancement implementation and
then select this option
Source Code plug-in

You can include your


source code here.
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.
Function Module Enhancement

Before Activation

After Activation
Class/Interface Enhancement
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.
Class/Interface Enhancement

• Add new methods


– Constructor and Class-Constructor can not be created as class
enhancements.
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.
Enhancements, Exits and BADI's
1 Introduction

2 Syntax Description

3 Demonstration

4 Exercises

5 HelpMe
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)
Name of the Functionality

1 Introduction

2 Syntax Description

3 Demonstration

4 Exercises

5 HelpMe
HelpMe

• Tips and Tricks


• Additional Info
HelpMe
Tips and Tricks
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 function module they want z CALL CUSTOMER-
FUNCTION )

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.
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 for subroutines,


ZXaaaOnn for PBO modules,
ZXaaaInn for PAI modules,
ZXaaaEnn for events.
Searching BADI: Method 1
Search for BAdI corresponding to the transaction:
Method 1: Search for the CL_EXITHANDLER=>GET_INSTANCE in the
main program
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.

También podría gustarte