The aim of this page is to provide a high-level introduction to the concept and main functionalities of Purchasing BAPIs.
Overview - What is a BAPI?
BAPI stands for Business Application Programming Interface. It provides an interface to a process or document in business application systems such as R/3. A BAPI is implemented as a function module, that is stored and described in the Function Builder transaction SE37.
What type of BAPIs do exist and what they are used for?
BAPIs are available across the enterprise business processes, such as Purchasing or Inventory Management. In the procurement process, separate interfaces exist for Purchase Order (BAPI_PO_CREATE, BAPI_PO_CREATE1, BAPI_PO_CHANGE), Purchase Requisition (BAPI_PR_CREATE, BAPI_REQUISITION_CREATE) or Contracts/Agreements (BAPI_SAG_CREATE, BAPI_CONTRACT_CREATE). They represent the same functionalities as the online SAP-transactions. That means the BAPI should provide the same standard functionalities as the corresponding business transaction in ECC.
BAPI_PO_CREATE1 represents the online enjoy transaction ME21N;
BAPI_PR_CREATE represents the online enjoy transaction ME51N and so on.
A comprehensive list of BAPIs can be found on our List of BAPIs wiki page.
In order to save changes done by a BAPI permanently in the database, the BAPI BAPI_TRANSACTION_COMMIT must be executed.
What BAPIs are supported?
Not all interfaces are supported by SAP. Old BAPIs like BAPI_PO_CREATE or BAPI_REQUISITION_CREATE are representing the obsolete transactions ME21 and ME51. These functions are not supported anymore. That is documented in the following FAQ Note: 1803189 - "FAQ: End of Support of ME21, ME51, BAPI_PO_CREATE and Archiving Reports etc.".
How to fill a BAPI? What are the BAPI-structures?
BAPI Explorer transaction (t-code BAPI) enumerates all the available BAPIs by Enterprise hierarchy. For example, by drilling down to Materials Management > Purchasing > Purchase Order > CreateFromData1 method, you can display the BAPI function BAPI_PO_CREATE1. BAPI Explorer then provides you a comprehensive description of the BAPI-interface, even more you have example data about how to fill the different BAPI-structures.
When working with a BAPI, you not only have to enter the fields where an update should be triggered, but also the so-called X-structures. The X-structures contain administrative fields, and they define by an ‘X’ what should be considered by the BAPI interface and by a blank field ‘ ’ what should be not.
Example: You would like to send the currency in the BAPI interface. You should send:
How to Test a BAPI? How to prepare Test data?
1 Creating Test data with the FBGENDAT report
See a complete description of this process in the SAP Note 539978 – Automatic generation of BAPI test data directory (no code inside)
1. Set the FBGENDAT parameter to ‘X’ for the user creating or changing the document in SU01;
2. Run the FBGENDAT report in ECC for the Function BAPI_PO_CREATE1 or BAPI_PO_CHANGE… etc. in mode ‘B’;
3. Create/change the document as usual;
4. Check the test data repository in the given BAPI Function BAPI_PO_CREATE1 or BAPI_PO_CHANGE… etc.
In case you require SAP Support to analyze that data, please let us know the record number and open the corresponding ECC system connection.
In case you create test data from an SRM system, you can consult our Creating test data for ECC backend purchasing documents wiki page, or the SAP Knowledge Base Article 1943620 (How to create test data in ECC system (from SRM)).
FBGENDAT Execution modes
A = Write test data and terminate (A test data record is created after the call of the function module and the calling program ends with a termination message (dump))
B = Write test data and continue normally (A test data record is created after the call of the function module and the function module is processed normally.)
C = Endless loop (NO test data record is generated)
D = Retrieve test data and continue normally (A test data record is prepared after the call of the function module, but it is not stored.)
You can activate, display and delete a given BAPI-Function execution mode.
Attention! Always mind the deactivation of the test data generation by deleting the entries in report FBGENDAT and resetting the user parameter!
2 Test data creation in the runtime by debugging (not during RFC-call)
1. Set a breakpoint onto the first code line of the BAPI;
2. Run the application or program which should call the BAPI > debugger stops at the code line;
3. Click on „Tools” (small hammer) icon on the lower right-side panel of the ABAP-debugger;
4. Give a proper name to your test data entry and remove your breakpoint.
3 Manual creation of the Test data
Of course, you can start filling the data anytime manually. At any moment, you can choose to save your data from SE37 transaction. In case of incomplete data, you will encounter the same messages as if you were trying to save an incomplete document during the online transaction.
Examples of BAPI Test data
Examples about how to fill a BAPI with a given set of ready-made data are available in the following SAP Knowledge Base Articles [no ABAP-code inside]:
Debugging the BAPI
Debugging error messages from the BAPI
1. Start the BAPI and import your test data from the test directory.
2. Execute that test data in ‘Test run’ (flag the ‘Test run’ field to ‘X’).
3. Now you can see all the errors and messages in the RETURN table.
4. Select the error you need and note its number.
5. Now run the same test data in ‘Test run’ by debugging.
6. In the debugger menu, select ‘Breakpoint at message’.
7. Now you can set a breakpoint on the required message.
8. Click ‘Execute’. The BAPI stops at the message/error.
Related SAP Notes/KBAs
KBA 2470394 - Troubleshooting guide for BAPIs in purchasing area - Guided Answers
SAP Note 499627 - FAQ: BAPIs for purchase requisitions
SAP Note 1803189 - FAQ: End of Support of ME21, ME51, BAPI_PO_CREATE and Archiving Reports etc.
SAP Note 582221 - FAQ: BAPIs for purchase orders
SAP Note 1046794 - FAQ: BAPI for Outline Agreement
SAP Note 539978 – Automatic generation of BAPI test data directory
KBA 2134946 - Sample of BAPI_PO_CREATE1 Test Data for Material PO Transferred from SRM