1 Package Body ame_apg_ins as
2 /* $Header: amapgrhi.pkb 120.6 2006/10/05 16:02:47 pvelugul noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' ame_apg_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_id_i number default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19 (p_approval_group_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_apg_ins.g_approval_group_id_i := p_approval_group_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_apg_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
93 ame_apg_shd.g_old_rec.start_date
90 from ame_approval_groups t
91 where t.approval_group_id = p_rec.approval_group_id
92 and t.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_groups t
99 where t.approval_group_id = p_rec.approval_group_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_groups.created_by%TYPE;
105 l_creation_date ame_approval_groups.creation_date%TYPE;
106 l_last_update_date ame_approval_groups.last_update_date%TYPE;
107 l_last_updated_by ame_approval_groups.last_updated_by%TYPE;
108 l_last_update_login ame_approval_groups.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_apg_shd.get_object_version_number
132 (p_approval_group_id => p_rec.approval_group_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_groups
187 --
188 insert into ame_approval_groups
189 (approval_group_id
190 ,name
191 ,start_date
192 ,end_date
193 ,description
194 ,query_string
195 ,is_static
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_id
206 ,p_rec.name
207 ,p_rec.start_date
208 ,p_rec.end_date
209 ,p_rec.description
210 ,p_rec.query_string
211 ,p_rec.is_static
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_apg_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_apg_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_apg_shd.g_rec_type
245 ,p_effective_date in date
246 ,p_datetrack_mode in varchar2
247 ,p_validation_start_date in date
251 l_proc varchar2(72) := g_package||'insert_dml';
248 ,p_validation_end_date in date
249 ) is
250 --
252 --
253 Begin
254 hr_utility.set_location('Entering:'||l_proc, 5);
255 --
256 ame_apg_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_apg_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_groups_s.nextval from sys.dual;
315 --
316 Cursor C_Sel2 is
317 Select null
318 from ame_approval_groups
319 where approval_group_id =
320 ame_apg_ins.g_approval_group_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_apg_ins.g_approval_group_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_groups');
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_id :=
350 ame_apg_ins.g_approval_group_id_i;
351 ame_apg_ins.g_approval_group_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_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}
402 ,p_effective_date in date
399 -- ----------------------------------------------------------------------------
400 Procedure post_insert
401 (p_rec in ame_apg_shd.g_rec_type
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_apg_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_id
422 => p_rec.approval_group_id
423 ,p_name
424 => p_rec.name
425 ,p_start_date
426 => p_rec.start_date
427 ,p_end_date
428 => p_rec.end_date
429 ,p_description
430 => p_rec.description
431 ,p_query_string
432 => p_rec.query_string
433 ,p_is_static
434 => p_rec.is_static
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_GROUPS'
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_apg_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 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 hr_utility.set_location(' Leaving:'||l_proc, 10);
518 --
519 End ins_lck;
520 --
521 -- ----------------------------------------------------------------------------
522 -- |---------------------------------< ins >----------------------------------|
523 -- ----------------------------------------------------------------------------
524 Procedure ins
525 (p_effective_date in date
526 ,p_rec in out nocopy ame_apg_shd.g_rec_type
527 ) is
528 --
529 l_proc varchar2(72) := g_package||'ins';
530 l_datetrack_mode varchar2(30) := hr_api.g_insert;
531 l_validation_start_date date;
532 l_validation_end_date date;
533 --
534 Begin
535 hr_utility.set_location('Entering:'||l_proc, 5);
536 --
537 -- Call the lock operation
538 --
539 ame_apg_ins.ins_lck
540 (p_effective_date => p_effective_date
541 ,p_datetrack_mode => l_datetrack_mode
542 ,p_rec => p_rec
543 ,p_validation_start_date => l_validation_start_date
544 ,p_validation_end_date => l_validation_end_date
545 );
546 --
547 -- Call the supporting insert validate operations
548 --
549 ame_apg_bus.insert_validate
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 -- Call to raise any errors on multi-message list
558 hr_multi_message.end_validation_set;
559 --
560 -- Call the supporting pre-insert operation
561 --
562 ame_apg_ins.pre_insert
563 (p_rec => p_rec
564 ,p_effective_date => p_effective_date
565 ,p_datetrack_mode => l_datetrack_mode
566 ,p_validation_start_date => l_validation_start_date
567 ,p_validation_end_date => l_validation_end_date
568 );
569 --
570 -- Insert the row
571 --
572 ame_apg_ins.insert_dml
573 (p_rec => p_rec
574 ,p_effective_date => p_effective_date
575 ,p_datetrack_mode => l_datetrack_mode
576 ,p_validation_start_date => l_validation_start_date
577 ,p_validation_end_date => l_validation_end_date
578 );
579 --
580 -- Call the supporting post-insert operation
581 --
582 ame_apg_ins.post_insert
583 (p_rec => p_rec
584 ,p_effective_date => p_effective_date
585 ,p_datetrack_mode => l_datetrack_mode
586 ,p_validation_start_date => l_validation_start_date
587 ,p_validation_end_date => l_validation_end_date
588 );
589 --
590 -- Call to raise any errors on multi-message list
591 hr_multi_message.end_validation_set;
592 --
593 hr_utility.set_location('Leaving:'||l_proc,10);
594 end ins;
595 --
596 -- ----------------------------------------------------------------------------
597 -- |---------------------------------< ins >----------------------------------|
598 -- ----------------------------------------------------------------------------
599 Procedure ins
600 (p_effective_date in date
601 ,p_name in varchar2
602 ,p_description in varchar2
603 ,p_query_string in varchar2 default null
604 ,p_is_static in varchar2
605 ,p_security_group_id in number default null
606 ,p_approval_group_id out nocopy number
607 ,p_object_version_number out nocopy number
608 ,p_start_date out nocopy date
609 ,p_end_date out nocopy date
610 ) is
611 --
612 l_rec ame_apg_shd.g_rec_type;
613 l_proc varchar2(72) := g_package||'ins';
614 --
615 Begin
616 hr_utility.set_location('Entering:'||l_proc, 5);
617 --
618 -- Call conversion function to turn arguments into the
619 -- p_rec structure.
620 --
621 l_rec :=
622 ame_apg_shd.convert_args
623 (null
624 ,p_name
625 ,null
626 ,null
627 ,p_description
628 ,p_query_string
629 ,p_is_static
630 ,p_security_group_id
631 ,null
632 );
633 --
634 -- Having converted the arguments into the ame_apg_rec
635 -- plsql record structure we call the corresponding record
636 -- business process.
637 --
638 ame_apg_ins.ins
639 (p_effective_date
640 ,l_rec
641 );
642 --
643 -- Set the OUT arguments.
644 --
645 p_approval_group_id := l_rec.approval_group_id;
646 p_start_date := l_rec.start_date;
647 p_end_date := l_rec.end_date;
648 p_object_version_number := l_rec.object_version_number;
649 --
650 --
651 hr_utility.set_location(' Leaving:'||l_proc, 10);
652 End ins;
653 --
654 end ame_apg_ins;