Download Create and Change Customer Data Through BAPI Class Method XD01 XD02...
Create/Change Customer Using Class and Method 1. Create Customer DATA DATA DATA DATA
ls_customers_in ls_customers_out ls_customer_in ls_header_in
TYPE TYPE TYPE TYPE
cmds_ei_main. cmds_ei_main. cmds_ei_extern. cmds_ei_header.
*PARAMETERS: P_radio1 RADIOBUTTON GROUP RAD1 DEFAULT 'X' USER-COMMAND RAD, * P_Radio2 RADIOBUTTON GROUP RAD1. PARAMETERS: p_kunnr TYPE kna1-kunnr. PERFORM create. ls_header_in-object_instance-kunnr = p_kunnr. ls_header_in-object_task = cvi_ei_api_map_structure=>gc_modify. ls_customer_in-header = ls_header_in. * Complete interface structure APPEND ls_customer_in TO ls_customers_in-customers. CALL METHOD cmd_ei_api_extract=>get_data EXPORTING is_master_data = ls_customers_in IMPORTING es_master_data = ls_customers_out * es_error = . BREAK-POINT. *&---------------------------------------------------------------------* *& Form create *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM create. DATA: ls_masterdata TYPE ls_customers TYPE ls_customers2 TYPE ls_header_2 TYPE lt_customers TYPE lt_customers2 TYPE * for Exportparameters of Methode ls_master_data_correct TYPE ls_message_correct TYPE ls_master_data_defective TYPE ls_message_defective TYPE
cmds_ei_main, cmds_ei_extern, cmds_ei_extern, cmds_ei_header, cmds_ei_extern_t, cmds_ei_extern_t, cmds_ei_main, cvis_message, cmds_ei_main, cvis_message,
* for Transfer Communication data ls_phone_main TYPE ls_phone TYPE lt_phone TYPE ls_fax_main TYPE ls_fax TYPE lt_fax TYPE ls_mail_main TYPE ls_mail TYPE lt_mail TYPE cust_no TYPE
cvis_ei_cvi_phone, cvis_ei_phone_str, cvis_ei_phone_t, cvis_ei_cvi_fax, cvis_ei_fax_str, cvis_ei_fax_t, cvis_ei_cvi_smtp, cvis_ei_smtp_str, cvis_ei_smtp_t, kunnr.
* Customer number (in case of external creating of numbers) * ls_customers-header-object_instance-kunnr = '0022281958'. * Mark CREATE ls_customers-header-object_task = 'I'. * Fill central data like Customer Account Group ls_customers-central_data-central-data-ktokd = 'ZAG1'. * ls_customers-central_data-central-data-KUKLA = '01'. ls_customers-central_data-central-data-stcd1 = '22281958-K'. ls_customers-central_data-central-data-niels = ' '. ls_customers-central_data-central-datax-ktokd = 'X'. ls_customers-central_data-central-datax-KUKLA = 'X'. ls_customers-central_data-central-datax-stcd1 = 'X'. ls_customers-central_data-central-datax-niels = 'X'. * now address data ls_customers-central_data-address-task = 'I'. * if the FROM date should be filled here , it has also to be filled in all ot her used structures ls_customers-central_data-address-postal-data-from_date = sy-datum. * NAME and SORT1 are Mandatory fields ls_customers-central_data-address-postal-data-name = 'pablo'. ls_customers-central_data-address-postal-data-sort1 = 'pablo'. ls_customers-central_data-address-postal-data-name_2 = 'tapia'. ls_customers-central_data-address-postal-data-city = '2'."city1 ls_customers-central_data-address-postal-data-postl_cod1 = '.'. ls_customers-central_data-address-postal-data-street = '2'. ls_customers-central_data-address-postal-data-country = 'PK'. ls_customers-central_data-address-postal-data-langu = 'E'. ls_customers-central_data-address-postal-data-title = '0002'. ls_customers-central_data-address-postal-data-district = 'santiago'."city2 ls_customers-central_data-address-postal-data-region = '01'. "regio *ls_customers-central_data-address-postal-data-TRANSPZONE = 'Z1340'. * and now mark all used fields ls_customers-central_data-address-postal-datax-from_date = 'X'. ls_customers-central_data-address-postal-datax-to_date = 'X'. ls_customers-central_data-address-postal-datax-name = 'X'. ls_customers-central_data-address-postal-datax-sort1 = 'X'. ls_customers-central_data-address-postal-datax-name_2 = 'X'. ls_customers-central_data-address-postal-datax-city = 'X'. ls_customers-central_data-address-postal-datax-postl_cod1 = 'X'. *
ls_customers-central_data-address-postal-datax-street = 'X'. ls_customers-central_data-address-postal-datax-house_no = 'X'. ls_customers-central_data-address-postal-datax-country = 'X'. ls_customers-central_data-address-postal-datax-langu = 'X'. ls_customers-central_data-address-postal-datax-title = 'X'. ls_customers-central_data-address-postal-datax-district = 'X'. ls_customers-central_data-address-postal-datax-region = 'X'. ls_customers-central_data-address-postal-datax-transpzone = 'X'.
* fill telephon data ls_phone-contact-task = 'I'. ls_phone-contact-data-telephone = '69792'. ls_phone-contact-data-country = 'CL'. ls_phone-contact-data-std_no = 'X'. ls_phone-contact-data-r_3_user = '1'. ls_phone-contact-data-home_flag = 'X'. ls_phone-contact-data-caller_no = '69792'. ls_phone-contact-data-consnumber = '001'. ls_phone-contact-datax-country = 'X'. ls_phone-contact-datax-telephone = 'X'. ls_phone-contact-datax-std_no = 'X'. ls_phone-contact-datax-r_3_user = 'X'. ls_phone-contact-datax-home_flag = 'X'. ls_phone-contact-datax-caller_no = 'X'. ls_phone-contact-datax-consnumber = 'X'. APPEND ls_phone TO lt_phone.
ls_phone-contact-task = 'I'. ls_phone-contact-data-telephone = '9843'. ls_phone-contact-data-country = 'CL'. ls_phone-contact-data-std_no = ' '. ls_phone-contact-data-r_3_user = '3'. ls_phone-contact-data-home_flag = ' '. ls_phone-contact-data-caller_no = '9843'. ls_phone-contact-data-consnumber = '002'. ls_phone-contact-datax-country = 'X'. ls_phone-contact-datax-telephone = 'X'. ls_phone-contact-datax-std_no = 'X'. ls_phone-contact-datax-r_3_user = 'X'. ls_phone-contact-datax-home_flag = 'X'. ls_phone-contact-datax-caller_no = 'X'. ls_phone-contact-datax-consnumber = 'X'. APPEND ls_phone TO lt_phone. ls_phone_main-phone = lt_phone.
* fill fax data
ls_fax-contact-task = 'I'. ls_fax-contact-data-fax = '84380'. ls_fax-contact-data-country = 'CL'. ls_fax-contact-data-home_flag = 'X'. ls_fax-contact-data-consnumber = '001'. ls_fax-contact-data-std_no = 'X'. ls_fax-contact-data-sender_no = '84380'. ls_fax-contact-data-std_no = 'X'.
ls_fax-contact-datax-fax = 'X'. ls_fax-contact-datax-country = 'X'. ls_fax-contact-datax-home_flag = 'X'. ls_fax-contact-datax-consnumber = 'X'. ls_fax-contact-datax-std_no = 'X'. ls_fax-contact-datax-sender_no = 'X'. ls_fax-contact-datax-std_no = 'X'. APPEND ls_fax TO lt_fax. ls_fax_main-fax = lt_fax. * fill mail data ls_mail-contact-task = 'I'. ls_mail-contact-data-e_mail = '
[email protected]'. ls_mail-contact-datax-e_mail = 'X'. APPEND ls_mail TO lt_mail. ls_mail_main-smtp = lt_mail. ls_customers-central_data-address-communication-smtp = ls_mail_main. ls_customers-central_data-address-communication-phone = ls_phone_main . ls_customers-central_data-address-communication-fax = ls_fax_main. APPEND ls_customers TO lt_customers. ls_masterdata-customers = lt_customers. BREAK-POINT. cmd_ei_api=>maintain_bapi( EXPORTING * iv_test_run = 'X' iv_collect_messages = 'X' is_master_data = ls_masterdata IMPORTING es_master_data_correct = ls_master_data_correct es_message_correct = ls_message_correct es_master_data_defective = ls_master_data_defective es_message_defective = ls_message_defective ). * to start booking CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' . READ TABLE ls_master_data_correct-customers INDEX 1 INTO ls_customers2. APPEND ls_customers2 TO lt_customers2. CLEAR ls_customers2.
LOOP AT lt_customers2 INTO ls_customers2. ls_header_2 = ls_customers2-header. cust_no = ls_header_2-object_instance-kunnr. ENDLOOP. WRITE cust_no. BREAK-POINT. ENDFORM.
"create
2. Change Customer *Modify Customer Data DATA DATA DATA DATA
ls_customers_in ls_customers_out ls_customer_in ls_header_in
TYPE TYPE TYPE TYPE
cmds_ei_main. cmds_ei_main. cmds_ei_extern. cmds_ei_header.
PARAMETERS: p_kunnr TYPE kna1-kunnr, p_city TYPE ad_city1 LOWER CASE, p_street TYPE ad_street LOWER CASE, p_tel TYPE ad_tlnmbr, p_mail TYPE ad_smtpadr.
PERFORM create USING p_kunnr. ls_header_in-object_instance-kunnr = p_kunnr. ls_header_in-object_task = cvi_ei_api_map_structure=>gc_modify. ls_customer_in-header = ls_header_in. * Complete interface structure APPEND ls_customer_in TO ls_customers_in-customers. CALL METHOD cmd_ei_api_extract=>get_data EXPORTING is_master_data = ls_customers_in IMPORTING es_master_data = ls_customers_out * es_error = . BREAK-POINT. FORM create USING p_kunnr. DATA: ls_masterdata TYPE cmds_ei_main, ls_customers TYPE cmds_ei_extern, lt_customers TYPE cmds_ei_extern_t, * for Exportparameters of Methode ls_master_data_correct TYPE cmds_ei_main, ls_message_correct TYPE cvis_message,
ls_master_data_defective TYPE ls_message_defective TYPE * for Transfer Communication data ls_phone_main TYPE ls_phone TYPE lt_phone TYPE ls_fax_main TYPE ls_fax TYPE lt_fax TYPE ls_mail_main TYPE ls_mail TYPE lt_mail TYPE
cmds_ei_main, cvis_message, cvis_ei_cvi_phone, cvis_ei_phone_str, cvis_ei_phone_t, cvis_ei_cvi_fax, cvis_ei_fax_str, cvis_ei_fax_t, cvis_ei_cvi_smtp, cvis_ei_smtp_str, cvis_ei_smtp_t.
* Customer number (in case of external creating of numbers) ls_customers-header-object_instance-kunnr = p_kunnr. * Mark CREATE ls_customers-header-object_task = 'U'. * Fill central data like Customer Account Group * ls_customers-central_data-central-data-ktokd = 'CLNA'. * ls_customers-central_data-central-data-KUKLA = '01'. * ls_customers-central_data-central-data-stcd1 = '22281958-K'. * ls_customers-central_data-central-data-GFORM = '02'. * *ls_customers-central_data-central-datax-ktokd = 'X'. * ls_customers-central_data-central-datax-KUKLA = 'X'. * ls_customers-central_data-central-datax-stcd1 = 'X'. * ls_customers-central_data-central-datax-GFORM = 'X'. * now address data ls_customers-central_data-address-task = 'U'. * if the FROM date should be filled here , it has also to be filled in *all other used structures ls_customers-central_data-address-postal-data-from_date = sy-datum. * NAME and SORT1 are Mandatory fields ls_customers-central_data-address-postal-data-city = p_city. "city1 ls_customers-central_data-address-postal-data-street = p_street. * and now mark all used fields ls_customers-central_data-address-postal-datax-city = 'X'. ls_customers-central_data-address-postal-datax-street = 'X'.
* fill telephon data ls_phone-contact-task = 'U'. ls_phone-contact-data-telephone = p_tel. ls_phone-contact-data-country = 'CL'. ls_phone-contact-data-std_no = 'X'. ls_phone-contact-data-r_3_user = '1'. ls_phone-contact-data-home_flag = 'X'.
ls_phone-contact-data-caller_no = p_tel. *ls_phone-contact-data-CONSNUMBER = '001'. ls_phone-contact-datax-country = 'X'. ls_phone-contact-datax-telephone = 'X'. ls_phone-contact-datax-std_no = 'X'. ls_phone-contact-datax-r_3_user = 'X'. ls_phone-contact-datax-home_flag = 'X'. ls_phone-contact-datax-caller_no = 'X'. *ls_phone-contact-datax-CONSNUMBER = 'X'. APPEND ls_phone TO lt_phone. ls_phone_main-phone = lt_phone. * fill mail data ls_mail-contact-task = 'U'. ls_mail-contact-data-e_mail = p_mail. ls_mail-contact-datax-e_mail = 'X'. APPEND ls_mail TO lt_mail. ls_mail_main-smtp = lt_mail. ls_customers-central_data-address-communication-smtp = ls_mail_main. ls_customers-central_data-address-communication-phone = ls_phone_main . *ls_customers-central_data-address-communication-fax = ls_fax_main. APPEND ls_customers TO lt_customers. ls_masterdata-customers = lt_customers. BREAK-POINT. cmd_ei_api=>maintain_bapi( EXPORTING *iv_test_run = 'X' iv_collect_messages = 'X' is_master_data = ls_masterdata IMPORTING es_master_data_correct = ls_master_data_correct es_message_correct = ls_message_correct es_master_data_defective = ls_master_data_defective es_message_defective = ls_message_defective ). * to start booking CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' . BREAK-POINT. ENDFORM.