1 Package Body ben_pei_ins as
2 /* $Header: bepeirhi.pkb 120.0 2005/05/28 10:33:49 appldev noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' ben_pei_ins.'; -- Global package name
9 --
10 -- ----------------------------------------------------------------------------
11 -- |----------------------------< dt_insert_dml >-----------------------------|
12 -- ----------------------------------------------------------------------------
13 -- {Start Of Comments}
14 --
15 -- Description:
16 -- This procedure controls the actual dml insert logic for datetrack. The
17 -- functions of this procedure are as follows:
18 -- 1) Get the object_version_number.
19 -- 2) To set the effective start and end dates to the corresponding
20 -- validation start and end dates. Also, the object version number
21 -- record attribute is set.
22 -- 3) To set and unset the g_api_dml status as required (as we are about to
23 -- perform dml).
24 -- 4) To insert the row into the schema with the derived effective start
25 -- and end dates and the object version number.
26 -- 5) To trap any constraint violations that may have occurred.
27 -- 6) To raise any other errors.
28 --
29 -- Prerequisites:
30 -- This is an internal private procedure which must be called from the
31 -- insert_dml and pre_update (logic permitting) procedure and must have
32 -- all mandatory arguments set.
33 --
34 -- In Parameters:
35 -- A Pl/Sql record structre.
36 --
37 -- Post Success:
38 -- The specified row will be inserted into the schema.
39 --
40 -- Post Failure:
41 -- On the insert dml failure it is important to note that we always reset the
42 -- g_api_dml status to false.
43 -- If a check or unique integrity constraint violation is raised the
44 -- constraint_error procedure will be called.
45 -- If any other error is reported, the error will be raised after the
46 -- g_api_dml status is reset.
47 --
48 -- Developer Implementation Notes:
49 -- This is an internal datetrack maintenance procedure which should
50 -- not be modified in anyway.
51 --
52 -- Access Status:
53 -- Internal Row Handler Use Only.
54 --
55 -- {End Of Comments}
56 -- ----------------------------------------------------------------------------
57 Procedure dt_insert_dml
58 (p_rec in out nocopy ben_pei_shd.g_rec_type,
59 p_effective_date in date,
60 p_datetrack_mode in varchar2,
61 p_validation_start_date in date,
62 p_validation_end_date in date) is
63 --
64 -- Cursor to select 'old' created AOL who column values
65 --
66 Cursor C_Sel1 Is
67 select t.created_by,
68 t.creation_date
69 from ben_pl_extract_identifier_f t
70 where t.pl_extract_identifier_id = p_rec.pl_extract_identifier_id
71 and t.effective_start_date = ben_pei_shd.g_old_rec.effective_start_date
72 and t.effective_end_date = (p_validation_start_date - 1);
73 --
74 l_proc varchar2(72) := g_package||'dt_insert_dml';
75 l_created_by ben_pl_extract_identifier_f.created_by%TYPE;
76 l_creation_date ben_pl_extract_identifier_f.creation_date%TYPE;
77 l_last_update_date ben_pl_extract_identifier_f.last_update_date%TYPE;
78 l_last_updated_by ben_pl_extract_identifier_f.last_updated_by%TYPE;
79 l_last_update_login ben_pl_extract_identifier_f.last_update_login%TYPE;
80 --
81 Begin
82 hr_utility.set_location('Entering:'||l_proc, 5);
83 --
84 -- Get the object version number for the insert
85 --
86 p_rec.object_version_number :=
87 dt_api.get_object_version_number
88 (p_base_table_name => 'ben_pl_extract_identifier_f',
89 p_base_key_column => 'pl_extract_identifier_id',
90 p_base_key_value => p_rec.pl_extract_identifier_id);
91 --
92 -- Set the effective start and end dates to the corresponding
93 -- validation start and end dates
94 --
95 p_rec.effective_start_date := p_validation_start_date;
96 p_rec.effective_end_date := p_validation_end_date;
97 --
98 -- If the datetrack_mode is not INSERT then we must populate the WHO
99 -- columns with the 'old' creation values and 'new' updated values.
100 --
101 If (p_datetrack_mode <> 'INSERT') then
102 hr_utility.set_location(l_proc, 10);
103 --
104 -- Select the 'old' created values
105 --
106 Open C_Sel1;
107 Fetch C_Sel1 Into l_created_by, l_creation_date;
108 If C_Sel1%notfound Then
109 --
110 -- The previous 'old' created row has not been found. We need
111 -- to error as an internal datetrack problem exists.
112 --
113 Close C_Sel1;
114 fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
115 fnd_message.set_token('PROCEDURE', l_proc);
116 fnd_message.set_token('STEP','10');
117 fnd_message.raise_error;
118 End If;
119 Close C_Sel1;
120 --
121 -- Set the AOL updated WHO values
122 --
123 l_last_update_date := sysdate;
124 l_last_updated_by := fnd_global.user_id;
125 l_last_update_login := fnd_global.login_id;
126 End If;
127 --
128 ben_pei_shd.g_api_dml := true; -- Set the api dml status
129 --
130 -- Insert the row into: ben_pl_f
131 --
132 insert into ben_pl_extract_identifier_f
133 (
134 pl_extract_identifier_id
135 ,pl_id
136 ,plip_id
137 ,oipl_id
138 ,third_party_identifier
139 ,organization_id
140 ,job_id
141 ,position_id
142 ,people_group_id
143 ,grade_id
144 ,payroll_id
145 ,home_state
146 ,home_zip
147 ,effective_start_date
148 ,effective_end_date
149 ,created_by
150 ,creation_date
151 ,last_update_date
152 ,last_updated_by
153 ,last_update_login
154 ,object_version_number
155 ,business_group_id
156 )
157 values
158 (
159 p_rec.pl_extract_identifier_id
160 ,p_rec.pl_id
161 ,p_rec.plip_id
162 ,p_rec.oipl_id
163 ,p_rec.third_party_identifier
164 ,p_rec.organization_id
165 ,p_rec.job_id
166 ,p_rec.position_id
167 ,p_rec.people_group_id
168 ,p_rec.grade_id
169 ,p_rec.payroll_id
170 ,p_rec.home_state
171 ,p_rec.home_zip
172 ,p_rec.effective_start_date
173 ,p_rec.effective_end_date
174 ,p_rec.created_by
175 ,p_rec.creation_date
176 ,p_rec.last_update_date
177 ,p_rec.last_updated_by
178 ,p_rec.last_update_login
179 ,p_rec.object_version_number
180 ,p_rec.business_group_id
181 );
182 --
183 ben_pei_shd.g_api_dml := false; -- Unset the api dml status
184 hr_utility.set_location(' Leaving:'||l_proc, 15);
185 --
186 Exception
187 When hr_api.check_integrity_violated Then
188 -- A check constraint has been violated
189 ben_pei_shd.g_api_dml := false; -- Unset the api dml status
190 ben_pei_shd.constraint_error
191 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
192 When hr_api.unique_integrity_violated Then
193 -- Unique integrity has been violated
194 ben_pei_shd.g_api_dml := false; -- Unset the api dml status
195 ben_pei_shd.constraint_error
196 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
197 When Others Then
198 ben_pei_shd.g_api_dml := false; -- Unset the api dml status
199 Raise;
200 End dt_insert_dml;
201 --
202 -- ----------------------------------------------------------------------------
203 -- |------------------------------< insert_dml >------------------------------|
204 -- ----------------------------------------------------------------------------
205 Procedure insert_dml
206 (p_rec in out nocopy ben_pei_shd.g_rec_type,
207 p_effective_date in date,
208 p_datetrack_mode in varchar2,
209 p_validation_start_date in date,
210 p_validation_end_date in date) is
211 --
212 l_proc varchar2(72) := g_package||'insert_dml';
213 --
214 Begin
215 hr_utility.set_location('Entering:'||l_proc, 5);
216 --
217 dt_insert_dml(p_rec => p_rec,
218 p_effective_date => p_effective_date,
219 p_datetrack_mode => p_datetrack_mode,
220 p_validation_start_date => p_validation_start_date,
221 p_validation_end_date => p_validation_end_date);
222 --
223 hr_utility.set_location(' Leaving:'||l_proc, 10);
224 End insert_dml;
225 --
226 -- ----------------------------------------------------------------------------
227 -- |------------------------------< pre_insert >------------------------------|
228 -- ----------------------------------------------------------------------------
229 -- {Start Of Comments}
230 --
231 -- Description:
232 -- This private procedure contains any processing which is required before
233 -- the insert dml. Presently, if the entity has a corresponding primary
234 -- key which is maintained by an associating sequence, the primary key for
235 -- the entity will be populated with the next sequence value in
236 -- preparation for the insert dml.
237 -- Also, if comments are defined for this entity, the comments insert
238 -- logic will also be called, generating a comment_id if required.
239 --
240 -- Prerequisites:
241 -- This is an internal procedure which is called from the ins procedure.
242 --
243 -- In Parameters:
244 -- A Pl/Sql record structre.
245 --
246 -- Post Success:
247 -- Processing continues.
248 --
249 -- Post Failure:
250 -- If an error has occurred, an error message and exception will be raised
251 -- but not handled.
252 --
253 -- Developer Implementation Notes:
254 -- Any pre-processing required before the insert dml is issued should be
255 -- coded within this procedure. As stated above, a good example is the
256 -- generation of a primary key number via a corresponding sequence.
257 -- It is important to note that any 3rd party maintenance should be reviewed
258 -- before placing in this procedure.
259 --
260 -- Access Status:
261 -- Internal Row Handler Use Only.
262 --
263 -- {End Of Comments}
264 -- ----------------------------------------------------------------------------
265 Procedure pre_insert
266 (p_rec in out nocopy ben_pei_shd.g_rec_type,
267 p_effective_date in date,
268 p_datetrack_mode in varchar2,
269 p_validation_start_date in date,
270 p_validation_end_date in date) is
271 --
272 l_proc varchar2(72) := g_package||'pre_insert';
273 --
274 cursor c1 is
275 select ben_pl_extract_identifier_s.nextval
276 from sys.dual;
277 --
278 Begin
279 hr_utility.set_location('Entering:'||l_proc, 5);
280 --
281 open c1;
282 fetch c1 into p_rec.pl_extract_identifier_id;
283 close c1;
284 --
285 hr_utility.set_location(' Leaving:'||l_proc, 10);
286 End pre_insert;
287 --
288 -- ----------------------------------------------------------------------------
289 -- |-----------------------------< post_insert >------------------------------|
290 -- ----------------------------------------------------------------------------
291 -- {Start Of Comments}
292 --
293 -- Description:
294 -- This private procedure contains any processing which is required after the
295 -- insert dml.
296 --
297 -- Prerequisites:
298 -- This is an internal procedure which is called from the ins procedure.
299 --
300 -- In Parameters:
301 -- A Pl/Sql record structre.
302 --
303 -- Post Success:
304 -- Processing continues.
305 --
306 -- Post Failure:
307 -- If an error has occurred, an error message and exception will be raised
308 -- but not handled.
309 --
310 -- Developer Implementation Notes:
311 -- Any post-processing required after the insert dml is issued should be
312 -- coded within this procedure. It is important to note that any 3rd party
313 -- maintenance should be reviewed before placing in this procedure.
314 --
315 -- Access Status:
316 -- Internal Row Handler Use Only.
317 --
318 -- {End Of Comments}
319 -- ----------------------------------------------------------------------------
320 Procedure post_insert
321 (p_rec in ben_pei_shd.g_rec_type,
322 p_effective_date in date,
323 p_datetrack_mode in varchar2,
324 p_validation_start_date in date,
325 p_validation_end_date in date) is
326 --
327 l_proc varchar2(72) := g_package||'post_insert';
328 --
329 Begin
330 hr_utility.set_location('Entering:'||l_proc, 5);
331 --
332 -- Start of API User Hook for post_insert.
333 --
334 begin
335 --
336 ben_pei_rki.after_insert
337 (
338 p_pl_extract_identifier_id => p_rec.pl_extract_identifier_id
339 ,p_pl_id => p_rec.pl_id
340 ,p_plip_id => p_rec.plip_id
341 ,p_oipl_id => p_rec.oipl_id
342 ,p_third_party_identifier => p_rec.third_party_identifier
343 ,p_organization_id => p_rec.organization_id
344 ,p_job_id => p_rec.job_id
345 ,p_position_id => p_rec.position_id
346 ,p_people_group_id => p_rec.people_group_id
347 ,p_grade_id => p_rec.grade_id
348 ,p_payroll_id => p_rec.payroll_id
349 ,p_home_state => p_rec.home_state
350 ,p_home_zip => p_rec.home_zip
351 ,p_effective_start_date => p_rec.effective_start_date
352 ,p_effective_end_date => p_rec.effective_end_date
353 ,p_object_version_number => p_rec.object_version_number
354 ,p_business_group_id => p_rec.business_group_id
355 ,p_effective_date => p_effective_date
356 ,p_validation_start_date => p_validation_start_date
357 ,p_validation_end_date => p_validation_end_date
358 );
359 --
360 exception
361 --
362 when hr_api.cannot_find_prog_unit then
363 --
364 hr_api.cannot_find_prog_unit_error
365 (p_module_name => 'ben_pl_extract_identifier_f'
366 ,p_hook_type => 'AI');
367 --
368 end;
369 --
370 -- End of API User Hook for post_insert.
371 --
372 hr_utility.set_location(' Leaving:'||l_proc, 10);
373 End post_insert;
374 --
375 -- ----------------------------------------------------------------------------
376 -- |-------------------------------< ins_lck >--------------------------------|
377 -- ----------------------------------------------------------------------------
378 -- {Start Of Comments}
379 --
380 -- Description:
381 -- The ins_lck process has one main function to perform. When inserting
382 -- a datetracked row, we must validate the DT mode.
383 -- be manipulated.
384 --
385 -- Prerequisites:
386 -- This procedure can only be called for the datetrack mode of INSERT.
387 --
388 -- In Parameters:
389 --
390 -- Post Success:
391 -- On successful completion of the ins_lck process the parental
392 -- datetracked rows will be locked providing the p_enforce_foreign_locking
393 -- argument value is TRUE.
394 -- If the p_enforce_foreign_locking argument value is FALSE then the
395 -- parential rows are not locked.
396 --
397 -- Post Failure:
398 -- The Lck process can fail for:
399 -- 1) When attempting to lock the row the row could already be locked by
400 -- another user. This will raise the HR_Api.Object_Locked exception.
401 -- 2) When attempting to the lock the parent which doesn't exist.
402 -- For the entity to be locked the parent must exist!
403 --
404 -- Developer Implementation Notes:
405 -- None.
406 --
407 -- Access Status:
408 -- Internal Row Handler Use Only.
409 --
410 -- {End Of Comments}
411 -- ----------------------------------------------------------------------------
412 Procedure ins_lck
413 (p_effective_date in date,
414 p_datetrack_mode in varchar2,
415 p_rec in ben_pei_shd.g_rec_type,
416 p_validation_start_date out nocopy date,
417 p_validation_end_date out nocopy date) is
418 --
419 l_proc varchar2(72) := g_package||'ins_lck';
420 l_validation_start_date date;
421 l_validation_end_date date;
422 --
423 Begin
424 hr_utility.set_location('Entering:'||l_proc, 5);
425 --
426 -- Validate the datetrack mode mode getting the validation start
427 -- and end dates for the specified datetrack operation.
428 --
429 dt_api.validate_dt_mode
430 (p_effective_date => p_effective_date,
431 p_datetrack_mode => p_datetrack_mode,
432 p_base_table_name => 'ben_pl_extract_identifier_f',
433 p_base_key_column => 'pl_extract_identifier_id',
434 p_base_key_value => p_rec.pl_extract_identifier_id,
435 p_enforce_foreign_locking => true,
436 p_validation_start_date => l_validation_start_date,
437 p_validation_end_date => l_validation_end_date);
438 --
439 -- Set the validation start and end date OUT arguments
440 --
441 p_validation_start_date := l_validation_start_date;
442 p_validation_end_date := l_validation_end_date;
443 --
444 hr_utility.set_location(' Leaving:'||l_proc, 10);
445 --
446 End ins_lck;
447 --
448 -- ----------------------------------------------------------------------------
449 -- |---------------------------------< ins >----------------------------------|
450 -- ----------------------------------------------------------------------------
451 Procedure ins
452 (
453 p_rec in out nocopy ben_pei_shd.g_rec_type,
454 p_effective_date in date
455 ) is
456 --
457 l_proc varchar2(72) := g_package||'ins';
458 l_datetrack_mode varchar2(30) := 'INSERT';
459 l_validation_start_date date;
460 l_validation_end_date date;
461 --
462 Begin
463 hr_utility.set_location('Entering:'||l_proc, 5);
464 --
465 -- Call the lock operation
466 --
467 ins_lck
468 (p_effective_date => p_effective_date,
469 p_datetrack_mode => l_datetrack_mode,
470 p_rec => p_rec,
471 p_validation_start_date => l_validation_start_date,
472 p_validation_end_date => l_validation_end_date);
473 --
474 --
475 -- Call the supporting insert validate operations
476 --
477 ben_pei_bus.insert_validate
478 (p_rec => p_rec,
479 p_effective_date => p_effective_date,
480 p_datetrack_mode => l_datetrack_mode,
481 p_validation_start_date => l_validation_start_date,
482 p_validation_end_date => l_validation_end_date);
483 --
484 --
485 -- Call the supporting pre-insert operation
486 --
487 pre_insert
488 (p_rec => p_rec,
489 p_effective_date => p_effective_date,
490 p_datetrack_mode => l_datetrack_mode,
491 p_validation_start_date => l_validation_start_date,
492 p_validation_end_date => l_validation_end_date);
493 --
494 -- Insert the row
495 --
496 insert_dml
497 (p_rec => p_rec,
498 p_effective_date => p_effective_date,
499 p_datetrack_mode => l_datetrack_mode,
500 p_validation_start_date => l_validation_start_date,
501 p_validation_end_date => l_validation_end_date);
502 --
503 -- Call the supporting post-insert operation
504 --
505 post_insert
506 (p_rec => p_rec,
507 p_effective_date => p_effective_date,
508 p_datetrack_mode => l_datetrack_mode,
509 p_validation_start_date => l_validation_start_date,
510 p_validation_end_date => l_validation_end_date);
511 end ins;
512 --
513 -- ----------------------------------------------------------------------------
514 -- |---------------------------------< ins >----------------------------------|
515 -- ----------------------------------------------------------------------------
516 Procedure ins
517 (
518 p_pl_extract_identifier_id out nocopy number,
519 p_effective_start_date out nocopy date,
520 p_effective_end_date out nocopy date,
521 p_pl_id in number default null,
522 p_plip_id in number default null,
523 p_oipl_id in number default null,
524 p_third_party_identifier in varchar2 default null,
525 p_organization_id in number default null,
526 p_job_id in number default null,
527 p_position_id in number default null,
528 p_people_group_id in number default null,
529 p_grade_id in number default null,
530 p_payroll_id in number default null,
531 p_home_state in varchar2 default null,
532 p_home_zip in varchar2 default null,
533 p_business_group_id in number default null,
534 p_object_version_number out nocopy number,
535 p_effective_date in date
536 ) is
537 --
538 l_rec ben_pei_shd.g_rec_type;
539 l_proc varchar2(72) := g_package||'ins';
540 --
541 Begin
542 hr_utility.set_location('Entering:'||l_proc, 5);
543 --
544 -- Call conversion function to turn arguments into the
545 -- p_rec structure.
546 --
547 l_rec :=
548 ben_pei_shd.convert_args
549 (
550 null
551 ,p_pl_id
552 ,p_plip_id
553 ,p_oipl_id
554 ,p_third_party_identifier
555 ,p_organization_id
556 ,p_job_id
557 ,p_position_id
558 ,p_people_group_id
559 ,p_grade_id
560 ,p_payroll_id
561 ,p_home_state
562 ,p_home_zip
563 ,null
564 ,null
565 ,null
566 ,p_business_group_id
567 );
568 --
569 -- Having converted the arguments into the ben_pei_rec
570 -- plsql record structure we call the corresponding record
571 -- business process.
572 --
573 ins(l_rec, p_effective_date);
574 --
575 -- Set the OUT arguments.
576 --
577 p_pl_extract_identifier_id := l_rec.pl_extract_identifier_id;
578 p_effective_start_date := l_rec.effective_start_date;
579 p_effective_end_date := l_rec.effective_end_date;
580 p_object_version_number := l_rec.object_version_number;
581 --
582 --
583 hr_utility.set_location(' Leaving:'||l_proc, 10);
584 End ins;
585 --
586 end ben_pei_ins;