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