DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_UCI_INS

Source


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