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