• 批量创建客户主数据函数SD_CUSTOMER_MAINTAIN_ALL


    分享一下批创建客户主数据函数:SD_CUSTOMER_MAINTAIN_ALL

      TABLES:T077D,ZCITY,T005S,BNKA,ADRC,KNA1.
      DATA: TMP_KTOKD(4) TYPE N,
            TMP_REGIO(3)  TYPE N.
      DATA: CURLINE LIKE SY-TABIX.

    **定义调用bapiSD_CUSTOMER_MAINTAIN_ALL创建的输入参数
      DATA:I_KNA1 TYPE KNA1,
           I_KNB1 TYPE KNB1,
           I_BAPIADDR1 TYPE BAPIADDR1,
           T_XKNBK LIKE FKNBK OCCURS 0 WITH HEADER LINE,
           T_YKNBK LIKE FKNBK OCCURS 0 WITH HEADER LINE,
           T_XKNVA LIKE FKNVA OCCURS 0 WITH HEADER LINE,
           T_XKNVK LIKE FKNVK OCCURS 0 WITH HEADER LINE,
           E_KUNNR LIKE KNA1-KUNNR,
           O_KNA1 LIKE KNA1,
           E_SD_CUST_1321_DONE TYPE C.

      LOOP AT T_CUSTOMER.
    **--客户主文件的一般数据
          I_KNA1-KUNNR = T_CUSTOMER-KUNNR.          "0003 0004 0009 人工授码
          I_KNA1-KTOKD = T_CUSTOMER-KTOKD.          "客户帐户组
          I_KNA1-LIFNR = T_CUSTOMER-LIFNR.          "供应商或债权人的帐号
          I_KNA1-VBUND = T_CUSTOMER-VBUND.          "贸易伙伴
          I_KNA1-STCEG = T_CUSTOMER-STCEG.          "纳税登记号
          I_KNA1-RPMKR = T_CUSTOMER-RPMKR.          "地区市场
          IF T_CUSTOMER-KTOKD = '0002'.             "国外客户
             I_KNA1-CIVVE = 'X'.
          ENDIF.
    **--地址数据
          I_BAPIADDR1-TITLE = T_CUSTOMER-TITLE.     "标题文本
          I_BAPIADDR1-NAME = T_CUSTOMER-NAME.       "名称 1
          I_BAPIADDR1-NAME_2 = T_CUSTOMER-NAME_2.   "名称 2
          I_BAPIADDR1-SORT1 = T_CUSTOMER-SORT1.     "排序字段
          I_BAPIADDR1-STR_SUPPL1 = T_CUSTOMER-STR_SUPPL1.    "街道2
          I_BAPIADDR1-STREET = T_CUSTOMER-STREET.   "街道名
          I_BAPIADDR1-CITY = T_CUSTOMER-CITY.       "城市
          I_BAPIADDR1-COUNTRY = T_CUSTOMER-COUNTRY. "国家代码
          I_BAPIADDR1-REGION = T_CUSTOMER-REGION.   "地区 (州、省、县)
          I_BAPIADDR1-LANGU = T_CUSTOMER-LANGU.     "语言代码
    **--客户主数据 (银行细目)
          T_XKNBK-KUNNR = T_CUSTOMER-KUNNR.         "自动授码0001 0002为空 人工先授码0003 0004 0009不为空
          T_XKNBK-BANKS = T_CUSTOMER-BANKS.         "银行国家代码
          T_XKNBK-BANKL = T_CUSTOMER-BANKL.         "银行码
          T_XKNBK-BANKN = T_CUSTOMER-BANKN.         "帐号
          T_XKNBK-KOINH = T_CUSTOMER-KOINH.         "帐户持有人姓名
          APPEND T_XKNBK.
    **--客户主装货点
          T_XKNVA-KUNNR = T_CUSTOMER-KUNNR.        "自动授码0001 0002为空 人工先授码0003 0004 0009不为空
          T_XKNVA-ABLAD = T_CUSTOMER-ABLAD.        "卸货点
          T_XKNVA-KNFAK = T_CUSTOMER-KNFAK.        "客户的工厂日历
          APPEND T_XKNVA.
    **--客户主要联系伙伴
          T_XKNVK-NAME1 = T_CUSTOMER-NAME1.         "联系人名称
          T_XKNVK-NAMEV = T_CUSTOMER-NAMEV.         "电话
          APPEND T_XKNVK.

          CALL FUNCTION 'SD_CUSTOMER_MAINTAIN_ALL'
           EXPORTING
             I_KNA1                              = I_KNA1
    *        I_KNB1                              =
             I_BAPIADDR1                         = I_BAPIADDR1
             I_MAINTAIN_ADDRESS_BY_KNA1          = 'X'
             PI_POSTFLAG                         = 'X'
             I_FROM_CUSTOMERMASTER               = ' '
           IMPORTING
             E_KUNNR                             = E_KUNNR
             O_KNA1                              = O_KNA1
           TABLES
             T_XKNBK                             = T_XKNBK
             T_XKNVA                             = T_XKNVA
             T_XKNVK                             = T_XKNVK
           EXCEPTIONS
             CLIENT_ERROR                        = 1
             KNA1_INCOMPLETE                     = 2
             KNB1_INCOMPLETE                     = 3
             KNB5_INCOMPLETE                     = 4
             KNVV_INCOMPLETE                     = 5
             KUNNR_NOT_UNIQUE                    = 6
             SALES_AREA_NOT_UNIQUE               = 7
             SALES_AREA_NOT_VALID                = 8
             INSERT_UPDATE_CONFLICT              = 9
             NUMBER_ASSIGNMENT_ERROR             = 10
             NUMBER_NOT_IN_RANGE                 = 11
             NUMBER_RANGE_NOT_EXTERN             = 12
             NUMBER_RANGE_NOT_INTERN             = 13
             ACCOUNT_GROUP_NOT_VALID             = 14
             PARNR_INVALID                       = 15
             BANK_ADDRESS_INVALID                = 16
             TAX_DATA_NOT_VALID                  = 17
             NO_AUTHORITY                        = 18
             COMPANY_CODE_NOT_UNIQUE             = 19
             DUNNING_DATA_NOT_VALID              = 20
             KNB1_REFERENCE_INVALID              = 21
             CAM_ERROR                           = 22
             OTHERS                              = 23
                    .
    *      当前处理出现异常,回滚操作
                IF SY-SUBRC NE 0.
                   CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

                   SELECT SINGLE TEXT FROM T100 INTO T_RETURN-MESSAGE
                                 WHERE SPRSL = '1'
                                   AND ARBGB = SY-MSGID
                                   AND MSGNR = SY-MSGNO.
                    DO 4 TIMES.
                       SEARCH T_RETURN-MESSAGE FOR '&'.
                       IF SY-SUBRC = 0.
                         CASE SY-INDEX.
                             WHEN 1.
                               REPLACE  '&' WITH SY-MSGV1 INTO T_RETURN-MESSAGE.
                             WHEN 2.
                               REPLACE  '&' WITH SY-MSGV2 INTO T_RETURN-MESSAGE.
                             WHEN 3.
                               REPLACE  '&' WITH SY-MSGV3 INTO T_RETURN-MESSAGE.
                             WHEN 4.
                               REPLACE  '&' WITH SY-MSGV4 INTO T_RETURN-MESSAGE.
                         ENDCASE.
                         CONDENSE T_RETURN-MESSAGE. "replace会将SY-MSGV&50位替换,压缩空格 ERR_TAB-MESSAGE也要足够长
                       ENDIF.
                    ENDDO.
                    T_RETURN-INDEX = CURLINE.
                    T_RETURN-TYPE = 'E'.
                    IF T_RETURN-MESSAGE IS INITIAL.
                       T_RETURN-MESSAGE = '客户创建未成功'.
                    ENDIF.
                    APPEND T_RETURN.
                    CLEAR T_RETURN.
                ELSE.
                   CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
                    EXPORTING
                      WAIT          = 'X'.
                   IF SY-SUBRC = 0.
                      T_RETURN-TYPE = 'S'.
                      T_RETURN-MESSAGE = O_KNA1-KUNNR."'客户创建成功'.
                    ELSE.
                      T_RETURN-TYPE = 'E'.
                      T_RETURN-MESSAGE = '客户创建未成功'.
                    ENDIF.
                    T_RETURN-INDEX = CURLINE.
                    APPEND T_RETURN.
                    CLEAR T_RETURN.

               ENDIF.
            CLEAR:T_CUSTOMER,T_RETURN,
                  I_KNA1,I_BAPIADDR1,E_KUNNR,O_KNA1,
                  T_XKNBK[],T_XKNVA[],T_XKNVK[].
      ENDLOOP.

     
     
  • 相关阅读:
    iOS中循环引用的解除
    Block的循环引用详解
    Mac OS X下面 Node.js环境的搭建
    swift中闭包和OC的block的对比
    STL priority_queue
    优先使用map(或者unordered_map)的find函数而非algorithm里的find函数
    Insert Interval
    Integer Break
    Unique Binary Search Trees
    腾讯2016实习生笔试
  • 原文地址:https://www.cnblogs.com/zfswff/p/5691966.html
Copyright © 2020-2023  润新知