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