The following lines contain the word 'select', 'insert', 'update' or 'delete':
/* The following procedure initializes the global variable run_id which distinguishes records inserted into the temporary table by each session*/
procedure set_runid is
BEGIN
select psp_ls_runid_s.nextval into global_run_id
from dual;
/* this procedure deletes all the records that have been inserted into the temp table in that session*/
procedure clear_table (event VARCHAR2)is
BEGIN
delete from psp_matrix_driver
where run_id = global_run_id;
select count(*) into v_count1 from psp_schedule_lines
where schedule_begin_date = dat(start_period+n+1)
and schedule_hierarchy_id = s_id;
select count(*) into v_count1 from psp_schedule_lines
where schedule_begin_date = dat(start_period+n)
and schedule_hierarchy_id = s_id;
select count(*) into v_count2 from psp_schedule_lines
where schedule_begin_date = dat(start_period+n+1)
and schedule_hierarchy_id = s_id;
select count(*) into v_count3 from psp_schedule_lines
where schedule_end_date = dat(start_period+n)
and schedule_hierarchy_id = s_id;
select count(*) into v_count4 from psp_schedule_lines
where schedule_end_date = dat(start_period+n+1)
and schedule_hierarchy_id = s_id;
select sum(PERIOD_SCHEDULE_PERCENT)
into total
from psp_matrix_driver
where run_id = global_run_id
and period_start_date = st_date
and period_end_date = schedule_chunk.schedule_end_date(start_period+n+1);
dat.DELETE;
dat1.DELETE;
type_dat.DELETE;
schedule_chunk.schedule_end_date.delete; -- Commented for bug fix 4511249
schedule_chunk.schedule_begin_date.delete; -- Commented for bug fix 4511249
/* After the sort it inserts the dates into pl/sql table thereby forming distinct periods of consistent charging instructions. */
/*Once the pl/sql table is loaded, the start and end dates of the distinct periods are inserted into the temp table. */
/*As the cursor parses through each record a correponding schedule percentage is inserted according to the overlap of these distinct periods with the periods specified on each schedule line*/
procedure load_table(sch_id number) is
CURSOR sched_lines(s_id NUMBER) IS
SELECT schedule_line_id l_id,
schedule_begin_date sbd,
schedule_end_date sed,
schedule_percent sp
FROM psp_schedule_lines
WHERE schedule_hierarchy_id = s_id;
SELECT schedule_begin_date dat , 'B'
FROM psp_schedule_lines
WHERE schedule_hierarchy_id = s_id
UNION
SELECT schedule_end_date dat , 'E'
FROM psp_schedule_lines
WHERE schedule_hierarchy_id = s_id
ORDER BY 1, 2 ;
insert into psp_matrix_driver(RUN_ID,
SCHEDULE_LINE_ID,
PERIOD_START_DATE,
PERIOD_END_DATE,
PERIOD_SCHEDULE_PERCENT) values
(global_run_id,
sch_rec.l_id,
dat(i),
dat(i+1),
per);
INSERT INTO psp_matrix_driver
(RUN_ID, SCHEDULE_LINE_ID,
PERIOD_START_DATE,
PERIOD_END_DATE,
PERIOD_SCHEDULE_PERCENT)
SELECT global_run_id, schedule_line_id,
schedule_chunk.schedule_begin_date(rowno),
schedule_chunk.schedule_end_date(rowno),
schedule_percent
FROM psp_schedule_lines psl
WHERE schedule_hierarchy_id = sch_id
AND psl.schedule_begin_date <= schedule_chunk.schedule_end_date(rowno)
AND psl.schedule_end_date >= schedule_chunk.schedule_begin_date(rowno);
INSERT INTO psp_matrix_driver
(RUN_ID, SCHEDULE_LINE_ID,
PERIOD_START_DATE,
PERIOD_END_DATE,
PERIOD_SCHEDULE_PERCENT)
SELECT global_run_id, schedule_line_id,
schedule_chunk.schedule_begin_date(rowno),
schedule_chunk.schedule_end_date(rowno),
0
FROM psp_schedule_lines psl
WHERE schedule_hierarchy_id = sch_id
AND (psl.schedule_begin_date > schedule_chunk.schedule_end_date(rowno)
OR psl.schedule_end_date < schedule_chunk.schedule_begin_date(rowno));
SELECT max(ptp.end_date)
FROM per_time_periods ptp
WHERE (ptp.time_period_id,payroll_id) in (SELECT MAX(ppc.time_period_id),ppc.payroll_id
FROM psp_payroll_controls ppc ,
psp_payroll_lines ppl -- Introduced for Bug 4511249
-- WHERE ppc.payroll_id = p_payroll_id Commented for Bug 4511249
WHERE ppc.payroll_control_id = ppl.payroll_control_id
AND ppl.assignment_id = p_assignment_id
AND ppc.source_type IN ('O','N')
group by ppc.payroll_id);
SELECT sum(PERIOD_SCHEDULE_PERCENT)
FROM psp_matrix_driver
WHERE run_id = global_run_id
AND period_end_date > TRUNC ( NVL ( l_payroll_end_date,fnd_date.canonical_to_date('1900/01/01')))-- added this and conditoin for bug 2836176
GROUP BY period_start_date , period_end_date;
select sum(PERIOD_SCHEDULE_PERCENT)
from psp_matrix_driver
where run_id = global_run_id
group by PERIOD_START_DATE, PERIOD_END_DATE;
for all those persons who are employees for the selected organizations.
The procedure finds all the schedule hierarchies and internally calls the load_table function to load
the corresponding schedule lines */
PROCEDURE load_organizations (retcode OUT NOCOPY NUMBER,
p_organization_id IN VARCHAR2,
p_period_from IN DATE,
p_period_to IN DATE,
p_report_type IN VARCHAR2,
p_business_group_id IN NUMBER,
p_set_of_books_id IN NUMBER) IS
CURSOR sch_hier_cur(v_organization_id NUMBER) IS
SELECT distinct psh.schedule_hierarchy_id
FROM psp_schedule_hierarchy psh,
psp_schedule_lines psl,
per_assignments_f paf
WHERE psh.schedule_hierarchy_id = psl.schedule_hierarchy_id
AND paf.assignment_id = psh.assignment_id
AND paf.organization_id = v_organization_id
AND psl.schedule_begin_date <= p_period_to
AND psl.schedule_end_date >= p_period_from
AND psl.business_group_id = p_business_group_id
AND psl.set_of_books_id = p_set_of_books_id
-- Included the following condition for bug fix 2020596 to prevent duplicate import of schedule data
-- for assignments that are assigned to more than one organization
AND NOT EXISTS (SELECT 1 FROM psp_matrix_driver pmd
WHERE pmd.run_id = global_run_id
AND pmd.schedule_line_id = psl.schedule_line_id);
SELECT schedule_line_id l_id,
schedule_begin_date sbd,
schedule_end_date sed,
schedule_percent sp
FROM psp_schedule_lines
WHERE schedule_hierarchy_id = schedule_hierarchy_id
AND schedule_end_date >= p_period_from
AND schedule_begin_date <= p_period_to;
SELECT schedule_begin_date dat , 'B'
FROM psp_schedule_lines
WHERE schedule_hierarchy_id = p_schedule_hierarchy_id
AND schedule_end_date >= p_period_from
AND schedule_begin_date <= p_period_to
UNION
SELECT schedule_end_date dat , 'E'
FROM psp_schedule_lines
WHERE schedule_hierarchy_id = p_schedule_hierarchy_id
AND schedule_end_date >= p_period_from
AND schedule_begin_date <= p_period_to
ORDER BY 1, 2 ;
SELECT distinct paf.organization_id
FROM psp_schedule_hierarchy psh,
psp_schedule_lines psl,
per_assignments_f paf
WHERE psh.schedule_hierarchy_id = psl.schedule_hierarchy_id
AND paf.assignment_id = psh.assignment_id
AND psl.schedule_begin_date <= p_period_to
AND psl.schedule_end_date >= p_period_from
AND psl.business_group_id = p_business_group_id
AND psl.set_of_books_id = p_set_of_books_id;
INSERT INTO psp_matrix_driver
(RUN_ID, SCHEDULE_LINE_ID,
PERIOD_START_DATE,
PERIOD_END_DATE,
PERIOD_SCHEDULE_PERCENT)
SELECT global_run_id, schedule_line_id,
GREATEST(p_period_from, schedule_chunk.schedule_begin_date(rowno)),
LEAST(p_period_to, schedule_chunk.schedule_end_date(rowno)),
schedule_percent
FROM psp_schedule_lines psl
WHERE schedule_hierarchy_id = sch_hier_rec.schedule_hierarchy_id
AND psl.schedule_begin_date <= p_period_to
AND psl.schedule_end_date >= p_period_from
AND psl.schedule_begin_date <= schedule_chunk.schedule_end_date(rowno)
AND psl.schedule_end_date >= schedule_chunk.schedule_begin_date(rowno);
dat.delete;
type_dat.delete;
schedule_chunk.schedule_end_date.delete;
schedule_chunk.schedule_begin_date.delete;
INSERT INTO psp_matrix_driver
(RUN_ID, SCHEDULE_LINE_ID,
PERIOD_START_DATE,
PERIOD_END_DATE,
PERIOD_SCHEDULE_PERCENT)
SELECT global_run_id, schedule_line_id,
GREATEST(p_period_from, schedule_chunk.schedule_begin_date(rowno)),
LEAST(p_period_to, schedule_chunk.schedule_end_date(rowno)),
schedule_percent
FROM psp_schedule_lines psl
WHERE schedule_hierarchy_id = sch_hier_rec.schedule_hierarchy_id
AND psl.schedule_begin_date <= p_period_to
AND psl.schedule_end_date >= p_period_from
AND psl.schedule_begin_date <= schedule_chunk.schedule_end_date(rowno)
AND psl.schedule_end_date >= schedule_chunk.schedule_begin_date(rowno);
dat.delete;
type_dat.delete;
schedule_chunk.schedule_end_date.delete;
schedule_chunk.schedule_begin_date.delete;
DELETE psp_matrix_driver pmd
WHERE run_id = global_run_id
AND period_schedule_percent = 0;
UPDATE psp_matrix_driver pmd
SET period_start_date = period_start_date + 1
WHERE run_id = global_run_id
AND EXISTS (SELECT 1
FROM psp_schedule_lines psl,
psp_schedule_lines psl2
WHERE psl.schedule_line_id = pmd.schedule_line_id
AND psl2.schedule_hierarchy_id = psl.schedule_hierarchy_id
AND psl2.schedule_end_date = pmd.period_start_date
AND psl2.schedule_line_id <> psl.schedule_line_id);
UPDATE psp_matrix_driver pmd
SET period_end_date = period_end_date - 1
WHERE run_id = global_run_id
AND EXISTS (SELECT 1
FROM psp_schedule_lines psl,
psp_schedule_lines psl2
WHERE psl.schedule_line_id = pmd.schedule_line_id
AND psl2.schedule_hierarchy_id = psl.schedule_hierarchy_id
AND psl2.schedule_begin_date = pmd.period_end_date
AND psl2.schedule_line_id <> psl.schedule_line_id);
UPDATE psp_matrix_driver pmd
SET period_end_date = period_end_date - 1
WHERE run_id = global_run_id
AND period_start_date < period_end_date
AND period_start_date = (SELECT MIN(psl1.schedule_begin_date)
FROM psp_schedule_lines psl1
WHERE psl1.schedule_hierarchy_id = (SELECT psl2.schedule_hierarchy_id
FROM psp_schedule_lines psl2
WHERE psl2.schedule_line_id = pmd.schedule_line_id))
AND EXISTS (SELECT 1
FROM psp_schedule_lines psl1
WHERE psl1.schedule_line_id <> pmd.schedule_line_id
AND psl1.schedule_begin_date = pmd.period_end_date
AND psl1.schedule_hierarchy_id = (SELECT psl2.schedule_hierarchy_id
FROM psp_schedule_lines psl2
WHERE psl2.schedule_line_id = pmd.schedule_line_id));
UPDATE psp_matrix_driver pmd
SET period_end_date = period_end_date - 1
WHERE run_id = global_run_id
AND period_start_date < period_end_date
AND NOT (NOT EXISTS (SELECT 1
FROM psp_schedule_lines psl1
WHERE psl1.schedule_line_id <> pmd.schedule_line_id
AND psl1.schedule_begin_date = pmd.period_end_date
AND psl1.schedule_hierarchy_id = (SELECT psl2.schedule_hierarchy_id
FROM psp_schedule_lines psl2
where psl2.schedule_line_id = pmd.schedule_line_id))
AND EXISTS (SELECT 1
FROM psp_schedule_lines psl1
WHERE psl1.schedule_end_date = pmd.period_end_date
AND psl1.schedule_hierarchy_id = (SELECT psl2.schedule_hierarchy_id
FROM psp_schedule_lines psl2
WHERE psl2.schedule_line_id = pmd.schedule_line_id)))
AND period_start_date <> (SELECT MIN(psl1.schedule_begin_date)
FROM psp_schedule_lines psl1
WHERE psl1.schedule_hierarchy_id = (SELECT psl2.schedule_hierarchy_id
FROM psp_schedule_lines psl2
WHERE psl2.schedule_line_id = pmd.schedule_line_id));
UPDATE psp_matrix_driver pmd
SET period_start_date = period_start_date + 1
WHERE run_id = global_run_id
AND period_start_date < period_end_date
AND NOT EXISTS (SELECT 1
FROM psp_schedule_lines psl1
WHERE psl1.schedule_begin_date = pmd.period_start_date
AND psl1.schedule_hierarchy_id = (SELECT psl2.schedule_hierarchy_id
FROM psp_schedule_lines psl2
WHERE psl2.schedule_line_id = pmd.schedule_line_id))
AND period_start_date <> (SELECT MIN(psl1.schedule_begin_date)
FROM psp_schedule_lines psl1
WHERE psl1.schedule_hierarchy_id = (SELECT psl2.schedule_hierarchy_id
FROM psp_schedule_lines psl2
WHERE psl2.schedule_line_id = pmd.schedule_line_id));
UPDATE psp_matrix_driver pmd
SET period_start_date = period_start_date + 1
WHERE run_id = global_run_id
AND period_start_date < period_end_date
AND EXISTS (SELECT 1
FROM psp_schedule_lines psl1
WHERE psl1.schedule_begin_date = pmd.period_start_date
AND psl1.schedule_hierarchy_id = (SELECT psl2.schedule_hierarchy_id
FROM psp_schedule_lines psl2
WHERE psl2.schedule_line_id = pmd.schedule_line_id))
AND EXISTS (SELECT 1
FROM psp_schedule_lines psl1
WHERE psl1.schedule_line_id <> pmd.schedule_line_id
AND psl1.schedule_end_date = pmd.period_start_date
AND psl1.schedule_hierarchy_id = (SELECT psl2.schedule_hierarchy_id
FROM psp_schedule_lines psl2
WHERE psl2.schedule_line_id = pmd.schedule_line_id))
AND period_start_date <> (SELECT MIN(psl1.schedule_begin_date)
FROM psp_schedule_lines psl1
WHERE psl1.schedule_hierarchy_id = (SELECT psl2.schedule_hierarchy_id
FROM psp_schedule_lines psl2
WHERE psl2.schedule_line_id = pmd.schedule_line_id));
DELETE psp_matrix_driver pmd
WHERE run_id = global_run_id
AND EXISTS (SELECT 1
FROM psp_schedule_lines psl,
psp_schedule_lines psl2
WHERE psl2.schedule_hierarchy_id = psl.schedule_hierarchy_id
AND psl.schedule_line_id = pmd.schedule_line_id
AND psl2.schedule_begin_date <= pmd.period_end_date
AND psl2.schedule_end_date >= pmd.period_start_date
GROUP BY psl2.schedule_hierarchy_id
HAVING SUM(psl2.schedule_percent) = 100);
UPDATE psp_matrix_driver
SET period_end_date = p_period_to
WHERE run_id = global_run_id
AND period_end_date > p_period_to;
UPDATE psp_matrix_driver
SET period_start_date = p_period_from
WHERE run_id = global_run_id
AND period_start_date < p_period_from;
X=30:Updates the period_start_date of the schedule_lines in matrix_driver table
,for each organization,except the schedule lines with minimum period_start_date
so that data in the table becomes as required for the report PSPLSODR.rdf
X=40:Deletes the schedule lines with zero schedule percent for that run_id.
X=50:Checks if the user has asked for an Exception report. If yes, then it deletes
for a particular organization and particular period_start_date,period_end_date ,
all those schedule lines whose sum of period_schedule_percent equals 100
Know limitations, enhancements or remarks
Change History
Who When What
Lveerubh 05-SEP-2001 Created the procedure
Lveerubh 03-OCT-2001 1. Removing the call for the report from the package -Bug 2022193
***************************************************************/
procedure load_org_schedule(p_return_status OUT NOCOPY NUMBER,
p_log_message OUT NOCOPY VARCHAR2,
p_list_organization_id IN VARCHAR2,
p_period_from IN VARCHAR2,
p_period_to IN VARCHAR2,
p_report_type IN VARCHAR2,
p_business_group_id IN NUMBER,
p_set_of_books_id IN NUMBER
)
IS
CURSOR c_schedule_percent(F_run_id NUMBER)
IS
SELECT pdls.organization_id,
pmd.period_start_date,
pmd.period_end_date
FROM psp_default_labor_schedules pdls,
psp_matrix_driver pmd
WHERE pdls.org_schedule_id = pmd.schedule_line_id
AND pmd.run_id = F_run_id
GROUP BY pdls.organization_id,
pmd.period_start_date,
pmd.period_end_date
HAVING SUM(pmd.period_schedule_percent) = 100;
SELECT pdls.org_schedule_id
FROM psp_default_labor_schedules pdls,
psp_matrix_driver pmd
WHERE pdls.organization_id = F_organization_id
AND pdls.schedule_begin_date <= F_period_end_date
AND pdls.schedule_end_date >= F_period_start_date
AND pmd.schedule_line_id = pdls.org_Schedule_id
AND pmd.run_id = F_run_id;
SELECT min(pmd1.period_start_date) period_start_date,
pdls.organization_id
FROM psp_matrix_driver pmd1,
psp_default_labor_schedules pdls
WHERE pmd1.run_id = F_run_id
AND pmd1.schedule_line_id = pdls.org_schedule_id
GROUP BY pdls.organization_id;
SELECT distinct organization_id
FROM psp_default_labor_schedules
WHERE business_group_id = p_business_group_id
AND set_of_books_id = p_set_of_books_id;
UPDATE psp_matrix_driver pmd
SET period_start_date = period_start_date + 1
WHERE run_id =l_run_id
AND EXISTS (SELECT 1
FROM psp_default_labor_schedules pdls1,
psp_default_labor_schedules pdls2
WHERE pdls1.org_schedule_id=pmd.schedule_line_id
AND pdls1.organization_id=pdls2.organization_id
AND pdls1.org_schedule_id<>pdls2.org_schedule_id
AND pdls2.schedule_end_date=pmd.period_start_date);
UPDATE psp_matrix_driver pmd
SET period_end_date = period_end_date - 1
WHERE run_id =l_run_id
AND EXISTS (SELECT pmd.period_end_date
FROM psp_default_labor_schedules pdls1,
psp_default_labor_schedules pdls2
WHERE pdls1.org_schedule_id=pmd.schedule_line_id
AND pdls2.organization_id=pdls1.organization_id
AND pdls2.schedule_begin_date=pmd.period_end_date
AND pdls1.org_schedule_id<>pdls2.org_schedule_id);
DELETE psp_matrix_driver
WHERE run_id = global_run_id
AND period_schedule_percent = 0;
DELETE psp_matrix_driver pmd
WHERE pmd.run_id = l_run_id
And pmd.schedule_line_id = rec_sch_line_id.org_schedule_id
And pmd.period_start_date = rec_sch_percent.period_start_date
And pmd.period_end_date = rec_sch_percent.period_end_date;
UPDATE psp_matrix_driver
SET period_end_date = p_period_to
WHERE run_id = l_run_id
AND period_end_date > p_period_to;
UPDATE psp_matrix_driver
SET period_start_date = p_period_from
WHERE run_id = l_run_id
AND period_start_date < p_period_from;
specified on the various schedule lines. After the sort it inserts the dates into
pl/sql table thereby forming distinct periods of consistent charging instructions.
Once the pl/sql table is loaded, the start and end dates of the distinct periods are
inserted into the temp table.As the cursor parses through each record a correponding
schedule percentage is inserted according to the overlap of these distinct periods with
the periods specified on each schedule line
Know limitations, enhancements or remarks
Change History
Who When What
Lveerubh 05-SEP-2001 Created the procedure
***************************************************************/
PROCEDURE load_table_schedule(sch_id NUMBER,
p_business_group_id NUMBER,
p_set_of_books_id NUMBER)
IS
CURSOR sched_lines(s_id NUMBER)
IS
SELECT org_schedule_id l_id,
schedule_begin_date sbd,
schedule_end_date sed,
schedule_percent sp
FROM psp_default_labor_schedules
WHERE organization_id = s_id
AND business_group_id = p_business_group_id
AND set_of_books_id = p_set_of_books_id;
SELECT schedule_begin_date dat , 'B'
FROM psp_default_labor_schedules
WHERE organization_id = s_id
AND business_group_id = p_business_group_id
AND set_of_books_id = p_set_of_books_id
UNION
SELECT schedule_end_date dat , 'E'
FROM psp_default_labor_schedules
WHERE organization_id = s_id
AND business_group_id = p_business_group_id
AND set_of_books_id = p_set_of_books_id
ORDER BY 1, 2 ;
INSERT INTO psp_matrix_driver(RUN_ID,
SCHEDULE_LINE_ID,
PERIOD_START_DATE,
PERIOD_END_DATE,
PERIOD_SCHEDULE_PERCENT) values
(global_run_id,
sch_rec.l_id,
dat(i),
dat(i+1),
per);
SELECT schedule_hierarchy_id
FROM psp_schedule_hierarchy
WHERE assignment_id = p_assignment_id;