SAP BAPI for Accounting Document Posting: BAPI_ACC_DOCUMENT_POST Generator
This generator builds an ABAP report for SAP ECC 6.0 that validates or posts a two-line FI document through BAPI_ACC_DOCUMENT_CHECK or BAPI_ACC_DOCUMENT_POST. It covers the two most requested cases: a G/L to G/L journal (SA) and a vendor invoice with an expense line on a cost center (KR).
Fill in
CHECK calls BAPI_ACC_DOCUMENT_CHECK and never commits.
ABAP report: BAPI_ACC_DOCUMENT_CHECK / POST
REPORT z_bapi_acc_document_post.
* Posts (or only checks) a two-line FI document with BAPI_ACC_DOCUMENT_POST.
* Positive amount = debit, negative amount = credit. Lines must net to zero.
DATA: ls_header TYPE bapiache09,
ls_glacc TYPE bapiacgl09,
lt_glacc TYPE STANDARD TABLE OF bapiacgl09,
ls_payable TYPE bapiacap09,
lt_payable TYPE STANDARD TABLE OF bapiacap09,
ls_curr TYPE bapiaccr09,
lt_curr TYPE STANDARD TABLE OF bapiaccr09,
ls_return TYPE bapiret2,
lt_return TYPE STANDARD TABLE OF bapiret2,
lv_amount TYPE bapiaccr09-amt_doccur,
lv_gl1 TYPE bapiacgl09-gl_account,
lv_offset TYPE bapiacap09-vendor_no,
lv_kostl TYPE bapiacgl09-costcenter,
lv_objtype TYPE bapiache09-obj_type,
lv_objkey TYPE bapiache09-obj_key,
lv_objsys TYPE bapiache09-obj_sys,
lv_error TYPE c.
START-OF-SELECTION.
lv_amount = '1250.00'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = '476000'
IMPORTING
output = lv_gl1.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = '100045'
IMPORTING
output = lv_offset.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = '4110'
IMPORTING
output = lv_kostl.
* Header
ls_header-bus_act = 'RFBU'.
ls_header-username = sy-uname.
ls_header-comp_code = '1000'.
ls_header-doc_date = '20261020'.
ls_header-pstng_date = '20261022'.
ls_header-doc_type = 'KR'.
ls_header-ref_doc_no = 'INV-88231'.
ls_header-header_txt = 'Freight invoice Oct 2026'.
* Line 1: G/L account with cost center (debit)
ls_glacc-itemno_acc = 1.
ls_glacc-gl_account = lv_gl1.
ls_glacc-costcenter = lv_kostl.
ls_glacc-item_text = 'Freight invoice Oct 2026'.
APPEND ls_glacc TO lt_glacc.
ls_curr-itemno_acc = 1.
ls_curr-currency = 'USD'.
ls_curr-amt_doccur = lv_amount.
APPEND ls_curr TO lt_curr.
* Line 2: vendor or offsetting G/L account (credit)
IF 'VENDOR' = 'VENDOR'.
ls_payable-itemno_acc = 2.
ls_payable-vendor_no = lv_offset.
ls_payable-item_text = 'Freight invoice Oct 2026'.
APPEND ls_payable TO lt_payable.
ELSE.
CLEAR ls_glacc.
ls_glacc-itemno_acc = 2.
ls_glacc-gl_account = lv_offset.
ls_glacc-item_text = 'Freight invoice Oct 2026'.
APPEND ls_glacc TO lt_glacc.
ENDIF.
ls_curr-itemno_acc = 2.
ls_curr-currency = 'USD'.
ls_curr-amt_doccur = lv_amount * -1.
APPEND ls_curr TO lt_curr.
* Tax: to post tax, add a line to table ACCOUNTTAX (BAPIACTX09) with
* the tax code, set TAX_CODE on the base lines, and add the tax amount
* line in CURRENCYAMOUNT with AMT_BASE. Example tax code: V0
IF 'CHECK' = 'CHECK'.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
EXPORTING
documentheader = ls_header
TABLES
accountgl = lt_glacc
accountpayable = lt_payable
currencyamount = lt_curr
return = lt_return.
ELSE.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = ls_header
IMPORTING
obj_type = lv_objtype
obj_key = lv_objkey
obj_sys = lv_objsys
TABLES
accountgl = lt_glacc
accountpayable = lt_payable
currencyamount = lt_curr
return = lt_return.
ENDIF.
LOOP AT lt_return INTO ls_return.
WRITE: / ls_return-type, ls_return-id, ls_return-number, ls_return-message.
IF ls_return-type = 'E' OR ls_return-type = 'A'.
lv_error = 'X'.
ENDIF.
ENDLOOP.
IF 'CHECK' = 'POST'.
IF lv_error IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
* OBJ_KEY = document number (10) + company code (4) + fiscal year (4)
WRITE: / 'Posted, object key:', lv_objkey.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
ENDIF.
Confirm in SE37 that BAPI_ACC_DOCUMENT_POST on your release uses DOCUMENTHEADER (BAPIACHE09), ACCOUNTGL (BAPIACGL09), ACCOUNTPAYABLE (BAPIACAP09) and CURRENCYAMOUNT (BAPIACCR09). Your field status group may require more fields (business area, profit center, assignment, baseline date). Use document type KR only with a vendor line. Run CHECK first in a test company code.
Have your posting interface reviewed
Send us the document types and account assignments you need and we will check the BAPI mapping, sign handling and error path before you connect an external system.
Optional. The tool and every export work without this. No spam.
How to use it
Start in CHECK mode. Fill company code, document type, dates in YYYYMMDD, currency, the expense G/L and cost center, the amount, and either a vendor number or an offset G/L. Paste the report into SE38 and run it: the list shows every RETURN message. When the check is clean, switch to POST, run again and note the object key. Account numbers and cost centers pass through CONVERSION_EXIT_ALPHA_INPUT so 476000 becomes 0000476000 as the BAPI expects. Dates must be in internal format YYYYMMDD, not the user date format.
- BUS_ACT 'RFBU' is the business transaction for FI postings from this BAPI.
- ITEMNO_ACC links each account line to its CURRENCYAMOUNT line.
- The document is saved only after BAPI_TRANSACTION_COMMIT.
Signs, amounts and the object key
The BAPI has no debit or credit indicator. AMT_DOCCUR is signed: positive is a debit, negative is a credit, and all lines in CURRENCYAMOUNT must sum to zero per currency type. In the vendor invoice case line 1 debits the expense account with +1250.00 and line 2 credits the vendor with -1250.00. After a successful post, OBJ_TYPE is BKPFF and OBJ_KEY holds the document number, company code and fiscal year in one 18-character string, which you can split to open the document in FB03.
Clearing, extra fields and tax
BAPI_ACC_DOCUMENT_POST creates open items but does not clear them, so a payment-with-clearing like F-32 or F-37 cannot be done with it. For clearing, the usual route is the POSTING_INTERFACE_START, POSTING_INTERFACE_CLEARING and POSTING_INTERFACE_END function modules, which drive the clearing transaction in batch-input style. For fields the BAPI structures lack, pass them in EXTENSION2 and move them in an implementation of BAdI ACC_DOCUMENT. For tax, add an ACCOUNTTAX line and a matching tax amount with AMT_BASE; the comment in the code shows where.
- Payment terms and baseline date go in BAPIACAP09 (PMNTTRMS, BLINE_DATE).
- A reconciliation-account override is not needed for a normal vendor line.
How to check the result
Open the document in FB03 with the number from OBJ_KEY. BKPF holds the header (BLART, BUDAT, XBLNR), BSEG the lines. The vendor line shows in FBL1N as an open item and the expense line in FBL3N and in KSB1 for the cost center. If CHECK passes but POST or the commit fails, look first at document number assignment, which only the posting step performs, for example a missing number range interval for the document type and fiscal year in FBN1. The RETURN table lists every message, so read all of them, not just the first.
Frequently Asked Questions
Which SAP BAPI is used for invoice posting in FI?
For a direct FI vendor invoice (like FB60), BAPI_ACC_DOCUMENT_POST with document type KR, an ACCOUNTPAYABLE line and an ACCOUNTGL expense line. For a logistics invoice against a purchase order (like MIRO), use BAPI_INCOMINGINVOICE_CREATE instead, because it performs the PO and goods receipt matching that the accounting BAPI does not.
Can BAPI_ACC_DOCUMENT_POST post with clearing?
No. It posts open items but cannot clear existing ones. Clearing such as F-32, F-37 or an outgoing payment with clearing is usually done with POSTING_INTERFACE_START, POSTING_INTERFACE_CLEARING and POSTING_INTERFACE_END, which process the clearing transaction in the background. Test the field mapping on your release carefully.
What is the difference between BAPI_ACC_DOCUMENT_CHECK and BAPI_ACC_DOCUMENT_POST?
Both take the same header and line tables. CHECK runs the validations and returns messages without creating a document. POST also returns OBJ_TYPE, OBJ_KEY and OBJ_SYS and prepares the posting, which is written when you call BAPI_TRANSACTION_COMMIT. Some checks, such as document number assignment, only happen at POST.
Why do I get a balance error from BAPI_ACC_DOCUMENT_POST?
The CURRENCYAMOUNT lines do not net to zero, usually because both lines were entered as positive. Credits must be negative. Also check that every ITEMNO_ACC in ACCOUNTGL or ACCOUNTPAYABLE has exactly one CURRENCYAMOUNT line per currency type, and that tax lines are included in the total.
If your finance team wants to ask ECC about postings and open items in plain English on your own servers, with any posting going through BAPIs like this after review, we can set that up.
Related Tools
SAP ECC BAPI_MATERIAL_SAVEDATA Material Creation ABAP Generator
Fill in material type, plant, sales and valuation data and get a complete ABAP report that creates the material with BAPI_MATERIAL_SAVEDATA and commits it.
Developer ToolsSAP ECC Cost Center and Order Plan/Actual Cost ABAP Generator (COSP, COSS)
Enter controlling area, cost center or order, year, periods and version to get a report that sums plan and actual costs per cost element from COSP and COSS.
Developer ToolsABAP BAPI Return Handling and Commit Generator
Wrap any BAPI call with BAPIRET2 error checking, message text building and a safe commit or rollback.
SAPSAP Posting Keys Reference
The standard SAP posting keys with debit or credit side, account type and meaning, searchable in the browser.
More Developer Tools tools
See all- SAP ECC Enhancement Transactions and Exit Tables Reference (SMOD, CMOD, SE18, MODSAP, SXC_EXIT)
- SAP ECC Data Dictionary and Repository Tables Reference (DD02L, DD03L, T100, E070, TSTC)
- SAP ECC ABAP Runtime Errors (ST22 Dumps) and Error Log Transactions Reference
- SAP ECC Background Job History ABAP Query Generator (TBTCO + TBTCP)
- SAP ECC Background Job Creation ABAP Generator (JOB_OPEN, SUBMIT, JOB_CLOSE)
- SAP ECC IDoc Segment Data Reader ABAP Generator (EDIDC, EDID4, EDIDS)
- SAP ECC Custom Inbound IDoc Function Module Skeleton Generator
- SAP ECC BAPI_SALESORDER_CHANGE ABAP Generator
- SAP ECC BAPI_PO_CHANGE ABAP Generator
Keep exploring
Free tools
- SAP ECC BAPI_PO_CHANGE ABAP GeneratorGenerate a working ABAP program that changes an SAP purchase order item with BAPI_PO_CHANGE, with POITEM/POITEMX, schedule line date conversion, test run and commit handling.
- SAP ECC BAPI_SALESORDER_CHANGE ABAP GeneratorGenerate a working ABAP program that updates an SAP sales order with BAPI_SALESORDER_CHANGE, with the correct X structures, schedule line handling, error check and commit or rollback.
- SAP ECC BAPI_MATERIAL_SAVEDATA Material Creation ABAP GeneratorFill in material type, plant, sales and valuation data and get a complete ABAP report that creates the material with BAPI_MATERIAL_SAVEDATA and commits it.
ERP fixes and how-tos
- How to Use BAPI_TRANSACTION_COMMIT CorrectlyBAPIs never commit their own update. Here is when to call BAPI_TRANSACTION_COMMIT with WAIT, and why a BAPI can run fine and still save nothing.
- SAP MM BAPI for PO Create and Change: BAPI_PO_CREATE1 and BAPI_PO_CHANGEHow to use BAPI_PO_CREATE1 and BAPI_PO_CHANGE: header, item and schedule structures, the X-structures, error handling in RETURN and the commit step.
- How to add AI to SAP ECC 6.0 on-prem without moving data to a cloudReference architecture for a private on-prem AI assistant on SAP ECC 6.0: RFC and BAPI reads, SLT replica, retrieval index, local LLM, permission mirroring.
AI on your ERP
- Get AI Value From SAP ECC Now, and Use It to De-Risk the Move to S/4HANASAP ECC 6.0 mainstream maintenance ends in 2027. Add AI value on ECC now, using its existing BAPIs and IDocs, and use it to de-risk the S/4HANA migration.
- AI for accounts payable invoice matching in your ERPOn-prem AI reads vendor invoices, runs 3-way match against your ERP PO and receipt, and routes only real exceptions to your AP team. No invoice data leaves your network.
Integrations
- How to automate email into SAP ECC 6.0Turn inbound emails into SAP ECC 6.0 transactions: customer POs into sales orders, supplier confirmations, RFQs and invoices, with review and BAPI posting.
- How to add document OCR to SAP ECC 6.0Capture invoices, packing slips and certificates into SAP ECC 6.0 with OCR and AI: ArchiveLink, parked invoices via BAPI, confidence thresholds and human review.