1 Package Body ame_itu_ins as
2 /* $Header: amiturhi.pkb 120.6 2006/10/05 16:11:40 pvelugul noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' ame_itu_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_application_id_i number default null;
14 g_item_class_id_i number default null;
15 --
16 -- ----------------------------------------------------------------------------
17 -- |------------------------< set_base_key_value >----------------------------|
18 -- ----------------------------------------------------------------------------
19 procedure set_base_key_value
20 (p_application_id in number
21 ,p_item_class_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_itu_ins.g_application_id_i := p_application_id;
29 ame_itu_ins.g_item_class_id_i := p_item_class_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_itu_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_item_class_usages t
94 where t.item_class_id = p_rec.item_class_id
95 and t.application_id = p_rec.application_id
96 and t.start_date = ame_itu_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_item_class_usages t
102 where t.item_class_id = p_rec.item_class_id
103 and t.application_id = p_rec.application_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_item_class_usages.created_by%TYPE;
109 l_creation_date ame_item_class_usages.creation_date%TYPE;
110 l_last_update_date ame_item_class_usages.last_update_date%TYPE;
111 l_last_updated_by ame_item_class_usages.last_updated_by%TYPE;
112 l_last_update_login ame_item_class_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 --
125 --
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;
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_itu_shd.get_object_version_number
136 (p_item_class_id => p_rec.item_class_id
137 ,p_application_id => p_rec.application_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_item_class_usages
192 --
193 insert into ame_item_class_usages
194 (application_id
195 ,item_class_id
196 ,item_id_query
197 ,item_class_order_number
198 ,item_class_par_mode
199 ,item_class_sublist_mode
200 ,start_date
201 ,end_date
202 ,object_version_number
203 ,created_by
204 ,creation_date
205 ,last_update_date
206 ,last_updated_by
207 ,last_update_login
208 )
209 Values
210 (p_rec.application_id
211 ,p_rec.item_class_id
212 ,p_rec.item_id_query
213 ,p_rec.item_class_order_number
214 ,p_rec.item_class_par_mode
215 ,p_rec.item_class_sublist_mode
216 ,p_rec.start_date
217 ,p_rec.end_date
218 ,p_rec.object_version_number
219 ,l_created_by
220 ,l_creation_date
221 ,l_last_update_date
222 ,l_last_updated_by
223 ,l_last_update_login
224 );
225 --
226 --
227 hr_utility.set_location(' Leaving:'||l_proc, 15);
228 --
229 Exception
230 When hr_api.check_integrity_violated Then
231 -- A check constraint has been violated
232 --
233 ame_itu_shd.constraint_error
234 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
235 When hr_api.unique_integrity_violated Then
236 -- Unique integrity has been violated
237 --
238 ame_itu_shd.constraint_error
239 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
240 When Others Then
241 --
242 Raise;
243 End dt_insert_dml;
244 --
245 -- ----------------------------------------------------------------------------
246 -- |------------------------------< insert_dml >------------------------------|
247 -- ----------------------------------------------------------------------------
248 Procedure insert_dml
249 (p_rec in out nocopy ame_itu_shd.g_rec_type
250 ,p_effective_date in date
251 ,p_datetrack_mode in varchar2
252 ,p_validation_start_date in date
253 ,p_validation_end_date in date
254 ) is
255 --
256 l_proc varchar2(72) := g_package||'insert_dml';
257 --
258 Begin
259 hr_utility.set_location('Entering:'||l_proc, 5);
260 --
261 ame_itu_ins.dt_insert_dml
262 (p_rec => p_rec
263 ,p_effective_date => p_effective_date
264 ,p_datetrack_mode => p_datetrack_mode
265 ,p_validation_start_date => p_validation_start_date
266 ,p_validation_end_date => p_validation_end_date
267 );
268 --
269 hr_utility.set_location(' Leaving:'||l_proc, 10);
270 End insert_dml;
271 --
272 -- ----------------------------------------------------------------------------
273 -- |------------------------------< pre_insert >------------------------------|
274 -- ----------------------------------------------------------------------------
275 -- {Start Of Comments}
276 --
277 -- Description:
278 -- This private procedure contains any processing which is required before
279 -- the insert dml. Presently, if the entity has a corresponding primary
280 -- key which is maintained by an associating sequence, the primary key for
281 -- the entity will be populated with the next sequence value in
282 -- preparation for the insert dml.
283 -- Also, if comments are defined for this entity, the comments insert
284 -- logic will also be called, generating a comment_id if required.
285 --
286 -- Prerequisites:
287 -- This is an internal procedure which is called from the ins procedure.
288 --
289 -- In Parameters:
290 -- A Pl/Sql record structure.
291 --
292 -- Post Success:
293 -- Processing continues.
294 --
295 -- Post Failure:
296 -- If an error has occurred, an error message and exception will be raised
297 -- but not handled.
298 --
299 -- Developer Implementation Notes:
300 -- Any pre-processing required before the insert dml is issued should be
301 -- coded within this procedure. As stated above, a good example is the
302 -- generation of a primary key number via a corresponding sequence.
303 -- It is important to note that any 3rd party maintenance should be reviewed
304 -- before placing in this procedure.
305 --
306 -- Access Status:
307 -- Internal Row Handler Use Only.
308 --
309 -- {End Of Comments}
310 -- ----------------------------------------------------------------------------
311 Procedure pre_insert
312 (p_rec in out nocopy ame_itu_shd.g_rec_type
313 ,p_effective_date in date
314 ,p_datetrack_mode in varchar2
315 ,p_validation_start_date in date
316 ,p_validation_end_date in date
317 ) is
318 --
319 /*
320 Cursor C_Sel1 is select ame_item_class_usages_s.nextval from sys.dual;
321 */
322 --
323 Cursor C_Sel2 is
324 Select null
325 from ame_item_class_usages
326 where application_id =
327 ame_itu_ins.g_application_id_i
328 and item_class_id =
329 ame_itu_ins.g_item_class_id_i;
330 --
331 l_proc varchar2(72) := g_package||'pre_insert';
332 l_exists varchar2(1);
333 --
334 Begin
335 hr_utility.set_location('Entering:'||l_proc, 5);
336 --
337 If (ame_itu_ins.g_application_id_i is not null or
338 ame_itu_ins.g_item_class_id_i is not null) Then
339 --
340 -- Verify registered primary key values not already in use
341 --
342 Open C_Sel2;
343 Fetch C_Sel2 into l_exists;
344 If C_Sel2%found Then
345 Close C_Sel2;
346 --
347 -- The primary key values are already in use.
348 --
349 fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
350 fnd_message.set_token('TABLE_NAME','ame_item_class_usages');
351 fnd_message.raise_error;
352 End If;
353 Close C_Sel2;
354 --
355 -- Use registered key values and clear globals
356 --
357 p_rec.application_id :=
358 ame_itu_ins.g_application_id_i;
359 ame_itu_ins.g_application_id_i := null;
360 p_rec.item_class_id :=
361 ame_itu_ins.g_item_class_id_i;
362 ame_itu_ins.g_item_class_id_i := null;
363 /*
364 Else
365 --
366 -- No registerd key values, so select the next sequence number
367 --
368 --
369 -- Select the next sequence number
370 --
371 Open C_Sel1;
372 Fetch C_Sel1 Into p_rec.application_id;
373 Close C_Sel1;
374 */
375 End If;
376 --
377 --
378 hr_utility.set_location(' Leaving:'||l_proc, 10);
379 End pre_insert;
380 --
381 -- ----------------------------------------------------------------------------
382 -- |----------------------------< post_insert >-------------------------------|
383 -- ----------------------------------------------------------------------------
384 -- {Start Of Comments}
385 --
386 -- Description:
387 -- This private procedure contains any processing which is required after
388 -- the insert dml.
389 --
390 -- Prerequisites:
391 -- This is an internal procedure which is called from the ins procedure.
392 --
393 -- In Parameters:
394 -- A Pl/Sql record structure.
395 --
396 -- Post Success:
397 -- Processing continues.
398 --
399 -- Post Failure:
400 -- If an error has occurred, an error message and exception will be raised
401 -- but not handled.
402 --
403 -- Developer Implementation Notes:
404 -- Any post-processing required after the insert dml is issued should be
405 -- coded within this procedure. It is important to note that any 3rd party
406 -- maintenance should be reviewed before placing in this procedure.
407 --
408 -- Access Status:
409 -- Internal Row Handler Use Only.
410 --
414 (p_rec in ame_itu_shd.g_rec_type
411 -- {End Of Comments}
412 -- ----------------------------------------------------------------------------
413 Procedure post_insert
415 ,p_effective_date in date
416 ,p_datetrack_mode in varchar2
417 ,p_validation_start_date in date
418 ,p_validation_end_date in date
419 ) is
420 --
421 l_proc varchar2(72) := g_package||'post_insert';
422 --
423 Begin
424 hr_utility.set_location('Entering:'||l_proc, 5);
425 begin
426 --
427 ame_itu_rki.after_insert
428 (p_effective_date => p_effective_date
429 ,p_validation_start_date => p_validation_start_date
430 ,p_validation_end_date => p_validation_end_date
431 ,p_application_id => p_rec.application_id
432 ,p_item_class_id => p_rec.item_class_id
433 ,p_item_id_query => p_rec.item_id_query
434 ,p_item_class_order_number => p_rec.item_class_order_number
435 ,p_item_class_par_mode => p_rec.item_class_par_mode
436 ,p_item_class_sublist_mode => p_rec.item_class_sublist_mode
437 ,p_start_date => p_rec.start_date
438 ,p_end_date => p_rec.end_date
439 ,p_object_version_number => 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_ITEM_CLASS_USAGES'
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_itu_shd.g_rec_type
495 ,p_validation_start_date out nocopy date
496 ,p_validation_end_date out nocopy date
497 ) is
498 --
499 l_proc varchar2(72) := g_package||'ins_lck';
500 l_validation_start_date date;
501 l_validation_end_date date;
502 --
503 Begin
504 hr_utility.set_location('Entering:'||l_proc, 5);
505 --
506 -- Validate the datetrack mode mode getting the validation start
507 -- and end dates for the specified datetrack operation.
508 --
509 --
510 -- Set the validation start and end date OUT arguments
511 --
512 -- p_validation_start_date := l_validation_start_date;
513 -- p_validation_end_date := l_validation_end_date;
514 -- MURTHY_CHANGES
515 p_validation_start_date := sysdate;
516 p_validation_end_date := ame_utility_pkg.endOfTime;
517 --
518 hr_utility.set_location(' Leaving:'||l_proc, 10);
519 --
520 End ins_lck;
521 --
522 -- ----------------------------------------------------------------------------
523 -- |---------------------------------< ins >----------------------------------|
524 -- ----------------------------------------------------------------------------
525 Procedure ins
526 (p_effective_date in date
527 ,p_rec in out nocopy ame_itu_shd.g_rec_type
528 ) is
529 --
530 l_proc varchar2(72) := g_package||'ins';
531 l_datetrack_mode varchar2(30) := hr_api.g_insert;
532 l_validation_start_date date;
533 l_validation_end_date date;
534 --
535 Begin
536 hr_utility.set_location('Entering:'||l_proc, 5);
537 --
538 -- Call the lock operation
539 --
540 ame_itu_ins.ins_lck
541 (p_effective_date => p_effective_date
542 ,p_datetrack_mode => l_datetrack_mode
543 ,p_rec => p_rec
544 ,p_validation_start_date => l_validation_start_date
545 ,p_validation_end_date => l_validation_end_date
546 );
547 --
548 -- Call the supporting insert validate operations
549 --
550 ame_itu_bus.insert_validate
551 (p_rec => p_rec
552 ,p_effective_date => p_effective_date
553 ,p_datetrack_mode => l_datetrack_mode
554 ,p_validation_start_date => l_validation_start_date
555 ,p_validation_end_date => l_validation_end_date
556 );
557 --
558 -- Call to raise any errors on multi-message list
559 hr_multi_message.end_validation_set;
560 --
561 -- Call the supporting pre-insert operation
562 --
563 ame_itu_ins.pre_insert
564 (p_rec => p_rec
565 ,p_effective_date => p_effective_date
566 ,p_datetrack_mode => l_datetrack_mode
567 ,p_validation_start_date => l_validation_start_date
568 ,p_validation_end_date => l_validation_end_date
569 );
570 --
571 -- Insert the row
572 --
573 ame_itu_ins.insert_dml
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 -- Call the supporting post-insert operation
582 --
583 ame_itu_ins.post_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 -- Call to raise any errors on multi-message list
592 hr_multi_message.end_validation_set;
593 --
594 hr_utility.set_location('Leaving:'||l_proc,10);
595 end ins;
596 --
597 -- ----------------------------------------------------------------------------
598 -- |---------------------------------< ins >----------------------------------|
599 -- ----------------------------------------------------------------------------
600 Procedure ins
601 (p_effective_date in date
602 ,p_item_id_query in varchar2
603 ,p_item_class_order_number in number
604 ,p_item_class_par_mode in varchar2
605 ,p_item_class_sublist_mode in varchar2
606 ,p_application_id in out nocopy number
607 ,p_item_class_id in out nocopy number
608 ,p_object_version_number out nocopy number
609 ,p_start_date out nocopy date
610 ,p_end_date out nocopy date
611 ) is
612 --
613 l_rec ame_itu_shd.g_rec_type;
614 l_proc varchar2(72) := g_package||'ins';
615 --
616 Begin
617 hr_utility.set_location('Entering:'||l_proc, 5);
618 --
619 -- Call conversion function to turn arguments into the
620 -- p_rec structure.
621 --
622 l_rec :=
623 ame_itu_shd.convert_args
624 (p_application_id
625 ,p_item_class_id
626 ,p_item_id_query
627 ,p_item_class_order_number
628 ,p_item_class_par_mode
629 ,p_item_class_sublist_mode
630 ,null
631 ,null
632 ,null
633 );
634 --
635 -- Having converted the arguments into the ame_itu_rec
636 -- plsql record structure we call the corresponding record
637 -- business process.
638 --
639 ame_itu_ins.ins
640 (p_effective_date
641 ,l_rec
642 );
643 --
644 -- Set the OUT arguments.
645 --
646 p_item_class_id := l_rec.item_class_id;
647 p_application_id := l_rec.application_id;
648 p_start_date := l_rec.start_date;
649 p_end_date := l_rec.end_date;
650 p_object_version_number := l_rec.object_version_number;
651 --
652 --
653 hr_utility.set_location(' Leaving:'||l_proc, 10);
654 End ins;
655 --
656 end ame_itu_ins;