Introduction:
- This document shows how to create/update contact person (VAP1 tcode) of an existing customer using the class cmd_ei_api and its method “maintain”.
- Contact person has “last name” as a mandatory field.
- Contacts can be created, updated, deleted using the above method and class.
- This document also shows how to update both telephone and mobile number together using the method maintain.
Code:
*declaration
DATA: ls_cmds_ei_main TYPE cmds_ei_main, " Total Customer Data
ls_cmds_ei_extern TYPE cmds_ei_extern, " Complex External Interface
es_error TYPE cvis_message,
lv_phone1 TYPE LINE OF cvis_ei_phone_t,
lv_contact TYPE LINE OF cmds_ei_contacts_t.
*existing customer is getting updated, hence object_task – ‘U’
ls_cmds_ei_extern-header-object_instance-kunnr = 'DAKK103'.”existing customer no.
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 example, 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'. "insert/create the contact person
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 internal table of phone has 2 entries, one for telephone number and other one for mobile number.
*fill telephone, mob 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.
*append the lv_contact to the contacts table & append final structure to customer table
INSERT lv_contact INTO TABLE ls_cmds_ei_extern-central_data-contact-contacts.
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.
*lock the customer number before updating
CALL METHOD cmd_ei_api=>lock( iv_kunnr = ls_cmds_ei_extern-header-object_instance-kunnr ).
*update the customer using the method maintain
CALL METHOD cmd_ei_api=>maintain
EXPORTING is_master_data = ls_cmds_ei_main " Total Customer Data
IMPORTING es_error = es_error. " Error Indicator and System Messages
*unlock the customer
CALL METHOD cmd_ei_api=>unlock( iv_kunnr = ls_cmds_ei_extern-header-object_instance-kunnr ).
ENDIF.
Finally call the below statement or commit work statement to reflect all the changes. Else contact person would have not been created.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
View the contact person created by viewing the customer in XD03=>contact person tab.
It's like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you can do with some pics to drive the message home a little bit, but instead of that, this is fantastic blog. A great read. I will definitely be back.
ReplyDeleteSAP Training in Chennai
in vmd_ei_api=>maintain_bapi is not work
ReplyDelete