[Home] [Help]
PACKAGE BODY: APPS.BEN_CPO_BUS
Source
1 Package Body ben_cpo_bus as
2 /* $Header: becporhi.pkb 115.11 2002/12/13 06:20:48 hmani ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' ben_cpo_bus.'; -- Global package name
9 --
10 -- ----------------------------------------------------------------------------
11 -- |-------------------------< chk_popl_org_id >------------------------------|
12 -- ----------------------------------------------------------------------------
13 --
14 -- Description
15 -- This procedure is used to check that the primary key for the table
16 -- is created properly. It should be null on insert and
17 -- should not be able to be updated.
18 --
19 -- Pre Conditions
20 -- None.
21 --
22 -- In Parameters
23 -- popl_org_id PK of record being inserted or updated.
24 -- effective_date Effective Date of session
25 -- object_version_number Object version number of record being
26 -- inserted or updated.
27 --
28 -- Post Success
29 -- Processing continues
30 --
31 -- Post Failure
32 -- Errors handled by the procedure
33 --
34 -- Access Status
35 -- Internal table handler use only.
36 --
37 Procedure chk_popl_org_id(p_popl_org_id in number,
38 p_effective_date in date,
39 p_object_version_number in number) is
40 --
41 l_proc varchar2(72) := g_package||'chk_popl_org_id';
42 l_api_updating boolean;
43 --
44 Begin
45 --
46 hr_utility.set_location('Entering:'||l_proc, 5);
47 --
48 l_api_updating := ben_cpo_shd.api_updating
49 (p_effective_date => p_effective_date,
50 p_popl_org_id => p_popl_org_id,
51 p_object_version_number => p_object_version_number);
52 --
53 if (l_api_updating
54 and nvl(p_popl_org_id,hr_api.g_number)
55 <> ben_cpo_shd.g_old_rec.popl_org_id) then
56 --
57 -- raise error as PK has changed
58 --
59 ben_cpo_shd.constraint_error('BEN_POPL_ORG_PK');
60 --
61 elsif not l_api_updating then
62 --
63 -- check if PK is null
64 --
65 if p_popl_org_id is not null then
66 --
67 -- raise error as PK is not null
68 --
69 ben_cpo_shd.constraint_error('BEN_POPL_ORG_PK');
70 --
71 end if;
72 --
73 end if;
74 --
75 hr_utility.set_location('Leaving:'||l_proc, 10);
76 --
77 End chk_popl_org_id;
78 --
79 -- ----------------------------------------------------------------------------
80 -- |----------------------------< chk_organization_id >-----------------------|
81 -- ----------------------------------------------------------------------------
82 --
83 -- Description
84 -- This procedure checks that a referenced foreign key actually exists
85 -- in the referenced table.
86 --
87 -- Pre-Conditions
88 -- None.
89 --
90 -- In Parameters
91 -- p_popl_org_id PK
92 -- p_organization_id ID of FK column
93 -- p_effective_date Session Date of record
94 -- p_object_version_number object version number
95 --
96 -- Post Success
97 -- Processing continues
98 --
99 -- Post Failure
100 -- Error raised.
101 --
102 -- Access Status
103 -- Internal table handler use only.
104 --
105 Procedure chk_organization_id (p_popl_org_id in number,
106 p_organization_id in number,
107 p_effective_date in date,
108 p_object_version_number in number) is
109 --
110 l_proc varchar2(72) := g_package||'chk_organization_id';
111 l_api_updating boolean;
112 l_dummy varchar2(1);
113 --
114 cursor c1 is
115 select null
116 from hr_all_organization_units a
117 where a.organization_id = p_organization_id;
118 --
119 Begin
120 --
121 hr_utility.set_location('Entering:'||l_proc,5);
122 --
123 l_api_updating := ben_cpo_shd.api_updating
124 (p_popl_org_id => p_popl_org_id,
125 p_effective_date => p_effective_date,
126 p_object_version_number => p_object_version_number);
127 --
128 if (l_api_updating
129 and nvl(p_organization_id,hr_api.g_number)
130 <> nvl(ben_cpo_shd.g_old_rec.organization_id,hr_api.g_number)
131 or not l_api_updating) then
132 --
133 -- check if organization_id value exists in hr_all_organization_units table
134 --
135 open c1;
136 --
137 fetch c1 into l_dummy;
138 if c1%notfound then
139 --
140 close c1;
141 --
142 -- raise error as FK does not relate to PK in hr_all_organization_units
143 -- table.
144 --
145 ben_cpo_shd.constraint_error('BEN_POPL_ORG_FK2');
146 --
147 end if;
148 --
149 close c1;
150 --
151 end if;
152 --
153 hr_utility.set_location('Leaving:'||l_proc,10);
154 --
155 End chk_organization_id;
156 --
157 -- ----------------------------------------------------------------------------
158 -- |----------------------------< chk_pgm_pl_id >-----------------------------|
159 -- ----------------------------------------------------------------------------
160 --
161 -- Description
162 -- This procedure checks that either the pl_id or pgm_id is populated and not
163 -- both.
164 --
165 -- Pre-Conditions
166 -- None.
167 --
168 -- In Parameters
169 -- p_pl_id plan id of record.
170 -- p_pgm_id program id of record.
171 --
172 -- Post Success
173 -- Processing continues
174 --
175 -- Post Failure
176 -- Error raised.
177 --
178 -- Access Status
179 -- Internal table handler use only.
180 --
181 Procedure chk_pgm_pl_id (p_pgm_id in number,
182 p_pl_id in number) is
183 --
184 l_proc varchar2(72) := g_package||'chk_pgm_pl_id';
185 --
186 Begin
187 --
188 hr_utility.set_location('Entering:'||l_proc,5);
189 --
190 -- check that only one of the foreign keys is populated.
191 --
192 if p_pgm_id is not null and
193 p_pl_id is not null then
194 --
195 hr_utility.set_message(801,'PGM_OR_PL_ID_SET');
196 hr_utility.raise_error;
197 --
198 elsif p_pgm_id is null and
199 p_pl_id is null then
200 --
201 hr_utility.set_message(801,'PGM_OR_PL_ID_SET');
202 hr_utility.raise_error;
203 --
204 end if;
205 --
206 hr_utility.set_location('Leaving:'||l_proc,10);
207 --
208 End chk_pgm_pl_id;
209
210 -- ----------------------------------------------------------------------------
211 -- |--------------------------< dt_update_validate >--------------------------|
212 -- ----------------------------------------------------------------------------
213 -- {Start Of Comments}
214 --
215 -- Description:
216 -- This procedure is used for referential integrity of datetracked
217 -- parent entities when a datetrack update operation is taking place
218 -- and where there is no cascading of update defined for this entity.
219 --
220 -- Prerequisites:
221 -- This procedure is called from the update_validate.
222 --
223 -- In Parameters:
224 --
225 -- Post Success:
226 -- Processing continues.
227 --
228 -- Post Failure:
229 --
230 -- Developer Implementation Notes:
231 -- This procedure should not need maintenance unless the HR Schema model
232 -- changes.
233 --
234 -- Access Status:
235 -- Internal Row Handler Use Only.
236 --
237 -- {End Of Comments}
238 -- ----------------------------------------------------------------------------
239 Procedure dt_update_validate
240 (p_pl_id in number default hr_api.g_number,
241 p_pgm_id in number default hr_api.g_number,
242 p_datetrack_mode in varchar2,
243 p_validation_start_date in date,
244 p_validation_end_date in date) Is
245 --
246 l_proc varchar2(72) := g_package||'dt_update_validate';
247 l_integrity_error Exception;
248 l_table_name all_tables.table_name%TYPE;
249 --
250 Begin
251 hr_utility.set_location('Entering:'||l_proc, 5);
252 --
253 -- Ensure that the p_datetrack_mode argument is not null
254 --
255 hr_api.mandatory_arg_error
256 (p_api_name => l_proc,
257 p_argument => 'datetrack_mode',
258 p_argument_value => p_datetrack_mode);
259 --
260 -- Only perform the validation if the datetrack update mode is valid
261 --
262 If (dt_api.validate_dt_upd_mode(p_datetrack_mode => p_datetrack_mode)) then
263 --
264 --
265 -- Ensure the arguments are not null
266 --
267 hr_api.mandatory_arg_error
268 (p_api_name => l_proc,
269 p_argument => 'validation_start_date',
270 p_argument_value => p_validation_start_date);
271 --
272 hr_api.mandatory_arg_error
273 (p_api_name => l_proc,
274 p_argument => 'validation_end_date',
275 p_argument_value => p_validation_end_date);
276 --
277 If ((nvl(p_pl_id, hr_api.g_number) <> hr_api.g_number) and
278 NOT (dt_api.check_min_max_dates
279 (p_base_table_name => 'ben_pl_f',
280 p_base_key_column => 'pl_id',
281 p_base_key_value => p_pl_id,
282 p_from_date => p_validation_start_date,
283 p_to_date => p_validation_end_date))) Then
284 l_table_name := 'ben_pl_f';
285 Raise l_integrity_error;
286 End If;
287 If ((nvl(p_pgm_id, hr_api.g_number) <> hr_api.g_number) and
288 NOT (dt_api.check_min_max_dates
289 (p_base_table_name => 'ben_pgm_f',
290 p_base_key_column => 'pgm_id',
291 p_base_key_value => p_pgm_id,
292 p_from_date => p_validation_start_date,
293 p_to_date => p_validation_end_date))) Then
294 l_table_name := 'ben_pgm_f';
295 Raise l_integrity_error;
296 End If;
297 --
298 End If;
299 --
300 hr_utility.set_location(' Leaving:'||l_proc, 10);
301 Exception
302 When l_integrity_error Then
303 --
304 -- A referential integrity check was violated therefore
305 -- we must error
306 --
307 hr_utility.set_message(801, 'HR_7216_DT_UPD_INTEGRITY_ERR');
308 hr_utility.set_message_token('TABLE_NAME', l_table_name);
309 hr_utility.raise_error;
310 When Others Then
311 --
312 -- An unhandled or unexpected error has occurred which
313 -- we must report
314 --
315 hr_utility.set_message(801, 'HR_6153_ALL_PROCEDURE_FAIL');
316 hr_utility.set_message_token('PROCEDURE', l_proc);
317 hr_utility.set_message_token('STEP','15');
318 hr_utility.raise_error;
319 End dt_update_validate;
320 --
321 -- ----------------------------------------------------------------------------
322 -- |--------------------------< dt_delete_validate >--------------------------|
323 -- ----------------------------------------------------------------------------
324 -- {Start Of Comments}
325 --
326 -- Description:
327 -- This procedure is used for referential integrity of datetracked
328 -- child entities when either a datetrack DELETE or ZAP is in operation
329 -- and where there is no cascading of delete defined for this entity.
330 -- For the datetrack mode of DELETE or ZAP we must ensure that no
331 -- datetracked child rows exist between the validation start and end
332 -- dates.
333 --
334 -- Prerequisites:
335 -- This procedure is called from the delete_validate.
336 --
337 -- In Parameters:
338 --
339 -- Post Success:
340 -- Processing continues.
341 --
342 -- Post Failure:
343 -- If a row exists by determining the returning Boolean value from the
344 -- generic dt_api.rows_exist function then we must supply an error via
345 -- the use of the local exception handler l_rows_exist.
346 --
347 -- Developer Implementation Notes:
348 -- This procedure should not need maintenance unless the HR Schema model
349 -- changes.
350 --
351 -- Access Status:
352 -- Internal Row Handler Use Only.
353 --
354 -- {End Of Comments}
355 -- ----------------------------------------------------------------------------
356 Procedure dt_delete_validate
357 (p_popl_org_id in number,
358 p_datetrack_mode in varchar2,
359 p_validation_start_date in date,
360 p_validation_end_date in date) Is
361 --
362 l_proc varchar2(72) := g_package||'dt_delete_validate';
363 l_rows_exist Exception;
364 l_table_name all_tables.table_name%TYPE;
365 --
366 Begin
367 hr_utility.set_location('Entering:'||l_proc, 5);
368 --
369 -- Ensure that the p_datetrack_mode argument is not null
370 --
371 hr_api.mandatory_arg_error
372 (p_api_name => l_proc,
373 p_argument => 'datetrack_mode',
374 p_argument_value => p_datetrack_mode);
375 --
376 -- Only perform the validation if the datetrack mode is either
377 -- DELETE or ZAP
378 --
379 If (p_datetrack_mode = 'DELETE' or
380 p_datetrack_mode = 'ZAP') then
381 --
382 --
383 -- Ensure the arguments are not null
384 --
385 hr_api.mandatory_arg_error
386 (p_api_name => l_proc,
387 p_argument => 'validation_start_date',
388 p_argument_value => p_validation_start_date);
389 --
390 hr_api.mandatory_arg_error
391 (p_api_name => l_proc,
392 p_argument => 'validation_end_date',
393 p_argument_value => p_validation_end_date);
394 --
395 hr_api.mandatory_arg_error
396 (p_api_name => l_proc,
397 p_argument => 'popl_org_id',
398 p_argument_value => p_popl_org_id);
399 --
400 --
401 --
402 End If;
403 --
404 hr_utility.set_location(' Leaving:'||l_proc, 10);
405 Exception
406 When l_rows_exist Then
407 --
408 -- A referential integrity check was violated therefore
409 -- we must error
410 --
411 hr_utility.set_message(801, 'HR_7215_DT_CHILD_EXISTS');
412 hr_utility.set_message_token('TABLE_NAME', l_table_name);
413 hr_utility.raise_error;
414 When Others Then
415 --
416 -- An unhandled or unexpected error has occurred which
417 -- we must report
418 --
419 hr_utility.set_message(801, 'HR_6153_ALL_PROCEDURE_FAIL');
420 hr_utility.set_message_token('PROCEDURE', l_proc);
421 hr_utility.set_message_token('STEP','15');
422 hr_utility.raise_error;
423 End dt_delete_validate;
424 --
425 -- ----------------------------------------------------------------------------
426 -- |---------------------------< insert_validate >----------------------------|
427 -- ----------------------------------------------------------------------------
428 Procedure insert_validate
429 (p_rec in ben_cpo_shd.g_rec_type,
430 p_effective_date in date,
431 p_datetrack_mode in varchar2,
432 p_validation_start_date in date,
433 p_validation_end_date in date) is
434 --
435 l_proc varchar2(72) := g_package||'insert_validate';
436 --
437 Begin
438 hr_utility.set_location('Entering:'||l_proc, 5);
439 --
440 -- Call all supporting business operations
441 --
442 --
443 hr_api.validate_bus_grp_id(p_rec.business_group_id); -- Validate Bus Grp
444 --
445 chk_popl_org_id
446 (p_popl_org_id => p_rec.popl_org_id,
447 p_effective_date => p_effective_date,
448 p_object_version_number => p_rec.object_version_number);
449 --
450 chk_organization_id
451 (p_popl_org_id => p_rec.popl_org_id,
452 p_organization_id => p_rec.organization_id,
453 p_effective_date => p_effective_date,
454 p_object_version_number => p_rec.object_version_number);
455 --
456 chk_pgm_pl_id
457 (p_pgm_id => p_rec.pgm_id,
458 p_pl_id => p_rec.pl_id);
459 --
460
461 hr_utility.set_location(' Leaving:'||l_proc, 10);
462 End insert_validate;
463 --
464 -- ----------------------------------------------------------------------------
465 -- |---------------------------< update_validate >----------------------------|
466 -- ----------------------------------------------------------------------------
467 Procedure update_validate
468 (p_rec in ben_cpo_shd.g_rec_type,
469 p_effective_date in date,
470 p_datetrack_mode in varchar2,
471 p_validation_start_date in date,
472 p_validation_end_date in date) is
473 --
474 l_proc varchar2(72) := g_package||'update_validate';
475 --
476 Begin
477 hr_utility.set_location('Entering:'||l_proc, 5);
478 --
479 -- Call all supporting business operations
480 --
481 --
482 hr_api.validate_bus_grp_id(p_rec.business_group_id); -- Validate Bus Grp
483 --
484 chk_popl_org_id
485 (p_popl_org_id => p_rec.popl_org_id,
486 p_effective_date => p_effective_date,
487 p_object_version_number => p_rec.object_version_number);
488 --
489 chk_organization_id
490 (p_popl_org_id => p_rec.popl_org_id,
491 p_organization_id => p_rec.organization_id,
492 p_effective_date => p_effective_date,
493 p_object_version_number => p_rec.object_version_number);
494 --
495 chk_pgm_pl_id
496 (p_pgm_id => p_rec.pgm_id,
497 p_pl_id => p_rec.pl_id);
498 --
499
500 -- Call the datetrack update integrity operation
501 --
502 dt_update_validate
503 (p_pl_id => p_rec.pl_id,
504 p_pgm_id => p_rec.pgm_id,
505 p_datetrack_mode => p_datetrack_mode,
506 p_validation_start_date => p_validation_start_date,
507 p_validation_end_date => p_validation_end_date);
508 --
509
510 hr_utility.set_location(' Leaving:'||l_proc, 10);
511 End update_validate;
512 --
513 -- ----------------------------------------------------------------------------
514 -- |---------------------------< delete_validate >----------------------------|
515 -- ----------------------------------------------------------------------------
516 Procedure delete_validate
517 (p_rec in ben_cpo_shd.g_rec_type,
518 p_effective_date in date,
519 p_datetrack_mode in varchar2,
520 p_validation_start_date in date,
521 p_validation_end_date in date) is
522 --
523 l_proc varchar2(72) := g_package||'delete_validate';
524 --
525 Begin
526 hr_utility.set_location('Entering:'||l_proc, 5);
527 --
528 -- Call all supporting business operations
529 --
530 dt_delete_validate
531 (p_datetrack_mode => p_datetrack_mode,
532 p_validation_start_date => p_validation_start_date,
533 p_validation_end_date => p_validation_end_date,
534 p_popl_org_id => p_rec.popl_org_id);
535 --
536 hr_utility.set_location(' Leaving:'||l_proc, 10);
537 End delete_validate;
538 --
539 -- ---------------------------------------------------------------------------
540 -- |---------------------< return_legislation_code >-------------------------|
541 -- ---------------------------------------------------------------------------
542 --
543 function return_legislation_code
544 (p_popl_org_id in number) return varchar2 is
545 --
546 -- Declare cursor
547 --
548 cursor csr_leg_code is
549 select a.legislation_code
550 from per_business_groups a,
551 ben_popl_org_f b
552 where b.popl_org_id = p_popl_org_id
553 and a.business_group_id = b.business_group_id;
554 --
555 -- Declare local variables
556 --
557 l_legislation_code per_business_groups.legislation_code%TYPE; -- UTF8 varchar2(150);
558 l_proc varchar2(72) := g_package||'return_legislation_code';
559 --
560 begin
561 --
562 hr_utility.set_location('Entering:'|| l_proc, 10);
563 --
564 -- Ensure that all the mandatory parameter are not null
565 --
566 hr_api.mandatory_arg_error(p_api_name => l_proc,
567 p_argument => 'popl_org_id',
568 p_argument_value => p_popl_org_id);
569 --
570 open csr_leg_code;
571 --
572 fetch csr_leg_code into l_legislation_code;
573 --
574 if csr_leg_code%notfound then
575 --
576 close csr_leg_code;
577 --
578 -- The primary key is invalid therefore we must error
579 --
580 hr_utility.set_message(801,'HR_7220_INVALID_PRIMARY_KEY');
581 hr_utility.raise_error;
582 --
583 end if;
584 --
585 close csr_leg_code;
586 --
587 hr_utility.set_location(' Leaving:'|| l_proc, 20);
588 --
589 return l_legislation_code;
590 --
591 end return_legislation_code;
592 --
593 end ben_cpo_bus;