abap中物料主数据导入程序(基本视图、公司代码视图、采购视图、银行视图)

2023-10-13 16:55:45 浏览数 (2)

代码语言:javascript复制
REPORT zmmb_003  LINE-SIZE 400
                 MESSAGE-ID zmm
                 NO STANDARD PAGE HEADING.

*--------------------------------------------------------------------
*  tables(聲明使用到的數據庫表)
*--------------------------------------------------------------------
TABLES: sscrfields.
*----------------------------------------------------------------------*
*  type-pools define(定義使用到的類型池)
*----------------------------------------------------------------------*
TYPE-POOLS:
icon.

*----------------------------------------------------------------------*
* ALV 相關
*----------------------------------------------------------------------*
DATA w_layout TYPE lvc_s_layo.
DATA it_fieldcat_lvc TYPE lvc_t_fcat.
DATA w_fieldcat TYPE lvc_s_fcat.
DATA: gs_fcode TYPE char10.
DATA: gv_error TYPE c.
DATA: gs_functxt  TYPE smp_dyntxt.
*--------------------------------------------------------------------
*  define internal table(定義類型結構)
*--------------------------------------------------------------------
TYPES: BEGIN OF typ_return,
         flagf    TYPE char4,
         msg(255),
       END OF typ_return.

*基本視圖
TYPES: BEGIN OF   typ_upload_basic,
         partner     TYPE  but100-partner  , "  業務夥伴編號編碼
         bu_role     TYPE  bu_role_screen , "  "BP 角色"
         name_org1   TYPE  but000-name_org1  , "  供應商名稱
         name_org2   TYPE  but000-name_org2  , "  組織名稱 2
         name_org3   TYPE  but000-name_org3  , "  組織名稱 3
         name_org4   TYPE  but000-name_org4  , "  組織名稱 4
         bu_sort1    TYPE  but000-bu_sort1 , "  搜索詞1
         bu_sort2    TYPE  but000-bu_sort2 , "  搜索詞2
         street      TYPE adrc-street, "街道地址1
         str_suppl1  TYPE adrc-str_suppl1, "街道地址2
         country     TYPE  adrc-country  , "  國家代碼
         city1       TYPE  adrc-city1  , "  城市
         region      TYPE  addr1_data-region , "  地區
         post_code1  TYPE  adrc-post_code1 , "  城市郵遞區號
         house_num1  TYPE  adrc-house_num1 , "  門牌號
         langu       TYPE   char2 , "  語言代碼
         tel_number  TYPE  adrc-tel_number , "  送貨聯繫電話
         tel_number2 TYPE  adrc-tel_number  , "  送貨聯繫電話2
         telf2       TYPE  kna1-telf2  , "  行動電話
         fax_number  TYPE  adrc-fax_number , "  傳真號
         smtp_addr   TYPE  adr6-smtp_addr  , "  電子郵件
         smtp_addr2  TYPE  adr6-smtp_addr  , "  電子郵件2
         taxtype     TYPE  dfkkbptaxnum-taxtype  , "  稅碼類別
         taxnumxl    LIKE dfkkbptaxnum-taxnumxl, "  統一編號(稅號)
       END OF  typ_upload_basic.

TYPES: BEGIN OF typ_basic_result.
         INCLUDE TYPE typ_upload_basic.
         INCLUDE TYPE  typ_return.
TYPES: END OF typ_basic_result.

TYPES: BEGIN OF typ_upload_pur,
         partner   TYPE  but100-partner  , "  供應商編碼
         name_org1 TYPE  but000-name_org1  , "  供應商名稱
         ekorg     TYPE  lfm1-ekorg  , "  採購組織
         waers     TYPE  lfm1-waers  , "  採購訂單貨幣
         zterm     TYPE  lfm1-zterm  , "  付款條件
         inco1     TYPE  lfm1-inco1  , "  貿易條款
         inco2     TYPE  lfm1-inco2  , "  貿易條款地點1
         vsbed     TYPE  lfm1-vsbed  , "  裝運條件
         webre     TYPE  lfm1-webre  , "  發票驗證
         verkf     TYPE lfm1-verkf, "業務人員
       END OF   typ_upload_pur.

TYPES: BEGIN OF typ_pur_result.
         INCLUDE TYPE typ_upload_pur.
         INCLUDE TYPE  typ_return.
TYPES: END OF typ_pur_result.

TYPES: BEGIN OF   typ_upload_company,
         partner   TYPE  but100-partner  , "  供應商編碼
         name_org1 TYPE  but000-name_org1  , "  供應商名稱
         bukrs     TYPE  lfb1-bukrs  , "  "公司代碼
         akont     TYPE  lfb1-akont  , "  "總帳的統馭科目
         zterm     TYPE  lfb1-zterm  , "  付款條件
         zwels     TYPE  lfb1-zwels  , "  付款方式
         hbkid     TYPE  lfb1-hbkid  , "  往來銀行
       END OF   typ_upload_company.

TYPES: BEGIN OF typ_company_result.
         INCLUDE TYPE typ_upload_company.
         INCLUDE TYPE  typ_return.
TYPES: END OF typ_company_result.

TYPES: BEGIN OF   typ_upload_bank,
         partner TYPE but000-partner, "供應商名稱
         banks   TYPE knbk-banks, "银行国家代码參考國家頁籤
         bkdsc   TYPE  knbk-ebpp_accname, "銀行名稱
         bankl   TYPE knbk-bankl, "银行代碼
         koinh   TYPE knbk-koinh, "帳戶持有的公司名稱
         bankn   TYPE knbk-bankn, "銀行帳號
       END OF   typ_upload_bank.

TYPES: BEGIN OF typ_bank_result.
         INCLUDE TYPE typ_upload_bank.
         INCLUDE TYPE  typ_return.
TYPES: END OF typ_bank_result.


DATA: it_upload_basic   TYPE TABLE OF typ_upload_basic,
      it_upload_pur     TYPE TABLE OF typ_upload_pur,
      it_upload_company TYPE TABLE OF typ_upload_company,
      it_upload_bank    TYPE TABLE OF typ_upload_bank,
      it_basic_result   TYPE TABLE OF typ_basic_result,
      it_pur_result     TYPE TABLE OF typ_pur_result,
      it_company_result TYPE TABLE OF typ_company_result,
      it_bank_result    TYPE TABLE OF typ_bank_result.

*CONSTANTS : c_parvw1 TYPE parvw VALUE 'PI',
*            c_parvw2 TYPE parvw VALUE 'OA',
*            c_parvw3 TYPE parvw VALUE 'VN'.


*-------------------------------------------------------------------
*  selection-screen(定義選擇螢幕)
*-------------------------------------------------------------------
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.
  SELECTION-SCREEN FUNCTION KEY 1.
  PARAMETERS:
    p_basic RADIOBUTTON  GROUP g1 DEFAULT 'X' USER-COMMAND com1,
    p_pur   RADIOBUTTON  GROUP g1,
    p_comp  RADIOBUTTON  GROUP g1,
    p_bank  RADIOBUTTON  GROUP g1.
SELECTION-SCREEN: END OF BLOCK b1.

SELECTION-SCREEN: BEGIN OF BLOCK b5 WITH FRAME TITLE TEXT-002.
  PARAMETERS: p_path LIKE rlgrap-filename .
SELECTION-SCREEN: END OF BLOCK b5.

*SELECTION-SCREEN FUNCTION KEY 2.
*--------------------------------------------------------------------
*  initialization(螢幕的初始化)
*--------------------------------------------------------------------
INITIALIZATION.
  PERFORM f_init_scr.

*------------------------------------------------------------------
*  at selection-screen(處理用於在選擇螢幕上的操作)
*------------------------------------------------------------------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
  PERFORM f_get_filepath USING p_path.

AT SELECTION-SCREEN.
  PERFORM f_auth_check.
* 螢幕處理 範本下載
  PERFORM frm_at_sle_scr.
*--------------------------------------------------------------------
*  start-of-selection(調用perform)
*--------------------------------------------------------------------
START-OF-SELECTION.
  PERFORM frm_check_filepath.
  "* set function code
  PERFORM f_set_fcode.
  "* upload data from file
  PERFORM f_upload_data.
* 導入數據
  PERFORM f_maintain_data.
*--------------------------------------------------------------------
*  end-of-selection(調用perform)
*--------------------------------------------------------------------
END-OF-SELECTION.


*********************************************************************
*  subroutines(子例程)
*********************************************************************
*&------------------------------------------------------------------*
*&      Form  f_get_filepath
*&------------------------------------------------------------------*
*       get the file to be updated
*-------------------------------------------------------------------*
FORM f_get_filepath USING    pr_path.
  CALL FUNCTION 'WS_FILENAME_GET'
    EXPORTING
      mask             =
                         ',All Files,*.*,Excel(*.XLSX;*.XLS),*.XLSX,*.XLS.'
      mode             = 'O'
    IMPORTING
      filename         = pr_path
    EXCEPTIONS
      inv_winsys       = 1
      no_batch         = 2
      selection_cancel = 3
      selection_error  = 4
      OTHERS           = 5.
ENDFORM.                    " f_get_filepath

*&------------------------------------------------------------------*
*&      Form  f_set_fcode
*&------------------------------------------------------------------*
FORM f_set_fcode .
  CASE 'X'.
    WHEN p_basic.
      gs_fcode = 'V_BASIC'.

    WHEN p_pur.
      gs_fcode = 'V_PUR'.

    WHEN p_comp.
      gs_fcode = 'V_COMPANY'.

    WHEN p_bank.
      gs_fcode = 'V_BANK'.

  ENDCASE.
  IF gs_fcode IS INITIAL.
    MESSAGE i208(00) WITH 'Please run prgram via TCode!'.
    STOP.
  ENDIF.
ENDFORM.
*&-------------------------------------------------------------------*
*&      Form  f_upload_data
*&-------------------------------------------------------------------*
*       Upload data for maitain material
*-------------------------------------------------------------------*
FORM f_upload_data .

  CASE gs_fcode.
    WHEN 'V_BASIC'.
      PERFORM f_upl_data TABLES it_upload_basic.
      LOOP AT it_upload_basic ASSIGNING FIELD-SYMBOL(<fs_basic>).
*        PERFORM frm_matnr_input USING <fs_basic>-matnr CHANGING <fs_basic>-matnr.
        <fs_basic>-partner =  |{ <fs_basic>-partner ALPHA = IN }|. ."
      ENDLOOP.

    WHEN 'V_PUR'.
      PERFORM f_upl_data TABLES it_upload_pur.
      LOOP AT it_upload_pur ASSIGNING FIELD-SYMBOL(<fs_pur>).
*        PERFORM frm_matnr_input USING <fs_PUR>-matnr CHANGING <fs_PUR>-matnr.
        <fs_pur>-partner =  |{ <fs_pur>-partner ALPHA = IN }|. "
      ENDLOOP.

    WHEN 'V_COMPANY'.
      PERFORM f_upl_data TABLES it_upload_company.
      LOOP AT it_upload_company ASSIGNING FIELD-SYMBOL(<fs_company>).
*        PERFORM frm_matnr_input USING <fs_company>-matnr CHANGING <fs_company>-matnr.
        <fs_company>-partner =  |{ <fs_company>-partner ALPHA = IN }|. "
        <fs_company>-akont =  | { <fs_company>-akont ALPHA = IN }|. "
      ENDLOOP.

    WHEN 'V_BANK'.
      PERFORM f_upl_data TABLES it_upload_bank.
      LOOP AT it_upload_pur ASSIGNING FIELD-SYMBOL(<fs_bank>).
*        PERFORM frm_matnr_input USING <fs_PUR>-matnr CHANGING <fs_PUR>-matnr.
        <fs_bank>-partner =  |{ <fs_bank>-partner ALPHA = IN }|. "
      ENDLOOP.

    WHEN OTHERS.
  ENDCASE.
*  BREAK-POINT.
ENDFORM.                    " f_upload_data
*&-------------------------------------------------------------------*
*&      Form  f_upl_data
*&-------------------------------------------------------------------*
FORM f_upl_data  TABLES   pt_data .
  DATA:  lt_raw TYPE truxs_t_text_data.
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*     I_FIELD_SEPERATOR    =
      i_line_header        = 'X'
      "if this flag is set,first row of record will be ignored during import.
      i_tab_raw_data       = lt_raw  " working buffer
      i_filename           = p_path  " input Excel file.
    TABLES
      i_tab_converted_data = pt_data "internal table holding the Excel data
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    EXIT.
  ENDIF.

  IF pt_data[] IS INITIAL.
    MESSAGE s999 WITH TEXT-001 DISPLAY LIKE 'E'.
    LEAVE LIST-PROCESSING AND RETURN TO SCREEN 0.
  ENDIF.

ENDFORM.                    " f_upl_purchase
*&-------------------------------------------------------------------*
*&      Form  f_maintain_data
*&-------------------------------------------------------------------*
*       Call BAPI to maintain material master
*--------------------------------------------------------------------*
FORM f_maintain_data .
  CHECK gv_error IS INITIAL.
  CASE gs_fcode.
    WHEN 'V_BASIC'.
      PERFORM f_maintain_basic.

    WHEN 'V_PUR'.
      PERFORM f_maintain_pur.

    WHEN 'V_COMPANY'.
      PERFORM f_maintain_company.

    WHEN 'V_BANK'.
      PERFORM f_maintain_bank.

    WHEN OTHERS.
  ENDCASE.
ENDFORM.                    " f_maintain_data

*&------------------------------------------------------------------*
*&      Form  f_maintain_BASIC
*&------------------------------------------------------------------*
*       基本視圖
*-------------------------------------------------------------------*
FORM f_maintain_basic .
  DATA: ls_basic_result TYPE typ_basic_result,
        ls_return       TYPE bapiret2.

  DATA : ls_data TYPE  cvis_ei_extern,
         lt_data TYPE  cvis_ei_extern_t.

  DATA : ls_partner TYPE bus_ei_extern,
         ls_vendor  TYPE vmds_ei_extern.

* 根據夥伴GUID取出供應商編號
  DATA : lt_partnerguid_list TYPE bu_partner_guid_t,
         ls_partnerguid_list LIKE LINE OF lt_partnerguid_list.
  DATA : lt_vendor_list TYPE cvis_vend_link_t,
         ls_vendor_list TYPE cvi_vend_link.

  DATA : ls_header          TYPE vmds_ei_header,
         ls_central_data    TYPE vmds_ei_central_data,
         ls_company_data    TYPE  vmds_ei_vmd_company,
         ls_purchasing_data TYPE vmds_ei_vmd_purchasing.

  DATA : lt_roles         TYPE bus_ei_bupa_roles_t,
         ls_roles         TYPE bus_ei_bupa_roles,
         lt_ident_numbers TYPE bus_ei_bupa_identification_t,
         ls_ident_numbers TYPE bus_ei_bupa_identification,
         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_fax           TYPE bus_ei_bupa_fax_t,
         ls_fax           TYPE bus_ei_bupa_fax,
         lt_smtp          TYPE bus_ei_bupa_smtp_t,
         ls_smtp          TYPE bus_ei_bupa_smtp,
         lt_tax           TYPE  bus_ei_bupa_taxnumber_t,
         ls_tax           TYPE  bus_ei_bupa_taxnumber,
         ls_central       TYPE vmds_ei_vmd_central,
         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,
         lt_texts         TYPE cvis_ei_text_t,
         ls_texts         TYPE cvis_ei_text,
         lt_tab           TYPE tline_tab,
         ls_tab           TYPE tline,
         ls_remarks       TYPE bus_ei_bupa_comrem,
         lt_remarks       TYPE bus_ei_bupa_comrem_t.
  DATA : lv_bpartnerguid TYPE bu_partner_guid_bapi,
         lv_partner      TYPE bu_partner.

  LOOP AT it_upload_basic INTO DATA(ls_basic).
    MOVE-CORRESPONDING ls_basic TO ls_basic_result.


    SELECT SINGLE *
    FROM but000
    INTO @DATA(ls_but000)
    WHERE partner = @ls_basic-partner.

*sy-subrc=0表示找到,M表示供應商已經存在修改,I表示新建
*I插入 U更新 M修改 D删除 C当前状态
    IF sy-subrc = 0.
      DATA(lv_object_task) = 'M'.
      lv_bpartnerguid = ls_but000-partner_guid.
    ELSE.
      lv_object_task = 'I'.
      TRY .
          lv_bpartnerguid = cl_uuid_factory=>create_system_uuid( )->create_uuid_x16( ).
        CATCH cx_uuid_error.
      ENDTRY.
    ENDIF.

    CLEAR:lt_roles.
    ls_roles-task =  lv_object_task.
    ls_roles-data_key = ls_basic-bu_role."BP角色
    APPEND ls_roles TO lt_roles.
    ls_partner-central_data-role-roles = lt_roles.

    ls_partner-header-object_task =  lv_object_task.
    ls_partner-header-object_instance-bpartner     = ls_basic-partner."業務夥伴編號編碼
    ls_partner-header-object_instance-bpartnerguid = lv_bpartnerguid.



****業務合作夥伴數據的中心數據***********************************
    ls_partner-central_data-common-data-bp_control-category = '2'.                 "業務夥伴類別
    ls_partner-central_data-common-data-bp_control-grouping = 'Z002'.             "業務夥伴分組
    ls_partner-central_data-common-data-bp_centraldata-title_key = '0003'.  "固定值,代表公司
    ls_partner-central_data-common-data-bp_organization-name1 = ls_basic-name_org1.      "供應商名稱1
    ls_partner-central_data-common-data-bp_organization-name2 = ls_basic-name_org2.     "供應商名稱2
    ls_partner-central_data-common-data-bp_organization-name3 = ls_basic-name_org3.      "供應商名稱3
    ls_partner-central_data-common-data-bp_organization-name4 = ls_basic-name_org4.      "供應商名稱4
    ls_partner-central_data-common-data-bp_centraldata-searchterm1 = ls_basic-bu_sort1.      "檢索項
    ls_partner-central_data-common-data-bp_centraldata-searchterm2 = ls_basic-bu_sort2.      "檢索項


    ls_partner-central_data-common-datax-bp_centraldata-title_key = abap_true.
    ls_partner-central_data-common-datax-bp_organization-name1 = abap_true.
    ls_partner-central_data-common-datax-bp_organization-name2 = abap_true.
    ls_partner-central_data-common-datax-bp_organization-name3 = abap_true.
    ls_partner-central_data-common-datax-bp_organization-name4 = abap_true.
    ls_partner-central_data-common-datax-bp_centraldata-searchterm1 = abap_true.
    ls_partner-central_data-common-datax-bp_centraldata-searchterm2 = abap_true.


***地址資訊
    CLEAR:lt_remarks,lt_phone,lt_fax,lt_smtp,lt_addresses.
    ls_addresses-task = lv_object_task.
    ls_addresses-data-postal-data-street = ls_basic-street.            "街道1
    ls_addresses-data-postal-data-str_suppl1 = ls_basic-str_suppl1." 街道2
    ls_addresses-data-postal-data-country = ls_basic-country.             "國家
    ls_addresses-data-postal-data-city = ls_basic-city1.              "城市
    ls_addresses-data-postal-data-region = ls_basic-region.             "地區
    ls_addresses-data-postal-data-postl_cod1 = ls_basic-post_code1 .      "郵編
    ls_addresses-data-postal-data-house_no = ls_basic-house_num1. "  門牌號
    ls_addresses-data-postal-data-languiso = ls_basic-langu.                "語言

    ls_addresses-data-postal-datax-postl_cod1 = abap_true.
    ls_addresses-data-postal-datax-city = abap_true.
    ls_addresses-data-postal-datax-street = abap_true.
    ls_addresses-data-postal-datax-str_suppl1 = abap_true.
    ls_addresses-data-postal-datax-country = abap_true.
    ls_addresses-data-postal-datax-region = abap_true.       "地區
    ls_addresses-data-postal-datax-langu_iso = abap_true.        "語言
    ls_addresses-data-postal-datax-house_no = abap_true.   "  門牌號

    CLEAR:ls_phone.
    ls_phone-contact-task = lv_object_task.
    ls_phone-contact-data-telephone = ls_basic-tel_number.  "送貨聯繫電話
    ls_phone-contact-datax-telephone = abap_true.
    APPEND ls_phone TO lt_phone.

    CLEAR ls_phone.
    ls_phone-contact-task = lv_object_task.
    ls_phone-contact-data-telephone = ls_basic-tel_number2.  "送貨聯繫電話2
    ls_phone-contact-datax-telephone = abap_true.
    APPEND ls_phone TO lt_phone.

    CLEAR ls_phone.
    ls_phone-contact-task = lv_object_task.
    ls_phone-contact-data-telephone = ls_basic-telf2.  "行動電話
    ls_phone-contact-datax-telephone = abap_true.
    ls_phone-contact-data-r_3_user = '3'.    "3行動電話
    ls_phone-contact-datax-r_3_user = abap_true.    "3行動電話
    APPEND ls_phone TO lt_phone.

    CLEAR:lt_fax.
    ls_fax-contact-task = lv_object_task.
    ls_fax-contact-data-fax = ls_basic-fax_number.     "傳真號
    ls_fax-contact-datax-fax = abap_true.
    APPEND ls_fax TO lt_fax.
    ls_addresses-data-communication-fax-fax = lt_fax.

    CLEAR:lt_smtp.
    ls_smtp-contact-task = lv_object_task.
    ls_smtp-contact-data-e_mail = ls_basic-smtp_addr . "電子郵件
    ls_smtp-contact-datax-e_mail = abap_true.
    APPEND ls_smtp TO lt_smtp.
    ls_addresses-data-communication-smtp-smtp = lt_smtp.
    APPEND ls_addresses TO lt_addresses.


    CLEAR:lt_smtp.
    ls_smtp-contact-task = lv_object_task.
    ls_smtp-contact-data-e_mail = ls_basic-smtp_addr2. "電子郵件2
    ls_smtp-contact-datax-e_mail = abap_true.
    APPEND ls_smtp TO lt_smtp.
    ls_addresses-data-communication-smtp-smtp = lt_smtp.
    APPEND ls_addresses TO lt_addresses.

    CLEAR: lt_tax.
    ls_tax-task = lv_object_task.
    ls_tax-data_key-taxtype = ls_basic-taxtype.
    ls_tax-data_key-taxnumxl = ls_basic-taxnumxl.
    APPEND ls_tax TO lt_tax.


    ls_partner-central_data-address-addresses = lt_addresses.
    ls_partner-central_data-communication-phone-phone = lt_phone.
    ls_partner-central_data-communication-fax-fax = lt_fax.
    ls_partner-central_data-communication-smtp-smtp = lt_smtp.
    ls_partner-central_data-taxnumber-taxnumbers = lt_tax.

   ls_vendor-header-object_instance-lifnr = ls_basic-partner.
   ls_vendor-header-object_task = lv_object_task.
*    ls_data-vendor = ls_vendor.
    ls_data-partner = ls_partner.

    APPEND ls_data TO lt_data.

    PERFORM frm_cvi_ei  USING  lv_bpartnerguid
                                  CHANGING  lt_data
                                                     ls_return
                                                     lv_partner."創建BP用戶

    IF ls_return-type = 'E'.
      ls_basic_result-flagf = icon_red_light.
    ELSE.
      ls_basic_result-flagf = icon_green_light.
      ls_basic_result-partner =  lv_partner.
    ENDIF.
    ls_basic_result-msg = ls_return-message.

    APPEND ls_basic_result TO it_basic_result.
    CLEAR  ls_basic_result .
    CLEAR  ls_return.
  ENDLOOP.

*ALV SHOW.
  PERFORM frm_create_row USING 'FLAGF' '標記'(t04) ''.
  PERFORM frm_create_row USING 'MSG' '消息'(t07) ''.
  PERFORM frm_create_row USING 'PARTNER' '業務夥伴編號編碼'(t08) ''.
  PERFORM frm_create_row USING 'BU_ROLE' 'BP 角色'(t15) ''.
  PERFORM frm_create_row USING 'NAME_ORG1' '供應商名稱'(t16) ''.
  PERFORM frm_create_row USING 'NAME_ORG2' '組織名稱 2'(t17) ''.
  PERFORM frm_create_row USING 'NAME_ORG3' '組織名稱 3'(t18) ''.
  PERFORM frm_create_row USING 'NAME_ORG4' '組織名稱 4'(t19) ''.
  PERFORM frm_create_row USING 'BU_SORT1' '搜索詞1'(t20) ''.
  PERFORM frm_create_row USING  'BU_SORT2'  '搜索詞2'(t21) ''.
  PERFORM frm_create_row USING 'STREET' '街道地址1'(t22) ''.
  PERFORM frm_create_row USING 'STR_SUPPL1' '街道地址2'(t23) ''.
  PERFORM frm_create_row USING 'COUNTRY' '國家代碼'(t24) ''.
  PERFORM frm_create_row USING 'CITY1' '城市'(t25) ''.
  PERFORM frm_create_row USING 'REGION' '地區'(t26) ''.
  PERFORM frm_create_row USING 'POST_CODE1' '城市郵遞區號'(t27) ''.
  PERFORM frm_create_row USING  'HOUSE_NUM1' '門牌號'(t28) ''.
  PERFORM frm_create_row USING 'LANGU' '語言代碼'(t29) ''.
  PERFORM frm_create_row USING 'TEL_NUMBER' '送貨聯繫電話'(t30) ''.
  PERFORM frm_create_row USING 'TEL_NUMBER2' '送貨聯繫電話2'(t31) ''.
  PERFORM frm_create_row USING 'TELF2' '行動電話'(t32) ''.
  PERFORM frm_create_row USING 'FAX_NUMBER' '傳真號'(t33) ''.
  PERFORM frm_create_row USING  'SMTP_ADDR' '電子郵件'(t34) ''.
  PERFORM frm_create_row USING 'SMTP_ADDR2' '電子郵件2'(t35) ''.
  PERFORM frm_create_row USING 'TAXTYPE' '稅碼類別'(t36) ''.
  PERFORM frm_create_row USING 'TAXNUMXL' '統一編號(稅號)'(t37) ''.

  PERFORM display_result TABLES it_basic_result.

ENDFORM.          " f_maintain_BASIC


*********************************************************************
* SUBROUTINES(子例程)
*********************************************************************
*&------------------------------------------------------------------*
*&      Form  F_INIT_SCR
*&------------------------------------------------------------------*
FORM f_init_scr .
  gs_functxt-icon_id    = icon_export.
  gs_functxt-icon_text  = '範本下載'(t01).
  sscrfields-functxt_01 = gs_functxt.
ENDFORM.                    " F_INIT_SCR
*&------------------------------------------------------------------*
*&      Form  F_AUTH_CHECK
*&------------------------------------------------------------------*
FORM f_auth_check .
  DATA: lv_tcode TYPE sy-tcode.
  MOVE sy-tcode TO lv_tcode.        " DECK901081
  AUTHORITY-CHECK OBJECT 'S_TCODE'
           ID 'TCD' FIELD lv_tcode.
  IF sy-subrc NE 0.
    MESSAGE i172(00) WITH lv_tcode.
    EXIT.
  ENDIF.
ENDFORM.                    " F_AUTH_CHECK
*&---------------------------------------------------------------------*
*& Form FRM_AT_SLE_SCR
*&---------------------------------------------------------------------*
FORM frm_at_sle_scr .
  DATA:
    ls_wwwdata_item LIKE wwwdatatab,
    lv_file         TYPE rlgrap-filename,
    lv_rc           LIKE sy-subrc.

  CASE sscrfields-ucomm.
    WHEN 'FC01'.
      CALL FUNCTION 'WS_FILENAME_GET'
        EXPORTING
          def_filename     = '採購資訊紀錄導入範本.xlsx'(t02)
          def_path         = 'C:'
          mask             = ',EXCEL FILES(*.XLSX),*.XLSX,ALL FILES(*.*),*.*,'
          mode             = 'S'
          title            = '選擇範本匯入檔'(t03)
        IMPORTING
          filename         = lv_file
        EXCEPTIONS
          inv_winsys       = 1
          no_batch         = 2
          selection_cancel = 3
          selection_error  = 4
          OTHERS           = 5.

      IF sy-subrc <> 0.
        EXIT.
      ENDIF.


      SELECT SINGLE *
      INTO CORRESPONDING FIELDS OF ls_wwwdata_item
      FROM wwwdata
      WHERE srtf2 = 0
      AND relid = 'MI'
********************************UPDATE BY HAND 20201210 START
*      AND OBJID = 'ZBT_PP0003I'.
      AND objid = 'ZGY_MM001'.
********************************UPDATE BY HAND 20201210 END

      IF sy-subrc NE 0 OR ls_wwwdata_item-objid EQ space.
        MESSAGE '模版檔不存在!'(m01) TYPE 'E'.
        EXIT.
      ENDIF.

      CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
        EXPORTING
          key         = ls_wwwdata_item
          destination = lv_file
        IMPORTING
          rc          = lv_rc.

      IF lv_rc = 0.
        MESSAGE s398(00) DISPLAY LIKE 'S' WITH '模版檔下載成功'(m02).
      ELSE.
        MESSAGE s398(00) DISPLAY LIKE 'E' WITH '模版檔下載失敗'(m03).
      ENDIF.
  ENDCASE.
ENDFORM.
*&-----------------------------------------------------------------*
*&      Form  FRM_CHECK_FILEPATH
*&-----------------------------------------------------------------*
*       校驗路徑
*------------------------------------------------------------------*
FORM frm_check_filepath .
  IF p_path IS INITIAL .
    MESSAGE s000 WITH '檔路徑為空,是否點錯了?'(m04) DISPLAY LIKE 'E'.
    STOP.
  ENDIF.
ENDFORM.                    " FRM_CHECK_FILEPATH
*&-----------------------------------------------------------------*
*&      Form  FRM_MATNR_INPUT
*&-----------------------------------------------------------------*
FORM frm_matnr_input USING fu_matnr TYPE matnr
                           CHANGING fc_matnr TYPE matnr.
  CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
    EXPORTING
      input  = fu_matnr
    IMPORTING
      output = fc_matnr.
ENDFORM.
*&-----------------------------------------------------------------*
*&      Form  FRM_MATNR_OUTPUT
*&-----------------------------------------------------------------*
FORM frm_matnr_output USING fu_matnr
        CHANGING fc_matnr TYPE matnr.
  CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
    EXPORTING
      input  = fu_matnr
    IMPORTING
      output = fc_matnr.
ENDFORM.
*&-----------------------------------------------------------------*
*&      Form  FRM_CUNIT_INPUT
*&-----------------------------------------------------------------*
FORM frm_cunit_input USING fu_input
                      CHANGING fc_input.
  CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
    EXPORTING
      input          = fu_input
      language       = sy-langu
    IMPORTING
      output         = fc_input
    EXCEPTIONS
      unit_not_found = 1
      OTHERS         = 2.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form frm_isola_input
*&---------------------------------------------------------------------*
FORM frm_isola_input USING fu_input
                           CHANGING fc_output.
  CALL FUNCTION 'CONVERSION_EXIT_ISOLA_INPUT'
    EXPORTING
      input            = fu_input
    IMPORTING
      output           = fc_output
    EXCEPTIONS
      unknown_language = 1
      OTHERS           = 2.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& display_result.
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& 顯示結果
*&---------------------------------------------------------------------*
FORM display_result  TABLES ft_result.
*  w_layout-detailtitl = 'TEST'.
  w_layout-cwidth_opt = 'X'.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program = sy-repid
      is_layout_lvc      = w_layout
      it_fieldcat_lvc    = it_fieldcat_lvc[]
    TABLES
      t_outtab           = ft_result.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.
ENDFORM.



*&---------------------------------------------------------------------*
*& Form f_maintain_PUR
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM f_maintain_pur .

  DATA: ls_pur_result TYPE typ_pur_result,
        ls_return     TYPE bapiret2.

  DATA : ls_data TYPE  cvis_ei_extern,
         lt_data TYPE  cvis_ei_extern_t.

  DATA : ls_partner TYPE bus_ei_extern,
         ls_vendor  TYPE vmds_ei_extern.

* 根據夥伴GUID取出供應商編號
  DATA : lt_partnerguid_list TYPE bu_partner_guid_t,
         ls_partnerguid_list LIKE LINE OF lt_partnerguid_list.
  DATA : lt_vendor_list TYPE cvis_vend_link_t,
         ls_vendor_list TYPE cvi_vend_link.

  DATA : ls_header          TYPE vmds_ei_header,
         ls_central_data    TYPE vmds_ei_central_data,
         ls_company_data    TYPE  vmds_ei_vmd_company,
         ls_purchasing_data TYPE vmds_ei_vmd_purchasing.

  DATA : lt_roles         TYPE bus_ei_bupa_roles_t,
         ls_roles         TYPE bus_ei_bupa_roles,
         lt_ident_numbers TYPE bus_ei_bupa_identification_t,
         ls_ident_numbers TYPE bus_ei_bupa_identification,
         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_fax           TYPE bus_ei_bupa_fax_t,
         ls_fax           TYPE bus_ei_bupa_fax,
         lt_smtp          TYPE bus_ei_bupa_smtp_t,
         ls_smtp          TYPE bus_ei_bupa_smtp,
         lt_tax           TYPE  bus_ei_bupa_taxnumber_t,
         ls_tax           TYPE  bus_ei_bupa_taxnumber,
         ls_central       TYPE vmds_ei_vmd_central,
         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,
         lt_texts         TYPE cvis_ei_text_t,
         ls_texts         TYPE cvis_ei_text,
         lt_tab           TYPE tline_tab,
         ls_tab           TYPE tline,
         ls_remarks       TYPE bus_ei_bupa_comrem,
         lt_remarks       TYPE bus_ei_bupa_comrem_t.
  DATA : lv_bpartnerguid TYPE bu_partner_guid_bapi,
         lv_partner      TYPE bu_partner.
  LOOP AT it_upload_pur INTO DATA(ls_pur).
    MOVE-CORRESPONDING ls_pur TO ls_pur_result.

*通过查询采购组织判断是创建还是查询
    SELECT SINGLE *
    FROM but000
    INTO @DATA(ls_but000)
    WHERE partner = @ls_pur-partner.

    IF sy-subrc = 0.
      DATA(lv_object_task) = 'M'.
      lv_bpartnerguid = ls_but000-partner_guid.
    ELSE.
      lv_object_task = 'I'.
      TRY .
          lv_bpartnerguid = cl_uuid_factory=>create_system_uuid( )->create_uuid_x16( ).
        CATCH cx_uuid_error.
      ENDTRY.
    ENDIF.

    "採購角色
    CLEAR:lt_roles.
    ls_roles-task = lv_object_task.
    ls_roles-data_key = 'FLVN00' .
    APPEND ls_roles TO lt_roles.
    ls_partner-central_data-role-roles = lt_roles.

    ls_partner-header-object_task = lv_object_task.
    ls_partner-header-object_instance-bpartner     = ls_pur-partner."  供應商編碼
    ls_partner-header-object_instance-bpartnerguid = lv_bpartnerguid.

    ls_partner-central_data-common-data-bp_organization-name1 = ls_pur-name_org1.      "供應商名稱1
    ls_partner-central_data-common-datax-bp_organization-name1 = abap_true.      "供應商名稱1

    CLEAR:lt_functions,lt_purchasing.
    ls_purchasing-task = lv_object_task.
    ls_purchasing-data_key-ekorg = ls_pur-ekorg.  "採購組織
    ls_purchasing-data-waers = ls_pur-waers.       "採購訂單貨幣
    ls_purchasing-data-zterm = ls_pur-zterm.      "付款條件
    ls_purchasing-data-inco1 = ls_pur-inco1.      "貿易條款
    ls_purchasing-data-inco2 = ls_pur-inco2.      "貿易條款地點1
    ls_purchasing-data-vsbed = ls_pur-vsbed.      "裝運條件
    ls_purchasing-data-webre = ls_pur-webre.        "發票驗證
    ls_purchasing-data-verkf = ls_pur-verkf.           "業務人員

    ls_purchasing-datax-waers = abap_true."採購訂單貨幣
    ls_purchasing-datax-zterm = abap_true. "付款條件
    ls_purchasing-datax-inco1 = abap_true.    "貿易條款
    ls_purchasing-datax-inco2 = abap_true.    "貿易條款地點1
    ls_purchasing-datax-vsbed = abap_true.    "裝運條件
    ls_purchasing-datax-webre = abap_true.        "發票驗證
    ls_purchasing-datax-verkf = abap_true.        "業務人員

    APPEND ls_purchasing TO lt_purchasing.

    ls_purchasing_data-purchasing = lt_purchasing.
    ls_vendor-purchasing_data = ls_purchasing_data.

    ls_vendor-header-object_instance-lifnr = ls_pur-partner.
    ls_vendor-header-object_task = lv_object_task.
    ls_data-partner = ls_partner.
*    ls_data-vendor = ls_vendor.
    APPEND ls_data TO lt_data.

    PERFORM frm_cvi_ei  USING  lv_bpartnerguid
                                  CHANGING  lt_data
                                                     ls_return
                                                     lv_partner.

    IF ls_return-type = 'E'.
      ls_pur_result-flagf = icon_red_light.
    ELSE.
      ls_pur_result-flagf = icon_green_light.
      ls_pur_result-partner =  lv_partner.
    ENDIF.
    ls_pur_result-msg = ls_return-message.

    APPEND ls_pur_result TO it_pur_result.
    CLEAR  ls_pur_result .
    CLEAR  ls_return.
*    BREAK-POINT.
  ENDLOOP.

*ALV SHOW.
  PERFORM frm_create_row USING 'FLAGF' '標記'(t04) ''.
  PERFORM frm_create_row USING  'MSG' '消息'(t07) ''.
  PERFORM frm_create_row USING  'PARTNER' '業務夥伴種類 '(t38) ''.
  PERFORM frm_create_row USING  'NAME_ORG1' '供應商名稱'(t16) ''.
  PERFORM frm_create_row USING  'EKORG'  '採購組織'(t40) ''.
  PERFORM frm_create_row USING  'WAERS' '採購訂單貨幣'(t41) ''.
  PERFORM frm_create_row USING 'ZTERM' '付款條件'(t12) ''.
  PERFORM frm_create_row USING  'INCO1' '貿易條款'(t43) ''.
  PERFORM frm_create_row USING 'INCO2' '貿易條款地點1'(t44) ''.
  PERFORM frm_create_row USING 'VSBED' '裝運條件'(t45) ''.
  PERFORM frm_create_row USING 'WEBRE' '發票驗證'(t46) ''.
  PERFORM frm_create_row USING 'VERKF' '業務人員'(t52) ''.

  PERFORM display_result TABLES it_pur_result.
ENDFORM.


FORM f_maintain_company .
  DATA: ls_company_result TYPE typ_company_result,
        ls_return         TYPE bapiret2.

  DATA : ls_data TYPE  cvis_ei_extern,
         lt_data TYPE  cvis_ei_extern_t.

  DATA : ls_partner TYPE bus_ei_extern,
         ls_vendor  TYPE vmds_ei_extern.

* 根據夥伴GUID取出供應商編號
  DATA : lt_partnerguid_list TYPE bu_partner_guid_t,
         ls_partnerguid_list LIKE LINE OF lt_partnerguid_list.
  DATA : lt_vendor_list TYPE cvis_vend_link_t,
         ls_vendor_list TYPE cvi_vend_link.

  DATA : ls_header          TYPE vmds_ei_header,
         ls_central_data    TYPE vmds_ei_central_data,
         ls_company_data    TYPE  vmds_ei_vmd_company,
         ls_purchasing_data TYPE vmds_ei_vmd_purchasing.

  DATA : lt_roles         TYPE bus_ei_bupa_roles_t,
         ls_roles         TYPE bus_ei_bupa_roles,
         lt_ident_numbers TYPE bus_ei_bupa_identification_t,
         ls_ident_numbers TYPE bus_ei_bupa_identification,
         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_fax           TYPE bus_ei_bupa_fax_t,
         ls_fax           TYPE bus_ei_bupa_fax,
         lt_smtp          TYPE bus_ei_bupa_smtp_t,
         ls_smtp          TYPE bus_ei_bupa_smtp,
         lt_tax           TYPE  bus_ei_bupa_taxnumber_t,
         ls_tax           TYPE  bus_ei_bupa_taxnumber,
         ls_central       TYPE vmds_ei_vmd_central,
         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,
         lt_texts         TYPE cvis_ei_text_t,
         ls_texts         TYPE cvis_ei_text,
         lt_tab           TYPE tline_tab,
         ls_tab           TYPE tline,
         ls_remarks       TYPE bus_ei_bupa_comrem,
         lt_remarks       TYPE bus_ei_bupa_comrem_t.
  DATA : lv_bpartnerguid TYPE bu_partner_guid_bapi,
         lv_partner      TYPE bu_partner.

  LOOP AT it_upload_company INTO DATA(ls_comp).
    MOVE-CORRESPONDING ls_comp TO ls_company_result.

*通过查询采购组织判断是创建还是查询
    SELECT SINGLE *
    FROM but000
    INTO @DATA(ls_but000)
    WHERE partner = @ls_comp-partner.

    IF sy-subrc = 0.
      DATA(lv_object_task) = 'M'.
      lv_bpartnerguid = ls_but000-partner_guid.
    ELSE.
      lv_object_task = 'I'.
      TRY .
          lv_bpartnerguid = cl_uuid_factory=>create_system_uuid( )->create_uuid_x16( ).
        CATCH cx_uuid_error.
      ENDTRY.
    ENDIF.

    "公司角色
    CLEAR:lt_roles.
    ls_roles-task = lv_object_task.
    ls_roles-data_key = 'FLVN01' .    "
    APPEND ls_roles TO lt_roles.
    ls_partner-central_data-role-roles = lt_roles.


    ls_partner-header-object_task = lv_object_task.
    ls_partner-header-object_instance-bpartner     = ls_comp-partner."  供應商編碼
    ls_partner-header-object_instance-bpartnerguid = lv_bpartnerguid.

    ls_partner-central_data-common-data-bp_organization-name1 = ls_comp-name_org1.      "供應商名稱1
    ls_partner-central_data-common-datax-bp_organization-name1 = abap_true.      "供應商名稱1

    ls_company-task = lv_object_task.
    ls_company-data_key-bukrs = ls_comp-bukrs.     "公司代碼
    ls_company-data-akont =  ls_comp-akont.  "總帳的統馭科目
    ls_company-data-zterm = ls_comp-zterm.         "付款條件
    ls_company-data-zwels  = ls_comp-zwels."  付款方式
    ls_company-data-hbkid  = ls_comp-hbkid.  "  往來銀行

    ls_company-datax-akont = abap_true.
    ls_company-datax-zterm = abap_true.
    ls_company-datax-zwels  = abap_true.
    ls_company-datax-hbkid  = abap_true.

    APPEND ls_company TO lt_company.

    ls_vendor-company_data-company = lt_company.
    ls_vendor-header-object_task = lv_object_task.
    ls_data-partner = ls_partner.
*    ls_data-vendor = ls_vendor.
    APPEND ls_data TO lt_data.

    PERFORM frm_cvi_ei  USING  lv_bpartnerguid
                                  CHANGING  lt_data
                                                     ls_return
                                                     lv_partner.

    IF ls_return-type = 'E'.
      ls_company_result-flagf = icon_red_light.
    ELSE.
      ls_company_result-flagf = icon_green_light.
      ls_company_result-partner =  lv_partner.
    ENDIF.
    ls_company_result-msg = ls_return-message.

    APPEND ls_company_result TO it_company_result.
    CLEAR  ls_company_result .
    CLEAR  ls_return.
  ENDLOOP.

*ALV SHOW.
  PERFORM frm_create_row USING 'FLAGF'  '標記'(t04) ''.
  PERFORM frm_create_row USING 'MSG' '消息'(t07) ''.
  PERFORM frm_create_row USING 'PARTNER' '業務夥伴種類'(t38) ''.
  PERFORM frm_create_row USING 'NAME_ORG1' '供應商名稱'(t09) ''.
  PERFORM frm_create_row USING 'BUKRS' '公司代碼'(t10) ''.
  PERFORM frm_create_row USING 'AKONT' '總帳的統馭科目'(t11) ''.
  PERFORM frm_create_row USING 'ZTERM' '付款條件'(t12) ''.
  PERFORM frm_create_row USING 'ZWELS' '付款方式'(t13) ''.
  PERFORM frm_create_row USING 'HBKID' '往來銀行'(t14) ''.
  PERFORM display_result TABLES it_company_result.
ENDFORM.


FORM f_maintain_bank .
  DATA: ls_bank_result TYPE typ_bank_result,
        ls_return      TYPE bapiret2.

  DATA : ls_data TYPE  cvis_ei_extern,
         lt_data TYPE  cvis_ei_extern_t.

  DATA : ls_partner TYPE bus_ei_extern,
         ls_vendor  TYPE vmds_ei_extern.

* 根據夥伴GUID取出供應商編號
  DATA : lt_partnerguid_list TYPE bu_partner_guid_t,
         ls_partnerguid_list LIKE LINE OF lt_partnerguid_list.
  DATA : lt_vendor_list TYPE cvis_vend_link_t,
         ls_vendor_list TYPE cvi_vend_link.

  DATA : ls_header          TYPE vmds_ei_header,
         ls_central_data    TYPE vmds_ei_central_data,
         ls_company_data    TYPE  vmds_ei_vmd_company,
         ls_purchasing_data TYPE vmds_ei_vmd_purchasing.

  DATA : lt_roles         TYPE bus_ei_bupa_roles_t,
         ls_roles         TYPE bus_ei_bupa_roles,
         lt_ident_numbers TYPE bus_ei_bupa_identification_t,
         ls_ident_numbers TYPE bus_ei_bupa_identification,
         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_bankdetails   TYPE bus_ei_bupa_bankdetail_t,
         ls_bankdetails   TYPE bus_ei_bupa_bankdetail,
         lt_fax           TYPE bus_ei_bupa_fax_t,
         ls_fax           TYPE bus_ei_bupa_fax,
         lt_smtp          TYPE bus_ei_bupa_smtp_t,
         ls_smtp          TYPE bus_ei_bupa_smtp,
         lt_tax           TYPE  bus_ei_bupa_taxnumber_t,
         ls_tax           TYPE  bus_ei_bupa_taxnumber,
         ls_central       TYPE vmds_ei_vmd_central,
         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,
         lt_texts         TYPE cvis_ei_text_t,
         ls_texts         TYPE cvis_ei_text,
         lt_tab           TYPE tline_tab,
         ls_tab           TYPE tline,
         ls_remarks       TYPE bus_ei_bupa_comrem,
         lt_remarks       TYPE bus_ei_bupa_comrem_t.
  DATA : lv_bpartnerguid TYPE bu_partner_guid_bapi,
         lv_partner      TYPE bu_partner.

  LOOP AT it_upload_bank INTO DATA(ls_bank).
    MOVE-CORRESPONDING ls_bank TO ls_bank_result.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = ls_bank-partner
      IMPORTING
        output = ls_bank-partner.


    SELECT SINGLE *
    FROM but000
    INTO @DATA(ls_but000)
    WHERE partner = @ls_bank-partner.



    IF sy-subrc = 0.
      DATA(lv_object_task) = 'U'.
      lv_bpartnerguid = ls_but000-partner_guid.
    ELSE.
      lv_object_task = 'I'.
      TRY .
          lv_bpartnerguid = cl_uuid_factory=>create_system_uuid( )->create_uuid_x16( ).
        CATCH cx_uuid_error.
      ENDTRY.
    ENDIF.

    CLEAR:lt_roles.
    ls_roles-task = lv_object_task."lv_object_task'.
    ls_roles-data_key = 'FLVN00' .
    APPEND ls_roles TO lt_roles.
    ls_partner-central_data-role-roles = lt_roles.

    ls_partner-header-object_task = lv_object_task.
    ls_partner-header-object_instance-bpartner     = ls_bank-partner."  供應商編碼
    ls_partner-header-object_instance-bpartnerguid = lv_bpartnerguid.

    CLEAR lt_bankdetails.
    ls_bankdetails-task = lv_object_task.
    ls_bankdetails-data_key              = '0001'.
    ls_bankdetails-data-bank_ctry  = ls_bank-banks.     "银行国家代码參考國家頁籤
    ls_bankdetails-data-bankaccountname  = ls_bank-bkdsc.     "银行名称
    ls_bankdetails-data-bank_key  = ls_bank-bankl.     "银行代码
    ls_bankdetails-data-accountholder  = ls_bank-koinh.     "帳戶所有人
    ls_bankdetails-data-bank_acct  = ls_bank-bankn.     "银行帐户号码

    ls_bankdetails-datax-bank_ctry = abap_true.
    ls_bankdetails-datax-bankaccountname = abap_true.
    ls_bankdetails-datax-bank_key = abap_true.
    ls_bankdetails-datax-accountholder = abap_true.
    ls_bankdetails-datax-bank_acct  = abap_true.
    APPEND ls_bankdetails TO lt_bankdetails.

    ls_partner-central_data-bankdetail-bankdetails = lt_bankdetails.
    ls_vendor-header-object_instance-lifnr = ls_bank-partner.
    ls_vendor-header-object_task = lv_object_task. "U

    ls_data-partner = ls_partner.
*    ls_data-vendor = ls_vendor.
    APPEND ls_data TO lt_data.

    PERFORM frm_cvi_ei  USING  lv_bpartnerguid
                                  CHANGING  lt_data
                                                     ls_return
                                                     lv_partner.


    IF ls_return-type = 'E'.
      ls_bank_result-flagf = icon_red_light.
    ELSE.
      ls_bank_result-flagf = icon_green_light.
      ls_bank_result-partner =  lv_partner.
    ENDIF.
    ls_bank_result-msg = ls_return-message.

    APPEND ls_bank_result TO it_bank_result.
    CLEAR  ls_bank_result .
    CLEAR  ls_return.

  ENDLOOP.

*ALV SHOW.
  PERFORM frm_create_row USING 'FLAGF'  '標記'(t04) ''.
  PERFORM frm_create_row USING 'MSG' '消息'(t07) ''.
  PERFORM frm_create_row USING 'PARTNER' '業務夥伴種類'(t38) ''.
  PERFORM frm_create_row USING 'BANKS' '银行国家代码參考國家頁籤'(t47) ''.
  PERFORM frm_create_row USING 'BKDSC' '银行名称'(t48) ''.
  PERFORM frm_create_row USING 'BANKL' '银行代码'(t49) ''.
  PERFORM frm_create_row USING 'KOINH' '帳戶持有的公司名稱'(t50) ''.
  PERFORM frm_create_row USING 'BANKN' '銀行帳號'(t51) ''.


  PERFORM display_result TABLES it_bank_result.
ENDFORM.


FORM frm_cvi_ei  USING        fu_guid TYPE bu_partner_guid_bapi
                          CHANGING  ft_data  TYPE cvis_ei_extern_t
                                            fc_return TYPE bapiret2
                                            fc_partner TYPE bu_partner.

  DATA: lt_return TYPE bapiretm,
        lv_msg    TYPE string.

* 根據夥伴GUID取出供應商編號
  DATA : lt_partnerguid_list TYPE bu_partner_guid_t,
         ls_partnerguid_list LIKE LINE OF lt_partnerguid_list.

  DATA : lt_vendor_list TYPE cvis_vend_link_t,
         ls_vendor_list TYPE cvi_vend_link.

  "通過方法創建供應商住數據
  CALL FUNCTION 'CVI_EI_INBOUND_MAIN'
    EXPORTING
      i_data   = ft_data
*     I_EXT_DATA       =
    IMPORTING
      e_return = lt_return.

*    CLEAR LV_MSG.
  LOOP AT lt_return INTO DATA(ls_return).
    LOOP AT ls_return-object_msg INTO DATA(ls_msg) WHERE type CA 'EAX'.
      CONCATENATE lv_msg ls_msg-message INTO lv_msg.
    ENDLOOP.
  ENDLOOP.

  IF lv_msg IS INITIAL.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = abap_true.

** 根據夥伴GUID取出供應商編號
    ls_partnerguid_list = fu_guid.
    SELECT SINGLE partner
    FROM but000
    INTO fc_partner
    WHERE partner_guid = fu_guid.

    IF sy-subrc = 0.
      fc_return-type = 'S'.
      CONCATENATE '供应商' fc_partner '導入或修改成功!'  lv_msg INTO lv_msg.
      fc_return-message = lv_msg.
    ENDIF.

  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
    fc_return-type = 'E'.
    fc_return-message = lv_msg.
  ENDIF.

  CLEAR ft_data.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CREATE_ROW
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_create_row USING pv_name TYPE c
                             pv_txt  TYPE c
                             pv_outputlen TYPE c.

  w_fieldcat-fieldname = pv_name.
  w_fieldcat-scrtext_l = pv_txt.
  w_fieldcat-outputlen = pv_outputlen.
  APPEND w_fieldcat TO it_fieldcat_lvc.
  CLEAR w_fieldcat.
ENDFORM. " FRM_CREATE_ROW

fk03查看物料主数据信息。 该程序是根据选择的文件来导入主数据。 使用的方法是(两个都可以):

  • RFC_CVI_EI_INBOUND_MAIN RFC_CVI_EI_INBOUND_MAIN的使用
  • CVI_EI_INBOUND_MAIN CVI_EI_INBOUND_MAIN的使用

0 人点赞