DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_RFI_INS

Source


1 Package Body pay_rfi_ins as
2 /* $Header: pyrfirhi.pkb 120.0 2005/05/29 08:19 appldev noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  pay_rfi_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_item_id_i  number   default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19   (p_report_format_item_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_rfi_ins.g_report_format_item_id_i := p_report_format_item_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_rfi_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_items_f t
92     where  t.report_format_item_id       = p_rec.report_format_item_id
93     and    t.effective_start_date =
94              pay_rfi_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_items_f.created_by%TYPE;
99   l_creation_date       pay_report_format_items_f.creation_date%TYPE;
100   l_last_update_date    pay_report_format_items_f.last_update_date%TYPE;
101   l_last_updated_by     pay_report_format_items_f.last_updated_by%TYPE;
102   l_last_update_login   pay_report_format_items_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_items_f'
124       ,p_base_key_column => 'report_format_item_id'
125       ,p_base_key_value  => p_rec.report_format_item_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_rfi_shd.g_api_dml := true;  -- Set the api dml status
155   --
156   -- Insert the row into: pay_report_format_items_f
157   --
158   insert into pay_report_format_items_f
159       (report_type
160       ,report_qualifier
161       ,report_category
162       ,user_entity_id
163       ,effective_start_date
164       ,effective_end_date
165       ,archive_type
166       ,updatable_flag
167       ,display_sequence
168       ,object_version_number
169       ,report_format_item_id
170       ,created_by
171       ,creation_date
172       ,last_update_date
173       ,last_updated_by
174       ,last_update_login
175       )
176   Values
177     (p_rec.report_type
178     ,p_rec.report_qualifier
179     ,p_rec.report_category
180     ,p_rec.user_entity_id
181     ,p_rec.effective_start_date
182     ,p_rec.effective_end_date
183     ,p_rec.archive_type
184     ,p_rec.updatable_flag
185     ,p_rec.display_sequence
186     ,p_rec.object_version_number
187     ,p_rec.report_format_item_id
188     ,l_created_by
189     ,l_creation_date
190     ,l_last_update_date
191     ,l_last_updated_by
192     ,l_last_update_login
193     );
194   --
195   pay_rfi_shd.g_api_dml := false;   -- Unset the api dml status
196   hr_utility.set_location(' Leaving:'||l_proc, 15);
197 --
198 Exception
199   When hr_api.check_integrity_violated Then
200     -- A check constraint has been violated
201     pay_rfi_shd.g_api_dml := false;   -- Unset the api dml status
202     pay_rfi_shd.constraint_error
203       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
204   When hr_api.unique_integrity_violated Then
205     -- Unique integrity has been violated
206     pay_rfi_shd.g_api_dml := false;   -- Unset the api dml status
207     pay_rfi_shd.constraint_error
208       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
209   When Others Then
210     pay_rfi_shd.g_api_dml := false;   -- Unset the api dml status
211     Raise;
212 End dt_insert_dml;
213 --
214 -- ----------------------------------------------------------------------------
215 -- |------------------------------< insert_dml >------------------------------|
216 -- ----------------------------------------------------------------------------
217 Procedure insert_dml
218   (p_rec                   in out nocopy pay_rfi_shd.g_rec_type
219   ,p_effective_date        in date
220   ,p_datetrack_mode        in varchar2
221   ,p_validation_start_date in date
222   ,p_validation_end_date   in date
223   ) is
224 --
225   l_proc        varchar2(72) := g_package||'insert_dml';
226 --
227 Begin
228   hr_utility.set_location('Entering:'||l_proc, 5);
229   --
230   pay_rfi_ins.dt_insert_dml
231     (p_rec                   => p_rec
232     ,p_effective_date        => p_effective_date
233     ,p_datetrack_mode        => p_datetrack_mode
234     ,p_validation_start_date => p_validation_start_date
235     ,p_validation_end_date   => p_validation_end_date
236     );
237   --
238   hr_utility.set_location(' Leaving:'||l_proc, 10);
239 End insert_dml;
240 --
241 -- ----------------------------------------------------------------------------
242 -- |------------------------------< pre_insert >------------------------------|
243 -- ----------------------------------------------------------------------------
244 -- {Start Of Comments}
245 --
246 -- Description:
247 --   This private procedure contains any processing which is required before
248 --   the insert dml. Presently, if the entity has a corresponding primary
249 --   key which is maintained by an associating sequence, the primary key for
250 --   the entity will be populated with the next sequence value in
251 --   preparation for the insert dml.
252 --   Also, if comments are defined for this entity, the comments insert
253 --   logic will also be called, generating a comment_id if required.
254 --
255 -- Prerequisites:
256 --   This is an internal procedure which is called from the ins procedure.
257 --
258 -- In Parameters:
259 --   A Pl/Sql record structure.
260 --
261 -- Post Success:
262 --   Processing continues.
263 --
264 -- Post Failure:
265 --   If an error has occurred, an error message and exception will be raised
266 --   but not handled.
267 --
268 -- Developer Implementation Notes:
269 --   Any pre-processing required before the insert dml is issued should be
270 --   coded within this procedure. As stated above, a good example is the
271 --   generation of a primary key number via a corresponding sequence.
272 --   It is important to note that any 3rd party maintenance should be reviewed
273 --   before placing in this procedure.
274 --
275 -- Access Status:
276 --   Internal Row Handler Use Only.
277 --
278 -- {End Of Comments}
279 -- ----------------------------------------------------------------------------
280 Procedure pre_insert
281   (p_rec                   in out nocopy pay_rfi_shd.g_rec_type
282   ,p_effective_date        in date
283   ,p_datetrack_mode        in varchar2
284   ,p_validation_start_date in date
285   ,p_validation_end_date   in date
286   ) is
287 --
288   Cursor C_Sel1 is select pay_report_format_items_s.nextval from sys.dual;
289 --
290  Cursor C_Sel2 is
291     Select null
292       from pay_report_format_items_f
293      where report_format_item_id =
294              pay_rfi_ins.g_report_format_item_id_i;
295 --
296   l_proc        varchar2(72) := g_package||'pre_insert';
297   l_exists      varchar2(1);
298 --
299 Begin
300   hr_utility.set_location('Entering:'||l_proc, 5);
301   --
302     If (pay_rfi_ins.g_report_format_item_id_i is not null) Then
303     --
304     -- Verify registered primary key values not already in use
305     --
306     Open C_Sel2;
307     Fetch C_Sel2 into l_exists;
308     If C_Sel2%found Then
309        Close C_Sel2;
310        --
311        -- The primary key values are already in use.
312        --
313        fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
314        fnd_message.set_token('TABLE_NAME','pay_report_format_items_f');
315        fnd_message.raise_error;
316     End If;
317     Close C_Sel2;
318     --
319     -- Use registered key values and clear globals
320     --
321     p_rec.report_format_item_id :=
322       pay_rfi_ins.g_report_format_item_id_i;
323     pay_rfi_ins.g_report_format_item_id_i := null;
324   Else
325     --
326     -- No registerd key values, so select the next sequence number
327     --
328     --
329     -- Select the next sequence number
330     --
331     Open C_Sel1;
332     Fetch C_Sel1 Into p_rec.report_format_item_id;
333     Close C_Sel1;
334   End If;
335   --
336   pay_rfi_bus.chk_report_format_item_id
337          ( p_report_format_item_id => p_rec.report_format_item_id );
338   --
339   hr_utility.set_location(' Leaving:'||l_proc, 10);
340 End pre_insert;
341 --
342 -- ----------------------------------------------------------------------------
343 -- |----------------------------< post_insert >-------------------------------|
344 -- ----------------------------------------------------------------------------
345 -- {Start Of Comments}
346 --
347 -- Description:
348 --   This private procedure contains any processing which is required after
349 --   the insert dml.
350 --
351 -- Prerequisites:
352 --   This is an internal procedure which is called from the ins procedure.
353 --
354 -- In Parameters:
355 --   A Pl/Sql record structure.
356 --
357 -- Post Success:
358 --   Processing continues.
359 --
360 -- Post Failure:
361 --   If an error has occurred, an error message and exception will be raised
362 --   but not handled.
363 --
364 -- Developer Implementation Notes:
365 --   Any post-processing required after the insert dml is issued should be
366 --   coded within this procedure. It is important to note that any 3rd party
367 --   maintenance should be reviewed before placing in this procedure.
368 --
369 -- Access Status:
370 --   Internal Row Handler Use Only.
371 --
372 -- {End Of Comments}
373 -- ----------------------------------------------------------------------------
374 Procedure post_insert
375   (p_rec                   in pay_rfi_shd.g_rec_type
376   ,p_effective_date        in date
377   ,p_datetrack_mode        in varchar2
378   ,p_validation_start_date in date
379   ,p_validation_end_date   in date
380   ) is
381 --
382   l_proc        varchar2(72) := g_package||'post_insert';
383 --
384 Begin
385   hr_utility.set_location('Entering:'||l_proc, 5);
386   --
387   hr_utility.set_location(' Leaving:'||l_proc, 10);
388 End post_insert;
389 --
390 -- ----------------------------------------------------------------------------
391 -- |-------------------------------< ins_lck >--------------------------------|
392 -- ----------------------------------------------------------------------------
393 -- {Start Of Comments}
394 --
395 -- Description:
396 --   The ins_lck process has one main function to perform. When inserting
397 --   a datetracked row, we must validate the DT mode.
398 --
399 -- Prerequisites:
400 --   This procedure can only be called for the datetrack mode of INSERT.
401 --
402 -- In Parameters:
403 --
404 -- Post Success:
405 --   On successful completion of the ins_lck process the parental
406 --   datetracked rows will be locked providing the p_enforce_foreign_locking
407 --   argument value is TRUE.
408 --   If the p_enforce_foreign_locking argument value is FALSE then the
409 --   parential rows are not locked.
410 --
411 -- Post Failure:
412 --   The Lck process can fail for:
413 --   1) When attempting to lock the row the row could already be locked by
414 --      another user. This will raise the HR_Api.Object_Locked exception.
415 --   2) When attempting to the lock the parent which doesn't exist.
416 --      For the entity to be locked the parent must exist!
417 --
418 -- Developer Implementation Notes:
419 --   None.
420 --
421 -- Access Status:
422 --   Internal Row Handler Use Only.
423 --
424 -- {End Of Comments}
425 -- ----------------------------------------------------------------------------
426 Procedure ins_lck
427   (p_effective_date        in date
428   ,p_datetrack_mode        in varchar2
429   ,p_rec                   in pay_rfi_shd.g_rec_type
430   ,p_validation_start_date out nocopy date
431   ,p_validation_end_date   out nocopy date
432   ) is
433 --
434   l_proc                  varchar2(72) := g_package||'ins_lck';
435   l_validation_start_date date;
436   l_validation_end_date   date;
437 --
438 Begin
439   hr_utility.set_location('Entering:'||l_proc, 5);
440   --
441   -- Validate the datetrack mode mode getting the validation start
442   -- and end dates for the specified datetrack operation.
443   --
444   dt_api.validate_dt_mode
445     (p_effective_date          => p_effective_date
446     ,p_datetrack_mode          => p_datetrack_mode
447     ,p_base_table_name         => 'pay_report_format_items_f'
448     ,p_base_key_column         => 'report_format_item_id'
449     ,p_base_key_value          => p_rec.report_format_item_id
450     ,p_parent_table_name1      => 'pay_report_format_mappings_f'
451     ,p_parent_key_column1      => 'report_format_mapping_id'
452     ,p_parent_key_value1       => p_rec.report_format_mapping_id
453     ,p_enforce_foreign_locking => true
454     ,p_validation_start_date   => l_validation_start_date
455     ,p_validation_end_date     => l_validation_end_date
456     );
457   --
458   -- Set the validation start and end date OUT arguments
459   --
460   p_validation_start_date := l_validation_start_date;
461   p_validation_end_date   := l_validation_end_date;
462   --
463   hr_utility.set_location(' Leaving:'||l_proc, 10);
464   --
465 End ins_lck;
466 --
467 -- ----------------------------------------------------------------------------
468 -- |---------------------------------< ins >----------------------------------|
469 -- ----------------------------------------------------------------------------
470 Procedure ins
471   (p_effective_date in     date
472   ,p_rec            in out nocopy pay_rfi_shd.g_rec_type
473   ) is
474 --
475   l_proc                        varchar2(72) := g_package||'ins';
476   l_datetrack_mode              varchar2(30) := hr_api.g_insert;
477   l_validation_start_date       date;
478   l_validation_end_date         date;
479 --
480 Begin
481   hr_utility.set_location('Entering:'||l_proc, 5);
482   --
483   -- Call the lock operation
484   --
485   pay_rfi_ins.ins_lck
486     (p_effective_date        => p_effective_date
487     ,p_datetrack_mode        => l_datetrack_mode
488     ,p_rec                   => p_rec
489     ,p_validation_start_date => l_validation_start_date
490     ,p_validation_end_date   => l_validation_end_date
491     );
492   --
493   -- Call the supporting insert validate operations
494   --
495   pay_rfi_bus.insert_validate
496     (p_rec                   => p_rec
497     ,p_effective_date        => p_effective_date
498     ,p_datetrack_mode        => l_datetrack_mode
499     ,p_validation_start_date => l_validation_start_date
500     ,p_validation_end_date   => l_validation_end_date
501     );
502   --
503   -- Call to raise any errors on multi-message list
504   hr_multi_message.end_validation_set;
505   --
506   -- Call the supporting pre-insert operation
507   --
508   pay_rfi_ins.pre_insert
509     (p_rec                   => p_rec
510     ,p_effective_date        => p_effective_date
511     ,p_datetrack_mode        => l_datetrack_mode
512     ,p_validation_start_date => l_validation_start_date
513     ,p_validation_end_date   => l_validation_end_date
514     );
515   --
516   -- Insert the row
517   --
518   pay_rfi_ins.insert_dml
519     (p_rec                   => p_rec
520     ,p_effective_date        => p_effective_date
521     ,p_datetrack_mode        => l_datetrack_mode
522     ,p_validation_start_date => l_validation_start_date
523     ,p_validation_end_date   => l_validation_end_date
524     );
525   --
526   -- Call the supporting post-insert operation
527   --
528   pay_rfi_ins.post_insert
529     (p_rec                   => p_rec
530     ,p_effective_date        => p_effective_date
531     ,p_datetrack_mode        => l_datetrack_mode
532     ,p_validation_start_date => l_validation_start_date
533     ,p_validation_end_date   => l_validation_end_date
534     );
535   --
536   -- Call to raise any errors on multi-message list
537   hr_multi_message.end_validation_set;
538   --
539   hr_utility.set_location('Leaving:'||l_proc,10);
540 end ins;
541 --
542 -- ----------------------------------------------------------------------------
543 -- |---------------------------------< ins >----------------------------------|
544 -- ----------------------------------------------------------------------------
545 Procedure ins
546   (p_effective_date                 in     date
547   ,p_report_type                    in     varchar2
548   ,p_report_qualifier               in     varchar2
549   ,p_report_category                in     varchar2
550   ,p_user_entity_id                 in     number
551   ,p_archive_type                   in     varchar2 default null
552   ,p_updatable_flag                 in     varchar2 default null
553   ,p_display_sequence               in     number   default null
554   ,p_report_format_item_id             out nocopy number
555   ,p_object_version_number             out nocopy number
556   ,p_effective_start_date              out nocopy date
557   ,p_effective_end_date                out nocopy date
558   ) is
559 --
560   l_rec         pay_rfi_shd.g_rec_type;
561   l_proc        varchar2(72) := g_package||'ins';
562   l_report_format_mapping_id pay_report_format_mappings_f.report_format_mapping_id%type;
563 --
564 Begin
565   hr_utility.set_location('Entering:'||l_proc, 5);
566   --
567   -- Call conversion function to turn arguments into the
568   -- p_rec structure.
569   --
570 
571   l_report_format_mapping_id := pay_rfm_shd.get_report_format_mapping_id
572                                            ( p_report_type      => p_report_type
573                                             ,p_report_qualifier => p_report_qualifier
574                                             ,p_report_category  => p_report_category );
575 
576   l_rec :=
577   pay_rfi_shd.convert_args
578     (p_report_type
579     ,p_report_qualifier
580     ,p_report_category
581     ,p_user_entity_id
582     ,null
583     ,null
584     ,p_archive_type
585     ,p_updatable_flag
586     ,p_display_sequence
587     ,null
588     ,null
589     ,l_report_format_mapping_id
590     );
591   --
592   -- Having converted the arguments into the pay_rfi_rec
593   -- plsql record structure we call the corresponding record
594   -- business process.
595   --
596   pay_rfi_ins.ins
597     (trunc(p_effective_date)
598     ,l_rec
599     );
600   --
601   -- Set the OUT arguments.
602   --
603   p_report_format_item_id            := l_rec.report_format_item_id;
604   p_effective_start_date             := l_rec.effective_start_date;
605   p_effective_end_date               := l_rec.effective_end_date;
606   p_object_version_number            := l_rec.object_version_number;
607   --
608   --
609   hr_utility.set_location(' Leaving:'||l_proc, 10);
610 End ins;
611 --
612 end pay_rfi_ins;