DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_ECU_INS

Source


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