DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_PD_COPY_TO_BEN_FIVE

Source


1 Package BODY BEN_PD_COPY_TO_BEN_five as
2 /* $Header: bepdccp5.pkb 120.9 2006/04/10 05:42:54 gsehgal noship $ */
3 --
4 -- {Start Of Comments}
5 --
6 -- {End Of Comments}
7 --
8   /*
9    function get_fk(p_col_name varchar2, p_old_val number) return number is
10      l_counter number;
11      l_ret_id  number := null;
12    begin
13      --
14      l_counter := nvl(ben_pd_copy_to_ben_one.g_pk_tbl.LAST, 0);
15      if l_counter > 0  and p_old_val is not null then
16         for i in 1..l_counter loop
17             if ben_pd_copy_to_ben_one.g_pk_tbl(i).pk_id_column = p_col_name and
18                ben_pd_copy_to_ben_one.g_pk_tbl(i).old_value    = p_old_val
19             then
20                l_ret_id := ben_pd_copy_to_ben_one.g_pk_tbl(i).new_value;
21                exit;
22             end if;
23         end loop;
24      end if;
25      --
26      return l_ret_id;
27      --
28    end;
29    */
30 
31 function get_fk(p_col_name varchar2, p_old_val number,p_dml_operation varchar2 default null) return number is
32   l_counter number;
33   l_ret_id  number := null;
34 begin
35   --
36   /*
37   if p_dml_operation = 'UPDATE' then
38     --
39     l_ret_id := p_old_val ;
40     --
41   else
42   */
43     --
44     l_counter := nvl(ben_pd_copy_to_ben_one.g_pk_tbl.LAST, 0);
45     if l_counter > 0  and p_old_val is not null then
46        for i in 1..l_counter loop
47            if ben_pd_copy_to_ben_one.g_pk_tbl(i).pk_id_column = p_col_name and
48               ben_pd_copy_to_ben_one.g_pk_tbl(i).old_value    = p_old_val
49            then
50               l_ret_id := ben_pd_copy_to_ben_one.g_pk_tbl(i).new_value;
51               exit;
52            end if;
53        end loop;
54        --
55     end if;
56     --
57   /*
58   end if;
59   */
60   return l_ret_id;
61   --
62 end;
63 
64    --
65    --
66 --UPD Changes New procedure for getting the dtmodes
67 --
68 procedure get_dt_modes(p_effective_date       in date,
69                        p_effective_end_date   in date,
70                        p_effective_start_date in date,
71                        p_dml_operation        in varchar2,
72                        p_datetrack_mode       in out nocopy varchar2
73           --             p_update                  out nocopy boolean
74                       ) is
75   l_update            boolean := true ;
76   l_datetrack_mode    varchar2(80) := p_datetrack_mode ;
77 begin
78   --
79   hr_utility.set_location('Intering get_dt_modes p_dt_mode '||l_datetrack_mode,10);
80   hr_utility.set_location('p_effective_start_date '||p_effective_start_date,10);
81   hr_utility.set_location('p_effective_end_date '||p_effective_end_date,10);
82   hr_utility.set_location('p_effective_date '||p_effective_date,10);
83   --
84   if p_effective_end_date <> hr_api.g_eot then
85     --
86     if p_dml_operation = 'INSERT' then
87       --
88       l_datetrack_mode := hr_api.g_update;
89       l_update  := true;
90       --
91     elsif l_datetrack_mode in ('CORRECTION') then
92       --
93       l_datetrack_mode := hr_api.g_correction ;
94       l_update := true;
95       --
96     elsif l_datetrack_mode in ('UPDATE_OVERRIDE','UPDATE' ) then
97       --
98       if p_effective_date = p_effective_start_date then
99         l_datetrack_mode := hr_api.g_correction ;
100         l_update := true;
101       else
102         --
103         if l_datetrack_mode in ('UPDATE_OVERRIDE') then
104          --
105          l_datetrack_mode := hr_api.g_update_override ;
106          l_update := false ;
107          --
108         elsif l_datetrack_mode in ('UPDATE') then
109          --
110          l_datetrack_mode := hr_api.g_update;
111          --
112         end if;
113         --
114       end if;
115       --
116     elsif l_datetrack_mode in ('UPDATE_CHANGE_INSERT') then
117       --
118       if p_effective_date = p_effective_start_date then
119         l_datetrack_mode := hr_api.g_correction ;
120         l_update := true;
121       else
122         l_datetrack_mode := hr_api.g_update_change_insert ;
123         l_update := true;
124       end if;
125       --
126     else
127       --
128       l_datetrack_mode := hr_api.g_update;
129       l_update  := false;
130       --
131     end if;
132     --
133   else
134     --
135     if p_dml_operation = 'INSERT' then
136       --
137       l_datetrack_mode := hr_api.g_update;
138       l_update  := false;
139       --
140     elsif l_datetrack_mode in ('CORRECTION') then
141       --
142       l_datetrack_mode := hr_api.g_correction ;
143       l_update := false;
144       --
145     elsif l_datetrack_mode in ('UPDATE_OVERRIDE','UPDATE' ) then
146       --
147       if p_effective_date = p_effective_start_date then
148         l_datetrack_mode := hr_api.g_correction ;
149         l_update := true;
150       else
151         l_datetrack_mode := hr_api.g_update ;
152         l_update := false ;
153       end if;
154       --
155     elsif l_datetrack_mode in ('UPDATE_CHANGE_INSERT') then
156       --
157       if p_effective_date = p_effective_start_date then
158         l_datetrack_mode := hr_api.g_correction ;
159         l_update := false;
160       else
161         l_datetrack_mode := hr_api.g_update ;
162         l_update := false;
163       end if;
164       --
165     else
166       --
167       l_datetrack_mode := hr_api.g_update;
168       l_update  := false;
169       --
170     end if;
171     --
172   end if ;
173   --
174   p_datetrack_mode := l_datetrack_mode ;
175  --  p_update  := l_update ;
176   --
177   hr_utility.set_location('Leaving get_dt_modes p_dt_mode '||p_datetrack_mode,10);
178   --
179 end get_dt_modes ;
180 --
181    procedure get_elm_inpt_ids(p_elm_old_name       in     varchar2
182                               ,p_elm_new_id        out nocopy    number
183                               ,p_business_group_id in     number
184                               ,p_effective_date    in     date
185                               ,p_inpt_old_name     in     varchar2
186                               ,p_inpt_new_id       out nocopy    number  ) is
187      --
188      cursor c_element_values(p_elm_old_name varchar2) is
189        select pet.element_type_id
190        from pay_element_types_f pet
191        where pet.element_name = p_elm_old_name
192          and pet.business_group_id is null
193          and  p_effective_date between  Effective_Start_Date and Effective_End_Date;
194      --
195      cursor c_input_values(p_inpt_old_name varchar2, p_elm_new_id number) is
196        select input_value_id
197          from pay_input_values_f
198         where name = p_inpt_old_name
199           and element_type_id = p_elm_new_id
200           and business_group_id is null
201           and p_effective_date  between  Effective_Start_Date and Effective_End_Date;
202      --
203 
204    begin
205 
206    open c_element_values(p_elm_old_name);
207    fetch c_element_values into p_elm_new_id;
208    close c_element_values;
209    --
210    open c_input_values(p_inpt_old_name, p_elm_new_id);
211    fetch c_input_values into p_inpt_new_id;
212    close c_input_values;
213    --
214 
215 hr_utility.set_location('get_elm_inpt_ids ' ||p_elm_new_id,100);
216 hr_utility.set_location('get_elm_inpt_ids ' ||p_inpt_new_id,100);
217 
218    end get_elm_inpt_ids;
219    --
220    -- Private procedure to update the cer with target details
221    --
222    procedure update_cer_with_target(c_pk_rec BEN_PD_COPY_TO_BEN_one.G_PK_REC_TYPE, p_copy_entity_txn_id in number) is
223    begin
224      hr_utility.set_location('Inside update_cer_with_target ',233);
225          update ben_copy_entity_results
226            set information9     = c_pk_rec.copy_reuse_type||'-'||c_pk_rec.new_value
227            where copy_entity_txn_id = p_copy_entity_txn_id
228            and   table_route_id     = c_pk_rec.table_route_id
229            and   information1       = c_pk_rec.old_value ;
230    end update_cer_with_target ;
231 
232    --
233    --
234    ---------------------------------------------------------------
235    ----------------------< create_CTU_rows >-----------------------
236    ---------------------------------------------------------------
237    --
238    procedure create_CTU_rows
239    (
240          p_validate                       in  number     default 0
241         ,p_copy_entity_txn_id             in  number
242         ,p_effective_date                 in  date
243         ,p_prefix_suffix_text             in  varchar2  default null
244         ,p_reuse_object_flag              in  varchar2  default null
245         ,p_target_business_group_id       in  varchar2  default null
246         ,p_prefix_suffix_cd               in  varchar2  default null
247    ) is
248    --
249    l_ACTN_TYP_ID  number;
250    l_CM_TYP_ID  number;
251    l_CM_USG_RL  number;
252    l_ENRT_PERD_ID  number;
253    l_LER_ID  number;
254    l_PGM_ID  number;
255    l_PL_ID  number;
256    l_PL_TYP_ID  number;
257    cursor c_unique_CTU(l_table_alias varchar2) is
258    select distinct cpe.information1,
259      cpe.information2,
260      cpe.information3,
261      cpe.table_route_id,
262      -- UPD START
263      cpe.dml_operation,
264      cpe.datetrack_mode
265      -- UPD END
266    from ben_copy_entity_results cpe,
267         pqh_table_route tr
268    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
269    and   cpe.table_route_id     = tr.table_route_id
270    -- and   tr.where_clause        = l_BEN_CM_TYP_USG_F
271    and   tr.table_alias = l_table_alias
272    and   cpe.number_of_copies   = 1 -- ADDITION
273    -- UPD START
274    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
275    order by information1, information2; --added for bug: 5151945
276    --UPD END
277    --
278    --
279    cursor c_CTU_min_max_dates(c_table_route_id  number,
280                 c_information1   number) is
281    select
282      min(cpe.information2) min_esd,
283      max(cpe.information3) min_eed
284    from ben_copy_entity_results cpe
285    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
286    and   cpe.table_route_id     = c_table_route_id
287    and   cpe.information1       = c_information1 ;
288    --
289    cursor c_CTU(c_table_route_id  number,
290                 c_information1   number,
291                 c_information2   date,
292                 c_information3   date)  is
293    select
294      cpe.*
295    from ben_copy_entity_results cpe
296    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
297    and   cpe.table_route_id     = c_table_route_id
298    and   cpe.information1       = c_information1
299    and   cpe.information2       = c_information2
300    and   cpe.information3       = c_information3
301    and rownum = 1 ;
302    -- Date Track target record
303    cursor c_find_CTU_in_target(
304                                 c_effective_start_date    date,
305                                 c_effective_end_date      date,
306                                 c_business_group_id       number,
307                                 c_new_pk_id               number) is
308    select
309      CTU.cm_typ_usg_id new_value
310    from BEN_CM_TYP_USG_F CTU
311    where
312    nvl(CTU.ACTN_TYP_ID,-999)     = nvl(l_ACTN_TYP_ID,-999)  and
313    nvl(CTU.CM_TYP_ID,-999)     = nvl(l_CM_TYP_ID,-999)  and
314    nvl(CTU.ENRT_PERD_ID,-999)     = nvl(l_ENRT_PERD_ID,-999)  and
315    nvl(CTU.LER_ID,-999)     = nvl(l_LER_ID,-999)  and
316    nvl(CTU.PGM_ID,-999)     = nvl(l_PGM_ID,-999)  and
317    nvl(CTU.PL_ID,-999)     = nvl(l_PL_ID,-999)  and
318    nvl(CTU.PL_TYP_ID,-999)     = nvl(l_PL_TYP_ID,-999)  and
319    CTU.business_group_id  = c_business_group_id
320    and   CTU.cm_typ_usg_id  <> c_new_pk_id
321 --TEMPIK
322    and c_effective_start_date between effective_start_date
323                             and effective_end_date ;
324 --END TEMPIK
325 --TEMPIK
326 /*   and exists ( select null
327                 from BEN_CM_TYP_USG_F CTU1
328                 where
329                 nvl(CTU1.ACTN_TYP_ID,-999)     = nvl(l_ACTN_TYP_ID,-999)  and
330                 nvl(CTU1.CM_TYP_ID,-999)     = nvl(l_CM_TYP_ID,-999)  and
331                 nvl(CTU1.ENRT_PERD_ID,-999)     = nvl(l_ENRT_PERD_ID,-999)  and
332                 nvl(CTU1.LER_ID,-999)     = nvl(l_LER_ID,-999)  and
333                 nvl(CTU1.PGM_ID,-999)     = nvl(l_PGM_ID,-999)  and
334                 nvl(CTU1.PL_ID,-999)     = nvl(l_PL_ID,-999)  and
335                 nvl(CTU1.PL_TYP_ID,-999)     = nvl(l_PL_TYP_ID,-999)  and
336                 CTU1.business_group_id  = c_business_group_id
337                 and   CTU1.effective_start_date <= c_effective_start_date )
338    and exists ( select null
339                 from BEN_CM_TYP_USG_F CTU2
340                 where
341                 nvl(CTU2.ACTN_TYP_ID,-999)     = nvl(l_ACTN_TYP_ID,-999)  and
342                 nvl(CTU2.CM_TYP_ID,-999)     = nvl(l_CM_TYP_ID,-999)  and
343                 nvl(CTU2.ENRT_PERD_ID,-999)     = nvl(l_ENRT_PERD_ID,-999)  and
344                 nvl(CTU2.LER_ID,-999)     = nvl(l_LER_ID,-999)  and
345                 nvl(CTU2.PGM_ID,-999)     = nvl(l_PGM_ID,-999)  and
346                 nvl(CTU2.PL_ID,-999)     = nvl(l_PL_ID,-999)  and
347                 nvl(CTU2.PL_TYP_ID,-999)     = nvl(l_PL_TYP_ID,-999)  and
348                 CTU2.business_group_id  = c_business_group_id
349                 and   CTU2.effective_end_date >= c_effective_end_date )
350                 ;
351 */
352 --END TEMPIK
353    --
354    --TEMPIK
355    l_dt_rec_found            boolean ;
356    --END TEMPIK
357 
358    --UPD START
359    --
360    l_update                  boolean      := false ;
361    l_datetrack_mode          varchar2(80) := hr_api.g_update;
362    l_process_date            date;
363    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
364    --
365    --UPD END
366 
367    l_current_pk_id           number := null ;
368    l_prev_pk_id              number := null ;
369    l_first_rec               boolean := true ;
370    r_CTU                     c_CTU%rowtype;
371    l_cm_typ_usg_id             number ;
372    l_object_version_number   number ;
373    l_effective_start_date    date ;
374    l_effective_end_date      date ;
375    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
376    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
377    l_new_value               number(15);
378    l_object_found_in_target  boolean := false ;
379    l_min_esd                 date;
380    l_max_eed                 date;
381    l_effective_date          date;
382    --
383  begin
384    -- Initialization
385    l_object_found_in_target := false ;
386    -- End Initialization
387    -- Derive the prefix - sufix
388    if   p_prefix_suffix_cd = 'PREFIX' then
389      l_prefix  := p_prefix_suffix_text ;
390    elsif p_prefix_suffix_cd = 'SUFFIX' then
391      l_suffix   := p_prefix_suffix_text ;
392    else
393      l_prefix := null ;
394      l_suffix  := null ;
395    end if ;
396    -- End Prefix Sufix derivation
397    for r_CTU_unique in c_unique_CTU('CTU') loop
398 
399      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
400           (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
401            r_CTU_unique.information3 >=
402                    ben_pd_copy_to_ben_one.g_copy_effective_date)
403           ) then
404        --
405        hr_utility.set_location(' r_CTU_unique.table_route_id '||r_CTU_unique.table_route_id,10);
406        hr_utility.set_location(' r_CTU_unique.information1 '||r_CTU_unique.information1,10);
407        hr_utility.set_location( 'r_CTU_unique.information2 '||r_CTU_unique.information2,10);
408        hr_utility.set_location( 'r_CTU_unique.information3 '||r_CTU_unique.information3,10);
409        -- If reuse objects flag is 'Y' then check for the object in the target business group
410        -- if found insert the record into PLSql table and exit the loop else try create the
411        -- object in the target business group
412        --
413        l_object_found_in_target := false ;
414 
415        -- UPD START
416        --
417        open c_CTU(r_CTU_unique.table_route_id,
418                 r_CTU_unique.information1,
419                 r_CTU_unique.information2,
420                 r_CTU_unique.information3 ) ;
421        --
422        fetch c_CTU into r_CTU ;
423        --
424        close c_CTU ;
425 
426        -- UPD END
427        l_dml_operation:= r_CTU_unique.dml_operation ;
428        l_ACTN_TYP_ID := get_fk('ACTN_TYP_ID', r_CTU.information221,r_CTU.dml_operation);
429        l_CM_TYP_ID := get_fk('CM_TYP_ID', r_CTU.information237,r_CTU.dml_operation);
430        l_CM_USG_RL := get_fk('FORMULA_ID', r_CTU.information258,r_CTU.dml_operation);
431        l_ENRT_PERD_ID := get_fk('ENRT_PERD_ID', r_CTU.information244,r_CTU.dml_operation);
432        l_LER_ID := get_fk('LER_ID', r_CTU.information257,r_CTU.dml_operation);
433        l_PGM_ID := get_fk('PGM_ID', r_CTU.information260,r_CTU.dml_operation);
434        l_PL_ID := get_fk('PL_ID', r_CTU.information261,r_CTU.dml_operation);
435        l_PL_TYP_ID := get_fk('PL_TYP_ID', r_CTU.information248,r_CTU.dml_operation);
436        --UPD START
437        l_update := false;
438        l_process_date := p_effective_date;
439        --
440        if l_dml_operation = 'UPDATE' then
441          --
442          l_object_found_in_target := TRUE;
443          --
444          if l_process_date between r_CTU_unique.information2 and r_CTU_unique.information3 then
445                l_update := true;
446                if r_CTU_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
447                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'CM_TYP_USG_ID'
448                then
449                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'CM_TYP_USG_ID' ;
450                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_CTU_unique.information1 ;
451                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_CTU_unique.information1 ;
452                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
453                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_CTU_unique.table_route_id;
454                   --
455                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
456                   --
457                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
458                   -- DOUBT WHERE  IS NAME ?
459                   -- log_data('CTU',l_new_value,l_prefix || r_CTU_unique.name|| l_suffix,'REUSED');
460                   --
461                end if ;
462                hr_utility.set_location( 'found record for update',10);
463            --
464          else
465            --
466            l_update := false;
467            --
468          end if;
469       else
470       --
471               --UPD END
472 
473 
474                l_min_esd := null ;
475                l_max_eed := null ;
476                open c_CTU_min_max_dates(r_CTU_unique.table_route_id, r_CTU_unique.information1 ) ;
477                fetch c_CTU_min_max_dates into l_min_esd,l_max_eed ;
478                --
479 
480                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
481                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
482                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
483                end if;
484                l_min_esd := greatest(l_min_esd,r_CTU_unique.information2);
485 
486                /*open c_CTU(r_CTU_unique.table_route_id,
487                         r_CTU_unique.information1,
488                         r_CTU_unique.information2,
489                         r_CTU_unique.information3 ) ;
490                --
491                fetch c_CTU into r_CTU ;
492                --
493                close c_CTU ;*/
494                --
495 
496 
497                if p_reuse_object_flag = 'Y' then
498                  if c_CTU_min_max_dates%found then
499                    -- cursor to find the object
500                    open c_find_CTU_in_target( l_min_esd,l_max_eed,
501                                          p_target_business_group_id, nvl(l_cm_typ_usg_id, -999)  ) ;
502                    fetch c_find_CTU_in_target into l_new_value ;
503                    if c_find_CTU_in_target%found then
504                      --
505                      --TEMPIK
506                      l_dt_rec_found :=   dt_api.check_min_max_dates
507                          (p_base_table_name => 'BEN_CM_TYP_USG_F',
508                           p_base_key_column => 'CM_TYP_USG_ID',
509                           p_base_key_value  => l_new_value,
510                           p_from_date       => l_min_esd,
511                           p_to_date         => l_max_eed );
512                      if l_dt_rec_found THEN
513                      --END TEMPIK
514                      --
515                      if r_CTU_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
516                         nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'CM_TYP_USG_ID'  then
517                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'CM_TYP_USG_ID' ;
518                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_CTU_unique.information1 ;
519                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
520                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
521                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_CTU_unique.table_route_id;
522                         --
523                         -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
524                         --
525                         ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
526                      end if ;
527                      --
528                      l_object_found_in_target := true ;
529                      --TEMPIK
530                      end if; -- l_dt_rec_found
531                      --END TEMPIK
532                    end if;
533                    close c_find_CTU_in_target ;
534                  --
535                  end if;
536                end if ;
537                --
538                close c_CTU_min_max_dates ;
539       -- UPD START
540       end if; --if p_dml_operation
541       --
542       if not l_object_found_in_target OR l_update  then
543       --if not l_object_found_in_target then
544       -- UPD END
545          --
546          l_current_pk_id := r_CTU.information1;
547          --
548          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
549          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
550          --
551          if l_current_pk_id =  l_prev_pk_id  then
552            --
553            l_first_rec := false ;
554            --
555          else
556            --
557            l_first_rec := true ;
558            --
559          end if ;
560          --
561 
562          l_effective_date := r_CTU.information2;
563          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
564               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
565            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
566          end if;
567 
568          --if l_first_rec then
569          -- UPD START
570          if l_first_rec and not l_update then
571          -- UPD END
572 
573            -- Call Create routine.
574            hr_utility.set_location(' BEN_CM_TYP_USG_F CREATE_CM_TYP_USG ',20);
575            BEN_CM_TYP_USG_API.CREATE_CM_TYP_USG(
576              --
577              P_VALIDATE               => false
578              ,P_EFFECTIVE_DATE        => l_effective_date
579              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
580              --
581             ,P_ACTN_TYP_ID      => l_ACTN_TYP_ID
582             ,P_ALL_R_ANY_CD      => r_CTU.INFORMATION11
583             ,P_CM_TYP_ID      => l_CM_TYP_ID
584             ,P_CM_TYP_USG_ID      => l_cm_typ_usg_id
585             ,P_CM_USG_RL      => l_CM_USG_RL
586             ,P_CTU_ATTRIBUTE1      => r_CTU.INFORMATION111
587             ,P_CTU_ATTRIBUTE10      => r_CTU.INFORMATION120
588             ,P_CTU_ATTRIBUTE11      => r_CTU.INFORMATION121
589             ,P_CTU_ATTRIBUTE12      => r_CTU.INFORMATION122
590             ,P_CTU_ATTRIBUTE13      => r_CTU.INFORMATION123
591             ,P_CTU_ATTRIBUTE14      => r_CTU.INFORMATION124
592             ,P_CTU_ATTRIBUTE15      => r_CTU.INFORMATION125
593             ,P_CTU_ATTRIBUTE16      => r_CTU.INFORMATION126
594             ,P_CTU_ATTRIBUTE17      => r_CTU.INFORMATION127
595             ,P_CTU_ATTRIBUTE18      => r_CTU.INFORMATION128
596             ,P_CTU_ATTRIBUTE19      => r_CTU.INFORMATION129
597             ,P_CTU_ATTRIBUTE2      => r_CTU.INFORMATION112
598             ,P_CTU_ATTRIBUTE20      => r_CTU.INFORMATION130
599             ,P_CTU_ATTRIBUTE21      => r_CTU.INFORMATION131
600             ,P_CTU_ATTRIBUTE22      => r_CTU.INFORMATION132
601             ,P_CTU_ATTRIBUTE23      => r_CTU.INFORMATION133
602             ,P_CTU_ATTRIBUTE24      => r_CTU.INFORMATION134
603             ,P_CTU_ATTRIBUTE25      => r_CTU.INFORMATION135
604             ,P_CTU_ATTRIBUTE26      => r_CTU.INFORMATION136
605             ,P_CTU_ATTRIBUTE27      => r_CTU.INFORMATION137
606             ,P_CTU_ATTRIBUTE28      => r_CTU.INFORMATION138
607             ,P_CTU_ATTRIBUTE29      => r_CTU.INFORMATION139
608             ,P_CTU_ATTRIBUTE3      => r_CTU.INFORMATION113
609             ,P_CTU_ATTRIBUTE30      => r_CTU.INFORMATION140
610             ,P_CTU_ATTRIBUTE4      => r_CTU.INFORMATION114
611             ,P_CTU_ATTRIBUTE5      => r_CTU.INFORMATION115
612             ,P_CTU_ATTRIBUTE6      => r_CTU.INFORMATION116
613             ,P_CTU_ATTRIBUTE7      => r_CTU.INFORMATION117
614             ,P_CTU_ATTRIBUTE8      => r_CTU.INFORMATION118
615             ,P_CTU_ATTRIBUTE9      => r_CTU.INFORMATION119
616             ,P_CTU_ATTRIBUTE_CATEGORY      => r_CTU.INFORMATION110
617             ,P_DESCR_TEXT      => r_CTU.INFORMATION219
618             ,P_ENRT_PERD_ID      => l_ENRT_PERD_ID
619             ,P_LER_ID      => l_LER_ID
620             ,P_PGM_ID      => l_PGM_ID
621             ,P_PL_ID      => l_PL_ID
622             ,P_PL_TYP_ID      => l_PL_TYP_ID
623              --
624              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
625              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
626              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
627            );
628            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
629            -- Update all relevent cer records with new pk_id
630            hr_utility.set_location('Before plsql table ',222);
631            hr_utility.set_location('new_value id '||l_cm_typ_usg_id,222);
632            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'CM_TYP_USG_ID' ;
633            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_CTU.information1 ;
634            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_CM_TYP_USG_ID ;
635            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
636            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_CTU_unique.table_route_id;
637            hr_utility.set_location('After plsql table ',222);
638            --
639            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
640            --
641            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
642            --
643          else
644            --
645            -- Call Update routine for the pk_id created in prev run .
646            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
647            hr_utility.set_location(' BEN_CM_TYP_USG_F UPDATE_CM_TYP_USG ',30);
648 
649            --UPD START
650            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
651            --
652            if l_update then
653              --
654              l_datetrack_mode := r_CTU.datetrack_mode ;
655              --
656              get_dt_modes(
657                p_effective_date        => l_process_date,
658                p_effective_end_date    => r_CTU.information3,
659                p_effective_start_date  => r_CTU.information2,
660                p_dml_operation         => r_CTU.dml_operation,
661                p_datetrack_mode        => l_datetrack_mode );
662            --    p_update                => l_update
663              --
664              l_effective_date := l_process_date;
665              l_cm_typ_usg_id   := r_CTU.information1;
666              l_object_version_number := r_CTU.information265;
667              --
668            end if;
669            --
670            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
671            --
672            IF l_update OR l_dml_operation <> 'UPDATE' THEN
673            --UPD END
674             --
675                    BEN_CM_TYP_USG_API.UPDATE_CM_TYP_USG(
676                      --
677                      P_VALIDATE               => false
678                      ,P_EFFECTIVE_DATE        => l_effective_date
679                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
680                      --
681                      ,P_ACTN_TYP_ID      => l_ACTN_TYP_ID
682                      ,P_ALL_R_ANY_CD      => r_CTU.INFORMATION11
683                      ,P_CM_TYP_ID      => l_CM_TYP_ID
684                      ,P_CM_TYP_USG_ID      => l_cm_typ_usg_id
685                      ,P_CM_USG_RL      => l_CM_USG_RL
686                      ,P_CTU_ATTRIBUTE1      => r_CTU.INFORMATION111
687                      ,P_CTU_ATTRIBUTE10      => r_CTU.INFORMATION120
688                      ,P_CTU_ATTRIBUTE11      => r_CTU.INFORMATION121
689                      ,P_CTU_ATTRIBUTE12      => r_CTU.INFORMATION122
690                      ,P_CTU_ATTRIBUTE13      => r_CTU.INFORMATION123
691                      ,P_CTU_ATTRIBUTE14      => r_CTU.INFORMATION124
692                      ,P_CTU_ATTRIBUTE15      => r_CTU.INFORMATION125
693                      ,P_CTU_ATTRIBUTE16      => r_CTU.INFORMATION126
694                      ,P_CTU_ATTRIBUTE17      => r_CTU.INFORMATION127
695                      ,P_CTU_ATTRIBUTE18      => r_CTU.INFORMATION128
696                      ,P_CTU_ATTRIBUTE19      => r_CTU.INFORMATION129
697                      ,P_CTU_ATTRIBUTE2      => r_CTU.INFORMATION112
698                      ,P_CTU_ATTRIBUTE20      => r_CTU.INFORMATION130
699                      ,P_CTU_ATTRIBUTE21      => r_CTU.INFORMATION131
700                      ,P_CTU_ATTRIBUTE22      => r_CTU.INFORMATION132
701                      ,P_CTU_ATTRIBUTE23      => r_CTU.INFORMATION133
702                      ,P_CTU_ATTRIBUTE24      => r_CTU.INFORMATION134
703                      ,P_CTU_ATTRIBUTE25      => r_CTU.INFORMATION135
704                      ,P_CTU_ATTRIBUTE26      => r_CTU.INFORMATION136
705                      ,P_CTU_ATTRIBUTE27      => r_CTU.INFORMATION137
706                      ,P_CTU_ATTRIBUTE28      => r_CTU.INFORMATION138
707                      ,P_CTU_ATTRIBUTE29      => r_CTU.INFORMATION139
708                      ,P_CTU_ATTRIBUTE3      => r_CTU.INFORMATION113
709                      ,P_CTU_ATTRIBUTE30      => r_CTU.INFORMATION140
710                      ,P_CTU_ATTRIBUTE4      => r_CTU.INFORMATION114
711                      ,P_CTU_ATTRIBUTE5      => r_CTU.INFORMATION115
712                      ,P_CTU_ATTRIBUTE6      => r_CTU.INFORMATION116
713                      ,P_CTU_ATTRIBUTE7      => r_CTU.INFORMATION117
714                      ,P_CTU_ATTRIBUTE8      => r_CTU.INFORMATION118
715                      ,P_CTU_ATTRIBUTE9      => r_CTU.INFORMATION119
716                      ,P_CTU_ATTRIBUTE_CATEGORY      => r_CTU.INFORMATION110
717                      ,P_DESCR_TEXT      => r_CTU.INFORMATION219
718                      ,P_ENRT_PERD_ID      => l_ENRT_PERD_ID
719                      ,P_LER_ID      => l_LER_ID
720                      ,P_PGM_ID      => l_PGM_ID
721                      ,P_PL_ID      => l_PL_ID
722                      ,P_PL_TYP_ID      => l_PL_TYP_ID
723                      --
724                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
725                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
726                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
727                      --UPD START
728                      --,P_DATETRACK_MODE        => hr_api.g_update
729                      ,P_DATETRACK_MODE        => l_DATETRACK_MODE
730 
731                    );
732            --
733            -- UPD START
734            end if;  -- l_update
735            -- UPD END
736          end if;
737          --
738          -- Delete the row if it is end dated.
739          --
740          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
741              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
742            trunc(l_max_eed) = r_CTU.information3) then
743            --
744            BEN_CM_TYP_USG_API.delete_CM_TYP_USG(
745             --
746              p_validate                       => false
747             ,p_cm_typ_usg_id                  => l_cm_typ_usg_id
748             ,p_effective_start_date           => l_effective_start_date
749             ,p_effective_end_date             => l_effective_end_date
750             ,p_object_version_number          => l_object_version_number
751             ,p_effective_date                 => l_max_eed
752             ,p_datetrack_mode                 => hr_api.g_delete
753             --
754            );
755            --
756          end if;
757          --
758          l_prev_pk_id := l_current_pk_id ;
759          --
760        end if;
761        --
762      end if;
763      --
764    end loop;
765    --
766  end create_CTU_rows;
767 
768    --
769    ---------------------------------------------------------------
770    ----------------------< create_CTT_rows >-----------------------
771    ---------------------------------------------------------------
772    --
773    procedure create_CTT_rows
774    (
775          p_validate                       in  number     default 0
776         ,p_copy_entity_txn_id             in  number
777         ,p_effective_date                 in  date
778         ,p_prefix_suffix_text             in  varchar2  default null
779         ,p_reuse_object_flag              in  varchar2  default null
780         ,p_target_business_group_id       in  varchar2  default null
781         ,p_prefix_suffix_cd               in  varchar2  default null
782    ) is
783    --
784    l_CM_TRGR_ID  number;
785    l_CM_TYP_ID  number;
786    l_CM_TYP_TRGR_RL  number;
787    cursor c_unique_CTT(l_table_alias varchar2) is
788    select distinct cpe.information1,
789      cpe.information2,
790      cpe.information3,
791      cpe.table_route_id,
792    -- UPD START
793      cpe.dml_operation,
794      cpe.datetrack_mode
795    -- UPD END
796    from   ben_copy_entity_results cpe,
797           pqh_table_route tr
798    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
799    and   cpe.table_route_id     = tr.table_route_id
800    -- and   tr.where_clause        = l_BEN_CM_TYP_TRGR_F
801    and   tr.table_alias = l_table_alias
802    and   cpe.number_of_copies   = 1 -- ADDITION
803    -- UPD START
804    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
805    order by information1, information2; --added for bug: 5151945
806    -- UPD END
807 
808    --
809    --
810    cursor c_CTT_min_max_dates(c_table_route_id  number,
811                 c_information1   number) is
812    select
813      min(cpe.information2) min_esd,
814      max(cpe.information3) min_eed
815    from ben_copy_entity_results cpe
816    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
817    and   cpe.table_route_id     = c_table_route_id
818    and   cpe.information1       = c_information1 ;
819    --
820    cursor c_CTT(c_table_route_id  number,
821                 c_information1   number,
822                 c_information2   date,
823                 c_information3   date)  is
824    select
825      cpe.*
826    from ben_copy_entity_results cpe
827    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
828    and   cpe.table_route_id     = c_table_route_id
829    and   cpe.information1       = c_information1
830    and   cpe.information2       = c_information2
831    and   cpe.information3       = c_information3
832    and rownum = 1 ;
833    -- Date Track target record
834    cursor c_find_CTT_in_target(
835                                 c_effective_start_date    date,
836                                 c_effective_end_date      date,
837                                 c_business_group_id       number,
838                                 c_new_pk_id               number) is
839    select
840      CTT.cm_typ_trgr_id new_value
841    from BEN_CM_TYP_TRGR_F CTT
842    where
843    nvl(CTT.CM_TRGR_ID,-999)     = nvl(l_CM_TRGR_ID,-999)  and
844    nvl(CTT.CM_TYP_ID,-999)     = nvl(l_CM_TYP_ID,-999)  and
845    CTT.business_group_id  = c_business_group_id
846    and   CTT.cm_typ_trgr_id  <> c_new_pk_id
847 --TEMPIK
848    and c_effective_start_date between effective_start_date
849                             and effective_end_date ;
850 --END TEMPIK
851 /*TEMPIK
852         and exists ( select null
853                 from BEN_CM_TYP_TRGR_F CTT1
854                 where
855                 nvl(CTT1.CM_TRGR_ID,-999)     = nvl(l_CM_TRGR_ID,-999)  and
856                 nvl(CTT1.CM_TYP_ID,-999)     = nvl(l_CM_TYP_ID,-999)  and
857                 CTT1.business_group_id  = c_business_group_id
858                 and   CTT1.effective_start_date <= c_effective_start_date )
859    and exists ( select null
860                 from BEN_CM_TYP_TRGR_F CTT2
861                 where
862                 nvl(CTT2.CM_TRGR_ID,-999)     = nvl(l_CM_TRGR_ID,-999)  and
863                 nvl(CTT2.CM_TYP_ID,-999)     = nvl(l_CM_TYP_ID,-999)  and
864                 CTT2.business_group_id  = c_business_group_id
865                 and   CTT2.effective_end_date >= c_effective_end_date )
866                 ;
867 TEMPIK */
868    --TEMPIK
869    l_dt_rec_found            boolean ;
870    --END TEMPIK
871 
872    --UPD START
873    --
874    l_update                  boolean      := false ;
875    l_datetrack_mode          varchar2(80) := hr_api.g_update;
876    l_process_date            date;
877    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
878    --
879    --UPD END
880 
881    --
882    l_current_pk_id           number := null ;
883    l_prev_pk_id              number := null ;
884    l_first_rec               boolean := true ;
885    r_CTT                     c_CTT%rowtype;
886    l_cm_typ_trgr_id             number ;
887    l_object_version_number   number ;
888    l_effective_start_date    date ;
889    l_effective_end_date      date ;
890    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
891    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
892    l_new_value               number(15);
893    l_object_found_in_target  boolean := false ;
894    l_min_esd                 date;
895    l_max_eed                 date;
896    l_effective_date          date;
897    --
898  begin
899    -- Initialization
900    l_object_found_in_target := false ;
901    -- End Initialization
902    -- Derive the prefix - sufix
903    if   p_prefix_suffix_cd = 'PREFIX' then
904      l_prefix  := p_prefix_suffix_text ;
905    elsif p_prefix_suffix_cd = 'SUFFIX' then
906      l_suffix   := p_prefix_suffix_text ;
907    else
908      l_prefix := null ;
909      l_suffix  := null ;
910    end if ;
911    -- End Prefix Sufix derivation
912    for r_CTT_unique in c_unique_CTT('CTT') loop
913 
914      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
915         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
916          r_CTT_unique.information3 >=
917                  ben_pd_copy_to_ben_one.g_copy_effective_date)
918         ) then
919        --
920        hr_utility.set_location(' r_CTT_unique.table_route_id '||r_CTT_unique.table_route_id,10);
921        hr_utility.set_location(' r_CTT_unique.information1 '||r_CTT_unique.information1,10);
922        hr_utility.set_location( 'r_CTT_unique.information2 '||r_CTT_unique.information2,10);
923        hr_utility.set_location( 'r_CTT_unique.information3 '||r_CTT_unique.information3,10);
924        -- If reuse objects flag is 'Y' then check for the object in the target business group
925        -- if found insert the record into PLSql table and exit the loop else try create the
926        -- object in the target business group
927        --
928        l_object_found_in_target := false ;
929 
930        -- UPD START
931        open c_CTT(r_CTT_unique.table_route_id,
932                         r_CTT_unique.information1,
933                         r_CTT_unique.information2,
934                         r_CTT_unique.information3 ) ;
935        --
936        fetch c_CTT into r_CTT ;
937        --
938        close c_CTT ;
939        --
940        l_dml_operation:= r_CTT_unique.dml_operation ;
941        l_CM_TRGR_ID := get_fk('CM_TRGR_ID', r_CTT.information257,r_CTT.dml_operation);
942        l_CM_TYP_ID := get_fk('CM_TYP_ID', r_CTT.information237,r_CTT.dml_operation);
943        l_CM_TYP_TRGR_RL := get_fk('FORMULA_ID', r_CTT.information258,r_CTT.dml_operation);
944        --
945        l_update := false;
946        l_process_date := p_effective_date;
947        --
948        if l_dml_operation = 'UPDATE' then
949          --
950                  l_object_found_in_target := TRUE;
951                  --
952                  if l_process_date between r_CTT_unique.information2 and r_CTT_unique.information3 then
953                        l_update := true;
954                        if r_CTT_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
955                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'CM_TYP_TRGR_ID'
956                        then
957                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'CM_TYP_TRGR_ID' ;
958                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_CTT_unique.information1 ;
959                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_CTT_unique.information1 ;
960                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
961                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_CTT_unique.table_route_id;
962                           --
963                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
964                           --
965                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
966                           -- DOUBT
967                           --log_data('CTT',l_new_value,l_prefix || r_CTT_unique.name|| l_suffix,'REUSED');
968                           --
969                        end if ;
970                        hr_utility.set_location( 'found record for update',10);
971                    --
972                  else
973                    --
974                    l_update := false;
975                    --
976                  end if;
977                else
978                 --
979                 --UPD END
980 
981                l_min_esd := null ;
982                l_max_eed := null ;
983                open c_CTT_min_max_dates(r_CTT_unique.table_route_id, r_CTT_unique.information1 ) ;
984                fetch c_CTT_min_max_dates into l_min_esd,l_max_eed ;
985                --
986 
987                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
988                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
989                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
990                end if;
991                l_min_esd := greatest(l_min_esd,r_CTT_unique.information2);
992                /*open c_CTT(r_CTT_unique.table_route_id,
993                         r_CTT_unique.information1,
994                         r_CTT_unique.information2,
995                         r_CTT_unique.information3 ) ;
996                --
997                fetch c_CTT into r_CTT ;
998                --
999                close c_CTT ;*/
1000                --
1001                if p_reuse_object_flag = 'Y' then
1002                  if c_CTT_min_max_dates%found then
1003                    -- cursor to find the object
1004                    open c_find_CTT_in_target( l_min_esd,l_max_eed,
1005                                          p_target_business_group_id, nvl(l_cm_typ_trgr_id, -999)  ) ;
1006                    fetch c_find_CTT_in_target into l_new_value ;
1007                    if c_find_CTT_in_target%found then
1008                      --
1009                      --TEMPIK
1010                      l_dt_rec_found :=   dt_api.check_min_max_dates
1011                          (p_base_table_name => 'BEN_CM_TYP_TRGR_F',
1012                           p_base_key_column => 'CM_TYP_TRGR_ID',
1013                           p_base_key_value  => l_new_value,
1014                           p_from_date       => l_min_esd,
1015                           p_to_date         => l_max_eed );
1016                      if l_dt_rec_found THEN
1017                      --END TEMPIK
1018                      if r_CTT_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
1019                         nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'CM_TYP_TRGR_ID'  then
1020                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'CM_TYP_TRGR_ID' ;
1021                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_CTT_unique.information1 ;
1022                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
1023                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
1024                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_CTT_unique.table_route_id;
1025                         --
1026                         -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
1027                         --
1028                         ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
1029                      end if ;
1030                      --
1031                      l_object_found_in_target := true ;
1032                      --TEMPIK
1033                      end if; -- l_dt_rec_found
1034                      --END TEMPIK
1035                    end if;
1036                    close c_find_CTT_in_target ;
1037                  --
1038                  end if;
1039                end if ;
1040                --
1041                close c_CTT_min_max_dates ;
1042        -- UPD START
1043        --
1044        end if; --if p_dml_operation
1045        --
1046        if not l_object_found_in_target OR l_update  then
1047        --if not l_object_found_in_target then
1048        -- UPD END
1049          --
1050          l_current_pk_id := r_CTT.information1;
1051          --
1052          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
1053          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
1054          --
1055          if l_current_pk_id =  l_prev_pk_id  then
1056            --
1057            l_first_rec := false ;
1058            --
1059          else
1060            --
1061            l_first_rec := true ;
1062            --
1063          end if ;
1064          --
1065 
1066          l_effective_date := r_CTT.information2;
1067          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
1068               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
1069            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
1070          end if;
1071          -- UPD START
1072          --if l_first_rec then
1073          if l_first_rec and not l_update then
1074          -- UPD END
1075            -- Call Create routine.
1076            hr_utility.set_location(' BEN_CM_TYP_TRGR_F CREATE_CM_TYP_TRGR ',20);
1077            BEN_CM_TYP_TRGR_API.CREATE_CM_TYP_TRGR(
1078              --
1079              P_VALIDATE               => false
1080              ,P_EFFECTIVE_DATE        => l_effective_date
1081              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
1082              --
1083              ,P_CM_TRGR_ID      => l_CM_TRGR_ID
1084              ,P_CM_TYP_ID      => l_CM_TYP_ID
1085              ,P_CM_TYP_TRGR_ID      => l_cm_typ_trgr_id
1086              ,P_CM_TYP_TRGR_RL      => l_CM_TYP_TRGR_RL
1087              ,P_CTT_ATTRIBUTE1      => r_CTT.INFORMATION111
1088              ,P_CTT_ATTRIBUTE10      => r_CTT.INFORMATION120
1089              ,P_CTT_ATTRIBUTE11      => r_CTT.INFORMATION121
1090              ,P_CTT_ATTRIBUTE12      => r_CTT.INFORMATION122
1091              ,P_CTT_ATTRIBUTE13      => r_CTT.INFORMATION123
1092              ,P_CTT_ATTRIBUTE14      => r_CTT.INFORMATION124
1093              ,P_CTT_ATTRIBUTE15      => r_CTT.INFORMATION125
1094              ,P_CTT_ATTRIBUTE16      => r_CTT.INFORMATION126
1095              ,P_CTT_ATTRIBUTE17      => r_CTT.INFORMATION127
1096              ,P_CTT_ATTRIBUTE18      => r_CTT.INFORMATION128
1097              ,P_CTT_ATTRIBUTE19      => r_CTT.INFORMATION129
1098              ,P_CTT_ATTRIBUTE2      => r_CTT.INFORMATION112
1099              ,P_CTT_ATTRIBUTE20      => r_CTT.INFORMATION130
1100              ,P_CTT_ATTRIBUTE21      => r_CTT.INFORMATION131
1101              ,P_CTT_ATTRIBUTE22      => r_CTT.INFORMATION132
1102              ,P_CTT_ATTRIBUTE23      => r_CTT.INFORMATION133
1103              ,P_CTT_ATTRIBUTE24      => r_CTT.INFORMATION134
1104              ,P_CTT_ATTRIBUTE25      => r_CTT.INFORMATION135
1105              ,P_CTT_ATTRIBUTE26      => r_CTT.INFORMATION136
1106              ,P_CTT_ATTRIBUTE27      => r_CTT.INFORMATION137
1107              ,P_CTT_ATTRIBUTE28      => r_CTT.INFORMATION138
1108              ,P_CTT_ATTRIBUTE29      => r_CTT.INFORMATION139
1109              ,P_CTT_ATTRIBUTE3      => r_CTT.INFORMATION113
1110              ,P_CTT_ATTRIBUTE30      => r_CTT.INFORMATION140
1111              ,P_CTT_ATTRIBUTE4      => r_CTT.INFORMATION114
1112              ,P_CTT_ATTRIBUTE5      => r_CTT.INFORMATION115
1113              ,P_CTT_ATTRIBUTE6      => r_CTT.INFORMATION116
1114              ,P_CTT_ATTRIBUTE7      => r_CTT.INFORMATION117
1115              ,P_CTT_ATTRIBUTE8      => r_CTT.INFORMATION118
1116              ,P_CTT_ATTRIBUTE9      => r_CTT.INFORMATION119
1117              ,P_CTT_ATTRIBUTE_CATEGORY      => r_CTT.INFORMATION110
1118              --
1119              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
1120              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
1121              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
1122            );
1123            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
1124            -- Update all relevent cer records with new pk_id
1125            hr_utility.set_location('Before plsql table ',222);
1126            hr_utility.set_location('new_value id '||l_cm_typ_trgr_id,222);
1127            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'CM_TYP_TRGR_ID' ;
1128            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_CTT.information1 ;
1129            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_CM_TYP_TRGR_ID ;
1130            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
1131            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_CTT_unique.table_route_id;
1132            hr_utility.set_location('After plsql table ',222);
1133            --
1134            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
1135            --
1136            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
1137            --
1138          else
1139            --
1140            -- Call Update routine for the pk_id created in prev run .
1141            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
1142            hr_utility.set_location(' BEN_CM_TYP_TRGR_F UPDATE_CM_TYP_TRGR ',30);
1143 
1144            --UPD START
1145            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
1146            --
1147            if l_update then
1148              --
1149              l_datetrack_mode := r_CTT.datetrack_mode ;
1150              --
1151              get_dt_modes(
1152                p_effective_date        => l_process_date,
1153                p_effective_end_date    => r_CTT.information3,
1154                p_effective_start_date  => r_CTT.information2,
1155                p_dml_operation         => r_CTT.dml_operation,
1156                p_datetrack_mode        => l_datetrack_mode );
1157            --    p_update                => l_update
1158              --
1159              l_effective_date := l_process_date;
1160              l_CM_TRGR_ID  := r_CTT.information1;
1161              l_object_version_number := r_CTT.information265;
1162              --
1163            end if;
1164            --
1165            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
1166            --
1167            IF l_update OR l_dml_operation <> 'UPDATE' THEN
1168            --UPD END
1169 
1170                    BEN_CM_TYP_TRGR_API.UPDATE_CM_TYP_TRGR(
1171                      --
1172                      P_VALIDATE               => false
1173                      ,P_EFFECTIVE_DATE        => l_effective_date
1174                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
1175                      --
1176                      ,P_CM_TRGR_ID      => l_CM_TRGR_ID
1177                      ,P_CM_TYP_ID      => l_CM_TYP_ID
1178                      ,P_CM_TYP_TRGR_ID      => l_cm_typ_trgr_id
1179                      ,P_CM_TYP_TRGR_RL      => l_CM_TYP_TRGR_RL
1180                      ,P_CTT_ATTRIBUTE1      => r_CTT.INFORMATION111
1181                      ,P_CTT_ATTRIBUTE10      => r_CTT.INFORMATION120
1182                      ,P_CTT_ATTRIBUTE11      => r_CTT.INFORMATION121
1183                      ,P_CTT_ATTRIBUTE12      => r_CTT.INFORMATION122
1184                      ,P_CTT_ATTRIBUTE13      => r_CTT.INFORMATION123
1185                      ,P_CTT_ATTRIBUTE14      => r_CTT.INFORMATION124
1186                      ,P_CTT_ATTRIBUTE15      => r_CTT.INFORMATION125
1187                      ,P_CTT_ATTRIBUTE16      => r_CTT.INFORMATION126
1188                      ,P_CTT_ATTRIBUTE17      => r_CTT.INFORMATION127
1189                      ,P_CTT_ATTRIBUTE18      => r_CTT.INFORMATION128
1190                      ,P_CTT_ATTRIBUTE19      => r_CTT.INFORMATION129
1191                      ,P_CTT_ATTRIBUTE2      => r_CTT.INFORMATION112
1192                      ,P_CTT_ATTRIBUTE20      => r_CTT.INFORMATION130
1193                      ,P_CTT_ATTRIBUTE21      => r_CTT.INFORMATION131
1194                      ,P_CTT_ATTRIBUTE22      => r_CTT.INFORMATION132
1195                      ,P_CTT_ATTRIBUTE23      => r_CTT.INFORMATION133
1196                      ,P_CTT_ATTRIBUTE24      => r_CTT.INFORMATION134
1197                      ,P_CTT_ATTRIBUTE25      => r_CTT.INFORMATION135
1198                      ,P_CTT_ATTRIBUTE26      => r_CTT.INFORMATION136
1199                      ,P_CTT_ATTRIBUTE27      => r_CTT.INFORMATION137
1200                      ,P_CTT_ATTRIBUTE28      => r_CTT.INFORMATION138
1201                      ,P_CTT_ATTRIBUTE29      => r_CTT.INFORMATION139
1202                      ,P_CTT_ATTRIBUTE3      => r_CTT.INFORMATION113
1203                      ,P_CTT_ATTRIBUTE30      => r_CTT.INFORMATION140
1204                      ,P_CTT_ATTRIBUTE4      => r_CTT.INFORMATION114
1205                      ,P_CTT_ATTRIBUTE5      => r_CTT.INFORMATION115
1206                      ,P_CTT_ATTRIBUTE6      => r_CTT.INFORMATION116
1207                      ,P_CTT_ATTRIBUTE7      => r_CTT.INFORMATION117
1208                      ,P_CTT_ATTRIBUTE8      => r_CTT.INFORMATION118
1209                      ,P_CTT_ATTRIBUTE9      => r_CTT.INFORMATION119
1210                      ,P_CTT_ATTRIBUTE_CATEGORY      => r_CTT.INFORMATION110
1211                      --
1212                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
1213                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
1214                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
1215                      -- UPD START
1216                      --,P_DATETRACK_MODE        => hr_api.g_update
1217                      ,P_DATETRACK_MODE        => l_datetrack_mode
1218                      -- UPD END
1219                    );
1220            -- UPD START
1221            end if;  -- l_update
1222            -- UPD END
1223 
1224          end if;
1225          --
1226          --
1227          -- Delete the row if it is end dated.
1228          --
1229          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
1230              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
1231            trunc(l_max_eed) = r_CTT.information3) then
1232              --
1233            BEN_CM_TYP_TRGR_API.delete_CM_TYP_TRGR(
1234               --
1235                p_validate                       => false
1236               ,p_cm_typ_trgr_id                 => l_cm_typ_trgr_id
1237               ,p_effective_start_date           => l_effective_start_date
1238               ,p_effective_end_date             => l_effective_end_date
1239               ,p_object_version_number          => l_object_version_number
1240               ,p_effective_date                 => l_max_eed
1241               ,p_datetrack_mode                 => hr_api.g_delete
1242               --
1243             );
1244             --
1245          end if;
1246          --
1247          l_prev_pk_id := l_current_pk_id ;
1248          --
1249        end if;
1250        --
1251      end if;
1252      --
1253    end loop;
1254    --
1255  end create_CTT_rows;
1256 
1257    --
1258    ---------------------------------------------------------------
1259    ----------------------< create_CMT_rows >-----------------------
1260    ---------------------------------------------------------------
1261    --
1262    procedure create_CMT_rows
1263    (
1264          p_validate                       in  number     default 0
1265         ,p_copy_entity_txn_id             in  number
1266         ,p_effective_date                 in  date
1267         ,p_prefix_suffix_text             in  varchar2  default null
1268         ,p_reuse_object_flag              in  varchar2  default null
1269         ,p_target_business_group_id       in  varchar2  default null
1270         ,p_prefix_suffix_cd               in  varchar2  default null
1271    ) is
1272    --
1273    l_CM_TYP_ID  number;
1274    l_CM_DLVRY_MTHD_TYP_CD varchar2(100);
1275    cursor c_unique_CMT(l_table_alias varchar2) is
1276    select distinct cpe.information1,
1277      cpe.information2,
1278      cpe.information3,
1279      cpe.information25 name, -- This needs to be derived from the api call below
1280      cpe.table_route_id,
1281      -- UPD START
1282      cpe.dml_operation,
1283      cpe.datetrack_mode
1284      -- UPD END
1285    from ben_copy_entity_results cpe,
1286         pqh_table_route tr
1287    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
1288    and   cpe.table_route_id     = tr.table_route_id
1289    -- and   tr.where_clause        = l_BEN_CM_DLVRY_MTHD_TYP
1290    and   tr.table_alias = l_table_alias
1291    and   cpe.number_of_copies   = 1 -- ADDITION
1292    -- UPD START
1293    group by cpe.information1,cpe.information2,cpe.information3, cpe.information25, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
1294    order by information1, information2; --added for bug: 5151945
1295    --UPD END
1296    --
1297    --
1298    cursor c_CMT_min_max_dates(c_table_route_id  number,
1299                 c_information1   number) is
1300    select
1301      min(cpe.information2) min_esd,
1302      max(cpe.information3) min_eed
1303    from ben_copy_entity_results cpe
1304    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
1305    and   cpe.table_route_id     = c_table_route_id
1306    and   cpe.information1       = c_information1 ;
1307    --
1308    cursor c_CMT(c_table_route_id  number,
1309                 c_information1   number,
1310                 c_information2   date,
1311                 c_information3   date)  is
1312    select
1313      cpe.*
1314    from ben_copy_entity_results cpe
1315    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
1316    and   cpe.table_route_id     = c_table_route_id
1317    and   cpe.information1       = c_information1
1318    and rownum = 1 ;
1319    -- Date Track target record
1320    cursor c_find_CMT_in_target(
1321                                 c_effective_start_date    date,
1322                                 c_effective_end_date      date,
1323                                 c_business_group_id       number,
1324                                 c_new_pk_id               number) is
1325    select
1326      CMT.cm_dlvry_mthd_typ_id new_value
1327    from BEN_CM_DLVRY_MTHD_TYP CMT
1328    where
1329    CMT.CM_TYP_ID     = l_CM_TYP_ID  and
1330    CMT.CM_DLVRY_MTHD_TYP_CD = l_CM_DLVRY_MTHD_TYP_CD and
1331    CMT.business_group_id  = c_business_group_id
1332    and   CMT.cm_dlvry_mthd_typ_id  <> c_new_pk_id;
1333    --
1334    --UPD START
1335    --
1336    l_update                  boolean      := false ;
1337    l_datetrack_mode          varchar2(80) := hr_api.g_update;
1338    l_process_date            date;
1339    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
1340    --
1341    --UPD END
1342 
1343    l_current_pk_id           number := null ;
1344    l_prev_pk_id              number := null ;
1345    l_first_rec               boolean := true ;
1346    r_CMT                     c_CMT%rowtype;
1347    l_cm_dlvry_mthd_typ_id             number ;
1348    l_object_version_number   number ;
1349    l_effective_start_date    date ;
1350    l_effective_end_date      date ;
1351    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
1352    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
1353    l_new_value               number(15);
1354    l_object_found_in_target  boolean := false ;
1355    l_min_esd                 date;
1356    l_max_eed                 date;
1357    l_effective_date          date;
1358    --
1359  begin
1360    -- Initialization
1361    l_object_found_in_target := false ;
1362    -- End Initialization
1363    -- Derive the prefix - sufix
1364    if   p_prefix_suffix_cd = 'PREFIX' then
1365      l_prefix  := p_prefix_suffix_text ;
1366    elsif p_prefix_suffix_cd = 'SUFFIX' then
1367      l_suffix   := p_prefix_suffix_text ;
1368    else
1369      l_prefix := null ;
1370      l_suffix  := null ;
1371    end if ;
1372    -- End Prefix Sufix derivation
1373    for r_CMT_unique in c_unique_CMT('CMT') loop
1374      --
1375      hr_utility.set_location(' r_CMT_unique.table_route_id '||r_CMT_unique.table_route_id,10);
1376      hr_utility.set_location(' r_CMT_unique.information1 '||r_CMT_unique.information1,10);
1377      hr_utility.set_location( 'r_CMT_unique.information2 '||r_CMT_unique.information2,10);
1378      hr_utility.set_location( 'r_CMT_unique.information3 '||r_CMT_unique.information3,10);
1379      -- If reuse objects flag is 'Y' then check for the object in the target business group
1380      -- if found insert the record into PLSql table and exit the loop else try create the
1381      -- object in the target business group
1382      --
1383      l_object_found_in_target := false ;
1384 
1385       -- UPD START
1386       open c_CMT(r_CMT_unique.table_route_id,
1387                 r_CMT_unique.information1,
1388                 r_CMT_unique.information2,
1389                 r_CMT_unique.information3 ) ;
1390       --
1391       fetch c_CMT into r_CMT ;
1392       --
1393       close c_CMT ;
1394       -- UPD END
1395 
1396 
1397 
1398      l_min_esd := null ;
1399      l_max_eed := null ;
1400        /*--
1401        open c_CMT(r_CMT_unique.table_route_id,
1402                 r_CMT_unique.information1,
1403                 r_CMT_unique.information2,
1404                 r_CMT_unique.information3 ) ;
1405        --
1406        fetch c_CMT into r_CMT ;
1407        --
1408        close c_CMT ;*/
1409        --
1410         l_update := false;
1411         l_process_date := p_effective_date;
1412         l_dml_operation:= r_CMT_unique.dml_operation ;
1413        --
1414        --
1415        l_CM_TYP_ID := get_fk('CM_TYP_ID', r_CMT.information237,l_dml_operation);
1416        l_CM_DLVRY_MTHD_TYP_CD := r_CMT.information11;
1417       --UPD START
1418       --
1419       if l_dml_operation = 'UPDATE' then
1420        --
1421                l_update := true;
1422                if r_CMT_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
1423                   nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'CM_DLVRY_MTHD_TYP_ID'  then
1424                   ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'CM_DLVRY_MTHD_TYP_ID' ;
1425                   ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_CMT_unique.information1 ;
1426                   ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := r_CMT_unique.information1 ;
1427                   ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
1428                   ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_CMT_unique.table_route_id;
1429                   --
1430                   -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ; -- NEW
1431                   --
1432                   ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
1433                   --
1434                   ben_pd_copy_to_ben_one.log_data('CMT',l_new_value,l_prefix || r_CMT_unique.name|| l_suffix,'REUSED');
1435                   --
1436                end if ;
1437                l_CM_DLVRY_MTHD_TYP_ID := r_CMT_unique.information1 ;
1438                l_object_version_number := r_CMT.information265 ;
1439                hr_utility.set_location( 'found record for update',10);
1440            --
1441         else
1442         --
1443              if p_reuse_object_flag = 'Y' then
1444                    -- cursor to find the object
1445                    open c_find_CMT_in_target( r_CMT_unique.information2,l_max_eed,
1446                                          p_target_business_group_id, nvl(l_cm_dlvry_mthd_typ_id, -999)  ) ;
1447                    fetch c_find_CMT_in_target into l_new_value ;
1448                    if c_find_CMT_in_target%found then
1449                      --
1450                      if r_CMT_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
1451                         nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'CM_DLVRY_MTHD_TYP_ID'  then
1452                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'CM_DLVRY_MTHD_TYP_ID' ;
1453                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_CMT_unique.information1 ;
1454                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
1455                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
1456                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_CMT_unique.table_route_id;
1457                         --
1458                         -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
1459                         --
1460                         ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
1461                      end if ;
1462                      --
1463                      l_object_found_in_target := true ;
1464                    end if;
1465                    close c_find_CMT_in_target ;
1466                  --
1467              end if ;
1468      --
1469 
1470      --
1471      -- UPD START
1472      end if; --if p_dml_operation
1473        --
1474      if not l_object_found_in_target OR l_update  then
1475      --if not l_object_found_in_target then
1476      -- UPD END
1477        --
1478        l_current_pk_id := r_CMT.information1;
1479        --
1480        hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
1481        hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
1482        --
1483        if l_current_pk_id =  l_prev_pk_id  then
1484          --
1485          l_first_rec := false ;
1486          --
1487        else
1488          --
1489          l_first_rec := true ;
1490          --
1491        end if ;
1492        --
1493        -- UPD START
1494        -- To avoid creating a child with out a parent
1495        --
1496        --
1497        if l_CM_TYP_ID is null then
1498           l_first_rec := false ;
1499        end if;
1500        --
1501        if l_first_rec and not l_update then
1502        --if l_first_rec then
1503        -- UPD END
1504 
1505          -- Call Create routine.
1506          hr_utility.set_location(' BEN_CM_DLVRY_MTHD_TYP CREATE_COMM_DLVRY_MTHDS ',20);
1507          BEN_COMM_DLVRY_MTHDS_API.CREATE_COMM_DLVRY_MTHDS(
1508              --
1509              P_VALIDATE               => false
1510              ,P_EFFECTIVE_DATE        => NVL(ben_pd_copy_to_ben_one.g_copy_effective_date ,p_effective_date)
1511              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
1512              --
1513              ,P_CMT_ATTRIBUTE1      => r_CMT.INFORMATION111
1514              ,P_CMT_ATTRIBUTE10      => r_CMT.INFORMATION120
1515              ,P_CMT_ATTRIBUTE11      => r_CMT.INFORMATION121
1516              ,P_CMT_ATTRIBUTE12      => r_CMT.INFORMATION122
1517              ,P_CMT_ATTRIBUTE13      => r_CMT.INFORMATION123
1518              ,P_CMT_ATTRIBUTE14      => r_CMT.INFORMATION124
1519              ,P_CMT_ATTRIBUTE15      => r_CMT.INFORMATION125
1520              ,P_CMT_ATTRIBUTE16      => r_CMT.INFORMATION126
1521              ,P_CMT_ATTRIBUTE17      => r_CMT.INFORMATION127
1522              ,P_CMT_ATTRIBUTE18      => r_CMT.INFORMATION128
1523              ,P_CMT_ATTRIBUTE19      => r_CMT.INFORMATION129
1524              ,P_CMT_ATTRIBUTE2      => r_CMT.INFORMATION112
1525              ,P_CMT_ATTRIBUTE20      => r_CMT.INFORMATION130
1526              ,P_CMT_ATTRIBUTE21      => r_CMT.INFORMATION131
1527              ,P_CMT_ATTRIBUTE22      => r_CMT.INFORMATION132
1528              ,P_CMT_ATTRIBUTE23      => r_CMT.INFORMATION133
1529              ,P_CMT_ATTRIBUTE24      => r_CMT.INFORMATION134
1530              ,P_CMT_ATTRIBUTE25      => r_CMT.INFORMATION135
1531              ,P_CMT_ATTRIBUTE26      => r_CMT.INFORMATION136
1532              ,P_CMT_ATTRIBUTE27      => r_CMT.INFORMATION137
1533              ,P_CMT_ATTRIBUTE28      => r_CMT.INFORMATION138
1534              ,P_CMT_ATTRIBUTE29      => r_CMT.INFORMATION139
1535              ,P_CMT_ATTRIBUTE3      => r_CMT.INFORMATION113
1536              ,P_CMT_ATTRIBUTE30      => r_CMT.INFORMATION140
1537              ,P_CMT_ATTRIBUTE4      => r_CMT.INFORMATION114
1538              ,P_CMT_ATTRIBUTE5      => r_CMT.INFORMATION115
1539              ,P_CMT_ATTRIBUTE6      => r_CMT.INFORMATION116
1540              ,P_CMT_ATTRIBUTE7      => r_CMT.INFORMATION117
1541              ,P_CMT_ATTRIBUTE8      => r_CMT.INFORMATION118
1542              ,P_CMT_ATTRIBUTE9      => r_CMT.INFORMATION119
1543              ,P_CMT_ATTRIBUTE_CATEGORY      => r_CMT.INFORMATION110
1544              ,P_CM_DLVRY_MTHD_TYP_CD      => r_CMT.INFORMATION11
1545              ,P_CM_DLVRY_MTHD_TYP_ID      => l_cm_dlvry_mthd_typ_id
1546              ,P_CM_TYP_ID      => l_CM_TYP_ID
1547              ,P_DFLT_FLAG      => r_CMT.INFORMATION12
1548              ,P_RQD_FLAG      => r_CMT.INFORMATION13
1549              --
1550              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
1551          );
1552          -- insert the table_name,old_pk_id,new_pk_id into a plsql record
1553          -- Update all relevent cer records with new pk_id
1554          hr_utility.set_location('Before plsql table ',222);
1555          hr_utility.set_location('new_value id '||l_cm_dlvry_mthd_typ_id,222);
1556          ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'CM_DLVRY_MTHD_TYP_ID' ;
1557          ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_CMT.information1 ;
1558          ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_CM_DLVRY_MTHD_TYP_ID ;
1559          ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
1560          ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_CMT_unique.table_route_id;
1561          hr_utility.set_location('After plsql table ',222);
1562          --
1563          -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
1564          --
1565          ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
1566          --
1567        elsif l_update then
1568          --
1569 
1570                   BEN_COMM_DLVRY_MTHDS_API.UPDATE_COMM_DLVRY_MTHDS(
1571                      --
1572                      P_VALIDATE               => false
1573                      ,P_EFFECTIVE_DATE        => l_effective_date
1574                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
1575                      --
1576                      ,P_CMT_ATTRIBUTE1      => r_CMT.INFORMATION111
1577                      ,P_CMT_ATTRIBUTE10      => r_CMT.INFORMATION120
1578                      ,P_CMT_ATTRIBUTE11      => r_CMT.INFORMATION121
1579                      ,P_CMT_ATTRIBUTE12      => r_CMT.INFORMATION122
1580                      ,P_CMT_ATTRIBUTE13      => r_CMT.INFORMATION123
1581                      ,P_CMT_ATTRIBUTE14      => r_CMT.INFORMATION124
1582                      ,P_CMT_ATTRIBUTE15      => r_CMT.INFORMATION125
1583                      ,P_CMT_ATTRIBUTE16      => r_CMT.INFORMATION126
1584                      ,P_CMT_ATTRIBUTE17      => r_CMT.INFORMATION127
1585                      ,P_CMT_ATTRIBUTE18      => r_CMT.INFORMATION128
1586                      ,P_CMT_ATTRIBUTE19      => r_CMT.INFORMATION129
1587                      ,P_CMT_ATTRIBUTE2      => r_CMT.INFORMATION112
1588                      ,P_CMT_ATTRIBUTE20      => r_CMT.INFORMATION130
1589                      ,P_CMT_ATTRIBUTE21      => r_CMT.INFORMATION131
1590                      ,P_CMT_ATTRIBUTE22      => r_CMT.INFORMATION132
1591                      ,P_CMT_ATTRIBUTE23      => r_CMT.INFORMATION133
1592                      ,P_CMT_ATTRIBUTE24      => r_CMT.INFORMATION134
1593                      ,P_CMT_ATTRIBUTE25      => r_CMT.INFORMATION135
1594                      ,P_CMT_ATTRIBUTE26      => r_CMT.INFORMATION136
1595                      ,P_CMT_ATTRIBUTE27      => r_CMT.INFORMATION137
1596                      ,P_CMT_ATTRIBUTE28      => r_CMT.INFORMATION138
1597                      ,P_CMT_ATTRIBUTE29      => r_CMT.INFORMATION139
1598                      ,P_CMT_ATTRIBUTE3      => r_CMT.INFORMATION113
1599                      ,P_CMT_ATTRIBUTE30      => r_CMT.INFORMATION140
1600                      ,P_CMT_ATTRIBUTE4      => r_CMT.INFORMATION114
1601                      ,P_CMT_ATTRIBUTE5      => r_CMT.INFORMATION115
1602                      ,P_CMT_ATTRIBUTE6      => r_CMT.INFORMATION116
1603                      ,P_CMT_ATTRIBUTE7      => r_CMT.INFORMATION117
1604                      ,P_CMT_ATTRIBUTE8      => r_CMT.INFORMATION118
1605                      ,P_CMT_ATTRIBUTE9      => r_CMT.INFORMATION119
1606                      ,P_CMT_ATTRIBUTE_CATEGORY      => r_CMT.INFORMATION110
1607                      ,P_CM_DLVRY_MTHD_TYP_CD      => r_CMT.INFORMATION11
1608                      ,P_CM_DLVRY_MTHD_TYP_ID      => l_cm_dlvry_mthd_typ_id
1609                      ,P_CM_TYP_ID      => l_CM_TYP_ID
1610                      ,P_DFLT_FLAG      => r_CMT.INFORMATION12
1611                      ,P_RQD_FLAG      => r_CMT.INFORMATION13
1612                      --
1613                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
1614                  );
1615 
1616          --
1617        end if;
1618        --
1619        l_prev_pk_id := l_current_pk_id ;
1620        --
1621      end if;
1622      --
1623    end loop;
1624    --
1625  end create_CMT_rows;
1626 
1627    --
1628    ---------------------------------------------------------------
1629    ----------------------< create_CMD_rows >-----------------------
1630    ---------------------------------------------------------------
1631    --
1632    procedure create_CMD_rows
1633    (
1634          p_validate                       in  number     default 0
1635         ,p_copy_entity_txn_id             in  number
1636         ,p_effective_date                 in  date
1637         ,p_prefix_suffix_text             in  varchar2  default null
1638         ,p_reuse_object_flag              in  varchar2  default null
1639         ,p_target_business_group_id       in  varchar2  default null
1640         ,p_prefix_suffix_cd               in  varchar2  default null
1641    ) is
1642    --
1643    l_CM_DLVRY_MTHD_TYP_ID  number;
1644    l_CM_DLVRY_MED_TYP_CD   varchar2(100);
1645    cursor c_unique_CMD(l_table_alias varchar2) is
1646    select distinct cpe.information1,
1647      cpe.information2,
1648      cpe.information3,
1649      cpe.information25 name, -- This needs to be derived from the api call below
1650      cpe.table_route_id,
1651      --UPD START
1652      cpe.dml_operation,
1653      cpe.datetrack_mode
1654      -- UPD END
1655    from ben_copy_entity_results cpe,
1656         pqh_table_route tr
1657    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
1658    and   cpe.table_route_id     = tr.table_route_id
1659    -- and   tr.where_clause        = l_BEN_CM_DLVRY_MED_TYP
1660    and   tr.table_alias = l_table_alias
1661    and   cpe.number_of_copies   = 1 -- ADDITION
1662    -- UPD START
1663    group by cpe.information1,cpe.information2,cpe.information3, cpe.information25, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
1664    order by information1, information2; --added for bug: 5151945
1665    -- UPD END
1666    --
1667    --
1668    cursor c_CMD_min_max_dates(c_table_route_id  number,
1669                 c_information1   number) is
1670    select
1671      min(cpe.information2) min_esd,
1672      max(cpe.information3) min_eed
1673    from ben_copy_entity_results cpe
1674    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
1675    and   cpe.table_route_id     = c_table_route_id
1676    and   cpe.information1       = c_information1 ;
1677    --
1678    cursor c_CMD(c_table_route_id  number,
1679                 c_information1   number,
1680                 c_information2   date,
1681                 c_information3   date)  is
1682    select
1683      cpe.*
1684    from ben_copy_entity_results cpe
1685    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
1686    and   cpe.table_route_id     = c_table_route_id
1687    and   cpe.information1       = c_information1
1688    and rownum = 1 ;
1689    -- Date Track target record
1690    cursor c_find_CMD_in_target(
1691                                 c_effective_start_date    date,
1692                                 c_effective_end_date      date,
1693                                 c_business_group_id       number,
1694                                 c_new_pk_id               number) is
1695    select
1696      CMD.cm_dlvry_med_typ_id new_value
1697    from BEN_CM_DLVRY_MED_TYP CMD
1698    where
1699    CMD.CM_DLVRY_MTHD_TYP_ID     = l_CM_DLVRY_MTHD_TYP_ID
1700    and CMD.CM_DLVRY_MED_TYP_CD  = l_CM_DLVRY_MED_TYP_CD
1701    and CMD.business_group_id  = c_business_group_id
1702    and   CMD.cm_dlvry_med_typ_id  <> c_new_pk_id;
1703 
1704    --UPD START
1705    --
1706    l_update                  boolean      := false ;
1707    l_datetrack_mode          varchar2(80) := hr_api.g_update;
1708    l_process_date            date;
1709    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
1710    --
1711    --UPD END
1712 
1713    --
1714    l_current_pk_id           number := null ;
1715    l_prev_pk_id              number := null ;
1716    l_first_rec               boolean := true ;
1717    r_CMD                     c_CMD%rowtype;
1718    l_cm_dlvry_med_typ_id             number ;
1719    l_object_version_number   number ;
1720    l_effective_start_date    date ;
1721    l_effective_end_date      date ;
1722    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
1723    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
1724    l_new_value               number(15);
1725    l_object_found_in_target  boolean := false ;
1726    l_min_esd                 date;
1727    l_max_eed                 date;
1728    l_effective_date          date;
1729    --
1730  begin
1731    -- Initialization
1732    l_object_found_in_target := false ;
1733    -- End Initialization
1734    -- Derive the prefix - sufix
1735    if   p_prefix_suffix_cd = 'PREFIX' then
1736      l_prefix  := p_prefix_suffix_text ;
1737    elsif p_prefix_suffix_cd = 'SUFFIX' then
1738      l_suffix   := p_prefix_suffix_text ;
1739    else
1740      l_prefix := null ;
1741      l_suffix  := null ;
1742    end if ;
1743    -- End Prefix Sufix derivation
1744    for r_CMD_unique in c_unique_CMD('CMD') loop
1745      --
1746      hr_utility.set_location(' r_CMD_unique.table_route_id '||r_CMD_unique.table_route_id,10);
1747      hr_utility.set_location(' r_CMD_unique.information1 '||r_CMD_unique.information1,10);
1748      hr_utility.set_location( 'r_CMD_unique.information2 '||r_CMD_unique.information2,10);
1749      hr_utility.set_location( 'r_CMD_unique.information3 '||r_CMD_unique.information3,10);
1750      -- If reuse objects flag is 'Y' then check for the object in the target business group
1751      -- if found insert the record into PLSql table and exit the loop else try create the
1752      -- object in the target business group
1753      --
1754      l_object_found_in_target := false ;
1755      --
1756      open c_CMD(r_CMD_unique.table_route_id,
1757                 r_CMD_unique.information1,
1758                 r_CMD_unique.information2,
1759                 r_CMD_unique.information3 ) ;
1760      --
1761      fetch c_CMD into r_CMD ;
1762      --
1763      close c_CMD ;
1764      --
1765 
1766              l_min_esd := null ;
1767              l_max_eed := null ;
1768                --
1769               /* open c_CMD(r_CMD_unique.table_route_id,
1770                         r_CMD_unique.information1,
1771                         r_CMD_unique.information2,
1772                         r_CMD_unique.information3 ) ;
1773                --
1774                fetch c_CMD into r_CMD ;
1775                --
1776                close c_CMD ;*/
1777                 --UPD START
1778                l_update := false;
1779                l_process_date := p_effective_date;
1780                l_dml_operation:= r_CMD_unique.dml_operation ;
1781        --
1782                --
1783                l_CM_DLVRY_MTHD_TYP_ID := get_fk('CM_DLVRY_MTHD_TYP_ID', r_CMD.information257,l_dml_operation);
1784                l_CM_DLVRY_MED_TYP_CD  := r_CMD.information11;
1785 
1786               if l_dml_operation = 'UPDATE' then
1787               --
1788                  l_object_found_in_target := TRUE;
1789                  --
1790                  if l_process_date between r_CMD_unique.information2 and r_CMD_unique.information3 then
1791                        l_update := true;
1792                        if r_CMD_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
1793                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'CM_DLVRY_MED_TYP_ID'
1794                        then
1795                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'CM_DLVRY_MED_TYP_ID' ;
1796                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_CMD_unique.information1 ;
1797                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_CMD_unique.information1 ;
1798                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
1799                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_CMD_unique.table_route_id;
1800                           --
1801                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
1802                           --
1803                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
1804                           --
1805                           BEN_PD_COPY_TO_BEN_ONE.log_data('CMD',l_new_value,l_prefix || r_CMD_unique.name|| l_suffix,'REUSED');
1806                           --
1807                        end if ;
1808                        hr_utility.set_location( 'found record for update',10);
1809                    --
1810                  else
1811                    --
1812                    l_update := false;
1813                    --
1814                  end if;
1815              else
1816              if p_reuse_object_flag = 'Y' then
1817                    -- cursor to find the object
1818                    open c_find_CMD_in_target( r_CMD_unique.information2,l_max_eed,
1819                                          p_target_business_group_id, nvl(l_cm_dlvry_med_typ_id, -999)  ) ;
1820                    fetch c_find_CMD_in_target into l_new_value ;
1821                    if c_find_CMD_in_target%found then
1822                                  --
1823                                  if r_CMD_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
1824                                         nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'CM_DLVRY_MED_TYP_ID'  then
1825                                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'CM_DLVRY_MED_TYP_ID' ;
1826                                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_CMD_unique.information1 ;
1827                                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
1828                                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
1829                                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_CMD_unique.table_route_id;
1830                                         --
1831                                         -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
1832                                         --
1833                                         ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
1834                                  end if ;
1835                                  --
1836                                  l_object_found_in_target := true ;
1837                    end if;
1838                    close c_find_CMD_in_target ;
1839                  --
1840              end if ;
1841      -- UPD START
1842      --
1843      end if; --if p_dml_operation
1844        --
1845      if not l_object_found_in_target OR l_update  then
1846      -- UPD END
1847 
1848      --if not l_object_found_in_target then
1849        --
1850        l_current_pk_id := r_CMD.information1;
1851        --
1852        hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
1853        hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
1854        --
1855        if l_current_pk_id =  l_prev_pk_id  then
1856          --
1857          l_first_rec := false ;
1858          --
1859        else
1860          --
1861          l_first_rec := true ;
1862          --
1863        end if ;
1864        --
1865        -- UPD START
1866        --if l_first_rec then
1867        if l_first_rec and not l_update then
1868        -- UPD END
1869 
1870          -- Call Create routine.
1871          hr_utility.set_location(' BEN_CM_DLVRY_MED_TYP CREATE_COMM_DLVRY_MEDIA ',20);
1872          BEN_COMM_DLVRY_MEDIA_API.CREATE_COMM_DLVRY_MEDIA(
1873              --
1874              P_VALIDATE               => false
1875              ,P_EFFECTIVE_DATE        => NVL(ben_pd_copy_to_ben_one.g_copy_effective_date ,p_effective_date)
1876              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
1877              --
1878              ,P_CMD_ATTRIBUTE1      => r_CMD.INFORMATION111
1879              ,P_CMD_ATTRIBUTE10      => r_CMD.INFORMATION120
1880              ,P_CMD_ATTRIBUTE11      => r_CMD.INFORMATION121
1881              ,P_CMD_ATTRIBUTE12      => r_CMD.INFORMATION122
1882              ,P_CMD_ATTRIBUTE13      => r_CMD.INFORMATION123
1883              ,P_CMD_ATTRIBUTE14      => r_CMD.INFORMATION124
1884              ,P_CMD_ATTRIBUTE15      => r_CMD.INFORMATION125
1885              ,P_CMD_ATTRIBUTE16      => r_CMD.INFORMATION126
1886              ,P_CMD_ATTRIBUTE17      => r_CMD.INFORMATION127
1887              ,P_CMD_ATTRIBUTE18      => r_CMD.INFORMATION128
1888              ,P_CMD_ATTRIBUTE19      => r_CMD.INFORMATION129
1889              ,P_CMD_ATTRIBUTE2      => r_CMD.INFORMATION112
1890              ,P_CMD_ATTRIBUTE20      => r_CMD.INFORMATION130
1891              ,P_CMD_ATTRIBUTE21      => r_CMD.INFORMATION131
1892              ,P_CMD_ATTRIBUTE22      => r_CMD.INFORMATION132
1893              ,P_CMD_ATTRIBUTE23      => r_CMD.INFORMATION133
1894              ,P_CMD_ATTRIBUTE24      => r_CMD.INFORMATION134
1895              ,P_CMD_ATTRIBUTE25      => r_CMD.INFORMATION135
1896              ,P_CMD_ATTRIBUTE26      => r_CMD.INFORMATION136
1897              ,P_CMD_ATTRIBUTE27      => r_CMD.INFORMATION137
1898              ,P_CMD_ATTRIBUTE28      => r_CMD.INFORMATION138
1899              ,P_CMD_ATTRIBUTE29      => r_CMD.INFORMATION139
1900              ,P_CMD_ATTRIBUTE3      => r_CMD.INFORMATION113
1901              ,P_CMD_ATTRIBUTE30      => r_CMD.INFORMATION140
1902              ,P_CMD_ATTRIBUTE4      => r_CMD.INFORMATION114
1903              ,P_CMD_ATTRIBUTE5      => r_CMD.INFORMATION115
1904              ,P_CMD_ATTRIBUTE6      => r_CMD.INFORMATION116
1905              ,P_CMD_ATTRIBUTE7      => r_CMD.INFORMATION117
1906              ,P_CMD_ATTRIBUTE8      => r_CMD.INFORMATION118
1907              ,P_CMD_ATTRIBUTE9      => r_CMD.INFORMATION119
1908              ,P_CMD_ATTRIBUTE_CATEGORY      => r_CMD.INFORMATION110
1909              ,P_CM_DLVRY_MED_TYP_CD      => r_CMD.INFORMATION11
1910              ,P_CM_DLVRY_MED_TYP_ID      => l_cm_dlvry_med_typ_id
1911              ,P_CM_DLVRY_MTHD_TYP_ID      => l_CM_DLVRY_MTHD_TYP_ID
1912              ,P_DFLT_FLAG      => r_CMD.INFORMATION13
1913              ,P_RQD_FLAG      => r_CMD.INFORMATION12
1914              --
1915              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
1916          );
1917          -- insert the table_name,old_pk_id,new_pk_id into a plsql record
1918          -- Update all relevent cer records with new pk_id
1919          hr_utility.set_location('Before plsql table ',222);
1920          hr_utility.set_location('new_value id '||l_cm_dlvry_med_typ_id,222);
1921          ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'CM_DLVRY_MED_TYP_ID' ;
1922          ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_CMD.information1 ;
1923          ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_CM_DLVRY_MED_TYP_ID ;
1924          ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
1925          ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_CMD_unique.table_route_id;
1926          hr_utility.set_location('After plsql table ',222);
1927          --
1928          -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
1929          --
1930          ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
1931          --
1932          elsif l_update then
1933          --
1934          -- UPD START
1935           hr_utility.set_location(' BEN_CM_DLVRY_MED_TYP CREATE_COMM_DLVRY_MEDIA ',20);
1936          BEN_COMM_DLVRY_MEDIA_API.UPDATE_COMM_DLVRY_MEDIA(
1937              --
1938              P_VALIDATE               => false
1939              ,P_EFFECTIVE_DATE        => NVL(ben_pd_copy_to_ben_one.g_copy_effective_date ,p_effective_date)
1940              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
1941              --
1942              ,P_CMD_ATTRIBUTE1      => r_CMD.INFORMATION111
1943              ,P_CMD_ATTRIBUTE10      => r_CMD.INFORMATION120
1944              ,P_CMD_ATTRIBUTE11      => r_CMD.INFORMATION121
1945              ,P_CMD_ATTRIBUTE12      => r_CMD.INFORMATION122
1946              ,P_CMD_ATTRIBUTE13      => r_CMD.INFORMATION123
1947              ,P_CMD_ATTRIBUTE14      => r_CMD.INFORMATION124
1948              ,P_CMD_ATTRIBUTE15      => r_CMD.INFORMATION125
1949              ,P_CMD_ATTRIBUTE16      => r_CMD.INFORMATION126
1950              ,P_CMD_ATTRIBUTE17      => r_CMD.INFORMATION127
1951              ,P_CMD_ATTRIBUTE18      => r_CMD.INFORMATION128
1952              ,P_CMD_ATTRIBUTE19      => r_CMD.INFORMATION129
1953              ,P_CMD_ATTRIBUTE2      => r_CMD.INFORMATION112
1954              ,P_CMD_ATTRIBUTE20      => r_CMD.INFORMATION130
1955              ,P_CMD_ATTRIBUTE21      => r_CMD.INFORMATION131
1956              ,P_CMD_ATTRIBUTE22      => r_CMD.INFORMATION132
1957              ,P_CMD_ATTRIBUTE23      => r_CMD.INFORMATION133
1958              ,P_CMD_ATTRIBUTE24      => r_CMD.INFORMATION134
1959              ,P_CMD_ATTRIBUTE25      => r_CMD.INFORMATION135
1960              ,P_CMD_ATTRIBUTE26      => r_CMD.INFORMATION136
1961              ,P_CMD_ATTRIBUTE27      => r_CMD.INFORMATION137
1962              ,P_CMD_ATTRIBUTE28      => r_CMD.INFORMATION138
1963              ,P_CMD_ATTRIBUTE29      => r_CMD.INFORMATION139
1964              ,P_CMD_ATTRIBUTE3      => r_CMD.INFORMATION113
1965              ,P_CMD_ATTRIBUTE30      => r_CMD.INFORMATION140
1966              ,P_CMD_ATTRIBUTE4      => r_CMD.INFORMATION114
1967              ,P_CMD_ATTRIBUTE5      => r_CMD.INFORMATION115
1968              ,P_CMD_ATTRIBUTE6      => r_CMD.INFORMATION116
1969              ,P_CMD_ATTRIBUTE7      => r_CMD.INFORMATION117
1970              ,P_CMD_ATTRIBUTE8      => r_CMD.INFORMATION118
1971              ,P_CMD_ATTRIBUTE9      => r_CMD.INFORMATION119
1972              ,P_CMD_ATTRIBUTE_CATEGORY      => r_CMD.INFORMATION110
1973              ,P_CM_DLVRY_MED_TYP_CD      => r_CMD.INFORMATION11
1974              ,P_CM_DLVRY_MED_TYP_ID      => l_cm_dlvry_med_typ_id
1975              ,P_CM_DLVRY_MTHD_TYP_ID      => l_CM_DLVRY_MTHD_TYP_ID
1976              ,P_DFLT_FLAG      => r_CMD.INFORMATION13
1977              ,P_RQD_FLAG      => r_CMD.INFORMATION12
1978              --
1979              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
1980          );
1981 
1982          -- UPD END
1983          --
1984        end if;
1985        --
1986        l_prev_pk_id := l_current_pk_id ;
1987        --
1988      end if;
1989      --
1990    end loop;
1991    --
1992  end create_CMD_rows;
1993  --
1994  procedure build_abr_hierarchy
1995    ( p_copy_entity_txn_id             in  number )
1996    is
1997      --
1998      -- Bug : 3752407 : Global cursor ben_plan_design_program_module.g_table_route will now be used
1999      --
2000      -- cursor c_table_route is
2001      -- select table_route_id
2002      -- from pqh_table_route
2003      -- where from_clause = 'OAB' and
2004      -- table_alias = 'ABR' ;
2005      --
2006      --
2007      -- Changed to workaround db bug 3165930
2008      --
2009      cursor c_hierarchy(v_cet_id number, v_tr_id number)  is
2010      select distinct rate, Parent_rate
2011      from (select information1 rate ,information267 parent_rate
2012            from  ben_copy_entity_results cpe
2013            where table_route_id = v_tr_id
2014              and copy_entity_txn_id = v_cet_id)
2015      start with Parent_rate is null
2016      connect by Parent_rate = prior rate
2017      order by 2 desc, rate;
2018      /*
2019      select distinct information1 rate,
2020             information267  Parent_rate
2021      from  ben_copy_entity_results cpe
2022      where table_route_id = v_tr_id
2023      and copy_entity_txn_id = v_cet_id
2024      start with information267 is null and
2025            table_route_id = v_tr_id and
2026            copy_entity_txn_id = v_cet_id
2027      connect by cpe.information267 = prior cpe.information1
2028      order by  information267 desc , information1 ;
2029      */
2030      --
2031      l_table_route_id         number ;
2032      l_counter                number := 1 ;
2033      --
2034    begin
2035      --
2036      open ben_plan_design_program_module.g_table_route('ABR')  ;
2037        fetch ben_plan_design_program_module.g_table_route into l_table_route_id ;
2038      close ben_plan_design_program_module.g_table_route  ;
2039      --
2040      for i in c_hierarchy(p_copy_entity_txn_id,l_table_route_id) loop
2041        --
2042        update ben_copy_entity_results cpe
2043          set information169 = l_counter
2044        where cpe.copy_entity_txn_id = p_copy_entity_txn_id
2045        and   cpe.information1 = i.rate
2046        and   cpe.table_route_id = l_table_route_id ;
2047        --
2048        l_counter := l_counter + 1 ;
2049        --
2050      end loop ;
2051      --
2052    end build_abr_hierarchy;
2053    --
2054    ---------------------------------------------------------------
2055    ----------------------< create_ABR_rows >-----------------------
2056    ---------------------------------------------------------------
2057    --
2058    procedure create_ABR_rows
2059    (
2060          p_validate                       in  number     default 0
2061         ,p_copy_entity_txn_id             in  number
2062         ,p_effective_date                 in  date
2063         ,p_prefix_suffix_text             in  varchar2  default null
2064         ,p_reuse_object_flag              in  varchar2  default null
2065         ,p_target_business_group_id       in  varchar2  default null
2066         ,p_prefix_suffix_cd               in  varchar2  default null
2067    ) is
2068    --
2069    l_ACTL_PREM_ID  number;
2070    l_CLM_COMP_LVL_FCTR_ID  number;
2071    l_CMBN_PLIP_ID  number;
2072    l_CMBN_PTIP_ID  number;
2073    l_CMBN_PTIP_OPT_ID  number;
2074    l_COMP_LVL_FCTR_ID  number;
2075    l_COST_ALLOCATION_KEYFLEX_ID  number;
2076    l_ELEMENT_TYPE_ID  number;
2077    l_INPUT_VALUE_ID  number;
2078    l_LWR_LMT_CALC_RL  number;
2079    l_OIPLIP_ID  number;
2080    l_OIPL_ID  number;
2081    l_PARNT_ACTY_BASE_RT_ID  number;
2082    l_PGM_ID  number;
2083    l_PLIP_ID  number;
2084    l_PL_ID  number;
2085    l_PRORT_MN_ANN_ELCN_VAL_RL  number;
2086    l_PRORT_MX_ANN_ELCN_VAL_RL  number;
2087    l_MN_MX_ELCN_RL             number;
2088    l_RATE_PERIODIZATION_RL     number;
2089    l_PRTL_MO_DET_MTHD_RL  number;
2090    l_PRTL_MO_EFF_DT_DET_RL  number;
2091    l_PTD_COMP_LVL_FCTR_ID  number;
2092    l_PTIP_ID  number;
2093    l_RNDG_RL  number;
2094    l_TTL_COMP_LVL_FCTR_ID  number;
2095    l_UPR_LMT_CALC_RL  number;
2096    l_VAL_CALC_RL  number;
2097    l_INPUT_VA_CALC_RL number;
2098    l_VSTG_FOR_ACTY_RT_ID  number;
2099    --
2100    l_PAY_RATE_GRADE_RULE_ID number;
2101    l_OPT_ID               number;
2102    l_ELEMENT_DET_RL    number;
2103    --
2104    cursor c_unique_ABR(l_table_alias varchar2) is
2105    select distinct cpe.information1,
2106      cpe.information2,
2107      cpe.information3,
2108      cpe.information170 name,
2109      cpe.table_route_id,
2110      cpe.information169,
2111      cpe.dml_operation,
2112      cpe.datetrack_mode
2113    from ben_copy_entity_results cpe,
2114         pqh_table_route tr
2115    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
2116    and   cpe.table_route_id     = tr.table_route_id
2117    -- and   tr.where_clause        = l_BEN_ACTY_BASE_RT_F
2118    and   tr.table_alias = l_table_alias
2119    and   cpe.number_of_copies   = 1 -- ADDITION
2120    group by cpe.information169, cpe.information1, cpe.information2, cpe.information3,
2121             cpe.information170, cpe.table_route_id ,cpe.dml_operation, cpe.datetrack_mode
2122    order by NVL(cpe.information169, -1), cpe.information1, cpe.information2; -- 4641690
2123 
2124    --
2125    --
2126    cursor c_ABR_min_max_dates(c_table_route_id  number,
2127                 c_information1   number) is
2128    select
2129      min(cpe.information2) min_esd,
2130      max(cpe.information3) min_eed
2131    from ben_copy_entity_results cpe
2132    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
2133    And   cpe.table_route_id     = c_table_route_id
2134    and   cpe.information1       = c_information1 ;
2135    --
2136    cursor c_ABR(c_table_route_id  number,
2137                 c_information1   number,
2138                 c_information2   date,
2139                 c_information3   date)  is
2140    select
2141      cpe.*
2142    from ben_copy_entity_results cpe
2143    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
2144    and   cpe.table_route_id     = c_table_route_id
2145    and   cpe.information1       = c_information1
2146    and   cpe.information2       = c_information2
2147    and   cpe.information3       = c_information3
2148    and rownum = 1 ;
2149    -- Date Track target record
2150    cursor c_find_ABR_in_target( c_ABR_name           varchar2,
2151                                 c_effective_start_date    date,
2152                                 c_effective_end_date      date,
2153                                 c_business_group_id       number,
2154                                 c_new_pk_id               number) is
2155    select
2156      ABR.acty_base_rt_id new_value
2157    from BEN_ACTY_BASE_RT_F ABR
2158    where  ABR.name               = c_ABR_name and
2159    nvl(ABR.CMBN_PLIP_ID,-999)     = nvl(l_CMBN_PLIP_ID,-999)  and
2160    nvl(ABR.CMBN_PTIP_ID,-999)     = nvl(l_CMBN_PTIP_ID,-999)  and
2161    nvl(ABR.CMBN_PTIP_OPT_ID,-999)     = nvl(l_CMBN_PTIP_OPT_ID,-999)  and
2162    nvl(ABR.OIPLIP_ID,-999)     = nvl(l_OIPLIP_ID,-999)  and
2163    nvl(ABR.OIPL_ID,-999)     = nvl(l_OIPL_ID,-999)  and
2164    nvl(ABR.PGM_ID,-999)     = nvl(l_PGM_ID,-999)  and
2165    nvl(ABR.PLIP_ID,-999)     = nvl(l_PLIP_ID,-999)  and
2166    nvl(ABR.PL_ID,-999)     = nvl(l_PL_ID,-999)  and
2167    nvl(ABR.PTIP_ID,-999)     = nvl(l_PTIP_ID,-999)  and
2168    --
2169    nvl(ABR.OPT_ID,-999)      = nvl(l_OPT_ID,-999) and
2170    --
2171    ABR.business_group_id  = c_business_group_id
2172    and   ABR.acty_base_rt_id  <> c_new_pk_id
2173 --TEMPIK
2174    and c_effective_start_date between effective_start_date
2175                             and effective_end_date ;
2176 --END TEMPIK
2177 /*TEMPIK
2178    and exists ( select null
2179                 from BEN_ACTY_BASE_RT_F ABR1
2180                 where ABR1.name               = c_ABR_name and
2181                 nvl(ABR1.CMBN_PLIP_ID,-999)     = nvl(l_CMBN_PLIP_ID,-999)  and
2182                 nvl(ABR1.CMBN_PTIP_ID,-999)     = nvl(l_CMBN_PTIP_ID,-999)  and
2183                 nvl(ABR1.CMBN_PTIP_OPT_ID,-999)     = nvl(l_CMBN_PTIP_OPT_ID,-999)  and
2184                 nvl(ABR1.OIPLIP_ID,-999)     = nvl(l_OIPLIP_ID,-999)  and
2185                 nvl(ABR1.OIPL_ID,-999)     = nvl(l_OIPL_ID,-999)  and
2186                 nvl(ABR1.OPT_ID,-999)      = nvl(l_OPT_ID,-999) and
2187                 nvl(ABR1.PGM_ID,-999)     = nvl(l_PGM_ID,-999)  and
2188                 nvl(ABR1.PLIP_ID,-999)     = nvl(l_PLIP_ID,-999)  and
2189                 nvl(ABR1.PL_ID,-999)     = nvl(l_PL_ID,-999)  and
2190                 nvl(ABR1.PTIP_ID,-999)     = nvl(l_PTIP_ID,-999)  and
2191                 ABR1.business_group_id  = c_business_group_id
2192                 and   ABR1.effective_start_date <= c_effective_start_date )
2193    and exists ( select null
2194                 from BEN_ACTY_BASE_RT_F ABR2
2195                 where ABR2.name               = c_ABR_name and
2196                 nvl(ABR2.CMBN_PLIP_ID,-999)     = nvl(l_CMBN_PLIP_ID,-999)  and
2197                 nvl(ABR2.CMBN_PTIP_ID,-999)     = nvl(l_CMBN_PTIP_ID,-999)  and
2198                 nvl(ABR2.CMBN_PTIP_OPT_ID,-999)     = nvl(l_CMBN_PTIP_OPT_ID,-999)  and
2199                 nvl(ABR2.OIPLIP_ID,-999)     = nvl(l_OIPLIP_ID,-999)  and
2200                 nvl(ABR2.OIPL_ID,-999)     = nvl(l_OIPL_ID,-999)  and
2201                 nvl(ABR2.OPT_ID,-999)      = nvl(l_OPT_ID,-999) and
2202                 nvl(ABR2.PGM_ID,-999)     = nvl(l_PGM_ID,-999)  and
2203                 nvl(ABR2.PLIP_ID,-999)     = nvl(l_PLIP_ID,-999)  and
2204                 nvl(ABR2.PL_ID,-999)     = nvl(l_PL_ID,-999)  and
2205                 nvl(ABR2.PTIP_ID,-999)     = nvl(l_PTIP_ID,-999)  and
2206                 ABR2.business_group_id  = c_business_group_id
2207                 and   ABR2.effective_end_date >= c_effective_end_date )
2208                 ;
2209 TEMPIK */
2210    -- Date Track target record
2211    cursor c_find_ABR_name_in_target( c_ABR_name           varchar2,
2212                                 c_effective_start_date    date,
2213                                 c_effective_end_date      date,
2214                                 c_business_group_id       number,
2215                                 c_new_pk_id               number) is
2216    select
2217      ABR.acty_base_rt_id new_value
2218    from BEN_ACTY_BASE_RT_F ABR
2219    where  ABR.name               = c_ABR_name and
2220    ABR.business_group_id  = c_business_group_id
2221    and   ABR.acty_base_rt_id  <> c_new_pk_id
2222 --TEMPIK
2223    and c_effective_start_date between effective_start_date
2224                             and effective_end_date ;
2225 --END TEMPIK
2226 /*TEMPIK
2227    and exists ( select null
2228                 from BEN_ACTY_BASE_RT_F ABR1
2229                 where ABR1.name               = c_ABR_name and
2230                 ABR1.business_group_id  = c_business_group_id
2231                 and   ABR1.effective_start_date <= c_effective_start_date )
2232    and exists ( select null
2233                 from BEN_ACTY_BASE_RT_F ABR2
2234                 where ABR2.name               = c_ABR_name and
2235                 ABR2.business_group_id  = c_business_group_id
2236                 and   ABR2.effective_end_date >= c_effective_end_date )
2237                 ;
2238 TEMPIK */
2239    --TEMPIK
2240    l_dt_rec_found            boolean ;
2241    --END TEMPIK
2242 
2243    --UPD START
2244    --
2245    l_update                  boolean      := false ;
2246    l_datetrack_mode          varchar2(80) := hr_api.g_update;
2247    l_process_date            date;
2248    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
2249    --
2250    --UPD END
2251 
2252    --
2253    l_current_pk_id           number := null ;
2254    l_prev_pk_id              number := null ;
2255    l_first_rec               boolean := true ;
2256    r_ABR                     c_ABR%rowtype;
2257    l_acty_base_rt_id             number ;
2258    l_object_version_number   number ;
2259    l_effective_start_date    date ;
2260    l_effective_end_date      date ;
2261    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
2262    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
2263    l_new_value               number(15);
2264    l_object_found_in_target  boolean := false ;
2265    l_min_esd                 date;
2266    l_max_eed                 date;
2267    l_cmbn_flag               boolean := true ;
2268    --
2269    l_message                 varchar2(2000);
2270    l_effective_date          date;
2271  begin
2272    -- Initialization
2273    l_object_found_in_target := false ;
2274    -- End Initialization
2275    -- Derive the prefix - sufix
2276    -- End Prefix Sufix derivation
2277    for r_ABR_unique in c_unique_ABR('ABR') loop
2278 
2279      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
2280         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
2281          r_ABR_unique.information3 >=
2282                  ben_pd_copy_to_ben_one.g_copy_effective_date)
2283         ) then
2284        --
2285        if   p_prefix_suffix_cd = 'PREFIX' then
2286          l_prefix  := p_prefix_suffix_text ;
2287        elsif p_prefix_suffix_cd = 'SUFFIX' then
2288          l_suffix   := p_prefix_suffix_text ;
2289        else
2290          l_prefix := null ;
2291          l_suffix  := null ;
2292        end if ;
2293        --
2294        hr_utility.set_location(' r_ABR_unique.table_route_id '||r_ABR_unique.table_route_id,10);
2295        hr_utility.set_location(' r_ABR_unique.information1 '||r_ABR_unique.information1,10);
2296        hr_utility.set_location( 'r_ABR_unique.information2 '||r_ABR_unique.information2,10);
2297        hr_utility.set_location( 'r_ABR_unique.information3 '||r_ABR_unique.information3,10);
2298        -- If reuse objects flag is 'Y' then check for the object in the target business group
2299        -- if found insert the record into PLSql table and exit the loop else try create the
2300        -- object in the target business group
2301        --
2302        l_object_found_in_target := false ;
2303 
2304        --UPD START
2305        l_update := false;
2306        l_process_date := p_effective_date;
2307        l_dml_operation:= r_ABR_unique.dml_operation ;
2308 
2309        -- UPD START
2310        open c_ABR(r_ABR_unique.table_route_id,
2311                 r_ABR_unique.information1,
2312                 r_ABR_unique.information2,
2313                 r_ABR_unique.information3 ) ;
2314        --
2315        fetch c_ABR into r_ABR ;
2316        --
2317        close c_ABR ;
2318        --
2319        l_ACTL_PREM_ID := get_fk('ACTL_PREM_ID' ,  r_ABR.information250,r_ABR.dml_operation);
2320        l_CLM_COMP_LVL_FCTR_ID := get_fk('COMP_LVL_FCTR_ID' ,  r_ABR.information273,r_ABR.dml_operation);
2321        l_CMBN_PLIP_ID := get_fk('CMBN_PLIP_ID' ,  r_ABR.information239,r_ABR.dml_operation);
2322        l_CMBN_PTIP_ID := get_fk('CMBN_PTIP_ID' ,  r_ABR.information236,r_ABR.dml_operation);
2323        l_CMBN_PTIP_OPT_ID := get_fk('CMBN_PTIP_OPT_ID' ,  r_ABR.information249,r_ABR.dml_operation);
2324        l_COMP_LVL_FCTR_ID := get_fk('COMP_LVL_FCTR_ID' ,  r_ABR.information254,r_ABR.dml_operation);
2325        l_COST_ALLOCATION_KEYFLEX_ID := get_fk('COST_ALLOCATION_KEYFLEX_ID', r_ABR.information262,r_ABR.dml_operation);
2326        --
2327        l_OPT_ID                     := get_fk('OPT_ID',r_ABR.information247,r_ABR.dml_operation);
2328                l_LWR_LMT_CALC_RL := get_fk('FORMULA_ID', r_ABR.information268,r_ABR.dml_operation);
2329                l_OIPLIP_ID := get_fk('OIPLIP_ID', r_ABR.information227,r_ABR.dml_operation);
2330                l_OIPL_ID := get_fk('OIPL_ID', r_ABR.information258,r_ABR.dml_operation);
2331                l_PARNT_ACTY_BASE_RT_ID := get_fk('ACTY_BASE_RT_ID', r_ABR.information267,r_ABR.dml_operation);
2332                l_PGM_ID := get_fk('PGM_ID', r_ABR.information260,r_ABR.dml_operation);
2333                l_PLIP_ID := get_fk('PLIP_ID', r_ABR.information256);
2334                l_PL_ID := get_fk('PL_ID', r_ABR.information261,r_ABR.dml_operation);
2335 
2336                l_PAY_RATE_GRADE_RULE_ID := get_fk('PAY_RATE_GRADE_RULE_ID', r_ABR.INFORMATION266,r_ABR.dml_operation);
2337                    /*added during plan copy package changes*/
2338                -- l_OPT_ID := get_fk('OPT_ID', r_ABR.Not found);
2339                    /*using correction file generated by script*/
2340                l_PRORT_MN_ANN_ELCN_VAL_RL := get_fk('FORMULA_ID', r_ABR.information274,r_ABR.dml_operation);
2341                l_PRORT_MX_ANN_ELCN_VAL_RL := get_fk('FORMULA_ID', r_ABR.information275,r_ABR.dml_operation);
2342                l_PRTL_MO_DET_MTHD_RL := get_fk('FORMULA_ID', r_ABR.information281,r_ABR.dml_operation);
2343                l_PRTL_MO_EFF_DT_DET_RL := get_fk('FORMULA_ID', r_ABR.information280,r_ABR.dml_operation);
2344                l_PTD_COMP_LVL_FCTR_ID := get_fk('COMP_LVL_FCTR_ID', r_ABR.information272,r_ABR.dml_operation);
2345                l_PTIP_ID := get_fk('PTIP_ID', r_ABR.information259,r_ABR.dml_operation);
2346                l_RNDG_RL := get_fk('FORMULA_ID', r_ABR.information279,r_ABR.dml_operation);
2347                l_TTL_COMP_LVL_FCTR_ID := get_fk('COMP_LVL_FCTR_ID', r_ABR.information257);
2348                l_UPR_LMT_CALC_RL := get_fk('FORMULA_ID', r_ABR.information269,r_ABR.dml_operation);
2349                l_VAL_CALC_RL := get_fk('FORMULA_ID', r_ABR.information282,r_ABR.dml_operation);
2350                l_INPUT_VA_CALC_RL := get_fk('FORMULA_ID', r_ABR.information263,r_ABR.dml_operation);
2351                l_VSTG_FOR_ACTY_RT_ID := get_fk('VSTG_FOR_ACTY_RT_ID', r_ABR.information271,r_ABR.dml_operation);
2352                l_MN_MX_ELCN_RL := get_fk('FORMULA_ID', r_ABR.information285,r_ABR.dml_operation);
2353                l_RATE_PERIODIZATION_RL := get_fk('FORMULA_ID', r_ABR.information286,r_ABR.dml_operation);
2354 	       l_ELEMENT_DET_RL := get_fk('FORMULA_ID', r_ABR.information287,r_ABR.dml_operation);
2355 
2356                -- l_ELEMENT_TYPE_ID := get_fk('ELEMENT_TYPE_ID',r_ABR.information174,r_ABR.dml_operation);
2357                -- l_INPUT_VALUE_ID :=  get_fk('INPUT_VALUE_ID',r_ABR.information178,r_ABR.dml_operation);
2358 
2359                if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
2360                  l_ELEMENT_TYPE_ID := r_ABR.information176;
2361                  l_INPUT_VALUE_ID  := r_ABR.information180;
2362                else
2363                  l_ELEMENT_TYPE_ID := r_ABR.information174;
2364                  l_INPUT_VALUE_ID :=  r_ABR.information178;
2365                end if;
2366 
2367                --
2368                if (g_ghr_mode = 'TRUE') then
2369                   get_elm_inpt_ids(p_elm_old_name       =>     r_ABR.information173
2370                                    ,p_elm_new_id        =>     l_ELEMENT_TYPE_ID
2371                                    ,p_business_group_id =>     p_target_business_group_id
2372                                    ,p_effective_date    =>     NVL(ben_pd_copy_to_ben_one.g_copy_effective_date ,p_effective_date)
2373                                    ,p_inpt_old_name     =>     r_ABR.information177
2374                                    ,p_inpt_new_id       =>     l_INPUT_VALUE_ID  ) ;
2375                end if;
2376                --
2377                if l_ELEMENT_TYPE_ID is null or l_INPUT_VALUE_ID is null then
2378                   --
2379                   r_ABR.INFORMATION45 := 'N'; -- If mapping is not done then make element not required.
2380                   --
2381                end if;
2382        -- UPD END
2383        --
2384        if l_dml_operation = 'UPDATE' then
2385          --
2386                  l_object_found_in_target := TRUE;
2387                  --
2388                  if l_process_date between r_ABR_unique.information2 and r_ABR_unique.information3 then
2389                        l_update := true;
2390                        if r_ABR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
2391                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ACTY_BASE_RT_ID'
2392                        then
2393                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ACTY_BASE_RT_ID' ;
2394                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_ABR_unique.information1 ;
2395                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_ABR_unique.information1 ;
2396                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
2397                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_ABR_unique.table_route_id;
2398                           --
2399                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
2400                           --
2401                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
2402                           --
2403                           BEN_PD_COPY_TO_BEN_ONE.log_data('ABR',l_new_value,l_prefix || r_ABR_unique.name|| l_suffix,'REUSED');
2404                           --
2405                        end if ;
2406                        hr_utility.set_location( 'found record for update',10);
2407                    --
2408                  else
2409                    --
2410                    l_update := false;
2411                    --
2412                  end if;
2413                else
2414                  --
2415                --UPD END
2416 
2417                l_min_esd := null ;
2418                l_max_eed := null ;
2419                open c_ABR_min_max_dates(r_ABR_unique.table_route_id, r_ABR_unique.information1 ) ;
2420                fetch c_ABR_min_max_dates into l_min_esd,l_max_eed ;
2421                --
2422 
2423                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
2424                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
2425                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
2426                end if;
2427                l_min_esd := greatest(l_min_esd,r_ABR_unique.information2);
2428 
2429                -- UPD START
2430                /*open c_ABR(r_ABR_unique.table_route_id,
2431                         r_ABR_unique.information1,
2432                         r_ABR_unique.information2,
2433                         r_ABR_unique.information3 ) ;
2434                --
2435                fetch c_ABR into r_ABR ;
2436                --
2437                close c_ABR ;*/
2438                -- UPD END
2439                --
2440                --Combination Flag If rate is for combinations and the combination is null
2441                --we don't try to create the combination.
2442                --
2443                l_cmbn_flag := true ;
2444                --
2445                if (( r_ABR.information239 is not null and l_CMBN_PLIP_ID is null ) OR
2446                    (r_ABR.information236  is not null and l_CMBN_PTIP_ID is null ) OR
2447                    (r_ABR.information249  is not null and l_CMBN_PTIP_OPT_ID is null )) then
2448                  --
2449                  l_cmbn_flag := false ;
2450                  --
2451                end if ;
2452                --
2453                /*
2454                if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
2455                  l_ELEMENT_TYPE_ID := r_ABR.information176;
2456                  l_INPUT_VALUE_ID  := r_ABR.information180;
2457                else
2458                  l_ELEMENT_TYPE_ID := r_ABR.information174;
2459                  l_INPUT_VALUE_ID :=  r_ABR.information178;
2460                end if;
2461 
2462                --
2463                if (g_ghr_mode = 'TRUE') then
2464                   get_elm_inpt_ids(p_elm_old_name       =>     r_ABR.information173
2465                                    ,p_elm_new_id        =>     l_ELEMENT_TYPE_ID
2466                                    ,p_business_group_id =>     p_target_business_group_id
2467                                    ,p_effective_date    =>     NVL(ben_pd_copy_to_ben_one.g_copy_effective_date ,p_effective_date)
2468                                    ,p_inpt_old_name     =>     r_ABR.information177
2469                                    ,p_inpt_new_id       =>     l_INPUT_VALUE_ID  ) ;
2470                end if;
2471                --
2472                if l_ELEMENT_TYPE_ID is null or l_INPUT_VALUE_ID is null then
2473                   --
2474                   r_ABR.INFORMATION45 := 'N'; -- If mapping is not done then make element not required.
2475                   --
2476                end if;
2477                */
2478                --
2479               /* Moved to TOP
2480                l_LWR_LMT_CALC_RL := get_fk('FORMULA_ID', r_ABR.information268,r_ABR.dml_operation);
2481                l_OIPLIP_ID := get_fk('OIPLIP_ID', r_ABR.information227,r_ABR.dml_operation);
2482                l_OIPL_ID := get_fk('OIPL_ID', r_ABR.information258,r_ABR.dml_operation);
2483                l_PARNT_ACTY_BASE_RT_ID := get_fk('ACTY_BASE_RT_ID', r_ABR.information267,r_ABR.dml_operation);
2484                l_PGM_ID := get_fk('PGM_ID', r_ABR.information260,r_ABR.dml_operation);
2485                l_PLIP_ID := get_fk('PLIP_ID', r_ABR.information256);
2486                l_PL_ID := get_fk('PL_ID', r_ABR.information261,r_ABR.dml_operation);
2487 
2488                l_PAY_RATE_GRADE_RULE_ID := get_fk('PAY_RATE_GRADE_RULE_ID', r_ABR.INFORMATION266,r_ABR.dml_operation);
2489                l_PRORT_MN_ANN_ELCN_VAL_RL := get_fk('FORMULA_ID', r_ABR.information274,r_ABR.dml_operation);
2490                l_PRORT_MX_ANN_ELCN_VAL_RL := get_fk('FORMULA_ID', r_ABR.information275,r_ABR.dml_operation);
2491                l_PRTL_MO_DET_MTHD_RL := get_fk('FORMULA_ID', r_ABR.information281,r_ABR.dml_operation);
2492                l_PRTL_MO_EFF_DT_DET_RL := get_fk('FORMULA_ID', r_ABR.information280,r_ABR.dml_operation);
2493                l_PTD_COMP_LVL_FCTR_ID := get_fk('COMP_LVL_FCTR_ID', r_ABR.information272,r_ABR.dml_operation);
2494                l_PTIP_ID := get_fk('PTIP_ID', r_ABR.information259,r_ABR.dml_operation);
2495                l_RNDG_RL := get_fk('FORMULA_ID', r_ABR.information279,r_ABR.dml_operation);
2496                l_TTL_COMP_LVL_FCTR_ID := get_fk('COMP_LVL_FCTR_ID', r_ABR.information257);
2497                l_UPR_LMT_CALC_RL := get_fk('FORMULA_ID', r_ABR.information269,r_ABR.dml_operation);
2498                l_VAL_CALC_RL := get_fk('FORMULA_ID', r_ABR.information282,r_ABR.dml_operation);
2499                l_INPUT_VA_CALC_RL := get_fk('FORMULA_ID', r_ABR.information263,r_ABR.dml_operation);
2500                l_VSTG_FOR_ACTY_RT_ID := get_fk('VSTG_FOR_ACTY_RT_ID', r_ABR.information271,r_ABR.dml_operation);
2501                */
2502 
2503                if p_reuse_object_flag = 'Y' then
2504                  if c_ABR_min_max_dates%found then
2505                    -- cursor to find the object
2506                    open c_find_ABR_in_target( l_prefix || r_ABR_unique.name|| l_suffix  ,l_min_esd,l_max_eed,
2507                                          p_target_business_group_id, nvl(l_acty_base_rt_id, -999)  ) ;
2508                    fetch c_find_ABR_in_target into l_new_value ;
2509                    if c_find_ABR_in_target%found then
2510                      --TEMPIK
2511                      l_dt_rec_found :=   dt_api.check_min_max_dates
2512                          (p_base_table_name => 'BEN_ACTY_BASE_RT_F',
2513                           p_base_key_column => 'ACTY_BASE_RT_ID',
2514                           p_base_key_value  => l_new_value,
2515                           p_from_date       => l_min_esd,
2516                           p_to_date         => l_max_eed );
2517                      if l_dt_rec_found THEN
2518                      --END TEMPIK
2519                                          --
2520                                          if r_ABR_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
2521                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'ACTY_BASE_RT_ID'  then
2522                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'ACTY_BASE_RT_ID' ;
2523                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_ABR_unique.information1 ;
2524                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
2525                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
2526                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_ABR_unique.table_route_id;
2527                                                 --
2528                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
2529                                                 --
2530                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
2531                                                 --
2532                                                 -- LOG
2533                                                 BEN_PD_COPY_TO_BEN_ONE.log_data('ABR',l_new_value,l_prefix || r_ABR_unique.name|| l_suffix,'REUSED');
2534                                                 --
2535                                          end if ;
2536                                          --
2537                                          l_object_found_in_target := true ;
2538                      --TEMPIK
2539                      end if; -- l_dt_rec_found
2540                      --END TEMPIK
2541                    else
2542                      -- NEW
2543                      if p_prefix_suffix_text is null then
2544                        --
2545                        open c_find_ABR_name_in_target( l_prefix || r_ABR_unique.name|| l_suffix  ,
2546                                        l_min_esd,l_max_eed,
2547                                        p_target_business_group_id, nvl(l_acty_base_rt_id, -999) ) ;
2548                        fetch c_find_ABR_name_in_target into l_new_value ;
2549                        if c_find_ABR_name_in_target%found then
2550                                          --TEMPIK
2551                                          l_dt_rec_found :=   dt_api.check_min_max_dates
2552                                                  (p_base_table_name => 'BEN_ACTY_BASE_RT_F',
2553                                                   p_base_key_column => 'ACTY_BASE_RT_ID',
2554                                                   p_base_key_value  => l_new_value,
2555                                                   p_from_date       => l_min_esd,
2556                                                   p_to_date         => l_max_eed );
2557                                          if l_dt_rec_found THEN
2558                                          --END TEMPIK
2559                                                  --
2560                                                  if   p_prefix_suffix_cd = 'PREFIX' then
2561                                                    l_prefix  := BEN_PLAN_DESIGN_TXNS_API.g_pgm_pl_prefix_suffix_text ;
2562                                                  elsif p_prefix_suffix_cd = 'SUFFIX' then
2563                                                    l_suffix   := BEN_PLAN_DESIGN_TXNS_API.g_pgm_pl_prefix_suffix_text ;
2564                                                  else
2565                                                    l_prefix := null ;
2566                                                    l_suffix  := null ;
2567                                                  end if ;
2568                                          --TEMPIK
2569                                          end if; -- l_dt_rec_found
2570                                          --END TEMPIK
2571                          --
2572                        end if;
2573                      close c_find_ABR_name_in_target ;
2574                      end if;
2575                    end if;
2576                    close c_find_ABR_in_target ;
2577                    -- NEW
2578                  --
2579                  end if;
2580                end if ;
2581                --
2582                --
2583                close c_ABR_min_max_dates ;
2584 
2585        -- UPD START
2586        end if; --if p_dml_operation
2587        --
2588 
2589        if (not l_object_found_in_target and l_cmbn_flag ) OR l_update then
2590        -- UPD END
2591 
2592          l_current_pk_id := r_ABR.information1;
2593          --
2594          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
2595          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
2596          --
2597 
2598          if l_current_pk_id =  l_prev_pk_id  then
2599            --
2600            l_first_rec := false ;
2601            --
2602          else
2603            --
2604            l_first_rec := true ;
2605            --
2606          end if ;
2607          --
2608          ben_pd_copy_to_ben_one.ben_chk_col_len('NAME' ,'BEN_ACTY_BASE_RT_F',l_prefix || r_ABR.INFORMATION170 || l_suffix);
2609          --
2610 
2611          l_effective_date := r_ABR.information2;
2612          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
2613               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
2614            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
2615          end if;
2616          -- UPD START
2617          --if l_first_rec then
2618          if l_first_rec and not l_update then
2619          -- UPD END
2620            -- Call Create routine.
2621            hr_utility.set_location(' BEN_ACTY_BASE_RT_F CREATE_ACTY_BASE_RATE ',20);
2622            BEN_ACTY_BASE_RATE_API.CREATE_ACTY_BASE_RATE(
2623              --
2624              P_VALIDATE               => false
2625              ,P_EFFECTIVE_DATE        => l_effective_date
2626              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
2627              --
2628              ,P_ABR_ATTRIBUTE1      => r_ABR.INFORMATION111
2629              ,P_ABR_ATTRIBUTE10      => r_ABR.INFORMATION120
2630              ,P_ABR_ATTRIBUTE11      => r_ABR.INFORMATION121
2631              ,P_ABR_ATTRIBUTE12      => r_ABR.INFORMATION122
2632              ,P_ABR_ATTRIBUTE13      => r_ABR.INFORMATION123
2633              ,P_ABR_ATTRIBUTE14      => r_ABR.INFORMATION124
2634              ,P_ABR_ATTRIBUTE15      => r_ABR.INFORMATION125
2635              ,P_ABR_ATTRIBUTE16      => r_ABR.INFORMATION126
2636              ,P_ABR_ATTRIBUTE17      => r_ABR.INFORMATION127
2637              ,P_ABR_ATTRIBUTE18      => r_ABR.INFORMATION128
2638              ,P_ABR_ATTRIBUTE19      => r_ABR.INFORMATION129
2639              ,P_ABR_ATTRIBUTE2      => r_ABR.INFORMATION112
2640              ,P_ABR_ATTRIBUTE20      => r_ABR.INFORMATION130
2641              ,P_ABR_ATTRIBUTE21      => r_ABR.INFORMATION131
2642              ,P_ABR_ATTRIBUTE22      => r_ABR.INFORMATION132
2643              ,P_ABR_ATTRIBUTE23      => r_ABR.INFORMATION133
2644              ,P_ABR_ATTRIBUTE24      => r_ABR.INFORMATION134
2645              ,P_ABR_ATTRIBUTE25      => r_ABR.INFORMATION135
2646              ,P_ABR_ATTRIBUTE26      => r_ABR.INFORMATION136
2647              ,P_ABR_ATTRIBUTE27      => r_ABR.INFORMATION137
2648              ,P_ABR_ATTRIBUTE28      => r_ABR.INFORMATION138
2649              ,P_ABR_ATTRIBUTE29      => r_ABR.INFORMATION139
2650              ,P_ABR_ATTRIBUTE3      => r_ABR.INFORMATION113
2651              ,P_ABR_ATTRIBUTE30      => r_ABR.INFORMATION140
2652              ,P_ABR_ATTRIBUTE4      => r_ABR.INFORMATION114
2653              ,P_ABR_ATTRIBUTE5      => r_ABR.INFORMATION115
2654              ,P_ABR_ATTRIBUTE6      => r_ABR.INFORMATION116
2655              ,P_ABR_ATTRIBUTE7      => r_ABR.INFORMATION117
2656              ,P_ABR_ATTRIBUTE8      => r_ABR.INFORMATION118
2657              ,P_ABR_ATTRIBUTE9      => r_ABR.INFORMATION119
2658              ,P_ABR_ATTRIBUTE_CATEGORY      => r_ABR.INFORMATION110
2659              ,P_ABV_MX_ELCN_VAL_ALWD_FLAG      => r_ABR.INFORMATION27
2660              ,P_ACTL_PREM_ID      => l_ACTL_PREM_ID
2661              ,P_ACTY_BASE_RT_ID      => l_acty_base_rt_id
2662              ,P_ACTY_BASE_RT_STAT_CD      => r_ABR.INFORMATION17
2663              ,P_ACTY_TYP_CD      => r_ABR.INFORMATION49
2664              ,P_ALWS_CHG_CD      => r_ABR.INFORMATION11
2665              ,P_ANN_MN_ELCN_VAL      => r_ABR.INFORMATION298
2666              ,P_ANN_MX_ELCN_VAL      => r_ABR.INFORMATION299
2667              ,P_ASMT_TO_USE_CD      => r_ABR.INFORMATION23
2668              ,P_ASN_ON_ENRT_FLAG      => r_ABR.INFORMATION26
2669              ,P_BLW_MN_ELCN_ALWD_FLAG      => r_ABR.INFORMATION28
2670              ,P_BNFT_RT_TYP_CD      => r_ABR.INFORMATION51
2671              ,P_CLM_COMP_LVL_FCTR_ID      => l_CLM_COMP_LVL_FCTR_ID
2672              ,P_CMBN_PLIP_ID      => l_CMBN_PLIP_ID
2673              ,P_CMBN_PTIP_ID      => l_CMBN_PTIP_ID
2674              ,P_CMBN_PTIP_OPT_ID      => l_CMBN_PTIP_OPT_ID
2675              ,P_COMP_LVL_FCTR_ID      => l_COMP_LVL_FCTR_ID
2676              ,P_COST_ALLOCATION_KEYFLEX_ID      => l_COST_ALLOCATION_KEYFLEX_ID
2677              ,P_DET_PL_YTD_CNTRS_CD      => r_ABR.INFORMATION24
2678              ,P_DFLT_FLAG      => r_ABR.INFORMATION39
2679              ,P_DFLT_VAL      => r_ABR.INFORMATION297
2680              ,P_DSPLY_ON_ENRT_FLAG      => r_ABR.INFORMATION29
2681              ,P_ELEMENT_TYPE_ID      => l_ELEMENT_TYPE_ID
2682              ,P_ELE_ENTRY_VAL_CD      => r_ABR.INFORMATION12
2683              ,P_ELE_RQD_FLAG      => r_ABR.INFORMATION45
2684              ,P_ENTR_ANN_VAL_FLAG      => r_ABR.INFORMATION44
2685              ,P_ENTR_VAL_AT_ENRT_FLAG      => r_ABR.INFORMATION41
2686              ,P_FRGN_ERG_DED_IDENT      => r_ABR.INFORMATION141
2687              ,P_FRGN_ERG_DED_NAME      => r_ABR.INFORMATION185
2688              ,P_FRGN_ERG_DED_TYP_CD      => r_ABR.INFORMATION19
2689              ,P_INCRMT_ELCN_VAL      => r_ABR.INFORMATION296
2690              ,P_INPUT_VALUE_ID      => l_INPUT_VALUE_ID
2691              ,P_INPUT_VA_CALC_RL      => l_INPUT_VA_CALC_RL
2692              ,P_LWR_LMT_CALC_RL      => l_LWR_LMT_CALC_RL
2693              ,P_LWR_LMT_VAL      => r_ABR.INFORMATION300
2694              ,P_MN_ELCN_VAL      => r_ABR.INFORMATION293
2695              ,P_MX_ELCN_VAL      => r_ABR.INFORMATION294
2696              ,P_NAME      => l_prefix || r_ABR.INFORMATION170 || l_suffix
2697              ,P_NNMNTRY_UOM      => r_ABR.INFORMATION14
2698              ,P_NO_MN_ELCN_VAL_DFND_FLAG      => r_ABR.INFORMATION42
2699              ,P_NO_MX_ELCN_VAL_DFND_FLAG      => r_ABR.INFORMATION40
2700              ,P_NO_STD_RT_USED_FLAG      => r_ABR.INFORMATION36
2701              ,P_OIPLIP_ID      => l_OIPLIP_ID
2702              ,P_OIPL_ID      => l_OIPL_ID
2703              ,P_ONE_ANN_PYMT_CD      => r_ABR.INFORMATION46
2704              ,P_ONLY_ONE_BAL_TYP_ALWD_FLAG      => r_ABR.INFORMATION43
2705              ,P_OPT_ID      => l_OPT_ID
2706              ,P_ORDR_NUM      => r_ABR.INFORMATION264
2707              ,P_PARNT_ACTY_BASE_RT_ID      => l_PARNT_ACTY_BASE_RT_ID
2708              ,P_PARNT_CHLD_CD      => r_ABR.INFORMATION53
2709              ,P_PAY_RATE_GRADE_RULE_ID      => l_PAY_RATE_GRADE_RULE_ID
2710              ,P_PGM_ID      => l_PGM_ID
2711              ,P_PLIP_ID      => l_PLIP_ID
2712              ,P_PL_ID      => l_PL_ID
2713              ,P_PRDCT_FLX_CR_WHEN_ELIG_FLAG      => r_ABR.INFORMATION35
2714              ,P_PROCG_SRC_CD      => r_ABR.INFORMATION18
2715              ,P_PROC_EACH_PP_DFLT_FLAG      => r_ABR.INFORMATION34
2716              ,P_PRORT_MN_ANN_ELCN_VAL_CD      => r_ABR.INFORMATION47
2717              ,P_PRORT_MN_ANN_ELCN_VAL_RL      => l_PRORT_MN_ANN_ELCN_VAL_RL
2718              ,P_PRORT_MX_ANN_ELCN_VAL_CD      => r_ABR.INFORMATION48
2719              ,P_PRORT_MX_ANN_ELCN_VAL_RL      => l_PRORT_MX_ANN_ELCN_VAL_RL
2720              ,P_PRTL_MO_DET_MTHD_CD      => r_ABR.INFORMATION16
2721              ,P_PRTL_MO_DET_MTHD_RL      => l_PRTL_MO_DET_MTHD_RL
2722              ,P_PRTL_MO_EFF_DT_DET_CD      => r_ABR.INFORMATION20
2723              ,P_PRTL_MO_EFF_DT_DET_RL      => l_PRTL_MO_EFF_DT_DET_RL
2724              ,P_PTD_COMP_LVL_FCTR_ID      => l_PTD_COMP_LVL_FCTR_ID
2725              ,P_PTIP_ID      => l_PTIP_ID
2726              ,P_RCRRG_CD      => r_ABR.INFORMATION13
2727              ,P_RNDG_CD      => r_ABR.INFORMATION15
2728              ,P_RNDG_RL      => l_RNDG_RL
2729              ,P_RT_MLT_CD      => r_ABR.INFORMATION54
2730              ,P_RT_TYP_CD      => r_ABR.INFORMATION50
2731              ,P_RT_USG_CD      => r_ABR.INFORMATION21
2732              ,P_SUBJ_TO_IMPTD_INCM_FLAG      => r_ABR.INFORMATION22
2733              ,P_TTL_COMP_LVL_FCTR_ID      => l_TTL_COMP_LVL_FCTR_ID
2734              ,P_TX_TYP_CD      => r_ABR.INFORMATION52
2735              ,P_UPR_LMT_CALC_RL      => l_UPR_LMT_CALC_RL
2736              ,P_UPR_LMT_VAL      => r_ABR.INFORMATION301
2737              ,P_USES_DED_SCHED_FLAG      => r_ABR.INFORMATION31
2738              ,P_USES_PYMT_SCHED_FLAG      => r_ABR.INFORMATION37
2739              ,P_USES_VARBL_RT_FLAG      => r_ABR.INFORMATION32
2740              ,P_USE_CALC_ACTY_BS_RT_FLAG      => r_ABR.INFORMATION30
2741              ,P_USE_TO_CALC_NET_FLX_CR_FLAG      => r_ABR.INFORMATION25
2742              ,P_VAL      => r_ABR.INFORMATION295
2743              ,P_VAL_CALC_RL      => l_VAL_CALC_RL
2744              ,P_VAL_OVRID_ALWD_FLAG      => r_ABR.INFORMATION38
2745              ,P_VSTG_FOR_ACTY_RT_ID      => l_VSTG_FOR_ACTY_RT_ID
2746              ,P_VSTG_SCHED_APLS_FLAG      => r_ABR.INFORMATION33
2747              ,P_WSH_RL_DY_MO_NUM      => r_ABR.INFORMATION270
2748              ,p_MAPPING_TABLE_NAME    => r_ABR.INFORMATION186     /* Bug 4169120 : Rate By Criteria */
2749              ,p_MAPPING_TABLE_PK_ID   => r_ABR.INFORMATION284     /* Bug 4169120 : Rate By Criteria */
2750              ,p_MN_MX_ELCN_RL         => l_MN_MX_ELCN_RL          /* Bug 4169044 : Min/Max Rule */
2751              ,p_RATE_PERIODIZATION_CD => r_ABR.INFORMATION56      /* Bug 3700087 : Rate Periodization Code */
2752              ,p_RATE_PERIODIZATION_RL => L_RATE_PERIODIZATION_RL  /* Bug 3700087 : Rate Periodization Rule */
2753              ,p_CONTEXT_PGM_ID        => NULL                     /* Bug 4725928 : Value populated in RHI */
2754              ,p_CONTEXT_PL_ID         => NULL                     /* Bug 4725928 : Value populated in RHI */
2755              ,p_CONTEXT_OPT_ID        => NULL                     /* Bug 4725928 : Value populated in RHI */
2756 	     ,p_ELEMENT_DET_RL        => l_ELEMENT_DET_RL         /* Bug 4926267 : CWB Multiple currency  */
2757 	     ,p_CURRENCY_DET_CD       => r_ABR.INFORMATION57      /* Bug 4926267 : CWB Multiple currency  */
2758 	     ,p_ABR_SEQ_NUM           => r_ABR.INFORMATION221     /* Absenses Enhancement */
2759              --
2760              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
2761              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
2762              --cwbglobal tilk
2763              ,P_SUB_ACTY_TYP_CD      => r_ABR.information55
2764              --
2765              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
2766            );
2767            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
2768            -- Update all relevent cer records with new pk_id
2769            hr_utility.set_location('Before plsql table ',222);
2770            hr_utility.set_location('new_value id '||l_acty_base_rt_id,222);
2771            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'ACTY_BASE_RT_ID' ;
2772            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_ABR.information1 ;
2773            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_ACTY_BASE_RT_ID ;
2774            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
2775            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_ABR_unique.table_route_id;
2776            hr_utility.set_location('After plsql table ',222);
2777            --
2778            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
2779            --
2780            if (g_ghr_mode = 'TRUE' and r_ABR.INFORMATION45 = 'Y') then
2781               --
2782               -- In ghr mode mapping is done based on names so just
2783               -- update the target id's
2784               --
2785               update ben_copy_entity_results
2786                 set information176   = l_element_type_id,
2787                     information180   = l_input_value_id
2788                 where copy_entity_txn_id = p_copy_entity_txn_id
2789                 and   table_route_id     = ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id
2790                 and   information1       = ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value;
2791               --
2792            end if;
2793            --
2794            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
2795            --
2796            -- LOG
2797            BEN_PD_COPY_TO_BEN_ONE.log_data('ABR',l_new_value,l_prefix || r_ABR.INFORMATION170|| l_suffix,'COPIED');
2798            --
2799          else
2800            --
2801            -- Call Update routine for the pk_id created in prev run .
2802            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
2803            hr_utility.set_location(' BEN_ACTY_BASE_RT_F UPDATE_ACTY_BASE_RATE ',30);
2804 
2805            --UPD START
2806            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
2807            --
2808            if l_update then
2809              --
2810              l_datetrack_mode := r_ABR.datetrack_mode ;
2811              --
2812              get_dt_modes(
2813                p_effective_date        => l_process_date,
2814                p_effective_end_date    => r_ABR.information3,
2815                p_effective_start_date  => r_ABR.information2,
2816                p_dml_operation         => r_ABR.dml_operation,
2817                p_datetrack_mode        => l_datetrack_mode );
2818            --    p_update                => l_update
2819              --
2820              l_effective_date := l_process_date;
2821              l_acty_base_rt_id   := r_ABR.information1;
2822              l_object_version_number := r_ABR.information265;
2823              --
2824            end if;
2825            --
2826            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
2827            --
2828            IF l_update OR l_dml_operation <> 'UPDATE' THEN
2829            --UPD END
2830                --
2831                    BEN_ACTY_BASE_RATE_API.UPDATE_ACTY_BASE_RATE(
2832                      --
2833                      P_VALIDATE               => false
2834                      ,P_EFFECTIVE_DATE        => l_effective_date
2835                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
2836                      --
2837                      ,P_ABR_ATTRIBUTE1      => r_ABR.INFORMATION111
2838                      ,P_ABR_ATTRIBUTE10      => r_ABR.INFORMATION120
2839                      ,P_ABR_ATTRIBUTE11      => r_ABR.INFORMATION121
2840                      ,P_ABR_ATTRIBUTE12      => r_ABR.INFORMATION122
2841                      ,P_ABR_ATTRIBUTE13      => r_ABR.INFORMATION123
2842                      ,P_ABR_ATTRIBUTE14      => r_ABR.INFORMATION124
2843                      ,P_ABR_ATTRIBUTE15      => r_ABR.INFORMATION125
2844                      ,P_ABR_ATTRIBUTE16      => r_ABR.INFORMATION126
2845                      ,P_ABR_ATTRIBUTE17      => r_ABR.INFORMATION127
2846                      ,P_ABR_ATTRIBUTE18      => r_ABR.INFORMATION128
2847                      ,P_ABR_ATTRIBUTE19      => r_ABR.INFORMATION129
2848                      ,P_ABR_ATTRIBUTE2      => r_ABR.INFORMATION112
2849                      ,P_ABR_ATTRIBUTE20      => r_ABR.INFORMATION130
2850                      ,P_ABR_ATTRIBUTE21      => r_ABR.INFORMATION131
2851                      ,P_ABR_ATTRIBUTE22      => r_ABR.INFORMATION132
2852                      ,P_ABR_ATTRIBUTE23      => r_ABR.INFORMATION133
2853                      ,P_ABR_ATTRIBUTE24      => r_ABR.INFORMATION134
2854                      ,P_ABR_ATTRIBUTE25      => r_ABR.INFORMATION135
2855                      ,P_ABR_ATTRIBUTE26      => r_ABR.INFORMATION136
2856                      ,P_ABR_ATTRIBUTE27      => r_ABR.INFORMATION137
2857                      ,P_ABR_ATTRIBUTE28      => r_ABR.INFORMATION138
2858                      ,P_ABR_ATTRIBUTE29      => r_ABR.INFORMATION139
2859                      ,P_ABR_ATTRIBUTE3      => r_ABR.INFORMATION113
2860                      ,P_ABR_ATTRIBUTE30      => r_ABR.INFORMATION140
2861                      ,P_ABR_ATTRIBUTE4      => r_ABR.INFORMATION114
2862                      ,P_ABR_ATTRIBUTE5      => r_ABR.INFORMATION115
2863                      ,P_ABR_ATTRIBUTE6      => r_ABR.INFORMATION116
2864                      ,P_ABR_ATTRIBUTE7      => r_ABR.INFORMATION117
2865                      ,P_ABR_ATTRIBUTE8      => r_ABR.INFORMATION118
2866                      ,P_ABR_ATTRIBUTE9      => r_ABR.INFORMATION119
2867                      ,P_ABR_ATTRIBUTE_CATEGORY      => r_ABR.INFORMATION110
2868                      ,P_ABV_MX_ELCN_VAL_ALWD_FLAG      => r_ABR.INFORMATION27
2869                      ,P_ACTL_PREM_ID      => l_ACTL_PREM_ID
2870                      ,P_ACTY_BASE_RT_ID      => l_acty_base_rt_id
2871                      ,P_ACTY_BASE_RT_STAT_CD      => r_ABR.INFORMATION17
2872                      ,P_ACTY_TYP_CD      => r_ABR.INFORMATION49
2873                      ,P_ALWS_CHG_CD      => r_ABR.INFORMATION11
2874                      ,P_ANN_MN_ELCN_VAL      => r_ABR.INFORMATION298
2875                      ,P_ANN_MX_ELCN_VAL      => r_ABR.INFORMATION299
2876                      ,P_ASMT_TO_USE_CD      => r_ABR.INFORMATION23
2877                      ,P_ASN_ON_ENRT_FLAG      => r_ABR.INFORMATION26
2878                      ,P_BLW_MN_ELCN_ALWD_FLAG      => r_ABR.INFORMATION28
2879                      ,P_BNFT_RT_TYP_CD      => r_ABR.INFORMATION51
2880                      ,P_CLM_COMP_LVL_FCTR_ID      => l_CLM_COMP_LVL_FCTR_ID
2881                      ,P_CMBN_PLIP_ID      => l_CMBN_PLIP_ID
2882                      ,P_CMBN_PTIP_ID      => l_CMBN_PTIP_ID
2883                      ,P_CMBN_PTIP_OPT_ID      => l_CMBN_PTIP_OPT_ID
2884                      ,P_COMP_LVL_FCTR_ID      => l_COMP_LVL_FCTR_ID
2885                      ,P_COST_ALLOCATION_KEYFLEX_ID      => l_COST_ALLOCATION_KEYFLEX_ID
2886                      ,P_DET_PL_YTD_CNTRS_CD      => r_ABR.INFORMATION24
2887                      ,P_DFLT_FLAG      => r_ABR.INFORMATION39
2888                      ,P_DFLT_VAL      => r_ABR.INFORMATION297
2889                      ,P_DSPLY_ON_ENRT_FLAG      => r_ABR.INFORMATION29
2890                      ,P_ELEMENT_TYPE_ID      => l_ELEMENT_TYPE_ID
2891                      ,P_ELE_ENTRY_VAL_CD      => r_ABR.INFORMATION12
2892                      ,P_ELE_RQD_FLAG      => r_ABR.INFORMATION45
2893                      ,P_ENTR_ANN_VAL_FLAG      => r_ABR.INFORMATION44
2894                      ,P_ENTR_VAL_AT_ENRT_FLAG      => r_ABR.INFORMATION41
2895                      ,P_FRGN_ERG_DED_IDENT      => r_ABR.INFORMATION141
2896                      ,P_FRGN_ERG_DED_NAME      => r_ABR.INFORMATION185
2897                      ,P_FRGN_ERG_DED_TYP_CD      => r_ABR.INFORMATION19
2898                      ,P_INCRMT_ELCN_VAL      => r_ABR.INFORMATION296
2899                      ,P_INPUT_VALUE_ID      => l_INPUT_VALUE_ID
2900                      ,P_INPUT_VA_CALC_RL      => l_INPUT_VA_CALC_RL
2901                      ,P_LWR_LMT_CALC_RL      => l_LWR_LMT_CALC_RL
2902                      ,P_LWR_LMT_VAL      => r_ABR.INFORMATION300
2903                      ,P_MN_ELCN_VAL      => r_ABR.INFORMATION293
2904                      ,P_MX_ELCN_VAL      => r_ABR.INFORMATION294
2905                      ,P_NAME      => l_prefix || r_ABR.INFORMATION170 || l_suffix
2906                      ,P_NNMNTRY_UOM      => r_ABR.INFORMATION14
2907                      ,P_NO_MN_ELCN_VAL_DFND_FLAG      => r_ABR.INFORMATION42
2908                      ,P_NO_MX_ELCN_VAL_DFND_FLAG      => r_ABR.INFORMATION40
2909                      ,P_NO_STD_RT_USED_FLAG      => r_ABR.INFORMATION36
2910                      ,P_OIPLIP_ID      => l_OIPLIP_ID
2911                 -- 3622315. Uncommented the below paramter.
2912                      ,P_OIPL_ID      => l_OIPL_ID
2913                -- 3622315
2914                      ,P_ONE_ANN_PYMT_CD      => r_ABR.INFORMATION46
2915                      ,P_ONLY_ONE_BAL_TYP_ALWD_FLAG      => r_ABR.INFORMATION43
2916                      ,P_OPT_ID      => l_OPT_ID
2917                      ,P_ORDR_NUM      => r_ABR.INFORMATION264
2918                      ,P_PARNT_ACTY_BASE_RT_ID      => l_PARNT_ACTY_BASE_RT_ID
2919                      ,P_PARNT_CHLD_CD      => r_ABR.INFORMATION53
2920                      ,P_PAY_RATE_GRADE_RULE_ID      => l_PAY_RATE_GRADE_RULE_ID
2921                      ,P_PGM_ID      => l_PGM_ID
2922                      ,P_PLIP_ID      => l_PLIP_ID
2923                      ,P_PL_ID      => l_PL_ID
2924                      ,P_PRDCT_FLX_CR_WHEN_ELIG_FLAG      => r_ABR.INFORMATION35
2925                      ,P_PROCG_SRC_CD      => r_ABR.INFORMATION18
2926                      ,P_PROC_EACH_PP_DFLT_FLAG      => r_ABR.INFORMATION34
2927                      ,P_PRORT_MN_ANN_ELCN_VAL_CD      => r_ABR.INFORMATION47
2928                      ,P_PRORT_MN_ANN_ELCN_VAL_RL      => l_PRORT_MN_ANN_ELCN_VAL_RL
2929                      ,P_PRORT_MX_ANN_ELCN_VAL_CD      => r_ABR.INFORMATION48
2930                      ,P_PRORT_MX_ANN_ELCN_VAL_RL      => l_PRORT_MX_ANN_ELCN_VAL_RL
2931                      ,P_PRTL_MO_DET_MTHD_CD      => r_ABR.INFORMATION16
2932                      ,P_PRTL_MO_DET_MTHD_RL      => l_PRTL_MO_DET_MTHD_RL
2933                      ,P_PRTL_MO_EFF_DT_DET_CD      => r_ABR.INFORMATION20
2934                      ,P_PRTL_MO_EFF_DT_DET_RL      => l_PRTL_MO_EFF_DT_DET_RL
2935                      ,P_PTD_COMP_LVL_FCTR_ID      => l_PTD_COMP_LVL_FCTR_ID
2936                      ,P_PTIP_ID      => l_PTIP_ID
2937                      ,P_RCRRG_CD      => r_ABR.INFORMATION13
2938                      ,P_RNDG_CD      => r_ABR.INFORMATION15
2939                      ,P_RNDG_RL      => l_RNDG_RL
2940                      ,P_RT_MLT_CD      => r_ABR.INFORMATION54
2941                      ,P_RT_TYP_CD      => r_ABR.INFORMATION50
2942                      ,P_RT_USG_CD      => r_ABR.INFORMATION21
2943                      ,P_SUBJ_TO_IMPTD_INCM_FLAG      => r_ABR.INFORMATION22
2944                      ,P_TTL_COMP_LVL_FCTR_ID      => l_TTL_COMP_LVL_FCTR_ID
2945                      ,P_TX_TYP_CD      => r_ABR.INFORMATION52
2946                      ,P_UPR_LMT_CALC_RL      => l_UPR_LMT_CALC_RL
2947                      ,P_UPR_LMT_VAL      => r_ABR.INFORMATION301
2948                      ,P_USES_DED_SCHED_FLAG      => r_ABR.INFORMATION31
2949                      ,P_USES_PYMT_SCHED_FLAG      => r_ABR.INFORMATION37
2950                      ,P_USES_VARBL_RT_FLAG      => r_ABR.INFORMATION32
2951                      ,P_USE_CALC_ACTY_BS_RT_FLAG      => r_ABR.INFORMATION30
2952                      ,P_USE_TO_CALC_NET_FLX_CR_FLAG      => r_ABR.INFORMATION25
2953                      ,P_VAL      => r_ABR.INFORMATION295
2954                      ,P_VAL_CALC_RL      => l_VAL_CALC_RL
2955                      ,P_VAL_OVRID_ALWD_FLAG      => r_ABR.INFORMATION38
2956                      ,P_VSTG_FOR_ACTY_RT_ID      => l_VSTG_FOR_ACTY_RT_ID
2957                      ,P_VSTG_SCHED_APLS_FLAG      => r_ABR.INFORMATION33
2958                      ,P_WSH_RL_DY_MO_NUM      => r_ABR.INFORMATION270
2959                      ,p_MAPPING_TABLE_NAME    => r_ABR.INFORMATION186   /* Bug 4169120 : Rate By Criteria */
2960                      ,p_MAPPING_TABLE_PK_ID   => r_ABR.INFORMATION284   /* Bug 4169120 : Rate By Criteria */
2961                      ,p_MN_MX_ELCN_RL         => l_MN_MX_ELCN_RL   /* Bug 4169044 : Min/Max Rule */
2962                      ,p_RATE_PERIODIZATION_CD => r_ABR.INFORMATION56      /* Bug 3700087 : Rate Periodization Code */
2963                      ,p_RATE_PERIODIZATION_RL => L_RATE_PERIODIZATION_RL  /* Bug 3700087 : Rate Periodization Rule */
2964                      ,p_CONTEXT_PGM_ID        => NULL                     /* Bug 4725928 : Value populated in RHI */
2965                      ,p_CONTEXT_PL_ID         => NULL                     /* Bug 4725928 : Value populated in RHI */
2966                      ,p_CONTEXT_OPT_ID        => NULL                     /* Bug 4725928 : Value populated in RHI */
2967 		     ,p_ELEMENT_DET_RL        => l_ELEMENT_DET_RL         /* Bug 4926267 : CWB Multiple currency  */
2968 	             ,p_CURRENCY_DET_CD       => r_ABR.INFORMATION57      /* Bug 4926267 : CWB Multiple currency  */
2969          	     ,p_ABR_SEQ_NUM           => r_ABR.INFORMATION221     /* Absenses Enhancement */
2970                      --
2971                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
2972                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
2973                      --cwbglobal tilak
2974                      ,P_SUB_ACTY_TYP_CD      => r_ABR.information55
2975                      --
2976                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
2977                      -- UPD START
2978                      --,P_DATETRACK_MODE        => hr_api.g_update
2979                      ,P_DATETRACK_MODE        => l_datetrack_mode
2980                      --UPD END
2981                    );
2982            --
2983            end if;  -- l_update
2984          end if;
2985          --
2986          --
2987          -- Delete the row if it is end dated.
2988          --
2989          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
2990              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
2991            trunc(l_max_eed) = r_ABR.information3) then
2992            --
2993            BEN_ACTY_BASE_RATE_API.delete_ACTY_BASE_RATE(
2994               --
2995                p_validate                       => false
2996               ,p_acty_base_rt_id                => l_acty_base_rt_id
2997               ,p_effective_start_date           => l_effective_start_date
2998               ,p_effective_end_date             => l_effective_end_date
2999               ,p_object_version_number          => l_object_version_number
3000               ,p_effective_date                 => l_max_eed
3001               ,p_datetrack_mode                 => hr_api.g_delete
3002               --
3003               );
3004               --
3005          end if;
3006          --
3007          l_prev_pk_id := l_current_pk_id ;
3008          --
3009        end if;
3010        --
3011      end if;
3012      --
3013    end loop;
3014    --
3015  exception when others then
3016      --
3017      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'ABR',l_prefix || r_ABR.INFORMATION170 || l_suffix) ;
3018 
3019  end create_ABR_rows;
3020 
3021    --
3022    ---------------------------------------------------------------
3023    ----------------------< create_MTR_rows >-----------------------
3024    ---------------------------------------------------------------
3025    --
3026    procedure create_MTR_rows
3027    (
3028          p_validate                       in  number     default 0
3029         ,p_copy_entity_txn_id             in  number
3030         ,p_effective_date                 in  date
3031         ,p_prefix_suffix_text             in  varchar2  default null
3032         ,p_reuse_object_flag              in  varchar2  default null
3033         ,p_target_business_group_id       in  varchar2  default null
3034         ,p_prefix_suffix_cd               in  varchar2  default null
3035    ) is
3036    --
3037    l_ACTY_BASE_RT_ID  number;
3038    l_COMP_LVL_FCTR_ID  number;
3039    l_MTCHG_RT_CALC_RL  number;
3040    cursor c_unique_MTR(l_table_alias varchar2) is
3041    select distinct cpe.information1,
3042      cpe.information2,
3043      cpe.information3,
3044      cpe.table_route_id,
3045      cpe.dml_operation,
3046      cpe.datetrack_mode
3047    from ben_copy_entity_results cpe,
3048         pqh_table_route tr
3049    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
3050    and   cpe.table_route_id     = tr.table_route_id
3051    -- and   tr.where_clause        = l_BEN_MTCHG_RT_F
3052    and   tr.table_alias = l_table_alias
3053    and   cpe.number_of_copies   = 1 -- ADDITION
3054    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
3055    order by information1, information2; --added for bug: 5151945
3056    --
3057    --
3058    cursor c_MTR_min_max_dates(c_table_route_id  number,
3059                 c_information1   number) is
3060    select
3061      min(cpe.information2) min_esd,
3062      max(cpe.information3) min_eed
3063    from ben_copy_entity_results cpe
3064    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
3065    and   cpe.table_route_id     = c_table_route_id
3066    and   cpe.information1       = c_information1 ;
3067    --
3068    cursor c_MTR(c_table_route_id  number,
3069                 c_information1   number,
3070                 c_information2   date,
3071                 c_information3   date)  is
3072    select
3073      cpe.*
3074    from ben_copy_entity_results cpe
3075    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
3076    and   cpe.table_route_id     = c_table_route_id
3077    and   cpe.information1       = c_information1
3078    and   cpe.information2       = c_information2
3079    and   cpe.information3       = c_information3
3080    and rownum = 1 ;
3081    -- Date Track target record
3082    cursor c_find_MTR_in_target(
3083                                 c_effective_start_date    date,
3084                                 c_effective_end_date      date,
3085                                 c_business_group_id       number,
3086                                 c_new_pk_id               number) is
3087    select
3088      MTR.mtchg_rt_id new_value
3089    from BEN_MTCHG_RT_F MTR
3090    where
3091    MTR.ACTY_BASE_RT_ID     = l_ACTY_BASE_RT_ID and
3092    nvl(MTR.COMP_LVL_FCTR_ID,-999)     = nvl(l_COMP_LVL_FCTR_ID,-999)  and
3093    MTR.business_group_id  = c_business_group_id
3094    and   MTR.mtchg_rt_id  <> c_new_pk_id
3095 --TEMPIK
3096    and c_effective_start_date between effective_start_date
3097                             and effective_end_date ;
3098 --END TEMPIK
3099 /* TEMPIK
3100    and exists ( select null
3101                 from BEN_MTCHG_RT_F MTR1
3102                 where
3103                 MTR1.ACTY_BASE_RT_ID     = l_ACTY_BASE_RT_ID  and
3104                 nvl(MTR1.COMP_LVL_FCTR_ID,-999)     = nvl(l_COMP_LVL_FCTR_ID,-999)  and
3105                 MTR1.business_group_id  = c_business_group_id
3106                 and   MTR1.effective_start_date <= c_effective_start_date )
3107    and exists ( select null
3108                 from BEN_MTCHG_RT_F MTR2
3109                 where
3110                 MTR2.ACTY_BASE_RT_ID     = l_ACTY_BASE_RT_ID  and
3111                 nvl(MTR2.COMP_LVL_FCTR_ID,-999)     = nvl(l_COMP_LVL_FCTR_ID,-999)  and
3112                 MTR2.business_group_id  = c_business_group_id
3113                 and   MTR2.effective_end_date >= c_effective_end_date )
3114                 ;
3115 TEMPIK */
3116    --TEMPIK
3117    l_dt_rec_found            boolean ;
3118    --END TEMPIK
3119    --
3120 
3121    --UPD START
3122    --
3123    l_update                  boolean      := false ;
3124    l_datetrack_mode          varchar2(80) := hr_api.g_update;
3125    l_process_date            date;
3126    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
3127    --
3128    --UPD END
3129    --
3130    l_current_pk_id           number := null ;
3131    l_prev_pk_id              number := null ;
3132    l_first_rec               boolean := true ;
3133    r_MTR                     c_MTR%rowtype;
3134    l_mtchg_rt_id             number ;
3135    l_object_version_number   number ;
3136    l_effective_start_date    date ;
3137    l_effective_end_date      date ;
3138    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
3139    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
3140    l_new_value               number(15);
3141    l_object_found_in_target  boolean := false ;
3142    l_min_esd                 date;
3143    l_max_eed                 date;
3144    l_effective_date          date;
3145    --
3146  begin
3147    -- Initialization
3148    l_object_found_in_target := false ;
3149    -- End Initialization
3150    -- Derive the prefix - sufix
3151    if   p_prefix_suffix_cd = 'PREFIX' then
3152      l_prefix  := p_prefix_suffix_text ;
3153    elsif p_prefix_suffix_cd = 'SUFFIX' then
3154      l_suffix   := p_prefix_suffix_text ;
3155    else
3156      l_prefix := null ;
3157      l_suffix  := null ;
3158    end if ;
3159    -- End Prefix Sufix derivation
3160    for r_MTR_unique in c_unique_MTR('MTR') loop
3161 
3162      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
3163         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
3164          r_MTR_unique.information3 >=
3165                  ben_pd_copy_to_ben_one.g_copy_effective_date)
3166         ) then
3167        --
3168        hr_utility.set_location(' r_MTR_unique.table_route_id '||r_MTR_unique.table_route_id,10);
3169        hr_utility.set_location(' r_MTR_unique.information1 '||r_MTR_unique.information1,10);
3170        hr_utility.set_location( 'r_MTR_unique.information2 '||r_MTR_unique.information2,10);
3171        hr_utility.set_location( 'r_MTR_unique.information3 '||r_MTR_unique.information3,10);
3172        -- If reuse objects flag is 'Y' then check for the object in the target business group
3173        -- if found insert the record into PLSql table and exit the loop else try create the
3174        -- object in the target business group
3175        --
3176        l_object_found_in_target := false ;
3177 
3178        -- UPD START
3179        open c_MTR(r_MTR_unique.table_route_id,
3180                 r_MTR_unique.information1,
3181                 r_MTR_unique.information2,
3182                 r_MTR_unique.information3 ) ;
3183        --
3184        fetch c_MTR into r_MTR ;
3185        --
3186        close c_MTR ;
3187        --
3188        l_dml_operation:= r_MTR_unique.dml_operation ;
3189        l_ACTY_BASE_RT_ID := get_fk('ACTY_BASE_RT_ID', r_MTR.information253,r_MTR.dml_operation);
3190        l_COMP_LVL_FCTR_ID := get_fk('COMP_LVL_FCTR_ID', r_MTR.information254,r_MTR.dml_operation);
3191        l_MTCHG_RT_CALC_RL := get_fk('FORMULA_ID', r_MTR.information261,r_MTR.dml_operation);
3192        -- UPD END
3193 
3194        --UPD START
3195        l_update := false;
3196        l_process_date := p_effective_date;
3197        --
3198        if l_dml_operation = 'UPDATE' then
3199          --
3200                  l_object_found_in_target := TRUE;
3201                  --
3202                  if l_process_date between r_MTR_unique.information2 and r_MTR_unique.information3 then
3203                        l_update := true;
3204                        if r_MTR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
3205                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'MTCHG_RT_ID'
3206                        then
3207                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'MTCHG_RT_ID' ;
3208                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_MTR_unique.information1 ;
3209                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_MTR_unique.information1 ;
3210                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
3211                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_MTR_unique.table_route_id;
3212                           --
3213                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
3214                           --
3215                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
3216                           -- DOUBT
3217                           -- BEN_PD_COPY_TO_BEN_ONE.log_data('MTR',l_new_value,l_prefix || r_MTR_unique.name|| l_suffix,'REUSED');
3218                           --
3219                        end if ;
3220                        hr_utility.set_location( 'found record for update',10);
3221                    --
3222                  else
3223                    --
3224                    l_update := false;
3225                    --
3226                  end if;
3227                else
3228                --
3229                --UPD END
3230 
3231                l_min_esd := null ;
3232                l_max_eed := null ;
3233                open c_MTR_min_max_dates(r_MTR_unique.table_route_id, r_MTR_unique.information1 ) ;
3234                fetch c_MTR_min_max_dates into l_min_esd,l_max_eed ;
3235                --
3236 
3237                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
3238                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
3239                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
3240                end if;
3241                l_min_esd := greatest(l_min_esd,r_MTR_unique.information2);
3242                /*
3243                open c_MTR(r_MTR_unique.table_route_id,
3244                         r_MTR_unique.information1,
3245                         r_MTR_unique.information2,
3246                         r_MTR_unique.information3 ) ;
3247                --
3248                fetch c_MTR into r_MTR ;
3249                --
3250                close c_MTR ;*/
3251                --
3252                if p_reuse_object_flag = 'Y' then
3253                  if c_MTR_min_max_dates%found then
3254                    -- cursor to find the object
3255                    open c_find_MTR_in_target( l_min_esd,l_max_eed,
3256                                          p_target_business_group_id, nvl(l_mtchg_rt_id, -999)  ) ;
3257                    fetch c_find_MTR_in_target into l_new_value ;
3258                    if c_find_MTR_in_target%found then
3259                      --TEMPIK
3260                      l_dt_rec_found :=   dt_api.check_min_max_dates
3261                          (p_base_table_name => 'BEN_MTCHG_RT_F',
3262                           p_base_key_column => 'MTCHG_RT_ID',
3263                           p_base_key_value  => l_new_value,
3264                           p_from_date       => l_min_esd,
3265                           p_to_date         => l_max_eed );
3266                      if l_dt_rec_found THEN
3267                      --END TEMPIK
3268                                          --
3269                                          if r_MTR_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
3270                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'MTCHG_RT_ID'  then
3271                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'MTCHG_RT_ID' ;
3272                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_MTR_unique.information1 ;
3273                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
3274                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
3275                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_MTR_unique.table_route_id;
3276                                                 --
3277                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
3278                                                 --
3279                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
3280                                          end if ;
3281                                          --
3282                                          l_object_found_in_target := true ;
3283                      --TEMPIK
3284                      end if; -- l_dt_rec_found
3285                      --END TEMPIK
3286                    end if;
3287                    close c_find_MTR_in_target ;
3288                  --
3289                  end if;
3290                end if ;
3291                --
3292                close c_MTR_min_max_dates ;
3293        -- UPD START
3294        end if; --if p_dml_operation
3295        --
3296        if not l_object_found_in_target OR l_update  then
3297 
3298        --if not l_object_found_in_target then
3299        -- UPD END
3300          --
3301          l_current_pk_id := r_MTR.information1;
3302          --
3303          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
3304          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
3305          --
3306          if l_current_pk_id =  l_prev_pk_id  then
3307            --
3308            l_first_rec := false ;
3309            --
3310          else
3311            --
3312            l_first_rec := true ;
3313            --
3314          end if ;
3315          --
3316 
3317          l_effective_date := r_MTR.information2;
3318          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
3319               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
3320            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
3321          end if;
3322 
3323          -- UPD START
3324          --if l_first_rec then
3325          if l_first_rec and not l_update then
3326          -- UPD END
3327 
3328            -- Call Create routine.
3329            hr_utility.set_location(' BEN_MTCHG_RT_F CREATE_MATCHING_RATES ',20);
3330            BEN_MATCHING_RATES_API.CREATE_MATCHING_RATES(
3331              --
3332              P_VALIDATE               => false
3333              ,P_EFFECTIVE_DATE        => l_effective_date
3334              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
3335              --
3336              ,P_ACTY_BASE_RT_ID      => l_ACTY_BASE_RT_ID
3337              ,P_CNTNU_MTCH_AFTR_MX_RL_FLAG      => r_MTR.INFORMATION13
3338              ,P_COMP_LVL_FCTR_ID      => l_COMP_LVL_FCTR_ID
3339              ,P_FROM_PCT_VAL      => r_MTR.INFORMATION293
3340              ,P_MN_MTCH_AMT      => r_MTR.INFORMATION299
3341              ,P_MTCHG_RT_CALC_RL      => l_MTCHG_RT_CALC_RL
3342              ,P_MTCHG_RT_ID      => l_mtchg_rt_id
3343              ,P_MTR_ATTRIBUTE1      => r_MTR.INFORMATION111
3344              ,P_MTR_ATTRIBUTE10      => r_MTR.INFORMATION120
3345              ,P_MTR_ATTRIBUTE11      => r_MTR.INFORMATION121
3346              ,P_MTR_ATTRIBUTE12      => r_MTR.INFORMATION122
3347              ,P_MTR_ATTRIBUTE13      => r_MTR.INFORMATION123
3348              ,P_MTR_ATTRIBUTE14      => r_MTR.INFORMATION124
3349              ,P_MTR_ATTRIBUTE15      => r_MTR.INFORMATION125
3350              ,P_MTR_ATTRIBUTE16      => r_MTR.INFORMATION126
3351              ,P_MTR_ATTRIBUTE17      => r_MTR.INFORMATION127
3352              ,P_MTR_ATTRIBUTE18      => r_MTR.INFORMATION128
3353              ,P_MTR_ATTRIBUTE19      => r_MTR.INFORMATION129
3354              ,P_MTR_ATTRIBUTE2      => r_MTR.INFORMATION112
3355              ,P_MTR_ATTRIBUTE20      => r_MTR.INFORMATION130
3356              ,P_MTR_ATTRIBUTE21      => r_MTR.INFORMATION131
3357              ,P_MTR_ATTRIBUTE22      => r_MTR.INFORMATION132
3358              ,P_MTR_ATTRIBUTE23      => r_MTR.INFORMATION133
3359              ,P_MTR_ATTRIBUTE24      => r_MTR.INFORMATION134
3360              ,P_MTR_ATTRIBUTE25      => r_MTR.INFORMATION135
3361              ,P_MTR_ATTRIBUTE26      => r_MTR.INFORMATION136
3362              ,P_MTR_ATTRIBUTE27      => r_MTR.INFORMATION137
3363              ,P_MTR_ATTRIBUTE28      => r_MTR.INFORMATION138
3364              ,P_MTR_ATTRIBUTE29      => r_MTR.INFORMATION139
3365              ,P_MTR_ATTRIBUTE3      => r_MTR.INFORMATION113
3366              ,P_MTR_ATTRIBUTE30      => r_MTR.INFORMATION140
3367              ,P_MTR_ATTRIBUTE4      => r_MTR.INFORMATION114
3368              ,P_MTR_ATTRIBUTE5      => r_MTR.INFORMATION115
3369              ,P_MTR_ATTRIBUTE6      => r_MTR.INFORMATION116
3370              ,P_MTR_ATTRIBUTE7      => r_MTR.INFORMATION117
3371              ,P_MTR_ATTRIBUTE8      => r_MTR.INFORMATION118
3372              ,P_MTR_ATTRIBUTE9      => r_MTR.INFORMATION119
3373              ,P_MTR_ATTRIBUTE_CATEGORY      => r_MTR.INFORMATION110
3374              ,P_MX_AMT_OF_PY_NUM      => r_MTR.INFORMATION296
3375              ,P_MX_MTCH_AMT      => r_MTR.INFORMATION298
3376              ,P_MX_PCT_OF_PY_NUM      => r_MTR.INFORMATION297
3377              ,P_NO_MX_AMT_OF_PY_NUM_FLAG      => r_MTR.INFORMATION14
3378              ,P_NO_MX_MTCH_AMT_FLAG      => r_MTR.INFORMATION11
3379              ,P_NO_MX_PCT_OF_PY_NUM_FLAG      => r_MTR.INFORMATION12
3380              ,P_ORDR_NUM      => r_MTR.INFORMATION257
3381              ,P_PCT_VAL      => r_MTR.INFORMATION295
3382              ,P_TO_PCT_VAL      => r_MTR.INFORMATION294
3383              --
3384              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
3385              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
3386              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
3387            );
3388            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
3389            -- Update all relevent cer records with new pk_id
3390            hr_utility.set_location('Before plsql table ',222);
3391            hr_utility.set_location('new_value id '||l_mtchg_rt_id,222);
3392            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'MTCHG_RT_ID' ;
3393            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_MTR.information1 ;
3394            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_MTCHG_RT_ID ;
3395            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
3396            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_MTR_unique.table_route_id;
3397            hr_utility.set_location('After plsql table ',222);
3398            --
3399            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
3400            --
3401            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
3402            --
3403          else
3404            --
3405            -- Call Update routine for the pk_id created in prev run .
3406            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
3407            hr_utility.set_location(' BEN_MTCHG_RT_F UPDATE_MATCHING_RATES ',30);
3408 
3409             --UPD START
3410            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
3411            --
3412            if l_update then
3413              --
3414              l_datetrack_mode := r_MTR.datetrack_mode ;
3415              --
3416              get_dt_modes(
3417                p_effective_date        => l_process_date,
3418                p_effective_end_date    => r_MTR.information3,
3419                p_effective_start_date  => r_MTR.information2,
3420                p_dml_operation         => r_MTR.dml_operation,
3421                p_datetrack_mode        => l_datetrack_mode );
3422            --    p_update                => l_update
3423              --
3424              l_effective_date := l_process_date;
3425              l_mtchg_rt_id   := r_MTR.information1;
3426              l_object_version_number := r_MTR.information265;
3427              --
3428            end if;
3429            --
3430            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
3431            --
3432            IF l_update OR l_dml_operation <> 'UPDATE' THEN
3433            --UPD END
3434 
3435                    BEN_MATCHING_RATES_API.UPDATE_MATCHING_RATES(
3436                      --
3437                      P_VALIDATE               => false
3438                      ,P_EFFECTIVE_DATE        => l_effective_date
3439                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
3440                      --
3441                      ,P_ACTY_BASE_RT_ID      => l_ACTY_BASE_RT_ID
3442                      ,P_CNTNU_MTCH_AFTR_MX_RL_FLAG      => r_MTR.INFORMATION13
3443                      ,P_COMP_LVL_FCTR_ID      => l_COMP_LVL_FCTR_ID
3444                      ,P_FROM_PCT_VAL      => r_MTR.INFORMATION293
3445                      ,P_MN_MTCH_AMT      => r_MTR.INFORMATION299
3446                      ,P_MTCHG_RT_CALC_RL      => l_MTCHG_RT_CALC_RL
3447                      ,P_MTCHG_RT_ID      => l_mtchg_rt_id
3448                      ,P_MTR_ATTRIBUTE1      => r_MTR.INFORMATION111
3449                      ,P_MTR_ATTRIBUTE10      => r_MTR.INFORMATION120
3450                      ,P_MTR_ATTRIBUTE11      => r_MTR.INFORMATION121
3451                      ,P_MTR_ATTRIBUTE12      => r_MTR.INFORMATION122
3452                      ,P_MTR_ATTRIBUTE13      => r_MTR.INFORMATION123
3453                      ,P_MTR_ATTRIBUTE14      => r_MTR.INFORMATION124
3454                      ,P_MTR_ATTRIBUTE15      => r_MTR.INFORMATION125
3455                      ,P_MTR_ATTRIBUTE16      => r_MTR.INFORMATION126
3456                      ,P_MTR_ATTRIBUTE17      => r_MTR.INFORMATION127
3457                      ,P_MTR_ATTRIBUTE18      => r_MTR.INFORMATION128
3458                      ,P_MTR_ATTRIBUTE19      => r_MTR.INFORMATION129
3459                      ,P_MTR_ATTRIBUTE2      => r_MTR.INFORMATION112
3460                      ,P_MTR_ATTRIBUTE20      => r_MTR.INFORMATION130
3461                      ,P_MTR_ATTRIBUTE21      => r_MTR.INFORMATION131
3462                      ,P_MTR_ATTRIBUTE22      => r_MTR.INFORMATION132
3463                      ,P_MTR_ATTRIBUTE23      => r_MTR.INFORMATION133
3464                      ,P_MTR_ATTRIBUTE24      => r_MTR.INFORMATION134
3465                      ,P_MTR_ATTRIBUTE25      => r_MTR.INFORMATION135
3466                      ,P_MTR_ATTRIBUTE26      => r_MTR.INFORMATION136
3467                      ,P_MTR_ATTRIBUTE27      => r_MTR.INFORMATION137
3468                      ,P_MTR_ATTRIBUTE28      => r_MTR.INFORMATION138
3469                      ,P_MTR_ATTRIBUTE29      => r_MTR.INFORMATION139
3470                      ,P_MTR_ATTRIBUTE3      => r_MTR.INFORMATION113
3471                      ,P_MTR_ATTRIBUTE30      => r_MTR.INFORMATION140
3472                      ,P_MTR_ATTRIBUTE4      => r_MTR.INFORMATION114
3473                      ,P_MTR_ATTRIBUTE5      => r_MTR.INFORMATION115
3474                      ,P_MTR_ATTRIBUTE6      => r_MTR.INFORMATION116
3475                      ,P_MTR_ATTRIBUTE7      => r_MTR.INFORMATION117
3476                      ,P_MTR_ATTRIBUTE8      => r_MTR.INFORMATION118
3477                      ,P_MTR_ATTRIBUTE9      => r_MTR.INFORMATION119
3478                      ,P_MTR_ATTRIBUTE_CATEGORY      => r_MTR.INFORMATION110
3479                      ,P_MX_AMT_OF_PY_NUM      => r_MTR.INFORMATION296
3480                      ,P_MX_MTCH_AMT      => r_MTR.INFORMATION298
3481                      ,P_MX_PCT_OF_PY_NUM      => r_MTR.INFORMATION297
3482                      ,P_NO_MX_AMT_OF_PY_NUM_FLAG      => r_MTR.INFORMATION14
3483                      ,P_NO_MX_MTCH_AMT_FLAG      => r_MTR.INFORMATION11
3484                      ,P_NO_MX_PCT_OF_PY_NUM_FLAG      => r_MTR.INFORMATION12
3485                      ,P_ORDR_NUM      => r_MTR.INFORMATION257
3486                      ,P_PCT_VAL      => r_MTR.INFORMATION295
3487                      ,P_TO_PCT_VAL      => r_MTR.INFORMATION294
3488                      --
3489                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
3490                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
3491                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
3492                      ,P_DATETRACK_MODE        => l_datetrack_mode
3493                      --,P_DATETRACK_MODE        => hr_api.g_update
3494                    );
3495 
3496            end if;  -- l_update
3497 
3498          end if;
3499          --
3500          --
3501          -- Delete the row if it is end dated.
3502          --
3503          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
3504              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
3505              trunc(l_max_eed) = r_MTR.information3) then
3506              --
3507              BEN_MATCHING_RATES_API.delete_MATCHING_RATES(
3508                 --
3509                 p_validate                       => false
3510                 ,p_mtchg_rt_id                   => l_mtchg_rt_id
3511                 ,p_effective_start_date           => l_effective_start_date
3512                 ,p_effective_end_date             => l_effective_end_date
3513                 ,p_object_version_number          => l_object_version_number
3514                 ,p_effective_date                 => l_max_eed
3515                 ,p_datetrack_mode                 => hr_api.g_delete
3516                 --
3517                 );
3518                 --
3519          end if;
3520          --
3521          l_prev_pk_id := l_current_pk_id ;
3522          --
3523        end if;
3524        --
3525      end if;
3526      --
3527    end loop;
3528    --
3529  exception when others then
3530      --
3531      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'MTR',r_MTR.information5 ) ;
3532      --
3533  end create_MTR_rows;
3534 
3535    --
3536    ---------------------------------------------------------------
3537    ----------------------< create_APL1_rows >-----------------------
3538    ---------------------------------------------------------------
3539    --
3540    procedure create_APL1_rows
3541    (
3542          p_validate                       in  number     default 0
3543         ,p_copy_entity_txn_id             in  number
3544         ,p_effective_date                 in  date
3545         ,p_prefix_suffix_text             in  varchar2  default null
3546         ,p_reuse_object_flag              in  varchar2  default null
3547         ,p_target_business_group_id       in  varchar2  default null
3548         ,p_prefix_suffix_cd               in  varchar2  default null
3549    ) is
3550    --
3551    l_ACTY_BASE_RT_ID  number;
3552    l_PTD_LMT_ID  number;
3553    cursor c_unique_APL1(l_table_alias varchar2) is
3554    select distinct cpe.information1,
3555      cpe.information2,
3556      cpe.information3,
3557      cpe.table_route_id,
3558      cpe.dml_operation,
3559      cpe.datetrack_mode
3560    from ben_copy_entity_results cpe,
3561         pqh_table_route tr
3562    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
3563    and   cpe.table_route_id     = tr.table_route_id
3564    -- and   tr.where_clause        = l_BEN_ACTY_RT_PTD_LMT_F
3565    and   tr.table_alias = l_table_alias
3566    and   cpe.number_of_copies   = 1 -- ADDITION
3567    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id ,cpe.dml_operation,cpe.datetrack_mode
3568    order by information1, information2; --added for bug: 5151945
3569    --
3570    --
3571    cursor c_APL1_min_max_dates(c_table_route_id  number,
3572                 c_information1   number) is
3573    select
3574      min(cpe.information2) min_esd,
3575      max(cpe.information3) min_eed
3576    from ben_copy_entity_results cpe
3577    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
3578    and   cpe.table_route_id     = c_table_route_id
3579    and   cpe.information1       = c_information1 ;
3580    --
3581    cursor c_APL1(c_table_route_id  number,
3582                 c_information1   number,
3583                 c_information2   date,
3584                 c_information3   date)  is
3585    select
3586      cpe.*
3587    from ben_copy_entity_results cpe
3588    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
3589    and   cpe.table_route_id     = c_table_route_id
3590    and   cpe.information1       = c_information1
3591    and   cpe.information2       = c_information2
3592    and   cpe.information3       = c_information3
3593    and rownum = 1 ;
3594    -- Date Track target record
3595    cursor c_find_APL1_in_target(
3596                                 c_effective_start_date    date,
3597                                 c_effective_end_date      date,
3598                                 c_business_group_id       number,
3599                                 c_new_pk_id               number) is
3600    select
3601      APL1.acty_rt_ptd_lmt_id new_value
3602    from BEN_ACTY_RT_PTD_LMT_F APL1
3603    where
3604    APL1.ACTY_BASE_RT_ID     = l_ACTY_BASE_RT_ID  and
3605    APL1.PTD_LMT_ID     = l_PTD_LMT_ID  and
3606    APL1.business_group_id  = c_business_group_id
3607    and   APL1.acty_rt_ptd_lmt_id  <> c_new_pk_id
3608 --TEMPIK
3609    and c_effective_start_date between effective_start_date
3610                             and effective_end_date ;
3611 --END TEMPIK
3612 /* TEMPIK
3613    and exists ( select null
3614                 from BEN_ACTY_RT_PTD_LMT_F APL11
3615                 where
3616                 APL11.ACTY_BASE_RT_ID     = l_ACTY_BASE_RT_ID  and
3617                 APL11.PTD_LMT_ID     = l_PTD_LMT_ID  and
3618                 APL11.business_group_id  = c_business_group_id
3619                 and   APL11.effective_start_date <= c_effective_start_date )
3620    and exists ( select null
3621                 from BEN_ACTY_RT_PTD_LMT_F APL12
3622                 where
3623                 APL12.ACTY_BASE_RT_ID     = l_ACTY_BASE_RT_ID  and
3624                 APL12.PTD_LMT_ID     = l_PTD_LMT_ID  and
3625                 APL12.business_group_id  = c_business_group_id
3626                 and   APL12.effective_end_date >= c_effective_end_date )
3627                 ;
3628 TEMPIK */
3629    --TEMPIK
3630    l_dt_rec_found            boolean ;
3631    --END TEMPIK
3632    --
3633 
3634    --UPD START
3635    --
3636    l_update                  boolean      := false ;
3637    l_datetrack_mode          varchar2(80) := hr_api.g_update;
3638    l_process_date            date;
3639    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
3640    --
3641    --UPD END
3642 
3643 
3644    l_current_pk_id           number := null ;
3645    l_prev_pk_id              number := null ;
3646    l_first_rec               boolean := true ;
3647    r_APL1                     c_APL1%rowtype;
3648    l_acty_rt_ptd_lmt_id             number ;
3649    l_object_version_number   number ;
3650    l_effective_start_date    date ;
3651    l_effective_end_date      date ;
3652    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
3653    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
3654    l_new_value               number(15);
3655    l_object_found_in_target  boolean := false ;
3656    l_min_esd                 date;
3657    l_max_eed                 date;
3658    l_effective_date          date;
3659    --
3660  begin
3661    -- Initialization
3662    l_object_found_in_target := false ;
3663    -- End Initialization
3664    -- Derive the prefix - sufix
3665    if   p_prefix_suffix_cd = 'PREFIX' then
3666      l_prefix  := p_prefix_suffix_text ;
3667    elsif p_prefix_suffix_cd = 'SUFFIX' then
3668      l_suffix   := p_prefix_suffix_text ;
3669    else
3670      l_prefix := null ;
3671      l_suffix  := null ;
3672    end if ;
3673    -- End Prefix Sufix derivation
3674    for r_APL1_unique in c_unique_APL1('APL1') loop
3675 
3676      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
3677         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
3678          r_APL1_unique.information3 >=
3679                  ben_pd_copy_to_ben_one.g_copy_effective_date)
3680         ) then
3681        --
3682        hr_utility.set_location(' r_APL1_unique.table_route_id '||r_APL1_unique.table_route_id,10);
3683        hr_utility.set_location(' r_APL1_unique.information1 '||r_APL1_unique.information1,10);
3684        hr_utility.set_location( 'r_APL1_unique.information2 '||r_APL1_unique.information2,10);
3685        hr_utility.set_location( 'r_APL1_unique.information3 '||r_APL1_unique.information3,10);
3686        -- If reuse objects flag is 'Y' then check for the object in the target business group
3687        -- if found insert the record into PLSql table and exit the loop else try create the
3688        -- object in the target business group
3689        --
3690        l_object_found_in_target := false ;
3691 
3692        open c_APL1(r_APL1_unique.table_route_id,
3693                 r_APL1_unique.information1,
3694                 r_APL1_unique.information2,
3695                 r_APL1_unique.information3 ) ;
3696        --
3697        fetch c_APL1 into r_APL1 ;
3698        --
3699        close c_APL1 ;
3700 
3701         --UPD START
3702        l_update := false;
3703        l_process_date := p_effective_date;
3704        l_dml_operation:= r_APL1_unique.dml_operation ;
3705        l_ACTY_BASE_RT_ID := get_fk('ACTY_BASE_RT_ID', r_APL1.information253,r_APL1.dml_operation);
3706        l_PTD_LMT_ID := get_fk('PTD_LMT_ID', r_APL1.information257,r_APL1.dml_operation);
3707        --
3708        if l_dml_operation = 'UPDATE' then
3709          --
3710                  l_object_found_in_target := TRUE;
3711                  --
3712                  if l_process_date between r_APL1_unique.information2 and r_APL1_unique.information3 then
3713                        l_update := true;
3714                        if r_APL1_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
3715                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ACTY_RT_PTD_LMT_ID'
3716                        then
3717                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ACTY_RT_PTD_LMT_ID' ;
3718                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_APL1_unique.information1 ;
3719                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_APL1_unique.information1 ;
3720                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
3721                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_APL1_unique.table_route_id;
3722                           --
3723                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
3724                           --
3725                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
3726                           --
3727                           -- DOUBT
3728                           --BEN_PD_COPY_TO_BEN_ONE.log_data('APL1',l_new_value,l_prefix || r_APL1_unique.name|| l_suffix,'REUSED');
3729                           --
3730                        end if ;
3731                        hr_utility.set_location( 'found record for update',10);
3732                    --
3733                  else
3734                    --
3735                    l_update := false;
3736                    --
3737                  end if;
3738         else
3739         --
3740                --UPD END
3741 
3742                l_min_esd := null ;
3743                l_max_eed := null ;
3744                open c_APL1_min_max_dates(r_APL1_unique.table_route_id, r_APL1_unique.information1 ) ;
3745                fetch c_APL1_min_max_dates into l_min_esd,l_max_eed ;
3746                --
3747 
3748                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
3749                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
3750                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
3751                end if;
3752                l_min_esd := greatest(l_min_esd,r_APL1_unique.information2);
3753                /*open c_APL1(r_APL1_unique.table_route_id,
3754                         r_APL1_unique.information1,
3755                         r_APL1_unique.information2,
3756                         r_APL1_unique.information3 ) ;
3757                --
3758                fetch c_APL1 into r_APL1 ;
3759                --
3760                close c_APL1 ;*/
3761                --
3762                if p_reuse_object_flag = 'Y' then
3763                  if c_APL1_min_max_dates%found then
3764                    -- cursor to find the object
3765                    open c_find_APL1_in_target( l_min_esd,l_max_eed,
3766                                          p_target_business_group_id, nvl(l_acty_rt_ptd_lmt_id, -999)  ) ;
3767                    fetch c_find_APL1_in_target into l_new_value ;
3768                    if c_find_APL1_in_target%found then
3769                      --TEMPIK
3770                      l_dt_rec_found :=   dt_api.check_min_max_dates
3771                          (p_base_table_name => 'BEN_ACTY_RT_PTD_LMT_F',
3772                           p_base_key_column => 'ACTY_RT_PTD_LMT_ID',
3773                           p_base_key_value  => l_new_value,
3774                           p_from_date       => l_min_esd,
3775                           p_to_date         => l_max_eed );
3776                      if l_dt_rec_found THEN
3777                      --END TEMPIK
3778                                          --
3779                                          if r_APL1_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
3780                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'ACTY_RT_PTD_LMT_ID'  then
3781                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'ACTY_RT_PTD_LMT_ID' ;
3782                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_APL1_unique.information1 ;
3783                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
3784                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
3785                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_APL1_unique.table_route_id;
3786                                                 --
3787                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
3788                                                 --
3789                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
3790                                          end if ;
3791                                          --
3792                                          l_object_found_in_target := true ;
3793                      --TEMPIK
3794                      end if; -- l_dt_rec_found
3795                      --END TEMPIK
3796                    end if;
3797                    close c_find_APL1_in_target ;
3798                  --
3799                  end if;
3800                end if ;
3801                --
3802                close c_APL1_min_max_dates ;
3803 
3804        -- UPD START
3805        end if; --if p_dml_operation
3806        --
3807        if not l_object_found_in_target OR l_update  then
3808        --if not l_object_found_in_target then
3809        -- UPD END
3810 
3811          --
3812          l_current_pk_id := r_APL1.information1;
3813          --
3814          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
3815          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
3816          --
3817          if l_current_pk_id =  l_prev_pk_id  then
3818            --
3819            l_first_rec := false ;
3820            --
3821          else
3822            --
3823            l_first_rec := true ;
3824            --
3825          end if ;
3826          --
3827 
3828          l_effective_date := r_APL1.information2;
3829          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
3830               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
3831            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
3832          end if;
3833          -- UPD START
3834          -- if l_first_rec then
3835          if l_first_rec and not l_update then
3836          -- UPD END
3837            -- Call Create routine.
3838            hr_utility.set_location(' BEN_ACTY_RT_PTD_LMT_F CREATE_ACTY_RT_PTD_LMT ',20);
3839            BEN_ACTY_RT_PTD_LMT_API.CREATE_ACTY_RT_PTD_LMT(
3840              --
3841              P_VALIDATE               => false
3842              ,P_EFFECTIVE_DATE        => l_effective_date
3843              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
3844              --
3845              ,P_ACTY_BASE_RT_ID      => l_ACTY_BASE_RT_ID
3846              ,P_ACTY_RT_PTD_LMT_ID      => l_acty_rt_ptd_lmt_id
3847              ,P_APL_ATTRIBUTE1      => r_APL1.INFORMATION111
3848              ,P_APL_ATTRIBUTE10      => r_APL1.INFORMATION120
3849              ,P_APL_ATTRIBUTE11      => r_APL1.INFORMATION121
3850              ,P_APL_ATTRIBUTE12      => r_APL1.INFORMATION122
3851              ,P_APL_ATTRIBUTE13      => r_APL1.INFORMATION123
3852              ,P_APL_ATTRIBUTE14      => r_APL1.INFORMATION124
3853              ,P_APL_ATTRIBUTE15      => r_APL1.INFORMATION125
3854              ,P_APL_ATTRIBUTE16      => r_APL1.INFORMATION126
3855              ,P_APL_ATTRIBUTE17      => r_APL1.INFORMATION127
3856              ,P_APL_ATTRIBUTE18      => r_APL1.INFORMATION128
3857              ,P_APL_ATTRIBUTE19      => r_APL1.INFORMATION129
3858              ,P_APL_ATTRIBUTE2      => r_APL1.INFORMATION112
3859              ,P_APL_ATTRIBUTE20      => r_APL1.INFORMATION130
3860              ,P_APL_ATTRIBUTE21      => r_APL1.INFORMATION131
3861              ,P_APL_ATTRIBUTE22      => r_APL1.INFORMATION132
3862              ,P_APL_ATTRIBUTE23      => r_APL1.INFORMATION133
3863              ,P_APL_ATTRIBUTE24      => r_APL1.INFORMATION134
3864              ,P_APL_ATTRIBUTE25      => r_APL1.INFORMATION135
3865              ,P_APL_ATTRIBUTE26      => r_APL1.INFORMATION136
3866              ,P_APL_ATTRIBUTE27      => r_APL1.INFORMATION137
3867              ,P_APL_ATTRIBUTE28      => r_APL1.INFORMATION138
3868              ,P_APL_ATTRIBUTE29      => r_APL1.INFORMATION139
3869              ,P_APL_ATTRIBUTE3      => r_APL1.INFORMATION113
3870              ,P_APL_ATTRIBUTE30      => r_APL1.INFORMATION140
3871              ,P_APL_ATTRIBUTE4      => r_APL1.INFORMATION114
3872              ,P_APL_ATTRIBUTE5      => r_APL1.INFORMATION115
3873              ,P_APL_ATTRIBUTE6      => r_APL1.INFORMATION116
3874              ,P_APL_ATTRIBUTE7      => r_APL1.INFORMATION117
3875              ,P_APL_ATTRIBUTE8      => r_APL1.INFORMATION118
3876              ,P_APL_ATTRIBUTE9      => r_APL1.INFORMATION119
3877              ,P_APL_ATTRIBUTE_CATEGORY      => r_APL1.INFORMATION110
3878              ,P_PTD_LMT_ID      => l_PTD_LMT_ID
3879              --
3880              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
3881              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
3882              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
3883            );
3884            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
3885            -- Update all relevent cer records with new pk_id
3886            hr_utility.set_location('Before plsql table ',222);
3887            hr_utility.set_location('new_value id '||l_acty_rt_ptd_lmt_id,222);
3888            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'ACTY_RT_PTD_LMT_ID' ;
3889            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_APL1.information1 ;
3890            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_ACTY_RT_PTD_LMT_ID ;
3891            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
3892            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_APL1_unique.table_route_id;
3893            hr_utility.set_location('After plsql table ',222);
3894            --
3895            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
3896            --
3897            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
3898            --
3899          else
3900            --
3901            -- Call Update routine for the pk_id created in prev run .
3902            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
3903            hr_utility.set_location(' BEN_ACTY_RT_PTD_LMT_F UPDATE_ACTY_RT_PTD_LMT ',30);
3904 
3905             --UPD START
3906            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
3907            --
3908            if l_update then
3909              --
3910              l_datetrack_mode := r_APL1.datetrack_mode ;
3911              --
3912              get_dt_modes(
3913                p_effective_date        => l_process_date,
3914                p_effective_end_date    => r_APL1.information3,
3915                p_effective_start_date  => r_APL1.information2,
3916                p_dml_operation         => r_APL1.dml_operation,
3917                p_datetrack_mode        => l_datetrack_mode );
3918            --    p_update                => l_update
3919              --
3920              l_effective_date := l_process_date;
3921              l_acty_rt_ptd_lmt_id  := r_APL1.information1;
3922              l_object_version_number := r_APL1.information265;
3923              --
3924            end if;
3925            --
3926            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
3927            --
3928            IF l_update OR l_dml_operation <> 'UPDATE' THEN
3929            --UPD END
3930 
3931                    BEN_ACTY_RT_PTD_LMT_API.UPDATE_ACTY_RT_PTD_LMT(
3932                      --
3933                      P_VALIDATE               => false
3934                      ,P_EFFECTIVE_DATE        => l_effective_date
3935                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
3936                      --
3937                      ,P_ACTY_BASE_RT_ID      => l_ACTY_BASE_RT_ID
3938                      ,P_ACTY_RT_PTD_LMT_ID      => l_acty_rt_ptd_lmt_id
3939                      ,P_APL_ATTRIBUTE1      => r_APL1.INFORMATION111
3940                      ,P_APL_ATTRIBUTE10      => r_APL1.INFORMATION120
3941                      ,P_APL_ATTRIBUTE11      => r_APL1.INFORMATION121
3942                      ,P_APL_ATTRIBUTE12      => r_APL1.INFORMATION122
3943                      ,P_APL_ATTRIBUTE13      => r_APL1.INFORMATION123
3944                      ,P_APL_ATTRIBUTE14      => r_APL1.INFORMATION124
3945                      ,P_APL_ATTRIBUTE15      => r_APL1.INFORMATION125
3946                      ,P_APL_ATTRIBUTE16      => r_APL1.INFORMATION126
3947                      ,P_APL_ATTRIBUTE17      => r_APL1.INFORMATION127
3948                      ,P_APL_ATTRIBUTE18      => r_APL1.INFORMATION128
3949                      ,P_APL_ATTRIBUTE19      => r_APL1.INFORMATION129
3950                      ,P_APL_ATTRIBUTE2      => r_APL1.INFORMATION112
3951                      ,P_APL_ATTRIBUTE20      => r_APL1.INFORMATION130
3952                      ,P_APL_ATTRIBUTE21      => r_APL1.INFORMATION131
3953                      ,P_APL_ATTRIBUTE22      => r_APL1.INFORMATION132
3954                      ,P_APL_ATTRIBUTE23      => r_APL1.INFORMATION133
3955                      ,P_APL_ATTRIBUTE24      => r_APL1.INFORMATION134
3956                      ,P_APL_ATTRIBUTE25      => r_APL1.INFORMATION135
3957                      ,P_APL_ATTRIBUTE26      => r_APL1.INFORMATION136
3958                      ,P_APL_ATTRIBUTE27      => r_APL1.INFORMATION137
3959                      ,P_APL_ATTRIBUTE28      => r_APL1.INFORMATION138
3960                      ,P_APL_ATTRIBUTE29      => r_APL1.INFORMATION139
3961                      ,P_APL_ATTRIBUTE3      => r_APL1.INFORMATION113
3962                      ,P_APL_ATTRIBUTE30      => r_APL1.INFORMATION140
3963                      ,P_APL_ATTRIBUTE4      => r_APL1.INFORMATION114
3964                      ,P_APL_ATTRIBUTE5      => r_APL1.INFORMATION115
3965                      ,P_APL_ATTRIBUTE6      => r_APL1.INFORMATION116
3966                      ,P_APL_ATTRIBUTE7      => r_APL1.INFORMATION117
3967                      ,P_APL_ATTRIBUTE8      => r_APL1.INFORMATION118
3968                      ,P_APL_ATTRIBUTE9      => r_APL1.INFORMATION119
3969                      ,P_APL_ATTRIBUTE_CATEGORY      => r_APL1.INFORMATION110
3970                      ,P_PTD_LMT_ID      => l_PTD_LMT_ID
3971 
3972                      --
3973                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
3974                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
3975                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
3976                      -- UPD START
3977                      -- ,P_DATETRACK_MODE        => hr_api.g_update
3978                      ,P_DATETRACK_MODE        => l_datetrack_mode
3979                      -- UPD END
3980                    );
3981               end if;  -- l_update
3982          end if;
3983          --
3984          --
3985          -- Delete the row if it is end dated.
3986          --
3987          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
3988              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
3989            trunc(l_max_eed) = r_APL1.information3) then
3990              --
3991              BEN_ACTY_RT_PTD_LMT_API.delete_ACTY_RT_PTD_LMT(
3992                 --
3993                 p_validate                       => false
3994                 ,p_acty_rt_ptd_lmt_id                   => l_acty_rt_ptd_lmt_id
3995                 ,p_effective_start_date           => l_effective_start_date
3996                 ,p_effective_end_date             => l_effective_end_date
3997                 ,p_object_version_number          => l_object_version_number
3998                 ,p_effective_date                 => l_max_eed
3999                 ,p_datetrack_mode                 => hr_api.g_delete
4000                 --
4001                 );
4002                 --
4003          end if;
4004          --
4005          l_prev_pk_id := l_current_pk_id ;
4006          --
4007        end if;
4008        --
4009      end if;
4010      --
4011    end loop;
4012    --
4013  exception when others then
4014      --
4015      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'APL1',r_APL1.information5 ) ;
4016      --
4017  end create_APL1_rows;
4018 
4019    --
4020    ---------------------------------------------------------------
4021    ----------------------< create_APR_rows >-----------------------
4022    ---------------------------------------------------------------
4023    --
4024    procedure create_APR_rows
4025    (
4026          p_validate                       in  number     default 0
4027         ,p_copy_entity_txn_id             in  number
4028         ,p_effective_date                 in  date
4029         ,p_prefix_suffix_text             in  varchar2  default null
4030         ,p_reuse_object_flag              in  varchar2  default null
4031         ,p_target_business_group_id       in  varchar2  default null
4032         ,p_prefix_suffix_cd               in  varchar2  default null
4033    ) is
4034    --
4035    l_COMP_LVL_FCTR_ID  number;
4036    l_COST_ALLOCATION_KEYFLEX_ID  number;
4037    l_LWR_LMT_CALC_RL  number;
4038    l_OIPL_ID  number;
4039    l_ORGANIZATION_ID  number;
4040    l_PL_ID  number;
4041    l_PRTL_MO_DET_MTHD_RL  number;
4042    l_RNDG_RL  number;
4043    l_UPR_LMT_CALC_RL  number;
4044    l_VAL_CALC_RL  number;
4045    l_VRBL_RT_ADD_ON_CALC_RL  number;
4046    cursor c_unique_APR(l_table_alias varchar2) is
4047    select distinct cpe.information1,
4048      cpe.information2,
4049      cpe.information3,
4050      cpe.information170 name,
4051      cpe.table_route_id,
4052      cpe.dml_operation,
4053      cpe.datetrack_mode
4054    from ben_copy_entity_results cpe,
4055         pqh_table_route tr
4056    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
4057    and   cpe.table_route_id     = tr.table_route_id
4058    -- and   tr.where_clause        = l_BEN_ACTL_PREM_F
4059    and   tr.table_alias = l_table_alias
4060    and   cpe.number_of_copies   = 1 -- ADDITION
4061    group by cpe.information1,cpe.information2,cpe.information3, cpe.information170, cpe.table_route_id ,cpe.dml_operation,cpe.datetrack_mode
4062    order by information1, information2; --added for bug: 5151945
4063    --
4064    --
4065    cursor c_APR_min_max_dates(c_table_route_id  number,
4066                 c_information1   number) is
4067    select
4068      min(cpe.information2) min_esd,
4069      max(cpe.information3) min_eed
4070    from ben_copy_entity_results cpe
4071    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
4072    and   cpe.table_route_id     = c_table_route_id
4073    and   cpe.information1       = c_information1 ;
4074    --
4075    cursor c_APR(c_table_route_id  number,
4076                 c_information1   number,
4077                 c_information2   date,
4078                 c_information3   date)  is
4079    select
4080      cpe.*
4081    from ben_copy_entity_results cpe
4082    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
4083    and   cpe.table_route_id     = c_table_route_id
4084    and   cpe.information1       = c_information1
4085    and   cpe.information2       = c_information2
4086    and   cpe.information3       = c_information3
4087    and rownum = 1 ;
4088    -- Date Track target record
4089    cursor c_find_APR_in_target( c_APR_name           varchar2,
4090                                 c_effective_start_date    date,
4091                                 c_effective_end_date      date,
4092                                 c_business_group_id       number,
4093                                 c_new_pk_id               number) is
4094    select
4095      APR.actl_prem_id new_value
4096    from BEN_ACTL_PREM_F APR
4097    where
4098    APR.name               = c_APR_name and
4099    nvl(APR.OIPL_ID,-999)     = nvl(l_OIPL_ID,-999)  and
4100    nvl(APR.PL_ID,-999)     = nvl(l_PL_ID,-999)  and
4101    APR.business_group_id  = c_business_group_id
4102    and   APR.actl_prem_id  <> c_new_pk_id
4103 --TEMPIK
4104    and c_effective_start_date between effective_start_date
4105                             and effective_end_date ;
4106 --END TEMPIK
4107 /*TEMPIK
4108         and exists ( select null
4109                 from BEN_ACTL_PREM_F APR1
4110                 where
4111                    APR1.name               = c_APR_name and
4112                 nvl(APR1.OIPL_ID,-999)     = nvl(l_OIPL_ID,-999)  and
4113                 nvl(APR1.PL_ID,-999)     = nvl(l_PL_ID,-999)  and
4114                 APR1.business_group_id  = c_business_group_id
4115                 and   APR1.effective_start_date <= c_effective_start_date )
4116    and exists ( select null
4117                 from BEN_ACTL_PREM_F APR2
4118                 where
4119                    APR2.name               = c_APR_name and
4120                 nvl(APR2.OIPL_ID,-999)     = nvl(l_OIPL_ID,-999)  and
4121                 nvl(APR2.PL_ID,-999)     = nvl(l_PL_ID,-999)  and
4122                 APR2.business_group_id  = c_business_group_id
4123                 and   APR2.effective_end_date >= c_effective_end_date )
4124                 ;
4125 TEMPIK */
4126    --TEMPIK
4127    l_dt_rec_found            boolean ;
4128    --END TEMPIK
4129    --
4130    cursor c_find_APR_name_in_target( c_APR_name           varchar2,
4131                                 c_effective_start_date    date,
4132                                 c_effective_end_date      date,
4133                                 c_business_group_id       number,
4134                                 c_new_pk_id               number) is
4135    select
4136      APR.actl_prem_id new_value
4137    from BEN_ACTL_PREM_F APR
4138    where
4139    APR.name               = c_APR_name and
4140    APR.business_group_id  = c_business_group_id
4141    and   APR.actl_prem_id  <> c_new_pk_id
4142 --TEMPIK
4143    and c_effective_start_date between effective_start_date
4144                             and effective_end_date ;
4145 --END TEMPIK
4146 /*TEMPIK
4147    and exists ( select null
4148                 from BEN_ACTL_PREM_F APR1
4149                 where
4150                    APR1.name               = c_APR_name and
4151                 APR1.business_group_id  = c_business_group_id
4152                 and   APR1.effective_start_date <= c_effective_start_date )
4153    and exists ( select null
4154                 from BEN_ACTL_PREM_F APR2
4155                 where
4156                  APR2.name               = c_APR_name and
4157                 APR2.business_group_id  = c_business_group_id
4158                 and   APR2.effective_end_date >= c_effective_end_date )
4159                 ;
4160 TEMPIK */
4161 
4162    --UPD START
4163    --
4164    l_update                  boolean      := false ;
4165    l_datetrack_mode          varchar2(80) := hr_api.g_update;
4166    l_process_date            date;
4167    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
4168    --
4169    --UPD END
4170 
4171 
4172    l_current_pk_id           number := null ;
4173    l_prev_pk_id              number := null ;
4174    l_first_rec               boolean := true ;
4175    r_APR                     c_APR%rowtype;
4176    l_actl_prem_id             number ;
4177    l_object_version_number   number ;
4178    l_effective_start_date    date ;
4179    l_effective_end_date      date ;
4180    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
4181    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
4182    l_new_value               number(15);
4183    l_object_found_in_target  boolean := false ;
4184    l_min_esd                 date;
4185    l_max_eed                 date;
4186    l_effective_date          date;
4187    --
4188  begin
4189    -- Initialization
4190    l_object_found_in_target := false ;
4191    -- End Initialization
4192    -- Derive the prefix - sufix
4193    -- End Prefix Sufix derivation
4194    for r_APR_unique in c_unique_APR('APR') loop
4195 
4196      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
4197         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
4198          r_APR_unique.information3 >=
4199                  ben_pd_copy_to_ben_one.g_copy_effective_date)
4200         ) then
4201        --
4202        if   p_prefix_suffix_cd = 'PREFIX' then
4203          l_prefix  := p_prefix_suffix_text ;
4204        elsif p_prefix_suffix_cd = 'SUFFIX' then
4205          l_suffix   := p_prefix_suffix_text ;
4206        else
4207          l_prefix := null ;
4208          l_suffix  := null ;
4209        end if ;
4210        --
4211        hr_utility.set_location(' r_APR_unique.table_route_id '||r_APR_unique.table_route_id,10);
4212        hr_utility.set_location(' r_APR_unique.information1 '||r_APR_unique.information1,10);
4213        hr_utility.set_location( 'r_APR_unique.information2 '||r_APR_unique.information2,10);
4214        hr_utility.set_location( 'r_APR_unique.information3 '||r_APR_unique.information3,10);
4215        -- If reuse objects flag is 'Y' then check for the object in the target business group
4216        -- if found insert the record into PLSql table and exit the loop else try create the
4217        -- object in the target business group
4218        --
4219        l_object_found_in_target := false ;
4220         --UPD START
4221        l_update := false;
4222        l_process_date := p_effective_date;
4223        l_dml_operation:= r_APR_unique.dml_operation ;
4224        open c_APR(r_APR_unique.table_route_id,
4225                 r_APR_unique.information1,
4226                 r_APR_unique.information2,
4227                 r_APR_unique.information3 ) ;
4228        --
4229        fetch c_APR into r_APR ;
4230        --
4231        close c_APR ;
4232        --
4233        l_COMP_LVL_FCTR_ID := get_fk('COMP_LVL_FCTR_ID', r_APR.information254,r_APR.dml_operation);
4234        l_COST_ALLOCATION_KEYFLEX_ID := get_fk('COST_ALLOCATION_KEYFLEX_ID', r_APR.information270,r_APR.dml_operation);
4235        l_LWR_LMT_CALC_RL := get_fk('FORMULA_ID', r_APR.information268,r_APR.dml_operation);
4236        l_OIPL_ID := get_fk('OIPL_ID', r_APR.information258,r_APR.dml_operation);
4237        l_ORGANIZATION_ID := get_fk('ORGANIZATION_ID', r_APR.information252,r_APR.dml_operation);
4238        l_PL_ID := get_fk('PL_ID', r_APR.information261,r_APR.dml_operation);
4239        l_PRTL_MO_DET_MTHD_RL := get_fk('FORMULA_ID', r_APR.information263,r_APR.dml_operation);
4240        l_RNDG_RL := get_fk('FORMULA_ID', r_APR.information264,r_APR.dml_operation);
4241        l_UPR_LMT_CALC_RL := get_fk('FORMULA_ID', r_APR.information267,r_APR.dml_operation);
4242        l_VAL_CALC_RL := get_fk('FORMULA_ID', r_APR.information266,r_APR.dml_operation);
4243        l_VRBL_RT_ADD_ON_CALC_RL := get_fk('FORMULA_ID', r_APR.information269,r_APR.dml_operation);
4244        --
4245        if l_dml_operation = 'UPDATE' then
4246          --
4247                  l_object_found_in_target := TRUE;
4248                  --
4249                  if l_process_date between r_APR_unique.information2 and r_APR_unique.information3 then
4250                        l_update := true;
4251                        if r_APR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
4252                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ACTL_PREM_ID'
4253                        then
4254                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ACTL_PREM_ID' ;
4255                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_APR_unique.information1 ;
4256                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_APR_unique.information1 ;
4257                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
4258                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_APR_unique.table_route_id;
4259                           --
4260                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
4261                           --
4262                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
4263                           --
4264                           BEN_PD_COPY_TO_BEN_ONE.log_data('APR',l_new_value,l_prefix || r_APR_unique.name|| l_suffix,'REUSED');
4265                           --
4266                        end if ;
4267                        hr_utility.set_location( 'found record for update',10);
4268                    --
4269                  else
4270                    --
4271                    l_update := false;
4272                    --
4273                  end if;
4274        else
4275        --
4276        --UPD END
4277 
4278                l_min_esd := null ;
4279                l_max_eed := null ;
4280                open c_APR_min_max_dates(r_APR_unique.table_route_id, r_APR_unique.information1 ) ;
4281                fetch c_APR_min_max_dates into l_min_esd,l_max_eed ;
4282                --
4283 
4284                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
4285                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
4286                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
4287                end if;
4288                l_min_esd := greatest(l_min_esd,r_APR_unique.information2);
4289                /*
4290                open c_APR(r_APR_unique.table_route_id,
4291                         r_APR_unique.information1,
4292                         r_APR_unique.information2,
4293                         r_APR_unique.information3 ) ;
4294                --
4295                fetch c_APR into r_APR ;
4296                --
4297                close c_APR ;
4298                --
4299                */
4300                if p_reuse_object_flag = 'Y' then
4301                  if c_APR_min_max_dates%found then
4302                    -- cursor to find the object
4303                    open c_find_APR_in_target( l_prefix || r_APR_unique.name|| l_suffix  ,l_min_esd,l_max_eed,
4304                                          p_target_business_group_id, nvl(l_actl_prem_id, -999)  ) ;
4305                    fetch c_find_APR_in_target into l_new_value ;
4306                    if c_find_APR_in_target%found then
4307                      --TEMPIK
4308                      l_dt_rec_found :=   dt_api.check_min_max_dates
4309                          (p_base_table_name => 'BEN_ACTL_PREM_F',
4310                           p_base_key_column => 'ACTL_PREM_ID',
4311                           p_base_key_value  => l_new_value,
4312                           p_from_date       => l_min_esd,
4313                           p_to_date         => l_max_eed );
4314                      if l_dt_rec_found THEN
4315                      --END TEMPIK             --
4316                                          if r_APR_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
4317                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'ACTL_PREM_ID'  then
4318                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'ACTL_PREM_ID' ;
4319                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_APR_unique.information1 ;
4320                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
4321                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
4322                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_APR_unique.table_route_id;
4323                                                 --
4324                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
4325                                                 --
4326                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
4327                                                 --
4328                                                 ben_pd_copy_to_ben_one.log_data('APR',l_new_value,l_prefix || r_APR_unique.name|| l_suffix,'REUSED');
4329                                                 --
4330                                          end if ;
4331                                          --
4332                                          l_object_found_in_target := true ;
4333                      --TEMPIK
4334                      end if; -- l_dt_rec_found
4335                      --END TEMPIK
4336                    else
4337                      -- NEW
4338                      if p_prefix_suffix_text is null then
4339                        --
4340                        open c_find_APR_name_in_target( l_prefix || r_APR_unique.name|| l_suffix  ,
4341                                        l_min_esd,l_max_eed,
4342                                        p_target_business_group_id, nvl(l_actl_prem_id, -999) ) ;
4343                        fetch c_find_APR_name_in_target into l_new_value ;
4344                        if c_find_APR_name_in_target%found then
4345                          --
4346                                          --TEMPIK
4347                                          l_dt_rec_found :=   dt_api.check_min_max_dates
4348                                                  (p_base_table_name => 'BEN_ACTL_PREM_F',
4349                                                   p_base_key_column => 'ACTL_PREM_ID',
4350                                                   p_base_key_value  => l_new_value,
4351                                                   p_from_date       => l_min_esd,
4352                                                   p_to_date         => l_max_eed );
4353                                          if l_dt_rec_found THEN
4354                                          --END TEMPIK             --
4355                                                  if   p_prefix_suffix_cd = 'PREFIX' then
4356                                                    l_prefix  := BEN_PLAN_DESIGN_TXNS_API.g_pgm_pl_prefix_suffix_text ;
4357                                                  elsif p_prefix_suffix_cd = 'SUFFIX' then
4358                                                    l_suffix   := BEN_PLAN_DESIGN_TXNS_API.g_pgm_pl_prefix_suffix_text ;
4359                                                  else
4360                                                    l_prefix := null ;
4361                                                    l_suffix  := null ;
4362                                                  end if ;
4363                                          --TEMPIK
4364                                          end if; -- l_dt_rec_found
4365                                          --END TEMPIK
4366                          --
4367                        end if;
4368                      close c_find_APR_name_in_target ;
4369                      end if;
4370                    end if;
4371                    close c_find_APR_in_target ;
4372                  --
4373                  end if;
4374                end if ;
4375                --
4376                close c_APR_min_max_dates ;
4377        -- UPD START
4378        --if not l_object_found_in_target then
4379        end if; --if p_dml_operation
4380        -- UPD END
4381        --
4382        if not l_object_found_in_target OR l_update  then
4383 
4384          --
4385          l_current_pk_id := r_APR.information1;
4386          --
4387          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
4388          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
4389          --
4390          if l_current_pk_id =  l_prev_pk_id  then
4391            --
4392            l_first_rec := false ;
4393            --
4394          else
4395            --
4396            l_first_rec := true ;
4397            --
4398          end if ;
4399          --
4400          ben_pd_copy_to_ben_one.ben_chk_col_len('NAME' ,'BEN_ACTL_PREM_F',l_prefix || r_APR.information170 || l_suffix);
4401          --
4402 
4403          l_effective_date := r_APR.information2;
4404          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
4405               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
4406            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
4407          end if;
4408          -- UPD START
4409          --if l_first_rec then
4410          if l_first_rec and not l_update then
4411          -- UPD END
4412            -- Call Create routine.
4413            hr_utility.set_location(' BEN_ACTL_PREM_F CREATE_ACTUAL_PREMIUM ',20);
4414            BEN_ACTUAL_PREMIUM_API.CREATE_ACTUAL_PREMIUM(
4415              --
4416              P_VALIDATE               => false
4417              ,P_EFFECTIVE_DATE        => l_effective_date
4418              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
4419              --
4420              ,P_ACTL_PREM_ID      => l_actl_prem_id
4421              ,P_ACTL_PREM_TYP_CD      => r_APR.INFORMATION22
4422              ,P_ACTY_REF_PERD_CD      => r_APR.INFORMATION11
4423              ,P_APR_ATTRIBUTE1      => r_APR.INFORMATION111
4424              ,P_APR_ATTRIBUTE10      => r_APR.INFORMATION120
4425              ,P_APR_ATTRIBUTE11      => r_APR.INFORMATION121
4426              ,P_APR_ATTRIBUTE12      => r_APR.INFORMATION122
4427              ,P_APR_ATTRIBUTE13      => r_APR.INFORMATION123
4428              ,P_APR_ATTRIBUTE14      => r_APR.INFORMATION124
4429              ,P_APR_ATTRIBUTE15      => r_APR.INFORMATION125
4430              ,P_APR_ATTRIBUTE16      => r_APR.INFORMATION126
4431              ,P_APR_ATTRIBUTE17      => r_APR.INFORMATION127
4432              ,P_APR_ATTRIBUTE18      => r_APR.INFORMATION128
4433              ,P_APR_ATTRIBUTE19      => r_APR.INFORMATION129
4434              ,P_APR_ATTRIBUTE2      => r_APR.INFORMATION112
4435              ,P_APR_ATTRIBUTE20      => r_APR.INFORMATION130
4436              ,P_APR_ATTRIBUTE21      => r_APR.INFORMATION131
4437              ,P_APR_ATTRIBUTE22      => r_APR.INFORMATION132
4438              ,P_APR_ATTRIBUTE23      => r_APR.INFORMATION133
4439              ,P_APR_ATTRIBUTE24      => r_APR.INFORMATION134
4440              ,P_APR_ATTRIBUTE25      => r_APR.INFORMATION135
4441              ,P_APR_ATTRIBUTE26      => r_APR.INFORMATION136
4442              ,P_APR_ATTRIBUTE27      => r_APR.INFORMATION137
4443              ,P_APR_ATTRIBUTE28      => r_APR.INFORMATION138
4444              ,P_APR_ATTRIBUTE29      => r_APR.INFORMATION139
4445              ,P_APR_ATTRIBUTE3      => r_APR.INFORMATION113
4446              ,P_APR_ATTRIBUTE30      => r_APR.INFORMATION140
4447              ,P_APR_ATTRIBUTE4      => r_APR.INFORMATION114
4448              ,P_APR_ATTRIBUTE5      => r_APR.INFORMATION115
4449              ,P_APR_ATTRIBUTE6      => r_APR.INFORMATION116
4450              ,P_APR_ATTRIBUTE7      => r_APR.INFORMATION117
4451              ,P_APR_ATTRIBUTE8      => r_APR.INFORMATION118
4452              ,P_APR_ATTRIBUTE9      => r_APR.INFORMATION119
4453              ,P_APR_ATTRIBUTE_CATEGORY      => r_APR.INFORMATION110
4454              ,P_BNFT_RT_TYP_CD      => r_APR.INFORMATION16
4455              ,P_COMP_LVL_FCTR_ID      => l_COMP_LVL_FCTR_ID
4456              ,P_COST_ALLOCATION_KEYFLEX_ID      => l_COST_ALLOCATION_KEYFLEX_ID
4457              ,P_CR_LKBK_CRNT_PY_ONLY_FLAG      => r_APR.INFORMATION13
4458              ,P_CR_LKBK_UOM      => r_APR.INFORMATION24
4459              ,P_CR_LKBK_VAL      => r_APR.INFORMATION293
4460              ,P_LWR_LMT_CALC_RL      => l_LWR_LMT_CALC_RL
4461              ,P_LWR_LMT_VAL      => r_APR.INFORMATION295
4462              ,P_MLT_CD      => r_APR.INFORMATION17
4463              ,P_NAME      => l_prefix || r_APR.INFORMATION170 || l_suffix
4464              ,P_OIPL_ID      => l_OIPL_ID
4465              ,P_ORGANIZATION_ID      => l_ORGANIZATION_ID
4466              ,P_PL_ID      => l_PL_ID
4467              ,P_PRDCT_CD      => r_APR.INFORMATION18
4468              ,P_PREM_ASNMT_CD      => r_APR.INFORMATION20
4469              ,P_PREM_ASNMT_LVL_CD      => r_APR.INFORMATION21
4470              ,P_PREM_PYR_CD      => r_APR.INFORMATION23
4471              ,P_PRSPTV_R_RTSPTV_CD      => r_APR.INFORMATION25
4472              ,P_PRTL_MO_DET_MTHD_CD      => r_APR.INFORMATION14
4473              ,P_PRTL_MO_DET_MTHD_RL      => l_PRTL_MO_DET_MTHD_RL
4474              ,P_RNDG_CD      => r_APR.INFORMATION19
4475              ,P_RNDG_RL      => l_RNDG_RL
4476              ,P_RT_TYP_CD      => r_APR.INFORMATION15
4477              ,P_UOM      => r_APR.INFORMATION12
4478              ,P_UPR_LMT_CALC_RL      => l_UPR_LMT_CALC_RL
4479              ,P_UPR_LMT_VAL      => r_APR.INFORMATION294
4480              ,P_VAL      => r_APR.INFORMATION287
4481              ,P_VAL_CALC_RL      => l_VAL_CALC_RL
4482              ,P_VRBL_RT_ADD_ON_CALC_RL      => l_VRBL_RT_ADD_ON_CALC_RL
4483              ,P_WSH_RL_DY_MO_NUM      => r_APR.INFORMATION257
4484              --
4485              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
4486              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
4487              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
4488            );
4489            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
4490            -- Update all relevent cer records with new pk_id
4491            hr_utility.set_location('Before plsql table ',222);
4492            hr_utility.set_location('new_value id '||l_actl_prem_id,222);
4493            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'ACTL_PREM_ID' ;
4494            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_APR.information1 ;
4495            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_ACTL_PREM_ID ;
4496            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
4497            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_APR_unique.table_route_id;
4498            hr_utility.set_location('After plsql table ',222);
4499            --
4500            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
4501            --
4502            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
4503            ben_pd_copy_to_ben_one.log_data('APR',l_new_value,l_prefix || r_APR.information170|| l_suffix,'COPIED');
4504            --
4505          else
4506            --
4507            -- Call Update routine for the pk_id created in prev run .
4508            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
4509            hr_utility.set_location(' BEN_ACTL_PREM_F UPDATE_ACTUAL_PREMIUM ',30);
4510 
4511             --UPD START
4512            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
4513            --
4514            if l_update then
4515              --
4516              l_datetrack_mode := r_APR.datetrack_mode ;
4517              --
4518              get_dt_modes(
4519                p_effective_date        => l_process_date,
4520                p_effective_end_date    => r_APR.information3,
4521                p_effective_start_date  => r_APR.information2,
4522                p_dml_operation         => r_APR.dml_operation,
4523                p_datetrack_mode        => l_datetrack_mode );
4524            --    p_update                => l_update
4525              --
4526              l_effective_date := l_process_date;
4527              l_actl_prem_id   := r_APR.information1;
4528              l_object_version_number := r_APR.information265;
4529              --
4530            end if;
4531            --
4532            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
4533            --
4534            IF l_update OR l_dml_operation <> 'UPDATE' THEN
4535            --UPD END
4536 
4537                    BEN_ACTUAL_PREMIUM_API.UPDATE_ACTUAL_PREMIUM(
4538                      --
4539                      P_VALIDATE               => false
4540                      ,P_EFFECTIVE_DATE        => l_effective_date
4541                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
4542                      --
4543                      ,P_ACTL_PREM_ID      => l_actl_prem_id
4544                      ,P_ACTL_PREM_TYP_CD      => r_APR.INFORMATION22
4545                      ,P_ACTY_REF_PERD_CD      => r_APR.INFORMATION11
4546                      ,P_APR_ATTRIBUTE1      => r_APR.INFORMATION111
4547                      ,P_APR_ATTRIBUTE10      => r_APR.INFORMATION120
4548                      ,P_APR_ATTRIBUTE11      => r_APR.INFORMATION121
4549                      ,P_APR_ATTRIBUTE12      => r_APR.INFORMATION122
4550                      ,P_APR_ATTRIBUTE13      => r_APR.INFORMATION123
4551                      ,P_APR_ATTRIBUTE14      => r_APR.INFORMATION124
4552                      ,P_APR_ATTRIBUTE15      => r_APR.INFORMATION125
4553                      ,P_APR_ATTRIBUTE16      => r_APR.INFORMATION126
4554                      ,P_APR_ATTRIBUTE17      => r_APR.INFORMATION127
4555                      ,P_APR_ATTRIBUTE18      => r_APR.INFORMATION128
4556                      ,P_APR_ATTRIBUTE19      => r_APR.INFORMATION129
4557                      ,P_APR_ATTRIBUTE2      => r_APR.INFORMATION112
4558                      ,P_APR_ATTRIBUTE20      => r_APR.INFORMATION130
4559                      ,P_APR_ATTRIBUTE21      => r_APR.INFORMATION131
4560                      ,P_APR_ATTRIBUTE22      => r_APR.INFORMATION132
4561                      ,P_APR_ATTRIBUTE23      => r_APR.INFORMATION133
4562                      ,P_APR_ATTRIBUTE24      => r_APR.INFORMATION134
4563                      ,P_APR_ATTRIBUTE25      => r_APR.INFORMATION135
4564                      ,P_APR_ATTRIBUTE26      => r_APR.INFORMATION136
4565                      ,P_APR_ATTRIBUTE27      => r_APR.INFORMATION137
4566                      ,P_APR_ATTRIBUTE28      => r_APR.INFORMATION138
4567                      ,P_APR_ATTRIBUTE29      => r_APR.INFORMATION139
4568                      ,P_APR_ATTRIBUTE3      => r_APR.INFORMATION113
4569                      ,P_APR_ATTRIBUTE30      => r_APR.INFORMATION140
4570                      ,P_APR_ATTRIBUTE4      => r_APR.INFORMATION114
4571                      ,P_APR_ATTRIBUTE5      => r_APR.INFORMATION115
4572                      ,P_APR_ATTRIBUTE6      => r_APR.INFORMATION116
4573                      ,P_APR_ATTRIBUTE7      => r_APR.INFORMATION117
4574                      ,P_APR_ATTRIBUTE8      => r_APR.INFORMATION118
4575                      ,P_APR_ATTRIBUTE9      => r_APR.INFORMATION119
4576                      ,P_APR_ATTRIBUTE_CATEGORY      => r_APR.INFORMATION110
4577                      ,P_BNFT_RT_TYP_CD      => r_APR.INFORMATION16
4578                      ,P_COMP_LVL_FCTR_ID      => l_COMP_LVL_FCTR_ID
4579                      ,P_COST_ALLOCATION_KEYFLEX_ID      => l_COST_ALLOCATION_KEYFLEX_ID
4580                      ,P_CR_LKBK_CRNT_PY_ONLY_FLAG      => r_APR.INFORMATION13
4581                      ,P_CR_LKBK_UOM      => r_APR.INFORMATION24
4582                      ,P_CR_LKBK_VAL      => r_APR.INFORMATION293
4583                      ,P_LWR_LMT_CALC_RL      => l_LWR_LMT_CALC_RL
4584                      ,P_LWR_LMT_VAL      => r_APR.INFORMATION295
4585                      ,P_MLT_CD      => r_APR.INFORMATION17
4586                      ,P_NAME      => l_prefix || r_APR.INFORMATION170 || l_suffix
4587                      ,P_OIPL_ID      => l_OIPL_ID
4588                      ,P_ORGANIZATION_ID      => l_ORGANIZATION_ID
4589                      ,P_PL_ID      => l_PL_ID
4590                      ,P_PRDCT_CD      => r_APR.INFORMATION18
4591                      ,P_PREM_ASNMT_CD      => r_APR.INFORMATION20
4592                      ,P_PREM_ASNMT_LVL_CD      => r_APR.INFORMATION21
4593                      ,P_PREM_PYR_CD      => r_APR.INFORMATION23
4594                      ,P_PRSPTV_R_RTSPTV_CD      => r_APR.INFORMATION25
4595                      ,P_PRTL_MO_DET_MTHD_CD      => r_APR.INFORMATION14
4596                      ,P_PRTL_MO_DET_MTHD_RL      => l_PRTL_MO_DET_MTHD_RL
4597                      ,P_RNDG_CD      => r_APR.INFORMATION19
4598                      ,P_RNDG_RL      => l_RNDG_RL
4599                      ,P_RT_TYP_CD      => r_APR.INFORMATION15
4600                      ,P_UOM      => r_APR.INFORMATION12
4601                      ,P_UPR_LMT_CALC_RL      => l_UPR_LMT_CALC_RL
4602                      ,P_UPR_LMT_VAL      => r_APR.INFORMATION294
4603                      ,P_VAL      => r_APR.INFORMATION287
4604                      ,P_VAL_CALC_RL      => l_VAL_CALC_RL
4605                      ,P_VRBL_RT_ADD_ON_CALC_RL      => l_VRBL_RT_ADD_ON_CALC_RL
4606                      ,P_WSH_RL_DY_MO_NUM      => r_APR.INFORMATION257
4607                      --
4608                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
4609                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
4610                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
4611                      -- UPD START
4612                      --,P_DATETRACK_MODE        => hr_api.g_update
4613                      ,P_DATETRACK_MODE        => l_datetrack_mode
4614                      -- UPD END
4615                    );
4616              end if;  -- l_update
4617          end if;
4618          --
4619          --
4620          -- Delete the row if it is end dated.
4621          --
4622          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
4623              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
4624            trunc(l_max_eed) = r_APR.information3) then
4625              --
4626              BEN_ACTUAL_PREMIUM_API.delete_ACTUAL_PREMIUM(
4627                 --
4628                 p_validate                       => false
4629                 ,p_actl_prem_id                   => l_actl_prem_id
4630                 ,p_effective_start_date           => l_effective_start_date
4631                 ,p_effective_end_date             => l_effective_end_date
4632                 ,p_object_version_number          => l_object_version_number
4633                 ,p_effective_date                 => l_max_eed
4634                 ,p_datetrack_mode                 => hr_api.g_delete
4635                 --
4636                 );
4637                 --
4638          end if;
4639          --
4640          l_prev_pk_id := l_current_pk_id ;
4641          --
4642        end if;
4643        --
4644      end if;
4645      --
4646    end loop;
4647    --
4648  exception when others then
4649      --
4650      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'APR',l_prefix || r_APR.information170 || l_suffix) ;
4651      --
4652  end create_APR_rows;
4653 
4654    --
4655    ---------------------------------------------------------------
4656    ----------------------< create_AVR_rows >-----------------------
4657    ---------------------------------------------------------------
4658    --
4659    procedure create_AVR_rows
4660    (
4661          p_validate                       in  number     default 0
4662         ,p_copy_entity_txn_id             in  number
4663         ,p_effective_date                 in  date
4664         ,p_prefix_suffix_text             in  varchar2  default null
4665         ,p_reuse_object_flag              in  varchar2  default null
4666         ,p_target_business_group_id       in  varchar2  default null
4667         ,p_prefix_suffix_cd               in  varchar2  default null
4668    ) is
4669    --
4670    l_ACTY_BASE_RT_ID  number;
4671    l_VRBL_RT_PRFL_ID  number;
4672    cursor c_unique_AVR(l_table_alias varchar2) is
4673    select distinct cpe.information1,
4674      cpe.information2,
4675      cpe.information3,
4676      cpe.table_route_id,
4677      cpe.dml_operation,
4678      cpe.datetrack_mode
4679    from ben_copy_entity_results cpe,
4680         pqh_table_route tr
4681    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
4682    and   cpe.table_route_id     = tr.table_route_id
4683    -- and   tr.where_clause        = l_BEN_ACTY_VRBL_RT_F
4684    and   tr.table_alias = l_table_alias
4685    and   cpe.number_of_copies   = 1 -- ADDITION
4686    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
4687    order by information1, information2; --added for bug: 5151945
4688    --
4689    --
4690    cursor c_AVR_min_max_dates(c_table_route_id  number,
4691                 c_information1   number) is
4692    select
4693      min(cpe.information2) min_esd,
4694      max(cpe.information3) min_eed
4695    from ben_copy_entity_results cpe
4696    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
4697    and   cpe.table_route_id     = c_table_route_id
4698    and   cpe.information1       = c_information1 ;
4699    --
4700    cursor c_AVR(c_table_route_id  number,
4701                 c_information1   number,
4702                 c_information2   date,
4703                 c_information3   date)  is
4704    select
4705      cpe.*
4706    from ben_copy_entity_results cpe
4707    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
4708    and   cpe.table_route_id     = c_table_route_id
4709    and   cpe.information1       = c_information1
4710    and   cpe.information2       = c_information2
4711    and   cpe.information3       = c_information3
4712    and rownum = 1 ;
4713    -- Date Track target record
4714    cursor c_find_AVR_in_target(
4715                                 c_effective_start_date    date,
4716                                 c_effective_end_date      date,
4717                                 c_business_group_id       number,
4718                                 c_new_pk_id               number) is
4719    select
4720      AVR.acty_vrbl_rt_id new_value
4721    from BEN_ACTY_VRBL_RT_F AVR
4722    where
4723    AVR.ACTY_BASE_RT_ID     = l_ACTY_BASE_RT_ID  and
4724    AVR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
4725    AVR.business_group_id  = c_business_group_id
4726    and   AVR.acty_vrbl_rt_id  <> c_new_pk_id
4727 --TEMPIK
4728    and c_effective_start_date between effective_start_date
4729                             and effective_end_date ;
4730 --END TEMPIK
4731 /*TEMPIK
4732         and exists ( select null
4733                 from BEN_ACTY_VRBL_RT_F AVR1
4734                 where
4735                 AVR1.ACTY_BASE_RT_ID     = l_ACTY_BASE_RT_ID  and
4736                 AVR1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
4737                 AVR1.business_group_id  = c_business_group_id
4738                 and   AVR1.effective_start_date <= c_effective_start_date )
4739    and exists ( select null
4740                 from BEN_ACTY_VRBL_RT_F AVR2
4741                 where
4742                 AVR2.ACTY_BASE_RT_ID     = l_ACTY_BASE_RT_ID  and
4743                 AVR2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
4744                 AVR2.business_group_id  = c_business_group_id
4745                 and   AVR2.effective_end_date >= c_effective_end_date )
4746                 ;
4747 TEMPIK */
4748    --TEMPIK
4749    l_dt_rec_found            boolean ;
4750    --END TEMPIK
4751    --
4752 
4753    --UPD START
4754    --
4755    l_update                  boolean      := false ;
4756    l_datetrack_mode          varchar2(80) := hr_api.g_update;
4757    l_process_date            date;
4758    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
4759    --
4760    --UPD END
4761 
4762    l_current_pk_id           number := null ;
4763    l_prev_pk_id              number := null ;
4764    l_first_rec               boolean := true ;
4765    r_AVR                     c_AVR%rowtype;
4766    l_acty_vrbl_rt_id             number ;
4767    l_object_version_number   number ;
4768    l_effective_start_date    date ;
4769    l_effective_end_date      date ;
4770    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
4771    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
4772    l_new_value               number(15);
4773    l_object_found_in_target  boolean := false ;
4774    l_min_esd                 date;
4775    l_max_eed                 date;
4776    l_effective_date          date;
4777    --
4778  begin
4779    -- Initialization
4780    l_object_found_in_target := false ;
4781    -- End Initialization
4782    -- Derive the prefix - sufix
4783    if   p_prefix_suffix_cd = 'PREFIX' then
4784      l_prefix  := p_prefix_suffix_text ;
4785    elsif p_prefix_suffix_cd = 'SUFFIX' then
4786      l_suffix   := p_prefix_suffix_text ;
4787    else
4788      l_prefix := null ;
4789      l_suffix  := null ;
4790    end if ;
4791    -- End Prefix Sufix derivation
4792    for r_AVR_unique in c_unique_AVR('AVR') loop
4793 
4794      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
4795         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
4796          r_AVR_unique.information3 >=
4797                  ben_pd_copy_to_ben_one.g_copy_effective_date)
4798         ) then
4799        --
4800        hr_utility.set_location(' r_AVR_unique.table_route_id '||r_AVR_unique.table_route_id,10);
4801        hr_utility.set_location(' r_AVR_unique.information1 '||r_AVR_unique.information1,10);
4802        hr_utility.set_location( 'r_AVR_unique.information2 '||r_AVR_unique.information2,10);
4803        hr_utility.set_location( 'r_AVR_unique.information3 '||r_AVR_unique.information3,10);
4804        -- If reuse objects flag is 'Y' then check for the object in the target business group
4805        -- if found insert the record into PLSql table and exit the loop else try create the
4806        -- object in the target business group
4807        --
4808        l_object_found_in_target := false ;
4809 
4810        --UPD START
4811        l_update := false;
4812        l_process_date := p_effective_date;
4813        l_dml_operation:= r_AVR_unique.dml_operation ;
4814        --
4815        open c_AVR(r_AVR_unique.table_route_id,
4816                  r_AVR_unique.information1,
4817                  r_AVR_unique.information2,
4818                  r_AVR_unique.information3 ) ;
4819         --
4820         fetch c_AVR into r_AVR ;
4821         --
4822         close c_AVR ;
4823         --
4824         l_ACTY_BASE_RT_ID := get_fk('ACTY_BASE_RT_ID', r_AVR.information253,r_AVR.dml_operation);
4825         l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_AVR.information262,r_AVR.dml_operation);
4826        --
4827        if l_dml_operation = 'UPDATE' then
4828          --
4829                  l_object_found_in_target := TRUE;
4830                  --
4831                  if l_process_date between r_AVR_unique.information2 and r_AVR_unique.information3 then
4832                        l_update := true;
4833                        if r_AVR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
4834                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ACTY_VRBL_RT_ID'
4835                        then
4836                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ACTY_VRBL_RT_ID' ;
4837                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_AVR_unique.information1 ;
4838                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_AVR_unique.information1 ;
4839                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
4840                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_AVR_unique.table_route_id;
4841                           --
4842                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
4843                           --
4844                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
4845                           --
4846                           -- DOUBT
4847                           --BEN_PD_COPY_TO_BEN_ONE.log_data('AVR',l_new_value,l_prefix || r_AVR_unique.name|| l_suffix,'REUSED');
4848                           --
4849                        end if ;
4850                        hr_utility.set_location( 'found record for update',10);
4851                    --
4852                  else
4853                    --
4854                    l_update := false;
4855                    --
4856                  end if;
4857        else
4858        --
4859        --UPD END
4860 
4861                l_min_esd := null ;
4862                l_max_eed := null ;
4863                open c_AVR_min_max_dates(r_AVR_unique.table_route_id, r_AVR_unique.information1 ) ;
4864                fetch c_AVR_min_max_dates into l_min_esd,l_max_eed ;
4865                --
4866 
4867                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
4868                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
4869                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
4870                end if;
4871                 l_min_esd := greatest(l_min_esd,r_AVR_unique.information2);
4872                /*
4873                open c_AVR(r_AVR_unique.table_route_id,
4874                         r_AVR_unique.information1,
4875                         r_AVR_unique.information2,
4876                         r_AVR_unique.information3 ) ;
4877                --
4878                fetch c_AVR into r_AVR ;
4879                --
4880                close c_AVR ;
4881                --
4882                l_ACTY_BASE_RT_ID := get_fk('ACTY_BASE_RT_ID', r_AVR.information253,r_AVR.dml_operation);
4883                l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_AVR.information262,r_AVR.dml_operation);
4884                */
4885                if p_reuse_object_flag = 'Y' then
4886                  if c_AVR_min_max_dates%found then
4887                    -- cursor to find the object
4888                    open c_find_AVR_in_target( l_min_esd,l_max_eed,
4889                                          p_target_business_group_id, nvl(l_acty_vrbl_rt_id, -999)  ) ;
4890                    fetch c_find_AVR_in_target into l_new_value ;
4891                    if c_find_AVR_in_target%found then
4892                      --TEMPIK
4893                      l_dt_rec_found :=   dt_api.check_min_max_dates
4894                          (p_base_table_name => 'BEN_ACTY_VRBL_RT_F',
4895                           p_base_key_column => 'ACTY_VRBL_RT_ID',
4896                           p_base_key_value  => l_new_value,
4897                           p_from_date       => l_min_esd,
4898                           p_to_date         => l_max_eed );
4899                      if l_dt_rec_found THEN
4900                      --END TEMPIK             --
4901                                          if r_AVR_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
4902                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'ACTY_VRBL_RT_ID'  then
4903                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'ACTY_VRBL_RT_ID' ;
4904                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_AVR_unique.information1 ;
4905                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
4906                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
4907                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_AVR_unique.table_route_id;
4908                                                 --
4909                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
4910                                                 --
4911                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
4912                                          end if ;
4913                                          --
4914                                          l_object_found_in_target := true ;
4915                      --TEMPIK
4916                      end if; -- l_dt_rec_found
4917                      --END TEMPIK
4918                    end if;
4919                    close c_find_AVR_in_target ;
4920                  --
4921                  end if;
4922                end if ;
4923                --
4924                close c_AVR_min_max_dates ;
4925 
4926        -- UPD START
4927        --if not l_object_found_in_target then
4928        end if; --if p_dml_operation
4929        --
4930        if not l_object_found_in_target OR l_update  then
4931 
4932        -- UPD END
4933          --
4934          l_current_pk_id := r_AVR.information1;
4935          --
4936          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
4937          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
4938          --
4939          if l_current_pk_id =  l_prev_pk_id  then
4940            --
4941            l_first_rec := false ;
4942            --
4943          else
4944            --
4945            l_first_rec := true ;
4946            --
4947          end if ;
4948          --
4949 
4950          l_effective_date := r_AVR.information2;
4951          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
4952               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
4953            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
4954          end if;
4955          -- UPD START
4956          --if l_first_rec then
4957          if l_first_rec and not l_update then
4958          -- UPD END
4959            -- Call Create routine.
4960            hr_utility.set_location(' BEN_ACTY_VRBL_RT_F CREATE_ACTY_VRBL_RATE ',20);
4961            BEN_ACTY_VRBL_RATE_API.CREATE_ACTY_VRBL_RATE(
4962              --
4963              P_VALIDATE               => false
4964              ,P_EFFECTIVE_DATE        => l_effective_date
4965              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
4966              --
4967              ,P_ACTY_BASE_RT_ID      => l_ACTY_BASE_RT_ID
4968              ,P_ACTY_VRBL_RT_ID      => l_acty_vrbl_rt_id
4969              ,P_AVR_ATTRIBUTE1      => r_AVR.INFORMATION111
4970              ,P_AVR_ATTRIBUTE10      => r_AVR.INFORMATION120
4971              ,P_AVR_ATTRIBUTE11      => r_AVR.INFORMATION121
4972              ,P_AVR_ATTRIBUTE12      => r_AVR.INFORMATION122
4973              ,P_AVR_ATTRIBUTE13      => r_AVR.INFORMATION123
4974              ,P_AVR_ATTRIBUTE14      => r_AVR.INFORMATION124
4975              ,P_AVR_ATTRIBUTE15      => r_AVR.INFORMATION125
4976              ,P_AVR_ATTRIBUTE16      => r_AVR.INFORMATION126
4977              ,P_AVR_ATTRIBUTE17      => r_AVR.INFORMATION127
4978              ,P_AVR_ATTRIBUTE18      => r_AVR.INFORMATION128
4979              ,P_AVR_ATTRIBUTE19      => r_AVR.INFORMATION129
4980              ,P_AVR_ATTRIBUTE2      => r_AVR.INFORMATION112
4981              ,P_AVR_ATTRIBUTE20      => r_AVR.INFORMATION130
4982              ,P_AVR_ATTRIBUTE21      => r_AVR.INFORMATION131
4983              ,P_AVR_ATTRIBUTE22      => r_AVR.INFORMATION132
4984              ,P_AVR_ATTRIBUTE23      => r_AVR.INFORMATION133
4985              ,P_AVR_ATTRIBUTE24      => r_AVR.INFORMATION134
4986              ,P_AVR_ATTRIBUTE25      => r_AVR.INFORMATION135
4987              ,P_AVR_ATTRIBUTE26      => r_AVR.INFORMATION136
4988              ,P_AVR_ATTRIBUTE27      => r_AVR.INFORMATION137
4989              ,P_AVR_ATTRIBUTE28      => r_AVR.INFORMATION138
4990              ,P_AVR_ATTRIBUTE29      => r_AVR.INFORMATION139
4991              ,P_AVR_ATTRIBUTE3      => r_AVR.INFORMATION113
4992              ,P_AVR_ATTRIBUTE30      => r_AVR.INFORMATION140
4993              ,P_AVR_ATTRIBUTE4      => r_AVR.INFORMATION114
4994              ,P_AVR_ATTRIBUTE5      => r_AVR.INFORMATION115
4995              ,P_AVR_ATTRIBUTE6      => r_AVR.INFORMATION116
4996              ,P_AVR_ATTRIBUTE7      => r_AVR.INFORMATION117
4997              ,P_AVR_ATTRIBUTE8      => r_AVR.INFORMATION118
4998              ,P_AVR_ATTRIBUTE9      => r_AVR.INFORMATION119
4999              ,P_AVR_ATTRIBUTE_CATEGORY      => r_AVR.INFORMATION110
5000              ,P_ORDR_NUM      => r_AVR.INFORMATION260
5001              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
5002              --
5003              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
5004              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
5005              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
5006            );
5007            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
5008            -- Update all relevent cer records with new pk_id
5009            hr_utility.set_location('Before plsql table ',222);
5010            hr_utility.set_location('new_value id '||l_acty_vrbl_rt_id,222);
5011            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'ACTY_VRBL_RT_ID' ;
5012            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_AVR.information1 ;
5013            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_ACTY_VRBL_RT_ID ;
5014            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
5015            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_AVR_unique.table_route_id;
5016            hr_utility.set_location('After plsql table ',222);
5017            --
5018            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
5019            --
5020            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
5021            --
5022          else
5023            --
5024            -- Call Update routine for the pk_id created in prev run .
5025            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
5026            hr_utility.set_location(' BEN_ACTY_VRBL_RT_F UPDATE_ACTY_VRBL_RATE ',30);
5027              --UPD START
5028            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
5029            --
5030            if l_update then
5031              --
5032              l_datetrack_mode := r_AVR.datetrack_mode ;
5033              --
5034              get_dt_modes(
5035                p_effective_date        => l_process_date,
5036                p_effective_end_date    => r_AVR.information3,
5037                p_effective_start_date  => r_AVR.information2,
5038                p_dml_operation         => r_AVR.dml_operation,
5039                p_datetrack_mode        => l_datetrack_mode );
5040            --    p_update                => l_update
5041              --
5042              l_effective_date := l_process_date;
5043              l_acty_vrbl_rt_id   := r_AVR.information1;
5044              l_object_version_number := r_AVR.information265;
5045              --
5046            end if;
5047            --
5048            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
5049            --
5050            IF l_update OR l_dml_operation <> 'UPDATE' THEN
5051            --UPD END
5052                    BEN_ACTY_VRBL_RATE_API.UPDATE_ACTY_VRBL_RATE(
5053                      --
5054                      P_VALIDATE               => false
5055                      ,P_EFFECTIVE_DATE        => l_effective_date
5056                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
5057                      --
5058                      ,P_ACTY_BASE_RT_ID      => l_ACTY_BASE_RT_ID
5059                      ,P_ACTY_VRBL_RT_ID      => l_acty_vrbl_rt_id
5060                      ,P_AVR_ATTRIBUTE1      => r_AVR.INFORMATION111
5061                      ,P_AVR_ATTRIBUTE10      => r_AVR.INFORMATION120
5062                      ,P_AVR_ATTRIBUTE11      => r_AVR.INFORMATION121
5063                      ,P_AVR_ATTRIBUTE12      => r_AVR.INFORMATION122
5064                      ,P_AVR_ATTRIBUTE13      => r_AVR.INFORMATION123
5065                      ,P_AVR_ATTRIBUTE14      => r_AVR.INFORMATION124
5066                      ,P_AVR_ATTRIBUTE15      => r_AVR.INFORMATION125
5067                      ,P_AVR_ATTRIBUTE16      => r_AVR.INFORMATION126
5068                      ,P_AVR_ATTRIBUTE17      => r_AVR.INFORMATION127
5069                      ,P_AVR_ATTRIBUTE18      => r_AVR.INFORMATION128
5070                      ,P_AVR_ATTRIBUTE19      => r_AVR.INFORMATION129
5071                      ,P_AVR_ATTRIBUTE2      => r_AVR.INFORMATION112
5072                      ,P_AVR_ATTRIBUTE20      => r_AVR.INFORMATION130
5073                      ,P_AVR_ATTRIBUTE21      => r_AVR.INFORMATION131
5074                      ,P_AVR_ATTRIBUTE22      => r_AVR.INFORMATION132
5075                      ,P_AVR_ATTRIBUTE23      => r_AVR.INFORMATION133
5076                      ,P_AVR_ATTRIBUTE24      => r_AVR.INFORMATION134
5077                      ,P_AVR_ATTRIBUTE25      => r_AVR.INFORMATION135
5078                      ,P_AVR_ATTRIBUTE26      => r_AVR.INFORMATION136
5079                      ,P_AVR_ATTRIBUTE27      => r_AVR.INFORMATION137
5080                      ,P_AVR_ATTRIBUTE28      => r_AVR.INFORMATION138
5081                      ,P_AVR_ATTRIBUTE29      => r_AVR.INFORMATION139
5082                      ,P_AVR_ATTRIBUTE3      => r_AVR.INFORMATION113
5083                      ,P_AVR_ATTRIBUTE30      => r_AVR.INFORMATION140
5084                      ,P_AVR_ATTRIBUTE4      => r_AVR.INFORMATION114
5085                      ,P_AVR_ATTRIBUTE5      => r_AVR.INFORMATION115
5086                      ,P_AVR_ATTRIBUTE6      => r_AVR.INFORMATION116
5087                      ,P_AVR_ATTRIBUTE7      => r_AVR.INFORMATION117
5088                      ,P_AVR_ATTRIBUTE8      => r_AVR.INFORMATION118
5089                      ,P_AVR_ATTRIBUTE9      => r_AVR.INFORMATION119
5090                      ,P_AVR_ATTRIBUTE_CATEGORY      => r_AVR.INFORMATION110
5091                      ,P_ORDR_NUM      => r_AVR.INFORMATION260
5092                      ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
5093                      --
5094                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
5095                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
5096                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
5097                      -- UPD START
5098                      --,P_DATETRACK_MODE        => hr_api.g_update
5099                      ,P_DATETRACK_MODE        => l_datetrack_mode
5100                      -- UPD END
5101                    );
5102                -- UPD START
5103                end if;  -- l_update
5104                -- UPD END
5105          end if;
5106          --
5107          --
5108          -- Delete the row if it is end dated.
5109          --
5110          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
5111              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
5112              trunc(l_max_eed) = r_AVR.information3) then
5113              --
5114              BEN_ACTY_VRBL_RATE_API.delete_ACTY_VRBL_RATE(
5115                 --
5116                 p_validate                       => false
5117                 ,p_acty_vrbl_rt_id                   => l_acty_vrbl_rt_id
5118                 ,p_effective_start_date           => l_effective_start_date
5119                 ,p_effective_end_date             => l_effective_end_date
5120                 ,p_object_version_number          => l_object_version_number
5121                 ,p_effective_date                 => l_max_eed
5122                 ,p_datetrack_mode                 => hr_api.g_delete
5123                 --
5124                 );
5125                 --
5126          end if;
5127          --
5128          l_prev_pk_id := l_current_pk_id ;
5129          --
5130        end if;
5131        --
5132      end if;
5133      --
5134    end loop;
5135    --
5136  exception when others then
5137      --
5138      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'AVR',r_AVR.information5 ) ;
5139      --
5140  end create_AVR_rows;
5141 
5142    --
5143    ---------------------------------------------------------------
5144    ----------------------< create_VPF_rows >-----------------------
5145    ---------------------------------------------------------------
5146    --
5147    procedure create_VPF_rows
5148    (
5149          p_validate                       in  number     default 0
5150         ,p_copy_entity_txn_id             in  number
5151         ,p_effective_date                 in  date
5152         ,p_prefix_suffix_text             in  varchar2  default null
5153         ,p_reuse_object_flag              in  varchar2  default null
5154         ,p_target_business_group_id       in  varchar2  default null
5155         ,p_prefix_suffix_cd               in  varchar2  default null
5156    ) is
5157    --
5158    l_COMP_LVL_FCTR_ID  number;
5159    l_LWR_LMT_CALC_RL  number;
5160    l_OIPL_ID  number;
5161    l_PL_ID  number;
5162    l_PL_TYP_OPT_TYP_ID  number;
5163    l_RNDG_RL  number;
5164    l_ULTMT_LWR_LMT_CALC_RL  number;
5165    l_ULTMT_UPR_LMT_CALC_RL  number;
5166    l_UPR_LMT_CALC_RL  number;
5167    l_VAL_CALC_RL  number;
5168    l_NAME         varchar2(1000);
5169    --
5170    cursor c_unique_VPF(l_table_alias varchar2) is
5171    select distinct cpe.information1,
5172      cpe.information2,
5173      cpe.information3,
5174      cpe.information170 name,
5175      cpe.table_route_id,
5176      cpe.dml_operation,
5177      cpe.datetrack_mode
5178    from ben_copy_entity_results cpe,
5179         pqh_table_route tr
5180    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
5181    and   cpe.table_route_id     = tr.table_route_id
5182    -- and   tr.where_clause        = l_BEN_VRBL_RT_PRFL_F
5183    and   tr.table_alias = l_table_alias
5184    and   cpe.number_of_copies   = 1 -- ADDITION
5185    group by cpe.information1,cpe.information2,cpe.information3, cpe.information170 , cpe.table_route_id ,cpe.dml_operation,cpe.datetrack_mode
5186    order by information1, information2; --added for bug: 5151945
5187    --
5188    --
5189    cursor c_VPF_min_max_dates(c_table_route_id  number,
5190                 c_information1   number) is
5191    select
5192      min(cpe.information2) min_esd,
5193      max(cpe.information3) min_eed
5194    from ben_copy_entity_results cpe
5195    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
5196    and   cpe.table_route_id     = c_table_route_id
5197    and   cpe.information1       = c_information1 ;
5198    --
5199    cursor c_VPF(c_table_route_id  number,
5200                 c_information1   number,
5201                 c_information2   date,
5202                 c_information3   date)  is
5203    select
5204      cpe.*
5205    from ben_copy_entity_results cpe
5206    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
5207    and   cpe.table_route_id     = c_table_route_id
5208    and   cpe.information1       = c_information1
5209    and   cpe.information2       = c_information2
5210    and   cpe.information3       = c_information3
5211    and rownum = 1 ;
5212    -- Date Track target record
5213    cursor c_find_VPF_in_target(
5214                                 c_effective_start_date    date,
5215                                 c_effective_end_date      date,
5216                                 c_business_group_id       number,
5217                                 c_new_pk_id               number) is
5218    select
5219      VPF.vrbl_rt_prfl_id new_value
5220    from BEN_VRBL_RT_PRFL_F VPF
5221    where
5222    VPF.name                  = l_name and
5223    VPF.business_group_id  = c_business_group_id
5224    and   VPF.vrbl_rt_prfl_id  <> c_new_pk_id
5225 --TEMPIK
5226    and c_effective_start_date between effective_start_date
5227                             and effective_end_date ;
5228 --END TEMPIK
5229 /*TEMPIK
5230    and exists ( select null
5231                 from BEN_VRBL_RT_PRFL_F VPF1
5232                 where
5233                 VPF1.name                  = l_name and
5234                 VPF1.business_group_id  = c_business_group_id
5235                 and   VPF1.effective_start_date <= c_effective_start_date )
5236    and exists ( select null
5237                 from BEN_VRBL_RT_PRFL_F VPF2
5238                 where
5239                 VPF2.name                           = l_name and
5240                 VPF2.business_group_id  = c_business_group_id
5241                 and   VPF2.effective_end_date >= c_effective_end_date )
5242                 ;
5243 TEMPIK */
5244    --TEMPIK
5245    l_dt_rec_found            boolean ;
5246    --END TEMPIK
5247    --
5248    --UPD START
5249    --
5250    l_update                  boolean      := false ;
5251    l_datetrack_mode          varchar2(80) := hr_api.g_update;
5252    l_process_date            date;
5253    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
5254    --
5255    --UPD END
5256 
5257    l_current_pk_id           number := null ;
5258    l_prev_pk_id              number := null ;
5259    l_first_rec               boolean := true ;
5260    r_VPF                     c_VPF%rowtype;
5261    l_vrbl_rt_prfl_id             number ;
5262    l_object_version_number   number ;
5263    l_effective_start_date    date ;
5264    l_effective_end_date      date ;
5265    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
5266    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
5267    l_new_value               number(15);
5268    l_object_found_in_target  boolean := false ;
5269    l_min_esd                 date;
5270    l_max_eed                 date;
5271    l_effective_date          date;
5272    --
5273  begin
5274    -- Initialization
5275    l_object_found_in_target := false ;
5276    -- End Initialization
5277    -- Derive the prefix - sufix
5278    if   p_prefix_suffix_cd = 'PREFIX' then
5279      l_prefix  := p_prefix_suffix_text ;
5280    elsif p_prefix_suffix_cd = 'SUFFIX' then
5281      l_suffix   := p_prefix_suffix_text ;
5282    else
5283      l_prefix := null ;
5284      l_suffix  := null ;
5285    end if ;
5286    -- End Prefix Sufix derivation
5287    for r_VPF_unique in c_unique_VPF('VPF') loop
5288 
5289      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
5290         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
5291          r_VPF_unique.information3 >=
5292                  ben_pd_copy_to_ben_one.g_copy_effective_date)
5293         ) then
5294        --
5295        hr_utility.set_location(' r_VPF_unique.table_route_id '||r_VPF_unique.table_route_id,10);
5296        hr_utility.set_location(' r_VPF_unique.information1 '||r_VPF_unique.information1,10);
5297        hr_utility.set_location( 'r_VPF_unique.information2 '||r_VPF_unique.information2,10);
5298        hr_utility.set_location( 'r_VPF_unique.information3 '||r_VPF_unique.information3,10);
5299        -- If reuse objects flag is 'Y' then check for the object in the target business group
5300        -- if found insert the record into PLSql table and exit the loop else try create the
5301        -- object in the target business group
5302        --
5303        l_object_found_in_target := false ;
5304 
5305        --UPD START
5306        l_update := false;
5307        l_process_date := p_effective_date;
5308        l_dml_operation:= r_VPF_unique.dml_operation ;
5309        open c_VPF(r_VPF_unique.table_route_id,
5310                 r_VPF_unique.information1,
5311                 r_VPF_unique.information2,
5312                 r_VPF_unique.information3 ) ;
5313        --
5314        fetch c_VPF into r_VPF ;
5315        --
5316        close c_VPF ;
5317        --
5318        l_COMP_LVL_FCTR_ID := get_fk('COMP_LVL_FCTR_ID', r_VPF.information254,r_VPF.dml_operation);
5319        l_LWR_LMT_CALC_RL := get_fk('FORMULA_ID', r_VPF.information260,r_VPF.dml_operation);
5320        l_RNDG_RL := get_fk('FORMULA_ID', r_VPF.information269,r_VPF.dml_operation);
5321        l_ULTMT_LWR_LMT_CALC_RL := get_fk('FORMULA_ID', r_VPF.information259,r_VPF.dml_operation);
5322        l_ULTMT_UPR_LMT_CALC_RL := get_fk('FORMULA_ID', r_VPF.information257,r_VPF.dml_operation);
5323        l_UPR_LMT_CALC_RL := get_fk('FORMULA_ID', r_VPF.information263,r_VPF.dml_operation);
5324        l_VAL_CALC_RL := get_fk('FORMULA_ID', r_VPF.information268,r_VPF.dml_operation);
5325        --
5326        if l_dml_operation = 'UPDATE' then
5327          --
5328                  l_object_found_in_target := TRUE;
5329                  --
5330                  if l_process_date between r_VPF_unique.information2 and r_VPF_unique.information3 then
5331                        l_update := true;
5332                        if r_VPF_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
5333                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'VRBL_RT_PRFL_ID'
5334                        then
5335                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'VRBL_RT_PRFL_ID' ;
5336                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_VPF_unique.information1 ;
5337                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_VPF_unique.information1 ;
5338                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
5339                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_VPF_unique.table_route_id;
5340                           --
5341                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
5342                           --
5343                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
5344                           --
5345                           BEN_PD_COPY_TO_BEN_ONE.log_data('VPF',l_new_value,l_prefix || r_VPF_unique.name|| l_suffix,'REUSED');
5346                           --
5347                        end if ;
5348                        hr_utility.set_location( 'found record for update',10);
5349                    --
5350                  else
5351                    --
5352                    l_update := false;
5353                    --
5354                  end if;
5355        else
5356        --
5357        --UPD END
5358 
5359                l_min_esd := null ;
5360                l_max_eed := null ;
5361                open c_VPF_min_max_dates(r_VPF_unique.table_route_id, r_VPF_unique.information1 ) ;
5362                fetch c_VPF_min_max_dates into l_min_esd,l_max_eed ;
5363                --
5364 
5365                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
5366                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
5367                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
5368                end if;
5369                l_min_esd := greatest(l_min_esd,r_VPF_unique.information2);
5370 
5371                -- Only For Use by Create Wizard - Same Business Group
5372 
5373                if BEN_PD_COPY_TO_BEN_ONE.g_transaction_category = 'BEN_PDCRWZ' then
5374 
5375                  l_OIPL_ID := NVL(get_fk('OIPL_ID', r_VPF.information258,r_VPF.dml_operation),
5376                                 r_VPF.information258);
5377                  l_PL_ID := NVL(get_fk('PL_ID', r_VPF.information261,r_VPF.dml_operation),
5378                               r_VPF.information261);
5379                  l_PL_TYP_OPT_TYP_ID := NVL(get_fk('PL_TYP_OPT_TYP_ID',
5380                                             r_VPF.information228,r_VPF.dml_operation),
5381                                             r_VPF.information228);
5382                else
5383                  l_OIPL_ID:= null;
5384                  l_PL_ID := null;
5385                  l_PL_TYP_OPT_TYP_ID := null;
5386                end if;
5387 
5388                l_name        := l_prefix || r_VPF.information170 || l_suffix ;
5389                if p_reuse_object_flag = 'Y' then
5390                  if c_VPF_min_max_dates%found then
5391                    -- cursor to find the object
5392                    open c_find_VPF_in_target( l_min_esd,l_max_eed,
5393                                          p_target_business_group_id, nvl(l_vrbl_rt_prfl_id, -999)  ) ;
5394                    fetch c_find_VPF_in_target into l_new_value ;
5395                    if c_find_VPF_in_target%found then
5396                      --TEMPIK
5397                      l_dt_rec_found :=   dt_api.check_min_max_dates
5398                          (p_base_table_name => 'BEN_VRBL_RT_PRFL_F',
5399                           p_base_key_column => 'VRBL_RT_PRFL_ID',
5400                           p_base_key_value  => l_new_value,
5401                           p_from_date       => l_min_esd,
5402                           p_to_date         => l_max_eed );
5403                      if l_dt_rec_found THEN
5404                      --END TEMPIK
5405                                          --
5406                                          if r_VPF_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
5407                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'VRBL_RT_PRFL_ID'  then
5408                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'VRBL_RT_PRFL_ID' ;
5409                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_VPF_unique.information1 ;
5410                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
5411                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
5412                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_VPF_unique.table_route_id;
5413                                                 --
5414                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
5415                                                 --
5416                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
5417                                                 --
5418                                                 ben_pd_copy_to_ben_one.log_data('VPF',l_new_value,l_prefix || r_VPF_unique.name|| l_suffix,'REUSED');
5419                                                 --
5420                                          end if ;
5421                                          --
5422                                          l_object_found_in_target := true ;
5423                      --TEMPIK
5424                      end if; -- l_dt_rec_found
5425                      --END TEMPIK
5426                    end if;
5427                    close c_find_VPF_in_target ;
5428                  --
5429                  end if;
5430                end if ;
5431                --
5432                close c_VPF_min_max_dates ;
5433        -- UPD START
5434        --if not l_object_found_in_target then
5435        end if; --if p_dml_operation
5436        --
5437        if not l_object_found_in_target OR l_update  then
5438        -- UPD END
5439 
5440          --
5441          l_current_pk_id := r_VPF.information1;
5442          --
5443          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
5444          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
5445          --
5446          if l_current_pk_id =  l_prev_pk_id  then
5447            --
5448            l_first_rec := false ;
5449            --
5450          else
5451            --
5452            l_first_rec := true ;
5453            --
5454          end if ;
5455          --
5456          ben_pd_copy_to_ben_one.ben_chk_col_len('NAME' ,'BEN_VRBL_RT_PRFL_F',l_prefix || r_VPF.information170 || l_suffix);
5457          --
5458 
5459          l_effective_date := r_VPF.information2;
5460          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
5461               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
5462            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
5463          end if;
5464          -- UPD START
5465          --if l_first_rec then
5466          if l_first_rec and not l_update then
5467          -- UPD END
5468 
5469            -- Call Create routine.
5470            hr_utility.set_location(' BEN_VRBL_RT_PRFL_F CREATE_VRBL_RATE_PROFILE ',20);
5471            BEN_VRBL_RATE_PROFILE_API.CREATE_VRBL_RATE_PROFILE(
5472              --
5473                P_VALIDATE               => false
5474                ,P_EFFECTIVE_DATE        => l_effective_date
5475                ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
5476                --
5477                ,P_ACTY_REF_PERD_CD      => r_VPF.INFORMATION67
5478                ,P_ACTY_TYP_CD      => r_VPF.INFORMATION72
5479                ,P_ALWYS_CNT_ALL_PRTTS_FLAG      => r_VPF.INFORMATION76
5480                ,P_ALWYS_SUM_ALL_CVG_FLAG      => r_VPF.INFORMATION75
5481                ,P_ANN_MN_ELCN_VAL      => r_VPF.INFORMATION297
5482                ,P_ANN_MX_ELCN_VAL      => r_VPF.INFORMATION298
5483                ,P_ASMT_TO_USE_CD      => r_VPF.INFORMATION71
5484                ,P_BNFT_RT_TYP_CD      => r_VPF.INFORMATION74
5485                ,P_COMP_LVL_FCTR_ID      => l_COMP_LVL_FCTR_ID
5486                ,P_DFLT_ELCN_VAL      => r_VPF.INFORMATION300
5487                ,P_INCRMNT_ELCN_VAL      => r_VPF.INFORMATION299
5488                ,P_LWR_LMT_CALC_RL      => l_LWR_LMT_CALC_RL
5489                ,P_LWR_LMT_VAL      => r_VPF.INFORMATION295
5490                ,P_MLT_CD      => r_VPF.INFORMATION68
5491                ,P_MN_ELCN_VAL      => r_VPF.INFORMATION302
5492                ,P_MX_ELCN_VAL      => r_VPF.INFORMATION301
5493                ,P_NAME      => l_prefix || r_VPF.INFORMATION170 || l_suffix
5494                ,P_NO_MN_ELCN_VAL_DFND_FLAG      => r_VPF.INFORMATION69
5495                ,P_NO_MX_ELCN_VAL_DFND_FLAG      => r_VPF.INFORMATION70
5496                ,P_OIPL_ID      => l_OIPL_ID
5497                ,P_PL_ID      => l_PL_ID
5498                ,P_PL_TYP_OPT_TYP_ID      => l_PL_TYP_OPT_TYP_ID
5499                ,P_RNDG_CD      => r_VPF.INFORMATION79
5500                ,P_RNDG_RL      => l_RNDG_RL
5501                ,P_RT_AGE_FLAG      => r_VPF.INFORMATION38
5502                ,P_RT_ASNT_SET_FLAG      => r_VPF.INFORMATION45
5503                ,P_RT_BENFTS_GRP_FLAG      => r_VPF.INFORMATION35
5504                ,P_RT_BRGNG_UNIT_FLAG      => r_VPF.INFORMATION37
5505                ,P_RT_CBR_QUALD_BNF_FLAG      => r_VPF.INFORMATION24
5506                ,P_RT_CMBN_AGE_LOS_FLAG      => r_VPF.INFORMATION54
5507                ,P_RT_CNTNG_PRTN_PRFL_FLAG      => r_VPF.INFORMATION23
5508                ,P_RT_COMPTNCY_FLAG      => r_VPF.INFORMATION25
5509                ,P_RT_COMP_LVL_FLAG      => r_VPF.INFORMATION47
5510                ,P_RT_DPNT_CVRD_PGM_FLAG      => r_VPF.INFORMATION11
5511                ,P_RT_DPNT_CVRD_PLIP_FLAG      => r_VPF.INFORMATION29
5512                ,P_RT_DPNT_CVRD_PL_FLAG      => r_VPF.INFORMATION82
5513                ,P_RT_DPNT_CVRD_PTIP_FLAG      => r_VPF.INFORMATION30
5514                ,P_RT_DPNT_OTHR_PTIP_FLAG      => r_VPF.INFORMATION20
5515                ,P_RT_DSBLD_FLAG      => r_VPF.INFORMATION58
5516                ,P_RT_EE_STAT_FLAG      => r_VPF.INFORMATION42
5517                ,P_RT_ENRLD_OIPL_FLAG      => r_VPF.INFORMATION12
5518                ,P_RT_ENRLD_PGM_FLAG      => r_VPF.INFORMATION16
5519                ,P_RT_ENRLD_PLIP_FLAG      => r_VPF.INFORMATION14
5520                ,P_RT_ENRLD_PL_FLAG      => r_VPF.INFORMATION13
5521                ,P_RT_ENRLD_PTIP_FLAG      => r_VPF.INFORMATION15
5522                ,P_RT_FL_TM_PT_TM_FLAG      => r_VPF.INFORMATION41
5523                ,P_RT_GNDR_FLAG      => r_VPF.INFORMATION63
5524                ,P_RT_GRD_FLAG      => r_VPF.INFORMATION43
5525                ,P_RT_HLTH_CVG_FLAG      => r_VPF.INFORMATION59
5526                ,P_RT_HRLY_SLRD_FLAG      => r_VPF.INFORMATION31
5527                ,P_RT_HRS_WKD_FLAG      => r_VPF.INFORMATION46
5528                ,P_RT_JOB_FLAG      => r_VPF.INFORMATION80
5529                ,P_RT_LBR_MMBR_FLAG      => r_VPF.INFORMATION33
5530                ,P_RT_LGL_ENTY_FLAG      => r_VPF.INFORMATION34
5531                ,P_RT_LOA_RSN_FLAG      => r_VPF.INFORMATION49
5532                ,P_RT_LOS_FLAG      => r_VPF.INFORMATION39
5533                ,P_RT_LVG_RSN_FLAG      => r_VPF.INFORMATION27
5534                ,P_RT_NO_OTHR_CVG_FLAG      => r_VPF.INFORMATION19
5535                ,P_RT_OPTD_MDCR_FLAG      => r_VPF.INFORMATION26
5536                ,P_RT_ORG_UNIT_FLAG      => r_VPF.INFORMATION48
5537                ,P_RT_OTHR_PTIP_FLAG      => r_VPF.INFORMATION18
5538                ,P_RT_PCT_FL_TM_FLAG      => r_VPF.INFORMATION44
5539                ,P_RT_PERF_RTNG_FLAG      => r_VPF.INFORMATION21
5540                ,P_RT_PER_TYP_FLAG      => r_VPF.INFORMATION40
5541                ,P_RT_POE_FLAG      => r_VPF.INFORMATION60
5542                ,P_RT_PPL_GRP_FLAG      => r_VPF.INFORMATION57
5543                ,P_RT_PRFL_RL_FLAG      => r_VPF.INFORMATION53
5544                ,P_RT_PRTT_ANTHR_PL_FLAG      => r_VPF.INFORMATION17
5545                ,P_RT_PRTT_PL_FLAG      => r_VPF.INFORMATION55
5546                ,P_RT_PSTL_CD_FLAG      => r_VPF.INFORMATION32
5547                ,P_RT_PSTN_FLAG      => r_VPF.INFORMATION28
5548                ,P_RT_PYRL_FLAG      => r_VPF.INFORMATION50
5549                ,P_RT_PY_BSS_FLAG      => r_VPF.INFORMATION52
5550                ,P_RT_QUAL_TITL_FLAG      => r_VPF.INFORMATION81
5551                ,P_RT_QUA_IN_GR_FLAG      => r_VPF.INFORMATION22
5552                ,P_RT_SCHEDD_HRS_FLAG      => r_VPF.INFORMATION51
5553                ,P_RT_SVC_AREA_FLAG      => r_VPF.INFORMATION56
5554                ,P_RT_TBCO_USE_FLAG      => r_VPF.INFORMATION64
5555                ,P_RT_TTL_CVG_VOL_FLAG      => r_VPF.INFORMATION61
5556                ,P_RT_TTL_PRTT_FLAG      => r_VPF.INFORMATION62
5557                ,P_RT_TYP_CD      => r_VPF.INFORMATION73
5558                ,P_RT_WK_LOC_FLAG      => r_VPF.INFORMATION36
5559                ,P_TX_TYP_CD      => r_VPF.INFORMATION65
5560                ,P_ULTMT_LWR_LMT      => r_VPF.INFORMATION293
5561                ,P_ULTMT_LWR_LMT_CALC_RL      => l_ULTMT_LWR_LMT_CALC_RL
5562                ,P_ULTMT_UPR_LMT      => r_VPF.INFORMATION294
5563                ,P_ULTMT_UPR_LMT_CALC_RL      => l_ULTMT_UPR_LMT_CALC_RL
5564                ,P_UPR_LMT_CALC_RL      => l_UPR_LMT_CALC_RL
5565                ,P_UPR_LMT_VAL      => r_VPF.INFORMATION296
5566                ,P_VAL      => r_VPF.INFORMATION303
5567                ,P_VAL_CALC_RL      => l_VAL_CALC_RL
5568                ,P_VPF_ATTRIBUTE1      => r_VPF.INFORMATION111
5569                ,P_VPF_ATTRIBUTE10      => r_VPF.INFORMATION120
5570                ,P_VPF_ATTRIBUTE11      => r_VPF.INFORMATION121
5571                ,P_VPF_ATTRIBUTE12      => r_VPF.INFORMATION122
5572                ,P_VPF_ATTRIBUTE13      => r_VPF.INFORMATION123
5573                ,P_VPF_ATTRIBUTE14      => r_VPF.INFORMATION124
5574                ,P_VPF_ATTRIBUTE15      => r_VPF.INFORMATION125
5575                ,P_VPF_ATTRIBUTE16      => r_VPF.INFORMATION126
5576                ,P_VPF_ATTRIBUTE17      => r_VPF.INFORMATION127
5577                ,P_VPF_ATTRIBUTE18      => r_VPF.INFORMATION128
5578                ,P_VPF_ATTRIBUTE19      => r_VPF.INFORMATION129
5579                ,P_VPF_ATTRIBUTE2      => r_VPF.INFORMATION112
5580                ,P_VPF_ATTRIBUTE20      => r_VPF.INFORMATION130
5581                ,P_VPF_ATTRIBUTE21      => r_VPF.INFORMATION131
5582                ,P_VPF_ATTRIBUTE22      => r_VPF.INFORMATION132
5583                ,P_VPF_ATTRIBUTE23      => r_VPF.INFORMATION133
5584                ,P_VPF_ATTRIBUTE24      => r_VPF.INFORMATION134
5585                ,P_VPF_ATTRIBUTE25      => r_VPF.INFORMATION135
5586                ,P_VPF_ATTRIBUTE26      => r_VPF.INFORMATION136
5587                ,P_VPF_ATTRIBUTE27      => r_VPF.INFORMATION137
5588                ,P_VPF_ATTRIBUTE28      => r_VPF.INFORMATION138
5589                ,P_VPF_ATTRIBUTE29      => r_VPF.INFORMATION139
5590                ,P_VPF_ATTRIBUTE3      => r_VPF.INFORMATION113
5591                ,P_VPF_ATTRIBUTE30      => r_VPF.INFORMATION140
5592                ,P_VPF_ATTRIBUTE4      => r_VPF.INFORMATION114
5593                ,P_VPF_ATTRIBUTE5      => r_VPF.INFORMATION115
5594                ,P_VPF_ATTRIBUTE6      => r_VPF.INFORMATION116
5595                ,P_VPF_ATTRIBUTE7      => r_VPF.INFORMATION117
5596                ,P_VPF_ATTRIBUTE8      => r_VPF.INFORMATION118
5597                ,P_VPF_ATTRIBUTE9      => r_VPF.INFORMATION119
5598                ,P_VPF_ATTRIBUTE_CATEGORY      => r_VPF.INFORMATION110
5599                ,P_VRBL_RT_PRFL_ID      => l_vrbl_rt_prfl_id
5600                ,P_VRBL_RT_PRFL_STAT_CD      => r_VPF.INFORMATION77
5601                ,P_VRBL_RT_TRTMT_CD      => r_VPF.INFORMATION66
5602                ,P_VRBL_USG_CD      => r_VPF.INFORMATION78
5603                ,P_RT_ELIG_PRFL_FLAG => NVL(r_VPF.INFORMATION83,'N')
5604              --
5605              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
5606              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
5607              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
5608            );
5609            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
5610            -- Update all relevent cer records with new pk_id
5611            hr_utility.set_location('Before plsql table ',222);
5612            hr_utility.set_location('new_value id '||l_vrbl_rt_prfl_id,222);
5613            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'VRBL_RT_PRFL_ID' ;
5614            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_VPF.information1 ;
5615            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_VRBL_RT_PRFL_ID ;
5616            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
5617            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_VPF_unique.table_route_id;
5618            hr_utility.set_location('After plsql table ',222);
5619            --
5620            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
5621            --
5622            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
5623            ben_pd_copy_to_ben_one.log_data('VPF',l_new_value,l_prefix || r_VPF.information170|| l_suffix,'COPIED');
5624            --
5625          else
5626            --
5627            -- Call Update routine for the pk_id created in prev run .
5628            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
5629            hr_utility.set_location(' BEN_VRBL_RT_PRFL_F UPDATE_VRBL_RATE_PROFILE ',30);
5630 
5631            --UPD START
5632            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
5633            --
5634            if l_update then
5635              --
5636              l_datetrack_mode := r_VPF.datetrack_mode ;
5637              --
5638              get_dt_modes(
5639                p_effective_date        => l_process_date,
5640                p_effective_end_date    => r_VPF.information3,
5641                p_effective_start_date  => r_VPF.information2,
5642                p_dml_operation         => r_VPF.dml_operation,
5643                p_datetrack_mode        => l_datetrack_mode );
5644            --    p_update                => l_update
5645              --
5646              l_effective_date := l_process_date;
5647              l_vrbl_rt_prfl_id   := r_VPF.information1;
5648              l_object_version_number := r_VPF.information265;
5649              --
5650            end if;
5651            --
5652            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
5653            --
5654            IF l_update OR l_dml_operation <> 'UPDATE' THEN
5655            --UPD END
5656 
5657                    BEN_VRBL_RATE_PROFILE_API.UPDATE_VRBL_RATE_PROFILE(
5658                      --
5659                      P_VALIDATE               => false
5660                      ,P_EFFECTIVE_DATE        => l_effective_date
5661                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
5662                      --
5663                      ,P_ACTY_REF_PERD_CD      => r_VPF.INFORMATION67
5664                      ,P_ACTY_TYP_CD      => r_VPF.INFORMATION72
5665                      ,P_ALWYS_CNT_ALL_PRTTS_FLAG      => r_VPF.INFORMATION76
5666                      ,P_ALWYS_SUM_ALL_CVG_FLAG      => r_VPF.INFORMATION75
5667                      ,P_ANN_MN_ELCN_VAL      => r_VPF.INFORMATION297
5668                      ,P_ANN_MX_ELCN_VAL      => r_VPF.INFORMATION298
5669                      ,P_ASMT_TO_USE_CD      => r_VPF.INFORMATION71
5670                      ,P_BNFT_RT_TYP_CD      => r_VPF.INFORMATION74
5671                      ,P_COMP_LVL_FCTR_ID      => l_COMP_LVL_FCTR_ID
5672                      ,P_DFLT_ELCN_VAL      => r_VPF.INFORMATION300
5673                      ,P_INCRMNT_ELCN_VAL      => r_VPF.INFORMATION299
5674                      ,P_LWR_LMT_CALC_RL      => l_LWR_LMT_CALC_RL
5675                      ,P_LWR_LMT_VAL      => r_VPF.INFORMATION295
5676                      ,P_MLT_CD      => r_VPF.INFORMATION68
5677                      ,P_MN_ELCN_VAL      => r_VPF.INFORMATION302
5678                      ,P_MX_ELCN_VAL      => r_VPF.INFORMATION301
5679                      ,P_NAME      => l_prefix || r_VPF.INFORMATION170 || l_suffix
5680                      ,P_NO_MN_ELCN_VAL_DFND_FLAG      => r_VPF.INFORMATION69
5681                      ,P_NO_MX_ELCN_VAL_DFND_FLAG      => r_VPF.INFORMATION70
5682                      ,P_OIPL_ID      => l_OIPL_ID
5683                      ,P_PL_ID      => l_PL_ID
5684                      ,P_PL_TYP_OPT_TYP_ID      => l_PL_TYP_OPT_TYP_ID
5685                      ,P_RNDG_CD      => r_VPF.INFORMATION79
5686                      ,P_RNDG_RL      => l_RNDG_RL
5687                      ,P_RT_AGE_FLAG      => r_VPF.INFORMATION38
5688                      ,P_RT_ASNT_SET_FLAG      => r_VPF.INFORMATION45
5689                      ,P_RT_BENFTS_GRP_FLAG      => r_VPF.INFORMATION35
5690                      ,P_RT_BRGNG_UNIT_FLAG      => r_VPF.INFORMATION37
5691                      ,P_RT_CBR_QUALD_BNF_FLAG      => r_VPF.INFORMATION24
5692                      ,P_RT_CMBN_AGE_LOS_FLAG      => r_VPF.INFORMATION54
5693                      ,P_RT_CNTNG_PRTN_PRFL_FLAG      => r_VPF.INFORMATION23
5694                      ,P_RT_COMPTNCY_FLAG      => r_VPF.INFORMATION25
5695                      ,P_RT_COMP_LVL_FLAG      => r_VPF.INFORMATION47
5696                      ,P_RT_DPNT_CVRD_PGM_FLAG      => r_VPF.INFORMATION11
5697                      ,P_RT_DPNT_CVRD_PLIP_FLAG      => r_VPF.INFORMATION29
5698                      ,P_RT_DPNT_CVRD_PL_FLAG      => r_VPF.INFORMATION82
5699                      ,P_RT_DPNT_CVRD_PTIP_FLAG      => r_VPF.INFORMATION30
5700                      ,P_RT_DPNT_OTHR_PTIP_FLAG      => r_VPF.INFORMATION20
5701                      ,P_RT_DSBLD_FLAG      => r_VPF.INFORMATION58
5702                      ,P_RT_EE_STAT_FLAG      => r_VPF.INFORMATION42
5703         --           ,P_RT_ELIG_PRFL_FLAG      => r_VPF.Not found
5704                      ,P_RT_ENRLD_OIPL_FLAG      => r_VPF.INFORMATION12
5705                      ,P_RT_ENRLD_PGM_FLAG      => r_VPF.INFORMATION16
5706                      ,P_RT_ENRLD_PLIP_FLAG      => r_VPF.INFORMATION14
5707                      ,P_RT_ENRLD_PL_FLAG      => r_VPF.INFORMATION13
5708                      ,P_RT_ENRLD_PTIP_FLAG      => r_VPF.INFORMATION15
5709                      ,P_RT_FL_TM_PT_TM_FLAG      => r_VPF.INFORMATION41
5710                      ,P_RT_GNDR_FLAG      => r_VPF.INFORMATION63
5711                      ,P_RT_GRD_FLAG      => r_VPF.INFORMATION43
5712                      ,P_RT_HLTH_CVG_FLAG      => r_VPF.INFORMATION59
5713                      ,P_RT_HRLY_SLRD_FLAG      => r_VPF.INFORMATION31
5714                      ,P_RT_HRS_WKD_FLAG      => r_VPF.INFORMATION46
5715                      ,P_RT_JOB_FLAG      => r_VPF.INFORMATION80
5716                      ,P_RT_LBR_MMBR_FLAG      => r_VPF.INFORMATION33
5717                      ,P_RT_LGL_ENTY_FLAG      => r_VPF.INFORMATION34
5718                      ,P_RT_LOA_RSN_FLAG      => r_VPF.INFORMATION49
5719                      ,P_RT_LOS_FLAG      => r_VPF.INFORMATION39
5720                      ,P_RT_LVG_RSN_FLAG      => r_VPF.INFORMATION27
5721                      ,P_RT_NO_OTHR_CVG_FLAG      => r_VPF.INFORMATION19
5722                      ,P_RT_OPTD_MDCR_FLAG      => r_VPF.INFORMATION26
5723                      ,P_RT_ORG_UNIT_FLAG      => r_VPF.INFORMATION48
5724                      ,P_RT_OTHR_PTIP_FLAG      => r_VPF.INFORMATION18
5725                      ,P_RT_PCT_FL_TM_FLAG      => r_VPF.INFORMATION44
5726                      ,P_RT_PERF_RTNG_FLAG      => r_VPF.INFORMATION21
5727                      ,P_RT_PER_TYP_FLAG      => r_VPF.INFORMATION40
5728                      ,P_RT_POE_FLAG      => r_VPF.INFORMATION60
5729                      ,P_RT_PPL_GRP_FLAG      => r_VPF.INFORMATION57
5730                      ,P_RT_PRFL_RL_FLAG      => r_VPF.INFORMATION53
5731                      ,P_RT_PRTT_ANTHR_PL_FLAG      => r_VPF.INFORMATION17
5732                      ,P_RT_PRTT_PL_FLAG      => r_VPF.INFORMATION55
5733                      ,P_RT_PSTL_CD_FLAG      => r_VPF.INFORMATION32
5734                      ,P_RT_PSTN_FLAG      => r_VPF.INFORMATION28
5735                      ,P_RT_PYRL_FLAG      => r_VPF.INFORMATION50
5736                      ,P_RT_PY_BSS_FLAG      => r_VPF.INFORMATION52
5737                      ,P_RT_QUAL_TITL_FLAG      => r_VPF.INFORMATION81
5738                      ,P_RT_QUA_IN_GR_FLAG      => r_VPF.INFORMATION22
5739                      ,P_RT_SCHEDD_HRS_FLAG      => r_VPF.INFORMATION51
5740                      ,P_RT_SVC_AREA_FLAG      => r_VPF.INFORMATION56
5741                      ,P_RT_TBCO_USE_FLAG      => r_VPF.INFORMATION64
5742                      ,P_RT_TTL_CVG_VOL_FLAG      => r_VPF.INFORMATION61
5743                      ,P_RT_TTL_PRTT_FLAG      => r_VPF.INFORMATION62
5744                      ,P_RT_TYP_CD      => r_VPF.INFORMATION73
5745                      ,P_RT_WK_LOC_FLAG      => r_VPF.INFORMATION36
5746                      ,P_TX_TYP_CD      => r_VPF.INFORMATION65
5747                      ,P_ULTMT_LWR_LMT      => r_VPF.INFORMATION293
5748                      ,P_ULTMT_LWR_LMT_CALC_RL      => l_ULTMT_LWR_LMT_CALC_RL
5749                      ,P_ULTMT_UPR_LMT      => r_VPF.INFORMATION294
5750                      ,P_ULTMT_UPR_LMT_CALC_RL      => l_ULTMT_UPR_LMT_CALC_RL
5751                      ,P_UPR_LMT_CALC_RL      => l_UPR_LMT_CALC_RL
5752                      ,P_UPR_LMT_VAL      => r_VPF.INFORMATION296
5753                      ,P_VAL      => r_VPF.INFORMATION303
5754                      ,P_VAL_CALC_RL      => l_VAL_CALC_RL
5755                      ,P_VPF_ATTRIBUTE1      => r_VPF.INFORMATION111
5756                      ,P_VPF_ATTRIBUTE10      => r_VPF.INFORMATION120
5757                      ,P_VPF_ATTRIBUTE11      => r_VPF.INFORMATION121
5758                      ,P_VPF_ATTRIBUTE12      => r_VPF.INFORMATION122
5759                      ,P_VPF_ATTRIBUTE13      => r_VPF.INFORMATION123
5760                      ,P_VPF_ATTRIBUTE14      => r_VPF.INFORMATION124
5761                      ,P_VPF_ATTRIBUTE15      => r_VPF.INFORMATION125
5762                      ,P_VPF_ATTRIBUTE16      => r_VPF.INFORMATION126
5763                      ,P_VPF_ATTRIBUTE17      => r_VPF.INFORMATION127
5764                      ,P_VPF_ATTRIBUTE18      => r_VPF.INFORMATION128
5765                      ,P_VPF_ATTRIBUTE19      => r_VPF.INFORMATION129
5766                      ,P_VPF_ATTRIBUTE2      => r_VPF.INFORMATION112
5767                      ,P_VPF_ATTRIBUTE20      => r_VPF.INFORMATION130
5768                      ,P_VPF_ATTRIBUTE21      => r_VPF.INFORMATION131
5769                      ,P_VPF_ATTRIBUTE22      => r_VPF.INFORMATION132
5770                      ,P_VPF_ATTRIBUTE23      => r_VPF.INFORMATION133
5771                      ,P_VPF_ATTRIBUTE24      => r_VPF.INFORMATION134
5772                      ,P_VPF_ATTRIBUTE25      => r_VPF.INFORMATION135
5773                      ,P_VPF_ATTRIBUTE26      => r_VPF.INFORMATION136
5774                      ,P_VPF_ATTRIBUTE27      => r_VPF.INFORMATION137
5775                      ,P_VPF_ATTRIBUTE28      => r_VPF.INFORMATION138
5776                      ,P_VPF_ATTRIBUTE29      => r_VPF.INFORMATION139
5777                      ,P_VPF_ATTRIBUTE3      => r_VPF.INFORMATION113
5778                      ,P_VPF_ATTRIBUTE30      => r_VPF.INFORMATION140
5779                      ,P_VPF_ATTRIBUTE4      => r_VPF.INFORMATION114
5780                      ,P_VPF_ATTRIBUTE5      => r_VPF.INFORMATION115
5781                      ,P_VPF_ATTRIBUTE6      => r_VPF.INFORMATION116
5782                      ,P_VPF_ATTRIBUTE7      => r_VPF.INFORMATION117
5783                      ,P_VPF_ATTRIBUTE8      => r_VPF.INFORMATION118
5784                      ,P_VPF_ATTRIBUTE9      => r_VPF.INFORMATION119
5785                      ,P_VPF_ATTRIBUTE_CATEGORY      => r_VPF.INFORMATION110
5786                      ,P_VRBL_RT_PRFL_ID      => l_vrbl_rt_prfl_id
5787                      ,P_VRBL_RT_PRFL_STAT_CD      => r_VPF.INFORMATION77
5788                      ,P_VRBL_RT_TRTMT_CD      => r_VPF.INFORMATION66
5789                      ,P_VRBL_USG_CD      => r_VPF.INFORMATION78
5790                      --
5791                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
5792                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
5793                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
5794                      -- UPD START
5795                      --,P_DATETRACK_MODE        => hr_api.g_update
5796                      ,P_DATETRACK_MODE        => l_datetrack_mode
5797                      -- UPD END
5798                 );
5799 
5800            end if;  -- l_update
5801 
5802          end if;
5803          --
5804          --
5805          -- Delete the row if it is end dated.
5806          --
5807          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
5808              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
5809              trunc(l_max_eed) = r_VPF.information3) then
5810              --
5811              BEN_VRBL_RATE_PROFILE_API.delete_VRBL_RATE_PROFILE(
5812                 --
5813                 p_validate                       => false
5814                 ,p_vrbl_rt_prfl_id                   => l_vrbl_rt_prfl_id
5815                 ,p_effective_start_date           => l_effective_start_date
5816                 ,p_effective_end_date             => l_effective_end_date
5817                 ,p_object_version_number          => l_object_version_number
5818                 ,p_effective_date                 => l_max_eed
5819                 ,p_datetrack_mode                 => hr_api.g_delete
5820                 --
5821                 );
5822                 --
5823          end if;
5824          --
5825          l_prev_pk_id := l_current_pk_id ;
5826          --
5827        end if;
5828        --
5829      end if;
5830      --
5831    end loop;
5832    --
5833  exception when others then
5834      --
5835      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'VPF', l_prefix || r_VPF.information170 || l_suffix) ;
5836      --
5837  end create_VPF_rows;
5838 
5839    --
5840    ---------------------------------------------------------------
5841    ----------------------< create_CCM_rows >-----------------------
5842    ---------------------------------------------------------------
5843    --
5844    procedure create_CCM_rows
5845    (
5846          p_validate                       in  number     default 0
5847         ,p_copy_entity_txn_id             in  number
5848         ,p_effective_date                 in  date
5849         ,p_prefix_suffix_text             in  varchar2  default null
5850         ,p_reuse_object_flag              in  varchar2  default null
5851         ,p_target_business_group_id       in  varchar2  default null
5852         ,p_prefix_suffix_cd               in  varchar2  default null
5853    ) is
5854    --
5855    l_COMP_LVL_FCTR_ID  number;
5856    l_LWR_LMT_CALC_RL  number;
5857    l_OIPL_ID  number;
5858    l_PLIP_ID  number;
5859    l_PL_ID  number;
5860    l_RNDG_RL  number;
5861    l_UPR_LMT_CALC_RL  number;
5862    l_VAL_CALC_RL  number;
5863    cursor c_unique_CCM(l_table_alias varchar2) is
5864    select distinct cpe.information1,
5865      cpe.information2,
5866      cpe.information3,
5867      cpe.information170 name,
5868      cpe.table_route_id,
5869      cpe.dml_operation,
5870      cpe.datetrack_mode
5871    from ben_copy_entity_results cpe,
5872         pqh_table_route tr
5873    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
5874    and   cpe.table_route_id     = tr.table_route_id
5875    -- and   tr.where_clause        = l_BEN_CVG_AMT_CALC_MTHD_F
5876    and   tr.table_alias = l_table_alias
5877    and   cpe.number_of_copies   = 1 -- ADDITION
5878    group by cpe.information1,cpe.information2,cpe.information3, cpe.information170, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
5879    order by information1, information2; --added for bug: 5151945
5880    --
5881    --
5882    cursor c_CCM_min_max_dates(c_table_route_id  number,
5883                 c_information1   number) is
5884    select
5885      min(cpe.information2) min_esd,
5886      max(cpe.information3) min_eed
5887    from ben_copy_entity_results cpe
5888    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
5889    and   cpe.table_route_id     = c_table_route_id
5890    and   cpe.information1       = c_information1 ;
5891    --
5892    cursor c_CCM(c_table_route_id  number,
5893                 c_information1   number,
5894                 c_information2   date,
5895                 c_information3   date)  is
5896    select
5897      cpe.*
5898    from ben_copy_entity_results cpe
5899    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
5900    and   cpe.table_route_id     = c_table_route_id
5901    and   cpe.information1       = c_information1
5902    and   cpe.information2       = c_information2
5903    and   cpe.information3       = c_information3
5904    and rownum = 1 ;
5905    -- Date Track target record
5906    cursor c_find_CCM_in_target( c_CCM_name           varchar2,
5907                                 c_effective_start_date    date,
5908                                 c_effective_end_date      date,
5909                                 c_business_group_id       number,
5910                                 c_new_pk_id               number) is
5911    select
5912      CCM.cvg_amt_calc_mthd_id new_value
5913    from BEN_CVG_AMT_CALC_MTHD_F CCM
5914    where  CCM.name               = c_CCM_name and
5915    nvl(CCM.OIPL_ID,-999)     = nvl(l_OIPL_ID,-999)  and
5916    nvl(CCM.PLIP_ID,-999)     = nvl(l_PLIP_ID,-999)  and
5917    nvl(CCM.PL_ID,-999)     = nvl(l_PL_ID,-999)  and
5918    CCM.business_group_id  = c_business_group_id
5919    and   CCM.cvg_amt_calc_mthd_id  <> c_new_pk_id
5920 --TEMPIK
5921    and c_effective_start_date between effective_start_date
5922                             and effective_end_date ;
5923 --END TEMPIK
5924 /*TEMPIK
5925    and exists ( select null
5926                 from BEN_CVG_AMT_CALC_MTHD_F CCM1
5927                 where CCM1.name               = c_CCM_name and
5928                 nvl(CCM1.OIPL_ID,-999)     = nvl(l_OIPL_ID,-999)  and
5929                 nvl(CCM1.PLIP_ID,-999)     = nvl(l_PLIP_ID,-999)  and
5930                 nvl(CCM1.PL_ID,-999)     = nvl(l_PL_ID,-999)  and
5931                 CCM1.business_group_id  = c_business_group_id
5932                 and   CCM1.effective_start_date <= c_effective_start_date )
5933    and exists ( select null
5934                 from BEN_CVG_AMT_CALC_MTHD_F CCM2
5935                 where CCM2.name               = c_CCM_name and
5936                 nvl(CCM2.OIPL_ID,-999)     = nvl(l_OIPL_ID,-999)  and
5937                 nvl(CCM2.PLIP_ID,-999)     = nvl(l_PLIP_ID,-999)  and
5938                 nvl(CCM2.PL_ID,-999)     = nvl(l_PL_ID,-999)  and
5939                 CCM2.business_group_id  = c_business_group_id
5940                 and   CCM2.effective_end_date >= c_effective_end_date )
5941                 ;
5942    --
5943 TEMPIK */
5944    --TEMPIK
5945    l_dt_rec_found            boolean ;
5946    --END TEMPIK
5947    --
5948     cursor c_find_CCM_name_in_target( c_CCM_name           varchar2,
5949                                 c_effective_start_date    date,
5950                                 c_effective_end_date      date,
5951                                 c_business_group_id       number,
5952                                 c_new_pk_id               number) is
5953    select
5954      CCM.cvg_amt_calc_mthd_id new_value
5955    from BEN_CVG_AMT_CALC_MTHD_F CCM
5956    where  CCM.name               = c_CCM_name and
5957    CCM.business_group_id  = c_business_group_id
5958    and   CCM.cvg_amt_calc_mthd_id  <> c_new_pk_id
5959 --TEMPIK
5960    and c_effective_start_date between effective_start_date
5961                             and effective_end_date ;
5962 --END TEMPIK
5963 /*TEMPIK
5964    and exists ( select null
5965                 from BEN_CVG_AMT_CALC_MTHD_F CCM1
5966                 where CCM1.name               = c_CCM_name and
5967                 CCM1.business_group_id  = c_business_group_id
5968                 and   CCM1.effective_start_date <= c_effective_start_date )
5969    and exists ( select null
5970                 from BEN_CVG_AMT_CALC_MTHD_F CCM2
5971                 where CCM2.name               = c_CCM_name and
5972                 CCM2.business_group_id  = c_business_group_id
5973                 and   CCM2.effective_end_date >= c_effective_end_date )
5974                 ;
5975 TEMPIK */
5976 
5977    --UPD START
5978    --
5979    l_update                  boolean      := false ;
5980    l_datetrack_mode          varchar2(80) := hr_api.g_update;
5981    l_process_date            date;
5982    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
5983    --
5984    --UPD END
5985 
5986    l_current_pk_id           number := null ;
5987    l_prev_pk_id              number := null ;
5988    l_first_rec               boolean := true ;
5989    r_CCM                     c_CCM%rowtype;
5990    l_cvg_amt_calc_mthd_id             number ;
5991    l_object_version_number   number ;
5992    l_effective_start_date    date ;
5993    l_effective_end_date      date ;
5994    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
5995    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
5996    l_new_value               number(15);
5997    l_object_found_in_target  boolean := false ;
5998    l_min_esd                 date;
5999    l_max_eed                 date;
6000    l_effective_date          date;
6001    --
6002  begin
6003    -- Initialization
6004    l_object_found_in_target := false ;
6005    -- End Initialization
6006    -- Derive the prefix - sufix
6007    -- End Prefix Sufix derivation
6008    for r_CCM_unique in c_unique_CCM('CCM') loop
6009 
6010      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
6011         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
6012          r_CCM_unique.information3 >=
6013                  ben_pd_copy_to_ben_one.g_copy_effective_date)
6014         ) then
6015        --
6016        if   p_prefix_suffix_cd = 'PREFIX' then
6017          l_prefix  := p_prefix_suffix_text ;
6018        elsif p_prefix_suffix_cd = 'SUFFIX' then
6019          l_suffix   := p_prefix_suffix_text ;
6020        else
6021          l_prefix := null ;
6022          l_suffix  := null ;
6023        end if ;
6024        --
6025        hr_utility.set_location(' r_CCM_unique.table_route_id '||r_CCM_unique.table_route_id,10);
6026        hr_utility.set_location(' r_CCM_unique.information1 '||r_CCM_unique.information1,10);
6027        hr_utility.set_location( 'r_CCM_unique.information2 '||r_CCM_unique.information2,10);
6028        hr_utility.set_location( 'r_CCM_unique.information3 '||r_CCM_unique.information3,10);
6029        -- If reuse objects flag is 'Y' then check for the object in the target business group
6030        -- if found insert the record into PLSql table and exit the loop else try create the
6031        -- object in the target business group
6032        --
6033        l_object_found_in_target := false ;
6034 
6035        --UPD START
6036        l_update := false;
6037        l_process_date := p_effective_date;
6038        l_dml_operation:= r_CCM_unique.dml_operation ;
6039        open c_CCM(r_CCM_unique.table_route_id,
6040                 r_CCM_unique.information1,
6041                 r_CCM_unique.information2,
6042                 r_CCM_unique.information3 ) ;
6043        --
6044        fetch c_CCM into r_CCM ;
6045        --
6046        close c_CCM ;
6047        --
6048        l_COMP_LVL_FCTR_ID := get_fk('COMP_LVL_FCTR_ID', r_CCM.information254,r_CCM.dml_operation);
6049        l_LWR_LMT_CALC_RL := get_fk('FORMULA_ID', r_CCM.information257,r_CCM.dml_operation);
6050        l_OIPL_ID := get_fk('OIPL_ID', r_CCM.information258,r_CCM.dml_operation);
6051        l_PLIP_ID := get_fk('PLIP_ID', r_CCM.information256,r_CCM.dml_operation);
6052        l_PL_ID := get_fk('PL_ID', r_CCM.information261,r_CCM.dml_operation);
6053        l_RNDG_RL := get_fk('FORMULA_ID', r_CCM.information264,r_CCM.dml_operation);
6054        l_UPR_LMT_CALC_RL := get_fk('FORMULA_ID', r_CCM.information259,r_CCM.dml_operation);
6055        l_VAL_CALC_RL := get_fk('FORMULA_ID', r_CCM.information266,r_CCM.dml_operation);
6056        --
6057        if l_dml_operation = 'UPDATE' then
6058          --
6059                  l_object_found_in_target := TRUE;
6060                  --
6061                  if l_process_date between r_CCM_unique.information2 and r_CCM_unique.information3 then
6062                        l_update := true;
6063                        if r_CCM_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
6064                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'CVG_AMT_CALC_MTHD_ID'
6065                        then
6066                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'CVG_AMT_CALC_MTHD_ID' ;
6067                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_CCM_unique.information1 ;
6068                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_CCM_unique.information1 ;
6069                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
6070                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_CCM_unique.table_route_id;
6071                           --
6072                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
6073                           --
6074                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
6075                           --
6076                           BEN_PD_COPY_TO_BEN_ONE.log_data('CCM',l_new_value,l_prefix || r_CCM_unique.name|| l_suffix,'REUSED');
6077                           --
6078                        end if ;
6079                        hr_utility.set_location( 'found record for update',10);
6080                    --
6081                  else
6082                    --
6083                    l_update := false;
6084                    --
6085                  end if;
6086        --
6087        else
6088        --
6089        --UPD END
6090 
6091                l_min_esd := null ;
6092                l_max_eed := null ;
6093                open c_CCM_min_max_dates(r_CCM_unique.table_route_id, r_CCM_unique.information1 ) ;
6094                fetch c_CCM_min_max_dates into l_min_esd,l_max_eed ;
6095                --
6096 
6097                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
6098                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
6099                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
6100                end if;
6101                l_min_esd := greatest(l_min_esd,r_CCM_unique.information2);
6102                if p_reuse_object_flag = 'Y' then
6103                  if c_CCM_min_max_dates%found then
6104                    -- cursor to find the object
6105                    open c_find_CCM_in_target( l_prefix || r_CCM_unique.name|| l_suffix  ,l_min_esd,l_max_eed,
6106                                          p_target_business_group_id, nvl(l_cvg_amt_calc_mthd_id, -999)  ) ;
6107                    fetch c_find_CCM_in_target into l_new_value ;
6108                    if c_find_CCM_in_target%found then
6109                      --TEMPIK
6110                      l_dt_rec_found :=   dt_api.check_min_max_dates
6111                          (p_base_table_name => 'BEN_CVG_AMT_CALC_MTHD_F',
6112                           p_base_key_column => 'CVG_AMT_CALC_MTHD_ID',
6113                           p_base_key_value  => l_new_value,
6114                           p_from_date       => l_min_esd,
6115                           p_to_date         => l_max_eed );
6116                      if l_dt_rec_found THEN
6117                      --END TEMPIK
6118                      --
6119                                          if r_CCM_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
6120                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'CVG_AMT_CALC_MTHD_ID'  then
6121                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'CVG_AMT_CALC_MTHD_ID' ;
6122                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_CCM_unique.information1 ;
6123                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
6124                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
6125                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_CCM_unique.table_route_id;
6126                                                 --
6127                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
6128                                                 --
6129                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
6130                                                 ben_pd_copy_to_ben_one.log_data('CCM',l_new_value,l_prefix || r_CCM_unique.name|| l_suffix,'REUSED');
6131                                          end if ;
6132                                          --
6133                                          l_object_found_in_target := true ;
6134                      --TEMPIK
6135                      end if; -- l_dt_rec_found
6136                      --END TEMPIK
6137                    else
6138                      if p_prefix_suffix_text is null then
6139                        --
6140                        open c_find_CCM_name_in_target( l_prefix || r_CCM_unique.name|| l_suffix  ,
6141                                        l_min_esd,l_max_eed,
6142                                        p_target_business_group_id, nvl(l_cvg_amt_calc_mthd_id, -999) ) ;
6143                        fetch c_find_CCM_name_in_target into l_new_value ;
6144                        if c_find_CCM_name_in_target%found then
6145                          --
6146                                          --TEMPIK
6147                                          l_dt_rec_found :=   dt_api.check_min_max_dates
6148                                                  (p_base_table_name => 'BEN_CVG_AMT_CALC_MTHD_F',
6149                                                   p_base_key_column => 'CVG_AMT_CALC_MTHD_ID',
6150                                                   p_base_key_value  => l_new_value,
6151                                                   p_from_date       => l_min_esd,
6152                                                   p_to_date         => l_max_eed );
6153                                          if l_dt_rec_found THEN
6154                                          --END TEMPIK
6155                                                  if   p_prefix_suffix_cd = 'PREFIX' then
6156                                                    l_prefix  := BEN_PLAN_DESIGN_TXNS_API.g_pgm_pl_prefix_suffix_text ;
6157                                                  elsif p_prefix_suffix_cd = 'SUFFIX' then
6158                                                    l_suffix   := BEN_PLAN_DESIGN_TXNS_API.g_pgm_pl_prefix_suffix_text ;
6159                                                  else
6160                                                    l_prefix := null ;
6161                                                    l_suffix  := null ;
6162                                                  end if ;
6163                                          --TEMPIK
6164                                          end if; -- l_dt_rec_found
6165                                          --END TEMPIK
6166                          --
6167                        end if;
6168                      close c_find_CCM_name_in_target ;
6169                      end if;
6170                    end if;
6171                    close c_find_CCM_in_target ;
6172                  --
6173                  end if;
6174                end if ;
6175                --
6176                close c_CCM_min_max_dates ;
6177 
6178        -- UPD START
6179        end if; --if p_dml_operation
6180        --
6181        if not l_object_found_in_target OR l_update  then
6182        --if not l_object_found_in_target then
6183        -- UPD END
6184 
6185          --
6186          l_current_pk_id := r_CCM.information1;
6187          --
6188          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
6189          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
6190          --
6191          if l_current_pk_id =  l_prev_pk_id  then
6192            --
6193            l_first_rec := false ;
6194            --
6195          else
6196            --
6197            l_first_rec := true ;
6198            --
6199          end if ;
6200          --
6201          ben_pd_copy_to_ben_one.ben_chk_col_len('NAME' ,'BEN_CVG_AMT_CALC_MTHD_F',l_prefix || r_CCM.information170 || l_suffix);
6202          --
6203 
6204          l_effective_date := r_CCM.information2;
6205          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
6206               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
6207            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
6208          end if;
6209 
6210          -- UPD START
6211          --if l_first_rec then
6212          if l_first_rec and not l_update then
6213          -- UPD END
6214 
6215            -- Call Create routine.
6216            hr_utility.set_location(' BEN_CVG_AMT_CALC_MTHD_F CREATE_CVG_AMT_CALC ',20);
6217            BEN_CVG_AMT_CALC_API.CREATE_CVG_AMT_CALC(
6218              --
6219              P_VALIDATE               => false
6220              ,P_EFFECTIVE_DATE        => l_effective_date
6221              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
6222              --
6223              ,P_BNDRY_PERD_CD      => r_CCM.INFORMATION19
6224              ,P_BNFT_TYP_CD      => r_CCM.INFORMATION20
6225              ,P_CCM_ATTRIBUTE1      => r_CCM.INFORMATION111
6226              ,P_CCM_ATTRIBUTE10      => r_CCM.INFORMATION120
6227              ,P_CCM_ATTRIBUTE11      => r_CCM.INFORMATION121
6228              ,P_CCM_ATTRIBUTE12      => r_CCM.INFORMATION122
6229              ,P_CCM_ATTRIBUTE13      => r_CCM.INFORMATION123
6230              ,P_CCM_ATTRIBUTE14      => r_CCM.INFORMATION124
6231              ,P_CCM_ATTRIBUTE15      => r_CCM.INFORMATION125
6232              ,P_CCM_ATTRIBUTE16      => r_CCM.INFORMATION126
6233              ,P_CCM_ATTRIBUTE17      => r_CCM.INFORMATION127
6234              ,P_CCM_ATTRIBUTE18      => r_CCM.INFORMATION128
6235              ,P_CCM_ATTRIBUTE19      => r_CCM.INFORMATION129
6236              ,P_CCM_ATTRIBUTE2      => r_CCM.INFORMATION112
6237              ,P_CCM_ATTRIBUTE20      => r_CCM.INFORMATION130
6238              ,P_CCM_ATTRIBUTE21      => r_CCM.INFORMATION131
6239              ,P_CCM_ATTRIBUTE22      => r_CCM.INFORMATION132
6240              ,P_CCM_ATTRIBUTE23      => r_CCM.INFORMATION133
6241              ,P_CCM_ATTRIBUTE24      => r_CCM.INFORMATION134
6242              ,P_CCM_ATTRIBUTE25      => r_CCM.INFORMATION135
6243              ,P_CCM_ATTRIBUTE26      => r_CCM.INFORMATION136
6244              ,P_CCM_ATTRIBUTE27      => r_CCM.INFORMATION137
6245              ,P_CCM_ATTRIBUTE28      => r_CCM.INFORMATION138
6246              ,P_CCM_ATTRIBUTE29      => r_CCM.INFORMATION139
6247              ,P_CCM_ATTRIBUTE3      => r_CCM.INFORMATION113
6248              ,P_CCM_ATTRIBUTE30      => r_CCM.INFORMATION140
6249              ,P_CCM_ATTRIBUTE4      => r_CCM.INFORMATION114
6250              ,P_CCM_ATTRIBUTE5      => r_CCM.INFORMATION115
6251              ,P_CCM_ATTRIBUTE6      => r_CCM.INFORMATION116
6252              ,P_CCM_ATTRIBUTE7      => r_CCM.INFORMATION117
6253              ,P_CCM_ATTRIBUTE8      => r_CCM.INFORMATION118
6254              ,P_CCM_ATTRIBUTE9      => r_CCM.INFORMATION119
6255              ,P_CCM_ATTRIBUTE_CATEGORY      => r_CCM.INFORMATION110
6256              ,P_COMP_LVL_FCTR_ID      => l_COMP_LVL_FCTR_ID
6257              ,P_CVG_AMT_CALC_MTHD_ID      => l_cvg_amt_calc_mthd_id
6258              ,P_CVG_MLT_CD      => r_CCM.INFORMATION21
6259              ,P_DFLT_FLAG      => r_CCM.INFORMATION15
6260              ,P_DFLT_VAL      => r_CCM.INFORMATION299
6261              ,P_ENTR_VAL_AT_ENRT_FLAG      => r_CCM.INFORMATION14
6262              ,P_INCRMT_VAL      => r_CCM.INFORMATION295
6263              ,P_LWR_LMT_CALC_RL      => l_LWR_LMT_CALC_RL
6264              ,P_LWR_LMT_VAL      => r_CCM.INFORMATION293
6265              ,P_MN_VAL      => r_CCM.INFORMATION297
6266              ,P_MX_VAL      => r_CCM.INFORMATION296
6267              ,P_NAME      => l_prefix || r_CCM.INFORMATION170 || l_suffix
6268              ,P_NNMNTRY_UOM      => r_CCM.INFORMATION18
6269              ,P_NO_MN_VAL_DFND_FLAG      => r_CCM.INFORMATION12
6270              ,P_NO_MX_VAL_DFND_FLAG      => r_CCM.INFORMATION11
6271              ,P_OIPL_ID      => l_OIPL_ID
6272              ,P_PLIP_ID      => l_PLIP_ID
6273              ,P_PL_ID      => l_PL_ID
6274              ,P_RNDG_CD      => r_CCM.INFORMATION16
6275              ,P_RNDG_RL      => l_RNDG_RL
6276              ,P_RT_TYP_CD      => r_CCM.INFORMATION22
6277              ,P_UOM      => r_CCM.INFORMATION17
6278              ,P_UPR_LMT_CALC_RL      => l_UPR_LMT_CALC_RL
6279              ,P_UPR_LMT_VAL      => r_CCM.INFORMATION294
6280              ,P_VAL      => r_CCM.INFORMATION298
6281              ,P_VAL_CALC_RL      => l_VAL_CALC_RL
6282              ,P_VAL_OVRID_ALWD_FLAG      => r_CCM.INFORMATION13
6283              --
6284              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
6285              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
6286              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
6287            );
6288            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
6289            -- Update all relevent cer records with new pk_id
6290            hr_utility.set_location('Before plsql table ',222);
6291            hr_utility.set_location('new_value id '||l_cvg_amt_calc_mthd_id,222);
6292            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'CVG_AMT_CALC_MTHD_ID' ;
6293            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_CCM.information1 ;
6294            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_CVG_AMT_CALC_MTHD_ID ;
6295            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
6296            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_CCM_unique.table_route_id;
6297            hr_utility.set_location('After plsql table ',222);
6298            --
6299            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
6300            --
6301            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
6302            ben_pd_copy_to_ben_one.log_data('CCM',l_new_value,l_prefix || r_CCM.information170|| l_suffix,'COPIED');
6303            --
6304          else
6305            --
6306            -- Call Update routine for the pk_id created in prev run .
6307            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
6308            hr_utility.set_location(' BEN_CVG_AMT_CALC_MTHD_F UPDATE_CVG_AMT_CALC ',30);
6309            --UPD START
6310            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
6311            --
6312            if l_update then
6313              --
6314              l_datetrack_mode := r_CCM.datetrack_mode ;
6315              --
6316              get_dt_modes(
6317                p_effective_date        => l_process_date,
6318                p_effective_end_date    => r_CCM.information3,
6319                p_effective_start_date  => r_CCM.information2,
6320                p_dml_operation         => r_CCM.dml_operation,
6321                p_datetrack_mode        => l_datetrack_mode );
6322            --    p_update                => l_update
6323              --
6324              l_effective_date := l_process_date;
6325              l_cvg_amt_calc_mthd_id   := r_CCM.information1;
6326              l_object_version_number  := r_CCM.information265;
6327              --
6328            end if;
6329            --
6330            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
6331            --
6332            IF l_update OR l_dml_operation <> 'UPDATE' THEN
6333            --UPD END
6334 
6335                    BEN_CVG_AMT_CALC_API.UPDATE_CVG_AMT_CALC(
6336                      --
6337                      P_VALIDATE               => false
6338                      ,P_EFFECTIVE_DATE        => l_effective_date
6339                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
6340                      --
6341                      ,P_BNDRY_PERD_CD      => r_CCM.INFORMATION19
6342                      ,P_BNFT_TYP_CD      => r_CCM.INFORMATION20
6343                      ,P_CCM_ATTRIBUTE1      => r_CCM.INFORMATION111
6344                      ,P_CCM_ATTRIBUTE10      => r_CCM.INFORMATION120
6345                      ,P_CCM_ATTRIBUTE11      => r_CCM.INFORMATION121
6346                      ,P_CCM_ATTRIBUTE12      => r_CCM.INFORMATION122
6347                      ,P_CCM_ATTRIBUTE13      => r_CCM.INFORMATION123
6348                      ,P_CCM_ATTRIBUTE14      => r_CCM.INFORMATION124
6349                      ,P_CCM_ATTRIBUTE15      => r_CCM.INFORMATION125
6350                      ,P_CCM_ATTRIBUTE16      => r_CCM.INFORMATION126
6351                      ,P_CCM_ATTRIBUTE17      => r_CCM.INFORMATION127
6352                      ,P_CCM_ATTRIBUTE18      => r_CCM.INFORMATION128
6353                      ,P_CCM_ATTRIBUTE19      => r_CCM.INFORMATION129
6354                      ,P_CCM_ATTRIBUTE2      => r_CCM.INFORMATION112
6355                      ,P_CCM_ATTRIBUTE20      => r_CCM.INFORMATION130
6356                      ,P_CCM_ATTRIBUTE21      => r_CCM.INFORMATION131
6357                      ,P_CCM_ATTRIBUTE22      => r_CCM.INFORMATION132
6358                      ,P_CCM_ATTRIBUTE23      => r_CCM.INFORMATION133
6359                      ,P_CCM_ATTRIBUTE24      => r_CCM.INFORMATION134
6360                      ,P_CCM_ATTRIBUTE25      => r_CCM.INFORMATION135
6361                      ,P_CCM_ATTRIBUTE26      => r_CCM.INFORMATION136
6362                      ,P_CCM_ATTRIBUTE27      => r_CCM.INFORMATION137
6363                      ,P_CCM_ATTRIBUTE28      => r_CCM.INFORMATION138
6364                      ,P_CCM_ATTRIBUTE29      => r_CCM.INFORMATION139
6365                      ,P_CCM_ATTRIBUTE3      => r_CCM.INFORMATION113
6366                      ,P_CCM_ATTRIBUTE30      => r_CCM.INFORMATION140
6367                      ,P_CCM_ATTRIBUTE4      => r_CCM.INFORMATION114
6368                      ,P_CCM_ATTRIBUTE5      => r_CCM.INFORMATION115
6369                      ,P_CCM_ATTRIBUTE6      => r_CCM.INFORMATION116
6370                      ,P_CCM_ATTRIBUTE7      => r_CCM.INFORMATION117
6371                      ,P_CCM_ATTRIBUTE8      => r_CCM.INFORMATION118
6372                      ,P_CCM_ATTRIBUTE9      => r_CCM.INFORMATION119
6373                      ,P_CCM_ATTRIBUTE_CATEGORY      => r_CCM.INFORMATION110
6374                      ,P_COMP_LVL_FCTR_ID      => l_COMP_LVL_FCTR_ID
6375                      ,P_CVG_AMT_CALC_MTHD_ID      => l_cvg_amt_calc_mthd_id
6376                      ,P_CVG_MLT_CD      => r_CCM.INFORMATION21
6377                      ,P_DFLT_FLAG      => r_CCM.INFORMATION15
6378                      ,P_DFLT_VAL      => r_CCM.INFORMATION299
6379                      ,P_ENTR_VAL_AT_ENRT_FLAG      => r_CCM.INFORMATION14
6380                      ,P_INCRMT_VAL      => r_CCM.INFORMATION295
6381                      ,P_LWR_LMT_CALC_RL      => l_LWR_LMT_CALC_RL
6382                      ,P_LWR_LMT_VAL      => r_CCM.INFORMATION293
6383                      ,P_MN_VAL      => r_CCM.INFORMATION297
6384                      ,P_MX_VAL      => r_CCM.INFORMATION296
6385                      ,P_NAME      => l_prefix || r_CCM.INFORMATION170 || l_suffix
6386                      ,P_NNMNTRY_UOM      => r_CCM.INFORMATION18
6387                      ,P_NO_MN_VAL_DFND_FLAG      => r_CCM.INFORMATION12
6388                      ,P_NO_MX_VAL_DFND_FLAG      => r_CCM.INFORMATION11
6389                      ,P_OIPL_ID      => l_OIPL_ID
6390                      ,P_PLIP_ID      => l_PLIP_ID
6391                      ,P_PL_ID      => l_PL_ID
6392                      ,P_RNDG_CD      => r_CCM.INFORMATION16
6393                      ,P_RNDG_RL      => l_RNDG_RL
6394                      ,P_RT_TYP_CD      => r_CCM.INFORMATION22
6395                      ,P_UOM      => r_CCM.INFORMATION17
6396                      ,P_UPR_LMT_CALC_RL      => l_UPR_LMT_CALC_RL
6397                      ,P_UPR_LMT_VAL      => r_CCM.INFORMATION294
6398                      ,P_VAL      => r_CCM.INFORMATION298
6399                      ,P_VAL_CALC_RL      => l_VAL_CALC_RL
6400                      ,P_VAL_OVRID_ALWD_FLAG      => r_CCM.INFORMATION13
6401                      --
6402                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
6403                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
6404                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
6405                      ,P_DATETRACK_MODE        => l_datetrack_mode
6406                      --,P_DATETRACK_MODE        => hr_api.g_update
6407                    );
6408                 end if;  -- l_update
6409          end if;
6410          --
6411          --
6412          -- Delete the row if it is end dated.
6413          --
6414          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
6415              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
6416              trunc(l_max_eed) = r_CCM.information3) then
6417              --
6418              BEN_CVG_AMT_CALC_API.delete_CVG_AMT_CALC(
6419                 --
6420                 p_validate                       => false
6421                 ,p_cvg_amt_calc_mthd_id                   => l_cvg_amt_calc_mthd_id
6422                 ,p_effective_start_date           => l_effective_start_date
6423                 ,p_effective_end_date             => l_effective_end_date
6424                 ,p_object_version_number          => l_object_version_number
6425                 ,p_effective_date                 => l_max_eed
6426                 ,p_datetrack_mode                 => hr_api.g_delete
6427                 --
6428                 );
6429                 --
6430          end if;
6431          --
6432          l_prev_pk_id := l_current_pk_id ;
6433          --
6434        end if;
6435        --
6436      end if;
6437      --
6438    end loop;
6439    --
6440  exception when others then
6441      --
6442      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'CCM',l_prefix || r_CCM.information170 || l_suffix) ;
6443      --
6444  end create_CCM_rows;
6445 
6446    --
6447    ---------------------------------------------------------------
6448    ----------------------< create_BVR1_rows >-----------------------
6449    ---------------------------------------------------------------
6450    --
6451    procedure create_BVR1_rows
6452    (
6453          p_validate                       in  number     default 0
6454         ,p_copy_entity_txn_id             in  number
6455         ,p_effective_date                 in  date
6456         ,p_prefix_suffix_text             in  varchar2  default null
6457         ,p_reuse_object_flag              in  varchar2  default null
6458         ,p_target_business_group_id       in  varchar2  default null
6459         ,p_prefix_suffix_cd               in  varchar2  default null
6460    ) is
6461    --
6462    l_CVG_AMT_CALC_MTHD_ID  number;
6463    l_VRBL_RT_PRFL_ID  number;
6464    l_ORDR_NUM         number;
6465    cursor c_unique_BVR1(l_table_alias varchar2) is
6466    select distinct cpe.information1,
6467      cpe.information2,
6468      cpe.information3,
6469      cpe.table_route_id,
6470      cpe.dml_operation,
6471      cpe.datetrack_mode
6472    from ben_copy_entity_results cpe,
6473         pqh_table_route tr
6474    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
6475    and   cpe.table_route_id     = tr.table_route_id
6476    -- and   tr.where_clause        = l_BEN_BNFT_VRBL_RT_F
6477    and   tr.table_alias = l_table_alias
6478    and   cpe.number_of_copies   = 1 -- ADDITION
6479    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
6480    order by information1, information2; --added for bug: 5151945
6481    --
6482    --
6483    cursor c_BVR1_min_max_dates(c_table_route_id  number,
6484                 c_information1   number) is
6485    select
6486      min(cpe.information2) min_esd,
6487      max(cpe.information3) min_eed
6488    from ben_copy_entity_results cpe
6489    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
6490    and   cpe.table_route_id     = c_table_route_id
6491    and   cpe.information1       = c_information1 ;
6492    --
6493    cursor c_BVR1(c_table_route_id  number,
6494                 c_information1   number,
6495                 c_information2   date,
6496                 c_information3   date)  is
6497    select
6498      cpe.*
6499    from ben_copy_entity_results cpe
6500    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
6501    and   cpe.table_route_id     = c_table_route_id
6502    and   cpe.information1       = c_information1
6503    and   cpe.information2       = c_information2
6504    and   cpe.information3       = c_information3
6505    and rownum = 1 ;
6506    -- Date Track target record
6507    cursor c_find_BVR1_in_target(
6508                                 c_effective_start_date    date,
6509                                 c_effective_end_date      date,
6510                                 c_business_group_id       number,
6511                                 c_new_pk_id               number) is
6512    select
6513      BVR1.bnft_vrbl_rt_id new_value
6514    from BEN_BNFT_VRBL_RT_F BVR1
6515    where
6516    BVR1.CVG_AMT_CALC_MTHD_ID     = l_CVG_AMT_CALC_MTHD_ID  and
6517    BVR1.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
6518    NVL(BVR1.ORDR_NUM,-9999)= NVL(l_ORDR_NUM,-9999) and
6519    BVR1.business_group_id  = c_business_group_id
6520    and   BVR1.bnft_vrbl_rt_id  <> c_new_pk_id
6521 --TEMPIK
6522    and c_effective_start_date between effective_start_date
6523                             and effective_end_date ;
6524 --END TEMPIK
6525 /*TEMPIK
6526    and exists ( select null
6527                 from BEN_BNFT_VRBL_RT_F BVR11
6528                 where
6529                 BVR11.CVG_AMT_CALC_MTHD_ID     = l_CVG_AMT_CALC_MTHD_ID  and
6530                 BVR11.ORDR_NUM           = l_ORDR_NUM and
6531                 BVR11.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
6532                 BVR11.business_group_id  = c_business_group_id
6533                 and   BVR11.effective_start_date <= c_effective_start_date )
6534    and exists ( select null
6535                 from BEN_BNFT_VRBL_RT_F BVR12
6536                 where
6537                 BVR12.CVG_AMT_CALC_MTHD_ID     = l_CVG_AMT_CALC_MTHD_ID  and
6538                 BVR12.ORDR_NUM           = l_ORDR_NUM and
6539                 BVR12.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
6540                 BVR12.business_group_id  = c_business_group_id
6541                 and   BVR12.effective_end_date >= c_effective_end_date )
6542                 ;
6543 TEMPIK */
6544    --TEMPIK
6545    l_dt_rec_found            boolean ;
6546    --END TEMPIK
6547    --
6548    --UPD START
6549    --
6550    l_update                  boolean      := false ;
6551    l_datetrack_mode          varchar2(80) := hr_api.g_update;
6552    l_process_date            date;
6553    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
6554    --
6555    --UPD END
6556 
6557    l_current_pk_id           number := null ;
6558    l_prev_pk_id              number := null ;
6559    l_first_rec               boolean := true ;
6560    r_BVR1                     c_BVR1%rowtype;
6561    l_bnft_vrbl_rt_id             number ;
6562    l_object_version_number   number ;
6563    l_effective_start_date    date ;
6564    l_effective_end_date      date ;
6565    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
6566    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
6567    l_new_value               number(15);
6568    l_object_found_in_target  boolean := false ;
6569    l_min_esd                 date;
6570    l_max_eed                 date;
6571    l_effective_date          date;
6572    --
6573  begin
6574    -- Initialization
6575    l_object_found_in_target := false ;
6576    -- End Initialization
6577    -- Derive the prefix - sufix
6578    if   p_prefix_suffix_cd = 'PREFIX' then
6579      l_prefix  := p_prefix_suffix_text ;
6580    elsif p_prefix_suffix_cd = 'SUFFIX' then
6581      l_suffix   := p_prefix_suffix_text ;
6582    else
6583      l_prefix := null ;
6584      l_suffix  := null ;
6585    end if ;
6586    -- End Prefix Sufix derivation
6587    for r_BVR1_unique in c_unique_BVR1('BVR1') loop
6588 
6589      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
6590         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
6591          r_BVR1_unique.information3 >=
6592                  ben_pd_copy_to_ben_one.g_copy_effective_date)
6593         ) then
6594        --
6595        hr_utility.set_location(' r_BVR1_unique.table_route_id '||r_BVR1_unique.table_route_id,10);
6596        hr_utility.set_location(' r_BVR1_unique.information1 '||r_BVR1_unique.information1,10);
6597        hr_utility.set_location( 'r_BVR1_unique.information2 '||r_BVR1_unique.information2,10);
6598        hr_utility.set_location( 'r_BVR1_unique.information3 '||r_BVR1_unique.information3,10);
6599        -- If reuse objects flag is 'Y' then check for the object in the target business group
6600        -- if found insert the record into PLSql table and exit the loop else try create the
6601        -- object in the target business group
6602        --
6603        l_object_found_in_target := false ;
6604 
6605        --UPD START
6606        l_update := false;
6607        l_process_date := p_effective_date;
6608        l_dml_operation:= r_BVR1_unique.dml_operation ;
6609        open c_BVR1(r_BVR1_unique.table_route_id,
6610                 r_BVR1_unique.information1,
6611                 r_BVR1_unique.information2,
6612                 r_BVR1_unique.information3 ) ;
6613        --
6614        fetch c_BVR1 into r_BVR1 ;
6615        --
6616        close c_BVR1 ;
6617        --
6618        l_CVG_AMT_CALC_MTHD_ID := get_fk('CVG_AMT_CALC_MTHD_ID', r_BVR1.information238,r_BVR1.dml_operation);
6619        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_BVR1.information262,r_BVR1.dml_operation);
6620        l_ORDR_NUM        := r_BVR1.information260 ;
6621        --
6622        if l_dml_operation = 'UPDATE' then
6623          --
6624                  l_object_found_in_target := TRUE;
6625                  --
6626                  if l_process_date between r_BVR1_unique.information2 and r_BVR1_unique.information3 then
6627                        l_update := true;
6628                        if r_BVR1_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
6629                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'BNFT_VRBL_RT_ID'
6630                        then
6631                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'BNFT_VRBL_RT_ID' ;
6632                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_BVR1_unique.information1 ;
6633                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_BVR1_unique.information1 ;
6634                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
6635                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_BVR1_unique.table_route_id;
6636                           --
6637                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
6638                           --
6639                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
6640                           --
6641                           -- DOUBT
6642                           --BEN_PD_COPY_TO_BEN_ONE.log_data('BVR1',l_new_value,l_prefix || r_BVR1_unique.name|| l_suffix,'REUSED');
6643                           --
6644                        end if ;
6645                        hr_utility.set_location( 'found record for update',10);
6646                    --
6647                  else
6648                    --
6649                    l_update := false;
6650                    --
6651                  end if;
6652        else
6653        --
6654        --UPD END
6655 
6656                l_min_esd := null ;
6657                l_max_eed := null ;
6658                open c_BVR1_min_max_dates(r_BVR1_unique.table_route_id, r_BVR1_unique.information1 ) ;
6659                fetch c_BVR1_min_max_dates into l_min_esd,l_max_eed ;
6660                --
6661 
6662                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
6663                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
6664                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
6665                end if;
6666                l_min_esd := greatest(l_min_esd,r_BVR1_unique.information2);
6667                --
6668                if p_reuse_object_flag = 'Y' then
6669                  if c_BVR1_min_max_dates%found then
6670                    -- cursor to find the object
6671                    open c_find_BVR1_in_target( l_min_esd,l_max_eed,
6672                                          p_target_business_group_id, nvl(l_bnft_vrbl_rt_id, -999)  ) ;
6673                    fetch c_find_BVR1_in_target into l_new_value ;
6674                    if c_find_BVR1_in_target%found then
6675                      --
6676                      --TEMPIK
6677                      l_dt_rec_found :=   dt_api.check_min_max_dates
6678                          (p_base_table_name => 'BEN_BNFT_VRBL_RT_F',
6679                           p_base_key_column => 'BNFT_VRBL_RT_ID',
6680                           p_base_key_value  => l_new_value,
6681                           p_from_date       => l_min_esd,
6682                           p_to_date         => l_max_eed );
6683                      if l_dt_rec_found THEN
6684                      --END TEMPIK
6685                                          if r_BVR1_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
6686                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'BNFT_VRBL_RT_ID'  then
6687                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'BNFT_VRBL_RT_ID' ;
6688                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_BVR1_unique.information1 ;
6689                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
6690                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
6691                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_BVR1_unique.table_route_id;
6692                                                 --
6693                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
6694                                                 --
6695                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
6696                                          end if ;
6697                                          --
6698                                          l_object_found_in_target := true ;
6699                                  --TEMPIK
6700                                  end if; -- l_dt_rec_found
6701                      --END TEMPIK
6702                    end if;
6703                    close c_find_BVR1_in_target ;
6704                  --
6705                  end if;
6706                end if ;
6707                --
6708                close c_BVR1_min_max_dates ;
6709        -- UPD START
6710        --if not l_object_found_in_target then
6711        end if; --if p_dml_operation
6712        --
6713        if not l_object_found_in_target OR l_update  then
6714        -- UPD END
6715 
6716          --
6717          l_current_pk_id := r_BVR1.information1;
6718          --
6719          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
6720          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
6721          --
6722          if l_current_pk_id =  l_prev_pk_id  then
6723            --
6724            l_first_rec := false ;
6725            --
6726          else
6727            --
6728            l_first_rec := true ;
6729            --
6730          end if ;
6731          --
6732 
6733          l_effective_date := r_BVR1.information2;
6734          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
6735               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
6736            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
6737          end if;
6738 
6739          -- UPD START
6740          --if l_first_rec then
6741          if l_first_rec and not l_update then
6742          -- UPD END
6743 
6744            -- Call Create routine.
6745            hr_utility.set_location(' BEN_BNFT_VRBL_RT_F CREATE_BNFT_VRBL_RT ',20);
6746            BEN_BNFT_VRBL_RT_API.CREATE_BNFT_VRBL_RT(
6747              --
6748              P_VALIDATE               => false
6749              ,P_EFFECTIVE_DATE        => l_effective_date
6750              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
6751              --
6752              ,P_BNFT_VRBL_RT_ID      => l_bnft_vrbl_rt_id
6753              ,P_BVR_ATTRIBUTE1      => r_BVR1.INFORMATION111
6754              ,P_BVR_ATTRIBUTE10      => r_BVR1.INFORMATION120
6755              ,P_BVR_ATTRIBUTE11      => r_BVR1.INFORMATION121
6756              ,P_BVR_ATTRIBUTE12      => r_BVR1.INFORMATION122
6757              ,P_BVR_ATTRIBUTE13      => r_BVR1.INFORMATION123
6758              ,P_BVR_ATTRIBUTE14      => r_BVR1.INFORMATION124
6759              ,P_BVR_ATTRIBUTE15      => r_BVR1.INFORMATION125
6760              ,P_BVR_ATTRIBUTE16      => r_BVR1.INFORMATION126
6761              ,P_BVR_ATTRIBUTE17      => r_BVR1.INFORMATION127
6762              ,P_BVR_ATTRIBUTE18      => r_BVR1.INFORMATION128
6763              ,P_BVR_ATTRIBUTE19      => r_BVR1.INFORMATION129
6764              ,P_BVR_ATTRIBUTE2      => r_BVR1.INFORMATION112
6765              ,P_BVR_ATTRIBUTE20      => r_BVR1.INFORMATION130
6766              ,P_BVR_ATTRIBUTE21      => r_BVR1.INFORMATION131
6767              ,P_BVR_ATTRIBUTE22      => r_BVR1.INFORMATION132
6768              ,P_BVR_ATTRIBUTE23      => r_BVR1.INFORMATION133
6769              ,P_BVR_ATTRIBUTE24      => r_BVR1.INFORMATION134
6770              ,P_BVR_ATTRIBUTE25      => r_BVR1.INFORMATION135
6771              ,P_BVR_ATTRIBUTE26      => r_BVR1.INFORMATION136
6772              ,P_BVR_ATTRIBUTE27      => r_BVR1.INFORMATION137
6773              ,P_BVR_ATTRIBUTE28      => r_BVR1.INFORMATION138
6774              ,P_BVR_ATTRIBUTE29      => r_BVR1.INFORMATION139
6775              ,P_BVR_ATTRIBUTE3      => r_BVR1.INFORMATION113
6776              ,P_BVR_ATTRIBUTE30      => r_BVR1.INFORMATION140
6777              ,P_BVR_ATTRIBUTE4      => r_BVR1.INFORMATION114
6778              ,P_BVR_ATTRIBUTE5      => r_BVR1.INFORMATION115
6779              ,P_BVR_ATTRIBUTE6      => r_BVR1.INFORMATION116
6780              ,P_BVR_ATTRIBUTE7      => r_BVR1.INFORMATION117
6781              ,P_BVR_ATTRIBUTE8      => r_BVR1.INFORMATION118
6782              ,P_BVR_ATTRIBUTE9      => r_BVR1.INFORMATION119
6783              ,P_BVR_ATTRIBUTE_CATEGORY      => r_BVR1.INFORMATION110
6784              ,P_CVG_AMT_CALC_MTHD_ID      => l_CVG_AMT_CALC_MTHD_ID
6785              ,P_ORDR_NUM      => r_BVR1.INFORMATION260
6786              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
6787              --
6788              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
6789              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
6790              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
6791            );
6792            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
6793            -- Update all relevent cer records with new pk_id
6794            hr_utility.set_location('Before plsql table ',222);
6795            hr_utility.set_location('new_value id '||l_bnft_vrbl_rt_id,222);
6796            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'BNFT_VRBL_RT_ID' ;
6797            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_BVR1.information1 ;
6798            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_BNFT_VRBL_RT_ID ;
6799            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
6800            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_BVR1_unique.table_route_id;
6801            hr_utility.set_location('After plsql table ',222);
6802            --
6803            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
6804            --
6805            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
6806            --
6807          else
6808            --
6809            -- Call Update routine for the pk_id created in prev run .
6810            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
6811            hr_utility.set_location(' BEN_BNFT_VRBL_RT_F UPDATE_BNFT_VRBL_RT ',30);
6812            --UPD START
6813            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
6814            --
6815            if l_update then
6816              --
6817              l_datetrack_mode := r_BVR1.datetrack_mode ;
6818              --
6819              get_dt_modes(
6820                p_effective_date        => l_process_date,
6821                p_effective_end_date    => r_BVR1.information3,
6822                p_effective_start_date  => r_BVR1.information2,
6823                p_dml_operation         => r_BVR1.dml_operation,
6824                p_datetrack_mode        => l_datetrack_mode );
6825            --    p_update                => l_update
6826              --
6827              l_effective_date := l_process_date;
6828              l_bnft_vrbl_rt_id   := r_BVR1.information1;
6829              l_object_version_number := r_BVR1.information265;
6830              --
6831            end if;
6832            --
6833            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
6834            --
6835            IF l_update OR l_dml_operation <> 'UPDATE' THEN
6836            --UPD END
6837 
6838                    BEN_BNFT_VRBL_RT_API.UPDATE_BNFT_VRBL_RT(
6839                      --
6840                      P_VALIDATE               => false
6841                      ,P_EFFECTIVE_DATE        => l_effective_date
6842                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
6843                      --
6844                      ,P_BNFT_VRBL_RT_ID      => l_bnft_vrbl_rt_id
6845                      ,P_BVR_ATTRIBUTE1      => r_BVR1.INFORMATION111
6846                      ,P_BVR_ATTRIBUTE10      => r_BVR1.INFORMATION120
6847                      ,P_BVR_ATTRIBUTE11      => r_BVR1.INFORMATION121
6848                      ,P_BVR_ATTRIBUTE12      => r_BVR1.INFORMATION122
6849                      ,P_BVR_ATTRIBUTE13      => r_BVR1.INFORMATION123
6850                      ,P_BVR_ATTRIBUTE14      => r_BVR1.INFORMATION124
6851                      ,P_BVR_ATTRIBUTE15      => r_BVR1.INFORMATION125
6852                      ,P_BVR_ATTRIBUTE16      => r_BVR1.INFORMATION126
6853                      ,P_BVR_ATTRIBUTE17      => r_BVR1.INFORMATION127
6854                      ,P_BVR_ATTRIBUTE18      => r_BVR1.INFORMATION128
6855                      ,P_BVR_ATTRIBUTE19      => r_BVR1.INFORMATION129
6856                      ,P_BVR_ATTRIBUTE2      => r_BVR1.INFORMATION112
6857                      ,P_BVR_ATTRIBUTE20      => r_BVR1.INFORMATION130
6858                      ,P_BVR_ATTRIBUTE21      => r_BVR1.INFORMATION131
6859                      ,P_BVR_ATTRIBUTE22      => r_BVR1.INFORMATION132
6860                      ,P_BVR_ATTRIBUTE23      => r_BVR1.INFORMATION133
6861                      ,P_BVR_ATTRIBUTE24      => r_BVR1.INFORMATION134
6862                      ,P_BVR_ATTRIBUTE25      => r_BVR1.INFORMATION135
6863                      ,P_BVR_ATTRIBUTE26      => r_BVR1.INFORMATION136
6864                      ,P_BVR_ATTRIBUTE27      => r_BVR1.INFORMATION137
6865                      ,P_BVR_ATTRIBUTE28      => r_BVR1.INFORMATION138
6866                      ,P_BVR_ATTRIBUTE29      => r_BVR1.INFORMATION139
6867                      ,P_BVR_ATTRIBUTE3      => r_BVR1.INFORMATION113
6868                      ,P_BVR_ATTRIBUTE30      => r_BVR1.INFORMATION140
6869                      ,P_BVR_ATTRIBUTE4      => r_BVR1.INFORMATION114
6870                      ,P_BVR_ATTRIBUTE5      => r_BVR1.INFORMATION115
6871                      ,P_BVR_ATTRIBUTE6      => r_BVR1.INFORMATION116
6872                      ,P_BVR_ATTRIBUTE7      => r_BVR1.INFORMATION117
6873                      ,P_BVR_ATTRIBUTE8      => r_BVR1.INFORMATION118
6874                      ,P_BVR_ATTRIBUTE9      => r_BVR1.INFORMATION119
6875                      ,P_BVR_ATTRIBUTE_CATEGORY      => r_BVR1.INFORMATION110
6876                      ,P_CVG_AMT_CALC_MTHD_ID      => l_CVG_AMT_CALC_MTHD_ID
6877                      ,P_ORDR_NUM      => r_BVR1.INFORMATION260
6878                      ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
6879                      --
6880                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
6881                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
6882                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
6883                      --,P_DATETRACK_MODE        => hr_api.g_update
6884                      ,P_DATETRACK_MODE        => l_datetrack_mode
6885                    );
6886            end if;  -- l_update
6887          end if;
6888          --
6889          --
6890          -- Delete the row if it is end dated.
6891          --
6892          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
6893              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
6894            trunc(l_max_eed) = r_BVR1.information3) then
6895              --
6896              BEN_BNFT_VRBL_RT_API.delete_BNFT_VRBL_RT(
6897                 --
6898                 p_validate                       => false
6899                 ,p_bnft_vrbl_rt_id                   => l_bnft_vrbl_rt_id
6900                 ,p_effective_start_date           => l_effective_start_date
6901                 ,p_effective_end_date             => l_effective_end_date
6902                 ,p_object_version_number          => l_object_version_number
6903                 ,p_effective_date                 => l_max_eed
6904                 ,p_datetrack_mode                 => hr_api.g_delete
6905                 --
6906                 );
6907                 --
6908          end if;
6909          --
6910          l_prev_pk_id := l_current_pk_id ;
6911          --
6912        end if;
6913        --
6914      end if;
6915      --
6916    end loop;
6917    --
6918  exception when others then
6919      --
6920      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'BVR1',r_BVR1.information5 ) ;
6921      --
6922  end create_BVR1_rows;
6923 
6924    --
6925    ---------------------------------------------------------------
6926    ----------------------< create_BRR_rows >-----------------------
6927    ---------------------------------------------------------------
6928    --
6929    procedure create_BRR_rows
6930    (
6931          p_validate                       in  number     default 0
6932         ,p_copy_entity_txn_id             in  number
6933         ,p_effective_date                 in  date
6934         ,p_prefix_suffix_text             in  varchar2  default null
6935         ,p_reuse_object_flag              in  varchar2  default null
6936         ,p_target_business_group_id       in  varchar2  default null
6937         ,p_prefix_suffix_cd               in  varchar2  default null
6938    ) is
6939    --
6940    l_CVG_AMT_CALC_MTHD_ID  number;
6941    l_FORMULA_ID  number;
6942    cursor c_unique_BRR(l_table_alias varchar2) is
6943    select distinct cpe.information1,
6944      cpe.information2,
6945      cpe.information3,
6946      cpe.table_route_id,
6947      cpe.dml_operation,
6948      cpe.datetrack_mode
6949    from ben_copy_entity_results cpe,
6950         pqh_table_route tr
6951    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
6952    and   cpe.table_route_id     = tr.table_route_id
6953    -- and   tr.where_clause        = l_BEN_BNFT_VRBL_RT_RL_F
6954    and   tr.table_alias = l_table_alias
6955    and   cpe.number_of_copies   = 1 -- ADDITION
6956    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
6957    order by information1, information2; --added for bug: 5151945
6958    --
6959    --
6960    cursor c_BRR_min_max_dates(c_table_route_id  number,
6961                 c_information1   number) is
6962    select
6963      min(cpe.information2) min_esd,
6964      max(cpe.information3) min_eed
6965    from ben_copy_entity_results cpe
6966    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
6967    and   cpe.table_route_id     = c_table_route_id
6968    and   cpe.information1       = c_information1 ;
6969    --
6970    cursor c_BRR(c_table_route_id  number,
6971                 c_information1   number,
6972                 c_information2   date,
6973                 c_information3   date)  is
6974    select
6975      cpe.*
6976    from ben_copy_entity_results cpe
6977    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
6978    and   cpe.table_route_id     = c_table_route_id
6979    and   cpe.information1       = c_information1
6980    and   cpe.information2       = c_information2
6981    and   cpe.information3       = c_information3
6982    and rownum = 1 ;
6983    -- Date Track target record
6984    cursor c_find_BRR_in_target(
6985                                 c_effective_start_date    date,
6986                                 c_effective_end_date      date,
6987                                 c_business_group_id       number,
6988                                 c_new_pk_id               number) is
6989    select
6990      BRR.bnft_vrbl_rt_rl_id new_value
6991    from BEN_BNFT_VRBL_RT_RL_F BRR
6992    where
6993    BRR.CVG_AMT_CALC_MTHD_ID     = l_CVG_AMT_CALC_MTHD_ID  and
6994    BRR.FORMULA_ID     = l_FORMULA_ID  and
6995    BRR.business_group_id  = c_business_group_id
6996    and   BRR.bnft_vrbl_rt_rl_id  <> c_new_pk_id
6997 --TEMPIK
6998    and c_effective_start_date between effective_start_date
6999                             and effective_end_date ;
7000 --END TEMPIK
7001 /*TEMPIK
7002    and exists ( select null
7003                 from BEN_BNFT_VRBL_RT_RL_F BRR1
7004                 where
7005                 BRR1.CVG_AMT_CALC_MTHD_ID     = l_CVG_AMT_CALC_MTHD_ID  and
7006                 BRR1.FORMULA_ID     = l_FORMULA_ID  and
7007                 BRR1.business_group_id  = c_business_group_id
7008                 and   BRR1.effective_start_date <= c_effective_start_date )
7009    and exists ( select null
7010                 from BEN_BNFT_VRBL_RT_RL_F BRR2
7011                 where
7012                 BRR2.CVG_AMT_CALC_MTHD_ID     = l_CVG_AMT_CALC_MTHD_ID  and
7013                 BRR2.FORMULA_ID     = l_FORMULA_ID  and
7014                 BRR2.business_group_id  = c_business_group_id
7015                 and   BRR2.effective_end_date >= c_effective_end_date )
7016                 ;
7017 TEMPIK */
7018    --TEMPIK
7019    l_dt_rec_found            boolean ;
7020    --END TEMPIK
7021 
7022    --UPD START
7023    --
7024    l_update                  boolean      := false ;
7025    l_datetrack_mode          varchar2(80) := hr_api.g_update;
7026    l_process_date            date;
7027    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
7028    --
7029    --UPD END
7030 
7031    --
7032    l_current_pk_id           number := null ;
7033    l_prev_pk_id              number := null ;
7034    l_first_rec               boolean := true ;
7035    r_BRR                     c_BRR%rowtype;
7036    l_bnft_vrbl_rt_rl_id             number ;
7037    l_object_version_number   number ;
7038    l_effective_start_date    date ;
7039    l_effective_end_date      date ;
7040    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
7041    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
7042    l_new_value               number(15);
7043    l_object_found_in_target  boolean := false ;
7044    l_min_esd                 date;
7045    l_max_eed                 date;
7046    l_effective_date          date;
7047    --
7048  begin
7049    -- Initialization
7050    l_object_found_in_target := false ;
7051    -- End Initialization
7052    -- Derive the prefix - sufix
7053    if   p_prefix_suffix_cd = 'PREFIX' then
7054      l_prefix  := p_prefix_suffix_text ;
7055    elsif p_prefix_suffix_cd = 'SUFFIX' then
7056      l_suffix   := p_prefix_suffix_text ;
7057    else
7058      l_prefix := null ;
7059      l_suffix  := null ;
7060    end if ;
7061    -- End Prefix Sufix derivation
7062    for r_BRR_unique in c_unique_BRR('BRR') loop
7063 
7064      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
7065         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
7066          r_BRR_unique.information3 >=
7067                  ben_pd_copy_to_ben_one.g_copy_effective_date)
7068         ) then
7069        --
7070        hr_utility.set_location(' r_BRR_unique.table_route_id '||r_BRR_unique.table_route_id,10);
7071        hr_utility.set_location(' r_BRR_unique.information1 '||r_BRR_unique.information1,10);
7072        hr_utility.set_location( 'r_BRR_unique.information2 '||r_BRR_unique.information2,10);
7073        hr_utility.set_location( 'r_BRR_unique.information3 '||r_BRR_unique.information3,10);
7074        -- If reuse objects flag is 'Y' then check for the object in the target business group
7075        -- if found insert the record into PLSql table and exit the loop else try create the
7076        -- object in the target business group
7077        --
7078        l_object_found_in_target := false ;
7079        --UPD START
7080        l_update := false;
7081        l_process_date := p_effective_date;
7082        l_dml_operation:= r_BRR_unique.dml_operation ;
7083        --
7084        open c_BRR(r_BRR_unique.table_route_id,
7085                 r_BRR_unique.information1,
7086                 r_BRR_unique.information2,
7087                 r_BRR_unique.information3 ) ;
7088        --
7089        fetch c_BRR into r_BRR ;
7090        --
7091        close c_BRR ;
7092        --
7093        l_CVG_AMT_CALC_MTHD_ID := get_fk('CVG_AMT_CALC_MTHD_ID', r_BRR.information238,r_BRR.dml_operation);
7094        l_FORMULA_ID := get_fk('FORMULA_ID', r_BRR.information251,r_BRR.dml_operation);
7095        --
7096        if l_dml_operation = 'UPDATE' then
7097          --
7098                  l_object_found_in_target := TRUE;
7099                  --
7100                  if l_process_date between r_BRR_unique.information2 and r_BRR_unique.information3 then
7101                        l_update := true;
7102                        if r_BRR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
7103                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'BNFT_VRBL_RT_RL_ID'
7104                        then
7105                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'BNFT_VRBL_RT_RL_ID' ;
7106                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_BRR_unique.information1 ;
7107                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_BRR_unique.information1 ;
7108                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
7109                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_BRR_unique.table_route_id;
7110                           --
7111                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
7112                           --
7113                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
7114                           --
7115                           --BEN_PD_COPY_TO_BEN_ONE.log_data('BRR',l_new_value,l_prefix || r_BRR_unique.name|| l_suffix,'REUSED');
7116                           --
7117                        end if ;
7118                        hr_utility.set_location( 'found record for update',10);
7119                    --
7120                  else
7121                    --
7122                    l_update := false;
7123                    --
7124                  end if;
7125        else
7126        --
7127        --UPD END
7128 
7129        l_min_esd := null ;
7130        l_max_eed := null ;
7131        open c_BRR_min_max_dates(r_BRR_unique.table_route_id, r_BRR_unique.information1 ) ;
7132        fetch c_BRR_min_max_dates into l_min_esd,l_max_eed ;
7133        --
7134 
7135        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
7136             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
7137          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
7138        end if;
7139        l_min_esd := greatest(l_min_esd,r_BRR_unique.information2);
7140 
7141        if p_reuse_object_flag = 'Y' then
7142          if c_BRR_min_max_dates%found then
7143            -- cursor to find the object
7144            open c_find_BRR_in_target( l_min_esd,l_max_eed,
7145                                  p_target_business_group_id, nvl(l_bnft_vrbl_rt_rl_id, -999)  ) ;
7146            fetch c_find_BRR_in_target into l_new_value ;
7147            if c_find_BRR_in_target%found then
7148              --TEMPIK
7149              l_dt_rec_found :=   dt_api.check_min_max_dates
7150                  (p_base_table_name => 'BEN_BNFT_VRBL_RT_RL_F',
7151                   p_base_key_column => 'BNFT_VRBL_RT_RL_ID',
7152                   p_base_key_value  => l_new_value,
7153                   p_from_date       => l_min_esd,
7154                   p_to_date         => l_max_eed );
7155              if l_dt_rec_found THEN
7156              --END TEMPIK
7157              --
7158                                  if r_BRR_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
7159                                         nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'BNFT_VRBL_RT_RL_ID'  then
7160                                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'BNFT_VRBL_RT_RL_ID' ;
7161                                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_BRR_unique.information1 ;
7162                                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
7163                                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
7164                                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_BRR_unique.table_route_id;
7165                                         --
7166                                         -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
7167                                         --
7168                                         ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
7169                                  end if ;
7170                                  --
7171                                  l_object_found_in_target := true ;
7172              --TEMPIK
7173              end if; -- l_dt_rec_found
7174              --END TEMPIK
7175                    end if;
7176            close c_find_BRR_in_target ;
7177          --
7178          end if;
7179        end if ;
7180        --
7181        close c_BRR_min_max_dates ;
7182        -- UPD START
7183        end if; --if p_dml_operation
7184        --
7185        if not l_object_found_in_target OR l_update  then
7186        --if not l_object_found_in_target then
7187        -- UPD END
7188          --
7189          l_current_pk_id := r_BRR.information1;
7190          --
7191          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
7192          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
7193          --
7194          if l_current_pk_id =  l_prev_pk_id  then
7195            --
7196            l_first_rec := false ;
7197            --
7198          else
7199            --
7200            l_first_rec := true ;
7201            --
7202          end if ;
7203          --
7204 
7205          l_effective_date := r_BRR.information2;
7206          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
7207               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
7208            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
7209          end if;
7210 
7211          -- UPD START
7212          --if l_first_rec then
7213          if l_first_rec and not l_update then
7214            -- Call Create routine.
7215            hr_utility.set_location(' BEN_BNFT_VRBL_RT_RL_F CREATE_BNFT_VRBL_RT_RL ',20);
7216            BEN_BNFT_VRBL_RT_RL_API.CREATE_BNFT_VRBL_RT_RL(
7217              --
7218              P_VALIDATE               => false
7219              ,P_EFFECTIVE_DATE        => l_effective_date
7220              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
7221              --
7222              ,P_BNFT_VRBL_RT_RL_ID      => l_bnft_vrbl_rt_rl_id
7223              ,P_BRR_ATTRIBUTE1      => r_BRR.INFORMATION111
7224              ,P_BRR_ATTRIBUTE10      => r_BRR.INFORMATION120
7225              ,P_BRR_ATTRIBUTE11      => r_BRR.INFORMATION121
7226              ,P_BRR_ATTRIBUTE12      => r_BRR.INFORMATION122
7227              ,P_BRR_ATTRIBUTE13      => r_BRR.INFORMATION123
7228              ,P_BRR_ATTRIBUTE14      => r_BRR.INFORMATION124
7229              ,P_BRR_ATTRIBUTE15      => r_BRR.INFORMATION125
7230              ,P_BRR_ATTRIBUTE16      => r_BRR.INFORMATION126
7231              ,P_BRR_ATTRIBUTE17      => r_BRR.INFORMATION127
7232              ,P_BRR_ATTRIBUTE18      => r_BRR.INFORMATION128
7233              ,P_BRR_ATTRIBUTE19      => r_BRR.INFORMATION129
7234              ,P_BRR_ATTRIBUTE2      => r_BRR.INFORMATION112
7235              ,P_BRR_ATTRIBUTE20      => r_BRR.INFORMATION130
7236              ,P_BRR_ATTRIBUTE21      => r_BRR.INFORMATION131
7237              ,P_BRR_ATTRIBUTE22      => r_BRR.INFORMATION132
7238              ,P_BRR_ATTRIBUTE23      => r_BRR.INFORMATION133
7239              ,P_BRR_ATTRIBUTE24      => r_BRR.INFORMATION134
7240              ,P_BRR_ATTRIBUTE25      => r_BRR.INFORMATION135
7241              ,P_BRR_ATTRIBUTE26      => r_BRR.INFORMATION136
7242              ,P_BRR_ATTRIBUTE27      => r_BRR.INFORMATION137
7243              ,P_BRR_ATTRIBUTE28      => r_BRR.INFORMATION138
7244              ,P_BRR_ATTRIBUTE29      => r_BRR.INFORMATION139
7245              ,P_BRR_ATTRIBUTE3      => r_BRR.INFORMATION113
7246              ,P_BRR_ATTRIBUTE30      => r_BRR.INFORMATION140
7247              ,P_BRR_ATTRIBUTE4      => r_BRR.INFORMATION114
7248              ,P_BRR_ATTRIBUTE5      => r_BRR.INFORMATION115
7249              ,P_BRR_ATTRIBUTE6      => r_BRR.INFORMATION116
7250              ,P_BRR_ATTRIBUTE7      => r_BRR.INFORMATION117
7251              ,P_BRR_ATTRIBUTE8      => r_BRR.INFORMATION118
7252              ,P_BRR_ATTRIBUTE9      => r_BRR.INFORMATION119
7253              ,P_BRR_ATTRIBUTE_CATEGORY      => r_BRR.INFORMATION110
7254              ,P_CVG_AMT_CALC_MTHD_ID      => l_CVG_AMT_CALC_MTHD_ID
7255              ,P_FORMULA_ID      => l_FORMULA_ID
7256              ,P_ORDR_TO_APLY_NUM      => r_BRR.INFORMATION260
7257              --
7258              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
7259              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
7260              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
7261            );
7262            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
7263            -- Update all relevent cer records with new pk_id
7264            hr_utility.set_location('Before plsql table ',222);
7265            hr_utility.set_location('new_value id '||l_bnft_vrbl_rt_rl_id,222);
7266            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'BNFT_VRBL_RT_RL_ID' ;
7267            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_BRR.information1 ;
7268            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_BNFT_VRBL_RT_RL_ID ;
7269            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
7270            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_BRR_unique.table_route_id;
7271            hr_utility.set_location('After plsql table ',222);
7272            --
7273            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
7274            --
7275            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
7276            --
7277          else
7278            --
7279            -- Call Update routine for the pk_id created in prev run .
7280            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
7281            hr_utility.set_location(' BEN_BNFT_VRBL_RT_RL_F UPDATE_BNFT_VRBL_RT_RL ',30);
7282            --UPD START
7283            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
7284            --
7285            if l_update then
7286              --
7287              l_datetrack_mode := r_brr.datetrack_mode ;
7288              --
7289              get_dt_modes(
7290                p_effective_date        => l_process_date,
7291                p_effective_end_date    => r_brr.information3,
7292                p_effective_start_date  => r_brr.information2,
7293                p_dml_operation         => r_brr.dml_operation,
7294                p_datetrack_mode        => l_datetrack_mode );
7295            --    p_update                => l_update
7296              --
7297              l_effective_date := l_process_date;
7298              l_bnft_vrbl_rt_rl_id   := r_brr.information1;
7299              l_object_version_number := r_brr.information265;
7300              --
7301            end if;
7302            --
7303            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
7304            --
7305            IF l_update OR l_dml_operation <> 'UPDATE' THEN
7306            --UPD END
7307 
7308            BEN_BNFT_VRBL_RT_RL_API.UPDATE_BNFT_VRBL_RT_RL(
7309              --
7310              P_VALIDATE               => false
7311              ,P_EFFECTIVE_DATE        => l_effective_date
7312              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
7313              --
7314              ,P_BNFT_VRBL_RT_RL_ID      => l_bnft_vrbl_rt_rl_id
7315              ,P_BRR_ATTRIBUTE1      => r_BRR.INFORMATION111
7316              ,P_BRR_ATTRIBUTE10      => r_BRR.INFORMATION120
7317              ,P_BRR_ATTRIBUTE11      => r_BRR.INFORMATION121
7318              ,P_BRR_ATTRIBUTE12      => r_BRR.INFORMATION122
7319              ,P_BRR_ATTRIBUTE13      => r_BRR.INFORMATION123
7320              ,P_BRR_ATTRIBUTE14      => r_BRR.INFORMATION124
7321              ,P_BRR_ATTRIBUTE15      => r_BRR.INFORMATION125
7322              ,P_BRR_ATTRIBUTE16      => r_BRR.INFORMATION126
7323              ,P_BRR_ATTRIBUTE17      => r_BRR.INFORMATION127
7324              ,P_BRR_ATTRIBUTE18      => r_BRR.INFORMATION128
7325              ,P_BRR_ATTRIBUTE19      => r_BRR.INFORMATION129
7326              ,P_BRR_ATTRIBUTE2      => r_BRR.INFORMATION112
7327              ,P_BRR_ATTRIBUTE20      => r_BRR.INFORMATION130
7328              ,P_BRR_ATTRIBUTE21      => r_BRR.INFORMATION131
7329              ,P_BRR_ATTRIBUTE22      => r_BRR.INFORMATION132
7330              ,P_BRR_ATTRIBUTE23      => r_BRR.INFORMATION133
7331              ,P_BRR_ATTRIBUTE24      => r_BRR.INFORMATION134
7332              ,P_BRR_ATTRIBUTE25      => r_BRR.INFORMATION135
7333              ,P_BRR_ATTRIBUTE26      => r_BRR.INFORMATION136
7334              ,P_BRR_ATTRIBUTE27      => r_BRR.INFORMATION137
7335              ,P_BRR_ATTRIBUTE28      => r_BRR.INFORMATION138
7336              ,P_BRR_ATTRIBUTE29      => r_BRR.INFORMATION139
7337              ,P_BRR_ATTRIBUTE3      => r_BRR.INFORMATION113
7338              ,P_BRR_ATTRIBUTE30      => r_BRR.INFORMATION140
7339              ,P_BRR_ATTRIBUTE4      => r_BRR.INFORMATION114
7340              ,P_BRR_ATTRIBUTE5      => r_BRR.INFORMATION115
7341              ,P_BRR_ATTRIBUTE6      => r_BRR.INFORMATION116
7342              ,P_BRR_ATTRIBUTE7      => r_BRR.INFORMATION117
7343              ,P_BRR_ATTRIBUTE8      => r_BRR.INFORMATION118
7344              ,P_BRR_ATTRIBUTE9      => r_BRR.INFORMATION119
7345              ,P_BRR_ATTRIBUTE_CATEGORY      => r_BRR.INFORMATION110
7346              ,P_CVG_AMT_CALC_MTHD_ID      => l_CVG_AMT_CALC_MTHD_ID
7347              ,P_FORMULA_ID      => l_FORMULA_ID
7348              ,P_ORDR_TO_APLY_NUM      => r_BRR.INFORMATION260
7349              --
7350              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
7351              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
7352              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
7353              --,P_DATETRACK_MODE        => hr_api.g_update
7354              ,P_DATETRACK_MODE        => l_datetrack_mode
7355            );
7356           end if;  -- l_update
7357          end if;
7358          --
7359          --
7360          -- Delete the row if it is end dated.
7361          --
7362          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
7363              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
7364              trunc(l_max_eed) = r_BRR.information3) then
7365              --
7366              BEN_BNFT_VRBL_RT_RL_API.delete_BNFT_VRBL_RT_RL(
7367                 --
7368                 p_validate                       => false
7369                 ,p_bnft_vrbl_rt_rl_id                   => l_bnft_vrbl_rt_rl_id
7370                 ,p_effective_start_date           => l_effective_start_date
7371                 ,p_effective_end_date             => l_effective_end_date
7372                 ,p_object_version_number          => l_object_version_number
7373                 ,p_effective_date                 => l_max_eed
7374                 ,p_datetrack_mode                 => hr_api.g_delete
7375                 --
7376                 );
7377                 --
7378          end if;
7379          --
7380          l_prev_pk_id := l_current_pk_id ;
7381          --
7382        end if;
7383        --
7384      end if;
7385      --
7386    end loop;
7387    --
7388  exception when others then
7389      --
7390      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'BRR',r_BRR.information5 ) ;
7391      --
7392  end create_BRR_rows;
7393 
7394    --
7395    ---------------------------------------------------------------
7396    ----------------------< create_APV_rows >-----------------------
7397    ---------------------------------------------------------------
7398    --
7399    procedure create_APV_rows
7400    (
7401          p_validate                       in  number     default 0
7402         ,p_copy_entity_txn_id             in  number
7403         ,p_effective_date                 in  date
7404         ,p_prefix_suffix_text             in  varchar2  default null
7405         ,p_reuse_object_flag              in  varchar2  default null
7406         ,p_target_business_group_id       in  varchar2  default null
7407         ,p_prefix_suffix_cd               in  varchar2  default null
7408    ) is
7409    --
7410    l_ACTL_PREM_ID  number;
7411    l_VRBL_RT_PRFL_ID  number;
7412    cursor c_unique_APV(l_table_alias varchar2) is
7413    select distinct cpe.information1,
7414      cpe.information2,
7415      cpe.information3,
7416      cpe.table_route_id,
7417      cpe.dml_operation,
7418      cpe.datetrack_mode
7419    from ben_copy_entity_results cpe,
7420         pqh_table_route tr
7421    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
7422    and   cpe.table_route_id     = tr.table_route_id
7423    -- and   tr.where_clause        = l_BEN_ACTL_PREM_VRBL_RT_F
7424    and   tr.table_alias = l_table_alias
7425    and   cpe.number_of_copies   = 1 -- ADDITION
7426    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id ,cpe.dml_operation,cpe.datetrack_mode
7427    order by information1, information2; --added for bug: 5151945
7428    --
7429    --
7430    cursor c_APV_min_max_dates(c_table_route_id  number,
7431                 c_information1   number) is
7432    select
7433      min(cpe.information2) min_esd,
7434      max(cpe.information3) min_eed
7435    from ben_copy_entity_results cpe
7436    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
7437    and   cpe.table_route_id     = c_table_route_id
7438    and   cpe.information1       = c_information1 ;
7439    --
7440    cursor c_APV(c_table_route_id  number,
7441                 c_information1   number,
7442                 c_information2   date,
7443                 c_information3   date)  is
7444    select
7445      cpe.*
7446    from ben_copy_entity_results cpe
7447    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
7448    and   cpe.table_route_id     = c_table_route_id
7449    and   cpe.information1       = c_information1
7450    and   cpe.information2       = c_information2
7451    and   cpe.information3       = c_information3
7452    and rownum = 1 ;
7453    -- Date Track target record
7454    cursor c_find_APV_in_target(
7455                                 c_effective_start_date    date,
7456                                 c_effective_end_date      date,
7457                                 c_business_group_id       number,
7458                                 c_new_pk_id               number) is
7459    select
7460      APV.actl_prem_vrbl_rt_id new_value
7461    from BEN_ACTL_PREM_VRBL_RT_F APV
7462    where
7463    APV.ACTL_PREM_ID     = l_ACTL_PREM_ID  and
7464    APV.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
7465    APV.business_group_id  = c_business_group_id
7466    and   APV.actl_prem_vrbl_rt_id  <> c_new_pk_id
7467 --TEMPIK
7468    and c_effective_start_date between effective_start_date
7469                             and effective_end_date ;
7470 --END TEMPIK
7471 /*TEMPIK
7472    and exists ( select null
7473                 from BEN_ACTL_PREM_VRBL_RT_F APV1
7474                 where
7475                 APV1.ACTL_PREM_ID     = l_ACTL_PREM_ID  and
7476                 APV1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
7477                 APV1.business_group_id  = c_business_group_id
7478                 and   APV1.effective_start_date <= c_effective_start_date )
7479    and exists ( select null
7480                 from BEN_ACTL_PREM_VRBL_RT_F APV2
7481                 where
7482                 APV2.ACTL_PREM_ID     = l_ACTL_PREM_ID  and
7483                 APV2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
7484                 APV2.business_group_id  = c_business_group_id
7485                 and   APV2.effective_end_date >= c_effective_end_date )
7486                 ;
7487 TEMPIK */
7488    --TEMPIK
7489    l_dt_rec_found            boolean ;
7490    --END TEMPIK
7491    --
7492    --
7493    --UPD START
7494    --
7495    l_update                  boolean      := false ;
7496    l_datetrack_mode          varchar2(80) := hr_api.g_update;
7497    l_process_date            date;
7498    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
7499    --
7500    --UPD END
7501 
7502    l_current_pk_id           number := null ;
7503    l_prev_pk_id              number := null ;
7504    l_first_rec               boolean := true ;
7505    r_APV                     c_APV%rowtype;
7506    l_actl_prem_vrbl_rt_id             number ;
7507    l_object_version_number   number ;
7508    l_effective_start_date    date ;
7509    l_effective_end_date      date ;
7510    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
7511    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
7512    l_new_value               number(15);
7513    l_object_found_in_target  boolean := false ;
7514    l_min_esd                 date;
7515    l_max_eed                 date;
7516    l_effective_date          date;
7517    --
7518  begin
7519    -- Initialization
7520    l_object_found_in_target := false ;
7521    -- End Initialization
7522    -- Derive the prefix - sufix
7523    if   p_prefix_suffix_cd = 'PREFIX' then
7524      l_prefix  := p_prefix_suffix_text ;
7525    elsif p_prefix_suffix_cd = 'SUFFIX' then
7526      l_suffix   := p_prefix_suffix_text ;
7527    else
7528      l_prefix := null ;
7529      l_suffix  := null ;
7530    end if ;
7531    -- End Prefix Sufix derivation
7532    for r_APV_unique in c_unique_APV('APV') loop
7533 
7534      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
7535         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
7536          r_APV_unique.information3 >=
7537                  ben_pd_copy_to_ben_one.g_copy_effective_date)
7538         ) then
7539        --
7540        hr_utility.set_location(' r_APV_unique.table_route_id '||r_APV_unique.table_route_id,10);
7541        hr_utility.set_location(' r_APV_unique.information1 '||r_APV_unique.information1,10);
7542        hr_utility.set_location( 'r_APV_unique.information2 '||r_APV_unique.information2,10);
7543        hr_utility.set_location( 'r_APV_unique.information3 '||r_APV_unique.information3,10);
7544        -- If reuse objects flag is 'Y' then check for the object in the target business group
7545        -- if found insert the record into PLSql table and exit the loop else try create the
7546        -- object in the target business group
7547        --
7548        l_object_found_in_target := false ;
7549        --UPD START
7550        l_update := false;
7551        l_process_date := p_effective_date;
7552        l_dml_operation:= r_APV_unique.dml_operation ;
7553        --
7554        open c_APV(r_APV_unique.table_route_id,
7555                 r_APV_unique.information1,
7556                 r_APV_unique.information2,
7557                 r_APV_unique.information3 ) ;
7558         --
7559         fetch c_APV into r_APV ;
7560         --
7561         close c_APV ;
7562         --
7563         l_ACTL_PREM_ID := get_fk('ACTL_PREM_ID', r_APV.information250,r_APV.dml_operation);
7564         l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_APV.information262,r_APV.dml_operation);
7565        --
7566        if l_dml_operation = 'UPDATE' then
7567          --
7568                  l_object_found_in_target := TRUE;
7569                  --
7570                  if l_process_date between r_APV_unique.information2 and r_APV_unique.information3 then
7571                        l_update := true;
7572                        if r_APV_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
7573                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ACTL_PREM_VRBL_RT_ID'
7574                        then
7575                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ACTL_PREM_VRBL_RT_ID' ;
7576                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_APV_unique.information1 ;
7577                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_APV_unique.information1 ;
7578                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
7579                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_APV_unique.table_route_id;
7580                           --
7581                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
7582                           --
7583                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
7584                           --
7585                           --BEN_PD_COPY_TO_BEN_ONE.log_data('APV',l_new_value,l_prefix || r_APV_unique.name|| l_suffix,'REUSED');
7586                           --
7587                        end if ;
7588                        hr_utility.set_location( 'found record for update',10);
7589                    --
7590                  else
7591                    --
7592                    l_update := false;
7593            --
7594          end if;
7595        else
7596        --
7597        --UPD END
7598                l_min_esd := null ;
7599                l_max_eed := null ;
7600                open c_APV_min_max_dates(r_APV_unique.table_route_id, r_APV_unique.information1 ) ;
7601                fetch c_APV_min_max_dates into l_min_esd,l_max_eed ;
7602                --
7603 
7604                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
7605                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
7606                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
7607                end if;
7608                l_min_esd := greatest(l_min_esd,r_APV_unique.information2);
7609                if p_reuse_object_flag = 'Y' then
7610                  if c_APV_min_max_dates%found then
7611                    -- cursor to find the object
7612                    open c_find_APV_in_target( l_min_esd,l_max_eed,
7613                                          p_target_business_group_id, nvl(l_actl_prem_vrbl_rt_id, -999)  ) ;
7614                    fetch c_find_APV_in_target into l_new_value ;
7615                    if c_find_APV_in_target%found then
7616                      --TEMPIK
7617                      l_dt_rec_found :=   dt_api.check_min_max_dates
7618                          (p_base_table_name => 'BEN_ACTL_PREM_VRBL_RT_F',
7619                           p_base_key_column => 'ACTL_PREM_VRBL_RT_ID',
7620                           p_base_key_value  => l_new_value,
7621                           p_from_date       => l_min_esd,
7622                           p_to_date         => l_max_eed );
7623                      if l_dt_rec_found THEN
7624                      --END TEMPIK             --
7625                                          if r_APV_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
7626                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'ACTL_PREM_VRBL_RT_ID'  then
7627                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'ACTL_PREM_VRBL_RT_ID' ;
7628                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_APV_unique.information1 ;
7629                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
7630                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
7631                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_APV_unique.table_route_id;
7632                                                 --
7633                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
7634                                                 --
7635                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
7636                                          end if ;
7637                                          --
7638                                          l_object_found_in_target := true ;
7639                      --TEMPIK
7640                      end if; -- l_dt_rec_found
7641                      --END TEMPIK
7642                    end if;
7643                    close c_find_APV_in_target ;
7644                  --
7645                  end if;
7646                end if ;
7647                --
7648                close c_APV_min_max_dates ;
7649        -- UPD START
7650        --if not l_object_found_in_target then
7651        end if; --if p_dml_operation
7652        --
7653        if not l_object_found_in_target OR l_update  then
7654        -- UPD END
7655          --
7656          l_current_pk_id := r_APV.information1;
7657          --
7658          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
7659          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
7660          --
7661          if l_current_pk_id =  l_prev_pk_id  then
7662            --
7663            l_first_rec := false ;
7664            --
7665          else
7666            --
7667            l_first_rec := true ;
7668            --
7669          end if ;
7670          --
7671 
7672          l_effective_date := r_APV.information2;
7673          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
7674               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
7675            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
7676          end if;
7677          -- UPD START
7678          --if l_first_rec then
7679          if l_first_rec and not l_update then
7680          -- UPD END
7681 
7682            -- Call Create routine.
7683            hr_utility.set_location(' BEN_ACTL_PREM_VRBL_RT_F CREATE_ACTUAL_PREMIUM_RATE ',20);
7684            BEN_ACTUAL_PREMIUM_RATE_API.CREATE_ACTUAL_PREMIUM_RATE(
7685              --
7686              P_VALIDATE               => false
7687              ,P_EFFECTIVE_DATE        => l_effective_date
7688              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
7689              --
7690             ,P_ACTL_PREM_ID      => l_ACTL_PREM_ID
7691             ,P_ACTL_PREM_VRBL_RT_ID      => l_actl_prem_vrbl_rt_id
7692             ,P_APV_ATTRIBUTE1      => r_APV.INFORMATION111
7693             ,P_APV_ATTRIBUTE10      => r_APV.INFORMATION120
7694             ,P_APV_ATTRIBUTE11      => r_APV.INFORMATION121
7695             ,P_APV_ATTRIBUTE12      => r_APV.INFORMATION122
7696             ,P_APV_ATTRIBUTE13      => r_APV.INFORMATION123
7697             ,P_APV_ATTRIBUTE14      => r_APV.INFORMATION124
7698             ,P_APV_ATTRIBUTE15      => r_APV.INFORMATION125
7699             ,P_APV_ATTRIBUTE16      => r_APV.INFORMATION126
7700             ,P_APV_ATTRIBUTE17      => r_APV.INFORMATION127
7701             ,P_APV_ATTRIBUTE18      => r_APV.INFORMATION128
7702             ,P_APV_ATTRIBUTE19      => r_APV.INFORMATION129
7703             ,P_APV_ATTRIBUTE2      => r_APV.INFORMATION112
7704             ,P_APV_ATTRIBUTE20      => r_APV.INFORMATION130
7705             ,P_APV_ATTRIBUTE21      => r_APV.INFORMATION131
7706             ,P_APV_ATTRIBUTE22      => r_APV.INFORMATION132
7707             ,P_APV_ATTRIBUTE23      => r_APV.INFORMATION133
7708             ,P_APV_ATTRIBUTE24      => r_APV.INFORMATION134
7709             ,P_APV_ATTRIBUTE25      => r_APV.INFORMATION135
7710             ,P_APV_ATTRIBUTE26      => r_APV.INFORMATION136
7711             ,P_APV_ATTRIBUTE27      => r_APV.INFORMATION137
7712             ,P_APV_ATTRIBUTE28      => r_APV.INFORMATION138
7713             ,P_APV_ATTRIBUTE29      => r_APV.INFORMATION139
7714             ,P_APV_ATTRIBUTE3      => r_APV.INFORMATION113
7715             ,P_APV_ATTRIBUTE30      => r_APV.INFORMATION140
7716             ,P_APV_ATTRIBUTE4      => r_APV.INFORMATION114
7717             ,P_APV_ATTRIBUTE5      => r_APV.INFORMATION115
7718             ,P_APV_ATTRIBUTE6      => r_APV.INFORMATION116
7719             ,P_APV_ATTRIBUTE7      => r_APV.INFORMATION117
7720             ,P_APV_ATTRIBUTE8      => r_APV.INFORMATION118
7721             ,P_APV_ATTRIBUTE9      => r_APV.INFORMATION119
7722             ,P_APV_ATTRIBUTE_CATEGORY      => r_APV.INFORMATION110
7723             ,P_ORDR_NUM      => r_APV.INFORMATION260
7724             ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
7725 
7726              --
7727              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
7728              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
7729              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
7730            );
7731            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
7732            -- Update all relevent cer records with new pk_id
7733            hr_utility.set_location('Before plsql table ',222);
7734            hr_utility.set_location('new_value id '||l_actl_prem_vrbl_rt_id,222);
7735            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'ACTL_PREM_VRBL_RT_ID' ;
7736            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_APV.information1 ;
7737            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_ACTL_PREM_VRBL_RT_ID ;
7738            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
7739            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_APV_unique.table_route_id;
7740            hr_utility.set_location('After plsql table ',222);
7741            --
7742            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
7743            --
7744            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
7745            --
7746          else
7747            --
7748            -- Call Update routine for the pk_id created in prev run .
7749            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
7750            hr_utility.set_location(' BEN_ACTL_PREM_VRBL_RT_F UPDATE_ACTUAL_PREMIUM_RATE ',30);
7751            --UPD START
7752            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
7753            --
7754            if l_update then
7755              --
7756              l_datetrack_mode := r_APV.datetrack_mode ;
7757              --
7758              get_dt_modes(
7759                p_effective_date        => l_process_date,
7760                p_effective_end_date    => r_APV.information3,
7761                p_effective_start_date  => r_APV.information2,
7762                p_dml_operation         => r_APV.dml_operation,
7763                p_datetrack_mode        => l_datetrack_mode );
7764            --    p_update                => l_update
7765              --
7766              l_effective_date := l_process_date;
7767              l_ACTL_PREM_ID   := r_APV.information1;
7768              l_object_version_number := r_APV.information265;
7769              --
7770            end if;
7771            --
7772            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
7773            --
7774            IF l_update OR l_dml_operation <> 'UPDATE' THEN
7775            --UPD END
7776 
7777                    BEN_ACTUAL_PREMIUM_RATE_API.UPDATE_ACTUAL_PREMIUM_RATE(
7778                      --
7779                      P_VALIDATE               => false
7780                      ,P_EFFECTIVE_DATE        => l_effective_date
7781                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
7782                      --
7783                      ,P_ACTL_PREM_ID      => l_ACTL_PREM_ID
7784                      ,P_ACTL_PREM_VRBL_RT_ID      => l_actl_prem_vrbl_rt_id
7785                      ,P_APV_ATTRIBUTE1      => r_APV.INFORMATION111
7786                      ,P_APV_ATTRIBUTE10      => r_APV.INFORMATION120
7787                      ,P_APV_ATTRIBUTE11      => r_APV.INFORMATION121
7788                      ,P_APV_ATTRIBUTE12      => r_APV.INFORMATION122
7789                      ,P_APV_ATTRIBUTE13      => r_APV.INFORMATION123
7790                      ,P_APV_ATTRIBUTE14      => r_APV.INFORMATION124
7791                      ,P_APV_ATTRIBUTE15      => r_APV.INFORMATION125
7792                      ,P_APV_ATTRIBUTE16      => r_APV.INFORMATION126
7793                      ,P_APV_ATTRIBUTE17      => r_APV.INFORMATION127
7794                      ,P_APV_ATTRIBUTE18      => r_APV.INFORMATION128
7795                      ,P_APV_ATTRIBUTE19      => r_APV.INFORMATION129
7796                      ,P_APV_ATTRIBUTE2      => r_APV.INFORMATION112
7797                      ,P_APV_ATTRIBUTE20      => r_APV.INFORMATION130
7798                      ,P_APV_ATTRIBUTE21      => r_APV.INFORMATION131
7799                      ,P_APV_ATTRIBUTE22      => r_APV.INFORMATION132
7800                      ,P_APV_ATTRIBUTE23      => r_APV.INFORMATION133
7801                      ,P_APV_ATTRIBUTE24      => r_APV.INFORMATION134
7802                      ,P_APV_ATTRIBUTE25      => r_APV.INFORMATION135
7803                      ,P_APV_ATTRIBUTE26      => r_APV.INFORMATION136
7804                      ,P_APV_ATTRIBUTE27      => r_APV.INFORMATION137
7805                      ,P_APV_ATTRIBUTE28      => r_APV.INFORMATION138
7806                      ,P_APV_ATTRIBUTE29      => r_APV.INFORMATION139
7807                      ,P_APV_ATTRIBUTE3      => r_APV.INFORMATION113
7808                      ,P_APV_ATTRIBUTE30      => r_APV.INFORMATION140
7809                      ,P_APV_ATTRIBUTE4      => r_APV.INFORMATION114
7810                      ,P_APV_ATTRIBUTE5      => r_APV.INFORMATION115
7811                      ,P_APV_ATTRIBUTE6      => r_APV.INFORMATION116
7812                      ,P_APV_ATTRIBUTE7      => r_APV.INFORMATION117
7813                      ,P_APV_ATTRIBUTE8      => r_APV.INFORMATION118
7814                      ,P_APV_ATTRIBUTE9      => r_APV.INFORMATION119
7815                      ,P_APV_ATTRIBUTE_CATEGORY      => r_APV.INFORMATION110
7816                      ,P_ORDR_NUM      => r_APV.INFORMATION260
7817                      ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
7818                      --
7819                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
7820                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
7821                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
7822                      --,P_DATETRACK_MODE        => hr_api.g_update
7823                      ,P_DATETRACK_MODE        => l_datetrack_mode
7824                    );
7825           end if;  -- l_update
7826          end if;
7827          --
7828          --
7829          -- Delete the row if it is end dated.
7830          --
7831          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
7832              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
7833              trunc(l_max_eed) = r_APV.information3) then
7834              --
7835              BEN_ACTUAL_PREMIUM_RATE_API.delete_ACTUAL_PREMIUM_RATE(
7836                 --
7837                 p_validate                       => false
7838                 ,p_actl_prem_vrbl_rt_id                   => l_actl_prem_vrbl_rt_id
7839                 ,p_effective_start_date           => l_effective_start_date
7840                 ,p_effective_end_date             => l_effective_end_date
7841                 ,p_object_version_number          => l_object_version_number
7842                 ,p_effective_date                 => l_max_eed
7843                 ,p_datetrack_mode                 => hr_api.g_delete
7844                 --
7845                 );
7846                 --
7847          end if;
7848          --
7849          l_prev_pk_id := l_current_pk_id ;
7850          --
7851        end if;
7852        --
7853      end if;
7854      --
7855    end loop;
7856    --
7857  exception when others then
7858      --
7859      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'APV',r_APV.information5 ) ;
7860      --
7861  end create_APV_rows;
7862 
7863    --
7864    ---------------------------------------------------------------
7865    ----------------------< create_AVA_rows >-----------------------
7866    ---------------------------------------------------------------
7867    --
7868    procedure create_AVA_rows
7869    (
7870          p_validate                       in  number     default 0
7871         ,p_copy_entity_txn_id             in  number
7872         ,p_effective_date                 in  date
7873         ,p_prefix_suffix_text             in  varchar2  default null
7874         ,p_reuse_object_flag              in  varchar2  default null
7875         ,p_target_business_group_id       in  varchar2  default null
7876         ,p_prefix_suffix_cd               in  varchar2  default null
7877    ) is
7878    --
7879    l_ACTL_PREM_ID  number;
7880    l_FORMULA_ID  number;
7881    cursor c_unique_AVA(l_table_alias varchar2) is
7882    select distinct cpe.information1,
7883      cpe.information2,
7884      cpe.information3,
7885      cpe.table_route_id,
7886      cpe.dml_operation,
7887      cpe.datetrack_mode
7888    from ben_copy_entity_results cpe,
7889         pqh_table_route tr
7890    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
7891    and   cpe.table_route_id     = tr.table_route_id
7892    -- and   tr.where_clause        = l_BEN_ACTL_PREM_VRBL_RT_RL_F
7893    and   tr.table_alias = l_table_alias
7894    and   cpe.number_of_copies   = 1 -- ADDITION
7895    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
7896    order by information1, information2; --added for bug: 5151945
7897    --
7898    --
7899    cursor c_AVA_min_max_dates(c_table_route_id  number,
7900                 c_information1   number) is
7901    select
7902      min(cpe.information2) min_esd,
7903      max(cpe.information3) min_eed
7904    from ben_copy_entity_results cpe
7905    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
7906    and   cpe.table_route_id     = c_table_route_id
7907    and   cpe.information1       = c_information1 ;
7908    --
7909    cursor c_AVA(c_table_route_id  number,
7910                 c_information1   number,
7911                 c_information2   date,
7912                 c_information3   date)  is
7913    select
7914      cpe.*
7915    from ben_copy_entity_results cpe
7916    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
7917    and   cpe.table_route_id     = c_table_route_id
7918    and   cpe.information1       = c_information1
7919    and   cpe.information2       = c_information2
7920    and   cpe.information3       = c_information3
7921    and rownum = 1 ;
7922    -- Date Track target record
7923    cursor c_find_AVA_in_target(
7924                                 c_effective_start_date    date,
7925                                 c_effective_end_date      date,
7926                                 c_business_group_id       number,
7927                                 c_new_pk_id               number) is
7928    select
7929      AVA.actl_prem_vrbl_rt_rl_id new_value
7930    from BEN_ACTL_PREM_VRBL_RT_RL_F AVA
7931    where
7932    AVA.ACTL_PREM_ID     = l_ACTL_PREM_ID  and
7933    AVA.FORMULA_ID     = l_FORMULA_ID  and
7934    AVA.business_group_id  = c_business_group_id
7935    and   AVA.actl_prem_vrbl_rt_rl_id  <> c_new_pk_id
7936 --TEMPIK
7937    and c_effective_start_date between effective_start_date
7938                             and effective_end_date ;
7939 --END TEMPIK
7940 /*TEMPIK
7941    and exists ( select null
7942                 from BEN_ACTL_PREM_VRBL_RT_RL_F AVA1
7943                 where
7944                 AVA1.ACTL_PREM_ID     = l_ACTL_PREM_ID  and
7945                 AVA1.FORMULA_ID     = l_FORMULA_ID  and
7946                 AVA1.business_group_id  = c_business_group_id
7947                 and   AVA1.effective_start_date <= c_effective_start_date )
7948    and exists ( select null
7949                 from BEN_ACTL_PREM_VRBL_RT_RL_F AVA2
7950                 where
7951                 AVA2.ACTL_PREM_ID     = l_ACTL_PREM_ID  and
7952                 AVA2.FORMULA_ID     = l_FORMULA_ID  and
7953                 AVA2.business_group_id  = c_business_group_id
7954                 and   AVA2.effective_end_date >= c_effective_end_date )
7955                 ;
7956 TEMPIK */
7957    --TEMPIK
7958    l_dt_rec_found            boolean ;
7959    --END TEMPIK
7960    --
7961    --UPD START
7962    --
7963    l_update                  boolean      := false ;
7964    l_datetrack_mode          varchar2(80) := hr_api.g_update;
7965    l_process_date            date;
7966    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
7967    --
7968    --UPD END
7969 
7970    --
7971    l_current_pk_id           number := null ;
7972    l_prev_pk_id              number := null ;
7973    l_first_rec               boolean := true ;
7974    r_AVA                     c_AVA%rowtype;
7975    l_actl_prem_vrbl_rt_rl_id             number ;
7976    l_object_version_number   number ;
7977    l_effective_start_date    date ;
7978    l_effective_end_date      date ;
7979    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
7980    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
7981    l_new_value               number(15);
7982    l_object_found_in_target  boolean := false ;
7983    l_min_esd                 date;
7984    l_max_eed                 date;
7985    l_effective_date          date;
7986    --
7987  begin
7988    -- Initialization
7989    l_object_found_in_target := false ;
7990    -- End Initialization
7991    -- Derive the prefix - sufix
7992    if   p_prefix_suffix_cd = 'PREFIX' then
7993      l_prefix  := p_prefix_suffix_text ;
7994    elsif p_prefix_suffix_cd = 'SUFFIX' then
7995      l_suffix   := p_prefix_suffix_text ;
7996    else
7997      l_prefix := null ;
7998      l_suffix  := null ;
7999    end if ;
8000    -- End Prefix Sufix derivation
8001    for r_AVA_unique in c_unique_AVA('AVA') loop
8002 
8003      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
8004         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
8005          r_AVA_unique.information3 >=
8006                  ben_pd_copy_to_ben_one.g_copy_effective_date)
8007         ) then
8008        --
8009        hr_utility.set_location(' r_AVA_unique.table_route_id '||r_AVA_unique.table_route_id,10);
8010        hr_utility.set_location(' r_AVA_unique.information1 '||r_AVA_unique.information1,10);
8011        hr_utility.set_location( 'r_AVA_unique.information2 '||r_AVA_unique.information2,10);
8012        hr_utility.set_location( 'r_AVA_unique.information3 '||r_AVA_unique.information3,10);
8013        -- If reuse objects flag is 'Y' then check for the object in the target business group
8014        -- if found insert the record into PLSql table and exit the loop else try create the
8015        -- object in the target business group
8016        --
8017        l_object_found_in_target := false ;
8018               --UPD START
8019        l_update := false;
8020        l_process_date := p_effective_date;
8021        l_dml_operation:= r_AVA_unique.dml_operation ;
8022        -- UPD START
8023        open c_AVA(r_AVA_unique.table_route_id,
8024                         r_AVA_unique.information1,
8025                         r_AVA_unique.information2,
8026                         r_AVA_unique.information3 ) ;
8027        --
8028        fetch c_AVA into r_AVA ;
8029        --
8030        close c_AVA ;
8031        l_ACTL_PREM_ID := get_fk('ACTL_PREM_ID', r_AVA.information250,r_AVA.dml_operation);
8032        l_FORMULA_ID := get_fk('FORMULA_ID', r_AVA.information251,r_AVA.dml_operation);
8033        -- UPD END
8034        --
8035        if l_dml_operation = 'UPDATE' then
8036          --
8037                  l_object_found_in_target := TRUE;
8038                  --
8039                  if l_process_date between r_AVA_unique.information2 and r_AVA_unique.information3 then
8040                        l_update := true;
8041                        if r_AVA_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
8042                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ACTL_PREM_VRBL_RT_RL_ID'
8043                        then
8044                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ACTL_PREM_VRBL_RT_RL_ID' ;
8045                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_AVA_unique.information1 ;
8046                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_AVA_unique.information1 ;
8047                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
8048                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_AVA_unique.table_route_id;
8049                           --
8050                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
8051                           --
8052                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
8053                           --
8054                           --BEN_PD_COPY_TO_BEN_ONE.log_data('AVA',l_new_value,l_prefix || r_AVA_unique.name|| l_suffix,'REUSED');
8055                           --
8056                        end if ;
8057                        hr_utility.set_location( 'found record for update',10);
8058                    --
8059                  else
8060                    --
8061                    l_update := false;
8062                    --
8063                  end if;
8064         --
8065        else
8066          --
8067          --UPD END
8068 
8069                l_min_esd := null ;
8070                l_max_eed := null ;
8071                open c_AVA_min_max_dates(r_AVA_unique.table_route_id, r_AVA_unique.information1 ) ;
8072                fetch c_AVA_min_max_dates into l_min_esd,l_max_eed ;
8073                --
8074 
8075                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
8076                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
8077                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
8078                end if;
8079                l_min_esd := greatest(l_min_esd,r_AVA_unique.information2);
8080                /*open c_AVA(r_AVA_unique.table_route_id,
8081                         r_AVA_unique.information1,
8082                         r_AVA_unique.information2,
8083                         r_AVA_unique.information3 ) ;
8084                --
8085                fetch c_AVA into r_AVA ;
8086                --
8087                close c_AVA ;*/
8088                --
8089                if p_reuse_object_flag = 'Y' then
8090                  if c_AVA_min_max_dates%found then
8091                    -- cursor to find the object
8092                    open c_find_AVA_in_target( l_min_esd,l_max_eed,
8093                                          p_target_business_group_id, nvl(l_actl_prem_vrbl_rt_rl_id, -999)  ) ;
8094                    fetch c_find_AVA_in_target into l_new_value ;
8095                    if c_find_AVA_in_target%found then
8096                      --
8097                      --TEMPIK
8098                      l_dt_rec_found :=   dt_api.check_min_max_dates
8099                          (p_base_table_name => 'BEN_ACTL_PREM_VRBL_RT_RL_F',
8100                           p_base_key_column => 'ACTL_PREM_VRBL_RT_RL_ID',
8101                           p_base_key_value  => l_new_value,
8102                           p_from_date       => l_min_esd,
8103                           p_to_date         => l_max_eed );
8104                      if l_dt_rec_found THEN
8105                      --END TEMPIK
8106                                          if r_AVA_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
8107                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'ACTL_PREM_VRBL_RT_RL_ID'  then
8108                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'ACTL_PREM_VRBL_RT_RL_ID' ;
8109                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_AVA_unique.information1 ;
8110                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
8111                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
8112                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_AVA_unique.table_route_id;
8113                                                 --
8114                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
8115                                                 --
8116                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
8117                                          end if ;
8118                                          --
8119                                          l_object_found_in_target := true ;
8120                      --TEMPIK
8121                      end if; -- l_dt_rec_found
8122                      --END TEMPIK
8123                    end if;
8124                    close c_find_AVA_in_target ;
8125                  --
8126                  end if;
8127                end if ;
8128                --
8129                close c_AVA_min_max_dates ;
8130        -- UPD START
8131        --if not l_object_found_in_target then
8132        end if; --if p_dml_operation
8133        --
8134        if not l_object_found_in_target OR l_update  then
8135        -- UPD END
8136 
8137          --
8138          l_current_pk_id := r_AVA.information1;
8139          --
8140          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
8141          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
8142          --
8143          if l_current_pk_id =  l_prev_pk_id  then
8144            --
8145            l_first_rec := false ;
8146            --
8147          else
8148            --
8149            l_first_rec := true ;
8150            --
8151          end if ;
8152          --
8153 
8154          l_effective_date := r_AVA.information2;
8155          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
8156               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
8157            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
8158          end if;
8159 
8160          -- UPD START
8161          --if l_first_rec then
8162          if l_first_rec and not l_update then
8163          -- UPD END
8164 
8165            -- Call Create routine.
8166            hr_utility.set_location(' BEN_ACTL_PREM_VRBL_RT_RL_F CREATE_ACTUAL_PREMIUM_RULE ',20);
8167            BEN_ACTUAL_PREMIUM_RULE_API.CREATE_ACTUAL_PREMIUM_RULE(
8168              --
8169              P_VALIDATE               => false
8170              ,P_EFFECTIVE_DATE        => l_effective_date
8171              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
8172              --
8173              ,P_ACTL_PREM_ID      => l_ACTL_PREM_ID
8174              ,P_ACTL_PREM_VRBL_RT_RL_ID      => l_actl_prem_vrbl_rt_rl_id
8175              ,P_AVA_ATTRIBUTE1      => r_AVA.INFORMATION111
8176              ,P_AVA_ATTRIBUTE10      => r_AVA.INFORMATION120
8177              ,P_AVA_ATTRIBUTE11      => r_AVA.INFORMATION121
8178              ,P_AVA_ATTRIBUTE12      => r_AVA.INFORMATION122
8179              ,P_AVA_ATTRIBUTE13      => r_AVA.INFORMATION123
8180              ,P_AVA_ATTRIBUTE14      => r_AVA.INFORMATION124
8181              ,P_AVA_ATTRIBUTE15      => r_AVA.INFORMATION125
8182              ,P_AVA_ATTRIBUTE16      => r_AVA.INFORMATION126
8183              ,P_AVA_ATTRIBUTE17      => r_AVA.INFORMATION127
8184              ,P_AVA_ATTRIBUTE18      => r_AVA.INFORMATION128
8185              ,P_AVA_ATTRIBUTE19      => r_AVA.INFORMATION129
8186              ,P_AVA_ATTRIBUTE2      => r_AVA.INFORMATION112
8187              ,P_AVA_ATTRIBUTE20      => r_AVA.INFORMATION130
8188              ,P_AVA_ATTRIBUTE21      => r_AVA.INFORMATION131
8189              ,P_AVA_ATTRIBUTE22      => r_AVA.INFORMATION132
8190              ,P_AVA_ATTRIBUTE23      => r_AVA.INFORMATION133
8191              ,P_AVA_ATTRIBUTE24      => r_AVA.INFORMATION134
8192              ,P_AVA_ATTRIBUTE25      => r_AVA.INFORMATION135
8193              ,P_AVA_ATTRIBUTE26      => r_AVA.INFORMATION136
8194              ,P_AVA_ATTRIBUTE27      => r_AVA.INFORMATION137
8195              ,P_AVA_ATTRIBUTE28      => r_AVA.INFORMATION138
8196              ,P_AVA_ATTRIBUTE29      => r_AVA.INFORMATION139
8197              ,P_AVA_ATTRIBUTE3      => r_AVA.INFORMATION113
8198              ,P_AVA_ATTRIBUTE30      => r_AVA.INFORMATION140
8199              ,P_AVA_ATTRIBUTE4      => r_AVA.INFORMATION114
8200              ,P_AVA_ATTRIBUTE5      => r_AVA.INFORMATION115
8201              ,P_AVA_ATTRIBUTE6      => r_AVA.INFORMATION116
8202              ,P_AVA_ATTRIBUTE7      => r_AVA.INFORMATION117
8203              ,P_AVA_ATTRIBUTE8      => r_AVA.INFORMATION118
8204              ,P_AVA_ATTRIBUTE9      => r_AVA.INFORMATION119
8205              ,P_AVA_ATTRIBUTE_CATEGORY      => r_AVA.INFORMATION110
8206              ,P_FORMULA_ID      => l_FORMULA_ID
8207              ,P_ORDR_TO_APLY_NUM      => r_AVA.INFORMATION260
8208              ,P_RT_TRTMT_CD      => r_AVA.INFORMATION11
8209              --
8210              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
8211              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
8212              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
8213            );
8214            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
8215            -- Update all relevent cer records with new pk_id
8216            hr_utility.set_location('Before plsql table ',222);
8217            hr_utility.set_location('new_value id '||l_actl_prem_vrbl_rt_rl_id,222);
8218            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'ACTL_PREM_VRBL_RT_RL_ID' ;
8219            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_AVA.information1 ;
8220            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_ACTL_PREM_VRBL_RT_RL_ID ;
8221            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
8222            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_AVA_unique.table_route_id;
8223            hr_utility.set_location('After plsql table ',222);
8224            --
8225            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
8226            --
8227            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
8228            --
8229          else
8230            --
8231            -- Call Update routine for the pk_id created in prev run .
8232            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
8233            hr_utility.set_location(' BEN_ACTL_PREM_VRBL_RT_RL_F UPDATE_ACTUAL_PREMIUM_RULE ',30);
8234            --UPD START
8235            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
8236            --
8237            if l_update then
8238              --
8239              l_datetrack_mode := r_AVA.datetrack_mode ;
8240              --
8241              get_dt_modes(
8242                p_effective_date        => l_process_date,
8243                p_effective_end_date    => r_AVA.information3,
8244                p_effective_start_date  => r_AVA.information2,
8245                p_dml_operation         => r_AVA.dml_operation,
8246                p_datetrack_mode        => l_datetrack_mode );
8247            --    p_update                => l_update
8248              --
8249              l_effective_date := l_process_date;
8250              l_actl_prem_vrbl_rt_rl_id   := r_AVA.information1;
8251              l_object_version_number := r_AVA.information265;
8252              --
8253            end if;
8254            --
8255            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
8256            --
8257            IF l_update OR l_dml_operation <> 'UPDATE' THEN
8258            --UPD END
8259 
8260                            BEN_ACTUAL_PREMIUM_RULE_API.UPDATE_ACTUAL_PREMIUM_RULE(
8261                              --
8262                              P_VALIDATE               => false
8263                              ,P_EFFECTIVE_DATE        => l_effective_date
8264                              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
8265                              --
8266                              ,P_ACTL_PREM_ID      => l_ACTL_PREM_ID
8267                              ,P_ACTL_PREM_VRBL_RT_RL_ID      => l_actl_prem_vrbl_rt_rl_id
8268                              ,P_AVA_ATTRIBUTE1      => r_AVA.INFORMATION111
8269                              ,P_AVA_ATTRIBUTE10      => r_AVA.INFORMATION120
8270                              ,P_AVA_ATTRIBUTE11      => r_AVA.INFORMATION121
8271                              ,P_AVA_ATTRIBUTE12      => r_AVA.INFORMATION122
8272                              ,P_AVA_ATTRIBUTE13      => r_AVA.INFORMATION123
8273                              ,P_AVA_ATTRIBUTE14      => r_AVA.INFORMATION124
8274                              ,P_AVA_ATTRIBUTE15      => r_AVA.INFORMATION125
8275                              ,P_AVA_ATTRIBUTE16      => r_AVA.INFORMATION126
8276                              ,P_AVA_ATTRIBUTE17      => r_AVA.INFORMATION127
8277                              ,P_AVA_ATTRIBUTE18      => r_AVA.INFORMATION128
8278                              ,P_AVA_ATTRIBUTE19      => r_AVA.INFORMATION129
8279                              ,P_AVA_ATTRIBUTE2      => r_AVA.INFORMATION112
8280                              ,P_AVA_ATTRIBUTE20      => r_AVA.INFORMATION130
8281                              ,P_AVA_ATTRIBUTE21      => r_AVA.INFORMATION131
8282                              ,P_AVA_ATTRIBUTE22      => r_AVA.INFORMATION132
8283                              ,P_AVA_ATTRIBUTE23      => r_AVA.INFORMATION133
8284                              ,P_AVA_ATTRIBUTE24      => r_AVA.INFORMATION134
8285                              ,P_AVA_ATTRIBUTE25      => r_AVA.INFORMATION135
8286                              ,P_AVA_ATTRIBUTE26      => r_AVA.INFORMATION136
8287                              ,P_AVA_ATTRIBUTE27      => r_AVA.INFORMATION137
8288                              ,P_AVA_ATTRIBUTE28      => r_AVA.INFORMATION138
8289                              ,P_AVA_ATTRIBUTE29      => r_AVA.INFORMATION139
8290                              ,P_AVA_ATTRIBUTE3      => r_AVA.INFORMATION113
8291                              ,P_AVA_ATTRIBUTE30      => r_AVA.INFORMATION140
8292                              ,P_AVA_ATTRIBUTE4      => r_AVA.INFORMATION114
8293                              ,P_AVA_ATTRIBUTE5      => r_AVA.INFORMATION115
8294                              ,P_AVA_ATTRIBUTE6      => r_AVA.INFORMATION116
8295                              ,P_AVA_ATTRIBUTE7      => r_AVA.INFORMATION117
8296                              ,P_AVA_ATTRIBUTE8      => r_AVA.INFORMATION118
8297                              ,P_AVA_ATTRIBUTE9      => r_AVA.INFORMATION119
8298                              ,P_AVA_ATTRIBUTE_CATEGORY      => r_AVA.INFORMATION110
8299                              ,P_FORMULA_ID      => l_FORMULA_ID
8300                              ,P_ORDR_TO_APLY_NUM      => r_AVA.INFORMATION260
8301                              ,P_RT_TRTMT_CD      => r_AVA.INFORMATION11
8302                              --
8303                              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
8304                              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
8305                              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
8306                              ,P_DATETRACK_MODE        => l_datetrack_mode
8307                              --,P_DATETRACK_MODE        => hr_api.g_update
8308                            );
8309 
8310                    end if;  -- l_update
8311                  end if;
8312          --
8313          --
8314          -- Delete the row if it is end dated.
8315          --
8316          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
8317              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
8318            trunc(l_max_eed) = r_AVA.information3) then
8319              --
8320              BEN_ACTUAL_PREMIUM_RULE_API.delete_ACTUAL_PREMIUM_RULE(
8321                 --
8322                 p_validate                       => false
8323                 ,p_actl_prem_vrbl_rt_rl_id                   => l_actl_prem_vrbl_rt_rl_id
8324                 ,p_effective_start_date           => l_effective_start_date
8325                 ,p_effective_end_date             => l_effective_end_date
8326                 ,p_object_version_number          => l_object_version_number
8327                 ,p_effective_date                 => l_max_eed
8328                 ,p_datetrack_mode                 => hr_api.g_delete
8329                 --
8330                 );
8331                 --
8332          end if;
8333          --
8334          l_prev_pk_id := l_current_pk_id ;
8335          --
8336        end if;
8337        --
8338      end if;
8339      --
8340    end loop;
8341    --
8342  exception when others then
8343      --
8344      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'AVA',r_AVA.information5 ) ;
8345      --
8346  end create_AVA_rows;
8347    ---------------------------------------------------------------
8348    ----------------------< create_ABP_rows >-----------------------
8349    ---------------------------------------------------------------
8350    --
8351    procedure create_ABP_rows
8352    (
8353          p_validate                       in  number     default 0
8354         ,p_copy_entity_txn_id             in  number
8355         ,p_effective_date                 in  date
8356         ,p_prefix_suffix_text             in  varchar2  default null
8357         ,p_reuse_object_flag              in  varchar2  default null
8358         ,p_target_business_group_id       in  varchar2  default null
8359         ,p_prefix_suffix_cd               in  varchar2  default null
8360    ) is
8361    --
8362    l_ACTY_BASE_RT_ID  number;
8363    l_BNFT_PRVDR_POOL_ID  number;
8364    cursor c_unique_ABP(l_table_alias varchar2) is
8365    select distinct cpe.information1,
8366      cpe.information2,
8367      cpe.information3,
8368      cpe.table_route_id,
8369      cpe.dml_operation,
8370      cpe.datetrack_mode
8371    from ben_copy_entity_results cpe,
8372         pqh_table_route tr
8373    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
8374    and   cpe.table_route_id     = tr.table_route_id
8375    -- and   tr.where_clause        = l_BEN_APLCN_TO_BNFT_POOL_F
8376    and   tr.table_alias = l_table_alias
8377    and   cpe.number_of_copies   = 1 -- ADDITION
8378    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
8379    order by information1, information2; --added for bug: 5151945
8380    --
8381    --
8382    cursor c_ABP_min_max_dates(c_table_route_id  number,
8383                 c_information1   number) is
8384    select
8385      min(cpe.information2) min_esd,
8386      max(cpe.information3) min_eed
8387    from ben_copy_entity_results cpe
8388    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
8389    and   cpe.table_route_id     = c_table_route_id
8390    and   cpe.information1       = c_information1 ;
8391    --
8392    cursor c_ABP(c_table_route_id  number,
8393                 c_information1   number,
8394                 c_information2   date,
8395                 c_information3   date)  is
8396    select
8397      cpe.*
8398    from ben_copy_entity_results cpe
8399    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
8400    and   cpe.table_route_id     = c_table_route_id
8401    and   cpe.information1       = c_information1
8402    and   cpe.information2       = c_information2
8403    and   cpe.information3       = c_information3
8404    and rownum = 1 ;
8405    -- Date Track target record
8406    cursor c_find_ABP_in_target(
8407                                 c_effective_start_date    date,
8408                                 c_effective_end_date      date,
8409                                 c_business_group_id       number,
8410                                 c_new_pk_id               number) is
8411    select
8412      ABP.aplcn_to_bnft_pool_id new_value
8413    from BEN_APLCN_TO_BNFT_POOL_F ABP
8414    where
8415    ABP.ACTY_BASE_RT_ID     = l_ACTY_BASE_RT_ID  and
8416    ABP.BNFT_PRVDR_POOL_ID     = l_BNFT_PRVDR_POOL_ID  and
8417    ABP.business_group_id  = c_business_group_id
8418    and   ABP.aplcn_to_bnft_pool_id  <> c_new_pk_id
8419 --TEMPIK
8420    and c_effective_start_date between effective_start_date
8421                             and effective_end_date ;
8422 --END TEMPIK
8423 /*TEMPIK
8424    and exists ( select null
8425                 from BEN_APLCN_TO_BNFT_POOL_F ABP1
8426                 where
8427                 ABP1.ACTY_BASE_RT_ID     = l_ACTY_BASE_RT_ID  and
8428                 ABP1.BNFT_PRVDR_POOL_ID     = l_BNFT_PRVDR_POOL_ID  and
8429                 ABP1.business_group_id  = c_business_group_id
8430                 and   ABP1.effective_start_date <= c_effective_start_date )
8431    and exists ( select null
8432                 from BEN_APLCN_TO_BNFT_POOL_F ABP2
8433                 where
8434                 ABP2.ACTY_BASE_RT_ID     = l_ACTY_BASE_RT_ID  and
8435                 ABP2.BNFT_PRVDR_POOL_ID     = l_BNFT_PRVDR_POOL_ID  and
8436                 ABP2.business_group_id  = c_business_group_id
8437                 and   ABP2.effective_end_date >= c_effective_end_date )
8438                 ;
8439 TEMPIK */
8440    --TEMPIK
8441    l_dt_rec_found            boolean ;
8442    --END TEMPIK
8443 
8444    --UPD START
8445    --
8446    l_update                  boolean      := false ;
8447    l_datetrack_mode          varchar2(80) := hr_api.g_update;
8448    l_process_date            date;
8449    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
8450    --
8451    --UPD END
8452 
8453    --
8454    l_current_pk_id           number := null ;
8455    l_prev_pk_id              number := null ;
8456    l_first_rec               boolean := true ;
8457    r_ABP                     c_ABP%rowtype;
8458    l_aplcn_to_bnft_pool_id             number ;
8459    l_object_version_number   number ;
8460    l_effective_start_date    date ;
8461    l_effective_end_date      date ;
8462    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
8463    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
8464    l_new_value               number(15);
8465    l_object_found_in_target  boolean := false ;
8466    l_min_esd                 date;
8467    l_max_eed                 date;
8468    l_effective_date          date;
8469    --
8470  begin
8471    -- Initialization
8472    l_object_found_in_target := false ;
8473    -- End Initialization
8474    -- Derive the prefix - sufix
8475    if   p_prefix_suffix_cd = 'PREFIX' then
8476      l_prefix  := p_prefix_suffix_text ;
8477    elsif p_prefix_suffix_cd = 'SUFFIX' then
8478      l_suffix   := p_prefix_suffix_text ;
8479    else
8480      l_prefix := null ;
8481      l_suffix  := null ;
8482    end if ;
8483    -- End Prefix Sufix derivation
8484    for r_ABP_unique in c_unique_ABP('ABP') loop
8485 
8486      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
8487         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
8488          r_ABP_unique.information3 >=
8489                  ben_pd_copy_to_ben_one.g_copy_effective_date)
8490         ) then
8491        --
8492        hr_utility.set_location(' r_ABP_unique.table_route_id '||r_ABP_unique.table_route_id,10);
8493        hr_utility.set_location(' r_ABP_unique.information1 '||r_ABP_unique.information1,10);
8494        hr_utility.set_location( 'r_ABP_unique.information2 '||r_ABP_unique.information2,10);
8495        hr_utility.set_location( 'r_ABP_unique.information3 '||r_ABP_unique.information3,10);
8496        -- If reuse objects flag is 'Y' then check for the object in the target business group
8497        -- if found insert the record into PLSql table and exit the loop else try create the
8498        -- object in the target business group
8499        --
8500        l_object_found_in_target := false ;
8501        --UPD START
8502        l_update := false;
8503        l_process_date := p_effective_date;
8504        l_dml_operation:= r_ABP_unique.dml_operation ;
8505        --
8506        open c_ABP(r_ABP_unique.table_route_id,
8507                 r_ABP_unique.information1,
8508                 r_ABP_unique.information2,
8509                 r_ABP_unique.information3 ) ;
8510        --
8511        fetch c_ABP into r_ABP ;
8512        --
8513        close c_ABP ;
8514        -- Only For Use by Create Wizard - Same Business Group
8515        l_ACTY_BASE_RT_ID := NVL(get_fk('ACTY_BASE_RT_ID', r_ABP.information253,r_ABP.DML_OPERATION),
8516                                 r_ABP.information253);
8517 
8518        l_BNFT_PRVDR_POOL_ID := get_fk('BNFT_PRVDR_POOL_ID', r_ABP.information235,r_ABP.DML_OPERATION);
8519        --
8520        if l_dml_operation = 'UPDATE' then
8521          --
8522                  l_object_found_in_target := TRUE;
8523                  --
8524                  if l_process_date between r_ABP_unique.information2 and r_ABP_unique.information3 then
8525                        l_update := true;
8526                        if r_ABP_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
8527                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'APLCN_TO_BNFT_POOL_ID'
8528                        then
8529                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'APLCN_TO_BNFT_POOL_ID' ;
8530                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_ABP_unique.information1 ;
8531                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_ABP_unique.information1 ;
8532                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
8533                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_ABP_unique.table_route_id;
8534                           --
8535                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
8536                           --
8537                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
8538                           --
8539                          -- BEN_PD_COPY_TO_BEN_ONE.log_data('ABP',l_new_value,l_prefix || r_ABP_unique.name|| l_suffix,'REUSED');
8540                           --
8541                        end if ;
8542                        hr_utility.set_location( 'found record for update',10);
8543                    --
8544                  else
8545                    --
8546                    l_update := false;
8547            --
8548          end if;
8549        else
8550        --
8551        --UPD END
8552 
8553        l_min_esd := null ;
8554        l_max_eed := null ;
8555        open c_ABP_min_max_dates(r_ABP_unique.table_route_id, r_ABP_unique.information1 ) ;
8556        fetch c_ABP_min_max_dates into l_min_esd,l_max_eed ;
8557        --
8558 
8559        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
8560             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
8561          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
8562        end if;
8563        l_min_esd := greatest(l_min_esd,r_ABP_unique.information2);
8564        /*open c_ABP(r_ABP_unique.table_route_id,
8565                 r_ABP_unique.information1,
8566                 r_ABP_unique.information2,
8567                 r_ABP_unique.information3 ) ;
8568        --
8569        fetch c_ABP into r_ABP ;
8570        --
8571        close c_ABP ;*/
8572        --
8573        if p_reuse_object_flag = 'Y' then
8574          if c_ABP_min_max_dates%found then
8575            -- cursor to find the object
8576            open c_find_ABP_in_target( l_min_esd,l_max_eed,
8577                                  p_target_business_group_id, nvl(l_aplcn_to_bnft_pool_id, -999)  ) ;
8578            fetch c_find_ABP_in_target into l_new_value ;
8579            if c_find_ABP_in_target%found then
8580              --
8581              --TEMPIK
8582              l_dt_rec_found :=   dt_api.check_min_max_dates
8583                  (p_base_table_name => 'BEN_APLCN_TO_BNFT_POOL_F',
8584                   p_base_key_column => 'APLCN_TO_BNFT_POOL_ID',
8585                   p_base_key_value  => l_new_value,
8586                   p_from_date       => l_min_esd,
8587                   p_to_date         => l_max_eed );
8588              if l_dt_rec_found THEN
8589              --END TEMPIK
8590                                  if r_ABP_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
8591                                         nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'APLCN_TO_BNFT_POOL_ID'  then
8592                                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'APLCN_TO_BNFT_POOL_ID' ;
8593                                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_ABP_unique.information1 ;
8594                                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
8595                                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
8596                                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_ABP_unique.table_route_id;
8597                                         --
8598                                         -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
8599                                         --
8600                                         ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
8601                                  end if ;
8602                                  --
8603                                  l_object_found_in_target := true ;
8604              --TEMPIK
8605              end if; -- l_dt_rec_found
8606              --END TEMPIK
8607            end if;
8608            close c_find_ABP_in_target ;
8609          --
8610          end if;
8611        end if ;
8612        --
8613        close c_ABP_min_max_dates ;
8614 
8615        -- UPD START
8616        end if; --if p_dml_operation
8617        --
8618        if not l_object_found_in_target OR l_update  then
8619        --if not l_object_found_in_target then
8620        -- UPD END
8621          --
8622          l_current_pk_id := r_ABP.information1;
8623          --
8624          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
8625          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
8626          --
8627          if l_current_pk_id =  l_prev_pk_id  then
8628            --
8629            l_first_rec := false ;
8630            --
8631          else
8632            --
8633            l_first_rec := true ;
8634            --
8635          end if ;
8636          --
8637 
8638          l_effective_date := r_ABP.information2;
8639          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
8640               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
8641            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
8642          end if;
8643 
8644          -- UPD START
8645          --if l_first_rec then
8646          if l_first_rec and not l_update then
8647          -- UPD END
8648 
8649            -- Call Create routine.
8650            hr_utility.set_location(' BEN_APLCN_TO_BNFT_POOL_F CREATE_APLCN_TO_BENEFIT_POOL ',20);
8651            BEN_APLCN_TO_BENEFIT_POOL_API.CREATE_APLCN_TO_BENEFIT_POOL(
8652              --
8653              P_VALIDATE               => false
8654              ,P_EFFECTIVE_DATE        => l_effective_date
8655              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
8656              --
8657              ,P_ABP_ATTRIBUTE1      => r_ABP.INFORMATION111
8658              ,P_ABP_ATTRIBUTE10      => r_ABP.INFORMATION120
8659              ,P_ABP_ATTRIBUTE11      => r_ABP.INFORMATION121
8660              ,P_ABP_ATTRIBUTE12      => r_ABP.INFORMATION122
8661              ,P_ABP_ATTRIBUTE13      => r_ABP.INFORMATION123
8662              ,P_ABP_ATTRIBUTE14      => r_ABP.INFORMATION124
8663              ,P_ABP_ATTRIBUTE15      => r_ABP.INFORMATION125
8664              ,P_ABP_ATTRIBUTE16      => r_ABP.INFORMATION126
8665              ,P_ABP_ATTRIBUTE17      => r_ABP.INFORMATION127
8666              ,P_ABP_ATTRIBUTE18      => r_ABP.INFORMATION128
8667              ,P_ABP_ATTRIBUTE19      => r_ABP.INFORMATION129
8668              ,P_ABP_ATTRIBUTE2      => r_ABP.INFORMATION112
8669              ,P_ABP_ATTRIBUTE20      => r_ABP.INFORMATION130
8670              ,P_ABP_ATTRIBUTE21      => r_ABP.INFORMATION131
8671              ,P_ABP_ATTRIBUTE22      => r_ABP.INFORMATION132
8672              ,P_ABP_ATTRIBUTE23      => r_ABP.INFORMATION133
8673              ,P_ABP_ATTRIBUTE24      => r_ABP.INFORMATION134
8674              ,P_ABP_ATTRIBUTE25      => r_ABP.INFORMATION135
8675              ,P_ABP_ATTRIBUTE26      => r_ABP.INFORMATION136
8676              ,P_ABP_ATTRIBUTE27      => r_ABP.INFORMATION137
8677              ,P_ABP_ATTRIBUTE28      => r_ABP.INFORMATION138
8678              ,P_ABP_ATTRIBUTE29      => r_ABP.INFORMATION139
8679              ,P_ABP_ATTRIBUTE3      => r_ABP.INFORMATION113
8680              ,P_ABP_ATTRIBUTE30      => r_ABP.INFORMATION140
8681              ,P_ABP_ATTRIBUTE4      => r_ABP.INFORMATION114
8682              ,P_ABP_ATTRIBUTE5      => r_ABP.INFORMATION115
8683              ,P_ABP_ATTRIBUTE6      => r_ABP.INFORMATION116
8684              ,P_ABP_ATTRIBUTE7      => r_ABP.INFORMATION117
8685              ,P_ABP_ATTRIBUTE8      => r_ABP.INFORMATION118
8686              ,P_ABP_ATTRIBUTE9      => r_ABP.INFORMATION119
8687              ,P_ABP_ATTRIBUTE_CATEGORY      => r_ABP.INFORMATION110
8688              ,P_ACTY_BASE_RT_ID      => l_ACTY_BASE_RT_ID
8689              ,P_APLCN_TO_BNFT_POOL_ID      => l_aplcn_to_bnft_pool_id
8690              ,P_BNFT_PRVDR_POOL_ID      => l_BNFT_PRVDR_POOL_ID
8691              --
8692              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
8693              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
8694              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
8695            );
8696            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
8697            -- Update all relevent cer records with new pk_id
8698            hr_utility.set_location('Before plsql table ',222);
8699            hr_utility.set_location('new_value id '||l_aplcn_to_bnft_pool_id,222);
8700            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'APLCN_TO_BNFT_POOL_ID' ;
8701            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_ABP.information1 ;
8702            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_APLCN_TO_BNFT_POOL_ID ;
8703            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
8704            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_ABP_unique.table_route_id;
8705            hr_utility.set_location('After plsql table ',222);
8706            --
8707            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
8708            --
8709            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
8710            --
8711          else
8712            --
8713            -- Call Update routine for the pk_id created in prev run .
8714            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
8715            hr_utility.set_location(' BEN_APLCN_TO_BNFT_POOL_F UPDATE_APLCN_TO_BENEFIT_POOL ',30);
8716             --UPD START
8717            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
8718            --
8719            if l_update then
8720              --
8721              l_datetrack_mode := r_ABP.datetrack_mode ;
8722              --
8723              get_dt_modes(
8724                p_effective_date        => l_process_date,
8725                p_effective_end_date    => r_ABP.information3,
8726                p_effective_start_date  => r_ABP.information2,
8727                p_dml_operation         => r_ABP.dml_operation,
8728                p_datetrack_mode        => l_datetrack_mode );
8729            --    p_update                => l_update
8730              --
8731              l_effective_date := l_process_date;
8732              l_aplcn_to_bnft_pool_id  := r_ABP.information1;
8733              l_object_version_number := r_ABP.information265;
8734              --
8735            end if;
8736            --
8737            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
8738            --
8739            IF l_update OR l_dml_operation <> 'UPDATE' THEN
8740            --UPD END
8741 
8742                    BEN_APLCN_TO_BENEFIT_POOL_API.UPDATE_APLCN_TO_BENEFIT_POOL(
8743                      --
8744                      P_VALIDATE               => false
8745                      ,P_EFFECTIVE_DATE        => l_effective_date
8746                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
8747                      --
8748                      ,P_ABP_ATTRIBUTE1      => r_ABP.INFORMATION111
8749                      ,P_ABP_ATTRIBUTE10      => r_ABP.INFORMATION120
8750                      ,P_ABP_ATTRIBUTE11      => r_ABP.INFORMATION121
8751                      ,P_ABP_ATTRIBUTE12      => r_ABP.INFORMATION122
8752                      ,P_ABP_ATTRIBUTE13      => r_ABP.INFORMATION123
8753                      ,P_ABP_ATTRIBUTE14      => r_ABP.INFORMATION124
8754                      ,P_ABP_ATTRIBUTE15      => r_ABP.INFORMATION125
8755                      ,P_ABP_ATTRIBUTE16      => r_ABP.INFORMATION126
8756                      ,P_ABP_ATTRIBUTE17      => r_ABP.INFORMATION127
8757                      ,P_ABP_ATTRIBUTE18      => r_ABP.INFORMATION128
8758                      ,P_ABP_ATTRIBUTE19      => r_ABP.INFORMATION129
8759                      ,P_ABP_ATTRIBUTE2      => r_ABP.INFORMATION112
8760                      ,P_ABP_ATTRIBUTE20      => r_ABP.INFORMATION130
8761                      ,P_ABP_ATTRIBUTE21      => r_ABP.INFORMATION131
8762                      ,P_ABP_ATTRIBUTE22      => r_ABP.INFORMATION132
8763                      ,P_ABP_ATTRIBUTE23      => r_ABP.INFORMATION133
8764                      ,P_ABP_ATTRIBUTE24      => r_ABP.INFORMATION134
8765                      ,P_ABP_ATTRIBUTE25      => r_ABP.INFORMATION135
8766                      ,P_ABP_ATTRIBUTE26      => r_ABP.INFORMATION136
8767                      ,P_ABP_ATTRIBUTE27      => r_ABP.INFORMATION137
8768                      ,P_ABP_ATTRIBUTE28      => r_ABP.INFORMATION138
8769                      ,P_ABP_ATTRIBUTE29      => r_ABP.INFORMATION139
8770                      ,P_ABP_ATTRIBUTE3      => r_ABP.INFORMATION113
8771                      ,P_ABP_ATTRIBUTE30      => r_ABP.INFORMATION140
8772                      ,P_ABP_ATTRIBUTE4      => r_ABP.INFORMATION114
8773                      ,P_ABP_ATTRIBUTE5      => r_ABP.INFORMATION115
8774                      ,P_ABP_ATTRIBUTE6      => r_ABP.INFORMATION116
8775                      ,P_ABP_ATTRIBUTE7      => r_ABP.INFORMATION117
8776                      ,P_ABP_ATTRIBUTE8      => r_ABP.INFORMATION118
8777                      ,P_ABP_ATTRIBUTE9      => r_ABP.INFORMATION119
8778                      ,P_ABP_ATTRIBUTE_CATEGORY      => r_ABP.INFORMATION110
8779                      ,P_ACTY_BASE_RT_ID      => l_ACTY_BASE_RT_ID
8780                      ,P_APLCN_TO_BNFT_POOL_ID      => l_aplcn_to_bnft_pool_id
8781                      ,P_BNFT_PRVDR_POOL_ID      => l_BNFT_PRVDR_POOL_ID
8782                      --
8783                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
8784                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
8785                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
8786                      ,P_DATETRACK_MODE        => l_datetrack_mode
8787                      --,P_DATETRACK_MODE        => hr_api.g_update
8788                    );
8789              end if;  -- l_update
8790          end if;
8791          --
8792          --
8793          -- Delete the row if it is end dated.
8794          --
8795          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
8796              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
8797            trunc(l_max_eed) = r_ABP.information3) then
8798              --
8799              BEN_APLCN_TO_BENEFIT_POOL_API.delete_APLCN_TO_BENEFIT_POOL(
8800                 --
8801                 p_validate                       => false
8802                 ,p_aplcn_to_bnft_pool_id                   => l_aplcn_to_bnft_pool_id
8803                 ,p_effective_start_date           => l_effective_start_date
8804                 ,p_effective_end_date             => l_effective_end_date
8805                 ,p_object_version_number          => l_object_version_number
8806                 ,p_effective_date                 => l_max_eed
8807                 ,p_datetrack_mode                 => hr_api.g_delete
8808                 --
8809                 );
8810                 --
8811          end if;
8812          --
8813          l_prev_pk_id := l_current_pk_id ;
8814          --
8815        end if;
8816        --
8817      end if;
8818      --
8819    end loop;
8820    --
8821  exception when others then
8822      --
8823      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'ABP',r_ABP.information5 ) ;
8824      --
8825  end create_ABP_rows;
8826 
8827    --
8828    ---------------------------------------------------------------
8829    ----------------------< create_BPR_rows >-----------------------
8830    ---------------------------------------------------------------
8831    --
8832    procedure create_BPR_rows
8833    (
8834          p_validate                       in  number     default 0
8835         ,p_copy_entity_txn_id             in  number
8836         ,p_effective_date                 in  date
8837         ,p_prefix_suffix_text             in  varchar2  default null
8838         ,p_reuse_object_flag              in  varchar2  default null
8839         ,p_target_business_group_id       in  varchar2  default null
8840         ,p_prefix_suffix_cd               in  varchar2  default null
8841    ) is
8842    --
8843    l_ACTY_BASE_RT_ID  number;
8844    l_BNFT_PRVDR_POOL_ID  number;
8845    l_PCT_RNDG_RL  number;
8846    l_PRTT_ELIG_RLOVR_RL  number;
8847    l_RLOVR_VAL_RL  number;
8848    l_VAL_RNDG_RL  number;
8849    cursor c_unique_BPR(l_table_alias varchar2) is
8850    select distinct cpe.information1,
8851      cpe.information2,
8852      cpe.information3,
8853      cpe.table_route_id,
8854      cpe.dml_operation,
8855      cpe.datetrack_mode
8856    from ben_copy_entity_results cpe,
8857         pqh_table_route tr
8858    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
8859    and   cpe.table_route_id     = tr.table_route_id
8860    -- and   tr.where_clause        = l_BEN_BNFT_POOL_RLOVR_RQMT_F
8861    and   tr.table_alias = l_table_alias
8862    and   cpe.number_of_copies   = 1 -- ADDITION
8863    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
8864    order by information1, information2; --added for bug: 5151945
8865    --
8866    --
8867    cursor c_BPR_min_max_dates(c_table_route_id  number,
8868                 c_information1   number) is
8869    select
8870      min(cpe.information2) min_esd,
8871      max(cpe.information3) min_eed
8872    from ben_copy_entity_results cpe
8873    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
8874    and   cpe.table_route_id     = c_table_route_id
8875    and   cpe.information1       = c_information1 ;
8876    --
8877    cursor c_BPR(c_table_route_id  number,
8878                 c_information1   number,
8879                 c_information2   date,
8880                 c_information3   date)  is
8881    select
8882      cpe.*
8883    from ben_copy_entity_results cpe
8884    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
8885    and   cpe.table_route_id     = c_table_route_id
8886    and   cpe.information1       = c_information1
8887    and   cpe.information2       = c_information2
8888    and   cpe.information3       = c_information3
8889    and rownum = 1 ;
8890    -- Date Track target record
8891    cursor c_find_BPR_in_target(
8892                                 c_effective_start_date    date,
8893                                 c_effective_end_date      date,
8894                                 c_business_group_id       number,
8895                                 c_new_pk_id               number) is
8896    select
8897      BPR.bnft_pool_rlovr_rqmt_id new_value
8898    from BEN_BNFT_POOL_RLOVR_RQMT_F BPR
8899    where
8900    BPR.ACTY_BASE_RT_ID     = l_ACTY_BASE_RT_ID  and
8901    BPR.BNFT_PRVDR_POOL_ID     = l_BNFT_PRVDR_POOL_ID  and
8902    BPR.business_group_id  = c_business_group_id
8903    and   BPR.bnft_pool_rlovr_rqmt_id  <> c_new_pk_id
8904 --TEMPIK
8905    and c_effective_start_date between effective_start_date
8906                             and effective_end_date ;
8907 --END TEMPIK
8908 /*TEMPIK
8909    and exists ( select null
8910                 from BEN_BNFT_POOL_RLOVR_RQMT_F BPR1
8911                 where
8912                 BPR1.ACTY_BASE_RT_ID     = l_ACTY_BASE_RT_ID  and
8913                 BPR1.BNFT_PRVDR_POOL_ID     = l_BNFT_PRVDR_POOL_ID  and
8914                 BPR1.business_group_id  = c_business_group_id
8915                 and   BPR1.effective_start_date <= c_effective_start_date )
8916    and exists ( select null
8917                 from BEN_BNFT_POOL_RLOVR_RQMT_F BPR2
8918                 where
8919                 BPR2.ACTY_BASE_RT_ID     = l_ACTY_BASE_RT_ID  and
8920                 BPR2.BNFT_PRVDR_POOL_ID     = l_BNFT_PRVDR_POOL_ID  and
8921                 BPR2.business_group_id  = c_business_group_id
8922                 and   BPR2.effective_end_date >= c_effective_end_date )
8923                 ;
8924 TEMPIK */
8925    --TEMPIK
8926    l_dt_rec_found            boolean ;
8927    --END TEMPIK
8928    --
8929    --UPD START
8930    --
8931    l_update                  boolean      := false ;
8932    l_datetrack_mode          varchar2(80) := hr_api.g_update;
8933    l_process_date            date;
8934    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
8935    --
8936    --UPD END
8937 
8938    l_current_pk_id           number := null ;
8939    l_prev_pk_id              number := null ;
8940    l_first_rec               boolean := true ;
8941    r_BPR                     c_BPR%rowtype;
8942    l_bnft_pool_rlovr_rqmt_id             number ;
8943    l_object_version_number   number ;
8944    l_effective_start_date    date ;
8945    l_effective_end_date      date ;
8946    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
8947    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
8948    l_new_value               number(15);
8949    l_object_found_in_target  boolean := false ;
8950    l_min_esd                 date;
8951    l_max_eed                 date;
8952    l_effective_date          date;
8953    --
8954  begin
8955    -- Initialization
8956    l_object_found_in_target := false ;
8957    -- End Initialization
8958    -- Derive the prefix - sufix
8959    if   p_prefix_suffix_cd = 'PREFIX' then
8960      l_prefix  := p_prefix_suffix_text ;
8961    elsif p_prefix_suffix_cd = 'SUFFIX' then
8962      l_suffix   := p_prefix_suffix_text ;
8963    else
8964      l_prefix := null ;
8965      l_suffix  := null ;
8966    end if ;
8967    -- End Prefix Sufix derivation
8968    for r_BPR_unique in c_unique_BPR('BPR1') loop
8969 
8970      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
8971         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
8972          r_BPR_unique.information3 >=
8973                  ben_pd_copy_to_ben_one.g_copy_effective_date)
8974         ) then
8975        --
8976        hr_utility.set_location(' r_BPR_unique.table_route_id '||r_BPR_unique.table_route_id,10);
8977        hr_utility.set_location(' r_BPR_unique.information1 '||r_BPR_unique.information1,10);
8978        hr_utility.set_location( 'r_BPR_unique.information2 '||r_BPR_unique.information2,10);
8979        hr_utility.set_location( 'r_BPR_unique.information3 '||r_BPR_unique.information3,10);
8980        -- If reuse objects flag is 'Y' then check for the object in the target business group
8981        -- if found insert the record into PLSql table and exit the loop else try create the
8982        -- object in the target business group
8983        --
8984        l_object_found_in_target := false ;
8985        --UPD START
8986        l_update := false;
8987        l_process_date := p_effective_date;
8988        l_dml_operation:= r_BPR_unique.dml_operation ;
8989        --
8990        open c_BPR(r_BPR_unique.table_route_id,
8991                         r_BPR_unique.information1,
8992                         r_BPR_unique.information2,
8993                         r_BPR_unique.information3 ) ;
8994         --
8995         fetch c_BPR into r_BPR ;
8996         --
8997         close c_BPR ;
8998         -- Only For Use by Create Wizard - Same Business Group
8999         l_ACTY_BASE_RT_ID := NVL(get_fk('ACTY_BASE_RT_ID', r_BPR.information253,r_BPR.dml_operation),
9000                                         r_BPR.information253);
9001 
9002         l_BNFT_PRVDR_POOL_ID := get_fk('BNFT_PRVDR_POOL_ID', r_BPR.information235,r_BPR.dml_operation);
9003         l_PCT_RNDG_RL := get_fk('FORMULA_ID', r_BPR.information263,r_BPR.dml_operation);
9004         l_PRTT_ELIG_RLOVR_RL := get_fk('FORMULA_ID', r_BPR.information260,r_BPR.dml_operation);
9005         l_RLOVR_VAL_RL := get_fk('FORMULA_ID', r_BPR.information269,r_BPR.dml_operation);
9006         l_VAL_RNDG_RL := get_fk('FORMULA_ID', r_BPR.information262,r_BPR.dml_operation);
9007        --
9008        if l_dml_operation = 'UPDATE' then
9009          --
9010                  l_object_found_in_target := TRUE;
9011                  --
9012                  if l_process_date between r_BPR_unique.information2 and r_BPR_unique.information3 then
9013                        l_update := true;
9014                        if r_BPR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
9015                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'BNFT_POOL_RLOVR_RQMT_ID'
9016                        then
9017                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'BNFT_POOL_RLOVR_RQMT_ID' ;
9018                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_BPR_unique.information1 ;
9019                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_BPR_unique.information1 ;
9020                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
9021                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_BPR_unique.table_route_id;
9022                           --
9023                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
9024                           --
9025                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
9026                           --
9027                           --BEN_PD_COPY_TO_BEN_ONE.log_data('BPR',l_new_value,l_prefix || r_BPR_unique.name|| l_suffix,'REUSED');
9028                           --
9029                        end if ;
9030                        hr_utility.set_location( 'found record for update',10);
9031                    --
9032                  else
9033                    --
9034                    l_update := false;
9035                    --
9036                  end if;
9037        else
9038         --
9039         --UPD END
9040 
9041                l_min_esd := null ;
9042                l_max_eed := null ;
9043                open c_BPR_min_max_dates(r_BPR_unique.table_route_id, r_BPR_unique.information1 ) ;
9044                fetch c_BPR_min_max_dates into l_min_esd,l_max_eed ;
9045                --
9046 
9047                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
9048                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
9049                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
9050                end if;
9051                l_min_esd := greatest(l_min_esd,r_BPR_unique.information2);
9052                /*open c_BPR(r_BPR_unique.table_route_id,
9053                         r_BPR_unique.information1,
9054                         r_BPR_unique.information2,
9055                         r_BPR_unique.information3 ) ;
9056                --
9057                fetch c_BPR into r_BPR ;
9058                --
9059                close c_BPR ;*/
9060                --
9061                if p_reuse_object_flag = 'Y' then
9062                  if c_BPR_min_max_dates%found then
9063                    -- cursor to find the object
9064                    open c_find_BPR_in_target( l_min_esd,l_max_eed,
9065                                          p_target_business_group_id, nvl(l_bnft_pool_rlovr_rqmt_id, -999)  ) ;
9066                    fetch c_find_BPR_in_target into l_new_value ;
9067                    if c_find_BPR_in_target%found then
9068                      --
9069                      --TEMPIK
9070                      l_dt_rec_found :=   dt_api.check_min_max_dates
9071                          (p_base_table_name => 'BEN_BNFT_POOL_RLOVR_RQMT_F',
9072                           p_base_key_column => 'BNFT_POOL_RLOVR_RQMT_ID',
9073                           p_base_key_value  => l_new_value,
9074                           p_from_date       => l_min_esd,
9075                           p_to_date         => l_max_eed );
9076                      if l_dt_rec_found THEN
9077                      --END TEMPIK
9078                                          if r_BPR_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
9079                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'BNFT_POOL_RLOVR_RQMT_ID'  then
9080                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'BNFT_POOL_RLOVR_RQMT_ID' ;
9081                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_BPR_unique.information1 ;
9082                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
9083                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
9084                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_BPR_unique.table_route_id;
9085                                                 --
9086                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
9087                                                 --
9088                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
9089                                          end if ;
9090                                          --
9091                                          l_object_found_in_target := true ;
9092                      --TEMPIK
9093                      end if; -- l_dt_rec_found
9094                      --END TEMPIK
9095                    end if;
9096                    close c_find_BPR_in_target ;
9097                  --
9098                  end if;
9099                end if ;
9100                --
9101                close c_BPR_min_max_dates ;
9102        -- UPD START
9103        --if not l_object_found_in_target then
9104        end if; --if p_dml_operation
9105        --
9106        if not l_object_found_in_target OR l_update  then
9107          --
9108          l_current_pk_id := r_BPR.information1;
9109          --
9110          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
9111          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
9112          --
9113          if l_current_pk_id =  l_prev_pk_id  then
9114            --
9115            l_first_rec := false ;
9116            --
9117          else
9118            --
9119            l_first_rec := true ;
9120            --
9121          end if ;
9122          --
9123 
9124          l_effective_date := r_BPR.information2;
9125          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
9126               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
9127            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
9128          end if;
9129 
9130          -- UPD START
9131          --if l_first_rec then
9132          if l_first_rec and not l_update then
9133          -- UPD END
9134 
9135            -- Call Create routine.
9136            hr_utility.set_location(' BEN_BNFT_POOL_RLOVR_RQMT_F CREATE_BNFT_POOL_RLOVR_RQMT ',20);
9137            BEN_BNFT_POOL_RLOVR_RQMT_API.CREATE_BNFT_POOL_RLOVR_RQMT(
9138              --
9139              P_VALIDATE               => false
9140              ,P_EFFECTIVE_DATE        => l_effective_date
9141              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
9142              --
9143              ,P_ACTY_BASE_RT_ID      => l_ACTY_BASE_RT_ID
9144              ,P_BNFT_POOL_RLOVR_RQMT_ID      => l_bnft_pool_rlovr_rqmt_id
9145              ,P_BNFT_PRVDR_POOL_ID      => l_BNFT_PRVDR_POOL_ID
9146              ,P_BPR_ATTRIBUTE1      => r_BPR.INFORMATION111
9147              ,P_BPR_ATTRIBUTE10      => r_BPR.INFORMATION120
9148              ,P_BPR_ATTRIBUTE11      => r_BPR.INFORMATION121
9149              ,P_BPR_ATTRIBUTE12      => r_BPR.INFORMATION122
9150              ,P_BPR_ATTRIBUTE13      => r_BPR.INFORMATION123
9151              ,P_BPR_ATTRIBUTE14      => r_BPR.INFORMATION124
9152              ,P_BPR_ATTRIBUTE15      => r_BPR.INFORMATION125
9153              ,P_BPR_ATTRIBUTE16      => r_BPR.INFORMATION126
9154              ,P_BPR_ATTRIBUTE17      => r_BPR.INFORMATION127
9155              ,P_BPR_ATTRIBUTE18      => r_BPR.INFORMATION128
9156              ,P_BPR_ATTRIBUTE19      => r_BPR.INFORMATION129
9157              ,P_BPR_ATTRIBUTE2      => r_BPR.INFORMATION112
9158              ,P_BPR_ATTRIBUTE20      => r_BPR.INFORMATION130
9159              ,P_BPR_ATTRIBUTE21      => r_BPR.INFORMATION131
9160              ,P_BPR_ATTRIBUTE22      => r_BPR.INFORMATION132
9161              ,P_BPR_ATTRIBUTE23      => r_BPR.INFORMATION133
9162              ,P_BPR_ATTRIBUTE24      => r_BPR.INFORMATION134
9163              ,P_BPR_ATTRIBUTE25      => r_BPR.INFORMATION135
9164              ,P_BPR_ATTRIBUTE26      => r_BPR.INFORMATION136
9165              ,P_BPR_ATTRIBUTE27      => r_BPR.INFORMATION137
9166              ,P_BPR_ATTRIBUTE28      => r_BPR.INFORMATION138
9167              ,P_BPR_ATTRIBUTE29      => r_BPR.INFORMATION139
9168              ,P_BPR_ATTRIBUTE3      => r_BPR.INFORMATION113
9169              ,P_BPR_ATTRIBUTE30      => r_BPR.INFORMATION140
9170              ,P_BPR_ATTRIBUTE4      => r_BPR.INFORMATION114
9171              ,P_BPR_ATTRIBUTE5      => r_BPR.INFORMATION115
9172              ,P_BPR_ATTRIBUTE6      => r_BPR.INFORMATION116
9173              ,P_BPR_ATTRIBUTE7      => r_BPR.INFORMATION117
9174              ,P_BPR_ATTRIBUTE8      => r_BPR.INFORMATION118
9175              ,P_BPR_ATTRIBUTE9      => r_BPR.INFORMATION119
9176              ,P_BPR_ATTRIBUTE_CATEGORY      => r_BPR.INFORMATION110
9177              ,P_CRS_RLOVR_PROCG_CD      => r_BPR.INFORMATION11
9178              ,P_MN_RLOVR_PCT_NUM      => r_BPR.INFORMATION258
9179              ,P_MN_RLOVR_VAL      => r_BPR.INFORMATION293
9180              ,P_MX_PCT_TTL_CRS_CN_ROLL_NUM      => r_BPR.INFORMATION261
9181              ,P_MX_RCHD_DFLT_ORDR_NUM      => r_BPR.INFORMATION270
9182              ,P_MX_RLOVR_PCT_NUM      => r_BPR.INFORMATION259
9183              ,P_MX_RLOVR_VAL      => r_BPR.INFORMATION294
9184              ,P_NO_MN_RLOVR_PCT_DFND_FLAG      => r_BPR.INFORMATION12
9185              ,P_NO_MN_RLOVR_VAL_DFND_FLAG      => r_BPR.INFORMATION14
9186              ,P_NO_MX_RLOVR_PCT_DFND_FLAG      => r_BPR.INFORMATION13
9187              ,P_NO_MX_RLOVR_VAL_DFND_FLAG      => r_BPR.INFORMATION15
9188              ,P_PCT_RLOVR_INCRMT_NUM      => r_BPR.INFORMATION257
9189              ,P_PCT_RNDG_CD      => r_BPR.INFORMATION17
9190              ,P_PCT_RNDG_RL      => l_PCT_RNDG_RL
9191              ,P_PRTT_ELIG_RLOVR_RL      => l_PRTT_ELIG_RLOVR_RL
9192              ,P_RLOVR_VAL_INCRMT_NUM      => r_BPR.INFORMATION268
9193              ,P_RLOVR_VAL_RL      => l_RLOVR_VAL_RL
9194              ,P_VAL_RNDG_CD      => r_BPR.INFORMATION16
9195              ,P_VAL_RNDG_RL      => l_VAL_RNDG_RL
9196              --
9197              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
9198              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
9199              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
9200            );
9201            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
9202            -- Update all relevent cer records with new pk_id
9203            hr_utility.set_location('Before plsql table ',222);
9204            hr_utility.set_location('new_value id '||l_bnft_pool_rlovr_rqmt_id,222);
9205            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'BNFT_POOL_RLOVR_RQMT_ID' ;
9206            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_BPR.information1 ;
9207            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_BNFT_POOL_RLOVR_RQMT_ID ;
9208            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
9209            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_BPR_unique.table_route_id;
9210            hr_utility.set_location('After plsql table ',222);
9211            --
9212            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
9213            --
9214            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
9215            --
9216          else
9217            --
9218            -- Call Update routine for the pk_id created in prev run .
9219            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
9220            hr_utility.set_location(' BEN_BNFT_POOL_RLOVR_RQMT_F UPDATE_BNFT_POOL_RLOVR_RQMT ',30);
9221            --UPD START
9222            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
9223            --
9224            if l_update then
9225              --
9226              l_datetrack_mode := r_BPR.datetrack_mode ;
9227              --
9228              get_dt_modes(
9229                p_effective_date        => l_process_date,
9230                p_effective_end_date    => r_BPR.information3,
9231                p_effective_start_date  => r_BPR.information2,
9232                p_dml_operation         => r_BPR.dml_operation,
9233                p_datetrack_mode        => l_datetrack_mode );
9234            --    p_update                => l_update
9235              --
9236              l_effective_date := l_process_date;
9237              l_bnft_pool_rlovr_rqmt_id  := r_BPR.information1;
9238              l_object_version_number := r_BPR.information265;
9239              --
9240            end if;
9241            --
9242            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
9243            --
9244            IF l_update OR l_dml_operation <> 'UPDATE' THEN
9245            --UPD END
9246                    BEN_BNFT_POOL_RLOVR_RQMT_API.UPDATE_BNFT_POOL_RLOVR_RQMT(
9247                      --
9248                       P_VALIDATE               => false
9249                      ,P_EFFECTIVE_DATE        => l_effective_date
9250                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
9251                      --
9252                      ,P_ACTY_BASE_RT_ID      => l_ACTY_BASE_RT_ID
9253                      ,P_BNFT_POOL_RLOVR_RQMT_ID      => l_bnft_pool_rlovr_rqmt_id
9254                      ,P_BNFT_PRVDR_POOL_ID      => l_BNFT_PRVDR_POOL_ID
9255                      ,P_BPR_ATTRIBUTE1      => r_BPR.INFORMATION111
9256                      ,P_BPR_ATTRIBUTE10      => r_BPR.INFORMATION120
9257                      ,P_BPR_ATTRIBUTE11      => r_BPR.INFORMATION121
9258                      ,P_BPR_ATTRIBUTE12      => r_BPR.INFORMATION122
9259                      ,P_BPR_ATTRIBUTE13      => r_BPR.INFORMATION123
9260                      ,P_BPR_ATTRIBUTE14      => r_BPR.INFORMATION124
9261                      ,P_BPR_ATTRIBUTE15      => r_BPR.INFORMATION125
9262                      ,P_BPR_ATTRIBUTE16      => r_BPR.INFORMATION126
9263                      ,P_BPR_ATTRIBUTE17      => r_BPR.INFORMATION127
9264                      ,P_BPR_ATTRIBUTE18      => r_BPR.INFORMATION128
9265                      ,P_BPR_ATTRIBUTE19      => r_BPR.INFORMATION129
9266                      ,P_BPR_ATTRIBUTE2      => r_BPR.INFORMATION112
9267                      ,P_BPR_ATTRIBUTE20      => r_BPR.INFORMATION130
9268                      ,P_BPR_ATTRIBUTE21      => r_BPR.INFORMATION131
9269                      ,P_BPR_ATTRIBUTE22      => r_BPR.INFORMATION132
9270                      ,P_BPR_ATTRIBUTE23      => r_BPR.INFORMATION133
9271                      ,P_BPR_ATTRIBUTE24      => r_BPR.INFORMATION134
9272                      ,P_BPR_ATTRIBUTE25      => r_BPR.INFORMATION135
9273                      ,P_BPR_ATTRIBUTE26      => r_BPR.INFORMATION136
9274                      ,P_BPR_ATTRIBUTE27      => r_BPR.INFORMATION137
9275                      ,P_BPR_ATTRIBUTE28      => r_BPR.INFORMATION138
9276                      ,P_BPR_ATTRIBUTE29      => r_BPR.INFORMATION139
9277                      ,P_BPR_ATTRIBUTE3      => r_BPR.INFORMATION113
9278                      ,P_BPR_ATTRIBUTE30      => r_BPR.INFORMATION140
9279                      ,P_BPR_ATTRIBUTE4      => r_BPR.INFORMATION114
9280                      ,P_BPR_ATTRIBUTE5      => r_BPR.INFORMATION115
9281                      ,P_BPR_ATTRIBUTE6      => r_BPR.INFORMATION116
9282                      ,P_BPR_ATTRIBUTE7      => r_BPR.INFORMATION117
9283                      ,P_BPR_ATTRIBUTE8      => r_BPR.INFORMATION118
9284                      ,P_BPR_ATTRIBUTE9      => r_BPR.INFORMATION119
9285                      ,P_BPR_ATTRIBUTE_CATEGORY      => r_BPR.INFORMATION110
9286                      ,P_CRS_RLOVR_PROCG_CD      => r_BPR.INFORMATION11
9287                      ,P_MN_RLOVR_PCT_NUM      => r_BPR.INFORMATION258
9288                      ,P_MN_RLOVR_VAL      => r_BPR.INFORMATION293
9289                      ,P_MX_PCT_TTL_CRS_CN_ROLL_NUM      => r_BPR.INFORMATION261
9290                      ,P_MX_RCHD_DFLT_ORDR_NUM      => r_BPR.INFORMATION270
9291                      ,P_MX_RLOVR_PCT_NUM      => r_BPR.INFORMATION259
9292                      ,P_MX_RLOVR_VAL      => r_BPR.INFORMATION294
9293                      ,P_NO_MN_RLOVR_PCT_DFND_FLAG      => r_BPR.INFORMATION12
9294                      ,P_NO_MN_RLOVR_VAL_DFND_FLAG      => r_BPR.INFORMATION14
9295                      ,P_NO_MX_RLOVR_PCT_DFND_FLAG      => r_BPR.INFORMATION13
9296                      ,P_NO_MX_RLOVR_VAL_DFND_FLAG      => r_BPR.INFORMATION15
9297                      ,P_PCT_RLOVR_INCRMT_NUM      => r_BPR.INFORMATION257
9298                      ,P_PCT_RNDG_CD      => r_BPR.INFORMATION17
9299                      ,P_PCT_RNDG_RL      => l_PCT_RNDG_RL
9300                      ,P_PRTT_ELIG_RLOVR_RL      => l_PRTT_ELIG_RLOVR_RL
9301                      ,P_RLOVR_VAL_INCRMT_NUM      => r_BPR.INFORMATION268
9302                      ,P_RLOVR_VAL_RL      => l_RLOVR_VAL_RL
9303                      ,P_VAL_RNDG_CD      => r_BPR.INFORMATION16
9304                      ,P_VAL_RNDG_RL      => l_VAL_RNDG_RL
9305                      --
9306                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
9307                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
9308                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
9309                      -- upd start
9310                      --,P_DATETRACK_MODE        => hr_api.g_update
9311                      ,P_DATETRACK_MODE        => l_datetrack_mode
9312                      -- upd end
9313                    );
9314               end if;  -- l_update
9315          end if;
9316          --
9317          --
9318          -- Delete the row if it is end dated.
9319          --
9320          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
9321              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
9322            trunc(l_max_eed) = r_BPR.information3) then
9323              --
9324              BEN_BNFT_POOL_RLOVR_RQMT_API.delete_BNFT_POOL_RLOVR_RQMT(
9325                 --
9326                 p_validate                       => false
9327                 ,p_bnft_pool_rlovr_rqmt_id                   => l_bnft_pool_rlovr_rqmt_id
9328                 ,p_effective_start_date           => l_effective_start_date
9329                 ,p_effective_end_date             => l_effective_end_date
9330                 ,p_object_version_number          => l_object_version_number
9331                 ,p_effective_date                 => l_max_eed
9332                 ,p_datetrack_mode                 => hr_api.g_delete
9333                 --
9334                 );
9335                 --
9336          end if;
9337          --
9338          l_prev_pk_id := l_current_pk_id ;
9339          --
9340        end if;
9341        --
9342      end if;
9343      --
9344    end loop;
9345    --
9346  exception when others then
9347      --
9348      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'BPR',r_BPR.information5 ) ;
9349      --
9350  end create_BPR_rows;
9351 
9352    --
9353    --
9354    ---------------------------------------------------------------
9355    ----------------------< create_DCR_rows >-----------------------
9356    ---------------------------------------------------------------
9357    --
9358    procedure create_DCR_rows
9359    (
9360          p_validate                       in  number     default 0
9361         ,p_copy_entity_txn_id             in  number
9362         ,p_effective_date                 in  date
9363         ,p_prefix_suffix_text             in  varchar2  default null
9364         ,p_reuse_object_flag              in  varchar2  default null
9365         ,p_target_business_group_id       in  varchar2  default null
9366         ,p_prefix_suffix_cd               in  varchar2  default null
9367    ) is
9368    --
9369    l_CVG_STRT_DT_RL  number;
9370    l_CVG_THRU_DT_RL  number;
9371    l_DPNT_CVG_ELIGY_PRFL_ID  number;
9372    l_PER_RELSHP_TYP_CD ben_dpnt_cvg_rqd_rlshp_f.per_relshp_typ_cd%type;
9373    cursor c_unique_DCR(l_table_alias varchar2) is
9374    select distinct cpe.information1,
9375      cpe.information2,
9376      cpe.information3,
9377      cpe.table_route_id,
9378      cpe.dml_operation,
9379      cpe.datetrack_mode
9380    from ben_copy_entity_results cpe,
9381         pqh_table_route tr
9382    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
9383    and   cpe.table_route_id     = tr.table_route_id
9384    -- and   tr.where_clause        = l_BEN_DPNT_CVG_RQD_RLSHP_F
9385    and   tr.table_alias = l_table_alias
9386    and   cpe.number_of_copies   = 1 -- ADDITION
9387    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
9388    order by information1, information2; --added for bug: 5151945
9389    --
9390    --
9391    cursor c_DCR_min_max_dates(c_table_route_id  number,
9392                 c_information1   number) is
9393    select
9394      min(cpe.information2) min_esd,
9395      max(cpe.information3) min_eed
9396    from ben_copy_entity_results cpe
9397    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
9398    and   cpe.table_route_id     = c_table_route_id
9399    and   cpe.information1       = c_information1 ;
9400    --
9401    cursor c_DCR(c_table_route_id  number,
9402                 c_information1   number,
9403                 c_information2   date,
9404                 c_information3   date)  is
9405    select
9406      cpe.*
9407    from ben_copy_entity_results cpe
9408    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
9409    and   cpe.table_route_id     = c_table_route_id
9410    and   cpe.information1       = c_information1
9411    and   cpe.information2       = c_information2
9412    and   cpe.information3       = c_information3
9413    and rownum = 1 ;
9414    -- Date Track target record
9415    cursor c_find_DCR_in_target(
9416                                 c_effective_start_date    date,
9417                                 c_effective_end_date      date,
9418                                 c_business_group_id       number,
9419                                 c_new_pk_id               number) is
9420    select
9421      DCR.dpnt_cvg_rqd_rlshp_id new_value
9422    from BEN_DPNT_CVG_RQD_RLSHP_F DCR
9423    where
9424    DCR.DPNT_CVG_ELIGY_PRFL_ID     = l_DPNT_CVG_ELIGY_PRFL_ID  and
9425    DCR.PER_RELSHP_TYP_CD          = l_PER_RELSHP_TYP_CD and
9426    DCR.business_group_id  = c_business_group_id
9427    and   DCR.dpnt_cvg_rqd_rlshp_id  <> c_new_pk_id
9428 --TEMPIK
9429    and c_effective_start_date between effective_start_date
9430                             and effective_end_date ;
9431 --END TEMPIK
9432 /*TEMPIK
9433    and exists ( select null
9434                 from BEN_DPNT_CVG_RQD_RLSHP_F DCR1
9435                 where
9436                 DCR1.DPNT_CVG_ELIGY_PRFL_ID     = l_DPNT_CVG_ELIGY_PRFL_ID  and
9437                 DCR1.PER_RELSHP_TYP_CD          = l_PER_RELSHP_TYP_CD and
9438                 DCR1.business_group_id  = c_business_group_id
9439                 and   DCR1.effective_start_date <= c_effective_start_date )
9440    and exists ( select null
9441                 from BEN_DPNT_CVG_RQD_RLSHP_F DCR2
9442                 where
9443                 DCR2.DPNT_CVG_ELIGY_PRFL_ID     = l_DPNT_CVG_ELIGY_PRFL_ID  and
9444                 DCR2.PER_RELSHP_TYP_CD          = l_PER_RELSHP_TYP_CD and
9445                 DCR2.business_group_id  = c_business_group_id
9446                 and   DCR2.effective_end_date >= c_effective_end_date )
9447                 ;
9448 TEMPIK */
9449    --TEMPIK
9450    l_dt_rec_found            boolean ;
9451    --END TEMPIK
9452    --
9453    --UPD START
9454    --
9455    l_update                  boolean      := false ;
9456    l_datetrack_mode          varchar2(80) := hr_api.g_update;
9457    l_process_date            date;
9458    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
9459    --
9460    --UPD END
9461    --
9462    l_current_pk_id           number := null ;
9463    l_prev_pk_id              number := null ;
9464    l_first_rec               boolean := true ;
9465    r_DCR                     c_DCR%rowtype;
9466    l_dpnt_cvg_rqd_rlshp_id             number ;
9467    l_object_version_number   number ;
9468    l_effective_start_date    date ;
9469    l_effective_end_date      date ;
9470    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
9471    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
9472    l_new_value               number(15);
9473    l_object_found_in_target  boolean := false ;
9474    l_min_esd                 date;
9475    l_max_eed                 date;
9476    l_effective_date          date;
9477    --
9478  begin
9479    -- Initialization
9480    l_object_found_in_target := false ;
9481    -- End Initialization
9482    -- Derive the prefix - sufix
9483    if   p_prefix_suffix_cd = 'PREFIX' then
9484      l_prefix  := p_prefix_suffix_text ;
9485    elsif p_prefix_suffix_cd = 'SUFFIX' then
9486      l_suffix   := p_prefix_suffix_text ;
9487    else
9488      l_prefix := null ;
9489      l_suffix  := null ;
9490    end if ;
9491    -- End Prefix Sufix derivation
9492    for r_DCR_unique in c_unique_DCR('DCR') loop
9493 
9494      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
9495         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
9496          r_DCR_unique.information3 >=
9497                  ben_pd_copy_to_ben_one.g_copy_effective_date)
9498         ) then
9499        --
9500        hr_utility.set_location(' r_DCR_unique.table_route_id '||r_DCR_unique.table_route_id,10);
9501        hr_utility.set_location(' r_DCR_unique.information1 '||r_DCR_unique.information1,10);
9502        hr_utility.set_location( 'r_DCR_unique.information2 '||r_DCR_unique.information2,10);
9503        hr_utility.set_location( 'r_DCR_unique.information3 '||r_DCR_unique.information3,10);
9504        -- If reuse objects flag is 'Y' then check for the object in the target business group
9505        -- if found insert the record into PLSql table and exit the loop else try create the
9506        -- object in the target business group
9507        --
9508        l_object_found_in_target := false ;
9509        --
9510        --UPD START
9511        l_update := false;
9512        l_process_date := p_effective_date;
9513        l_dml_operation:= r_DCR_unique.dml_operation ;
9514        --
9515        open c_DCR(r_DCR_unique.table_route_id,
9516                 r_DCR_unique.information1,
9517                 r_DCR_unique.information2,
9518                 r_DCR_unique.information3 ) ;
9519        --
9520        fetch c_DCR into r_DCR ;
9521        --
9522        close c_DCR ;
9523        l_CVG_STRT_DT_RL := get_fk('FORMULA_ID', r_DCR.information258,r_DCR.dml_operation);
9524        l_CVG_THRU_DT_RL := get_fk('FORMULA_ID', r_DCR.information257,r_DCR.dml_operation);
9525        l_DPNT_CVG_ELIGY_PRFL_ID := get_fk('DPNT_CVG_ELIGY_PRFL_ID', r_DCR.information255,r_DCR.dml_operation);
9526        l_PER_RELSHP_TYP_CD := r_DCR.information11;
9527        --
9528        if l_dml_operation = 'UPDATE' then
9529          --
9530                  l_object_found_in_target := TRUE;
9531                  --
9532                  if l_process_date between r_DCR_unique.information2 and r_DCR_unique.information3 then
9533                        l_update := true;
9534                        if r_DCR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
9535                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'DPNT_CVG_RQD_RLSHP_ID'
9536                        then
9537                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'DPNT_CVG_RQD_RLSHP_ID' ;
9538                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_DCR_unique.information1 ;
9539                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_DCR_unique.information1 ;
9540                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
9541                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_DCR_unique.table_route_id;
9542                           --
9543                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
9544                           --
9545                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
9546                           --
9547                           --BEN_PD_COPY_TO_BEN_ONE.log_data('DCR',l_new_value,l_prefix || r_DCR_unique.name|| l_suffix,'REUSED');
9548                           --
9549                        end if ;
9550                        hr_utility.set_location( 'found record for update',10);
9551                    --
9552                  else
9553                    --
9554                    l_update := false;
9555                    --
9556                  end if;
9557        else
9558        --
9559        --UPD END
9560        --
9561                l_min_esd := null ;
9562                l_max_eed := null ;
9563                open c_DCR_min_max_dates(r_DCR_unique.table_route_id, r_DCR_unique.information1 ) ;
9564                fetch c_DCR_min_max_dates into l_min_esd,l_max_eed ;
9565                --
9566 
9567                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
9568                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
9569                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
9570                end if;
9571                l_min_esd := greatest(l_min_esd,r_DCR_unique.information2);
9572 
9573                /*open c_DCR(r_DCR_unique.table_route_id,
9574                         r_DCR_unique.information1,
9575                         r_DCR_unique.information2,
9576                         r_DCR_unique.information3 ) ;
9577                --
9578                fetch c_DCR into r_DCR ;
9579                --
9580                close c_DCR ; */
9581                --
9582                if p_reuse_object_flag = 'Y' then
9583                  if c_DCR_min_max_dates%found then
9584                    -- cursor to find the object
9585                    open c_find_DCR_in_target( l_min_esd,l_max_eed,
9586                                          p_target_business_group_id, nvl(l_dpnt_cvg_rqd_rlshp_id, -999)  ) ;
9587                    fetch c_find_DCR_in_target into l_new_value ;
9588                    if c_find_DCR_in_target%found then
9589                      --
9590                      --TEMPIK
9591                      l_dt_rec_found :=   dt_api.check_min_max_dates
9592                          (p_base_table_name => 'BEN_DPNT_CVG_RQD_RLSHP_F',
9593                           p_base_key_column => 'DPNT_CVG_RQD_RLSHP_ID',
9594                           p_base_key_value  => l_new_value,
9595                           p_from_date       => l_min_esd,
9596                           p_to_date         => l_max_eed );
9597                      if l_dt_rec_found THEN
9598                      --END TEMPIK
9599                                          if r_DCR_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
9600                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'DPNT_CVG_RQD_RLSHP_ID'  then
9601                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'DPNT_CVG_RQD_RLSHP_ID' ;
9602                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_DCR_unique.information1 ;
9603                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
9604                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
9605                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_DCR_unique.table_route_id;
9606                                                 --
9607                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
9608                                                 --
9609                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
9610                                          end if ;
9611                                          --
9612                                          l_object_found_in_target := true ;
9613                      --TEMPIK
9614                      end if; -- l_dt_rec_found
9615                      --END TEMPIK
9616                    end if;
9617                    close c_find_DCR_in_target ;
9618                  --
9619                  end if;
9620                end if ;
9621                --
9622                close c_DCR_min_max_dates ;
9623 
9624        --if not l_object_found_in_target then
9625        end if; --if p_dml_operation
9626        --
9627        if not l_object_found_in_target OR l_update  then
9628          --
9629          l_current_pk_id := r_DCR.information1;
9630          --
9631          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
9632          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
9633          --
9634          if l_current_pk_id =  l_prev_pk_id  then
9635            --
9636            l_first_rec := false ;
9637            --
9638          else
9639            --
9640            l_first_rec := true ;
9641            --
9642          end if ;
9643          --
9644 
9645          l_effective_date := r_DCR.information2;
9646          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
9647               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
9648            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
9649          end if;
9650          -- UPD START
9651          --if l_first_rec then
9652          if l_first_rec and not l_update then
9653          -- UPD END
9654            -- Call Create routine.
9655            hr_utility.set_location(' BEN_DPNT_CVG_RQD_RLSHP_F CREATE_DPNT_CVG_RQD_RLSHP ',20);
9656            BEN_DPNT_CVG_RQD_RLSHP_API.CREATE_DPNT_CVG_RQD_RLSHP(
9657              --
9658              P_VALIDATE               => false
9659              ,P_EFFECTIVE_DATE        => l_effective_date
9660              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
9661              --
9662              ,P_CVG_STRT_DT_CD      => r_DCR.INFORMATION12
9663              ,P_CVG_STRT_DT_RL      => l_CVG_STRT_DT_RL
9664              ,P_CVG_THRU_DT_CD      => r_DCR.INFORMATION13
9665              ,P_CVG_THRU_DT_RL      => l_CVG_THRU_DT_RL
9666              ,P_DCR_ATTRIBUTE1      => r_DCR.INFORMATION111
9667              ,P_DCR_ATTRIBUTE10      => r_DCR.INFORMATION120
9668              ,P_DCR_ATTRIBUTE11      => r_DCR.INFORMATION121
9669              ,P_DCR_ATTRIBUTE12      => r_DCR.INFORMATION122
9670              ,P_DCR_ATTRIBUTE13      => r_DCR.INFORMATION123
9671              ,P_DCR_ATTRIBUTE14      => r_DCR.INFORMATION124
9672              ,P_DCR_ATTRIBUTE15      => r_DCR.INFORMATION125
9673              ,P_DCR_ATTRIBUTE16      => r_DCR.INFORMATION126
9674              ,P_DCR_ATTRIBUTE17      => r_DCR.INFORMATION127
9675              ,P_DCR_ATTRIBUTE18      => r_DCR.INFORMATION128
9676              ,P_DCR_ATTRIBUTE19      => r_DCR.INFORMATION129
9677              ,P_DCR_ATTRIBUTE2      => r_DCR.INFORMATION112
9678              ,P_DCR_ATTRIBUTE20      => r_DCR.INFORMATION130
9679              ,P_DCR_ATTRIBUTE21      => r_DCR.INFORMATION131
9680              ,P_DCR_ATTRIBUTE22      => r_DCR.INFORMATION132
9681              ,P_DCR_ATTRIBUTE23      => r_DCR.INFORMATION133
9682              ,P_DCR_ATTRIBUTE24      => r_DCR.INFORMATION134
9683              ,P_DCR_ATTRIBUTE25      => r_DCR.INFORMATION135
9684              ,P_DCR_ATTRIBUTE26      => r_DCR.INFORMATION136
9685              ,P_DCR_ATTRIBUTE27      => r_DCR.INFORMATION137
9686              ,P_DCR_ATTRIBUTE28      => r_DCR.INFORMATION138
9687              ,P_DCR_ATTRIBUTE29      => r_DCR.INFORMATION139
9688              ,P_DCR_ATTRIBUTE3      => r_DCR.INFORMATION113
9689              ,P_DCR_ATTRIBUTE30      => r_DCR.INFORMATION140
9690              ,P_DCR_ATTRIBUTE4      => r_DCR.INFORMATION114
9691              ,P_DCR_ATTRIBUTE5      => r_DCR.INFORMATION115
9692              ,P_DCR_ATTRIBUTE6      => r_DCR.INFORMATION116
9693              ,P_DCR_ATTRIBUTE7      => r_DCR.INFORMATION117
9694              ,P_DCR_ATTRIBUTE8      => r_DCR.INFORMATION118
9695              ,P_DCR_ATTRIBUTE9      => r_DCR.INFORMATION119
9696              ,P_DCR_ATTRIBUTE_CATEGORY      => r_DCR.INFORMATION110
9697              ,P_DPNT_CVG_ELIGY_PRFL_ID      => l_DPNT_CVG_ELIGY_PRFL_ID
9698              ,P_DPNT_CVG_RQD_RLSHP_ID      => l_dpnt_cvg_rqd_rlshp_id
9699              ,P_PER_RELSHP_TYP_CD      => r_DCR.INFORMATION11
9700              --
9701              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
9702              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
9703              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
9704            );
9705            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
9706            -- Update all relevent cer records with new pk_id
9707            hr_utility.set_location('Before plsql table ',222);
9708            hr_utility.set_location('new_value id '||l_dpnt_cvg_rqd_rlshp_id,222);
9709            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'DPNT_CVG_RQD_RLSHP_ID' ;
9710            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_DCR.information1 ;
9711            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_DPNT_CVG_RQD_RLSHP_ID ;
9712            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
9713            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_DCR_unique.table_route_id;
9714            hr_utility.set_location('After plsql table ',222);
9715            --
9716            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
9717            --
9718            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
9719            --
9720          else
9721            --
9722            -- Call Update routine for the pk_id created in prev run .
9723            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
9724            hr_utility.set_location(' BEN_DPNT_CVG_RQD_RLSHP_F UPDATE_DPNT_CVG_RQD_RLSHP ',30);
9725            --UPD START
9726            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
9727            --
9728            if l_update then
9729              --
9730              l_datetrack_mode := r_DCR.datetrack_mode ;
9731              --
9732              get_dt_modes(
9733                p_effective_date        => l_process_date,
9734                p_effective_end_date    => r_DCR.information3,
9735                p_effective_start_date  => r_DCR.information2,
9736                p_dml_operation         => r_DCR.dml_operation,
9737                p_datetrack_mode        => l_datetrack_mode );
9738            --    p_update                => l_update
9739              --
9740              l_effective_date := l_process_date;
9741              l_dpnt_cvg_rqd_rlshp_id   := r_DCR.information1;
9742              l_object_version_number := r_DCR.information265;
9743              --
9744            end if;
9745            --
9746            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
9747            --
9748            IF l_update OR l_dml_operation <> 'UPDATE' THEN
9749            --UPD END
9750 
9751                    BEN_DPNT_CVG_RQD_RLSHP_API.UPDATE_DPNT_CVG_RQD_RLSHP(
9752                      --
9753                      P_VALIDATE               => false
9754                      ,P_EFFECTIVE_DATE        => l_effective_date
9755                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
9756                      --
9757                      ,P_CVG_STRT_DT_CD      => r_DCR.INFORMATION12
9758                      ,P_CVG_STRT_DT_RL      => l_CVG_STRT_DT_RL
9759                      ,P_CVG_THRU_DT_CD      => r_DCR.INFORMATION13
9760                      ,P_CVG_THRU_DT_RL      => l_CVG_THRU_DT_RL
9761                      ,P_DCR_ATTRIBUTE1      => r_DCR.INFORMATION111
9762                      ,P_DCR_ATTRIBUTE10      => r_DCR.INFORMATION120
9763                      ,P_DCR_ATTRIBUTE11      => r_DCR.INFORMATION121
9764                      ,P_DCR_ATTRIBUTE12      => r_DCR.INFORMATION122
9765                      ,P_DCR_ATTRIBUTE13      => r_DCR.INFORMATION123
9766                      ,P_DCR_ATTRIBUTE14      => r_DCR.INFORMATION124
9767                      ,P_DCR_ATTRIBUTE15      => r_DCR.INFORMATION125
9768                      ,P_DCR_ATTRIBUTE16      => r_DCR.INFORMATION126
9769                      ,P_DCR_ATTRIBUTE17      => r_DCR.INFORMATION127
9770                      ,P_DCR_ATTRIBUTE18      => r_DCR.INFORMATION128
9771                      ,P_DCR_ATTRIBUTE19      => r_DCR.INFORMATION129
9772                      ,P_DCR_ATTRIBUTE2      => r_DCR.INFORMATION112
9773                      ,P_DCR_ATTRIBUTE20      => r_DCR.INFORMATION130
9774                      ,P_DCR_ATTRIBUTE21      => r_DCR.INFORMATION131
9775                      ,P_DCR_ATTRIBUTE22      => r_DCR.INFORMATION132
9776                      ,P_DCR_ATTRIBUTE23      => r_DCR.INFORMATION133
9777                      ,P_DCR_ATTRIBUTE24      => r_DCR.INFORMATION134
9778                      ,P_DCR_ATTRIBUTE25      => r_DCR.INFORMATION135
9779                      ,P_DCR_ATTRIBUTE26      => r_DCR.INFORMATION136
9780                      ,P_DCR_ATTRIBUTE27      => r_DCR.INFORMATION137
9781                      ,P_DCR_ATTRIBUTE28      => r_DCR.INFORMATION138
9782                      ,P_DCR_ATTRIBUTE29      => r_DCR.INFORMATION139
9783                      ,P_DCR_ATTRIBUTE3      => r_DCR.INFORMATION113
9784                      ,P_DCR_ATTRIBUTE30      => r_DCR.INFORMATION140
9785                      ,P_DCR_ATTRIBUTE4      => r_DCR.INFORMATION114
9786                      ,P_DCR_ATTRIBUTE5      => r_DCR.INFORMATION115
9787                      ,P_DCR_ATTRIBUTE6      => r_DCR.INFORMATION116
9788                      ,P_DCR_ATTRIBUTE7      => r_DCR.INFORMATION117
9789                      ,P_DCR_ATTRIBUTE8      => r_DCR.INFORMATION118
9790                      ,P_DCR_ATTRIBUTE9      => r_DCR.INFORMATION119
9791                      ,P_DCR_ATTRIBUTE_CATEGORY      => r_DCR.INFORMATION110
9792                      ,P_DPNT_CVG_ELIGY_PRFL_ID      => l_DPNT_CVG_ELIGY_PRFL_ID
9793                      ,P_DPNT_CVG_RQD_RLSHP_ID      => l_dpnt_cvg_rqd_rlshp_id
9794                      ,P_PER_RELSHP_TYP_CD      => r_DCR.INFORMATION11
9795                      --
9796                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
9797                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
9798                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
9799                      --,P_DATETRACK_MODE        => hr_api.g_update
9800                      ,P_DATETRACK_MODE        => l_datetrack_mode
9801                    );
9802            end if;  -- l_update
9803          end if;
9804          --
9805          --
9806          -- Delete the row if it is end dated.
9807          --
9808          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
9809              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
9810              trunc(l_max_eed) = r_DCR.information3) then
9811              --
9812              BEN_DPNT_CVG_RQD_RLSHP_API.delete_DPNT_CVG_RQD_RLSHP(
9813                 --
9814                 p_validate                       => false
9815                 ,p_dpnt_cvg_rqd_rlshp_id                   => l_dpnt_cvg_rqd_rlshp_id
9816                 ,p_effective_start_date           => l_effective_start_date
9817                 ,p_effective_end_date             => l_effective_end_date
9818                 ,p_object_version_number          => l_object_version_number
9819                 ,p_effective_date                 => l_max_eed
9820                 ,p_datetrack_mode                 => hr_api.g_delete
9821                 --
9822                 );
9823                 --
9824          end if;
9825          --
9826          l_prev_pk_id := l_current_pk_id ;
9827          --
9828        end if;
9829        --
9830      end if;
9831      --
9832    end loop;
9833    --
9834  exception when others then
9835      --
9836      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'DCR',r_DCR.information5 ) ;
9837      --
9838  end create_DCR_rows;
9839 
9840  --
9841     --
9842    ---------------------------------------------------------------
9843    ----------------------< create_DEC_rows >-----------------------
9844    ---------------------------------------------------------------
9845    --
9846    procedure create_DEC_rows
9847    (
9848          p_validate                       in  number     default 0
9849         ,p_copy_entity_txn_id             in  number
9850         ,p_effective_date                 in  date
9851         ,p_prefix_suffix_text             in  varchar2  default null
9852         ,p_reuse_object_flag              in  varchar2  default null
9853         ,p_target_business_group_id       in  varchar2  default null
9854         ,p_prefix_suffix_cd               in  varchar2  default null
9855    ) is
9856    --
9857    l_DPNT_CVG_ELIGY_PRFL_ID  number;
9858    l_DSGNTR_CRNTLY_ENRLD_FLAG ben_dsgntr_enrld_cvg_f.dsgntr_crntly_enrld_flag%type;
9859    cursor c_unique_DEC(l_table_alias varchar2) is
9860    select distinct cpe.information1,
9861      cpe.information2,
9862      cpe.information3,
9863      cpe.table_route_id,
9864      cpe.dml_operation,
9865      cpe.datetrack_mode
9866    from ben_copy_entity_results cpe,
9867         pqh_table_route tr
9868    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
9869    and   cpe.table_route_id     = tr.table_route_id
9870    -- and   tr.where_clause        = l_BEN_DSGNTR_ENRLD_CVG_F
9871    and   tr.table_alias = l_table_alias
9872    and   cpe.number_of_copies   = 1 -- ADDITION
9873    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
9874    order by information1, information2; --added for bug: 5151945
9875    --
9876    --
9877    cursor c_DEC_min_max_dates(c_table_route_id  number,
9878                 c_information1   NUMBER) is
9879    select
9880      min(cpe.information2) min_esd,
9881      max(cpe.information3) min_eed
9882    from ben_copy_entity_results cpe
9883    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
9884    and   cpe.table_route_id     = c_table_route_id
9885    and   cpe.information1       = c_information1 ;
9886    --
9887    cursor c_DEC(c_table_route_id  number,
9888                 c_information1   number,
9889                 c_information2   date,
9890                 c_information3   date)  is
9891    select
9892      cpe.*
9893    from ben_copy_entity_results cpe
9894    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
9895    and   cpe.table_route_id     = c_table_route_id
9896    and   cpe.information1       = c_information1
9897    and   cpe.information2       = c_information2
9898    and   cpe.information3       = c_information3
9899    and rownum = 1 ;
9900    -- Date Track target record
9901    cursor c_find_DEC_in_target(
9902                                 c_effective_start_date    date,
9903                                 c_effective_end_date      date,
9904                                 c_business_group_id       number,
9905                                 c_new_pk_id               number) is
9906    select
9907      DEC.dsgntr_enrld_cvg_id new_value
9908    from BEN_DSGNTR_ENRLD_CVG_F DEC
9909    where
9910    nvl(DEC.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
9911    DEC.DSGNTR_CRNTLY_ENRLD_FLAG             = l_DSGNTR_CRNTLY_ENRLD_FLAG and
9912    DEC.business_group_id  = c_business_group_id
9913    and   DEC.dsgntr_enrld_cvg_id  <> c_new_pk_id
9914 --TEMPIK
9915    and c_effective_start_date between effective_start_date
9916                             and effective_end_date ;
9917 --END TEMPIK
9918 /*TEMPIK
9919    and exists ( select null
9920                 from BEN_DSGNTR_ENRLD_CVG_F DEC1
9921                 where
9922                 nvl(DEC1.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
9923                 DEC1.DSGNTR_CRNTLY_ENRLD_FLAG             = l_DSGNTR_CRNTLY_ENRLD_FLAG and
9924                 DEC1.business_group_id  = c_business_group_id
9925                 and   DEC1.effective_start_date <= c_effective_start_date )
9926    and exists ( select null
9927                 from BEN_DSGNTR_ENRLD_CVG_F DEC2
9928                 where
9929                 nvl(DEC2.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
9930                 DEC2.DSGNTR_CRNTLY_ENRLD_FLAG             = l_DSGNTR_CRNTLY_ENRLD_FLAG and
9931                 DEC2.business_group_id  = c_business_group_id
9932                 and   DEC2.effective_end_date >= c_effective_end_date )
9933                 ;
9934 TEMPIK */
9935    --TEMPIK
9936    l_dt_rec_found            boolean ;
9937    --END TEMPIK
9938    --
9939    --UPD START
9940    --
9941    l_update                  boolean      := false ;
9942    l_datetrack_mode          varchar2(80) := hr_api.g_update;
9943    l_process_date            date;
9944    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
9945    --
9946    --UPD END
9947    --
9948    l_current_pk_id           number := null ;
9949    l_prev_pk_id              number := null ;
9950    l_first_rec               boolean := true ;
9951    r_DEC                     c_DEC%rowtype;
9952    l_dsgntr_enrld_cvg_id             number ;
9953    l_object_version_number   number ;
9954    l_effective_start_date    date ;
9955    l_effective_end_date      date ;
9956    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
9957    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
9958    l_new_value               number(15);
9959    l_object_found_in_target  boolean := false ;
9960    l_min_esd                 date;
9961    l_max_eed                 date;
9962    l_effective_date          date;
9963    --
9964  begin
9965    -- Initialization
9966    l_object_found_in_target := false ;
9967    -- End Initialization
9968    -- Derive the prefix - sufix
9969    if   p_prefix_suffix_cd = 'PREFIX' then
9970      l_prefix  := p_prefix_suffix_text ;
9971    elsif p_prefix_suffix_cd = 'SUFFIX' then
9972      l_suffix   := p_prefix_suffix_text ;
9973    else
9974      l_prefix := null ;
9975      l_suffix  := null ;
9976    end if ;
9977    -- End Prefix Sufix derivation
9978    for r_DEC_unique in c_unique_DEC('DEC') loop
9979 
9980      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
9981         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
9982          r_DEC_unique.information3 >=
9983                  ben_pd_copy_to_ben_one.g_copy_effective_date)
9984         ) then
9985        --
9986        hr_utility.set_location(' r_DEC_unique.table_route_id '||r_DEC_unique.table_route_id,10);
9987        hr_utility.set_location(' r_DEC_unique.information1 '||r_DEC_unique.information1,10);
9988        hr_utility.set_location( 'r_DEC_unique.information2 '||r_DEC_unique.information2,10);
9989        hr_utility.set_location( 'r_DEC_unique.information3 '||r_DEC_unique.information3,10);
9990        -- If reuse objects flag is 'Y' then check for the object in the target business group
9991        -- if found insert the record into PLSql table and exit the loop else try create the
9992        -- object in the target business group
9993        --
9994        l_object_found_in_target := false ;
9995        --UPD START
9996        l_update := false;
9997        l_process_date := p_effective_date;
9998        l_dml_operation:= r_DEC_unique.dml_operation ;
9999        --
10000        open c_DEC(r_DEC_unique.table_route_id,
10001                    r_DEC_unique.information1,
10002                         r_DEC_unique.information2,
10003                         r_DEC_unique.information3 ) ;
10004        --
10005        fetch c_DEC into r_DEC ;
10006        --
10007        close c_DEC ;
10008        l_DPNT_CVG_ELIGY_PRFL_ID := get_fk('DPNT_CVG_ELIGY_PRFL_ID', r_DEC.information255,r_DEC.dml_operation);
10009        l_DSGNTR_CRNTLY_ENRLD_FLAG := r_DEC.information11;
10010        --
10011        if l_dml_operation = 'UPDATE' then
10012          --
10013                  l_object_found_in_target := TRUE;
10014                  --
10015                  if l_process_date between r_DEC_unique.information2 and r_DEC_unique.information3 then
10016                        l_update := true;
10017                        if r_DEC_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
10018                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'DSGNTR_ENRLD_CVG_ID'
10019                        then
10020                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'DSGNTR_ENRLD_CVG_ID' ;
10021                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_DEC_unique.information1 ;
10022                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_DEC_unique.information1 ;
10023                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
10024                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_DEC_unique.table_route_id;
10025                           --
10026                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
10027                           --
10028                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
10029                           --
10030                           --BEN_PD_COPY_TO_BEN_ONE.log_data('DEC',l_new_value,l_prefix || r_DEC_unique.name|| l_suffix,'REUSED');
10031                           --
10032                        end if ;
10033                        hr_utility.set_location( 'found record for update',10);
10034                    --
10035                  else
10036                    --
10037                    l_update := false;
10038                    --
10039                  end if;
10040        --
10041        else
10042          --
10043          --UPD END
10044                l_min_esd := null ;
10045                l_max_eed := null ;
10046                open c_DEC_min_max_dates(r_DEC_unique.table_route_id, r_DEC_unique.information1 ) ;
10047                fetch c_DEC_min_max_dates into l_min_esd,l_max_eed ;
10048                --
10049 
10050                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
10051                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
10052                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
10053                end if;
10054                l_min_esd := greatest(l_min_esd,r_DEC_unique.information2);
10055                /*open c_DEC(r_DEC_unique.table_route_id,
10056                         r_DEC_unique.information1,
10057                         r_DEC_unique.information2,
10058                         r_DEC_unique.information3 ) ;
10059                --
10060                fetch c_DEC into r_DEC ;
10061                --
10062                close c_DEC ;*/
10063                --
10064                if p_reuse_object_flag = 'Y' then
10065                  if c_DEC_min_max_dates%found then
10066                    -- cursor to find the object
10067                    open c_find_DEC_in_target( l_min_esd,l_max_eed,
10068                                          p_target_business_group_id, nvl(l_dsgntr_enrld_cvg_id, -999)  ) ;
10069                    fetch c_find_DEC_in_target into l_new_value ;
10070                    if c_find_DEC_in_target%found then
10071                      --
10072                      --TEMPIK
10073                      l_dt_rec_found :=   dt_api.check_min_max_dates
10074                          (p_base_table_name => 'BEN_DSGNTR_ENRLD_CVG_F',
10075                           p_base_key_column => 'DSGNTR_ENRLD_CVG_ID',
10076                           p_base_key_value  => l_new_value,
10077                           p_from_date       => l_min_esd,
10078                           p_to_date         => l_max_eed );
10079                      if l_dt_rec_found THEN
10080                      --END TEMPIK
10081                                          if r_DEC_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
10082                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'DSGNTR_ENRLD_CVG_ID'  then
10083                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'DSGNTR_ENRLD_CVG_ID' ;
10084                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_DEC_unique.information1 ;
10085                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
10086                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
10087                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_DEC_unique.table_route_id;
10088                                                 --
10089                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
10090                                                 --
10091                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
10092                                          end if ;
10093                                          --
10094                                          l_object_found_in_target := true ;
10095                      --TEMPIK
10096                      end if; -- l_dt_rec_found
10097                      --END TEMPIK
10098                    end if;
10099                    close c_find_DEC_in_target ;
10100                  --
10101                  end if;
10102                end if ;
10103                --
10104                close c_DEC_min_max_dates ;
10105 
10106        --if not l_object_found_in_target then
10107        end if; --if p_dml_operation
10108        --
10109        if not l_object_found_in_target OR l_update  then
10110 
10111          --
10112          l_current_pk_id := r_DEC.information1;
10113          --
10114          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
10115          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
10116          --
10117          if l_current_pk_id =  l_prev_pk_id  then
10118            --
10119            l_first_rec := false ;
10120            --
10121          else
10122            --
10123            l_first_rec := true ;
10124            --
10125          end if ;
10126          --
10127 
10128          l_effective_date := r_DEC.information2;
10129          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
10130               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
10131            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
10132          end if;
10133 
10134          --if l_first_rec then
10135          if l_first_rec and not l_update then
10136 
10137            -- Call Create routine.
10138            hr_utility.set_location(' BEN_DSGNTR_ENRLD_CVG_F CREATE_DSGNTR_ENRLD_CVG ',20);
10139            BEN_DSGNTR_ENRLD_CVG_API.CREATE_DSGNTR_ENRLD_CVG(
10140              --
10141              P_VALIDATE               => false
10142              ,P_EFFECTIVE_DATE        => l_effective_date
10143              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
10144              --
10145              ,P_DEC_ATTRIBUTE1      => r_DEC.INFORMATION111
10146              ,P_DEC_ATTRIBUTE10      => r_DEC.INFORMATION120
10147              ,P_DEC_ATTRIBUTE11      => r_DEC.INFORMATION121
10148              ,P_DEC_ATTRIBUTE12      => r_DEC.INFORMATION122
10149              ,P_DEC_ATTRIBUTE13      => r_DEC.INFORMATION123
10150              ,P_DEC_ATTRIBUTE14      => r_DEC.INFORMATION124
10151              ,P_DEC_ATTRIBUTE15      => r_DEC.INFORMATION125
10152              ,P_DEC_ATTRIBUTE16      => r_DEC.INFORMATION126
10153              ,P_DEC_ATTRIBUTE17      => r_DEC.INFORMATION127
10154              ,P_DEC_ATTRIBUTE18      => r_DEC.INFORMATION128
10155              ,P_DEC_ATTRIBUTE19      => r_DEC.INFORMATION129
10156              ,P_DEC_ATTRIBUTE2      => r_DEC.INFORMATION112
10157              ,P_DEC_ATTRIBUTE20      => r_DEC.INFORMATION130
10158              ,P_DEC_ATTRIBUTE21      => r_DEC.INFORMATION131
10159              ,P_DEC_ATTRIBUTE22      => r_DEC.INFORMATION132
10160              ,P_DEC_ATTRIBUTE23      => r_DEC.INFORMATION133
10161              ,P_DEC_ATTRIBUTE24      => r_DEC.INFORMATION134
10162              ,P_DEC_ATTRIBUTE25      => r_DEC.INFORMATION135
10163              ,P_DEC_ATTRIBUTE26      => r_DEC.INFORMATION136
10164              ,P_DEC_ATTRIBUTE27      => r_DEC.INFORMATION137
10165              ,P_DEC_ATTRIBUTE28      => r_DEC.INFORMATION138
10166              ,P_DEC_ATTRIBUTE29      => r_DEC.INFORMATION139
10167              ,P_DEC_ATTRIBUTE3      => r_DEC.INFORMATION113
10168              ,P_DEC_ATTRIBUTE30      => r_DEC.INFORMATION140
10169              ,P_DEC_ATTRIBUTE4      => r_DEC.INFORMATION114
10170              ,P_DEC_ATTRIBUTE5      => r_DEC.INFORMATION115
10171              ,P_DEC_ATTRIBUTE6      => r_DEC.INFORMATION116
10172              ,P_DEC_ATTRIBUTE7      => r_DEC.INFORMATION117
10173              ,P_DEC_ATTRIBUTE8      => r_DEC.INFORMATION118
10174              ,P_DEC_ATTRIBUTE9      => r_DEC.INFORMATION119
10175              ,P_DEC_ATTRIBUTE_CATEGORY      => r_DEC.INFORMATION110
10176              ,P_DPNT_CVG_ELIGY_PRFL_ID      => l_DPNT_CVG_ELIGY_PRFL_ID
10177              ,P_DSGNTR_CRNTLY_ENRLD_FLAG      => r_DEC.INFORMATION11
10178              ,P_DSGNTR_ENRLD_CVG_ID      => l_dsgntr_enrld_cvg_id
10179              --
10180              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
10181              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
10182              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
10183            );
10184            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
10185            -- Update all relevent cer records with new pk_id
10186            hr_utility.set_location('Before plsql table ',222);
10187            hr_utility.set_location('new_value id '||l_dsgntr_enrld_cvg_id,222);
10188            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'DSGNTR_ENRLD_CVG_ID' ;
10189            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_DEC.information1 ;
10190            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_DSGNTR_ENRLD_CVG_ID ;
10191            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
10192            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_DEC_unique.table_route_id;
10193            hr_utility.set_location('After plsql table ',222);
10194            --
10195            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
10196            --
10197            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
10198            --
10199          else
10200            --
10201            -- Call Update routine for the pk_id created in prev run .
10202            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
10203            hr_utility.set_location(' BEN_DSGNTR_ENRLD_CVG_F UPDATE_DSGNTR_ENRLD_CVG ',30);
10204             --UPD START
10205            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
10206            --
10207            if l_update then
10208              --
10209              l_datetrack_mode := r_DEC.datetrack_mode ;
10210              --
10211              get_dt_modes(
10212                p_effective_date        => l_process_date,
10213                p_effective_end_date    => r_DEC.information3,
10214                p_effective_start_date  => r_DEC.information2,
10215                p_dml_operation         => r_DEC.dml_operation,
10216                p_datetrack_mode        => l_datetrack_mode );
10217            --    p_update                => l_update
10218              --
10219              l_effective_date := l_process_date;
10220              l_dsgntr_enrld_cvg_id   := r_DEC.information1;
10221              l_object_version_number := r_DEC.information265;
10222              --
10223            end if;
10224            --
10225            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
10226            --
10227            IF l_update OR l_dml_operation <> 'UPDATE' THEN
10228            --UPD END
10229 
10230            BEN_DSGNTR_ENRLD_CVG_API.UPDATE_DSGNTR_ENRLD_CVG(
10231              --
10232              P_VALIDATE               => false
10233              ,P_EFFECTIVE_DATE        => l_effective_date
10234              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
10235              --
10236              ,P_DEC_ATTRIBUTE1      => r_DEC.INFORMATION111
10237              ,P_DEC_ATTRIBUTE10      => r_DEC.INFORMATION120
10238              ,P_DEC_ATTRIBUTE11      => r_DEC.INFORMATION121
10239              ,P_DEC_ATTRIBUTE12      => r_DEC.INFORMATION122
10240              ,P_DEC_ATTRIBUTE13      => r_DEC.INFORMATION123
10241              ,P_DEC_ATTRIBUTE14      => r_DEC.INFORMATION124
10242              ,P_DEC_ATTRIBUTE15      => r_DEC.INFORMATION125
10243              ,P_DEC_ATTRIBUTE16      => r_DEC.INFORMATION126
10244              ,P_DEC_ATTRIBUTE17      => r_DEC.INFORMATION127
10245              ,P_DEC_ATTRIBUTE18      => r_DEC.INFORMATION128
10246              ,P_DEC_ATTRIBUTE19      => r_DEC.INFORMATION129
10247              ,P_DEC_ATTRIBUTE2      => r_DEC.INFORMATION112
10248              ,P_DEC_ATTRIBUTE20      => r_DEC.INFORMATION130
10249              ,P_DEC_ATTRIBUTE21      => r_DEC.INFORMATION131
10250              ,P_DEC_ATTRIBUTE22      => r_DEC.INFORMATION132
10251              ,P_DEC_ATTRIBUTE23      => r_DEC.INFORMATION133
10252              ,P_DEC_ATTRIBUTE24      => r_DEC.INFORMATION134
10253              ,P_DEC_ATTRIBUTE25      => r_DEC.INFORMATION135
10254              ,P_DEC_ATTRIBUTE26      => r_DEC.INFORMATION136
10255              ,P_DEC_ATTRIBUTE27      => r_DEC.INFORMATION137
10256              ,P_DEC_ATTRIBUTE28      => r_DEC.INFORMATION138
10257              ,P_DEC_ATTRIBUTE29      => r_DEC.INFORMATION139
10258              ,P_DEC_ATTRIBUTE3      => r_DEC.INFORMATION113
10259              ,P_DEC_ATTRIBUTE30      => r_DEC.INFORMATION140
10260              ,P_DEC_ATTRIBUTE4      => r_DEC.INFORMATION114
10261              ,P_DEC_ATTRIBUTE5      => r_DEC.INFORMATION115
10262              ,P_DEC_ATTRIBUTE6      => r_DEC.INFORMATION116
10263              ,P_DEC_ATTRIBUTE7      => r_DEC.INFORMATION117
10264              ,P_DEC_ATTRIBUTE8      => r_DEC.INFORMATION118
10265              ,P_DEC_ATTRIBUTE9      => r_DEC.INFORMATION119
10266              ,P_DEC_ATTRIBUTE_CATEGORY      => r_DEC.INFORMATION110
10267              ,P_DPNT_CVG_ELIGY_PRFL_ID      => l_DPNT_CVG_ELIGY_PRFL_ID
10268              ,P_DSGNTR_CRNTLY_ENRLD_FLAG      => r_DEC.INFORMATION11
10269              ,P_DSGNTR_ENRLD_CVG_ID      => l_dsgntr_enrld_cvg_id
10270              --
10271              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
10272              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
10273              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
10274              ,P_DATETRACK_MODE        => l_datetrack_mode
10275              --,P_DATETRACK_MODE        => hr_api.g_update
10276            );
10277           end if;  -- l_update
10278          end if;
10279          --
10280          --
10281          -- Delete the row if it is end dated.
10282          --
10283          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
10284              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
10285              trunc(l_max_eed) = r_DEC.information3) then
10286              --
10287              BEN_DSGNTR_ENRLD_CVG_API.delete_DSGNTR_ENRLD_CVG(
10288                 --
10289                 p_validate                       => false
10290                 ,p_dsgntr_enrld_cvg_id                   => l_dsgntr_enrld_cvg_id
10291                 ,p_effective_start_date           => l_effective_start_date
10292                 ,p_effective_end_date             => l_effective_end_date
10293                 ,p_object_version_number          => l_object_version_number
10294                 ,p_effective_date                 => l_max_eed
10295                 ,p_datetrack_mode                 => hr_api.g_delete
10296                 --
10297                 );
10298                 --
10299          end if;
10300          --
10301          l_prev_pk_id := l_current_pk_id ;
10302          --
10303        end if;
10304        --
10305      end if;
10306      --
10307    end loop;
10308    --
10309  exception when others then
10310      --
10311      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'DEC',r_DEC.information5 ) ;
10312      --
10313  end create_DEC_rows;
10314    --
10315    ---------------------------------------------------------------
10316    ----------------------< create_DPC_rows >-----------------------
10317    ---------------------------------------------------------------
10318    --
10319    procedure create_DPC_rows
10320    (
10321          p_validate                       in  number     default 0
10322         ,p_copy_entity_txn_id             in  number
10323         ,p_effective_date                 in  date
10324         ,p_prefix_suffix_text             in  varchar2  default null
10325         ,p_reuse_object_flag              in  varchar2  default null
10326         ,p_target_business_group_id       in  varchar2  default null
10327         ,p_prefix_suffix_cd               in  varchar2  default null
10328    ) is
10329    --
10330    l_DPNT_CVG_ELIGY_PRFL_ID  number;
10331    l_PL_ID  number;
10332    cursor c_unique_DPC(l_table_alias varchar2) is
10333    select distinct cpe.information1,
10334      cpe.information2,
10335      cpe.information3,
10336      cpe.table_route_id,
10337      cpe.dml_operation,
10338      cpe.datetrack_mode
10339    from ben_copy_entity_results cpe,
10340         pqh_table_route tr
10341    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
10342    and   cpe.table_route_id     = tr.table_route_id
10343    -- and   tr.where_clause        = l_BEN_DPNT_CVRD_ANTHR_PL_CVG_F
10344    and   tr.table_alias = l_table_alias
10345    and   cpe.number_of_copies   = 1 -- ADDITION
10346    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
10347    order by information1, information2; --added for bug: 5151945
10348    --
10349    --
10350    cursor c_DPC_min_max_dates(c_table_route_id  number,
10351                 c_information1   number) is
10352    select
10353      min(cpe.information2) min_esd,
10354      max(cpe.information3) min_eed
10355    from ben_copy_entity_results cpe
10356    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
10357    and   cpe.table_route_id     = c_table_route_id
10358    and   cpe.information1       = c_information1 ;
10359    --
10360    cursor c_DPC(c_table_route_id  number,
10361                 c_information1   number,
10362                 c_information2   date,
10363                 c_information3   date)  is
10364    select
10365      cpe.*
10366    from ben_copy_entity_results cpe
10367    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
10368    and   cpe.table_route_id     = c_table_route_id
10369    and   cpe.information1       = c_information1
10370    and   cpe.information2       = c_information2
10371    and   cpe.information3       = c_information3
10372    and rownum = 1 ;
10373    -- Date Track target record
10374    cursor c_find_DPC_in_target(
10375                                 c_effective_start_date    date,
10376                                 c_effective_end_date      date,
10377                                 c_business_group_id       number,
10378                                 c_new_pk_id               number) is
10379    select
10380      DPC.dpnt_cvrd_anthr_pl_cvg_id new_value
10381    from BEN_DPNT_CVRD_ANTHR_PL_CVG_F DPC
10382    where
10383    nvl(DPC.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
10384    nvl(DPC.PL_ID,-999)     = nvl(l_PL_ID,-999)  and
10385    DPC.business_group_id  = c_business_group_id
10386    and   DPC.dpnt_cvrd_anthr_pl_cvg_id  <> c_new_pk_id
10387 --TEMPIK
10388    and c_effective_start_date between effective_start_date
10389                             and effective_end_date ;
10390 --END TEMPIK
10391 /*TEMPIK
10392    and exists ( select null
10393                 from BEN_DPNT_CVRD_ANTHR_PL_CVG_F DPC1
10394                 where
10395                 nvl(DPC1.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
10396                 nvl(DPC1.PL_ID,-999)     = nvl(l_PL_ID,-999)  and
10397                 DPC1.business_group_id  = c_business_group_id
10398                 and   DPC1.effective_start_date <= c_effective_start_date )
10399    and exists ( select null
10400                 from BEN_DPNT_CVRD_ANTHR_PL_CVG_F DPC2
10401                 where
10402                 nvl(DPC2.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
10403                 nvl(DPC2.PL_ID,-999)     = nvl(l_PL_ID,-999)  and
10404                 DPC2.business_group_id  = c_business_group_id
10405                 and   DPC2.effective_end_date >= c_effective_end_date )
10406                 ;
10407 TEMPIK */
10408    --TEMPIK
10409    l_dt_rec_found            boolean ;
10410    --END TEMPIK
10411    --
10412    --UPD START
10413    --
10414    l_update                  boolean      := false ;
10415    l_datetrack_mode          varchar2(80) := hr_api.g_update;
10416    l_process_date            date;
10417    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
10418    --
10419    --UPD END
10420    --
10421    l_current_pk_id           number := null ;
10422    l_prev_pk_id              number := null ;
10423    l_first_rec               boolean := true ;
10424    r_DPC                     c_DPC%rowtype;
10425    l_dpnt_cvrd_anthr_pl_cvg_id             number ;
10426    l_object_version_number   number ;
10427    l_effective_start_date    date ;
10428    l_effective_end_date      date ;
10429    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
10430    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
10431    l_new_value               number(15);
10432    l_object_found_in_target  boolean := false ;
10433    l_min_esd                 date;
10434    l_max_eed                 date;
10435    l_effective_date          date;
10436    --
10437  begin
10438    -- Initialization
10439    l_object_found_in_target := false ;
10440    -- End Initialization
10441    -- Derive the prefix - sufix
10442    if   p_prefix_suffix_cd = 'PREFIX' then
10443      l_prefix  := p_prefix_suffix_text ;
10444    elsif p_prefix_suffix_cd = 'SUFFIX' then
10445      l_suffix   := p_prefix_suffix_text ;
10446    else
10447      l_prefix := null ;
10448      l_suffix  := null ;
10449    end if ;
10450    -- End Prefix Sufix derivation
10451    for r_DPC_unique in c_unique_DPC('DPC') loop
10452 
10453      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
10454         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
10455          r_DPC_unique.information3 >=
10456                  ben_pd_copy_to_ben_one.g_copy_effective_date)
10457         ) then
10458        --
10459        hr_utility.set_location(' r_DPC_unique.table_route_id '||r_DPC_unique.table_route_id,10);
10460        hr_utility.set_location(' r_DPC_unique.information1 '||r_DPC_unique.information1,10);
10461        hr_utility.set_location( 'r_DPC_unique.information2 '||r_DPC_unique.information2,10);
10462        hr_utility.set_location( 'r_DPC_unique.information3 '||r_DPC_unique.information3,10);
10463        -- If reuse objects flag is 'Y' then check for the object in the target business group
10464        -- if found insert the record into PLSql table and exit the loop else try create the
10465        -- object in the target business group
10466        --
10467        l_object_found_in_target := false ;
10468        --UPD START
10469        l_update := false;
10470        l_process_date := p_effective_date;
10471        l_dml_operation:= r_DPC_unique.dml_operation ;
10472        --
10473        open c_DPC(r_DPC_unique.table_route_id,
10474                         r_DPC_unique.information1,
10475                         r_DPC_unique.information2,
10476                         r_DPC_unique.information3 ) ;
10477        --
10478        fetch c_DPC into r_DPC ;
10479        --
10480        close c_DPC ;
10481        l_DPNT_CVG_ELIGY_PRFL_ID := get_fk('DPNT_CVG_ELIGY_PRFL_ID', r_DPC.information255,r_DPC.dml_operation);
10482 
10483        -- Only For Use by Create Wizard - Same Business Group
10484        l_PL_ID := NVL(get_fk('PL_ID', r_DPC.information261,r_DPC.dml_operation),
10485                               r_DPC.information261);
10486        --
10487        if l_dml_operation = 'UPDATE' then
10488          --
10489                  l_object_found_in_target := TRUE;
10490                  --
10491                  if l_process_date between r_DPC_unique.information2 and r_DPC_unique.information3 then
10492                        l_update := true;
10493                        if r_DPC_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
10494                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'DPNT_CVRD_ANTHR_PL_CVG_ID'
10495                        then
10496                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'DPNT_CVRD_ANTHR_PL_CVG_ID' ;
10497                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_DPC_unique.information1 ;
10498                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_DPC_unique.information1 ;
10499                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
10500                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_DPC_unique.table_route_id;
10501                           --
10502                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
10503                           --
10504                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
10505                           --
10506                           --BEN_PD_COPY_TO_BEN_ONE.log_data('DPC',l_new_value,l_prefix || r_DPC_unique.name|| l_suffix,'REUSED');
10507                           --
10508                        end if ;
10509                        hr_utility.set_location( 'found record for update',10);
10510                    --
10511                  else
10512                    --
10513                    l_update := false;
10514                    --
10515                  end if;
10516          --
10517        else
10518          --
10519          --UPD END
10520 
10521                l_min_esd := null ;
10522                l_max_eed := null ;
10523                open c_DPC_min_max_dates(r_DPC_unique.table_route_id, r_DPC_unique.information1 ) ;
10524                fetch c_DPC_min_max_dates into l_min_esd,l_max_eed ;
10525                --
10526 
10527                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
10528                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
10529                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
10530                end if;
10531                l_min_esd := greatest(l_min_esd,r_DPC_unique.information2);
10532                /*open c_DPC(r_DPC_unique.table_route_id,
10533                         r_DPC_unique.information1,
10534                         r_DPC_unique.information2,
10535                         r_DPC_unique.information3 ) ;
10536                --
10537                fetch c_DPC into r_DPC ;
10538                --
10539                close c_DPC ;*/
10540                --
10541 
10542                if p_reuse_object_flag = 'Y' then
10543                  if c_DPC_min_max_dates%found then
10544                    -- cursor to find the object
10545                    open c_find_DPC_in_target( l_min_esd,l_max_eed,
10546                                          p_target_business_group_id, nvl(l_dpnt_cvrd_anthr_pl_cvg_id, -999)  ) ;
10547                    fetch c_find_DPC_in_target into l_new_value ;
10548                    if c_find_DPC_in_target%found then
10549                      --
10550                      --TEMPIK
10551                      l_dt_rec_found :=   dt_api.check_min_max_dates
10552                          (p_base_table_name => 'BEN_DPNT_CVRD_ANTHR_PL_CVG_F',
10553                           p_base_key_column => 'DPNT_CVRD_ANTHR_PL_CVG_ID',
10554                           p_base_key_value  => l_new_value,
10555                           p_from_date       => l_min_esd,
10556                           p_to_date         => l_max_eed );
10557                      if l_dt_rec_found THEN
10558                      --END TEMPIK
10559                                          if r_DPC_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
10560                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'DPNT_CVRD_ANTHR_PL_CVG_ID'  then
10561                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'DPNT_CVRD_ANTHR_PL_CVG_ID' ;
10562                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_DPC_unique.information1 ;
10563                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
10564                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
10565                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_DPC_unique.table_route_id;
10566                                                 --
10567                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
10568                                                 --
10569                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
10570                                          end if ;
10571                                          --
10572                                          l_object_found_in_target := true ;
10573                      --TEMPIK
10574                      end if; -- l_dt_rec_found
10575                      --END TEMPIK
10576                    end if;
10577                    close c_find_DPC_in_target ;
10578                  --
10579                  end if;
10580                end if ;
10581                --
10582                close c_DPC_min_max_dates ;
10583        end if; --if p_dml_operation
10584        --
10585        -- UPD START
10586        if not l_object_found_in_target OR l_update  then
10587        --if not l_object_found_in_target then
10588        -- UPD END
10589          --
10590          l_current_pk_id := r_DPC.information1;
10591          --
10592          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
10593          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
10594          --
10595          if l_current_pk_id =  l_prev_pk_id  then
10596            --
10597            l_first_rec := false ;
10598            --
10599          else
10600            --
10601            l_first_rec := true ;
10602            --
10603          end if ;
10604          --
10605 
10606          l_effective_date := r_DPC.information2;
10607          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
10608               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
10609            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
10610          end if;
10611          -- UPD START
10612          --if l_first_rec then
10613          if l_first_rec and not l_update then
10614          -- UPD END
10615 
10616            -- Call Create routine.
10617            hr_utility.set_location(' BEN_DPNT_CVRD_ANTHR_PL_CVG_F CREATE_DPNT_CVD_ANTHR_PL_CVG ',20);
10618            BEN_DPNT_CVD_ANTHR_PL_CVG_API.CREATE_DPNT_CVD_ANTHR_PL_CVG(
10619              --
10620              P_VALIDATE               => false
10621              ,P_EFFECTIVE_DATE        => l_effective_date
10622              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
10623              --
10624              ,P_CVG_DET_DT_CD      => r_DPC.INFORMATION12
10625              ,P_DPC_ATTRIBUTE1      => r_DPC.INFORMATION111
10626              ,P_DPC_ATTRIBUTE10      => r_DPC.INFORMATION120
10627              ,P_DPC_ATTRIBUTE11      => r_DPC.INFORMATION121
10628              ,P_DPC_ATTRIBUTE12      => r_DPC.INFORMATION122
10629              ,P_DPC_ATTRIBUTE13      => r_DPC.INFORMATION123
10630              ,P_DPC_ATTRIBUTE14      => r_DPC.INFORMATION124
10631              ,P_DPC_ATTRIBUTE15      => r_DPC.INFORMATION125
10632              ,P_DPC_ATTRIBUTE16      => r_DPC.INFORMATION126
10633              ,P_DPC_ATTRIBUTE17      => r_DPC.INFORMATION127
10634              ,P_DPC_ATTRIBUTE18      => r_DPC.INFORMATION128
10635              ,P_DPC_ATTRIBUTE19      => r_DPC.INFORMATION129
10636              ,P_DPC_ATTRIBUTE2      => r_DPC.INFORMATION112
10637              ,P_DPC_ATTRIBUTE20      => r_DPC.INFORMATION130
10638              ,P_DPC_ATTRIBUTE21      => r_DPC.INFORMATION131
10639              ,P_DPC_ATTRIBUTE22      => r_DPC.INFORMATION132
10640              ,P_DPC_ATTRIBUTE23      => r_DPC.INFORMATION133
10641              ,P_DPC_ATTRIBUTE24      => r_DPC.INFORMATION134
10642              ,P_DPC_ATTRIBUTE25      => r_DPC.INFORMATION135
10643              ,P_DPC_ATTRIBUTE26      => r_DPC.INFORMATION136
10644              ,P_DPC_ATTRIBUTE27      => r_DPC.INFORMATION137
10645              ,P_DPC_ATTRIBUTE28      => r_DPC.INFORMATION138
10646              ,P_DPC_ATTRIBUTE29      => r_DPC.INFORMATION139
10647              ,P_DPC_ATTRIBUTE3      => r_DPC.INFORMATION113
10648              ,P_DPC_ATTRIBUTE30      => r_DPC.INFORMATION140
10649              ,P_DPC_ATTRIBUTE4      => r_DPC.INFORMATION114
10650              ,P_DPC_ATTRIBUTE5      => r_DPC.INFORMATION115
10651              ,P_DPC_ATTRIBUTE6      => r_DPC.INFORMATION116
10652              ,P_DPC_ATTRIBUTE7      => r_DPC.INFORMATION117
10653              ,P_DPC_ATTRIBUTE8      => r_DPC.INFORMATION118
10654              ,P_DPC_ATTRIBUTE9      => r_DPC.INFORMATION119
10655              ,P_DPC_ATTRIBUTE_CATEGORY      => r_DPC.INFORMATION110
10656              ,P_DPNT_CVG_ELIGY_PRFL_ID      => l_DPNT_CVG_ELIGY_PRFL_ID
10657              ,P_DPNT_CVRD_ANTHR_PL_CVG_ID      => l_dpnt_cvrd_anthr_pl_cvg_id
10658              ,P_EXCLD_FLAG      => r_DPC.INFORMATION11
10659              ,P_ORDR_NUM      => r_DPC.INFORMATION260
10660              ,P_PL_ID      => l_PL_ID
10661              --
10662              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
10663              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
10664              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
10665            );
10666            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
10667            -- Update all relevent cer records with new pk_id
10668            hr_utility.set_location('Before plsql table ',222);
10669            hr_utility.set_location('new_value id '||l_dpnt_cvrd_anthr_pl_cvg_id,222);
10670            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'DPNT_CVRD_ANTHR_PL_CVG_ID' ;
10671            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_DPC.information1 ;
10672            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_DPNT_CVRD_ANTHR_PL_CVG_ID ;
10673            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
10674            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_DPC_unique.table_route_id;
10675            hr_utility.set_location('After plsql table ',222);
10676            --
10677            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
10678            --
10679            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
10680            --
10681          else
10682            --
10683            -- Call Update routine for the pk_id created in prev run .
10684            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
10685            hr_utility.set_location(' BEN_DPNT_CVRD_ANTHR_PL_CVG_F UPDATE_DPNT_CVD_ANTHR_PL_CVG ',30);
10686             --UPD START
10687            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
10688            --
10689            if l_update then
10690              --
10691              l_datetrack_mode := r_DPC.datetrack_mode ;
10692              --
10693              get_dt_modes(
10694                p_effective_date        => l_process_date,
10695                p_effective_end_date    => r_DPC.information3,
10696                p_effective_start_date  => r_DPC.information2,
10697                p_dml_operation         => r_DPC.dml_operation,
10698                p_datetrack_mode        => l_datetrack_mode );
10699            --    p_update                => l_update
10700              --
10701              l_effective_date := l_process_date;
10702              l_dpnt_cvrd_anthr_pl_cvg_id  := r_DPC.information1;
10703              l_object_version_number := r_DPC.information265;
10704              --
10705            end if;
10706            --
10707            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
10708            --
10709            IF l_update OR l_dml_operation <> 'UPDATE' THEN
10710            --UPD END
10711 
10712                    BEN_DPNT_CVD_ANTHR_PL_CVG_API.UPDATE_DPNT_CVD_ANTHR_PL_CVG(
10713                      --
10714                      P_VALIDATE               => false
10715                      ,P_EFFECTIVE_DATE        => l_effective_date
10716                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
10717                      --
10718                      ,P_CVG_DET_DT_CD      => r_DPC.INFORMATION12
10719                      ,P_DPC_ATTRIBUTE1      => r_DPC.INFORMATION111
10720                      ,P_DPC_ATTRIBUTE10      => r_DPC.INFORMATION120
10721                      ,P_DPC_ATTRIBUTE11      => r_DPC.INFORMATION121
10722                      ,P_DPC_ATTRIBUTE12      => r_DPC.INFORMATION122
10723                      ,P_DPC_ATTRIBUTE13      => r_DPC.INFORMATION123
10724                      ,P_DPC_ATTRIBUTE14      => r_DPC.INFORMATION124
10725                      ,P_DPC_ATTRIBUTE15      => r_DPC.INFORMATION125
10726                      ,P_DPC_ATTRIBUTE16      => r_DPC.INFORMATION126
10727                      ,P_DPC_ATTRIBUTE17      => r_DPC.INFORMATION127
10728                      ,P_DPC_ATTRIBUTE18      => r_DPC.INFORMATION128
10729                      ,P_DPC_ATTRIBUTE19      => r_DPC.INFORMATION129
10730                      ,P_DPC_ATTRIBUTE2      => r_DPC.INFORMATION112
10731                      ,P_DPC_ATTRIBUTE20      => r_DPC.INFORMATION130
10732                      ,P_DPC_ATTRIBUTE21      => r_DPC.INFORMATION131
10733                      ,P_DPC_ATTRIBUTE22      => r_DPC.INFORMATION132
10734                      ,P_DPC_ATTRIBUTE23      => r_DPC.INFORMATION133
10735                      ,P_DPC_ATTRIBUTE24      => r_DPC.INFORMATION134
10736                      ,P_DPC_ATTRIBUTE25      => r_DPC.INFORMATION135
10737                      ,P_DPC_ATTRIBUTE26      => r_DPC.INFORMATION136
10738                      ,P_DPC_ATTRIBUTE27      => r_DPC.INFORMATION137
10739                      ,P_DPC_ATTRIBUTE28      => r_DPC.INFORMATION138
10740                      ,P_DPC_ATTRIBUTE29      => r_DPC.INFORMATION139
10741                      ,P_DPC_ATTRIBUTE3      => r_DPC.INFORMATION113
10742                      ,P_DPC_ATTRIBUTE30      => r_DPC.INFORMATION140
10743                      ,P_DPC_ATTRIBUTE4      => r_DPC.INFORMATION114
10744                      ,P_DPC_ATTRIBUTE5      => r_DPC.INFORMATION115
10745                      ,P_DPC_ATTRIBUTE6      => r_DPC.INFORMATION116
10746                      ,P_DPC_ATTRIBUTE7      => r_DPC.INFORMATION117
10747                      ,P_DPC_ATTRIBUTE8      => r_DPC.INFORMATION118
10748                      ,P_DPC_ATTRIBUTE9      => r_DPC.INFORMATION119
10749                      ,P_DPC_ATTRIBUTE_CATEGORY      => r_DPC.INFORMATION110
10750                      ,P_DPNT_CVG_ELIGY_PRFL_ID      => l_DPNT_CVG_ELIGY_PRFL_ID
10751                      ,P_DPNT_CVRD_ANTHR_PL_CVG_ID      => l_dpnt_cvrd_anthr_pl_cvg_id
10752                      ,P_EXCLD_FLAG      => r_DPC.INFORMATION11
10753                      ,P_ORDR_NUM      => r_DPC.INFORMATION260
10754                      ,P_PL_ID      => l_PL_ID
10755                      --
10756                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
10757                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
10758                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
10759                      --,P_DATETRACK_MODE        => hr_api.g_update
10760                      ,P_DATETRACK_MODE        => l_datetrack_mode
10761                    );
10762           end if;  -- l_update
10763          end if;
10764          --
10765          --
10766          -- Delete the row if it is end dated.
10767          --
10768          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
10769              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
10770            trunc(l_max_eed) = r_DPC.information3) then
10771              --
10772              BEN_DPNT_CVD_ANTHR_PL_CVG_API.delete_DPNT_CVD_ANTHR_PL_CVG(
10773                 --
10774                 p_validate                       => false
10775                 ,p_dpnt_cvrd_anthr_pl_cvg_id                   => l_dpnt_cvrd_anthr_pl_cvg_id
10776                 ,p_effective_start_date           => l_effective_start_date
10777                 ,p_effective_end_date             => l_effective_end_date
10778                 ,p_object_version_number          => l_object_version_number
10779                 ,p_effective_date                 => l_max_eed
10780                 ,p_datetrack_mode                 => hr_api.g_delete
10781                 --
10782                 );
10783                 --
10784          end if;
10785          --
10786          l_prev_pk_id := l_current_pk_id ;
10787          --
10788        end if;
10789        --
10790      end if;
10791      --
10792    end loop;
10793    --
10794  exception when others then
10795      --
10796      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'DPC',r_DPC.information5 ) ;
10797      --
10798  end create_DPC_rows;
10799 
10800    --
10801    ---------------------------------------------------------------
10802    ----------------------< create_EAC_rows >-----------------------
10803    ---------------------------------------------------------------
10804    --
10805    procedure create_EAC_rows
10806    (
10807          p_validate                       in  number     default 0
10808         ,p_copy_entity_txn_id             in  number
10809         ,p_effective_date                 in  date
10810         ,p_prefix_suffix_text             in  varchar2  default null
10811         ,p_reuse_object_flag              in  varchar2  default null
10812         ,p_target_business_group_id       in  varchar2  default null
10813         ,p_prefix_suffix_cd               in  varchar2  default null
10814    ) is
10815    --
10816    l_AGE_FCTR_ID  number;
10817    l_CVG_STRT_RL  number;
10818    l_CVG_THRU_RL  number;
10819    l_DPNT_CVG_ELIGY_PRFL_ID  number;
10820    cursor c_unique_EAC(l_table_alias varchar2) is
10821    select distinct cpe.information1,
10822      cpe.information2,
10823      cpe.information3,
10824      cpe.table_route_id,
10825      cpe.dml_operation,
10826      cpe.datetrack_mode
10827    from ben_copy_entity_results cpe,
10828         pqh_table_route tr
10829    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
10830    and   cpe.table_route_id     = tr.table_route_id
10831    -- and   tr.where_clause        = l_BEN_ELIG_AGE_CVG_F
10832    and   tr.table_alias = l_table_alias
10833    and   cpe.number_of_copies   = 1 -- ADDITION
10834    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
10835    order by information1, information2; --added for bug: 5151945
10836    --
10837    --
10838    cursor c_EAC_min_max_dates(c_table_route_id  number,
10839                 c_information1   number) is
10840    select
10841      min(cpe.information2) min_esd,
10842      max(cpe.information3) min_eed
10843    from ben_copy_entity_results cpe
10844    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
10845    and   cpe.table_route_id     = c_table_route_id
10846    and   cpe.information1       = c_information1 ;
10847    --
10848    cursor c_EAC(c_table_route_id  number,
10849                 c_information1   number,
10850                 c_information2   date,
10851                 c_information3   date)  is
10852    select
10853      cpe.*
10854    from ben_copy_entity_results cpe
10855    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
10856    and   cpe.table_route_id     = c_table_route_id
10857    and   cpe.information1       = c_information1
10858    and   cpe.information2       = c_information2
10859    and   cpe.information3       = c_information3
10860    and rownum = 1 ;
10861    -- Date Track target record
10862    cursor c_find_EAC_in_target(
10863                                 c_effective_start_date    date,
10864                                 c_effective_end_date      date,
10865                                 c_business_group_id       number,
10866                                 c_new_pk_id               number) is
10867    select
10868      EAC.elig_age_cvg_id new_value
10869    from BEN_ELIG_AGE_CVG_F EAC
10870    where
10871    nvl(EAC.AGE_FCTR_ID,-999)     = nvl(l_AGE_FCTR_ID,-999)  and
10872    nvl(EAC.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
10873    EAC.business_group_id  = c_business_group_id
10874    and   EAC.elig_age_cvg_id  <> c_new_pk_id
10875 --TEMPIK
10876    and c_effective_start_date between effective_start_date
10877                             and effective_end_date ;
10878 --END TEMPIK
10879 /*TEMPIK
10880    and exists ( select null
10881                 from BEN_ELIG_AGE_CVG_F EAC1
10882                 where
10883                 nvl(EAC1.AGE_FCTR_ID,-999)     = nvl(l_AGE_FCTR_ID,-999)  and
10884                 nvl(EAC1.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
10885                 EAC1.business_group_id  = c_business_group_id
10886                 and   EAC1.effective_start_date <= c_effective_start_date )
10887    and exists ( select null
10888                 from BEN_ELIG_AGE_CVG_F EAC2
10889                 where
10890                 nvl(EAC2.AGE_FCTR_ID,-999)     = nvl(l_AGE_FCTR_ID,-999)  and
10891                 nvl(EAC2.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
10892                 EAC2.business_group_id  = c_business_group_id
10893                 and   EAC2.effective_end_date >= c_effective_end_date )
10894                 ;
10895 TEMPIK */
10896    --TEMPIK
10897    l_dt_rec_found            boolean ;
10898    --END TEMPIK
10899    --
10900    --UPD START
10901    --
10902    l_update                  boolean      := false ;
10903    l_datetrack_mode          varchar2(80) := hr_api.g_update;
10904    l_process_date            date;
10905    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
10906    --
10907    --UPD END
10908    --
10909    l_current_pk_id           number := null ;
10910    l_prev_pk_id              number := null ;
10911    l_first_rec               boolean := true ;
10912    r_EAC                     c_EAC%rowtype;
10913    l_elig_age_cvg_id             number ;
10914    l_object_version_number   number ;
10915    l_effective_start_date    date ;
10916    l_effective_end_date      date ;
10917    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
10918    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
10919    l_new_value               number(15);
10920    l_object_found_in_target  boolean := false ;
10921    l_min_esd                 date;
10922    l_max_eed                 date;
10923    l_effective_date          date;
10924    --
10925  begin
10926    -- Initialization
10927    l_object_found_in_target := false ;
10928    -- End Initialization
10929    -- Derive the prefix - sufix
10930    if   p_prefix_suffix_cd = 'PREFIX' then
10931      l_prefix  := p_prefix_suffix_text ;
10932    elsif p_prefix_suffix_cd = 'SUFFIX' then
10933      l_suffix   := p_prefix_suffix_text ;
10934    else
10935      l_prefix := null ;
10936      l_suffix  := null ;
10937    end if ;
10938    -- End Prefix Sufix derivation
10939    for r_EAC_unique in c_unique_EAC('EAC') loop
10940 
10941      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
10942         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
10943          r_EAC_unique.information3 >=
10944                  ben_pd_copy_to_ben_one.g_copy_effective_date)
10945         ) then
10946        --
10947        hr_utility.set_location(' r_EAC_unique.table_route_id '||r_EAC_unique.table_route_id,10);
10948        hr_utility.set_location(' r_EAC_unique.information1 '||r_EAC_unique.information1,10);
10949        hr_utility.set_location( 'r_EAC_unique.information2 '||r_EAC_unique.information2,10);
10950        hr_utility.set_location( 'r_EAC_unique.information3 '||r_EAC_unique.information3,10);
10951        -- If reuse objects flag is 'Y' then check for the object in the target business group
10952        -- if found insert the record into PLSql table and exit the loop else try create the
10953        -- object in the target business group
10954        --
10955        l_object_found_in_target := false ;
10956        --UPD START
10957        l_update := false;
10958        l_process_date := p_effective_date;
10959        l_dml_operation:= r_EAC_unique.dml_operation ;
10960        --
10961        open c_EAC(r_EAC_unique.table_route_id,
10962                         r_EAC_unique.information1,
10963                         r_EAC_unique.information2,
10964                         r_EAC_unique.information3 ) ;
10965         --
10966         fetch c_EAC into r_EAC ;
10967         --
10968         close c_EAC ;
10969         --
10970         l_AGE_FCTR_ID := get_fk('AGE_FCTR_ID', r_EAC.information246,r_EAC.dml_operation);
10971         l_CVG_STRT_RL := get_fk('FORMULA_ID', r_EAC.information257,r_EAC.dml_operation);
10972         l_CVG_THRU_RL := get_fk('FORMULA_ID', r_EAC.information258,r_EAC.dml_operation);
10973         l_DPNT_CVG_ELIGY_PRFL_ID := get_fk('DPNT_CVG_ELIGY_PRFL_ID', r_EAC.information255,r_EAC.dml_operation);
10974        --
10975        if l_dml_operation = 'UPDATE' then
10976          --
10977                  l_object_found_in_target := TRUE;
10978                  --
10979                  if l_process_date between r_EAC_unique.information2 and r_EAC_unique.information3 then
10980                        l_update := true;
10981                        if r_EAC_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
10982                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ELIG_AGE_CVG_ID'
10983                        then
10984                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ELIG_AGE_CVG_ID' ;
10985                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_EAC_unique.information1 ;
10986                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_EAC_unique.information1 ;
10987                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
10988                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_EAC_unique.table_route_id;
10989                           --
10990                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
10991                           --
10992                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
10993                           --
10994                           --BEN_PD_COPY_TO_BEN_ONE.log_data('EAC',l_new_value,l_prefix || r_EAC_unique.name|| l_suffix,'REUSED');
10995                           --
10996                        end if ;
10997                        hr_utility.set_location( 'found record for update',10);
10998                    --
10999                  else
11000                    --
11001                    l_update := false;
11002                    --
11003                  end if;
11004        else
11005          --
11006          --UPD END
11007                l_min_esd := null ;
11008                l_max_eed := null ;
11009                open c_EAC_min_max_dates(r_EAC_unique.table_route_id, r_EAC_unique.information1 ) ;
11010                fetch c_EAC_min_max_dates into l_min_esd,l_max_eed ;
11011                --
11012 
11013                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
11014                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
11015                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
11016                end if;
11017                l_min_esd := greatest(l_min_esd,r_EAC_unique.information2);
11018                /*open c_EAC(r_EAC_unique.table_route_id,
11019                         r_EAC_unique.information1,
11020                         r_EAC_unique.information2,
11021                         r_EAC_unique.information3 ) ;
11022                --
11023                fetch c_EAC into r_EAC ;
11024                --
11025                close c_EAC ;*/
11026                --
11027                if p_reuse_object_flag = 'Y' then
11028                  if c_EAC_min_max_dates%found then
11029                    -- cursor to find the object
11030                    open c_find_EAC_in_target( l_min_esd,l_max_eed,
11031                                          p_target_business_group_id, nvl(l_elig_age_cvg_id, -999)  ) ;
11032                    fetch c_find_EAC_in_target into l_new_value ;
11033                    if c_find_EAC_in_target%found then
11034                      --
11035                      --TEMPIK
11036                      l_dt_rec_found :=   dt_api.check_min_max_dates
11037                          (p_base_table_name => 'BEN_ELIG_AGE_CVG_F',
11038                           p_base_key_column => 'ELIG_AGE_CVG_ID',
11039                           p_base_key_value  => l_new_value,
11040                           p_from_date       => l_min_esd,
11041                           p_to_date         => l_max_eed );
11042                      if l_dt_rec_found THEN
11043                      --END TEMPIK
11044                                          if r_EAC_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
11045                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'ELIG_AGE_CVG_ID'  then
11046                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'ELIG_AGE_CVG_ID' ;
11047                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_EAC_unique.information1 ;
11048                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
11049                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
11050                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_EAC_unique.table_route_id;
11051                                                 --
11052                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
11053                                                 --
11054                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
11055                                          end if ;
11056                                          --
11057                                          l_object_found_in_target := true ;
11058                      --TEMPIK
11059                      end if; -- l_dt_rec_found
11060                      --END TEMPIK
11061                    end if;
11062                    close c_find_EAC_in_target ;
11063                  --
11064                  end if;
11065                end if ;
11066                --
11067                close c_EAC_min_max_dates ;
11068 
11069        -- UPD START
11070        --if not l_object_found_in_target then
11071        end if; --if p_dml_operation
11072        --
11073        if not l_object_found_in_target OR l_update  then
11074        -- UPD END
11075          --
11076          l_current_pk_id := r_EAC.information1;
11077          --
11078          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
11079          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
11080          --
11081          if l_current_pk_id =  l_prev_pk_id  then
11082            --
11083            l_first_rec := false ;
11084            --
11085          else
11086            --
11087            l_first_rec := true ;
11088            --
11089          end if ;
11090          --
11091 
11092          l_effective_date := r_EAC.information2;
11093          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
11094               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
11095            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
11096          end if;
11097 
11098          --if l_first_rec then
11099          if l_first_rec and not l_update then
11100 
11101            -- Call Create routine.
11102            hr_utility.set_location(' BEN_ELIG_AGE_CVG_F CREATE_ELIG_AGE_CVG ',20);
11103            BEN_ELIG_AGE_CVG_API.CREATE_ELIG_AGE_CVG(
11104              --
11105              P_VALIDATE               => false
11106              ,P_EFFECTIVE_DATE        => l_effective_date
11107              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
11108              --
11109              ,P_AGE_FCTR_ID      => l_AGE_FCTR_ID
11110              ,P_CVG_STRT_CD      => r_EAC.INFORMATION12
11111              ,P_CVG_STRT_RL      => l_CVG_STRT_RL
11112              ,P_CVG_THRU_CD      => r_EAC.INFORMATION13
11113              ,P_CVG_THRU_RL      => l_CVG_THRU_RL
11114              ,P_DPNT_CVG_ELIGY_PRFL_ID      => l_DPNT_CVG_ELIGY_PRFL_ID
11115              ,P_EAC_ATTRIBUTE1      => r_EAC.INFORMATION111
11116              ,P_EAC_ATTRIBUTE10      => r_EAC.INFORMATION120
11117              ,P_EAC_ATTRIBUTE11      => r_EAC.INFORMATION121
11118              ,P_EAC_ATTRIBUTE12      => r_EAC.INFORMATION122
11119              ,P_EAC_ATTRIBUTE13      => r_EAC.INFORMATION123
11120              ,P_EAC_ATTRIBUTE14      => r_EAC.INFORMATION124
11121              ,P_EAC_ATTRIBUTE15      => r_EAC.INFORMATION125
11122              ,P_EAC_ATTRIBUTE16      => r_EAC.INFORMATION126
11123              ,P_EAC_ATTRIBUTE17      => r_EAC.INFORMATION127
11124              ,P_EAC_ATTRIBUTE18      => r_EAC.INFORMATION128
11125              ,P_EAC_ATTRIBUTE19      => r_EAC.INFORMATION129
11126              ,P_EAC_ATTRIBUTE2      => r_EAC.INFORMATION112
11127              ,P_EAC_ATTRIBUTE20      => r_EAC.INFORMATION130
11128              ,P_EAC_ATTRIBUTE21      => r_EAC.INFORMATION131
11129              ,P_EAC_ATTRIBUTE22      => r_EAC.INFORMATION132
11130              ,P_EAC_ATTRIBUTE23      => r_EAC.INFORMATION133
11131              ,P_EAC_ATTRIBUTE24      => r_EAC.INFORMATION134
11132              ,P_EAC_ATTRIBUTE25      => r_EAC.INFORMATION135
11133              ,P_EAC_ATTRIBUTE26      => r_EAC.INFORMATION136
11134              ,P_EAC_ATTRIBUTE27      => r_EAC.INFORMATION137
11135              ,P_EAC_ATTRIBUTE28      => r_EAC.INFORMATION138
11136              ,P_EAC_ATTRIBUTE29      => r_EAC.INFORMATION139
11137              ,P_EAC_ATTRIBUTE3      => r_EAC.INFORMATION113
11138              ,P_EAC_ATTRIBUTE30      => r_EAC.INFORMATION140
11139              ,P_EAC_ATTRIBUTE4      => r_EAC.INFORMATION114
11140              ,P_EAC_ATTRIBUTE5      => r_EAC.INFORMATION115
11141              ,P_EAC_ATTRIBUTE6      => r_EAC.INFORMATION116
11142              ,P_EAC_ATTRIBUTE7      => r_EAC.INFORMATION117
11143              ,P_EAC_ATTRIBUTE8      => r_EAC.INFORMATION118
11144              ,P_EAC_ATTRIBUTE9      => r_EAC.INFORMATION119
11145              ,P_EAC_ATTRIBUTE_CATEGORY      => r_EAC.INFORMATION110
11146              ,P_ELIG_AGE_CVG_ID      => l_elig_age_cvg_id
11147              ,P_EXCLD_FLAG      => r_EAC.INFORMATION11
11148              --
11149              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
11150              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
11151              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
11152            );
11153            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
11154            -- Update all relevent cer records with new pk_id
11155            hr_utility.set_location('Before plsql table ',222);
11156            hr_utility.set_location('new_value id '||l_elig_age_cvg_id,222);
11157            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'ELIG_AGE_CVG_ID' ;
11158            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_EAC.information1 ;
11159            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_ELIG_AGE_CVG_ID ;
11160            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
11161            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_EAC_unique.table_route_id;
11162            hr_utility.set_location('After plsql table ',222);
11163            --
11164            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
11165            --
11166            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
11167            --
11168          else
11169            --
11170            -- Call Update routine for the pk_id created in prev run .
11171            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
11172            hr_utility.set_location(' BEN_ELIG_AGE_CVG_F UPDATE_ELIG_AGE_CVG ',30);
11173            --UPD START
11174            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
11175            --
11176            if l_update then
11177              --
11178              l_datetrack_mode := r_EAC.datetrack_mode ;
11179              --
11180              get_dt_modes(
11181                p_effective_date        => l_process_date,
11182                p_effective_end_date    => r_EAC.information3,
11183                p_effective_start_date  => r_EAC.information2,
11184                p_dml_operation         => r_EAC.dml_operation,
11185                p_datetrack_mode        => l_datetrack_mode );
11186            --    p_update                => l_update
11187              --
11188              l_effective_date := l_process_date;
11189              l_elig_age_cvg_id   := r_EAC.information1;
11190              l_object_version_number := r_EAC.information265;
11191              --
11192            end if;
11193            --
11194            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
11195            --
11196            IF l_update OR l_dml_operation <> 'UPDATE' THEN
11197            --UPD END
11198 
11199            BEN_ELIG_AGE_CVG_API.UPDATE_ELIG_AGE_CVG(
11200              --
11201              P_VALIDATE               => false
11202              ,P_EFFECTIVE_DATE        => l_effective_date
11203              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
11204              --
11205              ,P_AGE_FCTR_ID      => l_AGE_FCTR_ID
11206              ,P_CVG_STRT_CD      => r_EAC.INFORMATION12
11207              ,P_CVG_STRT_RL      => l_CVG_STRT_RL
11208              ,P_CVG_THRU_CD      => r_EAC.INFORMATION13
11209              ,P_CVG_THRU_RL      => l_CVG_THRU_RL
11210              ,P_DPNT_CVG_ELIGY_PRFL_ID      => l_DPNT_CVG_ELIGY_PRFL_ID
11211              ,P_EAC_ATTRIBUTE1      => r_EAC.INFORMATION111
11212              ,P_EAC_ATTRIBUTE10      => r_EAC.INFORMATION120
11213              ,P_EAC_ATTRIBUTE11      => r_EAC.INFORMATION121
11214              ,P_EAC_ATTRIBUTE12      => r_EAC.INFORMATION122
11215              ,P_EAC_ATTRIBUTE13      => r_EAC.INFORMATION123
11216              ,P_EAC_ATTRIBUTE14      => r_EAC.INFORMATION124
11217              ,P_EAC_ATTRIBUTE15      => r_EAC.INFORMATION125
11218              ,P_EAC_ATTRIBUTE16      => r_EAC.INFORMATION126
11219              ,P_EAC_ATTRIBUTE17      => r_EAC.INFORMATION127
11220              ,P_EAC_ATTRIBUTE18      => r_EAC.INFORMATION128
11221              ,P_EAC_ATTRIBUTE19      => r_EAC.INFORMATION129
11222              ,P_EAC_ATTRIBUTE2      => r_EAC.INFORMATION112
11223              ,P_EAC_ATTRIBUTE20      => r_EAC.INFORMATION130
11224              ,P_EAC_ATTRIBUTE21      => r_EAC.INFORMATION131
11225              ,P_EAC_ATTRIBUTE22      => r_EAC.INFORMATION132
11226              ,P_EAC_ATTRIBUTE23      => r_EAC.INFORMATION133
11227              ,P_EAC_ATTRIBUTE24      => r_EAC.INFORMATION134
11228              ,P_EAC_ATTRIBUTE25      => r_EAC.INFORMATION135
11229              ,P_EAC_ATTRIBUTE26      => r_EAC.INFORMATION136
11230              ,P_EAC_ATTRIBUTE27      => r_EAC.INFORMATION137
11231              ,P_EAC_ATTRIBUTE28      => r_EAC.INFORMATION138
11232              ,P_EAC_ATTRIBUTE29      => r_EAC.INFORMATION139
11233              ,P_EAC_ATTRIBUTE3      => r_EAC.INFORMATION113
11234              ,P_EAC_ATTRIBUTE30      => r_EAC.INFORMATION140
11235              ,P_EAC_ATTRIBUTE4      => r_EAC.INFORMATION114
11236              ,P_EAC_ATTRIBUTE5      => r_EAC.INFORMATION115
11237              ,P_EAC_ATTRIBUTE6      => r_EAC.INFORMATION116
11238              ,P_EAC_ATTRIBUTE7      => r_EAC.INFORMATION117
11239              ,P_EAC_ATTRIBUTE8      => r_EAC.INFORMATION118
11240              ,P_EAC_ATTRIBUTE9      => r_EAC.INFORMATION119
11241              ,P_EAC_ATTRIBUTE_CATEGORY      => r_EAC.INFORMATION110
11242              ,P_ELIG_AGE_CVG_ID      => l_elig_age_cvg_id
11243              ,P_EXCLD_FLAG      => r_EAC.INFORMATION11
11244              --
11245              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
11246              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
11247              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
11248              --,P_DATETRACK_MODE        => hr_api.g_update
11249              ,P_DATETRACK_MODE        => l_datetrack_mode
11250            );
11251           end if;  -- l_update
11252          end if;
11253          --
11254          --
11255          -- Delete the row if it is end dated.
11256          --
11257          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
11258              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
11259            trunc(l_max_eed) = r_EAC.information3) then
11260              --
11261              BEN_ELIG_AGE_CVG_API.delete_ELIG_AGE_CVG(
11262                 --
11263                 p_validate                       => false
11264                 ,p_elig_age_cvg_id                   => l_elig_age_cvg_id
11265                 ,p_effective_start_date           => l_effective_start_date
11266                 ,p_effective_end_date             => l_effective_end_date
11267                 ,p_object_version_number          => l_object_version_number
11268                 ,p_effective_date                 => l_max_eed
11269                 ,p_datetrack_mode                 => hr_api.g_delete
11270                 --
11271                 );
11272                 --
11273          end if;
11274          --
11275          l_prev_pk_id := l_current_pk_id ;
11276          --
11277        end if;
11278        --
11279      end if;
11280      --
11281    end loop;
11282    --
11283  exception when others then
11284      --
11285      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'EAC',r_EAC.information5 ) ;
11286      --
11287  end create_EAC_rows;
11288 
11289    --
11290    ---------------------------------------------------------------
11291    ----------------------< create_EDC_rows >-----------------------
11292    ---------------------------------------------------------------
11293    --
11294    procedure create_EDC_rows
11295    (
11296          p_validate                       in  number     default 0
11297         ,p_copy_entity_txn_id             in  number
11298         ,p_effective_date                 in  date
11299         ,p_prefix_suffix_text             in  varchar2  default null
11300         ,p_reuse_object_flag              in  varchar2  default null
11301         ,p_target_business_group_id       in  varchar2  default null
11302         ,p_prefix_suffix_cd               in  varchar2  default null
11303    ) is
11304    --
11305    l_CVG_STRT_RL  number;
11306    l_CVG_THRU_RL  number;
11307    l_DPNT_CVG_ELIGY_PRFL_ID  number;
11308    l_DSBLD_CD     ben_elig_dsbld_stat_cvg_f.dsbld_cd%type;
11309    cursor c_unique_EDC(l_table_alias varchar2) is
11310    select distinct cpe.information1,
11311      cpe.information2,
11312      cpe.information3,
11313      cpe.table_route_id,
11314      cpe.dml_operation,
11315      cpe.datetrack_mode
11316    from ben_copy_entity_results cpe,
11317         pqh_table_route tr
11318    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
11319    and   cpe.table_route_id     = tr.table_route_id
11320    -- and   tr.where_clause        = l_BEN_ELIG_DSBLD_STAT_CVG_F
11321    and   tr.table_alias = l_table_alias
11322    and   cpe.number_of_copies   = 1 -- ADDITION
11323    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
11324    order by information1, information2; --added for bug: 5151945
11325    --
11326    --
11327    cursor c_EDC_min_max_dates(c_table_route_id  number,
11328                 c_information1   number) is
11329    select
11330      min(cpe.information2) min_esd,
11331      max(cpe.information3) min_eed
11332    from ben_copy_entity_results cpe
11333    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
11334    and   cpe.table_route_id     = c_table_route_id
11335    and   cpe.information1       = c_information1 ;
11336    --
11337    cursor c_EDC(c_table_route_id  number,
11338                 c_information1   number,
11339                 c_information2   date,
11340                 c_information3   date)  is
11341    select
11342      cpe.*
11343    from ben_copy_entity_results cpe
11344    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
11345    and   cpe.table_route_id     = c_table_route_id
11346    and   cpe.information1       = c_information1
11347    and   cpe.information2       = c_information2
11348    and   cpe.information3       = c_information3
11349    and rownum = 1 ;
11350    -- Date Track target record
11351    cursor c_find_EDC_in_target(
11352                                 c_effective_start_date    date,
11353                                 c_effective_end_date      date,
11354                                 c_business_group_id       number,
11355                                 c_new_pk_id               number) is
11356    select
11357      EDC.elig_dsbld_stat_cvg_id new_value
11358    from BEN_ELIG_DSBLD_STAT_CVG_F EDC
11359    where
11360    nvl(EDC.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
11361    EDC.DSBLD_CD                             = l_DSBLD_CD and
11362    EDC.business_group_id  = c_business_group_id
11363    and   EDC.elig_dsbld_stat_cvg_id  <> c_new_pk_id
11364 --TEMPIK
11365    and c_effective_start_date between effective_start_date
11366                             and effective_end_date ;
11367 --END TEMPIK
11368 /*TEMPIK
11369    and exists ( select null
11370                 from BEN_ELIG_DSBLD_STAT_CVG_F EDC1
11371                 where
11372                 nvl(EDC1.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
11373                 EDC1.DSBLD_CD                             = l_DSBLD_CD and
11374                 EDC1.business_group_id  = c_business_group_id
11375                 and   EDC1.effective_start_date <= c_effective_start_date )
11376    and exists ( select null
11377                 from BEN_ELIG_DSBLD_STAT_CVG_F EDC2
11378                 where
11379                 nvl(EDC2.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
11380                 EDC2.DSBLD_CD                             = l_DSBLD_CD and
11381                 EDC2.business_group_id  = c_business_group_id
11382                 and   EDC2.effective_end_date >= c_effective_end_date )
11383                 ;
11384 TEMPIK */
11385    --TEMPIK
11386    l_dt_rec_found            boolean ;
11387    --END TEMPIK
11388    --
11389    --UPD START
11390    --
11391    l_update                  boolean      := false ;
11392    l_datetrack_mode          varchar2(80) := hr_api.g_update;
11393    l_process_date            date;
11394    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
11395    --
11396    --UPD END
11397    --
11398    l_current_pk_id           number := null ;
11399    l_prev_pk_id              number := null ;
11400    l_first_rec               boolean := true ;
11401    r_EDC                     c_EDC%rowtype;
11402    l_elig_dsbld_stat_cvg_id             number ;
11403    l_object_version_number   number ;
11404    l_effective_start_date    date ;
11405    l_effective_end_date      date ;
11406    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
11407    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
11408    l_new_value               number(15);
11409    l_object_found_in_target  boolean := false ;
11410    l_min_esd                 date;
11411    l_max_eed                 date;
11412    l_effective_date          date;
11413    --
11414  begin
11415    -- Initialization
11416    l_object_found_in_target := false ;
11417    -- End Initialization
11418    -- Derive the prefix - sufix
11419    if   p_prefix_suffix_cd = 'PREFIX' then
11420      l_prefix  := p_prefix_suffix_text ;
11421    elsif p_prefix_suffix_cd = 'SUFFIX' then
11422      l_suffix   := p_prefix_suffix_text ;
11423    else
11424      l_prefix := null ;
11425      l_suffix  := null ;
11426    end if ;
11427    -- End Prefix Sufix derivation
11428    for r_EDC_unique in c_unique_EDC('EDC') loop
11429 
11430      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
11431         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
11432          r_EDC_unique.information3 >=
11433                  ben_pd_copy_to_ben_one.g_copy_effective_date)
11434         ) then
11435        --
11436        hr_utility.set_location(' r_EDC_unique.table_route_id '||r_EDC_unique.table_route_id,10);
11437        hr_utility.set_location(' r_EDC_unique.information1 '||r_EDC_unique.information1,10);
11438        hr_utility.set_location( 'r_EDC_unique.information2 '||r_EDC_unique.information2,10);
11439        hr_utility.set_location( 'r_EDC_unique.information3 '||r_EDC_unique.information3,10);
11440        -- If reuse objects flag is 'Y' then check for the object in the target business group
11441        -- if found insert the record into PLSql table and exit the loop else try create the
11442        -- object in the target business group
11443        --
11444        l_object_found_in_target := false ;
11445        --
11446        --UPD START
11447        l_update := false;
11448        l_process_date := p_effective_date;
11449        l_dml_operation:= r_EDC_unique.dml_operation ;
11450        open c_EDC(r_EDC_unique.table_route_id,
11451                 r_EDC_unique.information1,
11452                 r_EDC_unique.information2,
11453                 r_EDC_unique.information3 ) ;
11454        --
11455        fetch c_EDC into r_EDC ;
11456        --
11457        close c_EDC ;
11458        --
11459        l_CVG_STRT_RL := get_fk('FORMULA_ID', r_EDC.information260,r_EDC.dml_operation);
11460        l_CVG_THRU_RL := get_fk('FORMULA_ID', r_EDC.information261,r_EDC.dml_operation);
11461        l_DPNT_CVG_ELIGY_PRFL_ID := get_fk('DPNT_CVG_ELIGY_PRFL_ID', r_EDC.information255,r_EDC.dml_operation);
11462        l_DSBLD_CD    := r_EDC.information13;
11463        --
11464        if l_dml_operation = 'UPDATE' then
11465          --
11466                  l_object_found_in_target := TRUE;
11467                  --
11468                  if l_process_date between r_EDC_unique.information2 and r_EDC_unique.information3 then
11469                        l_update := true;
11470                        if r_EDC_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
11471                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ELIG_DSBLD_STAT_CVG_ID'
11472                        then
11473                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ELIG_DSBLD_STAT_CVG_ID' ;
11474                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_EDC_unique.information1 ;
11475                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_EDC_unique.information1 ;
11476                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
11477                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_EDC_unique.table_route_id;
11478                           --
11479                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
11480                           --
11481                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
11482                           --
11483                           --BEN_PD_COPY_TO_BEN_ONE.log_data('EDC',l_new_value,l_prefix || r_EDC_unique.name|| l_suffix,'REUSED');
11484                           --
11485                        end if ;
11486                        hr_utility.set_location( 'found record for update',10);
11487                    --
11488                  else
11489                    --
11490                    l_update := false;
11491                    --
11492                  end if;
11493        else
11494          --
11495          --UPD END
11496        --
11497                l_min_esd := null ;
11498                l_max_eed := null ;
11499                open c_EDC_min_max_dates(r_EDC_unique.table_route_id, r_EDC_unique.information1 ) ;
11500                fetch c_EDC_min_max_dates into l_min_esd,l_max_eed ;
11501                --
11502 
11503                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
11504                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
11505                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
11506                end if;
11507                l_min_esd := greatest(l_min_esd,r_EDC_unique.information2);
11508                --
11509                if p_reuse_object_flag = 'Y' then
11510                  if c_EDC_min_max_dates%found then
11511                    -- cursor to find the object
11512                    open c_find_EDC_in_target( l_min_esd,l_max_eed,
11513                                          p_target_business_group_id, nvl(l_elig_dsbld_stat_cvg_id, -999)  ) ;
11514                    fetch c_find_EDC_in_target into l_new_value ;
11515                    if c_find_EDC_in_target%found then
11516                      --
11517                      --TEMPIK
11518                      l_dt_rec_found :=   dt_api.check_min_max_dates
11519                          (p_base_table_name => 'BEN_ELIG_DSBLD_STAT_CVG_F',
11520                           p_base_key_column => 'ELIG_DSBLD_STAT_CVG_ID',
11521                           p_base_key_value  => l_new_value,
11522                           p_from_date       => l_min_esd,
11523                           p_to_date         => l_max_eed );
11524                      if l_dt_rec_found THEN
11525                      --END TEMPIK
11526                                          if r_EDC_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
11527                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'ELIG_DSBLD_STAT_CVG_ID'  then
11528                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'ELIG_DSBLD_STAT_CVG_ID' ;
11529                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_EDC_unique.information1 ;
11530                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
11531                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
11532                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_EDC_unique.table_route_id;
11533                                                 --
11534                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
11535                                                 --
11536                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
11537                                          end if ;
11538                                          --
11539                                          l_object_found_in_target := true ;
11540                                  --TEMPIK
11541                                  end if; -- l_dt_rec_found
11542                                  --END TEMPIK
11543                    end if;
11544                    close c_find_EDC_in_target ;
11545                  --
11546                  end if;
11547                end if ;
11548                --
11549                close c_EDC_min_max_dates ;
11550 
11551        end if; --if p_dml_operation
11552        --
11553        if not l_object_found_in_target OR l_update  then
11554        --if not l_object_found_in_target then
11555          --
11556          l_current_pk_id := r_EDC.information1;
11557          --
11558          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
11559          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
11560          --
11561          if l_current_pk_id =  l_prev_pk_id  then
11562            --
11563            l_first_rec := false ;
11564            --
11565          else
11566            --
11567            l_first_rec := true ;
11568            --
11569          end if ;
11570          --
11571 
11572          l_effective_date := r_EDC.information2;
11573          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
11574               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
11575            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
11576          end if;
11577 
11578          --if l_first_rec then
11579          if l_first_rec and not l_update then
11580            -- Call Create routine.
11581            hr_utility.set_location(' BEN_ELIG_DSBLD_STAT_CVG_F CREATE_ELIG_DSBLD_STAT_CVG ',20);
11582            BEN_ELIG_DSBLD_STAT_CVG_API.CREATE_ELIG_DSBLD_STAT_CVG(
11583              --
11584              P_VALIDATE               => false
11585              ,P_EFFECTIVE_DATE        => l_effective_date
11586              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
11587              --
11588              ,P_CVG_STRT_CD      => r_EDC.INFORMATION11
11589              ,P_CVG_STRT_RL      => l_CVG_STRT_RL
11590              ,P_CVG_THRU_CD      => r_EDC.INFORMATION12
11591              ,P_CVG_THRU_RL      => l_CVG_THRU_RL
11592              ,P_DPNT_CVG_ELIGY_PRFL_ID      => l_DPNT_CVG_ELIGY_PRFL_ID
11593              ,P_DSBLD_CD      => r_EDC.INFORMATION13
11594              ,P_EDC_ATTRIBUTE1      => r_EDC.INFORMATION111
11595              ,P_EDC_ATTRIBUTE10      => r_EDC.INFORMATION120
11596              ,P_EDC_ATTRIBUTE11      => r_EDC.INFORMATION121
11597              ,P_EDC_ATTRIBUTE12      => r_EDC.INFORMATION122
11598              ,P_EDC_ATTRIBUTE13      => r_EDC.INFORMATION123
11599              ,P_EDC_ATTRIBUTE14      => r_EDC.INFORMATION124
11600              ,P_EDC_ATTRIBUTE15      => r_EDC.INFORMATION125
11601              ,P_EDC_ATTRIBUTE16      => r_EDC.INFORMATION126
11602              ,P_EDC_ATTRIBUTE17      => r_EDC.INFORMATION127
11603              ,P_EDC_ATTRIBUTE18      => r_EDC.INFORMATION128
11604              ,P_EDC_ATTRIBUTE19      => r_EDC.INFORMATION129
11605              ,P_EDC_ATTRIBUTE2      => r_EDC.INFORMATION112
11606              ,P_EDC_ATTRIBUTE20      => r_EDC.INFORMATION130
11607              ,P_EDC_ATTRIBUTE21      => r_EDC.INFORMATION131
11608              ,P_EDC_ATTRIBUTE22      => r_EDC.INFORMATION132
11609              ,P_EDC_ATTRIBUTE23      => r_EDC.INFORMATION133
11610              ,P_EDC_ATTRIBUTE24      => r_EDC.INFORMATION134
11611              ,P_EDC_ATTRIBUTE25      => r_EDC.INFORMATION135
11612              ,P_EDC_ATTRIBUTE26      => r_EDC.INFORMATION136
11613              ,P_EDC_ATTRIBUTE27      => r_EDC.INFORMATION137
11614              ,P_EDC_ATTRIBUTE28      => r_EDC.INFORMATION138
11615              ,P_EDC_ATTRIBUTE29      => r_EDC.INFORMATION139
11616              ,P_EDC_ATTRIBUTE3      => r_EDC.INFORMATION113
11617              ,P_EDC_ATTRIBUTE30      => r_EDC.INFORMATION140
11618              ,P_EDC_ATTRIBUTE4      => r_EDC.INFORMATION114
11619              ,P_EDC_ATTRIBUTE5      => r_EDC.INFORMATION115
11620              ,P_EDC_ATTRIBUTE6      => r_EDC.INFORMATION116
11621              ,P_EDC_ATTRIBUTE7      => r_EDC.INFORMATION117
11622              ,P_EDC_ATTRIBUTE8      => r_EDC.INFORMATION118
11623              ,P_EDC_ATTRIBUTE9      => r_EDC.INFORMATION119
11624              ,P_EDC_ATTRIBUTE_CATEGORY      => r_EDC.INFORMATION110
11625              ,P_ELIG_DSBLD_STAT_CVG_ID      => l_elig_dsbld_stat_cvg_id
11626              --
11627              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
11628              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
11629              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
11630            );
11631            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
11632            -- Update all relevent cer records with new pk_id
11633            hr_utility.set_location('Before plsql table ',222);
11634            hr_utility.set_location('new_value id '||l_elig_dsbld_stat_cvg_id,222);
11635            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'ELIG_DSBLD_STAT_CVG_ID' ;
11636            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_EDC.information1 ;
11637            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_ELIG_DSBLD_STAT_CVG_ID ;
11638            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
11639            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_EDC_unique.table_route_id;
11640            hr_utility.set_location('After plsql table ',222);
11641            --
11642            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
11643            --
11644            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
11645            --
11646          else
11647            --
11648            -- Call Update routine for the pk_id created in prev run .
11649            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
11650            hr_utility.set_location(' BEN_ELIG_DSBLD_STAT_CVG_F UPDATE_ELIG_DSBLD_STAT_CVG ',30);
11651            --UPD START
11652            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
11653            --
11654            if l_update then
11655              --
11656              l_datetrack_mode := r_EDC.datetrack_mode ;
11657              --
11658              get_dt_modes(
11659                p_effective_date        => l_process_date,
11660                p_effective_end_date    => r_EDC.information3,
11661                p_effective_start_date  => r_EDC.information2,
11662                p_dml_operation         => r_EDC.dml_operation,
11663                p_datetrack_mode        => l_datetrack_mode );
11664            --    p_update                => l_update
11665              --
11666              l_effective_date := l_process_date;
11667              l_elig_dsbld_stat_cvg_id   := r_EDC.information1;
11668              l_object_version_number := r_EDC.information265;
11669              --
11670            end if;
11671            --
11672            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
11673            --
11674            IF l_update OR l_dml_operation <> 'UPDATE' THEN
11675            --UPD END
11676 
11677                    BEN_ELIG_DSBLD_STAT_CVG_API.UPDATE_ELIG_DSBLD_STAT_CVG(
11678                      --
11679                      P_VALIDATE               => false
11680                      ,P_EFFECTIVE_DATE        => l_effective_date
11681                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
11682                      --
11683                      ,P_CVG_STRT_CD      => r_EDC.INFORMATION11
11684                      ,P_CVG_STRT_RL      => l_CVG_STRT_RL
11685                      ,P_CVG_THRU_CD      => r_EDC.INFORMATION12
11686                      ,P_CVG_THRU_RL      => l_CVG_THRU_RL
11687                      ,P_DPNT_CVG_ELIGY_PRFL_ID      => l_DPNT_CVG_ELIGY_PRFL_ID
11688                      ,P_DSBLD_CD      => r_EDC.INFORMATION13
11689                      ,P_EDC_ATTRIBUTE1      => r_EDC.INFORMATION111
11690                      ,P_EDC_ATTRIBUTE10      => r_EDC.INFORMATION120
11691                      ,P_EDC_ATTRIBUTE11      => r_EDC.INFORMATION121
11692                      ,P_EDC_ATTRIBUTE12      => r_EDC.INFORMATION122
11693                      ,P_EDC_ATTRIBUTE13      => r_EDC.INFORMATION123
11694                      ,P_EDC_ATTRIBUTE14      => r_EDC.INFORMATION124
11695                      ,P_EDC_ATTRIBUTE15      => r_EDC.INFORMATION125
11696                      ,P_EDC_ATTRIBUTE16      => r_EDC.INFORMATION126
11697                      ,P_EDC_ATTRIBUTE17      => r_EDC.INFORMATION127
11698                      ,P_EDC_ATTRIBUTE18      => r_EDC.INFORMATION128
11699                      ,P_EDC_ATTRIBUTE19      => r_EDC.INFORMATION129
11700                      ,P_EDC_ATTRIBUTE2      => r_EDC.INFORMATION112
11701                      ,P_EDC_ATTRIBUTE20      => r_EDC.INFORMATION130
11702                      ,P_EDC_ATTRIBUTE21      => r_EDC.INFORMATION131
11703                      ,P_EDC_ATTRIBUTE22      => r_EDC.INFORMATION132
11704                      ,P_EDC_ATTRIBUTE23      => r_EDC.INFORMATION133
11705                      ,P_EDC_ATTRIBUTE24      => r_EDC.INFORMATION134
11706                      ,P_EDC_ATTRIBUTE25      => r_EDC.INFORMATION135
11707                      ,P_EDC_ATTRIBUTE26      => r_EDC.INFORMATION136
11708                      ,P_EDC_ATTRIBUTE27      => r_EDC.INFORMATION137
11709                      ,P_EDC_ATTRIBUTE28      => r_EDC.INFORMATION138
11710                      ,P_EDC_ATTRIBUTE29      => r_EDC.INFORMATION139
11711                      ,P_EDC_ATTRIBUTE3      => r_EDC.INFORMATION113
11712                      ,P_EDC_ATTRIBUTE30      => r_EDC.INFORMATION140
11713                      ,P_EDC_ATTRIBUTE4      => r_EDC.INFORMATION114
11714                      ,P_EDC_ATTRIBUTE5      => r_EDC.INFORMATION115
11715                      ,P_EDC_ATTRIBUTE6      => r_EDC.INFORMATION116
11716                      ,P_EDC_ATTRIBUTE7      => r_EDC.INFORMATION117
11717                      ,P_EDC_ATTRIBUTE8      => r_EDC.INFORMATION118
11718                      ,P_EDC_ATTRIBUTE9      => r_EDC.INFORMATION119
11719                      ,P_EDC_ATTRIBUTE_CATEGORY      => r_EDC.INFORMATION110
11720                      ,P_ELIG_DSBLD_STAT_CVG_ID      => l_elig_dsbld_stat_cvg_id
11721                      --
11722                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
11723                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
11724                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
11725                      --,P_DATETRACK_MODE        => hr_api.g_update
11726                      ,P_DATETRACK_MODE        => l_DATETRACK_MODE
11727                    );
11728               end if;  -- l_update
11729          end if;
11730          --
11731          --
11732          -- Delete the row if it is end dated.
11733          --
11734          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
11735              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
11736            trunc(l_max_eed) = r_EDC.information3) then
11737              --
11738              BEN_ELIG_DSBLD_STAT_CVG_API.delete_ELIG_DSBLD_STAT_CVG(
11739                 --
11740                 p_validate                       => false
11741                 ,p_elig_dsbld_stat_cvg_id                   => l_elig_dsbld_stat_cvg_id
11742                 ,p_effective_start_date           => l_effective_start_date
11743                 ,p_effective_end_date             => l_effective_end_date
11744                 ,p_object_version_number          => l_object_version_number
11745                 ,p_effective_date                 => l_max_eed
11746                 ,p_datetrack_mode                 => hr_api.g_delete
11747                 --
11748                 );
11749                 --
11750          end if;
11751          --
11752          l_prev_pk_id := l_current_pk_id ;
11753          --
11754        end if;
11755        --
11756      end if;
11757      --
11758    end loop;
11759    --
11760  exception when others then
11761      --
11762      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'EDC',r_EDC.information5 ) ;
11763      --
11764  end create_EDC_rows;
11765 
11766    --
11767    ---------------------------------------------------------------
11768    ----------------------< create_EMC_rows >-----------------------
11769    ---------------------------------------------------------------
11770    --
11771    procedure create_EMC_rows
11772    (
11773          p_validate                       in  number     default 0
11774         ,p_copy_entity_txn_id             in  number
11775         ,p_effective_date                 in  date
11776         ,p_prefix_suffix_text             in  varchar2  default null
11777         ,p_reuse_object_flag              in  varchar2  default null
11778         ,p_target_business_group_id       in  varchar2  default null
11779         ,p_prefix_suffix_cd               in  varchar2  default null
11780    ) is
11781    --
11782    l_CVG_STRT_RL  number;
11783    l_CVG_THRU_RL  number;
11784    l_DPNT_CVG_ELIGY_PRFL_ID  number;
11785    l_MLTRY_STAT_CD ben_elig_mltry_stat_cvg_f.mltry_stat_cd%type;
11786    cursor c_unique_EMC(l_table_alias varchar2) is
11787    select distinct cpe.information1,
11788      cpe.information2,
11789      cpe.information3,
11790      cpe.table_route_id,
11791      cpe.dml_operation,cpe.datetrack_mode
11792    from ben_copy_entity_results cpe,
11793         pqh_table_route tr
11794    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
11795    and   cpe.table_route_id     = tr.table_route_id
11796    -- and   tr.where_clause        = l_BEN_ELIG_MLTRY_STAT_CVG_F
11797    and   tr.table_alias = l_table_alias
11798    and   cpe.number_of_copies   = 1 -- ADDITION
11799    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
11800    order by information1, information2; --added for bug: 5151945
11801    --
11802    --
11803    cursor c_EMC_min_max_dates(c_table_route_id  number,
11804                 c_information1   number) is
11805    select
11806      min(cpe.information2) min_esd,
11807      max(cpe.information3) min_eed
11808    from ben_copy_entity_results cpe
11809    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
11810    and   cpe.table_route_id     = c_table_route_id
11811    and   cpe.information1       = c_information1 ;
11812    --
11813    cursor c_EMC(c_table_route_id  number,
11814                 c_information1   number,
11815                 c_information2   date,
11816                 c_information3   date)  is
11817    select
11818      cpe.*
11819    from ben_copy_entity_results cpe
11820    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
11821    and   cpe.table_route_id     = c_table_route_id
11822    and   cpe.information1       = c_information1
11823    and   cpe.information2       = c_information2
11824    and   cpe.information3       = c_information3
11825    and rownum = 1 ;
11826    -- Date Track target record
11827    cursor c_find_EMC_in_target(
11828                                 c_effective_start_date    date,
11829                                 c_effective_end_date      date,
11830                                 c_business_group_id       number,
11831                                 c_new_pk_id               number) is
11832    select
11833      EMC.elig_mltry_stat_cvg_id new_value
11834    from BEN_ELIG_MLTRY_STAT_CVG_F EMC
11835    where
11836    nvl(EMC.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
11837    EMC.MLTRY_STAT_CD                        = l_MLTRY_STAT_CD and
11838    EMC.business_group_id  = c_business_group_id
11839    and   EMC.elig_mltry_stat_cvg_id  <> c_new_pk_id
11840 --TEMPIK
11841    and c_effective_start_date between effective_start_date
11842                             and effective_end_date ;
11843 --END TEMPIK
11844 /*TEMPIK
11845    and exists ( select null
11846                 from BEN_ELIG_MLTRY_STAT_CVG_F EMC1
11847                 where
11848                 nvl(EMC1.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
11849                 EMC1.MLTRY_STAT_CD                        = l_MLTRY_STAT_CD and
11850                 EMC1.business_group_id  = c_business_group_id
11851                 and   EMC1.effective_start_date <= c_effective_start_date )
11852    and exists ( select null
11853                 from BEN_ELIG_MLTRY_STAT_CVG_F EMC2
11854                 where
11855                 nvl(EMC2.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
11856                 EMC2.MLTRY_STAT_CD                        = l_MLTRY_STAT_CD and
11857                 EMC2.business_group_id  = c_business_group_id
11858                 and   EMC2.effective_end_date >= c_effective_end_date )
11859                 ;
11860 TEMPIK */
11861    --TEMPIK
11862    l_dt_rec_found            boolean ;
11863    --END TEMPIK
11864     --UPD START
11865    --
11866    l_update                  boolean      := false ;
11867    l_datetrack_mode          varchar2(80) := hr_api.g_update;
11868    l_process_date            date;
11869    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
11870    --
11871    --UPD END
11872    --
11873    l_current_pk_id           number := null ;
11874    l_prev_pk_id              number := null ;
11875    l_first_rec               boolean := true ;
11876    r_EMC                     c_EMC%rowtype;
11877    l_elig_mltry_stat_cvg_id             number ;
11878    l_object_version_number   number ;
11879    l_effective_start_date    date ;
11880    l_effective_end_date      date ;
11881    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
11882    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
11883    l_new_value               number(15);
11884    l_object_found_in_target  boolean := false ;
11885    l_min_esd                 date;
11886    l_max_eed                 date;
11887    l_effective_date          date;
11888    --
11889  begin
11890    -- Initialization
11891    l_object_found_in_target := false ;
11892    -- End Initialization
11893    -- Derive the prefix - sufix
11894    if   p_prefix_suffix_cd = 'PREFIX' then
11895      l_prefix  := p_prefix_suffix_text ;
11896    elsif p_prefix_suffix_cd = 'SUFFIX' then
11897      l_suffix   := p_prefix_suffix_text ;
11898    else
11899      l_prefix := null ;
11900      l_suffix  := null ;
11901    end if ;
11902    -- End Prefix Sufix derivation
11903    for r_EMC_unique in c_unique_EMC('EMC') loop
11904 
11905      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
11906         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
11907          r_EMC_unique.information3 >=
11908                  ben_pd_copy_to_ben_one.g_copy_effective_date)
11909         ) then
11910        --
11911        hr_utility.set_location(' r_EMC_unique.table_route_id '||r_EMC_unique.table_route_id,10);
11912        hr_utility.set_location(' r_EMC_unique.information1 '||r_EMC_unique.information1,10);
11913        hr_utility.set_location( 'r_EMC_unique.information2 '||r_EMC_unique.information2,10);
11914        hr_utility.set_location( 'r_EMC_unique.information3 '||r_EMC_unique.information3,10);
11915        -- If reuse objects flag is 'Y' then check for the object in the target business group
11916        -- if found insert the record into PLSql table and exit the loop else try create the
11917        -- object in the target business group
11918        --
11919        l_object_found_in_target := false ;
11920        --
11921        --UPD START
11922        l_update := false;
11923        l_process_date := p_effective_date;
11924        l_dml_operation:= r_EMC_unique.dml_operation ;
11925 
11926        open c_EMC(r_EMC_unique.table_route_id,
11927                         r_EMC_unique.information1,
11928                         r_EMC_unique.information2,
11929                         r_EMC_unique.information3 ) ;
11930        --
11931        fetch c_EMC into r_EMC ;
11932        --
11933        close c_EMC ;
11934        --
11935        l_CVG_STRT_RL := get_fk('FORMULA_ID', r_EMC.information257,r_EMC.dml_operation);
11936        l_CVG_THRU_RL := get_fk('FORMULA_ID', r_EMC.information258,r_EMC.dml_operation);
11937        l_DPNT_CVG_ELIGY_PRFL_ID := get_fk('DPNT_CVG_ELIGY_PRFL_ID', r_EMC.information255,r_EMC.dml_operation);
11938        l_MLTRY_STAT_CD := r_EMC.information11;
11939        --
11940        if l_dml_operation = 'UPDATE' then
11941          --
11942                  l_object_found_in_target := TRUE;
11943                  --
11944                  if l_process_date between r_EMC_unique.information2 and r_EMC_unique.information3 then
11945                        l_update := true;
11946                        if r_EMC_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
11947                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ELIG_MLTRY_STAT_CVG_ID'
11948                        then
11949                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ELIG_MLTRY_STAT_CVG_ID' ;
11950                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_EMC_unique.information1 ;
11951                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_EMC_unique.information1 ;
11952                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
11953                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_EMC_unique.table_route_id;
11954                           --
11955                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
11956                           --
11957                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
11958                           --
11959                           --BEN_PD_COPY_TO_BEN_ONE.log_data('EMC',l_new_value,l_prefix || r_EMC_unique.name|| l_suffix,'REUSED');
11960                           --
11961                        end if ;
11962                        hr_utility.set_location( 'found record for update',10);
11963                    --
11964                  else
11965                    --
11966                    l_update := false;
11967                    --
11968                  end if;
11969        else
11970          --
11971          --UPD END
11972        --
11973                l_min_esd := null ;
11974                l_max_eed := null ;
11975                open c_EMC_min_max_dates(r_EMC_unique.table_route_id, r_EMC_unique.information1 ) ;
11976                fetch c_EMC_min_max_dates into l_min_esd,l_max_eed ;
11977                --
11978 
11979                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
11980                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
11981                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
11982                end if;
11983                l_min_esd := greatest(l_min_esd,r_EMC_unique.information2);
11984                /*open c_EMC(r_EMC_unique.table_route_id,
11985                         r_EMC_unique.information1,
11986                         r_EMC_unique.information2,
11987                         r_EMC_unique.information3 ) ;
11988                --
11989                fetch c_EMC into r_EMC ;
11990                --
11991                close c_EMC ;*/
11992                --
11993                if p_reuse_object_flag = 'Y' then
11994                  if c_EMC_min_max_dates%found then
11995                    -- cursor to find the object
11996                    open c_find_EMC_in_target( l_min_esd,l_max_eed,
11997                                          p_target_business_group_id, nvl(l_elig_mltry_stat_cvg_id, -999)  ) ;
11998                    fetch c_find_EMC_in_target into l_new_value ;
11999                    if c_find_EMC_in_target%found then
12000                      --TEMPIK
12001                      l_dt_rec_found :=   dt_api.check_min_max_dates
12002                          (p_base_table_name => 'BEN_ELIG_MLTRY_STAT_CVG_F',
12003                           p_base_key_column => 'ELIG_MLTRY_STAT_CVG_ID',
12004                           p_base_key_value  => l_new_value,
12005                           p_from_date       => l_min_esd,
12006                           p_to_date         => l_max_eed );
12007                      if l_dt_rec_found THEN
12008                      --END TEMPIK             --
12009                                          if r_EMC_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
12010                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'ELIG_MLTRY_STAT_CVG_ID'  then
12011                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'ELIG_MLTRY_STAT_CVG_ID' ;
12012                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_EMC_unique.information1 ;
12013                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
12014                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
12015                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_EMC_unique.table_route_id;
12016                                                 --
12017                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
12018                                                 --
12019                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
12020                                          end if ;
12021                                          --
12022                                          l_object_found_in_target := true ;
12023                      --TEMPIK
12024                      end if; -- l_dt_rec_found
12025                      --END TEMPIK
12026                    end if;
12027                    close c_find_EMC_in_target ;
12028                  --
12029                  end if;
12030                end if ;
12031                --
12032                close c_EMC_min_max_dates ;
12033        --
12034        --if not l_object_found_in_target then
12035        end if; --if p_dml_operation
12036        --
12037        if not l_object_found_in_target OR l_update  then
12038          --
12039          l_current_pk_id := r_EMC.information1;
12040          --
12041          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
12042          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
12043          --
12044          if l_current_pk_id =  l_prev_pk_id  then
12045            --
12046            l_first_rec := false ;
12047            --
12048          else
12049            --
12050            l_first_rec := true ;
12051            --
12052          end if ;
12053          --
12054 
12055          l_effective_date := r_EMC.information2;
12056          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
12057               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
12058            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
12059          end if;
12060 
12061          --if l_first_rec then
12062          if l_first_rec and not l_update then
12063            -- Call Create routine.
12064            hr_utility.set_location(' BEN_ELIG_MLTRY_STAT_CVG_F CREATE_ELIG_MLTRY_STAT_CVG ',20);
12065            BEN_ELIG_MLTRY_STAT_CVG_API.CREATE_ELIG_MLTRY_STAT_CVG(
12066              --
12067              P_VALIDATE               => false
12068              ,P_EFFECTIVE_DATE        => l_effective_date
12069              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
12070              --
12071              ,P_CVG_STRT_CD      => r_EMC.INFORMATION12
12072              ,P_CVG_STRT_RL      => l_CVG_STRT_RL
12073              ,P_CVG_THRU_CD      => r_EMC.INFORMATION13
12074              ,P_CVG_THRU_RL      => l_CVG_THRU_RL
12075              ,P_DPNT_CVG_ELIGY_PRFL_ID      => l_DPNT_CVG_ELIGY_PRFL_ID
12076              ,P_ELIG_MLTRY_STAT_CVG_ID      => l_elig_mltry_stat_cvg_id
12077              ,P_EMC_ATTRIBUTE1      => r_EMC.INFORMATION111
12078              ,P_EMC_ATTRIBUTE10      => r_EMC.INFORMATION120
12079              ,P_EMC_ATTRIBUTE11      => r_EMC.INFORMATION121
12080              ,P_EMC_ATTRIBUTE12      => r_EMC.INFORMATION122
12081              ,P_EMC_ATTRIBUTE13      => r_EMC.INFORMATION123
12082              ,P_EMC_ATTRIBUTE14      => r_EMC.INFORMATION124
12083              ,P_EMC_ATTRIBUTE15      => r_EMC.INFORMATION125
12084              ,P_EMC_ATTRIBUTE16      => r_EMC.INFORMATION126
12085              ,P_EMC_ATTRIBUTE17      => r_EMC.INFORMATION127
12086              ,P_EMC_ATTRIBUTE18      => r_EMC.INFORMATION128
12087              ,P_EMC_ATTRIBUTE19      => r_EMC.INFORMATION129
12088              ,P_EMC_ATTRIBUTE2      => r_EMC.INFORMATION112
12089              ,P_EMC_ATTRIBUTE20      => r_EMC.INFORMATION130
12090              ,P_EMC_ATTRIBUTE21      => r_EMC.INFORMATION131
12091              ,P_EMC_ATTRIBUTE22      => r_EMC.INFORMATION132
12092              ,P_EMC_ATTRIBUTE23      => r_EMC.INFORMATION133
12093              ,P_EMC_ATTRIBUTE24      => r_EMC.INFORMATION134
12094              ,P_EMC_ATTRIBUTE25      => r_EMC.INFORMATION135
12095              ,P_EMC_ATTRIBUTE26      => r_EMC.INFORMATION136
12096              ,P_EMC_ATTRIBUTE27      => r_EMC.INFORMATION137
12097              ,P_EMC_ATTRIBUTE28      => r_EMC.INFORMATION138
12098              ,P_EMC_ATTRIBUTE29      => r_EMC.INFORMATION139
12099              ,P_EMC_ATTRIBUTE3      => r_EMC.INFORMATION113
12100              ,P_EMC_ATTRIBUTE30      => r_EMC.INFORMATION140
12101              ,P_EMC_ATTRIBUTE4      => r_EMC.INFORMATION114
12102              ,P_EMC_ATTRIBUTE5      => r_EMC.INFORMATION115
12103              ,P_EMC_ATTRIBUTE6      => r_EMC.INFORMATION116
12104              ,P_EMC_ATTRIBUTE7      => r_EMC.INFORMATION117
12105              ,P_EMC_ATTRIBUTE8      => r_EMC.INFORMATION118
12106              ,P_EMC_ATTRIBUTE9      => r_EMC.INFORMATION119
12107              ,P_EMC_ATTRIBUTE_CATEGORY      => r_EMC.INFORMATION110
12108              ,P_MLTRY_STAT_CD      => r_EMC.INFORMATION11
12109              --
12110              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
12111              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
12112              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
12113            );
12114            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
12115            -- Update all relevent cer records with new pk_id
12116            hr_utility.set_location('Before plsql table ',222);
12117            hr_utility.set_location('new_value id '||l_elig_mltry_stat_cvg_id,222);
12118            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'ELIG_MLTRY_STAT_CVG_ID' ;
12119            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_EMC.information1 ;
12120            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_ELIG_MLTRY_STAT_CVG_ID ;
12121            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
12122            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_EMC_unique.table_route_id;
12123            hr_utility.set_location('After plsql table ',222);
12124            --
12125            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
12126            --
12127            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
12128            --
12129          else
12130            --
12131            -- Call Update routine for the pk_id created in prev run .
12132            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
12133            hr_utility.set_location(' BEN_ELIG_MLTRY_STAT_CVG_F UPDATE_ELIG_MLTRY_STAT_CVG ',30);
12134            --UPD START
12135            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
12136            --
12137            if l_update then
12138              --
12139              l_datetrack_mode := r_EMC.datetrack_mode ;
12140              --
12141              get_dt_modes(
12142                p_effective_date        => l_process_date,
12143                p_effective_end_date    => r_EMC.information3,
12144                p_effective_start_date  => r_EMC.information2,
12145                p_dml_operation         => r_EMC.dml_operation,
12146                p_datetrack_mode        => l_datetrack_mode );
12147            --    p_update                => l_update
12148              --
12149              l_effective_date := l_process_date;
12150              l_elig_mltry_stat_cvg_id  := r_EMC.information1;
12151              l_object_version_number := r_EMC.information265;
12152              --
12153            end if;
12154            --
12155            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
12156            --
12157            IF l_update OR l_dml_operation <> 'UPDATE' THEN
12158            --UPD END
12159 
12160                    BEN_ELIG_MLTRY_STAT_CVG_API.UPDATE_ELIG_MLTRY_STAT_CVG(
12161                      --
12162                      P_VALIDATE               => false
12163                      ,P_EFFECTIVE_DATE        => l_effective_date
12164                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
12165                      --
12166                      ,P_CVG_STRT_CD      => r_EMC.INFORMATION12
12167                      ,P_CVG_STRT_RL      => l_CVG_STRT_RL
12168                      ,P_CVG_THRU_CD      => r_EMC.INFORMATION13
12169                      ,P_CVG_THRU_RL      => l_CVG_THRU_RL
12170                      ,P_DPNT_CVG_ELIGY_PRFL_ID      => l_DPNT_CVG_ELIGY_PRFL_ID
12171                      ,P_ELIG_MLTRY_STAT_CVG_ID      => l_elig_mltry_stat_cvg_id
12172                      ,P_EMC_ATTRIBUTE1      => r_EMC.INFORMATION111
12173                      ,P_EMC_ATTRIBUTE10      => r_EMC.INFORMATION120
12174                      ,P_EMC_ATTRIBUTE11      => r_EMC.INFORMATION121
12175                      ,P_EMC_ATTRIBUTE12      => r_EMC.INFORMATION122
12176                      ,P_EMC_ATTRIBUTE13      => r_EMC.INFORMATION123
12177                      ,P_EMC_ATTRIBUTE14      => r_EMC.INFORMATION124
12178                      ,P_EMC_ATTRIBUTE15      => r_EMC.INFORMATION125
12179                      ,P_EMC_ATTRIBUTE16      => r_EMC.INFORMATION126
12180                      ,P_EMC_ATTRIBUTE17      => r_EMC.INFORMATION127
12181                      ,P_EMC_ATTRIBUTE18      => r_EMC.INFORMATION128
12182                      ,P_EMC_ATTRIBUTE19      => r_EMC.INFORMATION129
12183                      ,P_EMC_ATTRIBUTE2      => r_EMC.INFORMATION112
12184                      ,P_EMC_ATTRIBUTE20      => r_EMC.INFORMATION130
12185                      ,P_EMC_ATTRIBUTE21      => r_EMC.INFORMATION131
12186                      ,P_EMC_ATTRIBUTE22      => r_EMC.INFORMATION132
12187                      ,P_EMC_ATTRIBUTE23      => r_EMC.INFORMATION133
12188                      ,P_EMC_ATTRIBUTE24      => r_EMC.INFORMATION134
12189                      ,P_EMC_ATTRIBUTE25      => r_EMC.INFORMATION135
12190                      ,P_EMC_ATTRIBUTE26      => r_EMC.INFORMATION136
12191                      ,P_EMC_ATTRIBUTE27      => r_EMC.INFORMATION137
12192                      ,P_EMC_ATTRIBUTE28      => r_EMC.INFORMATION138
12193                      ,P_EMC_ATTRIBUTE29      => r_EMC.INFORMATION139
12194                      ,P_EMC_ATTRIBUTE3      => r_EMC.INFORMATION113
12195                      ,P_EMC_ATTRIBUTE30      => r_EMC.INFORMATION140
12196                      ,P_EMC_ATTRIBUTE4      => r_EMC.INFORMATION114
12197                      ,P_EMC_ATTRIBUTE5      => r_EMC.INFORMATION115
12198                      ,P_EMC_ATTRIBUTE6      => r_EMC.INFORMATION116
12199                      ,P_EMC_ATTRIBUTE7      => r_EMC.INFORMATION117
12200                      ,P_EMC_ATTRIBUTE8      => r_EMC.INFORMATION118
12201                      ,P_EMC_ATTRIBUTE9      => r_EMC.INFORMATION119
12202                      ,P_EMC_ATTRIBUTE_CATEGORY      => r_EMC.INFORMATION110
12203                      ,P_MLTRY_STAT_CD      => r_EMC.INFORMATION11
12204                      --
12205                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
12206                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
12207                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
12208                      --,P_DATETRACK_MODE        => hr_api.g_update
12209                      ,P_DATETRACK_MODE        => l_datetrack_mode
12210                    );
12211                end if;  -- l_update
12212          end if;
12213          --
12214          --
12215          -- Delete the row if it is end dated.
12216          --
12217          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
12218              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
12219            trunc(l_max_eed) = r_EMC.information3) then
12220              --
12221              BEN_ELIG_MLTRY_STAT_CVG_API.delete_ELIG_MLTRY_STAT_CVG(
12222                 --
12223                 p_validate                       => false
12224                 ,p_elig_mltry_stat_cvg_id                   => l_elig_mltry_stat_cvg_id
12225                 ,p_effective_start_date           => l_effective_start_date
12226                 ,p_effective_end_date             => l_effective_end_date
12227                 ,p_object_version_number          => l_object_version_number
12228                 ,p_effective_date                 => l_max_eed
12229                 ,p_datetrack_mode                 => hr_api.g_delete
12230                 --
12231                 );
12232                 --
12233          end if;
12234          --
12235          l_prev_pk_id := l_current_pk_id ;
12236          --
12237        end if;
12238        --
12239      end if;
12240      --
12241    end loop;
12242    --
12243  exception when others then
12244      --
12245      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'EMC',r_EMC.information5 ) ;
12246      --
12247  end create_EMC_rows;
12248 
12249    --
12250    ---------------------------------------------------------------
12251    ----------------------< create_EMS_rows >-----------------------
12252    ---------------------------------------------------------------
12253    --
12254    procedure create_EMS_rows
12255    (
12256          p_validate                       in  number     default 0
12257         ,p_copy_entity_txn_id             in  number
12258         ,p_effective_date                 in  date
12259         ,p_prefix_suffix_text             in  varchar2  default null
12260         ,p_reuse_object_flag              in  varchar2  default null
12261         ,p_target_business_group_id       in  varchar2  default null
12262         ,p_prefix_suffix_cd               in  varchar2  default null
12263    ) is
12264    --
12265    l_CVG_STRT_RL  number;
12266    l_CVG_THRU_RL  number;
12267    l_DPNT_CVG_ELIGY_PRFL_ID  number;
12268    l_MRTL_STAT_CD ben_elig_mrtl_stat_cvg_f.mrtl_stat_cd%type;
12269    cursor c_unique_EMS(l_table_alias varchar2) is
12270    select distinct cpe.information1,
12271      cpe.information2,
12272      cpe.information3,
12273      cpe.table_route_id,
12274      cpe.dml_operation,
12275      cpe.datetrack_mode
12276    from ben_copy_entity_results cpe,
12277         pqh_table_route tr
12278    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
12279    and   cpe.table_route_id     = tr.table_route_id
12280    -- and   tr.where_clause        = l_BEN_ELIG_MRTL_STAT_CVG_F
12281    and   tr.table_alias = l_table_alias
12282    and   cpe.number_of_copies   = 1 -- ADDITION
12283    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
12284    order by information1, information2; --added for bug: 5151945
12285    --
12286    --
12287    cursor c_EMS_min_max_dates(c_table_route_id  number,
12288                 c_information1   number) is
12289    select
12290      min(cpe.information2) min_esd,
12291      max(cpe.information3) min_eed
12292    from ben_copy_entity_results cpe
12293    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
12294    and   cpe.table_route_id     = c_table_route_id
12295    and   cpe.information1       = c_information1 ;
12296    --
12297    cursor c_EMS(c_table_route_id  number,
12298                 c_information1   number,
12299                 c_information2   date,
12300                 c_information3   date)  is
12301    select
12302      cpe.*
12303    from ben_copy_entity_results cpe
12304    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
12305    and   cpe.table_route_id     = c_table_route_id
12306    and   cpe.information1       = c_information1
12307    and   cpe.information2       = c_information2
12308    and   cpe.information3       = c_information3
12309    and rownum = 1 ;
12310    -- Date Track target record
12311    cursor c_find_EMS_in_target(
12312                                 c_effective_start_date    date,
12313                                 c_effective_end_date      date,
12314                                 c_business_group_id       number,
12315                                 c_new_pk_id               number) is
12316    select
12317      EMS.elig_mrtl_stat_cvg_id new_value
12318    from BEN_ELIG_MRTL_STAT_CVG_F EMS
12319    where
12320    nvl(EMS.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
12321    EMS.MRTL_STAT_CD                         = l_MRTL_STAT_CD and
12322    EMS.business_group_id  = c_business_group_id
12323    and   EMS.elig_mrtl_stat_cvg_id  <> c_new_pk_id
12324 --TEMPIK
12325    and c_effective_start_date between effective_start_date
12326                             and effective_end_date ;
12327 --END TEMPIK
12328 /*TEMPIK
12329    and exists ( select null
12330                 from BEN_ELIG_MRTL_STAT_CVG_F EMS1
12331                 where
12332                 nvl(EMS1.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
12333                 EMS1.MRTL_STAT_CD                         = l_MRTL_STAT_CD and
12334                 EMS1.business_group_id  = c_business_group_id
12335                 and   EMS1.effective_start_date <= c_effective_start_date )
12336    and exists ( select null
12337                 from BEN_ELIG_MRTL_STAT_CVG_F EMS2
12338                 where
12339                 nvl(EMS2.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
12340                 EMS2.MRTL_STAT_CD                         = l_MRTL_STAT_CD and
12341                 EMS2.business_group_id  = c_business_group_id
12342                 and   EMS2.effective_end_date >= c_effective_end_date )
12343                 ;
12344 TEMPIK */
12345    --TEMPIK
12346    l_dt_rec_found            boolean ;
12347    --END TEMPIK
12348    --
12349    --UPD START
12350    --
12351    l_update                  boolean      := false ;
12352    l_datetrack_mode          varchar2(80) := hr_api.g_update;
12353    l_process_date            date;
12354    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
12355    --
12356    --UPD END
12357    --
12358    l_current_pk_id           number := null ;
12359    l_prev_pk_id              number := null ;
12360    l_first_rec               boolean := true ;
12361    r_EMS                     c_EMS%rowtype;
12362    l_elig_mrtl_stat_cvg_id             number ;
12363    l_object_version_number   number ;
12364    l_effective_start_date    date ;
12365    l_effective_end_date      date ;
12366    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
12367    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
12368    l_new_value               number(15);
12369    l_object_found_in_target  boolean := false ;
12370    l_min_esd                 date;
12371    l_max_eed                 date;
12372    l_effective_date          date;
12373    --
12374  begin
12375    -- Initialization
12376    l_object_found_in_target := false ;
12377    -- End Initialization
12378    -- Derive the prefix - sufix
12379    if   p_prefix_suffix_cd = 'PREFIX' then
12380      l_prefix  := p_prefix_suffix_text ;
12381    elsif p_prefix_suffix_cd = 'SUFFIX' then
12382      l_suffix   := p_prefix_suffix_text ;
12383    else
12384      l_prefix := null ;
12385      l_suffix  := null ;
12386    end if ;
12387    -- End Prefix Sufix derivation
12388    for r_EMS_unique in c_unique_EMS('EMS') loop
12389 
12390      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
12391         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
12392          r_EMS_unique.information3 >=
12393                  ben_pd_copy_to_ben_one.g_copy_effective_date)
12394         ) then
12395        --
12396        hr_utility.set_location(' r_EMS_unique.table_route_id '||r_EMS_unique.table_route_id,10);
12397        hr_utility.set_location(' r_EMS_unique.information1 '||r_EMS_unique.information1,10);
12398        hr_utility.set_location( 'r_EMS_unique.information2 '||r_EMS_unique.information2,10);
12399        hr_utility.set_location( 'r_EMS_unique.information3 '||r_EMS_unique.information3,10);
12400        -- If reuse objects flag is 'Y' then check for the object in the target business group
12401        -- if found insert the record into PLSql table and exit the loop else try create the
12402        -- object in the target business group
12403        --
12404        l_object_found_in_target := false ;
12405        --
12406        --UPD START
12407        l_update := false;
12408        l_process_date := p_effective_date;
12409        l_dml_operation:= r_EMS_unique.dml_operation ; -- bug 4570649
12410 
12411        open c_EMS(r_EMS_unique.table_route_id,
12412                         r_EMS_unique.information1,
12413                         r_EMS_unique.information2,
12414                         r_EMS_unique.information3 ) ;
12415        --
12416        fetch c_EMS into r_EMS ;
12417        --
12418        close c_EMS ;
12419        --
12420        l_CVG_STRT_RL := get_fk('FORMULA_ID', r_EMS.information258,r_EMS.dml_operation);
12421        l_CVG_THRU_RL := get_fk('FORMULA_ID', r_EMS.information259,r_EMS.dml_operation);
12422        l_DPNT_CVG_ELIGY_PRFL_ID := get_fk('DPNT_CVG_ELIGY_PRFL_ID', r_EMS.information255,r_EMS.dml_operation);
12423        l_MRTL_STAT_CD := r_EMS.information11;
12424        --
12425        if l_dml_operation = 'UPDATE' then
12426          --
12427                  l_object_found_in_target := TRUE;
12428                  --
12429                  if l_process_date between r_EMS_unique.information2 and r_EMS_unique.information3 then
12430                        l_update := true;
12431                        if r_EMS_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
12432                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ELIG_MRTL_STAT_CVG_ID'
12433                        then
12434                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ELIG_MRTL_STAT_CVG_ID' ;
12435                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_EMS_unique.information1 ;
12436                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_EMS_unique.information1 ;
12437                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
12438                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_EMS_unique.table_route_id;
12439                           --
12440                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
12441                           --
12442                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
12443                           --
12444                           --BEN_PD_COPY_TO_BEN_ONE.log_data('EMS',l_new_value,l_prefix || r_EMS_unique.name|| l_suffix,'REUSED');
12445                           --
12446                        end if ;
12447                        hr_utility.set_location( 'found record for update',10);
12448                    --
12449                  else
12450                    --
12451                    l_update := false;
12452                    --
12453                  end if;
12454        else
12455          --
12456          --UPD END
12457        --
12458                l_min_esd := null ;
12459                l_max_eed := null ;
12460                open c_EMS_min_max_dates(r_EMS_unique.table_route_id, r_EMS_unique.information1 ) ;
12461                fetch c_EMS_min_max_dates into l_min_esd,l_max_eed ;
12462                --
12463 
12464                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
12465                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
12466                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
12467                end if;
12468                 l_min_esd := greatest(l_min_esd,r_EMS_unique.information2);
12469                /*open c_EMS(r_EMS_unique.table_route_id,
12470                         r_EMS_unique.information1,
12471                         r_EMS_unique.information2,
12472                         r_EMS_unique.information3 ) ;
12473                --
12474                fetch c_EMS into r_EMS ;
12475                --
12476                close c_EMS ;*/
12477                --
12478                if p_reuse_object_flag = 'Y' then
12479                  if c_EMS_min_max_dates%found then
12480                    -- cursor to find the object
12481                    open c_find_EMS_in_target( l_min_esd,l_max_eed,
12482                                          p_target_business_group_id, nvl(l_elig_mrtl_stat_cvg_id, -999)  ) ;
12483                    fetch c_find_EMS_in_target into l_new_value ;
12484                    if c_find_EMS_in_target%found then
12485                      --
12486                      --TEMPIK
12487                      l_dt_rec_found :=   dt_api.check_min_max_dates
12488                          (p_base_table_name => 'BEN_ELIG_MRTL_STAT_CVG_F',
12489                           p_base_key_column => 'ELIG_MRTL_STAT_CVG_ID',
12490                           p_base_key_value  => l_new_value,
12491                           p_from_date       => l_min_esd,
12492                           p_to_date         => l_max_eed );
12493                      if l_dt_rec_found THEN
12494                      --END TEMPIK
12495                                          if r_EMS_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
12496                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'ELIG_MRTL_STAT_CVG_ID'  then
12497                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'ELIG_MRTL_STAT_CVG_ID' ;
12498                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_EMS_unique.information1 ;
12499                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
12500                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
12501                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_EMS_unique.table_route_id;
12502                                                 --
12503                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
12504                                                 --
12505                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
12506                                          end if ;
12507                                          --
12508                                          l_object_found_in_target := true ;
12509                      --TEMPIK
12510                      end if; -- l_dt_rec_found
12511                      --END TEMPIK
12512                    end if;
12513                    close c_find_EMS_in_target ;
12514                  --
12515                  end if;
12516                end if ;
12517                --
12518                close c_EMS_min_max_dates ;
12519 
12520        --if not l_object_found_in_target then
12521        end if; --if p_dml_operation
12522        --
12523        if not l_object_found_in_target OR l_update  then
12524          --
12525          l_current_pk_id := r_EMS.information1;
12526          --
12527          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
12528          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
12529          --
12530          if l_current_pk_id =  l_prev_pk_id  then
12531            --
12532            l_first_rec := false ;
12533            --
12534          else
12535            --
12536            l_first_rec := true ;
12537            --
12538          end if ;
12539          --
12540 
12541          l_effective_date := r_EMS.information2;
12542          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
12543               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
12544            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
12545          end if;
12546 
12547          --if l_first_rec then
12548          if l_first_rec and not l_update then
12549 
12550            -- Call Create routine.
12551            hr_utility.set_location(' BEN_ELIG_MRTL_STAT_CVG_F CREATE_ELIG_MRTL_STAT_CVG ',20);
12552            BEN_ELIG_MRTL_STAT_CVG_API.CREATE_ELIG_MRTL_STAT_CVG(
12553              --
12554              P_VALIDATE               => false
12555              ,P_EFFECTIVE_DATE        => l_effective_date
12556              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
12557              --
12558              ,P_CVG_STRT_CD      => r_EMS.INFORMATION12
12559              ,P_CVG_STRT_RL      => l_CVG_STRT_RL
12560              ,P_CVG_THRU_CD      => r_EMS.INFORMATION13
12561              ,P_CVG_THRU_RL      => l_CVG_THRU_RL
12562              ,P_DPNT_CVG_ELIGY_PRFL_ID      => l_DPNT_CVG_ELIGY_PRFL_ID
12563              ,P_ELIG_MRTL_STAT_CVG_ID      => l_elig_mrtl_stat_cvg_id
12564              ,P_EMS_ATTRIBUTE1      => r_EMS.INFORMATION111
12565              ,P_EMS_ATTRIBUTE10      => r_EMS.INFORMATION120
12566              ,P_EMS_ATTRIBUTE11      => r_EMS.INFORMATION121
12567              ,P_EMS_ATTRIBUTE12      => r_EMS.INFORMATION122
12568              ,P_EMS_ATTRIBUTE13      => r_EMS.INFORMATION123
12569              ,P_EMS_ATTRIBUTE14      => r_EMS.INFORMATION124
12570              ,P_EMS_ATTRIBUTE15      => r_EMS.INFORMATION125
12571              ,P_EMS_ATTRIBUTE16      => r_EMS.INFORMATION126
12572              ,P_EMS_ATTRIBUTE17      => r_EMS.INFORMATION127
12573              ,P_EMS_ATTRIBUTE18      => r_EMS.INFORMATION128
12574              ,P_EMS_ATTRIBUTE19      => r_EMS.INFORMATION129
12575              ,P_EMS_ATTRIBUTE2      => r_EMS.INFORMATION112
12576              ,P_EMS_ATTRIBUTE20      => r_EMS.INFORMATION130
12577              ,P_EMS_ATTRIBUTE21      => r_EMS.INFORMATION131
12578              ,P_EMS_ATTRIBUTE22      => r_EMS.INFORMATION132
12579              ,P_EMS_ATTRIBUTE23      => r_EMS.INFORMATION133
12580              ,P_EMS_ATTRIBUTE24      => r_EMS.INFORMATION134
12581              ,P_EMS_ATTRIBUTE25      => r_EMS.INFORMATION135
12582              ,P_EMS_ATTRIBUTE26      => r_EMS.INFORMATION136
12583              ,P_EMS_ATTRIBUTE27      => r_EMS.INFORMATION137
12584              ,P_EMS_ATTRIBUTE28      => r_EMS.INFORMATION138
12585              ,P_EMS_ATTRIBUTE29      => r_EMS.INFORMATION139
12586              ,P_EMS_ATTRIBUTE3      => r_EMS.INFORMATION113
12587              ,P_EMS_ATTRIBUTE30      => r_EMS.INFORMATION140
12588              ,P_EMS_ATTRIBUTE4      => r_EMS.INFORMATION114
12589              ,P_EMS_ATTRIBUTE5      => r_EMS.INFORMATION115
12590              ,P_EMS_ATTRIBUTE6      => r_EMS.INFORMATION116
12591              ,P_EMS_ATTRIBUTE7      => r_EMS.INFORMATION117
12592              ,P_EMS_ATTRIBUTE8      => r_EMS.INFORMATION118
12593              ,P_EMS_ATTRIBUTE9      => r_EMS.INFORMATION119
12594              ,P_EMS_ATTRIBUTE_CATEGORY      => r_EMS.INFORMATION110
12595              ,P_MRTL_STAT_CD      => r_EMS.INFORMATION11
12596              --
12597              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
12598              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
12599              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
12600            );
12601            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
12602            -- Update all relevent cer records with new pk_id
12603            hr_utility.set_location('Before plsql table ',222);
12604            hr_utility.set_location('new_value id '||l_elig_mrtl_stat_cvg_id,222);
12605            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'ELIG_MRTL_STAT_CVG_ID' ;
12606            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_EMS.information1 ;
12607            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_ELIG_MRTL_STAT_CVG_ID ;
12608            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
12609            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_EMS_unique.table_route_id;
12610            hr_utility.set_location('After plsql table ',222);
12611            --
12612            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
12613            --
12614            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
12615            --
12616          else
12617            --
12618            -- Call Update routine for the pk_id created in prev run .
12619            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
12620            hr_utility.set_location(' BEN_ELIG_MRTL_STAT_CVG_F UPDATE_ELIG_MRTL_STAT_CVG ',30);
12621            --UPD START
12622            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
12623            --
12624            if l_update then
12625              --
12626              l_datetrack_mode := r_EMS.datetrack_mode ;
12627              --
12628              get_dt_modes(
12629                p_effective_date        => l_process_date,
12630                p_effective_end_date    => r_EMS.information3,
12631                p_effective_start_date  => r_EMS.information2,
12632                p_dml_operation         => r_EMS.dml_operation,
12633                p_datetrack_mode        => l_datetrack_mode );
12634            --    p_update                => l_update
12635              --
12636              l_effective_date := l_process_date;
12637              l_elig_mrtl_stat_cvg_id   := r_EMS.information1;
12638              l_object_version_number := r_EMS.information265;
12639              --
12640            end if;
12641            --
12642            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
12643            --
12644            IF l_update OR l_dml_operation <> 'UPDATE' THEN
12645            --UPD END
12646 
12647                    BEN_ELIG_MRTL_STAT_CVG_API.UPDATE_ELIG_MRTL_STAT_CVG(
12648                      --
12649                      P_VALIDATE               => false
12650                      ,P_EFFECTIVE_DATE        => l_effective_date
12651                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
12652                      --
12653                      ,P_CVG_STRT_CD      => r_EMS.INFORMATION12
12654                      ,P_CVG_STRT_RL      => l_CVG_STRT_RL
12655                      ,P_CVG_THRU_CD      => r_EMS.INFORMATION13
12656                      ,P_CVG_THRU_RL      => l_CVG_THRU_RL
12657                      ,P_DPNT_CVG_ELIGY_PRFL_ID      => l_DPNT_CVG_ELIGY_PRFL_ID
12658                      ,P_ELIG_MRTL_STAT_CVG_ID      => l_elig_mrtl_stat_cvg_id
12659                      ,P_EMS_ATTRIBUTE1      => r_EMS.INFORMATION111
12660                      ,P_EMS_ATTRIBUTE10      => r_EMS.INFORMATION120
12661                      ,P_EMS_ATTRIBUTE11      => r_EMS.INFORMATION121
12662                      ,P_EMS_ATTRIBUTE12      => r_EMS.INFORMATION122
12663                      ,P_EMS_ATTRIBUTE13      => r_EMS.INFORMATION123
12664                      ,P_EMS_ATTRIBUTE14      => r_EMS.INFORMATION124
12665                      ,P_EMS_ATTRIBUTE15      => r_EMS.INFORMATION125
12666                      ,P_EMS_ATTRIBUTE16      => r_EMS.INFORMATION126
12667                      ,P_EMS_ATTRIBUTE17      => r_EMS.INFORMATION127
12668                      ,P_EMS_ATTRIBUTE18      => r_EMS.INFORMATION128
12669                      ,P_EMS_ATTRIBUTE19      => r_EMS.INFORMATION129
12670                      ,P_EMS_ATTRIBUTE2      => r_EMS.INFORMATION112
12671                      ,P_EMS_ATTRIBUTE20      => r_EMS.INFORMATION130
12672                      ,P_EMS_ATTRIBUTE21      => r_EMS.INFORMATION131
12673                      ,P_EMS_ATTRIBUTE22      => r_EMS.INFORMATION132
12674                      ,P_EMS_ATTRIBUTE23      => r_EMS.INFORMATION133
12675                      ,P_EMS_ATTRIBUTE24      => r_EMS.INFORMATION134
12676                      ,P_EMS_ATTRIBUTE25      => r_EMS.INFORMATION135
12677                      ,P_EMS_ATTRIBUTE26      => r_EMS.INFORMATION136
12678                      ,P_EMS_ATTRIBUTE27      => r_EMS.INFORMATION137
12679                      ,P_EMS_ATTRIBUTE28      => r_EMS.INFORMATION138
12680                      ,P_EMS_ATTRIBUTE29      => r_EMS.INFORMATION139
12681                      ,P_EMS_ATTRIBUTE3      => r_EMS.INFORMATION113
12682                      ,P_EMS_ATTRIBUTE30      => r_EMS.INFORMATION140
12683                      ,P_EMS_ATTRIBUTE4      => r_EMS.INFORMATION114
12684                      ,P_EMS_ATTRIBUTE5      => r_EMS.INFORMATION115
12685                      ,P_EMS_ATTRIBUTE6      => r_EMS.INFORMATION116
12686                      ,P_EMS_ATTRIBUTE7      => r_EMS.INFORMATION117
12687                      ,P_EMS_ATTRIBUTE8      => r_EMS.INFORMATION118
12688                      ,P_EMS_ATTRIBUTE9      => r_EMS.INFORMATION119
12689                      ,P_EMS_ATTRIBUTE_CATEGORY      => r_EMS.INFORMATION110
12690                      ,P_MRTL_STAT_CD      => r_EMS.INFORMATION11
12691                      --
12692                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
12693                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
12694                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
12695                      --,P_DATETRACK_MODE        => hr_api.g_update
12696                      ,P_DATETRACK_MODE        => l_datetrack_mode
12697                    );
12698                 end if;  -- l_update
12699          end if;
12700          --
12701          --
12702          -- Delete the row if it is end dated.
12703          --
12704          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
12705              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
12706              trunc(l_max_eed) = r_EMS.information3) then
12707              --
12708              BEN_ELIG_MRTL_STAT_CVG_API.delete_ELIG_MRTL_STAT_CVG(
12709                 --
12710                 p_validate                       => false
12711                 ,p_elig_mrtl_stat_cvg_id                   => l_elig_mrtl_stat_cvg_id
12712                 ,p_effective_start_date           => l_effective_start_date
12713                 ,p_effective_end_date             => l_effective_end_date
12714                 ,p_object_version_number          => l_object_version_number
12715                 ,p_effective_date                 => l_max_eed
12716                 ,p_datetrack_mode                 => hr_api.g_delete
12717                 --
12718                 );
12719                 --
12720          end if;
12721          --
12722          l_prev_pk_id := l_current_pk_id ;
12723          --
12724        end if;
12725        --
12726      end if;
12727      --
12728    end loop;
12729    --
12730  exception when others then
12731      --
12732      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'EMS',r_EMS.information5 ) ;
12733      --
12734  end create_EMS_rows;
12735 
12736    --
12737    ---------------------------------------------------------------
12738    ----------------------< create_EPL_rows >-----------------------
12739    ---------------------------------------------------------------
12740    --
12741    procedure create_EPL_rows
12742    (
12743          p_validate                       in  number     default 0
12744         ,p_copy_entity_txn_id             in  number
12745         ,p_effective_date                 in  date
12746         ,p_prefix_suffix_text             in  varchar2  default null
12747         ,p_reuse_object_flag              in  varchar2  default null
12748         ,p_target_business_group_id       in  varchar2  default null
12749         ,p_prefix_suffix_cd               in  varchar2  default null
12750    ) is
12751    --
12752    l_DPNT_CVG_ELIGY_PRFL_ID  number;
12753    l_PSTL_ZIP_RNG_ID  number;
12754    cursor c_unique_EPL(l_table_alias varchar2) is
12755    select distinct cpe.information1,
12756      cpe.information2,
12757      cpe.information3,
12758      cpe.table_route_id,
12759      cpe.dml_operation,
12760      cpe.datetrack_mode
12761    from ben_copy_entity_results cpe,
12762         pqh_table_route tr
12763    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
12764    and   cpe.table_route_id     = tr.table_route_id
12765    -- and   tr.where_clause        = l_BEN_ELIG_PSTL_CD_R_RNG_CVG_F
12766    and   tr.table_alias = l_table_alias
12767    and   cpe.number_of_copies   = 1 -- ADDITION
12768    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
12769    order by information1, information2; --added for bug: 5151945
12770    --
12771    --
12772    cursor c_EPL_min_max_dates(c_table_route_id  number,
12773                 c_information1   number) is
12774    select
12775      min(cpe.information2) min_esd,
12776      max(cpe.information3) min_eed
12777    from ben_copy_entity_results cpe
12778    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
12779    and   cpe.table_route_id     = c_table_route_id
12780    and   cpe.information1       = c_information1 ;
12781    --
12782    cursor c_EPL(c_table_route_id  number,
12783                 c_information1   number,
12784                 c_information2   date,
12785                 c_information3   date)  is
12786    select
12787      cpe.*
12788    from ben_copy_entity_results cpe
12789    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
12790    and   cpe.table_route_id     = c_table_route_id
12791    and   cpe.information1       = c_information1
12792    and   cpe.information2       = c_information2
12793    and   cpe.information3       = c_information3
12794    and rownum = 1 ;
12795    -- Date Track target record
12796    cursor c_find_EPL_in_target(
12797                                 c_effective_start_date    date,
12798                                 c_effective_end_date      date,
12799                                 c_business_group_id       number,
12800                                 c_new_pk_id               number) is
12801    select
12802      EPL.elig_pstl_cd_r_rng_cvg_id new_value
12803    from BEN_ELIG_PSTL_CD_R_RNG_CVG_F EPL
12804    where
12805    nvl(EPL.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
12806    nvl(EPL.PSTL_ZIP_RNG_ID,-999)     = nvl(l_PSTL_ZIP_RNG_ID,-999)  and
12807    EPL.business_group_id  = c_business_group_id
12808    and   EPL.elig_pstl_cd_r_rng_cvg_id  <> c_new_pk_id
12809 --TEMPIK
12810    and c_effective_start_date between effective_start_date
12811                             and effective_end_date ;
12812 --END TEMPIK
12813 /*TEMPIK
12814    and exists ( select null
12815                 from BEN_ELIG_PSTL_CD_R_RNG_CVG_F EPL1
12816                 where
12817                 nvl(EPL1.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
12818                 nvl(EPL1.PSTL_ZIP_RNG_ID,-999)     = nvl(l_PSTL_ZIP_RNG_ID,-999)  and
12819                 EPL1.business_group_id  = c_business_group_id
12820                 and   EPL1.effective_start_date <= c_effective_start_date )
12821    and exists ( select null
12822                 from BEN_ELIG_PSTL_CD_R_RNG_CVG_F EPL2
12823                 where
12824                 nvl(EPL2.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
12825                 nvl(EPL2.PSTL_ZIP_RNG_ID,-999)     = nvl(l_PSTL_ZIP_RNG_ID,-999)  and
12826                 EPL2.business_group_id  = c_business_group_id
12827                 and   EPL2.effective_end_date >= c_effective_end_date )
12828                 ;
12829 TEMPIK */
12830    --TEMPIK
12831    l_dt_rec_found            boolean ;
12832    --END TEMPIK
12833    --
12834    --UPD START
12835    --
12836    l_update                  boolean      := false ;
12837    l_datetrack_mode          varchar2(80) := hr_api.g_update;
12838    l_process_date            date;
12839    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
12840    --
12841    --UPD END
12842    --
12843    l_current_pk_id           number := null ;
12844    l_prev_pk_id              number := null ;
12845    l_first_rec               boolean := true ;
12846    r_EPL                     c_EPL%rowtype;
12847    l_elig_pstl_cd_r_rng_cvg_id             number ;
12848    l_object_version_number   number ;
12849    l_effective_start_date    date ;
12850    l_effective_end_date      date ;
12851    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
12852    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
12853    l_new_value               number(15);
12854    l_object_found_in_target  boolean := false ;
12855    l_min_esd                 date;
12856    l_max_eed                 date;
12857    l_effective_date          date;
12858    --
12859  begin
12860    -- Initialization
12861    l_object_found_in_target := false ;
12862    -- End Initialization
12863    -- Derive the prefix - sufix
12864    if   p_prefix_suffix_cd = 'PREFIX' then
12865      l_prefix  := p_prefix_suffix_text ;
12866    elsif p_prefix_suffix_cd = 'SUFFIX' then
12867      l_suffix   := p_prefix_suffix_text ;
12868    else
12869      l_prefix := null ;
12870      l_suffix  := null ;
12871    end if ;
12872    -- End Prefix Sufix derivation
12873    for r_EPL_unique in c_unique_EPL('EPL') loop
12874 
12875      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
12876         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
12877          r_EPL_unique.information3 >=
12878                   ben_pd_copy_to_ben_one.g_copy_effective_date)
12879         ) then
12880        --
12881        hr_utility.set_location(' r_EPL_unique.table_route_id '||r_EPL_unique.table_route_id,10);
12882        hr_utility.set_location(' r_EPL_unique.information1 '||r_EPL_unique.information1,10);
12883        hr_utility.set_location( 'r_EPL_unique.information2 '||r_EPL_unique.information2,10);
12884        hr_utility.set_location( 'r_EPL_unique.information3 '||r_EPL_unique.information3,10);
12885        -- If reuse objects flag is 'Y' then check for the object in the target business group
12886        -- if found insert the record into PLSql table and exit the loop else try create the
12887        -- object in the target business group
12888        --
12889        l_object_found_in_target := false ;
12890        --UPD START
12891        l_update := false;
12892        l_process_date := p_effective_date;
12893        l_dml_operation:= r_EPL_unique.dml_operation ;
12894        open c_EPL(r_EPL_unique.table_route_id,
12895                 r_EPL_unique.information1,
12896                 r_EPL_unique.information2,
12897                 r_EPL_unique.information3 ) ;
12898        --
12899        fetch c_EPL into r_EPL ;
12900        --
12901        close c_EPL ;
12902        --
12903        l_DPNT_CVG_ELIGY_PRFL_ID := get_fk('DPNT_CVG_ELIGY_PRFL_ID', r_EPL.information255,r_EPL.dml_operation);
12904        l_PSTL_ZIP_RNG_ID := get_fk('PSTL_ZIP_RNG_ID', r_EPL.information245,r_EPL.dml_operation);
12905        --
12906        if l_dml_operation = 'UPDATE' then
12907          --
12908                  l_object_found_in_target := TRUE;
12909                  --
12910                  if l_process_date between r_EPL_unique.information2 and r_EPL_unique.information3 then
12911                        l_update := true;
12912                        if r_EPL_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
12913                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ELIG_PSTL_CD_R_RNG_CVG_ID'
12914                        then
12915                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ELIG_PSTL_CD_R_RNG_CVG_ID' ;
12916                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_EPL_unique.information1 ;
12917                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_EPL_unique.information1 ;
12918                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
12919                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_EPL_unique.table_route_id;
12920                           --
12921                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
12922                           --
12923                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
12924                           --
12925                          -- BEN_PD_COPY_TO_BEN_ONE.log_data('EPL',l_new_value,l_prefix || r_EPL_unique.name|| l_suffix,'REUSED');
12926                           --
12927                        end if ;
12928                        hr_utility.set_location( 'found record for update',10);
12929                    --
12930                  else
12931                    --
12932                    l_update := false;
12933                    --
12934                  end if;
12935        else
12936          --
12937          --UPD END
12938                l_min_esd := null ;
12939                l_max_eed := null ;
12940                open c_EPL_min_max_dates(r_EPL_unique.table_route_id, r_EPL_unique.information1 ) ;
12941                fetch c_EPL_min_max_dates into l_min_esd,l_max_eed ;
12942                --
12943 
12944                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
12945                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
12946                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
12947                end if;
12948                l_min_esd := greatest(l_min_esd,r_EPL_unique.information2);
12949                --
12950                if p_reuse_object_flag = 'Y' then
12951                  if c_EPL_min_max_dates%found then
12952                    -- cursor to find the object
12953                    open c_find_EPL_in_target( l_min_esd,l_max_eed,
12954                                          p_target_business_group_id, nvl(l_elig_pstl_cd_r_rng_cvg_id, -999)  ) ;
12955                    fetch c_find_EPL_in_target into l_new_value ;
12956                    if c_find_EPL_in_target%found then
12957                      --TEMPIK
12958                      l_dt_rec_found :=   dt_api.check_min_max_dates
12959                          (p_base_table_name => 'BEN_ELIG_PSTL_CD_R_RNG_CVG_F',
12960                           p_base_key_column => 'ELIG_PSTL_CD_R_RNG_CVG_ID',
12961                           p_base_key_value  => l_new_value,
12962                           p_from_date       => l_min_esd,
12963                           p_to_date         => l_max_eed );
12964                      if l_dt_rec_found THEN
12965                      --END TEMPIK             --
12966                                          if r_EPL_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
12967                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'ELIG_PSTL_CD_R_RNG_CVG_ID'  then
12968                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'ELIG_PSTL_CD_R_RNG_CVG_ID' ;
12969                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_EPL_unique.information1 ;
12970                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
12971                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
12972                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_EPL_unique.table_route_id;
12973                                                 --
12974                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
12975                                                 --
12976                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
12977                                          end if ;
12978                                          --
12979                                          l_object_found_in_target := true ;
12980                      --TEMPIK
12981                      end if; -- l_dt_rec_found
12982                      --END TEMPIK
12983                    end if;
12984                    close c_find_EPL_in_target ;
12985                  --
12986                  end if;
12987                end if ;
12988                --
12989                close c_EPL_min_max_dates ;
12990          --if not l_object_found_in_target then
12991        end if; --if p_dml_operation
12992        --
12993        if not l_object_found_in_target OR l_update  then
12994 
12995          --
12996          l_current_pk_id := r_EPL.information1;
12997          --
12998          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
12999          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
13000          --
13001          if l_current_pk_id =  l_prev_pk_id  then
13002            --
13003            l_first_rec := false ;
13004            --
13005          else
13006            --
13007            l_first_rec := true ;
13008            --
13009          end if ;
13010          --
13011 
13012          l_effective_date := r_EPL.information2;
13013          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
13014               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
13015            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
13016          end if;
13017 
13018          --if l_first_rec then
13019          if l_first_rec and not l_update then
13020            -- Call Create routine.
13021            hr_utility.set_location(' BEN_ELIG_PSTL_CD_R_RNG_CVG_F CREATE_ELIG_PSTL_CD_CVG ',20);
13022            BEN_ELIG_PSTL_CD_CVG_API.CREATE_ELIG_PSTL_CD_CVG(
13023              --
13024              P_VALIDATE               => false
13025              ,P_EFFECTIVE_DATE        => l_effective_date
13026              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
13027              --
13028              ,P_DPNT_CVG_ELIGY_PRFL_ID      => l_DPNT_CVG_ELIGY_PRFL_ID
13029              ,P_ELIG_PSTL_CD_R_RNG_CVG_ID      => l_elig_pstl_cd_r_rng_cvg_id
13030              ,P_EPL_ATTRIBUTE1      => r_EPL.INFORMATION111
13031              ,P_EPL_ATTRIBUTE10      => r_EPL.INFORMATION120
13032              ,P_EPL_ATTRIBUTE11      => r_EPL.INFORMATION121
13033              ,P_EPL_ATTRIBUTE12      => r_EPL.INFORMATION122
13034              ,P_EPL_ATTRIBUTE13      => r_EPL.INFORMATION123
13035              ,P_EPL_ATTRIBUTE14      => r_EPL.INFORMATION124
13036              ,P_EPL_ATTRIBUTE15      => r_EPL.INFORMATION125
13037              ,P_EPL_ATTRIBUTE16      => r_EPL.INFORMATION126
13038              ,P_EPL_ATTRIBUTE17      => r_EPL.INFORMATION127
13039              ,P_EPL_ATTRIBUTE18      => r_EPL.INFORMATION128
13040              ,P_EPL_ATTRIBUTE19      => r_EPL.INFORMATION129
13041              ,P_EPL_ATTRIBUTE2      => r_EPL.INFORMATION112
13042              ,P_EPL_ATTRIBUTE20      => r_EPL.INFORMATION130
13043              ,P_EPL_ATTRIBUTE21      => r_EPL.INFORMATION131
13044              ,P_EPL_ATTRIBUTE22      => r_EPL.INFORMATION132
13045              ,P_EPL_ATTRIBUTE23      => r_EPL.INFORMATION133
13046              ,P_EPL_ATTRIBUTE24      => r_EPL.INFORMATION134
13047              ,P_EPL_ATTRIBUTE25      => r_EPL.INFORMATION135
13048              ,P_EPL_ATTRIBUTE26      => r_EPL.INFORMATION136
13049              ,P_EPL_ATTRIBUTE27      => r_EPL.INFORMATION137
13050              ,P_EPL_ATTRIBUTE28      => r_EPL.INFORMATION138
13051              ,P_EPL_ATTRIBUTE29      => r_EPL.INFORMATION139
13052              ,P_EPL_ATTRIBUTE3      => r_EPL.INFORMATION113
13053              ,P_EPL_ATTRIBUTE30      => r_EPL.INFORMATION140
13054              ,P_EPL_ATTRIBUTE4      => r_EPL.INFORMATION114
13055              ,P_EPL_ATTRIBUTE5      => r_EPL.INFORMATION115
13056              ,P_EPL_ATTRIBUTE6      => r_EPL.INFORMATION116
13057              ,P_EPL_ATTRIBUTE7      => r_EPL.INFORMATION117
13058              ,P_EPL_ATTRIBUTE8      => r_EPL.INFORMATION118
13059              ,P_EPL_ATTRIBUTE9      => r_EPL.INFORMATION119
13060              ,P_EPL_ATTRIBUTE_CATEGORY      => r_EPL.INFORMATION110
13061              ,P_EXCLD_FLAG      => r_EPL.INFORMATION11
13062              ,P_ORDR_NUM      => r_EPL.INFORMATION260
13063              ,P_PSTL_ZIP_RNG_ID      => l_PSTL_ZIP_RNG_ID
13064              --
13065              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
13066              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
13067              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
13068            );
13069            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
13070            -- Update all relevent cer records with new pk_id
13071            hr_utility.set_location('Before plsql table ',222);
13072            hr_utility.set_location('new_value id '||l_elig_pstl_cd_r_rng_cvg_id,222);
13073            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'ELIG_PSTL_CD_R_RNG_CVG_ID' ;
13074            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_EPL.information1 ;
13075            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_ELIG_PSTL_CD_R_RNG_CVG_ID ;
13076            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
13077            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_EPL_unique.table_route_id;
13078            hr_utility.set_location('After plsql table ',222);
13079            --
13080            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
13081            --
13082            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
13083            --
13084          else
13085            --
13086            -- Call Update routine for the pk_id created in prev run .
13087            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
13088            hr_utility.set_location(' BEN_ELIG_PSTL_CD_R_RNG_CVG_F UPDATE_ELIG_PSTL_CD_CVG ',30);
13089            --UPD START
13090            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
13091            --
13092            if l_update then
13093              --
13094              l_datetrack_mode := r_EPL.datetrack_mode ;
13095              --
13096              get_dt_modes(
13097                p_effective_date        => l_process_date,
13098                p_effective_end_date    => r_EPL.information3,
13099                p_effective_start_date  => r_EPL.information2,
13100                p_dml_operation         => r_EPL.dml_operation,
13101                p_datetrack_mode        => l_datetrack_mode );
13102            --    p_update                => l_update
13103              --
13104              l_effective_date := l_process_date;
13105              l_elig_pstl_cd_r_rng_cvg_id   := r_EPL.information1;
13106              l_object_version_number := r_EPL.information265;
13107              --
13108            end if;
13109            --
13110            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
13111            --
13112            IF l_update OR l_dml_operation <> 'UPDATE' THEN
13113            --UPD END
13114 
13115                    BEN_ELIG_PSTL_CD_CVG_API.UPDATE_ELIG_PSTL_CD_CVG(
13116                      --
13117                      P_VALIDATE               => false
13118                      ,P_EFFECTIVE_DATE        => l_effective_date
13119                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
13120                      --
13121                      ,P_DPNT_CVG_ELIGY_PRFL_ID      => l_DPNT_CVG_ELIGY_PRFL_ID
13122                      ,P_ELIG_PSTL_CD_R_RNG_CVG_ID      => l_elig_pstl_cd_r_rng_cvg_id
13123                      ,P_EPL_ATTRIBUTE1      => r_EPL.INFORMATION111
13124                      ,P_EPL_ATTRIBUTE10      => r_EPL.INFORMATION120
13125                      ,P_EPL_ATTRIBUTE11      => r_EPL.INFORMATION121
13126                      ,P_EPL_ATTRIBUTE12      => r_EPL.INFORMATION122
13127                      ,P_EPL_ATTRIBUTE13      => r_EPL.INFORMATION123
13128                      ,P_EPL_ATTRIBUTE14      => r_EPL.INFORMATION124
13129                      ,P_EPL_ATTRIBUTE15      => r_EPL.INFORMATION125
13130                      ,P_EPL_ATTRIBUTE16      => r_EPL.INFORMATION126
13131                      ,P_EPL_ATTRIBUTE17      => r_EPL.INFORMATION127
13132                      ,P_EPL_ATTRIBUTE18      => r_EPL.INFORMATION128
13133                      ,P_EPL_ATTRIBUTE19      => r_EPL.INFORMATION129
13134                      ,P_EPL_ATTRIBUTE2      => r_EPL.INFORMATION112
13135                      ,P_EPL_ATTRIBUTE20      => r_EPL.INFORMATION130
13136                      ,P_EPL_ATTRIBUTE21      => r_EPL.INFORMATION131
13137                      ,P_EPL_ATTRIBUTE22      => r_EPL.INFORMATION132
13138                      ,P_EPL_ATTRIBUTE23      => r_EPL.INFORMATION133
13139                      ,P_EPL_ATTRIBUTE24      => r_EPL.INFORMATION134
13140                      ,P_EPL_ATTRIBUTE25      => r_EPL.INFORMATION135
13141                      ,P_EPL_ATTRIBUTE26      => r_EPL.INFORMATION136
13142                      ,P_EPL_ATTRIBUTE27      => r_EPL.INFORMATION137
13143                      ,P_EPL_ATTRIBUTE28      => r_EPL.INFORMATION138
13144                      ,P_EPL_ATTRIBUTE29      => r_EPL.INFORMATION139
13145                      ,P_EPL_ATTRIBUTE3      => r_EPL.INFORMATION113
13146                      ,P_EPL_ATTRIBUTE30      => r_EPL.INFORMATION140
13147                      ,P_EPL_ATTRIBUTE4      => r_EPL.INFORMATION114
13148                      ,P_EPL_ATTRIBUTE5      => r_EPL.INFORMATION115
13149                      ,P_EPL_ATTRIBUTE6      => r_EPL.INFORMATION116
13150                      ,P_EPL_ATTRIBUTE7      => r_EPL.INFORMATION117
13151                      ,P_EPL_ATTRIBUTE8      => r_EPL.INFORMATION118
13152                      ,P_EPL_ATTRIBUTE9      => r_EPL.INFORMATION119
13153                      ,P_EPL_ATTRIBUTE_CATEGORY      => r_EPL.INFORMATION110
13154                      ,P_EXCLD_FLAG      => r_EPL.INFORMATION11
13155                      ,P_ORDR_NUM      => r_EPL.INFORMATION260
13156                      ,P_PSTL_ZIP_RNG_ID      => l_PSTL_ZIP_RNG_ID
13157                      --
13158                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
13159                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
13160                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
13161                      --,P_DATETRACK_MODE        => hr_api.g_update
13162                      ,P_DATETRACK_MODE        => l_datetrack_mode
13163                    );
13164               end if;  -- l_update
13165          end if;
13166          --
13167          --
13168          -- Delete the row if it is end dated.
13169          --
13170          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
13171              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
13172              trunc(l_max_eed) = r_EPL.information3) then
13173              --
13174              BEN_ELIG_PSTL_CD_CVG_API.delete_ELIG_PSTL_CD_CVG(
13175                 --
13176                 p_validate                       => false
13177                 ,p_elig_pstl_cd_r_rng_cvg_id                   => l_elig_pstl_cd_r_rng_cvg_id
13178                 ,p_effective_start_date           => l_effective_start_date
13179                 ,p_effective_end_date             => l_effective_end_date
13180                 ,p_object_version_number          => l_object_version_number
13181                 ,p_effective_date                 => l_max_eed
13182                 ,p_datetrack_mode                 => hr_api.g_delete
13183                 --
13184                 );
13185                 --
13186          --
13187          end if;
13188          --
13189          l_prev_pk_id := l_current_pk_id ;
13190          --
13191        end if;
13192        --
13193      end if;
13194      --
13195    end loop;
13196    --
13197  exception when others then
13198      --
13199      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'EPL',r_EPL.information5 ) ;
13200      --
13201  end create_EPL_rows;
13202 
13203    --
13204    ---------------------------------------------------------------
13205    ----------------------< create_ESC_rows >-----------------------
13206    ---------------------------------------------------------------
13207    --
13208    procedure create_ESC_rows
13209    (
13210          p_validate                       in  number     default 0
13211         ,p_copy_entity_txn_id             in  number
13212         ,p_effective_date                 in  date
13213         ,p_prefix_suffix_text             in  varchar2  default null
13214         ,p_reuse_object_flag              in  varchar2  default null
13215         ,p_target_business_group_id       in  varchar2  default null
13216         ,p_prefix_suffix_cd               in  varchar2  default null
13217    ) is
13218    --
13219    l_CVG_STRT_RL  number;
13220    l_CVG_THRU_RL  number;
13221    l_DPNT_CVG_ELIGY_PRFL_ID  number;
13222    l_STDNT_STAT_CD ben_elig_stdnt_stat_cvg_f.stdnt_stat_cd%type;
13223    cursor c_unique_ESC(l_table_alias varchar2) is
13224    select distinct cpe.information1,
13225      cpe.information2,
13226      cpe.information3,
13227      cpe.table_route_id,
13228      cpe.dml_operation,cpe.datetrack_mode
13229    from ben_copy_entity_results cpe,
13230         pqh_table_route tr
13231    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
13232    and   cpe.table_route_id     = tr.table_route_id
13233    -- and   tr.where_clause        = l_BEN_ELIG_STDNT_STAT_CVG_F
13234    and   tr.table_alias = l_table_alias
13235    and   cpe.number_of_copies   = 1 -- ADDITION
13236    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
13237    order by information1, information2; --added for bug: 5151945
13238    --
13239    --
13240    cursor c_ESC_min_max_dates(c_table_route_id  number,
13241                 c_information1   number) is
13242    select
13243      min(cpe.information2) min_esd,
13244      max(cpe.information3) min_eed
13245    from ben_copy_entity_results cpe
13246    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
13247    and   cpe.table_route_id     = c_table_route_id
13248    and   cpe.information1       = c_information1 ;
13249    --
13250    cursor c_ESC(c_table_route_id  number,
13251                 c_information1   number,
13252                 c_information2   date,
13253                 c_information3   date)  is
13254    select
13255      cpe.*
13256    from ben_copy_entity_results cpe
13257    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
13258    and   cpe.table_route_id     = c_table_route_id
13259    and   cpe.information1       = c_information1
13260    and   cpe.information2       = c_information2
13261    and   cpe.information3       = c_information3
13262    and rownum = 1 ;
13263    -- Date Track target record
13264    cursor c_find_ESC_in_target(
13265                                 c_effective_start_date    date,
13266                                 c_effective_end_date      date,
13267                                 c_business_group_id       number,
13268                                 c_new_pk_id               number) is
13269    select
13270      ESC.elig_stdnt_stat_cvg_id new_value
13271    from BEN_ELIG_STDNT_STAT_CVG_F ESC
13272    where
13273    nvl(ESC.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
13274    ESC.STDNT_STAT_CD                        = l_STDNT_STAT_CD and
13275    ESC.business_group_id  = c_business_group_id
13276    and   ESC.elig_stdnt_stat_cvg_id  <> c_new_pk_id
13277 --TEMPIK
13278    and c_effective_start_date between effective_start_date
13279                             and effective_end_date ;
13280 --END TEMPIK
13281 /*TEMPIK
13282         and exists ( select null
13283                 from BEN_ELIG_STDNT_STAT_CVG_F ESC1
13284                 where
13285                 nvl(ESC1.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
13286                 ESC1.STDNT_STAT_CD                        = l_STDNT_STAT_CD and
13287                 ESC1.business_group_id  = c_business_group_id
13288                 and   ESC1.effective_start_date <= c_effective_start_date )
13289    and exists ( select null
13290                 from BEN_ELIG_STDNT_STAT_CVG_F ESC2
13291                 where
13292                 nvl(ESC2.DPNT_CVG_ELIGY_PRFL_ID,-999)     = nvl(l_DPNT_CVG_ELIGY_PRFL_ID,-999)  and
13293                 ESC2.STDNT_STAT_CD                        = l_STDNT_STAT_CD and
13294                 ESC2.business_group_id  = c_business_group_id
13295                 and   ESC2.effective_end_date >= c_effective_end_date )
13296                 ;
13297 TEMPIK */
13298    --TEMPIK
13299    l_dt_rec_found            boolean ;
13300    --END TEMPIK
13301    --
13302    --UPD START
13303    --
13304    l_update                  boolean      := false ;
13305    l_datetrack_mode          varchar2(80) := hr_api.g_update;
13306    l_process_date            date;
13307    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
13308    --
13309    --UPD END
13310    --
13311    l_current_pk_id           number := null ;
13312    l_prev_pk_id              number := null ;
13313    l_first_rec               boolean := true ;
13314    r_ESC                     c_ESC%rowtype;
13315    l_elig_stdnt_stat_cvg_id             number ;
13316    l_object_version_number   number ;
13317    l_effective_start_date    date ;
13318    l_effective_end_date      date ;
13319    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
13320    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
13321    l_new_value               number(15);
13322    l_object_found_in_target  boolean := false ;
13323    l_min_esd                 date;
13324    l_max_eed                 date;
13325    l_effective_date          date;
13326    --
13327  begin
13328    -- Initialization
13329    l_object_found_in_target := false ;
13330    -- End Initialization
13331    -- Derive the prefix - sufix
13332    if   p_prefix_suffix_cd = 'PREFIX' then
13333      l_prefix  := p_prefix_suffix_text ;
13334    elsif p_prefix_suffix_cd = 'SUFFIX' then
13335      l_suffix   := p_prefix_suffix_text ;
13336    else
13337      l_prefix := null ;
13338      l_suffix  := null ;
13339    end if ;
13340    -- End Prefix Sufix derivation
13341    for r_ESC_unique in c_unique_ESC('ESC') loop
13342 
13343      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
13344         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
13345          r_ESC_unique.information3 >=
13346                  ben_pd_copy_to_ben_one.g_copy_effective_date)
13347         ) then
13348        --
13349        hr_utility.set_location(' r_ESC_unique.table_route_id '||r_ESC_unique.table_route_id,10);
13350        hr_utility.set_location(' r_ESC_unique.information1 '||r_ESC_unique.information1,10);
13351        hr_utility.set_location( 'r_ESC_unique.information2 '||r_ESC_unique.information2,10);
13352        hr_utility.set_location( 'r_ESC_unique.information3 '||r_ESC_unique.information3,10);
13353        -- If reuse objects flag is 'Y' then check for the object in the target business group
13354        -- if found insert the record into PLSql table and exit the loop else try create the
13355        -- object in the target business group
13356        --
13357        l_object_found_in_target := false ;
13358        --
13359        --UPD START
13360        l_update := false;
13361        l_process_date := p_effective_date;
13362        l_dml_operation:= r_ESC_unique.dml_operation ;
13363        --
13364        open c_ESC(r_ESC_unique.table_route_id,
13365                   r_ESC_unique.information1,
13366                         r_ESC_unique.information2,
13367                         r_ESC_unique.information3 ) ;
13368        --
13369        fetch c_ESC into r_ESC ;
13370        --
13371        close c_ESC ;
13372        --
13373        l_CVG_STRT_RL := get_fk('FORMULA_ID', r_ESC.information260,r_ESC.dml_operation);
13374        l_CVG_THRU_RL := get_fk('FORMULA_ID', r_ESC.information261,r_ESC.dml_operation);
13375        l_DPNT_CVG_ELIGY_PRFL_ID := get_fk('DPNT_CVG_ELIGY_PRFL_ID', r_ESC.information255,r_ESC.dml_operation);
13376        l_STDNT_STAT_CD := r_ESC.information13;
13377        --
13378        if l_dml_operation = 'UPDATE' then
13379          --
13380                  l_object_found_in_target := TRUE;
13381                  --
13382                  if l_process_date between r_ESC_unique.information2 and r_ESC_unique.information3 then
13383                        l_update := true;
13384                        if r_ESC_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
13385                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ELIG_STDNT_STAT_CVG_ID'
13386                        then
13387                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ELIG_STDNT_STAT_CVG_ID' ;
13388                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_ESC_unique.information1 ;
13389                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_ESC_unique.information1 ;
13390                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
13391                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_ESC_unique.table_route_id;
13392                           --
13393                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
13394                           --
13395                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
13396                           --
13397                           --BEN_PD_COPY_TO_BEN_ONE.log_data('ESC',l_new_value,l_prefix || r_ESC_unique.name|| l_suffix,'REUSED');
13398                           --
13399                        end if ;
13400                        hr_utility.set_location( 'found record for update',10);
13401                    --
13402                  else
13403                    --
13404                    l_update := false;
13405                    --
13406                  end if;
13407        else
13408          --
13409          --UPD END
13410        --
13411                l_min_esd := null ;
13412                l_max_eed := null ;
13413                open c_ESC_min_max_dates(r_ESC_unique.table_route_id, r_ESC_unique.information1 ) ;
13414                fetch c_ESC_min_max_dates into l_min_esd,l_max_eed ;
13415                --
13416 
13417                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
13418                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
13419                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
13420                end if;
13421                l_min_esd := greatest(l_min_esd,r_ESC_unique.information2);
13422                /*open c_ESC(r_ESC_unique.table_route_id,
13423                         r_ESC_unique.information1,
13424                         r_ESC_unique.information2,
13425                         r_ESC_unique.information3 ) ;
13426                --
13427                fetch c_ESC into r_ESC ;
13428                --
13429                close c_ESC ;*/
13430                --
13431                if p_reuse_object_flag = 'Y' then
13432                  if c_ESC_min_max_dates%found then
13433                    -- cursor to find the object
13434                    open c_find_ESC_in_target( l_min_esd,l_max_eed,
13435                                          p_target_business_group_id, nvl(l_elig_stdnt_stat_cvg_id, -999)  ) ;
13436                    fetch c_find_ESC_in_target into l_new_value ;
13437                    if c_find_ESC_in_target%found then
13438                      --TEMPIK
13439                      l_dt_rec_found :=   dt_api.check_min_max_dates
13440                          (p_base_table_name => 'BEN_ELIG_STDNT_STAT_CVG_F',
13441                           p_base_key_column => 'ELIG_STDNT_STAT_CVG_ID',
13442                           p_base_key_value  => l_new_value,
13443                           p_from_date       => l_min_esd,
13444                           p_to_date         => l_max_eed );
13445                      if l_dt_rec_found THEN
13446                      --END TEMPIK             --
13447                                          if r_ESC_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
13448                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'ELIG_STDNT_STAT_CVG_ID'  then
13449                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'ELIG_STDNT_STAT_CVG_ID' ;
13450                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_ESC_unique.information1 ;
13451                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
13452                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
13453                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_ESC_unique.table_route_id;
13454                                                 --
13455                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
13456                                                 --
13457                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
13458                                          end if ;
13459                                          --
13460                                          l_object_found_in_target := true ;
13461                      --TEMPIK
13462                      end if; -- l_dt_rec_found
13463                      --END TEMPIK
13464                    end if;
13465                    close c_find_ESC_in_target ;
13466                  --
13467                  end if;
13468                end if ;
13469                --
13470                close c_ESC_min_max_dates ;
13471 
13472        --if not l_object_found_in_target then
13473        end if; --if p_dml_operation
13474        --
13475        if not l_object_found_in_target OR l_update  then
13476          --
13477          l_current_pk_id := r_ESC.information1;
13478          --
13479          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
13480          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
13481          --
13482          if l_current_pk_id =  l_prev_pk_id  then
13483            --
13484            l_first_rec := false ;
13485            --
13486          else
13487            --
13488            l_first_rec := true ;
13489            --
13490          end if ;
13491          --
13492 
13493          l_effective_date := r_ESC.information2;
13494          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
13495               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
13496            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
13497          end if;
13498 
13499          --if l_first_rec then
13500          if l_first_rec and not l_update then
13501            -- Call Create routine.
13502            hr_utility.set_location(' BEN_ELIG_STDNT_STAT_CVG_F CREATE_ELIG_STDNT_STAT_CVG ',20);
13503            BEN_ELIG_STDNT_STAT_CVG_API.CREATE_ELIG_STDNT_STAT_CVG(
13504              --
13505              P_VALIDATE               => false
13506              ,P_EFFECTIVE_DATE        => l_effective_date
13507              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
13508              --
13509              ,P_CVG_STRT_CD      => r_ESC.INFORMATION11
13510              ,P_CVG_STRT_RL      => l_CVG_STRT_RL
13511              ,P_CVG_THRU_CD      => r_ESC.INFORMATION12
13512              ,P_CVG_THRU_RL      => l_CVG_THRU_RL
13513              ,P_DPNT_CVG_ELIGY_PRFL_ID      => l_DPNT_CVG_ELIGY_PRFL_ID
13514              ,P_ELIG_STDNT_STAT_CVG_ID      => l_elig_stdnt_stat_cvg_id
13515              ,P_ESC_ATTRIBUTE1      => r_ESC.INFORMATION111
13516              ,P_ESC_ATTRIBUTE10      => r_ESC.INFORMATION120
13517              ,P_ESC_ATTRIBUTE11      => r_ESC.INFORMATION121
13518              ,P_ESC_ATTRIBUTE12      => r_ESC.INFORMATION122
13519              ,P_ESC_ATTRIBUTE13      => r_ESC.INFORMATION123
13520              ,P_ESC_ATTRIBUTE14      => r_ESC.INFORMATION124
13521              ,P_ESC_ATTRIBUTE15      => r_ESC.INFORMATION125
13522              ,P_ESC_ATTRIBUTE16      => r_ESC.INFORMATION126
13523              ,P_ESC_ATTRIBUTE17      => r_ESC.INFORMATION127
13524              ,P_ESC_ATTRIBUTE18      => r_ESC.INFORMATION128
13525              ,P_ESC_ATTRIBUTE19      => r_ESC.INFORMATION129
13526              ,P_ESC_ATTRIBUTE2      => r_ESC.INFORMATION112
13527              ,P_ESC_ATTRIBUTE20      => r_ESC.INFORMATION130
13528              ,P_ESC_ATTRIBUTE21      => r_ESC.INFORMATION131
13529              ,P_ESC_ATTRIBUTE22      => r_ESC.INFORMATION132
13530              ,P_ESC_ATTRIBUTE23      => r_ESC.INFORMATION133
13531              ,P_ESC_ATTRIBUTE24      => r_ESC.INFORMATION134
13532              ,P_ESC_ATTRIBUTE25      => r_ESC.INFORMATION135
13533              ,P_ESC_ATTRIBUTE26      => r_ESC.INFORMATION136
13534              ,P_ESC_ATTRIBUTE27      => r_ESC.INFORMATION137
13535              ,P_ESC_ATTRIBUTE28      => r_ESC.INFORMATION138
13536              ,P_ESC_ATTRIBUTE29      => r_ESC.INFORMATION139
13537              ,P_ESC_ATTRIBUTE3      => r_ESC.INFORMATION113
13538              ,P_ESC_ATTRIBUTE30      => r_ESC.INFORMATION140
13539              ,P_ESC_ATTRIBUTE4      => r_ESC.INFORMATION114
13540              ,P_ESC_ATTRIBUTE5      => r_ESC.INFORMATION115
13541              ,P_ESC_ATTRIBUTE6      => r_ESC.INFORMATION116
13542              ,P_ESC_ATTRIBUTE7      => r_ESC.INFORMATION117
13543              ,P_ESC_ATTRIBUTE8      => r_ESC.INFORMATION118
13544              ,P_ESC_ATTRIBUTE9      => r_ESC.INFORMATION119
13545              ,P_ESC_ATTRIBUTE_CATEGORY      => r_ESC.INFORMATION110
13546              ,P_STDNT_STAT_CD      => r_ESC.INFORMATION13
13547              --
13548              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
13549              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
13550              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
13551            );
13552            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
13553            -- Update all relevent cer records with new pk_id
13554            hr_utility.set_location('Before plsql table ',222);
13555            hr_utility.set_location('new_value id '||l_elig_stdnt_stat_cvg_id,222);
13556            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'ELIG_STDNT_STAT_CVG_ID' ;
13557            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_ESC.information1 ;
13558            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_ELIG_STDNT_STAT_CVG_ID ;
13559            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
13560            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_ESC_unique.table_route_id;
13561            hr_utility.set_location('After plsql table ',222);
13562            --
13563            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
13564            --
13565            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
13566            --
13567          else
13568            --
13569            -- Call Update routine for the pk_id created in prev run .
13570            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
13571            hr_utility.set_location(' BEN_ELIG_STDNT_STAT_CVG_F UPDATE_ELIG_STDNT_STAT_CVG ',30);
13572            --UPD START
13573            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
13574            --
13575            if l_update then
13576              --
13577              l_datetrack_mode := r_ESC.datetrack_mode ;
13578              --
13579              get_dt_modes(
13580                p_effective_date        => l_process_date,
13581                p_effective_end_date    => r_ESC.information3,
13582                p_effective_start_date  => r_ESC.information2,
13583                p_dml_operation         => r_ESC.dml_operation,
13584                p_datetrack_mode        => l_datetrack_mode );
13585            --    p_update                => l_update
13586              --
13587              l_effective_date := l_process_date;
13588              l_elig_stdnt_stat_cvg_id  := r_ESC.information1;
13589              l_object_version_number := r_ESC.information265;
13590              --
13591            end if;
13592            --
13593            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
13594            --
13595            IF l_update OR l_dml_operation <> 'UPDATE' THEN
13596            --UPD END
13597 
13598                    BEN_ELIG_STDNT_STAT_CVG_API.UPDATE_ELIG_STDNT_STAT_CVG(
13599                      --
13600                      P_VALIDATE               => false
13601                      ,P_EFFECTIVE_DATE        => l_effective_date
13602                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
13603                      --
13604                      ,P_CVG_STRT_CD      => r_ESC.INFORMATION11
13605                      ,P_CVG_STRT_RL      => l_CVG_STRT_RL
13606                      ,P_CVG_THRU_CD      => r_ESC.INFORMATION12
13607                      ,P_CVG_THRU_RL      => l_CVG_THRU_RL
13608                      ,P_DPNT_CVG_ELIGY_PRFL_ID      => l_DPNT_CVG_ELIGY_PRFL_ID
13609                      ,P_ELIG_STDNT_STAT_CVG_ID      => l_elig_stdnt_stat_cvg_id
13610                      ,P_ESC_ATTRIBUTE1      => r_ESC.INFORMATION111
13611                      ,P_ESC_ATTRIBUTE10      => r_ESC.INFORMATION120
13612                      ,P_ESC_ATTRIBUTE11      => r_ESC.INFORMATION121
13613                      ,P_ESC_ATTRIBUTE12      => r_ESC.INFORMATION122
13614                      ,P_ESC_ATTRIBUTE13      => r_ESC.INFORMATION123
13615                      ,P_ESC_ATTRIBUTE14      => r_ESC.INFORMATION124
13616                      ,P_ESC_ATTRIBUTE15      => r_ESC.INFORMATION125
13617                      ,P_ESC_ATTRIBUTE16      => r_ESC.INFORMATION126
13618                      ,P_ESC_ATTRIBUTE17      => r_ESC.INFORMATION127
13619                      ,P_ESC_ATTRIBUTE18      => r_ESC.INFORMATION128
13620                      ,P_ESC_ATTRIBUTE19      => r_ESC.INFORMATION129
13621                      ,P_ESC_ATTRIBUTE2      => r_ESC.INFORMATION112
13622                      ,P_ESC_ATTRIBUTE20      => r_ESC.INFORMATION130
13623                      ,P_ESC_ATTRIBUTE21      => r_ESC.INFORMATION131
13624                      ,P_ESC_ATTRIBUTE22      => r_ESC.INFORMATION132
13625                      ,P_ESC_ATTRIBUTE23      => r_ESC.INFORMATION133
13626                      ,P_ESC_ATTRIBUTE24      => r_ESC.INFORMATION134
13627                      ,P_ESC_ATTRIBUTE25      => r_ESC.INFORMATION135
13628                      ,P_ESC_ATTRIBUTE26      => r_ESC.INFORMATION136
13629                      ,P_ESC_ATTRIBUTE27      => r_ESC.INFORMATION137
13630                      ,P_ESC_ATTRIBUTE28      => r_ESC.INFORMATION138
13631                      ,P_ESC_ATTRIBUTE29      => r_ESC.INFORMATION139
13632                      ,P_ESC_ATTRIBUTE3      => r_ESC.INFORMATION113
13633                      ,P_ESC_ATTRIBUTE30      => r_ESC.INFORMATION140
13634                      ,P_ESC_ATTRIBUTE4      => r_ESC.INFORMATION114
13635                      ,P_ESC_ATTRIBUTE5      => r_ESC.INFORMATION115
13636                      ,P_ESC_ATTRIBUTE6      => r_ESC.INFORMATION116
13637                      ,P_ESC_ATTRIBUTE7      => r_ESC.INFORMATION117
13638                      ,P_ESC_ATTRIBUTE8      => r_ESC.INFORMATION118
13639                      ,P_ESC_ATTRIBUTE9      => r_ESC.INFORMATION119
13640                      ,P_ESC_ATTRIBUTE_CATEGORY      => r_ESC.INFORMATION110
13641                      ,P_STDNT_STAT_CD      => r_ESC.INFORMATION13
13642                      --
13643                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
13644                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
13645                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
13646                      --,P_DATETRACK_MODE        => hr_api.g_update
13647                      ,P_DATETRACK_MODE        => l_datetrack_mode
13648                    );
13649               end if;  -- l_update
13650          end if;
13651          --
13652          --
13653          -- Delete the row if it is end dated.
13654          --
13655          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
13656              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
13657            trunc(l_max_eed) = r_ESC.information3) then
13658              --
13659              BEN_ELIG_STDNT_STAT_CVG_API.delete_ELIG_STDNT_STAT_CVG(
13660                 --
13661                 p_validate                       => false
13662                 ,p_elig_stdnt_stat_cvg_id                   => l_elig_stdnt_stat_cvg_id
13663                 ,p_effective_start_date           => l_effective_start_date
13664                 ,p_effective_end_date             => l_effective_end_date
13665                 ,p_object_version_number          => l_object_version_number
13666                 ,p_effective_date                 => l_max_eed
13667                 ,p_datetrack_mode                 => hr_api.g_delete
13668                 --
13669                 );
13670                 --
13671          end if;
13672          --
13673          l_prev_pk_id := l_current_pk_id ;
13674          --
13675        end if;
13676        --
13677      end if;
13678      --
13679    end loop;
13680    --
13681  exception when others then
13682      --
13683      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'ESC',r_ESC.information5 ) ;
13684      --
13685  end create_ESC_rows;
13686 
13687  --
13688  ---------------------------------------------------------------
13689  ----------------------< create_EIV_rows >-----------------------
13690  ---------------------------------------------------------------
13691  --
13692  procedure create_EIV_rows
13693    (
13694          p_validate                       in  number     default 0
13695         ,p_copy_entity_txn_id             in  number
13696         ,p_effective_date                 in  date
13697         ,p_prefix_suffix_text             in  varchar2  default null
13698         ,p_reuse_object_flag              in  varchar2  default null
13699         ,p_target_business_group_id       in  varchar2  default null
13700         ,p_prefix_suffix_cd               in  varchar2  default null
13701    ) is
13702    --
13703    l_ACTY_BASE_RT_ID  number;
13704    l_INPUT_VALUE_ID  number;
13705    cursor c_unique_EIV(l_table_alias varchar2) is
13706    select distinct cpe.information1,
13707      cpe.information2,
13708      cpe.information3,
13709      cpe.table_route_id,
13710      cpe.dml_operation,cpe.datetrack_mode
13711    from ben_copy_entity_results cpe,
13712         pqh_table_route tr
13713    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
13714    and   cpe.table_route_id     = tr.table_route_id
13715    -- and   tr.where_clause        = l_BEN_EXTRA_INPUT_VALUES
13716    and   tr.table_alias = l_table_alias
13717    and   cpe.number_of_copies   = 1 -- ADDITION
13718    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
13719    order by information1, information2; --added for bug: 5151945
13720    --
13721    --
13722    cursor c_EIV_min_max_dates(c_table_route_id  number,
13723                 c_information1   varchar2) is
13724    select
13725      min(cpe.information2) min_esd,
13726      max(cpe.information3) min_eed
13727    from ben_copy_entity_results cpe
13728    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
13729    and   cpe.table_route_id     = c_table_route_id
13730    and   cpe.information1       = c_information1 ;
13731    --
13732    cursor c_EIV(c_table_route_id  number,
13733                 c_information1   number,
13734                 c_information2   date,
13735                 c_information3   date )  is
13736    select
13737      cpe.*
13738    from ben_copy_entity_results cpe
13739    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
13740    and   cpe.table_route_id     = c_table_route_id
13741    and   cpe.information1       = c_information1
13742    and rownum = 1 ;
13743    -- Date Track target record
13744    cursor c_find_EIV_in_target(
13745                                 c_effective_start_date    date,
13746                                 c_effective_end_date      date,
13747                                 c_business_group_id       number,
13748                                 c_new_pk_id               number) is
13749    select
13750      EIV.extra_input_value_id new_value
13751    from BEN_EXTRA_INPUT_VALUES EIV
13752    where
13753    EIV.ACTY_BASE_RT_ID    = l_ACTY_BASE_RT_ID  and
13754    EIV.INPUT_VALUE_ID     = l_INPUT_VALUE_ID  and
13755    EIV.business_group_id  = c_business_group_id
13756    and   EIV.extra_input_value_id  <> c_new_pk_id
13757         ;
13758    --
13759 
13760    cursor c_element_type_id(c_acty_base_rt_id in number,
13761                             c_copy_entity_txn_id in number) is
13762    select cpe.information176 element_type_id
13763    from   ben_copy_entity_results cpe,
13764           pqh_table_route tre
13765    where  cpe.information1 = c_acty_base_rt_id
13766    and    cpe.copy_entity_txn_id = c_copy_entity_txn_id
13767    and    cpe.table_route_id = tre.table_route_id
13768    and    tre.table_alias = 'ABR'
13769    order by cpe.information3 desc;
13770 
13771    cursor c_input_value_in_target(c_element_type_id in number,
13772                                   c_input_value_name in varchar2,
13773                                   c_business_group_id in number,
13774                                   c_effective_date in date) is
13775    select input_value_id
13776    from pay_input_values_f
13777    where name = c_input_value_name
13778    and element_type_id = c_element_type_id
13779    and (business_group_id is null or business_group_id = c_business_group_id)
13780    and  c_effective_date between effective_start_date
13781    and  effective_end_date;
13782 
13783    l_element_type_id pay_input_values.element_type_id%type;
13784    --
13785    --UPD START
13786    --
13787    l_update                  boolean      := false ;
13788    l_datetrack_mode          varchar2(80) := hr_api.g_update;
13789    l_process_date            date;
13790    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
13791    --
13792    --UPD END
13793    --
13794    l_current_pk_id           number := null ;
13795    l_prev_pk_id              number := null ;
13796    l_first_rec               boolean := true ;
13797    r_EIV                     c_EIV%rowtype;
13798    l_extra_input_value_id             number ;
13799    l_object_version_number   number ;
13800    l_effective_start_date    date ;
13801    l_effective_end_date      date ;
13802    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
13803    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
13804    l_new_value               number(15);
13805    l_object_found_in_target  boolean := false ;
13806    l_min_esd                 date;
13807    l_max_eed                 date;
13808    l_parent_effective_start_date date;
13809    --
13810  begin
13811    -- Initialization
13812    l_object_found_in_target := false ;
13813    -- End Initialization
13814    -- Derive the prefix - sufix
13815    if   p_prefix_suffix_cd = 'PREFIX' then
13816      l_prefix  := p_prefix_suffix_text ;
13817    elsif p_prefix_suffix_cd = 'SUFFIX' then
13818      l_suffix   := p_prefix_suffix_text ;
13819    else
13820      l_prefix := null ;
13821      l_suffix  := null ;
13822    end if ;
13823    -- End Prefix Sufix derivation
13824    for r_EIV_unique in c_unique_EIV('EIV') loop
13825      --
13826      hr_utility.set_location(' r_EIV_unique.table_route_id '||r_EIV_unique.table_route_id,10);
13827      hr_utility.set_location(' r_EIV_unique.information1 '||r_EIV_unique.information1,10);
13828      hr_utility.set_location( 'r_EIV_unique.information2 '||r_EIV_unique.information2,10);
13829      hr_utility.set_location( 'r_EIV_unique.information3 '||r_EIV_unique.information3,10);
13830      -- If reuse objects flag is 'Y' then check for the object in the target business group
13831      -- if found insert the record into PLSql table and exit the loop else try create the
13832      -- object in the target business group
13833      --
13834      l_object_found_in_target := false ;
13835      open c_EIV(r_EIV_unique.table_route_id,
13836                         r_EIV_unique.information1,
13837                         r_EIV_unique.information2,
13838                         r_EIV_unique.information3 ) ;
13839      --
13840      fetch c_EIV into r_EIV ;
13841      --
13842      close c_EIV ;
13843      --
13844 
13845      --
13846              l_min_esd := null ;
13847              l_max_eed := null ;
13848              --
13849              /*open c_EIV(r_EIV_unique.table_route_id,
13850                         r_EIV_unique.information1,
13851                         r_EIV_unique.information2,
13852                         r_EIV_unique.information3 ) ;
13853              --
13854              fetch c_EIV into r_EIV ;
13855              --
13856              close c_EIV ;*/
13857 
13858              l_update := false;
13859              l_process_date := p_effective_date;
13860              l_dml_operation:= r_EIV_unique.dml_operation ;
13861 
13862              --
13863              l_ACTY_BASE_RT_ID := get_fk('ACTY_BASE_RT_ID', r_EIV.INFORMATION253,l_dml_operation);
13864 
13865              if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
13866 
13867                -- Begin Logic for finding input values in target
13868                open c_element_type_id(r_EIV.information253,
13869                                       r_EIV.copy_entity_txn_id);
13870                fetch c_element_type_id into l_element_type_id;
13871                close c_element_type_id;
13872 
13873                if l_element_type_id is null then
13874                   l_INPUT_VALUE_ID := null;  -- No mapping done for Element
13875                else
13876                   open c_input_value_in_target(l_element_type_id,
13877                                                r_EIV.information173,
13878                                                p_target_business_group_id,
13879                                                NVL(ben_pd_copy_to_ben_one.g_copy_effective_date ,p_effective_date));
13880                   fetch c_input_value_in_target into l_INPUT_VALUE_ID;
13881                   if c_input_value_in_target%notfound then
13882                     l_INPUT_VALUE_ID := null;
13883                   end if;
13884                   close c_input_value_in_target;
13885                end if;
13886                -- End Logic for finding input values in target
13887 
13888              else
13889                l_INPUT_VALUE_ID :=  r_EIV.information174;
13890              end if;
13891 
13892              if l_INPUT_VALUE_ID  is not null and l_ACTY_BASE_RT_ID is not null then
13893               --UPD START
13894 
13895            --
13896          if l_dml_operation = 'UPDATE' then
13897          --
13898                  l_object_found_in_target := TRUE;
13899                  --
13900                  if l_process_date between r_EIV_unique.information2 and r_EIV_unique.information3 then
13901                        l_update := true;
13902                        if r_EIV_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
13903                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'EXTRA_INPUT_VALUE_ID'
13904                        then
13905                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'EXTRA_INPUT_VALUE_ID' ;
13906                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_EIV_unique.information1 ;
13907                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_EIV_unique.information1 ;
13908                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
13909                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_EIV_unique.table_route_id;
13910                           --
13911                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
13912                           --
13913                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
13914                           --
13915                           --BEN_PD_COPY_TO_BEN_ONE.log_data('EIV',l_new_value,l_prefix || r_EIV_unique.name|| l_suffix,'REUSED');
13916                           --
13917                        end if ;
13918                        hr_utility.set_location( 'found record for update',10);
13919                    --
13920                  else
13921                    --
13922                    l_update := false;
13923            --
13924          end if;
13925        else
13926          --
13927          --UPD END
13928                  if p_reuse_object_flag = 'Y' then
13929                  -- cursor to find the object
13930                    open c_find_EIV_in_target( r_EIV_unique.information2,l_max_eed,
13931                                          p_target_business_group_id, nvl(l_extra_input_value_id, -999)  ) ;
13932                    fetch c_find_EIV_in_target into l_new_value ;
13933                    if c_find_EIV_in_target%found then
13934                      --
13935                      if r_EIV_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
13936                         nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'EXTRA_INPUT_VALUE_ID'  then
13937                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'EXTRA_INPUT_VALUE_ID' ;
13938                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_EIV_unique.information1 ;
13939                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
13940                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
13941                         ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_EIV_unique.table_route_id;
13942                         --
13943                         -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
13944                         --
13945                         ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
13946                      end if ;
13947                      --
13948                      l_object_found_in_target := true ;
13949                    end if;
13950                    close c_find_EIV_in_target ;
13951                  --
13952                  end if ;
13953          --
13954          --if not l_object_found_in_target then
13955        end if; --if p_dml_operation
13956        --
13957        if not l_object_found_in_target OR l_update  then
13958          --
13959            l_current_pk_id := r_EIV.information1;
13960            --
13961            hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
13962            hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
13963            --
13964            if l_current_pk_id =  l_prev_pk_id  then
13965            --
13966              l_first_rec := false ;
13967            --
13968            else
13969            --
13970              l_first_rec := true ;
13971            --
13972            end if ;
13973            --
13974 
13975            l_parent_effective_start_date := r_EIV.information10;
13976            if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null ) then
13977              if l_parent_effective_start_date is null then
13978                l_parent_effective_start_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
13979              elsif l_parent_effective_start_date < ben_pd_copy_to_ben_one.g_copy_effective_date  then
13980                l_parent_effective_start_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
13981              end if;
13982            end if;
13983            --
13984            -- To avoid creating a child with out a parent
13985            --
13986            --
13987            if l_ACTY_BASE_RT_ID is null then
13988               l_first_rec := false ;
13989            end if;
13990            --
13991            --if l_first_rec then
13992             if l_first_rec and not l_update then
13993            -- Call Create routine.
13994              hr_utility.set_location(' BEN_EXTRA_INPUT_VALUES CREATE_EXTRA_INPUT_VALUE ',20);
13995              BEN_EXTRA_INPUT_VALUE_API.CREATE_EXTRA_INPUT_VALUE(
13996              --
13997              P_VALIDATE               => false
13998              ,P_EFFECTIVE_DATE        => NVL(l_parent_effective_start_date,p_effective_date)
13999              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
14000              --
14001              ,P_ACTY_BASE_RT_ID      => l_ACTY_BASE_RT_ID
14002              ,P_EIV_ATTRIBUTE1      => r_EIV.INFORMATION111
14003              ,P_EIV_ATTRIBUTE10      => r_EIV.INFORMATION120
14004              ,P_EIV_ATTRIBUTE11      => r_EIV.INFORMATION121
14005              ,P_EIV_ATTRIBUTE12      => r_EIV.INFORMATION122
14006              ,P_EIV_ATTRIBUTE13      => r_EIV.INFORMATION123
14007              ,P_EIV_ATTRIBUTE14      => r_EIV.INFORMATION124
14008              ,P_EIV_ATTRIBUTE15      => r_EIV.INFORMATION125
14009              ,P_EIV_ATTRIBUTE16      => r_EIV.INFORMATION126
14010              ,P_EIV_ATTRIBUTE17      => r_EIV.INFORMATION127
14011              ,P_EIV_ATTRIBUTE18      => r_EIV.INFORMATION128
14012              ,P_EIV_ATTRIBUTE19      => r_EIV.INFORMATION129
14013              ,P_EIV_ATTRIBUTE2      => r_EIV.INFORMATION112
14014              ,P_EIV_ATTRIBUTE20      => r_EIV.INFORMATION130
14015              ,P_EIV_ATTRIBUTE21      => r_EIV.INFORMATION131
14016              ,P_EIV_ATTRIBUTE22      => r_EIV.INFORMATION132
14017              ,P_EIV_ATTRIBUTE23      => r_EIV.INFORMATION133
14018              ,P_EIV_ATTRIBUTE24      => r_EIV.INFORMATION134
14019              ,P_EIV_ATTRIBUTE25      => r_EIV.INFORMATION135
14020              ,P_EIV_ATTRIBUTE26      => r_EIV.INFORMATION136
14021              ,P_EIV_ATTRIBUTE27      => r_EIV.INFORMATION137
14022              ,P_EIV_ATTRIBUTE28      => r_EIV.INFORMATION138
14023              ,P_EIV_ATTRIBUTE29      => r_EIV.INFORMATION139
14024              ,P_EIV_ATTRIBUTE3      => r_EIV.INFORMATION113
14025              ,P_EIV_ATTRIBUTE30      => r_EIV.INFORMATION140
14026              ,P_EIV_ATTRIBUTE4      => r_EIV.INFORMATION114
14027              ,P_EIV_ATTRIBUTE5      => r_EIV.INFORMATION115
14028              ,P_EIV_ATTRIBUTE6      => r_EIV.INFORMATION116
14029              ,P_EIV_ATTRIBUTE7      => r_EIV.INFORMATION117
14030              ,P_EIV_ATTRIBUTE8      => r_EIV.INFORMATION118
14031              ,P_EIV_ATTRIBUTE9      => r_EIV.INFORMATION119
14032              ,P_EIV_ATTRIBUTE_CATEGORY      => r_EIV.INFORMATION110
14033              ,P_EXTRA_INPUT_VALUE_ID      => l_EXTRA_INPUT_VALUE_ID
14034              ,P_INPUT_TEXT      => r_EIV.INFORMATION185
14035              ,P_INPUT_VALUE_ID      => l_INPUT_VALUE_ID
14036              ,P_RETURN_VAR_NAME      => r_EIV.INFORMATION186
14037              ,P_UPD_WHEN_ELE_ENDED_CD      => r_EIV.INFORMATION11
14038              --
14039              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
14040              );
14041              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
14042              -- Update all relevent cer records with new pk_id
14043              hr_utility.set_location('Before plsql table ',222);
14044              hr_utility.set_location('new_value id '||l_extra_input_value_id,222);
14045              ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'EXTRA_INPUT_VALUE_ID' ;
14046              ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_EIV.information1 ;
14047              ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_EXTRA_INPUT_VALUE_ID ;
14048              ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
14049              ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_EIV_unique.table_route_id;
14050              hr_utility.set_location('After plsql table ',222);
14051              --
14052              -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
14053              --
14054              ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
14055              --
14056            elsif l_update then
14057            --
14058              hr_utility.set_location(' BEN_EXTRA_INPUT_VALUES UPDATE_EXTRA_INPUT_VALUE ',20);
14059              BEN_EXTRA_INPUT_VALUE_API.UPDATE_EXTRA_INPUT_VALUE(
14060              --
14061              P_VALIDATE               => false
14062              ,P_EFFECTIVE_DATE        => NVL(l_parent_effective_start_date,p_effective_date)
14063              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
14064              --
14065              ,P_ACTY_BASE_RT_ID      => l_ACTY_BASE_RT_ID
14066              ,P_EIV_ATTRIBUTE1      => r_EIV.INFORMATION111
14067              ,P_EIV_ATTRIBUTE10      => r_EIV.INFORMATION120
14068              ,P_EIV_ATTRIBUTE11      => r_EIV.INFORMATION121
14069              ,P_EIV_ATTRIBUTE12      => r_EIV.INFORMATION122
14070              ,P_EIV_ATTRIBUTE13      => r_EIV.INFORMATION123
14071              ,P_EIV_ATTRIBUTE14      => r_EIV.INFORMATION124
14072              ,P_EIV_ATTRIBUTE15      => r_EIV.INFORMATION125
14073              ,P_EIV_ATTRIBUTE16      => r_EIV.INFORMATION126
14074              ,P_EIV_ATTRIBUTE17      => r_EIV.INFORMATION127
14075              ,P_EIV_ATTRIBUTE18      => r_EIV.INFORMATION128
14076              ,P_EIV_ATTRIBUTE19      => r_EIV.INFORMATION129
14077              ,P_EIV_ATTRIBUTE2      => r_EIV.INFORMATION112
14078              ,P_EIV_ATTRIBUTE20      => r_EIV.INFORMATION130
14079              ,P_EIV_ATTRIBUTE21      => r_EIV.INFORMATION131
14080              ,P_EIV_ATTRIBUTE22      => r_EIV.INFORMATION132
14081              ,P_EIV_ATTRIBUTE23      => r_EIV.INFORMATION133
14082              ,P_EIV_ATTRIBUTE24      => r_EIV.INFORMATION134
14083              ,P_EIV_ATTRIBUTE25      => r_EIV.INFORMATION135
14084              ,P_EIV_ATTRIBUTE26      => r_EIV.INFORMATION136
14085              ,P_EIV_ATTRIBUTE27      => r_EIV.INFORMATION137
14086              ,P_EIV_ATTRIBUTE28      => r_EIV.INFORMATION138
14087              ,P_EIV_ATTRIBUTE29      => r_EIV.INFORMATION139
14088              ,P_EIV_ATTRIBUTE3      => r_EIV.INFORMATION113
14089              ,P_EIV_ATTRIBUTE30      => r_EIV.INFORMATION140
14090              ,P_EIV_ATTRIBUTE4      => r_EIV.INFORMATION114
14091              ,P_EIV_ATTRIBUTE5      => r_EIV.INFORMATION115
14092              ,P_EIV_ATTRIBUTE6      => r_EIV.INFORMATION116
14093              ,P_EIV_ATTRIBUTE7      => r_EIV.INFORMATION117
14094              ,P_EIV_ATTRIBUTE8      => r_EIV.INFORMATION118
14095              ,P_EIV_ATTRIBUTE9      => r_EIV.INFORMATION119
14096              ,P_EIV_ATTRIBUTE_CATEGORY      => r_EIV.INFORMATION110
14097              ,P_EXTRA_INPUT_VALUE_ID      => l_EXTRA_INPUT_VALUE_ID
14098              ,P_INPUT_TEXT      => r_EIV.INFORMATION185
14099              ,P_INPUT_VALUE_ID      => l_INPUT_VALUE_ID
14100              ,P_RETURN_VAR_NAME      => r_EIV.INFORMATION186
14101              ,P_UPD_WHEN_ELE_ENDED_CD      => r_EIV.INFORMATION11
14102              --
14103              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
14104              );
14105            --
14106            end if;
14107            --
14108            l_prev_pk_id := l_current_pk_id ;
14109            --
14110          end if;
14111      --
14112      end if;
14113    --
14114    end loop;
14115    --
14116  exception when others then
14117      --
14118      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'EIV',r_EIV.information5 ) ;
14119      --
14120  end create_EIV_rows;
14121    --
14122    ---------------------------------------------------------------
14123    ----------------------< create_PSQ_rows >-----------------------
14124    ---------------------------------------------------------------
14125    --
14126    procedure create_PSQ_rows
14127    (
14128          p_validate                       in  number     default 0
14129         ,p_copy_entity_txn_id             in  number
14130         ,p_effective_date                 in  date
14131         ,p_prefix_suffix_text             in  varchar2  default null
14132         ,p_reuse_object_flag              in  varchar2  default null
14133         ,p_target_business_group_id       in  varchar2  default null
14134         ,p_prefix_suffix_cd               in  varchar2  default null
14135    ) is
14136    --
14137    l_ACTY_RT_PYMT_SCHED_ID  number;
14138    l_PY_FREQ_CD             ben_pymt_sched_py_freq.py_freq_cd%type;
14139    cursor c_unique_PSQ(l_table_alias varchar2) is
14140    select distinct cpe.information1,
14141      cpe.information2,
14142      cpe.information3,
14143      cpe.table_route_id,
14144      cpe.dml_operation,
14145      cpe.datetrack_mode
14146    from ben_copy_entity_results cpe,
14147         pqh_table_route tr
14148    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
14149    and   cpe.table_route_id     = tr.table_route_id
14150    -- and   tr.where_clause        = l_BEN_PYMT_SCHED_PY_FREQ
14151    and   tr.table_alias = l_table_alias
14152    and   cpe.number_of_copies   = 1
14153    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
14154    order by information1, information2; --added for bug: 5151945
14155    --
14156    --
14157    cursor c_PSQ_min_max_dates(c_table_route_id  number,
14158                 c_information1   varchar2) is
14159    select
14160      min(cpe.information2) min_esd,
14161      max(cpe.information3) min_eed
14162    from ben_copy_entity_results cpe
14163    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
14164    and   cpe.table_route_id     = c_table_route_id
14165    and   cpe.information1       = c_information1 ;
14166    --
14167    cursor c_PSQ(c_table_route_id  number,
14168                 c_information1   number,
14169                 c_information2   date,
14170                 c_information3   date )  is
14171    select
14172      cpe.*
14173    from ben_copy_entity_results cpe
14174    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
14175    and   cpe.table_route_id     = c_table_route_id
14176    and   cpe.information1       = c_information1
14177    and rownum = 1 ;
14178    -- Date Track target record
14179    cursor c_find_PSQ_in_target(
14180                                 c_effective_start_date    date,
14181                                 c_effective_end_date      date,
14182                                 c_business_group_id       number,
14183                                 c_new_pk_id               number) is
14184    select
14185      PSQ.pymt_sched_py_freq_id new_value
14186    from BEN_PYMT_SCHED_PY_FREQ PSQ
14187    where
14188    PSQ.business_group_id      = c_business_group_id and
14189    PSQ.PY_FREQ_CD             = l_PY_FREQ_CD and
14190    PSQ.ACTY_RT_PYMT_SCHED_ID  = l_ACTY_RT_PYMT_SCHED_ID
14191    and   PSQ.pymt_sched_py_freq_id  <> c_new_pk_id
14192                 ;
14193    --
14194    --UPD START
14195    --
14196    l_update                  boolean      := false ;
14197    l_datetrack_mode          varchar2(80) := hr_api.g_update;
14198    l_process_date            date;
14199    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
14200    --
14201    --UPD END
14202    --
14203    l_current_pk_id           number := null ;
14204    l_prev_pk_id              number := null ;
14205    l_first_rec               boolean := true ;
14206    r_PSQ                     c_PSQ%rowtype;
14207    l_pymt_sched_py_freq_id             number ;
14208    l_object_version_number   number ;
14209    l_effective_start_date    date ;
14210    l_effective_end_date      date ;
14211    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
14212    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
14213    l_new_value               number(15);
14214    l_object_found_in_target  boolean := false ;
14215    l_min_esd                 date;
14216    l_max_eed                 date;
14217    --
14218  begin
14219    -- Initialization
14220    l_object_found_in_target := false ;
14221    -- End Initialization
14222    -- Derive the prefix - sufix
14223    if   p_prefix_suffix_cd = 'PREFIX' then
14224      l_prefix  := p_prefix_suffix_text ;
14225    elsif p_prefix_suffix_cd = 'SUFFIX' then
14226      l_suffix   := p_prefix_suffix_text ;
14227    else
14228      l_prefix := null ;
14229      l_suffix  := null ;
14230    end if ;
14231    -- End Prefix Sufix derivation
14232     --
14233    for r_PSQ_unique in c_unique_PSQ('PSQ') loop
14234      --
14235      hr_utility.set_location(' r_PSQ_unique.table_route_id '||r_PSQ_unique.table_route_id,10);
14236      hr_utility.set_location(' r_PSQ_unique.information1 '||r_PSQ_unique.information1,10);
14237      hr_utility.set_location( 'r_PSQ_unique.information2 '||r_PSQ_unique.information2,10);
14238      hr_utility.set_location( 'r_PSQ_unique.information3 '||r_PSQ_unique.information3,10);
14239      -- If reuse objects flag is 'Y' then check for the object in the target business group
14240      -- if found insert the record into PLSql table and exit the loop else try create the
14241      -- object in the target business group
14242      --
14243    --
14244    open c_PSQ(r_PSQ_unique.table_route_id,
14245               r_PSQ_unique.information1,
14246               r_PSQ_unique.information2,
14247               r_PSQ_unique.information3 ) ;
14248     --
14249     fetch c_PSQ into r_PSQ ;
14250     --
14251     close c_PSQ ;
14252      l_object_found_in_target := false ;
14253      --
14254      --UPD START
14255     l_min_esd := null ;
14256      l_max_eed := null ;
14257     --
14258     l_update := false;
14259     l_process_date := p_effective_date;
14260     l_dml_operation:= r_PSQ_unique.dml_operation ;
14261     --
14262     l_ACTY_RT_PYMT_SCHED_ID := get_fk('ACTY_RT_PYMT_SCHED_ID', r_PSQ.INFORMATION257,l_dml_operation);
14263     l_PY_FREQ_CD            := r_PSQ.INFORMATION11;
14264      hr_utility.set_location(' l_ACTY_RT_PYMT_SCHED_ID '||l_ACTY_RT_PYMT_SCHED_ID,10);
14265      hr_utility.set_location(' r_PSQ.information11 '||r_PSQ.information11,10);
14266      hr_utility.set_location(' r_PSQ.information45 '||r_PSQ.information45,10);
14267      if l_dml_operation = 'UPDATE' then
14268          --
14269                  l_object_found_in_target := TRUE;
14270                  --
14271                  if l_process_date between r_PSQ_unique.information2 and r_PSQ_unique.information3 then
14272                        l_update := true;
14273                        if r_PSQ_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
14274                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'PYMT_SCHED_PY_FREQ_ID'
14275                        then
14276                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'PYMT_SCHED_PY_FREQ_ID' ;
14277                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_PSQ_unique.information1 ;
14278                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_PSQ_unique.information1 ;
14279                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
14280                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_PSQ_unique.table_route_id;
14281                           --
14282                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
14283                           --
14284                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
14285                           --
14286                           --BEN_PD_COPY_TO_BEN_ONE.log_data('PSQ',l_new_value,l_prefix || r_PSQ_unique.name|| l_suffix,'REUSED');
14287                           --
14288                        end if ;
14289                        hr_utility.set_location( 'found record for update',10);
14290                    --
14291                  else
14292                    --
14293                    l_update := false;
14294                    --
14295                  end if ;
14296        else
14297          --
14298          --UPD END
14299              if p_reuse_object_flag = 'Y' then
14300                    -- cursor to find the object
14301                    open c_find_PSQ_in_target( r_PSQ_unique.information2,l_max_eed,
14302                                          p_target_business_group_id, nvl(l_pymt_sched_py_freq_id, -999)  ) ;
14303                    fetch c_find_PSQ_in_target into l_new_value ;
14304                    if c_find_PSQ_in_target%found then
14305                      --
14306                      if r_PSQ_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999) or
14307                         nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <>  'PYMT_SCHED_PY_FREQ_ID'  then
14308                         BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'PYMT_SCHED_PY_FREQ_ID' ;
14309                         BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_PSQ_unique.information1 ;
14310                         BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := l_new_value ;
14311                         BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
14312                         BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_PSQ_unique.table_route_id;
14313                         --
14314                         -- update_cer_with_target( BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count) , p_copy_entity_txn_id) ;
14315                         --
14316                         BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
14317                         --
14318                      end if ;
14319                      --
14320                      l_object_found_in_target := true ;
14321                    end if;
14322                    close c_find_PSQ_in_target ;
14323                  --
14324              end if ;
14325      --
14326      --if not l_object_found_in_target then
14327      end if; --if p_dml_operation
14328        --
14329      if not l_object_found_in_target OR l_update  then
14330 
14331        --
14332        l_current_pk_id := r_PSQ.information1;
14333        --
14334        hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
14335        hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
14336        --
14337        if l_current_pk_id =  l_prev_pk_id  then
14338          --
14339          l_first_rec := false ;
14340          --
14341        else
14342          --
14343          l_first_rec := true ;
14344          --
14345        end if ;
14346        --
14347        -- To avoid creating a child with out a parent
14348        --
14349        if l_ACTY_RT_PYMT_SCHED_ID is null then
14350           l_first_rec := false ;
14351        end if;
14352        --
14353        --if l_first_rec then
14354        if l_first_rec and not l_update then
14355          -- Call Create routine.
14356          hr_utility.set_location(' BEN_PYMT_SCHED_PY_FREQ CREATE_PYMT_SCHED_PY_FREQ ',20);
14357          BEN_PYMT_SCHED_PY_FREQ_API.CREATE_PYMT_SCHED_PY_FREQ(
14358              --
14359              P_VALIDATE               => false
14360              ,P_EFFECTIVE_DATE        => NVL(ben_pd_copy_to_ben_one.g_copy_effective_date ,p_effective_date)
14361              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
14362              --
14363              ,P_ACTY_RT_PYMT_SCHED_ID      => l_ACTY_RT_PYMT_SCHED_ID
14364              ,P_DFLT_FLAG      => r_PSQ.INFORMATION12
14365              ,P_PSQ_ATTRIBUTE1      => r_PSQ.INFORMATION111
14366              ,P_PSQ_ATTRIBUTE10      => r_PSQ.INFORMATION120
14367              ,P_PSQ_ATTRIBUTE11      => r_PSQ.INFORMATION121
14368              ,P_PSQ_ATTRIBUTE12      => r_PSQ.INFORMATION122
14369              ,P_PSQ_ATTRIBUTE13      => r_PSQ.INFORMATION123
14370              ,P_PSQ_ATTRIBUTE14      => r_PSQ.INFORMATION124
14371              ,P_PSQ_ATTRIBUTE15      => r_PSQ.INFORMATION125
14372              ,P_PSQ_ATTRIBUTE16      => r_PSQ.INFORMATION126
14373              ,P_PSQ_ATTRIBUTE17      => r_PSQ.INFORMATION127
14374              ,P_PSQ_ATTRIBUTE18      => r_PSQ.INFORMATION128
14375              ,P_PSQ_ATTRIBUTE19      => r_PSQ.INFORMATION129
14376              ,P_PSQ_ATTRIBUTE2      => r_PSQ.INFORMATION112
14377              ,P_PSQ_ATTRIBUTE20      => r_PSQ.INFORMATION130
14378              ,P_PSQ_ATTRIBUTE21      => r_PSQ.INFORMATION131
14379              ,P_PSQ_ATTRIBUTE22      => r_PSQ.INFORMATION132
14380              ,P_PSQ_ATTRIBUTE23      => r_PSQ.INFORMATION133
14381              ,P_PSQ_ATTRIBUTE24      => r_PSQ.INFORMATION134
14382              ,P_PSQ_ATTRIBUTE25      => r_PSQ.INFORMATION135
14383              ,P_PSQ_ATTRIBUTE26      => r_PSQ.INFORMATION136
14384              ,P_PSQ_ATTRIBUTE27      => r_PSQ.INFORMATION137
14385              ,P_PSQ_ATTRIBUTE28      => r_PSQ.INFORMATION138
14386              ,P_PSQ_ATTRIBUTE29      => r_PSQ.INFORMATION139
14387              ,P_PSQ_ATTRIBUTE3      => r_PSQ.INFORMATION113
14388              ,P_PSQ_ATTRIBUTE30      => r_PSQ.INFORMATION140
14389              ,P_PSQ_ATTRIBUTE4      => r_PSQ.INFORMATION114
14390              ,P_PSQ_ATTRIBUTE5      => r_PSQ.INFORMATION115
14391              ,P_PSQ_ATTRIBUTE6      => r_PSQ.INFORMATION116
14392              ,P_PSQ_ATTRIBUTE7      => r_PSQ.INFORMATION117
14393              ,P_PSQ_ATTRIBUTE8      => r_PSQ.INFORMATION118
14394              ,P_PSQ_ATTRIBUTE9      => r_PSQ.INFORMATION119
14395              ,P_PSQ_ATTRIBUTE_CATEGORY      => r_PSQ.INFORMATION110
14396              ,P_PYMT_SCHED_PY_FREQ_ID      => l_pymt_sched_py_freq_id
14397              ,P_PY_FREQ_CD      => r_PSQ.INFORMATION11
14398              --
14399              ,P_OBJECT_VERSION_NUMBER =>        l_object_version_number
14400          );
14401          -- insert the table_name,old_pk_id,new_pk_id into a plsql record
14402          -- Update all relevent cer records with new pk_id
14403          hr_utility.set_location('Before plsql table ',222);
14404          hr_utility.set_location('new_value id '||l_pymt_sched_py_freq_id,222);
14405          BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column := 'PYMT_SCHED_PY_FREQ_ID' ;
14406          BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value    := r_PSQ.information1 ;
14407          BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value    := l_PYMT_SCHED_PY_FREQ_ID ;
14408          BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type  := 'COPIED';
14409          BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_PSQ_unique.table_route_id;
14410          hr_utility.set_location('After plsql table ',222);
14411          --
14412          -- update_cer_with_target( BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count),p_copy_entity_txn_id ) ;
14413          --
14414          BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
14415         elsif l_update then
14416         --
14417          hr_utility.set_location(' BEN_PYMT_SCHED_PY_FREQ UPDATE_PYMT_SCHED_PY_FREQ ',20);
14418          BEN_PYMT_SCHED_PY_FREQ_API.UPDATE_PYMT_SCHED_PY_FREQ(
14419              --
14420              P_VALIDATE               => false
14421              ,P_EFFECTIVE_DATE        => NVL(ben_pd_copy_to_ben_one.g_copy_effective_date ,p_effective_date)
14422              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
14423              --
14424              ,P_ACTY_RT_PYMT_SCHED_ID      => l_ACTY_RT_PYMT_SCHED_ID
14425              ,P_DFLT_FLAG      => r_PSQ.INFORMATION12
14426              ,P_PSQ_ATTRIBUTE1      => r_PSQ.INFORMATION111
14427              ,P_PSQ_ATTRIBUTE10      => r_PSQ.INFORMATION120
14428              ,P_PSQ_ATTRIBUTE11      => r_PSQ.INFORMATION121
14429              ,P_PSQ_ATTRIBUTE12      => r_PSQ.INFORMATION122
14430              ,P_PSQ_ATTRIBUTE13      => r_PSQ.INFORMATION123
14431              ,P_PSQ_ATTRIBUTE14      => r_PSQ.INFORMATION124
14432              ,P_PSQ_ATTRIBUTE15      => r_PSQ.INFORMATION125
14433              ,P_PSQ_ATTRIBUTE16      => r_PSQ.INFORMATION126
14434              ,P_PSQ_ATTRIBUTE17      => r_PSQ.INFORMATION127
14435              ,P_PSQ_ATTRIBUTE18      => r_PSQ.INFORMATION128
14436              ,P_PSQ_ATTRIBUTE19      => r_PSQ.INFORMATION129
14437              ,P_PSQ_ATTRIBUTE2      => r_PSQ.INFORMATION112
14438              ,P_PSQ_ATTRIBUTE20      => r_PSQ.INFORMATION130
14439              ,P_PSQ_ATTRIBUTE21      => r_PSQ.INFORMATION131
14440              ,P_PSQ_ATTRIBUTE22      => r_PSQ.INFORMATION132
14441              ,P_PSQ_ATTRIBUTE23      => r_PSQ.INFORMATION133
14442              ,P_PSQ_ATTRIBUTE24      => r_PSQ.INFORMATION134
14443              ,P_PSQ_ATTRIBUTE25      => r_PSQ.INFORMATION135
14444              ,P_PSQ_ATTRIBUTE26      => r_PSQ.INFORMATION136
14445              ,P_PSQ_ATTRIBUTE27      => r_PSQ.INFORMATION137
14446              ,P_PSQ_ATTRIBUTE28      => r_PSQ.INFORMATION138
14447              ,P_PSQ_ATTRIBUTE29      => r_PSQ.INFORMATION139
14448              ,P_PSQ_ATTRIBUTE3      => r_PSQ.INFORMATION113
14449              ,P_PSQ_ATTRIBUTE30      => r_PSQ.INFORMATION140
14450              ,P_PSQ_ATTRIBUTE4      => r_PSQ.INFORMATION114
14451              ,P_PSQ_ATTRIBUTE5      => r_PSQ.INFORMATION115
14452              ,P_PSQ_ATTRIBUTE6      => r_PSQ.INFORMATION116
14453              ,P_PSQ_ATTRIBUTE7      => r_PSQ.INFORMATION117
14454              ,P_PSQ_ATTRIBUTE8      => r_PSQ.INFORMATION118
14455              ,P_PSQ_ATTRIBUTE9      => r_PSQ.INFORMATION119
14456              ,P_PSQ_ATTRIBUTE_CATEGORY      => r_PSQ.INFORMATION110
14457              ,P_PYMT_SCHED_PY_FREQ_ID      => l_pymt_sched_py_freq_id
14458              ,P_PY_FREQ_CD      => r_PSQ.INFORMATION11
14459              --
14460              ,P_OBJECT_VERSION_NUMBER =>        l_object_version_number
14461          );
14462 
14463         --
14464        end if;
14465        --
14466        l_prev_pk_id := l_current_pk_id ;
14467        --
14468      end if;
14469      --
14470    end loop;
14471    --
14472  exception when others then
14473      --
14474      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'PSQ',R_PSQ.information5 ) ;
14475      --
14476  end create_PSQ_rows;
14477 
14478    --
14479    ---------------------------------------------------------------
14480    ----------------------< create_APF_rows >-----------------------
14481    ---------------------------------------------------------------
14482    --
14483    procedure create_APF_rows
14484    (
14485          p_validate                       in  number     default 0
14486         ,p_copy_entity_txn_id             in  number
14487         ,p_effective_date                 in  date
14488         ,p_prefix_suffix_text             in  varchar2  default null
14489         ,p_reuse_object_flag              in  varchar2  default null
14490         ,p_target_business_group_id       in  varchar2  default null
14491         ,p_prefix_suffix_cd               in  varchar2  default null
14492    ) is
14493    --
14494    l_ACTY_BASE_RT_ID  number;
14495    l_PYMT_SCHED_RL  number;
14496    l_PYMT_SCHED_CD  ben_acty_rt_pymt_sched_f.pymt_sched_cd%type;
14497    cursor c_unique_APF(l_table_alias varchar2) is
14498    select distinct cpe.information1,
14499      cpe.information2,
14500      cpe.information3,
14501      cpe.table_route_id,
14502      cpe.dml_operation,cpe.datetrack_mode
14503    from ben_copy_entity_results cpe,
14504         pqh_table_route tr
14505    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
14506    and   cpe.table_route_id     = tr.table_route_id
14507    -- and   tr.where_clause        = l_BEN_ACTY_RT_PYMT_SCHED_F
14508    and   tr.table_alias = l_table_alias
14509    and   cpe.number_of_copies   = 1
14510    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
14511    order by information1, information2; --added for bug: 5151945
14512    --
14513    --
14514    cursor c_APF_min_max_dates(c_table_route_id  number,
14515                 c_information1   varchar2) is
14516    select
14517      min(cpe.information2) min_esd,
14518      max(cpe.information3) min_eed
14519    from ben_copy_entity_results cpe
14520    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
14521    and   cpe.table_route_id     = c_table_route_id
14522    and   cpe.information1       = c_information1 ;
14523    --
14524    cursor c_APF(c_table_route_id  number,
14525                 c_information1   number,
14526                 c_information2   date,
14527                 c_information3   date )  is
14528    select
14529      cpe.*
14530    from ben_copy_entity_results cpe
14531    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
14532    and   cpe.table_route_id     = c_table_route_id
14533    and   cpe.information1       = c_information1
14534    and   cpe.information2       = c_information2
14535    and   cpe.information3       = c_information3
14536    and rownum = 1 ;
14537    -- Date Track target record
14538    cursor c_find_APF_in_target(
14539                                 c_effective_start_date    date,
14540                                 c_effective_end_date      date,
14541                                 c_business_group_id       number,
14542                                 c_new_pk_id               number) is
14543    select
14544      APF.acty_rt_pymt_sched_id new_value
14545    from BEN_ACTY_RT_PYMT_SCHED_F APF
14546    where
14547    APF.ACTY_BASE_RT_ID = l_ACTY_BASE_RT_ID and
14548    APF.PYMT_SCHED_CD   = l_PYMT_SCHED_CD and
14549    APF.business_group_id  = c_business_group_id
14550    and   APF.acty_rt_pymt_sched_id  <> c_new_pk_id
14551 --TEMPIK
14552    and c_effective_start_date between effective_start_date
14553                             and effective_end_date ;
14554 --END TEMPIK
14555 /*TEMPIK
14556    and exists ( select null
14557                 from BEN_ACTY_RT_PYMT_SCHED_F APF1
14558                 where
14559                 APF1.ACTY_BASE_RT_ID = l_ACTY_BASE_RT_ID and
14560                 APF1.PYMT_SCHED_CD   = l_PYMT_SCHED_CD and
14561                 APF1.business_group_id  = c_business_group_id
14562                 and   APF1.effective_start_date <= c_effective_start_date )
14563    and exists ( select null
14564                 from BEN_ACTY_RT_PYMT_SCHED_F APF2
14565                 where
14566                 APF2.ACTY_BASE_RT_ID = l_ACTY_BASE_RT_ID and
14567                 APF2.PYMT_SCHED_CD   = l_PYMT_SCHED_CD and
14568                 APF2.business_group_id  = c_business_group_id
14569                 and   APF2.effective_end_date >= c_effective_end_date )
14570                 ;
14571 TEMPIK */
14572    --TEMPIK
14573    l_dt_rec_found            boolean ;
14574    --END TEMPIK
14575    --
14576 
14577    --UPD START
14578    --
14579    l_update                  boolean      := false ;
14580    l_datetrack_mode          varchar2(80) := hr_api.g_update;
14581    l_process_date            date;
14582    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
14583    --
14584    --UPD END
14585 
14586    l_current_pk_id           number := null ;
14587    l_prev_pk_id              number := null ;
14588    l_first_rec               boolean := true ;
14589    r_APF                     c_APF%rowtype;
14590    l_acty_rt_pymt_sched_id             number ;
14591    l_object_version_number   number ;
14592    l_effective_start_date    date ;
14593    l_effective_end_date      date ;
14594    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
14595    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
14596    l_new_value               number(15);
14597    l_object_found_in_target  boolean := false ;
14598    l_min_esd                 date;
14599    l_max_eed                 date;
14600    l_effective_date          date;
14601    --
14602  begin
14603    -- Initialization
14604    l_object_found_in_target := false ;
14605    -- End Initialization
14606    -- Derive the prefix - sufix
14607    if   p_prefix_suffix_cd = 'PREFIX' then
14608      l_prefix  := p_prefix_suffix_text ;
14609    elsif p_prefix_suffix_cd = 'SUFFIX' then
14610      l_suffix   := p_prefix_suffix_text ;
14611    else
14612      l_prefix := null ;
14613      l_suffix  := null ;
14614    end if ;
14615    -- End Prefix Sufix derivation
14616    for r_APF_unique in c_unique_APF('APF') loop
14617 
14618      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
14619         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
14620          r_APF_unique.information3 >=
14621                  ben_pd_copy_to_ben_one.g_copy_effective_date)
14622         ) then
14623        --
14624        hr_utility.set_location(' r_APF_unique.table_route_id '||r_APF_unique.table_route_id,10);
14625        hr_utility.set_location(' r_APF_unique.information1 '||r_APF_unique.information1,10);
14626        hr_utility.set_location( 'r_APF_unique.information2 '||r_APF_unique.information2,10);
14627        hr_utility.set_location( 'r_APF_unique.information3 '||r_APF_unique.information3,10);
14628        -- If reuse objects flag is 'Y' then check for the object in the target business group
14629        -- if found insert the record into PLSql table and exit the loop else try create the
14630        -- object in the target business group
14631        --
14632        l_object_found_in_target := false ;
14633        --UPD START
14634        l_update := false;
14635        l_process_date := p_effective_date;
14636        l_dml_operation:= r_APF_unique.dml_operation ;
14637        open c_APF(r_APF_unique.table_route_id,
14638                         r_APF_unique.information1,
14639                         r_APF_unique.information2,
14640                         r_APF_unique.information3 ) ;
14641        --
14642        fetch c_APF into r_APF ;
14643        --
14644        close c_APF ;
14645        --
14646        l_ACTY_BASE_RT_ID := get_fk('ACTY_BASE_RT_ID', r_APF.INFORMATION253,r_APF.dml_operation);
14647        l_PYMT_SCHED_RL := get_fk('FORMULA_ID', r_APF.INFORMATION257,r_APF.dml_operation);
14648        l_PYMT_SCHED_CD := r_APF.INFORMATION11;
14649 
14650        --
14651        if l_dml_operation = 'UPDATE' then
14652          --
14653                  l_object_found_in_target := TRUE;
14654                  --
14655                  if l_process_date between r_APF_unique.information2 and r_APF_unique.information3 then
14656                        l_update := true;
14657                        if r_APF_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
14658                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ACTY_RT_PYMT_SCHED_ID'
14659                        then
14660                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ACTY_RT_PYMT_SCHED_ID' ;
14661                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_APF_unique.information1 ;
14662                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_APF_unique.information1 ;
14663                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
14664                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_APF_unique.table_route_id;
14665                           --
14666                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
14667                           --
14668                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
14669                           --
14670                           --BEN_PD_COPY_TO_BEN_ONE.log_data('APF',l_new_value,l_prefix || r_APF_unique.name|| l_suffix,'REUSED');
14671                           --
14672                        end if ;
14673                        hr_utility.set_location( 'found record for update',10);
14674                    --
14675                  else
14676                    --
14677                    l_update := false;
14678                    --
14679                  end if;
14680        else
14681          --
14682          --UPD END
14683 
14684                l_min_esd := null ;
14685                l_max_eed := null ;
14686                open c_APF_min_max_dates(r_APF_unique.table_route_id, r_APF_unique.information1 ) ;
14687                fetch c_APF_min_max_dates into l_min_esd,l_max_eed ;
14688                --
14689 
14690                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
14691                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
14692                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
14693                end if;
14694                l_min_esd := greatest(l_min_esd,r_APF_unique.information2);
14695                /*open c_APF(r_APF_unique.table_route_id,
14696                         r_APF_unique.information1,
14697                         r_APF_unique.information2,
14698                         r_APF_unique.information3 ) ;
14699                --
14700                fetch c_APF into r_APF ;
14701                --
14702                close c_APF ;*/
14703                --
14704                if p_reuse_object_flag = 'Y' then
14705                  if c_APF_min_max_dates%found then
14706                    -- cursor to find the object
14707                    open c_find_APF_in_target( l_min_esd,l_max_eed,
14708                                          p_target_business_group_id, nvl(l_acty_rt_pymt_sched_id, -999)  ) ;
14709                    fetch c_find_APF_in_target into l_new_value ;
14710                    if c_find_APF_in_target%found then
14711                      --TEMPIK
14712                      l_dt_rec_found :=   dt_api.check_min_max_dates
14713                          (p_base_table_name => 'BEN_ACTY_RT_PYMT_SCHED_F',
14714                           p_base_key_column => 'ACTY_RT_PYMT_SCHED_ID',
14715                           p_base_key_value  => l_new_value,
14716                           p_from_date       => l_min_esd,
14717                           p_to_date         => l_max_eed );
14718                      if l_dt_rec_found THEN
14719                      --END TEMPIK             --
14720                                          if r_APF_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999) or
14721                                                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <>  'ACTY_RT_PYMT_SCHED_ID'  then
14722                                                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ACTY_RT_PYMT_SCHED_ID' ;
14723                                                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_APF_unique.information1 ;
14724                                                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := l_new_value ;
14725                                                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
14726                                                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_APF_unique.table_route_id;
14727                                                 --
14728                                                 -- update_cer_with_target( BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count) , p_copy_entity_txn_id) ;
14729                                                 --
14730                                                 BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
14731                                                 --
14732                                          end if ;
14733                                          --
14734                                          l_object_found_in_target := true ;
14735                      --TEMPIK
14736                      end if; -- l_dt_rec_found
14737                      --END TEMPIK
14738                    end if;
14739                    close c_find_APF_in_target ;
14740                  --
14741                  end if;
14742                end if ;
14743                --
14744                close c_APF_min_max_dates ;
14745        end if; --if p_dml_operation
14746        --
14747        if not l_object_found_in_target OR l_update  then
14748        --if not l_object_found_in_target then
14749          --
14750          l_current_pk_id := r_APF.information1;
14751          --
14752          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
14753          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
14754          --
14755          if l_current_pk_id =  l_prev_pk_id  then
14756            --
14757            l_first_rec := false ;
14758            --
14759          else
14760            --
14761            l_first_rec := true ;
14762            --
14763          end if ;
14764          --
14765 
14766          l_effective_date := r_APF.information2;
14767          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
14768               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
14769            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
14770          end if;
14771 
14772          --if l_first_rec then
14773          if l_first_rec and not l_update then
14774 
14775            -- Call Create routine.
14776            hr_utility.set_location(' BEN_ACTY_RT_PYMT_SCHED_F CREATE_ACTY_RT_PYMT_SCHED ',20);
14777            BEN_ACTY_RT_PYMT_SCHED_API.CREATE_ACTY_RT_PYMT_SCHED(
14778              --
14779              P_VALIDATE               => false
14780              ,P_EFFECTIVE_DATE        => l_effective_date
14781              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
14782              --
14783              ,P_ACTY_BASE_RT_ID      => l_ACTY_BASE_RT_ID
14784              ,P_ACTY_RT_PYMT_SCHED_ID      => l_acty_rt_pymt_sched_id
14785              ,P_APF_ATTRIBUTE1      => r_APF.INFORMATION111
14786              ,P_APF_ATTRIBUTE10      => r_APF.INFORMATION120
14787              ,P_APF_ATTRIBUTE11      => r_APF.INFORMATION121
14788              ,P_APF_ATTRIBUTE12      => r_APF.INFORMATION122
14789              ,P_APF_ATTRIBUTE13      => r_APF.INFORMATION123
14790              ,P_APF_ATTRIBUTE14      => r_APF.INFORMATION124
14791              ,P_APF_ATTRIBUTE15      => r_APF.INFORMATION125
14792              ,P_APF_ATTRIBUTE16      => r_APF.INFORMATION126
14793              ,P_APF_ATTRIBUTE17      => r_APF.INFORMATION127
14794              ,P_APF_ATTRIBUTE18      => r_APF.INFORMATION128
14795              ,P_APF_ATTRIBUTE19      => r_APF.INFORMATION129
14796              ,P_APF_ATTRIBUTE2      => r_APF.INFORMATION112
14797              ,P_APF_ATTRIBUTE20      => r_APF.INFORMATION130
14798              ,P_APF_ATTRIBUTE21      => r_APF.INFORMATION131
14799              ,P_APF_ATTRIBUTE22      => r_APF.INFORMATION132
14800              ,P_APF_ATTRIBUTE23      => r_APF.INFORMATION133
14801              ,P_APF_ATTRIBUTE24      => r_APF.INFORMATION134
14802              ,P_APF_ATTRIBUTE25      => r_APF.INFORMATION135
14803              ,P_APF_ATTRIBUTE26      => r_APF.INFORMATION136
14804              ,P_APF_ATTRIBUTE27      => r_APF.INFORMATION137
14805              ,P_APF_ATTRIBUTE28      => r_APF.INFORMATION138
14806              ,P_APF_ATTRIBUTE29      => r_APF.INFORMATION139
14807              ,P_APF_ATTRIBUTE3      => r_APF.INFORMATION113
14808              ,P_APF_ATTRIBUTE30      => r_APF.INFORMATION140
14809              ,P_APF_ATTRIBUTE4      => r_APF.INFORMATION114
14810              ,P_APF_ATTRIBUTE5      => r_APF.INFORMATION115
14811              ,P_APF_ATTRIBUTE6      => r_APF.INFORMATION116
14812              ,P_APF_ATTRIBUTE7      => r_APF.INFORMATION117
14813              ,P_APF_ATTRIBUTE8      => r_APF.INFORMATION118
14814              ,P_APF_ATTRIBUTE9      => r_APF.INFORMATION119
14815              ,P_APF_ATTRIBUTE_CATEGORY      => r_APF.INFORMATION110
14816              ,P_PYMT_SCHED_CD      => r_APF.INFORMATION11
14817              ,P_PYMT_SCHED_RL      => l_PYMT_SCHED_RL
14818              --
14819              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
14820              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
14821              ,P_OBJECT_VERSION_NUMBER =>        l_object_version_number
14822            );
14823            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
14824            -- Update all relevent cer records with new pk_id
14825            hr_utility.set_location('Before plsql table ',222);
14826            hr_utility.set_location('new_value id '||l_acty_rt_pymt_sched_id,222);
14827            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column := 'ACTY_RT_PYMT_SCHED_ID' ;
14828            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value    := r_APF.information1 ;
14829            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value    := l_ACTY_RT_PYMT_SCHED_ID ;
14830            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type  := 'COPIED';
14831            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_APF_unique.table_route_id;
14832            hr_utility.set_location('After plsql table ',222);
14833            --
14834            -- update_cer_with_target( BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count),p_copy_entity_txn_id ) ;
14835            --
14836            BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
14837            --
14838          else
14839            --
14840            -- Call Update routine for the pk_id created in prev run .
14841            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
14842            hr_utility.set_location(' BEN_ACTY_RT_PYMT_SCHED_F UPDATE_ACTY_RT_PYMT_SCHED ',30);
14843            --UPD START
14844            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
14845            --
14846            if l_update then
14847              --
14848              l_datetrack_mode := r_APF.datetrack_mode ;
14849              --
14850              get_dt_modes(
14851                p_effective_date        => l_process_date,
14852                p_effective_end_date    => r_APF.information3,
14853                p_effective_start_date  => r_APF.information2,
14854                p_dml_operation         => r_APF.dml_operation,
14855                p_datetrack_mode        => l_datetrack_mode );
14856            --    p_update                => l_update
14857              --
14858              l_effective_date := l_process_date;
14859              l_acty_rt_pymt_sched_id   := r_APF.information1;
14860              l_object_version_number := r_APF.information265;
14861              --
14862            end if;
14863            --
14864            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
14865            --
14866            IF l_update OR l_dml_operation <> 'UPDATE' THEN
14867            --UPD END
14868 
14869                    BEN_ACTY_RT_PYMT_SCHED_API.UPDATE_ACTY_RT_PYMT_SCHED(
14870                      --
14871                      P_VALIDATE               => false
14872                      ,P_EFFECTIVE_DATE        => l_effective_date
14873                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
14874                      --
14875                      ,P_ACTY_BASE_RT_ID      => l_ACTY_BASE_RT_ID
14876                      ,P_ACTY_RT_PYMT_SCHED_ID      => l_acty_rt_pymt_sched_id
14877                      ,P_APF_ATTRIBUTE1      => r_APF.INFORMATION111
14878                      ,P_APF_ATTRIBUTE10      => r_APF.INFORMATION120
14879                      ,P_APF_ATTRIBUTE11      => r_APF.INFORMATION121
14880                      ,P_APF_ATTRIBUTE12      => r_APF.INFORMATION122
14881                      ,P_APF_ATTRIBUTE13      => r_APF.INFORMATION123
14882                      ,P_APF_ATTRIBUTE14      => r_APF.INFORMATION124
14883                      ,P_APF_ATTRIBUTE15      => r_APF.INFORMATION125
14884                      ,P_APF_ATTRIBUTE16      => r_APF.INFORMATION126
14885                      ,P_APF_ATTRIBUTE17      => r_APF.INFORMATION127
14886                      ,P_APF_ATTRIBUTE18      => r_APF.INFORMATION128
14887                      ,P_APF_ATTRIBUTE19      => r_APF.INFORMATION129
14888                      ,P_APF_ATTRIBUTE2      => r_APF.INFORMATION112
14889                      ,P_APF_ATTRIBUTE20      => r_APF.INFORMATION130
14890                      ,P_APF_ATTRIBUTE21      => r_APF.INFORMATION131
14891                      ,P_APF_ATTRIBUTE22      => r_APF.INFORMATION132
14892                      ,P_APF_ATTRIBUTE23      => r_APF.INFORMATION133
14893                      ,P_APF_ATTRIBUTE24      => r_APF.INFORMATION134
14894                      ,P_APF_ATTRIBUTE25      => r_APF.INFORMATION135
14895                      ,P_APF_ATTRIBUTE26      => r_APF.INFORMATION136
14896                      ,P_APF_ATTRIBUTE27      => r_APF.INFORMATION137
14897                      ,P_APF_ATTRIBUTE28      => r_APF.INFORMATION138
14898                      ,P_APF_ATTRIBUTE29      => r_APF.INFORMATION139
14899                      ,P_APF_ATTRIBUTE3      => r_APF.INFORMATION113
14900                      ,P_APF_ATTRIBUTE30      => r_APF.INFORMATION140
14901                      ,P_APF_ATTRIBUTE4      => r_APF.INFORMATION114
14902                      ,P_APF_ATTRIBUTE5      => r_APF.INFORMATION115
14903                      ,P_APF_ATTRIBUTE6      => r_APF.INFORMATION116
14904                      ,P_APF_ATTRIBUTE7      => r_APF.INFORMATION117
14905                      ,P_APF_ATTRIBUTE8      => r_APF.INFORMATION118
14906                      ,P_APF_ATTRIBUTE9      => r_APF.INFORMATION119
14907                      ,P_APF_ATTRIBUTE_CATEGORY      => r_APF.INFORMATION110
14908                      ,P_PYMT_SCHED_CD      => r_APF.INFORMATION11
14909                      ,P_PYMT_SCHED_RL      => l_PYMT_SCHED_RL
14910                      --
14911                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
14912                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
14913                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
14914                      ,P_DATETRACK_MODE        => l_datetrack_mode
14915                      --,P_DATETRACK_MODE        => hr_api.g_update
14916                    );
14917             end if ;
14918          end if;
14919          --
14920          --
14921          -- Delete the row if it is end dated.
14922          --
14923          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
14924              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
14925            trunc(l_max_eed) = trunc(r_APF.information3)) then
14926            --
14927            BEN_ACTY_RT_PYMT_SCHED_API.delete_ACTY_RT_PYMT_SCHED(
14928               --
14929               p_validate                       => false
14930               ,p_acty_rt_pymt_sched_id                   => l_acty_rt_pymt_sched_id
14931               ,p_effective_start_date           => l_effective_start_date
14932               ,p_effective_end_date             => l_effective_end_date
14933               ,p_object_version_number          => l_object_version_number
14934               ,p_effective_date                 => l_max_eed
14935               ,p_datetrack_mode                 => hr_api.g_delete
14936               --
14937               );
14938               --
14939          end if;
14940          --
14941          l_prev_pk_id := l_current_pk_id ;
14942          --
14943        end if;
14944        --
14945      end if;
14946      --
14947    end loop;
14948    --
14949  exception when others then
14950      --
14951      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'APF',r_APF.information5 ) ;
14952      --
14953  end create_APF_rows;
14954 
14955  --
14956  ---------------------------------------------------------------
14957  ----------------------< create_ABC_rows >-----------------------
14958  ---------------------------------------------------------------
14959  --
14960  procedure create_ABC_rows
14961    (
14962          p_validate                       in  number     default 0
14963         ,p_copy_entity_txn_id             in  number
14964         ,p_effective_date                 in  date
14965         ,p_prefix_suffix_text             in  varchar2  default null
14966         ,p_reuse_object_flag              in  varchar2  default null
14967         ,p_target_business_group_id       in  varchar2  default null
14968         ,p_prefix_suffix_cd               in  varchar2  default null
14969    ) is
14970    --
14971    l_ACTY_BASE_RT_ID   number;
14972    l_CTFN_RQD_WHEN_RL  number;
14973    l_ENRT_CTFN_TYP_CD  ben_acty_base_rt_ctfn_f.enrt_ctfn_typ_cd%type;
14974 
14975    cursor c_unique_ABC(l_table_alias varchar2) is
14976    select distinct cpe.information1,
14977      cpe.information2,
14978      cpe.information3,
14979      cpe.table_route_id,
14980      cpe.dml_operation,cpe.datetrack_mode
14981    from ben_copy_entity_results cpe,
14982         pqh_table_route tr
14983    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
14984    and   cpe.table_route_id     = tr.table_route_id
14985    -- and   tr.where_clause        = l_BEN_ACTY_BASE_RT_CTFN_F
14986    and   tr.table_alias = l_table_alias
14987    and   cpe.number_of_copies   = 1 -- ADDITION
14988    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
14989    order by information1, information2; --added for bug: 5151945
14990    --
14991    --
14992    cursor c_ABC_min_max_dates(c_table_route_id  number,
14993                 c_information1   varchar2) is
14994    select
14995      min(cpe.information2) min_esd,
14996      max(cpe.information3) min_eed
14997    from ben_copy_entity_results cpe
14998    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
14999    and   cpe.table_route_id     = c_table_route_id
15000    and   cpe.information1       = c_information1 ;
15001    --
15002    cursor c_ABC(c_table_route_id  number,
15003                 c_information1   number,
15004                 c_information2   date,          /* Bug 4350396 */
15005                 c_information3   date )  is
15006    select
15007      cpe.*
15008    from ben_copy_entity_results cpe
15009    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
15010    and   cpe.table_route_id     = c_table_route_id
15011    and   cpe.information1       = c_information1
15012    and   cpe.information2       = c_information2
15013    and   cpe.information3       = c_information3
15014    and rownum = 1 ;
15015    -- Date Track target record
15016    cursor c_find_ABC_in_target(
15017                                 c_effective_start_date    date,
15018                                 c_effective_end_date      date,
15019                                 c_business_group_id       number,
15020                                 c_new_pk_id               number) is
15021    select
15022      ABC.acty_base_rt_ctfn_id new_value
15023    from BEN_ACTY_BASE_RT_CTFN_F ABC
15024    where
15025    ABC.ACTY_BASE_RT_ID    = l_ACTY_BASE_RT_ID  and
15026    ABC.ENRT_CTFN_TYP_CD   = l_ENRT_CTFN_TYP_CD and
15027    ABC.business_group_id  = c_business_group_id
15028    and   ABC.acty_base_rt_ctfn_id  <> c_new_pk_id
15029 --TEMPIK
15030    and c_effective_start_date between effective_start_date
15031                             and effective_end_date ;
15032 --END TEMPIK
15033 /*TEMPIK
15034    and exists ( select null
15035                 from BEN_ACTY_BASE_RT_CTFN_F ABC1
15036                 where
15037                 ABC1.ACTY_BASE_RT_ID    = l_ACTY_BASE_RT_ID  and
15038                 ABC1.ENRT_CTFN_TYP_CD   = l_ENRT_CTFN_TYP_CD and
15039                 ABC1.business_group_id  = c_business_group_id
15040                 and   ABC1.effective_start_date <= c_effective_start_date )
15041    and exists ( select null
15042                 from BEN_ACTY_BASE_RT_CTFN_F ABC2
15043                 where
15044                 ABC2.ACTY_BASE_RT_ID    = l_ACTY_BASE_RT_ID  and
15045                 ABC2.ENRT_CTFN_TYP_CD   = l_ENRT_CTFN_TYP_CD and
15046                 ABC2.business_group_id  = c_business_group_id
15047                 and   ABC2.effective_end_date >= c_effective_end_date )
15048                 ;
15049 TEMPIK */
15050    --TEMPIK
15051    l_dt_rec_found            boolean ;
15052    --END TEMPIK
15053    --
15054    --UPD START
15055    --
15056    l_update                  boolean      := false ;
15057    l_datetrack_mode          varchar2(80) := hr_api.g_update;
15058    l_process_date            date;
15059    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
15060    --
15061    --UPD END
15062 
15063    --
15064    l_current_pk_id           number := null ;
15065    l_prev_pk_id              number := null ;
15066    l_first_rec               boolean := true ;
15067    r_ABC                     c_ABC%rowtype;
15068    l_acty_base_rt_ctfn_id             number ;
15069    l_object_version_number   number ;
15070    l_effective_start_date    date ;
15071    l_effective_end_date      date ;
15072    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
15073    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
15074    l_new_value               number(15);
15075    l_object_found_in_target  boolean := false ;
15076    l_min_esd                 date;
15077    l_max_eed                 date;
15078    l_effective_date          date;
15079    --
15080  begin
15081    -- Initialization
15082    l_object_found_in_target := false ;
15083    -- End Initialization
15084    -- Derive the prefix - sufix
15085    if   p_prefix_suffix_cd = 'PREFIX' then
15086      l_prefix  := p_prefix_suffix_text ;
15087    elsif p_prefix_suffix_cd = 'SUFFIX' then
15088      l_suffix   := p_prefix_suffix_text ;
15089    else
15090      l_prefix := null ;
15091      l_suffix  := null ;
15092    end if ;
15093    -- End Prefix Sufix derivation
15094    for r_ABC_unique in c_unique_ABC('ABC') loop
15095 
15096      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
15097         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
15098          r_ABC_unique.information3 >=
15099                  ben_pd_copy_to_ben_one.g_copy_effective_date)
15100         ) then
15101        --
15102        hr_utility.set_location(' r_ABC_unique.table_route_id '||r_ABC_unique.table_route_id,10);
15103        hr_utility.set_location(' r_ABC_unique.information1 '||r_ABC_unique.information1,10);
15104        hr_utility.set_location( 'r_ABC_unique.information2 '||r_ABC_unique.information2,10);
15105        hr_utility.set_location( 'r_ABC_unique.information3 '||r_ABC_unique.information3,10);
15106        -- If reuse objects flag is 'Y' then check for the object in the target business group
15107        -- if found insert the record into PLSql table and exit the loop else try create the
15108        -- object in the target business group
15109        --
15110        l_object_found_in_target := false ;
15111        --
15112        --UPD START
15113        l_update := false;
15114        l_process_date := p_effective_date;
15115        --
15116        open c_ABC(r_ABC_unique.table_route_id,
15117                 r_ABC_unique.information1,
15118                 r_ABC_unique.information2,
15119                 r_ABC_unique.information3 ) ;
15120        --
15121        fetch c_ABC into r_ABC ;
15122        --
15123        close c_ABC ;
15124        --
15125        l_dml_operation:= r_ABC_unique.dml_operation ;
15126        l_ACTY_BASE_RT_ID := get_fk('ACTY_BASE_RT_ID', r_ABC.INFORMATION253,r_ABC.dml_operation);
15127        l_CTFN_RQD_WHEN_RL := get_fk('FORMULA_ID', r_ABC.INFORMATION260,r_ABC.dml_operation);
15128        l_ENRT_CTFN_TYP_CD := r_ABC.INFORMATION11;
15129        --
15130        --
15131        if l_dml_operation = 'UPDATE' then
15132          --
15133                  l_object_found_in_target := TRUE;
15134                  --
15135                  if l_process_date between r_ABC_unique.information2 and r_ABC_unique.information3 then
15136                        l_update := true;
15137                        if r_ABC_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
15138                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ACTY_BASE_RT_CTFN_ID'
15139                        then
15140                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ACTY_BASE_RT_CTFN_ID' ;
15141                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_ABC_unique.information1 ;
15142                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_ABC_unique.information1 ;
15143                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
15144                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_ABC_unique.table_route_id;
15145                           --
15146                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
15147                           --
15148                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
15149                           --
15150                           --BEN_PD_COPY_TO_BEN_ONE.log_data('ABC',l_new_value,l_prefix || r_ABC_unique.name|| l_suffix,'REUSED');
15151                           --
15152                        end if ;
15153                        hr_utility.set_location( 'found record for update',10);
15154                    --
15155                  else
15156                    --
15157                    l_update := false;
15158                    --
15159                  end if;
15160        else
15161          --
15162          --UPD END
15163        --
15164                l_min_esd := null ;
15165                l_max_eed := null ;
15166                open c_ABC_min_max_dates(r_ABC_unique.table_route_id, r_ABC_unique.information1 ) ;
15167                fetch c_ABC_min_max_dates into l_min_esd,l_max_eed ;
15168                --
15169 
15170                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
15171                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
15172                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
15173                end if;
15174                l_min_esd := greatest(l_min_esd,r_ABC_unique.information2);
15175                /*open c_ABC(r_ABC_unique.table_route_id,
15176                         r_ABC_unique.information1,
15177                         r_ABC_unique.information2,
15178                         r_ABC_unique.information3 ) ;
15179                --
15180                fetch c_ABC into r_ABC ;
15181                --
15182                close c_ABC ;*/
15183                --
15184 
15185                if p_reuse_object_flag = 'Y' then
15186                  if c_ABC_min_max_dates%found then
15187                    -- cursor to find the object
15188                    open c_find_ABC_in_target( l_min_esd,l_max_eed,
15189                                          p_target_business_group_id, nvl(l_acty_base_rt_ctfn_id, -999)  ) ;
15190                    fetch c_find_ABC_in_target into l_new_value ;
15191                    if c_find_ABC_in_target%found then
15192                      --TEMPIK
15193                      l_dt_rec_found :=   dt_api.check_min_max_dates
15194                          (p_base_table_name => 'BEN_ACTY_BASE_RT_CTFN_F',
15195                           p_base_key_column => 'ACTY_BASE_RT_CTFN_ID',
15196                           p_base_key_value  => l_new_value,
15197                           p_from_date       => l_min_esd,
15198                           p_to_date         => l_max_eed );
15199                      if l_dt_rec_found THEN
15200                      --END TEMPIK             --
15201                                          if r_ABC_unique.information1 <> nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).old_value, -999) or
15202                                                 nvl(ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count-1).pk_id_column, '999') <>  'ACTY_BASE_RT_CTFN_ID'  then
15203                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column    := 'ACTY_BASE_RT_CTFN_ID' ;
15204                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value       := r_ABC_unique.information1 ;
15205                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value       := l_new_value ;
15206                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type := 'REUSED';
15207                                                 ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_ABC_unique.table_route_id;
15208                                                 --
15209                                                 -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count) , p_copy_entity_txn_id) ;
15210                                                 --
15211                                                 ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
15212                                          end if ;
15213                                          --
15214                                          l_object_found_in_target := true ;
15215                      --TEMPIK
15216                      end if; -- l_dt_rec_found
15217                      --END TEMPIK
15218                    end if;
15219                    close c_find_ABC_in_target ;
15220                  --
15221                  end if;
15222                end if ;
15223                --
15224                close c_ABC_min_max_dates ;
15225 
15226        end if; --if p_dml_operation
15227        --
15228        if not l_object_found_in_target OR l_update  then
15229        --if not l_object_found_in_target then
15230          --
15231          l_current_pk_id := r_ABC.information1;
15232          --
15233          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
15234          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
15235          --
15236          if l_current_pk_id =  l_prev_pk_id  then
15237            --
15238            l_first_rec := false ;
15239            --
15240          else
15241            --
15242            l_first_rec := true ;
15243            --
15244          end if ;
15245          --
15246 
15247          l_effective_date := r_ABC.information2;
15248          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
15249               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
15250            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
15251          end if;
15252 
15253          --if l_first_rec then
15254          if l_first_rec and not l_update then
15255            -- Call Create routine.
15256            hr_utility.set_location(' BEN_ACTY_BASE_RT_CTFN_F CREATE_ACTY_BASE_RT_CTFN ',20);
15257            BEN_ACTY_BASE_RT_CTFN_API.CREATE_ACTY_BASE_RT_CTFN(
15258              --
15259              P_VALIDATE               => false
15260              ,P_EFFECTIVE_DATE        => l_effective_date
15261              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
15262              --
15263              ,P_ABC_ATTRIBUTE1      => r_ABC.INFORMATION111
15264              ,P_ABC_ATTRIBUTE10      => r_ABC.INFORMATION120
15265              ,P_ABC_ATTRIBUTE11      => r_ABC.INFORMATION121
15266              ,P_ABC_ATTRIBUTE12      => r_ABC.INFORMATION122
15267              ,P_ABC_ATTRIBUTE13      => r_ABC.INFORMATION123
15268              ,P_ABC_ATTRIBUTE14      => r_ABC.INFORMATION124
15269              ,P_ABC_ATTRIBUTE15      => r_ABC.INFORMATION125
15270              ,P_ABC_ATTRIBUTE16      => r_ABC.INFORMATION126
15271              ,P_ABC_ATTRIBUTE17      => r_ABC.INFORMATION127
15272              ,P_ABC_ATTRIBUTE18      => r_ABC.INFORMATION128
15273              ,P_ABC_ATTRIBUTE19      => r_ABC.INFORMATION129
15274              ,P_ABC_ATTRIBUTE2      => r_ABC.INFORMATION112
15275              ,P_ABC_ATTRIBUTE20      => r_ABC.INFORMATION130
15276              ,P_ABC_ATTRIBUTE21      => r_ABC.INFORMATION131
15277              ,P_ABC_ATTRIBUTE22      => r_ABC.INFORMATION132
15278              ,P_ABC_ATTRIBUTE23      => r_ABC.INFORMATION133
15279              ,P_ABC_ATTRIBUTE24      => r_ABC.INFORMATION134
15280              ,P_ABC_ATTRIBUTE25      => r_ABC.INFORMATION135
15281              ,P_ABC_ATTRIBUTE26      => r_ABC.INFORMATION136
15282              ,P_ABC_ATTRIBUTE27      => r_ABC.INFORMATION137
15283              ,P_ABC_ATTRIBUTE28      => r_ABC.INFORMATION138
15284              ,P_ABC_ATTRIBUTE29      => r_ABC.INFORMATION139
15285              ,P_ABC_ATTRIBUTE3      => r_ABC.INFORMATION113
15286              ,P_ABC_ATTRIBUTE30      => r_ABC.INFORMATION140
15287              ,P_ABC_ATTRIBUTE4      => r_ABC.INFORMATION114
15288              ,P_ABC_ATTRIBUTE5      => r_ABC.INFORMATION115
15289              ,P_ABC_ATTRIBUTE6      => r_ABC.INFORMATION116
15290              ,P_ABC_ATTRIBUTE7      => r_ABC.INFORMATION117
15291              ,P_ABC_ATTRIBUTE8      => r_ABC.INFORMATION118
15292              ,P_ABC_ATTRIBUTE9      => r_ABC.INFORMATION119
15293              ,P_ABC_ATTRIBUTE_CATEGORY      => r_ABC.INFORMATION110
15294              ,P_ACTY_BASE_RT_CTFN_ID      => l_acty_base_rt_ctfn_id
15295              ,P_ACTY_BASE_RT_ID      => l_ACTY_BASE_RT_ID
15296              ,P_CTFN_RQD_WHEN_RL      => l_CTFN_RQD_WHEN_RL
15297              ,P_ENRT_CTFN_TYP_CD      => r_ABC.INFORMATION11
15298              ,P_RQD_FLAG      => r_ABC.INFORMATION12
15299              --
15300              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
15301              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
15302              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
15303            );
15304            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
15305            -- Update all relevent cer records with new pk_id
15306            hr_utility.set_location('Before plsql table ',222);
15307            hr_utility.set_location('new_value id '||l_acty_base_rt_ctfn_id,222);
15308            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).pk_id_column := 'ACTY_BASE_RT_CTFN_ID' ;
15309            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).old_value    := r_ABC.information1 ;
15310            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).new_value    := l_ACTY_BASE_RT_CTFN_ID ;
15311            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).copy_reuse_type  := 'COPIED';
15312            ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count).table_route_id  := r_ABC_unique.table_route_id;
15313            hr_utility.set_location('After plsql table ',222);
15314            --
15315            -- update_cer_with_target( ben_pd_copy_to_ben_one.g_pk_tbl(ben_pd_copy_to_ben_one.g_count),p_copy_entity_txn_id ) ;
15316            --
15317            ben_pd_copy_to_ben_one.g_count := ben_pd_copy_to_ben_one.g_count + 1 ;
15318            --
15319          else
15320            --
15321            -- Call Update routine for the pk_id created in prev run .
15322            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
15323            hr_utility.set_location(' BEN_ACTY_BASE_RT_CTFN_F UPDATE_ACTY_BASE_RT_CTFN ',30);
15324            --UPD START
15325            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
15326            --
15327            if l_update then
15328              --
15329              l_datetrack_mode := r_ABC.datetrack_mode ;
15330              --
15331              get_dt_modes(
15332                p_effective_date        => l_process_date,
15333                p_effective_end_date    => r_ABC.information3,
15334                p_effective_start_date  => r_ABC.information2,
15335                p_dml_operation         => r_ABC.dml_operation,
15336                p_datetrack_mode        => l_datetrack_mode );
15337            --    p_update                => l_update
15338              --
15339              l_effective_date := l_process_date;
15340              l_acty_base_rt_ctfn_id   := r_ABC.information1;
15341              l_object_version_number := r_ABC.information265;
15342              --
15343            end if;
15344            --
15345            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
15346            --
15347            IF l_update OR l_dml_operation <> 'UPDATE' THEN
15348            --UPD END
15349 
15350                    BEN_ACTY_BASE_RT_CTFN_API.UPDATE_ACTY_BASE_RT_CTFN(
15351                      --
15352                      P_VALIDATE               => false
15353                      ,P_EFFECTIVE_DATE        => l_effective_date
15354                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
15355                      --
15356                      ,P_ABC_ATTRIBUTE1      => r_ABC.INFORMATION111
15357                      ,P_ABC_ATTRIBUTE10      => r_ABC.INFORMATION120
15358                      ,P_ABC_ATTRIBUTE11      => r_ABC.INFORMATION121
15359                      ,P_ABC_ATTRIBUTE12      => r_ABC.INFORMATION122
15360                      ,P_ABC_ATTRIBUTE13      => r_ABC.INFORMATION123
15361                      ,P_ABC_ATTRIBUTE14      => r_ABC.INFORMATION124
15362                      ,P_ABC_ATTRIBUTE15      => r_ABC.INFORMATION125
15363                      ,P_ABC_ATTRIBUTE16      => r_ABC.INFORMATION126
15364                      ,P_ABC_ATTRIBUTE17      => r_ABC.INFORMATION127
15365                      ,P_ABC_ATTRIBUTE18      => r_ABC.INFORMATION128
15366                      ,P_ABC_ATTRIBUTE19      => r_ABC.INFORMATION129
15367                      ,P_ABC_ATTRIBUTE2      => r_ABC.INFORMATION112
15368                      ,P_ABC_ATTRIBUTE20      => r_ABC.INFORMATION130
15369                      ,P_ABC_ATTRIBUTE21      => r_ABC.INFORMATION131
15370                      ,P_ABC_ATTRIBUTE22      => r_ABC.INFORMATION132
15371                      ,P_ABC_ATTRIBUTE23      => r_ABC.INFORMATION133
15372                      ,P_ABC_ATTRIBUTE24      => r_ABC.INFORMATION134
15373                      ,P_ABC_ATTRIBUTE25      => r_ABC.INFORMATION135
15374                      ,P_ABC_ATTRIBUTE26      => r_ABC.INFORMATION136
15375                      ,P_ABC_ATTRIBUTE27      => r_ABC.INFORMATION137
15376                      ,P_ABC_ATTRIBUTE28      => r_ABC.INFORMATION138
15377                      ,P_ABC_ATTRIBUTE29      => r_ABC.INFORMATION139
15378                      ,P_ABC_ATTRIBUTE3      => r_ABC.INFORMATION113
15379                      ,P_ABC_ATTRIBUTE30      => r_ABC.INFORMATION140
15380                      ,P_ABC_ATTRIBUTE4      => r_ABC.INFORMATION114
15381                      ,P_ABC_ATTRIBUTE5      => r_ABC.INFORMATION115
15382                      ,P_ABC_ATTRIBUTE6      => r_ABC.INFORMATION116
15383                      ,P_ABC_ATTRIBUTE7      => r_ABC.INFORMATION117
15384                      ,P_ABC_ATTRIBUTE8      => r_ABC.INFORMATION118
15385                      ,P_ABC_ATTRIBUTE9      => r_ABC.INFORMATION119
15386                      ,P_ABC_ATTRIBUTE_CATEGORY      => r_ABC.INFORMATION110
15387                      ,P_ACTY_BASE_RT_CTFN_ID      => l_acty_base_rt_ctfn_id
15388                      ,P_ACTY_BASE_RT_ID      => l_ACTY_BASE_RT_ID
15389                      ,P_CTFN_RQD_WHEN_RL      => l_CTFN_RQD_WHEN_RL
15390                      ,P_ENRT_CTFN_TYP_CD      => r_ABC.INFORMATION11
15391                      ,P_RQD_FLAG      => r_ABC.INFORMATION12
15392                      --
15393                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
15394                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
15395                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
15396                      --,P_DATETRACK_MODE        => hr_api.g_update
15397                      ,P_DATETRACK_MODE        => l_datetrack_mode
15398                    );
15399               end if;  -- l_update
15400          end if;
15401          --
15402          --
15403          -- Delete the row if it is end dated.
15404          --
15405          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
15406              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
15407              trunc(l_max_eed) = trunc(r_ABC.information3)) then
15408              --
15409              BEN_ACTY_BASE_RT_CTFN_API.delete_ACTY_BASE_RT_CTFN(
15410                 --
15411                 p_validate                       => false
15412                 ,p_acty_base_rt_ctfn_id                   => l_acty_base_rt_ctfn_id
15413                 ,p_effective_start_date           => l_effective_start_date
15414                 ,p_effective_end_date             => l_effective_end_date
15415                 ,p_object_version_number          => l_object_version_number
15416                 ,p_effective_date                 => l_max_eed
15417                 ,p_datetrack_mode                 => hr_api.g_delete
15418                 --
15419                 );
15420                 --
15421          end if;
15422          --
15423          l_prev_pk_id := l_current_pk_id ;
15424          --
15425        end if;
15426        --
15427      end if;
15428      --
15429    end loop;
15430    --
15431  exception when others then
15432      --
15433      BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'ABC',r_ABC.information5 ) ;
15434      --
15435  end create_ABC_rows;
15436 
15437 
15438 --
15439 ---------------------------------------------------------------
15440 ----------------------< create_PMRPV_rows >-----------------------
15441 ---------------------------------------------------------------
15442 --
15443   procedure create_PMRPV_rows
15444    (
15445          p_validate                       in  number     default 0
15446         ,p_copy_entity_txn_id             in  number
15447         ,p_effective_date                 in  date
15448         ,p_prefix_suffix_text             in  varchar2  default null
15449         ,p_reuse_object_flag              in  varchar2  default null
15450         ,p_target_business_group_id       in  varchar2  default null
15451         ,p_prefix_suffix_cd               in  varchar2  default null
15452    ) is
15453    --
15454    l_RNDG_CD                                  VARCHAR2(30);
15455    l_TO_DY_MO_NUM                             NUMBER(15);
15456    l_FROM_DY_MO_NUM                           NUMBER(15);
15457    l_PCT_VAL                                  NUMBER;
15458    l_STRT_R_STP_CVG_CD                        VARCHAR2(30);
15459    l_RNDG_RL                                  NUMBER(15);
15460    l_PRTL_MO_PRORTN_RL                        NUMBER(15);
15461    l_ACTL_PREM_ID                             NUMBER(15);
15462    l_CVG_AMT_CALC_MTHD_ID                     NUMBER(15);
15463    l_ACTY_BASE_RT_ID                          NUMBER(15);
15464 
15465    cursor c_unique_PMRPV(l_table_alias varchar2) is
15466    select distinct cpe.information1,
15467      cpe.information2,
15468      cpe.information3,
15469      cpe.table_route_id,
15470      cpe.dml_operation,cpe.datetrack_mode
15471    from ben_copy_entity_results cpe,
15472         pqh_table_route tr
15473    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
15474    and   cpe.table_route_id     = tr.table_route_id
15475    -- and   tr.where_clause        = l_BEN_PRTL_MO_RT_PRTN_VAL_F
15476    and   tr.table_alias = l_table_alias
15477    and   cpe.number_of_copies   = 1 -- ADDITION
15478    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
15479    order by information1, information2; --added for bug: 5151945
15480    --
15481    --
15482    cursor c_PMRPV_min_max_dates(c_table_route_id  number,
15483                 c_information1   number) is
15484    select
15485      min(cpe.information2) min_esd,
15486      max(cpe.information3) min_eed
15487    from ben_copy_entity_results cpe
15488    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
15489    and   cpe.table_route_id     = c_table_route_id
15490    and   cpe.information1       = c_information1 ;
15491    --
15492    cursor c_PMRPV(c_table_route_id  number,
15493                 c_information1   number,
15494                 c_information2   date,
15495                 c_information3   date)  is
15496    select
15497      cpe.*
15498    from ben_copy_entity_results cpe
15499    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
15500    and   cpe.table_route_id     = c_table_route_id
15501    and   cpe.information1       = c_information1
15502    and   cpe.information2       = c_information2
15503    and   cpe.information3       = c_information3
15504    and rownum = 1 ;
15505    -- Date Track target record
15506    cursor c_find_PMRPV_in_target(
15507                                 c_effective_start_date    date,
15508                                 c_effective_end_date      date,
15509                                 c_business_group_id       number,
15510                                 c_new_pk_id               number) is
15511    select
15512      PMRPV.prtl_mo_rt_prtn_val_id new_value
15513    from BEN_PRTL_MO_RT_PRTN_VAL_F PMRPV
15514    where
15515    NVL(PMRPV.RNDG_CD,-999)              = NVL(l_RNDG_CD,-999) and
15516    NVL(PMRPV.TO_DY_MO_NUM,-999)         = NVL(l_TO_DY_MO_NUM,-999) and
15517    NVL(PMRPV.FROM_DY_MO_NUM,-999)       = NVL(l_FROM_DY_MO_NUM,-999) and
15518    NVL(PMRPV.PCT_VAL,-999)              = NVL(l_PCT_VAL,-999) and
15519    NVL(PMRPV.STRT_R_STP_CVG_CD,-999)    = NVL(l_STRT_R_STP_CVG_CD,-999) and
15520    NVL(PMRPV.RNDG_RL,-999)              = NVL(l_RNDG_RL,-999) and
15521    NVL(PMRPV.PRTL_MO_PRORTN_RL,-999)    = NVL(l_PRTL_MO_PRORTN_RL,-999) and
15522    NVL(PMRPV.ACTL_PREM_ID,-999)         = NVL(l_ACTL_PREM_ID,-999) and
15523    NVL(PMRPV.CVG_AMT_CALC_MTHD_ID,-999) = NVL(l_CVG_AMT_CALC_MTHD_ID,-999) and
15524    NVL(PMRPV.ACTY_BASE_RT_ID,-999)      = NVL(l_ACTY_BASE_RT_ID,-999) and
15525    PMRPV.business_group_id  = c_business_group_id
15526    and   PMRPV.prtl_mo_rt_prtn_val_id  <> c_new_pk_id
15527 --TEMPIK
15528    and c_effective_start_date between effective_start_date
15529                             and effective_end_date ;
15530 --END TEMPIK
15531 /*TEMPIK
15532    and exists ( select null
15533                 from BEN_PRTL_MO_RT_PRTN_VAL_F PMRPV1
15534                 where
15535                 NVL(PMRPV1.RNDG_CD,-999)              = NVL(l_RNDG_CD,-999) and
15536                 NVL(PMRPV1.TO_DY_MO_NUM,-999)         = NVL(l_TO_DY_MO_NUM,-999) and
15537                 NVL(PMRPV1.FROM_DY_MO_NUM,-999)       = NVL(l_FROM_DY_MO_NUM,-999) and
15538                 NVL(PMRPV1.PCT_VAL,-999)              = NVL(l_PCT_VAL,-999) and
15539                 NVL(PMRPV1.STRT_R_STP_CVG_CD,-999)    = NVL(l_STRT_R_STP_CVG_CD,-999) and
15540                 NVL(PMRPV1.RNDG_RL,-999)              = NVL(l_RNDG_RL,-999) and
15541                 NVL(PMRPV1.PRTL_MO_PRORTN_RL,-999)    = NVL(l_PRTL_MO_PRORTN_RL,-999) and
15542                 NVL(PMRPV1.ACTL_PREM_ID,-999)         = NVL(l_ACTL_PREM_ID,-999) and
15543                 NVL(PMRPV1.CVG_AMT_CALC_MTHD_ID,-999) = NVL(l_CVG_AMT_CALC_MTHD_ID,-999) and
15544                 NVL(PMRPV1.ACTY_BASE_RT_ID,-999)      = NVL(l_ACTY_BASE_RT_ID,-999) and
15545                 PMRPV1.business_group_id  = c_business_group_id
15546                 and   PMRPV1.effective_start_date <= c_effective_start_date )
15547    and exists ( select null
15548                 from BEN_PRTL_MO_RT_PRTN_VAL_F PMRPV2
15549                 where
15550                 NVL(PMRPV2.RNDG_CD,-999)              = NVL(l_RNDG_CD,-999) and
15551                 NVL(PMRPV2.TO_DY_MO_NUM,-999)         = NVL(l_TO_DY_MO_NUM,-999) and
15552                 NVL(PMRPV2.FROM_DY_MO_NUM,-999)       = NVL(l_FROM_DY_MO_NUM,-999) and
15553                 NVL(PMRPV2.PCT_VAL,-999)              = NVL(l_PCT_VAL,-999) and
15554                 NVL(PMRPV2.STRT_R_STP_CVG_CD,-999)    = NVL(l_STRT_R_STP_CVG_CD,-999) and
15555                 NVL(PMRPV2.RNDG_RL,-999)              = NVL(l_RNDG_RL,-999) and
15556                 NVL(PMRPV2.PRTL_MO_PRORTN_RL,-999)    = NVL(l_PRTL_MO_PRORTN_RL,-999) and
15557                 NVL(PMRPV2.ACTL_PREM_ID,-999)         = NVL(l_ACTL_PREM_ID,-999) and
15558                 NVL(PMRPV2.CVG_AMT_CALC_MTHD_ID,-999) = NVL(l_CVG_AMT_CALC_MTHD_ID,-999) and
15559                 NVL(PMRPV2.ACTY_BASE_RT_ID,-999)      = NVL(l_ACTY_BASE_RT_ID,-999) and
15560                 PMRPV2.business_group_id  = c_business_group_id
15561                 and   PMRPV2.effective_end_date >= c_effective_end_date )
15562                 ;
15563 TEMPIK */
15564    --TEMPIK
15565    l_dt_rec_found            boolean ;
15566    --END TEMPIK
15567    --
15568    --UPD START
15569    --
15570    l_update                  boolean      := false ;
15571    l_datetrack_mode          varchar2(80) := hr_api.g_update;
15572    l_process_date            date;
15573    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
15574    --
15575    --UPD END
15576    --
15577    l_current_pk_id           number := null ;
15578    l_prev_pk_id              number := null ;
15579    l_first_rec               boolean := true ;
15580    r_PMRPV                     c_PMRPV%rowtype;
15581    l_prtl_mo_rt_prtn_val_id             number ;
15582    l_object_version_number   number ;
15583    l_effective_start_date    date ;
15584    l_effective_end_date      date ;
15585    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
15586    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
15587    l_new_value               number(15);
15588    l_object_found_in_target  boolean := false ;
15589    l_min_esd                 date;
15590    l_max_eed                 date;
15591    l_effective_date          date;
15592    --
15593  begin
15594    -- Initialization
15595    l_object_found_in_target := false ;
15596    -- End Initialization
15597    -- Derive the prefix - sufix
15598    if   p_prefix_suffix_cd = 'PREFIX' then
15599      l_prefix  := p_prefix_suffix_text ;
15600    elsif p_prefix_suffix_cd = 'SUFFIX' then
15601      l_suffix   := p_prefix_suffix_text ;
15602    else
15603      l_prefix := null ;
15604      l_suffix  := null ;
15605    end if ;
15606    -- End Prefix Sufix derivation
15607    for r_PMRPV_unique in c_unique_PMRPV('PMRPV') loop
15608 
15609      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
15610         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
15611          r_PMRPV_unique.information3 >=
15612                  ben_pd_copy_to_ben_one.g_copy_effective_date)
15613         ) then
15614        --
15615        hr_utility.set_location(' r_PMRPV_unique.table_route_id '||r_PMRPV_unique.table_route_id,10);
15616        hr_utility.set_location(' r_PMRPV_unique.information1 '||r_PMRPV_unique.information1,10);
15617        hr_utility.set_location( 'r_PMRPV_unique.information2 '||r_PMRPV_unique.information2,10);
15618        hr_utility.set_location( 'r_PMRPV_unique.information3 '||r_PMRPV_unique.information3,10);
15619        -- If reuse objects flag is 'Y' then check for the object in the target business group
15620        -- if found insert the record into PLSql table and exit the loop else try create the
15621        -- object in the target business group
15622        --
15623        l_object_found_in_target := false ;
15624        --
15625        --UPD START
15626        l_update := false;
15627        l_process_date := p_effective_date;
15628        l_dml_operation:= r_PMRPV_unique.dml_operation ;
15629        --
15630        open c_PMRPV(r_PMRPV_unique.table_route_id,
15631                 r_PMRPV_unique.information1,
15632                 r_PMRPV_unique.information2,
15633                 r_PMRPV_unique.information3 ) ;
15634        --
15635        fetch c_PMRPV into r_PMRPV ;
15636        --
15637        close c_PMRPV ;
15638        --
15639 
15640        l_RNDG_CD                := r_PMRPV.information11;
15641        l_TO_DY_MO_NUM           := r_PMRPV.information260;
15642        l_FROM_DY_MO_NUM         := r_PMRPV.information261;
15643        l_PCT_VAL                := r_PMRPV.information293;
15644        l_STRT_R_STP_CVG_CD      := r_PMRPV.information12;
15645        l_RNDG_RL                := get_fk('FORMULA_ID', r_PMRPV.information262,r_PMRPV.dml_operation);
15646        l_PRTL_MO_PRORTN_RL      := get_fk('FORMULA_ID', r_PMRPV.information263,r_PMRPV.dml_operation);
15647        l_ACTL_PREM_ID           := get_fk('ACTL_PREM_ID', r_PMRPV.information250,r_PMRPV.dml_operation);
15648        l_CVG_AMT_CALC_MTHD_ID   := get_fk('CVG_AMT_CALC_MTHD_ID', r_PMRPV.information238,r_PMRPV.dml_operation);
15649        l_ACTY_BASE_RT_ID        := get_fk('ACTY_BASE_RT_ID', r_PMRPV.information253,r_PMRPV.dml_operation);
15650        --
15651        if l_dml_operation = 'UPDATE' then
15652          --
15653                  l_object_found_in_target := TRUE;
15654                  --
15655                  if l_process_date between r_PMRPV_unique.information2 and r_PMRPV_unique.information3 then
15656                        l_update := true;
15657                        if r_PMRPV_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
15658                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'PRTL_MO_RT_PRTN_VAL_ID'
15659                        then
15660                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'PRTL_MO_RT_PRTN_VAL_ID' ;
15661                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_PMRPV_unique.information1 ;
15662                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_PMRPV_unique.information1 ;
15663                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
15664                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_PMRPV_unique.table_route_id;
15665                           --
15666                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
15667                           --
15668                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
15669                           --
15670                           --BEN_PD_COPY_TO_BEN_ONE.log_data('PMRPV',l_new_value,l_prefix || r_PMRPV_unique.name|| l_suffix,'REUSED');
15671                           --
15672                        end if ;
15673                        hr_utility.set_location( 'found record for update',10);
15674                    --
15675                  else
15676                    --
15677                    l_update := false;
15678                    --
15679                  end if;
15680        else
15681          --
15682          --UPD END
15683        --
15684        l_min_esd := null ;
15685        l_max_eed := null ;
15686        open c_PMRPV_min_max_dates(r_PMRPV_unique.table_route_id, r_PMRPV_unique.information1 ) ;
15687        fetch c_PMRPV_min_max_dates into l_min_esd,l_max_eed ;
15688        --
15689 
15690        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
15691             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
15692          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
15693        end if;
15694        l_min_esd := greatest(l_min_esd,r_PMRPV_unique.information2);
15695 
15696        if p_reuse_object_flag = 'Y' then
15697          if c_PMRPV_min_max_dates%found then
15698            -- cursor to find the object
15699            open c_find_PMRPV_in_target( l_min_esd,l_max_eed,
15700                                  p_target_business_group_id, nvl(l_prtl_mo_rt_prtn_val_id, -999)  ) ;
15701            fetch c_find_PMRPV_in_target into l_new_value ;
15702            if c_find_PMRPV_in_target%found then
15703              --TEMPIK
15704              l_dt_rec_found :=   dt_api.check_min_max_dates
15705                  (p_base_table_name => 'BEN_PRTL_MO_RT_PRTN_VAL_F',
15706                   p_base_key_column => 'PRTL_MO_RT_PRTN_VAL_ID',
15707                   p_base_key_value  => l_new_value,
15708                   p_from_date       => l_min_esd,
15709                   p_to_date         => l_max_eed );
15710              if l_dt_rec_found THEN
15711              --END TEMPIK
15712              --
15713                                  if r_PMRPV_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999) or
15714                                         nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <>  'PRTL_MO_RT_PRTN_VAL_ID'  then
15715                                         BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'PRTL_MO_RT_PRTN_VAL_ID' ;
15716                                         BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_PMRPV_unique.information1 ;
15717                                         BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := l_new_value ;
15718                                         BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
15719                                         BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_PMRPV_unique.table_route_id;
15720                                         --
15721                                         -- update_cer_with_target( BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count) , p_copy_entity_txn_id) ;
15722                                         --
15723                                         BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
15724                                  end if ;
15725              --
15726                                  l_object_found_in_target := true ;
15727              --TEMPIK
15728              end if; -- l_dt_rec_found
15729              --END TEMPIK
15730            end if;
15731            close c_find_PMRPV_in_target ;
15732          --
15733          end if;
15734        end if ;
15735        --
15736        close c_PMRPV_min_max_dates ;
15737 
15738        --if not l_object_found_in_target then
15739        end if; --if p_dml_operation
15740        --
15741        if not l_object_found_in_target OR l_update  then
15742          --
15743          l_current_pk_id := r_PMRPV.information1;
15744          --
15745          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
15746          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
15747          --
15748          if l_current_pk_id =  l_prev_pk_id  then
15749            --
15750            l_first_rec := false ;
15751            --
15752          else
15753            --
15754            l_first_rec := true ;
15755            --
15756          end if ;
15757          --
15758 
15759          l_effective_date := r_PMRPV.information2;
15760          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
15761               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
15762            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
15763          end if;
15764 
15765          --if l_first_rec then
15766          if l_first_rec and not l_update then
15767            -- Call Create routine.
15768            hr_utility.set_location(' BEN_PRTL_MO_RT_PRTN_VAL_F CREATE_PRTL_MO_RT_PRTN_VAL ',20);
15769            BEN_PRTL_MO_RT_PRTN_VAL_API.CREATE_PRTL_MO_RT_PRTN_VAL(
15770              --
15771              P_VALIDATE               => false
15772              ,P_EFFECTIVE_DATE        => l_effective_date
15773              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
15774               --
15775              ,P_ACTL_PREM_ID      => l_ACTL_PREM_ID
15776              ,P_ACTY_BASE_RT_ID      => l_ACTY_BASE_RT_ID
15777              ,P_CVG_AMT_CALC_MTHD_ID      => l_CVG_AMT_CALC_MTHD_ID
15778              ,P_FROM_DY_MO_NUM      => r_PMRPV.INFORMATION261
15779              ,P_PCT_VAL      => r_PMRPV.INFORMATION293
15780              ,P_PMRPV_ATTRIBUTE1      => r_PMRPV.INFORMATION111
15781              ,P_PMRPV_ATTRIBUTE10      => r_PMRPV.INFORMATION120
15782              ,P_PMRPV_ATTRIBUTE11      => r_PMRPV.INFORMATION121
15783              ,P_PMRPV_ATTRIBUTE12      => r_PMRPV.INFORMATION122
15784              ,P_PMRPV_ATTRIBUTE13      => r_PMRPV.INFORMATION123
15785              ,P_PMRPV_ATTRIBUTE14      => r_PMRPV.INFORMATION124
15786              ,P_PMRPV_ATTRIBUTE15      => r_PMRPV.INFORMATION125
15787              ,P_PMRPV_ATTRIBUTE16      => r_PMRPV.INFORMATION126
15788              ,P_PMRPV_ATTRIBUTE17      => r_PMRPV.INFORMATION127
15789              ,P_PMRPV_ATTRIBUTE18      => r_PMRPV.INFORMATION128
15790              ,P_PMRPV_ATTRIBUTE19      => r_PMRPV.INFORMATION129
15791              ,P_PMRPV_ATTRIBUTE2      => r_PMRPV.INFORMATION112
15792              ,P_PMRPV_ATTRIBUTE20      => r_PMRPV.INFORMATION130
15793              ,P_PMRPV_ATTRIBUTE21      => r_PMRPV.INFORMATION131
15794              ,P_PMRPV_ATTRIBUTE22      => r_PMRPV.INFORMATION132
15795              ,P_PMRPV_ATTRIBUTE23      => r_PMRPV.INFORMATION133
15796              ,P_PMRPV_ATTRIBUTE24      => r_PMRPV.INFORMATION134
15797              ,P_PMRPV_ATTRIBUTE25      => r_PMRPV.INFORMATION135
15798              ,P_PMRPV_ATTRIBUTE26      => r_PMRPV.INFORMATION136
15799              ,P_PMRPV_ATTRIBUTE27      => r_PMRPV.INFORMATION137
15800              ,P_PMRPV_ATTRIBUTE28      => r_PMRPV.INFORMATION138
15801              ,P_PMRPV_ATTRIBUTE29      => r_PMRPV.INFORMATION139
15802              ,P_PMRPV_ATTRIBUTE3      => r_PMRPV.INFORMATION113
15803              ,P_PMRPV_ATTRIBUTE30      => r_PMRPV.INFORMATION140
15804              ,P_PMRPV_ATTRIBUTE4      => r_PMRPV.INFORMATION114
15805              ,P_PMRPV_ATTRIBUTE5      => r_PMRPV.INFORMATION115
15806              ,P_PMRPV_ATTRIBUTE6      => r_PMRPV.INFORMATION116
15807              ,P_PMRPV_ATTRIBUTE7      => r_PMRPV.INFORMATION117
15808              ,P_PMRPV_ATTRIBUTE8      => r_PMRPV.INFORMATION118
15809              ,P_PMRPV_ATTRIBUTE9      => r_PMRPV.INFORMATION119
15810              ,P_PMRPV_ATTRIBUTE_CATEGORY      => r_PMRPV.INFORMATION110
15811              ,P_PRTL_MO_PRORTN_RL      => l_PRTL_MO_PRORTN_RL
15812              ,P_PRTL_MO_RT_PRTN_VAL_ID      => l_prtl_mo_rt_prtn_val_id
15813              ,P_RNDG_CD      => r_PMRPV.INFORMATION11
15814              ,P_RNDG_RL      => l_RNDG_RL
15815              ,P_STRT_R_STP_CVG_CD      => r_PMRPV.INFORMATION12
15816              ,P_TO_DY_MO_NUM      => r_PMRPV.INFORMATION260
15817            --
15818            -- Bug No 4440138 Added mappings for PRORATE_BY_DAY_TO_MON_FLAG and NUM_DAYS_MONTH
15819 	   --
15820              ,P_PRORATE_BY_DAY_TO_MON_FLAG => r_PMRPV.INFORMATION13
15821              ,P_NUM_DAYS_MONTH             => r_PMRPV.INFORMATION266
15822 	   -- End Bug No 4440138
15823 	   --
15824              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
15825              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
15826              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
15827            );
15828            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
15829            -- Update all relevent cer records with new pk_id
15830            hr_utility.set_location('Before plsql table ',222);
15831            hr_utility.set_location('new_value id '||l_prtl_mo_rt_prtn_val_id,222);
15832            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column := 'PRTL_MO_RT_PRTN_VAL_ID' ;
15833            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value    := r_PMRPV.information1 ;
15834            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value    := l_PRTL_MO_RT_PRTN_VAL_ID ;
15835            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type  := 'COPIED';
15836            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_PMRPV_unique.table_route_id;
15837            hr_utility.set_location('After plsql table ',222);
15838            --
15839            -- update_cer_with_target(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count),p_copy_entity_txn_id ) ;
15840            --
15841            BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
15842            --
15843          else
15844            --
15845            -- Call Update routine for the pk_id created in prev run .
15846            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
15847            hr_utility.set_location(' BEN_PRTL_MO_RT_PRTN_VAL_F UPDATE_PRTL_MO_RT_PRTN_VAL ',30);
15848            --UPD START
15849            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
15850            --
15851            if l_update then
15852              --
15853              l_datetrack_mode := r_PMRPV.datetrack_mode ;
15854              --
15855              get_dt_modes(
15856                p_effective_date        => l_process_date,
15857                p_effective_end_date    => r_PMRPV.information3,
15858                p_effective_start_date  => r_PMRPV.information2,
15859                p_dml_operation         => r_PMRPV.dml_operation,
15860                p_datetrack_mode        => l_datetrack_mode );
15861            --    p_update                => l_update
15862              --
15863              l_effective_date := l_process_date;
15864              l_prtl_mo_rt_prtn_val_id   := r_PMRPV.information1;
15865              l_object_version_number := r_PMRPV.information265;
15866              --
15867            end if;
15868            --
15869            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
15870            --
15871            IF l_update OR l_dml_operation <> 'UPDATE' THEN
15872            --UPD END
15873 
15874            BEN_PRTL_MO_RT_PRTN_VAL_API.UPDATE_PRTL_MO_RT_PRTN_VAL(
15875              --
15876              P_VALIDATE               => false
15877              ,P_EFFECTIVE_DATE        => l_effective_date
15878              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
15879              --
15880              ,P_ACTL_PREM_ID      => l_ACTL_PREM_ID
15881              ,P_ACTY_BASE_RT_ID      => l_ACTY_BASE_RT_ID
15882              ,P_CVG_AMT_CALC_MTHD_ID      => l_CVG_AMT_CALC_MTHD_ID
15883              ,P_FROM_DY_MO_NUM      => r_PMRPV.INFORMATION261
15884              ,P_PCT_VAL      => r_PMRPV.INFORMATION293
15885              ,P_PMRPV_ATTRIBUTE1      => r_PMRPV.INFORMATION111
15886              ,P_PMRPV_ATTRIBUTE10      => r_PMRPV.INFORMATION120
15887              ,P_PMRPV_ATTRIBUTE11      => r_PMRPV.INFORMATION121
15888              ,P_PMRPV_ATTRIBUTE12      => r_PMRPV.INFORMATION122
15889              ,P_PMRPV_ATTRIBUTE13      => r_PMRPV.INFORMATION123
15890              ,P_PMRPV_ATTRIBUTE14      => r_PMRPV.INFORMATION124
15891              ,P_PMRPV_ATTRIBUTE15      => r_PMRPV.INFORMATION125
15892              ,P_PMRPV_ATTRIBUTE16      => r_PMRPV.INFORMATION126
15893              ,P_PMRPV_ATTRIBUTE17      => r_PMRPV.INFORMATION127
15894              ,P_PMRPV_ATTRIBUTE18      => r_PMRPV.INFORMATION128
15895              ,P_PMRPV_ATTRIBUTE19      => r_PMRPV.INFORMATION129
15896              ,P_PMRPV_ATTRIBUTE2      => r_PMRPV.INFORMATION112
15897              ,P_PMRPV_ATTRIBUTE20      => r_PMRPV.INFORMATION130
15898              ,P_PMRPV_ATTRIBUTE21      => r_PMRPV.INFORMATION131
15899              ,P_PMRPV_ATTRIBUTE22      => r_PMRPV.INFORMATION132
15900              ,P_PMRPV_ATTRIBUTE23      => r_PMRPV.INFORMATION133
15901              ,P_PMRPV_ATTRIBUTE24      => r_PMRPV.INFORMATION134
15902              ,P_PMRPV_ATTRIBUTE25      => r_PMRPV.INFORMATION135
15903              ,P_PMRPV_ATTRIBUTE26      => r_PMRPV.INFORMATION136
15904              ,P_PMRPV_ATTRIBUTE27      => r_PMRPV.INFORMATION137
15905              ,P_PMRPV_ATTRIBUTE28      => r_PMRPV.INFORMATION138
15906              ,P_PMRPV_ATTRIBUTE29      => r_PMRPV.INFORMATION139
15907              ,P_PMRPV_ATTRIBUTE3      => r_PMRPV.INFORMATION113
15908              ,P_PMRPV_ATTRIBUTE30      => r_PMRPV.INFORMATION140
15909              ,P_PMRPV_ATTRIBUTE4      => r_PMRPV.INFORMATION114
15910              ,P_PMRPV_ATTRIBUTE5      => r_PMRPV.INFORMATION115
15911              ,P_PMRPV_ATTRIBUTE6      => r_PMRPV.INFORMATION116
15912              ,P_PMRPV_ATTRIBUTE7      => r_PMRPV.INFORMATION117
15913              ,P_PMRPV_ATTRIBUTE8      => r_PMRPV.INFORMATION118
15914              ,P_PMRPV_ATTRIBUTE9      => r_PMRPV.INFORMATION119
15915              ,P_PMRPV_ATTRIBUTE_CATEGORY      => r_PMRPV.INFORMATION110
15916              ,P_PRTL_MO_PRORTN_RL      => l_PRTL_MO_PRORTN_RL
15917              ,P_PRTL_MO_RT_PRTN_VAL_ID      => l_prtl_mo_rt_prtn_val_id
15918              ,P_RNDG_CD      => r_PMRPV.INFORMATION11
15919              ,P_RNDG_RL      => l_RNDG_RL
15920              ,P_STRT_R_STP_CVG_CD      => r_PMRPV.INFORMATION12
15921              ,P_TO_DY_MO_NUM      => r_PMRPV.INFORMATION260
15922            --
15923            -- Bug No 4440138 Added mappings for PRORATE_BY_DAY_TO_MON_FLAG and NUM_DAYS_MONTH
15924 	   --
15925              ,P_PRORATE_BY_DAY_TO_MON_FLAG => r_PMRPV.INFORMATION13
15926              ,P_NUM_DAYS_MONTH             => r_PMRPV.INFORMATION266
15927 	   -- End Bug No 4440138
15928 	   --
15929              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
15930              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
15931              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
15932              --,P_DATETRACK_MODE        => hr_api.g_update
15933              ,P_DATETRACK_MODE          => l_datetrack_mode
15934            );
15935           end if;  -- l_update
15936          end if;
15937          --
15938          --
15939          -- Delete the row if it is end dated.
15940          --
15941          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
15942              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
15943            trunc(l_max_eed) = r_PMRPV.information3) then
15944              --
15945              BEN_PRTL_MO_RT_PRTN_VAL_API.delete_PRTL_MO_RT_PRTN_VAL(
15946                 --
15947                 p_validate                       => false
15948                 ,p_prtl_mo_rt_prtn_val_id                   => l_prtl_mo_rt_prtn_val_id
15949                 ,p_effective_start_date           => l_effective_start_date
15950                 ,p_effective_end_date             => l_effective_end_date
15951                 ,p_object_version_number          => l_object_version_number
15952                 ,p_effective_date                 => l_max_eed
15953                 ,p_datetrack_mode                 => hr_api.g_delete
15954                 --
15955                 );
15956                 --
15957          end if;
15958          --
15959          l_prev_pk_id := l_current_pk_id ;
15960          --
15961        end if;
15962        --
15963      end if;
15964      --
15965    end loop;
15966    --
15967  end create_PMRPV_rows;
15968 
15969  --
15970  ---------------------------------------------------------------
15971  ----------------------< create_VEP_rows >-----------------------
15972  ---------------------------------------------------------------
15973  --
15974  procedure create_VEP_rows
15975    (
15976          p_validate                       in  number     default 0
15977         ,p_copy_entity_txn_id             in  number
15978         ,p_effective_date                 in  date
15979         ,p_prefix_suffix_text             in  varchar2  default null
15980         ,p_reuse_object_flag              in  varchar2  default null
15981         ,p_target_business_group_id       in  varchar2  default null
15982         ,p_prefix_suffix_cd               in  varchar2  default null
15983    ) is
15984    --
15985    l_ELIGY_PRFL_ID  number;
15986    l_VRBL_RT_PRFL_ID  number;
15987    cursor c_unique_VEP(l_table_alias varchar2) is
15988    select distinct cpe.information1,
15989      cpe.information2,
15990      cpe.information3,
15991      cpe.table_route_id,
15992      cpe.dml_operation,cpe.datetrack_mode
15993    from ben_copy_entity_results cpe,
15994         pqh_table_route tr
15995    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
15996    and   cpe.table_route_id     = tr.table_route_id
15997    -- and   tr.where_clause        = l_BEN_VRBL_RT_ELIG_PRFL_F
15998    and tr.table_alias = l_table_alias
15999    and   cpe.number_of_copies   = 1 -- ADDITION
16000    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
16001    order by information1, information2; --added for bug: 5151945
16002    --
16003    --
16004    cursor c_VEP_min_max_dates(c_table_route_id  number,
16005                 c_information1   number) is
16006    select
16007      min(cpe.information2) min_esd,
16008      max(cpe.information3) min_eed
16009    from ben_copy_entity_results cpe
16010    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
16011    and   cpe.table_route_id     = c_table_route_id
16012    and   cpe.information1       = c_information1 ;
16013    --
16014    cursor c_VEP(c_table_route_id  number,
16015                 c_information1    number,
16016                 c_information2    date,
16017                 c_information3    date )  is
16018    select
16019      cpe.*
16020    from ben_copy_entity_results cpe
16021    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
16022    and   cpe.table_route_id     = c_table_route_id
16023    and   cpe.information1       = c_information1
16024    and   cpe.information2       = c_information2
16025    and   cpe.information3       = c_information3
16026    and rownum = 1 ;
16027    -- Date Track target record
16028    cursor c_find_VEP_in_target(
16029                                 c_effective_start_date    date,
16030                                 c_effective_end_date      date,
16031                                 c_business_group_id       number,
16032                                 c_new_pk_id               number) is
16033    select
16034      VEP.vrbl_rt_elig_prfl_id new_value
16035    from BEN_VRBL_RT_ELIG_PRFL_F VEP
16036    where
16037    VEP.ELIGY_PRFL_ID      = l_ELIGY_PRFL_ID   and
16038    VEP.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID   and
16039    VEP.business_group_id  = c_business_group_id
16040    and   VEP.vrbl_rt_elig_prfl_id  <> c_new_pk_id
16041 --TEMPIK
16042    and c_effective_start_date between effective_start_date
16043                             and effective_end_date ;
16044 --END TEMPIK
16045 /*TEMPIK
16046    and exists ( select null
16047                 from BEN_VRBL_RT_ELIG_PRFL_F VEP1
16048                 where
16049                 VEP1.ELIGY_PRFL_ID      = l_ELIGY_PRFL_ID  and
16050                 VEP1.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
16051                 VEP1.business_group_id  = c_business_group_id
16052                 and   VEP1.effective_start_date <= c_effective_start_date )
16053    and exists ( select null
16054                 from BEN_VRBL_RT_ELIG_PRFL_F VEP2
16055                 where
16056                 VEP2.ELIGY_PRFL_ID      = l_ELIGY_PRFL_ID  and
16057                 VEP2.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
16058                 VEP2.business_group_id  = c_business_group_id
16059                 and   VEP2.effective_end_date >= c_effective_end_date )
16060                 ;
16061 TEMPIK */
16062    --TEMPIK
16063    l_dt_rec_found            boolean ;
16064    --END TEMPIK
16065    --
16066    --UPD START
16067    --
16068    l_update                  boolean      := false ;
16069    l_datetrack_mode          varchar2(80) := hr_api.g_update;
16070    l_process_date            date;
16071    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
16072    --
16073    --UPD END
16074    --
16075    l_current_pk_id           number := null ;
16076    l_prev_pk_id              number := null ;
16077    l_first_rec               boolean := true ;
16078    r_VEP                     c_VEP%rowtype;
16079    l_vrbl_rt_elig_prfl_id             number ;
16080    l_object_version_number   number ;
16081    l_effective_start_date    date ;
16082    l_effective_end_date      date ;
16083    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
16084    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
16085    l_new_value               number(15);
16086    l_object_found_in_target  boolean := false ;
16087    l_min_esd                 date;
16088    l_max_eed                 date;
16089    l_effective_date          date;
16090    --
16091  begin
16092    -- Initialization
16093    l_object_found_in_target := false ;
16094    -- End Initialization
16095    -- Derive the prefix - sufix
16096    if   p_prefix_suffix_cd = 'PREFIX' then
16097      l_prefix  := p_prefix_suffix_text ;
16098    elsif p_prefix_suffix_cd = 'SUFFIX' then
16099      l_suffix   := p_prefix_suffix_text ;
16100    else
16101      l_prefix := null ;
16102      l_suffix  := null ;
16103    end if ;
16104    -- End Prefix Sufix derivation
16105    for r_VEP_unique in c_unique_VEP('VEP') loop
16106 
16107      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
16108         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
16109           r_VEP_unique.information3 >=
16110                  ben_pd_copy_to_ben_one.g_copy_effective_date)
16111         ) then
16112        --
16113        hr_utility.set_location(' r_VEP_unique.table_route_id '||r_VEP_unique.table_route_id,10);
16114        hr_utility.set_location(' r_VEP_unique.information1 '||r_VEP_unique.information1,10);
16115        hr_utility.set_location( 'r_VEP_unique.information2 '||r_VEP_unique.information2,10);
16116        hr_utility.set_location( 'r_VEP_unique.information3 '||r_VEP_unique.information3,10);
16117        -- If reuse objects flag is 'Y' then check for the object in the target business group
16118        -- if found insert the record into PLSql table and exit the loop else try create the
16119        -- object in the target business group
16120        --
16121        l_object_found_in_target := false ;
16122        --
16123        --UPD START
16124        l_update := false;
16125        l_process_date := p_effective_date;
16126        l_dml_operation:= r_VEP_unique.dml_operation ;
16127        --
16128        open c_VEP(r_VEP_unique.table_route_id,
16129                 r_VEP_unique.information1,
16130                 r_VEP_unique.information2,
16131                 r_VEP_unique.information3 ) ;
16132        --
16133        fetch c_VEP into r_VEP ;
16134        --
16135        close c_VEP ;
16136        l_ELIGY_PRFL_ID := get_fk('ELIGY_PRFL_ID', r_VEP.INFORMATION263,r_VEP.dml_operation);
16137        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_VEP.INFORMATION262,r_VEP.dml_operation);
16138 
16139        --
16140        if l_dml_operation = 'UPDATE' then
16141          --
16142                  l_object_found_in_target := TRUE;
16143                  --
16144                  if l_process_date between r_VEP_unique.information2 and r_VEP_unique.information3 then
16145                        l_update := true;
16146                        if r_VEP_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
16147                          or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'VRBL_RT_ELIG_PRFL_ID'
16148                        then
16149                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'VRBL_RT_ELIG_PRFL_ID' ;
16150                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_VEP_unique.information1 ;
16151                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_VEP_unique.information1 ;
16152                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
16153                           BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_VEP_unique.table_route_id;
16154                           --
16155                           -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
16156                           --
16157                           BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
16158                           --
16159                           --BEN_PD_COPY_TO_BEN_ONE.log_data('VEP',l_new_value,l_prefix || r_VEP_unique.name|| l_suffix,'REUSED');
16160                           --
16161                        end if ;
16162                        hr_utility.set_location( 'found record for update',10);
16163                    --
16164                  else
16165                    --
16166                    l_update := false;
16167                    --
16168                  end if;
16169        else
16170          --
16171          --UPD END
16172        --
16173                l_min_esd := null ;
16174                l_max_eed := null ;
16175                open c_VEP_min_max_dates(r_VEP_unique.table_route_id, r_VEP_unique.information1 ) ;
16176                fetch c_VEP_min_max_dates into l_min_esd,l_max_eed ;
16177                --
16178 
16179                if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
16180                     l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
16181                  l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
16182                end if;
16183                l_min_esd := greatest(l_min_esd,r_VEP_unique.information2);
16184                /*open c_VEP(r_VEP_unique.table_route_id,
16185                         r_VEP_unique.information1,
16186                         r_VEP_unique.information2,
16187                         r_VEP_unique.information3 ) ;
16188                --
16189                fetch c_VEP into r_VEP ;
16190                --
16191                close c_VEP ;*/
16192                --
16193                if p_reuse_object_flag = 'Y' then
16194                  if c_VEP_min_max_dates%found then
16195                    -- cursor to find the object
16196                    open c_find_VEP_in_target( l_min_esd,l_max_eed,
16197                                          p_target_business_group_id, nvl(l_vrbl_rt_elig_prfl_id, -999)  ) ;
16198                    fetch c_find_VEP_in_target into l_new_value ;
16199                    if c_find_VEP_in_target%found then
16200                      --TEMPIK
16201                      l_dt_rec_found :=   dt_api.check_min_max_dates
16202                          (p_base_table_name => 'BEN_VRBL_RT_ELIG_PRFL_F',
16203                           p_base_key_column => 'VRBL_RT_ELIG_PRFL_ID',
16204                           p_base_key_value  => l_new_value,
16205                           p_from_date       => l_min_esd,
16206                           p_to_date         => l_max_eed );
16207                      if l_dt_rec_found THEN
16208                      --END TEMPIK             --
16209                                          if r_VEP_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999) or
16210                                                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <>  'VRBL_RT_ELIG_PRFL_ID'  then
16211                                                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'VRBL_RT_ELIG_PRFL_ID' ;
16212                                                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_VEP_unique.information1 ;
16213                                                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := l_new_value ;
16214                                                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
16215                                                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_VEP_unique.table_route_id;
16216                                                 --
16217                                                 -- update_cer_with_target( BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count) , p_copy_entity_txn_id) ;
16218                                                 --
16219                                                 BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
16220                                          end if ;
16221                                          --
16222                                          l_object_found_in_target := true ;
16223                      --TEMPIK
16224                      end if; -- l_dt_rec_found
16225                      --END TEMPIK
16226                    end if;
16227                    close c_find_VEP_in_target ;
16228                  --
16229                  end if;
16230                end if ;
16231                --
16232                close c_VEP_min_max_dates ;
16233        --if not l_object_found_in_target then
16234        end if; --if p_dml_operation
16235        --
16236        if not l_object_found_in_target OR l_update  then
16237          --
16238          l_current_pk_id := r_VEP.information1;
16239          --
16240          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
16241          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
16242          --
16243          if l_current_pk_id =  l_prev_pk_id  then
16244            --
16245            l_first_rec := false ;
16246            --
16247          else
16248            --
16249            l_first_rec := true ;
16250            --
16251          end if ;
16252          --
16253 
16254          l_effective_date := r_VEP.information2;
16255          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
16256               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
16257            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
16258          end if;
16259 
16260          --if l_first_rec then
16261          if l_first_rec and not l_update then
16262            -- Call Create routine.
16263            hr_utility.set_location(' BEN_VRBL_RT_ELIG_PRFL_F CREATE_VRBL_RT_ELIG_PRFL ',20);
16264            BEN_VRBL_RT_ELIG_PRFL_API.CREATE_VRBL_RT_ELIG_PRFL(
16265              --
16266              P_VALIDATE               => false
16267              ,P_EFFECTIVE_DATE        => l_effective_date
16268              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
16269              --
16270              ,P_ELIGY_PRFL_ID      => l_ELIGY_PRFL_ID
16271              ,P_MNDTRY_FLAG      => r_VEP.INFORMATION11
16272              ,P_VEP_ATTRIBUTE1      => r_VEP.INFORMATION111
16273              ,P_VEP_ATTRIBUTE10      => r_VEP.INFORMATION120
16274              ,P_VEP_ATTRIBUTE11      => r_VEP.INFORMATION121
16275              ,P_VEP_ATTRIBUTE12      => r_VEP.INFORMATION122
16276              ,P_VEP_ATTRIBUTE13      => r_VEP.INFORMATION123
16277              ,P_VEP_ATTRIBUTE14      => r_VEP.INFORMATION124
16278              ,P_VEP_ATTRIBUTE15      => r_VEP.INFORMATION125
16279              ,P_VEP_ATTRIBUTE16      => r_VEP.INFORMATION126
16280              ,P_VEP_ATTRIBUTE17      => r_VEP.INFORMATION127
16281              ,P_VEP_ATTRIBUTE18      => r_VEP.INFORMATION128
16282              ,P_VEP_ATTRIBUTE19      => r_VEP.INFORMATION129
16283              ,P_VEP_ATTRIBUTE2      => r_VEP.INFORMATION112
16284              ,P_VEP_ATTRIBUTE20      => r_VEP.INFORMATION130
16285              ,P_VEP_ATTRIBUTE21      => r_VEP.INFORMATION131
16286              ,P_VEP_ATTRIBUTE22      => r_VEP.INFORMATION132
16287              ,P_VEP_ATTRIBUTE23      => r_VEP.INFORMATION133
16288              ,P_VEP_ATTRIBUTE24      => r_VEP.INFORMATION134
16289              ,P_VEP_ATTRIBUTE25      => r_VEP.INFORMATION135
16290              ,P_VEP_ATTRIBUTE26      => r_VEP.INFORMATION136
16291              ,P_VEP_ATTRIBUTE27      => r_VEP.INFORMATION137
16292              ,P_VEP_ATTRIBUTE28      => r_VEP.INFORMATION138
16293              ,P_VEP_ATTRIBUTE29      => r_VEP.INFORMATION139
16294              ,P_VEP_ATTRIBUTE3      => r_VEP.INFORMATION113
16295              ,P_VEP_ATTRIBUTE30      => r_VEP.INFORMATION140
16296              ,P_VEP_ATTRIBUTE4      => r_VEP.INFORMATION114
16297              ,P_VEP_ATTRIBUTE5      => r_VEP.INFORMATION115
16298              ,P_VEP_ATTRIBUTE6      => r_VEP.INFORMATION116
16299              ,P_VEP_ATTRIBUTE7      => r_VEP.INFORMATION117
16300              ,P_VEP_ATTRIBUTE8      => r_VEP.INFORMATION118
16301              ,P_VEP_ATTRIBUTE9      => r_VEP.INFORMATION119
16302              ,P_VEP_ATTRIBUTE_CATEGORY      => r_VEP.INFORMATION110
16303              ,P_VRBL_RT_ELIG_PRFL_ID      => l_vrbl_rt_elig_prfl_id
16304              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
16305              --
16306              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
16307              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
16308              ,P_OBJECT_VERSION_NUMBER =>        l_object_version_number
16309          );
16310          -- insert the table_name,old_pk_id,new_pk_id into a plsql record
16311          -- Update all relevent cer records with new pk_id
16312          hr_utility.set_location('Before plsql table ',222);
16313          hr_utility.set_location('new_value id '||l_vrbl_rt_elig_prfl_id,222);
16314          BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column := 'VRBL_RT_ELIG_PRFL_ID' ;
16315          BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value    := r_VEP.information1 ;
16316          BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value    := l_VRBL_RT_ELIG_PRFL_ID ;
16317          BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type  := 'COPIED';
16318          BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_VEP_unique.table_route_id;
16319          hr_utility.set_location('After plsql table ',222);
16320          --
16321          -- update_cer_with_target( BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count),p_copy_entity_txn_id ) ;
16322          --
16323          BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
16324          --
16325        else
16326          --
16327          -- Call Update routine for the pk_id created in prev run .
16328          -- insert the table_name,old_pk_id,new_pk_id into a plsql record
16329          hr_utility.set_location(' BEN_VRBL_RT_ELIG_PRFL_F UPDATE_VRBL_RT_ELIG_PRFL ',30);
16330          --UPD START
16331            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
16332            --
16333            if l_update then
16334              --
16335              l_datetrack_mode := r_VEP.datetrack_mode ;
16336              --
16337              get_dt_modes(
16338                p_effective_date        => l_process_date,
16339                p_effective_end_date    => r_VEP.information3,
16340                p_effective_start_date  => r_VEP.information2,
16341                p_dml_operation         => r_VEP.dml_operation,
16342                p_datetrack_mode        => l_datetrack_mode );
16343            --    p_update                => l_update
16344              --
16345              l_effective_date := l_process_date;
16346              l_vrbl_rt_elig_prfl_id  := r_VEP.information1;
16347              l_object_version_number := r_VEP.information265;
16348              --
16349            end if;
16350            --
16351            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
16352            --
16353            IF l_update OR l_dml_operation <> 'UPDATE' THEN
16354            --UPD END
16355 
16356                  BEN_VRBL_RT_ELIG_PRFL_API.UPDATE_VRBL_RT_ELIG_PRFL(
16357                      --
16358                      P_VALIDATE               => false
16359                      ,P_EFFECTIVE_DATE        => l_effective_date
16360                      ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
16361                      --
16362                      ,P_ELIGY_PRFL_ID      => l_ELIGY_PRFL_ID
16363                      ,P_MNDTRY_FLAG      => r_VEP.INFORMATION11
16364                      ,P_VEP_ATTRIBUTE1      => r_VEP.INFORMATION111
16365                      ,P_VEP_ATTRIBUTE10      => r_VEP.INFORMATION120
16366                      ,P_VEP_ATTRIBUTE11      => r_VEP.INFORMATION121
16367                      ,P_VEP_ATTRIBUTE12      => r_VEP.INFORMATION122
16368                      ,P_VEP_ATTRIBUTE13      => r_VEP.INFORMATION123
16369                      ,P_VEP_ATTRIBUTE14      => r_VEP.INFORMATION124
16370                      ,P_VEP_ATTRIBUTE15      => r_VEP.INFORMATION125
16371                      ,P_VEP_ATTRIBUTE16      => r_VEP.INFORMATION126
16372                      ,P_VEP_ATTRIBUTE17      => r_VEP.INFORMATION127
16373                      ,P_VEP_ATTRIBUTE18      => r_VEP.INFORMATION128
16374                      ,P_VEP_ATTRIBUTE19      => r_VEP.INFORMATION129
16375                      ,P_VEP_ATTRIBUTE2      => r_VEP.INFORMATION112
16376                      ,P_VEP_ATTRIBUTE20      => r_VEP.INFORMATION130
16377                      ,P_VEP_ATTRIBUTE21      => r_VEP.INFORMATION131
16378                      ,P_VEP_ATTRIBUTE22      => r_VEP.INFORMATION132
16379                      ,P_VEP_ATTRIBUTE23      => r_VEP.INFORMATION133
16380                      ,P_VEP_ATTRIBUTE24      => r_VEP.INFORMATION134
16381                      ,P_VEP_ATTRIBUTE25      => r_VEP.INFORMATION135
16382                      ,P_VEP_ATTRIBUTE26      => r_VEP.INFORMATION136
16383                      ,P_VEP_ATTRIBUTE27      => r_VEP.INFORMATION137
16384                      ,P_VEP_ATTRIBUTE28      => r_VEP.INFORMATION138
16385                      ,P_VEP_ATTRIBUTE29      => r_VEP.INFORMATION139
16386                      ,P_VEP_ATTRIBUTE3      => r_VEP.INFORMATION113
16387                      ,P_VEP_ATTRIBUTE30      => r_VEP.INFORMATION140
16388                      ,P_VEP_ATTRIBUTE4      => r_VEP.INFORMATION114
16389                      ,P_VEP_ATTRIBUTE5      => r_VEP.INFORMATION115
16390                      ,P_VEP_ATTRIBUTE6      => r_VEP.INFORMATION116
16391                      ,P_VEP_ATTRIBUTE7      => r_VEP.INFORMATION117
16392                      ,P_VEP_ATTRIBUTE8      => r_VEP.INFORMATION118
16393                      ,P_VEP_ATTRIBUTE9      => r_VEP.INFORMATION119
16394                      ,P_VEP_ATTRIBUTE_CATEGORY      => r_VEP.INFORMATION110
16395                      ,P_VRBL_RT_ELIG_PRFL_ID      => l_vrbl_rt_elig_prfl_id
16396                      ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
16397                      --
16398                      ,P_EFFECTIVE_START_DATE  => l_effective_start_date
16399                      ,P_EFFECTIVE_END_DATE    => l_effective_end_date
16400                      ,P_OBJECT_VERSION_NUMBER => l_object_version_number
16401                      --,P_DATETRACK_MODE        => hr_api.g_update
16402                      ,P_DATETRACK_MODE        => l_datetrack_mode
16403                    );
16404               end if;  -- l_update
16405            --
16406            -- Delete the row if it is end dated.
16407            --
16408            if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
16409              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
16410              trunc(l_max_eed) = r_VEP.information3) then
16411              --
16412              BEN_VRBL_RT_ELIG_PRFL_API.delete_VRBL_RT_ELIG_PRFL(
16413                 --
16414                 p_validate                        => false
16415                 ,p_vrbl_rt_elig_prfl_id           => l_vrbl_rt_elig_prfl_id
16416                 ,p_vrbl_rt_prfl_id                => l_vrbl_rt_prfl_id
16417                 ,p_effective_start_date           => l_effective_start_date
16418                 ,p_effective_end_date             => l_effective_end_date
16419                 ,p_object_version_number          => l_object_version_number
16420                 ,p_effective_date                 => l_max_eed
16421                 ,p_datetrack_mode                 => hr_api.g_delete
16422                 --
16423                 );
16424                 --
16425            end if;
16426            --
16427          end if;
16428          --
16429          l_prev_pk_id := l_current_pk_id ;
16430          --
16431        end if;
16432        --
16433      end if;
16434      --
16435    end loop;
16436    --
16437 exception when others then
16438   --
16439   BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'VEP',r_vep.information5 );
16440   --
16441 end create_VEP_rows;
16442 
16443 procedure create_rate_rows
16444 (
16445      p_validate                       in  number     default 0
16446     ,p_copy_entity_txn_id             in  number
16447     ,p_effective_date                 in  date
16448     ,p_prefix_suffix_text             in  varchar2  default null
16449     ,p_reuse_object_flag              in  varchar2  default null
16450     ,p_target_business_group_id       in  varchar2  default null
16451     ,p_prefix_suffix_cd               in  varchar2  default null
16452 ) is
16453   begin
16454     --
16455     --dbms_output.put_line(' Start of create_rate_rows ') ;
16456     /* TEMP COMMENT Communication Types
16457     --
16458   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('CTU') then
16459     BEN_PD_COPY_TO_BEN_five.create_CTU_rows
16460     (p_validate                     => p_validate
16461     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16462     ,p_effective_date               => p_effective_date
16463     ,p_prefix_suffix_text           => p_prefix_suffix_text
16464     ,p_reuse_object_flag            => p_reuse_object_flag
16465     ,p_target_business_group_id     => p_target_business_group_id
16466     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16467   end if;
16468     --
16469 
16470     --
16471   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('CTT') then
16472     BEN_PD_COPY_TO_BEN_five.create_CTT_rows
16473     (p_validate                     => p_validate
16474     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16475     ,p_effective_date               => p_effective_date
16476     ,p_prefix_suffix_text           => p_prefix_suffix_text
16477     ,p_reuse_object_flag            => p_reuse_object_flag
16478     ,p_target_business_group_id     => p_target_business_group_id
16479     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16480   end if;
16481     --
16482 
16483     --
16484   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('CMT') then
16485     BEN_PD_COPY_TO_BEN_five.create_CMT_rows
16486     (p_validate                     => p_validate
16487     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16488     ,p_effective_date               => p_effective_date
16489     ,p_prefix_suffix_text           => p_prefix_suffix_text
16490     ,p_reuse_object_flag            => p_reuse_object_flag
16491     ,p_target_business_group_id     => p_target_business_group_id
16492     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16493   end if;
16494     --
16495 
16496     --
16497   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('CMD') then
16498     BEN_PD_COPY_TO_BEN_five.create_CMD_rows
16499     (p_validate                     => p_validate
16500     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16501     ,p_effective_date               => p_effective_date
16502     ,p_prefix_suffix_text           => p_prefix_suffix_text
16503     ,p_reuse_object_flag            => p_reuse_object_flag
16504     ,p_target_business_group_id     => p_target_business_group_id
16505     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16506   end if;
16507     --
16508 */
16509     -- Bug 2695254 Moved to be in CCM,APR and ABR Order
16510     --
16511   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('CCM') then
16512     BEN_PD_COPY_TO_BEN_five.create_CCM_rows
16513     (p_validate                     => p_validate
16514     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16515     ,p_effective_date               => p_effective_date
16516     ,p_prefix_suffix_text           => p_prefix_suffix_text
16517     ,p_reuse_object_flag            => p_reuse_object_flag
16518     ,p_target_business_group_id     => p_target_business_group_id
16519     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16520   end if;
16521     --
16522   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('APR') then
16523     BEN_PD_COPY_TO_BEN_five.create_APR_rows
16524     (p_validate                     => p_validate
16525     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16526     ,p_effective_date               => p_effective_date
16527     ,p_prefix_suffix_text           => p_prefix_suffix_text
16528     ,p_reuse_object_flag            => p_reuse_object_flag
16529     ,p_target_business_group_id     => p_target_business_group_id
16530     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16531   end if;
16532     --
16533     build_abr_hierarchy ( p_copy_entity_txn_id );
16534     --
16535   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('ABR') then
16536     BEN_PD_COPY_TO_BEN_five.create_ABR_rows
16537     (p_validate                     => p_validate
16538     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16539     ,p_effective_date               => p_effective_date
16540     ,p_prefix_suffix_text           => p_prefix_suffix_text
16541     ,p_reuse_object_flag            => p_reuse_object_flag
16542     ,p_target_business_group_id     => p_target_business_group_id
16543     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16544   end if;
16545     --
16546     --
16547   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('EIV') then
16548     BEN_PD_COPY_TO_BEN_five.create_EIV_rows
16549     (p_validate                     => p_validate
16550     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16551     ,p_effective_date               => p_effective_date
16552     ,p_prefix_suffix_text           => p_prefix_suffix_text
16553     ,p_reuse_object_flag            => p_reuse_object_flag
16554     ,p_target_business_group_id     => p_target_business_group_id
16555     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16556   end if;
16557     --
16558     --
16559   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('APF') then
16560     BEN_PD_COPY_TO_BEN_five.create_APF_rows
16561     (p_validate                     => p_validate
16562     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16563     ,p_effective_date               => p_effective_date
16564     ,p_prefix_suffix_text           => p_prefix_suffix_text
16565     ,p_reuse_object_flag            => p_reuse_object_flag
16566     ,p_target_business_group_id     => p_target_business_group_id
16567     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16568   end if;
16569     --
16570     --
16571   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('PSQ') then
16572     BEN_PD_COPY_TO_BEN_five.create_PSQ_rows
16573     (p_validate                     => p_validate
16574     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16575     ,p_effective_date               => p_effective_date
16576     ,p_prefix_suffix_text           => p_prefix_suffix_text
16577     ,p_reuse_object_flag            => p_reuse_object_flag
16578     ,p_target_business_group_id     => p_target_business_group_id
16579     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16580   end if;
16581     --
16582     --
16583   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('ABC') then
16584     BEN_PD_COPY_TO_BEN_five.create_ABC_rows
16585     (p_validate                     => p_validate
16586     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16587     ,p_effective_date               => p_effective_date
16588     ,p_prefix_suffix_text           => p_prefix_suffix_text
16589     ,p_reuse_object_flag            => p_reuse_object_flag
16590     ,p_target_business_group_id     => p_target_business_group_id
16591     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16592   end if;
16593     --
16594 
16595     --
16596   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('MTR') then
16597     BEN_PD_COPY_TO_BEN_five.create_MTR_rows
16598     (p_validate                     => p_validate
16599     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16600     ,p_effective_date               => p_effective_date
16601     ,p_prefix_suffix_text           => p_prefix_suffix_text
16602     ,p_reuse_object_flag            => p_reuse_object_flag
16603     ,p_target_business_group_id     => p_target_business_group_id
16604     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16605   end if;
16606     --
16607 
16608     --
16609   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('APL1') then
16610     BEN_PD_COPY_TO_BEN_five.create_APL1_rows
16611     (p_validate                     => p_validate
16612     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16613     ,p_effective_date               => p_effective_date
16614     ,p_prefix_suffix_text           => p_prefix_suffix_text
16615     ,p_reuse_object_flag            => p_reuse_object_flag
16616     ,p_target_business_group_id     => p_target_business_group_id
16617     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16618   end if;
16619     --
16620     --
16621   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('VPF') then
16622         BEN_PD_COPY_TO_BEN_five.create_VPF_rows
16623         (p_validate                                             => p_validate
16624         ,p_copy_entity_txn_id                   => p_copy_entity_txn_id
16625         ,p_effective_date                               => p_effective_date
16626         ,p_prefix_suffix_text                   => p_prefix_suffix_text
16627         ,p_reuse_object_flag                    => p_reuse_object_flag
16628         ,p_target_business_group_id             => p_target_business_group_id
16629         ,p_prefix_suffix_cd                             => p_prefix_suffix_cd);
16630   end if;
16631         --
16632     --
16633   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('AVR') then
16634     BEN_PD_COPY_TO_BEN_five.create_AVR_rows
16635     (p_validate                     => p_validate
16636     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16637     ,p_effective_date               => p_effective_date
16638     ,p_prefix_suffix_text           => p_prefix_suffix_text
16639     ,p_reuse_object_flag            => p_reuse_object_flag
16640     ,p_target_business_group_id     => p_target_business_group_id
16641     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16642   end if;
16643     --
16644     --
16645     -- Create Partial Month Proration
16646     -- (To be called after creating ABR, APR and CCM)
16647     --
16648   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('PMRPV') then
16649     BEN_PD_COPY_TO_BEN_five.create_PMRPV_rows
16650     (p_validate                     => p_validate
16651     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16652     ,p_effective_date               => p_effective_date
16653     ,p_prefix_suffix_text           => p_prefix_suffix_text
16654     ,p_reuse_object_flag            => p_reuse_object_flag
16655     ,p_target_business_group_id     => p_target_business_group_id
16656     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16657   end if;
16658     --
16659 
16660     --
16661   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('BVR1') then
16662     BEN_PD_COPY_TO_BEN_five.create_BVR1_rows
16663     (p_validate                     => p_validate
16664     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16665     ,p_effective_date               => p_effective_date
16666     ,p_prefix_suffix_text           => p_prefix_suffix_text
16667     ,p_reuse_object_flag            => p_reuse_object_flag
16668     ,p_target_business_group_id     => p_target_business_group_id
16669     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16670   end if;
16671     --
16672 
16673     --
16674   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('BRR') then
16675     BEN_PD_COPY_TO_BEN_five.create_BRR_rows
16676     (p_validate                     => p_validate
16677     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16678     ,p_effective_date               => p_effective_date
16679     ,p_prefix_suffix_text           => p_prefix_suffix_text
16680     ,p_reuse_object_flag            => p_reuse_object_flag
16681     ,p_target_business_group_id     => p_target_business_group_id
16682     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16683   end if;
16684     --
16685 
16686     --
16687   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('APV') then
16688     BEN_PD_COPY_TO_BEN_five.create_APV_rows
16689     (p_validate                     => p_validate
16690     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16691     ,p_effective_date               => p_effective_date
16692     ,p_prefix_suffix_text           => p_prefix_suffix_text
16693     ,p_reuse_object_flag            => p_reuse_object_flag
16694     ,p_target_business_group_id     => p_target_business_group_id
16695     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16696   end if;
16697     --
16698 
16699     --
16700   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('AVA') then
16701     BEN_PD_COPY_TO_BEN_five.create_AVA_rows
16702     (p_validate                     => p_validate
16703     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16704     ,p_effective_date               => p_effective_date
16705     ,p_prefix_suffix_text           => p_prefix_suffix_text
16706     ,p_reuse_object_flag            => p_reuse_object_flag
16707     ,p_target_business_group_id     => p_target_business_group_id
16708     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16709   end if;
16710     --
16711 
16712     --
16713   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('DCR') then
16714     BEN_PD_COPY_TO_BEN_five.create_DCR_rows
16715     (p_validate                     => p_validate
16716     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16717     ,p_effective_date               => p_effective_date
16718     ,p_prefix_suffix_text           => p_prefix_suffix_text
16719     ,p_reuse_object_flag            => p_reuse_object_flag
16720     ,p_target_business_group_id     => p_target_business_group_id
16721     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16722   end if;
16723     --
16724 
16725     --
16726   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('DEC') then
16727     BEN_PD_COPY_TO_BEN_five.create_DEC_rows
16728     (p_validate                     => p_validate
16729     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16730     ,p_effective_date               => p_effective_date
16731     ,p_prefix_suffix_text           => p_prefix_suffix_text
16732     ,p_reuse_object_flag            => p_reuse_object_flag
16733     ,p_target_business_group_id     => p_target_business_group_id
16734     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16735   end if;
16736     --
16737 
16738     --
16739   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('EAC') then
16740     BEN_PD_COPY_TO_BEN_five.create_EAC_rows
16741     (p_validate                     => p_validate
16742     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16743     ,p_effective_date               => p_effective_date
16744     ,p_prefix_suffix_text           => p_prefix_suffix_text
16745     ,p_reuse_object_flag            => p_reuse_object_flag
16746     ,p_target_business_group_id     => p_target_business_group_id
16747     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16748   end if;
16749     --
16750 
16751     --
16752   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('EDC') then
16753     BEN_PD_COPY_TO_BEN_five.create_EDC_rows
16754     (p_validate                     => p_validate
16755     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16756     ,p_effective_date               => p_effective_date
16757     ,p_prefix_suffix_text           => p_prefix_suffix_text
16758     ,p_reuse_object_flag            => p_reuse_object_flag
16759     ,p_target_business_group_id     => p_target_business_group_id
16760     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16761   end if;
16762     --
16763 
16764     --
16765   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('EMC') then
16766     BEN_PD_COPY_TO_BEN_five.create_EMC_rows
16767     (p_validate                     => p_validate
16768     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16769     ,p_effective_date               => p_effective_date
16770     ,p_prefix_suffix_text           => p_prefix_suffix_text
16771     ,p_reuse_object_flag            => p_reuse_object_flag
16772     ,p_target_business_group_id     => p_target_business_group_id
16773     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16774   end if;
16775     --
16776 
16777     --
16778   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('EMS') then
16779     BEN_PD_COPY_TO_BEN_five.create_EMS_rows
16780     (p_validate                     => p_validate
16781     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16782     ,p_effective_date               => p_effective_date
16783     ,p_prefix_suffix_text           => p_prefix_suffix_text
16784     ,p_reuse_object_flag            => p_reuse_object_flag
16785     ,p_target_business_group_id     => p_target_business_group_id
16786     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16787   end if;
16788     --
16789 
16790     --
16791   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('EPL') then
16792     BEN_PD_COPY_TO_BEN_five.create_EPL_rows
16793     (p_validate                     => p_validate
16794     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16795     ,p_effective_date               => p_effective_date
16796     ,p_prefix_suffix_text           => p_prefix_suffix_text
16797     ,p_reuse_object_flag            => p_reuse_object_flag
16798     ,p_target_business_group_id     => p_target_business_group_id
16799     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16800   end if;
16801     --
16802     --
16803   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('ESC') then
16804     BEN_PD_COPY_TO_BEN_five.create_ESC_rows
16805     (p_validate                     => p_validate
16806     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16807     ,p_effective_date               => p_effective_date
16808     ,p_prefix_suffix_text           => p_prefix_suffix_text
16809     ,p_reuse_object_flag            => p_reuse_object_flag
16810     ,p_target_business_group_id     => p_target_business_group_id
16811     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16812   end if;
16813 
16814   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('VEP') then
16815         BEN_PD_COPY_TO_BEN_five.create_VEP_rows
16816         (p_validate                 => p_validate
16817         ,p_copy_entity_txn_id       => p_copy_entity_txn_id
16818         ,p_effective_date           => p_effective_date
16819         ,p_prefix_suffix_text       => p_prefix_suffix_text
16820         ,p_reuse_object_flag        => p_reuse_object_flag
16821         ,p_target_business_group_id => p_target_business_group_id
16822         ,p_prefix_suffix_cd         => p_prefix_suffix_cd);
16823   end if;
16824   --
16825   --dbms_output.put_line('End of create_rate_rows ');
16826   --
16827 
16828  --
16829  -- Foll. Criteria to be copied only in Create Plan Wizard flow
16830  --
16831  if BEN_PD_COPY_TO_BEN_ONE.g_transaction_category = 'BEN_PDCRWZ' then
16832 
16833     --
16834   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('ABP') then
16835     BEN_PD_COPY_TO_BEN_five.create_ABP_rows
16836     (p_validate                     => p_validate
16837     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16838     ,p_effective_date               => p_effective_date
16839     ,p_prefix_suffix_text           => p_prefix_suffix_text
16840     ,p_reuse_object_flag            => p_reuse_object_flag
16841     ,p_target_business_group_id     => p_target_business_group_id
16842     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16843   end if;
16844     --
16845     --
16846   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('BPR1') then
16847     BEN_PD_COPY_TO_BEN_five.create_BPR_rows
16848     (p_validate                     => p_validate
16849     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16850     ,p_effective_date               => p_effective_date
16851     ,p_prefix_suffix_text           => p_prefix_suffix_text
16852     ,p_reuse_object_flag            => p_reuse_object_flag
16853     ,p_target_business_group_id     => p_target_business_group_id
16854     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16855   end if;
16856     --
16857     --
16858   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('DPC') then
16859     BEN_PD_COPY_TO_BEN_five.create_DPC_rows
16860     (p_validate                     => p_validate
16861     ,p_copy_entity_txn_id           => p_copy_entity_txn_id
16862     ,p_effective_date               => p_effective_date
16863     ,p_prefix_suffix_text           => p_prefix_suffix_text
16864     ,p_reuse_object_flag            => p_reuse_object_flag
16865     ,p_target_business_group_id     => p_target_business_group_id
16866     ,p_prefix_suffix_cd             => p_prefix_suffix_cd);
16867   end if;
16868     --
16869  end if;
16870 end;
16871  --
16872 end BEN_PD_COPY_TO_BEN_five;