DBA Data[Home] [Help]

PACKAGE BODY: APPS.GHR_CORR_CANC_SF52

Source


1 Package Body GHR_CORR_CANC_SF52 as
2 /* $Header: ghcorcan.pkb 120.53.12020000.5 2012/07/27 09:54:22 vmididho ship $ */
3 --
4 --
5 -- ----------------------------------------------------------------------------
6 -- |--------------------------< <Ghr_Corr_Canc_SF52> >--------------------------|
7 -- ----------------------------------------------------------------------------
8 --
9 
10 --
11 	TYPE pa_req_info is record (
12 		pa_request_id			ghr_pa_requests.pa_request_id%type,
13 		object_version_number		ghr_pa_requests.object_version_number%type,
14 		status				ghr_pa_requests.status%type,
15 		row_id				varchar2(20),
16                 cancel_legal_authority          ghr_pa_requests.first_action_la_code1%type
17 	);
18 
19 	cursor c_get_sf52 (c_pa_request_id in number) is
20 	select
21 		*
22 	from ghr_pa_requests
23 	where pa_request_id = c_pa_request_id;
24 
25 --
26 
27 -- Declaring local procedures and functions
28 Procedure	delete_element_entry(
29 				p_hist_rec 		in 	ghr_pa_history%rowtype,
30 				p_del_mode		in	varchar2 default hr_api.g_delete_next_change,
31    			p_cannot_cancel	 out nocopy Boolean) ;
32 
33 Procedure	delete_eleentval( p_hist_rec in ghr_pa_history%rowtype) ;
34 Procedure	delete_peop_row(
35 				p_person_id		in	varchar2,
36   				p_dt_mode		in	varchar2,
37   				p_date_effective	in	date) ;
38 Procedure	delete_asgn_row(
39 				p_assignment_id	in	varchar2,
40   				p_dt_mode		in	varchar2,
41   				p_date_effective	in	date) ;
42 Procedure	delete_peopei_row( p_person_extra_info_id	in	varchar2) ;
43 Procedure	delete_asgnei_row( p_assignment_extra_info_id	in	varchar2) ;
44 Procedure	delete_posnei_row( p_position_extra_info_id	in	varchar2) ;
45 Procedure	delete_address_row(p_address_id	in	varchar2) ;
46 Procedure	delete_person_analyses_row ( p_person_analysis_id	in	number);
47 
48 Procedure	delete_appl_row(
49 				p_table_name	in	varchar2,
50   				p_table_pk_id	in	varchar2,
51   				p_dt_mode		in	varchar2,
52   				p_date_effective	in	date) ;
53 Procedure	delete_hist_row (
54 				p_row_id 			in	rowid);
55 Procedure	delete_hist_row (
56 				p_pa_history_id 	in	ghr_pa_history.pa_history_id%type);
57 Procedure	apply_correction(
58 				p_sf52rec_correct  	in 		ghr_pa_requests%rowtype,
59 				p_corr_pa_request_id	in		ghr_pa_requests.pa_request_id%type,
60 			 	p_sf52rec   		in out nocopy 	ghr_pa_requests%rowtype ) ;
61 Procedure apply_noa_corrections(
62 				p_sf52_data		in	ghr_pa_requests%rowtype,
63 				p_sf52_data_result in out nocopy ghr_pa_requests%rowtype );
64 Procedure Undo_Mark_Cancel(
65 				p_sf52_data  in  ghr_pa_requests%rowtype);
66 
67 Procedure what_to_do(	p_datetrack_table		in		boolean,
68 				p_pre_record_exists 	in 		boolean,
69 				p_interv_on_table		in		boolean,
70 				p_interv_on_eff_date	in		boolean,
71 				p_rec_created_flag	in		boolean,
72 				p_can_delete	 out nocopy 	boolean,
73 				p_last_row		 out nocopy 	boolean,
74 				p_cannot_cancel	 out nocopy 	boolean) ;
75 
76 Procedure convert_shadow_to_sf52 (
77 				p_shadow	 in   ghr_pa_request_shadow%rowtype,
78 				p_sf52 out nocopy ghr_pa_requests%rowtype);
79 
80 Procedure IF_ZAP_ELE_ENT(
81 				p_element_entry_id	in	number,
82 				p_effective_start_date	in	date,
83 				p_pa_history_id		in	number,
84 				p_result	 out nocopy Boolean);
85 
86 -- VSM [Procedures for delete subsequent correction functionality]
87 Procedure Process_Cancel (
88 	p_sf52_data in out nocopy ghr_pa_requests%rowtype);
89 
90 Procedure Cancel_subs_correction (
91 	p_corr_sf52_detail in out nocopy pa_req_info,
92 		p_which_noa        in number);
93 
94 -- Bug#2521744
95 -- This procedure will delete the first datetrack row for the
96 -- other pay elements/other elements whereever necessary.
97 Procedure delete_other_pay_entries(p_hist_rec in ghr_pa_history%rowtype,
98                                     p_element_name in varchar2);
99 
100 -- This procedure will get the other pay component values
101 -- at the time of intervening correction.
102 PROCEDURE get_sf52_to_othpays_for_ia
103             (p_sf52_ia_rec in out nocopy ghr_pa_requests%rowtype);
104 -- End of Bug#2521744
105 
106 Function get_sf52_ovn ( p_pa_request_id in number) return number;
107 --
108 
109 -- 6850492 Added this procedure for dual action corrections
110 Procedure  apply_dual_noa_corrections(p_sf52_data		in	ghr_pa_requests%rowtype,
111 				      p_sf52_data_result in out nocopy ghr_pa_requests%rowtype );
112 
113 
114 
115 ----- End of Local procedure declaration -------
116 
117 -- ---------------------------------------------------------------------------
118 -- |--------------------------< cancel_term_sf52>---------------------------|
119 -- ---------------------------------------------------------------------------
120 -- {Start Of Comments}
121 --
122 -- Description:
123 --   	This procedure cancels a termination sf52.
124 --
125 -- Pre-Requisities:
126 --   	None.
127 --
128 -- In Parameters:
129 --	p_sf52_data		->		ghr_pa_requests record of the cancellation sf52.
130 --
131 -- Post Success:
132 -- 	The termination sf52 will have been cancelled.
133 --
134 -- Post Failure:
135 --   No failure conditions.
136 --
137 -- Developer Implementation Notes:
138 --   None
139 --
140 -- Access Status:
141 --   Internal Development Use Only.
142 --
143 -- {End Of Comments}
144 -- ---------------------------------------------------------------------------
145 
146 Procedure cancel_term_SF52 ( p_sf52_data	in out nocopy ghr_pa_requests%rowtype) is
147 
148 	-- this cursor gets the rowids from ghr_pa_history for the given pa_request_id.
149 	cursor c_hist ( c_pa_request_id	number,
150 			    c_noa_id		number) is
151 	select
152 		rowid row_id, table_name,pa_history_id,information5
153                 ,information9, information10
154 	from ghr_pa_history
155 	where pa_request_id = c_pa_request_id
156 	and  nature_of_action_id = c_noa_id
157 	for update of person_id
158         order by pa_history_id desc; -- Bug# 1316321
159 
160 
161 	cursor c_follow_rec( 	c_table_name	ghr_pa_history.table_name%type,
162 					c_pk_id		ghr_pa_history.information1%type,
163 					c_pa_history_id	ghr_pa_history.pa_history_id%type) is
164 	select 	pa_history_id
165 	from		ghr_pa_history
166 	where		table_name		= c_table_name
167 		and	information1	= c_pk_id
168 		and 	pa_history_id	> c_pa_history_id;
169 
170 
171         cursor c_hist_sevpay ( c_pa_request_id  number,
172                             c_table_name       ghr_pa_history.table_name%type) IS
173         select  *
174         from ghr_pa_history
175         where pa_request_id = c_pa_request_id
176           and table_name    = c_table_name;
177 
178 
179 	l_buf				number;
180 	l_follow_rec		boolean;
181 	l_hist_pre			ghr_pa_history%rowtype;
182 	l_hist_rec			ghr_pa_history%rowtype;
183         l_hist_sevpay                   ghr_pa_history%rowtype;
184         l_cannot_cancel_sevpay          boolean;
185 	l_interv_on_table		boolean;
186 	l_interv_on_eff_date	boolean;
187 	l_hist_data_as_of_date	ghr_pa_history%rowtype;
188 	l_session_var	ghr_history_api.g_session_var_type;
189 	l_agency_ei_data	ghr_pa_request_extra_info%rowtype;
190 	l_imm_asg_sf52          	ghr_api.asg_sf52_type;
191 	l_imm_asg_non_sf52		ghr_api.asg_non_sf52_type;
192 	l_imm_asg_nte_dates     	ghr_api.asg_nte_dates_type;
193 	l_imm_asg_detail_info		ghr_api.asg_detail_info_type; --Bug# 8653508
194 	l_imm_per_sf52          	ghr_api.per_sf52_type;
195 	l_imm_per_group1        	ghr_api.per_group1_type;
196 	l_imm_per_group2        	ghr_api.per_group2_type;
197 	l_imm_per_scd_info      	ghr_api.per_scd_info_type;
198 	l_imm_per_retained_grade    ghr_api.per_retained_grade_type;
199 	l_imm_per_probations        ghr_api.per_probations_type;
200 	l_imm_per_sep_retire        ghr_api.per_sep_retire_type;
201 	l_imm_per_security		    ghr_api.per_security_type;
202 	-- Bug#4486823 RRR changes
203 	l_imm_per_service_oblig     ghr_api.per_service_oblig_type;
204 	l_imm_per_conversions		ghr_api.per_conversions_type;
205 	-- 4352589 BEN_EIT Changes
206 	l_imm_per_benefit_info        ghr_api.per_benefit_info_type;
207 	l_imm_per_uniformed_services  ghr_api.per_uniformed_services_type;
208 	l_imm_pos_oblig               ghr_api.pos_oblig_type;
209 	l_imm_pos_grp2                ghr_api.pos_grp2_type;
210 	l_imm_pos_grp1                ghr_api.pos_grp1_type;
211 	l_imm_pos_valid_grade         ghr_api.pos_valid_grade_type;
212 	l_imm_pos_car_prog            ghr_api.pos_car_prog_type;
213 	l_imm_loc_info                ghr_api.loc_info_type;
214 	l_imm_wgi     	            ghr_api.within_grade_increase_type;
215 	l_imm_gov_awards              ghr_api.government_awards_type;
216 	l_imm_recruitment_bonus	      ghr_api.recruitment_bonus_type;
217 	l_imm_relocation_bonus		ghr_api.relocation_bonus_type;
218 	l_imm_student_loan_repay  	ghr_api.student_loan_repay_type;
219 	--Pradeep
220 	l_imm_mddds_special_pay         ghr_api.mddds_special_pay_type;
221 	l_imm_premium_pay_ind           ghr_api.premium_pay_ind_type;
222 
223 	l_imm_extra_info_rec	 	ghr_api.extra_info_rec_type ;
224 	l_imm_sf52_from_data          ghr_api.prior_sf52_data_type;
225 	l_imm_personal_info		ghr_api.personal_info_type;
226 	l_imm_generic_extra_info_rec	ghr_api.generic_extra_info_rec_type ;
227 	l_imm_agency_sf52		      ghr_api.agency_sf52_type;
228 	l_agency_code			varchar2(50);
229 	l_imm_perf_appraisal          ghr_api.performance_appraisal_type;
230 	l_imm_conduct_performance     ghr_api.conduct_performance_type;
231 	l_imm_payroll_type            ghr_api.government_payroll_type;
232 	l_imm_par_term_retained_grade ghr_api.par_term_retained_grade_type;
233 	l_imm_entitlement             ghr_api.entitlement_type;
234         -- Bug#2759379 Added FEGLI Record
235         l_imm_fegli                   ghr_api.fegli_type;
236 	l_imm_foreign_lang_prof_pay   ghr_api.foreign_lang_prof_pay_type;
237 	-- Bug#3385386 Added FTA Record
238 	l_imm_fta                     ghr_api.fta_type;
239 	l_imm_edp_pay                 ghr_api.edp_pay_type;
240 	l_imm_hazard_pay              ghr_api.hazard_pay_type;
241 	l_imm_health_benefits         ghr_api.health_benefits_type;
242 	l_imm_danger_pay              ghr_api.danger_pay_type;
243 	l_imm_imminent_danger_pay     ghr_api.imminent_danger_pay_type;
244 	l_imm_living_quarters_allow   ghr_api.living_quarters_allow_type;
245 	l_imm_post_diff_amt           ghr_api.post_diff_amt_type;
246 	l_imm_post_diff_percent       ghr_api.post_diff_percent_type;
247 	l_imm_sep_maintenance_allow   ghr_api.sep_maintenance_allow_type;
248 	l_imm_supplemental_post_allow ghr_api.supplemental_post_allow_type;
249 	l_imm_temp_lodge_allow        ghr_api.temp_lodge_allow_type;
250  	l_imm_premium_pay             ghr_api.premium_pay_type;
251  	l_imm_retirement_annuity      ghr_api.retirement_annuity_type;
252 	l_imm_severance_pay           ghr_api.severance_pay_type;
253  	l_imm_thrift_saving_plan      ghr_api.thrift_saving_plan;
254  	l_imm_retention_allow_review  ghr_api.retention_allow_review_type;
255 	l_imm_health_ben_pre_tax      ghr_api.health_ben_pre_tax_type;
256 	l_imm_per_race_ethnic_info 	  ghr_api.per_race_ethnic_type; -- Bug 4724337 Race or National Origin changes
257         --Bug# 6312144
258         l_imm_ipa_benefits_cont       ghr_api.per_ipa_ben_cont_info_type;
259         l_imm_retirement_info         ghr_api.per_retirement_info_type;
260 	--BUG # 13571004
261 	l_imm_roth_tsp                ghr_api.tsp_roth_type;
262 
263 	l_sf52_data	              ghr_pa_requests%rowtype;
264 	l_sf52_data_rec           ghr_pa_requests%rowtype;
265 	l_health_plan	              varchar2(30);
266 	l_error_flag		      boolean;
267 	l_return_status	varchar2(30);
268 
269         l_position_definition_id      number;
270         l_pos_name                    varchar2(2000);
271         l_valid_grades_changed_warning boolean;
272         l_object_version_number       number;
273         l_effective_start_date        date;
274         l_effective_end_date          date;
275 
276 	l_result		varchar2(30);
277 	l_proc	varchar2(30):='cancel_term_SF52';
278 --
279 
280 Begin
281 
282 	hr_utility.set_location( 'entering : ' || l_proc, 10);
283    l_sf52_data_rec := p_sf52_data;
284 --
285 --
286 	-- reinitialise session variables
287 	ghr_history_api.reinit_g_session_var;
288 	-- set values of session variables
289 
290 	l_session_var.pa_request_id 	:= p_sf52_data.pa_request_id;
291 	l_session_var.noa_id		:= p_sf52_data.second_noa_id;
292 	-- No triggers should be fired as cancellation can not be corrected or cancelled
293 	-- so none of the changes will be saved.
294 	l_session_var.fire_trigger	:= 'N';
295 	l_session_var.date_Effective	:= p_sf52_data.effective_date;
296 	l_session_var.person_id		:= p_sf52_data.person_id;
297 	l_session_var.program_name	:= 'sf50';
298 	l_session_var.assignment_id	:= p_sf52_data.employee_assignment_id;
299 	l_session_var.altered_pa_request_id	:= p_sf52_data.altered_pa_request_id;
300 	l_session_var.noa_id_correct	:= p_sf52_data.second_noa_id;
301 	ghr_history_api.set_g_session_var(l_session_var);
302 
303 	ghr_process_Sf52.Fetch_extra_info(
304 			p_pa_request_id 	=> p_sf52_data.pa_request_id,
305 			p_noa_id   		=> p_sf52_data.second_noa_id,
306 			p_agency_ei		=> TRUE,
307 			p_sf52_ei_data 	=> l_agency_ei_data,
308 			p_result		=> l_result);
309 
310 	l_sf52_data 	:= p_sf52_data;
311 	-- all corrections will have the original sf52 information in the 2nd noa columns, so
312 	-- copy that information to 1st noa columns.
313 	ghr_process_sf52.copy_2ndNoa_to_1stNoa(l_sf52_data);
314 	-- null the second noa columns since we don't want anything to be done with these now.
315 	ghr_process_sf52.null_2ndNoa_cols(l_sf52_data);
316 	ghr_sf52_pre_update.populate_record_groups (
317 		 	p_pa_request_rec                => l_sf52_data,
318 			p_generic_ei_rec                => l_agency_ei_data,
319 			p_imm_asg_sf52                  => l_imm_asg_sf52,
320 			p_imm_asg_non_sf52              => l_imm_asg_non_sf52,
321 			p_imm_asg_nte_dates             => l_imm_asg_nte_dates,
322 			p_imm_asg_detail_info	        => l_imm_asg_detail_info, --Bug# 8653508
323 			p_imm_per_sf52                  => l_imm_per_sf52,
324 			p_imm_per_group1                => l_imm_per_group1,
325 			p_imm_per_group2                => l_imm_per_group2,
326 			p_imm_per_scd_info              => l_imm_per_scd_info,
327 			p_imm_per_retained_grade        => l_imm_per_retained_grade,
328 			p_imm_per_probations            => l_imm_per_probations,
329 			p_imm_per_sep_retire            => l_imm_per_sep_retire,
330 			p_imm_per_security              => l_imm_per_security,
331 			--Bug#4486823 RRR Changes
332             p_imm_per_service_oblig         => l_imm_per_service_oblig,
333 			p_imm_per_conversions           => l_imm_per_conversions,
334 			-- 4352589 BEN_EIT Changes
335 			p_imm_per_benefit_info          => l_imm_per_benefit_info,
336 			p_imm_per_uniformed_services    => l_imm_per_uniformed_services,
337 			p_imm_pos_oblig                 => l_imm_pos_oblig,
338 			p_imm_pos_grp2                  => l_imm_pos_grp2,
339 			p_imm_pos_grp1                  => l_imm_pos_grp1,
340 			p_imm_pos_valid_grade           => l_imm_pos_valid_grade,
341 			p_imm_pos_car_prog              => l_imm_pos_car_prog,
342 			p_imm_loc_info                  => l_imm_loc_info,
343 			p_imm_wgi                       => l_imm_wgi,
344 			p_imm_gov_awards                => l_imm_gov_awards,
345 			p_imm_recruitment_bonus         => l_imm_recruitment_bonus,
346 			p_imm_relocation_bonus          => l_imm_relocation_bonus,
347 			p_imm_student_loan_repay        => l_imm_student_loan_repay,
348 			p_imm_per_race_ethnic_info 		=> l_imm_per_race_ethnic_info, -- Bug 4724337 Race or National Origin changes
349 			--Pradeep
350 			p_imm_mddds_special_pay         => l_imm_mddds_special_pay,
351 			p_imm_premium_pay_ind           => l_imm_premium_pay_ind,
352 
353 			p_imm_perf_appraisal            => l_imm_perf_appraisal,
354 			p_imm_conduct_performance       => l_imm_conduct_performance,
355 			p_imm_payroll_type              => l_imm_payroll_type,
356 			p_imm_extra_info_rec	        => l_imm_extra_info_rec,
357 			p_imm_sf52_from_data            => l_imm_sf52_from_data,
358 			p_imm_personal_info	        	=> l_imm_personal_info,
359 			p_imm_generic_extra_info_rec    => l_imm_generic_extra_info_rec,
360 			p_imm_agency_sf52               => l_imm_agency_sf52,
361 			p_agency_code                   => l_agency_code,
362 			p_imm_par_term_retained_grade   => l_imm_par_term_retained_grade,
363 			p_imm_entitlement               => l_imm_entitlement,
364                         -- Bug#2759379 Added FEGLI Record
365             p_imm_fegli                     => l_imm_fegli,
366 			p_imm_foreign_lang_prof_pay     => l_imm_foreign_lang_prof_pay,
367 			-- Bug#3385386 Added FTA Record
368 			p_imm_fta                       => l_imm_fta,
369 			p_imm_edp_pay                   => l_imm_edp_pay,
370 			p_imm_hazard_pay                => l_imm_hazard_pay,
371 			p_imm_health_benefits           => l_imm_health_benefits,
372 			p_imm_danger_pay                => l_imm_danger_pay,
373 			p_imm_imminent_danger_pay       => l_imm_imminent_danger_pay,
374 			p_imm_living_quarters_allow     => l_imm_living_quarters_allow,
375 			p_imm_post_diff_amt             => l_imm_post_diff_amt,
376 			p_imm_post_diff_percent         => l_imm_post_diff_percent,
377 			p_imm_sep_maintenance_allow     => l_imm_sep_maintenance_allow,
378 			p_imm_supplemental_post_allow   => l_imm_supplemental_post_allow,
379 			p_imm_temp_lodge_allow          => l_imm_temp_lodge_allow,
380 			p_imm_premium_pay               => l_imm_premium_pay,
381 			p_imm_retirement_annuity        => l_imm_retirement_annuity,
382 			p_imm_severance_pay             => l_imm_severance_pay,
383 			p_imm_thrift_saving_plan        => l_imm_thrift_saving_plan,
384 			p_imm_retention_allow_review    => l_imm_retention_allow_review,
385 			p_imm_health_ben_pre_tax        => l_imm_health_ben_pre_tax,
386 			--Bug# 6312144 RPA EIT Benefits
387 			p_imm_ipa_benefits_cont         => l_imm_ipa_benefits_cont,
388                         p_imm_retirement_info           => l_imm_retirement_info,
389 			--BUG # 13571004 added TSP Roth
390                         p_imm_tsp_roth                  => l_imm_roth_tsp
391                          );
392 --
393    		ghr_api.retrieve_element_entry_value
394 		( p_element_name	=> 'Health Benefits'
395 		 ,p_input_value_name    =>  'Health Plan'
396 		 ,p_assignment_id       =>   l_sf52_data.employee_assignment_id
397 		 ,p_effective_date      =>   trunc(l_sf52_data.effective_date)
398 		 ,p_value               =>   l_health_plan
399 		 ,p_multiple_error_flag =>   l_error_flag
400 		 );
401 --
402 	GHR_AGENCY_CHECK.AGENCY_CHECK(
403 			p_pa_request_rec			=> l_sf52_data,
404 			p_asg_sf52					=> l_imm_asg_sf52,
405 			p_asg_non_sf52				=> l_imm_asg_non_sf52,
406 			p_asg_nte_dates				=> l_imm_asg_nte_dates,
407 			p_per_sf52              	=> l_imm_per_sf52,
408 			p_per_group1            	=> l_imm_per_group1,
409 			p_per_group2            	=> l_imm_per_group2,
410 			p_per_scd_info          	=> l_imm_per_scd_info,
411 			p_per_retained_grade    	=> l_imm_per_retained_grade,
412 			p_per_probations			=> l_imm_per_probations,
413 			p_per_sep_Retire 	      	=> l_imm_per_sep_retire,
414 			p_per_security          	=> l_imm_per_security,
415 			p_per_conversions	      	=> l_imm_per_conversions,
416 			p_per_uniformed_services	=> l_imm_per_uniformed_services,
417 			p_pos_oblig                   => l_imm_pos_oblig,
418 			p_pos_grp2                    => l_imm_pos_grp2,
419 			p_pos_grp1                    => l_imm_pos_grp1,
420 			p_pos_valid_grade             => l_imm_pos_valid_grade,
421 			p_pos_car_prog                => l_imm_pos_car_prog,
422 			p_loc_info                    => l_imm_loc_info,
423 			p_wgi                         => l_imm_wgi,
424 			p_recruitment_bonus	      => l_imm_recruitment_bonus,
425 			p_relocation_bonus	      => l_imm_relocation_bonus ,
426 			p_sf52_from_data              => l_imm_sf52_from_data,
427 			p_personal_info	            => l_imm_personal_info,
428 			p_gov_awards_type             => l_imm_gov_awards,
429 			p_perf_appraisal_type         => l_imm_perf_appraisal,
430 			p_payroll_type                => l_imm_payroll_type,
431 			p_conduct_perf_type           => l_imm_conduct_performance,
432 			p_agency_code		      => l_agency_code,
433 			p_agency_sf52			=> l_imm_agency_sf52,
434 			p_health_plan			=> l_health_plan,
435 			p_entitlement                 => l_imm_entitlement,
436 			p_foreign_lang_prof_pay       => l_imm_foreign_lang_prof_pay,
437 			p_edp_pay                     => l_imm_edp_pay,
438 			p_hazard_pay                  => l_imm_hazard_pay,
439 			p_health_benefits             => l_imm_health_benefits,
440 			p_danger_pay                  => l_imm_danger_pay,
441 			p_imminent_danger_pay         => l_imm_imminent_danger_pay,
442 			p_living_quarters_allow       => l_imm_living_quarters_allow,
443 			p_post_diff_amt               => l_imm_post_diff_amt,
444 			p_post_diff_percent           => l_imm_post_diff_percent,
445 			p_sep_maintenance_allow       => l_imm_sep_maintenance_allow,
446 			p_supplemental_post_allow     => l_imm_supplemental_post_allow,
447 			p_temp_lodge_allow            => l_imm_temp_lodge_allow,
448 			p_premium_pay                 => l_imm_premium_pay,
449 			p_retirement_annuity          => l_imm_retirement_annuity,
450 			p_severance_pay               => l_imm_severance_pay,
451 			p_thrift_saving_plan          => l_imm_thrift_saving_plan,
452 			p_retention_allow_review      => l_imm_retention_allow_review,
453 			p_health_ben_pre_tax          => l_imm_health_ben_pre_tax,
454 			p_per_benefit_info            => l_imm_per_benefit_info,
455 			p_imm_retirement_info         => l_imm_retirement_info, --Bug# 7131104
456 			--Begin Bug# 10181661
457 			p_asg_detail_info	      => l_imm_asg_detail_info,
458 			p_ipa_detail_ben_cont_info    => l_imm_ipa_benefits_cont
459 			--End Bug# 10181661
460 			);
461 
462         -- call to cancel termination moved after history handling. Bug# 1316321
463 
464 	-- if this was a 352 termination, then the following special handling is required.
465 	if p_sf52_data.second_noa_code = '352' then
466 		-- null out end_date for position
467 
468                 -- Added by Edward Nunez (Position Date Track Changes Phase 2).
469 /*
470             -- Deleting of Position Rows handled by code below ref bug 2983738.
471 		-- Need to delete end dated position record only if it's MTO -- Sundar 2835138
472 		IF (UPPER(SUBSTR(p_sf52_data.request_number,1,3)) = 'MTO') THEN
473 		-- End 2835138
474                 SELECT name, object_version_number
475                   INTO l_pos_name, l_object_version_number
476                 FROM hr_all_positions_f
477                 WHERE position_id = p_sf52_data.from_position_id
478                   AND (p_sf52_data.effective_date  - 1) BETWEEN effective_start_date
479                                                      AND effective_end_date;
480                  hr_position_api.delete_position
481                  (p_position_id                   => p_sf52_data.from_position_id,
482                   p_object_version_number         => l_object_version_number,
483                   p_effective_date                => p_sf52_data.effective_date - 1,
484                   p_effective_start_date          => l_effective_start_date,
485                   p_effective_end_date            => l_effective_end_date,
486                   p_datetrack_mode                => 'DELETE_NEXT_CHANGE'
487                   );
488 		END IF; -- If MTO
489 */
490                 --
491 
492 /*  -- Commented out by Edward Nunez (Position Date Track changes Phase 2).
493 		UPDATE 	per_positions
494 		SET 		date_end = null
495 		WHERE	 	position_id = p_sf52_data.from_position_id;
496 */
497 
498 		-- Bug # 9081332 Added the Exception to handle if there are no rows exists
499 
500 		BEGIN
501 		SELECT 	*
502 		INTO 	l_hist_rec
503 		FROM 	ghr_pa_history
504 		WHERE	pa_request_id 		= p_sf52_data.altered_pa_request_id
505 		AND	information5 		= 'GHR_US_PER_SEPARATE_RETIRE'
506 		AND	table_name			= ghr_history_api.g_peopei_table
507 		AND	nature_of_action_id 	= (select nature_of_action_id from ghr_nature_of_actions where
508 									code = '352');
509 
510 
511 
512  		ghr_history_api.fetch_history_info(
513  			p_table_name 		=> ghr_history_api.g_peopei_table,
514   			p_hist_data			=> l_hist_pre,
515   			p_pa_history_id		=> l_hist_rec.pa_history_id,
516   			p_table_pk_id 		=> l_hist_rec.information1,
517   			p_person_id			=> p_sf52_data.person_id,
518   			p_date_effective		=> p_sf52_data.effective_date,
519   			p_result_code		=> l_return_status);
520   		if (l_return_status is not null) then
521 			-- there were no prevalues for this record
522 		      hr_utility.set_location('no pre-values'|| l_proc,15);
523 			-- only delete application table if there are no following records.
524 			open c_follow_rec(	c_table_name	=>	l_hist_rec.table_name,
525 							c_pk_id		=>	l_hist_rec.information1,
526 							c_pa_history_id	=>	l_hist_rec.pa_history_id);
527 			fetch c_follow_rec into l_buf;
528 			if c_follow_rec%NOTFOUND then
529 		      hr_utility.set_location('no following records. Deleting appl table. '|| l_proc,915);
530 			delete_appl_row(
531 				p_table_name	=> ghr_history_api.g_peopei_table,
532 				p_table_pk_id	=> l_hist_rec.information1,
533 				p_dt_mode		=> null,
534 				p_date_effective	=> l_hist_rec.effective_date);
535 			end if;
536 			close c_follow_rec;
537 
538 		else
539 			-- there is a pre record, so apply it to the history table and to the application table.
540  			ghr_history_cascade.cascade_history_data (
541   				p_table_name		=> 	l_hist_rec.table_name,
542   				p_person_id			=>	l_hist_rec.person_id,
543   				p_pre_record		=>	l_hist_pre,
544   				p_post_record		=>	l_hist_rec,
545   				p_cascade_type		=>	'cancel',
546   				p_interv_on_table 	=>	l_interv_on_table,
547   				p_interv_on_eff_date	=>	l_interv_on_eff_date,
548   				p_hist_data_as_of_date	=>	l_hist_data_as_of_date);
549  			ghr_history_cascade.cascade_appl_table_data (
550   				p_table_name		=> 	l_hist_rec.table_name,
551   				p_person_id			=>	l_hist_rec.person_id,
552   				p_pre_record		=>	l_hist_pre,
553   				p_post_record		=>	l_hist_rec,
554   				p_cascade_type		=>	'cancel',
555   				p_interv_on_table 	=>	l_interv_on_table,
556   				p_interv_on_eff_date	=>	l_interv_on_eff_date,
557   				p_hist_data_as_of_date	=>	l_hist_data_as_of_date);
558 
559  		end if;
560 		EXCEPTION
561 		WHEN NO_DATA_FOUND THEN
562 		     NULL;
563 		END;
564 
565 	end if;
566 
567 -- Bug#2082535
568      Open c_hist_sevpay(p_sf52_data.altered_pa_request_id,ghr_history_api.g_eleent_table);
569         fetch c_hist_sevpay into l_hist_sevpay;
570         if c_hist_sevpay%notfound then
571                 -- raise error;
572                 close c_hist_sevpay;
573         else
574 
575           delete_element_entry( p_hist_rec   => l_hist_sevpay,
576                          p_del_mode          => hr_api.g_zap,
577                          p_cannot_cancel     => l_cannot_cancel_sevpay);
578 
579           if l_cannot_cancel_sevpay then
580             -- raise error
581            hr_utility.set_location('ERROR: Cannot Cancel'|| l_proc,35);
582            hr_utility.set_message(8301,'GHR_38212_CANNOT_CANCEL');
583            hr_utility.raise_error;
584           else
585            hr_utility.set_location('Delete rows.'|| l_proc,40);
586            delete_hist_row ( l_hist_sevpay.pa_history_id);
587            delete_eleentval( l_hist_sevpay);
588           end if;
589           close c_hist_sevpay;
590         end if;
591 
592 -- Bug#2082535
593 
594 	-- delete all history records for the termination that is being cancelled.
595 	-- if an address table record is encountered, then set application
596 	-- table to what it currently should be according to history.
597 	hr_utility.set_location( l_proc, 20);
598 	for l_hist in c_hist( p_sf52_data.altered_pa_request_id,
599 				    l_session_var.noa_id_correct)
600 	loop
601                 hr_utility.set_location(' LOOP history_id(' || l_hist.pa_history_id || ')', 25);
602 		exit when c_hist%notfound;
603 		-- Bug#3780671 Added the Assignment Extra Info condition as
604 		-- the EIT "GHR_US_ASG_NTE_DATES" requires the process similar to
605 		-- Address table.
606 		IF (l_hist.table_name = ghr_history_api.g_addres_table) OR
607 		   (l_hist.table_name = 'PER_ASSIGNMENT_EXTRA_INFO' and
608                     l_hist.information5 = 'GHR_US_ASG_NTE_DATES') THEN
609 
610 			SELECT 	*
611 			INTO 		l_hist_rec
612 			FROM 		ghr_pa_history
613 			WHERE		pa_history_id	= l_hist.pa_history_id;
614 
615                         hr_utility.set_location('Non 352 and  Address '||l_hist.table_name,26);
616 			-- Bug#3780671 Passed the parameter l_hist.table_name instead of Address table
617 			--             to handle PER_ASSIGNMENT_EXTRA_INFO table.
618 	 		ghr_history_api.fetch_history_info(
619 	 			p_table_name 		=> l_hist.table_name,
620   				p_hist_data		=> l_hist_pre,
621   				p_pa_history_id		=> l_hist_rec.pa_history_id,
622   				p_table_pk_id 		=> l_hist_rec.information1,
623   				p_person_id		=> p_sf52_data.person_id,
624   				p_date_effective	=> p_sf52_data.effective_date,
625   				p_result_code		=> l_return_status);
626   			if (l_return_status is not null) then
627 				-- there were no prevalues for this record
628 			    	hr_utility.set_location('no pre-values'|| l_proc,15);
629 				-- only delete application table if there are no following records.
630 				open c_follow_rec(	c_table_name	=>	l_hist_rec.table_name,
631 								c_pk_id		=>	l_hist_rec.information1,
632 								c_pa_history_id	=>	l_hist_rec.pa_history_id);
633 				fetch c_follow_rec into l_buf;
634 				if c_follow_rec%NOTFOUND then
635 				        -- Bug#3780671 Passed the parameter l_hist.table_name instead of Address table
636 			                --             to handle PER_ASSIGNMENT_EXTRA_INFO table.
637 					delete_appl_row(
638 						p_table_name	=> l_hist.table_name,
639 						p_table_pk_id	=> l_hist_rec.information1,
640 						p_dt_mode		=> null,
641 						p_date_effective	=> l_hist_rec.effective_date);
642 				end if;
643 				close c_follow_rec;
644 			else
645 				-- there is a pre record, so apply it to the history table and to the application table.
646  				ghr_history_cascade.cascade_history_data (
647   					p_table_name		=> 	l_hist_rec.table_name,
648   					p_person_id			=>	l_hist_rec.person_id,
649   					p_pre_record		=>	l_hist_pre,
650   					p_post_record		=>	l_hist_rec,
651   					p_cascade_type		=>	'cancel',
652   					p_interv_on_table 	=>	l_interv_on_table,
653   					p_interv_on_eff_date	=>	l_interv_on_eff_date,
654   					p_hist_data_as_of_date	=>	l_hist_data_as_of_date);
655 				delete_hist_row( l_hist.row_id);
656 				ghr_history_cascade.cascade_appl_table_data (
657 					p_table_name		=> 	l_hist_rec.table_name,
658 					p_person_id			=>	l_hist_rec.person_id,
659 					p_pre_record		=>	l_hist_pre,
660 					p_post_record		=>	l_hist_rec,
661 					p_cascade_type		=>	'cancel',
662 					p_interv_on_table 	=>	l_interv_on_table,
663 					p_interv_on_eff_date	=>	l_interv_on_eff_date,
664 					p_hist_data_as_of_date	=>	l_hist_data_as_of_date);
665 			end if;
666 
667 --		else
668                 hr_utility.set_location('Non 352 and  delete_hist_row '||l_proc,27);
669 --			delete_hist_row( l_hist.row_id);
670 		end if;
671 	end loop;
672 
673 	-- delete all history records for the termination that is being cancelled.
674 	-- if an address table record is encountered, then set application
675 	-- table to what it currently should be according to history.
676 	hr_utility.set_location( l_proc, 20);
677 	for l_hist in c_hist( p_sf52_data.altered_pa_request_id,
678 				    l_session_var.noa_id_correct)
679 	loop
680           exit when c_hist%notfound;
681           delete_hist_row( l_hist.row_id);
682         end loop;
683 
684         -- Moved after history handling due to bug# 1316321
685 	-- call core HR api to cancel the termination.
686 	hrempter.cancel_termination(
687 		p_person_id				=> p_sf52_data.person_id,
688 		p_Actual_termination_date 	=> p_sf52_data.effective_date
689          	);
690 -- added to resolve bug#2205014
691 -- Commented the following procedure call as this is included in hrempter.cancel_termination
692 -- through Core HR Bug#3889294
693 /*      hr_per_type_usage_internal.cancel_person_type_usage
694         (p_effective_date       => p_sf52_data.effective_date + 1
695         ,p_person_id            => p_sf52_data.person_id
696         ,p_system_person_type   => 'EX_EMP');
697 */
698 
699 
700 	ghr_agency_update.ghr_agency_upd(
701 			p_pa_request_rec			=> l_sf52_data,
702 			p_asg_sf52				=> l_imm_asg_sf52,
703 			p_asg_non_sf52			=> l_imm_asg_non_sf52,
704 			p_asg_nte_dates			=> l_imm_asg_nte_dates,
705 			p_per_sf52              	=> l_imm_per_sf52,
706 			p_per_group1            	=> l_imm_per_group1,
707 			p_per_group2            	=> l_imm_per_group2,
708 			p_per_scd_info          	=> l_imm_per_scd_info,
709 			p_per_retained_grade    	=> l_imm_per_retained_grade,
710 			p_per_probations			=> l_imm_per_probations,
711 			p_per_sep_Retire 	      	=> l_imm_per_sep_retire,
712 			p_per_security          	=> l_imm_per_security,
713 			p_per_conversions	      	=> l_imm_per_conversions,
714 			p_per_uniformed_services	=> l_imm_per_uniformed_services,
715 			p_pos_oblig                   => l_imm_pos_oblig,
716 			p_pos_grp2                    => l_imm_pos_grp2,
717 			p_pos_grp1                    => l_imm_pos_grp1,
718 			p_pos_valid_grade             => l_imm_pos_valid_grade,
719 			p_pos_car_prog                => l_imm_pos_car_prog,
720 			p_loc_info                    => l_imm_loc_info,
721 			p_wgi                         => l_imm_wgi,
722 			p_recruitment_bonus	      => l_imm_recruitment_bonus,
723 			p_relocation_bonus	      => l_imm_relocation_bonus ,
724 			p_sf52_from_data              => l_imm_sf52_from_data,
725 			p_personal_info	            => l_imm_personal_info,
726 			p_gov_awards_type             => l_imm_gov_awards,
727 			p_perf_appraisal_type         => l_imm_perf_appraisal,
728 			p_payroll_type                => l_imm_payroll_type,
729 			p_conduct_perf_type           => l_imm_conduct_performance,
730 			p_agency_code		      => l_agency_code,
731 			p_agency_sf52			=> l_imm_agency_sf52,
732 			p_entitlement                 => l_imm_entitlement,
733 			p_foreign_lang_prof_pay       => l_imm_foreign_lang_prof_pay,
734 			p_edp_pay                     => l_imm_edp_pay,
735 			p_hazard_pay                  => l_imm_hazard_pay,
736 			p_health_benefits             => l_imm_health_benefits,
737 			p_danger_pay                  => l_imm_danger_pay,
738 			p_imminent_danger_pay         => l_imm_imminent_danger_pay,
739 			p_living_quarters_allow       => l_imm_living_quarters_allow,
740 			p_post_diff_amt               => l_imm_post_diff_amt,
741 			p_post_diff_percent           => l_imm_post_diff_percent,
742 			p_sep_maintenance_allow       => l_imm_sep_maintenance_allow,
743 			p_supplemental_post_allow     => l_imm_supplemental_post_allow,
744 			p_temp_lodge_allow            => l_imm_temp_lodge_allow,
745 			p_premium_pay                 => l_imm_premium_pay,
746 			p_retirement_annuity          => l_imm_retirement_annuity,
747 			p_severance_pay               => l_imm_severance_pay,
748 			p_thrift_saving_plan          => l_imm_thrift_saving_plan,
749 			p_retention_allow_review      => l_imm_retention_allow_review,
750 			p_health_ben_pre_tax          => l_imm_health_ben_pre_tax,
751 			p_per_benefit_info            => l_imm_per_benefit_info,
752 			p_imm_retirement_info         => l_imm_retirement_info, --Bug# 7131104
753 			--Begin Bug# 10181661
754 			p_asg_detail_info	      => l_imm_asg_detail_info,
755 			p_ipa_detail_ben_cont_info    => l_imm_ipa_benefits_cont
756 			--End Bug# 10181661
757 			);
758 
759 	-- call post_sf52_cancel to handle notifications, marking pa_requests cancelled, etc.
760 	hr_utility.set_location( l_proc, 30);
761 	ghr_sf52_post_update.post_sf52_cancel(
762 		p_pa_request_id		=> p_sf52_data.pa_request_id,
763 		p_effective_date	=> l_session_var.date_effective,
764 		p_object_version_number	=> p_sf52_data.object_version_number,
765 		p_from_position_id	=> p_sf52_data.from_position_id,
766 		p_to_position_id	=> p_sf52_data.to_position_id,
767 		p_agency_code		=> p_sf52_data.agency_code);
768 
769 	hr_utility.set_location( 'leaving : ' || l_proc, 40);
770   exception when others then
771                  --
772                  -- Reset IN OUT parameters and set OUT parameters
773                  --
774                  p_sf52_data := l_sf52_data_rec;
775                  raise;
776 end cancel_term_SF52;
777 
778 -- ---------------------------------------------------------------------------
779 -- |--------------------------< cancel_appt_sf52>---------------------------|
780 -- ---------------------------------------------------------------------------
781 -- {Start Of Comments}
782 --
783 -- Description:
784 --   	This procedure cancels an appointment sf52.
785 --
786 -- Pre-Requisities:
787 --   	None.
788 --
789 -- In Parameters:
790 --	p_sf52_data		->		ghr_pa_requests record of the cancellation sf52.
791 --
792 -- Post Success:
793 -- 	The appointment sf52 will have been cancelled.
794 --
795 -- Post Failure:
796 --   No failure conditions.
797 --
798 -- Developer Implementation Notes:
799 --   None
800 --
801 -- Access Status:
802 --   Internal Development Use Only.
803 --
804 -- {End Of Comments}
805 -- ---------------------------------------------------------------------------
806 
807 Procedure Cancel_Appt_SF52( p_sf52_data		in out nocopy 	ghr_pa_requests%rowtype) is
808 
809 	l_session_var	ghr_history_api.g_session_var_type;
810 	l_hist_post		ghr_pa_history%rowtype;
811 	l_business_group_id	number;
812 	l_u_prh_object_version_number number;
813 	l_i_pa_routing_history_id     number;
814 	l_i_prh_object_version_number number;
815 	l_agency_ei_data	ghr_pa_request_extra_info%rowtype;
816 	l_imm_asg_sf52          	ghr_api.asg_sf52_type;
817 	l_imm_asg_non_sf52		ghr_api.asg_non_sf52_type;
818 	l_imm_asg_nte_dates     	ghr_api.asg_nte_dates_type;
819 	l_imm_per_sf52          	ghr_api.per_sf52_type;
820 	l_imm_per_group1        	ghr_api.per_group1_type;
821 	l_imm_per_group2        	ghr_api.per_group2_type;
822 	l_imm_per_scd_info      	ghr_api.per_scd_info_type;
823 	l_imm_per_retained_grade      ghr_api.per_retained_grade_type;
824 	l_imm_per_probations          ghr_api.per_probations_type;
825 	l_imm_per_sep_retire          ghr_api.per_sep_retire_type;
826 	l_imm_per_security		ghr_api.per_security_type;
827 	-- Bug#4486823 RRR changes
828 	l_imm_per_service_oblig     ghr_api.per_service_oblig_type;
829 	l_imm_per_conversions		ghr_api.per_conversions_type;
830 	-- 4352589 BEN_EIT Changes
831 	l_imm_per_benefit_info        ghr_api.per_benefit_info_type;
832 	l_imm_per_uniformed_services  ghr_api.per_uniformed_services_type;
833 	l_imm_pos_oblig               ghr_api.pos_oblig_type;
834 	l_imm_pos_grp2                ghr_api.pos_grp2_type;
835 	l_imm_pos_grp1                ghr_api.pos_grp1_type;
836 	l_imm_pos_valid_grade         ghr_api.pos_valid_grade_type;
837 	l_imm_pos_car_prog            ghr_api.pos_car_prog_type;
838 	l_imm_loc_info                ghr_api.loc_info_type;
839 	l_imm_wgi     	            ghr_api.within_grade_increase_type;
840 	l_imm_gov_awards              ghr_api.government_awards_type;
841 	l_imm_recruitment_bonus	      ghr_api.recruitment_bonus_type;
842 	l_imm_relocation_bonus		ghr_api.relocation_bonus_type;
843 	l_imm_student_loan_repay  	ghr_api.student_loan_repay_type;
844 	--Pradeep
845 	l_imm_mddds_special_pay         ghr_api.mddds_special_pay_type;
846 	l_imm_premium_pay_ind           ghr_api.premium_pay_ind_type;
847 
848 	l_imm_extra_info_rec	 	ghr_api.extra_info_rec_type ;
849 	l_imm_sf52_from_data          ghr_api.prior_sf52_data_type;
850 	l_imm_personal_info		ghr_api.personal_info_type;
851 	l_imm_generic_extra_info_rec	ghr_api.generic_extra_info_rec_type ;
852 	l_imm_agency_sf52		      ghr_api.agency_sf52_type;
853 	l_agency_code			varchar2(50);
854 	l_imm_perf_appraisal          ghr_api.performance_appraisal_type;
855 	l_imm_conduct_performance     ghr_api.conduct_performance_type;
856 	l_imm_payroll_type            ghr_api.government_payroll_type;
857 	l_imm_par_term_retained_grade ghr_api.par_term_retained_grade_type;
858 	l_imm_entitlement             ghr_api.entitlement_type;
859         -- Bug#2759379 Added FEGLI Record
860     l_imm_fegli                   ghr_api.fegli_type;
861 	l_imm_foreign_lang_prof_pay   ghr_api.foreign_lang_prof_pay_type;
862 	-- Bug#3385386 Added FTA Record
863 	l_imm_fta                     ghr_api.fta_type;
864 	l_imm_edp_pay                 ghr_api.edp_pay_type;
865 	l_imm_hazard_pay              ghr_api.hazard_pay_type;
866 	l_imm_health_benefits         ghr_api.health_benefits_type;
867 	l_imm_danger_pay              ghr_api.danger_pay_type;
868 	l_imm_imminent_danger_pay     ghr_api.imminent_danger_pay_type;
869 	l_imm_living_quarters_allow   ghr_api.living_quarters_allow_type;
870 	l_imm_post_diff_amt           ghr_api.post_diff_amt_type;
871 	l_imm_post_diff_percent       ghr_api.post_diff_percent_type;
872 	l_imm_sep_maintenance_allow   ghr_api.sep_maintenance_allow_type;
873 	l_imm_supplemental_post_allow ghr_api.supplemental_post_allow_type;
874 	l_imm_temp_lodge_allow        ghr_api.temp_lodge_allow_type;
875 	l_imm_premium_pay             ghr_api.premium_pay_type;
876 	l_imm_retirement_annuity      ghr_api.retirement_annuity_type;
877 	l_imm_severance_pay           ghr_api.severance_pay_type;
878 	l_imm_thrift_saving_plan      ghr_api.thrift_saving_plan;
879 	l_imm_retention_allow_review  ghr_api.retention_allow_review_type;
880 	l_imm_health_ben_pre_tax         ghr_api.health_ben_pre_tax_type;
881 	l_imm_per_race_ethnic_info 	  ghr_api.per_race_ethnic_type; -- Bug 4724337 Race or National Origin changes
882 	l_sf52_data				ghr_pa_requests%rowtype;
883 	l_sf52_data_rec      ghr_pa_requests%rowtype;
884 	l_health_plan			varchar2(30);
885 	l_error_flag			boolean;
886 	l_return_status	varchar2(30);
887 	l_result		varchar2(30);
888       -- JH CAO
889       l_cao_effective_date          date;
890       l_cancel_effective_date       date;
891 
892        --Bug# 6312144
893        l_imm_ipa_benefits_cont       ghr_api.per_ipa_ben_cont_info_type;
894        l_imm_retirement_info         ghr_api.per_retirement_info_type;
895        l_imm_asg_detail_info		ghr_api.asg_detail_info_type; --Bug# 8653508
896 
897        --BUG # 13571004
898 	l_imm_roth_tsp                ghr_api.tsp_roth_type;
899 
900 
901 	-- this cursor gets the business_group_id for the person_id/effective_date passed.
902 	cursor c_bg ( c_person_id  number,
903 			  c_as_on_date date) is
904 	select
905 		business_group_id
906 	from per_people_f
907 	where person_id = c_person_id and
908 		c_as_on_date between effective_start_date and effective_end_date;
909 
910 	-- this cursor gets the ghr_pa_history rows (with the rowid included) for the person_id specified and locks
911 	-- the rows for update.
912 	-- note that it selects all the records that were effective on or after the effective_date passed.
913 	-- also note that it orders by dml_operation, in order to ensure that updated rows are handled
914 	-- before inserted rows. This is necessary for the way we are handling the setting of extra info tables
915 	-- back to what they were prior to the appointment. If updated rows were handled before inserted rows, then
916 	-- the cascade_appl_table_data call may fail since it will be trying to fetch a pre-record for the
917 	-- updated row, but the pre-record has been deleted since we handled inserted rows first.
918 	cursor c_hist (c_person_id number,
919 			   c_eff_date  date) is
920 	select
921 		pah.rowid row_id,
922 		pah.*
923 	from ghr_pa_history pah
924 	where person_id = c_person_id and
925 		(effective_date > c_eff_date or
926 		 (effective_date = c_eff_date and pa_request_id is not NULL))
927         and upper(pah.table_name) not in (upper(ghr_history_api.g_addres_table))
928 	for update of person_id
929 	order by dml_operation desc;
930 
931 	--8259229 for address order by information1 and then on dml operation
932 	cursor c_add_hist (c_person_id number,
933 			   c_eff_date  date) is
934 	select
935 		pah.rowid row_id,
936 		pah.*
937 	from ghr_pa_history pah
938 	where person_id = c_person_id and
939 		(effective_date > c_eff_date or
940 		 (effective_date = c_eff_date and pa_request_id is not NULL))
941 	and upper(pah.table_name) in (upper(ghr_history_api.g_addres_table))
942 	for update of person_id
943 	order by information1 desc,dml_operation desc;
944 	--8259229
945 
946 	-- this cursor gets the ghr_pa_request rows (with the rowid included) for the person_id passed and locks
947 	-- the rows for update.
948 	-- It returns all pa request rows that were effective on or after the effective date passed, as long as the
949 	-- pa request has been approved.
950 	cursor c_par ( c_person_id number,
951 			   c_eff_date  date) is
952 	select
953 		par.rowid,
954 		par.*
955 	from ghr_pa_requests par
956 	where person_id = c_person_id        and
957 		effective_date >= c_eff_date   and
958             pa_notification_id is not null and
959             approval_date is not null
960 	for update of person_id;
961 
962 
963 	 --Bug # 12652865 cursor for checking whether person analysis record exists
964         cursor chk_perana_exists(p_person_analysis_id in per_person_analyses.person_analysis_id%type)
965         is
966         SELECT 1
967         FROM   PER_PERSON_ANALYSES
968         WHERE  person_analysis_id = p_person_analysis_id;
969         l_rec_exists                  boolean;
970 	m_perana                      varchar2(1);
971 
972 	--Begin BUG # 13334984
973 	cursor c_upd_hist(p_table_name in varchar2,
974 			  p_information1 in ghr_pa_history.information1%type)
975             is
976 	    select pah.rowid row_id
977 	    from   ghr_pa_history pah
978 	    where  table_name = p_table_name
979 	    and    information1 = p_information1
980 	    and    dml_operation = 'U';
981 		--End  BUG # 13334984
982 
983         l_pos_name                    varchar2(2000);
984         l_object_version_number       number;
985         l_effective_start_date        date;
986         l_effective_end_date          date;
987 
988 --
989 	l_proc	varchar2(30):='cancel_appt_sf52';
990 
991 Begin
992 
993 	hr_utility.set_location(' Entering : ' || l_proc, 10);
994    l_sf52_data_rec := p_sf52_data;
995 
996 
997 	-- reinitialise session variables
998 	ghr_history_api.reinit_g_session_var;
999 
1000 	-- set values of session variables
1001 	l_session_var.pa_request_id 	:= p_sf52_data.pa_request_id;
1002 	l_session_var.noa_id		:= p_sf52_data.second_noa_id;
1003 	-- No triggers should be fired as cancellation can not be corrected or cancelled
1004 	-- so none of the changes will be saved.
1005 	l_session_var.fire_trigger	:= 'N';
1006 	l_session_var.date_Effective	:= p_sf52_data.effective_date;
1007 	l_session_var.person_id		:= p_sf52_data.person_id;
1008 	l_session_var.program_name	:= 'sf50';
1009 	l_session_var.altered_pa_request_id	:= p_sf52_data.altered_pa_request_id;
1010 	l_session_var.noa_id_correct	:= p_sf52_data.second_noa_id;
1011 	l_session_var.assignment_id	:= p_sf52_data.employee_assignment_id;
1012 
1013 	ghr_history_api.set_g_session_var(l_session_var);
1014 
1015 	ghr_process_Sf52.Fetch_extra_info(
1016 			p_pa_request_id 	=> p_sf52_data.pa_request_id,
1017 			p_noa_id   		=> p_sf52_data.second_noa_id,
1018 			p_agency_ei		=> TRUE,
1019 			p_sf52_ei_data 	=> l_agency_ei_data,
1020 			p_result		=> l_result);
1021 
1022 	l_sf52_data 	:= p_sf52_data;
1023 	-- all corrections will have the original sf52 information in the 2nd noa columns, so
1024 	-- copy that information to 1st noa columns.
1025 	ghr_process_sf52.copy_2ndNoa_to_1stNoa(l_sf52_data);
1026 	-- null the second noa columns since we don't want anything to be done with these now.
1027 	ghr_process_sf52.null_2ndNoa_cols(l_sf52_data);
1028 
1029 	ghr_sf52_pre_update.populate_record_groups (
1030 		 	p_pa_request_rec                => l_sf52_data,
1031 			p_generic_ei_rec                => l_agency_ei_data,
1032 			p_imm_asg_sf52                  => l_imm_asg_sf52,
1033 			p_imm_asg_non_sf52              => l_imm_asg_non_sf52,
1034 			p_imm_asg_nte_dates             => l_imm_asg_nte_dates,
1035 			p_imm_asg_detail_info	        => l_imm_asg_detail_info, --Bug# 8653508
1036 			p_imm_per_sf52                  => l_imm_per_sf52,
1037 			p_imm_per_group1                => l_imm_per_group1,
1038 			p_imm_per_group2                => l_imm_per_group2,
1039 			p_imm_per_scd_info              => l_imm_per_scd_info,
1040 			p_imm_per_retained_grade        => l_imm_per_retained_grade,
1041 			p_imm_per_probations            => l_imm_per_probations,
1042 			p_imm_per_sep_retire            => l_imm_per_sep_retire,
1043 			p_imm_per_security              => l_imm_per_security,
1044             --Bug#4486823 RRR Changes
1045             p_imm_per_service_oblig         => l_imm_per_service_oblig,
1046 			p_imm_per_conversions           => l_imm_per_conversions,
1047 			-- 4352589 BEN_EIT Changes
1048 			p_imm_per_benefit_info          => l_imm_per_benefit_info,
1049 			p_imm_per_uniformed_services    => l_imm_per_uniformed_services,
1050 			p_imm_pos_oblig                 => l_imm_pos_oblig,
1051 			p_imm_pos_grp2                  => l_imm_pos_grp2,
1052 			p_imm_pos_grp1                  => l_imm_pos_grp1,
1053 			p_imm_pos_valid_grade           => l_imm_pos_valid_grade,
1054 			p_imm_pos_car_prog              => l_imm_pos_car_prog,
1055 			p_imm_loc_info                  => l_imm_loc_info,
1056 			p_imm_wgi                       => l_imm_wgi,
1057 			p_imm_gov_awards                => l_imm_gov_awards,
1058 			p_imm_recruitment_bonus         => l_imm_recruitment_bonus,
1059 			p_imm_relocation_bonus          => l_imm_relocation_bonus,
1060 			p_imm_student_loan_repay        => l_imm_student_loan_repay,
1061 			p_imm_per_race_ethnic_info 		=> l_imm_per_race_ethnic_info, -- Bug 4724337 Race or National Origin changes
1062 			--Pradeep
1063 			p_imm_mddds_special_pay         => l_imm_mddds_special_pay,
1064 			p_imm_premium_pay_ind           => l_imm_premium_pay_ind,
1065 
1066 			p_imm_perf_appraisal            => l_imm_perf_appraisal,
1067 			p_imm_conduct_performance       => l_imm_conduct_performance,
1068 			p_imm_payroll_type              => l_imm_payroll_type,
1069 			p_imm_extra_info_rec	        => l_imm_extra_info_rec,
1070 			p_imm_sf52_from_data            => l_imm_sf52_from_data,
1071 			p_imm_personal_info	        => l_imm_personal_info,
1072 			p_imm_generic_extra_info_rec    => l_imm_generic_extra_info_rec,
1073 			p_imm_agency_sf52               => l_imm_agency_sf52,
1074 			p_agency_code                   => l_agency_code,
1075 			p_imm_par_term_retained_grade   => l_imm_par_term_retained_grade,
1076 			p_imm_entitlement               => l_imm_entitlement,
1077                         -- Bug#2759379 Added FEGLI Record
1078                         p_imm_fegli                     => l_imm_fegli,
1079 			p_imm_foreign_lang_prof_pay     => l_imm_foreign_lang_prof_pay,
1080 			-- Bug#3385386 Added FTA Record
1081 			p_imm_fta                       => l_imm_fta,
1082 			p_imm_edp_pay                   => l_imm_edp_pay,
1083 			p_imm_hazard_pay                => l_imm_hazard_pay,
1084 			p_imm_health_benefits           => l_imm_health_benefits,
1085 			p_imm_danger_pay                => l_imm_danger_pay,
1086 			p_imm_imminent_danger_pay       => l_imm_imminent_danger_pay,
1087 			p_imm_living_quarters_allow     => l_imm_living_quarters_allow,
1088 			p_imm_post_diff_amt             => l_imm_post_diff_amt,
1089 			p_imm_post_diff_percent         => l_imm_post_diff_percent,
1090 			p_imm_sep_maintenance_allow     => l_imm_sep_maintenance_allow,
1091 			p_imm_supplemental_post_allow   => l_imm_supplemental_post_allow,
1092 			p_imm_temp_lodge_allow          => l_imm_temp_lodge_allow,
1093 			p_imm_premium_pay               => l_imm_premium_pay,
1094 			p_imm_retirement_annuity        => l_imm_retirement_annuity,
1095 			p_imm_severance_pay             => l_imm_severance_pay,
1096 			p_imm_thrift_saving_plan        => l_imm_thrift_saving_plan,
1097 			p_imm_retention_allow_review        => l_imm_retention_allow_review,
1098 			p_imm_health_ben_pre_tax           => l_imm_health_ben_pre_tax,
1099 			--Bug #6312144 RPA EIT Benefits
1100 			p_imm_ipa_benefits_cont         => l_imm_ipa_benefits_cont,
1101                         p_imm_retirement_info           => l_imm_retirement_info,
1102 			--BUG # 13571004 added TSP Roth
1103                         p_imm_tsp_roth                  => l_imm_roth_tsp
1104 			);
1105 
1106 	ghr_api.retrieve_element_entry_value
1107 		( p_element_name	=> 'Health Benefits'
1108 		 ,p_input_value_name    =>  'Health Plan'
1109 		 ,p_assignment_id       =>   l_sf52_data.employee_assignment_id
1110 		 ,p_effective_date      =>   trunc(l_sf52_data.effective_date)
1111 		 ,p_value               =>   l_health_plan
1112 		 ,p_multiple_error_flag =>   l_error_flag
1113 		 );
1114 
1115 
1116 	GHR_AGENCY_CHECK.AGENCY_CHECK(
1117 			p_pa_request_rec			=> l_sf52_data,
1118 			p_asg_sf52				=> l_imm_asg_sf52,
1119 			p_asg_non_sf52			=> l_imm_asg_non_sf52,
1120 			p_asg_nte_dates			=> l_imm_asg_nte_dates,
1121 			p_per_sf52              	=> l_imm_per_sf52,
1122 			p_per_group1            	=> l_imm_per_group1,
1123 			p_per_group2            	=> l_imm_per_group2,
1124 			p_per_scd_info          	=> l_imm_per_scd_info,
1125 			p_per_retained_grade    	=> l_imm_per_retained_grade,
1126 			p_per_probations			=> l_imm_per_probations,
1127 			p_per_sep_Retire 	      	=> l_imm_per_sep_retire,
1128 			p_per_security          	=> l_imm_per_security,
1129 			p_per_conversions	      	=> l_imm_per_conversions,
1130 			p_per_uniformed_services	=> l_imm_per_uniformed_services,
1131 			p_pos_oblig                   => l_imm_pos_oblig,
1132 			p_pos_grp2                    => l_imm_pos_grp2,
1133 			p_pos_grp1                    => l_imm_pos_grp1,
1134 			p_pos_valid_grade             => l_imm_pos_valid_grade,
1135 			p_pos_car_prog                => l_imm_pos_car_prog,
1136 			p_loc_info                    => l_imm_loc_info,
1137 			p_wgi                         => l_imm_wgi,
1138 			p_recruitment_bonus	      => l_imm_recruitment_bonus,
1139 			p_relocation_bonus	      => l_imm_relocation_bonus ,
1140 			p_sf52_from_data              => l_imm_sf52_from_data,
1141 			p_personal_info	            => l_imm_personal_info,
1142 			p_gov_awards_type             => l_imm_gov_awards,
1143 			p_perf_appraisal_type         => l_imm_perf_appraisal,
1144 			p_payroll_type                => l_imm_payroll_type,
1145 			p_conduct_perf_type           => l_imm_conduct_performance,
1146 			p_agency_code		      => l_agency_code,
1147 			p_agency_sf52			=> l_imm_agency_sf52,
1148 			p_health_plan			=> l_health_plan,
1149 			p_entitlement                 => l_imm_entitlement,
1150 			p_foreign_lang_prof_pay       => l_imm_foreign_lang_prof_pay,
1151 			p_edp_pay                     => l_imm_edp_pay,
1152 			p_hazard_pay                  => l_imm_hazard_pay,
1153 			p_health_benefits             => l_imm_health_benefits,
1154 			p_danger_pay                  => l_imm_danger_pay,
1155 			p_imminent_danger_pay         => l_imm_imminent_danger_pay,
1156 			p_living_quarters_allow       => l_imm_living_quarters_allow,
1157 			p_post_diff_amt               => l_imm_post_diff_amt,
1158 			p_post_diff_percent           => l_imm_post_diff_percent,
1159 			p_sep_maintenance_allow       => l_imm_sep_maintenance_allow,
1160 			p_supplemental_post_allow     => l_imm_supplemental_post_allow,
1161 			p_temp_lodge_allow            => l_imm_temp_lodge_allow,
1162 			p_premium_pay                 => l_imm_premium_pay,
1163 			p_retirement_annuity          => l_imm_retirement_annuity,
1164 			p_severance_pay               => l_imm_severance_pay,
1165 			p_thrift_saving_plan          => l_imm_thrift_saving_plan,
1166 			p_retention_allow_review      => l_imm_retention_allow_review,
1167 			p_health_ben_pre_tax          => l_imm_health_ben_pre_tax,
1168 			p_per_benefit_info            => l_imm_per_benefit_info,
1169 			p_imm_retirement_info         => l_imm_retirement_info, --Bug# 7131104
1170 			--Begin Bug# 10181661
1171 			p_asg_detail_info	      => l_imm_asg_detail_info,
1172 			p_ipa_detail_ben_cont_info    => l_imm_ipa_benefits_cont
1173 			--End Bug# 10181661
1174 			);
1175 
1176         -- Segment which calls do_cancel_hire moved after history handling. Bug# 1295751.
1177 
1178 	hr_utility.set_location( l_proc, 40);
1179 	for l_hist in c_hist( p_sf52_data.person_id,
1180 				    p_sf52_data.effective_date)
1181 	loop
1182 		hr_utility.set_location( 'GOT HERE!!!!: ' || l_proc, 59);
1183 		exit when c_hist%notfound;
1184 		delete_hist_row( l_hist.row_id);
1185 		hr_utility.set_location( 'checking if table needs deleting: ' || l_hist.table_name|| l_proc, 58);
1186 		-- Delete all extraInfo table records which were created by the SF52.
1187 		if  upper(l_hist.table_name) in (upper(ghr_history_api.g_peopei_table),
1188 							  upper(ghr_history_api.g_posnei_table),
1189 							  upper(ghr_history_api.g_asgnei_table),
1190 							  upper(ghr_history_api.g_addres_table),
1191 							  upper(ghr_history_api.g_perana_table)) then
1192 			hr_utility.set_location( 'table_name qualifies: ' || l_hist.table_name|| l_proc, 57);
1193 			if l_hist.DML_operation = ghr_history_api.g_ins_operation then
1194 				hr_utility.set_location( 'delete appl row table_name: ' || l_hist.table_name|| l_proc, 51);
1195 				hr_utility.set_location( 'delete appl row information1: ' || l_hist.information1|| l_proc, 52);
1196 				hr_utility.set_location( 'delete appl row effective_date: ' || l_hist.effective_date|| l_proc, 53);
1197 				delete_appl_row(
1198 					p_table_name	=> l_hist.table_name,
1199 					p_table_pk_id	=> l_hist.information1,
1200 					p_dt_mode	=> null,
1201 					p_date_effective=> l_hist.effective_date);
1202                                 --Begin BUG # 13334984
1203                                 --Added to delete all the Updation rows if a row
1204 				-- is deleted from base table
1205                                 FOR l_upd_hist in c_upd_hist(l_hist.table_name,
1206 							     l_hist.information1)
1207 				LOOP
1208 				   delete_hist_row( l_upd_hist.row_id);
1209 				END LOOP;
1210                                  --End BUG # 13334984
1211 
1212 			elsif l_hist.DML_operation = ghr_history_api.g_upd_operation then
1213 				l_hist_post.information1 	:= l_hist.information1;
1214 				l_hist_post.person_id		:= l_hist.person_id;
1215 				hr_utility.set_location(l_proc || 'l_hist.information1: ' || l_hist.information1, 1200);
1216 				hr_utility.set_location(l_proc || 'l_hist.table_name: ' || l_hist.table_name, 1210);
1217 				hr_utility.set_location(l_proc || 'l_hist.person_id: ' || l_hist.person_id, 1220);
1218 
1219 				--Bug # 12652865 as no need to cascade if already person analyses record is not
1220 			       --- available in the base table PER_PERSON_ANALYSES
1221 
1222 			      l_rec_exists := TRUE;
1223    	                      IF l_hist.table_name = 'PER_PERSON_ANALYSES' THEN
1224                                  OPEN chk_perana_exists(p_person_analysis_id => l_hist.information1);
1225                                  FETCH chk_perana_exists into m_perana;
1226                                  IF chk_perana_exists%NOTFOUND THEN
1227                                     l_rec_exists := FALSE;
1228                                  END IF;
1229                                  CLOSE chk_perana_exists;
1230                               END IF;
1231 
1232 			      IF l_rec_exists THEN
1233 
1234 				ghr_history_cascade.cascade_appl_table_data(
1235 					p_table_name		=>	l_hist.table_name,
1236 					p_person_id			=>	l_hist.person_id,
1237 					p_pre_record		=>	null,
1238 					p_post_record		=>	l_hist_post,
1239 					p_cascade_type		=>	null,
1240 					p_interv_on_table		=>	null,
1241 					p_interv_on_eff_date	=>	null,
1242 					p_hist_data_as_of_date	=>	null);
1243 			      END IF;
1244 			end if;
1245 		end if;
1246 	end loop;
1247 
1248 	--8259229   added a seperate loop for address
1249 	for l_add_hist in c_add_hist( p_sf52_data.person_id,
1250 			      p_sf52_data.effective_date)
1251 	loop
1252 		hr_utility.set_location( 'GOT HERE!!!!: ' || l_proc, 59);
1253 		hr_utility.set_location( 'GOT HERE' || l_add_hist.pa_history_id, 59);
1254 		exit when c_add_hist%notfound;
1255 		delete_hist_row( l_add_hist.row_id);
1256 		hr_utility.set_location( 'checking if table needs deleting: ' || l_add_hist.table_name|| l_proc, 58);
1257 		-- Delete all extraInfo table records which were created by the SF52.
1258 			hr_utility.set_location( 'table_name qualifies: ' || l_add_hist.table_name|| l_proc, 57);
1259 			if l_add_hist.DML_operation = ghr_history_api.g_ins_operation then
1260 				hr_utility.set_location( 'delete appl row table_name: ' || l_add_hist.table_name|| l_proc, 51);
1261 				hr_utility.set_location( 'delete appl row information1: ' || l_add_hist.information1|| l_proc, 52);
1262 				hr_utility.set_location( 'delete appl row effective_date: ' || l_add_hist.effective_date|| l_proc, 53);
1263 				delete_appl_row(
1264 					p_table_name	=> l_add_hist.table_name,
1265 					p_table_pk_id	=> l_add_hist.information1,
1266 					p_dt_mode		=> null,
1267 					p_date_effective	=> l_add_hist.effective_date);
1268 			elsif l_add_hist.DML_operation = ghr_history_api.g_upd_operation then
1269 				l_hist_post.information1 	:= l_add_hist.information1;
1270 				l_hist_post.person_id		:= l_add_hist.person_id;
1271 				hr_utility.set_location(l_proc || 'l_add_hist.information1: ' || l_add_hist.information1, 1200);
1272 				hr_utility.set_location(l_proc || 'l_add_hist.table_name: ' || l_add_hist.table_name, 1210);
1273 				hr_utility.set_location(l_proc || 'l_add_hist.person_id: ' || l_add_hist.person_id, 1220);
1274 				ghr_history_cascade.cascade_appl_table_data(
1275 					p_table_name		=>	l_add_hist.table_name,
1276 					p_person_id			=>	l_add_hist.person_id,
1277 					p_pre_record		=>	null,
1278 					p_post_record		=>	l_hist_post,
1279 					p_cascade_type		=>	null,
1280 					p_interv_on_table		=>	null,
1281 					p_interv_on_eff_date	=>	null,
1282 					p_hist_data_as_of_date	=>	null);
1283 			end if;
1284 	end loop;
1285 	--8259229
1286 
1287         -- Moved this segment to be executed after history deletion handling.
1288         -- Bug# 1295751.
1289 	hr_utility.set_location( l_proc, 20);
1290 	open c_bg (p_sf52_data.person_id, p_sf52_data.effective_date);
1291 	fetch c_bg into l_business_group_id;
1292 	if c_bg%notfound then
1293 		close c_bg;
1294 	      hr_utility.set_message(8301,'GHR_38210_BUSINESS_GROUP_NFND');
1295 	      hr_utility.raise_error;
1296 		--raise error
1297 	end if;
1298 	hr_utility.set_location( l_proc, 30);
1299 	-- Check if need to call cancel_hire_or_apl.lock_per_row ???
1300 	-- call core HR api to cancel the hire.
1301 --*****************************************************************************
1302 -- Added as per Rohini's suggestion to fix bug#3106101
1303      pay_us_tax_internal.maintain_us_employee_taxes (
1304          p_effective_date =>  p_sf52_data.effective_date
1305         ,p_datetrack_mode => 'ZAP'
1306         ,p_assignment_id  => l_sf52_data.employee_assignment_id
1307        ,p_delete_routine => 'ASSIGNMENT' );
1308 
1309 -- to fix bug 3106101
1310 --*****************************************************************************
1311 
1312 -- JH CAO
1313 -- Bug 2989431 New User Hook GHR_AGENCY_CHECK.CANCEL_HIRE_CAO
1314 	GHR_AGENCY_CHECK.CANCEL_HIRE_CAO(
1315 			p_pa_request_rec			=> l_sf52_data,
1316 			p_asg_sf52				=> l_imm_asg_sf52,
1317 			p_asg_non_sf52			=> l_imm_asg_non_sf52,
1318 			p_asg_nte_dates			=> l_imm_asg_nte_dates,
1319 			p_per_sf52              	=> l_imm_per_sf52,
1320 			p_per_group1            	=> l_imm_per_group1,
1321 			p_per_group2            	=> l_imm_per_group2,
1322 			p_per_scd_info          	=> l_imm_per_scd_info,
1323 			p_per_retained_grade    	=> l_imm_per_retained_grade,
1324 			p_per_probations			=> l_imm_per_probations,
1325 			p_per_sep_Retire 	      	=> l_imm_per_sep_retire,
1326 			p_per_security          	=> l_imm_per_security,
1327 			p_per_conversions	      	=> l_imm_per_conversions,
1328 			p_per_uniformed_services	=> l_imm_per_uniformed_services,
1329 			p_pos_oblig                   => l_imm_pos_oblig,
1330 			p_pos_grp2                    => l_imm_pos_grp2,
1331 			p_pos_grp1                    => l_imm_pos_grp1,
1332 			p_pos_valid_grade             => l_imm_pos_valid_grade,
1333 			p_pos_car_prog                => l_imm_pos_car_prog,
1334 			p_loc_info                    => l_imm_loc_info,
1335 			p_wgi                         => l_imm_wgi,
1336 			p_recruitment_bonus	      => l_imm_recruitment_bonus,
1337 			p_relocation_bonus	      => l_imm_relocation_bonus ,
1338 			p_sf52_from_data              => l_imm_sf52_from_data,
1339 			p_personal_info	            => l_imm_personal_info,
1340 			p_gov_awards_type             => l_imm_gov_awards,
1341 			p_perf_appraisal_type         => l_imm_perf_appraisal,
1342 			p_payroll_type                => l_imm_payroll_type,
1343 			p_conduct_perf_type           => l_imm_conduct_performance,
1344 			p_agency_code		      => l_agency_code,
1345 			p_agency_sf52			=> l_imm_agency_sf52,
1346 			p_health_plan			=> l_health_plan,
1347 			p_entitlement                 => l_imm_entitlement,
1348 			p_foreign_lang_prof_pay       => l_imm_foreign_lang_prof_pay,
1349 			p_edp_pay                     => l_imm_edp_pay,
1350 			p_hazard_pay                  => l_imm_hazard_pay,
1351 			p_health_benefits             => l_imm_health_benefits,
1352 			p_danger_pay                  => l_imm_danger_pay,
1353 			p_imminent_danger_pay         => l_imm_imminent_danger_pay,
1354 			p_living_quarters_allow       => l_imm_living_quarters_allow,
1355 			p_post_diff_amt               => l_imm_post_diff_amt,
1356 			p_post_diff_percent           => l_imm_post_diff_percent,
1357 			p_sep_maintenance_allow       => l_imm_sep_maintenance_allow,
1358 			p_supplemental_post_allow     => l_imm_supplemental_post_allow,
1359 			p_temp_lodge_allow            => l_imm_temp_lodge_allow,
1360 			p_premium_pay                 => l_imm_premium_pay,
1361 			p_retirement_annuity          => l_imm_retirement_annuity,
1362 			p_severance_pay               => l_imm_severance_pay,
1363 			p_thrift_saving_plan          => l_imm_thrift_saving_plan,
1364 			p_retention_allow_review      => l_imm_retention_allow_review,
1365 			p_health_ben_pre_tax          => l_imm_health_ben_pre_tax,
1366                   p_cao_effective_date          => l_cao_effective_date
1367 );
1368 
1369       IF l_cao_effective_date IS NOT NULL THEN
1370          l_cancel_effective_date := l_cao_effective_date;
1371       ELSE
1372          l_cancel_effective_date := p_sf52_data.effective_date;
1373       END IF;
1374 
1375 	per_cancel_hire_or_apl_pkg.do_cancel_hire(
1376 		p_person_id			=> p_sf52_data.person_id,
1377 		p_date_start		=> l_cancel_effective_date,
1378 		p_end_of_time		=> hr_api.g_eot,
1379 		p_business_group_id	=> l_business_group_id,
1380 		p_period_of_service_id	=> null
1381 		);
1382         -- End segment for bug# 1295751
1383 
1384 	ghr_agency_update.ghr_agency_upd(
1385 			p_pa_request_rec			=> l_sf52_data,
1386 			p_asg_sf52				=> l_imm_asg_sf52,
1387 			p_asg_non_sf52			=> l_imm_asg_non_sf52,
1388 			p_asg_nte_dates			=> l_imm_asg_nte_dates,
1389 			p_per_sf52              	=> l_imm_per_sf52,
1390 			p_per_group1            	=> l_imm_per_group1,
1391 			p_per_group2            	=> l_imm_per_group2,
1392 			p_per_scd_info          	=> l_imm_per_scd_info,
1393 			p_per_retained_grade    	=> l_imm_per_retained_grade,
1394 			p_per_probations			=> l_imm_per_probations,
1395 			p_per_sep_Retire 	      	=> l_imm_per_sep_retire,
1396 			p_per_security          	=> l_imm_per_security,
1397 			p_per_conversions	      	=> l_imm_per_conversions,
1398 			p_per_uniformed_services	=> l_imm_per_uniformed_services,
1399 			p_pos_oblig                   => l_imm_pos_oblig,
1400 			p_pos_grp2                    => l_imm_pos_grp2,
1401 			p_pos_grp1                    => l_imm_pos_grp1,
1402 			p_pos_valid_grade             => l_imm_pos_valid_grade,
1403 			p_pos_car_prog                => l_imm_pos_car_prog,
1404 			p_loc_info                    => l_imm_loc_info,
1405 			p_wgi                         => l_imm_wgi,
1406 			p_recruitment_bonus	      => l_imm_recruitment_bonus,
1407 			p_relocation_bonus	      => l_imm_relocation_bonus ,
1408 			p_sf52_from_data              => l_imm_sf52_from_data,
1409 			p_personal_info	            => l_imm_personal_info,
1410 			p_gov_awards_type             => l_imm_gov_awards,
1411 			p_perf_appraisal_type         => l_imm_perf_appraisal,
1412 			p_payroll_type                => l_imm_payroll_type,
1413 			p_conduct_perf_type           => l_imm_conduct_performance,
1414 			p_agency_code		      => l_agency_code,
1415 			p_agency_sf52			=> l_imm_agency_sf52,
1416 			p_entitlement                 => l_imm_entitlement,
1417 			p_foreign_lang_prof_pay       => l_imm_foreign_lang_prof_pay,
1418 			p_edp_pay                     => l_imm_edp_pay,
1419 			p_hazard_pay                  => l_imm_hazard_pay,
1420 			p_health_benefits             => l_imm_health_benefits,
1421 			p_danger_pay                  => l_imm_danger_pay,
1422 			p_imminent_danger_pay         => l_imm_imminent_danger_pay,
1423 			p_living_quarters_allow       => l_imm_living_quarters_allow,
1424 			p_post_diff_amt               => l_imm_post_diff_amt,
1425 			p_post_diff_percent           => l_imm_post_diff_percent,
1426 			p_sep_maintenance_allow       => l_imm_sep_maintenance_allow,
1427 			p_supplemental_post_allow     => l_imm_supplemental_post_allow,
1428 			p_temp_lodge_allow            => l_imm_temp_lodge_allow,
1429 			p_premium_pay                 => l_imm_premium_pay,
1430 			p_retirement_annuity          => l_imm_retirement_annuity,
1431 			p_severance_pay               => l_imm_severance_pay,
1432 			p_thrift_saving_plan          => l_imm_thrift_saving_plan,
1433 			p_retention_allow_review      => l_imm_retention_allow_review,
1434 			p_health_ben_pre_tax          => l_imm_health_ben_pre_tax,
1435 			p_per_benefit_info            => l_imm_per_benefit_info,
1436 			p_imm_retirement_info         => l_imm_retirement_info, --Bug# 7131104
1437 			--Begin Bug# 10181661
1438 			p_asg_detail_info	      => l_imm_asg_detail_info,
1439 			p_ipa_detail_ben_cont_info    => l_imm_ipa_benefits_cont
1440 			--End Bug# 10181661
1441 			);
1442 
1443 	hr_utility.set_location( l_proc, 50);
1444 	ghr_sf52_post_update.post_sf52_cancel(
1445 		p_pa_request_id		=> p_sf52_data.pa_request_id,
1446 		p_effective_date		=> l_session_var.date_effective,
1447 		p_object_version_number	=> p_sf52_data.object_version_number,
1448 		p_from_position_id	=> p_sf52_data.from_position_id,
1449 		p_to_position_id		=> p_sf52_data.to_position_id,
1450 		p_agency_code		=> p_sf52_data.agency_code);
1451 
1452 	--
1453 	-- Mark all the SF52s cancelled which were created after Appt. SF52
1454 	--
1455 	hr_utility.set_location( l_proc, 110);
1456 	for l_par in c_par( p_sf52_data.person_id,
1457                           p_sf52_data.effective_date)
1458 	loop
1459 		hr_utility.set_location( l_proc, 111);
1460 		exit when c_par%notfound;
1461 
1462 		-- Special handling is required for the termination action 352.
1463 -- Added by VVL
1464                -- BUG # 9890213 modified to delete the position change only when 352
1465 	     -- is processed through MTO and it is not yet cancelled
1466 	     -- Moved the code up as cancelled need not to be considered
1467 
1468                if (l_par.first_noa_code = '352') and (UPPER(SUBSTR(NVL(l_par.request_number,'***'),1,3)) = 'MTO')
1469 	          and l_par.first_noa_cancel_or_correct <> ghr_history_api.g_cancel then
1470                   -- null out end_date for position
1471 
1472 
1473                   SELECT name, object_version_number
1474                     INTO l_pos_name, l_object_version_number
1475                     FROM hr_all_positions_f
1476                    WHERE position_id = l_par.from_position_id
1477                      AND (l_par.effective_date  - 1) BETWEEN effective_start_date
1478                                                                AND effective_end_date;
1479                    hr_position_api.delete_position
1480                    (p_position_id                   => l_par.from_position_id,
1481                     p_object_version_number         => l_object_version_number,
1482                     p_effective_date                => l_par.effective_date - 1,
1483                     p_effective_start_date          => l_effective_start_date,
1484                     p_effective_end_date            => l_effective_end_date,
1485                     p_datetrack_mode                => 'DELETE_NEXT_CHANGE'
1486                     );
1487                end if;
1488 --Added by VVL
1489 
1490 		-- mark delete
1491 		if l_par.first_noa_code not in ('001' , '002') then
1492 			-- no need to do anything with cancellation/correction actions as they
1493 			-- already will not appear in cancellation/correction form.
1494                         -- EDWARD NUNEZ 03/03/2000
1495                         -- NOTE: To fix bug# 1222525 please change following line
1496                         --       "if l_par.first_noa_cancel_or_correct is null then" to
1497                         --       "if l_par.first_noa_cancel_or_correct is null OR
1498                         --           NVL(l_par.first_noa_cancel_or_correct, '***') = 'CORRECT' then"
1499 			if l_par.first_noa_cancel_or_correct is null or
1500                            NVL(l_par.first_noa_cancel_or_correct, '***') = 'CORRECT'
1501                         then
1502 				l_par.first_noa_cancel_or_correct := ghr_history_api.g_cancel;
1503 			end if;
1504 		end if;
1505 
1506 		if l_par.second_noa_code is not NULL then
1507 			-- handle dual actions
1508 			if l_par.second_noa_cancel_or_correct is null  then
1509 				l_par.second_noa_cancel_or_correct := ghr_history_api.g_cancel;
1510 			end if;
1511 
1512 		     --6850492 added the condition for dual action correction
1513 		     -- added for the bug 8250185
1514 		     if l_par.first_noa_code not in ('001' , '002') and
1515 		         l_par.second_noa_code is not NULL  and
1516 			 NVL(l_par.second_noa_cancel_or_correct, '***') = 'CORRECT' then
1517 			 l_par.second_noa_cancel_or_correct := ghr_history_api.g_cancel;
1518 	             end if;
1519 		     --8250185
1520 		end if;
1521 
1522 
1523 
1524 		ghr_sf52_api.update_Sf52(
1525 			p_pa_request_id                => l_par.pa_request_id,
1526 			p_par_object_version_number    => l_par.object_version_number,
1527 			p_first_noa_cancel_or_correct  => l_par.first_noa_cancel_or_correct,
1528 			p_second_noa_cancel_or_correct => l_par.second_noa_cancel_or_correct,
1529 			p_u_prh_object_version_number  => l_u_prh_object_version_number,
1530 			p_i_pa_routing_history_id      => l_i_pa_routing_history_id,
1531 			p_i_prh_object_version_number  => l_i_prh_object_version_number,
1532 			p_u_action_taken               => 'NONE'
1533 			);
1534 	End loop;
1535 
1536 	hr_utility.set_location( l_proc, 80);
1537 
1538 	hr_utility.set_location(' Leaving ' || l_proc, 100);
1539   Exception when others then
1540             --
1541             -- Reset IN OUT parameters and set OUT parameters
1542             --
1543             p_sf52_data := l_sf52_data_rec;
1544             raise;
1545 
1546 End Cancel_Appt_SF52;
1547 
1548 -- ---------------------------------------------------------------------------
1549 -- |--------------------------< cancel_correction_sf52>-----------------------|
1550 -- ---------------------------------------------------------------------------
1551 -- {Start Of Comments}
1552 --
1553 -- Description:
1554 --   	This procedure cancels a correction sf52.
1555 --
1556 -- Pre-Requisities:
1557 --   	None.
1558 --
1559 -- In Parameters:
1560 --	p_sf52_data		->		ghr_pa_requests record of the correction sf52.
1561 --
1562 -- Post Success:
1563 -- 	The correction sf52 will have been cancelled.
1564 --
1565 -- Post Failure:
1566 --   	No failure conditions.
1567 --
1568 -- Developer Implementation Notes:
1569 --   	At this point, cancellation of a correction sf52 is handled just the same as a cancellation
1570 --	of a normal sf52. So, this procedure just calls the cancel_other_family_sf52 procedure.
1571 --
1572 -- Access Status:
1573 --   Internal Development Use Only.
1574 --
1575 -- {End Of Comments}
1576 -- ---------------------------------------------------------------------------
1577 Procedure Cancel_Correction_SF52 ( p_sf52_data		in out nocopy 	ghr_pa_requests%rowtype) is
1578 	l_proc	varchar2(30):='Cancel_Correction_SF52';
1579    l_sf52_data ghr_pa_requests%rowtype;
1580 Begin
1581 	hr_utility.set_location('entering : ' || l_proc, 10);
1582    l_sf52_data := p_sf52_data;
1583 	Cancel_Other_Family_Sf52 (p_sf52_data);
1584 	hr_utility.set_location('leaving : ' || l_proc, 20);
1585  exception when others then
1586            --
1587            -- Reset IN OUT parameters and set OUT parameters
1588            --
1589            p_sf52_data := l_sf52_data;
1590            raise;
1591 End Cancel_Correction_SF52;
1592 
1593 -- ---------------------------------------------------------------------------
1594 -- |--------------------------< cancel_other_family_sf52>---------------------|
1595 -- ---------------------------------------------------------------------------
1596 -- {Start Of Comments}
1597 --
1598 -- Description:
1599 --   	This procedure handles a cancellation of a 'normal' sf52.
1600 --
1601 -- Pre-Requisities:
1602 --   	None.
1603 --
1604 -- In Parameters:
1605 --	p_sf52_data		->		ghr_pa_requests record of the correction sf52.
1606 -- Post Success:
1607 -- 	The cancellation will have been applied.
1608 --
1609 -- Post Failure:
1610 --   	No failure conditions.
1611 --
1612 -- Developer Implementation Notes:
1613 --	None.
1614 --
1615 -- Access Status:
1616 --   Internal Development Use Only.
1617 --
1618 -- {End Of Comments}
1619 -- ---------------------------------------------------------------------------
1620 
1621 PROCEDURE Cancel_Other_Family_Sf52 ( p_sf52_data in out nocopy ghr_pa_requests%rowtype) AS
1622         l_buf                           number;
1623    	l_eff_date			date;
1624    	l_proc				varchar2(72) := 'Cancel_Other_Family_Sf52' ;
1625    	l_date_eff_rec			pay_element_entry_values_f%rowtype;
1626    	l_hist_dummy			ghr_pa_history%rowtype;
1627    	l_hist_rec			ghr_pa_requests%rowtype;
1628         l_hist_address_rec      ghr_pa_history%rowtype;
1629    	l_hist_pre			ghr_pa_history%rowtype;
1630    	l_hist_data_as_of_date	ghr_pa_history%rowtype;
1631    	l_return_status		varchar2(100);
1632    	l_interv_on_table		boolean;
1633    	l_interv_on_eff_date		boolean;
1634    	l_pre_record			boolean;
1635    	l_can_delete			boolean;
1636    	l_last_row			boolean;
1637    	l_cannot_cancel		boolean;
1638    	l_datetrack_table		boolean;
1639    	l_datetrack_mode		varchar2(30);
1640    	l_session_var			ghr_history_api.g_session_var_type;
1641    	l_result_code			varchar2(30);
1642    	l_rec_created_flag   	boolean;
1643    	l_del_mode			varchar2(30);
1644 	l_agency_ei_data	ghr_pa_request_extra_info%rowtype;
1645 	l_imm_asg_sf52          	ghr_api.asg_sf52_type;
1646 	l_imm_asg_non_sf52		ghr_api.asg_non_sf52_type;
1647 	l_imm_asg_nte_dates     	ghr_api.asg_nte_dates_type;
1648 	l_imm_per_sf52          	ghr_api.per_sf52_type;
1649 	l_imm_per_group1        	ghr_api.per_group1_type;
1650 	l_imm_per_group2        	ghr_api.per_group2_type;
1651 	l_imm_per_scd_info      	ghr_api.per_scd_info_type;
1652 	l_imm_per_retained_grade      ghr_api.per_retained_grade_type;
1653 	l_imm_per_probations          ghr_api.per_probations_type;
1654 	l_imm_per_sep_retire          ghr_api.per_sep_retire_type;
1655 	l_imm_per_security		ghr_api.per_security_type;
1656 	-- Bug#4486823 RRR changes
1657 	l_imm_per_service_oblig     ghr_api.per_service_oblig_type;
1658 	l_imm_per_conversions		ghr_api.per_conversions_type;
1659 	-- 4352589 BEN_EIT Changes
1660 	l_imm_per_benefit_info        ghr_api.per_benefit_info_type;
1661 	l_imm_per_uniformed_services  ghr_api.per_uniformed_services_type;
1662 	l_imm_pos_oblig               ghr_api.pos_oblig_type;
1663 	l_imm_pos_grp2                ghr_api.pos_grp2_type;
1664 	l_imm_pos_grp1                ghr_api.pos_grp1_type;
1665 	l_imm_pos_valid_grade         ghr_api.pos_valid_grade_type;
1666 	l_imm_pos_car_prog            ghr_api.pos_car_prog_type;
1667 	l_imm_loc_info                ghr_api.loc_info_type;
1668 	l_imm_wgi     	            ghr_api.within_grade_increase_type;
1669 	l_imm_gov_awards              ghr_api.government_awards_type;
1670 	l_imm_recruitment_bonus	      ghr_api.recruitment_bonus_type;
1671 	l_imm_relocation_bonus		ghr_api.relocation_bonus_type;
1672 	l_imm_student_loan_repay  	ghr_api.student_loan_repay_type;
1673 	--Pradeep
1674 	l_imm_mddds_special_pay         ghr_api.mddds_special_pay_type;
1675 	l_imm_premium_pay_ind           ghr_api.premium_pay_ind_type;
1676 
1677 	l_imm_extra_info_rec	 	ghr_api.extra_info_rec_type ;
1678 	l_imm_sf52_from_data          ghr_api.prior_sf52_data_type;
1679 	l_imm_personal_info		ghr_api.personal_info_type;
1680 	l_imm_generic_extra_info_rec	ghr_api.generic_extra_info_rec_type ;
1681 	l_imm_agency_sf52		      ghr_api.agency_sf52_type;
1682 	l_agency_code			varchar2(50);
1683 	l_imm_perf_appraisal          ghr_api.performance_appraisal_type;
1684 	l_imm_conduct_performance     ghr_api.conduct_performance_type;
1685 	l_imm_payroll_type            ghr_api.government_payroll_type;
1686 	l_imm_par_term_retained_grade ghr_api.par_term_retained_grade_type;
1687 	l_imm_entitlement             ghr_api.entitlement_type;
1688         -- Bug#2759379 Added FEGLI Record
1689         l_imm_fegli                   ghr_api.fegli_type;
1690 	l_imm_foreign_lang_prof_pay   ghr_api.foreign_lang_prof_pay_type;
1691 	-- Bug#3385386 Added FTA Record
1692 	l_imm_fta                     ghr_api.fta_type;
1693 	l_imm_edp_pay                 ghr_api.edp_pay_type;
1694 	l_imm_hazard_pay              ghr_api.hazard_pay_type;
1695 	l_imm_health_benefits         ghr_api.health_benefits_type;
1696 	l_imm_danger_pay              ghr_api.danger_pay_type;
1697 	l_imm_imminent_danger_pay     ghr_api.imminent_danger_pay_type;
1698 	l_imm_living_quarters_allow   ghr_api.living_quarters_allow_type;
1699 	l_imm_post_diff_amt           ghr_api.post_diff_amt_type;
1700 	l_imm_post_diff_percent       ghr_api.post_diff_percent_type;
1701 	l_imm_sep_maintenance_allow   ghr_api.sep_maintenance_allow_type;
1702 	l_imm_supplemental_post_allow ghr_api.supplemental_post_allow_type;
1703 	l_imm_temp_lodge_allow        ghr_api.temp_lodge_allow_type;
1704 	l_imm_premium_pay             ghr_api.premium_pay_type;
1705 	l_imm_retirement_annuity      ghr_api.retirement_annuity_type;
1706 	l_imm_severance_pay           ghr_api.severance_pay_type;
1707 	l_imm_thrift_saving_plan      ghr_api.thrift_saving_plan;
1708 	l_imm_retention_allow_review  ghr_api.retention_allow_review_type;
1709 	l_imm_health_ben_pre_tax         ghr_api.health_ben_pre_tax_type;
1710 	l_imm_per_race_ethnic_info 	  ghr_api.per_race_ethnic_type; -- Bug 4724337 Race or National Origin changes
1711 	l_sf52_data				ghr_pa_requests%rowtype;
1712 	l_sf52_data_rec      ghr_pa_requests%rowtype;
1713 	l_health_plan			varchar2(30);
1714 	l_error_flag			boolean;
1715 	l_pa_history_id			number;
1716    	l_result				boolean;
1717    	l_deleted				boolean;
1718         l_system_type                   per_person_types.system_person_type%type;
1719         l_prior_noa_code                ghr_nature_of_actions.code%type;
1720         l_noa_family_code               ghr_families.noa_family_code%type;
1721 		l_prior_asg_id					per_assignments_f.assignment_id%type; --Bug# 5442674
1722 
1723          -- bug #6312144
1724          l_imm_ipa_benefits_cont       ghr_api.per_ipa_ben_cont_info_type;
1725         l_imm_retirement_info         ghr_api.per_retirement_info_type;
1726 	l_imm_asg_detail_info		ghr_api.asg_detail_info_type; --Bug# 8653508
1727 
1728 	--BUG # 13571004
1729 	l_imm_roth_tsp                ghr_api.tsp_roth_type;
1730 
1731 
1732    -- this cursor retrieves the ghr_pa_history row for the pa_request_id and noa_id given.
1733    -- note that this cursor orders by table name, this is due to the fact that we need to
1734    -- handle PAY_ELEMENT_ENTRY_VALUES_F history records before PAY_ELEMENT_ENTRIES_F history
1735    -- records due to the parent-child relationship of these two tables. Fetch_history routine
1736    -- for elements relies on the parent record in history being intact.
1737    cursor c_history_info 	(cp_pa_request_id in 	ghr_pa_requests.pa_request_id%type,
1738    				cp_noa_id		in	ghr_pa_requests.first_noa_id%type) is
1739    SELECT	*
1740    FROM		GHR_PA_HISTORY
1741    WHERE		pa_request_id		= cp_pa_request_id
1742    	AND	nature_of_action_id	= cp_noa_id
1743 	ORDER BY DECODE(table_name, 'PAY_ELEMENT_ENTRY_VALUES_F', -2,
1744                                     'PAY_ELEMENT_ENTRIES_F', -1,
1745                         pa_history_id) asc;
1746 
1747 --start of bug #5900178
1748 -- Added this below cursor for the bug#5900178 to validate whether per_person_analyses
1749 --record is available for updation or not if it is available it will be continue otherwise
1750 --- it wont continue for cascading
1751     cursor chk_perana_exists(p_person_analysis_id in per_person_analyses.person_analysis_id%type)
1752         is
1753         SELECT 1
1754         FROM   PER_PERSON_ANALYSES
1755         WHERE  person_analysis_id = p_person_analysis_id;
1756 
1757    m_perana varchar2(1);
1758    l_rec_exists boolean;
1759 --end of bug #5900178
1760 
1761 -- Bug#2780976 Modified the cursor c_prior_person_type
1762 -- Bug# 5442674 Modified the select statement
1763    Cursor c_prior_person_type is
1764   Select paf.assignment_id
1765       from   per_assignments_f paf
1766       where  paf.person_id =   p_sf52_data.person_id
1767 	  and	 paf.assignment_type='E'
1768       and    p_sf52_data.effective_date-1 between paf.effective_start_date and paf.effective_end_date;
1769 
1770    Cursor c_prior_noa_code is
1771      Select par.first_noa_code,
1772             par.first_noa_id
1773      from   ghr_pa_requests par
1774      where  par.pa_request_id = p_sf52_data.altered_pa_request_id;
1775 
1776   Cursor c_noa_family(p_noa_id in number) is
1777     Select fam.noa_family_code
1778     from   ghr_noa_families nof,
1779            ghr_families fam
1780     where  nof.nature_of_action_id =  p_noa_id
1781     and    fam.noa_family_code     = nof.noa_family_code
1782     and    nvl(fam.proc_method_flag,hr_api.g_varchar2) = 'Y'
1783     and    p_sf52_data.effective_date
1784     between nvl(fam.start_date_active,p_sf52_data.effective_date)
1785     and     nvl(fam.end_date_active,p_sf52_data.effective_date);
1786 
1787     cursor c_follow_rec(        c_table_name    ghr_pa_history.table_name%type,
1788                                         c_pk_id         ghr_pa_history.information1%type,
1789                                         c_pa_history_id ghr_pa_history.pa_history_id%type) is
1790         select  pa_history_id
1791         from            ghr_pa_history
1792         where           table_name              = c_table_name
1793                 and     information1    = c_pk_id
1794                 and     pa_history_id   > c_pa_history_id;
1795 
1796 
1797         cursor c_hist_address ( c_pa_request_id number,
1798                             c_noa_id            number) is
1799         select
1800                 rowid row_id, table_name,pa_history_id,information5
1801                 ,information9, information10
1802         from ghr_pa_history
1803         where pa_request_id = c_pa_request_id
1804         and   table_name = ghr_history_api.g_addres_table
1805         and  nature_of_action_id = c_noa_id
1806         for update of person_id
1807         order by pa_history_id desc;
1808 --
1809        Cursor Cur_bg(p_person_id NUMBER,
1810                     p_eff_date DATE) is
1811        Select distinct business_group_id bg
1812        from per_assignments_f
1813        where person_id = p_person_id
1814        and   p_eff_date between effective_start_date
1815              and effective_end_date;
1816 --
1817        ll_bg_id                    NUMBER;
1818        ll_pay_basis                VARCHAR2(80);
1819        ll_effective_date           DATE;
1820        l_new_element_name          VARCHAR2(80);
1821    --
1822     -- Bug#2521744 Declared 2 variables,2 cursors.
1823            l_element_name    VARCHAR2(80);
1824            l_element_name1   VARCHAR2(80);
1825 	   l_bus_group_id    NUMBER;
1826 
1827         CURSOR c_element_name(p_element_link_id NUMBER) IS
1828         SELECT elt.element_name
1829         FROM PAY_ELEMENT_LINKS_F ell,PAY_ELEMENT_TYPES_F elt
1830         WHERE ell.ELEMENT_type_id = elt.element_type_id
1831           AND ell.element_link_id = p_element_link_id;
1832     --
1833     --  Created the following cursor to handle same day other pay actions.
1834     CURSOR c_element_name1(p_element_entry_id NUMBER) IS
1835             SELECT elt.element_name
1836         FROM PAY_ELEMENT_LINKS_F ell,
1837              PAY_ELEMENT_TYPES_F elt,
1838              pay_element_entries_f ele
1839         WHERE ell.ELEMENT_type_id = elt.element_type_id
1840           AND ele.element_type_id = elt.element_type_id
1841           AND ell.element_link_id = ele.element_link_id
1842           AND ele.element_entry_id = p_element_entry_id;
1843     -- end of 2521744;
1844 --
1845  --Bug# 6127620
1846    --  l_curr_sess_date        fnd_sessions.effective_date%type;
1847 
1848 --   Bug  14002125
1849 CURSOR chk_hist_rec_avl(p_pa_request_id  NUMBER,
1850                         p_pa_history_id  NUMBER,
1851 			p_table_name     VARCHAR2,
1852 			p_information    VARCHAR2)
1853     IS
1854     SELECT   1
1855     FROM     ghr_pa_history
1856     WHERE    pa_request_id IN (SELECT pa_request_id FROM ghr_pa_requests
1857                                CONNECT BY pa_request_id = PRIOR altered_pa_request_id
1858 			       START WITH pa_request_id = p_pa_request_id)
1859      AND     pa_history_id < p_pa_history_id
1860      AND     table_name   = p_table_name
1861      AND     information1 = p_information;
1862 
1863 p_avl  NUMBER;
1864 
1865 BEGIN
1866        -- hr_utility.trace_on(null,'venkat');
1867         hr_utility.set_location('Entering  '|| l_proc,5);
1868         l_sf52_data_rec  := p_sf52_data;
1869 -- Initialization
1870 --
1871 	l_sf52_data_rec  := p_sf52_data;
1872          For BG_rec in Cur_BG(l_sf52_data_rec.person_id,
1873 	                      l_sf52_data_rec.effective_date)
1874           Loop
1875            ll_bg_id  :=BG_rec.bg;
1876           End Loop;
1877 -- Effective_date
1878      ll_effective_date := l_sf52_data_rec.effective_date;
1879 --   Pick pay basis from PAR
1880 
1881           for noa_family_rec in c_noa_family(p_sf52_data.second_noa_id) loop
1882             l_noa_family_code :=  noa_family_rec.noa_family_code;
1883         end loop;
1884         If nvl(l_noa_family_code,hr_api.g_varchar2) = 'CONV_APP' then
1885           hr_utility.set_location('CAncel of conversion',1);
1886           -- check to see if the person was an EX_EMP prior to the effective
1887           -- date of this action.
1888           for prior_person_type in c_prior_person_type loop
1889             l_prior_asg_id :=  prior_person_type.assignment_id;  --Bug# 5442674
1890             exit;
1891           end loop;
1892           for prior_noa_code in c_prior_noa_code loop
1893             l_prior_noa_code := prior_noa_code.first_noa_code;
1894           end loop;
1895         End if;
1896 		hr_utility.set_location('Family Code' || l_noa_family_code,1000);
1897 		hr_utility.set_location('Second NOA Code' || p_sf52_data.second_noa_code,1000);
1898 		hr_utility.set_location('Prior Assignment Id' || l_prior_asg_id,1001);
1899 		hr_utility.set_location('Assignment Id' || l_sf52_data_rec.employee_assignment_id,1002);
1900         If nvl(l_noa_family_code,hr_api.g_varchar2) = 'CONV_APP'  and
1901 		nvl(l_prior_asg_id,hr_api.g_number) <> l_sf52_data_rec.employee_assignment_id and  --Bug# 5442674
1902            nvl(l_prior_noa_code,hr_api.g_varchar2) <> '002' then
1903 
1904             hr_utility.set_location('Cancel of Ex_EMP conversion',1);
1905              ghr_corr_canc_sf52.cancel_appt_sf52(p_sf52_data);
1906         Else
1907   	-- reinitialise session variables
1908   	ghr_history_api.reinit_g_session_var;
1909   	-- set values of session variables
1910   	l_session_var.pa_request_id 	:= p_sf52_data.pa_request_id;
1911   	l_session_var.noa_id		:= p_sf52_data.second_noa_id;
1912   	l_session_var.fire_trigger	:= 'Y';
1913   	l_session_var.date_Effective	:= p_sf52_data.effective_date;
1914   	l_session_var.person_id		:= p_sf52_data.person_id;
1915   	l_session_var.program_name	:= 'sf50';
1916   	l_session_var.altered_pa_request_id	:= p_sf52_data.altered_pa_request_id;
1917   	l_session_var.noa_id_correct	:= p_sf52_data.second_noa_id;
1918   	l_session_var.assignment_id	:= p_sf52_data.employee_assignment_id;
1919 
1920   	ghr_history_api.set_g_session_var(l_session_var);
1921 
1922 	ghr_process_Sf52.Fetch_extra_info(
1923 			p_pa_request_id 	=> p_sf52_data.pa_request_id,
1924 			p_noa_id   		=> p_sf52_data.second_noa_id,
1925 			p_agency_ei		=> TRUE,
1926 			p_sf52_ei_data 	=> l_agency_ei_data,
1927 			p_result		=> l_result_code);
1928 
1929 	l_sf52_data 	:= p_sf52_data;
1930 	-- all corrections will have the original sf52 information in the 2nd noa columns, so
1931 	-- copy that information to 1st noa columns.
1932 	ghr_process_sf52.copy_2ndNoa_to_1stNoa(l_sf52_data);
1933 	-- null the second noa columns since we don't want anything to be done with these now.
1934 	ghr_process_sf52.null_2ndNoa_cols(l_sf52_data);
1935 
1936 	ghr_sf52_pre_update.populate_record_groups (
1937 		 	p_pa_request_rec                => l_sf52_data,
1938 			p_generic_ei_rec                => l_agency_ei_data,
1939 			p_imm_asg_sf52                  => l_imm_asg_sf52,
1940 			p_imm_asg_non_sf52              => l_imm_asg_non_sf52,
1941 			p_imm_asg_nte_dates             => l_imm_asg_nte_dates,
1942 			p_imm_asg_detail_info	        => l_imm_asg_detail_info, --Bug# 8653508
1943 			p_imm_per_sf52                  => l_imm_per_sf52,
1944 			p_imm_per_group1                => l_imm_per_group1,
1945 			p_imm_per_group2                => l_imm_per_group2,
1946 			p_imm_per_scd_info              => l_imm_per_scd_info,
1947 			p_imm_per_retained_grade        => l_imm_per_retained_grade,
1948 			p_imm_per_probations            => l_imm_per_probations,
1949 			p_imm_per_sep_retire            => l_imm_per_sep_retire,
1950 			p_imm_per_security              => l_imm_per_security,
1951             --Bug#4486823 RRR Changes
1952             p_imm_per_service_oblig         => l_imm_per_service_oblig,
1953 			p_imm_per_conversions           => l_imm_per_conversions,
1954 			-- 4352589 BEN_EIT Changes
1955 			p_imm_per_benefit_info          => l_imm_per_benefit_info,
1956 			p_imm_per_uniformed_services    => l_imm_per_uniformed_services,
1957 			p_imm_pos_oblig                 => l_imm_pos_oblig,
1958 			p_imm_pos_grp2                  => l_imm_pos_grp2,
1959 			p_imm_pos_grp1                  => l_imm_pos_grp1,
1960 			p_imm_pos_valid_grade           => l_imm_pos_valid_grade,
1961 			p_imm_pos_car_prog              => l_imm_pos_car_prog,
1962 			p_imm_loc_info                  => l_imm_loc_info,
1963 			p_imm_wgi                       => l_imm_wgi,
1964 			p_imm_gov_awards                => l_imm_gov_awards,
1965 			p_imm_recruitment_bonus         => l_imm_recruitment_bonus,
1966 			p_imm_relocation_bonus          => l_imm_relocation_bonus,
1967 			p_imm_student_loan_repay        => l_imm_student_loan_repay,
1968 			p_imm_per_race_ethnic_info 		=> l_imm_per_race_ethnic_info, -- Bug 4724337 Race or National Origin changes
1969 			--Pradeep
1970 			p_imm_mddds_special_pay         => l_imm_mddds_special_pay,
1971 			p_imm_premium_pay_ind           => l_imm_premium_pay_ind,
1972 
1973 			p_imm_perf_appraisal            => l_imm_perf_appraisal,
1974 			p_imm_conduct_performance       => l_imm_conduct_performance,
1975 			p_imm_payroll_type              => l_imm_payroll_type,
1976 			p_imm_extra_info_rec	        => l_imm_extra_info_rec,
1977 			p_imm_sf52_from_data            => l_imm_sf52_from_data,
1978 			p_imm_personal_info	        => l_imm_personal_info,
1979 			p_imm_generic_extra_info_rec    => l_imm_generic_extra_info_rec,
1980 			p_imm_agency_sf52               => l_imm_agency_sf52,
1981 			p_agency_code                   => l_agency_code,
1982 			p_imm_par_term_retained_grade   => l_imm_par_term_retained_grade,
1983 			p_imm_entitlement               => l_imm_entitlement,
1984                         -- Bug#2759379 Added FEGLI Record
1985                         p_imm_fegli                     => l_imm_fegli,
1986 			p_imm_foreign_lang_prof_pay     => l_imm_foreign_lang_prof_pay,
1987 			-- Bug#3385386 Added FTA Record
1988 			p_imm_fta                       => l_imm_fta,
1989 			p_imm_edp_pay                   => l_imm_edp_pay,
1990 			p_imm_hazard_pay                => l_imm_hazard_pay,
1991 			p_imm_health_benefits           => l_imm_health_benefits,
1992 			p_imm_danger_pay                => l_imm_danger_pay,
1993 			p_imm_imminent_danger_pay       => l_imm_imminent_danger_pay,
1994 			p_imm_living_quarters_allow     => l_imm_living_quarters_allow,
1995 			p_imm_post_diff_amt             => l_imm_post_diff_amt,
1996 			p_imm_post_diff_percent         => l_imm_post_diff_percent,
1997 			p_imm_sep_maintenance_allow     => l_imm_sep_maintenance_allow,
1998 			p_imm_supplemental_post_allow   => l_imm_supplemental_post_allow,
1999 			p_imm_temp_lodge_allow          => l_imm_temp_lodge_allow,
2000 			p_imm_premium_pay               => l_imm_premium_pay,
2001 			p_imm_retirement_annuity        => l_imm_retirement_annuity,
2002 			p_imm_severance_pay             => l_imm_severance_pay,
2003 			p_imm_thrift_saving_plan        => l_imm_thrift_saving_plan,
2004 			p_imm_retention_allow_review        => l_imm_retention_allow_review,
2005 			p_imm_health_ben_pre_tax           => l_imm_health_ben_pre_tax,
2006 			--Bug# 6312144 RPA EIT Benefits
2007 			p_imm_ipa_benefits_cont         => l_imm_ipa_benefits_cont,
2008                         p_imm_retirement_info           => l_imm_retirement_info,
2009 			--BUG # 13571004 added TSP Roth
2010                         p_imm_tsp_roth                  => l_imm_roth_tsp
2011 			);
2012 
2013 --
2014 	ghr_api.retrieve_element_entry_value
2015 		( p_element_name	=>  'Health Benefits'
2016 		 ,p_input_value_name    =>  'Health Plan'
2017 		 ,p_assignment_id       =>   l_sf52_data.employee_assignment_id
2018 		 ,p_effective_date      =>   trunc(l_sf52_data.effective_date)
2019 		 ,p_value               =>   l_health_plan
2020 		 ,p_multiple_error_flag =>   l_error_flag
2021 		 );
2022 
2023 	GHR_AGENCY_CHECK.AGENCY_CHECK(
2024 			p_pa_request_rec			=> l_sf52_data,
2025 			p_asg_sf52				=> l_imm_asg_sf52,
2026 			p_asg_non_sf52			=> l_imm_asg_non_sf52,
2027 			p_asg_nte_dates			=> l_imm_asg_nte_dates,
2028 			p_per_sf52              	=> l_imm_per_sf52,
2029 			p_per_group1            	=> l_imm_per_group1,
2030 			p_per_group2            	=> l_imm_per_group2,
2031 			p_per_scd_info          	=> l_imm_per_scd_info,
2032 			p_per_retained_grade    	=> l_imm_per_retained_grade,
2033 			p_per_probations			=> l_imm_per_probations,
2034 			p_per_sep_Retire 	      	=> l_imm_per_sep_retire,
2035 			p_per_security          	=> l_imm_per_security,
2036 			p_per_conversions	      	=> l_imm_per_conversions,
2037 			p_per_uniformed_services	=> l_imm_per_uniformed_services,
2038 			p_pos_oblig                   => l_imm_pos_oblig,
2039 			p_pos_grp2                    => l_imm_pos_grp2,
2040 			p_pos_grp1                    => l_imm_pos_grp1,
2041 			p_pos_valid_grade             => l_imm_pos_valid_grade,
2042 			p_pos_car_prog                => l_imm_pos_car_prog,
2043 			p_loc_info                    => l_imm_loc_info,
2044 			p_wgi                         => l_imm_wgi,
2045 			p_recruitment_bonus	      => l_imm_recruitment_bonus,
2046 			p_relocation_bonus	      => l_imm_relocation_bonus ,
2047 			p_sf52_from_data              => l_imm_sf52_from_data,
2048 			p_personal_info	            => l_imm_personal_info,
2049 			p_gov_awards_type             => l_imm_gov_awards,
2050 			p_perf_appraisal_type         => l_imm_perf_appraisal,
2051 			p_payroll_type                => l_imm_payroll_type,
2052 			p_conduct_perf_type           => l_imm_conduct_performance,
2053 			p_agency_code		      => l_agency_code,
2054 			p_agency_sf52			=> l_imm_agency_sf52,
2055 			p_health_plan			=> l_health_plan,
2056 			p_entitlement                 => l_imm_entitlement,
2057 			p_foreign_lang_prof_pay       => l_imm_foreign_lang_prof_pay,
2058 			p_edp_pay                     => l_imm_edp_pay,
2059 			p_hazard_pay                  => l_imm_hazard_pay,
2060 			p_health_benefits             => l_imm_health_benefits,
2061 			p_danger_pay                  => l_imm_danger_pay,
2062 			p_imminent_danger_pay         => l_imm_imminent_danger_pay,
2063 			p_living_quarters_allow       => l_imm_living_quarters_allow,
2064 			p_post_diff_amt               => l_imm_post_diff_amt,
2065 			p_post_diff_percent           => l_imm_post_diff_percent,
2066 			p_sep_maintenance_allow       => l_imm_sep_maintenance_allow,
2067 			p_supplemental_post_allow     => l_imm_supplemental_post_allow,
2068 			p_temp_lodge_allow            => l_imm_temp_lodge_allow,
2069 			p_premium_pay                 => l_imm_premium_pay,
2070 			p_retirement_annuity          => l_imm_retirement_annuity,
2071 			p_severance_pay               => l_imm_severance_pay,
2072 			p_thrift_saving_plan          => l_imm_thrift_saving_plan,
2073 			p_retention_allow_review      => l_imm_retention_allow_review,
2074 			p_health_ben_pre_tax          => l_imm_health_ben_pre_tax,
2075 			p_per_benefit_info            => l_imm_per_benefit_info,
2076 			p_imm_retirement_info         => l_imm_retirement_info, --Bug# 7131104
2077 			--Begin Bug# 10181661
2078 			p_asg_detail_info	      => l_imm_asg_detail_info,
2079 			p_ipa_detail_ben_cont_info    => l_imm_ipa_benefits_cont
2080 			--End Bug# 10181661
2081 			);
2082 -- Bug#2347658
2083 --Cancel address records in a different style for Correction to Separation action.
2084   IF (l_noa_family_code = 'SEPARATION') Then
2085     FOR l_hist IN c_hist_address(p_sf52_data.altered_pa_request_id, p_sf52_data.second_noa_id)
2086     LOOP
2087                        SELECT   *
2088                         INTO            l_hist_address_rec
2089                         FROM            ghr_pa_history
2090                         WHERE           pa_history_id   = l_hist.pa_history_id;
2091 
2092                         ghr_history_api.fetch_history_info(
2093                                 p_table_name            => ghr_history_api.g_addres_table,
2094                                 p_hist_data                     => l_hist_pre,
2095                                 p_pa_history_id         => l_hist_address_rec.pa_history_id,
2096                                 p_table_pk_id           => l_hist_address_rec.information1,
2097                                 p_person_id                     => p_sf52_data.person_id,
2098                                 p_date_effective                => p_sf52_data.effective_date,
2099                                 p_result_code           => l_return_status);
2100                         if (l_return_status is not null) then
2101                                 -- there were no prevalues for this record
2102                                 -- only delete application table if there are no following records.
2103                                 open c_follow_rec(  c_table_name    =>      l_hist_address_rec.table_name,
2104                                                     c_pk_id        =>      l_hist_address_rec.information1,
2105                                                     c_pa_history_id =>      l_hist_address_rec.pa_history_id);
2106                                 fetch c_follow_rec into l_buf;
2107                                 if c_follow_rec%NOTFOUND then
2108                                         delete_appl_row(
2109                                                 p_table_name    => ghr_history_api.g_addres_table,
2110                                                 p_table_pk_id   => l_hist_address_rec.information1,
2111                                                 p_dt_mode               => null,
2112                                                 p_date_effective        => l_hist_address_rec.effective_date);
2113                                 end if;
2114                                 close c_follow_rec;
2115                         else
2116                        -- there is a pre record, so apply it to the history table and to the application table.
2117                                 ghr_history_cascade.cascade_history_data (
2118                                         p_table_name            =>      l_hist_address_rec.table_name,
2119                                         p_person_id                     =>      l_hist_address_rec.person_id,
2120                                         p_pre_record            =>      l_hist_pre,
2121                                         p_post_record           =>      l_hist_address_rec,
2122                                         p_cascade_type          =>      'cancel',
2123                                         p_interv_on_table       =>      l_interv_on_table,
2124                                         p_interv_on_eff_date    =>      l_interv_on_eff_date,
2125                                         p_hist_data_as_of_date  =>      l_hist_data_as_of_date);
2126                                 delete_hist_row( l_hist.row_id);
2127                                 ghr_history_cascade.cascade_appl_table_data (
2128                                         p_table_name            =>      l_hist_address_rec.table_name,
2129                                         p_person_id             =>      l_hist_address_rec.person_id,
2130                                         p_pre_record            =>      l_hist_pre,
2131                                        p_post_record           =>      l_hist_address_rec,
2132                                         p_cascade_type          =>      'cancel',
2133                                         p_interv_on_table       =>      l_interv_on_table,
2134                                         p_interv_on_eff_date    =>      l_interv_on_eff_date,
2135                                         p_hist_data_as_of_date  =>      l_hist_data_as_of_date);
2136                         end if;
2137      END LOOP;
2138   END IF;
2139 -- Bug#2347658 (End of fix)
2140 
2141   	-- loop thru all history records for the NOA that is being cancelled.
2142   	FOR l_hist_rec in c_history_info(p_sf52_data.altered_pa_request_id, p_sf52_data.second_noa_id) LOOP
2143 	      hr_utility.set_location('Entering  LOOP'|| l_proc,10);
2144   		l_pre_record 	:=	TRUE;
2145   		l_datetrack_table	:= 	TRUE;
2146 		-- initialize pre-record to all nulls
2147 		l_hist_pre	:=	l_hist_dummy;
2148   		-- get pre-record for the record fetched
2149   		ghr_history_api.fetch_history_info(
2150  			p_table_name 		=> l_hist_rec.table_name,
2151   			p_hist_data			=> l_hist_pre,
2152   			p_pa_history_id		=> l_hist_rec.pa_history_id,
2153   			p_table_pk_id 		=> l_hist_rec.information1,
2154   			p_person_id			=> l_hist_rec.person_id,
2155   			p_date_effective		=> l_hist_rec.effective_date,
2156   			p_result_code		=> l_return_status);
2157 		hr_utility.set_location('after fetch history info',12345);
2158 		hr_utility.set_location('status is'||l_return_status,12345);
2159 		hr_utility.set_location('hist id'||l_hist_rec.pa_history_id,12345);
2160 		hr_utility.set_location('person id'||l_hist_rec.person_id,12345);
2161 		hr_utility.set_location('eff_date is '||l_hist_rec.effective_date,12345);
2162 
2163 		if (l_return_status is not null) then
2164 			-- there were no prevalues for this record
2165 		      hr_utility.set_location('no pre-values'|| l_proc,15);
2166  			l_pre_record 	:= FALSE;
2167 		else
2168 			-- Debug statements
2169 			hr_utility.set_location('Pre Value - pa_history_id ' || l_hist_pre.pa_history_id, 16);
2170 			hr_utility.set_location('Pre Value - effective_date ' || l_hist_pre.effective_date, 17);
2171 			hr_utility.set_location('Information1 : ' || l_hist_pre.information1, 18);
2172 			hr_utility.set_location('Information2 : ' || l_hist_pre.information2, 19);
2173 
2174  		end if;
2175 		-- all mappings are such that information2 always corresponds to effective_start_date. If this
2176 		-- column is null, then the row concerns a non-datetrack table. If it is not null, then this row
2177 		-- concerns a datetrack table.
2178   		if (l_hist_rec.information2 is null) then
2179 		      hr_utility.set_location('datetrack table'|| l_proc,20);
2180   			l_datetrack_table	:= FALSE;
2181   		end if;
2182 		-- PAY_ELEMENT_ENTRY needs to be handled differently
2183   		if lower(l_hist_rec.table_name) = lower(ghr_history_api.g_eleent_table) then
2184 		      hr_utility.set_location('Processing element entry record'|| l_proc,25);
2185     			if l_hist_rec.DML_operation = ghr_history_api.g_ins_operation then
2186 			--6850492
2187 			   if to_date(l_hist_pre.information2, ghr_history_api.g_hist_date_format) = to_date(l_hist_rec.information2, ghr_history_api.g_hist_date_format) then
2188 			       ghr_history_api.fetch_history_info(
2189  			                 p_table_name 		=> l_hist_rec.table_name,
2190   			                 p_hist_data			=> l_hist_pre,
2191   			                 p_pa_history_id		=> l_hist_rec.pa_history_id,
2192   			                 p_table_pk_id 		=> l_hist_rec.information1,
2193   			                 p_person_id			=> l_hist_rec.person_id,
2194   			                 p_date_effective		=> l_hist_rec.effective_date-1,
2195   			                 p_result_code		=> l_return_status);
2196 				if (l_return_status is not null) then
2197 			            -- there were no prevalues for this record
2198 		                     hr_utility.set_location('no pre-values'|| l_proc,15);
2199  			             l_pre_record 	:= FALSE;
2200 		                else
2201 				     null;
2202 				end if;
2203 			    end if;
2204 			    --6850492
2205 
2206 			      hr_utility.set_location('Record was created'|| l_proc,30);
2207   				-- Call Delete_element_entry;
2208   				-- delete all entry values from history;
2209 				-- VSM Changes made for BUG # 611161
2210 				-- To be able to delete this entry we have to pass previous record and
2211 				-- ask to delete next change.
2212 				-- If there is no pre-record then Call IF_ZAP_ELE_ENT to find if we need to zap
2213 				-- the entry.
2214 				l_result := FALSE;
2215 				l_del_mode := hr_api.g_delete_next_change;
2216 				if l_return_status is not null then
2217 					hr_utility.set_location(' Call IF_ZAP_ELE_ENT' || l_proc, 31);
2218                                    If l_session_var.noa_id_correct is not null and l_sf52_data.first_noa_code = '866' then
2219 			        		IF_ZAP_ELE_ENT(
2220 							p_element_entry_id	=> l_hist_rec.information1,
2221 							p_effective_start_date	=> l_hist_rec.effective_date + 1,
2222 							p_pa_history_id		=> l_hist_rec.pa_history_id,
2223 							p_result			=> l_result);
2224 						if l_result then
2225 						-- ie can zap the element;
2226 
2227 							hr_utility.set_location(' ZAP Mode set ' || l_proc, 32);
2228 							l_del_mode := hr_api.g_zap;
2229 							-- As there is no pre record. copy current row in pre record
2230 							l_hist_pre	:= l_hist_rec;
2231                                         	end if;
2232                                      	Else
2233 			        		IF_ZAP_ELE_ENT(
2234 							p_element_entry_id	=> l_hist_rec.information1,
2235 							p_effective_start_date	=> l_hist_rec.effective_date,
2236 							p_pa_history_id		=> l_hist_rec.pa_history_id,
2237 							p_result			=> l_result);
2238 						if l_result then
2239 						-- ie can zap the element;
2240 
2241 							hr_utility.set_location(' ZAP Mode set ' || l_proc, 32);
2242 							l_del_mode := hr_api.g_zap;
2243 							-- As there is no pre record. copy current row in pre record
2244 							l_hist_pre	:= l_hist_rec;
2245                                         	end if;
2246 			              End if;
2247 				end if;
2248 
2249 				if l_return_status is null or l_result then
2250 					-- ie previous row exists or this is the only row.
2251 	  				delete_element_entry( p_hist_rec 		=> l_hist_pre,
2252 								    p_del_mode          => l_del_mode,
2253   								    p_cannot_cancel 	=> l_cannot_cancel);
2254   					if l_cannot_cancel then
2255   						-- raise error
2256 					      hr_utility.set_location('ERROR: Cannot Cancel'|| l_proc,35);
2257   		     				hr_utility.set_message(8301,'GHR_38212_CANNOT_CANCEL');
2258 					      hr_utility.raise_error;
2259   					else
2260 					      hr_utility.set_location('Delete rows.'|| l_proc,40);
2261   						delete_hist_row ( l_hist_rec.pa_history_id);
2262   						delete_eleentval( l_hist_rec);
2263 	  				end if;
2264 				else
2265                                         --Bug#2521744 Added the following code
2266 					for  element_name_rec in c_element_name(l_hist_rec.information7)
2267 					loop
2268 						l_element_name := element_name_rec.element_name;
2269 						exit;
2270 					end loop;
2271 					hr_utility.set_location('element_name '||l_element_name,10);
2272 				        delete_other_pay_entries(p_hist_rec => l_hist_rec,
2273 				                             p_element_name => l_element_name);
2274 					--Bug#2521744 testing
2275 				end if;
2276   			else
2277 			      hr_utility.set_location('Record was not created.'|| l_proc,45);
2278   				null;
2279   			end if;
2280 			-- Delete history record
2281   			delete_hist_row ( l_hist_rec.pa_history_id);
2282 
2283 
2284   		-- PAY_ELEMENT_ENTRY_VALUE needs to be handled differently
2285 		elsif lower(l_hist_rec.table_name) = lower (ghr_history_api.g_eleevl_table) then
2286 		      hr_utility.set_location('Processing element entry value record'|| l_proc,47);
2287 			if l_hist_rec.DML_operation = ghr_history_api.g_upd_operation then
2288 			      hr_utility.set_location('Record was updated' || l_proc,48);
2289 			      if (l_pre_record = FALSE) then
2290                                     -- Bug#2521744 Added if condition
2291 				     for  element_name_rec1 in c_element_name1(l_hist_rec.information5)
2292 				     loop
2293 					    l_element_name1 := element_name_rec1.element_name;
2294 					    exit;
2295 				     end loop;
2296 				     fnd_profile.get('PER_BUSINESS_GROUP_ID',l_bus_group_id);
2297                                      l_element_name1 := pqp_fedhr_uspay_int_utils.return_old_element_name
2298                                                         (l_element_name1,l_bus_group_id,l_hist_rec.effective_date);
2299 
2300 					 hr_utility.set_location('element_name '||l_element_name1,10);
2301  				     IF l_element_name1 IN ('Retention Allowance','Supervisory Differential',
2302                                                               'AUO','Availability Pay','Other Pay') then
2303 					hr_utility.set_location('Inside Oth pay elt val condition',15);
2304 				        NULL;
2305 				     Else
2306 					 -- raise error. Must have a pre in order to cancel.
2307 					 hr_utility.set_location('ERROR: Cannot Cancel'|| l_proc,35);
2308 					 hr_utility.set_message(8301,'GHR_38212_CANNOT_CANCEL');
2309 					 hr_utility.raise_error;
2310 				   End IF;
2311 				     -- End of Bug#2521744
2312 				else
2313 					-- get date_effective row from table. See if it is different than the value of the
2314 					-- action we are cancelling. If it is different, then there are intervening actions on
2315 					-- the same date and the update should not be applied to pay_element_entry_values_f table.
2316 					-- If it is the same, then there are no intervening actions on the same date and the
2317 					-- update should be applied.
2318 					ghr_history_fetch.get_date_eff_eleevl(p_element_entry_value_id	=> l_hist_pre.information1,
2319 											  p_date_effective		=> l_hist_rec.effective_date,
2320 											  p_element_entry_data		=> l_date_eff_rec,
2321 											  p_result_code			=> l_result_code,
2322 											  p_pa_history_id			=> l_pa_history_id);
2323 					if l_result_code is not null then
2324 						-- this should never be the case
2325 						-- raise error.
2326 						hr_utility.set_location( l_proc, 50);
2327 			     			hr_utility.set_message(8301,'GHR_38361_ELEMENT_ROW_NFND');
2328 					      hr_utility.raise_error;
2329 					end if;
2330 					hr_utility.set_location( 'l_hist_rec.pa_history_id: ' || l_hist_rec.pa_history_id || l_proc, 1150);
2331 					hr_utility.set_location( 'l_pa_history_id: ' || l_pa_history_id || l_proc, 1250);
2332 					if (l_hist_rec.pa_history_id = l_pa_history_id) then
2333 
2334 						-- update element_entry_value here.
2335 						-- update application table with pre-values
2336 						update_eleentval	(p_hist_pre		=>	l_hist_pre);
2337 					end if;
2338 				end if;
2339 			end if;
2340 			-- Delete history record
2341   			delete_hist_row ( l_hist_rec.pa_history_id);
2342   		else
2343 		      hr_utility.set_location('Processing non element entry table'|| l_proc,50);
2344   			-- cascade changes thru history table
2345   			ghr_history_cascade.cascade_history_data (
2346   				p_table_name		=> 	l_hist_rec.table_name,
2347   				p_person_id			=>	l_hist_rec.person_id,
2348   				p_pre_record		=>	l_hist_pre,
2349   				p_post_record		=>	l_hist_rec,
2350   				p_cascade_type		=>	'cancel',
2351   				p_interv_on_table 	=>	l_interv_on_table,
2352   				p_interv_on_eff_date	=>	l_interv_on_eff_date,
2353   				p_hist_data_as_of_date	=>	l_hist_data_as_of_date);
2354 
2355 			-- Determine if this record was created or updated.
2356 			if l_datetrack_table then
2357                                   hr_utility.set_location('In Cancel - Date track table' ,1);
2358 				if l_hist_rec.DML_operation = ghr_history_api.g_ins_operation then
2359                                   hr_utility.set_location('in Cancel - DML - Ins' ,1);
2360 					l_rec_created_flag := TRUE;
2361 
2362 				-- if this sf50 updated the row, then the pre must have the same date.
2363 				-- The triggers work such that we will only have update from sf50 operation
2364 				-- when the effective_date is the same. If the pre has a different effective
2365 				-- date, then the original row that was created must have been deleted due to
2366 				-- a cancellation. In this case, the current row becomes the row that was created
2367 				-- by the sf52. So, we must set the rec_created_flag to true for this row. Note
2368 				-- this stands true with date tracked tables only as with non-date tracked tables there
2369 				-- is only one row in a record, so this case will never occur.
2370 				elsif l_hist_rec.DML_operation = ghr_history_api.g_upd_operation then
2371                                                hr_utility.set_location('in Cancel - DML - Upd' ,1);
2372 					if l_hist_rec.effective_date <> l_hist_pre.effective_date then
2373 						l_rec_created_flag := TRUE;
2374                                                      hr_utility.set_location('in Cancel - Created' ,1);
2375 					else
2376 						l_rec_created_flag := FALSE;
2377                                                      hr_utility.set_location('in Cancel - Not Created' ,1);
2378 					end if;
2379 				end if;
2380 			else
2381                                                hr_utility.set_location('In Cancel - Not a Date track table' ,1);
2382 				l_rec_created_flag := (l_hist_rec.DML_operation = ghr_history_api.g_ins_operation);
2383 			end if;
2384 
2385    			what_to_do(
2386 				p_datetrack_table		=>	l_datetrack_table,
2387   				p_pre_record_exists 	=>	l_pre_record,
2388   				p_interv_on_table		=>	l_interv_on_table,
2389   				p_interv_on_eff_date	=>	l_interv_on_eff_date,
2390   				p_rec_created_flag	=>	l_rec_created_flag,
2391   				p_can_delete		=>	l_can_delete,
2392   				p_last_row			=>	l_last_row,
2393   				p_cannot_cancel		=>	l_cannot_cancel);
2394 		   If l_interv_on_table then
2395 				hr_utility.set_location('what to do' || '  interv on table',1);
2396 		   else
2397 		 		hr_utility.set_location('what to do ' || 'no interv on table',1);
2398 		   end if;
2399 		   If l_interv_on_eff_date then
2400 				hr_utility.set_location('what to do' || '  interv on eff',1);
2401 		   else
2402 				hr_utility.set_location('what to do ' || 'no interv on eff' ,1);
2403 		   end if;
2404 
2405   			if (l_cannot_cancel = TRUE) then
2406 			      hr_utility.set_location('ERROR: Cannot cancel'|| l_proc,55);
2407   				-- error, cannot cancel
2408   			      hr_utility.set_message(8301,'GHR_38212_CANNOT_CANCEL');
2409 			      hr_utility.raise_error;
2410   			end if;
2411 
2412 			-- use flags to determine datetrack_mode, if needed.
2413 			-- delete row under conditions outlined below.
2414 			l_deleted	:= FALSE;
2415   			l_datetrack_mode := null;
2416   			if (l_can_delete = TRUE) then
2417 			      hr_utility.set_location('CAN delete'|| l_proc,60);
2418   				if (l_datetrack_table = TRUE) then
2419 				      hr_utility.set_location('Datetrack table'|| l_proc,65);
2420   					if (l_pre_record = FALSE and l_last_row = TRUE) then
2421 					      hr_utility.set_location('Only Row'|| l_proc,70);
2422   						l_datetrack_mode := hr_api.g_zap;
2423   					else
2424 					      hr_utility.set_location('Not Only Row'|| l_proc,75);
2425   						l_datetrack_mode	:= hr_api.g_delete_next_change;
2426 
2427   					end if;
2428   				end if;
2429                                 hr_utility.set_location('after what to do Del Mode ' || l_datetrack_mode,1);
2430   				-- only do the delete if this is a datetrack table or if it is the only row of a
2431   				-- non datetrack table. In all other cases, cascade will properly handle it.
2432 
2433   				if (l_datetrack_table = TRUE or (l_last_row = TRUE and l_pre_record = FALSE)) then
2434 					hr_utility.set_location('Deleting Application row'|| l_proc,80);
2435 					l_deleted := TRUE;
2436   					delete_appl_row(	p_table_name	=> 	l_hist_rec.table_name,
2437   								p_table_pk_id	=>	l_hist_rec.information1,
2438   								p_dt_mode		=>	l_datetrack_mode,
2439   								p_date_effective	=>	l_hist_rec.effective_date);
2440                                          hr_utility.set_location('Hist Rec Eff . Date ' || l_hist_rec.effective_date,1);
2441 
2442   				end if;
2443   			end if;
2444 			-- Delete history record
2445   			delete_hist_row ( l_hist_rec.pa_history_id);
2446   			-- cascade changes thru application table, if the application table record was not already deleted above.
2447                         if (l_deleted = FALSE)
2448                                      or (l_datetrack_mode   = hr_api.g_delete_next_change) then
2449                           if (l_deleted = FALSE) then
2450                           hr_utility.set_location('deleted is false : Bef cascade appl_table',1);
2451                           else
2452 
2453                           hr_utility.set_location('delete next change : Bef cascade appl_table',1);
2454                           end if;
2455 			-- Sundar Bug#2872298 Cascade should not occur if records are already deleted and
2456 				-- delete mode in DELETE_NEXT_CHANGE
2457 				IF (l_deleted = TRUE) AND (l_datetrack_mode   = hr_api.g_delete_next_change) --AND (p_sf52_data.second_noa_code = '790')
2458 				THEN
2459 						   NULL;
2460 				ELSE
2461 				  --5900178
2462 				      l_rec_exists := TRUE;
2463    	                              IF l_hist_rec.table_name = 'PER_PERSON_ANALYSES' THEN
2464       	                                 hr_utility.set_location('In per_person_analyses record checking',997);
2465                                 	 OPEN chk_perana_exists(p_person_analysis_id => l_hist_rec.information1);
2466                                  	 FETCH chk_perana_exists into m_perana;
2467                                          IF chk_perana_exists%NOTFOUND THEN
2468                                        	    hr_utility.set_location('In per_person_analyses record checking--notfound',996);
2469                                             l_rec_exists := FALSE;
2470                                          END IF;
2471                                          CLOSE chk_perana_exists;
2472                                       END IF;
2473 
2474                                        IF l_rec_exists THEN
2475 				        --- Bug # 6127620  need to set the FND Session Date before calling extra info
2476                                       /*  If p_sf52_data.second_noa_code = '800' then
2477                                            GHR_HISTORY_API.get_session_date(l_curr_sess_date);
2478                                            ghr_session.set_fnd_session_date(p_sf52_data.effective_date);
2479                                         end if;
2480 					Begin	  */
2481                                         ----Bug #6127620
2482  				     -- BUG # 14002125 added to not to cascade table data during correction
2483 				     --  as it will cascade during base action cancellation.
2484 				     p_avl := 0;
2485 
2486 				     OPEN chk_hist_rec_avl(p_pa_request_id  => l_hist_rec.pa_request_id,
2487                                                            p_pa_history_id  => l_hist_rec.pa_history_id,
2488 							   p_table_name     => l_hist_rec.table_name,
2489 			                                   p_information    =>l_hist_rec.information1);
2490                                      FETCH chk_hist_rec_avl into p_avl;
2491         			     CLOSE chk_hist_rec_avl;
2492 				     IF NVL(p_avl,0) <> 1 THEN
2493 	  				ghr_history_cascade.cascade_appl_table_data (
2494 						p_table_name		=> 	l_hist_rec.table_name,
2495 						p_person_id	        =>	l_hist_rec.person_id,
2496 						p_pre_record		=>	l_hist_pre,
2497 						p_post_record		=>	l_hist_rec,
2498 						p_cascade_type		=>	'cancel',
2499 						p_interv_on_table 	=>	l_interv_on_table,
2500 						p_interv_on_eff_date	=>	l_interv_on_eff_date,
2501 						p_hist_data_as_of_date	=>	l_hist_data_as_of_date);
2502                                      END IF;
2503 
2504 				       -- Bug # 6127620
2505                                        /* Exception
2506                                          when OTHERS then
2507                                                If p_sf52_data.second_noa_code = '800' then
2508                                                   ghr_session.set_fnd_session_date(l_curr_sess_date);
2509 						  raise;
2510 					       else
2511 						  raise;
2512 					       end if;
2513 					End;
2514 					  If p_sf52_data.second_noa_code = '800' then
2515 					     ghr_session.set_fnd_session_date(l_curr_sess_date);
2516 					  end if;   */
2517 					-- Bug # 6127620
2518 				       END IF;
2519 				END IF;
2520 
2521 			end if;
2522   		end if;
2523   	END LOOP;
2524 	hr_utility.set_location('Exited Loop'|| l_proc,85);
2525 
2526 	ghr_agency_update.ghr_agency_upd(
2527 			p_pa_request_rec			=> l_sf52_data,
2528 			p_asg_sf52				=> l_imm_asg_sf52,
2529 			p_asg_non_sf52			=> l_imm_asg_non_sf52,
2530 			p_asg_nte_dates			=> l_imm_asg_nte_dates,
2531 			p_per_sf52              	=> l_imm_per_sf52,
2532 			p_per_group1            	=> l_imm_per_group1,
2533 			p_per_group2            	=> l_imm_per_group2,
2534 			p_per_scd_info          	=> l_imm_per_scd_info,
2535 			p_per_retained_grade    	=> l_imm_per_retained_grade,
2536 			p_per_probations			=> l_imm_per_probations,
2537 			p_per_sep_Retire 	      	=> l_imm_per_sep_retire,
2538 			p_per_security          	=> l_imm_per_security,
2539 			p_per_conversions	      	=> l_imm_per_conversions,
2540 			p_per_uniformed_services	=> l_imm_per_uniformed_services,
2541 			p_pos_oblig                   => l_imm_pos_oblig,
2542 			p_pos_grp2                    => l_imm_pos_grp2,
2543 			p_pos_grp1                    => l_imm_pos_grp1,
2544 			p_pos_valid_grade             => l_imm_pos_valid_grade,
2545 			p_pos_car_prog                => l_imm_pos_car_prog,
2546 			p_loc_info                    => l_imm_loc_info,
2547 			p_wgi                         => l_imm_wgi,
2548 			p_recruitment_bonus	      => l_imm_recruitment_bonus,
2549 			p_relocation_bonus	      => l_imm_relocation_bonus ,
2550 			p_sf52_from_data              => l_imm_sf52_from_data,
2551 			p_personal_info	            => l_imm_personal_info,
2552 			p_gov_awards_type             => l_imm_gov_awards,
2553 			p_perf_appraisal_type         => l_imm_perf_appraisal,
2554 			p_payroll_type                => l_imm_payroll_type,
2555 			p_conduct_perf_type           => l_imm_conduct_performance,
2556 			p_agency_code		      => l_agency_code,
2557 			p_agency_sf52			=> l_imm_agency_sf52,
2558 			p_entitlement                 => l_imm_entitlement,
2559 			p_foreign_lang_prof_pay       => l_imm_foreign_lang_prof_pay,
2560 			p_edp_pay                     => l_imm_edp_pay,
2561 			p_hazard_pay                  => l_imm_hazard_pay,
2562 			p_health_benefits             => l_imm_health_benefits,
2563 			p_danger_pay                  => l_imm_danger_pay,
2564 			p_imminent_danger_pay         => l_imm_imminent_danger_pay,
2565 			p_living_quarters_allow       => l_imm_living_quarters_allow,
2566 			p_post_diff_amt               => l_imm_post_diff_amt,
2567 			p_post_diff_percent           => l_imm_post_diff_percent,
2568 			p_sep_maintenance_allow       => l_imm_sep_maintenance_allow,
2569 			p_supplemental_post_allow     => l_imm_supplemental_post_allow,
2570 			p_temp_lodge_allow            => l_imm_temp_lodge_allow,
2571 			p_premium_pay                 => l_imm_premium_pay,
2572 			p_retirement_annuity          => l_imm_retirement_annuity,
2573 			p_severance_pay               => l_imm_severance_pay,
2574 			p_thrift_saving_plan          => l_imm_thrift_saving_plan,
2575 			p_retention_allow_review      => l_imm_retention_allow_review,
2576 			p_health_ben_pre_tax          => l_imm_health_ben_pre_tax,
2577 			p_per_benefit_info            => l_imm_per_benefit_info,
2578 			p_imm_retirement_info         => l_imm_retirement_info, --Bug# 7131104
2579 			--Begin Bug# 10181661
2580 			p_asg_detail_info	      => l_imm_asg_detail_info,
2581 			p_ipa_detail_ben_cont_info    => l_imm_ipa_benefits_cont
2582 			--End Bug# 10181661
2583 			);
2584 
2585 	-- call post_sf52_cancel to handle notifications, marking pa_requests cancelled, etc.
2586 	ghr_sf52_post_update.post_sf52_cancel(
2587 		p_pa_request_id		=> p_sf52_data.pa_request_id,
2588 		p_effective_date		=> l_session_var.date_effective,
2589 		p_object_version_number	=> p_sf52_data.object_version_number,
2590 		p_from_position_id	=> p_sf52_data.from_position_id,
2591 		p_to_position_id		=> p_sf52_data.to_position_id,
2592 		p_agency_code		=> p_sf52_data.agency_code);
2593 
2594 	hr_utility.set_location( l_proc, 90);
2595 	Undo_Mark_Cancel ( p_sf52_data  => p_sf52_data);
2596 	hr_utility.set_location( 'Leaving ' || l_proc, 100);
2597       End if;
2598  Exception when others then
2599            --
2600            -- Reset IN OUT parameters and set OUT parameters
2601            --
2602            p_sf52_data := l_sf52_data_rec;
2603            raise;
2604 
2605 END Cancel_Other_Family_Sf52 ;
2606 
2607 -- ---------------------------------------------------------------------------
2608 -- |--------------------------< correction_sf52>------------------------------|
2609 -- ---------------------------------------------------------------------------
2610 -- {Start Of Comments}
2611 --
2612 -- Description:
2613 --   	This procedure handles a correction sf52.
2614 --
2615 -- Pre-Requisities:
2616 --   	None.
2617 --
2618 -- In Parameters:
2619 --	p_sf52_data		->		ghr_pa_requests record of the correction sf52.
2620 -- Post Success:
2621 -- 	The correction will have been applied.
2622 --
2623 -- Post Failure:
2624 --   	No failure conditions.
2625 --
2626 -- Developer Implementation Notes:
2627 --	None.
2628 --
2629 -- Access Status:
2630 --   Internal Development Use Only.
2631 --
2632 -- {End Of Comments}
2633 -- ---------------------------------------------------------------------------
2634 
2635 -- This is a sf52 wrapper procedure. It gets the sf52 and the sf52 extra info
2636 -- record and calls db_update procedures.
2637 Procedure correction_sf52( p_sf52_data 	in	ghr_pa_requests%rowtype,
2638 			   p_process_type in	varchar2	default 'CURRENT',
2639                            p_capped_other_pay in number default null  ) is
2640 
2641 	l_sf52_data_result	ghr_pa_requests%rowtype;
2642 	l_sf52                  ghr_pa_requests%rowtype;
2643 	l_root_sf52             ghr_pa_requests%rowtype;
2644 
2645 	l_pa_request_id		number;
2646 	l_today			date	:=sysdate;
2647 	l_session_var		ghr_history_api.g_session_var_type;
2648 	l_sf52_ei_data		ghr_pa_request_extra_info%rowtype;
2649 	l_agency_ei_data		ghr_pa_request_extra_info%rowtype;
2650 	l_sf52_data			ghr_pa_requests%rowtype;
2651 	l_sf52_data1		ghr_pa_requests%rowtype;
2652 	l_shadow_data		ghr_pa_request_shadow%rowtype;
2653 	l_result			varchar2(1000);
2654 
2655 	-- this cursor gets the noa_family_code for noa_id (nature of action ID) passed.
2656 	cursor c_fam (c_noa_id number) is
2657 	select
2658 		fams.noa_family_code
2659 	from  ghr_noa_families noafam,
2660 		ghr_families     fams
2661 	where noafam.nature_of_action_id = c_noa_id               and
2662 		noafam.enabled_flag        = 'Y'                    and
2663 		fams.noa_family_code 	   = noafam.noa_family_code and
2664 		fams.enabled_flag          = 'Y'                    and
2665 		fams.update_hr_flag = 'Y';
2666 
2667 	cursor c_get_root (c_pa_request_id in number) is
2668 	select *
2669 	from ghr_pa_requests
2670 		connect by pa_request_id = prior altered_pa_request_id
2671 		start with pa_request_id = c_pa_request_id
2672 	order by level desc;
2673 
2674 	cursor c_get_hist_id (c_pa_request_id in number) is
2675 	select
2676 		min(pa_history_id)
2677 	from ghr_pa_history
2678 	where pa_request_id = c_pa_request_id;
2679 
2680 	cursor get_shadow (c_pa_request_id in number) is
2681 	select *
2682 	from ghr_pa_request_shadow
2683 	where pa_request_id = c_pa_request_id;
2684 
2685 	l_proc		varchar2(30):='correction_sf52';
2686 	l_people_data	per_all_people_f%rowtype;
2687 
2688 	--6850492
2689 	cursor chk_dual_action(c_pa_request_id in number)
2690 	    is
2691 	    select 'Y'
2692 	    from   ghr_pa_requests
2693 	    where  pa_request_id = (select min(pa_request_id)
2694      	                            from   ghr_pa_requests
2695                	                    where  pa_notification_id is not null
2696 	                            connect by pa_request_id = prior altered_pa_request_id
2697 	                            start with pa_request_id = c_pa_request_id)
2698             and   second_noa_code is not null
2699 	    and   first_noa_code not in ('001','002');
2700 
2701 
2702 	l_dual_flag_yn varchar2(1);
2703 	--6850492
2704 
2705 
2706 
2707 Procedure Refresh_Cascade_Name( p_sf52_rec	in out nocopy 	ghr_pa_requests%rowtype,
2708 					 p_shadow_rec	in out nocopy ghr_pa_request_shadow%rowtype) is
2709 
2710 	l_result_code	varchar2(30);
2711 	l_people_data	per_all_people_f%rowtype;
2712 	l_hist_id		number;
2713 	l_proc		varchar2(40):='Refresh_Cascade_Name';
2714         l_capped_other_pay number := hr_api.g_number;
2715 
2716 	cursor get_hist is
2717 	select pa_history_id
2718 	from ghr_pa_history
2719 	where pa_request_id = p_sf52_rec.altered_pa_request_id and
2720 		nature_of_action_id = p_sf52_rec.second_noa_id;
2721 
2722    l_sf52_rec   ghr_pa_requests%rowtype;
2723    l_shadow_rec ghr_pa_request_shadow%rowtype;
2724 Begin
2725 
2726 	hr_utility.set_location( 'Entering ' || l_proc, 10);
2727    l_sf52_rec    := p_sf52_rec;
2728    l_shadow_rec  := p_shadow_rec;
2729 
2730 	open get_hist;
2731 	fetch get_hist into l_hist_id;
2732 	close get_hist;
2733 	hr_utility.set_location( 'Fetched Hist id' || l_proc, 15);
2734 
2735 	ghr_history_fetch.fetch_people(
2736 		p_person_id				=> p_sf52_data.person_id,
2737 		p_date_effective			=> p_sf52_data.effective_date,
2738 		p_pa_history_id			=> l_hist_id,
2739 		p_altered_pa_request_id		=> p_sf52_data.altered_pa_request_id,
2740 		p_noa_id_corrected		=> p_sf52_data.second_noa_id,
2741 		p_people_data			=> l_people_data,
2742 		p_result_code			=> l_result_code
2743 	);
2744 
2745 	if l_result_code is NULL then
2746 		hr_utility.set_location( 'People Data Found' || l_proc, 20);
2747 
2748 		if nvl(p_sf52_rec.employee_first_name, hr_api.g_varchar2)  = nvl(p_shadow_rec.employee_first_name , hr_api.g_varchar2) and
2749 		   nvl(p_sf52_rec.employee_last_name , hr_api.g_varchar2)  = nvl(p_shadow_rec.employee_last_name  , hr_api.g_varchar2) and
2750 		   nvl(p_sf52_rec.employee_middle_names,hr_api.g_varchar2) = nvl(p_shadow_rec.employee_middle_names, hr_api.g_varchar2)    then
2751 
2752 			hr_utility.set_location( 'Refresh Name ' || l_proc, 30);
2753 			p_sf52_rec.employee_first_name	:=	l_people_data.first_name;
2754 			p_sf52_rec.employee_last_name		:=	l_people_data.last_name;
2755 			p_sf52_rec.employee_middle_names	:=	l_people_data.middle_names;
2756 
2757 			p_shadow_rec.employee_first_name	:=	l_people_data.first_name;
2758 			p_shadow_rec.employee_last_name	:=	l_people_data.last_name;
2759 			p_shadow_rec.employee_middle_names	:=	l_people_data.middle_names;
2760 		end if;
2761 
2762 		hr_utility.set_location( 'Check SSN ' || l_proc, 35);
2763 		if nvl(p_sf52_rec.employee_national_identifier, hr_api.g_varchar2) = nvl(p_shadow_rec.employee_national_identifier, hr_api.g_varchar2) then
2764 			hr_utility.set_location( 'Refresh SSN ' || l_proc, 40);
2765 			p_sf52_rec.employee_national_identifier   := l_people_data.national_identifier;
2766 			hr_utility.set_location( 'Refresh SSN ' || l_proc, 41);
2767 			p_shadow_rec.employee_national_identifier := l_people_data.national_identifier;
2768 		end if;
2769 
2770 		hr_utility.set_location( 'check DOB ' || l_proc, 45);
2771 		if nvl(p_sf52_rec.employee_date_of_birth, hr_api.g_date) = nvl(p_shadow_rec.employee_date_of_birth, hr_api.g_date) then
2772 			hr_utility.set_location( 'Refresh DOB ' || l_proc, 50);
2773 			p_sf52_rec.employee_date_of_birth   := l_people_data.date_of_birth;
2774 			hr_utility.set_location( 'Refresh DOB ' || l_proc, 51);
2775 			p_shadow_rec.employee_date_of_birth := l_people_data.date_of_birth;
2776 		end if;
2777 
2778 	end if;
2779 	hr_utility.set_location( 'Leaving ' || l_proc, 100);
2780  Exception when others then
2781       --
2782       -- Reset IN OUT parameters and set OUT parameters
2783       --
2784       p_sf52_rec    := l_sf52_rec;
2785       p_shadow_rec  := l_shadow_rec;
2786       raise;
2787 
2788 End;
2789 
2790 begin
2791 
2792 	hr_utility.set_location('Entering:'|| l_proc, 5);
2793 	-- reinitialise session variables
2794 	ghr_history_api.reinit_g_session_var;
2795 
2796 	-- set values of session variables
2797 	l_session_var.pa_request_id 	:= p_sf52_data.pa_request_id;
2798 	l_session_var.noa_id		:= p_sf52_data.second_noa_id;
2799 	l_session_var.fire_trigger	:= 'Y';
2800 	l_session_var.date_Effective	:= p_sf52_data.effective_date;
2801 	l_session_var.person_id		:= p_sf52_data.person_id;
2802 	l_session_var.program_name	:= 'sf50';
2803 	l_session_var.altered_pa_request_id	:= p_sf52_data.altered_pa_request_id;
2804 	l_session_var.noa_id_correct	:= p_sf52_data.second_noa_id;
2805 	l_session_var.assignment_id	:= p_sf52_data.employee_assignment_id;
2806 	ghr_history_api.set_g_session_var(l_session_var);
2807 
2808 
2809 -- .47
2810 
2811 	-- Refresh Correction and shadow for Employee Name
2812 	open get_shadow( p_sf52_data.pa_request_id);
2813 	fetch get_shadow into l_shadow_data;
2814 	close get_shadow;
2815 
2816 	l_sf52_data := p_sf52_data;
2817       IF (l_sf52_data.second_noa_code <> '780') then
2818 	Refresh_Cascade_Name( p_sf52_rec	=> l_sf52_data,
2819 				    p_shadow_rec	=> l_shadow_data);
2820 
2821 	ghr_process_sf52.update_rfrs_values(p_sf52_data		=>	l_sf52_data,
2822 							p_shadow_data	=>	l_shadow_data);
2823       END IF;
2824 
2825 	l_sf52_data1 := l_sf52_data;
2826 -- .47
2827 
2828 /* .47
2829 	-- get root sf52 for this correction
2830 	hr_utility.set_location(l_proc, 102);
2831 	open c_get_root (p_sf52_data.altered_pa_request_id);
2832 	fetch c_get_root into l_root_sf52;
2833 	if c_get_root%notfound then
2834 		hr_utility.set_location(l_proc, 103);
2835 		close c_get_root ;
2836 	      hr_utility.set_message(8301,'GHR_38493_ROOT_SF52_NFND');
2837 	      hr_utility.raise_error;
2838 	else
2839 		close c_get_root ;
2840 	end if;
2841 
2842 
2843 	-- refresh root sf52 and its correction
2844 	-- get pa_history_id for the root pa_request_id
2845 	open c_get_hist_id( l_root_sf52.pa_request_id);
2846 	fetch c_get_hist_id into l_session_var.pa_history_id;
2847 	if c_get_hist_id%notfound then
2848 		-- raise error;
2849 		close c_get_hist_id;
2850 	else
2851 		close c_get_hist_id;
2852 	end if;
2853 	-- We are setting pa_history_id in session var to be able to fetch
2854 	-- Pre-record values of the root SF52 for refresh purpose.
2855 	-- It'll be reset after refresh has been done
2856 
2857 	ghr_history_api.set_g_session_var(l_session_var);
2858 	ghr_process_sf52.refresh_req_shadow(p_sf52_data		=>	l_root_sf52,
2859 							p_shadow_data	=>	l_shadow_data);
2860 	ghr_process_sf52.redo_pay_calc(	p_sf52_rec		=>	l_root_sf52);
2861 	ghr_process_sf52.update_rfrs_values(p_sf52_data		=>	l_root_sf52,
2862 							p_shadow_data	=>	l_shadow_data);
2863 
2864 	-- reset pa_history_id in session variable.
2865 	l_session_var.pa_history_id := null;
2866 	ghr_history_api.set_g_session_var(l_session_var);
2867 
2868 -- .47
2869 */
2870 
2871 
2872 	-- fetch the noa_family_code for the original noa in the correction chain; second_noa_id contains the
2873 	-- noa_id of the original noa in the chain).
2874 	open c_fam(l_sf52_data.second_noa_id);
2875 	fetch c_fam into l_sf52_data.noa_family_code;
2876 	if c_fam%NOTFOUND then
2877 		close c_fam;
2878 	      hr_utility.set_message(8301,'GHR_38211_NOA_FAMILY_NOTFOUND');
2879 	      hr_utility.raise_error;
2880 	end if;
2881 	close c_fam;
2882 
2883 
2884 	-- build up the sf52_data record by calling apply_noa_corrections.
2885 	-- when this completes, l_sf52_data_result will contain the data of the original
2886 	-- sf52, with all corrections in the correction chain applied onto it.
2887 	-- apply_noa_corrections ensures that name/dob/ssn are retained from the last correction ie the one being processed.
2888 	hr_utility.set_location('from_step_or_rate right before apply_noa_corrections: '|| l_sf52_data.from_step_or_rate || l_proc, 915);
2889         ghr_process_sf52.print_sf52(' l_sf52_data before apply_noa ',l_sf52_data);
2890         ghr_process_sf52.print_sf52(' l_sf52_data_result before apply_noa ',l_sf52_data_result);
2891 	-- Bug # 6850492 added the following if condition to call seperate correction
2892 	-- procedure for dual actions.
2893 	hr_utility.set_location('l_root_sf52.second_noa_code'||l_root_sf52.second_noa_code,100);
2894 	hr_utility.set_location('l_root_sf52.first_noa_code'||l_root_sf52.first_noa_code,100);
2895         hr_utility.set_location('l_sf52_data.mass_action_id'||l_sf52_data.mass_action_id,100);
2896         hr_utility.set_location('l_sf52_data.rpa_type'||l_sf52_data.rpa_type,100);
2897 	l_dual_flag_yn :='N';
2898 	open chk_dual_action(l_sf52_data.pa_request_id);
2899 	fetch  chk_dual_action into l_dual_flag_yn;
2900 	close chk_dual_action;
2901 	if NVL(l_dual_flag_yn,'N') = 'Y' and  l_sf52_data.mass_action_id is not null and
2902 	  l_sf52_data.rpa_type = 'DUAL' then
2903 	    hr_utility.set_location('Calling dual noa_corrections',1000);
2904 	    apply_dual_noa_corrections(l_sf52_data, l_sf52_data_result);
2905 	else
2906 	    apply_noa_corrections( 	l_sf52_data, l_sf52_data_result );
2907 	end if;
2908         ghr_process_sf52.print_sf52(' l_sf52_data after apply_noa ',l_sf52_data);
2909         ghr_process_sf52.print_sf52(' l_sf52_data_result after apply_noa ',l_sf52_data_result);
2910 
2911 	ghr_process_Sf52.Fetch_extra_info(
2912 			p_pa_request_id 	=> l_sf52_data.pa_request_id,
2913 			p_noa_id   		=> l_sf52_data.second_noa_id,
2914 			p_sf52_ei_data 	=> l_sf52_ei_data,
2915 			p_result		=> l_result);
2916 
2917 	ghr_process_Sf52.Fetch_extra_info(
2918 			p_pa_request_id 	=> l_sf52_data.pa_request_id,
2919 			p_noa_id   		=> l_sf52_data.second_noa_id,
2920 			p_agency_ei		=> TRUE,
2921 			p_sf52_ei_data 	=> l_agency_ei_data,
2922 			p_result		=> l_result);
2923 
2924 	-- check for future action
2925 	hr_utility.set_location('national_identifier right before update sf52: '|| l_sf52_data_result.employee_national_identifier || l_proc, 915);
2926 	hr_utility.set_location('from_step_or_rate right before update sf52: '|| l_sf52_data_result.from_step_or_rate || l_proc, 915);
2927 	hr_utility.set_location('to_step_or_rate right before update sf52: '|| l_sf52_data_result.to_step_or_rate || l_proc, 915);
2928 
2929 	ghr_history_api.display_g_session_var;
2930       -- Check if atleast the min. required items exist in the pa_request
2931       ghr_sf52_validn_pkg.prelim_req_chk_for_update_hr(p_pa_request_rec       =>  l_sf52_data_result);
2932 	if (l_session_var.date_Effective > l_today) then
2933 		-- issue savepoint
2934 		savepoint single_Action_sf52;
2935 
2936 		ghr_sf52_update.main( 	p_pa_request_rec    	=> 	l_sf52_data_result,
2937 						p_pa_request_ei_rec 	=>	l_sf52_ei_data,
2938 						p_generic_ei_rec		=> 	l_agency_ei_data,
2939                                                 p_capped_other_pay => p_capped_other_pay);
2940 		-- rollback to savepoint
2941 		rollback  to single_action_sf52;
2942 	else
2943                --RP
2944 		ghr_sf52_update.main( 	p_pa_request_rec    	=> 	l_sf52_data_result,
2945 						p_pa_request_ei_rec 	=>	l_sf52_ei_data,
2946 						p_generic_ei_rec		=> 	l_agency_ei_data,
2947                                                 p_capped_other_pay => p_capped_other_pay);
2948 	hr_utility.set_location('to_position_id right before update sf52: '|| l_sf52_data_result.to_position_id || l_proc, 915);
2949      hr_utility.set_location('After main update :'|| l_proc, 20);
2950                 ghr_sf52_post_update.Post_sf52_process(
2951                         p_pa_request_id         => p_sf52_data.pa_request_id,
2952                         p_effective_date                => l_session_var.date_effective,
2953                         p_object_version_number => l_sf52_data1.object_version_number,
2954                         p_from_position_id      => l_sf52_data_result.from_position_id,
2955                         p_to_position_id                => l_sf52_data_result.to_position_id,
2956                         p_agency_code           => l_sf52_data_result.agency_code,
2957                         p_sf52_data_result      => l_sf52_data_result,
2958                         p_called_from           => 'CORRECTION_SF52'
2959                 );
2960 
2961        end if;
2962 		hr_utility.set_location(' Leaving:'||l_proc, 10);
2963 end correction_sf52;
2964 
2965 -- ---------------------------------------------------------------------------
2966 -- |--------------------------< delete_hist_row>------------------------------|
2967 -- ---------------------------------------------------------------------------
2968 -- {Start Of Comments}
2969 --
2970 -- Description:
2971 --   	This procedure deletes a row in ghr_pa_history for the rowid passed.
2972 --
2973 -- Pre-Requisities:
2974 --   	None.
2975 --
2976 -- In Parameters:
2977 --	p_row_id		->		rowid of the row to be deleted in
2978 --						ghr_pa_history.
2979 -- Post Success:
2980 -- 	The row will have been deleted.
2981 --
2982 -- Post Failure:
2983 --   	No failure conditions.
2984 --
2985 -- Developer Implementation Notes:
2986 --	None.
2987 --
2988 -- Access Status:
2989 --   Internal Development Use Only.
2990 --
2991 -- {End Of Comments}
2992 -- ---------------------------------------------------------------------------
2993 
2994 Procedure delete_hist_row ( p_row_id 	in	rowid) is
2995 	l_proc	varchar2(30):='delete_hist_row';
2996 Begin
2997 	hr_utility.set_location( 'Entering : ' || l_proc, 10);
2998 	delete ghr_pa_history
2999 		where rowid = p_row_id;
3000 	hr_utility.set_location( 'Leaving : ' || l_proc, 20);
3001 End delete_hist_row;
3002 
3003 -- ---------------------------------------------------------------------------
3004 -- |--------------------------< delete_hist_row>------------------------------|
3005 -- ---------------------------------------------------------------------------
3006 -- {Start Of Comments}
3007 --
3008 -- Description:
3009 --   	This procedure deletes a row in ghr_pa_history for the pa_history_id passed.
3010 --
3011 -- Pre-Requisities:
3012 --   	None.
3013 --
3014 -- In Parameters:
3015 --	p_pa_history_id		->		pa_history_id
3016 --							of the row to be deleted in ghr_pa_history.
3017 -- Post Success:
3018 -- 	The row will have been deleted.
3019 --
3020 -- Post Failure:
3021 --   	No failure conditions.
3022 --
3023 -- Developer Implementation Notes:
3024 --	None.
3025 --
3026 -- Access Status:
3027 --   Internal Development Use Only.
3028 --
3029 -- {End Of Comments}
3030 -- ---------------------------------------------------------------------------
3031 
3032 Procedure delete_hist_row ( p_pa_history_id 	in	ghr_pa_history.pa_history_id%type) is
3033 	l_proc	varchar2(30):='delete_hist_row';
3034 Begin
3035 	hr_utility.set_location( 'Entering : ' || l_proc, 30);
3036 	delete ghr_pa_history
3037 		where pa_history_id = p_pa_history_id;
3038 	hr_utility.set_location( 'Leaving : ' || l_proc, 40);
3039 End delete_hist_row;
3040 
3041 -- ---------------------------------------------------------------------------
3042 -- |--------------------------< apply_correction>-----------------------------|
3043 -- ---------------------------------------------------------------------------
3044 -- {Start Of Comments}
3045 --
3046 -- Description:
3047 --   	This procedure applies a correction by copying the fields from the
3048 --	p_sf52rec_correct record to p_sf52rec record and puts the result in
3049 --	sf52rec_result.
3050 --
3051 -- Pre-Requisities:
3052 --   	None.
3053 --
3054 -- In Parameters:
3055 --	p_sf52_rec_correct		->		the ghr_pa_requests record that we are
3056 --								copying from.
3057 --	p_corr_pa_request_id		->		the pa_request_id of the correction
3058 --								that is currently being processed.
3059 --	p_sf52rec				->		results of the applied correction are put
3060 --								here.
3061 -- Post Success:
3062 -- 	The correction will have been applied and the result put in p_sf52rec.
3063 --
3064 -- Post Failure:
3065 --   	No failure conditions.
3066 --
3067 -- Developer Implementation Notes:
3068 --	Note that a lot of thought went into determining which fields should be copied and
3069 --	which fields should not be copied. (Need to re-visit this comment to put in details of
3070 --	why certain fields were included and others not included).
3071 --
3072 -- Access Status:
3073 --   Internal Development Use Only.
3074 --
3075 -- {End Of Comments}
3076 -- ---------------------------------------------------------------------------
3077 
3078 -- This procedure copies the fields from the p_sf52rec_correct record to
3079 -- p_sf52rec record and puts te result in sf52rec_result.
3080 PROCEDURE apply_correction (
3081    		p_sf52rec_correct  	in 		ghr_pa_requests%rowtype,
3082 		p_corr_pa_request_id	in		ghr_pa_requests.pa_request_id%type,
3083  		p_sf52rec   		in out nocopy 	ghr_pa_requests%rowtype ) is
3084 
3085 	l_proc	varchar2(30):='apply_correction';
3086     l_sf52rec ghr_pa_requests%rowtype;
3087 
3088     -- Begin Bug# 5014663
3089     l_asg_ei_data  		per_assignment_extra_info%rowtype;
3090     l_award_salary		number;
3091     l_temp_award_amount	number;
3092     -- End Bug# 5014663
3093 
3094 
3095 BEGIN
3096 	hr_utility.set_location('Entering:'|| l_proc, 5);
3097    l_sf52rec := p_sf52rec;
3098 	hr_utility.set_location('pre par: rec_correct pa_request id=' || p_sf52rec_correct.pa_request_id,6);
3099 	hr_utility.set_location('pre par: rec pa_request id=' || p_sf52rec.pa_request_id,7);
3100 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.pa_request_id                   , p_sf52rec.pa_request_id                    );
3101 	hr_utility.set_location('post par: rec_correct pa_request id=' || p_sf52rec_correct.pa_request_id,6);
3102 	hr_utility.set_location('post par: rec pa_request id=' || p_sf52rec.pa_request_id,7);
3103 -- the following two fields are not filled in because they are derived.
3104 --	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.pa_notification_id              , p_sf52rec.pa_notification_id               );
3105 --	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.noa_family_code                 , p_sf52rec.noa_family_code                  );
3106 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.academic_discipline             , p_sf52rec.academic_discipline              );
3107 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.agency_code                     , p_sf52rec.agency_code                      );
3108 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.altered_pa_request_id           , p_sf52rec.altered_pa_request_id            );
3109 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.annuitant_indicator             , p_sf52rec.annuitant_indicator              );
3110 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.annuitant_indicator_desc        , p_sf52rec.annuitant_indicator_desc         );
3111 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.appropriation_code1             , p_sf52rec.appropriation_code1              );
3112 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.appropriation_code2             , p_sf52rec.appropriation_code2              );
3113 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.approval_date                   , p_sf52rec.approval_date                    );
3114 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.approving_official_work_title   , p_sf52rec.approving_official_work_title    );
3115 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.award_uom                       , p_sf52rec.award_uom                        );
3116 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.bargaining_unit_status          , p_sf52rec.bargaining_unit_status           );
3117 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.citizenship                     , p_sf52rec.citizenship                      );
3118 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.duty_station_code               , p_sf52rec.duty_station_code                );
3119 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.duty_station_desc               , p_sf52rec.duty_station_desc                );
3120 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.duty_station_id                 , p_sf52rec.duty_station_id                  );
3121 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.duty_station_location_id        , p_sf52rec.duty_station_location_id         );
3122 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.education_level                 , p_sf52rec.education_level                  );
3123 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.effective_date                  , p_sf52rec.effective_date                   );
3124 	hr_utility.set_location('pre: rec_correct assignment id=' || p_sf52rec_correct.employee_assignment_id,6);
3125 	hr_utility.set_location('pre: rec assignment id=' || p_sf52rec.employee_assignment_id,7);
3126 	hr_utility.set_location('pre: rec_correct pa_request id=' || p_sf52rec_correct.pa_request_id,6);
3127 	hr_utility.set_location('pre: rec pa_request id=' || p_sf52rec.pa_request_id,7);
3128 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.employee_assignment_id          , p_sf52rec.employee_assignment_id           );
3129 	hr_utility.set_location('post: rec_correct assignment id=' || p_sf52rec_correct.employee_assignment_id,8);
3130 	hr_utility.set_location('post: rec assignment id=' || p_sf52rec.employee_assignment_id,9);
3131 	hr_utility.set_location('post: rec_correct pa_request id=' || p_sf52rec_correct.pa_request_id,6);
3132 	hr_utility.set_location('post: rec pa_request id=' || p_sf52rec.pa_request_id,7);
3133 	hr_utility.set_location('post: national_identifier=' || p_sf52rec.employee_national_identifier,7);
3134     	hr_utility.set_location('post: reccorrect national_identifier =' || p_sf52rec_correct.employee_national_identifier,7);
3135 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.employee_date_of_birth          , p_sf52rec.employee_date_of_birth           );
3136 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.employee_dept_or_agency         , p_sf52rec.employee_dept_or_agency          );
3137 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.employee_first_name             , p_sf52rec.employee_first_name              );
3138 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.employee_last_name              , p_sf52rec.employee_last_name               );
3139 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.employee_middle_names           , p_sf52rec.employee_middle_names            );
3140 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.employee_national_identifier    , p_sf52rec.employee_national_identifier     );
3141 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.fegli                           , p_sf52rec.fegli                            );
3142 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.fegli_desc                      , p_sf52rec.fegli_desc                       );
3143 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_action_la_code1           , p_sf52rec.first_action_la_code1            );
3144 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_action_la_code2           , p_sf52rec.first_action_la_code2            );
3145 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_action_la_desc1           , p_sf52rec.first_action_la_desc1            );
3146 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_action_la_desc2           , p_sf52rec.first_action_la_desc2            );
3147 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_noa_cancel_or_correct     , p_sf52rec.first_noa_cancel_or_correct      );
3148 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_noa_code                  , p_sf52rec.first_noa_code                   );
3149 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_noa_desc                  , p_sf52rec.first_noa_desc                   );
3150 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_noa_id                    , p_sf52rec.first_noa_id                     );
3151 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_noa_pa_request_id         , p_sf52rec.first_noa_pa_request_id          );
3152 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.flsa_category                   , p_sf52rec.flsa_category                    );
3153 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.forwarding_address_line1        , p_sf52rec.forwarding_address_line1         );
3154 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.forwarding_address_line2        , p_sf52rec.forwarding_address_line2         );
3155 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.forwarding_address_line3        , p_sf52rec.forwarding_address_line3         );
3156 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.forwarding_country              , p_sf52rec.forwarding_country               );
3157 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.forwarding_postal_code          , p_sf52rec.forwarding_postal_code           );
3158 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.forwarding_region_2             , p_sf52rec.forwarding_region_2              );
3159 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.forwarding_town_or_city         , p_sf52rec.forwarding_town_or_city          );
3160 
3161 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_adj_basic_pay              , p_sf52rec.from_adj_basic_pay               );
3162 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_position_org_line1         , p_sf52rec.from_position_org_line1          );
3163 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_agency_code                , p_sf52rec.from_agency_code                 );
3164 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_agency_desc                , p_sf52rec.from_agency_desc                 );
3165 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_basic_pay                  , p_sf52rec.from_basic_pay                   );
3166 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_grade_or_level             , p_sf52rec.from_grade_or_level              );
3167 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_locality_adj               , p_sf52rec.from_locality_adj                );
3168 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_occ_code                   , p_sf52rec.from_occ_code                    );
3169 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_office_symbol              , p_sf52rec.from_office_symbol               );
3170 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_other_pay_amount           , p_sf52rec.from_other_pay_amount            );
3171 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_pay_basis                  , p_sf52rec.from_pay_basis                   );
3172       hr_utility.set_location('correct ' || p_sf52rec_correct.from_pay_plan,1);
3173       hr_utility.set_location('sf52rec ' || p_sf52rec.from_pay_plan,1);
3174 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_pay_plan                   , p_sf52rec.from_pay_plan                    );
3175 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_position_id                , p_sf52rec.from_position_id                 );
3176 -- this is informational only and is not needed
3177 -- ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_position_name              , p_sf52rec.from_position_name               );
3178 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_position_number            , p_sf52rec.from_position_number             );
3179 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_position_seq_no            , p_sf52rec.from_position_seq_no             );
3180 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_position_title             , p_sf52rec.from_position_title              );
3181 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_step_or_rate               , p_sf52rec.from_step_or_rate                );
3182 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.from_total_salary               , p_sf52rec.from_total_salary                );
3183 
3184 
3185 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.functional_class                , p_sf52rec.functional_class                 );
3186     -- Bug#4694896
3187     ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.input_pay_rate_determinant      , p_sf52rec.input_pay_rate_determinant       );
3188     ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.pay_rate_determinant            , p_sf52rec.pay_rate_determinant             );
3189 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.personnel_office_id             , p_sf52rec.personnel_office_id              );
3190 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.person_id                       , p_sf52rec.person_id                        );
3191 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.position_occupied               , p_sf52rec.position_occupied                );
3192 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.resign_and_retire_reason_desc   , p_sf52rec.resign_and_retire_reason_desc    );
3193 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.retirement_plan                 , p_sf52rec.retirement_plan                  );
3194 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.retirement_plan_desc            , p_sf52rec.retirement_plan_desc             );
3195 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.service_comp_date               , p_sf52rec.service_comp_date                );
3196 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.supervisory_status              , p_sf52rec.supervisory_status               );
3197 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.tenure                          , p_sf52rec.tenure                           );
3198 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_grade_id                     , p_sf52rec.to_grade_id                      );
3199 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_office_symbol                , p_sf52rec.to_office_symbol                 );
3200 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_job_id   		          , p_sf52rec.to_job_id	                   );
3201 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_occ_code  	                , p_sf52rec.to_occ_code                 	 );
3202 
3203 	--Bug # 12647449
3204         ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_pay_table_identifier, p_sf52rec.to_pay_table_identifier);
3205 
3206 -- this is informational only and is not needed
3207 	-- ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_position_name                , p_sf52rec.to_position_name                 );
3208 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_step_or_rate                 , p_sf52rec.to_step_or_rate                  );
3209 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_total_salary                 , p_sf52rec.to_total_salary                  );
3210 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_other_pay_amount             , p_sf52rec.to_other_pay_amount	 );
3211 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_availability_pay             , p_sf52rec.to_availability_pay	 );
3212 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_ap_premium_pay_indicator     , p_sf52rec.to_ap_premium_pay_indicator );
3213 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_auo_premium_pay_indicator    , p_sf52rec.to_auo_premium_pay_indicator );
3214 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_au_overtime	       	    , p_sf52rec.to_au_overtime		 );
3215 --VSM .49
3216 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_basic_pay                    , p_sf52rec.to_basic_pay       );
3217 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_locality_adj                 , p_sf52rec.to_locality_adj    );
3218 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_adj_basic_pay                , p_sf52rec.to_adj_basic_pay   );
3219 -- VSM .49
3220 	/*
3221 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_position_org_line1   	    , p_sf52rec.to_position_org_line1          );
3222 	-- Sundar 15Dec2003 Bug 3191676 Copy other orglines too.
3223 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_position_org_line2   	    , p_sf52rec.to_position_org_line2          );
3224 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_position_org_line3   	    , p_sf52rec.to_position_org_line3          );
3225 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_position_org_line4   	    , p_sf52rec.to_position_org_line4          );
3226 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_position_org_line5   	    , p_sf52rec.to_position_org_line5          );
3227 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.to_position_org_line6   	    , p_sf52rec.to_position_org_line6          );
3228 	-- End Bug 3191676 */
3229 	-- Above lines commented by Sundar for Bug 2681726 They've been moved below.
3230 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.veterans_preference             , p_sf52rec.veterans_preference              );
3231 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.veterans_pref_for_rif           , p_sf52rec.veterans_pref_for_rif            );
3232 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.veterans_status                 , p_sf52rec.veterans_status                  );
3233 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.work_schedule_desc              , p_sf52rec.work_schedule_desc               );
3234 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.year_degree_attained            , p_sf52rec.year_degree_attained             );
3235 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_noa_information1          , p_sf52rec.first_noa_information1           );
3236 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_noa_information2          , p_sf52rec.first_noa_information2           );
3237 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_noa_information3          , p_sf52rec.first_noa_information3           );
3238 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_noa_information4          , p_sf52rec.first_noa_information4           );
3239 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_noa_information5          , p_sf52rec.first_noa_information5           );
3240 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_lac1_information1         , p_sf52rec.first_lac1_information1          );
3241 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_lac1_information2         , p_sf52rec.first_lac1_information2          );
3242 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_lac1_information3         , p_sf52rec.first_lac1_information3          );
3243 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_lac1_information4         , p_sf52rec.first_lac1_information4          );
3244 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_lac1_information5         , p_sf52rec.first_lac1_information5          );
3245 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_lac2_information1         , p_sf52rec.first_lac2_information1          );
3246 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_lac2_information2         , p_sf52rec.first_lac2_information2          );
3247 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_lac2_information3         , p_sf52rec.first_lac2_information3          );
3248 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_lac2_information4         , p_sf52rec.first_lac2_information4          );
3249 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.first_lac2_information5         , p_sf52rec.first_lac2_information5          );
3250 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute_category              , p_sf52rec.attribute_category               );
3251 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute1                      , p_sf52rec.attribute1                       );
3252 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute2                      , p_sf52rec.attribute2                       );
3253 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute3                      , p_sf52rec.attribute3                       );
3254 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute4                      , p_sf52rec.attribute4                       );
3255 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute5                      , p_sf52rec.attribute5                       );
3256 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute6                      , p_sf52rec.attribute6                       );
3257 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute7                      , p_sf52rec.attribute7                       );
3258 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute8                      , p_sf52rec.attribute8                       );
3259 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute9                      , p_sf52rec.attribute9                       );
3260 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute10                     , p_sf52rec.attribute10                      );
3261 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute11                     , p_sf52rec.attribute11                      );
3262 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute12                     , p_sf52rec.attribute12                      );
3263 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute13                     , p_sf52rec.attribute13                      );
3264 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute14                     , p_sf52rec.attribute14                      );
3265 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute15                     , p_sf52rec.attribute15                      );
3266 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute16                     , p_sf52rec.attribute16                      );
3267 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute17                     , p_sf52rec.attribute17                      );
3268 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute18                     , p_sf52rec.attribute18                      );
3269 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute19                     , p_sf52rec.attribute19                      );
3270 	ghr_history_conv_rg.copy_field_value( p_sf52rec_correct.attribute20                     , p_sf52rec.attribute20                      );
3271 
3272 
3273 	-- the following fields should only be copied if the position_id changed, otherwise original values should be
3274 	-- retained.
3275     if ( 	p_sf52rec_correct.to_position_id is not null ) then
3276 		hr_utility.set_location(' Position id changed :'||l_proc, 20);
3277 		p_sf52rec.to_position_id                  := p_sf52rec_correct.to_position_id     ;
3278 		p_sf52rec.to_organization_id              := p_sf52rec_correct.to_organization_id ;
3279 		p_sf52rec.to_pay_plan                     := p_sf52rec_correct.to_pay_plan        ;
3280 		p_sf52rec.to_position_title               := p_sf52rec_correct.to_position_title  ;
3281 		p_sf52rec.to_position_number              := p_sf52rec_correct.to_position_number ;
3282 		p_sf52rec.to_position_seq_no              := p_sf52rec_correct.to_position_seq_no ;
3283 		p_sf52rec.to_grade_or_level               := p_sf52rec_correct.to_grade_or_level  ;
3284 /*
3285 		p_sf52rec.to_basic_pay                    := p_sf52rec_correct.to_basic_pay       ;
3286 		p_sf52rec.to_locality_adj                 := p_sf52rec_correct.to_locality_adj    ;
3287 		p_sf52rec.to_adj_basic_pay                := p_sf52rec_correct.to_adj_basic_pay   ;
3288 */
3289 		p_sf52rec.to_pay_basis                    := p_sf52rec_correct.to_pay_basis       ;
3290 
3291                 -- Populating position org lines (Bug# 948208)
3292 		-- Bug 3343579 Commented the following IF condition.
3293 
3294 		-- IF (p_sf52rec.to_position_org_line1 IS NULL)   THEN
3295 		  p_sf52rec.to_position_org_line1           := p_sf52rec_correct.to_position_org_line1;
3296                   p_sf52rec.to_position_org_line2           := p_sf52rec_correct.to_position_org_line2;
3297                   p_sf52rec.to_position_org_line3           := p_sf52rec_correct.to_position_org_line3;
3298                   p_sf52rec.to_position_org_line4           := p_sf52rec_correct.to_position_org_line4;
3299                   p_sf52rec.to_position_org_line5           := p_sf52rec_correct.to_position_org_line5;
3300                   p_sf52rec.to_position_org_line6           := p_sf52rec_correct.to_position_org_line6;
3301                 -- END IF;
3302 
3303        end if;
3304 
3305        p_sf52rec.custom_pay_calc_flag            := p_sf52rec_correct.custom_pay_calc_flag;
3306 
3307 	-- Below Added by Sundar for Bug 3191676 and 2681726
3308 	IF ( p_sf52rec_correct.first_noa_code = '790') THEN
3309 	p_sf52rec.to_position_org_line1           := p_sf52rec_correct.to_position_org_line1;
3310         p_sf52rec.to_position_org_line2           := p_sf52rec_correct.to_position_org_line2;
3311         p_sf52rec.to_position_org_line3           := p_sf52rec_correct.to_position_org_line3;
3312         p_sf52rec.to_position_org_line4           := p_sf52rec_correct.to_position_org_line4;
3313         p_sf52rec.to_position_org_line5           := p_sf52rec_correct.to_position_org_line5;
3314         p_sf52rec.to_position_org_line6           := p_sf52rec_correct.to_position_org_line6;
3315 	ELSIF ( p_sf52rec_correct.first_noa_code = '352') THEN
3316  	  p_sf52rec.to_position_org_line1           := p_sf52rec_correct.to_position_org_line1;
3317 	END IF;
3318 	-- End Bug 3191676 and 2681726
3319 
3320 	-- work_schedule and part_time_hours are interdependent, part_time_hours should also
3321 	-- be copied when work_schedule changes.
3322 	if ( p_sf52rec_correct.work_schedule <> p_sf52rec.work_schedule
3323     		AND p_sf52rec_correct.work_schedule is not null ) then
3324 		hr_utility.set_location(' Work Schedule changed :'||l_proc, 30);
3325 		p_sf52rec.work_schedule                   := p_sf52rec_correct.work_schedule     ;
3326 		p_sf52rec.part_time_hours                 := p_sf52rec_correct.part_time_hours   ;
3327 	elsif (p_sf52rec_correct.part_time_hours <> p_sf52rec.part_time_hours) then
3328 		hr_utility.set_location(' Part Time hours changed :'||l_proc, 30);
3329 		p_sf52rec.part_time_hours                 := p_sf52rec_correct.part_time_hours   ;
3330 	end if;
3331 
3332 	if (p_corr_pa_request_id = p_sf52rec_correct.pa_request_id) then
3333 		-- these fields should retain value of correction currently being processed. Any values from previous
3334 		-- corrections are ignored.
3335 		hr_utility.set_location(' Last correction :'||l_proc, 35);
3336 		p_sf52rec.routing_group_id 			:= p_sf52rec_correct.routing_group_id			;
3337 		p_sf52rec.proposed_effective_asap_flag    := p_sf52rec_correct.proposed_effective_asap_flag	;
3338 		p_sf52rec.additional_info_person_id       := p_sf52rec_correct.additional_info_person_id    	;
3339 		p_sf52rec.additional_info_tel_number      := p_sf52rec_correct.additional_info_tel_number   	;
3340 		p_sf52rec.authorized_by_person_id         := p_sf52rec_correct.authorized_by_person_id      	;
3341 		p_sf52rec.authorized_by_title             := p_sf52rec_correct.authorized_by_title          	;
3342 		p_sf52rec.concurrence_date                := p_sf52rec_correct.concurrence_date             	;
3343 		p_sf52rec.notepad                         := p_sf52rec_correct.notepad                      	;
3344 		p_sf52rec.proposed_effective_date         := p_sf52rec_correct.proposed_effective_date      	;
3345 		p_sf52rec.requested_by_person_id          := p_sf52rec_correct.requested_by_person_id          	;
3346 		p_sf52rec.requested_by_title              := p_sf52rec_correct.requested_by_title              	;
3347 		p_sf52rec.requested_date                  := p_sf52rec_correct.requested_date                  	;
3348 		p_sf52rec.requesting_office_remarks_desc  := p_sf52rec_correct.requesting_office_remarks_desc  	;
3349 		p_sf52rec.requesting_office_remarks_flag  := p_sf52rec_correct.requesting_office_remarks_flag  	;
3350 		p_sf52rec.request_number                  := p_sf52rec_correct.request_number                  	;
3351 
3352 		p_sf52rec.employee_first_name			:= p_sf52rec_correct.employee_first_name			;
3353 		p_sf52rec.employee_last_name			:= p_sf52rec_correct.employee_last_name			;
3354 		p_sf52rec.employee_middle_names		:= p_sf52rec_correct.employee_middle_names		;
3355 		p_sf52rec.employee_national_identifier	:= p_sf52rec_correct.employee_national_identifier	;
3356 		p_sf52rec.employee_date_of_birth		:= p_sf52rec_correct.employee_date_of_birth		;
3357 
3358 	end if;
3359       -- added by skutteti on 14-oct-98 to take care of the new requirements for
3360       -- percentages on awards and other pay
3361       if p_sf52rec_correct.award_amount is not null or
3362          p_sf52rec_correct.award_percentage is not null then
3363 		 p_sf52rec.award_amount     := p_sf52rec_correct.award_amount;
3364          p_sf52rec.award_percentage := p_sf52rec_correct.award_percentage;
3365       else
3366          ghr_history_conv_rg.copy_field_value(p_sf52rec_correct.award_percentage,p_sf52rec.award_percentage);
3367 		 IF p_sf52rec.award_percentage IS NOT NULL THEN
3368              -- Begin Bug# 5014663
3369              ghr_history_fetch.fetch_asgei(
3370                                 p_assignment_id    => p_sf52rec.employee_assignment_id,
3371                                 p_information_type => 'GHR_US_ASG_SF52',
3372                                 p_date_effective   => p_sf52rec.effective_date,
3373                                 p_asg_ei_data      => l_asg_ei_data);
3374 
3375              ghr_pay_calc.award_amount_calc (
3376                              p_position_id		=> p_sf52rec.from_position_id
3377                             ,p_pay_plan			=> p_sf52rec.from_pay_plan
3378                             ,p_award_percentage => p_sf52rec.award_percentage
3379                             ,p_user_table_id	=> p_sf52rec.from_pay_table_identifier
3380                             ,p_grade_or_level	=> p_sf52rec.from_grade_or_level
3381                             ,p_effective_date	=> p_sf52rec.effective_date
3382                             ,p_basic_pay		=> p_sf52rec.from_basic_pay
3383                             ,p_adj_basic_pay	=> p_sf52rec.from_adj_basic_pay
3384                             ,p_duty_station_id	=> p_sf52rec.duty_station_id
3385                             ,p_prd				=> l_asg_ei_data.aei_information6
3386                             ,p_pay_basis		=> p_sf52rec.from_pay_basis
3387                             ,p_person_id		=> p_sf52rec.person_id
3388                             ,p_award_amount		=> l_temp_award_amount
3389                             ,p_award_salary		=> l_award_salary
3390                             );
3391                 ghr_history_conv_rg.copy_field_value(l_temp_award_amount,p_sf52rec.award_amount);
3392         ELSE
3393             ghr_history_conv_rg.copy_field_value(p_sf52rec_correct.award_amount,p_sf52rec.award_amount);
3394         END IF;
3395 		-- End Bug# 5014663
3396 
3397       end if;
3398       if p_sf52rec_correct.to_supervisory_differential is not null or
3399          p_sf52rec_correct.to_supervisory_diff_percentage is not null then
3400          p_sf52rec.to_supervisory_differential    := p_sf52rec_correct.to_supervisory_differential;
3401          p_sf52rec.to_supervisory_diff_percentage := p_sf52rec_correct.to_supervisory_diff_percentage;
3402       else
3403          ghr_history_conv_rg.copy_field_value(p_sf52rec_correct.to_supervisory_differential,
3404                                               p_sf52rec.to_supervisory_differential);
3405          ghr_history_conv_rg.copy_field_value(p_sf52rec_correct.to_supervisory_diff_percentage,
3406                                               p_sf52rec.to_supervisory_diff_percentage);
3407       end if;
3408       if p_sf52rec_correct.to_retention_allowance is not null or
3409          p_sf52rec_correct.to_retention_allow_percentage is not null then
3410          p_sf52rec.to_retention_allowance        := p_sf52rec_correct.to_retention_allowance;
3411          p_sf52rec.to_retention_allow_percentage := p_sf52rec_correct.to_retention_allow_percentage;
3412       else
3413          ghr_history_conv_rg.copy_field_value(p_sf52rec_correct.to_retention_allowance,
3414                                               p_sf52rec.to_retention_allowance);
3415          ghr_history_conv_rg.copy_field_value(p_sf52rec_correct.to_retention_allow_percentage,
3416                                               p_sf52rec.to_retention_allow_percentage);
3417       end if;
3418       if p_sf52rec_correct.to_staffing_differential is not null or
3419          p_sf52rec_correct.to_staffing_diff_percentage is not null then
3420          p_sf52rec.to_staffing_differential    := p_sf52rec_correct.to_staffing_differential;
3421          p_sf52rec.to_staffing_diff_percentage := p_sf52rec_correct.to_staffing_diff_percentage;
3422       else
3423          ghr_history_conv_rg.copy_field_value(p_sf52rec_correct.to_staffing_differential,
3424                                               p_sf52rec.to_staffing_differential);
3425          ghr_history_conv_rg.copy_field_value(p_sf52rec_correct.to_staffing_diff_percentage,
3426                                               p_sf52rec.to_staffing_diff_percentage);
3427       end if;
3428 
3429 	hr_utility.set_location(' Leaving:'||l_proc, 40);
3430   Exception when others then
3431             --
3432             -- Reset IN OUT parameters and set OUT parameters
3433             --
3434             p_sf52rec := l_sf52rec;
3435             raise;
3436 End  apply_correction ;
3437 
3438 -- --------------------------------------------------------------------------------
3439 -- |--------------------------< apply_noa_corrections>-----------------------------|
3440 -- --------------------------------------------------------------------------------
3441 -- {Start Of Comments}
3442 --
3443 -- Description:
3444 -- 	This procedure finds the original sf52 record and the intermediate incremental
3445 -- 	changes. The intermediate incremental changes are applied in sequence to
3446 -- 	arrive at final corrected record.
3447 --
3448 -- Pre-Requisities:
3449 --   	None.
3450 --
3451 -- In Parameters:
3452 --	p_sf52_data			->	the ghr_pa_requests record for the
3453 --						correction we are currently processing.
3454 --	p_sf52_data_result	->	the ghr_pa_requests record that will hold the final
3455 --						corrected data for all corrections in the correction
3456 --						chain upon successful completion of this procedure.
3457 -- Post Success:
3458 -- 	All the corrections in the correction chain will have been applied and the
3459 --	result put in p_sf52_data_result.
3460 --
3461 -- Post Failure:
3462 --   	No failure conditions.
3463 --
3464 -- Developer Implementation Notes:
3465 --	None.
3466 --
3467 -- Access Status:
3468 --   Internal Development Use Only.
3469 --
3470 -- {End Of Comments}
3471 -- ---------------------------------------------------------------------------
3472 
3473 Procedure apply_noa_corrections( 	p_sf52_data		in	ghr_pa_requests%rowtype,
3474 						p_sf52_data_result in out nocopy ghr_pa_requests%rowtype ) is
3475 
3476 l_sf52_data_orig		ghr_pa_requests%rowtype;
3477 l_sf52_data_step		ghr_pa_requests%rowtype;
3478 l_sf52_ia_rec                   ghr_pa_requests%rowtype;
3479 l_sf52_dummy		ghr_pa_requests%rowtype;
3480 l_sf52_cursor_step_indx	number;
3481 l_session_var		ghr_history_api.g_session_var_type;
3482 -- Bug#5435374 added l_session_var1.
3483 l_session_var1   ghr_history_api.g_session_var_type;
3484 l_capped_other_pay number := hr_api.g_number;
3485 l_retro_eff_date        ghr_pa_requests.effective_date%type;
3486 l_retro_pa_request_id   ghr_pa_requests.pa_request_id%type;
3487 l_retro_first_noa       ghr_nature_of_actions.code%type;
3488 l_retro_second_noa       ghr_nature_of_actions.code%type;
3489 l_sf52_data_result      ghr_pa_requests%rowtype;
3490 -- Bug#3543213 Created l_dummy variable
3491 l_dummy                 VARCHAR2(30);
3492 -- this cursor selects all rows in the correction chain from ghr_pa_requests
3493 cursor  l_sf52_cursor is
3494 	select 	*
3495 	from 		ghr_pa_requests
3496 	connect by 	prior altered_pa_request_id = pa_request_id
3497 	start with	pa_request_id = p_sf52_data.pa_request_id
3498 	order by 	level desc;
3499 
3500 cursor c_orig_details_for_ia is
3501         select pa_request_id,pa_notification_id,person_id,
3502                effective_date,from_position_id,
3503                to_position_id
3504         from ghr_pa_requests
3505         where pa_request_id = p_sf52_data.altered_pa_request_id;
3506 
3507 	cursor c_get_hist_id (c_pa_request_id in number) is
3508 	select
3509 		min(pa_history_id)
3510 	from ghr_pa_history
3511 	where pa_request_id = c_pa_request_id;
3512 
3513 	-- Bug#5435374
3514 	l_pos_ei_grade_data  per_position_extra_info%rowtype;
3515 
3516 	cursor c_grade_kff (grd_id number) is
3517         select gdf.segment1
3518               ,gdf.segment2
3519           from per_grades grd,
3520                per_grade_definitions gdf
3521          where grd.grade_id = grd_id
3522            and grd.grade_definition_id = gdf.grade_definition_id;
3523 
3524 --bug #6356058 start
3525 l_core_chg_avbl number;
3526 l_prev_request_id number;
3527 l_curr_pa_history_id number;
3528 l_pos_ei_grp1_data	per_position_extra_info%rowtype;
3529 --   8737300 Modified the cursor for improving performance
3530 cursor core_chg_check(p_to_position_id in number,
3531                       p_effective_date in date)
3532     is
3533        select  1
3534        from    ghr_pa_history hist_1
3535        where   pa_request_id is null
3536        and     hist_1.pa_history_id > (select min(pa_history_id)
3537                                        from ghr_pa_history
3538 	  			       where pa_request_id = l_prev_request_id)
3539        and     hist_1.pa_history_id < nvl(l_curr_pa_history_id,999999999)
3540        and     information1 in   (select  to_char(position_extra_info_id)
3541                                   from    per_position_extra_info
3542                                   where   position_id          =  p_to_position_id
3543                                   and     information_type     in  ('GHR_US_POS_GRP1'))
3544        and     information5   =  'GHR_US_POS_GRP1'
3545        and     effective_date =  p_effective_date
3546        and     table_name     =  'PER_POSITION_EXTRA_INFO';
3547 --bug #6356058 start
3548 
3549 
3550 
3551 	l_shadow_data	ghr_pa_request_shadow%rowtype;
3552 	l_proc	varchar2(30):='apply_noa_corrections';
3553 begin
3554 	hr_utility.set_location('Entering:'|| l_proc, 5);
3555    l_sf52_data_result := p_sf52_data_result;
3556 	ghr_history_api.get_g_session_var(l_session_var);
3557 	-- loop through all corrections in the correction chain, incrementally applying them by
3558 	-- calling apply_corrections procedure.
3559 	open l_sf52_cursor ;
3560 	l_sf52_cursor_step_indx := 0;
3561 	loop
3562 		-- initialize l_sf52_data_step to nulls;
3563 		l_sf52_data_step := l_sf52_dummy;
3564 		-- l_sf52_data_step holds intermediate incremental values for final corrected record that is
3565 		-- being built.
3566 		fetch l_sf52_cursor into l_sf52_data_step;
3567 		exit when l_sf52_cursor%notfound;
3568 		l_sf52_cursor_step_indx := l_sf52_cursor_step_indx +1;
3569 		if ( 	l_sf52_cursor_step_indx = 1) then
3570 		--Bug # 6356058 start
3571 		         l_prev_request_id := l_sf52_data_step.pa_request_id;
3572 		--Bug # 6356058 end
3573 			hr_utility.set_location('Fetch l_sf52_data_step original :'|| l_proc, 10);
3574 			l_sf52_data_orig 	  := l_sf52_data_step;
3575 			p_sf52_data_result  := l_sf52_data_step;
3576 			hr_utility.set_location('assignment_id of original =' || l_sf52_data_step.employee_assignment_id, 14);
3577 			hr_utility.set_location('from grd or leveloriginal =' || l_sf52_data_step.from_grade_or_level, 14);
3578 
3579 			hr_utility.set_location(l_proc || 'pa_request_id of original= ' || l_sf52_data_step.pa_request_id,26);
3580 -- .47
3581 			-- refresh root sf52 and its correction
3582 			-- get pa_history_id for the root pa_request_id
3583 			open c_get_hist_id( l_sf52_data_step.pa_request_id);
3584 			fetch c_get_hist_id into l_session_var.pa_history_id;
3585 			if c_get_hist_id%notfound then
3586 				-- raise error;
3587 				close c_get_hist_id;
3588 			else
3589 				close c_get_hist_id;
3590 			end if;
3591 			-- We are setting pa_history_id in session var to be able to fetch
3592 			-- Pre-record values of the root SF52 for refresh purpose.
3593 			-- It'll be reset after refresh has been done
3594 
3595 			ghr_history_api.set_g_session_var(l_session_var);
3596 			ghr_process_sf52.refresh_req_shadow(p_sf52_data		=>	p_sf52_data_result,
3597 									p_shadow_data	=>	l_shadow_data);
3598 			ghr_process_sf52.redo_pay_calc(	p_sf52_rec		=>	p_sf52_data_result,
3599                                                         p_capped_other_pay      =>   l_capped_other_pay);
3600 
3601 			-- reset pa_history_id in session variable.
3602 			l_session_var.pa_history_id := null;
3603 			ghr_history_api.set_g_session_var(l_session_var);
3604 -- .47
3605  		        -- Bug#3543213 For PRD U,V and NOA 894(Pay Adjustment) get the PRD Value from assignment
3606 			IF p_sf52_data_result.first_noa_code = '894' AND
3607 			   p_sf52_data_result.pay_rate_determinant IN ('U','V') THEN
3608 			   ghr_pa_requests_pkg.get_SF52_asg_ddf_details
3609 	                     (p_assignment_id         => p_sf52_data_result.employee_assignment_id
3610 	                     ,p_date_effective        => p_sf52_data_result.effective_date
3611 	                     ,p_tenure                => l_dummy
3612 	                     ,p_annuitant_indicator   => l_dummy
3613 	                     ,p_pay_rate_determinant  => p_sf52_data_result.pay_rate_determinant
3614                            ,p_work_schedule         => l_dummy
3615                            ,p_part_time_hours       => l_dummy);
3616 			END IF;
3617 		        -- End of Bug#3543213
3618 
3619 			-- check if original action in correction chain was a dual action. If so, determine which of
3620 			--   the two actions this correction is for and call ghr_process_sf52.assign_new_rg to null out columns not having
3621 			--   to do with the noa we are correcting.
3622 			if (p_sf52_data_result.second_noa_id is not null) then
3623 				hr_utility.set_location('original sf52 is dual action :'|| l_proc, 11);
3624 				if (p_sf52_data.second_noa_id = p_sf52_data_result.second_noa_id) then
3625 					hr_utility.set_location('Correcting second action in dual action:'|| l_proc, 12);
3626 					ghr_process_sf52.assign_new_rg(p_action_num			=>	2,
3627 										 p_pa_req				=>	p_sf52_data_result);
3628 				else
3629 					hr_utility.set_location('Correcting first action in dual action:'|| l_proc, 13);
3630 					ghr_process_sf52.assign_new_rg(p_action_num			=>	1,
3631 								 		 p_pa_req				=>	p_sf52_data_result);
3632 		 			-- if first action is 893, then we need to derive to_columns as both actions of
3633 					-- the dual action potentially could have changed the to fields (in particular,
3634 					-- to_step_or_rate) so we need to determine what the to_fields should be or the first action.
3635 					if (p_sf52_data_result.first_noa_code = '893') then--Bug# 8926400
3636 						ghr_process_sf52.derive_to_columns(p_sf52_data	=>	p_sf52_data_result);
3637 					end if;
3638 				end if;
3639 			end if;
3640 			-- Nullfy columns which must not be passed
3641 			p_sf52_data_result.pa_notification_id		:= NULL;
3642 			p_sf52_data_result.agency_code			:= NULL;
3643 			p_sf52_data_result.approval_date			:= NULL;
3644 			p_sf52_data_result.approving_official_work_title:= NULL;
3645 			p_sf52_data_result.employee_dept_or_agency 	:= NULL;
3646 			p_sf52_data_result.from_agency_code			:= NULL;
3647 			p_sf52_data_result.from_agency_desc			:= NULL;
3648 			p_sf52_data_result.from_office_symbol		:= NULL;
3649 			p_sf52_data_result.personnel_office_id		:= NULL;
3650 			p_sf52_data_result.to_office_symbol			:= NULL;
3651 		else
3652 		        l_retro_pa_request_id := NULL;
3653 			hr_utility.set_location('Fetch l_sf52_data_step loop :'|| l_proc, 15);
3654 			-- all corrections will have the original sf52 information in the 2nd noa columns, so
3655 			-- copy that information to 1st noa columns.
3656 			hr_utility.set_location('from grd or levelbefcp2to1 =' || l_sf52_data_step.from_grade_or_level, 14);
3657 			ghr_process_sf52.copy_2ndNoa_to_1stNoa(l_sf52_data_step);
3658 			-- null the second noa columns since we don't want anything to be done with these now.
3659 			hr_utility.set_location('from grd or levelaftcp2to1 =' || l_sf52_data_step.from_grade_or_level, 14);
3660 			ghr_process_sf52.null_2ndNoa_cols(l_sf52_data_step);
3661 			hr_utility.set_location('from grd or levelaftnull2noa =' || l_sf52_data_step.from_grade_or_level, 14);
3662 			hr_utility.set_location(l_proc || 'pa_request_id before correction= ' || l_sf52_data_step.pa_request_id,16);
3663 			hr_utility.set_location(l_proc || 'assignment id before correction= ' || l_sf52_data_step.employee_assignment_id,17);
3664 			hr_utility.set_location('from grd or levelbef appcorr =' || l_sf52_data_step.from_grade_or_level, 14);
3665                         ghr_process_sf52.print_sf52('l_sf52_step bef apply_correction',
3666                                                      l_sf52_data_step );
3667                         ghr_process_sf52.print_sf52('result bef copy_ia_rec_on_result',
3668                                                      p_sf52_data_result );
3669                        -- Start Intervening Actions Processing
3670                        -- Processing added to assign the From side details to
3671                        -- To side if it is a Intervening action and
3672                        -- Original action from position_id = to position id
3673                        -- Fetch the original action details
3674                        FOR c_orig_det_rec in c_orig_details_for_ia
3675                        LOOP
3676                             hr_utility.set_location('Inside the orig_details for loop' ,15);
3677                             hr_utility.set_location('orig pa_request_id'||c_orig_det_rec.pa_request_id ,15);
3678                             hr_utility.set_location('orig pa_notification_id'||c_orig_det_rec.pa_notification_id ,15);
3679                             hr_utility.set_location('orig person_id'||c_orig_det_rec.person_id ,15);
3680                             hr_utility.set_location('orig from_position_id'||c_orig_det_rec.from_position_id ,15);
3681                             hr_utility.set_location('orig to_position_id'||c_orig_det_rec.to_position_id ,15);
3682                             hr_utility.set_location('orig effective_date'||c_orig_det_rec.effective_date ,15);
3683 			    --BUG #7216635 added the parameter p_noa_id_correct
3684                            GHR_APPROVED_PA_REQUESTS.determine_ia(
3685                                  p_pa_request_id => c_orig_det_rec.pa_request_id,
3686                                  p_pa_notification_id => c_orig_det_rec.pa_notification_id,
3687                                  p_person_id      => c_orig_det_rec.person_id,
3688                                  p_effective_date => c_orig_det_rec.effective_date,
3689 				 p_noa_id_correct => l_session_var.noa_id_correct,
3690                                  p_retro_pa_request_id => l_retro_pa_request_id,
3691                                  p_retro_eff_date => l_retro_eff_date,
3692                                  p_retro_first_noa => l_retro_first_noa,
3693                                  p_retro_second_noa => l_retro_second_noa);
3694                             hr_utility.set_location('retro effective_date is '||l_retro_eff_date ,16);
3695                             -- Bug#2521744 Splitting the single if condition into 2 separate if conditions.
3696                             IF l_retro_eff_date is NOT NULL  THEN
3697                                IF c_orig_det_rec.from_position_id
3698                                     = c_orig_det_rec.to_position_id THEN
3699                                        -- copy the from details
3700                                     hr_utility.set_location('Its a Intervening Action ' ,16);
3701                                     hr_utility.set_location('pa_request_id passed to get_sf52_to_det '||p_sf52_data.pa_request_id ,17);
3702 
3703                                     get_sf52_to_details_for_ia
3704                                        (p_pa_request_id => p_sf52_data.pa_request_id,
3705                                         p_retro_eff_date   => l_retro_eff_date,
3706                                         p_sf52_ia_rec  => p_sf52_data_result);
3707                                     ghr_process_sf52.print_sf52('result aft get_sf52_to_details_for_ia',
3708                                                      p_sf52_data_result );
3709                                     get_sf52_to_othpays_for_ia(p_sf52_ia_rec  => p_sf52_data_result);
3710                                     ghr_process_sf52.print_sf52('reslt aft get_sf52_to_other_pay_det_for_ia',
3711                                                      p_sf52_data_result );
3712                               ELSE
3713                                 -- Verify whether the original action is one of the salary change actions
3714                                 -- If yes, check whether the other pay related elements are present or not
3715                                 -- as on the effective date. If they are not present, set that other pay comp
3716                                 -- to_value as null.
3717                                 get_sf52_to_othpays_for_ia(p_sf52_ia_rec  => p_sf52_data_result);
3718                                 ghr_process_sf52.print_sf52('Aft get_sf52_to_other_pay_det_for_ia in else',
3719                                                  p_sf52_data_result );
3720                               END IF;
3721 
3722 
3723                  	       END IF;
3724 --bug #6356058 start
3725                             IF p_sf52_data_result.from_position_id = p_sf52_data_result.to_position_id THEN
3726                               IF l_retro_pa_request_id IS NOT NULL THEN
3727 			         l_prev_request_id := l_retro_pa_request_id;
3728 			      end if;
3729                                 open c_get_hist_id(l_sf52_data_step.pa_request_id);
3730 			        fetch c_get_hist_id into l_curr_pa_history_id;
3731 				close c_get_hist_id;
3732                                 open core_chg_check( p_sf52_data_result.to_position_id,
3733 				                     c_orig_det_rec.effective_date);
3734 				fetch core_chg_check into l_core_chg_avbl;
3735 				if core_chg_check%found then
3736 				  ghr_history_api.get_g_session_var(l_session_var);
3737                                   ghr_history_api.reinit_g_session_var;
3738                                   l_session_var1.date_Effective            := l_session_var.date_Effective;
3739                                   l_session_var1.person_id                 := l_session_var.person_id;
3740                                   l_session_var1.assignment_id             := l_session_var.assignment_id;
3741                                   l_session_var1.fire_trigger    := 'N';
3742                                   l_session_var1.program_name := 'sf50';
3743                                   ghr_history_api.set_g_session_var(l_session_var1);
3744 				  ghr_history_fetch.fetch_positionei(
3745                                        p_position_id      => p_sf52_data_result.to_position_id,
3746                                        p_information_type => 'GHR_US_POS_GRP1',
3747                                        p_date_effective   => p_sf52_data_result.effective_date,
3748                                        p_pos_ei_data      => l_pos_ei_grp1_data);
3749 				    p_sf52_data_result.supervisory_status     := l_pos_ei_grp1_data.poei_information16;
3750                                     p_sf52_data_result.part_time_hours        := l_pos_ei_grp1_data.poei_information23;
3751                                   ghr_history_api.reinit_g_session_var;
3752                                   ghr_history_api.set_g_session_var(l_session_var);
3753 				end if;
3754 				close core_chg_check;
3755                               END IF;
3756 --bug #6356058 end
3757                        END LOOP;
3758 		       --bug #6356058
3759 		       l_prev_request_id := l_sf52_data_step.pa_request_id;
3760            			   hr_utility.set_location('Out side the orig_details for loop' ,17);
3761                        -- End Intervening Actions Processing
3762 
3763                         apply_correction( p_sf52rec_correct		=>	l_sf52_data_step,
3764                                     p_corr_pa_request_id	=>	p_sf52_data.pa_request_id,
3765                                     p_sf52rec			=>	p_sf52_data_result );
3766 
3767                         -- Recalculating Retention Allowance
3768                         -- Recalculate Retention allowance if it is a OTHER_PAY action
3769                         -- and Correction of Intervening Action
3770                          if p_sf52_data_result.noa_family_code = 'OTHER_PAY' and
3771                            l_retro_eff_date is NOT NULL and
3772                            p_sf52_data_result.to_retention_allow_percentage is not null then
3773    --Modified for FWS
3774                            IF p_sf52_data_result.to_pay_basis ='PH' THEN
3775        			      p_sf52_data_result.to_retention_allowance :=
3776                                  TRUNC(p_sf52_data_result.to_basic_pay * p_sf52_data_result.to_retention_allow_percentage/100,2);
3777 			   ELSE
3778 			        p_sf52_data_result.to_retention_allowance :=
3779                                  TRUNC(p_sf52_data_result.to_basic_pay * p_sf52_data_result.to_retention_allow_percentage/100,0);
3780                            END IF;
3781 
3782                              p_sf52_data_result.to_other_pay_amount :=
3783                              nvl(p_sf52_data_result.to_au_overtime,0) +
3784                              nvl(p_sf52_data_result.to_availability_pay,0) +
3785                              nvl(p_sf52_data_result.to_retention_allowance,0) +
3786                              nvl(p_sf52_data_result.to_supervisory_differential,0) +
3787                              nvl(p_sf52_data_result.to_staffing_differential,0);
3788                              p_sf52_data_result.to_total_salary :=
3789                              p_sf52_data_result.to_adj_basic_pay + p_sf52_data_result.to_other_pay_amount;
3790                              if p_sf52_data_result.to_other_pay_amount = 0 then
3791                                p_sf52_data_result.to_other_pay_amount := null;
3792                              end if;
3793                            end if;
3794 			hr_utility.set_location( l_proc || 'assignment_id after correction=' || p_sf52_data_result.employee_assignment_id ,18);
3795 			hr_utility.set_location('Applied corrections :'|| l_proc, 20);
3796 		end if;
3797 	end loop;
3798 	close l_sf52_cursor;
3799 
3800 	 -- Bug#5435374 If the from and to position ids are same, verify the pay plan, grade details.
3801 	 IF p_sf52_data_result.from_position_id = p_sf52_data_result.to_position_id THEN
3802 
3803         -- Reinitializing the session variables to get the valid grade as on the
3804         -- effective date.
3805         ghr_history_api.get_g_session_var(l_session_var);
3806         ghr_history_api.reinit_g_session_var;
3807         l_session_var1.date_Effective            := l_session_var.date_Effective;
3808         l_session_var1.person_id                 := l_session_var.person_id;
3809         l_session_var1.assignment_id             := l_session_var.assignment_id;
3810         l_session_var1.fire_trigger    := 'N';
3811         l_session_var1.program_name := 'sf50';
3812         ghr_history_api.set_g_session_var(l_session_var1);
3813 
3814 		 -- Retrieve the Grade info from the POI history table
3815 		ghr_history_fetch.fetch_positionei(
3816 		p_position_id      => p_sf52_data_result.to_position_id,
3817 		p_information_type => 'GHR_US_POS_VALID_GRADE',
3818 		p_date_effective   => p_sf52_data_result.effective_date,
3819 		p_pos_ei_data      => l_pos_ei_grade_data);
3820 
3821         -- Reset the session variables after getting the date effective valid grade
3822         -- to continue with the correction process.
3823         ghr_history_api.reinit_g_session_var;
3824         ghr_history_api.set_g_session_var(l_session_var);
3825 
3826 		IF l_pos_ei_grade_data.position_extra_info_id IS NOT NULL THEN
3827 			hr_utility.set_location('GL: to grd id:'||p_sf52_data_result.to_grade_id,30);
3828 			hr_utility.set_location('GL: pos ei grd:'||l_pos_ei_grade_data.poei_information3,40);
3829 			IF l_pos_ei_grade_data.poei_information3 <> p_sf52_data_result.to_grade_id THEN
3830 				--Bug# 5638869
3831                 --p_sf52_data_result.to_grade_id := l_pos_ei_grade_data.poei_information3;
3832                 l_pos_ei_grade_data.poei_information3 := p_sf52_data_result.to_grade_id;
3833                 --Bug# 5638869
3834 				FOR c_grade_kff_rec IN c_grade_kff (p_sf52_data_result.to_grade_id)
3835 				LOOP
3836 					hr_utility.set_location('GL: Inside setting pay plan grade',60);
3837 					p_sf52_data_result.to_pay_plan := c_grade_kff_rec.segment1  ;
3838 					p_sf52_data_result.to_grade_or_level := c_grade_kff_rec.segment2;
3839 					EXIT;
3840     			END LOOP;
3841 			END IF;
3842     	END IF;
3843 	END IF;
3844     -- Bug#5435374 End of the fix.
3845 
3846 	hr_utility.set_location(' Leaving:'||l_proc, 25);
3847  Exception when others then
3848            --
3849            -- Reset IN OUT parameters and set OUT parameters
3850            --
3851            p_sf52_data_result := l_sf52_data_result;
3852            raise;
3853 end apply_noa_corrections;
3854 
3855 -- ---------------------------------------------------------------------------
3856 -- |--------------------------< what_to_do>-----------------------------------|
3857 -- ---------------------------------------------------------------------------
3858 -- {Start Of Comments}
3859 --
3860 -- Description:
3861 --	This procedure sets p_can_delete, p_last_row, and p_cannot_cancel flags
3862 --	according to the data it was passed.
3863 --
3864 -- Pre-Requisities:
3865 --   	None.
3866 --
3867 -- In Parameters:
3868 --	p_datetrack_table		->	boolean that indicates if this is a datetrack table or not.
3869 --	p_pre_record_exists	->	boolean that indicates if a pre-value was found for this history record.
3870 --	p_interv_on_table		->	boolean that indicates if there are intervening changes to this row.
3871 --	p_interv_on_eff_date	->	boolean that indicates if there are intervening changes to this row on the
3872 --						same date.
3873 --	p_rec_created_flag	->	boolean that indicates if this record was created by this action.
3874 --	p_can_delete		->	output flag that indicates if this row can be deleted.
3875 --	p_last_row			->	output flag that indicates if this row is the last row in history (there are
3876 --						no following records).
3877 --	p_cannot_cancel		->	output flag that indicates if this row can be cancelled or not.
3878 --
3879 -- Post Success:
3880 -- 	p_can_delete, p_last_row, and p_rec_created_flag will be set appropriately.
3881 --
3882 -- Post Failure:
3883 --   	No failure conditions.
3884 --
3885 -- Developer Implementation Notes:
3886 --	None.
3887 --
3888 -- Access Status:
3889 --   Internal Development Use Only.
3890 --
3891 -- {End Of Comments}
3892 -- ---------------------------------------------------------------------------
3893 
3894 PROCEDURE what_to_do(	p_datetrack_table		in		boolean,
3895 				p_pre_record_exists 	in 		boolean,
3896 				p_interv_on_table		in		boolean,
3897 				p_interv_on_eff_date	in		boolean,
3898 				p_rec_created_flag	in		boolean,
3899 				p_can_delete	 out nocopy 	boolean,
3900 				p_last_row		 out nocopy 	boolean,
3901 				p_cannot_cancel	 out nocopy 	boolean) IS
3902    	l_proc		varchar2(72) := 'what_to_do?';
3903  BEGIN
3904      	hr_utility.set_location('Entering  '|| l_proc,5);
3905 	-- initialize output parms.
3906   	p_can_delete 	:= FALSE;
3907   	p_last_row	 	:= FALSE;
3908   	p_cannot_cancel	:= FALSE;
3909   	if (p_datetrack_table = TRUE) then
3910      		hr_utility.set_location('Datetrack table  '|| l_proc,10);
3911   		-- this is a datetrack table
3912   		if (p_pre_record_exists = FALSE) then
3913         		hr_utility.set_location('no pre'|| l_proc,15);
3914    			if (p_interv_on_eff_date = FALSE) then
3915    	      		hr_utility.set_location('no following records on same date'|| l_proc,20);
3916    				if (p_interv_on_table = TRUE) then
3917 					-- datetrack tables with no pre cannot be cancelled if they have following records in history.
3918 		      		hr_utility.set_location(' Following records on later date'|| l_proc,45);
3919    					p_cannot_cancel 	:= TRUE;
3920 				else
3921 		      		hr_utility.set_location('NO Following records on later date'|| l_proc,70);
3922 					-- there is no pre and no following records, so we CAN cancel and we CAN delete. And this is
3923 					-- the last row in history.
3924    					p_can_delete 	:= TRUE;
3925     					p_last_row 		:= TRUE;
3926     				end if;
3927    			else
3928 	      		hr_utility.set_location('Following records on same date'|| l_proc,75);
3929 				-- datetrack tables with no pre cannot be cancelled if they have following records in history.
3930 				p_cannot_cancel	:= TRUE;
3931 			end if;
3932 		else
3933 			-- there is a pre_record
3934       		hr_utility.set_location('has pre'|| l_proc,25);
3935 			if (p_interv_on_eff_date = FALSE) then
3936 	      		hr_utility.set_location(' no following recs on same date'|| l_proc,30);
3937 				if (p_rec_created_flag = TRUE) then
3938 		      		hr_utility.set_location('record created = TRUE'|| l_proc,35);
3939 					p_can_delete := TRUE;
3940 				end if;
3941 				if (p_interv_on_table = FALSE) then
3942 		      		hr_utility.set_location(' no following recs at all'|| l_proc,40);
3943 					p_last_row := TRUE;
3944 				end if;
3945 			end if;
3946 		end if;
3947 	else
3948 		-- this is a non datetrack table
3949      		hr_utility.set_location(' non datetrack table'|| l_proc,50);
3950 		-- assume there is always a pre-record for datetrack tables. It is just all nulls.
3951 		if (p_interv_on_table = FALSE) then
3952 	      	hr_utility.set_location('no following recs '|| l_proc,60);
3953 			if (p_rec_created_flag = TRUE) then
3954 		      	hr_utility.set_location('record created = Y '|| l_proc,65);
3955 				p_can_delete := TRUE;
3956 				p_last_row   := TRUE;
3957 			end if;
3958 		end if;
3959 	end if;
3960  exception when others then
3961            --
3962            -- Reset IN OUT parameters and set OUT parameters
3963            --
3964            p_can_delete     := null;
3965            p_last_row       := null;
3966            p_cannot_cancel  := null;
3967            raise;
3968 END what_to_do;
3969 
3970 -- ---------------------------------------------------------------------------
3971 -- |--------------------------< delete_element_entry>--------------------------|
3972 -- ---------------------------------------------------------------------------
3973 -- {Start Of Comments}
3974 --
3975 -- Description:
3976 --	This procedure deletes an element entry.
3977 --
3978 -- Pre-Requisities:
3979 --   	None.
3980 --
3981 -- In Parameters:
3982 --	p_hist_rec			->	element entry to be deleted (ghr_pa_history%rowtype).
3983 --	p_cannot_cancel		->	boolean indicates if there is some problem with deleting this element (the action
3984 --						cannot be cancelled).
3985 --
3986 -- Post Success:
3987 -- 	element entry will have been deleted. p_cannot_cancel will be false.
3988 --
3989 -- Post Failure:
3990 --   	p_cannot_cancel will be true.
3991 --
3992 -- Developer Implementation Notes:
3993 --	None.
3994 --
3995 -- Access Status:
3996 --   Internal Development Use Only.
3997 --
3998 -- {End Of Comments}
3999 -- ---------------------------------------------------------------------------
4000 
4001    Procedure delete_element_entry( p_hist_rec 		in 	ghr_pa_history%rowtype,
4002 					     p_del_mode		in	varchar2 default hr_api.g_delete_next_change,
4003    					     p_cannot_cancel out nocopy Boolean) is
4004    	l_del_warning	boolean;
4005 	-- this cursor selects the element_entry_id and object_version_number from
4006 	-- pay_element_entries_f for the element_entry_id and date_effective passed.
4007    	cursor c_elmt ( cp_element_entry_id number,
4008    			    cp_date_Effective	date) is
4009    	select element_entry_id,
4010    		 object_version_number
4011    	from pay_element_entries_f
4012   	where element_entry_id = cp_element_entry_id and
4013  		cp_date_effective between effective_start_date and effective_end_date;
4014   	l_c_elmt	c_elmt%rowtype;
4015   	l_eff_start_date	date;
4016   	l_eff_end_date	date;
4017   	l_proc	varchar2(30):='delete_element_entry';
4018   Begin
4019   	hr_utility.set_location( 'Entering : ' || l_proc, 10);
4020   	hr_utility.set_location( ' info 1 : ' || p_hist_rec.information1 || l_proc, 11);
4021   	hr_utility.set_location( ' info 2 : ' || p_hist_rec.information2 || l_proc, 12);
4022 
4023 	p_cannot_cancel := FALSE;
4024   	open c_elmt (p_hist_rec.information1,
4025   			 to_date(p_hist_rec.information2, ghr_history_conv_rg.g_hist_date_format));
4026   	fetch c_elmt into l_c_elmt;
4027   	if c_elmt%notfound then
4028   		hr_utility.set_location( l_proc, 20);
4029   		close c_elmt;
4030   		p_cannot_cancel	:=	TRUE;
4031   	else
4032   		close c_elmt;
4033   		hr_utility.set_location( l_proc, 30);
4034 
4035 		hr_utility.set_location( 'effective date ' || p_hist_rec.information2, 31);
4036 		hr_utility.set_location( 'element entry id ' || l_c_elmt.element_entry_id, 32);
4037 		hr_utility.set_location( 'ovn ' || l_c_elmt.object_version_number, 33);
4038 
4039   		PY_element_entry_api.delete_element_entry(
4040  			p_datetrack_delete_mode		=>	nvl(p_del_mode, hr_api.g_delete_next_change),
4041   			p_effective_date		=>	to_date(p_hist_rec.information2, ghr_history_conv_rg.g_hist_date_format),
4042   			p_element_entry_id		=>	l_c_elmt.element_entry_id,
4043   			p_object_version_number		=>	l_c_elmt.object_version_number,
4044   			p_effective_start_date		=>	l_eff_start_date,
4045   			p_effective_end_date		=>	l_eff_end_date,
4046   			p_delete_warning			=>	l_del_warning);
4047 		if l_del_warning then
4048 			hr_utility.set_location( 'Warning ' || l_proc, 39);
4049 		end if;
4050 
4051   --added
4052   	end if;
4053  	hr_utility.set_location( 'Leaving : ' || l_proc, 40);
4054    exception when others then
4055              --
4056              -- Reset IN OUT parameters and set OUT parameters
4057              --
4058              p_cannot_cancel := null;
4059              raise;
4060  End delete_element_entry;
4061 
4062 -- ---------------------------------------------------------------------------
4063 -- |--------------------------< update_eleentval>--------------------------|
4064 -- ---------------------------------------------------------------------------
4065 -- {Start Of Comments}
4066 --
4067 -- Description:
4068 --	This procedure updates an element entry value.
4069 --
4070 -- Pre-Requisities:
4071 --   	None.
4072 --
4073 -- In Parameters:
4074 --	p_hist_pre			->	value to update element entry value to  (ghr_pa_history%rowtype).
4075 --
4076 -- Post Success:
4077 -- 	element entry value will have been updated.
4078 --
4079 -- Post Failure:
4080 --   	User message will have been displayed explaining why the element_entry_value couldn't be
4081 --	updated.
4082 --
4083 -- Developer Implementation Notes:
4084 --	Note that this is used in other packages as well. Changes to this procedure will have effects on the other
4085 --	packages using this procedure.
4086 --
4087 -- Access Status:
4088 --   Internal Development Use Only.
4089 --
4090 -- {End Of Comments}
4091 -- ---------------------------------------------------------------------------
4092 
4093 PROCEDURE update_eleentval(	p_hist_pre	in	ghr_pa_history%rowtype) IS
4094 	-- this cursor selects the input value name given the input_value_id and effective date.
4095 
4096         CURSOR 	c_input_value (cp_input_value_id     in number
4097           		       ,cp_eff_date          in date
4098 				,p_bg_id             in NUMBER)
4099 	IS
4100         		SELECT 	IPV.NAME
4101           		FROM		PAY_INPUT_VALUES_F IPV
4102          		WHERE  	TRUNC(cp_eff_date)
4103 			        BETWEEN IPV.EFFECTIVE_START_DATE AND IPV.EFFECTIVE_END_DATE
4104           		AND 	IPV.INPUT_VALUE_ID = cp_input_value_id;
4105 --			AND (IPV.BUSINESS_GROUP_ID IS NULL OR IPV.BUSINESS_GROUP_ID=P_BG_ID);
4106 
4107 	-- this cursor selects the element name given the element_entry_id and effective date.
4108 	CURSOR	c_element_name(	cp_element_entry_id 	in	number
4109 				,cp_eff_date		in	date
4110 				,p_bg_id                IN      number)
4111 	IS
4112 			SELECT 	ELT.ELEMENT_NAME
4113 			FROM		PAY_ELEMENT_TYPES_F	ELT,
4114 					PAY_ELEMENT_LINKS_F	ELL,
4115 					PAY_ELEMENT_ENTRIES_F	ELE
4116 			WHERE	TRUNC(cp_eff_date)	BETWEEN	ELT.EFFECTIVE_START_DATE
4117 									AND	ELT.EFFECTIVE_END_DATE
4118 			AND	TRUNC(cp_eff_date)	BETWEEN	ELL.EFFECTIVE_START_DATE
4119 									AND	ELL.EFFECTIVE_END_DATE
4120 			AND	TRUNC(cp_eff_date)	BETWEEN	ELE.EFFECTIVE_START_DATE
4121 									AND	ELE.EFFECTIVE_END_DATE
4122 			AND	ELE.ELEMENT_ENTRY_ID	= 	cp_element_entry_id
4123 			AND	ELL.ELEMENT_LINK_ID	=	ELE.ELEMENT_LINK_ID
4124 			AND	ELT.ELEMENT_TYPE_ID	= 	ELL.ELEMENT_TYPE_ID
4125                         AND    (ELT.BUSINESS_GROUP_ID is null OR ELT.BUSINESS_GROUP_ID = p_bg_id);
4126 
4127 	-- this cursor gets the assignment id given the primary key, efective_start_date, effective_end_date and
4128 	-- table name. (ghr_pa_history views are structured such that ghr_pa_history.information1 is always the primary
4129 	-- key, information2 is always the effective_start_date, and information3 is always the effective_end_date).
4130 	cursor	c_asgmt_id(	cp_information1	in	ghr_pa_history.information1%type,
4131 					cp_information2	in	ghr_pa_history.information2%type,
4132 					cp_information3	in	ghr_pa_history.information3%type,
4133 					cp_table_name	in	ghr_pa_history.table_name%type) IS
4134 			SELECT	ASSIGNMENT_ID
4135 			FROM		GHR_PA_HISTORY
4136 			WHERE		INFORMATION1	=	cp_information1
4137 				AND	INFORMATION2	= 	cp_information2
4138 				AND 	INFORMATION3	=	cp_information3
4139 				AND	TABLE_NAME		= 	cp_table_name
4140                         ORDER BY PROCESS_DATE DESC;  -- Line Added by ENUNEZ (04/11/2000) bug# 1235958
4141 
4142 	l_ipv_name		pay_input_values_f.name%type;
4143 	l_element_name	pay_element_types_f.element_name%type;
4144 	l_proc_warn		boolean;
4145 	l_proc		varchar2(30):='update_eleentval';
4146 	l_eff_date		date;
4147 	l_asg_id		number;
4148         l_value1 pay_element_entry_values_f.screen_entry_value%type;
4149 
4150   cursor c_ipv (ele_name       in varchar2
4151                ,input_name     in varchar2
4152                ,eff_date       in date
4153 		,p_bg_id         in number) is
4154              select ipv.uom
4155           from pay_element_types_f elt,
4156                pay_input_values_f ipv
4157          where trunc(eff_date) between elt.effective_start_date
4158                                    and elt.effective_end_date
4159            and trunc(eff_date) between ipv.effective_start_date
4160                                    and ipv.effective_end_date
4161            and elt.element_type_id = ipv.element_type_id
4162            and upper(elt.element_name) = upper(ele_name)
4163            and upper(ipv.name) = upper(input_name);
4164 --           and (elt.business_group_id is NULL or elt.business_group_id =p_bg_id);
4165 --
4166 -- Payroll Integration Changes
4167 --
4168 CURSOR Cur_bg(p_person_id NUMBER,
4169               p_eff_date DATE)
4170 IS
4171 SELECT business_group_id bg
4172 FROM   per_assignments_f
4173 WHERE  person_id = p_person_id
4174 AND    p_eff_Date between effective_start_Date
4175        AND effective_end_Date;
4176 
4177 ll_bg_id           NUMBER;
4178 l_new_element_name VARCHAR2(80);
4179 --*****************************************************************************
4180 --- to fix bug 3102049
4181 CURSOR cur_is_old_ele_name(p_ele_name IN VARCHAR2)
4182 IS
4183 SELECT pcv_information1 ele_name
4184 FROM   pqp_configuration_Values
4185 WHERE  pcv_information_category='PQP_FEDHR_ELEMENT'
4186 AND    business_group_id is NULL and legislation_code='US'
4187 AND    upper(pcv_information1)=upper(p_ele_name);
4188 
4189 l_ele_name        VARCHAR2(80);
4190 --*****************************************************************************
4191 --
4192 BEGIN
4193 --
4194   	hr_utility.set_location( 'Entering : ' || l_proc, 10);
4195   	hr_utility.set_location( 'information4 : ' || p_hist_pre.information4 || l_proc, 11);
4196   	hr_utility.set_location( 'Effective Date : ' || p_hist_pre.information2 || l_proc, 12);
4197  	hr_utility.set_location( 'Business Group id : ' || ll_bg_id, 100000002);
4198 --
4199 --Payroll Integration Changes
4200 --
4201 FOR bg_rec IN Cur_bg(p_hist_pre.person_id,
4202                      p_hist_pre.effective_date)
4203 LOOP
4204 ll_bg_id := bg_rec.bg;
4205 END LOOP;
4206 
4207 IF ll_bg_id is null THEN
4208 ll_bg_id := fnd_profile.value('PER_BUSINESS_GROUP_ID');
4209 END IF;
4210 
4211 
4212   	hr_utility.set_location( 'information4 : ' || p_hist_pre.information4 || l_proc, 11);
4213   	hr_utility.set_location( 'Effective Date : ' || p_hist_pre.information2 || l_proc, 12);
4214  	hr_utility.set_location( 'Business Group id : ' || ll_bg_id, 100000002);
4215 
4216 	l_eff_date := to_date(p_hist_pre.information2, ghr_history_api.g_hist_date_format);
4217 	hr_utility.set_location('Converted eff Date: ' || l_eff_date || l_proc,18);
4218 	-- get input value name.
4219 	open c_input_value(	cp_input_value_id	=>	p_hist_pre.information4,
4220 				cp_eff_date		=> 	l_eff_date,
4221 				p_bg_id  	        =>      ll_bg_id);
4222 	hr_utility.set_location('After open cursor: ' || l_proc,19);
4223 	fetch c_input_value into l_ipv_name;
4224 	hr_utility.set_location('After fetch cursor: ' || l_proc,21);
4225 	if c_input_value%NOTFOUND then
4226 	 	hr_utility.set_location( 'input_value_name notfound : ' || l_proc, 20);
4227 		close c_input_value;
4228 	      hr_utility.set_message(8301,'GHR_38270_INPUT_VALUE_NAME_NF');
4229 	      hr_utility.raise_error;
4230 	end if;
4231 	close c_input_value;
4232   	hr_utility.set_location( 'Open element name cursor: ' || l_proc, 30);
4233 	-- get element name.
4234 	open c_element_name(	cp_element_entry_id	=>  p_hist_pre.information5,
4235 				cp_eff_date		=>  l_eff_date,
4236 				p_bg_id                 =>  ll_bg_id);
4237 	hr_utility.set_location('Fetch element name cursor: ' || l_proc, 31);
4238 	fetch c_element_name into l_element_name;
4239 	hr_utility.set_location('After Fetch element name cursor: ' || l_proc, 32);
4240 	if c_element_name%NOTFOUND then
4241 	 	hr_utility.set_location( 'element_name notfound : ' || l_proc, 40);
4242 		close c_element_name;
4243 	      hr_utility.set_message(8301,'GHR_38271_ELEMENT_NAME_NOTFND');
4244 	      hr_utility.raise_error;
4245 	end if;
4246 	close c_element_name;
4247 	-- get assignment id.
4248 	open	c_asgmt_id	(cp_information1 =>	p_hist_pre.information1,
4249 				cp_information2	 =>	p_hist_pre.information2,
4250 				cp_information3	 =>	p_hist_pre.information3,
4251 				cp_table_name	 =>	ghr_history_api.g_eleevl_table);
4252 	fetch c_asgmt_id into l_asg_id;
4253 	if c_asgmt_id%NOTFOUND then
4254 	 	hr_utility.set_location( 'assignment_id notfound : ' || l_proc, 41);
4255 		close c_asgmt_id;
4256 	      hr_utility.set_message(8301,'GHR_38362_ASGMT_ID_NOTFND');
4257 	      hr_utility.raise_error;
4258 	end if;
4259 
4260 	hr_utility.set_location('Element Assignment ID: ' || p_hist_pre.assignment_id || l_proc, 36);
4261 	hr_utility.set_location('Element name: ' || l_element_name || l_proc, 37);
4262 	hr_utility.set_location('IPV Name: ' || l_ipv_name || l_proc, 38);
4263        -- UOM error for date input values
4264         hr_utility.set_location('p_hist_pre.information6: '
4265                    || p_hist_pre.information6 || l_proc, 38);
4266         l_value1 :=  p_hist_pre.information6;
4267         hr_utility.set_location('l_value1: ' || l_value1 || l_proc, 38);
4268         FOR c_ipv_rec IN c_ipv(l_element_name,l_ipv_name,l_eff_date,ll_bg_id) LOOP
4269           IF c_ipv_rec.uom = 'D'  THEN
4270             l_value1 := fnd_date.date_to_displaydate(fnd_date.canonical_to_date(l_value1));
4271             hr_utility.set_location('l_value1: ' || l_value1 || l_proc, 38);
4272           END IF;
4273         END LOOP;
4274 ---*****************************************************************************
4275 --- Check if the element name is new element name or hard coded ele name
4276 --- to fix bug 3102049
4277         FOR old_ele_name IN cur_is_old_ele_name(l_element_name)
4278         LOOP
4279            l_ele_name := old_ele_name.ele_name;
4280         END LOOP;
4281 
4282 	IF l_ele_name is not null THEN
4283           l_new_element_name := l_element_name;
4284 	ELSE
4285           l_new_element_name := pqp_fedhr_uspay_int_utils.return_old_element_name(
4286                       l_element_name,
4287 		      ll_bg_id,
4288 		      l_eff_date);
4289         END IF;
4290 --- to fix bug 3102049
4291 ---*****************************************************************************
4292       ghr_element_api.process_sf52_element
4293 	(p_assignment_id  	=>	l_asg_id
4294 	,p_element_name	      =>	l_new_element_name
4295 	,p_input_value_name1	=>	l_ipv_name
4296 	,p_value1		      => l_value1
4297 	,p_effective_date		=>   l_eff_date
4298 	,p_process_warning	=>	l_proc_warn
4299       );
4300 	/*To be included after Martin Reid's element api handles the create and update warning
4301 	if l_proc_warn = FALSE then
4302      	hr_utility.set_message(8301,'GHR_99999_FL_TO_UPD_ELEMENT_FOR_CANC');
4303      	hr_utility.raise_error;
4304   	end if;
4305 	*/
4306  	hr_utility.set_location( 'Leaving : ' || l_proc, 50);
4307 END update_eleentval;
4308 
4309 -- ---------------------------------------------------------------------------
4310 -- |--------------------------< delete_eleentval>-----------------------------|
4311 -- ---------------------------------------------------------------------------
4312 -- {Start Of Comments}
4313 --
4314 -- Description:
4315 --	This procedure deletes an element entry value from history table.
4316 --
4317 -- Pre-Requisities:
4318 --   	None.
4319 --
4320 -- In Parameters:
4321 --	p_hist_rec			->	element entry value to delete (ghr_pa_history%rowtype).
4322 --
4323 -- Post Success:
4324 -- 	element entry value will have been deleted rom history.
4325 --
4326 -- Post Failure:
4327 --	no failure conditions.
4328 --
4329 -- Developer Implementation Notes:
4330 --	None.
4331 --
4332 -- Access Status:
4333 --   Internal Development Use Only.
4334 --
4335 -- {End Of Comments}
4336 -- ---------------------------------------------------------------------------
4337 
4338   Procedure delete_eleentval( p_hist_rec in ghr_pa_history%rowtype) is
4339 	-- this cursor gets the rowid of the history_rec for the ghr_pa_history row passed
4340 	-- to us.
4341   	cursor c_hist is
4342   	select rowid row_id
4343   	from ghr_pa_history
4344   	where table_name			= ghr_history_api.g_eleevl_table	and
4345   		pa_request_id		= p_hist_rec.pa_request_id		and
4346   		nature_of_action_id	= p_hist_rec.nature_of_action_id
4347   	for update of table_name;
4348 	l_proc		varchar2(30):='delete_eleentval';
4349   Begin
4350   	hr_utility.set_location( 'Entering : ' || l_proc, 10);
4351   	for c_data in c_hist
4352   	loop
4353   		delete_hist_row( c_data.row_id);
4354   	end loop;
4355   	hr_utility.set_location( 'Leaving : ' || l_proc, 20);
4356   end delete_eleentval;
4357 
4358 -- ---------------------------------------------------------------------------
4359 -- |--------------------------< delete_peop_row>------------------------------|
4360 -- ---------------------------------------------------------------------------
4361 -- {Start Of Comments}
4362 --
4363 -- Description:
4364 --	This procedure deletes a row from per_people_f table.
4365 --
4366 -- Pre-Requisities:
4367 --   	None.
4368 --
4369 -- In Parameters:
4370 --	p_person_id			->	person_id to be deleted.
4371 --	p_dt_mode			->	datetrack delete mode.
4372 --	p_date_effective		->	effective date of delete.
4373 --
4374 -- Post Success:
4375 -- 	per_people_f row will have been deleted.
4376 --
4377 -- Post Failure:
4378 --	message will have been displayed to user explaining why the delete could not be completed.
4379 --
4380 -- Developer Implementation Notes:
4381 --	None.
4382 --
4383 -- Access Status:
4384 --   Internal Development Use Only.
4385 --
4386 -- {End Of Comments}
4387 -- ---------------------------------------------------------------------------
4388 
4389   PROCEDURE	delete_peop_row(	p_person_id		in	varchar2,
4390   					p_dt_mode		in	varchar2,
4391   					p_date_effective	in	date) IS
4392   	l_proc	varchar2(72) 	:= 	'delete_per_people_f_row';
4393   	l_ovn		number;
4394   	l_effective_start_date	date;
4395   	l_effective_end_date	date;
4396   	cursor	c_get_ovn	(cp_person_id	in	number,
4397   					cp_date_effective	in	date) 	is
4398   	SELECT object_version_number
4399   	FROM	PER_PEOPLE_F
4400   	WHERE person_id = cp_person_id
4401   		AND cp_date_effective between effective_start_date and effective_end_date;
4402   BEGIN
4403   	hr_utility.set_location( 'Entering : ' || l_proc, 10);
4404   	if (p_dt_mode = hr_api.g_delete_next_change) then
4405   		open c_get_ovn(p_person_id, p_date_effective -1);
4406   		fetch c_get_ovn into l_ovn;
4407   		if c_get_ovn%NOTFOUND then
4408 			-- can't delete without object_version_number.
4409 			close c_get_ovn;
4410 		      hr_utility.set_message(8301,'GHR_38213_PEOPLE_OVN_NOTFOUND');
4411 		      hr_utility.raise_error;
4412   			-- raise error;
4413   		end if;
4414   		per_per_del.del(
4415   			p_person_id			=>	p_person_id,
4416   			p_effective_start_date	=>	l_effective_start_date,
4417   			p_effective_end_date	=>	l_effective_end_date,
4418   			p_object_version_number	=>	l_ovn,
4419   			p_effective_date		=>	p_date_effective -1,
4420   			p_datetrack_mode		=>	p_dt_mode);
4421   	elsif (p_dt_mode = hr_api.g_zap) then
4422   		open c_get_ovn(p_person_id, p_date_effective );
4423   		fetch c_get_ovn into l_ovn;
4424   		if c_get_ovn%NOTFOUND then
4425   			-- raise error;
4426 			-- can't delete without object_version_number.
4427 			close c_get_ovn;
4428  		      hr_utility.set_message(8301,'GHR_38213_PEOPLE_OVN_NOTFOUND');
4429 		      hr_utility.raise_error;
4430   		end if;
4431   		per_per_del.del(
4432   			p_person_id			=>	p_person_id,
4433   			p_effective_start_date	=>	l_effective_start_date,
4434   			p_effective_end_date	=>	l_effective_end_date,
4435   			p_object_version_number	=>	l_ovn,
4436   			p_effective_date		=>	p_date_effective,
4437   			p_datetrack_mode		=>	p_dt_mode );
4438   	else
4439   		-- raise error, unacceptable datetrack mode
4440 	      hr_utility.set_message(8301,'GHR_38216_INVALID_DT_MODE_PPL');
4441 	      hr_utility.raise_error;
4442   	end if;
4443   	hr_utility.set_location( 'Leaving : ' || l_proc, 20);
4444   END delete_peop_row;
4445 
4446 --  Added Procedure delete_posn_row. ENUNEZ 11-MAY-2000, it didnt exist before as position used to
4447 --  be a non datetracked table.  Bug# 1252481
4448   PROCEDURE	delete_posn_row(	p_position_id		in	varchar2,
4449   					p_dt_mode		in	varchar2,
4450   					p_date_effective	in	date) IS
4451   	l_proc	varchar2(72) 	:= 	'delete_hr_all_positions_f_row';
4452   	l_ovn		number;
4453 	l_pos_ovn       number;
4454   	l_effective_start_date	date;
4455   	l_effective_end_date	date;
4456   	cursor	c_get_ovn	(cp_position_id	in	number,
4457   					cp_date_effective	in	date) 	is
4458   	SELECT object_version_number
4459   	FROM	HR_ALL_POSITIONS_F
4460   	WHERE position_id = cp_position_id
4461   		AND cp_date_effective between effective_start_date and effective_end_date;
4462 
4463         --Bug #12412678
4464 	cursor c1 (p_position_id in number)
4465 	    is
4466             select object_version_number
4467             from per_all_positions
4468             where position_id = p_position_id;
4469 
4470         -- Bug 3786467 Procedure to update position name in hr_all_positions_f_tl
4471 
4472           PROCEDURE ghr_regenerate_position_name(p_position_id IN hr_all_positions_f.position_id%type) IS
4473 			CURSOR c_position(c_position_id  IN hr_all_positions_f.position_id%type) is
4474             SELECT psf.position_definition_id
4475             FROM hr_all_positions_f psf
4476             WHERE position_id = c_position_id
4477             AND effective_end_date = hr_api.g_eot
4478             FOR UPDATE;
4479             --
4480             l_position_definition_id       number;
4481             BEGIN
4482               IF (p_position_id IS NOT NULL) THEN
4483             --
4484                 OPEN c_position(p_position_id);
4485                 FETCH c_position INTO l_position_definition_id;
4486             --
4487                 IF (c_position%FOUND) THEN
4488                   --
4489                    hr_pft_upd.upd_tl
4490                   ( p_language_code                => 'US'
4491                   , p_position_id                  => p_position_id
4492                   , p_position_definition_id       => l_position_definition_id
4493                   );
4494                   --
4495                 END IF;
4496             --
4497                 CLOSE c_position;
4498             --
4499           END IF;
4500         END ghr_regenerate_position_name;
4501   BEGIN
4502   	hr_utility.set_location( 'Entering : ' || l_proc, 10);
4503   	if (p_dt_mode = hr_api.g_delete_next_change) then
4504   		open c_get_ovn(p_position_id, p_date_effective -1);
4505   		fetch c_get_ovn into l_ovn;
4506   		if c_get_ovn%NOTFOUND then
4507 			-- can't delete without object_version_number.
4508 			close c_get_ovn;
4509 		      hr_utility.set_message(8301,'GHR_38504_POS_OVN_NOTFOUND');
4510 		      hr_utility.raise_error;
4511   			-- raise error;
4512   		end if;
4513   		hr_psf_del.del(
4514   			p_position_id			=>	p_position_id,
4515   			p_effective_start_date	=>	l_effective_start_date,
4516   			p_effective_end_date	=>	l_effective_end_date,
4517   			p_object_version_number	=>	l_ovn,
4518   			p_effective_date		=>	p_date_effective -1,
4519   			p_datetrack_mode		=>	p_dt_mode);
4520 		-- Regenerate Position Bug 3786467.
4521         hr_utility.set_location('Entered ghr regenerate position',15);
4522 		ghr_regenerate_position_name(p_position_id);
4523 
4524 		--Bug # 12412678 synchronizing the position in per_all_positions
4525                   update hr_all_positions_f
4526                   set copied_to_old_table_flag = 'N'
4527                   where position_id = p_position_id and
4528                   effective_end_date > p_date_effective - 1;
4529 
4530 		  per_refresh_position.refresh_single_position
4531                         (p_position_id           => p_position_id
4532                         ,p_effective_date        => p_date_effective
4533                         ,p_object_version_number => l_ovn
4534                         ,p_refresh_date          => trunc(sysdate));
4535 
4536    	elsif (p_dt_mode = hr_api.g_zap) then
4537   		open c_get_ovn(p_position_id, p_date_effective );
4538   		fetch c_get_ovn into l_ovn;
4539   		if c_get_ovn%NOTFOUND then
4540   			-- raise error;
4541 			-- can't delete without object_version_number.
4542 			close c_get_ovn;
4543  		      hr_utility.set_message(8301,'GHR_38504_POS_OVN_NOTFOUND');
4544 		      hr_utility.raise_error;
4545   		end if;
4546   		hr_psf_del.del(
4547   			p_position_id			=>	p_position_id,
4548   			p_effective_start_date	=>	l_effective_start_date,
4549   			p_effective_end_date	=>	l_effective_end_date,
4550   			p_object_version_number	=>	l_ovn,
4551   			p_effective_date		=>	p_date_effective,
4552   			p_datetrack_mode		=>	p_dt_mode );
4553 		-- Regenerate Position Bug 3786467
4554         hr_utility.set_location('Entered ghr regenerate position',15);
4555 		ghr_regenerate_position_name(p_position_id);
4556 
4557 		--Bug # 12412678 synchronizing the position in per_all_positions
4558                    open c1(p_position_id);
4559                    fetch c1 into l_pos_ovn;
4560                    close c1;
4561 
4562                    per_pos_shd.lck(p_position_id           => p_position_id
4563                                   ,p_object_version_number => l_pos_ovn);
4564                    -- delete row from per_all_positions
4565 
4566                    per_pos_del.del(p_position_id           => p_position_id
4567                                   ,p_object_version_number => l_pos_ovn);
4568 
4569   	else
4570   		-- raise error, unacceptable datetrack mode
4571 	      hr_utility.set_message(8301,'GHR_38216_INVALID_DT_MODE_PPL');
4572 	      hr_utility.raise_error;
4573   	end if;
4574   	hr_utility.set_location( 'Leaving : ' || l_proc, 20);
4575   END delete_posn_row;
4576 
4577 -- ---------------------------------------------------------------------------
4578 -- |--------------------------< delete_asgn_row>------------------------------|
4579 -- ---------------------------------------------------------------------------
4580 -- {Start Of Comments}
4581 --
4582 -- Description:
4583 --	This procedure deletes a row from per_people_f table.
4584 --
4585 -- Pre-Requisities:
4586 --   	None.
4587 --
4588 -- In Parameters:
4589 --	p_assignment_id		->	assignment_id to be deleted.
4590 --	p_dt_mode			->	datetrack delete mode.
4591 --	p_date_effective		->	effective date of delete.
4592 --
4593 -- Post Success:
4594 -- 	per_assignments_f row will have been deleted.
4595 --
4596 -- Post Failure:
4597 --	message will have been displayed to user explaining why the delete could not be completed.
4598 --
4599 -- Developer Implementation Notes:
4600 --	None.
4601 --
4602 -- Access Status:
4603 --   Internal Development Use Only.
4604 --
4605 -- {End Of Comments}
4606 -- ---------------------------------------------------------------------------
4607 
4608   PROCEDURE	delete_asgn_row(	p_assignment_id	in	varchar2,
4609   					p_dt_mode		in	varchar2,
4610   					p_date_effective	in	date) IS
4611   	l_proc	varchar2(72) 	:= 	'delete_per_assignments_f_row';
4612   	l_ovn		number;
4613   	l_effective_start_date		date;
4614   	l_effective_end_date		date;
4615   	l_validation_start_date		date;
4616   	l_validation_end_date		date;
4617   	l_business_group_id		number;
4618   	l_org_now_no_manager_warning  boolean;
4619 	-- this cursor gets the object_version_number given the assignment_id and effective_date.
4620   	cursor	c_get_ovn	(cp_assignment_id	in	number,
4621   					cp_date_effective	in	date) 	is
4622   	SELECT object_version_number
4623   	FROM	PER_ASSIGNMENTS_F
4624   	WHERE assignment_id = cp_assignment_id
4625  		AND cp_date_effective between effective_start_date and effective_end_date;
4626 
4627 Cursor Cur_proposal_exists (p_assignment_id IN NUMBER,
4628                             p_eff_date IN DATE) is
4629 Select ppp.pay_proposal_id       proposal_id
4630        ,ppp.object_version_number ovn
4631 from   per_pay_proposals ppp
4632 where  ppp.assignment_id = p_assignment_id
4633 and    change_date  <= p_eff_date;
4634 
4635 l_pay_proposal_id          NUMBER;
4636 -- sal admin fields
4637 l_sal_admin_ovn number;
4638 
4639 l_payroll_warn boolean;
4640 l_approve_warn  boolean;
4641 l_sal_warn  boolean;
4642 l_date_warn  boolean;
4643 --
4644 l_asg_del_ovn                  NUMBER;
4645 --l_org_now_no_manager_warning   BOOLEAN;
4646 l_payroll_value                NUMBER;
4647 l_ele_entry_id                 NUMBER;
4648 ll_payroll_value               NUMBER;
4649 ll_value                       NUMBER;
4650 l_pay_intg                     BOOLEAN:=FALSE;
4651 
4652   BEGIN
4653   	hr_utility.set_location( 'Entering : ' || l_proc, 10);
4654   	if (p_dt_mode = hr_api.g_delete_next_change) then
4655   		open c_get_ovn(p_assignment_id, p_date_effective -1);
4656   		fetch c_get_ovn into l_ovn;
4657   		if c_get_ovn%NOTFOUND then
4658 			-- can't delete without object_version_number.
4659   			-- raise error;
4660 			close c_get_ovn;
4661   		      hr_utility.set_message(8301,'GHR_38215_ASSG_OVN_NOTFOUND');
4662 		      hr_utility.raise_error;
4663   		end if;
4664   		per_asg_del.del(
4665   			p_assignment_id			=>	p_assignment_id,
4666   			p_effective_start_date		=>	l_effective_start_date,
4667   			p_effective_end_date		=>	l_effective_end_date,
4668   			p_validation_start_date		=>	l_validation_start_date,
4669   			p_validation_end_date		=>	l_validation_end_date,
4670   			p_business_group_id		=>	l_business_group_id,
4671   			p_object_version_number		=>	l_ovn,
4672   			p_effective_date			=>	p_date_effective -1,
4673   			p_datetrack_mode			=>	p_dt_mode,
4674   			p_org_now_no_manager_warning	=>  	l_org_now_no_manager_warning  );
4675   	elsif (p_dt_mode = hr_api.g_zap) then
4676   		open c_get_ovn(p_assignment_id, p_date_effective );
4677   		fetch c_get_ovn into l_ovn;
4678   		if c_get_ovn%NOTFOUND then
4679 			-- can't delete without object_version_number.
4680   			-- raise error;
4681 			close c_get_ovn;
4682   		      hr_utility.set_message(8301,'GHR_38215_ASSG_OVN_NOTFOUND');
4683 		      hr_utility.raise_error;
4684   		end if;
4685        -- Payroll Integration Changes
4686        ----**********************************************************************
4687        --           CHECK # :- Existence of PAYROLL Product
4688        ----**********************************************************************
4689        IF (hr_utility.chk_product_install('GHR','US')  = TRUE
4690          and hr_utility.chk_product_install('PAY', 'US') = TRUE
4691          and fnd_profile.value('HR_USER_TYPE')='INT')
4692        THEN
4693          l_pay_intg:=TRUE;
4694        ELSE
4695          l_pay_intg:=FALSE;
4696        END IF;
4697        ----**********************************************************************
4698         IF l_pay_intg  THEN
4699 
4700 	  For Proposal_rec IN Cur_proposal_exists
4701              (p_assignment_id,p_date_effective-1)
4702           Loop
4703             l_pay_proposal_id   := proposal_rec.proposal_id;
4704             l_sal_admin_ovn     := proposal_rec.ovn;
4705           End Loop;
4706 
4707           hr_utility.set_location('l_hist basic value not null '||ll_value,100000);
4708 
4709           per_asg_del.del(
4710         	  p_assignment_id              => p_assignment_id,
4711 	          p_effective_start_date      => l_effective_start_date,
4712 	          p_effective_end_date        => l_effective_end_date,
4713 	          p_validation_start_date      => l_validation_start_date,
4714 	          p_validation_end_date        => l_validation_end_date,
4715 	          p_business_group_id          => l_business_group_id,
4716 	          p_object_version_number      => l_ovn,
4717 	          p_effective_date            =>  (p_date_effective -1),
4718 	          p_datetrack_mode            => 'DELETE_NEXT_CHANGE',
4719 	          p_org_now_no_manager_warning => l_org_now_no_manager_warning  );
4720 
4721 	 /* hr_maintain_proposal_api.delete_salary_proposal
4722                 (
4723                 p_pay_proposal_id      => l_pay_proposal_id ,
4724                 p_business_group_id    => l_business_group_id         ,
4725                 p_object_version_number => l_sal_admin_ovn            ,
4726                 p_validate              => FALSE            ,
4727                 p_salary_warning        => l_sal_warn
4728                 ); */
4729 
4730             per_pay_proposals_populate.GET_ELEMENT_ID(
4731                            p_assignment_id      => p_assignment_id,
4732                            p_business_group_id  => l_business_group_id,
4733                            p_change_date        => p_date_effective -1,
4734                            p_payroll_value      => l_payroll_value,
4735                            p_element_entry_id   => l_ele_entry_id );
4736 
4737              hr_utility.set_location(' The Entry value '||ll_payroll_value,12345);
4738              hr_utility.set_location(' The Entry id '||l_ele_entry_id,12345);
4739 
4740              hr_entry_api.delete_element_entry
4741 	                   ('DELETE_NEXT_CHANGE',
4742 	                    p_date_effective - 1,
4743 	                    l_ele_entry_id  );
4744 
4745           ELSE
4746   		per_asg_del.del(
4747   			p_assignment_id		=>	p_assignment_id,
4748   			p_effective_start_date	=>	l_effective_start_date,
4749   			p_effective_end_date	=>	l_effective_end_date,
4750   			p_validation_start_date	=>	l_validation_start_date,
4751   			p_validation_end_date	=>	l_validation_end_date,
4752   			p_business_group_id	=>	l_business_group_id,
4753   			p_object_version_number	=>	l_ovn,
4754   			p_effective_date		=>	p_date_effective,
4755    			p_datetrack_mode		=>	p_dt_mode,
4756  			p_org_now_no_manager_warning	=>  	l_org_now_no_manager_warning  );
4757           END IF;
4758   	else
4759   		-- raise error, unacceptable datetrack mode
4760   		hr_utility.set_message(8301,'GHR_38214_INVALID_DT_MODE_ASSG');
4761 		hr_utility.raise_error;
4762   	end if;
4763   	hr_utility.set_location( 'Leaving : ' || l_proc, 20);
4764   END delete_asgn_row;
4765 
4766 -- ---------------------------------------------------------------------------
4767 -- |--------------------------< delete_peopei_row>----------------------------|
4768 -- ---------------------------------------------------------------------------
4769 -- {Start Of Comments}
4770 --
4771 -- Description:
4772 --	This procedure deletes a row from per_people_extra_info table.
4773 --
4774 -- Pre-Requisities:
4775 --   	None.
4776 --
4777 -- In Parameters:
4778 --	p_person_extra_info_id	->	person_extra_info_id to be deleted.
4779 --
4780 -- Post Success:
4781 -- 	per_person_extra_info row will have been deleted.
4782 --
4783 -- Post Failure:
4784 --	message will have been displayed to user explaining why the delete could not be completed.
4785 --
4786 -- Developer Implementation Notes:
4787 --	None.
4788 --
4789 -- Access Status:
4790 --   Internal Development Use Only.
4791 --
4792 -- {End Of Comments}
4793 -- ---------------------------------------------------------------------------
4794 
4795   PROCEDURE	delete_peopei_row(	p_person_extra_info_id	in	varchar2) IS
4796   	l_proc	varchar2(72) 	:= 	'delete_per_people_extra_info_row';
4797   	l_ovn		number;
4798   	cursor	c_get_ovn	(cp_person_extra_info_id	in	number) 	is
4799   	SELECT object_version_number
4800   	FROM	PER_PEOPLE_EXTRA_INFO
4801   	WHERE person_extra_info_id = cp_person_extra_info_id ;
4802  BEGIN
4803   	hr_utility.set_location( 'Entering : ' || l_proc, 10);
4804   	open c_get_ovn(p_person_extra_info_id);
4805   	fetch c_get_ovn into l_ovn;
4806   	if c_get_ovn%NOTFOUND then
4807 		-- can't do delete without object_version_number.
4808 		close c_get_ovn;
4809 		return;
4810 		-- if record is not there means it has already been deleted thru core form.
4811 	      -- hr_utility.set_message(8301,'GHR_38217_PEI_OVN_NOTFOUND');
4812 	      -- hr_utility.raise_error;
4813   	end if;
4814   	pe_pei_del.del(
4815   		p_person_extra_info_id	=>	p_person_extra_info_id,
4816   		p_object_version_number	=>	l_ovn);
4817   	hr_utility.set_location( 'Leaving : ' || l_proc, 20);
4818   END delete_peopei_row;
4819 
4820 -- ---------------------------------------------------------------------------
4821 -- |--------------------------< delete_asgnei_row>----------------------------|
4822 -- ---------------------------------------------------------------------------
4823 -- {Start Of Comments}
4824 --
4825 -- Description:
4826 --	This procedure deletes a row from per_assignment_extra_info table.
4827 --
4828 -- Pre-Requisities:
4829 --   	None.
4830 --
4831 -- In Parameters:
4832 --	p_assignment_extra_info_id	->	assignment_extra_info_id to be deleted.
4833 --
4834 -- Post Success:
4835 -- 	per_assignment_extra_info row will have been deleted.
4836 --
4837 -- Post Failure:
4838 --	message will have been displayed to user explaining why the delete could not be completed.
4839 --
4840 -- Developer Implementation Notes:
4841 --	None.
4842 --
4843 -- Access Status:
4844 --   Internal Development Use Only.
4845 --
4846 -- {End Of Comments}
4847 -- ---------------------------------------------------------------------------
4848 
4849   PROCEDURE	delete_asgnei_row(	p_assignment_extra_info_id	in	varchar2) IS
4850   	l_proc	varchar2(72) 	:= 	'delete_per_assignment_extra_info_row';
4851   	l_ovn		number;
4852 	-- this cursor gets the object_version_number for the assignment_extra_info_id passed.
4853   	cursor	c_get_ovn	(cp_assignment_extra_info_id	in	number) 	is
4854   	SELECT object_version_number
4855   	FROM	PER_ASSIGNMENT_EXTRA_INFO
4856   	WHERE assignment_extra_info_id = cp_assignment_extra_info_id ;
4857   BEGIN
4858   	hr_utility.set_location( 'Entering : ' || l_proc, 10);
4859   	open c_get_ovn(p_assignment_extra_info_id);
4860   	fetch c_get_ovn into l_ovn;
4861   	if c_get_ovn%NOTFOUND then
4862 		-- can't do delete without object_version_number.
4863 		close c_get_ovn;
4864 		return;
4865 		-- if record is not there means it has already been deleted thru core form.
4866 	      -- hr_utility.set_message(8301,'GHR_38218_ASGEI_OVN_NOTFOUND');
4867 	      -- hr_utility.raise_error;
4868   	end if;
4869   	pe_aei_del.del(
4870   		p_assignment_extra_info_id	=>	p_assignment_extra_info_id,
4871   		p_object_version_number		=>	l_ovn);
4872   	hr_utility.set_location( 'Leaving : ' || l_proc, 20);
4873   END delete_asgnei_row;
4874 
4875 -- ---------------------------------------------------------------------------
4876 -- |--------------------------< delete_posnei_row>----------------------------|
4877 -- ---------------------------------------------------------------------------
4878 -- {Start Of Comments}
4879 --
4880 -- Description:
4881 --	This procedure deletes a row from per_position_extra_info table.
4882 --
4883 -- Pre-Requisities:
4884 --   	None.
4885 --
4886 -- In Parameters:
4887 --	p_position_extra_info_id	->	position_extra_info_id to be deleted.
4888 --
4889 -- Post Success:
4890 -- 	per_position_extra_info row will have been deleted.
4891 --
4892 -- Post Failure:
4893 --	message will have been displayed to user explaining why the delete could not be completed.
4894 --
4895 -- Developer Implementation Notes:
4896 --	None.
4897 --
4898 -- Access Status:
4899 --   Internal Development Use Only.
4900 --
4901 -- {End Of Comments}
4902 -- ---------------------------------------------------------------------------
4903   PROCEDURE	delete_posnei_row(	p_position_extra_info_id	in	varchar2) IS
4904   	l_proc	varchar2(72) 	:= 	'delete_per_position_extra_info_row';
4905   	l_ovn		number;
4906 	-- this cursor gets the object_version_number for the position_extra_info_id passed.
4907   	cursor	c_get_ovn	(cp_position_extra_info_id	in	number) 	is
4908   	SELECT object_version_number
4909   	FROM	PER_POSITION_EXTRA_INFO
4910   	WHERE position_extra_info_id = cp_position_extra_info_id ;
4911   BEGIN
4912   	hr_utility.set_location( 'Entering : ' || l_proc, 10);
4913   	open c_get_ovn(p_position_extra_info_id);
4914   	fetch c_get_ovn into l_ovn;
4915   	if c_get_ovn%NOTFOUND then
4916 		-- can't do delete without object_version_number.
4917 		close c_get_ovn;
4918 		return;
4919 		-- if record is not there means it has already been deleted thru core form.
4920 	      -- hr_utility.set_message(8301,'GHR_38218_ASGEI_OVN_NOTFOUND');
4921 	      -- hr_utility.raise_error;
4922   	end if;
4923   	pe_poi_del.del(
4924   		p_position_extra_info_id	=>	p_position_extra_info_id,
4925   		p_object_version_number		=>	l_ovn);
4926   	hr_utility.set_location( 'Leaving : ' || l_proc, 20);
4927   END delete_posnei_row;
4928 
4929 -- ---------------------------------------------------------------------------
4930 -- |--------------------------< delete_address_row>----------------------------|
4931 -- ---------------------------------------------------------------------------
4932 -- {Start Of Comments}
4933 --
4934 -- Description:
4935 --	This procedure deletes a row from per_addresses table.
4936 --
4937 -- Pre-Requisities:
4938 --   	None.
4939 --
4940 -- In Parameters:
4941 --	p_address_id	->	address_id to be deleted.
4942 --
4943 -- Post Success:
4944 -- 	per_addresses row will have been deleted.
4945 --
4946 -- Post Failure:
4947 --	message will have been displayed to user explaining why the delete could not be completed.
4948 --
4949 -- Developer Implementation Notes:
4950 --	None.
4951 --
4952 -- Access Status:
4953 --   Internal Development Use Only.
4954 --
4955 -- {End Of Comments}
4956 -- ---------------------------------------------------------------------------
4957 
4958   PROCEDURE	delete_address_row(	p_address_id	in	varchar2) IS
4959 
4960   	l_proc	varchar2(72) 	:= 	'delete_per_addresses_row';
4961   	l_ovn		number;
4962   	cursor	c_get_ovn	(cp_address_id	in	number) 	is
4963   	SELECT object_version_number
4964   	FROM	PER_ADDRESSES
4965   	WHERE address_id = cp_address_id ;
4966 
4967   BEGIN
4968   	hr_utility.set_location( 'Entering : ' || l_proc, 10);
4969   	open c_get_ovn(p_address_id);
4970   	fetch c_get_ovn into l_ovn;
4971   	if c_get_ovn%NOTFOUND then
4972 		-- can't do delete without object_version_number.
4973 		close c_get_ovn;
4974 		return;
4975 		-- if record is not there means it has already been deleted thru core form.
4976 	      -- hr_utility.set_message(8301,'GHR_38220_ADDRESS_OVN_NOTFOUND');
4977 	      -- hr_utility.raise_error;
4978   	end if;
4979         hr_utility.set_location('*Deleting p_address_id:' || p_address_id, 12);
4980   	per_add_del.del(
4981   		p_address_id			=>	p_address_id,
4982   		p_object_version_number		=>	l_ovn);
4983   	hr_utility.set_location( 'Leaving : ' || l_proc, 20);
4984   END delete_address_row;
4985 
4986 -- ---------------------------------------------------------------------------
4987 -- |--------------------------< delete_person_analyses_row>-------------------|
4988 -- ---------------------------------------------------------------------------
4989 -- {Start Of Comments}
4990 --
4991 -- Description:
4992 --	This procedure deletes a row from per_person_analyses table.
4993 --
4994 -- Pre-Requisities:
4995 --   	None.
4996 --
4997 -- In Parameters:
4998 --	p_person_analysis_id	->	person_analysis_id to be deleted.
4999 --
5000 -- Post Success:
5001 -- 	per_person_analyses row will have been deleted.
5002 --
5003 -- Post Failure:
5004 --	message will have been displayed to user explaining why the delete could not be completed.
5005 --
5006 -- Developer Implementation Notes:
5007 --	None.
5008 --
5009 -- Access Status:
5010 --   Internal Development Use Only.
5011 --
5012 -- {End Of Comments}
5013 -- ---------------------------------------------------------------------------
5014 
5015   PROCEDURE delete_person_analyses_row ( p_person_analysis_id	in	number) is
5016 
5017   	l_proc	varchar2(72) 	:= 	'delete_person_analyses_row';
5018   	l_ovn		number;
5019   	cursor	c_get_ovn	(cp_person_analysis_id	in	number) 	is
5020   	SELECT object_version_number
5021   	FROM	PER_PERSON_ANALYSES
5022   	WHERE person_analysis_id = cp_person_analysis_id ;
5023 
5024   Begin
5025   	hr_utility.set_location( 'Entering : ' || l_proc, 10);
5026   	open c_get_ovn(p_person_analysis_id);
5027   	fetch c_get_ovn into l_ovn;
5028   	if c_get_ovn%NOTFOUND then
5029 		-- can't do delete without object_version_number.
5030   		-- raise error;
5031 		close c_get_ovn;
5032 		return;
5033 		-- if record is not there means it has already been deleted thru core form.
5034 	      -- hr_utility.set_message(8301,'GHR_38272_PERSON_ANALYSE_OV_NF');
5035 	      -- hr_utility.raise_error;
5036   	end if;
5037 
5038 	per_pea_del.del(
5039 		p_person_analysis_id	=>	p_person_analysis_id,
5040 		p_object_version_number	=>	l_ovn);
5041 
5042   End delete_person_analyses_row;
5043 
5044 -- ---------------------------------------------------------------------------
5045 -- |--------------------------< delete_appl_row>------------------------------|
5046 -- ---------------------------------------------------------------------------
5047 -- {Start Of Comments}
5048 --
5049 -- Description:
5050 --	This procedure deletes a row from the corresponding application table.
5051 --
5052 -- Pre-Requisities:
5053 --   	None.
5054 --
5055 -- In Parameters:
5056 --	p_table_name	->	name of table to be deleted from.
5057 --	p_table_pk_id	->	pk_id of row to be deleted.
5058 --	p_dt_mode		->	datetrack delete mode.
5059 --	p_date_effective	->	effective date of delete.
5060 --
5061 -- Post Success:
5062 -- 	specified application table row will have been deleted.
5063 --
5064 -- Post Failure:
5065 --	message will have been displayed to user explaining why the delete could not be completed.
5066 --
5067 -- Developer Implementation Notes:
5068 --	None.
5069 --
5070 -- Access Status:
5071 --   Internal Development Use Only.
5072 --
5073 -- {End Of Comments}
5074 -- ---------------------------------------------------------------------------
5075   PROCEDURE	delete_appl_row(	p_table_name	in	varchar2,
5076   					p_table_pk_id	in	varchar2,
5077   					p_dt_mode		in	varchar2,
5078   					p_date_effective	in	date) IS
5079   	l_proc	varchar2(72) 	:= 	'delete_appl_row';
5080   BEGIN
5081   	hr_utility.set_location( 'Entering : ' || l_proc, 10);
5082         hr_utility.set_location('     P_TABLE_NAME:' || p_table_name, 15);
5083   	if (lower(p_table_name) = lower(ghr_history_api.g_peop_table)) then
5084   		delete_peop_row(		p_person_id	=>	p_table_pk_id,
5085   						p_dt_mode		=>	p_dt_mode,
5086   						p_date_effective	=>	p_date_effective);
5087         -- Added Handling of Position table. Bug# 1252481 11-MAY-2000
5088   	elsif (lower(p_table_name) = lower(ghr_history_api.g_posn_table)) then
5089   		delete_posn_row(		p_position_id	=>	p_table_pk_id,
5090   						p_dt_mode		=>	p_dt_mode,
5091   						p_date_effective	=>	p_date_effective);
5092   	elsif (lower(p_table_name) = lower(ghr_history_api.g_asgn_table)) then
5093   		delete_asgn_row(		p_assignment_id	=>	p_table_pk_id,
5094   						p_dt_mode		=>	p_dt_mode,
5095   						p_date_effective	=>	p_date_effective);
5096   	elsif (lower(p_table_name) = lower(ghr_history_api.g_peopei_table)) then
5097   		delete_peopei_row(	p_person_extra_info_id	=>	p_table_pk_id);
5098   	elsif (lower(p_table_name) = lower(ghr_history_api.g_asgnei_table)) then
5099   		delete_asgnei_row(	p_assignment_extra_info_id	=>	p_table_pk_id);
5100   	elsif (lower(p_table_name) = lower(ghr_history_api.g_posnei_table)) then
5101   		delete_posnei_row(	p_position_extra_info_id	=>	p_table_pk_id);
5102   	elsif (lower(p_table_name) = lower(ghr_history_api.g_addres_table)) then
5103   		delete_address_row(	p_address_id	=>	p_table_pk_id);
5104 	elsif (lower(p_table_name) = lower(ghr_history_api.g_perana_table)) then
5105   		delete_person_analyses_row(	p_person_analysis_id	=>	p_table_pk_id);
5106   	end if;
5107   	hr_utility.set_location( 'Leaving : ' || l_proc, 20);
5108   END delete_appl_row;
5109 
5110 -- ---------------------------------------------------------------------------
5111 -- |--------------------------< undo_mark_cancel>------------------------------|
5112 -- ---------------------------------------------------------------------------
5113 -- {Start Of Comments}
5114 --
5115 -- Description:
5116 --	This procedure makes the parent sf52 available for cancellation/correction. This
5117 --	is needed in the case where a correction is cancelled and the parent sf52 has
5118 --	been marked as unavailable for correction/cancellation. This procedure will mark it
5119 --	available again.
5120 --
5121 -- Pre-Requisities:
5122 --   	None.
5123 --
5124 -- In Parameters:
5125 --	p_sf52_data		->	ghr_pa_requests row of the cancellation being processed.
5126 --
5127 -- Post Success:
5128 -- 	If this is a cancellation of correction, the parent sf52 will have been marked as
5129 --	available for cancellation/correction again.
5130 --
5131 -- Post Failure:
5132 --	Exception will have ben raised and message displayed.
5133 --
5134 -- Developer Implementation Notes:
5135 --	None.
5136 --
5137 -- Access Status:
5138 --   Internal Development Use Only.
5139 --
5140 -- {End Of Comments}
5141 -- ---------------------------------------------------------------------------
5142 
5143 Procedure Undo_Mark_Cancel ( p_sf52_data  in  ghr_pa_requests%rowtype) is
5144 	cursor get_req (cp_pa_request_id number) is
5145 	select
5146 		pa_request_id,
5147 		altered_pa_request_id,
5148 		first_noa_id,
5149 		second_noa_id,
5150 		object_version_number ovn
5151 	from ghr_pa_requests
5152 	where pa_request_id = cp_pa_request_id;
5153 	l_proc		varchar2(30):='Undo_Mark_Cancel';
5154 	l_sf52_data	get_req%rowtype;
5155 Begin
5156 	hr_utility.set_location( 'Entering ' || l_proc, 10);
5157 	if p_sf52_data.altered_pa_request_id is not null then
5158 		-- if it is a correction/cancellation it'll have altered_pa_request_id
5159 		hr_utility.set_location( l_proc, 20);
5160 		-- fetch cancelled/corrected pa_request record
5161 		open get_req( p_sf52_data.altered_pa_request_id);
5162 		fetch get_req into l_sf52_data;
5163 		if get_req%notfound then
5164 			-- this must never happen until data has been corrupted.
5165 			hr_utility.set_location( 'Error ' || l_proc, 30);
5166 			hr_utility.set_message(8301 , 'GHR_38278_PARENT_SF52_NOT_FND');
5167 			hr_utility.raise_error;
5168 		end if;
5169 		close get_req;
5170 		-- Only if a correction is canceled following logic must be executed to mark
5171 		-- parent SF52 available for cancellation/correction.
5172 		if l_sf52_data.altered_pa_request_id is not null then
5173 			hr_utility.set_location( l_proc, 40);
5174 			open get_req(l_sf52_data.altered_pa_request_id);
5175 			fetch get_req into l_sf52_data;
5176 			if get_req%notfound then
5177 				hr_utility.set_location( 'Error ' || l_proc , 50);
5178 				hr_utility.set_message(8301 , 'GHR_38278_PARENT_SF52_NOT_FND');
5179 				hr_utility.raise_error;
5180 			end if;
5181 			close get_req;
5182 			if l_sf52_data.first_noa_id = p_sf52_data.second_noa_id then
5183 				hr_utility.set_location( l_proc, 60);
5184 				ghr_par_upd.upd
5185 				(p_pa_request_id                 =>  l_sf52_data.pa_request_id,
5186 				 p_object_version_number         =>  l_sf52_data.ovn,
5187 				 p_first_noa_cancel_or_correct   =>  NULL,
5188 				 p_first_noa_pa_request_id       =>  NULL
5189 				);
5190 			elsif l_sf52_data.second_noa_id = p_sf52_data.second_noa_id then
5191 				hr_utility.set_location( l_proc, 70);
5192 				ghr_par_upd.upd
5193 				(p_pa_request_id                 =>  l_sf52_data.pa_request_id,
5194 				 p_object_version_number         =>  l_sf52_data.ovn,
5195 				 p_second_noa_cancel_or_correct  =>  NULL,
5196 				 p_second_noa_pa_request_id      =>  NULL
5197 				);
5198 			else
5199 				-- This must never be the case where parent SF52 has different
5200 				-- NOACs then the correction/cancellation.
5201 				hr_utility.set_location( l_proc, 80);
5202 				hr_utility.set_message(8301 , 'GHR_38279_PARENT_NOA_IS_DIFF');
5203 				hr_utility.raise_error;
5204 				null;
5205 			end if;
5206 		end if;
5207 		hr_utility.set_location( l_proc, 90);
5208 	end if;
5209 	hr_utility.set_location( 'Leaving ' || l_proc, 100);
5210 
5211 End Undo_Mark_Cancel;
5212 
5213 Procedure convert_shadow_to_sf52 (
5214 	p_shadow	 in   ghr_pa_request_shadow%rowtype,
5215 	p_sf52 out nocopy ghr_pa_requests%rowtype) is
5216 l_sf52  ghr_pa_requests%rowtype;
5217 Begin
5218 
5219     l_sf52                                   := p_sf52;
5220     p_sf52.pa_request_id                     := p_shadow.pa_request_id                ;
5221     p_sf52.academic_discipline               := p_shadow.academic_discipline          ;
5222     p_sf52.annuitant_indicator               := p_shadow.annuitant_indicator          ;
5223     p_sf52.appropriation_code1               := p_shadow.appropriation_code1          ;
5224     p_sf52.appropriation_code2               := p_shadow.appropriation_code2          ;
5225     p_sf52.bargaining_unit_status            := p_shadow.bargaining_unit_status       ;
5226     p_sf52.citizenship                       := p_shadow.citizenship                  ;
5227 --    p_sf52.duty_station_code                 := p_shadow.duty_station_code            ;
5228     p_sf52.duty_station_location_id          := p_shadow.duty_station_location_id     ;
5229     p_sf52.education_level                   := p_shadow.education_level              ;
5230 --    p_sf52.employee_assignment_id            := p_shadow.employee_assignment_id       ;
5231     p_sf52.fegli                             := p_shadow.fegli                        ;
5232     p_sf52.flsa_category                     := p_shadow.flsa_category                ;
5233     p_sf52.forwarding_address_line1          := p_shadow.forwarding_address_line1 ;
5234     p_sf52.forwarding_address_line2          := p_shadow.forwarding_address_line2 ;
5235     p_sf52.forwarding_address_line3          := p_shadow.forwarding_address_line3  ;
5236     p_sf52.forwarding_country_short_name     := p_shadow.forwarding_country_short_name;
5237     p_sf52.forwarding_postal_code            := p_shadow.forwarding_postal_code       ;
5238     p_sf52.forwarding_region_2               := p_shadow.forwarding_region_2          ;
5239     p_sf52.forwarding_town_or_city           := p_shadow.forwarding_town_or_city      ;
5240     p_sf52.functional_class                  := p_shadow.functional_class             ;
5241     p_sf52.part_time_hours                   := p_shadow.part_time_hours              ;
5242     p_sf52.pay_rate_determinant              := p_shadow.pay_rate_determinant         ;
5243     p_sf52.position_occupied                 := p_shadow.position_occupied            ;
5244     p_sf52.retirement_plan                   := p_shadow.retirement_plan              ;
5245     p_sf52.service_comp_date                 := p_shadow.service_comp_date            ;
5246     p_sf52.supervisory_status                := p_shadow.supervisory_status           ;
5247     p_sf52.tenure                            := p_shadow.tenure                       ;
5248     p_sf52.to_ap_premium_pay_indicator       := p_shadow.to_ap_premium_pay_indicator  ;
5249     p_sf52.to_auo_premium_pay_indicator      := p_shadow.to_auo_premium_pay_indicator ;
5250 --    p_sf52.to_au_overtime                    := p_shadow.to_au_overtime               ;
5251 --    p_sf52.to_availability_pay               := p_shadow.to_availability_pay          ;
5252     p_sf52.to_occ_code                       := p_shadow.to_occ_code                  ;
5253 --    p_sf52.to_other_pay_amount               := p_shadow.to_other_pay_amount          ;
5254     p_sf52.to_position_id                    := p_shadow.to_position_id               ;
5255     p_sf52.to_retention_allowance            := p_shadow.to_retention_allowance       ;
5256     p_sf52.to_retention_allow_percentage     := p_shadow.to_retention_allow_percentage;
5257     p_sf52.to_staffing_differential          := p_shadow.to_staffing_differential     ;
5258     p_sf52.to_staffing_diff_percentage       := p_shadow.to_staffing_diff_percentage  ;
5259     p_sf52.to_step_or_rate                   := p_shadow.to_step_or_rate              ;
5260     p_sf52.to_supervisory_differential       := p_shadow.to_supervisory_differential  ;
5261     p_sf52.to_supervisory_diff_percentage    := p_shadow.to_supervisory_diff_percentage ;
5262     p_sf52.veterans_preference               := p_shadow.veterans_preference          ;
5263     p_sf52.veterans_pref_for_rif             := p_shadow.veterans_pref_for_rif        ;
5264     p_sf52.veterans_status                   := p_shadow.veterans_status              ;
5265     p_sf52.work_schedule                     := p_shadow.work_schedule                ;
5266     p_sf52.year_degree_attained              := p_shadow.year_degree_attained         ;
5267   exception when others then
5268             --
5269             -- Reset IN OUT parameters and set OUT parameters
5270             --
5271             p_sf52 := null;
5272             raise;
5273 
5274 End;
5275 
5276 Procedure convert_sf52_to_shadow (
5277 	p_sf52	 in	ghr_pa_requests%rowtype,
5278 	p_shadow out nocopy   ghr_pa_request_shadow%rowtype
5279 ) is
5280 
5281 Begin
5282 
5283     p_shadow.pa_request_id                     := p_sf52.pa_request_id                ;
5284     p_shadow.academic_discipline               := p_sf52.academic_discipline          ;
5285     p_shadow.annuitant_indicator               := p_sf52.annuitant_indicator          ;
5286     p_shadow.appropriation_code1               := p_sf52.appropriation_code1          ;
5287     p_shadow.appropriation_code2               := p_sf52.appropriation_code2          ;
5288     p_shadow.bargaining_unit_status            := p_sf52.bargaining_unit_status       ;
5289     p_shadow.citizenship                       := p_sf52.citizenship                  ;
5290 --    p_shadow.duty_station_code                 := p_sf52.duty_station_code            ;
5291     p_shadow.duty_station_location_id          := p_sf52.duty_station_location_id     ;
5292     p_shadow.education_level                   := p_sf52.education_level              ;
5293 --    p_shadow.employee_assignment_id            := p_sf52.employee_assignment_id       ;
5294     p_shadow.fegli                             := p_sf52.fegli                        ;
5295     p_shadow.flsa_category                     := p_sf52.flsa_category                ;
5296     p_shadow.forwarding_address_line1          := p_sf52.forwarding_address_line1 ;
5297     p_shadow.forwarding_address_line2          := p_sf52.forwarding_address_line2 ;
5298     p_shadow.forwarding_address_line3          := p_sf52.forwarding_address_line3  ;
5299     p_shadow.forwarding_country_short_name     := p_sf52.forwarding_country_short_name;
5300     p_shadow.forwarding_postal_code            := p_sf52.forwarding_postal_code       ;
5301     p_shadow.forwarding_region_2               := p_sf52.forwarding_region_2          ;
5302     p_shadow.forwarding_town_or_city           := p_sf52.forwarding_town_or_city      ;
5303     p_shadow.functional_class                  := p_sf52.functional_class             ;
5304     p_shadow.part_time_hours                   := p_sf52.part_time_hours              ;
5305     p_shadow.pay_rate_determinant              := p_sf52.pay_rate_determinant         ;
5306     p_shadow.position_occupied                 := p_sf52.position_occupied            ;
5307     p_shadow.retirement_plan                   := p_sf52.retirement_plan              ;
5308     p_shadow.service_comp_date                 := p_sf52.service_comp_date            ;
5309     p_shadow.supervisory_status                := p_sf52.supervisory_status           ;
5310     p_shadow.tenure                            := p_sf52.tenure                       ;
5311     p_shadow.to_ap_premium_pay_indicator       := p_sf52.to_ap_premium_pay_indicator  ;
5312     p_shadow.to_auo_premium_pay_indicator      := p_sf52.to_auo_premium_pay_indicator ;
5313 --    p_shadow.to_au_overtime                    := p_sf52.to_au_overtime               ;
5314 --    p_shadow.to_availability_pay               := p_sf52.to_availability_pay          ;
5315     p_shadow.to_occ_code                       := p_sf52.to_occ_code                  ;
5316 --    p_shadow.to_other_pay_amount               := p_sf52.to_other_pay_amount          ;
5317     p_shadow.to_position_id                    := p_sf52.to_position_id               ;
5318     p_shadow.to_retention_allowance            := p_sf52.to_retention_allowance       ;
5319     p_shadow.to_retention_allow_percentage     := p_sf52.to_retention_allow_percentage;
5320     p_shadow.to_staffing_differential          := p_sf52.to_staffing_differential     ;
5321     p_shadow.to_staffing_diff_percentage       := p_sf52.to_staffing_diff_percentage     ;
5322 
5323     p_shadow.to_step_or_rate                   := p_sf52.to_step_or_rate              ;
5324     p_shadow.to_supervisory_differential       := p_sf52.to_supervisory_differential  ;
5325     p_shadow.to_supervisory_diff_percentage    := p_sf52.to_supervisory_diff_percentage  ;
5326     p_shadow.veterans_preference               := p_sf52.veterans_preference          ;
5327     p_shadow.veterans_pref_for_rif             := p_sf52.veterans_pref_for_rif        ;
5328     p_shadow.veterans_status                   := p_sf52.veterans_status              ;
5329     p_shadow.work_schedule                     := p_sf52.work_schedule                ;
5330     p_shadow.year_degree_attained              := p_sf52.year_degree_attained         ;
5331   exception when others then
5332             --
5333             -- Reset IN OUT parameters and set OUT parameters
5334             --
5335             p_shadow := null;
5336             raise;
5337 
5338 End;
5339 
5340 Procedure build_corrected_sf52(p_pa_request_id		in number,
5341 		p_noa_code_correct	in varchar2,
5342 		p_sf52_data_result in out nocopy ghr_pa_requests%rowtype,
5343                 p_called_from in varchar2 default null ) is
5344 
5345 	l_sf52_data_orig		ghr_pa_requests%rowtype;
5346 	l_sf52_data_step		ghr_pa_requests%rowtype;
5347 	l_sf52_data_result_rec		ghr_pa_requests%rowtype;
5348 	l_sf52_dummy		ghr_pa_requests%rowtype;
5349 	l_sf52_cursor_step_indx	number;
5350         l_capped_other_pay number := hr_api.g_number;
5351 
5352 	-- this cursor selects all rows in the correction chain from ghr_pa_requests
5353 	cursor  l_sf52_cursor is
5354 	select 	*
5355 	from 		ghr_pa_requests
5356 	connect by 	prior altered_pa_request_id = pa_request_id
5357 	start with	pa_request_id = p_pa_request_id
5358 	order by 	level desc;
5359 	l_shadow_data	ghr_pa_request_shadow%rowtype;
5360 	l_proc	varchar2(30):='build_corrected_sf52';
5361 
5362 --Bug 2141522
5363    l_session_var   ghr_history_api.g_session_var_type;
5364    -- Bug#5435374 added l_session_var1.
5365    l_session_var1   ghr_history_api.g_session_var_type;
5366    l_session_sf52_rec ghr_pa_requests%rowtype;
5367    cursor c_rpa is
5368    select *
5369    from ghr_pa_requests
5370    where pa_request_id = p_pa_request_id;
5371 --Bug 2141522
5372 cursor c_orig_details_for_ia is
5373         select pa_request_id,pa_notification_id,person_id,
5374                effective_date,from_position_id,
5375                to_position_id
5376         from ghr_pa_requests
5377         where pa_request_id in (
5378             select  altered_pa_request_id from
5379              ghr_pa_requests where pa_request_id = p_pa_request_id);
5380 
5381 	     -- Bug#5435374
5382         l_pos_ei_grade_data  per_position_extra_info%rowtype;
5383 
5384         cursor c_grade_kff (grd_id number) is
5385             select gdf.segment1
5386                   ,gdf.segment2
5387               from per_grades grd,
5388                    per_grade_definitions gdf
5389              where grd.grade_id = grd_id
5390                and grd.grade_definition_id = gdf.grade_definition_id;
5391 
5392 l_retro_eff_date date;
5393 l_retro_pa_request_id   ghr_pa_requests.pa_request_id%type;
5394 l_retro_first_noa       ghr_nature_of_actions.code%type;
5395 l_retro_second_noa       ghr_nature_of_actions.code%type;
5396 l_sf52_ia_rec		ghr_pa_requests%rowtype;
5397 
5398 
5399 begin
5400 	hr_utility.set_location('Entering:'|| l_proc, 5);
5401    l_sf52_data_result_rec := p_sf52_data_result;
5402 --	ghr_history_api.get_g_session_var(l_session_var);
5403 --Bug 2141522
5404         -- set values of session variables
5405         open  c_rpa;
5406         fetch c_rpa into l_session_sf52_rec;
5407         close c_rpa;
5408 
5409         l_session_var.pa_request_id             := p_pa_request_id;
5410         l_session_var.noa_id                    := l_session_sf52_rec.second_noa_id;
5411         l_session_var.fire_trigger              := 'N';
5412         l_session_var.date_Effective            := l_session_sf52_rec.effective_date;
5413         l_session_var.person_id                 := l_session_sf52_rec.person_id;
5414         l_session_var.program_name              := 'sf50';
5415         l_session_var.assignment_id             := l_session_sf52_rec.employee_assignment_id;
5416         l_session_var.altered_pa_request_id     := l_session_sf52_rec.altered_pa_request_id;
5417         l_session_var.noa_id_correct            := l_session_sf52_rec.second_noa_id;
5418         ghr_history_api.set_g_session_var(l_session_var);
5419 --Bug 2141522
5420 
5421 	-- loop through all corrections in the correction chain, incrementally applying them by
5422 	-- calling apply_corrections procedure.
5423 	open l_sf52_cursor ;
5424 	l_sf52_cursor_step_indx := 0;
5425 	loop
5426 		-- initialize l_sf52_data_step to nulls;
5427 		l_sf52_data_step := l_sf52_dummy;
5428 		-- l_sf52_data_step holds intermediate incremental values for final corrected record that is
5429 		-- being built.
5430 		fetch l_sf52_cursor into l_sf52_data_step;
5431 		exit when l_sf52_cursor%notfound;
5432 		l_sf52_cursor_step_indx := l_sf52_cursor_step_indx +1;
5433 		if ( 	l_sf52_cursor_step_indx = 1) then
5434 			hr_utility.set_location('Fetch l_sf52_data_step original :'|| l_proc, 10);
5435 			l_sf52_data_orig 	  := l_sf52_data_step;
5436 			p_sf52_data_result  := l_sf52_data_step;
5437             -- Bug 3228557 Added the following IF condition. In case of NPA Printing
5438             -- Pass parameter 'NPA' to the procedure call to refresh_req_shadow.
5439             IF NVL(p_called_from,hr_api.g_varchar2) = 'NPA' THEN
5440 			    hr_utility.set_location('Inside NPA printing',10);
5441 			    ghr_process_sf52.refresh_req_shadow(p_sf52_data=>p_sf52_data_result,
5442                                                                 p_shadow_data=>l_shadow_data,
5443                                                                 p_process_type => 'NPA');
5444             ELSE
5445 			    hr_utility.set_location('Calling Refresh_req_shadow ',10);
5446                             ghr_process_sf52.refresh_req_shadow(p_sf52_data=>p_sf52_data_result,
5447                                                                   p_shadow_data=>l_shadow_data);
5448             END IF;
5449             -- Bug 3228557 Skip Pay Calculation in case of NPA report printing.
5450 			IF nvl(p_called_from,hr_api.g_varchar2) NOT IN ('FROM_PAYCAL','NPA') THEN
5451 			ghr_process_sf52.redo_pay_calc(	p_sf52_rec		=>	p_sf52_data_result,
5452                                             p_capped_other_pay      =>   l_capped_other_pay);
5453             END IF;
5454 			hr_utility.set_location('assignment_id of original =' || l_sf52_data_step.employee_assignment_id, 14);
5455 			hr_utility.set_location(l_proc || 'pa_request_id of original= ' || l_sf52_data_step.pa_request_id,26);
5456 			-- check if original action in correction chain was a dual action. If so, determine which of
5457 			--   the two actions this correction is for and call ghr_process_sf52.assign_new_rg to null out columns not having
5458 			--   to do with the noa we are correcting.
5459 			if (p_sf52_data_result.second_noa_id is not null) then
5460 				hr_utility.set_location('original sf52 is dual action :'|| l_proc, 11);
5461 ---- commented the below if condition because is is compared against NOAC Code
5462 ---- Dual action correction need to be tested.
5463 ----        if (p_noa_code_correct = p_sf52_data_result.second_noa_id) then
5464 				if (p_noa_code_correct = p_sf52_data_result.second_noa_code) then
5465 					hr_utility.set_location('Correcting second action in dual action:'|| l_proc, 12);
5466 					-- Bug 8264475Modified to comment the code for handling dual actions
5467 					-- as both the actions need to consider the same to side information
5468 					/*ghr_process_sf52.assign_new_rg(p_action_num			=>	2,
5469 										 p_pa_req				=>	p_sf52_data_result);*/
5470 					ghr_process_sf52.copy_2ndNoa_to_1stNoa(p_sf52_data_result);
5471                               	        ghr_process_sf52.null_2ndNoa_cols(p_sf52_data_result);
5472 				else
5473 					hr_utility.set_location('Correcting first action in dual action:'|| l_proc, 13);
5474 					-- Bug 8264475Modified to comment the code for handling dual actions
5475 					-- as both the actions need to consider the same to side information
5476 
5477 					/*ghr_process_sf52.assign_new_rg(p_action_num			=>	1,
5478 								 		 p_pa_req				=>	p_sf52_data_result);*/
5479 		 			-- if first action is 893, then we need to derive to_columns as both actions of
5480 					-- the dual action potentially could have changed the to fields (in particular,
5481 					-- to_step_or_rate) so we need to determine what the to_fields should be or the first action.
5482 					if (p_sf52_data_result.first_noa_code = '893') then--Bug# 8926400
5483 						ghr_process_sf52.derive_to_columns(p_sf52_data	=>	p_sf52_data_result);
5484 					end if;
5485 					ghr_process_sf52.null_2ndNoa_cols(p_sf52_data_result);
5486 				end if;
5487 			end if;
5488 			-- Nullfy columns which must not be passed
5489 			p_sf52_data_result.pa_notification_id		:= NULL;
5490 			p_sf52_data_result.agency_code			:= NULL;
5491 			p_sf52_data_result.approval_date			:= NULL;
5492 			p_sf52_data_result.approving_official_work_title:= NULL;
5493 			p_sf52_data_result.employee_dept_or_agency 	:= NULL;
5494 			p_sf52_data_result.from_agency_code			:= NULL;
5495 			p_sf52_data_result.from_agency_desc			:= NULL;
5496 			p_sf52_data_result.from_office_symbol		:= NULL;
5497 			p_sf52_data_result.personnel_office_id		:= NULL;
5498 			p_sf52_data_result.to_office_symbol			:= NULL;
5499 		else
5500 			hr_utility.set_location('Fetch l_sf52_data_step loop :'|| l_proc, 15);
5501 			-- all corrections will have the original sf52 information in the 2nd noa columns, so
5502 			-- copy that information to 1st noa columns.
5503 			ghr_process_sf52.copy_2ndNoa_to_1stNoa(l_sf52_data_step);
5504 			-- null the second noa columns since we don't want anything to be done with these now.
5505 			ghr_process_sf52.null_2ndNoa_cols(l_sf52_data_step);
5506 			hr_utility.set_location(l_proc || 'pa_request_id before correction= ' || l_sf52_data_step.pa_request_id,16);
5507 			hr_utility.set_location(l_proc || 'assignment id before correction= ' || l_sf52_data_step.employee_assignment_id,17);
5508                        -- Start Intervening Actions Processing
5509                        -- Processing added to assign the From side details to
5510                        -- To side if it is a Intervening action and
5511                        -- Original action from position_id = to position id
5512                        -- Fetch the original action details
5513                        FOR c_orig_det_rec in c_orig_details_for_ia
5514                        LOOP
5515 			hr_utility.set_location('Inside the orig_details for loop' ,15);
5516 			hr_utility.set_location('orig pa_request_id'||c_orig_det_rec.pa_request_id ,15);
5517 			hr_utility.set_location('orig pa_notification_id'||c_orig_det_rec.pa_notification_id ,15);
5518 			hr_utility.set_location('orig person_id'||c_orig_det_rec.person_id ,15);
5519 			hr_utility.set_location('orig from_position_id'||c_orig_det_rec.from_position_id ,15);
5520 			hr_utility.set_location('orig to_position_id'||c_orig_det_rec.to_position_id ,15);
5521 			hr_utility.set_location('orig effective_date'||c_orig_det_rec.effective_date ,15);
5522 		    --BUG #7216635 added the parameter p_noa_id_correct
5523                         GHR_APPROVED_PA_REQUESTS.determine_ia(
5524                              p_pa_request_id => c_orig_det_rec.pa_request_id,
5525                              p_pa_notification_id => c_orig_det_rec.pa_notification_id,
5526                              p_person_id      => c_orig_det_rec.person_id,
5527                              p_effective_date => c_orig_det_rec.effective_date,
5528 			      p_noa_id_correct => l_session_var.noa_id_correct,
5529                              p_retro_pa_request_id => l_retro_pa_request_id,
5530                              p_retro_eff_date => l_retro_eff_date,
5531                              p_retro_first_noa => l_retro_first_noa,
5532                              p_retro_second_noa => l_retro_second_noa);
5533 			hr_utility.set_location('retro effective_date is '||l_retro_eff_date ,16);
5534 			-- Bug#2521744 Splitting the single if condition into 2 separate if conditions.
5535                         IF l_retro_eff_date is NOT NULL  THEN
5536                            IF c_orig_det_rec.from_position_id
5537                                 = c_orig_det_rec.to_position_id THEN
5538                                 -- copy the from details
5539                                 -- copy the from details
5540 				hr_utility.set_location('Its a Intervening Action ' ,16);
5541 				hr_utility.set_location('pa_request_id passed to get_sf52_to_det '||p_pa_request_id ,17);
5542 
5543 				get_sf52_to_details_for_ia
5544 				   (p_pa_request_id => p_pa_request_id,
5545 				    p_retro_eff_date   => l_retro_eff_date,
5546 				    p_sf52_ia_rec  => p_sf52_data_result);
5547 				get_sf52_to_othpays_for_ia(p_sf52_ia_rec  => p_sf52_data_result);
5548 				ghr_process_sf52.print_sf52('result aft get_sf52_to_details_for_ia',
5549 							     p_sf52_data_result );
5550                           ELSE
5551                                 -- Verify whether the original action is one of the salary change actions
5552                                 -- If yes, check whether the other pay related elements are present or not
5553                                 -- as on the effective date. If they are not present, set that other pay comp
5554                                 -- to_value as null.
5555                                 get_sf52_to_othpays_for_ia(p_sf52_ia_rec  => p_sf52_data_result);
5556                                 ghr_process_sf52.print_sf52('Aft get_sf52_to_other_pay_det_for_ia in else',
5557                                                  p_sf52_data_result );
5558                           END IF;
5559                         END IF;
5560                       END LOOP;
5561                         ghr_process_sf52.print_sf52('step aft get_sf52_to_details_for_ia',
5562                                                     l_sf52_data_step);
5563 			apply_correction( p_sf52rec_correct		=>	l_sf52_data_step,
5564 						p_corr_pa_request_id	=>	p_pa_request_id,
5565 						p_sf52rec		=>	p_sf52_data_result );
5566 
5567                         if (l_sf52_data_step.first_noa_code = '352') then
5568                                 p_sf52_data_result.to_position_org_line1 :=
5569                                 ghr_pa_requests_pkg2.get_agency_code_to(
5570                                   p_pa_request_id => l_sf52_data_step.pa_request_id,
5571                                   p_noa_id        => l_sf52_data_step.first_noa_id);
5572                -- Bug#2681726 In case of Realignment print all the Position Org Lines.
5573                         elsif (l_sf52_data_step.first_noa_code = '790' ) then
5574                            ghr_pa_requests_pkg.get_rei_org_lines(
5575                                  p_pa_request_id       => p_sf52_data_result.pa_request_id,
5576                                  p_organization_id     => p_sf52_data_result.to_organization_id,
5577                                  p_position_org_line1  => p_sf52_data_result.to_position_org_line1,
5578                                  p_position_org_line2  => p_sf52_data_result.to_position_org_line2,
5579                                  p_position_org_line3  => p_sf52_data_result.to_position_org_line3,
5580                                  p_position_org_line4  => p_sf52_data_result.to_position_org_line4,
5581                                  p_position_org_line5  => p_sf52_data_result.to_position_org_line5,
5582                                  p_position_org_line6  => p_sf52_data_result.to_position_org_line6);
5583                         end if;
5584 
5585                         -- Recalculating Retention Allowance
5586                         -- Recalculate Retention allowance if it is a OTHER_PAY action
5587                         -- and Correction of Intervening Action
5588                          if p_sf52_data_result.noa_family_code = 'OTHER_PAY' and
5589                            l_retro_eff_date is NOT NULL and
5590 			   p_sf52_data_result.to_retention_allow_percentage is not null then
5591    --Modified for FWS
5592                            IF p_sf52_data_result.to_pay_basis ='PH' THEN
5593        			      p_sf52_data_result.to_retention_allowance :=
5594                                  TRUNC(p_sf52_data_result.to_basic_pay * p_sf52_data_result.to_retention_allow_percentage/100,2);
5595 			   ELSE
5596 			        p_sf52_data_result.to_retention_allowance :=
5597                                  TRUNC(p_sf52_data_result.to_basic_pay * p_sf52_data_result.to_retention_allow_percentage/100,0);
5598                            END IF;
5599     --FWS END
5600                              p_sf52_data_result.to_other_pay_amount :=
5601                              nvl(p_sf52_data_result.to_au_overtime,0) +
5602                              nvl(p_sf52_data_result.to_availability_pay,0) +
5603                              nvl(p_sf52_data_result.to_retention_allowance,0) +
5604                              nvl(p_sf52_data_result.to_supervisory_differential,0) +
5605                              nvl(p_sf52_data_result.to_staffing_differential,0);
5606                              p_sf52_data_result.to_total_salary :=
5607                              p_sf52_data_result.to_adj_basic_pay + p_sf52_data_result.to_other_pay_amount;
5608                              if p_sf52_data_result.to_other_pay_amount = 0 then
5609                                p_sf52_data_result.to_other_pay_amount := null;
5610                              end if;
5611                            end if;
5612 			hr_utility.set_location( l_proc || 'assignment_id after correction=' || p_sf52_data_result.employee_assignment_id ,18);
5613 			hr_utility.set_location('Applied corrections :'|| l_proc, 20);
5614 		end if;
5615 	end loop;
5616 	close l_sf52_cursor;
5617 
5618     -- Bug#5435374 If the from and to position ids are same, verify the grade details.
5619 	 IF p_sf52_data_result.from_position_id = p_sf52_data_result.to_position_id THEN
5620 
5621         -- Reinitializing the session variables to get the valid grade as on the
5622         -- effective date.
5623         ghr_history_api.get_g_session_var(l_session_var);
5624         ghr_history_api.reinit_g_session_var;
5625         l_session_var1.date_Effective            := l_session_var.date_Effective;
5626         l_session_var1.person_id                 := l_session_var.person_id;
5627         l_session_var1.assignment_id             := l_session_var.assignment_id;
5628         l_session_var1.fire_trigger    := 'N';
5629         l_session_var1.program_name := 'sf50';
5630         ghr_history_api.set_g_session_var(l_session_var1);
5631 
5632         -- Retrieve the Grade info from the POI history table
5633 		ghr_history_fetch.fetch_positionei(
5634 		p_position_id      => p_sf52_data_result.to_position_id,
5635 		p_information_type => 'GHR_US_POS_VALID_GRADE',
5636 		p_date_effective   => p_sf52_data_result.effective_date,
5637 		p_pos_ei_data      => l_pos_ei_grade_data);
5638 
5639         -- Reset the session variables after getting the date effective grade value.
5640         ghr_history_api.reinit_g_session_var;
5641         ghr_history_api.set_g_session_var(l_session_var);
5642 
5643         IF l_pos_ei_grade_data.position_extra_info_id IS NOT NULL THEN
5644 			hr_utility.set_location('GL: to grd id:'||p_sf52_data_result.to_grade_id,30);
5645 			hr_utility.set_location('GL: pos ei grd:'||l_pos_ei_grade_data.poei_information3,40);
5646 			IF l_pos_ei_grade_data.poei_information3 <> p_sf52_data_result.to_grade_id THEN
5647 				--Bug# 5638869
5648                 --p_sf52_data_result.to_grade_id := l_pos_ei_grade_data.poei_information3;
5649                 l_pos_ei_grade_data.poei_information3 := p_sf52_data_result.to_grade_id;
5650                 --Bug# 5638869
5651 				FOR c_grade_kff_rec IN c_grade_kff (p_sf52_data_result.to_grade_id)
5652 				LOOP
5653 					p_sf52_data_result.to_pay_plan := c_grade_kff_rec.segment1  ;
5654 					p_sf52_data_result.to_grade_or_level := c_grade_kff_rec.segment2;
5655 					EXIT;
5656 				END LOOP;
5657 			END IF;
5658 		END IF;
5659 	 END IF;
5660      -- Bug#5435374 End of bug fix.
5661 
5662      ghr_process_sf52.print_sf52('Result after apply_correction ' , p_sf52_data_result);
5663 
5664      hr_utility.set_location(' Leaving:'||l_proc, 25);
5665 exception when others then
5666             --
5667             -- Reset IN OUT parameters and set OUT parameters
5668             --
5669             p_sf52_data_result := l_sf52_data_result_rec;
5670             raise;
5671 
5672 end build_corrected_sf52;
5673 
5674 -- Following 4 procedures and functions are created to handle correction RPAs
5675 -- In reports.
5676 
5677 Procedure populate_corrected_sf52(p_pa_request_id    in number,
5678                                   p_noa_code_correct in varchar2)
5679 is
5680   l_session_var     ghr_history_api.g_session_var_type;
5681   l_sf52_data       ghr_pa_requests%ROWTYPE;
5682 
5683 
5684   FUNCTION get_record_category(p_sf52_record IN ghr_pa_requests%ROWTYPE)
5685   RETURN NUMBER IS
5686     CURSOR c_noa_fam_code(c_noa_id NUMBER) is
5687     select fam.noa_family_code family_code
5688     from ghr_noa_families fam
5689     where fam.nature_of_action_id = c_noa_id;
5690 
5691     l_found VARCHAR2(10) := 'FALSE';
5692     l_proc  VARCHAR2(30) := 'get_record_category';
5693 
5694   BEGIN
5695      hr_utility.set_location('Entering: '||l_proc,0);
5696      IF p_sf52_record.from_position_id      IS NOT NULL AND
5697         p_sf52_record.from_position_title   IS NOT NULL AND
5698         p_sf52_record.from_position_number  IS NOT NULL AND
5699       --  p_sf52_record.from_position_seq_no  IS NOT NULL AND
5700         p_sf52_record.from_pay_plan         IS NOT NULL AND
5701         p_sf52_record.from_grade_or_level   IS NOT NULL AND
5702         p_sf52_record.from_step_or_rate     IS NOT NULL AND
5703         p_sf52_record.from_pay_basis        IS NOT NULL AND
5704         p_sf52_record.from_basic_pay        IS NOT NULL AND
5705         p_sf52_record.from_adj_basic_pay    IS NOT NULL AND
5706         p_sf52_record.from_locality_adj     IS NOT NULL AND
5707         p_sf52_record.from_total_salary     IS NOT NULL AND
5708         p_sf52_record.to_position_id        IS NOT NULL AND
5709         p_sf52_record.to_position_title     IS NOT NULL AND
5710         p_sf52_record.to_position_number    IS NOT NULL AND
5711     --    p_sf52_record.to_position_seq_no    IS NOT NULL AND
5712         p_sf52_record.to_pay_plan           IS NOT NULL AND
5713         p_sf52_record.to_grade_or_level     IS NOT NULL AND
5714         p_sf52_record.to_step_or_rate       IS NOT NULL AND
5715         p_sf52_record.to_pay_basis          IS NOT NULL AND
5716         p_sf52_record.to_basic_pay          IS NOT NULL AND
5717         p_sf52_record.to_adj_basic_pay      IS NOT NULL AND
5718         p_sf52_record.to_locality_adj       IS NOT NULL AND
5719         p_sf52_record.to_total_salary       IS NOT NULL THEN
5720             hr_utility.set_location('Leaving: '||l_proc,10);
5721             -- Added the following code as there are some 2 category corr. to Other Pay
5722             -- actions where all the above fields are not null. but, still the record belongs
5723             -- to 2nd category if the correction is dummy correction. In this case,
5724             -- to_au_overtime/to_availability pay is null.
5725             FOR noa_fam_rec  IN c_noa_fam_code(p_sf52_record.second_noa_id)
5726             LOOP
5727                 hr_utility.set_location(' OTHER PAY Family Code = '||noa_fam_rec.family_code,15);
5728                 IF  noa_fam_rec.family_code IN ('OTHER_PAY') THEN
5729                     l_found := 'TRUE';
5730                     EXIT;
5731                 END IF;
5732             END LOOP;
5733             IF l_found = 'TRUE' THEN
5734                 IF (p_sf52_record.second_noa_code = '818' AND p_sf52_record.to_au_overtime IS NULL) OR
5735                    (p_sf52_record.second_noa_code = '819' AND p_sf52_record.to_availability_pay IS NULL) THEN
5736                    Return 2;
5737                 ELSE
5738                    Return 3;
5739                 END IF;
5740             ELSE
5741                 Return 3;
5742             END IF;
5743 
5744         ELSIF
5745         p_sf52_record.from_position_id      IS NOT NULL AND
5746         p_sf52_record.from_position_title   IS NOT NULL AND
5747         p_sf52_record.from_position_number  IS NOT NULL AND
5748       --  p_sf52_record.from_position_seq_no  IS NOT NULL AND
5749         p_sf52_record.from_pay_plan         IS NOT NULL AND
5750         p_sf52_record.from_grade_or_level   IS NOT NULL AND
5751         p_sf52_record.from_step_or_rate     IS NOT NULL AND
5752         p_sf52_record.from_pay_basis        IS NOT NULL AND
5753         p_sf52_record.from_basic_pay        IS NOT NULL AND
5754         p_sf52_record.from_adj_basic_pay    IS NOT NULL AND
5755         p_sf52_record.from_locality_adj     IS NOT NULL AND
5756         p_sf52_record.from_total_salary     IS NOT NULL THEN
5757             -- For correction to Separation actions also, from side data is
5758             -- NOT NULL and TO SIDE DATA IS NULL. So, in such case, return
5759             -- value should be 3.
5760             IF  p_sf52_record.to_position_id        IS NULL AND
5761                 p_sf52_record.to_position_title     IS NULL AND
5762                 p_sf52_record.to_position_number    IS NULL AND
5763               --  p_sf52_record.to_position_seq_no    IS NULL AND
5764                 p_sf52_record.to_pay_plan           IS NULL AND
5765                 p_sf52_record.to_grade_or_level     IS NULL AND
5766                 p_sf52_record.to_step_or_rate       IS NULL AND
5767                 p_sf52_record.to_pay_basis          IS NULL AND
5768                 p_sf52_record.to_basic_pay          IS NULL AND
5769                 p_sf52_record.to_adj_basic_pay      IS NULL AND
5770                 p_sf52_record.to_locality_adj       IS NULL AND
5771                 p_sf52_record.to_total_salary       IS NULL THEN
5772                 FOR noa_fam_rec  IN c_noa_fam_code(p_sf52_record.second_noa_id)
5773                 LOOP
5774                     hr_utility.set_location(' SEP Family Code = '||noa_fam_rec.family_code,15);
5775                     IF  noa_fam_rec.family_code IN ('SEPARATION','NON_PAY_DUTY_STATUS',
5776 		                                    'AWARD','GHR_INCENTIVE') THEN
5777                         l_found := 'TRUE';
5778                         EXIT;
5779                     END IF;
5780                 END LOOP;
5781                 IF l_found = 'TRUE' THEN
5782                     hr_utility.set_location('Leaving: '||l_proc,20);
5783                     Return 3;
5784                 ELSE
5785                     hr_utility.set_location('Leaving: '||l_proc,30);
5786                     Return 2;
5787                 END IF;
5788             ELSE
5789                 hr_utility.set_location('Leaving: '||l_proc,40);
5790                 Return 2;
5791             END IF;
5792         ELSE
5793             -- For correction to Appointment actions also, from side data is
5794             -- NULL and TO SIDE DATA IS NOT NULL. So, in such case, return
5795             -- value should be 3.
5796 	        IF  p_sf52_record.from_position_id      IS NULL AND
5797                 p_sf52_record.from_position_title   IS NULL AND
5798                 p_sf52_record.from_position_number  IS NULL AND
5799              --   p_sf52_record.from_position_seq_no  IS NULL AND
5800                 p_sf52_record.from_pay_plan         IS NULL AND
5801                 p_sf52_record.from_grade_or_level   IS NULL AND
5802                 p_sf52_record.from_step_or_rate     IS NULL AND
5803                 p_sf52_record.from_pay_basis        IS NULL AND
5804                 p_sf52_record.from_basic_pay        IS NULL AND
5805                 p_sf52_record.from_adj_basic_pay    IS NULL AND
5806                 p_sf52_record.from_locality_adj     IS NULL AND
5807                 p_sf52_record.from_total_salary     IS NULL AND
5808                 p_sf52_record.to_position_id        IS NOT NULL AND
5809                 p_sf52_record.to_position_title     IS NOT NULL AND
5810                 p_sf52_record.to_position_number    IS NOT NULL AND
5811               --  p_sf52_record.to_position_seq_no    IS NOT NULL AND
5812                 p_sf52_record.to_pay_plan           IS NOT NULL AND
5813                 p_sf52_record.to_grade_or_level     IS NOT NULL AND
5814                 p_sf52_record.to_step_or_rate       IS NOT NULL AND
5815                 p_sf52_record.to_pay_basis          IS NOT NULL AND
5816                 p_sf52_record.to_basic_pay          IS NOT NULL AND
5817                 p_sf52_record.to_adj_basic_pay      IS NOT NULL AND
5818                 p_sf52_record.to_locality_adj       IS NOT NULL AND
5819                 p_sf52_record.to_total_salary       IS NOT NULL THEN
5820                     hr_utility.set_location('Leaving: '||l_proc,40);
5821                     Return 3;
5822              ELSE
5823                 hr_utility.set_location('Leaving: '||l_proc,50);
5824                 Return 1;
5825             END IF;
5826         END IF;
5827     END get_record_category;
5828 
5829 BEGIN
5830     -- Get the CORRECTION RPA record from ghr_pa_requests table.
5831     SELECT *
5832     INTO l_sf52_data
5833     FROM ghr_pa_requests
5834     WHERE pa_request_id = p_pa_request_id;
5835     -- Check the record's category..
5836     -- If record belongs to category 1 or 2 then call build_corrected_sf52 with NPA parameter.
5837     -- BUG#3958914 Added the OR Conidtions
5838     IF (get_record_category(l_sf52_data) IN (1,2) OR
5839          ( l_sf52_data.appropriation_code1 IS NULL OR l_sf52_data.appropriation_code2 IS NULL      OR
5840            l_sf52_data.annuitant_indicator is NULL OR l_sf52_data.fegli is NULL                    OR
5841            l_sf52_data.retirement_plan is NULL     OR l_sf52_data.service_comp_date IS NULL OR
5842            l_sf52_data.tenure IS NULL              OR l_sf52_data.veterans_preference IS NULL      OR
5843            l_sf52_data.veterans_pref_for_rif IS NULL
5844 	 )
5845        )THEN
5846         l_session_var.pa_request_id   := l_sf52_data.pa_request_id;
5847         l_session_var.noa_id          := l_sf52_data.second_noa_id;
5848         -- No triggers should be fired as cancellation can not be corrected or cancelled
5849         -- so none of the changes will be saved.
5850         l_session_var.fire_trigger    := 'N';
5851         l_session_var.date_Effective  := l_sf52_data.effective_date;
5852         l_session_var.person_id               := l_sf52_data.person_id;
5853         l_session_var.program_name    := 'GHRSF50';
5854         l_session_var.assignment_id   := l_sf52_data.employee_assignment_id;
5855         l_session_var.altered_pa_request_id   := l_sf52_data.altered_pa_request_id;
5856         l_session_var.noa_id_correct  := l_sf52_data.second_noa_id;
5857         ghr_history_api.set_g_session_var(l_session_var);
5858       ---Bug 5220727
5859         IF (l_sf52_data.second_noa_code <> '825' AND
5860            NOT(l_sf52_data.rpa_type='DUAL' and l_sf52_data.second_noa_code like '3%')) then --Bug# 8299172
5861 	build_corrected_sf52(p_pa_request_id, p_noa_code_correct, sf52_corr_rec,'NPA');
5862         ELSE
5863         sf52_corr_rec := l_sf52_data;
5864         END IF;
5865     ELSE
5866       hr_utility.set_location('assinging the original record',20);
5867       sf52_corr_rec := l_sf52_data;
5868     END IF;
5869 end populate_corrected_sf52;
5870 
5871 Function  get_date_column(p_value in varchar2) return date is
5872   p_rows   integer;
5873   l_cursor integer;
5874 begin
5875   l_cursor := dbms_sql.open_cursor;
5876   dbms_sql.parse(l_cursor,
5877      'begin ' ||
5878      '  ghr_corr_canc_sf52.l_date_result := ghr_corr_canc_sf52.sf52_corr_rec.' || p_value || '; ' ||
5879      'end;', dbms_sql.v7);
5880   p_rows := dbms_sql.execute(l_cursor);
5881   dbms_sql.close_cursor(l_cursor);
5882   return l_date_result;
5883 end get_date_column;
5884 
5885 Function  get_number_column(p_value in varchar2) return number is
5886   p_rows   integer;
5887   l_cursor integer;
5888 begin
5889   l_cursor := dbms_sql.open_cursor;
5890   dbms_sql.parse(l_cursor,
5891      'begin ' ||
5892      '  ghr_corr_canc_sf52.l_number_result := ghr_corr_canc_sf52.sf52_corr_rec.' || p_value || '; ' ||
5893      'end;', dbms_sql.v7);
5894   p_rows := dbms_sql.execute(l_cursor);
5895   dbms_sql.close_cursor(l_cursor);
5896   return l_number_result;
5897 end get_number_column;
5898 
5899 Function  get_varchar2_column(p_value in varchar2) return varchar2 is
5900   p_rows   integer;
5901   l_cursor integer;
5902 begin
5903   l_cursor := dbms_sql.open_cursor;
5904   dbms_sql.parse(l_cursor,
5905      'begin ' ||
5906      '  ghr_corr_canc_sf52.l_varchar2_result := ghr_corr_canc_sf52.sf52_corr_rec.' || p_value || '; ' ||
5907      'end;', dbms_sql.v7);
5908   p_rows := dbms_sql.execute(l_cursor);
5909   dbms_sql.close_cursor(l_cursor);
5910   return l_varchar2_result;
5911 end get_varchar2_column;
5912 
5913 
5914 -- Procedure IF_ZAP_ELE_ENT
5915 -- Description : This procedure will be called from Cancel_Other_Family
5916 -- when we know that there does not exist a pre-record (by looking into history)
5917 -- for element_entry table and it needs to figure out if it can zap the element entry or not
5918 -- Logic : If element entry type is Non-recurring then it can be zapped
5919 --         But re-curring elements can be zapped only if there are no following records in history table
5920 --         for element entry values  ie only one transaction touched element entry and element entry values
5921 --
5922 Procedure IF_ZAP_ELE_ENT(
5923 		p_element_entry_id	in	number,
5924 		p_effective_start_date	in	date,
5925 		p_pa_history_id		in	number,
5926 		p_result	 out nocopy Boolean) is
5927 
5928 	cursor c_get_ele_ent
5929 		(cp_element_entry_id		in number,
5930 		 cp_effective_start_date	in date) is
5931 	select
5932 		pet.effective_start_date,
5933 		pet.effective_end_date,
5934 		pet.processing_type
5935 	from
5936 		pay_element_types_f pet, pay_element_links_f pel, pay_element_entries_f pee
5937 	where pee.element_entry_id 	= cp_element_entry_id and
5938 		pee.element_link_id	= pel.element_link_id and
5939 		pet.element_type_id	= pel.element_type_id and
5940 		cp_effective_start_date between pee.effective_start_date and pee.effective_end_date and
5941 		cp_effective_start_date between pet.effective_start_date and pet.effective_end_date and
5942 		cp_effective_start_date between pel.effective_start_date and pel.effective_end_date ;
5943 
5944 /*	cursor get_root_min_hist_id (cp_pa_history_id	in	number) is
5945 	select min(pa_history_id)
5946 	from ghr_pa_history
5947 	where pa_request_id = (select min(pa_request_id)
5948 					from ghr_pa_requests
5949 					start with pa_request_id = (select pa_request_id -- Bug# 1253981
5950 										from ghr_pa_history
5951 										where pa_history_id = cp_pa_history_id)
5952 					connect by  prior altered_pa_request_id  =  pa_request_id)
5953 --					connect by pa_request_id = altered_pa_request_id)
5954 		and nature_of_action_id = (select nature_of_action_id
5955 							from ghr_pa_history
5956 							where pa_history_id = cp_pa_history_id); */
5957 
5958 	-- Bug 3694358
5959 	-- In the cursor get_root_min_hist_id, start with - connect by is removed as it always returns the original
5960 	-- action as the min. and no need to loop through all the correction actions and find the min pa_request_id
5961 /*Bug 6868486 below cursor changed*/
5962 	cursor get_root_min_hist_id (cp_pa_history_id	in	number) is
5963 	select min(pa_history_id)
5964 	from ghr_pa_history
5965 	where pa_request_id = (select pa_request_id -- Bug# 1253981
5966 				from ghr_pa_history
5967 				where pa_history_id = cp_pa_history_id);
5968 
5969 	-- Bug 3694358
5970 	-- Changed connect by pa_request_id = altered_pa_request_id
5971 	-- to connect by altered_pa_request_id = pa_request_id
5972 	-- This cursor will fetch element entr value records, for a given element entry, that
5973 	-- were created after the c_root_hist_id
5974       Cursor c_history(
5975 			c_information1	varchar2,
5976 			c_effective_date	date,
5977 			c_root_hist_id	number) is
5978 		Select   pa_history_id
5979 		from     ghr_pa_history  pah
5980 		where    table_name 	      = ghr_history_api.g_eleevl_table
5981 		and      information5 	      = c_information1
5982 		and      (effective_date      > c_effective_date   or
5983 			   (effective_date      = c_effective_date  and
5984 			    c_root_hist_id      <
5985 						(select min(pa_history_id)
5986 						from ghr_pa_history
5987 						where pa_request_id =
5988 						(select 	min(pa_request_id)
5989 						from 		ghr_pa_requests
5990 						connect by 	prior altered_pa_request_id 	=  pa_request_id
5991 						start with 	pa_request_id 		= 	pah.pa_request_id))));
5992 
5993 	l_ele			c_get_ele_ent%rowtype;
5994 	l_root_hist_id	number;
5995 	l_dummy		number;
5996 	l_ret_val		Boolean:=FALSE;
5997 	l_proc		varchar2(30):='IF_ZAP_ELE_ENT';
5998 Begin
5999 
6000 	hr_utility.set_location('Entering : ' || l_proc, 5);
6001 	-- Find Element Type
6002 	open c_get_ele_ent(
6003 		p_element_entry_id,
6004 		p_effective_start_date);
6005 	fetch c_get_ele_ent into l_ele;
6006 	if c_get_ele_ent%notfound then
6007 		close c_get_ele_ent;
6008 		-- This case must not happen.
6009 		-- Not raising error. As it must be handled in calling routine
6010 		hr_utility.set_location(' Could not find Element Type. Must not happen !!' || l_proc, 10);
6011 		l_ret_val := FALSE;
6012 	else
6013 		if l_ele.processing_type = 'N' then
6014 			-- Non-recurring elemnt can be zapped.
6015 			close c_get_ele_ent;
6016 			l_ret_val := TRUE;
6017 			hr_utility.set_location('Non recurring CAN ZAP' || l_proc, 20);
6018 		else
6019 			-- For recurring
6020 			close c_get_ele_ent;
6021 			open get_root_min_hist_id (p_pa_history_id);
6022 			fetch get_root_min_hist_id into l_root_hist_id;
6023 			if get_root_min_hist_id%notfound then
6024 				close get_root_min_hist_id;
6025 				hr_utility.set_location(' Root Hist ID Not found!! Must not happen'  || l_proc, 30);
6026 				l_ret_val := FALSE;
6027 			else
6028 				close get_root_min_hist_id;
6029 				hr_utility.set_location(' Fetching successor,if any, from history'  || l_proc, 40);
6030 				open c_history(
6031 					c_information1	=> p_element_entry_id,
6032 					c_effective_date	=> p_effective_start_date,
6033 					c_root_hist_id	=> l_root_hist_id);
6034 				fetch c_history into l_dummy;
6035 				l_ret_val := c_history%notfound;
6036 			end if;
6037 		end if;
6038 	end if;
6039 	p_result := l_ret_val;
6040 	hr_utility.set_location(' Leaving : '  || l_proc, 100);
6041    Exception when others then
6042              --
6043              -- Reset IN OUT parameters and set OUT parameters
6044              --
6045              p_result := null;
6046              raise;
6047 
6048 End IF_ZAP_ELE_ENT;
6049 
6050 -- VSM
6051 Procedure Cancel_Routine (p_sf52_data in out nocopy ghr_pa_requests%rowtype) is
6052 
6053 	l_proc			varchar2(30):='cancel_routine';
6054    l_sf52_data_rec ghr_pa_requests%rowtype;
6055 
6056 	--
6057 
6058 	-- This cursor would fetch active chain of subsequent corrections.
6059 	cursor c_get_subs_corr (c_pa_request_id	in number,
6060 					c_noa_id		in number) is
6061 	select
6062 		 pa_request_id
6063 		,object_version_number
6064 		,status
6065 		,rowid row_id
6066 	from ghr_pa_requests
6067 	where (level = 1 or ( level > 1 								and
6068 		nvl(second_noa_cancel_or_correct, '@#$') <> ghr_history_api.g_cancel))	and
6069 		first_noa_code <> '001'									and
6070 		nvl(status, '@!#') <> 'CANCELED'
6071 	start with pa_request_id = c_pa_request_id
6072 	connect by  prior pa_request_id	= altered_pa_request_id and
6073 			prior c_noa_id 		= second_noa_id;
6074 
6075 
6076 	TYPE array_pa_req is table of pa_req_info index by binary_integer;
6077 	l_subsequent_pa_req	array_pa_req;
6078 	l_count			number:=0;
6079 	l_rev_count			number;
6080 	l_noa_id			ghr_pa_requests.first_noa_id%type;
6081 	l_sf52_canc			ghr_pa_requests%rowtype;
6082 	l_sf52			ghr_pa_requests%rowtype;
6083 	l_canc_pa_request_id	ghr_pa_requests.pa_request_id%type;
6084 	--BUG # 13655849 increased length
6085 	l_username			fnd_user.user_name%type :=fnd_global.user_name;
6086 	l_null_sf52			ghr_pa_requests%rowtype;
6087 	l_ovn				number;
6088 	l_which_noa			number;
6089 	--
6090 Begin
6091 	hr_utility.set_location( 'Entering : ' || l_proc, 10);
6092 	hr_utility.set_location( 'PA_Request_id : ' || p_sf52_data.pa_request_id || '   ' || l_proc, 15);
6093    l_sf52_data_rec := p_sf52_data;
6094 
6095 	-- Fetch Original SF50 being cancelled
6096 	for v_get_sf52 in c_get_sf52 ( p_sf52_data.altered_pa_request_id)
6097 	loop
6098 		l_sf52 := v_get_sf52;
6099 		exit;
6100 	end loop;
6101 
6102 	--
6103 	--
6104 
6105 	l_noa_id := p_sf52_data.second_noa_id;
6106 
6107 	-- >> Build array of subsequent corrections;
6108 	for v_pa_req in c_get_subs_corr ( p_sf52_data.altered_pa_request_id, p_sf52_data.second_noa_id)
6109 	loop
6110 		hr_utility.set_location( 'Sub Pa_request_id  : ' || v_pa_req.pa_request_id || '   ' || l_proc, 20);
6111 		l_count := l_count + 1;
6112 		l_subsequent_pa_req(l_count).pa_request_id		:= v_pa_req.pa_request_id;
6113 		l_subsequent_pa_req(l_count).object_version_number	:= v_pa_req.object_version_number;
6114 		l_subsequent_pa_req(l_count).status				:= v_pa_req.status;
6115 		l_subsequent_pa_req(l_count).row_id				:= v_pa_req.row_id;
6116                 l_subsequent_pa_req(l_count).cancel_legal_authority     := p_sf52_data.first_action_la_code1;
6117 	end loop;
6118 
6119 	l_rev_count := l_count;
6120 
6121 	if l_count = 0 then
6122 		hr_utility.set_location('Subsequent SF52 Tree is blank. Error !!!! ' || l_proc, 40);
6123 	      hr_utility.set_message(8301 , 'GHR_99999_CANC_SF52_NOT_FOUND');
6124 	      hr_utility.raise_error;
6125 	end if;
6126 
6127 
6128 	hr_utility.set_location(' Start Process Subsequent SF52 ' || l_proc , 60);
6129 	while l_rev_count > 0
6130 	loop
6131 		l_sf52_canc := l_null_sf52;
6132 		if l_rev_count = 1 then
6133 			-- original SF52;
6134 			hr_utility.set_location('Processing Original SF52 ' || l_proc , 70);
6135 			l_sf52_canc := p_sf52_data;
6136 			-- Cancel SF52
6137 			Process_Cancel( p_sf52_Data => l_sf52_canc);
6138 		elsif nvl(l_subsequent_pa_req(l_rev_count).status, 'CANCELED') = 'CANCELED' then
6139 			-- No Action required
6140 			hr_utility.set_location('No Action Req. for SF52 :  ' ||
6141 				l_subsequent_pa_req(l_rev_count).pa_request_id || '  ' || l_proc , 80);
6142 		elsif nvl(l_subsequent_pa_req(l_rev_count).status, 'CANCELED') <> 'UPDATE_HR_COMPLETE' then
6143 			-- SF52 has not been processed
6144 			-- Soft Cancel this SF52
6145 			-- No need to re-fetch object_version_number. As this must be last SF52 in the chain and
6146 			-- OVN must not change since last fetch
6147 			hr_utility.set_location('Soft Cancelling SF52 :  ' ||
6148 				l_subsequent_pa_req(l_rev_count).pa_request_id || '  ' || l_proc , 90);
6149 			ghr_sf52_api.end_sf52(
6150 				 p_pa_request_id			=> l_sf52.pa_request_id
6151 				,p_user_name			=> l_username
6152 				,p_par_object_version_number	=> l_subsequent_pa_req(l_rev_count).object_version_number
6153 				,p_action_taken			=> 'CANCELED'
6154 			);
6155 		else
6156 			-- Call Cancel_correction
6157 			hr_utility.set_location('Calling Cancel_subs_correction for SF52 :  ' ||
6158 				l_subsequent_pa_req(l_rev_count).pa_request_id || '  ' || l_proc , 100);
6159 			if l_sf52_canc.first_noa_code = p_sf52_data.second_noa_code then
6160 				hr_utility.set_location('Ist NOA CODE '|| l_proc , 105);
6161 				l_which_noa := 1;
6162 			else
6163 				hr_utility.set_location('2nd NOA CODE '|| l_proc , 105);
6164 				l_which_noa := 2;
6165 			end if;
6166 
6167 			Cancel_subs_correction (
6168 				p_corr_sf52_detail => l_subsequent_pa_req(l_rev_count),
6169 				p_which_noa        => l_which_noa);
6170 			ghr_api.g_api_dml	:= TRUE; --bug# 5389132
6171 		end if;
6172 		l_rev_count := l_rev_count - 1;
6173 	end loop;
6174 
6175 	hr_utility.set_location('Fetching original SF52 ' || l_proc , 110);
6176 
6177 	-- Set column values in the SF50 being Cancelled;
6178 	-- copy first/second_noa_canc_pa_request_id to first/second_noa_pa_request_id
6179 	-- set first/second_noa_canel_correct_flag = 'ghr_history_api.g_cancel
6180 
6181 	l_sf52.object_version_number := get_sf52_ovn ( p_pa_request_id => l_sf52.pa_request_id);
6182 
6183 	if l_sf52.first_noa_code = p_sf52_data.second_noa_code then
6184 		if l_sf52.first_noa_canc_pa_request_id is not null then
6185 			hr_utility.set_location('Reset First_noa_canel_or_correct ' || l_proc , 120);
6186 			ghr_par_upd.upd(
6187 				 p_pa_request_id				=> l_sf52.pa_request_id
6188 				,p_object_version_number		=> l_sf52.object_version_number
6189 				,p_first_noa_pa_request_id		=> l_sf52.first_noa_canc_pa_request_id
6190 				,p_first_noa_cancel_or_correct	=> ghr_history_api.g_cancel
6191 			);
6192 
6193 		end if;
6194 	else
6195 		if l_sf52.second_noa_canc_pa_request_id is not null then
6196 			hr_utility.set_location('Reset Second_noa_canel_or_correct ' || l_proc , 120);
6197 			ghr_par_upd.upd(
6198 				 p_pa_request_id				=> l_sf52.pa_request_id
6199 				,p_object_version_number		=> l_sf52.object_version_number
6200 				,p_second_noa_pa_request_id		=> l_sf52.second_noa_canc_pa_request_id
6201 				,p_second_noa_cancel_or_correct	=> ghr_history_api.g_cancel
6202 			);
6203 		end if;
6204 	end if;
6205 
6206 	hr_utility.set_location(' Leaving ' || l_proc , 200);
6207    Exception when others then
6208              --
6209              -- Reset IN OUT parameters and set OUT parameters
6210              --
6211              p_sf52_data := l_sf52_data_rec;
6212              raise;
6213 
6214 
6215 End Cancel_routine;
6216 
6217 Procedure Process_Cancel (
6218 		p_sf52_data in out nocopy ghr_pa_requests%rowtype) is
6219 
6220 	l_noa_family_code		varchar2(30);
6221 	l_proc			varchar2(30):='Process_Cancel';
6222 	l_prev_sf52_data		ghr_pa_requests%rowtype;
6223 	l_sf52_data		      ghr_pa_requests%rowtype;
6224 
6225       l_posn_eff_start_date   date;
6226       l_posn_eff_end_date     date;
6227       l_prior_posn_ovn        number;
6228 
6229 
6230 	-- Cursor to fetch noa_codes for given pa_request_id
6231 	cursor c_sf52 (c_pa_request_id in number) is
6232 	select
6233 		*
6234 	from ghr_pa_requests
6235 	where pa_request_id = c_pa_request_id;
6236 
6237 	-- cursor to fetch noa_family_code for the given noa_id.
6238 	cursor c_fam (c_noa_id in number) is
6239 	select
6240 		fams.noa_family_code
6241 	from  ghr_noa_families noafam,
6242 		ghr_families     fams
6243 	where noafam.nature_of_action_id = c_noa_id               and
6244 		noafam.enabled_flag        = 'Y'                    and
6245 		fams.noa_family_code 	   = noafam.noa_family_code and
6246 		fams.enabled_flag          = 'Y'                    and
6247 		fams.update_hr_flag = 'Y';
6248 
6249 	-- Start of Bug# 5195518
6250 
6251 	Cursor get_fehb_life_events(p_person_id in number,
6252 	                           p_business_group_id in number,
6253 				   p_effective_date in date)
6254 	    is
6255 	    select  per_in_ler_id, ptnl_ler_for_per_stat_cd
6256 	    from    ben_per_in_ler pil,
6257 	            ben_ler_f lf,
6258 	            ben_ptnl_ler_for_per ptnl
6259             where pil.person_id = p_person_id
6260             and pil.business_group_id = p_business_group_id
6261             and pil.lf_evt_ocrd_dt = p_effective_date
6262             and pil.PER_IN_LER_STAT_CD IN ('PROCD','STRTD')
6263             and lf.ler_id = pil.ler_id
6264 	    and pil.ptnl_ler_for_per_id = ptnl.ptnl_ler_for_per_id
6265             and name <> 'Unrestricted'
6266             and p_effective_date between lf.effective_start_date
6267                                  and lf.effective_end_date;
6268 
6269         Cursor get_tsp_life_events(p_person_id in number,
6270 	                           p_business_group_id in number,
6271 				   p_effective_date in date)
6272 	    is
6273 	    select per_in_ler_id,PER_IN_LER_STAT_CD
6274 	    from ben_per_in_ler pil,ben_ler_f lf
6275             where pil.person_id = p_person_id
6276             and pil.business_group_id = p_business_group_id
6277             and pil.lf_evt_ocrd_dt = p_effective_date
6278             and PER_IN_LER_STAT_CD IN ('PROCD','STRTD')
6279             and lf.ler_id = pil.ler_id
6280             and name = 'Unrestricted'
6281             and p_effective_date between lf.effective_start_date
6282                                  and lf.effective_end_date;
6283 
6284 	Cursor c_chk_pa_request(p_person_id in number
6285 	                       ,p_effective_date in date)
6286 	    is
6287 	    select 1
6288 	    from   ghr_pa_requests par
6289 	    where  person_id = p_person_id
6290 	    and    effective_date <= p_effective_date
6291 	    and    first_noa_code not in ('100')
6292 	    and    pa_notification_id is not null
6293 	    and    not exists (select 1
6294 	                       from  ghr_pa_requests b
6295 			       where person_id = p_person_id
6296 			       and   altered_pa_request_id = par.pa_request_id
6297 			       and   first_noa_code = '001'
6298 			       and   second_noa_code = par.first_noa_code);
6299 
6300 
6301         Cursor    c_bg_id(c_person_id per_all_people_f.person_id%type,
6302     		          c_effective_date per_all_people_f.effective_start_date%type)
6303             is
6304             select   business_group_id bg_id
6305             from     per_all_people_f
6306             where    person_id = c_person_id
6307             and      c_effective_date between effective_start_date
6308 	                              and     effective_end_date;
6309 
6310         Cursor c_get_pgm_id(c_prog_name ben_pgm_f.name%type,
6311 	                    c_business_group_id ben_pgm_f.business_group_id%type,
6312 		            c_effective_date ben_pgm_f.effective_start_date%type)
6313 	    is
6314 	    select pgm.pgm_id
6315 	    from   ben_pgm_f pgm
6316 	    where  pgm.name = c_prog_name
6317 	    and    pgm.business_group_id  = c_business_group_id
6318 	    and    c_effective_date between effective_start_date and effective_end_date;
6319 
6320         Cursor c_get_enrt_rslt(p_person_id      per_all_people_f.person_id%type,
6321 	                       p_pgm_id         ben_pgm_f.pgm_id%type,
6322 			       p_per_in_ler_id  ben_per_in_ler.per_in_ler_id%type,
6323 			       p_effective_date date)
6324             is
6325             select prtt_enrt_rslt_id,
6326 	           object_version_number,
6327 		   effective_start_date,
6328 		   enrt_cvg_thru_dt
6329    	    from   ben_prtt_enrt_rslt_f
6330 	    where  person_id = p_person_id
6331 	    and    pgm_id    = p_pgm_id
6332 	    and    per_in_ler_id = p_per_in_ler_id
6333 	    and    p_effective_date between effective_start_date and effective_end_date
6334 	    and    enrt_cvg_strt_dt >= p_effective_date;
6335 
6336 
6337 
6338 
6339         l_bg_id number;
6340 	l_effective_start_date date;
6341 	l_effective_end_date   date;
6342 	l_object_version_number number;
6343 	l_pgm_id  number;
6344 	l_deenrtsp boolean;
6345 	l_datetrack_mode  varchar2(30);
6346      	--End of Bug# 5195518
6347  Begin
6348 
6349 	-- Cancellation
6350 	hr_utility.set_location( 'Entering ' || l_proc, 10);
6351    l_sf52_data := p_sf52_data;
6352 	-- get first_noa_code and second_noa_code for the pa_request that this cancellation is being
6353 	-- applied to.
6354 	open c_sf52( p_sf52_data.altered_pa_request_id);
6355 	fetch c_sf52 into l_prev_sf52_data;
6356 	if not c_sf52%found then
6357 		close c_sf52;
6358 		-- original SF52 not found
6359 		hr_utility.set_location(' Parent of pa_request_id : ' ||
6360 					p_sf52_data.pa_request_id || ' Not Found. !! ERROR !! ' || l_proc , 20);
6361 	      hr_utility.set_message(8301 , 'GHR_38221_CORR_SF50_NOT_FOUND');
6362 		ghr_api.g_api_dml	:= FALSE;
6363 	      hr_utility.raise_error;
6364 		-- raise error
6365 	else
6366 		hr_utility.set_location( l_proc, 30);
6367 		if l_prev_sf52_data.first_noa_code = '002' then
6368 			-- Cancellation of the correction
6369 			hr_utility.set_location( l_proc, 40);
6370 			ghr_corr_canc_sf52.Cancel_Correction_SF52( p_sf52_data);
6371 		else
6372                  -------------------------------------------------
6373                  -- JH Bug 2983738 Position Hiring Status Changes Generic to All Cancellations.
6374                  -------------------------------------------------
6375                  --l_posn_eff_start_date date;
6376                  --l_posn_eff_end_date date;
6377                  --l_prior_posn_ovn            number;
6378 
6379                  hr_utility.set_location('JH Hiring Status Start'|| l_proc,45);
6380                  hr_utility.set_location('First NOA code = '||l_sf52_data.first_noa_code || l_proc,45);
6381 
6382                  IF l_sf52_data.first_noa_code = '001' THEN
6383                     hr_utility.set_location('From Posn ID = '||to_char(l_sf52_data.from_position_id)|| l_proc,45);
6384                     hr_utility.set_location('Effective Date = '||l_sf52_data.effective_date|| l_proc,45);
6385                     -- Tests for Position in Non-Active status ON the effective Date.
6386                     posn_not_active(p_position_id         => l_sf52_data.from_position_id
6387                                    ,p_effective_date      => l_sf52_data.effective_date
6388                                    ,p_posn_eff_start_date => l_posn_eff_start_date
6389                                    ,p_posn_eff_end_date   => l_posn_eff_end_date
6390                                    ,p_prior_posn_ovn      => l_prior_posn_ovn);
6391 
6392                     IF l_posn_eff_start_date IS NULL THEN
6393                        -- Test if user manually set position to non-active day AFTER the effective date.
6394                        posn_not_active(p_position_id         => l_sf52_data.from_position_id
6395                                       ,p_effective_date      => l_sf52_data.effective_date+1
6396                                       ,p_posn_eff_start_date => l_posn_eff_start_date
6397                                       ,p_posn_eff_end_date   => l_posn_eff_end_date
6398                                       ,p_prior_posn_ovn      => l_prior_posn_ovn);
6399                     END IF;
6400 
6401                     hr_utility.set_location('Hiring Status Start/End : '||l_posn_eff_start_date||'/'||l_posn_eff_end_date,45);
6402 
6403                     IF l_posn_eff_start_date IS NOT NULL THEN
6404                       hr_utility.set_location('Hiring Status - Calling Delete API',45);
6405                       hr_position_api.delete_position(p_validate              => FALSE
6406                                                      ,p_position_id           => to_number(l_sf52_data.from_position_id)
6407                                                      ,p_effective_date        => l_posn_eff_start_date-1
6408                                                      ,p_effective_start_date  => l_posn_eff_start_date
6409                                                      ,p_effective_end_date    => l_posn_eff_end_date
6410                                                      ,p_object_version_number => l_prior_posn_ovn
6411                                                      ,p_datetrack_mode        => 'DELETE_NEXT_CHANGE');
6412                     END IF;
6413                     hr_utility.set_location('Hiring Status - Exiting',45);
6414                   END IF; -- Cancellations Bug 2983738
6415 
6416 
6417 
6418 			hr_utility.set_location( l_proc, 50);
6419 			open c_fam( p_sf52_data.second_noa_id);
6420 			fetch c_fam into
6421 				l_noa_family_code;
6422 			if c_fam%notfound then
6423 				-- error
6424 				close c_fam;
6425 			      hr_utility.set_message(8301,'GHR_38211_NOA_FAMILY_NOTFOUND');
6426 			      hr_utility.raise_error;
6427 			else
6428 				close c_fam;
6429 			end if;
6430 			 -- Bug # 5195518
6431 			 IF l_noa_family_code in ('APP','CONV_APP','SEPARATION') THEN
6432                 	   FOR l_cur_bg_id IN c_bg_id(p_sf52_data.person_id, p_sf52_data.effective_date)
6433 			   LOOP
6434 			       l_bg_id := l_cur_bg_id.bg_id;
6435                  	   END LOOP;
6436 			   -- Bug  4122470 added FEGLI
6437         		   IF ghr_utility.is_ghr_ben_fehb = 'TRUE' or ghr_utility.is_ghr_ben_fegli = 'TRUE' THEN
6438 			      For rec_le in get_fehb_life_events(p_person_id => p_sf52_data.person_id,
6439                         	                                p_business_group_id => l_bg_id,
6440                              				        p_effective_date => p_sf52_data.effective_date)
6441 			      loop
6442 
6443 			        ben_back_out_life_event.back_out_life_events
6444                                              (p_per_in_ler_id     => rec_le.per_in_ler_id,
6445                                               p_business_group_id => l_bg_id,
6446                                               p_bckt_stat_cd      => 'VOIDD',
6447                                               p_copy_only         => 'N' ,
6448                                               p_effective_date    => p_sf52_data.effective_date);
6449                                end loop;
6450 			    END IF;
6451 			  END IF;
6452 			  --Checking whether it is reappointment after separation
6453 			  -- it should not be deenrolled for reappointment.
6454 			/*  For rec_pa_req in c_chk_pa_request(p_person_id => p_sf52_data.person_id
6455                                                             ,p_effective_date => p_sf52_data.effective_date)
6456 			  loop
6457 			     l_deenrtsp := TRUE;
6458 			  end loop;
6459 
6460  		          IF l_deenrtsp then
6461               		    l_datetrack_mode := hr_api.g_delete_next_change;
6462            		  ELSE
6463               		    l_datetrack_mode :=  hr_api.g_zap;
6464              		  END IF;      */
6465 
6466 
6467 			  hr_utility.set_location('p_sf52_data.effective_date'||p_sf52_data.effective_date,1000);
6468 			  IF l_noa_family_code in ('APP','CONV_APP') THEN
6469 			    IF ghr_utility.is_ghr_ben_tsp = 'TRUE' THEN
6470 			      For rec_le in get_tsp_life_events(p_person_id => p_sf52_data.person_id,
6471                         	                                p_business_group_id => l_bg_id,
6472                              				        p_effective_date => p_sf52_data.effective_date)
6473 			      loop
6474 
6475 			         for pgm_rec in c_get_pgm_id('Federal Thrift Savings Plan (TSP)', l_bg_id, p_sf52_data.effective_date)
6476 				 loop
6477 				     l_pgm_id := pgm_rec.pgm_id;
6478           			     exit;
6479                                  end loop;
6480 
6481 
6482 				 for enrt_rec in c_get_enrt_rslt(p_person_id      => p_sf52_data.person_id,
6483                                       	                         p_pgm_id         => l_pgm_id,
6484                                        			         p_per_in_ler_id  => rec_le.per_in_ler_id,
6485                                 			         p_effective_date => p_sf52_data.effective_date)
6486                                  loop
6487 				   IF  enrt_rec.effective_start_date = p_sf52_data.effective_date THEN
6488 
6489 				       l_object_version_number := enrt_rec.object_version_number;
6490    			               ben_prtt_enrt_result_api.delete_enrollment
6491 						 (p_validate              => false
6492 						 ,p_per_in_ler_id         => rec_le.per_in_ler_id
6493 						 ,p_prtt_enrt_rslt_id     => enrt_rec.prtt_enrt_rslt_id
6494 						 ,p_business_group_id     => l_bg_id
6495 						 ,p_effective_start_date  => l_effective_start_date
6496 						 ,p_effective_end_date    => l_effective_end_date
6497 						 ,p_object_version_number => l_object_version_number
6498 						 ,p_effective_date        => enrt_rec.effective_start_date
6499 						 ,p_datetrack_mode        => hr_api.g_zap
6500 						 ,p_enrt_cvg_thru_dt      => enrt_rec.enrt_cvg_thru_dt
6501 						 ,p_multi_row_validate    => FALSE);
6502 			             END IF;
6503                                   end loop;
6504 			       end loop;
6505 			     END IF;
6506 			 END IF;
6507 			 -- End of Bug # 5195518
6508 				if l_noa_family_code = 'APP' then
6509 				-- must be checked for the appt. family
6510 				-- Cancellation of an appointment
6511 				hr_utility.set_location( l_proc, 60);
6512 				ghr_corr_canc_sf52.Cancel_Appt_SF52( p_sf52_data);
6513 				null;
6514 			elsif l_noa_family_code = 'SEPARATION' then
6515 				-- cancellation of termination
6516 				hr_utility.set_location( l_proc, 70);
6517 				ghr_corr_canc_sf52.cancel_term_sf52( p_sf52_data);
6518 		--	elsif l_noa_code like '9%' then
6519 		--		-- user defined families not supported by update to database
6520 		--		-- should generate a message and raise_error here.
6521 		--		hr_utility.set_location( l_proc, 80);
6522 		--		NULL;
6523 		-- user defined NOA would be treated as any other family in cancel_other_family_sf52
6524 		-- if these don't belong to special families (APP/SEPARATION)
6525 			else
6526 				hr_utility.set_location( l_proc, 90);
6527 				ghr_corr_canc_sf52.Cancel_Other_Family_Sf52( p_sf52_data);
6528 			end if;
6529 
6530 
6531 
6532 
6533 		end if;
6534 	end if;
6535 		close c_sf52;
6536    Exception when others then
6537              --
6538              -- Reset IN OUT parameters and set OUT parameters
6539              --
6540              p_sf52_data := l_sf52_data;
6541              raise;
6542 End Process_Cancel;
6543 
6544 Procedure Cancel_subs_correction (
6545 		p_corr_sf52_detail in out nocopy pa_req_info,
6546 		p_which_noa        in number) is
6547 
6548 	l_proc			varchar2(30):='Cancel_subs_correction';
6549 	l_ovn				number;
6550 	l_canc_pa_request_id	number;
6551 	l_noa_id			number;
6552 	--BUG # 13655849 increased length
6553 	l_username			fnd_user.user_name%type;
6554 	l_dummy_number		number;
6555 	l_sf52_canc			ghr_pa_requests%rowtype;
6556    l_corr_sf52_detail pa_req_info;
6557 
6558 cursor c_get_asg_id is
6559           select employee_assignment_id
6560             from ghr_pa_requests
6561             where pa_request_id in
6562           ( select altered_pa_request_id from
6563              ghr_pa_requests where
6564              pa_request_id =  p_corr_sf52_detail.pa_request_id);
6565         l_asg_id            per_assignments_f.assignment_id%type;
6566 
6567 
6568 Begin
6569 
6570 	-- create cancellation;
6571 	hr_utility.set_location(' Call ghr_cancel_sf52 ' || p_corr_sf52_detail.pa_request_id ||
6572 				l_proc , 80);
6573    l_corr_sf52_detail := p_corr_sf52_detail;
6574  -- Start Bug  2542417
6575         -- Fetching employee_assignment_id to pass in ghr_sf52_api.update_sf52
6576         -- In the Cancellation of Subsequent corrections assignment id is
6577         -- missing in call to get_cop in ghr_sf52_api.update_sf52
6578         -- This passing of l_asg_id in the call below fixes the issue
6579         for c_get_asg_rec in c_get_asg_id LOOP
6580           l_asg_id := c_get_asg_rec.employee_assignment_id;
6581           exit;
6582         END LOOP;
6583         hr_utility.set_location(' l_asg_id is ' || l_asg_id || '   ' || l_proc , 90);
6584  -- End Bug  2542417
6585 
6586 
6587 --	l_username			:= fnd_global.user_name;
6588 	l_username			:= fnd_profile.value('USERNAME');
6589     -- Bug#5260624 If the profile value returns NULL, get it from fnd_global.
6590 	IF l_username is NULL THEN
6591 		l_username			:= fnd_global.user_name;
6592     END IF;
6593 
6594 	l_ovn := NULL;
6595 
6596 	for v_get_sf52 in c_get_sf52 ( p_corr_sf52_detail.pa_request_id)
6597 	loop
6598 		l_ovn    := v_get_sf52.object_version_number;
6599 		l_noa_id := v_get_sf52.second_noa_id;
6600 		exit;
6601 	end loop;
6602 
6603 	if l_ovn is NULL then
6604 	      hr_utility.set_message(8301 , 'GHR_99999_SF52_NOT_FOUND');
6605 	      hr_utility.raise_error;
6606 	end if;
6607 
6608 	hr_utility.set_location(' User name  ' || l_username || '   ' || l_proc , 90);
6609 
6610 	l_canc_pa_request_id := ghr_approved_pa_requests.ghr_cancel_sf52(
6611 		 p_pa_request_id			=> p_corr_sf52_detail.pa_request_id
6612 		,p_par_object_version_number	=> l_ovn
6613 		,p_noa_id				=> l_noa_id
6614 		,p_which_noa			=> p_which_noa
6615 		,p_row_id				=> p_corr_sf52_detail.row_id
6616 		,p_username				=> l_username
6617                 ,p_cancel_legal_authority       => p_corr_sf52_detail.cancel_legal_authority);
6618 
6619 	-- fetch cancel sf52;
6620 	if nvl(l_canc_pa_request_id, 0 ) = 0 then
6621 		hr_utility.set_location(' Cancellation SF52 not created!! ERROR !! ' || l_proc , 90);
6622 	      hr_utility.set_message(8301 , 'GHR_99999_CREA_CANC_52_FAIL');
6623 	      hr_utility.raise_error;
6624 	end if;
6625 	for v_get_sf52 in c_get_sf52(l_canc_pa_request_id)
6626 	loop
6627 		l_sf52_canc := v_get_sf52;
6628 		exit;
6629 	end loop;
6630 	if l_sf52_canc.pa_request_id is NULL then
6631 		hr_utility.set_location(' Fetch Cancel SF52 failed. ERROR !! ' || l_proc , 100);
6632 	      hr_utility.set_message(8301 , 'GHR_99999_SF52_NOT_FOUND');
6633 	      hr_utility.raise_error;
6634 	end if;
6635 
6636 	-- Call update_sf52
6637 	-- This is a recursive call as Process_SF52 is called from ghr_sf52_api.update_sf52
6638 	hr_utility.set_location(' BEGIN Update_SF52 for pa_request_id : ' ||
6639 					l_sf52_canc.pa_request_id || '  ' || l_proc , 110);
6640         hr_utility.set_location('l_dummy_number '||to_char(l_dummy_number),120);
6641 	hr_utility.set_location('l_OVN '||to_char(l_sf52_canc.object_version_number),130);
6642 	hr_utility.set_location('l_ASG '||to_char(l_asg_id),140);
6643 	ghr_sf52_api.update_sf52(
6644 		 p_pa_request_id			=> l_sf52_canc.pa_request_id
6645                  ,p_employee_assignment_id       => l_asg_id
6646 		-- OUT parameters
6647 		,p_par_object_version_number	=> l_sf52_canc.object_version_number
6648 		,p_u_prh_object_version_number=> l_dummy_number
6649 		,p_i_pa_routing_history_id	=> l_dummy_number
6650 		,p_i_prh_object_version_number=> l_dummy_number
6651 		,p_u_action_taken			=> 'UPDATE_HR'
6652 		,p_u_approval_status		=> 'APPROVE'
6653 	);
6654 
6655 	hr_utility.set_location(' END Update_SF52 for pa_request_id : ' ||
6656 					l_sf52_canc.pa_request_id || '  ' || l_proc , 120);
6657 
6658 	-- Nullify Second_noa_pa_request_id from Correction SF52 beinf cancelled
6659 	ghr_par_upd.upd(
6660 		 p_pa_request_id			=> p_corr_sf52_detail.pa_request_id
6661 		,p_object_version_number	=> l_ovn
6662 		,p_second_noa_pa_request_id	=> NULL);
6663 
6664 	-- Delete GHR_Routing_History
6665 	delete from ghr_pa_routing_history
6666 	where pa_request_id = l_sf52_canc.pa_request_id;
6667 
6668       -- Delete Pa_request_EI_shadow data
6669       delete ghr_pa_request_ei_shadow
6670       where  pa_request_id = l_sf52_canc.pa_request_id;
6671 
6672 	-- Delete Cancelation SF50 Shadow row
6673 	hr_utility.set_location(' Deleting Shadow ' || l_sf52_canc.pa_request_id || '  ' || l_proc , 130);
6674 	Delete from ghr_pa_request_shadow
6675 	where pa_request_id = l_sf52_canc.pa_request_id;
6676 
6677       -- Delete Pa_request_EI data
6678       -- for l_sf52_canc.pa_request_id;
6679       delete ghr_pa_request_extra_info
6680       where  pa_request_id = l_sf52_canc.pa_request_id;
6681 
6682 	-- Delete pa_reques row
6683 	l_sf52_canc.object_version_number := get_sf52_ovn( l_sf52_canc.pa_request_id);
6684 
6685 	hr_utility.set_location(' Deleting Pa Request  ' || l_sf52_canc.pa_request_id || '  ' || l_proc , 140);
6686 	ghr_par_del.del(
6687 		p_pa_request_id 		=> l_sf52_canc.pa_request_id,
6688 		p_object_version_number => l_sf52_canc.object_version_number);
6689 
6690 	hr_utility.set_location(' Leaving ' || l_proc , 200);
6691   Exception when others then
6692             --
6693             -- Reset IN OUT parameters and set OUT parameters
6694             --
6695             p_corr_sf52_detail := l_corr_sf52_detail;
6696             raise;
6697 
6698 End Cancel_subs_correction;
6699 -- VSM
6700 
6701 -- Bug#2521744 Added the following procedure
6702 -- LOGIC :
6703 -- Check for the element passed to this procedure.
6704 -- If element = 'OTHER PAY' THEN
6705 -- Check whether another other pay action processed on the same effective date;
6706 --      IF processed then
6707 --          fetch the other pay value using history id and element entry id.
6708 --          update the pay_element_entry_values_f table with the correct value.
6709 --       ELSE
6710 --          Delete the rows from pay_element_entry_values_f, pay_element_entries_f tables;
6711 --        END If;
6712 -- ELSIF element IN ('Retention Allowance', 'Supervisory Differential,'AUO','Availability Pay' Then
6713 --    Delete the rows from pay_element_entry_values_f, pay_element_entries_f tables;
6714 -- ELSE
6715 --    Delete the rows from pay_element_entry_values_f, pay_element_entries_f tables with id and effective start date;
6716 -- END If;
6717 
6718 Procedure delete_other_pay_entries(p_hist_rec in ghr_pa_history%rowtype,
6719                                    p_element_name IN VARCHAR2 ) IS
6720 
6721 l_history_exists               BOOLEAN := FALSE;
6722 l_hist_rec                     ghr_pa_history%rowtype;
6723 l_future_othpay_effective_date DATE;
6724 l_bus_group_id                 NUMBER;
6725 l_element_name                 VARCHAR2(80);
6726 
6727 CURSOR c_history_record IS
6728 SELECT *
6729 FROM  ghr_pa_history
6730 WHERE table_name = 'PAY_ELEMENT_ENTRIES_F'
6731 AND   information1 = p_hist_rec.information1
6732 AND   information2 = p_hist_rec.information2
6733 AND   nvl(pa_request_id,0) <> nvl(p_hist_rec.pa_request_id,0);
6734 
6735 
6736 -- CURSOR to verify whether any future other pay action is existing or not.
6737 CURSOR c_future_other_pay_exists(p_assignment_id NUMBER,p_effective_date DATE) IS
6738 SELECT min(effective_date) effective_date
6739 FROM ghr_pa_requests
6740 where noa_family_code = 'OTHER_PAY'
6741 and pa_notification_id is not null
6742 and effective_date > p_effective_date
6743 and status = 'UPDATE_HR_COMPLETE'
6744 and employee_assignment_id = p_assignment_id
6745 and NVL(first_noa_cancel_or_correct,'C') <> 'CANCEL';
6746 
6747 
6748 BEGIN
6749     hr_utility.set_location('Entering Delete Oth Pay Entr '||p_element_name,0);
6750 
6751     fnd_profile.get('PER_BUSINESS_GROUP_ID',l_bus_group_id);
6752     l_element_name := pqp_fedhr_uspay_int_utils.return_old_element_name
6753                       (p_element_name,l_bus_group_id,p_hist_rec.effective_date);
6754     hr_utility.set_location('l_element_name IS '||l_element_name,10);
6755     IF l_element_name = 'Other Pay' THEN
6756         Open c_history_record;
6757         Fetch c_history_record into l_hist_rec;
6758         IF c_history_record%NOTFOUND THEN
6759            l_history_exists := FALSE;
6760         ELSE
6761            l_history_exists  := TRUE;
6762         END IF;
6763         Close c_history_record;
6764 
6765 
6766         IF l_history_exists THEN
6767             hr_utility.set_location('Same day action',70);
6768         ELSE
6769 	    -- Check whether any future dated OTHER PAY Actions exists or not
6770 	    FOR future_other_pay IN c_future_other_pay_exists(p_hist_rec.information5,p_hist_rec.effective_date)
6771 	    LOOP
6772 		l_future_othpay_effective_date := future_other_pay.effective_date;
6773 	    END LOOP;
6774 	    -- IF any Future other pay action exists,
6775 	    --   Delete the other pay element from this effective date to the future
6776 	    --   other pay action (effective date - 1).
6777 	    -- Else
6778 	    --   Delete the Other Pay element with this element entry ID.
6779 	    -- End If;
6780 	    IF l_future_othpay_effective_date IS NOT NULL THEN
6781 	            hr_utility.set_location(' Inside Future Other Pay Exists',20);
6782 		    --  DELETE THE RECORD FROM PAY_ELEMENT_ENTRY_VALUES_F;
6783 		    DELETE pay_element_entry_values_f
6784 		    where  element_entry_id = p_hist_rec.information1
6785 		    AND    effective_start_date BETWEEN fnd_date.canonical_to_date(p_hist_rec.information2)
6786 		                                    AND (l_future_othpay_effective_date - 1) ;
6787 
6788 	            hr_utility.set_location(' After deleting Other pay element entries',30);
6789 		    --	DELETE THE RECORD FROM PAY_ELEMENT_ENTRIES_F;
6790 		    DELETE PAY_ELEMENT_ENTRIES_F
6791 		    where  element_entry_id = p_hist_rec.information1
6792 		    AND    effective_start_date BETWEEN fnd_date.canonical_to_date(p_hist_rec.information2)
6793 		                                    AND (l_future_othpay_effective_date - 1) ;
6794 
6795 		    -- DELETE THE HISTORY RECORDS with the same element entry ID created after the current
6796 		    -- action and prior to the next other pay action.
6797 		    DELETE ghr_pa_history
6798                     WHERE (information5 = p_hist_rec.information1
6799                        OR  information1 = p_hist_rec.information1)
6800                       AND effective_date BETWEEN (fnd_date.canonical_to_date(p_hist_rec.information2) + 1)
6801 		                             AND (l_future_othpay_effective_date - 1);
6802 
6803 	    ELSE
6804 		    hr_utility.set_location(' No Future Other Pay Action exists.',40);
6805 		    --	DELETE THE RECORD FROM PAY_ELEMENT_ENTRY_VALUES_F;
6806 		    DELETE pay_element_entry_values_f
6807 		    where  element_entry_id = p_hist_rec.information1;
6808 
6809 
6810 		    --	DELETE THE RECORD FROM PAY_ELEMENT_ENTRIES_F;
6811 		    DELETE PAY_ELEMENT_ENTRIES_F
6812 		    where  element_entry_id = p_hist_rec.information1;
6813 
6814 		    -- DELETE THE HISTORY RECORDS with the same element entry ID created after the
6815 		    -- current other pay action.
6816 		    DELETE ghr_pa_history
6817                     WHERE (information5 = p_hist_rec.information1 OR  information1 = p_hist_rec.information1)
6818                       AND effective_date > (fnd_date.canonical_to_date(p_hist_rec.information2) + 1);
6819 
6820 	    END IF;
6821         END IF;
6822     ELSIF l_element_name IN ('Retention Allowance','Supervisory Differential','AUO',
6823                              'Availability Pay') THEN
6824 	--	DELETE THE RECORD FROM PAY_ELEMENT_ENTRY_VALUES_F;
6825 
6826         DELETE pay_element_entry_values_f
6827         where  element_entry_id = p_hist_rec.information1;
6828         -- AND    effective_start_date = fnd_date.canonical_to_date(p_hist_rec.information2);
6829 
6830         --	DELETE THE RECORD FROM PAY_ELEMENT_ENTRIES_F;
6831 
6832         DELETE PAY_ELEMENT_ENTRIES_F
6833         where  element_entry_id = p_hist_rec.information1;
6834         -- AND    effective_start_date = fnd_date.canonical_to_date(p_hist_rec.information2);
6835 
6836         hr_utility.set_location('Leaving delete_other_pay_entries',170);
6837     ELSE
6838         hr_utility.set_location('Elements Other than OTHER PAY '||p_element_name,110);
6839 
6840         --	DELETE THE RECORD FROM PAY_ELEMENT_ENTRY_VALUES_F;
6841 
6842         DELETE pay_element_entry_values_f
6843         where  element_entry_id = p_hist_rec.information1
6844         AND    effective_start_date = fnd_date.canonical_to_date(p_hist_rec.information2);
6845 
6846         --	DELETE THE RECORD FROM PAY_ELEMENT_ENTRIES_F;
6847 
6848         DELETE PAY_ELEMENT_ENTRIES_F
6849         where  element_entry_id = p_hist_rec.information1
6850         AND    effective_start_date = fnd_date.canonical_to_date(p_hist_rec.information2);
6851 
6852         hr_utility.set_location('Leaving delete_other_pay_entries',70);
6853     END IF;
6854 
6855 EXCEPTION
6856     WHEN OTHERS THEN
6857         hr_utility.set_location('ERROR: '||sqlerrm,80);
6858         hr_utility.set_location('Leaving delete_other_pay_entries',90);
6859 END delete_other_pay_entries;
6860 --
6861 -- Bug#2521744 Added the above procedure
6862 
6863 
6864 Function get_sf52_ovn ( p_pa_request_id in number) return number is
6865 
6866 	cursor c_get_sf52 (c_pa_request_id in number) is
6867 	select
6868 		object_version_number
6869 	from ghr_pa_requests
6870 	where pa_request_id = c_pa_request_id;
6871 
6872 	l_ovn		number;
6873 	l_proc	varchar2(30):='get_sf52_ovn';
6874 Begin
6875 	hr_utility.set_location( 'Entering ' || l_proc, 10);
6876 	for v_get_sf52 in c_get_sf52 (p_pa_request_id)
6877 	loop
6878 		l_ovn := v_get_sf52.object_version_number;
6879 	end loop;
6880 	hr_utility.set_location( 'Leaving ' || l_proc, 20);
6881 
6882 	return l_ovn;
6883 End get_sf52_ovn;
6884 
6885 PROCEDURE get_sf52_to_details_for_ia
6886 (p_pa_request_id in ghr_pa_requests.pa_request_id%type,
6887  p_retro_eff_date in ghr_pa_requests.effective_date%type,
6888  p_sf52_ia_rec in out nocopy ghr_pa_requests%rowtype)
6889 IS
6890 
6891 CURSOR c_from_data IS
6892 SELECT * FROM ghr_pa_requests
6893 WHERE pa_request_id = p_pa_request_id;
6894 
6895 CURSOR c_grade_id(c_business_group_id per_grades.business_group_id%type,
6896 		  c_pay_plan per_grades.name%type,
6897 		  c_grade per_grades.name%type,
6898 		  c_effective_date per_grades.date_from%type) IS
6899 SELECT grade_id
6900 FROM per_grades
6901 WHERE business_group_id = c_business_group_id
6902 AND substr(name,1,2) = c_pay_plan
6903 AND substr(name,length(name)-1) = c_grade
6904 AND c_effective_date BETWEEN NVL(date_from,to_date('01/01/1951','dd/mm/yyyy')) AND NVL(date_to,to_date('31/12/4712','dd/mm/yyyy'));
6905 
6906 l_proc	          varchar2(30):='get_sf52_to_details_for_ia';
6907 l_dummy_varchar   varchar2(30);
6908 l_sf52_ia_rec     ghr_pa_requests%rowtype;
6909 l_business_group_id per_grades.business_group_id%type;
6910 
6911 BEGIN
6912 -- First assign the current From pos items to To pos items
6913 	hr_utility.set_location( 'Entering ' || l_proc, 5);
6914    l_sf52_ia_rec := p_sf52_ia_rec;
6915 FOR c_sf52_data IN c_from_data LOOP
6916   hr_utility.set_location( 'Assigning the from side to sf52_ia_rec ' || l_proc, 5);
6917   p_sf52_ia_rec.to_position_id                := c_sf52_data.from_position_id;
6918   p_sf52_ia_rec.to_position_title             := c_sf52_data.from_position_title;
6919   p_sf52_ia_rec.to_position_number            := c_sf52_data.from_position_number;
6920   p_sf52_ia_rec.TO_POSITION_SEQ_NO            := c_sf52_data.FROM_POSITION_SEQ_NO;
6921   p_sf52_ia_rec.to_occ_code                   := c_sf52_data.from_occ_code;
6922   p_sf52_ia_rec.to_office_symbol              := c_sf52_data.from_office_symbol;
6923   -- Bug#4696860 Added the following IF Condition.
6924   IF NOT (c_sf52_data.noa_family_code IN ('AWARD','GHR_INCENTIVE') OR
6925           ghr_pa_requests_pkg.GET_NOA_PM_FAMILY(c_sf52_data.second_noa_id) IN ('AWARD','GHR_INCENTIVE')) THEN
6926 	  p_sf52_ia_rec.to_pay_basis                  := c_sf52_data.from_pay_basis;
6927 	  p_sf52_ia_rec.to_total_salary               := c_sf52_data.from_total_salary;
6928 	  p_sf52_ia_rec.to_other_pay_amount           := c_sf52_data.from_other_pay_amount;
6929 	  p_sf52_ia_rec.to_adj_basic_pay              := c_sf52_data.from_adj_basic_pay;
6930 	  p_sf52_ia_rec.to_basic_pay                  := c_sf52_data.from_basic_pay;
6931 	  p_sf52_ia_rec.to_grade_or_level             := c_sf52_data.from_grade_or_level;
6932 	  p_sf52_ia_rec.to_locality_adj               := c_sf52_data.from_locality_adj;
6933 	  p_sf52_ia_rec.to_pay_plan                   := c_sf52_data.from_pay_plan;
6934 	  p_sf52_ia_rec.to_step_or_rate               := c_sf52_data.from_step_or_rate;
6935   END IF;
6936   -- Bug 4086845 Need to assign grade id
6937   fnd_profile.get('PER_BUSINESS_GROUP_ID',l_business_group_id);
6938   IF p_sf52_ia_rec.to_pay_plan IS NOT NULL AND
6939      p_sf52_ia_rec.to_grade_or_level IS NOT NULL THEN
6940 	FOR l_get_grade_id IN c_grade_id(l_business_group_id,p_sf52_ia_rec.to_pay_plan,
6941 					 p_sf52_ia_rec.to_grade_or_level,c_sf52_data.effective_date) LOOP
6942 		p_sf52_ia_rec.to_grade_id := l_get_grade_id.grade_id;
6943 		hr_utility.set_location( 'Grade ID ' || p_sf52_ia_rec.to_grade_id, 6);
6944 	END LOOP;
6945   END IF;
6946   -- End Bug 4086845
6947 
6948   -- Bug 2970608 - Do not copy from side pos org details to side for 790 action
6949   IF  nvl(p_sf52_ia_rec.first_noa_code,hr_api.g_varchar2) <> '790' THEN
6950     p_sf52_ia_rec.to_position_org_line1         := c_sf52_data.from_position_org_line1;
6951     p_sf52_ia_rec.to_position_org_line2         := c_sf52_data.from_position_org_line2;
6952     p_sf52_ia_rec.to_position_org_line3         := c_sf52_data.from_position_org_line3;
6953     p_sf52_ia_rec.to_position_org_line4         := c_sf52_data.from_position_org_line4;
6954     p_sf52_ia_rec.to_position_org_line5         := c_sf52_data.from_position_org_line5;
6955     p_sf52_ia_rec.to_position_org_line6         := c_sf52_data.from_position_org_line6;
6956     -- Bug 2639509
6957     -- From postion org lines should be in sync with To Postion Org Lines
6958     p_sf52_ia_rec.from_position_org_line1         := c_sf52_data.from_position_org_line1;
6959     p_sf52_ia_rec.from_position_org_line2         := c_sf52_data.from_position_org_line2;
6960     p_sf52_ia_rec.from_position_org_line3         := c_sf52_data.from_position_org_line3;
6961     p_sf52_ia_rec.from_position_org_line4         := c_sf52_data.from_position_org_line4;
6962     p_sf52_ia_rec.from_position_org_line5         := c_sf52_data.from_position_org_line5;
6963     p_sf52_ia_rec.from_position_org_line6         := c_sf52_data.from_position_org_line6;
6964   END IF;
6965   -- Get position ddf data related to from_position_id
6966   ghr_pa_requests_pkg.get_SF52_pos_ddf_details
6967     (p_position_id            => c_sf52_data.from_position_id
6968     ,p_date_effective         => c_sf52_data.effective_date
6969     ,p_flsa_category          => p_sf52_ia_rec.flsa_category
6970     ,p_bargaining_unit_status => p_sf52_ia_rec.bargaining_unit_status
6971     ,p_work_schedule          => p_sf52_ia_rec.work_schedule
6972     ,p_functional_class       => p_sf52_ia_rec.functional_class
6973     ,p_supervisory_status     => p_sf52_ia_rec.supervisory_status
6974     ,p_position_occupied      => p_sf52_ia_rec.position_occupied
6975     ,p_appropriation_code1    => p_sf52_ia_rec.appropriation_code1
6976     ,p_appropriation_code2    => p_sf52_ia_rec.appropriation_code2
6977     ,p_personnel_office_id    => p_sf52_ia_rec.personnel_office_id
6978      ,p_office_symbol	      => l_dummy_varchar
6979     ,p_part_time_hours        => p_sf52_ia_rec.part_time_hours);
6980   EXIT;
6981 END LOOP;
6982 hr_utility.set_location( 'Leaving' || l_proc, 20);
6983 Exception when others then
6984           --
6985           -- Reset IN OUT parameters and set OUT parameters
6986           --
6987           p_sf52_ia_rec := l_sf52_ia_rec;
6988           raise;
6989 
6990 END get_sf52_to_details_for_ia;
6991 
6992 -- Bug#2521744
6993 -- This procedure will get the other pay component values
6994 -- at the time of intervening correction.
6995 PROCEDURE get_sf52_to_othpays_for_ia
6996             (p_sf52_ia_rec in out nocopy ghr_pa_requests%rowtype) IS
6997 
6998     CURSOR C_element_exists(p_element_name IN VARCHAR2,
6999                             p_assignment_id IN number,
7000                             p_effective_date IN DATE) IS
7001     SELECT  '1'
7002       FROM    pay_element_types_f        elt
7003              ,pay_element_entries_f      ele
7004       WHERE  elt.element_type_id    = ele.element_type_id
7005       AND    elt.element_name= p_element_name
7006       AND    ele.assignment_id      = p_assignment_id
7007       AND    elt.business_group_id is NULL
7008       AND    p_effective_date BETWEEN elt.effective_start_date AND elt.effective_end_date
7009       AND    p_effective_date BETWEEN ele.effective_start_date AND ele.effective_end_date;
7010 
7011 
7012       cursor c_noa_fam_code(p_noa_id  ghr_nature_of_actions.nature_of_action_id%type) is
7013        select fam.noa_family_code
7014         from ghr_noa_families fam
7015        where fam.nature_of_action_id = p_noa_id;
7016 
7017 
7018     l_proc	          varchar2(30):='get_sf52_to_othpays_for_ia';
7019     l_dummy_varchar   varchar2(1);
7020     l_sf52_ia_rec     ghr_pa_requests%rowtype;
7021     l_noa_id          ghr_nature_of_actions.nature_of_action_id%type;
7022     l_noa_fam_code    ghr_noa_families.noa_family_code%type;
7023 
7024 BEGIN
7025     -- First assign the current From pos items to To pos items
7026     hr_utility.set_location( 'Entering ' || l_proc, 5);
7027     l_sf52_ia_rec := p_sf52_ia_rec;
7028     -- Bug#2521744 Added by VVL for testing the correction process.
7029     -- for Other pay Elements update nulls as nulls.
7030     -- Added the following code to check whether the Family is Salary change family or not
7031     -- Depending on that, assign the values of Other Pay components(Retention, Supervisory, AUO etc.)
7032     IF p_sf52_ia_rec.first_noa_code IN ('001','002') THEN
7033        l_noa_id := p_sf52_ia_rec.second_noa_id;
7034     ELSE
7035         l_noa_id := p_sf52_ia_rec.first_noa_id;
7036     END IF;
7037 
7038     FOR noa_fam_rec in c_noa_fam_code(l_noa_id) loop
7039         l_noa_fam_code := noa_fam_rec.noa_family_code;
7040         IF l_noa_fam_code like 'GHR_SAL%' THEN
7041             EXIT;
7042         END IF;
7043     END LOOP;
7044 	hr_utility.set_location('NOA Family Code '||l_noa_fam_code,10000);
7045 	IF (p_sf52_ia_rec.first_noa_code  IN ('810','818','819')  OR
7046 	    p_sf52_ia_rec.second_noa_code IN ('810','818','819') OR
7047 	    l_noa_fam_code like 'GHR_SAL%'
7048 	    ) THEN
7049             -- Check for Retention Allowance Element
7050             Open C_element_exists('Retention Allowance',p_sf52_ia_rec.employee_assignment_id,p_sf52_ia_rec.effective_date);
7051             Fetch c_element_exists into l_dummy_varchar;
7052             IF c_element_exists%NOTFOUND THEN
7053             p_sf52_ia_rec.to_retention_allowance        := NULL;
7054             p_sf52_ia_rec.to_retention_allow_percentage := NULL;
7055             END IF;
7056             close c_element_exists;
7057 
7058             -- Check for Supervisory Differential Element
7059             Open C_element_exists('Supervisory Differential',p_sf52_ia_rec.employee_assignment_id,p_sf52_ia_rec.effective_date);
7060             Fetch c_element_exists into l_dummy_varchar;
7061             IF c_element_exists%NOTFOUND THEN
7062             p_sf52_ia_rec.to_Supervisory_Differential        := NULL;
7063             p_sf52_ia_rec.to_Supervisory_Diff_percentage := NULL;
7064             END IF;
7065             close c_element_exists;
7066 
7067             -- Check for AUO Element
7068             Open C_element_exists('AUO',p_sf52_ia_rec.employee_assignment_id,p_sf52_ia_rec.effective_date);
7069             Fetch c_element_exists into l_dummy_varchar;
7070             IF c_element_exists%NOTFOUND THEN
7071             p_sf52_ia_rec.to_au_overtime       := NULL;
7072             p_sf52_ia_rec.to_auo_premium_pay_indicator := NULL;
7073             END IF;
7074             close c_element_exists;
7075             -- Check for Availability Pay Element
7076 
7077             Open C_element_exists('Availability Pay',p_sf52_ia_rec.employee_assignment_id,p_sf52_ia_rec.effective_date);
7078             Fetch c_element_exists into l_dummy_varchar;
7079             IF c_element_exists%NOTFOUND THEN
7080             p_sf52_ia_rec.to_availability_pay        := NULL;
7081             p_sf52_ia_rec.to_ap_premium_pay_indicator := NULL;
7082             END IF;
7083             close c_element_exists;
7084         END IF;
7085         -- End of Bug#2521744 Changes.
7086         hr_utility.set_location( 'Leaving' || l_proc, 20);
7087 
7088 EXCEPTION
7089     WHEN OTHERS THEN
7090         --
7091         -- Reset IN OUT parameters and set OUT parameters
7092         --
7093         p_sf52_ia_rec := l_sf52_ia_rec;
7094         RAISE;
7095 
7096 END get_sf52_to_othpays_for_ia;
7097 
7098 
7099 -- JH Bug 2983738 Position Hiring Status Changes.
7100 PROCEDURE posn_not_active(p_position_id         in number
7101                          ,p_effective_date      in date
7102                          ,p_posn_eff_start_date OUT NOCOPY date
7103                          ,p_posn_eff_end_date   OUT NOCOPY date
7104                          ,p_prior_posn_ovn      OUT NOCOPY number)
7105 IS
7106 
7107 CURSOR c_posn IS
7108  select apf.effective_start_date, apf.effective_end_date
7109  from   HR_ALL_POSITIONS_F apf
7110  where  apf.position_id = p_position_id
7111  and    apf.availability_status_id <> 1
7112  and    p_effective_date between apf.effective_start_date and apf.effective_end_date;
7113 
7114 CURSOR c_prior_posn IS
7115  select apf.object_version_number
7116  from   HR_ALL_POSITIONS_F apf
7117  where  apf.position_id = p_position_id
7118  and    p_posn_eff_start_date-1 between apf.effective_start_date and apf.effective_end_date;
7119 
7120 BEGIN
7121  -- Note OVN returned is for Prior Record
7122  FOR c_posn_rec IN c_posn LOOP
7123    p_posn_eff_start_date := c_posn_rec.effective_start_date;
7124    p_posn_eff_end_date   := c_posn_rec.effective_end_date;
7125  END LOOP;
7126 
7127  FOR c_prior_posn_rec IN c_prior_posn LOOP
7128    p_prior_posn_ovn            := c_prior_posn_rec.object_version_number;
7129  END LOOP;
7130 
7131 END posn_not_active;
7132 
7133 --6850492
7134 procedure apply_dual_correction(p_sf52_data in ghr_pa_requests%rowtype,
7135                                 p_sf52_data_result in out nocopy ghr_pa_requests%rowtype,
7136 				p_retro_action_exists in varchar2) is
7137 cursor get_first_corr(p_pa_request_id in number)
7138     is
7139     select *
7140     from   ghr_pa_requests
7141     where  pa_request_id = p_pa_request_id;
7142 
7143 l_first_corr ghr_pa_requests%rowtype;
7144 begin
7145 
7146  open get_first_corr(p_pa_request_id => p_sf52_data.mass_action_id);
7147  fetch 	get_first_corr into l_first_corr;
7148  close get_first_corr;
7149 
7150  if l_first_corr.status <> 'CANCELED' and ((l_first_corr.to_position_id is not null and
7151      nvl(l_first_corr.from_position_id,'-1') <> nvl(l_first_corr.to_position_id,'-1')) or
7152     (l_first_corr.to_step_or_rate is not null and
7153      nvl(l_first_corr.from_step_or_rate,'-1') <> nvl(l_first_corr.to_step_or_rate,'-1')) or
7154      (l_first_corr.to_basic_pay is not null and
7155      nvl(l_first_corr.from_basic_pay,'-1') <> nvl(l_first_corr.to_basic_pay,'-1'))   or
7156      (l_first_corr.to_locality_adj is not null and
7157      nvl(l_first_corr.from_locality_adj,'-1') <> nvl(l_first_corr.to_locality_adj,'-1')) or
7158      (l_first_corr.to_other_pay_amount is not null and
7159      nvl(l_first_corr.from_other_pay_amount,'-1') <> nvl(l_first_corr.to_other_pay_amount,'-1')))
7160      then
7161     hr_utility.set_location('If the first correction is not cancelled',1000);
7162 
7163     p_sf52_data_result.from_position_id :=  l_first_corr.to_position_id;
7164     p_sf52_data_result.from_position_title := l_first_corr.to_position_title;
7165     p_sf52_data_result.from_position_number := l_first_corr.to_position_number;
7166     p_sf52_data_result.from_position_seq_no := l_first_corr.to_position_seq_no;
7167     p_sf52_data_result.from_pay_plan := l_first_corr.to_pay_plan;
7168     p_sf52_data_result.from_occ_code := l_first_corr.to_occ_code;
7169     p_sf52_data_result.from_grade_or_level := l_first_corr.to_grade_or_level;
7170     p_sf52_data_result.from_step_or_rate := l_first_corr.to_step_or_rate;
7171     p_sf52_data_result.from_total_salary := l_first_corr.to_total_salary;
7172     p_sf52_data_result.from_pay_basis := l_first_corr.to_pay_basis;
7173 --    p_sf52_data_result.input_pay_rate_determinant := l_first_corr.pay_rate_determinant;
7174     p_sf52_data_result.from_pay_table_identifier := l_first_corr.to_pay_table_identifier;
7175     p_sf52_data_result.from_basic_pay := l_first_corr.to_basic_pay;
7176     p_sf52_data_result.from_locality_adj := l_first_corr.to_locality_adj;
7177     p_sf52_data_result.from_adj_basic_pay := l_first_corr.to_adj_basic_pay;
7178     p_sf52_data_result.from_other_pay_amount := l_first_corr.to_other_pay_amount;
7179     p_sf52_data_result.from_position_org_line1 := l_first_corr.to_position_org_line1;
7180     p_sf52_data_result.from_position_org_line2 := l_first_corr.to_position_org_line2;
7181     p_sf52_data_result.from_position_org_line3 := l_first_corr.to_position_org_line3;
7182     p_sf52_data_result.from_position_org_line4 := l_first_corr.to_position_org_line4;
7183     p_sf52_data_result.from_position_org_line5 := l_first_corr.to_position_org_line5;
7184     p_sf52_data_result.from_position_org_line6 := l_first_corr.to_position_org_line6;
7185 elsif NVL(p_retro_action_exists,'N') = 'Y' then
7186 
7187     hr_utility.set_location('retro action exists',1000);
7188 
7189     p_sf52_data_result.from_position_id :=  p_sf52_data.from_position_id;
7190     p_sf52_data_result.from_position_title := p_sf52_data.from_position_title;
7191     p_sf52_data_result.from_position_number := p_sf52_data.from_position_number;
7192     p_sf52_data_result.from_position_seq_no := p_sf52_data.from_position_seq_no;
7193     p_sf52_data_result.from_pay_plan := p_sf52_data.from_pay_plan;
7194     p_sf52_data_result.from_occ_code := p_sf52_data.from_occ_code;
7195     p_sf52_data_result.from_grade_or_level := p_sf52_data.from_grade_or_level;
7196     p_sf52_data_result.from_step_or_rate := p_sf52_data.from_step_or_rate;
7197     p_sf52_data_result.from_total_salary := p_sf52_data.from_total_salary;
7198     p_sf52_data_result.from_pay_basis := p_sf52_data.from_pay_basis;
7199 --    p_sf52_data_result.input_pay_rate_determinant := p_sf52_data.pay_rate_determinant;
7200     p_sf52_data_result.from_pay_table_identifier := p_sf52_data.to_pay_table_identifier;
7201     p_sf52_data_result.from_basic_pay := p_sf52_data.from_basic_pay;
7202     p_sf52_data_result.from_locality_adj := p_sf52_data.from_locality_adj;
7203     p_sf52_data_result.from_adj_basic_pay := p_sf52_data.from_adj_basic_pay;
7204     p_sf52_data_result.from_other_pay_amount := p_sf52_data.from_other_pay_amount;
7205     p_sf52_data_result.from_position_org_line1 := p_sf52_data.from_position_org_line1;
7206     p_sf52_data_result.from_position_org_line2 := p_sf52_data.from_position_org_line2;
7207     p_sf52_data_result.from_position_org_line3 := p_sf52_data.from_position_org_line3;
7208     p_sf52_data_result.from_position_org_line4 := p_sf52_data.from_position_org_line4;
7209     p_sf52_data_result.from_position_org_line5 := p_sf52_data.from_position_org_line5;
7210     p_sf52_data_result.from_position_org_line6 := p_sf52_data.from_position_org_line6;
7211 elsif p_sf52_data_result.noa_family_code in ('CHG_WORK_SCHED', 'CHG_HOURS') then
7212 hr_utility.set_location('for change in work schedule',1000);
7213     p_sf52_data_result.from_position_id :=  p_sf52_data_result.to_position_id;
7214     p_sf52_data_result.from_position_title := p_sf52_data_result.to_position_title;
7215     p_sf52_data_result.from_position_number := p_sf52_data_result.to_position_number;
7216     p_sf52_data_result.from_position_seq_no := p_sf52_data_result.to_position_seq_no;
7217     p_sf52_data_result.from_pay_plan := p_sf52_data_result.to_pay_plan;
7218     p_sf52_data_result.from_occ_code := p_sf52_data_result.to_occ_code;
7219     p_sf52_data_result.from_grade_or_level := p_sf52_data_result.to_grade_or_level;
7220     p_sf52_data_result.from_step_or_rate := p_sf52_data_result.to_step_or_rate;
7221     p_sf52_data_result.from_total_salary := p_sf52_data_result.to_total_salary;
7222     p_sf52_data_result.from_pay_basis := p_sf52_data_result.to_pay_basis;
7223 --    p_sf52_data_result.input_pay_rate_determinant := p_sf52_data_result.pay_rate_determinant;
7224     p_sf52_data_result.from_pay_table_identifier := p_sf52_data_result.to_pay_table_identifier;
7225     p_sf52_data_result.from_basic_pay := p_sf52_data_result.to_basic_pay;
7226     p_sf52_data_result.from_locality_adj := p_sf52_data_result.to_locality_adj;
7227     p_sf52_data_result.from_adj_basic_pay := p_sf52_data_result.to_adj_basic_pay;
7228     p_sf52_data_result.from_other_pay_amount := p_sf52_data_result.to_other_pay_amount;
7229     p_sf52_data_result.from_position_org_line1 := p_sf52_data_result.to_position_org_line1;
7230     p_sf52_data_result.from_position_org_line2 := p_sf52_data_result.to_position_org_line2;
7231     p_sf52_data_result.from_position_org_line3 := p_sf52_data_result.to_position_org_line3;
7232     p_sf52_data_result.from_position_org_line4 := p_sf52_data_result.to_position_org_line4;
7233     p_sf52_data_result.from_position_org_line5 := p_sf52_data_result.to_position_org_line5;
7234     p_sf52_data_result.from_position_org_line6 := p_sf52_data_result.to_position_org_line6;
7235 end if;
7236 
7237 end  apply_dual_correction;
7238 
7239 -- Bug 8264475 Added the procedure for dual correction for dual actions inplace of apply noa corrections
7240 -- this will be called
7241 Procedure apply_dual_noa_corrections(p_sf52_data        in  	      ghr_pa_requests%rowtype,
7242 				     p_sf52_data_result in out nocopy ghr_pa_requests%rowtype ) is
7243 
7244    l_sf52_data_orig		ghr_pa_requests%rowtype;
7245    l_sf52_data_step		ghr_pa_requests%rowtype;
7246    l_sf52_ia_rec                   ghr_pa_requests%rowtype;
7247    l_sf52_dummy		ghr_pa_requests%rowtype;
7248    l_sf52_cursor_step_indx	number;
7249    l_session_var		ghr_history_api.g_session_var_type;
7250    -- Bug#5435374 added l_session_var1.
7251    l_session_var1   ghr_history_api.g_session_var_type;
7252    l_capped_other_pay number := hr_api.g_number;
7253    l_retro_eff_date        ghr_pa_requests.effective_date%type;
7254    l_retro_pa_request_id   ghr_pa_requests.pa_request_id%type;
7255    l_retro_first_noa       ghr_nature_of_actions.code%type;
7256    l_retro_second_noa       ghr_nature_of_actions.code%type;
7257    l_sf52_data_result      ghr_pa_requests%rowtype;
7258    -- Bug#3543213 Created l_dummy variable
7259    l_dummy                 VARCHAR2(30);
7260   -- this cursor selects all rows in the correction chain from ghr_pa_requests
7261    cursor  l_sf52_cursor
7262        is
7263        select 	*
7264        from 		ghr_pa_requests
7265        connect by 	prior altered_pa_request_id = pa_request_id
7266        start with	pa_request_id = p_sf52_data.pa_request_id
7267        order by 	level desc;
7268 
7269    cursor c_orig_details_for_ia
7270        is
7271        select pa_request_id,pa_notification_id,person_id,
7272               effective_date,from_position_id,
7273               to_position_id,noa_family_code,second_noa_code
7274        from ghr_pa_requests
7275        where pa_request_id = p_sf52_data.altered_pa_request_id;
7276 
7277    cursor c_get_hist_id (c_pa_request_id in number)
7278        is
7279        select min(pa_history_id)
7280        from ghr_pa_history
7281        where pa_request_id = c_pa_request_id;
7282 
7283    -- Bug#5435374
7284    l_pos_ei_grade_data  per_position_extra_info%rowtype;
7285 
7286    cursor c_grade_kff (grd_id number)
7287        is
7288        select gdf.segment1
7289              ,gdf.segment2
7290        from per_grades grd,
7291             per_grade_definitions gdf
7292        where grd.grade_id = grd_id
7293        and   grd.grade_definition_id = gdf.grade_definition_id;
7294 
7295    --bug #6356058 start
7296    l_core_chg_avbl number;
7297    l_prev_request_id number;
7298    l_curr_pa_history_id number;
7299    l_pos_ei_grp1_data	per_position_extra_info%rowtype;
7300 
7301 --   8737300 Modified the cursor for improving performance
7302    cursor core_chg_check(p_to_position_id in number,
7303                       p_effective_date in date)
7304        is
7305        select  1
7306        from    ghr_pa_history hist_1
7307        where   pa_request_id is null
7308        and     hist_1.pa_history_id > (select min(pa_history_id)
7309                                        from ghr_pa_history
7310 	  			       where pa_request_id = l_prev_request_id)
7311        and     hist_1.pa_history_id < nvl(l_curr_pa_history_id,999999999)
7312        and     information1 in   (select  to_char(position_extra_info_id)
7313                                   from    per_position_extra_info
7314                                   where   position_id          =  p_to_position_id
7315                                   and     information_type     in  ('GHR_US_POS_GRP1'))
7316        and     information5   =  'GHR_US_POS_GRP1'
7317        and     effective_date =  p_effective_date
7318        and     table_name     =  'PER_POSITION_EXTRA_INFO';
7319    --bug #6356058 start
7320 
7321    --BUG 6976052
7322    cursor get_position_det(p_position_id in number,
7323 			p_effective_date in date)
7324        is
7325        SELECT pos.job_id
7326              ,pos.business_group_id
7327              ,pos.organization_id
7328              ,pos.location_id
7329        FROM  hr_all_positions_f           pos  -- Venkat -- Position DT
7330        WHERE pos.position_id = p_position_id
7331        and  p_effective_date between pos.effective_start_date
7332                              and pos.effective_end_date ;
7333     --BUG 6976052
7334 
7335     -- 8264545
7336     Cursor c_noa_family(p_noa_id in number)
7337         is
7338         Select fam.noa_family_code
7339         from   ghr_noa_families nof,
7340                ghr_families fam
7341         where  nof.nature_of_action_id =  p_noa_id
7342         and    fam.noa_family_code     = nof.noa_family_code
7343         and    nvl(fam.proc_method_flag,hr_api.g_varchar2) = 'Y'
7344         and    p_sf52_data.effective_date
7345         between nvl(fam.start_date_active,p_sf52_data.effective_date)
7346         and     nvl(fam.end_date_active,p_sf52_data.effective_date);
7347      -- 8264545
7348 
7349      cursor chk_dual_sec_corr(p_pa_request_id in number)
7350      is
7351      select 1
7352      from   ghr_pa_requests
7353      where  pa_request_id = p_pa_request_id
7354      and    pa_request_id > mass_action_id
7355      and    second_noa_code = (select second_noa_code
7356                                from ghr_pa_requests
7357    		               where pa_request_id = (select 	  min(pa_request_id)
7358 				         	       from 	  ghr_pa_requests
7359 						       where      pa_notification_id is not null
7360 						       connect by pa_request_id = prior altered_pa_request_id
7361 						       start with pa_request_id = p_pa_request_id));
7362 
7363 
7364 l_shadow_data	ghr_pa_request_shadow%rowtype;
7365 l_proc	varchar2(30):='apply_dual_noa_corrections';
7366 l_dual_flag  varchar2(1);
7367 l_retro_action_exists  varchar2(1) := 'N';
7368 begin
7369   hr_utility.set_location('Entering:'|| l_proc, 5);
7370   l_sf52_data_result := p_sf52_data_result;
7371   ghr_history_api.get_g_session_var(l_session_var);
7372    -- loop through all corrections in the correction chain, incrementally applying them by
7373    -- calling apply_corrections procedure.
7374    open l_sf52_cursor ;
7375    l_sf52_cursor_step_indx := 0;
7376    loop
7377      -- initialize l_sf52_data_step to nulls;
7378      l_sf52_data_step := l_sf52_dummy;
7379 	-- l_sf52_data_step holds intermediate incremental values for final corrected record that is
7380 	-- being built.
7381      fetch l_sf52_cursor into l_sf52_data_step;
7382      exit when l_sf52_cursor%notfound;
7383      l_sf52_cursor_step_indx := l_sf52_cursor_step_indx +1;
7384      if (l_sf52_cursor_step_indx = 1) then
7385      --Bug # 6356058 start
7386 	l_prev_request_id := l_sf52_data_step.pa_request_id;
7387      --Bug # 6356058 end
7388 	hr_utility.set_location('Fetch l_sf52_data_step original :'|| l_proc, 10);
7389 	l_sf52_data_orig 	  := l_sf52_data_step;
7390 	p_sf52_data_result  := l_sf52_data_step;
7391 	hr_utility.set_location('assignment_id of original =' || l_sf52_data_step.employee_assignment_id, 14);
7392 	hr_utility.set_location('from grd or leveloriginal =' || l_sf52_data_step.from_grade_or_level, 14);
7393    	hr_utility.set_location(l_proc || 'pa_request_id of original= ' || l_sf52_data_step.pa_request_id,26);
7394      -- .47
7395 	-- refresh root sf52 and its correction
7396 	-- get pa_history_id for the root pa_request_id
7397 	open c_get_hist_id( l_sf52_data_step.pa_request_id);
7398 	fetch c_get_hist_id into l_session_var.pa_history_id;
7399 	if c_get_hist_id%notfound then
7400 	   -- raise error;
7401 	   close c_get_hist_id;
7402 	else
7403 	   close c_get_hist_id;
7404 	end if;
7405 	-- We are setting pa_history_id in session var to be able to fetch
7406 	-- Pre-record values of the root SF52 for refresh purpose.
7407 	-- It'll be reset after refresh has been done
7408 	ghr_history_api.set_g_session_var(l_session_var);
7409 
7410 	-- 8303159 Added to fetch family code for second correction of dual action before refresh
7411         if (p_sf52_data_result.second_noa_id is not null) then
7412 	   if (p_sf52_data.second_noa_id = p_sf52_data_result.second_noa_id) then
7413 	      --8264545
7414 	     for noa_family_rec in c_noa_family(p_sf52_data.second_noa_id) loop --Bug# 8270548
7415                 p_sf52_data_result.noa_family_code :=  noa_family_rec.noa_family_code;
7416              end loop;
7417 	      --8264545
7418 	   end if;
7419 	end if;
7420 
7421 	ghr_process_sf52.refresh_req_shadow(p_sf52_data		=>	p_sf52_data_result,
7422           				    p_shadow_data	=>	l_shadow_data);
7423 	ghr_process_sf52.redo_pay_calc(	p_sf52_rec		=>	p_sf52_data_result,
7424                                         p_capped_other_pay      =>   l_capped_other_pay);
7425 	-- reset pa_history_id in session variable.
7426 	l_session_var.pa_history_id := null;
7427 	ghr_history_api.set_g_session_var(l_session_var);
7428      -- .47
7429  	 -- Bug#3543213 For PRD U,V and NOA 894(Pay Adjustment) get the PRD Value from assignment
7430 	IF p_sf52_data_result.first_noa_code = '894' AND
7431 	   p_sf52_data_result.pay_rate_determinant IN ('U','V') THEN
7432 	   ghr_pa_requests_pkg.get_SF52_asg_ddf_details
7433 	                     (p_assignment_id         => p_sf52_data_result.employee_assignment_id
7434 	                     ,p_date_effective        => p_sf52_data_result.effective_date
7435 	                     ,p_tenure                => l_dummy
7436 	                     ,p_annuitant_indicator   => l_dummy
7437 	                     ,p_pay_rate_determinant  => p_sf52_data_result.pay_rate_determinant
7438                            ,p_work_schedule         => l_dummy
7439                            ,p_part_time_hours       => l_dummy);
7440  	END IF;
7441         --End of Bug#3543213
7442 	--check if original action in correction chain was a dual action. If so, determine which of
7443 	--the two actions this correction is for and call ghr_process_sf52.assign_new_rg to null out columns not having
7444         -- to do with the noa we are correcting.
7445 	--l_dual_flag := 'N';
7446 	 if (p_sf52_data_result.second_noa_id is not null) then
7447 	             hr_utility.set_location('original sf52 is dual action :'|| l_proc, 11);
7448 		     ghr_process_sf52.g_dual_action_yn := 'Y';
7449 		     ghr_process_sf52.g_dual_first_noac := p_sf52_data_result.first_noa_code;
7450 		     ghr_process_sf52.g_dual_second_noac := p_sf52_data_result.second_noa_code;
7451 
7452 	   if (p_sf52_data.second_noa_id = p_sf52_data_result.second_noa_id) then
7453 	       /*ghr_process_sf52.assign_new_rg(p_action_num			=>	2,
7454 		 			       p_pa_req				=>	p_sf52_data_result);*/
7455 		     -- to change the Family code for second action correction as it is raising errors
7456 		     -- based on family code
7457 		     ghr_process_sf52.copy_2ndNoa_to_1stNoa(p_sf52_data_result);
7458 		     ghr_process_sf52.null_2ndNoa_cols(p_sf52_data_result);
7459 	   else
7460       	     /*ghr_process_sf52.assign_new_rg(p_action_num			=>	1,
7461 		 	 		      p_pa_req				=>	p_sf52_data_result);*/
7462 
7463 		     -- if first action is 893, then we need to derive to_columns as both actions of
7464 		     -- the dual action potentially could have changed the to fields (in particular,
7465 		     -- to_step_or_rate) so we need to determine what the to_fields should be or the first action.
7466 		     if (p_sf52_data_result.first_noa_code = '893') then--Bug# 8926400
7467 			ghr_process_sf52.derive_to_columns(p_sf52_data	=>	p_sf52_data_result);
7468 		     end if;
7469 		     ghr_process_sf52.null_2ndNoa_cols(p_sf52_data_result);
7470 	   end if;
7471 	--			l_dual_flag := 'Y';
7472 	  end if;
7473 	  hr_utility.set_location('ghr_process_sf52.g_dual_flag_yn'||ghr_process_sf52.g_dual_action_yn,100);
7474   	  hr_utility.set_location('ghr_process_sf52.g_dual_first_noac'||ghr_process_sf52.g_dual_first_noac,100);
7475  	  hr_utility.set_location('ghr_process_sf52.g_dual_second_noac'||ghr_process_sf52.g_dual_second_noac,100);
7476 	   -- Nullfy columns which must not be passed
7477 	    p_sf52_data_result.pa_notification_id		:= NULL;
7478 	    p_sf52_data_result.agency_code			:= NULL;
7479 	    p_sf52_data_result.approval_date			:= NULL;
7480 	    p_sf52_data_result.approving_official_work_title:= NULL;
7481 	    p_sf52_data_result.employee_dept_or_agency 	:= NULL;
7482 	    p_sf52_data_result.from_agency_code			:= NULL;
7483 	    p_sf52_data_result.from_agency_desc			:= NULL;
7484 	    p_sf52_data_result.from_office_symbol		:= NULL;
7485 	    p_sf52_data_result.personnel_office_id		:= NULL;
7486 	    p_sf52_data_result.to_office_symbol			:= NULL;
7487      else
7488 	l_retro_pa_request_id := NULL;
7489         hr_utility.set_location('Fetch l_sf52_data_step loop :'|| l_proc, 15);
7490 	-- all corrections will have the original sf52 information in the 2nd noa columns, so
7491 	-- copy that information to 1st noa columns.
7492 	hr_utility.set_location('from grd or levelbefcp2to1 =' || l_sf52_data_step.from_grade_or_level, 14);
7493 	ghr_process_sf52.copy_2ndNoa_to_1stNoa(l_sf52_data_step);
7494 	-- null the second noa columns since we don't want anything to be done with these now.
7495 	hr_utility.set_location('from grd or levelaftcp2to1 =' || l_sf52_data_step.from_grade_or_level, 14);
7496 	ghr_process_sf52.null_2ndNoa_cols(l_sf52_data_step);
7497 	hr_utility.set_location('from grd or levelaftnull2noa =' || l_sf52_data_step.from_grade_or_level, 14);
7498 	hr_utility.set_location(l_proc || 'pa_request_id before correction= ' || l_sf52_data_step.pa_request_id,16);
7499 	hr_utility.set_location(l_proc || 'assignment id before correction= ' || l_sf52_data_step.employee_assignment_id,17);
7500 	hr_utility.set_location('from grd or levelbef appcorr =' || l_sf52_data_step.from_grade_or_level, 14);
7501         ghr_process_sf52.print_sf52('l_sf52_step bef apply_correction',
7502                                     l_sf52_data_step );
7503         ghr_process_sf52.print_sf52('result bef copy_ia_rec_on_result',
7504                                      p_sf52_data_result );
7505         -- Start Intervening Actions Processing
7506         -- Processing added to assign the From side details to
7507         -- To side if it is a Intervening action and
7508         -- Original action from position_id = to position id
7509         -- Fetch the original action details
7510         FOR c_orig_det_rec in c_orig_details_for_ia
7511         LOOP
7512            hr_utility.set_location('Inside the orig_details for loop' ,15);
7513 	   hr_utility.set_location('orig pa_request_id'||c_orig_det_rec.pa_request_id ,15);
7514            hr_utility.set_location('orig pa_notification_id'||c_orig_det_rec.pa_notification_id ,15);
7515            hr_utility.set_location('orig person_id'||c_orig_det_rec.person_id ,15);
7516            hr_utility.set_location('orig from_position_id'||c_orig_det_rec.from_position_id ,15);
7517            hr_utility.set_location('orig to_position_id'||c_orig_det_rec.to_position_id ,15);
7518            hr_utility.set_location('orig effective_date'||c_orig_det_rec.effective_date ,15);
7519 	   --BUG #7216635 added the parameter p_noa_id_correct
7520           GHR_APPROVED_PA_REQUESTS.determine_ia(
7521                      p_pa_request_id => c_orig_det_rec.pa_request_id,
7522                      p_pa_notification_id => c_orig_det_rec.pa_notification_id,
7523                      p_person_id      => c_orig_det_rec.person_id,
7524                      p_effective_date => c_orig_det_rec.effective_date,
7525 		     p_noa_id_correct => l_session_var.noa_id_correct,
7526                      p_retro_pa_request_id => l_retro_pa_request_id,
7527                      p_retro_eff_date => l_retro_eff_date,
7528                      p_retro_first_noa => l_retro_first_noa,
7529                      p_retro_second_noa => l_retro_second_noa);
7530           hr_utility.set_location('retro effective_date is '||l_retro_eff_date ,16);
7531           -- Bug#2521744 Splitting the single if condition into 2 separate if conditions.
7532           IF l_retro_eff_date is NOT NULL  THEN
7533             IF c_orig_det_rec.from_position_id
7534               = c_orig_det_rec.to_position_id THEN
7535               -- copy the from details
7536               hr_utility.set_location('Its a Intervening Action ' ,16);
7537               hr_utility.set_location('pa_request_id passed to get_sf52_to_det '||p_sf52_data.pa_request_id ,17);
7538 
7539               get_sf52_to_details_for_ia
7540                   (p_pa_request_id => p_sf52_data.pa_request_id,
7541                    p_retro_eff_date   => l_retro_eff_date,
7542                    p_sf52_ia_rec  => p_sf52_data_result);
7543 
7544 
7545 
7546               ghr_process_sf52.print_sf52('result aft get_sf52_to_details_for_ia',
7547                                            p_sf52_data_result );
7548               get_sf52_to_othpays_for_ia(p_sf52_ia_rec  => p_sf52_data_result);
7549               ghr_process_sf52.print_sf52('reslt aft get_sf52_to_other_pay_det_for_ia',
7550                                            p_sf52_data_result );
7551 		l_retro_action_exists := 'Y';
7552              ELSE
7553 
7554                  -- Verify whether the original action is one of the salary change actions
7555                  -- If yes, check whether the other pay related elements are present or not
7556                  -- as on the effective date. If they are not present, set that other pay comp
7557                  -- to_value as null.
7558                 get_sf52_to_othpays_for_ia(p_sf52_ia_rec  => p_sf52_data_result);
7559                 ghr_process_sf52.print_sf52('Aft get_sf52_to_other_pay_det_for_ia in else',
7560                                             p_sf52_data_result );
7561              END IF;
7562            END IF;
7563          --bug #6356058 start
7564          IF p_sf52_data_result.from_position_id = p_sf52_data_result.to_position_id THEN
7565            IF l_retro_pa_request_id IS NOT NULL THEN
7566 	      l_prev_request_id := l_retro_pa_request_id;
7567 	   end if;
7568            open c_get_hist_id(l_sf52_data_step.pa_request_id);
7569 	   fetch c_get_hist_id into l_curr_pa_history_id;
7570 	   close c_get_hist_id;
7571            open core_chg_check( p_sf52_data_result.to_position_id,
7572 	                        c_orig_det_rec.effective_date);
7573 	   fetch core_chg_check into l_core_chg_avbl;
7574 	   if core_chg_check%found then
7575 	      ghr_history_api.get_g_session_var(l_session_var);
7576               ghr_history_api.reinit_g_session_var;
7577               l_session_var1.date_Effective            := l_session_var.date_Effective;
7578               l_session_var1.person_id                 := l_session_var.person_id;
7579               l_session_var1.assignment_id             := l_session_var.assignment_id;
7580               l_session_var1.fire_trigger    := 'N';
7581               l_session_var1.program_name := 'sf50';
7582               ghr_history_api.set_g_session_var(l_session_var1);
7583 	      ghr_history_fetch.fetch_positionei(
7584                       p_position_id      => p_sf52_data_result.to_position_id,
7585                       p_information_type => 'GHR_US_POS_GRP1',
7586                       p_date_effective   => p_sf52_data_result.effective_date,
7587                       p_pos_ei_data      => l_pos_ei_grp1_data);
7588                p_sf52_data_result.supervisory_status     := l_pos_ei_grp1_data.poei_information16;
7589                p_sf52_data_result.part_time_hours        := l_pos_ei_grp1_data.poei_information23;
7590                ghr_history_api.reinit_g_session_var;
7591                ghr_history_api.set_g_session_var(l_session_var);
7592 	     end if;
7593 		close core_chg_check;
7594           END IF;
7595 --bug #6356058 end
7596         END LOOP; -- Intervening actions
7597 	      -- End Intervening Actions Processing
7598 
7599         --bug #6356058
7600         l_prev_request_id := l_sf52_data_step.pa_request_id;
7601          hr_utility.set_location('Out side the orig_details for loop' ,17);
7602         -- This has been added for dual actions correction processing
7603         --- to copy the to side details of first correction to from side details
7604         ---  of second correction while building the correction record
7605         apply_correction( p_sf52rec_correct	=>	l_sf52_data_step,
7606                           p_corr_pa_request_id	=>	p_sf52_data.pa_request_id,
7607                           p_sf52rec		=>	p_sf52_data_result );
7608 
7609 	--6850492
7610         If  l_sf52_data_step.rpa_type = 'DUAL' and l_sf52_data_step.mass_action_id is not null then
7611           for rec_chk_sec_corr in chk_dual_sec_corr(p_pa_request_id => l_sf52_data_step.pa_request_id)
7612 	  loop
7613 	  hr_utility.set_location('in second correction',1000);
7614            apply_dual_correction(l_sf52_data_step,p_sf52_data_result,l_retro_action_exists);
7615 	  end loop;
7616         end if;
7617         --6850492
7618 
7619         -- Recalculating Retention Allowance
7620         -- Recalculate Retention allowance if it is a OTHER_PAY action
7621         -- and Correction of Intervening Action
7622         if p_sf52_data_result.noa_family_code = 'OTHER_PAY' and
7623            l_retro_eff_date is NOT NULL and
7624            p_sf52_data_result.to_retention_allow_percentage is not null then
7625            --Modified for FWS
7626           IF p_sf52_data_result.to_pay_basis ='PH' THEN
7627        	     p_sf52_data_result.to_retention_allowance :=
7628              TRUNC(p_sf52_data_result.to_basic_pay * p_sf52_data_result.to_retention_allow_percentage/100,2);
7629 	  ELSE
7630 	     p_sf52_data_result.to_retention_allowance :=
7631              TRUNC(p_sf52_data_result.to_basic_pay * p_sf52_data_result.to_retention_allow_percentage/100,0);
7632           END IF;
7633 	  p_sf52_data_result.to_other_pay_amount := nvl(p_sf52_data_result.to_au_overtime,0) +
7634                                                     nvl(p_sf52_data_result.to_availability_pay,0) +
7635                                                     nvl(p_sf52_data_result.to_retention_allowance,0) +
7636                                                     nvl(p_sf52_data_result.to_supervisory_differential,0) +
7637                                                     nvl(p_sf52_data_result.to_staffing_differential,0);
7638           p_sf52_data_result.to_total_salary :=  p_sf52_data_result.to_adj_basic_pay + p_sf52_data_result.to_other_pay_amount;
7639           if p_sf52_data_result.to_other_pay_amount = 0 then
7640              p_sf52_data_result.to_other_pay_amount := null;
7641           end if;
7642        end if;
7643  	  hr_utility.set_location( l_proc || 'assignment_id after correction=' || p_sf52_data_result.employee_assignment_id ,18);
7644 	  hr_utility.set_location('Applied corrections :'|| l_proc, 20);
7645        end if;
7646    end loop;
7647    close l_sf52_cursor;
7648 
7649    --6976052
7650    --- Modified to get job id from hr_positions_f while applying all correction
7651    -- actions based on the position
7652    for rec in get_position_det(p_position_id => p_sf52_data_result.to_position_id,
7653          		       p_effective_date => p_sf52_data_result.effective_date)
7654    loop
7655      p_sf52_data_result.to_job_id := rec.job_id;
7656      p_sf52_data_result.to_organization_id := rec.organization_id;
7657    end loop;
7658    --6976052
7659 
7660     -- Bug#5435374 If the from and to position ids are same, verify the pay plan, grade details.
7661    IF p_sf52_data_result.from_position_id = p_sf52_data_result.to_position_id THEN
7662       -- Reinitializing the session variables to get the valid grade as on the
7663       -- effective date.
7664       ghr_history_api.get_g_session_var(l_session_var);
7665       ghr_history_api.reinit_g_session_var;
7666       l_session_var1.date_Effective            := l_session_var.date_Effective;
7667       l_session_var1.person_id                 := l_session_var.person_id;
7668       l_session_var1.assignment_id             := l_session_var.assignment_id;
7669       l_session_var1.fire_trigger    := 'N';
7670       l_session_var1.program_name := 'sf50';
7671       ghr_history_api.set_g_session_var(l_session_var1);
7672 
7673       -- Retrieve the Grade info from the POI history table
7674       ghr_history_fetch.fetch_positionei(
7675 		p_position_id      => p_sf52_data_result.to_position_id,
7676 		p_information_type => 'GHR_US_POS_VALID_GRADE',
7677 		p_date_effective   => p_sf52_data_result.effective_date,
7678 		p_pos_ei_data      => l_pos_ei_grade_data);
7679 
7680       -- Reset the session variables after getting the date effective valid grade
7681       -- to continue with the correction process.
7682       ghr_history_api.reinit_g_session_var;
7683       ghr_history_api.set_g_session_var(l_session_var);
7684 
7685       IF l_pos_ei_grade_data.position_extra_info_id IS NOT NULL THEN
7686 	 hr_utility.set_location('GL: to grd id:'||p_sf52_data_result.to_grade_id,30);
7687 	 hr_utility.set_location('GL: pos ei grd:'||l_pos_ei_grade_data.poei_information3,40);
7688 	 IF l_pos_ei_grade_data.poei_information3 <> p_sf52_data_result.to_grade_id THEN
7689 	 --Bug# 5638869
7690            --p_sf52_data_result.to_grade_id := l_pos_ei_grade_data.poei_information3;
7691            l_pos_ei_grade_data.poei_information3 := p_sf52_data_result.to_grade_id;
7692          --Bug# 5638869
7693 	 FOR c_grade_kff_rec IN c_grade_kff (p_sf52_data_result.to_grade_id)
7694 	 LOOP
7695 	   hr_utility.set_location('GL: Inside setting pay plan grade',60);
7696 	   p_sf52_data_result.to_pay_plan := c_grade_kff_rec.segment1  ;
7697 	   p_sf52_data_result.to_grade_or_level := c_grade_kff_rec.segment2;
7698 	   EXIT;
7699     	 END LOOP;
7700       END IF;
7701    END IF;
7702   END IF;
7703    -- Bug#5435374 End of the fix.
7704 
7705   hr_utility.set_location(' Leaving:'||l_proc, 25);
7706  Exception when others then
7707    --
7708    -- Reset IN OUT parameters and set OUT parameters
7709    --
7710    p_sf52_data_result := l_sf52_data_result;
7711    raise;
7712 end apply_dual_noa_corrections;
7713 -- Bug 8264475
7714 --6850492
7715 
7716 End;