You are on page 1of 20

0

BAPIs

Contents:
 The role of BAPIs
 BAPI Transaction Model

 SAP AG 1999

© SAP AG D446AW 10-1


0.2
BAPIs: Unit Objectives

At the conclusion of this unit, you will be able to:

 Understand the BAPI concept


 Describe how to find a BAPI
 Explain the usage of BAPIs

 SAP AG 1999

© SAP AG D446AW 10-2


0.3
BAPIs: Overview

Good Bye
Enhancements
and Modifications
1 12 1 Course Overview

BAPIs
1
New Concepts
0
9 1

2 3
News in ABAP
ABAP Objects Workbench

ABAP Language

4
Graphical Query
8

Tools
7 5
Screen Objects 6 Logical Databases
ABAP Dictionary

 SAP AG 1999

© SAP AG D446AW 10-3


0.4
BAPI – Definition

 Business Application Programming Interface

 A BAPI is a well-defined interface to processes and


data of a business application system, implemented as
a method of an object in the Business Object
Repository (BOR).

BAPI

 SAP AG 1999

 A BAPI functions as a "gateway" to the R/3 System, in other words, the R/3 System uses it to
provide access to business data and processes.
 An object in the BOR can have many methods, one or more of which are implemented as BAPIs.
 BAPIs can have various functions
Generating an object
Querying attributes of an object
Changing attributes of an object
...

© SAP AG D446AW 10-4


0.5
T h e R o le o f B A P Is

R /3 s a te llite s y s te m s /
d is tr ib u te d s c e n a r io s (A L E )

B u s in e s s
W o r k flo w

V is u a lB a s ic /J A V A ...
In te r n e t/
In tr a n e t
B u s in e s s B u s in e s s
C om ponent C o m p o n e Bn t

R /3 c o m p o n e n t
fo r m a tio n B u s in e s s C u s to m e r o r p a rtn e r
C om ponent
d e v e lo p m e n ts
 SAP AG 1999

 A BAPI is an interface that can be used for various applications, e.g.


Internet Application Components - mapping individual R/3 functions on the Internet/Intranet for
users that have no R/3 experience
R/3 component formation - communication between the business objects of different R/3
components (applications)
VisualBasic/JAVA/C++ - external clients (e.g. alternative GUIs) access business data and
processes directly

© SAP AG D446AW 10-5


0.6
BAPI Attributes

 Object-oriented
 Access to methods from BOR objects
 Stable interface
 A BAPI interface is "frozen"
 Release function module for customer
 Link data elements to the interface parameters of the FM
 Can be used internally and externally
 BAPIs can be used within R/3 and externally
 But: BAPIs do not contain a presentation layer
 Results are visualized externally by the individual caller

 SAP AG 1999

For BAPIs with UPDATE semantics:


 BAPIs are always called synchronously.
Exception: Sent asynchronously via ALE in an IDoc, then called again synchronously in the target
system (new as of Release 4.0).
 BAPIs implement your database changes via update.
 New as of Release 4.6: BAPIs themselves do not program a COMMIT WORK.
Two methods
- TransactionCommit (FBS name: BAPI_TRANSACTION_COMMIT) and
- TransactionRollback (FBS name: BAPI_TRANSACTION_ROLLBACK)
of the service object BAPISERVICE (technical name SAP0001) must be used instead.

© SAP AG D446AW 10-6


0.7
Example: FlightBooking Business Object

Methods:
FlightBooking.GetList
FlightBooking.GetDetail
FlightBooking.CreateFromData
FlightBooking.Cancel
AirlineCarrier
ConnectionNumber
DateOfFlight
BookingNumber

 SAP AG 1999

 An example business object from the training course data model is called FlightBooking. It contains
a booking. Each booking is uniquely identifiable from its key information: AirlineCarrier ,
ConnectionNumber (flight number), DateOfFlight, BookingNumber. The following
methods are available for this object:
 FlightBooking.GetDetail returns detailed information on a booking
 FlightBooking.CreateFromData creates a booking
 FlightBooking.Cancel
 FlightBooking.GetList returns a list containing details of all the bookings for that flight.
Generally displays fewer details for each booking than GetDetail.

© SAP AG D446AW 10-7


0.8
BAPI Explorer

Hierarchical Alphabetical Detail Documentation Tools Project

Component
hierarchy

Application component

Business object

Key attributes

API methods More information on


subcomponents available in
other ABAP Workbench tools

Hierarchy area

 SAP AG 1999

 You can display more information on business objects and the BAPIs that belong to them using
BAPI Explorer Information. The screen is in two parts: a hierarchy area and a details window. The
hierarchy area displays the component hierarchy. You can expand an application component to find
out which business objects belong to it. If you expand a single business object, the system displays a
sub-tree, showing you which key attributes and API methods belong to it. (API stands for
Application Programming Interface).

© SAP AG D446AW 10-8


0.9
BAPI Explorer - Legend

Business object type


Interface type
Key attribute
Instance-specific method
Non-instance-specific method
Import parameters
Export parameters
Changing parameters

 SAP AG 1999

 Symbols are used to indicate business objects, key attributes, and BAPIs. You can display the key to
these symbols using the Display Legend button.

© SAP AG D446AW 10-9


0.10
Business Objects in the BAPI Explorer

Hierarchical Alphabetical Detail Documentation Tools Project

FlightBooking
AirlineCarrier
ConnectionNumber
DateOfFlight Key attributes
BookingNumber

Cancel
CreateFromData API methods
GetDetail
GetList

FlightCustomer
FlightConnection

 SAP AG 1999

 If you expand a sub-tree for a business object in the BAPI Explorer, the system displays the
following:
 Key attributes, which provide a unique identifier for each business object
 Instance-specific methods, which are methods that are bound to the instance identified by the key
attributes. The business object type FlightBooking has one instance-specific method, GetDetail
(which returns a structure with booking details). Key attribute values must be passed to this
method.
 Non-instance specific methods, which can be called by all instances of an object type.
FlightBooking has one such method, GetList (which returns a list of all bookings, for which a
business object already exists at runtime).

© SAP AG D446AW 10-10


0.11
BAPIs in the BAPI Explorer

Hierarchical Alphabetical Detail Documentation Tools Project

Tool selection
FlightBooking
AirlineCarrier Business Object Builder
ConnectionNumber Function Builder
DateOfFlight ABAP Dictionary
BookingNumber BAPI Konsistenzprüfungen
BAPI Liste erstellen

Cancel
CreateFromData
BookingdataIn Dictionary Structure BAPISBDTIN
Return
Bookingdata
GetDetail Display
GetList
FlightCustomer
FlightConnection

 SAP AG 1999

 If you expand a substructure for a method, the system returns the names of its import and export
parameters. You can obtain more detailed information on the typing of interface parameters by
choosing the Tools tab, then choosing the ABAP Dictionary. BAPI interface parameters are always
typed using ABAP Dictionary types.
 BAPIs usually have an export parameter called RETURN. This can be a structure or internal table.
The Return Parameter contains information on errors that occurred while the BAPI was being
processed. There are no exceptions for BAPIs.

© SAP AG D446AW 10-11


0.12
B u s in e s s O b je c t B u ild e r

O b je c t ty p e

B a s ic d a ta C o m p le te
b u s in e s s o b je c t
v ie w
I Inn t tee rr ff a c e s

K e y fie ld s

A tt r ib u t e s

M e th o d s

E v e n ts

 SAP AG 1999

 To display complete information on a business object type, use the Business Object Builder tool. The
system displays a tree structure for the business object type, including non-API methods.
 To search for a business object, use the Business Object Repository (BOR) tool. This tool displays
the component hierarchy with all the business objects that belong to it. You can navigate from this
tree structure to the Business Object Builder. The system displays the relevant business object
automatically.

© SAP AG D446AW 10-12


0.13
Standard BAPIs

 GetList
 Returns the contents of the key fields for the object you have
chosen
 GetDetail
 Returns detailed information (attributes) for the required object
 CreateFromData
 Creates a new object in R/3 and returns information about it

 SAP AG 1999

 BAPIs with standardized names contain standard methods. Three of the most important are listed
here.

© SAP AG D446AW 10-13


0.14
BAPIs Are Implemented as Function Modules

Hierarchical Alphabetical Detail Documentation Tools Project

Tool selection
FlightBooking
AirlineCarrier Business Object Builder
ConnectionNumber Function Builder
DateOfFlight ABAP Dictionary
BookingNumber BAPI Konsistenzprüfungen
BAPI Liste erstellen

Cancel
CreateFromData
GetDetail
Function module BAPI_SBOOK_GETDETAIL
Return
Bookingdata
GetList
Display
FlightCustomer
FlightConnection

 SAP AG 1999

 In Release 4.6 BAPIs have been implemented using function modules. You can display the function
module for the BAPI you have chosen using the BAPI Explorer.
 Select the BAPI in the hierarchy area.
 In the detailed information display window, choose the Tools tab.
 Choose Function Builder: The system displays the name of the function module.
 Choose Display

© SAP AG D446AW 10-14


0.15
Calling a BAPI from an ABAP Program

ABAP Program
PROGRAM ...
R/3
TABLES ...
DATA ... Business Object
Repository
MODULE init OUTPUT.
CALL
CALL FUNCTION
FUNCTION 'BAPI_...'
'BAPI_...' ...
... Business object A:
ENDMODULE.
Method 1 = M1
MODULE read_data INPUT. Method 2 = M2
CALL FUNCTION
CALL FUNCTION 'BAPI_...'
'BAPI_...' ...
...
ENDMODULE. Function modules:
BAPI_A_M1
MODULE confirm_reservation.
CALL
CALL FUNCTION
FUNCTION 'BAPI_...'...
'BAPI_...' ... BAPI_A_M2
IF ... .
CALLFUNCTION
CALL FUNCTION'BAPI_...'
'BAPI_...'...
...
ENDIF.
ENDMODULE.
 SAP AG 1999

 If you would like to use a BAPI in an R/3 System, you can directly call the function module
containing it. Note that information about any errors that occur are passed to the program using the
interface parameter RETURN. BAPI function modules do not contain either exceptions or user
dialogs. They exist only to encapsulate business logic .

© SAP AG D446AW 10-15


0.16
BAPIs: Exception Handling

 No exceptions
 Errors are handled using exporting parameters (structures
or tables)
 Parameter name: RETURN
 ABAP Dictionary Structure (depends on Release):
BAPIRETURN, BAPIRETURN1,
BAPIRET1, BAPIRET2, BAPIRET2_FIX

 SAP AG 1999

 Every BAPI contains an interface parameter, RETURN, which contains information about errors that
occur. This parameter is always of an ABAP Dictionary type. This means that you must include a
structure of an identical type in your program.

© SAP AG D446AW 10-16


0.17
BAPI Transaction Model for Release 3.1 (Example
of External Client)

Logon BAPI1 BAPI2 Logoff

Client

R/3 COMMIT COMMIT Time


WORK WORK

LUW 1 LUW 2

Update task Update task

RFC - Session
 SAP AG 1999

 In Release 3.1, the BAPIs themselves execute the COMMIT WORK command, in other words, a
BAPI is synonymous with an LUW or transaction.
 If a BAPI itself executes a COMMIT WORK command, it must be listed explicitly in the
documentation for the BAPI (as of Release 4.0). This is the only way in which the user can find out
that a COMMIT WORK is taking place in the BAPI.
 These BAPIs must also be documented in the Online Service System (OSS) in note no. 0131838
"Collective note for BAPIs with 'Commit Work' command".

© SAP AG D446AW 10-17


0.18
BAPI Transaction Model for Release 4.0 (Example
of External Client)

BAPI_TRANSACTION_COMMIT

Logon BAPI1 BAPI2 Logoff

Client

R/3 COMMIT COMMIT Time


WORK WORK

SAP LUW 1 SAP LUW 2

Update task Update task

RFC - Session
 SAP AG 1999

 In Release 4.0A, the Commit control must be removed from the BAPIs that cause the database
changes. Here, the existing transaction model used in Release 3.1 should not be changed. For this
purpose, the RFC-capable function module BAPI_TRANSACTION_COMMIT, which performs the
COMMIT WORK command, must be called.

© SAP AG D446AW 10-18


0.19
BAPI Transaction Model for Release 4.6 (Example
of External Client)

BAPI_TRANSACTION_COMMIT

Logon BAPI1 BAPI2 Logoff

Client

R/3 COMMIT Time


WORK

SAP LUW

Update task

RFC - Session
 SAP AG 1999

 In the transaction model used to develop BAPIs, a transaction represents a processing unit or Logical
Unit of Work (LUW).
 Operations that change the database must be executed via the update.
 As of Release 4.0, BAPIs no longer execute COMMIT WORK commands. This enables several BAPIs
to be combined with each other in an LUW.
 To close LUW processing initiated by the BAPI calls, use the function module
BAPI_TRANSACTION_COMMIT. This module implements the TransactionCommit method of
the BAPISERVICE business object.
 For further details on using BAPIs, see the BAPI User Manual and the BAPI Programming Guide.
These are available in the online documentation as well as on the SAP Homepage (http://www.sap-
ag.de) under Technology -> Open BAPI Network/ BAPI Section.

© SAP AG D446AW 10-19


0.20
BAPIs: Unit Summary

You are now able to:


 Understand the BAPI concept
 Describe how to find a BAPI
 Explain the usage of BAPIs

 SAP AG 1999

© SAP AG D446AW 10-20

You might also like