FUNCTION zzmm_vendor_update.
*"----------------------------------------------------------------------
*"*"本地接口:
*" TABLES
*" U_DATA STRUCTURE ZMM_VENDOR_LOG
*"----------------------------------------------------------------------
CONSTANTS:
g_object_task_c TYPE bus_ei_object_task VALUE 'C',
g_object_task_m TYPE bus_ei_object_task VALUE 'M',
g_object_task_d TYPE bus_ei_object_task VALUE 'D'.
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_functions TYPE vmds_ei_functions_t,
ls_functions TYPE vmds_ei_functions,
lt_purchasing TYPE vmds_ei_purchasing_t,
ls_purchasing TYPE vmds_ei_purchasing,
lt_vendor_phone type CVIS_EI_PHONE_T,
ls_vendor_phone type CVIS_EI_PHONE,
lv_partner_guid TYPE bu_partner_guid,
lt_but0bk TYPE TABLE OF but0bk,
ls_but0bk TYPE but0bk,
lt_but020 TYPE TABLE OF but020,
ls_but020 TYPE but020.
zfmparavalsave1 'ZZMM_VENDOR_UPDATE'.
zfmparavalsave2 'B'.
LOOP AT u_data.
CLEAR:
ls_data,
lt_data,
ls_partner,
ls_vendor.
lv_tabix = sy-tabix.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = u_data-lifnr
IMPORTING
output = u_data-lifnr.
"基本信息
ls_partner-header-object_task = g_object_task_c.
ls_partner-header-object_instance-bpartner = u_data-lifnr.
SELECT SINGLE partner_guid
INTO lv_partner_guid
FROM but000
WHERE partner = u_data-lifnr.
ls_partner-header-object_instance-bpartnerguid = lv_partner_guid.
ls_partner-central_data-common-data-bp_centraldata-title_key = u_data-title_medi.
ls_partner-central_data-common-data-bp_centraldata-searchterm1 = u_data-sortl.
ls_partner-central_data-common-data-bp_organization-name1 = u_data-vender.
ls_partner-central_data-common-data-bp_organization-name2 = u_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 = g_object_task_c.
ls_roles-data_key = 'ZLVN00'. "采购角色
APPEND ls_roles TO lt_roles.
ls_roles-task = g_object_task_c.
ls_roles-data_key = 'ZLVN01'. "公司角色
APPEND ls_roles TO lt_roles.
ls_partner-central_data-role-roles = lt_roles.
"地址信息
CLEAR: ls_but020,ls_but020.
SELECT *
INTO TABLE lt_but020
FROM but020
WHERE partner = u_data-lifnr.
"取最新地址guid
SORT lt_but020 BY partner addrnumber DESCENDING.
READ TABLE lt_but020 INTO ls_but020 INDEX 1.
CLEAR lt_addresses.
ls_addresses-task = g_object_task_m.
ls_addresses-data_key-guid = ls_but020-address_guid.
ls_addresses-data-postal-data-street = u_data-stras. "街道
ls_addresses-data-postal-data-country = u_data-land1. "国家
ls_addresses-data-postal-data-langu = u_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_c.
ls_phone-contact-data-telephone = u_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_c.
ls_remarks-data-langu = u_data-spras.
ls_remarks-data-comm_notes = u_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.
"银行信息
"先删除已存在的银行信息
IF u_data-banks IS NOT INITIAL.
CLEAR lt_but0bk.
SELECT *
INTO TABLE lt_but0bk
FROM but0bk
WHERE partner = u_data-lifnr.
LOOP AT lt_but0bk INTO ls_but0bk.
ls_bankdetails-task = g_object_task_d.
ls_bankdetails-data_key = ls_but0bk-bkvid.
APPEND ls_bankdetails TO lt_bankdetails.
ENDLOOP.
CLEAR lt_bankdetails.
ls_bankdetails-task = g_object_task_c.
ls_bankdetails-data_key = '0001'.
ls_bankdetails-data-bank_ctry = u_data-banks.
ls_bankdetails-data-bank_key = u_data-bankl.
ls_bankdetails-data-bank_acct = u_data-bankn.
ls_bankdetails-data-accountholder = u_data-koinh.
ls_bankdetails-data-bankaccountname = u_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 = u_data-lifnr.
ls_vendor-header-object_task = g_object_task_c.
"如果不更新以下数据,LFA1中的数据不会更新
ls_vendor-central_data-address-task = g_object_task_m.
ls_vendor-central_data-address-postal-data-name = u_data-vender.
ls_vendor-central_data-address-postal-data-sort1 = u_data-sortl.
ls_vendor-central_data-address-postal-data-street = u_data-stras.
ls_vendor-central_data-address-postal-data-country = u_data-land1.
ls_vendor-central_data-address-postal-data-langu = u_data-spras.
ls_vendor-central_data-address-postal-datax-name = abap_true.
ls_vendor-central_data-address-postal-datax-sort1 = abap_true.
ls_vendor-central_data-address-postal-datax-street = abap_true.
ls_vendor-central_data-address-postal-datax-country = abap_true.
ls_vendor-central_data-address-postal-datax-langu = abap_true.
ls_vendor_phone-task = g_object_task_m.
ls_vendor_phone-data-telephone = u_data-telf1.
ls_vendor_phone-data-r_3_user = '3'.
ls_vendor_phone-datax-telephone = abap_true.
ls_vendor_phone-datax-r_3_user = abap_true.
ls_vendor-central_data-address-communication-phone-phone = lt_vendor_phone.
****公司代码数据************************************************
CLEAR:lt_company.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' " 统驭科目补零
EXPORTING
input = u_data-akont
IMPORTING
output = u_data-akont.
ls_company-task = g_object_task_c.
ls_company-data_key-bukrs = u_data-bukrs. "公司代码
ls_company-data-akont = u_data-akont. "统驭科目
ls_company-data-zuawa = u_data-zuawa. "排序码
ls_company-data-zterm = u_data-zterm. "付款条件
ls_company-data-reprf = u_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_c.
ls_purchasing-data_key-ekorg = u_data-ekorg. "采购组织
ls_purchasing-data-waers = u_data-waers. "货币
ls_purchasing-data-webre = u_data-webre. "基于收货的发票校验
ls_purchasing-data-zterm = u_data-zterm. "付款条件
ls_purchasing-data-ekgrp = u_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_m.
ls_functions-data_key-parvw = 'BA'. " PANERFUNCTION中 OA 对应的输出是 BA
ls_functions-data-partner = u_data-lifnr.
ls_functions-datax-partner = abap_true.
APPEND ls_functions TO lt_functions.
ls_functions-task = g_object_task_m.
ls_functions-data_key-parvw = 'RS'. " PANERFUNCTION中 RS 对应的输出是 PI
ls_functions-data-partner = u_data-lifnr.
ls_functions-datax-partner = abap_true.
APPEND ls_functions TO lt_functions.
ls_functions-task = g_object_task_m.
ls_functions-data_key-parvw = 'LF'. " PANERFUNCTION中 LF 对应的输出是 VN
ls_functions-data-partner = u_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.
APPEND ls_data TO lt_data.
cl_md_bp_maintain=>maintain(
EXPORTING
i_data = lt_data
IMPORTING
e_return = lt_return ).
CLEAR u_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 u_data-msg ls_msg-message INTO u_data-msg.
ENDLOOP.
ENDLOOP.
IF u_data-msg IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
CONCATENATE '供应商' u_data-lifnr '修改成功!' INTO u_data-msg.
u_data-zis_ok = '0'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
u_data-zis_ok = '4'.
ENDIF.
SHIFT u_data-LIFNR LEFT DELETING LEADING '0'.
SHIFT u_data-akont LEFT DELETING LEADING '0'.
MODIFY u_data INDEX lv_tabix.
ENDLOOP.
MODIFY zmm_vendor_log FROM TABLE u_data.
zfmparavalsave2 'R'.
ENDFUNCTION.
*"----------------------------------------------------------------------
*"*"本地接口:
*" TABLES
*" U_DATA STRUCTURE ZMM_VENDOR_LOG
*"----------------------------------------------------------------------
CONSTANTS:
g_object_task_c TYPE bus_ei_object_task VALUE 'C',
g_object_task_m TYPE bus_ei_object_task VALUE 'M',
g_object_task_d TYPE bus_ei_object_task VALUE 'D'.
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_functions TYPE vmds_ei_functions_t,
ls_functions TYPE vmds_ei_functions,
lt_purchasing TYPE vmds_ei_purchasing_t,
ls_purchasing TYPE vmds_ei_purchasing,
lt_vendor_phone type CVIS_EI_PHONE_T,
ls_vendor_phone type CVIS_EI_PHONE,
lv_partner_guid TYPE bu_partner_guid,
lt_but0bk TYPE TABLE OF but0bk,
ls_but0bk TYPE but0bk,
lt_but020 TYPE TABLE OF but020,
ls_but020 TYPE but020.
zfmparavalsave1 'ZZMM_VENDOR_UPDATE'.
zfmparavalsave2 'B'.
LOOP AT u_data.
CLEAR:
ls_data,
lt_data,
ls_partner,
ls_vendor.
lv_tabix = sy-tabix.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = u_data-lifnr
IMPORTING
output = u_data-lifnr.
"基本信息
ls_partner-header-object_task = g_object_task_c.
ls_partner-header-object_instance-bpartner = u_data-lifnr.
SELECT SINGLE partner_guid
INTO lv_partner_guid
FROM but000
WHERE partner = u_data-lifnr.
ls_partner-header-object_instance-bpartnerguid = lv_partner_guid.
ls_partner-central_data-common-data-bp_centraldata-title_key = u_data-title_medi.
ls_partner-central_data-common-data-bp_centraldata-searchterm1 = u_data-sortl.
ls_partner-central_data-common-data-bp_organization-name1 = u_data-vender.
ls_partner-central_data-common-data-bp_organization-name2 = u_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 = g_object_task_c.
ls_roles-data_key = 'ZLVN00'. "采购角色
APPEND ls_roles TO lt_roles.
ls_roles-task = g_object_task_c.
ls_roles-data_key = 'ZLVN01'. "公司角色
APPEND ls_roles TO lt_roles.
ls_partner-central_data-role-roles = lt_roles.
"地址信息
CLEAR: ls_but020,ls_but020.
SELECT *
INTO TABLE lt_but020
FROM but020
WHERE partner = u_data-lifnr.
"取最新地址guid
SORT lt_but020 BY partner addrnumber DESCENDING.
READ TABLE lt_but020 INTO ls_but020 INDEX 1.
CLEAR lt_addresses.
ls_addresses-task = g_object_task_m.
ls_addresses-data_key-guid = ls_but020-address_guid.
ls_addresses-data-postal-data-street = u_data-stras. "街道
ls_addresses-data-postal-data-country = u_data-land1. "国家
ls_addresses-data-postal-data-langu = u_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_c.
ls_phone-contact-data-telephone = u_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_c.
ls_remarks-data-langu = u_data-spras.
ls_remarks-data-comm_notes = u_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.
"银行信息
"先删除已存在的银行信息
IF u_data-banks IS NOT INITIAL.
CLEAR lt_but0bk.
SELECT *
INTO TABLE lt_but0bk
FROM but0bk
WHERE partner = u_data-lifnr.
LOOP AT lt_but0bk INTO ls_but0bk.
ls_bankdetails-task = g_object_task_d.
ls_bankdetails-data_key = ls_but0bk-bkvid.
APPEND ls_bankdetails TO lt_bankdetails.
ENDLOOP.
CLEAR lt_bankdetails.
ls_bankdetails-task = g_object_task_c.
ls_bankdetails-data_key = '0001'.
ls_bankdetails-data-bank_ctry = u_data-banks.
ls_bankdetails-data-bank_key = u_data-bankl.
ls_bankdetails-data-bank_acct = u_data-bankn.
ls_bankdetails-data-accountholder = u_data-koinh.
ls_bankdetails-data-bankaccountname = u_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 = u_data-lifnr.
ls_vendor-header-object_task = g_object_task_c.
"如果不更新以下数据,LFA1中的数据不会更新
ls_vendor-central_data-address-task = g_object_task_m.
ls_vendor-central_data-address-postal-data-name = u_data-vender.
ls_vendor-central_data-address-postal-data-sort1 = u_data-sortl.
ls_vendor-central_data-address-postal-data-street = u_data-stras.
ls_vendor-central_data-address-postal-data-country = u_data-land1.
ls_vendor-central_data-address-postal-data-langu = u_data-spras.
ls_vendor-central_data-address-postal-datax-name = abap_true.
ls_vendor-central_data-address-postal-datax-sort1 = abap_true.
ls_vendor-central_data-address-postal-datax-street = abap_true.
ls_vendor-central_data-address-postal-datax-country = abap_true.
ls_vendor-central_data-address-postal-datax-langu = abap_true.
ls_vendor_phone-task = g_object_task_m.
ls_vendor_phone-data-telephone = u_data-telf1.
ls_vendor_phone-data-r_3_user = '3'.
ls_vendor_phone-datax-telephone = abap_true.
ls_vendor_phone-datax-r_3_user = abap_true.
ls_vendor-central_data-address-communication-phone-phone = lt_vendor_phone.
****公司代码数据************************************************
CLEAR:lt_company.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' " 统驭科目补零
EXPORTING
input = u_data-akont
IMPORTING
output = u_data-akont.
ls_company-task = g_object_task_c.
ls_company-data_key-bukrs = u_data-bukrs. "公司代码
ls_company-data-akont = u_data-akont. "统驭科目
ls_company-data-zuawa = u_data-zuawa. "排序码
ls_company-data-zterm = u_data-zterm. "付款条件
ls_company-data-reprf = u_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_c.
ls_purchasing-data_key-ekorg = u_data-ekorg. "采购组织
ls_purchasing-data-waers = u_data-waers. "货币
ls_purchasing-data-webre = u_data-webre. "基于收货的发票校验
ls_purchasing-data-zterm = u_data-zterm. "付款条件
ls_purchasing-data-ekgrp = u_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_m.
ls_functions-data_key-parvw = 'BA'. " PANERFUNCTION中 OA 对应的输出是 BA
ls_functions-data-partner = u_data-lifnr.
ls_functions-datax-partner = abap_true.
APPEND ls_functions TO lt_functions.
ls_functions-task = g_object_task_m.
ls_functions-data_key-parvw = 'RS'. " PANERFUNCTION中 RS 对应的输出是 PI
ls_functions-data-partner = u_data-lifnr.
ls_functions-datax-partner = abap_true.
APPEND ls_functions TO lt_functions.
ls_functions-task = g_object_task_m.
ls_functions-data_key-parvw = 'LF'. " PANERFUNCTION中 LF 对应的输出是 VN
ls_functions-data-partner = u_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.
APPEND ls_data TO lt_data.
cl_md_bp_maintain=>maintain(
EXPORTING
i_data = lt_data
IMPORTING
e_return = lt_return ).
CLEAR u_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 u_data-msg ls_msg-message INTO u_data-msg.
ENDLOOP.
ENDLOOP.
IF u_data-msg IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
CONCATENATE '供应商' u_data-lifnr '修改成功!' INTO u_data-msg.
u_data-zis_ok = '0'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
u_data-zis_ok = '4'.
ENDIF.
SHIFT u_data-LIFNR LEFT DELETING LEADING '0'.
SHIFT u_data-akont LEFT DELETING LEADING '0'.
MODIFY u_data INDEX lv_tabix.
ENDLOOP.
MODIFY zmm_vendor_log FROM TABLE u_data.
zfmparavalsave2 'R'.
ENDFUNCTION.