SAP IDoc INVOIC02 to XRechnung and Peppol: which segment feeds which field
Your SAP system already emits the invoice as an INVOIC02 IDoc. A segment-by-segment mapping to EN 16931 — E1EDKA1 partner roles, E1EDK02 references, E1EDK04 VAT, E1EDS01 totals — the six places where it goes wrong, and how to turn the IDoc into a validated XRechnung or Peppol invoice.
If your invoices come out of SAP ECC or S/4HANA on-premise, the e-invoicing mandate does not ask you for new data. Billing already writes every invoice as an IDoc of type INVOIC01 or INVOIC02 whenever output is set up for a customer — the same message that has fed EDI converters since the nineties. Party names, VAT numbers, references, lines, tax per rate, totals: it is all there.
What an IDoc is not is an e-invoice. XRechnung, Peppol BIS and the other EN 16931 formats want named business terms: BT-1 invoice number, BT-13 purchase order reference, BT-31 seller VAT identifier. An IDoc has generic segments that repeat, and a qualifier that says what each repetition means. The whole job is reading the qualifiers correctly.
The header segments
- E1EDK01 — document header: invoice number (BELNR), document currency (CURCY), local currency and exchange rate (HWAER, WKURS).
- E1EDKA1 — one segment per partner, told apart by the role in PARVW. RS is the invoicing party, so the seller. RE, AG and RG are bill-to, sold-to and payer, the buyer side. WE is the ship-to address.
- E1EDK02 — document references by qualifier. 001 is the customer’s purchase order, 002 the sales order, 009 the invoice’s own number, 012 the delivery note.
- E1EDK03 — dates by qualifier, such as the invoice date and the due date.
- E1EDK04 — VAT: one segment per tax rate, with the rate and the tax amount.
- E1EDK05 — header conditions: discounts, surcharges, freight.
- E1EDK18 — terms of payment. Qualifiers 001 and 002 are the two cash-discount terms (percentage and days), 003 is the net due period.
- E1EDK28 — bank details: IBAN and BIC of the account to be paid.
- E1EDKT1 / E1EDKT2 — header texts.
- E1EDS01 — totals by SUMID: 010 is the net invoice value, 005 the tax total, 011 the amount invoiced.
The line segments
- E1EDP01 — the invoice line: quantity (MENGE) and unit (MENEE).
- E1EDP02 — line references, such as the purchase order number and its item.
- E1EDP19 — item identification by qualifier: 001 the customer’s material number, 002 your own, 003 the EAN / GTIN.
- E1EDP26 — line amounts by qualifier: net value, gross value, price, tax.
- E1EDP05 — line conditions: discounts and surcharges for that item.
- E1EDP04 — tax on the line.
What lands where in the e-invoice
- Seller (BG-4) — the E1EDKA1 with role RS: name, address, VAT number.
- Buyer (BG-7) — the bill-to / sold-to partner. The Peppol address of each party is not in an IDoc at all; it is derived from the VAT number.
- Delivery address (BG-15) — the E1EDKA1 with role WE.
- Purchase order reference (BT-13) and buyer reference (BT-10) — E1EDK02 qualifier 001. Sales order reference (BT-14) — qualifier 002.
- Payment terms (BT-20) — E1EDK18. Payment account (BT-84, BT-86) — E1EDK28.
- VAT breakdown (BG-23) — E1EDK04, one group per rate.
- Document-level allowances and charges (BG-20, BG-21) — E1EDK05.
- Totals (BG-22) — E1EDS01.
- Lines (BG-25) — E1EDP01 with its E1EDP26 amounts, E1EDP19 item numbers and E1EDP05 conditions.
Six places where IDoc projects lose weeks
1. The reference qualifiers. E1EDK02 with qualifier 009 carries the billing document’s own number. Qualifier 001 is the customer’s purchase order. Mappings that mix these up put the sales order or the invoice number into the purchase-order field. The XML still validates. Then the customer’s three-way match fails on every invoice, and a German public buyer rejects it because the buyer reference is wrong.
2. The ship-to is not the buyer. WE is where the goods went. Taking the buyer from WE sends the invoice to a warehouse’s name and, on Peppol, sometimes to the wrong legal entity’s inbox.
3. A down payment is not a discount. A down-payment condition in E1EDK05 reduces what is still to be paid. It does not reduce the invoice total. Map it as an allowance and the sums stop adding up, and rules like BR-CO-10 fail for reasons nobody can see in the document. It belongs in the paid amount (BT-113).
4. Units are SAP keys, not standard codes. ST, KAR and STD mean something in your system. An e-invoice needs UN/ECE Recommendation 20 codes: H87 for a piece, XCT for a carton, HUR for an hour. A unit that cannot be translated should stop the invoice — not go out as “each”.
5. The terms-of-payment key means nothing outside your system. ZTERM is a key from your own customising. ZB01 can be “14 days 2 %, 30 days net” in one client and something else in the next. The readable terms are in E1EDK18.
6. The totals have to be SAP’s totals. If a converter recalculates VAT line by line and comes out one cent away from what SAP posted, the customer receives an invoice that differs from your ledger. Check SAP’s figures against the lines, and when they reconcile, send SAP’s figures.
From IDoc to a validated e-invoice
FiscalSpan reads the INVOIC01/02 IDoc as XML — the export of SAP ECC, S/4HANA on-premise and private cloud — and returns the format you ask for. Send the IDoc as it leaves your system:
curl -X POST "https://api.fiscalspan.com/v1/erp/sap?profile=xrechnung-3" \
-H "X-API-Key: ek_live_..." \
-H "Content-Type: application/json" \
-d '{"idocXml": "<INVOIC02><IDOC>...</IDOC></INVOIC02>"}'Replace the profile with peppol-bis-3, nlcius or facturx-en16931 and the same IDoc becomes a Belgian Peppol invoice, a Dutch one or a ZUGFeRD file. A few things happen on the way that are worth knowing:
- Partners are resolved by role, and the ship-to is only ever used as the delivery address.
- Every total in E1EDS01 and every VAT amount in E1EDK04 is reconciled against the lines. If they agree, the document carries SAP’s own figures, so it matches your ledger to the cent. If they do not, you get an error that names the SUMID — not a silently “corrected” invoice.
- A down payment goes to the paid amount, not to the allowances.
- An unknown unit, a withdrawn currency or an unreadable number is refused with the segment and field named.
- The result is validated against the XSD and the official rules of the target format before it is returned.
And when a rule does fail, the diagnostics point back into the IDoc: the segment, the qualifier and the partner role the value came from, and whether the fix belongs in master data, in the document or in the mapping.
How diagnostics trace a rule back to the ERP fieldOne limit, stated plainly: an IDoc is the format of the ABAP stack. S/4HANA public cloud, Business ByDesign and Business One export different formats. Business One has its own connector; for the others, talk to us first.
Try a sample in the sandboxBefore you start
- Pull five real INVOIC IDocs from WE02: a plain invoice, a credit note, one with a discount, one with a down payment, one in a foreign currency.
- Check that every customer has the VAT number in master data. It is the most common missing field and the one Peppol routing depends on.
- Check which E1EDK02 qualifiers your output actually fills. Custom output routines differ.
- Decide the target formats per country: XRechnung or ZUGFeRD for Germany, Peppol BIS for Belgium, NLCIUS for the Netherlands.
If Germany is why you are reading this: the issuing obligation starts on 1 January 2027 for businesses above €800,000 turnover.
Germany, 1 January 2027: the €800,000 test and the December trapSAP, S/4HANA and IDoc are trademarks of SAP SE. FiscalSpan is not affiliated with SAP.
Read the API docs