This sample code will delete a customer address following :Delete Customer Address in SAP.
It uses the standard function ADDR_DELETE.
ADDR_MEMORY_SAVE and ADDR_MEMORY_CLEAR are called at the end to commit modification and clean the address buffer.
Alternative Delete Address
The same program can be easily modified to update. The only thing to modify is the Reference to Address
ls_reference-appl_table = 'ADRC'. ls_reference-appl_field = 'ADDRNUMBER'.
The complete list fo Reference can be found in the table
TSADRV: Where-used list addresses: Object types, DDIC information.
here few examples of Reference can be used:
[table tablesorter=”o” class=”table table-border”]
Description,Application Table Name, Application Table Field Name
Create/Update/Delete Vendor Address,LFA1, ADRNR
Create/Update/Delete Customer Address,KNA1, ADRNR
Create/Update/Delete Contact Person Address,KNVK,ADRND
[/table]
Delete Customer Address Sample ABAP Code
Here the full ABAP source code how to delete Customer Address in SAP :
"*******************************************************"
" Delete Customer Address
" Input:
" -> IV_KUNNR TYPE KUNNR
" -> IV_ADDRESS_GROUP TYPE AD_GROUP
" Output:
" <- ET_RETURN TYPE BAPIRETTAB
" <- EV_SUBRC TYPE SYSUBRC
"*******************************************************"
DATA: lv_kunnr TYPE kunnr.
DATA: lv_addrnumber TYPE ad_addrnum.
DATA: ls_reference TYPE addr_ref.
" Format Customer Number
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = iv_kunnr
IMPORTING
output = lv_kunnr.
" Build Reference to Address
ls_reference-appl_table = 'ADRC'.
ls_reference-appl_field = 'ADDRNUMBER'.
" CONCATENATE sy-mandt lv_addrnumber INTO ls_reference-appl_key.
ls_reference-addr_group = iv_address_group.
ls_reference-owner = 'X'.
" Deletion of an address without dialog
CALL FUNCTION 'ADDR_DELETE'
EXPORTING
address_number = lv_addrnumber
address_reference = ls_reference
EXCEPTIONS
address_not_exist = 1
parameter_error = 2
internal_error = 3
reference_not_exist = 4
OTHERS = 5.
IF sy-subrc NE 0 .
APPEND INITIAL LINE TO et_return ASSIGNING <fs_return>.
CALL FUNCTION 'BALW_BAPIRETURN_GET2'
EXPORTING
type = sy-msgty
cl = sy-msgid
number = sy-msgno
par1 = sy-msgv1
par2 = sy-msgv2
par3 = sy-msgv3
par4 = sy-msgv4
IMPORTING
return = <fs_return>.
ev_subrc = 1.
RETURN.
ELSE.
" Saves all address data from local memory to the database
CALL FUNCTION 'ADDR_MEMORY_SAVE'.
COMMIT WORK.
" Clear Address Memory
CALL FUNCTION 'ADDR_MEMORY_CLEAR'.
ENDIF.
For more about How SAP handles Address check this help.sap link.
Read also SAP KNVV: Customer Master Sales Data