Procedura

download Procedura

If you can't read please download the document

description

procedura za dobiti besplatan pristup

Transcript of Procedura

CREATE OR REPLACE function DBO.Send (p_scenario IN varchar2 default ' ', p_value_date IN date) RETURN NUMBER as cursor c_instrument(cp_instrument_id in instrument.id%type) is select * from instrument where id = cp_instrument_id; r_instrument c_instrument%rowtype; cursor c_price is select p.id, P.price_type_id, MIM.NAME_ID, mim.type_id , (decode(p.price_type_id, 196708, price_1, price_3)+decode(p.price_type_id, 196708, price_2, price_4))/2 price from prices p , scenario s , marketinfomap mim where s.name_id = p_scenario and s.id = p.scenario_id and p."date" = p_value_date and p.id = mim.id and (mim.type_id = 'IR-QUOTE' and p.price_type_id = 196708 or mim.type_id = 'IR-YTM' and not exists (select 1 from prices p2, marketinfomap mim2 where p2.id = mim2.id and p2.price_type_id = 196708 and mim.name_id = mim2.name_id and p2."date" = p_value_date) ) ; rp c_price%rowtype; CR1 sybemu.REFCURSOR; r_sc securitycode%rowtype; l_isin varchar(25); res number; l_configuration_value CONFIGURATION.VALUE%type; log_line varchar2(400); l_counter number := 0; l_price number; l_accr_book_value number(15,6) := 0; cursor c_timeseries (cp_scenario varchar2, cp_value_date date, cp_real_unreal varchar2) is select * from timeseriesob where instrument_type_id = 'USBILL' and figure_date = cp_value_date and instrument_id = r_instrument.id and portfolio_id in ('NET-RES-USD-INV', 'MAN-RES') and currency_id = 'USD' and scenario_id = cp_scenario and upper(real_unreal) = upper(nvl(cp_real_unreal, 'REALIZED')) and transaction_state = 'FINAL'; cursor c_timeseries2 (cp_scenario varchar2, cp_value_date date, cp_real_unreal varchar2) is select * from timeseriesob where figure_date = cp_value_date and instrument_id = r_instrument.id and scenario_id = cp_scenario and upper(real_unreal) = upper(nvl(cp_real_unreal, 'REALIZED')) and transaction_state = 'FINAL' and substr(portfolio_id, length(portfolio_id)-2, 3) = 'HTM'; r_timeseries c_timeseries%rowtype; l_timeseries_found boolean; cursor c_papers_in_htm (cp_scenario varchar2, cp_value_date date, cp_real_unreal varchar2) is select * from timeseriesob where figure_date = cp_value_date and scenario_id = cp_scenario and upper(real_unreal) = upper(nvl(cp_real_unreal, 'REALIZED')) and transaction_state = 'FINAL' and substr(portfolio_id, length(portfolio_id)-2, 3) = 'HTM' and instrument_id not in (select mim.name_id from prices p , scenario s , marketinfomap mim where s.name_id = p_scenario and s.id = p.scenario_id and p."date" = p_value_date and p.id = mim.id and (mim.type_id = 'IR-QUOTE' and p.price_type_id = 196708 or mim.type_id = 'IR-YTM' and not exists (select 1 from prices p2, marketinfomap mim2 where p2.id = mim2.id and p2.price_type_id = 196708 and mim.name_id = mim2.name_id and p2."date" = p_value_date) ));begin SYBEMU.pushProcName('CBSendGLPriceData'); results.print(' Exporting prices for date '||p_value_date); if GetValueFromConfiguration(pId => 1000, CR1 => CR1) = 0 then fetch CR1 into l_configuration_value; close CR1; end if; for rp in c_price loop -- Fetch ISIN if SearchSecurityCode (pStandard_ID => 'ISIN', pInstrument_ID => rp.name_id, CR1 => CR1) = 0 then fetch CR1 into r_sc; l_isin := r_sc.code; close CR1; else l_isin := null; end if; l_accr_book_value := 0; --dbms_output.put_line(l_isin); if l_isin is not null then if l_configuration_value = 'true' then log_line :=' '||p_value_date||';'||l_isin||';'||rp.price; results.print(log_line); res := 0; elsif l_configuration_value = 'false' then r_instrument := null; open c_instrument(rp.name_id); fetch c_instrument into r_instrument; close c_instrument; r_timeseries := null; open c_timeseries2(p_scenario, p_value_date, 'REALIZED'); fetch c_timeseries2 into r_timeseries; l_timeseries_found := c_timeseries2%found; close c_timeseries2; l_accr_book_value := nvl(round(r_timeseries.accrued_book_value,6), 0); if r_instrument.type_id = 'USBILL' then --za USBILLove, izracunaj price r_timeseries := null; open c_timeseries(p_scenario, p_value_date, 'REALIZED'); fetch c_timeseries into r_timeseries; l_timeseries_found := c_timeseries%found; close c_timeseries; if l_timeseries_found then if r_timeseries.nominal_amount = 0 then l_price := 0; else l_price := round(r_timeseries.market_value / r_timeseries.nominal_amount * 100, 8); end if; else l_price := 0; end if; else l_price := rp.price; end if; --p_log('Standard loop; count = '||l_counter); --p_log(p_value_date || ' ' || l_isin || ' ' || l_price || ' ' || l_accr_book_value); begin res := wss_gl_securities_price@remote( p_value_date , l_isin , l_price , l_accr_book_value ); l_counter := l_counter + 1; --log_line :=' '||p_value_date||';'||l_isin||';'||rp.price; --results.print(log_line); --res := 0; exception when others then --rollback; --RESULTS.RAISERROR( 40019, '*Error in remote function during WSSGLSecuritiesPrice CALL call.'); log_line :=' Failed with values: '||p_value_date||';'||l_isin||';'||l_price; results.print(log_line); raise; SYBEMU.popProcName; return 1; end; end if; -- configuration if res = 0 then if res = 0 then null; else SYBEMU.popProcName; return 1; end if; end if; end if; -- security code exists?; end loop; --for rp in c_price -- now handle all papers in HTM potfolio which haven't been exported in the above loop -- this is because we need ABV exported during the weekends, when there are no prices for r_htm in c_papers_in_htm(p_scenario, p_value_date, 'REALIZED') loop r_sc := null; l_isin := null; l_accr_book_value := 0; if SearchSecurityCode (pStandard_ID => 'ISIN', pInstrument_ID => r_htm.instrument_id, CR1 => CR1) = 0 then fetch CR1 into r_sc; l_isin := r_sc.code; close CR1; else l_isin := null; end if; l_accr_book_value := nvl(round(r_htm.accrued_book_value,6), 0); l_price := 0; --no price found for these papers, send 0 begin --p_log('HTM loop; count = '||l_counter); --p_log(p_value_date || ' ' || l_isin || ' ' || l_price || ' ' || l_accr_book_value); res := wss_gl_securities_price@remote( p_value_date , l_isin , l_price , l_accr_book_value ); l_counter := l_counter + 1; exception when others then --rollback; --RESULTS.RAISERROR( 40019, '*Error in remote function during WSSGLSecuritiesPrice CALL call for HTM portfolio.'); log_line :=' Failed with values: '||p_value_date||';'||l_isin||';'||l_price; results.print(log_line); raise; SYBEMU.popProcName; return 1; end; end loop; results.print(' Number of exported prices: '||l_counter); SYBEMU.popProcName; return 0;end CBSendGLPriceData;/