Skip to Content
Author's profile photo Poornima Sridharan

cmd_ei_api class to maintain customer & contact person


  • This document shows the usage of the class & method cmd_ei_api=>maintain.
  • It mainly focusses on creation of contact person and deletion of customer/contact person.

  • Customer/Contact person can be created, updated, deleted using the above method and class.

Contact person create for existing customer:

  • This topic mainly shows how to update both telephone and mobile number of a contact person using the method maintain. Both fields can be updated by setting the flag value.
  • Contact person has last name as a mandatory field.
  • Declare the necessary class and its types.
DATA:     ls_cmds_ei_main   TYPE cmds_ei_main, " Total Customer Data
          ls_cmds_ei_extern TYPE cmds_ei_extern, " Complex External Interface for Customers
          es_error          TYPE cvis_message,
          lv_phone1         TYPE LINE OF cvis_ei_phone_t,
          lv_contact        TYPE LINE OF cmds_ei_contacts_t.
  • Pass the object_task field as ‘I’ for customer creation or ‘U’ for customer update. In the below case, we are going to create a contact person for the existing customer.
*existing customer is getting updated, hence object_task – ‘U’
ls_cmds_ei_extern-header-object_instance-kunnr = 'DAKK103'.” pass the existing customer number
ls_cmds_ei_extern-header-object_task           = 'U'."I for insert U for update
  • Title can be Mr. Mrs. Etc. But this title_p accepts the address key. So pass the key related to Mr. Mrs. Miss.

  • So the relevant values should be passed to the title_p field,

  • In the below code, we are going to pass Mr. (0002) so the address key 0002 is passed in the field title_p.
*fil lastname, title,
lv_contact-task = 'I'.
lv_contact-address_type_3-task = 'I'.
lv_contact-address_type_3-postal-data-title_p = '0002'.
lv_contact-address_type_3-postal-datax-title_p = 'X'.

lv_contact-address_type_3-postal-data-lastname = 'lastname'.
lv_contact-address_type_3-postal-datax-lastname = 'X'.
  • To pass the telephone number & mobile number together we need to set the flag for the field R_3_USER.

  • R_3_USER has the data element AD_FLGMOB (mobile indicator). View the value of the data element to see the possible entries.

  • We need to update both telephone number and mobile number, hence we are passing R_3_USER = ‘1’ (telephone) R_3_USER = ‘2’(mobile) and appending the value to phone structure separately.
  • So the phone internal table of phone has 2 entries, one for telephone number and other one for mobile number.
*fill telephone, tel_extens, mob number, fax number
lv_phone1-contact-task = 'I'.
lv_phone1-contact-data-telephone = '004823283'.
lv_phone1-contact-datax-telephone = 'X'.
lv_phone1-contact-data-R_3_USER = '1'.
lv_phone1-contact-datax-R_3_USER = 'X'.
INSERT lv_phone1 INTO TABLE lv_contact-address_type_3-communication-phone-phone.

lv_phone1-contact-task = 'I'.
lv_phone1-contact-data-telephone = '9710893900'.
lv_phone1-contact-datax-telephone = 'X'.
lv_phone1-contact-data-R_3_USER = '2'.
lv_phone1-contact-datax-R_3_USER = 'X'.
INSERT lv_phone1 INTO TABLE lv_contact-address_type_3-communication-phone-phone.

Delete customer/contact person:

  • This topic mainly focuses on the deletion of customer/contact person.
  • There is no way to delete a customer, instead we can set some values to the fields and set the flag for deletion.
  • When you try to delete a customer using XD05(customer block & unblock) or XD06(customer flag for deletion) it certainly sets some field values as ‘X’. we can see it while recording in SHDB.
  • The necessary fields for setting the customer flag for delete are,
  • AUFSD – central order block for customer
  • SPERR – central posting block
  • CASSD – central sales block for customer
  • LOEVM – central deletion flag for master record
  • We achieve the same functionality of XD05 and XD06 through our code by modifying the customer (task as ‘M’) using the method “maintain” and set the above flag values.
  • Customer number still can be viewed using the transaction XD03 with a warning as “Customer marked for deletion”.
  • Contact person can be deleted completely and it cannot be viewed in XD03->contact person tab or in VAP3.

Customer deletion (setting the deletion flag):

  • Set the necessary flags for blocking the customer on different parameters.
*set the central posting block
  ls_cmds_ei_extern-central_data-central-data-sperr = ' '.
  ls_cmds_ei_extern-central_data-central-datax-sperr = 'X'.
*set the central order block
  ls_cmds_ei_extern-central_data-central-data-aufsd = '01'.
  ls_cmds_ei_extern-central_data-central-datax-aufsd = 'X'.
*set the central sales block
  ls_cmds_ei_extern-central_data-central-data-cassd = 'X'.
  ls_cmds_ei_extern-central_data-central-datax-cassd = 'X'.
*set the central deletion flag
  ls_cmds_ei_extern-central_data-central-data-loevm = 'X'.
  ls_cmds_ei_extern-central_data-central-datax-loevm = 'X'.
  • AUFSD value as ‘01’ is for overall block.

Contact Person Deletion:

  • Pass the contact-task as ‘D’ (delete) and pass the contact person number (PARNR) value to be deleted.
lv_contact-task = 'D'.
lv_contact-data_key-parnr = '1101'.
  • Append the contact structure to the contacts internal table as mentioned below.
INSERT lv_contact INTO TABLE ls_cmds_ei_extern-central_data-contact-contacts.

common steps to be followed:

  • Append the structure to customer internal table and call the method cmd_ei_api=>maintain to reflect the changes.
APPEND ls_cmds_ei_extern TO ls_cmds_ei_main-customers.
CLEAR ls_cmds_ei_extern.

IF ls_cmds_ei_main IS NOT INITIAL.

    CALL METHOD cmd_ei_api=>initialize.
    CALL METHOD cmd_ei_api=>lock( iv_kunnr = ls_cmds_ei_extern-header-object_instance-kunnr ).
    CALL METHOD cmd_ei_api=>maintain
        is_master_data = ls_cmds_ei_main " Total Customer Data
        es_error       = es_error. " Error Indicator and System Messages
    CALL METHOD cmd_ei_api=>unlock( iv_kunnr = ls_cmds_ei_extern-header-object_instance-kunnr ).
  • Then call the “commit work” statement or

    to reflect the changes.


Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Franklin Asis
      Franklin Asis

      Hi Poornima,

      I made a program that uses this method to Mark the Flag for Deletion(XD06) and/or Block/unblock(XD05) specific customers. However, i keep encountering an error if I am trying to do either or both of the operations I mentioned to a customer which is a branch account (has knb1-knrze). I traced this down to the method cmd_ei_api_check=>struc_knb1_plausibility_check. I am simply passing the X value to SPERR under the company data and/or LOEVM under the central data, together with their corresponding DATAX entries. Would you be able to point out what I am missing?



      Author's profile photo Raphael Sommer
      Raphael Sommer


      thank you for your blog, I had to change email address on contact person of customer and some Z-fields on customer. This worked perfect with

      cmd_ei_api class

      and your blog. Great!

      Best regards