DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_BER_INS

Source


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