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