Get Proforma Invoice from Commercial Invoice in ABAP
If proforma invoice is used in SAP system, it is a common requirement to print proforma invoice number for given commercial invoice number like the case on Sales invoice outputs, SAP Smartform output. It is best practice to use SAP sales document flow table or document flow function modules to find proforma invoice for commercial invoice. This ABAP tutorial shows ABAP codes to manage this task.
If ABAP developers check the document category VBTYP value range, they will see that for commercial invoices M is used. On the other hand for pro-forma invoices U is used on VBTYP data values. So in VBRK ABAP table, developers can distinguish proforma and commercial invoices using the document category types.
SAP SD document category VBTYP value for proforma invoice and commercial invoice
Let's now search Sales Document Flow ABAP table and use document category types to find a preceeding proforma invoice with VBTYP value equal to U for a given commercial invoice. Here is sample ABAP codes that query VBFA Sales Document Flow SAP table to find the related proforma invoice document number for a given commercial invoice.
ABAP programmers will realize that first from sales document flow I find out the delivery documents. Then from delivery document, again using document flow I find the related proforma invoice document. So the above ABAP code works in two steps to get the proforma invoice for a given sales invoice number.