其他分享
首页 > 其他分享> > 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.
"-----------------------------@斌将军-----------------------------

 

标签:创建,供应商,data,lv,lt,BP,ls,template,TYPE
来源: https://www.cnblogs.com/BinGeneral/p/16058727.html