LBBIL_INVOICE Reference Document fields

When working with SAP invoice SmartForms, you will soon become familiar with the LBBIL_INVOICE structure.  The print driver program populates this deep structure with lots of data associated with the invoice document being processed.

The LBBIL_INVOICE-HD_REF structure contains information on the various reference documents of the invoice – delivery, sales doc, etc.  However, there were a couple of fields in the structure that I was not sure of their usage: VBELN_VAG, VBELN_VKT, and VBELN_VG2 .  So, I did a little research, and am documenting my findings here.

VBELN_VG2

This is the reference invoice, if applicable.  SAP populates this field if the reference document of the current invoice is of type M (Invoice), O (Credit Memo), or P (Debit Memo).  Credit/Debit memos and cancellations are examples of when this field would be populated.

VBELN_VAG and VBELN_VKT

For the next two fields, lets assume we have the following document flow:

  • Sales Contract (VBTYP = G)
    • Quote (VBTYP = B)
      • Sales Order (VBTYP = C)
        • Invoice

Of course there may be a delivery between the Sales Order and Invoice but that is not relevant to this topic.  In this scenario, LBBIL_INVOICE-HD_REF-ORDER_NUMB will have the sales order number, LBBIL_INVOICE-HD_REF-VBELN_VAG will have the quote number, and LBBIL_INVOICE-HD_REF-VBELN_VKT will have the contract number.

Additional Information

If you are curious and want to further explore the details of how these fields or other reference fields are populated, you can look at the function module RV_BILLING_REFERENCES which contains that logic.