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.
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.