DBA Data[Home] [Help]

PACKAGE BODY: APPS.AME_CNU_INS

Source


1 Package Body ame_cnu_ins as
2 /* $Header: amcnurhi.pkb 120.4 2005/11/22 03:15 santosin noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  ame_cnu_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_rule_id_i  number   default null;
14 g_condition_id_i  number   default null;
15 --
16 -- ----------------------------------------------------------------------------
17 -- |------------------------< set_base_key_value >----------------------------|
18 -- ----------------------------------------------------------------------------
19 procedure set_base_key_value
20   (p_rule_id  in  number
21   ,p_condition_id  in  number) is
22 --
23   l_proc       varchar2(72) := g_package||'set_base_key_value';
24 --
25 Begin
26   hr_utility.set_location('Entering:'||l_proc, 10);
27   --
28   ame_cnu_ins.g_rule_id_i := p_rule_id;
29   ame_cnu_ins.g_condition_id_i := p_condition_id;
30   --
31   hr_utility.set_location(' Leaving:'||l_proc, 20);
32 End set_base_key_value;
33 --
34 --
35 -- ----------------------------------------------------------------------------
36 -- |----------------------------< dt_insert_dml >-----------------------------|
37 -- ----------------------------------------------------------------------------
38 -- {Start Of Comments}
39 --
40 -- Description:
41 --   This procedure controls the actual dml insert logic for datetrack. The
42 --   functions of this procedure are as follows:
43 --   1) Get the object_version_number.
44 --   2) To set the effective start and end dates to the corresponding
45 --      validation start and end dates. Also, the object version number
46 --      record attribute is set.
47 --   3) To set and unset the g_api_dml status as required (as we are about to
48 --      perform dml).
49 --   4) To insert the row into the schema with the derived effective start
50 --      and end dates and the object version number.
51 --   5) To trap any constraint violations that may have occurred.
52 --   6) To raise any other errors.
53 --
54 -- Prerequisites:
55 --   This is an internal private procedure which must be called from the
56 --   insert_dml and pre_update (logic permitting) procedure and must have
57 --   all mandatory arguments set.
58 --
59 -- In Parameters:
60 --   A Pl/Sql record structure.
61 --
62 -- Post Success:
63 --   The specified row will be inserted into the schema.
64 --
65 -- Post Failure:
66 --   On the insert dml failure it is important to note that we always reset the
67 --   g_api_dml status to false.
68 --   If a check or unique integrity constraint violation is raised the
69 --   constraint_error procedure will be called.
70 --   If any other error is reported, the error will be raised after the
71 --   g_api_dml status is reset.
72 --
73 -- Developer Implementation Notes:
74 --   This is an internal datetrack maintenance procedure which should
75 --   not be modified in anyway.
76 --
77 -- Access Status:
78 --   Internal Row Handler Use Only.
79 --
80 -- {End Of Comments}
81 -- ----------------------------------------------------------------------------
82 Procedure dt_insert_dml
83   (p_rec                     in out nocopy ame_cnu_shd.g_rec_type
84   ,p_effective_date          in date
85   ,p_datetrack_mode          in varchar2
86   ,p_validation_start_date   in date
87   ,p_validation_end_date     in date
88   ) is
89 -- Cursor to select 'old' created AOL who column values
90 --
91   Cursor C_Sel1 Is
92     select t.creation_date
93     from   ame_condition_usages t
94     where t.condition_id = p_rec.condition_id
95  and    t.rule_id = p_rec.rule_id
96     and    t.start_date =
97              ame_cnu_shd.g_old_rec.start_date
98     and    t.end_date   = p_validation_start_date;
99 --
100    Cursor C_Sel2 Is
101     select created_by
102       from ame_condition_usages t
103      where t.condition_id = p_rec.condition_id
104  and    t.rule_id = p_rec.rule_id
105        and ame_utility_pkg.is_seed_user(created_by) = ame_util.seededDataCreatedById
106        and rownum < 2;
107 --
108   l_proc                varchar2(72) := g_package||'dt_insert_dml';
109   l_created_by          ame_condition_usages.created_by%TYPE;
110   l_creation_date       ame_condition_usages.creation_date%TYPE;
111   l_last_update_date    ame_condition_usages.last_update_date%TYPE;
112   l_last_updated_by     ame_condition_usages.last_updated_by%TYPE;
113   l_last_update_login   ame_condition_usages.last_update_login%TYPE;
114   l_current_user_id     integer;
115   l_temp_count          integer;
116 --
117 Begin
118   hr_utility.set_location('Entering:'||l_proc, 5);
119   --
120   -- Set the effective start and end dates to the corresponding
121   -- validation start and end dates
122   --
123   --  p_rec.start_date  := p_validation_start_date;
124   --  p_rec.end_date    := p_validation_end_date;
125   l_current_user_id := fnd_global.user_id;
126   --
127   -- If the datetrack_mode is not INSERT then we must populate the WHO
128   -- columns with the 'old' creation values and 'new' updated values.
129   --
130   If (p_datetrack_mode <> hr_api.g_insert) then
131     hr_utility.set_location(l_proc, 10);
132     --
133       -- Get the object version number for the insert
134   --
135   p_rec.object_version_number :=
136    ame_cnu_shd.get_object_version_number
137       (p_condition_id =>  p_rec.condition_id
138       ,p_rule_id =>  p_rec.rule_id
139       );
140   --
141     -- Select the 'old' created values
142     --
143     Open C_Sel1;
144     Fetch C_Sel1 Into l_creation_date;
145     If C_Sel1%notfound Then
146       --
147       -- The previous 'old' created row has not been found. We need
148       -- to error as an internal datetrack problem exists.
149       --
150       Close C_Sel1;
151       fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
152       fnd_message.set_token('PROCEDURE', l_proc);
153       fnd_message.set_token('STEP','10');
154       fnd_message.raise_error;
155     End If;
156     Close C_Sel1;
157     --
158     --
159     Open C_Sel2;
160     Fetch C_Sel2 Into l_temp_count;
161     if C_Sel2%found then
162       l_created_by := l_temp_count;
163     else
164       l_created_by := l_current_user_id;
165     end if;
166     Close C_Sel2;
167     --
168     -- Set the AOL updated WHO values
169     --
170     if sysdate > p_effective_date then
171       l_last_update_date   := p_effective_date;
172     else
173       l_last_update_date   := sysdate;
174     end if;
175     l_last_updated_by    := l_current_user_id;
176     l_last_update_login  := l_current_user_id;
177   Else
178     p_rec.object_version_number := 1;  -- Initialise the object version
179     --
180     -- If the current user logged in using AME Developer responsibility
181     -- then the created_by value should be ame_util.seededDataCreatedById
182     --
183     if fnd_global.resp_name = 'AME Developer' then
184       l_created_by         := ame_util.seededDataCreatedById;
185     else
186       l_created_by         := l_current_user_id;
187     end if;
188 
189     -- For future rules, creation_date is set to sysdate.But for current rules it will be set to rule_start_date.
190     if sysdate > p_effective_date then
191       l_creation_date      := p_effective_date;
192       l_last_update_date   := p_effective_date;
193     else
194       l_creation_date      := sysdate;
195       l_last_update_date   := sysdate;
196     end if;
197 
198     l_last_updated_by    := l_current_user_id;
199     l_last_update_login  := l_current_user_id;
200   End If;
201   --
202   --
203   --
204   -- Insert the row into: ame_condition_usages
205   --
206   insert into ame_condition_usages
207       (rule_id
208       ,condition_id
209       ,start_date
210       ,end_date
211       ,security_group_id
212       ,object_version_number
213       ,created_by
214       ,creation_date
215       ,last_update_date
216       ,last_updated_by
217       ,last_update_login
218       )
219   Values
220     (p_rec.rule_id
221     ,p_rec.condition_id
222     ,p_rec.start_date
223     ,p_rec.end_date
224     ,p_rec.security_group_id
225     ,p_rec.object_version_number
226     ,l_created_by
227     ,l_creation_date
228     ,l_last_update_date
229     ,l_last_updated_by
230     ,l_last_update_login
231     );
232   --
233   --
234   hr_utility.set_location(' Leaving:'||l_proc, 15);
235 --
236 Exception
237   When hr_api.check_integrity_violated Then
238     -- A check constraint has been violated
239     --
240     ame_cnu_shd.constraint_error
241       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
242   When hr_api.unique_integrity_violated Then
243     -- Unique integrity has been violated
244     --
245     ame_cnu_shd.constraint_error
246       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
247   When Others Then
248     --
249     Raise;
250 End dt_insert_dml;
251 --
252 -- ----------------------------------------------------------------------------
253 -- |------------------------------< insert_dml >------------------------------|
254 -- ----------------------------------------------------------------------------
255 Procedure insert_dml
256   (p_rec                   in out nocopy ame_cnu_shd.g_rec_type
257   ,p_effective_date        in date
258   ,p_datetrack_mode        in varchar2
259   ,p_validation_start_date in date
260   ,p_validation_end_date   in date
261   ) is
262 --
263   l_proc        varchar2(72) := g_package||'insert_dml';
264 --
265 Begin
266   hr_utility.set_location('Entering:'||l_proc, 5);
267   --
268   ame_cnu_ins.dt_insert_dml
269     (p_rec                   => p_rec
270     ,p_effective_date        => p_effective_date
271     ,p_datetrack_mode        => p_datetrack_mode
272     ,p_validation_start_date => p_validation_start_date
273     ,p_validation_end_date   => p_validation_end_date
274     );
275   --
276   hr_utility.set_location(' Leaving:'||l_proc, 10);
277 End insert_dml;
278 --
279 -- ----------------------------------------------------------------------------
280 -- |------------------------------< pre_insert >------------------------------|
281 -- ----------------------------------------------------------------------------
282 -- {Start Of Comments}
283 --
284 -- Description:
285 --   This private procedure contains any processing which is required before
286 --   the insert dml. Presently, if the entity has a corresponding primary
287 --   key which is maintained by an associating sequence, the primary key for
288 --   the entity will be populated with the next sequence value in
289 --   preparation for the insert dml.
290 --   Also, if comments are defined for this entity, the comments insert
291 --   logic will also be called, generating a comment_id if required.
292 --
293 -- Prerequisites:
294 --   This is an internal procedure which is called from the ins procedure.
295 --
296 -- In Parameters:
297 --   A Pl/Sql record structure.
298 --
299 -- Post Success:
300 --   Processing continues.
301 --
302 -- Post Failure:
303 --   If an error has occurred, an error message and exception will be raised
304 --   but not handled.
305 --
306 -- Developer Implementation Notes:
307 --   Any pre-processing required before the insert dml is issued should be
311 --   before placing in this procedure.
308 --   coded within this procedure. As stated above, a good example is the
309 --   generation of a primary key number via a corresponding sequence.
310 --   It is important to note that any 3rd party maintenance should be reviewed
312 --
313 -- Access Status:
314 --   Internal Row Handler Use Only.
315 --
316 -- {End Of Comments}
317 -- ----------------------------------------------------------------------------
318 Procedure pre_insert
319   (p_rec                   in out nocopy ame_cnu_shd.g_rec_type
320   ,p_effective_date        in date
321   ,p_datetrack_mode        in varchar2
322   ,p_validation_start_date in date
323   ,p_validation_end_date   in date
324   ) is
325 --
326 --  Cursor C_Sel1 is select ame_condition_usages_s.nextval from sys.dual;
327 --
328  Cursor C_Sel2 is
329     Select null
330       from ame_condition_usages
331      where rule_id =
332              ame_cnu_ins.g_rule_id_i
333        and condition_id =
334              ame_cnu_ins.g_condition_id_i
335      and    ( p_effective_date
336            between start_date and nvl(end_date - ame_util.oneSecond,p_effective_date)
337           or
338          (p_effective_date < start_date and
339             start_date < nvl(end_date,start_date + ame_util.oneSecond)));
340 --
341   l_proc        varchar2(72) := g_package||'pre_insert';
342   l_exists      varchar2(1);
343 --
344 Begin
345   hr_utility.set_location('Entering:'||l_proc, 5);
346   --
347     If (ame_cnu_ins.g_rule_id_i is not null or
348       ame_cnu_ins.g_condition_id_i is not null) Then
349     --
350     -- Verify registered primary key values not already in use
351     --
352     Open C_Sel2;
353     Fetch C_Sel2 into l_exists;
354     If C_Sel2%found Then
355        Close C_Sel2;
356        --
357        -- The primary key values are already in use.
358        --
359        fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
360        fnd_message.set_token('TABLE_NAME','ame_condition_usages');
361        fnd_message.raise_error;
362     End If;
363     Close C_Sel2;
364     --
365     -- Use registered key values and clear globals
366     --
367     p_rec.rule_id :=
368       ame_cnu_ins.g_rule_id_i;
369     ame_cnu_ins.g_rule_id_i := null;
370     p_rec.condition_id :=
371       ame_cnu_ins.g_condition_id_i;
372     ame_cnu_ins.g_condition_id_i := null;
373   End If;
374   --
375   --
376   hr_utility.set_location(' Leaving:'||l_proc, 10);
377 End pre_insert;
378 --
379 -- ----------------------------------------------------------------------------
380 -- |----------------------------< post_insert >-------------------------------|
381 -- ----------------------------------------------------------------------------
382 -- {Start Of Comments}
383 --
384 -- Description:
385 --   This private procedure contains any processing which is required after
386 --   the insert dml.
387 --
388 -- Prerequisites:
389 --   This is an internal procedure which is called from the ins procedure.
390 --
391 -- In Parameters:
392 --   A Pl/Sql record structure.
393 --
394 -- Post Success:
395 --   Processing continues.
396 --
397 -- Post Failure:
398 --   If an error has occurred, an error message and exception will be raised
399 --   but not handled.
400 --
401 -- Developer Implementation Notes:
402 --   Any post-processing required after the insert dml is issued should be
403 --   coded within this procedure. It is important to note that any 3rd party
404 --   maintenance should be reviewed before placing in this procedure.
405 --
406 -- Access Status:
407 --   Internal Row Handler Use Only.
408 --
409 -- {End Of Comments}
410 -- ----------------------------------------------------------------------------
411 Procedure post_insert
412   (p_rec                   in ame_cnu_shd.g_rec_type
413   ,p_effective_date        in date
414   ,p_datetrack_mode        in varchar2
415   ,p_validation_start_date in date
416   ,p_validation_end_date   in date
417   ) is
418 --
419   l_proc        varchar2(72) := g_package||'post_insert';
420 --
421 Begin
422   hr_utility.set_location('Entering:'||l_proc, 5);
423   begin
424     --
425     ame_cnu_rki.after_insert
426       (p_effective_date
427       => p_effective_date
428       ,p_validation_start_date
429       => p_validation_start_date
430       ,p_validation_end_date
431       => p_validation_end_date
432       ,p_rule_id
433       => p_rec.rule_id
434       ,p_condition_id
435       => p_rec.condition_id
436       ,p_start_date
437       => p_rec.start_date
438       ,p_end_date
439       => p_rec.end_date
440       ,p_security_group_id
441       => p_rec.security_group_id
442       ,p_object_version_number
443       => p_rec.object_version_number
444       );
445     --
446   exception
447     --
448     when hr_api.cannot_find_prog_unit then
449       --
450       hr_api.cannot_find_prog_unit_error
451         (p_module_name => 'AME_CONDITION_USAGES'
452         ,p_hook_type   => 'AI');
453       --
454   end;
455   --
456   hr_utility.set_location(' Leaving:'||l_proc, 10);
457 End post_insert;
458 --
459 -- ----------------------------------------------------------------------------
460 -- |-------------------------------< ins_lck >--------------------------------|
461 -- ----------------------------------------------------------------------------
462 -- {Start Of Comments}
463 --
464 -- Description:
465 --   The ins_lck process has one main function to perform. When inserting
469 --   This procedure can only be called for the datetrack mode of INSERT.
466 --   a datetracked row, we must validate the DT mode.
467 --
468 -- Prerequisites:
470 --
471 -- In Parameters:
472 --
473 -- Post Success:
474 --   On successful completion of the ins_lck process the parental
475 --   datetracked rows will be locked providing the p_enforce_foreign_locking
476 --   argument value is TRUE.
477 --   If the p_enforce_foreign_locking argument value is FALSE then the
478 --   parential rows are not locked.
479 --
480 -- Post Failure:
481 --   The Lck process can fail for:
482 --   1) When attempting to lock the row the row could already be locked by
483 --      another user. This will raise the HR_Api.Object_Locked exception.
484 --   2) When attempting to the lock the parent which doesn't exist.
485 --      For the entity to be locked the parent must exist!
486 --
487 -- Developer Implementation Notes:
488 --   None.
489 --
490 -- Access Status:
491 --   Internal Row Handler Use Only.
492 --
493 -- {End Of Comments}
494 -- ----------------------------------------------------------------------------
495 Procedure ins_lck
496   (p_effective_date        in date
497   ,p_datetrack_mode        in varchar2
498   ,p_rec                   in ame_cnu_shd.g_rec_type
499   ,p_validation_start_date out nocopy date
500   ,p_validation_end_date   out nocopy date
501   ) is
502 --
503   l_dummy                 varchar2(10);
504   l_proc                  varchar2(72) := g_package||'ins_lck';
505   l_validation_start_date date;
506   l_validation_end_date   date;
507 --
508 Begin
509   hr_utility.set_location('Entering:'||l_proc, 5);
510   --
511   -- Validate the datetrack mode mode getting the validation start
512   -- and end dates for the specified datetrack operation.
513   --
514   --
515   -- Set the validation start and end date OUT arguments
516   --
517 --  p_validation_start_date := l_validation_start_date;
518 --  p_validation_end_date   := l_validation_end_date;
519 -- MURTHY_CHANGES
520   p_validation_start_date := sysdate;
521   p_validation_end_date   := ame_utility_pkg.endOfTime;
522   --
523   -- Lock the parent rows in ame_rules and ame_conditions
524   --
525   begin
526     select null
527       into l_dummy
528       from ame_conditions
529       where condition_id = p_rec.condition_id
530        and  p_effective_date between start_date and
531                  nvl(end_date - ame_util.oneSecond, p_effective_date)
532        for update of end_date nowait;
533     select null
534       into l_dummy
535       from ame_rules
536       where rule_id = p_rec.rule_id and
537        ((p_effective_date between start_date and
538             nvl(end_date - ame_util.oneSecond, p_effective_date)) or
539         (p_effective_date < start_date and
540             start_date < nvl(end_date,start_date + ame_util.oneSecond)))
541        for update of end_date nowait;
542   exception
543     when others then
544     --
545     fnd_message.set_name('PER', 'AME_99999_CANT_LOCK_PARENT');
546     fnd_message.set_token('PROCEDURE', l_proc);
547     fnd_message.set_token('STEP','40');
548     fnd_message.raise_error;
549   end;
550   --
551   hr_utility.set_location(' Leaving:'||l_proc, 10);
552 End ins_lck;
553 --
554 -- ----------------------------------------------------------------------------
555 -- |---------------------------------< ins >----------------------------------|
556 -- ----------------------------------------------------------------------------
557 Procedure ins
558   (p_effective_date in     date
559   ,p_rec            in out nocopy ame_cnu_shd.g_rec_type
560   ) is
561 --
562   l_proc                        varchar2(72) := g_package||'ins';
563   l_datetrack_mode              varchar2(30) := hr_api.g_insert;
564   l_validation_start_date       date;
565   l_validation_end_date         date;
566 --
567 Begin
568   hr_utility.set_location('Entering:'||l_proc, 5);
569   --
570   -- Call the lock operation
571   --
572   ame_cnu_ins.ins_lck
573     (p_effective_date        => p_effective_date
574     ,p_datetrack_mode        => l_datetrack_mode
575     ,p_rec                   => p_rec
576     ,p_validation_start_date => l_validation_start_date
577     ,p_validation_end_date   => l_validation_end_date
578     );
579   --
580   -- Call the supporting insert validate operations
581   --
582   ame_cnu_bus.insert_validate
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 to raise any errors on multi-message list
591   hr_multi_message.end_validation_set;
592   --
593   -- Call the supporting pre-insert operation
594   --
595   ame_cnu_ins.pre_insert
596     (p_rec                   => p_rec
597     ,p_effective_date        => p_effective_date
598     ,p_datetrack_mode        => l_datetrack_mode
599     ,p_validation_start_date => l_validation_start_date
600     ,p_validation_end_date   => l_validation_end_date
601     );
602   --
603   -- Insert the row
604   --
605   ame_cnu_ins.insert_dml
606     (p_rec                   => p_rec
607     ,p_effective_date        => p_effective_date
608     ,p_datetrack_mode        => l_datetrack_mode
609     ,p_validation_start_date => l_validation_start_date
610     ,p_validation_end_date   => l_validation_end_date
611     );
612   --
613   -- Call the supporting post-insert operation
614   --
615   ame_cnu_ins.post_insert
616     (p_rec                   => p_rec
617     ,p_effective_date        => p_effective_date
618     ,p_datetrack_mode        => l_datetrack_mode
619     ,p_validation_start_date => l_validation_start_date
620     ,p_validation_end_date   => l_validation_end_date
621     );
622   --
623   -- Call to raise any errors on multi-message list
624   hr_multi_message.end_validation_set;
625   --
626   hr_utility.set_location('Leaving:'||l_proc,10);
627 end ins;
628 --
629 -- ----------------------------------------------------------------------------
630 -- |---------------------------------< ins >----------------------------------|
631 -- ----------------------------------------------------------------------------
632 Procedure ins
633   (p_effective_date                 in     date
634   ,p_rule_id                        in     number
635   ,p_condition_id                   in     number
636   ,p_security_group_id              in     number   default null
637   ,p_start_date                     in out nocopy date
638   ,p_end_date                       in out nocopy date
639   ,p_object_version_number             out nocopy number
640   ) is
641 --
642   l_rec         ame_cnu_shd.g_rec_type;
643   l_proc        varchar2(72) := g_package||'ins';
644 --
645 Begin
646   hr_utility.set_location('Entering:'||l_proc, 5);
647   --
648   -- Call conversion function to turn arguments into the
649   -- p_rec structure.
650   --
651   l_rec :=
652   ame_cnu_shd.convert_args
653     (p_rule_id
654     ,p_condition_id
655     ,p_start_date
656     ,p_end_date
657     ,p_security_group_id
658     ,null
659     );
660   --
661   -- Having converted the arguments into the ame_cnu_rec
662   -- plsql record structure we call the corresponding record
663   -- business process.
664   --
665   ame_cnu_ins.ins
666     (p_effective_date
667     ,l_rec
668     );
669   --
670   -- Set the OUT arguments.
671   --
672   p_start_date             := l_rec.start_date;
673   p_end_date               := l_rec.end_date;
674   p_object_version_number            := l_rec.object_version_number;
675   --
676   --
677   hr_utility.set_location(' Leaving:'||l_proc, 10);
678 End ins;
679 --
680 end ame_cnu_ins;