DBA Data[Home] [Help]

PACKAGE BODY: APPS.AME_CFV_INS

Source


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