DBA Data[Home] [Help]

PACKAGE BODY: APPS.AME_ATR_INS

Source


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