Sie sind auf Seite 1von 14

create or replace

PACKAGE BODY ICAP_LOAD_HFM_INT_PKG AS


/****************************************************************************
*
MODULE NAME:
ICAP_LOAD_HFM_INT_PKG
ORIGINAL AUTHOR: Siva Prasad
DATE:
1st July 2013
DESCRIPTION:
Notes: This module is used by HFM to Refresh the interface table with the
latest data from the GAA MGMT Overnight view

CHANGE HISTORY
==============
VERSION DATE
AUTHOR
CHANGE DESCRIPTION
------- ----------- --------------- ------ -----------------------------------1.0
01-Jul-2013 Siva Prasad
initial Release
1.1
16-Jul-2013 Siva
Removed
insert to HFM interface table
1.2
12-AUG-2013 Siva
Changes to accounts from P13
to have '_ADJ'
1.3
04-SEP-2013 Harjit
Removed delete from ICAP_HFM
_AIF_OPEN_INTERFACE statements.
Now using a procedure in rem
ote database instead.
1.4
11-SEP-2013 Vinod Durbhaka
Added a wrapper
FUNCTION submit_hfm_stat_actuals
to submit the concurrent program from command line.
Logic includes supplying any parameters when
not passed. They will be picked from the table
ICAP_GAA_PARAMETERS.
*****************************************************************************
**/
-- Global variables section
g_debug
VARCHAR2(1);
TYPE t_error IS RECORD(error_date DATE
,error_location VARCHAR2(100)
,error_message VARCHAR2(4000)
);
TYPE t_errors IS TABLE OF t_error INDEX BY BINARY_INTEGER;
g_errors
t_errors;
/****************************************************************************
*
PROCEDURE:

write_log

DESCRIPTION: Writes a string to the concurrent request log. The procedure

writes the date, location of the program and the message to the
log.
PARAMETERS:
NAME
--------------1. p_location
2. p_message

TYPE
-------VARCHAR2
VARCAHR2

DESCRIPTION
--------------------------------------Location of the log within the program
Message to be written

*****************************************************************************
/
PROCEDURE write_log(p_location IN VARCHAR2
,p_message IN VARCHAR2) IS
BEGIN
FND_FILE.PUT_LINE(FND_FILE.LOG
,fnd_date.date_to_displayDT(sysdate)
|| ' ' || p_location || '
);

' || p_message

END write_log;
/* *************************************************************************
***
PROCEDURE:

write_output

DESCRIPTION: Writes a string to the concurrent request output. The procedure


writes the date, location of the program and the message to the
output.
PARAMETERS:
NAME
--------------1. p_location
2. p_message

TYPE
-------VARCHAR2
VARCAHR2

DESCRIPTION
--------------------------------------Location of the log within the program
Message to be written

****************************************************************************
*/
PROCEDURE write_output(p_message

IN VARCHAR2) IS

BEGIN
FND_FILE.PUT_LINE(FND_FILE.OUTPUT, p_message);
END write_output;
/* ****************************************************************************
PROCEDURE: debug
DESCRIPTION: Writes a string to the concurrent request log if the debug
parameter has been set in the package.
PARAMETERS:
NAME
---------------

TYPE
--------

DESCRIPTION
---------------------------------------

1. p_location
2. p_message

VARCHAR2
VARCAHR2

Location of the log within the program


Message to be written

****************************************************************************
*/
PROCEDURE debug(p_location IN VARCHAR2
,p_message IN VARCHAR2) IS
BEGIN
IF nvl(g_debug, 'N') = 'Y' THEN
write_log(p_location => p_location, p_message => p_message);
END IF;
END debug;
/* **************************************************************************
**
PROCEDURE:

write_error

DESCRIPTION: Writes an error message to the concurrent request log and stores
the error message in the global errors collection.
PARAMETERS:
NAME
--------------1. p_location
2. p_message

TYPE
-------VARCHAR2
VARCHAR2

DESCRIPTION
--------------------------------------Location of the error within the program
Message to be written

****************************************************************************
*/
PROCEDURE write_error(p_location IN VARCHAR2
,p_message IN VARCHAR2) IS
v_date
DATE;
v_text
VARCHAR2(2000);
v_location VARCHAR2(30) := 'output_report';
BEGIN
v_date := sysdate;
g_errors(g_errors.count+1).error_date := sysdate;
g_errors(g_errors.count).error_location := p_location;
g_errors(g_errors.count).error_message := p_message;
write_log(p_location => p_location, p_message => '*** ERROR *** ' || p_mes
sage);
END write_error;
/* *************************************************************************
***
PROCEDURE:

Delete_HFM_DATA

DESCRIPTION: This procedure is used to delete the data


form the interface table for a given period

PARAMETERS: period
NAME
---------------

TYPE
--------

DESCRIPTION
---------------------------------------

****************************************************************************
*/
PROCEDURE DELETE_HFM_DATA(p_period IN VARCHAR2 )
IS
lc_curr_proc
VARCHAR2(40) := 'DELETE HFM BALANCES';
lc_period_num
VARCHAR2(10);
lc_year
VARCHAR2(4);
ln_err_cnt
NUMBER := 0;
ln_rec_cnt
NUMBER := 0;
LN_START
number := 0;
ln_env_name
varchar2(10);
BEGIN
select period_num,period_year into lc_period_num, lc_year
from gl_periods
where period_name=p_period
and period_set_name = 'ICAP-Calendar'
and rownum =1;
select value into ln_env_name from V$PARAMETER where name ='instance_name' a
nd rownum=1;
debug(lc_curr_proc, '-------------------------------------');
ln_start := dbms_utility.get_time;
write_output('Delete existing HFM balances for period : '||p_period);
debug(lc_curr_proc, 'Delete existing HFM balances for period : '||p_period);
/* below procedure call now delete the data in remote database (added by Ha
rjit) */
ICAP_HFM_DEL_ERPI_OI.DELETE_HFM_STAT_INTERFACE('HFM_Stat_'||ln_env_name,'AC
T');
COMMIT;
write_output('HFM Balance rows Deleted');
-- write_output('HFM Balance rows Deleted : '||ln_rec_cnt);
-- debug(lc_curr_proc, 'HFM Balance rows Deleted for period('||p_period||')
:'||ln_rec_cnt);
debug(lc_curr_proc, 'Time taken for Deleting HFM Balances(secs) :'||to_cha
r((dbms_utility.get_time-ln_start)/100));
EXCEPTION
WHEN OTHERS THEN
write_error(lc_curr_proc,'Error in DELETE_HFM_DATA:'||SQLERRM);
END DELETE_HFM_DATA;
/* ***********************************************************************
*****
PROCEDURE: LOAD_HFM_DATA
DESCRIPTION: This procedure is used to refresh the interface table
for the GAA Mgmt Overnight view for a given period
PARAMETERS: period

NAME
---------------

TYPE
--------

DESCRIPTION
---------------------------------------

****************************************************************************
*/
PROCEDURE LOAD_HFM_DATA(p_period
IS
lc_curr_proc
lc_period_num
lc_year
lc_month
ln_err_cnt
ln_start
ln_rec_cnt
ln_count
ln_env_name
--ln_temp
ln_curr_period

IN VARCHAR2)

VARCHAR2(40) := 'LOAD_HFM_DATA';
VARCHAR2(10);
VARCHAR2(4);
VARCHAR2(2);
NUMBER := 0;
NUMBER := 0;
NUMBER := 0;
number :=0;
varchar2(30);
varchar2(10);
varchar2(10);

BEGIN
debug(lc_curr_proc, '-------------------------------------');
select period_num,period_year into lc_period_num, lc_year
from gl_periods
where period_name=p_period
and period_set_name = 'ICAP-Calendar'
and rownum =1;
--SELECT substr(period_name,1,3) into ln_curr_period
--FROM GL_PERIODS GP
-- WHERE TRUNC(sysdate) BETWEEN START_DATE AND END_DATE
-- and ADJUSTMENT_PERIOD_FLAG <> 'Y'
-- AND period_set_name = 'ICAP-Calendar'
-- and rownum=1;
ln_curr_period :='APR';
select value into ln_env_name from V$PARAMETER where name ='instance_name' a
nd rownum=1;

-- debug(lc_curr_proc, 'period_num: 'lc_year'Period_year : 'lc_period_num);


SELECT count(1) into ln_count
FROM ICAP_HFM_AIF_OPEN_INTERFACE a
WHERE a.YEAR = lc_year
and a.period_num=lc_period_num
and a.batch_name='HFM_Stat_'||ln_env_name;
if ln_count > 0 then
DELETE_HFM_DATA(P_PERIOD);
end if;
-- debug(lc_curr_proc, 'ln_count: 'ln_count);

ln_start := dbms_utility.get_time;
debug(lc_curr_proc,'Start loading HFM Balances into staging table for period
: '||p_period);
write_output('Start loading HFM Balances into staging table for period : '||p
_period);
EXECUTE IMMEDIATE 'TRUNCATE TABLE ICAP.ICAP_TBL_FACT_ACT_HFM_STG';
if (p_period like 'MAR%' and ln_curr_period like 'APR%') then
INSERT INTO ICAP.ICAP_TBL_FACT_ACT_HFM_STG
with
ADJ_PER_HIGH_LOW(ADJ_PERIOD_YEAR_HIGH,
ADJ_PERIOD_YEAR_LOW,
ADJ_START_DTAE,
adj_end_date)
as
(select PERIOD_YEAR-2
, PERIOD_YEAR-5 ,YEAR_START_DATE , end_date from GL_PERIODS
where PERIOD_NAM
E=p_period
and PERIOD_SET_N
AME='ICAP-Calendar'),
hfm_view as (
select to_number(fin_year) fin_year
,SUBSTR(time,1,3) time
,to_number(fin_month) fin_month
,functionalcurrency
,scenario
,account
,account_type
,company
,costcentre
,intercompany
,product
,project
,erpi_resp_id
,erpi_resp_appl_id
,erpi_balance_type
,erpi_sob_id
,erpi_period
,erpi_code_combination_id
,NVL(FUNCTCURR_DATA_YTD,0) FUNCT
CURR_DATA_YTD
from ICAP.ICAP_TBL_FACT_ACT_HFM_
MAR_V where
fin_year=lc_year
and fin_month=lc_period_num
and replace(time,'_','-') = p_pe
riod
and functionalcurrency <>'STAT'
union all
select to_number(lc_year) fin_year
,SUBSTR(p_period,1,3) time
, to_number(lc_period_num) fin_month
,functionalcurrency
,scenario
,account||'_ADJ' account
,account_type

,company
,costcentre
,intercompany
,product
,project
,erpi_resp_id
,erpi_resp_appl_id
,erpi_balance_type
,erpi_sob_id
,p_period erpi_period
,erpi_code_combination_id
,NVL(FUNCTCURR_DATA_PTD,0) FUNC
TCURR_DATA_YTD
from
ICAP.ICAP_TBL_FACT_ACT_HFM_MAR_V ita , gl_per
iods gp
where
((gp.period_year =lc_year and gp.period_num <=
lc_period_num)
or gp.period_year <lc_year)
and ita.time like 'P13%'
and account_type in ('E','R')
and replace(ita.postingperiod,'_','-')= gp.perio
d_name
and gp.PERIOD_SET_NAME = 'ICAP-Calendar'
and ita.functionalcurrency <>'STAT'
union all
select TO_NUMBER(LC_YEAR) FIN_YEAR
,SUBSTR(P_PERIOD,1,3) time
, to_number(lc_period_num) fin_month
,functionalcurrency
,scenario
,account||'_ADJ' account
,account_type
,company
,costcentre
,intercompany
,product
,project
,erpi_resp_id
,erpi_resp_appl_id
,erpi_balance_type
,ERPI_SOB_ID
,p_period erpi_period
,erpi_code_combination_id
,NVL(FUNCTCURR_DATA_PTD,0) FUNC
TCURR_DATA_YTD
from
ICAP.ICAP_TBL_FACT_ACTUALS ita , gl_periods g
p ,ADJ_PER_HIGH_LOW ahl
where
ITA.FIN_YEAR between AHL.ADJ_PERIOD_YEAR_LOW
and ADJ_PERIOD_YEAR_HIGH
and gp.start_date between ahl.ADJ_START_DTAE a
nd ahl.adj_end_date
and ita.time like 'P13%'
and account_type in ('E','R')
and replace(ITA.POSTINGPERIOD,'_','-')= GP.PERIO
D_NAME
and gp.PERIOD_SET_NAME = 'ICAP-Calendar'

and ita.functionalcurrency <>'STAT')


select
'HFM_Stat_'||ln_env_name BATCH_NAME
,fin_year YEAR
,SUBSTR(time,1,3) PERIOD
,fin_month PERIOD_NUM
,'YTD' DATAVIEW
,functionalcurrency CURRENCY
,'HFM Statutory Load from Staging area'
DESC1
,scenario COL01
,account COL02
,company COL04
,costcentre COL06
,intercompany COL10
,product
COL14
,project
COL16
,erpi_resp_id ATTR1
,erpi_resp_appl_id ATTR2
,erpi_balance_type ATTR3
,erpi_sob_id ATTR4
,erpi_period ATTR5
,erpi_code_combination_id ATTR6
,SUM(NVL(FUNCTCURR_DATA_YTD,0)) AMOUNT
from hfm_view
-- where account_type in ('E','R')
group by fin_year
,SUBSTR(time,1,3)
,fin_month
,functionalcurrency
,scenario
,account
,company
,costcentre
,intercompany
,product
,project
,erpi_resp_id
,erpi_resp_appl_id
,erpi_balance_type
,erpi_sob_id
,erpi_period
,erpi_code_combination_id;
ln_rec_cnt := SQL%ROWCOUNT;
COMMIT;
else
INSERT INTO ICAP.ICAP_TBL_FACT_ACT_HFM_STG
with
ADJ_PER_HIGH_LOW(ADJ_PERIOD_YEAR_HIGH,
ADJ_PERIOD_YEAR_LOW,
ADJ_START_DTAE,
adj_end_date)
as
(select PERIOD_YEAR-2
, PERIOD_YEAR-5 ,YEAR_START_DATE , end_date from GL_PERIODS
where PERIOD_NAM

E=p_period
and PERIOD_SET_N
AME='ICAP-Calendar'),
hfm_view as (
select to_number(fin_year) fin_year
,SUBSTR(time,1,3) time
,to_number(fin_month) fin_month
,functionalcurrency
,scenario
,account
,account_type
,company
,costcentre
,intercompany
,product
,project
,erpi_resp_id
,erpi_resp_appl_id
,erpi_balance_type
,erpi_sob_id
,erpi_period
,erpi_code_combination_id
,NVL(FUNCTCURR_DATA_YTD,0) FUNCT
CURR_DATA_YTD
from ICAP.ICAP_TBL_FACT_ACT_HFM_
OVR_V where
fin_year=lc_year
and fin_month=lc_period_num
and replace(time,'_','-') = p_pe
riod
and functionalcurrency <>'STAT'
union all
select to_number(lc_year) fin_year
,SUBSTR(p_period,1,3) time
, to_number(lc_period_num) fin_month
,functionalcurrency
,scenario
,account||'_ADJ' account
,account_type
,company
,costcentre
,intercompany
,product
,project
,erpi_resp_id
,erpi_resp_appl_id
,erpi_balance_type
,erpi_sob_id
,p_period erpi_period
,erpi_code_combination_id
,NVL(FUNCTCURR_DATA_PTD,0) FUNC
TCURR_DATA_YTD
from
ICAP.ICAP_TBL_FACT_ACT_HFM_OVR_V ita , gl_per
iods gp
where
((gp.period_year =lc_year and gp.period_num <=
lc_period_num)
or gp.period_year <lc_year)
and ita.time like 'P13%'

and account_type in ('E','R')


and replace(ita.postingperiod,'_','-')= gp.perio
d_name
and gp.PERIOD_SET_NAME = 'ICAP-Calendar'
and ita.functionalcurrency <>'STAT'
union all
select TO_NUMBER(LC_YEAR) FIN_YEAR
,SUBSTR(P_PERIOD,1,3) time
, to_number(lc_period_num) fin_month
,functionalcurrency
,scenario
,account||'_ADJ' account
,account_type
,company
,costcentre
,intercompany
,product
,project
,erpi_resp_id
,erpi_resp_appl_id
,erpi_balance_type
,ERPI_SOB_ID
,p_period erpi_period
,erpi_code_combination_id
,NVL(FUNCTCURR_DATA_PTD,0) FUNC
TCURR_DATA_YTD
from
ICAP.ICAP_TBL_FACT_ACTUALS ita , gl_periods g
p ,ADJ_PER_HIGH_LOW ahl
where
ITA.FIN_YEAR between AHL.ADJ_PERIOD_YEAR_LOW
and ADJ_PERIOD_YEAR_HIGH
and gp.start_date between ahl.ADJ_START_DTAE a
nd ahl.adj_end_date
and ita.time like 'P13%'
and account_type in ('E','R')
and replace(ITA.POSTINGPERIOD,'_','-')= GP.PERIO
D_NAME
and gp.PERIOD_SET_NAME = 'ICAP-Calendar'
and ita.functionalcurrency <>'STAT')
select
'HFM_Stat_'||ln_env_name BATCH_NAME
,fin_year YEAR
,SUBSTR(time,1,3) PERIOD
,fin_month PERIOD_NUM
,'YTD' DATAVIEW
,functionalcurrency CURRENCY
,'HFM Statutory Load from Staging area'
DESC1
,scenario COL01
,account COL02
,company COL04
,costcentre COL06
,intercompany COL10
,product
COL14
,project
COL16
,erpi_resp_id ATTR1
,erpi_resp_appl_id ATTR2
,erpi_balance_type ATTR3
,erpi_sob_id ATTR4

,erpi_period ATTR5
,erpi_code_combination_id ATTR6
,SUM(NVL(FUNCTCURR_DATA_YTD,0)) AMOUNT
from hfm_view
-- where account_type in ('E','R')
group by fin_year
,SUBSTR(time,1,3)
,fin_month
,functionalcurrency
,scenario
,account
,company
,costcentre
,intercompany
,product
,project
,erpi_resp_id
,erpi_resp_appl_id
,erpi_balance_type
,erpi_sob_id
,erpi_period
,erpi_code_combination_id;
ln_rec_cnt := SQL%ROWCOUNT;
COMMIT;
end if;
WRITE_OUTPUT('HFM Balance rows loaded : '||LN_REC_CNT);
DEBUG(LC_CURR_PROC, 'HFM Balance rows loaded into staging table for period(
'||P_PERIOD||') :'||LN_REC_CNT);
DEBUG(LC_CURR_PROC, 'Time taken for loading HFM Balances into staging table
(secs) :'||TO_CHAR((DBMS_UTILITY.GET_TIME-LN_START)/100));

ln_start := dbms_utility.get_time;
debug(lc_curr_proc,'Start loading HFM Balances for period : '||p_period);
write_output('Start loading HFM Balances for period : '||p_period);
insert into ICAP_HFM_AIF_OPEN_INTERFACE (
BATCH_NAME
,YEAR
,PERIOD
,PERIOD_NUM
,DATAVIEW
,CURRENCY
,DESC1
,COL01
,COL02
,COL04
,COL06
,COL10
,COL14
,COL16
,ATTR1
,ATTR2
,ATTR3
,ATTR4
,ATTR5

,ATTR6
,AMOUNT)
select * from ICAP.ICAP_TBL_FACT_ACT_HFM_STG;
ln_rec_cnt := SQL%ROWCOUNT;
COMMIT;
write_output('HFM Balance rows loaded : '||ln_rec_cnt);
debug(lc_curr_proc, 'HFM Balance rows loaded for period('||p_period||') :'|
|ln_rec_cnt);
debug(lc_curr_proc, 'Time taken for loading HFM Balances(secs) :'||to_char
((dbms_utility.get_time-ln_start)/100));
EXCEPTION
WHEN OTHERS THEN
write_error(lc_curr_proc,'Error in LOAD_HFM_DATA:'||SQLERRM);
RAISE;
END LOAD_HFM_DATA;
/**************************************************************************
***
PROCEDURE:

MAIN

DESCRIPTION: main procedure, called from concurrent program.


*****************************************************************************
/
PROCEDURE MAIN(errbuf
,retcode
,p_debug

OUT NOCOPY VARCHAR2


OUT NOCOPY NUMBER
IN VARCHAR2
,p_period

In VARCHAR2)

IS
lc_curr_proc

VARCHAR2(40) := 'MAIN

';

BEGIN
g_debug := p_debug;
debug(lc_curr_proc, 'Starting HFM Load program main, Period :'||p_per
iod);
write_output('Starting HFM Load program main');
LOAD_HFM_DATA(p_period);
EXCEPTION
WHEN OTHERS THEN
write_error(lc_curr_proc,'Error in main:'||SQLCODE||' ,Error: '||SQLERRM)
;
retcode := 2;
END MAIN;
/*****************************************************************************
FUNCTION: submit_hfm_stat_actuals
DESCRIPTION: This function can be directly called from the command line.
This submits a concurrent program to ensure all
the information

is logged in the application.


*****************************************************************************
/

FUNCTION submit_hfm_stat_actuals return boolean


IS
-- Call Conc Prog ICAP_LOAD_HFM_BAL
lc_curr_proc
VARCHAR2(40) := 'submit_hfm_stat_actuals';
lc_errbuf
VARCHAR2(2000);
lc_retcode
NUMBER;
lc_debug
VARCHAR2(1) := 'Y';
lc_period_param
VARCHAR2(20);
ln_user_id
NUMBER;
ln_resp_id
NUMBER;
ln_resp_appl_id
NUMBER;
ln_req_id
NUMBER := -1;
lv_req_return_status BOOLEAN;
lv_req_phase
VARCHAR2(100);
lv_req_status
VARCHAR2(100);
lv_req_dev_phase
VARCHAR2(100);
lv_req_dev_status
VARCHAR2(100);
lv_req_message
VARCHAR2(500);
BEGIN
dbms_output.PUT_LINE('----------------------------------------------------');
--ICAP
SELECT
INTO
FROM
WHERE

user used for scheduling.


user_id
ln_user_id
fnd_user
user_name = 'ICAP';

-- dbms_output.put_line('User id for ICAP => '||ln_user_id );


--SYSADMIN resp details used for scheduling.
SELECT responsibility_id,
application_id
INTO ln_resp_id, ln_resp_appl_id
FROM fnd_responsibility_tl
WHERE responsibility_name = 'System Administrator';
-- dbms_output.put_line('responsibility_id/application_id => '||ln_resp_
id||'/'||ln_resp_appl_id );
-- Get the period name parameter from the GAA Parameters table
BEGIN
SELECT TRIM(UPPER(REPLACE(gaa_value, '_', '-')))
INTO lc_period_param
FROM apps.icap_gaa_parameters
WHERE gaa_parameter = 'PreviousPeriod';
EXCEPTION
WHEN no_data_found THEN
dbms_output.PUT_LINE('No data found for the Previous period fro
m GAA Parameters table :'
||SQLERRM);
RETURN FALSE;
END;

fnd_global.APPS_INITIALIZE(ln_user_id, ln_resp_id, ln_resp_appl_id);


/*ln_req_id := FND_REQUEST.SUBMIT_REQUEST(application => 'ICAP'
, 'ICAP_LOAD_
HPCM_DRIVERS' -- 75
73/'ICAP_LOAD_HFM_BAL'
, ''
, ''
, FALSE
, 'Y'
, lc_period_p
aram ); */
ln_req_id := fnd_request.SUBMIT_REQUEST(application => 'ICAP',
program => 'ICAP_LOAD_HFM_BAL'
-- 75
73/'ICAP_LOAD_HFM_BAL'
, argument1 => 'Y', argument2 => lc_period_para
m);
COMMIT;
IF ln_req_id <= 0 THEN
dbms_output.PUT_LINE('Error during submitting HFM Stat Actuals :'
||fnd_message.get);
ELSIF ln_req_id > 0 THEN
LOOP
lv_req_return_status := fnd_concurrent.WAIT_FOR_REQUEST (ln_re
q_id, 60, 0,
lv_req_phase,
lv_req_status,
lv_req_dev_phase,
lv_re
q_dev_status, lv_req_message
);
EXIT WHEN UPPER (lv_req_phase) = 'COMPLETED'
OR UPPER (lv_req_status) IN (
'CANCELLED', 'ERROR', 'TERMINATE
D'
);
END LOOP;
dbms_output.PUT_LINE('Concurrent Request ID generated :'
||ln_req_id);
END IF;
RETURN TRUE;
dbms_output.PUT_LINE('----------------------------------------------------');
EXCEPTION
WHEN OTHERS THEN
dbms_output.PUT_LINE('Error during submitting HFM Stat Actuals
:'
||SQLERRM);
RETURN FALSE;
END submit_hfm_stat_actuals;
end ICAP_LOAD_HFM_INT_PKG;

Das könnte Ihnen auch gefallen