DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_RTU_INS

Source


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