- March 24, 2026
- Kishore Thutaram
-
- 0
Data Transfer to Credit Memo from the Original Invoice or any Sales doc. by using routine
Business requirement: Update the billing date from the original invoice to the credit memo during creation.
Steps: VOFM->Data Transfer->Billing documents
Create a new routine with the 900 series
Assign the routine at VTFL->Item level->Data VBRK/VBRP.
Implement the code below in the routine
"add standard routine if it is needed
PERFORM daten_kopieren_007.
CONSTANTS : lc_m TYPE vbtypl_v VALUE 'M',
lc_h TYPE vbtypl_v VALUE 'H'.
*--* Credit memo - With reference to Invoice
*--* Fetch Preceeding Inv document based on delivery and its item
SELECT SINGLE vbelv FROM vbfa INTO @DATA(lv_inv) WHERE vbeln = @lips-vbeln "Del.
AND posnn = @lips-posnr "Del Item
AND vbtyp_v = @lc_m "preceding doc cat. - Inv
AND stufe = 1. " same level
*--*Credit Memo - With reference to Order
IF sy-subrc NE 0.
SELECT SINGLE vbelv,posnv FROM vbfa INTO ( @DATA(lv_ret_ord),@DATA(lv_ret_item) ) WHERE vbeln = @lips-vbeln "Del.
AND posnn = @lips-posnr "Del Item
AND vbtyp_v = @lc_h. "preceeding doc cat. - Return
IF sy-subrc EQ 0.
"Fetch Original Sales Order
SELECT SINGLE vgbel, vgpos FROM vbap INTO ( @DATA(lv_sales_ord), @DATA(lv_sales_item) ) WHERE vbeln = @lv_ret_ord AND posnr = @lv_ret_item.
*--* Fetch Original Invoice doc.
IF sy-subrc EQ 0.
SELECT SINGLE vbeln FROM vbfa INTO @lv_inv WHERE vbelv = @lv_sales_ord "Original Sales doc
AND posnv = @lv_sales_item " Item
AND vbtyp_n = @lc_m. " Doc category M - Invoice
ENDIF.
ENDIF.
ENDIF.
*--*Fetch Original Inv. Billing date and update
IF lv_inv IS NOT INITIAL.
SELECT SINGLE fkdat FROM vbrk INTO @vbrk-fkdat WHERE vbeln = @lv_inv.
ENDIF.






























