1 Package Body irc_iad_ins as
2 /* $Header: iriadrhi.pkb 120.5.12010000.2 2010/01/11 10:41:25 uuddavol ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' irc_iad_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_assignment_details_id_i number default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19 (p_assignment_details_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 irc_iad_ins.g_assignment_details_id_i := p_assignment_details_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 irc_iad_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.created_by,
90 t.creation_date
91 from irc_assignment_details_f t
92 where t.assignment_id = p_rec.assignment_id
93 and t.effective_start_date =
94 irc_iad_shd.g_old_rec.effective_start_date
95 and (t.effective_end_date = (p_validation_start_date - 1)
96 or t.effective_end_date = irc_iad_shd.g_old_rec.effective_end_date);
97 --
98 -- Cursor to get the new Details Version number
99 Cursor c_details_version is
100 select nvl(max(details_version), 0)+1
101 from irc_assignment_details_f
102 where assignment_id = p_rec.assignment_id
103 and effective_start_date = p_validation_start_date
104 and effective_end_date = p_validation_end_date;
105 --
106 l_proc varchar2(72) := g_package||'dt_insert_dml';
107 l_created_by irc_assignment_details_f.created_by%TYPE;
108 l_creation_date irc_assignment_details_f.creation_date%TYPE;
109 l_last_update_date irc_assignment_details_f.last_update_date%TYPE;
110 l_last_updated_by irc_assignment_details_f.last_updated_by%TYPE;
111 l_last_update_login irc_assignment_details_f.last_update_login%TYPE;
112 --
113 Begin
114 hr_utility.set_location('Entering:'||l_proc, 5);
115 --
116 -- Set the effective start and end dates to the corresponding
117 -- validation start and end dates
118 --
119 p_rec.effective_start_date := p_validation_start_date;
120 p_rec.effective_end_date := p_validation_end_date;
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 dt_api.get_object_version_number
132 (p_base_table_name => 'irc_assignment_details_f'
133 ,p_base_key_column => 'assignment_id'
134 ,p_base_key_value => p_rec.assignment_id
135 );
136 --
137 -- Select the 'old' created values
138 --
139 Open C_Sel1;
140 Fetch C_Sel1 Into l_created_by, l_creation_date;
141 If C_Sel1%notfound Then
142 --
143 -- The previous 'old' created row has not been found. We need
144 -- to error as an internal datetrack problem exists.
145 --
146 Close C_Sel1;
147 fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
148 fnd_message.set_token('PROCEDURE', l_proc);
149 fnd_message.set_token('STEP','10');
150 fnd_message.raise_error;
151 End If;
152 Close C_Sel1;
153 --
154 -- Set the AOL updated WHO values
155 --
156 l_last_update_date := sysdate;
157 l_last_updated_by := fnd_global.user_id;
158 l_last_update_login := fnd_global.login_id;
159 --
160 -- Get the Assignemnt Details Version
161 --
162 open c_details_version;
163 fetch c_details_version into p_rec.details_version;
164 close c_details_version;
165 Else
166 p_rec.object_version_number := 1; -- Initialise the object version
167 p_rec.details_version := 1;
168 End If;
169 --
170 -- Mark the new row being added as the latest
171 --
172 p_rec.latest_details := 'Y';
173 --
174 -- Insert the row into: irc_assignment_details_f
175 --
176 insert into irc_assignment_details_f
177 (assignment_details_id
178 ,assignment_id
179 ,effective_start_date
180 ,effective_end_date
181 ,details_version
182 ,latest_details
183 ,attempt_id
184 ,qualified
185 ,considered
186 ,object_version_number
187 ,created_by
188 ,creation_date
189 ,last_update_date
190 ,last_updated_by
191 ,last_update_login
192 )
193 Values
194 (p_rec.assignment_details_id
195 ,p_rec.assignment_id
196 ,p_rec.effective_start_date
197 ,p_rec.effective_end_date
198 ,p_rec.details_version
199 ,p_rec.latest_details
200 ,p_rec.attempt_id
201 ,p_rec.qualified
202 ,p_rec.considered
203 ,p_rec.object_version_number
204 ,l_created_by
205 ,l_creation_date
206 ,l_last_update_date
207 ,l_last_updated_by
208 ,l_last_update_login
209 );
210 --
211 --
212 hr_utility.set_location(' Leaving:'||l_proc, 15);
213 --
214 Exception
215 When hr_api.check_integrity_violated Then
216 -- A check constraint has been violated
217 --
218 irc_iad_shd.constraint_error
219 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
220 When hr_api.unique_integrity_violated Then
221 -- Unique integrity has been violated
222 --
223 irc_iad_shd.constraint_error
224 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
225 When Others Then
226 --
227 Raise;
228 End dt_insert_dml;
229 --
230 -- ----------------------------------------------------------------------------
231 -- |------------------------------< insert_dml >------------------------------|
232 -- ----------------------------------------------------------------------------
233 Procedure insert_dml
234 (p_rec in out nocopy irc_iad_shd.g_rec_type
235 ,p_effective_date in date
236 ,p_datetrack_mode in varchar2
237 ,p_validation_start_date in date
238 ,p_validation_end_date in date
239 ) is
240 --
241 l_proc varchar2(72) := g_package||'insert_dml';
242 --
243 Begin
244 hr_utility.set_location('Entering:'||l_proc, 5);
245 --
246 irc_iad_ins.dt_insert_dml
247 (p_rec => p_rec
248 ,p_effective_date => p_effective_date
249 ,p_datetrack_mode => p_datetrack_mode
250 ,p_validation_start_date => p_validation_start_date
251 ,p_validation_end_date => p_validation_end_date
252 );
253 --
254 hr_utility.set_location(' Leaving:'||l_proc, 10);
255 End insert_dml;
256 --
257 -- ----------------------------------------------------------------------------
258 -- |------------------------------< pre_insert >------------------------------|
259 -- ----------------------------------------------------------------------------
260 -- {Start Of Comments}
261 --
262 -- Description:
263 -- This private procedure contains any processing which is required before
264 -- the insert dml. Presently, if the entity has a corresponding primary
265 -- key which is maintained by an associating sequence, the primary key for
266 -- the entity will be populated with the next sequence value in
267 -- preparation for the insert dml.
268 -- Also, if comments are defined for this entity, the comments insert
269 -- logic will also be called, generating a comment_id if required.
270 --
271 -- Prerequisites:
272 -- This is an internal procedure which is called from the ins procedure.
273 --
274 -- In Parameters:
275 -- A Pl/Sql record structure.
276 --
277 -- Post Success:
278 -- Processing continues.
279 --
280 -- Post Failure:
281 -- If an error has occurred, an error message and exception will be raised
282 -- but not handled.
283 --
284 -- Developer Implementation Notes:
285 -- Any pre-processing required before the insert dml is issued should be
286 -- coded within this procedure. As stated above, a good example is the
287 -- generation of a primary key number via a corresponding sequence.
288 -- It is important to note that any 3rd party maintenance should be reviewed
289 -- before placing in this procedure.
290 --
291 -- Access Status:
292 -- Internal Row Handler Use Only.
293 --
294 -- {End Of Comments}
295 -- ----------------------------------------------------------------------------
296 Procedure pre_insert
297 (p_rec in out nocopy irc_iad_shd.g_rec_type
298 ,p_effective_date in date
299 ,p_datetrack_mode in varchar2
300 ,p_validation_start_date in date
301 ,p_validation_end_date in date
302 ) is
303 --
304 Cursor C_Sel1 is select irc_assignment_details_s.nextval from sys.dual;
305 --
306 Cursor C_Sel2 is
307 Select null
308 from irc_assignment_details_f
309 where assignment_details_id =
310 irc_iad_ins.g_assignment_details_id_i;
311 --
312 l_proc varchar2(72) := g_package||'pre_insert';
313 l_exists varchar2(1);
314 --
315 Begin
316 hr_utility.set_location('Entering:'||l_proc, 5);
317 --
318 If (irc_iad_ins.g_assignment_details_id_i is not null) Then
319 --
320 -- Verify registered primary key values not already in use
321 --
322 Open C_Sel2;
323 Fetch C_Sel2 into l_exists;
324 If C_Sel2%found Then
325 Close C_Sel2;
326 --
327 -- The primary key values are already in use.
328 --
329 fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
330 fnd_message.set_token('TABLE_NAME','irc_assignment_details_f');
331 fnd_message.raise_error;
332 End If;
333 Close C_Sel2;
334 --
335 -- Use registered key values and clear globals
336 --
337 p_rec.assignment_details_id :=
338 irc_iad_ins.g_assignment_details_id_i;
339 irc_iad_ins.g_assignment_details_id_i := null;
340 Else
341 --
342 -- No registerd key values, so select the next sequence number
343 --
344 --
345 -- Select the next sequence number
346 --
347 Open C_Sel1;
348 Fetch C_Sel1 Into p_rec.assignment_details_id;
349 Close C_Sel1;
350 End If;
351 --
352 --
353 hr_utility.set_location(' Leaving:'||l_proc, 10);
354 End pre_insert;
355 --
356 -- ----------------------------------------------------------------------------
357 -- |----------------------------< post_insert >-------------------------------|
358 -- ----------------------------------------------------------------------------
359 -- {Start Of Comments}
360 --
361 -- Description:
362 -- This private procedure contains any processing which is required after
363 -- the insert dml.
364 --
365 -- Prerequisites:
366 -- This is an internal procedure which is called from the ins procedure.
367 --
368 -- In Parameters:
369 -- A Pl/Sql record structure.
370 --
371 -- Post Success:
372 -- Processing continues.
373 --
374 -- Post Failure:
375 -- If an error has occurred, an error message and exception will be raised
376 -- but not handled.
377 --
378 -- Developer Implementation Notes:
379 -- Any post-processing required after the insert dml is issued should be
380 -- coded within this procedure. It is important to note that any 3rd party
381 -- maintenance should be reviewed before placing in this procedure.
382 --
383 -- Access Status:
384 -- Internal Row Handler Use Only.
385 --
386 -- {End Of Comments}
387 -- ----------------------------------------------------------------------------
388 Procedure post_insert
389 (p_rec in irc_iad_shd.g_rec_type
390 ,p_effective_date in date
391 ,p_datetrack_mode in varchar2
392 ,p_validation_start_date in date
393 ,p_validation_end_date in date
394 ) is
395 --
396 l_proc varchar2(72) := g_package||'post_insert';
397 --
398 Begin
399 hr_utility.set_location('Entering:'||l_proc, 5);
400 begin
401 --
402 irc_iad_rki.after_insert
403 (p_effective_date
404 => p_effective_date
405 ,p_validation_start_date
406 => p_validation_start_date
407 ,p_validation_end_date
408 => p_validation_end_date
409 ,p_assignment_details_id
410 => p_rec.assignment_details_id
411 ,p_qualified
412 => p_rec.qualified
413 ,p_considered
414 => p_rec.considered
415 ,p_assignment_id
416 => p_rec.assignment_id
417 ,p_effective_start_date
418 => p_rec.effective_start_date
419 ,p_effective_end_date
420 => p_rec.effective_end_date
421 ,p_details_version
422 => p_rec.details_version
423 ,p_latest_details
424 => p_rec.latest_details
425 ,p_attempt_id
426 => p_rec.attempt_id
427 ,p_object_version_number
428 => p_rec.object_version_number
429 );
430 --
431 exception
432 --
433 when hr_api.cannot_find_prog_unit then
434 --
435 hr_api.cannot_find_prog_unit_error
436 (p_module_name => 'IRC_ASSIGNMENT_DETAILS_F'
437 ,p_hook_type => 'AI');
438 --
439 end;
440 --
441 hr_utility.set_location(' Leaving:'||l_proc, 10);
442 End post_insert;
443 --
444 -- ----------------------------------------------------------------------------
445 -- |-------------------------------< ins_lck >--------------------------------|
446 -- ----------------------------------------------------------------------------
447 -- {Start Of Comments}
448 --
449 -- Description:
450 -- The ins_lck process has one main function to perform. When inserting
451 -- a datetracked row, we must validate the DT mode.
452 --
453 -- Prerequisites:
454 -- This procedure can only be called for the datetrack mode of INSERT.
455 --
456 -- In Parameters:
457 --
458 -- Post Success:
459 -- On successful completion of the ins_lck process the parental
460 -- datetracked rows will be locked providing the p_enforce_foreign_locking
461 -- argument value is TRUE.
462 -- If the p_enforce_foreign_locking argument value is FALSE then the
463 -- parential rows are not locked.
464 --
465 -- Post Failure:
466 -- The Lck process can fail for:
467 -- 1) When attempting to lock the row the row could already be locked by
468 -- another user. This will raise the HR_Api.Object_Locked exception.
469 -- 2) When attempting to the lock the parent which doesn't exist.
470 -- For the entity to be locked the parent must exist!
471 --
472 -- Developer Implementation Notes:
473 -- None.
474 --
475 -- Access Status:
476 -- Internal Row Handler Use Only.
477 --
478 -- {End Of Comments}
479 -- ----------------------------------------------------------------------------
480 Procedure ins_lck
481 (p_effective_date in date
482 ,p_datetrack_mode in varchar2
483 ,p_rec in irc_iad_shd.g_rec_type
484 ,p_validation_start_date out nocopy date
485 ,p_validation_end_date out nocopy date
486 ) is
487 --
488 l_proc varchar2(72) := g_package||'ins_lck';
489 l_validation_start_date date;
490 l_validation_end_date date;
491 --
492 Begin
493 hr_utility.set_location('Entering:'||l_proc, 5);
494 --
495 -- Validate the datetrack mode mode getting the validation start
496 -- and end dates for the specified datetrack operation.
497 --
498 dt_api.validate_dt_mode
499 (p_effective_date => p_effective_date
500 ,p_datetrack_mode => p_datetrack_mode
501 ,p_base_table_name => 'irc_assignment_details_f'
502 ,p_base_key_column => 'assignment_details_id'
503 ,p_base_key_value => p_rec.assignment_details_id
504 ,p_parent_table_name1 => 'per_all_assignments_f'
505 ,p_parent_key_column1 => 'assignment_id'
506 ,p_parent_key_value1 => p_rec.assignment_id
507 ,p_enforce_foreign_locking => true
508 ,p_validation_start_date => l_validation_start_date
509 ,p_validation_end_date => l_validation_end_date
510 );
511 --
512 -- Set the validation start and end date OUT arguments
513 --
514 p_validation_start_date := l_validation_start_date;
515 p_validation_end_date := l_validation_end_date;
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 irc_iad_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 irc_iad_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 irc_iad_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 irc_iad_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 irc_iad_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 irc_iad_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_assignment_id in number
602 ,p_attempt_id in number default null
603 ,p_qualified in varchar2
604 ,p_considered in varchar2
605 ,p_assignment_details_id out nocopy number
606 ,p_details_version out nocopy number
607 ,p_latest_details out nocopy varchar2
608 ,p_effective_start_date out nocopy date
609 ,p_effective_end_date out nocopy date
610 ,p_object_version_number out nocopy number
611 ) is
612 --
613 l_rec irc_iad_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 irc_iad_shd.convert_args
624 (null
625 ,p_assignment_id
626 ,null
627 ,null
628 ,null
629 ,null
630 ,p_attempt_id
631 ,p_qualified
632 ,p_considered
633 ,null
634 );
635 --
636 -- Having converted the arguments into the irc_iad_rec
637 -- plsql record structure we call the corresponding record
638 -- business process.
639 --
640 irc_iad_ins.ins
641 (p_effective_date
642 ,l_rec
643 );
644 --
645 -- Set the OUT arguments.
646 --
647 p_assignment_details_id := l_rec.assignment_details_id;
648 p_details_version := l_rec.details_version;
649 p_latest_details := l_rec.latest_details;
650 p_effective_start_date := l_rec.effective_start_date;
651 p_effective_end_date := l_rec.effective_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 irc_iad_ins;