目录
一、问题描述
利用SAP标准BAPI,对客户的银行信息进行创建或修改。
二、解决方法
(1)创建客户的银行信息 (XD01)
BAPI函数:BAPI_BANK_CREATE
(2)修改客户的银行信息(XD02)
BAPI函数:SD_CUSTOMER_MAINTAIN_ALL
三、代码
(1)创建
DATA: ls_address TYPE bapi1011_address,
ls_addressx TYPE bapi1011_addressx,
ls_return TYPE bapiret2,
l_banks TYPE banks, "银行国家代码
l_bankl TYPE bankl, "银行编号
l_banka TYPE banka. "银行名称
CLEAR: ls_address.
ls_address-bank_name = l_banka. "银行名称
ls_address-bank_no = l_bankl. "银行编号
ls_addressx-bank_name = 'X'.
ls_addressx-bank_no = 'X'.
CALL FUNCTION 'BAPI_BANK_CREATE'
EXPORTING
bank_ctry = l_banks "银行国家代码
bank_key = l_bankl "银行代码
bank_address = ls_address
i_xupdate = 'X'
IMPORTING
return = ls_return.
IF ls_return-type EQ 'E' OR ls_return-type EQ 'A'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
CLEAR ls_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = ls_return.
ENDIF.
(2) 修改
DATA:t_kna1 TYPE kna1,
t_xknbk LIKE fknbk OCCURS 0 WITH HEADER LINE,
t_yknbk LIKE fknbk OCCURS 0 WITH HEADER LINE.
"根据客户编码查看现有的客户信息
SELECT SINGLE * INTO t_kna1
FROM kna1
WHERE kunnr = l_kunnr.
"银行信息赋值
t_xknbk-kunnr = l_kunnr.
t_xknbk-banks = l_banks. "银行国家代码
t_xknbk-bankl = l_bankl. "银行码
t_xknbk-bankn = l_xbankn. "银行帐号
t_xknbk-bkref = l_bkref. "参考
t_xknbk-bkont = l_BKONT. "银行控制代码
t_xknbk-bvtyp = l_BVTYP. "合作伙伴银行类型 CNY
t_xknbk-koinh = gs_in-koinh. "帐户持有人姓名
APPEND t_xknbk.
IF t_xknbk IS NOT INITIAL.
"旧的银行信息
SELECT *
FROM knbk
INTO CORRESPONDING FIELDS OF TABLE t_yknbk
WHERE kunnr = l_kunnr.
ENDIF.
CALL FUNCTION 'SD_CUSTOMER_MAINTAIN_ALL'
EXPORTING
i_kna1 = t_kna1
pi_postflag = 'X'
i_from_customermaster = 'X'
TABLES
t_xknbk = t_xknbk "X表是新银行信息,新增
t_yknbk = t_yknbk "Y表是旧银行信息,删除
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 = 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
四、注意事项
在修改银行信息时,利用函数 SD_CUSTOMER_MAINTAIN_ALL 时,参数t_xknbk和t_yknbk应注意:
1、X表,t_xknbk 放新增的银行信息,进行新增或修改。
Y表,t_yknbk 放原有的银行信息,进行删除。
2、如果Y表是空,会在原来基础上自动插入X表内的银行信息。
3、前台界面路径:XD02/支付交易
五、总结
创建银行信息,采用BAPI函数:BAPI_BANK_CREATE
修改银行信息,采用BAPI函数:SD_CUSTOMER_MAINTAIN_ALL
日期:2024年10月19日