cancel
Showing results for 
Search instead for 
Did you mean: 

Function module for deleting customer street address: XD02

sanjay_deshpande4
Participant
0 Kudos

Dear All, I am having a requirement to Delete customer street address: XD02(from KNA1).I searched for function module for the same but couldn't find it. Also these street address Fields in XD02 are suppressed. SO cant delete the Street address using BDC or LSMW by passing Space .

Only input I have is Customer number and account number.

I will be thankful for kindly helping with function module or solution for above requirement.

Or Kindly provide alternative tcode for XD02 where all the data will be visible and BDC/LSMW can be written.

Regards.

Accepted Solutions (0)

Answers (3)

Answers (3)

Lakshmipathi
Active Contributor

Did you try with MASS ?

raymond_giuseppi
Active Contributor
0 Kudos

Did you try following methods

  • CMD_EI_API_EXTRACT=>GET_DATA
  • CMD_EI_API=>MAINTAIN_BAPI

NB: Also you mentionned BDC/LSMW, during SHDB did you check the 'use central address management' box?

sanjay_deshpande4
Participant
0 Kudos

Dear Raymond, Thanks for replying. I tried the method BAPI_MAINTAIN and Maintain.

The value KNA1-PSTLZ = 999999 not getting deleted.

Am I correct with below code? Or some thing missed. Kindly guide.

The method doesnt return any error message.


  WA_ADDRESS-POSTL_COD1 =  '999999'.    "”COMNT
WA_ADDRESSX-POSTL_COD1 = 'X'.
  WA_CUSTOMER-CENTRAL_DATA-ADDRESS-POSTAL-DATA = WA_ADDRESS.

WA_CUSTOMER-CENTRAL_DATA-ADDRESS-POSTAL-DATAX = WA_ADDRESSX.

WA_CUSTOMER-CENTRAL_DATA-ADDRESS-task = 'D'.
  WA_CUSTOMER-HEADER-OBJECT_INSTANCE-KUNNR  = '0000108704'.

WA_CUSTOMER-HEADER-OBJECT_TASK = 'U'.

* WA_CUSTOMER-COMPANY_DATA = WA_COMPANY_CODE.

APPEND WA_CUSTOMER TO WA_CUSTOMERS-CUSTOMERS.

CALL METHOD CMD_EI_API=>INITIALIZE.
CALL METHOD CMD_EI_API=>LOCK( IV_KUNNR = WA_CUSTOMER-HEADER-OBJECT_INSTANCE-KUNNR ).
CALL METHOD CMD_EI_API=>MAINTAIN_BAPI
EXPORTING
* IV_TEST_RUN = ''
* IV_COLLECT_MESSAGES = 'X'
IS_MASTER_DATA = WA_CUSTOMERS
IMPORTING
ES_MASTER_DATA_CORRECT = WA_CORRECT
ES_MESSAGE_CORRECT = WA_MES_CORRECT
ES_MASTER_DATA_DEFECTIVE = WA_DEFECTIVE
ES_MESSAGE_DEFECTIVE = WA_MES_ERROR.

COMMIT WORK.
CALL METHOD CMD_EI_API=>UNLOCK( IV_KUNNR = WA_CUSTOMER-HEADER-OBJECT_INSTANCE-KUNNR ).
raymond_giuseppi
Active Contributor
0 Kudos

Replace

WA_ADDRESS-POSTL_COD1 =  '999999'. 
WA_CUSTOMER-CENTRAL_DATA-ADDRESS-task = 'D'.

with

WA_ADDRESS-POSTL_COD1 =  '      '.
WA_CUSTOMER-CENTRAL_DATA-ADDRESS-task = 'D'.

Also from you original post, shouldn't you use STREET and STREET_NO fields and not POSTL_COD1 ?

sanjay_deshpande4
Participant
0 Kudos

I tried your suggestion.

Got error message: E AM 219 Enter a postal code

WA_ADDRESS-POSTL_COD1 =  '          '.  
WA_ADDRESSX-POSTL_COD1 = 'X'.

Kept WA_CUSTOMER-CENTRAL_DATA-ADDRESS-task = 'D' as it is.

Also, street Address has several fields-for verifying whether above method works have tried POSTL_COD1 field which is one of the fields in street address.

Kindly help further.

raymond_giuseppi
Active Contributor
0 Kudos

Look at your Customizing, for the mandatory fields you have to provide a value, even a dummy one. Are you anonymizing data in a test environment (privacy, GDPR)?

sanjay_deshpande4
Participant
0 Kudos

I think you are talking about LSMW/BDC in your latest reply-Am I correct? I cant use LSMW/BDC because of customizing neither I can pass Dummy values as requirement is to delete the street address fields in XD02 which are suppressed and values are still available in KNA1 table and other dependent tables.

If you are talking about the class-method we are discussing then I want to delete the mandatory fields like country/City as well.

I am not anonymizing as need is to delete the street address fields data in prod system.

Can you kindly help further.

former_member736527
Active Participant
0 Kudos

You can try using the FM ADDR_DELETE. You will need to pass to it the Address Number. There is code already available on below link.

Delete Address

sanjay_deshpande4
Participant
0 Kudos

HI Taha Farosh,

I tried something as below as per the thread:

However it just deletes the Address number from ADRC not from Street address details like Street name or Postal code etc from KNA1.

I will be thankful for kindly helping further.

ls_reference-appl_table = 'KNA1'.
ls_reference-appl_field = 'ADRNR'.
" CONCATENATE sy-mandt lv_addrnumber INTO ls_reference-appl_key.
ls_reference-appl_key = '8100000108695'.
* ls_reference-addr_group = 'BP'.
* ls_reference-owner = 'X'.

" Deletion of an address without dialog
CALL FUNCTION 'ADDR_DELETE'
EXPORTING
address_number = '0002493193'
address_reference = ls_reference
EXCEPTIONS
address_not_exist = 1
parameter_error = 2
internal_error = 3
reference_not_exist = 4
OTHERS = 5.