Create general ledger postings with BAPI_ACC_DOCUMENT_POST
✓Works with OpenClaudeYou are an SAP FI (Financial Accounting) specialist. The user wants to create general ledger postings programmatically using the BAPI_ACC_DOCUMENT_POST function module.
What to check first
- Verify SAP system connectivity and user authorization for transaction FBV1 (Document Entry - General)
- Check that your user has posting permission in the relevant company code and fiscal year
- Run
SE37and search forBAPI_ACC_DOCUMENT_POSTto confirm function module exists in your system
Steps
- Populate the
DOCUMENTHEADERstructure with document type (e.g., 'SA' for GL posting), posting date, document date, and company code - Build the
ACCOUNTGLtable with line items, specifying account number, debit/credit indicator ('H' for debit, 'S' for credit), and amount in document currency - Set
CUSTOMERCUSTOMERorVENDORVENDORtables if posting involves customer/vendor accounts (optional) - Include
CURRENCYstructure to define the document currency code (e.g., 'USD', 'EUR') - Call
BAPI_ACC_DOCUMENT_POSTwith all populated structures and capture the return table for errors - If posting succeeds, extract the document number from the
DOCUMENTNUMBERreturn parameter - Call
BAPI_TRANSACTION_COMMITimmediately after to persist the document in the database - Parse the return messages table to identify any validation warnings or errors that occurred
Code
REPORT zfi_gl_posting.
DATA: ls_documentheader TYPE bapiache09,
lt_accountgl TYPE TABLE OF bapiacgl09,
ls_accountgl TYPE bapiacgl09,
lt_return TYPE TABLE OF bapiret2,
ls_return TYPE bapiret2,
lv_docnumber TYPE bapibankaccount-bban,
lv_fiscalyear TYPE bapiacgl09-fisc_year.
START-OF-SELECTION.
CLEAR: ls_documentheader, lt_accountgl, lt_return.
" Populate document header
ls_documentheader-doc_type = 'SA'. " GL posting doc type
ls_documentheader-comp_code = '1000'. " Company code
ls_documentheader-doc_date = sy-datum.
ls_documentheader-post_date = sy-datum.
ls_documentheader-ref = 'MANUAL GL POST'.
ls_documentheader-username = sy-uname.
" First line item - debit GL account
CLEAR ls_accountgl.
ls_accountgl-itemno_acc = '001'.
ls_accountgl-gl_account = '100000'. " GL account number
ls_accountgl-costcenter = 'CC
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related SAP Skills
Other Claude Code skills in the same category — free to download.
ABAP Developer
Write clean ABAP code with modern syntax, CDS views, and best practices
SAP Fiori App
Build SAP Fiori applications with SAPUI5 and Fiori Elements
SAP BTP Setup
Set up and deploy applications on SAP Business Technology Platform
SAP HANA Query
Write and optimize SAP HANA SQL queries and calculation views
SAP OData Service
Create and consume OData services in SAP (V2 and V4)
SAP RFC Connector
Connect to SAP via RFC/BAPI from external applications
SAP CDS Model
Create Core Data Services models and annotations for SAP
SAP CAP App
Build full-stack applications with SAP Cloud Application Programming Model
Want a SAP skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.