供应商主数据创建

原文地址:供应商主数据创建 作者:Harvey

供应商主数据创建有三种方法:第一种是BDC 第二种是用SAP自身的一个方法VMD_EI_API=>MAINTAIN_BAPI 第三种是用IDOC的方式。IDOC的方式比较简单,通过配置IDOC然后就可以实现。IDOC TYPE为CREMAS03或者CREMAS05都可以 看你的需要啦。如果有些字段在IDOC TYPE里面没有的(比如EMAIL这样的字段)那么就要写IDOC增强,不过写增强还得找出口还得去增强标准的一些代码我觉得很烦,我是把它的IDOC关联的标准FUNCTION COPY出来创建完成后生成了供应商代码,然后再写一个更新EMAIL的function去更新email信息和其他IDOC TYPE 里面没有的字段信息。以下为通过VMD_EI_API=>MAINTAIN_BAPI 去创建供应商主数据的部分数据代码。

*&---------------------------------------------------------------------*
*& Report  ZVENDOR
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZVENDOR.
*&---------------------------------------------------------------------*
*&      Form  FRM_CREATE_VENDOR
*&---------------------------------------------------------------------*
      text
*----------------------------------------------------------------------*
     --> text
*----------------------------------------------------------------------*
              " FRM_CREATE_VENDOR

*&---------------------------------------------------------------------*
*&      Form  FRM_CREATE_VENDOR
*&---------------------------------------------------------------------*
      text
*----------------------------------------------------------------------*
     --> text
*----------------------------------------------------------------------*

  DATA: LS_RETURN TYPE BAPIRET2.
  DATA: LS_MASTER_DATA TYPE VMDS_EI_MAIN.
  DATA: LS_MASTER_DATA_CORRECT  TYPE  VMDS_EI_MAIN,
        LS_MESSAGE_CORRECT  TYPE  CVIS_MESSAGE,
        LS_MASTER_DATA_DEFECTIVE  TYPE  VMDS_EI_MAIN,
        LS_MESSAGE_DEFECTIVE  TYPE  CVIS_MESSAGE.
  DATA: LS_VMDS_EI_EXTERN TYPE VMDS_EI_EXTERN.
  DATA: LS_CORRECT_EXTERN TYPE VMDS_EI_EXTERN.
  DATA: LS_REMARKS TYPE CVIS_EI_REM.
  DATA: LS_BANK TYPE CVIS_EI_CVI_BANKDETAIL.
  DATA: LS_COMMUNICATION_PHONE TYPE CVIS_EI_PHONE_STR,
        LS_COMMUNICATION_FAX TYPE  CVIS_EI_FAX_STR,
        LS_COMMUNICATION_SMTP TYPE CVIS_EI_SMTP_STR.
  DATA: LV_STRING TYPE STRING .
  DATA: LV_APPROVED_DATE TYPE STRING,
        LV_APPROVED_DATE1 TYPE STRING.
  DATA: LV_ADRNR TYPE ADRNR,
        LS_KNVK TYPE KNVK,
       LS_ZMMR1010 TYPE ZMMR1010,
        LV_RETCODE TYPE NRRETURN,
        LV_PERSON_NUMBER TYPE AD_PERSNUM.
  DATA: LS_CVI_BANKDETAIL TYPE CVIS_EI_CVI_BANKDETAIL,
        LS_BANKDETAIL_KEY TYPE CVIS_EI_BANKDETAIL_KEY,
        LS_BANKDETAIL_DATA TYPE CVIS_EI_BANKDETAIL_DATA,
        LS_BANKDETAIL_DATAX TYPE CVIS_EI_BANKDETAIL_DATAX.
  DATA: LV_MAX_LIFNR TYPE LIFNR.
  DATA: LS_VMDS_CMP TYPE VMDS_EI_COMPANY,
        LS_VMDS_PUR TYPE VMDS_EI_PURCHASING,
        LS_VMDS_FUN TYPE VMDS_EI_FUNCTIONS.
  DATA: ZLFBK TYPE LFBK.
  DATA:IV_FLAG  TYPE C .
  CLEAR:LS_RETURN ,
        LS_MASTER_DATA ,
        LS_MASTER_DATA_CORRECT ,
        LS_MESSAGE_CORRECT  ,
        LS_MASTER_DATA_DEFECTIVE  ,
        LS_MESSAGE_DEFECTIVE  ,
        LS_VMDS_EI_EXTERN ,
        LS_CORRECT_EXTERN ,
        LS_REMARKS ,
        LS_BANK ,
        LS_COMMUNICATION_PHONE ,
        LS_COMMUNICATION_FAX ,
        LS_COMMUNICATION_SMTP ,
        LV_STRING ,
        LV_APPROVED_DATE ,
        LV_APPROVED_DATE1 ,
        LV_ADRNR ,
        LS_KNVK ,
        LV_RETCODE  ,
        LV_PERSON_NUMBER ,
        LS_CVI_BANKDETAIL ,
        LS_BANKDETAIL_KEY ,
        LS_BANKDETAIL_DATA ,
        LS_BANKDETAIL_DATAX ,
        LV_MAX_LIFNR ,
        LS_VMDS_CMP ,
        LS_VMDS_PUR ,
        LS_VMDS_FUN ,
        ZLFBK ,
        IV_FLAG .
  CLEAR LS_VMDS_EI_EXTERN.

* 维护标识:插入、更新
  IV_FLAG =  'I' .
  LS_VMDS_EI_EXTERN-HEADER-OBJECT_TASK = IV_FLAG.
LS_VMDS_EI_EXTERN-HEADER-OBJECT_INSTANCE-LIFNR = IT_LIFNR-LIFNR.  "供应商

* 公司代码默认:JNPC    ???
  CLEAR LS_VMDS_CMP.
  LS_VMDS_CMP-TASK = IV_FLAG.
  LS_VMDS_CMP-DATA_KEY-BUKRS = '2000' .  "取采购组织下的
  LS_VMDS_CMP-DATA-AKONT  = '0000062130'.        "总帐中的统驭科目  其他应付款-往来
  LS_VMDS_CMP-DATA-FDGRV  = 'A5'.
LS_VMDS_CMP-DATA-XVERR  = 'X'.                 " 结算客户

  LS_VMDS_CMP-DATAX-AKONT = 'X'.                  "总帐中的统驭科目  其他应付款-往来
  LS_VMDS_CMP-DATAX-FDGRV = 'X'.
LS_VMDS_CMP-DATAX-XVERR = 'X'.                "结算客户
  APPEND LS_VMDS_CMP TO LS_VMDS_EI_EXTERN-COMPANY_DATA-COMPANY.

* 采购组织默认:1000
CLEAR LS_VMDS_PUR.
LS_VMDS_PUR-TASK = IV_FLAG.
LS_VMDS_PUR-DATA_KEY-EKORG = IS_VENDOR_DATA-EKORG.
LS_VMDS_PUR-DATA-WAERS     = IS_VENDOR_DATA-WAERS."'RMB'.

* 合同伙伴
LS_VMDS_FUN-TASK = IV_FLAG.
LS_VMDS_FUN-DATA_KEY-PARVW = 'LF'.   "供应商
LS_VMDS_FUN-DATA-PARTNER =  .
LS_VMDS_FUN-DATAX-PARTNER = 'X'.
APPEND LS_VMDS_FUN TO LS_VMDS_PUR-FUNCTIONS-FUNCTIONS.

CLEAR LS_VMDS_FUN.
LS_VMDS_FUN-TASK = IV_FLAG.
LS_VMDS_FUN-DATA_KEY-PARVW = 'RS'. "发票提供者
LS_VMDS_FUN-DATA-PARTNER = LV_LIFNR.
LS_VMDS_FUN-DATAX-PARTNER = 'X'.
APPEND LS_VMDS_FUN TO LS_VMDS_PUR-FUNCTIONS-FUNCTIONS.

CLEAR LS_VMDS_FUN.
LS_VMDS_FUN-TASK = IV_FLAG.
LS_VMDS_FUN-DATA_KEY-PARVW = 'BA'. "订货地址在表TPAR里查  原厂商  VN 供应商
LS_VMDS_FUN-DATA-PARTNER = LV_LIFNR.
LS_VMDS_FUN-DATAX-PARTNER = 'X'.
APPEND LS_VMDS_FUN TO LS_VMDS_PUR-FUNCTIONS-FUNCTIONS.
APPEND LS_VMDS_PUR TO LS_VMDS_EI_EXTERN-PURCHASING_DATA-PURCHASING.

* 外部接口:组织地址
  LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-TASK = IV_FLAG.
  LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATA-TITLE   '0003'.       "公司
  LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATA-NAME    = '我擦'."描述
  LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATA-COUNTRY = 'CN' .         "国家
  LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATA-LANGU   = SY-LANGU.      "语言
  LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATA-SORT1  = '搜索条件.
LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATA-CITY = IS_VENDOR_DATA-ORT01.        "城市
LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATA-POSTL_COD1 = IS_VENDOR_DATA-PSTLZ.  "邮编
LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATA-SORT1 = IS_VENDOR_DATA-ZGFJC. "简称
LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATA-COMM_TYPE = 'INT'. "???邮件
LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATA-EXTENS_1 = LV_APPROVED_DATE. "资质有效期

  LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-TITLE   = 'X'.
  LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-NAME    = 'X'.
  LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-COUNTRY = 'X'.
  LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-LANGU   = 'X'.
   LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-SORT1 = 'X' .
LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-CITY = 'X'.        "城市
LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-DISTRICT = 'X'.     "???
LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-POSTL_COD1 = 'X' . “邮编
ls_vmds_ei_extern-central_data-address-postal-datax-postl_cod2 = 'X'.
LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-PO_BOX = 'X'.      "邮政信箱???
LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-STREET = 'X'.      "街道
LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-SORT1 = 'X'.
LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-REGION = 'X'."地区(省/自治区/直辖市、市、县)
LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-COMM_TYPE = 'X'.
LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-EXTENS_1 = 'X'. "资质有效期

*
CLEAR:LV_STRING, LS_VMDS_FUN.
CONCATENATE 'L_' IT_LIFNR-LIFNR INTO  LV_STRING .
IF IT_LIFNR-LIFNR =  'Y001'.
   LV_STRING = 'Y_SH01' .   "特殊情况
ENDIF.
CONDENSE LV_STRING NO-GAPS .
  LS_VMDS_EI_EXTERN-CENTRAL_DATA-CENTRAL-DATA-KUNNR     = '0000000484' .    "客户
  LS_VMDS_EI_EXTERN-CENTRAL_DATA-CENTRAL-DATA-VBUND     = '002000' .    "贸易伙伴
  LS_VMDS_EI_EXTERN-CENTRAL_DATA-CENTRAL-DATA-KTOKK     = 'Z001'.   "帐户组

  LS_VMDS_EI_EXTERN-CENTRAL_DATA-CENTRAL-DATAX-KUNNR    = 'X' .   "客户
  LS_VMDS_EI_EXTERN-CENTRAL_DATA-CENTRAL-DATAX-VBUND    = 'X' .   "贸易伙伴
  LS_VMDS_EI_EXTERN-CENTRAL_DATA-CENTRAL-DATAX-KTOKK    = 'X' .

IF IS_VENDOR_DATA-BANKN IS NOT INITIAL AND IS_VENDOR_DATA-BANKL IS NOT INITIAL.
   LS_bank-TASK = IV_FLAG.
   LS_bank-DATA_KEY-BANKS = IS_VENDOR_DATA-LAND1. "银行国家代码 = IV_FLAG.
   LS_bank-DATA_KEY-BANKL = IS_VENDOR_DATA-BANKL. "银行帐户号码
   LS_bank-DATA_KEY-BANKN =  IS_VENDOR_DATA-BANKN."银行编号
   LS_bank-DATA-BKREF =  IS_VENDOR_DATA-BANKN2."银行编号参考
   IF IV_FLAG = 'U'.
     SELECT SINGLE * INTO ZLFBK FROM LFBK WHERE LIFNR =  LV_LIFNR.
     IF SY-SUBRC = 0.
       LS_BANK-TASK = 'D'.
       LS_BANK-DATA_KEY-BANKS = ZLFBK-BANKS. "银行国家代码 = IV_FLAG.
       LS_BANK-DATA_KEY-BANKL = ZLFBK-BANKL. "银行帐户号码
       LS_BANK-DATA_KEY-BANKN = ZLFBK-BANKN."银行编号
     LS_bank-DATA-BKREF =  IS_VENDOR_DATA-BANKN2."银行编号参考
     LS_bank-DATAX-BKREF =  'X'."银行编号参考
       APPEND LS_BANK TO LS_VMDS_EI_EXTERN-CENTRAL_DATA-BANKDETAIL-BANKDETAILS.
     ENDIF.
   ENDIF.
   LS_BANK-TASK = 'I'.
   LS_BANK-DATA_KEY-BANKS = IS_VENDOR_DATA-LAND1. "银行国家代码 = IV_FLAG.
   LS_BANK-DATA_KEY-BANKL = IS_VENDOR_DATA-BANKL. "银行帐户号码
   LS_BANK-DATA_KEY-BANKN =  IS_VENDOR_DATA-BANKN."银行编号
   LS_BANK-DATA-BKREF =  IS_VENDOR_DATA-BANKN2."银行编号参考
   APPEND LS_BANK TO LS_VMDS_EI_EXTERN-CENTRAL_DATA-BANKDETAIL-BANKDETAILS.
   if IV_FLAG = 'U'.
     LS_VMDS_EI_EXTERN-CENTRAL_DATA-BANKDETAIL-CURRENT_STATE = IV_FLAG.
   endif.
ENDIF.
* 外部接口:地址注释
LS_REMARKS-TASK = IV_FLAG.
*
LS_REMARKS-DATA-LANGU =  SY-LANGU.
LS_REMARKS-DATAX-LANGU = 'X'.
LS_REMARKS-DATAX-ADR_NOTES = 'X'.
APPEND LS_REMARKS TO LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-REMARK-REMARKS.
*
** 外部接口:电话号码
LS_COMMUNICATION_PHONE-CONTACT-TASK = IV_FLAG.
LS_COMMUNICATION_PHONE-CONTACT-DATA-TELEPHONE = IS_VENDOR_DATA-TELF1.
LS_COMMUNICATION_PHONE-CONTACT-DATA-COUNTRY = IS_VENDOR_DATA-LAND1. "'CN'.IS_VENDOR_DATA-COUNTRY.
*
LS_COMMUNICATION_PHONE-CONTACT-DATAX-TELEPHONE = 'X'.
LS_COMMUNICATION_PHONE-CONTACT-DATAX-COUNTRY = 'X'.
APPEND LS_COMMUNICATION_PHONE TO LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-COMMUNICATION-PHONE-PHONE.
** 外部接口:传真
LS_COMMUNICATION_FAX-CONTACT-TASK = IV_FLAG.
LS_COMMUNICATION_FAX-CONTACT-DATA-FAX = IS_VENDOR_DATA-TELFX.
LS_COMMUNICATION_FAX-CONTACT-DATA-COUNTRY = IS_VENDOR_DATA-LAND1. "'CN'.IS_VENDOR_DATA-COUNTRY.
*
LS_COMMUNICATION_FAX-CONTACT-DATAX-FAX = 'X'.
LS_COMMUNICATION_FAX-CONTACT-DATAX-COUNTRY = 'X'.
APPEND LS_COMMUNICATION_FAX TO LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-COMMUNICATION-FAX-FAX.
*
*
** 扩展接口:电子邮件号
LS_COMMUNICATION_SMTP-CONTACT-TASK = IV_FLAG.
LS_COMMUNICATION_SMTP-CONTACT-DATA-E_MAIL = IS_VENDOR_DATA-SMTP_ADDR.
LS_COMMUNICATION_SMTP-CONTACT-DATAX-E_MAIL = 'X'.
APPEND LS_COMMUNICATION_SMTP TO LS_VMDS_EI_EXTERN-CENTRAL_DATA-ADDRESS-COMMUNICATION-SMTP-SMTP.

* 复杂外部接口的供应商
  APPEND LS_VMDS_EI_EXTERN TO LS_MASTER_DATA-VENDORS.

  SET UPDATE TASK LOCAL.

* 调用api维护供应商
  CALL METHOD VMD_EI_API=>MAINTAIN_BAPI
    EXPORTING
      IV_COLLECT_MESSAGES      = 'X'
      IS_MASTER_DATA           = LS_MASTER_DATA
    IMPORTING
      ES_MASTER_DATA_CORRECT   = LS_MASTER_DATA_CORRECT
      ES_MESSAGE_CORRECT       = LS_MESSAGE_CORRECT
      ES_MASTER_DATA_DEFECTIVE = LS_MASTER_DATA_DEFECTIVE
      ES_MESSAGE_DEFECTIVE     = LS_MESSAGE_DEFECTIVE.

* 返回结果处理
  LOOP AT LS_MESSAGE_DEFECTIVE-MESSAGES
  TRANSPORTING NO FIELDS
  WHERE TYPE CA 'EA'.
    EXIT.
  ENDLOOP.
  IF SY-SUBRC = 0. "失败

    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
   IT_LIFNR-FLAG = 'N' .
  ELSE."成功

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT = 'X'.
   IT_LIFNR-FLAG = 'Y' .

  ENDIF.
                    " FRM_CREATE_VENDOR

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值