1 Package Body ame_stv_ins as
2 /* $Header: amstvrhi.pkb 120.2 2005/11/22 03:20 santosin noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' ame_stv_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_condition_id_i number default null;
14 g_string_value_i varchar2(4000) default null;
15 --
16 -- ----------------------------------------------------------------------------
17 -- |------------------------< set_base_key_value >----------------------------|
18 -- ----------------------------------------------------------------------------
19 procedure set_base_key_value
20 (p_condition_id in number
21 ,p_string_value in varchar2) 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_stv_ins.g_condition_id_i := p_condition_id;
29 ame_stv_ins.g_string_value_i := p_string_value;
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_stv_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_string_values t
94 where t.condition_id = p_rec.condition_id
95 and t.string_value = p_rec.string_value
96 and t.start_date =
97 ame_stv_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_string_values t
103 where t.condition_id = p_rec.condition_id
104 and t.string_value = p_rec.string_value
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_string_values.created_by%TYPE;
110 l_creation_date ame_string_values.creation_date%TYPE;
111 l_last_update_date ame_string_values.last_update_date%TYPE;
112 l_last_updated_by ame_string_values.last_updated_by%TYPE;
113 l_last_update_login ame_string_values.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_stv_shd.get_object_version_number
137 (p_condition_id => p_rec.condition_id
138 ,p_string_value => p_rec.string_value
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 l_last_update_date := sysdate;
171 l_last_updated_by := l_current_user_id;
172 l_last_update_login := l_current_user_id;
173 Else
174 p_rec.object_version_number := 1; -- Initialise the object version
175 --
176 -- If the current user logged in using AME Developer responsibility
177 -- then the created_by value should be ame_util.seededDataCreatedById
178 --
179 if fnd_global.resp_name = 'AME Developer' then
180 l_created_by := ame_util.seededDataCreatedById;
181 else
182 l_created_by := l_current_user_id;
183 end if;
184 l_creation_date := sysdate;
185 l_last_update_date := sysdate;
186 l_last_updated_by := l_current_user_id;
187 l_last_update_login := l_current_user_id;
188 End If;
189 --
190 --
191 --
192 -- Insert the row into: ame_string_values
193 --
194 insert into ame_string_values
195 (condition_id
196 ,string_value
197 ,start_date
198 ,end_date
199 ,security_group_id
200 ,object_version_number
201 ,created_by
202 ,creation_date
203 ,last_update_date
204 ,last_updated_by
205 ,last_update_login
206 )
207 Values
208 (p_rec.condition_id
209 ,p_rec.string_value
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_stv_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_stv_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_stv_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_stv_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_stv_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_string_values_s.nextval from sys.dual;*/
315 --
316 Cursor C_Sel2 is
317 Select null
318 from ame_string_values
319 where condition_id =
320 ame_stv_ins.g_condition_id_i
321 and string_value =
322 ame_stv_ins.g_string_value_i
323 and p_effective_date between start_date
324 and nvl(end_date - ame_util.oneSecond , p_effective_date);
325 --
326 l_proc varchar2(72) := g_package||'pre_insert';
327 l_exists varchar2(1);
328 --
329 Begin
330 hr_utility.set_location('Entering:'||l_proc, 5);
331 --
332 If (ame_stv_ins.g_condition_id_i is not null or
333 ame_stv_ins.g_string_value_i is not null) Then
334 --
335 -- Verify registered primary key values not already in use
336 --
337 Open C_Sel2;
338 Fetch C_Sel2 into l_exists;
339 If C_Sel2%found Then
340 Close C_Sel2;
341 --
342 -- The primary key values are already in use.
343 --
344 fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
345 fnd_message.set_token('TABLE_NAME','ame_string_values');
346 fnd_message.raise_error;
347 End If;
348 Close C_Sel2;
349 --
350 -- Use registered key values and clear globals
351 --
352 p_rec.condition_id :=
353 ame_stv_ins.g_condition_id_i;
354 ame_stv_ins.g_condition_id_i := null;
355 p_rec.string_value :=
356 ame_stv_ins.g_string_value_i;
357 ame_stv_ins.g_string_value_i := null;
358 /*Else
359 --
360 -- No registerd key values, so select the next sequence number
361 --
362 --
363 -- Select the next sequence number
364 --
365 Open C_Sel1;
366 Fetch C_Sel1 Into p_rec.string_value;
367 Close C_Sel1;
368 */
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_stv_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_stv_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_condition_id
429 => p_rec.condition_id
430 ,p_string_value
431 => p_rec.string_value
432 ,p_start_date
433 => p_rec.start_date
434 ,p_end_date
435 => p_rec.end_date
436 ,p_security_group_id
437 => p_rec.security_group_id
438 ,p_object_version_number
439 => p_rec.object_version_number
440 );
441 --
442 exception
443 --
444 when hr_api.cannot_find_prog_unit then
445 --
446 hr_api.cannot_find_prog_unit_error
447 (p_module_name => 'AME_STRING_VALUES'
448 ,p_hook_type => 'AI');
449 --
450 end;
451 --
452 hr_utility.set_location(' Leaving:'||l_proc, 10);
453 End post_insert;
454 --
455 -- ----------------------------------------------------------------------------
456 -- |-------------------------------< ins_lck >--------------------------------|
457 -- ----------------------------------------------------------------------------
458 -- {Start Of Comments}
459 --
460 -- Description:
461 -- The ins_lck process has one main function to perform. When inserting
462 -- a datetracked row, we must validate the DT mode.
463 --
464 -- Prerequisites:
465 -- This procedure can only be called for the datetrack mode of INSERT.
466 --
467 -- In Parameters:
468 --
469 -- Post Success:
470 -- On successful completion of the ins_lck process the parental
471 -- datetracked rows will be locked providing the p_enforce_foreign_locking
472 -- argument value is TRUE.
473 -- If the p_enforce_foreign_locking argument value is FALSE then the
474 -- parential rows are not locked.
475 --
476 -- Post Failure:
477 -- The Lck process can fail for:
478 -- 1) When attempting to lock the row the row could already be locked by
479 -- another user. This will raise the HR_Api.Object_Locked exception.
480 -- 2) When attempting to the lock the parent which doesn't exist.
481 -- For the entity to be locked the parent must exist!
482 --
483 -- Developer Implementation Notes:
484 -- None.
485 --
486 -- Access Status:
487 -- Internal Row Handler Use Only.
488 --
489 -- {End Of Comments}
490 -- ----------------------------------------------------------------------------
491 Procedure ins_lck
492 (p_effective_date in date
493 ,p_datetrack_mode in varchar2
494 ,p_rec in ame_stv_shd.g_rec_type
495 ,p_validation_start_date out nocopy date
496 ,p_validation_end_date out nocopy date
497 ) is
498 --
499 cursor csr_lck is
500 select null
501 from AME_CONDITIONS
502 where condition_id = p_rec.condition_id
503 and p_effective_date between start_date
504 and nvl(end_date - ame_util.oneSecond, p_effective_date)
505 for update nowait;
506 l_proc varchar2(72) := g_package||'ins_lck';
507 l_key varchar2(1);
508 l_validation_start_date date;
509 l_validation_end_date date;
510 --
511 Begin
512 hr_utility.set_location('Entering:'||l_proc, 5);
513 --
514 -- Validate the datetrack mode mode getting the validation start
515 -- and end dates for the specified datetrack operation.
516 --
517 --
518 -- Set the validation start and end date OUT arguments
519 --
520 -- p_validation_start_date := l_validation_start_date;
521 -- p_validation_end_date := l_validation_end_date;
522 -- MURTHY_CHANGES
523 --
524 -- Issue a lock on the parents.
525 --
526 open csr_lck;
527 fetch csr_lck into l_key;
528 if(csr_lck%notfound) then
529 close csr_lck;
530 fnd_message.set_name('PER', 'AME_400478_CANNOT_LOCK_PARENT');
531 fnd_message.raise_error;
532 end if;
533 close csr_lck;
534 --
535 p_validation_start_date := sysdate;
536 p_validation_end_date := ame_utility_pkg.endOfTime;
537 --
538 hr_utility.set_location(' Leaving:'||l_proc, 10);
539 --
540 End ins_lck;
541 --
542 -- ----------------------------------------------------------------------------
543 -- |---------------------------------< ins >----------------------------------|
544 -- ----------------------------------------------------------------------------
545 Procedure ins
546 (p_effective_date in date
547 ,p_rec in out nocopy ame_stv_shd.g_rec_type
548 ) is
549 --
550 l_proc varchar2(72) := g_package||'ins';
551 l_datetrack_mode varchar2(30) := hr_api.g_insert;
552 l_validation_start_date date;
553 l_validation_end_date date;
554 --
555 Begin
556 hr_utility.set_location('Entering:'||l_proc, 5);
557 --
558 -- Call the lock operation
559 --
560 ame_stv_ins.ins_lck
561 (p_effective_date => p_effective_date
562 ,p_datetrack_mode => l_datetrack_mode
563 ,p_rec => p_rec
564 ,p_validation_start_date => l_validation_start_date
565 ,p_validation_end_date => l_validation_end_date
566 );
567 --
568 -- Call the supporting insert validate operations
569 --
570 ame_stv_bus.insert_validate
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 -- Call to raise any errors on multi-message list
579 hr_multi_message.end_validation_set;
580 --
581 -- Call the supporting pre-insert operation
582 --
583 ame_stv_ins.pre_insert
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 -- Insert the row
592 --
593 ame_stv_ins.insert_dml
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 the supporting post-insert operation
602 --
603 ame_stv_ins.post_insert
604 (p_rec => p_rec
605 ,p_effective_date => p_effective_date
606 ,p_datetrack_mode => l_datetrack_mode
607 ,p_validation_start_date => l_validation_start_date
608 ,p_validation_end_date => l_validation_end_date
609 );
610 --
611 -- Call to raise any errors on multi-message list
612 hr_multi_message.end_validation_set;
613 --
614 hr_utility.set_location('Leaving:'||l_proc,10);
615 end ins;
616 --
617 -- ----------------------------------------------------------------------------
618 -- |---------------------------------< ins >----------------------------------|
619 -- ----------------------------------------------------------------------------
620 Procedure ins
621 (p_effective_date in date
622 ,p_security_group_id in number default null
623 ,p_condition_id in number
624 ,p_string_value in varchar2
625 ,p_object_version_number out nocopy number
626 ,p_start_date out nocopy date
627 ,p_end_date out nocopy date
628 ) is
629 --
630 l_rec ame_stv_shd.g_rec_type;
631 l_proc varchar2(72) := g_package||'ins';
632 --
633 Begin
634 hr_utility.set_location('Entering:'||l_proc, 5);
635 --
636 -- Call conversion function to turn arguments into the
637 -- p_rec structure.
638 --
639 l_rec :=
640 ame_stv_shd.convert_args
641 (p_condition_id
642 ,p_string_value
643 ,null
644 ,null
645 ,p_security_group_id
646 ,null
647 );
648 --
649 -- Having converted the arguments into the ame_stv_rec
650 -- plsql record structure we call the corresponding record
651 -- business process.
652 --
653 ame_stv_ins.ins
654 (p_effective_date
655 ,l_rec
656 );
657 --
658 -- Set the OUT arguments.
659 --
660 p_start_date := l_rec.start_date;
661 p_end_date := l_rec.end_date;
662 p_object_version_number := l_rec.object_version_number;
663 --
664 --
665 hr_utility.set_location(' Leaving:'||l_proc, 10);
666 End ins;
667 --
668 end ame_stv_ins;