cancel
Showing results for 
Search instead for 
Did you mean: 

Customer Creation Using CMD_EI_API=>MAINTAIN_BAPI

03-21-2013 7:57 AM
4407 views 2 comments
0 Likes
SAP Managed Tags
Subscribe

Hi,

I tried creating customer using class CMD_EI_API using MAINTAIN_BAPI method. Customer is successfully created when I'm not providing Customer Sales details. When I'm providing sales details, it errors out on partner functions.

My Code:

REPORT  ZTEST_CUST75_CC.

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_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_s_company_code  type cmds_ei_company,

       wa_t_company_code  type cmds_ei_company_t,

       wa_s_functions     type cmds_ei_functions,

       wa_t_functions     type CMDS_EI_FUNCTIONS_T,

       wa_functions       type cmds_ei_cmd_functions,

       wa_s_sales_data    type cmds_ei_sales,

       wa_t_sales_data    type cmds_ei_sales_t,

       wa_sales_data      type cmds_ei_cmd_sales,

       wa_customer        type cmds_ei_extern,

       wa_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,

       wa_t_corr_cust     type CMDS_EI_EXTERN_T,

       wa_s_corr_cust     like line of wa_t_corr_cust.

data: return_t           type bapiret2_t,

       return_s           type bapiret2,

       g_kunnr            type kunnr.

data: wa_t_phone         type CVIS_EI_PHONE_T,

       wa_s_phone         like line of wa_t_phone,

       wa_t_fax           type CVIS_EI_FAX_T,

       wa_s_fax           like line of wa_t_fax,

       wa_t_email         type CVIS_EI_SMTP_T,

       wa_s_email         like line of wa_t_email,

       wa_comm            type CVIS_EI_CVI_COMMUNICATION.

constants: c_update type c value 'M',

            c_insert type c value 'I'.

 

start-of-selection.

   clear: wa_customer, wa_s_company_code.

   wa_customer-header-object_task = c_insert.

******************Begin of Populating the Address******************

   wa_address-name       = 'NAVTEQ Test Peugeot NSO Dealer'.

   wa_address-city       = 'Veldhoven'.

   wa_address-postl_cod1 = '5503LB'.

   wa_address-street     = 'De Run'.

   wa_address-country    = 'CZ'.

   wa_address-langu      = 'E'.

   wa_address-sort1      = 'SORT1'.

   wa_address-sort2      = 'Sort2'.

   wa_address-TRANSPZONE = '0000000001'.

*  Assign address data directly

   wa_customer-central_data-address-postal-data = wa_address.

   wa_addressx-name       = 'X'.

   wa_addressx-city       = 'X'.

   wa_addressx-postl_cod1 = 'X'.

   wa_addressx-street     = 'X'.

   wa_addressx-country    = 'X'.

   wa_addressx-langu      = 'X'.

   wa_addressx-sort1      = 'X'.

   wa_addressx-sort2      = 'X'.

   wa_addressx-TRANSPZONE = 'X'.

*  Assign address data directly

   wa_customer-central_data-address-postal-datax = wa_addressx.

*******************End of Populating the Address*******************

** Assign account group directly

   wa_customer-central_data-central-data-ktokd = '0001'."'OKRA'.

   wa_customer-central_data-central-datax-ktokd = 'X'.

   wa_customer-central_data-central-data-STCD1 = '8291004247'.

   wa_customer-central_data-central-datax-stcd1 = 'X'.

*******************Begin of Communication details******************

*if i_meth_id = 'Phone'.

   wa_s_phone-contact-task = c_insert.

   wa_s_phone-contact-data-telephone  = '040-1234567'.

   wa_s_phone-contact-datax-telephone = 'X'.

   append wa_s_phone to wa_t_phone.

*  wa_comm-PHONE-current_state = 'X'.

   wa_comm-PHONE-PHONE = wa_t_phone[].

*elseif i_meth_id = 'Fax'.

   wa_s_fax-contact-task = c_insert.

   wa_s_fax-contact-data-fax = '1234567891'.

   wa_s_fax-contact-datax-fax = 'X'.

   append wa_s_fax to wa_t_fax.

*  wa_comm-FAX-current_state = 'X'.

   wa_comm-FAX-FAX = wa_t_fax[].

*elseif i_meth_id = 'Email'.

   wa_s_email-contact-task = c_insert.

   wa_s_email-contact-data-e_mail = '[email protected]'.

   wa_s_email-contact-datax-e_mail = 'X'.

   append wa_s_email to wa_t_email.

*  wa_comm-SMTP-current_state = 'X'.

   wa_comm-SMTP-SMTP = wa_t_email[].

*endif.

* Assign contact mediums data directly

wa_customer-central_data-address-communication = wa_comm.

*******************End of Communication details*******************

***************Begin of Customer Company code details*************

   wa_s_company_code-task           = c_insert.

   wa_s_company_code-data_key-bukrs = '3000'.

   wa_s_company_code-data-zuawa     = '009'.

   wa_s_company_code-data-akont     = '0000140555'.

   wa_s_company_code-data-zterm = 'Z30'.

   wa_s_company_code-data-xzver = 'X'.

   append wa_s_company_code to wa_t_company_code.

   wa_customer-company_data-current_state = 'X'.

   wa_customer-company_data-company = wa_t_company_code[].

*****************End of Customer Company code details*************

******************Begin of Customer Sales details*****************

wa_s_sales_data-task = c_insert.

wa_s_sales_data-data_key-vkorg = '3000'."i_sales_org.

wa_s_sales_data-data_key-vtweg = '01'.

wa_s_sales_data-data_key-spart = '30'.

wa_s_sales_data-data-versg = '1'.

wa_s_sales_data-datax-versg = 'X'.

wa_s_sales_data-data-kalks = '3'.

wa_s_sales_data-datax-kalks = 'X'.

wa_s_sales_data-data-kdgrp = 'MC'.

wa_s_sales_data-datax-kdgrp = 'MC'.

wa_s_sales_data-data-vsbed = '02'.

wa_s_sales_data-datax-vsbed = 'X'.

wa_s_sales_data-data-waers = 'EUR'.

wa_s_sales_data-datax-waers = 'X'.

wa_s_sales_data-data-ktgrd = '02'.

wa_s_sales_data-datax-ktgrd = 'X'.

*wa_s_sales_data-data-zterm = 'Z30'."i_pay_term.

*wa_s_sales_data-datax-zterm = 'X'.

******Begin of Partner roles details*****

wa_s_sales_data-functions-current_state = 'X'.

wa_s_functions-task = c_insert.

wa_s_functions-data_key-parvw = 'RE'.

wa_s_functions-data_key-parza = '000'.

wa_s_functions-data-knref = 'Bill to Party'.

wa_s_functions-datax-knref = 'X'.

*wa_s_functions-data-partner = ' '.

*wa_s_functions-datax-partner = 'X'.

append wa_s_functions to wa_t_functions.

clear wa_s_functions.

wa_s_functions-task = c_insert.

wa_s_functions-data_key-parvw = 'AG'.

wa_s_functions-data_key-parza = '000'.

wa_s_functions-data-knref = 'Sold to Party'.

wa_s_functions-datax-knref = 'X'.

*wa_s_functions-data-partner = ' '.

*wa_s_functions-datax-partner = 'X'.

append wa_s_functions to wa_t_functions.

clear wa_s_functions.

wa_s_functions-task = c_insert.

wa_s_functions-data_key-parvw = 'RG'.

wa_s_functions-data_key-parza = '000'.

wa_s_functions-data-knref = 'Payer'.

wa_s_functions-datax-knref = 'X'.

*wa_s_functions-data-partner = ' '.

*wa_s_functions-datax-partner = 'X'.

append wa_s_functions to wa_t_functions.

clear wa_s_functions.

wa_s_functions-task = c_insert.

wa_s_functions-data_key-parvw = 'WE'.

wa_s_functions-data_key-parza = '000'.

wa_s_functions-data-knref = 'Ship to Party'.

wa_s_functions-datax-knref = 'X'.

wa_s_functions-data-partner = ' '.

wa_s_functions-datax-partner = 'X'.

append wa_s_functions to wa_t_functions.

wa_s_sales_data-functions-functions = wa_t_functions[].

******End of Partner roles details******

append wa_s_sales_data to wa_t_sales_data.

wa_sales_data-current_state = 'X'.

wa_sales_data-sales = wa_t_sales_data[].

*Assign Sales data directly

wa_customer-sales_data = wa_sales_data.

*******************End of Customer Sales details******************

   append wa_customer to wa_customers-customers.

   call method cmd_ei_api=>maintain_bapi

     EXPORTING

*      iv_test_run         = p_test

*      iv_collect_messages = 'X'

       is_master_data      = wa_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.

if wa_mes_error-is_error is initial.

   COMMIT WORK.

   wa_t_corr_cust[] = wa_correct-customers[].

   read table wa_t_corr_cust into wa_s_corr_cust index 1.

   if sy-subrc eq 0.

     g_kunnr = wa_s_corr_cust-header-object_instance-kunnr.

   endif.

   write:/'Customer Created:',g_kunnr.

else.

   return_t = wa_mes_error-messages.

   loop at return_t into return_s where type = 'E'.

     write:/'Error:',return_s-message.

   endloop.

endif.

Please let me know where I'm wrong..

0 Likes

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member632649
Discoverer
0 Likes

Hi, I am trying to put ICMS Taxpayer (KNA1-ICMSTAXPAY) from Brazil tax into this Customer creation structure, but I had no lucky, I can’t find a way to include this information, it’s not in any structure.

former_member186741
Active Contributor
0 Likes

I'm guessing the problem was that all of the PARZA values were set to 000. This field is the partner counter and I think that they should have all should have been different, ie 001, 002, 003, 004.

But thanks for doing the post, I am thinking of using this class/method and your code looks like a good model!