Hi Fellow ABAP members ,
Greetings for the day ahead .
I have a Requirement to Copy PO no & Date Fields of all line items in creation of Return Order ( VA01 ) from Original Order .The original order may have line items with different PO numbers and Dates .
1. Can this be achieved using VOFM routines and copying them and adding code there ? Which form routine to be used and what logic has to be added ? I tried few routines but may be i am using the incorrect routines . Can VOFM -> ORDERS -> 102 help ?
2. I also tried writing logic in USEREXIT_MOVE_FIELD_TO_VBKD as picking the sales order number from CVBRP-VBELN & CVBRP-POSNR from VBRP and then passing it in VBKD to get BSTKD BSTDK po number and po date fields . This brings the line items different PO numbers but doesnot bring the PO no of header which is with blank POSNR in VBKD .
How to bring the header value of PO correct with date OR some vofm routine option has to be used ? .Screenshots attached
Code snippet as follows :
IF VBAK-VBTYP = 'H' . for return order
TYPES : BEGIN OF TY_VBRP ,
AUBEL LIKE VBRP-AUBEL , " sales document number
POSNR LIKE VBRP-POSNR , " sales document item
END OF TY_VBRP .
DATA : LWA_VBRP TYPE TY_VBRP .
TYPES : BEGIN OF TY_VBKD ,
BSTKD LIKE VBKD-BSTKD , " Customer purchase order number
BSTDK LIKE VBKD-BSTDK , " Customer purchase order dat
END OF TY_VBKD .
DATA : LWA_VBKD TYPE TY_VBKD .
IF CVBRP-VBELN IS NOT INITIAL AND CVBRP-POSNR IS NOT INITIAL .
" Fetching data from VBRP by passing billing document and billing item to get sales document number & sales document item
SELECT SINGLE AUBEL POSNR FROM VBRP INTO LWA_VBRP
WHERE VBELN = CVBRP-VBELN
AND POSNR = CVBRP-POSNR .
IF SY-SUBRC = 0 .
" Fetching data from VBKD by passing sales document and sales document item
SELECT SINGLE BSTKD BSTDK FROM VBKD INTO LWA_VBKD
WHERE VBELN = LWA_VBRP-AUBEL
AND POSNR = LWA_VBRP-POSNR .
IF SY-SUBRC = 0 . " in case value is obtained
VBKD-BSTKD = LWA_VBKD-BSTKD . " Customer purchase order number
VBKD-BSTDK = LWA_VBKD-BSTDK . " Customer purchase order date
ELSE .
*************
" Fetching data from VBKD ( if value not found in earlier query then fetch by sales document only )
SELECT SINGLE BSTKD BSTDK FROM VBKD INTO LWA_VBKD
WHERE VBELN = LWA_VBRP-AUBEL AND
POSNR = '000000' .
IF SY-SUBRC = 0 .
VBKD-BSTKD = LWA_VBKD-BSTKD . " Customer purchase order number
VBKD-BSTDK = LWA_VBKD-BSTDK . " Customer purchase order date
ENDIF .
*************
ENDIF .
ENDIF .
ENDIF .
CLEAR : CVBRP-POSNR .
ENDIF .
The correct value in above screenshot should be PO # OTC_158_01 but it always displays PO # OTC_158_02 which is not as per Requirement . The desired output has of original order is as follows : VA03 screenshot below :
Kindly guide Plz .
Thanks in advance .
Rgds ,
Dave