DBA Data[Home] [Help]

PACKAGE BODY: APPS.AME_ACU_UPD

Source


1 Package Body ame_acu_upd as
2 /* $Header: amacurhi.pkb 120.4 2005/11/22 03:13 santosin noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  ame_acu_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_acu_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_acu_shd.get_object_version_number
78         (p_action_id =>  p_rec.action_id
79  ,p_rule_id =>  p_rec.rule_id
80       );
81     --
82     --
83     --
84     -- Update the ame_action_usages Row
85     --
86     update  ame_action_usages
87     set
88      rule_id                              = p_rec.rule_id
89     ,action_id                            = p_rec.action_id
90     ,object_version_number                = p_rec.object_version_number
91     where   action_id  =   p_rec.action_id
92   and rule_id  =   p_rec.rule_id
93     and     start_date = p_validation_start_date
94     and     ((p_validation_end_date is null and end_date is null) or
95               (end_date  = p_validation_end_date));
96     --
97     --
98     --
99     -- Set the effective start and end dates
100     --
101     p_rec.start_date := p_validation_start_date;
102     p_rec.end_date   := p_validation_end_date;
103   End If;
104 --
105 hr_utility.set_location(' Leaving:'||l_proc, 15);
106 Exception
107   When hr_api.check_integrity_violated Then
108     -- A check constraint has been violated
109     --
110     ame_acu_shd.constraint_error
111       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
112   When hr_api.unique_integrity_violated Then
113     -- Unique integrity has been violated
114     --
115     ame_acu_shd.constraint_error
116       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
117   When Others Then
118     --
119     Raise;
120 End dt_update_dml;
121 --
122 -- ----------------------------------------------------------------------------
123 -- |------------------------------< update_dml >------------------------------|
124 -- ----------------------------------------------------------------------------
125 -- {Start Of Comments}
126 --
127 -- Description:
128 --   This procedure calls the dt_update_dml control logic which handles
129 --   the actual datetrack dml.
130 --
131 -- Prerequisites:
132 --   This is an internal private procedure which must be called from the upd
133 --   procedure.
134 --
135 -- In Parameters:
136 --   A Pl/Sql record structre.
137 --
138 -- Post Success:
139 --   Processing contines.
140 --
141 -- Post Failure:
142 --   No specific error handling is required within this procedure.
143 --
144 -- Developer Implementation Notes:
145 --   The update 'set' arguments list should be modified if any of your
146 --   attributes are not updateable.
147 --
148 -- Access Status:
149 --   Internal Row Handler Use Only.
150 --
151 -- {End Of Comments}
152 -- ----------------------------------------------------------------------------
153 Procedure update_dml
154   (p_rec                      in out nocopy ame_acu_shd.g_rec_type
155   ,p_effective_date           in date
156   ,p_datetrack_mode           in varchar2
157   ,p_validation_start_date    in date
158   ,p_validation_end_date      in date
159   ) is
160 --
161   l_proc        varchar2(72) := g_package||'update_dml';
162 --
163 Begin
164   hr_utility.set_location('Entering:'||l_proc, 5);
165   --
166   ame_acu_upd.dt_update_dml
167     (p_rec                   => p_rec
168     ,p_effective_date        => p_effective_date
169     ,p_datetrack_mode        => p_datetrack_mode
170     ,p_validation_start_date => p_validation_start_date
171     ,p_validation_end_date   => p_validation_end_date
172     );
173   --
174   hr_utility.set_location(' Leaving:'||l_proc, 10);
175 End update_dml;
176 --
177 -- ----------------------------------------------------------------------------
178 -- |----------------------------< dt_pre_update >-----------------------------|
179 -- ----------------------------------------------------------------------------
180 -- {Start Of Comments}
181 --
182 -- Description:
183 --   The dt_pre_update procedure controls the execution
184 --   of dml for the datetrack modes of: UPDATE, UPDATE_OVERRIDE
185 --   and UPDATE_CHANGE_INSERT only. The execution required is as
186 --   follows:
187 --
188 --   1) Providing the datetrack update mode is not 'CORRECTION'
189 --      then set the effective end date of the current row (this
190 --      will be the validation_start_date - 1).
191 --   2) If the datetrack mode is 'UPDATE_OVERRIDE' then call the
192 --      corresponding delete_dml process to delete any future rows
193 --      where the effective_start_date is greater than or equal to
194 --      the validation_start_date.
195 --   3) Call the insert_dml process to insert the new updated row
196 --      details.
197 --
198 -- Prerequisites:
199 --   This is an internal procedure which is called from the
200 --   pre_update procedure.
201 --
202 -- In Parameters:
203 --
204 -- Post Success:
205 --   Processing continues.
206 --
207 -- Post Failure:
208 --   If an error has occurred, an error message and exception will be raised
209 --   but not handled.
210 --
211 -- Developer Implementation Notes:
212 --   This is an internal procedure which is required by Datetrack. Don't
213 --   remove or modify.
214 --
215 -- Access Status:
216 --   Internal Row Handler Use Only.
217 --
218 -- {End Of Comments}
219 -- ----------------------------------------------------------------------------
220 Procedure dt_pre_update
221   (p_rec                     in out  nocopy   ame_acu_shd.g_rec_type
222   ,p_effective_date          in date
223   ,p_datetrack_mode          in varchar2
224   ,p_validation_start_date   in date
225   ,p_validation_end_date     in date
226   ) is
227 --
228   l_proc                 varchar2(72) := g_package||'dt_pre_update';
229   l_dummy_version_number number;
230 --
231 Begin
232   hr_utility.set_location('Entering:'||l_proc, 5);
233   If (p_datetrack_mode <> hr_api.g_correction) then
234     --
235     -- Update the current effective end date
236     --
237     ame_acu_shd.upd_end_date
238       (p_effective_date         => p_effective_date
239       ,p_action_id =>  p_rec.action_id
240  ,p_rule_id =>  p_rec.rule_id
241       ,p_new_end_date           => p_validation_start_date
242       ,p_object_version_number  => l_dummy_version_number
243       );
244     --
245     If (p_datetrack_mode = hr_api.g_update_override) then
246       --
247       -- As the datetrack mode is 'UPDATE_OVERRIDE' then we must
248       -- delete any future rows
249       --
250       ame_acu_del.delete_dml
251         (p_rec                   => p_rec
252         ,p_effective_date        => p_effective_date
253         ,p_datetrack_mode        => p_datetrack_mode
254         ,p_validation_start_date => p_validation_start_date
255         ,p_validation_end_date   => p_validation_end_date
256         );
257     End If;
258     --
259     -- We must now insert the updated row
260     --
261     ame_acu_ins.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   End If;
269   hr_utility.set_location(' Leaving:'||l_proc, 20);
270 End dt_pre_update;
271 --
272 -- ----------------------------------------------------------------------------
273 -- |------------------------------< pre_update >------------------------------|
274 -- ----------------------------------------------------------------------------
275 -- {Start Of Comments}
276 --
277 -- Description:
278 --   This private procedure contains any processing which is required before
279 --   the update dml.
280 --
281 -- Prerequisites:
282 --   This is an internal procedure which is called from the upd procedure.
283 --
284 -- In Parameters:
285 --   A Pl/Sql record structure.
286 --
287 -- Post Success:
288 --   Processing continues.
289 --
290 -- Post Failure:
291 --   If an error has occurred, an error message and exception will be raised
292 --   but not handled.
293 -- Developer Implementation Notes:
294 --   Any pre-processing required before the update dml is issued should be
295 --   coded within this procedure. It is important to note that any 3rd party
296 --   maintenance should be reviewed before placing in this procedure. The call
297 --   to the dt_update_dml procedure should NOT be removed.
298 --
299 -- Access Status:
300 --   Internal Row Handler Use Only.
301 --
302 -- {End Of Comments}
303 -- ----------------------------------------------------------------------------
304 Procedure pre_update
305   (p_rec                   in out nocopy ame_acu_shd.g_rec_type
306   ,p_effective_date        in date
307   ,p_datetrack_mode        in varchar2
308   ,p_validation_start_date in date
309   ,p_validation_end_date   in date
310   ) is
311 --
312   l_proc        varchar2(72) := g_package||'pre_update';
313 --
314 Begin
315   hr_utility.set_location('Entering:'||l_proc, 5);
316   --
317   --
318   --
319   dt_pre_update
320     (p_rec                   => p_rec
321     ,p_effective_date        => p_effective_date
322     ,p_datetrack_mode        => p_datetrack_mode
323     ,p_validation_start_date => p_validation_start_date
324     ,p_validation_end_date   => p_validation_end_date
325     );
326   --
327   hr_utility.set_location(' Leaving:'||l_proc, 10);
328 End pre_update;
329 --
330 -- ----------------------------------------------------------------------------
331 -- |----------------------------< post_update >-------------------------------|
332 -- ----------------------------------------------------------------------------
333 -- {Start Of Comments}
334 --
335 -- Description:
336 --   This private procedure contains any processing which is required after
337 --   the update dml.
338 --
339 -- Prerequisites:
340 --   This is an internal procedure which is called from the upd procedure.
341 --
342 -- In Parameters:
343 --   A Pl/Sql record structure.
344 --
345 -- Post Success:
346 --   Processing continues.
347 --
348 -- Post Failure:
349 --   If an error has occurred, an error message and exception will be raised
350 --   but not handled.
351 --
352 -- Developer Implementation Notes:
353 --   Any post-processing required after the update dml is issued should be
354 --   coded within this procedure. It is important to note that any 3rd party
355 --   maintenance should be reviewed before placing in this procedure.
356 --
357 -- Access Status:
358 --   Internal Row Handler Use Only.
359 --
360 -- {End Of Comments}
361 -- ----------------------------------------------------------------------------
362 Procedure post_update
363   (p_rec                   in ame_acu_shd.g_rec_type
364   ,p_effective_date        in date
365   ,p_datetrack_mode        in varchar2
366   ,p_validation_start_date in date
367   ,p_validation_end_date   in date
368   ) is
369 --
370   l_proc        varchar2(72) := g_package||'post_update';
371 --
372 Begin
373   hr_utility.set_location('Entering:'||l_proc, 5);
374   begin
375     --
376     ame_acu_rku.after_update
377       (p_effective_date
378       => p_effective_date
379       ,p_datetrack_mode
380       => p_datetrack_mode
381       ,p_validation_start_date
382       => p_validation_start_date
383       ,p_validation_end_date
384       => p_validation_end_date
385       ,p_rule_id
386       => p_rec.rule_id
387       ,p_action_id
388       => p_rec.action_id
389       ,p_start_date
390       => p_rec.start_date
391       ,p_end_date
392       => p_rec.end_date
393       ,p_object_version_number
394       => p_rec.object_version_number
395       ,p_start_date_o
396       => ame_acu_shd.g_old_rec.start_date
397       ,p_end_date_o
398       => ame_acu_shd.g_old_rec.end_date
399       ,p_object_version_number_o
400       => ame_acu_shd.g_old_rec.object_version_number
401       );
402     --
403   exception
404     --
405     when hr_api.cannot_find_prog_unit then
406       --
407       hr_api.cannot_find_prog_unit_error
408         (p_module_name => 'AME_ACTION_USAGES'
409         ,p_hook_type   => 'AU');
410       --
411   end;
412   --
413   hr_utility.set_location(' Leaving:'||l_proc, 10);
414 End post_update;
415 --
416 -- ----------------------------------------------------------------------------
417 -- |-----------------------------< convert_defs >-----------------------------|
418 -- ----------------------------------------------------------------------------
419 -- {Start Of Comments}
420 --
421 -- Description:
422 --   The Convert_Defs procedure has one very important function:
423 --   It must return the record structure for the row with all system defaulted
424 --   values converted into its corresponding parameter value for update. When
425 --   we attempt to update a row through the Upd process , certain
426 --   parameters can be defaulted which enables flexibility in the calling of
427 --   the upd process (e.g. only attributes which need to be updated need to be
428 --   specified). For the upd process to determine which attributes
429 --   have NOT been specified we need to check if the parameter has a reserved
430 --   system default value. Therefore, for all parameters which have a
431 --   corresponding reserved system default mechanism specified we need to
432 --   check if a system default is being used. If a system default is being
433 --   used then we convert the defaulted value into its corresponding attribute
434 --   value held in the g_old_rec data structure.
435 --
436 -- Prerequisites:
437 --   This private function can only be called from the upd process.
438 --
439 -- In Parameters:
440 --   A Pl/Sql record structure.
441 --
442 -- Post Success:
443 --   The record structure will be returned with all system defaulted parameter
444 --   values converted into its current row attribute value.
445 --
446 -- Post Failure:
447 --   No direct error handling is required within this function. Any possible
448 --   errors within this procedure will be a PL/SQL value error due to
449 --   conversion of datatypes or data lengths.
450 --
451 -- Developer Implementation Notes:
452 --   None.
453 --
454 -- Access Status:
455 --   Internal Row Handler Use Only.
456 --
457 -- {End Of Comments}
458 -- ----------------------------------------------------------------------------
459 Procedure convert_defs
460   (p_rec in out nocopy ame_acu_shd.g_rec_type
461   ) is
462 --
463 Begin
464   --
465   If (p_rec.start_date = hr_api.g_date) then
466      p_rec.start_date := ame_acu_shd.g_old_rec.start_date;
467   End If;
468   If (p_rec.end_date = hr_api.g_date) then
469     p_rec.end_date := ame_acu_shd.g_old_rec.end_date;
470   End If;
471   --
472 End convert_defs;
473 --
474 -- ----------------------------------------------------------------------------
475 -- |---------------------------------< upd >----------------------------------|
476 -- ----------------------------------------------------------------------------
477 Procedure upd
478   (p_effective_date in     date
479   ,p_datetrack_mode in     varchar2
480   ,p_rec            in out nocopy ame_acu_shd.g_rec_type
481   ) is
482 --
483   l_proc                        varchar2(72) := g_package||'upd';
484   l_validation_start_date       date;
485   l_validation_end_date         date;
486 --
487 Begin
488   hr_utility.set_location('Entering:'||l_proc, 5);
489   --
490   -- Ensure that the DateTrack update mode is valid
491   --
492   dt_api.validate_dt_upd_mode(p_datetrack_mode => p_datetrack_mode);
493   --
494   -- set the start and end dates if not set
495   --
496   if p_rec.start_date is null then
497     p_rec.start_date := hr_api.g_date;
498   end if;
499   if p_rec.end_date is null then
500     p_rec.end_date := hr_api.g_date;
501   end if;
502   --
503   -- We must lock the row which we need to update.
504   --
505   ame_acu_shd.lck
506     (p_effective_date                   => p_effective_date
507     ,p_datetrack_mode                   => p_datetrack_mode
508     ,p_action_id =>  p_rec.action_id
509  ,p_rule_id =>  p_rec.rule_id
510     ,p_object_version_number            => p_rec.object_version_number
511     ,p_validation_start_date            => l_validation_start_date
512     ,p_validation_end_date              => l_validation_end_date
513     );
514   --
515   -- 1. During an update system defaults are used to determine if
516   --    arguments have been defaulted or not. We must therefore
517   --    derive the full record structure values to be updated.
518   --
519   -- 2. Call the supporting update validate operations.
520   --
521   ame_acu_upd.convert_defs(p_rec);
522   --
523   -- Make sure that the Rule start_date and end_date are correct
524   --
525   -- p_validation_start_date is sysdate, so if the start_date is greater
526   -- than sysdate then we should use the p_start_date else use sysdate.
527   --
528   if p_rec.start_date < l_validation_start_date   then
529     p_rec.start_date := l_validation_start_date ;
530   end if;
531   --
532   -- p_validation_end_date is ame_util.endOfTime, so if the end_date is less
533   -- than ame_util.endOfTime then we should use the p_end_date  else use
534   -- p_validation_end_date.
535   --
536   /*if p_rec.end_date <> l_validation_end_date   then
537     p_rec.end_date := l_validation_end_date ;
538   end if;*/
539   --
540   ame_acu_bus.update_validate
541     (p_rec                              => p_rec
542     ,p_effective_date                   => p_effective_date
543     ,p_datetrack_mode                   => p_datetrack_mode
544     ,p_validation_start_date            => l_validation_start_date
545     ,p_validation_end_date              => l_validation_end_date
546     );
547   --
548   -- Call to raise any errors on multi-message list
549   hr_multi_message.end_validation_set;
550   --
551   -- Call the supporting pre-update operation
552   --
553   pre_update
554     (p_rec                              => p_rec
555     ,p_effective_date                   => p_effective_date
556     ,p_datetrack_mode                   => p_datetrack_mode
557     ,p_validation_start_date            => l_validation_start_date
558     ,p_validation_end_date              => l_validation_end_date
559     );
560   --
561   -- Update the row.
562   --
563   update_dml
564     (p_rec                              => p_rec
565     ,p_effective_date                   => p_effective_date
566     ,p_datetrack_mode                   => p_datetrack_mode
567     ,p_validation_start_date            => l_validation_start_date
568     ,p_validation_end_date                  => l_validation_end_date
569     );
570   --
571   -- Call the supporting post-update operation
572   --
573   post_update
574     (p_rec                              => p_rec
575     ,p_effective_date                   => p_effective_date
576     ,p_datetrack_mode                   => p_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 End upd;
584 --
585 -- ----------------------------------------------------------------------------
586 -- |------------------------------< upd >-------------------------------------|
587 -- ----------------------------------------------------------------------------
588 Procedure upd
589   (p_effective_date               in     date
590   ,p_datetrack_mode               in     varchar2
591   ,p_rule_id                      in     number
592   ,p_action_id                    in     number
593   ,p_object_version_number        in out nocopy number
594   ,p_start_date                   in out nocopy date
595   ,p_end_date                     in out nocopy date
596   ) is
597 --
598   l_rec         ame_acu_shd.g_rec_type;
599   l_proc        varchar2(72) := g_package||'upd';
600 --
601 Begin
602   hr_utility.set_location('Entering:'||l_proc, 5);
603   --
604   -- Call conversion function to turn arguments into the
605   -- l_rec structure.
606   --
607   l_rec :=
608   ame_acu_shd.convert_args
609     (p_rule_id
610     ,p_action_id
611     ,p_start_date
612     ,p_end_date
613     ,p_object_version_number
614     );
615   --
616   -- Having converted the arguments into the
617   -- plsql record structure we call the corresponding record
618   -- business process.
619   --
620   ame_acu_upd.upd
621     (p_effective_date
622     ,p_datetrack_mode
623     ,l_rec
624     );
625   --
626   -- Set the out parameters
627   --
628   p_object_version_number            := l_rec.object_version_number;
629   p_start_date             := l_rec.start_date;
630   p_end_date               := l_rec.end_date;
631   --
632   --
633   hr_utility.set_location(' Leaving:'||l_proc, 10);
634 End upd;
635 --
636 end ame_acu_upd;