固定資產每月執行自動攤提折舊作業(afap300),執行完後再執行月底結轉作業(afap304),但是每年年初需執行年底結轉作業(afap305),而不是執行月底結轉作業,會計偶而會忘記這個程序而繼續使用月底結轉,常常發現時已經一年過了一半了,已經無法還原了。當期累折就會一直是錯誤的情況,此時只能自行寫程式更新了:
============================================================
CREATE OR REPLACE procedure update_fan08
is
cursor fan1 is select fan01,fan02,fan03,fan04,fan041,fan05,fan06
from fan_file where fan03=2010 and fan05 in ('1','2') Order by fan03,fan04;
cursor fan2 is select fan01,fan02,fan03,fan04,fan041,fan05,fan06
from fan_file where fan03=2010 and fan05=3 Order by fan03,fan04;
cfan01 varchar2(10);
cfan02 varchar2(04);
nfan03 number(5);
nfan04 number(5);
cfan041 varchar2(01);
cfan05 varchar2(01);
cfan06 varchar2(08);
nfan08 number(20,6);
begin
open fan2;
loop
begin
fetch fan2 into cfan01,cfan02,nfan03,nfan04,cfan041,cfan05,cfan06;
EXIT WHEN cfan01 IS NULL;
nfan08 := 0 ;
select fan08 into nfan08 from fan_file
where fan01=cfan01 and fan02=cfan02 and fan03=2010 and fan04=nfan04-1
and fan041=cfan041 and fan05=cfan05 and fan06=cfan06;
update fan_file set fan08=fan07+nfan08
where fan01=cfan01 and fan02=cfan02 and fan03=nfan03 and fan04=nfan04
and fan041=cfan041 and fan05=cfan05 and fan06=cfan06;
COMMIT;
EXCEPTION
WHEN NO_DATA_FOUND THEN
update fan_file set fan08=fan07+nfan08
where fan01=cfan01 and fan02=cfan02 and fan03=nfan03 and fan04=nfan04
and fan041=cfan041 and fan05=cfan05 and fan06=cfan06;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
end;
EXIT WHEN fan2%NOTFOUND;
end loop;
commit;
close fan2;
open fan1;
loop
begin
fetch fan1 into cfan01,cfan02,nfan03,nfan04,cfan041,cfan05,cfan06;
EXIT WHEN cfan01 IS NULL;
nfan08 := 0 ;
select fan08 into nfan08 from fan_file
where fan01=cfan01 and fan02=cfan02 and fan03=2010 and fan04=nfan04-1
and fan041=cfan041 and fan05=cfan05;
update fan_file set fan08=fan07+nfan08
where fan01=cfan01 and fan02=cfan02 and fan03=nfan03 and fan04=nfan04
and fan041=cfan041 and fan05=cfan05 and fan06=cfan06;
COMMIT;
EXCEPTION
WHEN NO_DATA_FOUND THEN
update fan_file set fan08=fan07+nfan08
where fan01=cfan01 and fan02=cfan02 and fan03=nfan03 and fan04=nfan04
and fan041=cfan041 and fan05=cfan05 and fan06=cfan06;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
end;
EXIT WHEN fan1%NOTFOUND;
end loop;
commit;
close fan1;
end;
/
============================================================
分兩段更新,主要是分攤方式的分別
留言列表