DBA Data[Home] [Help]

PACKAGE BODY: APPS.PQH_GIN_INS

Source


1 Package Body pqh_gin_ins as
2 /* $Header: pqginrhi.pkb 115.7 2004/03/15 03:05 svorugan noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
11 -- the set_base_key_value and pre_insert procedures.
8 g_package  varchar2(33) := '  pqh_gin_ins.';  -- Global package name
9 --
10 -- The following global variables are only to be used by
12 --
13 g_global_index_id_i  number   default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19   (p_global_index_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   pqh_gin_ins.g_global_index_id_i := p_global_index_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 pqh_gin_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   pqh_fr_global_indices_f t
92     where  t.global_index_id       = p_rec.global_index_id
93     and    t.effective_start_date =
94              pqh_gin_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          pqh_fr_global_indices_f.created_by%TYPE;
99   l_creation_date       pqh_fr_global_indices_f.creation_date%TYPE;
100   l_last_update_date    pqh_fr_global_indices_f.last_update_date%TYPE;
101   l_last_updated_by     pqh_fr_global_indices_f.last_updated_by%TYPE;
102   l_last_update_login   pqh_fr_global_indices_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 => 'pqh_fr_global_indices_f'
124       ,p_base_key_column => 'global_index_id'
125       ,p_base_key_value  => p_rec.global_index_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;
141       fnd_message.raise_error;
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');
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   --
156   -- Insert the row into: pqh_fr_global_indices_f
157   --
158   insert into pqh_fr_global_indices_f
159       (global_index_id
160       ,effective_start_date
161       ,effective_end_date
162       ,type_of_record
163       ,gross_index
164       ,increased_index
165       ,basic_salary_rate
166       ,housing_indemnity_rate
167       ,currency_code
168       ,object_version_number
169       ,created_by
170       ,creation_date
171       ,last_update_date
172       ,last_updated_by
173       ,last_update_login
174       )
175   Values
176     (p_rec.global_index_id
177     ,p_rec.effective_start_date
178     ,p_rec.effective_end_date
179     ,p_rec.type_of_record
180     ,p_rec.gross_index
181     ,p_rec.increased_index
182     ,p_rec.basic_salary_rate
183     ,p_rec.housing_indemnity_rate
184     ,p_rec.currency_code
185     ,p_rec.object_version_number
186     ,l_created_by
187     ,l_creation_date
188     ,l_last_update_date
189     ,l_last_updated_by
190     ,l_last_update_login
191     );
192   --
193   --
194   hr_utility.set_location(' Leaving:'||l_proc, 15);
195 --
196 Exception
197   When hr_api.check_integrity_violated Then
198     -- A check constraint has been violated
199     --
200     pqh_gin_shd.constraint_error
201       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
202   When hr_api.unique_integrity_violated Then
203     -- Unique integrity has been violated
204     --
205     pqh_gin_shd.constraint_error
206       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
207   When Others Then
208     --
209     Raise;
210 End dt_insert_dml;
211 --
212 -- ----------------------------------------------------------------------------
213 -- |------------------------------< insert_dml >------------------------------|
214 -- ----------------------------------------------------------------------------
215 Procedure insert_dml
216   (p_rec                   in out nocopy pqh_gin_shd.g_rec_type
217   ,p_effective_date        in date
218   ,p_datetrack_mode        in varchar2
219   ,p_validation_start_date in date
220   ,p_validation_end_date   in date
221   ) is
222 --
223   l_proc        varchar2(72) := g_package||'insert_dml';
224 --
225 Begin
226   hr_utility.set_location('Entering:'||l_proc, 5);
227   --
228   pqh_gin_ins.dt_insert_dml
229     (p_rec                   => p_rec
230     ,p_effective_date        => p_effective_date
231     ,p_datetrack_mode        => p_datetrack_mode
232     ,p_validation_start_date => p_validation_start_date
233     ,p_validation_end_date   => p_validation_end_date
234     );
235   --
236   hr_utility.set_location(' Leaving:'||l_proc, 10);
237 End insert_dml;
238 --
239 -- ----------------------------------------------------------------------------
240 -- |------------------------------< pre_insert >------------------------------|
241 -- ----------------------------------------------------------------------------
242 -- {Start Of Comments}
243 --
244 -- Description:
245 --   This private procedure contains any processing which is required before
246 --   the insert dml. Presently, if the entity has a corresponding primary
247 --   key which is maintained by an associating sequence, the primary key for
248 --   the entity will be populated with the next sequence value in
249 --   preparation for the insert dml.
250 --   Also, if comments are defined for this entity, the comments insert
251 --   logic will also be called, generating a comment_id if required.
252 --
253 -- Prerequisites:
254 --   This is an internal procedure which is called from the ins procedure.
255 --
256 -- In Parameters:
257 --   A Pl/Sql record structure.
258 --
259 -- Post Success:
260 --   Processing continues.
261 --
262 -- Post Failure:
263 --   If an error has occurred, an error message and exception will be raised
264 --   but not handled.
265 --
266 -- Developer Implementation Notes:
267 --   Any pre-processing required before the insert dml is issued should be
268 --   coded within this procedure. As stated above, a good example is the
269 --   generation of a primary key number via a corresponding sequence.
270 --   It is important to note that any 3rd party maintenance should be reviewed
271 --   before placing in this procedure.
272 --
273 -- Access Status:
274 --   Internal Row Handler Use Only.
275 --
276 -- {End Of Comments}
277 -- ----------------------------------------------------------------------------
278 Procedure pre_insert
279   (p_rec                   in out nocopy pqh_gin_shd.g_rec_type
280   ,p_effective_date        in date
281   ,p_datetrack_mode        in varchar2
282   ,p_validation_start_date in date
283   ,p_validation_end_date   in date
284   ) is
285 --
286   Cursor C_Sel1 is select pqh_fr_global_indices_s.nextval from sys.dual;
287 --
288  Cursor C_Sel2 is
289     Select null
293 --
290       from pqh_fr_global_indices_f
291      where global_index_id =
292              pqh_gin_ins.g_global_index_id_i;
294   l_proc        varchar2(72) := g_package||'pre_insert';
295   l_exists      varchar2(1);
296 --
297 Begin
298   hr_utility.set_location('Entering:'||l_proc, 5);
299   --
300     If (pqh_gin_ins.g_global_index_id_i is not null) Then
301     --
302     -- Verify registered primary key values not already in use
303     --
304     Open C_Sel2;
305     Fetch C_Sel2 into l_exists;
306     If C_Sel2%found Then
307        Close C_Sel2;
308        --
309        -- The primary key values are already in use.
310        --
311        fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
312        fnd_message.set_token('TABLE_NAME','pqh_fr_global_indices_f');
313        fnd_message.raise_error;
314     End If;
315     Close C_Sel2;
316     --
317     -- Use registered key values and clear globals
318     --
319     p_rec.global_index_id :=
320       pqh_gin_ins.g_global_index_id_i;
321     pqh_gin_ins.g_global_index_id_i := null;
322   Else
323     --
324     -- No registerd key values, so select the next sequence number
325     --
326     --
327     -- Select the next sequence number
328     --
329     Open C_Sel1;
330     Fetch C_Sel1 Into p_rec.global_index_id;
331     Close C_Sel1;
332   End If;
333   --
334   --
335   hr_utility.set_location(' Leaving:'||l_proc, 10);
336 End pre_insert;
337 --
338 -- ----------------------------------------------------------------------------
339 -- |----------------------------< post_insert >-------------------------------|
340 -- ----------------------------------------------------------------------------
341 -- {Start Of Comments}
342 --
343 -- Description:
344 --   This private procedure contains any processing which is required after
345 --   the insert dml.
346 --
347 -- Prerequisites:
348 --   This is an internal procedure which is called from the ins procedure.
349 --
350 -- In Parameters:
351 --   A Pl/Sql record structure.
352 --
353 -- Post Success:
354 --   Processing continues.
355 --
356 -- Post Failure:
357 --   If an error has occurred, an error message and exception will be raised
358 --   but not handled.
359 --
360 -- Developer Implementation Notes:
361 --   Any post-processing required after the insert dml is issued should be
362 --   coded within this procedure. It is important to note that any 3rd party
363 --   maintenance should be reviewed before placing in this procedure.
364 --
365 -- Access Status:
366 --   Internal Row Handler Use Only.
367 --
368 -- {End Of Comments}
369 -- ----------------------------------------------------------------------------
370 Procedure post_insert
371   (p_rec                   in pqh_gin_shd.g_rec_type
372   ,p_effective_date        in date
373   ,p_datetrack_mode        in varchar2
374   ,p_validation_start_date in date
375   ,p_validation_end_date   in date
376   ) is
377 --
378   l_proc        varchar2(72) := g_package||'post_insert';
379 --
380 Begin
381   hr_utility.set_location('Entering:'||l_proc, 5);
382   begin
383     --
384     pqh_gin_rki.after_insert
385       (p_effective_date
386       => p_effective_date
387       ,p_validation_start_date
388       => p_validation_start_date
389       ,p_validation_end_date
390       => p_validation_end_date
391       ,p_global_index_id
392       => p_rec.global_index_id
393       ,p_effective_start_date
394       => p_rec.effective_start_date
395       ,p_effective_end_date
396       => p_rec.effective_end_date
397       ,p_type_of_record
398       => p_rec.type_of_record
399       ,p_gross_index
400       => p_rec.gross_index
401       ,p_increased_index
402       => p_rec.increased_index
403       ,p_basic_salary_rate
404       => p_rec.basic_salary_rate
405       ,p_housing_indemnity_rate
406       => p_rec.housing_indemnity_rate
407       ,p_object_version_number
408       => p_rec.object_version_number
409       ,p_currency_code
410       => p_rec.currency_code
411       );
412     --
413   exception
414     --
415     when hr_api.cannot_find_prog_unit then
416       --
417       hr_api.cannot_find_prog_unit_error
418         (p_module_name => 'PQH_FR_GLOBAL_INDICES_F'
419         ,p_hook_type   => 'AI');
420       --
421   end;
422   --
423   hr_utility.set_location(' Leaving:'||l_proc, 10);
424 End post_insert;
425 --
426 -- ----------------------------------------------------------------------------
427 -- |-------------------------------< ins_lck >--------------------------------|
428 -- ----------------------------------------------------------------------------
429 -- {Start Of Comments}
430 --
431 -- Description:
432 --   The ins_lck process has one main function to perform. When inserting
433 --   a datetracked row, we must validate the DT mode.
434 --
435 -- Prerequisites:
436 --   This procedure can only be called for the datetrack mode of INSERT.
437 --
438 -- In Parameters:
439 --
440 -- Post Success:
441 --   On successful completion of the ins_lck process the parental
442 --   datetracked rows will be locked providing the p_enforce_foreign_locking
443 --   argument value is TRUE.
444 --   If the p_enforce_foreign_locking argument value is FALSE then the
445 --   parential rows are not locked.
446 --
447 -- Post Failure:
451 --   2) When attempting to the lock the parent which doesn't exist.
448 --   The Lck process can fail for:
449 --   1) When attempting to lock the row the row could already be locked by
450 --      another user. This will raise the HR_Api.Object_Locked exception.
452 --      For the entity to be locked the parent must exist!
453 --
454 -- Developer Implementation Notes:
455 --   None.
456 --
457 -- Access Status:
458 --   Internal Row Handler Use Only.
459 --
460 -- {End Of Comments}
461 -- ----------------------------------------------------------------------------
462 Procedure ins_lck
463   (p_effective_date        in date
464   ,p_datetrack_mode        in varchar2
465   ,p_rec                   in pqh_gin_shd.g_rec_type
466   ,p_validation_start_date out nocopy date
467   ,p_validation_end_date   out nocopy date
468   ) is
469 --
470   l_proc                  varchar2(72) := g_package||'ins_lck';
471   l_validation_start_date date;
472   l_validation_end_date   date;
473 --
474 Begin
475   hr_utility.set_location('Entering:'||l_proc, 5);
476   --
477   -- Validate the datetrack mode mode getting the validation start
478   -- and end dates for the specified datetrack operation.
479   --
480   dt_api.validate_dt_mode
481     (p_effective_date          => p_effective_date
482     ,p_datetrack_mode          => p_datetrack_mode
483     ,p_base_table_name         => 'pqh_fr_global_indices_f'
484     ,p_base_key_column         => 'global_index_id'
485     ,p_base_key_value          => p_rec.global_index_id
486     ,p_enforce_foreign_locking => true
487     ,p_validation_start_date   => l_validation_start_date
488     ,p_validation_end_date     => l_validation_end_date
489     );
490   --
491   -- Set the validation start and end date OUT arguments
492   --
493   p_validation_start_date := l_validation_start_date;
494   p_validation_end_date   := l_validation_end_date;
495   --
496   hr_utility.set_location(' Leaving:'||l_proc, 10);
497   --
498 End ins_lck;
499 --
500 -- ----------------------------------------------------------------------------
501 -- |---------------------------------< ins >----------------------------------|
502 -- ----------------------------------------------------------------------------
503 Procedure ins
504   (p_effective_date in     date
505   ,p_rec            in out nocopy pqh_gin_shd.g_rec_type
506   ) is
507 --
508   l_proc                        varchar2(72) := g_package||'ins';
509   l_datetrack_mode              varchar2(30) := hr_api.g_insert;
510   l_validation_start_date       date;
511   l_validation_end_date         date;
512 --
513 Begin
514   hr_utility.set_location('Entering:'||l_proc, 5);
515   --
516   -- Call the lock operation
517   --
518   pqh_gin_ins.ins_lck
519     (p_effective_date        => p_effective_date
520     ,p_datetrack_mode        => l_datetrack_mode
521     ,p_rec                   => p_rec
522     ,p_validation_start_date => l_validation_start_date
523     ,p_validation_end_date   => l_validation_end_date
524     );
525   --
526   -- Call the supporting insert validate operations
527   --
528   pqh_gin_bus.insert_validate
529     (p_rec                   => p_rec
530     ,p_effective_date        => p_effective_date
531     ,p_datetrack_mode        => l_datetrack_mode
532     ,p_validation_start_date => l_validation_start_date
533     ,p_validation_end_date   => l_validation_end_date
534     );
535   --
536   -- Call to raise any errors on multi-message list
537   hr_multi_message.end_validation_set;
538   --
539   -- Call the supporting pre-insert operation
540   --
541   pqh_gin_ins.pre_insert
542     (p_rec                   => p_rec
543     ,p_effective_date        => p_effective_date
544     ,p_datetrack_mode        => l_datetrack_mode
545     ,p_validation_start_date => l_validation_start_date
546     ,p_validation_end_date   => l_validation_end_date
547     );
548   --
549   -- Insert the row
550   --
551   pqh_gin_ins.insert_dml
552     (p_rec                   => p_rec
553     ,p_effective_date        => p_effective_date
554     ,p_datetrack_mode        => l_datetrack_mode
555     ,p_validation_start_date => l_validation_start_date
556     ,p_validation_end_date   => l_validation_end_date
557     );
558   --
559   -- Call the supporting post-insert operation
560   --
561   pqh_gin_ins.post_insert
562     (p_rec                   => p_rec
563     ,p_effective_date        => p_effective_date
564     ,p_datetrack_mode        => l_datetrack_mode
565     ,p_validation_start_date => l_validation_start_date
566     ,p_validation_end_date   => l_validation_end_date
567     );
568   --
569   -- Call to raise any errors on multi-message list
570   hr_multi_message.end_validation_set;
571   --
572   hr_utility.set_location('Leaving:'||l_proc,10);
573 end ins;
574 --
575 -- ----------------------------------------------------------------------------
576 -- |---------------------------------< ins >----------------------------------|
577 -- ----------------------------------------------------------------------------
578 Procedure ins
579   (p_effective_date                 in     date
580   ,p_type_of_record                 in     varchar2 default null
581   ,p_gross_index                    in     number   default null
582   ,p_increased_index                in     number   default null
583   ,p_basic_salary_rate              in     number   default null
584   ,p_housing_indemnity_rate              in     number   default null
585   ,p_currency_code		    in     varchar2 default null
586   ,p_global_index_id                   out nocopy number
590   ) is
587   ,p_object_version_number             out nocopy number
588   ,p_effective_start_date              out nocopy date
589   ,p_effective_end_date                out nocopy date
591 --
592   l_rec         pqh_gin_shd.g_rec_type;
593   l_proc        varchar2(72) := g_package||'ins';
594 --
595 Begin
596   hr_utility.set_location('Entering:'||l_proc, 5);
597   --
598   -- Call conversion function to turn arguments into the
599   -- p_rec structure.
600   --
601   l_rec :=
602   pqh_gin_shd.convert_args
603     (null
604     ,null
605     ,null
606     ,p_type_of_record
607     ,p_gross_index
608     ,p_increased_index
609     ,p_basic_salary_rate
610     ,p_housing_indemnity_rate
611     ,null
612     ,p_currency_code
613     );
614 
615   --
616   -- Having converted the arguments into the pqh_gin_rec
617   -- plsql record structure we call the corresponding record
618   -- business process.
619   --
620   pqh_gin_ins.ins
621     (p_effective_date
622     ,l_rec
623     );
624   --
625   -- Set the OUT arguments.
626   --
627   p_global_index_id                  := l_rec.global_index_id;
628   p_effective_start_date             := l_rec.effective_start_date;
629   p_effective_end_date               := l_rec.effective_end_date;
630   p_object_version_number            := l_rec.object_version_number;
631   --
632   --
633   hr_utility.set_location(' Leaving:'||l_proc, 10);
634 End ins;
635 --
636 end pqh_gin_ins;