FUNCTION zzmm_vendor_create.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" TABLES
*" I_DATA STRUCTURE ZMM_VENDOR_LOG
*"----------------------------------------------------------------------
CONSTANTS:
g_object_task_i TYPE bus_ei_object_task VALUE 'I'.
DATA: lv_tabix TYPE sy-tabix,
lt_data TYPE cvis_ei_extern_t,
ls_data TYPE cvis_ei_extern,
lt_return TYPE bapiretm,
ls_return TYPE bapireti,
ls_msg TYPE bapiretc,
ls_partner TYPE bus_ei_extern,
ls_vendor TYPE vmds_ei_extern,
lt_roles TYPE bus_ei_bupa_roles_t,
ls_roles TYPE bus_ei_bupa_roles,
lt_addresses TYPE bus_ei_bupa_address_t,
ls_addresses TYPE bus_ei_bupa_address,
lt_phone TYPE bus_ei_bupa_telephone_t,
ls_phone TYPE bus_ei_bupa_telephone,
lt_remarks TYPE bus_ei_bupa_comrem_t,
ls_remarks TYPE bus_ei_bupa_comrem,
lt_bankdetails TYPE bus_ei_bupa_bankdetail_t,
ls_bankdetails TYPE bus_ei_bupa_bankdetail,
lt_company TYPE vmds_ei_company_t,
ls_company TYPE vmds_ei_company,
lt_purchasing TYPE vmds_ei_purchasing_t,
ls_purchasing TYPE vmds_ei_purchasing,
lt_functions TYPE vmds_ei_functions_t,
ls_functions TYPE vmds_ei_functions,
lv_partner_guid TYPE bu_partner_guid,
ls_cvis_error TYPE cvis_error,
lt_bapiret2 TYPE bapiret2_t,
ls_bapiret2 TYPE bapiret2,
* 根据伙伴GUID取出供应商编号
lt_partnerguid_list TYPE bu_partner_guid_t,
ls_partnerguid_list TYPE bu_partner_guid,
lt_vendor_list TYPE cvis_vend_link_t,
ls_vendor_list TYPE cvi_vend_link..
DATA: l_str TYPE string.
zfmparavalsave1 'ZZMM_VENDOR_CREATE'.
zfmparavalsave2 'B'.
LOOP AT i_data.
CLEAR:
ls_data,
lt_data.
lv_tabix = sy-tabix.
IF i_data-title_medi IS INITIAL.
i_data-title_medi = '0003'.
ENDIF.
IF i_data-spras IS INITIAL.
i_data-spras = sy-langu.
ENDIF.
IF i_data-bukrs IS INITIAL.
i_data-bukrs = '1000'.
ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = i_data-lifnr
IMPORTING
output = i_data-lifnr.
SELECT SINGLE but000~partner
INTO ls_partner-header-object_instance-bpartner
FROM but000
WHERE partner = i_data-lifnr.
IF sy-subrc = 0.
i_data-zis_ok = '4'.
i_data-msg = '供应商' && i_data-lifnr && '已存在!'.
MODIFY i_data INDEX lv_tabix.
RETURN.
ENDIF.
TRY .
lv_partner_guid = cl_uuid_factory=>create_system_uuid( )->create_uuid_x16( ).
CATCH cx_uuid_error.
"返回消息
ENDTRY.
"基本信息
ls_partner-header-object_task = g_object_task_i.
ls_partner-header-object_instance-bpartner = i_data-lifnr.
ls_partner-header-object_instance-bpartnerguid = lv_partner_guid.
****业务合作伙伴数据的中心数据***********************************
ls_partner-central_data-common-data-bp_control-category = 2. "业务伙伴类别
ls_partner-central_data-common-data-bp_control-grouping = i_data-ktokk. "业务伙伴分组
ls_partner-central_data-common-data-bp_centraldata-title_key = i_data-title_medi. "称谓
ls_partner-central_data-common-data-bp_centraldata-searchterm1 = i_data-sortl. "检索项
ls_partner-central_data-common-data-bp_organization-name1 = i_data-vender. "供应商名称
ls_partner-central_data-common-data-bp_organization-name2 = i_data-zbz1. "供应商名称
ls_partner-central_data-common-datax-bp_centraldata-searchterm1 = abap_true.
ls_partner-central_data-common-datax-bp_organization-name1 = abap_true.
ls_partner-central_data-common-datax-bp_organization-name2 = abap_true.
CLEAR:lt_roles.
ls_roles-task = 'I'.
ls_roles-data_key = 'ZLVN00'. "采购角色
APPEND ls_roles TO lt_roles.
ls_roles-task = 'I'.
ls_roles-data_key = 'ZLVN01'. "公司角色
APPEND ls_roles TO lt_roles.
ls_partner-central_data-role-roles = lt_roles.
"地址信息
CLEAR lt_addresses.
ls_addresses-task = g_object_task_i.
ls_addresses-data-postal-data-street = i_data-stras. "街道
ls_addresses-data-postal-data-country = i_data-land1. "国家
ls_addresses-data-postal-data-langu = i_data-spras. "语言
ls_addresses-data-postal-datax-street = abap_true.
ls_addresses-data-postal-datax-country = abap_true.
ls_addresses-data-postal-datax-langu = abap_true.
"手机
CLEAR lt_phone.
ls_phone-contact-task = g_object_task_i.
ls_phone-contact-data-telephone = i_data-telf1. "电话1
ls_phone-contact-data-r_3_user = '3'. "移动电话
ls_phone-contact-datax-telephone = abap_true.
ls_phone-contact-datax-r_3_user = abap_true.
"手机备注1(联系人)
CLEAR lt_remarks.
ls_remarks-task = g_object_task_i.
ls_remarks-data-langu = i_data-spras.
ls_remarks-data-comm_notes = i_data-contacts.
ls_remarks-datax-langu = abap_true.
ls_remarks-datax-comm_notes = abap_true.
APPEND ls_remarks TO lt_remarks.
ls_phone-remark-remarks = lt_remarks.
APPEND ls_phone TO lt_phone.
ls_addresses-data-communication-phone-phone = lt_phone.
APPEND ls_addresses TO lt_addresses.
ls_partner-central_data-address-addresses = lt_addresses.
"银行信息
CLEAR lt_bankdetails.
IF i_data-banks IS NOT INITIAL.
ls_bankdetails-task = g_object_task_i.
ls_bankdetails-data_key = '0001'.
ls_bankdetails-data-bank_ctry = i_data-banks.
ls_bankdetails-data-bank_key = i_data-bankl.
ls_bankdetails-data-bank_acct = i_data-bankn.
ls_bankdetails-data-accountholder = i_data-koinh.
ls_bankdetails-data-bankaccountname = i_data-accname.
ls_bankdetails-datax-bank_ctry = abap_true.
ls_bankdetails-datax-bank_key = abap_true.
ls_bankdetails-datax-bank_acct = abap_true.
ls_bankdetails-datax-accountholder = abap_true.
ls_bankdetails-datax-bankaccountname = abap_true.
APPEND ls_bankdetails TO lt_bankdetails.
ls_partner-central_data-bankdetail-bankdetails = lt_bankdetails.
ENDIF.
ls_vendor-header-object_instance-lifnr = i_data-lifnr.
ls_vendor-header-object_task = g_object_task_i.
****公司代码数据************************************************
CLEAR:lt_company.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' " 统驭科目补零
EXPORTING
input = i_data-akont
IMPORTING
output = i_data-akont.
ls_company-task = g_object_task_i.
ls_company-data_key-bukrs = i_data-bukrs. "公司代码
ls_company-data-akont = i_data-akont. "统驭科目
ls_company-data-zuawa = i_data-zuawa. "排序码
ls_company-data-zterm = i_data-zterm. "付款条件
ls_company-data-reprf = i_data-reprf. "检查重复发票
ls_company-datax-akont = abap_true.
ls_company-datax-zuawa = abap_true.
ls_company-datax-zterm = abap_true.
ls_company-datax-reprf = abap_true.
APPEND ls_company TO lt_company.
ls_vendor-company_data-company = lt_company.
****采购数据****************************************************
CLEAR:lt_purchasing.
ls_purchasing-task = g_object_task_i.
ls_purchasing-data_key-ekorg = i_data-ekorg. "采购组织
ls_purchasing-data-waers = i_data-waers. "货币
ls_purchasing-data-webre = i_data-webre. "基于收货的发票校验
ls_purchasing-data-zterm = i_data-zterm. "付款条件
ls_purchasing-data-ekgrp = i_data-ekgrp.
ls_purchasing-datax-waers = abap_true.
ls_purchasing-datax-webre = abap_true.
ls_purchasing-datax-zterm = abap_true.
ls_purchasing-datax-ekgrp = abap_true.
CLEAR lt_functions.
ls_functions-task = g_object_task_i.
ls_functions-data_key-parvw = 'BA'. " PANERFUNCTION中 OA 对应的输出是 BA
ls_functions-data-partner = i_data-lifnr.
ls_functions-datax-partner = abap_true.
APPEND ls_functions TO lt_functions.
ls_functions-task = g_object_task_i.
ls_functions-data_key-parvw = 'RS'. " PANERFUNCTION中 RS 对应的输出是 PI
ls_functions-data-partner = i_data-lifnr.
ls_functions-datax-partner = abap_true.
APPEND ls_functions TO lt_functions.
ls_functions-task = g_object_task_i.
ls_functions-data_key-parvw = 'LF'. " PANERFUNCTION中 LF 对应的输出是 VN
ls_functions-data-partner = i_data-lifnr.
ls_functions-datax-partner = abap_true.
APPEND ls_functions TO lt_functions.
ls_purchasing-functions-functions = lt_functions.
APPEND ls_purchasing TO lt_purchasing.
ls_vendor-purchasing_data-purchasing = lt_purchasing.
ls_data-partner = ls_partner.
ls_data-vendor = ls_vendor.
* ls_data-ensure_create-create_vendor = abap_true.
APPEND ls_data TO lt_data.
cl_md_bp_maintain=>maintain(
EXPORTING
i_data = lt_data
IMPORTING
e_return = lt_return ).
CLEAR i_data-msg.
LOOP AT lt_return INTO ls_return.
LOOP AT ls_return-object_msg INTO ls_msg WHERE type = 'E' OR type = 'A'.
CONCATENATE i_data-msg ls_msg-message INTO i_data-msg.
ENDLOOP.
ENDLOOP.
IF i_data-msg IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
* 根据伙伴GUID取出供应商编号
CLEAR: lt_partnerguid_list,lt_vendor_list.
ls_partnerguid_list = ls_partner-header-object_instance-bpartnerguid.
APPEND ls_partnerguid_list TO lt_partnerguid_list.
lt_vendor_list = cvi_mapper=>get_instance( )->get_assigned_vendors_for_bps(
i_partner_guids = lt_partnerguid_list ).
IF lt_vendor_list IS NOT INITIAL.
READ TABLE lt_vendor_list INTO ls_vendor_list INDEX 1 .
IF sy-subrc EQ 0.
CONCATENATE '供应商' ls_vendor_list-vendor '创建成功!' INTO i_data-msg.
i_data-lifnr = ls_vendor_list-vendor.
i_data-zis_ok = '0'.
ENDIF.
ELSE.
"可能创建成功了BP,但未创建成功Vendor
ls_cvis_error = cvi_mapper=>get_instance( )->undo_assignments(
i_for_partners = lt_partnerguid_list ).
i_data-msg = '供应商创建出错,供应商部分数据出错,请检查是否是BP伙伴功能问题'.
i_data-zis_ok = '4'.
ENDIF.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
i_data-zis_ok = '4'.
ENDIF.
SHIFT i_data-lifnr LEFT DELETING LEADING '0'.
SHIFT i_data-akont LEFT DELETING LEADING '0'.
MODIFY i_data INDEX lv_tabix.
ENDLOOP.
MODIFY zmm_vendor_log FROM TABLE i_data.
zfmparavalsave2 'R'.
ENDFUNCTION.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" TABLES
*" I_DATA STRUCTURE ZMM_VENDOR_LOG
*"----------------------------------------------------------------------
CONSTANTS:
g_object_task_i TYPE bus_ei_object_task VALUE 'I'.
DATA: lv_tabix TYPE sy-tabix,
lt_data TYPE cvis_ei_extern_t,
ls_data TYPE cvis_ei_extern,
lt_return TYPE bapiretm,
ls_return TYPE bapireti,
ls_msg TYPE bapiretc,
ls_partner TYPE bus_ei_extern,
ls_vendor TYPE vmds_ei_extern,
lt_roles TYPE bus_ei_bupa_roles_t,
ls_roles TYPE bus_ei_bupa_roles,
lt_addresses TYPE bus_ei_bupa_address_t,
ls_addresses TYPE bus_ei_bupa_address,
lt_phone TYPE bus_ei_bupa_telephone_t,
ls_phone TYPE bus_ei_bupa_telephone,
lt_remarks TYPE bus_ei_bupa_comrem_t,
ls_remarks TYPE bus_ei_bupa_comrem,
lt_bankdetails TYPE bus_ei_bupa_bankdetail_t,
ls_bankdetails TYPE bus_ei_bupa_bankdetail,
lt_company TYPE vmds_ei_company_t,
ls_company TYPE vmds_ei_company,
lt_purchasing TYPE vmds_ei_purchasing_t,
ls_purchasing TYPE vmds_ei_purchasing,
lt_functions TYPE vmds_ei_functions_t,
ls_functions TYPE vmds_ei_functions,
lv_partner_guid TYPE bu_partner_guid,
ls_cvis_error TYPE cvis_error,
lt_bapiret2 TYPE bapiret2_t,
ls_bapiret2 TYPE bapiret2,
* 根据伙伴GUID取出供应商编号
lt_partnerguid_list TYPE bu_partner_guid_t,
ls_partnerguid_list TYPE bu_partner_guid,
lt_vendor_list TYPE cvis_vend_link_t,
ls_vendor_list TYPE cvi_vend_link..
DATA: l_str TYPE string.
zfmparavalsave1 'ZZMM_VENDOR_CREATE'.
zfmparavalsave2 'B'.
LOOP AT i_data.
CLEAR:
ls_data,
lt_data.
lv_tabix = sy-tabix.
IF i_data-title_medi IS INITIAL.
i_data-title_medi = '0003'.
ENDIF.
IF i_data-spras IS INITIAL.
i_data-spras = sy-langu.
ENDIF.
IF i_data-bukrs IS INITIAL.
i_data-bukrs = '1000'.
ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = i_data-lifnr
IMPORTING
output = i_data-lifnr.
SELECT SINGLE but000~partner
INTO ls_partner-header-object_instance-bpartner
FROM but000
WHERE partner = i_data-lifnr.
IF sy-subrc = 0.
i_data-zis_ok = '4'.
i_data-msg = '供应商' && i_data-lifnr && '已存在!'.
MODIFY i_data INDEX lv_tabix.
RETURN.
ENDIF.
TRY .
lv_partner_guid = cl_uuid_factory=>create_system_uuid( )->create_uuid_x16( ).
CATCH cx_uuid_error.
"返回消息
ENDTRY.
"基本信息
ls_partner-header-object_task = g_object_task_i.
ls_partner-header-object_instance-bpartner = i_data-lifnr.
ls_partner-header-object_instance-bpartnerguid = lv_partner_guid.
****业务合作伙伴数据的中心数据***********************************
ls_partner-central_data-common-data-bp_control-category = 2. "业务伙伴类别
ls_partner-central_data-common-data-bp_control-grouping = i_data-ktokk. "业务伙伴分组
ls_partner-central_data-common-data-bp_centraldata-title_key = i_data-title_medi. "称谓
ls_partner-central_data-common-data-bp_centraldata-searchterm1 = i_data-sortl. "检索项
ls_partner-central_data-common-data-bp_organization-name1 = i_data-vender. "供应商名称
ls_partner-central_data-common-data-bp_organization-name2 = i_data-zbz1. "供应商名称
ls_partner-central_data-common-datax-bp_centraldata-searchterm1 = abap_true.
ls_partner-central_data-common-datax-bp_organization-name1 = abap_true.
ls_partner-central_data-common-datax-bp_organization-name2 = abap_true.
CLEAR:lt_roles.
ls_roles-task = 'I'.
ls_roles-data_key = 'ZLVN00'. "采购角色
APPEND ls_roles TO lt_roles.
ls_roles-task = 'I'.
ls_roles-data_key = 'ZLVN01'. "公司角色
APPEND ls_roles TO lt_roles.
ls_partner-central_data-role-roles = lt_roles.
"地址信息
CLEAR lt_addresses.
ls_addresses-task = g_object_task_i.
ls_addresses-data-postal-data-street = i_data-stras. "街道
ls_addresses-data-postal-data-country = i_data-land1. "国家
ls_addresses-data-postal-data-langu = i_data-spras. "语言
ls_addresses-data-postal-datax-street = abap_true.
ls_addresses-data-postal-datax-country = abap_true.
ls_addresses-data-postal-datax-langu = abap_true.
"手机
CLEAR lt_phone.
ls_phone-contact-task = g_object_task_i.
ls_phone-contact-data-telephone = i_data-telf1. "电话1
ls_phone-contact-data-r_3_user = '3'. "移动电话
ls_phone-contact-datax-telephone = abap_true.
ls_phone-contact-datax-r_3_user = abap_true.
"手机备注1(联系人)
CLEAR lt_remarks.
ls_remarks-task = g_object_task_i.
ls_remarks-data-langu = i_data-spras.
ls_remarks-data-comm_notes = i_data-contacts.
ls_remarks-datax-langu = abap_true.
ls_remarks-datax-comm_notes = abap_true.
APPEND ls_remarks TO lt_remarks.
ls_phone-remark-remarks = lt_remarks.
APPEND ls_phone TO lt_phone.
ls_addresses-data-communication-phone-phone = lt_phone.
APPEND ls_addresses TO lt_addresses.
ls_partner-central_data-address-addresses = lt_addresses.
"银行信息
CLEAR lt_bankdetails.
IF i_data-banks IS NOT INITIAL.
ls_bankdetails-task = g_object_task_i.
ls_bankdetails-data_key = '0001'.
ls_bankdetails-data-bank_ctry = i_data-banks.
ls_bankdetails-data-bank_key = i_data-bankl.
ls_bankdetails-data-bank_acct = i_data-bankn.
ls_bankdetails-data-accountholder = i_data-koinh.
ls_bankdetails-data-bankaccountname = i_data-accname.
ls_bankdetails-datax-bank_ctry = abap_true.
ls_bankdetails-datax-bank_key = abap_true.
ls_bankdetails-datax-bank_acct = abap_true.
ls_bankdetails-datax-accountholder = abap_true.
ls_bankdetails-datax-bankaccountname = abap_true.
APPEND ls_bankdetails TO lt_bankdetails.
ls_partner-central_data-bankdetail-bankdetails = lt_bankdetails.
ENDIF.
ls_vendor-header-object_instance-lifnr = i_data-lifnr.
ls_vendor-header-object_task = g_object_task_i.
****公司代码数据************************************************
CLEAR:lt_company.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' " 统驭科目补零
EXPORTING
input = i_data-akont
IMPORTING
output = i_data-akont.
ls_company-task = g_object_task_i.
ls_company-data_key-bukrs = i_data-bukrs. "公司代码
ls_company-data-akont = i_data-akont. "统驭科目
ls_company-data-zuawa = i_data-zuawa. "排序码
ls_company-data-zterm = i_data-zterm. "付款条件
ls_company-data-reprf = i_data-reprf. "检查重复发票
ls_company-datax-akont = abap_true.
ls_company-datax-zuawa = abap_true.
ls_company-datax-zterm = abap_true.
ls_company-datax-reprf = abap_true.
APPEND ls_company TO lt_company.
ls_vendor-company_data-company = lt_company.
****采购数据****************************************************
CLEAR:lt_purchasing.
ls_purchasing-task = g_object_task_i.
ls_purchasing-data_key-ekorg = i_data-ekorg. "采购组织
ls_purchasing-data-waers = i_data-waers. "货币
ls_purchasing-data-webre = i_data-webre. "基于收货的发票校验
ls_purchasing-data-zterm = i_data-zterm. "付款条件
ls_purchasing-data-ekgrp = i_data-ekgrp.
ls_purchasing-datax-waers = abap_true.
ls_purchasing-datax-webre = abap_true.
ls_purchasing-datax-zterm = abap_true.
ls_purchasing-datax-ekgrp = abap_true.
CLEAR lt_functions.
ls_functions-task = g_object_task_i.
ls_functions-data_key-parvw = 'BA'. " PANERFUNCTION中 OA 对应的输出是 BA
ls_functions-data-partner = i_data-lifnr.
ls_functions-datax-partner = abap_true.
APPEND ls_functions TO lt_functions.
ls_functions-task = g_object_task_i.
ls_functions-data_key-parvw = 'RS'. " PANERFUNCTION中 RS 对应的输出是 PI
ls_functions-data-partner = i_data-lifnr.
ls_functions-datax-partner = abap_true.
APPEND ls_functions TO lt_functions.
ls_functions-task = g_object_task_i.
ls_functions-data_key-parvw = 'LF'. " PANERFUNCTION中 LF 对应的输出是 VN
ls_functions-data-partner = i_data-lifnr.
ls_functions-datax-partner = abap_true.
APPEND ls_functions TO lt_functions.
ls_purchasing-functions-functions = lt_functions.
APPEND ls_purchasing TO lt_purchasing.
ls_vendor-purchasing_data-purchasing = lt_purchasing.
ls_data-partner = ls_partner.
ls_data-vendor = ls_vendor.
* ls_data-ensure_create-create_vendor = abap_true.
APPEND ls_data TO lt_data.
cl_md_bp_maintain=>maintain(
EXPORTING
i_data = lt_data
IMPORTING
e_return = lt_return ).
CLEAR i_data-msg.
LOOP AT lt_return INTO ls_return.
LOOP AT ls_return-object_msg INTO ls_msg WHERE type = 'E' OR type = 'A'.
CONCATENATE i_data-msg ls_msg-message INTO i_data-msg.
ENDLOOP.
ENDLOOP.
IF i_data-msg IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
* 根据伙伴GUID取出供应商编号
CLEAR: lt_partnerguid_list,lt_vendor_list.
ls_partnerguid_list = ls_partner-header-object_instance-bpartnerguid.
APPEND ls_partnerguid_list TO lt_partnerguid_list.
lt_vendor_list = cvi_mapper=>get_instance( )->get_assigned_vendors_for_bps(
i_partner_guids = lt_partnerguid_list ).
IF lt_vendor_list IS NOT INITIAL.
READ TABLE lt_vendor_list INTO ls_vendor_list INDEX 1 .
IF sy-subrc EQ 0.
CONCATENATE '供应商' ls_vendor_list-vendor '创建成功!' INTO i_data-msg.
i_data-lifnr = ls_vendor_list-vendor.
i_data-zis_ok = '0'.
ENDIF.
ELSE.
"可能创建成功了BP,但未创建成功Vendor
ls_cvis_error = cvi_mapper=>get_instance( )->undo_assignments(
i_for_partners = lt_partnerguid_list ).
i_data-msg = '供应商创建出错,供应商部分数据出错,请检查是否是BP伙伴功能问题'.
i_data-zis_ok = '4'.
ENDIF.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
i_data-zis_ok = '4'.
ENDIF.
SHIFT i_data-lifnr LEFT DELETING LEADING '0'.
SHIFT i_data-akont LEFT DELETING LEADING '0'.
MODIFY i_data INDEX lv_tabix.
ENDLOOP.
MODIFY zmm_vendor_log FROM TABLE i_data.
zfmparavalsave2 'R'.
ENDFUNCTION.