The following lines contain the word 'select', 'insert', 'update' or 'delete':
/* If user views in primary global, use 1st view which SELECTs the primary amount. For secondary global
currency, use 2nd view which SELECTs secondary amount for Functional currency, use 3rd view which
SELECTs functional amount. */
IF g_currency = 'FII_GLOBAL1' THEN
g_curr_suffix := '_p_v';
SELECT nvl(min(start_date), trunc(sysdate)) INTO g_min_start_date
FROM fii_time_ent_period;
SELECT nvl(min(start_date), g_min_start_date) INTO g_curr_month_start
FROM fii_time_ent_period
WHERE g_as_of_date between start_date and END_date;
SELECT NVL(fii_time_api.pwk_end(g_as_of_date-84),g_min_start_date) INTO g_sd_prior FROM DUAL;
SELECT NVL(fii_time_api.ent_sd_lysper_end(fii_time_api.ent_sd_lysper_end(g_as_of_date)),g_min_start_date) INTO g_sd_prior_prior FROM DUAL;
SELECT NVL(fii_time_api.cwk_start(g_sd_prior), g_min_start_date) INTO g_sd_curr_sdate FROM DUAL;
SELECT NVL(fii_time_api.cwk_start(g_as_of_date), g_min_start_date) INTO g_curr_per_start FROM DUAL;
SELECT NVL(fii_time_api.cwk_end(g_as_of_date), g_min_start_date) INTO g_curr_per_end FROM DUAL;
SELECT NVL(fii_time_api.pwk_start(g_previous_asof_date), g_min_start_date) INTO g_prior_per_start FROM DUAL;
SELECT NVL(fii_time_api.pwk_end(g_previous_asof_date), g_min_start_date) INTO g_prior_per_end FROM DUAL;
SELECT NVL(fii_time_api.ent_sd_pper_end(g_as_of_date),g_min_start_date) INTO g_previous_asof_date FROM dual;
SELECT NVL(fii_time_api.ent_sd_lysper_END(g_as_of_date),g_min_start_date) INTO g_previous_asof_date FROM dual;
SELECT NVL(fii_time_api.ent_sd_lysper_end(g_as_of_date), g_min_start_date) INTO g_sd_prior FROM DUAL;
SELECT NVL(fii_time_api.ent_sd_lysper_end(g_sd_prior), g_min_start_date) INTO g_sd_prior_prior FROM DUAL;
SELECT fii_time_api.ent_cper_end(g_sd_prior)+1 INTO g_sd_curr_sdate FROM DUAL;
SELECT NVL(fii_time_api.ent_cper_start(g_as_of_date), g_min_start_date) INTO g_curr_per_start FROM DUAL;
SELECT NVL(fii_time_api.ent_cper_end(g_as_of_date), g_min_start_date) INTO g_curr_per_end FROM DUAL;
SELECT NVL(fii_time_api.ent_cper_start(g_previous_asof_date), g_min_start_date) INTO g_prior_per_start FROM DUAL;
SELECT NVL(fii_time_api.ent_cper_end(g_previous_asof_date), g_min_start_date) INTO g_prior_per_end FROM DUAL;
SELECT NVL(fii_time_api.ent_sd_pqtr_end(g_as_of_date),g_min_start_date) INTO g_previous_asof_date FROM dual;
SELECT NVL(fii_time_api.ent_sd_lysqtr_end(g_as_of_date),g_min_start_date) INTO g_previous_asof_date FROM dual;
SELECT NVL(fii_time_api.ent_sd_lysqtr_end(g_as_of_date),g_min_start_date) INTO g_sd_prior FROM dual;
SELECT NVL(fii_time_api.ent_sd_lysqtr_end(g_sd_prior),g_min_start_date) INTO g_sd_prior_prior FROM dual;
SELECT fii_time_api.ent_cqtr_end(g_sd_prior)+1 INTO g_sd_curr_sdate FROM dual;
SELECT NVL(fii_time_api.ent_cqtr_start(g_as_of_date), g_min_start_date) INTO g_curr_per_start FROM DUAL;
SELECT NVL(fii_time_api.ent_cqtr_end(g_as_of_date), g_min_start_date) INTO g_curr_per_end FROM DUAL;
SELECT NVL(fii_time_api.ent_cqtr_start(g_previous_asof_date), g_min_start_date) INTO g_prior_per_start FROM DUAL;
SELECT NVL(fii_time_api.ent_cqtr_end(g_previous_asof_date), g_min_start_date) INTO g_prior_per_end FROM DUAL;
SELECT NVL(fii_time_api.ent_pyr_end(fii_time_api.ent_pyr_end(fii_time_api.ent_pyr_end(fii_time_api.ent_pyr_end(g_as_of_date)))), g_min_start_date) INTO g_sd_prior FROM DUAL;
SELECT NVL(fii_time_api.ent_pyr_end(g_sd_prior), g_min_start_date) INTO g_sd_prior_prior FROM DUAL;
SELECT NVL(fii_time_api.ent_cyr_start(g_as_of_date), g_min_start_date) INTO g_curr_per_start FROM DUAL;
SELECT NVL(fii_time_api.ent_cyr_end(g_as_of_date), g_min_start_date) INTO g_curr_per_end FROM DUAL;
SELECT NVL(fii_time_api.ent_cyr_start(g_previous_asof_date), g_min_start_date) INTO g_prior_per_start FROM DUAL;
SELECT NVL(fii_time_api.ent_cyr_end(g_previous_asof_date), g_min_start_date) INTO g_prior_per_end FROM DUAL;
SELECT NVL(fii_time_api.ent_sd_lysper_end(g_as_of_date), g_min_start_date) INTO g_sd_prior FROM DUAL;
SELECT NVL(fii_time_api.ent_sd_lysper_end(g_sd_prior), g_min_start_date) INTO g_sd_prior_prior FROM DUAL;
SELECT fii_time_api.ent_cper_end(g_sd_prior)+1 INTO g_sd_curr_sdate FROM DUAL;
SELECT fii_ar_util_pkg.get_dso_period_profile
INTO g_dso_period
FROM dual;
SELECT dso_value INTO l_flag FROM FII_AR_DSO_SETUP WHERE dso_type = p_category;
l_dso_sql := ' SELECT dso_type,dso_value FROM FII_AR_DSO_SETUP ';
SELECT view_all_organizations_flag, business_group_id
INTO l_all_org_flag, l_business_group_id
FROM per_security_profiles
WHERE security_profile_id = g_security_profile_id;
SELECT business_group_id
INTO l_business_group_id
FROM per_security_profiles
WHERE security_profile_id = g_security_profile_id;
FUNCTION get_display_currency(p_selected_operating_unit IN VARCHAR2) RETURN VARCHAR2 IS
l_org_id NUMBER;
IF(p_selected_operating_unit <> 'ALL') then
IF (g_operating_unit is null or g_operating_unit <> p_selected_operating_unit) THEN
g_operating_unit := p_selected_operating_unit;
select currency_code
into g_functional_currency_code
from ar_system_parameters_all fsp,
gl_sets_of_books gsob
where fsp.org_id = p_selected_operating_unit
and fsp.set_of_books_id = gsob.set_of_books_id;
select distinct currency_code
into g_common_functional_currency
from ar_system_parameters_all fsp,
gl_sets_of_books gsob
where fsp.set_of_books_id = gsob.set_of_books_id
and fsp.org_id = fsp.org_id ;
select distinct currency_code
into g_common_functional_currency
from ar_system_parameters_all fsp,
gl_sets_of_books gsob
where fsp.set_of_books_id = gsob.set_of_books_id
AND fsp.org_id in (SELECT organization_id
FROM hr_operating_units
WHERE business_group_id = fii_ar_util_pkg.g_business_group_id) ;
select distinct currency_code
into g_common_functional_currency
from ar_system_parameters_all fsp,
gl_sets_of_books gsob
where fsp.set_of_books_id = gsob.set_of_books_id
AND fsp.org_id in (SELECT organization_id
FROM per_organization_list
WHERE security_profile_id = g_security_profile_id) ;
select distinct currency_code
into g_common_functional_currency
from ar_system_parameters_all fsp,
gl_sets_of_books gsob
where fsp.set_of_books_id = gsob.set_of_books_id
AND fsp.org_id = l_org_id ;
select distinct currency_code
into g_common_functional_currency
from ar_system_parameters_all fsp,
gl_sets_of_books_v gsob
where fsp.set_of_books_id = gsob.set_of_books_id
AND (
(
g_det_ou_lov=1 AND fsp.org_id = fsp.org_id
)
OR (
g_det_ou_lov=2
AND fsp.org_id in (
SELECT organization_id
FROM hr_operating_units
WHERE business_group_id = fii_ar_util_pkg.g_business_group_id
)
)
OR (
g_det_ou_lov=3
AND fsp.org_id in (
SELECT organization_id
FROM per_organization_list
WHERE security_profile_id = g_security_profile_id
)
)
OR(
g_det_ou_lov=4 AND fsp.org_id = nvl(fnd_profile.value('ORG_ID'), -1)
)
);
SELECT id INTO stmt FROM fii_currencies_v WHERE id = 'FII_GLOBAL1';
l_party_select VARCHAR2(500):=NULL;
l_org_select VARCHAR2(240):=NULL;
l_select VARCHAR2(1500):=NULL;
l_select2 VARCHAR2(1500):=NULL;
l_collector_select VARCHAR2(100):=NULL;
l_parent_select VARCHAR2(500):=NULL;
l_industry_select VARCHAR2(500):=NULL;
/* This dynamic select in the case of customer dimension is hierarchical checks if the
party chosen is leaf node. If True it gets the immediate parent_party_id from
fii_customer_hierarches.*/
IF g_is_hierarchical_flag = 'Y'
AND (g_view_by = 'CUSTOMER+FII_CUSTOMERS' or g_view_by = 'CUSTOMER+FII_CUSTOMER_ACCOUNTS')
AND (g_count_parent_party_id = 1 AND g_party_id <> '-111' ) THEN
l_parent_select := ' f.next_level_is_leaf_flag,(SELECT decode (x.next_level_is_leaf_flag,
''Y'', x.parent_party_id, f.child_party_id)
FROM fii_customer_hierarchies x
WHERE x.next_level_party_id = f.child_party_id
AND x.child_party_id = f.child_party_id
AND x.child_party_id <> x.parent_party_id) parent_party_id ';
l_parent_select := ' f.next_level_is_leaf_flag,(SELECT decode (x.next_level_is_leaf_flag,
''Y'', x.parent_party_id, f.child_party_id)
FROM fii_customer_hierarchies x
WHERE x.next_level_party_id = f.child_party_id
AND x.child_party_id = f.child_party_id
AND x.child_party_id <> x.parent_party_id) parent_party_id ';
l_parent_select := ' f.next_level_is_leaf_flag,(SELECT decode (x.next_level_is_leaf_flag,
''Y'', x.parent_party_id, f.child_party_id)
FROM fii_customer_hierarchies x
WHERE x.next_level_party_id = f.child_party_id
AND x.child_party_id = f.child_party_id
AND x.child_party_id <> x.parent_party_id) parent_party_id ';
--l_parent_select := ' f.next_level_is_leaf_flag, f.parent_party_id ';
l_parent_select := 'f.next_level_is_leaf_flag, f.parent_party_id parent_party_id ' ;
l_parent_select := 'NULL is_leaf_flag, NULL parent_party_id ' ;
party selected. In the case when only 1 party is chosen, the where clause is built to
show both parent self record and all its child parties.*/
IF g_is_hierarchical_flag = 'Y' AND g_count_parent_party_id > 1 THEN
IF g_view_by = 'ORGANIZATION+FII_OPERATING_UNITS' THEN
l_party_select := ' ,f.child_party_id child_party_id ';
l_party_select := ' ,f.child_party_id child_party_id ';
l_party_select := ' ,f.child_party_id child_party_id ';
l_party_select := ' ,f.child_party_id child_party_id ';
l_party_select := ' ,NULL child_party_id ';
l_party_select := ' ,f.child_party_id child_party_id ';
l_party_select := ' ,f.child_party_id child_party_id ';
l_party_select := ' ,NULL child_party_id ';
l_party_select := ' ,f.child_party_id child_party_id ';
l_party_select := ' ,NULL child_party_id ';
l_party_select := ' ,f.child_party_id child_party_id ';
/* Handles Org related SELECT, FROM and WHERE clause */
g_security_profile_id := fii_ar_util_pkg.get_sec_profile;
SELECT view_all_organizations_flag, business_group_id
INTO l_all_org_flag, l_business_group_id
FROM per_security_profiles
WHERE security_profile_id = g_security_profile_id;
l_org_select := ' p.organization_id, ';
l_org_from := ' ( SELECT per.organization_id,hr.name
FROM hr_operating_units per, ar_system_parameters_all ar, hr_all_organization_units hr
WHERE per.business_group_id = '||l_business_group_id ||'
AND per.organization_id = ar.org_id
AND per.organization_id = hr.organization_id '||l_org_specific_where||') p ';
l_org_from := ' (SELECT per.organization_id
FROM hr_operating_units per, ar_system_parameters_all ar
WHERE per.business_group_id = '||l_business_group_id ||'
AND per.organization_id = ar.org_id '||l_org_specific_where||') p ';
l_org_select := ' p.organization_id, ';
l_org_from := ' ( SELECT per.organization_id,hr.name
FROM hr_operating_units per, hr_all_organization_units hr
WHERE per.organization_id = hr.organization_id '||l_org_specific_where||') p ';
l_org_from := ' (SELECT per.organization_id
FROM hr_operating_units per
WHERE 1=1 '||l_org_specific_where||') p ';
l_org_select := ' p.organization_id, ';
l_org_from := ' ( SELECT per.organization_id,hr.name
FROM per_organization_list per, ar_system_parameters_all ar, hr_all_organization_units hr
WHERE per.security_profile_id = '||g_security_profile_id||'
AND per.organization_id = ar.org_id
AND per.organization_id = hr.organization_id '||l_org_specific_where||') p ';
l_org_from := ' (SELECT organization_id
FROM per_organization_list per, ar_system_parameters_all ar
WHERE per.security_profile_id = '||g_security_profile_id ||'
AND per.organization_id = ar.org_id '||l_org_specific_where||') p ';
l_org_select := g_security_org_id||' organization_id, ';
l_org_select := '-1 organization_id, ';
l_org_from := ' (SELECT organization_id, name
FROM hr_all_organization_units
WHERE organization_id ='||g_security_org_id||') p ';
l_org_select := '-1 organization_id, ';
l_org_from :=' (SELECT organization_id, name
FROM hr_all_organization_units
WHERE organization_id =-1) p ';
/* Handles the select clause for Collectors */
IF g_view_by = 'FII_COLLECTOR+FII_COLLECTOR' THEN
l_collector_select := ' c.collector_id, ';
l_collector_where := ' exists (select ''x''
from fii_collectors hz
where hz.collector_id = c.collector_id
and hz.party_id = f.child_party_id) ';
l_collector_where := ' exists (select ''x''
from fii_collectors hz
where hz.collector_id = c.collector_id '||
case when g_party_id <> '-111' then 'AND hz.party_id = f.child_party_id' else '' end||') ';
l_collector_select := NULL;
l_collector_select := ' NULL collector_id, ';
l_collector_select := g_collector_id||' collector_id, ';
l_industry_select := ' hz.class_code class_code, hz.class_category class_category, ';
l_industry_select := ' c.class_code class_code, c.class_category class_category, ';
l_industry_where := ' exists (select ''x''
from fii_party_mkt_class hz
where hz.class_code = c.class_code
and hz.party_id = f.child_party_id) ';
l_industry_select := ' NULL class_code, NULL class_category, ';
l_industry_select := ' '||g_industry_id||', '''||g_industry_class_type||''', ';
l_industry_select := ' '||g_industry_id||' class_code, '||''''||g_industry_class_type||''''||' class_category,';
/* Code for appending comma, WHERE, AND, GROUP BY clauses to the dynamic SELECT clause */
IF l_party_from IS NOT NULL AND l_org_from IS NOT NULL THEN
l_org_from := ','||l_org_from;
l_select := ' SELECT '||l_parent_select||l_party_select||', '
||l_org_select||l_collector_select||l_industry_select||
' hz.party_name view_by FROM '||l_party_from||l_org_from||l_party_where||
l_party_group_by||l_parent_group_by||l_org_group_by;
l_select := 'SELECT '||l_parent_select||l_party_select||', '
||l_org_select||l_collector_select||l_industry_select||
' case when f.parent_party_id = hz.party_id
and f.next_level_is_leaf_flag <> ''Y''
then hz.party_name||'' '||g_self_msg||
''' else hz.party_name end view_by,
hz.party_id viewby_code,
case when f.parent_party_id = hz.party_id
and f.next_level_is_leaf_flag <> ''Y''
then ''Y''
else ''N'' end is_self_flag FROM '||l_party_from||l_org_from||l_industry_from||l_party_where||l_industry_where||
l_party_group_by||l_parent_group_by||l_org_group_by||l_industry_group_by;
l_select := ' SELECT '||l_parent_select||l_party_select||', '||l_org_select||l_collector_select||l_industry_select||' c.class_name view_by,
c.class_code viewby_code, null is_self_flag FROM '||l_party_from||l_org_from||l_industry_from||l_party_where||l_industry_where||
l_party_group_by||l_org_group_by||l_parent_group_by;
l_select := ' SELECT '||l_parent_select||l_party_select||', '||l_org_select||l_collector_select||l_industry_select||
' p.name viewby, p.organization_id viewby_code, null is_self_flag FROM '||l_party_from||l_org_from||l_party_where||l_party_group_by||l_parent_group_by;
l_select := ' SELECT '||l_parent_select||l_party_select||', '
||l_org_select||l_collector_select||l_industry_select||' c.name view_by,
c.collector_id viewby_code, null is_self_flag FROM '||l_party_from||l_org_from||l_party_where||l_collector_where||
l_party_group_by||l_org_group_by||l_parent_group_by;
SELECT COUNT(*) INTO l_table_count
FROM all_tables
WHERE table_name = 'FII_AR_DEBUG_STATEMENTS'
and owner = l_schema_name;
EXECUTE IMMEDIATE 'DELETE FROM '||l_schema_name||'.FII_AR_DEBUG_STATEMENTS WHERE REGION_CODE = '''||g_region_code||''' AND SESSION_ID = '||g_session_id;
EXECUTE IMMEDIATE 'INSERT INTO '||l_schema_name||'.FII_AR_DEBUG_STATEMENTS (package,
procedure,
session_id,
region_code,
sql_statement,
value)
VALUES (''FII_AR_UTIL_PKG'',
''POPULATE_SUMMARY_GT_TABLES'',
'||g_session_id||','''||g_region_code||''' ,
''l_select'',
'''||REPLACE(l_select, '''', '''''')||''')';
EXECUTE IMMEDIATE l_select BULK COLLECT INTO tbl_is_leaf_flag, tbl_parent_party_id, tbl_party_id,
tbl_org_id, tbl_collector_id, tbl_class_code, tbl_class_category, tbl_view_by, tbl_viewby_code, tbl_is_self_flag;
INSERT INTO fii_ar_summary_gt (parent_party_id, party_id, org_id, collector_id, viewby, viewby_code, is_leaf_flag, class_code, class_category, is_self_flag)
VALUES
(tbl_parent_party_id(i), tbl_party_id(i), tbl_org_id(i), tbl_collector_id(i),
tbl_view_by(i), tbl_viewby_code(i), tbl_is_leaf_flag(i), tbl_class_code(i), tbl_class_category(i), tbl_is_self_flag(i));
EXECUTE IMMEDIATE 'INSERT INTO FII_AR_SUMMARY_GT
(is_leaf_flag, parent_party_id, party_id, org_id, collector_id, class_code, class_category, viewby, viewby_code, is_self_flag) '
|| l_select;
l_select2 := 'SELECT ''Y'' is_leaf_flag, -999 parent_party_id, -2 party_id, '
||l_org_select||l_collector_select||' -1 class_code, '''||g_industry_class_type||''', '||
' '''||l_unid_message||''' view_by,
-2 viewby_code,
''N'' is_self_flag FROM '|| LTRIM(l_org_from, ',');
l_select2 := 'SELECT ''Y'' is_leaf_flag, -999 parent_party_id, -2 party_id, '
||l_org_select||l_collector_select||' -1 class_code, '''||g_industry_class_type||''', '||
' '''||l_unid_message||''' view_by,
-2 viewby_code,
''N'' is_self_flag FROM dual';
EXECUTE IMMEDIATE l_select2 BULK COLLECT INTO tbl_is_leaf_flag, tbl_parent_party_id, tbl_party_id,
tbl_org_id, tbl_collector_id, tbl_class_code, tbl_class_category, tbl_view_by, tbl_viewby_code, tbl_is_self_flag;
INSERT INTO fii_ar_summary_gt (parent_party_id, party_id, org_id, collector_id, class_code, class_category, viewby, viewby_code, is_leaf_flag, is_self_flag)
VALUES
(tbl_parent_party_id(i), tbl_party_id(i), tbl_org_id(i), tbl_collector_id(i), tbl_class_code(i), tbl_class_category(i),
tbl_view_by(i), tbl_viewby_code(i), tbl_is_leaf_flag(i), tbl_is_self_flag(i));
EXECUTE IMMEDIATE 'INSERT INTO FII_AR_SUMMARY_GT
(is_leaf_flag, parent_party_id, party_id, org_id, collector_id, class_code, class_category, viewby, viewby_code, is_self_flag) '
|| l_select2;
l_select2 := 'SELECT null is_leaf_flag, null parent_party_id, '||case when g_party_id = '-2' then '-2' else 'null' end||' party_id, '
||l_org_select||' -1 collector_id, '||l_industry_select||
' '''||l_unid_message||''' view_by,
-1 viewby_code,
null is_self_flag FROM '|| LTRIM(l_org_from, ',');
l_select2 := 'SELECT null is_leaf_flag, null parent_party_id, '||case when g_party_id = '-2' then '-2' else 'null' end||' party_id, '
||l_org_select||' -1 collector_id, '||l_industry_select||
' '''||l_unid_message||''' view_by,
-1 viewby_code,
null is_self_flag FROM dual';
EXECUTE IMMEDIATE l_select2 BULK COLLECT INTO tbl_is_leaf_flag, tbl_parent_party_id, tbl_party_id,
tbl_org_id, tbl_collector_id, tbl_class_code, tbl_class_category, tbl_view_by, tbl_viewby_code, tbl_is_self_flag;
INSERT INTO fii_ar_summary_gt (parent_party_id, party_id, org_id, collector_id, class_code, class_category, viewby, viewby_code, is_leaf_flag, is_self_flag)
VALUES
(tbl_parent_party_id(i), tbl_party_id(i), tbl_org_id(i), tbl_collector_id(i), tbl_class_code(i), tbl_class_category(i),
tbl_view_by(i), tbl_viewby_code(i), tbl_is_leaf_flag(i), tbl_is_self_flag(i));
EXECUTE IMMEDIATE 'INSERT INTO FII_AR_SUMMARY_GT
(is_leaf_flag, parent_party_id, party_id, org_id, collector_id, class_code, class_category, viewby, viewby_code, is_self_flag) '
|| l_select2;
l_select2 := 'SELECT ''Y'' is_leaf_flag, -999 parent_party_id, -2 party_id, '
||l_org_select||l_collector_select||' -1 class_code, '''||g_industry_class_type||''', '||
' '''||l_unid_message||''' view_by,
-2 viewby_code,
''N'' is_self_flag FROM '|| LTRIM(l_org_from, ',');
l_select2 := 'SELECT ''Y'' is_leaf_flag, -999 parent_party_id, -2 party_id, '
||l_org_select||l_collector_select||' -1 class_code, '''||g_industry_class_type||''', '||
' '''||l_unid_message||''' view_by,
-2 viewby_code,
''N'' is_self_flag FROM dual';
EXECUTE IMMEDIATE l_select2 BULK COLLECT INTO tbl_is_leaf_flag, tbl_parent_party_id, tbl_party_id,
tbl_org_id, tbl_collector_id, tbl_class_code, tbl_class_category, tbl_view_by, tbl_viewby_code, tbl_is_self_flag;
INSERT INTO fii_ar_summary_gt (parent_party_id, party_id, org_id, collector_id, class_code, class_category, viewby, viewby_code, is_leaf_flag, is_self_flag)
VALUES
(tbl_parent_party_id(i), tbl_party_id(i), tbl_org_id(i), tbl_collector_id(i), tbl_class_code(i), tbl_class_category(i),
tbl_view_by(i), tbl_viewby_code(i), tbl_is_leaf_flag(i), tbl_is_self_flag(i));
EXECUTE IMMEDIATE 'INSERT INTO FII_AR_SUMMARY_GT
(is_leaf_flag, parent_party_id, party_id, org_id, collector_id, class_code, class_category, viewby, viewby_code, is_self_flag) '
|| l_select2;
insert_into_debug_table;
EXECUTE IMMEDIATE 'INSERT INTO '||l_schema_name||'.FII_AR_DEBUG_STATEMENTS (package,
procedure,
session_id,
region_code,
sql_statement,
value)
VALUES (''FII_AR_UTIL_PKG'',
''POPULATE_SUMMARY_GT_TABLES'',
'||g_session_id||','''||g_region_code||''' ,
''l_select2'',
'''||REPLACE(l_select2, '''', '''''')||''')';
PROCEDURE insert_into_debug_table IS
/* logic for this api...
1. We first search for existence of debug table. If it doesn't exist, we create it else we delete the records inserted for the same session_id and region code.
2. We then insert all columns of corresponding gt table + session_id and report_region_code into debug tables.
*/
l_table_count NUMBER := 0;
SELECT COUNT(*) INTO l_table_count
FROM all_tables
WHERE table_name = 'FII_AR_DEBUG_SUMMARY'
and owner = l_schema_name;
EXECUTE IMMEDIATE 'DELETE FROM '||l_schema_name||'.FII_AR_DEBUG_SUMMARY WHERE REGION_CODE = '''||g_region_code||''' AND SESSION_ID = '||g_session_id;
EXECUTE IMMEDIATE 'INSERT INTO '||l_schema_name||'.FII_AR_DEBUG_SUMMARY (PARENT_PARTY_ID,
PARTY_ID,
ORG_ID,
COLLECTOR_ID,
IS_LEAF_FLAG,
IS_SELF_FLAG,
CLASS_CODE,
CLASS_CATEGORY,
VIEWBY,
VIEWBY_CODE,
SESSION_ID,
REGION_CODE)
SELECT gt.PARENT_PARTY_ID,
gt.PARTY_ID,
gt.ORG_ID,
gt.COLLECTOR_ID,
gt.IS_LEAF_FLAG,
gt.IS_SELF_FLAG,
gt.CLASS_CODE,
gt.CLASS_CATEGORY,
gt.VIEWBY,
gt.VIEWBY_CODE,
'||g_session_id||','''||g_region_code||'''
FROM fii_ar_summary_gt gt';
END insert_into_debug_table;
l_select VARCHAR2(10000);
SELECT INSTR(g_party_id,',', 1, l_occur) into l_position FROM DUAL;
SELECT LENGTH(g_party_id) INTO l_str_length FROM DUAL;
SELECT SUBSTR(g_party_id, l_substr_start, l_substr_val) into l_tmp_party_id FROM DUAL;
l_select := ' SELECT parent_party_id FROM fii_customer_hierarchies p
WHERE p.parent_party_id=p.next_level_party_id
AND p.next_level_party_id = p.child_party_id
AND p.child_party_id IN ('||l_parse_party_id||')
AND NOT EXISTS (SELECT c.child_party_id FROM fii_customer_hierarchies c
WHERE c.child_party_id IN ('||l_parse_party_id||')
AND c.parent_party_id IN ('||l_parse_party_id||')
AND c.parent_party_id <> c.next_level_party_id
and c.child_party_id = p.child_party_id) ';
EXECUTE IMMEDIATE l_select BULK COLLECT INTO tbl_parent_party_id;
select nvl(last_refresh_date,sysdate) INTO g_page_refresh_date
from bis_obj_properties
where object_name = 'FII_AR_STATUS_DASHBOARD'
and object_type = 'PAGE';