Skip to Content

Hello everybody,

Today i would like to share a code snippet to create customers based upon a text file with tab separator, it’s very easy and functional using this api, in 161 lines of code you can create a client with basic central data and sales data.

The form receives the work area with customer data, this create a customer at time, so i call this routine from a loop of a internal table with file data.

form create_customer_api  using p_wa_file type ty_file

                                 value(p_row_id) type sytabix.

  data: l_wa_main type cmds_ei_main,

        l_it_customers type cmds_ei_extern_t,

        l_wa_customers type cmds_ei_extern,

        l_wa_phones type cvis_ei_phone_str,

        l_wa_email type cvis_ei_smtp_str,

        l_wa_sales type cmds_ei_sales,

        l_wa_loading type cmds_ei_loading,

        l_wa_functions type cmds_ei_functions,

        l_update_errors type cvis_message,

        l_it_bdcmsgcoll type table of bdcmsgcoll,

        l_wa_bdcmsgcoll type bdcmsgcoll,

        l_wa_messages type bapiret2,

        l_wa_log_alv type ty_log_alv,

        l_kunnr type kna1kunnr.

  l_wa_customersheaderobject_task = ‘I’.

  l_wa_customerscentral_dataaddresstask = ‘I’.

  case p_wa_fileanred.

   when ‘Sra.’.

    l_wa_customerscentral_dataaddresspostaldatatitle = ‘0001’.

   when ‘Sr.’.

    l_wa_customerscentral_dataaddresspostaldatatitle = ‘0002’.

   when ‘Empresa’.

    l_wa_customerscentral_dataaddresspostaldatatitle = ‘0003’.

   when others.

    l_wa_customerscentral_dataaddresspostaldatatitle = p_wa_fileanred.

  endcase.

  l_wa_customerscentral_dataaddresspostaldataname = p_wa_filename1.

  l_wa_customerscentral_dataaddresspostaldataname_2 = p_wa_filename2.

  l_wa_customerscentral_dataaddresspostaldataname_3 = p_wa_filename3.

  l_wa_customerscentral_dataaddresspostaldataname_4 = p_wa_filename4.

  l_wa_customerscentral_dataaddresspostaldatasort1 = p_wa_filesortl.

  l_wa_customerscentral_dataaddresspostaldatastreet = p_wa_filestreet.

  l_wa_customerscentral_dataaddresspostaldatastr_suppl3 = p_wa_filestr_suppl3.

  l_wa_customerscentral_dataaddresspostaldatapostl_cod1 = p_wa_filepost_code1.

  l_wa_customerscentral_dataaddresspostaldatacity = p_wa_filecity1.

  l_wa_customerscentral_dataaddresspostaldataregion = p_wa_fileregion.

  l_wa_customerscentral_dataaddresspostaldatatranspzone = p_wa_filetranspzone.

  l_wa_customerscentral_dataaddresspostaldataextens_1 = p_wa_fileextension1.

  l_wa_customerscentral_dataaddresspostaldatalangu = ‘S’.

  l_wa_customerscentral_dataaddresspostaldatacountry = ‘CO’.

  l_wa_customerscentral_datacentraldatabrsch = p_wa_filebrsch.

  l_wa_customerscentral_datacentraldatastcd1 = p_wa_filestcd1.

  l_wa_customerscentral_datacentraldatastcdt = p_wa_filestcdt.

  l_wa_customerscentral_datacentraldatafityp = p_wa_filefityp.

  l_wa_customerscentral_datacentraldataniels = p_wa_fileniels.

  l_wa_customerscentral_datacentraldatakukla = p_wa_filekukla.

  l_wa_customerscentral_datacentraldatabran1 = p_wa_filebran1.

  l_wa_customerscentral_datacentraldataktokd = pa_ktokd.

  l_wa_customerscentral_datacentraldatakatr1 = p_wa_filekatr1.

  l_wa_customerscentral_datacentraldatakatr2 = p_wa_filekatr2.

  l_wa_customerscentral_datacentraldatakatr3 = p_wa_filekatr3.

  l_wa_loadingtask = ‘I’.

  l_wa_loadingdata_keyablad = p_wa_fileablad.

  l_wa_loadingdataknfak = p_wa_fileknfak.

  append l_wa_loading to l_wa_customerscentral_dataloadingloading.

  l_wa_phonescontacttask = ‘I’.

  l_wa_phonescontactdatatelephone = p_wa_filetelf1.

  append l_wa_phones to l_wa_customerscentral_dataaddresscommunicationphonephone.

  l_wa_emailcontacttask = ‘I’.

  l_wa_emailcontactdatae_mail = p_wa_filesmtp_addr.

  append l_wa_email to l_wa_customerscentral_dataaddresscommunicationsmtpsmtp.

  l_wa_salestask = ‘I’.

  l_wa_salesdata_keyvkorg = pa_vkorg.

  l_wa_salesdata_keyvtweg = pa_vtweg.

  l_wa_salesdata_keyspart = pa_spart.

  l_wa_salesdatabzirk = p_wa_filebzirk.

  l_wa_salesdatavkbur = p_wa_filevkbur.

  l_wa_salesdatavkgrp = p_wa_filevkgrp.

  l_wa_salesdatakdgrp = p_wa_filekdgrp.

  l_wa_salesdatakonda = p_wa_filekonda.

  l_wa_salesdatakalks = p_wa_filekalks.

  l_wa_salesdatapltyp = p_wa_filepltyp.

  l_wa_salesdataversg = p_wa_fileversg.

  l_wa_salesdatalprio = p_wa_filelprio.

  l_wa_salesdatavsbed = p_wa_filevsbed.

  l_wa_salesdatavwerk = p_wa_filevwerk.

  l_wa_salesdatabokre = p_wa_filebokre.

  l_wa_salesdataprfre = p_wa_fileprfre.

  l_wa_salesdatainco1 = p_wa_fileinco1.

  l_wa_salesdatakkber = p_wa_filekkber.

  l_wa_salesdatakabss = p_wa_filekabss.

  l_wa_functionstask = ‘I’.

  l_wa_functionsdata_keyparvw = ‘WE’.

  l_wa_functionsdatadefpa = ‘X’.

  append l_wa_functions to l_wa_salesfunctionsfunctions.

  clear l_wa_functionsdatadefpa.

  call function ‘CONVERSION_EXIT_ALPHA_INPUT’

    exporting

      input = p_wa_filekunn2

    importing

      output = l_wa_functionsdatapartner.

  l_wa_functionsdata_keyparvw = ‘AG’.

  append l_wa_functions to l_wa_salesfunctionsfunctions.

  l_wa_functionsdata_keyparvw = ‘VE’.

  l_wa_functionsdatapartner = p_wa_filepernr.

  append l_wa_functions to l_wa_salesfunctionsfunctions.

  append l_wa_sales to l_wa_customerssales_datasales.

  cmd_ei_api=>get_number( exporting iv_ktokd = pa_ktokd

                          importing ev_kunnr = l_wa_customersheaderobject_instancekunnr

                                    es_error = l_update_errors ).

  append l_wa_customers to l_wa_maincustomers.

  if l_update_errorsis_error = space.

   clear: l_update_errors.

   cmd_ei_api=>maintain(

      exporting

        iv_test_run    = space

        is_master_data = l_wa_main

      importing

        es_error       l_update_errors ).

   if l_update_errorsis_error = space.

    commit work.

   else.

    rollback work.

   endif.

  endif.

  if l_update_errorsis_error = ‘X’.

    cont_reg_error = cont_reg_error + 1.

    loop at l_update_errorsmessages into l_wa_messages.

     l_wa_log_alvrow_id = p_row_id.

     l_wa_log_alvmsgtyp = l_wa_messagestype.

     call function ‘MESSAGE_TEXT_BUILD’

       exporting

         msgid               = l_wa_messagesid

         msgnr               = l_wa_messagesnumber

         msgv1               = l_wa_messagesmessage_v1

         msgv2               = l_wa_messagesmessage_v2

         msgv3               = l_wa_messagesmessage_v3

         msgv4               = l_wa_messagesmessage_v4

       importing

         message_text_output = l_wa_log_alvmessage.

     append l_wa_log_alv to it_log_alv.

    endloop.

  else.

   l_wa_log_alvrow_id = p_row_id.

   l_wa_log_alvmsgtyp = ‘S’.

   l_wa_log_alvkunnr = l_wa_customersheaderobject_instancekunnr.

   l_wa_log_alvmessage = ‘Cliente creado exitosamente’.

   append l_wa_log_alv to it_log_alv.

  endif.

endform.        


Kind regards.


Jhon Jairo.

To report this post you need to login first.

8 Comments

You must be Logged on to comment or reply to a post.

    1. Jhon Jairo Teran Salazar Post author

      Yes of course, that’s right, it can be much less if you use MOVE-CORRESPONDING, but the point is that using this API is much less code if you use other tecnology like BATCH INPUT, even if you are using MOVE-CORRESPONDING or not.

      I appreciate your comments,

      Kind regards.

      Jhon Jairo.

      (0) 
  1. ayush sethi

    Sir,

    i appreciate your work. I need to provide customer role in business partner. Can i do this by using this code. I will appreciate your reply.

    Regards
    Ayush Sethi

    (0) 
  2. ayush sethi

    Hello sir,

    i am working on s4 hana server so the concept of transaction XD* is obsolete. So we are using BP(Business Partner ) Transaction to create customer. Here i need to update sales and distribution data for a particular roles (FLCU01 which is CUSTOMER and company code data FLCU00 which is FI customer). But i am not able to update these two data through any bapi. pls help me out

    (0) 
  3. ayush sethi

    hi

    Yes sir i have used this bapi only but this is used to create business partner and give roles my requirement is to update sales and distribution data and company code data in bp transaction.

    Moreover i am facing one tragic thing, the details of sales and distribution can be seen in customer tables (KNVV) but they are not getting reflected on BP transaction.

    regards
    Ayush Sethi

    (0) 
  4. Jhon Jairo Teran Salazar Post author

    Hello Ayush, I think if your requirement is to update sales and distribution data you could actually  try to use the class cmd_ei_api, because as you say I understand that this information is saved in KNVV table, the same for KNB1 that saves the company data, it is the same when you create or enhance a customer in XD* transaction.

    Regars.

    Jhon Jairo.

    (0) 

Leave a Reply