【SD】客户主数据批导CVI_EI_INBOUND_MAIN

源代码

1主函数部分,根据接口传入的标识,判断

FUNCTION ZZSD_CUSTOMER_CREATE.
*"----------------------------------------------------------------------
*"*"本地接口
*"  IMPORTING
*"     VALUE(I_RLTGR) TYPE  BU_RLGROUP DEFAULT 'ZCUST'
*"     VALUE(I_BU_GROUP) TYPE  BU_GROUP DEFAULT 'Z001'
*"  EXPORTING
*"     VALUE(E_CODE) TYPE  MSGTY
*"     VALUE(E_MSG) TYPE  MSGTXT
*"  TABLES
*"      T_INPUT STRUCTURE  ZSSD0040
*"      T_OUTPUT STRUCTURE  ZSSD0041
*"----------------------------------------------------------------------
*"*"本地接口
*"  IMPORTING
*"     VALUE(I_RLTGR) TYPE  BU_RLGROUP DEFAULT 'ZCUST'
*"     VALUE(I_BU_GROUP) TYPE  BU_GROUP DEFAULT 'Z001'
*"  EXPORTING
*"     VALUE(E_CODE) TYPE  MSGTY
*"     VALUE(E_MSG) TYPE  MSGTXT
*"  TABLES
*"      T_INPUT STRUCTURE  ZSSD0040
*"      T_OUTPUT STRUCTURE  ZSSD0041
  " PROGRAMMED BY HANDYY 20181108   创建和修改日志记录同步到自建表ZTSD0041
*"----------------------------------------------------------------------
  MACRO_SAVE_LOG_BEFORE_PROC.     "日志保存——保存函数名称

  MACRO_SAVE_LOG_AFTER_PROC 'IN'"日志保存——输入参数

  DATA:S_INPUT TYPE ZSSD0040,
       T_IN    TYPE STANDARD TABLE OF ZSSD0040.

  DATAE_RTYPE TYPE MSGTY,
        E_RTMSG TYPE MSGTXT.


  LOOP AT T_INPUT INTO S_INPUT.
    APPEND S_INPUT TO T_IN.
    CASE S_INPUT-ZUDID.
      WHEN 'A'.
        "创建客户主数据(基本视图,公司视图,销售视图)
        PERFORM FRM_CUSTOMER_CREATGE TABLES T_IN
                                            T_OUTPUT
                                     
USING  I_RLTGR
                                            I_BU_GROUP
                                     
CHANGING E_CODE
                                              E_MSG
.
        CLEAR T_IN[].
      WHEN 'C'.
        "创建客户主数据(公司视图,销售视图)
        PERFORM FRM_CUSTOMER_CREATGE2 TABLES T_IN
                                            T_OUTPUT
                                     
USING  I_RLTGR
                                            I_BU_GROUP
                                     
CHANGING E_CODE
                                              E_MSG
.
        CLEAR T_IN[].
      WHEN 'B'.
        "修改客户主数据(修改账期【付款条件】字段)
        PERFORM FRM_CUSTOMER_CHANGE TABLES T_IN
                                           T_OUTPUT
                                    
USING  I_RLTGR
                                           I_BU_GROUP
                                    
CHANGING E_CODE
                                             E_MSG
.

        CLEAR T_IN[].
      WHEN OTHERS.
        E_CODE 'E'.
        E_MSG '您输入的标识错误,请重新输入'.
        CLEAR T_IN[].
    ENDCASE.
    CLEAR S_INPUT.
  ENDLOOP.

  E_RTYPE E_CODE.
  E_RTMSG E_MSG.

  MACRO_SAVE_LOG_AFTER_PROC 'OUT'"日志保存——输出参数

ENDFUNCTION.

2.客户主数据的创建(全部视图)


*----------------------------------------------------------------------*
***INCLUDE LZSDI001F03.           PROGRAMMED BY HANDYY 20181108
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  FRM_CUSTOMER_CREATGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_CUSTOMER_CREATGE TABLES PT_IN STRUCTURE ZSSD0040
                                 PT_OUTPUT 
STRUCTURE ZSSD0041
                          
USING   PV_RLTGR
                                  PV_BU_GROUP
                          
CHANGING PV_CODE
                                   PV_MSG
.

  TYPES:BEGIN OF TY_KNA1,
          NAME1 TYPE KNA1-NAME1,
          KUNNR TYPE KNA1-KUNNR,
        END OF TY_KNA1.

  DATALT_KNA1  TYPE STANDARD TABLE OF TY_KNA1,
        LT_KUNNR TYPE STANDARD TABLE OF TY_KNA1,
        LS_KUNNR TYPE TY_KNA1.

  DATALS_OUTPUT TYPE ZSSD0041,
        LT_RECORD TYPE STANDARD TABLE OF ZTSD0041"同步日志到自建表
        LS_RECORD TYPE ZTSD0041.


  DATA LT_PARTNERGUID_LIST TYPE BU_PARTNER_GUID_T,
         LS_PARTNERGUID_LIST LIKE LINE OF LT_PARTNERGUID_LIST.
  DATA LT_CUSTOMER_LIST TYPE CVIS_CUST_LINK_T,
         LS_CUSTOMER_LIST TYPE CVI_CUST_LINK.

  DATA LS_DATA   TYPE  CVIS_EI_EXTERN,
         LT_DATA   TYPE  CVIS_EI_EXTERN_T,
         LT_RETURN TYPE  BAPIRETM,
         LS_RETURN TYPE  BAPIRETI,
         LS_MSG    TYPE  BAPIRETC.

  DATA LS_PARTNER  TYPE BUS_EI_EXTERN,
         LS_CUSTOMER TYPE CMDS_EI_EXTERN.


  DATA LS_HEADER       TYPE CMDS_EI_HEADER,
         LS_CENTRAL_DATA TYPE CMDS_EI_CENTRAL_DATA,
         LS_COMPANY_DATA TYPE CMDS_EI_CMD_COMPANY,
         LS_SALES_DATA   TYPE CMDS_EI_CMD_SALES.

  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,
         LS_REMARKS       TYPE BUS_EI_BUPA_COMREM,
         LT_REMARKS       TYPE BUS_EI_BUPA_COMREM_T,
         LT_COMPANY       TYPE CMDS_EI_COMPANY_T,
         LS_COMPANY       TYPE CMDS_EI_COMPANY,
         LT_SALES         TYPE CMDS_EI_SALES_T,
         LS_SALES         TYPE CMDS_EI_SALES,
         LT_FUNCTIONS     TYPE CMDS_EI_FUNCTIONS_T,
         LS_FUNCTIONS     TYPE CMDS_EI_FUNCTIONS,
         LS_CENTRAL       TYPE CMDS_EI_CMD_CENTRAL,
         LT_TAX_IND       TYPE CMDS_EI_TAX_IND_T,
         LS_TAX_IND       TYPE CMDS_EI_TAX_IND.

  FIELD-SYMBOLS TYPE ZSSD0040.


  DATA LV_BPARTNERGUID TYPE BU_PARTNER_GUID_BAPI.

  LOOP AT PT_IN ASSIGNING .    "创建时需要获取唯一标识ID
    TRY .
        LV_BPARTNERGUID CL_UUID_FACTORY=>CREATE_SYSTEM_UUID( )->CREATE_UUID_X16( ).
      CATCH CX_UUID_ERROR.
        "返回消息

    ENDTRY.
    IF -NAME1 IS INITIAL.   "不输入公司名称会导致后面的公司代码视图和销售你视图扩充失败,故此处创建时需要校验名称不为空
      PV_CODE 'E'.
      PV_MSG '请输入公司名称'.
    ELSE.
      SELECT
        NAME1
        
INTO TABLE LT_KNA1
        
FROM KNA1
        
WHERE NAME1 -NAME1.
      IF SY-SUBRC <> 0.

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'    "客户编号加前导零
          EXPORTING
            INPUT  -KUNNR
          
IMPORTING
            OUTPUT -KUNNR.

        LS_PARTNER-HEADER-OBJECT_TASK 'I'.         "I插入 U更新 M修改 D删除 C当前状态
        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 PV_BU_GROUP.    "业务伙伴分组


        LS_PARTNER-CENTRAL_DATA-COMMON-DATA-BP_ORGANIZATION-NAME1 -NAME1名称1
        LS_PARTNER-CENTRAL_DATA-COMMON-DATA-BP_ORGANIZATION-NAME2 -NAME2名称2
        LS_PARTNER-CENTRAL_DATA-COMMON-DATA-BP_ORGANIZATION-NAME3 -NAME3名称3
        LS_PARTNER-CENTRAL_DATA-COMMON-DATA-BP_ORGANIZATION-NAME4 -NAME4名称4
        LS_PARTNER-CENTRAL_DATA-COMMON-DATA-BP_CENTRALDATA-SEARCHTERM1 -SORTL.  搜索项
        LS_PARTNER-CENTRAL_DATA-COMMON-DATA-BP_CENTRALDATA-TITLE_KEY =  -ANRED称谓


        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-TITLE_KEY ABAP_TRUE.

        "必须扩充业务伙伴角色分组下的全部业务伙伴角色才能扩充出该业务伙伴角色分组
        CLEAR:LS_ROLES,LT_ROLES.
        LS_ROLES-TASK 'I'.
        LS_ROLES-DATA_KEY 'FLCU00'.            "业务伙伴角色
*      LS_ROLES-DATA-ROLECATEGORY = 'FLCU00'.     "业务伙伴角色类别
        APPEND LS_ROLES TO LT_ROLES.

        CLEAR:LS_ROLES.
        LS_ROLES-TASK 'I'.
        LS_ROLES-DATA_KEY 'FLCU01'.            "业务伙伴角色
*      LS_ROLES-DATA-ROLECATEGORY = 'FLCU01'.     "业务伙伴角色类别
        APPEND LS_ROLES TO LT_ROLES.
        LS_PARTNER-CENTRAL_DATA-ROLE-ROLES LT_ROLES.

        CLEAR:LS_ADDRESSES,LT_ADDRESSES.
        LS_ADDRESSES-TASK 'I'.                "I插入 U更新 M修改 D删除 C当前状态
        LS_ADDRESSES-DATA-POSTAL-DATA-PO_CTRYISO -LAND1.   国家代码
        LS_ADDRESSES-DATA-POSTAL-DATA-CITY -ORT01.         "城市
        LS_ADDRESSES-DATA-POSTAL-DATA-REGION -REGIO.       地区代码
        LS_ADDRESSES-DATA-POSTAL-DATA-C_O_NAME -NAME1_LXR联系人姓名
        LS_ADDRESSES-DATA-POSTAL-DATA-STREET -STRAS.       街道
        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
          EXPORTING
            INPUT  -LIFNR
          
IMPORTING
            OUTPUT LS_ADDRESSES-DATA-POSTAL-DATA-POSTL_COD1.


*      LS_ADDRESSES-DATA-POSTAL-DATA-POSTL_COD1 = -LIFNR.     "邮政编码
        LS_ADDRESSES-DATA-POSTAL-DATA-STR_SUPPL1 -STR_SUPPL1街道2
        LS_ADDRESSES-DATA-POSTAL-DATA-STR_SUPPL2 -STR_SUPPL2街道3
        LS_ADDRESSES-DATA-POSTAL-DATA-STR_SUPPL3 -STR_SUPPL3街道4

        CALL FUNCTION 'CONVERSION_EXIT_ISOLA_INPUT'
          EXPORTING
            INPUT            -SPRAS
          
IMPORTING
            OUTPUT           LS_ADDRESSES-DATA-POSTAL-DATA-LANGU
          
EXCEPTIONS
            UNKNOWN_LANGUAGE 1
            OTHERS           2.
        IF SY-SUBRC <> 0.
* Implement suitable error handling here
        ENDIF.

*      LS_ADDRESSES-DATA-POSTAL-DATA-LANGU = -SPRAS.           "语言

        LS_ADDRESSES-DATA-POSTAL-DATAX-PO_CTRYISO ABAP_TRUE国家代码
        LS_ADDRESSES-DATA-POSTAL-DATAX-CITY ABAP_TRUE.       "城市
        LS_ADDRESSES-DATA-POSTAL-DATAX-REGION ABAP_TRUE.     地区代码
        LS_ADDRESSES-DATA-POSTAL-DATAX-C_O_NAME ABAP_TRUE.   代收人
        LS_ADDRESSES-DATA-POSTAL-DATAX-POSTL_COD1 ABAP_TRUE.       邮政编码
        LS_ADDRESSES-DATA-POSTAL-DATAX-STREET ABAP_TRUE.           街道
        LS_ADDRESSES-DATA-POSTAL-DATAX-STR_SUPPL1 ABAP_TRUE.     街道2
        LS_ADDRESSES-DATA-POSTAL-DATAX-STR_SUPPL2 ABAP_TRUE.     街道3
        LS_ADDRESSES-DATA-POSTAL-DATAX-STR_SUPPL3 ABAP_TRUE.     街道4
        LS_ADDRESSES-DATA-POSTAL-DATAX-LANGU ABAP_TRUE.         "语言

        CLEAR:LS_PHONE,LT_PHONE.
        LS_PHONE-CONTACT-TASK 'I'.  "I插入 U更新 M修改 D删除 C当前状态
        LS_PHONE-CONTACT-DATA-TELEPHONE -TELF1.  "电话
        LS_PHONE-CONTACT-DATAX-TELEPHONE ABAP_TRUE.
        APPEND LS_PHONE TO LT_PHONE.
        CLEAR:LS_PHONE.
        LS_PHONE-CONTACT-TASK 'I'.  "I插入 U更新 M修改 D删除 C当前状态
        LS_PHONE-CONTACT-DATA-TELEPHONE -TELF2"手机
        LS_PHONE-CONTACT-DATA-R_3_USER '3'.    "3表示移动电话
        LS_PHONE-CONTACT-DATAX-TELEPHONE ABAP_TRUE.
        LS_PHONE-CONTACT-DATAX-R_3_USER ABAP_TRUE.
        APPEND LS_PHONE TO LT_PHONE.
        LS_ADDRESSES-DATA-COMMUNICATION-PHONE-PHONE LT_PHONE.

        CLEAR:LS_FAX,LT_FAX.
        LS_FAX-CONTACT-TASK 'I'.   "I插入 U更新 M修改 D删除 C当前状态
        LS_FAX-CONTACT-DATA-FAX -TELFX.  "传真号
        LS_FAX-CONTACT-DATAX-FAX ABAP_TRUE.
        APPEND LS_FAX TO LT_FAX.
        LS_ADDRESSES-DATA-COMMUNICATION-FAX-FAX LT_FAX.

        CLEAR:LS_SMTP,LT_SMTP.
        LS_SMTP-CONTACT-TASK 'I'.   "I插入 U更新 M修改 D删除 C当前状态
        LS_SMTP-CONTACT-DATA-E_MAIL -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.
        LS_PARTNER-CENTRAL_DATA-ADDRESS-ADDRESSES LT_ADDRESSES.


*******客户抬头数据***********************************************************
        LS_HEADER-OBJECT_TASK 'I'.


        LS_CUSTOMER-HEADER =  LS_HEADER.

****中心客户数据*************************************************
        LS_CENTRAL-DATA-NIELS -NIELS.     "Nielsen 标识
*      LS_CENTRAL-DATA-BRSCH = -BRSCH.     "行业代码
        LS_CENTRAL-DATA-KUKLA -KUKLA.     "客户分类
        LS_CENTRAL-DATA-BRAN1 -BRAN1.     "行业代码1
*        LS_CENTRAL-DATA-LIFNR = -LIFNR.     "供应商或债权人的帐号
        LS_CENTRAL-DATA-KONZS -KONZS.     "组代码
*      LS_CENTRAL-DATA-STCEG = |{ -STCEG ALPHA = IN }|.     "增值税登记号
*      LS_CENTRAL-DATA-KTOKD = |{ -KTOKD ALPHA = IN }|.     "客户账户组

        LS_CENTRAL-DATAX-NIELS ABAP_TRUE.
*      LS_CENTRAL-DATAX-BRSCH = ABAP_TRUE.
        LS_CENTRAL-DATAX-KUKLA ABAP_TRUE.
        LS_CENTRAL-DATAX-BRAN1 ABAP_TRUE.
*        LS_CENTRAL-DATAX-LIFNR = ABAP_TRUE.
        LS_CENTRAL-DATAX-KONZS ABAP_TRUE.
        LS_CUSTOMER-CENTRAL_DATA-CENTRAL LS_CENTRAL.

****公司代码数据************************************************
        IF -BUKRS IS NOT INITIAL.
          CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'   统驭科目补前导零
            EXPORTING
              INPUT  -AKONT
            
IMPORTING
              OUTPUT -AKONT.

          LS_COMPANY-TASK 'I'.
          LS_COMPANY-DATA_KEY-BUKRS '1210'公司代码

          LS_COMPANY-DATA-AKONT -AKONT统驭科目
          LS_COMPANY-DATA-ZTERM -ZTERM_KNB1付款条款
          LS_COMPANY-DATA-EIKTO -EIKTO_D.   "客户处我方账户(对账日期)
          LS_COMPANY-DATA-KVERM -KVERM.     "备注(收票截止日期)

          LS_COMPANY-DATAX-AKONT ABAP_TRUE.
          LS_COMPANY-DATAX-ZTERM ABAP_TRUE.
          LS_COMPANY-DATAX-EIKTO ABAP_TRUE.
          LS_COMPANY-DATAX-KVERM ABAP_TRUE.
          APPEND LS_COMPANY TO LT_COMPANY.

          LS_COMPANY-TASK 'I'.
          LS_COMPANY-DATA_KEY-BUKRS '1200'公司代码

          LS_COMPANY-DATA-AKONT -AKONT统驭科目
          LS_COMPANY-DATA-ZTERM -ZTERM_KNB1付款条款
          LS_COMPANY-DATA-EIKTO -EIKTO_D.   "客户处我方账户(对账日期)
          LS_COMPANY-DATA-KVERM -KVERM.     "备注(收票截止日期)

          LS_COMPANY-DATAX-AKONT ABAP_TRUE.
          LS_COMPANY-DATAX-ZTERM ABAP_TRUE.
          LS_COMPANY-DATAX-EIKTO ABAP_TRUE.
          LS_COMPANY-DATAX-KVERM ABAP_TRUE.
          APPEND LS_COMPANY TO LT_COMPANY.

          LS_COMPANY_DATA-COMPANY LT_COMPANY.
          LS_CUSTOMER-COMPANY_DATA LS_COMPANY_DATA.
        ENDIF.

*********税收标识********************************************************
        LS_TAX_IND-TASK 'I'.
        LS_TAX_IND-DATA_KEY-ALAND 'CN'.
        LS_TAX_IND-DATA_KEY-TATYP 'MWST'.

        IF -VTWEG '20'.
          LS_TAX_IND-DATA-TAXKD '0'.  "客户税分类
        ELSE.
          LS_TAX_IND-DATA-TAXKD '1'.  "客户税分类
        ENDIF.


        LS_TAX_IND-DATA-TAXKD -TAXKD.  "客户税分类
        LS_TAX_IND-DATAX-TAXKD ABAP_TRUE.
        APPEND LS_TAX_IND TO LT_TAX_IND.
        LS_CUSTOMER-CENTRAL_DATA-TAX_IND-TAX_IND LT_TAX_IND.


*****销售数据****************************************************
*      IF -KTOKD <> 'ZS03' AND -KTOKD <> 'ZS07' AND -KTOKD <> 'ZS08'  .
        IF  -VKORG IS NOT INITIAL
            AND -VTWEG IS NOT INITIAL
            AND -SPART IS NOT INITIAL.
          LS_SALES-TASK 'I'.
          LS_SALES-DATA_KEY-VKORG '1200'.    "销售组织
          LS_SALES-DATA_KEY-VTWEG -VTWEG.    "分销渠道
          LS_SALES-DATA_KEY-SPART -SPART.    "产品组

          IF -VTWEG '20'.
            LS_SALES-DATA-WAERS 'USD'.        "货币
            LS_SALES-DATA-KALKS '1'.        "用于确定定价过程的客户分类
          ELSE.
            LS_SALES-DATA-WAERS 'CNY'.        "货币
            LS_SALES-DATA-KALKS '2'.        "用于确定定价过程的客户分类
          ENDIF.


*          LS_SALES-DATA-KALKS = -KALKS.        "用于确定定价过程的客户分类
          LS_SALES-DATA-VSBED -VSBED.        "装运条件
          LS_SALES-DATA-KDGRP -KDGRP.        "客户组
          LS_SALES-DATA-KONDA -KONDA.        "客户价格组
          LS_SALES-DATA-KTGRD -KTGRD.        "此客户的账户分配组
          LS_SALES-DATA-EIKTO -EIKTO.        "客户处我方账户(送货区域/路线)
          LS_SALES-DATA-ZTERM -ZTERM_KNVV.   "付款条件(账期)


*          LS_SALES-DATAX-WAERS = ABAP_TRUE.
*          LS_SALES-DATAX-KALKS = ABAP_TRUE.
          LS_SALES-DATAX-VSBED ABAP_TRUE.
*          LS_SALES-DATAX-PODKZ = ABAP_TRUE.
*          LS_SALES-DATAX-INCO1 = ABAP_TRUE.
*          LS_SALES-DATAX-INCO2 = ABAP_TRUE.
          LS_SALES-DATAX-KDGRP ABAP_TRUE.
          LS_SALES-DATAX-KONDA ABAP_TRUE.
          LS_SALES-DATAX-KTGRD ABAP_TRUE.
          LS_SALES-DATAX-EIKTO ABAP_TRUE.
          LS_SALES-DATAX-ZTERM ABAP_TRUE.


*          Function伙伴功能  (如果不添加,会导致销售视图无法维护成功,从而使公司代码视图也无法成功维护)
          LS_FUNCTIONS-TASK 'I'.
          IF -ZUDID 'A'.
*          LS_FUNCTIONS-DATA_KEY-PARVW = 'Z1'.
*          LS_FUNCTIONS-DATA-PARTNER = -LIFNR_YW.   "业务员编码
            CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
              EXPORTING
                INPUT  'SP' "收票方
              IMPORTING
                OUTPUT LS_FUNCTIONS-DATA_KEY-PARVW.
            APPEND LS_FUNCTIONS TO LT_FUNCTIONS.

            CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
              EXPORTING
                INPUT  'BP' "收票方
              IMPORTING
                OUTPUT LS_FUNCTIONS-DATA_KEY-PARVW.
            APPEND LS_FUNCTIONS TO LT_FUNCTIONS.

            CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
              EXPORTING
                INPUT  'PY' "收票方
              IMPORTING
                OUTPUT LS_FUNCTIONS-DATA_KEY-PARVW.
            APPEND LS_FUNCTIONS TO LT_FUNCTIONS.

            CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
              EXPORTING
                INPUT  'SH' "收票方
              IMPORTING
                OUTPUT LS_FUNCTIONS-DATA_KEY-PARVW.
            APPEND LS_FUNCTIONS TO LT_FUNCTIONS.
          ELSE.
*          LS_FUNCTIONS-DATA_KEY-PARVW = 'Z2'.
*          LS_FUNCTIONS-DATA-PARTNER = -LIFNR_YG.   "销售内勤编码(营管员编码)
          ENDIF.

*        APPEND LS_FUNCTIONS TO LT_FUNCTIONS.
          LS_SALES-FUNCTIONS-FUNCTIONS LT_FUNCTIONS.

          APPEND LS_SALES TO LT_SALES.

*增加1210 s
          LS_SALES-TASK 'I'.
          LS_SALES-DATA_KEY-VKORG '1210'.    "销售组织
          LS_SALES-DATA_KEY-VTWEG -VTWEG.    "分销渠道
          LS_SALES-DATA_KEY-SPART -SPART.    "产品组

          IF -VTWEG '20'.
            LS_SALES-DATA-WAERS 'USD'.        "货币
            LS_SALES-DATA-KALKS '1'.        "用于确定定价过程的客户分类
          ELSE.
            LS_SALES-DATA-WAERS 'CNY'.        "货币
            LS_SALES-DATA-KALKS '2'.        "用于确定定价过程的客户分类
          ENDIF.

*          LS_SALES-DATA-KALKS = -KALKS.        "用于确定定价过程的客户分类
          LS_SALES-DATA-VSBED -VSBED.        "装运条件
          LS_SALES-DATA-KDGRP -KDGRP.        "客户组
          LS_SALES-DATA-KONDA -KONDA.        "客户价格组
          LS_SALES-DATA-KTGRD -KTGRD.        "此客户的账户分配组
          LS_SALES-DATA-EIKTO -EIKTO.        "客户处我方账户(送货区域/路线)
          LS_SALES-DATA-ZTERM -ZTERM_KNVV.   "付款条件(账期)

*          LS_SALES-DATAX-WAERS = ABAP_TRUE.
*          LS_SALES-DATAX-KALKS = ABAP_TRUE.
          LS_SALES-DATAX-VSBED ABAP_TRUE.
*          LS_SALES-DATAX-PODKZ = ABAP_TRUE.
*          LS_SALES-DATAX-INCO1 = ABAP_TRUE.
*          LS_SALES-DATAX-INCO2 = ABAP_TRUE.
          LS_SALES-DATAX-KDGRP ABAP_TRUE.
          LS_SALES-DATAX-KONDA ABAP_TRUE.
          LS_SALES-DATAX-KTGRD ABAP_TRUE.
          LS_SALES-DATAX-EIKTO ABAP_TRUE.
          LS_SALES-DATAX-ZTERM ABAP_TRUE.

*          Function伙伴功能
          LS_FUNCTIONS-TASK 'I'.
          IF -ZUDID 'A'.
*          LS_FUNCTIONS-DATA_KEY-PARVW = 'Z1'.
*          LS_FUNCTIONS-DATA-PARTNER = -LIFNR_YW.   "业务员编码
            CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
              EXPORTING
                INPUT  'SP' "收票方
              IMPORTING
                OUTPUT LS_FUNCTIONS-DATA_KEY-PARVW.
            APPEND LS_FUNCTIONS TO LT_FUNCTIONS.

            CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
              EXPORTING
                INPUT  'BP' "收票方
              IMPORTING
                OUTPUT LS_FUNCTIONS-DATA_KEY-PARVW.
            APPEND LS_FUNCTIONS TO LT_FUNCTIONS.

            CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
              EXPORTING
                INPUT  'PY' "收票方
              IMPORTING
                OUTPUT LS_FUNCTIONS-DATA_KEY-PARVW.
            APPEND LS_FUNCTIONS TO LT_FUNCTIONS.

            CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
              EXPORTING
                INPUT  'SH' "收票方
              IMPORTING
                OUTPUT LS_FUNCTIONS-DATA_KEY-PARVW.
            APPEND LS_FUNCTIONS TO LT_FUNCTIONS.
          ELSE.
          ENDIF.

          LS_SALES-FUNCTIONS-FUNCTIONS LT_FUNCTIONS.
          APPEND LS_SALES TO LT_SALES.
*增加1210 e

          LS_SALES_DATA-SALES LT_SALES.
          LS_CUSTOMER-SALES_DATA LS_SALES_DATA.
        ENDIF.
*      ENDIF.

        LS_DATA-PARTNER LS_PARTNER.
        LS_DATA-CUSTOMER LS_CUSTOMER.
*      LS_DATA-ENSURE_CREATE-CREATE_CUSTOMER = ABAP_TRUE.
        APPEND LS_DATA TO LT_DATA.

        "调用BP创建函数
        CALL FUNCTION 'CVI_EI_INBOUND_MAIN'
          EXPORTING
            I_DATA   LT_DATA
          
IMPORTING
            E_RETURN LT_RETURN.

        CLEARPV_CODEPV_MSG.
        LOOP AT LT_RETURN INTO LS_RETURN.
          LOOP AT LS_RETURN-OBJECT_MSG INTO DATA(LS_OBJECT_MSGWHERE TYPE CA 'EA'.
            IF PV_MSG IS INITIAL.
              PV_MSG LS_OBJECT_MSG-MESSAGE.
            ELSE.
              CONCATENATE PV_MSG '/' LS_OBJECT_MSG-MESSAGE INTO PV_MSG.
            ENDIF.
          ENDLOOP.
          
          
IF SY-SUBRC 0.
            "回滚BAPI
            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'"回滚BAPI
            PV_CODE 'E'.
            EXIT.
          ENDIF.
        ENDLOOP.

        IF PV_CODE <> 'E' .
          "提交BAPI
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
            EXPORTING
              WAIT 'X'.
*    IMPORTING
*     RETURN        =
          "去底表中取客户名称对应的客户编号
          CLEAR LS_KUNNR.
          SELECT SINGLE
            NAME1
            KUNNR
          
INTO  LS_KUNNR
          
FROM KNA1
          
WHERE NAME1 -NAME1.

          PV_CODE 'S'.
          CONCATENATE '客户编号为LS_KUNNR-KUNNR '的客户主数据创建成功INTO PV_MSG.

        ENDIF.

        LS_OUTPUT-Z003 -Z003.   "OA 号码
        LS_OUTPUT-PARTNER LS_KUNNR-KUNNR.  "业务伙伴编码
        LS_OUTPUT-RTYPE PV_CODE.        "消息类型
        LS_OUTPUT-RTMSG PV_MSG.         "消息文本
        APPEND LS_OUTPUT TO PT_OUTPUT.

        LS_RECORD-ZZOANUM -Z003.   "OA 号码
        LS_RECORD-KUNNR LS_KUNNR-KUNNR.    "业务伙伴编码
        LS_RECORD-ZZNAME1 -ANRED.  "客户名称
        LS_RECORD-BUKRS -BUKRS.    "公司代码
        LS_RECORD-ZZDATE SY-DATUM.          "SAP接收日期
        LS_RECORD-ZZTIME SY-UZEIT.          "SAP接收时间
        LS_RECORD-ZZRES PV_CODE.            "导入状态
        LS_RECORD-ZZEMES PV_MSG.            "报错信息
        MODIFY ZTSD0041 FROM  LS_RECORD.     "更新日志表


      ELSE.
        PV_CODE 'E'.
        PV_MSG '此公司客户主数据已存在'.
      ENDIF.
    ENDIF.

  ENDLOOP.
ENDFORM.

3.公司代码和销售视图的维护

*----------------------------------------------------------------------*
***INCLUDE LZSDI001F06.    PROGRAMMED BY HANDYY 20181108
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  FRM_CUSTOMER_CREATGE2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_T_IN  text
*      -->P_T_OUTPUT  text
*      -->P_I_RLTGR  text
*      -->P_I_BU_GROUP  text
*      <--P_E_CODE  text
*      <--P_E_MSG  text
*----------------------------------------------------------------------*
FORM FRM_CUSTOMER_CREATGE2 TABLES PT_IN STRUCTURE ZSSD0040
                                 PT_OUTPUT 
STRUCTURE ZSSD0041
                          
USING   PV_RLTGR
                                  PV_BU_GROUP
                          
CHANGING PV_CODE
                                   PV_MSG
.

  DATALS_OUTPUT TYPE ZSSD0041,
        LT_RECORD TYPE STANDARD TABLE OF ZTSD0041"同步日志到自建表
        LS_RECORD TYPE ZTSD0041.

  DATA LT_PARTNERGUID_LIST TYPE BU_PARTNER_GUID_T,
         LS_PARTNERGUID_LIST LIKE LINE OF LT_PARTNERGUID_LIST.
  DATA LT_CUSTOMER_LIST TYPE CVIS_CUST_LINK_T,
         LS_CUSTOMER_LIST TYPE CVI_CUST_LINK.

  DATA LS_DATA   TYPE  CVIS_EI_EXTERN,
         LT_DATA   TYPE  CVIS_EI_EXTERN_T,
         LT_RETURN TYPE  BAPIRETM,
         LS_RETURN TYPE  BAPIRETI,
         LS_MSG    TYPE  BAPIRETC.

  DATA LS_PARTNER  TYPE BUS_EI_EXTERN,
         LS_CUSTOMER TYPE CMDS_EI_EXTERN.


  DATA LS_HEADER       TYPE CMDS_EI_HEADER,
         LS_CENTRAL_DATA TYPE CMDS_EI_CENTRAL_DATA,
         LS_COMPANY_DATA TYPE CMDS_EI_CMD_COMPANY,
         LS_SALES_DATA   TYPE CMDS_EI_CMD_SALES.

  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,
         LS_REMARKS       TYPE BUS_EI_BUPA_COMREM,
         LT_REMARKS       TYPE BUS_EI_BUPA_COMREM_T,
         LT_COMPANY       TYPE CMDS_EI_COMPANY_T,
         LS_COMPANY       TYPE CMDS_EI_COMPANY,
         LT_SALES         TYPE CMDS_EI_SALES_T,
         LS_SALES         TYPE CMDS_EI_SALES,
         LT_FUNCTIONS     TYPE CMDS_EI_FUNCTIONS_T,
         LS_FUNCTIONS     TYPE CMDS_EI_FUNCTIONS,
         LS_CENTRAL       TYPE CMDS_EI_CMD_CENTRAL,
         LT_TAX_IND       TYPE CMDS_EI_TAX_IND_T,
         LS_TAX_IND       TYPE CMDS_EI_TAX_IND.

  FIELD-SYMBOLS TYPE ZSSD0040.

  DATA LV_BPARTNERGUID TYPE BU_PARTNER_GUID_BAPI.


  LOOP AT PT_IN ASSIGNING .

    -KUNNR |{ -KUNNR ALPHA IN }|"加前导零
    
    
"获取业务伙伴对应的唯一标识
    SELECT SINGLE
      B~PARTNER,
      A~PARTNER_GUID
      
INTO @DATA(LS_BUT000)
      FROM CVI_CUST_LINK AS A INNER JOIN BUT000 AS B
                        
ON A~PARTNER_GUID B~PARTNER_GUID
      
WHERE CUSTOMER @-KUNNR.


    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'  "客户编号加前导零
      EXPORTING
        INPUT  -KUNNR
      
IMPORTING
        OUTPUT -KUNNR.
    LS_BUT000-PARTNER |{ LS_BUT000-PARTNER ALPHA IN }|"加前导零
    LS_PARTNER-HEADER-OBJECT_TASK 'M'.         "I插入 U更新 M修改 D删除 C当前状态
    LS_PARTNER-HEADER-OBJECT_INSTANCE-BPARTNER LS_BUT000-PARTNER.         "业务伙伴编号
    LS_PARTNER-HEADER-OBJECT_INSTANCE-BPARTNERGUID LS_BUT000-PARTNER_GUID.   "唯一标识
    LS_PARTNER-CENTRAL_DATA-COMMON-DATA-BP_CONTROL-CATEGORY 2.               "业务伙伴类别
    LS_PARTNER-CENTRAL_DATA-COMMON-DATA-BP_CONTROL-GROUPING PV_BU_GROUP.    "业务伙伴分组

*******客户抬头数据***********************************************************
    LS_HEADER-OBJECT_TASK 'U'.
    LS_HEADER-OBJECT_INSTANCE-KUNNR -KUNNR"客户编号
    LS_CUSTOMER-HEADER =  LS_HEADER.

****中心客户数据*************************************************
    LS_CENTRAL-DATA-NIELS -NIELS.     "Nielsen 标识
*      LS_CENTRAL-DATA-BRSCH = -BRSCH.     "行业代码
    LS_CENTRAL-DATA-KUKLA -KUKLA.     "客户分类
    LS_CENTRAL-DATA-BRAN1 -BRAN1.     "行业代码1
*    LS_CENTRAL-DATA-LIFNR = -LIFNR.     "供应商或债权人的帐号
    LS_CENTRAL-DATA-KONZS -KONZS.     "组代码
*      LS_CENTRAL-DATA-STCEG = -STCEG.     "增值税登记号
*      LS_CENTRAL-DATA-KTOKD = -KTOKD.     "客户账户组
    LS_CENTRAL-DATA-AUFSD '01'.   "客户主要订单块 (冻结相关)

    LS_CENTRAL-DATAX-NIELS ABAP_TRUE.
*      LS_CENTRAL-DATAX-BRSCH = ABAP_TRUE.
    LS_CENTRAL-DATAX-KUKLA ABAP_TRUE.
    LS_CENTRAL-DATAX-BRAN1 ABAP_TRUE.
*    LS_CENTRAL-DATAX-LIFNR = ABAP_TRUE.
    LS_CENTRAL-DATAX-KONZS ABAP_TRUE.
*      LS_CENTRAL-DATAX-STCEG = ABAP_TRUE.
    LS_CENTRAL-DATAX-AUFSD ABAP_TRUE.
    LS_CUSTOMER-CENTRAL_DATA-CENTRAL LS_CENTRAL.


****公司代码数据************************************************
    IF -BUKRS IS NOT INITIAL.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'   统驭科目补前导零
        EXPORTING
          INPUT  -AKONT
        
IMPORTING
          OUTPUT -AKONT.

      LS_COMPANY-TASK 'M'.
      LS_COMPANY-DATA_KEY-BUKRS -BUKRS公司代码

      LS_COMPANY-DATA-AKONT -AKONT统驭科目
      LS_COMPANY-DATA-ZTERM -ZTERM_KNB1付款条款
      LS_COMPANY-DATA-EIKTO -EIKTO_D.   "客户处我方账户(对账日期)
      LS_COMPANY-DATA-KVERM -KVERM.     "备注(收票截止日期)

      LS_COMPANY-DATAX-AKONT ABAP_TRUE.
      LS_COMPANY-DATAX-ZTERM ABAP_TRUE.
      LS_COMPANY-DATAX-EIKTO ABAP_TRUE.
      LS_COMPANY-DATAX-KVERM ABAP_TRUE.
      APPEND LS_COMPANY TO LT_COMPANY.

      LS_COMPANY_DATA-COMPANY LT_COMPANY.
      LS_CUSTOMER-COMPANY_DATA LS_COMPANY_DATA.
    ENDIF.

*********税收标识********************************************************
    LS_TAX_IND-TASK 'M'.
    LS_TAX_IND-DATA_KEY-ALAND 'CN'.
    LS_TAX_IND-DATA_KEY-TATYP 'MWST'.
    IF -VTWEG '20'.
      LS_TAX_IND-DATA-TAXKD '0'.  "客户税分类
    ELSE.
      LS_TAX_IND-DATA-TAXKD '1'.  "客户税分类
    ENDIF.
*    LS_TAX_IND-DATA-TAXKD = -TAXKD.  "客户税分类
    APPEND LS_TAX_IND TO LT_TAX_IND.
    LS_CUSTOMER-CENTRAL_DATA-TAX_IND-TAX_IND LT_TAX_IND.

*****销售数据****************************************************
    IF  -VKORG IS NOT INITIAL
        AND -VTWEG IS NOT INITIAL
        AND -SPART IS NOT INITIAL.
      LS_SALES-TASK 'M'.
      LS_SALES-DATA_KEY-VKORG -VKORG.    "销售组织
      LS_SALES-DATA_KEY-VTWEG -VTWEG.    "分销渠道
      LS_SALES-DATA_KEY-SPART -SPART.    "产品组
*      LS_SALES-DATA-WAERS = -WAERS.        "货币
*      LS_SALES-DATA-KALKS = -KALKS.        "用于确定定价过程的客户分类
      LS_SALES-DATA-VSBED -VSBED.        "装运条件
      LS_SALES-DATA-KDGRP -KDGRP.        "客户组
      LS_SALES-DATA-KONDA -KONDA.        "客户价格组
      LS_SALES-DATA-KTGRD -KTGRD.        "此客户的账户分配组
      LS_SALES-DATA-EIKTO -EIKTO.        "客户处我方账户(送货区域/路线)
      LS_SALES-DATA-ZTERM -ZTERM_KNVV.   "付款条件(账期)
*      LS_SALES-DATA-AUFSD = '01'.                   "客户订单冻结(销售范围)

      LS_SALES-DATAX-VSBED ABAP_TRUE.
      LS_SALES-DATAX-KDGRP ABAP_TRUE.
      LS_SALES-DATAX-KONDA ABAP_TRUE.
      LS_SALES-DATAX-KTGRD ABAP_TRUE.
      LS_SALES-DATAX-EIKTO ABAP_TRUE.
      LS_SALES-DATAX-ZTERM ABAP_TRUE.
*      LS_SALES-DATAX-AUFSD = ABAP_TRUE.


      IF -VTWEG '20'.
        LS_SALES-DATA-WAERS 'USD'.        "货币
        LS_SALES-DATA-KALKS '1'.        "用于确定定价过程的客户分类
      ELSE.
        LS_SALES-DATA-WAERS 'CNY'.        "货币
        LS_SALES-DATA-KALKS '2'.        "用于确定定价过程的客户分类
      ENDIF.
      LS_SALES-DATAX-WAERS ABAP_TRUE.
      LS_SALES-DATAX-KALKS ABAP_TRUE.

*          Function伙伴功能
      LS_FUNCTIONS-TASK 'M'.
      IF -ZUDID 'C'.
*          LS_FUNCTIONS-DATA_KEY-PARVW = 'Z1'.
*          LS_FUNCTIONS-DATA-PARTNER = -LIFNR_YW.   "业务员编码
        CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
          EXPORTING
            INPUT  'SP' "收票方
          IMPORTING
            OUTPUT LS_FUNCTIONS-DATA_KEY-PARVW.
        APPEND LS_FUNCTIONS TO LT_FUNCTIONS.

        CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
          EXPORTING
            INPUT  'BP' "收票方
          IMPORTING
            OUTPUT LS_FUNCTIONS-DATA_KEY-PARVW.
        APPEND LS_FUNCTIONS TO LT_FUNCTIONS.

        CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
          EXPORTING
            INPUT  'PY' "收票方
          IMPORTING
            OUTPUT LS_FUNCTIONS-DATA_KEY-PARVW.
        APPEND LS_FUNCTIONS TO LT_FUNCTIONS.

        CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
          EXPORTING
            INPUT  'SH' "收票方
          IMPORTING
            OUTPUT LS_FUNCTIONS-DATA_KEY-PARVW.
        APPEND LS_FUNCTIONS TO LT_FUNCTIONS.
      ELSE.
*          LS_FUNCTIONS-DATA_KEY-PARVW = 'Z2'.
*          LS_FUNCTIONS-DATA-PARTNER = -LIFNR_YG.   "销售内勤编码(营管员编码)
      ENDIF.

*        APPEND LS_FUNCTIONS TO LT_FUNCTIONS.
      LS_SALES-FUNCTIONS-FUNCTIONS LT_FUNCTIONS.

      APPEND LS_SALES TO LT_SALES.
      LS_SALES_DATA-SALES LT_SALES.
      LS_CUSTOMER-SALES_DATA LS_SALES_DATA.
    ENDIF.

    LS_DATA-PARTNER LS_PARTNER.
    LS_DATA-CUSTOMER LS_CUSTOMER.
    APPEND LS_DATA TO LT_DATA.


    CALL FUNCTION 'CVI_EI_INBOUND_MAIN'
      EXPORTING
        I_DATA   LT_DATA
      
IMPORTING
        E_RETURN LT_RETURN.

    CLEARPV_CODEPV_MSG.
    LOOP AT LT_RETURN INTO LS_RETURN.
      LOOP AT LS_RETURN-OBJECT_MSG INTO DATA(LS_OBJECT_MSGWHERE TYPE CA 'EA'.
        IF PV_MSG IS INITIAL.
          PV_MSG LS_OBJECT_MSG-MESSAGE.
        ELSE.
          CONCATENATE PV_MSG '/' LS_OBJECT_MSG-MESSAGE INTO PV_MSG.
        ENDIF.
      ENDLOOP.
      IF SY-SUBRC 0.
        "回滚BAPI

        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'"回滚BAPI

        PV_CODE 'E'.
        EXIT.
      ENDIF.
    ENDLOOP.

    IF PV_CODE <> 'E' .
      "提交BAPI

      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          WAIT 'X'.
*    IMPORTING
*     RETURN        =

      PV_CODE 'S'.
      CONCATENATE '客户编号为-KUNNR '的客户主数据创建成功INTO PV_MSG.

    ENDIF.

    LS_OUTPUT-Z003 -Z003.   "OA 号码
    LS_OUTPUT-PARTNER -KUNNR.  "业务伙伴编码
    LS_OUTPUT-RTYPE PV_CODE.        "消息类型
    LS_OUTPUT-RTMSG PV_MSG.         "消息文本
    APPEND LS_OUTPUT TO PT_OUTPUT.

    LS_RECORD-ZZOANUM -Z003.   "OA 号码
    LS_RECORD-KUNNR -KUNNR.    "业务伙伴编码
    LS_RECORD-ZZNAME1 -ANRED.  "客户名称
    LS_RECORD-BUKRS -BUKRS.    "公司代码
    LS_RECORD-ZZDATE SY-DATUM.          "SAP接收日期
    LS_RECORD-ZZTIME SY-UZEIT.          "SAP接收时间
    LS_RECORD-ZZRES PV_CODE.            "导入状态
    LS_RECORD-ZZEMES PV_MSG.            "报错信息
    MODIFY ZTSD0041 FROM LS_RECORD.

  ENDLOOP.
ENDFORM.

4.公司代码视图和销售视图的修改

*----------------------------------------------------------------------*
***INCLUDE LZSDI001F05.  PROGRAMMED BY HANDYY 20181108
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  FRM_CUSTOMER_CHANGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_T_IN  text
*      -->P_T_OUTPUT  text
*      -->P_I_RLTGR  text
*      -->P_I_BU_GROUP  text
*      <--P_E_CODE  text
*      <--P_E_MSG  text
*----------------------------------------------------------------------*
FORM FRM_CUSTOMER_CHANGE  TABLES PT_IN STRUCTURE ZSSD0040
                                 PT_OUTPUT 
STRUCTURE ZSSD0041
                          
USING   PV_RLTGR
                                  PV_BU_GROUP
                          
CHANGING PV_CODE
                                   PV_MSG
.
  TYPES:BEGIN OF TY_KNA1,
          NAME1 TYPE KNA1-NAME1,
          KUNNR TYPE KNA1-KUNNR,
        END OF TY_KNA1.

  DATALT_KNA1  TYPE STANDARD TABLE OF TY_KNA1,
        LT_KUNNR TYPE STANDARD TABLE OF TY_KNA1,
        LS_KUNNR TYPE TY_KNA1.

  DATALS_OUTPUT TYPE ZSSD0041,
        LT_RECORD TYPE STANDARD TABLE OF ZTSD0041"同步日志到自建表
        LS_RECORD TYPE ZTSD0041.

  DATA LT_PARTNERGUID_LIST TYPE BU_PARTNER_GUID_T,
         LS_PARTNERGUID_LIST LIKE LINE OF LT_PARTNERGUID_LIST.
  DATA LT_CUSTOMER_LIST TYPE CVIS_CUST_LINK_T,
         LS_CUSTOMER_LIST TYPE CVI_CUST_LINK.

  DATA LS_DATA   TYPE  CVIS_EI_EXTERN,
         LT_DATA   TYPE  CVIS_EI_EXTERN_T,
         LT_RETURN TYPE  BAPIRETM,
         LS_RETURN TYPE  BAPIRETI,
         LS_MSG    TYPE  BAPIRETC.

  DATA LS_PARTNER  TYPE BUS_EI_EXTERN,
         LS_CUSTOMER TYPE CMDS_EI_EXTERN.


  DATA LS_HEADER       TYPE CMDS_EI_HEADER,
         LS_CENTRAL_DATA TYPE CMDS_EI_CENTRAL_DATA,
         LS_COMPANY_DATA TYPE CMDS_EI_CMD_COMPANY,
         LS_SALES_DATA   TYPE CMDS_EI_CMD_SALES.

  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,
         LS_REMARKS       TYPE BUS_EI_BUPA_COMREM,
         LT_REMARKS       TYPE BUS_EI_BUPA_COMREM_T,
         LT_COMPANY       TYPE CMDS_EI_COMPANY_T,
         LS_COMPANY       TYPE CMDS_EI_COMPANY,
         LT_SALES         TYPE CMDS_EI_SALES_T,
         LS_SALES         TYPE CMDS_EI_SALES,
         LT_FUNCTIONS     TYPE CMDS_EI_FUNCTIONS_T,
         LS_FUNCTIONS     TYPE CMDS_EI_FUNCTIONS,
         LS_CENTRAL       TYPE CMDS_EI_CMD_CENTRAL,
         LT_TAX_IND       TYPE CMDS_EI_TAX_IND_T,
         LS_TAX_IND       TYPE CMDS_EI_TAX_IND.

  FIELD-SYMBOLS TYPE ZSSD0040.

  DATA LV_BPARTNERGUID TYPE BU_PARTNER_GUID_BAPI.


  LOOP AT PT_IN ASSIGNING .

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        INPUT  -KUNNR
      
IMPORTING
        OUTPUT -KUNNR.

    SELECT
      KUNNR
  
INTO TABLE LT_KNA1
  
FROM KNA1
  
WHERE KUNNR -KUNNR.

    IF SY-SUBRC 0.

      SELECT SINGLE
        B~PARTNER,
        A~PARTNER_GUID
        
INTO @DATA(LS_BUT000)
        FROM CVI_CUST_LINK AS A INNER JOIN BUT000 AS B
                          
ON A~PARTNER_GUID B~PARTNER_GUID
        
WHERE CUSTOMER @-KUNNR.

      LS_PARTNER-HEADER-OBJECT_TASK 'M'.         "I插入 U更新 M修改 D删除 C当前状态
      LS_PARTNER-HEADER-OBJECT_INSTANCE-BPARTNER LS_BUT000-PARTNER.              "业务伙伴编号
      LS_PARTNER-HEADER-OBJECT_INSTANCE-BPARTNERGUID LS_BUT000-PARTNER_GUID.          "唯一标识
      LS_PARTNER-CENTRAL_DATA-COMMON-DATA-BP_CONTROL-CATEGORY 2.               "业务伙伴类别
      LS_PARTNER-CENTRAL_DATA-COMMON-DATA-BP_CONTROL-GROUPING PV_BU_GROUP.    "业务伙伴分组

      LS_PARTNER-CENTRAL_DATA-COMMON-DATA-BP_ORGANIZATION-NAME1 -NAME1名称1
      LS_PARTNER-CENTRAL_DATA-COMMON-DATA-BP_ORGANIZATION-NAME2 -NAME2名称2
      LS_PARTNER-CENTRAL_DATA-COMMON-DATA-BP_ORGANIZATION-NAME3 -NAME3名称3
      LS_PARTNER-CENTRAL_DATA-COMMON-DATA-BP_ORGANIZATION-NAME4 -NAME4名称4
      LS_PARTNER-CENTRAL_DATA-COMMON-DATA-BP_CENTRALDATA-SEARCHTERM1 -SORTL.  搜索项
      LS_PARTNER-CENTRAL_DATA-COMMON-DATA-BP_CENTRALDATA-TITLE_KEY =  -ANRED称谓

      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-TITLE_KEY ABAP_TRUE.


      CLEAR:LS_ADDRESSES,LT_ADDRESSES.
      LS_ADDRESSES-TASK 'M'.                "I插入 U更新 M修改 D删除 C当前状态

      SELECT SINGLE
        ADDRESS_GUID
        
INTO @DATA(LV_PARTNER_GUID)
        FROM BUT020
        
WHERE PARTNER @-KUNNR.
      IF SY-SUBRC 0.
        LS_ADDRESSES-DATA_KEY-GUID LV_PARTNER_GUID.
      ENDIF.
      LS_ADDRESSES-DATA-POSTAL-DATA-PO_CTRYISO -LAND1.   国家代码
      LS_ADDRESSES-DATA-POSTAL-DATA-CITY -ORT01.         "城市
      LS_ADDRESSES-DATA-POSTAL-DATA-REGION |{ -REGIO ALPHA IN }|.       地区代码
      LS_ADDRESSES-DATA-POSTAL-DATA-C_O_NAME -NAME1_LXR联系人姓名
*      LS_ADDRESSES-DATA-POSTAL-DATA-POSTL_COD1 = -LIFNR.     "邮政编码
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
        EXPORTING
          INPUT  -LIFNR
        
IMPORTING
          OUTPUT LS_ADDRESSES-DATA-POSTAL-DATA-POSTL_COD1.

      LS_ADDRESSES-DATA-POSTAL-DATA-STREET -STRAS.       街道
      LS_ADDRESSES-DATA-POSTAL-DATA-STR_SUPPL1 -STR_SUPPL1街道2
      LS_ADDRESSES-DATA-POSTAL-DATA-STR_SUPPL2 -STR_SUPPL2街道3
      LS_ADDRESSES-DATA-POSTAL-DATA-STR_SUPPL3 -STR_SUPPL3街道4
      LS_ADDRESSES-DATA-POSTAL-DATA-LANGU -SPRAS.           "语言

      LS_ADDRESSES-DATA-POSTAL-DATAX-PO_CTRYISO ABAP_TRUE国家代码
      LS_ADDRESSES-DATA-POSTAL-DATAX-CITY ABAP_TRUE.       "城市
      LS_ADDRESSES-DATA-POSTAL-DATAX-REGION ABAP_TRUE.     地区代码
      LS_ADDRESSES-DATA-POSTAL-DATAX-C_O_NAME ABAP_TRUE.   代收人
      LS_ADDRESSES-DATA-POSTAL-DATAX-POSTL_COD1 ABAP_TRUE.  "邮政编码
      LS_ADDRESSES-DATA-POSTAL-DATAX-STREET ABAP_TRUE.           街道
      LS_ADDRESSES-DATA-POSTAL-DATAX-STR_SUPPL1 ABAP_TRUE.     街道2
      LS_ADDRESSES-DATA-POSTAL-DATAX-STR_SUPPL2 ABAP_TRUE.     街道3
      LS_ADDRESSES-DATA-POSTAL-DATAX-STR_SUPPL3 ABAP_TRUE.     街道4
      LS_ADDRESSES-DATA-POSTAL-DATAX-LANGU ABAP_TRUE.         "语言

      CLEAR:LS_PHONE,LT_PHONE.
      LS_PHONE-CONTACT-TASK 'U'.  "I插入 U更新 M修改 D删除 C当前状态
      LS_PHONE-CONTACT-DATA-TELEPHONE -TELF1.  "电话
      LS_PHONE-CONTACT-DATAX-TELEPHONE ABAP_TRUE.
      APPEND LS_PHONE TO LT_PHONE.
      CLEAR:LS_PHONE.
      LS_PHONE-CONTACT-TASK 'U'.  "I插入 U更新 M修改 D删除 C当前状态
      LS_PHONE-CONTACT-DATA-TELEPHONE -TELF2"手机
      LS_PHONE-CONTACT-DATA-R_3_USER '3'.    "3表示移动电话
      LS_PHONE-CONTACT-DATAX-TELEPHONE ABAP_TRUE.
      LS_PHONE-CONTACT-DATAX-R_3_USER ABAP_TRUE.
      APPEND LS_PHONE TO LT_PHONE.
      LS_ADDRESSES-DATA-COMMUNICATION-PHONE-PHONE LT_PHONE.

      CLEAR:LS_FAX,LT_FAX.
      LS_FAX-CONTACT-TASK 'U'.   "I插入 U更新 M修改 D删除 C当前状态
      LS_FAX-CONTACT-DATA-FAX -TELFX.  "传真号
      LS_FAX-CONTACT-DATAX-FAX ABAP_TRUE.
      APPEND LS_FAX TO LT_FAX.
      LS_ADDRESSES-DATA-COMMUNICATION-FAX-FAX LT_FAX.

      CLEAR:LS_SMTP,LT_SMTP.
      LS_SMTP-CONTACT-TASK 'U'.   "I插入 U更新 M修改 D删除 C当前状态
      LS_SMTP-CONTACT-DATA-E_MAIL -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.
      LS_PARTNER-CENTRAL_DATA-ADDRESS-ADDRESSES LT_ADDRESSES.


*******客户抬头数据***********************************************************
      LS_HEADER-OBJECT_TASK 'U'.
      LS_HEADER-OBJECT_INSTANCE-KUNNR -KUNNR"客户编号

      LS_CUSTOMER-HEADER =  LS_HEADER.

****中心客户数据*************************************************
      LS_CENTRAL-DATA-NIELS -NIELS.     "Nielsen 标识
*      LS_CENTRAL-DATA-BRSCH = -BRSCH.     "行业代码
      LS_CENTRAL-DATA-KUKLA -KUKLA.     "客户分类
      LS_CENTRAL-DATA-BRAN1 -BRAN1.     "行业代码1
*      LS_CENTRAL-DATA-LIFNR = -LIFNR.     "供应商或债权人的帐号
      LS_CENTRAL-DATA-KONZS -KONZS.     "组代码
*      LS_CENTRAL-DATA-STCEG = -STCEG.     "增值税登记号
*      LS_CENTRAL-DATA-KTOKD = -KTOKD.     "客户账户组

      LS_CENTRAL-DATAX-NIELS ABAP_TRUE.
*      LS_CENTRAL-DATAX-BRSCH = ABAP_TRUE.
      LS_CENTRAL-DATAX-KUKLA ABAP_TRUE.
      LS_CENTRAL-DATAX-BRAN1 ABAP_TRUE.
*      LS_CENTRAL-DATAX-LIFNR = ABAP_TRUE.
      LS_CENTRAL-DATAX-KONZS ABAP_TRUE.
*      LS_CENTRAL-DATAX-STCEG = ABAP_TRUE.

      LS_CUSTOMER-CENTRAL_DATA-CENTRAL LS_CENTRAL.

****公司代码数据************************************************
      IF -BUKRS IS NOT INITIAL.

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'   统驭科目补前导零
          EXPORTING
            INPUT  -AKONT
          
IMPORTING
            OUTPUT -AKONT.

        LS_COMPANY-TASK 'U'.
        LS_COMPANY-DATA_KEY-BUKRS -BUKRS公司代码

        LS_COMPANY-DATA-AKONT -AKONT.      统驭科目
        LS_COMPANY-DATA-ZTERM -ZTERM_KNB1付款条款
        LS_COMPANY-DATA-EIKTO -EIKTO_D.   "客户处我方账户(对账日期)
        LS_COMPANY-DATA-KVERM -KVERM.     "备注(收票截止日期)

        LS_COMPANY-DATAX-AKONT ABAP_TRUE.
        LS_COMPANY-DATAX-ZTERM ABAP_TRUE.
        LS_COMPANY-DATAX-EIKTO ABAP_TRUE.
        LS_COMPANY-DATAX-KVERM ABAP_TRUE.

        APPEND LS_COMPANY TO LT_COMPANY.
        LS_COMPANY_DATA-COMPANY LT_COMPANY.
        LS_CUSTOMER-COMPANY_DATA LS_COMPANY_DATA.
      ENDIF.



*********税收标识********************************************************
      LS_TAX_IND-TASK 'U'.
      LS_TAX_IND-DATA_KEY-ALAND 'CN'.
      LS_TAX_IND-DATA_KEY-TATYP 'MWST'.
      IF -VTWEG '20'.
        LS_TAX_IND-DATA-TAXKD '0'.  "客户税分类
      ELSE.
        LS_TAX_IND-DATA-TAXKD '1'.  "客户税分类
      ENDIF.
*      LS_TAX_IND-DATA-TAXKD = -TAXKD.  "客户税分类
      LS_TAX_IND-DATAX-TAXKD ABAP_TRUE.
      APPEND LS_TAX_IND TO LT_TAX_IND.
      LS_CUSTOMER-CENTRAL_DATA-TAX_IND-TAX_IND LT_TAX_IND.
*****销售数据****************************************************
*    IF -KTOKD <> 'ZS03' AND -KTOKD <> 'ZS07' AND -KTOKD <> 'ZS08'  .
      IF  -VKORG IS NOT INITIAL
          AND -VTWEG IS NOT INITIAL
          AND -SPART IS NOT INITIAL.
        LS_SALES-TASK 'U'.
        LS_SALES-DATA_KEY-VKORG -VKORG.    "销售组织
        LS_SALES-DATA_KEY-VTWEG -VTWEG.    "分销渠道
        LS_SALES-DATA_KEY-SPART -SPART.    "产品组

        IF -VTWEG '20'.
          LS_SALES-DATA-WAERS 'USD'.        "货币
          LS_SALES-DATA-KALKS '1'.        "用于确定定价过程的客户分类
        ELSE.
          LS_SALES-DATA-WAERS 'CNY'.        "货币
          LS_SALES-DATA-KALKS '2'.        "用于确定定价过程的客户分类
        ENDIF.

*        LS_SALES-DATA-WAERS = -WAERS.        "货币
*        LS_SALES-DATA-KALKS = -KALKS.        "用于确定定价过程的客户分类
        LS_SALES-DATA-VSBED -VSBED.        "装运条件
        LS_SALES-DATA-KDGRP -KDGRP.        "客户组
        LS_SALES-DATA-KONDA -KONDA.        "客户价格组
        LS_SALES-DATA-KTGRD -KTGRD.        "此客户的账户分配组
        LS_SALES-DATA-EIKTO -EIKTO.        "客户处我方账户(送货区域/路线)
        LS_SALES-DATA-ZTERM -ZTERM_KNVV.   "付款条件(账期)

*        LS_SALES-DATAX-WAERS = ABAP_TRUE.
*        LS_SALES-DATAX-KALKS = ABAP_TRUE.
        LS_SALES-DATAX-VSBED ABAP_TRUE.
*        LS_SALES-DATAX-PODKZ = ABAP_TRUE.
*        LS_SALES-DATAX-INCO1 = ABAP_TRUE.
*        LS_SALES-DATAX-INCO2 = ABAP_TRUE.
*        LS_SALES-DATAX-ZTERM = ABAP_TRUE.
        LS_SALES-DATAX-KDGRP ABAP_TRUE.
        LS_SALES-DATAX-KONDA ABAP_TRUE.
        LS_SALES-DATAX-KTGRD ABAP_TRUE.
        LS_SALES-DATAX-EIKTO ABAP_TRUE.
        LS_SALES-DATAX-ZTERM ABAP_TRUE.

        "Function伙伴功能
        LS_FUNCTIONS-TASK 'U'.
        IF -ZUDID 'B'.
*          LS_FUNCTIONS-DATA_KEY-PARVW = 'Z1'.
*          LS_FUNCTIONS-DATA-PARTNER = -LIFNR_YW.   "业务员编码
          CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
            EXPORTING
              INPUT  'SP' "收票方
            IMPORTING
              OUTPUT LS_FUNCTIONS-DATA_KEY-PARVW.
          APPEND LS_FUNCTIONS TO LT_FUNCTIONS.

          CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
            EXPORTING
              INPUT  'BP' "收票方
            IMPORTING
              OUTPUT LS_FUNCTIONS-DATA_KEY-PARVW.
          APPEND LS_FUNCTIONS TO LT_FUNCTIONS.

          CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
            EXPORTING
              INPUT  'PY' "收票方
            IMPORTING
              OUTPUT LS_FUNCTIONS-DATA_KEY-PARVW.
          APPEND LS_FUNCTIONS TO LT_FUNCTIONS.

          CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
            EXPORTING
              INPUT  'SH' "收票方
            IMPORTING
              OUTPUT LS_FUNCTIONS-DATA_KEY-PARVW.
          APPEND LS_FUNCTIONS TO LT_FUNCTIONS.
        ELSE.
*          LS_FUNCTIONS-DATA_KEY-PARVW = 'Z2'.
*          LS_FUNCTIONS-DATA-PARTNER = -LIFNR_YG.   "销售内勤编码(营管员编码)
        ENDIF.

*        APPEND LS_FUNCTIONS TO LT_FUNCTIONS.
        LS_SALES-FUNCTIONS-FUNCTIONS LT_FUNCTIONS.

        APPEND LS_SALES TO LT_SALES.
*增加1210 s
        LS_SALES-TASK 'U'.
        LS_SALES-DATA_KEY-VKORG '1210'.    "销售组织
        LS_SALES-DATA_KEY-VTWEG -VTWEG.    "分销渠道
        LS_SALES-DATA_KEY-SPART -SPART.    "产品组

        IF -VTWEG '20'.
          LS_SALES-DATA-WAERS 'USD'.        "货币
          LS_SALES-DATA-KALKS '1'.        "用于确定定价过程的客户分类
        ELSE.
          LS_SALES-DATA-WAERS 'CNY'.        "货币
          LS_SALES-DATA-KALKS '2'.        "用于确定定价过程的客户分类
        ENDIF.

*          LS_SALES-DATA-KALKS = -KALKS.        "用于确定定价过程的客户分类
        LS_SALES-DATA-VSBED -VSBED.        "装运条件
        LS_SALES-DATA-KDGRP -KDGRP.        "客户组
        LS_SALES-DATA-KONDA -KONDA.        "客户价格组
        LS_SALES-DATA-KTGRD -KTGRD.        "此客户的账户分配组
        LS_SALES-DATA-EIKTO -EIKTO.        "客户处我方账户(送货区域/路线)
        LS_SALES-DATA-ZTERM -ZTERM_KNVV.   "付款条件(账期)

*          LS_SALES-DATAX-WAERS = ABAP_TRUE.
*          LS_SALES-DATAX-KALKS = ABAP_TRUE.
        LS_SALES-DATAX-VSBED ABAP_TRUE.
*          LS_SALES-DATAX-PODKZ = ABAP_TRUE.
*          LS_SALES-DATAX-INCO1 = ABAP_TRUE.
*          LS_SALES-DATAX-INCO2 = ABAP_TRUE.
        LS_SALES-DATAX-KDGRP ABAP_TRUE.
        LS_SALES-DATAX-KONDA ABAP_TRUE.
        LS_SALES-DATAX-KTGRD ABAP_TRUE.
        LS_SALES-DATAX-EIKTO ABAP_TRUE.
        LS_SALES-DATAX-ZTERM ABAP_TRUE.

        APPEND LS_SALES TO LT_SALES.
*增加1210 e
        LS_SALES_DATA-SALES LT_SALES.
        LS_CUSTOMER-SALES_DATA LS_SALES_DATA.
      ENDIF.

      LS_DATA-PARTNER LS_PARTNER.
      LS_DATA-CUSTOMER LS_CUSTOMER.
      APPEND LS_DATA TO LT_DATA.


      CALL FUNCTION 'CVI_EI_INBOUND_MAIN'
        EXPORTING
          I_DATA   LT_DATA
        
IMPORTING
          E_RETURN LT_RETURN.


      CLEARPV_CODEPV_MSG.
      LOOP AT LT_RETURN INTO LS_RETURN.
        LOOP AT LS_RETURN-OBJECT_MSG INTO DATA(LS_OBJECT_MSGWHERE TYPE CA 'EA'.
          IF PV_MSG IS INITIAL.
            PV_MSG LS_OBJECT_MSG-MESSAGE.
          ELSE.
            CONCATENATE PV_MSG '/' LS_OBJECT_MSG-MESSAGE INTO PV_MSG.
          ENDIF.
        ENDLOOP.
        IF SY-SUBRC 0.
          "回滚BAPI

          CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'"回滚BAPI

          PV_CODE 'E'.
          EXIT.
        ENDIF.
      ENDLOOP.

      IF PV_CODE <> 'E' .
        "提交BAPI

        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            WAIT 'X'.
*    IMPORTING
*     RETURN        =


        PV_CODE 'S'.
        CONCATENATE '客户编号为-KUNNR '的客户主数据修改成功INTO PV_MSG.


      ENDIF.


      LS_OUTPUT-Z003 -Z003.   "OA 号码
      LS_OUTPUT-PARTNER LS_KUNNR-KUNNR.  "业务伙伴编码
      LS_OUTPUT-RTYPE PV_CODE.        "消息类型
      LS_OUTPUT-RTMSG PV_MSG.         "消息文本
      APPEND LS_OUTPUT TO PT_OUTPUT.

      LS_RECORD-ZZOANUM -Z003.   "OA 号码
      LS_RECORD-KUNNR LS_KUNNR-KUNNR.    "业务伙伴编码
      LS_RECORD-ZZNAME1 -ANRED.  "客户名称
      LS_RECORD-BUKRS -BUKRS.    "公司代码
      LS_RECORD-ZZDATE SY-DATUM.          "SAP接收日期
      LS_RECORD-ZZTIME SY-UZEIT.          "SAP接收时间
      LS_RECORD-ZZRES PV_CODE.            "导入状态
      LS_RECORD-ZZEMES PV_MSG.            "报错信息
      MODIFY ZTSD0041 FROM  LS_RECORD.


    ELSE.
      PV_CODE 'E'.
      PV_MSG '此公司客户主数据不存在,无法修改'.
    ENDIF.
  ENDLOOP.
ENDFORM.

 

你可能感兴趣的:(ABAP,BAPI)