Full ABAP Program How to Delete Customer Address in SAP

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:

Related Post
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

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

Share
Published by
John
Tags: Address

Recent Posts

The Most Important SAP ISU Tables

SAP ISU Tables for Technical master data, for Billing Master Data, Billing and invoicing Tables?…

December 22, 2020

SAP Fiori 3 UX and Design of SAP Fiori Apps for SAP S/4HANA, SAP TechEd Lecture

SAP Fiori 3 UX and Design of SAP Fiori Apps for SAP S/4HANA, SAP TechEd…

November 18, 2020

The Main SAP Dunning Transaction Codes

Dunning is the business practice of informing a customer of past due payment. Dunning letters…

November 28, 2019

SAP Accounts Payable Tcodes & Accounts Receivable Tcodes ( SAP AP Tcodes & SAP AR Tcodes)

SAP AP Tcodes & SAP AR Tcodes: House Banks Tcodes, Advance Payments or Down Payments,…

August 1, 2019

The Most Important SAP Payment Terms Tables (ZTERM, Text…)

What are the main SAP Payment Terms Tables ? What are the related Tables in…

October 21, 2018

The most Important SAP Work Center Tables in SAP PP

Work center consists of master data related to routing of products. It contains data related…

October 21, 2018