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 SAP ABAP Programming and HANA Database Tutorials
Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Windows, Windows Phone, SAP and ABAP, like SAP UI5, Screen Personas, etc.




Install SAP Free


Find Accounting Document Number From Invoice Number in Smartforms


While preparing an SAP Smartforms document for printing SAP Invoice documents, I had the requirement from our customer to print FI document number on the document instead of SAP Sales document number (VBAK-VBELN field).

The FI document number can be seen on SAP Invoice document flow screen.
But to get this data using ABAP code within SAP Smartforms required me to deal with ABAP BKPF table.
ABAP BKPF table is for Accounting Document Header data.
SAP BKPF table has the linking field XBLNR which is Reference Document Number data in ABAP element type XBLNR1 and CHAR 16 data type.





Using SAP Smartforms for Output Management has the advantage of using ABAP codes within the Smartform document.
Here is the ABAP code, I used to fetch FI Accounting document number in Initialization code tab of the SAP Smartform for Invoice.

DATA ls_bkpf TYPE BKPF.
DATA lt_bkpf TYPE TABLE OF BKPF.

SELECT * FROM BKPF INTO TABLE lt_bkpf
  WHERE xblnr = IS_BIL_INVOICE-HD_GEN-bil_number.

LOOP AT lt_bkpf INTO ls_bkpf WHERE BUKRS = IS_BIL_INVOICE-HD_ORG-COMP_CODE.
  gv_belnr = ls_bkpf-belnr.
ENDLOOP.

It is important to read data which has Company code equal to IS_BIL_INVOICE-HD_ORG-COMP_CODE.
BKPF table may have more than one record with same reference document number XBLNR.
But BKPF has only one row for each company code. So while selecting data, BUKRS is a criteria field.
Within SAP Smart Form, company code is stored at IS_BIL_INVOICE-HD_ORG-COMP_CODE field.

After BELNR field (Accounting Document Number) is read and stored at gv_belnr global variable, you can use this global variable in any where of the SAP Smartform Invoice output document.
This is a solution I used for converting Invoice number to FI number.







SAP Resources

SAP Tutorial

SAP Forums

SAP Tools

SAP Transaction Codes Table








Copyright © 2004 - 2018 Eralper YILMAZ. All rights reserved.
Community Server by Telligent Systems