Developer ToolsFree generatorPDF, Excel, Word exportSAP ECC 6.0All SAP ECC 6.0 tools

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.

Generated code
Download:

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.

Was this tool useful?

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.

ArchRay builder
Design the on-prem AI stack for SAP ECC 6.0: model, GPUs, RAG pipeline, guardrails
See memory, speed and cost as you swap parts, then export the diagram. Free, in your browser.
Open the builder

Keep exploring

Free tools

ERP fixes and how-tos

Runs with your ERP

AI on your ERP

Integrations