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