批量更新 应用: 现金管理系统 标题: 银行帐户弹性域
create or replace PROCEDURE ML_UPDATE_BANK_ACCT_INFO(
errbuf OUT VARCHAR2,
retcode OUT VARCHAR2,
ic_user_file IN VARCHAR2 )
AS
TYPE T_BANK_ACCT
IS
RECORD
(
BANK_ACCOUNT_ID NUMBER(15),
-- BANK_ACCOUNT_NAME VARCHAR2(100),
Payment_bank_Code VARCHAR2(30),
BANK_ACCOUNT_NUM VARCHAR2(30),
STATUS VARCHAR2(200) );
TYPE R_BANK_ACCT_LIST
IS
TABLE OF T_BANK_ACCT INDEX BY BINARY_INTEGER;
vc_file_path VARCHAR2(20) :='/home/';
vc_folder VARCHAR2(20) := NULL;
vc_file_location VARCHAR2(100);
vc_file_info VARCHAR2(2000);
vc_file_ref utl_file.file_type;
v_read_file_flag BOOLEAN := TRUE;
v_BANK_ACCT_list R_BANK_ACCT_LIST;
v_counter INTEGER :=0;
v_BANK_ACC_check INTEGER :=0;
v_o_mverp VARCHAR2(20):= NULL;
v_org_id NUMBER := fnd_global.org_id;
--------------------------------------
Vrec_BankAcct ce_bank_pub.BankAcct_rec_type;
v_obj_v_num NUMBER := 1;
Vc_upd_Status VARCHAR2(10);
Vc_Return_Status VARCHAR2(2000);
Vn_Msg_Count NUMBER;
Vl_Msg_Data LONG;
Vn_Message_Int NUMBER;
Vn_Record_Num_bankacc NUMBER:=0 ;
BEGIN
--设置缓冲区不受限制
DBMS_OUTPUT.ENABLE(buffer_size => NULL) ;
/****************read file************************/
--get file object
BEGIN
BEGIN
SELECT attribute4
INTO vc_folder
FROM HR_ORGANIZATION_INFORMATION
WHERE organization_id = v_org_id
AND org_information_context = 'Operating Unit Information';
IF NVL(vc_folder, '') = '' OR vc_folder IS NULL THEN
fnd_file.put_line(fnd_file.log,'AP Folder Name is empty.');
fnd_file.put_line(fnd_file.log,'AP Folder Name is empty.');
vc_file_location := NULL;
RETURN;
ELSE
vc_file_location := ltrim(vc_file_path) || ltrim(vc_folder);
END IF;
EXCEPTION
WHEN OTHERS THEN
fnd_file.put_line(fnd_file.log,'Cannot get the AP Folder Name.');
fnd_file.put_line(fnd_file.log,'Cannot get the AP Folder Name.');
vc_file_location := NULL;
RETURN;
END;
vc_file_ref := utl_file.fopen(vc_file_location,ic_user_file,'r');
-- send_output('成功打开文件.');
fnd_file.put_line(fnd_file.log,'open file successful.');
EXCEPTION
WHEN utl_file.invalid_path THEN
-- send_output('文件名无效');
fnd_file.put_line(fnd_file.log,'FileName is invalid:'||SQLCODE||'-'||SQLERRM);
v_read_file_flag:= FALSE;
WHEN UTL_FILE.INVALID_OPERATION THEN
fnd_file.put_line(fnd_file.log,'Operation is invalid:'||SQLCODE||'-'||SQLERRM);
v_read_file_flag:= FALSE;
WHEN UTL_FILE.READ_ERROR THEN
fnd_file.put_line(fnd_file.log,'Read error:'||SQLCODE||'-'||SQLERRM);
v_read_file_flag:= FALSE;
WHEN OTHERS THEN
fnd_file.put_line(fnd_file.log,'Other error:'||SQLCODE||'-'||SQLERRM);
v_read_file_flag:= FALSE;
END;
--start read file
-- send_output('开始读取文件.');
fnd_file.put_line(fnd_file.log,'Begin to read file.');
IF v_read_file_flag THEN
BEGIN
utl_file.get_line(vc_file_ref,vc_file_info);
EXCEPTION
WHEN NO_DATA_FOUND THEN
fnd_file.put_line(fnd_file.log,'No_Data_Found:-----'||SQLCODE||'-'||SQLERRM);
v_read_file_flag:= FALSE;
END;
END IF;
IF v_read_file_flag THEN
LOOP
--read txt file and Each time read only read one line data of the target txt file
BEGIN
utl_file.get_line(vc_file_ref,vc_file_info);
IF vc_file_info IS NULL OR TRIM(vc_file_info) = '' THEN
CONTINUE;
END IF;
v_counter := v_counter +1;
v_BANK_ACCT_list(v_counter).Payment_bank_Code := REPLACE(SUBSTR(vc_file_info,1,instr(vc_file_info,chr(9) ,1,1)-1),'"','');
-- v_BANK_ACCT_list(v_counter).BANK_ACCOUNT_NUM := SUBSTR(vc_file_info,instr(vc_file_info,chr(9) ,1,1) +1,instr(vc_file_info,chr(9) ,1,2)-instr(vc_file_info,chr(9) ,1,1)-1) ;
v_BANK_ACCT_list(v_counter).BANK_ACCOUNT_NUM := SUBSTR(vc_file_info,INSTR(vc_file_info,chr(9) ,1,1) +1);
-- SEND_OUTPUT(v_BANK_ACCT_list(v_counter).VENDOR_SITE_CODE||' : '||v_BANK_ACCT_list(v_counter).VENDOR_CASHFLOW_TYPE);
EXCEPTION
WHEN NO_DATA_FOUND THEN
fnd_file.put_line(fnd_file.log,'Total bank account record:'||v_counter);
fnd_file.put_line(fnd_file.log,'Read file completed.');
EXIT;
WHEN OTHERS THEN
fnd_file.put_line(fnd_file.log,'Get error when get data from file:-----('||v_counter||')--'||vc_file_info||'-'||SQLCODE||'-'||SQLERRM);
v_read_file_flag:= FALSE;
EXIT;
END;
END LOOP;
END IF;
----validation
IF v_read_file_flag THEN
FOR i IN 1..v_counter
LOOP
IF v_BANK_ACCT_list(i).Payment_bank_Code IS NOT NULL AND v_BANK_ACCT_list(i).BANK_ACCOUNT_NUM IS NOT NULL THEN
BEGIN
SELECT count(1) into v_BANK_ACC_check
FROM ce_bank_accounts
WHERE bank_account_num = trim(v_BANK_ACCT_list(i).BANK_ACCOUNT_NUM) ;
if v_BANK_ACC_check < 1 then
v_BANK_ACCT_list(i).STATUS := '银行账户不存在';
v_read_file_flag := FALSE;
end if;
v_BANK_ACCT_list(i).STATUS :='OK' ;
EXCEPTION
WHEN OTHERS THEN
fnd_file.put_line(fnd_file.log,'Error when get :'||v_BANK_ACCT_list(i).BANK_ACCOUNT_NUM||' BANK_ACCOUNT_ID ; ==>'||SQLERRM);
v_BANK_ACCT_list(i).STATUS := SUBSTR(SQLERRM,1,150);
v_read_file_flag := FALSE;
END;
ELSE
v_BANK_ACCT_list(i).STATUS :='Payment_bank_Code IS NULL or BANK_ACCOUNT_NUM IS NULL' ;
v_read_file_flag := FALSE;
END IF;
END LOOP;
END IF;
--update bank account to Oracle EBS with api
IF v_read_file_flag THEN
fnd_file.put_line(fnd_file.log,'Total bank account record: '||v_counter );
FOR i IN 1..v_counter
LOOP
-- fnd_file.put_line(fnd_file.log,i||':'||v_org_id||' - '||v_BANK_ACCT_list(i).VENDOR_SITE_CODE||' display :'||i||'/'||v_counter);
-- SEND_OUTPUT(v_BANK_ACCT_list(i).VENDOR_SITE_CODE||' : '||v_o_mverp||' => '||v_BANK_ACCT_list(i).VENDOR_CASHFLOW_TYPE);
--upadat supplier site table
-- IF v_BANK_ACCT_list(i).STATUS ='OK' THEN
BEGIN
BEGIN
FOR acc_list IN
(SELECT BANK_ACCOUNT_ID,bank_account_name,OBJECT_VERSION_NUMBER
FROM ce_bank_accounts
WHERE bank_account_num = trim(v_BANK_ACCT_list(i).BANK_ACCOUNT_NUM)
)
LOOP
-- all required params:
-- bank_account_id
-- bank_account_name
-- bank_account_num
-- account_classification
-- p_object_version_number
Vrec_BankAcct.bank_account_id := acc_list.BANK_ACCOUNT_ID;
-- fnd_file.put_line(fnd_file.log,'BANK_ACCOUNT_ID - '||acc_list.BANK_ACCOUNT_ID );
Vrec_BankAcct.attribute2 := v_BANK_ACCT_list(i).Payment_bank_Code;
Vrec_BankAcct.account_classification := 'SUBSIDIARY'; --INTERNAL 原数据为,但是不行
Vrec_BankAcct.bank_account_name := acc_list.bank_account_name;
Vrec_BankAcct.bank_account_num := trim(v_BANK_ACCT_list(i).BANK_ACCOUNT_NUM);
ce_bank_pub.update_bank_acct (
p_init_msg_list => fnd_api.g_false,
p_acct_rec => Vrec_BankAcct,
p_object_version_number => acc_list.OBJECT_VERSION_NUMBER,
x_return_status => vc_return_status,
x_msg_count => vn_msg_count,
x_msg_data => vl_msg_data
);
END LOOP;
EXCEPTION
WHEN OTHERS THEN
Vc_upd_Status := 'E';
fnd_file.put_line(fnd_file.log,'Vc_upd_Status - '||Vc_upd_Status );
END ;
IF (vc_return_status <> 'S') OR Vc_upd_Status = 'E' THEN
fnd_file.put_line(fnd_file.log,'vl_msg_data - '||vl_msg_data );
v_BANK_ACCT_list(i).STATUS := '----ERROR';
ELSE
Vn_Record_Num_bankacc := Vn_Record_Num_bankacc + 1;
v_BANK_ACCT_list(i).STATUS := 'Imported';
END IF;
END;
-- END IF;
END LOOP;
END IF;
--print data status
-- fnd_file.put_line(fnd_file.log,'#:Oracle_site_code:Old_vendor_cashflow_type:New_vendor_cashflow_type:Status');
FOR i IN 1..v_counter
LOOP
fnd_file.put_line(fnd_file.log,i||' BANK_ACCOUNT_NUM:'||v_BANK_ACCT_list(i).BANK_ACCOUNT_NUM ||' ,Payment_bank_Code:'||v_BANK_ACCT_list(i).Payment_bank_Code||', check status:'||v_BANK_ACCT_list(i).STATUS);
END LOOP;
/****************end read file************************/
-- send_output('付款银行.编码 更新条数:');
-- fnd_file.put_line(fnd_file.log,'Total updated bank account record:'||Vn_Record_Num_bankacc);
fnd_file.put_line(fnd_file.log,'Total updated bank account record:'||Vn_Record_Num_bankacc);
EXCEPTION
WHEN OTHERS THEN
fnd_file.put_line(fnd_file.log,'Othes Exception - '||SQLCODE||sqlerrm );
ROLLBACK;
END ML_UPDATE_BANK_ACCT_INFO;