DBA Data[Home] [Help]

PACKAGE BODY: APPS.AME_ATR_UPD

Source


1 Package Body ame_atr_upd 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_upd.';  -- Global package name
9 --
10 -- ----------------------------------------------------------------------------
11 -- |----------------------------< dt_update_dml >-----------------------------|
12 -- ----------------------------------------------------------------------------
13 -- {Start Of Comments}
14 --
15 -- Description:
16 --   This procedure controls the execution of dml from the datetrack mode
17 --   of CORRECTION only. It is important to note that the object version
18 --   number is only increment by 1 because the datetrack correction is
19 --   soley for one datetracked row.
20 --   This procedure controls the actual dml update logic. The functions of
21 --   this procedure are as follows:
22 --   1) Get the next object_version_number.
23 --   2) To set and unset the g_api_dml status as required (as we are about to
24 --      perform dml).
25 --   3) To update the specified row in the schema using the primary key in
26 --      the predicates.
27 --   4) To trap any constraint violations that may have occurred.
28 --   5) To raise any other errors.
29 --
30 -- Prerequisites:
31 --   This is an internal private procedure which must be called from the
32 --   update_dml procedure.
33 --
34 -- In Parameters:
35 --   A Pl/Sql record structure.
36 --
37 -- Post Success:
38 --   The specified row will be updated in the schema.
39 --
40 -- Post Failure:
41 --   On the update dml failure it is important to note that we always reset the
42 --   g_api_dml status to false.
43 --   If a check or unique integrity constraint violation is raised the
44 --   constraint_error procedure will be called.
45 --   If any other error is reported, the error will be raised after the
46 --   g_api_dml status is reset.
47 --
48 -- Developer Implementation Notes:
49 --   The update 'set' arguments list should be modified if any of your
50 --   attributes are not updateable.
51 --
52 -- Access Status:
53 --   Internal Row Handler Use Only.
54 --
55 -- {End Of Comments}
56 -- ----------------------------------------------------------------------------
57 Procedure dt_update_dml
58   (p_rec                   in out nocopy ame_atr_shd.g_rec_type
59   ,p_effective_date        in date
60   ,p_datetrack_mode        in varchar2
61   ,p_validation_start_date in date
62   ,p_validation_end_date   in date
63   ) is
64 --
65   l_proc        varchar2(72) := g_package||'dt_update_dml';
66 --
67 Begin
68   hr_utility.set_location('Entering:'||l_proc, 5);
69   --
70   If (p_datetrack_mode = hr_api.g_correction) then
71     hr_utility.set_location(l_proc, 10);
72     --
73     -- Because we are updating a row we must get the next object
74     -- version number.
75     --
76     p_rec.object_version_number :=
77      ame_atr_shd.get_object_version_number
78         (p_attribute_id =>  p_rec.attribute_id
79       );
80     --
81     --
82     --
83     -- Update the ame_attributes Row
84     --
85     update  ame_attributes
86     set
87      attribute_id                         = p_rec.attribute_id
88     ,name                                 = p_rec.name
89     ,attribute_type                       = p_rec.attribute_type
90     ,line_item                            = p_rec.line_item
91     ,description                          = p_rec.description
92     ,security_group_id                    = p_rec.security_group_id
93     ,approver_type_id                     = p_rec.approver_type_id
94     ,item_class_id                        = p_rec.item_class_id
95     ,object_version_number                = p_rec.object_version_number
96     where   attribute_id  =   p_rec.attribute_id
97     and     start_date = p_validation_start_date
98     and     ((p_validation_end_date is null and end_date is null) or
99               (end_date  = p_validation_end_date));
100     --
101     --
102     --
103     -- Set the effective start and end dates
104     --
105     p_rec.start_date := p_validation_start_date;
106     p_rec.end_date   := p_validation_end_date;
107   End If;
108 --
109 hr_utility.set_location(' Leaving:'||l_proc, 15);
110 Exception
111   When hr_api.check_integrity_violated Then
112     -- A check constraint has been violated
113     --
114     ame_atr_shd.constraint_error
115       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
116   When hr_api.unique_integrity_violated Then
117     -- Unique integrity has been violated
118     --
119     ame_atr_shd.constraint_error
120       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
121   When Others Then
122     --
123     Raise;
124 End dt_update_dml;
125 --
126 -- ----------------------------------------------------------------------------
127 -- |------------------------------< update_dml >------------------------------|
128 -- ----------------------------------------------------------------------------
129 -- {Start Of Comments}
130 --
131 -- Description:
132 --   This procedure calls the dt_update_dml control logic which handles
133 --   the actual datetrack dml.
134 --
135 -- Prerequisites:
136 --   This is an internal private procedure which must be called from the upd
137 --   procedure.
138 --
139 -- In Parameters:
140 --   A Pl/Sql record structre.
141 --
142 -- Post Success:
143 --   Processing contines.
144 --
145 -- Post Failure:
146 --   No specific error handling is required within this procedure.
147 --
148 -- Developer Implementation Notes:
149 --   The update 'set' arguments list should be modified if any of your
150 --   attributes are not updateable.
151 --
152 -- Access Status:
153 --   Internal Row Handler Use Only.
154 --
155 -- {End Of Comments}
156 -- ----------------------------------------------------------------------------
157 Procedure update_dml
158   (p_rec                      in out nocopy ame_atr_shd.g_rec_type
159   ,p_effective_date           in date
160   ,p_datetrack_mode           in varchar2
161   ,p_validation_start_date    in date
162   ,p_validation_end_date      in date
163   ) is
164 --
165   l_proc        varchar2(72) := g_package||'update_dml';
166 --
167 Begin
168   hr_utility.set_location('Entering:'||l_proc, 5);
169   --
170   ame_atr_upd.dt_update_dml
171     (p_rec                   => p_rec
172     ,p_effective_date        => p_effective_date
173     ,p_datetrack_mode        => p_datetrack_mode
174     ,p_validation_start_date => p_validation_start_date
175     ,p_validation_end_date   => p_validation_end_date
176     );
177   --
178   hr_utility.set_location(' Leaving:'||l_proc, 10);
179 End update_dml;
180 --
181 -- ----------------------------------------------------------------------------
182 -- |----------------------------< dt_pre_update >-----------------------------|
183 -- ----------------------------------------------------------------------------
184 -- {Start Of Comments}
185 --
186 -- Description:
187 --   The dt_pre_update procedure controls the execution
188 --   of dml for the datetrack modes of: UPDATE, UPDATE_OVERRIDE
189 --   and UPDATE_CHANGE_INSERT only. The execution required is as
190 --   follows:
191 --
192 --   1) Providing the datetrack update mode is not 'CORRECTION'
193 --      then set the effective end date of the current row (this
194 --      will be the validation_start_date - 1).
195 --   2) If the datetrack mode is 'UPDATE_OVERRIDE' then call the
196 --      corresponding delete_dml process to delete any future rows
197 --      where the effective_start_date is greater than or equal to
198 --      the validation_start_date.
199 --   3) Call the insert_dml process to insert the new updated row
200 --      details.
201 --
202 -- Prerequisites:
203 --   This is an internal procedure which is called from the
204 --   pre_update procedure.
205 --
206 -- In Parameters:
207 --
208 -- Post Success:
209 --   Processing continues.
210 --
211 -- Post Failure:
212 --   If an error has occurred, an error message and exception will be raised
213 --   but not handled.
214 --
215 -- Developer Implementation Notes:
216 --   This is an internal procedure which is required by Datetrack. Don't
217 --   remove or modify.
218 --
219 -- Access Status:
220 --   Internal Row Handler Use Only.
221 --
222 -- {End Of Comments}
223 -- ----------------------------------------------------------------------------
224 Procedure dt_pre_update
225   (p_rec                     in out  nocopy   ame_atr_shd.g_rec_type
226   ,p_effective_date          in date
227   ,p_datetrack_mode          in varchar2
228   ,p_validation_start_date   in date
229   ,p_validation_end_date     in date
230   ) is
231 --
232   l_proc                 varchar2(72) := g_package||'dt_pre_update';
233   l_dummy_version_number number;
234 --
235 Begin
236   hr_utility.set_location('Entering:'||l_proc, 5);
237   If (p_datetrack_mode <> hr_api.g_correction) then
238     --
239     -- Update the current effective end date
240     --
241     ame_atr_shd.upd_end_date
242       (p_effective_date         => p_effective_date
243       ,p_attribute_id =>  p_rec.attribute_id
244       ,p_new_end_date           => p_validation_start_date
245       ,p_object_version_number  => l_dummy_version_number
246       );
247     --
248     If (p_datetrack_mode = hr_api.g_update_override) then
249       --
250       -- As the datetrack mode is 'UPDATE_OVERRIDE' then we must
251       -- delete any future rows
252       --
253       ame_atr_del.delete_dml
254         (p_rec                   => p_rec
255         ,p_effective_date        => p_effective_date
256         ,p_datetrack_mode        => p_datetrack_mode
257         ,p_validation_start_date => p_validation_start_date
258         ,p_validation_end_date   => p_validation_end_date
259         );
260     End If;
261     --
262     -- We must now insert the updated row
263     --
264     ame_atr_ins.insert_dml
265       (p_rec                    => p_rec
266       ,p_effective_date         => p_effective_date
267       ,p_datetrack_mode         => p_datetrack_mode
268       ,p_validation_start_date  => p_validation_start_date
269       ,p_validation_end_date    => p_validation_end_date
270       );
271   End If;
272   hr_utility.set_location(' Leaving:'||l_proc, 20);
273 End dt_pre_update;
274 --
275 -- ----------------------------------------------------------------------------
276 -- |------------------------------< pre_update >------------------------------|
277 -- ----------------------------------------------------------------------------
278 -- {Start Of Comments}
279 --
280 -- Description:
281 --   This private procedure contains any processing which is required before
282 --   the update dml.
283 --
284 -- Prerequisites:
285 --   This is an internal procedure which is called from the upd procedure.
286 --
287 -- In Parameters:
288 --   A Pl/Sql record structure.
289 --
290 -- Post Success:
291 --   Processing continues.
292 --
293 -- Post Failure:
294 --   If an error has occurred, an error message and exception will be raised
295 --   but not handled.
296 -- Developer Implementation Notes:
297 --   Any pre-processing required before the update dml is issued should be
298 --   coded within this procedure. It is important to note that any 3rd party
299 --   maintenance should be reviewed before placing in this procedure. The call
300 --   to the dt_update_dml procedure should NOT be removed.
301 --
302 -- Access Status:
303 --   Internal Row Handler Use Only.
304 --
305 -- {End Of Comments}
306 -- ----------------------------------------------------------------------------
307 Procedure pre_update
308   (p_rec                   in out nocopy ame_atr_shd.g_rec_type
309   ,p_effective_date        in date
310   ,p_datetrack_mode        in varchar2
311   ,p_validation_start_date in date
312   ,p_validation_end_date   in date
313   ) is
314 --
315   l_proc        varchar2(72) := g_package||'pre_update';
316 --
317 Begin
318   hr_utility.set_location('Entering:'||l_proc, 5);
319   --
320   --
321   --
322   dt_pre_update
323     (p_rec                   => p_rec
324     ,p_effective_date        => p_effective_date
325     ,p_datetrack_mode        => p_datetrack_mode
326     ,p_validation_start_date => p_validation_start_date
327     ,p_validation_end_date   => p_validation_end_date
328     );
329   --
330   hr_utility.set_location(' Leaving:'||l_proc, 10);
331 End pre_update;
332 --
333 -- ----------------------------------------------------------------------------
334 -- |----------------------------< post_update >-------------------------------|
335 -- ----------------------------------------------------------------------------
336 -- {Start Of Comments}
337 --
338 -- Description:
339 --   This private procedure contains any processing which is required after
340 --   the update dml.
341 --
342 -- Prerequisites:
343 --   This is an internal procedure which is called from the upd procedure.
344 --
345 -- In Parameters:
346 --   A Pl/Sql record structure.
347 --
348 -- Post Success:
349 --   Processing continues.
350 --
351 -- Post Failure:
352 --   If an error has occurred, an error message and exception will be raised
353 --   but not handled.
354 --
355 -- Developer Implementation Notes:
356 --   Any post-processing required after the update dml is issued should be
357 --   coded within this procedure. It is important to note that any 3rd party
358 --   maintenance should be reviewed before placing in this procedure.
359 --
360 -- Access Status:
361 --   Internal Row Handler Use Only.
362 --
363 -- {End Of Comments}
364 -- ----------------------------------------------------------------------------
365 Procedure post_update
366   (p_rec                   in ame_atr_shd.g_rec_type
367   ,p_effective_date        in date
368   ,p_datetrack_mode        in varchar2
369   ,p_validation_start_date in date
370   ,p_validation_end_date   in date
371   ) is
372 --
373   l_proc        varchar2(72) := g_package||'post_update';
374 --
375 Begin
376   hr_utility.set_location('Entering:'||l_proc, 5);
377   begin
378     --
379     ame_atr_rku.after_update
380       (p_effective_date
381       => p_effective_date
382       ,p_datetrack_mode
383       => p_datetrack_mode
384       ,p_validation_start_date
385       => p_validation_start_date
386       ,p_validation_end_date
387       => p_validation_end_date
388       ,p_attribute_id
389       => p_rec.attribute_id
390       ,p_name
391       => p_rec.name
392       ,p_attribute_type
393       => p_rec.attribute_type
394       ,p_line_item
395       => p_rec.line_item
396       ,p_start_date
397       => p_rec.start_date
398       ,p_end_date
399       => p_rec.end_date
400       ,p_description
401       => p_rec.description
402       ,p_security_group_id
403       => p_rec.security_group_id
404       ,p_approver_type_id
405       => p_rec.approver_type_id
406       ,p_item_class_id
407       => p_rec.item_class_id
408       ,p_object_version_number
409       => p_rec.object_version_number
410       ,p_name_o
411       => ame_atr_shd.g_old_rec.name
412       ,p_attribute_type_o
413       => ame_atr_shd.g_old_rec.attribute_type
414       ,p_line_item_o
415       => ame_atr_shd.g_old_rec.line_item
416       ,p_start_date_o
417       => ame_atr_shd.g_old_rec.start_date
418       ,p_end_date_o
419       => ame_atr_shd.g_old_rec.end_date
420       ,p_description_o
421       => ame_atr_shd.g_old_rec.description
422       ,p_security_group_id_o
423       => ame_atr_shd.g_old_rec.security_group_id
424       ,p_approver_type_id_o
425       => ame_atr_shd.g_old_rec.approver_type_id
426       ,p_item_class_id_o
427       => ame_atr_shd.g_old_rec.item_class_id
428       ,p_object_version_number_o
429       => ame_atr_shd.g_old_rec.object_version_number
430       );
431     --
432   exception
433     --
434     when hr_api.cannot_find_prog_unit then
435       --
436       hr_api.cannot_find_prog_unit_error
437         (p_module_name => 'AME_ATTRIBUTES'
438         ,p_hook_type   => 'AU');
439       --
440   end;
441   --
442   hr_utility.set_location(' Leaving:'||l_proc, 10);
443 End post_update;
444 --
445 -- ----------------------------------------------------------------------------
446 -- |-----------------------------< convert_defs >-----------------------------|
447 -- ----------------------------------------------------------------------------
448 -- {Start Of Comments}
449 --
450 -- Description:
451 --   The Convert_Defs procedure has one very important function:
452 --   It must return the record structure for the row with all system defaulted
453 --   values converted into its corresponding parameter value for update. When
454 --   we attempt to update a row through the Upd process , certain
455 --   parameters can be defaulted which enables flexibility in the calling of
456 --   the upd process (e.g. only attributes which need to be updated need to be
457 --   specified). For the upd process to determine which attributes
458 --   have NOT been specified we need to check if the parameter has a reserved
459 --   system default value. Therefore, for all parameters which have a
460 --   corresponding reserved system default mechanism specified we need to
461 --   check if a system default is being used. If a system default is being
462 --   used then we convert the defaulted value into its corresponding attribute
463 --   value held in the g_old_rec data structure.
464 --
465 -- Prerequisites:
466 --   This private function can only be called from the upd process.
467 --
468 -- In Parameters:
469 --   A Pl/Sql record structure.
470 --
471 -- Post Success:
472 --   The record structure will be returned with all system defaulted parameter
473 --   values converted into its current row attribute value.
474 --
475 -- Post Failure:
476 --   No direct error handling is required within this function. Any possible
477 --   errors within this procedure will be a PL/SQL value error due to
478 --   conversion of datatypes or data lengths.
479 --
480 -- Developer Implementation Notes:
481 --   None.
482 --
483 -- Access Status:
484 --   Internal Row Handler Use Only.
485 --
486 -- {End Of Comments}
487 -- ----------------------------------------------------------------------------
488 Procedure convert_defs
489   (p_rec in out nocopy ame_atr_shd.g_rec_type
490   ) is
491 --
492 Begin
493   --
494   -- We must now examine each argument value in the
495   -- p_rec plsql record structure
496   -- to see if a system default is being used. If a system default
497   -- is being used then we must set to the 'current' argument value.
498   --
499   If (p_rec.name = hr_api.g_varchar2) then
500     p_rec.name :=
501     ame_atr_shd.g_old_rec.name;
502   End If;
503   If (p_rec.attribute_type = hr_api.g_varchar2) then
504     p_rec.attribute_type :=
505     ame_atr_shd.g_old_rec.attribute_type;
506   End If;
507   If (p_rec.line_item = hr_api.g_varchar2) then
508     p_rec.line_item :=
509     ame_atr_shd.g_old_rec.line_item;
510   End If;
511   If (p_rec.description = hr_api.g_varchar2) then
512     p_rec.description :=
513     ame_atr_shd.g_old_rec.description;
514   End If;
515   If (p_rec.security_group_id = hr_api.g_number) then
516     p_rec.security_group_id :=
517     ame_atr_shd.g_old_rec.security_group_id;
518   End If;
519   If (p_rec.approver_type_id = hr_api.g_number) then
520     p_rec.approver_type_id :=
521     ame_atr_shd.g_old_rec.approver_type_id;
522   End If;
523   If (p_rec.item_class_id = hr_api.g_number) then
524     p_rec.item_class_id :=
525     ame_atr_shd.g_old_rec.item_class_id;
526   End If;
527   --
528 End convert_defs;
529 --
530 -- ----------------------------------------------------------------------------
531 -- |---------------------------------< upd >----------------------------------|
532 -- ----------------------------------------------------------------------------
533 Procedure upd
534   (p_effective_date in     date
535   ,p_datetrack_mode in     varchar2
536   ,p_rec            in out nocopy ame_atr_shd.g_rec_type
537   ) is
538 --
539   l_proc                        varchar2(72) := g_package||'upd';
540   l_validation_start_date       date;
541   l_validation_end_date         date;
542 --
543 Begin
544   hr_utility.set_location('Entering:'||l_proc, 5);
545   --
546   -- Ensure that the DateTrack update mode is valid
547   --
548   dt_api.validate_dt_upd_mode(p_datetrack_mode => p_datetrack_mode);
549   --
550   -- We must lock the row which we need to update.
551   --
552   ame_atr_shd.lck
553     (p_effective_date                   => p_effective_date
554     ,p_datetrack_mode                   => p_datetrack_mode
555     ,p_attribute_id =>  p_rec.attribute_id
556     ,p_object_version_number            => p_rec.object_version_number
557     ,p_validation_start_date            => l_validation_start_date
558     ,p_validation_end_date              => l_validation_end_date
559     );
560   --
561   -- 1. During an update system defaults are used to determine if
562   --    arguments have been defaulted or not. We must therefore
563   --    derive the full record structure values to be updated.
564   --
565   -- 2. Call the supporting update validate operations.
566   --
567   ame_atr_upd.convert_defs(p_rec);
568   --
569   ame_atr_bus.update_validate
570     (p_rec                              => p_rec
571     ,p_effective_date                   => p_effective_date
572     ,p_datetrack_mode                   => p_datetrack_mode
573     ,p_validation_start_date            => l_validation_start_date
574     ,p_validation_end_date              => l_validation_end_date
575     );
576   --
577   -- Call to raise any errors on multi-message list
578   hr_multi_message.end_validation_set;
579   --
580   -- Call the supporting pre-update operation
581   --
582   pre_update
583     (p_rec                              => p_rec
584     ,p_effective_date                   => p_effective_date
585     ,p_datetrack_mode                   => p_datetrack_mode
586     ,p_validation_start_date            => l_validation_start_date
587     ,p_validation_end_date              => l_validation_end_date
588     );
589   --
590   -- Update the row.
591   --
592   update_dml
593     (p_rec                              => p_rec
594     ,p_effective_date                   => p_effective_date
595     ,p_datetrack_mode                   => p_datetrack_mode
596     ,p_validation_start_date            => l_validation_start_date
597     ,p_validation_end_date                  => l_validation_end_date
598     );
599   --
600   -- Call the supporting post-update operation
601   --
602   post_update
603     (p_rec                              => p_rec
604     ,p_effective_date                   => p_effective_date
605     ,p_datetrack_mode                   => p_datetrack_mode
606     ,p_validation_start_date            => l_validation_start_date
607     ,p_validation_end_date              => l_validation_end_date
608     );
609   --
610   -- Call to raise any errors on multi-message list
611   hr_multi_message.end_validation_set;
612 End upd;
613 --
614 -- ----------------------------------------------------------------------------
615 -- |------------------------------< upd >-------------------------------------|
616 -- ----------------------------------------------------------------------------
617 Procedure upd
618   (p_effective_date               in     date
619   ,p_datetrack_mode               in     varchar2
620   ,p_attribute_id                 in     number
621   ,p_object_version_number        in out nocopy number
622   ,p_name                         in     varchar2  default hr_api.g_varchar2
623   ,p_attribute_type               in     varchar2  default hr_api.g_varchar2
624   ,p_description                  in     varchar2  default hr_api.g_varchar2
625   ,p_item_class_id                in     number    default hr_api.g_number
626   ,p_line_item                    in     varchar2  default hr_api.g_varchar2
627   ,p_security_group_id            in     number    default hr_api.g_number
628   ,p_approver_type_id             in     number    default hr_api.g_number
629   ,p_start_date                      out nocopy date
630   ,p_end_date                        out nocopy date
631   ) is
632 --
633   l_rec         ame_atr_shd.g_rec_type;
634   l_proc        varchar2(72) := g_package||'upd';
635 --
636 Begin
637   hr_utility.set_location('Entering:'||l_proc, 5);
638   --
639   -- Call conversion function to turn arguments into the
640   -- l_rec structure.
641   --
642   l_rec :=
643   ame_atr_shd.convert_args
644     (p_attribute_id
645     ,p_name
646     ,p_attribute_type
647     ,p_line_item
648     ,null
649     ,null
650     ,p_description
651     ,p_security_group_id
652     ,p_approver_type_id
653     ,p_item_class_id
654     ,p_object_version_number
655     );
656   --
657   -- Having converted the arguments into the
658   -- plsql record structure we call the corresponding record
659   -- business process.
660   --
661   ame_atr_upd.upd
662     (p_effective_date
663     ,p_datetrack_mode
664     ,l_rec
665     );
666   --
667   -- Set the out parameters
668   --
669   p_object_version_number            := l_rec.object_version_number;
670   p_start_date             := l_rec.start_date;
671   p_end_date               := l_rec.end_date;
672   --
673   --
674   hr_utility.set_location(' Leaving:'||l_proc, 10);
675 End upd;
676 --
677 end ame_atr_upd;