BAPI – Business Application
Programming Interface
What is a BAPI?
A BAPI (Business Application Programming Interface) is a
standardized function module provided by SAP that allows external
applications (or internal programs) to interact with SAP business
objects like Material, Customer, Sales Order, etc.
It is:
A part of the Business Object Repository (BOR)
Used for data exchange between SAP and non-SAP systems
Released by SAP for public use (stable interface)
Often used in integrations and custom developments
How is a BAPI different from a regular
Function Module?
Aspect BAPI Regular Function Module
Standardized interface to SAP Business
Definition Generic reusable procedure
Objects
Integration (external systems, business
Use Case General ABAP logic reuse
apps)
Registered in BOR (Business Object
Registration Not registered in BOR
Repository)
Can be changed freely by
Stability Released by SAP, interface is stable
developers
Can be called from outside SAP (via
Calling Method Usually used internally
RFC)
Naming Starts with BAPI_, e.g., Custom or standard names
Convention BAPI_MATERIAL_SAVEDATA
Transaction May or may not handle
Often uses commit/rollback work pattern
Handling transactions
Summary
BAPI is a function module with rules, meant for business-level
operations, stable, and integrable with external systems.
Regular function modules are used within ABAP programs for
internal modularization and logic handling, with no strict exposure
or stability rules.
What are the steps to execute a BAPI in
custom code?
Executing a BAPI in custom ABAP code involves a structured approach
to ensure correct data processing and database consistency.
We'll use BAPI_BUPA_CREATE_FROM_DATA to create a Business
Partner in SAP IS-U.
Steps to Execute a BAPI in Custom Code –
1. Identify the Appropriate BAPI
Use transaction BAPI or SE37 to find the correct BAPI.
In our case:
BAPI_BUPA_CREATE_FROM_DATA is used to create a Business Partner in
IS-U.
2. Prepare Input Data
Fill in the required importing parameters and structures as per the BAPI
definition.
DATA: ls_bpartner TYPE bapibus1006_head,
ls_address TYPE bapiaddr1,
lt_return TYPE TABLE OF bapiret2.
ls_bpartner-partnertype = '1'. " 1 = Natural person
ls_bpartner-firstname = 'John'.
ls_bpartner-lastname = 'Doe'.
ls_bpartner-language = 'EN'.
ls_address-name = 'John Doe'.
ls_address-country = 'US'.
ls_address-street = 'Main Street'.
ls_address-postl_cod1 = '12345'.
ls_address-city = 'New York'.
3. Call the BAPI
CALL FUNCTION 'BAPI_BUPA_CREATE_FROM_DATA'
EXPORTING
businesspartnergeneraldata = ls_bpartner
addressdata = ls_address
IMPORTING
businesspartner = DATA(lv_partner)
TABLES
return = lt_return.
4. Check the Return Table for Errors
LOOP AT lt_return INTO DATA(ls_msg) WHERE type = 'E' OR type = 'A'.
MESSAGE ls_msg-message TYPE 'E'. " Display the error message
and stop
ENDLOOP.
5. Commit the Transaction
BAPIs do not commit data automatically. You must explicitly call:
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
6. Handle Output and Confirm Creation
WRITE: / 'Business Partner Created Successfully:', lv_partner.
Full Example
DATA: ls_bpartner TYPE bapibus1006_head,
ls_address TYPE bapiaddr1,
lt_return TYPE TABLE OF bapiret2,
lv_partner TYPE bu_partner.
ls_bpartner-partnertype = '1'.
ls_bpartner-firstname = 'John'.
ls_bpartner-lastname = 'Doe'.
ls_bpartner-language = 'EN'.
ls_address-name = 'John Doe'.
ls_address-country = 'US'.
ls_address-street = 'Main Street'.
ls_address-postl_cod1 = '12345'.
ls_address-city = 'New York'.
CALL FUNCTION 'BAPI_BUPA_CREATE_FROM_DATA'
EXPORTING
businesspartnergeneraldata = ls_bpartner
addressdata = ls_address
IMPORTING
businesspartner = lv_partner
TABLES
return = lt_return.
LOOP AT lt_return INTO DATA(ls_msg) WHERE type = 'E' OR type = 'A'.
MESSAGE ls_msg-message TYPE 'E'.
ENDLOOP.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
WRITE: / 'Business Partner Created Successfully:', lv_partner.
📌 Summary Checklist
Step Description
✅1 Find the right BAPI (BAPI_BUPA_CREATE_FROM_DATA)
✅2 Prepare required input data (BP details, address)
✅3 Call the BAPI
✅4 Check the return table for success/errors
Step Description
Commit the transaction using
✅5
BAPI_TRANSACTION_COMMIT
✅6 Handle response/output (e.g., show new BP number)
Use of BAPI_TRANSACTION_COMMIT –
BAPI_TRANSACTION_COMMIT is a standard SAP function module used
to finalize and persist changes made by BAPIs that modify data.
BAPIs do not commit data themselves — SAP follows the unit-
of-work concept.
So, after using a BAPI to create or change data, you must explicitly
call BAPI_TRANSACTION_COMMIT to save it to the database.
Example: Using BAPI_CONNECTION_CREATEFROMDATA
(SAP IS-U)
Let’s say you are creating a technical installation (connection object)
using this IS-U BAPI:
CALL FUNCTION 'BAPI_CONNECTION_CREATEFROMDATA'
EXPORTING
connectiondata = ls_conn_data
IMPORTING
connectionobject = lv_connobj
TABLES
return = lt_return.
At this point:
The BAPI has performed validations and prepared the data for
commit.
But nothing is yet saved to the database.
Now, to finalize the creation, you must call:
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
The wait = 'X' parameter ensures that the commit is synchronous — the
system waits until the changes are completely saved.
Why is this necessary?
Because SAP uses the LUW (Logical Unit of Work) model:
BAPI calls only queue changes
BAPI_TRANSACTION_COMMIT is what confirms and applies those
changes
If you forget to call it:
No data is saved
The BAPI appears to "work" (no error), but nothing is created in the
database
Use of ROLLBACK in BAPI
ROLLBACK (via BAPI_TRANSACTION_ROLLBACK) is used to undo any
database changes made by a BAPI call when an error occurs.
Why it's needed:
BAPIs don't auto-commit or auto-rollback.
If a BAPI call fails (e.g., due to validation or data errors), any
intermediate or partial changes are not automatically reversed.
To maintain data consistency, you must explicitly rollback the
transaction.
Typical Flow for BAPI + Rollback
Let’s say you’re calling a series of BAPIs, and one of them fails:
abap
CopyEdit
DATA: lt_return TYPE TABLE OF bapiret2.
CALL FUNCTION 'BAPI_BUPA_CREATE_FROM_DATA'
EXPORTING
businesspartnerdata = ls_bp
TABLES
return = lt_return.
READ TABLE lt_return WITH KEY type = 'E' TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
" Error occurred, rollback all BAPI changes
ROLLBACK WORK.
MESSAGE 'Business Partner creation failed. Rolled back.' TYPE 'E'.
EXIT.
ENDIF.
CALL FUNCTION 'BAPI_CA_CREATE'
EXPORTING
customerca = ls_ca
TABLES
return = lt_return.
READ TABLE lt_return WITH KEY type = 'E' TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
" Another error – rollback everything
ROLLBACK WORK.
MESSAGE 'Contract Account creation failed. Rolled back.' TYPE 'E'.
EXIT.
ENDIF.
" Everything is okay, commit all changes
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
Key Rules for BAPI Rollback
Rule # What to Remember
BAPIs don’t auto-commit — changes are queued until you call
1
BAPI_TRANSACTION_COMMIT
Until you call BAPI_TRANSACTION_COMMIT, you can cancel
2
everything using ROLLBACK WORK
3 Once committed, changes cannot be rolled back via ABAP
4 Always check the RETURN table from each BAPI for success/failure
5 Use ROLLBACK WORK only before you commit
Real-World IS-U Example
" Step 1: Create BP
CALL FUNCTION 'BAPI_BUPA_CREATE_FROM_DATA'
... RETURN = lt_return.
IF error_found_in( lt_return ).
ROLLBACK WORK.
EXIT.
ENDIF.
" Step 2: Create Contract Account
CALL FUNCTION 'BAPI_CA_CREATE'
... RETURN = lt_return.
IF error_found_in( lt_return ).
ROLLBACK WORK.
EXIT.
ENDIF.
" Step 3: All good — now commit
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING wait = 'X'.
❌ What If You Call COMMIT Too Early?
If you do this:
CALL FUNCTION 'BAPI_BUPA_CREATE_FROM_DATA'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'. " <-- Too early!
CALL FUNCTION 'BAPI_CA_CREATE'. " Fails here
ROLLBACK WORK. " Too late! BP already committed
Now you’re stuck:
BP is created ✅
CA is not ❌
Data inconsistency ❗
Summary
Action What It Does
Cancels all uncommitted BAPI and DB
ROLLBACK WORK
changes in current LUW
BAPI_TRANSACTION_COMMI Finalizes BAPI changes — after this, you can’t
T roll back
Commit only after all validations pass.
Rule
Roll back on first error.
Can BAPI be used for mass processing?
BAPIs are technically single-record APIs, but many of them support
batch processing by being called in loops — or some offer table
parameters to handle multiple entries in one go.
Types of BAPI available in SAP
Here’s a detailed breakdown of the different types of BAPIs we’ll
typically encounter:
Type Descripti Example
on
Single-record BAPI Deals with one BAPI_BUPA_CREATE_FROM_DATA
business object at a
time.
Multi-record BAPI Processes multiple BAPI_ACC_DOCUMENT_POST
records in a single
call.
Get/Read BAPI Retrieves data (does BAPI_MATERIAL_GET_DETAIL
not change DB).
Delete BAPI Deletes a specific BAPI_MATERIAL_DELETE
business object.
Change/Update Updates existing BAPI_BUPA_CHANGE_FROM_DATA
BAPI records.
Transaction BAPI Used for business BAPI_TRANSACTION_COMMIT
transactions
Interface BAPI Integrates with BAPI_PO_CREATE1
external systems.
Status BAPI Queries or updates BAPI_ORDER_STATUS_CHANGE
the status of
business objects.
Custom BAPI Custom-defined ZBAPI_CUSTOM_PROCESS
BAPIs to meet
specific needs.
Testing & Debugging :
How do you test a BAPI in the SAP system?