Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Update Customer Address using CMD_EI_API

bryan_sippel3
Explorer
0 Likes
9,837

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.

1 ACCEPTED SOLUTION
Read only

bryan_sippel3
Explorer
0 Likes
4,413

Any ideas, anybody?

4 REPLIES 4
Read only

bryan_sippel3
Explorer
0 Likes
4,414

Any ideas, anybody?

Read only

0 Likes
4,413

Hi Bryan,

I have used this in a past requirement to maintain partner contact data without any issues.  All of the flags that you are setting are consistent with how I was able to get it to work.  The only sticking point that I recall is that I did have trouble if I did not call the initialize method before executing the maintain_bapi method.  Maybe that is causing some trouble for you also since you are using the getter to read the customer data first.  Aside from that I would try to set a breakpoint on MESSAGE or a watchpoint when sy-msgnr = '019' and see where it stops so you can find what logic it is executing.

Regards,
Ryan Crosby

Read only

0 Likes
4,413

After setting a watchpoint on MESSAGE, it stopped in the CHECK_EXISTENCE method of the CMD_EI_API_MAP_STRUCTURE class.

For each subordinate data structure related to the customer retrieved by the CMD_EI_API_EXTRACT=>GET_DATA method, if the CURRENT_STATE flag is blank and the associated table data is populated, the corresponding section of code is executed and an error message can occur if the TASK field is not set properly.

So unfortunately, rather than just setting CURRENT_STATE to blank to indicate nothing has changed, I also had to clear out the associated table data even though I did not need or want to change it, just so it would skip these sections of code. The beneficial side-effect was that it increased the efficiency tremendously!

I cleared the CURRENT_STATE and associated table data fields in the following structures before calling the MAINTAIN method...

CENTRAL_DATA:

     ADDRESS:

          COMMUNICATION

               PHONE, FAX, TTX, ...,

          VERSION

     TEXT,

     VAT_NUMBER,

     TAX_GROUPING,

     TAX_IND,

     EXPORT,

     LOADING,

     CONTACT,

     CREDITCARD,

     BANKDETAIL,

COMPANY_DATA,

SALES_DATA

There are similar related data structures in the VMD_EI_API MAINTAIN call.

Thinking the INITIALIZE method might be related to the MAINTAIN method, I also created a local CMD_EI_API object variable and called the INITIALIZE method, and although it did not change the outcome, I left it in there as a good practice.

I also found I needed to clear the associated tax jurisdiction code in case the changed address needed to redetermine it.

Hope that helps anyone else needing to use these classes.

Read only

Ryan-Crosby
Active Contributor
0 Likes
4,413

Hi Bryan,

I dug a little further and I see that in some cases the system throws errors for certain indicators so I would switch the flag under address to 'M' and see if that works.  I know from my case that 'U' works at the customer header level.

Regards,

Ryan Crosby