Posting from ABAP: BAPI_ACC_DOCUMENT_POST

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Sometimes a program, not a person, has to book a journal entry: an interface that turns a file from a shop system into postings, a month-end program that books an accrual, a migration of old documents. SAP has long offered one ready-made function module for this, BAPI_ACC_DOCUMENT_POST. You fill a few internal tables with the header of the entry and its lines, call the module, read the messages it returns, and then commit or roll back. This page explains those four steps, shows a complete call for Example Trading Co., and explains why the module is not available to ABAP Cloud code and what SAP names as its successor. It is written against SAP S/4HANA 2025 FPS02 on premise and Private Edition, where the module runs as a classic function module. In SAP S/4HANA Cloud Public Edition 2608 you cannot write ABAP code that calls it directly; the Public Edition offers released services instead.

Before you read

Key terms

  • BAPI: a documented function module that outside programs call to read or change business data without touching the tables.

  • Journal entry: one posting with a header and at least two lines that balance.

  • Line item: one row of the entry, for one account and one amount.

  • Reference key: the object key that a posting from another application carries, so that the source document can be found again.

  • Clean core: the rule to extend SAP only through released interfaces.

What the module does and where it fits

BAPI_ACC_DOCUMENT_POST is a function module, and the SAP documentation of Financial Operations lists it as one of four ways to upload journal entries into the error correction and suspense accounting layer (ECS): an ABAP report, a Fiori app, an asynchronous SOAP service, and this BAPI. SAP’s description of the BAPI there is short: you can use it to upload journal entries, and its own system documentation, which you open in transaction SE37, tells you more. The same page names the sister module BAPI_ACC_DOCUMENT_CHECK, which is used to check whether a posting to accounting is possible. That pair is the pattern of this page: check first, post second.

Two things are worth knowing before the first call. The first is that the module posts an accounting document in the same way a person would: the usual checks run (period open, account exists, document balances, field status). If any check fails, no document is created and the return table says why. The second is that the module is a classic Standard ABAP function module. It is remote-enabled, which means it can also be called from another system by RFC, but SAP’s Cloudification Repository does not release it for ABAP Cloud, as the last part of this page explains.

The interface: what you fill and what you get back

A BAPI call is a list of named parameters. This module has a small group that every call uses and a long list of optional ones. The names and the structures below come from the interface metadata of the module as published by SAP in the archived repository node-rfc-samples (read on 2026-11-13; the file was generated from a system in 2021, so check the interface of your own release in SE37 or in ADT before you rely on a field).

Parameter Structure What it carries

DOCUMENTHEADER (importing)

BAPIACHE09

The header of the entry: company code COMP_CODE, document date DOC_DATE, posting date PSTNG_DATE, document type DOC_TYPE, header text HEADER_TXT, reference document number REF_DOC_NO, the user USERNAME, the business transaction BUS_ACT and the three fields that identify the source document: OBJ_TYPE, OBJ_KEY and OBJ_SYS.

ACCOUNTGL (table)

BAPIACGL09

The G/L account lines. Each line has a line number ITEMNO_ACC and the account GL_ACCOUNT, and can carry the account assignments of the line, for example COSTCENTER, PROFIT_CTR, ORDERID and WBS_ELEMENT, plus ITEM_TEXT and TAX_CODE.

ACCOUNTRECEIVABLE (table)

BAPIACAR09

The customer lines: ITEMNO_ACC, the customer CUSTOMER, payment terms PMNTTRMS, the baseline date BLINE_DATE, ITEM_TEXT and the special G/L indicator SP_GL_IND.

ACCOUNTPAYABLE (table)

BAPIACAP09

The supplier lines: ITEMNO_ACC, the supplier VENDOR_NO, payment terms PMNTTRMS, the baseline date BLINE_DATE, payment block PMNT_BLOCK, ITEM_TEXT and SP_GL_IND.

CURRENCYAMOUNT (table)

BAPIACCR09

The amounts. One row per line and currency type: the line number ITEMNO_ACC, the currency type CURR_TYPE, the currency CURRENCY, the amount in document currency AMT_DOCCUR, the exchange rate EXCH_RATE, and the tax and cash discount amounts AMT_BASE, TAX_AMT, DISC_BASE, DISC_AMT.

RETURN (table)

BAPIRET2

The messages. Each row has TYPE (S success, E error, W warning, I information, A abort), the message class ID, the number NUMBER and the text MESSAGE.

OBJ_TYPE, OBJ_KEY, OBJ_SYS (exporting)

The reference key of the new document. OBJ_KEY is the identifier of the posted document, which you pass on or store so that the document can be found again.

Other tables exist for the cases outside this page: ACCOUNTTAX (tax lines), ACCOUNTWT (withholding tax), CUSTOMERCPD (one-time customers), CRITERIA and VALUEFIELD (profitability analysis characteristics and values), PAYMENTCARD, REALESTATE, CONTRACTHEADER and CONTRACTITEM, and the two extension containers EXTENSION1 and EXTENSION2 through which a customer enhancement receives fields the standard structures lack. The DOCUMENTHEADER also contains the fields ACC_PRINCIPLE (accounting principle), ECS_ENV and DOC_STATUS. The SAP documentation of the ECS layer states that when you upload through ECS, the field ECS_ENV must be filled with the value of the ECS environment variable.

The central rule is the link between the tables. Every line of a business partner or G/L account gets a number in ITEMNO_ACC, and the CURRENCYAMOUNT rows refer to the line by that same number. A line in one of the account tables without a CURRENCYAMOUNT row has no amount, and an amount row without a line is rejected. This is the same relationship that ties the header, the lines and the amounts of the entry in the Universal Journal. The sign of the amount tells the module which side the line is on; the example below uses a positive amount for a debit and a negative amount for a credit, but this page cannot confirm that convention from an official page: check the parameter documentation of the module in your system before you rely on it.

The four steps in order

sequenceDiagram participant P as ABAP program participant C as BAPI_ACC_DOCUMENT_CHECK participant B as BAPI_ACC_DOCUMENT_POST participant T as BAPI_TRANSACTION_COMMIT P->>C: header, lines, amounts C-->>P: RETURN messages, nothing is posted alt a message of type E or A P->>P: stop, show or log the messages else no error P->>B: same header, lines, amounts B-->>P: RETURN messages and OBJ_KEY alt a message of type E or A P->>P: BAPI_TRANSACTION_ROLLBACK else no error P->>T: commit (WAIT if the next step needs the document) T-->>P: the document is saved end end
  1. Fill the header, the line tables and the amount table in the program. Fill ITEMNO_ACC with the same value in a line and its amount row.

  2. Call BAPI_ACC_DOCUMENT_CHECK with the same data. If the return table holds a message of type E or A, stop; nothing was posted and you have lost nothing.

  3. Call BAPI_ACC_DOCUMENT_POST. Read RETURN again, because the check cannot know everything the posting finds, for example a lock held by another user.

  4. If there was no error, call BAPI_TRANSACTION_COMMIT. If there was one, call BAPI_TRANSACTION_ROLLBACK.

The module does not commit by itself. That is the rule of the BAPI programming model, described in the page on BAPIs, and it is the SAP LUW rule applied to a function module: the caller decides when the unit of work ends, so that several BAPI calls can be made permanent together or not at all. If you forget the commit, the program runs without an error and the document is never saved, which is the most common mistake with this module. The page on the SAP LUW explains what the commit does and why a posting function may register its work for the update task instead of writing it at once.

The WAIT parameter of BAPI_TRANSACTION_COMMIT turns the commit into a commit that waits for the update to finish. The SAP Community describes it as a non-blank value giving COMMIT WORK AND WAIT. That is a community description, not an official page, so confirm the parameter in SE37. You need it when the next statement of your program reads the document you just posted or builds on it.

A complete call for Example Trading Co.

Example Trading Co. (company code EX01, euro, leading ledger 0L) books an accrual of EUR 1,200.00 for an IT service that has been used but not yet invoiced: a debit on an expense account assigned to cost center EX-IT, and a credit on a liability account. The account numbers are made up for this site, and so is the user name. The program checks, posts, reads the result and commits. Run of the numbers, by hand:

The two amounts add up to zero, which is the balance rule every journal entry obeys.

Requires an SAP system; not run here.

CLASS zcl_exp_accrual_poster DEFINITION PUBLIC FINAL CREATE PUBLIC.
  PUBLIC SECTION.
    METHODS post
      RETURNING VALUE(result) TYPE bapiret2-message.
ENDCLASS.

CLASS zcl_exp_accrual_poster IMPLEMENTATION.
  METHOD post.
    DATA obj_type TYPE bapiache09-obj_type.
    DATA obj_key  TYPE bapiache09-obj_key.
    DATA obj_sys  TYPE bapiache09-obj_sys.

    DATA(header) = VALUE bapiache09(
      comp_code  = 'EX01'
      doc_date   = sy-datlo
      pstng_date = sy-datlo
      doc_type   = 'SA'
      header_txt = 'IT accrual'
      username   = sy-uname ).

    DATA gl_lines TYPE STANDARD TABLE OF bapiacgl09 WITH EMPTY KEY.
    gl_lines = VALUE #(
      ( itemno_acc = '0000000001' gl_account = '0000477000' costcenter = 'EX-IT' item_text = 'IT service used' )
      ( itemno_acc = '0000000002' gl_account = '0000217000' item_text = 'IT service accrued' ) ).

    DATA amounts TYPE STANDARD TABLE OF bapiaccr09 WITH EMPTY KEY.
    amounts = VALUE #(
      ( itemno_acc = '0000000001' curr_type = '00' currency = 'EUR' amt_doccur =  '1200.00' )
      ( itemno_acc = '0000000002' curr_type = '00' currency = 'EUR' amt_doccur = '-1200.00' ) ).

    DATA return TYPE STANDARD TABLE OF bapiret2 WITH EMPTY KEY.

    CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
      EXPORTING
        documentheader = header
      TABLES
        accountgl      = gl_lines
        currencyamount = amounts
        return         = return.
    IF line_exists( return[ type = 'E' ] ) OR line_exists( return[ type = 'A' ] ).
      result = VALUE #( return[ type = 'E' ]-message OPTIONAL ).
      RETURN.
    ENDIF.

    CLEAR return.
    CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
      EXPORTING
        documentheader = header
      IMPORTING
        obj_type       = obj_type
        obj_key        = obj_key
        obj_sys        = obj_sys
      TABLES
        accountgl      = gl_lines
        currencyamount = amounts
        return         = return.
    IF line_exists( return[ type = 'E' ] ) OR line_exists( return[ type = 'A' ] ).
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
      result = VALUE #( return[ type = 'E' ]-message OPTIONAL ).
      RETURN.
    ENDIF.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = abap_true.
    result = |Posted, reference key { obj_key }|.
  ENDMETHOD.
ENDCLASS.

Source: node-rfc-samples: interface of BAPI_ACC_DOCUMENT_POST (parameter and field names), Document Entry (the check module) and Implementing Your Own BAPIs (the return convention)

Reading it:

  • The header holds only what a person would type on the first screen of the posting transaction: company code, the two dates, the document type (a value such as SA is used in the example; check which document types exist in your system) and a text. The posting period and the fiscal year follow from the posting date.

  • There are two line rows and two amount rows with the same two line numbers. The account assignment for the expense, cost center EX-IT, sits on the line, not in the amount table.

  • CURR_TYPE is a two-character field that the interface describes as the currency type and valuation view. The example fills it with '00', which is meant to select the amount in the document currency (euro); check the parameter documentation in your system for the values your release accepts. The other currency types of the company code, such as the group currency, are derived by the system from its configuration (Ledgers, Currencies and Exchange Rates).

  • A real program also reads the whole RETURN table, not only the first error, and logs it, as the next section describes. The example returns one message to stay short.

  • The class contains no COMMIT WORK: the commit is done by the BAPI that is made for it. Never call COMMIT WORK inside a BAPI, a BAdI that runs during posting, or a PERFORM that is registered for the commit; the SAP LUW page lists the runtime errors that follow.

A customer or supplier line works the same way, with one table row in ACCOUNTRECEIVABLE or ACCOUNTPAYABLE in place of the row in ACCOUNTGL, and the amount row with the same ITEMNO_ACC. The payment terms and the baseline date go on that row.

Reading the return table

RETURN is a list of messages, not a single result, and the module can return several rows even for a successful posting.

  • A row of type S or I is information and does not stop anything. After a successful posting OBJ_KEY holds the key of the document.

  • A row of type W is a warning. The posting may still have succeeded; log it.

  • A row of type E or A is a failure. The ALE documentation states the convention for BAPIs: an E leads to a rollback, with no error to a commit. Do not commit if you find one.

  • The fields ID and NUMBER are the message class and number. If you need to react to one particular message, compare these two fields, never the text, which depends on the logon language.

  • PARAMETER, ROW and FIELD name where the problem is, for example the table ACCOUNTGL, row 2 and the field GL_ACCOUNT. Use them in your log, since they are the quickest way to find a wrong account.

If you call the module in a loop for many entries, commit after each successful entry or after a defined batch, and roll back only the failing one; one ROLLBACK removes everything uncommitted in the current SAP LUW, including entries that had succeeded.

Common errors

What you see What it usually means

The program ends without an error but there is no document

The commit is missing, or a message of type E was ignored. Read the whole RETURN table.

The amounts do not balance

The sum of AMT_DOCCUR in one currency is not zero. Check the signs.

An amount row is rejected

Its ITEMNO_ACC has no line in ACCOUNTGL, ACCOUNTRECEIVABLE or ACCOUNTPAYABLE.

A line is rejected for a missing field

The field status group of the account (see the page on number ranges and field status) demands a cost center or similar on the line. Fill it in the account table.

The next BAPI cannot find the document

The commit ran without waiting. Use the WAIT parameter of the commit module when the next step depends on the first.

The call works in your system but not in a Cloud system

The module is not released for ABAP Cloud. See the next section.

ABAP Cloud, the Public Edition and the clean core

SAP’s Cloudification Repository, the public list of released and classic APIs, is the place to look. For SAP Cloud ERP, its file objectReleaseInfoLatest.json marks BAPI_ACC_DOCUMENT_POST as not to be released and names I_JOURNALENTRYTP, a RAP business object interface, as the successor. For SAP Cloud ERP Private, the file objectClassifications_SAP.json lists the module among the classic APIs with the label remote-enabled. The consequence in plain words: on premise you can still call the module from classic ABAP and from outside by RFC, in the clean core model it counts as a classic API that you use deliberately, and in ABAP Cloud code you do not call it directly. Two ways lead on.

  • Use the successor. The business object interface I_JournalEntryTP is read and written with the Entity Manipulation Language, the subject of the pages on EML and on released APIs. This page does not show its fields; the repository names it, but the documentation page for it was not read for this page.

  • Wrap the module. The transaction ACO_PROXY and the SAP-samples project tier2-rfc-proxy generate a released wrapper class for a remote-enabled module, so ABAP Cloud code calls the wrapper. The page on RFC, BAPIs and IDocs describes this.

From outside the system, the Public Edition and on-premise systems also offer the journal entry web services: the synchronous service JournalEntryCreateRequestConfirmation_In and the asynchronous service JournalEntryBulkCreationRequest_In of the Public Edition, which post a journal entry from a SOAP message. Which of these four routes fits depends on where your program runs: inside an on-premise system (BAPI), inside ABAP Cloud (the RAP business object interface or a wrapper), or outside SAP (the web services).

What older books show, and what has changed

The book Configuring SAP S/4HANA Finance, 3rd edition (2025), and the book SAP S/4HANA Financial Accounting Configuration, 2nd edition (2023), concentrate on configuration and the standard posting transactions and do not teach the module. Older ABAP material for SAP ERP shows BAPI_ACC_DOCUMENT_POST as the standard way to post from a program and often leaves out the check module. Since SAP S/4HANA the general ledger, Controlling and the Material Ledger share the Universal Journal, so one call writes the lines to the table ACDOCA once, and a program that reads the old tables of that older material, for example FAGLFLEXA or COEP, finds nothing for new postings. The newer rule is that the module is a classic API: allowed for on-premise code and RFC callers, replaced by a released interface for ABAP Cloud code.

Summary

  • BAPI_ACC_DOCUMENT_POST posts a journal entry from ABAP: the header goes in DOCUMENTHEADER, the lines in ACCOUNTGL, ACCOUNTRECEIVABLE or ACCOUNTPAYABLE, and the amounts in CURRENCYAMOUNT, linked by ITEMNO_ACC.

  • BAPI_ACC_DOCUMENT_CHECK runs the checks without posting, so call it first.

  • Read the whole RETURN table. A row of type E or A means failure, and you roll back with BAPI_TRANSACTION_ROLLBACK; with no error you commit with BAPI_TRANSACTION_COMMIT.

  • The module never commits itself: that is the SAP LUW rule, and a missing commit is the usual reason for no document.

  • The module is not released for ABAP Cloud. The repository names I_JOURNALENTRYTP as the successor, a wrapper can be generated, and from outside the system the journal entry web services post entries.