Monday, January 11, 2010

Cursors in oracles

declare
cursor testv is
select code_combination_id,account_type
from gl_code_combinations;
Type rec_gl_periods is Record(ccid gl_code_combinations.code_combination_id%Type,
descr gl_code_combinations.account_type%Type
);
recs rec_gl_periods;
testrow testv%rowtype;
begin
open testv;
loop
fetch testv into testrow;
exit when testv%notfound;
message (testrow.code_combination_id);
message(testrow.account_type);

end loop;
null;
end;

Attaching reports with Forms

DECLARE
PL_ID PARAMLIST;
BEGIN

PL_ID := GET_PARAMETER_LIST ('report_plist');
IF NOT ID_NULL(PL_ID) THEN
-- this is just to make sure it clean
DESTROY_PARAMETER_LIST ('report_plist');
END IF;

PL_ID := CREATE_PARAMETER_LIST('report_plist');
Add_Parameter(pl_id,'DESTYPE',TEXT_PARAMETER,'SCREEN');
--Add_Parameter(pl_id,'DESNAME',TEXT_PARAMETER,'printer name');
--Add_Parameter(pl_id,'ORIENTATION',TEXT_PARAMETER,'LANDSCAPE');
--add_parameter (pl_id, 'BATCHID',text_parameter,'124');
--add_parameter (pl_id, 'COMPNAME' , text_parameter ,'Company Name' );
Add_Parameter(pl_id,'PARAMFORM',TEXT_PARAMETER,'NO');
RUN_PRODUCT (REPORTS,'c:\repo\manualque.rdf',SYNCHRONOUS,RUNTIME,FILESYSTEM, pl_id,NULL);
DESTROY_PARAMETER_LIST ('report_plist');
END;

Ledger's Opening Balancs

Select period_name,
period_year,
period_num,
to_char(start_date,'yyyy/mm/dd') ||' 00:00:00'
into lv_period_name,
ln_period_year,
ln_period_num,
lv_start_date
from gl_periods
where upper(period_set_name) = 'Dec-95'
and adjustment_period_flag <> 'Y'
and :p_date_from between (to_char(start_date,'yyyy/mm/dd') ||' 00:00:00') and (to_char(end_date,'yyyy/mm/dd') ||' 00:00:00') ;

--- Getting Op Bal for the period

Select sum(nvl(gb.begin_balance_dr,0)-nvl(gb.begin_balance_cr,0))
into ln_month_op_bal
from gl_Balances gb,
gl_code_combinations gcc
where gb.period_name = lv_period_name
and gb.code_combination_id = gcc.code_combination_id
and gb.code_combination_id = :ccid
and gb.Ledger_id = :p_sob
and gb.currency_code = 'PKR'
and gb.actual_fLag = 'A' ;


Select nvl(sum(nvl(jgl.accounted_dr,0) - nvl(jgl.accounted_cr,0)),0)
into ln_amt
from gl_je_headers jgh ,
gl_je_lines jgl
where
jgh.Ledger_id = :p_sob
and jgh.Ledger_id =jgl.ledger_id
and jgh.status = 'P'
and jgh.actual_flag = 'A'
and jgh.je_header_id = jgl.je_header_id
and jgl.code_combination_id = :ccid
and ((to_char(jgh.default_effective_date,'yyyy/mm/dd') ||' 00:00:00') >= lv_start_date
and (to_char(jgh.default_effective_date,'yyyy/mm/dd') ||' 00:00:00') < :p_date_from) ;

return nvl(ln_amt,0) + nvl(ln_month_op_bal,0) ;

Exception
when no_data_found then
return 0 ;
when too_many_rows then
return 0 ;
when others then
return 0 ;