This code returns the Delivery Address for a Purchase Order. It can be used in Print forms such as SAP Script and Smart Forms. It can also be used to populate custom IDoc segments with fields from the Delivery Address of the PO (Some of the standard IDoc types may not have complete delivery address)
FUNCTION z_inv_po_delivery_address.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(IM_EBELN) TYPE EBELN
*" REFERENCE(IM_EBELP) TYPE EBELP
*" CHANGING
*" REFERENCE(CT_DEL_ADDRESS) TYPE BAPIMEPOADDRDELIVERY_TP
*"----------------------------------------------------------------------
* This code returns the Delivery Address for a Purchase Order. It can be used
* in Print forms such as SAP Script and Smart Forms. It can also be used to
* populate custom IDoc segments with fields from the Delivery Address of the
* PO (Some of the standard IDoc types may not have complete delivery address)
DATA ls_cmmda TYPE cmmda.
DATA ls_cmmda2 TYPE cmmda.
DATA ls_ekpo TYPE ekpo.
DATA lt_cmmda TYPE TABLE OF cmmda.
DATA lt_del_address TYPE TABLE OF bapimepoaddrdelivery.
REFRESH lt_cmmda.
* Select the PO Item data (all fields need to be selected here!)
CLEAR ls_ekpo.
SELECT SINGLE * INTO ls_ekpo FROM ekpo
WHERE ebeln = im_ebeln
AND ebelp = im_ebelp.
* Populate the relevant global parameters from the
* function group MMDA
REFRESH lt_cmmda.
CLEAR ls_cmmda.
MOVE-CORRESPONDING ls_ekpo TO ls_cmmda.
APPEND ls_cmmda TO lt_cmmda.
CALL FUNCTION 'MM_DELIVERY_ADDRESS_INIT'
* EXPORTING
* IM_NO_REFRESH = ' '
TABLES
it_cmmda = lt_cmmda
.
* Get the address number and/or more details required to
* determine the delivery address
CALL FUNCTION 'MM_DELIVERY_ADDRESS_FOR_BAPI'
EXPORTING
im_ebeln = im_ebeln
im_ebelp = im_ebelp
IMPORTING
ex_cmmda = ls_cmmda2.
REFRESH lt_cmmda.
APPEND ls_cmmda2 TO lt_cmmda.
* Now call the standard subroutine from function group 2012
* to get the exact delivery address
* This subroutine is also used in function module BAPI_PO_GETDETAIL1
REFRESH lt_del_address.
PERFORM move_item_addr_out IN PROGRAM sapl2012
TABLES lt_cmmda lt_del_address.
* Pass the delivery address to the changing parameter
REFRESH ct_del_address.
APPEND LINES OF lt_del_address TO ct_del_address.
ENDFUNCTION.
Thank You Thank You Thank You Thank You Thank You Thank You so much for posting this code. It was a life saver and works like a charm. As a ABAP begginer I really appreciate you posting this.
ReplyDeleteIt's amazing designed for me to have a web page, which is helpful for my know-how. thanks admin
ReplyDeleteHave a look at my web-site :: reviewed quantrim