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