ABAPintermediate

BAPI Development & Usage

Business Application Programming Interfaces as SAP's stable, released API layer for external and cross-module access.

A BAPI is SAP's supported way to create or change business data from outside a transaction — a sales order, a goods movement, a vendor.

A BAPI is like using a bank's official teller window instead of reaching behind the counter into the vault yourself - you get validation, receipts (RETURN messages), and consistency, instead of silently corrupting the books.

Key Concepts

1
Why not just write to the table. A sales order is not one row. Creating one touches header and item tables, updates stock, checks credit, applies pricing, and writes document flow.
2
An INSERT into VBAK produces a row that looks like an order and is not one. Nothing downstream works, and the inconsistency is usually found weeks later. BAPIs exist so that the business logic runs.
INSERTVBAK
3
What makes a function module a BAPI. It is remote-enabled, registered in the Business Object Repository, follows SAP's naming and parameter conventions, and is released — meaning SAP commits to not breaking its interface between releases.
4
That last point is the real value. A standard function module you found by tracing a transaction can change in any support pack.
5
Errors come back in a table, not as exceptions.
    CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
      EXPORTING order_header_in = ls_header
      IMPORTING salesdocument   = lv_vbeln
      TABLES    order_items_in  = lt_items
                return          = lt_return.
6
lt_return holds messages with a type: S success, I info, W warning, E error, A abort. Nothing raises an exception, so code that does not read this table treats a complete failure as success.
lt_returnSIWE
7
    READ TABLE lt_return TRANSPORTING NO FIELDS
         WITH KEY type = 'E'.
    IF sy-subrc = 0. " an error: do not commit
    ENDIF.
8
The mistake everyone makes once: BAPIs do not commit. The changes sit in the update task until you say so:
9
    IF no errors.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    ENDIF.
10
Forget the commit and the BAPI returns a document number, the log looks perfect, and nothing was saved.
11
WAIT = 'X' makes the call return only once the update has finished. Without it, reading the new document immediately afterwards can find nothing — a race that appears intermittently and is hard to trace.
WAIT = 'X'
12
Ones worth knowing by name. BAPI_SALESORDER_CREATEFROMDAT2, BAPI_PO_CREATE1, BAPI_MATERIAL_SAVEDATA, BAPI_GOODSMVT_CREATE. Test any of them in SE37 before writing code around them.
BAPI_SALESORDER_CREATEFROMDAT2BAPI_PO_CREATE1BAPI_MATERIAL_SAVEDATABAPI_GOODSMVT_CREATESE37
13
When no BAPI exists. In S/4HANA, look for a released OData or RAP business object — SAP's current equivalent of a released API. What not to do is reverse-engineer the function modules a standard transaction calls internally: they are unreleased, undocumented, and free to change. A batch input recording of the transaction is the older fallback, and is fragile against screen changes.
14
What the interviewer is probing.1. "Why must you call BAPI_TRANSACTION_COMMIT?" Probing: the update model. Stalls: "It saves." Moves up: BAPIs do not commit; they register update tasks, so without the commit nothing is written — and you must check the return table first.
15
2. "How do you know a BAPI succeeded?" Probing: error handling. Stalls: "No exception." Moves up: inspect the RETURN table for type E or A messages before committing — a BAPI reports errors as data, not exceptions.
16
3. "Why prefer a BAPI over a BDC recording?" Probing: the comparison. Stalls: "It is newer." Moves up: it is a released, documented interface that survives screen changes and upgrades, where a BDC breaks when a screen moves.
17
4. "What is the point of the X-structures?" Probing: the detail. Stalls: "Nothing." *Moves up:* they mark which fields to actually change, so an update does not blank every field you left initial.