DBA Data[Home] [Help]

PACKAGE BODY: APPS.AME_AXU_INS

Source


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