Professional Documents
Culture Documents
Kannan Srinivasan
Net4site LLC
ABAP Objects
ABAP Objects as a strategic SAP technology
Programming with objects, classes, and interfaces in ABAP Interoperability with other object systems
Net4site LLC
Net4site LLC
Net4site LLC
Foundation for DCOM/CORBA connection Fully featured standard object model Medium level object wrappers for business functionality written in standard ABAP
Defined within the BOR Function-oriented, stable interfaces to R/3 applications Support for Internet applications
Net4site LLC
Procedural abstraction (function library) Data abstraction (type pools, complex data types) Logical databases for hierarchical data access Event-oriented programming with logical databases and interactive reporting Fully integrated SQL interface In-memory tables: fast key access, sorted and/or nested, group control, ... ...
R
Net4site LLC
Bottom up: use objects in existing ABAP programs (reports, module- and function-pools) Top down: call forms and functions from within objects All ABAP language constructs are available within objects Fully integrated into the ABAP Workbench
Net4site LLC
Make OO benefits available for the implementation of the worlds largest business application True two-way interoperability: ABAP <=> Java, ABAP <=> VB, ... Speed, speed, speed !
Enabling technology for GUI programming with frontend controls (ActiveX, JavaBeans)
R
Net4site LLC
ABAP Objects
ABAP Objects as a strategic SAP technology
Net4site LLC
Big common data structure and some common functions Lots of CASE statements, sparsely filled data structures
Various kinds of everything, objects for truck, load, Object: data and functions that belong together to model / implement a specific concept Fewer CASE statements, densely filled data, cohesion
R
Net4site LLC
...state, described by its attributes ...behavior, described by its methods ...identity to distinguish them from other objects with same state and behavior
...by accessing (public) attributes ...by calling methods ...by raising or handling events
Net4site LLC
...specify behavior of same kind of objects ...define how objects can be accessed from outside (public vs. protected vs. private) ...hide implementation details ...may be specialized in subclasses
CLASS class DEFINITION [ INHERITNG FROM superclass ]. [ PUBLIC SECTION. ...<definition of public components> ] [ PROTECTED SECTION. ...<definition of protected components> ] [ PRIVATE SECTION. ...<definition of private components> ] ENDCLASS. CLASS class IMPLEMENTATION. [...<method implementations> ] ENDCLASS.
Net4site LLC
An Example
CLASS CTruck DEFINITION. PUBLIC SECTION. DATA: VehicleId TYPE I READ-ONLY. METHODS: LoadParcel IMPORTING Parcel TYPE REF TO CParcel, UnloadParcel PRIVATE SECTION. DATA: ParcelTab TYPE REF TO CParcel OCCURS 0. ENDCLASS. CLASS CTruck IMPLEMENTATION. METHOD LoadParcel. APPEND Parcel TO ParcelTab. -- do more stuff ENDMETHOD. ENDCLASS. PROGRAM xy. DATA: Parcel TYPE REF TO CParcel, Truck1 TYPE REF TO CTruck, Truck2 TYPE REF TO CTruck. -- get input data for parcel from somewhere CREATE OBJECT Parcel. CALL METHOD Parcel->SetPars EXPORTING Weight = In_weight. --- deal with multiple instances CALL METHOD Truck1->UnloadParcel IMPORTING Parcel = Parcel. CALL METHOD Truck2->LoadParcel( Parcel ).
Net4site LLC
R
Distinguish instances by object reference Only and explicit means of dependency Sharing always and only via (object) references (similar to field-symbols; all other ABAP types are value-based!)
Net4site LLC
Component Definitions
Attributes
...store the internal state of an object (data) ...can be references to other objects can be: read-only, virtual, class attributes can be constants Virtual attributes: Attribute from the outside, inside the object Set- and Get-methods. Dynamic control of Set-/Get-methods.
{DATA|CLASS-DATA} attr TYPE type [ VALUE val ] [ READ-ONLY ] [ VIRTUAL [ SET-METHOD set-method] [GET-METHOD get-method] ]. CONSTANTS const TYPE type VALUE val.
R
Net4site LLC
Component Definitions
Methods
are operations on objects (the functionality) are the only way to change the state of an object (other than public attributes) ...have parameters and can raise exceptions (similar to function modules) ...can pass back a return value No method-name overloading!
{METHODS|CLASS-METHODS} method [ IMPORTING ...<list of import parameters> ] [ EXPORTING ...<list of export parameters> ] [ CHANGING ...<list of import/export parameters> ] [ EXCEPTIONS ...<list of exceptions> ] [ RETURNING result TYPE t ].
Net4site LLC
Net4site LLC
Component Definitions
Events...
...occur at a particular point in time, e.g. change in state of an object ...can be raised to inform other interested objects ...can pass parameters
Net4site LLC
Event Handling
Events are handled by classes
Event handlers...
...are methods for handling events from other objects ...are declared with reference to the event to be handled (signature from there) must be registered explicitly
Net4site LLC
Handler
CLASS CWindow1 DEFINITION. PUBLIC SECTION. "--- handle events by implementing "--- event handler methods METHODS: OKClicked FOR EVENT Clicked OF CButton IMPORTING DoubleClick, CanClicked FOR EVENT Clicked OF CButton. DATA: OKBtn TYPE REF TO CButton. ENDCLASS. CLASS CWindow1 IMPLEMENTATION. METHOD Init. CREATE OBJECT: OKBtn, CanBtn. SET HANDLER: OKClicked FOR OKBtn, CanClicked FOR CanBtn. ENDMETHOD. METHOD OKClicked. IF DoubleClick = 1. ENDMETHOD.
CLASS CButton IMPLEMENTATION. METHOD AnyMethod. RAISE EVENT Clicked EXPORTING DoubleClick = 0. ENDMETHOD. ENDCLASS.
ENDIF.
...are data on class level, independent of object / instance ...are always there like global variables / functions ...have global lifetime, with scope tied to class
Class methods...
...can only access class attributes ...can be called like global functions, but are tied to class
*--- class attribute definition CLASS-DATA: var TYPE t . *--- class method definition CLASS-METHODS: cm <parameter syntax like methods>.
Net4site LLC
Net4site LLC
Inheritance
A class can be derived from another
Only specify what is different / added Add attributes and methods Redefine / override existing methods (in any section) = change implementation, slight change of interface possible Single inheritance on class
CLASS class DEFINITION INHERITING FROM superclass. SECTION. --- added attributes and methods DATA: METHODS: --- override / redefine existing method METHODS m REDEFINITION
R
ENDCLASS.
Net4site LLC
Using Inheritance
Polymorphism on object references
CLASS DrawableObject DEFINITION PUBLIC SECTION. METHODS: Draw. ENDCLASS. CLASS Polygon DEFINITION INHERITING FROM DrawableObject. PUBLIC SECTION. METHODS: AddPoint IMPORTING P TYPE T_Point, Draw REDEFINITION. PRIVATE SECTION. DATA: PointTab TYPE T_Point OCCURS 0. ENDCLASS. CLASS Polygon IMPLEMENTATION. METHOD Draw. DATA: Point TYPE T_Point. LOOP AT PointTab INTO Point. CALL METHOD DrawableObject=>Draw( Point ). ENDLOOP. ENDMETHOD. ENDCLASS.
DrawableObject
Point
PROGRAM xy.
Polygon
Bitmap
DATA: DObj TYPE REF TO DrawableObject. DATA: DObjTab TYPE REF TO DrawableObject OCCURS 0. --- create drawable objects --- draw all of them LOOP AT DObjTab INTO DObj. CALL METHOD DObj->Draw. ENDLOOP.
R
Net4site LLC
Interfaces
Interfaces define the interaction between different objects Polymorphism independent of class / inheritance Classes can implement multiple interfaces Uniform access through interface reference
ArchiveMgr
IArchive
Plan
Customer
Material
R
Net4site LLC
Interface Definition
Interfaces...
can define same components as class - without implementation ...may enclose multiple other interfaces (hierarchy) have separate name spaces for their components Components of enclosed interfaces are not visible in the toplevel interface (black boxes); there is a mapping/aliasing feature
INTERFACE interface. [ INTERFACES ...<list of comprised interfaces> .] [ ...<definition of interface components> ] ENDINTERFACE.
R
Net4site LLC
Interfaces
Implementation of interfaces
A class can implement many interfaces Interfaces are implemented side-by-side in a class (like COM) No name conflicts on the class level No semantic conflicts at class level and interface composition
Using interfaces
Access by interface reference like object reference An interface reference only exposes the components of that interface Assignment / cast to another interface possible
Net4site LLC
Interface Example
INTERFACE IArchive DEFINITION. DATA: ObjID TYPE T_OID VIRTUAL. -- fast EVENTS: Saved, . METHODS: SaveYourself IMPORTING . ENDINTERFACE. CLASS Customer DEFINITION. INTERFACES: IArchive, IWorkflow, . ENDCLASS. CLASS Customer IMPLEMENTATION. METHOD IArchive~GET_ObjID. CALL FUNCTION Archive_Get_OID IMPORTING IArchive~objid. -- no more recompute SET DIRECT READ ACCESS FOR IArchive~ObjID. ENDMETHOD. METHOD IArchive~SaveYourself. --- save all own data into RAISE EVENT IArchive~Saved . ENDMETHOD. ENDCLASS.
Net4site LLC
CLASS CArchiveMgr. DATA: IAObj TYPE REF TO IArchive. DATA: IATab TYPE REF TO IArchive OCCURS 0. METHOD AddToArchive IMPORTING IAObj APPEND IAObj TO IATab. ENDMETHOD. METHOD DoArchive. --- archive all objects in table LOOP AT IATab INTO IAObj. WRITE: / Wrote:, IAObj->ObjID. CALL METHOD IAObj->SaveYourself . ENDLOOP. ENDMETHOD.
CArchiveMgr
Plan1
iaTab
IArchive
Plan2
Material
Customer
Class 1 Part
Interface 1
Interface 2
Interface reference
if 3 specific
Interface reference
interface 2 if 4 specific
Object reference
class 2 specific
Class 2 Part
R
Interface reference
interface 5
Net4site LLC
public = visible to all protected = visible to subclasses and implementation private = visible to the class implementation only
Interface components
Separate name space for interface components Interfaces are visible as a whole (like view)
Net4site LLC
Miscellaneous
Constructor (Destructor)
CLASS class DEFINITION. ... METHODS CONSTRUCTOR IMPORTING p TYPE t . ENDCLASS. "--- name / syntax TBD
Friends
CLASS c1 DEFINITION EXPOSING PRIVATE COMPONENTS TO c2. ... PRIVATE SECTION. ENDCLASS. CLASS c2 DEFINITION ACCESSING PRIVATE COMPONENTS OF c1. ... PRIVATE SECTION. ENDCLASS.
R
Net4site LLC
Classes and interfaces Attributes, methods, and events Classes can implement interfaces Interface composition Single inheritance for classes, multiple composition + aliasing for interfaces Event handling
Net4site LLC
ABAP Objects
ABAP Objects as a strategic SAP technology Programming with objects, classes, and interfaces in ABAP
Net4site LLC
Visual Basic
ABAP Objects
CORBA Bridge
R
Net4site LLC
Interoperability Features
Transparent two-way mapping between ABAP Objects and external object models Automatic generation of proxies and stubs Location transparency:
Net4site LLC
Net4site LLC
Objectives
The purpose of this presentation is to:
Provide an Overview of the Enhancement Framework Describe what a BADI is Classic vs. Kernel BADIs Implement a BADI (Classic) Tips & Tricks Address feedback and questions from Audience
R
Net4site LLC
Enhancement Framework
SAP is known for delivering business software easily adaptable by customers for their specific needs. Typically the software (for example, mySAP ERP) can be adapted by one of the following techniques:
Customizing (defining system behavior through standard SAP provided mechanism without coding), Enhancement (adding custom code at strategic hook positions provided by SAP) Modification (modifying SAP supplied code directly often called CoreMod
R
Net4site LLC
Enhancement Framework
Let us first take a look at how the enhancement technique has evolved so far in SAP.
User-Exit is one of the very first mechanisms provided by SAP to execute custom code in between the standard SAP control flow. This is implemented as subroutine call (PERFORM xxx). A classical example for User-Exit is MV45AFZZ include in order processing module of SAP R/3. Though this include object doesnt fall under customer namespace, the object doesnt get overwritten during upgrade. Customer-Exit is better than the user-exit, in the sense that it is implemented using Function Modules and so has a well defined parameter interface. Also since the custom coding done as part of these customer-exits is located away from the original SAP code, the maintenance is easier than user-exits. The BADI-s (Business Add-Ins), as they exist in pre NW04s releases are now called old classic-BADIs. This was the first object-oriented way to enhance the ABAP system. This, to a certain extent, allows multiple implementations with limited filter support. The classic-BADIs are implemented using ABAP Objects
R
Net4site LLC
Enhancement Framework
So what's so cool about this new enhancement technology?
Source Code enhancement Function Group enhancement Class enhancement Kernel-BADI Enhancement
The first three methods, viz., Source Code enhancement, Function Group enhancement, and Class enhancement are brand new ways to enhance the ABAP system. The final one Kernel-BADI is an improvement of the old classic-BADI now integrated into the Enhancement Framework. Remember that all of these techniques are considered enhancing and not modifying the system.
R
Net4site LLC
What is a BADI?
Business Add In
Business Add-Ins may be simply defined as an object-oriented extension of the SAP. They consist of special hooks provided by SAP core developers for incorporating customer (or company) specific logic. (BADI Definition) The process of adapting your program according to your specific scenario is known as implementation of the BADI.
BADIs are based upon the concept of object-orientation. The program that incorporates the enhancement option calls a method of a generated BADI class. During the implementation procedure, the customer-specific code is written in the relevant method. The method name is specified via a BADI interface. The name of the interface is of the form IF_EX_BADI, where BADI is the name of the Business Add-In in question. For example, in the case of the HR Add-In HR_INDVAL, the involved interface is IF_EX_HR_INDVAL.
R
Net4site LLC
What is a BADI?
What's important about this diagram is that it reflects both the definition of a classic BADI as well as its implementation.
Net4site LLC
1.CORE SAP Application developers define an interface for the add-in 2.SAP generates an adapter class for implementing the add-in thus opening a path for customer or partner implementations
R
Net4site LLC
1.Customer/partner developer creates an interface of the adapter class 2.The interface definition ensures that consistent data is passed to the different add-in implementations 3.Adapter class takes care of calling and filtering out the proper components
Net4site LLC
What is a BADI?
SAP guarantees upward compatibility of all BADI interfaces BADIs are not a replacement for Customer Exits (already existing exits were not converted to BADIs) Enhancements, interfaces & generated classes all lie in the SAP namespace Implementations lie in the customer/partner namespace and are transportable Standard naming conventions apply for BADIs start your implementations with Z Object oriented coding rules apply (i.e. no header lines on internal tables)
Net4site LLC
R
If an BADI is called frequently, performance problems can occur (No longer an issue with new Kernel BADIs) Customers can create BADIs Creating a BADI within a CMOD project exit can allow multiple developers to share an exit without stepping on each others toes
Net4site LLC
Net4site LLC
Improved Filters with complex filter condition editor Possibility to inherit the implementations Switchable using Switch Framework
Net4site LLC
Net4site LLC
Net4site LLC
Net4site LLC
Net4site LLC
The next step is to write the appropriate coding for the BADI method. This code incorporates the enhancement logic and is executed by the application program upon the BADI method call. Most of the ABAP statements are applicable in this case. However, since the BADI technology is based upon ABAP Objects, some ABAP constructs are not allowed. The method has importing, exporting, and changing parameters. The enhancement may be achieved by writing code that assigns suitable values to the changing and exporting parameters of the method. The main application program uses these values for further processing, and in this way the desired enhancement effect is achieved
R
Net4site LLC
Net4site LLC
There are multiple ways of searching for BADIs. First there is the obvious
Press F4
Net4site LLC
Go to the Transaction, for which we want to find the BADI. Click on System->Status. Double click on the program name. Once inside the program search for CL_EXITHANDLER=>GET_INSTANCE. Make sure the radio button In main program is checked. A list of all the programs with call to the BADIs will be listed. The export parameter EXIT_NAME for the method GET_INSTANCE of class CL_EXITHANDLER will have the METHOD assigned to it. The changing parameter INSTANCE will have the interface assigned to it. Double click on the method to enter the source code.
R
Net4site LLC
Go to Maintain Transaction (TCODE- SE93). Enter the Transaction for which you want to find BADI. Click on the Display push buttons. Get the Package Name. Go to TCode: SE84->Enhancements->Business Addinns->Definition, enter the Package Name and Execute.
R
Here you get a list of all the Enhancement BADIs for the given package
Net4site LLC
Conclusion
I reviewed the rudiments of Business Add-Ins and their benefits for SAP users and developers. Then, I discussed in detail the steps required in implementing an add-in. I hope this presentation will provide you with some breadcrumbs to help you in adapting standard SAP programs quickly and easily using BADIs!
Net4site LLC
Further Information
Help Portal
http://help.sap.com Documentation SAP Netweaver (04s) Application Platform ABAP technology ABAP Workbench Enhancement Framework
SDN
http://sdn.sap.com
Net4site LLC
Net4site LLC