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
-
Journal Entries, Document Types and Posting Keys: what a journal entry, a document type and a line item are, because the module takes exactly these as input.
-
RFC, BAPIs and IDocs: what a BAPI is and why it reports problems in a return table instead of raising an exception.
-
SAP LUW, Update Tasks and Commit: why a call alone changes nothing permanent until a commit.
-
Accounting Basics: debit, credit and why the amounts of an entry add up to zero.
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 |
|---|---|---|
|
|
The header of the entry: company code |
|
|
The G/L account lines. Each line has a line number |
|
|
The customer lines: |
|
|
The supplier lines: |
|
|
The amounts. One row per line and currency type: the line number |
|
|
The messages. Each row has |
|
The reference key of the new document. |
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
-
Fill the header, the line tables and the amount table in the program. Fill
ITEMNO_ACCwith the same value in a line and its amount row. -
Call BAPI_ACC_DOCUMENT_CHECK with the same data. If the return table holds a message of type
EorA, stop; nothing was posted and you have lost nothing. -
Call BAPI_ACC_DOCUMENT_POST. Read
RETURNagain, because the check cannot know everything the posting finds, for example a lock held by another user. -
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
SAis 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_TYPEis 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
RETURNtable, 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 callCOMMIT WORKinside 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
SorIis information and does not stop anything. After a successful postingOBJ_KEYholds the key of the document. -
A row of type
Wis a warning. The posting may still have succeeded; log it. -
A row of type
EorAis a failure. The ALE documentation states the convention for BAPIs: anEleads to a rollback, with no error to a commit. Do not commit if you find one. -
The fields
IDandNUMBERare 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,ROWandFIELDname where the problem is, for example the tableACCOUNTGL, row 2 and the fieldGL_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 |
The amounts do not balance |
The sum of |
An amount row is rejected |
Its |
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 |
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_JournalEntryTPis 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_PROXYand the SAP-samples projecttier2-rfc-proxygenerate 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 inACCOUNTGL,ACCOUNTRECEIVABLEorACCOUNTPAYABLE, and the amounts inCURRENCYAMOUNT, linked byITEMNO_ACC. -
BAPI_ACC_DOCUMENT_CHECK runs the checks without posting, so call it first.
-
Read the whole
RETURNtable. A row of typeEorAmeans 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_JOURNALENTRYTPas the successor, a wrapper can be generated, and from outside the system the journal entry web services post entries.
References
-
node-rfc-samples: interface of BAPI_ACC_DOCUMENT_POST (SAP-archive, read-only)
-
SAP-samples/tier2-rfc-proxy: generator for wrappers of RFC function modules
-
Journal Entry - Post (Synchronous) (SAP Help Portal, Public Edition)
-
Journal Entry - Post (Asynchronous) (SAP Help Portal, Public Edition)
-
SAP S/4HANA Financial Accounting Configuration, 2nd edition (Apress)