SAP Invoice IDoc INVOIC02 – Structure, User-Exit and BADI

Idoc INVOIC02: This article will introduce you to outbound IDoc for Invoice/Billing document in SAP.

It will cover the IDoc Invoic02 structures, XML Schema, Enhancement for INVOICE Idoc and ABAP Code to generate INVOICE Idoc with BAPI

  • Idoc INVOIC02 Structure
  • User Exit and BADI for Idoc INVOIC02
  • Generate Invoice IDoc with BAPI

Idoc INVOIC02 Structure

SAP INVOICE IDoc Basic Type Structure

First at all, let’s detail the main segments of INVOIC02 :

  • E1EDK01 for IDoc: Document header general data
  • E1EDKA1 for IDoc: Document Header Partner Information
  • E1EDKT1 for IDoc: Document Header Text Identification
  • E1EDKT2 for IDoc: Document Header Texts Lines
  • E1EDK14 for IDoc: Document Header Organizational Data
  • E1EDP01 for IDoc: Document Item General Data
Invoic02 IDoc Basic Type

The full INVOIC02 Basic Type is:

In Order to go further, you can check the full documentation on how to manage Inbound Processing of IDocs Received.

XML Schema for Invoice IDoc

This link contains the Idoc INVOIC02 XML Schema.( For obvious security reason, I put the document in Zipped format).

User Exit and BADI for Idoc INVOIC02

User Exit for SAP Invoice Idoc

EXIT_SAPLVEDF_001 (ZXEDFU01)

This User Exit offers to make additional Control Data IDoc_Output_Invoice.
So the parameters of this User Exist are:

User Exit EXIT_SAPLVEDF_002 (ZXEDFU02)

This User Exist allows Customer Enhancement in Data Segments when generating Billing Document Output.

It called when generating the INVOIC02 Idoc SEGMENT BY SEGMENT.

The following Code is an example of ABAP implementation of the user exit ZXEDFU02

BADI for SAP Invoice Idoc INVOICE02

SD_INVOICE_IDOC_OUTPUT_INT: Internal BADI for IDOC output processing

Hence, This BADI has 4 methods:

  • CONTROL_RECORD_OUT_PREPARE: check and modify EDIDD ( Idoc Data Table )
  • IDOC_DATA_APPEND: allows to add more data segment for IDoc
  • INVOICE_READ helps read the SAP Invoice.
  • PACKAGING_DATA_READ reads the packaging Data.

SAP Invoice Tables

In order to fill the enhancement of INVOIC02, you can rely on the most important tables for SAP Invoice

  • VBRP,Billing Document: Item Data
  • VBRK,Billing Document: Header Data
  • VBFK,Invoice: header Data
  • VBFP,Invoice: Item Data
  • RBKP,Document Header: Invoice Receipt

Generate Invoice IDoc with BAPI

With the following ABAP Program Snippet, you can generate an Idoc INVOIC.INVOIC02 in less than a couple of minutes ( between creating of ABAP program/function, copy/paste the activation ).

The main BAPI used to generate an outbound Idoc INVOIC02 for Invoice is the BAPI IDOC_OUTPUT_INVOIC.

Also This BAPI will fill the prepare the Idoc and fill the segments required for INVOIC02 Idoc ( and even extension if user exist or BADI are implemented ).

To explain the following ABAP Coden here the steps:

  1. Generate EDIDD tables for INVOICES with IDOC_OUTPUT_INVOIC
  2. Distribute the IDoc, So a IDoc number is generated with standard BAPI MASTER_IDOC_DISTRIBUTE
  3. If no error occurs when creating the IDoc, we call a commit work with both DB_COMMIT BAPI And COMMIT WORK.