cancel
Showing results for 
Search instead for 
Did you mean: 

Create Contact Person via BAPI / CMD_EI_API (TCode VAP1)

Former Member
0 Kudos

Hi everybody,

I have to develop a function module, which has to be called from an external application (java). This function module should, create contact persons for customers (like Transaction VAP1 does).

I did not find any function module or bapi for this, but I found class CMD_EI_API, which seems to possibly help me. Unfortunately, there is no documentation for this class.

Could anyone help me getting the contact person's addresses into the system? Just hustle me into the right direction and I will walk by myself

Thank you very much

Ralf

Edit: The contact persons addresses have to be maintained for existing customers.

Edited by: Ralf Wenzel on Feb 21, 2012 12:19 PM

Accepted Solutions (1)

Accepted Solutions (1)

Stephen3
Participant
0 Kudos

I have this working.  I wrote a wrapper BAPI.  If inserting a new contact, you need to get a new partner number otherwise it won't work.  There is extra code in this function module that you can remove.  I left it as I used the logic for other customer update BAPIs.

FUNCTION Z_CUSTOMER_CONTACT.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(CUST) LIKE  ZCUSTOMER STRUCTURE  ZCUSTOMER
*"     VALUE(TESTFLAG) LIKE  WDL_FLAG-XFLAG DEFAULT ' '
*"     VALUE(FBAPI) TYPE  CHAR01 OPTIONAL
*"     VALUE(CONTACT) LIKE  ZCONTACT STRUCTURE  ZCONTACT
*"  EXPORTING
*"     VALUE(CUSTOMERNO) LIKE  BAPIKNA103-CUSTOMER
*"     VALUE(RETURN) LIKE  BAPIRETURN1 STRUCTURE  BAPIRETURN1
*"  EXCEPTIONS
*"      CLIENT_ERROR
*"      KNA1_INCOMPLETE
*"      KNB1_INCOMPLETE
*"      KNB5_INCOMPLETE
*"      KNVV_INCOMPLETE
*"      KUNNR_NOT_UNIQUE
*"      SALES_AREA_NOT_UNIQUE
*"      SALES_AREA_NOT_VALID
*"      INSERT_UPDATE_CONFLICT
*"      NUMBER_ASSIGNMENT_ERROR
*"      NUMBER_NOT_IN_RANGE
*"      NUMBER_RANGE_NOT_EXTERN
*"      NUMBER_RANGE_NOT_INTERN
*"      ACCOUNT_GROUP_NOT_VALID
*"      PARNR_INVALID
*"      BANK_ADDRESS_INVALID
*"      TAX_DATA_NOT_VALID
*"      NO_AUTHORITY
*"      COMPANY_CODE_NOT_UNIQUE
*"      DUNNING_DATA_NOT_VALID
*"      KNB1_REFERENCE_INVALID
*"      CAM_ERROR
*"----------------------------------------------------------------------

   data: wa_header          type cmds_ei_header,
         wa_central_data    type cmds_ei_vmd_central_data,
         wa_central_datax   type cmds_ei_vmd_central_data_xflag,
         wa_address         type bapiad1vl,
         wa_addressx        type bapiad1vlx,
         wa_contact_addr    type bapiad3vl,
         wa_contact_addrx   type BAPIAD3VLX,
         wa_tax_ind_st      type cmds_ei_tax_ind,
         wa_tax_ind         type cmds_ei_cmd_tax_ind,
         wa_bankdetail_st   type cvis_ei_cvi_bankdetail,
         wa_bankdetail      type cvis_ei_bankdetail,
         wa_company_code_st type cmds_ei_company,
         wa_company_code    type cmds_ei_cmd_company,
         wa_functions_st    type cmds_ei_functions,
         wa_functions       type cmds_ei_cmd_functions,
         wa_tcontact        type CVIS_EI_PHONE,
         wa_phone_st        type CVIS_EI_PHONE_STR,
         wa_phone           type CVIS_EI_CVI_PHONE,
         wa_fcontact        type CVIS_EI_FAX,
         wa_fax_st          type CVIS_EI_FAX_STR,
         wa_fax             type CVIS_EI_CVI_FAX,
         wa_econtact        type CVIS_EI_SMTP,
         wa_smtp_st         type CVIS_EI_SMTP_STR,
         wa_smtp            type CVIS_EI_CVI_SMTP,
         wa_sales_data_st   type cmds_ei_sales,
         wa_sales_data      type cmds_ei_cmd_sales,
         wa_customer        type cmds_ei_extern,
         wa_cust_created    type cmds_ei_extern,
         is_customers       type cmds_ei_main,
         es_customers       type cmds_ei_main,
         wa_correct         type cmds_ei_main,
         wa_defective       type cmds_ei_main,
         wa_mes_correct     type cvis_message,
         wa_mes_error       type cvis_message,
         it_contacts        type cmds_ei_contacts_t,
         wa_contacts        type CMDS_EI_CONTACTS,
         messages           type BAPIRET2_T.

   FIELD-SYMBOLS: <bapiret2> type BAPIRET2.

   DATA: STATUS TYPE CHAR20,
         PARNR  LIKE KNVK-PARNR.

   constants: FILLCHAR VALUE '/',
              gc_objtype_customer TYPE mds_ctrl_object VALUE 'CUSTOMER',
              gc_insert           TYPE c VALUE 'I',
              gc_delete           TYPE c VALUE 'D',
              gc_current_state    TYPE c VALUE 'C',
              gc_update           TYPE c VALUE 'U',
              gc_true             TYPE c VALUE 'X',
              gc_false            TYPE c VALUE ' '.

   include fbgenmac.

* generate data record
   fbgenmac 'Z_CUSTOMER_CONTACT'.

* Clear memory variables - needed if run in Test mode
***********************************************************************
* Initialization
***********************************************************************
   CALL METHOD cmd_ei_api=>initialize.

   wa_customer-header-object_instance-kunnr = cust-kunnr.
   wa_customer-header-object_task           = gc_update.
   append wa_customer to is_customers-customers.

   call method CMD_EI_API_EXTRACT=>get_data
     EXPORTING
       is_master_data = is_customers
     IMPORTING
       es_master_data = es_customers
       es_error       = wa_mes_error.

   IF wa_mes_error-is_error is initial.

     STATUS = 'OK'.

     LOOP at es_customers-customers into wa_cust_created.

       wa_company_code = wa_cust_created-company_data.

       IF STATUS = 'OK' and wa_mes_error-is_error is INITIAL.
*      is_customers = es_customers.

         free: wa_customer, wa_company_code_st,
               wa_company_code, wa_address, wa_sales_data_st,
               wa_contacts, wa_contact_addr,
               wa_sales_data, wa_tax_ind_st, wa_functions,
               wa_functions_st, wa_correct, wa_mes_correct,
               wa_defective, wa_mes_error, wa_cust_created,
               wa_tcontact, wa_phone_st, wa_phone,
               wa_fcontact, wa_fax_st, wa_fax, wa_econtact,
               wa_smtp_st, wa_smtp.

         FREE: is_customers.

         IF CONTACT-FIRSTNAME IS NOT INITIAL.

           CALL FUNCTION 'NUMBER_GET_NEXT'
             EXPORTING
               nr_range_nr                   = 'AP'
               object                        = 'PARTNER'
               QUANTITY                      = '1'
               SUBOBJECT                     = ' '
*           TOYEAR                        = '0000'
**          IGNORE_BUFFER                 = ' '
             IMPORTING
               NUMBER                        = PARNR
*           QUANTITY                      =
*           RETURNCODE                    =
            EXCEPTIONS
               INTERVAL_NOT_FOUND            = 1
               NUMBER_RANGE_NOT_INTERN       = 2
               OBJECT_NOT_FOUND              = 3
               QUANTITY_IS_0                 = 4
               QUANTITY_IS_NOT_1             = 5
               INTERVAL_OVERFLOW             = 6
               BUFFER_OVERFLOW               = 7
               OTHERS                        = 8.

           IF SY-SUBRC = 0.

* Add partner type 20
             wa_contacts-task           = gc_insert.
             wa_contacts-data_key-parnr = PARNR.
             wa_contacts-data-pafkt     = '20'.
             wa_contacts-datax-pafkt    = 'X'.
*        wa_contacts-address_type_1 = ''.
*        wa_contacts-address_type_2 = ''.

*        wa_contact_addr-fullname   = CUST-NAME.
             wa_contact_addr-firstname  = CONTACT-FIRSTNAME.
             wa_contact_addrx-firstname = 'X'.
             wa_contact_addr-lastname   = CONTACT-LASTNAME.
             wa_contact_addrx-lastname  = 'X'.

* Assign address data directly
             wa_contacts-address_type_3-task  = gc_insert.
             wa_contacts-address_type_3-postal-data  = wa_contact_addr.
             wa_contacts-address_type_3-postal-datax = wa_contact_addrx.

* e-mail address
             wa_econtact-task = gc_insert.
             wa_econtact-data-std_no = 'X'.
             wa_econtact-data-e_mail = CONTACT-E_MAIL.

*        wa_econtact-datax-std_no = 'X'.
*        wa_econtact-datax-e_mail = 'X'.

             wa_smtp-current_state = ' '.
             wa_smtp_st-contact = wa_econtact.
             append wa_smtp_st to wa_smtp-smtp.

             wa_contacts-address_type_3-communication-smtp = wa_smtp.

*        wa_contacts-contact_texts  = ''.

             append wa_contacts to it_contacts.

           ENDIF.

           CALL FUNCTION 'NUMBER_GET_NEXT'
             EXPORTING
               nr_range_nr                   = 'AP'
               object                        = 'PARTNER'
               QUANTITY                      = '1'
               SUBOBJECT                     = ' '
*           TOYEAR                        = '0000'
**          IGNORE_BUFFER                 = ' '
             IMPORTING
               NUMBER                        = PARNR
*           QUANTITY                      =
*           RETURNCODE                    =
            EXCEPTIONS
               INTERVAL_NOT_FOUND            = 1
               NUMBER_RANGE_NOT_INTERN       = 2
               OBJECT_NOT_FOUND              = 3
               QUANTITY_IS_0                 = 4
               QUANTITY_IS_NOT_1             = 5
               INTERVAL_OVERFLOW             = 6
               BUFFER_OVERFLOW               = 7
               OTHERS                        = 8.

           IF SY-SUBRC = 0.
* Add partner type 30
             wa_contacts-data_key-parnr = parnr.
             wa_contacts-data-pafkt     = '30'.
             append wa_contacts to it_contacts.
           ENDIF.

* Assign contacts to customer structure
           wa_customer-central_data-contact-contacts = it_contacts.

* Set object_task to modify
           wa_customer-header-object_instance-kunnr = cust-kunnr.
           wa_customer-header-object_task = gc_update.

           append wa_customer to is_customers-customers.

           IF FBAPI = 'X'.
* MAINTAIN_BAPI seems to now work.  Fills in table addr_appl_to_int used in function module
* ADDR_MEMORY_SAVE line 631.  It should be blank.
             call method cmd_ei_api=>maintain_bapi
               EXPORTING
                 iv_test_run              = TESTFLAG
                 iv_collect_messages      = 'X'
                 is_master_data           = is_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.
           ELSE.
             call method cmd_ei_api=>maintain
               EXPORTING
                 iv_test_run    = TESTFLAG
                 is_master_data = is_customers
               IMPORTING
                 es_error       = wa_mes_error.
           ENDIF.

           IF wa_mes_error-is_error is initial.

             if testflag <> 'X'.
               commit work and wait.
               LOOP at wa_correct-customers into wa_cust_created.
                 CUSTOMERNO = wa_cust_created-header-object_instance-kunnr.
                 SY-MSGID = 'F2'.
                 SY-MSGNO = '056'.     " Failure
                 SY-MSGV1 = ''.
                 SY-MSGV2 = ''.
                 SY-MSGV3 = ''.
                 SY-MSGV4 = ''.

                 CALL FUNCTION 'BALW_BAPIRETURN_GET1'
                   EXPORTING
                     TYPE       = 'E'
                     CL         = SY-MSGID
                     NUMBER     = SY-MSGNO
                     PAR1       = SY-MSGV1
                     PAR2       = SY-MSGV2
                     PAR3       = SY-MSGV3
                     PAR4       = SY-MSGV4
*               LOG_NO     = ' '
*               LOG_MSG_NO = ' '
                   IMPORTING
                     BAPIRETURN = RETURN.
               ENDLOOP.

               CALL FUNCTION 'ADDR_MEMORY_CLEAR'
                 EXPORTING
                   force              = 'X'
                 EXCEPTIONS
                   unsaved_data_exist = 1
                   internal_error     = 2
                   others             = 3.

             ELSE.
               ROLLBACK WORK.
               LOOP at wa_correct-customers into wa_cust_created.
                 CUSTOMERNO = wa_cust_created-header-object_instance-kunnr.
                 SY-MSGID = 'F2'.
                 SY-MSGNO = '035'.
                 SY-MSGV1 = ''.
                 SY-MSGV2 = ''.
                 SY-MSGV3 = ''.
                 SY-MSGV4 = ''.

                 CALL FUNCTION 'BALW_BAPIRETURN_GET1'
                   EXPORTING
                     TYPE       = 'E'
                     CL         = SY-MSGID
                     NUMBER     = SY-MSGNO
                     PAR1       = SY-MSGV1
                     PAR2       = SY-MSGV2
                     PAR3       = SY-MSGV3
                     PAR4       = SY-MSGV4
*               LOG_NO     = ' '
*               LOG_MSG_NO = ' '
                   IMPORTING
                     BAPIRETURN = RETURN.
               ENDLOOP.

               CALL FUNCTION 'ADDR_MEMORY_CLEAR'
                 EXPORTING
                   force              = 'X'
                 EXCEPTIONS
                   unsaved_data_exist = 1
                   internal_error     = 2
                   others             = 3.

             ENDIF.
           ELSE.
             messages = wa_mes_error-messages.
             LOOP at wa_mes_error-messages assigning <bapiret2>.

               CUSTOMERNO = CUST-KUNNR.

               CALL FUNCTION 'BALW_BAPIRETURN_GET1'
                 EXPORTING
                   TYPE       = <bapiret2>-type
                   CL         = <bapiret2>-id
                   NUMBER     = <bapiret2>-number
                   PAR1       = <bapiret2>-message_v1
                   PAR2       = <bapiret2>-message_v2
                   PAR3       = <bapiret2>-message_v3
                   PAR4       = <bapiret2>-message_v4
*         LOG_NO     = ' '
*         LOG_MSG_NO = ' '
                 IMPORTING
                   BAPIRETURN = RETURN.
             ENDLOOP.
           ENDIF.
         ELSE.
           CUSTOMERNO = CUST-KUNNR.
           SY-MSGID = 'F2'.
           SY-MSGNO = '152'.     " Failure
           SY-MSGV1 = CUST-KUNNR.
           SY-MSGV2 = CUST-BUKRS.
           SY-MSGV3 = ''.
           SY-MSGV4 = ''.

           CALL FUNCTION 'BALW_BAPIRETURN_GET1'
             EXPORTING
               TYPE       = 'E'
               CL         = SY-MSGID
               NUMBER     = SY-MSGNO
               PAR1       = SY-MSGV1
               PAR2       = SY-MSGV2
               PAR3       = SY-MSGV3
               PAR4       = SY-MSGV4
*         LOG_NO     = ' '
*         LOG_MSG_NO = ' '
             IMPORTING
               BAPIRETURN = RETURN.
         ENDIF.
       ENDIF.
     ENDLOOP.
   ELSE.
     CUSTOMERNO = CUST-KUNNR.
     SY-MSGID = 'F2'.
     SY-MSGNO = '077'.     " Failure
     SY-MSGV1 = CUST-NAME.
     SY-MSGV2 = ''.
     SY-MSGV3 = ''.
     SY-MSGV4 = ''.

     CALL FUNCTION 'BALW_BAPIRETURN_GET1'
       EXPORTING
         TYPE       = 'E'
         CL         = SY-MSGID
         NUMBER     = SY-MSGNO
         PAR1       = SY-MSGV1
         PAR2       = SY-MSGV2
         PAR3       = SY-MSGV3
         PAR4       = SY-MSGV4
*         LOG_NO     = ' '
*         LOG_MSG_NO = ' '
       IMPORTING
         BAPIRETURN = RETURN.

   ENDIF.


ENDFUNCTION.

former_member189545
Participant
0 Kudos

Hi Ralf,

Note 306275 decribes the use of BAPI functional modules for transferring
address data.

As per note 306275 -

o  the BAPI BAPI_ADDRESSORG_SAVEREPLICA for addresses of companies
   and organizations (for example, customer address, vendor address,
   deviating business address of the contact person),

o  the BAPI BAPI_ADDRESSPERS_SAVEREPLICA for private addresses (home
   address of the contact person),

o  and the BAPI BAPI_ADDRCONTPART_SAVEREPLICA for work center
   addresses (assembled business address of the contact person)

You can make use any of the above three BAPI's to update address data
for contact person based on your requirement.
However to upload the data correctly use need to fill the import
parameters with appropriate values.

Also you should call the FM BAPI_TRANSACTION_COMMIT immediately
immediately after your bapi call. Also use the FM 'BUFFER_REFRESH_ALL'
before calling your BAPI.

BR,

Zsuzsanna

0 Kudos

Hi Zsuzsanna,

I need your help about BAPI : BAPI_ADDRCONTPART_SAVEREPLICA, I want use this BAPI for create contact person for VENDOR, but, this BAPI just only create in ADRP table not in knvk table. How to use this BAPI?

Please help me,

Thanks before.

bruno_esperanca
Contributor
0 Kudos

Hi Fernando,

Like you mentioned, that BAPI is useless, I would check this blog post of mine:

You will need to install SAPlink on your SAP system to be able to install the class I've created, which will enable you to create vendor contacts properly.

If you need help, let me know.

Cheers,

Bruno

former_member189545
Participant
0 Kudos

Hi Fernando,

    What we need to focus here is that we are dealing with two different

components. One is customer master and the other one is Business Address

Services(BAS).BAS is a basic functionality which is used by all the

master data objects. Now you are using BAPI_ADDRCONTPART_SAVEREPLICA

to save the details related to the contact person but this is not

updated in KNVK. Usually BAPI is used in non dialog scenario and

generally application which is using  BAS will call this and they are

responsible for updating the address number to their tables. Since in

this case you are calling the BAPI, you need to update the address

number in KNVK and there is no way this BAPI can update it.

For mass updating of contact persons data it might be better to update
such data from customer master transactions like VAP2 or XD02. The
reason why I would not recommend to use BAPI_ADDRCONTPART is because it
will not updates the contact person table (KNVK) which is the main
contact person table. VAP2 or XD02 will assure a consisten update on
both tables KNVK and ADRP. Therefore, you may use LSMW or
SM35 via batch input

Please have a look to notes 384462 and 306275.

If you still want to use directly Bapi_AddrcontPart-savereplica, please
check the documentation or in the BOR (Transaction SWO1, Object BUS4003,
method SAVEREPLICA and menu goto/documentation).

I hope I could help you with this information further.

Have a nice day 🙂

Best regards,

Zsuzsanna

bruno_esperanca
Contributor
0 Kudos

Hi Zsuzsanna,

The class I created takes care of all that, without the need of a batch input (which is terrible for performance).

Maybe you could take a look and tell me what you think of it.

Cheers,

Bruno

Answers (4)

Answers (4)

bruno_esperanca
Contributor
0 Kudos

Hi Ralf,

Please check the class I have created for this, should be easier than using the BAPIs or the class that you found (I found it as well, it was worthless...)

Best,

Bruno

former_member189545
Participant
0 Kudos

Hi Ralf,

Note 306275 decribes the use of BAPI functional modules for transferring
address data.

As per note 306275 -

o  the BAPI BAPI_ADDRESSORG_SAVEREPLICA for addresses of companies
   and organizations (for example, customer address, vendor address,
   deviating business address of the contact person),

o  the BAPI BAPI_ADDRESSPERS_SAVEREPLICA for private addresses (home
   address of the contact person),

o  and the BAPI BAPI_ADDRCONTPART_SAVEREPLICA for work center
   addresses (assembled business address of the contact person)

You can make use any of the above three BAPI's to update address data
for contact person based on your requirement.
However to upload the data correctly use need to fill the import
parameters with appropriate values.

Also you should call the FM BAPI_TRANSACTION_COMMIT immediately
immediately after your bapi call. Also use the FM 'BUFFER_REFRESH_ALL'
before calling your BAPI.

BR,

Zsuzsanna

Former Member
0 Kudos

Hi,

we found function module ISAI_CONTACT_CREATE instead. Seems to work fine.

Thanks

Ralf

former_member202528
Active Contributor
0 Kudos

Pls check OSS note - 1494799

Below is the description of note, might be of some help for your scenario,

-


Symptom

You run webservice ECC_SALESARRANGEMENTUPDRC (SalesArrangementERPUpdateRequestConfirmation_In) or web dynpro application LCM_WEBDYNPRO to change sales data and/or general data of a customer.

The customer you changed has contact person data but you did not change any contact person data.

Then if you check contact person data in XD03:

'General Data' -> 'Contact Person' tab -> Menu 'Extras' -> 'Administrative Data': creation date and creation processor are the ones of 'General Data'.

Technically you can notice that fields KNVK-ERNAM and KNVK-ERDAT are empty.

Other terms

KNVK ERNAM ERDAT CMD_EI_API maintain empty lost blank DUEFL kzherk

Reason and Prerequisites

This could happen also with any equivalent direct use of class CMD_EI_API.

Solution

Please implement relevant attached correction.

-


BR,

Krishna