1 Package Body pqh_rmr_ins as
2 /* $Header: pqrmrrhi.pkb 120.0 2005/05/29 02:34 appldev noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' pqh_rmr_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_rate_matrix_rate_id_i number default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19 (p_rate_matrix_rate_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 pqh_rmr_ins.g_rate_matrix_rate_id_i := p_rate_matrix_rate_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 pqh_rmr_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 pqh_rate_matrix_rates_f t
92 where t.rate_matrix_rate_id = p_rec.rate_matrix_rate_id
93 and t.effective_start_date =
94 pqh_rmr_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 pqh_rate_matrix_rates_f.created_by%TYPE;
99 l_creation_date pqh_rate_matrix_rates_f.creation_date%TYPE;
100 l_last_update_date pqh_rate_matrix_rates_f.last_update_date%TYPE;
101 l_last_updated_by pqh_rate_matrix_rates_f.last_updated_by%TYPE;
102 l_last_update_login pqh_rate_matrix_rates_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 => 'pqh_rate_matrix_rates_f'
124 ,p_base_key_column => 'rate_matrix_rate_id'
125 ,p_base_key_value => p_rec.rate_matrix_rate_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 --
155 --
156 -- Insert the row into: pqh_rate_matrix_rates_f
157 --
158 insert into pqh_rate_matrix_rates_f
159 (rate_matrix_rate_id
160 ,effective_start_date
161 ,effective_end_date
162 ,rate_matrix_node_id
163 ,criteria_rate_defn_id
164 ,min_rate_value
165 ,max_rate_value
166 ,mid_rate_value
167 ,rate_value
168 ,business_group_id
169 ,legislation_code
170 ,object_version_number
171 ,created_by
172 ,creation_date
173 ,last_update_date
174 ,last_updated_by
175 ,last_update_login
176 )
177 Values
178 (p_rec.rate_matrix_rate_id
179 ,p_rec.effective_start_date
180 ,p_rec.effective_end_date
181 ,p_rec.rate_matrix_node_id
182 ,p_rec.criteria_rate_defn_id
183 ,p_rec.min_rate_value
184 ,p_rec.max_rate_value
185 ,p_rec.mid_rate_value
186 ,p_rec.rate_value
187 ,p_rec.business_group_id
188 ,p_rec.legislation_code
189 ,p_rec.object_version_number
190 ,l_created_by
191 ,l_creation_date
192 ,l_last_update_date
193 ,l_last_updated_by
194 ,l_last_update_login
195 );
196 --
197 --
198 hr_utility.set_location(' Leaving:'||l_proc, 15);
199 --
200 Exception
201 When hr_api.check_integrity_violated Then
202 -- A check constraint has been violated
203 --
204 pqh_rmr_shd.constraint_error
205 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
206 When hr_api.unique_integrity_violated Then
207 -- Unique integrity has been violated
208 --
209 pqh_rmr_shd.constraint_error
210 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
211 When Others Then
212 --
213 Raise;
214 End dt_insert_dml;
215 --
216 -- ----------------------------------------------------------------------------
217 -- |-----------------------< create_app_ownerships >--------------------------|
218 -- ----------------------------------------------------------------------------
219 --
220 -- Description:
221 -- This procedure inserts a row into the HR_APPLICATION_OWNERSHIPS table
222 -- when the row handler is called in the appropriate mode.
223 --
224 -- ----------------------------------------------------------------------------
225 PROCEDURE create_app_ownerships(p_pk_column IN varchar2
226 ,p_pk_value IN varchar2) IS
227 --
228 CURSOR csr_definition IS
229 SELECT product_short_name
230 FROM hr_owner_definitions
231 WHERE session_id = hr_startup_data_api_support.g_session_id;
232 --
233 BEGIN
234 --
235 IF (hr_startup_data_api_support.return_startup_mode IN
236 ('STARTUP','GENERIC')) THEN
237 --
238 FOR c1 IN csr_definition LOOP
239 --
240 INSERT INTO hr_application_ownerships
241 (key_name
242 ,key_value
243 ,product_name
244 )
245 VALUES
246 (p_pk_column
247 ,fnd_number.number_to_canonical(p_pk_value)
248 ,c1.product_short_name
249 );
250 END LOOP;
251 END IF;
252 END create_app_ownerships;
253 --
254 -- ----------------------------------------------------------------------------
255 -- |-----------------------< create_app_ownerships >--------------------------|
256 -- ----------------------------------------------------------------------------
257 PROCEDURE create_app_ownerships(p_pk_column IN varchar2
258 ,p_pk_value IN number) IS
259 --
260 BEGIN
261 create_app_ownerships(p_pk_column, to_char(p_pk_value));
262 END create_app_ownerships;
263 --
264 -- ----------------------------------------------------------------------------
265 -- |------------------------------< insert_dml >------------------------------|
266 -- ----------------------------------------------------------------------------
267 Procedure insert_dml
268 (p_rec in out nocopy pqh_rmr_shd.g_rec_type
269 ,p_effective_date in date
270 ,p_datetrack_mode in varchar2
271 ,p_validation_start_date in date
272 ,p_validation_end_date in date
273 ) is
274 --
275 l_proc varchar2(72) := g_package||'insert_dml';
276 --
277 Begin
278 hr_utility.set_location('Entering:'||l_proc, 5);
279 --
280 pqh_rmr_ins.dt_insert_dml
281 (p_rec => p_rec
282 ,p_effective_date => p_effective_date
283 ,p_datetrack_mode => p_datetrack_mode
284 ,p_validation_start_date => p_validation_start_date
285 ,p_validation_end_date => p_validation_end_date
286 );
287 --
288 hr_utility.set_location(' Leaving:'||l_proc, 10);
289 End insert_dml;
290 --
291 -- ----------------------------------------------------------------------------
292 -- |------------------------------< pre_insert >------------------------------|
293 -- ----------------------------------------------------------------------------
294 -- {Start Of Comments}
295 --
296 -- Description:
297 -- This private procedure contains any processing which is required before
298 -- the insert dml. Presently, if the entity has a corresponding primary
299 -- key which is maintained by an associating sequence, the primary key for
300 -- the entity will be populated with the next sequence value in
301 -- preparation for the insert dml.
302 -- Also, if comments are defined for this entity, the comments insert
303 -- logic will also be called, generating a comment_id if required.
304 --
305 -- Prerequisites:
306 -- This is an internal procedure which is called from the ins procedure.
307 --
308 -- In Parameters:
309 -- A Pl/Sql record structure.
310 --
311 -- Post Success:
312 -- Processing continues.
313 --
314 -- Post Failure:
315 -- If an error has occurred, an error message and exception will be raised
316 -- but not handled.
317 --
318 -- Developer Implementation Notes:
319 -- Any pre-processing required before the insert dml is issued should be
320 -- coded within this procedure. As stated above, a good example is the
321 -- generation of a primary key number via a corresponding sequence.
322 -- It is important to note that any 3rd party maintenance should be reviewed
323 -- before placing in this procedure.
324 --
325 -- Access Status:
326 -- Internal Row Handler Use Only.
327 --
328 -- {End Of Comments}
329 -- ----------------------------------------------------------------------------
330 Procedure pre_insert
331 (p_rec in out nocopy pqh_rmr_shd.g_rec_type
332 ,p_effective_date in date
333 ,p_datetrack_mode in varchar2
334 ,p_validation_start_date in date
335 ,p_validation_end_date in date
336 ) is
337 --
338 Cursor C_Sel1 is select pqh_rate_matrix_rates_s.nextval from sys.dual;
339 --
340 Cursor C_Sel2 is
341 Select null
342 from pqh_rate_matrix_rates_f
343 where rate_matrix_rate_id =
344 pqh_rmr_ins.g_rate_matrix_rate_id_i;
345 --
346 l_proc varchar2(72) := g_package||'pre_insert';
347 l_exists varchar2(1);
348 --
349 Begin
350 hr_utility.set_location('Entering:'||l_proc, 5);
351 --
352 If (pqh_rmr_ins.g_rate_matrix_rate_id_i is not null) Then
353 --
354 -- Verify registered primary key values not already in use
355 --
356 Open C_Sel2;
357 Fetch C_Sel2 into l_exists;
358 If C_Sel2%found Then
359 Close C_Sel2;
360 --
361 -- The primary key values are already in use.
362 --
363 fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
364 fnd_message.set_token('TABLE_NAME','pqh_rate_matrix_rates_f');
365 fnd_message.raise_error;
366 End If;
367 Close C_Sel2;
368 --
369 -- Use registered key values and clear globals
370 --
371 p_rec.rate_matrix_rate_id :=
372 pqh_rmr_ins.g_rate_matrix_rate_id_i;
373 pqh_rmr_ins.g_rate_matrix_rate_id_i := null;
374 Else
375 --
376 -- No registerd key values, so select the next sequence number
377 --
378 --
379 -- Select the next sequence number
380 --
381 Open C_Sel1;
382 Fetch C_Sel1 Into p_rec.rate_matrix_rate_id;
383 Close C_Sel1;
384 End If;
385 --
386 --
387 hr_utility.set_location(' Leaving:'||l_proc, 10);
388 End pre_insert;
389 --
390 -- ----------------------------------------------------------------------------
391 -- |----------------------------< post_insert >-------------------------------|
392 -- ----------------------------------------------------------------------------
393 -- {Start Of Comments}
394 --
395 -- Description:
396 -- This private procedure contains any processing which is required after
397 -- the insert dml.
398 --
399 -- Prerequisites:
400 -- This is an internal procedure which is called from the ins procedure.
401 --
402 -- In Parameters:
403 -- A Pl/Sql record structure.
404 --
405 -- Post Success:
406 -- Processing continues.
407 --
408 -- Post Failure:
409 -- If an error has occurred, an error message and exception will be raised
410 -- but not handled.
411 --
412 -- Developer Implementation Notes:
413 -- Any post-processing required after the insert dml is issued should be
414 -- coded within this procedure. It is important to note that any 3rd party
415 -- maintenance should be reviewed before placing in this procedure.
416 --
417 -- Access Status:
418 -- Internal Row Handler Use Only.
419 --
420 -- {End Of Comments}
421 -- ----------------------------------------------------------------------------
422 Procedure post_insert
423 (p_rec in pqh_rmr_shd.g_rec_type
424 ,p_effective_date in date
425 ,p_datetrack_mode in varchar2
426 ,p_validation_start_date in date
427 ,p_validation_end_date in date
428 ) is
429 --
430 l_proc varchar2(72) := g_package||'post_insert';
431 --
432 Begin
433 hr_utility.set_location('Entering:'||l_proc, 5);
434 begin
435 --
436 -- insert ownerships if applicable
437 create_app_ownerships
438 ('RATE_MATRIX_RATE_ID', p_rec.rate_matrix_rate_id
439 );
440 --
441 --
442 pqh_rmr_rki.after_insert
443 (p_effective_date
444 => p_effective_date
445 ,p_validation_start_date
446 => p_validation_start_date
447 ,p_validation_end_date
448 => p_validation_end_date
449 ,p_rate_matrix_rate_id
450 => p_rec.rate_matrix_rate_id
451 ,p_effective_start_date
452 => p_rec.effective_start_date
453 ,p_effective_end_date
454 => p_rec.effective_end_date
455 ,p_rate_matrix_node_id
456 => p_rec.rate_matrix_node_id
457 ,p_criteria_rate_defn_id
458 => p_rec.criteria_rate_defn_id
459 ,p_min_rate_value
460 => p_rec.min_rate_value
461 ,p_max_rate_value
462 => p_rec.max_rate_value
463 ,p_mid_rate_value
464 => p_rec.mid_rate_value
465 ,p_rate_value
466 => p_rec.rate_value
467 ,p_business_group_id
468 => p_rec.business_group_id
469 ,p_legislation_code
470 => p_rec.legislation_code
471 ,p_object_version_number
472 => p_rec.object_version_number
473 );
474 --
475 exception
476 --
477 when hr_api.cannot_find_prog_unit then
478 --
479 hr_api.cannot_find_prog_unit_error
480 (p_module_name => 'PQH_RATE_MATRIX_RATES_F'
481 ,p_hook_type => 'AI');
482 --
483 end;
484 --
485 hr_utility.set_location(' Leaving:'||l_proc, 10);
486 End post_insert;
487 --
488 -- ----------------------------------------------------------------------------
489 -- |-------------------------------< ins_lck >--------------------------------|
490 -- ----------------------------------------------------------------------------
491 -- {Start Of Comments}
492 --
493 -- Description:
494 -- The ins_lck process has one main function to perform. When inserting
495 -- a datetracked row, we must validate the DT mode.
496 --
497 -- Prerequisites:
498 -- This procedure can only be called for the datetrack mode of INSERT.
499 --
500 -- In Parameters:
501 --
502 -- Post Success:
503 -- On successful completion of the ins_lck process the parental
504 -- datetracked rows will be locked providing the p_enforce_foreign_locking
505 -- argument value is TRUE.
506 -- If the p_enforce_foreign_locking argument value is FALSE then the
507 -- parential rows are not locked.
508 --
509 -- Post Failure:
510 -- The Lck process can fail for:
511 -- 1) When attempting to lock the row the row could already be locked by
512 -- another user. This will raise the HR_Api.Object_Locked exception.
513 -- 2) When attempting to the lock the parent which doesn't exist.
514 -- For the entity to be locked the parent must exist!
515 --
516 -- Developer Implementation Notes:
517 -- None.
518 --
519 -- Access Status:
520 -- Internal Row Handler Use Only.
521 --
522 -- {End Of Comments}
523 -- ----------------------------------------------------------------------------
524 Procedure ins_lck
525 (p_effective_date in date
526 ,p_datetrack_mode in varchar2
527 ,p_rec in pqh_rmr_shd.g_rec_type
528 ,p_validation_start_date out nocopy date
529 ,p_validation_end_date out nocopy date
530 ) is
531 --
532 l_proc varchar2(72) := g_package||'ins_lck';
533 l_validation_start_date date;
534 l_validation_end_date date;
535 --
536 Begin
537 hr_utility.set_location('Entering:'||l_proc, 5);
538 --
539 -- Validate the datetrack mode mode getting the validation start
540 -- and end dates for the specified datetrack operation.
541 --
542 dt_api.validate_dt_mode
543 (p_effective_date => p_effective_date
544 ,p_datetrack_mode => p_datetrack_mode
545 ,p_base_table_name => 'pqh_rate_matrix_rates_f'
546 ,p_base_key_column => 'rate_matrix_rate_id'
547 ,p_base_key_value => p_rec.rate_matrix_rate_id
548 ,p_enforce_foreign_locking => true
549 ,p_validation_start_date => l_validation_start_date
550 ,p_validation_end_date => l_validation_end_date
551 );
552 --
553 -- Set the validation start and end date OUT arguments
554 --
555 p_validation_start_date := l_validation_start_date;
556 p_validation_end_date := l_validation_end_date;
557 --
558 hr_utility.set_location(' Leaving:'||l_proc, 10);
559 --
560 End ins_lck;
561 --
562 -- ----------------------------------------------------------------------------
563 -- |---------------------------------< ins >----------------------------------|
564 -- ----------------------------------------------------------------------------
565 Procedure ins
566 (p_effective_date in date
567 ,p_rec in out nocopy pqh_rmr_shd.g_rec_type
568 ) is
569 --
570 l_proc varchar2(72) := g_package||'ins';
571 l_datetrack_mode varchar2(30) := hr_api.g_insert;
572 l_validation_start_date date;
573 l_validation_end_date date;
574 --
575 Begin
576 hr_utility.set_location('Entering:'||l_proc, 5);
577 --
578 -- Call the lock operation
579 --
580 pqh_rmr_ins.ins_lck
581 (p_effective_date => p_effective_date
582 ,p_datetrack_mode => l_datetrack_mode
583 ,p_rec => p_rec
584 ,p_validation_start_date => l_validation_start_date
585 ,p_validation_end_date => l_validation_end_date
586 );
587 --
588 -- Call the supporting insert validate operations
589 --
590 pqh_rmr_bus.insert_validate
591 (p_rec => p_rec
592 ,p_effective_date => p_effective_date
593 ,p_datetrack_mode => l_datetrack_mode
594 ,p_validation_start_date => l_validation_start_date
595 ,p_validation_end_date => l_validation_end_date
596 );
597 --
598 -- Call to raise any errors on multi-message list
599 hr_multi_message.end_validation_set;
600 --
601 -- Call the supporting pre-insert operation
602 --
603 pqh_rmr_ins.pre_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 -- Insert the row
612 --
613 pqh_rmr_ins.insert_dml
614 (p_rec => p_rec
615 ,p_effective_date => p_effective_date
616 ,p_datetrack_mode => l_datetrack_mode
617 ,p_validation_start_date => l_validation_start_date
618 ,p_validation_end_date => l_validation_end_date
619 );
620 --
621 -- Call the supporting post-insert operation
622 --
623 pqh_rmr_ins.post_insert
624 (p_rec => p_rec
625 ,p_effective_date => p_effective_date
626 ,p_datetrack_mode => l_datetrack_mode
627 ,p_validation_start_date => l_validation_start_date
628 ,p_validation_end_date => l_validation_end_date
629 );
630 --
631 -- Call to raise any errors on multi-message list
632 hr_multi_message.end_validation_set;
633 --
634 hr_utility.set_location('Leaving:'||l_proc,10);
635 end ins;
636 --
637 -- ----------------------------------------------------------------------------
638 -- |---------------------------------< ins >----------------------------------|
639 -- ----------------------------------------------------------------------------
640 Procedure ins
641 (p_effective_date in date
642 ,p_rate_matrix_node_id in number
643 ,p_criteria_rate_defn_id in number
644 ,p_rate_value in number
645 ,p_min_rate_value in number default null
646 ,p_max_rate_value in number default null
647 ,p_mid_rate_value in number default null
648 ,p_business_group_id in number default null
649 ,p_legislation_code in varchar2 default null
650 ,p_rate_matrix_rate_id out nocopy number
651 ,p_object_version_number out nocopy number
652 ,p_effective_start_date out nocopy date
653 ,p_effective_end_date out nocopy date
654 ) is
655 --
656 l_rec pqh_rmr_shd.g_rec_type;
657 l_proc varchar2(72) := g_package||'ins';
658 --
659 Begin
660 hr_utility.set_location('Entering:'||l_proc, 5);
661 --
662 -- Call conversion function to turn arguments into the
663 -- p_rec structure.
664 --
665 l_rec :=
666 pqh_rmr_shd.convert_args
667 (null
668 ,null
669 ,null
670 ,p_rate_matrix_node_id
671 ,p_criteria_rate_defn_id
672 ,p_min_rate_value
673 ,p_max_rate_value
674 ,p_mid_rate_value
675 ,p_rate_value
676 ,p_business_group_id
677 ,p_legislation_code
678 ,null
679 );
680 --
681 -- Having converted the arguments into the pqh_rmr_rec
682 -- plsql record structure we call the corresponding record
683 -- business process.
684 --
685 pqh_rmr_ins.ins
686 (p_effective_date
687 ,l_rec
688 );
689 --
690 -- Set the OUT arguments.
691 --
692 p_rate_matrix_rate_id := l_rec.rate_matrix_rate_id;
693 p_effective_start_date := l_rec.effective_start_date;
694 p_effective_end_date := l_rec.effective_end_date;
695 p_object_version_number := l_rec.object_version_number;
696 --
697 --
698 hr_utility.set_location(' Leaving:'||l_proc, 10);
699 End ins;
700 --
701 end pqh_rmr_ins;