procedure ast_opn_movement(p_locnid in varchar2,p_month in date,p_assetcd in varchar2,p_dcat_code in varchar2,p_error in out varchar2,p_upcount in out number) is cursor c_fm0asset is -- to reterive unique cstcd with location select cstcd,astlocncd from fm0asset where locnid = p_locnid and assetcd = nvl(p_assetcd,assetcd) and nvl(cum_value,0) > 1 -- New criteria and disabled_status is null group by cstcd,astlocncd; cursor c_asset(t_assetcd in varchar2) is select cum_date from fm0asset -- old stmnt. select docdt from fm0asset where locnid = p_locnid and assetcd = t_assetcd; tmp_docno varchar2(8); tmp_docid varchar2(14); tmp_error varchar2(200); tmp_check number(1) := 0; tmp_upcount number(5); Begin tmp_upcount := 0; for rec in c_fm0asset loop -- chk for opn asset movement is avilable from this cstcd on this month tmp_check := 0; for i in ( select assetcd from fm0asset where locnid = p_locnid and assetcd = nvl(p_assetcd,assetcd) and cstcd = rec.cstcd and astlocncd = rec.astlocncd and nvl(cum_value,0) > 1 and disabled_status is null minus select assetcd from ft0astldgr where locnid = p_locnid and assetcd = nvl(p_assetcd,assetcd) and to_char(docdt,'MM/RRRR') = to_char(p_month,'MM/RRRR') and fm_cstcd = rec.cstcd and fm_astlocncd = rec.astlocncd and opn_type is not null) loop if i.assetcd is not null then tmp_check := 1; exit; end if; end loop; if tmp_check = 1 then -- if present -- Generate Next docno for Asset Movements docno_gen(p_locnid,'AST-P','/', to_char(p_month,'YY'),tmp_docno,tmp_error); if tmp_error is not null then p_error := tmp_error; raise user_exception; end if; tmp_docid := p_locnid||tmp_docno; insert into ft0astmv (LOCNID,ASTMV_DOCNO,ASTMV_DOCDT,ASTMV_DOCID,FM_CSTCD,TO_CSTCD, FM_ASTLOCNCD,TO_ASTLOCNCD,ASTMV_STATUS,REMARKS) values (p_locnid,tmp_docno,p_month,tmp_docid,rec.cstcd,rec.cstcd,rec.astlocncd, rec.astlocncd,'A','Opening Movement'); if sql%notfound then p_error := 'Error while Inserting Master Record for the Opening Asset Movemnt with the cstcd'||rec.cstcd||' location '||rec.astlocncd; raise user_exception; end if; for rec1 in (select assetcd from fm0asset where locnid = p_locnid and assetcd = nvl(p_assetcd,assetcd) and cstcd = rec.cstcd and astlocncd = rec.astlocncd and nvl(cum_value,0) > 1 and disabled_status is null minus select assetcd from ft0astldgr where locnid = p_locnid and assetcd = nvl(p_assetcd,assetcd) and to_char(docdt,'MM/RRRR') = to_char(p_month,'MM/RRRR') and fm_cstcd = rec.cstcd and fm_astlocncd = rec.astlocncd and opn_type is not null) loop if rec1.assetcd is not null then -- Insert into FT1ASTMV TABLE insert into ft1astmv (LOCNID,ASTMV_DOCNO,ASTMV_DOCDT,ASTMV_DOCID,ASSETCD,FM_CSTCD, FM_ASTLOCNCD,TO_CSTCD,TO_ASTLOCNCD,ASTMV_STATUS) values(p_locnid,tmp_docno,p_month,tmp_docid,rec1.assetcd,rec.cstcd,rec.astlocncd, rec.cstcd,rec.astlocncd,'A'); if sql%notfound then p_error := 'Error while Inserting Detail Record for the Opening Asset Movemnt with the Asset'||rec1.assetcd||' with Cstcd '||rec.cstcd||' - '||rec.astlocncd; raise user_exception; end if; for rec2 in c_asset(rec1.assetcd) loop -- this cursor for getting Pur_date -- Insert into Asset Ledger table (No need to caluculate consume days for opn movement) insert into FT0ASTLDGR (LOCNID,DOCNO,DOCDT,DOCID,ASSETCD,FM_CSTCD,FM_ASTLOCNCD, TO_CSTCD,TO_ASTLOCNCD,CONSUME_DAYS,CONSUME_AMT,OPN_TYPE,PUR_DATE) values (p_locnid,tmp_docno,p_month,tmp_docid,rec1.assetcd,rec.cstcd,rec.astlocncd, rec.cstcd,rec.astlocncd,null,null,'Y',rec2.cum_date); if sql%notfound then p_error := 'Error while Inserting Detail Record for the Opening Asset Movemnt into the Asset Ledger for the Asset'||rec1.assetcd||' with Cstcd '||rec.cstcd||' - '||rec.astlocncd; raise user_exception; end if; end loop; -- end of cursor c_fm0asset tmp_upcount := tmp_upcount + 1; end if; end loop; end if; end loop; p_upcount := tmp_upcount; exception When user_exception then null; when others then p_error := sqlerrm; end ast_opn_movement;