SAP SD CMD_EI_API=>MAINTAIN 创建客户主数据

 DATA: IS_MAIN       TYPE ZSDT_CUSTOMER.
DATA: IS_SALES      TYPE ZSDT_SALES.
DATA: IT_BUKRS      TYPE STANDARD TABLE OF ZSDT_SALES.
DATA: IS_BUKRS      TYPE ZSDT_SALES.
DATA: IS_CONTACT    TYPE ZSDT_CONTACT.
DATA: GV_KUNNR      TYPE KUNNR.
DATA: ES_RETURN     TYPE ZSDT_CUST_RETURN.
DATA: GS_HEADER     TYPE CMDS_EI_HEADER.
DATA: GS_CENTRAL    TYPE CMDS_EI_CENTRAL_DATA.
DATA: GT_CUST       TYPE CMDS_EI_EXTERN_T,
      GS_CUST       TYPE CMDS_EI_EXTERN,
      GS_MAIN       TYPE CMDS_EI_MAIN,
      GT_FUNCTIONS  TYPE CMDS_EI_FUNCTIONS_T,
      GS_FUNCTIONS  TYPE CMDS_EI_FUNCTIONS,
      GS_MESG       TYPE CVIS_MESSAGE,
      GS_MESG1      TYPE CVIS_MESSAGE,
      GS_MAIN1      TYPE CMDS_EI_MAIN,
      GS_MAIN2      TYPE CMDS_EI_MAIN,
      GS_SALE       TYPE CMDS_EI_SALES,
      GT_SALE       TYPE CMDS_EI_SALES_T,
      GT_COMPANY    TYPE CMDS_EI_COMPANY_T,
      GS_TAX        TYPE CMDS_EI_TAX_IND,
      GT_TAX        TYPE CMDS_EI_TAX_IND_T,
      GT_FAX        TYPE CVIS_EI_FAX_T,
      GT_FAX1       TYPE CVIS_EI_FAX_T,
      GS_FAX        TYPE CVIS_EI_FAX_STR,
      GS_FAX1       TYPE CVIS_EI_FAX_STR,
      GT_PHONE      TYPE CVIS_EI_PHONE_T,
      GT_PHONE1     TYPE CVIS_EI_PHONE_T,
      GS_PHONE      TYPE CVIS_EI_PHONE_STR,
      GS_PHONE1     TYPE CVIS_EI_PHONE_STR,
      GS_COMPANY    TYPE CMDS_EI_COMPANY,
      GS_REMARK     TYPE CVIS_EI_REM,
      GS_ERROR      TYPE CVIS_MESSAGE,
      GS_CONTACT    TYPE CMDS_EI_CONTACTS,
      GT_CONTACT    TYPE CMDS_EI_CONTACTS_T,
      GT_BANK       TYPE CVIS_EI_BANKDETAIL_T,
      GS_BANK       TYPE CVIS_EI_CVI_BANKDETAIL.
DATA: GS_TEL        TYPE CVIS_EI_TTX_STR.
DATA: GT_TEL        TYPE CVIS_EI_TTX_T.
DATA: GS_PHONE2     TYPE CVIS_EI_TLX_STR.
DATA: GT_PHONE2     TYPE CVIS_EI_TLX_T.
DATA: GS_EMAIL      TYPE CVIS_EI_SMTP_STR.
DATA: GT_EMAIL      TYPE CVIS_EI_SMTP_T.
DATA: GS_MESSAGE    TYPE BAPIRET2.

  LOOP AT IT_MAIN INTO IS_MAIN.

      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          INPUT  = IS_MAIN-KUNNR
        IMPORTING
          OUTPUT = GV_KUNNR.

  CLEAR: GS_HEADER    ,
         GS_CENTRAL   ,
         GT_CUST      ,
         GS_CUST      ,
         GS_MAIN      ,
         GT_FUNCTIONS ,
         GS_FUNCTIONS ,
         GS_MESG      ,
         GS_MESG1     ,
         GS_MAIN1     ,
         GS_MAIN2     ,
         GS_SALE      ,
         GT_SALE      ,
         GT_COMPANY   ,
         GS_TAX       ,
         GT_TAX       ,
         GT_FAX       ,
         GT_FAX1      ,
         GS_FAX       ,
         GS_FAX1      ,
         GT_PHONE     ,
         GT_PHONE1    ,
         GS_PHONE     ,
         GS_PHONE1    ,
         GS_COMPANY   ,
         GS_REMARK    ,
         GS_ERROR     ,
         GS_CONTACT   ,
         GT_CONTACT   ,
         GT_BANK      ,
         GS_BANK      ,
         GS_TEL       ,
         GT_TEL       ,
         GS_PHONE2    ,
         GT_PHONE2    ,
         GS_EMAIL     ,
         GT_EMAIL     ,
         GS_MESSAGE   .

      GS_CUST-HEADER-OBJECT_INSTANCE-KUNNR = GV_KUNNR.
      GS_CUST-HEADER-OBJECT_TASK = 'M'.
*-----------------------------------------------------------------CENTAL DATA
      GS_CUST-CENTRAL_DATA-CENTRAL-DATA-KTOKD = 'Z002'.   "IS_MAIN-KTOKD放到定义字段“账户组
      "GS_CUST-CENTRAL_DATA-CENTRAL-DATA-UWAER = IS_MAIN-UWAER.   "币别
      GS_CUST-CENTRAL_DATA-CENTRAL-DATA-STCEG = IS_MAIN-STCEG.   "增值税登记号
      "GS_CUST-CENTRAL_DATA-CENTRAL-DATA-UMSA1 = ''.              "年度销售
      GS_CUST-CENTRAL_DATA-CENTRAL-DATA-STKZU = IS_MAIN-STKZU.             "增值税义务

      GS_CUST-CENTRAL_DATA-CENTRAL-DATAX-KTOKD = 'X'."账户组
      "GS_CUST-CENTRAL_DATA-CENTRAL-DATAX-UWAER = IS_MAIN-UWAER.   "币别
      GS_CUST-CENTRAL_DATA-CENTRAL-DATAX-STCEG = 'X'."IS_MAIN-STCEG'.   "增值税登记号
      "GS_CUST-CENTRAL_DATA-CENTRAL-DATAX-UMSA1 = 'X'.   "年度销售
      GS_CUST-CENTRAL_DATA-CENTRAL-DATAX-STKZU = 'X'.             "增值税义务

*税分类
      GS_TAX-TASK = 'M'.
      GS_TAX-DATA_KEY-ALAND = 'CN'.
      GS_TAX-DATA_KEY-TATYP = 'MWST' .
      GS_TAX-DATA-TAXKD = '1'.
      GS_TAX-DATAX-TAXKD = 'X'.
      APPEND GS_TAX TO GT_TAX.

*-----------------------------------------------------------------ADDRESS DATA
      GS_CUST-CENTRAL_DATA-ADDRESS-TASK  = 'M'.
      GS_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-NAME       = IS_MAIN-NAME1.       "名称 1
      GS_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-NAME_2     = IS_MAIN-NAME2.       "名称 2
      GS_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-SORT1      = IS_MAIN-SORTL.       "检索项1
      GS_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-STREET     = IS_MAIN-STREET.      "街道
      GS_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-DISTRICT     = IS_MAIN-STR_SUPPL3.  "区域
      GS_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-POSTL_COD1 = IS_MAIN-POST_CODE1.  "城市邮政编码
      GS_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-COUNTRY    = IS_MAIN-LAND1.       "国家
      GS_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-CITY       = IS_MAIN-ORT01.       "城市
      GS_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-LANGU      = SY-LANGU.            "语言代码

      GS_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-NAME       = 'X'.       "名称 1
      GS_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-NAME_2     = 'X'.       "名称 2
      GS_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-SORT1      = 'X'.       "检索项1
      GS_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-STREET     = 'X'.       "街道
      GS_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-DISTRICT     = 'X'.       "区域
      GS_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-POSTL_COD1 = 'X'.       "城市邮政编码
      GS_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-COUNTRY    = 'X'.       "国家
      GS_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-CITY       = 'X'.       "城市
      GS_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-LANGU      = 'X'.       "语言代码

*第一个电话
      GS_PHONE-CONTACT-TASK = 'M'.
      GS_PHONE-CONTACT-DATA-TELEPHONE = IS_MAIN-TEL_NUMBER.
      GS_PHONE-CONTACT-DATAX-TELEPHONE = 'X'.
      APPEND GS_PHONE TO GT_PHONE.
      GS_CUST-CENTRAL_DATA-ADDRESS-COMMUNICATION-PHONE-PHONE = GT_PHONE.

*传真
      GS_FAX-CONTACT-TASK = 'M'.
      GS_FAX-CONTACT-DATA-FAX = IS_MAIN-FAX_NUMBER.
      GS_FAX-CONTACT-DATAX-FAX = 'X'.
      APPEND GS_FAX TO GT_FAX.
      GS_CUST-CENTRAL_DATA-ADDRESS-COMMUNICATION-FAX-FAX = GT_FAX.

**电子邮件
*      GS_MAIL-CONTACT-TASK = 'M'.
*      GS_MAIL-CONTACT-DATA-E_MAIL = W_BASIS-SMTP.
*      GS_MAIL-CONTACT-DATAX-E_MAIL = 'X'.
*      APPEND GS_MAIL TO GT_MAIL.
*      GS_CUST-CENTRAL_DATA-ADDRESS-COMMUNICATION-SMTP-SMTP = GT_MAIL.

       GS_BANK-TASK = 'M'.
       GS_BANK-DATA_KEY-BANKS = 'CN'.  "银行国家代码
       GS_BANK-DATA_KEY-BANKL = '99999'.  "银行编号
       GS_BANK-DATA_KEY-BANKN = IS_MAIN-BANKN.  "银行帐户号码

       GS_BANK-DATA-KOINH     = IS_MAIN-KOINH.  "银行帐户编号
       GS_BANK-DATA-BKREF     = IS_MAIN-BKREF.  "银行帐户的参考规定
       GS_BANK-DATAX-KOINH    = 'X'.  "银行帐户编号
       GS_BANK-DATAX-BKREF    = 'X'.  "银行帐户的参考规定

       APPEND GS_BANK TO GT_BANK.
       GS_CUST-CENTRAL_DATA-BANKDETAIL-BANKDETAILS = GT_BANK.


*-----------------------------------------------------------------SALES DATA
      LOOP AT IT_SALES INTO IS_SALES.
        GS_SALE-TASK = 'M'.
        GS_SALE-DATA_KEY-VKORG =  IS_SALES-VKORG."销售组织
        GS_SALE-DATA_KEY-VTWEG =  IS_SALES-VTWEG."分销渠道
        GS_SALE-DATA_KEY-SPART =  '10'.           "产品组

*        GS_SALE-DATA-INCO1     =  IS_SALES-INCO1."国际贸易条款 (部分1)
        GS_SALE-DATA-ZTERM     =  IS_MAIN-ZTERM."付款条件代码
*       GS_SALE-DATA-VWERK     =  IS_SALES-VWERK."交货工厂
        GS_SALE-DATA-AWAHR     =  '100'.         "订单可能性
        GS_SALE-DATA-VSBED     =  '01'.          "装运条件
        GS_SALE-DATA-PODKZ     =  'X'.           "与POD相关
        GS_SALE-DATA-BZIRK     =  '100000'.      "销售地区
        GS_SALE-DATA-KALKS     =  '1'.           "定价过程
        GS_SALE-DATA-KONDA     =  '01'.          "价格组(客户)
        GS_SALE-DATA-WAERS     =  'CNY'.         "货币

*        GS_SALE-DATAX-INCO1     =  'X'."国际贸易条款 (部分1)
        GS_SALE-DATAX-ZTERM     =  'X'."付款条件代码
*        GS_SALE-DATAX-VWERK      =  'X'."交货工厂
        GS_SALE-DATAX-AWAHR     =  'X'."订单可能性
        GS_SALE-DATAX-VSBED     =  'X'."装运条件
        GS_SALE-DATAX-PODKZ     =  'X'."与POD相关
        GS_SALE-DATAX-BZIRK     =  'X'."销售地区
        GS_SALE-DATAX-KALKS     =  'X'."定价过程
        GS_SALE-DATAX-KONDA     =  'X'."价格组(客户)
        GS_SALE-DATAX-WAERS     =  'X'."货币


        GS_FUNCTIONS-TASK = 'M'.
        GS_FUNCTIONS-DATA_KEY-PARVW = 'AG'.
        GS_FUNCTIONS-DATA-PARTNER = GV_KUNNR.
        GS_FUNCTIONS-DATAX-PARTNER = 'X'.
        APPEND GS_FUNCTIONS TO GT_FUNCTIONS.
        CLEAR GS_FUNCTIONS.

        GS_FUNCTIONS-TASK = 'M'.
        GS_FUNCTIONS-DATA_KEY-PARVW = 'RE'.
        GS_FUNCTIONS-DATA-PARTNER = GV_KUNNR.
        GS_FUNCTIONS-DATAX-PARTNER = 'X'.
        APPEND GS_FUNCTIONS TO GT_FUNCTIONS.
        CLEAR GS_FUNCTIONS.

        GS_FUNCTIONS-TASK = 'M'.
        GS_FUNCTIONS-DATA_KEY-PARVW = 'RG'.
        GS_FUNCTIONS-DATA-PARTNER = GV_KUNNR.
        GS_FUNCTIONS-DATAX-PARTNER = 'X'.
        APPEND GS_FUNCTIONS TO GT_FUNCTIONS.
        CLEAR GS_FUNCTIONS.

        GS_FUNCTIONS-TASK = 'M'.
        GS_FUNCTIONS-DATA_KEY-PARVW = 'WE'.
        GS_FUNCTIONS-DATA-PARTNER = GV_KUNNR.
        GS_FUNCTIONS-DATAX-PARTNER = 'X'.
        APPEND GS_FUNCTIONS TO GT_FUNCTIONS.
        CLEAR GS_FUNCTIONS.

        GS_SALE-FUNCTIONS-FUNCTIONS = GT_FUNCTIONS.
        APPEND GS_SALE TO GT_SALE.
        CLEAR  GS_SALE.
        CLEAR  GT_FUNCTIONS.
      ENDLOOP.

      LOOP AT IT_BUKRS INTO IS_BUKRS.

        GS_COMPANY-TASK = 'M'.
        GS_COMPANY-DATA_KEY-BUKRS  = IS_BUKRS-BUKRS.
"KTOKD=Z002和Z003时取1122000100;              当KTOKD=Z080时取1170000010
        IF IS_MAIN-KTOKD = 'Z002' OR IS_MAIN-KTOKD = 'Z003'.
         GS_COMPANY-DATA-AKONT      = '1122000100'.
         ELSEIF IS_MAIN-KTOKD = 'Z080'.
         GS_COMPANY-DATA-AKONT      = '1170000010'.
        ENDIF.
        GS_COMPANY-DATA-ZUAWA       = '001'.        "排序码
"如果客户国家=CN,取E2;否则E3
        IF IS_MAIN-LAND1 = 'CN'.
        GS_COMPANY-DATA-FDGRV       = 'E2'.       "现金管理组
        ELSE.
        GS_COMPANY-DATA-FDGRV       = 'E3'.       "现金管理组
        ENDIF.


        GS_COMPANY-DATAX-AKONT      = 'X'.
        GS_COMPANY-DATAX-ZUAWA      = 'X'.
        GS_COMPANY-DATAX-FDGRV      = 'X'.
        APPEND GS_COMPANY TO GT_COMPANY.
        CLEAR GS_COMPANY.
      ENDLOOP.

      LOOP AT IT_CONTACT INTO IS_CONTACT.
       CLEAR: LV_PARNR,GC_TASK.
"这是判断联系人是否创建过,有则修改,无则创建
        SELECT SINGLE PARNR INTO LV_PARNR FROM KNVK
          WHERE KUNNR = GV_KUNNR
          AND   PARAU = IS_CONTACT-PARAU.
        IF SY-SUBRC NE 0.
        CMD_EI_API=>GET_CONTACT_NUMBER( IMPORTING EV_PARNR = GS_CONTACT-DATA_KEY-PARNR
                                                  ES_ERROR = GS_ERROR ).
        GC_TASK = 'M'.
        ELSE.
        GS_CONTACT-DATA_KEY-PARNR = LV_PARNR.
        GC_TASK = 'U'.
        ENDIF.
        GS_CONTACT-TASK = GC_TASK.

        GS_CONTACT-DATA-PAFKT = IS_CONTACT-PAFKT."联系人功能
        GS_CONTACT-DATA-PARAU = IS_CONTACT-PARAU."关于联系人的注释

        GS_CONTACT-DATAX-PAFKT = 'X'."联系人功能
        GS_CONTACT-DATAX-PARAU = 'X'."关于联系人的注释

        GS_CONTACT-ADDRESS_TYPE_1-TASK = GC_TASK.
        GS_CONTACT-ADDRESS_TYPE_1-POSTAL-DATA-NAME = IS_CONTACT-NAME1.
        GS_CONTACT-ADDRESS_TYPE_1-POSTAL-DATAX-NAME = 'X'.


        GS_CONTACT-ADDRESS_TYPE_1-POSTAL-DATA-STR_SUPPL3 = IS_CONTACT-STR_SUPPL3.
        GS_CONTACT-ADDRESS_TYPE_1-POSTAL-DATAX-STR_SUPPL3 = 'X'.
        GS_CONTACT-ADDRESS_TYPE_1-POSTAL-DATA-STREET = IS_CONTACT-STREET.
        GS_CONTACT-ADDRESS_TYPE_1-POSTAL-DATAX-STREET = 'X'.
        GS_CONTACT-ADDRESS_TYPE_1-POSTAL-DATA-POSTL_COD1 = '123456'.
        GS_CONTACT-ADDRESS_TYPE_1-POSTAL-DATAX-POSTL_COD1 = 'X'.
        GS_CONTACT-ADDRESS_TYPE_1-POSTAL-DATA-COUNTRY = 'CN'.
        GS_CONTACT-ADDRESS_TYPE_1-POSTAL-DATAX-COUNTRY = 'X'.

        "GS_CONTACT-DATA_KEY-PARNR = IS_CONTACT-PARAU.
        GS_CONTACT-ADDRESS_TYPE_3-TASK = 'M'.
        "GS_CONTACT-ADDRESS_TYPE_3-POSTAL-DATA-FIRSTNAME = IS_CONTACT-PARAU.   "名
        GS_CONTACT-ADDRESS_TYPE_3-POSTAL-DATA-LASTNAME =  IS_CONTACT-NAME1.   "姓
        "GS_CONTACT-ADDRESS_TYPE_3-POSTAL-DATAX-FIRSTNAME = 'X'.
        GS_CONTACT-ADDRESS_TYPE_3-POSTAL-DATAX-LASTNAME = 'X'.


*第一个电话
        IF IS_CONTACT-TELF1 IS NOT INITIAL .
        GS_PHONE1-CONTACT-TASK =  'M'.
        GS_PHONE1-CONTACT-DATA-TELEPHONE  = IS_CONTACT-TELF1.
        GS_PHONE1-CONTACT-DATA-R_3_USER = '1'.
        GS_PHONE1-CONTACT-DATAX-TELEPHONE = 'X'.
        GS_PHONE1-CONTACT-DATAX-R_3_USER = 'X'.
        APPEND GS_PHONE1 TO GT_PHONE1.
        CLEAR  GS_PHONE1.
        GS_CONTACT-ADDRESS_TYPE_1-COMMUNICATION-PHONE-PHONE = GT_PHONE1.
        ENDIF.

*传真号
       IF IS_CONTACT-FAX_NUMBER IS NOT INITIAL .
        GS_FAX1-CONTACT-TASK = 'M'.
        GS_FAX1-CONTACT-DATA-FAX  = IS_CONTACT-FAX_NUMBER.
        GS_FAX1-CONTACT-DATAX-FAX = 'X'.
        APPEND GS_FAX1 TO GT_FAX1.
        CLEAR: GS_FAX1.
        GS_CONTACT-ADDRESS_TYPE_1-COMMUNICATION-FAX-FAX = GT_FAX1.
       ENDIF.

*手机号
       IF IS_CONTACT-MOB_NUMBER IS NOT INITIAL .
        GS_PHONE1-CONTACT-TASK =  'M'.
        GS_PHONE1-CONTACT-DATA-TELEPHONE = IS_CONTACT-MOB_NUMBER.
        GS_PHONE1-CONTACT-DATA-R_3_USER = '3'.                    "这里是设置它为手机号的
        GS_PHONE1-CONTACT-DATAX-TELEPHONE = 'X'.
        GS_PHONE1-CONTACT-DATAX-R_3_USER = 'X'.
        APPEND GS_PHONE1 TO GT_PHONE1.
        CLEAR  GS_PHONE1.
        GS_CONTACT-ADDRESS_TYPE_1-COMMUNICATION-PHONE-PHONE = GT_PHONE1.
        ENDIF.


*电子邮件
        IF IS_CONTACT-SMTP_ADDR IS NOT INITIAL .
          GS_EMAIL-CONTACT-TASK = 'M'.
          GS_EMAIL-CONTACT-DATA-E_MAIL  = IS_CONTACT-SMTP_ADDR.
          GS_EMAIL-CONTACT-DATAX-E_MAIL = 'X'.
          APPEND GS_EMAIL TO GT_EMAIL.
          CLEAR: GS_EMAIL.
          GS_CONTACT-ADDRESS_TYPE_1-COMMUNICATION-SMTP-SMTP = GT_EMAIL.
        ENDIF.

        APPEND GS_CONTACT to GT_CONTACT.
        CLEAR GS_CONTACT.
      ENDLOOP.


      GS_CUST-CENTRAL_DATA-CONTACT-CONTACTS = GT_CONTACT.
      GS_CUST-CENTRAL_DATA-TAX_IND-TAX_IND = GT_TAX.
      GS_CUST-COMPANY_DATA-COMPANY         = GT_COMPANY.
      GS_CUST-SALES_DATA-SALES             = GT_SALE.
      APPEND GS_CUST TO GT_CUST.
      GS_MAIN-CUSTOMERS = GT_CUST.

      CALL METHOD CMD_EI_API=>MAINTAIN
        EXPORTING
          IV_TEST_RUN    = SPACE
          IS_MASTER_DATA = GS_MAIN
        IMPORTING
          ES_ERROR       = GS_ERROR.
      IF GS_ERROR-IS_ERROR IS INITIAL .
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait = 'X'.

        ES_RETURN-KUNNR  = GV_KUNNR.
        ES_RETURN-STATUS = '0'.
        ES_RETURN-MESSAGE = '客户创建成功'.
        APPEND ES_RETURN TO ET_RETURN.
      ELSE.
        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
        ES_RETURN-KUNNR  = GV_KUNNR.
        ES_RETURN-STATUS = '4'.

        LOOP AT GS_ERROR-MESSAGES INTO GS_MESSAGE WHERE TYPE = 'E' .
        CONCATENATE ES_RETURN-MESSAGE GS_MESSAGE-MESSAGE INTO ES_RETURN-MESSAGE.
        ENDLOOP.
        APPEND ES_RETURN TO ET_RETURN.
      ENDIF.
    ENDLOOP.

 

 

上一篇:pwn_向进程中植入代码(未成功


下一篇:*面qq对话