1. 程式人生 > 其它 >BP供應商建立與修改

BP供應商建立與修改

1業務場景

BP中,供應商和客戶的建立發生了很大變化,之前的BAPI無法使用,本文件採用新的方法建立供應商。

2建立

2.1業務夥伴

1.定義引數

供應商主資料

 

2.BAPI_BUPA_CREATE_FROM_DATA

 

2.2新增BP角色

1.BAPI_BUPA_ROLE_ADD_2

新增BP角色FLVN00 FLVN01

 

 

2.3維護銀行資料

供應商主資料中需要維護銀行資料

 

而銀行資料需要通過BAPI_BUPA_BANKDETAIL_ADD維護

 

銀行賬戶號碼,只允許18位的長度,因此需要將過長的部分放在其他欄位。

2.4維護類別稅號資料

 

類別稅號通過BAPI_BUPA_TAX_ADD

 

2.5公司和採購檢視

以上操作便完成了供應商主資料的基本建立,之後要通過BAPI維護供應商的公司檢視和採購檢視。

1.定義引數

 

2.擴充套件公司檢視和採購檢視

2.1抬頭和中心資料

此處的的供應商一定要使用帶前導零的供應商編號,否則擴充套件不成功

 

公司檢視資料

 

採購檢視資料

 

採購中的業務夥伴功能

 

此處應使用OA VN PI未轉換的值。

 

 

3.呼叫方法維護檢視

 

3.修改

3.1修改供應商

修改時,填寫哪些欄位,則會修改哪些欄位,沒有賦值的欄位會保持原來的值

使用BAPI_BUPA_CENTRAL_CHANGE進行修改, 使用方法和建立類似。

3.2修改銀行

使用BAPI_BUPA_BANKDETAIL_CHANGE進行修改, 使用方法和建立類似。

3.3修改稅務

使用BAPI_BUPA_TAX_CHANGE進行修改, 使用方法和建立類似。

3.4修改地址等資訊

使用BAPI_BUPA_ADDRESS_CHANGE進行修改

 

 

 

 

4.原始碼

4.1建立供應商

"-----------------------------@斌將軍-----------------------------
FORM frm_bapi_creat.

*--------------------------------------------------------------------*
*           BAPI 欄位
*--------------------------------------------------------------------*
DATA:businesspartnerextern TYPE bapibus1006_head-bpartner, "匯入的客戶編碼 partnercategory TYPE bapibus1006_head-partn_cat, "夥伴類別 partnertype TYPE bapibus1006_head-partn_typ, "夥伴型別 partnergroup TYPE bapibus1006_head-partn_grp, "夥伴分組 centraldata TYPE bapibus1006_central, "中心資訊 centraldataperson TYPE bapibus1006_central_person, "人員資訊 centraldataorganization TYPE bapibus1006_central_organ, "組織 centraldatagroup TYPE bapibus1006_central_group, " addressdata TYPE bapibus1006_address, "地址 businesspartner TYPE bapibus1006_head-bpartner, "匯出的客戶編碼 lt_telefondata TYPE TABLE OF bapiadtel , "電話 ls_telefondata TYPE bapiadtel , "電話 lt_emaildata TYPE TABLE OF bapiadsmtp, ls_emaildata TYPE bapiadsmtp, lt_return TYPE TABLE OF bapiret2, "返回值 ls_return TYPE bapiret2. "返回值. DATA:ls_bankdata TYPE bapibus1006_bankdetail. DATA:lt_return_tax TYPE TABLE OF bapiret2 WITH HEADER LINE. DATA:ls_main TYPE vmds_ei_main, ls_cor1 TYPE vmds_ei_main, ls_cor2 TYPE vmds_ei_main, ls_mesg1 TYPE cvis_message, ls_mesg2 TYPE cvis_message, lt_msg TYPE bapiret2_t, ls_msg TYPE bapiret2, lt_vend TYPE vmds_ei_extern_t, "擴充套件資料 ls_vend TYPE vmds_ei_extern, lt_vat_number TYPE cvis_ei_vat_t, ls_vat_number TYPE cvis_ei_vat, lt_remarks TYPE cvis_ei_rem_t, ls_remarks TYPE cvis_ei_rem, lt_company TYPE vmds_ei_company_t, "公司程式碼資料 ls_company TYPE vmds_ei_company, lt_bankdetails TYPE cvis_ei_bankdetail_t, "銀行 ls_bankdetails TYPE cvis_ei_cvi_bankdetail, 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. DATA:lv_lifnr TYPE lfa1-lifnr, lv_msg TYPE char200, lv_message TYPE char200, "返回訊息 lv_check TYPE char2, lv_lenth TYPE char2, lv_ws TYPE char2, lv_bprole TYPE char6. "BP角色 "進度條使用標誌 CLEAR:gv_flag. DESCRIBE TABLE gt_template LINES gv_lines. LOOP AT gt_template INTO gs_template WHERE icon NE icon_led_red. "當前條目 gv_tabix = gv_tabix + 1. "進度條 PERFORM frm_indicator USING gv_tabix. REFRESH:lt_telefondata,lt_emaildata,lt_return. CLEAR:businesspartnerextern,partnercategory,partnergroup,centraldata,centraldataorganization,addressdata,businesspartner. businesspartnerextern = gs_template-lifnr. "外部給號 partnercategory = 2. " 業務夥伴類別 partnergroup = gs_template-ktokk." 分組 centraldataorganization-name1 = gs_template-name1. " 名稱1 * centraldataorganization-name2 = <fs_data>-name2. " 名稱2 addressdata-postl_cod1 = gs_template-pstl2. " 郵政編碼 addressdata-country = gs_template-land1. " 國家程式碼 addressdata-region = gs_template-regio. " 地區 addressdata-city = gs_template-ort01. " 城市 addressdata-languiso = gs_template-spras. " 語言 * addressdata-langu = gs_template-spras. " 語言 * addressdata-building = <fs_data>-building. " 性別 * addressdata-c_o_name = <fs_data>-name_org4. " 姓名 addressdata-street = gs_template-stras. " 街道 centraldata-searchterm1 = gs_template-sortl. " 搜尋項 CLEAR ls_telefondata. ls_telefondata-telephone = gs_template-telf1. "固話 * ls_telefondata-extension = <fs_data>-tel_extens. " 分機號 APPEND ls_telefondata TO lt_telefondata. CLEAR:ls_telefondata. ls_telefondata-telephone = gs_template-telf2. "行動電話 ls_telefondata-r_3_user = '3'."識別符號:電話是行動電話 APPEND ls_telefondata TO lt_telefondata. * ls_emaildata-e_mail = <fs_data>-smtp_addr. "電子郵件 * APPEND ls_emaildata TO lt_emaildata. CALL FUNCTION 'BAPI_BUPA_CREATE_FROM_DATA' EXPORTING businesspartnerextern = businesspartnerextern partnercategory = partnercategory partnergroup = partnergroup centraldata = centraldata * centraldataperson = centraldataperson centraldataorganization = centraldataorganization addressdata = addressdata * ACCEPT_ERROR = ' ' IMPORTING businesspartner = businesspartner "內部流水生成的客戶編號 TABLES telefondata = lt_telefondata * faxdata = faxdata e_maildata = lt_emaildata return = lt_return. lv_check = 'S'. LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A'. CONCATENATE 'BAPI錯誤' ':' ls_return-message INTO lv_message. lv_check = 'E'. CLEAR:ls_return. ENDLOOP. IF lv_check = 'S'. CLEAR:lv_lifnr. lv_lifnr = businesspartner."獲取建立成功的供應商編號 gs_template-icon = icon_led_green. CONCATENATE '供應商' gs_template-lifnr '建立成功' INTO lv_message. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. * lv_bprole = 'YG0001'. * CALL FUNCTION 'BAPI_BUPA_ROLE_ADD_2' "新增BP角色 * EXPORTING * businesspartner = businesspartner * businesspartnerrolecategory = lv_bprole. "BP角色 REFRESH:lt_return. lv_bprole = 'FLVN00'. CALL FUNCTION 'BAPI_BUPA_ROLE_ADD_2' "新增BP角色 EXPORTING businesspartner = lv_lifnr businesspartnerrolecategory = lv_bprole "公司 all_businesspartnerroles = '' TABLES return = lt_return. READ TABLE lt_return TRANSPORTING NO FIELDS WITH KEY type = 'E'. IF sy-subrc = 0. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. ENDIF. REFRESH:lt_return. lv_bprole = 'FLVN01'. CALL FUNCTION 'BAPI_BUPA_ROLE_ADD_2' "新增BP角色 EXPORTING businesspartner = lv_lifnr businesspartnerrolecategory = lv_bprole "公司 all_businesspartnerroles = '' TABLES return = lt_return. READ TABLE lt_return TRANSPORTING NO FIELDS WITH KEY type = 'E'. IF sy-subrc = 0. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. ENDIF. IF gs_template-bankn IS NOT INITIAL. REFRESH:lt_return. CLEAR:ls_bankdata,lv_lenth,lv_ws. ls_bankdata-bankdetailmoveid = gs_template-bkvid." 銀行明細標識 ls_bankdata-bank_ctry = gs_template-banks. " 銀行國家程式碼 ls_bankdata-bank_key = gs_template-bankl. " 銀行程式碼 * 銀行帳戶號碼過長,需要截字串 儲存在參考明細中 lv_lenth = strlen( gs_template-bankn )."欄位長度 ls_bankdata-bank_acct = gs_template-bankn. " 銀行帳戶號碼 IF lv_lenth > 18. lv_ws = lv_lenth - 18. ls_bankdata-bank_ref = gs_template-bankn+18(lv_ws). " 銀行帳戶的參考規定 ENDIF. * ls_bankdata-bank_acct = gs_template-bankn. " 銀行帳戶號碼 * ls_bankdata-bank_ref = gs_template-bkref. " 銀行帳戶的參考規定 CALL FUNCTION 'BAPI_BUPA_BANKDETAIL_ADD' EXPORTING businesspartner = lv_lifnr bankdetaildata = ls_bankdata TABLES return = lt_return. lv_check = 'S'. CLEAR:lv_msg. LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A'. CONCATENATE lv_msg ls_return-message INTO lv_msg. lv_check = 'E'. CLEAR:ls_return. ENDLOOP. IF lv_check = 'S'. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. ELSEIF lv_check = 'E'. CONCATENATE lv_message ',但銀行資訊拓展失敗:' lv_msg INTO lv_message. gs_template-icon = icon_led_yellow. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ENDIF. ENDIF. "稅別 稅號 IF gs_template-taxnum IS NOT INITIAL. REFRESH:lt_return_tax[]. CALL FUNCTION 'BAPI_BUPA_TAX_ADD' EXPORTING businesspartner = lv_lifnr taxtype = gs_template-taxtype "類別 taxnumber = gs_template-taxnum "稅號 TABLES return = lt_return_tax. lv_check = 'S'. CLEAR:lv_msg. LOOP AT lt_return_tax WHERE type = 'E' OR type = 'A'. CONCATENATE lv_msg lt_return_tax-message INTO lv_msg. lv_check = 'E'. CLEAR:lt_return_tax. ENDLOOP. IF lv_check = 'S'. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = abap_true. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. gs_template-icon = icon_led_yellow. CONCATENATE lv_message ' 稅號稅類別維護失敗:'lv_msg INTO lv_message. ENDIF. ENDIF. *--------------------------------------------------------------------* * 維護採購資料、公司程式碼資料 *--------------------------------------------------------------------* REFRESH:lt_vend. CLEAR:ls_vend. ls_vend-header-object_task = gv_task. ls_vend-header-object_instance-lifnr = lv_lifnr."此處一定要用帶前導零的供應商編號 * 主資料 ls_vend-central_data-central-data-ktokk = gs_template-ktokk."賬戶組 ls_vend-central_data-central-datax-ktokk = 'X'. * ls_vend-central_data-central-data-stenr = ." 供應商:稅務資料 稅號 * ls_vend-central_data-central-datax-stenr = 'X'. * ls_vend-CENTRAL_DATA-CENTRAL-DATA-KRAUS = gs_template-KRAUS. " 鄧白氏碼 * ls_vend-central_data-central-datax-kraus = 'X'. *地址資料 * IF gs_template-KUNNR IS NOT INITIAL. * ls_vend-CENTRAL_DATA-CENTRAL-DATA-KUNNR = gs_template-KUNNR. * ls_vend-CENTRAL_DATA-CENTRAL-DATAX-KUNNR = 'X'. * ENDIF. * IF gs_template-VBUND IS NOT INITIAL. * ls_vend-CENTRAL_DATA-CENTRAL-DATA-VBUND = gs_template-VBUND. * ls_vend-CENTRAL_DATA-CENTRAL-DATAX-VBUND = 'X'. * ENDIF. * ls_vend-central_data-address-postal-data-langu = gs_template-spras."語言 * ls_vend-central_data-address-postal-datax-langu = 'X'. ls_vend-central_data-address-postal-data-langu_iso = gs_template-spras."語言 ls_vend-central_data-address-postal-datax-langu_iso = 'X'. ls_vend-central_data-address-postal-data-sort1 = gs_template-sortl."搜尋項 ls_vend-central_data-address-postal-datax-sort1 = 'X'. ls_vend-central_data-address-postal-data-country = gs_template-land1."國家 ls_vend-central_data-address-postal-datax-country = 'X'. ls_vend-central_data-address-postal-data-region = gs_template-regio."地區 ls_vend-central_data-address-postal-datax-region = 'X'. ls_vend-central_data-address-postal-data-city = gs_template-ort01."城市 ls_vend-central_data-address-postal-datax-city = 'X'. ls_vend-central_data-address-postal-data-postl_cod1 = gs_template-pstl2. "郵政編碼 ls_vend-central_data-address-postal-datax-postl_cod1 = 'X'. ls_vend-central_data-address-postal-data-street = gs_template-stras."街道 ls_vend-central_data-address-postal-datax-street = 'X'. ls_vend-central_data-address-postal-data-name = gs_template-name1."名稱 ls_vend-central_data-address-postal-datax-name = 'X'. *地址註釋 CLEAR:ls_remarks. REFRESH:lt_remarks. ls_remarks-task = gv_task. ls_remarks-data-langu_iso = gs_template-spras. * ls_remarks-data-langu = gs_template-spras. * ls_remarks-data-adr_notes = gs_template-VERKF."聯絡人姓名 ls_remarks-datax-langu_iso = 'X'. * ls_remarks-datax-langu = 'X'. * ls_remarks-datax-adr_notes = 'X'. APPEND ls_remarks TO lt_remarks. ls_vend-central_data-address-remark-current_state = 'X'. ls_vend-central_data-address-remark-remarks = lt_remarks. * 公司程式碼資料 REFRESH:lt_company. CLEAR:ls_company. ls_company-task = gv_task. ls_company-data_key-bukrs = gs_template-bukrs. " 公司程式碼 ls_company-data-akont = gs_template-akont. " 統馭科目 * ls_company-data-zuawa = gs_template-zuawa. " 排序碼 ls_company-data-zterm = gs_template-cw_zterm. " 付款條件-財務 ls_company-data-mindk = gs_template-mindk. " 少數標誌 * ls_company-DATA-ZWELS = gs_template-ZWELS. " 付款方式 * ls_company-DATA-REPRF = 'X'. " 雙重發票校驗 * ls_company-DATA-TOGRU = gs_template-TOGRU. " 單獨收付標識 * ls_company-data-reprf = gs_template-reprf."檢查雙重發票或信貸憑單的標誌 ls_company-datax-akont = 'X'. * ls_company-datax-zuawa = 'X'. ls_company-datax-zterm = 'X'. ls_company-datax-mindk = 'X'. * ls_company-datax-zwels = 'X'. * ls_company-datax-reprf = 'X'. * ls_company-datax-togru = 'X'. APPEND ls_company TO lt_company. ls_vend-company_data-company = lt_company. *採購資料 IF r_cg = 'X'."採購供應商 REFRESH:lt_purchasing. CLEAR:ls_purchasing. ls_purchasing-task = gv_task. ls_purchasing-data_key-ekorg = gs_template-ekorg."採購組織 ls_purchasing-data-waers = gs_template-waers. " 貨幣 ls_purchasing-data-zterm = gs_template-cg_zterm. " 付款條件 ls_purchasing-data-verkf = gs_template-verkf. " 銷售人 ls_purchasing-data-telf1 = gs_template-xs_telf1. " 電話 ls_purchasing-data-webre = gs_template-webre. " 標識:基於收貨的發票驗證 * ls_purchasing-DATA-EKGRP = gs_template-EKGRP. " 採購組 * ls_purchasing-DATA-inco1 = gs_template-inco1. "貿易條款 * ls_purchasing-DATA-inco2_l = gs_template-inco2_l. "國際貿易條款位置 1 ls_purchasing-datax-waers = 'X'. ls_purchasing-datax-zterm = 'X'. ls_purchasing-datax-verkf = 'X'. ls_purchasing-datax-telf1 = 'X'. ls_purchasing-datax-webre = 'X'. * ls_purchasing-datax-ekgrp = 'X'. * ls_purchasing-datax-inco1 = 'X'. "貿易條款 * ls_purchasing-datax-inco2_l = 'X'."國際貿易條款位置 1 *功能 REFRESH:lt_functions. CLEAR:ls_functions. ls_functions-task = gv_task. ls_functions-data_key-parvw = 'BA'."OA 未轉換的值 BA ls_functions-data-partner = lv_lifnr."此處一定要用帶前導零的供應商編號 ls_functions-datax-partner = 'X'. " 業務合作伙伴號 APPEND ls_functions TO lt_functions. CLEAR:ls_functions. ls_functions-task = gv_task. ls_functions-data_key-parvw = 'LF'."VN 未轉換的值 LF ls_functions-data-partner = lv_lifnr."此處一定要用帶前導零的供應商編號 ls_functions-datax-partner = 'X'. "業務合作伙伴號 APPEND ls_functions TO lt_functions. CLEAR:ls_functions. ls_functions-task = gv_task. ls_functions-data_key-parvw = 'RS'."PI 未轉換的值 RS ls_functions-data-partner = lv_lifnr."此處一定要用帶前導零的供應商編號 ls_functions-datax-partner = 'X'. "業務合作伙伴號 APPEND ls_functions TO lt_functions. ls_purchasing-functions-functions = lt_functions. APPEND ls_purchasing TO lt_purchasing. ls_vend-purchasing_data-purchasing = lt_purchasing. ENDIF. APPEND ls_vend TO lt_vend. ls_main-vendors = lt_vend. WAIT UP TO '0.5' SECONDS. CALL METHOD vmd_ei_api=>maintain_direct_input EXPORTING * IV_TEST_RUN = SPACE is_master_data = ls_main IMPORTING es_master_data_correct = ls_cor1 "正確 es_message_correct = ls_mesg1 es_master_data_defective = ls_cor2 "錯誤 es_message_defective = ls_mesg2. lt_msg = ls_mesg2-messages. lv_check = 'S'. CLEAR:lv_msg. LOOP AT lt_msg INTO ls_msg WHERE type = 'E' OR type = 'A'. lv_check = 'E'. CONCATENATE lv_msg ls_msg-message INTO lv_msg. CLEAR:ls_msg. ENDLOOP. IF lv_check = 'S'. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. gs_template-icon = icon_led_green. gs_template-log = lv_message. ELSEIF lv_check = 'E'. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. gs_template-icon = icon_led_red. CONCATENATE lv_message ',' lv_msg INTO lv_message. gs_template-log = lv_message. ENDIF. ELSEIF lv_check = 'E'. gs_template-icon = icon_led_red. gs_template-log = lv_message. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ENDIF. MODIFY gt_template FROM gs_template. CLEAR:gs_template,lv_message. ENDLOOP. ENDFORM. "-----------------------------@斌將軍-----------------------------

4.2修改供應商

"-----------------------------@斌將軍-----------------------------
*"----------------------------------------------------------------------
*"*"本地介面:
*"  IMPORTING
*"     VALUE(I_VEROR) TYPE  ZSMM_VENDOR OPTIONAL
*"  EXPORTING
*"     VALUE(E_RETURN) TYPE  BAPIRETURN
*"----------------------------------------------------------------------
  TYPES:BEGIN OF ty_lfb1,
          lifnr TYPE lfb1-lifnr, "供應商或債權人的帳號
          bukrs TYPE lfb1-bukrs, "公司程式碼
          mindk TYPE lfb1-mindk, "少數標誌
          akont TYPE lfb1-akont, "統馭科目
          zterm TYPE lfb1-zterm, "付款條件-財務
        END OF ty_lfb1.

  TYPES:BEGIN OF ty_lfm1,
          lifnr TYPE lfm1-lifnr, "供應商或債權人的帳號
          ekorg TYPE lfm1-ekorg, "採購組織
          waers TYPE lfm1-waers, "訂單貨幣
          verkf TYPE lfm1-verkf, "聯絡人(銷售員)
          telf1 TYPE lfm1-telf1, "聯絡電話(銷售電話)
          webre TYPE lfm1-webre, "基於收貨的發票校驗
          zterm TYPE lfm1-zterm, "付款條件-採購
        END OF ty_lfm1.

  DATA:lt_lfb1 TYPE STANDARD TABLE OF ty_lfb1,
       ls_lfb1 TYPE ty_lfb1,
       lt_lfm1 TYPE STANDARD TABLE OF ty_lfm1,
       ls_lfm1 TYPE ty_lfm1.

  DATA:lv_lifnr         TYPE bapibus1006_head-bpartner,
       ls_centraldata   TYPE bapibus1006_central,
       ls_centraldatax  TYPE bapibus1006_central_x,
       ls_centralorgan  TYPE bapibus1006_central_organ,
       ls_centralorganx TYPE bapibus1006_central_organ_x,
       ls_address       TYPE bapibus1006_address,
       lt_telefondata   TYPE STANDARD TABLE OF bapiadtel,
       ls_telefondata   TYPE bapiadtel,
       lt_telefondatax  TYPE STANDARD TABLE OF bapiadtelx,
       ls_telefondatax  TYPE bapiadtelx,
       lt_return        TYPE STANDARD TABLE OF bapiret2,
       ls_return        TYPE bapiret2.

  DATA:ls_bankdata  TYPE bapibus1006_bankdetail,
       ls_bankdatax TYPE bapibus1006_bankdetail_x.

  DATA:ls_main       TYPE vmds_ei_main,
       ls_cor1       TYPE vmds_ei_main,
       ls_cor2       TYPE vmds_ei_main,
       ls_mesg1      TYPE cvis_message,
       ls_mesg2      TYPE cvis_message,
       lt_msg        TYPE bapiret2_t,
       ls_msg        TYPE bapiret2,
       lt_vend       TYPE vmds_ei_extern_t, "擴充套件資料
       ls_vend       TYPE vmds_ei_extern,
       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.

  DATA:lv_check   TYPE char2,
       gv_task    TYPE char1 VALUE 'M',
       lv_message TYPE char200.

  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      input  = i_veror-lifnr
    IMPORTING
      output = lv_lifnr.

  SELECT COUNT( * )
  FROM lfa1
  WHERE lifnr = lv_lifnr.

  IF sy-subrc NE 0."查詢該供應商,查詢不到報錯
    e_return-type = 'E'.
    e_return-message = '該業務夥伴不存在'.
  ENDIF.

  CHECK e_return-type <> 'E'.


  IF i_veror-ktokk IS INITIAL.
    e_return-type = 'E'.
    e_return-message = '賬戶組不能為空'.
  ENDIF.

  CHECK e_return-type <> 'E'.

  IF i_veror-name1 IS NOT INITIAL.
    ls_centralorgan-name1 = i_veror-name1."名稱1
    ls_centralorganx-name1 = 'X'.
  ENDIF.

  IF i_veror-sortl IS NOT INITIAL.
    ls_centraldata-searchterm1 = i_veror-sortl."搜尋項
    ls_centraldatax-searchterm1 = 'X'.
  ENDIF.

  IF i_veror-stras IS NOT INITIAL.
    ls_address-street = i_veror-stras."街道
  ENDIF.

  IF i_veror-pstl2 IS NOT INITIAL.
    ls_address-postl_cod2 = i_veror-pstl2."郵箱郵政編碼.
  ENDIF.

  IF i_veror-telf1 IS NOT INITIAL.
    CLEAR:ls_telefondata.
    ls_telefondata-telephone = i_veror-telf1."電話號碼
    APPEND ls_telefondata TO lt_telefondata.
  ENDIF.

  IF i_veror-telf2 IS NOT INITIAL.
    CLEAR:ls_telefondata.
    ls_telefondata-telephone = i_veror-telf2."行動電話
    ls_telefondata-r_3_user = '3'."識別符號:電話是行動電話
    APPEND ls_telefondata TO lt_telefondata.
  ENDIF.

  CALL FUNCTION 'BAPI_BUPA_CENTRAL_CHANGE'
    EXPORTING
      businesspartner           = lv_lifnr
      centraldata               = ls_centraldata
*     CENTRALDATAPERSON         =
      centraldataorganization   = ls_centralorgan
*     CENTRALDATAGROUP          =
      centraldata_x             = ls_centraldatax
*     CENTRALDATAPERSON_X       =
      centraldataorganization_x = ls_centralorganx
*     CENTRALDATAGROUP_X        =
*     VALID_DATE                = SY-DATLO
*     DUPLICATE_MESSAGE_TYPE    =
      duplicate_check_address   = ls_address
    TABLES
      telefondatanonaddress     = lt_telefondata
*     FAXDATANONADDRESS         =
*     TELETEXDATANONADDRESS     =
*     TELEXDATANONADDRESS       =
*     E_MAILDATANONADDRESS      =
*     RMLADDRESSDATANONADDRESS  =
*     X400ADDRESSDATANONADDRESS =
*     RFCADDRESSDATANONADDRESS  =
*     PRTADDRESSDATANONADDRESS  =
*     SSFADDRESSDATANONADDRESS  =
*     URIADDRESSDATANONADDRESS  =
*     PAGADDRESSDATANONADDRESS  =
*     COMMUNICATIONNOTESNONADDRESS        =
*     COMMUNICATIONUSAGENONADDRESS        =
*     TELEFONDATANONADDRESSX    =
*     FAXDATANONADDRESSX        =
*     TELETEXDATANONADDRESSX    =
*     TELEXDATANONADDRESSX      =
*     E_MAILDATANONADDRESSX     =
*     RMLADDRESSDATANONADDRESSX =
*     X400ADDRESSDATANONADDRESSX          =
*     RFCADDRESSDATANONADDRESSX =
*     PRTADDRESSDATANONADDRESSX =
*     SSFADDRESSDATANONADDRESSX =
*     URIADDRESSDATANONADDRESSX =
*     PAGADDRESSDATANONADDRESSX =
*     COMMUNICATIONNOTESNONADDRESSX       =
*     COMMUNICATIONUSAGENONADDRESSX       =
      return                    = lt_return
*     ADDRESSDUPLICATES         =
    .
  lv_check = 'S'.
  CLEAR:lv_message.
  LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A'.
    lv_check = 'E'.
    CONCATENATE lv_message ls_return-message INTO lv_message.
    CLEAR:ls_return.
  ENDLOOP.
  IF lv_check = 'S'.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.

    e_return-type = lv_check.
    e_return-message = '主資料更新成功'.

*    更新銀行資料
    IF i_veror-bankn IS NOT INITIAL.
      REFRESH:lt_return.
*      ls_bankdata-bankdetailmoveid = i_veror-bkvid." 銀行明細標識
      ls_bankdata-bank_ctry = i_veror-banks.    " 銀行國家程式碼
      ls_bankdata-bank_key  = i_veror-bankl.    " 銀行程式碼
      ls_bankdata-bank_acct = i_veror-bankn.     " 銀行帳戶號碼
      ls_bankdata-bank_ref  = i_veror-bkref.    " 銀行帳戶的參考規定

*      ls_bankdatax-bankdetailmoveid = 'X'." 銀行明細標識
      ls_bankdatax-bank_ctry = 'X'.    " 銀行國家程式碼
      ls_bankdatax-bank_key  = 'X'.    " 銀行程式碼
      ls_bankdatax-bank_acct = 'X'.     " 銀行帳戶號碼
      ls_bankdatax-bank_ref  = 'X'.    " 銀行帳戶的參考規定
      CALL FUNCTION 'BAPI_BUPA_BANKDETAIL_CHANGE'
        EXPORTING
          businesspartner  = lv_lifnr
          bankdetailid     = i_veror-bkvid
          bankdetaildata   = ls_bankdata
          bankdetaildata_x = ls_bankdatax
        TABLES
          return           = lt_return.

      lv_check = 'S'.
      CLEAR:lv_message.
      LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A'.
        CONCATENATE lv_message ls_return-message INTO lv_message.
        lv_check = 'E'.
        CLEAR:ls_return.
      ENDLOOP.
      IF lv_check = 'S'.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait = 'X'.
      ELSEIF lv_check = 'E'.
        e_return-type = lv_check.
        CONCATENATE e_return-message ',但銀行資訊拓展失敗:' lv_message INTO e_return-message.
        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
      ENDIF.
    ENDIF.

*    更新稅務資料
    IF i_veror-taxnum IS NOT INITIAL.
      REFRESH:lt_return.
      CALL FUNCTION 'BAPI_BUPA_TAX_CHANGE'
        EXPORTING
          businesspartner = lv_lifnr
          taxtype         = i_veror-taxtype "類別
          taxnumber       = i_veror-taxnum "稅號
        TABLES
          return          = lt_return.

      lv_check = 'S'.
      CLEAR:lv_message.
      LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A'.
        CONCATENATE lv_message ls_return-message INTO lv_message.
        lv_check = 'E'.
        CLEAR:ls_return.
      ENDLOOP.

      IF lv_check = 'S'.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait = abap_true.
      ELSEIF lv_check = 'E'.
        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
        e_return-type = lv_check.
        CONCATENATE e_return-message '!稅號稅類別維護失敗:'lv_message INTO e_return-message.
      ENDIF.
    ENDIF.

*   修改公司和採購檢視
    IF lv_lifnr IS NOT INITIAL AND i_veror-bukrs IS NOT INITIAL.
      SELECT SINGLE
        lifnr"供應商或債權人的帳號
        bukrs"公司程式碼
        mindk"少數標誌
        akont"統馭科目
        zterm"付款條件-財務
      FROM lfb1
      INTO ls_lfb1
      WHERE lifnr = lv_lifnr
      AND bukrs = i_veror-bukrs.
    ENDIF.

    IF lv_lifnr IS NOT INITIAL AND i_veror-ekorg IS NOT INITIAL.
      SELECT SINGLE
        lifnr"供應商或債權人的帳號
        ekorg"採購組織
        waers"訂單貨幣
        verkf"聯絡人(銷售員)
        telf1"聯絡電話(銷售電話)
        webre"基於收貨的發票校驗
        zterm"付款條件-採購
      FROM lfm1
      INTO ls_lfm1
      WHERE lifnr = lv_lifnr
      AND ekorg = i_veror-ekorg.
    ENDIF.

    IF ls_lfb1 IS NOT INITIAL.
      ls_vend-header-object_task = gv_task.
      ls_vend-header-object_instance-lifnr  = lv_lifnr.
      ls_vend-central_data-central-data-ktokk = i_veror-ktokk."賬戶組 "此處賬戶組如果為空將會DUMP
      ls_vend-central_data-central-datax-ktokk = 'X'.

      "公司程式碼資料
      CLEAR:ls_company.
      ls_company-task =  gv_task.
      ls_company-data_key-bukrs = i_veror-bukrs.  " 公司程式碼

      IF i_veror-akont IS NOT INITIAL.
        ls_company-data-akont  = i_veror-akont.     " 統馭科目
      ELSE.
        ls_company-data-akont  = ls_lfb1-akont.     " 統馭科目
      ENDIF.

      IF i_veror-cw_zterm IS NOT INITIAL.
        ls_company-data-zterm  = i_veror-cw_zterm." 付款條件-財務
      ELSE.
        ls_company-data-zterm  = ls_lfb1-zterm." 付款條件-財務
      ENDIF.

      IF i_veror-mindk IS NOT INITIAL.
        ls_company-data-mindk  = i_veror-mindk." 少數標誌
      ELSE.
        ls_company-data-mindk  = ls_lfb1-mindk." 少數標誌
      ENDIF.

      ls_company-datax-akont = 'X'.
      ls_company-datax-zterm = 'X'.
      ls_company-datax-mindk = 'X'.
      APPEND ls_company TO lt_company.

      ls_vend-company_data-current_state = 'X'.
      ls_vend-company_data-company = lt_company.

      "採購資料
      IF ls_lfm1 IS NOT INITIAL."維採購檢視
        CLEAR:ls_purchasing.
        ls_purchasing-task =  gv_task.
        ls_purchasing-data_key-ekorg = i_veror-ekorg."採購組織

        IF i_veror-waers IS NOT INITIAL.
          ls_purchasing-data-waers = i_veror-waers. " 貨幣
        ELSE.
          ls_purchasing-data-waers = ls_lfm1-waers. " 貨幣
        ENDIF.
        IF i_veror-cg_zterm IS NOT INITIAL.
          ls_purchasing-data-zterm = i_veror-cg_zterm. " 付款條件
        ELSE.
          ls_purchasing-data-zterm = ls_lfm1-zterm. " 付款條件
        ENDIF.
        IF i_veror-verkf IS NOT INITIAL.
          ls_purchasing-data-verkf = i_veror-verkf. " 銷售人
        ELSE.
          ls_purchasing-data-verkf = ls_lfm1-verkf. " 銷售人
        ENDIF.
        IF i_veror-xs_telf1 IS NOT INITIAL.
          ls_purchasing-data-telf1 = i_veror-xs_telf1. " 電話
        ELSE.
          ls_purchasing-data-telf1 = ls_lfm1-telf1. " 電話
        ENDIF.
        IF i_veror-webre IS NOT INITIAL.
          ls_purchasing-data-webre = i_veror-webre. " 標識:基於收貨的發票驗證
        ELSE.
          ls_purchasing-data-webre = ls_lfm1-webre. " 標識:基於收貨的發票驗證
        ENDIF.

        ls_purchasing-datax-waers = 'X'.
        ls_purchasing-datax-zterm = 'X'.
        ls_purchasing-datax-verkf = 'X'.
        ls_purchasing-datax-telf1 = 'X'.
        ls_purchasing-datax-webre = 'X'.
*功能
        ls_functions-task =  gv_task.
        ls_functions-data_key-parvw = 'BA'."OA 未轉換的值 BA
        ls_functions-data-partner = lv_lifnr.    " 業務合作伙伴號
        ls_functions-datax-partner = 'X'.       " 業務合作伙伴號
        APPEND ls_functions TO lt_functions.

        ls_functions-task = gv_task.
        ls_functions-data_key-parvw = 'LF'."VN 未轉換的值 LF
        ls_functions-data-partner = lv_lifnr. "業務合作伙伴號
        ls_functions-datax-partner = 'X'.    "業務合作伙伴號
        APPEND ls_functions TO lt_functions.

        ls_functions-task = gv_task.
        ls_functions-data_key-parvw = 'RS'."PI 未轉換的值 RS
        ls_functions-data-partner = lv_lifnr. "業務合作伙伴號
        ls_functions-datax-partner = 'X'. "業務合作伙伴號
        APPEND ls_functions TO lt_functions.

        ls_purchasing-functions-current_state = 'X'.
        ls_purchasing-functions-functions = lt_functions.
        APPEND ls_purchasing TO lt_purchasing.

        ls_vend-purchasing_data-current_state = 'X'.
        ls_vend-purchasing_data-purchasing = lt_purchasing.
      ENDIF.

      APPEND ls_vend TO lt_vend.
      ls_main-vendors = lt_vend.

*      WAIT UP TO '0.5' SECONDS.
      CALL METHOD vmd_ei_api=>maintain_direct_input
        EXPORTING
*         IV_TEST_RUN              = SPACE
          is_master_data           = ls_main
        IMPORTING
          es_master_data_correct   = ls_cor1 "正確
          es_message_correct       = ls_mesg1
          es_master_data_defective = ls_cor2 "錯誤
          es_message_defective     = ls_mesg2.

      lt_msg = ls_mesg2-messages.
      lv_check = 'S'.
      CLEAR:lv_message.
      LOOP AT lt_msg INTO ls_msg WHERE type = 'E' OR type = 'A'.
        lv_check = 'E'.
        CONCATENATE lv_message ls_msg-message INTO lv_message.
        CLEAR:ls_msg.
      ENDLOOP.
      IF lv_check = 'S'.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait = 'X'.
      ELSEIF lv_check = 'E'.
        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
        e_return-type = lv_check.
        CONCATENATE e_return-message '!公司和採購檢視修改失敗:' lv_message INTO e_return-message.
      ENDIF.
    ELSE.
      e_return-type = 'E'.
      CONCATENATE e_return-message '!未在LFB1發現公司檢視資料,修改失敗!' INTO e_return-message.
    ENDIF.
  ELSEIF  lv_check = 'E'.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    e_return-type = lv_check.
    e_return-message = lv_message.
  ENDIF.
"-----------------------------@斌將軍-----------------------------