SD_CUSTOMER_MAINTAIN_ALL
本BAPI是维护性BAPI,具有创建,修改等功能,可以用于客户主数据的维护,并且支持客户主数据的批量维护。
当修改客户主数据时比新增的输入参数多设置I_CUSTOMER_IS_CONSUMER =’X’,I_FROM_CUSTOMERMASTER = ‘X’这两个参数。
新增客户主数据时,表参数赋值的是以‘X’开头的表参数,修改客户主数据时,
表参数赋值的是以‘Y’开头的表参数。
状态TASK有U更新、I新增、E删除文档、D删除.
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. "客户号 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.