DBA Data[Home] [Help]

PACKAGE BODY: APPS.AME_CFV_UPD

Source


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