DBA Data[Home] [Help]

PACKAGE BODY: APPS.AME_ACT_INS

Source


1 Package Body ame_act_ins as
2 /* $Header: amactrhi.pkb 120.4 2005/11/22 03:12 santosin noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  ame_act_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_id_i  number   default null;
14 g_action_type_id_i  number   default null;
15 --
16 -- ----------------------------------------------------------------------------
17 -- |------------------------< set_base_key_value >----------------------------|
18 -- ----------------------------------------------------------------------------
19 procedure set_base_key_value
20   (p_action_id  in  number
21   ,p_action_type_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_act_ins.g_action_id_i := p_action_id;
29   ame_act_ins.g_action_type_id_i := p_action_type_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_act_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_actions t
94      where t.action_id = p_rec.action_id
95  and    t.action_type_id = p_rec.action_type_id
96        and t.start_date = ame_act_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_actions t
102      where t.action_id = p_rec.action_id
103  and    t.action_type_id = p_rec.action_type_id
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_actions.created_by%TYPE;
109   l_creation_date       ame_actions.creation_date%TYPE;
110   l_last_update_date    ame_actions.last_update_date%TYPE;
111   l_last_updated_by     ame_actions.last_updated_by%TYPE;
112   l_last_update_login   ame_actions.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_act_shd.get_object_version_number
136       (p_action_id =>  p_rec.action_id
137  ,p_action_type_id =>  p_rec.action_type_id
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_actions
192   --
193   insert into ame_actions
194       (action_id
195       ,action_type_id
196       ,parameter
197       ,start_date
198       ,end_date
199       ,description
200       ,security_group_id
201       ,parameter_two
202       ,object_version_number
203       ,created_by
204       ,creation_date
205       ,last_update_date
206       ,last_updated_by
207       ,last_update_login
208       )
209   Values
210     (p_rec.action_id
211     ,p_rec.action_type_id
212     ,p_rec.parameter
213     ,p_rec.start_date
214     ,p_rec.end_date
215     ,p_rec.description
216     ,p_rec.security_group_id
217     ,p_rec.parameter_two
218     ,p_rec.object_version_number
219     ,l_created_by
220     ,l_creation_date
221     ,l_last_update_date
222     ,l_last_updated_by
223     ,l_last_update_login
224     );
225   --
226   --
227   hr_utility.set_location(' Leaving:'||l_proc, 15);
228 --
229 Exception
230   When hr_api.check_integrity_violated Then
231     -- A check constraint has been violated
232     --
233     ame_act_shd.constraint_error
234       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
235   When hr_api.unique_integrity_violated Then
236     -- Unique integrity has been violated
237     --
238     ame_act_shd.constraint_error
239       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
240   When Others Then
241     --
242     Raise;
243 End dt_insert_dml;
244 --
245 -- ----------------------------------------------------------------------------
246 -- |------------------------------< insert_dml >------------------------------|
247 -- ----------------------------------------------------------------------------
248 Procedure insert_dml
249   (p_rec                   in out nocopy ame_act_shd.g_rec_type
250   ,p_effective_date        in date
251   ,p_datetrack_mode        in varchar2
252   ,p_validation_start_date in date
253   ,p_validation_end_date   in date
254   ) is
255 --
256   l_proc        varchar2(72) := g_package||'insert_dml';
257 --
258 Begin
259   hr_utility.set_location('Entering:'||l_proc, 5);
260   --
261   ame_act_ins.dt_insert_dml
262     (p_rec                   => p_rec
263     ,p_effective_date        => p_effective_date
264     ,p_datetrack_mode        => p_datetrack_mode
265     ,p_validation_start_date => p_validation_start_date
266     ,p_validation_end_date   => p_validation_end_date
267     );
268   --
269   hr_utility.set_location(' Leaving:'||l_proc, 10);
270 End insert_dml;
271 --
272 -- ----------------------------------------------------------------------------
273 -- |------------------------------< pre_insert >------------------------------|
274 -- ----------------------------------------------------------------------------
275 -- {Start Of Comments}
276 --
277 -- Description:
278 --   This private procedure contains any processing which is required before
279 --   the insert dml. Presently, if the entity has a corresponding primary
280 --   key which is maintained by an associating sequence, the primary key for
281 --   the entity will be populated with the next sequence value in
282 --   preparation for the insert dml.
283 --   Also, if comments are defined for this entity, the comments insert
284 --   logic will also be called, generating a comment_id if required.
285 --
286 -- Prerequisites:
287 --   This is an internal procedure which is called from the ins procedure.
288 --
289 -- In Parameters:
290 --   A Pl/Sql record structure.
291 --
292 -- Post Success:
293 --   Processing continues.
294 --
295 -- Post Failure:
296 --   If an error has occurred, an error message and exception will be raised
297 --   but not handled.
298 --
299 -- Developer Implementation Notes:
300 --   Any pre-processing required before the insert dml is issued should be
301 --   coded within this procedure. As stated above, a good example is the
302 --   generation of a primary key number via a corresponding sequence.
303 --   It is important to note that any 3rd party maintenance should be reviewed
304 --   before placing in this procedure.
305 --
306 -- Access Status:
307 --   Internal Row Handler Use Only.
308 --
309 -- {End Of Comments}
310 -- ----------------------------------------------------------------------------
311 Procedure pre_insert
312   (p_rec                   in out nocopy ame_act_shd.g_rec_type
313   ,p_effective_date        in date
314   ,p_datetrack_mode        in varchar2
315   ,p_validation_start_date in date
316   ,p_validation_end_date   in date
317   ) is
318 --
319   Cursor C_Sel1 is select ame_actions_s.nextval from sys.dual;
320 --
321  Cursor C_Sel2 is
322     Select null
323       from ame_actions
324      where action_id =
325              ame_act_ins.g_action_id_i
326        and action_type_id =
327              ame_act_ins.g_action_type_id_i;
328 --
329   l_proc        varchar2(72) := g_package||'pre_insert';
330   l_exists      varchar2(1);
331 --
332 Begin
333   hr_utility.set_location('Entering:'||l_proc, 5);
334   --
335     If(ame_act_ins.g_action_id_i is not null) then
336     /*
337     If (ame_act_ins.g_action_id_i is not null or
338       ame_act_ins.g_action_type_id_i is not null) Then
339     */
340 		--
341     -- Verify registered primary key values not already in use
342     --
343     Open C_Sel2;
344     Fetch C_Sel2 into l_exists;
345     If C_Sel2%found Then
346        Close C_Sel2;
347        --
348        -- The primary key values are already in use.
349        --
350        fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
351        fnd_message.set_token('TABLE_NAME','ame_actions');
352        fnd_message.raise_error;
353     End If;
354     Close C_Sel2;
355     --
356     -- Use registered key values and clear globals
357     --
358     p_rec.action_id :=
359       ame_act_ins.g_action_id_i;
360     ame_act_ins.g_action_id_i := null;
361     p_rec.action_type_id :=
362       ame_act_ins.g_action_type_id_i;
363     ame_act_ins.g_action_type_id_i := null;
364   Else
365     --
366     -- No registerd key values, so select the next sequence number
367     --
368     --
369     -- Select the next sequence number
370     --
371     Open C_Sel1;
372     Fetch C_Sel1 Into p_rec.action_id;
373     Close C_Sel1;
374   End If;
375   --
376   --
377   hr_utility.set_location(' Leaving:'||l_proc, 10);
378 End pre_insert;
379 --
380 -- ----------------------------------------------------------------------------
381 -- |----------------------------< post_insert >-------------------------------|
382 -- ----------------------------------------------------------------------------
383 -- {Start Of Comments}
384 --
385 -- Description:
386 --   This private procedure contains any processing which is required after
387 --   the insert dml.
388 --
389 -- Prerequisites:
390 --   This is an internal procedure which is called from the ins procedure.
391 --
392 -- In Parameters:
393 --   A Pl/Sql record structure.
394 --
395 -- Post Success:
396 --   Processing continues.
397 --
398 -- Post Failure:
399 --   If an error has occurred, an error message and exception will be raised
400 --   but not handled.
401 --
402 -- Developer Implementation Notes:
403 --   Any post-processing required after the insert dml is issued should be
404 --   coded within this procedure. It is important to note that any 3rd party
405 --   maintenance should be reviewed before placing in this procedure.
406 --
407 -- Access Status:
408 --   Internal Row Handler Use Only.
409 --
410 -- {End Of Comments}
411 -- ----------------------------------------------------------------------------
412 Procedure post_insert
413   (p_rec                   in ame_act_shd.g_rec_type
414   ,p_effective_date        in date
415   ,p_datetrack_mode        in varchar2
416   ,p_validation_start_date in date
417   ,p_validation_end_date   in date
418   ) is
419 --
420   l_proc        varchar2(72) := g_package||'post_insert';
421 --
422 Begin
423   hr_utility.set_location('Entering:'||l_proc, 5);
424   begin
425     --
426     ame_act_rki.after_insert
427       (p_effective_date
428       => p_effective_date
429       ,p_validation_start_date
430       => p_validation_start_date
431       ,p_validation_end_date
432       => p_validation_end_date
433       ,p_action_id
434       => p_rec.action_id
435       ,p_action_type_id
436       => p_rec.action_type_id
437       ,p_parameter
438       => p_rec.parameter
439       ,p_start_date
440       => p_rec.start_date
441       ,p_end_date
442       => p_rec.end_date
443       ,p_description
444       => p_rec.description
445       ,p_security_group_id
446       => p_rec.security_group_id
447       ,p_parameter_two
448       => p_rec.parameter_two
449       ,p_object_version_number
450       => p_rec.object_version_number
451       );
452     --
453   exception
454     --
455     when hr_api.cannot_find_prog_unit then
456       --
457       hr_api.cannot_find_prog_unit_error
458         (p_module_name => 'AME_ACTIONS'
459         ,p_hook_type   => 'AI');
460       --
461   end;
462   --
463   hr_utility.set_location(' Leaving:'||l_proc, 10);
464 End post_insert;
465 --
466 -- ----------------------------------------------------------------------------
467 -- |-------------------------------< ins_lck >--------------------------------|
468 -- ----------------------------------------------------------------------------
469 -- {Start Of Comments}
470 --
471 -- Description:
472 --   The ins_lck process has one main function to perform. When inserting
473 --   a datetracked row, we must validate the DT mode.
474 --
475 -- Prerequisites:
476 --   This procedure can only be called for the datetrack mode of INSERT.
477 --
478 -- In Parameters:
479 --
480 -- Post Success:
481 --   On successful completion of the ins_lck process the parental
482 --   datetracked rows will be locked providing the p_enforce_foreign_locking
483 --   argument value is TRUE.
484 --   If the p_enforce_foreign_locking argument value is FALSE then the
485 --   parential rows are not locked.
486 --
487 -- Post Failure:
488 --   The Lck process can fail for:
489 --   1) When attempting to lock the row the row could already be locked by
490 --      another user. This will raise the HR_Api.Object_Locked exception.
491 --   2) When attempting to the lock the parent which doesn't exist.
492 --      For the entity to be locked the parent must exist!
493 --
494 -- Developer Implementation Notes:
495 --   None.
496 --
497 -- Access Status:
498 --   Internal Row Handler Use Only.
499 --
500 -- {End Of Comments}
501 -- ----------------------------------------------------------------------------
502 Procedure ins_lck
503   (p_effective_date        in date
504   ,p_datetrack_mode        in varchar2
505   ,p_rec                   in ame_act_shd.g_rec_type
506   ,p_validation_start_date out nocopy date
507   ,p_validation_end_date   out nocopy date
508   ) is
509 --
510   cursor c_sel1 is
511     select action_type_id
512       from ame_action_types
513         where action_type_id = p_rec.action_type_id and
514           p_effective_date between
515             start_date and nvl(end_date - ame_util.oneSecond, sysdate)
516           for update nowait;
517   l_proc                  varchar2(72) := g_package||'ins_lck';
518   l_validation_start_date date;
519   l_validation_end_date   date;
520   l_action_type_id        number;
521 --
522 Begin
523   hr_utility.set_location('Entering:'||l_proc, 5);
524   --
525   -- Lock parent
526   open c_sel1;
527     fetch c_sel1 into l_action_type_id;
528   close c_sel1;
529   -- Validate the datetrack mode mode getting the validation start
530   -- and end dates for the specified datetrack operation.
531   --
532   --
533   -- Set the validation start and end date OUT arguments
534   --
535 --  p_validation_start_date := l_validation_start_date;
536 --  p_validation_end_date   := l_validation_end_date;
537 -- MURTHY_CHANGES
538   p_validation_start_date := sysdate;
539   p_validation_end_date   := ame_utility_pkg.endOfTime;
540   --
541   hr_utility.set_location(' Leaving:'||l_proc, 10);
542   --
543 End ins_lck;
544 --
545 -- ----------------------------------------------------------------------------
546 -- |---------------------------------< ins >----------------------------------|
547 -- ----------------------------------------------------------------------------
548 Procedure ins
549   (p_effective_date in     date
550   ,p_rec            in out nocopy ame_act_shd.g_rec_type
551   ) is
552 --
553   l_proc                        varchar2(72) := g_package||'ins';
554   l_datetrack_mode              varchar2(30) := hr_api.g_insert;
555   l_validation_start_date       date;
556   l_validation_end_date         date;
557 --
558 Begin
559   hr_utility.set_location('Entering:'||l_proc, 5);
560   --
561   -- Call the lock operation
562   --
563   ame_act_ins.ins_lck
564     (p_effective_date        => p_effective_date
565     ,p_datetrack_mode        => l_datetrack_mode
566     ,p_rec                   => p_rec
567     ,p_validation_start_date => l_validation_start_date
568     ,p_validation_end_date   => l_validation_end_date
569     );
570   --
571   -- Call the supporting insert validate operations
572   --
573   ame_act_bus.insert_validate
574     (p_rec                   => p_rec
575     ,p_effective_date        => p_effective_date
576     ,p_datetrack_mode        => l_datetrack_mode
577     ,p_validation_start_date => l_validation_start_date
578     ,p_validation_end_date   => l_validation_end_date
579     );
580   --
581   -- Call to raise any errors on multi-message list
582   hr_multi_message.end_validation_set;
583   --
584   -- Call the supporting pre-insert operation
585   --
586   ame_act_ins.pre_insert
587     (p_rec                   => p_rec
588     ,p_effective_date        => p_effective_date
589     ,p_datetrack_mode        => l_datetrack_mode
590     ,p_validation_start_date => l_validation_start_date
591     ,p_validation_end_date   => l_validation_end_date
592     );
593   --
594   -- Insert the row
595   --
596   ame_act_ins.insert_dml
597     (p_rec                   => p_rec
598     ,p_effective_date        => p_effective_date
599     ,p_datetrack_mode        => l_datetrack_mode
600     ,p_validation_start_date => l_validation_start_date
601     ,p_validation_end_date   => l_validation_end_date
602     );
603   --
604   -- Call the supporting post-insert operation
605   --
606   ame_act_ins.post_insert
607     (p_rec                   => p_rec
608     ,p_effective_date        => p_effective_date
609     ,p_datetrack_mode        => l_datetrack_mode
610     ,p_validation_start_date => l_validation_start_date
611     ,p_validation_end_date   => l_validation_end_date
612     );
613   --
614   -- Call to raise any errors on multi-message list
615   hr_multi_message.end_validation_set;
616   --
617   hr_utility.set_location('Leaving:'||l_proc,10);
618 end ins;
619 --
620 -- ----------------------------------------------------------------------------
621 -- |---------------------------------< ins >----------------------------------|
622 -- ----------------------------------------------------------------------------
623 Procedure ins
624   (p_effective_date                 in     date
625   ,p_description                    in     varchar2
626   ,p_parameter                      in     varchar2 default null
627   ,p_security_group_id              in     number   default null
628   ,p_parameter_two                  in     varchar2 default null
629   ,p_action_type_id                 in     number
630 	,p_action_id                         out nocopy number
631   ,p_object_version_number             out nocopy number
632   ,p_start_date                        out nocopy date
633   ,p_end_date                          out nocopy date
634   ) is
635 --
636   l_rec         ame_act_shd.g_rec_type;
637   l_proc        varchar2(72) := g_package||'ins';
638 --
639 Begin
640   hr_utility.set_location('Entering:'||l_proc, 5);
641   --
642   -- Call conversion function to turn arguments into the
643   -- p_rec structure.
644   --
645   l_rec :=
646   ame_act_shd.convert_args
647     (null
648     ,p_action_type_id
649     ,p_parameter
650     ,null
651     ,null
652     ,p_description
653     ,p_security_group_id
654     ,p_parameter_two
655     ,null
656     );
657   --
658   -- Having converted the arguments into the ame_act_rec
659   -- plsql record structure we call the corresponding record
660   -- business process.
661   --
662   ame_act_ins.ins
663     (p_effective_date
664     ,l_rec
665     );
666   --
667   -- Set the OUT arguments.
668   --
669   -- p_action_type_id := l_rec.action_type_id;
670   p_action_id := l_rec.action_id;
671   p_start_date             := l_rec.start_date;
672   p_end_date               := l_rec.end_date;
673   p_object_version_number            := l_rec.object_version_number;
674   --
675   --
676   hr_utility.set_location(' Leaving:'||l_proc, 10);
677 End ins;
678 --
679 end ame_act_ins;