Hello Experts!
I need to update customer zip codes to ZIP+4. We are retrieving validated zip codes via a web service, but I am having trouble updating the customer addresses.
I have tried using BAPI_ADDRESSORG_CHANGE but it only updates ADRC and does not update the corresponding address fields in KNA1 until you manually save the changes in XD02. I would really rather not resort to using a BDC for XD02.
I have tried using SD_CUSTOMER_MAINTAIN_ALL but I was getting exception KNA1_INCOMPLETE indicating my KNA1 structure was not complete even though I had just loaded it using a SELECT statement prior to the call.
In some of my searches, I saw references to the CMD_EI_API class MAINTAIN, MAINTAIN_BAPI, and MAINTAIN_DIRECT_INPUT methods.
The associated IS_MASTER_DATA structure contains several data modification indicators:
The HEADER-OBJECT_TASK field appears to want: I)nsert, U)pdate, M)odify, or C)urrent Status.
The CENTRAL_DATA-ADDRESS-TASK field appears to want: I)nsert, U)pdate, D)elete, or M)odify.
The CENTRAL_DATA-ADDRESS-DATAX structure contains flags for each field to be updated.
With both TASK fields set to "U", the ES_MESSAGE_DEFECTIVE parameter returns “E019(CMD_API) Field: TASK, value: is not permitted”.
If I blank out the CENTRAL_DATA-ADDRESS-TASK field, I get “E019(CMD_API) Field: TASK, value: is not permitted”.
If I blank out the HEADER-OBJECT_TASK field, I get “E019(CMD_API) Field: OBJECT_TASK, value: is not permitted”.
If I blank out both, I still get “E019(CMD_API) Field: OBJECT_TASK, value: is not permitted”.
Any assistance you can provide would be greatly appreciated!
Here is a snapshot of my test code…
DATA:
lw_kunnr TYPE kunnr,
is_master_data TYPE cmds_ei_main,
es_master_data TYPE cmds_ei_main,
es_error TYPE cvis_message,
wa_customers TYPE cmds_ei_extern,
lt_sales TYPE cmds_ei_sales_t,
wa_sales LIKE LINE OF lt_sales,
lw_master_data_correct TYPE cmds_ei_main,
lw_message_correct TYPE cvis_message,
lw_master_data_defective TYPE cmds_ei_main,
lw_message_defective TYPE cvis_message.
FIELD-SYMBOLS:
<lf_cst> TYPE cmds_ei_extern,
<lf_gen> TYPE cmds_ei_central_data.
lw_kunnr = '0001000011'. "use an existing customer number in your system
* set up the control parameters
wa_customers-header-object_instance-kunnr = lw_kunnr. "customer number
wa_customers-header-object_task = 'U'. "update customer
APPEND wa_customers TO is_master_data-customers.
* read the customer
cmd_ei_api_extract=>get_data( EXPORTING is_master_data = is_master_data
IMPORTING es_master_data = es_master_data ).
* read the customer information
READ TABLE es_master_data-customers ASSIGNING <lf_cst> INDEX 1.
CHECK sy-subrc EQ 0.
* set the modification control flags
<lf_cst>-header-object_task = 'U'. "update customer
<lf_cst>-central_data-address-task = 'U'. "update address
* just for testing, add or remove the +4
IF STRLEN( <lf_cst>-central_data-address-postal-data-postl_cod1 ) EQ 5.
<lf_cst>-central_data-address-postal-data-postl_cod1 = '95678-1234'.
ELSE.
<lf_cst>-central_data-address-postal-data-postl_cod1 = '95678'.
ENDIF.
* set the corresponding field changed and update flags
<lf_cst>-central_data-address-postal-datax-postl_cod1 = 'X'.
<lf_cst>-central_data-address-postal-datax-updateflag = 'U'.
* update the customer
CALL METHOD cmd_ei_api=>maintain_bapi
EXPORTING
is_master_data = es_master_data
IMPORTING
es_master_data_correct = lw_master_data_correct
es_message_correct = lw_message_correct
es_master_data_defective = lw_master_data_defective
es_message_defective = lw_message_defective.
...
--------------
Once I can get the method to return a successful status in ES_MASTER_DATA_CORRECT or ES_MESSAGE_CORRECT, I will call the COMMIT to post the changes.