‎2011 Nov 15 4:27 PM
Hi all,
I try to use class cmd_ei_api to create customer. It works fine but one thing is strange.
When I pass data with test run and customer is in a group with internal nummering system icrease number every time when i run program. Customer is not created ( that is good) but the assigned nummer is lost.
I tried to use method maintain_bapi and maintain.Problem occurs every time.
Do you have the same problem? Do you know solution of this problem?
regards,
JG
SAMPLE CODE:
report zcreate_customer.
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_company_code_st type cmds_ei_company,
wa_company_code type cmds_ei_cmd_company,
wa_functions_st type cmds_ei_functions,
wa_functions_t type CMDS_EI_FUNCTIONS_T,
wa_functions type cmds_ei_cmd_functions,
wa_sales_data_st type cmds_ei_sales,
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.
constants: c_update type c value 'M',
c_insert type c value 'I'.
PARAMETERS: p_test type c as CHECKBOX DEFAULT 'X'.
start-of-selection.
free: wa_customer, wa_company_code_st, wa_customer.
wa_address-name = 'CUSTOMER NAME'.
wa_address-city = 'CITY'.
wa_address-postl_cod1 = '28-500'.
wa_address-street = '1400 9TH ST W'.
wa_address-country = 'PL'.
wa_address-langu = 'L'.
wa_address-region = 'FL'.
wa_address-sort1 = 'SORT1'.
wa_address-sort2 = 'Sort2'.
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-region = 'X'.
wa_addressx-sort1 = 'X'.
wa_addressx-sort2 = 'X'.
wa_customer-central_data-address-postal-datax = wa_addressx.
wa_customer-central_data-central-data-ktokd = 'OKRA'.
wa_customer-central_data-central-data-STCD1 = '8291004247'.
wa_company_code_st-task = c_insert.
wa_company_code_st-data_key-bukrs = '1000'.
wa_company_code_st-data-zuawa = '009'.
wa_company_code_st-data-akont = '0000201100'.
append wa_company_code_st to wa_company_code-company.
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 and p_test is INITIAL.
commit work AND WAIT.
else.
ROLLBACK work.
endif.
‎2011 Nov 15 5:25 PM
I do not know the method that you use, but when I create customers thru IDOC method then I use function module NUMBER_GET_NEXT to get a number from internal number range, I then create write a record into a Z-table for cross reference purposes.
I always check this Z-table if there is already a number assigned before I call this function module.
So I can do several test runs and I always get the same numbers. if I want new numbers, then I just delete the cross reference entries from the z-table
‎2011 Nov 15 5:25 PM
I do not know the method that you use, but when I create customers thru IDOC method then I use function module NUMBER_GET_NEXT to get a number from internal number range, I then create write a record into a Z-table for cross reference purposes.
I always check this Z-table if there is already a number assigned before I call this function module.
So I can do several test runs and I always get the same numbers. if I want new numbers, then I just delete the cross reference entries from the z-table
‎2011 Nov 16 6:15 PM
At the begining I don't give number in test run. In this class is method get number or something like that. Unfortunately in test run when you don't give number the next number from range is used and it is reserved. In my opinion it is weird.
Solution this problem is simple. When you put any number in test run it will be good. In my test Vendor numbering range was between 10000 to 20000. I put number 1 in test run and class works fine.
JG
‎2013 Apr 05 12:03 AM
Hi experts, I am using cmd_ei_api to create customer. Each time when I create the customer, for the customer number KUNNR, first the method picks a new number from number range, if I don't supply one in program. Then it makes the necessary checks on customer data. If data check is success, customer is created and everything is okay. But if the check is failed, no customer gets created in the Data base, but the picked number is lost forever. Is there a way to avoid this?
The same happens, even when I ran it in Test Mode(iv_test_run = 'X'). A number is lost irrespective of whether the test run is success or not.
I tried supplying the customer number via the program. I this case also, I had to get a number from the Number Range and supply. As the Method validates whether the supplied number belongs to the right number range, I cannot use any dummy number(not even for a Test run). Also it validates whether a customer exists in KNA1 with the supplied number.
As a work around, now I am supplying the last number of the number range for the test run(which I have hard coded ~not a good practice!!). If this runs error free, I will pick a new number and creates the customer.
regards,
anish
sample code...
*-- Fill customer parameters to lwa_master_data
lwa_customer-header-object_instance-kunnr = '99999'.
* ***
* *** ~~
*-- Test Run with dummy customer no. for data check
IF lwa_master_data IS NOT INITIAL.
CALL METHOD cmd_ei_api=>maintain
EXPORTING
iv_test_run = 'X'
is_master_data = lwa_master_data
IMPORTING
es_error = lwa_es_error.
*-- Create customer if Test Run Succeeds.
IF lwa_es_error is INITIAL.
*-- Get new Customer Number
CALL METHOD cmd_ei_api=>get_number
EXPORTING
iv_ktokd = as_customer-ktokd
IMPORTING
ev_kunnr = lv_kunnr
es_error = lwa_getno_msg.
IF lv_kunnr is NOT INITIAL.
*-- Supply new customer number
CLEAR: lwa_master_data, lt_customer.
lwa_customer-header-object_instance-kunnr = lv_kunnr.
APPEND lwa_customer TO lt_customer.
CLEAR lwa_customer.
lwa_master_data-customers = lt_customer.
*-- Initialize Global and Current Customer Buffer
CALL METHOD cmd_ei_api=>initialize.
*-- Create Customer
CALL METHOD cmd_ei_api=>maintain
EXPORTING
iv_test_run = ''
is_master_data = lwa_master_data
IMPORTING
es_error = lwa_es_error.
*-- Proceed if no error with customer creation
IF lwa_es_error is INITIAL.
* ******************* * ******************* ~~