The introduction of the National e-Invoicing System (KSeF) in Poland is associated with a revolution in the approach to electronic invoicing and data exchange between taxpayers and the tax administration. While much attention is focused on sending invoices to KSeF, considerably less is devoted to the subject of handling incoming invoices. Incoming invoices from KSeF in SAP — for companies operating on SAP systems, effective automation of their receipt and processing is key to cost optimization, reducing the risk of errors, and ensuring compliance with new regulations.
In this article, we present a practical approach to integrating KSeF with SAP for incoming invoices, analyze the solution architecture, describe automation possibilities, and highlight best practices worth implementing.
Incoming invoices from KSeF in SAP. Architecture of SAP integration with KSeF for incoming invoices
From a technical perspective, the process of receiving purchase invoices from KSeF into SAP is based on REST API communication between the ERP system and the Ministry of Finance’s gateway. Secure authorization using access tokens generated in the KSeF application is crucial, as it allows SAP to retrieve XML documents and metadata.
In the approach presented by HAERGI, integration takes place entirely within SAP, without the need for external intermediary servers. The solution is based on ABAP, which ensures:
- high infrastructural independence,
- the ability to independently diagnose and correct errors,
- no need to transmit data outside of SAP,
- a simplified model for managing certificates and tokens.
Incoming invoices from KSeF in SAP – retrieval and classification mechanism
Document retrieval is carried out based on a query to the KSeF API using a certificate and a token linked to a specific tax ID (NIP). Invoices are imported into SAP and classified in a dedicated interface according to status:
- New (awaiting processing),
- Pre-booked (awaiting validation),
- Booked (processed and integrated with accounting documents).
The process can be fully automated (background job) or partially interactive – depending on the organization’s preferences.
Incoming invoices from KSeF in SAP – automatic assignment of operators and posting
The system enables automatic assignment of responsible operators based on:
- contractor data (NIP),
- invoice amount,
- line item content,
- fixed asset, project, or cost center.
Posting can be carried out based on predefined rules configured per company. For more complex scenarios, the system can trigger an approval workflow or send data to external tools (e.g., document circulation systems).
Extension possibilities and solution flexibility
In HAERGI’s product, extension points (BAdI) play a key role, allowing the logic of data mapping and posting to be tailored to specific companies and data sources. Each client receives a template implementation that is then adjusted during deployment to meet individual needs:
- handling of various input formats (e.g., external warehouse systems, invoices from XML files),
- different posting paths and data sources (e.g., from SAP MM or FI),
- the ability to integrate with other enterprise systems (e.g., workflow, BI, data warehouses).
Verification, visualization, and error management
Each invoice, once retrieved, can be visualized in SAP based on the FA(3) structure, including header data, line items, and metadata. The system enables:
- checking the invoice processing status (whether it is correct, approved),
- adding notes and comments to the invoice,
- viewing processing logs and detailed errors,
- automatic email notifications about errors, required approvals, or new invoices.
Further processing and inter-system integration
After booking or preliminary approval, the invoice can be forwarded:
- to an external financial-accounting system,
- to a document archive,
- for reporting purposes (e.g., SAP BW),
- for audit or control (e.g., BI tools).
Integration formats include XML, JSON, RFC, IDOC, SOAP/REST API, and saving to an FTP/SFTP server. Depending on the organization’s IT maturity, it is possible to implement full automation or remain with semi-automated solutions.
Incoming invoices from KSeF in SAP. Implementation recommendations and best practices
- Role and permission planning: Already at the design stage, it’s worth planning who has access to documents at each stage of the process and what editing capabilities they have.
- Integration tests with KSeF (demo/production): Testing in a demo environment allows assessment of data completeness and identification of errors without risk to real operations.
- Logging and diagnostics: Ensure clear processing logs and integration with email notifications.
- Modularity and scalability: Using extensions (BAdI) provides the ability to develop the solution as organizational needs and regulations evolve.
- User training: Although the interface is intuitive, training for accounting, controlling, and IT departments accelerates system adoption.
Integration of SAP with the National e-Invoicing System for incoming invoices is not just a regulatory obligation—it’s also a significant opportunity to streamline accounting processes. Thanks to HAERGI’s solution, it is possible to implement a fully internal, secure, and flexible solution that supports automation, reduces operational risks, and increases data transparency.
Well-designed processing of invoices from KSeF in SAP provides an organizational advantage – shortens document turnaround time, facilitates controlling, and paves the way for further digitalization of the finance domain.


