DBA Data[Home] [Help]

PACKAGE BODY: APPS.PQH_DOC_INS

Source


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