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