14 Business Add-Ins (BAdIs)

Post on 21-Apr-2015

34 views 4 download

Transcript of 14 Business Add-Ins (BAdIs)

deeper

Business Consulting Services

© Copyright IBM Corporation 2003

Business Add-In’s

November, 2003

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 2

Business Consulting Services

© Copyright IBM Corporation 2003

Lesson Objectives

After completing this lesson you will be able to :

Understand what Business Add In’s (BAdIs) are

Define BAdIs

Implement BAdIs

Use BAdIs

Create an implementation for an existing SAP BAdI

Create Multiple Use BAdIs

Create Filter Dependent BAdI

Create Menu Enhancement with BAdI

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 3

Business Consulting Services

© Copyright IBM Corporation 2003

Introduction

Traditional way of doing code modifications – Exits

3 Tier Architecture

– PRESENTATION :

Field Exits

Screen Exits

Menu Exits

– APPLICATION:

Programs -> Program exits -> call customer function -> Include

– DATABASE

Table -> SE11 -> Goto -> Append Structure

With BAdIs you can make changes only at the Application Layer.

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 4

Business Consulting Services

© Copyright IBM Corporation 2003

BAdIs

Business Add-Ins are a new SAP enhancement technique based on ABAP Objects

They can be inserted into the SAP system based on specific user requirements

Business Add-Ins should be considered generalized Business Transaction Events that can be used to bundle program, menu and screen enhancements into a single add-in.

Each Business Add-In has :

– at least one Business Add-In definition

– a Business Add-In interface

– a Business Add-In class that implements the interface

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 5

Business Consulting Services

© Copyright IBM Corporation 2003

BAdI Enhancement options

In Business Add-Ins, all the components of an enhancement option are grouped together

– Program Enhancements: Functional enhancement of the program are defined in the form of interface methods and can be used with or without Menu Enhancements or Screen Enhancements

– Menu Enhancements: Function codes can be entered for a BAdI for the corresponding menu entries in the user interface definition.

– Screen Enhancements: Subscreen areas can be entered for a Business Add-In. Screen enhancements can be implemented for these in the form of subscreen screens.

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 6

Business Consulting Services

© Copyright IBM Corporation 2003

BAdIs – SAP Delivered vs. Custom Developed

SAP has already created BAdI definitions (created with SE18) and placed references to these throughout the application code.

SAP developers create implementations (created with SE19) of these existing BAdI’s, entering custom code into the implemented methods

It is also possible for developers to create new BAdI definitions, and reference them in their own custom code. You would do this if you wanted to give future users of your application the ability to expand on functionality in a custom development. You would NOT define a new BAdI to place in SAP code!

Overview of steps to complete a BAdI.

– 1. Create BAdI definition with SE18

– 2. Code a reference to the BAdI in application code where functionality is to be expanded

– 3. Create an implementation of the BAdI that actually does something.

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 7

Business Consulting Services

© Copyright IBM Corporation 2003

Defining BAdIs

Enter BADI name

Click on CREATE

SE18

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 8

Business Consulting Services

© Copyright IBM Corporation 2003

Defining BAdIs – Attributes

Enter short text

BADI class is automatically created

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 9

Business Consulting Services

© Copyright IBM Corporation 2003

BADI Definition - Save

Enter Package name

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 10

Business Consulting Services

© Copyright IBM Corporation 2003

Defining BAdIs

Package name populated

BAdI class created

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 11

Business Consulting Services

© Copyright IBM Corporation 2003

Defining BAdIs - Interface

BADI Interface is created automatically

To edit double clickon the interface

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 12

Business Consulting Services

© Copyright IBM Corporation 2003

Defining BAdIs – Interface methods

Method name

Method type

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 13

Business Consulting Services

© Copyright IBM Corporation 2003

Defining BAdIs – Interface methods - parameters

Import and Export parameters

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 14

Business Consulting Services

© Copyright IBM Corporation 2003

Defining BAdIs – Exceptions

Exceptions

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 15

Business Consulting Services

© Copyright IBM Corporation 2003

BADI Implementation

SE19

Enter Implementation name

Click on create

Enter the BAdI Definition name

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 16

Business Consulting Services

© Copyright IBM Corporation 2003

BAdI Implementation

Double click onthe method to modify method code

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 17

Business Consulting Services

© Copyright IBM Corporation 2003

Implementing BAdIs: Method implementation

Modify the method code within the

METHOD/ENDMETHOD statements and activate

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 18

Business Consulting Services

© Copyright IBM Corporation 2003

Using a BAdI

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 19

Business Consulting Services

© Copyright IBM Corporation 2003

Create an Implementation for an SAP provided BAdI

Find the corresponding BAdI for the SAP transaction

Create a custom Implementation for the BAdI

From the methods available in the BAdI and select the appropriate method

Enter custom code in the method and activate

Execute SAP transaction and test if method with custom code is being invoked

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 20

Business Consulting Services

© Copyright IBM Corporation 2003

Finding a BAdI – Transaction VD02

Select System->Statusfrom the drop down menu

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 21

Business Consulting Services

© Copyright IBM Corporation 2003

Finding a BAdI – Transaction VD02

Double click on the program name

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 22

Business Consulting Services

© Copyright IBM Corporation 2003

Finding a BAdI – Source program

Do a search onCL_EXITHANDLER=>GET_INSTANCE

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 23

Business Consulting Services

© Copyright IBM Corporation 2003

Finding a BAdI – Search results

Three BAdIs usedin this program. Double click required BAdI to see the source code

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 24

Business Consulting Services

© Copyright IBM Corporation 2003

Finding a BAdI – Call to a BAdI in the source code

BAdI being used

Interface referenceVariable for the BAdI

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 25

Business Consulting Services

© Copyright IBM Corporation 2003

Finding a BAdI – Interface reference to the BAdI

Interface reference Variable defined

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 26

Business Consulting Services

© Copyright IBM Corporation 2003

Using an SAP BAdI – Create a Custom Implementation

Enter the name of the BAdI

SE19

Enter theimplementation

name

Click on CREATE

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 27

Business Consulting Services

© Copyright IBM Corporation 2003

BAdI Implementation – Attributes

Enter description

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 28

Business Consulting Services

© Copyright IBM Corporation 2003

BAdI Implementation – Interface methods

Click on the interfacetab to view the available methods

Double click on method SAVE_DATA to modify it

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 29

Business Consulting Services

© Copyright IBM Corporation 2003

BAdI Implementation – Class builder

Enter custom code

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 30

Business Consulting Services

© Copyright IBM Corporation 2003

BAdIs – Execute the Change customer transaction

Change name of Customer

Click on SAVE button

VD02

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 31

Business Consulting Services

© Copyright IBM Corporation 2003

BAdI Implementation – Invoked by VD02

Custom code for method invoked via BAdI

CUSTOMER_ADD_DATA

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 32

Business Consulting Services

© Copyright IBM Corporation 2003

Multiple Use BAdIs

Single Use Business Add-Ins

– Do NOT select the Multiple use checkbox from the Administration tab when defining a Single Use BAdI

– BAdI has a single Implementation

– Similar to procedures

– Return values can be expected

– Can use importing, changing and returning parameters

– N/A

– A single implementation will be triggered by the application program

Multiple Use Business Add-Ins

– Select the Multiple use checkbox from the Administration tab when creating the BAdI definition

– BAdI has multiple implementations

– Similar to event calls

– Cannot expect return values

– Can use importing and changing parameters

– For multiple implementations there is no sequence control because at the time of BAdI definition it does not know which implementation will be active

– All active implementations will be triggered by the application program using the BAdI

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 33

Business Consulting Services

© Copyright IBM Corporation 2003

Multi Use BAdIs – CUSTOMER_ADD_DATA Definition

Multiple use Button checked

SAP defined BAdI –CUSTOMER_ADD_DATA

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 34

Business Consulting Services

© Copyright IBM Corporation 2003

Multi Use BAdIs – Custom Implementation for BAdI – CUSTOMER_ADD_DATA

Create a second implementationfor BAdI CUSTOMER_ADD_DATA

Specify BAdI name

Click on CREATE

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 35

Business Consulting Services

© Copyright IBM Corporation 2003

Multi Use BAdIs – Interface method SAVE_DATA

Double click on method SAVE_DATA

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 36

Business Consulting Services

© Copyright IBM Corporation 2003

Multi Use BAdIs – Modify method SAVE_DATA

Enter custom code for method SAVE_DATA

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 37

Business Consulting Services

© Copyright IBM Corporation 2003

Multi Use BAdIs – View implementations for BAdI

SE18

Displays list ofImplementations

Select to display list of Implementations for BAdICUSTOMER_ADD_DATA

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 38

Business Consulting Services

© Copyright IBM Corporation 2003

Filter Dependent BAdIs

Business Add-Ins can be implemented based on a specific filter value

If you want to call the implementation of a Business Add-In depending not only on one filter value but on various values, you can enter the name of a structure into the Filter type field. The structure can consist of several data elements that fulfill the above conditions for data elements

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 39

Business Consulting Services

© Copyright IBM Corporation 2003

Filter Dependent BAdIs – BAdI Definition

SE18

Click checkbox for Filter Dependent BAdIs

Enter Filter type

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 40

Business Consulting Services

© Copyright IBM Corporation 2003

Filter Dependent BAdIs – BAdI Definition

Double click onthe Interface to add parametersand methods

Enter text

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 41

Business Consulting Services

© Copyright IBM Corporation 2003

Filter Dependent BAdIs – Interface - Method Definition

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 42

Business Consulting Services

© Copyright IBM Corporation 2003

Filter Dependent BAdIs – Interface – Parameter Definition

FLT_VAL parameterpreset for method

Create parameter toexport tax rate

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 43

Business Consulting Services

© Copyright IBM Corporation 2003

Filter Dependent BAdIs – Implementation

Create BAdI Implementation

Enter name of BAdI

Select CREATE button

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 44

Business Consulting Services

© Copyright IBM Corporation 2003

Filter Dependent BAdIs – BAdI Implementation

SE19

Select a value fromthe search help orenter a valid value

Click on button tocreate an entry for filter value

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 45

Business Consulting Services

© Copyright IBM Corporation 2003

Filter Dependent BAdIs – BAdI Implementation

Double click onthe Method to enter source code

Select the Interface tab

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 46

Business Consulting Services

© Copyright IBM Corporation 2003

Filter Dependent BAdIs – Method code

Enter code for the Method to calculate the tax rate based onthe company code inParameter FLT_VAL

Save and activate

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 47

Business Consulting Services

© Copyright IBM Corporation 2003

Filter Dependent BAdIs – Source code to Invoke BAdI

Call BADI from within the program

Selection screen parameter for Company code

Call method get_bukrs passingthe company codeThe Tax rate isreturned

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 48

Business Consulting Services

© Copyright IBM Corporation 2003

Menu Enhancement BAdIs – Creating a menu enhancement

Fcodes tab is only available whenmultiple use box isnot checked

SE18 – Create BADI definition

Menu enhancements are for Single Use BAdI’s only

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 49

Business Consulting Services

© Copyright IBM Corporation 2003

Menu Enhancement BAdIs – Definition via SE18 – FCode Tab

Enter related program and function code information. Double clicking on the new line will take you to dialog for defining an icon and function texts

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 50

Business Consulting Services

© Copyright IBM Corporation 2003

Menu Enhancement BAdIs – Function Code Attributes

Function texts screen shows all codes for associated program

Function attributes popup allows definition of code type and static texts

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 51

Business Consulting Services

© Copyright IBM Corporation 2003

Menu Enhancement BAdIs – Define the Interface (SE18)

Add method to interface that will be implemented by the menu exit

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 52

Business Consulting Services

© Copyright IBM Corporation 2003

Menu Enhancement BAdIs – Implement BAdI in SE19

Double click on method to add in custom code for the implementation

Don’t forget to activate during all steps in this process!

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 53

Business Consulting Services

© Copyright IBM Corporation 2003

Menu Enhancement BAdIs – Enter Fcode in GUI status

Don’t forget to activate during all steps in this process!

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 54

Business Consulting Services

© Copyright IBM Corporation 2003

Menu Enhancement BAdIs – Call the BADI in Application

Don’t forget to create a reference to the BADI instance in GLOBAL memory of the application as follows:

DATA o_exit TYPE REF TO zif_ex__menu_exit_badi_1. "BADI interface

ABAP | Confidential | 15_BAdl v1 .ppt | 04/11/23 55

Business Consulting Services

© Copyright IBM Corporation 2003

Menu Enhancement BAdIs – Call the BADI in Application!