DBA Data[Home] [Help]

PACKAGE BODY: APPS.AME_APU_UPD

Source


1 Package Body ame_apu_upd as
2 /* $Header: amapurhi.pkb 120.3 2005/11/22 03:13 santosin noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  ame_apu_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_apu_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_apu_shd.get_object_version_number
78         (p_approver_type_id =>  p_rec.approver_type_id
79  ,p_action_type_id =>  p_rec.action_type_id
80       );
81     --
82     --
83     --
84     -- Update the ame_approver_type_usages Row
85     --
86     update  ame_approver_type_usages
87     set
88      approver_type_id                     = p_rec.approver_type_id
89     ,action_type_id                       = p_rec.action_type_id
90     ,object_version_number                = p_rec.object_version_number
91     where   approver_type_id  =   p_rec.approver_type_id
92   and action_type_id  =   p_rec.action_type_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_apu_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_apu_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_apu_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_apu_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_apu_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_apu_shd.upd_end_date
238       (p_effective_date         => p_effective_date
239       ,p_approver_type_id =>  p_rec.approver_type_id
240  ,p_action_type_id =>  p_rec.action_type_id
241       ,p_new_end_date => p_validation_start_date
242       ,p_validation_start_date  => p_validation_start_date
243       ,p_validation_end_date    => p_validation_end_date
244       ,p_object_version_number  => l_dummy_version_number
245       );
246     --
247     If (p_datetrack_mode = hr_api.g_update_override) then
248       --
249       -- As the datetrack mode is 'UPDATE_OVERRIDE' then we must
250       -- delete any future rows
251       --
252       ame_apu_del.delete_dml
253         (p_rec                   => p_rec
254         ,p_effective_date        => p_effective_date
255         ,p_datetrack_mode        => p_datetrack_mode
256         ,p_validation_start_date => p_validation_start_date
257         ,p_validation_end_date   => p_validation_end_date
258         );
259     End If;
260     --
261     -- We must now insert the updated row
262     --
263     ame_apu_ins.insert_dml
264       (p_rec                    => p_rec
265       ,p_effective_date         => p_effective_date
266       ,p_datetrack_mode         => p_datetrack_mode
267       ,p_validation_start_date  => p_validation_start_date
268       ,p_validation_end_date    => p_validation_end_date
269       );
270   End If;
271   hr_utility.set_location(' Leaving:'||l_proc, 20);
272 End dt_pre_update;
273 --
274 -- ----------------------------------------------------------------------------
275 -- |------------------------------< pre_update >------------------------------|
276 -- ----------------------------------------------------------------------------
277 -- {Start Of Comments}
278 --
279 -- Description:
280 --   This private procedure contains any processing which is required before
281 --   the update dml.
282 --
283 -- Prerequisites:
284 --   This is an internal procedure which is called from the upd procedure.
285 --
286 -- In Parameters:
287 --   A Pl/Sql record structure.
288 --
289 -- Post Success:
290 --   Processing continues.
291 --
292 -- Post Failure:
293 --   If an error has occurred, an error message and exception will be raised
294 --   but not handled.
295 -- Developer Implementation Notes:
296 --   Any pre-processing required before the update dml is issued should be
297 --   coded within this procedure. It is important to note that any 3rd party
298 --   maintenance should be reviewed before placing in this procedure. The call
299 --   to the dt_update_dml procedure should NOT be removed.
300 --
301 -- Access Status:
302 --   Internal Row Handler Use Only.
303 --
304 -- {End Of Comments}
305 -- ----------------------------------------------------------------------------
306 Procedure pre_update
307   (p_rec                   in out nocopy ame_apu_shd.g_rec_type
308   ,p_effective_date        in date
309   ,p_datetrack_mode        in varchar2
310   ,p_validation_start_date in date
311   ,p_validation_end_date   in date
312   ) is
313 --
314   l_proc        varchar2(72) := g_package||'pre_update';
315 --
316 Begin
317   hr_utility.set_location('Entering:'||l_proc, 5);
318   --
319   --
320   --
321   dt_pre_update
322     (p_rec                   => p_rec
323     ,p_effective_date        => p_effective_date
324     ,p_datetrack_mode        => p_datetrack_mode
325     ,p_validation_start_date => p_validation_start_date
326     ,p_validation_end_date   => p_validation_end_date
327     );
328   --
329   hr_utility.set_location(' Leaving:'||l_proc, 10);
330 End pre_update;
331 --
332 -- ----------------------------------------------------------------------------
333 -- |----------------------------< post_update >-------------------------------|
334 -- ----------------------------------------------------------------------------
335 -- {Start Of Comments}
336 --
337 -- Description:
338 --   This private procedure contains any processing which is required after
339 --   the update dml.
340 --
341 -- Prerequisites:
342 --   This is an internal procedure which is called from the upd procedure.
343 --
344 -- In Parameters:
345 --   A Pl/Sql record structure.
346 --
347 -- Post Success:
348 --   Processing continues.
349 --
350 -- Post Failure:
351 --   If an error has occurred, an error message and exception will be raised
352 --   but not handled.
353 --
354 -- Developer Implementation Notes:
355 --   Any post-processing required after the update dml is issued should be
356 --   coded within this procedure. It is important to note that any 3rd party
357 --   maintenance should be reviewed before placing in this procedure.
358 --
359 -- Access Status:
360 --   Internal Row Handler Use Only.
361 --
362 -- {End Of Comments}
363 -- ----------------------------------------------------------------------------
364 Procedure post_update
365   (p_rec                   in ame_apu_shd.g_rec_type
366   ,p_effective_date        in date
367   ,p_datetrack_mode        in varchar2
368   ,p_validation_start_date in date
369   ,p_validation_end_date   in date
370   ) is
371 --
372   l_proc        varchar2(72) := g_package||'post_update';
373 --
374 Begin
375   hr_utility.set_location('Entering:'||l_proc, 5);
376   begin
377     --
378     ame_apu_rku.after_update
379       (p_effective_date
380       => p_effective_date
381       ,p_datetrack_mode
382       => p_datetrack_mode
383       ,p_validation_start_date
384       => p_validation_start_date
385       ,p_validation_end_date
386       => p_validation_end_date
387       ,p_approver_type_id
388       => p_rec.approver_type_id
389       ,p_action_type_id
390       => p_rec.action_type_id
391       ,p_start_date
392       => p_rec.start_date
393       ,p_end_date
394       => p_rec.end_date
395       ,p_object_version_number
396       => p_rec.object_version_number
397       ,p_start_date_o
398       => ame_apu_shd.g_old_rec.start_date
399       ,p_end_date_o
400       => ame_apu_shd.g_old_rec.end_date
401       ,p_object_version_number_o
402       => ame_apu_shd.g_old_rec.object_version_number
403       );
404     --
405   exception
406     --
407     when hr_api.cannot_find_prog_unit then
408       --
409       hr_api.cannot_find_prog_unit_error
410         (p_module_name => 'AME_APPROVER_TYPE_USAGES'
411         ,p_hook_type   => 'AU');
412       --
413   end;
414   --
415   hr_utility.set_location(' Leaving:'||l_proc, 10);
416 End post_update;
417 --
418 -- ----------------------------------------------------------------------------
419 -- |-----------------------------< convert_defs >-----------------------------|
420 -- ----------------------------------------------------------------------------
421 -- {Start Of Comments}
422 --
423 -- Description:
424 --   The Convert_Defs procedure has one very important function:
425 --   It must return the record structure for the row with all system defaulted
426 --   values converted into its corresponding parameter value for update. When
427 --   we attempt to update a row through the Upd process , certain
428 --   parameters can be defaulted which enables flexibility in the calling of
429 --   the upd process (e.g. only attributes which need to be updated need to be
430 --   specified). For the upd process to determine which attributes
431 --   have NOT been specified we need to check if the parameter has a reserved
432 --   system default value. Therefore, for all parameters which have a
433 --   corresponding reserved system default mechanism specified we need to
434 --   check if a system default is being used. If a system default is being
435 --   used then we convert the defaulted value into its corresponding attribute
436 --   value held in the g_old_rec data structure.
437 --
438 -- Prerequisites:
439 --   This private function can only be called from the upd process.
440 --
441 -- In Parameters:
442 --   A Pl/Sql record structure.
443 --
444 -- Post Success:
445 --   The record structure will be returned with all system defaulted parameter
446 --   values converted into its current row attribute value.
447 --
448 -- Post Failure:
449 --   No direct error handling is required within this function. Any possible
450 --   errors within this procedure will be a PL/SQL value error due to
451 --   conversion of datatypes or data lengths.
452 --
453 -- Developer Implementation Notes:
454 --   None.
455 --
456 -- Access Status:
457 --   Internal Row Handler Use Only.
458 --
459 -- {End Of Comments}
460 -- ----------------------------------------------------------------------------
461 Procedure convert_defs
462   (p_rec in out nocopy ame_apu_shd.g_rec_type
463   ) is
464 --
465 Begin
466   null;
467   --
468   -- We must now examine each argument value in the
469   -- p_rec plsql record structure
470   -- to see if a system default is being used. If a system default
471   -- is being used then we must set to the 'current' argument value.
472   --
473   --
474 End convert_defs;
475 --
476 -- ----------------------------------------------------------------------------
477 -- |---------------------------------< upd >----------------------------------|
478 -- ----------------------------------------------------------------------------
479 Procedure upd
480   (p_effective_date in     date
481   ,p_datetrack_mode in     varchar2
482   ,p_rec            in out nocopy ame_apu_shd.g_rec_type
483   ) is
484 --
485   l_proc                        varchar2(72) := g_package||'upd';
486   l_validation_start_date       date;
487   l_validation_end_date         date;
488 --
489 Begin
490   hr_utility.set_location('Entering:'||l_proc, 5);
491   --
492   -- Ensure that the DateTrack update mode is valid
493   --
494   dt_api.validate_dt_upd_mode(p_datetrack_mode => p_datetrack_mode);
495   --
496   -- We must lock the row which we need to update.
497   --
498   ame_apu_shd.lck
499     (p_effective_date                   => p_effective_date
500     ,p_datetrack_mode                   => p_datetrack_mode
501     ,p_approver_type_id =>  p_rec.approver_type_id
502  ,p_action_type_id =>  p_rec.action_type_id
503     ,p_object_version_number            => p_rec.object_version_number
504     ,p_validation_start_date            => l_validation_start_date
505     ,p_validation_end_date              => l_validation_end_date
506     );
507   --
508   -- 1. During an update system defaults are used to determine if
509   --    arguments have been defaulted or not. We must therefore
510   --    derive the full record structure values to be updated.
511   --
512   -- 2. Call the supporting update validate operations.
513   --
514   ame_apu_upd.convert_defs(p_rec);
515   --
516   ame_apu_bus.update_validate
517     (p_rec                              => p_rec
518     ,p_effective_date                   => p_effective_date
519     ,p_datetrack_mode                   => p_datetrack_mode
520     ,p_validation_start_date            => l_validation_start_date
521     ,p_validation_end_date              => l_validation_end_date
522     );
523   --
524   -- Call to raise any errors on multi-message list
525   hr_multi_message.end_validation_set;
526   --
527   -- Call the supporting pre-update operation
528   --
529   pre_update
530     (p_rec                              => p_rec
531     ,p_effective_date                   => p_effective_date
532     ,p_datetrack_mode                   => p_datetrack_mode
533     ,p_validation_start_date            => l_validation_start_date
534     ,p_validation_end_date              => l_validation_end_date
535     );
536   --
537   -- Update the row.
538   --
539   update_dml
540     (p_rec                              => p_rec
541     ,p_effective_date                   => p_effective_date
542     ,p_datetrack_mode                   => p_datetrack_mode
543     ,p_validation_start_date            => l_validation_start_date
544     ,p_validation_end_date                  => l_validation_end_date
545     );
546   --
547   -- Call the supporting post-update operation
548   --
549   post_update
550     (p_rec                              => p_rec
551     ,p_effective_date                   => p_effective_date
552     ,p_datetrack_mode                   => p_datetrack_mode
553     ,p_validation_start_date            => l_validation_start_date
554     ,p_validation_end_date              => l_validation_end_date
555     );
556   --
557   -- Call to raise any errors on multi-message list
558   hr_multi_message.end_validation_set;
559 End upd;
560 --
561 -- ----------------------------------------------------------------------------
562 -- |------------------------------< upd >-------------------------------------|
563 -- ----------------------------------------------------------------------------
564 Procedure upd
565   (p_effective_date               in     date
566   ,p_datetrack_mode               in     varchar2
567   ,p_approver_type_id             in     number
568   ,p_action_type_id               in     number
569   ,p_object_version_number        in out nocopy number
570   ,p_start_date                      out nocopy date
571   ,p_end_date                        out nocopy date
572   ) is
573 --
574   l_rec         ame_apu_shd.g_rec_type;
575   l_proc        varchar2(72) := g_package||'upd';
576 --
577 Begin
578   hr_utility.set_location('Entering:'||l_proc, 5);
579   --
580   -- Call conversion function to turn arguments into the
581   -- l_rec structure.
582   --
583   l_rec :=
584   ame_apu_shd.convert_args
585     (p_approver_type_id
586     ,p_action_type_id
587     ,p_start_date
588     ,p_end_date
589     ,p_object_version_number
590     );
591   --
592   -- Having converted the arguments into the
593   -- plsql record structure we call the corresponding record
594   -- business process.
595   --
596   ame_apu_upd.upd
597     (p_effective_date
598     ,p_datetrack_mode
599     ,l_rec
600     );
601   --
602   -- Set the out parameters
603   --
604   p_object_version_number            := l_rec.object_version_number;
605   p_start_date             := l_rec.start_date;
606   p_end_date               := l_rec.end_date;
607   --
608   --
609   hr_utility.set_location(' Leaving:'||l_proc, 10);
610 End upd;
611 --
612 end ame_apu_upd;