----------------------------------
--Create Position
----------------------------------
declare
l_eff_start_date date;
l_eff_end_date date;
l_effective_date date := sysdate;
l_date_end date := hr_general.end_of_time;
l_job_id per_positions.job_id%type;
l_pos_org_id per_positions.position_id%type;
l_validate_mode boolean := false;
l_pos_type fnd_lookup_values.lookup_code%type;
l_avail_id per_shared_types.shared_type_id%type;
l_fte number;
l_max_persons number;
l_probation_period number;
l_probation_unit_desc varchar2(500);
l_business_group_id number := 101;
l_segment1 varchar2(20) := '123456';
l_orcl_pos_title_code fnd_lookup_values.lookup_code%type;
l_attribute8 hr_all_positions_f.attribute8%type;
l_attribute9 hr_all_positions_f.attribute9%type;
l_grade_id hr_all_positions_f.entry_grade_id%type;
l_barg_unit_cd hr_all_positions_f.bargaining_unit_cd%type;
l_attribute6 hr_all_positions_f.attribute6%type;
l_working_hours hr_all_positions_f.working_hours%type;
l_frequency hr_all_positions_f.frequency%type;
l_position_id per_positions.position_id%type;
l_object_version_number hr_all_positions_f.object_version_number%type;
l_position_definition_id number;
l_pos_name per_positions.name%type;
--
begin
---
l_pos_org_id := 9780;
l_effective_date := trunc(sysdate);
l_date_end := hr_general.end_of_time;
l_job_id := 1082;
l_pos_type := 'SHARED';
l_avail_id := 1;
l_fte := 1;
l_max_persons := 100;
l_probation_period := 6;
l_probation_unit_desc := 'M';
l_frequency := 'W';
l_working_hours := 37;
l_grade_id := 1124;
l_barg_unit_cd := 'EWP';
l_attribute6 := NULL;
l_orcl_pos_title_code := 'MECH_TECH';
--
l_position_id := NULL;
l_object_version_number := NULL;
l_eff_start_date := NULL;
l_eff_end_date := NULL;
l_position_definition_id := NULL;
l_pos_name := NULL;
--
hr_position_api.create_position
(
p_job_id => l_job_id --The job for the position
,p_organization_id => l_pos_org_id
,p_effective_date => l_effective_date
,p_date_effective => l_effective_date --The date on which the position becomes active
,p_date_end => l_date_end
,p_validate => l_validate_mode
,p_position_type => l_pos_type
,p_availability_status_id => l_avail_id
,p_fte => l_fte
,p_max_persons => l_max_persons
,p_probation_period => l_probation_period
,p_probation_period_unit_cd => l_probation_unit_desc
,p_business_group_id => l_business_group_id
,p_segment1 => l_segment1
,p_segment2 => l_orcl_pos_title_code
,p_attribute8 => l_attribute8
,p_attribute9 => l_attribute9
,p_entry_grade_id => l_grade_id
,p_bargaining_unit_cd => l_barg_unit_cd
,p_attribute6 => l_attribute6
--
,p_working_hours => l_working_hours
,p_frequency => l_frequency
--OUT
,p_position_id => l_position_id
,p_object_version_number => l_object_version_number
,p_effective_start_date => l_eff_start_date
,p_effective_end_date => l_eff_end_date
--IN/OUT
,p_position_definition_id => l_position_definition_id
,p_name => l_pos_name
);
if l_position_id is null or l_object_version_number is null then
dbms_output.put_line('hr_position_api.create_position API Error: '||sqlerrm);
rollback;
else
commit;
end if;
--
exception
when others then
dbms_output.put_line('hr_position_api.create_position API failed with error :'||sqlerrm);
rollback;
end;
----------------------------------
----------------------------------
--Update Position
----------------------------------
declare
l_eff_start_date date;
l_eff_end_date date;
l_effective_date date := sysdate;
l_validate_mode boolean := false;
l_position_id per_positions.position_id%type;
l_object_version_number hr_all_positions_f.object_version_number%type;
l_position_definition_id number;
l_pos_name per_positions.name%type;
l_segment1 varchar2(20) := '123456';
l_pos_title_code fnd_lookup_values.lookup_code%type;
l_status varchar2(40);
l_valid_grades_changed_warning BOOLEAN;
--
begin
---
l_datetrack_mode := 'UPDATE';
l_position_id := 1918920;
l_position_definition_id := NULL;
l_eff_start_date := NULL;
l_eff_end_date := NULL;
l_pos_name := NULL;
l_effective_date := trunc(sysdate);
l_pos_number := '80304589.';
l_pos_title_code := 'MECH_TECH';
l_object_version_number := 3;
l_status := 'INVALID';
--
hr_position_api.update_position
( p_validate => l_validate_mode
,p_position_id => l_position_id
,p_effective_start_date => l_eff_start_date
,p_effective_end_date => l_eff_end_date
,p_position_definition_id => l_position_definition_id
,p_valid_grades_changed_warning => l_valid_grades_changed_warning
,p_status => l_status
,p_name => l_pos_name
,p_segment1 => l_segment1
,p_segment2 => l_pos_title_code
,p_object_version_number => l_object_version_number
,p_effective_date => l_effective_date
,p_datetrack_mode => l_datetrack_mode
);
dbms_output.put_line('Update Successful : ');
--Important: regenerate_position_name needs to be called when there is a name update
--
apps.hr_position_api.regenerate_position_name(l_position_id);
--
dbms_output.put_line('Regenerate Successful : ');
if l_object_version_number is null then
dbms_output.put_line('hr_position_api.update_position API Error: '||sqlerrm);
rollback;
elsif l_valid_grades_changed_warning then
dbms_output.put_line('Warning: Grade changed');
rollback;
else
commit;
end if;
--
exception
when others then
dbms_output.put_line('hr_position_api.update_position API failed with error :'||sqlerrm);
rollback;
end;
----------------------------------
--Delete Position
----------------------------------
declare
--
l_object_version_number number ;
l_pos_name hr_all_positions_f.name%type;
l_pos_id number ;
l_eff_start_date date;
l_eff_end_date date;
cursor cur_del_pos is
select max(pos.object_version_number) object_version_number
,pos.position_id
,pos.name
from hr_all_positions_f pos
where pos.position_id = 2182095
and pos.business_group_id = 101
group by position_id,name
;
--
begin
--
for i in cur_del_pos loop
l_object_version_number := i.object_version_number;
l_pos_id := i.position_id;
dbms_output.put_line('Deleting Position '||i.position_id);
hr_position_api.delete_position(
p_validate => false
,p_position_id => l_pos_id
,p_object_version_number => l_object_version_number
,p_effective_start_date => l_effective_start_date
,p_effective_end_date => l_effective_end_date
,p_effective_date => trunc(sysdate)
,p_datetrack_mode => 'ZAP'
);
end loop;
--
commit;
dbms_output.put_line('Success: ');
exception
when others then
dbms_output.put_line('Error: '||sqlerrm);
rollback;
end;
--Create Position
----------------------------------
declare
l_eff_start_date date;
l_eff_end_date date;
l_effective_date date := sysdate;
l_date_end date := hr_general.end_of_time;
l_job_id per_positions.job_id%type;
l_pos_org_id per_positions.position_id%type;
l_validate_mode boolean := false;
l_pos_type fnd_lookup_values.lookup_code%type;
l_avail_id per_shared_types.shared_type_id%type;
l_fte number;
l_max_persons number;
l_probation_period number;
l_probation_unit_desc varchar2(500);
l_business_group_id number := 101;
l_segment1 varchar2(20) := '123456';
l_orcl_pos_title_code fnd_lookup_values.lookup_code%type;
l_attribute8 hr_all_positions_f.attribute8%type;
l_attribute9 hr_all_positions_f.attribute9%type;
l_grade_id hr_all_positions_f.entry_grade_id%type;
l_barg_unit_cd hr_all_positions_f.bargaining_unit_cd%type;
l_attribute6 hr_all_positions_f.attribute6%type;
l_working_hours hr_all_positions_f.working_hours%type;
l_frequency hr_all_positions_f.frequency%type;
l_position_id per_positions.position_id%type;
l_object_version_number hr_all_positions_f.object_version_number%type;
l_position_definition_id number;
l_pos_name per_positions.name%type;
--
begin
---
l_pos_org_id := 9780;
l_effective_date := trunc(sysdate);
l_date_end := hr_general.end_of_time;
l_job_id := 1082;
l_pos_type := 'SHARED';
l_avail_id := 1;
l_fte := 1;
l_max_persons := 100;
l_probation_period := 6;
l_probation_unit_desc := 'M';
l_frequency := 'W';
l_working_hours := 37;
l_grade_id := 1124;
l_barg_unit_cd := 'EWP';
l_attribute6 := NULL;
l_orcl_pos_title_code := 'MECH_TECH';
--
l_position_id := NULL;
l_object_version_number := NULL;
l_eff_start_date := NULL;
l_eff_end_date := NULL;
l_position_definition_id := NULL;
l_pos_name := NULL;
--
hr_position_api.create_position
(
p_job_id => l_job_id --The job for the position
,p_organization_id => l_pos_org_id
,p_effective_date => l_effective_date
,p_date_effective => l_effective_date --The date on which the position becomes active
,p_date_end => l_date_end
,p_validate => l_validate_mode
,p_position_type => l_pos_type
,p_availability_status_id => l_avail_id
,p_fte => l_fte
,p_max_persons => l_max_persons
,p_probation_period => l_probation_period
,p_probation_period_unit_cd => l_probation_unit_desc
,p_business_group_id => l_business_group_id
,p_segment1 => l_segment1
,p_segment2 => l_orcl_pos_title_code
,p_attribute8 => l_attribute8
,p_attribute9 => l_attribute9
,p_entry_grade_id => l_grade_id
,p_bargaining_unit_cd => l_barg_unit_cd
,p_attribute6 => l_attribute6
--
,p_working_hours => l_working_hours
,p_frequency => l_frequency
--OUT
,p_position_id => l_position_id
,p_object_version_number => l_object_version_number
,p_effective_start_date => l_eff_start_date
,p_effective_end_date => l_eff_end_date
--IN/OUT
,p_position_definition_id => l_position_definition_id
,p_name => l_pos_name
);
if l_position_id is null or l_object_version_number is null then
dbms_output.put_line('hr_position_api.create_position API Error: '||sqlerrm);
rollback;
else
commit;
end if;
--
exception
when others then
dbms_output.put_line('hr_position_api.create_position API failed with error :'||sqlerrm);
rollback;
end;
----------------------------------
----------------------------------
--Update Position
----------------------------------
declare
l_eff_start_date date;
l_eff_end_date date;
l_effective_date date := sysdate;
l_validate_mode boolean := false;
l_position_id per_positions.position_id%type;
l_object_version_number hr_all_positions_f.object_version_number%type;
l_position_definition_id number;
l_pos_name per_positions.name%type;
l_segment1 varchar2(20) := '123456';
l_pos_title_code fnd_lookup_values.lookup_code%type;
l_status varchar2(40);
l_valid_grades_changed_warning BOOLEAN;
--
begin
---
l_datetrack_mode := 'UPDATE';
l_position_id := 1918920;
l_position_definition_id := NULL;
l_eff_start_date := NULL;
l_eff_end_date := NULL;
l_pos_name := NULL;
l_effective_date := trunc(sysdate);
l_pos_number := '80304589.';
l_pos_title_code := 'MECH_TECH';
l_object_version_number := 3;
l_status := 'INVALID';
--
hr_position_api.update_position
( p_validate => l_validate_mode
,p_position_id => l_position_id
,p_effective_start_date => l_eff_start_date
,p_effective_end_date => l_eff_end_date
,p_position_definition_id => l_position_definition_id
,p_valid_grades_changed_warning => l_valid_grades_changed_warning
,p_status => l_status
,p_name => l_pos_name
,p_segment1 => l_segment1
,p_segment2 => l_pos_title_code
,p_object_version_number => l_object_version_number
,p_effective_date => l_effective_date
,p_datetrack_mode => l_datetrack_mode
);
dbms_output.put_line('Update Successful : ');
--Important: regenerate_position_name needs to be called when there is a name update
--
apps.hr_position_api.regenerate_position_name(l_position_id);
--
dbms_output.put_line('Regenerate Successful : ');
if l_object_version_number is null then
dbms_output.put_line('hr_position_api.update_position API Error: '||sqlerrm);
rollback;
elsif l_valid_grades_changed_warning then
dbms_output.put_line('Warning: Grade changed');
rollback;
else
commit;
end if;
--
exception
when others then
dbms_output.put_line('hr_position_api.update_position API failed with error :'||sqlerrm);
rollback;
end;
----------------------------------
--Delete Position
----------------------------------
declare
--
l_object_version_number number ;
l_pos_name hr_all_positions_f.name%type;
l_pos_id number ;
l_eff_start_date date;
l_eff_end_date date;
cursor cur_del_pos is
select max(pos.object_version_number) object_version_number
,pos.position_id
,pos.name
from hr_all_positions_f pos
where pos.position_id = 2182095
and pos.business_group_id = 101
group by position_id,name
;
--
begin
--
for i in cur_del_pos loop
l_object_version_number := i.object_version_number;
l_pos_id := i.position_id;
dbms_output.put_line('Deleting Position '||i.position_id);
hr_position_api.delete_position(
p_validate => false
,p_position_id => l_pos_id
,p_object_version_number => l_object_version_number
,p_effective_start_date => l_effective_start_date
,p_effective_end_date => l_effective_end_date
,p_effective_date => trunc(sysdate)
,p_datetrack_mode => 'ZAP'
);
end loop;
--
commit;
dbms_output.put_line('Success: ');
exception
when others then
dbms_output.put_line('Error: '||sqlerrm);
rollback;
end;
thank you
ReplyDeleteThank you dear... :-)
ReplyDeleteYour good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
ReplyDeleteSurya Informatics
Can I update the attribute fields with the update position api?
ReplyDelete