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