SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for SAP HANA and ABAP, HANA Database, SQLScript, SAP UI5, Screen Personas, Web Dynpro, Workflow


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.

SD document category VBTYP value for proforma invoice
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.

DATA lv_proforma_invoice TYPE vbeln.
DATA p_vbfa TYPE vbfa.
DATA ls_vbfa TYPE vbfa.
DATA lt_vbfa TYPE TABLE OF vbfa.

SELECT * FROM vbfa INTO TABLE lt_vbfa
 WHERE vbeln = is_bil_invoice-hd_gen-bil_number "Commercial
 AND vbtyp_v = 'J' . " Delivery document

IF sy-subrc = 0.
 LOOP AT lt_vbfa INTO ls_vbfa.
  SELECT SINGLE * INTO p_vbfa FROM vbfa
   WHERE vbelv = ls_vbfa-vbelv
   AND posnv = ls_vbfa-posnv
   AND vbtyp_v = 'J'
   AND vbtyp_n = 'U'.
  IF gv_customs_inv IS INITIAL.
   lv_proforma_invoice = p_vbfa-vbeln.
  ENDIF.
 ENDLOOP.
ENDIF.
Code

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.



SAP HANA and ABAP

Install SAP Free
CRM Companies List
Web Based CRM Software


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.