DBA Data[Home] [Help]

PACKAGE BODY: APPS.HR_PSF_BUS

Source


1 PACKAGE BODY HR_PSF_BUS as
2 /* $Header: hrpsfrhi.pkb 120.14.12020000.5 2013/04/12 18:20:17 pathota ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  hr_psf_bus.';  -- Global package name
9 --
10 --
11 --
12 --  ---------------------------------------------------------------------------
13 --  |----------------------<  set_security_group_id  >------------------------|
14 --  ---------------------------------------------------------------------------
15 --
16 --
17   procedure set_security_group_id
18    (
19     p_position_id                in hr_positions.position_id%TYPE
20    ) is
21   --
22   -- Declare cursor
23   --
24      cursor csr_sec_grp is
25        select inf.org_information14
26       from hr_organization_information inf
27          , hr_all_positions_f  pos
28      where pos.position_id = p_position_id
29        and inf.organization_id = pos.business_group_id
30        and inf.org_information_context || '' = 'Business Group Information';
31   --
32   -- Local variables
33   --
34   l_security_group_id number;
35   l_proc              varchar2(72) ;
36   --
37   begin
38 g_debug := hr_utility.debug_enabled;
39 if g_debug then
40     l_proc        := g_package||'set_security_group_id';
41     hr_utility.set_location('Entering:'|| l_proc, 10);
42 end if;
43   --
44   -- Ensure that all the mandatory parameter are not null
45   --
46   hr_api.mandatory_arg_error(p_api_name       => l_proc,
47                              p_argument       => 'position_id',
48                              p_argument_value => p_position_id);
49   --
50   open csr_sec_grp;
51   fetch csr_sec_grp into l_security_group_id;
52   if csr_sec_grp%notfound then
53     close csr_sec_grp;
54     --
55     -- The primary key is invalid therefore we must error
56     --
57     hr_utility.set_message(801, 'HR_7220_INVALID_PRIMARY_KEY');
58     hr_utility.raise_error;
59   end if;
60   close csr_sec_grp;
61   --
62   -- Set the security_group_id in CLIENT_INFO
63   --
64   hr_api.set_security_group_id
65     (p_security_group_id => l_security_group_id
66     );
67   --
68 if g_debug then
69   hr_utility.set_location(' Leaving:'|| l_proc, 20);
70 end if;
71   --
72 end set_security_group_id;
73 --
74 --
75 --  ----------------------------------------------------------------------------
76 --  |--------------------------<  get_validation_date  >--------------------|
77 --  ----------------------------------------------------------------------------
78 --
79 --  Desciption :
80 --
81 --  Validates that the position NAME is unique within position's BUSINESS GROUP
82 --
83 --  Pre-conditions :
84 --
85 --  In Arguments :
86 --    p_date_effective
87 --    p_validation_Start_Date
88 --    p_validation_date
89 --
90 --  Post Success :
91 --
92 --  Post Failure :
93 --
94 --  Access Status :
95 --    Internal Table Handler Use only.
96 --
97 -- {End of Comments}
98 --
99 -- ---------------------------------------------------------------------------
100 --
101 Procedure get_validation_date(
102       p_date_effective        in  date
103      ,p_validation_start_date in  date
104      ,p_validation_date       out nocopy date
105 ) is
106 l_proc varchar2(30);
107 
108 Begin
109 if g_debug then
110 l_proc :='get_validation_date';
111   hr_utility.set_location('Entering:'||l_proc, 1);
112 end if;
113   --
114   --   Check mandatory parameters have been set
115   --
116   hr_api.mandatory_arg_error
117     (p_api_name                 => l_proc
118     ,p_argument                 => 'date_effective'
119     ,p_argument_value           => p_date_effective
120     );
121   --
122 if g_debug then
123   hr_utility.set_location(l_proc, 10);
124 end if;
125   --
126   hr_api.mandatory_arg_error
127     (p_api_name                 => l_proc
128     ,p_argument                 => 'validation_start_date'
129     ,p_argument_value           => p_validation_start_date
130     );
131   --
132 if g_debug then
133   hr_utility.set_location(l_proc, 20);
134 end if;
135   --
136   -- If this is the first row then date_effective must be used for validation
137   -- as this is the date a position becomes effective
138   -- for changes in any other row, use validation_start_Date.
139   --
140   if p_date_effective < p_validation_start_date then
141 if g_debug then
142     hr_utility.set_location(l_proc, 30);
143 end if;
144     p_validation_Date := p_validation_start_Date;
145   else
146 if g_debug then
147     hr_utility.set_location(l_proc, 40);
148 end if;
149     p_validation_date := p_date_effective;
150   end if;
151   --
152 if g_debug then
153   hr_utility.set_location(l_proc, 100);
154 end if;
155 --
156 End get_validation_date;
157 --
158 --  ---------------------------------------------------------------------------
159 --  |-----------------------<  chk_end dates >--------------------|
160 --  ---------------------------------------------------------------------------
161 --
162 --  Desciption :
163 --
164 --    Validates that the various end dates compared to the effective date
165 --
166 --  Pre-conditions :
167 --
168 --  In Arguments :
169 --
170 --  Post Success :
171 --
172 --  Post Failure :
173 --
174 --  Access Status :
175 --    Internal Table Handler Use only.
176 --
177 -- {End of Comments}
178 --
179 -- ---------------------------------------------------------------------------
180 --
181 procedure chk_end_dates
182 (
183 position_id                     in number
184 ,availability_status_id         in number
185 ,p_effective_date               in date
186 ,current_org_prop_end_date      in date
187 ,current_job_prop_end_date      in date
188 ,avail_status_prop_end_date     in date
189 ,earliest_hire_date             in date
190 ,fill_by_date                   in date
191 ,proposed_date_for_layoff       in date
192 ,date_effective                 in date)
193 is
194    l_avail_status_start_date  date;
195 begin
196    if current_org_prop_end_date < date_effective then
197       hr_utility.set_message(800,'PER_INVALID_ORG_PROP_END_DATE');
198       hr_utility.raise_error;
199    end if;
200    if current_job_prop_end_date < date_effective then
201       hr_utility.set_message(800,'PER_INVALID_JOB_PROP_END_DATE');
202       hr_utility.raise_error;
203    end if;
204 
205    l_avail_status_start_date := hr_general.DECODE_AVAIL_STATUS_START_DATE (
206                                             position_id
207                                             ,availability_status_id
208                                             ,p_effective_date ) ;
209    if avail_status_prop_end_date < nvl(l_avail_status_start_date,date_effective) then
210       hr_utility.set_message(800,'PER_INVALID_STATUS_PROP_END_DT');
211       hr_utility.raise_error;
212    end if;
213 
214    if earliest_hire_date < date_effective then
215       hr_utility.set_message(800,'PER_INVALID_EARLIEST_HIRE_DATE');
216       hr_utility.raise_error;
217    end if;
218    if fill_by_date < nvl(earliest_hire_date, date_effective) then
219       hr_utility.set_message(800,'PER_INVALID_FILL_BY_DATE');
220       hr_utility.set_message_token('VALID_DATE',nvl(earliest_hire_date, date_effective));
221       hr_utility.raise_error;
222    end if;
223    if proposed_date_for_layoff < date_effective then
224       hr_utility.set_message(800,'PER_INVALID_PROP_DT_FOR_LAYOFF');
225       hr_utility.raise_error;
226    end if;
227 end chk_end_dates;
228 --  ---------------------------------------------------------------------------
229 --  |--------------------------<  chg_date_effective >--------------------|
230 --  ---------------------------------------------------------------------------
231 --
232 --  Desciption :
233 --
234 --  Validates that the date effective is to be changed or not
235 --
236 --  Pre-conditions :
237 --
238 --  In Arguments :
239 --
240 --  Post Success :
241 --
242 --  Post Failure :
243 --
244 --  Access Status :
245 --    Internal Table Handler Use and independent procedure of the package
246 --
247 -- {End of Comments}
248 --
249 -- -------------------------------------------------------------------------
250 --
251 procedure chg_date_effective
252      (p_position_id             in number
253      ,p_effective_start_date    in date
254      ,p_effective_end_date      in date
255      ,p_date_effective          in date
256      ,p_new_date_effective      out nocopy date
257      ,p_chg_date_effective      out nocopy boolean
258      ,p_business_group_id       in number
259      ,p_old_avail_status_id     in number
260      ,p_availability_status_id  in number
261      ,p_datetrack_mode          in varchar2
262       )
263 is
264 -- cursor to check active rows for the position prior to the effective_start_date of their row
265     cursor pos_active_rows(p_position_id number,p_effective_start_date date) is
266        select count(*)
267        from hr_all_positions_f pos, per_shared_types sht
268        where pos.position_id = p_position_id
269        and pos.effective_start_date < p_effective_start_date
270        and hr_psf_shd.get_availability_status(pos.availability_status_id,p_business_group_id) ='ACTIVE';
271 -- cursor to find out the next active row's effective start date
272     cursor next_active_row(p_position_id number,p_effective_start_date date) is
273        select effective_start_date
274        from hr_all_positions_f pos, per_shared_types sht
275        where pos.position_id = p_position_id
276        and pos.effective_start_date > p_effective_start_date
277        and hr_psf_shd.get_availability_status(pos.availability_status_id,p_business_group_id) ='ACTIVE';
278 -- cursor to find the first active row
279     cursor valid_first_active_row(p_position_id number,p_effective_end_date date) is
280        select min(effective_start_date)
281        from hr_all_positions_f pos
282        where effective_start_date > p_effective_end_date + 1
283        and hr_psf_shd.get_availability_status(pos.availability_status_id,p_business_group_id) ='ACTIVE';
284     l_active_rows      number;
285     l_current_row_stat varchar2(30);
286     l_next_active_date date;
287     l_proc             varchar2(72) ;
288     l_effective_date   date;
289     l_date_effective   date;
290 begin
291 
292 g_debug := hr_utility.debug_enabled;
293 if g_debug then
294     l_proc              := g_package||'Chg_date_effective' ;
295    hr_utility.set_location('Entering'||l_proc, 10);
296 end if;
297    p_chg_date_effective := FALSE ;
298 -- call to chk_availability_status_id is made to check wether the status transition is a valid transition or not.
299 -- if it is a valid transition only then control will be coming to the change in date_effective code
300 -- otherwise invalid status change will be displayed
301    chk_availability_status_id(p_position_id            => p_position_id
302                              ,p_business_group_id      => p_business_group_id
303                              ,p_datetrack_mode         => p_datetrack_mode
304                              ,p_validation_start_date  => p_effective_start_date
305                              ,p_availability_status_id => p_availability_status_id
306                              ,p_effective_date         => l_effective_date
307                              ,p_date_effective         => l_date_effective
308                              ,p_old_avail_status_id    => p_old_avail_status_id
309                             );
310    if g_debug then
311    hr_utility.set_location('after chk_avail_stat '||l_proc, 20);
312    end if;
313 -- depending upon the datetrack mode action has to be taken to find out
314 -- the change in date effective
315     if p_datetrack_mode = 'INSERT'
316        or p_datetrack_mode = 'CORRECTION'
317        or p_datetrack_mode = 'UPDATE'
318        or p_datetrack_mode = 'UPDATE_OVERRIDE'
319        or p_datetrack_mode = 'UPDATE_CHANGE_INSERT'
320        then
321 --
322 -- if current row's status is active and there are no active rows
323 -- prior to this row then date effective is to
324 -- be changed to the effective start date of this row.
325 -- no. of active rows in the database for this position prior to
326 -- the effective start date is computed
327 --
328 if g_debug then
329        hr_utility.set_location('inside for action '||p_datetrack_mode||l_proc, 30);
330 end if;
331        open pos_active_rows(p_position_id,p_effective_start_date);
332        fetch pos_active_rows into l_active_rows ;
333        close pos_active_rows ;
334        if l_active_rows = 0 then
335           -- status of the current row is found
336           l_current_row_stat := hr_psf_shd.get_availability_status(p_availability_status_id,p_business_group_id);
337           if l_current_row_stat ='ACTIVE' then
338              -- current row is going to be first active row date effective is to be changed
339              -- to the effective start date of the first active row
340              p_new_date_effective := p_effective_start_date ;
341              p_chg_date_effective := (p_new_date_effective <> p_date_effective);
342           else
343              -- check to find out the effective start date of the first row after current row
344              -- next active row's effective start date is fetched
345              if g_debug then
346              hr_utility.set_location('next row is to be found'||l_proc, 40);
347              end if;
348              open next_active_row(p_position_id,p_effective_start_date);
349              fetch next_active_row into l_next_active_date;
350              if next_active_row%found then
351                 -- there is a active row for this position after the current position
352                 p_new_date_effective := l_next_active_date ;
353                 p_chg_date_effective := (p_new_date_effective <> p_date_effective);
354              end if;
355              close next_active_row;
356           end if;
357        else
358           -- there exists a active row prior to the current row
359           -- date effective is not going to be changed
360           p_chg_date_effective := FALSE ;
361        end if;
362     elsif p_datetrack_mode = 'DELETE_NEXT_CHANGE'  then
363     if g_debug then
364        hr_utility.set_location('inside for action '||p_datetrack_mode||l_proc, 50);
365     end if;
366           if p_date_effective < p_effective_start_date then
367              -- nothing should be done as first active row is not going to be deleted
368              null;
369           else
370              -- status of the current row is found
371              l_current_row_stat := hr_psf_shd.get_availability_status(p_availability_status_id,p_business_group_id);
372              if l_current_row_stat ='ACTIVE' then
373                 -- current row is active row itself, so nothing is to be changed
374                 p_chg_date_effective := FALSE;
375              else
376              if g_debug then
377                 hr_utility.set_location('valid active row searching'||l_proc, 60);
378              end if;
379                 open valid_first_active_row(p_position_id,p_effective_end_date);
380                 fetch valid_first_active_row into l_next_active_date ;
381                 if valid_first_active_row%found then
382                    -- next active row effective start date has been found after deletion of the next row
383                    p_new_date_effective := l_next_active_date ;
384                    p_chg_date_effective := (p_new_date_effective <> p_date_effective);
385                 end if;
386                 close valid_first_active_row ;
387              end if;
388           end if;
389     elsif p_datetrack_mode = 'FUTURE_CHANGE'
390        or p_datetrack_mode = 'ZAP' then  -- 'Purge' as seen on GUI
391           -- nothing is to be done in this case
392           p_chg_date_effective := FALSE ;
393          if g_debug then
394               hr_utility.set_location('inside for action '||p_datetrack_mode||l_proc, 70);
395          end if;
396     end if;
397    hr_utility.set_location('Leaving'||l_proc, 1000);
398 end chg_date_effective ;
399 
400 --  ---------------------------------------------------------------------------
401 --  |-----------------------<  chk_availability_status_id >--------------------|
402 --  ---------------------------------------------------------------------------
403 --
404 --  Desciption :
405 --
406 --    Validates that the availability_status_id exists in PER_SHARED_TYPES
407 --
408 --  Pre-conditions :
409 --
410 --  In Arguments :
411 --
412 --  Post Success :
413 --
414 --  Post Failure :
415 --
416 --  Access Status :
417 --    Internal Table Handler Use only.
418 --
419 -- {End of Comments}
420 --
421 -- ---------------------------------------------------------------------------
422 --
423 procedure chk_availability_status_id
424    (p_position_id            in number
425    ,p_validation_start_date  in date
426    ,p_availability_status_id in number
427    ,p_old_avail_status_id    in number
428    ,p_business_group_id      in number
429    ,p_date_effective         in date default null
430    ,p_effective_date         in date default null
431    ,p_object_version_number  in number default 1
432    ,p_datetrack_mode         in varchar2)
433 is
434    type stat_matrix is record
435         (previous_stat varchar2(30)
436         ,present_stat  varchar2(30)
437         ,future_stat   varchar2(30)) ;
438    TYPE tran_stat IS table of stat_matrix
439              index by binary_integer ;
440    chk_stat  tran_stat;
441    cursor csr_stat(p_position_id number,p_effective_start_date date,p_business_group_id number) is
442       select hr_psf_shd.get_availability_status(pos.availability_status_id,p_business_group_id)
443       from hr_all_positions_f pos
444       where pos.position_id = p_position_id
445       and pos.effective_start_date = p_effective_start_date;
446    cursor csr_prev(p_position_id number, p_effective_start_date date) is
447        select max(effective_start_date)
448        from hr_all_positions_f
449        where position_id = p_position_id
450        and effective_start_date < p_effective_start_date ;
451    cursor csr_future(p_position_id number, p_effective_start_date date) is
452        select min(effective_start_date)
453        from hr_all_positions_f
454        where position_id = p_position_id
455        and effective_start_date > p_effective_start_date ;
456    cursor csr_present(p_position_id number, p_object_version_number number) is
457        select effective_start_date
458        from hr_all_positions_f
459        where position_id = p_position_id
460        and object_version_number = p_object_version_number ;
461    l_present_stat varchar2(30) ;
462    l_prev_stat    varchar2(30);
463    l_future_stat  varchar2(30);
464    l_prev_esd     date ;
465    l_future_esd   date ;
466    l_current_esd  date ;
467    l_proc         varchar2(72) ;
468    l_return       boolean := false ;
469    i              number ;
470    l_count        number ;
471    l_validation_reqd boolean := TRUE ;
472    --
473    procedure set_stat (p_chk_stat     in out nocopy tran_stat
474                     , p_subscript     in     number
475                     , p_prev_stat     in     varchar2
476                     , p_present_stat  in     varchar2
477                     , p_future_stat   in     varchar2) is
478    --
479    begin
480      --
481      p_chk_stat(p_subscript).previous_stat := p_prev_stat ;
482      p_chk_stat(p_subscript).present_stat  := p_present_stat;
483      p_chk_stat(p_subscript).future_stat   := p_future_stat;
484      --
485    end;
486    --
487 begin
488   --
489   g_debug := hr_utility.debug_enabled;
490   --
491   if g_debug then
492     l_proc := g_package||'chk_avail_stat';
493   --
494   end if;
495   --
496   l_present_stat := hr_psf_shd.get_availability_status(p_availability_status_id
497                                                       ,p_business_group_id);
498   --
499   -- populating the status transition matrix
500   --
501       set_stat(chk_stat, 1, NULL, 'PROPOSED', NULL);
502       set_stat(chk_stat, 2, NULL, 'PROPOSED', 'PROPOSED');
503       set_stat(chk_stat, 3, 'PROPOSED', 'PROPOSED', NULL);
504       set_stat(chk_stat, 4, 'PROPOSED', 'PROPOSED', 'PROPOSED');
505       set_stat(chk_stat, 5, 'PROPOSED', 'PROPOSED', 'ACTIVE');
506       set_stat(chk_stat, 6, 'PROPOSED', 'PROPOSED', 'DELETED');
507       set_stat(chk_stat, 7, 'PROPOSED', 'DELETED', 'DELETED');
508       set_stat(chk_stat, 8, 'PROPOSED', 'DELETED', NULL);
509       set_stat(chk_stat, 9, 'PROPOSED', 'ACTIVE', NULL);
510       set_stat(chk_stat, 10, 'DELETED',  'DELETED', 'DELETED');
511       set_stat(chk_stat, 11, 'DELETED',  'DELETED', NULL);
512       set_stat(chk_stat, 12, 'PROPOSED', 'ACTIVE', 'ACTIVE');
513       set_stat(chk_stat, 13, 'ACTIVE', 'ACTIVE', 'ACTIVE');
514       set_stat(chk_stat, 14, 'ACTIVE', 'ACTIVE', NULL);
515       set_stat(chk_stat, 15, NULL, 'ACTIVE', 'ACTIVE');
516       set_stat(chk_stat, 16, NULL, 'ACTIVE', NULL);
517       set_stat(chk_stat, 17, 'ACTIVE', 'ACTIVE', 'FROZEN');
518       set_stat(chk_stat, 18, 'ACTIVE', 'FROZEN', 'FROZEN');
519       set_stat(chk_stat, 19, 'ACTIVE', 'FROZEN', 'ACTIVE');
520       set_stat(chk_stat, 20, 'FROZEN', 'FROZEN', 'FROZEN');
521       set_stat(chk_stat, 21, 'FROZEN', 'FROZEN', 'ACTIVE');
522       set_stat(chk_stat, 22, 'FROZEN', 'ACTIVE', 'ACTIVE');
523       set_stat(chk_stat, 23, 'FROZEN', 'ACTIVE', 'FROZEN');
524       set_stat(chk_stat, 24, 'ACTIVE', 'ACTIVE', 'FROZEN');
525       set_stat(chk_stat, 25, 'ACTIVE', 'FROZEN', 'FROZEN');
526       set_stat(chk_stat, 26, 'ACTIVE', 'ELIMINATED', 'ELIMINATED');
527       set_stat(chk_stat, 27, 'ACTIVE', 'ACTIVE', 'ELIMINATED');
528       set_stat(chk_stat, 28, 'ELIMINATED', 'ELIMINATED', 'ELIMINATED');
529       set_stat(chk_stat, 29, 'FROZEN', 'ELIMINATED', 'ELIMINATED');
530       set_stat(chk_stat, 30, 'FROZEN', 'FROZEN', 'ELIMINATED');
531       set_stat(chk_stat, 31, 'ACTIVE', 'FROZEN', 'ELIMINATED');
532       set_stat(chk_stat, 32, 'FROZEN', 'ACTIVE', 'ELIMINATED');
533       set_stat(chk_stat, 33, 'PROPOSED', 'ACTIVE', 'ELIMINATED');
534       set_stat(chk_stat, 34, 'PROPOSED', 'ACTIVE', 'FROZEN');
535       set_stat(chk_stat, 35, NULL, 'ACTIVE', 'ELIMINATED');
536       set_stat(chk_stat, 36, NULL, 'ACTIVE', 'FROZEN');
537       set_stat(chk_stat, 37, 'ACTIVE', 'FROZEN', NULL);
538       set_stat(chk_stat, 38, 'FROZEN', 'FROZEN', NULL);
539       set_stat(chk_stat, 39, 'ELIMINATED', 'ELIMINATED', NULL);
540       set_stat(chk_stat, 40, 'ACTIVE', 'ELIMINATED', NULL);
541       set_stat(chk_stat, 41, 'FROZEN', 'ELIMINATED', NULL);
542       set_stat(chk_stat, 42, 'FROZEN', 'ACTIVE', NULL);
543       set_stat(chk_stat, 43, NULL, 'PROPOSED', 'ACTIVE');
544       --
545       --set_stat(chk_stat, 44, 'ACTIVE', 'DELETED', NULL); -- Added for bug 2130540
546 
547 --
548 -- status transition matrix is populated depending upon the datetrack mode
549 -- previous and future status will be defined and compared with the matrix
550 -- values.
551     if p_datetrack_mode = 'INSERT' then
552        l_prev_stat := NULL;
553        l_future_stat := NULL ;
554     elsif p_datetrack_mode = 'CORRECTION' then
555        -- old rec value does not matter to us and previous and future
556        -- values are to be fetched from the database
557        open csr_prev(p_position_id,p_validation_start_date) ;
558        fetch csr_prev into l_prev_esd ;
559        close csr_prev ;
560        open csr_future(p_position_id,p_validation_start_date) ;
561        fetch csr_future into l_future_esd ;
562        close csr_future ;
563        -- corresponding to the previous and future records status is fetched
564        -- from the database
565        open csr_stat(p_position_id,l_prev_esd,p_business_group_id) ;
566        fetch csr_stat into l_prev_stat ;
567        close csr_stat ;
568        open csr_stat(p_position_id,l_future_esd,p_business_group_id) ;
569        fetch csr_stat into l_future_stat ;
570        close csr_stat ;
571     elsif p_datetrack_mode = 'UPDATE' or
572           p_datetrack_mode = 'UPDATE_OVERRIDE' then
573        -- old rec values are used for previous status and future stat is
574        -- fetched from the database
575        l_prev_stat := hr_psf_shd.get_availability_status( p_old_avail_status_id,
576                                                           p_business_group_id) ;
577        l_future_stat := NULL ;
578     elsif p_datetrack_mode = 'UPDATE_CHANGE_INSERT' then -- 'INSERT after UPDATE' as seen on GUI
579        -- old rec values are used for previous status and future stat is
580        -- fetched from the database
581        l_prev_stat := hr_psf_shd.get_availability_status( p_old_avail_status_id,
582                                                           p_business_group_id) ;
583 
584        open csr_future(p_position_id,p_validation_start_date) ;
585        fetch csr_future into l_future_esd ;
586        close csr_future ;
587        -- corresponding to the previous and future records status is fetched
588        -- from the database
589        open csr_stat(p_position_id,l_future_esd,p_business_group_id) ;
590        fetch csr_stat into l_future_stat ;
591        close csr_stat ;
592     elsif p_datetrack_mode = 'FUTURE_CHANGE' then -- 'All' as seen on GUI
593        l_validation_reqd := false ;
594     elsif p_datetrack_mode = 'DELETE_NEXT_CHANGE' then  -- 'Next' as seen on GUI
595        -- current row effective start date is used to fetch next rows  as
596        -- validation start date does not have value in this case
597        open csr_present(p_position_id,p_object_version_number) ;
598        fetch csr_present into l_current_esd ;
599        close csr_present ;
600 if g_debug then
601        hr_utility.set_location('current row esd is'||l_current_esd||l_proc,111);
602        hr_utility.set_location('curr, ovn is'||p_object_version_number||l_proc,111);
603 end if;
604 
605        -- old rec value does not matter to us and previous and future
606        -- values are to be fetched from the database
607        open csr_prev(p_position_id,l_current_esd) ;
608        fetch csr_prev into l_prev_esd ;
609        close csr_prev ;
610 
611        -- as next row is getting deleted we have to find out the status of the
612        -- next to next row. That's why there are two calls.
613        open csr_future(p_position_id,l_current_esd) ;
614        fetch csr_future into l_future_esd ;
615        close csr_future ;
616 if g_debug then
617        hr_utility.set_location('deleted row esd is'||l_future_esd||l_proc,111);
618 end if;
619        open csr_future(p_position_id,l_future_esd) ;
620        fetch csr_future into l_future_esd ;
621        close csr_future ;
622 if g_debug then
623        hr_utility.set_location('next row esd is'||l_future_esd||l_proc,111);
624 end if;
625 
626        -- corresponding to the previous and future records status is fetched
627        -- from the database
628        open csr_stat(p_position_id,l_prev_esd,p_business_group_id) ;
629        fetch csr_stat into l_prev_stat ;
630        close csr_stat ;
631        open csr_stat(p_position_id,l_future_esd,p_business_group_id) ;
632        fetch csr_stat into l_future_stat ;
633        close csr_stat ;
634 if g_debug then
635        hr_utility.set_location('next row stat is'||l_future_stat||l_proc,111);
636 end if;
637     elsif p_datetrack_mode = 'ZAP' then  -- 'Purge' as seen on GUI
638        l_validation_reqd := false ;
639     end if;
640 if g_debug then
641     hr_utility.set_location(nvl(l_prev_stat,'NULL')||nvl(l_present_stat,'NULL')||nvl(l_future_stat,'NULL'),100);
642     hr_utility.set_location(p_datetrack_mode||l_proc ,100);
643 end if;
644     if l_validation_reqd = true then
645        l_count := chk_stat.count ;
646        i := 1 ;
647        loop
648          if nvl(chk_stat(i).previous_stat,'ZZZZ') = nvl(l_prev_stat,'ZZZZ')
649            and nvl(chk_stat(i).present_stat,'ZZZZ') = nvl(l_present_stat,'ZZZZ')
650            and nvl(chk_stat(i).future_stat,'ZZZZ') = nvl(l_future_stat,'ZZZZ')
651          then
652            l_return := true ;
653            exit ;
654          else
655            i := i + 1;
656          end if;
657          if i > l_count then
658             exit ;
659          end if;
660        end loop;
661        if l_return <> true then
662           hr_utility.set_message(800,'HR_NOT_VALID_STATUS_CHANGE');
663           hr_utility.raise_error;
664        end if;
665    end if;
666 /*
667 -- code to stop change in availability status to active (Row is going to first active row )
668 -- when date_effective is not equal to effective date
669    if l_present_stat = 'ACTIVE' then
670       if l_prev_stat in ('NULL','PROPOSED') then
671          if p_effective_date <> p_date_effective then
672             -- raise the error
673             hr_utility.set_message(800,'PER_STAT_ACTIVE_DE_ED_ONLY');
674             hr_utility.raise_error;
675          end if;
676       end if;
677    end if;
678 */
679 end chk_availability_status_id;
680 --
681 
682 --  ---------------------------------------------------------------------------
683 --  |-------------------< chk_entry_step_id >-----------------------|
684 --  ---------------------------------------------------------------------------
685 --
686 procedure chk_entry_step_id
687   (p_position_id              in hr_all_positions_f.position_id%TYPE
688   ,p_entry_step_id            in hr_all_positions_f.entry_step_id%TYPE
689   ,p_entry_grade_id           in hr_all_positions_f.entry_grade_id%TYPE
690   ,p_business_group_id        in hr_all_positions_f.business_group_id%TYPE
691   ,p_validation_start_date    in hr_all_positions_f.effective_start_date%TYPE
692   ,p_validation_end_date      in hr_all_positions_f.effective_end_date%TYPE
693   ,p_effective_date           in date
694   ,p_object_version_number    in hr_all_positions_f.object_version_number%TYPE
695   )
696   is
697 --
698    l_sequence           per_spinal_point_steps_f.sequence%TYPE;
699    l_exists            varchar2(1);
700    l_api_updating      boolean;
701    l_business_group_id number(15);
702    l_proc              varchar2(72) ;
703 --
704    cursor csr_valid_step is
705    select  business_group_id
706      from  per_spinal_point_steps_f psps
707      where psps.step_id               = p_entry_step_id
708        and p_validation_start_date between psps.effective_start_date and psps.effective_end_date;
709 --
710    cursor csr_valid_step_grade is
711      select   psps.sequence
712      from     per_grade_spines_f pgs,
713               per_spinal_point_steps_f psps
714      where    psps.step_id       = p_entry_step_id
715        and    pgs.grade_id       = p_entry_grade_id
716        and    pgs.grade_spine_id = psps.grade_spine_id
717        and    p_effective_date between pgs.effective_start_date
718                                    and pgs.effective_end_date
719        and    p_effective_date between psps.effective_start_date
720                                    and psps.effective_end_date;
721 --
722 begin
723 if g_debug then
724   l_proc  := g_package||'chk_entry_step_id';
725   hr_utility.set_location('Entering:'|| l_proc, 10);
726 end if;
727   --
728   -- Check mandatory parameters have been set
729   --
730   hr_api.mandatory_arg_error
731     (p_api_name       => l_proc
732     ,p_argument       => 'validation_start_date'
733     ,p_argument_value => p_validation_start_date
734     );
735   --
736   hr_api.mandatory_arg_error
737     (p_api_name       => l_proc
738     ,p_argument       => 'validation_end_date'
739     ,p_argument_value => p_validation_end_date
740     );
741   --
742   hr_api.mandatory_arg_error
743     (p_api_name       => l_proc
744     ,p_argument       => 'effective_date'
745     ,p_argument_value => p_effective_date
746     );
747   --
748   hr_api.mandatory_arg_error
749     (p_api_name       => l_proc
750     ,p_argument       => 'business_group_id'
751     ,p_argument_value => p_business_group_id
752     );
753   if g_debug then
754             hr_utility.set_location(l_proc, 20);
755   end if;
756   --
757   -- Only proceed with validation if :
758   -- a) The current g_old_rec is current and
759   -- b) The value for special ceiling step has changed
760   --
761   l_api_updating := hr_psf_shd.api_updating
762         (p_position_id          => p_position_id
763         ,p_effective_date         => p_effective_date
764         ,p_object_version_number  => p_object_version_number
765         );
766 if g_debug then
767   hr_utility.set_location(l_proc, 30);
768 end if;
769   --
770   if ((l_api_updating and
771        nvl(hr_psf_shd.g_old_rec.entry_step_id, hr_api.g_number) <>
772        nvl(p_entry_step_id, hr_api.g_number)) or
773       (NOT l_api_updating)) then
774 if g_debug then
775     hr_utility.set_location(l_proc, 40);
776 end if;
777     --
778     if p_entry_step_id is not null then
779     if g_debug then
780       hr_utility.set_location(l_proc, 50);
781     end if;
782       --
783       -- Check that entry_step_id exists and is date effective
784       -- per_grade_spines_f
785       --
786       open csr_valid_step;
787       fetch csr_valid_step into l_business_group_id;
788       if csr_valid_step%notfound then
789         close csr_valid_step;
790         hr_utility.set_message(800, 'HR_ENTRY_STEP_ID_NF');
791         hr_utility.raise_error;
792         --
793       end if;
794       close csr_valid_step;
795       if g_debug then
796         hr_utility.set_location(l_proc, 60);
797       end if;
798       --
799       -- Check that the business group of the entry_step_id on
800       -- per_grade_spines is the same as that of the position.
801       --
802       if l_business_group_id <> p_business_group_id then
803        hr_utility.set_message(800, 'HR_PSF_INV_BG_FOR_ENTRY_STEP');
804         hr_utility.raise_error;
805       end if;
806       if g_debug then
807                 hr_utility.set_location(l_proc, 70);
808       end if;
809       --
810       -- Check that the entry_step_id is valid for the grade
811       -- if p_grade is not null.
812       --
813       if p_entry_grade_id is not null then
814         open csr_valid_step_grade;
815         fetch csr_valid_step_grade into l_sequence;
816         if csr_valid_step_grade%notfound then
817           close csr_valid_step_grade;
818           hr_utility.set_message(800, 'HR_PSF_STEP_INV_FOR_GRADE');
819           hr_utility.raise_error;
820         end if;
821         close csr_valid_step_grade;
822         if g_debug then
823           hr_utility.set_location(l_proc, 80);
824         end if;
825       else
826         --
827         -- If the value for step is not null
828         -- then grade id must also be not null
829         --
830         hr_utility.set_message(800, 'HR_PSF_GRADE_REQUIRED');
831         hr_utility.raise_error;
832       end if;
833       if g_debug then
834       hr_utility.set_location(l_proc, 90);
835       end if;
836       --
837     end if;
838     if g_debug then
839     hr_utility.set_location(l_proc, 130);
840     end if;
841     --
842   end if;
843   --
844   hr_utility.set_location(' Leaving:'|| l_proc, 140);
845 end chk_entry_step_id;
846 --
847 --
848 --
849 --  ---------------------------------------------------------------------------
850 --  |---------------------------< chk_entry_grade_id >------------------------------|
851 --  ---------------------------------------------------------------------------
852 --
853 procedure chk_entry_grade_id
854   (p_position_id              in     hr_all_positions_f.position_id%TYPE
855   ,p_business_group_id        in     hr_all_positions_f.business_group_id%TYPE
856   ,p_entry_grade_id           in     hr_all_positions_f.entry_grade_id%TYPE
857   ,p_effective_date           in     date
858   ,p_validation_start_date    in     hr_all_positions_f.effective_start_date%TYPE
859   ,p_validation_end_date      in     hr_all_positions_f.effective_end_date%TYPE
860   ,p_object_version_number    in     hr_all_positions_f.object_version_number%TYPE
861   )
862   is
863 --
864   l_exists             varchar2(1);
865   l_api_updating       boolean;
866   l_business_group_id  number(15);
867   l_proc               varchar2(72);
868   l_vac_grade_id       hr_all_positions_f.entry_grade_id%TYPE;
869   --
870   cursor csr_valid_grade is
871     select   business_group_id
872     from     per_grades
873     where    grade_id = p_entry_grade_id
874     and      p_validation_start_date
875       between date_from and nvl(date_to, hr_api.g_eot);
876   --
877 begin
878 if g_debug then
879  l_proc  :=    g_package||'chk_entry_grade_id';
880   hr_utility.set_location('Entering:'|| l_proc, 10);
881 end if;
882 
883   --
884   -- Check mandatory parameters have been set
885   --
886   hr_api.mandatory_arg_error
887     (p_api_name       => l_proc
888     ,p_argument       => 'effective_date'
889     ,p_argument_value => p_effective_date
890     );
891   --
892   hr_api.mandatory_arg_error
893     (p_api_name       => l_proc
894     ,p_argument       => 'validation_start_date'
895     ,p_argument_value => p_validation_start_date
896     );
897   --
898   hr_api.mandatory_arg_error
899     (p_api_name       => l_proc
900     ,p_argument       => 'validation_end_date'
901     ,p_argument_value => p_validation_end_date
902     );
903   --
904   hr_api.mandatory_arg_error
905     (p_api_name       => l_proc
906     ,p_argument       => 'business_group_id'
907     ,p_argument_value => p_business_group_id
908     );
909   if g_debug then
910   hr_utility.set_location(l_proc, 20);
911  end if;
912   --
913   -- Only proceed with validation if :
914   -- a) The current  g_old_rec is current and
915   -- b) The value for grade has changed
916   --
917   l_api_updating := hr_psf_shd.api_updating
918         (p_position_id            => p_position_id
919         ,p_effective_date         => p_effective_date
920         ,p_object_version_number  => p_object_version_number
921         );
922   if g_debug then
923   hr_utility.set_location(l_proc, 30);
924   end if;
925   --
926   if ((l_api_updating and
927        nvl(hr_psf_shd.g_old_rec.entry_grade_id, hr_api.g_number) <>
928        nvl(p_entry_grade_id, hr_api.g_number)) or
929       (NOT l_api_updating)) then
930    if g_debug then
931    hr_utility.set_location(l_proc, 40);
932    end if;
933    --
934    -- Check if the grade is set.
935    --
936    if p_entry_grade_id is not null then
937      --
938      -- Check that the grade exists between date from and date to in
939      -- PER_GRADES.
940      --
941      open csr_valid_grade;
942      fetch csr_valid_grade into l_business_group_id;
943      if csr_valid_grade%notfound then
944        close csr_valid_grade;
945        hr_utility.set_message(800, 'HR_PSF_INVALID_GRADE');
946        hr_utility.raise_error;
947        --
948      end if;
949      close csr_valid_grade;
950    if g_debug then
951      hr_utility.set_location(l_proc, 50);
952    end if;
953      --
954      -- Check that the business group for the grade is the same
955      -- as that of the position
956      --
957      if l_business_group_id <> p_business_group_id then
958        --
959        hr_utility.set_message(800, 'HR_PSF_INVALID_BG_GRADE');
960        hr_utility.raise_error;
961        --
962      end if;
963      if g_debug then
964      hr_utility.set_location(l_proc, 60);
965      end if;
966      --
967    end if;
968    if g_debug then
969    hr_utility.set_location(l_proc, 80);
970    end if;
971    --
972   end if;
973   if g_debug then
974   hr_utility.set_location(' Leaving:'|| l_proc, 110);
975   end if;
976   --
977 end chk_entry_grade_id;
978 --
979 --  ---------------------------------------------------------------------------
980 --  |---------------------------< chk_entry_grade_rule_id >------------------------------|
981 --  ---------------------------------------------------------------------------
982 --
983 procedure chk_entry_grade_rule_id
984   (p_position_id              in     hr_all_positions_f.position_id%TYPE
985   ,p_business_group_id        in     hr_all_positions_f.business_group_id%TYPE
986   ,p_entry_grade_rule_id           in     hr_all_positions_f.entry_grade_rule_id%TYPE
987   ,p_effective_date           in     date
988   ,p_validation_start_date    in     hr_all_positions_f.effective_start_date%TYPE
989   ,p_validation_end_date      in     hr_all_positions_f.effective_end_date%TYPE
990   ,p_object_version_number    in     hr_all_positions_f.object_version_number%TYPE
991   )
992   is
993 --
994   l_exists             varchar2(1);
995   l_api_updating       boolean;
996   l_business_group_id  number(15);
997   l_proc               varchar2(72) ;
998   l_entry_grade_rule_id       hr_all_positions_f.entry_grade_rule_id%TYPE;
999   --
1000   cursor csr_valid_grade_rule is
1001     select   business_group_id
1002     from     pay_grade_rules_f
1003     where    grade_rule_id = p_entry_grade_rule_id
1004     and      p_validation_start_date
1005       between effective_start_date and effective_end_date;
1006   --
1007 begin
1008 if g_debug then
1009  l_proc  :=  g_package||'chk_entry_grade_rule_id';
1010   hr_utility.set_location('Entering:'|| l_proc, 10);
1011 end if;
1012 
1013   --
1014   -- Check mandatory parameters have been set
1015   --
1016   hr_api.mandatory_arg_error
1017     (p_api_name       => l_proc
1018     ,p_argument       => 'effective_date'
1019     ,p_argument_value => p_effective_date
1020     );
1021   --
1022   hr_api.mandatory_arg_error
1023     (p_api_name       => l_proc
1024     ,p_argument       => 'validation_start_date'
1025     ,p_argument_value => p_validation_start_date
1026     );
1027   --
1028   hr_api.mandatory_arg_error
1029     (p_api_name       => l_proc
1030     ,p_argument       => 'validation_end_date'
1031     ,p_argument_value => p_validation_end_date
1032     );
1033   --
1034   hr_api.mandatory_arg_error
1035     (p_api_name       => l_proc
1036     ,p_argument       => 'business_group_id'
1037     ,p_argument_value => p_business_group_id
1038     );
1039     if g_debug then
1040   hr_utility.set_location(l_proc, 20);
1041   end if;
1042   --
1043   -- Only proceed with validation if :
1044   -- a) The current  g_old_rec is current and
1045   -- b) The value for grade has changed
1046   --
1047   l_api_updating := hr_psf_shd.api_updating
1048         (p_position_id            => p_position_id
1049         ,p_effective_date         => p_effective_date
1050         ,p_object_version_number  => p_object_version_number
1051         );
1052   if g_debug then
1053   hr_utility.set_location(l_proc, 30);
1054   end if;
1055   --
1056   if ((l_api_updating and
1057        nvl(hr_psf_shd.g_old_rec.entry_grade_rule_id, hr_api.g_number) <>
1058        nvl(p_entry_grade_rule_id, hr_api.g_number)) or
1059       (NOT l_api_updating)) then
1060    if g_debug then
1061    hr_utility.set_location(l_proc, 40);
1062    end if;
1063    --
1064    -- Check if the grade is set.
1065    --
1066    if p_entry_grade_rule_id is not null then
1067      --
1068      -- Check that the grade exists between date from and date to in
1069      -- PER_GRADES.
1070      --
1071      open csr_valid_grade_rule;
1072      fetch csr_valid_grade_rule into l_business_group_id;
1073      if csr_valid_grade_rule%notfound then
1074        close csr_valid_grade_rule;
1075        hr_utility.set_message(800, 'HR_PSF_INVALID_GRADE_RULE');
1076        hr_utility.raise_error;
1077        --
1078      end if;
1079      close csr_valid_grade_rule;
1080      if g_debug then
1081      hr_utility.set_location(l_proc, 50);
1082      end if;
1083      --
1084      -- Check that the business group for the grade rule is the same
1085      -- as that of the position
1086      --
1087      if l_business_group_id <> p_business_group_id then
1088        --
1089        hr_utility.set_message(800, 'HR_PSF_INVALID_BG_GRADE_RULE');
1090        hr_utility.raise_error;
1091        --
1092      end if;
1093      hr_utility.set_location(l_proc, 60);
1094      --
1095    end if;
1096    hr_utility.set_location(l_proc, 80);
1097    --
1098   end if;
1099   if g_debug then
1100   hr_utility.set_location(' Leaving:'|| l_proc, 110);
1101   end if;
1102   --
1103 end chk_entry_grade_rule_id;
1104 --
1105 --
1106 --
1107 --  ---------------------------------------------------------------------------
1108 --  |------------------------< chk_pay_freq_payroll_id >-------------------------------|
1109 --  ---------------------------------------------------------------------------
1110 --
1111 procedure chk_pay_freq_payroll_id
1112   (p_position_id           in hr_all_positions_f.position_id%TYPE
1113   ,p_business_group_id     in hr_all_positions_f.business_group_id%TYPE
1114   ,p_pay_freq_payroll_id   in hr_all_positions_f.pay_freq_payroll_id%TYPE
1115   ,p_validation_start_date in hr_all_positions_f.effective_start_date%TYPE
1116   ,p_validation_end_date   in hr_all_positions_f.effective_end_date%TYPE
1117   ,p_effective_date        in date
1118   ,p_datetrack_mode        in varchar2
1119   ,p_object_version_number in hr_all_positions_f.object_version_number%TYPE
1120   )
1121   is
1122   --
1123   l_api_updating                 boolean;
1124   l_cur_opu_effective_start_date date;
1125   l_cur_opu_effective_end_date   date;
1126   l_business_group_id            number(15);
1127   l_exists                       varchar2(1);
1128   l_future_change                boolean;
1129   l_invalid_ppm                  boolean;
1130   l_min_opu_effective_start_date date;
1131   l_min_ppm_effective_start_date date;
1132   l_max_opu_effective_end_date   date;
1133   l_max_ppm_effective_end_date   date;
1134   l_org_payment_method_id
1135                       pay_personal_payment_methods_f.org_payment_method_id%TYPE;
1136   l_org_pay_method_usage_id
1137                        pay_org_pay_method_usages_f.org_pay_method_usage_id%TYPE;
1138   l_personal_payment_method_id
1139                  pay_personal_payment_methods_f.personal_payment_method_id%TYPE;
1140   l_proc                         varchar2(72);
1141   l_working_start_date           date;
1142   l_working_end_date             date;
1143   --
1144   cursor csr_payroll_exists is
1145     select business_group_id
1146     from pay_payrolls_f pp
1147     where pp.payroll_id = p_pay_freq_payroll_id and
1148           p_validation_start_date between pp.effective_start_date and pp.effective_end_date ;
1149 --
1150 begin
1151 if g_debug then
1152 l_proc  :=  g_package||'chk_pay_freq_payroll_id';
1153   hr_utility.set_location('Entering:'|| l_proc, 10);
1154 end if;
1155   --
1156   -- Check mandatory parameters have been set
1157   --
1158   hr_api.mandatory_arg_error
1159     (p_api_name       => l_proc
1160     ,p_argument       => 'business_group_id'
1161     ,p_argument_value => p_business_group_id
1162     );
1163   --
1164   hr_api.mandatory_arg_error
1165     (p_api_name       => l_proc
1166     ,p_argument       => 'validation_start_date'
1167     ,p_argument_value => p_validation_start_date
1168     );
1169   --
1170   hr_api.mandatory_arg_error
1171     (p_api_name       => l_proc
1172     ,p_argument       => 'effective_date'
1173     ,p_argument_value => p_effective_date
1174     );
1175   --
1176   hr_api.mandatory_arg_error
1177     (p_api_name       => l_proc
1178     ,p_argument       => 'validation_end_date'
1179     ,p_argument_value => p_validation_end_date
1180     );
1181 if g_debug then
1182   hr_utility.set_location(l_proc, 20);
1183 end if;
1184   --
1185   l_api_updating := hr_psf_shd.api_updating
1186          (p_position_id          => p_position_id
1187          ,p_effective_date         => p_effective_date
1188          ,p_object_version_number  => p_object_version_number
1189          );
1190 if g_debug then
1191   hr_utility.set_location(l_proc, 30);
1192 end if;
1193   --
1194   if (l_api_updating and
1195        (nvl(hr_psf_shd.g_old_rec.pay_freq_payroll_id, hr_api.g_number)
1196          <> nvl(p_pay_freq_payroll_id, hr_api.g_number))
1197      )
1198     or  NOT l_api_updating
1199   then
1200 if g_debug then
1201     hr_utility.set_location(l_proc, 40);
1202 end if;
1203     --
1204     if p_pay_freq_payroll_id is not null then
1205       --
1206       -- Check that payroll exists and the effective start date of the
1207       -- position is the same as or after the effective start date
1208       -- of the payroll. Also the effective end date of the assignment
1209       -- is the same as or before the effective end date of the payroll.
1210       --
1211       open csr_payroll_exists;
1212       fetch csr_payroll_exists into l_business_group_id;
1213       if csr_payroll_exists%notfound then
1214         close csr_payroll_exists;
1215         hr_utility.set_message(800, 'HR_PSF_PAYROLL_NF');
1216         hr_utility.raise_error;
1217       end if;
1218       close csr_payroll_exists;
1219 if g_debug then
1220       hr_utility.set_location(l_proc, 60);
1221 end if;
1222       --
1223       -- Check that business group of payroll is the
1224       -- same as that of the position
1225       --
1226       if l_business_group_id <> p_business_group_id then
1227         hr_utility.set_message(800, 'HR_PSF_INVALID_BG_PAYROLL');
1228         hr_utility.raise_error;
1229       end if;
1230 if g_debug then
1231       hr_utility.set_location(l_proc, 70);
1232 end if;
1233     end if;
1234   end if;
1235   --
1236 if g_debug then
1237   hr_utility.set_location(' Leaving:'|| l_proc, 300);
1238 end if;
1239 end chk_pay_freq_payroll_id;
1240 --
1241 --  ----------------------------------------------------------------------------
1242 --  |--------------------------<  chk_ccid_unique_for_BG  >--------------------|
1243 --  ----------------------------------------------------------------------------
1244 --
1245 --  PMFLETCH - New uniqueness validation routine
1246 --
1247 --  Desciption :
1248 --
1249 --    Validates that the POSITION_DEFINITION_ID is unique within a
1250 --    position's BUSINESS GROUP
1251 --
1252 --  Pre-conditions :
1253 --
1254 --  In Arguments :
1255 --    p_business_group_id
1256 --    p_position_id
1257 --    p_position_definition_id
1258 --    p_validation_start_date
1259 --    p_validation_end_date
1260 --    p_effective_date
1261 --    p_object_version_number
1262 --
1263 --  Post Success :
1264 --    If the POSITION_DEFINITION_ID in HR_ALL_POSITIONS_F table does not exist
1265 --    for given BUSINESS_GROUP_ID then processing continues
1266 --
1267 --  Post Failure :
1268 --    If the POSITION_DEFINITION_ID does exist in HR_ALL_POSITIONS_F table for given
1269 --    BUSINESS_GROUP_ID, then an application error will be raised and processing
1270 --    terminated
1271 --
1272 --  Access Status :
1273 --    Internal Table Handler Use only.
1274 --
1275 -- {End of Comments}
1276 --
1277 -- ---------------------------------------------------------------------------
1278 --
1279 procedure chk_ccid_unique_for_BG
1280   (p_business_group_id             in      number
1281   ,p_position_id                   in      number
1282   ,p_position_definition_id        in      number
1283   ,p_validation_start_date         in      date
1284   ,p_validation_end_date           in      date
1285   ,p_effective_date                in      date
1286   ,p_object_version_number         in      number
1287   )  is
1288 --
1289    l_api_updating                  boolean;
1290    l_exists                        varchar2(1);
1291    l_proc                          varchar2(72) ;
1292 --
1293   -- Check there are no records in this business group that have the same
1294   -- position definition id within the validation date range - except for
1295   -- the current position
1296    cursor csr_ccid_unique is
1297      select 'x'
1298        from hr_all_positions_f psf
1299       where psf.position_id <> nvl(p_position_id, -1)
1300         and psf.business_group_id = p_business_group_id
1301         and psf.position_definition_id = p_position_definition_id
1302         and psf.effective_start_date <= p_validation_end_date
1303         and psf.effective_end_date   >= p_validation_start_date;
1304 --
1305 begin
1306   if g_debug then
1307      l_proc :=      g_package||'chk_ccid_unique_for_BG';
1308     hr_utility.set_location('Entering:'||l_proc, 10);
1309     hr_utility.set_location('p_business_group_id:'||p_business_group_id, 10);
1310     hr_utility.set_location('p_position_id:'||p_position_id, 10);
1311     hr_utility.set_location('p_position_definition_id:'||p_position_definition_id, 10);
1312     hr_utility.set_location('p_validation_start_date:'||p_validation_start_date, 10);
1313     hr_utility.set_location('p_validation_end_date:'||p_validation_end_date, 10);
1314     hr_utility.set_location('p_effective_date:'||p_effective_date, 10);
1315     hr_utility.set_location('p_object_version_number:'||p_object_version_number, 10);
1316   end if;
1317   --
1318   --   Check mandatory parameters have been set
1319   --
1320   hr_api.mandatory_arg_error
1321     (p_api_name                 => l_proc
1322     ,p_argument                 => 'business_group_id'
1323     ,p_argument_value           => p_business_group_id
1324     );
1325   if g_debug then
1326     hr_utility.set_location(l_proc, 20);
1327   end if;
1328   --
1329   hr_api.mandatory_arg_error
1330     (p_api_name                 => l_proc
1331     ,p_argument                 => 'position_definition_id'
1332     ,p_argument_value           => p_position_definition_id
1333     );
1334   if g_debug then
1335     hr_utility.set_location(l_proc, 30);
1336   end if;
1337   --
1338   hr_api.mandatory_arg_error
1339     (p_api_name                 => l_proc
1340     ,p_argument                 => 'validation_start_date'
1341     ,p_argument_value           => p_validation_start_date
1342     );
1343   if g_debug then
1344     hr_utility.set_location(l_proc, 40);
1345   end if;
1346   --
1347   hr_api.mandatory_arg_error
1348     (p_api_name                 => l_proc
1349     ,p_argument                 => 'validation_end_date'
1350     ,p_argument_value           => p_validation_end_date
1351     );
1352   if g_debug then
1353     hr_utility.set_location(l_proc, 50);
1354   end if;
1355   --
1356   hr_api.mandatory_arg_error
1357     (p_api_name                 => l_proc
1358     ,p_argument                 => 'effective_date'
1359     ,p_argument_value           => p_effective_date
1360     );
1361   if g_debug then
1362     hr_utility.set_location(l_proc, 60);
1363   end if;
1364   --
1365   l_api_updating := hr_psf_shd.api_updating
1366          (p_position_id          => p_position_id
1367          ,p_effective_date         => p_effective_date
1368          ,p_object_version_number  => p_object_version_number
1369          );
1370   if g_debug then
1371     hr_utility.set_location(l_proc, 70);
1372   end if;
1373   --
1374   if (l_api_updating and
1375        (nvl(hr_psf_shd.g_old_rec.position_definition_id, hr_api.g_number)
1376          <> nvl(p_position_definition_id, hr_api.g_number))
1377      )
1378     or  NOT l_api_updating
1379   then
1380     if g_debug then
1381       hr_utility.set_location(l_proc, 80);
1382     end if;
1383     --
1384     --    Check for unique ccid
1385     --
1386     open csr_ccid_unique;
1387     fetch csr_ccid_unique into l_exists;
1388     if csr_ccid_unique%found then
1389       close csr_ccid_unique;
1390       hr_utility.set_message(800,'PAY_7688_USER_POS_TAB_UNIQUE');
1391       hr_utility.raise_error;
1392     else
1393       close csr_ccid_unique;
1394       if g_debug then
1395         hr_utility.set_location(l_proc, 90);
1396       end if;
1397     end if;
1398   --
1399   end if;
1400   --
1401   if g_debug then
1402     hr_utility.set_location(' Leaving:'||l_proc, 100);
1403   end if;
1404 --
1405 end chk_ccid_unique_for_BG;
1406 --
1407 --
1408 --  ----------------------------------------------------------------------------
1409 --  |--------------------------<  chk_name_unique_for_BG  >--------------------|
1410 --  ----------------------------------------------------------------------------
1411 --
1412 --  Desciption :
1413 --
1414 --    Validates that the position NAME is unique within position's BUSINESS GROUP
1415 --
1416 --  Pre-conditions :
1417 --
1418 --  In Arguments :
1419 --    p_business_group_id
1420 --    p_position_id
1421 --    p_name
1422 --    p_effective_date
1423 --
1424 --  Post Success :
1425 --    If the NAME in HR_ALL_POSITIONS table does not exist for given BUSINESS_GROUP_ID
1426 --    then processing continues
1427 --
1428 --  Post Failure :
1429 --    If the NAME does exist in PER_POSITIONS table for given BUSINESS_GROUP_ID,
1430 --    then an application error will be raised and processing terminated
1431 --
1432 --  Access Status :
1433 --    Internal Table Handler Use only.
1434 --
1435 -- {End of Comments}
1436 --
1437 -- ---------------------------------------------------------------------------
1438 --
1439 procedure chk_name_unique_for_BG
1440   (p_business_group_id  in      number
1441   ,p_position_id        in      number
1442   ,p_effective_date     in      date
1443   ,p_name               in      varchar2
1444   ,p_object_version_number in number
1445   )  is
1446 --
1447    l_api_updating                 boolean;
1448    l_exists             varchar2(1);
1449    l_proc               varchar2(72) ;
1450 --
1451    cursor csr_name_unique is
1452       select  'x'
1453         from  hr_all_positions_f psf
1454        where  psf.name = p_name
1455          and  (p_position_id is null or psf.position_id <> p_position_id)
1456          and  psf.business_group_id = p_business_group_id;
1457 --
1458 --
1459 Begin
1460 if g_debug then
1461    l_proc :=      g_package||'chk_name_unique_for_BG';
1462   hr_utility.set_location('Entering:'||l_proc, 1);
1463 end if;
1464   --
1465   --   Check mandatory parameters have been set
1466   --
1467   hr_api.mandatory_arg_error
1468     (p_api_name                 => l_proc
1469     ,p_argument                 => 'business_group_id'
1470     ,p_argument_value           => p_business_group_id
1471     );
1472 if g_debug then
1473   hr_utility.set_location(l_proc, 2);
1474 end if;
1475   --
1476   hr_api.mandatory_arg_error
1477     (p_api_name                 => l_proc
1478     ,p_argument                 => 'name'
1479     ,p_argument_value           => p_name
1480     );
1481 if g_debug then
1482   hr_utility.set_location(l_proc, 3);
1483 end if;
1484   --
1485   hr_api.mandatory_arg_error
1486     (p_api_name                 => l_proc
1487     ,p_argument                 => 'effective_date'
1488     ,p_argument_value           => p_effective_date
1489     );
1490 if g_debug then
1491   hr_utility.set_location(l_proc, 20);
1492 end if;
1493   --
1494   l_api_updating := hr_psf_shd.api_updating
1495          (p_position_id          => p_position_id
1496          ,p_effective_date         => p_effective_date
1497          ,p_object_version_number  => p_object_version_number
1498          );
1499 if g_debug then
1500   hr_utility.set_location(l_proc, 30);
1501 end if;
1502   --
1503   if (l_api_updating and
1504        (nvl(hr_psf_shd.g_old_rec.name, hr_api.g_varchar2)
1505          <> nvl(p_name, hr_api.g_varchar2))
1506      )
1507     or  NOT l_api_updating
1508   then
1509 if g_debug then
1510     hr_utility.set_location(l_proc, 40);
1511 end if;
1512     --
1513     --    Check for unique name
1514     --
1515     open csr_name_unique;
1516     fetch csr_name_unique into l_exists;
1517     if csr_name_unique%found then
1518       close csr_name_unique;
1519       hr_utility.set_message(800,'PAY_7688_USER_POS_TAB_UNIQUE');
1520       hr_utility.raise_error;
1521     else
1522       close csr_name_unique;
1523     end if;
1524   --
1525   end if;
1526   --
1527 if g_debug then
1528   hr_utility.set_location(' Leaving:'||l_proc, 100);
1529 end if;
1530 end chk_name_unique_for_BG;
1531 --
1532 --
1533 -- End insert/update/delete_validate
1534 --
1535 --
1536 --  ---------------------------------------------------------------------------
1537 --  |-------------------------<  chk_hrs_frequency  >-------------------------|
1538 --  ---------------------------------------------------------------------------
1539 --
1540 --  Desciption :
1541 --
1542 --    Validate that if the values for WORKING_HOURS and FREQUENCY are null that
1543 --    the values are defaulted from HR_ORGANIZATION_UNITS for the position's
1544 --    ORGANIZATION_ID. When organization defaults are not maintained, the
1545 --    default values from the business group are used.
1546 --
1547 --    Validate that if FREQUENCY is null and WORKING_HOURS is not null
1548 --    or if WORKING_HOURS is null and FREQUENCY is not null an error
1549 --    is raised
1550 --
1551 --    Validate the FREQUENCY value against the table
1552 --    FND_COMMON_LOOKUPS where the LOOKUP_TYPE is 'FREQUENCY'. (I,U)
1553 --
1554 --    Validate that if the value for WORKING_HOURS is NOT NULL,
1555 --    that the FREQUENCY value is valid for the WORKING_HOURS value.
1556 --
1557 --
1558 --  Pre-conditions:
1559 --    None
1560 --
1561 --  In Arguments :
1562 --    p_business_group_id
1563 --    p_organization_id
1564 --    p_position_id
1565 --    p_working_hours
1566 --    p_frequency
1567 --    p_effective_date
1568 --    p_object_version_number
1569 --
1570 --  Post Success :
1571 --    If the above business rules are satisfied, processing continues
1572 --
1573 --  Post Failure :
1574 --    If the above business rules are violated, an application error
1575 --    is raised and processing terminates
1576 --
1577 --  Access Status :
1578 --    Internal Table Handler Use only.
1579 --
1580 -- {End of Comments}
1581 --
1582 -- ---------------------------------------------------------------------------
1583 procedure chk_hrs_frequency
1584   (p_position_id        in number default null
1585   ,p_working_hours         in number
1586   ,p_effective_date        in date
1587   ,p_frequency             in varchar2
1588   ,p_object_version_number in number default null)    is
1589 --
1590    l_proc   varchar2(72);
1591    l_exists          varchar2(1);
1592    l_working_hours    number;
1593    l_frequency        varchar2(30);
1594    l_api_updating     boolean;
1595 --
1596    cursor csr_valid_freq is
1597      select 'x'
1598      from fnd_common_lookups
1599      where lookup_type = 'FREQUENCY'
1600      and lookup_code = p_frequency
1601      and enabled_flag = 'Y'
1602      and p_effective_date between nvl(start_date_active,p_effective_date)
1603        and nvl(end_date_active,p_effective_date);
1604 --
1605 begin
1606 if g_debug then
1607    l_proc   := g_package||'chk_hrs_frequency';
1608   hr_utility.set_location('Entering:'||l_proc, 1);
1609 end if;
1610   --
1611   -- Only proceed with validation if :
1612   -- a) The current g_old_rec is current and
1613   -- b) The working hours value has changed or
1614   -- c) The frequency value has changed
1615   --
1616 --
1617   l_api_updating := hr_psf_shd.api_updating
1618     (p_position_id        => p_position_id
1619     ,p_effective_date        => p_effective_date
1620     ,p_object_version_number => p_object_version_number);
1621   --
1622   if ((l_api_updating and
1623       (nvl(hr_psf_shd.g_old_rec.working_hours,hr_api.g_number) <>
1624       nvl(p_working_hours,hr_api.g_number) or
1625       (nvl(hr_psf_shd.g_old_rec.frequency,hr_api.g_varchar2) <>
1626       nvl(p_frequency,hr_api.g_varchar2)))) or
1627       (NOT l_api_updating)) then
1628       --
1629       --    Check for values consistency
1630       --
1631 if g_debug then
1632       hr_utility.set_location(l_proc, 5);
1633 end if;
1634       --
1635     if ((p_working_hours is null and p_frequency is not null) or
1636       (p_working_hours is not null and p_frequency is null)) then
1637        hr_utility.set_message(800,'PER_52981_POS_WORK_FREQ_NULL');
1638        hr_utility.raise_error;
1639     end if;
1640       --
1641       --    Check for valid frequency against fnd_common_lookups
1642       --
1643 if g_debug then
1644     hr_utility.set_location(l_proc, 6);
1645 end if;
1646       --
1647 if p_frequency is not null then
1648 
1649     open csr_valid_freq;
1650     fetch csr_valid_freq into l_exists;
1651     if csr_valid_freq%notfound then
1652       hr_utility.set_message(800,'HR_51363_POS_INVAL_FREQUENCY');
1653       hr_utility.raise_error;
1654     end if;
1655       --
1656       --    Validate combinations of working_hours and frequency
1657       --
1658 if g_debug then
1659     hr_utility.set_location(l_proc, 7);
1660 end if;
1661       --
1662     if ((p_working_hours > 24 AND p_frequency = 'D') or
1663        ((p_working_hours > 168)
1664         and (p_frequency = 'W')) or
1665        ((p_working_hours > 744)
1666         and (p_frequency = 'M')) or
1667        ((p_working_hours > 8784)
1668         and (p_frequency = 'Y'))) then
1669        hr_utility.set_message(800,'HR_POS_2_MANY_HOURS');
1670        hr_utility.raise_error;
1671     end if;
1672     --
1673   end if;
1674 --
1675 end if;
1676 if g_debug then
1677 hr_utility.set_location(' Leaving:'||l_proc, 8);
1678 end if;
1679 end chk_hrs_frequency;
1680 --
1681 --
1682 --  ---------------------------------------------------------------------------
1683 --  |------------------------< chk_pay_basis_id >-------------------------------|
1684 --  ---------------------------------------------------------------------------
1685 --
1686 procedure chk_pay_basis_id
1687   (p_position_id           in hr_all_positions_f.position_id%TYPE
1688   ,p_business_group_id     in hr_all_positions_f.business_group_id%TYPE
1689   ,p_pay_basis_id          in hr_all_positions_f.pay_basis_id%TYPE
1690   ,p_validation_start_date in hr_all_positions_f.effective_start_date%TYPE
1691   ,p_validation_end_date   in hr_all_positions_f.effective_end_date%TYPE
1692   ,p_effective_date        in date
1693   ,p_datetrack_mode        in varchar2
1694   ,p_object_version_number in hr_all_positions_f.object_version_number%TYPE
1695   )
1696   is
1697   --
1698   cursor c1 is
1699   select 'x'
1700   from per_pay_bases
1701   where pay_basis_id = p_pay_basis_id and
1702         business_group_id = p_business_group_id;
1703   --
1704   -- Declare local variables
1705   --
1706   l_proc              varchar2(72);
1707   l_exists            varchar2(1);
1708 begin
1709 if g_debug then
1710   l_proc              :=  g_package||'chk_pay_basis_id';
1711   hr_utility.set_location('Entering:'|| l_proc, 10);
1712 end if;
1713   --
1714   -- Ensure that all the mandatory parameter are not null
1715   --
1716   hr_api.mandatory_arg_error(p_api_name       => l_proc,
1717                              p_argument       => 'position_id',
1718                              p_argument_value => p_position_id);
1719   --
1720 if g_debug then
1721   hr_utility.set_location('Entering : ' || l_proc, 10);
1722 end if;
1723   hr_api.mandatory_arg_error(p_api_name       => l_proc,
1724                              p_argument       => 'position_id',
1725                              p_argument_value => p_position_id);
1726   --
1727   hr_api.mandatory_arg_error(p_api_name       => l_proc,
1728                              p_argument       => 'business_group_id',
1729                              p_argument_value => p_business_group_id);
1730   --
1731   hr_api.mandatory_arg_error(p_api_name       => l_proc,
1732                              p_argument       => 'validation_start_date',
1733                              p_argument_value => p_validation_start_date);
1734   --
1735   open c1;
1736   fetch c1 into l_exists;
1737   if c1%notfound then
1738     --
1739       close c1;
1740       hr_utility.set_message(800,'HR_PSF_INVALID_PAY_BASIS');
1741       hr_utility.raise_error;
1742   else
1743       close c1;
1744   end if;
1745   --
1746 if g_debug then
1747   hr_utility.set_location(' Leaving : ' || l_proc, 100);
1748 end if;
1749 end;
1750 --
1751 --
1752 --  ---------------------------------------------------------------------------
1753 --  |---------------------< return_legislation_code >-------------------------|
1754 --  ---------------------------------------------------------------------------
1755 --
1756 function return_legislation_code
1757   (p_position_id              in number
1758   ) return varchar2 is
1759   --
1760   -- Declare cursor
1761   --
1762   cursor csr_leg_code is
1763     select pbg.legislation_code
1764       from per_business_groups  pbg
1765          , hr_positions_f         pos
1766      where pos.position_id       = p_position_id
1767        and pbg.business_group_id = pos.business_group_id
1768      order by pos.effective_start_date;
1769   --
1770   -- Declare local variables
1771   --
1772   l_legislation_code  varchar2(150);
1773   l_proc              varchar2(72)  ;
1774 begin
1775 if g_debug then
1776   l_proc              :=  g_package||'return_legislation_code';
1777   hr_utility.set_location('Entering:'|| l_proc, 10);
1778 end if;
1779   --
1780   -- Ensure that all the mandatory parameter are not null
1781   --
1782   hr_api.mandatory_arg_error(p_api_name       => l_proc,
1783                              p_argument       => 'position_id',
1784                              p_argument_value => p_position_id);
1785   --
1786   open csr_leg_code;
1787   fetch csr_leg_code into l_legislation_code;
1788   if csr_leg_code%notfound then
1789     close csr_leg_code;
1790     --
1791     -- The primary key is invalid therefore we must error
1792     --
1793     hr_utility.set_message(800, 'HR_7220_INVALID_PRIMARY_KEY');
1794     hr_utility.raise_error;
1795   end if;
1796   --
1797   close csr_leg_code;
1798 if g_debug then
1799   hr_utility.set_location(' Leaving:'|| l_proc, 20);
1800 end if;
1801   --
1802   return l_legislation_code;
1803 end return_legislation_code;
1804 --
1805 --  ---------------------------------------------------------------------------
1806 --  |---------------------------<  chk_dates >--------------------------------|
1807 --  ---------------------------------------------------------------------------
1808 --
1809 --  Desciption :
1810 --
1811 --    Validates DATE_EFFECTIVE is not null
1812 --
1813 --    Validates that DATE_EFFECTIVE is less than or equal to the value for
1814 --    DATE_END on the same POSITION record
1815 --
1816 --  Pre-conditions:
1817 --    Format of p_date_effective must be correct
1818 --
1819 --  In Arguments :
1820 --    p_position_id
1821 --    p_date_effective
1822 --    p_date_end
1823 --    p_effective_date
1824 --    p_validation_start_Date
1825 --    p_validation_end_date
1826 --    p_object_version_number
1827 --
1828 --  Post Success :
1829 --    If the above business rules are satisfied, processing continues
1830 --
1831 --  Post Failure :
1832 --    If the above business rules are violated, an application error
1833 --    is raised and processing terminates
1834 --
1835 --  Access Status :
1836 --    Internal Table Handler Use only.
1837 --
1838 -- {End of Comments}
1839 --
1840 -- ---------------------------------------------------------------------------
1841 procedure chk_dates
1842   (p_position_id           in number default null
1843   ,p_date_effective        in date
1844   ,p_date_end              in date
1845   ,p_validation_start_date in date
1846   ,p_validation_end_date   in date
1847   ,p_effective_date        in date
1848   ,p_object_version_number in number default null) is
1849 --
1850    cursor c_get_eff_start_date (p_position_id number) is
1851    select min(effective_start_date)
1852    from hr_all_positions_f
1853    where position_id = p_position_id;
1854 --
1855    l_proc               varchar2(72)   ;
1856    l_api_updating          boolean;
1857    l_effective_start_date  date;
1858 
1859    l_return    boolean;
1860    l_industry  varchar2(10);
1861    l_status    varchar2(10);
1862    l_full_hr   boolean;
1863    l_ll        date;
1864    l_ul        date;
1865    l_updateable Boolean;
1866 
1867 --
1868 begin
1869 if g_debug then
1870    l_proc   := g_package||'chk_dates';
1871   hr_utility.set_location('Entering:'||l_proc, 1);
1872 end if;
1873   --
1874   --  Check mandatory parameters have been set
1875   --
1876   hr_api.mandatory_arg_error
1877     (p_api_name      => l_proc
1878     ,p_argument      => 'date_effective'
1879     ,p_argument_value   => p_date_effective
1880     );
1881 
1882   hr_api.mandatory_arg_error
1883     (p_api_name      => l_proc
1884     ,p_argument      => 'validation_start_date'
1885     ,p_argument_value   => p_validation_start_date
1886     );
1887 
1888   hr_api.mandatory_arg_error
1889     (p_api_name      => l_proc
1890     ,p_argument      => 'validation_end_date'
1891     ,p_argument_value   => p_validation_end_date
1892     );
1893 
1894 if g_debug then
1895   hr_utility.set_location(l_proc, 2);
1896 end if;
1897   --
1898   -- Only proceed with validation if :
1899   -- a) The current g_old_rec is current and
1900   -- b) The date_end value has changed
1901   --
1902   l_api_updating := hr_psf_shd.api_updating
1903     (p_position_id        => p_position_id
1904     ,p_effective_date        => p_effective_date
1905     ,p_object_version_number => p_object_version_number);
1906   --
1907   --
1908 if g_debug then
1909   hr_utility.set_location('HR Installation check ' || l_proc, 40);
1910 end if;
1911   --
1912   -- Find if full hr installation or shared hr installation
1913   --
1914   l_return := fnd_installation.get(appl_id     => 800,
1915                                    dep_appl_id => 800,
1916                                    status      => l_status,
1917                                    industry    => l_industry);
1918   --
1919 if g_debug then
1920   hr_utility.set_location('HR Installation check done ' || l_proc, 45);
1921 end if;
1922   if l_status = 'I' then
1923      l_full_hr := true;
1924   elsif l_status = 'S' then
1925      l_full_hr := false;
1926   else
1927      hr_utility.set_message(801,'HR_NULL_INSTALLATION_STATUS');
1928      hr_utility.raise_error;
1929   end if;
1930 
1931   --
1932   -- if full hr is installed the date_end must be null
1933   --
1934   if l_full_hr  and p_date_end is not null then
1935       hr_utility.set_message(800,'HR_DATE_END_MUST_BE_NULL');
1936       hr_utility.raise_error;
1937   end if;
1938   --
1939   if (((l_api_updating and
1940        (hr_psf_shd.g_old_rec.date_end <> p_date_end) or
1941        (hr_psf_shd.g_old_rec.date_effective <> p_date_effective)) or
1942        (NOT l_api_updating))) then
1943     --
1944     --   Check that date_effective <= date_end
1945     --
1946 if g_debug then
1947     hr_utility.set_location(l_proc, 3);
1948 end if;
1949     --
1950     if p_date_effective > nvl(p_date_end,hr_api.g_eot) then
1951       hr_utility.set_message(800,'HR_51362_POS_INVAL_EFF_DATE');
1952       hr_utility.raise_error;
1953     end if;
1954     --
1955 /*
1956     --
1957     -- Date_effective must be on or after effective_start_Date
1958     --
1959     if ( l_api_updating) then
1960       --
1961       open c_get_eff_start_date(p_position_id);
1962       fetch c_get_eff_start_date into l_effective_start_Date;
1963       close c_get_eff_start_date;
1964       if l_effective_start_date is null then
1965 I       hr_utility.set_message(801, 'HR_6153_ALL_PROCEDURE_FAIL');
1966         hr_utility.set_message_token('PROCEDURE', l_proc);
1967         hr_utility.set_message_token('STEP','5');
1968         hr_utility.raise_error;
1969       end if;
1970     else
1971       l_effective_start_date := p_validation_start_date;
1972     end if;
1973     --
1974     if ( p_date_effective < l_effective_start_date ) then
1975       hr_utility.set_message(800,'HR_PSF_DE_MUST_LATER_OR_EQ_ESD');
1976       hr_utility.raise_error;
1977     end if;
1978 --
1979     if (nvl(p_date_effective, hr_api.g_date) <>
1980         nvl(hr_psf_shd.g_old_rec.effective_start_date, hr_api.g_date)) then
1981       -- find if date_Effective can be modified
1982       --
1983       DE_Update_properties(
1984           p_position_id           => p_position_id,
1985           p_effective_Start_Date  => hr_psf_shd.g_old_rec.effective_start_date,
1986           p_updateable            => l_updateable,
1987           p_lower_limit           => l_ll,
1988           p_upper_limit           => l_ul);
1989       --
1990       if not l_updateable then
1991         --
1992         hr_utility.set_message(800,'HR_PSF_DE_NOT_UPDT_THIS_ROW');
1993         hr_utility.raise_error;
1994       end if;
1995       --
1996       if p_date_effective not between l_ll and l_ul then
1997          hr_utility.set_message(801,'HR_PSF_DE_OUT_OF_RANGE');
1998          hr_utility.raise_error;
1999       end if;
2000       -- if it is first row with ACTIVE status then
2001     --
2002     end if;
2003   --
2004 */
2005   end if;
2006   --
2007 if g_debug then
2008   hr_utility.set_location(' Leaving:'||l_proc, 4);
2009 end if;
2010 end chk_dates;
2011 --
2012 --
2013 --  ---------------------------------------------------------------------------
2014 --  |-----------------------------< chk_job_id >------------------------------|
2015 --  ---------------------------------------------------------------------------
2016 --
2017 procedure chk_job_id
2018   (p_position_id             in     hr_positions_f.position_id%TYPE           default null
2019   ,p_business_group_id       in     hr_positions_f.business_group_id%TYPE
2020   ,p_job_id                  in     hr_positions_f.job_id%TYPE
2021   ,p_effective_date          in     date
2022   ,p_validation_start_date   in     hr_positions_f.effective_start_date%TYPE
2023   ,p_validation_end_date     in     hr_positions_f.effective_end_date%TYPE
2024   ,p_object_version_number   in     hr_positions_f.object_version_number%TYPE default null
2025   )
2026   is
2027   --
2028   l_proc              varchar2(72) ;
2029   l_exists            varchar2(1);
2030   l_api_updating      boolean;
2031   l_business_group_id hr_positions_f.business_group_id%TYPE;
2032   l_vac_job_id        hr_positions_f.job_id%TYPE;
2033   --
2034   cursor csr_valid_job_id is
2035      select 'x'
2036      from per_jobs_v job
2037      where job.job_id = p_job_id
2038      and job.business_group_id + 0 = p_business_group_id;
2039   --
2040   cursor csr_valid_job_dates(p_validation_date date)  is
2041      select 'x'
2042      from per_jobs_v job
2043      where job.job_id = p_job_id
2044        and p_validation_date between job.date_from
2045        and nvl(job.date_to,hr_api.g_eot);
2046   --
2047 
2048 begin
2049 if g_debug then
2050   l_proc :=  g_package||'chk_job_id';
2051   hr_utility.set_location('Entering:'|| l_proc, 10);
2052 end if;
2053   --
2054   -- Check mandatory arguments
2055   --
2056   hr_api.mandatory_arg_error
2057     (p_api_name      => l_proc
2058     ,p_argument      => 'job_id'
2059     ,p_argument_value   => p_job_id
2060     );
2061   --
2062   hr_api.mandatory_arg_error
2063     (p_api_name       => l_proc
2064     ,p_argument       => 'effective_date'
2065     ,p_argument_value => p_effective_date
2066     );
2067   --
2068   hr_api.mandatory_arg_error
2069     (p_api_name       =>  l_proc
2070     ,p_argument       =>  'validation_start_date'
2071     ,p_argument_value =>  p_validation_start_date
2072     );
2073   --
2074   hr_api.mandatory_arg_error
2075     (p_api_name        =>  l_proc
2076     ,p_argument       =>  'validation_end_date'
2077     ,p_argument_value =>  p_validation_end_date
2078     );
2079 if g_debug then
2080   hr_utility.set_location(l_proc, 20);
2081 end if;
2082   --
2083   --  Check if the position is being updated.
2084   --
2085   l_api_updating := hr_psf_shd.api_updating
2086         (p_position_id            => p_position_id
2087         ,p_effective_date         => p_effective_date
2088         ,p_object_version_number  => p_object_version_number
2089         );
2090 if g_debug then
2091   hr_utility.set_location(l_proc, 30);
2092 end if;
2093   --
2094   -- Only proceed with validation if :
2095   -- a) The current g_old_rec is current and
2096   -- b) The value for job has changed
2097   --
2098   if ((l_api_updating and
2099        nvl(hr_psf_shd.g_old_rec.job_id,
2100        hr_api.g_number) <> nvl(p_job_id, hr_api.g_number))
2101     or
2102       NOT l_api_updating) then
2103 if g_debug then
2104     hr_utility.set_location(l_proc, 40);
2105 end if;
2106     --
2107     --    Check for valid job id
2108     --
2109     open csr_valid_job_id;
2110     fetch csr_valid_job_id into l_exists;
2111     if csr_valid_job_id%notfound then
2112       close csr_valid_job_id;
2113       hr_utility.set_message(800,'HR_51090_JOB_NOT_EXIST');
2114       hr_utility.raise_error;
2115     else
2116 if g_debug then
2117       hr_utility.set_location(l_proc, 3);
2118 end if;
2119       --
2120       close csr_valid_job_id;
2121       --
2122       --    Check validation_date between job date_from and date_to
2123       --
2124       open csr_valid_job_dates(p_validation_start_date);
2125       fetch csr_valid_job_dates into l_exists;
2126       if csr_valid_job_dates%notfound then
2127         close csr_valid_job_dates;
2128         hr_utility.set_message(800,'HR_51358_POS_JOB_INVALID_DATE');
2129         hr_utility.raise_error;
2130       end if;
2131       close csr_valid_job_dates;
2132     end if;
2133     --
2134   end if;
2135 if g_debug then
2136   hr_utility.set_location(' Leaving:'|| l_proc, 100);
2137 end if;
2138   --
2139 end chk_job_id;
2140 --
2141 --
2142 --  ---------------------------------------------------------------------------
2143 --  |-----------------------< chk_organization_id >---------------------------|
2144 --  ---------------------------------------------------------------------------
2145 --
2146 procedure chk_organization_id
2147   (p_position_id             in  hr_positions_f.position_id%TYPE            default null
2148   ,p_organization_id         in  hr_positions_f.organization_id%TYPE
2149   ,p_business_group_id       in  hr_positions_f.business_group_id%TYPE
2150   ,p_validation_start_date   in  hr_positions_f.effective_start_date%TYPE
2151   ,p_validation_end_date     in  hr_positions_f.effective_end_date%TYPE
2152   ,p_effective_date          in  date
2153   ,p_object_version_number   in  hr_positions_f.object_version_number%TYPE  default null
2154   )
2155 is
2156   --
2157   l_exists               varchar2(1);
2158   l_api_updating         boolean;
2159   l_proc                 varchar2(72);
2160   l_business_group_id    hr_positions_f.business_group_id%TYPE;
2161   --
2162   cursor csr_valid_organization_id is
2163      select 'x'
2164      from per_organization_units oru
2165      where oru.organization_id = p_organization_id
2166      and oru.business_group_id = p_business_group_id
2167      and oru.internal_external_flag = 'INT';
2168   --
2169   cursor csr_valid_organization_dates( p_validation_date date) is
2170      select 'x'
2171      from hr_organization_units oru
2172      where oru.organization_id = p_organization_id
2173        and p_validation_date between oru.date_from
2174        and nvl(oru.date_to,hr_api.g_eot);
2175   --
2176 
2177 begin
2178 if g_debug then
2179   l_proc :=  g_package||'chk_organization_id';
2180   hr_utility.set_location('Entering:'|| l_proc, 10);
2181 end if;
2182   --
2183   -- Check mandatory parameters have been set
2184   --
2185   hr_api.mandatory_arg_error
2186     (p_api_name       => l_proc
2187     ,p_argument       => 'effective_date'
2188     ,p_argument_value => p_effective_date
2189     );
2190   --
2191   hr_api.mandatory_arg_error
2192     (p_api_name       => l_proc
2193     ,p_argument       => 'organization_id'
2194     ,p_argument_value => p_organization_id
2195     );
2196   --
2197   hr_api.mandatory_arg_error
2198     (p_api_name       => l_proc
2199     ,p_argument       => 'business_group_id'
2200     ,p_argument_value => p_business_group_id
2201     );
2202   --
2203   hr_api.mandatory_arg_error
2204     (p_api_name       => l_proc
2205     ,p_argument       => 'validation_start_date'
2206     ,p_argument_value => p_validation_start_date
2207     );
2208   --
2209   hr_api.mandatory_arg_error
2210     (p_api_name       => l_proc
2211     ,p_argument       => 'validation_end_date'
2212     ,p_argument_value => p_validation_end_date
2213     );
2214 if g_debug then
2215   hr_utility.set_location(l_proc, 20);
2216 end if;
2217   --
2218   -- Only proceed with validation if :
2219   -- a) The current  g_old_rec is current and
2220   -- b) The value for organization_id has changed
2221   --
2222   l_api_updating := hr_psf_shd.api_updating
2223          (p_position_id            => p_position_id
2224          ,p_effective_date         => p_effective_date
2225          ,p_object_version_number  => p_object_version_number
2226          );
2227 if g_debug then
2228   hr_utility.set_location(l_proc, 30);
2229 end if;
2230   --
2231   if (l_api_updating and
2232      hr_psf_shd.g_old_rec.organization_id <> p_organization_id)
2233     or
2234       NOT l_api_updating
2235   then
2236 if g_debug then
2237     hr_utility.set_location(l_proc, 40);
2238 end if;
2239     --
2240     --    Check for valid organization id
2241     --
2242     open csr_valid_organization_id;
2243     fetch csr_valid_organization_id into l_exists;
2244     if csr_valid_organization_id%notfound then
2245       close csr_valid_organization_id;
2246       hr_utility.set_message(800,'HR_51371_POS_ORG_NOT_EXIST');
2247       hr_utility.raise_error;
2248     else
2249 if g_debug then
2250       hr_utility.set_location(l_proc, 3);
2251 end if;
2252       close csr_valid_organization_id;
2253       --
2254       --    Check validation_date between org date_from and date_to
2255       --
2256       open csr_valid_organization_dates(p_validation_start_date);
2257       fetch csr_valid_organization_dates into l_exists;
2258       if csr_valid_organization_dates%notfound then
2259         close csr_valid_organization_dates;
2260         hr_utility.set_message(800,'HR_51359_POS_ORG_INVAL_W_DATE');
2261         hr_utility.raise_error;
2262       end if;
2263       close csr_valid_organization_dates;
2264     end if;
2265   end if;
2266   --
2267   --
2268 if g_debug then
2269   hr_utility.set_location(' Leaving:'|| l_proc, 140);
2270 end if;
2271 end chk_organization_id;
2272 --
2273 --
2274 --  ---------------------------------------------------------------------------
2275 --  |--------------------<  chk_successor_position_id  >----------------------|
2276 --  ---------------------------------------------------------------------------
2277 --
2278 --  Desciption:
2279 --
2280 --    Validates that if SUCCESSOR_POSITION_ID exists, it must be a valid
2281 --    position for the business group and the successor DATE_END is on or after
2282 --    the DATE_EFFECTIVE of the position.
2283 --
2284 --  Pre-conditions:
2285 --
2286 --  In Arguments :
2287 --    p_position_id
2288 --    p_business_group_id
2289 --    p_successor_position_id
2290 --    p_effective_date
2291 --    p_validation_start_Date
2292 --    p_validation_end_Date
2293 --    p_object_version_number
2294 --
2295 --  Post Success :
2296 --    If the above business rules are satisfied, processing continues
2297 --
2298 --  Post Failure :
2299 --    If the above business rules are violated, an application error
2300 --    is raised and processing terminates
2301 --
2302 --  Access Status :
2303 --    Internal Table Handler Use only.
2304 --
2305 -- {End of Comments}
2306 --
2307 -- ----------------------------------------------------------------------------
2308 procedure chk_successor_position_id
2309   (p_business_group_id      in number
2310   ,p_position_id            in number default null
2311   ,p_successor_position_id  in number
2312   ,p_validation_start_date  in date
2313   ,p_validation_end_date    in date
2314   ,p_effective_date      in date
2315   ,p_object_version_number  in number default null
2316   )   is
2317 --
2318    l_exists           varchar2(1);
2319    l_proc   varchar2(72) ;
2320    l_api_updating     boolean;
2321 --
2322 cursor csr_valid_successor_position (p_validation_start_date date) is
2323 select 'x'
2324 from hr_all_positions_f psf, per_shared_types sht
2325 where psf.position_id = p_successor_position_id
2326 and psf.availability_status_id = sht.shared_type_id
2327 and (sht.business_group_id = p_business_group_id
2328      or sht.business_group_id is null)
2329 and sht.system_type_cd in ('ACTIVE','FROZEN')
2330 and psf.business_group_id = p_business_group_id
2331 and p_validation_start_date between psf.effective_start_date
2332                             and psf.effective_end_date ;
2333 
2334 begin
2335 if g_debug then
2336   l_proc     :=   g_package||'chk_successor_position_id';
2337   hr_utility.set_location('Entering:'||l_proc, 1);
2338 end if;
2339   --
2340   -- Only proceed with validation if :
2341   -- a) The current g_old_rec is current and
2342   -- b) The successor_position_id value has changed
2343   --
2344   if p_successor_position_id is not null then
2345   --
2346   hr_api.mandatory_arg_error
2347     (p_api_name       => l_proc
2348     ,p_argument       => 'effective date'
2349     ,p_argument_value => p_effective_date);
2350   --
2351   hr_api.mandatory_arg_error
2352     (p_api_name       => l_proc
2353     ,p_argument       => 'validation start date'
2354     ,p_argument_value => p_validation_start_date);
2355   --
2356   hr_api.mandatory_arg_error
2357     (p_api_name       => l_proc
2358     ,p_argument       => 'validation end date'
2359     ,p_argument_value => p_validation_end_date);
2360   --
2361   l_api_updating := hr_psf_shd.api_updating
2362     (p_position_id            => p_position_id
2363     ,p_effective_date            => p_effective_date
2364     ,p_object_version_number     => p_object_version_number);
2365   --
2366   --
2367   --    Check for valid successor position id
2368   --
2369   if ((l_api_updating and
2370        hr_psf_shd.g_old_rec.successor_position_id <>
2371        p_successor_position_id) or
2372        (NOT l_api_updating)) then
2373     --
2374 if g_debug then
2375       hr_utility.set_location(l_proc, 2);
2376 end if;
2377       open csr_valid_successor_position(p_validation_start_date);
2378       fetch csr_valid_successor_position into l_exists;
2379       if csr_valid_successor_position%notfound then
2380         close csr_valid_successor_position;
2381         hr_utility.set_message(800,'PER_52979_POS_SUCC_NOT_EXIST');
2382         hr_utility.raise_error;
2383      else
2384       close csr_valid_successor_position;
2385       if(l_api_updating and p_position_id = p_successor_position_id) then
2386         hr_utility.set_message(800,'HR_51360_POS_SUCCESSOR_EQ_POS');
2387         hr_utility.raise_error;
2388      end if;
2389     end if;
2390    end if;
2391   end if;
2392   --
2393 if g_debug then
2394   hr_utility.set_location(' Leaving:'||l_proc, 3);
2395 end if;
2396 end chk_successor_position_id;
2397 --
2398 --
2399 --  ---------------------------------------------------------------------------
2400 --  |--------------------<  chk_relief_position_id  >----------------------|
2401 --  ---------------------------------------------------------------------------
2402 --
2403 --  Desciption:
2404 --
2405 --    Validates that if relief_position_id exists, it must be a valid
2406 
2407 --    position for the business group and the successor DATE_END is on or after
2408 --    the DATE_EFFECTIVE of the position.
2409 --
2410 --  Pre-conditions:
2411 --
2412 --  In Arguments :
2413 --    p_position_id
2414 --    p_business_group_id
2415 --    p_relief_position_id
2416 --    p_effective_date
2417 --    p_validation_start_Date
2418 --    p_validation_end_Date
2419 --    p_object_version_number
2420 --
2421 --  Post Success :
2422 --    If the above business rules are satisfied, processing continues
2423 --
2424 --  Post Failure :
2425 --    If the above business rules are violated, an application error
2426 --    is raised and processing terminates
2427 --
2428 --  Access Status :
2429 --    Internal Table Handler Use only.
2430 --
2431 -- {End of Comments}
2432 --
2433 -- ----------------------------------------------------------------------------
2434 procedure chk_relief_position_id
2435   (p_business_group_id      in number
2436   ,p_position_id            in number default null
2437   ,p_relief_position_id     in number
2438   ,p_validation_start_date  in date
2439   ,p_validation_end_date    in date
2440   ,p_effective_date      in date
2441   ,p_object_version_number  in number default null
2442   )   is
2443 --
2444    l_exists           varchar2(1);
2445    l_proc   varchar2(72) ;
2446    l_api_updating     boolean;
2447 --
2448 cursor csr_valid_relief_position (p_validation_start_date date) is
2449 select 'x'
2450 from hr_all_positions_f psf, per_shared_types sht
2451 where psf.position_id = p_relief_position_id
2452 and psf.availability_status_id = sht.shared_type_id
2453 and (sht.business_group_id = p_business_group_id
2454      or sht.business_group_id is null)
2455 and sht.system_type_cd in ('ACTIVE','FROZEN')
2456 and psf.business_group_id = p_business_group_id
2457 and p_validation_start_date between psf.effective_start_date
2458                             and psf.effective_end_date ;
2459 --
2460 begin
2461 if g_debug then
2462    l_proc :=   g_package||'chk_relief_position_id';
2463   hr_utility.set_location('Entering:'||l_proc, 1);
2464 end if;
2465   --
2466   -- Only proceed with validation if :
2467   -- a) The current g_old_rec is current and
2468   -- b) The relief_position_id value has changed
2469   --
2470   if p_relief_position_id is not null then
2471   --
2472   hr_api.mandatory_arg_error
2473     (p_api_name       => l_proc
2474     ,p_argument       => 'effective date'
2475     ,p_argument_value => p_effective_date);
2476   --
2477   l_api_updating := hr_psf_shd.api_updating
2478     (p_position_id            => p_position_id
2479     ,p_effective_date            => p_effective_date
2480     ,p_object_version_number     => p_object_version_number);
2481   --
2482   hr_api.mandatory_arg_error
2483     (p_api_name       => l_proc
2484     ,p_argument       => 'validation start date'
2485     ,p_argument_value => p_validation_start_date);
2486   --
2487   --
2488   hr_api.mandatory_arg_error
2489     (p_api_name       => l_proc
2490     ,p_argument       => 'validation end date'
2491     ,p_argument_value => p_validation_end_date);
2492   --
2493   --    Check for valid successor position id
2494   --
2495   if ((l_api_updating and
2496        hr_psf_shd.g_old_rec.relief_position_id <>
2497        p_relief_position_id) or
2498        (NOT l_api_updating)) then
2499     --
2500 if g_debug then
2501     hr_utility.set_location(l_proc, 2);
2502 end if;
2503     --
2504       open csr_valid_relief_position(p_validation_start_date);
2505       fetch csr_valid_relief_position into l_exists;
2506       if csr_valid_relief_position%notfound then
2507         close csr_valid_relief_position;
2508         hr_utility.set_message(800,'PER_52980_POS_RELF_NOT_EXIST');
2509         hr_utility.raise_error;
2510      else
2511       close csr_valid_relief_position;
2512       if(l_api_updating and p_position_id = p_relief_position_id) then
2513         hr_utility.set_message(800,'HR_51361_POS_RELIEF_EQ_POS');
2514         hr_utility.raise_error;
2515      end if;
2516     end if;
2517    end if;
2518   end if;
2519   --
2520 if g_debug then
2521   hr_utility.set_location(' Leaving:'||l_proc, 3);
2522 end if;
2523 end chk_relief_position_id;
2524 --
2525 --
2526 --  ---------------------------------------------------------------------------
2527 --  |--------------------------< chk_location_id >----------------------------|
2528 --  ---------------------------------------------------------------------------
2529 --
2530 procedure chk_location_id
2531   (p_position_id           in hr_positions.position_id%TYPE           default null
2532   ,p_location_id           in hr_positions.location_id%TYPE
2533   ,p_effective_date        in date
2534   ,p_validation_start_date in hr_positions.effective_start_date%TYPE
2535   ,p_validation_end_date   in hr_positions.effective_end_date%TYPE
2536   ,p_object_version_number in hr_positions.object_version_number%TYPE default null
2537   )
2538   is
2539   --
2540   l_exists          varchar2(1);
2541   l_api_updating    boolean;
2542   l_proc            varchar2(72);
2543   l_inactive_date   date;
2544   --
2545   cursor csr_valid_location is
2546      select 'x'
2547      from   hr_locations loc
2548      where  loc.location_id = p_location_id
2549       and p_effective_date < nvl(loc.inactive_date,
2550          hr_api.g_eot);
2551 
2552   --
2553 begin
2554 
2555 if g_debug then
2556   l_proc  :=  g_package||'chk_location_id';
2557   hr_utility.set_location('Entering:'|| l_proc, 10);
2558 end if;
2559   --
2560   -- Check mandatory parameters have been set
2561   --
2562   hr_api.mandatory_arg_error
2563     (p_api_name       => l_proc
2564     ,p_argument       => 'effective_date'
2565     ,p_argument_value => p_effective_date
2566     );
2567   --
2568   hr_api.mandatory_arg_error
2569     (p_api_name       => l_proc
2570     ,p_argument       => 'validation_start_date'
2571     ,p_argument_value => p_validation_start_date
2572     );
2573   --
2574   hr_api.mandatory_arg_error
2575     (p_api_name       => l_proc
2576     ,p_argument       => 'validation_end_date'
2577     ,p_argument_value => p_validation_end_date
2578     );
2579 if g_debug then
2580   hr_utility.set_location('Entering:'|| l_proc, 20);
2581 end if;
2582   --
2583   -- Only proceed with validation if :
2584   -- a) The current g_old_rec is current and
2585   -- b) The value for location_id has changed
2586   --
2587   l_api_updating := hr_psf_shd.api_updating
2588          (p_position_id          => p_position_id
2589          ,p_effective_date         => p_effective_date
2590          ,p_object_version_number  => p_object_version_number
2591          );
2592 if g_debug then
2593   hr_utility.set_location('Entering:'|| l_proc, 30);
2594 end if;
2595   --
2596   if ((l_api_updating and
2597        nvl(hr_psf_shd.g_old_rec.location_id, hr_api.g_number) <>
2598        nvl(p_location_id, hr_api.g_number)) or
2599       (NOT l_api_updating))
2600   then
2601     --
2602 if g_debug then
2603     hr_utility.set_location('Entering:'|| l_proc, 40);
2604 end if;
2605     --
2606     if p_location_id is not null then
2607       --
2608       -- Check that the location exists in HR_LOCATIONS
2609       --
2610       open csr_valid_location;
2611       fetch csr_valid_location into l_exists;
2612       if csr_valid_location%notfound then
2613         close csr_valid_location;
2614         hr_utility.set_message(800, 'HR_51357_POS_LOC_NOT_EXIST');
2615         hr_utility.raise_error;
2616         --
2617       end if;
2618       close csr_valid_location;
2619       --
2620     end if;
2621     --
2622   end if;
2623   --
2624 if g_debug then
2625   hr_utility.set_location('Entering:'|| l_proc, 90);
2626 end if;
2627 end chk_location_id;
2628 --
2629 --
2630 --  ---------------------------------------------------------------------------
2631 --  |--------------------<  chk_position_definition_id  >---------------------|
2632 --  ---------------------------------------------------------------------------
2633 --
2634 --  Desciption :
2635 --
2636 --    Validates that POSITION_DEFINITION_ID is not null
2637 --
2638 --
2639 --  Pre-conditions:
2640 --
2641 --  In Arguments :
2642 --    p_position_definition_id
2643 --
2644 --  Post Success :
2645 --
2646 --  Post Failure :
2647 --
2648 --  Access Status :
2649 --    Internal Table Handler Use only.
2650 --
2651 -- {End of Comments}
2652 --
2653 -- -----------------------------------------------------------------------
2654 procedure chk_position_definition_id
2655   (p_position_definition_id   in number
2656   ,p_effective_date           in    date
2657   ,p_position_id              in    number default null
2658   ,p_object_version_number    in    number default null
2659   )   is
2660 --
2661    l_proc   varchar2(72)   ;
2662    l_exists    varchar2(1);
2663    l_api_updating  boolean;
2664 --
2665 cursor csr_pos_def is
2666   select 'x'
2667   from per_position_definitions
2668   where position_definition_id = p_position_definition_id;
2669 --
2670 begin
2671 if g_debug then
2672    l_proc   := g_package||'chk_position_definition_id';
2673   hr_utility.set_location('Entering:'||l_proc, 1);
2674 end if;
2675   --
2676   --  Check mandatory parameters have been set
2677   --
2678   hr_api.mandatory_arg_error
2679     (p_api_name      => l_proc
2680     ,p_argument      => 'position_definition_id'
2681     ,p_argument_value   => p_position_definition_id
2682     );
2683   --
2684   hr_api.mandatory_arg_error
2685     (p_api_name      => l_proc
2686     ,p_argument      => 'effective_date'
2687     ,p_argument_value   => p_effective_date
2688     );
2689   --
2690 if g_debug then
2691   hr_utility.set_location(l_proc, 2);
2692 end if;
2693   --
2694   l_api_updating := hr_psf_shd.api_updating
2695     (p_position_id        => p_position_id
2696     ,p_effective_date        => p_effective_date
2697     ,p_object_version_number => p_object_version_number);
2698   --
2699 if g_debug then
2700   hr_utility.set_location(l_proc, 3);
2701 end if;
2702   --
2703   if ((l_api_updating and
2704        (hr_psf_shd.g_old_rec.position_definition_id <>
2705           p_position_definition_id)) or
2706        (NOT l_api_updating)) then
2707 --
2708 if g_debug then
2709   hr_utility.set_location(l_proc, 4);
2710 end if;
2711   --
2712   open csr_pos_def;
2713   fetch csr_pos_def into l_exists;
2714   if csr_pos_def%notfound then
2715     hr_utility.set_message(800,'HR_51369_POS_DEF_NOT_EXIST');
2716     hr_utility.raise_error;
2717   end if;
2718   close csr_pos_def;
2719 --
2720 end if;
2721 if g_debug then
2722   hr_utility.set_location('Leaving '||l_proc, 5);
2723 end if;
2724   --
2725 end chk_position_definition_id;
2726 --
2727 --  ---------------------------------------------------------------------------
2728 --  |---------------------<  chk_probation_info >---------------------------|
2729 --  ---------------------------------------------------------------------------
2730 --
2731 --  Desciption :
2732 --
2733 --    Validate that if the PROBATION_PERIOD is null and PROBATION_PERIOD_UNITS
2734 --    is not null or if PROBATION_PERIOD is not null and PROBATION_PERIOS_UNITS
2735 --    is null then an error is raised
2736 --
2737 --    Validate the value for PROBATION_PERIOD_UNITS against the table
2738 --    FND_COMMON_LOOKUPS where the LOOKUP_TYPE is 'QUALIFYING_UNITS'.
2739 --
2740 --  Pre-conditions:
2741 --    None
2742 --
2743 --  In Arguments :
2744 --    p_position_id
2745 --    p_probation_period
2746 --    p_probation_period_units
2747 --    p_effective_date
2748 --    p_object_version_number
2749 --
2750 --  Post Success :
2751 --    If the above business rules are satisfied, processing continues
2752 --
2753 --  Post Failure :
2754 --    If the above business rules are violated, an application error
2755 --    is raised and processing terminates
2756 --
2757 --  Access Status :
2758 --    Internal Table Handler Use only.
2759 --
2760 -- {End of Comments}
2761 --
2762 -- ---------------------------------------------------------------------------
2763 procedure chk_probation_info
2764   (p_position_id              in number default null
2765   ,p_Effective_date           in date
2766   ,p_probation_period      in number
2767   ,p_probation_period_unit_cd in varchar2
2768   ,p_object_version_number    in number default null) is
2769 --
2770    l_proc   varchar2(72);
2771    l_api_updating     boolean;
2772    l_exists    varchar2(1);
2773 --
2774    cursor csr_valid_unit is
2775      select 'x'
2776      from fnd_common_lookups
2777      where lookup_type = 'QUALIFYING_UNITS'
2778        and lookup_code = p_probation_period_unit_cd;
2779 --
2780 begin
2781 if g_debug then
2782    l_proc      := g_package||'chk_probation_info';
2783   hr_utility.set_location('Entering:'||l_proc, 1);
2784 end if;
2785   --
2786   -- Only proceed with validation if :
2787   -- a) The current g_old_rec is current and
2788   -- b) The probation_period value has changed
2789   -- c) The probation_period_unit_cd value has changed
2790   --
2791   l_api_updating := hr_psf_shd.api_updating
2792     (p_position_id        => p_position_id
2793     ,p_effective_date        => p_effective_date
2794     ,p_object_version_number => p_object_version_number);
2795   --
2796   if ((l_api_updating and
2797     (nvl(hr_psf_shd.g_old_rec.probation_period,hr_api.g_number) <>
2798     nvl(p_probation_period,hr_api.g_number)) or
2799     (nvl(hr_psf_shd.g_old_rec.probation_period_unit_cd,hr_api.g_varchar2) <>
2800     nvl(p_probation_period_unit_cd,hr_api.g_varchar2))) or
2801     (NOT l_api_updating)) then
2802     --
2803     --    Check for values consistency
2804     --
2805 if g_debug then
2806     hr_utility.set_location(l_proc, 2);
2807 end if;
2808     --
2809     if (p_probation_period is null and
2810         p_probation_period_unit_cd is not null) or
2811        (p_probation_period is not null and
2812        p_probation_period_unit_cd is null) then
2813        hr_utility.set_message(800,'HR_51365_POS_PROB_UNITS_REQ');
2814        hr_utility.raise_error;
2815     else
2816       --
2817       --    Validate probation_period_unit_cd against fnd_common_lookups
2818       --
2819 if g_debug then
2820       hr_utility.set_location(l_proc, 3);
2821 end if;
2822       --
2823       if p_probation_period is not null
2824            and p_probation_period_unit_cd is not null then
2825         open csr_valid_unit;
2826         fetch csr_valid_unit into l_exists;
2827         if csr_valid_unit%notfound then
2828           hr_utility.set_message(800,'HR_51366_POS_PROB_UNITS_INV');
2829           hr_utility.raise_error;
2830         end if;
2831      end if;
2832   end if;
2833 end if;
2834     --
2835 if g_debug then
2836   hr_utility.set_location(' Leaving:'||l_proc, 4);
2837 end if;
2838 end chk_probation_info;
2839 --
2840 --
2841 --  ---------------------------------------------------------------------------
2842 --  |------------------<  chk_time_start_finish  >---------------------------|
2843 --  ---------------------------------------------------------------------------
2844 --
2845 --  Desciption :
2846 --
2847 --    Validate that TIME_NORMAL_FINISH is not before TIME_NORMAL_START.
2848 --
2849 --    Selects TIME_NORMAL_START and TIME_NORMAL_FINISH from the corresponding
2850 --    values on HR_ORGANIZATION_UNITS for the position's ORGANIZATION_ID when
2851 --    the values are null. When organization defaults are not maintained, the
2852 --    default values from the business group are used.
2853 --
2854 --  Pre-conditions:
2855 --    None
2856 --
2857 --  In Arguments :
2858 --    p_business_group_id
2859 --    p_organization_id
2860 --    p_position_id
2861 --    p_time_normal_start
2862 --    p_time_normal_finish
2863 --    p_effective_date
2864 --    p_object_version_number
2865 --
2866 --  Post Success :
2867 --    If the above business rules are satisfied, processing continues
2868 --
2869 --  Post Failure :
2870 --    If the above business rules are violated, an application error
2871 --    is raised and processing terminates
2872 --
2873 --  Access Status :
2874 --    Internal Table Handler Use only.
2875 --
2876 -- {End of Comments}
2877 --
2878 -- ---------------------------------------------------------------------------
2879 procedure chk_time_start_finish
2880   (p_position_id         in number default null
2881   ,p_effective_Date         in date
2882   ,p_time_normal_start      in varchar2
2883   ,p_time_normal_finish     in varchar2
2884   ,p_object_version_number  in number default null)   is
2885 --
2886    l_exists            varchar2(1);
2887    l_proc              varchar2(72);
2888    l_time_normal_start    varchar2(5);
2889    l_time_normal_finish   varchar2(5);
2890    l_api_updating         boolean;
2891 --
2892 begin
2893 if g_debug then
2894    l_proc   := g_package||'chk_time_start_finish';
2895   hr_utility.set_location('Entering:'||l_proc, 1);
2896 end if;
2897   --
2898   -- Only proceed with validation if :
2899   -- a) The current g_old_rec is current and
2900   -- b) The time_normal_start value has changed
2901   -- c) The time_normal_finish value has changed
2902   --
2903   l_api_updating := hr_psf_shd.api_updating
2904     (p_position_id        => p_position_id
2905     ,p_effective_Date        => p_effective_date
2906     ,p_object_version_number => p_object_version_number);
2907   --
2908   if ((l_api_updating and
2909      (nvl(hr_psf_shd.g_old_rec.time_normal_start,hr_api.g_varchar2) <>
2910      nvl(p_time_normal_start,hr_api.g_varchar2) or
2911      (nvl(hr_psf_shd.g_old_rec.time_normal_finish,hr_api.g_varchar2) <>
2912      nvl(p_time_normal_finish,hr_api.g_varchar2)))) or
2913      (NOT l_api_updating)) then
2914   --
2915     --    Check for values consistency
2916     --
2917 if g_debug then
2918     hr_utility.set_location(l_proc, 4);
2919 end if;
2920     --
2921     if (p_time_normal_start is not null and p_time_normal_finish is null) or
2922       (p_time_normal_start is null and p_time_normal_finish is not null) then
2923         hr_utility.set_message(800,'HR_51367_POS_TIMES_REQ');
2924         hr_utility.raise_error;
2925 --
2926   elsif not (substr(p_time_normal_start,1,2) between '00' and '24'
2927         and substr(p_time_normal_start,4,2) between '00' and '59'
2928         and substr(p_time_normal_start,3,1) = ':') then
2929         hr_utility.set_message(800,'HR_51154_INVAL_TIME_FORMAT');
2930         hr_utility.raise_error;
2931 --
2932    elsif not (substr(p_time_normal_finish,1,2) between '00' and '24'
2933         and substr(p_time_normal_finish,4,2) between '00' and '59'
2934         and substr(p_time_normal_finish,3,1) = ':') then
2935         hr_utility.set_message(800,'HR_51154_INVAL_TIME_FORMAT');
2936         hr_utility.raise_error;
2937 end if;
2938 /*
2939 -- remove this check
2940     --
2941     --   Check that time_normal_start <= time_normal_finish
2942     --
2943 if g_debug then
2944     hr_utility.set_location(l_proc, 5);
2945 end if;
2946     --
2947     if p_time_normal_finish <= p_time_normal_start then
2948       hr_utility.set_message(801,'HR_51368_POS_FIN_GT_START');
2949       hr_utility.raise_error;
2950     end if;
2951 */
2952     --
2953   end if;
2954   --
2955 if g_debug then
2956   hr_utility.set_location(' Leaving:'||l_proc, 6);
2957 end if;
2958 end chk_time_start_finish;
2959 /*
2960 --
2961 --  ---------------------------------------------------------------------------
2962 --  |-------------------< chk_position_transaction_id >-----------------------|
2963 --  ---------------------------------------------------------------------------
2964 --
2965 procedure chk_position_transaction_id
2966   (p_position_id              in hr_all_positions_f.position_id%TYPE
2967   ,p_position_transaction_id  in hr_all_positions_f.position_transaction_id%TYPE
2968   ,p_validation_start_date    in hr_all_positions_f.effective_start_date%TYPE
2969   ,p_validation_end_date      in hr_all_positions_f.effective_end_date%TYPE
2970   ,p_effective_date           in date
2971   ,p_object_version_number    in hr_all_positions_f.object_version_number%TYPE
2972   )
2973   is
2974 --
2975    l_exists            varchar2(1);
2976    l_api_updating      boolean;
2977    l_business_group_id number(15);
2978    l_proc              varchar2(72) ;
2979 --
2980    cursor csr_valid_tran is
2981    select  null
2982      from  pqh_position_transactions ptx
2983      where ptx.position_transaction_id = p_position_transaction_id;
2984 --
2985 begin
2986 if g_debug then
2987    l_proc  := g_package||'chk_position_transaction_id';
2988   hr_utility.set_location('Entering:'|| l_proc, 10);
2989 end if;
2990   --
2991   -- Check mandatory parameters have been set
2992   --
2993   hr_api.mandatory_arg_error
2994     (p_api_name       => l_proc
2995     ,p_argument       => 'validation_start_date'
2996     ,p_argument_value => p_validation_start_date
2997     );
2998   --
2999   hr_api.mandatory_arg_error
3000     (p_api_name       => l_proc
3001     ,p_argument       => 'validation_end_date'
3002     ,p_argument_value => p_validation_end_date
3003     );
3004   --
3005   hr_api.mandatory_arg_error
3006     (p_api_name       => l_proc
3007     ,p_argument       => 'effective_date'
3008     ,p_argument_value => p_effective_date
3009     );
3010   --
3011 if g_debug then
3012   hr_utility.set_location(l_proc, 20);
3013 end if;
3014   --
3015   -- Only proceed with validation if :
3016   -- a) The current g_old_rec is current and
3017   -- b) The value for position_transaction_id has changed
3018   --
3019   l_api_updating := hr_psf_shd.api_updating
3020         (p_position_id            => p_position_id
3021         ,p_effective_date         => p_effective_date
3022         ,p_object_version_number  => p_object_version_number
3023         );
3024 if g_debug then
3025   hr_utility.set_location(l_proc, 30);
3026 end if;
3027   --
3028   if ((l_api_updating and
3029        nvl(hr_psf_shd.g_old_rec.position_transaction_id, hr_api.g_number) <>
3030        nvl(p_position_transaction_id, hr_api.g_number)) or
3031       (NOT l_api_updating)) then
3032 if g_debug then
3033     hr_utility.set_location(l_proc, 40);
3034 end if;
3035     --
3036     if p_position_transaction_id is not null then
3037 if g_debug then
3038       hr_utility.set_location(l_proc, 50);
3039 end if;
3040       --
3041       -- Check that position_transaction_id exists in
3042       -- pqh_position_transactions
3043       --
3044       open csr_valid_tran;
3045       fetch csr_valid_tran into l_exists;
3046       if csr_valid_tran%notfound then
3047         close csr_valid_tran;
3048         hr_utility.set_message(800, 'HR_INV_POSN_TRAN');
3049         hr_utility.raise_error;
3050         --
3051       end if;
3052       close csr_valid_tran;
3053 if g_debug then
3054       hr_utility.set_location(l_proc, 60);
3055     hr_utility.set_location(l_proc, 130);
3056   hr_utility.set_location(' Leaving:'|| l_proc, 140);
3057 end if;
3058 end chk_position_transaction_id;
3059 */
3060 --
3061 --
3062 --  ---------------------------------------------------------------------------
3063 --  |--------------------<  chk_supervisor_position_id  >----------------------|
3064 --  ---------------------------------------------------------------------------
3065 --
3066 --  Desciption:
3067 --
3068 --    Validates that if supervisor_position_id exists, it must be a valid
3069 --    position for the business group and the successor DATE_END is on or after
3070 --    the DATE_EFFECTIVE of the position.
3071 --
3072 --  Pre-conditions:
3073 --
3074 --  In Arguments :
3075 --    p_position_id
3076 --    p_business_group_id
3077 --    p_supervisor_position_id
3078 --    p_effective_date
3079 --    p_validation_start_Date
3080 --    p_validation_end_Date
3081 --    p_object_version_number
3082 --
3083 --  Post Success :
3084 --    If the above business rules are satisfied, processing continues
3085 --
3086 --  Post Failure :
3087 --    If the above business rules are violated, an application error
3088 --    is raised and processing terminates
3089 --
3090 --  Access Status :
3091 --    Internal Table Handler Use only.
3092 --
3093 -- {End of Comments}
3094 --
3095 -- ----------------------------------------------------------------------------
3096 procedure chk_supervisor_position_id
3097   (p_business_group_id      in number
3098   ,p_position_id            in number default null
3099   ,p_supervisor_position_id  in number
3100   ,p_validation_start_date  in date
3101   ,p_validation_end_date    in date
3102   ,p_effective_date      in date
3103   ,p_object_version_number  in number default null
3104   )   is
3105 --
3106    l_exists           varchar2(1);
3107    l_proc   varchar2(72) ;
3108    l_api_updating     boolean;
3109 --
3110 cursor csr_valid_supervisor_position (p_validation_start_date date) is
3111 select 'x'
3112 from hr_all_positions_f psf, per_shared_types sht
3113 where psf.position_id = p_supervisor_position_id
3114 and psf.availability_status_id = sht.shared_type_id
3115 and (sht.business_group_id = p_business_group_id
3116      or sht.business_group_id is null)
3117 and sht.system_type_cd in ('ACTIVE','FROZEN')
3118 and psf.business_group_id = p_business_group_id
3119 and p_validation_start_date between psf.effective_start_date
3120                             and psf.effective_end_date ;
3121 --
3122 begin
3123 if g_debug then
3124    l_proc    :=   g_package||'chk_supervisor_position_id';
3125   hr_utility.set_location('Entering:'||l_proc, 1);
3126 end if;
3127   --
3128   -- Only proceed with validation if :
3129   -- a) The current g_old_rec is current and
3130   -- b) The supervisor_position_id value has changed
3131   --
3132   if p_supervisor_position_id is not null then
3133     --
3134     hr_api.mandatory_arg_error
3135       (p_api_name       => l_proc
3136       ,p_argument       => 'effective date'
3137       ,p_argument_value => p_effective_date);
3138     --
3139     hr_api.mandatory_arg_error
3140       (p_api_name       => l_proc
3141       ,p_argument       => 'validation start date'
3142       ,p_argument_value => p_validation_start_date);
3143     --
3144     hr_api.mandatory_arg_error
3145       (p_api_name       => l_proc
3146       ,p_argument       => 'validation end date'
3147       ,p_argument_value => p_validation_end_date);
3148     --
3149     l_api_updating := hr_psf_shd.api_updating
3150       (p_position_id          => p_position_id
3151       ,p_effective_date            => p_effective_date
3152       ,p_object_version_number     => p_object_version_number);
3153     --
3154     --
3155     --    Check for valid successor position id
3156     --
3157     if ((l_api_updating and
3158          hr_psf_shd.g_old_rec.supervisor_position_id <>
3159          p_supervisor_position_id) or
3160          (NOT l_api_updating)) then
3161       --
3162 if g_debug then
3163       hr_utility.set_location(l_proc, 2);
3164 end if;
3165       open csr_valid_supervisor_position(p_validation_start_date);
3166       fetch csr_valid_supervisor_position into l_exists;
3167       if csr_valid_supervisor_position%notfound then
3168         close csr_valid_supervisor_position;
3169         hr_utility.set_message(800,'HR_PSF_SUPER_NOT_EXIST');
3170         hr_utility.raise_error;
3171       else
3172         close csr_valid_supervisor_position;
3173         if(l_api_updating and p_position_id = p_supervisor_position_id) then
3174             hr_utility.set_message(800,'HR_PSF_SUPERVISOR_EQ_POS');
3175             hr_utility.raise_error;
3176         end if;
3177       end if;
3178     end if;
3179   end if;
3180   --
3181 if g_debug then
3182   hr_utility.set_location(' Leaving:'||l_proc, 3);
3183 end if;
3184 end chk_supervisor_position_id;
3185 --
3186 --
3187 --
3188 --  ---------------------------------------------------------------------------
3189 --  |--------------------<  chk_prior_position_id  >----------------------|
3190 --  ---------------------------------------------------------------------------
3191 --
3192 --  Desciption:
3193 --
3194 --    Validates that if prior_position_id exists, it must be a valid
3195 --    position for the business group and the successor DATE_END is on or after
3196 --    the DATE_EFFECTIVE of the position.
3197 --
3198 --  Pre-conditions:
3199 --
3200 --  In Arguments :
3201 --    p_position_id
3202 --    p_business_group_id
3203 --    p_prior_position_id
3204 --    p_effective_date
3205 --    p_validation_start_Date
3206 --    p_validation_end_Date
3207 --    p_object_version_number
3208 --
3209 --  Post Success :
3210 --    If the above business rules are satisfied, processing continues
3211 --
3212 --  Post Failure :
3213 --    If the above business rules are violated, an application error
3214 --    is raised and processing terminates
3215 --
3216 --  Access Status :
3217 --    Internal Table Handler Use only.
3218 --
3219 -- {End of Comments}
3220 --
3221 -- ----------------------------------------------------------------------------
3222 procedure chk_prior_position_id
3223   (p_business_group_id      in number
3224   ,p_position_id            in number default null
3225   ,p_prior_position_id  in number
3226   ,p_validation_start_date  in date
3227   ,p_validation_end_date    in date
3228   ,p_effective_date      in date
3229   ,p_object_version_number  in number default null
3230   )   is
3231 --
3232    l_exists           varchar2(1);
3233    l_proc   varchar2(72) ;
3234    l_api_updating     boolean;
3235 --
3236 cursor csr_valid_prior_position (p_validation_start_date date) is
3237 select 'x'
3238 from hr_all_positions_f psf, per_shared_types sht
3239 where psf.position_id = p_prior_position_id
3240 and psf.availability_status_id = sht.shared_type_id
3241 and (sht.business_group_id = p_business_group_id
3242      or sht.business_group_id is null)
3243 and sht.system_type_cd in ('ACTIVE','FROZEN')
3244 and psf.business_group_id = p_business_group_id
3245 and p_validation_start_date between psf.effective_start_date
3246                             and psf.effective_end_date ;
3247 --
3248 begin
3249 if g_debug then
3250    l_proc    :=   g_package||'chk_prior_position_id';
3251   hr_utility.set_location('Entering:'||l_proc, 1);
3252 end if;
3253   --
3254   -- Only proceed with validation if :
3255   -- a) The current g_old_rec is current and
3256   -- b) The prior_position_id value has changed
3257   --
3258   if p_prior_position_id is not null then
3259     --
3260     hr_api.mandatory_arg_error
3261       (p_api_name       => l_proc
3262       ,p_argument       => 'effective date'
3263       ,p_argument_value => p_effective_date);
3264     --
3265     hr_api.mandatory_arg_error
3266       (p_api_name       => l_proc
3267       ,p_argument       => 'validation start date'
3268       ,p_argument_value => p_validation_start_date);
3269     --
3270     hr_api.mandatory_arg_error
3271       (p_api_name       => l_proc
3272       ,p_argument       => 'validation end date'
3273       ,p_argument_value => p_validation_end_date);
3274     --
3275     l_api_updating := hr_psf_shd.api_updating
3276       (p_position_id          => p_position_id
3277       ,p_effective_date            => p_effective_date
3278       ,p_object_version_number     => p_object_version_number);
3279     --
3280     --
3281     --    Check for valid successor position id
3282     --
3283     if ((l_api_updating and
3284          hr_psf_shd.g_old_rec.prior_position_id <>
3285          p_prior_position_id) or
3286          (NOT l_api_updating)) then
3287       --
3288 if g_debug then
3289       hr_utility.set_location(l_proc, 2);
3290 end if;
3291       open csr_valid_prior_position(p_validation_start_date);
3292       fetch csr_valid_prior_position into l_exists;
3293       if csr_valid_prior_position%notfound then
3294         close csr_valid_prior_position;
3295         hr_utility.set_message(800,'HR_PSF_PRIOR_NOT_EXIST');
3296         hr_utility.raise_error;
3297       else
3298         close csr_valid_prior_position;
3299       end if;
3300     end if;
3301   end if;
3302   --
3303 if g_debug then
3304   hr_utility.set_location(' Leaving:'||l_proc, 3);
3305 end if;
3306 end chk_prior_position_id;
3307 --
3308 -- ----------------------------------------------------------------------------
3309 -- |------< chk_work_term_end_month_cd >------|
3310 -- ----------------------------------------------------------------------------
3311 --
3312 -- Description
3313 --   This procedure is used to check that the lookup value is valid.
3314 --
3315 -- Pre Conditions
3316 --   None.
3317 --
3318 -- In Parameters
3319 --   position_id PK of record being inserted or updated.
3320 --   work_term_end_month_cd   Value of lookup code.
3321 --   effective_date           effective date
3322 --   validation_start_date
3323 --   validation_end_Date
3324 --   date_effective
3325 --   object_version_number    Object version number of record being
3326 --                         inserted or updated.
3327 --
3328 -- Post Success
3329 --   Processing continues
3330 --
3331 -- Post Failure
3332 --   Error handled by procedure
3333 --
3334 -- Access Status
3335 --   Internal table handler use only.
3336 --
3337 Procedure chk_work_term_end_month_cd
3338   (p_position_id             in number
3339   ,p_work_term_end_month_cd  in varchar2
3340   ,p_effective_date          in date
3341   ,p_validation_start_date   in date
3342   ,p_validation_end_date     in date
3343   ,p_object_version_number   in number) is
3344   --
3345   l_proc         varchar2(72) ;
3346   l_api_updating boolean;
3347   --
3348 Begin
3349   --
3350 if g_debug then
3351  l_proc       := g_package||'chk_work_term_end_month_cd';
3352   hr_utility.set_location('Entering:'||l_proc, 5);
3353 end if;
3354   --
3355   l_api_updating := hr_psf_shd.api_updating
3356     (p_position_id            => p_position_id
3357     ,p_effective_date         => p_effective_date
3358     ,p_object_version_number  => p_object_version_number);
3359   --
3360   if (l_api_updating
3361       and p_work_term_end_month_cd
3362       <> nvl(hr_psf_shd.g_old_rec.work_term_end_month_cd,hr_api.g_varchar2)
3363       or not l_api_updating)
3364       and p_work_term_end_month_cd is not null then
3365     --
3366     -- check if value of lookup falls within lookup type.
3367     --
3368     if hr_api.not_exists_in_dt_hr_lookups
3369           (p_lookup_type           => 'MONTH_CODE'
3370           ,p_lookup_code           => p_work_term_end_month_cd
3371           ,p_validation_start_date => p_validation_start_date
3372           ,p_validation_end_date   => p_validation_end_date
3373           ,p_effective_date        => p_effective_date) then
3374       --
3375       -- raise error as does not exist as lookup
3376       --
3377       hr_utility.set_message(800,'HR_LOOKUP_DOES_NOT_EXIST');
3378       hr_utility.raise_error;
3379       --
3380     end if;
3381     --
3382   end if;
3383   --
3384 if g_debug then
3385   hr_utility.set_location('Leaving:'||l_proc,10);
3386 end if;
3387   --
3388 end chk_work_term_end_month_cd;
3389 --
3390 --
3391 -- ----------------------------------------------------------------------------
3392 -- |------< chk_work_term_end_day_cd >------|
3393 -- ----------------------------------------------------------------------------
3394 --
3395 -- Description
3396 --   This procedure is used to check that the lookup value is valid.
3397 --
3398 -- Pre Conditions
3399 --   None.
3400 --
3401 -- In Parameters
3402 --   position_id                   PK of record being inserted or updated.
3403 --   work_term_end_day_cd          Value of lookup code.
3404 --   validation_start_date
3405 --   validation_end_Date
3406 --   date_effective
3407 --   effective_date                effective date
3408 --   object_version_number         Object version number of record being
3409 --                         inserted or updated.
3410 --
3411 -- Post Success
3412 --   Processing continues
3413 --
3414 -- Post Failure
3415 --   Error handled by procedure
3416 --
3417 -- Access Status
3418 --   Internal table handler use only.
3419 --
3420 Procedure chk_work_term_end_day_cd
3421   (p_position_id             in number
3422   ,p_work_term_end_day_cd    in varchar2
3423   ,p_effective_date          in date
3424   ,p_validation_start_date   in date
3425   ,p_validation_end_date     in date
3426   ,p_object_version_number   in number) is
3427   --
3428   l_proc         varchar2(72) ;
3429   l_api_updating boolean;
3430   --
3431 Begin
3432   --
3433 if g_debug then
3434   l_proc          := g_package||'chk_work_term_end_day_cd';
3435   hr_utility.set_location('Entering:'||l_proc, 5);
3436 end if;
3437   --
3438   l_api_updating := hr_psf_shd.api_updating
3439     (p_position_id            => p_position_id
3440     ,p_effective_date         => p_effective_date
3441     ,p_object_version_number  => p_object_version_number);
3442   --
3443   if (l_api_updating
3444       and p_work_term_end_day_cd
3445       <> nvl(hr_psf_shd.g_old_rec.work_term_end_day_cd,hr_api.g_varchar2)
3446       or not l_api_updating)
3447       and p_work_term_end_day_cd is not null then
3448     --
3449     -- check if value of lookup falls within lookup type.
3450     --
3451     if hr_api.not_exists_in_dt_hr_lookups
3452           (p_lookup_type           => 'DAY_CODE'
3453           ,p_lookup_code           => p_work_term_end_day_cd
3454           ,p_validation_start_date => p_validation_start_date
3455           ,p_validation_end_date   => p_validation_end_date
3456           ,p_effective_date        => p_effective_date) then
3457       --
3458       -- raise error as does not exist as lookup
3459       --
3460       hr_utility.set_message(800,'HR_LOOKUP_DOES_NOT_EXIST');
3461       hr_utility.raise_error;
3462       --
3463     end if;
3464     --
3465   end if;
3466   --
3467 if g_debug then
3468   hr_utility.set_location('Leaving:'||l_proc,10);
3469 end if;
3470   --
3471 end chk_work_term_end_day_cd;
3472 --
3473 -- ----------------------< chk_position_type > ------------------------
3474 --
3475 Procedure chk_position_type
3476   (p_position_id             in number
3477   ,p_position_type           in varchar2
3478   ,p_effective_date          in date
3479   ,p_validation_start_date   in date
3480   ,p_validation_end_date     in date
3481   ,p_object_version_number   in number) is
3482   --
3483   l_proc         varchar2(72);
3484   l_api_updating boolean;
3485   --
3486 Begin
3487   --
3488 if g_debug then
3489 l_proc        := g_package||'chk_position_type';
3490   hr_utility.set_location('Entering:'||l_proc, 5);
3491 end if;
3492   --
3493   hr_api.mandatory_arg_error
3494       (p_api_name       => l_proc
3495       ,p_argument       => 'position type'
3496       ,p_argument_value => p_position_type);
3497     --
3498   --
3499   hr_api.mandatory_arg_error
3500       (p_api_name       => l_proc
3501       ,p_argument       => 'validation start date'
3502       ,p_argument_value => p_validation_start_date);
3503     --
3504   --
3505   hr_api.mandatory_arg_error
3506       (p_api_name       => l_proc
3507       ,p_argument       => 'effective date'
3508       ,p_argument_value => p_effective_date);
3509     --
3510   l_api_updating := hr_psf_shd.api_updating
3511     (p_position_id            => p_position_id
3512     ,p_effective_date         => p_effective_date
3513     ,p_object_version_number  => p_object_version_number);
3514   --
3515   if (l_api_updating
3516       and p_position_type
3517       <> nvl(hr_psf_shd.g_old_rec.position_type,hr_api.g_varchar2)
3518       or not l_api_updating)
3519       and p_position_type is not null then
3520     --
3521     -- check if value of lookup falls within lookup type.
3522     --
3523     if hr_api.not_exists_in_dt_hr_lookups
3524           (p_lookup_type           => 'POSITION_TYPE'
3525           ,p_lookup_code           => p_position_type
3526           ,p_validation_start_date => p_validation_start_date
3527           ,p_validation_end_date   => p_validation_end_date
3528           ,p_effective_date        => p_effective_date) then
3529       --
3530       -- raise error as does not exist as lookup
3531       --
3532       hr_utility.set_message(800,'HR_LOOKUP_DOES_NOT_EXIST');
3533       hr_utility.raise_error;
3534       --
3535     end if;
3536     --
3537   end if;
3538   --
3539 if g_debug then
3540   hr_utility.set_location('Leaving:'||l_proc,10);
3541 end if;
3542   --
3543 end chk_position_type;
3544 --
3545 -- ----------------------------------------------------------------------------
3546 -- |------< chk_work_period_type_cd >------|
3547 -- ----------------------------------------------------------------------------
3548 --
3549 -- Description
3550 --   This procedure is used to check that the lookup value is valid.
3551 --
3552 -- Pre Conditions
3553 --   None.
3554 --
3555 -- In Parameters
3556 --   position_id                   PK of record being inserted or updated.
3557 --   work_period_type_cd          Value of lookup code.
3558 --   validation_start_date
3559 --   validation_end_Date
3560 --   date_effective
3561 --   effective_date                effective date
3562 --   object_version_number         Object version number of record being
3563 --                         inserted or updated.
3564 --
3565 -- Post Success
3566 --   Processing continues
3567 --
3568 -- Post Failure
3569 --   Error handled by procedure
3570 --
3571 -- Access Status
3572 --   Internal table handler use only.
3573 --
3574 Procedure chk_work_period_type_cd
3575   (p_position_id             in number
3576   ,p_work_period_type_cd    in varchar2
3577   ,p_effective_date          in date
3578   ,p_validation_start_date   in date
3579   ,p_validation_end_date     in date
3580   ,p_object_version_number   in number) is
3581   --
3582   l_proc         varchar2(72) ;
3583   l_api_updating boolean;
3584   --
3585 Begin
3586   --
3587 if g_debug then
3588   l_proc          := g_package||'chk_work_period_type_cd';
3589   hr_utility.set_location('Entering:'||l_proc, 5);
3590 end if;
3591   --
3592   l_api_updating := hr_psf_shd.api_updating
3593     (p_position_id            => p_position_id
3594     ,p_effective_date         => p_effective_date
3595     ,p_object_version_number  => p_object_version_number);
3596   --
3597   if (l_api_updating
3598       and p_work_period_type_cd
3599       <> nvl(hr_psf_shd.g_old_rec.work_period_type_cd,hr_api.g_varchar2)
3600       or not l_api_updating)
3601       and p_work_period_type_cd is not null then
3602     --
3603     -- check if value of lookup falls within lookup type.
3604     --
3605     if hr_api.not_exists_in_dt_hr_lookups
3606           (p_lookup_type           => 'YES_NO'
3607           ,p_lookup_code           => p_work_period_type_cd
3608           ,p_validation_start_date => p_validation_start_date
3609           ,p_validation_end_date   => p_validation_end_date
3610           ,p_effective_date        => p_effective_date) then
3611       --
3612       -- raise error as does not exist as lookup
3613       --
3614       hr_utility.set_message(800,'HR_LOOKUP_DOES_NOT_EXIST');
3615       hr_utility.raise_error;
3616       --
3617     end if;
3618     --
3619   end if;
3620   --
3621 if g_debug then
3622   hr_utility.set_location('Leaving:'||l_proc,10);
3623 end if;
3624   --
3625 end chk_work_period_type_cd;
3626 --
3627 -- ----------------------------------------------------------------------------
3628 -- |------< chk_works_council_approval_flg >------|
3629 -- ----------------------------------------------------------------------------
3630 --
3631 -- Description
3632 --   This procedure is used to check that the lookup value is valid.
3633 --
3634 -- Pre Conditions
3635 --   None.
3636 --
3637 -- In Parameters
3638 --   position_id                   PK of record being inserted or updated.
3639 --   works_council_approval_flag   Value of lookup code.
3640 --   validation_start_date
3641 --   validation_end_Date
3642 --   date_effective
3643 --   effective_date                effective date
3644 --   object_version_number         Object version number of record being
3645 --                         inserted or updated.
3646 --
3647 -- Post Success
3648 --   Processing continues
3649 --
3650 -- Post Failure
3651 --   Error handled by procedure
3652 --
3653 -- Access Status
3654 --   Internal table handler use only.
3655 --
3656 Procedure chk_works_council_approval_flg
3657   (p_position_id             in number
3658   ,p_works_council_approval_flag    in varchar2
3659   ,p_effective_date          in date
3660   ,p_validation_start_date   in date
3661   ,p_validation_end_date     in date
3662   ,p_object_version_number   in number) is
3663   --
3664   l_proc         varchar2(72) ;
3665   l_api_updating boolean;
3666   --
3667 Begin
3668   --
3669 if g_debug then
3670   l_proc     := g_package||'chk_works_council_approval_flg';
3671   hr_utility.set_location('Entering:'||l_proc, 5);
3672 end if;
3673   --
3674   l_api_updating := hr_psf_shd.api_updating
3675     (p_position_id            => p_position_id
3676     ,p_effective_date         => p_effective_date
3677     ,p_object_version_number  => p_object_version_number);
3678   --
3679   if (l_api_updating
3680       and p_works_council_approval_flag
3681       <> nvl(hr_psf_shd.g_old_rec.works_council_approval_flag,hr_api.g_varchar2)
3682       or not l_api_updating)
3683       and p_works_council_approval_flag is not null then
3684     --
3685     -- check if value of lookup falls within lookup type.
3686     --
3687     if hr_api.not_exists_in_dt_hr_lookups
3688           (p_lookup_type           => 'YES_NO'
3689           ,p_lookup_code           => p_works_council_approval_flag
3690           ,p_validation_start_date => p_validation_start_date
3691           ,p_validation_end_date   => p_validation_end_date
3692           ,p_effective_date        => p_effective_date) then
3693       --
3694       -- raise error as does not exist as lookup
3695       --
3696       hr_utility.set_message(800,'HR_LOOKUP_DOES_NOT_EXIST');
3697       hr_utility.raise_error;
3698       --
3699     end if;
3700     --
3701   end if;
3702   --
3703 if g_debug then
3704   hr_utility.set_location('Leaving:'||l_proc,10);
3705 end if;
3706   --
3707 end chk_works_council_approval_flg;
3708 --
3709 --
3710 -- ----------------------------------------------------------------------------
3711 -- |------< chk_term_start_month_cd >------|
3712 -- ----------------------------------------------------------------------------
3713 --
3714 -- Description
3715 --   This procedure is used to check that the lookup value is valid.
3716 --
3717 -- Pre Conditions
3718 --   None.
3719 --
3720 -- In Parameters
3721 --   position_id                   PK of record being inserted or updated.
3722 --   p_term_start_month_cd   Value of lookup code.
3723 --   validation_start_date
3724 --   validation_end_Date
3725 --   date_effective
3726 --   effective_date                effective date
3727 --   object_version_number         Object version number of record being
3728 --                         inserted or updated.
3729 --
3730 -- Post Success
3731 --   Processing continues
3732 --
3733 -- Post Failure
3734 --   Error handled by procedure
3735 --
3736 -- Access Status
3737 --   Internal table handler use only.
3738 --
3739 Procedure chk_term_start_month_cd
3740   (p_position_id             in number
3741   ,p_term_start_month_cd    in varchar2
3742   ,p_effective_date          in date
3743   ,p_validation_start_date   in date
3744   ,p_validation_end_date     in date
3745   ,p_object_version_number   in number) is
3746   --
3747   l_proc         varchar2(72);
3748   l_api_updating boolean;
3749   --
3750 Begin
3751   --
3752 if g_debug then
3753  l_proc          := g_package||'chk_term_start_month_cd';
3754   hr_utility.set_location('Entering:'||l_proc, 5);
3755 end if;
3756   --
3757   l_api_updating := hr_psf_shd.api_updating
3758     (p_position_id            => p_position_id
3759     ,p_effective_date         => p_effective_date
3760     ,p_object_version_number  => p_object_version_number);
3761   --
3762   if (l_api_updating
3763       and p_term_start_month_cd
3764       <> nvl(hr_psf_shd.g_old_rec.term_start_month_cd,hr_api.g_varchar2)
3765       or not l_api_updating)
3766       and p_term_start_month_cd is not null then
3767     --
3768     -- check if value of lookup falls within lookup type.
3769     --
3770     if hr_api.not_exists_in_dt_hr_lookups
3771           (p_lookup_type           => 'MONTH_CODE'
3772           ,p_lookup_code           => p_term_start_month_cd
3773           ,p_validation_start_date => p_validation_start_date
3774           ,p_validation_end_date   => p_validation_end_date
3775           ,p_effective_date        => p_effective_date) then
3776       --
3777       -- raise error as does not exist as lookup
3778       --
3779       hr_utility.set_message(800,'HR_LOOKUP_DOES_NOT_EXIST');
3780       hr_utility.raise_error;
3781       --
3782     end if;
3783     --
3784   end if;
3785   --
3786 if g_debug then
3787   hr_utility.set_location('Leaving:'||l_proc,10);
3788 end if;
3789   --
3790 end chk_term_start_month_cd;
3791 --
3792 --
3793 -- ----------------------------------------------------------------------------
3794 -- |------< chk_term_start_day_cd >------|
3795 -- ----------------------------------------------------------------------------
3796 --
3797 -- Description
3798 --   This procedure is used to check that the lookup value is valid.
3799 --
3800 -- Pre Conditions
3801 --   None.
3802 --
3803 -- In Parameters
3804 --   position_id                   PK of record being inserted or updated.
3805 --   p_term_start_day_cd   Value of lookup code.
3806 --   validation_start_date
3807 --   validation_end_Date
3808 --   date_effective
3809 --   effective_date                effective date
3810 --   object_version_number         Object version number of record being
3811 --                         inserted or updated.
3812 --
3813 -- Post Success
3814 --   Processing continues
3815 --
3816 -- Post Failure
3817 --   Error handled by procedure
3818 --
3819 -- Access Status
3820 --   Internal table handler use only.
3821 --
3822 Procedure chk_term_start_day_cd
3823   (p_position_id             in number
3824   ,p_term_start_day_cd    in varchar2
3825   ,p_effective_date          in date
3826   ,p_validation_start_date   in date
3827   ,p_validation_end_date     in date
3828   ,p_object_version_number   in number) is
3829   --
3830   l_proc         varchar2(72) ;
3831   l_api_updating boolean;
3832   --
3833 Begin
3834   --
3835 if g_debug then
3836   l_proc      := g_package||'chk_term_start_day_cd';
3837   hr_utility.set_location('Entering:'||l_proc, 5);
3838 end if;
3839   --
3840   l_api_updating := hr_psf_shd.api_updating
3841     (p_position_id            => p_position_id
3842     ,p_effective_date         => p_effective_date
3843     ,p_object_version_number  => p_object_version_number);
3844   --
3845   if (l_api_updating
3846       and p_term_start_day_cd
3847       <> nvl(hr_psf_shd.g_old_rec.term_start_day_cd,hr_api.g_varchar2)
3848       or not l_api_updating)
3849       and p_term_start_day_cd is not null then
3850     --
3851     -- check if value of lookup falls within lookup type.
3852     --
3853     if hr_api.not_exists_in_dt_hr_lookups
3854           (p_lookup_type           => 'DAY_CODE'
3855           ,p_lookup_code           => p_term_start_day_cd
3856           ,p_validation_start_date => p_validation_start_date
3857           ,p_validation_end_date   => p_validation_end_date
3858           ,p_effective_date        => p_effective_date) then
3859       --
3860       -- raise error as does not exist as lookup
3861       --
3862       hr_utility.set_message(800,'HR_LOOKUP_DOES_NOT_EXIST');
3863       hr_utility.raise_error;
3864       --
3865     end if;
3866     --
3867   end if;
3868   --
3869 if g_debug then
3870   hr_utility.set_location('Leaving:'||l_proc,10);
3871 end if;
3872   --
3873 end chk_term_start_day_cd;
3874 --
3875 --
3876 -- ----------------------------------------------------------------------------
3877 -- |------< chk_seasonal_flag >------|
3878 -- ----------------------------------------------------------------------------
3879 --
3880 -- Description
3881 --   This procedure is used to check that the lookup value is valid.
3882 --
3883 -- Pre Conditions
3884 --   None.
3885 --
3886 -- In Parameters
3887 --   position_id                   PK of record being inserted or updated.
3888 --   p_seasonal_flag               Value of lookup code.
3889 --   validation_start_date
3890 --   validation_end_Date
3891 --   date_effective
3892 --   effective_date                effective date
3893 --   object_version_number         Object version number of record being
3894 --                         inserted or updated.
3895 --
3896 -- Post Success
3897 --   Processing continues
3898 --
3899 -- Post Failure
3900 --   Error handled by procedure
3901 --
3902 -- Access Status
3903 --   Internal table handler use only.
3904 --
3905 Procedure chk_seasonal_flag
3906   (p_position_id             in number
3907   ,p_seasonal_flag    in varchar2
3908   ,p_effective_date          in date
3909   ,p_validation_start_date   in date
3910   ,p_validation_end_date     in date
3911   ,p_object_version_number   in number) is
3912   --
3913   l_proc         varchar2(72) ;
3914   l_api_updating boolean;
3915   --
3916 Begin
3917   --
3918 if g_debug then
3919   l_proc          := g_package||'chk_seasonal_flag';
3920   hr_utility.set_location('Entering:'||l_proc, 5);
3921 end if;
3922   --
3923   l_api_updating := hr_psf_shd.api_updating
3924     (p_position_id            => p_position_id
3925     ,p_effective_date         => p_effective_date
3926     ,p_object_version_number  => p_object_version_number);
3927   --
3928   if (l_api_updating
3929       and p_seasonal_flag
3930       <> nvl(hr_psf_shd.g_old_rec.seasonal_flag,hr_api.g_varchar2)
3931       or not l_api_updating)
3932       and p_seasonal_flag is not null then
3933     --
3934     -- check if value of lookup falls within lookup type.
3935     --
3936     if hr_api.not_exists_in_dt_hr_lookups
3937           (p_lookup_type           => 'YES_NO'
3938           ,p_lookup_code           => p_seasonal_flag
3939           ,p_validation_start_date => p_validation_start_date
3940           ,p_validation_end_date   => p_validation_end_date
3941           ,p_effective_date        => p_effective_date) then
3942       --
3943       -- raise error as does not exist as lookup
3944       --
3945       hr_utility.set_message(800,'HR_LOOKUP_DOES_NOT_EXIST');
3946       hr_utility.raise_error;
3947       --
3948     end if;
3949     --
3950   end if;
3951   --
3952 if g_debug then
3953   hr_utility.set_location('Leaving:'||l_proc,10);
3954 end if;
3955   --
3956 end chk_seasonal_flag;
3957 --
3958 --
3959 -- ----------------------------------------------------------------------------
3960 -- |------< chk_review_flag >------|
3961 -- ----------------------------------------------------------------------------
3962 --
3963 -- Description
3964 --   This procedure is used to check that the lookup value is valid.
3965 --
3966 -- Pre Conditions
3967 --   None.
3968 --
3969 -- In Parameters
3970 --   position_id                   PK of record being inserted or updated.
3971 --   p_review_flag                 Value of lookup code.
3972 --   validation_start_date
3973 --   validation_end_Date
3974 --   date_effective
3975 --   effective_date                effective date
3976 --   object_version_number         Object version number of record being
3977 --
3978 -- Post Success
3979 --   Processing continues
3980 --
3981 -- Post Failure
3982 --   Error handled by procedure
3983 --
3984 -- Access Status
3985 --   Internal table handler use only.
3986 --
3987 Procedure chk_review_flag
3988   (p_position_id             in number
3989   ,p_review_flag    in varchar2
3990   ,p_effective_date          in date
3991   ,p_validation_start_date   in date
3992   ,p_validation_end_date     in date
3993   ,p_object_version_number   in number) is
3994   --
3995   l_proc         varchar2(72) ;
3996   l_api_updating boolean;
3997   --
3998 Begin
3999   --
4000 if g_debug then
4001   l_proc         := g_package||'chk_review_flag';
4002   hr_utility.set_location('Entering:'||l_proc, 5);
4003 end if;
4004   --
4005   l_api_updating := hr_psf_shd.api_updating
4006     (p_position_id            => p_position_id
4007     ,p_effective_date         => p_effective_date
4008     ,p_object_version_number  => p_object_version_number);
4009   --
4010   if (l_api_updating
4011       and p_review_flag
4012       <> nvl(hr_psf_shd.g_old_rec.review_flag,hr_api.g_varchar2)
4013       or not l_api_updating)
4014       and p_review_flag is not null then
4015     --
4016     -- check if value of lookup falls within lookup type.
4017     --
4018     if hr_api.not_exists_in_dt_hr_lookups
4019           (p_lookup_type           => 'YES_NO'
4020           ,p_lookup_code           => p_review_flag
4021           ,p_validation_start_date => p_validation_start_date
4022           ,p_validation_end_date   => p_validation_end_date
4023           ,p_effective_date        => p_effective_date) then
4024       --
4025       -- raise error as does not exist as lookup
4026       --
4027       hr_utility.set_message(800,'HR_LOOKUP_DOES_NOT_EXIST');
4028       hr_utility.raise_error;
4029       --
4030     end if;
4031     --
4032   end if;
4033   --
4034 if g_debug then
4035   hr_utility.set_location('Leaving:'||l_proc,10);
4036 end if;
4037   --
4038 end chk_review_flag;
4039 --
4040 --
4041 -- ----------------------------------------------------------------------------
4042 -- |------< chk_replacement_required_flag >------|
4043 -- ----------------------------------------------------------------------------
4044 --
4045 -- Description
4046 --   This procedure is used to check that the lookup value is valid.
4047 --
4048 -- Pre Conditions
4049 --   None.
4050 --
4051 -- In Parameters
4052 --   position_id                   PK of record being inserted or updated.
4053 --   p_replacement_required_flag                 Value of lookup code.
4054 --   validation_start_date
4055 --   validation_end_Date
4056 --   date_effective
4057 --   effective_date                effective date
4058 --   object_version_number         Object version number of record being
4059 --
4060 -- Post Success
4061 --   Processing continues
4062 --
4063 -- Post Failure
4064 --   Error handled by procedure
4065 --
4066 -- Access Status
4067 --   Internal table handler use only.
4068 --
4069 Procedure chk_replacement_required_flag
4070   (p_position_id               in number
4071   ,p_replacement_required_flag in varchar2
4072   ,p_effective_date            in date
4073   ,p_validation_start_date     in date
4074   ,p_validation_end_date       in date
4075   ,p_object_version_number     in number) is
4076   --
4077   l_proc         varchar2(72) ;
4078   l_api_updating boolean;
4079   --
4080 Begin
4081   --
4082 if g_debug then
4083 l_proc       := g_package||'chk_replacement_required_flag';
4084   hr_utility.set_location('Entering:'||l_proc, 5);
4085 end if;
4086   --
4087   l_api_updating := hr_psf_shd.api_updating
4088     (p_position_id            => p_position_id
4089     ,p_effective_date         => p_effective_date
4090     ,p_object_version_number  => p_object_version_number);
4091   --
4092   if (l_api_updating
4093       and p_replacement_required_flag
4094       <> nvl(hr_psf_shd.g_old_rec.replacement_required_flag,hr_api.g_varchar2)
4095       or not l_api_updating)
4096       and p_replacement_required_flag is not null then
4097     --
4098     -- check if value of lookup falls within lookup type.
4099     --
4100     if hr_api.not_exists_in_dt_hr_lookups
4101           (p_lookup_type           => 'YES_NO'
4102           ,p_lookup_code           => p_replacement_required_flag
4103           ,p_validation_start_date => p_validation_start_date
4104           ,p_validation_end_date   => p_validation_end_date
4105           ,p_effective_date        => p_effective_date) then
4106       --
4107       -- raise error as does not exist as lookup
4108       --
4109       hr_utility.set_message(800,'HR_LOOKUP_DOES_NOT_EXIST');
4110       hr_utility.raise_error;
4111       --
4112     end if;
4113     --
4114   end if;
4115   --
4116 if g_debug then
4117   hr_utility.set_location('Leaving:'||l_proc,10);
4118 end if;
4119   --
4120 end chk_replacement_required_flag;
4121 --
4122 --
4123 -- ----------------------------------------------------------------------------
4124 -- |------< chk_probation_period_unit_cd >------|
4125 -- ----------------------------------------------------------------------------
4126 --
4127 -- Description
4128 --   This procedure is used to check that the lookup value is valid.
4129 --
4130 -- Pre Conditions
4131 --   None.
4132 --
4133 -- In Parameters
4134 --   position_id                   PK of record being inserted or updated.
4135 --   p_probation_period_unit_cd                 Value of lookup code.
4136 --   validation_start_date
4137 --   validation_end_Date
4138 --   date_effective
4139 --   effective_date                effective date
4140 --   object_version_number         Object version number of record being
4141 --
4142 -- Post Success
4143 --   Processing continues
4144 --
4145 -- Post Failure
4146 --   Error handled by procedure
4147 --
4148 -- Access Status
4149 --   Internal table handler use only.
4150 --
4151 Procedure chk_probation_period_unit_cd
4152   (p_position_id               in number
4153   ,p_probation_period_unit_cd in varchar2
4154   ,p_effective_date            in date
4155   ,p_validation_start_date     in date
4156   ,p_validation_end_date       in date
4157   ,p_object_version_number     in number) is
4158   --
4159   l_proc         varchar2(72);
4160   l_api_updating boolean;
4161   --
4162 Begin
4163   --
4164 if g_debug then
4165   l_proc   := g_package||'chk_probation_period_unit_cd';
4166   hr_utility.set_location('Entering:'||l_proc, 5);
4167 end if;
4168   --
4169   l_api_updating := hr_psf_shd.api_updating
4170     (p_position_id            => p_position_id
4171     ,p_effective_date         => p_effective_date
4172     ,p_object_version_number  => p_object_version_number);
4173   --
4174   if (l_api_updating
4175       and p_probation_period_unit_cd
4176       <> nvl(hr_psf_shd.g_old_rec.probation_period_unit_cd,hr_api.g_varchar2)
4177       or not l_api_updating)
4178       and p_probation_period_unit_cd is not null then
4179     --
4180     -- check if value of lookup falls within lookup type.
4181     --
4182     if hr_api.not_exists_in_dt_hr_lookups
4183           (p_lookup_type           => 'FREQUENCY'
4184           ,p_lookup_code           => p_probation_period_unit_cd
4185           ,p_validation_start_date => p_validation_start_date
4186           ,p_validation_end_date   => p_validation_end_date
4187           ,p_effective_date        => p_effective_date) then
4188       --
4189       -- raise error as does not exist as lookup
4190       --
4191       hr_utility.set_message(800,'HR_LOOKUP_DOES_NOT_EXIST');
4192       hr_utility.raise_error;
4193       --
4194     end if;
4195     --
4196   end if;
4197   --
4198 if g_debug then
4199   hr_utility.set_location('Leaving:'||l_proc,10);
4200 end if;
4201   --
4202 end chk_probation_period_unit_cd;
4203 --
4204 --
4205 -- ----------------------------------------------------------------------------
4206 -- |------< chk_permit_recruitment_flag >------|
4207 -- ----------------------------------------------------------------------------
4208 --
4209 -- Description
4210 --   This procedure is used to check that the lookup value is valid.
4211 --
4212 -- Pre Conditions
4213 --   None.
4214 --
4215 -- In Parameters
4216 --   position_id                   PK of record being inserted or updated.
4217 --   p_permit_recruitment_flag                 Value of lookup code.
4218 --   validation_start_date
4219 --   validation_end_Date
4220 --   date_effective
4221 --   effective_date                effective date
4222 --   object_version_number         Object version number of record being
4223 --
4224 -- Post Success
4225 --   Processing continues
4226 --
4227 -- Post Failure
4228 --   Error handled by procedure
4229 --
4230 -- Access Status
4231 --   Internal table handler use only.
4232 --
4233 Procedure chk_permit_recruitment_flag
4234   (p_position_id               in number
4235   ,p_permit_recruitment_flag   in varchar2
4236   ,p_effective_date            in date
4237   ,p_validation_start_date     in date
4238   ,p_validation_end_date       in date
4239   ,p_object_version_number     in number) is
4240   --
4241   l_proc         varchar2(72) ;
4242   l_api_updating boolean;
4243   --
4244 Begin
4245   --
4246 if g_debug then
4247   l_proc         := g_package||'chk_permit_recruitment_flag';
4248   hr_utility.set_location('Entering:'||l_proc, 5);
4249 end if;
4250   --
4251   l_api_updating := hr_psf_shd.api_updating
4252     (p_position_id            => p_position_id
4253     ,p_effective_date         => p_effective_date
4254     ,p_object_version_number  => p_object_version_number);
4255   --
4256   if (l_api_updating
4257       and p_permit_recruitment_flag
4258       <> nvl(hr_psf_shd.g_old_rec.permit_recruitment_flag,hr_api.g_varchar2)
4259       or not l_api_updating)
4260       and p_permit_recruitment_flag is not null then
4261     --
4262     -- check if value of lookup falls within lookup type.
4263     --
4264     if hr_api.not_exists_in_dt_hr_lookups
4265           (p_lookup_type           => 'YES_NO'
4266           ,p_lookup_code           => p_permit_recruitment_flag
4267           ,p_validation_start_date => p_validation_start_date
4268           ,p_validation_end_date   => p_validation_end_date
4269           ,p_effective_date        => p_effective_date) then
4270       --
4271       -- raise error as does not exist as lookup
4272       --
4273       hr_utility.set_message(800,'HR_LOOKUP_DOES_NOT_EXIST');
4274       hr_utility.raise_error;
4275       --
4276     end if;
4277     --
4278   end if;
4279   --
4280 if g_debug then
4281   hr_utility.set_location('Leaving:'||l_proc,10);
4282 end if;
4283   --
4284 end chk_permit_recruitment_flag;
4285 --
4286 --
4287 -- ----------------------------------------------------------------------------
4288 -- |------< chk_permanent_temporary_flag >------|
4289 -- ----------------------------------------------------------------------------
4290 --
4291 -- Description
4292 --   This procedure is used to check that the lookup value is valid.
4293 --
4294 -- Pre Conditions
4295 --   None.
4296 --
4297 -- In Parameters
4298 --   position_id                   PK of record being inserted or updated.
4299 --   permanent_temporary_flag                 Value of lookup code.
4300 --   validation_start_date
4301 --   validation_end_Date
4302 --   date_effective
4303 --   effective_date                effective date
4304 --   object_version_number         Object version number of record being
4305 --
4306 -- Post Success
4307 --   Processing continues
4308 --
4309 -- Post Failure
4310 --   Error handled by procedure
4311 --
4312 -- Access Status
4313 --   Internal table handler use only.
4314 --
4315 Procedure chk_permanent_temporary_flag
4316   (p_position_id               in number
4317   ,p_permanent_temporary_flag   in varchar2
4318   ,p_effective_date            in date
4319   ,p_validation_start_date     in date
4320   ,p_validation_end_date       in date
4321   ,p_object_version_number     in number) is
4322   --
4323   l_proc         varchar2(72) ;
4324   l_api_updating boolean;
4325   --
4326 Begin
4327   --
4328 if g_debug then
4329   l_proc          := g_package||'chk_permanent_temporary_flag';
4330   hr_utility.set_location('Entering:'||l_proc, 5);
4331 end if;
4332   --
4333   l_api_updating := hr_psf_shd.api_updating
4334     (p_position_id            => p_position_id
4335     ,p_effective_date         => p_effective_date
4336     ,p_object_version_number  => p_object_version_number);
4337   --
4338   if (l_api_updating
4339       and p_permanent_temporary_flag
4340       <> nvl(hr_psf_shd.g_old_rec.permanent_temporary_flag,hr_api.g_varchar2)
4341       or not l_api_updating)
4342       and p_permanent_temporary_flag is not null then
4343     --
4344     -- check if value of lookup falls within lookup type.
4345     --
4346     if hr_api.not_exists_in_dt_hr_lookups
4347           (p_lookup_type           => 'YES_NO'
4348           ,p_lookup_code           => p_permanent_temporary_flag
4349           ,p_validation_start_date => p_validation_start_date
4350           ,p_validation_end_date   => p_validation_end_date
4351           ,p_effective_date        => p_effective_date) then
4352       --
4353       -- raise error as does not exist as lookup
4354       --
4355       hr_utility.set_message(800,'HR_LOOKUP_DOES_NOT_EXIST');
4356       hr_utility.raise_error;
4357       --
4358     end if;
4359     --
4360   end if;
4361   --
4362 if g_debug then
4363   hr_utility.set_location('Leaving:'||l_proc,10);
4364 end if;
4365   --
4366 end chk_permanent_temporary_flag;
4367 --
4368 --
4369 -- ----------------------------------------------------------------------------
4370 -- |------< chk_pay_term_end_month_cd >------|
4371 -- ----------------------------------------------------------------------------
4372 --
4373 -- Description
4374 --   This procedure is used to check that the lookup value is valid.
4375 --
4376 -- Pre Conditions
4377 --   None.
4378 --
4379 -- In Parameters
4380 --   position_id                   PK of record being inserted or updated.
4381 --   pay_term_end_month_cd                 Value of lookup code.
4382 --   validation_start_date
4383 --   validation_end_Date
4384 --   date_effective
4385 --   effective_date                effective date
4386 --   object_version_number         Object version number of record being
4387 --
4388 -- Post Success
4389 --   Processing continues
4390 --
4391 -- Post Failure
4392 --   Error handled by procedure
4393 --
4394 -- Access Status
4395 --   Internal table handler use only.
4396 --
4397 Procedure chk_pay_term_end_month_cd
4398   (p_position_id               in number
4399   ,p_pay_term_end_month_cd   in varchar2
4400   ,p_effective_date            in date
4401   ,p_validation_start_date     in date
4402   ,p_validation_end_date       in date
4403   ,p_object_version_number     in number) is
4404   --
4405   l_proc         varchar2(72);
4406   l_api_updating boolean;
4407   --
4408 Begin
4409   --
4410 if g_debug then
4411   l_proc          := g_package||'chk_pay_term_end_month_cd';
4412   hr_utility.set_location('Entering:'||l_proc, 5);
4413 end if;
4414   --
4415   l_api_updating := hr_psf_shd.api_updating
4416     (p_position_id            => p_position_id
4417     ,p_effective_date         => p_effective_date
4418     ,p_object_version_number  => p_object_version_number);
4419   --
4420   if (l_api_updating
4421       and p_pay_term_end_month_cd
4422       <> nvl(hr_psf_shd.g_old_rec.pay_term_end_month_cd,hr_api.g_varchar2)
4423       or not l_api_updating)
4424       and p_pay_term_end_month_cd is not null then
4425     --
4426     -- check if value of lookup falls within lookup type.
4427     --
4428     if hr_api.not_exists_in_dt_hr_lookups
4429           (p_lookup_type           => 'MONTH_CODE'
4430           ,p_lookup_code           => p_pay_term_end_month_cd
4431           ,p_validation_start_date => p_validation_start_date
4432           ,p_validation_end_date   => p_validation_end_date
4433           ,p_effective_date        => p_effective_date) then
4434       --
4435       -- raise error as does not exist as lookup
4436       --
4437       hr_utility.set_message(800,'HR_LOOKUP_DOES_NOT_EXIST');
4438       hr_utility.raise_error;
4439       --
4440     end if;
4441     --
4442   end if;
4443   --
4444 if g_debug then
4445   hr_utility.set_location('Leaving:'||l_proc,10);
4446 end if;
4447   --
4448 end chk_pay_term_end_month_cd;
4449 --
4450 --
4451 -- ----------------------------------------------------------------------------
4452 -- |------< chk_pay_term_end_day_cd >------|
4453 -- ----------------------------------------------------------------------------
4454 --
4455 -- Description
4456 --   This procedure is used to check that the lookup value is valid.
4457 --
4458 -- Pre Conditions
4459 --   None.
4460 --
4461 -- In Parameters
4462 --   position_id                   PK of record being inserted or updated.
4463 --   pay_term_end_day_cd                 Value of lookup code.
4464 --   validation_start_date
4465 --   validation_end_Date
4466 --   date_effective
4467 --   effective_date                effective date
4468 --   object_version_number         Object version number of record being
4469 --
4470 -- Post Success
4471 --   Processing continues
4472 --
4473 -- Post Failure
4474 --   Error handled by procedure
4475 --
4476 -- Access Status
4477 --   Internal table handler use only.
4478 --
4479 Procedure chk_pay_term_end_day_cd
4480   (p_position_id               in number
4481   ,p_pay_term_end_day_cd   in varchar2
4482   ,p_effective_date            in date
4483   ,p_validation_start_date     in date
4484   ,p_validation_end_date       in date
4485   ,p_object_version_number     in number) is
4486   --
4487   l_proc         varchar2(72) ;
4488   l_api_updating boolean;
4489   --
4490 Begin
4491   --
4492 if g_debug then
4493   l_proc          := g_package||'chk_pay_term_end_day_cd';
4494   hr_utility.set_location('Entering:'||l_proc, 5);
4495 end if;
4496   --
4497   l_api_updating := hr_psf_shd.api_updating
4498     (p_position_id            => p_position_id
4499     ,p_effective_date         => p_effective_date
4500     ,p_object_version_number  => p_object_version_number);
4501   --
4502   if (l_api_updating
4503       and p_pay_term_end_day_cd
4504       <> nvl(hr_psf_shd.g_old_rec.pay_term_end_day_cd,hr_api.g_varchar2)
4505       or not l_api_updating)
4506       and p_pay_term_end_day_cd is not null then
4507     --
4508     -- check if value of lookup falls within lookup type.
4509     --
4510     if hr_api.not_exists_in_dt_hr_lookups
4511           (p_lookup_type           => 'DAY_CODE'
4512           ,p_lookup_code           => p_pay_term_end_day_cd
4513           ,p_validation_start_date => p_validation_start_date
4514           ,p_validation_end_date   => p_validation_end_date
4515           ,p_effective_date        => p_effective_date) then
4516       --
4517       -- raise error as does not exist as lookup
4518       --
4519       hr_utility.set_message(800,'HR_LOOKUP_DOES_NOT_EXIST');
4520       hr_utility.raise_error;
4521       --
4522     end if;
4523     --
4524   end if;
4525   --
4526 if g_debug then
4527   hr_utility.set_location('Leaving:'||l_proc,10);
4528 end if;
4529   --
4530 end chk_pay_term_end_day_cd;
4531 --
4532 --
4533 -- ----------------------------------------------------------------------------
4534 -- |------< chk_overlap_unit_cd >------|
4535 -- ----------------------------------------------------------------------------
4536 --
4537 -- Description
4538 --   This procedure is used to check that the lookup value is valid.
4539 --
4540 -- Pre Conditions
4541 --   None.
4542 --
4543 -- In Parameters
4544 --   position_id                   PK of record being inserted or updated.
4545 --   overlap_unit_cd                 Value of lookup code.
4546 --   validation_start_date
4547 --   validation_end_Date
4548 --   date_effective
4549 --   effective_date                effective date
4550 --   object_version_number         Object version number of record being
4551 --
4552 -- Post Success
4553 --   Processing continues
4554 --
4555 -- Post Failure
4556 --   Error handled by procedure
4557 --
4558 -- Access Status
4559 --   Internal table handler use only.
4560 --
4561 Procedure chk_overlap_unit_cd
4562   (p_position_id               in number
4563   ,p_overlap_unit_cd   in varchar2
4564   ,p_effective_date            in date
4565   ,p_validation_start_date     in date
4566   ,p_validation_end_date       in date
4567   ,p_object_version_number     in number) is
4568   --
4569   l_proc         varchar2(72);
4570   l_api_updating boolean;
4571   --
4572 Begin
4573   --
4574 if g_debug then
4575   l_proc          := g_package||'chk_overlap_unit_cd';
4576   hr_utility.set_location('Entering:'||l_proc, 5);
4577 end if;
4578   --
4579   l_api_updating := hr_psf_shd.api_updating
4580     (p_position_id            => p_position_id
4581     ,p_effective_date         => p_effective_date
4582     ,p_object_version_number  => p_object_version_number);
4583   --
4584   if (l_api_updating
4585       and p_overlap_unit_cd
4586       <> nvl(hr_psf_shd.g_old_rec.overlap_unit_cd,hr_api.g_varchar2)
4587       or not l_api_updating)
4588       and p_overlap_unit_cd is not null then
4589     --
4590     -- check if value of lookup falls within lookup type.
4591     --
4592     if hr_api.not_exists_in_dt_hr_lookups
4593           (p_lookup_type           => 'FREQUENCY'
4594           ,p_lookup_code           => p_overlap_unit_cd
4595           ,p_validation_start_date => p_validation_start_date
4596           ,p_validation_end_date   => p_validation_end_date
4597           ,p_effective_date        => p_effective_date) then
4598       --
4599       -- raise error as does not exist as lookup
4600       --
4601       hr_utility.set_message(800,'HR_LOOKUP_DOES_NOT_EXIST');
4602       hr_utility.raise_error;
4603       --
4604     end if;
4605     --
4606   end if;
4607   --
4608 if g_debug then
4609   hr_utility.set_location('Leaving:'||l_proc,10);
4610 end if;
4611   --
4612 end chk_overlap_unit_cd;
4613 --
4614 --
4615 -- ----------------------------------------------------------------------------
4616 -- |------< chk_bargaining_unit_cd >------|
4617 -- ----------------------------------------------------------------------------
4618 --
4619 -- Description
4620 --   This procedure is used to check that the lookup value is valid.
4621 --
4622 -- Pre Conditions
4623 --   None.
4624 --
4625 -- In Parameters
4626 --   position_id                   PK of record being inserted or updated.
4627 --   bargaining_unit_cd                 Value of lookup code.
4628 --   validation_start_date
4629 --   validation_end_Date
4630 --   date_effective
4631 --   effective_date                effective date
4632 --   object_version_number         Object version number of record being
4633 --
4634 -- Post Success
4635 --   Processing continues
4636 --
4637 -- Post Failure
4638 --   Error handled by procedure
4639 --
4640 -- Access Status
4641 --   Internal table handler use only.
4642 --
4643 Procedure chk_bargaining_unit_cd
4644   (p_position_id               in number
4645   ,p_bargaining_unit_cd   in varchar2
4646   ,p_effective_date            in date
4647   ,p_validation_start_date     in date
4648   ,p_validation_end_date       in date
4649   ,p_object_version_number     in number) is
4650   --
4651   l_proc         varchar2(72);
4652   l_api_updating boolean;
4653   --
4654 Begin
4655   --
4656 if g_debug then
4657   l_proc          := g_package||'chk_bargaining_unit_cd';
4658   hr_utility.set_location('Entering:'||l_proc, 5);
4659 end if;
4660   --
4661   l_api_updating := hr_psf_shd.api_updating
4662     (p_position_id            => p_position_id
4663     ,p_effective_date         => p_effective_date
4664     ,p_object_version_number  => p_object_version_number);
4665   --
4666   if (l_api_updating
4667       and p_bargaining_unit_cd
4668       <> nvl(hr_psf_shd.g_old_rec.bargaining_unit_cd,hr_api.g_varchar2)
4669       or not l_api_updating)
4670       and p_bargaining_unit_cd is not null then
4671     --
4672     -- check if value of lookup falls within lookup type.
4673     --
4674     if hr_api.not_exists_in_dt_hr_lookups
4675           (p_lookup_type           => 'BARGAINING_UNIT_CODE'
4676           ,p_lookup_code           => p_bargaining_unit_cd
4677           ,p_validation_start_date => p_validation_start_date
4678           ,p_validation_end_date   => p_validation_end_date
4679           ,p_effective_date        => p_effective_date) then
4680       --
4681       -- raise error as does not exist as lookup
4682       --
4683       hr_utility.set_message(800,'HR_LOOKUP_DOES_NOT_EXIST');
4684       hr_utility.raise_error;
4685       --
4686     end if;
4687     --
4688   end if;
4689   --
4690 if g_debug then
4691   hr_utility.set_location('Leaving:'||l_proc,10);
4692 end if;
4693   --
4694 end chk_bargaining_unit_cd;
4695 --
4696 -- ------------------ <chk_fte> ---------------------
4697 --
4698 Procedure chk_fte
4699   (p_position_id               in number
4700   ,p_fte                       in number
4701   ,p_position_type             in varchar2
4702   ,p_effective_date            in date
4703   ,p_validation_start_date     in date
4704   ,p_validation_end_date       in date
4705   ,p_object_version_number     in number) is
4706   --
4707   l_proc         varchar2(72) ;
4708   l_api_updating boolean;
4709   --
4710 Begin
4711   --
4712 if g_debug then
4713  l_proc          := g_package||'chk_fte';
4714   hr_utility.set_location('Entering:'||l_proc, 5);
4715 end if;
4716   --
4717   hr_api.mandatory_arg_error
4718       (p_api_name       => l_proc
4719       ,p_argument       => 'position type'
4720       ,p_argument_value => p_position_type);
4721     --
4722   --
4723   hr_api.mandatory_arg_error
4724       (p_api_name       => l_proc
4725       ,p_argument       => 'validation start date'
4726       ,p_argument_value => p_validation_start_date);
4727     --
4728   --
4729   hr_api.mandatory_arg_error
4730       (p_api_name       => l_proc
4731       ,p_argument       => 'effective date'
4732       ,p_argument_value => p_effective_date);
4733     --
4734   l_api_updating := hr_psf_shd.api_updating
4735     (p_position_id            => p_position_id
4736     ,p_effective_date         => p_effective_date
4737     ,p_object_version_number  => p_object_version_number);
4738   --
4739   if ((l_api_updating
4740       and ((p_fte <> nvl(hr_psf_shd.g_old_rec.fte,hr_api.g_number))
4741          or (p_position_type <> nvl(hr_psf_shd.g_old_rec.position_type,
4742                      hr_api.g_varchar2))))
4743       or not l_api_updating) then
4744       --
4745       if p_position_type <> 'NONE' then
4746         if ( p_fte is null and p_position_type <> 'POOLED') then
4747           hr_utility.set_message(800,'HR_FTE_NULL_INV_FOR_POS_TYPE');
4748           hr_utility.raise_error;
4749         elsif p_position_type = 'SINGLE' then
4750           if not (p_fte <= 1) then
4751             hr_utility.set_message(800,'HR_FTE_MUST_BE_LESS_OR_EQ_ONE');
4752             hr_utility.raise_error;
4753           end if;
4754         end if;
4755       end if;
4756       --
4757   end if;
4758   --
4759 end chk_fte;
4760 --
4761 -- ------------------ <chk_max_persons> ---------------------
4762 --
4763 Procedure chk_max_persons
4764   (p_position_id               in number
4765   ,p_max_persons               in number
4766   ,p_position_type             in varchar2
4767   ,p_effective_date            in date
4768   ,p_object_version_number     in number) is
4769   --
4770   l_proc         varchar2(72) ;
4771   l_api_updating boolean;
4772   --
4773 Begin
4774   --
4775 if g_debug then
4776  l_proc          := g_package||'p_max_persons';
4777   hr_utility.set_location('Entering:'||l_proc, 5);
4778   hr_utility.set_location('Entering:'||p_max_persons, 2);
4779 
4780 hr_utility.set_location('Entering:'||
4781      nvl(hr_psf_shd.g_old_rec.max_persons,hr_api.g_number),3);
4782 end if;
4783   --
4784   hr_api.mandatory_arg_error
4785       (p_api_name       => l_proc
4786       ,p_argument       => 'position type'
4787       ,p_argument_value => p_position_type);
4788   --
4789   hr_api.mandatory_arg_error
4790       (p_api_name       => l_proc
4791       ,p_argument       => 'effective date'
4792       ,p_argument_value => p_effective_date);
4793   --
4794   l_api_updating := hr_psf_shd.api_updating
4795     (p_position_id            => p_position_id
4796     ,p_effective_date         => p_effective_date
4797     ,p_object_version_number  => p_object_version_number);
4798   --
4799   if ((l_api_updating
4800     and ((nvl(p_max_persons,hr_api.g_number) <>
4801        nvl(hr_psf_shd.g_old_rec.max_persons,hr_api.g_number))
4802          or (p_position_type <> nvl(hr_psf_shd.g_old_rec.position_type,
4803                      hr_api.g_varchar2))))
4804       or not l_api_updating) then
4805       --
4806       if (p_position_type = 'SINGLE')
4807         and ((p_max_persons is NULL) or (p_max_persons <> 1 )) then
4808           hr_utility.set_message(800,'HR_POS_MAX_PERSONS_NE_ONE');
4809           hr_utility.raise_error;
4810       elsif (p_position_type = 'SHARED') and (p_max_persons IS NULL )
4811        then
4812           hr_utility.set_message(800,'HR_MAX_PERS_NULL_INV_POS_TYPE');
4813           hr_utility.raise_error;
4814       elsif (p_position_type = 'SHARED') and (p_max_persons < 1 )
4815        then
4816           hr_utility.set_message(800,'PER_INVALID_SHARED_MAX_PERSON');
4817           hr_utility.raise_error;
4818       end if;
4819       --
4820   end if;
4821   --
4822 end chk_max_persons;
4823 --
4824 -- ---------------------------------------------------------------------------
4825 -- --------------------------< chk_resesrved_fte >----------------------------
4826 -- ---------------------------------------------------------------------------
4827 
4828 Procedure chk_reserved_fte
4829   (p_position_id               in number
4830   ,p_fte                       in number
4831   ,p_position_type             in varchar2
4832   ,p_effective_date            in date
4833   ,p_validation_start_date     in date
4834   ,p_validation_end_date       in date
4835   ,p_object_version_number     in number) is
4836 
4837   l_proc         varchar2(72) ;
4838   l_api_updating boolean;
4839   l_rsv_fte   number;
4840 
4841 -- Cursor changed for Bug 8912106
4842 cursor csr_valid_fte(p_position_id number, p_effective_date date) is
4843 select sum(poei_information6) fte
4844 from (SELECT poei_information6, poei_information3, poei_information4, ROWNUM rn FROM per_position_extra_info
4845 where position_id = p_position_id
4846 and information_type= 'PER_RESERVED') PEI
4847 where p_effective_date
4848   between fnd_date.canonical_to_date(poei_information3)
4849   and nvl(fnd_date.canonical_to_date(poei_information4),hr_general.end_of_time);
4850   --
4851 cursor csr_valid_eff_date(p_position_id number,
4852                           p_validation_start_date date,
4853                           p_validation_end_date date) is
4854 select p_validation_start_date start_date
4855 from dual
4856 union
4857 select effective_start_date start_date
4858 from hr_all_positions_f
4859 where effective_start_date between p_validation_start_date
4860 and p_validation_end_date
4861 and position_id = p_position_id
4862 union
4863 select start_date
4864 from (select fnd_date.canonical_to_date(poei_information3) start_date, ROWNUM rn		-- bug 9387763
4865       from per_position_extra_info
4866       where position_id = p_position_id
4867       and information_type = 'PER_RESERVED') a
4868 where a.start_date between p_validation_start_date and p_validation_end_date;
4869 Begin
4870   --
4871 if g_debug then
4872   l_proc       := 'chk_reserved_fte';
4873   hr_utility.set_location('Entering:'||l_proc, 5);
4874 end if;
4875   --
4876   hr_api.mandatory_arg_error
4877       (p_api_name       => l_proc
4878       ,p_argument       => 'position type'
4879       ,p_argument_value => p_position_type);
4880     --
4881   --
4882   hr_api.mandatory_arg_error
4883       (p_api_name       => l_proc
4884       ,p_argument       => 'validation start date'      ,p_argument_value => p_validation_start_date);
4885     --
4886   --
4887   hr_api.mandatory_arg_error
4888       (p_api_name       => l_proc
4889       ,p_argument       => 'effective date'
4890       ,p_argument_value => p_effective_date);
4891     --
4892   l_api_updating := hr_psf_shd.api_updating
4893     (p_position_id            => p_position_id
4894     ,p_effective_date         => p_effective_date
4895     ,p_object_version_number  => p_object_version_number);
4896   --
4897 
4898   if (l_api_updating
4899       and p_fte
4900       <> nvl(hr_psf_shd.g_old_rec.fte,hr_api.g_number)
4901       ) then
4902       --
4903     for r2 in csr_valid_eff_date(p_position_id, p_validation_start_date, p_validation_end_date) loop
4904     if p_position_type ='SHARED' or p_position_type ='SINGLE' then
4905         open csr_valid_fte(p_position_id, r2.start_date);
4906          fetch csr_valid_fte into l_rsv_fte;
4907          if (p_fte < l_rsv_fte) then
4908             hr_utility.set_message(800,'PER_FTE_LT_RSVD_FTE');
4909             hr_utility.set_message_token('POSITION_FTE',p_fte);
4910             hr_utility.set_message_token('RESERVED_FTE',l_rsv_fte);
4911             hr_utility.set_message_token('EFFECTIVE_DATE',r2.start_date);
4912             hr_utility.raise_error;
4913          else
4914 if g_debug then
4915             hr_utility.set_location(l_proc, 3);
4916 end if;
4917          end if;
4918       --
4919        close csr_valid_fte;
4920     end if;
4921     end loop;
4922   end if;
4923   --
4924 end chk_reserved_fte;
4925 
4926 -- ---------------------------------------------------------------------------
4927 -- --------------------------< chk_proposed_fte_for_layoff >------------------
4928 -- ---------------------------------------------------------------------------
4929 Procedure chk_proposed_fte_for_layoff
4930 ( p_fte                      in number
4931  ,p_proposed_fte_for_layoff  in number
4932  ,p_proposed_date_for_layoff in date) is
4933 
4934  --
4935  l_proc    varchar2(30);
4936 Begin
4937   --
4938 if g_debug then
4939  l_proc    :='chk_proposed_fte_for_layoff';
4940   hr_utility.set_location('Entering:'||l_proc, 5);
4941 end if;
4942   --
4943   if p_proposed_fte_for_layoff is not null then
4944     if nvl(p_fte, 0) < p_proposed_fte_for_layoff then
4945       --
4946        hr_utility.set_message(800,'HR_FTE_TARGT_LT_LAYOFF_FTE');
4947        hr_utility.raise_error;
4948     end if;
4949     if p_proposed_date_for_layoff is null then
4950       --
4951        hr_utility.set_message(800,'HR_PROP_DT_LAYOFF_CANNOT_NULL');
4952        hr_utility.raise_error;
4953     end if;
4954   else
4955     if p_proposed_date_for_layoff is not null then
4956       --
4957        hr_utility.set_message(800,'HR_PROP_DT_LAYOFF_MUSTBE_NULL');
4958        hr_utility.raise_error;
4959     end if;
4960   end if;
4961 end chk_proposed_fte_for_layoff;
4962 --
4963 -- ----------------------------------------------------------------------------
4964 -- |--------------------------< chk_extended_pay >--------------------------|
4965 -- ----------------------------------------------------------------------------
4966 Procedure chk_extended_pay
4967   (p_position_id               in number
4968   ,p_work_period_type_cd       in varchar2
4969   ,p_term_start_day_cd         in varchar2
4970   ,p_term_start_month_cd       in varchar2
4971   ,p_pay_term_end_day_cd       in varchar2
4972   ,p_pay_term_end_month_cd     in varchar2
4973   ,p_work_term_end_day_cd      in varchar2
4974   ,p_work_term_end_month_cd    in varchar2 ) is
4975   --
4976   l_proc varchar2(30);
4977 Begin
4978   --
4979 if g_debug then
4980 l_proc :='chk_extended_flag';
4981   hr_utility.set_location('Entering:'||l_proc, 5);
4982 end if;
4983   --
4984   if p_work_period_type_cd = 'Y' then
4985 /*
4986     if p_pay_term_end_day_cd is null    or
4987        p_pay_term_end_month_cd is null  or
4988        p_work_term_end_day_cd is null   or
4989        p_work_term_end_month_cd is null     then
4990       --
4991        hr_utility.set_message(800,'HR_PAY_WORK_TERM_MUST_BE_ENTR');
4992        hr_utility.raise_error;
4993 */
4994     if (( (p_pay_term_end_day_cd is null and
4995           p_pay_term_end_month_cd is not null)  or
4996          (p_pay_term_end_day_cd is not null and
4997           p_pay_term_end_month_cd is null)) or
4998        ( (p_term_start_day_cd is null and
4999           p_term_start_month_cd is not null)  or
5000          (p_term_start_day_cd is not null and
5001           p_term_start_month_cd is null))) then
5002       --
5003        hr_utility.set_message(800,'HR_INVALID_PAY_TERM');
5004        hr_utility.raise_error;
5005     end if;
5006     if ( (p_work_term_end_day_cd is null and
5007           p_work_term_end_month_cd is not null)  or
5008          (p_work_term_end_day_cd is not null and
5009           p_work_term_end_month_cd is null)) then
5010       --
5011        hr_utility.set_message(800,'HR_INVALID_WORK_TERM');
5012        hr_utility.raise_error;
5013     end if;
5014   else
5015     if p_pay_term_end_day_cd is not null    or
5016        p_pay_term_end_month_cd is not null  or
5017        p_term_start_day_cd is not null    or
5018        p_term_start_month_cd is not null  or
5019        p_work_term_end_day_cd is not null   or
5020        p_work_term_end_month_cd is not null     then
5021       --
5022        hr_utility.set_message(800,'HR_PAY_WORK_TERM_MUST_BE_NULL');
5023        hr_utility.raise_error;
5024     end if;
5025   end if;
5026   --
5027 end chk_extended_pay;
5028 -- ----------------------------------------------------------------------------
5029 -- |--------------------------<  chk_seasonal_poi  >--------------------------|
5030 -- ----------------------------------------------------------------------------
5031 procedure chk_seasonal_poi
5032 (p_position_id              in number
5033   ,p_seasonal_flag          in varchar2
5034   ,p_effective_date            in date
5035   ,p_validation_start_date     in date
5036   ,p_validation_end_date       in date
5037   ,p_object_version_number     in number) is
5038 l_dummy             varchar2(1);
5039 l_api_updating     boolean;
5040 
5041 cursor c_seasonal is
5042 select 'X'
5043 from per_position_extra_info
5044 where position_id = p_position_id
5045 and information_type = 'PER_SEASONAL';
5046 begin
5047   l_api_updating := hr_psf_shd.api_updating
5048     (p_position_id            => p_position_id
5049     ,p_effective_date         => p_effective_date
5050     ,p_object_version_number  => p_object_version_number);
5051 
5052   if (l_api_updating
5053       and p_seasonal_flag
5054       <> nvl(hr_psf_shd.g_old_rec.seasonal_flag,hr_api.g_varchar2)
5055       and (p_seasonal_flag='N' or p_seasonal_flag is null)) then
5056     open c_seasonal;
5057     fetch c_seasonal into l_dummy;
5058     if c_seasonal%found then
5059           close c_seasonal;
5060           hr_utility.set_message(800,'HR_INV_SEASONAL_FLAG');
5061           hr_utility.raise_error;
5062     end if;
5063     close c_seasonal;
5064   end if;
5065 end;
5066 -- ----------------------------------------------------------------------------
5067 -- |--------------------------<   chk_overlap_poi  >--------------------------|
5068 -- ----------------------------------------------------------------------------
5069 procedure chk_overlap_poi
5070 (p_position_id              in number
5071   ,p_overlap_period         in number
5072   ,p_effective_date            in date
5073   ,p_validation_start_date     in date
5074   ,p_validation_end_date       in date
5075   ,p_object_version_number     in number) is
5076 l_proc varchar2(100) ;
5077 l_dummy             varchar2(1);
5078 l_api_updating     boolean;
5079 --
5080 cursor c_overlap is
5081 select 'X'
5082 from per_position_extra_info
5083 where position_id = p_position_id
5084 and information_type = 'PER_OVERLAP';
5085 begin
5086 if g_debug then
5087 l_proc  :='chk_overlap_poi';
5088   hr_utility.set_location('Entering:'||l_proc,10);
5089 end if;
5090   l_api_updating := hr_psf_shd.api_updating
5091     (p_position_id            => p_position_id
5092     ,p_effective_date         => p_effective_date
5093     ,p_object_version_number  => p_object_version_number);
5094 
5095   if (l_api_updating
5096       and nvl(p_overlap_period,-1)
5097       <> nvl(hr_psf_shd.g_old_rec.overlap_period,hr_api.g_number)
5098       and p_overlap_period is null) then
5099 if g_debug then
5100     hr_utility.set_location('Checking for Overlap Dates in Position Extra Info:'||l_proc,20);
5101 end if;
5102     open c_overlap;
5103     fetch c_overlap into l_dummy;
5104 if g_debug then
5105     hr_utility.set_location('Checked for Overlap Dates in Position Extra Info:'||l_proc,30);
5106 end if;
5107     if c_overlap%found then
5108 if g_debug then
5109     hr_utility.set_location('Overlap Dates Found in Position Extra Info:'||l_proc,40);
5110 end if;
5111           close c_overlap;
5112           hr_utility.set_message(800,'HR_INV_OVERLAP_PERIOD');
5113           hr_utility.raise_error;
5114     end if;
5115 if g_debug then
5116     hr_utility.set_location('Overlap Dates not Found in Position Extra Info:'||l_proc,40);
5117 end if;
5118     close c_overlap;
5119   end if;
5120 if g_debug then
5121   hr_utility.set_location('Leaving:'||l_proc,20);
5122 end if;
5123 end;
5124 -- ----------------------------------------------------------------------------
5125 -- |--------------------------< permit_extended_pay >-------------------------|
5126 -- ----------------------------------------------------------------------------
5127 function permit_extended_pay(p_position_id varchar2) return boolean is
5128 l_proc varchar2(100) ;
5129 l_position_family   varchar2(100);
5130 l_chk               boolean := false;
5131 cursor c1 is
5132 select poei_information3
5133 from per_position_extra_info
5134 where position_id = p_position_id
5135 and information_type = 'PER_FAMILY'
5136 and poei_information3 in ('ACADEMIC','FACULTY');
5137 begin
5138 if g_debug then
5139 l_proc  :='PERMIT_EXTENDED_PAY';
5140   hr_utility.set_location('Entering:'||l_proc,10);
5141 end if;
5142   if p_position_id is not null then
5143     open c1;
5144     fetch c1 into l_position_family;
5145     if c1%found then
5146 if g_debug then
5147       hr_utility.set_location('Academic/Faculty Position Extra info Found:'||l_proc,10);
5148 end if;
5149       close c1;
5150       return true;
5151     else
5152       close c1;
5153 if g_debug then
5154       hr_utility.set_location('Academic/Faculty Position Extra info not Found:'||l_proc,10);
5155 end if;
5156       return false;
5157     end if;
5158   else
5159     return(false);
5160   end if;
5161 if g_debug then
5162     hr_utility.set_location('Leaving:'||l_proc,20);
5163 end if;
5164 end;
5165 -- ----------------------------------------------------------------------------
5166 -- |--------------------------< chk_extended_pay_permit >--------------------------|
5167 -- ----------------------------------------------------------------------------
5168 procedure chk_extended_pay_permit
5169 (p_position_id           in number
5170   ,p_work_period_type_cd       in varchar2
5171   ,p_effective_date            in date
5172   ,p_validation_start_date     in date
5173   ,p_validation_end_date       in date
5174   ,p_object_version_number     in number
5175 ) is
5176 l_proc         varchar2(100);
5177 l_api_updating    boolean;
5178 l_permit_extended_pay   boolean;
5179 begin
5180 if g_debug then
5181 l_proc   :='chk_extended_pay_permit';
5182     hr_utility.set_location('Entering:'||l_proc,10);
5183 end if;
5184   l_api_updating := hr_psf_shd.api_updating
5185     (p_position_id            => p_position_id
5186     ,p_effective_date         => p_effective_date
5187     ,p_object_version_number  => p_object_version_number);
5188 
5189   if (((l_api_updating and p_work_period_type_cd
5190       <> nvl(hr_psf_shd.g_old_rec.work_period_type_cd,hr_api.g_varchar2)) or not l_api_updating)
5191       and nvl(p_WORK_PERIOD_TYPE_CD,'N') = 'Y') then
5192 if g_debug then
5193     hr_utility.set_location('Check permit_extended_pay:'||l_proc,10);
5194 end if;
5195     l_permit_extended_pay := permit_extended_pay(p_position_id => p_position_id);
5196 if g_debug then
5197         hr_utility.set_location('Checking permit_extended_pay complete:'||l_proc,10);
5198 end if;
5199     if (l_permit_extended_pay = false)  then
5200       --Position family is neither Academic nor Faculty, so Extended pay cannot be permitted.
5201       hr_utility.set_message(800,'HR_INV_EXTD_PAY_PERMIT');
5202       hr_utility.raise_error;
5203     end if;
5204   end if;
5205 if g_debug then
5206     hr_utility.set_location('Leaving:'||l_proc,20);
5207 end if;
5208 end;
5209 --
5210 --
5211 -- ----------------------------------------------------------------------------
5212 -- |-------------------< chk_position_type_single >---------------------------|
5213 -- ----------------------------------------------------------------------------
5214 --
5215 -- Description
5216 --   This procedure is used to check for invalid uptation os position type
5217 --    to Single.
5218 --
5219 -- Pre Conditions
5220 --   None.
5221 --
5222 -- In Parameters
5223 --   position_id                   PK of record being inserted or updated.
5224 --   p_position_type
5225 --   validation_start_date
5226 --   validation_end_Date
5227 --   date_effective
5228 --   effective_date                effective date
5229 --   object_version_number         Object version number of record being
5230 --
5231 -- Post Success
5232 --   Processing continues
5233 --
5234 -- Post Failure
5235 --   Error handled by procedure
5236 --
5237 -- Access Status
5238 --   Internal table handler use only.
5239 --
5240 Procedure chk_position_type_single
5241   (p_position_id               in number
5242   ,p_position_type             in varchar2
5243   ,p_effective_date            in date
5244   ,p_object_version_number     in number) is
5245   --
5246   l_proc         varchar2(72) ;
5247   l_api_updating boolean;
5248   l_no_assignments  number;
5249   --
5250   -- Start changes for bug 13519283
5251   cursor c_no_assignments(p_position_id number, p_effective_date date) is
5252   select asg.assignment_id, asg.effective_start_date, asg.effective_end_date
5253   from per_all_assignments_f asg, per_assignment_status_types ast
5254   where asg.position_id = p_position_id
5255   and (asg.effective_start_date >= p_effective_date
5256        or p_effective_date between asg.effective_start_date and asg.effective_end_date) -- Added for Bug#14022433
5257   and asg.assignment_type in ('E', 'C')
5258   and asg.assignment_status_type_id = ast.assignment_status_type_id
5259   and ast.per_system_status <> 'TERM_ASSIGN'
5260   order by 2,3;
5261 
5262   cursor c_asg_overlap(lp_asg_id number, lp_asg_start_date date, lp_asg_end_date date) is
5263   select
5264    asg.effective_start_date,
5265    asg.effective_end_date
5266   from
5267    per_all_assignments_f asg,
5268    per_assignment_status_types ast
5269   where asg.assignment_id <> lp_asg_id
5270    and asg.position_id = p_position_id
5271    and (lp_asg_start_date between asg.effective_start_date and asg.effective_end_date
5272         or
5273         lp_asg_end_date between asg.effective_start_date and asg.effective_end_date)
5274    and asg.assignment_type in ('E', 'C')
5275    and asg.assignment_status_type_id = ast.assignment_status_type_id
5276    and ast.per_system_status <> 'TERM_ASSIGN';
5277 
5278   cursor c_pos_overlap_dates(lp_asg_start_date date, lp_asg_end_date date) is
5279   select
5280    fnd_date.canonical_to_date(poei_information3) effective_start_date,
5281    fnd_date.canonical_to_date(poei_information4) effective_end_date
5282   from (
5283    select poei_information3, poei_information4
5284    from per_position_extra_info
5285    where information_type = 'PER_OVERLAP'
5286    and position_id = p_position_id)
5287   where lp_asg_start_date
5288    between fnd_date.canonical_to_date(poei_information3)
5289    and nvl(fnd_date.canonical_to_date(poei_information4), to_date('31/12/4712','dd/mm/rrrr'))
5290   and lp_asg_end_date
5291    between fnd_date.canonical_to_date(poei_information3)
5292    and nvl(fnd_date.canonical_to_date(poei_information4), to_date('31/12/4712','dd/mm/rrrr'));
5293 
5294   l_asg_id             number;
5295   l_asg_start_date     date;
5296   l_asg_end_date       date;
5297   l_asg_ol_start_date  date;
5298   l_asg_ol_end_date    date;
5299   l_pos_ol_start_date  date;
5300   l_pos_ol_end_date    date;
5301 
5302   -- Start changes for bug 13519283
5303   --
5304 Begin
5305   --
5306 if g_debug then
5307   l_proc         := g_package||'chk_position_type_single';
5308   hr_utility.set_location('Entering:'||l_proc, 5);
5309 end if;
5310   --
5311   l_api_updating := hr_psf_shd.api_updating
5312     (p_position_id            => p_position_id
5313     ,p_effective_date         => p_effective_date
5314     ,p_object_version_number  => p_object_version_number);
5315   --
5316   if (l_api_updating
5317       and p_position_type
5318       <> nvl(hr_psf_shd.g_old_rec.position_type,hr_api.g_varchar2))
5319   then
5320     --sqlpl
5321     -- check if value of lookup falls within lookup type.
5322     --
5323     if ((p_position_type = 'SINGLE')
5324         and (nvl(hr_psf_shd.g_old_rec.position_type,hr_api.g_varchar2)
5325         <> 'SINGLE' )) then
5326       -- Start changes for bug 13519283
5327       if g_debug then
5328         hr_utility.set_location('Converting the position into Single Incumbent', 10);
5329       end if;
5330 
5331       -- Retrieving all the assignments which are enrolled on the position.
5332       for lc_asg in c_no_assignments(p_position_id, p_effective_date)
5333       loop -- loop 1
5334         l_asg_id := lc_asg.assignment_id;
5335         l_asg_start_date := lc_asg.effective_start_date;
5336         l_asg_end_date := lc_asg.effective_end_date;
5337 
5338         if g_debug then
5339           hr_utility.set_location('Assignment : '||c_no_assignments%rowcount, 20);
5340           hr_utility.set_location('Asg ID: '||l_asg_id, 20);
5341           hr_utility.set_location('Asg Effective Start Date:'||l_asg_start_date, 20);
5342           hr_utility.set_location('Asg Effective End Date:'||l_asg_end_date, 20);
5343         end if;
5344 
5345         -- Retrieving the assignments which is overlaping with current assignment.
5346         for lc_asg_overlap in c_asg_overlap(l_asg_id, l_asg_start_date, l_asg_end_date)
5347         loop -- loop 2
5348           l_asg_ol_start_date := lc_asg_overlap.effective_start_date;
5349           l_asg_ol_end_date   := lc_asg_overlap.effective_end_date;
5350 
5351           if g_debug then
5352             hr_utility.set_location('Overlaped Asg Effective Start Date:'||l_asg_ol_start_date, 30);
5353             hr_utility.set_location('Overlaped Asg Effective End Date:'||l_asg_ol_end_date, 30);
5354           end if;
5355 
5356           -- Following 2 conditions will decide the overlap between these assignments.
5357           if l_asg_ol_start_date < l_asg_start_date then
5358             l_asg_ol_start_date := l_asg_start_date;
5359           end if;
5360 
5361           if l_asg_ol_end_date > l_asg_end_date then
5362             l_asg_ol_end_date := l_asg_end_date;
5363           end if;
5364 
5365           if g_debug then
5366             hr_utility.set_location('Overlap Effective Start Date:'||l_asg_ol_start_date, 30);
5367             hr_utility.set_location('Overlap Effective End Date:'||l_asg_ol_end_date, 30);
5368           end if;
5369 
5370           -- If the other assignment exists then checking the overlap periods of the position
5371           -- for the end date of current assignment and start date of other assignment.
5372           open c_pos_overlap_dates(l_asg_ol_start_date, l_asg_ol_end_date);
5373           fetch c_pos_overlap_dates into l_pos_ol_start_date, l_pos_ol_end_date;
5374 
5375           -- If the position overlap period defined for the assignment overlap then continue else raise the error.
5376           if c_pos_overlap_dates%found then
5377             close c_pos_overlap_dates;
5378             if g_debug then
5379               hr_utility.set_location('Position Overlap Start Date:'||l_pos_ol_start_date, 40);
5380               hr_utility.set_location('Position Overlap End Date:'||l_pos_ol_end_date, 40);
5381             end if;
5382           else
5383             if g_debug then
5384               hr_utility.set_location('Position Overlap Start Date:'||l_pos_ol_start_date, 50);
5385               hr_utility.set_location('Position Overlap End Date:'||l_pos_ol_end_date, 50);
5386             end if;
5387             close c_pos_overlap_dates;
5388             hr_utility.set_message(800,'PER_CANNOT_CHG_POS_SINGLE');
5389             hr_utility.raise_error;
5390           end if;
5391 
5392         end loop; -- loop 2
5393       end loop; -- loop 1
5394       -- End changes for bug 13519283
5395 
5396 
5397       /*open c_no_assignments(p_position_id, p_effective_date);
5398       fetch c_no_assignments into l_no_assignments;
5399       close c_no_assignments;
5400       if l_no_assignments > 1 then
5401         --
5402         -- raise error as does not exist as lookup
5403         --
5404         hr_utility.set_message(800,'PER_CANNOT_CHG_POS_SINGLE');
5405         hr_utility.raise_error;
5406         --
5407       end if;*/
5408       --
5409     end if;
5410     --
5411   end if;
5412   --
5413 if g_debug then
5414   hr_utility.set_location('Leaving:'||l_proc,10);
5415 end if;
5416   --
5417 end chk_position_type_single;
5418 --
5419 -- ----------------------------------------------------------------------------
5420 -- |--------------------------< dt_update_validate >--------------------------|
5421 -- ----------------------------------------------------------------------------
5422 -- {Start Of Comments}
5423 --
5424 -- Description:
5425 --   This procedure is used for referential integrity of datetracked
5426 --   parent entities when a datetrack update operation is taking place
5427 --   and where there is no cascading of update defined for this entity.
5428 --
5429 -- Prerequisites:
5430 --   This procedure is called from the update_validate.
5431 --
5432 -- In Parameters:
5433 --
5434 -- Post Success:
5435 --   Processing continues.
5436 --
5437 -- Post Failure:
5438 --
5439 -- Developer Implementation Notes:
5440 --   This procedure should not need maintenance unless the HR Schema model
5441 --   changes.
5442 --
5443 -- Access Status:
5444 --   Internal Row Handler Use Only.
5445 --
5446 -- {End Of Comments}
5447 -- ----------------------------------------------------------------------------
5448 Procedure dt_update_validate
5449             (p_relief_position_id            in number default hr_api.g_number,
5450              p_successor_position_id         in number default hr_api.g_number,
5451              p_supervisor_position_id        in number default hr_api.g_number,
5452              p_pay_freq_payroll_id           in number default hr_api.g_number,
5453              p_entry_grade_rule_id           in number default hr_api.g_number,
5454              p_entry_step_id                 in number default hr_api.g_number,
5455              p_datetrack_mode                in varchar2,
5456              p_validation_start_date         in date,
5457              p_validation_end_date           in date) Is
5458 --
5459   l_proc     varchar2(72) ;
5460   l_integrity_error Exception;
5461   l_table_name     all_tables.table_name%TYPE;
5462 --
5463 Begin
5464 if g_debug then
5465   l_proc   := g_package||'dt_update_validate';
5466   hr_utility.set_location('Entering:'||l_proc, 5);
5467 end if;
5468   --
5469   -- Ensure that the p_datetrack_mode argument is not null
5470   --
5471   hr_api.mandatory_arg_error
5472     (p_api_name       => l_proc,
5473      p_argument       => 'datetrack_mode',
5474      p_argument_value => p_datetrack_mode);
5475   --
5476   -- Only perform the validation if the datetrack update mode is valid
5477   --
5478   If (dt_api.validate_dt_upd_mode(p_datetrack_mode => p_datetrack_mode)) then
5479     --
5480     --
5481     -- Ensure the arguments are not null
5482     --
5483     hr_api.mandatory_arg_error
5484       (p_api_name       => l_proc,
5485        p_argument       => 'validation_start_date',
5486        p_argument_value => p_validation_start_date);
5487     --
5488     hr_api.mandatory_arg_error
5489       (p_api_name       => l_proc,
5490        p_argument       => 'validation_end_date',
5491        p_argument_value => p_validation_end_date);
5492     --
5493 -- ##
5494 if g_debug then
5495     hr_utility.set_location(l_proc,20 );
5496 end if;
5497     If ((nvl(p_relief_position_id, hr_api.g_number) <> hr_api.g_number) and
5498       NOT (dt_api.check_min_max_dates
5499             (p_base_table_name => 'hr_all_positions_f',
5500              p_base_key_column => 'position_id',
5501              p_base_key_value  => p_relief_position_id,
5502              p_from_date       => p_validation_start_date,
5503              p_to_date         => p_validation_end_date)))  Then
5504       l_table_name := 'all positions';
5505       Raise l_integrity_error;
5506     End If;
5507 if g_debug then
5508     hr_utility.set_location(l_proc,30 );
5509 end if;
5510     If ((nvl(p_successor_position_id, hr_api.g_number) <> hr_api.g_number) and
5511       NOT (dt_api.check_min_max_dates
5512             (p_base_table_name => 'hr_all_positions_f',
5513              p_base_key_column => 'position_id',
5514              p_base_key_value  => p_successor_position_id,
5515              p_from_date       => p_validation_start_date,
5516              p_to_date         => p_validation_end_date)))  Then
5517       l_table_name := 'all positions';
5518       Raise l_integrity_error;
5519     End If;
5520 if g_debug then
5521     hr_utility.set_location(l_proc,40 );
5522 end if;
5523     If ((nvl(p_supervisor_position_id, hr_api.g_number) <> hr_api.g_number) and
5524       NOT (dt_api.check_min_max_dates
5525             (p_base_table_name => 'hr_all_positions_f',
5526              p_base_key_column => 'position_id',
5527              p_base_key_value  => p_supervisor_position_id,
5528              p_from_date       => p_validation_start_date,
5529              p_to_date         => p_validation_end_date)))  Then
5530       l_table_name := 'all positions';
5531       Raise l_integrity_error;
5532     End If;
5533 if g_debug then
5534     hr_utility.set_location(l_proc,50 );
5535 end if;
5536     If ((nvl(p_pay_freq_payroll_id, hr_api.g_number) <> hr_api.g_number) and
5537       NOT (dt_api.check_min_max_dates
5538             (p_base_table_name => 'pay_all_payrolls_f',
5539              p_base_key_column => 'payroll_id',
5540              p_base_key_value  => p_pay_freq_payroll_id,
5541              p_from_date       => p_validation_start_date,
5542              p_to_date         => p_validation_end_date)))  Then
5543       l_table_name := 'all payrolls';
5544       Raise l_integrity_error;
5545     End If;
5546 if g_debug then
5547     hr_utility.set_location(l_proc,60 );
5548 end if;
5549     If ((nvl(p_entry_step_id, hr_api.g_number) <> hr_api.g_number) and
5550       NOT (dt_api.check_min_max_dates
5551             (p_base_table_name => 'per_spinal_point_steps_f',
5552              p_base_key_column => 'step_id',
5553              p_base_key_value  => p_entry_step_id,
5554              p_from_date       => p_validation_start_date,
5555              p_to_date         => p_validation_end_date)))  Then
5556       l_table_name := 'spinal point steps';
5557       Raise l_integrity_error;
5558     End If;
5559 if g_debug then
5560     hr_utility.set_location(l_proc,70 );
5561 end if;
5562     If ((nvl(p_entry_grade_rule_id, hr_api.g_number) <> hr_api.g_number) and
5563       NOT (dt_api.check_min_max_dates
5564             (p_base_table_name => 'pay_grade_rules_f',
5565              p_base_key_column => 'grade_rule_id',
5566              p_base_key_value  => p_entry_grade_rule_id,
5567              p_from_date       => p_validation_start_date,
5568              p_to_date         => p_validation_end_date)))  Then
5569       l_table_name := 'grade rules';
5570       Raise l_integrity_error;
5571     End If;
5572 -- ##
5573     --
5574   End If;
5575   --
5576 if g_debug then
5577   hr_utility.set_location(' Leaving:'||l_proc, 10);
5578 end if;
5579 Exception
5580   When l_integrity_error Then
5581     --
5582     -- A referential integrity check was violated therefore
5583     -- we must error
5584     --
5585     hr_utility.set_message(800, 'HR_7216_DT_UPD_INTEGRITY_ERR');
5586     hr_utility.set_message_token('TABLE_NAME', l_table_name);
5587     hr_utility.raise_error;
5588   When Others Then
5589     --
5590     -- An unhandled or unexpected error has occurred which
5591     -- we must report
5592     --
5593     hr_utility.set_message(800, 'HR_6153_ALL_PROCEDURE_FAIL');
5594     hr_utility.set_message_token('PROCEDURE', l_proc);
5595     hr_utility.set_message_token('STEP','15');
5596     hr_utility.raise_error;
5597 End dt_update_validate;
5598 --
5599 -- ----------------------------------------------------------------------------
5600 -- |--------------------------< dt_delete_validate >--------------------------|
5601 -- ----------------------------------------------------------------------------
5602 -- {Start Of Comments}
5603 --
5604 -- Description:
5605 --   This procedure is used for referential integrity of datetracked
5606 --   child entities when either a datetrack DELETE or ZAP is in operation
5607 --   and where there is no cascading of delete defined for this entity.
5608 --   For the datetrack mode of DELETE or ZAP we must ensure that no
5609 --   datetracked child rows exist between the validation start and end
5610 --   dates.
5611 --
5612 -- Prerequisites:
5613 --   This procedure is called from the delete_validate.
5614 --
5615 -- In Parameters:
5616 --
5617 -- Post Success:
5618 --   Processing continues.
5619 --
5620 -- Post Failure:
5621 --   If a row exists by determining the returning Boolean value from the
5622 --   generic dt_api.rows_exist function then we must supply an error via
5623 --   the use of the local exception handler l_rows_exist.
5624 --
5625 -- Developer Implementation Notes:
5626 --   This procedure should not need maintenance unless the HR Schema model
5627 --   changes.
5628 --
5629 -- Access Status:
5630 --   Internal Row Handler Use Only.
5631 --
5632 -- {End Of Comments}
5633 -- ----------------------------------------------------------------------------
5634 Procedure dt_delete_validate
5635             (p_position_id     in number,
5636              p_datetrack_mode     in varchar2,
5637              p_validation_start_date in date,
5638              p_validation_end_date   in date) Is
5639 --
5640   l_proc varchar2(72) ;
5641   l_rows_exist Exception;
5642   l_table_name all_tables.table_name%TYPE;
5643 --
5644 Begin
5645 if g_debug then
5646  l_proc     := g_package||'dt_delete_validate';
5647   hr_utility.set_location('Entering:'||l_proc, 5);
5648 end if;
5649   --
5650   -- Ensure that the p_datetrack_mode argument is not null
5651   --
5652   hr_api.mandatory_arg_error
5653     (p_api_name       => l_proc,
5654      p_argument       => 'datetrack_mode',
5655      p_argument_value => p_datetrack_mode);
5656   --
5657   -- Only perform the validation if the datetrack mode is either
5658   -- DELETE or ZAP
5659   --
5660   If (p_datetrack_mode = 'DELETE' or
5661       p_datetrack_mode = 'ZAP') then
5662     --
5663     --
5664     -- Ensure the arguments are not null
5665     --
5666     hr_api.mandatory_arg_error
5667       (p_api_name       => l_proc,
5668        p_argument       => 'validation_start_date',
5669        p_argument_value => p_validation_start_date);
5670     --
5671     hr_api.mandatory_arg_error
5672       (p_api_name       => l_proc,
5673        p_argument       => 'validation_end_date',
5674        p_argument_value => p_validation_end_date);
5675     --
5676     hr_api.mandatory_arg_error
5677       (p_api_name       => l_proc,
5678        p_argument       => 'position_id',
5679        p_argument_value => p_position_id);
5680     --
5681     If (dt_api.rows_exist
5682           (p_base_table_name => 'hr_all_positions_f',
5683            p_base_key_column => 'relief_position_id',
5684            p_base_key_value  => p_position_id,
5685            p_from_date       => p_validation_start_date,
5686            p_to_date         => p_validation_end_date)) Then
5687       l_table_name := 'all positions';
5688       Raise l_rows_exist;
5689     End If;
5690 
5691     If (dt_api.rows_exist
5692           (p_base_table_name => 'hr_all_positions_f',
5693            p_base_key_column => 'supervisor_position_id',
5694            p_base_key_value  => p_position_id,
5695            p_from_date       => p_validation_start_date,
5696            p_to_date         => p_validation_end_date)) Then
5697       l_table_name := 'all positions';
5698       Raise l_rows_exist;
5699     End If;
5700     If (dt_api.rows_exist
5701           (p_base_table_name => 'hr_all_positions_f',
5702            p_base_key_column => 'successor_position_id',
5703            p_base_key_value  => p_position_id,
5704            p_from_date       => p_validation_start_date,
5705            p_to_date         => p_validation_end_date)) Then
5706       l_table_name := 'all positions';
5707       Raise l_rows_exist;
5708     End If;
5709 /*
5710     If (dt_api.rows_exist
5711           (p_base_table_name => 'hr_all_positions_f',
5712            p_base_key_column => 'prior_position_id',
5713            p_base_key_value  => p_position_id,
5714            p_from_date       => p_validation_start_date,
5715            p_to_date         => p_validation_end_date)) Then
5716       l_table_name := 'all positions';
5717       Raise l_rows_exist;
5718     End If;
5719 */
5720     --
5721     -- Bug 3199913
5722     -- Removed refernce to 'per_all_assignments_f' since assignment and position
5723     -- do not have parent-child relationship.
5724     -- Removed refernce to 'pay_element_links_f' since assignment and position
5725     -- do not have parent-child relationship.
5726     --
5727   End If;
5728   --
5729 if g_debug then
5730   hr_utility.set_location(' Leaving:'||l_proc, 10);
5731 end if;
5732 Exception
5733   When l_rows_exist Then
5734     --
5735     -- A referential integrity check was violated therefore
5736     -- we must error
5737     --
5738     hr_utility.set_message(800, 'HR_7215_DT_CHILD_EXISTS');
5739     hr_utility.set_message_token('TABLE_NAME', l_table_name);
5740     hr_utility.raise_error;
5741   When Others Then
5742     --
5743     -- An unhandled or unexpected error has occurred which
5744     -- we must report
5745     --
5746     hr_utility.set_message(800, 'HR_6153_ALL_PROCEDURE_FAIL');
5747     hr_utility.set_message_token('PROCEDURE', l_proc);
5748     hr_utility.set_message_token('STEP','15');
5749     hr_utility.raise_error;
5750 End dt_delete_validate;
5751 --
5752 Procedure chk_proposed_status
5753   (p_position_id               in number
5754   ,p_availability_status_id    in varchar2
5755   ,p_business_group_id         in varchar2
5756   ,p_effective_date             in date
5757   ,p_validate_start_date       in date
5758   ,p_validate_end_date         in date
5759   ,p_object_version_number     in number
5760   ,p_datetrack_mode              in varchar2) is
5761   --
5762   l_proc         varchar2(72) ;
5763   l_api_updating boolean;
5764   l_count       number;
5765   --
5766   cursor c1 is
5767   select count(*)
5768   from per_all_assignments_f
5769   where position_id = p_position_id
5770   and effective_start_date between p_validate_start_date and p_validate_end_date;
5771   --
5772   --
5773 Begin
5774   --
5775 if g_debug then
5776   l_proc         := g_package||'chk_proposed_status';
5777   hr_utility.set_location('Entering:'||l_proc, 5);
5778 end if;
5779   --
5780   l_api_updating := hr_psf_shd.api_updating
5781     (p_position_id            => p_position_id
5782     ,p_effective_date         => p_effective_date
5783     ,p_object_version_number  => p_object_version_number);
5784   --
5785 if g_debug then
5786     hr_utility.set_location('datetrack mode:'||p_datetrack_mode, 5);
5787 end if;
5788  if p_datetrack_mode = 'CORRECTION' then
5789   if (l_api_updating
5790       and p_availability_status_id
5791       <> nvl(hr_psf_shd.g_old_rec.availability_status_id,hr_api.g_number))
5792   then
5793 if g_debug then
5794     hr_utility.set_location('Availability_status id:'||p_availability_status_id, 5);
5795     hr_utility.set_location('position id:'||p_position_id, 5);
5796   hr_utility.set_location('get avail '||hr_psf_shd.get_availability_status(p_availability_status_id,p_business_group_id),6);
5797 end if;
5798     if hr_psf_shd.get_availability_status(p_availability_status_id,p_business_group_id) = 'PROPOSED' then
5799 if g_debug then
5800   hr_utility.set_location('Entering:'||l_proc, 5);
5801 end if;
5802       open c1;
5803       fetch c1 into l_count;
5804       close c1;
5805       if l_count >0 then
5806         hr_utility.set_message(800, 'HR_ASG_EXISTS_CANT_CHG_PROP');
5807         hr_utility.raise_error;
5808       end if;
5809     end if;
5810    end if;
5811   end if;
5812   --
5813 if g_debug then
5814   hr_utility.set_location('Leaving:'||l_proc,10);
5815 end if;
5816   --
5817 end chk_proposed_status;
5818 --
5819 --
5820 -- ----------------------------------------------------------------------------
5821 -- |---------------------------< insert_validate >----------------------------|
5822 -- ----------------------------------------------------------------------------
5823 Procedure insert_validate
5824    (p_rec          in hr_psf_shd.g_rec_type,
5825     p_effective_date        in date,
5826     p_datetrack_mode        in varchar2,
5827     p_validation_start_date in date,
5828     p_validation_end_date   in date) is
5829 --
5830   l_proc varchar2(72) ;
5831 --
5832 Begin
5833 g_debug := hr_utility.debug_enabled;
5834 if g_debug then
5835   l_proc := g_package||'insert_validate';
5836   hr_utility.set_location('Entering:'||l_proc, 5);
5837 end if;
5838   --
5839   -- Call all supporting business operations
5840   --
5841   hr_api.validate_bus_grp_id(p_rec.business_group_id);  -- Validate Bus Grp
5842 --
5843 if g_debug then
5844 hr_utility.set_location(l_proc, 6);
5845 end if;
5846 --
5847 -- Validate date effective and date_end
5848 --
5849 chk_dates
5850   (p_date_effective        => p_rec.date_effective
5851   ,p_date_end              => p_rec.date_end
5852   ,p_validation_start_date => p_validation_start_date
5853   ,p_validation_end_date   => p_validation_end_date
5854   ,p_effective_Date        => p_effective_date
5855   ,p_object_version_number => p_rec.object_version_number
5856 );
5857 --
5858 if g_debug then
5859 hr_utility.set_location(l_proc, 50);
5860 end if;
5861 --
5862 -- validate end dates
5863 chk_end_dates
5864 (position_id                => p_rec.position_id
5865 ,availability_status_id     => p_rec.availability_status_id
5866 ,p_effective_date           => p_effective_date
5867 ,current_org_prop_end_date  => p_rec.current_org_prop_end_date
5868 ,current_job_prop_end_date  => p_rec.current_job_prop_end_date
5869 ,avail_status_prop_end_date => p_rec.avail_status_prop_end_date
5870 ,earliest_hire_date         => p_rec.earliest_hire_date
5871 ,fill_by_date               => p_rec.fill_by_date
5872 ,proposed_date_for_layoff   => p_rec.proposed_date_for_layoff
5873 ,date_effective             => p_rec.date_effective );
5874 --
5875 -- Validate job id
5876 --
5877 if g_debug then
5878 hr_utility.set_location(l_proc, 100);
5879 end if;
5880 chk_job_id
5881     (p_job_id          => p_rec.job_id
5882     ,p_business_group_id     => p_rec.business_group_id
5883     ,p_validation_start_date => p_validation_start_date
5884     ,p_validation_end_date   => p_validation_end_date
5885     ,p_effective_Date        => p_effective_date
5886     ,p_object_version_number => p_rec.object_version_number
5887 );
5888 --
5889 if g_debug then
5890 hr_utility.set_location(l_proc, 110);
5891 end if;
5892 --
5893 -- Validate organization id
5894 --
5895 chk_organization_id
5896   ( p_organization_id       =>  p_rec.organization_id
5897    ,p_business_group_id     =>  p_rec.business_group_id
5898    ,p_validation_start_date =>  p_validation_start_date
5899    ,p_validation_end_date   =>  p_validation_end_date
5900    ,p_effective_Date        =>  p_effective_date
5901    ,p_object_version_number =>  p_rec.object_version_number
5902 );
5903 --
5904 if g_debug then
5905 hr_utility.set_location(l_proc, 120);
5906 end if;
5907 --
5908 -- Validate successor position id
5909 --
5910 chk_successor_position_id
5911   (p_business_group_id     =>  p_rec.business_group_id
5912   ,p_position_id           =>  null
5913   ,p_successor_position_id =>  p_rec.successor_position_id
5914   ,p_validation_start_date =>  p_validation_start_date
5915   ,p_validation_end_date   =>  p_validation_end_date
5916   ,p_effective_date        =>  p_effective_date
5917   ,p_object_version_number =>  p_rec.object_version_number
5918 );
5919 if g_debug then
5920 hr_utility.set_location(l_proc, 130);
5921 end if;
5922 --
5923 -- Validate relief position id
5924 --
5925 chk_relief_position_id
5926   (p_business_group_id     =>  p_rec.business_group_id
5927   ,p_relief_position_id    =>  p_rec.relief_position_id
5928   ,p_validation_start_date =>  p_validation_start_date
5929   ,p_validation_end_date   =>  p_validation_end_date
5930   ,p_effective_date     =>  p_effective_Date
5931 );
5932 --
5933 if g_debug then
5934 hr_utility.set_location(l_proc, 140);
5935 end if;
5936 --
5937 -- Validate location_id
5938 --
5939 chk_location_id
5940   (p_location_id        => p_rec.location_id
5941   ,p_effective_Date        => p_effective_date
5942   ,p_validation_start_date => p_validation_start_Date
5943   ,p_validation_end_date   => p_validation_end_Date
5944 
5945 );
5946 --
5947 if g_debug then
5948 hr_utility.set_location(l_proc, 150);
5949 end if;
5950 --
5951 -- Validate position definition id
5952 --
5953 chk_position_definition_id
5954   (p_position_definition_id   => p_rec.position_definition_id
5955   ,p_effective_Date           => p_effective_date
5956 );
5957 --
5958 if g_debug then
5959 hr_utility.set_location(l_proc, 160);
5960 end if;
5961 --
5962 -- Validate working_hours and frequency
5963 --
5964 chk_hrs_frequency
5965   (p_working_hours     => p_rec.working_hours
5966   ,p_frequency      => p_rec.frequency
5967   ,p_effective_date       => p_effective_date
5968 );
5969 --
5970 if g_debug then
5971 hr_utility.set_location(l_proc, 170);
5972 end if;
5973 --
5974 -- Validate probation period and probation_period_unit_cd
5975 --
5976 chk_probation_info
5977   (p_probation_period         => p_rec.probation_period
5978   ,p_probation_period_unit_cd => p_rec.probation_period_unit_cd
5979   ,p_effective_Date           => p_effective_date
5980 );
5981 --
5982 if g_debug then
5983 hr_utility.set_location('Entering:'||l_proc, 180);
5984 end if;
5985 --
5986 -- Validate time normal start and time_normal_finish
5987 --
5988 chk_time_start_finish
5989   (p_time_normal_start    => p_rec.time_normal_start
5990   ,p_time_normal_finish   => p_rec.time_normal_finish
5991   ,p_effective_date       => p_effective_date
5992 );
5993 --
5994 if g_debug then
5995 hr_utility.set_location(l_proc, 200);
5996 end if;
5997 --
5998 chk_entry_step_id
5999   (p_position_id              => p_rec.position_id
6000   ,p_entry_step_id            => p_rec.entry_step_id
6001   ,p_entry_grade_id           => p_rec.entry_grade_id
6002   ,p_business_group_id        => p_rec.business_group_id
6003   ,p_validation_start_date    => p_validation_start_date
6004   ,p_validation_end_date      => p_validation_end_date
6005   ,p_effective_date           => p_effective_date
6006   ,p_object_version_number    => p_rec.object_version_number
6007   );
6008   --
6009 if g_debug then
6010   hr_utility.set_location(l_proc, 210);
6011 end if;
6012   --
6013   chk_entry_grade_id
6014   (p_position_id              => p_rec.position_id
6015   ,p_business_group_id        => p_rec.business_group_id
6016   ,p_entry_grade_id           => p_rec.entry_grade_id
6017   ,p_effective_date           => p_effective_date
6018   ,p_validation_start_date    => p_validation_start_date
6019   ,p_validation_end_date      => p_validation_end_date
6020   ,p_object_version_number    => p_rec.object_version_number
6021   );
6022   --
6023 if g_debug then
6024   hr_utility.set_location(l_proc, 215);
6025 end if;
6026   --
6027   chk_entry_grade_rule_id
6028   (p_position_id              => p_rec.position_id
6029   ,p_business_group_id        => p_rec.business_group_id
6030   ,p_entry_grade_rule_id      => p_rec.entry_grade_rule_id
6031   ,p_effective_date           => p_effective_date
6032   ,p_validation_start_date    => p_validation_start_date
6033   ,p_validation_end_date      => p_validation_end_date
6034   ,p_object_version_number    => p_rec.object_version_number
6035   );
6036   --
6037 if g_debug then
6038   hr_utility.set_location(l_proc, 220);
6039 end if;
6040   --
6041   chk_work_term_end_month_cd
6042   (p_position_id              => p_rec.position_id
6043   ,p_work_term_end_month_cd   => p_rec.work_term_end_month_cd
6044   ,p_effective_date           => p_effective_date
6045   ,p_validation_start_date    => p_validation_start_date
6046   ,p_validation_end_date      => p_validation_end_date
6047   ,p_object_version_number => p_rec.object_version_number);
6048   --
6049 if g_debug then
6050   hr_utility.set_location(l_proc, 230);
6051 end if;
6052   --
6053   chk_work_term_end_day_cd
6054   (p_position_id           => p_rec.position_id
6055   ,p_work_term_end_day_cd  => p_rec.work_term_end_day_cd
6056   ,p_effective_date        => p_effective_date
6057   ,p_validation_start_date => p_validation_start_date
6058   ,p_validation_end_date   => p_validation_end_date
6059   ,p_object_version_number => p_rec.object_version_number);
6060   --
6061 if g_debug then
6062   hr_utility.set_location(l_proc, 240);
6063 end if;
6064   --
6065   chk_work_period_type_cd
6066   (p_position_id           => p_rec.position_id
6067   ,p_work_period_type_cd   => p_rec.work_period_type_cd
6068   ,p_effective_date        => p_effective_date
6069   ,p_validation_start_date => p_validation_start_date
6070   ,p_validation_end_date   => p_validation_end_date
6071   ,p_object_version_number => p_rec.object_version_number);
6072   --
6073 if g_debug then
6074   hr_utility.set_location(l_proc, 250);
6075 end if;
6076   --
6077   chk_works_council_approval_flg
6078   (p_position_id                 => p_rec.position_id
6079   ,p_works_council_approval_flag => p_rec.works_council_approval_flag
6080   ,p_effective_date              => p_effective_date
6081   ,p_validation_start_date       => p_validation_start_date
6082   ,p_validation_end_date         => p_validation_end_date
6083   ,p_object_version_number       => p_rec.object_version_number);
6084   --
6085 if g_debug then
6086   hr_utility.set_location(l_proc, 260);
6087 end if;
6088   --
6089   chk_term_start_month_cd
6090   (p_position_id           => p_rec.position_id
6091   ,p_term_start_month_cd   => p_rec.term_start_month_cd
6092   ,p_effective_date        => p_effective_date
6093   ,p_validation_start_date => p_validation_start_date
6094   ,p_validation_end_date   => p_validation_end_date
6095   ,p_object_version_number => p_rec.object_version_number);
6096   --
6097 if g_debug then
6098   hr_utility.set_location(l_proc, 270);
6099 end if;
6100   --
6101   chk_term_start_day_cd
6102   (p_position_id           => p_rec.position_id
6103   ,p_term_start_day_cd     => p_rec.term_start_day_cd
6104   ,p_effective_date        => p_effective_date
6105   ,p_validation_start_date => p_validation_start_date
6106   ,p_validation_end_date   => p_validation_end_date
6107   ,p_object_version_number => p_rec.object_version_number);
6108   --
6109 if g_debug then
6110   hr_utility.set_location(l_proc, 280);
6111 end if;
6112   --
6113   chk_seasonal_flag
6114   (p_position_id           => p_rec.position_id
6115   ,p_seasonal_flag         => p_rec.seasonal_flag
6116   ,p_effective_date        => p_effective_date
6117   ,p_validation_start_date => p_validation_start_date
6118   ,p_validation_end_date   => p_validation_end_date
6119   ,p_object_version_number => p_rec.object_version_number);
6120   --
6121 if g_debug then
6122   hr_utility.set_location(l_proc, 290);
6123 end if;
6124   --
6125   chk_review_flag
6126   (p_position_id           => p_rec.position_id
6127   ,p_review_flag           => p_rec.review_flag
6128   ,p_effective_date        => p_effective_date
6129   ,p_validation_start_date => p_validation_start_date
6130   ,p_validation_end_date   => p_validation_end_date
6131   ,p_object_version_number => p_rec.object_version_number);
6132   --
6133 if g_debug then
6134   hr_utility.set_location(l_proc, 300);
6135 end if;
6136   --
6137   chk_replacement_required_flag
6138   (p_position_id               => p_rec.position_id
6139   ,p_replacement_required_flag => p_rec.replacement_required_flag
6140   ,p_effective_date            => p_effective_date
6141   ,p_validation_start_date     => p_validation_start_date
6142   ,p_validation_end_date       => p_validation_end_date
6143   ,p_object_version_number     => p_rec.object_version_number);
6144   --
6145 if g_debug then
6146   hr_utility.set_location(l_proc, 310);
6147 end if;
6148   --
6149   chk_probation_period_unit_cd
6150   (p_position_id              => p_rec.position_id
6151   ,p_probation_period_unit_cd => p_rec.probation_period_unit_cd
6152   ,p_effective_date           => p_effective_date
6153   ,p_validation_start_date    => p_validation_start_date
6154   ,p_validation_end_date      => p_validation_end_date
6155   ,p_object_version_number    => p_rec.object_version_number);
6156   --
6157 if g_debug then
6158   hr_utility.set_location(l_proc, 320);
6159 end if;
6160   --
6161   chk_permit_recruitment_flag
6162   (p_position_id             => p_rec.position_id
6163   ,p_permit_recruitment_flag => p_rec.permit_recruitment_flag
6164   ,p_effective_date          => p_effective_date
6165   ,p_validation_start_date   => p_validation_start_date
6166   ,p_validation_end_date     => p_validation_end_date
6167   ,p_object_version_number   => p_rec.object_version_number);
6168   --
6169 if g_debug then
6170   hr_utility.set_location(l_proc, 330);
6171 end if;
6172   --
6173   chk_permanent_temporary_flag
6174   (p_position_id              => p_rec.position_id
6175   ,p_permanent_temporary_flag => p_rec.permanent_temporary_flag
6176   ,p_effective_date           => p_effective_date
6177   ,p_validation_start_date    => p_validation_start_date
6178   ,p_validation_end_date      => p_validation_end_date
6179   ,p_object_version_number    => p_rec.object_version_number);
6180   --
6181 if g_debug then
6182    hr_utility.set_location(l_proc, 335);
6183  end if;
6184    --
6185  chk_permanent_seasonal_flag
6186    (p_position_id               => p_rec.position_id
6187    ,p_permanent_temporary_flag  => p_rec.permanent_temporary_flag
6188    ,p_seasonal_flag             => p_rec.seasonal_flag
6189    ,p_effective_date            => p_effective_date
6190    ,p_object_version_number     => p_rec.object_version_number);
6191    --
6192 
6193 if g_debug then
6194   hr_utility.set_location(l_proc, 340);
6195 end if;
6196   --
6197   chk_pay_term_end_month_cd
6198   (p_position_id           => p_rec.position_id
6199   ,p_pay_term_end_month_cd => p_rec.pay_term_end_month_cd
6200   ,p_effective_date        => p_effective_date
6201   ,p_validation_start_date => p_validation_start_date
6202   ,p_validation_end_date   => p_validation_end_date
6203   ,p_object_version_number => p_rec.object_version_number);
6204   --
6205 if g_debug then
6206   hr_utility.set_location(l_proc, 350);
6207 end if;
6208   --
6209   chk_pay_term_end_day_cd
6210   (p_position_id           => p_rec.position_id
6211   ,p_pay_term_end_day_cd   => p_rec.pay_term_end_day_cd
6212   ,p_effective_date        => p_effective_date
6213   ,p_validation_start_date => p_validation_start_date
6214   ,p_validation_end_date   => p_validation_end_date
6215   ,p_object_version_number => p_rec.object_version_number);
6216   --
6217 if g_debug then
6218   hr_utility.set_location(l_proc, 360);
6219 end if;
6220   --
6221   chk_overlap_unit_cd
6222   (p_position_id           => p_rec.position_id
6223   ,p_overlap_unit_cd       => p_rec.overlap_unit_cd
6224   ,p_effective_date        => p_effective_date
6225   ,p_validation_start_date => p_validation_start_date
6226   ,p_validation_end_date   => p_validation_end_date
6227   ,p_object_version_number => p_rec.object_version_number);
6228   --
6229 if g_debug then
6230   hr_utility.set_location(l_proc, 370);
6231 end if;
6232   --
6233   chk_bargaining_unit_cd
6234   (p_position_id           => p_rec.position_id
6235   ,p_bargaining_unit_cd    => p_rec.bargaining_unit_cd
6236   ,p_effective_date        => p_effective_date
6237   ,p_validation_start_date => p_validation_start_date
6238   ,p_validation_end_date   => p_validation_end_date
6239   ,p_object_version_number => p_rec.object_version_number);
6240   --
6241 if g_debug then
6242   hr_utility.set_location(l_proc, 380);
6243 end if;
6244   --
6245   chk_pay_freq_payroll_id
6246   (p_position_id           => p_rec.position_id
6247   ,p_business_group_id     => p_rec.business_group_id
6248   ,p_pay_freq_payroll_id   => p_rec.pay_freq_payroll_id
6249   ,p_validation_start_date => p_validation_start_date
6250   ,p_validation_end_date   => p_validation_end_date
6251   ,p_effective_date        => p_effective_Date
6252   ,p_datetrack_mode        => p_datetrack_mode
6253   ,p_object_version_number => p_rec.object_version_number
6254   );
6255   --
6256 if g_debug then
6257   hr_utility.set_location(l_proc, 390);
6258 end if;
6259   --
6260 /*
6261   chk_position_transaction_id
6262   (p_position_id              => p_rec.position_id
6263   ,p_position_transaction_id  => p_rec.position_transaction_id
6264   ,p_validation_start_date    => p_validation_start_date
6265   ,p_validation_end_date      => p_validation_end_date
6266   ,p_effective_date           => p_effective_date
6267   ,p_object_version_number    => p_rec.object_version_number
6268   );
6269   --
6270 */
6271  --
6272 if g_debug then
6273   hr_utility.set_location(l_proc, 400);
6274 end if;
6275   --
6276   chk_supervisor_position_id
6277   (p_business_group_id      => p_rec.business_group_id
6278   ,p_position_id            => p_rec.position_id
6279   ,p_supervisor_position_id => p_rec.supervisor_position_id
6280   ,p_validation_start_date  => p_validation_start_date
6281   ,p_validation_end_date    => p_validation_end_date
6282   ,p_effective_date      => p_effective_date
6283   ,p_object_version_number  => p_rec.object_version_number
6284   );
6285   --
6286 if g_debug then
6287   hr_utility.set_location(l_proc, 410);
6288 end if;
6289   --
6290   chk_prior_position_id
6291   (p_business_group_id      => p_rec.business_group_id
6292   ,p_position_id            => p_rec.position_id
6293   ,p_prior_position_id      => p_rec.prior_position_id
6294   ,p_validation_start_date  => p_validation_start_date
6295   ,p_validation_end_date    => p_validation_end_date
6296   ,p_effective_date      => p_effective_date
6297   ,p_object_version_number  => p_rec.object_version_number
6298   );
6299   --
6300 if g_debug then
6301   hr_utility.set_location(l_proc, 420);
6302 end if;
6303   --
6304   chk_availability_status_id
6305    (p_position_id            => p_rec.position_id
6306    ,p_validation_start_date  => p_validation_start_date
6307    ,p_availability_status_id => p_rec.availability_status_id
6308    ,p_old_avail_status_id    => hr_psf_shd.g_old_rec.availability_status_id
6309    ,p_effective_date         => p_effective_date
6310    ,p_date_effective         => p_rec.date_effective
6311    ,p_business_group_id      => p_rec.business_group_id
6312    ,p_object_version_number  => p_rec.object_version_number
6313    ,p_datetrack_mode         => p_datetrack_mode );
6314   --
6315 if g_debug then
6316   hr_utility.set_location(l_proc, 430);
6317 end if;
6318   --
6319   chk_position_type
6320   (p_position_id             => p_rec.position_id
6321   ,p_position_type           => p_rec.position_type
6322   ,p_effective_date          => p_effective_date
6323   ,p_validation_start_date   => p_validation_start_Date
6324   ,p_validation_end_date     => p_validation_end_date
6325   ,p_object_version_number   => p_rec.object_version_number
6326   );
6327   --
6328 if g_debug then
6329   hr_utility.set_location(l_proc, 440);
6330 end if;
6331   --
6332   chk_fte
6333   (p_position_id               => p_rec.position_id
6334   ,p_fte                       => p_rec.fte
6335   ,p_position_type             => p_rec.position_type
6336   ,p_effective_date            => p_effective_date
6337   ,p_validation_start_date     => p_validation_start_date
6338   ,p_validation_end_date       => p_validation_end_Date
6339   ,p_object_version_number     => p_rec.object_version_number);
6340   --
6341 if g_debug then
6342   hr_utility.set_location(l_proc, 445);
6343 end if;
6344   --
6345   chk_max_persons
6346   (p_position_id               => p_rec.position_id
6347   ,p_max_persons               => p_rec.max_persons
6348   ,p_position_type             => p_rec.position_type
6349   ,p_effective_date            => p_effective_date
6350   ,p_object_version_number     => p_rec.object_version_number);
6351   --
6352 if g_debug then
6353   hr_utility.set_location(l_proc, 450);
6354 end if;
6355   --
6356   chk_extended_pay
6357   (p_position_id               => p_rec.position_id
6358   ,p_work_period_type_cd       => p_rec.work_period_type_cd
6359   ,p_term_start_day_cd         => p_rec.term_start_day_cd
6360   ,p_term_start_month_cd       => p_rec.term_start_month_cd
6361   ,p_pay_term_end_day_cd       => p_rec.pay_term_end_day_cd
6362   ,p_pay_term_end_month_cd     => p_rec.pay_term_end_month_cd
6363   ,p_work_term_end_day_cd      => p_rec.work_term_end_day_cd
6364   ,p_work_term_end_month_cd    => p_rec.work_term_end_month_cd
6365   );
6366   --
6367 if g_debug then
6368   hr_utility.set_location(l_proc, 460);
6369 end if;
6370   --
6371   chk_proposed_fte_for_layoff
6372   (p_fte                      => p_rec.fte
6373   ,p_proposed_fte_for_layoff  => p_rec.proposed_fte_for_layoff
6374   ,p_proposed_date_for_layoff => p_rec.proposed_Date_for_layoff
6375   );
6376   --
6377 if g_debug then
6378   hr_utility.set_location(l_proc, 470);
6379 end if;
6380   --
6381 /*
6382 chk_extended_pay_permit
6383 (p_position_id            => p_rec.position_id
6384   ,p_work_period_type_cd        => p_rec.work_period_type_cd
6385   ,p_effective_date             => p_effective_date
6386   ,p_validation_start_date      => p_validation_start_Date
6387   ,p_validation_end_date        => p_validation_end_date
6388   ,p_object_version_number      => p_rec.object_version_number
6389 );
6390 if g_debug then
6391 hr_utility.set_location(l_proc, 2000);
6392 end if;
6393 --
6394 -- Validate status
6395 --
6396 chk_status
6397   (p_position_id            => p_rec.position_id
6398   ,p_effective_Date        =>  p_effective_date
6399   ,p_status                 => p_rec.status
6400   ,p_object_version_number  => p_rec.object_version_number
6401 );
6402 --
6403 */
6404 if g_debug then
6405   hr_utility.set_location('Entering:'||l_proc, 210);
6406 end if;
6407   --
6408   --
6409   -- Call developer descriptive flexfield validation routines
6410   --
6411   --hr_psf_bus.chk_ddf(p_rec => p_rec);
6412   --
6413   --
6414   --
6415   -- Call descriptive flexfield validation routines
6416   --
6417   hr_psf_bus.chk_df(p_rec => p_rec);
6418   --
6419 if g_debug then
6420   hr_utility.set_location('Entering:'||l_proc, 220);
6421 end if;
6422   --
6423   -- PMFLETCH ** Not using this uniqueness chech anymore **
6424   -- Check position_name is unique for Business_group
6425   --
6426   --chk_name_unique_for_BG
6427   -- (p_business_group_id    => p_rec.business_group_id
6428   -- ,p_position_id          => p_rec.position_id
6429   -- ,p_effective_date       => p_effective_date
6430   -- ,p_name                 => p_rec.name
6431   -- ,p_object_version_number  => p_rec.object_version_number
6432   -- );
6433   --
6434   -- PMFLETCH Check position_definition_id is unique for business group
6435   --
6436   chk_ccid_unique_for_BG
6437     (p_business_group_id             => p_rec.business_group_id
6438     ,p_position_id                   => p_rec.position_id
6439     ,p_position_definition_id        => p_rec.position_definition_id
6440     ,p_validation_start_date         => p_validation_start_date
6441     ,p_validation_end_date           => p_validation_end_date
6442     ,p_effective_date                => p_effective_date
6443     ,p_object_version_number         => p_rec.object_version_number
6444     );
6445   --
6446   --
6447   -- Call to validate Position Control Business Rules
6448   --
6449   if (per_pqh_shr.position_control_enabled
6450       ( p_organization_id => p_rec.organization_id
6451       , p_effective_date  => p_effective_date
6452       ) = 'Y') then
6453     --
6454     if p_rec.position_transaction_id is null then
6455       hr_utility.set_message(800, 'PER_CANT_CRE_PC_POS_NO_TXN');
6456       hr_utility.raise_error;
6457     end if;
6458     --
6459   end if;
6460   --
6461   per_pqh_shr.hr_psf_bus('INSERT_VALIDATE',p_rec
6462         ,p_effective_date
6463         ,p_validation_start_date
6464         ,p_validation_end_date
6465         ,p_datetrack_mode);
6466   --
6467   --End of Position Control Business Rules call
6468   --
6469   --
6470 if g_debug then
6471   hr_utility.set_location(' Leaving:'||l_proc, 230);
6472 end if;
6473   --
6474 End insert_validate;
6475 --
6476 -- ----------------------------------------------------------------------------
6477 -- |---------------------------< update_validate >----------------------------|
6478 -- ----------------------------------------------------------------------------
6479 Procedure update_validate
6480    (p_rec          in hr_psf_shd.g_rec_type,
6481     p_effective_date  in date,
6482     p_datetrack_mode  in varchar2,
6483     p_validation_start_date in date,
6484     p_validation_end_date   in date) is
6485 --
6486   l_proc varchar2(72) ;
6487 --
6488 Begin
6489 g_debug := hr_utility.debug_enabled;
6490 if g_debug then
6491 l_proc    := g_package||'update_validate';
6492   hr_utility.set_location('Entering:'||l_proc, 5);
6493 end if;
6494   --
6495   -- Call all supporting business operations
6496   --
6497   hr_api.validate_bus_grp_id(p_rec.business_group_id);  -- Validate Bus Grp
6498   --
6499 if g_debug then
6500   hr_utility.set_location('Entering:'||l_proc, 100);
6501 end if;
6502   -- Validate successor position id
6503   --
6504   chk_successor_position_id
6505     (p_business_group_id     => p_rec.business_group_id
6506     ,p_position_id           => p_rec.position_id
6507     ,p_successor_position_id => p_rec.successor_position_id
6508     ,p_validation_start_date =>  p_validation_start_date
6509     ,p_validation_end_date   =>  p_validation_end_date
6510     ,p_effective_date        =>  p_effective_date
6511     ,p_object_version_number => p_rec.object_version_number
6512   );
6513   --
6514 if g_debug then
6515   hr_utility.set_location('Entering:'||l_proc, 110);
6516 end if;
6517   --
6518   -- Validate relief position id
6519   --
6520   chk_relief_position_id
6521     (p_business_group_id     => p_rec.business_group_id
6522     ,p_position_id           => p_rec.position_id
6523     ,p_relief_position_id    => p_rec.relief_position_id
6524     ,p_validation_start_date =>  p_validation_start_date
6525     ,p_validation_end_date   =>  p_validation_end_date
6526     ,p_effective_date        =>  p_effective_Date
6527     ,p_object_version_number => p_rec.object_version_number
6528   );
6529   --
6530 if g_debug then
6531   hr_utility.set_location('Entering:'||l_proc, 120);
6532 end if;
6533   --
6534   -- Validate location_id
6535   --
6536   chk_location_id
6537     (p_position_id           => p_rec.position_id
6538     ,p_location_id        =>  p_rec.location_id
6539     ,p_effective_Date        => p_effective_date
6540     ,p_validation_start_date => p_validation_start_Date
6541     ,p_validation_end_date   => p_validation_end_Date
6542     ,p_object_version_number => p_rec.object_version_number
6543   );
6544   --
6545 if g_debug then
6546   hr_utility.set_location('Entering:'||l_proc, 130);
6547 end if;
6548   --
6549   -- Validate working_hours and frequency
6550   --
6551   chk_hrs_frequency
6552     (p_position_id        => p_rec.position_id
6553     ,p_working_hours      => p_rec.working_hours
6554     ,p_frequency       => p_rec.frequency
6555     ,p_effective_date        => p_effective_date
6556     ,p_object_version_number => p_rec.object_version_number
6557   );
6558   --
6559 if g_debug then
6560   hr_utility.set_location('Entering:'||l_proc, 140);
6561 end if;
6562   --
6563   -- Validate probation period and probation_period_unit_cd
6564   --
6565   chk_probation_info
6566     (p_position_id              => p_rec.position_id
6567     ,p_probation_period         => p_rec.probation_period
6568     ,p_probation_period_unit_cd => p_rec.probation_period_unit_cd
6569     ,p_effective_Date           => p_effective_date
6570     ,p_object_version_number    => p_rec.object_version_number
6571   );
6572   --
6573 if g_debug then
6574   hr_utility.set_location('Entering:'||l_proc, 150);
6575 end if;
6576   --
6577   -- Validate time normal start and time_normal_finish
6578   --
6579   chk_time_start_finish
6580     (p_position_id           => p_rec.position_id
6581     ,p_time_normal_start     => p_rec.time_normal_start
6582     ,p_time_normal_finish    => p_rec.time_normal_finish
6583     ,p_effective_date        => p_effective_date
6584     ,p_object_version_number => p_rec.object_version_number
6585   );
6586   --
6587 if g_debug then
6588   hr_utility.set_location('Entering:'||l_proc, 160);
6589 end if;
6590   --
6591   -- Validate position definition id
6592   --
6593   chk_position_definition_id
6594     (p_position_definition_id => p_rec.position_definition_id
6595     ,p_position_id              => p_rec.position_id
6596     ,p_effective_Date           => p_effective_date
6597     ,p_object_version_number    => p_rec.object_version_number
6598   );
6599   --
6600 if g_debug then
6601   hr_utility.set_location(l_proc, 165);
6602 end if;
6603   --
6604   -- Validate working_hours and frequency
6605   --
6606   chk_hrs_frequency
6607   (p_position_id          => p_rec.position_id
6608   ,p_working_hours     => p_rec.working_hours
6609   ,p_frequency      => p_rec.frequency
6610   ,p_effective_date       => p_effective_date
6611   );
6612   --
6613 if g_debug then
6614   hr_utility.set_location(l_proc, 170);
6615 end if;
6616   --
6617   -- Validate probation period and probation_period_unit_cd
6618   --
6619   chk_probation_info
6620   (p_position_id              => p_rec.position_id
6621   ,p_probation_period         => p_rec.probation_period
6622   ,p_probation_period_unit_cd => p_rec.probation_period_unit_cd
6623   ,p_effective_Date           => p_effective_date
6624   );
6625   --
6626 if g_debug then
6627   hr_utility.set_location('Entering:'||l_proc, 180);
6628 end if;
6629   --
6630   -- Validate time normal start and time_normal_finish
6631   --
6632   chk_time_start_finish
6633   (p_position_id          => p_rec.position_id
6634   ,p_time_normal_start    => p_rec.time_normal_start
6635   ,p_time_normal_finish   => p_rec.time_normal_finish
6636   ,p_effective_date       => p_effective_date
6637   );
6638   --
6639 if g_debug then
6640   hr_utility.set_location(l_proc, 200);
6641 end if;
6642   --
6643   chk_entry_step_id
6644   (p_position_id              => p_rec.position_id
6645   ,p_entry_step_id            => p_rec.entry_step_id
6646   ,p_entry_grade_id           => p_rec.entry_grade_id
6647   ,p_business_group_id        => p_rec.business_group_id
6648   ,p_validation_start_date    => p_validation_start_date
6649   ,p_validation_end_date      => p_validation_end_date
6650   ,p_effective_date           => p_effective_date
6651   ,p_object_version_number    => p_rec.object_version_number
6652   );
6653 if g_debug then
6654 hr_utility.set_location(l_proc, 210);
6655 end if;
6656 chk_entry_grade_id
6657   (p_position_id              => p_rec.position_id
6658   ,p_business_group_id        => p_rec.business_group_id
6659   ,p_entry_grade_id           => p_rec.entry_grade_id
6660   ,p_effective_date           => p_effective_date
6661   ,p_validation_start_date    => p_validation_start_date
6662   ,p_validation_end_date      => p_validation_end_date
6663   ,p_object_version_number    => p_rec.object_version_number
6664   );
6665   --
6666 if g_debug then
6667   hr_utility.set_location(l_proc, 215);
6668 end if;
6669   --
6670   chk_entry_grade_rule_id
6671   (p_position_id              => p_rec.position_id
6672   ,p_business_group_id        => p_rec.business_group_id
6673   ,p_entry_grade_rule_id      => p_rec.entry_grade_rule_id
6674   ,p_effective_date           => p_effective_date
6675   ,p_validation_start_date    => p_validation_start_date
6676   ,p_validation_end_date      => p_validation_end_date
6677   ,p_object_version_number    => p_rec.object_version_number
6678   );
6679   --
6680 if g_debug then
6681   hr_utility.set_location(l_proc, 220);
6682 end if;
6683   --
6684   chk_work_term_end_month_cd
6685   (p_position_id            => p_rec.position_id
6686   ,p_work_term_end_month_cd => p_rec.work_term_end_month_cd
6687   ,p_effective_date         => p_effective_date
6688   ,p_validation_start_date  => p_validation_start_date
6689   ,p_validation_end_date    => p_validation_end_date
6690   ,p_object_version_number  => p_rec.object_version_number);
6691   --
6692 if g_debug then
6693   hr_utility.set_location(l_proc, 230);
6694 end if;
6695   --
6696   chk_work_term_end_day_cd
6697   (p_position_id           => p_rec.position_id
6698   ,p_work_term_end_day_cd  => p_rec.work_term_end_day_cd
6699   ,p_effective_date        => p_effective_date
6700   ,p_validation_start_date => p_validation_start_date
6701   ,p_validation_end_date   => p_validation_end_date
6702   ,p_object_version_number => p_rec.object_version_number);
6703   --
6704 if g_debug then
6705   hr_utility.set_location(l_proc, 240);
6706 end if;
6707   --
6708   chk_work_period_type_cd
6709   (p_position_id           => p_rec.position_id
6710   ,p_work_period_type_cd   => p_rec.work_period_type_cd
6711   ,p_effective_date        => p_effective_date
6712   ,p_validation_start_date => p_validation_start_date
6713   ,p_validation_end_date   => p_validation_end_date
6714   ,p_object_version_number => p_rec.object_version_number);
6715   --
6716 if g_debug then
6717   hr_utility.set_location(l_proc, 250);
6718 end if;
6719   --
6720   chk_works_council_approval_flg
6721   (p_position_id                 => p_rec.position_id
6722   ,p_works_council_approval_flag => p_rec.works_council_approval_flag
6723   ,p_effective_date              => p_effective_date
6724   ,p_validation_start_date       => p_validation_start_date
6725   ,p_validation_end_date         => p_validation_end_date
6726   ,p_object_version_number       => p_rec.object_version_number);
6727   --
6728 if g_debug then
6729   hr_utility.set_location(l_proc, 260);
6730 end if;
6731   --
6732   chk_term_start_month_cd
6733   (p_position_id           => p_rec.position_id
6734   ,p_term_start_month_cd   => p_rec.term_start_month_cd
6735   ,p_effective_date        => p_effective_date
6736   ,p_validation_start_date => p_validation_start_date
6737   ,p_validation_end_date   => p_validation_end_date
6738   ,p_object_version_number => p_rec.object_version_number);
6739   --
6740 if g_debug then
6741   hr_utility.set_location(l_proc, 270);
6742 end if;
6743   --
6744   chk_term_start_day_cd
6745   (p_position_id           => p_rec.position_id
6746   ,p_term_start_day_cd     => p_rec.term_start_day_cd
6747   ,p_effective_date        => p_effective_date
6748   ,p_validation_start_date => p_validation_start_date
6749   ,p_validation_end_date   => p_validation_end_date
6750   ,p_object_version_number => p_rec.object_version_number);
6751   --
6752 if g_debug then
6753   hr_utility.set_location(l_proc, 280);
6754 end if;
6755   --
6756   chk_seasonal_flag
6757   (p_position_id           => p_rec.position_id
6758   ,p_seasonal_flag         => p_rec.seasonal_flag
6759   ,p_effective_date        => p_effective_date
6760   ,p_validation_start_date => p_validation_start_date
6761   ,p_validation_end_date   => p_validation_end_date
6762   ,p_object_version_number => p_rec.object_version_number);
6763   --
6764 if g_debug then
6765   hr_utility.set_location(l_proc, 290);
6766 end if;
6767   --
6768   chk_review_flag
6769   (p_position_id           => p_rec.position_id
6770   ,p_review_flag           => p_rec.review_flag
6771   ,p_effective_date        => p_effective_date
6772   ,p_validation_start_date => p_validation_start_date
6773   ,p_validation_end_date   => p_validation_end_date
6774   ,p_object_version_number => p_rec.object_version_number);
6775   --
6776 if g_debug then
6777   hr_utility.set_location(l_proc, 300);
6778 end if;
6779   --
6780   chk_replacement_required_flag
6781   (p_position_id               => p_rec.position_id
6782   ,p_replacement_required_flag => p_rec.replacement_required_flag
6783   ,p_effective_date            => p_effective_date
6784   ,p_validation_start_date     => p_validation_start_date
6785   ,p_validation_end_date       => p_validation_end_date
6786   ,p_object_version_number     => p_rec.object_version_number);
6787   --
6788 if g_debug then
6789   hr_utility.set_location(l_proc, 310);
6790 end if;
6791   --
6792   chk_probation_period_unit_cd
6793   (p_position_id              => p_rec.position_id
6794   ,p_probation_period_unit_cd => p_rec.probation_period_unit_cd
6795   ,p_effective_date           => p_effective_date
6796   ,p_validation_start_date    => p_validation_start_date
6797   ,p_validation_end_date      => p_validation_end_date
6798   ,p_object_version_number    => p_rec.object_version_number);
6799   --
6800 if g_debug then
6801   hr_utility.set_location(l_proc, 320);
6802 end if;
6803   --
6804   chk_permit_recruitment_flag
6805   (p_position_id             => p_rec.position_id
6806   ,p_permit_recruitment_flag => p_rec.permit_recruitment_flag
6807   ,p_effective_date          => p_effective_date
6808   ,p_validation_start_date   => p_validation_start_date
6809   ,p_validation_end_date     => p_validation_end_date
6810   ,p_object_version_number   => p_rec.object_version_number);
6811   --
6812 if g_debug then
6813   hr_utility.set_location(l_proc, 330);
6814 end if;
6815   --
6816   chk_permanent_temporary_flag
6817   (p_position_id              => p_rec.position_id
6818   ,p_permanent_temporary_flag => p_rec.permanent_temporary_flag
6819   ,p_effective_date           => p_effective_date
6820   ,p_validation_start_date    => p_validation_start_date
6821   ,p_validation_end_date      => p_validation_end_date
6822   ,p_object_version_number    => p_rec.object_version_number);
6823   --
6824 if g_debug then
6825   hr_utility.set_location(l_proc, 335);
6826 end if;
6827 --
6828 -- for bug fix 5250975
6829 chk_permanent_seasonal_flag
6830   (p_position_id               => p_rec.position_id
6831   ,p_permanent_temporary_flag  => p_rec.permanent_temporary_flag
6832   ,p_seasonal_flag             => p_rec.seasonal_flag
6833   ,p_effective_date            => p_effective_date
6834   ,p_object_version_number     => p_rec.object_version_number);
6835 --
6836 
6837 if g_debug then
6838   hr_utility.set_location(l_proc, 340);
6839 end if;
6840   --
6841   chk_pay_term_end_month_cd
6842   (p_position_id           => p_rec.position_id
6843   ,p_pay_term_end_month_cd => p_rec.pay_term_end_month_cd
6844   ,p_effective_date        => p_effective_date
6845   ,p_validation_start_date => p_validation_start_date
6846   ,p_validation_end_date   => p_validation_end_date
6847   ,p_object_version_number => p_rec.object_version_number);
6848   --
6849 if g_debug then
6850   hr_utility.set_location(l_proc, 350);
6851 end if;
6852   --
6853   chk_pay_term_end_day_cd
6854   (p_position_id           => p_rec.position_id
6855   ,p_pay_term_end_day_cd   => p_rec.pay_term_end_day_cd
6856   ,p_effective_date        => p_effective_date
6857   ,p_validation_start_date => p_validation_start_date
6858   ,p_validation_end_date   => p_validation_end_date
6859   ,p_object_version_number => p_rec.object_version_number);
6860   --
6861 if g_debug then
6862   hr_utility.set_location(l_proc, 360);
6863 end if;
6864   --
6865   chk_overlap_unit_cd
6866   (p_position_id           => p_rec.position_id
6867   ,p_overlap_unit_cd       => p_rec.overlap_unit_cd
6868   ,p_effective_date        => p_effective_date
6869   ,p_validation_start_date => p_validation_start_date
6870   ,p_validation_end_date   => p_validation_end_date
6871   ,p_object_version_number => p_rec.object_version_number);
6872   --
6873 if g_debug then
6874   hr_utility.set_location(l_proc, 370);
6875 end if;
6876   --
6877   chk_bargaining_unit_cd
6878   (p_position_id           => p_rec.position_id
6879   ,p_bargaining_unit_cd    => p_rec.bargaining_unit_cd
6880   ,p_effective_date        => p_effective_date
6881   ,p_validation_start_date => p_validation_start_date
6882   ,p_validation_end_date   => p_validation_end_date
6883   ,p_object_version_number => p_rec.object_version_number);
6884   --
6885 if g_debug then
6886   hr_utility.set_location(l_proc, 380);
6887 end if;
6888   --
6889   chk_pay_freq_payroll_id
6890   (p_position_id           => p_rec.position_id
6891   ,p_business_group_id     => p_rec.business_group_id
6892   ,p_pay_freq_payroll_id   => p_rec.pay_freq_payroll_id
6893   ,p_validation_start_date => p_validation_start_date
6894   ,p_validation_end_date   => p_validation_end_date
6895   ,p_effective_date        => p_effective_Date
6896   ,p_datetrack_mode        => p_datetrack_mode
6897   ,p_object_version_number => p_rec.object_version_number
6898   );
6899   --
6900 if g_debug then
6901   hr_utility.set_location(l_proc, 390);
6902 end if;
6903   --
6904 /*
6905   chk_position_transaction_id
6906   (p_position_id              => p_rec.position_id
6907   ,p_position_transaction_id  => p_rec.position_transaction_id
6908   ,p_validation_start_date    => p_validation_start_date
6909   ,p_validation_end_date      => p_validation_end_date
6910   ,p_effective_date           => p_effective_date
6911   ,p_object_version_number    => p_rec.object_version_number
6912   );
6913 */
6914   --
6915 if g_debug then
6916   hr_utility.set_location(l_proc, 400);
6917 end if;
6918   --
6919   chk_supervisor_position_id
6920   (p_business_group_id      => p_rec.business_group_id
6921   ,p_position_id            => p_rec.position_id
6922   ,p_supervisor_position_id => p_rec.supervisor_position_id
6923   ,p_validation_start_date  => p_validation_start_date
6924   ,p_validation_end_date    => p_validation_end_date
6925   ,p_effective_date      => p_effective_date
6926   ,p_object_version_number  => p_rec.object_version_number
6927   );
6928   --
6929 if g_debug then
6930   hr_utility.set_location(l_proc, 410);
6931 end if;
6932   --
6933   chk_prior_position_id
6934   (p_business_group_id      => p_rec.business_group_id
6935   ,p_position_id            => p_rec.position_id
6936   ,p_prior_position_id      => p_rec.prior_position_id
6937   ,p_validation_start_date  => p_validation_start_date
6938   ,p_validation_end_date    => p_validation_end_date
6939   ,p_effective_date      => p_effective_date
6940   ,p_object_version_number  => p_rec.object_version_number
6941   );
6942   --
6943 if g_debug then
6944   hr_utility.set_location(l_proc, 420);
6945 end if;
6946   --
6947   chk_availability_status_id
6948    (p_position_id            => p_rec.position_id
6949    ,p_validation_start_date  => p_validation_start_date
6950    ,p_availability_status_id => p_rec.availability_status_id
6951    ,p_old_avail_status_id    => hr_psf_shd.g_old_rec.availability_status_id
6952    ,p_effective_date         => p_effective_date
6953    ,p_date_effective         => p_rec.date_effective
6954    ,p_business_group_id      => p_rec.business_group_id
6955    ,p_object_version_number  => p_rec.object_version_number
6956    ,p_datetrack_mode         => p_datetrack_mode );
6957   --
6958 if g_debug then
6959   hr_utility.set_location(l_proc, 430);
6960 end if;
6961   --
6962   chk_position_type
6963   (p_position_id             => p_rec.position_id
6964   ,p_position_type           => p_rec.position_type
6965   ,p_effective_date          => p_effective_date
6966   ,p_validation_start_date   => p_validation_start_Date
6967   ,p_validation_end_date     => p_validation_end_date
6968   ,p_object_version_number   => p_rec.object_version_number
6969   );
6970   --
6971 if g_debug then
6972   hr_utility.set_location(l_proc, 440);
6973 end if;
6974   --
6975   chk_fte
6976   (p_position_id               => p_rec.position_id
6977   ,p_fte                       => p_rec.fte
6978   ,p_position_type             => p_rec.position_type
6979   ,p_effective_date            => p_effective_date
6980   ,p_validation_start_date     => p_validation_start_date
6981   ,p_validation_end_date       => p_validation_end_Date
6982   ,p_object_version_number     => p_rec.object_version_number);
6983   --
6984 if g_debug then
6985   hr_utility.set_location(l_proc, 445);
6986 end if;
6987   --
6988   chk_max_persons
6989   (p_position_id               => p_rec.position_id
6990   ,p_max_persons               => p_rec.max_persons
6991   ,p_position_type             => p_rec.position_type
6992   ,p_effective_date            => p_effective_date
6993   ,p_object_version_number     => p_rec.object_version_number);
6994   --
6995 if g_debug then
6996   hr_utility.set_location(l_proc, 450);
6997 end if;
6998   --
6999   if (p_rec.position_transaction_id is null)  then
7000   chk_reserved_fte
7001   (p_position_id               => p_rec.position_id
7002   ,p_fte                       => p_rec.fte
7003   ,p_position_type             => p_rec.position_type
7004   ,p_effective_date            => p_effective_date
7005   ,p_validation_start_date     => p_validation_start_date
7006   ,p_validation_end_date       => p_validation_end_Date
7007   ,p_object_version_number     => p_rec.object_version_number);
7008   end if;
7009   --
7010 if g_debug then
7011   hr_utility.set_location(l_proc, 455);
7012 end if;
7013   --
7014   chk_extended_pay
7015   (p_position_id               => p_rec.position_id
7016   ,p_work_period_type_cd       => p_rec.work_period_type_cd
7017   ,p_term_start_day_cd         => p_rec.term_start_day_cd
7018   ,p_term_start_month_cd       => p_rec.term_start_month_cd
7019   ,p_pay_term_end_day_cd       => p_rec.pay_term_end_day_cd
7020   ,p_pay_term_end_month_cd     => p_rec.pay_term_end_month_cd
7021   ,p_work_term_end_day_cd      => p_rec.work_term_end_day_cd
7022   ,p_work_term_end_month_cd    => p_rec.work_term_end_month_cd
7023   );
7024   --
7025 if g_debug then
7026   hr_utility.set_location(l_proc, 460);
7027 end if;
7028   --
7029   chk_proposed_fte_for_layoff
7030   (p_fte                      => p_rec.fte
7031   ,p_proposed_fte_for_layoff  => p_rec.proposed_fte_for_layoff
7032   ,p_proposed_date_for_layoff => p_rec.proposed_Date_for_layoff
7033   );
7034   --
7035 if g_debug then
7036   hr_utility.set_location(l_proc, 470);
7037 end if;
7038   --
7039   --
7040   -- Call the datetrack update integrity operation
7041   --
7042   dt_update_validate
7043     (p_supervisor_position_id        => p_rec.supervisor_position_id,
7044      p_successor_position_id         => p_rec.successor_position_id,
7045      p_relief_position_id            => p_rec.relief_position_id,
7046      p_pay_freq_payroll_id           => p_rec.pay_freq_payroll_id,
7047      p_entry_grade_rule_id           => p_rec.entry_grade_rule_id,
7048      p_entry_step_id                 => p_rec.entry_step_id,
7049      p_datetrack_mode                => p_datetrack_mode,
7050      p_validation_start_date       => p_validation_start_date,
7051      p_validation_end_date      => p_validation_end_date);
7052   --
7053   --
7054 if g_debug then
7055   hr_utility.set_location(l_proc, 480);
7056 end if;
7057   --
7058   --
7059   chk_proposed_status
7060   (p_position_id               =>p_rec.position_id
7061   ,p_availability_status_id    =>p_rec.availability_status_id
7062   ,p_business_group_id         =>p_rec.business_group_id
7063   ,p_effective_date            =>p_effective_date
7064   ,p_validate_start_date       =>p_validation_start_date
7065   ,p_validate_end_date         =>p_validation_end_date
7066   ,p_object_version_number     =>p_rec.object_version_number
7067   ,p_datetrack_mode            =>p_datetrack_mode);
7068   --
7069   -- Call all supporting business operations
7070   --
7071   --
7072 if g_debug then
7073   hr_utility.set_location(l_proc, 490);
7074 end if;
7075   --
7076   -- validate end dates
7077   chk_end_dates
7078   (position_id                => p_rec.position_id
7079   ,availability_status_id     => p_rec.availability_status_id
7080   ,p_effective_date           => p_effective_date
7081   ,current_org_prop_end_date  => p_rec.current_org_prop_end_date
7082   ,current_job_prop_end_date  => p_rec.current_job_prop_end_date
7083   ,avail_status_prop_end_date => p_rec.avail_status_prop_end_date
7084   ,earliest_hire_date         => p_rec.earliest_hire_date
7085   ,fill_by_date               => p_rec.fill_by_date
7086   ,proposed_date_for_layoff   => p_rec.proposed_date_for_layoff
7087   ,date_effective             => p_rec.date_effective );
7088   --
7089 if g_debug then
7090   hr_utility.set_location(l_proc, 500);
7091 end if;
7092   --
7093   -- Validate date effective
7094   --
7095   chk_dates
7096     (p_position_id            => p_rec.position_id
7097     ,p_date_effective      => p_rec.date_effective
7098     ,p_date_end            => p_rec.date_end
7099     ,p_validation_start_date => p_validation_start_date
7100     ,p_validation_end_date   => p_validation_end_date
7101     ,p_effective_Date        => p_effective_date
7102     ,p_object_version_number => p_rec.object_version_number
7103   );
7104   --
7105   --
7106   --
7107 if g_debug then
7108   hr_utility.set_location(l_proc, 510);
7109 end if;
7110   --
7111   chk_seasonal_poi
7112   (p_position_id     => p_rec.position_id
7113   ,p_seasonal_flag      => p_rec.seasonal_flag
7114   ,p_effective_date             => p_effective_date
7115   ,p_validation_start_date      => p_validation_start_Date
7116   ,p_validation_end_date        => p_validation_end_date
7117   ,p_object_version_number      => p_rec.object_version_number);
7118   --
7119 if g_debug then
7120   hr_utility.set_location(l_proc, 520);
7121 end if;
7122   --
7123   chk_overlap_poi
7124   (p_position_id     => p_rec.position_id
7125   ,p_overlap_period     => p_rec.overlap_period
7126   ,p_effective_date             => p_effective_date
7127   ,p_validation_start_date      => p_validation_start_Date
7128   ,p_validation_end_date        => p_validation_end_date
7129   ,p_object_version_number      => p_rec.object_version_number);
7130   --
7131 if g_debug then
7132   hr_utility.set_location(l_proc, 530);
7133 end if;
7134   --
7135 /*
7136 chk_extended_pay_permit
7137 (p_position_id            => p_rec.position_id
7138   ,p_work_period_type_cd        => p_rec.work_period_type_cd
7139   ,p_effective_date             => p_effective_date
7140   ,p_validation_start_date      => p_validation_start_Date
7141   ,p_validation_end_date        => p_validation_end_date
7142   ,p_object_version_number      => p_rec.object_version_number
7143 );
7144   --
7145 if g_debug then
7146   hr_utility.set_location('Entering:'||l_proc, 450);
7147 end if;
7148   --
7149   -- Validate status
7150   --
7151   chk_status
7152     (p_position_id            => p_rec.position_id
7153     ,p_status                 => p_rec.status
7154     ,p_object_version_number  => p_rec.object_version_number
7155   );
7156 */
7157   --
7158 if g_debug then
7159   hr_utility.set_location('Entering:'||l_proc, 600);
7160 end if;
7161   --
7162   -- PMFLETCH ** Not using this uniqueness chech anymore **
7163   -- Check position_name is unique for Business_group
7164   --
7165   --chk_name_unique_for_BG
7166   -- (p_business_group_id    => p_rec.business_group_id
7167   -- ,p_position_id          => p_rec.position_id
7168   -- ,p_effective_date       => p_effective_date
7169   -- ,p_name                 => p_rec.name
7170   -- ,p_object_version_number  => p_rec.object_version_number
7171   -- );
7172   --
7173   -- PMFLETCH Check position_definition_id is unique for business group
7174   --
7175   chk_ccid_unique_for_BG
7176     (p_business_group_id             => p_rec.business_group_id
7177     ,p_position_id                   => p_rec.position_id
7178     ,p_position_definition_id        => p_rec.position_definition_id
7179     ,p_validation_start_date         => p_validation_start_date
7180     ,p_validation_end_date           => p_validation_end_date
7181     ,p_effective_date                => p_effective_date
7182     ,p_object_version_number         => p_rec.object_version_number
7183     );
7184   --
7185   --
7186 if g_debug then
7187   hr_utility.set_location(l_proc, 610);
7188 end if;
7189   --
7190   -- Check validation for position_type change to Single
7191   --
7192   chk_position_type_single
7193   (  p_position_id              => p_rec.position_id
7194     ,p_position_type            => p_rec.position_type
7195     ,p_effective_date           => p_effective_date
7196     ,p_object_version_number    => p_rec.object_version_number);
7197   --
7198 if g_debug then
7199   hr_utility.set_location(l_proc, 620);
7200 end if;
7201   --
7202   --
7203   --
7204   -- Call developer descriptive flexfield validation routines
7205   --
7206   -- hr_psf_bus.chk_ddf(p_rec => p_rec);
7207   --
7208   --
7209 if g_debug then
7210   hr_utility.set_location(l_proc, 630);
7211 end if;
7212   --
7213   -- Call descriptive flexfield validation routines
7214   --
7215   hr_psf_bus.chk_df(p_rec => p_rec);
7216   --
7217   --
7218   -- Call to validate Position Control Business Rules
7219   --
7220   if (per_pqh_shr.position_control_enabled
7221                 ( p_organization_id => p_rec.organization_id
7222                 , p_effective_date  => p_effective_date
7223                 ) = 'Y') then
7224     --
7225     if p_rec.position_transaction_id is null then
7226       hr_utility.set_message(800, 'PER_CANT_CRE_PC_POS_NO_TXN');
7227       hr_utility.raise_error;
7228     end if;
7229     --
7230   end if;
7231   --
7232   per_pqh_shr.hr_psf_bus('UPDATE_VALIDATE',p_rec
7233     ,p_effective_date
7234     ,p_validation_start_date
7235     ,p_validation_end_date
7236     ,p_datetrack_mode);
7237   --
7238   --
7239   --End of Position Control Business Rules call
7240   --
7241   --
7242 if g_debug then
7243   hr_utility.set_location(' Leaving:'||l_proc, 700);
7244 end if;
7245   --
7246 End update_validate;
7247 --
7248 procedure delete_date_effective(p_position_id           in number
7249                                ,p_object_version_number in number
7250                                ,p_business_group_id     in number
7251                                ,p_datetrack_mode        in varchar2 ) is
7252  l_proc varchar2(72) ;
7253  l_next_stat varchar2(30);
7254  l_next_esd date;
7255  l_next_eed date;
7256  l_esd date;
7257  l_eed date;
7258  l_eot date := to_date('31/12/4712','dd/mm/yyyy');
7259 -- fetches the next row info. given effective start date
7260  cursor next_row(p_effective_start_date date) is
7261     select effective_start_date,effective_end_date
7262            ,hr_psf_shd.get_availability_status(availability_status_id,p_business_group_id)
7263     from hr_all_positions_f
7264     where position_id = p_position_id
7265     and effective_start_date > p_effective_start_date
7266     order by effective_start_date ;
7267   cursor current_row is
7268     select effective_start_date,effective_end_date
7269     from hr_all_positions_f
7270     where position_id = p_position_id
7271     and object_version_number = p_object_version_number ;
7272   cursor pos_all is
7273     select date_effective
7274     from hr_all_positions_f
7275     where position_id = p_position_id
7276     for update of date_effective;
7277 begin
7278 if g_debug then
7279  l_proc  := g_package||'delete_date_effective ';
7280   hr_utility.set_location('entering '||l_proc,5);
7281 end if;
7282   if p_datetrack_mode ='DELETE_NEXT_CHANGE' then
7283      open current_row ;
7284      fetch current_row into l_esd,l_eed ;
7285      close current_row ;
7286      -- effective start date of current row is fetched from the database
7287      -- that will be used to fetch the next row and its status
7288      if l_eed < l_eot then
7289 if g_debug then
7290         hr_utility.set_location('first row fetched and next row there '||l_proc,15);
7291 end if;
7292         open next_row(l_esd);
7293         fetch next_row into l_next_esd,l_next_eed,l_next_stat;
7294         if next_row%found then
7295       if l_next_eed <l_eot and l_next_stat = 'ACTIVE' then
7296 if g_debug then
7297               hr_utility.set_location('next row active and next row there '||l_proc,25);
7298 end if;
7299          fetch next_row into l_next_esd,l_next_eed,l_next_stat ;
7300          if l_next_stat = 'ACTIVE' then
7301        -- next to next row is active effective start date of that row will be
7302        -- made date effective for all the rows.
7303 if g_debug then
7304                  hr_utility.set_location('next row active changing date effective '||l_proc,35);
7305 end if;
7306        for i in pos_all loop
7307            update hr_all_positions_f
7308            set date_effective = l_next_esd
7309            where current of pos_all ;
7310        end loop;
7311          end if;
7312       end if;
7313         end if;
7314    close next_row;
7315      end if;
7316   end if;
7317 if g_debug then
7318   hr_utility.set_location('Leaving '||l_proc,100);
7319 end if;
7320 end;
7321 -- ----------------------------------------------------------------------------
7322 -- |-------------------------< pre_delete_checks >-----------------------------|
7323 -- ----------------------------------------------------------------------------
7324 --
7325 PROCEDURE pre_delete_checks(p_position_id        in  number
7326                            ,p_business_group_id  in  number
7327                            ,p_datetrack_mode  in  varchar2
7328                            ) is
7329  --
7330   l_exists                   varchar2(1);
7331   l_pos_structure_element_id number;
7332   l_sql_text                 VARCHAR2(2000);
7333   l_oci_out                  VARCHAR2(1);
7334   l_sql_cursor               NUMBER;
7335   l_rows_fetched             NUMBER;
7336   l_proc                  varchar2(72) ;
7337 
7338 begin
7339 if g_debug then
7340   l_proc                   := g_package||'pre_delete_checks';
7341  hr_utility.set_location('Entering : ' || l_proc, 10);
7342 end if;
7343  if p_datetrack_mode = 'ZAP' then
7344 if g_debug then
7345      hr_utility.set_location(l_proc, 20);
7346 end if;
7347      l_exists := NULL;
7348 --     if p_hr_ins = 'Y' then
7349          l_exists := NULL;
7350          begin
7351          select '1'
7352          into l_exists
7353          from sys.dual
7354          where exists(SELECT  NULL
7355                       from    PER_BUDGET_ELEMENTS BE
7356                       where   BE.POSITION_ID = p_position_id);
7357          exception when no_data_found then
7358                        null;
7359          end;
7360          if l_exists = '1' then
7361            hr_utility.set_message(801,'PER_7417_POS_ASSIGNMENT');
7362            hr_utility.raise_error;
7363          end if;
7364          l_exists := NULL;
7365 if g_debug then
7366          hr_utility.set_location(l_proc, 30);
7367 end if;
7368          begin
7369          select '1'
7370          into l_exists
7371          from sys.dual
7372          where exists(SELECT  NULL
7373                       from    PER_ALL_VACANCIES VAC
7374                       where   VAC.POSITION_ID = p_position_id);
7375          exception when no_data_found then
7376                        null;
7377          end;
7378          if l_exists = '1' then
7379            hr_utility.set_message(801,'PER_7861_DEL_POS_REC_ACT');
7380            hr_utility.raise_error;
7381          end if;
7382 if g_debug then
7383          hr_utility.set_location(l_proc, 40);
7384 end if;
7385 /**** Commented for Bug 9146790 **********
7386          begin
7387          select  e.pos_structure_element_id
7388          into    l_pos_structure_element_id
7389          from    per_pos_structure_elements e
7390          where   e.parent_position_id = p_position_id
7391          and     not exists (
7392                              select  null
7393          from    per_pos_structure_elements e2
7394          where   e2.subordinate_position_id = p_position_id)
7395          and     1 = (
7396                       select  count(e3.pos_structure_element_id)
7397                       from    per_pos_structure_elements e3
7398                       where   e3.parent_position_id = p_position_id);
7399          exception when no_data_found then
7400                         null;
7401          end;
7402 **** Commented for Bug 9146790 **********/
7403 if g_debug then
7404          hr_utility.set_location(l_proc, 50);
7405 end if;
7406          l_exists := NULL;
7407 	-- if l_pos_structure_element_id is null then			-- condition removed (Bug 9146790)
7408             begin
7409             select '1'
7410             into l_exists
7411             from sys.dual
7412             where exists(SELECT  NULL
7413                       FROM   PER_POS_STRUCTURE_ELEMENTS PSE
7414                       WHERE  PSE.PARENT_POSITION_ID      = p_position_id
7415                       OR     PSE.SUBORDINATE_POSITION_ID = p_position_id) ;
7416             exception when no_data_found then
7417                         null;
7418             end;
7419 if g_debug then
7420             hr_utility.set_location(l_proc, 70);
7421 end if;
7422             if l_exists = '1' then
7423                hr_utility.set_message(801,'PER_7416_POS_IN_POS_HIER');
7424                hr_utility.raise_error;
7425             end if;
7426         -- end if;							-- Bug 9146790
7427 
7428          l_exists := NULL;
7429 if g_debug then
7430          hr_utility.set_location(l_proc, 80);
7431 end if;
7432          begin
7433          select '1'
7434          into l_exists
7435          from sys.dual
7436          where exists(SELECT  NULL
7437                       FROM PER_VALID_GRADES VG1
7438                       WHERE business_group_id + 0 = p_business_group_id
7439                       AND VG1.POSITION_ID = p_position_id);
7440          exception when no_data_found then
7441                         null;
7442          end;
7443 if g_debug then
7444          hr_utility.set_location(l_proc, 90);
7445 end if;
7446          if l_exists = '1' then
7447                hr_utility.set_message(801,'PER_7865_DEF_POS_DEL_GRADE');
7448                hr_utility.raise_error;
7449          end if;
7450          l_exists := NULL;
7451 if g_debug then
7452          hr_utility.set_location(l_proc, 100);
7453 end if;
7454          begin
7455          select '1'
7456          into l_exists
7457          from sys.dual
7458          where exists(select  null
7459                       from per_job_requirements jre1
7460                       where jre1.position_id = p_position_id);
7461          exception when no_data_found then
7462                         null;
7463          end;
7464          if l_exists = '1' then
7465              hr_utility.set_message(801,'PER_7866_DEF_POS_DEL_REQ');
7466              hr_utility.raise_error;
7467          end if;
7468          l_exists := NULL;
7469 if g_debug then
7470          hr_utility.set_location(l_proc, 110);
7471 end if;
7472          begin
7473          select '1'
7474          into l_exists
7475          from sys.dual
7476          where exists(select  null
7477                       from per_job_evaluations jev1
7478                       where jev1.position_id = p_position_id);
7479          exception when no_data_found then
7480                         null;
7481          end;
7482          if l_exists = '1' then
7483              hr_utility.set_message(801,'PER_7867_DEF_POS_DEL_EVAL');
7484              hr_utility.raise_error;
7485          end if;
7486 
7487          l_exists := NULL;
7488 if g_debug then
7489          hr_utility.set_location(l_proc, 120);
7490 end if;
7491          begin
7492          select '1'
7493          into l_exists
7494          from sys.dual
7495          where exists(select  null
7496                       from hr_all_positions_f
7497                       where successor_position_id = p_position_id);
7498          exception when no_data_found then
7499                         null;
7500 
7501          end;
7502 
7503          if l_exists = '1' then
7504              hr_utility.set_message(801,'PER_7996_POS_SUCCESSOR_REF');
7505              hr_utility.raise_error;
7506          end if;
7507 
7508          l_exists := NULL;
7509 if g_debug then
7510          hr_utility.set_location(l_proc, 120);
7511 end if;
7512          begin
7513          select '1'
7514          into l_exists
7515          from sys.dual
7516          where exists(select  null
7517                       from hr_all_positions_f
7518                       where supervisor_position_id = p_position_id);
7519          exception when no_data_found then
7520                         null;
7521 
7522          end;
7523 
7524          if l_exists = '1' then
7525              hr_utility.set_message(800,'HR_PSF_SUPERVISOR_REF');
7526              hr_utility.raise_error;
7527          end if;
7528 
7529          l_exists := NULL;
7530 if g_debug then
7531          hr_utility.set_location(l_proc, 130);
7532 end if;
7533 /*
7534          begin
7535          select '1'
7536          into l_exists
7537          from sys.dual
7538          where exists(select  null
7539                       from per_position_extra_info
7540                       where position_id = p_position_id);
7541          exception when no_data_found then
7542                         null;
7543          end;
7544          if l_exists = '1' then
7545              hr_utility.set_message(800,'HR_DEL_POS_EXTRA_INFO');
7546              hr_utility.raise_error;
7547          end if;
7548 */
7549          l_exists := NULL;
7550 if g_debug then
7551          hr_utility.set_location(l_proc, 140);
7552 end if;
7553 
7554          begin
7555          select '1'
7556          into l_exists
7557          from sys.dual
7558          where exists(select  null
7559                       from per_mm_positions
7560                       where new_position_id = p_position_id);
7561          exception when no_data_found then
7562                         null;
7563          end;
7564 
7565          if l_exists = '1' then
7566              hr_utility.set_message(800,'HR_52776_NOT_DEL_MM_POSITIONS');
7567              hr_utility.raise_error;
7568          end if;
7569          --
7570          l_exists := NULL;
7571 if g_debug then
7572          hr_utility.set_location(l_proc, 150);
7573 end if;
7574 /* new logic
7575          --
7576          begin
7577          select '1'
7578          into l_exists
7579          from sys.dual
7580          where exists(select  null
7581                       from pqh_position_transactions
7582                       where position_id = p_position_id);
7583          exception when no_data_found then
7584                         null;
7585          end;
7586          --
7587          if l_exists = '1' then
7588              hr_utility.set_message(800,'HR_NOT_DEL_PTX');
7589              hr_utility.raise_error;
7590          end if;
7591          --
7592          l_exists := NULL;
7593 if g_debug then
7594          hr_utility.set_location(l_proc, 150);
7595 end if;
7596          --
7597          begin
7598          select '1'
7599          into l_exists
7600          from sys.dual
7601          where exists(select  null
7602                       from pqh_attribute_ranges
7603                       where position_id = p_position_id);
7604          exception when no_data_found then
7605                         null;
7606          end;
7607          --
7608          if l_exists = '1' then
7609              hr_utility.set_message(800,'HR_NOT_DEL_ATT_RANGES');
7610              hr_utility.raise_error;
7611          end if;
7612          --
7613          l_exists := NULL;
7614 if g_debug then
7615          hr_utility.set_location(l_proc, 150);
7616 end if;
7617          --
7618          begin
7619          select '1'
7620          into l_exists
7621          from sys.dual
7622          where exists(select  null
7623                       from pqh_budgets
7624                       where position_id = p_position_id);
7625          exception when no_data_found then
7626                         null;
7627          end;
7628          --
7629          if l_exists = '1' then
7630              hr_utility.set_message(800,'HR_NOT_DEL_BGT');
7631              hr_utility.raise_error;
7632          end if;
7633          --
7634          l_exists := NULL;
7635 if g_debug then
7636          hr_utility.set_location(l_proc, 150);
7637 end if;
7638          --
7639          begin
7640          select '1'
7641          into l_exists
7642          from sys.dual
7643          where exists(select  null
7644                       from pqh_worksheet_details
7645                       where position_id = p_position_id);
7646          exception when no_data_found then
7647                         null;
7648          end;
7649          --
7650          if l_exists = '1' then
7651              hr_utility.set_message(800,'HR_NOT_WKS_DETAIL');
7652              hr_utility.raise_error;
7653          end if;
7654 --     end if;
7655 */
7656     --
7657     -- is po installed?
7658     -- fix for bug 8439584
7659 --    if p_po_ins = 'Y' then
7660       begin
7661         l_sql_text := 'select null '
7662            ||' from sys.dual '
7663            ||' where exists( select null '
7664            ||'    from   po_system_parameters '
7665            ||'    where  security_position_structure_id = '
7666            ||to_char(p_position_id)
7667            ||' ) '
7668            ||' or exists( select null '
7669            ||'    from   po_employee_hierarchies '
7670            ||'    where  employee_position_id = '
7671            ||to_char(p_position_id)
7672            ||' or    superior_position_id = '
7673            ||to_char(p_position_id)
7674            ||' ) '
7675 	   || ' or exists ( select null '
7676 	   || ' from po_position_controls_all '
7677 	   || '    where  position_id = '
7678            || to_char(p_position_id)
7679            ||' ) ';
7680       --
7681       -- Open Cursor for Processing Sql statment.
7682       --
7683 if g_debug then
7684       hr_utility.set_location(l_proc, 150);
7685 end if;
7686       l_sql_cursor := dbms_sql.open_cursor;
7687       --
7688       -- Parse SQL statement.
7689       --
7690       dbms_sql.parse(l_sql_cursor, l_sql_text, dbms_sql.v7);
7691       --
7692       -- Map the local variables to each returned Column
7693       --
7694 if g_debug then
7695       hr_utility.set_location(l_proc, 160);
7696 end if;
7697       dbms_sql.define_column(l_sql_cursor, 1,l_oci_out,1);
7698       --
7699       -- Execute the SQL statement.
7700       --
7701 if g_debug then
7702       hr_utility.set_location(l_proc, 170);
7703 end if;
7704       l_rows_fetched := dbms_sql.execute(l_sql_cursor);
7705       --
7706       if (dbms_sql.fetch_rows(l_sql_cursor) > 0)
7707       then
7708          hr_utility.set_message(800,'HR_6048_PO_POS_DEL_POS_CONT');
7709          hr_utility.raise_error;
7710       end if;
7711       --
7712       -- Close cursor used for processing SQL statement.
7713       --
7714       dbms_sql.close_cursor(l_sql_cursor);
7715 if g_debug then
7716       hr_utility.set_location(l_proc, 180);
7717 end if;
7718       end;
7719 --    end if;
7720     --
7721     --  Ref Int check for OTA.
7722     --
7723     per_ota_predel_validation.ota_predel_pos_validation(p_position_id);
7724 if g_debug then
7725     hr_utility.set_location('Leaving : ' || l_proc, 300);
7726 end if;
7727     --
7728   end if;
7729 end pre_delete_checks;
7730 --
7731 -- ----------------------------------------------------------------------------
7732 -- |---------------------------< delete_validate >----------------------------|
7733 -- ----------------------------------------------------------------------------
7734 Procedure delete_validate
7735    (p_rec          in hr_psf_shd.g_rec_type,
7736     p_effective_date  in date,
7737     p_datetrack_mode  in varchar2,
7738     p_validation_start_date in date,
7739     p_validation_end_date   in date) is
7740 --
7741   l_proc varchar2(72) ;
7742 --
7743 Begin
7744 g_debug := hr_utility.debug_enabled;
7745 if g_debug then
7746  l_proc   := g_package||'delete_validate';
7747   hr_utility.set_location('Entering:'||l_proc, 5);
7748 end if;
7749   --
7750   -- Delete Validations
7751   pre_delete_checks(p_position_id        => p_rec.position_id
7752                    ,p_business_group_id  => p_rec.business_group_id
7753                    ,p_datetrack_mode     => p_datetrack_mode);
7754   --
7755   -- Call all supporting business operations
7756   --
7757   dt_delete_validate
7758     (p_datetrack_mode      => p_datetrack_mode,
7759      p_validation_start_date  => p_validation_start_date,
7760      p_validation_end_date => p_validation_end_date,
7761      p_position_id      => p_rec.position_id);
7762   --
7763   chk_availability_status_id
7764    (p_position_id            => p_rec.position_id
7765    ,p_validation_start_date  => p_validation_start_date
7766    ,p_availability_status_id => p_rec.availability_status_id
7767    ,p_old_avail_status_id    => hr_psf_shd.g_old_rec.availability_status_id
7768    ,p_effective_date         => p_effective_date
7769    ,p_date_effective         => p_rec.date_effective
7770    ,p_business_group_id      => p_rec.business_group_id
7771    ,p_object_version_number  => p_rec.object_version_number
7772    ,p_datetrack_mode         => p_datetrack_mode );
7773    --
7774    -- Bug 3199913 Start
7775    -- check added
7776    --
7777    chk_ref_int_del
7778     (p_position_id            => p_rec.position_id
7779     ,p_validation_start_date  => p_validation_start_date
7780     ,p_validation_end_date    => p_validation_end_date
7781     ,p_datetrack_mode         => p_datetrack_mode );
7782    -- Bug 3199913 End
7783 
7784 -- changes the date effective if only first active row is getting deleted and there is an
7785 -- active row after that in the position.
7786 -- Bug 12754983 starts
7787 /*   delete_date_effective(p_position_id           => p_rec.position_id
7788                         ,p_object_version_number => p_rec.object_version_number
7789                         ,p_business_group_id     => p_rec.business_group_id
7790                         ,p_datetrack_mode        => p_datetrack_mode ); */
7791 -- Bug 12754983 ends
7792 
7793 if g_debug then
7794   hr_utility.set_location(' Leaving:'||l_proc, 10);
7795 end if;
7796 End delete_validate;
7797 --
7798 -- -----------------------------------------------------------------------------
7799 -- |-------------------------------< chk_ddf >---------------------------------|
7800 -- -----------------------------------------------------------------------------
7801 --
7802 procedure chk_ddf
7803   (p_rec   in hr_psf_shd.g_rec_type) is
7804 --
7805   l_proc       varchar2(72) ;
7806   l_error      exception;
7807 --
7808 Begin
7809 g_debug := hr_utility.debug_enabled;
7810 if g_debug then
7811  l_proc        := g_package||'chk_ddf';
7812   hr_utility.set_location('Entering:'||l_proc, 5);
7813 end if;
7814   --
7815   -- Check if the row is being inserted or updated and a
7816   -- value has changed
7817   --
7818   if (p_rec.position_id is null)
7819     or ((p_rec.position_id is not null)
7820     and
7821     nvl(hr_psf_shd.g_old_rec.information_category, hr_api.g_varchar2) <>
7822     nvl(p_rec.information_category, hr_api.g_varchar2) or
7823     nvl(hr_psf_shd.g_old_rec.information1, hr_api.g_varchar2) <>
7824     nvl(p_rec.information1, hr_api.g_varchar2) or
7825     nvl(hr_psf_shd.g_old_rec.information2, hr_api.g_varchar2) <>
7826     nvl(p_rec.information2, hr_api.g_varchar2) or
7827     nvl(hr_psf_shd.g_old_rec.information3, hr_api.g_varchar2) <>
7828     nvl(p_rec.information3, hr_api.g_varchar2) or
7829     nvl(hr_psf_shd.g_old_rec.information4, hr_api.g_varchar2) <>
7830     nvl(p_rec.information4, hr_api.g_varchar2) or
7831     nvl(hr_psf_shd.g_old_rec.information5, hr_api.g_varchar2) <>
7832     nvl(p_rec.information5, hr_api.g_varchar2) or
7833     nvl(hr_psf_shd.g_old_rec.information6, hr_api.g_varchar2) <>
7834     nvl(p_rec.information6, hr_api.g_varchar2) or
7835     nvl(hr_psf_shd.g_old_rec.information7, hr_api.g_varchar2) <>
7836     nvl(p_rec.information7, hr_api.g_varchar2) or
7837     nvl(hr_psf_shd.g_old_rec.information8, hr_api.g_varchar2) <>
7838     nvl(p_rec.information8, hr_api.g_varchar2) or
7839     nvl(hr_psf_shd.g_old_rec.information9, hr_api.g_varchar2) <>
7840     nvl(p_rec.information9, hr_api.g_varchar2) or
7841     nvl(hr_psf_shd.g_old_rec.information10, hr_api.g_varchar2) <>
7842     nvl(p_rec.information10, hr_api.g_varchar2) or
7843     nvl(hr_psf_shd.g_old_rec.information11, hr_api.g_varchar2) <>
7844     nvl(p_rec.information11, hr_api.g_varchar2) or
7845     nvl(hr_psf_shd.g_old_rec.information12, hr_api.g_varchar2) <>
7846     nvl(p_rec.information12, hr_api.g_varchar2) or
7847     nvl(hr_psf_shd.g_old_rec.information13, hr_api.g_varchar2) <>
7848     nvl(p_rec.information13, hr_api.g_varchar2) or
7849     nvl(hr_psf_shd.g_old_rec.information14, hr_api.g_varchar2) <>
7850     nvl(p_rec.information14, hr_api.g_varchar2) or
7851     nvl(hr_psf_shd.g_old_rec.information15, hr_api.g_varchar2) <>
7852     nvl(p_rec.information15, hr_api.g_varchar2) or
7853     nvl(hr_psf_shd.g_old_rec.information16, hr_api.g_varchar2) <>
7854     nvl(p_rec.information16, hr_api.g_varchar2) or
7855     nvl(hr_psf_shd.g_old_rec.information17, hr_api.g_varchar2) <>
7856     nvl(p_rec.information17, hr_api.g_varchar2) or
7857     nvl(hr_psf_shd.g_old_rec.information18, hr_api.g_varchar2) <>
7858     nvl(p_rec.information18, hr_api.g_varchar2) or
7859     nvl(hr_psf_shd.g_old_rec.information19, hr_api.g_varchar2) <>
7860     nvl(p_rec.information19, hr_api.g_varchar2) or
7861     nvl(hr_psf_shd.g_old_rec.information20, hr_api.g_varchar2) <>
7862     nvl(p_rec.information20, hr_api.g_varchar2) or
7863     nvl(hr_psf_shd.g_old_rec.information21, hr_api.g_varchar2) <>
7864     nvl(p_rec.information21, hr_api.g_varchar2) or
7865     nvl(hr_psf_shd.g_old_rec.information22, hr_api.g_varchar2) <>
7866     nvl(p_rec.information22, hr_api.g_varchar2) or
7867     nvl(hr_psf_shd.g_old_rec.information23, hr_api.g_varchar2) <>
7868     nvl(p_rec.information23, hr_api.g_varchar2) or
7869     nvl(hr_psf_shd.g_old_rec.information24, hr_api.g_varchar2) <>
7870     nvl(p_rec.information24, hr_api.g_varchar2) or
7871     nvl(hr_psf_shd.g_old_rec.information25, hr_api.g_varchar2) <>
7872     nvl(p_rec.information25, hr_api.g_varchar2) or
7873     nvl(hr_psf_shd.g_old_rec.information26, hr_api.g_varchar2) <>
7874     nvl(p_rec.information26, hr_api.g_varchar2) or
7875     nvl(hr_psf_shd.g_old_rec.information27, hr_api.g_varchar2) <>
7876     nvl(p_rec.information27, hr_api.g_varchar2) or
7877     nvl(hr_psf_shd.g_old_rec.information28, hr_api.g_varchar2) <>
7878     nvl(p_rec.information28, hr_api.g_varchar2) or
7879     nvl(hr_psf_shd.g_old_rec.information29, hr_api.g_varchar2) <>
7880     nvl(p_rec.information29, hr_api.g_varchar2) or
7881     nvl(hr_psf_shd.g_old_rec.information30, hr_api.g_varchar2) <>
7882     nvl(p_rec.information30, hr_api.g_varchar2))
7883   then
7884     --
7885     hr_dflex_utility.ins_or_upd_descflex_attribs
7886       (p_appl_short_name    => 'PER'
7887       ,p_descflex_name      => 'DDF HR_ALL_POSITIONS_F'
7888       ,p_attribute_category => p_rec.information_category
7889       ,p_attribute1_name    => 'information1'
7890       ,p_attribute1_value   => p_rec.information1
7891       ,p_attribute2_name    => 'information2'
7892       ,p_attribute2_value   => p_rec.information2
7893       ,p_attribute3_name    => 'information3'
7894       ,p_attribute3_value   => p_rec.information3
7895       ,p_attribute4_name    => 'information4'
7896       ,p_attribute4_value   => p_rec.information4
7897       ,p_attribute5_name    => 'information5'
7898       ,p_attribute5_value   => p_rec.information5
7899       ,p_attribute6_name    => 'information6'
7900       ,p_attribute6_value   => p_rec.information6
7901       ,p_attribute7_name    => 'information7'
7902       ,p_attribute7_value   => p_rec.information7
7903       ,p_attribute8_name    => 'information8'
7904       ,p_attribute8_value   => p_rec.information8
7905       ,p_attribute9_name    => 'information9'
7906       ,p_attribute9_value   => p_rec.information9
7907       ,p_attribute10_name   => 'information10'
7908       ,p_attribute10_value  => p_rec.information10
7909       ,p_attribute11_name   => 'information11'
7910       ,p_attribute11_value  => p_rec.information11
7911       ,p_attribute12_name   => 'information12'
7912       ,p_attribute12_value  => p_rec.information12
7913       ,p_attribute13_name   => 'information13'
7914       ,p_attribute13_value  => p_rec.information13
7915       ,p_attribute14_name   => 'information14'
7916       ,p_attribute14_value  => p_rec.information14
7917       ,p_attribute15_name   => 'information15'
7918       ,p_attribute15_value  => p_rec.information15
7919       ,p_attribute16_name   => 'information16'
7920       ,p_attribute16_value  => p_rec.information16
7921       ,p_attribute17_name   => 'information17'
7922       ,p_attribute17_value  => p_rec.information17
7923       ,p_attribute18_name   => 'information18'
7924       ,p_attribute18_value  => p_rec.information18
7925       ,p_attribute19_name   => 'information19'
7926       ,p_attribute19_value  => p_rec.information19
7927       ,p_attribute20_name   => 'information20'
7928       ,p_attribute20_value  => p_rec.information20
7929       ,p_attribute21_name   => 'information21'
7930       ,p_attribute21_value  => p_rec.information21
7931       ,p_attribute22_name   => 'information22'
7932       ,p_attribute22_value  => p_rec.information22
7933       ,p_attribute23_name   => 'information23'
7934       ,p_attribute23_value  => p_rec.information23
7935       ,p_attribute24_name   => 'information24'
7936       ,p_attribute24_value  => p_rec.information24
7937       ,p_attribute25_name   => 'information25'
7938       ,p_attribute25_value  => p_rec.information25
7939       ,p_attribute26_name   => 'information26'
7940       ,p_attribute26_value  => p_rec.information26
7941       ,p_attribute27_name   => 'information27'
7942       ,p_attribute27_value  => p_rec.information27
7943       ,p_attribute28_name   => 'information28'
7944       ,p_attribute28_value  => p_rec.information28
7945       ,p_attribute29_name   => 'information29'
7946       ,p_attribute29_value  => p_rec.information29
7947       ,p_attribute30_name   => 'information30'
7948       ,p_attribute30_value  => p_rec.information30
7949       );
7950     --
7951   end if;
7952   --
7953 if g_debug then
7954   hr_utility.set_location(' Leaving:'||l_proc, 10);
7955 end if;
7956 end chk_ddf;
7957 --
7958 -- Location  :    hr_psf_bus package
7959 -- Called in :    insert_validate
7960 --       update_validate. [Must be the last validation. Can be a part of another
7961 --       procedure called from insert/update_validate]
7962 --
7963 
7964 --
7965 -- -----------------------------------------------------------------------
7966 -- |------------------------------< chk_df >-----------------------------|
7967 -- -----------------------------------------------------------------------
7968 --
7969 -- Description:
7970 --   Validates the all Descriptive Flexfield values.
7971 --
7972 -- Pre-conditions:
7973 --   All other columns have been validated. Must be called as the
7974 --   last step from insert_validate and update_validate.
7975 --
7976 -- In Arguments:
7977 --   p_rec
7978 --
7979 -- Post Success:
7980 --   If the Descriptive Flexfield structure column and data values are
7981 --   all valid this procedure will end normally and processing will
7982 --   continue.
7983 --
7984 -- Post Failure:
7985 --   If the Descriptive Flexfield structure column value or any of
7986 --   the data values are invalid then an application error is raised as
7987 --   a PL/SQL exception.
7988 --
7989 -- Access Status:
7990 --   Internal Row Handler Use Only.
7991 --
7992 procedure chk_df
7993   (p_rec in hr_psf_shd.g_rec_type) is
7994 --
7995   l_proc     varchar2(72);
7996 --
7997 begin
7998 g_debug := hr_utility.debug_enabled;
7999 if g_debug then
8000 l_proc      := g_package||'chk_df';
8001   hr_utility.set_location('Entering:'||l_proc, 10);
8002 end if;
8003   --
8004   if ((p_rec.position_id is not null) and (
8005     nvl(hr_psf_shd.g_old_rec.attribute_category, hr_api.g_varchar2) <>
8006     nvl(p_rec.attribute_category, hr_api.g_varchar2) or
8007     nvl(hr_psf_shd.g_old_rec.attribute1, hr_api.g_varchar2) <>
8008     nvl(p_rec.attribute1, hr_api.g_varchar2) or
8009     nvl(hr_psf_shd.g_old_rec.attribute2, hr_api.g_varchar2) <>
8010     nvl(p_rec.attribute2, hr_api.g_varchar2) or
8011     nvl(hr_psf_shd.g_old_rec.attribute3, hr_api.g_varchar2) <>
8012     nvl(p_rec.attribute3, hr_api.g_varchar2) or
8013     nvl(hr_psf_shd.g_old_rec.attribute4, hr_api.g_varchar2) <>
8014     nvl(p_rec.attribute4, hr_api.g_varchar2) or
8015     nvl(hr_psf_shd.g_old_rec.attribute5, hr_api.g_varchar2) <>
8016     nvl(p_rec.attribute5, hr_api.g_varchar2) or
8017     nvl(hr_psf_shd.g_old_rec.attribute6, hr_api.g_varchar2) <>
8018     nvl(p_rec.attribute6, hr_api.g_varchar2) or
8019     nvl(hr_psf_shd.g_old_rec.attribute7, hr_api.g_varchar2) <>
8020     nvl(p_rec.attribute7, hr_api.g_varchar2) or
8021     nvl(hr_psf_shd.g_old_rec.attribute8, hr_api.g_varchar2) <>
8022     nvl(p_rec.attribute8, hr_api.g_varchar2) or
8023     nvl(hr_psf_shd.g_old_rec.attribute9, hr_api.g_varchar2) <>
8024     nvl(p_rec.attribute9, hr_api.g_varchar2) or
8025     nvl(hr_psf_shd.g_old_rec.attribute10, hr_api.g_varchar2) <>
8026     nvl(p_rec.attribute10, hr_api.g_varchar2) or
8027     nvl(hr_psf_shd.g_old_rec.attribute11, hr_api.g_varchar2) <>
8028     nvl(p_rec.attribute11, hr_api.g_varchar2) or
8029     nvl(hr_psf_shd.g_old_rec.attribute12, hr_api.g_varchar2) <>
8030     nvl(p_rec.attribute12, hr_api.g_varchar2) or
8031     nvl(hr_psf_shd.g_old_rec.attribute13, hr_api.g_varchar2) <>
8032     nvl(p_rec.attribute13, hr_api.g_varchar2) or
8033     nvl(hr_psf_shd.g_old_rec.attribute14, hr_api.g_varchar2) <>
8034     nvl(p_rec.attribute14, hr_api.g_varchar2) or
8035     nvl(hr_psf_shd.g_old_rec.attribute15, hr_api.g_varchar2) <>
8036     nvl(p_rec.attribute15, hr_api.g_varchar2) or
8037     nvl(hr_psf_shd.g_old_rec.attribute16, hr_api.g_varchar2) <>
8038     nvl(p_rec.attribute16, hr_api.g_varchar2) or
8039     nvl(hr_psf_shd.g_old_rec.attribute17, hr_api.g_varchar2) <>
8040     nvl(p_rec.attribute17, hr_api.g_varchar2) or
8041     nvl(hr_psf_shd.g_old_rec.attribute18, hr_api.g_varchar2) <>
8042     nvl(p_rec.attribute18, hr_api.g_varchar2) or
8043     nvl(hr_psf_shd.g_old_rec.attribute19, hr_api.g_varchar2) <>
8044     nvl(p_rec.attribute19, hr_api.g_varchar2) or
8045     nvl(hr_psf_shd.g_old_rec.attribute20, hr_api.g_varchar2) <>
8046     nvl(p_rec.attribute20, hr_api.g_varchar2) or
8047     nvl(hr_psf_shd.g_old_rec.attribute21, hr_api.g_varchar2) <>
8048     nvl(p_rec.attribute21, hr_api.g_varchar2) or
8049     nvl(hr_psf_shd.g_old_rec.attribute22, hr_api.g_varchar2) <>
8050     nvl(p_rec.attribute22, hr_api.g_varchar2) or
8051     nvl(hr_psf_shd.g_old_rec.attribute23, hr_api.g_varchar2) <>
8052     nvl(p_rec.attribute23, hr_api.g_varchar2) or
8053     nvl(hr_psf_shd.g_old_rec.attribute24, hr_api.g_varchar2) <>
8054     nvl(p_rec.attribute24, hr_api.g_varchar2) or
8055     nvl(hr_psf_shd.g_old_rec.attribute25, hr_api.g_varchar2) <>
8056     nvl(p_rec.attribute25, hr_api.g_varchar2) or
8057     nvl(hr_psf_shd.g_old_rec.attribute26, hr_api.g_varchar2) <>
8058     nvl(p_rec.attribute26, hr_api.g_varchar2) or
8059     nvl(hr_psf_shd.g_old_rec.attribute27, hr_api.g_varchar2) <>
8060     nvl(p_rec.attribute27, hr_api.g_varchar2) or
8061     nvl(hr_psf_shd.g_old_rec.attribute28, hr_api.g_varchar2) <>
8062     nvl(p_rec.attribute28, hr_api.g_varchar2) or
8063     nvl(hr_psf_shd.g_old_rec.attribute29, hr_api.g_varchar2) <>
8064     nvl(p_rec.attribute29, hr_api.g_varchar2) or
8065     nvl(hr_psf_shd.g_old_rec.attribute30, hr_api.g_varchar2) <>
8066     nvl(p_rec.attribute30, hr_api.g_varchar2)))
8067     or (p_rec.position_id is null) then
8068    --
8069    -- Only execute the validation if absolutely necessary:
8070    -- a) During update, the structure column value or any
8071    --    of the attribute values have actually changed.
8072    -- b) During insert.
8073    --
8074    if nvl(fnd_profile.value('FLEXFIELDS:VALIDATE_ON_SERVER'),'N') = 'Y'
8075        then
8076    hr_dflex_utility.ins_or_upd_descflex_attribs
8077      (p_appl_short_name     => 'PER'
8078       ,p_descflex_name      => 'PER_POSITIONS'
8079       ,p_attribute_category => p_rec.attribute_category
8080       ,p_attribute1_name    => 'ATTRIBUTE1'
8081       ,p_attribute1_value   => p_rec.attribute1
8082       ,p_attribute2_name    => 'ATTRIBUTE2'
8083       ,p_attribute2_value   => p_rec.attribute2
8084       ,p_attribute3_name    => 'ATTRIBUTE3'
8085       ,p_attribute3_value   => p_rec.attribute3
8086       ,p_attribute4_name    => 'ATTRIBUTE4'
8087       ,p_attribute4_value   => p_rec.attribute4
8088       ,p_attribute5_name    => 'ATTRIBUTE5'
8089       ,p_attribute5_value   => p_rec.attribute5
8090       ,p_attribute6_name    => 'ATTRIBUTE6'
8091       ,p_attribute6_value   => p_rec.attribute6
8092       ,p_attribute7_name    => 'ATTRIBUTE7'
8093       ,p_attribute7_value   => p_rec.attribute7
8094       ,p_attribute8_name    => 'ATTRIBUTE8'
8095       ,p_attribute8_value   => p_rec.attribute8
8096       ,p_attribute9_name    => 'ATTRIBUTE9'
8097       ,p_attribute9_value   => p_rec.attribute9
8098       ,p_attribute10_name   => 'ATTRIBUTE10'
8099       ,p_attribute10_value  => p_rec.attribute10
8100       ,p_attribute11_name   => 'ATTRIBUTE11'
8101       ,p_attribute11_value  => p_rec.attribute11
8102       ,p_attribute12_name   => 'ATTRIBUTE12'
8103       ,p_attribute12_value  => p_rec.attribute12
8104       ,p_attribute13_name   => 'ATTRIBUTE13'
8105       ,p_attribute13_value  => p_rec.attribute13
8106       ,p_attribute14_name   => 'ATTRIBUTE14'
8107       ,p_attribute14_value  => p_rec.attribute14
8108       ,p_attribute15_name   => 'ATTRIBUTE15'
8109       ,p_attribute15_value  => p_rec.attribute15
8110       ,p_attribute16_name   => 'ATTRIBUTE16'
8111       ,p_attribute16_value  => p_rec.attribute16
8112       ,p_attribute17_name   => 'ATTRIBUTE17'
8113       ,p_attribute17_value  => p_rec.attribute17
8114       ,p_attribute18_name   => 'ATTRIBUTE18'
8115       ,p_attribute18_value  => p_rec.attribute18
8116       ,p_attribute19_name   => 'ATTRIBUTE19'
8117       ,p_attribute19_value  => p_rec.attribute19
8118       ,p_attribute20_name   => 'ATTRIBUTE20'
8119       ,p_attribute20_value  => p_rec.attribute20
8120       ,p_attribute21_name   => 'ATTRIBUTE21'
8121       ,p_attribute21_value  => p_rec.attribute21
8122       ,p_attribute22_name   => 'ATTRIBUTE22'
8123       ,p_attribute22_value  => p_rec.attribute22
8124       ,p_attribute23_name   => 'ATTRIBUTE23'
8125       ,p_attribute23_value  => p_rec.attribute23
8126       ,p_attribute24_name   => 'ATTRIBUTE24'
8127       ,p_attribute24_value  => p_rec.attribute24
8128       ,p_attribute25_name   => 'ATTRIBUTE25'
8129       ,p_attribute25_value  => p_rec.attribute25
8130       ,p_attribute26_name   => 'ATTRIBUTE26'
8131       ,p_attribute26_value  => p_rec.attribute26
8132       ,p_attribute27_name   => 'ATTRIBUTE27'
8133       ,p_attribute27_value  => p_rec.attribute27
8134       ,p_attribute28_name   => 'ATTRIBUTE28'
8135       ,p_attribute28_value  => p_rec.attribute28
8136       ,p_attribute29_name   => 'ATTRIBUTE29'
8137       ,p_attribute29_value  => p_rec.attribute29
8138       ,p_attribute30_name   => 'ATTRIBUTE30'
8139       ,p_attribute30_value  => p_rec.attribute30
8140       );
8141    end if;
8142   end if;
8143   --
8144 if g_debug then
8145   hr_utility.set_location(' Leaving:'||l_proc, 20);
8146 end if;
8147 
8148 end chk_df;
8149 --
8150 --
8151 --  ---------------------------------------------------------------------------
8152 --  |-------------------------< chk_ref_int_del >-----------------------------|
8153 --  ---------------------------------------------------------------------------
8154 --
8155 --  Description:
8156 --    Validates that a position cannot be purged if foreign key
8157 --    references exist to any of the following tables :
8158 --               - PER_ALL_ASSIGNMENTS_F
8159 --               - PAY_ELEMENT_LINKS_F
8160 --  Pre-conditions:
8161 --    None
8162 --
8163 --  In Arguments:
8164 --    p_position_id
8165 --    p_validation_start_date
8166 --    p_validation_end_date
8167 --    p_datetrack_mode
8168 --
8169 --  Post Success:
8170 --    If no rows exist in the tables listed above then processing continues.
8171 --
8172 --  Post Failure:
8173 --    If rows exist in any of the tables listed above, an application
8174 --    error is raised and processing is terminated.
8175 --
8176 --  Procedure added for bug 3199913
8177 procedure chk_ref_int_del
8178   (p_position_id           in varchar2
8179   ,p_validation_start_date in date
8180   ,p_validation_end_date   in date
8181   ,p_datetrack_mode        in varchar2
8182   )
8183   is
8184 --
8185    l_exists         varchar2(1);
8186    l_proc           varchar2(72)  :=  g_package||'chk_ref_int_del';
8187 --
8188    cursor csr_assgt is
8189      select   null
8190      from     sys.dual
8191      where exists(select   null
8192                   from     per_all_assignments_f
8193                   where    position_id = p_position_id
8194                   and      (p_datetrack_mode = 'ZAP'
8195                   or       (p_datetrack_mode = 'DELETE'
8196                   and       effective_start_date >= p_validation_start_date)));
8197 
8198    cursor csr_element_links is
8199      select null
8200      from sys.dual
8201      where exists(select   null
8202                   from     pay_element_links_f
8203                   where    position_id = p_position_id
8204                   and      (p_datetrack_mode = 'ZAP'
8205                   or       (p_datetrack_mode = 'DELETE'
8206                   and       effective_start_date >= p_validation_start_date)));
8207 
8208    cursor csr_budget_details is
8209      select   null
8210      from     sys.dual
8211      where exists(select   null
8212                   from     pqh_budget_details
8213                   where    position_id = p_position_id
8214                   and      p_datetrack_mode = 'ZAP');
8215 
8216 --
8217 begin
8218   hr_utility.set_location('Entering:'|| l_proc, 1);
8219   --
8220   -- Check that the position is not attached to any assignment
8221   --
8222   open csr_assgt;
8223   fetch csr_assgt into l_exists;
8224   if csr_assgt%found then
8225     close csr_assgt;
8226     hr_utility.set_message(801,'PER_7417_POS_ASSIGNMENT');
8227     hr_utility.raise_error;
8228   end if;
8229   close csr_assgt;
8230   --
8231   hr_utility.set_location(l_proc, 2);
8232   --
8233   -- Check that the position is not attached to any element link
8234   --
8235   open csr_element_links;
8236   fetch csr_element_links into l_exists;
8237   if csr_element_links%found then
8238     close csr_element_links;
8239     hr_utility.set_message(801,'PER_7863_DEL_POS_LINK');
8240     hr_utility.raise_error;
8241   end if;
8242   close csr_element_links;
8243   --
8244   hr_utility.set_location(l_proc, 3);
8245   --
8246   -- Check that the position is not attached to any Budget
8247   --
8248   open csr_budget_details;
8249   fetch csr_budget_details into l_exists;
8250   if csr_budget_details%found then
8251     close csr_budget_details;
8252     hr_utility.set_message(800,'PER_DEL_POSITION_BUDGET');
8253     hr_utility.raise_error;
8254   end if;
8255   close csr_budget_details;
8256   --
8257   --
8258   hr_utility.set_location(' Leaving:'|| l_proc, 11);
8259   --
8260 end chk_ref_int_del;
8261 
8262 --
8263 Function First_active_position_row(
8264   p_position_id          in  number,
8265   p_effective_start_date in  date) return boolean is
8266     --
8267     cursor c1 is
8268       select min(psf.effective_start_date)
8269       from
8270          hr_all_positions_f psf
8271       where psf.position_id = p_position_id
8272         and hr_psf_shd.get_availability_status(psf.availability_status_id
8273                                                ,psf.business_group_id) =  'ACTIVE';
8274 
8275     --
8276     l_minesd        date;
8277     l_proc          varchar2(30);
8278     --
8279 Begin
8280   --
8281 g_debug := hr_utility.debug_enabled;
8282 if g_debug then
8283    l_proc           :='First_active_position_row';
8284   hr_utility.set_location( 'Entering : ' || l_proc, 10);
8285 end if;
8286   open c1;
8287   fetch c1 into l_minesd;
8288   close c1;
8289   --
8290 if g_debug then
8291   hr_utility.set_location( l_proc, 20);
8292 end if;
8293   --
8294   if l_minesd is null or l_minesd = p_effective_start_date then
8295     --
8296 if g_debug then
8297     hr_utility.set_location( l_proc, 30);
8298 end if;
8299     --
8300     return (true);
8301     --
8302   else
8303     --
8304 if g_debug then
8305     hr_utility.set_location( l_proc, 40);
8306 end if;
8307     --
8308     return (false);
8309     --
8310   end if;
8311 if g_debug then
8312   hr_utility.set_location('Leaving : ' || l_proc, 100);
8313 end if;
8314   --
8315 End First_active_position_row;
8316 --
8317 Function First_proposed_only_position(
8318    p_position_id           number,
8319    p_effective_start_date  date) return boolean is
8320 
8321   --
8322   l_rows_not_proposed  number(15);
8323   l_esd              date;
8324   l_proc             varchar2(30)  ;
8325   --
8326   cursor c1 is
8327     select count(*)
8328     from
8329        hr_all_positions_f psf
8330     where psf.position_id = p_position_id
8331         and hr_psf_shd.get_availability_status(psf.availability_status_id
8332                                                ,psf.business_group_id) <>  'PROPOSED';
8333   --
8334   cursor c2 is
8335    select min(psf.effective_Start_Date)
8336    from
8337      hr_all_positions_f psf
8338    where psf.position_id = p_position_id;
8339   --
8340 Begin
8341   --
8342 if g_debug then
8343   l_proc              :='First_proposed_only_position';
8344   hr_utility.set_location('Entering : ' || l_proc, 10);
8345 end if;
8346   open c1;
8347   fetch c1 into l_rows_not_proposed;
8348   if l_rows_not_proposed = 0 then
8349     --
8350 if g_debug then
8351     hr_utility.set_location(l_proc, 20);
8352 end if;
8353     open c2;
8354     fetch c2 into l_esd;
8355     close c2;
8356     if l_esd is null or l_esd = p_effective_Start_date then
8357 if g_debug then
8358       hr_utility.set_location(l_proc, 30);
8359 end if;
8360       return(true);
8361     end if;
8362     --
8363 if g_debug then
8364     hr_utility.set_location(l_proc, 40);
8365 end if;
8366     --
8367   end if;
8368   --
8369 if g_debug then
8370   hr_utility.set_location( 'Leaving : ' || l_proc, 100);
8371 end if;
8372   return(false);
8373   --
8374 End First_proposed_only_position;
8375 --
8376 
8377 Function all_proposed_only_position(
8378    p_position_id           number )
8379  return boolean is
8380 
8381   --
8382   l_rows_not_proposed  number(15);
8383   l_esd              date;
8384   l_proc             varchar2(30)  ;
8385   --
8386   cursor c1 is
8387     select count(*)
8388     from
8389        hr_all_positions_f psf
8390     where psf.position_id = p_position_id
8391         and hr_psf_shd.get_availability_status(psf.availability_status_id
8392                                                ,psf.business_group_id) <>  'PROPOSED';
8393   --
8394 Begin
8395   --
8396 g_debug := hr_utility.debug_enabled;
8397 if g_debug then
8398   l_proc              :='all_proposed_only_position';
8399   hr_utility.set_location('Entering : ' || l_proc, 10);
8400 end if;
8401   open c1;
8402   fetch c1 into l_rows_not_proposed;
8403   if l_rows_not_proposed = 0 then
8404       return(true);
8405   end if;
8406   --
8407 if g_debug then
8408   hr_utility.set_location( 'Leaving : ' || l_proc, 100);
8409 end if;
8410   return(false);
8411   --
8412 End all_proposed_only_position;
8413 --
8414 Function Lower_limit(
8415    p_position_id           in number,
8416    p_effective_start_date  in date) return date is
8417   --
8418   l_esd      date;
8419   l_proc     varchar2(30)  ;
8420   --
8421   cursor c1 is
8422   select
8423      min(psf.effective_start_date)
8424   from
8425      hr_all_positions_f psf
8426   where psf.position_id = p_position_id;
8427   --
8428   cursor c2 is
8429   select max(effective_start_date)
8430   from hr_all_positions_f psf
8431   where psf.position_id = p_position_id
8432     and psf.effective_start_date < p_effective_start_date;
8433   --
8434   l_proposed_only boolean ;
8435   l_sot date ;
8436 Begin
8437   --
8438 if g_debug then
8439   l_proc      :='Lower_limit';
8440   hr_utility.set_location( 'Entering : ' || l_proc, 10);
8441 end if;
8442   l_sot := to_date('01/01/0001','mm/dd/yyyy');
8443   l_proposed_only := hr_psf_bus.all_proposed_only_position(p_position_id);
8444   if l_proposed_only = true then
8445      return(l_sot);
8446   end if;
8447   open c1;
8448   fetch c1 into l_esd;
8449   close c1;
8450   --
8451 if g_debug then
8452   hr_utility.set_location(l_proc, 20);
8453 end if;
8454   --
8455   if l_esd is null or l_esd = p_effective_start_date then
8456 if g_debug then
8457       hr_utility.set_location( 'Leaving : ' || l_proc, 30);
8458 end if;
8459      return(l_sot);
8460   else
8461     --
8462 if g_debug then
8463     hr_utility.set_location(l_proc, 40);
8464 end if;
8465     --
8466     open c2;
8467     fetch c2 into l_esd;
8468     close c2;
8469     --
8470 if g_debug then
8471     hr_utility.set_location( 'Leaving : ' || l_proc, 50);
8472 end if;
8473     --
8474     return(l_esd + 1);
8475     --
8476   end if;
8477   --
8478 End Lower_limit;
8479 --
8480 Function Upper_limit(
8481    p_position_id          in number,
8482    p_effective_Start_date in date) return date is
8483   --
8484   l_esd          date;
8485   l_tmp_esd      date;
8486   l_ret_date     date;
8487   l_eot          date;
8488   l_proc         varchar2(30)  ;
8489   --
8490   cursor c1 is
8491   select max(psf.effective_start_date)
8492     from hr_all_positions_f psf
8493     where psf.position_id = p_position_id;
8494   --
8495   cursor c2 is
8496   select min(effective_start_date)
8497     from per_all_assignments_f paf
8498     where paf.position_id = p_position_id;
8499   --
8500   cursor c3 is
8501   select min(effective_start_date)
8502     from hr_all_positions_f psf
8503     where psf.position_id = p_position_id
8504       and psf.effective_start_date > p_effective_start_date;
8505   --
8506   l_proposed_only boolean;
8507 Begin
8508   --
8509 if g_debug then
8510  l_proc          :='Upper_Limit';
8511   hr_utility.set_location( 'Entering : ' || l_proc, 10);
8512 end if;
8513   l_eot  := to_date('12/31/4712', 'mm/dd/yyyy');
8514   --
8515 if g_debug then
8516   hr_utility.set_location(l_proc, 20);
8517 end if;
8518   l_proposed_only := hr_psf_bus.all_proposed_only_position(p_position_id);
8519   if l_proposed_only = true then
8520      return(l_eot);
8521   else
8522      --
8523      open c1;
8524      fetch c1 into l_esd;
8525      close c1;
8526      --
8527 if g_debug then
8528      hr_utility.set_location(l_proc, 30);
8529 end if;
8530      --
8531      if l_esd is null or l_esd = p_effective_start_date then
8532 if g_debug then
8533         hr_utility.set_location(l_proc, 40);
8534 end if;
8535         --
8536         l_ret_date := l_eot;
8537      elsE
8538         --
8539         l_ret_date := l_esd -1;
8540      end if;
8541      --
8542 if g_debug then
8543      hr_utility.set_location(l_proc, 50);
8544 end if;
8545      --
8546      open c2;
8547      fetch c2 into l_tmp_esd;
8548      close c2;
8549      --
8550 if g_debug then
8551      hr_utility.set_location(l_proc, 60);
8552 end if;
8553      --
8554      if nvl(l_tmp_esd, l_eot) < nvl(l_ret_date, l_eot) then
8555 if g_debug then
8556         hr_utility.set_location(l_proc, 70);
8557 end if;
8558         --
8559         l_ret_date := l_tmp_esd;
8560      end if;
8561      --
8562 if g_debug then
8563      hr_utility.set_location(l_proc, 80);
8564 end if;
8565      --
8566      open c3;
8567      fetch c3 into l_tmp_esd;
8568      close c3;
8569      --
8570 if g_debug then
8571      hr_utility.set_location(l_proc, 90);
8572 end if;
8573      --
8574      if nvl(l_tmp_esd, l_eot) < nvl(l_esd, l_eot) then
8575 if g_debug then
8576        hr_utility.set_location(l_proc, 100);
8577 end if;
8578        --
8579        l_ret_date := l_tmp_esd - 1;
8580      end if;
8581      --
8582 if g_debug then
8583      hr_utility.set_location( 'Leaving : ' || l_proc, 200);
8584 end if;
8585      return(nvl(l_ret_date, l_eot));
8586      --
8587   end if;
8588 END Upper_limit;
8589 --
8590 --
8591 -- Procedure : DE_Update_properties
8592 -- Description : Determines in Date_Effective is updateable and
8593 --               the valid range
8594 --
8595 Procedure DE_Update_properties(
8596   p_position_id           in number,
8597   p_effective_Start_Date  in date,
8598   p_updateable           out nocopy boolean,
8599   p_lower_limit          out nocopy date,
8600   p_upper_limit          out nocopy date) is
8601 
8602   --
8603   l_updateable     Boolean:=false;
8604   --
8605 Begin
8606   --
8607   l_updateable :=  first_active_position_row (p_position_id, p_effective_start_date);
8608   if not l_updateable then
8609     l_updateable :=  hr_psf_bus.all_proposed_only_position(p_position_id);
8610   end if;
8611   --
8612   p_updateable := l_updateable;
8613   --
8614   if l_updateable then
8615      p_lower_limit := lower_limit(p_position_id, p_effective_start_Date);
8616      p_upper_limit := upper_limit(p_position_id, p_effective_start_Date);
8617   end if;
8618 end DE_update_properties;
8619 --
8620 --
8621 -- ----------------------------------------------------------------------------
8622 -- |------< chk_permanent_seasonal_flag >------|
8623 -- ----------------------------------------------------------------------------
8624 --
8625 -- Description
8626 --   This procedure is used to check whether both permanent and seasonal flags
8627 --   are enabled.
8628 --
8629 Procedure chk_permanent_seasonal_flag
8630   (p_position_id               in number
8631   ,p_permanent_temporary_flag   in varchar2
8632   ,p_seasonal_flag             in varchar2
8633   ,p_effective_date            in date
8634   ,p_object_version_number     in number) is
8635   --
8636   l_proc         varchar2(72) ;
8637   l_api_updating boolean;
8638   --
8639 Begin
8640   --
8641 if g_debug then
8642   l_proc          := g_package||'chk_permanent_seasonal_flag';
8643   hr_utility.set_location('Entering:'||l_proc, 5);
8644 end if;
8645   --
8646   l_api_updating := hr_psf_shd.api_updating
8647     (p_position_id            => p_position_id
8648     ,p_effective_date         => p_effective_date
8649     ,p_object_version_number  => p_object_version_number);
8650   --
8651   if ((l_api_updating and
8652       (p_permanent_temporary_flag <> nvl(hr_psf_shd.g_old_rec.permanent_temporary_flag,hr_api.g_varchar2)
8653       or p_seasonal_flag <> nvl(hr_psf_shd.g_old_rec.seasonal_flag,hr_api.g_varchar2)))
8654       or not l_api_updating) then
8655       if (p_permanent_temporary_flag is not null and p_seasonal_flag is not null) then
8656       	if(p_seasonal_flag = 'Y' and p_permanent_temporary_flag = 'Y') then
8657   	  -- raise error as both flags are set to Y.
8658 	  --
8659           hr_utility.set_message(8302,'PQH_INV_PRMNT_SEASONAL_FLAG');
8660           hr_utility.raise_error;
8661         end if;
8662       end if;
8663   end if;
8664   --
8665 if g_debug then
8666   hr_utility.set_location('Leaving:'||l_proc,10);
8667 end if;
8668   --
8669 end chk_permanent_seasonal_flag;
8670 --
8671 
8672 end hr_psf_bus;