Quick answer

How do you call an SAP BAPI from Excel?

To call SAP BAPIs from Excel you need four things: an RFC connection to SAP, the BAPI that fits the job, a mapping from your columns to its import and table parameters, and a commit after every call that returns no error. A BAPI is an RFC-enabled function module that SAP publishes for a business object; it reports the outcome in a RETURN table. PostNow.ai handles all four in Excel: it finds the BAPI in your own system, maps the columns, simulates with a rollback, commits clean rows and writes SAP's message back to each row.

  • The commit is yours. Most BAPIs post nothing until the caller runs BAPI_TRANSACTION_COMMIT in the same RFC session. A document number with nothing in SAP almost always means a missing or misplaced commit.
  • Success means no E or A in RETURN. Read every message, not only the first, and roll back when an error is present.

A BAPI Excel upload is the cleanest way to post spreadsheet data into SAP when a BAPI covers the fields you need: no screens to replay, and a structured answer for every document. If no BAPI covers a field you must fill, record the transaction instead: the trade-off is explained in BAPI vs BDC in SAP. Everything below assumes a BAPI fits, and follows the call in order, from the RFC connection to the message on the row.

What calling a BAPI from Excel involves: an RFC connection and five steps

PostNow.ai calls a BAPI from Excel over RFC, under the SAP login the user stored in PostNow.ai on their own computer, and closes the connection after each call. Any route from Excel to a BAPI goes through the same five steps, starting with the RFC connection; the table shows who does each one in PostNow.ai and in a program you write yourself.

StepIn PostNow.aiIn your own VBA, .NET or Python code
1. Connect over RFCUses the user's stored SAP login (application server, system number, client, user) and opens an RFC connection when the user starts the actionAn RFC library (SAP GUI's RFC controls, the SAP .NET Connector or the NetWeaver RFC SDK) plus logon parameters in your code or config
2. Read the interfaceReads the BAPI's parameters from your system with RFC_GET_FUNCTION_INTERFACE and expands each structure into fieldsThe connector reads the metadata for you, but you still need to know which parameters and fields to fill (SE37 or transaction BAPI)
3. Call the BAPIOne call per document: header and item rows of one document go into one callFill the import parameters and table rows from the sheet and call the function
4. Commit or roll backBAPI_TRANSACTION_COMMIT with WAIT = 'X' when RETURN holds no E or A message; BAPI_TRANSACTION_ROLLBACK otherwiseCall the commit yourself, in the same RFC session as the BAPI
5. Report the resultSAP's message in the Run Log column of the row, the document number in a column you chooseLoop over RETURN and write the messages and export values back to the sheet

Two authorisation layers apply to every call. The RFC call itself needs authorisation object S_RFC (activity 16, execute) for the function group of each module called, which includes the BAPI and the commit and rollback modules (function group BAPT). The BAPI then runs the business checks SAP built into it, such as the purchasing organisation or company code a user may post in. A missing S_RFC authorisation is a typical reason a first BAPI call from Excel fails before it reaches any business logic.

Find the right BAPI: the BAPI Explorer and Find with AI

PostNow.ai searches the function modules of your own SAP system (with SAP's RFC_FUNCTION_SEARCH), so the list matches your release and includes custom RFC modules. Find with AI takes a transaction code or a plain-English request: ME21N leads to BAPI_PO_CREATE1, FB50 to BAPI_ACC_DOCUMENT_POST, VA01 to BAPI_SALESORDER_CREATEFROMDAT2.

PostNow.ai Find a BAPI window searching the SAP system for purchase order BAPIs, with BAPI_PO_CREATE1 in the results
Find a BAPI searches your own system by name, or by describing the job in plain English.

In SAP itself, transaction BAPI opens the BAPI Explorer. It lists BAPIs by business object in the component hierarchy, or alphabetically, and shows only released BAPIs unless you change the setting in the Goto menu. Select a method, then use Detail for the function module name and parameters and Documentation for SAP's description. Before you build on a BAPI, check four things in that documentation:

  • Does it commit itself? Almost no BAPI does; the few that do say so in their documentation and are listed in SAP Note 131838.
  • Does it have a TESTRUN parameter? BAPI_PO_CREATE1 and BAPI_GOODSMVT_CREATE do. It runs SAP's checks without saving.
  • Which X structures go with the data structures? POHEADER pairs with POHEADERX, POITEM with POITEMX. A value whose X field is blank is ignored.
  • Which table holds the messages? Most BAPIs use RETURN with structure BAPIRET2. Older ones return a single BAPIRETURN or BAPIRETURN1 structure, and a few use a table with another name.

If no BAPI covers a field you have to fill, such as a field that exists only on a custom screen, record the transaction instead. The full trade-off, including commit and screen behaviour, is in BAPI vs BDC in SAP; how to record so the replay holds is in the BDC recording guide.

Map Excel columns to BAPI parameters

PostNow.ai shows every parameter and field of the BAPI next to your Excel columns in the BAPI Mapping Designer, and Mapping AI proposes the matches from your column headers; it never receives the row values. The mapping is the real work of a BAPI Excel upload, because a sheet is flat and a BAPI is not.

Parameter kindExample in BAPI_PO_CREATE1How it maps to Excel
Import, single fieldTESTRUNUsually a fixed value in the template, not a column
Import, structurePOHEADER (vendor, company code, purchasing organisation, document type)One value per document: columns on the header row
TablesPOITEM, POSCHEDULE, POACCOUNTOne line per item: columns on the item rows
X structuresPOHEADERX, POITEMX, POSCHEDULEXAn X for every field you send; no column needed
ExtensionsEXTENSIONINCustomer fields, packed into the extension structure your system defines
ExportEXPPURCHASEORDERWritten back to a result column after the call
MessagesRETURN (BAPIRET2)Read after the call; never mapped as input
PostNow.ai BAPI Mapping Designer with POHEADER fields of BAPI_PO_CREATE1 mapped to Excel columns
The BAPI Mapping Designer: structure, field, type and the Excel column for each field in one view.

Four details decide whether the first call works:

  • Header and items. A document with several items needs a rule for which rows belong together. PostNow.ai uses a marker column: an H row starts a document and the D rows below it become its item lines. The item number is copied into the schedule and account lines built from the same row, so they reach the right item.
  • X flags. PostNow.ai fills the X structures from the shape of each data structure and asks you to review the pairs it cannot decide. In your own code, every field you fill needs its X field set too.
  • Internal formats. Over RFC, SAP expects the internal value. Vendor 100045 must arrive as 0000100045; PostNow.ai switches on leading zeros for every field whose domain uses the ALPHA conversion exit. Dates go as YYYYMMDD, and you can set a date format per field.
  • Codes behind the screen text. Some fields show one value on screen and store another, through a language-dependent conversion: units of measure are the classic case, where an English logon shows PC for pieces and SAP stores ST. Send the internal value, or prove the screen value on a test call first.
PostNow.ai header and detail configuration with H and D row markers that group Excel rows into one SAP document
Header/detail grouping: the H row starts a document, the D rows below it become its items.

Read RETURN for every row

PostNow.ai reads the BAPI's RETURN messages after each call and writes SAP's message into the Run Log column of the row, with the document number in a column you choose. Whether a row succeeded is decided by the message types: no E or A message means the document can be committed.

TypeMeaningWhat to do with the row
SSuccess, often carrying the new document numberCommit, then write the number back
WWarning; SAP would still postCommit, but keep the text where the preparer sees it
IInformationCommit
EError; the document is not validRoll back and show the message on the row
AAbort; processing was cancelledRoll back and show the message on the row

An empty RETURN also means no error. Each BAPIRET2 line carries the message class (ID), NUMBER, the text in MESSAGE, the variables MESSAGE_V1 to MESSAGE_V4, and PARAMETER, ROW and FIELD, which point at the input that failed. Read all lines: BAPI_PO_CREATE1, for example, can return a general "Purchase order still contains faulty items" (MEPO 000) above the message that names the field.

The success message usually holds the number: BAPI_PO_CREATE1 returns 06 017, "Standard PO created under the number 4500017532", and the same number in the export parameter EXPPURCHASEORDER. In PostNow.ai the token $DOC_NO picks up the document number, $V1 to $V4 pick up the message variables, and a custom success message can add $USER, $DATE and $TIME.

Excel workbook with the PostNow.ai ribbon and purchase order rows, with the SAP purchase order number written back in the Run Log column
SAP's answer lands on the row it belongs to, with the purchase order number.

Commit with BAPI_TRANSACTION_COMMIT

PostNow.ai commits each document with BAPI_TRANSACTION_COMMIT and WAIT = 'X' only when its RETURN holds no E or A message, and calls BAPI_TRANSACTION_ROLLBACK otherwise, so a failed row leaves nothing behind. SAP's BAPI rules leave the commit to the caller, which is why a BAPI call from Excel needs this second call at all.

  • Same session, or no commit. The commit only closes the work of the BAPI that ran in the same RFC session. A program that opens a new connection for the commit, or uses a stateless call, gets a success message and a document number from the BAPI, and nothing in SAP.
  • Commit per document. A rollback discards everything since the last commit. Call the BAPI and commit (or roll back) for each document, so one bad document cannot take the good ones with it.
  • WAIT = 'X' when the next step reads the result. It makes the commit wait for the update task. Without it, a follow-up call that reads the new document can run before the document exists.
  • Self-committing BAPIs. The few BAPIs that commit internally are listed in SAP Note 131838. Calling the commit after them does no harm, but a rollback cannot undo them.
ⓘ
"Document created" but nothing in SAP? In a do-it-yourself macro this is the first thing to check: the commit is missing, runs in another session, or was skipped because the code only looked at the first RETURN line.

Test before you post: Validate, Simulate and TESTRUN

PostNow.ai tests in two stages. Validate checks the sheet offline, without calling SAP: required fields, type, length, characters, dates, decimals and allowed values. Simulate then sends each document to SAP as a real BAPI call and always follows it with BAPI_TRANSACTION_ROLLBACK, never a commit, so you read SAP's own messages for every row before the real run. The exception is the small group of BAPIs that commit internally (SAP Note 131838): a rollback cannot undo them, so test those in a quality client and use their TESTRUN parameter where they have one.

PostNow.ai validation results panel in Excel listing the rows checked and the rows ready to post
Validate checks the file before anything is sent to SAP; failing cells are marked on the sheet.

Inside SAP you have two ways to test a BAPI by hand:

  • TESTRUN where the BAPI has it. Set TESTRUN = 'X' and the BAPI runs its checks and returns messages without saving. Check the parameter's documentation: what is checked in a test run differs by BAPI.
  • SE37 test sequence. In SE37, Function Module, Test, Test Sequences lets you run the BAPI and then BAPI_TRANSACTION_COMMIT in one session. A single SE37 test of the BAPI alone shows the messages but leaves nothing posted, which is a quick way to see what SAP returns for one record.

Test on a few documents per template, then again after any configuration change, a support pack or a new field in the sheet.

How PostNow.ai calls a BAPI from Excel

PostNow.ai runs the whole call from the Excel ribbon, on the user's own computer and under the user's own SAP login. A designer builds the template once; operators fill the sheet and run it.

  1. Find the BAPI. Search by name in your system, or type a transaction code or a sentence into Find with AI. PostNow.ai reads the BAPI's interface from your system, including the extension structures you declare for customer fields.
  2. Map the columns. Drag fields onto columns, or let Mapping AI match your file's headers (or screenshots of the SAP screen) to the BAPI's fields. Set fixed values, date formats, leading zeros and allowed values per field.
  3. Group header and items. Choose single record or header/detail; with header/detail, the H/D marker column turns one header row and its item rows into one call.
  4. Validate. The offline check marks failing cells on the sheet before anything reaches SAP.
  5. Simulate. Each document is sent to the BAPI and rolled back; SAP's messages land on the rows.
  6. Run. Clean documents are committed with BAPI_TRANSACTION_COMMIT; documents with an E or A message are rolled back. The Run Log shows SAP's message, the user, the time and the SAP system on each row.
  7. Re-run safely. Before a real Run, PostNow.ai reads the Run Log and lists the documents that already posted, with Skip posted rows, Post again or Cancel. Retry Failed re-posts only the rows marked ERROR. A row marked UNKNOWN lost SAP's answer after the call was sent, so look the document up in SAP before you post it again.
PostNow.ai run summary for a BAPI_PO_CREATE1 run, showing the BAPI, the SAP system and the posted and failed counts
The run summary names the BAPI, the SAP system and the count of posted and failed documents.

BAPI calls need no PostNow.ai objects in SAP: standard RFC and the user's RFC authorisation are enough. A template published to the team library becomes run-only for operators; that side is covered in Excel to SAP automation. PostNow.ai's free SAP upload templates come with their columns already mapped to the BAPI.

Worked example: a BAPI Excel upload with BAPI_PO_CREATE1

A buyer at company code 1010 posts 40 purchase orders with 112 items from one Excel sheet through PostNow.ai. The designer built the template on BAPI_PO_CREATE1, starting from the free ME21N purchase order template.

Excel columnBAPI fieldRowNote
Marker(grouping)H and DH starts a purchase order
VendorPOHEADER-VENDORH100045, sent as 0000100045
Purch. org / groupPOHEADER-PURCH_ORG, PUR_GROUPH1010 / 001
Doc. typePOHEADER-DOC_TYPEHFixed value NB
Material, plant, quantityPOITEM-MATERIAL, PLANT, QUANTITYDTG-1001, 1010, 24
Delivery datePOSCHEDULE-DELIVERY_DATEDItem number copied from the item line
PO number$DOC_NOHResult column

Validate stops two item rows whose quantity reads "12 pcs" instead of a number; the buyer fixes the cells. Simulate sends all 40 orders and rolls each one back. Two orders come back with an E message on their header rows: one item in each uses a material that is not extended to plant 1010. The buyer replaces the material, simulates those two orders again, and runs the sheet. Each of the 40 orders is committed separately, and each H row shows "Standard PO created under the number ..." with the number in the result column.

Next morning a colleague opens the workbook and clicks Run by mistake. PostNow.ai lists the 40 orders that already posted and offers Skip posted rows; nothing is sent twice. In a home-made macro, that protection is code someone has to write.

Do-it-yourself routes: VBA, SAP .NET Connector and Python

PostNow.ai is the no-code route: the RFC connection, mapping, commit and per-row results come with the add-in. If you write the call yourself, you need an RFC library, and three are in common use. Whichever you pick, the code still has to handle the commit in the same session, the X flags, the internal formats and the Run Log, which are the parts that take the time.

RouteWhat you needWhat to know
PostNow.ai (Excel add-in)The add-in, the user's SAP login and RFC authorisationNo code; BAPI search, mapping, Simulate with rollback, commit per document and SAP's message on every row
Excel VBAThe RFC ActiveX controls installed with SAP GUI for Windows (SAP.Functions)The controls once depended on the classic RFC library, which SAP no longer supports; SAP GUI 7.50 delivers them on the NetWeaver RFC library, so re-test old macros after a GUI upgrade
SAP .NET Connector (NCo) 3.1The connector from the SAP Support Portal, plus a .NET program or Excel add-in that uses itSupported on .NET Framework 4.6.2 to 4.8.1 and, from patch level 3.1.5, on .NET 8; NCo 3.0 is out of support
Python with PyRFCPyRFC and the SAP NetWeaver RFC SDK, plus a script that reads the workbookSAP stopped maintaining PyRFC and archived its public repository, and recommends a fork or a new project for future work

A VBA macro that calls a BAPI is a different thing from a macro that drives SAP GUI screens. Screen scripting replays clicks, not an interface, and is covered in SAP GUI scripting alternative.

Calling BAPIs from Excel on S/4HANA

PostNow.ai calls BAPIs on SAP ECC and S/4HANA on-premise the same way, and adds API mode, which posts Excel rows through SAP's published OData V2, OData V4 and SOAP APIs. Most BAPIs carry over, with these points to check:

  • Longer material numbers. The material number can be 40 characters in S/4HANA, and many BAPIs keep the 18-character MATERIAL field next to a new MATERIAL_LONG. Map the long field and its X flag.
  • Business Partner for customers and suppliers. Customer and supplier master data is maintained in transaction BP; load it through the Business Partner interfaces rather than the old customer and vendor BAPIs.
  • Cloud, public edition. SAP S/4HANA Cloud, public edition, integrates through the APIs SAP has released for it, listed on the SAP Business Accelerator Hub.

What to plan for before the first real run

PostNow.ai posts through the BAPI's own logic, so SAP's rules decide every result. Settle these points before volume:

  • RFC authorisation. Ask security for S_RFC on the function groups of the BAPI and the commit, for every user who will run the template.
  • Simulate on a few documents. Validate checks the file offline; SAP's own checks start with Simulate.
  • Self-committing BAPIs. If the BAPI appears in SAP Note 131838, a rollback cannot undo it: test it in a quality client, with its TESTRUN parameter where it has one.
  • Fixed values. Put document type, purchasing group or company code in the template as fixed values when they never change, so operators cannot mistype them.
  • One workbook per run. The re-post check reads this sheet's Run Log; a new file with the same rows meets only SAP's own duplicate checks.
  • Re-test after upgrades. A support pack or a configuration change can change what the BAPI checks. Simulate the template again before the next run.

BAPI call errors from Excel and the fix

PostNow.ai writes SAP's message for each failed document into its row, so these are the messages you will read in the Run Log, or in your own code's output.

Symptom or messageWhat it meansFix
Document number returned, nothing in SAPNo commit, or the commit ran in another RFC sessionCall BAPI_TRANSACTION_COMMIT on the same connection after a clean RETURN; PostNow.ai does this on every clean document
Value sent but not postedThe field's X flag was blankSet the matching field in the X structure
Master record "does not exist" although it doesThe number was sent without leading zerosSend the internal format (ALPHA), for example 0000100045
RFC authorisation error before any business messageThe user lacks S_RFC for the function groupAsk security to add the function group; an authorisation trace (STAUTHTRACE) shows which check failed
MEPO 085 Check item number in tableA schedule or account line has no item number, or the wrong oneFill PO_ITEM in each child table; PostNow.ai copies it from the item line
Row marked UNKNOWNThe connection dropped after the call was sentLook the document up in SAP before you post the row again

Choosing a method for other SAP objects is covered in SAP mass upload from Excel.

Frequently asked questions

How does PostNow.ai call SAP BAPIs from Excel?
PostNow.ai is an Excel add-in that calls BAPIs over RFC under the user's own SAP login. You find the BAPI by name in your own system or with Find with AI, map Excel columns to its parameters (Mapping AI reads the headers only), and group header and item rows with an H/D marker. Validate checks the file offline, Simulate calls the BAPI and then BAPI_TRANSACTION_ROLLBACK instead of a commit, and Run commits each document with BAPI_TRANSACTION_COMMIT only when RETURN holds no error. SAP's message and the document number are written back to each row. A 14-day free trial is available.
Can you call an SAP BAPI from Excel?
Yes. Any BAPI is an RFC-enabled function module, so Excel can call it through an RFC library: the RFC controls installed with SAP GUI (from VBA), the SAP .NET Connector, or an add-in such as PostNow.ai that handles the connection for you. The user needs S_RFC authorisation for the BAPI's function group and the business authorisations the BAPI checks.
Do I need BAPI_TRANSACTION_COMMIT after a BAPI call?
Yes, for almost every BAPI that creates or changes data. SAP leaves the commit to the caller, and it must run in the same RFC session as the BAPI; otherwise the BAPI returns a document number and nothing is saved. Commit only when RETURN holds no E or A message, use WAIT = 'X' when the next step reads the new document, and call BAPI_TRANSACTION_ROLLBACK after an error. The few BAPIs that commit internally are listed in SAP Note 131838.
How do I find which BAPI to use?
In SAP, transaction BAPI opens the BAPI Explorer, which lists the released BAPIs by business object; Detail shows the function module and its parameters, and Documentation explains its use. SE37 shows the full interface of any function module. In PostNow.ai, search your system by name or type a transaction code into Find with AI: ME21N, for example, leads to BAPI_PO_CREATE1.
How do I test a BAPI without posting?
Where the BAPI has a TESTRUN parameter, as BAPI_PO_CREATE1 and BAPI_GOODSMVT_CREATE do, set it to X and the BAPI checks the data without saving. Without one, call the BAPI and roll back instead of committing. PostNow.ai's Simulate does exactly that for every document in the sheet and writes SAP's messages to the rows. In SE37, a test sequence lets you run the BAPI and the commit together when you want to post one record by hand.
Can VBA call a BAPI directly?
Yes, through the RFC ActiveX controls that SAP GUI for Windows installs (SAP.Functions). The macro logs on, fills the import parameters and tables, calls the BAPI, reads RETURN and then calls BAPI_TRANSACTION_COMMIT on the same connection. Macros written for older SAP GUI releases may need re-testing after an upgrade, because SAP GUI 7.50 moved these controls from the classic RFC library to the NetWeaver RFC library.
Is PyRFC still maintained?
No. SAP announced in 2024 that it could no longer maintain PyRFC, archived its public GitHub repository, and suggested a fork or a new project for future work. PyRFC also depends on the SAP NetWeaver RFC SDK. SAP still supports its .NET Connector 3.1 and the NetWeaver RFC SDK.
Does calling a BAPI from Excel respect SAP authorisations?
Yes. The RFC call needs S_RFC for the function group, and the BAPI runs the business authorisation checks SAP built into it under the logged-on user. In PostNow.ai, the call runs on the user's own computer, under the SAP login the user stored, when the user starts the action, so every document carries that user's name in SAP and in the Run Log.
BAPIs from Excel, without code

Call your first SAP BAPI from Excel

Find the BAPI, map your columns once, simulate with a rollback, and get SAP's message and document number back on every row.

Start free trial
  • 14-day free trial
  • Works with ECC and S/4HANA
  • Posts under your own SAP login