1 Package Body ame_man_ins as
2 /* $Header: ammanrhi.pkb 120.5 2005/11/22 03:18 santosin noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' ame_man_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_attribute_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_attribute_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_man_ins.g_attribute_id_i := p_attribute_id;
29 ame_man_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_man_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_mandatory_attributes t
94 where t.attribute_id = p_rec.attribute_id
95 and t.action_type_id = p_rec.action_type_id
96 and t.start_date = ame_man_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_mandatory_attributes t
102 where t.attribute_id = p_rec.attribute_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_mandatory_attributes.created_by%TYPE;
109 l_creation_date ame_mandatory_attributes.creation_date%TYPE;
110 l_last_update_date ame_mandatory_attributes.last_update_date%TYPE;
111 l_last_updated_by ame_mandatory_attributes.last_updated_by%TYPE;
112 l_last_update_login ame_mandatory_attributes.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_man_shd.get_object_version_number
136 (p_attribute_id => p_rec.attribute_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_mandatory_attributes
192 --
193 insert into ame_mandatory_attributes
194 (attribute_id
195 ,action_type_id
196 ,start_date
197 ,end_date
198 ,security_group_id
199 ,object_version_number
200 ,created_by
201 ,creation_date
202 ,last_update_date
203 ,last_updated_by
204 ,last_update_login
205 )
206 Values
207 (p_rec.attribute_id
208 ,p_rec.action_type_id
209 ,p_rec.start_date
210 ,p_rec.end_date
211 ,p_rec.security_group_id
212 ,p_rec.object_version_number
213 ,l_created_by
214 ,l_creation_date
215 ,l_last_update_date
216 ,l_last_updated_by
217 ,l_last_update_login
218 );
219 --
220 --
221 hr_utility.set_location(' Leaving:'||l_proc, 15);
222 --
223 Exception
224 When hr_api.check_integrity_violated Then
225 -- A check constraint has been violated
226 --
227 ame_man_shd.constraint_error
228 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
229 When hr_api.unique_integrity_violated Then
230 -- Unique integrity has been violated
231 --
232 ame_man_shd.constraint_error
233 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
234 When Others Then
235 --
236 Raise;
237 End dt_insert_dml;
238 --
239 -- ----------------------------------------------------------------------------
240 -- |------------------------------< insert_dml >------------------------------|
241 -- ----------------------------------------------------------------------------
242 Procedure insert_dml
243 (p_rec in out nocopy ame_man_shd.g_rec_type
244 ,p_effective_date in date
245 ,p_datetrack_mode in varchar2
246 ,p_validation_start_date in date
247 ,p_validation_end_date in date
248 ) is
249 --
250 l_proc varchar2(72) := g_package||'insert_dml';
251 --
252 Begin
253 hr_utility.set_location('Entering:'||l_proc, 5);
254 --
255 ame_man_ins.dt_insert_dml
256 (p_rec => p_rec
257 ,p_effective_date => p_effective_date
258 ,p_datetrack_mode => p_datetrack_mode
259 ,p_validation_start_date => p_validation_start_date
260 ,p_validation_end_date => p_validation_end_date
261 );
262 --
263 hr_utility.set_location(' Leaving:'||l_proc, 10);
264 End insert_dml;
265 --
266 -- ----------------------------------------------------------------------------
267 -- |------------------------------< pre_insert >------------------------------|
268 -- ----------------------------------------------------------------------------
269 -- {Start Of Comments}
270 --
271 -- Description:
272 -- This private procedure contains any processing which is required before
273 -- the insert dml. Presently, if the entity has a corresponding primary
274 -- key which is maintained by an associating sequence, the primary key for
275 -- the entity will be populated with the next sequence value in
276 -- preparation for the insert dml.
277 -- Also, if comments are defined for this entity, the comments insert
278 -- logic will also be called, generating a comment_id if required.
279 --
280 -- Prerequisites:
281 -- This is an internal procedure which is called from the ins procedure.
282 --
283 -- In Parameters:
284 -- A Pl/Sql record structure.
285 --
286 -- Post Success:
287 -- Processing continues.
288 --
289 -- Post Failure:
290 -- If an error has occurred, an error message and exception will be raised
291 -- but not handled.
292 --
293 -- Developer Implementation Notes:
294 -- Any pre-processing required before the insert dml is issued should be
295 -- coded within this procedure. As stated above, a good example is the
296 -- generation of a primary key number via a corresponding sequence.
297 -- It is important to note that any 3rd party maintenance should be reviewed
298 -- before placing in this procedure.
299 --
300 -- Access Status:
301 -- Internal Row Handler Use Only.
302 --
303 -- {End Of Comments}
304 -- ----------------------------------------------------------------------------
305 Procedure pre_insert
306 (p_rec in out nocopy ame_man_shd.g_rec_type
307 ,p_effective_date in date
308 ,p_datetrack_mode in varchar2
309 ,p_validation_start_date in date
310 ,p_validation_end_date in date
311 ) is
312 --
313 -- Cursor C_Sel1 is select ame_mandatory_attributes_s.nextval from sys.dual;
314 --
315 Cursor C_Sel2 is
316 Select null
317 from ame_mandatory_attributes
318 where attribute_id =
319 ame_man_ins.g_attribute_id_i
320 and action_type_id =
321 ame_man_ins.g_action_type_id_i;
322 --
323 l_proc varchar2(72) := g_package||'pre_insert';
324 l_exists varchar2(1);
325 --
326 Begin
327 hr_utility.set_location('Entering:'||l_proc, 5);
328 --
329 If (ame_man_ins.g_attribute_id_i is not null or
330 ame_man_ins.g_action_type_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_mandatory_attributes');
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.attribute_id :=
350 ame_man_ins.g_attribute_id_i;
351 ame_man_ins.g_attribute_id_i := null;
352 p_rec.action_type_id :=
353 ame_man_ins.g_action_type_id_i;
354 ame_man_ins.g_action_type_id_i := null;
355 End If;
356 --
357 -- No registerd key values, so select the next sequence number
358 --
359 --
360 -- Select the next sequence number
361 --
362 /*
363 Open C_Sel1;
364 Fetch C_Sel1 Into p_rec.action_type_id;
365 Close C_Sel1;
366 End If;
367 */
368 --
369 --
370 hr_utility.set_location(' Leaving:'||l_proc, 10);
371 End pre_insert;
372 --
373 -- ----------------------------------------------------------------------------
374 -- |----------------------------< post_insert >-------------------------------|
375 -- ----------------------------------------------------------------------------
376 -- {Start Of Comments}
377 --
378 -- Description:
379 -- This private procedure contains any processing which is required after
380 -- the insert dml.
381 --
382 -- Prerequisites:
383 -- This is an internal procedure which is called from the ins procedure.
384 --
385 -- In Parameters:
386 -- A Pl/Sql record structure.
387 --
388 -- Post Success:
389 -- Processing continues.
390 --
391 -- Post Failure:
392 -- If an error has occurred, an error message and exception will be raised
393 -- but not handled.
394 --
395 -- Developer Implementation Notes:
396 -- Any post-processing required after the insert dml is issued should be
397 -- coded within this procedure. It is important to note that any 3rd party
398 -- maintenance should be reviewed before placing in this procedure.
399 --
400 -- Access Status:
401 -- Internal Row Handler Use Only.
402 --
403 -- {End Of Comments}
404 -- ----------------------------------------------------------------------------
405 Procedure post_insert
406 (p_rec in ame_man_shd.g_rec_type
407 ,p_effective_date in date
408 ,p_datetrack_mode in varchar2
409 ,p_validation_start_date in date
410 ,p_validation_end_date in date
411 ) is
412 --
413 l_proc varchar2(72) := g_package||'post_insert';
414 --
415 Begin
416 hr_utility.set_location('Entering:'||l_proc, 5);
417 begin
418 --
419 ame_man_rki.after_insert
420 (p_effective_date
421 => p_effective_date
422 ,p_validation_start_date
423 => p_validation_start_date
424 ,p_validation_end_date
425 => p_validation_end_date
426 ,p_attribute_id
427 => p_rec.attribute_id
428 ,p_action_type_id
429 => p_rec.action_type_id
430 ,p_start_date
431 => p_rec.start_date
432 ,p_end_date
433 => p_rec.end_date
434 ,p_security_group_id
435 => p_rec.security_group_id
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_MANDATORY_ATTRIBUTES'
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_man_shd.g_rec_type
493 ,p_validation_start_date out nocopy date
494 ,p_validation_end_date out nocopy date
495 ) is
496 --
497 cursor c_sel1 is
498 select action_type_id
499 from ame_action_types
500 where action_type_id = p_rec.action_type_id and
501 p_effective_date between
502 start_date and nvl(end_date - ame_util.oneSecond, sysdate)
503 for update nowait;
504 l_proc varchar2(72) := g_package||'ins_lck';
505 l_validation_start_date date;
506 l_validation_end_date date;
507 l_action_type_id number;
508 --
509 Begin
510 hr_utility.set_location('Entering:'||l_proc, 5);
511 --
512 -- Lock parent
513 open c_sel1;
514 fetch c_sel1 into l_action_type_id;
515 close c_sel1;
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 --
528 hr_utility.set_location(' Leaving:'||l_proc, 10);
529 --
530 End ins_lck;
531 --
532 -- ----------------------------------------------------------------------------
533 -- |---------------------------------< ins >----------------------------------|
534 -- ----------------------------------------------------------------------------
535 Procedure ins
536 (p_effective_date in date
537 ,p_rec in out nocopy ame_man_shd.g_rec_type
538 ) is
539 --
540 l_proc varchar2(72) := g_package||'ins';
541 l_datetrack_mode varchar2(30) := hr_api.g_insert;
542 l_validation_start_date date;
543 l_validation_end_date date;
544 --
545 Begin
546 hr_utility.set_location('Entering:'||l_proc, 5);
547 --
548 -- Call the lock operation
549 --
550 ame_man_ins.ins_lck
551 (p_effective_date => p_effective_date
552 ,p_datetrack_mode => l_datetrack_mode
553 ,p_rec => p_rec
554 ,p_validation_start_date => l_validation_start_date
555 ,p_validation_end_date => l_validation_end_date
556 );
557 --
558 -- Call the supporting insert validate operations
559 --
560 ame_man_bus.insert_validate
561 (p_rec => p_rec
562 ,p_effective_date => p_effective_date
563 ,p_datetrack_mode => l_datetrack_mode
564 ,p_validation_start_date => l_validation_start_date
565 ,p_validation_end_date => l_validation_end_date
566 );
567 --
568 -- Call to raise any errors on multi-message list
569 hr_multi_message.end_validation_set;
570 --
571 -- Call the supporting pre-insert operation
572 --
573 ame_man_ins.pre_insert
574 (p_rec => p_rec
575 ,p_effective_date => p_effective_date
576 ,p_datetrack_mode => l_datetrack_mode
577 ,p_validation_start_date => l_validation_start_date
578 ,p_validation_end_date => l_validation_end_date
579 );
580 --
581 -- Insert the row
582 --
583 ame_man_ins.insert_dml
584 (p_rec => p_rec
585 ,p_effective_date => p_effective_date
586 ,p_datetrack_mode => l_datetrack_mode
587 ,p_validation_start_date => l_validation_start_date
588 ,p_validation_end_date => l_validation_end_date
589 );
590 --
591 -- Call the supporting post-insert operation
592 --
593 ame_man_ins.post_insert
594 (p_rec => p_rec
595 ,p_effective_date => p_effective_date
596 ,p_datetrack_mode => l_datetrack_mode
597 ,p_validation_start_date => l_validation_start_date
598 ,p_validation_end_date => l_validation_end_date
599 );
600 --
601 -- Call to raise any errors on multi-message list
602 hr_multi_message.end_validation_set;
603 --
604 hr_utility.set_location('Leaving:'||l_proc,10);
605 end ins;
606 --
607 -- ----------------------------------------------------------------------------
608 -- |---------------------------------< ins >----------------------------------|
609 -- ----------------------------------------------------------------------------
610 Procedure ins
611 (p_effective_date in date
612 ,p_security_group_id in number default null
613 ,p_attribute_id in number
614 ,p_action_type_id in number
615 ,p_object_version_number out nocopy number
616 ,p_start_date out nocopy date
617 ,p_end_date out nocopy date
618 ) is
619 --
620 l_rec ame_man_shd.g_rec_type;
621 l_proc varchar2(72) := g_package||'ins';
622 --
623 Begin
624 hr_utility.set_location('Entering:'||l_proc, 5);
625 --
626 -- Call conversion function to turn arguments into the
627 -- p_rec structure.
628 --
629 l_rec :=
630 ame_man_shd.convert_args
631 (p_attribute_id
632 ,p_action_type_id
633 ,null
634 ,null
635 ,p_security_group_id
636 ,null
637 );
638 --
639 -- Having converted the arguments into the ame_man_rec
640 -- plsql record structure we call the corresponding record
641 -- business process.
642 --
643 ame_man_ins.ins
644 (p_effective_date
645 ,l_rec
646 );
647 --
648 -- Set the OUT arguments.
649 --
650 p_start_date := l_rec.start_date;
651 p_end_date := l_rec.end_date;
652 p_object_version_number := l_rec.object_version_number;
653 --
654 --
655 hr_utility.set_location(' Leaving:'||l_proc, 10);
656 End ins;
657 --
658 end ame_man_ins;