Вы находитесь на странице: 1из 42

create or replace

PACKAGE BODY xx_per_positions_pkg IS


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

Name:xx_per_positions_pkg
Description:This Package has all the procedures used for import of Positions
Author:TCS
Date:10/08/2007 4:54:25 PM
History
Modified By Date Description
T
*****************************************************************************/
/*======================================================================
Validating mandatory columns
=========================================================================*/
PROCEDURE xx_per_positions_prc(p_request_id IN NUMBER, p_commit IN VARCHAR2
) IS
l_org_id NUMBER;
l_grade_id NUMBER;
l_position_id NUMBER;
l_effective_start_date DATE;
l_effective_end_date DATE;
l_position_definition_id NUMBER;
l_object_version_number NUMBER;
l_security_profile_id NUMBER;
l_language_code VARCHAR2(30);
l_name VARCHAR2(240);
l_status VARCHAR2(100);
l_valid_grade_id NUMBER;
l_count NUMBER;
l_read NUMBER;
l_success NUMBER;
l_error NUMBER;
l_commit VARCHAR2(3);
l_pos_ins boolean;
l_grd_ins boolean;
l_poscount NUMBER;
l_job_date DATE;
l_organization_date DATE;
l_hr_org_count NUMBER;
l_pos_name varchar2(60);
l_org_name varchar2(60);
l_working_hours NUMBER;
l_probation_duration NUMBER;
l_probation_unit VARCHAR2(50);
--Cursor for fetching data from staging table
CURSOR cur_pos_val_stg IS
SELECT xxhr.*,
xxhr.rowid
FROM xx_hr_positions_stg xxhr
WHERE processing_status ='N';

BEGIN
fnd_file.PUT_LINE(fnd_file.LOG, 'Mandetory validations started');
fnd_file.PUT_LINE(fnd_file.LOG, 'ORG_ID :' || fnd_profile.VALUE('ORG_ID'))
;
l_org_id := fnd_profile.VALUE('ORG_ID');
l_count := 0;
l_security_profile_id := 62;
l_language_code := hr_api.userenv_lang;
l_status := 'VALID';
l_commit := p_commit;
l_read := 0;
l_success := 0;
l_error := 0;
FOR cur_pos_val_rec IN cur_pos_val_stg
LOOP
l_read := l_read + 1;
l_position_id := NULL;
l_effective_start_date := NULL;
l_effective_end_date := NULL;
l_position_definition_id := NULL;
l_object_version_number := NULL;
l_name := NULL;
g_error_msg := NULL;
g_organization_id := NULL;
g_job_id := NULL;
g_jobname := NULL;
g_availability_status_id := NULL;
g_permanent_flag := NULL;
g_location_id := NULL;
g_business_group_id := NULL;
g_payroll_id := NULL;
g_bargaining_unit_cd := NULL;
g_pay_basis_id := NULL;
g_seasonal_flag := NULL;
g_entry_grade_id := NULL;
g_status := NULL;
g_frequency := NULL;
g_ptype := NULL;
l_job_date := NULL;
l_organization_date := NULL;
l_hr_org_count := 0;
l_pos_name := NULL;
l_org_name := NULL;
l_working_hours := NULL;
l_probation_duration := NULL;
l_probation_unit := NULL;
IF(cur_pos_val_rec.date_effective_name IS NULL) THEN
----checking mandetory column position_name
g_error_msg := 'Position name does not exist';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transaction
_id, cur_pos_val_rec.component_name, 'Position Name', cur_pos_val_rec.date
_effective_name, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Position name does not exist');
ELSIF LENGTH(cur_pos_val_rec.date_effective_name) > 120 THEN
g_error_msg := 'Position name must not be more that 120 Characters';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transacti
on_id, cur_pos_val_rec.component_name, 'Position Name', cur_pos_val_rec.da
te_effective_name, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Position name must not be more that
120 Characters');
END IF;
IF(cur_pos_val_rec.start_date IS NULL) THEN
---checking mandetory column startdate of position
g_error_msg := 'Start date does not exist';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transacti
on_id, cur_pos_val_rec.component_name, 'start_date', cur_pos_val_rec.start
_date, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Start date does not exist');
END IF;
BEGIN
IF(cur_pos_val_rec.position_type IS NULL) THEN
----checking mandetory column position_type
g_error_msg := 'Position type does not exist';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'position_type', cur_pos_val_rec.
position_type, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Position type does not exist');
ELSE
SELECT lookup_code ----deriving lookupcode of position_type
INTO g_ptype
FROM hr_lookups
WHERE lookup_type = 'POSITION_TYPE'
AND meaning = cur_pos_val_rec.position_type;
fnd_file.PUT_LINE(fnd_file.LOG, 'Position type' || g_ptype);
END IF;
EXCEPTION
WHEN no_data_found THEN
g_error_msg := 'No position_type exists with this name';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transacti
on_id, cur_pos_val_rec.component_name, 'position_type', cur_pos_val_rec.po
sition_type, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'No position_type exists with this n
ame');
WHEN others THEN
g_error_msg := 'Other error in finding position_type';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transacti
on_id, cur_pos_val_rec.component_name, 'position_type', cur_pos_val_rec.po
sition_type, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Other error in finding position_typ
e' || sqlerrm);
END;
BEGIN
IF(cur_pos_val_rec.position_name IS NULL) THEN
----checking mandetory column position_type
g_error_msg := 'Position name does not exist';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'position_name', cur_pos_val_rec.
position_name, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Position type does not exist');
ELSE
SELECT meaning ----deriving lookupcode of position_type
INTO l_pos_name
FROM hr_lookups
WHERE lookup_type = 'PH_POSITION_NAME'
AND meaning = cur_pos_val_rec.position_name;
fnd_file.PUT_LINE(fnd_file.LOG, 'Position name' || g_ptype);
END IF;
EXCEPTION
WHEN no_data_found THEN
g_error_msg := 'No position_name exists with this name';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transacti
on_id, cur_pos_val_rec.component_name, 'position_name', cur_pos_val_rec.po
sition_name, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'No position_type exists with this n
ame');
WHEN others THEN
g_error_msg := 'Other error in finding position_name';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transacti
on_id, cur_pos_val_rec.component_name, 'position_name', cur_pos_val_rec.po
sition_name, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Other error in finding position_typ
e' || sqlerrm);
END;
BEGIN
IF(cur_pos_val_rec.permanent_position IS NULL) THEN
----checking mandetory column permanent_flag
g_error_msg := 'Permanent flag does not exist';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'permanent_position', cur_pos_val
_rec.permanent_position, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Permanent flag does not exist');
ELSE
SELECT lookup_code
INTO g_permanent_flag ----deriving lookupcode for permanent_flag
FROM hr_lookups
WHERE lookup_type = 'YES_NO'
AND meaning = cur_pos_val_rec.permanent_position;
fnd_file.PUT_LINE(fnd_file.LOG, 'Permanent_flag:' || g_permanent_f
lag);
END IF;
EXCEPTION
WHEN no_data_found THEN
g_error_msg := 'Permanent status should be yes or no,no other data is
accepted';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transacti
on_id, cur_pos_val_rec.component_name, 'permanent_position', cur_pos_val_r
ec.permanent_position, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'PERMANENT STATUS SHOULD BE YES OR N
O');
WHEN others THEN
g_error_msg := 'Other error in finding permanent status ';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transacti
on_id, cur_pos_val_rec.component_name, 'permanent_position', cur_pos_val_r
ec.permanent_position, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'other error in finding permanent st
atus' || sqlerrm);
END;
BEGIN
IF(cur_pos_val_rec.organization_name IS NULL) THEN
----checking mandetory column organization
g_error_msg := 'Organization_name does not exist';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'organization_name', cur_pos_val_
rec.organization_name, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Organization_name does not exist'
);
ELSE
SELECT DISTINCT organization_id
INTO g_organization_id -----deriving organization_id
FROM hr_organization_units
WHERE name = cur_pos_val_rec.organization_name;
fnd_file.PUT_LINE(fnd_file.LOG, 'Organization_name:' || g_organiza
tion_id);
------------- By Niraj Date:30/08/07
SELECT COUNT(*)
INTO l_hr_org_count
FROM hr_organization_information
WHERE org_information_context = 'CLASS'
AND org_information1 = 'HR_ORG'
AND org_information2 = 'Y'
AND organization_id = g_organization_id;
IF l_hr_org_count = 0 THEN
g_error_msg := 'Organization is not an HR Organization';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.trans
action_id, cur_pos_val_rec.component_name, 'organization_name', cur_pos_va
l_rec.organization_name, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Organization is not an HR Organ
ization');
END IF;
-------------
UPDATE xx_hr_positions_stg ----updating organization_id in staging t
able
SET organization_id = g_organization_id
WHERE rowid = cur_pos_val_rec.rowid;
END IF;
EXCEPTION
WHEN no_data_found THEN
g_error_msg := 'Organization does not exist with this name';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transacti
on_id, cur_pos_val_rec.component_name, 'organization_name', cur_pos_val_re
c.organization_name, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, ' Organization does not exist with t
his name');
WHEN others THEN
g_error_msg := 'Other error in finding organization';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transacti
on_id, cur_pos_val_rec.component_name, 'organization_name', cur_pos_val_re
c.organization_name, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Other error in finding organization
' || sqlerrm);
END;
BEGIN
IF(cur_pos_val_rec.job_group IS NULL) THEN
------checking mandetory column jobgroup
g_error_msg := 'Job_group does not exist';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'job_group', cur_pos_val_rec.job_
group, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Job_group do not exist');
ELSIF(cur_pos_val_rec.job_band IS NULL) THEN
-------checking mandetory column jobband
g_error_msg := 'Job_band does not exist';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.trans
action_id, cur_pos_val_rec.component_name, 'job_band', cur_pos_val_rec.job
_band, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Job_band does not exist');
ELSE
g_jobname := cur_pos_val_rec.job_group || '.' || cur_pos_val_rec.j
ob_band;
fnd_file.PUT_LINE(fnd_file.LOG, 'Jobname:' || g_jobname);
SELECT DISTINCT job_id
INTO g_job_id -------deriving job_id by concatinating jobgroup and
jobband
FROM per_jobs
WHERE name = g_jobname;
fnd_file.PUT_LINE(fnd_file.LOG, 'Job_id:' || g_job_id);
UPDATE xx_hr_positions_stg
SET job_id = g_job_id --------updating staging table with job_id
WHERE rowid = cur_pos_val_rec.rowid;
END IF;
EXCEPTION
WHEN no_data_found THEN
g_error_msg := 'No job exists with this name';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'job_name', g_jobname, 'Validat
ion', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'No job exists with this name');
WHEN others THEN
g_error_msg := 'Other error in finding job';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'job_name', g_jobname, 'Validat
ion', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Other error in finding job' || sq
lerrm);
END;
BEGIN
IF(cur_pos_val_rec.status IS NULL) THEN
g_error_msg := 'Status does not exist';
-----checking mandetory column status of position
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.trans
action_id, cur_pos_val_rec.component_name, 'status ', cur_pos_val_rec.stat
us, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Status does not exist');
ELSE
SELECT DISTINCT shared_type_id
INTO g_availability_status_id ------deriving ststus_id
FROM per_shared_types
WHERE shared_type_name = cur_pos_val_rec.status;
fnd_file.PUT_LINE(fnd_file.LOG, 'STATUS:' || g_availability_stat
us_id);
UPDATE xx_hr_positions_stg
SET availability_status_id = g_availability_status_id
WHERE rowid = cur_pos_val_rec.rowid;
END IF;
EXCEPTION
WHEN no_data_found THEN
g_error_msg := 'No status exists with this name';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'status ', cur_pos_val_rec.status
, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'No status exists with this name')
;
WHEN others THEN
g_error_msg := 'Other error in finding status';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'status ', cur_pos_val_rec.status
, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Other error in finding status' ||
sqlerrm);
END;
IF(cur_pos_val_rec.effective_date_from IS NULL) THEN
------checking mandetory column effective_date_from
g_error_msg := 'Effective_date_from does not exist';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'effective_date_from', cur_pos_va
l_rec.effective_date_from, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Effective_date_from does not exis
t');
END IF;
BEGIN
IF(cur_pos_val_rec.effective_date_from IS NOT NULL) THEN
SELECT DISTINCT date_from
INTO l_job_date
FROM per_jobs
WHERE name = g_jobname;
IF(l_job_date IS NOT NULL) THEN
fnd_file.PUT_LINE(fnd_file.LOG, 'JOB_DATE:' || to_date(l_job_d
ate));
IF(to_date(cur_pos_val_rec.effective_date_from) < to_date(l_job_
date)) THEN
g_error_msg := 'Effective_date_from should be after job effect
ive start date';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.t
ransaction_id, cur_pos_val_rec.component_name, 'effective_date_from', cur_
pos_val_rec.effective_date_from, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Effective_date_from should
be after job effective start date');
END IF;
END IF;
END IF;
EXCEPTION
WHEN too_many_rows THEN
g_error_msg := 'TOO_MANY_ROWS error while validating job effective d
ate';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'effective_date_from', cur_pos_va
l_rec.effective_date_from, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'TOO_MANY_ROWS error in job_date')
;
WHEN others THEN
g_error_msg := 'Error while validating for job effective date as job
name not found';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'effective_date_from', cur_pos_va
l_rec.effective_date_from, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Miscallaneous error in job_date
of position' || sqlerrm);
END;
BEGIN
IF(cur_pos_val_rec.effective_date_from IS NOT NULL) THEN
SELECT DISTINCT date_from
INTO l_organization_date
FROM hr_all_organization_units
WHERE name = cur_pos_val_rec.organization_name;
IF(l_organization_date IS NOT NULL) THEN
fnd_file.PUT_LINE(fnd_file.LOG, 'ORGANIZATION:' || to_date(l_o
rganization_date));
IF(cur_pos_val_rec.effective_date_from < l_organization_date) TH
EN
g_error_msg := 'Effective_date_from should be after organizati
on effective start date';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.t
ransaction_id, cur_pos_val_rec.component_name, 'effective_date_from', cur_
pos_val_rec.effective_date_from, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Effective_date_from should
be after organization effective start date');
END IF;
END IF;
END IF;
EXCEPTION
WHEN too_many_rows THEN
g_error_msg := 'TOO_MANY_ROWS error while validating organization ef
fective date';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'effective_date_from', cur_pos_va
l_rec.effective_date_from, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'TOO_MANY_ROWS error in organizati
on_date of position' || sqlerrm);
WHEN others THEN
g_error_msg := 'Error while validating for organization effective da
te as organization name not found';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'effective_date_from', cur_pos_va
l_rec.effective_date_from, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Error while validating for organi
zation effective date as organization name not found' || sqlerrm);
END;
BEGIN
IF(cur_pos_val_rec.effective_date_from IS NOT NULL) THEN
IF(to_date(cur_pos_val_rec.effective_date_from) > to_date(cur_pos_
val_rec.start_date)) THEN
g_error_msg := 'Effective_date_from should be after start date';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.tra
nsaction_id, cur_pos_val_rec.component_name, 'effective_date_from', cur_po
s_val_rec.effective_date_from, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Effective_date_from should be
after start date');
END IF;
END IF;
EXCEPTION
WHEN others THEN
g_error_msg := 'Miscallaneous error in effective_date of position';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'effective_date_from', cur_pos_va
l_rec.effective_date_from, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Miscallaneous error in effective_
date of position' || sqlerrm);
END;

IF(cur_pos_val_rec.fte IS NULL) THEN


g_error_msg := 'FTE does not exist';
------checking mandetory column fte
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'fte', cur_pos_val_rec.fte, 'Da
ta', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'FTE does not exist');
END IF;
BEGIN
IF(cur_pos_val_rec.headcount IS NULL) THEN
g_error_msg := 'Head count does not exist';
------checking mandetory column fte
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.trans
action_id, cur_pos_val_rec.component_name, 'headcount', cur_pos_val_rec.he
adcount, 'Data', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Head count do not exist');
END IF;
EXCEPTION
WHEN others THEN
g_error_msg := 'Head count should be one for single incumbment';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'headcount', cur_pos_val_rec.head
count, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Head count should be one for sing
le incumbment ' || sqlerrm);
END;
SELECT COUNT(1) ----checking whether position already exists
INTO l_poscount
FROM hr_all_positions_f
WHERE name = cur_pos_val_rec.date_effective_name;
IF(l_poscount <> 0) THEN
g_error_msg := 'Position already exist';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'position', cur_pos_val_rec.date_
effective_name, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Errror.........Position already e
xist');
END IF;
/*====================================================================
=======================
DERIVING BUSINESS_GROUP_ID FROM ORGANIZATION_NAME
=====================================================================
=======================*/
BEGIN
IF(cur_pos_val_rec.organization_name IS NOT NULL) THEN
----deriving business_group_id
SELECT DISTINCT business_group_id
INTO g_business_group_id
FROM hr_organization_units
WHERE name = cur_pos_val_rec.organization_name;
fnd_file.PUT_LINE(fnd_file.LOG, 'BUSINESS GROUP:' || g_business_
group_id);
UPDATE xx_hr_positions_stg
SET business_group_id = g_business_group_id ------updating busines
s_group_id in staging_table
WHERE rowid = cur_pos_val_rec.rowid;
END IF;
EXCEPTION
WHEN no_data_found THEN
g_error_msg := 'No organization exists with this business group';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'business_group_id', g_business_g
roup_id, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'No organization exists with this
business group');
WHEN others THEN
g_error_msg := 'Other error in finding business group of given organ
ization';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'business_group_id', g_business_g
roup_id, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Other error in finding business g
roup of given organization' || sqlerrm);
END;
/*====================================================================
=================
DERIVING LOCATION_ID FROM LOCATION_NAME
==================================================================
=====================*/
BEGIN
IF(cur_pos_val_rec.organization_name IS NOT NULL) THEN
-----deriving location_id
SELECT DISTINCT location_id
INTO g_location_id
FROM hr_all_organization_units
WHERE name = cur_pos_val_rec.organization_name;
fnd_file.PUT_LINE(fnd_file.LOG, 'location:' || g_location_id);
UPDATE xx_hr_positions_stg ------updating location_id in staging_t
able
SET location_id = g_location_id
WHERE rowid = cur_pos_val_rec.rowid;
END IF;
EXCEPTION
WHEN no_data_found THEN
g_error_msg := 'No location exists with this name';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'location_name', cur_pos_val_rec.
location_name, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'No location exists with this name
');
WHEN others THEN
g_error_msg := 'Other error in finding location of given organizatio
n';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'location_id', g_location_id, '
Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Other error in finding location o
f given organization' || sqlerrm);
END;
/*--------------------------------------------------------------------
-----------------
DERIVING PAYROLL_ID FROM PAYROLL_NAME
--------------------------------------------------------------------
-----------------*/
BEGIN
IF(cur_pos_val_rec.payroll IS NOT NULL) THEN
SELECT DISTINCT payroll_id ----deriving payroll_id
INTO g_payroll_id
FROM pay_all_payrolls_f
WHERE payroll_name = cur_pos_val_rec.payroll;
fnd_file.PUT_LINE(fnd_file.LOG, 'payroll_id:' || g_payroll_id);
UPDATE xx_hr_positions_stg ------updating payroll_id in staging_ta
ble
SET payroll_id = g_payroll_id
WHERE rowid = cur_pos_val_rec.rowid;
END IF;
EXCEPTION
WHEN no_data_found THEN
g_error_msg := 'No payroll exists with this name';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'payroll', cur_pos_val_rec.payrol
l, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'No payroll exists with this name'
);
WHEN others THEN
g_error_msg := 'Other error in finding payroll of given organization
';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'payroll', cur_pos_val_rec.payrol
l, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Other error in finding payroll of
given organization' || sqlerrm);
END;
/*--------------------------------------------------------------------
-----------------
DERIVING BARGAINING_UNIT_CODE FROM BARGAINING_UNIT
---------------------------------------------------------------------
----------------*/
BEGIN
IF(cur_pos_val_rec.bargaining_unit IS NOT NULL) THEN
---deriving bargaining_unit lookupcode
SELECT lookup_code
INTO g_bargaining_unit_cd
FROM hr_lookups
WHERE lookup_type = 'BARGAINING_UNIT_CODE'
AND meaning = cur_pos_val_rec.bargaining_unit;
fnd_file.PUT_LINE(fnd_file.LOG, 'bargaining_unit:' || g_bargaini
ng_unit_cd);
END IF;
EXCEPTION
WHEN no_data_found THEN
g_error_msg := 'No bargaining_unit exists with this name';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'bargaining_unit', cur_pos_val_re
c.bargaining_unit, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'No bargaining_unit exists with th
is name');
WHEN others THEN
g_error_msg := 'Other error in finding bargaining_unit of given orga
nization';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'bargaining_unit', cur_pos_val_re
c.bargaining_unit, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Other error in finding bargaining
_unit of given organization' || sqlerrm);
END;
/* ===================================================================
===============
DERIVING V_SEASONAL_FLAG
==================================================================
==================*/
BEGIN
IF(cur_pos_val_rec.seasonal IS NOT NULL) THEN
--deriving seasonal_flag lookupcode
SELECT lookup_code
INTO g_seasonal_flag
FROM hr_lookups
WHERE lookup_type = 'YES_NO'
AND meaning = cur_pos_val_rec.seasonal;
END IF;
EXCEPTION
WHEN no_data_found THEN
g_error_msg := 'Seasonal status should be yes or no';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'seasonal', cur_pos_val_rec.seaso
nal, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Seasonal status should be yes or
no');
WHEN others THEN
g_error_msg := 'Other error in finding seasonal_flag of given organi
zation';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'seasonal', cur_pos_val_rec.seaso
nal, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Other error in finding seasonal_f
lag of given organization' || sqlerrm);
END;
/*--------------------------------------------------------------------
-----------------
DERIVING PAY_BASIS_ID FROM SALARY_BASIS
-------------------------------------------------------------------
------------------*/
BEGIN
IF(cur_pos_val_rec.salary_basis IS NOT NULL) THEN
----deriving paybasis_id
SELECT DISTINCT pay_basis_id
INTO g_pay_basis_id
FROM per_pay_bases
WHERE name = cur_pos_val_rec.salary_basis;
fnd_file.PUT_LINE(fnd_file.LOG, 'pay_basis:' || g_pay_basis_id);
UPDATE xx_hr_positions_stg --------updating paybasis_id in staging
table
SET pay_basis_id = g_pay_basis_id
WHERE rowid = cur_pos_val_rec.rowid;
END IF;
EXCEPTION
WHEN no_data_found THEN
g_error_msg := 'No salary_basis exists with this name';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'salary_basis', cur_pos_val_rec.s
alary_basis, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'No salary_basis exists with this
name');
WHEN others THEN
g_error_msg := 'Other error in finding salary_basis of given organiz
ation';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'salary_basis', cur_pos_val_rec.s
alary_basis, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Other error in finding salary_bas
is of given organization' || sqlerrm);
END;
---------------------------------------------------------------------------
----------
/*DERIVING GRADE_ID FROM GRADE_NAME*/
----------------------------------------------------------------------------
---------
BEGIN
IF(cur_pos_val_rec.grade IS NOT NULL) THEN
----deriving grade_id
SELECT DISTINCT grade_id
INTO g_entry_grade_id
FROM per_grades
WHERE name = cur_pos_val_rec.grade;
fnd_file.PUT_LINE(fnd_file.LOG, 'GRADE:' || g_entry_grade_id);
UPDATE xx_hr_positions_stg ------------updating grade_id in stagin
g table
SET entry_grade_id = g_entry_grade_id
WHERE rowid = cur_pos_val_rec.rowid;
END IF;
EXCEPTION
WHEN no_data_found THEN
g_error_msg := 'No grade exists with this name';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'grade', cur_pos_val_rec.grade,
'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'No grade exists with this name');
WHEN others THEN
g_error_msg := 'Other error in finding entry_grade of given organiza
tion';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'grade', cur_pos_val_rec.grade,
'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Other error in finding entry_grad
e of given organization' || sqlerrm);
END;
/*---------------------------------------------------------------------------
----------
DERIVING FREQUENCY
------------------------------------------------------------------------------
------*/
BEGIN
IF(cur_pos_val_rec.frequency IS NOT NULL) THEN
------deriving lookupcode for frequency
SELECT lookup_code
INTO g_frequency
FROM hr_lookups
WHERE meaning = cur_pos_val_rec.frequency
AND lookup_type = 'FREQUENCY';
fnd_file.PUT_LINE(fnd_file.LOG, 'frequency:' || g_frequency);
END IF;
EXCEPTION
WHEN no_data_found THEN
g_error_msg := 'No frequency exists with this name';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'frequency', cur_pos_val_rec.freq
uency, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'No frequency exists with this nam
e');
WHEN others THEN
g_error_msg := 'Workings hours should be specified along with freque
ncy';
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transac
tion_id, cur_pos_val_rec.component_name, 'frequency', cur_pos_val_rec.freq
uency, 'Validation', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Workings hours should be specifie
d along with frequency' || sqlerrm);
END;
SELECT decode(cur_pos_val_rec.working_hours,0,NULL,cur_pos_val_rec.wor
king_hours)
INTO l_working_hours
FROM dual;
IF cur_pos_val_rec.probation_duration = 0 THEN
l_probation_duration := NULL;
l_probation_unit := NULL;
END IF;

fnd_file.PUT_LINE(fnd_file.LOG, 'End of derivations');


IF(g_error_msg IS NULL) THEN
UPDATE xxph.xx_hr_positions_stg
SET processing_status = 'V'
WHERE processing_status = 'N'
AND rowid = cur_pos_val_rec.rowid;
--V fro Validate Records
ELSE
UPDATE xxph.xx_hr_positions_stg
SET processing_status = 'E'
WHERE processing_status = 'N'
AND rowid = cur_pos_val_rec.rowid;
-- xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transacti
on_id, cur_pos_val_rec.component_name, 'HR_POSITIONS', cur_pos_val_rec.dat
e_effective_name, 'Data', g_error_msg, '');
END IF;

fnd_file.PUT_LINE(fnd_file.LOG, '--- SAVEPOINT x');


SAVEPOINT x;
IF(l_commit = 'YES') THEN
IF g_error_msg IS NULL THEN
-------valid records inserted thru api
BEGIN
/*
hr_position_api.create_position(p_validate => FALSE, p_posit
ion_id => l_position_id, p_effective_start_date => l_effective_start_date, p
_effective_end_date => l_effective_end_date, p_position_definition_id => l_pos
ition_definition_id, p_name => l_name, p_object_version_number => l_object_v
ersion_number, p_job_id => g_job_id, p_organization_id => g_organization_id,
p_effective_date => cur_pos_val_rec.effective_date_from, p_date_effective =
> cur_pos_val_rec.start_date, p_language_code => l_language_code, p_availabi
lity_status_id => g_status, p_business_group_id => g_business_group_id, p_en
try_step_id => NULL, p_entry_grade_rule_id => NULL, p_location_id => g_locat
ion_id, p_pay_freq_payroll_id => g_payroll_id, p_position_transaction_id =>
cur_pos_val_rec.transaction_id, p_prior_position_id => NULL, p_relief_positi
on_id => NULL, p_entry_grade_id => g_entry_grade_id, p_successor_position_id
=> NULL, p_supervisor_position_id => NULL, p_amendment_date => NULL, p_am
endment_recommendation => NULL, p_amendment_ref_number => NULL, p_bargaining
_unit_cd => g_bargaining_unit_cd, p_comments => NULL, p_current_job_prop_end
_date => NULL, p_current_org_prop_end_date => NULL, p_avail_status_prop_end_
date => NULL, p_date_end => cur_pos_val_rec.effective_date_to, p_earliest_hi
re_date => NULL, p_fill_by_date => NULL, p_frequency => g_frequency, p_fte
=> cur_pos_val_rec.fte, p_max_persons => cur_pos_val_rec.headcount, p_overl
ap_period => NULL, p_overlap_unit_cd => NULL, p_pay_term_end_day_cd => NULL,
p_pay_term_end_month_cd => NULL, p_permanent_temporary_flag => g_permanent_
flag, p_permit_recruitment_flag => NULL, p_position_type => g_ptype, p_pos
ting_description => NULL, p_probation_period => l_probation_duration, p_prob
ation_period_unit_cd => l_probation_unit, p_replacement_required_flag => NULL,
p_review_flag => NULL, p_seasonal_flag => g_seasonal_flag, p_security_req
uirements => NULL, p_status => l_status, p_term_start_day_cd => NULL, p_te
rm_start_month_cd => NULL, p_time_normal_start => cur_pos_val_rec.start_time,
p_time_normal_finish => cur_pos_val_rec.end_time, p_update_source_cd => NULL
, p_working_hours => l_working_hours, p_works_council_approval_flag => NULL,
p_work_period_type_cd => NULL, p_work_term_end_day_cd => NULL, p_work_ter
m_end_month_cd => NULL, p_proposed_fte_for_layoff => NULL, p_proposed_date_f
or_layoff => NULL, p_pay_basis_id => g_pay_basis_id, p_supervisor_id => NULL
, p_attribute_category => 'PH_ADD_POS_DETAILS', p_attribute1 => cur_pos_val_
rec.registered_nurse, --cur_pos_val_rec.attribute31,
p_attribute2 => cur_pos_val_rec.direct_patient_staff, --cur_
pos_val_rec.attribute32,
p_attribute3 => cur_pos_val_rec.shoe_uniform_eligibility, --
cur_pos_val_rec.attribute33,
p_attribute4 => cur_pos_val_rec.meal_coupon_eligibility, p_s
egment1 => cur_pos_val_rec.position_name, p_segment2 => cur_pos_val_rec.organi
zation_name, p_segment3 => NULL, p_segment4 => NULL, p_concat_segments =>
NULL, p_request_id => NULL, p_program_application_id => NULL, p_program_id
=> NULL, p_program_update_date => NULL, p_security_profile_id => l_security
_profile_id);*/
hr_position_api.create_position(
p_validate => FALSE,
p_position_id => l_position_id,
p_effective_start_date => l_effective_start_date,
p_effective_end_date => l_effective_end_date,
p_position_definition_id => l_position_definition_id,
p_name => l_name,
p_object_version_number => l_object_version_number,
p_job_id => g_job_id,
p_organization_id => g_organization_id,
p_effective_date => cur_pos_val_rec.effective_d
ate_from,
p_date_effective => cur_pos_val_rec.start_date,
p_language_code => l_language_code,
p_availability_status_id => g_status,
p_business_group_id => g_business_group_id,
p_entry_step_id => NULL,
p_entry_grade_rule_id => NULL,
p_location_id => g_location_id,
p_pay_freq_payroll_id => g_payroll_id,
p_position_transaction_id => cur_pos_val_rec.transaction
_id,
p_prior_position_id => NULL,
p_relief_position_id => NULL,
p_entry_grade_id => g_entry_grade_id,
p_successor_position_id => NULL,
p_supervisor_position_id => NULL,
p_amendment_date => NULL,
p_amendment_recommendation => NULL,
p_amendment_ref_number => NULL,
p_bargaining_unit_cd => g_bargaining_unit_cd,
p_comments => NULL,
p_current_job_prop_end_date => NULL,
p_current_org_prop_end_date => NULL,
p_avail_status_prop_end_date => NULL,
p_date_end => cur_pos_val_rec.effective_d
ate_to,
p_earliest_hire_date => NULL,
p_fill_by_date => NULL,
p_frequency => g_frequency,
p_fte => cur_pos_val_rec.fte,
p_max_persons => cur_pos_val_rec.headcount,
p_overlap_period => NULL,
p_overlap_unit_cd => NULL,
p_pay_term_end_day_cd => NULL,
p_pay_term_end_month_cd => NULL,
p_permanent_temporary_flag => g_permanent_flag,
p_permit_recruitment_flag => NULL,
p_position_type => g_ptype,
p_posting_description => NULL,
p_probation_period => l_probation_duration,
p_probation_period_unit_cd => l_probation_unit,
p_replacement_required_flag => NULL,
p_review_flag => NULL,
p_seasonal_flag => g_seasonal_flag,
p_security_requirements => NULL,
p_status => l_status,
p_term_start_day_cd => NULL,
p_term_start_month_cd => NULL,
p_time_normal_start => cur_pos_val_rec.start_time,
p_time_normal_finish => cur_pos_val_rec.end_time,
p_update_source_cd => NULL,
p_working_hours => l_working_hours,
p_works_council_approval_flag => NULL,
p_work_period_type_cd => NULL,
p_work_term_end_day_cd => NULL,
p_work_term_end_month_cd => NULL,
p_proposed_fte_for_layoff => NULL,
p_proposed_date_for_layoff => NULL,
p_pay_basis_id => g_pay_basis_id,
p_supervisor_id => NULL,
p_attribute_category => 'PH_ADD_POS_DETAILS',
p_attribute1 => cur_pos_val_rec.registered_
nurse, --cur_pos_val_rec.attribute31,
p_attribute2 => cur_pos_val_rec.direct_pati
ent_staff, --cur_pos_val_rec.attribute32,
p_attribute3 => cur_pos_val_rec.shoe_unifor
m_eligibility, --cur_pos_val_rec.attribute33,
p_attribute4 => cur_pos_val_rec.meal_coupon
_eligibility,
p_segment1 => cur_pos_val_rec.position_na
me,
p_segment2 => cur_pos_val_rec.organizatio
n_name,
p_segment3 => NULL,
p_segment4 => NULL,
p_concat_segments => NULL,
p_request_id => NULL,
p_program_application_id => NULL,
p_program_id => NULL,
p_program_update_date => NULL,
p_security_profile_id => l_security_profile_id
);
IF g_error_msg IS NULL THEN
UPDATE xxph.xx_hr_positions_stg
SET processing_status = 'P'
WHERE processing_status='V'
AND rowid = cur_pos_val_rec.rowid;
ELSE
UPDATE xxph.xx_hr_positions_stg
SET processing_status = 'E'
WHERE processing_status='V'
AND rowid = cur_pos_val_rec.rowid;
END IF;
l_success := l_success + 1;
EXCEPTION
WHEN others THEN
g_error_msg := 'API failed when inserting position records: '|
| sqlerrm || fnd_message.GET;
xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.t
ransaction_id, cur_pos_val_rec.component_name, 'Position', cur_pos_val_rec
.position_name, 'ORACLE ERROR', g_error_msg, '');
xx_per_posfail_prc(cur_pos_val_rec.rowid, g_error_msg);
l_pos_ins := FALSE;
fnd_file.PUT_LINE(fnd_file.LOG, 'API failed when inserting p
osition records: ' || sqlerrm || fnd_message.GET);
END;

IF g_error_msg IS NOT NULL THEN


ROLLBACK TO x;
END IF;

END IF;
END IF;

COMMIT;
END LOOP;
/* IF(l_read=100) THEN
COMMIT;
END IF;*/ fnd_file.PUT_LINE(fnd_file.LOG, 'Total no of records:' |
| l_read);
fnd_file.PUT_LINE(fnd_file.LOG, 'Total no of records processed:' ||
l_success);
l_error := l_read -l_success;
fnd_file.PUT_LINE(fnd_file.LOG, 'Total no of records errored:' || l_
error);
END xx_per_positions_prc;
/*====================================================
--MAIN PROCEDURE OF POSITIONS--
=====================================================*/
PROCEDURE xx_load_positions_prc(errbuf OUT VARCHAR2, retcode OUT NUMB
ER, p_commit IN VARCHAR2) IS
l_ln_user_id NUMBER := fnd_global.user_id;
l_ln_responsibility_id NUMBER := fnd_global.resp_id;
l_ln_application_id NUMBER := fnd_global.prog_appl_id;
l_request_id NUMBER := fnd_global.conc_request_id;
l_commit VARCHAR2(3) := p_commit;
BEGIN
fnd_file.PUT_LINE(fnd_file.LOG, 'p_commit:' || p_commit);
--- fnd_global.apps_initialize(l_ln_user_id, l_ln_responsibility_id
, l_ln_application_id);
IF(l_commit = 'YES') THEN
fnd_file.PUT_LINE(fnd_file.LOG, 'l_commit:' || l_commit);
UPDATE xx_hr_positions_stg
SET processing_status = 'N',
conc_req_id = NULL
WHERE processing_status = 'V';

/* UPDATE xxph.xx_hr_validgrade_stg
SET conc_req_id = NULL
WHERE processing_status = 'V';
UPDATE xxph.xx_hr_validgrade_stg
SET processing_status = 'N'
WHERE processing_status = 'V';*/
COMMIT;
END IF;
UPDATE xx_hr_positions_stg
SET conc_req_id = l_request_id
WHERE processing_status = 'N';
------------N for New Records---------
/*
UPDATE xx_hr_validgrade_stg
SET conc_req_id = l_request_id
WHERE processing_status = 'N';
------------N for New Records---------*/
fnd_file.PUT_LINE(fnd_file.LOG, 'USER ID: ' || l_ln_user_id || 'RESP
ONSIBILITY ID: ' || l_ln_responsibility_id || 'APPLICATION ID: ' || l_ln_applica
tion_id);
xx_per_positions_prc(l_request_id, l_commit);
xx_output_report_prc(l_request_id, l_commit);
--xx_grades_output_report_prc(l_request_id, l_commit);
COMMIT;
END xx_load_positions_prc;
/*======================================================================
==================
Failure procedure for positions
===========================================================================
===============*/ PROCEDURE xx_per_posfail_prc(p_rowid IN rowid, p_err_msg IN
VARCHAR2) IS
v_user_id NUMBER;
BEGIN
fnd_file.PUT_LINE(fnd_file.LOG, 'FAILURE PROCEDURE');
v_user_id := fnd_profile.VALUE('USER_ID');
UPDATE xx_hr_positions_stg
SET creation_date = sysdate,
created_by = v_user_id,
last_updated_by = v_user_id,
last_update_date = sysdate,
last_update_login = v_user_id,
processing_status = 'E'
WHERE rowid = p_rowid;
EXCEPTION
WHEN others THEN
-- xxph_common_dmg_pkg.insert_error_message_prc(cur_pos_val_rec.transacti
on_id, cur_pos_val_rec.component_name, 'Position', cur_pos_val_rec.date_ef
fective_name, 'ORACLE ERROR', g_error_msg, '');
fnd_file.PUT_LINE(fnd_file.LOG, 'Error while updating error flag in
staging table for rowid' || p_rowid || ' ' || sqlerrm);
END xx_per_posfail_prc;
/*======================================================================
==================
Failure procedure for grades
========================================================================
==================
PROCEDURE xx_per_gradefail_prc(p_rowid IN rowid, p_err_msg IN VARCHAR2
) IS
v_user_id NUMBER;
BEGIN
fnd_file.PUT_LINE(fnd_file.LOG, 'Failure Procedure');
v_user_id := fnd_profile.VALUE('USER_ID');
UPDATE xx_hr_validgrade_stg
SET creation_date = sysdate,
created_by = v_user_id,
last_updated_by = v_user_id,
last_update_date = sysdate,
last_update_login = v_user_id,
processing_status = 'E'
WHERE rowid = p_rowid;
EXCEPTION
WHEN others THEN
fnd_file.PUT_LINE(fnd_file.LOG, 'Error While Updating Error Flag in
staging Table for rowid' || p_rowid || ' ' || sqlerrm);
END;
*/
/* =====================================================================
===================
Failure procedure for hierarchies
=========================================================================
=================*/
/* PROCEDURE xx_per_hierfail_prc(p_rowid IN rowid, p_err_msg IN VARCH
AR2) IS
v_user_id NUMBER;
BEGIN
FND_FILE.PUT_LINE(FND_FILE.LOG, 'Failure Procedure');
v_user_id := fnd_profile.VALUE('USER_ID');
UPDATE xx_reppos_stg
SET creation_date = SYSDATE,
created_by = v_user_id,
last_updated_by = v_user_id,
last_update_date =SYSDATE,
last_update_login = v_user_id,
processing_status = 'E'
WHERE rowid = p_rowid;
EXCEPTION
WHEN OTHERS THEN
FND_FILE.PUT_LINE(FND_FILE.LOG, 'Error While Updating Error Flag in s
taging Table for rowid' || p_rowid || ' ' || sqlerrm);
END;*/
/*=====================================================================
================
Loading Hierarchy and Reporting information
=======================================================================
================*/
/* PROCEDURE xx_per_hierarchies_prc(p_request_id IN NUMBER, p_commit
IN VARCHAR2) IS
l_pos_id NUMBER;
l_parent_position_id NUMBER;
l_pos_structure_version_id NUMBER;
l_business_group_id NUMBER;
l_pos_structure_element_id NUMBER;
l_object_version_number NUMBER;
l_commit VARCHAR2(3);
l_read NUMBER;
l_success NUMBER;
l_error NUMBER;
l_position_date DATE;
l_hierarchycount NUMBER;
l_reppositioncount NUMBER;
--l_effective_start_date DATE;
CURSOR cur_reppos_stg IS
SELECT xxrp.*,
xxrp.rowid
FROM xx_reppos_stg xxrp
WHERE processing_status = 'N';
CURSOR cur_reppos_ins IS
SELECT xxrp.*,
xxrp.rowid
FROM xx_reppos_stg xxrp
WHERE processing_status = 'V';
BEGIN
FND_FILE.PUT_LINE(FND_FILE.LOG, ' start of mandetory validations of r
eporting info');
l_read := 0;
l_success := 0;
l_error := 0;
FOR cur_reppos_rec IN cur_reppos_stg
LOOP
FND_FILE.PUT_LINE(FND_FILE.LOG, '----------------------------------
----T1');
l_pos_id := NULL;
l_parent_position_id := NULL;
l_pos_structure_version_id := NULL;
l_business_group_id := NULL;
l_pos_structure_element_id := NULL;
l_object_version_number := NULL;
l_commit := p_commit;
l_read := l_read + 1;
g_error_msg := NULL;
l_position_date := NULL;
l_hierarchycount := NULL;
l_reppositioncount := NULL;
BEGIN
IF(cur_reppos_rec.position_name IS NOT NULL) THEN-----deriving p
osition_id from position_name
SELECT DISTINCT position_id
INTO l_pos_id
FROM hr_all_positions_f
WHERE name = cur_reppos_rec.position_name;
FND_FILE.PUT_LINE(FND_FILE.LOG, 'position_id:' || l_pos_id);
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
g_error_msg := 'No position exists with this name to attach repo
rting position';
xx_per_hierfail_prc(cur_reppos_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_reppos_rec.tran
saction_id, cur_reppos_rec.component_name, 'position_name', cur_reppos_rec
.position_name, 'Validation', g_error_msg, '');
FND_FILE.PUT_LINE(FND_FILE.LOG, 'No position exists with this n
ame to attach reporting position');
WHEN TOO_MANY_ROWS THEN
g_error_msg := 'TOO MANY DATA FOR POSITION';
xx_per_hierfail_prc(cur_reppos_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_reppos_rec.tran
saction_id, cur_reppos_rec.component_name, 'position_name', cur_reppos_rec
.position_name, 'Validation', g_error_msg, '');
FND_FILE.PUT_LINE(FND_FILE.LOG, 'TOO MANY DATA FOR POSITION');
WHEN OTHERS THEN
g_error_msg := 'OTHER ERROR IN FINDING IN POSITION';
xx_per_hierfail_prc(cur_reppos_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_reppos_rec.tran
saction_id, cur_reppos_rec.component_name, 'position_name', cur_reppos_rec
.position_name, 'Validation', g_error_msg, '');
FND_FILE.PUT_LINE(FND_FILE.LOG, 'OTHER ERROR IN FINDING IN POSI
TION' || sqlerrm);
END;
BEGIN
IF(cur_reppos_rec.position_name IS NOT NULL
AND l_pos_id IS NOT NULL) THEN
SELECT DISTINCT effective_start_date
INTO l_position_date
FROM hr_all_positions_f
WHERE name = cur_reppos_rec.position_name;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
g_error_msg := 'NO DATE EXISTS FOR THIS POSITION';
xx_per_hierfail_prc(cur_reppos_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_reppos_rec.tran
saction_id, cur_reppos_rec.component_name, 'Date of position', l_position_
date, 'Validation', g_error_msg, '');
FND_FILE.PUT_LINE(FND_FILE.LOG, 'NO DATE EXISTS FOR THIS POSITION
' || sqlerrm);
WHEN TOO_MANY_ROWS THEN
g_error_msg := 'TOO MANY DATA FOR POSITION_DATE';
xx_per_hierfail_prc(cur_reppos_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_reppos_rec.tran
saction_id, cur_reppos_rec.component_name, 'position_name', cur_reppos_rec
.position_name, 'Validation', g_error_msg, '');
FND_FILE.PUT_LINE(FND_FILE.LOG, 'TOO MANY DATA FOR POSITION_DATE'
);
END;
BEGIN
IF(cur_reppos_rec.heirarchy IS NULL) THEN
------checking for mandetory column hierarchy
g_error_msg := 'REPORTING HIERARCHY DO NOT EXIST';
xx_per_hierfail_prc(cur_reppos_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_reppos_rec.tr
ansaction_id, cur_reppos_rec.component_name, 'HEIRARCHY', cur_reppos_rec.h
eirarchy, 'Data', g_error_msg, '');
FND_FILE.PUT_LINE(FND_FILE.LOG, 'REPORTING HIERARCHY DO NOT EXI
ST');
ELSE
SELECT DISTINCT ppsv.pos_structure_version_id,
----deriving version_id,businessgroup_id
pps.business_group_id
INTO l_pos_structure_version_id,
l_business_group_id
FROM per_pos_structure_versions ppsv,
per_position_structures pps
WHERE pps.position_structure_id = ppsv.position_structure_id
AND pps.name = cur_reppos_rec.heirarchy;
FND_FILE.PUT_LINE(FND_FILE.LOG, 'v_pos_structure_version_id:' |
| l_pos_structure_version_id);
FND_FILE.PUT_LINE(FND_FILE.LOG, 'v_business_group_id :' || l_bu
siness_group_id);
FND_FILE.PUT_LINE(FND_FILE.LOG, 'herarchy name:' || cur_reppos_
rec.heirarchy);
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
g_error_msg := 'NO HEIRARCHY EXISTS WITH THIS NAME';
xx_per_hierfail_prc(cur_reppos_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_reppos_rec.tran
saction_id, cur_reppos_rec.component_name, 'HEIRARCHY', cur_reppos_rec.hei
rarchy, 'Validation', g_error_msg, '');
FND_FILE.PUT_LINE(FND_FILE.LOG, 'NO HEIRARCHY EXISTS WITH THIS NA
ME');
WHEN TOO_MANY_ROWS THEN
g_error_msg := 'TOO MANY ROWS FOR HEIRARCHY NAME';
xx_per_hierfail_prc(cur_reppos_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_reppos_rec.tran
saction_id, cur_reppos_rec.component_name, 'HEIRARCHY', cur_reppos_rec.hei
rarchy, 'Validation', g_error_msg, '');
FND_FILE.PUT_LINE(FND_FILE.LOG, 'TOO MANY ROWS FOR HEIRARCHY NAME
');
WHEN OTHERS THEN
g_error_msg := 'MISCELLANEOUS ERROR IN FINDING HEIRARCHY';
xx_per_hierfail_prc(cur_reppos_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_reppos_rec.tran
saction_id, cur_reppos_rec.component_name, 'HEIRARCHY', cur_reppos_rec.hei
rarchy, 'Validation', g_error_msg, '');
FND_FILE.PUT_LINE(FND_FILE.LOG, ' MISCELLANEOUS ERROR IN FINDING
HEIRARCHY' || sqlerrm);
END;
BEGIN
IF(cur_reppos_rec.reporting_to_position IS NULL) THEN------check
ing mandetory column reportingposition
g_error_msg := 'REPORTING TO POSITION DO NOT EXIST';
xx_per_hierfail_prc(cur_reppos_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_reppos_rec.tr
ansaction_id, cur_reppos_rec.component_name, 'reporting_to_position', cur_
reppos_rec.reporting_to_position, 'Data', g_error_msg, '');
FND_FILE.PUT_LINE(FND_FILE.LOG, 'REPORTING TO POSITION DO NOT E
XIST');
ELSE
SELECT DISTINCT position_id ------deriving parentposition_id
INTO l_parent_position_id
FROM hr_all_positions_f
WHERE name = cur_reppos_rec.reporting_to_position;
FND_FILE.PUT_LINE(FND_FILE.LOG, 'parent_position_id:' || l_pare
nt_position_id);
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
g_error_msg := 'REPORTING TO POSITION DOES NOT EXIST WITH THIS N
AME';
xx_per_hierfail_prc(cur_reppos_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_reppos_rec.tran
saction_id, cur_reppos_rec.component_name, 'reporting_to_position', cur_re
ppos_rec.reporting_to_position, 'Data', g_error_msg, '');
FND_FILE.PUT_LINE(FND_FILE.LOG, 'REPORTING TO POSITION DOES NOT E
XIST WITH THIS NAME');
WHEN TOO_MANY_ROWS THEN
g_error_msg := 'TOO MANY ROWS FOR REPORTING TO POSITION ';
xx_per_hierfail_prc(cur_reppos_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_reppos_rec.tran
saction_id, cur_reppos_rec.component_name, 'reporting_to_position', cur_re
ppos_rec.reporting_to_position, 'Data', g_error_msg, '');
FND_FILE.PUT_LINE(FND_FILE.LOG, 'TOO MANY ROWS FOR REPORTING TO
POSITION');
WHEN OTHERS THEN
g_error_msg := 'MISCELLANEOUS ERROR REPORTING TO POSITION ';
xx_per_hierfail_prc(cur_reppos_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_reppos_rec.tran
saction_id, cur_reppos_rec.component_name, 'reporting_to_position', cur_re
ppos_rec.reporting_to_position, 'Data', g_error_msg, '');
FND_FILE.PUT_LINE(FND_FILE.LOG, ' MISCELLANEOUS ERROR REPORTING T
O POSITION' || sqlerrm);
END;
SELECT COUNT(1)
INTO l_hierarchycount
FROM xxph.xx_reppos_stg
WHERE heirarchy = cur_reppos_rec.heirarchy
AND position_name = cur_reppos_rec.position_name
AND processing_status IN('N', 'P');
IF(l_hierarchycount > 1) THEN
g_error_msg := 'ERRROR.........Hierarchy already Exist,Same Hier
archy cannot exist more than once for position';
xx_per_hierfail_prc(cur_reppos_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_reppos_rec.tran
saction_id, cur_reppos_rec.component_name, 'HEIRARCHY', cur_reppos_rec.hei
rarchy, 'Validation', g_error_msg, '');
FND_FILE.PUT_LINE(FND_FILE.LOG, 'ERRROR.........Hierarchy already
Exist,Same Hierarchy cannot exist more than once');
END IF;
SELECT COUNT(1)
INTO l_reppositioncount
FROM xxph.xx_reppos_stg
WHERE heirarchy = cur_reppos_rec.heirarchy
AND reporting_to_position = cur_reppos_rec.reporting_to_position
AND position_name = cur_reppos_rec.position_name
AND processing_status IN('N', 'P');
IF(l_hierarchycount > 1) THEN
g_error_msg := 'ERRROR.........Reporting to position already Exi
st,Same Hierarchy cannot have more than one reporting position';
xx_per_hierfail_prc(cur_reppos_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_reppos_rec.tran
saction_id, cur_reppos_rec.component_name, 'reporting_to_position', cur_re
ppos_rec.reporting_to_position, 'Data', g_error_msg, '');
FND_FILE.PUT_LINE(FND_FILE.LOG, 'ERRROR.........Reporting to posi
tion already Exist,Same Hierarchy cannot have more than one reporting position')
;
END IF;
FND_FILE.PUT_LINE(FND_FILE.LOG, 'Validations Over' || sqlerrm);
FND_FILE.PUT_LINE(FND_FILE.LOG, 'Validations Over' || g_error_msg);
IF g_error_msg IS NULL THEN
UPDATE xxph.xx_reppos_stg
SET processing_status = 'V'
WHERE processing_status = 'N'
AND rowid = cur_reppos_rec.rowid;
--V fro Validate Records
ELSE
UPDATE xxph.xx_reppos_stg
SET processing_status = 'E'
WHERE processing_status = 'N'
AND rowid = cur_reppos_rec.rowid;
END IF;
FND_FILE.PUT_LINE(FND_FILE.LOG, 'updating processing status:' || cu
r_reppos_rec.processing_status);
IF l_commit = 'YES' THEN
IF g_error_msg IS NULL THEN
BEGIN
FND_FILE.PUT_LINE(FND_FILE.LOG, 'start of insertion');
hr_pos_hierarchy_ele_api.create_pos_hierarchy_ele(p_validate
=> FALSE,
p_parent_position_id => l_parent_position_id,
p_pos_structure_version_id => l_pos_structure_version_id,
p_subordinate_position_id => l_pos_id,
p_business_group_id => l_business_group_id,
p_hr_installed => 'I',
p_effective_date => l_position_date,
p_pos_structure_element_id => l_pos_structure_element_id,
p_object_version_number => l_object_version_number);
IF g_error_msg IS NULL THEN
UPDATE xxph.xx_reppos_stg
SET processing_status = 'P'
WHERE processing_status = 'V'
AND rowid = cur_reppos_rec.rowid;
--P for processed Records
END IF;
COMMIT;
l_success := l_success + 1;
EXCEPTION
WHEN OTHERS THEN
g_error_msg := 'API FAILED WHEN INSERTING REPORTING_INFORMAT
ION:'||SQLERRM;
xx_per_hierfail_prc(cur_reppos_rec.rowid, g_error_msg);
xxph_common_dmg_pkg.insert_error_message_prc(cur_reppos_rec.
transaction_id, cur_reppos_rec.component_name, 'position_name', cur_reppos
_rec.position_name, 'ORACLE ERROR', g_error_msg, '');
FND_FILE.PUT_LINE(FND_FILE.LOG, 'API FAILED WHEN INSERTING RE
PORTING_INFORMATION' || sqlerrm);
END;
END IF;
END IF;
END LOOP;
FND_FILE.PUT_LINE(FND_FILE.LOG, 'Total no of records in reporting inf
o:' || l_read);
FND_FILE.PUT_LINE(FND_FILE.LOG, 'Total no of records processed in rep
orting info:' || l_success);
l_error := l_read -l_success;
FND_FILE.PUT_LINE(FND_FILE.LOG, 'Total no of records errored in repor
ting info:' || l_error);
END xx_per_hierarchies_prc;
/*====================================================================
=========================
Main Procedure For Hierarchies
==================================================================
==========================*/
/* PROCEDURE xx_load_poshier_prc(errbuf OUT VARCHAR2, retcode OUT NUM
BER, p_commit IN VARCHAR2) IS
l_ln_user_id NUMBER := fnd_global.user_id;
l_ln_responsibility_id NUMBER := fnd_global.resp_id;
l_ln_application_id NUMBER := fnd_global.prog_appl_id;
l_request_id NUMBER := fnd_global.conc_request_id;
l_commit VARCHAR2(3) := p_commit;
BEGIN
---fnd_global.apps_initialize(l_ln_user_id, l_ln_responsibility_id
, l_ln_application_id);
FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_commit:' || p_commit);
FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_commit:' || l_commit);
IF(l_commit = 'YES') THEN
UPDATE xxph.xx_reppos_stg
SET conc_req_id = NULL
WHERE processing_status = 'V';
UPDATE xxph.xx_reppos_stg
SET processing_status = 'N'
WHERE processing_status = 'V';
COMMIT;
END IF;
UPDATE xxph.xx_reppos_stg
SET conc_req_id = l_request_id
WHERE processing_status = 'N';
------------N for New Records---------
FND_FILE.PUT_LINE(FND_FILE.LOG, 'USER ID: ' || l_ln_user_id || 'RESPON
SIBILITY ID: ' || l_ln_responsibility_id || 'APPLICATION ID: ' || l_ln_applicati
on_id);
xx_per_hierarchies_prc(l_request_id, l_commit);
xx_hier_output_report_prc(l_request_id, l_commit);
COMMIT;
END xx_load_poshier_prc;*/
/*=====================================================================
======================
To Develop the error Report of positions
=======================================================================
=========================*/
PROCEDURE xx_output_report_prc(p_request_id IN NUMBER, p_commit IN VARCHA
R2) IS
--cursor to fetch all the valid records processed through this request
CURSOR cur_valid_positions(p_conc_req_id NUMBER) IS
SELECT xxvp.*,
xxvp.rowid
FROM xxph.xx_hr_positions_stg xxvp
WHERE xxvp.processing_status = 'V'
AND xxvp.conc_req_id = p_conc_req_id;
--cursor to fetch all the error records obtained through this request
CURSOR cur_error_records(p_conc_req_id NUMBER) IS
SELECT xxvp.date_effective_name,
xxe.error_column,
xxe.error_value,
xxe.error_type,
xxe.error_messg
FROM xxph.xx_hr_positions_stg xxvp,
xx_ph_all_errors xxe
WHERE xxvp.transaction_id = xxe.transaction_id
AND xxvp.component_name = xxe.component_name
AND xxe.conc_req_id = p_conc_req_id;
t_count NUMBER;
t_count_records NUMBER;
t_success_records NUMBER;
t_error_records NUMBER;
BEGIN
IF(p_commit = 'YES') THEN
FOR valid_positions_rec IN cur_valid_positions(p_request_id)
LOOP
--fnd_file.PUT_LINE(fnd_file.OUTPUT, 'P_Request_id:' || p_reques
t_id);
--To check whether the record exists in standard Table
SELECT COUNT(1)
INTO t_count
FROM hr_all_positions_f
WHERE name = valid_positions_rec.date_effective_name;
IF(t_count = 0) THEN
/* Update the staging table with error status for records that
are
not present in standard table */
UPDATE xxph.xx_hr_positions_stg
SET processing_status = 'E'
WHERE rowid = valid_positions_rec.rowid;
--TO insert error message into error table
xxph_common_dmg_pkg.insert_error_message_prc(valid_positions_rec
.transaction_id, valid_positions_rec.component_name, 'POSITION_NAME', vali
d_positions_rec.date_effective_name, 'ORACLE_ERROR', 'error report for posit
ions'||SQLERRM, NULL);
END IF;
IF(t_count = 1) THEN
/* Update the staging table with processed status for records t
hat are
present in standard table*/
UPDATE xx_hr_positions_stg
SET processing_status = 'P'
WHERE rowid = valid_positions_rec.rowid;
END IF;
END LOOP;
COMMIT;
END IF;
fnd_file.PUT_LINE(fnd_file.OUTPUT, rpad(nvl('SAP_Position_name', '
'), 70, ' ') || CHR(9) || rpad(nvl('Error_Column', ' '), 25, ' ') ||
CHR(9) || rpad(nvl('Error_Value', ' '), 30, ' ') || CHR(9) || rpad(nvl('Er
ror_Record_Type', ' '), 17, ' ') || CHR(9) || rpad(nvl('Error_Message',
' '), 100, ' '));
fnd_file.PUT_LINE(fnd_file.OUTPUT, rpad(nvl('=================', '
'), 70, ' ') || CHR(9) || rpad(nvl('============', ' '), 25, ' ') ||
CHR(9) || rpad(nvl('===========', ' '), 30, ' ') || CHR(9) || rpad(nvl('==
===============', ' '), 17, ' ') || CHR(9) || rpad(nvl('=============',
' '), 100, ' '));
FOR error_records_rec IN cur_error_records(p_request_id)
LOOP
fnd_file.PUT_LINE(fnd_file.OUTPUT, rpad(nvl(error_records_rec.date
_effective_name, ' '), 70, ' ') || CHR(9) || rpad(nvl(error_records_rec.er
ror_column, ' '), 25, ' ') || CHR(9) || rpad(nvl(error_records_rec.error_v
alue, ' '), 30, ' ') || CHR(9) || rpad(nvl(error_records_rec.error_type,
' '), 17, ' ') || CHR(9) || rpad(nvl(error_records_rec.error_messg, ' '),
100, ' '));
END LOOP;
fnd_file.PUT_LINE(fnd_file.OUTPUT, '================================
===============');
SELECT COUNT(1)
INTO t_count_records
FROM xx_hr_positions_stg xxvp
WHERE xxvp.conc_req_id = p_request_id;
fnd_file.PUT_LINE(fnd_file.OUTPUT, 'P_Request_id:' || p_request_id);
fnd_file.PUT_LINE(fnd_file.OUTPUT, 'Total Records Processed ' || t_c
ount_records);
IF(p_commit = 'NO') THEN
SELECT COUNT(1)
INTO t_success_records
FROM xx_hr_positions_stg xxvp
WHERE xxvp.conc_req_id = p_request_id
AND processing_status = 'V';
fnd_file.PUT_LINE(fnd_file.OUTPUT, 'Total Records that are Valid '
|| t_success_records);
END IF;
IF(p_commit = 'YES') THEN
SELECT COUNT(1)
INTO t_success_records
FROM xx_hr_positions_stg xxvp
WHERE xxvp.conc_req_id = p_request_id
AND processing_status = 'P';
fnd_file.PUT_LINE(fnd_file.OUTPUT, 'Total Records Processed Sucess
fully ' || t_success_records);
END IF;
SELECT COUNT(1)
INTO t_error_records
FROM xx_hr_positions_stg xxvp
WHERE xxvp.conc_req_id = p_request_id
AND processing_status = 'E';
fnd_file.PUT_LINE(fnd_file.OUTPUT, 'Total Records Processed with Err
or ' || t_error_records);
END xx_output_report_prc;
/* =====================================================================
======================
To Develop the error Report of grades
====================================================================
============================
PROCEDURE xx_grades_output_report_prc(p_request_id IN NUMBER, p_co
mmit IN VARCHAR2) IS
--cursor to fetch all the valid records processed through this request
CURSOR cur_valid_grades(p_conc_req_id NUMBER) IS
SELECT xxvg.*,
xxvg.rowid
FROM xxph.xx_hr_validgrade_stg xxvg
WHERE xxvg.processing_status = 'V'
AND xxvg.conc_req_id = p_conc_req_id;
--cursor to fetch all the error records obtained through this request
CURSOR cur_grades_error_records(p_conc_req_id NUMBER) IS
SELECT xxvg.valid_grade,
xxe.error_column,
xxe.error_value,
xxe.error_type,
xxe.error_messg
FROM xxph.xx_hr_validgrade_stg xxvg,
xx_ph_all_errors xxe
WHERE xxvg.transaction_id = xxe.transaction_id
AND xxvg.component_name = xxe.component_name
AND xxe.conc_req_id = p_conc_req_id;
l_grdcount NUMBER;
l_grdcount_records NUMBER;
l_grdsuccess_records NUMBER;
l_grderror_records NUMBER;
BEGIN
IF(p_commit = 'YES') THEN
FOR valid_grades_rec IN cur_valid_grades(p_request_id)
LOOP
--To check whether the record exists in standard Table
SELECT COUNT(1)
INTO l_grdcount
FROM per_valid_grades
WHERE position_id IN
(SELECT position_id
FROM hr_all_positions_f
WHERE name = valid_grades_rec.position_name)
;
IF(l_grdcount = 0) THEN
/* Update the staging table with error status for records that
are
not present in standard table */
/* UPDATE xxph.xx_hr_validgrade_stg
SET processing_status = 'E'
WHERE rowid = valid_grades_rec.rowid;
--TO insert error message into error table
xxph_common_dmg_pkg.insert_error_message_prc(valid_grades_rec.tr
ansaction_id, valid_grades_rec.component_name, 'Valid_grade', valid_grades
_rec.valid_grade, 'ORACLE_ERROR', 'error report for grades', NULL);
END IF;
IF(l_grdcount = 1) THEN
-- Update the staging table with processed status for records t
hat are
--present in standard table
UPDATE xxph.xx_hr_validgrade_stg
SET processing_status = 'P'
WHERE rowid = valid_grades_rec.rowid;
END IF;
END LOOP;
COMMIT;
END IF;
fnd_file.PUT_LINE(fnd_file.OUTPUT, rpad('SAP_Grade_name', 50, '
') || CHR(9) || 'Error_Column' || CHR(9) || rpad('Error_Value', 30, ' ') ||
CHR(9) || rpad('Error_Record_Type', 30, ' ') || CHR(9) || rpad('Error_Messag
e', 100, ' '));
FOR error_gradesrecords_rec IN cur_grades_error_records(p_request_id)
LOOP
fnd_file.PUT_LINE(fnd_file.OUTPUT, rpad(error_gradesrecords_rec.va
lid_grade, 50, ' ') || CHR(9) || rpad(error_gradesrecords_rec.error_column,
50, ' ') || CHR(9) || rpad(error_gradesrecords_rec.error_value, 30, ' ')
|| CHR(9) || rpad(error_gradesrecords_rec.error_type, 30, ' ') || CHR(9) ||
rpad(error_gradesrecords_rec.error_messg, 100, ' '));
END LOOP;
SELECT COUNT(1)
INTO l_grdcount_records
FROM xx_hr_validgrade_stg xxvg
WHERE xxvg.conc_req_id = p_request_id;
fnd_file.PUT_LINE(fnd_file.OUTPUT, 'Total Records Processed ' || l_g
rdcount_records);
IF(p_commit = 'YES') THEN
SELECT COUNT(1)
INTO l_grdsuccess_records
FROM xx_hr_validgrade_stg xxvg
WHERE xxvg.conc_req_id = p_request_id
AND processing_status = 'P';
fnd_file.PUT_LINE(fnd_file.OUTPUT, 'Total Records Processed Sucess
fully ' || l_grdsuccess_records);
ELSE
SELECT COUNT(1)
INTO l_grdsuccess_records
FROM xx_hr_validgrade_stg xxvg
WHERE xxvg.conc_req_id = p_request_id
AND processing_status = 'V';
fnd_file.PUT_LINE(fnd_file.OUTPUT, 'Total Records Valid Sucessfull
y ' || l_grdsuccess_records);
END IF;
SELECT COUNT(1)
INTO l_grderror_records
FROM xx_hr_validgrade_stg xxvg
WHERE xxvg.conc_req_id = p_request_id
AND processing_status = 'E';
fnd_file.PUT_LINE(fnd_file.OUTPUT, 'Total Records Processed with Err
or ' || l_grderror_records);
END xx_grades_output_report_prc;
/*======================================================================
=====================
To Develop the error Report of hierarchies
========================================================================
========================*/
/*PROCEDURE xx_hier_output_report_prc(p_request_id IN NUMBER, p_commi
t IN VARCHAR2) IS
--cursor to fetch all the valid records processed through this request
CURSOR cur_valid_hiers(p_conc_req_id NUMBER) IS
SELECT xxvh.*,
xxvh.rowid
FROM xxph.xx_reppos_stg xxvh
WHERE xxvh.processing_status = 'V'
AND xxvh.conc_req_id = p_conc_req_id;
--cursor to fetch all the error records obtained through this request
CURSOR cur_hier_error_records(p_conc_req_id NUMBER) IS
SELECT xxvh.heirarchy,
xxvh.position_name,
xxvh.reporting_to_position,
xxe.error_column,
xxe.error_value,
xxe.error_type,
xxe.error_messg
FROM xxph.xx_reppos_stg xxvh,
xx_ph_all_errors xxe
WHERE xxvh.transaction_id = xxe.transaction_id
AND xxvh.component_name = xxe.component_name
AND xxe.conc_req_id = p_conc_req_id;
l_hiercount NUMBER;
l_hiercount_records NUMBER;
l_hiersuccess_records NUMBER;
l_hiererror_records NUMBER;
BEGIN
IF(p_commit = 'YES') THEN
FOR valid_hier_rec IN cur_valid_hiers(p_request_id)
LOOP
--To check whether the record exists in standard Table
SELECT COUNT(1)
INTO l_hiercount
FROM per_pos_structure_elements
WHERE parent_position_id IN
(SELECT position_id
FROM hr_all_positions_f
WHERE name = valid_hier_rec.reporting_to_position) ;
IF(l_hiercount = 0) THEN
/* Update the staging table with error status for records tha
t are
not present in standard table */
/* UPDATE xxph.xx_reppos_stg
SET processing_status = 'E'
WHERE rowid = valid_hier_rec.rowid;
--TO insert error message into error table
xxph_common_dmg_pkg.insert_error_message_prc(valid_hier_rec.tr
ansaction_id, valid_hier_rec.component_name, 'Position Hierarchy', 'valid_
hier_rec.----------', 'ORACLE_ERROR', 'error report for hierarchies', NULL
);
END IF;
IF(l_hiercount = 1) THEN
-- Update the staging table with processed status for records
that are
--present in standard table
UPDATE xxph.xx_reppos_stg
SET processing_status = 'P'
WHERE rowid = valid_hier_rec.rowid;
END IF;
END LOOP;
COMMIT;
END IF;
FND_FILE.PUT_LINE(FND_FILE.OUTPUT, RPAD(NVL('SAP_Position_Name','
'),70,' ') || CHR(9) || RPAD(NVL('SAP_Hierarchy',' '),50,' ') || CHR(9) || RPAD(
NVL('SAP_ReportingPosition_Name',' '),50,' ') || CHR(9) || RPAD(NVL('Error_Colum
n',' '),50,' ') || CHR(9) || RPAD(NVL('Error_Value',' '),50,' ') || CHR(9) || RP
AD(NVL('Error_Record_Type',' '),30,' ') || CHR(9) || RPAD(NVL('Error_Message','
'),50,' '));
FOR error_hierrecords_rec IN cur_hier_error_records(p_request_id)
LOOP
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,RPAD(NVL(error_hierrecords_rec.p
osition_name,' '),70,' ') || CHR(9) || RPAD(NVL(error_hierrecords_rec.heirarchy,
' '),50,' ') || CHR(9) || RPAD(NVL(error_hierrecords_rec.reporting_to_position,'
'),50,' ') || CHR(9) || RPAD(NVL(error_hierrecords_rec.error_column,' '),50,' '
) || CHR(9) || RPAD(NVL(error_hierrecords_rec.error_value,' '),50,' ') || CHR(9)
||RPAD(NVL(error_hierrecords_rec.error_type,' '),30,' ') || CHR(9) || RPAD(NVL(
error_hierrecords_rec.error_messg,' '),200,' '));
END LOOP;
SELECT COUNT(1)
INTO l_hiercount_records
FROM xx_reppos_stg xxvh
WHERE xxvh.conc_req_id = p_request_id;
FND_FILE.PUT_LINE(FND_FILE.OUTPUT, 'Total Records Processed ' || l
_hiercount_records);
IF(p_commit = 'YES') THEN
SELECT COUNT(1)
INTO l_hiersuccess_records
FROM xx_reppos_stg xxvh
WHERE xxvh.conc_req_id = p_request_id
AND processing_status = 'P';
FND_FILE.PUT_LINE(FND_FILE.OUTPUT, 'Total Records Processed Suce
ssfully ' || l_hiersuccess_records);
ELSE
SELECT COUNT(1)
INTO l_hiersuccess_records
FROM xx_reppos_stg xxvh
WHERE xxvh.conc_req_id = p_request_id
AND processing_status = 'V';
FND_FILE.PUT_LINE(FND_FILE.OUTPUT, 'Total Records Valid ' || l_
hiersuccess_records);
END IF;
SELECT COUNT(1)
INTO l_hiererror_records
FROM xx_reppos_stg xxvh
WHERE xxvh.conc_req_id = p_request_id
AND processing_status = 'E';
FND_FILE.PUT_LINE(FND_FILE.OUTPUT, 'Total Records Processed with E
rror ' || l_hiererror_records);
END xx_hier_output_report_prc;*/
/*=====================================================================
==========================
Inserting Data Into Staging Tables
==========================================================================
=======================*/ PROCEDURE xx_positions_load_stg_prc(errbuf OUT VARCHAR
2, retcode OUT NUMBER, p_load_id IN NUMBER, p_vgload_id IN NUMBER) AS
l_ln_user_id NUMBER := fnd_global.user_id;
l_ln_responsibility_id NUMBER := fnd_global.resp_id;
l_ln_application_id NUMBER := fnd_global.prog_appl_id;
l_request_id NUMBER;
l_login_id NUMBER;
l_vg_count NUMBER;
l_pos_count NUMBER;
BEGIN
-- fnd_global.apps_initialize(l_ln_user_id,l_ln_responsibility_id,l_l
n_application_id);
COMMIT;
l_request_id := to_number(fnd_global.conc_request_id);
l_login_id := to_number(fnd_profile.VALUE('LOGIN_ID'));
fnd_file.PUT_LINE(fnd_file.LOG, 'Start Inserting Data ***********');
fnd_file.PUT_LINE(fnd_file.LOG, '***********************************
********************************');
fnd_file.PUT_LINE(fnd_file.LOG, 'Loading Data from SAP tables to Ora
cle Staging Table...');
fnd_file.PUT_LINE(fnd_file.LOG, '***********************************
********************************');
/* -- Niraj
INSERT
INTO xx_hr_positions_stg(batch_id, transaction_id, position_name,
position_id, start_date, date_effective_name, position_type, permanent
_position, seasonal, organization_name, organization_id, business_group_
id, job_group, job_band, job_id, status, availability_status_id, loc
ation_name, location_id, effective_date_from, effective_date_to, fte,
headcount, bargaining_unit, payroll, payroll_id, grade, entry_grade_id
, salary_basis, pay_basis_id, probation_duration, duration_unit, worki
ng_hours, frequency, start_time, end_time, registered_nurse, direct_pa
tient_staff, component_name, --attribute31,
--attribute32,
--attribute33,
--attribute34,
--attribute35,
--attribute36,
--attribute37,
--attribute38,
--attribute39,
--attribute40,
processing_status, created_by, creation_date, last_updated_by,
last_update_date, last_update_login, conc_req_id)
SELECT load_id,
xx_per_positions_transid_s.nextval,
position_name,
NULL,
start_date,
date_effective_name,
type,
permenant,
seasonal,
organization,
NULL,
NULL,
job_group,
job_band,
NULL,
status,
NULL,
location,
NULL,
effective_date_from,
NULL,
fte,
headcount,
NULL,
payroll,
NULL,
grade,
NULL,
salary_basis,
NULL,
probation_duration,
duration_unit,
working_hours,
frequency,
start_time,
end_time,
NULL,
NULL,
'HR_POSITIONS',
--attribute31,
--attribute32,
--attribute33,
--attribute34,
--attribute35,
--attribute36,
--attribute37,
--attribute38,
--attribute39,
--attribute40,
'N',
l_ln_user_id,
sysdate,
l_ln_user_id,
sysdate,
l_login_id,
l_request_id
FROM ods_sap_hr.stg_hr_positiondetails_temp @CRYSTAL
WHERE load_id = nvl(p_load_id, load_id); */
INSERT INTO xx_hr_positions_stg
(batch_id,
transaction_id,
position_name,
position_id,
start_date,
date_effective_name,
position_type,
permanent_position,
seasonal,
organization_name,
organization_id,
business_group_id,
job_group,
job_band,
job_id,
status,
availability_status_id,
location_name,
location_id,
effective_date_from,
effective_date_to,
fte,
headcount,
bargaining_unit,
payroll,
payroll_id,
grade,
entry_grade_id,
salary_basis,
pay_basis_id,
probation_duration,
duration_unit,
working_hours,
frequency,
start_time,
end_time,
registered_nurse,
direct_patient_staff,
shoe_uniform_eligibility,
meal_coupon_eligibility,
component_name, --attribute31,
--attribute32,
--attribute33,
--attribute34,
--attribute35,
--attribute36,
--attribute37,
--attribute38,
--attribute39,
--attribute40,
processing_status,
created_by,
creation_date,
last_updated_by,
last_update_date,
last_update_login,
conc_req_id)
SELECT load_id,
xx_per_positions_transid_s.NEXTVAL,
position_name,
NULL,
start_date,
date_effective_name,
TYPE,
permenant,
seasonal,
organization,
NULL,
NULL,
job_group,
job_band,
NULL,
status,
NULL,
location,
NULL,
effective_date_from,
NULL,
fte,
headcount,
NULL,
payroll,
NULL,
grade,
NULL,
salary_basis,
NULL,
probation_duration,
duration_unit,
working_hours,
frequency,
start_time,
end_time,
registered_nurse,
direct_patient_staff,
shoe_uniform_eligibility,
meal_coupon_eligibility,
'HR_POSITIONS',
--attribute31,
--attribute32,
--attribute33,
--attribute34,
--attribute35,
--attribute36,
--attribute37,
--attribute38,
--attribute39,
--attribute40,
'N',
l_ln_user_id,
SYSDATE,
l_ln_user_id,
SYSDATE,
l_login_id,
l_request_id
FROM ods_sap_hr.stg_hr_positiondetails_temp @crystal
WHERE load_id = nvl(p_load_id, load_id) AND date_effective_name NOT IN (
SELECT date_e
ffective_name
FROM xx_hr_po
sitions_stg
);
BEGIN
SELECT COUNT(1)
INTO l_pos_count
FROM xx_hr_positions_stg pos
WHERE pos.conc_req_id = l_request_id;
fnd_file.PUT_LINE(fnd_file.OUTPUT, '==============================
============================================================================');
fnd_file.PUT_LINE(fnd_file.OUTPUT, 'Number of records successfully
inserted into staging table' || ' ' || l_pos_count);
EXCEPTION
WHEN no_data_found THEN
fnd_file.PUT_LINE(fnd_file.LOG, 'No records inserted into the stag
ing table in this run' || sqlerrm);
WHEN others THEN
fnd_file.PUT_LINE(fnd_file.LOG, 'Error while inserting records int
o staging table' || sqlerrm);
END;
/*
INSERT
INTO xx_hr_validgrade_stg(batch_id, transaction_id, valid_grade,
position_name, from_date, to_date, component_name,
/* attribute31,
attribute32,
attribute33,
attribute34,
attribute35,
attribute36,
attribute37,
attribute38,
attribute39,
attribute40,*
processing_status,
created_by,
creation_date,
last_updated_by,
last_update_date,
last_update_login,
conc_req_id )
SELECT load_id,
xx_grade_transid_s.nextval,
valid_grade,
position_name || '.' || organization_name,
from_date,
to_date,
'XX_VALID_GRADES',
'N',
l_ln_user_id,
sysdate,
l_ln_user_id,
sysdate,
l_login_id,
l_request_id
FROM ods_sap_hr.stg_hr_validgrades_temp @CRYSTAL
WHERE load_id = nvl(p_vgload_id, load_id);
BEGIN
SELECT COUNT(1)
INTO l_vg_count
FROM xx_hr_validgrade_stg vg
WHERE vg.conc_req_id = l_request_id;
fnd_file.PUT_LINE(fnd_file.OUTPUT, '==============================
============================================================================');
fnd_file.PUT_LINE(fnd_file.OUTPUT, 'Number of records successfully
inserted into staging table' || ' ' || l_vg_count);
EXCEPTION
WHEN no_data_found THEN
fnd_file.PUT_LINE(fnd_file.LOG, 'No records inserted into the stag
ing table in this run' || sqlerrm);
WHEN others THEN
fnd_file.PUT_LINE(fnd_file.LOG, 'Error while inserting records int
o staging table' || sqlerrm);
END;
COMMIT;
EXCEPTION
WHEN others THEN
fnd_file.PUT_LINE(fnd_file.LOG, 'Error while inserting records into
staging table' || sqlerrm);*/
END xx_positions_load_stg_prc;
END xx_per_positions_pkg;
/
sho err