DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_PD_COPY_TO_BEN_THREE

Source


1 Package BODY BEN_PD_COPY_TO_BEN_three as
2 /* $Header: bepdccp3.pkb 120.1 2006/04/10 05:38:59 gsehgal noship $ */
3 --
4 --UPD Changes New procedure for getting the dtmodes
5 --
6 procedure get_dt_modes(p_effective_date       in date,
7                        p_effective_end_date   in date,
8                        p_effective_start_date in date,
9                        p_dml_operation        in varchar2,
10                        p_datetrack_mode       in out nocopy varchar2
11           --             p_update                  out nocopy boolean
12                       ) is
13   l_update            boolean := true ;
14   l_datetrack_mode    varchar2(80) := p_datetrack_mode ;
15 begin
16   --
17   hr_utility.set_location('Intering get_dt_modes p_dt_mode '||l_datetrack_mode,10);
18   hr_utility.set_location('p_effective_start_date '||p_effective_start_date,10);
19   hr_utility.set_location('p_effective_end_date '||p_effective_end_date,10);
20   hr_utility.set_location('p_effective_date '||p_effective_date,10);
21   --
22   if p_effective_end_date <> hr_api.g_eot then
23     --
24     if p_dml_operation = 'INSERT' then
25       --
26       l_datetrack_mode := hr_api.g_update;
27       l_update  := true;
28       --
29     elsif l_datetrack_mode in ('CORRECTION') then
30       --
31       l_datetrack_mode := hr_api.g_correction ;
32       l_update := true;
33       --
34     elsif l_datetrack_mode in ('UPDATE_OVERRIDE','UPDATE' ) then
35       --
36       if p_effective_date = p_effective_start_date then
37         l_datetrack_mode := hr_api.g_correction ;
38         l_update := true;
39       else
40         --
41         if l_datetrack_mode in ('UPDATE_OVERRIDE') then
42          --
43          l_datetrack_mode := hr_api.g_update_override ;
44          l_update := false ;
45          --
46         elsif l_datetrack_mode in ('UPDATE') then
47          --
48          l_datetrack_mode := hr_api.g_update;
49          --
50         end if;
51         --
52       end if;
53       --
54     elsif l_datetrack_mode in ('UPDATE_CHANGE_INSERT') then
55       --
56       if p_effective_date = p_effective_start_date then
57         l_datetrack_mode := hr_api.g_correction ;
58         l_update := true;
59       else
60         l_datetrack_mode := hr_api.g_update_change_insert ;
61         l_update := true;
62       end if;
63       --
64     else
65       --
66       l_datetrack_mode := hr_api.g_update;
67       l_update  := false;
68       --
69     end if;
70     --
71   else
72     --
73     if p_dml_operation = 'INSERT' then
74       --
75       l_datetrack_mode := hr_api.g_update;
76       l_update  := false;
77       --
78     elsif l_datetrack_mode in ('CORRECTION') then
79       --
80       l_datetrack_mode := hr_api.g_correction ;
81       l_update := false;
82       --
83     elsif l_datetrack_mode in ('UPDATE_OVERRIDE','UPDATE' ) then
84       --
85       if p_effective_date = p_effective_start_date then
86         l_datetrack_mode := hr_api.g_correction ;
87         l_update := true;
88       else
89         l_datetrack_mode := hr_api.g_update ;
90         l_update := false ;
91       end if;
92       --
93     elsif l_datetrack_mode in ('UPDATE_CHANGE_INSERT') then
94       --
95       if p_effective_date = p_effective_start_date then
96         l_datetrack_mode := hr_api.g_correction ;
97         l_update := false;
98       else
99         l_datetrack_mode := hr_api.g_update ;
100         l_update := false;
101       end if;
102       --
103     else
104       --
105       l_datetrack_mode := hr_api.g_update;
106       l_update  := false;
107       --
108     end if;
109     --
110   end if ;
111   --
112   p_datetrack_mode := l_datetrack_mode ;
113  --  p_update  := l_update ;
114   --
115   hr_utility.set_location('Leaving get_dt_modes p_dt_mode '||p_datetrack_mode,10);
116   --
117 end get_dt_modes ;
118 --
119 function get_fk(p_col_name varchar2,
120                 p_old_val number,
121                 p_dml_operation varchar2 default null) return number is
122      l_counter number;
123      l_ret_id  number := null;
124    begin
125      --
126      /*
127      if p_dml_operation = 'UPDATE' then
128        --
129        l_ret_id := p_old_val ;
130        --
131      else
132      */
133        --
134         l_counter := nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl.LAST, 0);
135         if l_counter > 0  and p_old_val is not null then
136            for i in 1..l_counter loop
137                if BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(i).pk_id_column = p_col_name and
138                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(i).old_value    = p_old_val
139                then
140                   l_ret_id := BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(i).new_value;
141                   exit;
142                end if;
143            end loop;
144         end if;
145         --
146      /*
147      end if;
148      */
149      return l_ret_id;
150      --
151    end;
152    --
153    -- Start Log additions
154    --
155    -- NOMAPPING
156    procedure log_nomapping_data(p_parent_table_alias       in varchar2
157                      ,p_parent_pk_id                       in number
158                      ,p_copy_entity_txn_id                 in number
159                      ,p_child_table_alias                  in varchar2
160                      ,p_child_data                         in varchar2) is
161    --
162    cursor c_display_name(p_table_alias varchar2) is
163      select display_name,table_route_id
164      from pqh_table_route
165      where table_alias= p_table_alias;
166    --
167    cursor c_parent_data(p_parent_pk_id number,
168                         p_copy_entity_txn_id number,
169                         p_table_route_id number) is
170      select information5
171      from ben_copy_entity_results
172      where table_route_id = p_table_route_id
173      and copy_entity_txn_id = p_copy_entity_txn_id
174      and information1 = p_parent_pk_id;
175 
176    l_parent_data c_parent_data%rowtype;
177    --
178    begin
179      --
180      open c_display_name(p_parent_table_alias);
181      fetch c_display_name into g_parent_display_name,g_parent_table_route_id;
182      close c_display_name;
183      --
184      open c_display_name(p_child_table_alias);
185      fetch c_display_name into g_child_display_name,g_child_table_route_id;
186      close c_display_name;
187      --
188      open c_parent_data(p_parent_pk_id
189                         ,p_copy_entity_txn_id
190                         ,g_parent_table_route_id);
191      fetch c_parent_data into l_parent_data;
192      close c_parent_data;
193      --
194 
195      hr_utility.set_location('Entering log_nomapping_data',5);
196      -- get All capitals from p_parent_table_alias, p_child_table_alias
197      /*l_text := 'VARIABLE RATE ROFILE - ' || 'Mediacal Variable Rate' || ' - ' ||
198                'JOB CRITERIA - ' || 'My Job' || ' - Not copied as mapping is not done'; */
199      --
200      g_not_copied_tbl(g_not_copied_tbl_count).text :=
201            '<B>' || g_parent_display_name ||'</B> - '||l_parent_data.information5 ||' : <B>'||g_child_display_name ||'</B> - '||p_child_data ;
202      --
203      g_not_copied_tbl_count    := g_not_copied_tbl_count + 1;
204      hr_utility.set_location('g_not_copied_tbl 1 '||g_parent_display_name,5);
205      hr_utility.set_location('g_not_copied_tbl 2 '||l_parent_data.information5,5);
206      hr_utility.set_location('g_not_copied_tbl 3 '||g_child_display_name,5);
207      hr_utility.set_location('Leaving log_nomapping_data',5);
208    end log_nomapping_data ;
209    --
210 
211    --
212    -- Private procedure to update the cer with target details
213    --
214    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
215    begin
216      hr_utility.set_location('Inside update_cer_with_target ',233);
217          update ben_copy_entity_results
218            set information9     = c_pk_rec.copy_reuse_type||'-'||c_pk_rec.new_value
219            where copy_entity_txn_id = p_copy_entity_txn_id
220            and   table_route_id     = c_pk_rec.table_route_id
221            and   information1       = c_pk_rec.old_value ;
222    end update_cer_with_target ;
223    --
224 
225    --
226    ---------------------------------------------------------------
227    ----------------------< create_JRT_rows >-----------------------
228    ---------------------------------------------------------------
229    --
230    procedure create_JRT_rows
231    (
232          p_validate                       in  number     default 0
233         ,p_copy_entity_txn_id             in  number
234         ,p_effective_date                 in  date
235         ,p_prefix_suffix_text             in  varchar2  default null
236         ,p_reuse_object_flag              in  varchar2  default null
237         ,p_target_business_group_id       in  varchar2  default null
238         ,p_prefix_suffix_cd               in  varchar2  default null
239    ) is
240    --
241    l_JOB_ID  number;
242    l_VRBL_RT_PRFL_ID  number;
243    l_EXCLD_FLAG       varchar2(100);
244    l_ORDR_NUM         number;
245    --
246    cursor c_unique_JRT(l_table_alias varchar2) is
247    select distinct cpe.information1,
248      cpe.information2,
249      cpe.information3,
250      cpe.table_route_id
251    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
252         pqh_table_route tr
253    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
254    and   cpe.table_route_id     = tr.table_route_id
255    -- and   tr.where_clause        = l_BEN_JOB_RT_F
256    and tr.table_alias = l_table_alias
257    and   cpe.number_of_copies   = 1 -- ADDITION
258    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
259    order by information1, information2; --added for bug: 5151945
260    --
261    --
262    cursor c_JRT_min_max_dates(c_table_route_id  number,
263                 c_information1   Number) is
264    select
265      min(cpe.information2) min_esd,
266      max(cpe.information3) min_eed
267    from ben_copy_entity_results cpe
268    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
269    and   cpe.table_route_id     = c_table_route_id
270    and   cpe.information1       = c_information1 ;
271    --
272    cursor c_JRT(c_table_route_id  number,
273                 c_information1   Number,
274                 c_information2   Date,
275                 c_information3   Date)  is
276    select
277      cpe.*
278    from ben_copy_entity_results cpe
279    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
280    and   cpe.table_route_id     = c_table_route_id
281    and   cpe.information1       = c_information1
282    and   cpe.information2       = c_information2
283    and   cpe.information3       = c_information3
284    and rownum = 1 ;
285    -- Date Track target record
286    cursor c_find_JRT_in_target(
287                                 c_effective_start_date    date,
288                                 c_effective_end_date      date,
289                                 c_business_group_id       number,
290                                 c_new_pk_id               number) is
291    select
292      JRT.job_rt_id new_value
293    from BEN_JOB_RT_F JRT
294    where
295    JRT.JOB_ID     = l_JOB_ID  and
296    JRT.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
297    JRT.ORDR_NUM           = l_ORDR_NUM and
298    JRT.business_group_id  = c_business_group_id
299    and   JRT.job_rt_id  <> c_new_pk_id
300 --TEMPIK
301    and c_effective_start_date between effective_start_date
302                             and effective_end_date ;
303 --END TEMPIK
304 /*TEMPIK
305    and exists ( select null
306                 from BEN_JOB_RT_F JRT1
307                 where
308                 JRT1.JOB_ID     = l_JOB_ID  and
309                 JRT1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
310                 JRT1.ORDR_NUM           = l_ORDR_NUM and
311                 JRT1.business_group_id  = c_business_group_id
312                 and   JRT1.effective_start_date <= c_effective_start_date )
313    and exists ( select null
314                 from BEN_JOB_RT_F JRT2
315                 where
316                 JRT2.JOB_ID     = l_JOB_ID  and
317                 JRT2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
318                 JRT2.ORDR_NUM           = l_ORDR_NUM and
319                 JRT2.business_group_id  = c_business_group_id
320                 and   JRT2.effective_end_date >= c_effective_end_date )
321                 ;
322 TEMPIK */
323    --TEMPIK
324    l_dt_rec_found            boolean ;
325    --END TEMPIK
326    --
327    l_current_pk_id           number := null ;
328    --UPD START
329    --
330    l_update                  boolean      := false ;
331    l_datetrack_mode          varchar2(80) := hr_api.g_update;
332    l_process_date            date;
333    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
334    --
335    --UPD END
336    l_prev_pk_id              number := null ;
337    l_first_rec               boolean := true ;
338    r_JRT                     c_JRT%rowtype;
339    l_job_rt_id             number ;
340    l_object_version_number   number ;
341    l_effective_start_date    date ;
342    l_effective_end_date      date ;
343    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
344    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
345    l_new_value               number(15);
346    l_object_found_in_target  boolean := false ;
347    l_min_esd                 date;
348    l_max_eed                 date;
349    l_effective_date          date;
350    --
351  begin
352    -- Initialization
353    l_object_found_in_target := false ;
354    -- End Initialization
355    -- Derive the prefix - sufix
356    if   p_prefix_suffix_cd = 'PREFIX' then
357      l_prefix  := p_prefix_suffix_text ;
358    elsif p_prefix_suffix_cd = 'SUFFIX' then
359      l_suffix   := p_prefix_suffix_text ;
360    else
361      l_prefix := null ;
362      l_suffix  := null ;
363    end if ;
364    -- End Prefix Sufix derivation
365    for r_JRT_unique in c_unique_JRT('JRT') loop
366 
367      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
368         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
369          r_JRT_unique.information3 >=
370                  ben_pd_copy_to_ben_one.g_copy_effective_date)
371         ) then
372        --
373        hr_utility.set_location(' r_JRT_unique.table_route_id '||r_JRT_unique.table_route_id,10);
374        hr_utility.set_location(' r_JRT_unique.information1 '||r_JRT_unique.information1,10);
375        hr_utility.set_location( 'r_JRT_unique.information2 '||r_JRT_unique.information2,10);
376        hr_utility.set_location( 'r_JRT_unique.information3 '||r_JRT_unique.information3,10);
377        -- If reuse objects flag is 'Y' then check for the object in the target business group
378        -- if found insert the record into PLSql table and exit the loop else try create the
379        -- object in the target business group
380        --
381        l_object_found_in_target := false ;
382        l_min_esd := null ;
383        l_max_eed := null ;
384        open c_JRT_min_max_dates(r_JRT_unique.table_route_id, r_JRT_unique.information1 ) ;
385        fetch c_JRT_min_max_dates into l_min_esd,l_max_eed ;
386        --
387 
388        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
389             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
390          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
391        end if;
392 
393        l_min_esd := greatest(l_min_esd,r_JRT_unique.information2);
394        open c_JRT(r_JRT_unique.table_route_id,
395                 r_JRT_unique.information1,
396                 r_JRT_unique.information2,
397                 r_JRT_unique.information3 ) ;
398        --
399        fetch c_JRT into r_JRT ;
400        --
401        close c_JRT ;
402        --
403        --l_JOB_ID := get_fk('JOB_ID', r_JRT.information176);
404        --
405        if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
406          l_JOB_ID := r_JRT.information176;
407          --
408          if l_JOB_ID is null then
409             --
410             log_nomapping_data(p_parent_table_alias =>'VPF'
411                      ,p_parent_pk_id         => r_JRT.information262
412                      ,p_copy_entity_txn_id   => p_copy_entity_txn_id
413                      ,p_child_table_alias    => 'JRT'
414                      ,p_child_data           => r_JRT.information173 );
415 
416             --
417          end if;
418          --
419        else
420          l_JOB_ID := r_JRT.information174;
421        end if;
422        --
423        l_update := false;
424        l_process_date := p_effective_date;
425        l_dml_operation:= r_JRT_unique.dml_operation ;
426        --
427        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_JRT.INFORMATION262,l_dml_operation);
428        l_ORDR_NUM         := r_JRT.information257;
429        l_EXCLD_FLAG      := r_JRT.information11;
430        --
431        if l_JOB_ID is null then
432          close c_JRT_min_max_dates;
433        else
434        if l_dml_operation = 'UPDATE' then
435          --
436          l_object_found_in_target := TRUE;
437          --
438          if l_process_date between r_JRT_unique.information2 and r_JRT_unique.information3 then
439                l_update := true;
440                if r_JRT_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
441                   nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <>  'JOB_RT_ID'  then
442                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'JOB_RT_ID' ;
443                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_JRT_unique.information1 ;
444                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_JRT_unique.information1 ;
445                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
446                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_JRT_unique.table_route_id;
447                   --
448                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
449                   --
450                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
451                   --
452                   -- log_data('JRT',l_new_value,l_prefix || r_JRT_unique.name|| l_suffix,'REUSED');
453                   --
454                end if ;
455                hr_utility.set_location( 'found record for update',10);
456            --
457          else
458            --
459            l_update := false;
460            --
461          end if;
462        else
463          --
464          --UPD END
465          if p_reuse_object_flag = 'Y' then
466            if c_JRT_min_max_dates%found then
467               -- cursor to find the object
468               open c_find_JRT_in_target( l_min_esd,l_max_eed,
469                                     p_target_business_group_id, nvl(l_job_rt_id, -999)  ) ;
470               fetch c_find_JRT_in_target into l_new_value ;
471               if c_find_JRT_in_target%found then
472                 --
473              --TEMPIK
474              l_dt_rec_found :=   dt_api.check_min_max_dates
475                  (p_base_table_name => 'BEN_JOB_RT_F',
476                   p_base_key_column => 'JOB_RT_ID',
477                   p_base_key_value  => l_new_value,
478                   p_from_date       => l_min_esd,
479                   p_to_date         => l_max_eed );
480              if l_dt_rec_found THEN
481              --END TEMPIK
482                 if r_JRT_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
483                    nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'JOB_RT_ID'  then
484                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'JOB_RT_ID' ;
485                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_JRT_unique.information1 ;
486                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
487                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
488                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_JRT_unique.table_route_id;
489                    --
490                    -- 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) ;
491                    --
492                    BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
493                 end if ;
494                 --
495                 l_object_found_in_target := true ;
496              --TEMPIK
497              end if; -- l_dt_rec_found
498              --END TEMPIK
499               end if;
500               close c_find_JRT_in_target ;
501               --
502            end if;
503          end if ;
504          --
505          close c_JRT_min_max_dates ;
506          end if;
507          if not l_object_found_in_target OR l_update   then
508            --
509            l_current_pk_id := r_JRT.information1;
510            --
511            hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
512            hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
513            --
514            if l_current_pk_id =  l_prev_pk_id  then
515              --
516              l_first_rec := false ;
517              --
518            else
519              --
520              l_first_rec := true ;
521              --
522            end if ;
523            --
524 
525            l_effective_date := r_JRT.information2;
526            if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
527                 l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
528                 l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
529            end if;
530 
531            if l_first_rec and not l_update then
532              -- Call Create routine.
533              hr_utility.set_location(' BEN_JOB_RT_F CREATE_JOB_RT ',20);
534              BEN_JOB_RT_API.CREATE_JOB_RT(
535                 --
536                 P_VALIDATE               => false
537                 ,P_EFFECTIVE_DATE        => l_effective_date
538                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
539                 --
540                 ,P_EXCLD_FLAG           => r_JRT.information11
541                 ,P_JOB_ID               => l_JOB_ID
542                 ,P_JOB_RT_ID            => l_job_rt_id
543                 ,P_JRT_ATTRIBUTE1       => r_JRT.INFORMATION111
544                 ,P_JRT_ATTRIBUTE10      => r_JRT.INFORMATION120
545                 ,P_JRT_ATTRIBUTE11      => r_JRT.INFORMATION121
546                 ,P_JRT_ATTRIBUTE12      => r_JRT.INFORMATION122
547                 ,P_JRT_ATTRIBUTE13      => r_JRT.INFORMATION123
548                 ,P_JRT_ATTRIBUTE14      => r_JRT.INFORMATION124
549                 ,P_JRT_ATTRIBUTE15      => r_JRT.INFORMATION125
550                 ,P_JRT_ATTRIBUTE16      => r_JRT.INFORMATION126
551                 ,P_JRT_ATTRIBUTE17      => r_JRT.INFORMATION127
552                 ,P_JRT_ATTRIBUTE18      => r_JRT.INFORMATION128
553                 ,P_JRT_ATTRIBUTE19      => r_JRT.INFORMATION129
554                 ,P_JRT_ATTRIBUTE2       => r_JRT.INFORMATION112
555                 ,P_JRT_ATTRIBUTE20      => r_JRT.INFORMATION130
556                 ,P_JRT_ATTRIBUTE21      => r_JRT.INFORMATION131
557                 ,P_JRT_ATTRIBUTE22      => r_JRT.INFORMATION132
558                 ,P_JRT_ATTRIBUTE23      => r_JRT.INFORMATION133
559                 ,P_JRT_ATTRIBUTE24      => r_JRT.INFORMATION134
560                 ,P_JRT_ATTRIBUTE25      => r_JRT.INFORMATION135
561                 ,P_JRT_ATTRIBUTE26      => r_JRT.INFORMATION136
562                 ,P_JRT_ATTRIBUTE27      => r_JRT.INFORMATION137
563                 ,P_JRT_ATTRIBUTE28      => r_JRT.INFORMATION138
564                 ,P_JRT_ATTRIBUTE29      => r_JRT.INFORMATION139
565                 ,P_JRT_ATTRIBUTE3       => r_JRT.INFORMATION113
566                 ,P_JRT_ATTRIBUTE30      => r_JRT.INFORMATION140
567                 ,P_JRT_ATTRIBUTE4       => r_JRT.INFORMATION114
568                 ,P_JRT_ATTRIBUTE5       => r_JRT.INFORMATION115
569                 ,P_JRT_ATTRIBUTE6       => r_JRT.INFORMATION116
570                 ,P_JRT_ATTRIBUTE7       => r_JRT.INFORMATION117
571                 ,P_JRT_ATTRIBUTE8       => r_JRT.INFORMATION118
572                 ,P_JRT_ATTRIBUTE9       => r_JRT.INFORMATION119
573                 ,P_JRT_ATTRIBUTE_CATEGORY      => r_JRT.INFORMATION110
574                 ,P_ORDR_NUM      => r_JRT.INFORMATION257
575                 ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
576                 --
577                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
578                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
579                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
580              );
581              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
582              -- Update all relevent cer records with new pk_id
583              hr_utility.set_location('Before plsql table ',222);
584              hr_utility.set_location('new_value id '||l_job_rt_id,222);
585              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'JOB_RT_ID' ;
586              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_JRT.information1 ;
587              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_JOB_RT_ID ;
588              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
589              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_JRT_unique.table_route_id;
590              hr_utility.set_location('After plsql table ',222);
591              --
592              -- 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 ) ;
593              --
594              BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
595              --
596            else
597              --
598              -- Call Update routine for the pk_id created in prev run .
599              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
600            --UPD START
601            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
602            --
603            if l_update then
604              --
605              l_datetrack_mode := r_JRT.datetrack_mode ;
606              --
607              get_dt_modes(
608                p_effective_date        => l_process_date,
609                p_effective_end_date    => r_JRT.information3,
610                p_effective_start_date  => r_JRT.information2,
611                p_dml_operation         => r_JRT.dml_operation,
612                p_datetrack_mode        => l_datetrack_mode );
613            --    p_update                => l_update
614              --
615              l_effective_date := l_process_date;
616              l_JOB_RT_ID   := r_JRT.information1;
617              l_object_version_number := r_JRT.information265;
618              --
619            end if;
620            --
621            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
622            --
623            IF l_update OR l_dml_operation <> 'UPDATE' THEN
624            --UPD END
625              hr_utility.set_location(' BEN_JOB_RT_F UPDATE_JOB_RT ',30);
626              BEN_JOB_RT_API.UPDATE_JOB_RT(
627                 --
628                 P_VALIDATE                => false
629                 ,P_EFFECTIVE_DATE         => l_effective_date
630                 ,P_BUSINESS_GROUP_ID      => p_target_business_group_id
631                 --
632                 ,P_EXCLD_FLAG             => r_JRT.information11
633                 ,P_JOB_ID                 => l_JOB_ID
634                 ,P_JOB_RT_ID              => l_job_rt_id
635  		,P_JRT_ATTRIBUTE1         => r_JRT.INFORMATION111
636                 ,P_JRT_ATTRIBUTE10        => r_JRT.INFORMATION120
637                 ,P_JRT_ATTRIBUTE11        => r_JRT.INFORMATION121
638                 ,P_JRT_ATTRIBUTE12        => r_JRT.INFORMATION122
639                 ,P_JRT_ATTRIBUTE13        => r_JRT.INFORMATION123
640                 ,P_JRT_ATTRIBUTE14        => r_JRT.INFORMATION124
641                 ,P_JRT_ATTRIBUTE15        => r_JRT.INFORMATION125
642                 ,P_JRT_ATTRIBUTE16        => r_JRT.INFORMATION126
643                 ,P_JRT_ATTRIBUTE17        => r_JRT.INFORMATION127
644                 ,P_JRT_ATTRIBUTE18        => r_JRT.INFORMATION128
645                 ,P_JRT_ATTRIBUTE19        => r_JRT.INFORMATION129
646                 ,P_JRT_ATTRIBUTE2         => r_JRT.INFORMATION112
647                 ,P_JRT_ATTRIBUTE20        => r_JRT.INFORMATION130
648                 ,P_JRT_ATTRIBUTE21        => r_JRT.INFORMATION131
649                 ,P_JRT_ATTRIBUTE22        => r_JRT.INFORMATION132
650                 ,P_JRT_ATTRIBUTE23        => r_JRT.INFORMATION133
651                 ,P_JRT_ATTRIBUTE24        => r_JRT.INFORMATION134
652                 ,P_JRT_ATTRIBUTE25        => r_JRT.INFORMATION135
653                 ,P_JRT_ATTRIBUTE26        => r_JRT.INFORMATION136
654                 ,P_JRT_ATTRIBUTE27        => r_JRT.INFORMATION137
655                 ,P_JRT_ATTRIBUTE28        => r_JRT.INFORMATION138
656                 ,P_JRT_ATTRIBUTE29        => r_JRT.INFORMATION139
657                 ,P_JRT_ATTRIBUTE3         => r_JRT.INFORMATION113
658                 ,P_JRT_ATTRIBUTE30        => r_JRT.INFORMATION140
659                 ,P_JRT_ATTRIBUTE4         => r_JRT.INFORMATION114
660                 ,P_JRT_ATTRIBUTE5         => r_JRT.INFORMATION115
661                 ,P_JRT_ATTRIBUTE6         => r_JRT.INFORMATION116
662                 ,P_JRT_ATTRIBUTE7         => r_JRT.INFORMATION117
663                 ,P_JRT_ATTRIBUTE8         => r_JRT.INFORMATION118
664                 ,P_JRT_ATTRIBUTE9         => r_JRT.INFORMATION119
665                 ,P_JRT_ATTRIBUTE_CATEGORY => r_JRT.INFORMATION110
666                 ,P_ORDR_NUM               => r_JRT.INFORMATION257
667                 ,P_VRBL_RT_PRFL_ID        => l_VRBL_RT_PRFL_ID
668                 --
669                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
670                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
671                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
672                 ,P_DATETRACK_MODE        => l_datetrack_mode
673              );
674              --
675              end if;
676            end if;
677            --
678            -- Delete the row if it is end dated.
679            --
680            if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
681              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
682                 trunc(l_max_eed) = r_JRT.information3) then
683                 --
684                 BEN_JOB_RT_API.delete_JOB_RT(
685                    --
686                    p_validate                       => false
687                    ,p_job_rt_id                   => l_job_rt_id
688                    ,p_effective_start_date           => l_effective_start_date
689                    ,p_effective_end_date             => l_effective_end_date
690                    ,p_object_version_number          => l_object_version_number
691                    ,p_effective_date                 => l_max_eed
692                    ,p_datetrack_mode                 => hr_api.g_delete
693                    --
694                    );
695                    --
696            end if;
697            --
698            l_prev_pk_id := l_current_pk_id ;
699            --
700          end if;
701          --
702        end if;
703        --
704      end if;
705      --
706    end loop;
707    --
708  exception when others then
709     --
710     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'JRT',r_jrt.information5 );
711     --
712  end create_JRT_rows;
713 
714    --
715    ---------------------------------------------------------------
716    ----------------------< create_HSR_rows >-----------------------
717    ---------------------------------------------------------------
718    --
719    procedure create_HSR_rows
720    (
721          p_validate                       in  number     default 0
722         ,p_copy_entity_txn_id             in  number
723         ,p_effective_date                 in  date
724         ,p_prefix_suffix_text             in  varchar2  default null
725         ,p_reuse_object_flag              in  varchar2  default null
726         ,p_target_business_group_id       in  varchar2  default null
727         ,p_prefix_suffix_cd               in  varchar2  default null
728    ) is
729    --
730    l_VRBL_RT_PRFL_ID  number;
731    l_EXCLD_FLAG       varchar2(100);
732    l_ORDR_NUM         number;
733    l_HRLY_SLRD_CD     varchar2(30); -- r_HSR.information12
734    --
735    cursor c_unique_HSR(l_table_alias varchar2) is
736    select distinct cpe.information1,
737      cpe.information2,
738      cpe.information3,
739      cpe.table_route_id
740    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
741         pqh_table_route tr
742    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
743    and   cpe.table_route_id     = tr.table_route_id
744    -- and   tr.where_clause        = l_BEN_HRLY_SLRD_RT_F
745    and tr.table_alias = l_table_alias
746    and   cpe.number_of_copies   = 1 -- ADDITION
747    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
748    order by information1, information2; --added for bug: 5151945
749    --
750    --
751    cursor c_HSR_min_max_dates(c_table_route_id  number,
752                 c_information1   Number) is
753    select
754      min(cpe.information2) min_esd,
755      max(cpe.information3) min_eed
756    from ben_copy_entity_results cpe
757    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
758    and   cpe.table_route_id     = c_table_route_id
759    and   cpe.information1       = c_information1 ;
760    --
761    cursor c_HSR(c_table_route_id  number,
762                 c_information1   Number,
763                 c_information2   Date,
764                 c_information3   Date)  is
765    select
766      cpe.*
767    from ben_copy_entity_results cpe
768    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
769    and   cpe.table_route_id     = c_table_route_id
770    and   cpe.information1       = c_information1
771    and   cpe.information2       = c_information2
772    and   cpe.information3       = c_information3
773    and rownum = 1 ;
774    -- Date Track target record
775    cursor c_find_HSR_in_target(
776                                 c_effective_start_date    date,
777                                 c_effective_end_date      date,
778                                 c_business_group_id       number,
779                                 c_new_pk_id               number) is
780    select
781      HSR.hrly_slrd_rt_id new_value
782    from BEN_HRLY_SLRD_RT_F HSR
783    where
784    HSR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
785    HSR.HRLY_SLRD_CD         = l_HRLY_SLRD_CD and
786    HSR.ORDR_NUM           = l_ORDR_NUM and
787    HSR.business_group_id  = c_business_group_id
788    and   HSR.hrly_slrd_rt_id  <> c_new_pk_id
789 --TEMPIK
790    and c_effective_start_date between effective_start_date
791                             and effective_end_date ;
792 --END TEMPIK
793 /*TEMPIK
794    and exists ( select null
795                 from BEN_HRLY_SLRD_RT_F HSR1
796                 where
797                 HSR1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
798                 HSR1.HRLY_SLRD_CD         = l_HRLY_SLRD_CD and
799                 HSR1.ORDR_NUM           = l_ORDR_NUM and
800                 HSR1.business_group_id  = c_business_group_id
801                 and   HSR1.effective_start_date <= c_effective_start_date )
802    and exists ( select null
803                 from BEN_HRLY_SLRD_RT_F HSR2
804                 where
805                 HSR2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
806                 HSR2.HRLY_SLRD_CD         = l_HRLY_SLRD_CD and
807                 HSR2.ORDR_NUM           = l_ORDR_NUM and
808                 HSR2.business_group_id  = c_business_group_id
809                 and   HSR2.effective_end_date >= c_effective_end_date )
810                 ;
811 TEMPIK */
812    --TEMPIK
813    l_dt_rec_found            boolean ;
814    --END TEMPIK
815    --
816    l_current_pk_id           number := null ;
817    --UPD START
818    --
819    l_update                  boolean      := false ;
820    l_datetrack_mode          varchar2(80) := hr_api.g_update;
821    l_process_date            date;
822    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
823    --
824    --UPD END
825    l_prev_pk_id              number := null ;
826    l_first_rec               boolean := true ;
827    r_HSR                     c_HSR%rowtype;
828    l_hrly_slrd_rt_id             number ;
829    l_object_version_number   number ;
830    l_effective_start_date    date ;
831    l_effective_end_date      date ;
832    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
833    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
834    l_new_value               number(15);
835    l_object_found_in_target  boolean := false ;
836    l_min_esd                 date;
837    l_max_eed                 date;
838    l_effective_date          date;
839    --
840  begin
841    -- Initialization
842    l_object_found_in_target := false ;
843    -- End Initialization
844    -- Derive the prefix - sufix
845    if   p_prefix_suffix_cd = 'PREFIX' then
846      l_prefix  := p_prefix_suffix_text ;
847    elsif p_prefix_suffix_cd = 'SUFFIX' then
848      l_suffix   := p_prefix_suffix_text ;
849    else
850      l_prefix := null ;
851      l_suffix  := null ;
852    end if ;
853    -- End Prefix Sufix derivation
854    for r_HSR_unique in c_unique_HSR('HSR') loop
855 
856      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
857         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
858          r_HSR_unique.information3 >=
859                  ben_pd_copy_to_ben_one.g_copy_effective_date)
860         ) then
861        --
862        hr_utility.set_location(' r_HSR_unique.table_route_id '||r_HSR_unique.table_route_id,10);
863        hr_utility.set_location(' r_HSR_unique.information1 '||r_HSR_unique.information1,10);
864        hr_utility.set_location( 'r_HSR_unique.information2 '||r_HSR_unique.information2,10);
865        hr_utility.set_location( 'r_HSR_unique.information3 '||r_HSR_unique.information3,10);
866        -- If reuse objects flag is 'Y' then check for the object in the target business group
867        -- if found insert the record into PLSql table and exit the loop else try create the
868        -- object in the target business group
869        --
870        l_object_found_in_target := false ;
871        l_min_esd := null ;
872        l_max_eed := null ;
873        open c_HSR_min_max_dates(r_HSR_unique.table_route_id, r_HSR_unique.information1 ) ;
874        fetch c_HSR_min_max_dates into l_min_esd,l_max_eed ;
875        --
876 
877        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
878             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
879          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
880        end if;
881        l_min_esd := greatest(l_min_esd,r_HSR_unique.information2);
882        open c_HSR(r_HSR_unique.table_route_id,
883                 r_HSR_unique.information1,
884                 r_HSR_unique.information2,
885                 r_HSR_unique.information3 ) ;
886        --
887        fetch c_HSR into r_HSR ;
888        --
889        close c_HSR ;
890        --
891        l_dml_operation:= r_HSR_unique.dml_operation ;
892        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_HSR.INFORMATION262,l_dml_operation);
893        l_ORDR_NUM         := r_HSR.INFORMATION257;
894        l_EXCLD_FLAG      := r_HSR.information11;
895        l_HRLY_SLRD_CD    := r_HSR.information12;
896        --UPD START
897        l_update := false;
898        l_process_date := p_effective_date;
899        --
900        if l_dml_operation = 'UPDATE' then
901          --
902          l_object_found_in_target := TRUE;
903          --
904          if l_process_date between r_HSR_unique.information2 and r_HSR_unique.information3 then
905                l_update := true;
906                if r_HSR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
907                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'HRLY_SLRD_RT_ID'
908                then
909                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'HRLY_SLRD_RT_ID' ;
910                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_HSR_unique.information1 ;
911                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_HSR_unique.information1 ;
912                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
913                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_HSR_unique.table_route_id;
914                   --
915                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
916                   --
917                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
918                   --
919                   -- log_data('HSR',l_new_value,l_prefix || r_HSR_unique.name|| l_suffix,'REUSED');
920                   --
921                end if ;
922                hr_utility.set_location( 'found record for update',10);
923            --
924          else
925            --
926            l_update := false;
927            --
928          end if;
929        else
930          --
931          --UPD END
932        if p_reuse_object_flag = 'Y' then
933          if c_HSR_min_max_dates%found then
934            -- cursor to find the object
935            open c_find_HSR_in_target( l_min_esd,l_max_eed,
936                                  p_target_business_group_id, nvl(l_hrly_slrd_rt_id, -999)  ) ;
937            fetch c_find_HSR_in_target into l_new_value ;
938            if c_find_HSR_in_target%found then
939              --
940              --TEMPIK
941              l_dt_rec_found :=   dt_api.check_min_max_dates
942                  (p_base_table_name => 'BEN_HRLY_SLRD_RT_F',
943                   p_base_key_column => 'HRLY_SLRD_RT_ID',
944                   p_base_key_value  => l_new_value,
945                   p_from_date       => l_min_esd,
946                   p_to_date         => l_max_eed );
947              if l_dt_rec_found THEN
948              --END TEMPIK
949              if r_HSR_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
950                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'HRLY_SLRD_RT_ID'  then
951                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'HRLY_SLRD_RT_ID' ;
952                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_HSR_unique.information1 ;
953                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
954                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
955                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_HSR_unique.table_route_id;
956                 --
957                 -- 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) ;
958                 --
959                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
960              end if ;
961              --
962              l_object_found_in_target := true ;
963              --TEMPIK
964              end if; -- l_dt_rec_found
965              --END TEMPIK
966            end if;
967            close c_find_HSR_in_target ;
968          --
969          end if;
970        end if ;
971        --
972        end if;
973        close c_HSR_min_max_dates ;
974        if not l_object_found_in_target OR l_update   then
975          --
976          l_current_pk_id := r_HSR.information1;
977          --
978          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
979          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
980          --
981          if l_current_pk_id =  l_prev_pk_id  then
982            --
983            l_first_rec := false ;
984            --
985          else
986            --
987            l_first_rec := true ;
988            --
989          end if ;
990          --
991 
992          l_effective_date := r_HSR.information2;
993          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
994               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
995            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
996          end if;
997 
998          if l_first_rec and not l_update then
999            -- Call Create routine.
1000            hr_utility.set_location(' BEN_HRLY_SLRD_RT_F CREATE_HRLY_SALARY_RATE ',20);
1001            BEN_HRLY_SALARY_RATE_API.CREATE_HRLY_SALARY_RATE(
1002              --
1003              P_VALIDATE               => false
1004              ,P_EFFECTIVE_DATE        => l_effective_date
1005              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
1006              --
1007              ,P_EXCLD_FLAG      => r_HSR.INFORMATION11
1008              ,P_HRLY_SLRD_CD      => r_HSR.INFORMATION12
1009              ,P_HRLY_SLRD_RT_ID      => l_hrly_slrd_rt_id
1010              ,P_HSR_ATTRIBUTE1      => r_HSR.INFORMATION111
1011              ,P_HSR_ATTRIBUTE10      => r_HSR.INFORMATION120
1012              ,P_HSR_ATTRIBUTE11      => r_HSR.INFORMATION121
1013              ,P_HSR_ATTRIBUTE12      => r_HSR.INFORMATION122
1014              ,P_HSR_ATTRIBUTE13      => r_HSR.INFORMATION123
1015              ,P_HSR_ATTRIBUTE14      => r_HSR.INFORMATION124
1016              ,P_HSR_ATTRIBUTE15      => r_HSR.INFORMATION125
1017              ,P_HSR_ATTRIBUTE16      => r_HSR.INFORMATION126
1018              ,P_HSR_ATTRIBUTE17      => r_HSR.INFORMATION127
1019              ,P_HSR_ATTRIBUTE18      => r_HSR.INFORMATION128
1020              ,P_HSR_ATTRIBUTE19      => r_HSR.INFORMATION129
1021              ,P_HSR_ATTRIBUTE2      => r_HSR.INFORMATION112
1022              ,P_HSR_ATTRIBUTE20      => r_HSR.INFORMATION130
1023              ,P_HSR_ATTRIBUTE21      => r_HSR.INFORMATION131
1024              ,P_HSR_ATTRIBUTE22      => r_HSR.INFORMATION132
1025              ,P_HSR_ATTRIBUTE23      => r_HSR.INFORMATION133
1026              ,P_HSR_ATTRIBUTE24      => r_HSR.INFORMATION134
1027              ,P_HSR_ATTRIBUTE25      => r_HSR.INFORMATION135
1028              ,P_HSR_ATTRIBUTE26      => r_HSR.INFORMATION136
1029              ,P_HSR_ATTRIBUTE27      => r_HSR.INFORMATION137
1030              ,P_HSR_ATTRIBUTE28      => r_HSR.INFORMATION138
1031              ,P_HSR_ATTRIBUTE29      => r_HSR.INFORMATION139
1032              ,P_HSR_ATTRIBUTE3      => r_HSR.INFORMATION113
1033              ,P_HSR_ATTRIBUTE30      => r_HSR.INFORMATION140
1034              ,P_HSR_ATTRIBUTE4      => r_HSR.INFORMATION114
1035              ,P_HSR_ATTRIBUTE5      => r_HSR.INFORMATION115
1036              ,P_HSR_ATTRIBUTE6      => r_HSR.INFORMATION116
1037              ,P_HSR_ATTRIBUTE7      => r_HSR.INFORMATION117
1038              ,P_HSR_ATTRIBUTE8      => r_HSR.INFORMATION118
1039              ,P_HSR_ATTRIBUTE9      => r_HSR.INFORMATION119
1040              ,P_HSR_ATTRIBUTE_CATEGORY      => r_HSR.INFORMATION110
1041              ,P_ORDR_NUM      => r_HSR.INFORMATION257
1042              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
1043              --
1044              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
1045              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
1046              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
1047            );
1048            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
1049            -- Update all relevent cer records with new pk_id
1050            hr_utility.set_location('Before plsql table ',222);
1051            hr_utility.set_location('new_value id '||l_hrly_slrd_rt_id,222);
1052            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'HRLY_SLRD_RT_ID' ;
1053            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_HSR.information1 ;
1054            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_HRLY_SLRD_RT_ID ;
1055            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
1056            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_HSR_unique.table_route_id;
1057            hr_utility.set_location('After plsql table ',222);
1058            --
1059            -- 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 ) ;
1060            --
1061            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
1062            --
1063          else
1064            --
1065            -- Call Update routine for the pk_id created in prev run .
1066            --UPD START
1067            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
1068            --
1069            if l_update then
1070              --
1071              l_datetrack_mode := r_HSR.datetrack_mode ;
1072              --
1073              get_dt_modes(
1074                p_effective_date        => l_process_date,
1075                p_effective_end_date    => r_HSR.information3,
1076                p_effective_start_date  => r_HSR.information2,
1077                p_dml_operation         => r_HSR.dml_operation,
1078                p_datetrack_mode        => l_datetrack_mode );
1079            --    p_update                => l_update
1080              --
1081              l_effective_date := l_process_date;
1082              l_HRLY_SLRD_RT_ID   := r_HSR.information1;
1083              l_object_version_number := r_HSR.information265;
1084              --
1085            end if;
1086            --
1087            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
1088            --
1089            IF l_update OR l_dml_operation <> 'UPDATE' THEN
1090            --UPD END
1091            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
1092            hr_utility.set_location(' BEN_HRLY_SLRD_RT_F UPDATE_HRLY_SALARY_RATE ',30);
1093            BEN_HRLY_SALARY_RATE_API.UPDATE_HRLY_SALARY_RATE(
1094              --
1095              P_VALIDATE               => false
1096              ,P_EFFECTIVE_DATE        => l_effective_date
1097              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
1098              --
1099              ,P_EXCLD_FLAG      => r_HSR.INFORMATION11
1100              ,P_HRLY_SLRD_CD      => r_HSR.INFORMATION12
1101              ,P_HRLY_SLRD_RT_ID      => l_hrly_slrd_rt_id
1102              ,P_HSR_ATTRIBUTE1      => r_HSR.INFORMATION111
1103              ,P_HSR_ATTRIBUTE10      => r_HSR.INFORMATION120
1104              ,P_HSR_ATTRIBUTE11      => r_HSR.INFORMATION121
1105              ,P_HSR_ATTRIBUTE12      => r_HSR.INFORMATION122
1106              ,P_HSR_ATTRIBUTE13      => r_HSR.INFORMATION123
1107              ,P_HSR_ATTRIBUTE14      => r_HSR.INFORMATION124
1108              ,P_HSR_ATTRIBUTE15      => r_HSR.INFORMATION125
1109              ,P_HSR_ATTRIBUTE16      => r_HSR.INFORMATION126
1110              ,P_HSR_ATTRIBUTE17      => r_HSR.INFORMATION127
1111              ,P_HSR_ATTRIBUTE18      => r_HSR.INFORMATION128
1112              ,P_HSR_ATTRIBUTE19      => r_HSR.INFORMATION129
1113              ,P_HSR_ATTRIBUTE2      => r_HSR.INFORMATION112
1114              ,P_HSR_ATTRIBUTE20      => r_HSR.INFORMATION130
1115              ,P_HSR_ATTRIBUTE21      => r_HSR.INFORMATION131
1116              ,P_HSR_ATTRIBUTE22      => r_HSR.INFORMATION132
1117              ,P_HSR_ATTRIBUTE23      => r_HSR.INFORMATION133
1118              ,P_HSR_ATTRIBUTE24      => r_HSR.INFORMATION134
1119              ,P_HSR_ATTRIBUTE25      => r_HSR.INFORMATION135
1120              ,P_HSR_ATTRIBUTE26      => r_HSR.INFORMATION136
1121              ,P_HSR_ATTRIBUTE27      => r_HSR.INFORMATION137
1122              ,P_HSR_ATTRIBUTE28      => r_HSR.INFORMATION138
1123              ,P_HSR_ATTRIBUTE29      => r_HSR.INFORMATION139
1124              ,P_HSR_ATTRIBUTE3      => r_HSR.INFORMATION113
1125              ,P_HSR_ATTRIBUTE30      => r_HSR.INFORMATION140
1126              ,P_HSR_ATTRIBUTE4      => r_HSR.INFORMATION114
1127              ,P_HSR_ATTRIBUTE5      => r_HSR.INFORMATION115
1128              ,P_HSR_ATTRIBUTE6      => r_HSR.INFORMATION116
1129              ,P_HSR_ATTRIBUTE7      => r_HSR.INFORMATION117
1130              ,P_HSR_ATTRIBUTE8      => r_HSR.INFORMATION118
1131              ,P_HSR_ATTRIBUTE9      => r_HSR.INFORMATION119
1132              ,P_HSR_ATTRIBUTE_CATEGORY      => r_HSR.INFORMATION110
1133              ,P_ORDR_NUM      => r_HSR.INFORMATION257
1134              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
1135              --
1136              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
1137              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
1138              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
1139              ,P_DATETRACK_MODE        => l_datetrack_mode
1140            );
1141            --
1142            end if;
1143          end if;
1144          --
1145          -- Delete the row if it is end dated.
1146          --
1147          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
1148              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
1149              trunc(l_max_eed) = r_HSR.information3) then
1150              --
1151              BEN_HRLY_SALARY_RATE_API.delete_HRLY_SALARY_RATE(
1152                 --
1153                 p_validate                       => false
1154                 ,p_hrly_slrd_rt_id                   => l_hrly_slrd_rt_id
1155                 ,p_effective_start_date           => l_effective_start_date
1156                 ,p_effective_end_date             => l_effective_end_date
1157                 ,p_object_version_number          => l_object_version_number
1158                 ,p_effective_date                 => l_max_eed
1159                 ,p_datetrack_mode                 => hr_api.g_delete
1160                 --
1161                 );
1162                 --
1163          end if;
1164          --
1165          l_prev_pk_id := l_current_pk_id ;
1166          --
1167        end if;
1168        --
1169      end if;
1170      --
1171    end loop;
1172    --
1173  exception when others then
1174     --
1175     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'HSR',r_hsr.information5 );
1176     --
1177  end create_HSR_rows;
1178 
1179    --
1180    ---------------------------------------------------------------
1181    ----------------------< create_GRR_rows >-----------------------
1182    ---------------------------------------------------------------
1183    --
1184    procedure create_GRR_rows
1185    (
1186          p_validate                       in  number     default 0
1187         ,p_copy_entity_txn_id             in  number
1188         ,p_effective_date                 in  date
1189         ,p_prefix_suffix_text             in  varchar2  default null
1190         ,p_reuse_object_flag              in  varchar2  default null
1191         ,p_target_business_group_id       in  varchar2  default null
1192         ,p_prefix_suffix_cd               in  varchar2  default null
1193    ) is
1194    --
1195    l_GRADE_ID  number;
1196    l_VRBL_RT_PRFL_ID  number;
1197    l_EXCLD_FLAG       varchar2(100);
1198    l_ORDR_NUM         number;
1199    --
1200    cursor c_unique_GRR(l_table_alias varchar2) is
1201    select distinct cpe.information1,
1202      cpe.information2,
1203      cpe.information3,
1204      cpe.table_route_id
1205    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
1206         pqh_table_route tr
1207    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
1208    and   cpe.table_route_id     = tr.table_route_id
1209    -- and   tr.where_clause        = l_BEN_GRADE_RT_F
1210    and tr.table_alias = l_table_alias
1211    and   cpe.number_of_copies   = 1 -- ADDITION
1212    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
1213    order by information1, information2; --added for bug: 5151945
1214    --
1215    --
1216    cursor c_GRR_min_max_dates(c_table_route_id  number,
1217                 c_information1   Number) is
1218    select
1219      min(cpe.information2) min_esd,
1220      max(cpe.information3) min_eed
1221    from ben_copy_entity_results cpe
1222    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
1223    and   cpe.table_route_id     = c_table_route_id
1224    and   cpe.information1       = c_information1 ;
1225    --
1226    cursor c_GRR(c_table_route_id  number,
1227                 c_information1   number,
1228                 c_information2   date,
1229                 c_information3   date)  is
1230    select
1231      cpe.*
1232    from ben_copy_entity_results cpe
1233    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
1234    and   cpe.table_route_id     = c_table_route_id
1235    and   cpe.information1       = c_information1
1236    and   cpe.information2       = c_information2
1237    and   cpe.information3       = c_information3
1238    and rownum = 1 ;
1239    -- Date Track target record
1240    cursor c_find_GRR_in_target(
1241                                 c_effective_start_date    date,
1242                                 c_effective_end_date      date,
1243                                 c_business_group_id       number,
1244                                 c_new_pk_id               number) is
1245    select
1246      GRR.grade_rt_id new_value
1247    from BEN_GRADE_RT_F GRR
1248    where
1249    GRR.GRADE_ID     = l_GRADE_ID  and
1250    GRR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
1251    GRR.ORDR_NUM           = l_ORDR_NUM and
1252    GRR.business_group_id  = c_business_group_id
1253    and   GRR.grade_rt_id  <> c_new_pk_id
1254 --TEMPIK
1255    and c_effective_start_date between effective_start_date
1256                             and effective_end_date ;
1257 --END TEMPIK
1258 /*TEMPIK
1259    and exists ( select null
1260                 from BEN_GRADE_RT_F GRR1
1261                 where
1262                 GRR1.GRADE_ID     = l_GRADE_ID  and
1263                 GRR1.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
1264                 GRR1.ORDR_NUM           = l_ORDR_NUM and
1265                 GRR1.business_group_id  = c_business_group_id
1266                 and   GRR1.effective_start_date <= c_effective_start_date )
1267    and exists ( select null
1268                 from BEN_GRADE_RT_F GRR2
1269                 where
1270                 GRR2.GRADE_ID     = l_GRADE_ID  and
1271                 GRR2.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
1272                 GRR2.ORDR_NUM           = l_ORDR_NUM and
1273                 GRR2.business_group_id  = c_business_group_id
1274                 and   GRR2.effective_end_date >= c_effective_end_date )
1275                 ;
1276 TEMPIK */
1277    --TEMPIK
1278    l_dt_rec_found            boolean ;
1279    --END TEMPIK
1280    --
1281    l_current_pk_id           number := null ;
1282    --UPD START
1283    --
1284    l_update                  boolean      := false ;
1285    l_datetrack_mode          varchar2(80) := hr_api.g_update;
1286    l_process_date            date;
1287    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
1288    --
1289    --UPD END
1290    l_prev_pk_id              number := null ;
1291    l_first_rec               boolean := true ;
1292    r_GRR                     c_GRR%rowtype;
1293    l_grade_rt_id             number ;
1294    l_object_version_number   number ;
1295    l_effective_start_date    date ;
1296    l_effective_end_date      date ;
1297    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
1298    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
1299    l_new_value               number(15);
1300    l_object_found_in_target  boolean := false ;
1301    l_min_esd                 date;
1302    l_max_eed                 date;
1303    l_effective_date          date;
1304    --
1305  begin
1306    -- Initialization
1307    l_object_found_in_target := false ;
1308    -- End Initialization
1309    -- Derive the prefix - sufix
1310    if   p_prefix_suffix_cd = 'PREFIX' then
1311      l_prefix  := p_prefix_suffix_text ;
1312    elsif p_prefix_suffix_cd = 'SUFFIX' then
1313      l_suffix   := p_prefix_suffix_text ;
1314    else
1315      l_prefix := null ;
1316      l_suffix  := null ;
1317    end if ;
1318    -- End Prefix Sufix derivation
1319    for r_GRR_unique in c_unique_GRR('GRR') loop
1320 
1321      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
1322         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
1323          r_GRR_unique.information3 >=
1324                  ben_pd_copy_to_ben_one.g_copy_effective_date)
1325         ) then
1326        --
1327        hr_utility.set_location(' r_GRR_unique.table_route_id '||r_GRR_unique.table_route_id,10);
1328        hr_utility.set_location(' r_GRR_unique.information1 '||r_GRR_unique.information1,10);
1329        hr_utility.set_location( 'r_GRR_unique.information2 '||r_GRR_unique.information2,10);
1330        hr_utility.set_location( 'r_GRR_unique.information3 '||r_GRR_unique.information3,10);
1331        -- If reuse objects flag is 'Y' then check for the object in the target business group
1332        -- if found insert the record into PLSql table and exit the loop else try create the
1333        -- object in the target business group
1334        --
1335        l_object_found_in_target := false ;
1336        l_min_esd := null ;
1337        l_max_eed := null ;
1338        open c_GRR_min_max_dates(r_GRR_unique.table_route_id, r_GRR_unique.information1 ) ;
1339        fetch c_GRR_min_max_dates into l_min_esd,l_max_eed ;
1340        --
1341 
1342        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
1343             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
1344          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
1345        end if;
1346        l_min_esd := greatest(l_min_esd,r_GRR_unique.information2);
1347        open c_GRR(r_GRR_unique.table_route_id,
1348                 r_GRR_unique.information1,
1349                 r_GRR_unique.information2,
1350                 r_GRR_unique.information3 ) ;
1351        --
1352        fetch c_GRR into r_GRR ;
1353        --
1354        close c_GRR ;
1355        --
1356        if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
1357          l_GRADE_ID := r_GRR.information176;
1358        else
1359          l_GRADE_ID := r_GRR.information174;
1360        end if;
1361        --
1362        l_dml_operation := r_GRR_unique.dml_operation ;
1363        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_GRR.INFORMATION262,l_dml_operation);
1364        l_ORDR_NUM        := r_GRR.INFORMATION260;
1365        l_EXCLD_FLAG      := r_GRR.INFORMATION11;
1366        --
1367        if l_GRADE_ID is null then
1368          close c_GRR_min_max_dates;
1369          --
1370          log_nomapping_data(p_parent_table_alias =>'VPF'
1371                      ,p_parent_pk_id         => r_GRR.information262
1372                      ,p_copy_entity_txn_id   => p_copy_entity_txn_id
1373                      ,p_child_table_alias    => 'GRR'
1374                      ,p_child_data           => r_GRR.information173 );
1375             --
1376        else
1377        --UPD START
1378        l_update := false;
1379        l_process_date := p_effective_date;
1380        l_dml_operation:= r_GRR_unique.dml_operation ;
1381        --
1382        if l_dml_operation = 'UPDATE' then
1383          --
1384          l_object_found_in_target := TRUE;
1385          --
1386          if l_process_date between r_GRR_unique.information2 and r_GRR_unique.information3 then
1387                l_update := true;
1388                if r_GRR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
1389                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'GRADE_RT_ID'
1390                then
1391                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'GRADE_RT_ID' ;
1392                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_GRR_unique.information1 ;
1393                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_GRR_unique.information1 ;
1394                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
1395                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_GRR_unique.table_route_id;
1396                   --
1397                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
1398                   --
1399                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
1400                   --
1401                   --log_data('GRR',l_new_value,l_prefix || r_GRR_unique.name|| l_suffix,'REUSED');
1402                   --
1403                end if ;
1404                hr_utility.set_location( 'found record for update',10);
1405            --
1406          else
1407            --
1408            l_update := false;
1409            --
1410          end if;
1411        else
1412          --
1413          --UPD END
1414          if p_reuse_object_flag = 'Y' then
1415            if c_GRR_min_max_dates%found then
1416               -- cursor to find the object
1417               open c_find_GRR_in_target( l_min_esd,l_max_eed,
1418                                     p_target_business_group_id, nvl(l_grade_rt_id, -999)  ) ;
1419               fetch c_find_GRR_in_target into l_new_value ;
1420               if c_find_GRR_in_target%found then
1421                 --
1422             --TEMPIK
1423              l_dt_rec_found :=   dt_api.check_min_max_dates
1424                  (p_base_table_name => 'BEN_GRADE_RT_F',
1425                   p_base_key_column => 'GRADE_RT_ID',
1426                   p_base_key_value  => l_new_value,
1427                   p_from_date       => l_min_esd,
1428                   p_to_date         => l_max_eed );
1429              if l_dt_rec_found THEN
1430              --END TEMPIK
1431                 if r_GRR_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
1432                    nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'GRADE_RT_ID'  then
1433                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'GRADE_RT_ID' ;
1434                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_GRR_unique.information1 ;
1435                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
1436                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
1437                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_GRR_unique.table_route_id;
1438                    --
1439                    -- 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) ;
1440                    --
1441                    BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
1442                 end if ;
1443                 --
1444                 l_object_found_in_target := true ;
1445              --TEMPIK
1446              end if; -- l_dt_rec_found
1447              --END TEMPIK
1448               end if;
1449               close c_find_GRR_in_target ;
1450            --
1451            end if;
1452          end if ;
1453          --
1454          end if;
1455          close c_GRR_min_max_dates ;
1456          if not l_object_found_in_target OR l_update   then
1457            --
1458            l_current_pk_id := r_GRR.information1;
1459            --
1460            hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
1461            hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
1462            --
1463            if l_current_pk_id =  l_prev_pk_id  then
1464              --
1465              l_first_rec := false ;
1466              --
1467            else
1468              --
1469              l_first_rec := true ;
1470              --
1471            end if ;
1472            --
1473 
1474            l_effective_date := r_GRR.information2;
1475            if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
1476                 l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
1477              l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
1478            end if;
1479 
1480            if l_first_rec and not l_update then
1481              -- Call Create routine.
1482              hr_utility.set_location(' BEN_GRADE_RT_F CREATE_GRADE_RATE ',20);
1483              BEN_GRADE_RATE_API.CREATE_GRADE_RATE(
1484                 --
1485                 P_VALIDATE               => false
1486                 ,P_EFFECTIVE_DATE        => l_effective_date
1487                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
1488                 --
1489              ,P_EXCLD_FLAG      => r_GRR.INFORMATION11
1490              ,P_GRADE_ID      => l_GRADE_ID
1491              ,P_GRADE_RT_ID      => l_grade_rt_id
1492              ,P_GRR_ATTRIBUTE1      => r_GRR.INFORMATION111
1493              ,P_GRR_ATTRIBUTE10      => r_GRR.INFORMATION120
1494              ,P_GRR_ATTRIBUTE11      => r_GRR.INFORMATION121
1495              ,P_GRR_ATTRIBUTE12      => r_GRR.INFORMATION122
1496              ,P_GRR_ATTRIBUTE13      => r_GRR.INFORMATION123
1497              ,P_GRR_ATTRIBUTE14      => r_GRR.INFORMATION124
1498              ,P_GRR_ATTRIBUTE15      => r_GRR.INFORMATION125
1499              ,P_GRR_ATTRIBUTE16      => r_GRR.INFORMATION126
1500              ,P_GRR_ATTRIBUTE17      => r_GRR.INFORMATION127
1501              ,P_GRR_ATTRIBUTE18      => r_GRR.INFORMATION128
1502              ,P_GRR_ATTRIBUTE19      => r_GRR.INFORMATION129
1503              ,P_GRR_ATTRIBUTE2      => r_GRR.INFORMATION112
1504              ,P_GRR_ATTRIBUTE20      => r_GRR.INFORMATION130
1505              ,P_GRR_ATTRIBUTE21      => r_GRR.INFORMATION131
1506              ,P_GRR_ATTRIBUTE22      => r_GRR.INFORMATION132
1507              ,P_GRR_ATTRIBUTE23      => r_GRR.INFORMATION133
1508              ,P_GRR_ATTRIBUTE24      => r_GRR.INFORMATION134
1509              ,P_GRR_ATTRIBUTE25      => r_GRR.INFORMATION135
1510              ,P_GRR_ATTRIBUTE26      => r_GRR.INFORMATION136
1511              ,P_GRR_ATTRIBUTE27      => r_GRR.INFORMATION137
1512              ,P_GRR_ATTRIBUTE28      => r_GRR.INFORMATION138
1513              ,P_GRR_ATTRIBUTE29      => r_GRR.INFORMATION139
1514              ,P_GRR_ATTRIBUTE3      => r_GRR.INFORMATION113
1515              ,P_GRR_ATTRIBUTE30      => r_GRR.INFORMATION140
1516              ,P_GRR_ATTRIBUTE4      => r_GRR.INFORMATION114
1517              ,P_GRR_ATTRIBUTE5      => r_GRR.INFORMATION115
1518              ,P_GRR_ATTRIBUTE6      => r_GRR.INFORMATION116
1519              ,P_GRR_ATTRIBUTE7      => r_GRR.INFORMATION117
1520              ,P_GRR_ATTRIBUTE8      => r_GRR.INFORMATION118
1521              ,P_GRR_ATTRIBUTE9      => r_GRR.INFORMATION119
1522              ,P_GRR_ATTRIBUTE_CATEGORY      => r_GRR.INFORMATION110
1523              ,P_ORDR_NUM      => r_GRR.INFORMATION260
1524              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
1525                 --
1526                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
1527                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
1528                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
1529               );
1530 
1531               -- insert the table_name,old_pk_id,new_pk_id into a plsql record
1532               -- Update all relevent cer records with new pk_id
1533               hr_utility.set_location('Before plsql table ',222);
1534               hr_utility.set_location('new_value id '||l_grade_rt_id,222);
1535               BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'GRADE_RT_ID' ;
1536               BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_GRR.information1 ;
1537               BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_GRADE_RT_ID ;
1538               BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
1539               BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_GRR_unique.table_route_id;
1540               hr_utility.set_location('After plsql table ',222);
1541               --
1542               -- 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 ) ;
1543               --
1544               BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
1545               --
1546             else
1547               --
1548               -- Call Update routine for the pk_id created in prev run .
1549            --UPD START
1550            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
1551            --
1552            if l_update then
1553              --
1554              l_datetrack_mode := r_GRR.datetrack_mode ;
1555              --
1556              get_dt_modes(
1557                p_effective_date        => l_process_date,
1558                p_effective_end_date    => r_GRR.information3,
1559                p_effective_start_date  => r_GRR.information2,
1560                p_dml_operation         => r_GRR.dml_operation,
1561                p_datetrack_mode        => l_datetrack_mode );
1562            --    p_update                => l_update
1563              --
1564              l_effective_date := l_process_date;
1565              l_GRADE_RT_ID   := r_GRR.information1;
1566              l_object_version_number := r_GRR.information265;
1567              --
1568            end if;
1569            --
1570            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
1571            --
1572            IF l_update OR l_dml_operation <> 'UPDATE' THEN
1573            --UPD END
1574               -- insert the table_name,old_pk_id,new_pk_id into a plsql record
1575               hr_utility.set_location(' BEN_GRADE_RT_F UPDATE_GRADE_RATE ',30);
1576               BEN_GRADE_RATE_API.UPDATE_GRADE_RATE(
1577                 --
1578                 P_VALIDATE               => false
1579                 ,P_EFFECTIVE_DATE        => l_effective_date
1580                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
1581                 --
1582             ,P_EXCLD_FLAG      => r_GRR.INFORMATION11
1583              ,P_GRADE_ID      => l_GRADE_ID
1584              ,P_GRADE_RT_ID      => l_grade_rt_id
1585              ,P_GRR_ATTRIBUTE1      => r_GRR.INFORMATION111
1586              ,P_GRR_ATTRIBUTE10      => r_GRR.INFORMATION120
1587              ,P_GRR_ATTRIBUTE11      => r_GRR.INFORMATION121
1588              ,P_GRR_ATTRIBUTE12      => r_GRR.INFORMATION122
1589              ,P_GRR_ATTRIBUTE13      => r_GRR.INFORMATION123
1590              ,P_GRR_ATTRIBUTE14      => r_GRR.INFORMATION124
1591              ,P_GRR_ATTRIBUTE15      => r_GRR.INFORMATION125
1592              ,P_GRR_ATTRIBUTE16      => r_GRR.INFORMATION126
1593              ,P_GRR_ATTRIBUTE17      => r_GRR.INFORMATION127
1594              ,P_GRR_ATTRIBUTE18      => r_GRR.INFORMATION128
1595              ,P_GRR_ATTRIBUTE19      => r_GRR.INFORMATION129
1596              ,P_GRR_ATTRIBUTE2      => r_GRR.INFORMATION112
1597              ,P_GRR_ATTRIBUTE20      => r_GRR.INFORMATION130
1598              ,P_GRR_ATTRIBUTE21      => r_GRR.INFORMATION131
1599              ,P_GRR_ATTRIBUTE22      => r_GRR.INFORMATION132
1600              ,P_GRR_ATTRIBUTE23      => r_GRR.INFORMATION133
1601              ,P_GRR_ATTRIBUTE24      => r_GRR.INFORMATION134
1602              ,P_GRR_ATTRIBUTE25      => r_GRR.INFORMATION135
1603              ,P_GRR_ATTRIBUTE26      => r_GRR.INFORMATION136
1604              ,P_GRR_ATTRIBUTE27      => r_GRR.INFORMATION137
1605              ,P_GRR_ATTRIBUTE28      => r_GRR.INFORMATION138
1606              ,P_GRR_ATTRIBUTE29      => r_GRR.INFORMATION139
1607              ,P_GRR_ATTRIBUTE3      => r_GRR.INFORMATION113
1608              ,P_GRR_ATTRIBUTE30      => r_GRR.INFORMATION140
1609              ,P_GRR_ATTRIBUTE4      => r_GRR.INFORMATION114
1610              ,P_GRR_ATTRIBUTE5      => r_GRR.INFORMATION115
1611              ,P_GRR_ATTRIBUTE6      => r_GRR.INFORMATION116
1612              ,P_GRR_ATTRIBUTE7      => r_GRR.INFORMATION117
1613              ,P_GRR_ATTRIBUTE8      => r_GRR.INFORMATION118
1614              ,P_GRR_ATTRIBUTE9      => r_GRR.INFORMATION119
1615              ,P_GRR_ATTRIBUTE_CATEGORY      => r_GRR.INFORMATION110
1616              ,P_ORDR_NUM      => r_GRR.INFORMATION260
1617              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
1618                 --
1619                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
1620                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
1621                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
1622                 ,P_DATETRACK_MODE        => l_datetrack_mode
1623               );
1624               --
1625               end if;
1626             end if;
1627             --
1628             -- Delete the row if it is end dated.
1629             --
1630             if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
1631              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
1632                 trunc(l_max_eed) = r_GRR.information3) then
1633                 --
1634                 BEN_GRADE_RATE_API.delete_GRADE_RATE(
1635                    --
1636                    p_validate                       => false
1637                    ,p_grade_rt_id                   => l_grade_rt_id
1638                    ,p_effective_start_date           => l_effective_start_date
1639                    ,p_effective_end_date             => l_effective_end_date
1640                    ,p_object_version_number          => l_object_version_number
1641                    ,p_effective_date                 => l_max_eed
1642                    ,p_datetrack_mode                 => hr_api.g_delete
1643                    --
1644                    );
1645                    --
1646             end if;
1647             --
1648             l_prev_pk_id := l_current_pk_id ;
1649             --
1650           end if;
1651           --
1652        end if;
1653        --
1654      end if;
1655      --
1656    end loop;
1657    --
1658  exception when others then
1659     --
1660     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'GRR',r_grr.information5 );
1661     --
1662  end create_GRR_rows;
1663 
1664    --
1665    ---------------------------------------------------------------
1666    ----------------------< create_FTR_rows >-----------------------
1667    ---------------------------------------------------------------
1668    --
1669    procedure create_FTR_rows
1670    (
1671          p_validate                       in  number     default 0
1672         ,p_copy_entity_txn_id             in  number
1673         ,p_effective_date                 in  date
1674         ,p_prefix_suffix_text             in  varchar2  default null
1675         ,p_reuse_object_flag              in  varchar2  default null
1676         ,p_target_business_group_id       in  varchar2  default null
1677         ,p_prefix_suffix_cd               in  varchar2  default null
1678    ) is
1679    --
1680    l_VRBL_RT_PRFL_ID  number;
1681    l_EXCLD_FLAG       varchar2(100);
1682    l_ORDR_NUM         number;
1683    l_FL_TM_PT_TM_CD   varchar2(30);
1684    --
1685    cursor c_unique_FTR(l_table_alias varchar2) is
1686    select distinct cpe.information1,
1687      cpe.information2,
1688      cpe.information3,
1689      cpe.table_route_id
1690    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
1691         pqh_table_route tr
1692    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
1693    and   cpe.table_route_id     = tr.table_route_id
1694    -- and   tr.where_clause        = l_BEN_FL_TM_PT_TM_RT_F
1695    and tr.table_alias = l_table_alias
1696    and   cpe.number_of_copies   = 1 -- ADDITION
1697    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
1698    order by information1, information2; --added for bug: 5151945
1699    --
1700    --
1701    cursor c_FTR_min_max_dates(c_table_route_id  number,
1702                 c_information1   Number) is
1703    select
1704      min(cpe.information2) min_esd,
1705      max(cpe.information3) min_eed
1706    from ben_copy_entity_results cpe
1707    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
1708    and   cpe.table_route_id     = c_table_route_id
1709    and   cpe.information1       = c_information1 ;
1710    --
1711    cursor c_FTR(c_table_route_id  number,
1712                 c_information1   Number,
1713                 c_information2   Date,
1714                 c_information3   Date)  is
1715    select
1716      cpe.*
1717    from ben_copy_entity_results cpe
1718    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
1719    and   cpe.table_route_id     = c_table_route_id
1720    and   cpe.information1       = c_information1
1721    and   cpe.information2       = c_information2
1722    and   cpe.information3       = c_information3
1723    and rownum = 1 ;
1724    -- Date Track target record
1725    cursor c_find_FTR_in_target(
1726                                 c_effective_start_date    date,
1727                                 c_effective_end_date      date,
1728                                 c_business_group_id       number,
1729                                 c_new_pk_id               number) is
1730    select
1731      FTR.fl_tm_pt_tm_rt_id new_value
1732    from BEN_FL_TM_PT_TM_RT_F FTR
1733    where
1734    FTR.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
1735    FTR.FL_TM_PT_TM_CD     = l_FL_TM_PT_TM_CD and
1736    FTR.ORDR_NUM           = l_ORDR_NUM and
1737    FTR.business_group_id  = c_business_group_id
1738    and   FTR.fl_tm_pt_tm_rt_id  <> c_new_pk_id
1739 --TEMPIK
1740    and c_effective_start_date between effective_start_date
1741                             and effective_end_date ;
1742 --END TEMPIK
1743 /*TEMPIK
1744    and exists ( select null
1745                 from BEN_FL_TM_PT_TM_RT_F FTR1
1746                 where
1747                 FTR1.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
1748                 FTR1.FL_TM_PT_TM_CD  = l_FL_TM_PT_TM_CD and
1749                 FTR1.ORDR_NUM           = l_ORDR_NUM and
1750                 FTR1.business_group_id  = c_business_group_id
1751                 and   FTR1.effective_start_date <= c_effective_start_date )
1752    and exists ( select null
1753                 from BEN_FL_TM_PT_TM_RT_F FTR2
1754                 where
1755                 FTR2.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
1756                 FTR2.FL_TM_PT_TM_CD = l_FL_TM_PT_TM_CD and
1757                 FTR2.ORDR_NUM           = l_ORDR_NUM and
1758                 FTR2.business_group_id  = c_business_group_id
1759                 and   FTR2.effective_end_date >= c_effective_end_date )
1760                 ;
1761 TEMPIK */
1762    --TEMPIK
1763    l_dt_rec_found            boolean ;
1764    --END TEMPIK
1765    --
1766    l_current_pk_id           number := null ;
1767    --UPD START
1768    --
1769    l_update                  boolean      := false ;
1770    l_datetrack_mode          varchar2(80) := hr_api.g_update;
1771    l_process_date            date;
1772    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
1773    --
1774    --UPD END
1775    l_prev_pk_id              number := null ;
1776    l_first_rec               boolean := true ;
1777    r_FTR                     c_FTR%rowtype;
1778    l_fl_tm_pt_tm_rt_id             number ;
1779    l_object_version_number   number ;
1780    l_effective_start_date    date ;
1781    l_effective_end_date      date ;
1782    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
1783    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
1784    l_new_value               number(15);
1785    l_object_found_in_target  boolean := false ;
1786    l_min_esd                 date;
1787    l_max_eed                 date;
1788    l_effective_date          date;
1789    --
1790  begin
1791    -- Initialization
1792    l_object_found_in_target := false ;
1793    -- End Initialization
1794    -- Derive the prefix - sufix
1795    if   p_prefix_suffix_cd = 'PREFIX' then
1796      l_prefix  := p_prefix_suffix_text ;
1797    elsif p_prefix_suffix_cd = 'SUFFIX' then
1798      l_suffix   := p_prefix_suffix_text ;
1799    else
1800      l_prefix := null ;
1801      l_suffix  := null ;
1802    end if ;
1803    -- End Prefix Sufix derivation
1804    for r_FTR_unique in c_unique_FTR('FTR') loop
1805 
1806      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
1807         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
1808          r_FTR_unique.information3 >=
1809                  ben_pd_copy_to_ben_one.g_copy_effective_date)
1810         ) then
1811        --
1812        hr_utility.set_location(' r_FTR_unique.table_route_id '||r_FTR_unique.table_route_id,10);
1813        hr_utility.set_location(' r_FTR_unique.information1 '||r_FTR_unique.information1,10);
1814        hr_utility.set_location( 'r_FTR_unique.information2 '||r_FTR_unique.information2,10);
1815        hr_utility.set_location( 'r_FTR_unique.information3 '||r_FTR_unique.information3,10);
1816        -- If reuse objects flag is 'Y' then check for the object in the target business group
1817        -- if found insert the record into PLSql table and exit the loop else try create the
1818        -- object in the target business group
1819        --
1820        l_object_found_in_target := false ;
1821        l_min_esd := null ;
1822        l_max_eed := null ;
1823        open c_FTR_min_max_dates(r_FTR_unique.table_route_id, r_FTR_unique.information1 ) ;
1824        fetch c_FTR_min_max_dates into l_min_esd,l_max_eed ;
1825        --
1826 
1827        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
1828             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
1829          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
1830        end if;
1831        l_min_esd := greatest(l_min_esd,r_FTR_unique.information2);
1832        open c_FTR(r_FTR_unique.table_route_id,
1833                 r_FTR_unique.information1,
1834                 r_FTR_unique.information2,
1835                 r_FTR_unique.information3 ) ;
1836        --
1837        fetch c_FTR into r_FTR ;
1838        --
1839        close c_FTR ;
1840        --
1841        l_VRBL_RT_PRFL_ID  := get_fk('VRBL_RT_PRFL_ID', r_FTR.INFORMATION262,r_FTR_unique.dml_operation);
1842        l_ORDR_NUM         := r_FTR.INFORMATION260;
1843        l_EXCLD_FLAG       := r_FTR.information11;
1844        l_FL_TM_PT_TM_CD   := r_FTR.information12;
1845        --
1846        --UPD START
1847        l_update := false;
1848        l_process_date := p_effective_date;
1849        l_dml_operation:= r_FTR_unique.dml_operation ;
1850        --
1851        if l_dml_operation = 'UPDATE' then
1852          --
1853          l_object_found_in_target := TRUE;
1854          --
1855          if l_process_date between r_FTR_unique.information2 and r_FTR_unique.information3 then
1856                l_update := true;
1857                if r_FTR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
1858                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'FL_TM_PT_TM_RT_ID'
1859                then
1860                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'FL_TM_PT_TM_RT_ID' ;
1861                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_FTR_unique.information1 ;
1862                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_FTR_unique.information1 ;
1863                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
1864                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_FTR_unique.table_route_id;
1865                   --
1866                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
1867                   --
1868                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
1869                   --
1870                   --log_data('FTR',l_new_value,l_prefix || r_FTR_unique.name|| l_suffix,'REUSED');
1871                   --
1872                end if ;
1873                hr_utility.set_location( 'found record for update',10);
1874            --
1875          else
1876            --
1877            l_update := false;
1878            --
1879          end if;
1880        else
1881          --
1882          --UPD END
1883        if p_reuse_object_flag = 'Y' then
1884          if c_FTR_min_max_dates%found then
1885            -- cursor to find the object
1886            open c_find_FTR_in_target( l_min_esd,l_max_eed,
1887                                  p_target_business_group_id, nvl(l_fl_tm_pt_tm_rt_id, -999)  ) ;
1888            fetch c_find_FTR_in_target into l_new_value ;
1889            if c_find_FTR_in_target%found then
1890              --
1891              --TEMPIK
1892              l_dt_rec_found :=   dt_api.check_min_max_dates
1893                  (p_base_table_name => 'BEN_FL_TM_PT_TM_RT_F',
1894                   p_base_key_column => 'FL_TM_PT_TM_RT_ID',
1895                   p_base_key_value  => l_new_value,
1896                   p_from_date       => l_min_esd,
1897                   p_to_date         => l_max_eed );
1898              if l_dt_rec_found THEN
1899              --END TEMPIK
1900              if r_FTR_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
1901                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'FL_TM_PT_TM_RT_ID'  then
1902                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'FL_TM_PT_TM_RT_ID' ;
1903                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_FTR_unique.information1 ;
1904                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
1905                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
1906                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_FTR_unique.table_route_id;
1907                 --
1908                 -- 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) ;
1909                 --
1910                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
1911              end if ;
1912              --
1913              l_object_found_in_target := true ;
1914              --TEMPIK
1915              end if; -- l_dt_rec_found
1916              --END TEMPIK
1917            end if;
1918            close c_find_FTR_in_target ;
1919          --
1920          end if;
1921        end if ;
1922        --
1923        end if;
1924        close c_FTR_min_max_dates ;
1925        if not l_object_found_in_target OR l_update   then
1926          --
1927          l_current_pk_id := r_FTR.information1;
1928          --
1929          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
1930          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
1931          --
1932          if l_current_pk_id =  l_prev_pk_id  then
1933            --
1934            l_first_rec := false ;
1935            --
1936          else
1937            --
1938            l_first_rec := true ;
1939            --
1940          end if ;
1941          --
1942 
1943          l_effective_date := r_FTR.information2;
1944          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
1945               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
1946            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
1947          end if;
1948 
1949          if l_first_rec and not l_update then
1950            -- Call Create routine.
1951            hr_utility.set_location(' BEN_FL_TM_PT_TM_RT_F CREATE_FULL_PRT_TIME_RATE ',20);
1952            BEN_FULL_PRT_TIME_RATE_API.CREATE_FULL_PRT_TIME_RATE(
1953              --
1954              P_VALIDATE               => false
1955              ,P_EFFECTIVE_DATE        => l_effective_date
1956              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
1957              --
1958               ,P_EXCLD_FLAG      => r_FTR.INFORMATION11
1959              ,P_FL_TM_PT_TM_CD      => r_FTR.INFORMATION12
1960              ,P_FL_TM_PT_TM_RT_ID      => l_fl_tm_pt_tm_rt_id
1961              ,P_FTR_ATTRIBUTE1      => r_FTR.INFORMATION111
1962              ,P_FTR_ATTRIBUTE10      => r_FTR.INFORMATION120
1963              ,P_FTR_ATTRIBUTE11      => r_FTR.INFORMATION121
1964              ,P_FTR_ATTRIBUTE12      => r_FTR.INFORMATION122
1965              ,P_FTR_ATTRIBUTE13      => r_FTR.INFORMATION123
1966              ,P_FTR_ATTRIBUTE14      => r_FTR.INFORMATION124
1967              ,P_FTR_ATTRIBUTE15      => r_FTR.INFORMATION125
1968              ,P_FTR_ATTRIBUTE16      => r_FTR.INFORMATION126
1969              ,P_FTR_ATTRIBUTE17      => r_FTR.INFORMATION127
1970              ,P_FTR_ATTRIBUTE18      => r_FTR.INFORMATION128
1971              ,P_FTR_ATTRIBUTE19      => r_FTR.INFORMATION129
1972              ,P_FTR_ATTRIBUTE2      => r_FTR.INFORMATION112
1973              ,P_FTR_ATTRIBUTE20      => r_FTR.INFORMATION130
1974              ,P_FTR_ATTRIBUTE21      => r_FTR.INFORMATION131
1975              ,P_FTR_ATTRIBUTE22      => r_FTR.INFORMATION132
1976              ,P_FTR_ATTRIBUTE23      => r_FTR.INFORMATION133
1977              ,P_FTR_ATTRIBUTE24      => r_FTR.INFORMATION134
1978              ,P_FTR_ATTRIBUTE25      => r_FTR.INFORMATION135
1979              ,P_FTR_ATTRIBUTE26      => r_FTR.INFORMATION136
1980              ,P_FTR_ATTRIBUTE27      => r_FTR.INFORMATION137
1981              ,P_FTR_ATTRIBUTE28      => r_FTR.INFORMATION138
1982              ,P_FTR_ATTRIBUTE29      => r_FTR.INFORMATION139
1983              ,P_FTR_ATTRIBUTE3      => r_FTR.INFORMATION113
1984              ,P_FTR_ATTRIBUTE30      => r_FTR.INFORMATION140
1985              ,P_FTR_ATTRIBUTE4      => r_FTR.INFORMATION114
1986              ,P_FTR_ATTRIBUTE5      => r_FTR.INFORMATION115
1987              ,P_FTR_ATTRIBUTE6      => r_FTR.INFORMATION116
1988              ,P_FTR_ATTRIBUTE7      => r_FTR.INFORMATION117
1989              ,P_FTR_ATTRIBUTE8      => r_FTR.INFORMATION118
1990              ,P_FTR_ATTRIBUTE9      => r_FTR.INFORMATION119
1991              ,P_FTR_ATTRIBUTE_CATEGORY      => r_FTR.INFORMATION110
1992              ,P_ORDR_NUM      => r_FTR.INFORMATION260
1993              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
1994              --
1995              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
1996              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
1997              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
1998            );
1999            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
2000            -- Update all relevent cer records with new pk_id
2001            hr_utility.set_location('Before plsql table ',222);
2002            hr_utility.set_location('new_value id '||l_fl_tm_pt_tm_rt_id,222);
2003            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'FL_TM_PT_TM_RT_ID' ;
2004            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_FTR.information1 ;
2005            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_FL_TM_PT_TM_RT_ID ;
2006            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
2007            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_FTR_unique.table_route_id;
2008            hr_utility.set_location('After plsql table ',222);
2009            --
2010            -- 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 ) ;
2011            --
2012            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
2013            --
2014          else
2015            --
2016            -- Call Update routine for the pk_id created in prev run .
2017            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
2018            --UPD START
2019            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
2020            --
2021            if l_update then
2022              --
2023              l_datetrack_mode := r_FTR.datetrack_mode ;
2024              --
2025              get_dt_modes(
2026                p_effective_date        => l_process_date,
2027                p_effective_end_date    => r_FTR.information3,
2028                p_effective_start_date  => r_FTR.information2,
2029                p_dml_operation         => r_FTR.dml_operation,
2030                p_datetrack_mode        => l_datetrack_mode );
2031            --    p_update                => l_update
2032              --
2033              l_effective_date := l_process_date;
2034              l_FL_TM_PT_TM_RT_ID   := r_FTR.information1;
2035              l_object_version_number := r_FTR.information265;
2036              --
2037            end if;
2038            --
2039            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
2040            --
2041            IF l_update OR l_dml_operation <> 'UPDATE' THEN
2042            --UPD END
2043            hr_utility.set_location(' BEN_FL_TM_PT_TM_RT_F UPDATE_FULL_PRT_TIME_RATE ',30);
2044            BEN_FULL_PRT_TIME_RATE_API.UPDATE_FULL_PRT_TIME_RATE(
2045              --
2046              P_VALIDATE               => false
2047              ,P_EFFECTIVE_DATE        => l_effective_date
2048              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
2049              --
2050              ,P_EXCLD_FLAG      => r_FTR.INFORMATION11
2051              ,P_FL_TM_PT_TM_CD      => r_FTR.INFORMATION12
2052              ,P_FL_TM_PT_TM_RT_ID      => l_fl_tm_pt_tm_rt_id
2053              ,P_FTR_ATTRIBUTE1      => r_FTR.INFORMATION111
2054              ,P_FTR_ATTRIBUTE10      => r_FTR.INFORMATION120
2055              ,P_FTR_ATTRIBUTE11      => r_FTR.INFORMATION121
2056              ,P_FTR_ATTRIBUTE12      => r_FTR.INFORMATION122
2057              ,P_FTR_ATTRIBUTE13      => r_FTR.INFORMATION123
2058              ,P_FTR_ATTRIBUTE14      => r_FTR.INFORMATION124
2059              ,P_FTR_ATTRIBUTE15      => r_FTR.INFORMATION125
2060              ,P_FTR_ATTRIBUTE16      => r_FTR.INFORMATION126
2061              ,P_FTR_ATTRIBUTE17      => r_FTR.INFORMATION127
2062              ,P_FTR_ATTRIBUTE18      => r_FTR.INFORMATION128
2063              ,P_FTR_ATTRIBUTE19      => r_FTR.INFORMATION129
2064              ,P_FTR_ATTRIBUTE2      => r_FTR.INFORMATION112
2065              ,P_FTR_ATTRIBUTE20      => r_FTR.INFORMATION130
2066              ,P_FTR_ATTRIBUTE21      => r_FTR.INFORMATION131
2067              ,P_FTR_ATTRIBUTE22      => r_FTR.INFORMATION132
2068              ,P_FTR_ATTRIBUTE23      => r_FTR.INFORMATION133
2069              ,P_FTR_ATTRIBUTE24      => r_FTR.INFORMATION134
2070              ,P_FTR_ATTRIBUTE25      => r_FTR.INFORMATION135
2071              ,P_FTR_ATTRIBUTE26      => r_FTR.INFORMATION136
2072              ,P_FTR_ATTRIBUTE27      => r_FTR.INFORMATION137
2073              ,P_FTR_ATTRIBUTE28      => r_FTR.INFORMATION138
2074              ,P_FTR_ATTRIBUTE29      => r_FTR.INFORMATION139
2075              ,P_FTR_ATTRIBUTE3      => r_FTR.INFORMATION113
2076              ,P_FTR_ATTRIBUTE30      => r_FTR.INFORMATION140
2077              ,P_FTR_ATTRIBUTE4      => r_FTR.INFORMATION114
2078              ,P_FTR_ATTRIBUTE5      => r_FTR.INFORMATION115
2079              ,P_FTR_ATTRIBUTE6      => r_FTR.INFORMATION116
2080              ,P_FTR_ATTRIBUTE7      => r_FTR.INFORMATION117
2081              ,P_FTR_ATTRIBUTE8      => r_FTR.INFORMATION118
2082              ,P_FTR_ATTRIBUTE9      => r_FTR.INFORMATION119
2083              ,P_FTR_ATTRIBUTE_CATEGORY      => r_FTR.INFORMATION110
2084              ,P_ORDR_NUM      => r_FTR.INFORMATION260
2085              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
2086              --
2087              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
2088              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
2089              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
2090              ,P_DATETRACK_MODE        => l_datetrack_mode
2091            );
2092            --
2093            end if;
2094          end if;
2095          --
2096          -- Delete the row if it is end dated.
2097          --
2098          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
2099              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
2100              trunc(l_max_eed) = r_FTR.information3) then
2101              --
2102              BEN_FULL_PRT_TIME_RATE_API.delete_FULL_PRT_TIME_RATE(
2103                 --
2104                 p_validate                       => false
2105                 ,p_fl_tm_pt_tm_rt_id                   => l_fl_tm_pt_tm_rt_id
2106                 ,p_effective_start_date           => l_effective_start_date
2107                 ,p_effective_end_date             => l_effective_end_date
2108                 ,p_object_version_number          => l_object_version_number
2109                 ,p_effective_date                 => l_max_eed
2110                 ,p_datetrack_mode                 => hr_api.g_delete
2111                 --
2112                 );
2113                 --
2114          end if;
2115          --
2116          l_prev_pk_id := l_current_pk_id ;
2117          --
2118        end if;
2119        --
2120      end if;
2121      --
2122    end loop;
2123    --
2124  exception when others then
2125     --
2126     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'FTR',r_ftr.information5 );
2127     --
2128  end create_FTR_rows;
2129 
2130    --
2131    ---------------------------------------------------------------
2132    ----------------------< create_BUR_rows >-----------------------
2133    ---------------------------------------------------------------
2134    --
2135    procedure create_BUR_rows
2136    (
2137          p_validate                       in  number     default 0
2138         ,p_copy_entity_txn_id             in  number
2139         ,p_effective_date                 in  date
2140         ,p_prefix_suffix_text             in  varchar2  default null
2141         ,p_reuse_object_flag              in  varchar2  default null
2142         ,p_target_business_group_id       in  varchar2  default null
2143         ,p_prefix_suffix_cd               in  varchar2  default null
2144    ) is
2145    --
2146    l_VRBL_RT_PRFL_ID  number;
2147    l_BRGNG_UNIT_CD    varchar2(100);
2148    l_ORDR_NUM         number;
2149    --
2150    cursor c_unique_BUR(l_table_alias varchar2) is
2151    select distinct cpe.information1,
2152      cpe.information2,
2153      cpe.information3,
2154      cpe.table_route_id
2155    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
2156         pqh_table_route tr
2157    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
2158    and   cpe.table_route_id     = tr.table_route_id
2159    -- and   tr.where_clause        = l_BEN_BRGNG_UNIT_RT_F
2160    and tr.table_alias = l_table_alias
2161    and   cpe.number_of_copies   = 1 -- ADDITION
2162    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
2163    order by information1, information2; --added for bug: 5151945
2164    --
2165    --
2166    cursor c_BUR_min_max_dates(c_table_route_id  number,
2167                 c_information1   Number) is
2168    select
2169      min(cpe.information2) min_esd,
2170      max(cpe.information3) min_eed
2171    from ben_copy_entity_results cpe
2172    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
2173    and   cpe.table_route_id     = c_table_route_id
2174    and   cpe.information1       = c_information1 ;
2175    --
2176    cursor c_BUR(c_table_route_id  number,
2177                 c_information1   number,
2178                 c_information2   date,
2179                 c_information3   date)  is
2180    select
2181      cpe.*
2182    from ben_copy_entity_results cpe
2183    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
2184    and   cpe.table_route_id     = c_table_route_id
2185    and   cpe.information1       = c_information1
2186    and   cpe.information2       = c_information2
2187    and   cpe.information3       = c_information3
2188    and rownum = 1 ;
2189    -- Date Track target record
2190    cursor c_find_BUR_in_target(
2191                                 c_effective_start_date    date,
2192                                 c_effective_end_date      date,
2193                                 c_business_group_id       number,
2194                                 c_new_pk_id               number) is
2195    select
2196      BUR.brgng_unit_rt_id new_value
2197    from BEN_BRGNG_UNIT_RT_F BUR
2198    where
2199    BUR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
2200    BUR.BRGNG_UNIT_CD         = l_BRGNG_UNIT_CD and
2201    BUR.ORDR_NUM           = l_ORDR_NUM and
2202    BUR.business_group_id  = c_business_group_id
2203    and   BUR.brgng_unit_rt_id  <> c_new_pk_id
2204 --TEMPIK
2205    and c_effective_start_date between effective_start_date
2206                             and effective_end_date ;
2207 --END TEMPIK
2208 /*TEMPIK
2209    and exists ( select null
2210                 from BEN_BRGNG_UNIT_RT_F BUR1
2211                 where
2212                 BUR1.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
2213                 BUR1.BRGNG_UNIT_CD         = l_BRGNG_UNIT_CD and
2214                 BUR1.ORDR_NUM           = l_ORDR_NUM and
2215                 BUR1.business_group_id  = c_business_group_id
2216                 and   BUR1.effective_start_date <= c_effective_start_date )
2217    and exists ( select null
2218                 from BEN_BRGNG_UNIT_RT_F BUR2
2219                 where
2220                 BUR2.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
2221                 BUR2.BRGNG_UNIT_CD         = l_BRGNG_UNIT_CD and
2222                 BUR2.ORDR_NUM           = l_ORDR_NUM and
2223                 BUR2.business_group_id  = c_business_group_id
2224                 and   BUR2.effective_end_date >= c_effective_end_date )
2225                 ;
2226 TEMPIK */
2227    --TEMPIK
2228    l_dt_rec_found            boolean ;
2229    --END TEMPIK
2230    --
2231    l_current_pk_id           number := null ;
2232    --UPD START
2233    --
2234    l_update                  boolean      := false ;
2235    l_datetrack_mode          varchar2(80) := hr_api.g_update;
2236    l_process_date            date;
2237    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
2238    --
2239    --UPD END
2240    l_prev_pk_id              number := null ;
2241    l_first_rec               boolean := true ;
2242    r_BUR                     c_BUR%rowtype;
2243    l_brgng_unit_rt_id             number ;
2244    l_object_version_number   number ;
2245    l_effective_start_date    date ;
2246    l_effective_end_date      date ;
2247    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
2248    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
2249    l_new_value               number(15);
2250    l_object_found_in_target  boolean := false ;
2251    l_min_esd                 date;
2252    l_max_eed                 date;
2253    l_effective_date          date;
2254    --
2255  begin
2256    -- Initialization
2257    l_object_found_in_target := false ;
2258    -- End Initialization
2259    -- Derive the prefix - sufix
2260    if   p_prefix_suffix_cd = 'PREFIX' then
2261      l_prefix  := p_prefix_suffix_text ;
2262    elsif p_prefix_suffix_cd = 'SUFFIX' then
2263      l_suffix   := p_prefix_suffix_text ;
2264    else
2265      l_prefix := null ;
2266      l_suffix  := null ;
2267    end if ;
2268    -- End Prefix Sufix derivation
2269    for r_BUR_unique in c_unique_BUR('BUR') loop
2270 
2271      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
2272         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
2273          r_BUR_unique.information3 >=
2274                  ben_pd_copy_to_ben_one.g_copy_effective_date)
2275         ) then
2276 
2277        --
2278        hr_utility.set_location(' r_BUR_unique.table_route_id '||r_BUR_unique.table_route_id,10);
2279        hr_utility.set_location(' r_BUR_unique.information1 '||r_BUR_unique.information1,10);
2280        hr_utility.set_location( 'r_BUR_unique.information2 '||r_BUR_unique.information2,10);
2281        hr_utility.set_location( 'r_BUR_unique.information3 '||r_BUR_unique.information3,10);
2282        -- If reuse objects flag is 'Y' then check for the object in the target business group
2283        -- if found insert the record into PLSql table and exit the loop else try create the
2284        -- object in the target business group
2285        --
2286        l_object_found_in_target := false ;
2287        l_min_esd := null ;
2288        l_max_eed := null ;
2289        open c_BUR_min_max_dates(r_BUR_unique.table_route_id, r_BUR_unique.information1 ) ;
2290        fetch c_BUR_min_max_dates into l_min_esd,l_max_eed ;
2291        --
2292 
2293        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
2294             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
2295          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
2296        end if;
2297        l_min_esd := greatest(l_min_esd,r_BUR_unique.information2);
2298        open c_BUR(r_BUR_unique.table_route_id,
2299                 r_BUR_unique.information1,
2300                 r_BUR_unique.information2,
2301                 r_BUR_unique.information3 ) ;
2302        --
2303        fetch c_BUR into r_BUR ;
2304        --
2305        close c_BUR ;
2306        --
2307        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_BUR.INFORMATION262,r_BUR_unique.dml_operation);
2308        l_ORDR_NUM         := r_BUR.INFORMATION260;
2309        l_BRGNG_UNIT_CD      := r_BUR.INFORMATION12;
2310        --UPD START
2311        l_update := false;
2312        l_process_date := p_effective_date;
2313        l_dml_operation:= r_BUR_unique.dml_operation ;
2314        --
2315        if l_dml_operation = 'UPDATE' then
2316          --
2317          l_object_found_in_target := TRUE;
2318          --
2319          if l_process_date between r_BUR_unique.information2 and r_BUR_unique.information3 then
2320                l_update := true;
2321                if r_BUR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
2322                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'BRGNG_UNIT_RT_ID'
2323                then
2324                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'BRGNG_UNIT_RT_ID' ;
2325                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_BUR_unique.information1 ;
2326                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_BUR_unique.information1 ;
2327                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
2328                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_BUR_unique.table_route_id;
2329                   --
2330                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
2331                   --
2332                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
2333                   --
2334                   --log_data('BUR',l_new_value,l_prefix || r_BUR_unique.name|| l_suffix,'REUSED');
2335                   --
2336                end if ;
2337                hr_utility.set_location( 'found record for update',10);
2338            --
2339          else
2340            --
2341            l_update := false;
2342            --
2343          end if;
2344        else
2345          --
2346          --UPD END
2347        if p_reuse_object_flag = 'Y' then
2348          if c_BUR_min_max_dates%found then
2349            -- cursor to find the object
2350            open c_find_BUR_in_target( l_min_esd,l_max_eed,
2351                                  p_target_business_group_id, nvl(l_brgng_unit_rt_id, -999)  ) ;
2352            fetch c_find_BUR_in_target into l_new_value ;
2353            if c_find_BUR_in_target%found then
2354              --
2355              --TEMPIK
2356              l_dt_rec_found :=   dt_api.check_min_max_dates
2357                  (p_base_table_name => 'BEN_BRGNG_UNIT_RT_F',
2358                   p_base_key_column => 'BRGNG_UNIT_RT_ID',
2359                   p_base_key_value  => l_new_value,
2360                   p_from_date       => l_min_esd,
2361                   p_to_date         => l_max_eed );
2362              if l_dt_rec_found THEN
2363              --END TEMPIK
2364              if r_BUR_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
2365                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'BRGNG_UNIT_RT_ID'  then
2366                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'BRGNG_UNIT_RT_ID' ;
2367                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_BUR_unique.information1 ;
2368                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
2369                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
2370                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_BUR_unique.table_route_id;
2371                 --
2372                 -- 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) ;
2373                 --
2374                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
2375              end if ;
2376              --
2377              l_object_found_in_target := true ;
2378              --TEMPIK
2379              end if; -- l_dt_rec_found
2380              --END TEMPIK
2381            end if;
2382            close c_find_BUR_in_target ;
2383          --
2384          end if;
2385        end if ;
2386        end if;
2387        --
2388        close c_BUR_min_max_dates ;
2389        if not l_object_found_in_target OR l_update   then
2390          --
2391          l_current_pk_id := r_BUR.information1;
2392          --
2393          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
2394          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
2395          --
2396          if l_current_pk_id =  l_prev_pk_id  then
2397            --
2398            l_first_rec := false ;
2399            --
2400          else
2401            --
2402            l_first_rec := true ;
2403            --
2404          end if ;
2405          --
2406 
2407          l_effective_date := r_BUR.information2;
2408          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
2409               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
2410            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
2411          end if;
2412 
2413          if l_first_rec and not l_update then
2414            -- Call Create routine.
2415            hr_utility.set_location(' BEN_BRGNG_UNIT_RT_F CREATE_BARGAINING_UNIT_RT ',20);
2416            BEN_BARGAINING_UNIT_RT_API.CREATE_BARGAINING_UNIT_RT(
2417              --
2418              P_VALIDATE               => false
2419              ,P_EFFECTIVE_DATE        => l_effective_date
2420              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
2421              --
2422              ,P_BRGNG_UNIT_CD      => r_BUR.INFORMATION12
2423              ,P_BRGNG_UNIT_RT_ID      => l_brgng_unit_rt_id
2424              ,P_BUR_ATTRIBUTE1      => r_BUR.INFORMATION111
2425              ,P_BUR_ATTRIBUTE10      => r_BUR.INFORMATION120
2426              ,P_BUR_ATTRIBUTE11      => r_BUR.INFORMATION121
2427              ,P_BUR_ATTRIBUTE12      => r_BUR.INFORMATION122
2428              ,P_BUR_ATTRIBUTE13      => r_BUR.INFORMATION123
2429              ,P_BUR_ATTRIBUTE14      => r_BUR.INFORMATION124
2430              ,P_BUR_ATTRIBUTE15      => r_BUR.INFORMATION125
2431              ,P_BUR_ATTRIBUTE16      => r_BUR.INFORMATION126
2432              ,P_BUR_ATTRIBUTE17      => r_BUR.INFORMATION127
2433              ,P_BUR_ATTRIBUTE18      => r_BUR.INFORMATION128
2434              ,P_BUR_ATTRIBUTE19      => r_BUR.INFORMATION129
2435              ,P_BUR_ATTRIBUTE2      => r_BUR.INFORMATION112
2436              ,P_BUR_ATTRIBUTE20      => r_BUR.INFORMATION130
2437              ,P_BUR_ATTRIBUTE21      => r_BUR.INFORMATION131
2438              ,P_BUR_ATTRIBUTE22      => r_BUR.INFORMATION132
2439              ,P_BUR_ATTRIBUTE23      => r_BUR.INFORMATION133
2440              ,P_BUR_ATTRIBUTE24      => r_BUR.INFORMATION134
2441              ,P_BUR_ATTRIBUTE25      => r_BUR.INFORMATION135
2442              ,P_BUR_ATTRIBUTE26      => r_BUR.INFORMATION136
2443              ,P_BUR_ATTRIBUTE27      => r_BUR.INFORMATION137
2444              ,P_BUR_ATTRIBUTE28      => r_BUR.INFORMATION138
2445              ,P_BUR_ATTRIBUTE29      => r_BUR.INFORMATION139
2446              ,P_BUR_ATTRIBUTE3      => r_BUR.INFORMATION113
2447              ,P_BUR_ATTRIBUTE30      => r_BUR.INFORMATION140
2448              ,P_BUR_ATTRIBUTE4      => r_BUR.INFORMATION114
2449              ,P_BUR_ATTRIBUTE5      => r_BUR.INFORMATION115
2450              ,P_BUR_ATTRIBUTE6      => r_BUR.INFORMATION116
2451              ,P_BUR_ATTRIBUTE7      => r_BUR.INFORMATION117
2452              ,P_BUR_ATTRIBUTE8      => r_BUR.INFORMATION118
2453              ,P_BUR_ATTRIBUTE9      => r_BUR.INFORMATION119
2454              ,P_BUR_ATTRIBUTE_CATEGORY      => r_BUR.INFORMATION110
2455              ,P_EXCLD_FLAG      => r_BUR.INFORMATION11
2456              ,P_ORDR_NUM      => r_BUR.INFORMATION260
2457              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
2458              --
2459              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
2460              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
2461              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
2462            );
2463            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
2464            -- Update all relevent cer records with new pk_id
2465            hr_utility.set_location('Before plsql table ',222);
2466            hr_utility.set_location('new_value id '||l_brgng_unit_rt_id,222);
2467            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'BRGNG_UNIT_RT_ID' ;
2468            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_BUR.information1 ;
2469            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_BRGNG_UNIT_RT_ID ;
2470            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
2471            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_BUR_unique.table_route_id;
2472            hr_utility.set_location('After plsql table ',222);
2473            --
2474            -- 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 ) ;
2475            --
2476            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
2477            --
2478          else
2479            --
2480            -- Call Update routine for the pk_id created in prev run .
2481            --UPD START
2482            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
2483            --
2484            if l_update then
2485              --
2486              l_datetrack_mode := r_BUR.datetrack_mode ;
2487              --
2488              get_dt_modes(
2489                p_effective_date        => l_process_date,
2490                p_effective_end_date    => r_BUR.information3,
2491                p_effective_start_date  => r_BUR.information2,
2492                p_dml_operation         => r_BUR.dml_operation,
2493                p_datetrack_mode        => l_datetrack_mode );
2494            --    p_update                => l_update
2495              --
2496              l_effective_date := l_process_date;
2497              l_BRGNG_UNIT_RT_ID   := r_BUR.information1;
2498              l_object_version_number := r_BUR.information265;
2499              --
2500            end if;
2501            --
2502            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
2503            --
2504            IF l_update OR l_dml_operation <> 'UPDATE' THEN
2505            --UPD END
2506            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
2507            hr_utility.set_location(' BEN_BRGNG_UNIT_RT_F UPDATE_BARGAINING_UNIT_RT ',30);
2508            BEN_BARGAINING_UNIT_RT_API.UPDATE_BARGAINING_UNIT_RT(
2509              --
2510              P_VALIDATE               => false
2511              ,P_EFFECTIVE_DATE        => l_effective_date
2512              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
2513              --
2514             ,P_BRGNG_UNIT_CD      => r_BUR.INFORMATION12
2515              ,P_BRGNG_UNIT_RT_ID      => l_brgng_unit_rt_id
2516              ,P_BUR_ATTRIBUTE1      => r_BUR.INFORMATION111
2517              ,P_BUR_ATTRIBUTE10      => r_BUR.INFORMATION120
2518              ,P_BUR_ATTRIBUTE11      => r_BUR.INFORMATION121
2519              ,P_BUR_ATTRIBUTE12      => r_BUR.INFORMATION122
2520              ,P_BUR_ATTRIBUTE13      => r_BUR.INFORMATION123
2521              ,P_BUR_ATTRIBUTE14      => r_BUR.INFORMATION124
2522              ,P_BUR_ATTRIBUTE15      => r_BUR.INFORMATION125
2523              ,P_BUR_ATTRIBUTE16      => r_BUR.INFORMATION126
2524              ,P_BUR_ATTRIBUTE17      => r_BUR.INFORMATION127
2525              ,P_BUR_ATTRIBUTE18      => r_BUR.INFORMATION128
2526              ,P_BUR_ATTRIBUTE19      => r_BUR.INFORMATION129
2527              ,P_BUR_ATTRIBUTE2      => r_BUR.INFORMATION112
2528              ,P_BUR_ATTRIBUTE20      => r_BUR.INFORMATION130
2529              ,P_BUR_ATTRIBUTE21      => r_BUR.INFORMATION131
2530              ,P_BUR_ATTRIBUTE22      => r_BUR.INFORMATION132
2531              ,P_BUR_ATTRIBUTE23      => r_BUR.INFORMATION133
2532              ,P_BUR_ATTRIBUTE24      => r_BUR.INFORMATION134
2533              ,P_BUR_ATTRIBUTE25      => r_BUR.INFORMATION135
2534              ,P_BUR_ATTRIBUTE26      => r_BUR.INFORMATION136
2535              ,P_BUR_ATTRIBUTE27      => r_BUR.INFORMATION137
2536              ,P_BUR_ATTRIBUTE28      => r_BUR.INFORMATION138
2537              ,P_BUR_ATTRIBUTE29      => r_BUR.INFORMATION139
2538              ,P_BUR_ATTRIBUTE3      => r_BUR.INFORMATION113
2539              ,P_BUR_ATTRIBUTE30      => r_BUR.INFORMATION140
2540              ,P_BUR_ATTRIBUTE4      => r_BUR.INFORMATION114
2541              ,P_BUR_ATTRIBUTE5      => r_BUR.INFORMATION115
2542              ,P_BUR_ATTRIBUTE6      => r_BUR.INFORMATION116
2543              ,P_BUR_ATTRIBUTE7      => r_BUR.INFORMATION117
2544              ,P_BUR_ATTRIBUTE8      => r_BUR.INFORMATION118
2545              ,P_BUR_ATTRIBUTE9      => r_BUR.INFORMATION119
2546              ,P_BUR_ATTRIBUTE_CATEGORY      => r_BUR.INFORMATION110
2547              ,P_EXCLD_FLAG      => r_BUR.INFORMATION11
2548              ,P_ORDR_NUM      => r_BUR.INFORMATION260
2549              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
2550              --
2551              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
2552              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
2553              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
2554              ,P_DATETRACK_MODE        => l_datetrack_mode
2555            );
2556            --
2557            end if;
2558          end if;
2559          --
2560          -- Delete the row if it is end dated.
2561          --
2562          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
2563              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
2564              trunc(l_max_eed) = r_BUR.information3) then
2565              --
2566              BEN_BARGAINING_UNIT_RT_API.delete_BARGAINING_UNIT_RT(
2567                 --
2568                 p_validate                       => false
2569                 ,p_brgng_unit_rt_id                   => l_brgng_unit_rt_id
2570                 ,p_effective_start_date           => l_effective_start_date
2571                 ,p_effective_end_date             => l_effective_end_date
2572                 ,p_object_version_number          => l_object_version_number
2573                 ,p_effective_date                 => l_max_eed
2574                 ,p_datetrack_mode                 => hr_api.g_delete
2575                 --
2576                 );
2577                 --
2578          end if;
2579          --
2580          l_prev_pk_id := l_current_pk_id ;
2581          --
2582        end if;
2583        --
2584      end if;
2585      --
2586    end loop;
2587    --
2588  exception when others then
2589     --
2590     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'BUR',r_bur.information5 );
2591     --
2592  end create_BUR_rows;
2593 
2594    --
2595    ---------------------------------------------------------------
2596    ----------------------< create_ESR_rows >-----------------------
2597    ---------------------------------------------------------------
2598    --
2599    procedure create_ESR_rows
2600    (
2601          p_validate                       in  number     default 0
2602         ,p_copy_entity_txn_id             in  number
2603         ,p_effective_date                 in  date
2604         ,p_prefix_suffix_text             in  varchar2  default null
2605         ,p_reuse_object_flag              in  varchar2  default null
2606         ,p_target_business_group_id       in  varchar2  default null
2607         ,p_prefix_suffix_cd               in  varchar2  default null
2608    ) is
2609    --
2610    l_ASSIGNMENT_STATUS_TYPE_ID  number;
2611    l_VRBL_RT_PRFL_ID  number;
2612    l_EXCLD_FLAG       varchar2(100);
2613    l_ORDR_NUM         number;
2614    --
2615    cursor c_unique_ESR(l_table_alias varchar2) is
2616    select distinct cpe.information1,
2617      cpe.information2,
2618      cpe.information3,
2619      cpe.table_route_id
2620    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
2621         pqh_table_route tr
2622    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
2623    and   cpe.table_route_id     = tr.table_route_id
2624    -- and   tr.where_clause        = l_BEN_EE_STAT_RT_F
2625    and tr.table_alias = l_table_alias
2626    and   cpe.number_of_copies   = 1 -- ADDITION
2627    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
2628    order by information1, information2; --added for bug: 5151945
2629    --
2630    --
2631    cursor c_ESR_min_max_dates(c_table_route_id  number,
2632                 c_information1   Number) is
2633    select
2634      min(cpe.information2) min_esd,
2635      max(cpe.information3) min_eed
2636    from ben_copy_entity_results cpe
2637    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
2638    and   cpe.table_route_id     = c_table_route_id
2639    and   cpe.information1       = c_information1 ;
2640    --
2641    cursor c_ESR(c_table_route_id  number,
2642                 c_information1   number,
2643                 c_information2   date,
2644                 c_information3   Date)  is
2645    select
2646      cpe.*
2647    from ben_copy_entity_results cpe
2648    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
2649    and   cpe.table_route_id     = c_table_route_id
2650    and   cpe.information1       = c_information1
2651    and   cpe.information2       = c_information2
2652    and   cpe.information3       = c_information3
2653    and rownum = 1 ;
2654    -- Date Track target record
2655    cursor c_find_ESR_in_target(
2656                                 c_effective_start_date    date,
2657                                 c_effective_end_date      date,
2658                                 c_business_group_id       number,
2659                                 c_new_pk_id               number) is
2660    select
2661      ESR.ee_stat_rt_id new_value
2662    from BEN_EE_STAT_RT_F ESR
2663    where
2664    ESR.ASSIGNMENT_STATUS_TYPE_ID     = l_ASSIGNMENT_STATUS_TYPE_ID  and
2665    ESR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
2666    ESR.ORDR_NUM           = l_ORDR_NUM and
2667    ESR.business_group_id  = c_business_group_id
2668    and   ESR.ee_stat_rt_id  <> c_new_pk_id
2669 --TEMPIK
2670    and c_effective_start_date between effective_start_date
2671                             and effective_end_date ;
2672 --END TEMPIK
2673 /*TEMPIK
2674    and exists ( select null
2675                 from BEN_EE_STAT_RT_F ESR1
2676                 where
2677                 ESR1.ASSIGNMENT_STATUS_TYPE_ID     = l_ASSIGNMENT_STATUS_TYPE_ID  and
2678                 ESR1.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
2679                 ESR1.ORDR_NUM           = l_ORDR_NUM and
2680                 ESR1.business_group_id  = c_business_group_id
2681                 and   ESR1.effective_start_date <= c_effective_start_date )
2682    and exists ( select null
2683                 from BEN_EE_STAT_RT_F ESR2
2684                 where
2685                 ESR2.ASSIGNMENT_STATUS_TYPE_ID     = l_ASSIGNMENT_STATUS_TYPE_ID  and
2686                 ESR2.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
2687                 ESR2.ORDR_NUM           = l_ORDR_NUM and
2688                 ESR2.business_group_id  = c_business_group_id
2689                 and   ESR2.effective_end_date >= c_effective_end_date )
2690                 ;
2691 TEMPIK */
2692    --TEMPIK
2693    l_dt_rec_found            boolean ;
2694    --END TEMPIK
2695    --
2696    l_current_pk_id           number := null ;
2697    --UPD START
2698    --
2699    l_update                  boolean      := false ;
2700    l_datetrack_mode          varchar2(80) := hr_api.g_update;
2701    l_process_date            date;
2702    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
2703    --
2704    --UPD END
2705    l_prev_pk_id              number := null ;
2706    l_first_rec               boolean := true ;
2707    r_ESR                     c_ESR%rowtype;
2708    l_ee_stat_rt_id             number ;
2709    l_object_version_number   number ;
2710    l_effective_start_date    date ;
2711    l_effective_end_date      date ;
2712    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
2713    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
2714    l_new_value               number(15);
2715    l_object_found_in_target  boolean := false ;
2716    l_min_esd                 date;
2717    l_max_eed                 date;
2718    l_effective_date          date;
2719    --
2720  begin
2721    -- Initialization
2722    l_object_found_in_target := false ;
2723    -- End Initialization
2724    -- Derive the prefix - sufix
2725    if   p_prefix_suffix_cd = 'PREFIX' then
2726      l_prefix  := p_prefix_suffix_text ;
2727    elsif p_prefix_suffix_cd = 'SUFFIX' then
2728      l_suffix   := p_prefix_suffix_text ;
2729    else
2730      l_prefix := null ;
2731      l_suffix  := null ;
2732    end if ;
2733    -- End Prefix Sufix derivation
2734    for r_ESR_unique in c_unique_ESR('ESR') loop
2735 
2736      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
2737         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
2738          r_ESR_unique.information3 >=
2739                  ben_pd_copy_to_ben_one.g_copy_effective_date)
2740         ) then
2741        --
2742        hr_utility.set_location(' r_ESR_unique.table_route_id '||r_ESR_unique.table_route_id,10);
2743        hr_utility.set_location(' r_ESR_unique.information1 '||r_ESR_unique.information1,10);
2744        hr_utility.set_location( 'r_ESR_unique.information2 '||r_ESR_unique.information2,10);
2745        hr_utility.set_location( 'r_ESR_unique.information3 '||r_ESR_unique.information3,10);
2746        -- If reuse objects flag is 'Y' then check for the object in the target business group
2747        -- if found insert the record into PLSql table and exit the loop else try create the
2748        -- object in the target business group
2749        --
2750        l_object_found_in_target := false ;
2751        l_min_esd := null ;
2752        l_max_eed := null ;
2753        open c_ESR_min_max_dates(r_ESR_unique.table_route_id, r_ESR_unique.information1 ) ;
2754        fetch c_ESR_min_max_dates into l_min_esd,l_max_eed ;
2755        --
2756 
2757        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
2758             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
2759          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
2760        end if;
2761        l_min_esd := greatest(l_min_esd,r_ESR_unique.information2);
2762        open c_ESR(r_ESR_unique.table_route_id,
2763                 r_ESR_unique.information1,
2764                 r_ESR_unique.information2,
2765                 r_ESR_unique.information3 ) ;
2766        --
2767        fetch c_ESR into r_ESR ;
2768        --
2769        close c_ESR ;
2770 
2771        if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
2772          l_ASSIGNMENT_STATUS_TYPE_ID := r_ESR.information176;
2773        else
2774          l_ASSIGNMENT_STATUS_TYPE_ID := r_ESR.information174;
2775        end if;
2776        --
2777        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_ESR.INFORMATION262,r_ESR_unique.dml_operation);
2778        l_ORDR_NUM         := r_ESR.INFORMATION257;
2779        l_EXCLD_FLAG      := r_ESR.INFORMATION11;
2780 
2781        if l_ASSIGNMENT_STATUS_TYPE_ID is null then
2782          close c_ESR_min_max_dates;
2783          log_nomapping_data(p_parent_table_alias =>'VPF'
2784                      ,p_parent_pk_id         => r_ESR.information262
2785                      ,p_copy_entity_txn_id   => p_copy_entity_txn_id
2786                      ,p_child_table_alias    => 'ESR'
2787                      ,p_child_data           => r_ESR.information173 );
2788        else
2789        --UPD START
2790        l_update := false;
2791        l_process_date := p_effective_date;
2792        l_dml_operation:= r_ESR_unique.dml_operation ;
2793        --
2794        if l_dml_operation = 'UPDATE' then
2795          --
2796          l_object_found_in_target := TRUE;
2797          --
2798          if l_process_date between r_ESR_unique.information2 and r_ESR_unique.information3 then
2799                l_update := true;
2800                if r_ESR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
2801                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'EE_STAT_RT_ID'
2802                then
2803                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'EE_STAT_RT_ID' ;
2804                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_ESR_unique.information1 ;
2805                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_ESR_unique.information1 ;
2806                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
2807                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_ESR_unique.table_route_id;
2808                   --
2809                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
2810                   --
2811                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
2812                   --
2813                   -- log_data('ESR',l_new_value,l_prefix || r_ESR_unique.name|| l_suffix,'REUSED');
2814                   --
2815                end if ;
2816                hr_utility.set_location( 'found record for update',10);
2817            --
2818          else
2819            --
2820            l_update := false;
2821            --
2822          end if;
2823        else
2824          --
2825          --UPD END
2826 
2827          if p_reuse_object_flag = 'Y' then
2828            if c_ESR_min_max_dates%found then
2829               -- cursor to find the object
2830               open c_find_ESR_in_target( l_min_esd,l_max_eed,
2831                                     p_target_business_group_id, nvl(l_ee_stat_rt_id, -999)  ) ;
2832               fetch c_find_ESR_in_target into l_new_value ;
2833               if c_find_ESR_in_target%found then
2834                 --
2835              --TEMPIK
2836              l_dt_rec_found :=   dt_api.check_min_max_dates
2837                  (p_base_table_name => 'BEN_EE_STAT_RT_F',
2838                   p_base_key_column => 'EE_STAT_RT_ID',
2839                   p_base_key_value  => l_new_value,
2840                   p_from_date       => l_min_esd,
2841                   p_to_date         => l_max_eed );
2842              if l_dt_rec_found THEN
2843              --END TEMPIK
2844                 if r_ESR_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
2845                    nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'EE_STAT_RT_ID'  then
2846                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'EE_STAT_RT_ID' ;
2847                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_ESR_unique.information1 ;
2848                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
2849                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
2850                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_ESR_unique.table_route_id;
2851                    --
2852                    -- 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) ;
2853                    --
2854                    BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
2855                 end if ;
2856                 --
2857                 l_object_found_in_target := true ;
2858              --TEMPIK
2859              end if; -- l_dt_rec_found
2860              --END TEMPIK
2861               end if;
2862               close c_find_ESR_in_target ;
2863            --
2864            end if;
2865          end if ;
2866          end if;
2867          --
2868          close c_ESR_min_max_dates ;
2869          if not l_object_found_in_target OR l_update   then
2870            --
2871            l_current_pk_id := r_ESR.information1;
2872            --
2873            hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
2874            hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
2875            --
2876            if l_current_pk_id =  l_prev_pk_id  then
2877              --
2878              l_first_rec := false ;
2879              --
2880            else
2881              --
2882              l_first_rec := true ;
2883              --
2884            end if ;
2885            --
2886 
2887            l_effective_date := r_ESR.information2;
2888            if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
2889                 l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
2890              l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
2891            end if;
2892 
2893            if l_first_rec and not l_update then
2894              -- Call Create routine.
2895              hr_utility.set_location(' BEN_EE_STAT_RT_F CREATE_EMPLOYEE_STATUS_RT ',20);
2896              BEN_EMPLOYEE_STATUS_RT_API.CREATE_EMPLOYEE_STATUS_RT(
2897                 --
2898                 P_VALIDATE               => false
2899                 ,P_EFFECTIVE_DATE        => l_effective_date
2900                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
2901                 --
2902              ,P_ASSIGNMENT_STATUS_TYPE_ID      => l_ASSIGNMENT_STATUS_TYPE_ID
2903              ,P_EE_STAT_RT_ID      => l_ee_stat_rt_id
2904              ,P_ESR_ATTRIBUTE1      => r_ESR.INFORMATION111
2905              ,P_ESR_ATTRIBUTE10      => r_ESR.INFORMATION120
2906              ,P_ESR_ATTRIBUTE11      => r_ESR.INFORMATION121
2907              ,P_ESR_ATTRIBUTE12      => r_ESR.INFORMATION122
2908              ,P_ESR_ATTRIBUTE13      => r_ESR.INFORMATION123
2909              ,P_ESR_ATTRIBUTE14      => r_ESR.INFORMATION124
2910              ,P_ESR_ATTRIBUTE15      => r_ESR.INFORMATION125
2911              ,P_ESR_ATTRIBUTE16      => r_ESR.INFORMATION126
2912              ,P_ESR_ATTRIBUTE17      => r_ESR.INFORMATION127
2913              ,P_ESR_ATTRIBUTE18      => r_ESR.INFORMATION128
2914              ,P_ESR_ATTRIBUTE19      => r_ESR.INFORMATION129
2915              ,P_ESR_ATTRIBUTE2      => r_ESR.INFORMATION112
2916              ,P_ESR_ATTRIBUTE20      => r_ESR.INFORMATION130
2917              ,P_ESR_ATTRIBUTE21      => r_ESR.INFORMATION131
2918              ,P_ESR_ATTRIBUTE22      => r_ESR.INFORMATION132
2919              ,P_ESR_ATTRIBUTE23      => r_ESR.INFORMATION133
2920              ,P_ESR_ATTRIBUTE24      => r_ESR.INFORMATION134
2921              ,P_ESR_ATTRIBUTE25      => r_ESR.INFORMATION135
2922              ,P_ESR_ATTRIBUTE26      => r_ESR.INFORMATION136
2923              ,P_ESR_ATTRIBUTE27      => r_ESR.INFORMATION137
2924              ,P_ESR_ATTRIBUTE28      => r_ESR.INFORMATION138
2925              ,P_ESR_ATTRIBUTE29      => r_ESR.INFORMATION139
2926              ,P_ESR_ATTRIBUTE3      => r_ESR.INFORMATION113
2927              ,P_ESR_ATTRIBUTE30      => r_ESR.INFORMATION140
2928              ,P_ESR_ATTRIBUTE4      => r_ESR.INFORMATION114
2929              ,P_ESR_ATTRIBUTE5      => r_ESR.INFORMATION115
2930              ,P_ESR_ATTRIBUTE6      => r_ESR.INFORMATION116
2931              ,P_ESR_ATTRIBUTE7      => r_ESR.INFORMATION117
2932              ,P_ESR_ATTRIBUTE8      => r_ESR.INFORMATION118
2933              ,P_ESR_ATTRIBUTE9      => r_ESR.INFORMATION119
2934              ,P_ESR_ATTRIBUTE_CATEGORY      => r_ESR.INFORMATION110
2935              ,P_EXCLD_FLAG      => r_ESR.INFORMATION11
2936              ,P_ORDR_NUM      => r_ESR.INFORMATION257
2937              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
2938                 --
2939                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
2940                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
2941                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
2942              );
2943              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
2944              -- Update all relevent cer records with new pk_id
2945              hr_utility.set_location('Before plsql table ',222);
2946              hr_utility.set_location('new_value id '||l_ee_stat_rt_id,222);
2947              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'EE_STAT_RT_ID' ;
2948              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_ESR.information1 ;
2949              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_EE_STAT_RT_ID ;
2950              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
2951              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_ESR_unique.table_route_id;
2952              hr_utility.set_location('After plsql table ',222);
2953              --
2954              -- 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 ) ;
2955              --
2956              BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
2957              --
2958            else
2959              --
2960              -- Call Update routine for the pk_id created in prev run .
2961            --UPD START
2962            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
2963            --
2964            if l_update then
2965              --
2966              l_datetrack_mode := r_ESR.datetrack_mode ;
2967              --
2968              get_dt_modes(
2969                p_effective_date        => l_process_date,
2970                p_effective_end_date    => r_ESR.information3,
2971                p_effective_start_date  => r_ESR.information2,
2972                p_dml_operation         => r_ESR.dml_operation,
2973                p_datetrack_mode        => l_datetrack_mode );
2974            --    p_update                => l_update
2975              --
2976              l_effective_date := l_process_date;
2977              l_EE_STAT_RT_ID   := r_ESR.information1;
2978              l_object_version_number := r_ESR.information265;
2979              --
2980            end if;
2981            --
2982            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
2983            --
2984            IF l_update OR l_dml_operation <> 'UPDATE' THEN
2985            --UPD END
2986              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
2987              hr_utility.set_location(' BEN_EE_STAT_RT_F UPDATE_EMPLOYEE_STATUS_RT ',30);
2988              BEN_EMPLOYEE_STATUS_RT_API.UPDATE_EMPLOYEE_STATUS_RT(
2989                 --
2990                 P_VALIDATE               => false
2991                 ,P_EFFECTIVE_DATE        => l_effective_date
2992                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
2993                 --
2994              ,P_ASSIGNMENT_STATUS_TYPE_ID      => l_ASSIGNMENT_STATUS_TYPE_ID
2995              ,P_EE_STAT_RT_ID      => l_ee_stat_rt_id
2996              ,P_ESR_ATTRIBUTE1      => r_ESR.INFORMATION111
2997              ,P_ESR_ATTRIBUTE10      => r_ESR.INFORMATION120
2998              ,P_ESR_ATTRIBUTE11      => r_ESR.INFORMATION121
2999              ,P_ESR_ATTRIBUTE12      => r_ESR.INFORMATION122
3000              ,P_ESR_ATTRIBUTE13      => r_ESR.INFORMATION123
3001              ,P_ESR_ATTRIBUTE14      => r_ESR.INFORMATION124
3002              ,P_ESR_ATTRIBUTE15      => r_ESR.INFORMATION125
3003              ,P_ESR_ATTRIBUTE16      => r_ESR.INFORMATION126
3004              ,P_ESR_ATTRIBUTE17      => r_ESR.INFORMATION127
3005              ,P_ESR_ATTRIBUTE18      => r_ESR.INFORMATION128
3006              ,P_ESR_ATTRIBUTE19      => r_ESR.INFORMATION129
3007              ,P_ESR_ATTRIBUTE2      => r_ESR.INFORMATION112
3008              ,P_ESR_ATTRIBUTE20      => r_ESR.INFORMATION130
3009              ,P_ESR_ATTRIBUTE21      => r_ESR.INFORMATION131
3010              ,P_ESR_ATTRIBUTE22      => r_ESR.INFORMATION132
3011              ,P_ESR_ATTRIBUTE23      => r_ESR.INFORMATION133
3012              ,P_ESR_ATTRIBUTE24      => r_ESR.INFORMATION134
3013              ,P_ESR_ATTRIBUTE25      => r_ESR.INFORMATION135
3014              ,P_ESR_ATTRIBUTE26      => r_ESR.INFORMATION136
3015              ,P_ESR_ATTRIBUTE27      => r_ESR.INFORMATION137
3016              ,P_ESR_ATTRIBUTE28      => r_ESR.INFORMATION138
3017              ,P_ESR_ATTRIBUTE29      => r_ESR.INFORMATION139
3018              ,P_ESR_ATTRIBUTE3      => r_ESR.INFORMATION113
3019              ,P_ESR_ATTRIBUTE30      => r_ESR.INFORMATION140
3020              ,P_ESR_ATTRIBUTE4      => r_ESR.INFORMATION114
3021              ,P_ESR_ATTRIBUTE5      => r_ESR.INFORMATION115
3022              ,P_ESR_ATTRIBUTE6      => r_ESR.INFORMATION116
3023              ,P_ESR_ATTRIBUTE7      => r_ESR.INFORMATION117
3024              ,P_ESR_ATTRIBUTE8      => r_ESR.INFORMATION118
3025              ,P_ESR_ATTRIBUTE9      => r_ESR.INFORMATION119
3026              ,P_ESR_ATTRIBUTE_CATEGORY      => r_ESR.INFORMATION110
3027              ,P_EXCLD_FLAG      => r_ESR.INFORMATION11
3028              ,P_ORDR_NUM      => r_ESR.INFORMATION257
3029              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
3030                 --
3031                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
3032                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
3033                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
3034                 ,P_DATETRACK_MODE        => l_datetrack_mode
3035              );
3036              --
3037              end if;
3038            end if;
3039            --
3040            -- Delete the row if it is end dated.
3041            --
3042            if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
3043              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
3044                 trunc(l_max_eed) = r_ESR.information3) then
3045                 --
3046                 BEN_EMPLOYEE_STATUS_RT_API.delete_EMPLOYEE_STATUS_RT(
3047                    --
3048                    p_validate                       => false
3049                    ,p_ee_stat_rt_id                   => l_ee_stat_rt_id
3050                    ,p_effective_start_date           => l_effective_start_date
3051                    ,p_effective_end_date             => l_effective_end_date
3052                    ,p_object_version_number          => l_object_version_number
3053                    ,p_effective_date                 => l_max_eed
3054                    ,p_datetrack_mode                 => hr_api.g_delete
3055                    --
3056                    );
3057                    --
3058            end if;
3059            --
3060            l_prev_pk_id := l_current_pk_id ;
3061            --
3062          end if;
3063          --
3064        end if;
3065        --
3066      end if;
3067      --
3068    end loop;
3069    --
3070  exception when others then
3071     --
3072     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'ESR',r_esr.information5 );
3073     --
3074  end create_ESR_rows;
3075 
3076    --
3077    ---------------------------------------------------------------
3078    ----------------------< create_ASR_rows >-----------------------
3079    ---------------------------------------------------------------
3080    --
3081    procedure create_ASR_rows
3082    (
3083          p_validate                       in  number     default 0
3084         ,p_copy_entity_txn_id             in  number
3085         ,p_effective_date                 in  date
3086         ,p_prefix_suffix_text             in  varchar2  default null
3087         ,p_reuse_object_flag              in  varchar2  default null
3088         ,p_target_business_group_id       in  varchar2  default null
3089         ,p_prefix_suffix_cd               in  varchar2  default null
3090    ) is
3091    --
3092    l_ASSIGNMENT_SET_ID  number;
3093    l_VRBL_RT_PRFL_ID  number;
3094    l_EXCLD_FLAG       varchar2(100);
3095    l_ORDR_NUM         number;
3096    --
3097    cursor c_unique_ASR(l_table_alias varchar2) is
3098    select distinct cpe.information1,
3099      cpe.information2,
3100      cpe.information3,
3101      cpe.table_route_id
3102    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
3103         pqh_table_route tr
3104    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
3105    and   cpe.table_route_id     = tr.table_route_id
3106    -- and   tr.where_clause        = l_BEN_ASNT_SET_RT_F
3107    and tr.table_alias = l_table_alias
3108    and   cpe.number_of_copies   = 1 -- ADDITION
3109    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
3110    order by information1, information2; --added for bug: 5151945
3111    --
3112    --
3113    cursor c_ASR_min_max_dates(c_table_route_id  number,
3114                 c_information1   number) is
3115    select
3116      min(cpe.information2) min_esd,
3117      max(cpe.information3) min_eed
3118    from ben_copy_entity_results cpe
3119    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
3120    and   cpe.table_route_id     = c_table_route_id
3121    and   cpe.information1       = c_information1 ;
3122    --
3123    cursor c_ASR(c_table_route_id  number,
3124                 c_information1   number,
3125                 c_information2   Date,
3126                 c_information3   Date )  is
3127    select
3128      cpe.*
3129    from ben_copy_entity_results cpe
3130    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
3131    and   cpe.table_route_id     = c_table_route_id
3132    and   cpe.information1       = c_information1
3133    and   cpe.information2       = c_information2
3134    and   cpe.information3       = c_information3
3135    and rownum = 1 ;
3136    -- Date Track target record
3137    cursor c_find_ASR_in_target(
3138                                 c_effective_start_date    date,
3139                                 c_effective_end_date      date,
3140                                 c_business_group_id       number,
3141                                 c_new_pk_id               number) is
3142    select
3143      ASR.asnt_set_rt_id new_value
3144    from BEN_ASNT_SET_RT_F ASR
3145    where
3146    ASR.ASSIGNMENT_SET_ID     = l_ASSIGNMENT_SET_ID  and
3147    ASR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
3148    ASR.ORDR_NUM           = l_ORDR_NUM and
3149    ASR.business_group_id  = c_business_group_id
3150    and   ASR.asnt_set_rt_id  <> c_new_pk_id
3151 --TEMPIK
3152    and c_effective_start_date between effective_start_date
3153                             and effective_end_date ;
3154 --END TEMPIK
3155 /*TEMPIK
3156    and exists ( select null
3157                 from BEN_ASNT_SET_RT_F ASR1
3158                 where
3159                 ASR1.ASSIGNMENT_SET_ID     = l_ASSIGNMENT_SET_ID  and
3160                 ASR1.vRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
3161                 ASR1.ORDR_NUM           = l_ORDR_NUM and
3162                 ASR1.business_group_id  = c_business_group_id
3163                 and   ASR1.effective_start_date <= c_effective_start_date )
3164    and exists ( select null
3165                 from BEN_ASNT_SET_RT_F ASR2
3166                 where
3167                 ASR2.ASSIGNMENT_SET_ID     = l_ASSIGNMENT_SET_ID  and
3168                 ASR2.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
3169                 ASR2.ORDR_NUM           = l_ORDR_NUM and
3170                 ASR2.business_group_id  = c_business_group_id
3171                 and   ASR2.effective_end_date >= c_effective_end_date )
3172                 ;
3173 TEMPIK */
3174    --TEMPIK
3175    l_dt_rec_found            boolean ;
3176    --END TEMPIK
3177    --
3178    l_current_pk_id           number := null ;
3179    --UPD START
3180    --
3181    l_update                  boolean      := false ;
3182    l_datetrack_mode          varchar2(80) := hr_api.g_update;
3183    l_process_date            date;
3184    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
3185    --
3186    --UPD END
3187    l_prev_pk_id              number := null ;
3188    l_first_rec               boolean := true ;
3189    r_ASR                     c_ASR%rowtype;
3190    l_asnt_set_rt_id             number ;
3191    l_object_version_number   number ;
3192    l_effective_start_date    date ;
3193    l_effective_end_date      date ;
3194    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
3195    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
3196    l_new_value               number(15);
3197    l_object_found_in_target  boolean := false ;
3198    l_min_esd                 date;
3199    l_max_eed                 date;
3200    l_effective_date          date;
3201    --
3202  begin
3203    -- Initialization
3204    l_object_found_in_target := false ;
3205    -- End Initialization
3206    -- Derive the prefix - sufix
3207    if   p_prefix_suffix_cd = 'PREFIX' then
3208      l_prefix  := p_prefix_suffix_text ;
3209    elsif p_prefix_suffix_cd = 'SUFFIX' then
3210      l_suffix   := p_prefix_suffix_text ;
3211    else
3212      l_prefix := null ;
3213      l_suffix  := null ;
3214    end if ;
3215    -- End Prefix Sufix derivation
3216    for r_ASR_unique in c_unique_ASR('ASR') loop
3217 
3218      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
3219         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
3220          r_ASR_unique.information3 >=
3221                  ben_pd_copy_to_ben_one.g_copy_effective_date)
3222         ) then
3223        --
3224        hr_utility.set_location(' r_ASR_unique.table_route_id '||r_ASR_unique.table_route_id,10);
3225        hr_utility.set_location(' r_ASR_unique.information1 '||r_ASR_unique.information1,10);
3226        hr_utility.set_location( 'r_ASR_unique.information2 '||r_ASR_unique.information2,10);
3227        hr_utility.set_location( 'r_ASR_unique.information3 '||r_ASR_unique.information3,10);
3228        -- If reuse objects flag is 'Y' then check for the object in the target business group
3229        -- if found insert the record into PLSql table and exit the loop else try create the
3230        -- object in the target business group
3231        --
3232        l_object_found_in_target := false ;
3233        l_min_esd := null ;
3234        l_max_eed := null ;
3235        open c_ASR_min_max_dates(r_ASR_unique.table_route_id, r_ASR_unique.information1 ) ;
3236        fetch c_ASR_min_max_dates into l_min_esd,l_max_eed ;
3237        --
3238 
3239        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
3240             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
3241          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
3242        end if;
3243        l_min_esd := greatest(l_min_esd,r_ASR_unique.information2);
3244        open c_ASR(r_ASR_unique.table_route_id,
3245                 r_ASR_unique.information1,
3246                 r_ASR_unique.information2,
3247                 r_ASR_unique.information3 ) ;
3248        --
3249        fetch c_ASR into r_ASR ;
3250        --
3251        close c_ASR ;
3252        --
3253        if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
3254          l_ASSIGNMENT_SET_ID := r_ASR.information176;
3255        else
3256          l_ASSIGNMENT_SET_ID := r_ASR.information174;
3257        end if;
3258        --
3259        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_ASR.INFORMATION262,r_ASR_unique.dml_operation );
3260        l_ORDR_NUM         := r_ASR.INFORMATION257;
3261        l_EXCLD_FLAG      := r_ASR.information11;
3262 
3263        if l_ASSIGNMENT_SET_ID is null then
3264          close c_ASR_min_max_dates;
3265          log_nomapping_data(p_parent_table_alias =>'VPF'
3266                      ,p_parent_pk_id         => r_ASR.information262
3267                      ,p_copy_entity_txn_id   => p_copy_entity_txn_id
3268                      ,p_child_table_alias    => 'ASR'
3269                      ,p_child_data           => r_ASR.information173 );
3270        else
3271        --UPD START
3272        l_update := false;
3273        l_process_date := p_effective_date;
3274        l_dml_operation:= r_ASR_unique.dml_operation ;
3275        --
3276        if l_dml_operation = 'UPDATE' then
3277          --
3278          l_object_found_in_target := TRUE;
3279          --
3280          if l_process_date between r_ASR_unique.information2 and r_ASR_unique.information3 then
3281                l_update := true;
3282                if r_ASR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
3283                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ASNT_SET_RT_ID'
3284                then
3285                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ASNT_SET_RT_ID' ;
3286                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_ASR_unique.information1 ;
3287                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_ASR_unique.information1 ;
3288                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
3289                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_ASR_unique.table_route_id;
3290                   --
3291                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
3292                   --
3293                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
3294                   --
3295                   -- log_data('ASR',l_new_value,l_prefix || r_ASR_unique.name|| l_suffix,'REUSED');
3296                   --
3297                end if ;
3298                hr_utility.set_location( 'found record for update',10);
3299            --
3300          else
3301            --
3302            l_update := false;
3303            --
3304          end if;
3305        else
3306          --
3307          --UPD END
3308          if p_reuse_object_flag = 'Y' then
3309             if c_ASR_min_max_dates%found then
3310               -- cursor to find the object
3311               open c_find_ASR_in_target( l_min_esd,l_max_eed,
3312                                     p_target_business_group_id, nvl(l_asnt_set_rt_id, -999)  ) ;
3313               fetch c_find_ASR_in_target into l_new_value ;
3314               if c_find_ASR_in_target%found then
3315                 --
3316              --TEMPIK
3317              l_dt_rec_found :=   dt_api.check_min_max_dates
3318                  (p_base_table_name => 'BEN_ASNT_SET_RT_F',
3319                   p_base_key_column => 'ASNT_SET_RT_ID',
3320                   p_base_key_value  => l_new_value,
3321                   p_from_date       => l_min_esd,
3322                   p_to_date         => l_max_eed );
3323              if l_dt_rec_found THEN
3324              --END TEMPIK
3325                 if r_ASR_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
3326                    nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'ASNT_SET_RT_ID'  then
3327                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'ASNT_SET_RT_ID' ;
3328                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_ASR_unique.information1 ;
3329                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
3330                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
3331                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_ASR_unique.table_route_id;
3332                    --
3333                    -- 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) ;
3334                    --
3335                    BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
3336                 end if ;
3337                 --
3338                 l_object_found_in_target := true ;
3339              --TEMPIK
3340              end if; -- l_dt_rec_found
3341              --END TEMPIK
3342               end if;
3343               close c_find_ASR_in_target ;
3344             --
3345             end if;
3346          end if ;
3347          --
3348          end if;
3349          close c_ASR_min_max_dates ;
3350          if not l_object_found_in_target OR l_update   then
3351            --
3352            l_current_pk_id := r_ASR.information1;
3353            --
3354            hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
3355            hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
3356            --
3357            if l_current_pk_id =  l_prev_pk_id  then
3358              --
3359              l_first_rec := false ;
3360              --
3361            else
3362              --
3363              l_first_rec := true ;
3364              --
3365            end if ;
3366            --
3367 
3368            l_effective_date := r_ASR.information2;
3369            if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
3370                 l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
3371              l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
3372            end if;
3373 
3374            if l_first_rec and not l_update then
3375              -- Call Create routine.
3376              hr_utility.set_location(' BEN_ASNT_SET_RT_F CREATE_ASSIGNMENT_SET_RATE ',20);
3377              BEN_ASSIGNMENT_SET_RATE_API.CREATE_ASSIGNMENT_SET_RATE(
3378                 --
3379                 P_VALIDATE               => false
3380                 ,P_EFFECTIVE_DATE        => l_effective_date
3381                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
3382                 --
3383               ,P_ASNT_SET_RT_ID      => l_asnt_set_rt_id
3384              ,P_ASR_ATTRIBUTE1      => r_ASR.INFORMATION111
3385              ,P_ASR_ATTRIBUTE10      => r_ASR.INFORMATION120
3386              ,P_ASR_ATTRIBUTE11      => r_ASR.INFORMATION121
3387              ,P_ASR_ATTRIBUTE12      => r_ASR.INFORMATION122
3388              ,P_ASR_ATTRIBUTE13      => r_ASR.INFORMATION123
3389              ,P_ASR_ATTRIBUTE14      => r_ASR.INFORMATION124
3390              ,P_ASR_ATTRIBUTE15      => r_ASR.INFORMATION125
3391              ,P_ASR_ATTRIBUTE16      => r_ASR.INFORMATION126
3392              ,P_ASR_ATTRIBUTE17      => r_ASR.INFORMATION127
3393              ,P_ASR_ATTRIBUTE18      => r_ASR.INFORMATION128
3394              ,P_ASR_ATTRIBUTE19      => r_ASR.INFORMATION129
3395              ,P_ASR_ATTRIBUTE2      => r_ASR.INFORMATION112
3396              ,P_ASR_ATTRIBUTE20      => r_ASR.INFORMATION130
3397              ,P_ASR_ATTRIBUTE21      => r_ASR.INFORMATION131
3398              ,P_ASR_ATTRIBUTE22      => r_ASR.INFORMATION132
3399              ,P_ASR_ATTRIBUTE23      => r_ASR.INFORMATION133
3400              ,P_ASR_ATTRIBUTE24      => r_ASR.INFORMATION134
3401              ,P_ASR_ATTRIBUTE25      => r_ASR.INFORMATION135
3402              ,P_ASR_ATTRIBUTE26      => r_ASR.INFORMATION136
3403              ,P_ASR_ATTRIBUTE27      => r_ASR.INFORMATION137
3404              ,P_ASR_ATTRIBUTE28      => r_ASR.INFORMATION138
3405              ,P_ASR_ATTRIBUTE29      => r_ASR.INFORMATION139
3406              ,P_ASR_ATTRIBUTE3      => r_ASR.INFORMATION113
3407              ,P_ASR_ATTRIBUTE30      => r_ASR.INFORMATION140
3408              ,P_ASR_ATTRIBUTE4      => r_ASR.INFORMATION114
3409              ,P_ASR_ATTRIBUTE5      => r_ASR.INFORMATION115
3410              ,P_ASR_ATTRIBUTE6      => r_ASR.INFORMATION116
3411              ,P_ASR_ATTRIBUTE7      => r_ASR.INFORMATION117
3412              ,P_ASR_ATTRIBUTE8      => r_ASR.INFORMATION118
3413              ,P_ASR_ATTRIBUTE9      => r_ASR.INFORMATION119
3414              ,P_ASR_ATTRIBUTE_CATEGORY      => r_ASR.INFORMATION110
3415              ,P_ASSIGNMENT_SET_ID      => l_ASSIGNMENT_SET_ID
3416              ,P_EXCLD_FLAG      => r_ASR.INFORMATION11
3417              ,P_ORDR_NUM      => r_ASR.INFORMATION257
3418              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
3419                 --
3420                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
3421                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
3422                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
3423              );
3424              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
3425              -- Update all relevent cer records with new pk_id
3426              hr_utility.set_location('Before plsql table ',222);
3427              hr_utility.set_location('new_value id '||l_asnt_set_rt_id,222);
3428              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'ASNT_SET_RT_ID' ;
3429              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_ASR.information1 ;
3430              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_ASNT_SET_RT_ID ;
3431              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
3432              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_ASR_unique.table_route_id;
3433              hr_utility.set_location('After plsql table ',222);
3434              --
3435              -- 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 ) ;
3436              --
3437              BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
3438              --
3439            else
3440              --
3441              -- Call Update routine for the pk_id created in prev run .
3442              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
3443            --UPD START
3444            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
3445            --
3446            if l_update then
3447              --
3448              l_datetrack_mode := r_ASR.datetrack_mode ;
3449              --
3450              get_dt_modes(
3451                p_effective_date        => l_process_date,
3452                p_effective_end_date    => r_ASR.information3,
3453                p_effective_start_date  => r_ASR.information2,
3454                p_dml_operation         => r_ASR.dml_operation,
3455                p_datetrack_mode        => l_datetrack_mode );
3456            --    p_update                => l_update
3457              --
3458              l_effective_date := l_process_date;
3459              l_ASNT_SET_RT_ID   := r_ASR.information1;
3460              l_object_version_number := r_ASR.information265;
3461              --
3462            end if;
3463            --
3464            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
3465            --
3466            IF l_update OR l_dml_operation <> 'UPDATE' THEN
3467            --UPD END
3468              hr_utility.set_location(' BEN_ASNT_SET_RT_F UPDATE_ASSIGNMENT_SET_RATE ',30);
3469              BEN_ASSIGNMENT_SET_RATE_API.UPDATE_ASSIGNMENT_SET_RATE(
3470                 --
3471                 P_VALIDATE               => false
3472                 ,P_EFFECTIVE_DATE        => l_effective_date
3473                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
3474                 --
3475              ,P_ASNT_SET_RT_ID      => l_asnt_set_rt_id
3476              ,P_ASR_ATTRIBUTE1      => r_ASR.INFORMATION111
3477              ,P_ASR_ATTRIBUTE10      => r_ASR.INFORMATION120
3478              ,P_ASR_ATTRIBUTE11      => r_ASR.INFORMATION121
3479              ,P_ASR_ATTRIBUTE12      => r_ASR.INFORMATION122
3480              ,P_ASR_ATTRIBUTE13      => r_ASR.INFORMATION123
3481              ,P_ASR_ATTRIBUTE14      => r_ASR.INFORMATION124
3482              ,P_ASR_ATTRIBUTE15      => r_ASR.INFORMATION125
3483              ,P_ASR_ATTRIBUTE16      => r_ASR.INFORMATION126
3484              ,P_ASR_ATTRIBUTE17      => r_ASR.INFORMATION127
3485              ,P_ASR_ATTRIBUTE18      => r_ASR.INFORMATION128
3486              ,P_ASR_ATTRIBUTE19      => r_ASR.INFORMATION129
3487              ,P_ASR_ATTRIBUTE2      => r_ASR.INFORMATION112
3488              ,P_ASR_ATTRIBUTE20      => r_ASR.INFORMATION130
3489              ,P_ASR_ATTRIBUTE21      => r_ASR.INFORMATION131
3490              ,P_ASR_ATTRIBUTE22      => r_ASR.INFORMATION132
3491              ,P_ASR_ATTRIBUTE23      => r_ASR.INFORMATION133
3492              ,P_ASR_ATTRIBUTE24      => r_ASR.INFORMATION134
3493              ,P_ASR_ATTRIBUTE25      => r_ASR.INFORMATION135
3494              ,P_ASR_ATTRIBUTE26      => r_ASR.INFORMATION136
3495              ,P_ASR_ATTRIBUTE27      => r_ASR.INFORMATION137
3496              ,P_ASR_ATTRIBUTE28      => r_ASR.INFORMATION138
3497              ,P_ASR_ATTRIBUTE29      => r_ASR.INFORMATION139
3498              ,P_ASR_ATTRIBUTE3      => r_ASR.INFORMATION113
3499              ,P_ASR_ATTRIBUTE30      => r_ASR.INFORMATION140
3500              ,P_ASR_ATTRIBUTE4      => r_ASR.INFORMATION114
3501              ,P_ASR_ATTRIBUTE5      => r_ASR.INFORMATION115
3502              ,P_ASR_ATTRIBUTE6      => r_ASR.INFORMATION116
3503              ,P_ASR_ATTRIBUTE7      => r_ASR.INFORMATION117
3504              ,P_ASR_ATTRIBUTE8      => r_ASR.INFORMATION118
3505              ,P_ASR_ATTRIBUTE9      => r_ASR.INFORMATION119
3506              ,P_ASR_ATTRIBUTE_CATEGORY      => r_ASR.INFORMATION110
3507              ,P_ASSIGNMENT_SET_ID      => l_ASSIGNMENT_SET_ID
3508              ,P_EXCLD_FLAG      => r_ASR.INFORMATION11
3509              ,P_ORDR_NUM      => r_ASR.INFORMATION257
3510              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
3511                 --
3512                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
3513                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
3514                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
3515                 ,P_DATETRACK_MODE        => l_datetrack_mode
3516              );
3517              --
3518              end if;
3519            end if;
3520            --
3521            -- Delete the row if it is end dated.
3522            --
3523            if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
3524              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
3525                 trunc(l_max_eed) = r_ASR.information3) then
3526                 --
3527                 BEN_ASSIGNMENT_SET_RATE_API.delete_ASSIGNMENT_SET_RATE(
3528                    --
3529                    p_validate                       => false
3530                    ,p_asnt_set_rt_id                   => l_asnt_set_rt_id
3531                    ,p_effective_start_date           => l_effective_start_date
3532                    ,p_effective_end_date             => l_effective_end_date
3533                    ,p_object_version_number          => l_object_version_number
3534                    ,p_effective_date                 => l_max_eed
3535                    ,p_datetrack_mode                 => hr_api.g_delete
3536                    --
3537                    );
3538                    --
3539            end if;
3540            --
3541            l_prev_pk_id := l_current_pk_id ;
3542            --
3543          end if;
3544          --
3545        end if;
3546        --
3547      end if;
3548      --
3549    end loop;
3550    --
3551  exception when others then
3552     --
3553     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'ASR',r_asr.information5 );
3554     --
3555  end create_ASR_rows;
3556 
3557    --
3558    ---------------------------------------------------------------
3559    ----------------------< create_TUR_rows >-----------------------
3560    ---------------------------------------------------------------
3561    --
3562    procedure create_TUR_rows
3563    (
3564          p_validate                       in  number     default 0
3565         ,p_copy_entity_txn_id             in  number
3566         ,p_effective_date                 in  date
3567         ,p_prefix_suffix_text             in  varchar2  default null
3568         ,p_reuse_object_flag              in  varchar2  default null
3569         ,p_target_business_group_id       in  varchar2  default null
3570         ,p_prefix_suffix_cd               in  varchar2  default null
3571    ) is
3572    --
3573    l_VRBL_RT_PRFL_ID  number;
3574    l_EXCLD_FLAG       varchar2(100);
3575    l_ORDR_NUM         number;
3576    l_USES_TBCO_FLAG   varchar2(30);
3577    --
3578    cursor c_unique_TUR(l_table_alias varchar2) is
3579    select distinct cpe.information1,
3580      cpe.information2,
3581      cpe.information3,
3582      cpe.table_route_id
3583    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
3584         pqh_table_route tr
3585    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
3586    and   cpe.table_route_id     = tr.table_route_id
3587    -- and   tr.where_clause        = l_BEN_TBCO_USE_RT_F
3588    and tr.table_alias = l_table_alias
3589    and   cpe.number_of_copies   = 1 -- ADDITION
3590    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
3591    order by information1, information2; --added for bug: 5151945
3592    --
3593    --
3594    cursor c_TUR_min_max_dates(c_table_route_id  number,
3595                 c_information1   Number) is
3596    select
3597      min(cpe.information2) min_esd,
3598      max(cpe.information3) min_eed
3599    from ben_copy_entity_results cpe
3600    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
3601    and   cpe.table_route_id     = c_table_route_id
3602    and   cpe.information1       = c_information1 ;
3603    --
3604    cursor c_TUR(c_table_route_id  number,
3605                 c_information1   number,
3606                 c_information2   Date,
3607                 c_information3   Date )  is
3608    select
3609      cpe.*
3610    from ben_copy_entity_results cpe
3611    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
3612    and   cpe.table_route_id     = c_table_route_id
3613    and   cpe.information1       = c_information1
3614    and   cpe.information2       = c_information2
3615    and   cpe.information3       = c_information3
3616    and rownum = 1 ;
3617    -- Date Track target record
3618    cursor c_find_TUR_in_target(
3619                                 c_effective_start_date    date,
3620                                 c_effective_end_date      date,
3621                                 c_business_group_id       number,
3622                                 c_new_pk_id               number) is
3623    select
3624      TUR.tbco_use_rt_id new_value
3625    from BEN_TBCO_USE_RT_F TUR
3626    where
3627    TUR.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
3628    TUR.USES_TBCO_FLAG     = l_USES_TBCO_FLAG and
3629    TUR.ORDR_NUM           = l_ORDR_NUM and
3630    TUR.business_group_id  = c_business_group_id
3631    and   TUR.tbco_use_rt_id  <> c_new_pk_id
3632 --TEMPIK
3633    and c_effective_start_date between effective_start_date
3634                             and effective_end_date ;
3635 --END TEMPIK
3636 /*TEMPIK
3637    and exists ( select null
3638                 from BEN_TBCO_USE_RT_F TUR1
3639                 where
3640                 TUR1.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
3641                 TUR1.USES_TBCO_FLAG     = l_USES_TBCO_FLAG and
3642                 TUR1.ORDR_NUM           = l_ORDR_NUM and
3643                 TUR1.business_group_id  = c_business_group_id
3644                 and   TUR1.effective_start_date <= c_effective_start_date )
3645    and exists ( select null
3646                 from BEN_TBCO_USE_RT_F TUR2
3647                 where
3648                 TUR2.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
3649                 TUR2.USES_TBCO_FLAG     = l_USES_TBCO_FLAG and
3650                 TUR2.ORDR_NUM           = l_ORDR_NUM and
3651                 TUR2.business_group_id  = c_business_group_id
3652                 and   TUR2.effective_end_date >= c_effective_end_date )
3653                 ;
3654 TEMPIK */
3655    --TEMPIK
3656    l_dt_rec_found            boolean ;
3657    --END TEMPIK
3658    --
3659    l_current_pk_id           number := null ;
3660    --UPD START
3661    --
3662    l_update                  boolean      := false ;
3663    l_datetrack_mode          varchar2(80) := hr_api.g_update;
3664    l_process_date            date;
3665    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
3666    --
3667    --UPD END
3668    l_prev_pk_id              number := null ;
3669    l_first_rec               boolean := true ;
3670    r_TUR                     c_TUR%rowtype;
3671    l_tbco_use_rt_id             number ;
3672    l_object_version_number   number ;
3673    l_effective_start_date    date ;
3674    l_effective_end_date      date ;
3675    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
3676    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
3677    l_new_value               number(15);
3678    l_object_found_in_target  boolean := false ;
3679    l_min_esd                 date;
3680    l_max_eed                 date;
3681    l_effective_date          date;
3682    --
3683  begin
3684    -- Initialization
3685    l_object_found_in_target := false ;
3686    -- End Initialization
3687    -- Derive the prefix - sufix
3688    if   p_prefix_suffix_cd = 'PREFIX' then
3689      l_prefix  := p_prefix_suffix_text ;
3690    elsif p_prefix_suffix_cd = 'SUFFIX' then
3691      l_suffix   := p_prefix_suffix_text ;
3692    else
3693      l_prefix := null ;
3694      l_suffix  := null ;
3695    end if ;
3696    -- End Prefix Sufix derivation
3697    for r_TUR_unique in c_unique_TUR('TUR') loop
3698 
3699      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
3700         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
3701          r_TUR_unique.information3 >=
3702                  ben_pd_copy_to_ben_one.g_copy_effective_date)
3703         ) then
3704        --
3705        hr_utility.set_location(' r_TUR_unique.table_route_id '||r_TUR_unique.table_route_id,10);
3706        hr_utility.set_location(' r_TUR_unique.information1 '||r_TUR_unique.information1,10);
3707        hr_utility.set_location( 'r_TUR_unique.information2 '||r_TUR_unique.information2,10);
3708        hr_utility.set_location( 'r_TUR_unique.information3 '||r_TUR_unique.information3,10);
3709        -- If reuse objects flag is 'Y' then check for the object in the target business group
3710        -- if found insert the record into PLSql table and exit the loop else try create the
3711        -- object in the target business group
3712        --
3713        l_object_found_in_target := false ;
3714        l_min_esd := null ;
3715        l_max_eed := null ;
3716        open c_TUR_min_max_dates(r_TUR_unique.table_route_id, r_TUR_unique.information1 ) ;
3717        fetch c_TUR_min_max_dates into l_min_esd,l_max_eed ;
3718        --
3719 
3720        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
3721             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
3722          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
3723        end if;
3724        l_min_esd := greatest(l_min_esd,r_TUR_unique.information2);
3725        open c_TUR(r_TUR_unique.table_route_id,
3726                 r_TUR_unique.information1,
3727                 r_TUR_unique.information2,
3728                 r_TUR_unique.information3 ) ;
3729        --
3730        fetch c_TUR into r_TUR ;
3731        --
3732        close c_TUR ;
3733        --
3734        l_VRBL_RT_PRFL_ID  := get_fk('VRBL_RT_PRFL_ID', r_TUR.information262,r_TUR_unique.dml_operation);
3735        l_ORDR_NUM         := r_TUR.INFORMATION257;
3736        l_EXCLD_FLAG       := r_TUR.information11;
3737        l_USES_TBCO_FLAG   := r_TUR.INFORMATION12;
3738        --
3739        --UPD START
3740        l_update := false;
3741        l_process_date := p_effective_date;
3742        l_dml_operation:= r_TUR_unique.dml_operation ;
3743        --
3744        if l_dml_operation = 'UPDATE' then
3745          --
3746          l_object_found_in_target := TRUE;
3747          --
3748          if l_process_date between r_TUR_unique.information2 and r_TUR_unique.information3 then
3749                l_update := true;
3750                if r_TUR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
3751                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'TBCO_USE_RT_ID'
3752                then
3753                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'TBCO_USE_RT_ID' ;
3754                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_TUR_unique.information1 ;
3755                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_TUR_unique.information1 ;
3756                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
3757                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_TUR_unique.table_route_id;
3758                   --
3759                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
3760                   --
3761                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
3762                   --
3763                   -- log_data('TUR',l_new_value,l_prefix || r_TUR_unique.name|| l_suffix,'REUSED');
3764                   --
3765                end if ;
3766                hr_utility.set_location( 'found record for update',10);
3767            --
3768          else
3769            --
3770            l_update := false;
3771            --
3772          end if;
3773        else
3774          --
3775          --UPD END
3776 
3777        if p_reuse_object_flag = 'Y' then
3778          if c_TUR_min_max_dates%found then
3779            -- cursor to find the object
3780            open c_find_TUR_in_target( l_min_esd,l_max_eed,
3781                                  p_target_business_group_id, nvl(l_tbco_use_rt_id, -999)  ) ;
3782            fetch c_find_TUR_in_target into l_new_value ;
3783            if c_find_TUR_in_target%found then
3784              --
3785              --TEMPIK
3786              l_dt_rec_found :=   dt_api.check_min_max_dates
3787                  (p_base_table_name => 'BEN_TBCO_USE_RT_F',
3788                   p_base_key_column => 'TBCO_USE_RT_ID',
3789                   p_base_key_value  => l_new_value,
3790                   p_from_date       => l_min_esd,
3791                   p_to_date         => l_max_eed );
3792              if l_dt_rec_found THEN
3793              --END TEMPIK
3794              if r_TUR_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
3795                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'TBCO_USE_RT_ID'  then
3796                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'TBCO_USE_RT_ID' ;
3797                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_TUR_unique.information1 ;
3798                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
3799                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
3800                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_TUR_unique.table_route_id;
3801                 --
3802                 -- 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) ;
3803                 --
3804                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
3805              end if ;
3806              --
3807              l_object_found_in_target := true ;
3808              --TEMPIK
3809              end if; -- l_dt_rec_found
3810              --END TEMPIK
3811            end if;
3812            close c_find_TUR_in_target ;
3813          --
3814          end if;
3815        end if ;
3816        --
3817        end if;
3818        close c_TUR_min_max_dates ;
3819        if not l_object_found_in_target OR l_update   then
3820          --
3821          l_current_pk_id := r_TUR.information1;
3822          --
3823          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
3824          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
3825          --
3826          if l_current_pk_id =  l_prev_pk_id  then
3827            --
3828            l_first_rec := false ;
3829            --
3830          else
3831            --
3832            l_first_rec := true ;
3833            --
3834          end if ;
3835          --
3836 
3837          l_effective_date := r_TUR.information2;
3838          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
3839               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
3840            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
3841          end if;
3842 
3843          if l_first_rec and not l_update then
3844            -- Call Create routine.
3845            hr_utility.set_location(' BEN_TBCO_USE_RT_F CREATE_TOBACCO_USE_RATE ',20);
3846            BEN_TOBACCO_USE_RATE_API.CREATE_TOBACCO_USE_RATE(
3847              --
3848              P_VALIDATE               => false
3849              ,P_EFFECTIVE_DATE        => l_effective_date
3850              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
3851              --
3852               ,P_EXCLD_FLAG      => r_TUR.INFORMATION11
3853              ,P_ORDR_NUM      => r_TUR.INFORMATION257
3854              ,P_TBCO_USE_RT_ID      => l_tbco_use_rt_id
3855              ,P_TUR_ATTRIBUTE1      => r_TUR.INFORMATION111
3856              ,P_TUR_ATTRIBUTE10      => r_TUR.INFORMATION120
3857              ,P_TUR_ATTRIBUTE11      => r_TUR.INFORMATION121
3858              ,P_TUR_ATTRIBUTE12      => r_TUR.INFORMATION122
3859              ,P_TUR_ATTRIBUTE13      => r_TUR.INFORMATION123
3860              ,P_TUR_ATTRIBUTE14      => r_TUR.INFORMATION124
3861              ,P_TUR_ATTRIBUTE15      => r_TUR.INFORMATION125
3862              ,P_TUR_ATTRIBUTE16      => r_TUR.INFORMATION126
3863              ,P_TUR_ATTRIBUTE17      => r_TUR.INFORMATION127
3864              ,P_TUR_ATTRIBUTE18      => r_TUR.INFORMATION128
3865              ,P_TUR_ATTRIBUTE19      => r_TUR.INFORMATION129
3866              ,P_TUR_ATTRIBUTE2      => r_TUR.INFORMATION112
3867              ,P_TUR_ATTRIBUTE20      => r_TUR.INFORMATION130
3868              ,P_TUR_ATTRIBUTE21      => r_TUR.INFORMATION131
3869              ,P_TUR_ATTRIBUTE22      => r_TUR.INFORMATION132
3870              ,P_TUR_ATTRIBUTE23      => r_TUR.INFORMATION133
3871              ,P_TUR_ATTRIBUTE24      => r_TUR.INFORMATION134
3872              ,P_TUR_ATTRIBUTE25      => r_TUR.INFORMATION135
3873              ,P_TUR_ATTRIBUTE26      => r_TUR.INFORMATION136
3874              ,P_TUR_ATTRIBUTE27      => r_TUR.INFORMATION137
3875              ,P_TUR_ATTRIBUTE28      => r_TUR.INFORMATION138
3876              ,P_TUR_ATTRIBUTE29      => r_TUR.INFORMATION139
3877              ,P_TUR_ATTRIBUTE3      => r_TUR.INFORMATION113
3878              ,P_TUR_ATTRIBUTE30      => r_TUR.INFORMATION140
3879              ,P_TUR_ATTRIBUTE4      => r_TUR.INFORMATION114
3880              ,P_TUR_ATTRIBUTE5      => r_TUR.INFORMATION115
3881              ,P_TUR_ATTRIBUTE6      => r_TUR.INFORMATION116
3882              ,P_TUR_ATTRIBUTE7      => r_TUR.INFORMATION117
3883              ,P_TUR_ATTRIBUTE8      => r_TUR.INFORMATION118
3884              ,P_TUR_ATTRIBUTE9      => r_TUR.INFORMATION119
3885              ,P_TUR_ATTRIBUTE_CATEGORY      => r_TUR.INFORMATION110
3886              ,P_USES_TBCO_FLAG      => r_TUR.INFORMATION12
3887              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
3888              --
3889              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
3890              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
3891              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
3892            );
3893            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
3894            -- Update all relevent cer records with new pk_id
3895            hr_utility.set_location('Before plsql table ',222);
3896            hr_utility.set_location('new_value id '||l_tbco_use_rt_id,222);
3897            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'TBCO_USE_RT_ID' ;
3898            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_TUR.information1 ;
3899            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_TBCO_USE_RT_ID ;
3900            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
3901            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_TUR_unique.table_route_id;
3902            hr_utility.set_location('After plsql table ',222);
3903            --
3904            -- 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 ) ;
3905            --
3906            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
3907            --
3908          else
3909            --
3910            -- Call Update routine for the pk_id created in prev run .
3911            --UPD START
3912            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
3913            --
3914            if l_update then
3915              --
3916              l_datetrack_mode := r_TUR.datetrack_mode ;
3917              --
3918              get_dt_modes(
3919                p_effective_date        => l_process_date,
3920                p_effective_end_date    => r_TUR.information3,
3921                p_effective_start_date  => r_TUR.information2,
3922                p_dml_operation         => r_TUR.dml_operation,
3923                p_datetrack_mode        => l_datetrack_mode );
3924            --    p_update                => l_update
3925              --
3926              l_effective_date := l_process_date;
3927              l_TBCO_USE_RT_ID   := r_TUR.information1;
3928              l_object_version_number := r_TUR.information265;
3929              --
3930            end if;
3931            --
3932            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
3933            --
3934            IF l_update OR l_dml_operation <> 'UPDATE' THEN
3935            --UPD END
3936            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
3937            hr_utility.set_location(' BEN_TBCO_USE_RT_F UPDATE_TOBACCO_USE_RATE ',30);
3938            BEN_TOBACCO_USE_RATE_API.UPDATE_TOBACCO_USE_RATE(
3939              --
3940              P_VALIDATE               => false
3941              ,P_EFFECTIVE_DATE        => l_effective_date
3942              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
3943              --
3944              ,P_EXCLD_FLAG      => r_TUR.INFORMATION11
3945              ,P_ORDR_NUM      => r_TUR.INFORMATION257
3946              ,P_TBCO_USE_RT_ID      => l_tbco_use_rt_id
3947              ,P_TUR_ATTRIBUTE1      => r_TUR.INFORMATION111
3948              ,P_TUR_ATTRIBUTE10      => r_TUR.INFORMATION120
3949              ,P_TUR_ATTRIBUTE11      => r_TUR.INFORMATION121
3950              ,P_TUR_ATTRIBUTE12      => r_TUR.INFORMATION122
3951              ,P_TUR_ATTRIBUTE13      => r_TUR.INFORMATION123
3952              ,P_TUR_ATTRIBUTE14      => r_TUR.INFORMATION124
3953              ,P_TUR_ATTRIBUTE15      => r_TUR.INFORMATION125
3954              ,P_TUR_ATTRIBUTE16      => r_TUR.INFORMATION126
3955              ,P_TUR_ATTRIBUTE17      => r_TUR.INFORMATION127
3956              ,P_TUR_ATTRIBUTE18      => r_TUR.INFORMATION128
3957              ,P_TUR_ATTRIBUTE19      => r_TUR.INFORMATION129
3958              ,P_TUR_ATTRIBUTE2      => r_TUR.INFORMATION112
3959              ,P_TUR_ATTRIBUTE20      => r_TUR.INFORMATION130
3960              ,P_TUR_ATTRIBUTE21      => r_TUR.INFORMATION131
3961              ,P_TUR_ATTRIBUTE22      => r_TUR.INFORMATION132
3962              ,P_TUR_ATTRIBUTE23      => r_TUR.INFORMATION133
3963              ,P_TUR_ATTRIBUTE24      => r_TUR.INFORMATION134
3964              ,P_TUR_ATTRIBUTE25      => r_TUR.INFORMATION135
3965              ,P_TUR_ATTRIBUTE26      => r_TUR.INFORMATION136
3966              ,P_TUR_ATTRIBUTE27      => r_TUR.INFORMATION137
3967              ,P_TUR_ATTRIBUTE28      => r_TUR.INFORMATION138
3968              ,P_TUR_ATTRIBUTE29      => r_TUR.INFORMATION139
3969              ,P_TUR_ATTRIBUTE3      => r_TUR.INFORMATION113
3970              ,P_TUR_ATTRIBUTE30      => r_TUR.INFORMATION140
3971              ,P_TUR_ATTRIBUTE4      => r_TUR.INFORMATION114
3972              ,P_TUR_ATTRIBUTE5      => r_TUR.INFORMATION115
3973              ,P_TUR_ATTRIBUTE6      => r_TUR.INFORMATION116
3974              ,P_TUR_ATTRIBUTE7      => r_TUR.INFORMATION117
3975              ,P_TUR_ATTRIBUTE8      => r_TUR.INFORMATION118
3976              ,P_TUR_ATTRIBUTE9      => r_TUR.INFORMATION119
3977              ,P_TUR_ATTRIBUTE_CATEGORY      => r_TUR.INFORMATION110
3978              ,P_USES_TBCO_FLAG      => r_TUR.INFORMATION12
3979              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
3980              --
3981              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
3982              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
3983              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
3984              ,P_DATETRACK_MODE        => l_datetrack_mode
3985            );
3986            --
3987            end if;
3988          end if;
3989          --
3990          -- Delete the row if it is end dated.
3991          --
3992          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
3993              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
3994              trunc(l_max_eed) = r_TUR.information3) then
3995              --
3996              BEN_TOBACCO_USE_RATE_API.delete_TOBACCO_USE_RATE(
3997                 --
3998                 p_validate                       => false
3999                 ,p_tbco_use_rt_id                   => l_tbco_use_rt_id
4000                 ,p_effective_start_date           => l_effective_start_date
4001                 ,p_effective_end_date             => l_effective_end_date
4002                 ,p_object_version_number          => l_object_version_number
4003                 ,p_effective_date                 => l_max_eed
4004                 ,p_datetrack_mode                 => hr_api.g_delete
4005                 --
4006                 );
4007                 --
4008          end if;
4009          --
4010          l_prev_pk_id := l_current_pk_id ;
4011          --
4012        end if;
4013        --
4014      end if;
4015      --
4016    end loop;
4017    --
4018  exception when others then
4019     --
4020     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'TUR',r_tur.information5 );
4021     --
4022  end create_TUR_rows;
4023 
4024    --
4025    ---------------------------------------------------------------
4026    ----------------------< create_SAR_rows >-----------------------
4027    ---------------------------------------------------------------
4028    --
4029    procedure create_SAR_rows
4030    (
4031          p_validate                       in  number     default 0
4032         ,p_copy_entity_txn_id             in  number
4033         ,p_effective_date                 in  date
4034         ,p_prefix_suffix_text             in  varchar2  default null
4035         ,p_reuse_object_flag              in  varchar2  default null
4036         ,p_target_business_group_id       in  varchar2  default null
4037         ,p_prefix_suffix_cd               in  varchar2  default null
4038    ) is
4039    --
4040    l_SVC_AREA_ID  number;
4041    l_VRBL_RT_PRFL_ID  number;
4042    l_EXCLD_FLAG       varchar2(100);
4043    l_ORDR_NUM         number;
4044    --
4045    cursor c_unique_SAR(l_table_alias varchar2) is
4046    select distinct cpe.information1,
4047      cpe.information2,
4048      cpe.information3,
4049      cpe.table_route_id
4050    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
4051         pqh_table_route tr
4052    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
4053    and   cpe.table_route_id     = tr.table_route_id
4054    -- and   tr.where_clause        = l_BEN_SVC_AREA_RT_F
4055    and tr.table_alias = l_table_alias
4056    and   cpe.number_of_copies   = 1 -- ADDITION
4057    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
4058    order by information1, information2; --added for bug: 5151945
4059    --
4060    --
4061    cursor c_SAR_min_max_dates(c_table_route_id  number,
4062                 c_information1   Number) is
4063    select
4064      min(cpe.information2) min_esd,
4065      max(cpe.information3) min_eed
4066    from ben_copy_entity_results cpe
4067    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
4068    and   cpe.table_route_id     = c_table_route_id
4069    and   cpe.information1       = c_information1 ;
4070    --
4071    cursor c_SAR(c_table_route_id  number,
4072                 c_information1   number,
4073                 c_information2   Date,
4074                 c_information3   Date )  is
4075    select
4076      cpe.*
4077    from ben_copy_entity_results cpe
4078    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
4079    and   cpe.table_route_id     = c_table_route_id
4080    and   cpe.information1       = c_information1
4081    and   cpe.information2       = c_information2
4082    and   cpe.information3       = c_information3
4083    and rownum = 1 ;
4084    -- Date Track target record
4085    cursor c_find_SAR_in_target(
4086                                 c_effective_start_date    date,
4087                                 c_effective_end_date      date,
4088                                 c_business_group_id       number,
4089                                 c_new_pk_id               number) is
4090    select
4091      SAR.svc_area_rt_id new_value
4092    from BEN_SVC_AREA_RT_F SAR
4093    where
4094    SAR.SVC_AREA_ID     = l_SVC_AREA_ID  and
4095    SAR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
4096    SAR.ORDR_NUM           = l_ORDR_NUM and
4097    SAR.business_group_id  = c_business_group_id
4098    and   SAR.svc_area_rt_id  <> c_new_pk_id
4099 --TEMPIK
4100    and c_effective_start_date between effective_start_date
4101                             and effective_end_date ;
4102 --END TEMPIK
4103 /*TEMPIK
4104    and exists ( select null
4105                 from BEN_SVC_AREA_RT_F SAR1
4106                 where
4107                 SAR1.SVC_AREA_ID     = l_SVC_AREA_ID  and
4108                 SAR1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
4109                 SAR1.ORDR_NUM           = l_ORDR_NUM and
4110                 SAR1.business_group_id  = c_business_group_id
4111                 and   SAR1.effective_start_date <= c_effective_start_date )
4112    and exists ( select null
4113                 from BEN_SVC_AREA_RT_F SAR2
4114                 where
4115                 SAR2.SVC_AREA_ID     = l_SVC_AREA_ID  and
4116                 SAR2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
4117                 SAR2.ORDR_NUM           = l_ORDR_NUM and
4118                 SAR2.business_group_id  = c_business_group_id
4119                 and   SAR2.effective_end_date >= c_effective_end_date )
4120                 ;
4121 TEMPIK */
4122    --TEMPIK
4123    l_dt_rec_found            boolean ;
4124    --END TEMPIK
4125    --
4126    l_current_pk_id           number := null ;
4127    --UPD START
4128    --
4129    l_update                  boolean      := false ;
4130    l_datetrack_mode          varchar2(80) := hr_api.g_update;
4131    l_process_date            date;
4132    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
4133    --
4134    --UPD END
4135    l_prev_pk_id              number := null ;
4136    l_first_rec               boolean := true ;
4137    r_SAR                     c_SAR%rowtype;
4138    l_svc_area_rt_id             number ;
4139    l_object_version_number   number ;
4140    l_effective_start_date    date ;
4141    l_effective_end_date      date ;
4142    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
4143    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
4144    l_new_value               number(15);
4145    l_object_found_in_target  boolean := false ;
4146    l_min_esd                 date;
4147    l_max_eed                 date;
4148    l_effective_date          date;
4149    --
4150  begin
4151    -- Initialization
4152    l_object_found_in_target := false ;
4153    -- End Initialization
4154    -- Derive the prefix - sufix
4155    if   p_prefix_suffix_cd = 'PREFIX' then
4156      l_prefix  := p_prefix_suffix_text ;
4157    elsif p_prefix_suffix_cd = 'SUFFIX' then
4158      l_suffix   := p_prefix_suffix_text ;
4159    else
4160      l_prefix := null ;
4161      l_suffix  := null ;
4162    end if ;
4163    -- End Prefix Sufix derivation
4164    for r_SAR_unique in c_unique_SAR('SAR') loop
4165 
4166      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
4167         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
4168          r_SAR_unique.information3 >=
4169                  ben_pd_copy_to_ben_one.g_copy_effective_date)
4170         ) then
4171        --
4172        hr_utility.set_location(' r_SAR_unique.table_route_id '||r_SAR_unique.table_route_id,10);
4173        hr_utility.set_location(' r_SAR_unique.information1 '||r_SAR_unique.information1,10);
4174        hr_utility.set_location( 'r_SAR_unique.information2 '||r_SAR_unique.information2,10);
4175        hr_utility.set_location( 'r_SAR_unique.information3 '||r_SAR_unique.information3,10);
4176        -- If reuse objects flag is 'Y' then check for the object in the target business group
4177        -- if found insert the record into PLSql table and exit the loop else try create the
4178        -- object in the target business group
4179        --
4180        l_object_found_in_target := false ;
4181        l_min_esd := null ;
4182        l_max_eed := null ;
4183        open c_SAR_min_max_dates(r_SAR_unique.table_route_id, r_SAR_unique.information1 ) ;
4184        fetch c_SAR_min_max_dates into l_min_esd,l_max_eed ;
4185        --
4186 
4187        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
4188             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
4189          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
4190        end if;
4191        l_min_esd := greatest(l_min_esd,r_SAR_unique.information2);
4192        open c_SAR(r_SAR_unique.table_route_id,
4193                 r_SAR_unique.information1,
4194                 r_SAR_unique.information2,
4195                 r_SAR_unique.information3 ) ;
4196        --
4197        fetch c_SAR into r_SAR ;
4198        --
4199        close c_SAR ;
4200        --
4201        l_SVC_AREA_ID := get_fk('SVC_AREA_ID', r_SAR.INFORMATION241,r_SAR_unique.dml_operation);
4202        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_SAR.INFORMATION262,r_SAR_unique.dml_operation);
4203        l_ORDR_NUM         := r_SAR.INFORMATION259;
4204        l_EXCLD_FLAG      := r_SAR.information11;
4205        --UPD START
4206        l_update := false;
4207        l_process_date := p_effective_date;
4208        l_dml_operation:= r_SAR_unique.dml_operation ;
4209        --
4210        if l_dml_operation = 'UPDATE' then
4211          --
4212          l_object_found_in_target := TRUE;
4213          --
4214          if l_process_date between r_SAR_unique.information2 and r_SAR_unique.information3 then
4215                l_update := true;
4216                if r_SAR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
4217                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'SVC_AREA_RT_ID'
4218                then
4219                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'SVC_AREA_RT_ID' ;
4220                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_SAR_unique.information1 ;
4221                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_SAR_unique.information1 ;
4222                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
4223                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_SAR_unique.table_route_id;
4224                   --
4225                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
4226                   --
4227                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
4228                   --
4229                   -- log_data('SAR',l_new_value,l_prefix || r_SAR_unique.name|| l_suffix,'REUSED');
4230                   --
4231                end if ;
4232                hr_utility.set_location( 'found record for update',10);
4233            --
4234          else
4235            --
4236            l_update := false;
4237            --
4238          end if;
4239        else
4240          --
4241          --UPD END
4242        if p_reuse_object_flag = 'Y' then
4243          if c_SAR_min_max_dates%found then
4244            -- cursor to find the object
4245            open c_find_SAR_in_target( l_min_esd,l_max_eed,
4246                                  p_target_business_group_id, nvl(l_svc_area_rt_id, -999)  ) ;
4247            fetch c_find_SAR_in_target into l_new_value ;
4248            if c_find_SAR_in_target%found then
4249              --
4250              --TEMPIK
4251              l_dt_rec_found :=   dt_api.check_min_max_dates
4252                  (p_base_table_name => 'BEN_SVC_AREA_RT_F',
4253                   p_base_key_column => 'SVC_AREA_RT_ID',
4254                   p_base_key_value  => l_new_value,
4255                   p_from_date       => l_min_esd,
4256                   p_to_date         => l_max_eed );
4257              if l_dt_rec_found THEN
4258              --END TEMPIK
4259              if r_SAR_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
4260                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'SVC_AREA_RT_ID'  then
4261                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'SVC_AREA_RT_ID' ;
4262                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_SAR_unique.information1 ;
4263                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
4264                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
4265                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_SAR_unique.table_route_id;
4266                 --
4267                 -- 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) ;
4268                 --
4269                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
4270              end if ;
4271              --
4272              l_object_found_in_target := true ;
4273              --TEMPIK
4274              end if; -- l_dt_rec_found
4275              --END TEMPIK
4276            end if;
4277            close c_find_SAR_in_target ;
4278          --
4279          end if;
4280        end if ;
4281        end if;
4282        --
4283        close c_SAR_min_max_dates ;
4284        if not l_object_found_in_target OR l_update   then
4285          --
4286          l_current_pk_id := r_SAR.information1;
4287          --
4288          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
4289          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
4290          --
4291          if l_current_pk_id =  l_prev_pk_id  then
4292            --
4293            l_first_rec := false ;
4294            --
4295          else
4296            --
4297            l_first_rec := true ;
4298            --
4299          end if ;
4300          --
4301 
4302          l_effective_date := r_SAR.information2;
4303          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
4304               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
4305            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
4306          end if;
4307 
4308          if l_first_rec and not l_update then
4309            -- Call Create routine.
4310            hr_utility.set_location(' BEN_SVC_AREA_RT_F CREATE_SERVICE_AREA_RATE ',20);
4311            BEN_SERVICE_AREA_RATE_API.CREATE_SERVICE_AREA_RATE(
4312              --
4313              P_VALIDATE               => false
4314              ,P_EFFECTIVE_DATE        => l_effective_date
4315              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
4316              --
4317              ,P_EXCLD_FLAG      => r_SAR.INFORMATION11
4318              ,P_ORDR_NUM      => r_SAR.INFORMATION259
4319              ,P_SAR_ATTRIBUTE1      => r_SAR.INFORMATION111
4320              ,P_SAR_ATTRIBUTE10      => r_SAR.INFORMATION120
4321              ,P_SAR_ATTRIBUTE11      => r_SAR.INFORMATION121
4322              ,P_SAR_ATTRIBUTE12      => r_SAR.INFORMATION122
4323              ,P_SAR_ATTRIBUTE13      => r_SAR.INFORMATION123
4324              ,P_SAR_ATTRIBUTE14      => r_SAR.INFORMATION124
4325              ,P_SAR_ATTRIBUTE15      => r_SAR.INFORMATION125
4326              ,P_SAR_ATTRIBUTE16      => r_SAR.INFORMATION126
4327              ,P_SAR_ATTRIBUTE17      => r_SAR.INFORMATION127
4328              ,P_SAR_ATTRIBUTE18      => r_SAR.INFORMATION128
4329              ,P_SAR_ATTRIBUTE19      => r_SAR.INFORMATION129
4330              ,P_SAR_ATTRIBUTE2      => r_SAR.INFORMATION112
4331              ,P_SAR_ATTRIBUTE20      => r_SAR.INFORMATION130
4332              ,P_SAR_ATTRIBUTE21      => r_SAR.INFORMATION131
4333              ,P_SAR_ATTRIBUTE22      => r_SAR.INFORMATION132
4334              ,P_SAR_ATTRIBUTE23      => r_SAR.INFORMATION133
4335              ,P_SAR_ATTRIBUTE24      => r_SAR.INFORMATION134
4336              ,P_SAR_ATTRIBUTE25      => r_SAR.INFORMATION135
4337              ,P_SAR_ATTRIBUTE26      => r_SAR.INFORMATION136
4338              ,P_SAR_ATTRIBUTE27      => r_SAR.INFORMATION137
4339              ,P_SAR_ATTRIBUTE28      => r_SAR.INFORMATION138
4340              ,P_SAR_ATTRIBUTE29      => r_SAR.INFORMATION139
4341              ,P_SAR_ATTRIBUTE3      => r_SAR.INFORMATION113
4342              ,P_SAR_ATTRIBUTE30      => r_SAR.INFORMATION140
4343              ,P_SAR_ATTRIBUTE4      => r_SAR.INFORMATION114
4344              ,P_SAR_ATTRIBUTE5      => r_SAR.INFORMATION115
4345              ,P_SAR_ATTRIBUTE6      => r_SAR.INFORMATION116
4346              ,P_SAR_ATTRIBUTE7      => r_SAR.INFORMATION117
4347              ,P_SAR_ATTRIBUTE8      => r_SAR.INFORMATION118
4348              ,P_SAR_ATTRIBUTE9      => r_SAR.INFORMATION119
4349              ,P_SAR_ATTRIBUTE_CATEGORY      => r_SAR.INFORMATION110
4350              ,P_SVC_AREA_ID      => l_SVC_AREA_ID
4351              ,P_SVC_AREA_RT_ID      => l_svc_area_rt_id
4352              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
4353              --
4354              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
4355              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
4356              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
4357            );
4358            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
4359            -- Update all relevent cer records with new pk_id
4360            hr_utility.set_location('Before plsql table ',222);
4361            hr_utility.set_location('new_value id '||l_svc_area_rt_id,222);
4362            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'SVC_AREA_RT_ID' ;
4363            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_SAR.information1 ;
4364            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_SVC_AREA_RT_ID ;
4365            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
4366            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_SAR_unique.table_route_id;
4367            hr_utility.set_location('After plsql table ',222);
4368            --
4369            -- 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 ) ;
4370            --
4371            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
4372            --
4373          else
4374            --
4375            -- Call Update routine for the pk_id created in prev run .
4376            --UPD START
4377            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
4378            --
4379            if l_update then
4380              --
4381              l_datetrack_mode := r_SAR.datetrack_mode ;
4382              --
4383              get_dt_modes(
4384                p_effective_date        => l_process_date,
4385                p_effective_end_date    => r_SAR.information3,
4386                p_effective_start_date  => r_SAR.information2,
4387                p_dml_operation         => r_SAR.dml_operation,
4388                p_datetrack_mode        => l_datetrack_mode );
4389            --    p_update                => l_update
4390              --
4391              l_effective_date := l_process_date;
4392              l_SVC_AREA_RT_ID   := r_SAR.information1;
4393              l_object_version_number := r_SAR.information265;
4394              --
4395            end if;
4396            --
4397            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
4398            --
4399            IF l_update OR l_dml_operation <> 'UPDATE' THEN
4400            --UPD END
4401            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
4402            hr_utility.set_location(' BEN_SVC_AREA_RT_F UPDATE_SERVICE_AREA_RATE ',30);
4403            BEN_SERVICE_AREA_RATE_API.UPDATE_SERVICE_AREA_RATE(
4404              --
4405              P_VALIDATE               => false
4406              ,P_EFFECTIVE_DATE        => l_effective_date
4407              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
4408              --
4409              ,P_EXCLD_FLAG      => r_SAR.INFORMATION11
4410              ,P_ORDR_NUM      => r_SAR.INFORMATION259
4411              ,P_SAR_ATTRIBUTE1      => r_SAR.INFORMATION111
4412              ,P_SAR_ATTRIBUTE10      => r_SAR.INFORMATION120
4413              ,P_SAR_ATTRIBUTE11      => r_SAR.INFORMATION121
4414              ,P_SAR_ATTRIBUTE12      => r_SAR.INFORMATION122
4415              ,P_SAR_ATTRIBUTE13      => r_SAR.INFORMATION123
4416              ,P_SAR_ATTRIBUTE14      => r_SAR.INFORMATION124
4417              ,P_SAR_ATTRIBUTE15      => r_SAR.INFORMATION125
4418              ,P_SAR_ATTRIBUTE16      => r_SAR.INFORMATION126
4419              ,P_SAR_ATTRIBUTE17      => r_SAR.INFORMATION127
4420              ,P_SAR_ATTRIBUTE18      => r_SAR.INFORMATION128
4421              ,P_SAR_ATTRIBUTE19      => r_SAR.INFORMATION129
4422              ,P_SAR_ATTRIBUTE2      => r_SAR.INFORMATION112
4423              ,P_SAR_ATTRIBUTE20      => r_SAR.INFORMATION130
4424              ,P_SAR_ATTRIBUTE21      => r_SAR.INFORMATION131
4425              ,P_SAR_ATTRIBUTE22      => r_SAR.INFORMATION132
4426              ,P_SAR_ATTRIBUTE23      => r_SAR.INFORMATION133
4427              ,P_SAR_ATTRIBUTE24      => r_SAR.INFORMATION134
4428              ,P_SAR_ATTRIBUTE25      => r_SAR.INFORMATION135
4429              ,P_SAR_ATTRIBUTE26      => r_SAR.INFORMATION136
4430              ,P_SAR_ATTRIBUTE27      => r_SAR.INFORMATION137
4431              ,P_SAR_ATTRIBUTE28      => r_SAR.INFORMATION138
4432              ,P_SAR_ATTRIBUTE29      => r_SAR.INFORMATION139
4433              ,P_SAR_ATTRIBUTE3      => r_SAR.INFORMATION113
4434              ,P_SAR_ATTRIBUTE30      => r_SAR.INFORMATION140
4435              ,P_SAR_ATTRIBUTE4      => r_SAR.INFORMATION114
4436              ,P_SAR_ATTRIBUTE5      => r_SAR.INFORMATION115
4437              ,P_SAR_ATTRIBUTE6      => r_SAR.INFORMATION116
4438              ,P_SAR_ATTRIBUTE7      => r_SAR.INFORMATION117
4439              ,P_SAR_ATTRIBUTE8      => r_SAR.INFORMATION118
4440              ,P_SAR_ATTRIBUTE9      => r_SAR.INFORMATION119
4441              ,P_SAR_ATTRIBUTE_CATEGORY      => r_SAR.INFORMATION110
4442              ,P_SVC_AREA_ID      => l_SVC_AREA_ID
4443              ,P_SVC_AREA_RT_ID      => l_svc_area_rt_id
4444              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
4445              --
4446              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
4447              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
4448              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
4449              ,P_DATETRACK_MODE        => l_datetrack_mode
4450            );
4451            --
4452            end if;
4453          end if;
4454          --
4455          -- Delete the row if it is end dated.
4456          --
4457          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
4458              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
4459              trunc(l_max_eed) = r_SAR.information3) then
4460              --
4461              BEN_SERVICE_AREA_RATE_API.delete_SERVICE_AREA_RATE(
4462                 --
4463                 p_validate                       => false
4464                 ,p_svc_area_rt_id                   => l_svc_area_rt_id
4465                 ,p_effective_start_date           => l_effective_start_date
4466                 ,p_effective_end_date             => l_effective_end_date
4467                 ,p_object_version_number          => l_object_version_number
4468                 ,p_effective_date                 => l_max_eed
4469                 ,p_datetrack_mode                 => hr_api.g_delete
4470                 --
4471                 );
4472                 --
4473          end if;
4474          --
4475          l_prev_pk_id := l_current_pk_id ;
4476          --
4477        end if;
4478        --
4479      end if;
4480      --
4481    end loop;
4482    --
4483  exception when others then
4484     --
4485     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'SAR',r_sar.information5 );
4486     --
4487  end create_SAR_rows;
4488 
4489    --
4490    ---------------------------------------------------------------
4491    ----------------------< create_QTR_rows >-----------------------
4492    ---------------------------------------------------------------
4493    --
4494    procedure create_QTR_rows
4495    (
4496          p_validate                       in  number     default 0
4497         ,p_copy_entity_txn_id             in  number
4498         ,p_effective_date                 in  date
4499         ,p_prefix_suffix_text             in  varchar2  default null
4500         ,p_reuse_object_flag              in  varchar2  default null
4501         ,p_target_business_group_id       in  varchar2  default null
4502         ,p_prefix_suffix_cd               in  varchar2  default null
4503    ) is
4504    --
4505    l_QUALIFICATION_TYPE_ID  number;
4506    l_VRBL_RT_PRFL_ID  number;
4507    l_EXCLD_FLAG       varchar2(100);
4508    l_ORDR_NUM         number;
4509    --
4510    cursor c_unique_QTR(l_table_alias varchar2) is
4511    select distinct cpe.information1,
4512      cpe.information2,
4513      cpe.information3,
4514      cpe.table_route_id
4515    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
4516         pqh_table_route tr
4517    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
4518    and   cpe.table_route_id     = tr.table_route_id
4519    -- and   tr.where_clause        = l_BEN_QUAL_TITL_RT_F
4520    and tr.table_alias = l_table_alias
4521    and   cpe.number_of_copies   = 1 -- ADDITION
4522    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
4523    order by information1, information2; --added for bug: 5151945
4524    --
4525    --
4526    cursor c_QTR_min_max_dates(c_table_route_id  number,
4527                 c_information1   Number) is
4528    select
4529      min(cpe.information2) min_esd,
4530      max(cpe.information3) min_eed
4531    from ben_copy_entity_results cpe
4532    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
4533    and   cpe.table_route_id     = c_table_route_id
4534    and   cpe.information1       = c_information1 ;
4535    --
4536    cursor c_QTR(c_table_route_id  number,
4537                 c_information1   number,
4538                 c_information2   Date,
4539                 c_information3   Date )  is
4540    select
4541      cpe.*
4542    from ben_copy_entity_results cpe
4543    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
4544    and   cpe.table_route_id     = c_table_route_id
4545    and   cpe.information1       = c_information1
4546    and   cpe.information2       = c_information2
4547    and   cpe.information3       = c_information3
4548    and rownum = 1 ;
4549    -- Date Track target record
4550    cursor c_find_QTR_in_target(
4551                                 c_effective_start_date    date,
4552                                 c_effective_end_date      date,
4553                                 c_business_group_id       number,
4554                                 c_new_pk_id               number) is
4555    select
4556      QTR.qual_titl_rt_id new_value
4557    from BEN_QUAL_TITL_RT_F QTR
4558    where
4559    QTR.QUALIFICATION_TYPE_ID     = l_QUALIFICATION_TYPE_ID  and
4560    QTR.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
4561    QTR.ORDR_NUM           = l_ORDR_NUM and
4562    QTR.business_group_id  = c_business_group_id
4563    and   QTR.qual_titl_rt_id  <> c_new_pk_id
4564 --TEMPIK
4565    and c_effective_start_date between effective_start_date
4566                             and effective_end_date ;
4567 --END TEMPIK
4568 /*TEMPIK
4569    and exists ( select null
4570                 from BEN_QUAL_TITL_RT_F QTR1
4571                 where
4572                 QTR1.QUALIFICATION_TYPE_ID     = l_QUALIFICATION_TYPE_ID  and
4573                 QTR1.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
4574                 QTR1.ORDR_NUM           = l_ORDR_NUM and
4575                 QTR1.business_group_id  = c_business_group_id
4576                 and   QTR1.effective_start_date <= c_effective_start_date )
4577    and exists ( select null
4578                 from BEN_QUAL_TITL_RT_F QTR2
4579                 where
4580                 QTR2.QUALIFICATION_TYPE_ID     = l_QUALIFICATION_TYPE_ID  and
4581                 QTR2.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
4582                 QTR2.ORDR_NUM           = l_ORDR_NUM and
4583                 QTR2.business_group_id  = c_business_group_id
4584                 and   QTR2.effective_end_date >= c_effective_end_date )
4585                 ;
4586 TEMPIK */
4587    --TEMPIK
4588    l_dt_rec_found            boolean ;
4589    --END TEMPIK
4590    --
4591    l_current_pk_id           number := null ;
4592    --UPD START
4593    --
4594    l_update                  boolean      := false ;
4595    l_datetrack_mode          varchar2(80) := hr_api.g_update;
4596    l_process_date            date;
4597    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
4598    --
4599    --UPD END
4600    l_prev_pk_id              number := null ;
4601    l_first_rec               boolean := true ;
4602    r_QTR                     c_QTR%rowtype;
4603    l_qual_titl_rt_id             number ;
4604    l_object_version_number   number ;
4605    l_effective_start_date    date ;
4606    l_effective_end_date      date ;
4607    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
4608    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
4609    l_new_value               number(15);
4610    l_object_found_in_target  boolean := false ;
4611    l_min_esd                 date;
4612    l_max_eed                 date;
4613    l_effective_date          date;
4614    --
4615  begin
4616    -- Initialization
4617    l_object_found_in_target := false ;
4618    -- End Initialization
4619    -- Derive the prefix - sufix
4620    if   p_prefix_suffix_cd = 'PREFIX' then
4621      l_prefix  := p_prefix_suffix_text ;
4622    elsif p_prefix_suffix_cd = 'SUFFIX' then
4623      l_suffix   := p_prefix_suffix_text ;
4624    else
4625      l_prefix := null ;
4626      l_suffix  := null ;
4627    end if ;
4628    -- End Prefix Sufix derivation
4629    for r_QTR_unique in c_unique_QTR('QTR') loop
4630 
4631      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
4632         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
4633          r_QTR_unique.information3 >=
4634                  ben_pd_copy_to_ben_one.g_copy_effective_date)
4635         ) then
4636        --
4637        hr_utility.set_location(' r_QTR_unique.table_route_id '||r_QTR_unique.table_route_id,10);
4638        hr_utility.set_location(' r_QTR_unique.information1 '||r_QTR_unique.information1,10);
4639        hr_utility.set_location( 'r_QTR_unique.information2 '||r_QTR_unique.information2,10);
4640        hr_utility.set_location( 'r_QTR_unique.information3 '||r_QTR_unique.information3,10);
4641        -- If reuse objects flag is 'Y' then check for the object in the target business group
4642        -- if found insert the record into PLSql table and exit the loop else try create the
4643        -- object in the target business group
4644        --
4645        l_object_found_in_target := false ;
4646        l_min_esd := null ;
4647        l_max_eed := null ;
4648        open c_QTR_min_max_dates(r_QTR_unique.table_route_id, r_QTR_unique.information1 ) ;
4649        fetch c_QTR_min_max_dates into l_min_esd,l_max_eed ;
4650        --
4651 
4652        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
4653             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
4654          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
4655        end if;
4656        l_min_esd := greatest(l_min_esd,r_QTR_unique.information2);
4657        open c_QTR(r_QTR_unique.table_route_id,
4658                 r_QTR_unique.information1,
4659                 r_QTR_unique.information2,
4660                 r_QTR_unique.information3 ) ;
4661        --
4662        fetch c_QTR into r_QTR ;
4663        --
4664        close c_QTR ;
4665        --
4666        if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
4667          l_QUALIFICATION_TYPE_ID := r_QTR.information176;
4668        else
4669          l_QUALIFICATION_TYPE_ID := r_QTR.information174;
4670        end if;
4671        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_QTR.INFORMATION262,r_QTR_unique.dml_operation);
4672        l_ORDR_NUM         := r_QTR.INFORMATION260;
4673        l_EXCLD_FLAG      := r_QTR.information11;
4674 
4675        if l_QUALIFICATION_TYPE_ID is null then
4676          close c_QTR_min_max_dates;
4677          log_nomapping_data(p_parent_table_alias =>'VPF'
4678                      ,p_parent_pk_id         => r_QTR.information262
4679                      ,p_copy_entity_txn_id   => p_copy_entity_txn_id
4680                      ,p_child_table_alias    => 'QTR'
4681                      ,p_child_data           => r_QTR.information173 );
4682        else
4683        --UPD START
4684        l_update := false;
4685        l_process_date := p_effective_date;
4686        l_dml_operation:= r_QTR_unique.dml_operation ;
4687        --
4688        if l_dml_operation = 'UPDATE' then
4689          --
4690          l_object_found_in_target := TRUE;
4691          --
4692          if l_process_date between r_QTR_unique.information2 and r_QTR_unique.information3 then
4693                l_update := true;
4694                if r_QTR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
4695                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'QUAL_TITL_RT_ID'
4696                then
4697                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'QUAL_TITL_RT_ID' ;
4698                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_QTR_unique.information1 ;
4699                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_QTR_unique.information1 ;
4700                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
4701                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_QTR_unique.table_route_id;
4702                   --
4703                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
4704                   --
4705                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
4706                   --
4707                   -- log_data('QTR',l_new_value,l_prefix || r_QTR_unique.name|| l_suffix,'REUSED');
4708                   --
4709                end if ;
4710                hr_utility.set_location( 'found record for update',10);
4711            --
4712          else
4713            --
4714            l_update := false;
4715            --
4716          end if;
4717        else
4718          --
4719          --UPD END
4720          if p_reuse_object_flag = 'Y' then
4721             if c_QTR_min_max_dates%found then
4722               -- cursor to find the object
4723               open c_find_QTR_in_target( l_min_esd,l_max_eed,
4724                                     p_target_business_group_id, nvl(l_qual_titl_rt_id, -999)  ) ;
4725               fetch c_find_QTR_in_target into l_new_value ;
4726               if c_find_QTR_in_target%found then
4727                 --
4728              --TEMPIK
4729              l_dt_rec_found :=   dt_api.check_min_max_dates
4730                  (p_base_table_name => 'BEN_QUAL_TITL_RT_F',
4731                   p_base_key_column => 'QUAL_TITL_RT_ID',
4732                   p_base_key_value  => l_new_value,
4733                   p_from_date       => l_min_esd,
4734                   p_to_date         => l_max_eed );
4735              if l_dt_rec_found THEN
4736              --END TEMPIK
4737                 if r_QTR_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
4738                    nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'QUAL_TITL_RT_ID'  then
4739                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'QUAL_TITL_RT_ID' ;
4740                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_QTR_unique.information1 ;
4741                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
4742                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
4743                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_QTR_unique.table_route_id;
4744                    --
4745                    -- 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) ;
4746                    --
4747                    BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
4748                 end if ;
4749                 --
4750                 l_object_found_in_target := true ;
4751              --TEMPIK
4752              end if; -- l_dt_rec_found
4753              --END TEMPIK
4754               end if;
4755               close c_find_QTR_in_target ;
4756             --
4757             end if;
4758          end if ;
4759          end if;
4760          --
4761          close c_QTR_min_max_dates ;
4762          if not l_object_found_in_target OR l_update   then
4763            --
4764            l_current_pk_id := r_QTR.information1;
4765            --
4766            hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
4767            hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
4768            --
4769            if l_current_pk_id =  l_prev_pk_id  then
4770              --
4771              l_first_rec := false ;
4772              --
4773            else
4774              --
4775              l_first_rec := true ;
4776              --
4777            end if ;
4778            --
4779 
4780            l_effective_date := r_QTR.information2;
4781            if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
4782                 l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
4783              l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
4784            end if;
4785 
4786            if l_first_rec and not l_update then
4787              -- Call Create routine.
4788              hr_utility.set_location(' BEN_QUAL_TITL_RT_F CREATE_QUAL_TITL_RT ',20);
4789              BEN_QUAL_TITL_RT_API.CREATE_QUAL_TITL_RT(
4790                 --
4791                 P_VALIDATE               => false
4792                 ,P_EFFECTIVE_DATE        => l_effective_date
4793                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
4794                 --
4795                ,P_EXCLD_FLAG      => r_QTR.INFORMATION11
4796              ,P_ORDR_NUM      => r_QTR.INFORMATION260
4797              ,P_QTR_ATTRIBUTE1      => r_QTR.INFORMATION111
4798              ,P_QTR_ATTRIBUTE10      => r_QTR.INFORMATION120
4799              ,P_QTR_ATTRIBUTE11      => r_QTR.INFORMATION121
4800              ,P_QTR_ATTRIBUTE12      => r_QTR.INFORMATION122
4801              ,P_QTR_ATTRIBUTE13      => r_QTR.INFORMATION123
4802              ,P_QTR_ATTRIBUTE14      => r_QTR.INFORMATION124
4803              ,P_QTR_ATTRIBUTE15      => r_QTR.INFORMATION125
4804              ,P_QTR_ATTRIBUTE16      => r_QTR.INFORMATION126
4805              ,P_QTR_ATTRIBUTE17      => r_QTR.INFORMATION127
4806              ,P_QTR_ATTRIBUTE18      => r_QTR.INFORMATION128
4807              ,P_QTR_ATTRIBUTE19      => r_QTR.INFORMATION129
4808              ,P_QTR_ATTRIBUTE2      => r_QTR.INFORMATION112
4809              ,P_QTR_ATTRIBUTE20      => r_QTR.INFORMATION130
4810              ,P_QTR_ATTRIBUTE21      => r_QTR.INFORMATION131
4811              ,P_QTR_ATTRIBUTE22      => r_QTR.INFORMATION132
4812              ,P_QTR_ATTRIBUTE23      => r_QTR.INFORMATION133
4813              ,P_QTR_ATTRIBUTE24      => r_QTR.INFORMATION134
4814              ,P_QTR_ATTRIBUTE25      => r_QTR.INFORMATION135
4815              ,P_QTR_ATTRIBUTE26      => r_QTR.INFORMATION136
4816              ,P_QTR_ATTRIBUTE27      => r_QTR.INFORMATION137
4817              ,P_QTR_ATTRIBUTE28      => r_QTR.INFORMATION138
4818              ,P_QTR_ATTRIBUTE29      => r_QTR.INFORMATION139
4819              ,P_QTR_ATTRIBUTE3      => r_QTR.INFORMATION113
4820              ,P_QTR_ATTRIBUTE30      => r_QTR.INFORMATION140
4821              ,P_QTR_ATTRIBUTE4      => r_QTR.INFORMATION114
4822              ,P_QTR_ATTRIBUTE5      => r_QTR.INFORMATION115
4823              ,P_QTR_ATTRIBUTE6      => r_QTR.INFORMATION116
4824              ,P_QTR_ATTRIBUTE7      => r_QTR.INFORMATION117
4825              ,P_QTR_ATTRIBUTE8      => r_QTR.INFORMATION118
4826              ,P_QTR_ATTRIBUTE9      => r_QTR.INFORMATION119
4827              ,P_QTR_ATTRIBUTE_CATEGORY      => r_QTR.INFORMATION110
4828              ,P_QUALIFICATION_TYPE_ID      => l_QUALIFICATION_TYPE_ID
4829              ,P_QUAL_TITL_RT_ID      => l_qual_titl_rt_id
4830              ,P_TITLE      => r_QTR.INFORMATION141
4831              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
4832                 --
4833                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
4834                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
4835                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
4836              );
4837              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
4838              -- Update all relevent cer records with new pk_id
4839              hr_utility.set_location('Before plsql table ',222);
4840              hr_utility.set_location('new_value id '||l_qual_titl_rt_id,222);
4841              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'QUAL_TITL_RT_ID' ;
4842              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_QTR.information1 ;
4843              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_QUAL_TITL_RT_ID ;
4844              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
4845              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_QTR_unique.table_route_id;
4846              hr_utility.set_location('After plsql table ',222);
4847              --
4848              -- 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 ) ;
4849              --
4850              BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
4851              --
4852            else
4853              --
4854              -- Call Update routine for the pk_id created in prev run .
4855            --UPD START
4856            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
4857            --
4858            if l_update then
4859              --
4860              l_datetrack_mode := r_QTR.datetrack_mode ;
4861              --
4862              get_dt_modes(
4863                p_effective_date        => l_process_date,
4864                p_effective_end_date    => r_QTR.information3,
4865                p_effective_start_date  => r_QTR.information2,
4866                p_dml_operation         => r_QTR.dml_operation,
4867                p_datetrack_mode        => l_datetrack_mode );
4868            --    p_update                => l_update
4869              --
4870              l_effective_date := l_process_date;
4871              l_QUAL_TITL_RT_ID   := r_QTR.information1;
4872              l_object_version_number := r_QTR.information265;
4873              --
4874            end if;
4875            --
4876            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
4877            --
4878            IF l_update OR l_dml_operation <> 'UPDATE' THEN
4879            --UPD END
4880              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
4881              hr_utility.set_location(' BEN_QUAL_TITL_RT_F UPDATE_QUAL_TITL_RT ',30);
4882              BEN_QUAL_TITL_RT_API.UPDATE_QUAL_TITL_RT(
4883                 --
4884                 P_VALIDATE               => false
4885                 ,P_EFFECTIVE_DATE        => l_effective_date
4886                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
4887                 --
4888             ,P_EXCLD_FLAG      => r_QTR.INFORMATION11
4889              ,P_ORDR_NUM      => r_QTR.INFORMATION260
4890              ,P_QTR_ATTRIBUTE1      => r_QTR.INFORMATION111
4891              ,P_QTR_ATTRIBUTE10      => r_QTR.INFORMATION120
4892              ,P_QTR_ATTRIBUTE11      => r_QTR.INFORMATION121
4893              ,P_QTR_ATTRIBUTE12      => r_QTR.INFORMATION122
4894              ,P_QTR_ATTRIBUTE13      => r_QTR.INFORMATION123
4895              ,P_QTR_ATTRIBUTE14      => r_QTR.INFORMATION124
4896              ,P_QTR_ATTRIBUTE15      => r_QTR.INFORMATION125
4897              ,P_QTR_ATTRIBUTE16      => r_QTR.INFORMATION126
4898              ,P_QTR_ATTRIBUTE17      => r_QTR.INFORMATION127
4899              ,P_QTR_ATTRIBUTE18      => r_QTR.INFORMATION128
4900              ,P_QTR_ATTRIBUTE19      => r_QTR.INFORMATION129
4901              ,P_QTR_ATTRIBUTE2      => r_QTR.INFORMATION112
4902              ,P_QTR_ATTRIBUTE20      => r_QTR.INFORMATION130
4903              ,P_QTR_ATTRIBUTE21      => r_QTR.INFORMATION131
4904              ,P_QTR_ATTRIBUTE22      => r_QTR.INFORMATION132
4905              ,P_QTR_ATTRIBUTE23      => r_QTR.INFORMATION133
4906              ,P_QTR_ATTRIBUTE24      => r_QTR.INFORMATION134
4907              ,P_QTR_ATTRIBUTE25      => r_QTR.INFORMATION135
4908              ,P_QTR_ATTRIBUTE26      => r_QTR.INFORMATION136
4909              ,P_QTR_ATTRIBUTE27      => r_QTR.INFORMATION137
4910              ,P_QTR_ATTRIBUTE28      => r_QTR.INFORMATION138
4911              ,P_QTR_ATTRIBUTE29      => r_QTR.INFORMATION139
4912              ,P_QTR_ATTRIBUTE3      => r_QTR.INFORMATION113
4913              ,P_QTR_ATTRIBUTE30      => r_QTR.INFORMATION140
4914              ,P_QTR_ATTRIBUTE4      => r_QTR.INFORMATION114
4915              ,P_QTR_ATTRIBUTE5      => r_QTR.INFORMATION115
4916              ,P_QTR_ATTRIBUTE6      => r_QTR.INFORMATION116
4917              ,P_QTR_ATTRIBUTE7      => r_QTR.INFORMATION117
4918              ,P_QTR_ATTRIBUTE8      => r_QTR.INFORMATION118
4919              ,P_QTR_ATTRIBUTE9      => r_QTR.INFORMATION119
4920              ,P_QTR_ATTRIBUTE_CATEGORY      => r_QTR.INFORMATION110
4921              ,P_QUALIFICATION_TYPE_ID      => l_QUALIFICATION_TYPE_ID
4922              ,P_QUAL_TITL_RT_ID      => l_qual_titl_rt_id
4923              ,P_TITLE      => r_QTR.INFORMATION141
4924              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
4925                 --
4926                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
4927                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
4928                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
4929                 ,P_DATETRACK_MODE        => l_datetrack_mode
4930              );
4931              --
4932              end if;
4933            end if;
4934            --
4935            -- Delete the row if it is end dated.
4936            --
4937            if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
4938              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
4939                 trunc(l_max_eed) = r_QTR.information3) then
4940                 --
4941                 BEN_QUAL_TITL_RT_API.delete_QUAL_TITL_RT(
4942                    --
4943                    p_validate                       => false
4944                    ,p_qual_titl_rt_id                   => l_qual_titl_rt_id
4945                    ,p_effective_start_date           => l_effective_start_date
4946                    ,p_effective_end_date             => l_effective_end_date
4947                    ,p_object_version_number          => l_object_version_number
4948                    ,p_effective_date                 => l_max_eed
4949                    ,p_datetrack_mode                 => hr_api.g_delete
4950                    --
4951                    );
4952                    --
4953            end if;
4954            --
4955            l_prev_pk_id := l_current_pk_id ;
4956            --
4957          end if;
4958          --
4959        end if;
4960        --
4961      end if;
4962      --
4963    end loop;
4964    --
4965  exception when others then
4966     --
4967     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'QTR',r_qtr.information5 );
4968     --
4969  end create_QTR_rows;
4970 
4971    --
4972    ---------------------------------------------------------------
4973    ----------------------< create_PZR_rows >-----------------------
4974    ---------------------------------------------------------------
4975    --
4976    procedure create_PZR_rows
4977    (
4978          p_validate                       in  number     default 0
4979         ,p_copy_entity_txn_id             in  number
4980         ,p_effective_date                 in  date
4981         ,p_prefix_suffix_text             in  varchar2  default null
4982         ,p_reuse_object_flag              in  varchar2  default null
4983         ,p_target_business_group_id       in  varchar2  default null
4984         ,p_prefix_suffix_cd               in  varchar2  default null
4985    ) is
4986    --
4987    l_PSTL_ZIP_RNG_ID  number;
4988    l_VRBL_RT_PRFL_ID  number;
4989    l_EXCLD_FLAG       varchar2(100);
4990    l_ORDR_NUM         number;
4991    --
4992    cursor c_unique_PZR(l_table_alias varchar2) is
4993    select distinct cpe.information1,
4994      cpe.information2,
4995      cpe.information3,
4996      cpe.table_route_id
4997    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
4998         pqh_table_route tr
4999    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
5000    and   cpe.table_route_id     = tr.table_route_id
5001    -- and   tr.where_clause        = l_BEN_PSTL_ZIP_RT_F
5002    and tr.table_alias = l_table_alias
5003    and   cpe.number_of_copies   = 1 -- ADDITION
5004    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
5005    order by information1, information2; --added for bug: 5151945
5006    --
5007    --
5008    cursor c_PZR_min_max_dates(c_table_route_id  number,
5009                 c_information1   Number) is
5010    select
5011      min(cpe.information2) min_esd,
5012      max(cpe.information3) min_eed
5013    from ben_copy_entity_results cpe
5014    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
5015    and   cpe.table_route_id     = c_table_route_id
5016    and   cpe.information1       = c_information1 ;
5017    --
5018    cursor c_PZR(c_table_route_id  number,
5019                 c_information1   number,
5020                 c_information2   Date,
5021                 c_information3   Date )  is
5022    select
5023      cpe.*
5024    from ben_copy_entity_results cpe
5025    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
5026    and   cpe.table_route_id     = c_table_route_id
5027    and   cpe.information1       = c_information1
5028    and   cpe.information2       = c_information2
5029    and   cpe.information3       = c_information3
5030    and rownum = 1 ;
5031    -- Date Track target record
5032    cursor c_find_PZR_in_target(
5033                                 c_effective_start_date    date,
5034                                 c_effective_end_date      date,
5035                                 c_business_group_id       number,
5036                                 c_new_pk_id               number) is
5037    select
5038      PZR.pstl_zip_rt_id new_value
5039    from BEN_PSTL_ZIP_RT_F PZR
5040    where
5041    PZR.PSTL_ZIP_RNG_ID     = l_PSTL_ZIP_RNG_ID  and
5042    PZR.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
5043    PZR.ORDR_NUM           = l_ORDR_NUM and
5044    PZR.business_group_id  = c_business_group_id
5045    and   PZR.pstl_zip_rt_id  <> c_new_pk_id
5046 --TEMPIK
5047    and c_effective_start_date between effective_start_date
5048                             and effective_end_date ;
5049 --END TEMPIK
5050 /*TEMPIK
5051    and exists ( select null
5052                 from BEN_PSTL_ZIP_RT_F PZR1
5053                 where
5054                 PZR1.PSTL_ZIP_RNG_ID     = l_PSTL_ZIP_RNG_ID  and
5055                 PZR1.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
5056                 PZR1.ORDR_NUM           = l_ORDR_NUM and
5057                 PZR1.business_group_id  = c_business_group_id
5058                 and   PZR1.effective_start_date <= c_effective_start_date )
5059    and exists ( select null
5060                 from BEN_PSTL_ZIP_RT_F PZR2
5061                 where
5062                 PZR2.PSTL_ZIP_RNG_ID     = l_PSTL_ZIP_RNG_ID  and
5063                 PZR2.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
5064                 PZR2.ORDR_NUM           = l_ORDR_NUM and
5065                 PZR2.business_group_id  = c_business_group_id
5066                 and   PZR2.effective_end_date >= c_effective_end_date )
5067                 ;
5068 TEMPIK */
5069    --TEMPIK
5070    l_dt_rec_found            boolean ;
5071    --END TEMPIK
5072    --
5073    l_current_pk_id           number := null ;
5074    --UPD START
5075    --
5076    l_update                  boolean      := false ;
5077    l_datetrack_mode          varchar2(80) := hr_api.g_update;
5078    l_process_date            date;
5079    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
5080    --
5081    --UPD END
5082    l_prev_pk_id              number := null ;
5083    l_first_rec               boolean := true ;
5084    r_PZR                     c_PZR%rowtype;
5085    l_pstl_zip_rt_id             number ;
5086    l_object_version_number   number ;
5087    l_effective_start_date    date ;
5088    l_effective_end_date      date ;
5089    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
5090    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
5091    l_new_value               number(15);
5092    l_object_found_in_target  boolean := false ;
5093    l_min_esd                 date;
5094    l_max_eed                 date;
5095    l_effective_date          date;
5096    --
5097  begin
5098    -- Initialization
5099    l_object_found_in_target := false ;
5100    -- End Initialization
5101    -- Derive the prefix - sufix
5102    if   p_prefix_suffix_cd = 'PREFIX' then
5103      l_prefix  := p_prefix_suffix_text ;
5104    elsif p_prefix_suffix_cd = 'SUFFIX' then
5105      l_suffix   := p_prefix_suffix_text ;
5106    else
5107      l_prefix := null ;
5108      l_suffix  := null ;
5109    end if ;
5110    -- End Prefix Sufix derivation
5111    for r_PZR_unique in c_unique_PZR('PZR') loop
5112 
5113      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
5114         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
5115          r_PZR_unique.information3 >=
5116                  ben_pd_copy_to_ben_one.g_copy_effective_date)
5117           ) then
5118        --
5119        hr_utility.set_location(' r_PZR_unique.table_route_id '||r_PZR_unique.table_route_id,10);
5120        hr_utility.set_location(' r_PZR_unique.information1 '||r_PZR_unique.information1,10);
5121        hr_utility.set_location( 'r_PZR_unique.information2 '||r_PZR_unique.information2,10);
5122        hr_utility.set_location( 'r_PZR_unique.information3 '||r_PZR_unique.information3,10);
5123        -- If reuse objects flag is 'Y' then check for the object in the target business group
5124        -- if found insert the record into PLSql table and exit the loop else try create the
5125        -- object in the target business group
5126        --
5127        l_object_found_in_target := false ;
5128        l_min_esd := null ;
5129        l_max_eed := null ;
5130        open c_PZR_min_max_dates(r_PZR_unique.table_route_id, r_PZR_unique.information1 ) ;
5131        fetch c_PZR_min_max_dates into l_min_esd,l_max_eed ;
5132        --
5133 
5134        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
5135             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
5136          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
5137        end if;
5138        l_min_esd := greatest(l_min_esd,r_PZR_unique.information2);
5139        open c_PZR(r_PZR_unique.table_route_id,
5140                 r_PZR_unique.information1,
5141                 r_PZR_unique.information2,
5142                 r_PZR_unique.information3 ) ;
5143        --
5144        fetch c_PZR into r_PZR ;
5145        --
5146        close c_PZR ;
5147        --
5148        l_PSTL_ZIP_RNG_ID := get_fk('PSTL_ZIP_RNG_ID', r_PZR.INFORMATION245,r_PZR_unique.dml_operation);
5149        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_PZR.INFORMATION262,r_PZR_unique.dml_operation);
5150        l_ORDR_NUM         := r_PZR.INFORMATION260;
5151        l_EXCLD_FLAG      := r_PZR.information11;
5152        --UPD START
5153        l_update := false;
5154        l_process_date := p_effective_date;
5155        l_dml_operation:= r_PZR_unique.dml_operation ;
5156        --
5157        if l_dml_operation = 'UPDATE' then
5158          --
5159          l_object_found_in_target := TRUE;
5160          --
5161          if l_process_date between r_PZR_unique.information2 and r_PZR_unique.information3 then
5162                l_update := true;
5163                if r_PZR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
5164                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'PSTL_ZIP_RT_ID'
5165                then
5166                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'PSTL_ZIP_RT_ID' ;
5167                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_PZR_unique.information1 ;
5168                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_PZR_unique.information1 ;
5169                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
5170                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_PZR_unique.table_route_id;
5171                   --
5172                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
5173                   --
5174                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
5175                   --
5176                   -- log_data('PZR',l_new_value,l_prefix || r_PZR_unique.name|| l_suffix,'REUSED');
5177                   --
5178                end if ;
5179                hr_utility.set_location( 'found record for update',10);
5180            --
5181          else
5182            --
5183            l_update := false;
5184            --
5185          end if;
5186        else
5187          --
5188          --UPD END
5189        if p_reuse_object_flag = 'Y' then
5190          if c_PZR_min_max_dates%found then
5191            -- cursor to find the object
5192            open c_find_PZR_in_target( l_min_esd,l_max_eed,
5193                                  p_target_business_group_id, nvl(l_pstl_zip_rt_id, -999)  ) ;
5194            fetch c_find_PZR_in_target into l_new_value ;
5195            if c_find_PZR_in_target%found then
5196              --
5197              --TEMPIK
5198              l_dt_rec_found :=   dt_api.check_min_max_dates
5199                  (p_base_table_name => 'BEN_PSTL_ZIP_RT_F',
5200                   p_base_key_column => 'PSTL_ZIP_RT_ID',
5201                   p_base_key_value  => l_new_value,
5202                   p_from_date       => l_min_esd,
5203                   p_to_date         => l_max_eed );
5204              if l_dt_rec_found THEN
5205              --END TEMPIK
5206              if r_PZR_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
5207                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'PSTL_ZIP_RT_ID'  then
5208                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'PSTL_ZIP_RT_ID' ;
5209                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_PZR_unique.information1 ;
5210                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
5211                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
5212                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PZR_unique.table_route_id;
5213                 --
5214                 -- 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) ;
5215                 --
5216                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
5217              end if ;
5218              --
5219              l_object_found_in_target := true ;
5220              --TEMPIK
5221              end if; -- l_dt_rec_found
5222              --END TEMPIK
5223            end if;
5224            close c_find_PZR_in_target ;
5225          --
5226          end if;
5227        end if ;
5228        --
5229        end if;
5230        close c_PZR_min_max_dates ;
5231        if not l_object_found_in_target OR l_update   then
5232          --
5233          l_current_pk_id := r_PZR.information1;
5234          --
5235          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
5236          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
5237          --
5238          if l_current_pk_id =  l_prev_pk_id  then
5239            --
5240            l_first_rec := false ;
5241            --
5242          else
5243            --
5244            l_first_rec := true ;
5245            --
5246          end if ;
5247          --
5248 
5249          l_effective_date := r_PZR.information2;
5250          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
5251               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
5252            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
5253          end if;
5254 
5255          if l_first_rec and not l_update then
5256            -- Call Create routine.
5257            hr_utility.set_location(' BEN_PSTL_ZIP_RT_F CREATE_POSTAL_ZIP_RATE ',20);
5258            BEN_POSTAL_ZIP_RATE_API.CREATE_POSTAL_ZIP_RATE(
5259              --
5260              P_VALIDATE               => false
5261              ,P_EFFECTIVE_DATE        => l_effective_date
5262              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
5263              --
5264              ,P_EXCLD_FLAG      => r_PZR.INFORMATION11
5265              ,P_ORDR_NUM      => r_PZR.INFORMATION260
5266              ,P_PSTL_ZIP_RNG_ID      => l_PSTL_ZIP_RNG_ID
5267              ,P_PSTL_ZIP_RT_ID      => l_pstl_zip_rt_id
5268              ,P_PZR_ATTRIBUTE1      => r_PZR.INFORMATION111
5269              ,P_PZR_ATTRIBUTE10      => r_PZR.INFORMATION120
5270              ,P_PZR_ATTRIBUTE11      => r_PZR.INFORMATION121
5271              ,P_PZR_ATTRIBUTE12      => r_PZR.INFORMATION122
5272              ,P_PZR_ATTRIBUTE13      => r_PZR.INFORMATION123
5273              ,P_PZR_ATTRIBUTE14      => r_PZR.INFORMATION124
5274              ,P_PZR_ATTRIBUTE15      => r_PZR.INFORMATION125
5275              ,P_PZR_ATTRIBUTE16      => r_PZR.INFORMATION126
5276              ,P_PZR_ATTRIBUTE17      => r_PZR.INFORMATION127
5277              ,P_PZR_ATTRIBUTE18      => r_PZR.INFORMATION128
5278              ,P_PZR_ATTRIBUTE19      => r_PZR.INFORMATION129
5279              ,P_PZR_ATTRIBUTE2      => r_PZR.INFORMATION112
5280              ,P_PZR_ATTRIBUTE20      => r_PZR.INFORMATION130
5281              ,P_PZR_ATTRIBUTE21      => r_PZR.INFORMATION131
5282              ,P_PZR_ATTRIBUTE22      => r_PZR.INFORMATION132
5283              ,P_PZR_ATTRIBUTE23      => r_PZR.INFORMATION133
5284              ,P_PZR_ATTRIBUTE24      => r_PZR.INFORMATION134
5285              ,P_PZR_ATTRIBUTE25      => r_PZR.INFORMATION135
5286              ,P_PZR_ATTRIBUTE26      => r_PZR.INFORMATION136
5287              ,P_PZR_ATTRIBUTE27      => r_PZR.INFORMATION137
5288              ,P_PZR_ATTRIBUTE28      => r_PZR.INFORMATION138
5289              ,P_PZR_ATTRIBUTE29      => r_PZR.INFORMATION139
5290              ,P_PZR_ATTRIBUTE3      => r_PZR.INFORMATION113
5291              ,P_PZR_ATTRIBUTE30      => r_PZR.INFORMATION140
5292              ,P_PZR_ATTRIBUTE4      => r_PZR.INFORMATION114
5293              ,P_PZR_ATTRIBUTE5      => r_PZR.INFORMATION115
5294              ,P_PZR_ATTRIBUTE6      => r_PZR.INFORMATION116
5295              ,P_PZR_ATTRIBUTE7      => r_PZR.INFORMATION117
5296              ,P_PZR_ATTRIBUTE8      => r_PZR.INFORMATION118
5297              ,P_PZR_ATTRIBUTE9      => r_PZR.INFORMATION119
5298              ,P_PZR_ATTRIBUTE_CATEGORY      => r_PZR.INFORMATION110
5299              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
5300              --
5301              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
5302              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
5303              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
5304            );
5305            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
5306            -- Update all relevent cer records with new pk_id
5307            hr_utility.set_location('Before plsql table ',222);
5308            hr_utility.set_location('new_value id '||l_pstl_zip_rt_id,222);
5309            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'PSTL_ZIP_RT_ID' ;
5310            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_PZR.information1 ;
5311            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_PSTL_ZIP_RT_ID ;
5312            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
5313            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PZR_unique.table_route_id;
5314            hr_utility.set_location('After plsql table ',222);
5315            --
5316            -- 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 ) ;
5317            --
5318            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
5319            --
5320          else
5321            --
5322            -- Call Update routine for the pk_id created in prev run .
5323            --UPD START
5324            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
5325            --
5326            if l_update then
5327              --
5328              l_datetrack_mode := r_PZR.datetrack_mode ;
5329              --
5330              get_dt_modes(
5331                p_effective_date        => l_process_date,
5332                p_effective_end_date    => r_PZR.information3,
5333                p_effective_start_date  => r_PZR.information2,
5334                p_dml_operation         => r_PZR.dml_operation,
5335                p_datetrack_mode        => l_datetrack_mode );
5336            --    p_update                => l_update
5337              --
5338              l_effective_date := l_process_date;
5339              l_PSTL_ZIP_RT_ID   := r_PZR.information1;
5340              l_object_version_number := r_PZR.information265;
5341              --
5342            end if;
5343            --
5344            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
5345            --
5346            IF l_update OR l_dml_operation <> 'UPDATE' THEN
5347            --UPD END
5348            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
5349            hr_utility.set_location(' BEN_PSTL_ZIP_RT_F UPDATE_POSTAL_ZIP_RATE ',30);
5350            BEN_POSTAL_ZIP_RATE_API.UPDATE_POSTAL_ZIP_RATE(
5351              --
5352              P_VALIDATE               => false
5353              ,P_EFFECTIVE_DATE        => l_effective_date
5354              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
5355              --
5356               ,P_EXCLD_FLAG      => r_PZR.INFORMATION11
5357              ,P_ORDR_NUM      => r_PZR.INFORMATION260
5358              ,P_PSTL_ZIP_RNG_ID      => l_PSTL_ZIP_RNG_ID
5359              ,P_PSTL_ZIP_RT_ID      => l_pstl_zip_rt_id
5360              ,P_PZR_ATTRIBUTE1      => r_PZR.INFORMATION111
5361              ,P_PZR_ATTRIBUTE10      => r_PZR.INFORMATION120
5362              ,P_PZR_ATTRIBUTE11      => r_PZR.INFORMATION121
5363              ,P_PZR_ATTRIBUTE12      => r_PZR.INFORMATION122
5364              ,P_PZR_ATTRIBUTE13      => r_PZR.INFORMATION123
5365              ,P_PZR_ATTRIBUTE14      => r_PZR.INFORMATION124
5366              ,P_PZR_ATTRIBUTE15      => r_PZR.INFORMATION125
5367              ,P_PZR_ATTRIBUTE16      => r_PZR.INFORMATION126
5368              ,P_PZR_ATTRIBUTE17      => r_PZR.INFORMATION127
5369              ,P_PZR_ATTRIBUTE18      => r_PZR.INFORMATION128
5370              ,P_PZR_ATTRIBUTE19      => r_PZR.INFORMATION129
5371              ,P_PZR_ATTRIBUTE2      => r_PZR.INFORMATION112
5372              ,P_PZR_ATTRIBUTE20      => r_PZR.INFORMATION130
5373              ,P_PZR_ATTRIBUTE21      => r_PZR.INFORMATION131
5374              ,P_PZR_ATTRIBUTE22      => r_PZR.INFORMATION132
5375              ,P_PZR_ATTRIBUTE23      => r_PZR.INFORMATION133
5376              ,P_PZR_ATTRIBUTE24      => r_PZR.INFORMATION134
5377              ,P_PZR_ATTRIBUTE25      => r_PZR.INFORMATION135
5378              ,P_PZR_ATTRIBUTE26      => r_PZR.INFORMATION136
5379              ,P_PZR_ATTRIBUTE27      => r_PZR.INFORMATION137
5380              ,P_PZR_ATTRIBUTE28      => r_PZR.INFORMATION138
5381              ,P_PZR_ATTRIBUTE29      => r_PZR.INFORMATION139
5382              ,P_PZR_ATTRIBUTE3      => r_PZR.INFORMATION113
5383              ,P_PZR_ATTRIBUTE30      => r_PZR.INFORMATION140
5384              ,P_PZR_ATTRIBUTE4      => r_PZR.INFORMATION114
5385              ,P_PZR_ATTRIBUTE5      => r_PZR.INFORMATION115
5386              ,P_PZR_ATTRIBUTE6      => r_PZR.INFORMATION116
5387              ,P_PZR_ATTRIBUTE7      => r_PZR.INFORMATION117
5388              ,P_PZR_ATTRIBUTE8      => r_PZR.INFORMATION118
5389              ,P_PZR_ATTRIBUTE9      => r_PZR.INFORMATION119
5390              ,P_PZR_ATTRIBUTE_CATEGORY      => r_PZR.INFORMATION110
5391              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
5392              --
5393              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
5394              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
5395              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
5396              ,P_DATETRACK_MODE        => l_datetrack_mode
5397            );
5398            --
5399            end if;
5400          end if;
5401          --
5402          -- Delete the row if it is end dated.
5403          --
5404          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
5405              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
5406              trunc(l_max_eed) = r_PZR.information3) then
5407              --
5408              BEN_POSTAL_ZIP_RATE_API.delete_POSTAL_ZIP_RATE(
5409                 --
5410                 p_validate                       => false
5411                 ,p_pstl_zip_rt_id                   => l_pstl_zip_rt_id
5412                 ,p_effective_start_date           => l_effective_start_date
5413                 ,p_effective_end_date             => l_effective_end_date
5414                 ,p_object_version_number          => l_object_version_number
5415                 ,p_effective_date                 => l_max_eed
5416                 ,p_datetrack_mode                 => hr_api.g_delete
5417                 --
5418                 );
5419                 --
5420          end if;
5421          --
5422          l_prev_pk_id := l_current_pk_id ;
5423          --
5424        end if;
5425        --
5426      end if;
5427      --
5428    end loop;
5429    --
5430  exception when others then
5431     --
5432     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'PZR',r_pzr.information5 );
5433     --
5434  end create_PZR_rows;
5435 
5436    --
5437    ---------------------------------------------------------------
5438    ----------------------< create_PTR_rows >-----------------------
5439    ---------------------------------------------------------------
5440    --
5441    procedure create_PTR_rows
5442    (
5443          p_validate                       in  number     default 0
5444         ,p_copy_entity_txn_id             in  number
5445         ,p_effective_date                 in  date
5446         ,p_prefix_suffix_text             in  varchar2  default null
5447         ,p_reuse_object_flag              in  varchar2  default null
5448         ,p_target_business_group_id       in  varchar2  default null
5449         ,p_prefix_suffix_cd               in  varchar2  default null
5450    ) is
5451    --
5452    l_PERSON_TYPE_ID  number;
5453    l_VRBL_RT_PRFL_ID  number;
5454    l_EXCLD_FLAG       varchar2(100);
5455    l_ORDR_NUM         number;
5456    --
5457    cursor c_unique_PTR(l_table_alias varchar2) is
5458    select distinct cpe.information1,
5459      cpe.information2,
5460      cpe.information3,
5461      cpe.table_route_id
5462    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
5463         pqh_table_route tr
5464    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
5465    and   cpe.table_route_id     = tr.table_route_id
5466    -- and   tr.where_clause        = l_BEN_PER_TYP_RT_F
5467    and tr.table_alias = l_table_alias
5468    and   cpe.number_of_copies   = 1 -- ADDITION
5469    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
5470    order by information1, information2; --added for bug: 5151945
5471    --
5472    --
5473    cursor c_PTR_min_max_dates(c_table_route_id  number,
5474                 c_information1   Number) is
5475    select
5476      min(cpe.information2) min_esd,
5477      max(cpe.information3) min_eed
5478    from ben_copy_entity_results cpe
5479    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
5480    and   cpe.table_route_id     = c_table_route_id
5481    and   cpe.information1       = c_information1 ;
5482    --
5483    cursor c_PTR(c_table_route_id  number,
5484                 c_information1   number,
5485                 c_information2   Date,
5486                 c_information3   Date )  is
5487    select
5488      cpe.*
5489    from ben_copy_entity_results cpe
5490    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
5491    and   cpe.table_route_id     = c_table_route_id
5492    and   cpe.information1       = c_information1
5493    and   cpe.information2       = c_information2
5494    and   cpe.information3       = c_information3
5495    and rownum = 1 ;
5496    -- Date Track target record
5497    cursor c_find_PTR_in_target(
5498                                 c_effective_start_date    date,
5499                                 c_effective_end_date      date,
5500                                 c_business_group_id       number,
5501                                 c_new_pk_id               number) is
5502    select
5503      PTR.per_typ_rt_id new_value
5504    from BEN_PER_TYP_RT_F PTR
5505    where
5506    PTR.PERSON_TYPE_ID     = l_PERSON_TYPE_ID  and
5507    PTR.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID and
5508    PTR.ORDR_NUM           = l_ORDR_NUM and
5509    PTR.business_group_id  = c_business_group_id
5510    and   PTR.per_typ_rt_id  <> c_new_pk_id
5511 --TEMPIK
5512    and c_effective_start_date between effective_start_date
5513                             and effective_end_date ;
5514 --END TEMPIK
5515 /*TEMPIK
5516    and exists ( select null
5517                 from BEN_PER_TYP_RT_F PTR1
5518                 where
5519                 PTR1.PERSON_TYPE_ID     = l_PERSON_TYPE_ID  and
5520                 PTR1.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID and
5521                 PTR1.ORDR_NUM           = l_ORDR_NUM and
5522                 PTR1.business_group_id  = c_business_group_id
5523                 and   PTR1.effective_start_date <= c_effective_start_date )
5524    and exists ( select null
5525                 from BEN_PER_TYP_RT_F PTR2
5526                 where
5527                 PTR2.PERSON_TYPE_ID     = l_PERSON_TYPE_ID  and
5528                 PTR2.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
5529                 PTR2.ORDR_NUM           = l_ORDR_NUM and
5530                 PTR2.business_group_id  = c_business_group_id
5531                 and   PTR2.effective_end_date >= c_effective_end_date )
5532                 ;
5533 TEMPIK */
5534    --TEMPIK
5535    l_dt_rec_found            boolean ;
5536    --END TEMPIK
5537    --
5538    l_current_pk_id           number := null ;
5539    --UPD START
5540    --
5541    l_update                  boolean      := false ;
5542    l_datetrack_mode          varchar2(80) := hr_api.g_update;
5543    l_process_date            date;
5544    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
5545    --
5546    --UPD END
5547    l_prev_pk_id              number := null ;
5548    l_first_rec               boolean := true ;
5549    r_PTR                     c_PTR%rowtype;
5550    l_per_typ_rt_id             number ;
5551    l_object_version_number   number ;
5552    l_effective_start_date    date ;
5553    l_effective_end_date      date ;
5554    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
5555    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
5556    l_new_value               number(15);
5557    l_object_found_in_target  boolean := false ;
5558    l_min_esd                 date;
5559    l_max_eed                 date;
5560    l_effective_date          date;
5561    --
5562  begin
5563    -- Initialization
5564    l_object_found_in_target := false ;
5565    -- End Initialization
5566    -- Derive the prefix - sufix
5567    if   p_prefix_suffix_cd = 'PREFIX' then
5568      l_prefix  := p_prefix_suffix_text ;
5569    elsif p_prefix_suffix_cd = 'SUFFIX' then
5570      l_suffix   := p_prefix_suffix_text ;
5571    else
5572      l_prefix := null ;
5573      l_suffix  := null ;
5574    end if ;
5575    -- End Prefix Sufix derivation
5576    for r_PTR_unique in c_unique_PTR('PTR') loop
5577 
5578      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
5579         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
5580          r_PTR_unique.information3 >=
5581                    ben_pd_copy_to_ben_one.g_copy_effective_date)
5582           ) then
5583        --
5584        hr_utility.set_location(' r_PTR_unique.table_route_id '||r_PTR_unique.table_route_id,10);
5585        hr_utility.set_location(' r_PTR_unique.information1 '||r_PTR_unique.information1,10);
5586        hr_utility.set_location( 'r_PTR_unique.information2 '||r_PTR_unique.information2,10);
5587        hr_utility.set_location( 'r_PTR_unique.information3 '||r_PTR_unique.information3,10);
5588        -- If reuse objects flag is 'Y' then check for the object in the target business group
5589        -- if found insert the record into PLSql table and exit the loop else try create the
5590        -- object in the target business group
5591        --
5592        l_object_found_in_target := false ;
5593        l_min_esd := null ;
5594        l_max_eed := null ;
5595        open c_PTR_min_max_dates(r_PTR_unique.table_route_id, r_PTR_unique.information1 ) ;
5596        fetch c_PTR_min_max_dates into l_min_esd,l_max_eed ;
5597        --
5598 
5599        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
5600             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
5601          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
5602        end if;
5603        l_min_esd := greatest(l_min_esd,r_PTR_unique.information2);
5604        open c_PTR(r_PTR_unique.table_route_id,
5605                 r_PTR_unique.information1,
5606                 r_PTR_unique.information2,
5607                 r_PTR_unique.information3 ) ;
5608        --
5609        fetch c_PTR into r_PTR ;
5610        --
5611        close c_PTR ;
5612        --
5613        if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
5614          l_PERSON_TYPE_ID := r_PTR.information176;
5615        else
5616          l_PERSON_TYPE_ID := r_PTR.information174;
5617        end if;
5618        --
5619        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_PTR.INFORMATION262,r_PTR_unique.dml_operation);
5620        l_ORDR_NUM         := r_PTR.INFORMATION257;
5621        l_EXCLD_FLAG      := r_PTR.information11;
5622        hr_utility.set_location(' l_PERSON_TYPE_ID '||l_PERSON_TYPE_ID,999);
5623        hr_utility.set_location(' info 1           '||r_PTR.information1,999);
5624        if l_PERSON_TYPE_ID is null then
5625          close c_PTR_min_max_dates;
5626          log_nomapping_data(p_parent_table_alias =>'VPF'
5627                      ,p_parent_pk_id         => r_PTR.information262
5628                      ,p_copy_entity_txn_id   => p_copy_entity_txn_id
5629                      ,p_child_table_alias    => 'PTR'
5630                      ,p_child_data           => r_PTR.information173 );
5631        else
5632        --UPD START
5633        l_update := false;
5634        l_process_date := p_effective_date;
5635        l_dml_operation:= r_PTR_unique.dml_operation ;
5636        --
5637        if l_dml_operation = 'UPDATE' then
5638          --
5639          l_object_found_in_target := TRUE;
5640          --
5641          if l_process_date between r_PTR_unique.information2 and r_PTR_unique.information3 then
5642                l_update := true;
5643                if r_PTR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
5644                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'PER_TYP_RT_ID'
5645                then
5646                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'PER_TYP_RT_ID' ;
5647                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_PTR_unique.information1 ;
5648                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_PTR_unique.information1 ;
5649                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
5650                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_PTR_unique.table_route_id;
5651                   --
5652                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
5653                   --
5654                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
5655                   --
5656                   -- log_data('PTR',l_new_value,l_prefix || r_PTR_unique.name|| l_suffix,'REUSED');
5657                   --
5658                end if ;
5659                hr_utility.set_location( 'found record for update',10);
5660            --
5661          else
5662            --
5663            l_update := false;
5664            --
5665          end if;
5666        else
5667          --
5668          --UPD END
5669          if p_reuse_object_flag = 'Y' then
5670            if c_PTR_min_max_dates%found then
5671               -- cursor to find the object
5672               open c_find_PTR_in_target( l_min_esd,l_max_eed,
5673                                     p_target_business_group_id, nvl(l_per_typ_rt_id, -999)  ) ;
5674               fetch c_find_PTR_in_target into l_new_value ;
5675               if c_find_PTR_in_target%found then
5676                 --
5677              --TEMPIK
5678              l_dt_rec_found :=   dt_api.check_min_max_dates
5679                  (p_base_table_name => 'BEN_PER_TYP_RT_F',
5680                   p_base_key_column => 'PER_TYP_RT_ID',
5681                   p_base_key_value  => l_new_value,
5682                   p_from_date       => l_min_esd,
5683                   p_to_date         => l_max_eed );
5684              if l_dt_rec_found THEN
5685              --END TEMPIK
5686                 if r_PTR_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
5687                    nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'PER_TYP_RT_ID'  then
5688                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'PER_TYP_RT_ID' ;
5689                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_PTR_unique.information1 ;
5690                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
5691                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
5692                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PTR_unique.table_route_id;
5693                    --
5694                    -- 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) ;
5695                    --
5696                    BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
5697                 end if ;
5698                 --
5699                 l_object_found_in_target := true ;
5700              --TEMPIK
5701              end if; -- l_dt_rec_found
5702              --END TEMPIK
5703               end if;
5704               close c_find_PTR_in_target ;
5705            --
5706            end if;
5707          end if ;
5708          --
5709          end if;
5710          close c_PTR_min_max_dates ;
5711          if not l_object_found_in_target OR l_update   then
5712            --
5713            l_current_pk_id := r_PTR.information1;
5714            --
5715            hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
5716            hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
5717            --
5718            if l_current_pk_id =  l_prev_pk_id  then
5719              --
5720              l_first_rec := false ;
5721              --
5722            else
5723              --
5724              l_first_rec := true ;
5725              --
5726            end if ;
5727            --
5728 
5729            l_effective_date := r_PTR.information2;
5730            if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
5731                 l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
5732              l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
5733            end if;
5734 
5735            if l_first_rec and not l_update then
5736              -- Call Create routine.
5737              hr_utility.set_location(' BEN_PER_TYP_RT_F CREATE_PERSON_TYPE_RATE ',20);
5738              BEN_PERSON_TYPE_RATE_API.CREATE_PERSON_TYPE_RATE(
5739                 --
5740                 P_VALIDATE               => false
5741                 ,P_EFFECTIVE_DATE        => l_effective_date
5742                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
5743                 --
5744              ,P_EXCLD_FLAG      => r_PTR.INFORMATION11
5745              ,P_ORDR_NUM      => r_PTR.INFORMATION257
5746              ,P_PERSON_TYPE_ID      => l_PERSON_TYPE_ID
5747              ,P_PER_TYP_CD      => r_PTR.INFORMATION12
5748              ,P_PER_TYP_RT_ID      => l_per_typ_rt_id
5749              ,P_PTR_ATTRIBUTE1      => r_PTR.INFORMATION111
5750              ,P_PTR_ATTRIBUTE10      => r_PTR.INFORMATION120
5751              ,P_PTR_ATTRIBUTE11      => r_PTR.INFORMATION121
5752              ,P_PTR_ATTRIBUTE12      => r_PTR.INFORMATION122
5753              ,P_PTR_ATTRIBUTE13      => r_PTR.INFORMATION123
5754              ,P_PTR_ATTRIBUTE14      => r_PTR.INFORMATION124
5755              ,P_PTR_ATTRIBUTE15      => r_PTR.INFORMATION125
5756              ,P_PTR_ATTRIBUTE16      => r_PTR.INFORMATION126
5757              ,P_PTR_ATTRIBUTE17      => r_PTR.INFORMATION127
5758              ,P_PTR_ATTRIBUTE18      => r_PTR.INFORMATION128
5759              ,P_PTR_ATTRIBUTE19      => r_PTR.INFORMATION129
5760              ,P_PTR_ATTRIBUTE2      => r_PTR.INFORMATION112
5761              ,P_PTR_ATTRIBUTE20      => r_PTR.INFORMATION130
5762              ,P_PTR_ATTRIBUTE21      => r_PTR.INFORMATION131
5763              ,P_PTR_ATTRIBUTE22      => r_PTR.INFORMATION132
5764              ,P_PTR_ATTRIBUTE23      => r_PTR.INFORMATION133
5765              ,P_PTR_ATTRIBUTE24      => r_PTR.INFORMATION134
5766              ,P_PTR_ATTRIBUTE25      => r_PTR.INFORMATION135
5767              ,P_PTR_ATTRIBUTE26      => r_PTR.INFORMATION136
5768              ,P_PTR_ATTRIBUTE27      => r_PTR.INFORMATION137
5769              ,P_PTR_ATTRIBUTE28      => r_PTR.INFORMATION138
5770              ,P_PTR_ATTRIBUTE29      => r_PTR.INFORMATION139
5771              ,P_PTR_ATTRIBUTE3      => r_PTR.INFORMATION113
5772              ,P_PTR_ATTRIBUTE30      => r_PTR.INFORMATION140
5773              ,P_PTR_ATTRIBUTE4      => r_PTR.INFORMATION114
5774              ,P_PTR_ATTRIBUTE5      => r_PTR.INFORMATION115
5775              ,P_PTR_ATTRIBUTE6      => r_PTR.INFORMATION116
5776              ,P_PTR_ATTRIBUTE7      => r_PTR.INFORMATION117
5777              ,P_PTR_ATTRIBUTE8      => r_PTR.INFORMATION118
5778              ,P_PTR_ATTRIBUTE9      => r_PTR.INFORMATION119
5779              ,P_PTR_ATTRIBUTE_CATEGORY      => r_PTR.INFORMATION110
5780              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
5781                 --
5782                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
5783                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
5784                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
5785              )   ;
5786              --    insert the table_name,old_pk_id,new_pk_id into a plsql record
5787              -- Update all relevent cer records with new pk_id
5788              hr_utility.set_location('Before plsql table ',222);
5789              hr_utility.set_location('new_value id '||l_per_typ_rt_id,222);
5790              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'PER_TYP_RT_ID' ;
5791              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_PTR.information1 ;
5792              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_PER_TYP_RT_ID ;
5793              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
5794              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PTR_unique.table_route_id;
5795              hr_utility.set_location('After plsql table ',222);
5796              --
5797              -- 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 ) ;
5798              --
5799              BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
5800              --
5801            else
5802              --
5803              -- Call Update routine for the pk_id created in prev run .
5804            --UPD START
5805            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
5806            --
5807            if l_update then
5808              --
5809              l_datetrack_mode := r_PTR.datetrack_mode ;
5810              --
5811              get_dt_modes(
5812                p_effective_date        => l_process_date,
5813                p_effective_end_date    => r_PTR.information3,
5814                p_effective_start_date  => r_PTR.information2,
5815                p_dml_operation         => r_PTR.dml_operation,
5816                p_datetrack_mode        => l_datetrack_mode );
5817            --    p_update                => l_update
5818              --
5819              l_effective_date := l_process_date;
5820              l_PER_TYP_RT_ID   := r_PTR.information1;
5821              l_object_version_number := r_PTR.information265;
5822              --
5823            end if;
5824            --
5825            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
5826            --
5827            IF l_update OR l_dml_operation <> 'UPDATE' THEN
5828              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
5829              hr_utility.set_location(' BEN_PER_TYP_RT_F UPDATE_PERSON_TYPE_RATE ',30);
5830              BEN_PERSON_TYPE_RATE_API.UPDATE_PERSON_TYPE_RATE(
5831                 --
5832                 P_VALIDATE               => false
5833                 ,P_EFFECTIVE_DATE        => l_effective_date
5834                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
5835                 --
5836             ,P_EXCLD_FLAG      => r_PTR.INFORMATION11
5837              ,P_ORDR_NUM      => r_PTR.INFORMATION257
5838              ,P_PERSON_TYPE_ID      => l_PERSON_TYPE_ID
5839              ,P_PER_TYP_CD      => r_PTR.INFORMATION12
5840              ,P_PER_TYP_RT_ID      => l_per_typ_rt_id
5841              ,P_PTR_ATTRIBUTE1      => r_PTR.INFORMATION111
5842              ,P_PTR_ATTRIBUTE10      => r_PTR.INFORMATION120
5843              ,P_PTR_ATTRIBUTE11      => r_PTR.INFORMATION121
5844              ,P_PTR_ATTRIBUTE12      => r_PTR.INFORMATION122
5845              ,P_PTR_ATTRIBUTE13      => r_PTR.INFORMATION123
5846              ,P_PTR_ATTRIBUTE14      => r_PTR.INFORMATION124
5847              ,P_PTR_ATTRIBUTE15      => r_PTR.INFORMATION125
5848              ,P_PTR_ATTRIBUTE16      => r_PTR.INFORMATION126
5849              ,P_PTR_ATTRIBUTE17      => r_PTR.INFORMATION127
5850              ,P_PTR_ATTRIBUTE18      => r_PTR.INFORMATION128
5851              ,P_PTR_ATTRIBUTE19      => r_PTR.INFORMATION129
5852              ,P_PTR_ATTRIBUTE2      => r_PTR.INFORMATION112
5853              ,P_PTR_ATTRIBUTE20      => r_PTR.INFORMATION130
5854              ,P_PTR_ATTRIBUTE21      => r_PTR.INFORMATION131
5855              ,P_PTR_ATTRIBUTE22      => r_PTR.INFORMATION132
5856              ,P_PTR_ATTRIBUTE23      => r_PTR.INFORMATION133
5857              ,P_PTR_ATTRIBUTE24      => r_PTR.INFORMATION134
5858              ,P_PTR_ATTRIBUTE25      => r_PTR.INFORMATION135
5859              ,P_PTR_ATTRIBUTE26      => r_PTR.INFORMATION136
5860              ,P_PTR_ATTRIBUTE27      => r_PTR.INFORMATION137
5861              ,P_PTR_ATTRIBUTE28      => r_PTR.INFORMATION138
5862              ,P_PTR_ATTRIBUTE29      => r_PTR.INFORMATION139
5863              ,P_PTR_ATTRIBUTE3      => r_PTR.INFORMATION113
5864              ,P_PTR_ATTRIBUTE30      => r_PTR.INFORMATION140
5865              ,P_PTR_ATTRIBUTE4      => r_PTR.INFORMATION114
5866              ,P_PTR_ATTRIBUTE5      => r_PTR.INFORMATION115
5867              ,P_PTR_ATTRIBUTE6      => r_PTR.INFORMATION116
5868              ,P_PTR_ATTRIBUTE7      => r_PTR.INFORMATION117
5869              ,P_PTR_ATTRIBUTE8      => r_PTR.INFORMATION118
5870              ,P_PTR_ATTRIBUTE9      => r_PTR.INFORMATION119
5871              ,P_PTR_ATTRIBUTE_CATEGORY      => r_PTR.INFORMATION110
5872              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
5873                    --
5874                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
5875                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
5876                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
5877                 ,P_DATETRACK_MODE        => l_datetrack_mode
5878              );
5879              --
5880              end if;
5881            end if;
5882            --
5883            -- Delete the row if it is end dated.
5884            --
5885            if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
5886              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
5887                 trunc(l_max_eed) = r_PTR.information3) then
5888                 --
5889                 BEN_PERSON_TYPE_RATE_API.delete_PERSON_TYPE_RATE(
5890                    --
5891                    p_validate                       => false
5892                    ,p_per_typ_rt_id                   => l_per_typ_rt_id
5893                    ,p_effective_start_date           => l_effective_start_date
5894                    ,p_effective_end_date             => l_effective_end_date
5895                    ,p_object_version_number          => l_object_version_number
5896                    ,p_effective_date                 => l_max_eed
5897                    ,p_datetrack_mode                 => hr_api.g_delete
5898                    --
5899                    );
5900                    --
5901            end if;
5902            --
5903            l_prev_pk_id := l_current_pk_id ;
5904            --
5905          end if;
5906          --
5907        end if;
5908        --
5909      end if;
5910      --
5911    end loop;
5912    --
5913  exception when others then
5914     --
5915     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'PTR',r_ptr.information5 );
5916     --
5917  end create_PTR_rows;
5918 
5919    --
5920    ---------------------------------------------------------------
5921    ----------------------< create_GNR_rows >-----------------------
5922    ---------------------------------------------------------------
5923    --
5924    procedure create_GNR_rows
5925    (
5926          p_validate                       in  number     default 0
5927         ,p_copy_entity_txn_id             in  number
5928         ,p_effective_date                 in  date
5929         ,p_prefix_suffix_text             in  varchar2  default null
5930         ,p_reuse_object_flag              in  varchar2  default null
5931         ,p_target_business_group_id       in  varchar2  default null
5932         ,p_prefix_suffix_cd               in  varchar2  default null
5933    ) is
5934    --
5935    l_VRBL_RT_PRFL_ID  number;
5936    l_GNDR_CD          varchar2(100);
5937    l_EXCLD_FLAG       varchar2(100);
5938    l_ORDR_NUM         number;
5939    --
5940    cursor c_unique_GNR(l_table_alias varchar2) is
5941    select distinct cpe.information1,
5942      cpe.information2,
5943      cpe.information3,
5944      cpe.table_route_id
5945    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
5946         pqh_table_route tr
5947    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
5948    and   cpe.table_route_id     = tr.table_route_id
5949    -- and   tr.where_clause        = l_BEN_GNDR_RT_F
5950    and tr.table_alias = l_table_alias
5951    and   cpe.number_of_copies   = 1 -- ADDITION
5952    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
5953    order by information1, information2; --added for bug: 5151945
5954    --
5955    --
5956    cursor c_GNR_min_max_dates(c_table_route_id  number,
5957                 c_information1   Number) is
5958    select
5959      min(cpe.information2) min_esd,
5960      max(cpe.information3) min_eed
5961    from ben_copy_entity_results cpe
5962    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
5963    and   cpe.table_route_id     = c_table_route_id
5964    and   cpe.information1       = c_information1 ;
5965    --
5966    cursor c_GNR(c_table_route_id  number,
5967                 c_information1   number,
5968                 c_information2   Date,
5969                 c_information3   Date)  is
5970    select
5971      cpe.*
5972    from ben_copy_entity_results cpe
5973    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
5974    and   cpe.table_route_id     = c_table_route_id
5975    and   cpe.information1       = c_information1
5976    and   cpe.information2       = c_information2
5977    and   cpe.information3       = c_information3
5978    and rownum = 1 ;
5979    -- Date Track target record
5980    cursor c_find_GNR_in_target(
5981                                 c_effective_start_date    date,
5982                                 c_effective_end_date      date,
5983                                 c_business_group_id       number,
5984                                 c_new_pk_id               number) is
5985    select
5986      GNR.gndr_rt_id new_value
5987    from BEN_GNDR_RT_F GNR
5988    where
5989    GNR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
5990    GNR.ORDR_NUM           = l_ORDR_NUM and
5991    GNR.business_group_id  = c_business_group_id
5992    and   GNR.gndr_rt_id  <> c_new_pk_id
5993 --TEMPIK
5994    and c_effective_start_date between effective_start_date
5995                             and effective_end_date ;
5996 --END TEMPIK
5997 /*TEMPIK
5998    and exists ( select null
5999                 from BEN_GNDR_RT_F GNR1
6000                 where
6001                 GNR1.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID  and
6002                 GNR1.ORDR_NUM           = l_ORDR_NUM and
6003                 GNR1.business_group_id  = c_business_group_id
6004                 and   GNR1.effective_start_date <= c_effective_start_date )
6005    and exists ( select null
6006                 from BEN_GNDR_RT_F GNR2
6007                 where
6008                 GNR2.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
6009                 GNR2.ORDR_NUM           = l_ORDR_NUM and
6010                 GNR2.business_group_id  = c_business_group_id
6011                 and   GNR2.effective_end_date >= c_effective_end_date )
6012                 ;
6013 TEMPIK */
6014    --TEMPIK
6015    l_dt_rec_found            boolean ;
6016    --END TEMPIK
6017    --
6018    l_current_pk_id           number := null ;
6019    --UPD START
6020    --
6021    l_update                  boolean      := false ;
6022    l_datetrack_mode          varchar2(80) := hr_api.g_update;
6023    l_process_date            date;
6024    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
6025    --
6026    --UPD END
6027    l_prev_pk_id              number := null ;
6028    l_first_rec               boolean := true ;
6029    r_GNR                     c_GNR%rowtype;
6030    l_gndr_rt_id             number ;
6031    l_object_version_number   number ;
6032    l_effective_start_date    date ;
6033    l_effective_end_date      date ;
6034    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
6035    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
6036    l_new_value               number(15);
6037    l_object_found_in_target  boolean := false ;
6038    l_min_esd                 date;
6039    l_max_eed                 date;
6040    l_effective_date          date;
6041    --
6042  begin
6043    -- Initialization
6044    l_object_found_in_target := false ;
6045    -- End Initialization
6046    -- Derive the prefix - sufix
6047    if   p_prefix_suffix_cd = 'PREFIX' then
6048      l_prefix  := p_prefix_suffix_text ;
6049    elsif p_prefix_suffix_cd = 'SUFFIX' then
6050      l_suffix   := p_prefix_suffix_text ;
6051    else
6052      l_prefix := null ;
6053      l_suffix  := null ;
6054    end if ;
6055    -- End Prefix Sufix derivation
6056    for r_GNR_unique in c_unique_GNR('GNR') loop
6057 
6058      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
6059         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
6060          r_GNR_unique.information3 >=
6061                  ben_pd_copy_to_ben_one.g_copy_effective_date)
6062         ) then
6063        --
6064        hr_utility.set_location(' r_GNR_unique.table_route_id '||r_GNR_unique.table_route_id,10);
6065        hr_utility.set_location(' r_GNR_unique.information1 '||r_GNR_unique.information1,10);
6066        hr_utility.set_location( 'r_GNR_unique.information2 '||r_GNR_unique.information2,10);
6067        hr_utility.set_location( 'r_GNR_unique.information3 '||r_GNR_unique.information3,10);
6068        -- If reuse objects flag is 'Y' then check for the object in the target business group
6069        -- if found insert the record into PLSql table and exit the loop else try create the
6070        -- object in the target business group
6071        --
6072        l_object_found_in_target := false ;
6073        l_min_esd := null ;
6074        l_max_eed := null ;
6075        open c_GNR_min_max_dates(r_GNR_unique.table_route_id, r_GNR_unique.information1 ) ;
6076        fetch c_GNR_min_max_dates into l_min_esd,l_max_eed ;
6077        --
6078 
6079        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
6080             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
6081          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
6082        end if;
6083        l_min_esd := greatest(l_min_esd,r_GNR_unique.information2);
6084        open c_GNR(r_GNR_unique.table_route_id,
6085                 r_GNR_unique.information1,
6086                 r_GNR_unique.information2,
6087                 r_GNR_unique.information3 ) ;
6088        --
6089        fetch c_GNR into r_GNR ;
6090        --
6091        close c_GNR ;
6092        --
6093        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_GNR.INFORMATION262,r_GNR_unique.dml_operation);
6094        l_ORDR_NUM         := r_GNR.INFORMATION257;
6095        l_GNDR_CD         := r_GNR.information11;
6096        l_EXCLD_FLAG      := r_GNR.information12;
6097        --UPD START
6098        l_update := false;
6099        l_process_date := p_effective_date;
6100        l_dml_operation:= r_GNR_unique.dml_operation ;
6101        --
6102        if l_dml_operation = 'UPDATE' then
6103          --
6104          l_object_found_in_target := TRUE;
6105          --
6106          if l_process_date between r_GNR_unique.information2 and r_GNR_unique.information3 then
6107                l_update := true;
6108                if r_GNR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
6109                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'GNDR_RT_ID'
6110                then
6111                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'GNDR_RT_ID' ;
6112                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_GNR_unique.information1 ;
6113                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_GNR_unique.information1 ;
6114                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
6115                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_GNR_unique.table_route_id;
6116                   --
6117                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
6118                   --
6119                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
6120                   --
6121                   --log_data('GNR',l_new_value,l_prefix || r_GNR_unique.name|| l_suffix,'REUSED');
6122                   --
6123                end if ;
6124                hr_utility.set_location( 'found record for update',10);
6125            --
6126          else
6127            --
6128            l_update := false;
6129            --
6130          end if;
6131        else
6132          --
6133          --UPD END
6134        if p_reuse_object_flag = 'Y' then
6135          if c_GNR_min_max_dates%found then
6136            -- cursor to find the object
6137            open c_find_GNR_in_target( l_min_esd,l_max_eed,
6138                                  p_target_business_group_id, nvl(l_gndr_rt_id, -999)  ) ;
6139            fetch c_find_GNR_in_target into l_new_value ;
6140            if c_find_GNR_in_target%found then
6141              --
6142              --TEMPIK
6143              l_dt_rec_found :=   dt_api.check_min_max_dates
6144                  (p_base_table_name => 'BEN_GNDR_RT_F',
6145                   p_base_key_column => 'GNDR_RT_ID',
6146                   p_base_key_value  => l_new_value,
6147                   p_from_date       => l_min_esd,
6148                   p_to_date         => l_max_eed );
6149              if l_dt_rec_found THEN
6150              --END TEMPIK
6151              if r_GNR_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
6152                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'GNDR_RT_ID'  then
6153                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'GNDR_RT_ID' ;
6154                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_GNR_unique.information1 ;
6155                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
6156                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
6157                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_GNR_unique.table_route_id;
6158                 --
6159                 -- 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) ;
6160                 --
6161                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
6162              end if ;
6163              --
6164              l_object_found_in_target := true ;
6165              --TEMPIK
6166              end if; -- l_dt_rec_found
6167              --END TEMPIK
6168            end if;
6169            close c_find_GNR_in_target ;
6170          --
6171          end if;
6172        end if ;
6173        --
6174        end if;
6175        close c_GNR_min_max_dates ;
6176        if not l_object_found_in_target OR l_update   then
6177          --
6178          l_current_pk_id := r_GNR.information1;
6179          --
6180          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
6181          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
6182          --
6183          if l_current_pk_id =  l_prev_pk_id  then
6184            --
6185            l_first_rec := false ;
6186            --
6187          else
6188            --
6189            l_first_rec := true ;
6190            --
6191          end if ;
6192          --
6193 
6194          l_effective_date := r_GNR.information2;
6195          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
6196               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
6197            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
6198          end if;
6199 
6200          if l_first_rec and not l_update then
6201            -- Call Create routine.
6202            hr_utility.set_location(' BEN_GNDR_RT_F CREATE_GENDER_RATE ',20);
6203            BEN_GENDER_RATE_API.CREATE_GENDER_RATE(
6204              --
6205              P_VALIDATE               => false
6206              ,P_EFFECTIVE_DATE        => l_effective_date
6207              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
6208              --
6209              ,P_EXCLD_FLAG      => r_GNR.INFORMATION12
6210              ,P_GNDR_CD      => r_GNR.INFORMATION11
6211              ,P_GNDR_RT_ID      => l_gndr_rt_id
6212              ,P_GNR_ATTRIBUTE1      => r_GNR.INFORMATION111
6213              ,P_GNR_ATTRIBUTE10      => r_GNR.INFORMATION120
6214              ,P_GNR_ATTRIBUTE11      => r_GNR.INFORMATION121
6215              ,P_GNR_ATTRIBUTE12      => r_GNR.INFORMATION122
6216              ,P_GNR_ATTRIBUTE13      => r_GNR.INFORMATION123
6217              ,P_GNR_ATTRIBUTE14      => r_GNR.INFORMATION124
6218              ,P_GNR_ATTRIBUTE15      => r_GNR.INFORMATION125
6219              ,P_GNR_ATTRIBUTE16      => r_GNR.INFORMATION126
6220              ,P_GNR_ATTRIBUTE17      => r_GNR.INFORMATION127
6221              ,P_GNR_ATTRIBUTE18      => r_GNR.INFORMATION128
6222              ,P_GNR_ATTRIBUTE19      => r_GNR.INFORMATION129
6223              ,P_GNR_ATTRIBUTE2      => r_GNR.INFORMATION112
6224              ,P_GNR_ATTRIBUTE20      => r_GNR.INFORMATION130
6225              ,P_GNR_ATTRIBUTE21      => r_GNR.INFORMATION131
6226              ,P_GNR_ATTRIBUTE22      => r_GNR.INFORMATION132
6227              ,P_GNR_ATTRIBUTE23      => r_GNR.INFORMATION133
6228              ,P_GNR_ATTRIBUTE24      => r_GNR.INFORMATION134
6229              ,P_GNR_ATTRIBUTE25      => r_GNR.INFORMATION135
6230              ,P_GNR_ATTRIBUTE26      => r_GNR.INFORMATION136
6231              ,P_GNR_ATTRIBUTE27      => r_GNR.INFORMATION137
6232              ,P_GNR_ATTRIBUTE28      => r_GNR.INFORMATION138
6233              ,P_GNR_ATTRIBUTE29      => r_GNR.INFORMATION139
6234              ,P_GNR_ATTRIBUTE3      => r_GNR.INFORMATION113
6235              ,P_GNR_ATTRIBUTE30      => r_GNR.INFORMATION140
6236              ,P_GNR_ATTRIBUTE4      => r_GNR.INFORMATION114
6237              ,P_GNR_ATTRIBUTE5      => r_GNR.INFORMATION115
6238              ,P_GNR_ATTRIBUTE6      => r_GNR.INFORMATION116
6239              ,P_GNR_ATTRIBUTE7      => r_GNR.INFORMATION117
6240              ,P_GNR_ATTRIBUTE8      => r_GNR.INFORMATION118
6241              ,P_GNR_ATTRIBUTE9      => r_GNR.INFORMATION119
6242              ,P_GNR_ATTRIBUTE_CATEGORY      => r_GNR.INFORMATION110
6243              ,P_ORDR_NUM      => r_GNR.INFORMATION257
6244              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
6245              --
6246              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
6247              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
6248              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
6249            );
6250            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
6251            -- Update all relevent cer records with new pk_id
6252            hr_utility.set_location('Before plsql table ',222);
6253            hr_utility.set_location('new_value id '||l_gndr_rt_id,222);
6254            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'GNDR_RT_ID' ;
6255            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_GNR.information1 ;
6256            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_GNDR_RT_ID ;
6257            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
6258            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_GNR_unique.table_route_id;
6259            hr_utility.set_location('After plsql table ',222);
6260            --
6261            -- 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 ) ;
6262            --
6263            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
6264            --
6265          else
6266            --
6267            -- Call Update routine for the pk_id created in prev run .
6268            --UPD START
6269            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
6270            --
6271            if l_update then
6272              --
6273              l_datetrack_mode := r_GNR.datetrack_mode ;
6274              --
6275              get_dt_modes(
6276                p_effective_date        => l_process_date,
6277                p_effective_end_date    => r_GNR.information3,
6278                p_effective_start_date  => r_GNR.information2,
6279                p_dml_operation         => r_GNR.dml_operation,
6280                p_datetrack_mode        => l_datetrack_mode );
6281            --    p_update                => l_update
6282              --
6283              l_effective_date := l_process_date;
6284              l_GNDR_RT_ID   := r_GNR.information1;
6285              l_object_version_number := r_GNR.information265;
6286              --
6287            end if;
6288            --
6289            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
6290            --
6291            IF l_update OR l_dml_operation <> 'UPDATE' THEN
6292            --UPD END
6293            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
6294            hr_utility.set_location(' BEN_GNDR_RT_F UPDATE_GENDER_RATE ',30);
6295            BEN_GENDER_RATE_API.UPDATE_GENDER_RATE(
6296              --
6297              P_VALIDATE               => false
6298              ,P_EFFECTIVE_DATE        => l_effective_date
6299              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
6300              --
6301              ,P_EXCLD_FLAG      => r_GNR.INFORMATION12
6302              ,P_GNDR_CD      => r_GNR.INFORMATION11
6303              ,P_GNDR_RT_ID      => l_gndr_rt_id
6304              ,P_GNR_ATTRIBUTE1      => r_GNR.INFORMATION111
6305              ,P_GNR_ATTRIBUTE10      => r_GNR.INFORMATION120
6306              ,P_GNR_ATTRIBUTE11      => r_GNR.INFORMATION121
6307              ,P_GNR_ATTRIBUTE12      => r_GNR.INFORMATION122
6308              ,P_GNR_ATTRIBUTE13      => r_GNR.INFORMATION123
6309              ,P_GNR_ATTRIBUTE14      => r_GNR.INFORMATION124
6310              ,P_GNR_ATTRIBUTE15      => r_GNR.INFORMATION125
6311              ,P_GNR_ATTRIBUTE16      => r_GNR.INFORMATION126
6312              ,P_GNR_ATTRIBUTE17      => r_GNR.INFORMATION127
6313              ,P_GNR_ATTRIBUTE18      => r_GNR.INFORMATION128
6314              ,P_GNR_ATTRIBUTE19      => r_GNR.INFORMATION129
6315              ,P_GNR_ATTRIBUTE2      => r_GNR.INFORMATION112
6316              ,P_GNR_ATTRIBUTE20      => r_GNR.INFORMATION130
6317              ,P_GNR_ATTRIBUTE21      => r_GNR.INFORMATION131
6318              ,P_GNR_ATTRIBUTE22      => r_GNR.INFORMATION132
6319              ,P_GNR_ATTRIBUTE23      => r_GNR.INFORMATION133
6320              ,P_GNR_ATTRIBUTE24      => r_GNR.INFORMATION134
6321              ,P_GNR_ATTRIBUTE25      => r_GNR.INFORMATION135
6322              ,P_GNR_ATTRIBUTE26      => r_GNR.INFORMATION136
6323              ,P_GNR_ATTRIBUTE27      => r_GNR.INFORMATION137
6324              ,P_GNR_ATTRIBUTE28      => r_GNR.INFORMATION138
6325              ,P_GNR_ATTRIBUTE29      => r_GNR.INFORMATION139
6326              ,P_GNR_ATTRIBUTE3      => r_GNR.INFORMATION113
6327              ,P_GNR_ATTRIBUTE30      => r_GNR.INFORMATION140
6328              ,P_GNR_ATTRIBUTE4      => r_GNR.INFORMATION114
6329              ,P_GNR_ATTRIBUTE5      => r_GNR.INFORMATION115
6330              ,P_GNR_ATTRIBUTE6      => r_GNR.INFORMATION116
6331              ,P_GNR_ATTRIBUTE7      => r_GNR.INFORMATION117
6332              ,P_GNR_ATTRIBUTE8      => r_GNR.INFORMATION118
6333              ,P_GNR_ATTRIBUTE9      => r_GNR.INFORMATION119
6334              ,P_GNR_ATTRIBUTE_CATEGORY      => r_GNR.INFORMATION110
6335              ,P_ORDR_NUM      => r_GNR.INFORMATION257
6336              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
6337              --
6338              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
6339              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
6340              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
6341              ,P_DATETRACK_MODE        => l_datetrack_mode
6342            );
6343            end if;
6344            --
6345          end if;
6346          --
6347          -- Delete the row if it is end dated.
6348          --
6349          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
6350              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
6351              trunc(l_max_eed) = r_GNR.information3) then
6352              --
6353              BEN_GENDER_RATE_API.delete_GENDER_RATE(
6354                 --
6355                 p_validate                       => false
6356                 ,p_gndr_rt_id                   => l_gndr_rt_id
6357                 ,p_effective_start_date           => l_effective_start_date
6358                 ,p_effective_end_date             => l_effective_end_date
6359                 ,p_object_version_number          => l_object_version_number
6360                 ,p_effective_date                 => l_max_eed
6361                 ,p_datetrack_mode                 => hr_api.g_delete
6362                 --
6363                 );
6364                 --
6365          end if;
6366          --
6367          l_prev_pk_id := l_current_pk_id ;
6368          --
6369        end if;
6370        --
6371      end if;
6372      --
6373    end loop;
6374    --
6375  exception when others then
6376     --
6377     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'GNR',r_gnr.information5 );
6378     --
6379  end create_GNR_rows;
6380 
6381    --
6382    ---------------------------------------------------------------
6383    ----------------------< create_DBR_rows >-----------------------
6384    ---------------------------------------------------------------
6385    --
6386    procedure create_DBR_rows
6387    (
6388          p_validate                       in  number     default 0
6389         ,p_copy_entity_txn_id             in  number
6390         ,p_effective_date                 in  date
6391         ,p_prefix_suffix_text             in  varchar2  default null
6392         ,p_reuse_object_flag              in  varchar2  default null
6393         ,p_target_business_group_id       in  varchar2  default null
6394         ,p_prefix_suffix_cd               in  varchar2  default null
6395    ) is
6396    --
6397    l_VRBL_RT_PRFL_ID  number;
6398    l_EXCLD_FLAG       varchar2(100);
6399    l_ORDR_NUM         number;
6400    l_DSBLD_CD         varchar2(100);
6401    --
6402    cursor c_unique_DBR(l_table_alias varchar2) is
6403    select distinct cpe.information1,
6404      cpe.information2,
6405      cpe.information3,
6406      cpe.table_route_id
6407    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
6408         pqh_table_route tr
6409    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
6410    and   cpe.table_route_id     = tr.table_route_id
6411    -- and   tr.where_clause        = l_BEN_DSBLD_RT_F
6412    and tr.table_alias = l_table_alias
6413    and   cpe.number_of_copies   = 1 -- ADDITION
6414    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
6415    order by information1, information2; --added for bug: 5151945
6416    --
6417    --
6418    cursor c_DBR_min_max_dates(c_table_route_id  number,
6419                 c_information1   Number) is
6420    select
6421      min(cpe.information2) min_esd,
6422      max(cpe.information3) min_eed
6423    from ben_copy_entity_results cpe
6424    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
6425    and   cpe.table_route_id     = c_table_route_id
6426    and   cpe.information1       = c_information1 ;
6427    --
6428    cursor c_DBR(c_table_route_id  number,
6429                 c_information1   number,
6430                 c_information2   Date,
6431                 c_information3   Date )  is
6432    select
6433      cpe.*
6434    from ben_copy_entity_results cpe
6435    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
6436    and   cpe.table_route_id     = c_table_route_id
6437    and   cpe.information1       = c_information1
6438    and   cpe.information2       = c_information2
6439    and   cpe.information3       = c_information3
6440    and rownum = 1 ;
6441    -- Date Track target record
6442    cursor c_find_DBR_in_target(
6443                                 c_effective_start_date    date,
6444                                 c_effective_end_date      date,
6445                                 c_business_group_id       number,
6446                                 c_new_pk_id               number) is
6447    select
6448      DBR.dsbld_rt_id new_value
6449    from BEN_DSBLD_RT_F DBR
6450    where
6451    DBR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
6452    DBR.DSBLD_CD         = l_DSBLD_CD and
6453    DBR.ORDR_NUM           = l_ORDR_NUM and
6454    DBR.business_group_id  = c_business_group_id
6455    and   DBR.dsbld_rt_id  <> c_new_pk_id
6456 --TEMPIK
6457    and c_effective_start_date between effective_start_date
6458                             and effective_end_date ;
6459 --END TEMPIK
6460 /*TEMPIK
6461    and exists ( select null
6462                 from BEN_DSBLD_RT_F DBR1
6463                 where
6464                 DBR1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
6465                 DBR1.DSBLD_CD         = l_DSBLD_CD and
6466                 DBR1.ORDR_NUM           = l_ORDR_NUM and
6467                 DBR1.business_group_id  = c_business_group_id
6468                 and   DBR1.effective_start_date <= c_effective_start_date )
6469    and exists ( select null
6470                 from BEN_DSBLD_RT_F DBR2
6471                 where
6472                 DBR2.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
6473                 DBR2.DSBLD_CD         = l_DSBLD_CD and
6474                 DBR2.ORDR_NUM           = l_ORDR_NUM and
6475                 DBR2.business_group_id  = c_business_group_id
6476                 and   DBR2.effective_end_date >= c_effective_end_date )
6477                 ;
6478 TEMPIK */
6479    --TEMPIK
6480    l_dt_rec_found            boolean ;
6481    --END TEMPIK
6482    --
6483    l_current_pk_id           number := null ;
6484    --UPD START
6485    --
6486    l_update                  boolean      := false ;
6487    l_datetrack_mode          varchar2(80) := hr_api.g_update;
6488    l_process_date            date;
6489    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
6490    --
6491    --UPD END
6492    l_prev_pk_id              number := null ;
6493    l_first_rec               boolean := true ;
6494    r_DBR                     c_DBR%rowtype;
6495    l_dsbld_rt_id             number ;
6496    l_object_version_number   number ;
6497    l_effective_start_date    date ;
6498    l_effective_end_date      date ;
6499    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
6500    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
6501    l_new_value               number(15);
6502    l_object_found_in_target  boolean := false ;
6503    l_min_esd                 date;
6504    l_max_eed                 date;
6505    l_effective_date          date;
6506    --
6507  begin
6508    -- Initialization
6509    l_object_found_in_target := false ;
6510    -- End Initialization
6511    -- Derive the prefix - sufix
6512    if   p_prefix_suffix_cd = 'PREFIX' then
6513      l_prefix  := p_prefix_suffix_text ;
6514    elsif p_prefix_suffix_cd = 'SUFFIX' then
6515      l_suffix   := p_prefix_suffix_text ;
6516    else
6517      l_prefix := null ;
6518      l_suffix  := null ;
6519    end if ;
6520    -- End Prefix Sufix derivation
6521    for r_DBR_unique in c_unique_DBR('DBR') loop
6522 
6523      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
6524         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
6525          r_DBR_unique.information3 >=
6526                  ben_pd_copy_to_ben_one.g_copy_effective_date)
6527           ) then
6528        --
6529        hr_utility.set_location(' r_DBR_unique.table_route_id '||r_DBR_unique.table_route_id,10);
6530        hr_utility.set_location(' r_DBR_unique.information1 '||r_DBR_unique.information1,10);
6531        hr_utility.set_location( 'r_DBR_unique.information2 '||r_DBR_unique.information2,10);
6532        hr_utility.set_location( 'r_DBR_unique.information3 '||r_DBR_unique.information3,10);
6533        -- If reuse objects flag is 'Y' then check for the object in the target business group
6534        -- if found insert the record into PLSql table and exit the loop else try create the
6535        -- object in the target business group
6536        --
6537        l_object_found_in_target := false ;
6538        l_min_esd := null ;
6539        l_max_eed := null ;
6540        open c_DBR_min_max_dates(r_DBR_unique.table_route_id, r_DBR_unique.information1 ) ;
6541        fetch c_DBR_min_max_dates into l_min_esd,l_max_eed ;
6542        --
6543 
6544        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
6545             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
6546          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
6547        end if;
6548        l_min_esd := greatest(l_min_esd,r_DBR_unique.information2);
6549        open c_DBR(r_DBR_unique.table_route_id,
6550                 r_DBR_unique.information1,
6551                 r_DBR_unique.information2,
6552                 r_DBR_unique.information3 ) ;
6553        --
6554        fetch c_DBR into r_DBR ;
6555        --
6556        close c_DBR ;
6557        --
6558        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_DBR.INFORMATION262,r_DBR_unique.dml_operation);
6559        l_ORDR_NUM         := r_DBR.INFORMATION260;
6560        l_EXCLD_FLAG       := r_DBR.information12;
6561        l_DSBLD_CD         := r_DBR.information11;
6562        --UPD START
6563        l_update := false;
6564        l_process_date := p_effective_date;
6565        l_dml_operation:= r_DBR_unique.dml_operation ;
6566        --
6567        if l_dml_operation = 'UPDATE' then
6568          --
6569          l_object_found_in_target := TRUE;
6570          --
6571          if l_process_date between r_DBR_unique.information2 and r_DBR_unique.information3 then
6572                l_update := true;
6573                if r_DBR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
6574                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'DSBLD_RT_ID'
6575                then
6576                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'DSBLD_RT_ID' ;
6577                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_DBR_unique.information1 ;
6578                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_DBR_unique.information1 ;
6579                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
6580                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_DBR_unique.table_route_id;
6581                   --
6582                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
6583                   --
6584                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
6585                   --
6586                   --log_data('DBR',l_new_value,l_prefix || r_DBR_unique.name|| l_suffix,'REUSED');
6587                   --
6588                end if ;
6589                hr_utility.set_location( 'found record for update',10);
6590            --
6591          else
6592            --
6593            l_update := false;
6594            --
6595          end if;
6596        else
6597          --
6598          --UPD END
6599        if p_reuse_object_flag = 'Y' then
6600          if c_DBR_min_max_dates%found then
6601            -- cursor to find the object
6602            open c_find_DBR_in_target( l_min_esd,l_max_eed,
6603                                  p_target_business_group_id, nvl(l_dsbld_rt_id, -999)  ) ;
6604            fetch c_find_DBR_in_target into l_new_value ;
6605            if c_find_DBR_in_target%found then
6606              --
6607              --TEMPIK
6608              l_dt_rec_found :=   dt_api.check_min_max_dates
6609                  (p_base_table_name => 'BEN_DSBLD_RT_F',
6610                   p_base_key_column => 'DSBLD_RT_ID',
6611                   p_base_key_value  => l_new_value,
6612                   p_from_date       => l_min_esd,
6613                   p_to_date         => l_max_eed );
6614              if l_dt_rec_found THEN
6615              --END TEMPIK
6616              if r_DBR_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
6617                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'DSBLD_RT_ID'  then
6618                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'DSBLD_RT_ID' ;
6619                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_DBR_unique.information1 ;
6620                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
6621                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
6622                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_DBR_unique.table_route_id;
6623                 --
6624                 -- 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) ;
6625                 --
6626                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
6627              end if ;
6628              --
6629              l_object_found_in_target := true ;
6630              --TEMPIK
6631              end if; -- l_dt_rec_found
6632              --END TEMPIK
6633            end if;
6634            close c_find_DBR_in_target ;
6635          --
6636          end if;
6637        end if ;
6638        --
6639        end if;
6640        close c_DBR_min_max_dates ;
6641        if not l_object_found_in_target OR l_update   then
6642          --
6643          l_current_pk_id := r_DBR.information1;
6644          --
6645          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
6646          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
6647          --
6648          if l_current_pk_id =  l_prev_pk_id  then
6649            --
6650            l_first_rec := false ;
6651            --
6652          else
6653            --
6654            l_first_rec := true ;
6655            --
6656          end if ;
6657          --
6658 
6659          l_effective_date := r_DBR.information2;
6660          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
6661               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
6662            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
6663          end if;
6664 
6665          if l_first_rec and not l_update then
6666            -- Call Create routine.
6667            hr_utility.set_location(' BEN_DSBLD_RT_F CREATE_DSBLD_RT ',20);
6668            BEN_DSBLD_RT_API.CREATE_DSBLD_RT(
6669              --
6670              P_VALIDATE               => false
6671              ,P_EFFECTIVE_DATE        => l_effective_date
6672              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
6673              --
6674             ,P_DBR_ATTRIBUTE1      => r_DBR.INFORMATION111
6675              ,P_DBR_ATTRIBUTE10      => r_DBR.INFORMATION120
6676              ,P_DBR_ATTRIBUTE11      => r_DBR.INFORMATION121
6677              ,P_DBR_ATTRIBUTE12      => r_DBR.INFORMATION122
6678              ,P_DBR_ATTRIBUTE13      => r_DBR.INFORMATION123
6679              ,P_DBR_ATTRIBUTE14      => r_DBR.INFORMATION124
6680              ,P_DBR_ATTRIBUTE15      => r_DBR.INFORMATION125
6681              ,P_DBR_ATTRIBUTE16      => r_DBR.INFORMATION126
6682              ,P_DBR_ATTRIBUTE17      => r_DBR.INFORMATION127
6683              ,P_DBR_ATTRIBUTE18      => r_DBR.INFORMATION128
6684              ,P_DBR_ATTRIBUTE19      => r_DBR.INFORMATION129
6685              ,P_DBR_ATTRIBUTE2      => r_DBR.INFORMATION112
6686              ,P_DBR_ATTRIBUTE20      => r_DBR.INFORMATION130
6687              ,P_DBR_ATTRIBUTE21      => r_DBR.INFORMATION131
6688              ,P_DBR_ATTRIBUTE22      => r_DBR.INFORMATION132
6689              ,P_DBR_ATTRIBUTE23      => r_DBR.INFORMATION133
6690              ,P_DBR_ATTRIBUTE24      => r_DBR.INFORMATION134
6691              ,P_DBR_ATTRIBUTE25      => r_DBR.INFORMATION135
6692              ,P_DBR_ATTRIBUTE26      => r_DBR.INFORMATION136
6693              ,P_DBR_ATTRIBUTE27      => r_DBR.INFORMATION137
6694              ,P_DBR_ATTRIBUTE28      => r_DBR.INFORMATION138
6695              ,P_DBR_ATTRIBUTE29      => r_DBR.INFORMATION139
6696              ,P_DBR_ATTRIBUTE3      => r_DBR.INFORMATION113
6697              ,P_DBR_ATTRIBUTE30      => r_DBR.INFORMATION140
6698              ,P_DBR_ATTRIBUTE4      => r_DBR.INFORMATION114
6699              ,P_DBR_ATTRIBUTE5      => r_DBR.INFORMATION115
6700              ,P_DBR_ATTRIBUTE6      => r_DBR.INFORMATION116
6701              ,P_DBR_ATTRIBUTE7      => r_DBR.INFORMATION117
6702              ,P_DBR_ATTRIBUTE8      => r_DBR.INFORMATION118
6703              ,P_DBR_ATTRIBUTE9      => r_DBR.INFORMATION119
6704              ,P_DBR_ATTRIBUTE_CATEGORY      => r_DBR.INFORMATION110
6705              ,P_DSBLD_CD      => r_DBR.INFORMATION11
6706              ,P_DSBLD_RT_ID      => l_dsbld_rt_id
6707              ,P_EXCLD_FLAG      => r_DBR.INFORMATION12
6708              ,P_ORDR_NUM      => r_DBR.INFORMATION260
6709              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
6710              --
6711              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
6712              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
6713              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
6714            );
6715            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
6716            -- Update all relevent cer records with new pk_id
6717            hr_utility.set_location('Before plsql table ',222);
6718            hr_utility.set_location('new_value id '||l_dsbld_rt_id,222);
6719            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'DSBLD_RT_ID' ;
6720            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_DBR.information1 ;
6721            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_DSBLD_RT_ID ;
6722            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
6723            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_DBR_unique.table_route_id;
6724            hr_utility.set_location('After plsql table ',222);
6725            --
6726            -- 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 ) ;
6727            --
6728            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
6729            --
6730          else
6731            --
6732            -- Call Update routine for the pk_id created in prev run .
6733            --UPD START
6734            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
6735            --
6736            if l_update then
6737              --
6738              l_datetrack_mode := r_DBR.datetrack_mode ;
6739              --
6740              get_dt_modes(
6741                p_effective_date        => l_process_date,
6742                p_effective_end_date    => r_DBR.information3,
6743                p_effective_start_date  => r_DBR.information2,
6744                p_dml_operation         => r_DBR.dml_operation,
6745                p_datetrack_mode        => l_datetrack_mode );
6746            --    p_update                => l_update
6747              --
6748              l_effective_date := l_process_date;
6749              l_DSBLD_RT_ID   := r_DBR.information1;
6750              l_object_version_number := r_DBR.information265;
6751              --
6752            end if;
6753            --
6754            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
6755            --
6756            IF l_update OR l_dml_operation <> 'UPDATE' THEN
6757            --UPD END
6758            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
6759            hr_utility.set_location(' BEN_DSBLD_RT_F UPDATE_DSBLD_RT ',30);
6760            BEN_DSBLD_RT_API.UPDATE_DSBLD_RT(
6761              --
6762              P_VALIDATE               => false
6763              ,P_EFFECTIVE_DATE        => l_effective_date
6764              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
6765              --
6766              ,P_DBR_ATTRIBUTE1      => r_DBR.INFORMATION111
6767              ,P_DBR_ATTRIBUTE10      => r_DBR.INFORMATION120
6768              ,P_DBR_ATTRIBUTE11      => r_DBR.INFORMATION121
6769              ,P_DBR_ATTRIBUTE12      => r_DBR.INFORMATION122
6770              ,P_DBR_ATTRIBUTE13      => r_DBR.INFORMATION123
6771              ,P_DBR_ATTRIBUTE14      => r_DBR.INFORMATION124
6772              ,P_DBR_ATTRIBUTE15      => r_DBR.INFORMATION125
6773              ,P_DBR_ATTRIBUTE16      => r_DBR.INFORMATION126
6774              ,P_DBR_ATTRIBUTE17      => r_DBR.INFORMATION127
6775              ,P_DBR_ATTRIBUTE18      => r_DBR.INFORMATION128
6776              ,P_DBR_ATTRIBUTE19      => r_DBR.INFORMATION129
6777              ,P_DBR_ATTRIBUTE2      => r_DBR.INFORMATION112
6778              ,P_DBR_ATTRIBUTE20      => r_DBR.INFORMATION130
6779              ,P_DBR_ATTRIBUTE21      => r_DBR.INFORMATION131
6780              ,P_DBR_ATTRIBUTE22      => r_DBR.INFORMATION132
6781              ,P_DBR_ATTRIBUTE23      => r_DBR.INFORMATION133
6782              ,P_DBR_ATTRIBUTE24      => r_DBR.INFORMATION134
6783              ,P_DBR_ATTRIBUTE25      => r_DBR.INFORMATION135
6784              ,P_DBR_ATTRIBUTE26      => r_DBR.INFORMATION136
6785              ,P_DBR_ATTRIBUTE27      => r_DBR.INFORMATION137
6786              ,P_DBR_ATTRIBUTE28      => r_DBR.INFORMATION138
6787              ,P_DBR_ATTRIBUTE29      => r_DBR.INFORMATION139
6788              ,P_DBR_ATTRIBUTE3      => r_DBR.INFORMATION113
6789              ,P_DBR_ATTRIBUTE30      => r_DBR.INFORMATION140
6790              ,P_DBR_ATTRIBUTE4      => r_DBR.INFORMATION114
6791              ,P_DBR_ATTRIBUTE5      => r_DBR.INFORMATION115
6792              ,P_DBR_ATTRIBUTE6      => r_DBR.INFORMATION116
6793              ,P_DBR_ATTRIBUTE7      => r_DBR.INFORMATION117
6794              ,P_DBR_ATTRIBUTE8      => r_DBR.INFORMATION118
6795              ,P_DBR_ATTRIBUTE9      => r_DBR.INFORMATION119
6796              ,P_DBR_ATTRIBUTE_CATEGORY      => r_DBR.INFORMATION110
6797              ,P_DSBLD_CD      => r_DBR.INFORMATION11
6798              ,P_DSBLD_RT_ID      => l_dsbld_rt_id
6799              ,P_EXCLD_FLAG      => r_DBR.INFORMATION12
6800              ,P_ORDR_NUM      => r_DBR.INFORMATION260
6801              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
6802              --
6803              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
6804              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
6805              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
6806              ,P_DATETRACK_MODE        => l_datetrack_mode
6807            );
6808            --
6809            end if;
6810          end if;
6811          --
6812          -- Delete the row if it is end dated.
6813          --
6814          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
6815              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
6816              trunc(l_max_eed) = r_DBR.information3) then
6817              --
6818              BEN_DSBLD_RT_API.delete_DSBLD_RT(
6819                 --
6820                 p_validate                       => false
6821                 ,p_dsbld_rt_id                   => l_dsbld_rt_id
6822                 ,p_effective_start_date           => l_effective_start_date
6823                 ,p_effective_end_date             => l_effective_end_date
6824                 ,p_object_version_number          => l_object_version_number
6825                 ,p_effective_date                 => l_max_eed
6826                 ,p_datetrack_mode                 => hr_api.g_delete
6827                 --
6828                 );
6829                 --
6830          end if;
6831          --
6832          l_prev_pk_id := l_current_pk_id ;
6833          --
6834        end if;
6835        --
6836      end if;
6837      --
6838    end loop;
6839    --
6840  exception when others then
6841     --
6842     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'DBR',r_dbr.information5 );
6843     --
6844  end create_DBR_rows;
6845 
6846    --
6847    ---------------------------------------------------------------
6848    ----------------------< create_CTY_rows >-----------------------
6849    ---------------------------------------------------------------
6850    --
6851    procedure create_CTY_rows
6852    (
6853          p_validate                       in  number     default 0
6854         ,p_copy_entity_txn_id             in  number
6855         ,p_effective_date                 in  date
6856         ,p_prefix_suffix_text             in  varchar2  default null
6857         ,p_reuse_object_flag              in  varchar2  default null
6858         ,p_target_business_group_id       in  varchar2  default null
6859         ,p_prefix_suffix_cd               in  varchar2  default null
6860    ) is
6861    --
6862    l_COMPETENCE_ID  number;
6863    l_RATING_LEVEL_ID  number;
6864    l_VRBL_RT_PRFL_ID  number;
6865    l_EXCLD_FLAG       varchar2(100);
6866    l_ORDR_NUM         number;
6867    --
6868    cursor c_unique_CTY(l_table_alias varchar2) is
6869    select distinct cpe.information1,
6870      cpe.information2,
6871      cpe.information3,
6872      cpe.table_route_id
6873    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
6874         pqh_table_route tr
6875    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
6876    and   cpe.table_route_id     = tr.table_route_id
6877    -- and   tr.where_clause        = l_BEN_COMPTNCY_RT_F
6878    and tr.table_alias = l_table_alias
6879    and   cpe.number_of_copies   = 1 -- ADDITION
6880    group by cpe.information1,cpe.information2,cpe.information3,  cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
6881    order by information1, information2; --added for bug: 5151945
6882    --
6883    --
6884    cursor c_CTY_min_max_dates(c_table_route_id  number,
6885                 c_information1   Number) is
6886    select
6887      min(cpe.information2) min_esd,
6888      max(cpe.information3) min_eed
6889    from ben_copy_entity_results cpe
6890    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
6891    and   cpe.table_route_id     = c_table_route_id
6892    and   cpe.information1       = c_information1 ;
6893    --
6894    cursor c_CTY(c_table_route_id  number,
6895                 c_information1   number,
6896                 c_information2   Date,
6897                 c_information3   Date)  is
6898    select
6899      cpe.*
6900    from ben_copy_entity_results cpe
6901    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
6902    and   cpe.table_route_id     = c_table_route_id
6903    and   cpe.information1       = c_information1
6904    and   cpe.information2       = c_information2
6905    and   cpe.information3       = c_information3
6906    and rownum = 1 ;
6907    -- Date Track target record
6908    cursor c_find_CTY_in_target(
6909                                 c_effective_start_date    date,
6910                                 c_effective_end_date      date,
6911                                 c_business_group_id       number,
6912                                 c_new_pk_id               number) is
6913    select
6914      CTY.comptncy_rt_id new_value
6915    from BEN_COMPTNCY_RT_F CTY
6916    where
6917    CTY.COMPETENCE_ID     = l_COMPETENCE_ID  and
6918    CTY.RATING_LEVEL_ID     =l_RATING_LEVEL_ID  and
6919    CTY.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID and
6920    CTY.ORDR_NUM           = l_ORDR_NUM and
6921    CTY.business_group_id  = c_business_group_id
6922    and   CTY.comptncy_rt_id  <> c_new_pk_id
6923 --TEMPIK
6924    and c_effective_start_date between effective_start_date
6925                             and effective_end_date ;
6926 --END TEMPIK
6927 /*TEMPIK
6928    and exists ( select null
6929                 from BEN_COMPTNCY_RT_F CTY1
6930                 where
6931                 CTY1.COMPETENCE_ID     = l_COMPETENCE_ID  and
6932                 CTY1.RATING_LEVEL_ID    =l_RATING_LEVEL_ID  and
6933                 CTY1.VRBL_RT_PRFL_ID =    l_VRBL_RT_PRFL_ID and
6934                 CTY1.ORDR_NUM           = l_ORDR_NUM and
6935                 CTY1.business_group_id  = c_business_group_id
6936                 and   CTY1.effective_start_date <= c_effective_start_date )
6937    and exists ( select null
6938                 from BEN_COMPTNCY_RT_F CTY2
6939                 where
6940                 CTY2.COMPETENCE_ID     = l_COMPETENCE_ID  and
6941                 CTY2.RATING_LEVEL_ID     = l_RATING_LEVEL_ID  and
6942                 CTY2.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
6943                 CTY2.ORDR_NUM           = l_ORDR_NUM and
6944                 CTY2.business_group_id  = c_business_group_id
6945                 and   CTY2.effective_end_date >= c_effective_end_date )
6946                 ;
6947 TEMPIK */
6948    --TEMPIK
6949    l_dt_rec_found            boolean ;
6950    --END TEMPIK
6951    --
6952    l_current_pk_id           number := null ;
6953    --UPD START
6954    --
6955    l_update                  boolean      := false ;
6956    l_datetrack_mode          varchar2(80) := hr_api.g_update;
6957    l_process_date            date;
6958    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
6959    --
6960    --UPD END
6961    l_prev_pk_id              number := null ;
6962    l_first_rec               boolean := true ;
6963    r_CTY                     c_CTY%rowtype;
6964    l_comptncy_rt_id             number ;
6965    l_object_version_number   number ;
6966    l_effective_start_date    date ;
6967 --       l_ORDR_NUM         := r_GNR.information12;
6968 --       l_EXCLD_FLAG      := r_GNR.information11;
6969    l_effective_end_date      date ;
6970    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
6971    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
6972    l_new_value               number(15);
6973    l_object_found_in_target  boolean := false ;
6974    l_min_esd                 date;
6975    l_max_eed                 date;
6976    l_effective_date          date;
6977    --
6978  begin
6979    -- Initialization
6980    l_object_found_in_target := false ;
6981    -- End Initialization
6982    -- Derive the prefix - sufix
6983    if   p_prefix_suffix_cd = 'PREFIX' then
6984      l_prefix  := p_prefix_suffix_text ;
6985    elsif p_prefix_suffix_cd = 'SUFFIX' then
6986      l_suffix   := p_prefix_suffix_text ;
6987    else
6988      l_prefix := null ;
6989      l_suffix  := null ;
6990    end if ;
6991    -- End Prefix Sufix derivation
6992    for r_CTY_unique in c_unique_CTY('CTY') loop
6993 
6994      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
6995         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
6996          r_CTY_unique.information3 >=
6997                  ben_pd_copy_to_ben_one.g_copy_effective_date)
6998         ) then
6999        --
7000        hr_utility.set_location(' r_CTY_unique.table_route_id '||r_CTY_unique.table_route_id,10);
7001        hr_utility.set_location(' r_CTY_unique.information1 '||r_CTY_unique.information1,10);
7002        hr_utility.set_location( 'r_CTY_unique.information2 '||r_CTY_unique.information2,10);
7003        hr_utility.set_location( 'r_CTY_unique.information3 '||r_CTY_unique.information3,10);
7004        -- If reuse objects flag is 'Y' then check for the object in the target business group
7005        -- if found insert the record into PLSql table and exit the loop else try create the
7006        -- object in the target business group
7007        --
7008        l_object_found_in_target := false ;
7009        l_min_esd := null ;
7010        l_max_eed := null ;
7011        open c_CTY_min_max_dates(r_CTY_unique.table_route_id, r_CTY_unique.information1 ) ;
7012        fetch c_CTY_min_max_dates into l_min_esd,l_max_eed ;
7013        --
7014 
7015        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
7016             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
7017          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
7018        end if;
7019        l_min_esd := greatest(l_min_esd,r_CTY_unique.information2);
7020        open c_CTY(r_CTY_unique.table_route_id,
7021                 r_CTY_unique.information1,
7022                 r_CTY_unique.information2,
7023                 r_CTY_unique.information3 ) ;
7024        --
7025        fetch c_CTY into r_CTY ;
7026        --
7027        close c_CTY ;
7028        --
7029        --Mapping Related
7030        --
7031        if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
7032          l_COMPETENCE_ID := r_CTY.information176;
7033        else
7034          l_COMPETENCE_ID := r_CTY.information174;
7035        end if;
7036        --
7037        if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
7038        l_RATING_LEVEL_ID := r_CTY.information180;
7039        else
7040          l_RATING_LEVEL_ID := r_CTY.information178;
7041        end if;
7042        --
7043        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_CTY.INFORMATION262,r_CTY_unique.dml_operation);
7044        l_ORDR_NUM         := r_CTY.INFORMATION260;
7045        l_EXCLD_FLAG      := r_CTY.INFORMATION11;
7046 
7047        if l_COMPETENCE_ID is null or l_RATING_LEVEL_ID is null then
7048          close c_CTY_min_max_dates;
7049          --
7050          log_nomapping_data(p_parent_table_alias =>'VPF'
7051                      ,p_parent_pk_id         => r_CTY.information262
7052                      ,p_copy_entity_txn_id   => p_copy_entity_txn_id
7053                      ,p_child_table_alias    => 'CTY'
7054                      ,p_child_data           => r_CTY.information173 );
7055 
7056          --
7057        else
7058        --UPD START
7059        l_update := false;
7060        l_process_date := p_effective_date;
7061        l_dml_operation:= r_CTY_unique.dml_operation ;
7062        --
7063        if l_dml_operation = 'UPDATE' then
7064          --
7065          l_object_found_in_target := TRUE;
7066          --
7067          if l_process_date between r_CTY_unique.information2 and r_CTY_unique.information3 then
7068                l_update := true;
7069                if r_CTY_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
7070                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'COMPTNCY_RT_ID'
7071                then
7072                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'COMPTNCY_RT_ID' ;
7073                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_CTY_unique.information1 ;
7074                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_CTY_unique.information1 ;
7075                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
7076                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_CTY_unique.table_route_id;
7077                   --
7078                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
7079                   --
7080                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
7081                   --
7082                   --log_data('CTY',l_new_value,l_prefix || r_CTY_unique.name|| l_suffix,'REUSED');
7083                   --
7084                end if ;
7085                hr_utility.set_location( 'found record for update',10);
7086            --
7087          else
7088            --
7089            l_update := false;
7090            --
7091          end if;
7092        else
7093          --
7094          --UPD END
7095          if p_reuse_object_flag = 'Y' then
7096            if c_CTY_min_max_dates%found then
7097               -- cursor to find the object
7098               open c_find_CTY_in_target( l_min_esd,l_max_eed,
7099                                     p_target_business_group_id, nvl(l_comptncy_rt_id, -999)  ) ;
7100               fetch c_find_CTY_in_target into l_new_value ;
7101               if c_find_CTY_in_target%found then
7102                 --
7103              --TEMPIK
7104              l_dt_rec_found :=   dt_api.check_min_max_dates
7105                  (p_base_table_name => 'BEN_COMPTNCY_RT_F',
7106                   p_base_key_column => 'COMPTNCY_RT_ID',
7107                   p_base_key_value  => l_new_value,
7108                   p_from_date       => l_min_esd,
7109                   p_to_date         => l_max_eed );
7110              if l_dt_rec_found THEN
7111              --END TEMPIK
7112                 if r_CTY_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
7113                    nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'COMPTNCY_RT_ID'  then
7114                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'COMPTNCY_RT_ID' ;
7115                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_CTY_unique.information1 ;
7116                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
7117                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
7118                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_CTY_unique.table_route_id;
7119                    --
7120                    -- 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) ;
7121                    --
7122                    BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
7123                 end if ;
7124                 --
7125                 l_object_found_in_target := true ;
7126              --TEMPIK
7127              end if; -- l_dt_rec_found
7128              --END TEMPIK
7129               end if;
7130               close c_find_CTY_in_target ;
7131            --
7132            end if;
7133          end if ;
7134          --
7135          end if;
7136          close c_CTY_min_max_dates ;
7137          if not l_object_found_in_target OR l_update   then
7138            --
7139            l_current_pk_id := r_CTY.information1;
7140            --
7141            hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
7142            hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
7143            --
7144            if l_current_pk_id =  l_prev_pk_id  then
7145              --
7146              l_first_rec := false ;
7147              --
7148            else
7149              --
7150              l_first_rec := true ;
7151              --
7152            end if ;
7153            --
7154 
7155            l_effective_date := r_CTY.information2;
7156            if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
7157                 l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
7158              l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
7159            end if;
7160 
7161            if l_first_rec and not l_update then
7162              -- Call Create routine.
7163              hr_utility.set_location(' BEN_COMPTNCY_RT_F CREATE_COMPTNCY_RT ',20);
7164              BEN_COMPTNCY_RT_API.CREATE_COMPTNCY_RT(
7165                 --
7166                 P_VALIDATE               => false
7167                 ,P_EFFECTIVE_DATE        => l_effective_date
7168                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
7169                 --
7170              ,P_COMPETENCE_ID      => l_COMPETENCE_ID
7171              ,P_COMPTNCY_RT_ID      => l_comptncy_rt_id
7172              ,P_CTY_ATTRIBUTE1      => r_CTY.INFORMATION111
7173              ,P_CTY_ATTRIBUTE10      => r_CTY.INFORMATION120
7174              ,P_CTY_ATTRIBUTE11      => r_CTY.INFORMATION121
7175              ,P_CTY_ATTRIBUTE12      => r_CTY.INFORMATION122
7176              ,P_CTY_ATTRIBUTE13      => r_CTY.INFORMATION123
7177              ,P_CTY_ATTRIBUTE14      => r_CTY.INFORMATION124
7178              ,P_CTY_ATTRIBUTE15      => r_CTY.INFORMATION125
7179              ,P_CTY_ATTRIBUTE16      => r_CTY.INFORMATION126
7180              ,P_CTY_ATTRIBUTE17      => r_CTY.INFORMATION127
7181              ,P_CTY_ATTRIBUTE18      => r_CTY.INFORMATION128
7182              ,P_CTY_ATTRIBUTE19      => r_CTY.INFORMATION129
7183              ,P_CTY_ATTRIBUTE2      => r_CTY.INFORMATION112
7184              ,P_CTY_ATTRIBUTE20      => r_CTY.INFORMATION130
7185              ,P_CTY_ATTRIBUTE21      => r_CTY.INFORMATION131
7186              ,P_CTY_ATTRIBUTE22      => r_CTY.INFORMATION132
7187              ,P_CTY_ATTRIBUTE23      => r_CTY.INFORMATION133
7188              ,P_CTY_ATTRIBUTE24      => r_CTY.INFORMATION134
7189              ,P_CTY_ATTRIBUTE25      => r_CTY.INFORMATION135
7190              ,P_CTY_ATTRIBUTE26      => r_CTY.INFORMATION136
7191              ,P_CTY_ATTRIBUTE27      => r_CTY.INFORMATION137
7192              ,P_CTY_ATTRIBUTE28      => r_CTY.INFORMATION138
7193              ,P_CTY_ATTRIBUTE29      => r_CTY.INFORMATION139
7194              ,P_CTY_ATTRIBUTE3      => r_CTY.INFORMATION113
7195              ,P_CTY_ATTRIBUTE30      => r_CTY.INFORMATION140
7196              ,P_CTY_ATTRIBUTE4      => r_CTY.INFORMATION114
7197              ,P_CTY_ATTRIBUTE5      => r_CTY.INFORMATION115
7198              ,P_CTY_ATTRIBUTE6      => r_CTY.INFORMATION116
7199              ,P_CTY_ATTRIBUTE7      => r_CTY.INFORMATION117
7200              ,P_CTY_ATTRIBUTE8      => r_CTY.INFORMATION118
7201              ,P_CTY_ATTRIBUTE9      => r_CTY.INFORMATION119
7202              ,P_CTY_ATTRIBUTE_CATEGORY      => r_CTY.INFORMATION110
7203              ,P_EXCLD_FLAG      => r_CTY.INFORMATION11
7204              ,P_ORDR_NUM      => r_CTY.INFORMATION260
7205              ,P_RATING_LEVEL_ID      => l_RATING_LEVEL_ID
7206              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
7207                 --
7208                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
7209                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
7210                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
7211              );
7212              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
7213              -- Update all relevent cer records with new pk_id
7214              hr_utility.set_location('Before plsql table ',222);
7215              hr_utility.set_location('new_value id '||l_comptncy_rt_id,222);
7216              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'COMPTNCY_RT_ID' ;
7217              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_CTY.information1 ;
7218              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_COMPTNCY_RT_ID ;
7219              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
7220              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_CTY_unique.table_route_id;
7221              hr_utility.set_location('After plsql table ',222);
7222              --
7223              -- 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 ) ;
7224              --
7225              BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
7226              --
7227            else
7228              --
7229              -- Call Update routine for the pk_id created in prev run .
7230            --UPD START
7231            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
7232            --
7233            if l_update then
7234              --
7235              l_datetrack_mode := r_CTY.datetrack_mode ;
7236              --
7237              get_dt_modes(
7238                p_effective_date        => l_process_date,
7239                p_effective_end_date    => r_CTY.information3,
7240                p_effective_start_date  => r_CTY.information2,
7241                p_dml_operation         => r_CTY.dml_operation,
7242                p_datetrack_mode        => l_datetrack_mode );
7243            --    p_update                => l_update
7244              --
7245              l_effective_date := l_process_date;
7246              l_COMPTNCY_RT_ID   := r_CTY.information1;
7247              l_object_version_number := r_CTY.information265;
7248              --
7249            end if;
7250            --
7251            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
7252            --
7253            IF l_update OR l_dml_operation <> 'UPDATE' THEN
7254            --UPD END
7255              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
7256              hr_utility.set_location(' BEN_COMPTNCY_RT_F UPDATE_COMPTNCY_RT ',30);
7257              BEN_COMPTNCY_RT_API.UPDATE_COMPTNCY_RT(
7258                 --
7259                 P_VALIDATE               => false
7260                 ,P_EFFECTIVE_DATE        => l_effective_date
7261                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
7262                 --
7263              ,P_COMPETENCE_ID      => l_COMPETENCE_ID
7264              ,P_COMPTNCY_RT_ID      => l_comptncy_rt_id
7265              ,P_CTY_ATTRIBUTE1      => r_CTY.INFORMATION111
7266              ,P_CTY_ATTRIBUTE10      => r_CTY.INFORMATION120
7267              ,P_CTY_ATTRIBUTE11      => r_CTY.INFORMATION121
7268              ,P_CTY_ATTRIBUTE12      => r_CTY.INFORMATION122
7269              ,P_CTY_ATTRIBUTE13      => r_CTY.INFORMATION123
7270              ,P_CTY_ATTRIBUTE14      => r_CTY.INFORMATION124
7271              ,P_CTY_ATTRIBUTE15      => r_CTY.INFORMATION125
7272              ,P_CTY_ATTRIBUTE16      => r_CTY.INFORMATION126
7273              ,P_CTY_ATTRIBUTE17      => r_CTY.INFORMATION127
7274              ,P_CTY_ATTRIBUTE18      => r_CTY.INFORMATION128
7275              ,P_CTY_ATTRIBUTE19      => r_CTY.INFORMATION129
7276              ,P_CTY_ATTRIBUTE2      => r_CTY.INFORMATION112
7277              ,P_CTY_ATTRIBUTE20      => r_CTY.INFORMATION130
7278              ,P_CTY_ATTRIBUTE21      => r_CTY.INFORMATION131
7279              ,P_CTY_ATTRIBUTE22      => r_CTY.INFORMATION132
7280              ,P_CTY_ATTRIBUTE23      => r_CTY.INFORMATION133
7281              ,P_CTY_ATTRIBUTE24      => r_CTY.INFORMATION134
7282              ,P_CTY_ATTRIBUTE25      => r_CTY.INFORMATION135
7283              ,P_CTY_ATTRIBUTE26      => r_CTY.INFORMATION136
7284              ,P_CTY_ATTRIBUTE27      => r_CTY.INFORMATION137
7285              ,P_CTY_ATTRIBUTE28      => r_CTY.INFORMATION138
7286              ,P_CTY_ATTRIBUTE29      => r_CTY.INFORMATION139
7287              ,P_CTY_ATTRIBUTE3      => r_CTY.INFORMATION113
7288              ,P_CTY_ATTRIBUTE30      => r_CTY.INFORMATION140
7289              ,P_CTY_ATTRIBUTE4      => r_CTY.INFORMATION114
7290              ,P_CTY_ATTRIBUTE5      => r_CTY.INFORMATION115
7291              ,P_CTY_ATTRIBUTE6      => r_CTY.INFORMATION116
7292              ,P_CTY_ATTRIBUTE7      => r_CTY.INFORMATION117
7293              ,P_CTY_ATTRIBUTE8      => r_CTY.INFORMATION118
7294              ,P_CTY_ATTRIBUTE9      => r_CTY.INFORMATION119
7295              ,P_CTY_ATTRIBUTE_CATEGORY      => r_CTY.INFORMATION110
7296              ,P_EXCLD_FLAG      => r_CTY.INFORMATION11
7297              ,P_ORDR_NUM      => r_CTY.INFORMATION260
7298              ,P_RATING_LEVEL_ID      => l_RATING_LEVEL_ID
7299              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
7300                 --
7301                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
7302                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
7303                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
7304                 ,P_DATETRACK_MODE        => l_datetrack_mode
7305              );
7306              --
7307              end if;
7308            end if;
7309            --
7310            -- Delete the row if it is end dated.
7311            --
7312            if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
7313              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
7314                 trunc(l_max_eed) = r_CTY.information3) then
7315                 --
7316                 BEN_COMPTNCY_RT_API.delete_COMPTNCY_RT(
7317                    --
7318                    p_validate                       => false
7319                    ,p_comptncy_rt_id                   => l_comptncy_rt_id
7320                    ,p_effective_start_date           => l_effective_start_date
7321                    ,p_effective_end_date             => l_effective_end_date
7322                    ,p_object_version_number          => l_object_version_number
7323                    ,p_effective_date                 => l_max_eed
7324                    ,p_datetrack_mode                 => hr_api.g_delete
7325                    --
7326                    );
7327                    --
7328            end if;
7329            --
7330            l_prev_pk_id := l_current_pk_id ;
7331            --
7332          end if;
7333          --
7334        end if;
7335        --
7336      end if;
7337      --
7338    end loop;
7339    --
7340  exception when others then
7341     --
7342     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'CTY',r_cty.information5 );
7343     --
7344  end create_CTY_rows;
7345 
7346    --
7347    ---------------------------------------------------------------
7348    ----------------------< create_LMM_rows >-----------------------
7349    ---------------------------------------------------------------
7350    --
7351    procedure create_LMM_rows
7352    (
7353          p_validate                       in  number     default 0
7354         ,p_copy_entity_txn_id             in  number
7355         ,p_effective_date                 in  date
7356         ,p_prefix_suffix_text             in  varchar2  default null
7357         ,p_reuse_object_flag              in  varchar2  default null
7358         ,p_target_business_group_id       in  varchar2  default null
7359         ,p_prefix_suffix_cd               in  varchar2  default null
7360    ) is
7361    --
7362    l_VRBL_RT_PRFL_ID  number;
7363    l_lbr_mmbr_flag   ben_lbr_mmbr_rt_f.lbr_mmbr_flag%type;
7364    cursor c_unique_LMM(l_table_alias varchar2) is
7365    select distinct cpe.information1,
7366      cpe.information2,
7367      cpe.information3,
7368      cpe.table_route_id
7369    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
7370         pqh_table_route tr
7371    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
7372    and   cpe.table_route_id     = tr.table_route_id
7373    -- and   tr.where_clause        = l_BEN_LBR_MMBR_RT_F
7374    and tr.table_alias = l_table_alias
7375    and   cpe.number_of_copies   = 1 -- ADDITION
7376    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
7377    order by information1, information2; --added for bug: 5151945
7378    --
7379    --
7380    cursor c_LMM_min_max_dates(c_table_route_id  number,
7381                 c_information1   Number) is
7382    select
7383      min(cpe.information2) min_esd,
7384      max(cpe.information3) min_eed
7385    from ben_copy_entity_results cpe
7386    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
7387    and   cpe.table_route_id     = c_table_route_id
7388    and   cpe.information1       = c_information1 ;
7389    --
7390    cursor c_LMM(c_table_route_id  number,
7391                 c_information1   number,
7392                 c_information2   Date,
7393                 c_information3   Date)  is
7394    select
7395      cpe.*
7396    from ben_copy_entity_results cpe
7397    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
7398    and   cpe.table_route_id     = c_table_route_id
7399    and   cpe.information1       = c_information1
7400    and   cpe.information2       = c_information2
7401    and   cpe.information3       = c_information3
7402    and rownum = 1 ;
7403    -- Date Track target record
7404    cursor c_find_LMM_in_target(
7405                                 c_effective_start_date    date,
7406                                 c_effective_end_date      date,
7407                                 c_business_group_id       number,
7408                                 c_new_pk_id               number) is
7409    select
7410      LMM.lbr_mmbr_rt_id new_value
7411    from BEN_LBR_MMBR_RT_F LMM
7412    where
7413    LMM.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
7414    LMM.business_group_id  = c_business_group_id
7415    and   LMM.lbr_mmbr_rt_id  <> c_new_pk_id
7416    and   LMM.lbr_mmbr_flag = l_lbr_mmbr_flag
7417 --TEMPIK
7418    and c_effective_start_date between effective_start_date
7419                             and effective_end_date ;
7420 --END TEMPIK
7421 /*TEMPIK
7422    and exists ( select null
7423                 from BEN_LBR_MMBR_RT_F LMM1
7424                 where
7425                 LMM1.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
7426                 LMM1.business_group_id  = c_business_group_id
7427                 and   LMM1.effective_start_date <= c_effective_start_date
7428                 and   LMM1.lbr_mmbr_flag = l_lbr_mmbr_flag )
7429    and exists ( select null
7430                 from BEN_LBR_MMBR_RT_F LMM2
7431                 where
7432                 LMM2.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
7433                 LMM2.business_group_id  = c_business_group_id
7434                 and   LMM2.effective_end_date >= c_effective_end_date
7435                 and   LMM2.lbr_mmbr_flag = l_lbr_mmbr_flag )
7436                 ;
7437 TEMPIK */
7438    --TEMPIK
7439    l_dt_rec_found            boolean ;
7440    --END TEMPIK
7441    --
7442    l_current_pk_id           number := null ;
7443    --UPD START
7444    --
7445    l_update                  boolean      := false ;
7446    l_datetrack_mode          varchar2(80) := hr_api.g_update;
7447    l_process_date            date;
7448    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
7449    --
7450    --UPD END
7451    l_prev_pk_id              number := null ;
7452    l_first_rec               boolean := true ;
7453    r_LMM                     c_LMM%rowtype;
7454    l_lbr_mmbr_rt_id             number ;
7455    l_object_version_number   number ;
7456    l_effective_start_date    date ;
7457    l_effective_end_date      date ;
7458    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
7459    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
7460    l_new_value               number(15);
7461    l_object_found_in_target  boolean := false ;
7462    l_min_esd                 date;
7463    l_max_eed                 date;
7464    l_effective_date          date;
7465    --
7466  begin
7467    -- Initialization
7468    l_object_found_in_target := false ;
7469    -- End Initialization
7470    -- Derive the prefix - sufix
7471    if   p_prefix_suffix_cd = 'PREFIX' then
7472      l_prefix  := p_prefix_suffix_text ;
7473    elsif p_prefix_suffix_cd = 'SUFFIX' then
7474      l_suffix   := p_prefix_suffix_text ;
7475    else
7476      l_prefix := null ;
7477      l_suffix  := null ;
7478    end if ;
7479    -- End Prefix Sufix derivation
7480    for r_LMM_unique in c_unique_LMM('LMM') loop
7481 
7482      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
7483         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
7484          r_LMM_unique.information3 >=
7485                  ben_pd_copy_to_ben_one.g_copy_effective_date)
7486           ) then
7487        --
7488        hr_utility.set_location(' r_LMM_unique.table_route_id '||r_LMM_unique.table_route_id,10);
7489        hr_utility.set_location(' r_LMM_unique.information1 '||r_LMM_unique.information1,10);
7490        hr_utility.set_location( 'r_LMM_unique.information2 '||r_LMM_unique.information2,10);
7491        hr_utility.set_location( 'r_LMM_unique.information3 '||r_LMM_unique.information3,10);
7492        -- If reuse objects flag is 'Y' then check for the object in the target business group
7493        -- if found insert the record into PLSql table and exit the loop else try create the
7494        -- object in the target business group
7495        --
7496        l_object_found_in_target := false ;
7497        l_min_esd := null ;
7498        l_max_eed := null ;
7499        open c_LMM_min_max_dates(r_LMM_unique.table_route_id, r_LMM_unique.information1 ) ;
7500        fetch c_LMM_min_max_dates into l_min_esd,l_max_eed ;
7501        --
7502 
7503        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
7504             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
7505          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
7506        end if;
7507        l_min_esd := greatest(l_min_esd,r_LMM_unique.information2);
7508        open c_LMM(r_LMM_unique.table_route_id,
7509                 r_LMM_unique.information1,
7510                 r_LMM_unique.information2,
7511                 r_LMM_unique.information3 ) ;
7512        --
7513        fetch c_LMM into r_LMM ;
7514        --
7515        close c_LMM ;
7516        --
7517        l_lbr_mmbr_flag := r_LMM.information12;
7518        --
7519        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_LMM.INFORMATION262,r_LMM_unique.dml_operation);
7520        --UPD START
7521        l_update := false;
7522        l_process_date := p_effective_date;
7523        l_dml_operation:= r_LMM_unique.dml_operation ;
7524        --
7525        if l_dml_operation = 'UPDATE' then
7526          --
7527          l_object_found_in_target := TRUE;
7528          --
7529          if l_process_date between r_LMM_unique.information2 and r_LMM_unique.information3 then
7530                l_update := true;
7531                if r_LMM_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
7532                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'LBR_MMBR_RT_ID'
7533                then
7534                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'LBR_MMBR_RT_ID' ;
7535                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_LMM_unique.information1 ;
7536                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_LMM_unique.information1 ;
7537                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
7538                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_LMM_unique.table_route_id;
7539                   --
7540                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
7541                   --
7542                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
7543                   --
7544                   -- log_data('LMM',l_new_value,l_prefix || r_LMM_unique.name|| l_suffix,'REUSED');
7545                   --
7546                end if ;
7547                hr_utility.set_location( 'found record for update',10);
7548            --
7549          else
7550            --
7551            l_update := false;
7552            --
7553          end if;
7554        else
7555          --
7556          --UPD END
7557        if p_reuse_object_flag = 'Y' then
7558          if c_LMM_min_max_dates%found then
7559            -- cursor to find the object
7560            open c_find_LMM_in_target( l_min_esd,l_max_eed,
7561                                  p_target_business_group_id, nvl(l_lbr_mmbr_rt_id, -999)  ) ;
7562            fetch c_find_LMM_in_target into l_new_value ;
7563            if c_find_LMM_in_target%found then
7564              --
7565              --TEMPIK
7566              l_dt_rec_found :=   dt_api.check_min_max_dates
7567                  (p_base_table_name => 'BEN_LBR_MMBR_RT_F',
7568                   p_base_key_column => 'LBR_MMBR_RT_ID',
7569                   p_base_key_value  => l_new_value,
7570                   p_from_date       => l_min_esd,
7571                   p_to_date         => l_max_eed );
7572              if l_dt_rec_found THEN
7573              --END TEMPIK
7574              if r_LMM_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
7575                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'LBR_MMBR_RT_ID'  then
7576                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'LBR_MMBR_RT_ID' ;
7577                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_LMM_unique.information1 ;
7578                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
7579                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
7580                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_LMM_unique.table_route_id;
7581                 --
7582                 -- 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) ;
7583                 --
7584                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
7585              end if ;
7586              --
7587              l_object_found_in_target := true ;
7588              --TEMPIK
7589              end if; -- l_dt_rec_found
7590              --END TEMPIK
7591            end if;
7592            close c_find_LMM_in_target ;
7593          --
7594          end if;
7595        end if ;
7596        --
7597        end if;
7598        close c_LMM_min_max_dates ;
7599        if not l_object_found_in_target OR l_update   then
7600          --
7601          l_current_pk_id := r_LMM.information1;
7602          --
7603          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
7604          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
7605          --
7606          if l_current_pk_id =  l_prev_pk_id  then
7607            --
7608            l_first_rec := false ;
7609            --
7610          else
7611            --
7612            l_first_rec := true ;
7613            --
7614          end if ;
7615          --
7616 
7617          l_effective_date := r_LMM.information2;
7618          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
7619               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
7620            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
7621          end if;
7622 
7623          if l_first_rec and not l_update then
7624            -- Call Create routine.
7625            hr_utility.set_location(' BEN_LBR_MMBR_RT_F CREATE_LABOR_MEMBER_RATE ',20);
7626            BEN_LABOR_MEMBER_RATE_API.CREATE_LABOR_MEMBER_RATE(
7627              --
7628              P_VALIDATE               => false
7629              ,P_EFFECTIVE_DATE        => l_effective_date
7630              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
7631              --
7632              ,P_EXCLD_FLAG      => r_LMM.INFORMATION12
7633              ,P_LBR_MMBR_FLAG      => r_LMM.INFORMATION11
7634              ,P_LBR_MMBR_RT_ID      => l_lbr_mmbr_rt_id
7635              ,P_LMM_ATTRIBUTE1      => r_LMM.INFORMATION111
7636              ,P_LMM_ATTRIBUTE10      => r_LMM.INFORMATION120
7637              ,P_LMM_ATTRIBUTE11      => r_LMM.INFORMATION121
7638              ,P_LMM_ATTRIBUTE12      => r_LMM.INFORMATION122
7639              ,P_LMM_ATTRIBUTE13      => r_LMM.INFORMATION123
7640              ,P_LMM_ATTRIBUTE14      => r_LMM.INFORMATION124
7641              ,P_LMM_ATTRIBUTE15      => r_LMM.INFORMATION125
7642              ,P_LMM_ATTRIBUTE16      => r_LMM.INFORMATION126
7643              ,P_LMM_ATTRIBUTE17      => r_LMM.INFORMATION127
7644              ,P_LMM_ATTRIBUTE18      => r_LMM.INFORMATION128
7645              ,P_LMM_ATTRIBUTE19      => r_LMM.INFORMATION129
7646              ,P_LMM_ATTRIBUTE2      => r_LMM.INFORMATION112
7647              ,P_LMM_ATTRIBUTE20      => r_LMM.INFORMATION130
7648              ,P_LMM_ATTRIBUTE21      => r_LMM.INFORMATION131
7649              ,P_LMM_ATTRIBUTE22      => r_LMM.INFORMATION132
7650              ,P_LMM_ATTRIBUTE23      => r_LMM.INFORMATION133
7651              ,P_LMM_ATTRIBUTE24      => r_LMM.INFORMATION134
7652              ,P_LMM_ATTRIBUTE25      => r_LMM.INFORMATION135
7653              ,P_LMM_ATTRIBUTE26      => r_LMM.INFORMATION136
7654              ,P_LMM_ATTRIBUTE27      => r_LMM.INFORMATION137
7655              ,P_LMM_ATTRIBUTE28      => r_LMM.INFORMATION138
7656              ,P_LMM_ATTRIBUTE29      => r_LMM.INFORMATION139
7657              ,P_LMM_ATTRIBUTE3      => r_LMM.INFORMATION113
7658              ,P_LMM_ATTRIBUTE30      => r_LMM.INFORMATION140
7659              ,P_LMM_ATTRIBUTE4      => r_LMM.INFORMATION114
7660              ,P_LMM_ATTRIBUTE5      => r_LMM.INFORMATION115
7661              ,P_LMM_ATTRIBUTE6      => r_LMM.INFORMATION116
7662              ,P_LMM_ATTRIBUTE7      => r_LMM.INFORMATION117
7663              ,P_LMM_ATTRIBUTE8      => r_LMM.INFORMATION118
7664              ,P_LMM_ATTRIBUTE9      => r_LMM.INFORMATION119
7665              ,P_LMM_ATTRIBUTE_CATEGORY      => r_LMM.INFORMATION110
7666              ,P_ORDR_NUM      => r_LMM.INFORMATION257
7667              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
7668              --
7669              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
7670              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
7671              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
7672            );
7673            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
7674            -- Update all relevent cer records with new pk_id
7675            hr_utility.set_location('Before plsql table ',222);
7676            hr_utility.set_location('new_value id '||l_lbr_mmbr_rt_id,222);
7677            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'LBR_MMBR_RT_ID' ;
7678            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_LMM.information1 ;
7679            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_LBR_MMBR_RT_ID ;
7680            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
7681            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_LMM_unique.table_route_id;
7682            hr_utility.set_location('After plsql table ',222);
7683            --
7684            -- 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 ) ;
7685            --
7686            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
7687            --
7688          else
7689            --
7690            -- Call Update routine for the pk_id created in prev run .
7691            --UPD START
7692            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
7693            --
7694            if l_update then
7695              --
7696              l_datetrack_mode := r_LMM.datetrack_mode ;
7697              --
7698              get_dt_modes(
7699                p_effective_date        => l_process_date,
7700                p_effective_end_date    => r_LMM.information3,
7701                p_effective_start_date  => r_LMM.information2,
7702                p_dml_operation         => r_LMM.dml_operation,
7703                p_datetrack_mode        => l_datetrack_mode );
7704            --    p_update                => l_update
7705              --
7706              l_effective_date := l_process_date;
7707              l_LBR_MMBR_RT_ID   := r_LMM.information1;
7708              l_object_version_number := r_LMM.information265;
7709              --
7710            end if;
7711            --
7712            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
7713            --
7714            IF l_update OR l_dml_operation <> 'UPDATE' THEN
7715            --UPD END
7716            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
7717            hr_utility.set_location(' BEN_LBR_MMBR_RT_F UPDATE_LABOR_MEMBER_RATE ',30);
7718            BEN_LABOR_MEMBER_RATE_API.UPDATE_LABOR_MEMBER_RATE(
7719              --
7720              P_VALIDATE               => false
7721              ,P_EFFECTIVE_DATE        => l_effective_date
7722              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
7723              --
7724              ,P_EXCLD_FLAG      => r_LMM.INFORMATION12
7725              ,P_LBR_MMBR_FLAG      => r_LMM.INFORMATION11
7726              ,P_LBR_MMBR_RT_ID      => l_lbr_mmbr_rt_id
7727              ,P_LMM_ATTRIBUTE1      => r_LMM.INFORMATION111
7728              ,P_LMM_ATTRIBUTE10      => r_LMM.INFORMATION120
7729              ,P_LMM_ATTRIBUTE11      => r_LMM.INFORMATION121
7730              ,P_LMM_ATTRIBUTE12      => r_LMM.INFORMATION122
7731              ,P_LMM_ATTRIBUTE13      => r_LMM.INFORMATION123
7732              ,P_LMM_ATTRIBUTE14      => r_LMM.INFORMATION124
7733              ,P_LMM_ATTRIBUTE15      => r_LMM.INFORMATION125
7734              ,P_LMM_ATTRIBUTE16      => r_LMM.INFORMATION126
7735              ,P_LMM_ATTRIBUTE17      => r_LMM.INFORMATION127
7736              ,P_LMM_ATTRIBUTE18      => r_LMM.INFORMATION128
7737              ,P_LMM_ATTRIBUTE19      => r_LMM.INFORMATION129
7738              ,P_LMM_ATTRIBUTE2      => r_LMM.INFORMATION112
7739              ,P_LMM_ATTRIBUTE20      => r_LMM.INFORMATION130
7740              ,P_LMM_ATTRIBUTE21      => r_LMM.INFORMATION131
7741              ,P_LMM_ATTRIBUTE22      => r_LMM.INFORMATION132
7742              ,P_LMM_ATTRIBUTE23      => r_LMM.INFORMATION133
7743              ,P_LMM_ATTRIBUTE24      => r_LMM.INFORMATION134
7744              ,P_LMM_ATTRIBUTE25      => r_LMM.INFORMATION135
7745              ,P_LMM_ATTRIBUTE26      => r_LMM.INFORMATION136
7746              ,P_LMM_ATTRIBUTE27      => r_LMM.INFORMATION137
7747              ,P_LMM_ATTRIBUTE28      => r_LMM.INFORMATION138
7748              ,P_LMM_ATTRIBUTE29      => r_LMM.INFORMATION139
7749              ,P_LMM_ATTRIBUTE3      => r_LMM.INFORMATION113
7750              ,P_LMM_ATTRIBUTE30      => r_LMM.INFORMATION140
7751              ,P_LMM_ATTRIBUTE4      => r_LMM.INFORMATION114
7752              ,P_LMM_ATTRIBUTE5      => r_LMM.INFORMATION115
7753              ,P_LMM_ATTRIBUTE6      => r_LMM.INFORMATION116
7754              ,P_LMM_ATTRIBUTE7      => r_LMM.INFORMATION117
7755              ,P_LMM_ATTRIBUTE8      => r_LMM.INFORMATION118
7756              ,P_LMM_ATTRIBUTE9      => r_LMM.INFORMATION119
7757              ,P_LMM_ATTRIBUTE_CATEGORY      => r_LMM.INFORMATION110
7758              ,P_ORDR_NUM      => r_LMM.INFORMATION257
7759              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
7760              --
7761              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
7762              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
7763              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
7764              ,P_DATETRACK_MODE        => l_datetrack_mode
7765            );
7766            --
7767            end if;
7768          end if;
7769          --
7770          -- Delete the row if it is end dated.
7771          --
7772          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
7773              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
7774              trunc(l_max_eed) = r_LMM.information3) then
7775              --
7776              BEN_LABOR_MEMBER_RATE_API.delete_LABOR_MEMBER_RATE(
7777                 --
7778                 p_validate                       => false
7779                 ,p_lbr_mmbr_rt_id                   => l_lbr_mmbr_rt_id
7780                 ,p_effective_start_date           => l_effective_start_date
7781                 ,p_effective_end_date             => l_effective_end_date
7782                 ,p_object_version_number          => l_object_version_number
7783                 ,p_effective_date                 => l_max_eed
7784                 ,p_datetrack_mode                 => hr_api.g_delete
7785                 --
7786                 );
7787                 --
7788          end if;
7789          --
7790          l_prev_pk_id := l_current_pk_id ;
7791          --
7792        end if;
7793        --
7794      end if;
7795      --
7796    end loop;
7797    --
7798  exception when others then
7799     --
7800     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'LMM',r_lmm.information5 );
7801     --
7802  end create_LMM_rows;
7803 
7804    --
7805    ---------------------------------------------------------------
7806    ----------------------< create_LAR_rows >-----------------------
7807    ---------------------------------------------------------------
7808    --
7809    procedure create_LAR_rows
7810    (
7811          p_validate                       in  number     default 0
7812         ,p_copy_entity_txn_id             in  number
7813         ,p_effective_date                 in  date
7814         ,p_prefix_suffix_text             in  varchar2  default null
7815         ,p_reuse_object_flag              in  varchar2  default null
7816         ,p_target_business_group_id       in  varchar2  default null
7817         ,p_prefix_suffix_cd               in  varchar2  default null
7818    ) is
7819    --
7820    l_ABSENCE_ATTENDANCE_TYPE_ID  number;
7821    l_ABS_ATTENDANCE_REASON_ID  number;
7822    l_VRBL_RT_PRFL_ID  number;
7823    cursor c_unique_LAR(l_table_alias varchar2) is
7824    select distinct cpe.information1,
7825      cpe.information2,
7826      cpe.information3,
7827      cpe.table_route_id
7828    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
7829         pqh_table_route tr
7830    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
7831    and   cpe.table_route_id     = tr.table_route_id
7832    -- and   tr.where_clause        = l_BEN_LOA_RSN_RT_F
7833    and tr.table_alias = l_table_alias
7834    and   cpe.number_of_copies   = 1 -- ADDITION
7835    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
7836    order by information1, information2; --added for bug: 5151945
7837    --
7838    --
7839    cursor c_LAR_min_max_dates(c_table_route_id  number,
7840                 c_information1   Number) is
7841    select
7842      min(cpe.information2) min_esd,
7843      max(cpe.information3) min_eed
7844    from ben_copy_entity_results cpe
7845    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
7846    and   cpe.table_route_id     = c_table_route_id
7847    and   cpe.information1       = c_information1 ;
7848    --
7849    cursor c_LAR(c_table_route_id  number,
7850                 c_information1   number,
7851                 c_information2   Date,
7852                 c_information3   Date )  is
7853    select
7854      cpe.*
7855    from ben_copy_entity_results cpe
7856    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
7857    and   cpe.table_route_id     = c_table_route_id
7858    and   cpe.information1       = c_information1
7859    and   cpe.information2       = c_information2
7860    and   cpe.information3       = c_information3
7861    and rownum = 1 ;
7862    -- Date Track target record
7863    cursor c_find_LAR_in_target(
7864                                 c_effective_start_date    date,
7865                                 c_effective_end_date      date,
7866                                 c_business_group_id       number,
7867                                 c_new_pk_id               number) is
7868    select
7869      LAR.loa_rsn_rt_id new_value
7870    from BEN_LOA_RSN_RT_F LAR
7871    where
7872    LAR.ABSENCE_ATTENDANCE_TYPE_ID   = l_ABSENCE_ATTENDANCE_TYPE_ID  and
7873    nvl(LAR.ABS_ATTENDANCE_REASON_ID,-999)     = nvl(l_ABS_ATTENDANCE_REASON_ID,-999)  and
7874    LAR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
7875    LAR.business_group_id  = c_business_group_id
7876    and   LAR.loa_rsn_rt_id  <> c_new_pk_id
7877 --TEMPIK
7878    and c_effective_start_date between effective_start_date
7879                             and effective_end_date ;
7880 --END TEMPIK
7881 /*TEMPIK
7882    and exists ( select null
7883                 from BEN_LOA_RSN_RT_F LAR1
7884                 where
7885                 LAR1.ABSENCE_ATTENDANCE_TYPE_ID  = l_ABSENCE_ATTENDANCE_TYPE_ID  and
7886                 nvl(LAR1.ABS_ATTENDANCE_REASON_ID,-999)     = nvl(l_ABS_ATTENDANCE_REASON_ID,-999)  and
7887                 LAR1.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
7888                 LAR1.business_group_id  = c_business_group_id
7889                 and   LAR1.effective_start_date <= c_effective_start_date )
7890    and exists ( select null
7891                 from BEN_LOA_RSN_RT_F LAR2
7892                 where
7893                 LAR2.ABSENCE_ATTENDANCE_TYPE_ID  = l_ABSENCE_ATTENDANCE_TYPE_ID  and
7894                 nvl(LAR2.ABS_ATTENDANCE_REASON_ID,-999)     = nvl(l_ABS_ATTENDANCE_REASON_ID,-999)  and
7895                 LAR2.VRBL_RT_PRFL_ID   = l_VRBL_RT_PRFL_ID  and
7896                 LAR2.business_group_id  = c_business_group_id
7897                 and   LAR2.effective_end_date >= c_effective_end_date )
7898                 ;
7899 TEMPIK */
7900    --TEMPIK
7901    l_dt_rec_found            boolean ;
7902    --END TEMPIK
7903    --
7904    l_current_pk_id           number := null ;
7905    --UPD START
7906    --
7907    l_update                  boolean      := false ;
7908    l_datetrack_mode          varchar2(80) := hr_api.g_update;
7909    l_process_date            date;
7910    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
7911    --
7912    --UPD END
7913    l_prev_pk_id              number := null ;
7914    l_first_rec               boolean := true ;
7915    r_LAR                     c_LAR%rowtype;
7916    l_loa_rsn_rt_id             number ;
7917    l_object_version_number   number ;
7918    l_effective_start_date    date ;
7919    l_effective_end_date      date ;
7920    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
7921    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
7922    l_new_value               number(15);
7923    l_object_found_in_target  boolean := false ;
7924    l_min_esd                 date;
7925    l_max_eed                 date;
7926    l_effective_date          date;
7927    --
7928  begin
7929    -- Initialization
7930    l_object_found_in_target := false ;
7931    -- End Initialization
7932    -- Derive the prefix - sufix
7933    if   p_prefix_suffix_cd = 'PREFIX' then
7934      l_prefix  := p_prefix_suffix_text ;
7935    elsif p_prefix_suffix_cd = 'SUFFIX' then
7936      l_suffix   := p_prefix_suffix_text ;
7937    else
7938      l_prefix := null ;
7939      l_suffix  := null ;
7940    end if ;
7941    -- End Prefix Sufix derivation
7942    for r_LAR_unique in c_unique_LAR('LAR') loop
7943 
7944      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
7945         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
7946          r_LAR_unique.information3 >=
7947                  ben_pd_copy_to_ben_one.g_copy_effective_date)
7948         ) then
7949 
7950        --
7951        hr_utility.set_location(' r_LAR_unique.table_route_id '||r_LAR_unique.table_route_id,10);
7952        hr_utility.set_location(' r_LAR_unique.information1 '||r_LAR_unique.information1,10);
7953        hr_utility.set_location( 'r_LAR_unique.information2 '||r_LAR_unique.information2,10);
7954        hr_utility.set_location( 'r_LAR_unique.information3 '||r_LAR_unique.information3,10);
7955        -- If reuse objects flag is 'Y' then check for the object in the target business group
7956        -- if found insert the record into PLSql table and exit the loop else try create the
7957        -- object in the target business group
7958        --
7959        l_object_found_in_target := false ;
7960        l_min_esd := null ;
7961        l_max_eed := null ;
7962        open c_LAR_min_max_dates(r_LAR_unique.table_route_id, r_LAR_unique.information1 ) ;
7963        fetch c_LAR_min_max_dates into l_min_esd,l_max_eed ;
7964        --
7965 
7966        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
7967             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
7968          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
7969        end if;
7970        l_min_esd := greatest(l_min_esd,r_LAR_unique.information2);
7971        open c_LAR(r_LAR_unique.table_route_id,
7972                 r_LAR_unique.information1,
7973                 r_LAR_unique.information2,
7974                 r_LAR_unique.information3 ) ;
7975        --
7976        fetch c_LAR into r_LAR ;
7977        --
7978        close c_LAR ;
7979        --
7980        if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
7981          l_ABSENCE_ATTENDANCE_TYPE_ID := r_LAR.information176;
7982        else
7983          l_ABSENCE_ATTENDANCE_TYPE_ID := r_LAR.information174;
7984        end if;
7985        --
7986        if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
7987          l_ABS_ATTENDANCE_REASON_ID := r_LAR.information180;
7988        else
7989          l_ABS_ATTENDANCE_REASON_ID := r_LAR.information178;
7990        end if ;
7991        --
7992        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_LAR.INFORMATION262,r_LAR_unique.dml_operation);
7993 
7994        if l_ABSENCE_ATTENDANCE_TYPE_ID is null /*or l_ABS_ATTENDANCE_REASON_ID is null */ then
7995          close c_LAR_min_max_dates;
7996          --
7997          log_nomapping_data(p_parent_table_alias =>'VPF'
7998                      ,p_parent_pk_id         => r_LAR.information262
7999                      ,p_copy_entity_txn_id   => p_copy_entity_txn_id
8000                      ,p_child_table_alias    => 'LAR'
8001                      ,p_child_data           => r_LAR.information173 );
8002 
8003          --
8004        else
8005        --UPD START
8006        l_update := false;
8007        l_process_date := p_effective_date;
8008        l_dml_operation:= r_LAR_unique.dml_operation ;
8009        --
8010        if l_dml_operation = 'UPDATE' then
8011          --
8012          l_object_found_in_target := TRUE;
8013          --
8014          if l_process_date between r_LAR_unique.information2 and r_LAR_unique.information3 then
8015                l_update := true;
8016                if r_LAR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
8017                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'LOA_RSN_RT_ID'
8018                then
8019                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'LOA_RSN_RT_ID' ;
8020                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_LAR_unique.information1 ;
8021                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_LAR_unique.information1 ;
8022                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
8023                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_LAR_unique.table_route_id;
8024                   --
8025                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
8026                   --
8027                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
8028                   --
8029                   -- log_data('LAR',l_new_value,l_prefix || r_LAR_unique.name|| l_suffix,'REUSED');
8030                   --
8031                end if ;
8032                hr_utility.set_location( 'found record for update',10);
8033            --
8034          else
8035            --
8036            l_update := false;
8037            --
8038          end if;
8039        else
8040          --
8041          --UPD END
8042          if p_reuse_object_flag = 'Y' then
8043            if c_LAR_min_max_dates%found then
8044               -- cursor to find the object
8045               open c_find_LAR_in_target( l_min_esd,l_max_eed,
8046                                     p_target_business_group_id, nvl(l_loa_rsn_rt_id, -999)  ) ;
8047               fetch c_find_LAR_in_target into l_new_value ;
8048               if c_find_LAR_in_target%found then
8049                 --
8050              --TEMPIK
8051              l_dt_rec_found :=   dt_api.check_min_max_dates
8052                  (p_base_table_name => 'BEN_LOA_RSN_RT_F',
8053                   p_base_key_column => 'LOA_RSN_RT_ID',
8054                   p_base_key_value  => l_new_value,
8055                   p_from_date       => l_min_esd,
8056                   p_to_date         => l_max_eed );
8057              if l_dt_rec_found THEN
8058              --END TEMPIK
8059                 if r_LAR_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
8060                    nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'LOA_RSN_RT_ID'  then
8061                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'LOA_RSN_RT_ID' ;
8062                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_LAR_unique.information1 ;
8063                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
8064                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
8065                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_LAR_unique.table_route_id;
8066                    --
8067                    -- 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) ;
8068                    --
8069                    BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
8070                 end if ;
8071                 --
8072                 l_object_found_in_target := true ;
8073              --TEMPIK
8074              end if; -- l_dt_rec_found
8075              --END TEMPIK
8076               end if;
8077               close c_find_LAR_in_target ;
8078            --
8079            end if;
8080          end if ;
8081          --
8082          end if;
8083          close c_LAR_min_max_dates ;
8084          if not l_object_found_in_target OR l_update   then
8085            --
8086            l_current_pk_id := r_LAR.information1;
8087            --
8088            hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
8089            hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
8090            --
8091            if l_current_pk_id =  l_prev_pk_id  then
8092              --
8093              l_first_rec := false ;
8094              --
8095            else
8096              --
8097              l_first_rec := true ;
8098              --
8099            end if ;
8100            --
8101 
8102            l_effective_date := r_LAR.information2;
8103            if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
8104                 l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
8105              l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
8106            end if;
8107 
8108            if l_first_rec and not l_update then
8109              -- Call Create routine.
8110              hr_utility.set_location(' BEN_LOA_RSN_RT_F CREATE_LOA_REASON_RATE ',20);
8111              BEN_LOA_REASON_RATE_API.CREATE_LOA_REASON_RATE(
8112                 --
8113                 P_VALIDATE               => false
8114                 ,P_EFFECTIVE_DATE        => l_effective_date
8115                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
8116                 --
8117              ,P_ABSENCE_ATTENDANCE_TYPE_ID      => l_ABSENCE_ATTENDANCE_TYPE_ID
8118              ,P_ABS_ATTENDANCE_REASON_ID      => l_ABS_ATTENDANCE_REASON_ID
8119              ,P_EXCLD_FLAG      => r_LAR.INFORMATION11
8120              ,P_LAR_ATTRIBUTE1      => r_LAR.INFORMATION111
8121              ,P_LAR_ATTRIBUTE10      => r_LAR.INFORMATION120
8122              ,P_LAR_ATTRIBUTE11      => r_LAR.INFORMATION121
8123              ,P_LAR_ATTRIBUTE12      => r_LAR.INFORMATION122
8124              ,P_LAR_ATTRIBUTE13      => r_LAR.INFORMATION123
8125              ,P_LAR_ATTRIBUTE14      => r_LAR.INFORMATION124
8126              ,P_LAR_ATTRIBUTE15      => r_LAR.INFORMATION125
8127              ,P_LAR_ATTRIBUTE16      => r_LAR.INFORMATION126
8128              ,P_LAR_ATTRIBUTE17      => r_LAR.INFORMATION127
8129              ,P_LAR_ATTRIBUTE18      => r_LAR.INFORMATION128
8130              ,P_LAR_ATTRIBUTE19      => r_LAR.INFORMATION129
8131              ,P_LAR_ATTRIBUTE2      => r_LAR.INFORMATION112
8132              ,P_LAR_ATTRIBUTE20      => r_LAR.INFORMATION130
8133              ,P_LAR_ATTRIBUTE21      => r_LAR.INFORMATION131
8134              ,P_LAR_ATTRIBUTE22      => r_LAR.INFORMATION132
8135              ,P_LAR_ATTRIBUTE23      => r_LAR.INFORMATION133
8136              ,P_LAR_ATTRIBUTE24      => r_LAR.INFORMATION134
8137              ,P_LAR_ATTRIBUTE25      => r_LAR.INFORMATION135
8138              ,P_LAR_ATTRIBUTE26      => r_LAR.INFORMATION136
8139              ,P_LAR_ATTRIBUTE27      => r_LAR.INFORMATION137
8140              ,P_LAR_ATTRIBUTE28      => r_LAR.INFORMATION138
8141              ,P_LAR_ATTRIBUTE29      => r_LAR.INFORMATION139
8142              ,P_LAR_ATTRIBUTE3      => r_LAR.INFORMATION113
8143              ,P_LAR_ATTRIBUTE30      => r_LAR.INFORMATION140
8144              ,P_LAR_ATTRIBUTE4      => r_LAR.INFORMATION114
8145              ,P_LAR_ATTRIBUTE5      => r_LAR.INFORMATION115
8146              ,P_LAR_ATTRIBUTE6      => r_LAR.INFORMATION116
8147              ,P_LAR_ATTRIBUTE7      => r_LAR.INFORMATION117
8148              ,P_LAR_ATTRIBUTE8      => r_LAR.INFORMATION118
8149              ,P_LAR_ATTRIBUTE9      => r_LAR.INFORMATION119
8150              ,P_LAR_ATTRIBUTE_CATEGORY      => r_LAR.INFORMATION110
8151              ,P_LOA_RSN_CD      => r_LAR.INFORMATION12
8152              ,P_LOA_RSN_RT_ID      => l_loa_rsn_rt_id
8153              ,P_ORDR_NUM      => r_LAR.INFORMATION260
8154              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
8155                 --
8156                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
8157                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
8158                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
8159              );
8160              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
8161              -- Update all relevent cer records with new pk_id
8162              hr_utility.set_location('Before plsql table ',222);
8163              hr_utility.set_location('new_value id '||l_loa_rsn_rt_id,222);
8164              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'LOA_RSN_RT_ID' ;
8165              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_LAR.information1 ;
8166              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_LOA_RSN_RT_ID ;
8167              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
8168              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_LAR_unique.table_route_id;
8169              hr_utility.set_location('After plsql table ',222);
8170              --
8171              -- 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 ) ;
8172              --
8173              BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
8174              --
8175            else
8176              --
8177              -- Call Update routine for the pk_id created in prev run .
8178              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
8179            --UPD START
8180            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
8181            --
8182            if l_update then
8183              --
8184              l_datetrack_mode := r_LAR.datetrack_mode ;
8185              --
8186              get_dt_modes(
8187                p_effective_date        => l_process_date,
8188                p_effective_end_date    => r_LAR.information3,
8189                p_effective_start_date  => r_LAR.information2,
8190                p_dml_operation         => r_LAR.dml_operation,
8191                p_datetrack_mode        => l_datetrack_mode );
8192            --    p_update                => l_update
8193              --
8194              l_effective_date := l_process_date;
8195              l_LOA_RSN_RT_ID   := r_LAR.information1;
8196              l_object_version_number := r_LAR.information265;
8197              --
8198            end if;
8199            --
8200            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
8201            --
8202            IF l_update OR l_dml_operation <> 'UPDATE' THEN
8203            --UPD END
8204              hr_utility.set_location(' BEN_LOA_RSN_RT_F UPDATE_LOA_REASON_RATE ',30);
8205              BEN_LOA_REASON_RATE_API.UPDATE_LOA_REASON_RATE(
8206                 --
8207                 P_VALIDATE               => false
8208                 ,P_EFFECTIVE_DATE        => l_effective_date
8209                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
8210                 --
8211              ,P_ABSENCE_ATTENDANCE_TYPE_ID      => l_ABSENCE_ATTENDANCE_TYPE_ID
8212              ,P_ABS_ATTENDANCE_REASON_ID      => l_ABS_ATTENDANCE_REASON_ID
8213              ,P_EXCLD_FLAG      => r_LAR.INFORMATION11
8214              ,P_LAR_ATTRIBUTE1      => r_LAR.INFORMATION111
8215              ,P_LAR_ATTRIBUTE10      => r_LAR.INFORMATION120
8216              ,P_LAR_ATTRIBUTE11      => r_LAR.INFORMATION121
8217              ,P_LAR_ATTRIBUTE12      => r_LAR.INFORMATION122
8218              ,P_LAR_ATTRIBUTE13      => r_LAR.INFORMATION123
8219              ,P_LAR_ATTRIBUTE14      => r_LAR.INFORMATION124
8220              ,P_LAR_ATTRIBUTE15      => r_LAR.INFORMATION125
8221              ,P_LAR_ATTRIBUTE16      => r_LAR.INFORMATION126
8222              ,P_LAR_ATTRIBUTE17      => r_LAR.INFORMATION127
8223              ,P_LAR_ATTRIBUTE18      => r_LAR.INFORMATION128
8224              ,P_LAR_ATTRIBUTE19      => r_LAR.INFORMATION129
8225              ,P_LAR_ATTRIBUTE2      => r_LAR.INFORMATION112
8226              ,P_LAR_ATTRIBUTE20      => r_LAR.INFORMATION130
8227              ,P_LAR_ATTRIBUTE21      => r_LAR.INFORMATION131
8228              ,P_LAR_ATTRIBUTE22      => r_LAR.INFORMATION132
8229              ,P_LAR_ATTRIBUTE23      => r_LAR.INFORMATION133
8230              ,P_LAR_ATTRIBUTE24      => r_LAR.INFORMATION134
8231              ,P_LAR_ATTRIBUTE25      => r_LAR.INFORMATION135
8232              ,P_LAR_ATTRIBUTE26      => r_LAR.INFORMATION136
8233              ,P_LAR_ATTRIBUTE27      => r_LAR.INFORMATION137
8234              ,P_LAR_ATTRIBUTE28      => r_LAR.INFORMATION138
8235              ,P_LAR_ATTRIBUTE29      => r_LAR.INFORMATION139
8236              ,P_LAR_ATTRIBUTE3      => r_LAR.INFORMATION113
8237              ,P_LAR_ATTRIBUTE30      => r_LAR.INFORMATION140
8238              ,P_LAR_ATTRIBUTE4      => r_LAR.INFORMATION114
8239              ,P_LAR_ATTRIBUTE5      => r_LAR.INFORMATION115
8240              ,P_LAR_ATTRIBUTE6      => r_LAR.INFORMATION116
8241              ,P_LAR_ATTRIBUTE7      => r_LAR.INFORMATION117
8242              ,P_LAR_ATTRIBUTE8      => r_LAR.INFORMATION118
8243              ,P_LAR_ATTRIBUTE9      => r_LAR.INFORMATION119
8244              ,P_LAR_ATTRIBUTE_CATEGORY      => r_LAR.INFORMATION110
8245              ,P_LOA_RSN_CD      => r_LAR.INFORMATION12
8246              ,P_LOA_RSN_RT_ID      => l_loa_rsn_rt_id
8247              ,P_ORDR_NUM      => r_LAR.INFORMATION260
8248              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
8249                 --
8250                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
8251                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
8252                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
8253                 ,P_DATETRACK_MODE        => l_datetrack_mode
8254              );
8255              --
8256              end if;
8257            end if;
8258            --
8259            -- Delete the row if it is end dated.
8260            --
8261            if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
8262              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
8263                 trunc(l_max_eed) = r_LAR.information3) then
8264                 --
8265                 BEN_LOA_REASON_RATE_API.delete_LOA_REASON_RATE(
8266                    --
8267                    p_validate                       => false
8268                    ,p_loa_rsn_rt_id                   => l_loa_rsn_rt_id
8269                    ,p_effective_start_date           => l_effective_start_date
8270                    ,p_effective_end_date             => l_effective_end_date
8271                    ,p_object_version_number          => l_object_version_number
8272                    ,p_effective_date                 => l_max_eed
8273                    ,p_datetrack_mode                 => hr_api.g_delete
8274                    --
8275                    );
8276                    --
8277            end if;
8278            --
8279            l_prev_pk_id := l_current_pk_id ;
8280            --
8281          end if;
8282          --
8283        end if;
8284        --
8285      end if;
8286      --
8287    end loop;
8288    --
8289  exception when others then
8290     --
8291     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'LAR',r_lar.information5 );
8292     --
8293  end create_LAR_rows;
8294 
8295    --
8296    --
8297    ---------------------------------------------------------------
8298    ----------------------< create_OUR_rows >-----------------------
8299    ---------------------------------------------------------------
8300    --
8301    procedure create_OUR_rows
8302    (
8303          p_validate                       in  number     default 0
8304         ,p_copy_entity_txn_id             in  number
8305         ,p_effective_date                 in  date
8306         ,p_prefix_suffix_text             in  varchar2  default null
8307         ,p_reuse_object_flag              in  varchar2  default null
8308         ,p_target_business_group_id       in  varchar2  default null
8309         ,p_prefix_suffix_cd               in  varchar2  default null
8310    ) is
8311    --
8312    l_ORGANIZATION_ID  number;
8313    l_VRBL_RT_PRFL_ID  number;
8314    cursor c_unique_OUR(l_table_alias varchar2) is
8315    select distinct cpe.information1,
8316      cpe.information2,
8317      cpe.information3,
8318      cpe.table_route_id
8319    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
8320         pqh_table_route tr
8321    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
8322    and   cpe.table_route_id     = tr.table_route_id
8323    -- and   tr.where_clause        = l_BEN_ORG_UNIT_RT_F
8324    and tr.table_alias = l_table_alias
8325    and   cpe.number_of_copies   = 1 -- ADDITION
8326    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
8327    order by information1, information2; --added for bug: 5151945
8328    --
8329    --
8330    cursor c_OUR_min_max_dates(c_table_route_id  number,
8331                 c_information1   Number) is
8332    select
8333      min(cpe.information2) min_esd,
8334      max(cpe.information3) min_eed
8335    from ben_copy_entity_results cpe
8336    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
8337    and   cpe.table_route_id     = c_table_route_id
8338    and   cpe.information1       = c_information1 ;
8339    --
8340    cursor c_OUR(c_table_route_id  number,
8341                 c_information1   number,
8342                 c_information2   Date,
8343                 c_information3   Date )  is
8344    select
8345      cpe.*
8346    from ben_copy_entity_results cpe
8347    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
8348    and   cpe.table_route_id     = c_table_route_id
8349    and   cpe.information1       = c_information1
8350    and   cpe.information2       = c_information2
8351    and   cpe.information3       = c_information3
8352    and rownum = 1 ;
8353    -- Date Track target record
8354    cursor c_find_OUR_in_target(
8355                                 c_effective_start_date    date,
8356                                 c_effective_end_date      date,
8357                                 c_business_group_id       number,
8358                                 c_new_pk_id               number) is
8359    select
8360      OUR.org_unit_rt_id new_value
8361    from BEN_ORG_UNIT_RT_F OUR
8362    where
8363    OUR.ORGANIZATION_ID     = l_ORGANIZATION_ID  and
8364    OUR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
8365    OUR.business_group_id  = c_business_group_id
8366 --TEMPIK
8367    and c_effective_start_date between effective_start_date
8368                             and effective_end_date ;
8369 --END TEMPIK
8370 /*TEMPIK
8371    and   OUR.org_unit_rt_id  <> c_new_pk_id
8372    and exists ( select null
8373                 from BEN_ORG_UNIT_RT_F OUR1
8374                 where
8375                 OUR1.ORGANIZATION_ID     = l_ORGANIZATION_ID  and
8376                 OUR1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
8377                 OUR1.business_group_id  = c_business_group_id
8378                 and   OUR1.effective_start_date <= c_effective_start_date )
8379    and exists ( select null
8380                 from BEN_ORG_UNIT_RT_F OUR2
8381                 where
8382                 OUR2.ORGANIZATION_ID    = l_ORGANIZATION_ID  and
8383                 OUR2.VRBL_RT_PRFL_ID    =l_VRBL_RT_PRFL_ID  and
8384                 OUR2.business_group_id  = c_business_group_id
8385                 and   OUR2.effective_end_date >= c_effective_end_date )
8386                 ;
8387 TEMPIK */
8388    --TEMPIK
8389    l_dt_rec_found            boolean ;
8390    --END TEMPIK
8391    --
8392    l_current_pk_id           number := null ;
8393    --UPD START
8394    --
8395    l_update                  boolean      := false ;
8396    l_datetrack_mode          varchar2(80) := hr_api.g_update;
8397    l_process_date            date;
8398    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
8399    --
8400    --UPD END
8401    l_prev_pk_id              number := null ;
8402    l_first_rec               boolean := true ;
8403    r_OUR                     c_OUR%rowtype;
8404    l_org_unit_rt_id             number ;
8405    l_object_version_number   number ;
8406    l_effective_start_date    date ;
8407    l_effective_end_date      date ;
8408    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
8409    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
8410    l_new_value               number(15);
8411    l_object_found_in_target  boolean := false ;
8412    l_min_esd                 date;
8413    l_max_eed                 date;
8414    l_effective_date          date;
8415    --
8416  begin
8417    -- Initialization
8418    l_object_found_in_target := false ;
8419    -- End Initialization
8420    -- Derive the prefix - sufix
8421    if   p_prefix_suffix_cd = 'PREFIX' then
8422      l_prefix  := p_prefix_suffix_text ;
8423    elsif p_prefix_suffix_cd = 'SUFFIX' then
8424      l_suffix   := p_prefix_suffix_text ;
8425    else
8426      l_prefix := null ;
8427      l_suffix  := null ;
8428    end if ;
8429    -- End Prefix Sufix derivation
8430    for r_OUR_unique in c_unique_OUR('OUR') loop
8431 
8432      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
8433         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
8434          r_OUR_unique.information3 >=
8435                  ben_pd_copy_to_ben_one.g_copy_effective_date)
8436         ) then
8437        --
8438        hr_utility.set_location(' r_OUR_unique.table_route_id '||r_OUR_unique.table_route_id,10);
8439        hr_utility.set_location(' r_OUR_unique.information1 '||r_OUR_unique.information1,10);
8440        hr_utility.set_location( 'r_OUR_unique.information2 '||r_OUR_unique.information2,10);
8441        hr_utility.set_location( 'r_OUR_unique.information3 '||r_OUR_unique.information3,10);
8442        -- If reuse objects flag is 'Y' then check for the object in the target business group
8443        -- if found insert the record into PLSql table and exit the loop else try create the
8444        -- object in the target business group
8445        --
8446        l_object_found_in_target := false ;
8447        l_min_esd := null ;
8448        l_max_eed := null ;
8449        open c_OUR_min_max_dates(r_OUR_unique.table_route_id, r_OUR_unique.information1 ) ;
8450        fetch c_OUR_min_max_dates into l_min_esd,l_max_eed ;
8451        --
8452 
8453        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
8454             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
8455          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
8456        end if;
8457        l_min_esd := greatest(l_min_esd,r_OUR_unique.information2);
8458        open c_OUR(r_OUR_unique.table_route_id,
8459                 r_OUR_unique.information1,
8460                 r_OUR_unique.information2,
8461                 r_OUR_unique.information3 ) ;
8462        --
8463        fetch c_OUR into r_OUR ;
8464        --
8465        close c_OUR ;
8466        --
8467        if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
8468          l_ORGANIZATION_ID := r_OUR.information176;
8469        else
8470          l_ORGANIZATION_ID := r_OUR.information174;
8471        end if;
8472        --
8473        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_OUR.INFORMATION262,r_OUR_unique.dml_operation);
8474 
8475        if l_ORGANIZATION_ID is null then
8476          close c_OUR_min_max_dates;
8477          --
8478          log_nomapping_data(p_parent_table_alias =>'VPF'
8479                      ,p_parent_pk_id         => r_OUR.information262
8480                      ,p_copy_entity_txn_id   => p_copy_entity_txn_id
8481                      ,p_child_table_alias    => 'OUR'
8482                      ,p_child_data           => r_OUR.information173 );
8483 
8484          --
8485        else
8486        --UPD START
8487        l_update := false;
8488        l_process_date := p_effective_date;
8489        l_dml_operation:= r_OUR_unique.dml_operation ;
8490        --
8491        if l_dml_operation = 'UPDATE' then
8492          --
8493          l_object_found_in_target := TRUE;
8494          --
8495          if l_process_date between r_OUR_unique.information2 and r_OUR_unique.information3 then
8496                l_update := true;
8497                if r_OUR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
8498                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ORG_UNIT_RT_ID'
8499                then
8500                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ORG_UNIT_RT_ID' ;
8501                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_OUR_unique.information1 ;
8502                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_OUR_unique.information1 ;
8503                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
8504                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_OUR_unique.table_route_id;
8505                   --
8506                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
8507                   --
8508                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
8509                   --
8510                   -- log_data('OUR',l_new_value,l_prefix || r_OUR_unique.name|| l_suffix,'REUSED');
8511                   --
8512                end if ;
8513                hr_utility.set_location( 'found record for update',10);
8514            --
8515          else
8516            --
8517            l_update := false;
8518            --
8519          end if;
8520        else
8521          --
8522          --UPD END
8523          if p_reuse_object_flag = 'Y' then
8524            if c_OUR_min_max_dates%found then
8525               -- cursor to find the object
8526               open c_find_OUR_in_target( l_min_esd,l_max_eed,
8527                                     p_target_business_group_id, nvl(l_org_unit_rt_id, -999)  ) ;
8528               fetch c_find_OUR_in_target into l_new_value ;
8529               if c_find_OUR_in_target%found then
8530                 --
8531              --TEMPIK
8532              l_dt_rec_found :=   dt_api.check_min_max_dates
8533                  (p_base_table_name => 'BEN_ORG_UNIT_RT_F',
8534                   p_base_key_column => 'ORG_UNIT_RT_ID',
8535                   p_base_key_value  => l_new_value,
8536                   p_from_date       => l_min_esd,
8537                   p_to_date         => l_max_eed );
8538              if l_dt_rec_found THEN
8539              --END TEMPIK
8540                 if r_OUR_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
8541                    nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'ORG_UNIT_RT_ID'  then
8542                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'ORG_UNIT_RT_ID' ;
8543                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_OUR_unique.information1 ;
8544                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
8545                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
8546                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_OUR_unique.table_route_id;
8547                    --
8548                    -- 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) ;
8549                    --
8550                    BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
8551                 end if ;
8552                 --
8553                 l_object_found_in_target := true ;
8554              --TEMPIK
8555              end if; -- l_dt_rec_found
8556              --END TEMPIK
8557               end if;
8558               close c_find_OUR_in_target ;
8559            --
8560            end if;
8561          end if ;
8562          --
8563          end if;
8564          close c_OUR_min_max_dates ;
8565          if not l_object_found_in_target OR l_update   then
8566            --
8567            l_current_pk_id := r_OUR.information1;
8568            --
8569            hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
8570            hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
8571            --
8572            if l_current_pk_id =  l_prev_pk_id  then
8573              --
8574              l_first_rec := false ;
8575              --
8576            else
8577              --
8578              l_first_rec := true ;
8579              --
8580            end if ;
8581            --
8582 
8583            l_effective_date := r_OUR.information2;
8584            if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
8585                 l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
8586              l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
8587            end if;
8588 
8589            if l_first_rec and not l_update then
8590              -- Call Create routine.
8591              hr_utility.set_location(' BEN_ORG_UNIT_RT_F CREATE_ORG_UNIT_RATE ',20);
8592              BEN_ORG_UNIT_RATE_API.CREATE_ORG_UNIT_RATE(
8593                 --
8594                 P_VALIDATE               => false
8595                 ,P_EFFECTIVE_DATE        => l_effective_date
8596                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
8597                 --
8598              ,P_EXCLD_FLAG      => r_OUR.INFORMATION11
8599              ,P_ORDR_NUM      => r_OUR.INFORMATION260
8600              ,P_ORGANIZATION_ID      => l_ORGANIZATION_ID
8601              ,P_ORG_UNIT_RT_ID      => l_org_unit_rt_id
8602              ,P_OUR_ATTRIBUTE1      => r_OUR.INFORMATION111
8603              ,P_OUR_ATTRIBUTE10      => r_OUR.INFORMATION120
8604              ,P_OUR_ATTRIBUTE11      => r_OUR.INFORMATION121
8605              ,P_OUR_ATTRIBUTE12      => r_OUR.INFORMATION122
8606              ,P_OUR_ATTRIBUTE13      => r_OUR.INFORMATION123
8607              ,P_OUR_ATTRIBUTE14      => r_OUR.INFORMATION124
8608              ,P_OUR_ATTRIBUTE15      => r_OUR.INFORMATION125
8609              ,P_OUR_ATTRIBUTE16      => r_OUR.INFORMATION126
8610              ,P_OUR_ATTRIBUTE17      => r_OUR.INFORMATION127
8611              ,P_OUR_ATTRIBUTE18      => r_OUR.INFORMATION128
8612              ,P_OUR_ATTRIBUTE19      => r_OUR.INFORMATION129
8613              ,P_OUR_ATTRIBUTE2      => r_OUR.INFORMATION112
8614              ,P_OUR_ATTRIBUTE20      => r_OUR.INFORMATION130
8615              ,P_OUR_ATTRIBUTE21      => r_OUR.INFORMATION131
8616              ,P_OUR_ATTRIBUTE22      => r_OUR.INFORMATION132
8617              ,P_OUR_ATTRIBUTE23      => r_OUR.INFORMATION133
8618              ,P_OUR_ATTRIBUTE24      => r_OUR.INFORMATION134
8619              ,P_OUR_ATTRIBUTE25      => r_OUR.INFORMATION135
8620              ,P_OUR_ATTRIBUTE26      => r_OUR.INFORMATION136
8621              ,P_OUR_ATTRIBUTE27      => r_OUR.INFORMATION137
8622              ,P_OUR_ATTRIBUTE28      => r_OUR.INFORMATION138
8623              ,P_OUR_ATTRIBUTE29      => r_OUR.INFORMATION139
8624              ,P_OUR_ATTRIBUTE3      => r_OUR.INFORMATION113
8625              ,P_OUR_ATTRIBUTE30      => r_OUR.INFORMATION140
8626              ,P_OUR_ATTRIBUTE4      => r_OUR.INFORMATION114
8627              ,P_OUR_ATTRIBUTE5      => r_OUR.INFORMATION115
8628              ,P_OUR_ATTRIBUTE6      => r_OUR.INFORMATION116
8629              ,P_OUR_ATTRIBUTE7      => r_OUR.INFORMATION117
8630              ,P_OUR_ATTRIBUTE8      => r_OUR.INFORMATION118
8631              ,P_OUR_ATTRIBUTE9      => r_OUR.INFORMATION119
8632              ,P_OUR_ATTRIBUTE_CATEGORY      => r_OUR.INFORMATION110
8633              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
8634                 --
8635                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
8636                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
8637                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
8638              );
8639              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
8640              -- Update all relevent cer records with new pk_id
8641              hr_utility.set_location('Before plsql table ',222);
8642              hr_utility.set_location('new_value id '||l_org_unit_rt_id,222);
8643              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'ORG_UNIT_RT_ID' ;
8644              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_OUR.information1 ;
8645              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_ORG_UNIT_RT_ID ;
8646              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
8647              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_OUR_unique.table_route_id;
8648              hr_utility.set_location('After plsql table ',222);
8649              --
8650              -- 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 ) ;
8651              --
8652              BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
8653              --
8654            else
8655              --
8656              -- Call Update routine for the pk_id created in prev run .
8657              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
8658            --UPD START
8659            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
8660            --
8661            if l_update then
8662              --
8663              l_datetrack_mode := r_OUR.datetrack_mode ;
8664              --
8665              get_dt_modes(
8666                p_effective_date        => l_process_date,
8667                p_effective_end_date    => r_OUR.information3,
8668                p_effective_start_date  => r_OUR.information2,
8669                p_dml_operation         => r_OUR.dml_operation,
8670                p_datetrack_mode        => l_datetrack_mode );
8671            --    p_update                => l_update
8672              --
8673              l_effective_date := l_process_date;
8674              l_ORG_UNIT_RT_ID   := r_OUR.information1;
8675              l_object_version_number := r_OUR.information265;
8676              --
8677            end if;
8678            --
8679            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
8680            --
8681            IF l_update OR l_dml_operation <> 'UPDATE' THEN
8682            --UPD END
8683              hr_utility.set_location(' BEN_ORG_UNIT_RT_F UPDATE_ORG_UNIT_RATE ',30);
8684              BEN_ORG_UNIT_RATE_API.UPDATE_ORG_UNIT_RATE(
8685                 --
8686                 P_VALIDATE               => false
8687                 ,P_EFFECTIVE_DATE        => l_effective_date
8688                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
8689                 --
8690              ,P_EXCLD_FLAG      => r_OUR.INFORMATION11
8691              ,P_ORDR_NUM      => r_OUR.INFORMATION260
8692              ,P_ORGANIZATION_ID      => l_ORGANIZATION_ID
8693              ,P_ORG_UNIT_RT_ID      => l_org_unit_rt_id
8694              ,P_OUR_ATTRIBUTE1      => r_OUR.INFORMATION111
8695              ,P_OUR_ATTRIBUTE10      => r_OUR.INFORMATION120
8696              ,P_OUR_ATTRIBUTE11      => r_OUR.INFORMATION121
8697              ,P_OUR_ATTRIBUTE12      => r_OUR.INFORMATION122
8698              ,P_OUR_ATTRIBUTE13      => r_OUR.INFORMATION123
8699              ,P_OUR_ATTRIBUTE14      => r_OUR.INFORMATION124
8700              ,P_OUR_ATTRIBUTE15      => r_OUR.INFORMATION125
8701              ,P_OUR_ATTRIBUTE16      => r_OUR.INFORMATION126
8702              ,P_OUR_ATTRIBUTE17      => r_OUR.INFORMATION127
8703              ,P_OUR_ATTRIBUTE18      => r_OUR.INFORMATION128
8704              ,P_OUR_ATTRIBUTE19      => r_OUR.INFORMATION129
8705              ,P_OUR_ATTRIBUTE2      => r_OUR.INFORMATION112
8706              ,P_OUR_ATTRIBUTE20      => r_OUR.INFORMATION130
8707              ,P_OUR_ATTRIBUTE21      => r_OUR.INFORMATION131
8708              ,P_OUR_ATTRIBUTE22      => r_OUR.INFORMATION132
8709              ,P_OUR_ATTRIBUTE23      => r_OUR.INFORMATION133
8710              ,P_OUR_ATTRIBUTE24      => r_OUR.INFORMATION134
8711              ,P_OUR_ATTRIBUTE25      => r_OUR.INFORMATION135
8712              ,P_OUR_ATTRIBUTE26      => r_OUR.INFORMATION136
8713              ,P_OUR_ATTRIBUTE27      => r_OUR.INFORMATION137
8714              ,P_OUR_ATTRIBUTE28      => r_OUR.INFORMATION138
8715              ,P_OUR_ATTRIBUTE29      => r_OUR.INFORMATION139
8716              ,P_OUR_ATTRIBUTE3      => r_OUR.INFORMATION113
8717              ,P_OUR_ATTRIBUTE30      => r_OUR.INFORMATION140
8718              ,P_OUR_ATTRIBUTE4      => r_OUR.INFORMATION114
8719              ,P_OUR_ATTRIBUTE5      => r_OUR.INFORMATION115
8720              ,P_OUR_ATTRIBUTE6      => r_OUR.INFORMATION116
8721              ,P_OUR_ATTRIBUTE7      => r_OUR.INFORMATION117
8722              ,P_OUR_ATTRIBUTE8      => r_OUR.INFORMATION118
8723              ,P_OUR_ATTRIBUTE9      => r_OUR.INFORMATION119
8724              ,P_OUR_ATTRIBUTE_CATEGORY      => r_OUR.INFORMATION110
8725              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
8726                 --
8727                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
8728                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
8729                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
8730                 ,P_DATETRACK_MODE        => l_datetrack_mode
8731              );
8732              --
8733              end if;
8734            end if;
8735            --
8736            -- Delete the row if it is end dated.
8737            --
8738            if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
8739              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
8740                 trunc(l_max_eed) = r_OUR.information3) then
8741                 --
8742                 BEN_ORG_UNIT_RATE_API.delete_ORG_UNIT_RATE(
8743                    --
8744                    p_validate                       => false
8745                    ,p_org_unit_rt_id                   => l_org_unit_rt_id
8746                    ,p_effective_start_date           => l_effective_start_date
8747                    ,p_effective_end_date             => l_effective_end_date
8748                    ,p_object_version_number          => l_object_version_number
8749                    ,p_effective_date                 => l_max_eed
8750                    ,p_datetrack_mode                 => hr_api.g_delete
8751                    --
8752                    );
8753                    --
8754            end if;
8755            --
8756            l_prev_pk_id := l_current_pk_id ;
8757            --
8758          end if;
8759          --
8760        end if;
8761        --
8762      end if;
8763      --
8764    end loop;
8765    --
8766  exception when others then
8767     --
8768     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'OUR',r_our.information5 );
8769     --
8770  end create_OUR_rows;
8771 
8772    ---------------------------------------------------------------
8773    ----------------------< create_LER1_rows >-----------------------
8774    ---------------------------------------------------------------
8775    --
8776    procedure create_LER1_rows
8777    (
8778          p_validate                       in  number     default 0
8779         ,p_copy_entity_txn_id             in  number
8780         ,p_effective_date                 in  date
8781         ,p_prefix_suffix_text             in  varchar2  default null
8782         ,p_reuse_object_flag              in  varchar2  default null
8783         ,p_target_business_group_id       in  varchar2  default null
8784         ,p_prefix_suffix_cd               in  varchar2  default null
8785    ) is
8786    --
8787    l_ORGANIZATION_ID  number;
8788    l_VRBL_RT_PRFL_ID  number;
8789    cursor c_unique_LER1(l_table_alias varchar2) is
8790    select distinct cpe.information1,
8791      cpe.information2,
8792      cpe.information3,
8793      cpe.table_route_id
8794    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
8795         pqh_table_route tr
8796    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
8797    and   cpe.table_route_id     = tr.table_route_id
8798    -- and   tr.where_clause        = l_BEN_LGL_ENTY_RT_F
8799    and tr.table_alias = l_table_alias
8800    and   cpe.number_of_copies   = 1 -- ADDITION
8801    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
8802    order by information1, information2; --added for bug: 5151945
8803    --
8804    --
8805    cursor c_LER1_min_max_dates(c_table_route_id  number,
8806                 c_information1   Number) is
8807    select
8808      min(cpe.information2) min_esd,
8809      max(cpe.information3) min_eed
8810    from ben_copy_entity_results cpe
8811    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
8812    and   cpe.table_route_id     = c_table_route_id
8813    and   cpe.information1       = c_information1 ;
8814    --
8815    cursor c_LER1(c_table_route_id  number,
8816                 c_information1   number,
8817                 c_information2   Date,
8818                 c_information3   Date )  is
8819    select
8820      cpe.*
8821    from ben_copy_entity_results cpe
8822    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
8823    and   cpe.table_route_id     = c_table_route_id
8824    and   cpe.information1       = c_information1
8825    and   cpe.information2       = c_information2
8826    and   cpe.information3       = c_information3
8827    and rownum = 1 ;
8828    -- Date Track target record
8829    cursor c_find_LER1_in_target(
8830                                 c_effective_start_date    date,
8831                                 c_effective_end_date      date,
8832                                 c_business_group_id       number,
8833                                 c_new_pk_id               number) is
8834    select
8835      LER1.lgl_enty_rt_id new_value
8836    from BEN_LGL_ENTY_RT_F LER1
8837    where
8838    LER1.ORGANIZATION_ID     = l_ORGANIZATION_ID  and
8839    LER1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
8840    LER1.business_group_id  = c_business_group_id
8841    and   LER1.lgl_enty_rt_id  <> c_new_pk_id
8842 --TEMPIK
8843    and c_effective_start_date between effective_start_date
8844                             and effective_end_date ;
8845 --END TEMPIK
8846 /*TEMPIK
8847    and exists ( select null
8848                 from BEN_LGL_ENTY_RT_F LER11
8849                 where
8850                 LER11.ORGANIZATION_ID     = l_ORGANIZATION_ID  and
8851                 LER11.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
8852                 LER11.business_group_id  = c_business_group_id
8853                 and   LER11.effective_start_date <= c_effective_start_date )
8854    and exists ( select null
8855                 from BEN_LGL_ENTY_RT_F LER12
8856                 where
8857                 LER12.ORGANIZATION_ID    = l_ORGANIZATION_ID  and
8858                 LER12.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
8859                 LER12.business_group_id  = c_business_group_id
8860                 and   LER12.effective_end_date >= c_effective_end_date )
8861                 ;
8862 TEMPIK */
8863    --TEMPIK
8864    l_dt_rec_found            boolean ;
8865    --END TEMPIK
8866    --
8867    l_current_pk_id           number := null ;
8868    --UPD START
8869    --
8870    l_update                  boolean      := false ;
8871    l_datetrack_mode          varchar2(80) := hr_api.g_update;
8872    l_process_date            date;
8873    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
8874    --
8875    --UPD END
8876    l_prev_pk_id              number := null ;
8877    l_first_rec               boolean := true ;
8878    r_LER1                     c_LER1%rowtype;
8879    l_lgl_enty_rt_id             number ;
8880    l_object_version_number   number ;
8881    l_effective_start_date    date ;
8882    l_effective_end_date      date ;
8883    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
8884    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
8885    l_new_value               number(15);
8886    l_object_found_in_target  boolean := false ;
8887    l_min_esd                 date;
8888    l_max_eed                 date;
8889    l_effective_date          date;
8890    --
8891  begin
8892    -- Initialization
8893    l_object_found_in_target := false ;
8894    -- End Initialization
8895    -- Derive the prefix - sufix
8896    if   p_prefix_suffix_cd = 'PREFIX' then
8897      l_prefix  := p_prefix_suffix_text ;
8898    elsif p_prefix_suffix_cd = 'SUFFIX' then
8899      l_suffix   := p_prefix_suffix_text ;
8900    else
8901      l_prefix := null ;
8902      l_suffix  := null ;
8903    end if ;
8904    -- End Prefix Sufix derivation
8905    for r_LER1_unique in c_unique_LER1('LER1') loop
8906 
8907      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
8908         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
8909          r_LER1_unique.information3 >=
8910                  ben_pd_copy_to_ben_one.g_copy_effective_date)
8911         ) then
8912        --
8913        hr_utility.set_location(' r_LER1_unique.table_route_id '||r_LER1_unique.table_route_id,10);
8914        hr_utility.set_location(' r_LER1_unique.information1 '||r_LER1_unique.information1,10);
8915        hr_utility.set_location( 'r_LER1_unique.information2 '||r_LER1_unique.information2,10);
8916        hr_utility.set_location( 'r_LER1_unique.information3 '||r_LER1_unique.information3,10);
8917        -- If reuse objects flag is 'Y' then check for the object in the target business group
8918        -- if found insert the record into PLSql table and exit the loop else try create the
8919        -- object in the target business group
8920        --
8921        l_object_found_in_target := false ;
8922        l_min_esd := null ;
8923        l_max_eed := null ;
8924        open c_LER1_min_max_dates(r_LER1_unique.table_route_id, r_LER1_unique.information1 ) ;
8925        fetch c_LER1_min_max_dates into l_min_esd,l_max_eed ;
8926        --
8927 
8928        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
8929             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
8930          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
8931        end if;
8932        l_min_esd := greatest(l_min_esd,r_LER1_unique.information2);
8933        open c_LER1(r_LER1_unique.table_route_id,
8934                 r_LER1_unique.information1,
8935                 r_LER1_unique.information2,
8936                 r_LER1_unique.information3 ) ;
8937        --
8938        fetch c_LER1 into r_LER1 ;
8939        --
8940        close c_LER1 ;
8941        --
8942        if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
8943          l_ORGANIZATION_ID := r_LER1.information176;
8944        else
8945          l_ORGANIZATION_ID := r_LER1.information174;
8946        end if;
8947        --
8948        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_LER1.information262,r_LER1_unique.dml_operation);
8949 
8950        if l_ORGANIZATION_ID is null then
8951          close c_LER1_min_max_dates;
8952          --
8953          log_nomapping_data(p_parent_table_alias =>'VPF'
8954                      ,p_parent_pk_id         => r_LER1.information262
8955                      ,p_copy_entity_txn_id   => p_copy_entity_txn_id
8956                      ,p_child_table_alias    => 'LER1'
8957                      ,p_child_data           => r_LER1.information173 );
8958 
8959          --
8960        else
8961        --UPD START
8962        l_update := false;
8963        l_process_date := p_effective_date;
8964        l_dml_operation:= r_LER1_unique.dml_operation ;
8965        --
8966        if l_dml_operation = 'UPDATE' then
8967          --
8968          l_object_found_in_target := TRUE;
8969          --
8970          if l_process_date between r_LER1_unique.information2 and r_LER1_unique.information3 then
8971                l_update := true;
8972                if r_LER1_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
8973                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'LGL_ENTY_RT_ID'
8974                then
8975                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'LGL_ENTY_RT_ID' ;
8976                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_LER1_unique.information1 ;
8977                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_LER1_unique.information1 ;
8978                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
8979                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_LER1_unique.table_route_id;
8980                   --
8981                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
8982                   --
8983                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
8984                   --
8985                   -- log_data('LER1',l_new_value,l_prefix || r_LER1_unique.name|| l_suffix,'REUSED');
8986                   --
8987                end if ;
8988                hr_utility.set_location( 'found record for update',10);
8989            --
8990          else
8991            --
8992            l_update := false;
8993            --
8994          end if;
8995        else
8996          --
8997          --UPD END
8998          if p_reuse_object_flag = 'Y' then
8999            if c_LER1_min_max_dates%found then
9000               -- cursor to find the object
9001               open c_find_LER1_in_target( l_min_esd,l_max_eed,
9002                                     p_target_business_group_id, nvl(l_lgl_enty_rt_id, -999)  ) ;
9003               fetch c_find_LER1_in_target into l_new_value ;
9004               if c_find_LER1_in_target%found then
9005                 --
9006              --TEMPIK
9007              l_dt_rec_found :=   dt_api.check_min_max_dates
9008                  (p_base_table_name => 'BEN_LGL_ENTY_RT_F',
9009                   p_base_key_column => 'LGL_ENTY_RT_ID',
9010                   p_base_key_value  => l_new_value,
9011                   p_from_date       => l_min_esd,
9012                   p_to_date         => l_max_eed );
9013              if l_dt_rec_found THEN
9014              --END TEMPIK
9015                 if r_LER1_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
9016                    nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'LGL_ENTY_RT_ID'  then
9017                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'LGL_ENTY_RT_ID' ;
9018                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_LER1_unique.information1 ;
9019                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
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_LER1_unique.table_route_id;
9022                    --
9023                    -- 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) ;
9024                    --
9025                    BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
9026                 end if ;
9027                 --
9028                 l_object_found_in_target := true ;
9029              --TEMPIK
9030              end if; -- l_dt_rec_found
9031              --END TEMPIK
9032               end if;
9033               close c_find_LER1_in_target ;
9034            --
9035            end if;
9036          end if ;
9037          --
9038          end if;
9039          close c_LER1_min_max_dates ;
9040          if not l_object_found_in_target OR l_update   then
9041            --
9042            l_current_pk_id := r_LER1.information1;
9043            --
9044            hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
9045            hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
9046            --
9047            if l_current_pk_id =  l_prev_pk_id  then
9048              --
9049              l_first_rec := false ;
9050              --
9051            else
9052              --
9053              l_first_rec := true ;
9054              --
9055            end if ;
9056            --
9057 
9058            l_effective_date := r_LER1.information2;
9059            if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
9060               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
9061            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
9062            end if;
9063 
9064            if l_first_rec and not l_update then
9065              -- Call Create routine.
9066              hr_utility.set_location(' BEN_LGL_ENTY_RT_F CREATE_LEGAL_ENTITY_RATE ',20);
9067              BEN_LEGAL_ENTITY_RATE_API.CREATE_LEGAL_ENTITY_RATE(
9068                 --
9069                 P_VALIDATE               => false
9070                 ,P_EFFECTIVE_DATE        => l_effective_date
9071                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
9072                 --
9073              ,P_EXCLD_FLAG      => r_LER1.INFORMATION11
9074              ,P_LER1_ATTRIBUTE1      => r_LER1.INFORMATION111
9075              ,P_LER1_ATTRIBUTE10      => r_LER1.INFORMATION120
9076              ,P_LER1_ATTRIBUTE11      => r_LER1.INFORMATION121
9077              ,P_LER1_ATTRIBUTE12      => r_LER1.INFORMATION122
9078              ,P_LER1_ATTRIBUTE13      => r_LER1.INFORMATION123
9079              ,P_LER1_ATTRIBUTE14      => r_LER1.INFORMATION124
9080              ,P_LER1_ATTRIBUTE15      => r_LER1.INFORMATION125
9081              ,P_LER1_ATTRIBUTE16      => r_LER1.INFORMATION126
9082              ,P_LER1_ATTRIBUTE17      => r_LER1.INFORMATION127
9083              ,P_LER1_ATTRIBUTE18      => r_LER1.INFORMATION128
9084              ,P_LER1_ATTRIBUTE19      => r_LER1.INFORMATION129
9085              ,P_LER1_ATTRIBUTE2      => r_LER1.INFORMATION112
9086              ,P_LER1_ATTRIBUTE20      => r_LER1.INFORMATION130
9087              ,P_LER1_ATTRIBUTE21      => r_LER1.INFORMATION131
9088              ,P_LER1_ATTRIBUTE22      => r_LER1.INFORMATION132
9089              ,P_LER1_ATTRIBUTE23      => r_LER1.INFORMATION133
9090              ,P_LER1_ATTRIBUTE24      => r_LER1.INFORMATION134
9091              ,P_LER1_ATTRIBUTE25      => r_LER1.INFORMATION135
9092              ,P_LER1_ATTRIBUTE26      => r_LER1.INFORMATION136
9093              ,P_LER1_ATTRIBUTE27      => r_LER1.INFORMATION137
9094              ,P_LER1_ATTRIBUTE28      => r_LER1.INFORMATION138
9095              ,P_LER1_ATTRIBUTE29      => r_LER1.INFORMATION139
9096              ,P_LER1_ATTRIBUTE3      => r_LER1.INFORMATION113
9097              ,P_LER1_ATTRIBUTE30      => r_LER1.INFORMATION140
9098              ,P_LER1_ATTRIBUTE4      => r_LER1.INFORMATION114
9099              ,P_LER1_ATTRIBUTE5      => r_LER1.INFORMATION115
9100              ,P_LER1_ATTRIBUTE6      => r_LER1.INFORMATION116
9101              ,P_LER1_ATTRIBUTE7      => r_LER1.INFORMATION117
9102              ,P_LER1_ATTRIBUTE8      => r_LER1.INFORMATION118
9103              ,P_LER1_ATTRIBUTE9      => r_LER1.INFORMATION119
9104              ,P_LER1_ATTRIBUTE_CATEGORY      => r_LER1.INFORMATION110
9105              ,P_LGL_ENTY_RT_ID      => l_lgl_enty_rt_id
9106              ,P_ORDR_NUM      => r_LER1.INFORMATION257
9107              ,P_ORGANIZATION_ID      => l_ORGANIZATION_ID
9108              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
9109                 --
9110                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
9111                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
9112                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
9113              );
9114              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
9115              -- Update all relevent cer records with new pk_id
9116              hr_utility.set_location('Before plsql table ',222);
9117              hr_utility.set_location('new_value id '||l_lgl_enty_rt_id,222);
9118              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'LGL_ENTY_RT_ID' ;
9119              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_LER1.information1 ;
9120              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_LGL_ENTY_RT_ID ;
9121              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
9122              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_LER1_unique.table_route_id;
9123              hr_utility.set_location('After plsql table ',222);
9124              --
9125              -- 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 ) ;
9126              --
9127              BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
9128              --
9129            else
9130              --
9131              -- Call Update routine for the pk_id created in prev run .
9132              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
9133            --UPD START
9134            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
9135            --
9136            if l_update then
9137              --
9138              l_datetrack_mode := r_LER1.datetrack_mode ;
9139              --
9140              get_dt_modes(
9141                p_effective_date        => l_process_date,
9142                p_effective_end_date    => r_LER1.information3,
9143                p_effective_start_date  => r_LER1.information2,
9144                p_dml_operation         => r_LER1.dml_operation,
9145                p_datetrack_mode        => l_datetrack_mode );
9146            --    p_update                => l_update
9147              --
9148              l_effective_date := l_process_date;
9149              l_LGL_ENTY_RT_ID   := r_LER1.information1;
9150              l_object_version_number := r_LER1.information265;
9151              --
9152            end if;
9153            --
9154            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
9155            --
9156            IF l_update OR l_dml_operation <> 'UPDATE' THEN
9157            --UPD END
9158              hr_utility.set_location(' BEN_LGL_ENTY_RT_F UPDATE_LEGAL_ENTITY_RATE ',30);
9159              BEN_LEGAL_ENTITY_RATE_API.UPDATE_LEGAL_ENTITY_RATE(
9160                 --
9161                 P_VALIDATE               => false
9162                 ,P_EFFECTIVE_DATE        => l_effective_date
9163                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
9164                 --
9165              ,P_EXCLD_FLAG      => r_LER1.INFORMATION11
9166              ,P_LER1_ATTRIBUTE1      => r_LER1.INFORMATION111
9167              ,P_LER1_ATTRIBUTE10      => r_LER1.INFORMATION120
9168              ,P_LER1_ATTRIBUTE11      => r_LER1.INFORMATION121
9169              ,P_LER1_ATTRIBUTE12      => r_LER1.INFORMATION122
9170              ,P_LER1_ATTRIBUTE13      => r_LER1.INFORMATION123
9171              ,P_LER1_ATTRIBUTE14      => r_LER1.INFORMATION124
9172              ,P_LER1_ATTRIBUTE15      => r_LER1.INFORMATION125
9173              ,P_LER1_ATTRIBUTE16      => r_LER1.INFORMATION126
9174              ,P_LER1_ATTRIBUTE17      => r_LER1.INFORMATION127
9175              ,P_LER1_ATTRIBUTE18      => r_LER1.INFORMATION128
9176              ,P_LER1_ATTRIBUTE19      => r_LER1.INFORMATION129
9177              ,P_LER1_ATTRIBUTE2      => r_LER1.INFORMATION112
9178              ,P_LER1_ATTRIBUTE20      => r_LER1.INFORMATION130
9179              ,P_LER1_ATTRIBUTE21      => r_LER1.INFORMATION131
9180              ,P_LER1_ATTRIBUTE22      => r_LER1.INFORMATION132
9181              ,P_LER1_ATTRIBUTE23      => r_LER1.INFORMATION133
9182              ,P_LER1_ATTRIBUTE24      => r_LER1.INFORMATION134
9183              ,P_LER1_ATTRIBUTE25      => r_LER1.INFORMATION135
9184              ,P_LER1_ATTRIBUTE26      => r_LER1.INFORMATION136
9185              ,P_LER1_ATTRIBUTE27      => r_LER1.INFORMATION137
9186              ,P_LER1_ATTRIBUTE28      => r_LER1.INFORMATION138
9187              ,P_LER1_ATTRIBUTE29      => r_LER1.INFORMATION139
9188              ,P_LER1_ATTRIBUTE3      => r_LER1.INFORMATION113
9189              ,P_LER1_ATTRIBUTE30      => r_LER1.INFORMATION140
9190              ,P_LER1_ATTRIBUTE4      => r_LER1.INFORMATION114
9191              ,P_LER1_ATTRIBUTE5      => r_LER1.INFORMATION115
9192              ,P_LER1_ATTRIBUTE6      => r_LER1.INFORMATION116
9193              ,P_LER1_ATTRIBUTE7      => r_LER1.INFORMATION117
9194              ,P_LER1_ATTRIBUTE8      => r_LER1.INFORMATION118
9195              ,P_LER1_ATTRIBUTE9      => r_LER1.INFORMATION119
9196              ,P_LER1_ATTRIBUTE_CATEGORY      => r_LER1.INFORMATION110
9197              ,P_LGL_ENTY_RT_ID      => l_lgl_enty_rt_id
9198              ,P_ORDR_NUM      => r_LER1.INFORMATION257
9199              ,P_ORGANIZATION_ID      => l_ORGANIZATION_ID
9200              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
9201                 --
9202                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
9203                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
9204                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
9205                 ,P_DATETRACK_MODE        => l_datetrack_mode
9206              );
9207              end if;
9208              --
9209            end if;
9210            --
9211            -- Delete the row if it is end dated.
9212            --
9213            if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
9214              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
9215                 trunc(l_max_eed) = r_LER1.information3) then
9216                 --
9217                 BEN_LEGAL_ENTITY_RATE_API.delete_LEGAL_ENTITY_RATE(
9218                    --
9219                    p_validate                       => false
9220                    ,p_lgl_enty_rt_id                   => l_lgl_enty_rt_id
9221                    ,p_effective_start_date           => l_effective_start_date
9222                    ,p_effective_end_date             => l_effective_end_date
9223                    ,p_object_version_number          => l_object_version_number
9224                    ,p_effective_date                 => l_max_eed
9225                    ,p_datetrack_mode                 => hr_api.g_delete
9226                    --
9227                    );
9228                    --
9229            end if;
9230            --
9231            l_prev_pk_id := l_current_pk_id ;
9232            --
9233          end if;
9234          --
9235        end if;
9236        --
9237      end if;
9238      --
9239    end loop;
9240    --
9241  exception when others then
9242     --
9243     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'LER1',r_ler1.information5 );
9244     --
9245  end create_LER1_rows;
9246 
9247    --
9248    ---------------------------------------------------------------
9249    ----------------------< create_PR__rows >-----------------------
9250    ---------------------------------------------------------------
9251    --
9252    procedure create_PR__rows
9253    (
9254          p_validate                       in  number     default 0
9255         ,p_copy_entity_txn_id             in  number
9256         ,p_effective_date                 in  date
9257         ,p_prefix_suffix_text             in  varchar2  default null
9258         ,p_reuse_object_flag              in  varchar2  default null
9259         ,p_target_business_group_id       in  varchar2  default null
9260         ,p_prefix_suffix_cd               in  varchar2  default null
9261    ) is
9262    --
9263    l_PAYROLL_ID  number;
9264    l_VRBL_RT_PRFL_ID  number;
9265    cursor c_unique_PR_(l_table_alias varchar2) is
9266    select distinct cpe.information1,
9267      cpe.information2,
9268      cpe.information3,
9269      cpe.table_route_id
9270    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
9271         pqh_table_route tr
9272    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
9273    and   cpe.table_route_id     = tr.table_route_id
9274    -- and   tr.where_clause        = l_BEN_PYRL_RT_F
9275    and tr.table_alias = l_table_alias
9276    and   cpe.number_of_copies   = 1 -- ADDITION
9277    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode ;
9278    --
9279    --
9280    cursor c_PR__min_max_dates(c_table_route_id  number,
9281                 c_information1   Number) is
9282    select
9283      min(cpe.information2) min_esd,
9284      max(cpe.information3) min_eed
9285    from ben_copy_entity_results cpe
9286    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
9287    and   cpe.table_route_id     = c_table_route_id
9288    and   cpe.information1       = c_information1 ;
9289    --
9290    cursor c_PR_(c_table_route_id  number,
9291                 c_information1   number,
9292                 c_information2   Date,
9293                 c_information3   Date)  is
9294    select
9295      cpe.*
9296    from ben_copy_entity_results cpe
9297    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
9298    and   cpe.table_route_id     = c_table_route_id
9299    and   cpe.information1       = c_information1
9300    and   cpe.information2       = c_information2
9301    and   cpe.information3       = c_information3
9302    and rownum = 1 ;
9303    -- Date Track target record
9304    cursor c_find_PR__in_target(
9305                                 c_effective_start_date    date,
9306                                 c_effective_end_date      date,
9307                                 c_business_group_id       number,
9308                                 c_new_pk_id               number) is
9309    select
9310      PR_.pyrl_rt_id new_value
9311    from BEN_PYRL_RT_F PR_
9312    where
9313    PR_.PAYROLL_ID     = l_PAYROLL_ID  and
9314    PR_.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
9315    PR_.business_group_id  = c_business_group_id
9316    and   PR_.pyrl_rt_id  <> c_new_pk_id
9317 --TEMPIK
9318    and c_effective_start_date between effective_start_date
9319                             and effective_end_date ;
9320 --END TEMPIK
9321 /*TEMPIK
9322    and exists ( select null
9323                 from BEN_PYRL_RT_F PR_1
9324                 where
9325                 PR_1.PAYROLL_ID     = l_PAYROLL_ID  and
9326                 PR_1.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
9327                 PR_1.business_group_id  = c_business_group_id
9328                 and   PR_1.effective_start_date <= c_effective_start_date )
9329    and exists ( select null
9330                 from BEN_PYRL_RT_F PR_2
9331                 where
9332                 PR_2.PAYROLL_ID     = l_PAYROLL_ID  and
9333                 PR_2.VRBL_RT_PRFL_ID  = l_VRBL_RT_PRFL_ID  and
9334                 PR_2.business_group_id  = c_business_group_id
9335                 and   PR_2.effective_end_date >= c_effective_end_date )
9336                 ;
9337 TEMPIK */
9338    --TEMPIK
9339    l_dt_rec_found            boolean ;
9340    --END TEMPIK
9341    --
9342    l_current_pk_id           number := null ;
9343    --UPD START
9344    --
9345    l_update                  boolean      := false ;
9346    l_datetrack_mode          varchar2(80) := hr_api.g_update;
9347    l_process_date            date;
9348    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
9349    --
9350    --UPD END
9351    l_prev_pk_id              number := null ;
9352    l_first_rec               boolean := true ;
9353    r_PR_                     c_PR_%rowtype;
9354    l_pyrl_rt_id             number ;
9355    l_object_version_number   number ;
9356    l_effective_start_date    date ;
9357    l_effective_end_date      date ;
9358    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
9359    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
9360    l_new_value               number(15);
9361    l_object_found_in_target  boolean := false ;
9362    l_min_esd                 date;
9363    l_max_eed                 date;
9364    l_effective_date          date;
9365    --
9366  begin
9367    -- Initialization
9368    l_object_found_in_target := false ;
9369    -- End Initialization
9370    -- Derive the prefix - sufix
9371    if   p_prefix_suffix_cd = 'PREFIX' then
9372      l_prefix  := p_prefix_suffix_text ;
9373    elsif p_prefix_suffix_cd = 'SUFFIX' then
9374      l_suffix   := p_prefix_suffix_text ;
9375    else
9376      l_prefix := null ;
9377      l_suffix  := null ;
9378    end if ;
9379    -- End Prefix Sufix derivation
9380    for r_PR__unique in c_unique_PR_('PR_') loop
9381 
9382      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
9383         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
9384          r_PR__unique.information3 >=
9385                  ben_pd_copy_to_ben_one.g_copy_effective_date)
9386         ) then
9387        --
9388        hr_utility.set_location(' r_PR__unique.table_route_id '||r_PR__unique.table_route_id,10);
9389        hr_utility.set_location(' r_PR__unique.information1 '||r_PR__unique.information1,10);
9390        hr_utility.set_location( 'r_PR__unique.information2 '||r_PR__unique.information2,10);
9391        hr_utility.set_location( 'r_PR__unique.information3 '||r_PR__unique.information3,10);
9392        -- If reuse objects flag is 'Y' then check for the object in the target business group
9393        -- if found insert the record into PLSql table and exit the loop else try create the
9394        -- object in the target business group
9395        --
9396        l_object_found_in_target := false ;
9397        l_min_esd := null ;
9398        l_max_eed := null ;
9399        open c_PR__min_max_dates(r_PR__unique.table_route_id, r_PR__unique.information1 ) ;
9400        fetch c_PR__min_max_dates into l_min_esd,l_max_eed ;
9401        --
9402 
9403        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
9404             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
9405          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
9406        end if;
9407        l_min_esd := greatest(l_min_esd,r_PR__unique.information2);
9408        open c_PR_(r_PR__unique.table_route_id,
9409                 r_PR__unique.information1,
9410                 r_PR__unique.information2,
9411                 r_PR__unique.information3 ) ;
9412        --
9413        fetch c_PR_ into r_PR_ ;
9414        --
9415        close c_PR_ ;
9416        --
9417        if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
9418          l_PAYROLL_ID := r_PR_.information176;
9419        else
9420          l_PAYROLL_ID := r_PR_.information174;
9421        end if;
9422        --
9423        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_PR_.information262,r_PR__unique.dml_operation);
9424 
9425        if l_PAYROLL_ID is null then
9426          close c_PR__min_max_dates;
9427          --
9428          log_nomapping_data(p_parent_table_alias =>'VPF'
9429                      ,p_parent_pk_id         => r_PR_.information262
9430                      ,p_copy_entity_txn_id   => p_copy_entity_txn_id
9431                      ,p_child_table_alias    => 'PR_'
9432                      ,p_child_data           => r_PR_.information173 );
9433 
9434          --
9435        else
9436        --UPD START
9437        l_update := false;
9438        l_process_date := p_effective_date;
9439        l_dml_operation:= r_PR__unique.dml_operation ;
9440        --
9441        if l_dml_operation = 'UPDATE' then
9442          --
9443          l_object_found_in_target := TRUE;
9444          --
9445          if l_process_date between r_PR__unique.information2 and r_PR__unique.information3 then
9446                l_update := true;
9447                if r_PR__unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
9448                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'PYRL_RT_ID'
9449                then
9450                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'PYRL_RT_ID' ;
9451                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_PR__unique.information1 ;
9452                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_PR__unique.information1 ;
9453                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
9454                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_PR__unique.table_route_id;
9455                   --
9456                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
9457                   --
9458                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
9459                   --
9460                   -- log_data('PR_',l_new_value,l_prefix || r_PR__unique.name|| l_suffix,'REUSED');
9461                   --
9462                end if ;
9463                hr_utility.set_location( 'found record for update',10);
9464            --
9465          else
9466            --
9467            l_update := false;
9468            --
9469          end if;
9470        else
9471          --
9472          if p_reuse_object_flag = 'Y' then
9473            if c_PR__min_max_dates%found then
9474               -- cursor to find the object
9475               open c_find_PR__in_target( l_min_esd,l_max_eed,
9476                                     p_target_business_group_id, nvl(l_pyrl_rt_id, -999)  ) ;
9477               fetch c_find_PR__in_target into l_new_value ;
9478               if c_find_PR__in_target%found then
9479                 --
9480              --TEMPIK
9481              l_dt_rec_found :=   dt_api.check_min_max_dates
9482                  (p_base_table_name => 'BEN_PYRL_RT_F',
9483                   p_base_key_column => 'PYRL_RT_ID',
9484                   p_base_key_value  => l_new_value,
9485                   p_from_date       => l_min_esd,
9486                   p_to_date         => l_max_eed );
9487              if l_dt_rec_found THEN
9488              --END TEMPIK
9489                 if r_PR__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
9490                    nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'PYRL_RT_ID'  then
9491                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'PYRL_RT_ID' ;
9492                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_PR__unique.information1 ;
9493                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
9494                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
9495                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PR__unique.table_route_id;
9496                    --
9497                    -- 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) ;
9498                    --
9499                    BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
9500                 end if ;
9501                 --
9502                 l_object_found_in_target := true ;
9503              --TEMPIK
9504              end if; -- l_dt_rec_found
9505              --END TEMPIK
9506               end if;
9507               close c_find_PR__in_target ;
9508            --
9509            end if;
9510          end if ;
9511          --
9512          end if;
9513          close c_PR__min_max_dates ;
9514          if not l_object_found_in_target OR l_update   then
9515            --
9516            l_current_pk_id := r_PR_.information1;
9517            --
9518            hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
9519            hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
9520            --
9521            if l_current_pk_id =  l_prev_pk_id  then
9522              --
9523              l_first_rec := false ;
9524              --
9525            else
9526              --
9527              l_first_rec := true ;
9528              --
9529            end if ;
9530            --
9531 
9532            l_effective_date := r_PR_.information2;
9533            if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
9534                 l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
9535              l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
9536            end if;
9537 
9538            if l_first_rec and not l_update then
9539              -- Call Create routine.
9540              hr_utility.set_location(' BEN_PYRL_RT_F CREATE_PAYROLL_RATE ',20);
9541              BEN_PAYROLL_RATE_API.CREATE_PAYROLL_RATE(
9542                 --
9543                 P_VALIDATE               => false
9544                 ,P_EFFECTIVE_DATE        => l_effective_date
9545                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
9546                 --
9547              ,P_EXCLD_FLAG      => r_PR_.INFORMATION11
9548              ,P_ORDR_NUM      => r_PR_.INFORMATION260
9549              ,P_PAYROLL_ID      => l_PAYROLL_ID
9550              ,P_PR_ATTRIBUTE1      => r_PR_.INFORMATION111
9551              ,P_PR_ATTRIBUTE10      => r_PR_.INFORMATION120
9552              ,P_PR_ATTRIBUTE11      => r_PR_.INFORMATION121
9553              ,P_PR_ATTRIBUTE12      => r_PR_.INFORMATION122
9554              ,P_PR_ATTRIBUTE13      => r_PR_.INFORMATION123
9555              ,P_PR_ATTRIBUTE14      => r_PR_.INFORMATION124
9556              ,P_PR_ATTRIBUTE15      => r_PR_.INFORMATION125
9557              ,P_PR_ATTRIBUTE16      => r_PR_.INFORMATION126
9558              ,P_PR_ATTRIBUTE17      => r_PR_.INFORMATION127
9559              ,P_PR_ATTRIBUTE18      => r_PR_.INFORMATION128
9560              ,P_PR_ATTRIBUTE19      => r_PR_.INFORMATION129
9561              ,P_PR_ATTRIBUTE2      => r_PR_.INFORMATION112
9562              ,P_PR_ATTRIBUTE20      => r_PR_.INFORMATION130
9563              ,P_PR_ATTRIBUTE21      => r_PR_.INFORMATION131
9564              ,P_PR_ATTRIBUTE22      => r_PR_.INFORMATION132
9565              ,P_PR_ATTRIBUTE23      => r_PR_.INFORMATION133
9566              ,P_PR_ATTRIBUTE24      => r_PR_.INFORMATION134
9567              ,P_PR_ATTRIBUTE25      => r_PR_.INFORMATION135
9568              ,P_PR_ATTRIBUTE26      => r_PR_.INFORMATION136
9569              ,P_PR_ATTRIBUTE27      => r_PR_.INFORMATION137
9570              ,P_PR_ATTRIBUTE28      => r_PR_.INFORMATION138
9571              ,P_PR_ATTRIBUTE29      => r_PR_.INFORMATION139
9572              ,P_PR_ATTRIBUTE3      => r_PR_.INFORMATION113
9573              ,P_PR_ATTRIBUTE30      => r_PR_.INFORMATION140
9574              ,P_PR_ATTRIBUTE4      => r_PR_.INFORMATION114
9575              ,P_PR_ATTRIBUTE5      => r_PR_.INFORMATION115
9576              ,P_PR_ATTRIBUTE6      => r_PR_.INFORMATION116
9577              ,P_PR_ATTRIBUTE7      => r_PR_.INFORMATION117
9578              ,P_PR_ATTRIBUTE8      => r_PR_.INFORMATION118
9579              ,P_PR_ATTRIBUTE9      => r_PR_.INFORMATION119
9580              ,P_PR_ATTRIBUTE_CATEGORY      => r_PR_.INFORMATION110
9581              ,P_PYRL_RT_ID      => l_pyrl_rt_id
9582              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
9583                 --
9584                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
9585                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
9586                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
9587              );
9588              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
9589              -- Update all relevent cer records with new pk_id
9590              hr_utility.set_location('Before plsql table ',222);
9591              hr_utility.set_location('new_value id '||l_pyrl_rt_id,222);
9592              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'PYRL_RT_ID' ;
9593              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_PR_.information1 ;
9594              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_PYRL_RT_ID ;
9595              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
9596              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PR__unique.table_route_id;
9597              hr_utility.set_location('After plsql table ',222);
9598              --
9599              -- 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 ) ;
9600              --
9601              BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
9602              --
9603            else
9604              --
9605              -- Call Update routine for the pk_id created in prev run .
9606              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
9607            --UPD START
9608            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
9609            --
9610            if l_update then
9611              --
9612              l_datetrack_mode := r_PR_.datetrack_mode ;
9613              --
9614              get_dt_modes(
9615                p_effective_date        => l_process_date,
9616                p_effective_end_date    => r_PR_.information3,
9617                p_effective_start_date  => r_PR_.information2,
9618                p_dml_operation         => r_PR_.dml_operation,
9619                p_datetrack_mode        => l_datetrack_mode );
9620            --    p_update                => l_update
9621              --
9622              l_effective_date := l_process_date;
9623              l_PYRL_RT_ID   := r_PR_.information1;
9624              l_object_version_number := r_PR_.information265;
9625              --
9626            end if;
9627            --
9628            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
9629            --
9630            IF l_update OR l_dml_operation <> 'UPDATE' THEN
9631            --UPD END
9632              hr_utility.set_location(' BEN_PYRL_RT_F UPDATE_PAYROLL_RATE ',30);
9633              BEN_PAYROLL_RATE_API.UPDATE_PAYROLL_RATE(
9634                 --
9635                 P_VALIDATE               => false
9636                 ,P_EFFECTIVE_DATE        => l_effective_date
9637                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
9638                 --
9639              ,P_EXCLD_FLAG      => r_PR_.INFORMATION11
9640              ,P_ORDR_NUM      => r_PR_.INFORMATION260
9641              ,P_PAYROLL_ID      => l_PAYROLL_ID
9642              ,P_PR_ATTRIBUTE1      => r_PR_.INFORMATION111
9643              ,P_PR_ATTRIBUTE10      => r_PR_.INFORMATION120
9644              ,P_PR_ATTRIBUTE11      => r_PR_.INFORMATION121
9645              ,P_PR_ATTRIBUTE12      => r_PR_.INFORMATION122
9646              ,P_PR_ATTRIBUTE13      => r_PR_.INFORMATION123
9647              ,P_PR_ATTRIBUTE14      => r_PR_.INFORMATION124
9648              ,P_PR_ATTRIBUTE15      => r_PR_.INFORMATION125
9649              ,P_PR_ATTRIBUTE16      => r_PR_.INFORMATION126
9650              ,P_PR_ATTRIBUTE17      => r_PR_.INFORMATION127
9651              ,P_PR_ATTRIBUTE18      => r_PR_.INFORMATION128
9652              ,P_PR_ATTRIBUTE19      => r_PR_.INFORMATION129
9653              ,P_PR_ATTRIBUTE2      => r_PR_.INFORMATION112
9654              ,P_PR_ATTRIBUTE20      => r_PR_.INFORMATION130
9655              ,P_PR_ATTRIBUTE21      => r_PR_.INFORMATION131
9656              ,P_PR_ATTRIBUTE22      => r_PR_.INFORMATION132
9657              ,P_PR_ATTRIBUTE23      => r_PR_.INFORMATION133
9658              ,P_PR_ATTRIBUTE24      => r_PR_.INFORMATION134
9659              ,P_PR_ATTRIBUTE25      => r_PR_.INFORMATION135
9660              ,P_PR_ATTRIBUTE26      => r_PR_.INFORMATION136
9661              ,P_PR_ATTRIBUTE27      => r_PR_.INFORMATION137
9662              ,P_PR_ATTRIBUTE28      => r_PR_.INFORMATION138
9663              ,P_PR_ATTRIBUTE29      => r_PR_.INFORMATION139
9664              ,P_PR_ATTRIBUTE3      => r_PR_.INFORMATION113
9665              ,P_PR_ATTRIBUTE30      => r_PR_.INFORMATION140
9666              ,P_PR_ATTRIBUTE4      => r_PR_.INFORMATION114
9667              ,P_PR_ATTRIBUTE5      => r_PR_.INFORMATION115
9668              ,P_PR_ATTRIBUTE6      => r_PR_.INFORMATION116
9669              ,P_PR_ATTRIBUTE7      => r_PR_.INFORMATION117
9670              ,P_PR_ATTRIBUTE8      => r_PR_.INFORMATION118
9671              ,P_PR_ATTRIBUTE9      => r_PR_.INFORMATION119
9672              ,P_PR_ATTRIBUTE_CATEGORY      => r_PR_.INFORMATION110
9673              ,P_PYRL_RT_ID      => l_pyrl_rt_id
9674              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
9675                 --
9676                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
9677                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
9678                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
9679                 ,P_DATETRACK_MODE        => l_datetrack_mode
9680              );
9681              --
9682              end if;
9683            end if;
9684            --
9685            -- Delete the row if it is end dated.
9686            --
9687            if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
9688              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
9689                 trunc(l_max_eed) = r_PR_.information3) then
9690                 --
9691                 BEN_PAYROLL_RATE_API.delete_PAYROLL_RATE(
9692                    --
9693                    p_validate                       => false
9694                    ,p_pyrl_rt_id                   => l_pyrl_rt_id
9695                    ,p_effective_start_date           => l_effective_start_date
9696                    ,p_effective_end_date             => l_effective_end_date
9697                    ,p_object_version_number          => l_object_version_number
9698                    ,p_effective_date                 => l_max_eed
9699                    ,p_datetrack_mode                 => hr_api.g_delete
9700                    --
9701                    );
9702                    --
9703            end if;
9704            --
9705            l_prev_pk_id := l_current_pk_id ;
9706            --
9707          end if;
9708          --
9709        end if;
9710        --
9711      end if;
9712      --
9713    end loop;
9714    --
9715  exception when others then
9716     --
9717     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'PR_',r_pr_.information5 );
9718     --
9719  end create_PR__rows;
9720 
9721    --
9722    ---------------------------------------------------------------
9723    ----------------------< create_PBR_rows >-----------------------
9724    ---------------------------------------------------------------
9725    --
9726    procedure create_PBR_rows
9727    (
9728          p_validate                       in  number     default 0
9729         ,p_copy_entity_txn_id             in  number
9730         ,p_effective_date                 in  date
9731         ,p_prefix_suffix_text             in  varchar2  default null
9732         ,p_reuse_object_flag              in  varchar2  default null
9733         ,p_target_business_group_id       in  varchar2  default null
9734         ,p_prefix_suffix_cd               in  varchar2  default null
9735    ) is
9736    --
9737    l_PAY_BASIS_ID  number;
9738    l_VRBL_RT_PRFL_ID  number;
9739    cursor c_unique_PBR(l_table_alias varchar2) is
9740    select distinct cpe.information1,
9741      cpe.information2,
9742      cpe.information3,
9743      cpe.table_route_id
9744    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
9745         pqh_table_route tr
9746    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
9747    and   cpe.table_route_id     = tr.table_route_id
9748    -- and   tr.where_clause        = l_BEN_PY_BSS_RT_F
9749    and tr.table_alias = l_table_alias
9750    and   cpe.number_of_copies   = 1 -- ADDITION
9751    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
9752    order by information1, information2; --added for bug: 5151945
9753    --
9754    --
9755    cursor c_PBR_min_max_dates(c_table_route_id  number,
9756                 c_information1   Number) is
9757    select
9758      min(cpe.information2) min_esd,
9759      max(cpe.information3) min_eed
9760    from ben_copy_entity_results cpe
9761    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
9762    and   cpe.table_route_id     = c_table_route_id
9763    and   cpe.information1       = c_information1 ;
9764    --
9765    cursor c_PBR(c_table_route_id  number,
9766                 c_information1   number,
9767                 c_information2   Date,
9768                 c_information3   Date)  is
9769    select
9770      cpe.*
9771    from ben_copy_entity_results cpe
9772    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
9773    and   cpe.table_route_id     = c_table_route_id
9774    and   cpe.information1       = c_information1
9775    and   cpe.information2       = c_information2
9776    and   cpe.information3       = c_information3
9777    and rownum = 1 ;
9778    -- Date Track target record
9779    cursor c_find_PBR_in_target(
9780                                 c_effective_start_date    date,
9781                                 c_effective_end_date      date,
9782                                 c_business_group_id       number,
9783                                 c_new_pk_id               number) is
9784    select
9785      PBR.py_bss_rt_id new_value
9786    from BEN_PY_BSS_RT_F PBR
9787    where
9788    PBR.PAY_BASIS_ID     = l_PAY_BASIS_ID  and
9789    PBR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
9790    PBR.business_group_id  = c_business_group_id
9791    and   PBR.py_bss_rt_id  <> c_new_pk_id
9792 --TEMPIK
9793    and c_effective_start_date between effective_start_date
9794                             and effective_end_date ;
9795 --END TEMPIK
9796 /*TEMPIK
9797    and exists ( select null
9798                 from BEN_PY_BSS_RT_F PBR1
9799                 where
9800                 PBR1.PAY_BASIS_ID     = l_PAY_BASIS_ID  and
9801                 PBR1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
9802                 PBR1.business_group_id  = c_business_group_id
9803                 and   PBR1.effective_start_date <= c_effective_start_date )
9804    and exists ( select null
9805                 from BEN_PY_BSS_RT_F PBR2
9806                 where
9807                 PBR2.PAY_BASIS_ID     = l_PAY_BASIS_ID  and
9808                 PBR2.VRBL_RT_PRFL_ID  = l_VRBL_RT_PRFL_ID  and
9809                 PBR2.business_group_id  = c_business_group_id
9810                 and   PBR2.effective_end_date >= c_effective_end_date )
9811                 ;
9812 TEMPIK */
9813    --TEMPIK
9814    l_dt_rec_found            boolean ;
9815    --END TEMPIK
9816    --
9817    l_current_pk_id           number := null ;
9818    --UPD START
9819    --
9820    l_update                  boolean      := false ;
9821    l_datetrack_mode          varchar2(80) := hr_api.g_update;
9822    l_process_date            date;
9823    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
9824    --
9825    --UPD END
9826    l_prev_pk_id              number := null ;
9827    l_first_rec               boolean := true ;
9828    r_PBR                     c_PBR%rowtype;
9829    l_py_bss_rt_id             number ;
9830    l_object_version_number   number ;
9831    l_effective_start_date    date ;
9832    l_effective_end_date      date ;
9833    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
9834    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
9835    l_new_value               number(15);
9836    l_object_found_in_target  boolean := false ;
9837    l_min_esd                 date;
9838    l_max_eed                 date;
9839    l_effective_date          date;
9840    --
9841  begin
9842    -- Initialization
9843    l_object_found_in_target := false ;
9844    -- End Initialization
9845    -- Derive the prefix - sufix
9846    if   p_prefix_suffix_cd = 'PREFIX' then
9847      l_prefix  := p_prefix_suffix_text ;
9848    elsif p_prefix_suffix_cd = 'SUFFIX' then
9849      l_suffix   := p_prefix_suffix_text ;
9850    else
9851      l_prefix := null ;
9852      l_suffix  := null ;
9853    end if ;
9854    -- End Prefix Sufix derivation
9855    for r_PBR_unique in c_unique_PBR('PBR') loop
9856 
9857      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
9858         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
9859          r_PBR_unique.information3 >=
9860                  ben_pd_copy_to_ben_one.g_copy_effective_date)
9861         ) then
9862        --
9863        hr_utility.set_location(' r_PBR_unique.table_route_id '||r_PBR_unique.table_route_id,10);
9864        hr_utility.set_location(' r_PBR_unique.information1 '||r_PBR_unique.information1,10);
9865        hr_utility.set_location( 'r_PBR_unique.information2 '||r_PBR_unique.information2,10);
9866        hr_utility.set_location( 'r_PBR_unique.information3 '||r_PBR_unique.information3,10);
9867        -- If reuse objects flag is 'Y' then check for the object in the target business group
9868        -- if found insert the record into PLSql table and exit the loop else try create the
9869        -- object in the target business group
9870        --
9871        l_object_found_in_target := false ;
9872        l_min_esd := null ;
9873        l_max_eed := null ;
9874        open c_PBR_min_max_dates(r_PBR_unique.table_route_id, r_PBR_unique.information1 ) ;
9875        fetch c_PBR_min_max_dates into l_min_esd,l_max_eed ;
9876        --
9877 
9878        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
9879             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
9880          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
9881        end if;
9882        l_min_esd := greatest(l_min_esd,r_PBR_unique.information2);
9883        open c_PBR(r_PBR_unique.table_route_id,
9884                 r_PBR_unique.information1,
9885                 r_PBR_unique.information2,
9886                 r_PBR_unique.information3 ) ;
9887        --
9888        fetch c_PBR into r_PBR ;
9889        --
9890        close c_PBR ;
9891        --
9892        if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
9893          l_PAY_BASIS_ID := r_PBR.information176;
9894        else
9895          l_PAY_BASIS_ID := r_PBR.information174;
9896        end if;
9897        --
9898        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_PBR.information262,r_PBR_unique.dml_operation);
9899 
9900        if l_PAY_BASIS_ID is null then
9901          close c_PBR_min_max_dates;
9902          --
9903          log_nomapping_data(p_parent_table_alias =>'VPF'
9904                      ,p_parent_pk_id         => r_PBR.information262
9905                      ,p_copy_entity_txn_id   => p_copy_entity_txn_id
9906                      ,p_child_table_alias    => 'PBR'
9907                      ,p_child_data           => r_PBR.information173 );
9908 
9909          --
9910        else
9911        --UPD START
9912        l_update := false;
9913        l_process_date := p_effective_date;
9914        l_dml_operation:= r_PBR_unique.dml_operation ;
9915        --
9916        if l_dml_operation = 'UPDATE' then
9917          --
9918          l_object_found_in_target := TRUE;
9919          --
9920          if l_process_date between r_PBR_unique.information2 and r_PBR_unique.information3 then
9921                l_update := true;
9922                if r_PBR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
9923                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'PY_BSS_RT_ID'
9924                then
9925                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'PY_BSS_RT_ID' ;
9926                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_PBR_unique.information1 ;
9927                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_PBR_unique.information1 ;
9928                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
9929                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_PBR_unique.table_route_id;
9930                   --
9931                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
9932                   --
9933                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
9934                   --
9935                   -- log_data('PBR',l_new_value,l_prefix || r_PBR_unique.name|| l_suffix,'REUSED');
9936                   --
9937                end if ;
9938                hr_utility.set_location( 'found record for update',10);
9939            --
9940          else
9941            --
9942            l_update := false;
9943            --
9944          end if;
9945        else
9946          --
9947          --UPD END
9948          if p_reuse_object_flag = 'Y' then
9949            if c_PBR_min_max_dates%found then
9950               -- cursor to find the object
9951               open c_find_PBR_in_target( l_min_esd,l_max_eed,
9952                                     p_target_business_group_id, nvl(l_py_bss_rt_id, -999)  ) ;
9953               fetch c_find_PBR_in_target into l_new_value ;
9954               if c_find_PBR_in_target%found then
9955                 --
9956              --TEMPIK
9957              l_dt_rec_found :=   dt_api.check_min_max_dates
9958                  (p_base_table_name => 'BEN_PY_BSS_RT_F',
9959                   p_base_key_column => 'PY_BSS_RT_ID',
9960                   p_base_key_value  => l_new_value,
9961                   p_from_date       => l_min_esd,
9962                   p_to_date         => l_max_eed );
9963              if l_dt_rec_found THEN
9964              --END TEMPIK
9965                 if r_PBR_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
9966                    nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'PY_BSS_RT_ID'  then
9967                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'PY_BSS_RT_ID' ;
9968                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_PBR_unique.information1 ;
9969                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
9970                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
9971                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PBR_unique.table_route_id;
9972                    --
9973                    -- 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) ;
9974                    --
9975                    BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
9976                 end if ;
9977                 --
9978                 l_object_found_in_target := true ;
9979              --TEMPIK
9980              end if; -- l_dt_rec_found
9981              --END TEMPIK
9982               end if;
9983               close c_find_PBR_in_target ;
9984            --
9985            end if;
9986          end if ;
9987          --
9988          end if;
9989          close c_PBR_min_max_dates ;
9990          if not l_object_found_in_target OR l_update   then
9991            --
9992            l_current_pk_id := r_PBR.information1;
9993            --
9994            hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
9995            hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
9996            --
9997            if l_current_pk_id =  l_prev_pk_id  then
9998              --
9999              l_first_rec := false ;
10000              --
10001            else
10002              --
10003              l_first_rec := true ;
10004              --
10005            end if ;
10006            --
10007 
10008            l_effective_date := r_PBR.information2;
10009            if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
10010                 l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
10011              l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
10012            end if;
10013 
10014            if l_first_rec and not l_update then
10015              -- Call Create routine.
10016              hr_utility.set_location(' BEN_PY_BSS_RT_F CREATE_PAY_BASIS_RATE ',20);
10017              BEN_PAY_BASIS_RATE_API.CREATE_PAY_BASIS_RATE(
10018                 --
10019                 P_VALIDATE               => false
10020                 ,P_EFFECTIVE_DATE        => l_effective_date
10021                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
10022                 --
10023               ,P_EXCLD_FLAG      => r_PBR.INFORMATION11
10024              ,P_ORDR_NUM      => r_PBR.INFORMATION257
10025              ,P_PAY_BASIS_ID      => l_PAY_BASIS_ID
10026              ,P_PBR_ATTRIBUTE1      => r_PBR.INFORMATION111
10027              ,P_PBR_ATTRIBUTE10      => r_PBR.INFORMATION120
10028              ,P_PBR_ATTRIBUTE11      => r_PBR.INFORMATION121
10029              ,P_PBR_ATTRIBUTE12      => r_PBR.INFORMATION122
10030              ,P_PBR_ATTRIBUTE13      => r_PBR.INFORMATION123
10031              ,P_PBR_ATTRIBUTE14      => r_PBR.INFORMATION124
10032              ,P_PBR_ATTRIBUTE15      => r_PBR.INFORMATION125
10033              ,P_PBR_ATTRIBUTE16      => r_PBR.INFORMATION126
10034              ,P_PBR_ATTRIBUTE17      => r_PBR.INFORMATION127
10035              ,P_PBR_ATTRIBUTE18      => r_PBR.INFORMATION128
10036              ,P_PBR_ATTRIBUTE19      => r_PBR.INFORMATION129
10037              ,P_PBR_ATTRIBUTE2      => r_PBR.INFORMATION112
10038              ,P_PBR_ATTRIBUTE20      => r_PBR.INFORMATION130
10039              ,P_PBR_ATTRIBUTE21      => r_PBR.INFORMATION131
10040              ,P_PBR_ATTRIBUTE22      => r_PBR.INFORMATION132
10041              ,P_PBR_ATTRIBUTE23      => r_PBR.INFORMATION133
10042              ,P_PBR_ATTRIBUTE24      => r_PBR.INFORMATION134
10043              ,P_PBR_ATTRIBUTE25      => r_PBR.INFORMATION135
10044              ,P_PBR_ATTRIBUTE26      => r_PBR.INFORMATION136
10045              ,P_PBR_ATTRIBUTE27      => r_PBR.INFORMATION137
10046              ,P_PBR_ATTRIBUTE28      => r_PBR.INFORMATION138
10047              ,P_PBR_ATTRIBUTE29      => r_PBR.INFORMATION139
10048              ,P_PBR_ATTRIBUTE3      => r_PBR.INFORMATION113
10049              ,P_PBR_ATTRIBUTE30      => r_PBR.INFORMATION140
10050              ,P_PBR_ATTRIBUTE4      => r_PBR.INFORMATION114
10051              ,P_PBR_ATTRIBUTE5      => r_PBR.INFORMATION115
10052              ,P_PBR_ATTRIBUTE6      => r_PBR.INFORMATION116
10053              ,P_PBR_ATTRIBUTE7      => r_PBR.INFORMATION117
10054              ,P_PBR_ATTRIBUTE8      => r_PBR.INFORMATION118
10055              ,P_PBR_ATTRIBUTE9      => r_PBR.INFORMATION119
10056              ,P_PBR_ATTRIBUTE_CATEGORY      => r_PBR.INFORMATION110
10057              ,P_PY_BSS_RT_ID      => l_py_bss_rt_id
10058              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
10059                 --
10060                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
10061                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
10062                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
10063              );
10064              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
10065              -- Update all relevent cer records with new pk_id
10066              hr_utility.set_location('Before plsql table ',222);
10067              hr_utility.set_location('new_value id '||l_py_bss_rt_id,222);
10068              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'PY_BSS_RT_ID' ;
10069              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_PBR.information1 ;
10070              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_PY_BSS_RT_ID ;
10071              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
10072              BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PBR_unique.table_route_id;
10073              hr_utility.set_location('After plsql table ',222);
10074              --
10075              -- 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 ) ;
10076              --
10077              BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
10078              --
10079            else
10080              --
10081              -- Call Update routine for the pk_id created in prev run .
10082            --UPD START
10083            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
10084            --
10085            if l_update then
10086              --
10087              l_datetrack_mode := r_PBR.datetrack_mode ;
10088              --
10089              get_dt_modes(
10090                p_effective_date        => l_process_date,
10091                p_effective_end_date    => r_PBR.information3,
10092                p_effective_start_date  => r_PBR.information2,
10093                p_dml_operation         => r_PBR.dml_operation,
10094                p_datetrack_mode        => l_datetrack_mode );
10095            --    p_update                => l_update
10096              --
10097              l_effective_date := l_process_date;
10098              l_PY_BSS_RT_ID   := r_PBR.information1;
10099              l_object_version_number := r_PBR.information265;
10100              --
10101            end if;
10102            --
10103            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
10104            --
10105            IF l_update OR l_dml_operation <> 'UPDATE' THEN
10106              -- insert the table_name,old_pk_id,new_pk_id into a plsql record
10107              hr_utility.set_location(' BEN_PY_BSS_RT_F UPDATE_PAY_BASIS_RATE ',30);
10108              BEN_PAY_BASIS_RATE_API.UPDATE_PAY_BASIS_RATE(
10109                 --
10110                 P_VALIDATE               => false
10111                 ,P_EFFECTIVE_DATE        => l_effective_date
10112                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
10113                 --
10114              ,P_EXCLD_FLAG      => r_PBR.INFORMATION11
10115              ,P_ORDR_NUM      => r_PBR.INFORMATION257
10116              ,P_PAY_BASIS_ID      => l_PAY_BASIS_ID
10117              ,P_PBR_ATTRIBUTE1      => r_PBR.INFORMATION111
10118              ,P_PBR_ATTRIBUTE10      => r_PBR.INFORMATION120
10119              ,P_PBR_ATTRIBUTE11      => r_PBR.INFORMATION121
10120              ,P_PBR_ATTRIBUTE12      => r_PBR.INFORMATION122
10121              ,P_PBR_ATTRIBUTE13      => r_PBR.INFORMATION123
10122              ,P_PBR_ATTRIBUTE14      => r_PBR.INFORMATION124
10123              ,P_PBR_ATTRIBUTE15      => r_PBR.INFORMATION125
10124              ,P_PBR_ATTRIBUTE16      => r_PBR.INFORMATION126
10125              ,P_PBR_ATTRIBUTE17      => r_PBR.INFORMATION127
10126              ,P_PBR_ATTRIBUTE18      => r_PBR.INFORMATION128
10127              ,P_PBR_ATTRIBUTE19      => r_PBR.INFORMATION129
10128              ,P_PBR_ATTRIBUTE2      => r_PBR.INFORMATION112
10129              ,P_PBR_ATTRIBUTE20      => r_PBR.INFORMATION130
10130              ,P_PBR_ATTRIBUTE21      => r_PBR.INFORMATION131
10131              ,P_PBR_ATTRIBUTE22      => r_PBR.INFORMATION132
10132              ,P_PBR_ATTRIBUTE23      => r_PBR.INFORMATION133
10133              ,P_PBR_ATTRIBUTE24      => r_PBR.INFORMATION134
10134              ,P_PBR_ATTRIBUTE25      => r_PBR.INFORMATION135
10135              ,P_PBR_ATTRIBUTE26      => r_PBR.INFORMATION136
10136              ,P_PBR_ATTRIBUTE27      => r_PBR.INFORMATION137
10137              ,P_PBR_ATTRIBUTE28      => r_PBR.INFORMATION138
10138              ,P_PBR_ATTRIBUTE29      => r_PBR.INFORMATION139
10139              ,P_PBR_ATTRIBUTE3      => r_PBR.INFORMATION113
10140              ,P_PBR_ATTRIBUTE30      => r_PBR.INFORMATION140
10141              ,P_PBR_ATTRIBUTE4      => r_PBR.INFORMATION114
10142              ,P_PBR_ATTRIBUTE5      => r_PBR.INFORMATION115
10143              ,P_PBR_ATTRIBUTE6      => r_PBR.INFORMATION116
10144              ,P_PBR_ATTRIBUTE7      => r_PBR.INFORMATION117
10145              ,P_PBR_ATTRIBUTE8      => r_PBR.INFORMATION118
10146              ,P_PBR_ATTRIBUTE9      => r_PBR.INFORMATION119
10147              ,P_PBR_ATTRIBUTE_CATEGORY      => r_PBR.INFORMATION110
10148              ,P_PY_BSS_RT_ID      => l_py_bss_rt_id
10149              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
10150                 --
10151                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
10152                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
10153                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
10154                 ,P_DATETRACK_MODE        => l_datetrack_mode
10155              );
10156              --
10157              end if;
10158            end if;
10159            --
10160            -- Delete the row if it is end dated.
10161            --
10162            if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
10163              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
10164                 trunc(l_max_eed) = r_PBR.information3) then
10165                 --
10166                 BEN_PAY_BASIS_RATE_API.delete_PAY_BASIS_RATE(
10167                    --
10168                    p_validate                       => false
10169                    ,p_py_bss_rt_id                   => l_py_bss_rt_id
10170                    ,p_effective_start_date           => l_effective_start_date
10171                    ,p_effective_end_date             => l_effective_end_date
10172                    ,p_object_version_number          => l_object_version_number
10173                    ,p_effective_date                 => l_max_eed
10174                    ,p_datetrack_mode                 => hr_api.g_delete
10175                    --
10176                    );
10177                    --
10178            end if;
10179            --
10180            l_prev_pk_id := l_current_pk_id ;
10181            --
10182          end if;
10183          --
10184        end if;
10185        --
10186      end if;
10187      --
10188    end loop;
10189    --
10190  exception when others then
10191     --
10192     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'PBR',r_pbr.information5 );
10193     --
10194  end create_PBR_rows;
10195 
10196    --
10197    --
10198    --
10199    ---------------------------------------------------------------
10200    ----------------------< create_CQR_rows >-----------------------
10201    ---------------------------------------------------------------
10202    --
10203    procedure create_CQR_rows
10204    (
10205          p_validate                       in  number     default 0
10206         ,p_copy_entity_txn_id             in  number
10207         ,p_effective_date                 in  date
10208         ,p_prefix_suffix_text             in  varchar2  default null
10209         ,p_reuse_object_flag              in  varchar2  default null
10210         ,p_target_business_group_id       in  varchar2  default null
10211         ,p_prefix_suffix_cd               in  varchar2  default null
10212    ) is
10213    --
10214    l_PGM_ID  number;
10215    l_PTIP_ID  number;
10216    l_VRBL_RT_PRFL_ID  number;
10217    cursor c_unique_CQR(l_table_alias varchar2) is
10218    select distinct cpe.information1,
10219      cpe.information2,
10220      cpe.information3,
10221      cpe.table_route_id
10222    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
10223         pqh_table_route tr
10224    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
10225    and   cpe.table_route_id     = tr.table_route_id
10226    -- and   tr.where_clause        = l_BEN_CBR_QUALD_BNF_RT_F
10227    and tr.table_alias = l_table_alias
10228    and   cpe.number_of_copies   = 1 -- ADDITION
10229    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
10230    order by information1, information2; --added for bug: 5151945
10231    --
10232    --
10233    cursor c_CQR_min_max_dates(c_table_route_id  number,
10234                 c_information1   Number) is
10235    select
10236      min(cpe.information2) min_esd,
10237      max(cpe.information3) min_eed
10238    from ben_copy_entity_results cpe
10239    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
10240    and   cpe.table_route_id     = c_table_route_id
10241    and   cpe.information1       = c_information1 ;
10242    --
10243    cursor c_CQR(c_table_route_id  number,
10244                 c_information1   number,
10245                 c_information2   Date,
10246                 c_information3   Date)  is
10247    select
10248      cpe.*
10249    from ben_copy_entity_results cpe
10250    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
10251    and   cpe.table_route_id     = c_table_route_id
10252    and   cpe.information1       = c_information1
10253    and   cpe.information2       = c_information2
10254    and   cpe.information3       = c_information3
10255    and rownum = 1 ;
10256    -- Date Track target record
10257    cursor c_find_CQR_in_target(
10258                                 c_effective_start_date    date,
10259                                 c_effective_end_date      date,
10260                                 c_business_group_id       number,
10261                                 c_new_pk_id               number) is
10262    select
10263      CQR.cbr_quald_bnf_rt_id new_value
10264    from BEN_CBR_QUALD_BNF_RT_F CQR
10265    where
10266    nvl(CQR.PGM_ID,-999)     = nvl(l_PGM_ID,-999)  and
10267    nvl(CQR.PTIP_ID,-999)     = nvl(l_PTIP_ID,-999)  and
10268    CQR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
10269    CQR.business_group_id  = c_business_group_id
10270    and   CQR.cbr_quald_bnf_rt_id  <> c_new_pk_id
10271 --TEMPIK
10272    and c_effective_start_date between effective_start_date
10273                             and effective_end_date ;
10274 --END TEMPIK
10275 /*TEMPIK
10276    and exists ( select null
10277                 from BEN_CBR_QUALD_BNF_RT_F CQR1
10278                 where
10279                 nvl(CQR1.PGM_ID,-999)     = nvl(l_PGM_ID,-999)  and
10280                 nvl(CQR1.PTIP_ID,-999)     = nvl(l_PTIP_ID,-999)  and
10281                 CQR1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
10282                 CQR1.business_group_id  = c_business_group_id
10283                 and   CQR1.effective_start_date <= c_effective_start_date )
10284    and exists ( select null
10285                 from BEN_CBR_QUALD_BNF_RT_F CQR2
10286                 where
10287                 nvl(CQR2.PGM_ID,-999)     = nvl(l_PGM_ID,-999)  and
10288                 nvl(CQR2.PTIP_ID,-999)     = nvl(l_PTIP_ID,-999)  and
10289                 CQR2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
10290                 CQR2.business_group_id  = c_business_group_id
10291                 and   CQR2.effective_end_date >= c_effective_end_date )
10292                 ;
10293 TEMPIK */
10294    --TEMPIK
10295    l_dt_rec_found            boolean ;
10296    --END TEMPIK
10297    --
10298    l_current_pk_id           number := null ;
10299    --UPD START
10300    --
10301    l_update                  boolean      := false ;
10302    l_datetrack_mode          varchar2(80) := hr_api.g_update;
10303    l_process_date            date;
10304    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
10305    --
10306    --UPD END
10307    l_prev_pk_id              number := null ;
10308    l_first_rec               boolean := true ;
10309    r_CQR                     c_CQR%rowtype;
10310    l_cbr_quald_bnf_rt_id             number ;
10311    l_object_version_number   number ;
10312    l_effective_start_date    date ;
10313    l_effective_end_date      date ;
10314    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
10315    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
10316    l_new_value               number(15);
10317    l_object_found_in_target  boolean := false ;
10318    l_min_esd                 date;
10319    l_max_eed                 date;
10320    l_effective_date          date;
10321    --
10322  begin
10323    -- Initialization
10324    l_object_found_in_target := false ;
10325    -- End Initialization
10326    -- Derive the prefix - sufix
10327    if   p_prefix_suffix_cd = 'PREFIX' then
10328      l_prefix  := p_prefix_suffix_text ;
10329    elsif p_prefix_suffix_cd = 'SUFFIX' then
10330      l_suffix   := p_prefix_suffix_text ;
10331    else
10332      l_prefix := null ;
10333      l_suffix  := null ;
10334    end if ;
10335    -- End Prefix Sufix derivation
10336    for r_CQR_unique in c_unique_CQR('CQR') loop
10337 
10338      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
10339         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
10340          r_CQR_unique.information3 >=
10341                  ben_pd_copy_to_ben_one.g_copy_effective_date)
10342         ) then
10343        --
10344        hr_utility.set_location(' r_CQR_unique.table_route_id '||r_CQR_unique.table_route_id,10);
10345        hr_utility.set_location(' r_CQR_unique.information1 '||r_CQR_unique.information1,10);
10346        hr_utility.set_location( 'r_CQR_unique.information2 '||r_CQR_unique.information2,10);
10347        hr_utility.set_location( 'r_CQR_unique.information3 '||r_CQR_unique.information3,10);
10348        -- If reuse objects flag is 'Y' then check for the object in the target business group
10349        -- if found insert the record into PLSql table and exit the loop else try create the
10350        -- object in the target business group
10351        --
10352        l_object_found_in_target := false ;
10353        l_min_esd := null ;
10354        l_max_eed := null ;
10355        open c_CQR_min_max_dates(r_CQR_unique.table_route_id, r_CQR_unique.information1 ) ;
10356        fetch c_CQR_min_max_dates into l_min_esd,l_max_eed ;
10357        --
10358 
10359        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
10360             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
10361          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
10362        end if;
10363        l_min_esd := greatest(l_min_esd,r_CQR_unique.information2);
10364        open c_CQR(r_CQR_unique.table_route_id,
10365                 r_CQR_unique.information1,
10366                 r_CQR_unique.information2,
10367                 r_CQR_unique.information3 ) ;
10368        --
10369        fetch c_CQR into r_CQR ;
10370        --
10371        close c_CQR ;
10372        --
10373 
10374        -- Only For Use by Create Wizard - Same Business Group
10375        l_PGM_ID := NVL(get_fk('PGM_ID', r_CQR.INFORMATION260,r_CQR_unique.dml_operation),
10376                        r_CQR.INFORMATION260);
10377 
10378        l_PTIP_ID := NVL(get_fk('PTIP_ID',  r_CQR.INFORMATION259,r_CQR_unique.dml_operation),
10379                         r_CQR.INFORMATION259);
10380 
10381        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_CQR.information262,r_CQR_unique.dml_operation);
10382        --UPD START
10383        l_update := false;
10384        l_process_date := p_effective_date;
10385        l_dml_operation:= r_CQR_unique.dml_operation ;
10386        --
10387        if l_dml_operation = 'UPDATE' then
10388          --
10389          l_object_found_in_target := TRUE;
10390          --
10391          if l_process_date between r_CQR_unique.information2 and r_CQR_unique.information3 then
10392                l_update := true;
10393                if r_CQR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
10394                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'CBR_QUALD_BNF_RT_ID'
10395                then
10396                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'CBR_QUALD_BNF_RT_ID' ;
10397                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_CQR_unique.information1 ;
10398                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_CQR_unique.information1 ;
10399                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
10400                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_CQR_unique.table_route_id;
10401                   --
10402                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
10403                   --
10404                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
10405                   --
10406                   -- log_data('CQR',l_new_value,l_prefix || r_CQR_unique.name|| l_suffix,'REUSED');
10407                   --
10408                end if ;
10409                hr_utility.set_location( 'found record for update',10);
10410            --
10411          else
10412            --
10413            l_update := false;
10414            --
10415          end if;
10416        else
10417          --
10418          --UPD END
10419        if p_reuse_object_flag = 'Y' then
10420          if c_CQR_min_max_dates%found then
10421            -- cursor to find the object
10422            open c_find_CQR_in_target( l_min_esd,l_max_eed,
10423                                  p_target_business_group_id, nvl(l_cbr_quald_bnf_rt_id, -999)  ) ;
10424            fetch c_find_CQR_in_target into l_new_value ;
10425            if c_find_CQR_in_target%found then
10426              --
10427              --TEMPIK
10428              l_dt_rec_found :=   dt_api.check_min_max_dates
10429                  (p_base_table_name => 'BEN_CBR_QUALD_BNF_RT_F',
10430                   p_base_key_column => 'CBR_QUALD_BNF_RT_ID',
10431                   p_base_key_value  => l_new_value,
10432                   p_from_date       => l_min_esd,
10433                   p_to_date         => l_max_eed );
10434              if l_dt_rec_found THEN
10435              --END TEMPIK
10436              if r_CQR_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
10437                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'CBR_QUALD_BNF_RT_ID'  then
10438                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'CBR_QUALD_BNF_RT_ID' ;
10439                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_CQR_unique.information1 ;
10440                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
10441                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
10442                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_CQR_unique.table_route_id;
10443                 --
10444                 -- 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) ;
10445                 --
10446                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
10447              end if ;
10448              --
10449              l_object_found_in_target := true ;
10450              --TEMPIK
10451              end if; -- l_dt_rec_found
10452              --END TEMPIK
10453            end if;
10454            close c_find_CQR_in_target ;
10455          --
10456          end if;
10457        end if ;
10458        --
10459        end if;
10460        close c_CQR_min_max_dates ;
10461        if not l_object_found_in_target OR l_update   then
10462          --
10463          l_current_pk_id := r_CQR.information1;
10464          --
10465          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
10466          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
10467          --
10468          if l_current_pk_id =  l_prev_pk_id  then
10469            --
10470            l_first_rec := false ;
10471            --
10472          else
10473            --
10474            l_first_rec := true ;
10475            --
10476          end if ;
10477          --
10478 
10479          l_effective_date := r_CQR.information2;
10480          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
10481               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
10482            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
10483          end if;
10484 
10485          if l_first_rec and not l_update then
10486            -- Call Create routine.
10487            hr_utility.set_location(' BEN_CBR_QUALD_BNF_RT_F CREATE_CBR_QUALD_BNF_RT ',20);
10488            BEN_CBR_QUALD_BNF_RT_API.CREATE_CBR_QUALD_BNF_RT(
10489              --
10490              P_VALIDATE               => false
10491              ,P_EFFECTIVE_DATE        => l_effective_date
10492              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
10493              --
10494              ,P_CBR_QUALD_BNF_RT_ID      => l_cbr_quald_bnf_rt_id
10495              ,P_CQR_ATTRIBUTE1      => r_CQR.INFORMATION111
10496              ,P_CQR_ATTRIBUTE10      => r_CQR.INFORMATION120
10497              ,P_CQR_ATTRIBUTE11      => r_CQR.INFORMATION121
10498              ,P_CQR_ATTRIBUTE12      => r_CQR.INFORMATION122
10499              ,P_CQR_ATTRIBUTE13      => r_CQR.INFORMATION123
10500              ,P_CQR_ATTRIBUTE14      => r_CQR.INFORMATION124
10501              ,P_CQR_ATTRIBUTE15      => r_CQR.INFORMATION125
10502              ,P_CQR_ATTRIBUTE16      => r_CQR.INFORMATION126
10503              ,P_CQR_ATTRIBUTE17      => r_CQR.INFORMATION127
10504              ,P_CQR_ATTRIBUTE18      => r_CQR.INFORMATION128
10505              ,P_CQR_ATTRIBUTE19      => r_CQR.INFORMATION129
10506              ,P_CQR_ATTRIBUTE2      => r_CQR.INFORMATION112
10507              ,P_CQR_ATTRIBUTE20      => r_CQR.INFORMATION130
10508              ,P_CQR_ATTRIBUTE21      => r_CQR.INFORMATION131
10509              ,P_CQR_ATTRIBUTE22      => r_CQR.INFORMATION132
10510              ,P_CQR_ATTRIBUTE23      => r_CQR.INFORMATION133
10511              ,P_CQR_ATTRIBUTE24      => r_CQR.INFORMATION134
10512              ,P_CQR_ATTRIBUTE25      => r_CQR.INFORMATION135
10513              ,P_CQR_ATTRIBUTE26      => r_CQR.INFORMATION136
10514              ,P_CQR_ATTRIBUTE27      => r_CQR.INFORMATION137
10515              ,P_CQR_ATTRIBUTE28      => r_CQR.INFORMATION138
10516              ,P_CQR_ATTRIBUTE29      => r_CQR.INFORMATION139
10517              ,P_CQR_ATTRIBUTE3      => r_CQR.INFORMATION113
10518              ,P_CQR_ATTRIBUTE30      => r_CQR.INFORMATION140
10519              ,P_CQR_ATTRIBUTE4      => r_CQR.INFORMATION114
10520              ,P_CQR_ATTRIBUTE5      => r_CQR.INFORMATION115
10521              ,P_CQR_ATTRIBUTE6      => r_CQR.INFORMATION116
10522              ,P_CQR_ATTRIBUTE7      => r_CQR.INFORMATION117
10523              ,P_CQR_ATTRIBUTE8      => r_CQR.INFORMATION118
10524              ,P_CQR_ATTRIBUTE9      => r_CQR.INFORMATION119
10525              ,P_CQR_ATTRIBUTE_CATEGORY      => r_CQR.INFORMATION110
10526              ,P_ORDR_NUM      => r_CQR.INFORMATION257
10527              ,P_PGM_ID      => l_PGM_ID
10528              ,P_PTIP_ID      => l_PTIP_ID
10529              ,P_QUALD_BNF_FLAG      => r_CQR.INFORMATION11
10530              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
10531              --
10532              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
10533              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
10534              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
10535            );
10536            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
10537            -- Update all relevent cer records with new pk_id
10538            hr_utility.set_location('Before plsql table ',222);
10539            hr_utility.set_location('new_value id '||l_cbr_quald_bnf_rt_id,222);
10540            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'CBR_QUALD_BNF_RT_ID' ;
10541            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_CQR.information1 ;
10542            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_CBR_QUALD_BNF_RT_ID ;
10543            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
10544            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_CQR_unique.table_route_id;
10545            hr_utility.set_location('After plsql table ',222);
10546            --
10547            -- 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 ) ;
10548            --
10549            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
10550            --
10551          else
10552            --
10553            -- Call Update routine for the pk_id created in prev run .
10554            --UPD START
10555            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
10556            --
10557            if l_update then
10558              --
10559              l_datetrack_mode := r_CQR.datetrack_mode ;
10560              --
10561              get_dt_modes(
10562                p_effective_date        => l_process_date,
10563                p_effective_end_date    => r_CQR.information3,
10564                p_effective_start_date  => r_CQR.information2,
10565                p_dml_operation         => r_CQR.dml_operation,
10566                p_datetrack_mode        => l_datetrack_mode );
10567            --    p_update                => l_update
10568              --
10569              l_effective_date := l_process_date;
10570              l_CBR_QUALD_BNF_RT_ID   := r_CQR.information1;
10571              l_object_version_number := r_CQR.information265;
10572              --
10573            end if;
10574            --
10575            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
10576            --
10577            IF l_update OR l_dml_operation <> 'UPDATE' THEN
10578            --UPD END
10579            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
10580            hr_utility.set_location(' BEN_CBR_QUALD_BNF_RT_F UPDATE_CBR_QUALD_BNF_RT ',30);
10581            BEN_CBR_QUALD_BNF_RT_API.UPDATE_CBR_QUALD_BNF_RT(
10582              --
10583              P_VALIDATE               => false
10584              ,P_EFFECTIVE_DATE        => l_effective_date
10585              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
10586              --
10587              ,P_CBR_QUALD_BNF_RT_ID      => l_cbr_quald_bnf_rt_id
10588              ,P_CQR_ATTRIBUTE1      => r_CQR.INFORMATION111
10589              ,P_CQR_ATTRIBUTE10      => r_CQR.INFORMATION120
10590              ,P_CQR_ATTRIBUTE11      => r_CQR.INFORMATION121
10591              ,P_CQR_ATTRIBUTE12      => r_CQR.INFORMATION122
10592              ,P_CQR_ATTRIBUTE13      => r_CQR.INFORMATION123
10593              ,P_CQR_ATTRIBUTE14      => r_CQR.INFORMATION124
10594              ,P_CQR_ATTRIBUTE15      => r_CQR.INFORMATION125
10595              ,P_CQR_ATTRIBUTE16      => r_CQR.INFORMATION126
10596              ,P_CQR_ATTRIBUTE17      => r_CQR.INFORMATION127
10597              ,P_CQR_ATTRIBUTE18      => r_CQR.INFORMATION128
10598              ,P_CQR_ATTRIBUTE19      => r_CQR.INFORMATION129
10599              ,P_CQR_ATTRIBUTE2      => r_CQR.INFORMATION112
10600              ,P_CQR_ATTRIBUTE20      => r_CQR.INFORMATION130
10601              ,P_CQR_ATTRIBUTE21      => r_CQR.INFORMATION131
10602              ,P_CQR_ATTRIBUTE22      => r_CQR.INFORMATION132
10603              ,P_CQR_ATTRIBUTE23      => r_CQR.INFORMATION133
10604              ,P_CQR_ATTRIBUTE24      => r_CQR.INFORMATION134
10605              ,P_CQR_ATTRIBUTE25      => r_CQR.INFORMATION135
10606              ,P_CQR_ATTRIBUTE26      => r_CQR.INFORMATION136
10607              ,P_CQR_ATTRIBUTE27      => r_CQR.INFORMATION137
10608              ,P_CQR_ATTRIBUTE28      => r_CQR.INFORMATION138
10609              ,P_CQR_ATTRIBUTE29      => r_CQR.INFORMATION139
10610              ,P_CQR_ATTRIBUTE3      => r_CQR.INFORMATION113
10611              ,P_CQR_ATTRIBUTE30      => r_CQR.INFORMATION140
10612              ,P_CQR_ATTRIBUTE4      => r_CQR.INFORMATION114
10613              ,P_CQR_ATTRIBUTE5      => r_CQR.INFORMATION115
10614              ,P_CQR_ATTRIBUTE6      => r_CQR.INFORMATION116
10615              ,P_CQR_ATTRIBUTE7      => r_CQR.INFORMATION117
10616              ,P_CQR_ATTRIBUTE8      => r_CQR.INFORMATION118
10617              ,P_CQR_ATTRIBUTE9      => r_CQR.INFORMATION119
10618              ,P_CQR_ATTRIBUTE_CATEGORY      => r_CQR.INFORMATION110
10619              ,P_ORDR_NUM      => r_CQR.INFORMATION257
10620              ,P_PGM_ID      => l_PGM_ID
10621              ,P_PTIP_ID      => l_PTIP_ID
10622              ,P_QUALD_BNF_FLAG      => r_CQR.INFORMATION11
10623              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
10624              --
10625              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
10626              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
10627              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
10628              ,P_DATETRACK_MODE        => l_datetrack_mode
10629            );
10630            --
10631            end if;
10632          end if;
10633          --
10634          -- Delete the row if it is end dated.
10635          --
10636          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
10637              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
10638              trunc(l_max_eed) = r_CQR.information3) then
10639              --
10640              BEN_CBR_QUALD_BNF_RT_API.delete_CBR_QUALD_BNF_RT(
10641                 --
10642                 p_validate                       => false
10643                 ,p_cbr_quald_bnf_rt_id                   => l_cbr_quald_bnf_rt_id
10644                 ,p_effective_start_date           => l_effective_start_date
10645                 ,p_effective_end_date             => l_effective_end_date
10646                 ,p_object_version_number          => l_object_version_number
10647                 ,p_effective_date                 => l_max_eed
10648                 ,p_datetrack_mode                 => hr_api.g_delete
10649                 --
10650                 );
10651                 --
10652          end if;
10653          --
10654          l_prev_pk_id := l_current_pk_id ;
10655          --
10656        end if;
10657        --
10658      end if;
10659      --
10660    end loop;
10661    --
10662  exception when others then
10663     --
10664     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'CQR',r_cqr.information5 );
10665     --
10666  end create_CQR_rows;
10667 
10668    ---------------------------------------------------------------
10669    ----------------------< create_BRG_rows >-----------------------
10670    ---------------------------------------------------------------
10671    --
10672    procedure create_BRG_rows
10673    (
10674          p_validate                       in  number     default 0
10675         ,p_copy_entity_txn_id             in  number
10676         ,p_effective_date                 in  date
10677         ,p_prefix_suffix_text             in  varchar2  default null
10678         ,p_reuse_object_flag              in  varchar2  default null
10679         ,p_target_business_group_id       in  varchar2  default null
10680         ,p_prefix_suffix_cd               in  varchar2  default null
10681    ) is
10682    --
10683    l_BENFTS_GRP_ID  number;
10684    l_VRBL_RT_PRFL_ID  number;
10685    cursor c_unique_BRG(l_table_alias varchar2) is
10686    select distinct cpe.information1,
10687      cpe.information2,
10688      cpe.information3,
10689      cpe.table_route_id
10690    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
10691         pqh_table_route tr
10692    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
10693    and   cpe.table_route_id     = tr.table_route_id
10694    -- and   tr.where_clause        = l_BEN_BENFTS_GRP_RT_F
10695    and tr.table_alias = l_table_alias
10696    and   cpe.number_of_copies   = 1 -- ADDITION
10697    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
10698    order by information1, information2; --added for bug: 5151945
10699    --
10700    --
10701    cursor c_BRG_min_max_dates(c_table_route_id  number,
10702                 c_information1   number) is
10703    select
10704      min(cpe.information2) min_esd,
10705      max(cpe.information3) min_eed
10706    from ben_copy_entity_results cpe
10707    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
10708    and   cpe.table_route_id     = c_table_route_id
10709    and   cpe.information1       = c_information1 ;
10710    --
10711    cursor c_BRG(c_table_route_id  number,
10712                 c_information1   number,
10713                 c_information2   Date,
10714                 c_information3   Date)  is
10715    select
10716      cpe.*
10717    from ben_copy_entity_results cpe
10718    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
10719    and   cpe.table_route_id     = c_table_route_id
10720    and   cpe.information1       = c_information1
10721    and   cpe.information2       = c_information2
10722    and   cpe.information3       = c_information3
10723    and rownum = 1 ;
10724    -- Date Track target record
10725    cursor c_find_BRG_in_target(
10726                                 c_effective_start_date    date,
10727                                 c_effective_end_date      date,
10728                                 c_business_group_id       number,
10729                                 c_new_pk_id               number) is
10730    select
10731      BRG.benfts_grp_rt_id new_value
10732    from BEN_BENFTS_GRP_RT_F BRG
10733    where
10734    BRG.BENFTS_GRP_ID     = l_BENFTS_GRP_ID  and
10735    BRG.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
10736    BRG.business_group_id  = c_business_group_id
10737    and   BRG.benfts_grp_rt_id  <> c_new_pk_id
10738 --TEMPIK
10739    and c_effective_start_date between effective_start_date
10740                             and effective_end_date ;
10741 --END TEMPIK
10742 /*TEMPIK
10743    and exists ( select null
10744                 from BEN_BENFTS_GRP_RT_F BRG1
10745                 where
10746                 BRG1.BENFTS_GRP_ID     = l_BENFTS_GRP_ID  and
10747                 BRG1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
10748                 BRG1.business_group_id  = c_business_group_id
10749                 and   BRG1.effective_start_date <= c_effective_start_date )
10750    and exists ( select null
10751                 from BEN_BENFTS_GRP_RT_F BRG2
10752                 where
10753                 BRG2.BENFTS_GRP_ID     = l_BENFTS_GRP_ID  and
10754                 BRG2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
10755                 BRG2.business_group_id  = c_business_group_id
10756                 and   BRG2.effective_end_date >= c_effective_end_date )
10757                 ;
10758 TEMPIK */
10759    --TEMPIK
10760    l_dt_rec_found            boolean ;
10761    --END TEMPIK
10762    --
10763    l_current_pk_id           number := null ;
10764    --UPD START
10765    --
10766    l_update                  boolean      := false ;
10767    l_datetrack_mode          varchar2(80) := hr_api.g_update;
10768    l_process_date            date;
10769    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
10770    --
10771    --UPD END
10772    l_prev_pk_id              number := null ;
10773    l_first_rec               boolean := true ;
10774    r_BRG                     c_BRG%rowtype;
10775    l_benfts_grp_rt_id             number ;
10776    l_object_version_number   number ;
10777    l_effective_start_date    date ;
10778    l_effective_end_date      date ;
10779    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
10780    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
10781    l_new_value               number(15);
10782    l_object_found_in_target  boolean := false ;
10783    l_min_esd                 date;
10784    l_max_eed                 date;
10785    l_effective_date          date;
10786    --
10787  begin
10788    -- Initialization
10789    l_object_found_in_target := false ;
10790    -- End Initialization
10791    -- Derive the prefix - sufix
10792    if   p_prefix_suffix_cd = 'PREFIX' then
10793      l_prefix  := p_prefix_suffix_text ;
10794    elsif p_prefix_suffix_cd = 'SUFFIX' then
10795      l_suffix   := p_prefix_suffix_text ;
10796    else
10797      l_prefix := null ;
10798      l_suffix  := null ;
10799    end if ;
10800    -- End Prefix Sufix derivation
10801    for r_BRG_unique in c_unique_BRG('BRG') loop
10802 
10803      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
10804         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
10805          r_BRG_unique.information3 >=
10806                  ben_pd_copy_to_ben_one.g_copy_effective_date)
10807         ) then
10808        --
10809        hr_utility.set_location(' r_BRG_unique.table_route_id '||r_BRG_unique.table_route_id,10);
10810        hr_utility.set_location(' r_BRG_unique.information1 '||r_BRG_unique.information1,10);
10811        hr_utility.set_location( 'r_BRG_unique.information2 '||r_BRG_unique.information2,10);
10812        hr_utility.set_location( 'r_BRG_unique.information3 '||r_BRG_unique.information3,10);
10813        -- If reuse objects flag is 'Y' then check for the object in the target business group
10814        -- if found insert the record into PLSql table and exit the loop else try create the
10815        -- object in the target business group
10816        --
10817        l_object_found_in_target := false ;
10818        l_min_esd := null ;
10819        l_max_eed := null ;
10820        open c_BRG_min_max_dates(r_BRG_unique.table_route_id, r_BRG_unique.information1 ) ;
10821        fetch c_BRG_min_max_dates into l_min_esd,l_max_eed ;
10822        --
10823 
10824        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
10825             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
10826          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
10827        end if;
10828        l_min_esd := greatest(l_min_esd,r_BRG_unique.information2);
10829        open c_BRG(r_BRG_unique.table_route_id,
10830                 r_BRG_unique.information1,
10831                 r_BRG_unique.information2,
10832                 r_BRG_unique.information3 ) ;
10833        --
10834        fetch c_BRG into r_BRG ;
10835        --
10836        close c_BRG ;
10837        --
10838        l_BENFTS_GRP_ID := get_fk('BENFTS_GRP_ID', r_BRG.information222,r_BRG_unique.dml_operation);
10839        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_BRG.information262,r_BRG_unique.dml_operation);
10840        --UPD START
10841        l_update := false;
10842        l_process_date := p_effective_date;
10843        l_dml_operation:= r_BRG_unique.dml_operation ;
10844        --
10845        if l_dml_operation = 'UPDATE' then
10846          --
10847          l_object_found_in_target := TRUE;
10848          --
10849          if l_process_date between r_BRG_unique.information2 and r_BRG_unique.information3 then
10850                l_update := true;
10851                if r_BRG_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
10852                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'BENFTS_GRP_RT_ID'
10853                then
10854                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'BENFTS_GRP_RT_ID' ;
10855                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_BRG_unique.information1 ;
10856                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_BRG_unique.information1 ;
10857                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
10858                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_BRG_unique.table_route_id;
10859                   --
10860                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
10861                   --
10862                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
10863                   --
10864                   -- log_data('BRG',l_new_value,l_prefix || r_BRG_unique.name|| l_suffix,'REUSED');
10865                   --
10866                end if ;
10867                hr_utility.set_location( 'found record for update',10);
10868            --
10869          else
10870            --
10871            l_update := false;
10872            --
10873          end if;
10874        else
10875          --
10876          --UPD END
10877        if p_reuse_object_flag = 'Y' then
10878          if c_BRG_min_max_dates%found then
10879            -- cursor to find the object
10880            open c_find_BRG_in_target( l_min_esd,l_max_eed,
10881                                  p_target_business_group_id, nvl(l_benfts_grp_rt_id, -999)  ) ;
10882            fetch c_find_BRG_in_target into l_new_value ;
10883            if c_find_BRG_in_target%found then
10884              --
10885 
10886              --TEMPIK
10887              l_dt_rec_found :=   dt_api.check_min_max_dates
10888                  (p_base_table_name => 'BEN_BENFTS_GRP_RT_F',
10889                   p_base_key_column => 'BENFTS_GRP_RT_ID',
10890                   p_base_key_value  => l_new_value,
10891                   p_from_date       => l_min_esd,
10892                   p_to_date         => l_max_eed );
10893              if l_dt_rec_found THEN
10894              --END TEMPIK
10895              if r_BRG_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
10896                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'BENFTS_GRP_RT_ID'  then
10897                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'BENFTS_GRP_RT_ID' ;
10898                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_BRG_unique.information1 ;
10899                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
10900                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
10901                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_BRG_unique.table_route_id;
10902                 --
10903                 -- 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) ;
10904                 --
10905                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
10906              end if ;
10907              --
10908              l_object_found_in_target := true ;
10909              --TEMPIK
10910              end if; -- l_dt_rec_found
10911              --END TEMPIK
10912            end if;
10913            close c_find_BRG_in_target ;
10914          --
10915          end if;
10916        end if ;
10917        --
10918        end if;
10919        close c_BRG_min_max_dates ;
10920        if not l_object_found_in_target OR l_update   then
10921          --
10922          l_current_pk_id := r_BRG.information1;
10923          --
10924          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
10925          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
10926          --
10927          if l_current_pk_id =  l_prev_pk_id  then
10928            --
10929            l_first_rec := false ;
10930            --
10931          else
10932            --
10933            l_first_rec := true ;
10934            --
10935          end if ;
10936          --
10937 
10938          l_effective_date := r_BRG.information2;
10939          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
10940               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
10941            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
10942          end if;
10943 
10944          if l_first_rec and not l_update then
10945            -- Call Create routine.
10946            hr_utility.set_location(' BEN_BENFTS_GRP_RT_F CREATE_BENEFIT_GRP_RATE ',20);
10947            BEN_BENEFIT_GRP_RATE_API.CREATE_BENEFIT_GRP_RATE(
10948              --
10949              P_VALIDATE               => false
10950              ,P_EFFECTIVE_DATE        => l_effective_date
10951              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
10952              --
10953              ,P_BENFTS_GRP_ID      => l_BENFTS_GRP_ID
10954              ,P_BENFTS_GRP_RT_ID      => l_benfts_grp_rt_id
10955              ,P_BRG_ATTRIBUTE1      => r_BRG.INFORMATION111
10956              ,P_BRG_ATTRIBUTE10      => r_BRG.INFORMATION120
10957              ,P_BRG_ATTRIBUTE11      => r_BRG.INFORMATION121
10958              ,P_BRG_ATTRIBUTE12      => r_BRG.INFORMATION122
10959              ,P_BRG_ATTRIBUTE13      => r_BRG.INFORMATION123
10960              ,P_BRG_ATTRIBUTE14      => r_BRG.INFORMATION124
10961              ,P_BRG_ATTRIBUTE15      => r_BRG.INFORMATION125
10962              ,P_BRG_ATTRIBUTE16      => r_BRG.INFORMATION126
10963              ,P_BRG_ATTRIBUTE17      => r_BRG.INFORMATION127
10964              ,P_BRG_ATTRIBUTE18      => r_BRG.INFORMATION128
10965              ,P_BRG_ATTRIBUTE19      => r_BRG.INFORMATION129
10966              ,P_BRG_ATTRIBUTE2      => r_BRG.INFORMATION112
10967              ,P_BRG_ATTRIBUTE20      => r_BRG.INFORMATION130
10968              ,P_BRG_ATTRIBUTE21      => r_BRG.INFORMATION131
10969              ,P_BRG_ATTRIBUTE22      => r_BRG.INFORMATION132
10970              ,P_BRG_ATTRIBUTE23      => r_BRG.INFORMATION133
10971              ,P_BRG_ATTRIBUTE24      => r_BRG.INFORMATION134
10972              ,P_BRG_ATTRIBUTE25      => r_BRG.INFORMATION135
10973              ,P_BRG_ATTRIBUTE26      => r_BRG.INFORMATION136
10974              ,P_BRG_ATTRIBUTE27      => r_BRG.INFORMATION137
10975              ,P_BRG_ATTRIBUTE28      => r_BRG.INFORMATION138
10976              ,P_BRG_ATTRIBUTE29      => r_BRG.INFORMATION139
10977              ,P_BRG_ATTRIBUTE3      => r_BRG.INFORMATION113
10978              ,P_BRG_ATTRIBUTE30      => r_BRG.INFORMATION140
10979              ,P_BRG_ATTRIBUTE4      => r_BRG.INFORMATION114
10980              ,P_BRG_ATTRIBUTE5      => r_BRG.INFORMATION115
10981              ,P_BRG_ATTRIBUTE6      => r_BRG.INFORMATION116
10982              ,P_BRG_ATTRIBUTE7      => r_BRG.INFORMATION117
10983              ,P_BRG_ATTRIBUTE8      => r_BRG.INFORMATION118
10984              ,P_BRG_ATTRIBUTE9      => r_BRG.INFORMATION119
10985              ,P_BRG_ATTRIBUTE_CATEGORY      => r_BRG.INFORMATION110
10986              ,P_EXCLD_FLAG      => r_BRG.INFORMATION11
10987              ,P_ORDR_NUM      => r_BRG.INFORMATION257
10988              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
10989              --
10990              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
10991              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
10992              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
10993            );
10994            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
10995            -- Update all relevent cer records with new pk_id
10996            hr_utility.set_location('Before plsql table ',222);
10997            hr_utility.set_location('new_value id '||l_benfts_grp_rt_id,222);
10998            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'BENFTS_GRP_RT_ID' ;
10999            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_BRG.information1 ;
11000            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_BENFTS_GRP_RT_ID ;
11001            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
11002            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_BRG_unique.table_route_id;
11003            hr_utility.set_location('After plsql table ',222);
11004            --
11005            -- 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 ) ;
11006            --
11007            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
11008            --
11009          else
11010            --
11011            -- Call Update routine for the pk_id created in prev run .
11012            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
11013            --UPD START
11014            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
11015            --
11016            if l_update then
11017              --
11018              l_datetrack_mode := r_BRG.datetrack_mode ;
11019              --
11020              get_dt_modes(
11021                p_effective_date        => l_process_date,
11022                p_effective_end_date    => r_BRG.information3,
11023                p_effective_start_date  => r_BRG.information2,
11024                p_dml_operation         => r_BRG.dml_operation,
11025                p_datetrack_mode        => l_datetrack_mode );
11026            --    p_update                => l_update
11027              --
11028              l_effective_date := l_process_date;
11029              l_BENFTS_GRP_RT_ID   := r_BRG.information1;
11030              l_object_version_number := r_BRG.information265;
11031              --
11032            end if;
11033            --
11034            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
11035            --
11036            IF l_update OR l_dml_operation <> 'UPDATE' THEN
11037            --UPD END
11038            hr_utility.set_location(' BEN_BENFTS_GRP_RT_F UPDATE_BENEFIT_GRP_RATE ',30);
11039            BEN_BENEFIT_GRP_RATE_API.UPDATE_BENEFIT_GRP_RATE(
11040              --
11041              P_VALIDATE               => false
11042              ,P_EFFECTIVE_DATE        => l_effective_date
11043              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
11044              --
11045              ,P_BENFTS_GRP_ID      => l_BENFTS_GRP_ID
11046              ,P_BENFTS_GRP_RT_ID      => l_benfts_grp_rt_id
11047              ,P_BRG_ATTRIBUTE1      => r_BRG.INFORMATION111
11048              ,P_BRG_ATTRIBUTE10      => r_BRG.INFORMATION120
11049              ,P_BRG_ATTRIBUTE11      => r_BRG.INFORMATION121
11050              ,P_BRG_ATTRIBUTE12      => r_BRG.INFORMATION122
11051              ,P_BRG_ATTRIBUTE13      => r_BRG.INFORMATION123
11052              ,P_BRG_ATTRIBUTE14      => r_BRG.INFORMATION124
11053              ,P_BRG_ATTRIBUTE15      => r_BRG.INFORMATION125
11054              ,P_BRG_ATTRIBUTE16      => r_BRG.INFORMATION126
11055              ,P_BRG_ATTRIBUTE17      => r_BRG.INFORMATION127
11056              ,P_BRG_ATTRIBUTE18      => r_BRG.INFORMATION128
11057              ,P_BRG_ATTRIBUTE19      => r_BRG.INFORMATION129
11058              ,P_BRG_ATTRIBUTE2      => r_BRG.INFORMATION112
11059              ,P_BRG_ATTRIBUTE20      => r_BRG.INFORMATION130
11060              ,P_BRG_ATTRIBUTE21      => r_BRG.INFORMATION131
11061              ,P_BRG_ATTRIBUTE22      => r_BRG.INFORMATION132
11062              ,P_BRG_ATTRIBUTE23      => r_BRG.INFORMATION133
11063              ,P_BRG_ATTRIBUTE24      => r_BRG.INFORMATION134
11064              ,P_BRG_ATTRIBUTE25      => r_BRG.INFORMATION135
11065              ,P_BRG_ATTRIBUTE26      => r_BRG.INFORMATION136
11066              ,P_BRG_ATTRIBUTE27      => r_BRG.INFORMATION137
11067              ,P_BRG_ATTRIBUTE28      => r_BRG.INFORMATION138
11068              ,P_BRG_ATTRIBUTE29      => r_BRG.INFORMATION139
11069              ,P_BRG_ATTRIBUTE3      => r_BRG.INFORMATION113
11070              ,P_BRG_ATTRIBUTE30      => r_BRG.INFORMATION140
11071              ,P_BRG_ATTRIBUTE4      => r_BRG.INFORMATION114
11072              ,P_BRG_ATTRIBUTE5      => r_BRG.INFORMATION115
11073              ,P_BRG_ATTRIBUTE6      => r_BRG.INFORMATION116
11074              ,P_BRG_ATTRIBUTE7      => r_BRG.INFORMATION117
11075              ,P_BRG_ATTRIBUTE8      => r_BRG.INFORMATION118
11076              ,P_BRG_ATTRIBUTE9      => r_BRG.INFORMATION119
11077              ,P_BRG_ATTRIBUTE_CATEGORY      => r_BRG.INFORMATION110
11078              ,P_EXCLD_FLAG      => r_BRG.INFORMATION11
11079              ,P_ORDR_NUM      => r_BRG.INFORMATION257
11080              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
11081              --
11082              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
11083              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
11084              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
11085              ,P_DATETRACK_MODE        => l_datetrack_mode
11086            );
11087            --
11088            end if;
11089          end if;
11090          --
11091          -- Delete the row if it is end dated.
11092          --
11093          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
11094              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
11095              trunc(l_max_eed) = r_BRG.information3) then
11096              --
11097              BEN_BENEFIT_GRP_RATE_API.delete_BENEFIT_GRP_RATE(
11098                 --
11099                 p_validate                       => false
11100                 ,p_benfts_grp_rt_id                   => l_benfts_grp_rt_id
11101                 ,p_effective_start_date           => l_effective_start_date
11102                 ,p_effective_end_date             => l_effective_end_date
11103                 ,p_object_version_number          => l_object_version_number
11104                 ,p_effective_date                 => l_max_eed
11105                 ,p_datetrack_mode                 => hr_api.g_delete
11106                 --
11107                 );
11108                 --
11109          end if;
11110          --
11111          l_prev_pk_id := l_current_pk_id ;
11112          --
11113        end if;
11114        --
11115      end if;
11116      --
11117    end loop;
11118    --
11119  exception when others then
11120     --
11121     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'BRG',r_brg.information5 );
11122     --
11123  end create_BRG_rows;
11124 
11125    ---------------------------------------------------------------
11126    ----------------------< create_CMR_rows >-----------------------
11127    ---------------------------------------------------------------
11128    --
11129    procedure create_CMR_rows
11130    (
11131          p_validate                       in  number     default 0
11132         ,p_copy_entity_txn_id             in  number
11133         ,p_effective_date                 in  date
11134         ,p_prefix_suffix_text             in  varchar2  default null
11135         ,p_reuse_object_flag              in  varchar2  default null
11136         ,p_target_business_group_id       in  varchar2  default null
11137         ,p_prefix_suffix_cd               in  varchar2  default null
11138    ) is
11139    --
11140    l_CMBN_AGE_LOS_FCTR_ID  number;
11141    l_VRBL_RT_PRFL_ID  number;
11142    cursor c_unique_CMR(l_table_alias varchar2) is
11143    select distinct cpe.information1,
11144      cpe.information2,
11145      cpe.information3,
11146      cpe.table_route_id
11147    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
11148         pqh_table_route tr
11149    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
11150    and   cpe.table_route_id     = tr.table_route_id
11151    -- and   tr.where_clause        = l_BEN_CMBN_AGE_LOS_RT_F
11152    and tr.table_alias = l_table_alias
11153    and   cpe.number_of_copies   = 1 -- ADDITION
11154    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
11155    order by information1, information2; --added for bug: 5151945
11156    --
11157    --
11158    cursor c_CMR_min_max_dates(c_table_route_id  number,
11159                 c_information1   Number) is
11160    select
11161      min(cpe.information2) min_esd,
11162      max(cpe.information3) min_eed
11163    from ben_copy_entity_results cpe
11164    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
11165    and   cpe.table_route_id     = c_table_route_id
11166    and   cpe.information1       = c_information1 ;
11167    --
11168    cursor c_CMR(c_table_route_id  number,
11169                 c_information1   number,
11170                 c_information2   Date,
11171                 c_information3   Date)  is
11172    select
11173      cpe.*
11174    from ben_copy_entity_results cpe
11175    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
11176    and   cpe.table_route_id     = c_table_route_id
11177    and   cpe.information1       = c_information1
11178    and   cpe.information2       = c_information2
11179    and   cpe.information3       = c_information3
11180    and rownum = 1 ;
11181    -- Date Track target record
11182    cursor c_find_CMR_in_target(
11183                                 c_effective_start_date    date,
11184                                 c_effective_end_date      date,
11185                                 c_business_group_id       number,
11186                                 c_new_pk_id               number) is
11187    select
11188      CMR.cmbn_age_los_rt_id new_value
11189    from BEN_CMBN_AGE_LOS_RT_F CMR
11190    where
11191    CMR.CMBN_AGE_LOS_FCTR_ID     = l_CMBN_AGE_LOS_FCTR_ID  and
11192    CMR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
11193    CMR.business_group_id  = c_business_group_id
11194    and   CMR.cmbn_age_los_rt_id  <> c_new_pk_id
11195 --TEMPIK
11196    and c_effective_start_date between effective_start_date
11197                             and effective_end_date ;
11198 --END TEMPIK
11199 /*TEMPIK
11200    and exists ( select null
11201                 from BEN_CMBN_AGE_LOS_RT_F CMR1
11202                 where
11203                 CMR1.CMBN_AGE_LOS_FCTR_ID    = l_CMBN_AGE_LOS_FCTR_ID  and
11204                 CMR1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
11205                 CMR1.business_group_id  = c_business_group_id
11206                 and   CMR1.effective_start_date <= c_effective_start_date )
11207    and exists ( select null
11208                 from BEN_CMBN_AGE_LOS_RT_F CMR2
11209                 where
11210                 CMR2.CMBN_AGE_LOS_FCTR_ID     = l_CMBN_AGE_LOS_FCTR_ID  and
11211                 CMR2.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
11212                 CMR2.business_group_id  = c_business_group_id
11213                 and   CMR2.effective_end_date >= c_effective_end_date )
11214                 ;
11215 TEMPIK */
11216    --TEMPIK
11217    l_dt_rec_found            boolean ;
11218    --END TEMPIK
11219    --
11220    l_current_pk_id           number := null ;
11221    --UPD START
11222    --
11223    l_update                  boolean      := false ;
11224    l_datetrack_mode          varchar2(80) := hr_api.g_update;
11225    l_process_date            date;
11226    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
11227    --
11228    --UPD END
11229    l_prev_pk_id              number := null ;
11230    l_first_rec               boolean := true ;
11231    r_CMR                     c_CMR%rowtype;
11232    l_cmbn_age_los_rt_id             number ;
11233    l_object_version_number   number ;
11234    l_effective_start_date    date ;
11235    l_effective_end_date      date ;
11236    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
11237    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
11238    l_new_value               number(15);
11239    l_object_found_in_target  boolean := false ;
11240    l_min_esd                 date;
11241    l_max_eed                 date;
11242    l_effective_date          date;
11243    --
11244  begin
11245    -- Initialization
11246    l_object_found_in_target := false ;
11247    -- End Initialization
11248    -- Derive the prefix - sufix
11249    if   p_prefix_suffix_cd = 'PREFIX' then
11250      l_prefix  := p_prefix_suffix_text ;
11251    elsif p_prefix_suffix_cd = 'SUFFIX' then
11252      l_suffix   := p_prefix_suffix_text ;
11253    else
11254      l_prefix := null ;
11255      l_suffix  := null ;
11256    end if ;
11257    -- End Prefix Sufix derivation
11258    for r_CMR_unique in c_unique_CMR('CMR') loop
11259 
11260      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
11261         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
11262          r_CMR_unique.information3 >=
11263                  ben_pd_copy_to_ben_one.g_copy_effective_date)
11264         ) then
11265        --
11266        hr_utility.set_location(' r_CMR_unique.table_route_id '||r_CMR_unique.table_route_id,10);
11267        hr_utility.set_location(' r_CMR_unique.information1 '||r_CMR_unique.information1,10);
11268        hr_utility.set_location( 'r_CMR_unique.information2 '||r_CMR_unique.information2,10);
11269        hr_utility.set_location( 'r_CMR_unique.information3 '||r_CMR_unique.information3,10);
11270        -- If reuse objects flag is 'Y' then check for the object in the target business group
11271        -- if found insert the record into PLSql table and exit the loop else try create the
11272        -- object in the target business group
11273        --
11274        l_object_found_in_target := false ;
11275        l_min_esd := null ;
11276        l_max_eed := null ;
11277        open c_CMR_min_max_dates(r_CMR_unique.table_route_id, r_CMR_unique.information1 ) ;
11278        fetch c_CMR_min_max_dates into l_min_esd,l_max_eed ;
11279        --
11280 
11281        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
11282             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
11283          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
11284        end if;
11285        l_min_esd := greatest(l_min_esd,r_CMR_unique.information2);
11286        open c_CMR(r_CMR_unique.table_route_id,
11287                 r_CMR_unique.information1,
11288                 r_CMR_unique.information2,
11289                 r_CMR_unique.information3 ) ;
11290        --
11291        fetch c_CMR into r_CMR ;
11292        --
11293        close c_CMR ;
11294        --
11295        l_CMBN_AGE_LOS_FCTR_ID := get_fk('CMBN_AGE_LOS_FCTR_ID', r_CMR.information223,r_CMR_unique.dml_operation);
11296        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_CMR.information262,r_CMR_unique.dml_operation);
11297        --UPD START
11298        l_update := false;
11299        l_process_date := p_effective_date;
11300        l_dml_operation:= r_CMR_unique.dml_operation ;
11301        --
11302        if l_dml_operation = 'UPDATE' then
11303          --
11304          l_object_found_in_target := TRUE;
11305          --
11306          if l_process_date between r_CMR_unique.information2 and r_CMR_unique.information3 then
11307                l_update := true;
11308                if r_CMR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
11309                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'CMBN_AGE_LOS_RT_ID'
11310                then
11311                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'CMBN_AGE_LOS_RT_ID' ;
11312                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_CMR_unique.information1 ;
11313                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_CMR_unique.information1 ;
11314                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
11315                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_CMR_unique.table_route_id;
11316                   --
11317                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
11318                   --
11319                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
11320                   --
11321                   -- log_data('CMR',l_new_value,l_prefix || r_CMR_unique.name|| l_suffix,'REUSED');
11322                   --
11323                end if ;
11324                hr_utility.set_location( 'found record for update',10);
11325            --
11326          else
11327            --
11328            l_update := false;
11329            --
11330          end if;
11331        else
11332          --
11333          --UPD END
11334        if p_reuse_object_flag = 'Y' then
11335          if c_CMR_min_max_dates%found then
11336            -- cursor to find the object
11337            open c_find_CMR_in_target( l_min_esd,l_max_eed,
11338                                  p_target_business_group_id, nvl(l_cmbn_age_los_rt_id, -999)  ) ;
11339            fetch c_find_CMR_in_target into l_new_value ;
11340            if c_find_CMR_in_target%found then
11341              --
11342              --TEMPIK
11343              l_dt_rec_found :=   dt_api.check_min_max_dates
11344                  (p_base_table_name => 'BEN_CMBN_AGE_LOS_RT_F',
11345                   p_base_key_column => 'CMBN_AGE_LOS_RT_ID',
11346                   p_base_key_value  => l_new_value,
11347                   p_from_date       => l_min_esd,
11348                   p_to_date         => l_max_eed );
11349              if l_dt_rec_found THEN
11350              --END TEMPIK
11351              if r_CMR_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
11352                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'CMBN_AGE_LOS_RT_ID'  then
11353                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'CMBN_AGE_LOS_RT_ID' ;
11354                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_CMR_unique.information1 ;
11355                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
11356                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
11357                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_CMR_unique.table_route_id;
11358                 --
11359                 -- 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) ;
11360                 --
11361                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
11362              end if ;
11363              --
11364              l_object_found_in_target := true ;
11365              --TEMPIK
11366              end if; -- l_dt_rec_found
11367              --END TEMPIK
11368            end if;
11369            close c_find_CMR_in_target ;
11370          --
11371          end if;
11372        end if ;
11373        --
11374        end if;
11375        close c_CMR_min_max_dates ;
11376        if not l_object_found_in_target OR l_update   then
11377          --
11378          l_current_pk_id := r_CMR.information1;
11379          --
11380          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
11381          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
11382          --
11383          if l_current_pk_id =  l_prev_pk_id  then
11384            --
11385            l_first_rec := false ;
11386            --
11387          else
11388            --
11389            l_first_rec := true ;
11390            --
11391          end if ;
11392          --
11393 
11394          l_effective_date := r_CMR.information2;
11395          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
11396               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
11397            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
11398          end if;
11399 
11400          if l_first_rec and not l_update then
11401            -- Call Create routine.
11402            hr_utility.set_location(' BEN_CMBN_AGE_LOS_RT_F CREATE_CMBN_AGE_LOS_RT ',20);
11403            BEN_CMBN_AGE_LOS_RT_API.CREATE_CMBN_AGE_LOS_RT(
11404              --
11405              P_VALIDATE               => false
11406              ,P_EFFECTIVE_DATE        => l_effective_date
11407              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
11408              --
11409              ,P_CMBN_AGE_LOS_FCTR_ID      => l_CMBN_AGE_LOS_FCTR_ID
11410              ,P_CMBN_AGE_LOS_RT_ID      => l_cmbn_age_los_rt_id
11411              ,P_CMR_ATTRIBUTE1      => r_CMR.INFORMATION111
11412              ,P_CMR_ATTRIBUTE10      => r_CMR.INFORMATION120
11413              ,P_CMR_ATTRIBUTE11      => r_CMR.INFORMATION121
11414              ,P_CMR_ATTRIBUTE12      => r_CMR.INFORMATION122
11415              ,P_CMR_ATTRIBUTE13      => r_CMR.INFORMATION123
11416              ,P_CMR_ATTRIBUTE14      => r_CMR.INFORMATION124
11417              ,P_CMR_ATTRIBUTE15      => r_CMR.INFORMATION125
11418              ,P_CMR_ATTRIBUTE16      => r_CMR.INFORMATION126
11419              ,P_CMR_ATTRIBUTE17      => r_CMR.INFORMATION127
11420              ,P_CMR_ATTRIBUTE18      => r_CMR.INFORMATION128
11421              ,P_CMR_ATTRIBUTE19      => r_CMR.INFORMATION129
11422              ,P_CMR_ATTRIBUTE2      => r_CMR.INFORMATION112
11423              ,P_CMR_ATTRIBUTE20      => r_CMR.INFORMATION130
11424              ,P_CMR_ATTRIBUTE21      => r_CMR.INFORMATION131
11425              ,P_CMR_ATTRIBUTE22      => r_CMR.INFORMATION132
11426              ,P_CMR_ATTRIBUTE23      => r_CMR.INFORMATION133
11427              ,P_CMR_ATTRIBUTE24      => r_CMR.INFORMATION134
11428              ,P_CMR_ATTRIBUTE25      => r_CMR.INFORMATION135
11429              ,P_CMR_ATTRIBUTE26      => r_CMR.INFORMATION136
11430              ,P_CMR_ATTRIBUTE27      => r_CMR.INFORMATION137
11431              ,P_CMR_ATTRIBUTE28      => r_CMR.INFORMATION138
11432              ,P_CMR_ATTRIBUTE29      => r_CMR.INFORMATION139
11433              ,P_CMR_ATTRIBUTE3      => r_CMR.INFORMATION113
11434              ,P_CMR_ATTRIBUTE30      => r_CMR.INFORMATION140
11435              ,P_CMR_ATTRIBUTE4      => r_CMR.INFORMATION114
11436              ,P_CMR_ATTRIBUTE5      => r_CMR.INFORMATION115
11437              ,P_CMR_ATTRIBUTE6      => r_CMR.INFORMATION116
11438              ,P_CMR_ATTRIBUTE7      => r_CMR.INFORMATION117
11439              ,P_CMR_ATTRIBUTE8      => r_CMR.INFORMATION118
11440              ,P_CMR_ATTRIBUTE9      => r_CMR.INFORMATION119
11441              ,P_CMR_ATTRIBUTE_CATEGORY      => r_CMR.INFORMATION110
11442              ,P_EXCLD_FLAG      => r_CMR.INFORMATION11
11443              ,P_ORDR_NUM      => r_CMR.INFORMATION257
11444              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
11445              --
11446              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
11447              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
11448              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
11449            );
11450            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
11451            -- Update all relevent cer records with new pk_id
11452            hr_utility.set_location('Before plsql table ',222);
11453            hr_utility.set_location('new_value id '||l_cmbn_age_los_rt_id,222);
11454            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'CMBN_AGE_LOS_RT_ID' ;
11455            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_CMR.information1 ;
11456            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_CMBN_AGE_LOS_RT_ID ;
11457            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
11458            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_CMR_unique.table_route_id;
11459            hr_utility.set_location('After plsql table ',222);
11460            --
11461            -- 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 ) ;
11462            --
11463            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
11464            --
11465          else
11466            --
11467            -- Call Update routine for the pk_id created in prev run .
11468            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
11469            --UPD START
11470            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
11471            --
11472            if l_update then
11473              --
11474              l_datetrack_mode := r_CMR.datetrack_mode ;
11475              --
11476              get_dt_modes(
11477                p_effective_date        => l_process_date,
11478                p_effective_end_date    => r_CMR.information3,
11479                p_effective_start_date  => r_CMR.information2,
11480                p_dml_operation         => r_CMR.dml_operation,
11481                p_datetrack_mode        => l_datetrack_mode );
11482            --    p_update                => l_update
11483              --
11484              l_effective_date := l_process_date;
11485              l_CMBN_AGE_LOS_RT_ID   := r_CMR.information1;
11486              l_object_version_number := r_CMR.information265;
11487              --
11488            end if;
11489            --
11490            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
11491            --
11492            IF l_update OR l_dml_operation <> 'UPDATE' THEN
11493            --UPD END
11494            hr_utility.set_location(' BEN_CMBN_AGE_LOS_RT_F UPDATE_CMBN_AGE_LOS_RT ',30);
11495            BEN_CMBN_AGE_LOS_RT_API.UPDATE_CMBN_AGE_LOS_RT(
11496              --
11497              P_VALIDATE               => false
11498              ,P_EFFECTIVE_DATE        => l_effective_date
11499              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
11500              --
11501              ,P_CMBN_AGE_LOS_FCTR_ID      => l_CMBN_AGE_LOS_FCTR_ID
11502              ,P_CMBN_AGE_LOS_RT_ID      => l_cmbn_age_los_rt_id
11503              ,P_CMR_ATTRIBUTE1      => r_CMR.INFORMATION111
11504              ,P_CMR_ATTRIBUTE10      => r_CMR.INFORMATION120
11505              ,P_CMR_ATTRIBUTE11      => r_CMR.INFORMATION121
11506              ,P_CMR_ATTRIBUTE12      => r_CMR.INFORMATION122
11507              ,P_CMR_ATTRIBUTE13      => r_CMR.INFORMATION123
11508              ,P_CMR_ATTRIBUTE14      => r_CMR.INFORMATION124
11509              ,P_CMR_ATTRIBUTE15      => r_CMR.INFORMATION125
11510              ,P_CMR_ATTRIBUTE16      => r_CMR.INFORMATION126
11511              ,P_CMR_ATTRIBUTE17      => r_CMR.INFORMATION127
11512              ,P_CMR_ATTRIBUTE18      => r_CMR.INFORMATION128
11513              ,P_CMR_ATTRIBUTE19      => r_CMR.INFORMATION129
11514              ,P_CMR_ATTRIBUTE2      => r_CMR.INFORMATION112
11515              ,P_CMR_ATTRIBUTE20      => r_CMR.INFORMATION130
11516              ,P_CMR_ATTRIBUTE21      => r_CMR.INFORMATION131
11517              ,P_CMR_ATTRIBUTE22      => r_CMR.INFORMATION132
11518              ,P_CMR_ATTRIBUTE23      => r_CMR.INFORMATION133
11519              ,P_CMR_ATTRIBUTE24      => r_CMR.INFORMATION134
11520              ,P_CMR_ATTRIBUTE25      => r_CMR.INFORMATION135
11521              ,P_CMR_ATTRIBUTE26      => r_CMR.INFORMATION136
11522              ,P_CMR_ATTRIBUTE27      => r_CMR.INFORMATION137
11523              ,P_CMR_ATTRIBUTE28      => r_CMR.INFORMATION138
11524              ,P_CMR_ATTRIBUTE29      => r_CMR.INFORMATION139
11525              ,P_CMR_ATTRIBUTE3      => r_CMR.INFORMATION113
11526              ,P_CMR_ATTRIBUTE30      => r_CMR.INFORMATION140
11527              ,P_CMR_ATTRIBUTE4      => r_CMR.INFORMATION114
11528              ,P_CMR_ATTRIBUTE5      => r_CMR.INFORMATION115
11529              ,P_CMR_ATTRIBUTE6      => r_CMR.INFORMATION116
11530              ,P_CMR_ATTRIBUTE7      => r_CMR.INFORMATION117
11531              ,P_CMR_ATTRIBUTE8      => r_CMR.INFORMATION118
11532              ,P_CMR_ATTRIBUTE9      => r_CMR.INFORMATION119
11533              ,P_CMR_ATTRIBUTE_CATEGORY      => r_CMR.INFORMATION110
11534              ,P_EXCLD_FLAG      => r_CMR.INFORMATION11
11535              ,P_ORDR_NUM      => r_CMR.INFORMATION257
11536              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
11537              --
11538              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
11539              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
11540              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
11541              ,P_DATETRACK_MODE        => l_datetrack_mode
11542            );
11543            --
11544            end if;
11545          end if;
11546          --
11547          -- Delete the row if it is end dated.
11548          --
11549          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
11550              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
11551              trunc(l_max_eed) = r_CMR.information3) then
11552              --
11553              BEN_CMBN_AGE_LOS_RT_API.delete_CMBN_AGE_LOS_RT(
11554                 --
11555                 p_validate                       => false
11556                 ,p_cmbn_age_los_rt_id                   => l_cmbn_age_los_rt_id
11557                 ,p_effective_start_date           => l_effective_start_date
11558                 ,p_effective_end_date             => l_effective_end_date
11559                 ,p_object_version_number          => l_object_version_number
11560                 ,p_effective_date                 => l_max_eed
11561                 ,p_datetrack_mode                 => hr_api.g_delete
11562                 --
11563                 );
11564                 --
11565          end if;
11566          --
11567          l_prev_pk_id := l_current_pk_id ;
11568          --
11569        end if;
11570        --
11571      end if;
11572      --
11573    end loop;
11574    --
11575  exception when others then
11576     --
11577     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'CMR',r_cmr.information5 );
11578     --
11579  end create_CMR_rows;
11580 
11581    --
11582    ---------------------------------------------------------------
11583    ----------------------< create_VMR_rows >-----------------------
11584    ---------------------------------------------------------------
11585    --
11586    procedure create_VMR_rows
11587    (
11588          p_validate                       in  number     default 0
11589         ,p_copy_entity_txn_id             in  number
11590         ,p_effective_date                 in  date
11591         ,p_prefix_suffix_text             in  varchar2  default null
11592         ,p_reuse_object_flag              in  varchar2  default null
11593         ,p_target_business_group_id       in  varchar2  default null
11594         ,p_prefix_suffix_cd               in  varchar2  default null
11595    ) is
11596    --
11597    l_MTCHG_RT_CALC_RL  number;
11598    l_VRBL_RT_PRFL_ID  number;
11599    cursor c_unique_VMR(l_table_alias varchar2) is
11600    select distinct cpe.information1,
11601      cpe.information2,
11602      cpe.information3,
11603      cpe.table_route_id
11604    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
11605         pqh_table_route tr
11606    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
11607    and   cpe.table_route_id     = tr.table_route_id
11608    -- and   tr.where_clause        = l_BEN_VRBL_MTCHG_RT_F
11609    and tr.table_alias = l_table_alias
11610    and   cpe.number_of_copies   = 1 -- ADDITION
11611    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
11612    order by information1, information2; --added for bug: 5151945
11613    --
11614    --
11615    cursor c_VMR_min_max_dates(c_table_route_id  number,
11616                 c_information1   Number) is
11617    select
11618      min(cpe.information2) min_esd,
11619      max(cpe.information3) min_eed
11620    from ben_copy_entity_results cpe
11621    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
11622    and   cpe.table_route_id     = c_table_route_id
11623    and   cpe.information1       = c_information1 ;
11624    --
11625    cursor c_VMR(c_table_route_id  number,
11626                 c_information1   number,
11627                 c_information2   Date,
11628                 c_information3   Date)  is
11629    select
11630      cpe.*
11631    from ben_copy_entity_results cpe
11632    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
11633    and   cpe.table_route_id     = c_table_route_id
11634    and   cpe.information1       = c_information1
11635    and   cpe.information2       = c_information2
11636    and   cpe.information3       = c_information3
11637    and rownum = 1 ;
11638    -- Date Track target record
11639    cursor c_find_VMR_in_target(
11640                                 c_effective_start_date    date,
11641                                 c_effective_end_date      date,
11642                                 c_business_group_id       number,
11643                                 c_new_pk_id               number) is
11644    select
11645      VMR.vrbl_mtchg_rt_id new_value
11646    from BEN_VRBL_MTCHG_RT_F VMR
11647    where
11648    VMR.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
11649    nvl(VMR.MTCHG_RT_CALC_RL, -999)   = nvl(l_MTCHG_RT_CALC_RL, -999) and
11650    VMR.business_group_id  = c_business_group_id
11651    and   VMR.vrbl_mtchg_rt_id  <> c_new_pk_id
11652 --TEMPIK
11653    and c_effective_start_date between effective_start_date
11654                             and effective_end_date ;
11655 --END TEMPIK
11656 /*TEMPIK
11657    and exists ( select null
11658                 from BEN_VRBL_MTCHG_RT_F VMR1
11659                 where
11660                 VMR1.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
11661                 nvl(VMR1.MTCHG_RT_CALC_RL, -999)   = nvl(l_MTCHG_RT_CALC_RL, -999) and
11662                 VMR1.business_group_id  = c_business_group_id
11663                 and   VMR1.effective_start_date <= c_effective_start_date )
11664    and exists ( select null
11665                 from BEN_VRBL_MTCHG_RT_F VMR2
11666                 where
11667                 VMR2.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
11668                 nvl(VMR2.MTCHG_RT_CALC_RL, -999)   = nvl(l_MTCHG_RT_CALC_RL, -999) and
11669                 VMR2.business_group_id  = c_business_group_id
11670                 and   VMR2.effective_end_date >= c_effective_end_date )
11671                 ;
11672 TEMPIK */
11673    --TEMPIK
11674    l_dt_rec_found            boolean ;
11675    --END TEMPIK
11676    --
11677    l_current_pk_id           number := null ;
11678    --UPD START
11679    --
11680    l_update                  boolean      := false ;
11681    l_datetrack_mode          varchar2(80) := hr_api.g_update;
11682    l_process_date            date;
11683    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
11684    --
11685    --UPD END
11686    l_prev_pk_id              number := null ;
11687    l_first_rec               boolean := true ;
11688    r_VMR                     c_VMR%rowtype;
11689    l_vrbl_mtchg_rt_id             number ;
11690    l_object_version_number   number ;
11691    l_effective_start_date    date ;
11692    l_effective_end_date      date ;
11693    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
11694    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
11695    l_new_value               number(15);
11696    l_object_found_in_target  boolean := false ;
11697    l_min_esd                 date;
11698    l_max_eed                 date;
11699    l_effective_date          date;
11700    --
11701  begin
11702    -- Initialization
11703    l_object_found_in_target := false ;
11704    -- End Initialization
11705    -- Derive the prefix - sufix
11706    if   p_prefix_suffix_cd = 'PREFIX' then
11707      l_prefix  := p_prefix_suffix_text ;
11708    elsif p_prefix_suffix_cd = 'SUFFIX' then
11709      l_suffix   := p_prefix_suffix_text ;
11710    else
11711      l_prefix := null ;
11712      l_suffix  := null ;
11713    end if ;
11714    -- End Prefix Sufix derivation
11715    for r_VMR_unique in c_unique_VMR('VMR') loop
11716 
11717      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
11718         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
11719          r_VMR_unique.information3 >=
11720                  ben_pd_copy_to_ben_one.g_copy_effective_date)
11721         ) then
11722        --
11723        hr_utility.set_location(' r_VMR_unique.table_route_id '||r_VMR_unique.table_route_id,10);
11724        hr_utility.set_location(' r_VMR_unique.information1 '||r_VMR_unique.information1,10);
11725        hr_utility.set_location( 'r_VMR_unique.information2 '||r_VMR_unique.information2,10);
11726        hr_utility.set_location( 'r_VMR_unique.information3 '||r_VMR_unique.information3,10);
11727        -- If reuse objects flag is 'Y' then check for the object in the target business group
11728        -- if found insert the record into PLSql table and exit the loop else try create the
11729        -- object in the target business group
11730        --
11731        l_object_found_in_target := false ;
11732        l_min_esd := null ;
11733        l_max_eed := null ;
11734        open c_VMR_min_max_dates(r_VMR_unique.table_route_id, r_VMR_unique.information1 ) ;
11735        fetch c_VMR_min_max_dates into l_min_esd,l_max_eed ;
11736        --
11737 
11738        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
11739             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
11740          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
11741        end if;
11742        l_min_esd := greatest(l_min_esd,r_VMR_unique.information2);
11743        open c_VMR(r_VMR_unique.table_route_id,
11744                 r_VMR_unique.information1,
11745                 r_VMR_unique.information2,
11746                 r_VMR_unique.information3 ) ;
11747        --
11748        fetch c_VMR into r_VMR ;
11749        --
11750        close c_VMR ;
11751        --
11752        l_MTCHG_RT_CALC_RL := get_fk('FORMULA_ID', r_VMR.information261,r_VMR_unique.dml_operation);
11753        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_VMR.information262,r_VMR_unique.dml_operation);
11754        --UPD START
11755        l_update := false;
11756        l_process_date := p_effective_date;
11757        l_dml_operation:= r_VMR_unique.dml_operation ;
11758        --
11759        if l_dml_operation = 'UPDATE' then
11760          --
11761          l_object_found_in_target := TRUE;
11762          --
11763          if l_process_date between r_VMR_unique.information2 and r_VMR_unique.information3 then
11764                l_update := true;
11765                if r_VMR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
11766                  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_MTCHG_RT_ID'
11767                then
11768                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'VRBL_MTCHG_RT_ID' ;
11769                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_VMR_unique.information1 ;
11770                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_VMR_unique.information1 ;
11771                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
11772                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_VMR_unique.table_route_id;
11773                   --
11774                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
11775                   --
11776                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
11777                   --
11778                   -- log_data('VMR',l_new_value,l_prefix || r_VMR_unique.name|| l_suffix,'REUSED');
11779                   --
11780                end if ;
11781                hr_utility.set_location( 'found record for update',10);
11782            --
11783          else
11784            --
11785            l_update := false;
11786            --
11787          end if;
11788        else
11789          --
11790          --UPD END
11791        if p_reuse_object_flag = 'Y' then
11792          if c_VMR_min_max_dates%found then
11793            -- cursor to find the object
11794            open c_find_VMR_in_target( l_min_esd,l_max_eed,
11795                                  p_target_business_group_id, nvl(l_vrbl_mtchg_rt_id, -999)  ) ;
11796            fetch c_find_VMR_in_target into l_new_value ;
11797            if c_find_VMR_in_target%found then
11798              --
11799              --TEMPIK
11800              l_dt_rec_found :=   dt_api.check_min_max_dates
11801                  (p_base_table_name => 'BEN_VRBL_MTCHG_RT_F',
11802                   p_base_key_column => 'VRBL_MTCHG_RT_ID',
11803                   p_base_key_value  => l_new_value,
11804                   p_from_date       => l_min_esd,
11805                   p_to_date         => l_max_eed );
11806              if l_dt_rec_found THEN
11807              --END TEMPIK
11808              if r_VMR_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
11809                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'VRBL_MTCHG_RT_ID'  then
11810                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'VRBL_MTCHG_RT_ID' ;
11811                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_VMR_unique.information1 ;
11812                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
11813                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
11814                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_VMR_unique.table_route_id;
11815                 --
11816                 -- 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) ;
11817                 --
11818                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
11819              end if ;
11820              --
11821              l_object_found_in_target := true ;
11822              --TEMPIK
11823              end if; -- l_dt_rec_found
11824              --END TEMPIK
11825            end if;
11826            close c_find_VMR_in_target ;
11827          --
11828          end if;
11829        end if ;
11830        --
11831        end if;
11832        close c_VMR_min_max_dates ;
11833        if not l_object_found_in_target OR l_update   then
11834          --
11835          l_current_pk_id := r_VMR.information1;
11836          --
11837          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
11838          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
11839          --
11840          if l_current_pk_id =  l_prev_pk_id  then
11841            --
11842            l_first_rec := false ;
11843            --
11844          else
11845            --
11846            l_first_rec := true ;
11847            --
11848          end if ;
11849          --
11850 
11851          l_effective_date := r_VMR.information2;
11852          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
11853               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
11854            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
11855          end if;
11856 
11857          if l_first_rec and not l_update then
11858            -- Call Create routine.
11859            hr_utility.set_location(' BEN_VRBL_MTCHG_RT_F CREATE_VRBL_MATCHING_RATE ',20);
11860            BEN_VRBL_MATCHING_RATE_API.CREATE_VRBL_MATCHING_RATE(
11861              --
11862              P_VALIDATE               => false
11863              ,P_EFFECTIVE_DATE        => l_effective_date
11864              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
11865              --
11866              ,P_CNTNU_MTCH_AFTR_MAX_RL_FLAG      => r_VMR.INFORMATION12
11867              ,P_FROM_PCT_VAL      => r_VMR.INFORMATION287
11868              ,P_MN_MTCH_AMT      => r_VMR.INFORMATION295
11869              ,P_MTCHG_RT_CALC_RL      => l_MTCHG_RT_CALC_RL
11870              ,P_MX_AMT_OF_PY_NUM      => r_VMR.INFORMATION294
11871              ,P_MX_MTCH_AMT      => r_VMR.INFORMATION293
11872              ,P_MX_PCT_OF_PY_NUM      => r_VMR.INFORMATION289
11873              ,P_NO_MX_AMT_OF_PY_NUM_FLAG      => r_VMR.INFORMATION14
11874              ,P_NO_MX_MTCH_AMT_FLAG      => r_VMR.INFORMATION11
11875              ,P_NO_MX_PCT_OF_PY_NUM_FLAG      => r_VMR.INFORMATION13
11876              ,P_ORDR_NUM      => r_VMR.INFORMATION257
11877              ,P_PCT_VAL      => r_VMR.INFORMATION290
11878              ,P_TO_PCT_VAL      => r_VMR.INFORMATION288
11879              ,P_VMR_ATTRIBUTE1      => r_VMR.INFORMATION111
11880              ,P_VMR_ATTRIBUTE10      => r_VMR.INFORMATION120
11881              ,P_VMR_ATTRIBUTE11      => r_VMR.INFORMATION121
11882              ,P_VMR_ATTRIBUTE12      => r_VMR.INFORMATION122
11883              ,P_VMR_ATTRIBUTE13      => r_VMR.INFORMATION123
11884              ,P_VMR_ATTRIBUTE14      => r_VMR.INFORMATION124
11885              ,P_VMR_ATTRIBUTE15      => r_VMR.INFORMATION125
11886              ,P_VMR_ATTRIBUTE16      => r_VMR.INFORMATION126
11887              ,P_VMR_ATTRIBUTE17      => r_VMR.INFORMATION127
11888              ,P_VMR_ATTRIBUTE18      => r_VMR.INFORMATION128
11889              ,P_VMR_ATTRIBUTE19      => r_VMR.INFORMATION129
11890              ,P_VMR_ATTRIBUTE2      => r_VMR.INFORMATION112
11891              ,P_VMR_ATTRIBUTE20      => r_VMR.INFORMATION130
11892              ,P_VMR_ATTRIBUTE21      => r_VMR.INFORMATION131
11893              ,P_VMR_ATTRIBUTE22      => r_VMR.INFORMATION132
11894              ,P_VMR_ATTRIBUTE23      => r_VMR.INFORMATION133
11895              ,P_VMR_ATTRIBUTE24      => r_VMR.INFORMATION134
11896              ,P_VMR_ATTRIBUTE25      => r_VMR.INFORMATION135
11897              ,P_VMR_ATTRIBUTE26      => r_VMR.INFORMATION136
11898              ,P_VMR_ATTRIBUTE27      => r_VMR.INFORMATION137
11899              ,P_VMR_ATTRIBUTE28      => r_VMR.INFORMATION138
11900              ,P_VMR_ATTRIBUTE29      => r_VMR.INFORMATION139
11901              ,P_VMR_ATTRIBUTE3      => r_VMR.INFORMATION113
11902              ,P_VMR_ATTRIBUTE30      => r_VMR.INFORMATION140
11903              ,P_VMR_ATTRIBUTE4      => r_VMR.INFORMATION114
11904              ,P_VMR_ATTRIBUTE5      => r_VMR.INFORMATION115
11905              ,P_VMR_ATTRIBUTE6      => r_VMR.INFORMATION116
11906              ,P_VMR_ATTRIBUTE7      => r_VMR.INFORMATION117
11907              ,P_VMR_ATTRIBUTE8      => r_VMR.INFORMATION118
11908              ,P_VMR_ATTRIBUTE9      => r_VMR.INFORMATION119
11909              ,P_VMR_ATTRIBUTE_CATEGORY      => r_VMR.INFORMATION110
11910              ,P_VRBL_MTCHG_RT_ID      => l_vrbl_mtchg_rt_id
11911              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
11912              --
11913              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
11914              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
11915              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
11916            );
11917            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
11918            -- Update all relevent cer records with new pk_id
11919            hr_utility.set_location('Before plsql table ',222);
11920            hr_utility.set_location('new_value id '||l_vrbl_mtchg_rt_id,222);
11921            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'VRBL_MTCHG_RT_ID' ;
11922            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_VMR.information1 ;
11923            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_VRBL_MTCHG_RT_ID ;
11924            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
11925            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_VMR_unique.table_route_id;
11926            hr_utility.set_location('After plsql table ',222);
11927            --
11928            -- 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 ) ;
11929            --
11930            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
11931            --
11932          else
11933            --
11934            -- Call Update routine for the pk_id created in prev run .
11935            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
11936            --UPD START
11937            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
11938            --
11939            if l_update then
11940              --
11941              l_datetrack_mode := r_VMR.datetrack_mode ;
11942              --
11943              get_dt_modes(
11944                p_effective_date        => l_process_date,
11945                p_effective_end_date    => r_VMR.information3,
11946                p_effective_start_date  => r_VMR.information2,
11947                p_dml_operation         => r_VMR.dml_operation,
11948                p_datetrack_mode        => l_datetrack_mode );
11949            --    p_update                => l_update
11950              --
11951              l_effective_date := l_process_date;
11952              l_VRBL_MTCHG_RT_ID   := r_VMR.information1;
11953              l_object_version_number := r_VMR.information265;
11954              --
11955            end if;
11956            --
11957            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
11958            --
11959            IF l_update OR l_dml_operation <> 'UPDATE' THEN
11960            --UPD END
11961            hr_utility.set_location(' BEN_VRBL_MTCHG_RT_F UPDATE_VRBL_MATCHING_RATE ',30);
11962            BEN_VRBL_MATCHING_RATE_API.UPDATE_VRBL_MATCHING_RATE(
11963              --
11964              P_VALIDATE               => false
11965              ,P_EFFECTIVE_DATE        => l_effective_date
11966              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
11967              --
11968              ,P_CNTNU_MTCH_AFTR_MAX_RL_FLAG      => r_VMR.INFORMATION12
11969              ,P_FROM_PCT_VAL      => r_VMR.INFORMATION287
11970              ,P_MN_MTCH_AMT      => r_VMR.INFORMATION295
11971              ,P_MTCHG_RT_CALC_RL      => l_MTCHG_RT_CALC_RL
11972              ,P_MX_AMT_OF_PY_NUM      => r_VMR.INFORMATION294
11973              ,P_MX_MTCH_AMT      => r_VMR.INFORMATION293
11974              ,P_MX_PCT_OF_PY_NUM      => r_VMR.INFORMATION289
11975              ,P_NO_MX_AMT_OF_PY_NUM_FLAG      => r_VMR.INFORMATION14
11976              ,P_NO_MX_MTCH_AMT_FLAG      => r_VMR.INFORMATION11
11977              ,P_NO_MX_PCT_OF_PY_NUM_FLAG      => r_VMR.INFORMATION13
11978              ,P_ORDR_NUM      => r_VMR.INFORMATION257
11979              ,P_PCT_VAL      => r_VMR.INFORMATION290
11980              ,P_TO_PCT_VAL      => r_VMR.INFORMATION288
11981              ,P_VMR_ATTRIBUTE1      => r_VMR.INFORMATION111
11982              ,P_VMR_ATTRIBUTE10      => r_VMR.INFORMATION120
11983              ,P_VMR_ATTRIBUTE11      => r_VMR.INFORMATION121
11984              ,P_VMR_ATTRIBUTE12      => r_VMR.INFORMATION122
11985              ,P_VMR_ATTRIBUTE13      => r_VMR.INFORMATION123
11986              ,P_VMR_ATTRIBUTE14      => r_VMR.INFORMATION124
11987              ,P_VMR_ATTRIBUTE15      => r_VMR.INFORMATION125
11988              ,P_VMR_ATTRIBUTE16      => r_VMR.INFORMATION126
11989              ,P_VMR_ATTRIBUTE17      => r_VMR.INFORMATION127
11990              ,P_VMR_ATTRIBUTE18      => r_VMR.INFORMATION128
11991              ,P_VMR_ATTRIBUTE19      => r_VMR.INFORMATION129
11992              ,P_VMR_ATTRIBUTE2      => r_VMR.INFORMATION112
11993              ,P_VMR_ATTRIBUTE20      => r_VMR.INFORMATION130
11994              ,P_VMR_ATTRIBUTE21      => r_VMR.INFORMATION131
11995              ,P_VMR_ATTRIBUTE22      => r_VMR.INFORMATION132
11996              ,P_VMR_ATTRIBUTE23      => r_VMR.INFORMATION133
11997              ,P_VMR_ATTRIBUTE24      => r_VMR.INFORMATION134
11998              ,P_VMR_ATTRIBUTE25      => r_VMR.INFORMATION135
11999              ,P_VMR_ATTRIBUTE26      => r_VMR.INFORMATION136
12000              ,P_VMR_ATTRIBUTE27      => r_VMR.INFORMATION137
12001              ,P_VMR_ATTRIBUTE28      => r_VMR.INFORMATION138
12002              ,P_VMR_ATTRIBUTE29      => r_VMR.INFORMATION139
12003              ,P_VMR_ATTRIBUTE3      => r_VMR.INFORMATION113
12004              ,P_VMR_ATTRIBUTE30      => r_VMR.INFORMATION140
12005              ,P_VMR_ATTRIBUTE4      => r_VMR.INFORMATION114
12006              ,P_VMR_ATTRIBUTE5      => r_VMR.INFORMATION115
12007              ,P_VMR_ATTRIBUTE6      => r_VMR.INFORMATION116
12008              ,P_VMR_ATTRIBUTE7      => r_VMR.INFORMATION117
12009              ,P_VMR_ATTRIBUTE8      => r_VMR.INFORMATION118
12010              ,P_VMR_ATTRIBUTE9      => r_VMR.INFORMATION119
12011              ,P_VMR_ATTRIBUTE_CATEGORY      => r_VMR.INFORMATION110
12012              ,P_VRBL_MTCHG_RT_ID      => l_vrbl_mtchg_rt_id
12013              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
12014              --
12015              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
12016              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
12017              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
12018              ,P_DATETRACK_MODE        => l_datetrack_mode
12019            );
12020            --
12021            end if;
12022          end if;
12023          --
12024          -- Delete the row if it is end dated.
12025          --
12026          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
12027              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
12028              trunc(l_max_eed) = r_VMR.information3) then
12029              --
12030              BEN_VRBL_MATCHING_RATE_API.delete_VRBL_MATCHING_RATE(
12031                 --
12032                 p_validate                       => false
12033                 ,p_vrbl_mtchg_rt_id                   => l_vrbl_mtchg_rt_id
12034                 ,p_effective_start_date           => l_effective_start_date
12035                 ,p_effective_end_date             => l_effective_end_date
12036                 ,p_object_version_number          => l_object_version_number
12037                 ,p_effective_date                 => l_max_eed
12038                 ,p_datetrack_mode                 => hr_api.g_delete
12039                 --
12040                 );
12041                 --
12042          end if;
12043          --
12044          l_prev_pk_id := l_current_pk_id ;
12045          --
12046        end if;
12047        --
12048      end if;
12049      --
12050    end loop;
12051    --
12052  exception when others then
12053     --
12054     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'VMR',r_vmr.information5 );
12055     --
12056  end create_VMR_rows;
12057 
12058    ---------------------------------------------------------------
12059    ----------------------< create_PAP_rows >-----------------------
12060    ---------------------------------------------------------------
12061    --
12062    procedure create_PAP_rows
12063    (
12064          p_validate                       in  number     default 0
12065         ,p_copy_entity_txn_id             in  number
12066         ,p_effective_date                 in  date
12067         ,p_prefix_suffix_text             in  varchar2  default null
12068         ,p_reuse_object_flag              in  varchar2  default null
12069         ,p_target_business_group_id       in  varchar2  default null
12070         ,p_prefix_suffix_cd               in  varchar2  default null
12071    ) is
12072    --
12073    l_PL_ID  number;
12074    l_VRBL_RT_PRFL_ID  number;
12075    cursor c_unique_PAP(l_table_alias varchar2) is
12076    select distinct cpe.information1,
12077      cpe.information2,
12078      cpe.information3,
12079      cpe.table_route_id
12080    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
12081         pqh_table_route tr
12082    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
12083    and   cpe.table_route_id     = tr.table_route_id
12084    -- and   tr.where_clause        = l_BEN_PRTT_ANTHR_PL_RT_F
12085    and tr.table_alias = l_table_alias
12086    and   cpe.number_of_copies   = 1 -- ADDITION
12087    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
12088    order by information1, information2; --added for bug: 5151945
12089    --
12090    --
12091    cursor c_PAP_min_max_dates(c_table_route_id  number,
12092                 c_information1   Number) is
12093    select
12094      min(cpe.information2) min_esd,
12095      max(cpe.information3) min_eed
12096    from ben_copy_entity_results cpe
12097    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
12098    and   cpe.table_route_id     = c_table_route_id
12099    and   cpe.information1       = c_information1 ;
12100    --
12101    cursor c_PAP(c_table_route_id  number,
12102                 c_information1   number,
12103                 c_information2   Date,
12104                 c_information3   Date)  is
12105    select
12106      cpe.*
12107    from ben_copy_entity_results cpe
12108    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
12109    and   cpe.table_route_id     = c_table_route_id
12110    and   cpe.information1       = c_information1
12111    and   cpe.information2       = c_information2
12112    and   cpe.information3       = c_information3
12113    and rownum = 1 ;
12114    -- Date Track target record
12115    cursor c_find_PAP_in_target(
12116                                 c_effective_start_date    date,
12117                                 c_effective_end_date      date,
12118                                 c_business_group_id       number,
12119                                 c_new_pk_id               number) is
12120    select
12121      PAP.prtt_anthr_pl_rt_id new_value
12122    from BEN_PRTT_ANTHR_PL_RT_F PAP
12123    where
12124    PAP.PL_ID     = l_PL_ID  and
12125    PAP.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
12126    PAP.business_group_id  = c_business_group_id
12127    and   PAP.prtt_anthr_pl_rt_id  <> c_new_pk_id
12128 --TEMPIK
12129    and c_effective_start_date between effective_start_date
12130                             and effective_end_date ;
12131 --END TEMPIK
12132 /*TEMPIK
12133    and exists ( select null
12134                 from BEN_PRTT_ANTHR_PL_RT_F PAP1
12135                 where
12136                 PAP1.PL_ID     = l_PL_ID  and
12137                 PAP1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
12138                 PAP1.business_group_id  = c_business_group_id
12139                 and   PAP1.effective_start_date <= c_effective_start_date )
12140    and exists ( select null
12141                 from BEN_PRTT_ANTHR_PL_RT_F PAP2
12142                 where
12143                 PAP2.PL_ID     = l_PL_ID  and
12144                 PAP2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
12145                 PAP2.business_group_id  = c_business_group_id
12146                 and   PAP2.effective_end_date >= c_effective_end_date )
12147                 ;
12148 TEMPIK */
12149    --TEMPIK
12150    l_dt_rec_found            boolean ;
12151    --END TEMPIK
12152    --
12153    l_current_pk_id           number := null ;
12154    --UPD START
12155    --
12156    l_update                  boolean      := false ;
12157    l_datetrack_mode          varchar2(80) := hr_api.g_update;
12158    l_process_date            date;
12159    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
12160    --
12161    --UPD END
12162    l_prev_pk_id              number := null ;
12163    l_first_rec               boolean := true ;
12164    r_PAP                     c_PAP%rowtype;
12165    l_prtt_anthr_pl_rt_id             number ;
12166    l_object_version_number   number ;
12167    l_effective_start_date    date ;
12168    l_effective_end_date      date ;
12169    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
12170    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
12171    l_new_value               number(15);
12172    l_object_found_in_target  boolean := false ;
12173    l_min_esd                 date;
12174    l_max_eed                 date;
12175    l_effective_date          date;
12176    --
12177  begin
12178    -- Initialization
12179    l_object_found_in_target := false ;
12180    -- End Initialization
12181    -- Derive the prefix - sufix
12182    if   p_prefix_suffix_cd = 'PREFIX' then
12183      l_prefix  := p_prefix_suffix_text ;
12184    elsif p_prefix_suffix_cd = 'SUFFIX' then
12185      l_suffix   := p_prefix_suffix_text ;
12186    else
12187      l_prefix := null ;
12188      l_suffix  := null ;
12189    end if ;
12190    -- End Prefix Sufix derivation
12191    for r_PAP_unique in c_unique_PAP('PAP') loop
12192 
12193      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
12194         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
12195          r_PAP_unique.information3 >=
12196                  ben_pd_copy_to_ben_one.g_copy_effective_date)
12197         ) then
12198        --
12199        hr_utility.set_location(' r_PAP_unique.table_route_id '||r_PAP_unique.table_route_id,10);
12200        hr_utility.set_location(' r_PAP_unique.information1 '||r_PAP_unique.information1,10);
12201        hr_utility.set_location( 'r_PAP_unique.information2 '||r_PAP_unique.information2,10);
12202        hr_utility.set_location( 'r_PAP_unique.information3 '||r_PAP_unique.information3,10);
12203        -- If reuse objects flag is 'Y' then check for the object in the target business group
12204        -- if found insert the record into PLSql table and exit the loop else try create the
12205        -- object in the target business group
12206        --
12207        l_object_found_in_target := false ;
12208        l_min_esd := null ;
12209        l_max_eed := null ;
12210        open c_PAP_min_max_dates(r_PAP_unique.table_route_id, r_PAP_unique.information1 ) ;
12211        fetch c_PAP_min_max_dates into l_min_esd,l_max_eed ;
12212        --
12213 
12214        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
12215             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
12216          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
12217        end if;
12218        l_min_esd := greatest(l_min_esd,r_PAP_unique.information2);
12219        open c_PAP(r_PAP_unique.table_route_id,
12220                 r_PAP_unique.information1,
12221                 r_PAP_unique.information2,
12222                 r_PAP_unique.information3 ) ;
12223        --
12224        fetch c_PAP into r_PAP ;
12225        --
12226        close c_PAP ;
12227        --
12228 
12229        -- Only For Use by Create Wizard - Same Business Group
12230        l_PL_ID := NVL(get_fk('PL_ID', r_PAP.information261,r_PAP_unique.dml_operation),
12231                       r_PAP.information261);
12232 
12233        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_PAP.information262,r_PAP_unique.dml_operation);
12234        --UPD START
12235        l_update := false;
12236        l_process_date := p_effective_date;
12237        l_dml_operation:= r_PAP_unique.dml_operation ;
12238        --
12239        if l_dml_operation = 'UPDATE' then
12240          --
12241          l_object_found_in_target := TRUE;
12242          --
12243          if l_process_date between r_PAP_unique.information2 and r_PAP_unique.information3 then
12244                l_update := true;
12245                if r_PAP_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
12246                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'PRTT_ANTHR_PL_RT_ID'
12247                then
12248                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'PRTT_ANTHR_PL_RT_ID' ;
12249                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_PAP_unique.information1 ;
12250                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_PAP_unique.information1 ;
12251                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
12252                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_PAP_unique.table_route_id;
12253                   --
12254                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
12255                   --
12256                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
12257                   --
12258                   -- log_data('PAP',l_new_value,l_prefix || r_PAP_unique.name|| l_suffix,'REUSED');
12259                   --
12260                end if ;
12261                hr_utility.set_location( 'found record for update',10);
12262            --
12263          else
12264            --
12265            l_update := false;
12266            --
12267          end if;
12268        else
12269          --
12270          --UPD END
12271        if p_reuse_object_flag = 'Y' then
12272          if c_PAP_min_max_dates%found then
12273            -- cursor to find the object
12274            open c_find_PAP_in_target( l_min_esd,l_max_eed,
12275                                  p_target_business_group_id, nvl(l_prtt_anthr_pl_rt_id, -999)  ) ;
12276            fetch c_find_PAP_in_target into l_new_value ;
12277            if c_find_PAP_in_target%found then
12278              --
12279              --TEMPIK
12280              l_dt_rec_found :=   dt_api.check_min_max_dates
12281                  (p_base_table_name => 'BEN_PRTT_ANTHR_PL_RT_F',
12282                   p_base_key_column => 'PRTT_ANTHR_PL_RT_ID',
12283                   p_base_key_value  => l_new_value,
12284                   p_from_date       => l_min_esd,
12285                   p_to_date         => l_max_eed );
12286              if l_dt_rec_found THEN
12287              --END TEMPIK
12288              if r_PAP_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
12289                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'PRTT_ANTHR_PL_RT_ID'  then
12290                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'PRTT_ANTHR_PL_RT_ID' ;
12291                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_PAP_unique.information1 ;
12292                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
12293                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
12294                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PAP_unique.table_route_id;
12295                 --
12296                 -- 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) ;
12297                 --
12298                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
12299              end if ;
12300              --
12301              l_object_found_in_target := true ;
12302              --TEMPIK
12303              end if; -- l_dt_rec_found
12304              --END TEMPIK
12305            end if;
12306            close c_find_PAP_in_target ;
12307          --
12308          end if;
12309        end if ;
12310        --
12311        end if;
12312        close c_PAP_min_max_dates ;
12313        if not l_object_found_in_target OR l_update   then
12314          --
12315          l_current_pk_id := r_PAP.information1;
12316          --
12317          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
12318          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
12319          --
12320          if l_current_pk_id =  l_prev_pk_id  then
12321            --
12322            l_first_rec := false ;
12323            --
12324          else
12325            --
12326            l_first_rec := true ;
12327            --
12328          end if ;
12329          --
12330 
12331          l_effective_date := r_PAP.information2;
12332          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
12333               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
12334            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
12335          end if;
12336 
12337          if l_first_rec and not l_update then
12338            -- Call Create routine.
12339            hr_utility.set_location(' BEN_PRTT_ANTHR_PL_RT_F CREATE_PRTT_ANTHR_PL_RT ',20);
12340            BEN_PRTT_ANTHR_PL_RT_API.CREATE_PRTT_ANTHR_PL_RT(
12341              --
12342              P_VALIDATE               => false
12343              ,P_EFFECTIVE_DATE        => l_effective_date
12344              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
12345              --
12346              ,P_EXCLD_FLAG      => r_PAP.INFORMATION11
12347              ,P_ORDR_NUM      => r_PAP.INFORMATION260
12348              ,P_PAP_ATTRIBUTE1      => r_PAP.INFORMATION111
12349              ,P_PAP_ATTRIBUTE10      => r_PAP.INFORMATION120
12350              ,P_PAP_ATTRIBUTE11      => r_PAP.INFORMATION121
12351              ,P_PAP_ATTRIBUTE12      => r_PAP.INFORMATION122
12352              ,P_PAP_ATTRIBUTE13      => r_PAP.INFORMATION123
12353              ,P_PAP_ATTRIBUTE14      => r_PAP.INFORMATION124
12354              ,P_PAP_ATTRIBUTE15      => r_PAP.INFORMATION125
12355              ,P_PAP_ATTRIBUTE16      => r_PAP.INFORMATION126
12356              ,P_PAP_ATTRIBUTE17      => r_PAP.INFORMATION127
12357              ,P_PAP_ATTRIBUTE18      => r_PAP.INFORMATION128
12358              ,P_PAP_ATTRIBUTE19      => r_PAP.INFORMATION129
12359              ,P_PAP_ATTRIBUTE2      => r_PAP.INFORMATION112
12360              ,P_PAP_ATTRIBUTE20      => r_PAP.INFORMATION130
12361              ,P_PAP_ATTRIBUTE21      => r_PAP.INFORMATION131
12362              ,P_PAP_ATTRIBUTE22      => r_PAP.INFORMATION132
12363              ,P_PAP_ATTRIBUTE23      => r_PAP.INFORMATION133
12364              ,P_PAP_ATTRIBUTE24      => r_PAP.INFORMATION134
12365              ,P_PAP_ATTRIBUTE25      => r_PAP.INFORMATION135
12366              ,P_PAP_ATTRIBUTE26      => r_PAP.INFORMATION136
12367              ,P_PAP_ATTRIBUTE27      => r_PAP.INFORMATION137
12368              ,P_PAP_ATTRIBUTE28      => r_PAP.INFORMATION138
12369              ,P_PAP_ATTRIBUTE29      => r_PAP.INFORMATION139
12370              ,P_PAP_ATTRIBUTE3      => r_PAP.INFORMATION113
12371              ,P_PAP_ATTRIBUTE30      => r_PAP.INFORMATION140
12372              ,P_PAP_ATTRIBUTE4      => r_PAP.INFORMATION114
12373              ,P_PAP_ATTRIBUTE5      => r_PAP.INFORMATION115
12374              ,P_PAP_ATTRIBUTE6      => r_PAP.INFORMATION116
12375              ,P_PAP_ATTRIBUTE7      => r_PAP.INFORMATION117
12376              ,P_PAP_ATTRIBUTE8      => r_PAP.INFORMATION118
12377              ,P_PAP_ATTRIBUTE9      => r_PAP.INFORMATION119
12378              ,P_PAP_ATTRIBUTE_CATEGORY      => r_PAP.INFORMATION110
12379              ,P_PL_ID      => l_PL_ID
12380              ,P_PRTT_ANTHR_PL_RT_ID      => l_prtt_anthr_pl_rt_id
12381              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
12382              --
12383              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
12384              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
12385              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
12386            );
12387            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
12388            -- Update all relevent cer records with new pk_id
12389            hr_utility.set_location('Before plsql table ',222);
12390            hr_utility.set_location('new_value id '||l_prtt_anthr_pl_rt_id,222);
12391            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'PRTT_ANTHR_PL_RT_ID' ;
12392            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_PAP.information1 ;
12393            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_PRTT_ANTHR_PL_RT_ID ;
12394            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
12395            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PAP_unique.table_route_id;
12396            hr_utility.set_location('After plsql table ',222);
12397            --
12398            -- 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 ) ;
12399            --
12400            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
12401            --
12402          else
12403            --
12404            -- Call Update routine for the pk_id created in prev run .
12405            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
12406            --UPD START
12407            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
12408            --
12409            if l_update then
12410              --
12411              l_datetrack_mode := r_PAP.datetrack_mode ;
12412              --
12413              get_dt_modes(
12414                p_effective_date        => l_process_date,
12415                p_effective_end_date    => r_PAP.information3,
12416                p_effective_start_date  => r_PAP.information2,
12417                p_dml_operation         => r_PAP.dml_operation,
12418                p_datetrack_mode        => l_datetrack_mode );
12419            --    p_update                => l_update
12420              --
12421              l_effective_date := l_process_date;
12422              l_PRTT_ANTHR_PL_RT_ID   := r_PAP.information1;
12423              l_object_version_number := r_PAP.information265;
12424              --
12425            end if;
12426            --
12427            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
12428            --
12429            IF l_update OR l_dml_operation <> 'UPDATE' THEN
12430            --UPD END
12431            hr_utility.set_location(' BEN_PRTT_ANTHR_PL_RT_F UPDATE_PRTT_ANTHR_PL_RT ',30);
12432            BEN_PRTT_ANTHR_PL_RT_API.UPDATE_PRTT_ANTHR_PL_RT(
12433              --
12434              P_VALIDATE               => false
12435              ,P_EFFECTIVE_DATE        => l_effective_date
12436              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
12437              --
12438              ,P_EXCLD_FLAG      => r_PAP.INFORMATION11
12439              ,P_ORDR_NUM      => r_PAP.INFORMATION260
12440              ,P_PAP_ATTRIBUTE1      => r_PAP.INFORMATION111
12441              ,P_PAP_ATTRIBUTE10      => r_PAP.INFORMATION120
12442              ,P_PAP_ATTRIBUTE11      => r_PAP.INFORMATION121
12443              ,P_PAP_ATTRIBUTE12      => r_PAP.INFORMATION122
12444              ,P_PAP_ATTRIBUTE13      => r_PAP.INFORMATION123
12445              ,P_PAP_ATTRIBUTE14      => r_PAP.INFORMATION124
12446              ,P_PAP_ATTRIBUTE15      => r_PAP.INFORMATION125
12447              ,P_PAP_ATTRIBUTE16      => r_PAP.INFORMATION126
12448              ,P_PAP_ATTRIBUTE17      => r_PAP.INFORMATION127
12449              ,P_PAP_ATTRIBUTE18      => r_PAP.INFORMATION128
12450              ,P_PAP_ATTRIBUTE19      => r_PAP.INFORMATION129
12451              ,P_PAP_ATTRIBUTE2      => r_PAP.INFORMATION112
12452              ,P_PAP_ATTRIBUTE20      => r_PAP.INFORMATION130
12453              ,P_PAP_ATTRIBUTE21      => r_PAP.INFORMATION131
12454              ,P_PAP_ATTRIBUTE22      => r_PAP.INFORMATION132
12455              ,P_PAP_ATTRIBUTE23      => r_PAP.INFORMATION133
12456              ,P_PAP_ATTRIBUTE24      => r_PAP.INFORMATION134
12457              ,P_PAP_ATTRIBUTE25      => r_PAP.INFORMATION135
12458              ,P_PAP_ATTRIBUTE26      => r_PAP.INFORMATION136
12459              ,P_PAP_ATTRIBUTE27      => r_PAP.INFORMATION137
12460              ,P_PAP_ATTRIBUTE28      => r_PAP.INFORMATION138
12461              ,P_PAP_ATTRIBUTE29      => r_PAP.INFORMATION139
12462              ,P_PAP_ATTRIBUTE3      => r_PAP.INFORMATION113
12463              ,P_PAP_ATTRIBUTE30      => r_PAP.INFORMATION140
12464              ,P_PAP_ATTRIBUTE4      => r_PAP.INFORMATION114
12465              ,P_PAP_ATTRIBUTE5      => r_PAP.INFORMATION115
12466              ,P_PAP_ATTRIBUTE6      => r_PAP.INFORMATION116
12467              ,P_PAP_ATTRIBUTE7      => r_PAP.INFORMATION117
12468              ,P_PAP_ATTRIBUTE8      => r_PAP.INFORMATION118
12469              ,P_PAP_ATTRIBUTE9      => r_PAP.INFORMATION119
12470              ,P_PAP_ATTRIBUTE_CATEGORY      => r_PAP.INFORMATION110
12471              ,P_PL_ID      => l_PL_ID
12472              ,P_PRTT_ANTHR_PL_RT_ID      => l_prtt_anthr_pl_rt_id
12473              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
12474              --
12475              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
12476              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
12477              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
12478              ,P_DATETRACK_MODE        => l_datetrack_mode
12479            );
12480            --
12481            end if;
12482          end if;
12483          --
12484          -- Delete the row if it is end dated.
12485          --
12486          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
12487              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
12488              trunc(l_max_eed) = r_PAP.information3) then
12489              --
12490              BEN_PRTT_ANTHR_PL_RT_API.delete_PRTT_ANTHR_PL_RT(
12491                 --
12492                 p_validate                       => false
12493                 ,p_prtt_anthr_pl_rt_id                   => l_prtt_anthr_pl_rt_id
12494                 ,p_effective_start_date           => l_effective_start_date
12495                 ,p_effective_end_date             => l_effective_end_date
12496                 ,p_object_version_number          => l_object_version_number
12497                 ,p_effective_date                 => l_max_eed
12498                 ,p_datetrack_mode                 => hr_api.g_delete
12499                 --
12500                 );
12501                 --
12502          end if;
12503          --
12504          l_prev_pk_id := l_current_pk_id ;
12505          --
12506        end if;
12507        --
12508      end if;
12509      --
12510    end loop;
12511    --
12512  exception when others then
12513     --
12514     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'PAP',r_pap.information5 );
12515     --
12516  end create_PAP_rows;
12517 
12518    ---------------------------------------------------------------
12519    ----------------------< create_OPR_rows >-----------------------
12520    ---------------------------------------------------------------
12521    --
12522    procedure create_OPR_rows
12523    (
12524          p_validate                       in  number     default 0
12525         ,p_copy_entity_txn_id             in  number
12526         ,p_effective_date                 in  date
12527         ,p_prefix_suffix_text             in  varchar2  default null
12528         ,p_reuse_object_flag              in  varchar2  default null
12529         ,p_target_business_group_id       in  varchar2  default null
12530         ,p_prefix_suffix_cd               in  varchar2  default null
12531    ) is
12532    --
12533    l_PTIP_ID  number;
12534    l_VRBL_RT_PRFL_ID  number;
12535    cursor c_unique_OPR(l_table_alias varchar2) is
12536    select distinct cpe.information1,
12537      cpe.information2,
12538      cpe.information3,
12539      cpe.table_route_id
12540    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
12541         pqh_table_route tr
12542    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
12543    and   cpe.table_route_id     = tr.table_route_id
12544    -- and   tr.where_clause        = l_BEN_OTHR_PTIP_RT_F
12545    and tr.table_alias = l_table_alias
12546    and   cpe.number_of_copies   = 1 -- ADDITION
12547    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
12548    order by information1, information2; --added for bug: 5151945
12549    --
12550    --
12551    cursor c_OPR_min_max_dates(c_table_route_id  number,
12552                 c_information1   Number) is
12553    select
12554      min(cpe.information2) min_esd,
12555      max(cpe.information3) min_eed
12556    from ben_copy_entity_results cpe
12557    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
12558    and   cpe.table_route_id     = c_table_route_id
12559    and   cpe.information1       = c_information1 ;
12560    --
12561    cursor c_OPR(c_table_route_id  number,
12562                 c_information1   number,
12563                 c_information2   Date,
12564                 c_information3   Date )  is
12565    select
12566      cpe.*
12567    from ben_copy_entity_results cpe
12568    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
12569    and   cpe.table_route_id     = c_table_route_id
12570    and   cpe.information1       = c_information1
12571    and   cpe.information2       = c_information2
12572    and   cpe.information3       = c_information3
12573    and rownum = 1 ;
12574    -- Date Track target record
12575    cursor c_find_OPR_in_target(
12576                                 c_effective_start_date    date,
12577                                 c_effective_end_date      date,
12578                                 c_business_group_id       number,
12579                                 c_new_pk_id               number) is
12580    select
12581      OPR.othr_ptip_rt_id new_value
12582    from BEN_OTHR_PTIP_RT_F OPR
12583    where
12584    OPR.PTIP_ID     = l_PTIP_ID  and
12585    OPR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
12586    OPR.business_group_id  = c_business_group_id
12587    and   OPR.othr_ptip_rt_id  <> c_new_pk_id
12588 --TEMPIK
12589    and c_effective_start_date between effective_start_date
12590                             and effective_end_date ;
12591 --END TEMPIK
12592 /*TEMPIK
12593    and exists ( select null
12594                 from BEN_OTHR_PTIP_RT_F OPR1
12595                 where
12596                 OPR1.PTIP_ID     = l_PTIP_ID  and
12597                 OPR1.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
12598                 OPR1.business_group_id  = c_business_group_id
12599                 and   OPR1.effective_start_date <= c_effective_start_date )
12600    and exists ( select null
12601                 from BEN_OTHR_PTIP_RT_F OPR2
12602                 where
12603                 OPR2.PTIP_ID     = l_PTIP_ID  and
12604                 OPR2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
12605                 OPR2.business_group_id  = c_business_group_id
12606                 and   OPR2.effective_end_date >= c_effective_end_date )
12607                 ;
12608 TEMPIK */
12609    --TEMPIK
12610    l_dt_rec_found            boolean ;
12611    --END TEMPIK
12612    --
12613    l_current_pk_id           number := null ;
12614    --UPD START
12615    --
12616    l_update                  boolean      := false ;
12617    l_datetrack_mode          varchar2(80) := hr_api.g_update;
12618    l_process_date            date;
12619    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
12620    --
12621    --UPD END
12622    l_prev_pk_id              number := null ;
12623    l_first_rec               boolean := true ;
12624    r_OPR                     c_OPR%rowtype;
12625    l_othr_ptip_rt_id             number ;
12626    l_object_version_number   number ;
12627    l_effective_start_date    date ;
12628    l_effective_end_date      date ;
12629    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
12630    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
12631    l_new_value               number(15);
12632    l_object_found_in_target  boolean := false ;
12633    l_min_esd                 date;
12634    l_max_eed                 date;
12635    l_effective_date          date;
12636    --
12637  begin
12638    -- Initialization
12639    l_object_found_in_target := false ;
12640    -- End Initialization
12641    -- Derive the prefix - sufix
12642    if   p_prefix_suffix_cd = 'PREFIX' then
12643      l_prefix  := p_prefix_suffix_text ;
12644    elsif p_prefix_suffix_cd = 'SUFFIX' then
12645      l_suffix   := p_prefix_suffix_text ;
12646    else
12647      l_prefix := null ;
12648      l_suffix  := null ;
12649    end if ;
12650    -- End Prefix Sufix derivation
12651    for r_OPR_unique in c_unique_OPR('OPR') loop
12652 
12653      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
12654         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
12655          r_OPR_unique.information3 >=
12656                  ben_pd_copy_to_ben_one.g_copy_effective_date)
12657           ) then
12658        --
12659        hr_utility.set_location(' r_OPR_unique.table_route_id '||r_OPR_unique.table_route_id,10);
12660        hr_utility.set_location(' r_OPR_unique.information1 '||r_OPR_unique.information1,10);
12661        hr_utility.set_location( 'r_OPR_unique.information2 '||r_OPR_unique.information2,10);
12662        hr_utility.set_location( 'r_OPR_unique.information3 '||r_OPR_unique.information3,10);
12663        -- If reuse objects flag is 'Y' then check for the object in the target business group
12664        -- if found insert the record into PLSql table and exit the loop else try create the
12665        -- object in the target business group
12666        --
12667        l_object_found_in_target := false ;
12668        l_min_esd := null ;
12669        l_max_eed := null ;
12670        open c_OPR_min_max_dates(r_OPR_unique.table_route_id, r_OPR_unique.information1 ) ;
12671        fetch c_OPR_min_max_dates into l_min_esd,l_max_eed ;
12672        --
12673 
12674        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
12675             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
12676          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
12677        end if;
12678        l_min_esd := greatest(l_min_esd,r_OPR_unique.information2);
12679        open c_OPR(r_OPR_unique.table_route_id,
12680                 r_OPR_unique.information1,
12681                 r_OPR_unique.information2,
12682                 r_OPR_unique.information3 ) ;
12683        --
12684        fetch c_OPR into r_OPR ;
12685        --
12686        close c_OPR ;
12687        --
12688        -- Only For Use by Create Wizard - Same Business Group
12689        l_PTIP_ID := NVL(get_fk('PTIP_ID', r_OPR.information259,r_OPR_unique.dml_operation),
12690                         r_OPR.information259);
12691 
12692        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_OPR.information262,r_OPR_unique.dml_operation);
12693        --UPD START
12694        l_update := false;
12695        l_process_date := p_effective_date;
12696        l_dml_operation:= r_OPR_unique.dml_operation ;
12697        --
12698        if l_dml_operation = 'UPDATE' then
12699          --
12700          l_object_found_in_target := TRUE;
12701          --
12702          if l_process_date between r_OPR_unique.information2 and r_OPR_unique.information3 then
12703                l_update := true;
12704                if r_OPR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
12705                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'OTHR_PTIP_RT_ID'
12706                then
12707                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'OTHR_PTIP_RT_ID' ;
12708                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_OPR_unique.information1 ;
12709                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_OPR_unique.information1 ;
12710                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
12711                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_OPR_unique.table_route_id;
12712                   --
12713                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
12714                   --
12715                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
12716                   --
12717                   -- log_data('OPR',l_new_value,l_prefix || r_OPR_unique.name|| l_suffix,'REUSED');
12718                   --
12719                end if ;
12720                hr_utility.set_location( 'found record for update',10);
12721            --
12722          else
12723            --
12724            l_update := false;
12725            --
12726          end if;
12727        else
12728          --
12729          --UPD END
12730        if p_reuse_object_flag = 'Y' then
12731          if c_OPR_min_max_dates%found then
12732            -- cursor to find the object
12733            open c_find_OPR_in_target( l_min_esd,l_max_eed,
12734                                  p_target_business_group_id, nvl(l_othr_ptip_rt_id, -999)  ) ;
12735            fetch c_find_OPR_in_target into l_new_value ;
12736            if c_find_OPR_in_target%found then
12737              --
12738              --TEMPIK
12739              l_dt_rec_found :=   dt_api.check_min_max_dates
12740                  (p_base_table_name => 'BEN_OTHR_PTIP_RT_F',
12741                   p_base_key_column => 'OTHR_PTIP_RT_ID',
12742                   p_base_key_value  => l_new_value,
12743                   p_from_date       => l_min_esd,
12744                   p_to_date         => l_max_eed );
12745              if l_dt_rec_found THEN
12746              --END TEMPIK
12747              if r_OPR_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
12748                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'OTHR_PTIP_RT_ID'  then
12749                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'OTHR_PTIP_RT_ID' ;
12750                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_OPR_unique.information1 ;
12751                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
12752                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
12753                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_OPR_unique.table_route_id;
12754                 --
12755                 -- 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) ;
12756                 --
12757                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
12758              end if ;
12759              --
12760              l_object_found_in_target := true ;
12761              --TEMPIK
12762              end if; -- l_dt_rec_found
12763              --END TEMPIK
12764            end if;
12765            close c_find_OPR_in_target ;
12766          --
12767          end if;
12768        end if ;
12769        --
12770        end if;
12771        close c_OPR_min_max_dates ;
12772        if not l_object_found_in_target OR l_update   then
12773          --
12774          l_current_pk_id := r_OPR.information1;
12775          --
12776          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
12777          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
12778          --
12779          if l_current_pk_id =  l_prev_pk_id  then
12780            --
12781            l_first_rec := false ;
12782            --
12783          else
12784            --
12785            l_first_rec := true ;
12786            --
12787          end if ;
12788          --
12789 
12790          l_effective_date := r_OPR.information2;
12791          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
12792               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
12793            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
12794          end if;
12795 
12796          if l_first_rec and not l_update then
12797            -- Call Create routine.
12798            hr_utility.set_location(' BEN_OTHR_PTIP_RT_F CREATE_OTHR_PTIP_RT ',20);
12799            BEN_OTHR_PTIP_RT_API.CREATE_OTHR_PTIP_RT(
12800              --
12801              P_VALIDATE               => false
12802              ,P_EFFECTIVE_DATE        => l_effective_date
12803              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
12804              --
12805              ,P_EXCLD_FLAG      => r_OPR.INFORMATION11
12806              ,P_ONLY_PLS_SUBJ_COBRA_FLAG      => r_OPR.INFORMATION12
12807              ,P_OPR_ATTRIBUTE1      => r_OPR.INFORMATION111
12808              ,P_OPR_ATTRIBUTE10      => r_OPR.INFORMATION120
12809              ,P_OPR_ATTRIBUTE11      => r_OPR.INFORMATION121
12810              ,P_OPR_ATTRIBUTE12      => r_OPR.INFORMATION122
12811              ,P_OPR_ATTRIBUTE13      => r_OPR.INFORMATION123
12812              ,P_OPR_ATTRIBUTE14      => r_OPR.INFORMATION124
12813              ,P_OPR_ATTRIBUTE15      => r_OPR.INFORMATION125
12814              ,P_OPR_ATTRIBUTE16      => r_OPR.INFORMATION126
12815              ,P_OPR_ATTRIBUTE17      => r_OPR.INFORMATION127
12816              ,P_OPR_ATTRIBUTE18      => r_OPR.INFORMATION128
12817              ,P_OPR_ATTRIBUTE19      => r_OPR.INFORMATION129
12818              ,P_OPR_ATTRIBUTE2      => r_OPR.INFORMATION112
12819              ,P_OPR_ATTRIBUTE20      => r_OPR.INFORMATION130
12820              ,P_OPR_ATTRIBUTE21      => r_OPR.INFORMATION131
12821              ,P_OPR_ATTRIBUTE22      => r_OPR.INFORMATION132
12822              ,P_OPR_ATTRIBUTE23      => r_OPR.INFORMATION133
12823              ,P_OPR_ATTRIBUTE24      => r_OPR.INFORMATION134
12824              ,P_OPR_ATTRIBUTE25      => r_OPR.INFORMATION135
12825              ,P_OPR_ATTRIBUTE26      => r_OPR.INFORMATION136
12826              ,P_OPR_ATTRIBUTE27      => r_OPR.INFORMATION137
12827              ,P_OPR_ATTRIBUTE28      => r_OPR.INFORMATION138
12828              ,P_OPR_ATTRIBUTE29      => r_OPR.INFORMATION139
12829              ,P_OPR_ATTRIBUTE3      => r_OPR.INFORMATION113
12830              ,P_OPR_ATTRIBUTE30      => r_OPR.INFORMATION140
12831              ,P_OPR_ATTRIBUTE4      => r_OPR.INFORMATION114
12832              ,P_OPR_ATTRIBUTE5      => r_OPR.INFORMATION115
12833              ,P_OPR_ATTRIBUTE6      => r_OPR.INFORMATION116
12834              ,P_OPR_ATTRIBUTE7      => r_OPR.INFORMATION117
12835              ,P_OPR_ATTRIBUTE8      => r_OPR.INFORMATION118
12836              ,P_OPR_ATTRIBUTE9      => r_OPR.INFORMATION119
12837              ,P_OPR_ATTRIBUTE_CATEGORY      => r_OPR.INFORMATION110
12838              ,P_ORDR_NUM      => r_OPR.INFORMATION257
12839              ,P_OTHR_PTIP_RT_ID      => l_othr_ptip_rt_id
12840              ,P_PTIP_ID      => l_PTIP_ID
12841              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
12842              --
12843              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
12844              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
12845              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
12846            );
12847            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
12848            -- Update all relevent cer records with new pk_id
12849            hr_utility.set_location('Before plsql table ',222);
12850            hr_utility.set_location('new_value id '||l_othr_ptip_rt_id,222);
12851            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'OTHR_PTIP_RT_ID' ;
12852            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_OPR.information1 ;
12853            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_OTHR_PTIP_RT_ID ;
12854            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
12855            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_OPR_unique.table_route_id;
12856            hr_utility.set_location('After plsql table ',222);
12857            --
12858            -- 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 ) ;
12859            --
12860            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
12861            --
12862          else
12863            --
12864            -- Call Update routine for the pk_id created in prev run .
12865            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
12866            --UPD START
12867            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
12868            --
12869            if l_update then
12870              --
12871              l_datetrack_mode := r_OPR.datetrack_mode ;
12872              --
12873              get_dt_modes(
12874                p_effective_date        => l_process_date,
12875                p_effective_end_date    => r_OPR.information3,
12876                p_effective_start_date  => r_OPR.information2,
12877                p_dml_operation         => r_OPR.dml_operation,
12878                p_datetrack_mode        => l_datetrack_mode );
12879            --    p_update                => l_update
12880              --
12881              l_effective_date := l_process_date;
12882              l_OTHR_PTIP_RT_ID   := r_OPR.information1;
12883              l_object_version_number := r_OPR.information265;
12884              --
12885            end if;
12886            --
12887            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
12888            --
12889            IF l_update OR l_dml_operation <> 'UPDATE' THEN
12890            --UPD END
12891            hr_utility.set_location(' BEN_OTHR_PTIP_RT_F UPDATE_OTHR_PTIP_RT ',30);
12892            BEN_OTHR_PTIP_RT_API.UPDATE_OTHR_PTIP_RT(
12893              --
12894              P_VALIDATE               => false
12895              ,P_EFFECTIVE_DATE        => l_effective_date
12896              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
12897              --
12898              ,P_EXCLD_FLAG      => r_OPR.INFORMATION11
12899              ,P_ONLY_PLS_SUBJ_COBRA_FLAG      => r_OPR.INFORMATION12
12900              ,P_OPR_ATTRIBUTE1      => r_OPR.INFORMATION111
12901              ,P_OPR_ATTRIBUTE10      => r_OPR.INFORMATION120
12902              ,P_OPR_ATTRIBUTE11      => r_OPR.INFORMATION121
12903              ,P_OPR_ATTRIBUTE12      => r_OPR.INFORMATION122
12904              ,P_OPR_ATTRIBUTE13      => r_OPR.INFORMATION123
12905              ,P_OPR_ATTRIBUTE14      => r_OPR.INFORMATION124
12906              ,P_OPR_ATTRIBUTE15      => r_OPR.INFORMATION125
12907              ,P_OPR_ATTRIBUTE16      => r_OPR.INFORMATION126
12908              ,P_OPR_ATTRIBUTE17      => r_OPR.INFORMATION127
12909              ,P_OPR_ATTRIBUTE18      => r_OPR.INFORMATION128
12910              ,P_OPR_ATTRIBUTE19      => r_OPR.INFORMATION129
12911              ,P_OPR_ATTRIBUTE2      => r_OPR.INFORMATION112
12912              ,P_OPR_ATTRIBUTE20      => r_OPR.INFORMATION130
12913              ,P_OPR_ATTRIBUTE21      => r_OPR.INFORMATION131
12914              ,P_OPR_ATTRIBUTE22      => r_OPR.INFORMATION132
12915              ,P_OPR_ATTRIBUTE23      => r_OPR.INFORMATION133
12916              ,P_OPR_ATTRIBUTE24      => r_OPR.INFORMATION134
12917              ,P_OPR_ATTRIBUTE25      => r_OPR.INFORMATION135
12918              ,P_OPR_ATTRIBUTE26      => r_OPR.INFORMATION136
12919              ,P_OPR_ATTRIBUTE27      => r_OPR.INFORMATION137
12920              ,P_OPR_ATTRIBUTE28      => r_OPR.INFORMATION138
12921              ,P_OPR_ATTRIBUTE29      => r_OPR.INFORMATION139
12922              ,P_OPR_ATTRIBUTE3      => r_OPR.INFORMATION113
12923              ,P_OPR_ATTRIBUTE30      => r_OPR.INFORMATION140
12924              ,P_OPR_ATTRIBUTE4      => r_OPR.INFORMATION114
12925              ,P_OPR_ATTRIBUTE5      => r_OPR.INFORMATION115
12926              ,P_OPR_ATTRIBUTE6      => r_OPR.INFORMATION116
12927              ,P_OPR_ATTRIBUTE7      => r_OPR.INFORMATION117
12928              ,P_OPR_ATTRIBUTE8      => r_OPR.INFORMATION118
12929              ,P_OPR_ATTRIBUTE9      => r_OPR.INFORMATION119
12930              ,P_OPR_ATTRIBUTE_CATEGORY      => r_OPR.INFORMATION110
12931              ,P_ORDR_NUM      => r_OPR.INFORMATION257
12932              ,P_OTHR_PTIP_RT_ID      => l_othr_ptip_rt_id
12933              ,P_PTIP_ID      => l_PTIP_ID
12934              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
12935              --
12936              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
12937              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
12938              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
12939              ,P_DATETRACK_MODE        => l_datetrack_mode
12940            );
12941            --
12942            end if;
12943          end if;
12944          --
12945          -- Delete the row if it is end dated.
12946          --
12947          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
12948              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
12949              trunc(l_max_eed) = r_OPR.information3) then
12950              --
12951              BEN_OTHR_PTIP_RT_API.delete_OTHR_PTIP_RT(
12952                 --
12953                 p_validate                       => false
12954                 ,p_othr_ptip_rt_id                   => l_othr_ptip_rt_id
12955                 ,p_effective_start_date           => l_effective_start_date
12956                 ,p_effective_end_date             => l_effective_end_date
12957                 ,p_object_version_number          => l_object_version_number
12958                 ,p_effective_date                 => l_max_eed
12959                 ,p_datetrack_mode                 => hr_api.g_delete
12960                 --
12961                 );
12962                 --
12963          end if;
12964          --
12965          l_prev_pk_id := l_current_pk_id ;
12966          --
12967        end if;
12968        --
12969      end if;
12970      --
12971    end loop;
12972    --
12973  exception when others then
12974     --
12975     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'OPR',r_opr.information5 );
12976     --
12977  end create_OPR_rows;
12978 
12979    ---------------------------------------------------------------
12980    ----------------------< create_NOC_rows >-----------------------
12981    ---------------------------------------------------------------
12982    --
12983    procedure create_NOC_rows
12984    (
12985          p_validate                       in  number     default 0
12986         ,p_copy_entity_txn_id             in  number
12987         ,p_effective_date                 in  date
12988         ,p_prefix_suffix_text             in  varchar2  default null
12989         ,p_reuse_object_flag              in  varchar2  default null
12990         ,p_target_business_group_id       in  varchar2  default null
12991         ,p_prefix_suffix_cd               in  varchar2  default null
12992    ) is
12993    --
12994    l_VRBL_RT_PRFL_ID  number;
12995    l_COORD_BEN_NO_CVG_FLAG varchar2(100);
12996    cursor c_unique_NOC(l_table_alias varchar2) is
12997    select distinct cpe.information1,
12998      cpe.information2,
12999      cpe.information3,
13000      cpe.table_route_id
13001    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
13002         pqh_table_route tr
13003    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
13004    and   cpe.table_route_id     = tr.table_route_id
13005    -- and   tr.where_clause        = l_BEN_NO_OTHR_CVG_RT_F
13006    and tr.table_alias = l_table_alias
13007    and   cpe.number_of_copies   = 1 -- ADDITION
13008    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
13009    order by information1, information2; --added for bug: 5151945
13010    --
13011    --
13012    cursor c_NOC_min_max_dates(c_table_route_id  number,
13013                 c_information1   Number) is
13014    select
13015      min(cpe.information2) min_esd,
13016      max(cpe.information3) min_eed
13017    from ben_copy_entity_results cpe
13018    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
13019    and   cpe.table_route_id     = c_table_route_id
13020    and   cpe.information1       = c_information1 ;
13021    --
13022    cursor c_NOC(c_table_route_id  number,
13023                 c_information1   number,
13024                 c_information2   Date,
13025                 c_information3   Date)  is
13026    select
13027      cpe.*
13028    from ben_copy_entity_results cpe
13029    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
13030    and   cpe.table_route_id     = c_table_route_id
13031    and   cpe.information1       = c_information1
13032    and   cpe.information2       = c_information2
13033    and   cpe.information3       = c_information3
13034    and rownum = 1 ;
13035    -- Date Track target record
13036    cursor c_find_NOC_in_target(
13037                                 c_effective_start_date    date,
13038                                 c_effective_end_date      date,
13039                                 c_business_group_id       number,
13040                                 c_new_pk_id               number) is
13041    select
13042      NOC.no_othr_cvg_rt_id new_value
13043    from BEN_NO_OTHR_CVG_RT_F NOC
13044    where
13045    NOC.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
13046    NOC.COORD_BEN_NO_CVG_FLAG     = l_COORD_BEN_NO_CVG_FLAG  and
13047    NOC.business_group_id  = c_business_group_id
13048    and   NOC.no_othr_cvg_rt_id  <> c_new_pk_id
13049 --TEMPIK
13050    and c_effective_start_date between effective_start_date
13051                             and effective_end_date ;
13052 --END TEMPIK
13053 /*TEMPIK
13054    and exists ( select null
13055                 from BEN_NO_OTHR_CVG_RT_F NOC1
13056                 where
13057                 NOC1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
13058                 NOC1.COORD_BEN_NO_CVG_FLAG     = l_COORD_BEN_NO_CVG_FLAG  and
13059                 NOC1.business_group_id  = c_business_group_id
13060                 and   NOC1.effective_start_date <= c_effective_start_date )
13061    and exists ( select null
13062                 from BEN_NO_OTHR_CVG_RT_F NOC2
13063                 where
13064                 NOC2.VRBL_RT_PRFL_ID    =l_VRBL_RT_PRFL_ID  and
13065                 NOC2.COORD_BEN_NO_CVG_FLAG     = l_COORD_BEN_NO_CVG_FLAG  and
13066                 NOC2.business_group_id  = c_business_group_id
13067                 and   NOC2.effective_end_date >= c_effective_end_date )
13068                 ;
13069 TEMPIK */
13070    --TEMPIK
13071    l_dt_rec_found            boolean ;
13072    --END TEMPIK
13073    --
13074    l_current_pk_id           number := null ;
13075    --UPD START
13076    --
13077    l_update                  boolean      := false ;
13078    l_datetrack_mode          varchar2(80) := hr_api.g_update;
13079    l_process_date            date;
13080    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
13081    --
13082    --UPD END
13083    l_prev_pk_id              number := null ;
13084    l_first_rec               boolean := true ;
13085    r_NOC                     c_NOC%rowtype;
13086    l_no_othr_cvg_rt_id             number ;
13087    l_object_version_number   number ;
13088    l_effective_start_date    date ;
13089    l_effective_end_date      date ;
13090    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
13091    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
13092    l_new_value               number(15);
13093    l_object_found_in_target  boolean := false ;
13094    l_min_esd                 date;
13095    l_max_eed                 date;
13096    l_effective_date          date;
13097    --
13098  begin
13099    -- Initialization
13100    l_object_found_in_target := false ;
13101    -- End Initialization
13102    -- Derive the prefix - sufix
13103    if   p_prefix_suffix_cd = 'PREFIX' then
13104      l_prefix  := p_prefix_suffix_text ;
13105    elsif p_prefix_suffix_cd = 'SUFFIX' then
13106      l_suffix   := p_prefix_suffix_text ;
13107    else
13108      l_prefix := null ;
13109      l_suffix  := null ;
13110    end if ;
13111    -- End Prefix Sufix derivation
13112    for r_NOC_unique in c_unique_NOC('NOC') loop
13113 
13114      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
13115         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
13116          r_NOC_unique.information3 >=
13117                  ben_pd_copy_to_ben_one.g_copy_effective_date)
13118         ) then
13119 
13120        --
13121        hr_utility.set_location(' r_NOC_unique.table_route_id '||r_NOC_unique.table_route_id,10);
13122        hr_utility.set_location(' r_NOC_unique.information1 '||r_NOC_unique.information1,10);
13123        hr_utility.set_location( 'r_NOC_unique.information2 '||r_NOC_unique.information2,10);
13124        hr_utility.set_location( 'r_NOC_unique.information3 '||r_NOC_unique.information3,10);
13125        -- If reuse objects flag is 'Y' then check for the object in the target business group
13126        -- if found insert the record into PLSql table and exit the loop else try create the
13127        -- object in the target business group
13128        --
13129        l_object_found_in_target := false ;
13130        l_min_esd := null ;
13131        l_max_eed := null ;
13132        open c_NOC_min_max_dates(r_NOC_unique.table_route_id, r_NOC_unique.information1 ) ;
13133        fetch c_NOC_min_max_dates into l_min_esd,l_max_eed ;
13134        --
13135 
13136        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
13137             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
13138          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
13139        end if;
13140        l_min_esd := greatest(l_min_esd,r_NOC_unique.information2);
13141        open c_NOC(r_NOC_unique.table_route_id,
13142                 r_NOC_unique.information1,
13143                 r_NOC_unique.information2,
13144                 r_NOC_unique.information3 ) ;
13145        --
13146        fetch c_NOC into r_NOC ;
13147        --
13148        close c_NOC ;
13149        --
13150        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_NOC.information262,r_NOC_unique.dml_operation);
13151        l_COORD_BEN_NO_CVG_FLAG      := r_NOC.information11;
13152        --UPD START
13153        l_update := false;
13154        l_process_date := p_effective_date;
13155        l_dml_operation:= r_NOC_unique.dml_operation ;
13156        --
13157        if l_dml_operation = 'UPDATE' then
13158          --
13159          l_object_found_in_target := TRUE;
13160          --
13161          if l_process_date between r_NOC_unique.information2 and r_NOC_unique.information3 then
13162                l_update := true;
13163                if r_NOC_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
13164                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'NO_OTHR_CVG_RT_ID'
13165                then
13166                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'NO_OTHR_CVG_RT_ID' ;
13167                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_NOC_unique.information1 ;
13168                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_NOC_unique.information1 ;
13169                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
13170                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_NOC_unique.table_route_id;
13171                   --
13172                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
13173                   --
13174                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
13175                   --
13176                   -- log_data('NOC',l_new_value,l_prefix || r_NOC_unique.name|| l_suffix,'REUSED');
13177                   --
13178                end if ;
13179                hr_utility.set_location( 'found record for update',10);
13180            --
13181          else
13182            --
13183            l_update := false;
13184            --
13185          end if;
13186        else
13187          --
13188          --UPD END
13189        if p_reuse_object_flag = 'Y' then
13190          if c_NOC_min_max_dates%found then
13191            -- cursor to find the object
13192            open c_find_NOC_in_target( l_min_esd,l_max_eed,
13193                                  p_target_business_group_id, nvl(l_no_othr_cvg_rt_id, -999)  ) ;
13194            fetch c_find_NOC_in_target into l_new_value ;
13195            if c_find_NOC_in_target%found then
13196              --
13197              --TEMPIK
13198              l_dt_rec_found :=   dt_api.check_min_max_dates
13199                  (p_base_table_name => 'BEN_NO_OTHR_CVG_RT_F',
13200                   p_base_key_column => 'NO_OTHR_CVG_RT_ID',
13201                   p_base_key_value  => l_new_value,
13202                   p_from_date       => l_min_esd,
13203                   p_to_date         => l_max_eed );
13204              if l_dt_rec_found THEN
13205              --END TEMPIK
13206              if r_NOC_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
13207                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'NO_OTHR_CVG_RT_ID'  then
13208                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'NO_OTHR_CVG_RT_ID' ;
13209                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_NOC_unique.information1 ;
13210                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
13211                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
13212                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_NOC_unique.table_route_id;
13213                 --
13214                 -- 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) ;
13215                 --
13216                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
13217              end if ;
13218              --
13219              l_object_found_in_target := true ;
13220              --TEMPIK
13221              end if; -- l_dt_rec_found
13222              --END TEMPIK
13223            end if;
13224            close c_find_NOC_in_target ;
13225          --
13226          end if;
13227        end if ;
13228        --
13229        end if;
13230        close c_NOC_min_max_dates ;
13231        if not l_object_found_in_target OR l_update   then
13232          --
13233          l_current_pk_id := r_NOC.information1;
13234          --
13235          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
13236          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
13237          --
13238          if l_current_pk_id =  l_prev_pk_id  then
13239            --
13240            l_first_rec := false ;
13241            --
13242          else
13243            --
13244            l_first_rec := true ;
13245            --
13246          end if ;
13247          --
13248 
13249          l_effective_date := r_NOC.information2;
13250          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
13251               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
13252            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
13253          end if;
13254 
13255          if l_first_rec and not l_update then
13256            -- Call Create routine.
13257            hr_utility.set_location(' BEN_NO_OTHR_CVG_RT_F CREATE_NO_OTHR_CVG_RT ',20);
13258            BEN_NO_OTHR_CVG_RT_API.CREATE_NO_OTHR_CVG_RT(
13259              --
13260              P_VALIDATE               => false
13261              ,P_EFFECTIVE_DATE        => l_effective_date
13262              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
13263              --
13264              ,P_COORD_BEN_NO_CVG_FLAG      => r_NOC.INFORMATION11
13265              ,P_NOC_ATTRIBUTE1      => r_NOC.INFORMATION111
13266              ,P_NOC_ATTRIBUTE10      => r_NOC.INFORMATION120
13267              ,P_NOC_ATTRIBUTE11      => r_NOC.INFORMATION121
13268              ,P_NOC_ATTRIBUTE12      => r_NOC.INFORMATION122
13269              ,P_NOC_ATTRIBUTE13      => r_NOC.INFORMATION123
13270              ,P_NOC_ATTRIBUTE14      => r_NOC.INFORMATION124
13271              ,P_NOC_ATTRIBUTE15      => r_NOC.INFORMATION125
13272              ,P_NOC_ATTRIBUTE16      => r_NOC.INFORMATION126
13273              ,P_NOC_ATTRIBUTE17      => r_NOC.INFORMATION127
13274              ,P_NOC_ATTRIBUTE18      => r_NOC.INFORMATION128
13275              ,P_NOC_ATTRIBUTE19      => r_NOC.INFORMATION129
13276              ,P_NOC_ATTRIBUTE2      => r_NOC.INFORMATION112
13277              ,P_NOC_ATTRIBUTE20      => r_NOC.INFORMATION130
13278              ,P_NOC_ATTRIBUTE21      => r_NOC.INFORMATION131
13279              ,P_NOC_ATTRIBUTE22      => r_NOC.INFORMATION132
13280              ,P_NOC_ATTRIBUTE23      => r_NOC.INFORMATION133
13281              ,P_NOC_ATTRIBUTE24      => r_NOC.INFORMATION134
13282              ,P_NOC_ATTRIBUTE25      => r_NOC.INFORMATION135
13283              ,P_NOC_ATTRIBUTE26      => r_NOC.INFORMATION136
13284              ,P_NOC_ATTRIBUTE27      => r_NOC.INFORMATION137
13285              ,P_NOC_ATTRIBUTE28      => r_NOC.INFORMATION138
13286              ,P_NOC_ATTRIBUTE29      => r_NOC.INFORMATION139
13287              ,P_NOC_ATTRIBUTE3      => r_NOC.INFORMATION113
13288              ,P_NOC_ATTRIBUTE30      => r_NOC.INFORMATION140
13289              ,P_NOC_ATTRIBUTE4      => r_NOC.INFORMATION114
13290              ,P_NOC_ATTRIBUTE5      => r_NOC.INFORMATION115
13291              ,P_NOC_ATTRIBUTE6      => r_NOC.INFORMATION116
13292              ,P_NOC_ATTRIBUTE7      => r_NOC.INFORMATION117
13293              ,P_NOC_ATTRIBUTE8      => r_NOC.INFORMATION118
13294              ,P_NOC_ATTRIBUTE9      => r_NOC.INFORMATION119
13295              ,P_NOC_ATTRIBUTE_CATEGORY      => r_NOC.INFORMATION110
13296              ,P_NO_OTHR_CVG_RT_ID      => l_no_othr_cvg_rt_id
13297              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
13298              --
13299              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
13300              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
13301              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
13302            );
13303            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
13304            -- Update all relevent cer records with new pk_id
13305            hr_utility.set_location('Before plsql table ',222);
13306            hr_utility.set_location('new_value id '||l_no_othr_cvg_rt_id,222);
13307            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'NO_OTHR_CVG_RT_ID' ;
13308            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_NOC.information1 ;
13309            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_NO_OTHR_CVG_RT_ID ;
13310            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
13311            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_NOC_unique.table_route_id;
13312            hr_utility.set_location('After plsql table ',222);
13313            --
13314            -- 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 ) ;
13315            --
13316            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
13317            --
13318          else
13319            --
13320            -- Call Update routine for the pk_id created in prev run .
13321            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
13322            --UPD START
13323            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
13324            --
13325            if l_update then
13326              --
13327              l_datetrack_mode := r_NOC.datetrack_mode ;
13328              --
13329              get_dt_modes(
13330                p_effective_date        => l_process_date,
13331                p_effective_end_date    => r_NOC.information3,
13332                p_effective_start_date  => r_NOC.information2,
13333                p_dml_operation         => r_NOC.dml_operation,
13334                p_datetrack_mode        => l_datetrack_mode );
13335            --    p_update                => l_update
13336              --
13337              l_effective_date := l_process_date;
13338              l_NO_OTHR_CVG_RT_ID   := r_NOC.information1;
13339              l_object_version_number := r_NOC.information265;
13340              --
13341            end if;
13342            --
13343            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
13344            --
13345            IF l_update OR l_dml_operation <> 'UPDATE' THEN
13346            --UPD END
13347            hr_utility.set_location(' BEN_NO_OTHR_CVG_RT_F UPDATE_NO_OTHR_CVG_RT ',30);
13348            BEN_NO_OTHR_CVG_RT_API.UPDATE_NO_OTHR_CVG_RT(
13349              --
13350              P_VALIDATE               => false
13351              ,P_EFFECTIVE_DATE        => l_effective_date
13352              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
13353              --
13354               ,P_COORD_BEN_NO_CVG_FLAG      => r_NOC.INFORMATION11
13355              ,P_NOC_ATTRIBUTE1      => r_NOC.INFORMATION111
13356              ,P_NOC_ATTRIBUTE10      => r_NOC.INFORMATION120
13357              ,P_NOC_ATTRIBUTE11      => r_NOC.INFORMATION121
13358              ,P_NOC_ATTRIBUTE12      => r_NOC.INFORMATION122
13359              ,P_NOC_ATTRIBUTE13      => r_NOC.INFORMATION123
13360              ,P_NOC_ATTRIBUTE14      => r_NOC.INFORMATION124
13361              ,P_NOC_ATTRIBUTE15      => r_NOC.INFORMATION125
13362              ,P_NOC_ATTRIBUTE16      => r_NOC.INFORMATION126
13363              ,P_NOC_ATTRIBUTE17      => r_NOC.INFORMATION127
13364              ,P_NOC_ATTRIBUTE18      => r_NOC.INFORMATION128
13365              ,P_NOC_ATTRIBUTE19      => r_NOC.INFORMATION129
13366              ,P_NOC_ATTRIBUTE2      => r_NOC.INFORMATION112
13367              ,P_NOC_ATTRIBUTE20      => r_NOC.INFORMATION130
13368              ,P_NOC_ATTRIBUTE21      => r_NOC.INFORMATION131
13369              ,P_NOC_ATTRIBUTE22      => r_NOC.INFORMATION132
13370              ,P_NOC_ATTRIBUTE23      => r_NOC.INFORMATION133
13371              ,P_NOC_ATTRIBUTE24      => r_NOC.INFORMATION134
13372              ,P_NOC_ATTRIBUTE25      => r_NOC.INFORMATION135
13373              ,P_NOC_ATTRIBUTE26      => r_NOC.INFORMATION136
13374              ,P_NOC_ATTRIBUTE27      => r_NOC.INFORMATION137
13375              ,P_NOC_ATTRIBUTE28      => r_NOC.INFORMATION138
13376              ,P_NOC_ATTRIBUTE29      => r_NOC.INFORMATION139
13377              ,P_NOC_ATTRIBUTE3      => r_NOC.INFORMATION113
13378              ,P_NOC_ATTRIBUTE30      => r_NOC.INFORMATION140
13379              ,P_NOC_ATTRIBUTE4      => r_NOC.INFORMATION114
13380              ,P_NOC_ATTRIBUTE5      => r_NOC.INFORMATION115
13381              ,P_NOC_ATTRIBUTE6      => r_NOC.INFORMATION116
13382              ,P_NOC_ATTRIBUTE7      => r_NOC.INFORMATION117
13383              ,P_NOC_ATTRIBUTE8      => r_NOC.INFORMATION118
13384              ,P_NOC_ATTRIBUTE9      => r_NOC.INFORMATION119
13385              ,P_NOC_ATTRIBUTE_CATEGORY      => r_NOC.INFORMATION110
13386              ,P_NO_OTHR_CVG_RT_ID      => l_no_othr_cvg_rt_id
13387              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
13388              --
13389              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
13390              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
13391              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
13392              ,P_DATETRACK_MODE        => l_datetrack_mode
13393            );
13394            --
13395            end if;
13396          end if;
13397          --
13398          -- Delete the row if it is end dated.
13399          --
13400          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
13401              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
13402              trunc(l_max_eed) = r_NOC.information3) then
13403              --
13404              BEN_NO_OTHR_CVG_RT_API.delete_NO_OTHR_CVG_RT(
13405                 --
13406                 p_validate                       => false
13407                 ,p_no_othr_cvg_rt_id                   => l_no_othr_cvg_rt_id
13408                 ,p_effective_start_date           => l_effective_start_date
13409                 ,p_effective_end_date             => l_effective_end_date
13410                 ,p_object_version_number          => l_object_version_number
13411                 ,p_effective_date                 => l_max_eed
13412                 ,p_datetrack_mode                 => hr_api.g_delete
13413                 --
13414                 );
13415                 --
13416          end if;
13417          --
13418          l_prev_pk_id := l_current_pk_id ;
13419          --
13420        end if;
13421        --
13422      end if;
13423      --
13424    end loop;
13425    --
13426  exception when others then
13427     --
13428     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'NOC',r_noc.information5 );
13429     --
13430  end create_NOC_rows;
13431 
13432    --
13433    ---------------------------------------------------------------
13434    ----------------------< create_OMR_rows >-----------------------
13435    ---------------------------------------------------------------
13436    --
13437    procedure create_OMR_rows
13438    (
13439          p_validate                       in  number     default 0
13440         ,p_copy_entity_txn_id             in  number
13441         ,p_effective_date                 in  date
13442         ,p_prefix_suffix_text             in  varchar2  default null
13443         ,p_reuse_object_flag              in  varchar2  default null
13444         ,p_target_business_group_id       in  varchar2  default null
13445         ,p_prefix_suffix_cd               in  varchar2  default null
13446    ) is
13447    --
13448    l_VRBL_RT_PRFL_ID  number;
13449    l_OPTD_MDCR_FLAG  varchar2(30);
13450    cursor c_unique_OMR(l_table_alias varchar2) is
13451    select distinct cpe.information1,
13452      cpe.information2,
13453      cpe.information3,
13454      cpe.table_route_id
13455    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
13456         pqh_table_route tr
13457    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
13458    and   cpe.table_route_id     = tr.table_route_id
13459    -- and   tr.where_clause        = l_BEN_OPTD_MDCR_RT_F
13460    and tr.table_alias = l_table_alias
13461    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
13462    order by information1, information2; --added for bug: 5151945
13463    --
13464    --
13465    cursor c_OMR_min_max_dates(c_table_route_id  number,
13466                 c_information1   Number) is
13467    select
13468      min(cpe.information2) min_esd,
13469      max(cpe.information3) min_eed
13470    from ben_copy_entity_results cpe
13471    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
13472    and   cpe.table_route_id     = c_table_route_id
13473    and   cpe.information1       = c_information1 ;
13474    --
13475    cursor c_OMR(c_table_route_id  number,
13476                 c_information1   number,
13477                 c_information2   Date,
13478                 c_information3   Date )  is
13479    select
13480      cpe.*
13481    from ben_copy_entity_results cpe
13482    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
13483    and   cpe.table_route_id     = c_table_route_id
13484    and   cpe.information1       = c_information1
13485    and   cpe.information2       = c_information2
13486    and   cpe.information3       = c_information3
13487    and rownum = 1 ;
13488    -- Date Track target record
13489    cursor c_find_OMR_in_target(
13490                                 c_effective_start_date    date,
13491                                 c_effective_end_date      date,
13492                                 c_business_group_id       number,
13493                                 c_new_pk_id               number) is
13494    select
13495      OMR.optd_mdcr_rt_id new_value
13496    from BEN_OPTD_MDCR_RT_F OMR
13497    where
13498    OMR.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
13499    OMR.OPTD_MDCR_FLAG    = l_OPTD_MDCR_FLAG and
13500    OMR.business_group_id  = c_business_group_id
13501    and   OMR.optd_mdcr_rt_id  <> c_new_pk_id
13502 --TEMPIK
13503    and c_effective_start_date between effective_start_date
13504                             and effective_end_date ;
13505 --END TEMPIK
13506 /*TEMPIK
13507    and exists ( select null
13508                 from BEN_OPTD_MDCR_RT_F OMR1
13509                 where
13510                 OMR1.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
13511                 OMR1.OPTD_MDCR_FLAG    = l_OPTD_MDCR_FLAG and
13512                 OMR1.business_group_id  = c_business_group_id
13513                 and   OMR1.effective_start_date <= c_effective_start_date )
13514    and exists ( select null
13515                 from BEN_OPTD_MDCR_RT_F OMR2
13516                 where
13517                 OMR2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
13518                 OMR2.OPTD_MDCR_FLAG    = l_OPTD_MDCR_FLAG and
13519                 OMR2.business_group_id  = c_business_group_id
13520                 and   OMR2.effective_end_date >= c_effective_end_date )
13521                 ;
13522 TEMPIK */
13523    --TEMPIK
13524    l_dt_rec_found            boolean ;
13525    --END TEMPIK
13526    --
13527    l_current_pk_id           number := null ;
13528    --UPD START
13529    --
13530    l_update                  boolean      := false ;
13531    l_datetrack_mode          varchar2(80) := hr_api.g_update;
13532    l_process_date            date;
13533    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
13534    --
13535    --UPD END
13536    l_prev_pk_id              number := null ;
13537    l_first_rec               boolean := true ;
13538    r_OMR                     c_OMR%rowtype;
13539    l_optd_mdcr_rt_id             number ;
13540    l_object_version_number   number ;
13541    l_effective_start_date    date ;
13542    l_effective_end_date      date ;
13543    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
13544    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
13545    l_new_value               number(15);
13546    l_object_found_in_target  boolean := false ;
13547    l_min_esd                 date;
13548    l_max_eed                 date;
13549    l_effective_date          date;
13550    --
13551  begin
13552    -- Initialization
13553    l_object_found_in_target := false ;
13554    -- End Initialization
13555    -- Derive the prefix - sufix
13556    if   p_prefix_suffix_cd = 'PREFIX' then
13557      l_prefix  := p_prefix_suffix_text ;
13558    elsif p_prefix_suffix_cd = 'SUFFIX' then
13559      l_suffix   := p_prefix_suffix_text ;
13560    else
13561      l_prefix := null ;
13562      l_suffix  := null ;
13563    end if ;
13564    -- End Prefix Sufix derivation
13565    for r_OMR_unique in c_unique_OMR('OMR') loop
13566 
13567      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
13568         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
13569          r_OMR_unique.information3 >=
13570                  ben_pd_copy_to_ben_one.g_copy_effective_date)
13571         ) then
13572        --
13573        hr_utility.set_location(' r_OMR_unique.table_route_id '||r_OMR_unique.table_route_id,10);
13574        hr_utility.set_location(' r_OMR_unique.information1 '||r_OMR_unique.information1,10);
13575        hr_utility.set_location( 'r_OMR_unique.information2 '||r_OMR_unique.information2,10);
13576        hr_utility.set_location( 'r_OMR_unique.information3 '||r_OMR_unique.information3,10);
13577        -- If reuse objects flag is 'Y' then check for the object in the target business group
13578        -- if found insert the record into PLSql table and exit the loop else try create the
13579        -- object in the target business group
13580        --
13581        l_object_found_in_target := false ;
13582        l_min_esd := null ;
13583        l_max_eed := null ;
13584        open c_OMR_min_max_dates(r_OMR_unique.table_route_id, r_OMR_unique.information1 ) ;
13585        fetch c_OMR_min_max_dates into l_min_esd,l_max_eed ;
13586        --
13587 
13588        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
13589             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
13590          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
13591        end if;
13592        l_min_esd := greatest(l_min_esd,r_OMR_unique.information2);
13593        open c_OMR(r_OMR_unique.table_route_id,
13594                 r_OMR_unique.information1,
13595                 r_OMR_unique.information2,
13596                 r_OMR_unique.information3 ) ;
13597        --
13598        fetch c_OMR into r_OMR ;
13599        --
13600        close c_OMR ;
13601        --
13602        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_OMR.information262,r_OMR_unique.dml_operation);
13603        l_OPTD_MDCR_FLAG := r_OMR.information11 ;
13604        --UPD START
13605        l_update := false;
13606        l_process_date := p_effective_date;
13607        l_dml_operation:= r_OMR_unique.dml_operation ;
13608        --
13609        if l_dml_operation = 'UPDATE' then
13610          --
13611          l_object_found_in_target := TRUE;
13612          --
13613          if l_process_date between r_OMR_unique.information2 and r_OMR_unique.information3 then
13614                l_update := true;
13615                if r_OMR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
13616                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'OPTD_MDCR_RT_ID'
13617                then
13618                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'OPTD_MDCR_RT_ID' ;
13619                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_OMR_unique.information1 ;
13620                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_OMR_unique.information1 ;
13621                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
13622                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_OMR_unique.table_route_id;
13623                   --
13624                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
13625                   --
13626                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
13627                   --
13628                   -- log_data('OMR',l_new_value,l_prefix || r_OMR_unique.name|| l_suffix,'REUSED');
13629                   --
13630                end if ;
13631                hr_utility.set_location( 'found record for update',10);
13632            --
13633          else
13634            --
13635            l_update := false;
13636            --
13637          end if;
13638        else
13639          --
13640          --UPD END
13641        if p_reuse_object_flag = 'Y' then
13642          if c_OMR_min_max_dates%found then
13643            -- cursor to find the object
13644            open c_find_OMR_in_target( l_min_esd,l_max_eed,
13645                                  p_target_business_group_id, nvl(l_optd_mdcr_rt_id, -999)  ) ;
13646            fetch c_find_OMR_in_target into l_new_value ;
13647            if c_find_OMR_in_target%found then
13648              --
13649              --TEMPIK
13650              l_dt_rec_found :=   dt_api.check_min_max_dates
13651                  (p_base_table_name => 'BEN_OPTD_MDCR_RT_F',
13652                   p_base_key_column => 'OPTD_MDCR_RT_ID',
13653                   p_base_key_value  => l_new_value,
13654                   p_from_date       => l_min_esd,
13655                   p_to_date         => l_max_eed );
13656              if l_dt_rec_found THEN
13657              --END TEMPIK
13658              if r_OMR_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
13659                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <>  'OPTD_MDCR_RT_ID'  then
13660                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'OPTD_MDCR_RT_ID' ;
13661                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_OMR_unique.information1 ;
13662                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := l_new_value ;
13663                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
13664                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_OMR_unique.table_route_id;
13665                 --
13666                 -- 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) ;
13667                 --
13668                 BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
13669              end if ;
13670              --
13671              l_object_found_in_target := true ;
13672              --TEMPIK
13673              end if; -- l_dt_rec_found
13674              --END TEMPIK
13675            end if;
13676            close c_find_OMR_in_target ;
13677          --
13678          end if;
13679        end if ;
13680        --
13681        end if;
13682        close c_OMR_min_max_dates ;
13683        if not l_object_found_in_target OR l_update   then
13684          --
13685          l_current_pk_id := r_OMR.information1;
13686          --
13687          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
13688          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
13689          --
13690          if l_current_pk_id =  l_prev_pk_id  then
13691            --
13692            l_first_rec := false ;
13693            --
13694          else
13695            --
13696            l_first_rec := true ;
13697            --
13698          end if ;
13699          --
13700 
13701          l_effective_date := r_OMR.information2;
13702          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
13703               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
13704            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
13705          end if;
13706 
13707          if l_first_rec and not l_update then
13708            -- Call Create routine.
13709            hr_utility.set_location(' BEN_OPTD_MDCR_RT_F CREATE_OPTD_MDCR_RT ',20);
13710            BEN_OPTD_MDCR_RT_API.CREATE_OPTD_MDCR_RT(
13711              --
13712              P_VALIDATE               => false
13713              ,P_EFFECTIVE_DATE        => l_effective_date
13714              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
13715              --
13716              ,P_EXLCD_FLAG      => r_OMR.INFORMATION12
13717              ,P_OMR_ATTRIBUTE1      => r_OMR.INFORMATION111
13718              ,P_OMR_ATTRIBUTE10      => r_OMR.INFORMATION120
13719              ,P_OMR_ATTRIBUTE11      => r_OMR.INFORMATION121
13720              ,P_OMR_ATTRIBUTE12      => r_OMR.INFORMATION122
13721              ,P_OMR_ATTRIBUTE13      => r_OMR.INFORMATION123
13722              ,P_OMR_ATTRIBUTE14      => r_OMR.INFORMATION124
13723              ,P_OMR_ATTRIBUTE15      => r_OMR.INFORMATION125
13724              ,P_OMR_ATTRIBUTE16      => r_OMR.INFORMATION126
13725              ,P_OMR_ATTRIBUTE17      => r_OMR.INFORMATION127
13726              ,P_OMR_ATTRIBUTE18      => r_OMR.INFORMATION128
13727              ,P_OMR_ATTRIBUTE19      => r_OMR.INFORMATION129
13728              ,P_OMR_ATTRIBUTE2      => r_OMR.INFORMATION112
13729              ,P_OMR_ATTRIBUTE20      => r_OMR.INFORMATION130
13730              ,P_OMR_ATTRIBUTE21      => r_OMR.INFORMATION131
13731              ,P_OMR_ATTRIBUTE22      => r_OMR.INFORMATION132
13732              ,P_OMR_ATTRIBUTE23      => r_OMR.INFORMATION133
13733              ,P_OMR_ATTRIBUTE24      => r_OMR.INFORMATION134
13734              ,P_OMR_ATTRIBUTE25      => r_OMR.INFORMATION135
13735              ,P_OMR_ATTRIBUTE26      => r_OMR.INFORMATION136
13736              ,P_OMR_ATTRIBUTE27      => r_OMR.INFORMATION137
13737              ,P_OMR_ATTRIBUTE28      => r_OMR.INFORMATION138
13738              ,P_OMR_ATTRIBUTE29      => r_OMR.INFORMATION139
13739              ,P_OMR_ATTRIBUTE3      => r_OMR.INFORMATION113
13740              ,P_OMR_ATTRIBUTE30      => r_OMR.INFORMATION140
13741              ,P_OMR_ATTRIBUTE4      => r_OMR.INFORMATION114
13742              ,P_OMR_ATTRIBUTE5      => r_OMR.INFORMATION115
13743              ,P_OMR_ATTRIBUTE6      => r_OMR.INFORMATION116
13744              ,P_OMR_ATTRIBUTE7      => r_OMR.INFORMATION117
13745              ,P_OMR_ATTRIBUTE8      => r_OMR.INFORMATION118
13746              ,P_OMR_ATTRIBUTE9      => r_OMR.INFORMATION119
13747              ,P_OMR_ATTRIBUTE_CATEGORY      => r_OMR.INFORMATION110
13748              ,P_OPTD_MDCR_FLAG      => r_OMR.INFORMATION11
13749              ,P_OPTD_MDCR_RT_ID      => l_optd_mdcr_rt_id
13750              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
13751              --
13752              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
13753              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
13754              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
13755            );
13756            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
13757            -- Update all relevent cer records with new pk_id
13758            hr_utility.set_location('Before plsql table ',222);
13759            hr_utility.set_location('new_value id '||l_optd_mdcr_rt_id,222);
13760            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column := 'OPTD_MDCR_RT_ID' ;
13761            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value    := r_OMR.information1 ;
13762            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value    := l_OPTD_MDCR_RT_ID ;
13763            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type  := 'COPIED';
13764            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_OMR_unique.table_route_id;
13765            hr_utility.set_location('After plsql table ',222);
13766            --
13767            -- 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 ) ;
13768            --
13769            BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
13770            --
13771          else
13772            --
13773            -- Call Update routine for the pk_id created in prev run .
13774            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
13775            --UPD START
13776            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
13777            --
13778            if l_update then
13779              --
13780              l_datetrack_mode := r_OMR.datetrack_mode ;
13781              --
13782              get_dt_modes(
13783                p_effective_date        => l_process_date,
13784                p_effective_end_date    => r_OMR.information3,
13785                p_effective_start_date  => r_OMR.information2,
13786                p_dml_operation         => r_OMR.dml_operation,
13787                p_datetrack_mode        => l_datetrack_mode );
13788            --    p_update                => l_update
13789              --
13790              l_effective_date := l_process_date;
13791              l_OPTD_MDCR_RT_ID   := r_OMR.information1;
13792              l_object_version_number := r_OMR.information265;
13793              --
13794            end if;
13795            --
13796            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
13797            --
13798            IF l_update OR l_dml_operation <> 'UPDATE' THEN
13799            --UPD END
13800            hr_utility.set_location(' BEN_OPTD_MDCR_RT_F UPDATE_OPTD_MDCR_RT ',30);
13801            BEN_OPTD_MDCR_RT_API.UPDATE_OPTD_MDCR_RT(
13802              --
13803              P_VALIDATE               => false
13804              ,P_EFFECTIVE_DATE        => l_effective_date
13805              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
13806              --
13807              ,P_EXLCD_FLAG      => r_OMR.INFORMATION12
13808              ,P_OMR_ATTRIBUTE1      => r_OMR.INFORMATION111
13809              ,P_OMR_ATTRIBUTE10      => r_OMR.INFORMATION120
13810              ,P_OMR_ATTRIBUTE11      => r_OMR.INFORMATION121
13811              ,P_OMR_ATTRIBUTE12      => r_OMR.INFORMATION122
13812              ,P_OMR_ATTRIBUTE13      => r_OMR.INFORMATION123
13813              ,P_OMR_ATTRIBUTE14      => r_OMR.INFORMATION124
13814              ,P_OMR_ATTRIBUTE15      => r_OMR.INFORMATION125
13815              ,P_OMR_ATTRIBUTE16      => r_OMR.INFORMATION126
13816              ,P_OMR_ATTRIBUTE17      => r_OMR.INFORMATION127
13817              ,P_OMR_ATTRIBUTE18      => r_OMR.INFORMATION128
13818              ,P_OMR_ATTRIBUTE19      => r_OMR.INFORMATION129
13819              ,P_OMR_ATTRIBUTE2      => r_OMR.INFORMATION112
13820              ,P_OMR_ATTRIBUTE20      => r_OMR.INFORMATION130
13821              ,P_OMR_ATTRIBUTE21      => r_OMR.INFORMATION131
13822              ,P_OMR_ATTRIBUTE22      => r_OMR.INFORMATION132
13823              ,P_OMR_ATTRIBUTE23      => r_OMR.INFORMATION133
13824              ,P_OMR_ATTRIBUTE24      => r_OMR.INFORMATION134
13825              ,P_OMR_ATTRIBUTE25      => r_OMR.INFORMATION135
13826              ,P_OMR_ATTRIBUTE26      => r_OMR.INFORMATION136
13827              ,P_OMR_ATTRIBUTE27      => r_OMR.INFORMATION137
13828              ,P_OMR_ATTRIBUTE28      => r_OMR.INFORMATION138
13829              ,P_OMR_ATTRIBUTE29      => r_OMR.INFORMATION139
13830              ,P_OMR_ATTRIBUTE3      => r_OMR.INFORMATION113
13831              ,P_OMR_ATTRIBUTE30      => r_OMR.INFORMATION140
13832              ,P_OMR_ATTRIBUTE4      => r_OMR.INFORMATION114
13833              ,P_OMR_ATTRIBUTE5      => r_OMR.INFORMATION115
13834              ,P_OMR_ATTRIBUTE6      => r_OMR.INFORMATION116
13835              ,P_OMR_ATTRIBUTE7      => r_OMR.INFORMATION117
13836              ,P_OMR_ATTRIBUTE8      => r_OMR.INFORMATION118
13837              ,P_OMR_ATTRIBUTE9      => r_OMR.INFORMATION119
13838              ,P_OMR_ATTRIBUTE_CATEGORY      => r_OMR.INFORMATION110
13839              ,P_OPTD_MDCR_FLAG      => r_OMR.INFORMATION11
13840              ,P_OPTD_MDCR_RT_ID      => l_optd_mdcr_rt_id
13841              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
13842              --
13843              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
13844              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
13845              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
13846              ,P_DATETRACK_MODE        => l_datetrack_mode
13847            );
13848            end if;
13849            --
13850          end if;
13851          --
13852          -- Delete the row if it is end dated.
13853          --
13854          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
13855              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
13856              trunc(l_max_eed) = r_OMR.information3) then
13857              --
13858              BEN_OPTD_MDCR_RT_API.delete_OPTD_MDCR_RT(
13859                 --
13860                 p_validate                       => false
13861                 ,p_optd_mdcr_rt_id                   => l_optd_mdcr_rt_id
13862                 ,p_effective_start_date           => l_effective_start_date
13863                 ,p_effective_end_date             => l_effective_end_date
13864                 ,p_object_version_number          => l_object_version_number
13865                 ,p_effective_date                 => l_max_eed
13866                 ,p_datetrack_mode                 => hr_api.g_delete
13867                 --
13868                 );
13869                 --
13870          end if;
13871          --
13872          l_prev_pk_id := l_current_pk_id ;
13873          --
13874        end if;
13875        --
13876      end if;
13877      --
13878    end loop;
13879    --
13880  exception when others then
13881     --
13882     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'OMR',r_omr.information5 );
13883     --
13884  end create_OMR_rows;
13885 
13886    ---------------------------------------------------------------
13887    ----------------------< create_EPM_rows >-----------------------
13888    ---------------------------------------------------------------
13889    --
13890    procedure create_EPM_rows
13891    (
13892          p_validate                       in  number     default 0
13893         ,p_copy_entity_txn_id             in  number
13894         ,p_effective_date                 in  date
13895         ,p_prefix_suffix_text             in  varchar2  default null
13896         ,p_reuse_object_flag              in  varchar2  default null
13897         ,p_target_business_group_id       in  varchar2  default null
13898         ,p_prefix_suffix_cd               in  varchar2  default null
13899    ) is
13900    --
13901    l_PGM_ID  number;
13902    l_VRBL_RT_PRFL_ID  number;
13903    cursor c_unique_EPM(l_table_alias varchar2) is
13904    select distinct cpe.information1,
13905      cpe.information2,
13906      cpe.information3,
13907      cpe.table_route_id
13908    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
13909         pqh_table_route tr
13910    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
13911    and   cpe.table_route_id     = tr.table_route_id
13912    -- and   tr.where_clause        = l_BEN_ENRLD_ANTHR_PGM_RT_F
13913    and tr.table_alias = l_table_alias
13914    and   cpe.number_of_copies   = 1 -- ADDITION
13915    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
13916    order by information1, information2; --added for bug: 5151945
13917    --
13918    --
13919    cursor c_EPM_min_max_dates(c_table_route_id  number,
13920                 c_information1   Number) is
13921    select
13922      min(cpe.information2) min_esd,
13923      max(cpe.information3) min_eed
13924    from ben_copy_entity_results cpe
13925    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
13926    and   cpe.table_route_id     = c_table_route_id
13927    and   cpe.information1       = c_information1 ;
13928    --
13929    cursor c_EPM(c_table_route_id  number,
13930                 c_information1   number,
13931                 c_information2   Date,
13932                 c_information3   Date)  is
13933    select
13934      cpe.*
13935    from ben_copy_entity_results cpe
13936    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
13937    and   cpe.table_route_id     = c_table_route_id
13938    and   cpe.information1       = c_information1
13939    and   cpe.information2       = c_information2
13940    and   cpe.information3       = c_information3
13941    and rownum = 1 ;
13942    -- Date Track target record
13943    cursor c_find_EPM_in_target(
13944                                 c_effective_start_date    date,
13945                                 c_effective_end_date      date,
13946                                 c_business_group_id       number,
13947                                 c_new_pk_id               number) is
13948    select
13949      EPM.enrld_anthr_pgm_rt_id new_value
13950    from BEN_ENRLD_ANTHR_PGM_RT_F EPM
13951    where
13952    EPM.PGM_ID     = l_PGM_ID  and
13953    EPM.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
13954    EPM.business_group_id  = c_business_group_id
13955    and   EPM.enrld_anthr_pgm_rt_id  <> c_new_pk_id
13956 --TEMPIK
13957    and c_effective_start_date between effective_start_date
13958                             and effective_end_date ;
13959 --END TEMPIK
13960 /*TEMPIK
13961    and exists ( select null
13962                 from BEN_ENRLD_ANTHR_PGM_RT_F EPM1
13963                 where
13964                 EPM1.PGM_ID     = l_PGM_ID  and
13965                 EPM1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
13966                 EPM1.business_group_id  = c_business_group_id
13967                 and   EPM1.effective_start_date <= c_effective_start_date )
13968    and exists ( select null
13969                 from BEN_ENRLD_ANTHR_PGM_RT_F EPM2
13970                 where
13971                 EPM2.PGM_ID     = l_PGM_ID  and
13972                 EPM2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
13973                 EPM2.business_group_id  = c_business_group_id
13974                 and   EPM2.effective_end_date >= c_effective_end_date )
13975                 ;
13976 TEMPIK */
13977    --TEMPIK
13978    l_dt_rec_found            boolean ;
13979    --END TEMPIK
13980    --
13981    l_current_pk_id           number := null ;
13982    --UPD START
13983    --
13984    l_update                  boolean      := false ;
13985    l_datetrack_mode          varchar2(80) := hr_api.g_update;
13986    l_process_date            date;
13987    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
13988    --
13989    --UPD END
13990    l_prev_pk_id              number := null ;
13991    l_first_rec               boolean := true ;
13992    r_EPM                     c_EPM%rowtype;
13993    l_enrld_anthr_pgm_rt_id             number ;
13994    l_object_version_number   number ;
13995    l_effective_start_date    date ;
13996    l_effective_end_date      date ;
13997    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
13998    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
13999    l_new_value               number(15);
14000    l_object_found_in_target  boolean := false ;
14001    l_min_esd                 date;
14002    l_max_eed                 date;
14003    l_effective_date          date;
14004    --
14005  begin
14006    -- Initialization
14007    l_object_found_in_target := false ;
14008    -- End Initialization
14009    -- Derive the prefix - sufix
14010    if   p_prefix_suffix_cd = 'PREFIX' then
14011      l_prefix  := p_prefix_suffix_text ;
14012    elsif p_prefix_suffix_cd = 'SUFFIX' then
14013      l_suffix   := p_prefix_suffix_text ;
14014    else
14015      l_prefix := null ;
14016      l_suffix  := null ;
14017    end if ;
14018    -- End Prefix Sufix derivation
14019    for r_EPM_unique in c_unique_EPM('EPM') loop
14020 
14021      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
14022         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
14023          r_EPM_unique.information3 >=
14024                  ben_pd_copy_to_ben_one.g_copy_effective_date)
14025         ) then
14026        --
14027        hr_utility.set_location(' r_EPM_unique.table_route_id '||r_EPM_unique.table_route_id,10);
14028        hr_utility.set_location(' r_EPM_unique.information1 '||r_EPM_unique.information1,10);
14029        hr_utility.set_location( 'r_EPM_unique.information2 '||r_EPM_unique.information2,10);
14030        hr_utility.set_location( 'r_EPM_unique.information3 '||r_EPM_unique.information3,10);
14031        -- If reuse objects flag is 'Y' then check for the object in the target business group
14032        -- if found insert the record into PLSql table and exit the loop else try create the
14033        -- object in the target business group
14034        --
14035        l_object_found_in_target := false ;
14036        l_min_esd := null ;
14037        l_max_eed := null ;
14038        open c_EPM_min_max_dates(r_EPM_unique.table_route_id, r_EPM_unique.information1 ) ;
14039        fetch c_EPM_min_max_dates into l_min_esd,l_max_eed ;
14040        --
14041 
14042        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
14043             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
14044          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
14045        end if;
14046        l_min_esd := greatest(l_min_esd,r_EPM_unique.information2);
14047        open c_EPM(r_EPM_unique.table_route_id,
14048                 r_EPM_unique.information1,
14049                 r_EPM_unique.information2,
14050                 r_EPM_unique.information3 ) ;
14051        --
14052        fetch c_EPM into r_EPM ;
14053        --
14054        close c_EPM ;
14055        --
14056        -- Only For Use by Create Wizard - Same Business Group
14057        l_PGM_ID := NVL(get_fk('PGM_ID', r_EPM.information260,r_EPM_unique.dml_operation),
14058                        r_EPM.information260);
14059 
14060        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_EPM.information262,r_EPM_unique.dml_operation);
14061        --UPD START
14062        l_update := false;
14063        l_process_date := p_effective_date;
14064        l_dml_operation:= r_EPM_unique.dml_operation ;
14065        --
14066        if l_dml_operation = 'UPDATE' then
14067          --
14068          l_object_found_in_target := TRUE;
14069          --
14070          if l_process_date between r_EPM_unique.information2 and r_EPM_unique.information3 then
14071                l_update := true;
14072                if r_EPM_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
14073                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ENRLD_ANTHR_PGM_RT_ID'
14074                then
14075                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ENRLD_ANTHR_PGM_RT_ID' ;
14076                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_EPM_unique.information1 ;
14077                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_EPM_unique.information1 ;
14078                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
14079                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_EPM_unique.table_route_id;
14080                   --
14081                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
14082                   --
14083                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
14084                   --
14085                   -- log_data('EPM',l_new_value,l_prefix || r_EPM_unique.name|| l_suffix,'REUSED');
14086                   --
14087                end if ;
14088                hr_utility.set_location( 'found record for update',10);
14089            --
14090          else
14091            --
14092            l_update := false;
14093            --
14094          end if;
14095        else
14096          --
14097          --UPD END
14098        if p_reuse_object_flag = 'Y' then
14099          if c_EPM_min_max_dates%found then
14100            -- cursor to find the object
14101            open c_find_EPM_in_target( l_min_esd,l_max_eed,
14102                                  p_target_business_group_id, nvl(l_enrld_anthr_pgm_rt_id, -999)  ) ;
14103            fetch c_find_EPM_in_target into l_new_value ;
14104            if c_find_EPM_in_target%found then
14105              --
14106              --TEMPIK
14107              l_dt_rec_found :=   dt_api.check_min_max_dates
14108                  (p_base_table_name => 'BEN_ENRLD_ANTHR_PGM_RT_F',
14109                   p_base_key_column => 'ENRLD_ANTHR_PGM_RT_ID',
14110                   p_base_key_value  => l_new_value,
14111                   p_from_date       => l_min_esd,
14112                   p_to_date         => l_max_eed );
14113              if l_dt_rec_found THEN
14114              --END TEMPIK
14115              if r_EPM_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
14116                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'ENRLD_ANTHR_PGM_RT_ID'  then
14117                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'ENRLD_ANTHR_PGM_RT_ID' ;
14118                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_EPM_unique.information1 ;
14119                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
14120                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
14121                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_EPM_unique.table_route_id;
14122                 --
14123                 -- 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) ;
14124                 --
14125                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
14126              end if ;
14127              --
14128              l_object_found_in_target := true ;
14129              --TEMPIK
14130              end if; -- l_dt_rec_found
14131              --END TEMPIK
14132            end if;
14133            close c_find_EPM_in_target ;
14134          --
14135          end if;
14136        end if ;
14137        --
14138        end if;
14139        close c_EPM_min_max_dates ;
14140        if not l_object_found_in_target OR l_update   then
14141          --
14142          l_current_pk_id := r_EPM.information1;
14143          --
14144          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
14145          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
14146          --
14147          if l_current_pk_id =  l_prev_pk_id  then
14148            --
14149            l_first_rec := false ;
14150            --
14151          else
14152            --
14153            l_first_rec := true ;
14154            --
14155          end if ;
14156          --
14157 
14158          l_effective_date := r_EPM.information2;
14159          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
14160               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
14161            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
14162          end if;
14163 
14164          if l_first_rec and not l_update then
14165            -- Call Create routine.
14166            hr_utility.set_location(' BEN_ENRLD_ANTHR_PGM_RT_F CREATE_ENRLD_ANTHR_PGM_RT ',20);
14167            BEN_ENRLD_ANTHR_PGM_RT_API.CREATE_ENRLD_ANTHR_PGM_RT(
14168              --
14169              P_VALIDATE               => false
14170              ,P_EFFECTIVE_DATE        => l_effective_date
14171              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
14172              --
14173              ,P_ENRLD_ANTHR_PGM_RT_ID      => l_enrld_anthr_pgm_rt_id
14174              ,P_ENRL_DET_DT_CD      => r_EPM.INFORMATION12
14175              ,P_EPM_ATTRIBUTE1      => r_EPM.INFORMATION111
14176              ,P_EPM_ATTRIBUTE10      => r_EPM.INFORMATION120
14177              ,P_EPM_ATTRIBUTE11      => r_EPM.INFORMATION121
14178              ,P_EPM_ATTRIBUTE12      => r_EPM.INFORMATION122
14179              ,P_EPM_ATTRIBUTE13      => r_EPM.INFORMATION123
14180              ,P_EPM_ATTRIBUTE14      => r_EPM.INFORMATION124
14181              ,P_EPM_ATTRIBUTE15      => r_EPM.INFORMATION125
14182              ,P_EPM_ATTRIBUTE16      => r_EPM.INFORMATION126
14183              ,P_EPM_ATTRIBUTE17      => r_EPM.INFORMATION127
14184              ,P_EPM_ATTRIBUTE18      => r_EPM.INFORMATION128
14185              ,P_EPM_ATTRIBUTE19      => r_EPM.INFORMATION129
14186              ,P_EPM_ATTRIBUTE2      => r_EPM.INFORMATION112
14187              ,P_EPM_ATTRIBUTE20      => r_EPM.INFORMATION130
14188              ,P_EPM_ATTRIBUTE21      => r_EPM.INFORMATION131
14189              ,P_EPM_ATTRIBUTE22      => r_EPM.INFORMATION132
14190              ,P_EPM_ATTRIBUTE23      => r_EPM.INFORMATION133
14191              ,P_EPM_ATTRIBUTE24      => r_EPM.INFORMATION134
14192              ,P_EPM_ATTRIBUTE25      => r_EPM.INFORMATION135
14193              ,P_EPM_ATTRIBUTE26      => r_EPM.INFORMATION136
14194              ,P_EPM_ATTRIBUTE27      => r_EPM.INFORMATION137
14195              ,P_EPM_ATTRIBUTE28      => r_EPM.INFORMATION138
14196              ,P_EPM_ATTRIBUTE29      => r_EPM.INFORMATION139
14197              ,P_EPM_ATTRIBUTE3      => r_EPM.INFORMATION113
14198              ,P_EPM_ATTRIBUTE30      => r_EPM.INFORMATION140
14199              ,P_EPM_ATTRIBUTE4      => r_EPM.INFORMATION114
14200              ,P_EPM_ATTRIBUTE5      => r_EPM.INFORMATION115
14201              ,P_EPM_ATTRIBUTE6      => r_EPM.INFORMATION116
14202              ,P_EPM_ATTRIBUTE7      => r_EPM.INFORMATION117
14203              ,P_EPM_ATTRIBUTE8      => r_EPM.INFORMATION118
14204              ,P_EPM_ATTRIBUTE9      => r_EPM.INFORMATION119
14205              ,P_EPM_ATTRIBUTE_CATEGORY      => r_EPM.INFORMATION110
14206              ,P_EXCLD_FLAG      => r_EPM.INFORMATION11
14207              ,P_ORDR_NUM      => r_EPM.INFORMATION257
14208              ,P_PGM_ID      => l_PGM_ID
14209              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
14210              --
14211              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
14212              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
14213              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
14214            );
14215            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
14216            -- Update all relevent cer records with new pk_id
14217            hr_utility.set_location('Before plsql table ',222);
14218            hr_utility.set_location('new_value id '||l_enrld_anthr_pgm_rt_id,222);
14219            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'ENRLD_ANTHR_PGM_RT_ID' ;
14220            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_EPM.information1 ;
14221            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_ENRLD_ANTHR_PGM_RT_ID ;
14222            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
14223            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_EPM_unique.table_route_id;
14224            hr_utility.set_location('After plsql table ',222);
14225            --
14226            -- 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 ) ;
14227            --
14228            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
14229            --
14230          else
14231            --
14232            -- Call Update routine for the pk_id created in prev run .
14233            --UPD START
14234            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
14235            --
14236            if l_update then
14237              --
14238              l_datetrack_mode := r_EPM.datetrack_mode ;
14239              --
14240              get_dt_modes(
14241                p_effective_date        => l_process_date,
14242                p_effective_end_date    => r_EPM.information3,
14243                p_effective_start_date  => r_EPM.information2,
14244                p_dml_operation         => r_EPM.dml_operation,
14245                p_datetrack_mode        => l_datetrack_mode );
14246            --    p_update                => l_update
14247              --
14248              l_effective_date := l_process_date;
14249              l_ENRLD_ANTHR_PGM_RT_ID   := r_EPM.information1;
14250              l_object_version_number := r_EPM.information265;
14251              --
14252            end if;
14253            --
14254            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
14255            --
14256            IF l_update OR l_dml_operation <> 'UPDATE' THEN
14257            --UPD END
14258            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
14259            hr_utility.set_location(' BEN_ENRLD_ANTHR_PGM_RT_F UPDATE_ENRLD_ANTHR_PGM_RT ',30);
14260            BEN_ENRLD_ANTHR_PGM_RT_API.UPDATE_ENRLD_ANTHR_PGM_RT(
14261              --
14262              P_VALIDATE               => false
14263              ,P_EFFECTIVE_DATE        => l_effective_date
14264              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
14265              --
14266              ,P_ENRLD_ANTHR_PGM_RT_ID      => l_enrld_anthr_pgm_rt_id
14267              ,P_ENRL_DET_DT_CD      => r_EPM.INFORMATION12
14268              ,P_EPM_ATTRIBUTE1      => r_EPM.INFORMATION111
14269              ,P_EPM_ATTRIBUTE10      => r_EPM.INFORMATION120
14270              ,P_EPM_ATTRIBUTE11      => r_EPM.INFORMATION121
14271              ,P_EPM_ATTRIBUTE12      => r_EPM.INFORMATION122
14272              ,P_EPM_ATTRIBUTE13      => r_EPM.INFORMATION123
14273              ,P_EPM_ATTRIBUTE14      => r_EPM.INFORMATION124
14274              ,P_EPM_ATTRIBUTE15      => r_EPM.INFORMATION125
14275              ,P_EPM_ATTRIBUTE16      => r_EPM.INFORMATION126
14276              ,P_EPM_ATTRIBUTE17      => r_EPM.INFORMATION127
14277              ,P_EPM_ATTRIBUTE18      => r_EPM.INFORMATION128
14278              ,P_EPM_ATTRIBUTE19      => r_EPM.INFORMATION129
14279              ,P_EPM_ATTRIBUTE2      => r_EPM.INFORMATION112
14280              ,P_EPM_ATTRIBUTE20      => r_EPM.INFORMATION130
14281              ,P_EPM_ATTRIBUTE21      => r_EPM.INFORMATION131
14282              ,P_EPM_ATTRIBUTE22      => r_EPM.INFORMATION132
14283              ,P_EPM_ATTRIBUTE23      => r_EPM.INFORMATION133
14284              ,P_EPM_ATTRIBUTE24      => r_EPM.INFORMATION134
14285              ,P_EPM_ATTRIBUTE25      => r_EPM.INFORMATION135
14286              ,P_EPM_ATTRIBUTE26      => r_EPM.INFORMATION136
14287              ,P_EPM_ATTRIBUTE27      => r_EPM.INFORMATION137
14288              ,P_EPM_ATTRIBUTE28      => r_EPM.INFORMATION138
14289              ,P_EPM_ATTRIBUTE29      => r_EPM.INFORMATION139
14290              ,P_EPM_ATTRIBUTE3      => r_EPM.INFORMATION113
14291              ,P_EPM_ATTRIBUTE30      => r_EPM.INFORMATION140
14292              ,P_EPM_ATTRIBUTE4      => r_EPM.INFORMATION114
14293              ,P_EPM_ATTRIBUTE5      => r_EPM.INFORMATION115
14294              ,P_EPM_ATTRIBUTE6      => r_EPM.INFORMATION116
14295              ,P_EPM_ATTRIBUTE7      => r_EPM.INFORMATION117
14296              ,P_EPM_ATTRIBUTE8      => r_EPM.INFORMATION118
14297              ,P_EPM_ATTRIBUTE9      => r_EPM.INFORMATION119
14298              ,P_EPM_ATTRIBUTE_CATEGORY      => r_EPM.INFORMATION110
14299              ,P_EXCLD_FLAG      => r_EPM.INFORMATION11
14300              ,P_ORDR_NUM      => r_EPM.INFORMATION257
14301              ,P_PGM_ID      => l_PGM_ID
14302              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
14303              --
14304              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
14305              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
14306              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
14307              ,P_DATETRACK_MODE        => l_datetrack_mode
14308            );
14309            --
14310            end if;
14311          end if;
14312          --
14313          -- Delete the row if it is end dated.
14314          --
14315          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
14316              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
14317              trunc(l_max_eed) = r_EPM.information3) then
14318              --
14319              BEN_ENRLD_ANTHR_PGM_RT_API.delete_ENRLD_ANTHR_PGM_RT(
14320                 --
14321                 p_validate                        => false
14322                 ,p_enrld_anthr_pgm_rt_id          => l_enrld_anthr_pgm_rt_id
14323                 ,p_effective_start_date           => l_effective_start_date
14324                 ,p_effective_end_date             => l_effective_end_date
14325                 ,p_object_version_number          => l_object_version_number
14326                 ,p_effective_date                 => l_max_eed
14327                 ,p_datetrack_mode                 => hr_api.g_delete
14328                 --
14329                 );
14330                 --
14331          end if;
14332          --
14333          l_prev_pk_id := l_current_pk_id ;
14334          --
14335        end if;
14336        --
14337      end if;
14338      --
14339    end loop;
14340    --
14341  exception when others then
14342     --
14343     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'EPM',r_epm.information5 );
14344     --
14345  end create_EPM_rows;
14346 
14347    ---------------------------------------------------------------
14348    ----------------------< create_ENT_rows >-----------------------
14349    ---------------------------------------------------------------
14350    --
14351    procedure create_ENT_rows
14352    (
14353          p_validate                       in  number     default 0
14354         ,p_copy_entity_txn_id             in  number
14355         ,p_effective_date                 in  date
14356         ,p_prefix_suffix_text             in  varchar2  default null
14357         ,p_reuse_object_flag              in  varchar2  default null
14358         ,p_target_business_group_id       in  varchar2  default null
14359         ,p_prefix_suffix_cd               in  varchar2  default null
14360    ) is
14361    --
14362    l_PTIP_ID  number;
14363    l_VRBL_RT_PRFL_ID  number;
14364    cursor c_unique_ENT(l_table_alias varchar2) is
14365    select distinct cpe.information1,
14366      cpe.information2,
14367      cpe.information3,
14368      cpe.table_route_id
14369    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
14370         pqh_table_route tr
14371    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
14372    and   cpe.table_route_id     = tr.table_route_id
14373    -- and   tr.where_clause        = l_BEN_ENRLD_ANTHR_PTIP_RT_F
14374    and tr.table_alias = l_table_alias
14375    and   cpe.number_of_copies   = 1 -- ADDITION
14376    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
14377    order by information1, information2; --added for bug: 5151945
14378    --
14379    --
14380    cursor c_ENT_min_max_dates(c_table_route_id  number,
14381                 c_information1   Number) is
14382    select
14383      min(cpe.information2) min_esd,
14384      max(cpe.information3) min_eed
14385    from ben_copy_entity_results cpe
14386    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
14387    and   cpe.table_route_id     = c_table_route_id
14388    and   cpe.information1       = c_information1 ;
14389    --
14390    cursor c_ENT(c_table_route_id  number,
14391                 c_information1   number,
14392                 c_information2   Date,
14393                 c_information3   Date)  is
14394    select
14395      cpe.*
14396    from ben_copy_entity_results cpe
14397    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
14398    and   cpe.table_route_id     = c_table_route_id
14399    and   cpe.information1       = c_information1
14400    and   cpe.information2       = c_information2
14401    and   cpe.information3       = c_information3
14402    and rownum = 1 ;
14403    -- Date Track target record
14404    cursor c_find_ENT_in_target(
14405                                 c_effective_start_date    date,
14406                                 c_effective_end_date      date,
14407                                 c_business_group_id       number,
14408                                 c_new_pk_id               number) is
14409    select
14410      ENT.enrld_anthr_ptip_rt_id new_value
14411    from BEN_ENRLD_ANTHR_PTIP_RT_F ENT
14412    where
14413    ENT.PTIP_ID     = l_PTIP_ID  and
14414    ENT.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
14415    ENT.business_group_id  = c_business_group_id
14416    and   ENT.enrld_anthr_ptip_rt_id  <> c_new_pk_id
14417 --TEMPIK
14418    and c_effective_start_date between effective_start_date
14419                             and effective_end_date ;
14420 --END TEMPIK
14421 /*TEMPIK
14422    and exists ( select null
14423                 from BEN_ENRLD_ANTHR_PTIP_RT_F ENT1
14424                 where
14425                 ENT1.PTIP_ID     = l_PTIP_ID  and
14426                 ENT1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
14427                 ENT1.business_group_id  = c_business_group_id
14428                 and   ENT1.effective_start_date <= c_effective_start_date )
14429    and exists ( select null
14430                 from BEN_ENRLD_ANTHR_PTIP_RT_F ENT2
14431                 where
14432                 ENT2.PTIP_ID     = l_PTIP_ID  and
14433                 ENT2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
14434                 ENT2.business_group_id  = c_business_group_id
14435                 and   ENT2.effective_end_date >= c_effective_end_date )
14436                 ;
14437 TEMPIK */
14438    --TEMPIK
14439    l_dt_rec_found            boolean ;
14440    --END TEMPIK
14441    --
14442    l_current_pk_id           number := null ;
14443    --UPD START
14444    --
14445    l_update                  boolean      := false ;
14446    l_datetrack_mode          varchar2(80) := hr_api.g_update;
14447    l_process_date            date;
14448    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
14449    --
14450    --UPD END
14451    l_prev_pk_id              number := null ;
14452    l_first_rec               boolean := true ;
14453    r_ENT                     c_ENT%rowtype;
14454    l_enrld_anthr_ptip_rt_id             number ;
14455    l_object_version_number   number ;
14456    l_effective_start_date    date ;
14457    l_effective_end_date      date ;
14458    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
14459    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
14460    l_new_value               number(15);
14461    l_object_found_in_target  boolean := false ;
14462    l_min_esd                 date;
14463    l_max_eed                 date;
14464    l_effective_date          date;
14465    --
14466  begin
14467    -- Initialization
14468    l_object_found_in_target := false ;
14469    -- End Initialization
14470    -- Derive the prefix - sufix
14471    if   p_prefix_suffix_cd = 'PREFIX' then
14472      l_prefix  := p_prefix_suffix_text ;
14473    elsif p_prefix_suffix_cd = 'SUFFIX' then
14474      l_suffix   := p_prefix_suffix_text ;
14475    else
14476      l_prefix := null ;
14477      l_suffix  := null ;
14478    end if ;
14479    -- End Prefix Sufix derivation
14480    for r_ENT_unique in c_unique_ENT('ENT') loop
14481 
14482      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
14483         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
14484          r_ENT_unique.information3 >=
14485                  ben_pd_copy_to_ben_one.g_copy_effective_date)
14486         ) then
14487        --
14488        hr_utility.set_location(' r_ENT_unique.table_route_id '||r_ENT_unique.table_route_id,10);
14489        hr_utility.set_location(' r_ENT_unique.information1 '||r_ENT_unique.information1,10);
14490        hr_utility.set_location( 'r_ENT_unique.information2 '||r_ENT_unique.information2,10);
14491        hr_utility.set_location( 'r_ENT_unique.information3 '||r_ENT_unique.information3,10);
14492        -- If reuse objects flag is 'Y' then check for the object in the target business group
14493        -- if found insert the record into PLSql table and exit the loop else try create the
14494        -- object in the target business group
14495        --
14496        l_object_found_in_target := false ;
14497        l_min_esd := null ;
14498        l_max_eed := null ;
14499        open c_ENT_min_max_dates(r_ENT_unique.table_route_id, r_ENT_unique.information1 ) ;
14500        fetch c_ENT_min_max_dates into l_min_esd,l_max_eed ;
14501        --
14502 
14503        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
14504             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
14505          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
14506        end if;
14507        l_min_esd := greatest(l_min_esd,r_ENT_unique.information2);
14508        open c_ENT(r_ENT_unique.table_route_id,
14509                 r_ENT_unique.information1,
14510                 r_ENT_unique.information2,
14511                 r_ENT_unique.information3 ) ;
14512        --
14513        fetch c_ENT into r_ENT ;
14514        --
14515        close c_ENT ;
14516        --
14517        -- Only For Use by Create Wizard - Same Business Group
14518        l_PTIP_ID := NVL(get_fk('PTIP_ID', r_ENT.information259,r_ENT_unique.dml_operation),
14519                         r_ENT.information259);
14520 
14521        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_ENT.information262,r_ENT_unique.dml_operation);
14522        --UPD START
14523        l_update := false;
14524        l_process_date := p_effective_date;
14525        l_dml_operation:= r_ENT_unique.dml_operation ;
14526        --
14527        if l_dml_operation = 'UPDATE' then
14528          --
14529          l_object_found_in_target := TRUE;
14530          --
14531          if l_process_date between r_ENT_unique.information2 and r_ENT_unique.information3 then
14532                l_update := true;
14533                if r_ENT_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
14534                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ENRLD_ANTHR_PTIP_RT_ID'
14535                then
14536                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ENRLD_ANTHR_PTIP_RT_ID' ;
14537                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_ENT_unique.information1 ;
14538                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_ENT_unique.information1 ;
14539                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
14540                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_ENT_unique.table_route_id;
14541                   --
14542                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
14543                   --
14544                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
14545                   --
14546                   -- log_data('ENT',l_new_value,l_prefix || r_ENT_unique.name|| l_suffix,'REUSED');
14547                   --
14548                end if ;
14549                hr_utility.set_location( 'found record for update',10);
14550            --
14551          else
14552            --
14553            l_update := false;
14554            --
14555          end if;
14556        else
14557          --
14558          --UPD END
14559        if p_reuse_object_flag = 'Y' then
14560          if c_ENT_min_max_dates%found then
14561            -- cursor to find the object
14562            open c_find_ENT_in_target( l_min_esd,l_max_eed,
14563                                  p_target_business_group_id, nvl(l_enrld_anthr_ptip_rt_id, -999)  ) ;
14564            fetch c_find_ENT_in_target into l_new_value ;
14565            if c_find_ENT_in_target%found then
14566              --
14567              --TEMPIK
14568              l_dt_rec_found :=   dt_api.check_min_max_dates
14569                  (p_base_table_name => 'BEN_ENRLD_ANTHR_PTIP_RT_F',
14570                   p_base_key_column => 'ENRLD_ANTHR_PTIP_RT_ID',
14571                   p_base_key_value  => l_new_value,
14572                   p_from_date       => l_min_esd,
14573                   p_to_date         => l_max_eed );
14574              if l_dt_rec_found THEN
14575              --END TEMPIK
14576              if r_ENT_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
14577                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'ENRLD_ANTHR_PTIP_RT_ID'  then
14578                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'ENRLD_ANTHR_PTIP_RT_ID' ;
14579                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_ENT_unique.information1 ;
14580                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
14581                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
14582                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_ENT_unique.table_route_id;
14583                 --
14584                 -- 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) ;
14585                 --
14586                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
14587              end if ;
14588              --
14589              l_object_found_in_target := true ;
14590              --TEMPIK
14591              end if; -- l_dt_rec_found
14592              --END TEMPIK
14593            end if;
14594            close c_find_ENT_in_target ;
14595          --
14596          end if;
14597        end if ;
14598        --
14599        end if;
14600        close c_ENT_min_max_dates ;
14601        if not l_object_found_in_target OR l_update   then
14602          --
14603          l_current_pk_id := r_ENT.information1;
14604          --
14605          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
14606          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
14607          --
14608          if l_current_pk_id =  l_prev_pk_id  then
14609            --
14610            l_first_rec := false ;
14611            --
14612          else
14613            --
14614            l_first_rec := true ;
14615            --
14616          end if ;
14617          --
14618 
14619          l_effective_date := r_ENT.information2;
14620          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
14621               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
14622            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
14623          end if;
14624 
14625          if l_first_rec and not l_update then
14626            -- Call Create routine.
14627            hr_utility.set_location(' BEN_ENRLD_ANTHR_PTIP_RT_F CREATE_ENRLD_ANTHR_PTIP_RT ',20);
14628            BEN_ENRLD_ANTHR_PTIP_RT_API.CREATE_ENRLD_ANTHR_PTIP_RT(
14629              --
14630              P_VALIDATE               => false
14631              ,P_EFFECTIVE_DATE        => l_effective_date
14632              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
14633              --
14634              ,P_ENRLD_ANTHR_PTIP_RT_ID      => l_enrld_anthr_ptip_rt_id
14635              ,P_ENRL_DET_DT_CD      => r_ENT.INFORMATION11
14636              ,P_ENT_ATTRIBUTE1      => r_ENT.INFORMATION111
14637              ,P_ENT_ATTRIBUTE10      => r_ENT.INFORMATION120
14638              ,P_ENT_ATTRIBUTE11      => r_ENT.INFORMATION121
14639              ,P_ENT_ATTRIBUTE12      => r_ENT.INFORMATION122
14640              ,P_ENT_ATTRIBUTE13      => r_ENT.INFORMATION123
14641              ,P_ENT_ATTRIBUTE14      => r_ENT.INFORMATION124
14642              ,P_ENT_ATTRIBUTE15      => r_ENT.INFORMATION125
14643              ,P_ENT_ATTRIBUTE16      => r_ENT.INFORMATION126
14644              ,P_ENT_ATTRIBUTE17      => r_ENT.INFORMATION127
14645              ,P_ENT_ATTRIBUTE18      => r_ENT.INFORMATION128
14646              ,P_ENT_ATTRIBUTE19      => r_ENT.INFORMATION129
14647              ,P_ENT_ATTRIBUTE2      => r_ENT.INFORMATION112
14648              ,P_ENT_ATTRIBUTE20      => r_ENT.INFORMATION130
14649              ,P_ENT_ATTRIBUTE21      => r_ENT.INFORMATION131
14650              ,P_ENT_ATTRIBUTE22      => r_ENT.INFORMATION132
14651              ,P_ENT_ATTRIBUTE23      => r_ENT.INFORMATION133
14652              ,P_ENT_ATTRIBUTE24      => r_ENT.INFORMATION134
14653              ,P_ENT_ATTRIBUTE25      => r_ENT.INFORMATION135
14654              ,P_ENT_ATTRIBUTE26      => r_ENT.INFORMATION136
14655              ,P_ENT_ATTRIBUTE27      => r_ENT.INFORMATION137
14656              ,P_ENT_ATTRIBUTE28      => r_ENT.INFORMATION138
14657              ,P_ENT_ATTRIBUTE29      => r_ENT.INFORMATION139
14658              ,P_ENT_ATTRIBUTE3      => r_ENT.INFORMATION113
14659              ,P_ENT_ATTRIBUTE30      => r_ENT.INFORMATION140
14660              ,P_ENT_ATTRIBUTE4      => r_ENT.INFORMATION114
14661              ,P_ENT_ATTRIBUTE5      => r_ENT.INFORMATION115
14662              ,P_ENT_ATTRIBUTE6      => r_ENT.INFORMATION116
14663              ,P_ENT_ATTRIBUTE7      => r_ENT.INFORMATION117
14664              ,P_ENT_ATTRIBUTE8      => r_ENT.INFORMATION118
14665              ,P_ENT_ATTRIBUTE9      => r_ENT.INFORMATION119
14666              ,P_ENT_ATTRIBUTE_CATEGORY      => r_ENT.INFORMATION110
14667              ,P_EXCLD_FLAG      => r_ENT.INFORMATION12
14668              ,P_ONLY_PLS_SUBJ_COBRA_FLAG      => r_ENT.INFORMATION13
14669              ,P_ORDR_NUM      => r_ENT.INFORMATION261
14670              ,P_PTIP_ID      => l_PTIP_ID
14671              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
14672              --
14673              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
14674              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
14675              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
14676            );
14677            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
14678            -- Update all relevent cer records with new pk_id
14679            hr_utility.set_location('Before plsql table ',222);
14680            hr_utility.set_location('new_value id '||l_enrld_anthr_ptip_rt_id,222);
14681            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'ENRLD_ANTHR_PTIP_RT_ID' ;
14682            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_ENT.information1 ;
14683            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_ENRLD_ANTHR_PTIP_RT_ID ;
14684            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
14685            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_ENT_unique.table_route_id;
14686            hr_utility.set_location('After plsql table ',222);
14687            --
14688            -- 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 ) ;
14689            --
14690            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
14691            --
14692          else
14693            --
14694            -- Call Update routine for the pk_id created in prev run .
14695            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
14696            --UPD START
14697            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
14698            --
14699            if l_update then
14700              --
14701              l_datetrack_mode := r_ENT.datetrack_mode ;
14702              --
14703              get_dt_modes(
14704                p_effective_date        => l_process_date,
14705                p_effective_end_date    => r_ENT.information3,
14706                p_effective_start_date  => r_ENT.information2,
14707                p_dml_operation         => r_ENT.dml_operation,
14708                p_datetrack_mode        => l_datetrack_mode );
14709            --    p_update                => l_update
14710              --
14711              l_effective_date := l_process_date;
14712              l_ENRLD_ANTHR_PTIP_RT_ID   := r_ENT.information1;
14713              l_object_version_number := r_ENT.information265;
14714              --
14715            end if;
14716            --
14717            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
14718            --
14719            IF l_update OR l_dml_operation <> 'UPDATE' THEN
14720            --UPD END
14721            hr_utility.set_location(' BEN_ENRLD_ANTHR_PTIP_RT_F UPDATE_ENRLD_ANTHR_PTIP_RT ',30);
14722            BEN_ENRLD_ANTHR_PTIP_RT_API.UPDATE_ENRLD_ANTHR_PTIP_RT(
14723              --
14724              P_VALIDATE               => false
14725              ,P_EFFECTIVE_DATE        => l_effective_date
14726              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
14727              --
14728              ,P_ENRLD_ANTHR_PTIP_RT_ID      => l_enrld_anthr_ptip_rt_id
14729              ,P_ENRL_DET_DT_CD      => r_ENT.INFORMATION11
14730              ,P_ENT_ATTRIBUTE1      => r_ENT.INFORMATION111
14731              ,P_ENT_ATTRIBUTE10      => r_ENT.INFORMATION120
14732              ,P_ENT_ATTRIBUTE11      => r_ENT.INFORMATION121
14733              ,P_ENT_ATTRIBUTE12      => r_ENT.INFORMATION122
14734              ,P_ENT_ATTRIBUTE13      => r_ENT.INFORMATION123
14735              ,P_ENT_ATTRIBUTE14      => r_ENT.INFORMATION124
14736              ,P_ENT_ATTRIBUTE15      => r_ENT.INFORMATION125
14737              ,P_ENT_ATTRIBUTE16      => r_ENT.INFORMATION126
14738              ,P_ENT_ATTRIBUTE17      => r_ENT.INFORMATION127
14739              ,P_ENT_ATTRIBUTE18      => r_ENT.INFORMATION128
14740              ,P_ENT_ATTRIBUTE19      => r_ENT.INFORMATION129
14741              ,P_ENT_ATTRIBUTE2      => r_ENT.INFORMATION112
14742              ,P_ENT_ATTRIBUTE20      => r_ENT.INFORMATION130
14743              ,P_ENT_ATTRIBUTE21      => r_ENT.INFORMATION131
14744              ,P_ENT_ATTRIBUTE22      => r_ENT.INFORMATION132
14745              ,P_ENT_ATTRIBUTE23      => r_ENT.INFORMATION133
14746              ,P_ENT_ATTRIBUTE24      => r_ENT.INFORMATION134
14747              ,P_ENT_ATTRIBUTE25      => r_ENT.INFORMATION135
14748              ,P_ENT_ATTRIBUTE26      => r_ENT.INFORMATION136
14749              ,P_ENT_ATTRIBUTE27      => r_ENT.INFORMATION137
14750              ,P_ENT_ATTRIBUTE28      => r_ENT.INFORMATION138
14751              ,P_ENT_ATTRIBUTE29      => r_ENT.INFORMATION139
14752              ,P_ENT_ATTRIBUTE3      => r_ENT.INFORMATION113
14753              ,P_ENT_ATTRIBUTE30      => r_ENT.INFORMATION140
14754              ,P_ENT_ATTRIBUTE4      => r_ENT.INFORMATION114
14755              ,P_ENT_ATTRIBUTE5      => r_ENT.INFORMATION115
14756              ,P_ENT_ATTRIBUTE6      => r_ENT.INFORMATION116
14757              ,P_ENT_ATTRIBUTE7      => r_ENT.INFORMATION117
14758              ,P_ENT_ATTRIBUTE8      => r_ENT.INFORMATION118
14759              ,P_ENT_ATTRIBUTE9      => r_ENT.INFORMATION119
14760              ,P_ENT_ATTRIBUTE_CATEGORY      => r_ENT.INFORMATION110
14761              ,P_EXCLD_FLAG      => r_ENT.INFORMATION12
14762              ,P_ONLY_PLS_SUBJ_COBRA_FLAG      => r_ENT.INFORMATION13
14763              ,P_ORDR_NUM      => r_ENT.INFORMATION261
14764              ,P_PTIP_ID      => l_PTIP_ID
14765              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
14766              --
14767              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
14768              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
14769              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
14770              ,P_DATETRACK_MODE        => l_datetrack_mode
14771            );
14772            --
14773            end if;
14774          end if;
14775          --
14776          -- Delete the row if it is end dated.
14777          --
14778          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
14779              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
14780              trunc(l_max_eed) = r_ENT.information3) then
14781              --
14782              BEN_ENRLD_ANTHR_PTIP_RT_API.delete_ENRLD_ANTHR_PTIP_RT(
14783                 --
14784                 p_validate                        => false
14785                 ,p_enrld_anthr_ptip_rt_id         => l_enrld_anthr_ptip_rt_id
14786                 ,p_effective_start_date           => l_effective_start_date
14787                 ,p_effective_end_date             => l_effective_end_date
14788                 ,p_object_version_number          => l_object_version_number
14789                 ,p_effective_date                 => l_max_eed
14790                 ,p_datetrack_mode                 => hr_api.g_delete
14791                 --
14792                 );
14793                 --
14794          end if;
14795          --
14796          l_prev_pk_id := l_current_pk_id ;
14797          --
14798        end if;
14799        --
14800      end if;
14801      --
14802    end loop;
14803    --
14804  exception when others then
14805     --
14806     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'ENT',r_ent.information5 );
14807     --
14808  end create_ENT_rows;
14809 
14810    ---------------------------------------------------------------
14811    ----------------------< create_ENL_rows >-----------------------
14812    ---------------------------------------------------------------
14813    --
14814    procedure create_ENL_rows
14815    (
14816          p_validate                       in  number     default 0
14817         ,p_copy_entity_txn_id             in  number
14818         ,p_effective_date                 in  date
14819         ,p_prefix_suffix_text             in  varchar2  default null
14820         ,p_reuse_object_flag              in  varchar2  default null
14821         ,p_target_business_group_id       in  varchar2  default null
14822         ,p_prefix_suffix_cd               in  varchar2  default null
14823    ) is
14824    --
14825    l_PL_ID  number;
14826    l_VRBL_RT_PRFL_ID  number;
14827    cursor c_unique_ENL(l_table_alias varchar2) is
14828    select distinct cpe.information1,
14829      cpe.information2,
14830      cpe.information3,
14831      cpe.table_route_id
14832    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
14833         pqh_table_route tr
14834    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
14835    and   cpe.table_route_id     = tr.table_route_id
14836    -- and   tr.where_clause        = l_BEN_ENRLD_ANTHR_PL_RT_F
14837    and tr.table_alias = l_table_alias
14838    and   cpe.number_of_copies   = 1 -- ADDITION
14839    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
14840    order by information1, information2; --added for bug: 5151945
14841    --
14842    --
14843    cursor c_ENL_min_max_dates(c_table_route_id  number,
14844                 c_information1   number) is
14845    select
14846      min(cpe.information2) min_esd,
14847      max(cpe.information3) min_eed
14848    from ben_copy_entity_results cpe
14849    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
14850    and   cpe.table_route_id     = c_table_route_id
14851    and   cpe.information1       = c_information1 ;
14852    --
14853    cursor c_ENL(c_table_route_id  number,
14854                 c_information1   number,
14855                 c_information2   date,
14856                 c_information3   Date)  is
14857    select
14858      cpe.*
14859    from ben_copy_entity_results cpe
14860    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
14861    and   cpe.table_route_id     = c_table_route_id
14862    and   cpe.information1       = c_information1
14863    and   cpe.information2       = c_information2
14864    and   cpe.information3       = c_information3
14865    and rownum = 1 ;
14866    -- Date Track target record
14867    cursor c_find_ENL_in_target(
14868                                 c_effective_start_date    date,
14869                                 c_effective_end_date      date,
14870                                 c_business_group_id       number,
14871                                 c_new_pk_id               number) is
14872    select
14873      ENL.enrld_anthr_pl_rt_id new_value
14874    from BEN_ENRLD_ANTHR_PL_RT_F ENL
14875    where
14876    ENL.PL_ID     = l_PL_ID  and
14877    ENL.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
14878    ENL.business_group_id  = c_business_group_id
14879    and   ENL.enrld_anthr_pl_rt_id  <> c_new_pk_id
14880 --TEMPIK
14881    and c_effective_start_date between effective_start_date
14882                             and effective_end_date ;
14883 --END TEMPIK
14884 /*TEMPIK
14885    and exists ( select null
14886                 from BEN_ENRLD_ANTHR_PL_RT_F ENL1
14887                 where
14888                 ENL1.PL_ID     = l_PL_ID  and
14889                 ENL1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
14890                 ENL1.business_group_id  = c_business_group_id
14891                 and   ENL1.effective_start_date <= c_effective_start_date )
14892    and exists ( select null
14893                 from BEN_ENRLD_ANTHR_PL_RT_F ENL2
14894                 where
14895                 ENL2.PL_ID     = l_PL_ID  and
14896                 ENL2.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
14897                 ENL2.business_group_id  = c_business_group_id
14898                 and   ENL2.effective_end_date >= c_effective_end_date )
14899                 ;
14900 TEMPIK */
14901    --TEMPIK
14902    l_dt_rec_found            boolean ;
14903    --END TEMPIK
14904    --
14905    l_current_pk_id           number := null ;
14906    --UPD START
14907    --
14908    l_update                  boolean      := false ;
14909    l_datetrack_mode          varchar2(80) := hr_api.g_update;
14910    l_process_date            date;
14911    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
14912    --
14913    --UPD END
14914    l_prev_pk_id              number := null ;
14915    l_first_rec               boolean := true ;
14916    r_ENL                     c_ENL%rowtype;
14917    l_enrld_anthr_pl_rt_id             number ;
14918    l_object_version_number   number ;
14919    l_effective_start_date    date ;
14920    l_effective_end_date      date ;
14921    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
14922    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
14923    l_new_value               number(15);
14924    l_object_found_in_target  boolean := false ;
14925    l_min_esd                 date;
14926    l_max_eed                 date;
14927    l_effective_date          date;
14928    --
14929  begin
14930    -- Initialization
14931    l_object_found_in_target := false ;
14932    -- End Initialization
14933    -- Derive the prefix - sufix
14934    if   p_prefix_suffix_cd = 'PREFIX' then
14935      l_prefix  := p_prefix_suffix_text ;
14936    elsif p_prefix_suffix_cd = 'SUFFIX' then
14937      l_suffix   := p_prefix_suffix_text ;
14938    else
14939      l_prefix := null ;
14940      l_suffix  := null ;
14941    end if ;
14942    -- End Prefix Sufix derivation
14943    for r_ENL_unique in c_unique_ENL('ENL') loop
14944 
14945      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
14946         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
14947          r_ENL_unique.information3 >=
14948                  ben_pd_copy_to_ben_one.g_copy_effective_date)
14949           ) then
14950        --
14951        hr_utility.set_location(' r_ENL_unique.table_route_id '||r_ENL_unique.table_route_id,10);
14952        hr_utility.set_location(' r_ENL_unique.information1 '||r_ENL_unique.information1,10);
14953        hr_utility.set_location( 'r_ENL_unique.information2 '||r_ENL_unique.information2,10);
14954        hr_utility.set_location( 'r_ENL_unique.information3 '||r_ENL_unique.information3,10);
14955        -- If reuse objects flag is 'Y' then check for the object in the target business group
14956        -- if found insert the record into PLSql table and exit the loop else try create the
14957        -- object in the target business group
14958        --
14959        l_object_found_in_target := false ;
14960        l_min_esd := null ;
14961        l_max_eed := null ;
14962        open c_ENL_min_max_dates(r_ENL_unique.table_route_id, r_ENL_unique.information1 ) ;
14963        fetch c_ENL_min_max_dates into l_min_esd,l_max_eed ;
14964 
14965        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
14966             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
14967          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
14968        end if;
14969        l_min_esd := greatest(l_min_esd,r_ENL_unique.information2);
14970        --
14971        open c_ENL(r_ENL_unique.table_route_id,
14972                 r_ENL_unique.information1,
14973                 r_ENL_unique.information2,
14974                 r_ENL_unique.information3 ) ;
14975        --
14976        fetch c_ENL into r_ENL ;
14977        --
14978        close c_ENL ;
14979        --
14980        -- Only For Use by Create Wizard - Same Business Group
14981        l_PL_ID := NVL(get_fk('PL_ID', r_ENL.information261,r_ENL_unique.dml_operation),
14982                       r_ENL.information261);
14983 
14984        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_ENL.information262,r_ENL_unique.dml_operation);
14985        --UPD START
14986        l_update := false;
14987        l_process_date := p_effective_date;
14988        l_dml_operation:= r_ENL_unique.dml_operation ;
14989        --
14990        if l_dml_operation = 'UPDATE' then
14991          --
14992          l_object_found_in_target := TRUE;
14993          --
14994          if l_process_date between r_ENL_unique.information2 and r_ENL_unique.information3 then
14995                l_update := true;
14996                if r_ENL_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
14997                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ENRLD_ANTHR_PL_RT_ID'
14998                then
14999                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ENRLD_ANTHR_PL_RT_ID' ;
15000                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_ENL_unique.information1 ;
15001                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_ENL_unique.information1 ;
15002                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
15003                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_ENL_unique.table_route_id;
15004                   --
15005                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
15006                   --
15007                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
15008                   --
15009                   -- log_data('ENL',l_new_value,l_prefix || r_ENL_unique.name|| l_suffix,'REUSED');
15010                   --
15011                end if ;
15012                hr_utility.set_location( 'found record for update',10);
15013            --
15014          else
15015            --
15016            l_update := false;
15017            --
15018          end if;
15019        else
15020          --
15021          --UPD END
15022        if p_reuse_object_flag = 'Y' then
15023          if c_ENL_min_max_dates%found then
15024            -- cursor to find the object
15025            open c_find_ENL_in_target( l_min_esd,l_max_eed,
15026                                  p_target_business_group_id, nvl(l_enrld_anthr_pl_rt_id, -999)  ) ;
15027            fetch c_find_ENL_in_target into l_new_value ;
15028            if c_find_ENL_in_target%found then
15029              --
15030              --TEMPIK
15031              l_dt_rec_found :=   dt_api.check_min_max_dates
15032                  (p_base_table_name => 'BEN_ENRLD_ANTHR_PL_RT_F',
15033                   p_base_key_column => 'ENRLD_ANTHR_PL_RT_ID',
15034                   p_base_key_value  => l_new_value,
15035                   p_from_date       => l_min_esd,
15036                   p_to_date         => l_max_eed );
15037              if l_dt_rec_found THEN
15038              --END TEMPIK
15039              if r_ENL_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
15040                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'ENRLD_ANTHR_PL_RT_ID'  then
15041                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'ENRLD_ANTHR_PL_RT_ID' ;
15042                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_ENL_unique.information1 ;
15043                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
15044                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
15045                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_ENL_unique.table_route_id;
15046                 --
15047                 -- 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) ;
15048                 --
15049                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
15050              end if ;
15051              --
15052              l_object_found_in_target := true ;
15053              --TEMPIK
15054              end if; -- l_dt_rec_found
15055              --END TEMPIK
15056            end if;
15057            close c_find_ENL_in_target ;
15058          --
15059          end if;
15060        end if ;
15061        --
15062        end if;
15063        close c_ENL_min_max_dates ;
15064        if not l_object_found_in_target OR l_update   then
15065          --
15066          l_current_pk_id := r_ENL.information1;
15067          --
15068          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
15069          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
15070          --
15071          if l_current_pk_id =  l_prev_pk_id  then
15072            --
15073            l_first_rec := false ;
15074            --
15075          else
15076            --
15077            l_first_rec := true ;
15078            --
15079          end if ;
15080          --
15081 
15082          l_effective_date := r_ENL.information2;
15083          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
15084               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
15085            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
15086          end if;
15087 
15088          if l_first_rec and not l_update then
15089            -- Call Create routine.
15090            hr_utility.set_location(' BEN_ENRLD_ANTHR_PL_RT_F CREATE_ENRLD_ANTHR_PL_RT ',20);
15091            BEN_ENRLD_ANTHR_PL_RT_API.CREATE_ENRLD_ANTHR_PL_RT(
15092              --
15093              P_VALIDATE               => false
15094              ,P_EFFECTIVE_DATE        => l_effective_date
15095              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
15096              --
15097              ,P_ENL_ATTRIBUTE1      => r_ENL.INFORMATION111
15098              ,P_ENL_ATTRIBUTE10      => r_ENL.INFORMATION120
15099              ,P_ENL_ATTRIBUTE11      => r_ENL.INFORMATION121
15100              ,P_ENL_ATTRIBUTE12      => r_ENL.INFORMATION122
15101              ,P_ENL_ATTRIBUTE13      => r_ENL.INFORMATION123
15102              ,P_ENL_ATTRIBUTE14      => r_ENL.INFORMATION124
15103              ,P_ENL_ATTRIBUTE15      => r_ENL.INFORMATION125
15104              ,P_ENL_ATTRIBUTE16      => r_ENL.INFORMATION126
15105              ,P_ENL_ATTRIBUTE17      => r_ENL.INFORMATION127
15106              ,P_ENL_ATTRIBUTE18      => r_ENL.INFORMATION128
15107              ,P_ENL_ATTRIBUTE19      => r_ENL.INFORMATION129
15108              ,P_ENL_ATTRIBUTE2      => r_ENL.INFORMATION112
15109              ,P_ENL_ATTRIBUTE20      => r_ENL.INFORMATION130
15110              ,P_ENL_ATTRIBUTE21      => r_ENL.INFORMATION131
15111              ,P_ENL_ATTRIBUTE22      => r_ENL.INFORMATION132
15112              ,P_ENL_ATTRIBUTE23      => r_ENL.INFORMATION133
15113              ,P_ENL_ATTRIBUTE24      => r_ENL.INFORMATION134
15114              ,P_ENL_ATTRIBUTE25      => r_ENL.INFORMATION135
15115              ,P_ENL_ATTRIBUTE26      => r_ENL.INFORMATION136
15116              ,P_ENL_ATTRIBUTE27      => r_ENL.INFORMATION137
15117              ,P_ENL_ATTRIBUTE28      => r_ENL.INFORMATION138
15118              ,P_ENL_ATTRIBUTE29      => r_ENL.INFORMATION139
15119              ,P_ENL_ATTRIBUTE3      => r_ENL.INFORMATION113
15120              ,P_ENL_ATTRIBUTE30      => r_ENL.INFORMATION140
15121              ,P_ENL_ATTRIBUTE4      => r_ENL.INFORMATION114
15122              ,P_ENL_ATTRIBUTE5      => r_ENL.INFORMATION115
15123              ,P_ENL_ATTRIBUTE6      => r_ENL.INFORMATION116
15124              ,P_ENL_ATTRIBUTE7      => r_ENL.INFORMATION117
15125              ,P_ENL_ATTRIBUTE8      => r_ENL.INFORMATION118
15126              ,P_ENL_ATTRIBUTE9      => r_ENL.INFORMATION119
15127              ,P_ENL_ATTRIBUTE_CATEGORY      => r_ENL.INFORMATION110
15128              ,P_ENRLD_ANTHR_PL_RT_ID      => l_enrld_anthr_pl_rt_id
15129              ,P_ENRL_DET_DT_CD      => r_ENL.INFORMATION12
15130              ,P_EXCLD_FLAG      => r_ENL.INFORMATION11
15131              ,P_ORDR_NUM      => r_ENL.INFORMATION260
15132              ,P_PL_ID      => l_PL_ID
15133              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
15134              --
15135              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
15136              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
15137              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
15138            );
15139            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
15140            -- Update all relevent cer records with new pk_id
15141            hr_utility.set_location('Before plsql table ',222);
15142            hr_utility.set_location('new_value id '||l_enrld_anthr_pl_rt_id,222);
15143            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'ENRLD_ANTHR_PL_RT_ID' ;
15144            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_ENL.information1 ;
15145            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_ENRLD_ANTHR_PL_RT_ID ;
15146            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
15147            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_ENL_unique.table_route_id;
15148            hr_utility.set_location('After plsql table ',222);
15149            --
15150            -- 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 ) ;
15151            --
15152            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
15153            --
15154          else
15155            --
15156            -- Call Update routine for the pk_id created in prev run .
15157            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
15158            --UPD START
15159            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
15160            --
15161            if l_update then
15162              --
15163              l_datetrack_mode := r_ENL.datetrack_mode ;
15164              --
15165              get_dt_modes(
15166                p_effective_date        => l_process_date,
15167                p_effective_end_date    => r_ENL.information3,
15168                p_effective_start_date  => r_ENL.information2,
15169                p_dml_operation         => r_ENL.dml_operation,
15170                p_datetrack_mode        => l_datetrack_mode );
15171            --    p_update                => l_update
15172              --
15173              l_effective_date := l_process_date;
15174              l_ENRLD_ANTHR_PL_RT_ID   := r_ENL.information1;
15175              l_object_version_number := r_ENL.information265;
15176              --
15177            end if;
15178            --
15179            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
15180            --
15181            IF l_update OR l_dml_operation <> 'UPDATE' THEN
15182            --UPD END
15183            hr_utility.set_location(' BEN_ENRLD_ANTHR_PL_RT_F UPDATE_ENRLD_ANTHR_PL_RT ',30);
15184            BEN_ENRLD_ANTHR_PL_RT_API.UPDATE_ENRLD_ANTHR_PL_RT(
15185              --
15186              P_VALIDATE               => false
15187              ,P_EFFECTIVE_DATE        => l_effective_date
15188              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
15189              --
15190              ,P_ENL_ATTRIBUTE1      => r_ENL.INFORMATION111
15191              ,P_ENL_ATTRIBUTE10      => r_ENL.INFORMATION120
15192              ,P_ENL_ATTRIBUTE11      => r_ENL.INFORMATION121
15193              ,P_ENL_ATTRIBUTE12      => r_ENL.INFORMATION122
15194              ,P_ENL_ATTRIBUTE13      => r_ENL.INFORMATION123
15195              ,P_ENL_ATTRIBUTE14      => r_ENL.INFORMATION124
15196              ,P_ENL_ATTRIBUTE15      => r_ENL.INFORMATION125
15197              ,P_ENL_ATTRIBUTE16      => r_ENL.INFORMATION126
15198              ,P_ENL_ATTRIBUTE17      => r_ENL.INFORMATION127
15199              ,P_ENL_ATTRIBUTE18      => r_ENL.INFORMATION128
15200              ,P_ENL_ATTRIBUTE19      => r_ENL.INFORMATION129
15201              ,P_ENL_ATTRIBUTE2      => r_ENL.INFORMATION112
15202              ,P_ENL_ATTRIBUTE20      => r_ENL.INFORMATION130
15203              ,P_ENL_ATTRIBUTE21      => r_ENL.INFORMATION131
15204              ,P_ENL_ATTRIBUTE22      => r_ENL.INFORMATION132
15205              ,P_ENL_ATTRIBUTE23      => r_ENL.INFORMATION133
15206              ,P_ENL_ATTRIBUTE24      => r_ENL.INFORMATION134
15207              ,P_ENL_ATTRIBUTE25      => r_ENL.INFORMATION135
15208              ,P_ENL_ATTRIBUTE26      => r_ENL.INFORMATION136
15209              ,P_ENL_ATTRIBUTE27      => r_ENL.INFORMATION137
15210              ,P_ENL_ATTRIBUTE28      => r_ENL.INFORMATION138
15211              ,P_ENL_ATTRIBUTE29      => r_ENL.INFORMATION139
15212              ,P_ENL_ATTRIBUTE3      => r_ENL.INFORMATION113
15213              ,P_ENL_ATTRIBUTE30      => r_ENL.INFORMATION140
15214              ,P_ENL_ATTRIBUTE4      => r_ENL.INFORMATION114
15215              ,P_ENL_ATTRIBUTE5      => r_ENL.INFORMATION115
15216              ,P_ENL_ATTRIBUTE6      => r_ENL.INFORMATION116
15217              ,P_ENL_ATTRIBUTE7      => r_ENL.INFORMATION117
15218              ,P_ENL_ATTRIBUTE8      => r_ENL.INFORMATION118
15219              ,P_ENL_ATTRIBUTE9      => r_ENL.INFORMATION119
15220              ,P_ENL_ATTRIBUTE_CATEGORY      => r_ENL.INFORMATION110
15221              ,P_ENRLD_ANTHR_PL_RT_ID      => l_enrld_anthr_pl_rt_id
15222              ,P_ENRL_DET_DT_CD      => r_ENL.INFORMATION12
15223              ,P_EXCLD_FLAG      => r_ENL.INFORMATION11
15224              ,P_ORDR_NUM      => r_ENL.INFORMATION260
15225              ,P_PL_ID      => l_PL_ID
15226              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
15227              --
15228              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
15229              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
15230              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
15231              ,P_DATETRACK_MODE        => l_datetrack_mode
15232            );
15233            --
15234            end if;
15235          end if;
15236          --
15237          -- Delete the row if it is end dated.
15238          --
15239          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
15240              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
15241              trunc(l_max_eed) = r_ENL.information3) then
15242              --
15243              BEN_ENRLD_ANTHR_PL_RT_API.delete_ENRLD_ANTHR_PL_RT(
15244                 --
15245                 p_validate                       => false
15246                 ,p_enrld_anthr_pl_rt_id                   => l_enrld_anthr_pl_rt_id
15247                 ,p_effective_start_date           => l_effective_start_date
15248                 ,p_effective_end_date             => l_effective_end_date
15249                 ,p_object_version_number          => l_object_version_number
15250                 ,p_effective_date                 => l_max_eed
15251                 ,p_datetrack_mode                 => hr_api.g_delete
15252                 --
15253                 );
15254                 --
15255          end if;
15256          --
15257          l_prev_pk_id := l_current_pk_id ;
15258          --
15259        end if;
15260        --
15261      end if;
15262      --
15263    end loop;
15264    --
15265  exception when others then
15266     --
15267     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'ENL',r_enl.information5 );
15268     --
15269  end create_ENL_rows;
15270 
15271    ---------------------------------------------------------------
15272    ----------------------< create_EAR_rows >-----------------------
15273    ---------------------------------------------------------------
15274    --
15275    procedure create_EAR_rows
15276    (
15277          p_validate                       in  number     default 0
15278         ,p_copy_entity_txn_id             in  number
15279         ,p_effective_date                 in  date
15280         ,p_prefix_suffix_text             in  varchar2  default null
15281         ,p_reuse_object_flag              in  varchar2  default null
15282         ,p_target_business_group_id       in  varchar2  default null
15283         ,p_prefix_suffix_cd               in  varchar2  default null
15284    ) is
15285    --
15286    l_PLIP_ID  number;
15287    l_VRBL_RT_PRFL_ID  number;
15288    cursor c_unique_EAR(l_table_alias varchar2) is
15289    select distinct cpe.information1,
15290      cpe.information2,
15291      cpe.information3,
15292      cpe.table_route_id
15293    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
15294         pqh_table_route tr
15295    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
15296    and   cpe.table_route_id     = tr.table_route_id
15297    -- and   tr.where_clause        = l_BEN_ENRLD_ANTHR_PLIP_RT_F
15298    and tr.table_alias = l_table_alias
15299    and   cpe.number_of_copies   = 1 -- ADDITION
15300    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
15301    order by information1, information2; --added for bug: 5151945
15302    --
15303    --
15304    cursor c_EAR_min_max_dates(c_table_route_id  number,
15305                 c_information1   number) is
15306    select
15307      min(cpe.information2) min_esd,
15308      max(cpe.information3) min_eed
15309    from ben_copy_entity_results cpe
15310    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
15311    and   cpe.table_route_id     = c_table_route_id
15312    and   cpe.information1       = c_information1 ;
15313    --
15314    cursor c_EAR(c_table_route_id number,
15315                 c_information1   number,
15316                 c_information2   Date,
15317                 c_information3   Date )  is
15318    select
15319      cpe.*
15320    from ben_copy_entity_results cpe
15321    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
15322    and   cpe.table_route_id     = c_table_route_id
15323    and   cpe.information1       = c_information1
15324    and   cpe.information2       = c_information2
15325    and   cpe.information3       = c_information3
15326    and rownum = 1 ;
15327    -- Date Track target record
15328    cursor c_find_EAR_in_target(
15329                                 c_effective_start_date    date,
15330                                 c_effective_end_date      date,
15331                                 c_business_group_id       number,
15332                                 c_new_pk_id               number) is
15333    select
15334      EAR.enrld_anthr_plip_rt_id new_value
15335    from BEN_ENRLD_ANTHR_PLIP_RT_F EAR
15336    where
15337    EAR.PLIP_ID     = l_PLIP_ID  and
15338    EAR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
15339    EAR.business_group_id  = c_business_group_id
15340    and   EAR.enrld_anthr_plip_rt_id  <> c_new_pk_id
15341 --TEMPIK
15342    and c_effective_start_date between effective_start_date
15343                             and effective_end_date ;
15344 --END TEMPIK
15345 /*TEMPIK
15346    and exists ( select null
15347                 from BEN_ENRLD_ANTHR_PLIP_RT_F EAR1
15348                 where
15349                 EAR1.PLIP_ID     = l_PLIP_ID  and
15350                 EAR1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
15351                 EAR1.business_group_id  = c_business_group_id
15352                 and   EAR1.effective_start_date <= c_effective_start_date )
15353    and exists ( select null
15354                 from BEN_ENRLD_ANTHR_PLIP_RT_F EAR2
15355                 where
15356                 EAR2.PLIP_ID     = l_PLIP_ID and
15357                 EAR2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
15358                 EAR2.business_group_id  = c_business_group_id
15359                 and   EAR2.effective_end_date >= c_effective_end_date )
15360                 ;
15361 TEMPIK */
15362    --TEMPIK
15363    l_dt_rec_found            boolean ;
15364    --END TEMPIK
15365    --
15366    l_current_pk_id           number := null ;
15367    --UPD START
15368    --
15369    l_update                  boolean      := false ;
15370    l_datetrack_mode          varchar2(80) := hr_api.g_update;
15371    l_process_date            date;
15372    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
15373    --
15374    --UPD END
15375    l_prev_pk_id              number := null ;
15376    l_first_rec               boolean := true ;
15377    r_EAR                     c_EAR%rowtype;
15378    l_enrld_anthr_plip_rt_id             number ;
15379    l_object_version_number   number ;
15380    l_effective_start_date    date ;
15381    l_effective_end_date      date ;
15382    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
15383    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
15384    l_new_value               number(15);
15385    l_object_found_in_target  boolean := false ;
15386    l_min_esd                 date;
15387    l_max_eed                 date;
15388    l_effective_date          date;
15389    --
15390  begin
15391    -- Initialization
15392    l_object_found_in_target := false ;
15393    -- End Initialization
15394    -- Derive the prefix - sufix
15395    if   p_prefix_suffix_cd = 'PREFIX' then
15396      l_prefix  := p_prefix_suffix_text ;
15397    elsif p_prefix_suffix_cd = 'SUFFIX' then
15398      l_suffix   := p_prefix_suffix_text ;
15399    else
15400      l_prefix := null ;
15401      l_suffix  := null ;
15402    end if ;
15403    -- End Prefix Sufix derivation
15404    for r_EAR_unique in c_unique_EAR('EAR') loop
15405 
15406      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
15407         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
15408          r_EAR_unique.information3 >=
15409                  ben_pd_copy_to_ben_one.g_copy_effective_date)
15410         ) then
15411        --
15412        hr_utility.set_location(' r_EAR_unique.table_route_id '||r_EAR_unique.table_route_id,10);
15413        hr_utility.set_location(' r_EAR_unique.information1 '||r_EAR_unique.information1,10);
15414        hr_utility.set_location( 'r_EAR_unique.information2 '||r_EAR_unique.information2,10);
15415        hr_utility.set_location( 'r_EAR_unique.information3 '||r_EAR_unique.information3,10);
15416        -- If reuse objects flag is 'Y' then check for the object in the target business group
15417        -- if found insert the record into PLSql table and exit the loop else try create the
15418        -- object in the target business group
15419        --
15420        l_object_found_in_target := false ;
15421        l_min_esd := null ;
15422        l_max_eed := null ;
15423        open c_EAR_min_max_dates(r_EAR_unique.table_route_id, r_EAR_unique.information1 ) ;
15424        fetch c_EAR_min_max_dates into l_min_esd,l_max_eed ;
15425        --
15426 
15427        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
15428             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
15429          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
15430        end if;
15431        l_min_esd := greatest(l_min_esd,r_EAR_unique.information2);
15432        open c_EAR(r_EAR_unique.table_route_id,
15433                 r_EAR_unique.information1,
15434                 r_EAR_unique.information2,
15435                 r_EAR_unique.information3 ) ;
15436        --
15437        fetch c_EAR into r_EAR ;
15438        --
15439        close c_EAR ;
15440        --
15441        -- Only For Use by Create Wizard - Same Business Group
15442        l_PLIP_ID := NVL(get_fk('PLIP_ID', r_EAR.information256,r_EAR_unique.dml_operation),
15443                         r_EAR.information256);
15444 
15445        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_EAR.information262,r_EAR_unique.dml_operation);
15446        --UPD START
15447        l_update := false;
15448        l_process_date := p_effective_date;
15449        l_dml_operation:= r_EAR_unique.dml_operation ;
15450        --
15451        if l_dml_operation = 'UPDATE' then
15452          --
15453          l_object_found_in_target := TRUE;
15454          --
15455          if l_process_date between r_EAR_unique.information2 and r_EAR_unique.information3 then
15456                l_update := true;
15457                if r_EAR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
15458                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ENRLD_ANTHR_PLIP_RT_ID'
15459                then
15460                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ENRLD_ANTHR_PLIP_RT_ID' ;
15461                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_EAR_unique.information1 ;
15462                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_EAR_unique.information1 ;
15463                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
15464                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_EAR_unique.table_route_id;
15465                   --
15466                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
15467                   --
15468                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
15469                   --
15470                   -- log_data('EAR',l_new_value,l_prefix || r_EAR_unique.name|| l_suffix,'REUSED');
15471                   --
15472                end if ;
15473                hr_utility.set_location( 'found record for update',10);
15474            --
15475          else
15476            --
15477            l_update := false;
15478            --
15479          end if;
15480        else
15481          --
15482          --UPD END
15483        if p_reuse_object_flag = 'Y' then
15484          if c_EAR_min_max_dates%found then
15485            -- cursor to find the object
15486            open c_find_EAR_in_target( l_min_esd,l_max_eed,
15487                                  p_target_business_group_id, nvl(l_enrld_anthr_plip_rt_id, -999)  ) ;
15488            fetch c_find_EAR_in_target into l_new_value ;
15489            if c_find_EAR_in_target%found then
15490              --
15491              --TEMPIK
15492              l_dt_rec_found :=   dt_api.check_min_max_dates
15493                  (p_base_table_name => 'BEN_ENRLD_ANTHR_PLIP_RT_F',
15494                   p_base_key_column => 'ENRLD_ANTHR_PLIP_RT_ID',
15495                   p_base_key_value  => l_new_value,
15496                   p_from_date       => l_min_esd,
15497                   p_to_date         => l_max_eed );
15498              if l_dt_rec_found THEN
15499              --END TEMPIK
15500              if r_EAR_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
15501                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'ENRLD_ANTHR_PLIP_RT_ID'  then
15502                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'ENRLD_ANTHR_PLIP_RT_ID' ;
15503                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_EAR_unique.information1 ;
15504                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
15505                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
15506                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_EAR_unique.table_route_id;
15507                 --
15508                 -- 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) ;
15509                 --
15510                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
15511              end if ;
15512              --
15513              l_object_found_in_target := true ;
15514              --TEMPIK
15515              end if; -- l_dt_rec_found
15516              --END TEMPIK
15517            end if;
15518            close c_find_EAR_in_target ;
15519          --
15520          end if;
15521        end if ;
15522        --
15523        end if;
15524        close c_EAR_min_max_dates ;
15525        if not l_object_found_in_target OR l_update   then
15526          --
15527          l_current_pk_id := r_EAR.information1;
15528          --
15529          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
15530          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
15531          --
15532          if l_current_pk_id =  l_prev_pk_id  then
15533            --
15534            l_first_rec := false ;
15535            --
15536          else
15537            --
15538            l_first_rec := true ;
15539            --
15540          end if ;
15541          --
15542 
15543          l_effective_date := r_EAR.information2;
15544          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
15545               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
15546            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
15547          end if;
15548 
15549          if l_first_rec and not l_update then
15550            -- Call Create routine.
15551            hr_utility.set_location(' BEN_ENRLD_ANTHR_PLIP_RT_F CREATE_ENRLD_ANTHR_PLIP_RT ',20);
15552            BEN_ENRLD_ANTHR_PLIP_RT_API.CREATE_ENRLD_ANTHR_PLIP_RT(
15553              --
15554              P_VALIDATE               => false
15555              ,P_EFFECTIVE_DATE        => l_effective_date
15556              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
15557              --
15558              ,P_EAR_ATTRIBUTE1      => r_EAR.INFORMATION111
15559              ,P_EAR_ATTRIBUTE10      => r_EAR.INFORMATION120
15560              ,P_EAR_ATTRIBUTE11      => r_EAR.INFORMATION121
15561              ,P_EAR_ATTRIBUTE12      => r_EAR.INFORMATION122
15562              ,P_EAR_ATTRIBUTE13      => r_EAR.INFORMATION123
15563              ,P_EAR_ATTRIBUTE14      => r_EAR.INFORMATION124
15564              ,P_EAR_ATTRIBUTE15      => r_EAR.INFORMATION125
15565              ,P_EAR_ATTRIBUTE16      => r_EAR.INFORMATION126
15566              ,P_EAR_ATTRIBUTE17      => r_EAR.INFORMATION127
15567              ,P_EAR_ATTRIBUTE18      => r_EAR.INFORMATION128
15568              ,P_EAR_ATTRIBUTE19      => r_EAR.INFORMATION129
15569              ,P_EAR_ATTRIBUTE2      => r_EAR.INFORMATION112
15570              ,P_EAR_ATTRIBUTE20      => r_EAR.INFORMATION130
15571              ,P_EAR_ATTRIBUTE21      => r_EAR.INFORMATION131
15572              ,P_EAR_ATTRIBUTE22      => r_EAR.INFORMATION132
15573              ,P_EAR_ATTRIBUTE23      => r_EAR.INFORMATION133
15574              ,P_EAR_ATTRIBUTE24      => r_EAR.INFORMATION134
15575              ,P_EAR_ATTRIBUTE25      => r_EAR.INFORMATION135
15576              ,P_EAR_ATTRIBUTE26      => r_EAR.INFORMATION136
15577              ,P_EAR_ATTRIBUTE27      => r_EAR.INFORMATION137
15578              ,P_EAR_ATTRIBUTE28      => r_EAR.INFORMATION138
15579              ,P_EAR_ATTRIBUTE29      => r_EAR.INFORMATION139
15580              ,P_EAR_ATTRIBUTE3      => r_EAR.INFORMATION113
15581              ,P_EAR_ATTRIBUTE30      => r_EAR.INFORMATION140
15582              ,P_EAR_ATTRIBUTE4      => r_EAR.INFORMATION114
15583              ,P_EAR_ATTRIBUTE5      => r_EAR.INFORMATION115
15584              ,P_EAR_ATTRIBUTE6      => r_EAR.INFORMATION116
15585              ,P_EAR_ATTRIBUTE7      => r_EAR.INFORMATION117
15586              ,P_EAR_ATTRIBUTE8      => r_EAR.INFORMATION118
15587              ,P_EAR_ATTRIBUTE9      => r_EAR.INFORMATION119
15588              ,P_EAR_ATTRIBUTE_CATEGORY      => r_EAR.INFORMATION110
15589              ,P_ENRLD_ANTHR_PLIP_RT_ID      => l_enrld_anthr_plip_rt_id
15590              ,P_ENRL_DET_DT_CD      => r_EAR.INFORMATION11
15591              ,P_EXCLD_FLAG      => r_EAR.INFORMATION12
15592              ,P_ORDR_NUM      => r_EAR.INFORMATION257
15593              ,P_PLIP_ID      => l_PLIP_ID
15594              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
15595              --
15596              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
15597              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
15598              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
15599            );
15600            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
15601            -- Update all relevent cer records with new pk_id
15602            hr_utility.set_location('Before plsql table ',222);
15603            hr_utility.set_location('new_value id '||l_enrld_anthr_plip_rt_id,222);
15604            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'ENRLD_ANTHR_PLIP_RT_ID' ;
15605            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_EAR.information1 ;
15606            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_ENRLD_ANTHR_PLIP_RT_ID ;
15607            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
15608            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_EAR_unique.table_route_id;
15609            hr_utility.set_location('After plsql table ',222);
15610            --
15611            -- 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 ) ;
15612            --
15613            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
15614            --
15615          else
15616            --
15617            -- Call Update routine for the pk_id created in prev run .
15618            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
15619            --UPD START
15620            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
15621            --
15622            if l_update then
15623              --
15624              l_datetrack_mode := r_EAR.datetrack_mode ;
15625              --
15626              get_dt_modes(
15627                p_effective_date        => l_process_date,
15628                p_effective_end_date    => r_EAR.information3,
15629                p_effective_start_date  => r_EAR.information2,
15630                p_dml_operation         => r_EAR.dml_operation,
15631                p_datetrack_mode        => l_datetrack_mode );
15632            --    p_update                => l_update
15633              --
15634              l_effective_date := l_process_date;
15635              l_ENRLD_ANTHR_PLIP_RT_ID   := r_EAR.information1;
15636              l_object_version_number := r_EAR.information265;
15637              --
15638            end if;
15639            --
15640            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
15641            --
15642            IF l_update OR l_dml_operation <> 'UPDATE' THEN
15643            --UPD END
15644            hr_utility.set_location(' BEN_ENRLD_ANTHR_PLIP_RT_F UPDATE_ENRLD_ANTHR_PLIP_RT ',30);
15645            BEN_ENRLD_ANTHR_PLIP_RT_API.UPDATE_ENRLD_ANTHR_PLIP_RT(
15646              --
15647              P_VALIDATE               => false
15648              ,P_EFFECTIVE_DATE        => l_effective_date
15649              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
15650              --
15651              ,P_EAR_ATTRIBUTE1      => r_EAR.INFORMATION111
15652              ,P_EAR_ATTRIBUTE10      => r_EAR.INFORMATION120
15653              ,P_EAR_ATTRIBUTE11      => r_EAR.INFORMATION121
15654              ,P_EAR_ATTRIBUTE12      => r_EAR.INFORMATION122
15655              ,P_EAR_ATTRIBUTE13      => r_EAR.INFORMATION123
15656              ,P_EAR_ATTRIBUTE14      => r_EAR.INFORMATION124
15657              ,P_EAR_ATTRIBUTE15      => r_EAR.INFORMATION125
15658              ,P_EAR_ATTRIBUTE16      => r_EAR.INFORMATION126
15659              ,P_EAR_ATTRIBUTE17      => r_EAR.INFORMATION127
15660              ,P_EAR_ATTRIBUTE18      => r_EAR.INFORMATION128
15661              ,P_EAR_ATTRIBUTE19      => r_EAR.INFORMATION129
15662              ,P_EAR_ATTRIBUTE2      => r_EAR.INFORMATION112
15663              ,P_EAR_ATTRIBUTE20      => r_EAR.INFORMATION130
15664              ,P_EAR_ATTRIBUTE21      => r_EAR.INFORMATION131
15665              ,P_EAR_ATTRIBUTE22      => r_EAR.INFORMATION132
15666              ,P_EAR_ATTRIBUTE23      => r_EAR.INFORMATION133
15667              ,P_EAR_ATTRIBUTE24      => r_EAR.INFORMATION134
15668              ,P_EAR_ATTRIBUTE25      => r_EAR.INFORMATION135
15669              ,P_EAR_ATTRIBUTE26      => r_EAR.INFORMATION136
15670              ,P_EAR_ATTRIBUTE27      => r_EAR.INFORMATION137
15671              ,P_EAR_ATTRIBUTE28      => r_EAR.INFORMATION138
15672              ,P_EAR_ATTRIBUTE29      => r_EAR.INFORMATION139
15673              ,P_EAR_ATTRIBUTE3      => r_EAR.INFORMATION113
15674              ,P_EAR_ATTRIBUTE30      => r_EAR.INFORMATION140
15675              ,P_EAR_ATTRIBUTE4      => r_EAR.INFORMATION114
15676              ,P_EAR_ATTRIBUTE5      => r_EAR.INFORMATION115
15677              ,P_EAR_ATTRIBUTE6      => r_EAR.INFORMATION116
15678              ,P_EAR_ATTRIBUTE7      => r_EAR.INFORMATION117
15679              ,P_EAR_ATTRIBUTE8      => r_EAR.INFORMATION118
15680              ,P_EAR_ATTRIBUTE9      => r_EAR.INFORMATION119
15681              ,P_EAR_ATTRIBUTE_CATEGORY      => r_EAR.INFORMATION110
15682              ,P_ENRLD_ANTHR_PLIP_RT_ID      => l_enrld_anthr_plip_rt_id
15683              ,P_ENRL_DET_DT_CD      => r_EAR.INFORMATION11
15684              ,P_EXCLD_FLAG      => r_EAR.INFORMATION12
15685              ,P_ORDR_NUM      => r_EAR.INFORMATION257
15686              ,P_PLIP_ID      => l_PLIP_ID
15687              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
15688              --
15689              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
15690              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
15691              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
15692              ,P_DATETRACK_MODE        => l_datetrack_mode
15693            );
15694            --
15695            end if;
15696          end if;
15697          --
15698          -- Delete the row if it is end dated.
15699          --
15700          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
15701              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
15702              trunc(l_max_eed) = r_EAR.information3) then
15703              --
15704              BEN_ENRLD_ANTHR_PLIP_RT_API.delete_ENRLD_ANTHR_PLIP_RT(
15705                 --
15706                 p_validate                       => false
15707                 ,p_enrld_anthr_plip_rt_id                   => l_enrld_anthr_plip_rt_id
15708                 ,p_effective_start_date           => l_effective_start_date
15709                 ,p_effective_end_date             => l_effective_end_date
15710                 ,p_object_version_number          => l_object_version_number
15711                 ,p_effective_date                 => l_max_eed
15712                 ,p_datetrack_mode                 => hr_api.g_delete
15713                 --
15714                 );
15715                 --
15716          end if;
15717          --
15718          l_prev_pk_id := l_current_pk_id ;
15719          --
15720        end if;
15721        --
15722      end if;
15723      --
15724    end loop;
15725    --
15726  exception when others then
15727     --
15728     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'EAR',r_ear.information5 );
15729     --
15730  end create_EAR_rows;
15731 
15732    ---------------------------------------------------------------
15733    ----------------------< create_EAO_rows >-----------------------
15734    ---------------------------------------------------------------
15735    --
15736    procedure create_EAO_rows
15737    (
15738          p_validate                       in  number     default 0
15739         ,p_copy_entity_txn_id             in  number
15740         ,p_effective_date                 in  date
15741         ,p_prefix_suffix_text             in  varchar2  default null
15742         ,p_reuse_object_flag              in  varchar2  default null
15743         ,p_target_business_group_id       in  varchar2  default null
15744         ,p_prefix_suffix_cd               in  varchar2  default null
15745    ) is
15746    --
15747    l_OIPL_ID  number;
15748    l_VRBL_RT_PRFL_ID  number;
15749    cursor c_unique_EAO(l_table_alias varchar2) is
15750    select distinct cpe.information1,
15751      cpe.information2,
15752      cpe.information3,
15753      cpe.table_route_id
15754    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
15755         pqh_table_route tr
15756    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
15757    and   cpe.table_route_id     = tr.table_route_id
15758    -- and   tr.where_clause        = l_BEN_ENRLD_ANTHR_OIPL_RT_F
15759    and tr.table_alias = l_table_alias
15760    and   cpe.number_of_copies   = 1 -- ADDITION
15761    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
15762    order by information1, information2; --added for bug: 5151945
15763    --
15764    --
15765    cursor c_EAO_min_max_dates(c_table_route_id  number,
15766                 c_information1   Number) is
15767    select
15768      min(cpe.information2) min_esd,
15769      max(cpe.information3) min_eed
15770    from ben_copy_entity_results cpe
15771    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
15772    and   cpe.table_route_id     = c_table_route_id
15773    and   cpe.information1       = c_information1 ;
15774    --
15775    cursor c_EAO(c_table_route_id  number,
15776                 c_information1   number,
15777                 c_information2   Date,
15778                 c_information3   Date)  is
15779    select
15780      cpe.*
15781    from ben_copy_entity_results cpe
15782    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
15783    and   cpe.table_route_id     = c_table_route_id
15784    and   cpe.information1       = c_information1
15785    and   cpe.information2       = c_information2
15786    and   cpe.information3       = c_information3
15787    and rownum = 1 ;
15788    -- Date Track target record
15789    cursor c_find_EAO_in_target(
15790                                 c_effective_start_date    date,
15791                                 c_effective_end_date      date,
15792                                 c_business_group_id       number,
15793                                 c_new_pk_id               number) is
15794    select
15795      EAO.enrld_anthr_oipl_rt_id new_value
15796    from BEN_ENRLD_ANTHR_OIPL_RT_F EAO
15797    where
15798    EAO.OIPL_ID     = l_OIPL_ID  and
15799    EAO.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
15800    EAO.business_group_id  = c_business_group_id
15801    and   EAO.enrld_anthr_oipl_rt_id  <> c_new_pk_id
15802 --TEMPIK
15803    and c_effective_start_date between effective_start_date
15804                             and effective_end_date ;
15805 --END TEMPIK
15806 /*TEMPIK
15807    and exists ( select null
15808                 from BEN_ENRLD_ANTHR_OIPL_RT_F EAO1
15809                 where
15810                 EAO1.OIPL_ID     = l_OIPL_ID  and
15811                 EAO1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
15812                 EAO1.business_group_id  = c_business_group_id
15813                 and   EAO1.effective_start_date <= c_effective_start_date )
15814    and exists ( select null
15815                 from BEN_ENRLD_ANTHR_OIPL_RT_F EAO2
15816                 where
15817                 EAO2.OIPL_ID     = l_OIPL_ID  and
15818                 EAO2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
15819                 EAO2.business_group_id  = c_business_group_id
15820                 and   EAO2.effective_end_date >= c_effective_end_date )
15821                 ;
15822 TEMPIK */
15823    --TEMPIK
15824    l_dt_rec_found            boolean ;
15825    --END TEMPIK
15826    --
15827    l_current_pk_id           number := null ;
15828    --UPD START
15829    --
15830    l_update                  boolean      := false ;
15831    l_datetrack_mode          varchar2(80) := hr_api.g_update;
15832    l_process_date            date;
15833    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
15834    --
15835    --UPD END
15836    l_prev_pk_id              number := null ;
15837    l_first_rec               boolean := true ;
15838    r_EAO                     c_EAO%rowtype;
15839    l_enrld_anthr_oipl_rt_id             number ;
15840    l_object_version_number   number ;
15841    l_effective_start_date    date ;
15842    l_effective_end_date      date ;
15843    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
15844    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
15845    l_new_value               number(15);
15846    l_object_found_in_target  boolean := false ;
15847    l_min_esd                 date;
15848    l_max_eed                 date;
15849    l_effective_date          date;
15850    --
15851  begin
15852    -- Initialization
15853    l_object_found_in_target := false ;
15854    -- End Initialization
15855    -- Derive the prefix - sufix
15856    if   p_prefix_suffix_cd = 'PREFIX' then
15857      l_prefix  := p_prefix_suffix_text ;
15858    elsif p_prefix_suffix_cd = 'SUFFIX' then
15859      l_suffix   := p_prefix_suffix_text ;
15860    else
15861      l_prefix := null ;
15862      l_suffix  := null ;
15863    end if ;
15864    -- End Prefix Sufix derivation
15865    for r_EAO_unique in c_unique_EAO('EAO') loop
15866 
15867      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
15868           (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
15869            r_EAO_unique.information3 >=
15870                    ben_pd_copy_to_ben_one.g_copy_effective_date)
15871           ) then
15872        --
15873        hr_utility.set_location(' r_EAO_unique.table_route_id '||r_EAO_unique.table_route_id,10);
15874        hr_utility.set_location(' r_EAO_unique.information1 '||r_EAO_unique.information1,10);
15875        hr_utility.set_location( 'r_EAO_unique.information2 '||r_EAO_unique.information2,10);
15876        hr_utility.set_location( 'r_EAO_unique.information3 '||r_EAO_unique.information3,10);
15877        -- If reuse objects flag is 'Y' then check for the object in the target business group
15878        -- if found insert the record into PLSql table and exit the loop else try create the
15879        -- object in the target business group
15880        --
15881        l_object_found_in_target := false ;
15882        l_min_esd := null ;
15883        l_max_eed := null ;
15884        open c_EAO_min_max_dates(r_EAO_unique.table_route_id, r_EAO_unique.information1 ) ;
15885        fetch c_EAO_min_max_dates into l_min_esd,l_max_eed ;
15886        --
15887 
15888        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
15889             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
15890          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
15891        end if;
15892        l_min_esd := greatest(l_min_esd,r_EAO_unique.information2);
15893        open c_EAO(r_EAO_unique.table_route_id,
15894                 r_EAO_unique.information1,
15895                 r_EAO_unique.information2,
15896                 r_EAO_unique.information3 ) ;
15897        --
15898        fetch c_EAO into r_EAO ;
15899        --
15900        close c_EAO ;
15901        --
15902        -- Only For Use by Create Wizard - Same Business Group
15903        l_OIPL_ID := NVL(get_fk('OIPL_ID', r_EAO.information25,r_EAO_unique.dml_operation),
15904                         r_EAO.information258);
15905 
15906        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_EAO.information262,r_EAO_unique.dml_operation);
15907        --UPD START
15908        l_update := false;
15909        l_process_date := p_effective_date;
15910        l_dml_operation:= r_EAO_unique.dml_operation ;
15911        --
15912        if l_dml_operation = 'UPDATE' then
15913          --
15914          l_object_found_in_target := TRUE;
15915          --
15916          if l_process_date between r_EAO_unique.information2 and r_EAO_unique.information3 then
15917                l_update := true;
15918                if r_EAO_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
15919                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'ENRLD_ANTHR_OIPL_RT_ID'
15920                then
15921                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'ENRLD_ANTHR_OIPL_RT_ID' ;
15922                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_EAO_unique.information1 ;
15923                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_EAO_unique.information1 ;
15924                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
15925                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_EAO_unique.table_route_id;
15926                   --
15927                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
15928                   --
15929                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
15930                   --
15931                   -- log_data('EAO',l_new_value,l_prefix || r_EAO_unique.name|| l_suffix,'REUSED');
15932                   --
15933                end if ;
15934                hr_utility.set_location( 'found record for update',10);
15935            --
15936          else
15937            --
15938            l_update := false;
15939            --
15940          end if;
15941        else
15942          --
15943          --UPD END
15944        if p_reuse_object_flag = 'Y' then
15945          if c_EAO_min_max_dates%found then
15946            -- cursor to find the object
15947            open c_find_EAO_in_target( l_min_esd,l_max_eed,
15948                                  p_target_business_group_id, nvl(l_enrld_anthr_oipl_rt_id, -999)  ) ;
15949            fetch c_find_EAO_in_target into l_new_value ;
15950            if c_find_EAO_in_target%found then
15951              --
15952              --TEMPIK
15953              l_dt_rec_found :=   dt_api.check_min_max_dates
15954                  (p_base_table_name => 'BEN_ENRLD_ANTHR_OIPL_RT_F',
15955                   p_base_key_column => 'ENRLD_ANTHR_OIPL_RT_ID',
15956                   p_base_key_value  => l_new_value,
15957                   p_from_date       => l_min_esd,
15958                   p_to_date         => l_max_eed );
15959              if l_dt_rec_found THEN
15960              --END TEMPIK
15961              if r_EAO_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
15962                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'ENRLD_ANTHR_OIPL_RT_ID'  then
15963                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'ENRLD_ANTHR_OIPL_RT_ID' ;
15964                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_EAO_unique.information1 ;
15965                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
15966                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
15967                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_EAO_unique.table_route_id;
15968                 --
15969                 -- 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) ;
15970                 --
15971                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
15972              end if ;
15973              --
15974              l_object_found_in_target := true ;
15975              --TEMPIK
15976              end if; -- l_dt_rec_found
15977              --END TEMPIK
15978            end if;
15979            close c_find_EAO_in_target ;
15980          --
15981          end if;
15982        end if ;
15983        --
15984        end if;
15985        close c_EAO_min_max_dates ;
15986        if not l_object_found_in_target OR l_update   then
15987          --
15988          l_current_pk_id := r_EAO.information1;
15989          --
15990          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
15991          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
15992          --
15993          if l_current_pk_id =  l_prev_pk_id  then
15994            --
15995            l_first_rec := false ;
15996            --
15997          else
15998            --
15999            l_first_rec := true ;
16000            --
16001          end if ;
16002          --
16003 
16004          l_effective_date := r_EAO.information2;
16005          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
16006               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
16007            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
16008          end if;
16009 
16010          if l_first_rec and not l_update then
16011            -- Call Create routine.
16012            hr_utility.set_location(' BEN_ENRLD_ANTHR_OIPL_RT_F CREATE_ENRLD_ANTHR_OIPL_RT ',20);
16013            BEN_ENRLD_ANTHR_OIPL_RT_API.CREATE_ENRLD_ANTHR_OIPL_RT(
16014              --
16015              P_VALIDATE               => false
16016              ,P_EFFECTIVE_DATE        => l_effective_date
16017              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
16018              --
16019             ,P_EAO_ATTRIBUTE1      => r_EAO.INFORMATION111
16020              ,P_EAO_ATTRIBUTE10      => r_EAO.INFORMATION120
16021              ,P_EAO_ATTRIBUTE11      => r_EAO.INFORMATION121
16022              ,P_EAO_ATTRIBUTE12      => r_EAO.INFORMATION122
16023              ,P_EAO_ATTRIBUTE13      => r_EAO.INFORMATION123
16024              ,P_EAO_ATTRIBUTE14      => r_EAO.INFORMATION124
16025              ,P_EAO_ATTRIBUTE15      => r_EAO.INFORMATION125
16026              ,P_EAO_ATTRIBUTE16      => r_EAO.INFORMATION126
16027              ,P_EAO_ATTRIBUTE17      => r_EAO.INFORMATION127
16028              ,P_EAO_ATTRIBUTE18      => r_EAO.INFORMATION128
16029              ,P_EAO_ATTRIBUTE19      => r_EAO.INFORMATION129
16030              ,P_EAO_ATTRIBUTE2      => r_EAO.INFORMATION112
16031              ,P_EAO_ATTRIBUTE20      => r_EAO.INFORMATION130
16032              ,P_EAO_ATTRIBUTE21      => r_EAO.INFORMATION131
16033              ,P_EAO_ATTRIBUTE22      => r_EAO.INFORMATION132
16034              ,P_EAO_ATTRIBUTE23      => r_EAO.INFORMATION133
16035              ,P_EAO_ATTRIBUTE24      => r_EAO.INFORMATION134
16036              ,P_EAO_ATTRIBUTE25      => r_EAO.INFORMATION135
16037              ,P_EAO_ATTRIBUTE26      => r_EAO.INFORMATION136
16038              ,P_EAO_ATTRIBUTE27      => r_EAO.INFORMATION137
16039              ,P_EAO_ATTRIBUTE28      => r_EAO.INFORMATION138
16040              ,P_EAO_ATTRIBUTE29      => r_EAO.INFORMATION139
16041              ,P_EAO_ATTRIBUTE3      => r_EAO.INFORMATION113
16042              ,P_EAO_ATTRIBUTE30      => r_EAO.INFORMATION140
16043              ,P_EAO_ATTRIBUTE4      => r_EAO.INFORMATION114
16044              ,P_EAO_ATTRIBUTE5      => r_EAO.INFORMATION115
16045              ,P_EAO_ATTRIBUTE6      => r_EAO.INFORMATION116
16046              ,P_EAO_ATTRIBUTE7      => r_EAO.INFORMATION117
16047              ,P_EAO_ATTRIBUTE8      => r_EAO.INFORMATION118
16048              ,P_EAO_ATTRIBUTE9      => r_EAO.INFORMATION119
16049              ,P_EAO_ATTRIBUTE_CATEGORY      => r_EAO.INFORMATION110
16050              ,P_ENRLD_ANTHR_OIPL_RT_ID      => l_enrld_anthr_oipl_rt_id
16051              ,P_ENRL_DET_DT_CD      => r_EAO.INFORMATION12
16052              ,P_EXCLD_FLAG      => r_EAO.INFORMATION11
16053              ,P_OIPL_ID      => l_OIPL_ID
16054              ,P_ORDR_NUM      => r_EAO.INFORMATION261
16055              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
16056              --
16057              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
16058              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
16059              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
16060            );
16061            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
16062            -- Update all relevent cer records with new pk_id
16063            hr_utility.set_location('Before plsql table ',222);
16064            hr_utility.set_location('new_value id '||l_enrld_anthr_oipl_rt_id,222);
16065            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'ENRLD_ANTHR_OIPL_RT_ID' ;
16066            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_EAO.information1 ;
16067            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_ENRLD_ANTHR_OIPL_RT_ID ;
16068            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
16069            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_EAO_unique.table_route_id;
16070            hr_utility.set_location('After plsql table ',222);
16071            --
16072            -- 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 ) ;
16073            --
16074            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
16075            --
16076          else
16077            --
16078            -- Call Update routine for the pk_id created in prev run .
16079            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
16080            --UPD START
16081            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
16082            --
16083            if l_update then
16084              --
16085              l_datetrack_mode := r_EAO.datetrack_mode ;
16086              --
16087              get_dt_modes(
16088                p_effective_date        => l_process_date,
16089                p_effective_end_date    => r_EAO.information3,
16090                p_effective_start_date  => r_EAO.information2,
16091                p_dml_operation         => r_EAO.dml_operation,
16092                p_datetrack_mode        => l_datetrack_mode );
16093            --    p_update                => l_update
16094              --
16095              l_effective_date := l_process_date;
16096              l_ENRLD_ANTHR_OIPL_RT_ID   := r_EAO.information1;
16097              l_object_version_number := r_EAO.information265;
16098              --
16099            end if;
16100            --
16101            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
16102            --
16103            IF l_update OR l_dml_operation <> 'UPDATE' THEN
16104            --UPD END
16105            hr_utility.set_location(' BEN_ENRLD_ANTHR_OIPL_RT_F UPDATE_ENRLD_ANTHR_OIPL_RT ',30);
16106            BEN_ENRLD_ANTHR_OIPL_RT_API.UPDATE_ENRLD_ANTHR_OIPL_RT(
16107              --
16108              P_VALIDATE               => false
16109              ,P_EFFECTIVE_DATE        => l_effective_date
16110              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
16111              --
16112              ,P_EAO_ATTRIBUTE1      => r_EAO.INFORMATION111
16113              ,P_EAO_ATTRIBUTE10      => r_EAO.INFORMATION120
16114              ,P_EAO_ATTRIBUTE11      => r_EAO.INFORMATION121
16115              ,P_EAO_ATTRIBUTE12      => r_EAO.INFORMATION122
16116              ,P_EAO_ATTRIBUTE13      => r_EAO.INFORMATION123
16117              ,P_EAO_ATTRIBUTE14      => r_EAO.INFORMATION124
16118              ,P_EAO_ATTRIBUTE15      => r_EAO.INFORMATION125
16119              ,P_EAO_ATTRIBUTE16      => r_EAO.INFORMATION126
16120              ,P_EAO_ATTRIBUTE17      => r_EAO.INFORMATION127
16121              ,P_EAO_ATTRIBUTE18      => r_EAO.INFORMATION128
16122              ,P_EAO_ATTRIBUTE19      => r_EAO.INFORMATION129
16123              ,P_EAO_ATTRIBUTE2      => r_EAO.INFORMATION112
16124              ,P_EAO_ATTRIBUTE20      => r_EAO.INFORMATION130
16125              ,P_EAO_ATTRIBUTE21      => r_EAO.INFORMATION131
16126              ,P_EAO_ATTRIBUTE22      => r_EAO.INFORMATION132
16127              ,P_EAO_ATTRIBUTE23      => r_EAO.INFORMATION133
16128              ,P_EAO_ATTRIBUTE24      => r_EAO.INFORMATION134
16129              ,P_EAO_ATTRIBUTE25      => r_EAO.INFORMATION135
16130              ,P_EAO_ATTRIBUTE26      => r_EAO.INFORMATION136
16131              ,P_EAO_ATTRIBUTE27      => r_EAO.INFORMATION137
16132              ,P_EAO_ATTRIBUTE28      => r_EAO.INFORMATION138
16133              ,P_EAO_ATTRIBUTE29      => r_EAO.INFORMATION139
16134              ,P_EAO_ATTRIBUTE3      => r_EAO.INFORMATION113
16135              ,P_EAO_ATTRIBUTE30      => r_EAO.INFORMATION140
16136              ,P_EAO_ATTRIBUTE4      => r_EAO.INFORMATION114
16137              ,P_EAO_ATTRIBUTE5      => r_EAO.INFORMATION115
16138              ,P_EAO_ATTRIBUTE6      => r_EAO.INFORMATION116
16139              ,P_EAO_ATTRIBUTE7      => r_EAO.INFORMATION117
16140              ,P_EAO_ATTRIBUTE8      => r_EAO.INFORMATION118
16141              ,P_EAO_ATTRIBUTE9      => r_EAO.INFORMATION119
16142              ,P_EAO_ATTRIBUTE_CATEGORY      => r_EAO.INFORMATION110
16143              ,P_ENRLD_ANTHR_OIPL_RT_ID      => l_enrld_anthr_oipl_rt_id
16144              ,P_ENRL_DET_DT_CD      => r_EAO.INFORMATION12
16145              ,P_EXCLD_FLAG      => r_EAO.INFORMATION11
16146              ,P_OIPL_ID      => l_OIPL_ID
16147              ,P_ORDR_NUM      => r_EAO.INFORMATION261
16148              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
16149              --
16150              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
16151              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
16152              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
16153              ,P_DATETRACK_MODE        => l_datetrack_mode
16154            );
16155            --
16156            end if;
16157          end if;
16158          --
16159          -- Delete the row if it is end dated.
16160          --
16161          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
16162              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
16163              trunc(l_max_eed) = r_EAO.information3) then
16164              --
16165              BEN_ENRLD_ANTHR_OIPL_RT_API.delete_ENRLD_ANTHR_OIPL_RT(
16166                 --
16167                 p_validate                       => false
16168                 ,p_enrld_anthr_oipl_rt_id                   => l_enrld_anthr_oipl_rt_id
16169                 ,p_effective_start_date           => l_effective_start_date
16170                 ,p_effective_end_date             => l_effective_end_date
16171                 ,p_object_version_number          => l_object_version_number
16172                 ,p_effective_date                 => l_max_eed
16173                 ,p_datetrack_mode                 => hr_api.g_delete
16174                 --
16175                 );
16176                 --
16177          end if;
16178          --
16179          l_prev_pk_id := l_current_pk_id ;
16180          --
16181        end if;
16182        --
16183      end if;
16184      --
16185    end loop;
16186    --
16187  exception when others then
16188     --
16189     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'EAO',r_eao.information5 );
16190     --
16191  end create_EAO_rows;
16192 
16193    ---------------------------------------------------------------
16194    ----------------------< create_DOT_rows >-----------------------
16195    ---------------------------------------------------------------
16196    --
16197    procedure create_DOT_rows
16198    (
16199          p_validate                       in  number     default 0
16200         ,p_copy_entity_txn_id             in  number
16201         ,p_effective_date                 in  date
16202         ,p_prefix_suffix_text             in  varchar2  default null
16203         ,p_reuse_object_flag              in  varchar2  default null
16204         ,p_target_business_group_id       in  varchar2  default null
16205         ,p_prefix_suffix_cd               in  varchar2  default null
16206    ) is
16207    --
16208    l_PTIP_ID  number;
16209    l_VRBL_RT_PRFL_ID  number;
16210    cursor c_unique_DOT(l_table_alias varchar2) is
16211    select distinct cpe.information1,
16212      cpe.information2,
16213      cpe.information3,
16214      cpe.table_route_id
16215    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
16216         pqh_table_route tr
16217    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
16218    and   cpe.table_route_id     = tr.table_route_id
16219    -- and   tr.where_clause        = l_BEN_DPNT_OTHR_PTIP_RT_F
16220    and tr.table_alias = l_table_alias
16221    and   cpe.number_of_copies   = 1 -- ADDITION
16222    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
16223    order by information1, information2; --added for bug: 5151945
16224    --
16225    --
16226    cursor c_DOT_min_max_dates(c_table_route_id  number,
16227                 c_information1   number) is
16228    select
16229      min(cpe.information2) min_esd,
16230      max(cpe.information3) min_eed
16231    from ben_copy_entity_results cpe
16232    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
16233    and   cpe.table_route_id     = c_table_route_id
16234    and   cpe.information1       = c_information1 ;
16235    --
16236    cursor c_DOT(c_table_route_id  number,
16237                 c_information1   number,
16238                 c_information2   Date,
16239                 c_information3   Date)  is
16240    select
16241      cpe.*
16242    from ben_copy_entity_results cpe
16243    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
16244    and   cpe.table_route_id     = c_table_route_id
16245    and   cpe.information1       = c_information1
16246    and   cpe.information2       = c_information2
16247    and   cpe.information3       = c_information3
16248    and rownum = 1 ;
16249    -- Date Track target record
16250    cursor c_find_DOT_in_target(
16251                                 c_effective_start_date    date,
16252                                 c_effective_end_date      date,
16253                                 c_business_group_id       number,
16254                                 c_new_pk_id               number) is
16255    select
16256      DOT.dpnt_othr_ptip_rt_id new_value
16257    from BEN_DPNT_OTHR_PTIP_RT_F DOT
16258    where
16259    DOT.PTIP_ID     = l_PTIP_ID  and
16260    DOT.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
16261    DOT.business_group_id  = c_business_group_id
16262    and   DOT.dpnt_othr_ptip_rt_id  <> c_new_pk_id
16263 --TEMPIK
16264    and c_effective_start_date between effective_start_date
16265                             and effective_end_date ;
16266 --END TEMPIK
16267 /*TEMPIK
16268    and exists ( select null
16269                 from BEN_DPNT_OTHR_PTIP_RT_F DOT1
16270                 where
16271                 DOT1.PTIP_ID     = l_PTIP_ID  and
16272                 DOT1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
16273                 DOT1.business_group_id  = c_business_group_id
16274                 and   DOT1.effective_start_date <= c_effective_start_date )
16275    and exists ( select null
16276                 from BEN_DPNT_OTHR_PTIP_RT_F DOT2
16277                 where
16278                 DOT2.PTIP_ID     = l_PTIP_ID  and
16279                 DOT2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
16280                 DOT2.business_group_id  = c_business_group_id
16281                 and   DOT2.effective_end_date >= c_effective_end_date )
16282                 ;
16283 TEMPIK */
16284    --TEMPIK
16285    l_dt_rec_found            boolean ;
16286    --END TEMPIK
16287    --
16288    l_current_pk_id           number := null ;
16289    --UPD START
16290    --
16291    l_update                  boolean      := false ;
16292    l_datetrack_mode          varchar2(80) := hr_api.g_update;
16293    l_process_date            date;
16294    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
16295    --
16296    --UPD END
16297    l_prev_pk_id              number := null ;
16298    l_first_rec               boolean := true ;
16299    r_DOT                     c_DOT%rowtype;
16300    l_dpnt_othr_ptip_rt_id             number ;
16301    l_object_version_number   number ;
16302    l_effective_start_date    date ;
16303    l_effective_end_date      date ;
16304    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
16305    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
16306    l_new_value               number(15);
16307    l_object_found_in_target  boolean := false ;
16308    l_min_esd                 date;
16309    l_max_eed                 date;
16310    l_effective_date          date;
16311    --
16312  begin
16313    -- Initialization
16314    l_object_found_in_target := false ;
16315    -- End Initialization
16316    -- Derive the prefix - sufix
16317    if   p_prefix_suffix_cd = 'PREFIX' then
16318      l_prefix  := p_prefix_suffix_text ;
16319    elsif p_prefix_suffix_cd = 'SUFFIX' then
16320      l_suffix   := p_prefix_suffix_text ;
16321    else
16322      l_prefix := null ;
16323      l_suffix  := null ;
16324    end if ;
16325    -- End Prefix Sufix derivation
16326    for r_DOT_unique in c_unique_DOT('DOT') loop
16327 
16328      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
16329         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
16330          r_DOT_unique.information3 >=
16331                  ben_pd_copy_to_ben_one.g_copy_effective_date)
16332         ) then
16333        --
16334        hr_utility.set_location(' r_DOT_unique.table_route_id '||r_DOT_unique.table_route_id,10);
16335        hr_utility.set_location(' r_DOT_unique.information1 '||r_DOT_unique.information1,10);
16336        hr_utility.set_location( 'r_DOT_unique.information2 '||r_DOT_unique.information2,10);
16337        hr_utility.set_location( 'r_DOT_unique.information3 '||r_DOT_unique.information3,10);
16338        -- If reuse objects flag is 'Y' then check for the object in the target business group
16339        -- if found insert the record into PLSql table and exit the loop else try create the
16340        -- object in the target business group
16341        --
16342        l_object_found_in_target := false ;
16343        l_min_esd := null ;
16344        l_max_eed := null ;
16345        open c_DOT_min_max_dates(r_DOT_unique.table_route_id, r_DOT_unique.information1 ) ;
16346        fetch c_DOT_min_max_dates into l_min_esd,l_max_eed ;
16347        --
16348 
16349        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
16350             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
16351          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
16352        end if;
16353        l_min_esd := greatest(l_min_esd,r_DOT_unique.information2);
16354        open c_DOT(r_DOT_unique.table_route_id,
16355                 r_DOT_unique.information1,
16356                 r_DOT_unique.information2,
16357                 r_DOT_unique.information3 ) ;
16358        --
16359        fetch c_DOT into r_DOT ;
16360        --
16361        close c_DOT ;
16362        --
16363        -- Only For Use by Create Wizard - Same Business Group
16364        l_PTIP_ID := NVL(get_fk('PTIP_ID', r_DOT.information259,r_DOT_unique.dml_operation),
16365                         r_DOT.information259);
16366 
16367        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_DOT.information262,r_DOT_unique.dml_operation);
16368        --UPD START
16369        l_update := false;
16370        l_process_date := p_effective_date;
16371        l_dml_operation:= r_DOT_unique.dml_operation ;
16372        --
16373        if l_dml_operation = 'UPDATE' then
16374          --
16375          l_object_found_in_target := TRUE;
16376          --
16377          if l_process_date between r_DOT_unique.information2 and r_DOT_unique.information3 then
16378                l_update := true;
16379                if r_DOT_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
16380                  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_OTHR_PTIP_RT_ID'
16381                then
16382                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'DPNT_OTHR_PTIP_RT_ID' ;
16383                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_DOT_unique.information1 ;
16384                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_DOT_unique.information1 ;
16385                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
16386                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_DOT_unique.table_route_id;
16387                   --
16388                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
16389                   --
16390                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
16391                   --
16392                   -- log_data('DOT',l_new_value,l_prefix || r_DOT_unique.name|| l_suffix,'REUSED');
16393                   --
16394                end if ;
16395                hr_utility.set_location( 'found record for update',10);
16396            --
16397          else
16398            --
16399            l_update := false;
16400            --
16401          end if;
16402        else
16403          --
16404          --UPD END
16405        if p_reuse_object_flag = 'Y' then
16406          if c_DOT_min_max_dates%found then
16407            -- cursor to find the object
16408            open c_find_DOT_in_target( l_min_esd,l_max_eed,
16409                                  p_target_business_group_id, nvl(l_dpnt_othr_ptip_rt_id, -999)  ) ;
16410            fetch c_find_DOT_in_target into l_new_value ;
16411            if c_find_DOT_in_target%found then
16412              --
16413              --TEMPIK
16414              l_dt_rec_found :=   dt_api.check_min_max_dates
16415                  (p_base_table_name => 'BEN_DPNT_OTHR_PTIP_RT_F',
16416                   p_base_key_column => 'DPNT_OTHR_PTIP_RT_ID',
16417                   p_base_key_value  => l_new_value,
16418                   p_from_date       => l_min_esd,
16419                   p_to_date         => l_max_eed );
16420              if l_dt_rec_found THEN
16421              --END TEMPIK
16422              if r_DOT_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
16423                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'DPNT_OTHR_PTIP_RT_ID'  then
16424                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'DPNT_OTHR_PTIP_RT_ID' ;
16425                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_DOT_unique.information1 ;
16426                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
16427                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
16428                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_DOT_unique.table_route_id;
16429                 --
16430                 -- 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) ;
16431                 --
16432                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
16433              end if ;
16434              --
16435              l_object_found_in_target := true ;
16436              --TEMPIK
16437              end if; -- l_dt_rec_found
16438              --END TEMPIK
16439            end if;
16440            close c_find_DOT_in_target ;
16441          --
16442          end if;
16443        end if ;
16444        --
16445        end if;
16446        close c_DOT_min_max_dates ;
16447        if not l_object_found_in_target OR l_update   then
16448          --
16449          l_current_pk_id := r_DOT.information1;
16450          --
16451          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
16452          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
16453          --
16454          if l_current_pk_id =  l_prev_pk_id  then
16455            --
16456            l_first_rec := false ;
16457            --
16458          else
16459            --
16460            l_first_rec := true ;
16461            --
16462          end if ;
16463          --
16464 
16465          l_effective_date := r_DOT.information2;
16466          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
16467               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
16468            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
16469          end if;
16470 
16471          if l_first_rec and not l_update then
16472            -- Call Create routine.
16473            hr_utility.set_location(' BEN_DPNT_OTHR_PTIP_RT_F CREATE_DPNT_OTHR_PTIP_RT ',20);
16474            BEN_DPNT_OTHR_PTIP_RT_API.CREATE_DPNT_OTHR_PTIP_RT(
16475              --
16476              P_VALIDATE               => false
16477              ,P_EFFECTIVE_DATE        => l_effective_date
16478              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
16479              --
16480              ,P_DOT_ATTRIBUTE1      => r_DOT.INFORMATION111
16481              ,P_DOT_ATTRIBUTE10      => r_DOT.INFORMATION120
16482              ,P_DOT_ATTRIBUTE11      => r_DOT.INFORMATION121
16483              ,P_DOT_ATTRIBUTE12      => r_DOT.INFORMATION122
16484              ,P_DOT_ATTRIBUTE13      => r_DOT.INFORMATION123
16485              ,P_DOT_ATTRIBUTE14      => r_DOT.INFORMATION124
16486              ,P_DOT_ATTRIBUTE15      => r_DOT.INFORMATION125
16487              ,P_DOT_ATTRIBUTE16      => r_DOT.INFORMATION126
16488              ,P_DOT_ATTRIBUTE17      => r_DOT.INFORMATION127
16489              ,P_DOT_ATTRIBUTE18      => r_DOT.INFORMATION128
16490              ,P_DOT_ATTRIBUTE19      => r_DOT.INFORMATION129
16491              ,P_DOT_ATTRIBUTE2      => r_DOT.INFORMATION112
16492              ,P_DOT_ATTRIBUTE20      => r_DOT.INFORMATION130
16493              ,P_DOT_ATTRIBUTE21      => r_DOT.INFORMATION131
16494              ,P_DOT_ATTRIBUTE22      => r_DOT.INFORMATION132
16495              ,P_DOT_ATTRIBUTE23      => r_DOT.INFORMATION133
16496              ,P_DOT_ATTRIBUTE24      => r_DOT.INFORMATION134
16497              ,P_DOT_ATTRIBUTE25      => r_DOT.INFORMATION135
16498              ,P_DOT_ATTRIBUTE26      => r_DOT.INFORMATION136
16499              ,P_DOT_ATTRIBUTE27      => r_DOT.INFORMATION137
16500              ,P_DOT_ATTRIBUTE28      => r_DOT.INFORMATION138
16501              ,P_DOT_ATTRIBUTE29      => r_DOT.INFORMATION139
16502              ,P_DOT_ATTRIBUTE3      => r_DOT.INFORMATION113
16503              ,P_DOT_ATTRIBUTE30      => r_DOT.INFORMATION140
16504              ,P_DOT_ATTRIBUTE4      => r_DOT.INFORMATION114
16505              ,P_DOT_ATTRIBUTE5      => r_DOT.INFORMATION115
16506              ,P_DOT_ATTRIBUTE6      => r_DOT.INFORMATION116
16507              ,P_DOT_ATTRIBUTE7      => r_DOT.INFORMATION117
16508              ,P_DOT_ATTRIBUTE8      => r_DOT.INFORMATION118
16509              ,P_DOT_ATTRIBUTE9      => r_DOT.INFORMATION119
16510              ,P_DOT_ATTRIBUTE_CATEGORY      => r_DOT.INFORMATION110
16511              ,P_DPNT_OTHR_PTIP_RT_ID      => l_dpnt_othr_ptip_rt_id
16512              ,P_EXCLD_FLAG      => r_DOT.INFORMATION11
16513              ,P_ORDR_NUM      => r_DOT.INFORMATION261
16514              ,P_PTIP_ID      => l_PTIP_ID
16515              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
16516              --
16517              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
16518              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
16519              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
16520            );
16521            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
16522            -- Update all relevent cer records with new pk_id
16523            hr_utility.set_location('Before plsql table ',222);
16524            hr_utility.set_location('new_value id '||l_dpnt_othr_ptip_rt_id,222);
16525            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'DPNT_OTHR_PTIP_RT_ID' ;
16526            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_DOT.information1 ;
16527            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_DPNT_OTHR_PTIP_RT_ID ;
16528            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
16529            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_DOT_unique.table_route_id;
16530            hr_utility.set_location('After plsql table ',222);
16531            --
16532            -- 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 ) ;
16533            --
16534            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
16535            --
16536          else
16537            --
16538            -- Call Update routine for the pk_id created in prev run .
16539            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
16540            --UPD START
16541            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
16542            --
16543            if l_update then
16544              --
16545              l_datetrack_mode := r_DOT.datetrack_mode ;
16546              --
16547              get_dt_modes(
16548                p_effective_date        => l_process_date,
16549                p_effective_end_date    => r_DOT.information3,
16550                p_effective_start_date  => r_DOT.information2,
16551                p_dml_operation         => r_DOT.dml_operation,
16552                p_datetrack_mode        => l_datetrack_mode );
16553            --    p_update                => l_update
16554              --
16555              l_effective_date := l_process_date;
16556              l_DPNT_OTHR_PTIP_RT_ID   := r_DOT.information1;
16557              l_object_version_number := r_DOT.information265;
16558              --
16559            end if;
16560            --
16561            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
16562            --
16563            IF l_update OR l_dml_operation <> 'UPDATE' THEN
16564            --UPD END
16565            hr_utility.set_location(' BEN_DPNT_OTHR_PTIP_RT_F UPDATE_DPNT_OTHR_PTIP_RT ',30);
16566            BEN_DPNT_OTHR_PTIP_RT_API.UPDATE_DPNT_OTHR_PTIP_RT(
16567              --
16568              P_VALIDATE               => false
16569              ,P_EFFECTIVE_DATE        => l_effective_date
16570              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
16571              --
16572               ,P_DOT_ATTRIBUTE1      => r_DOT.INFORMATION111
16573              ,P_DOT_ATTRIBUTE10      => r_DOT.INFORMATION120
16574              ,P_DOT_ATTRIBUTE11      => r_DOT.INFORMATION121
16575              ,P_DOT_ATTRIBUTE12      => r_DOT.INFORMATION122
16576              ,P_DOT_ATTRIBUTE13      => r_DOT.INFORMATION123
16577              ,P_DOT_ATTRIBUTE14      => r_DOT.INFORMATION124
16578              ,P_DOT_ATTRIBUTE15      => r_DOT.INFORMATION125
16579              ,P_DOT_ATTRIBUTE16      => r_DOT.INFORMATION126
16580              ,P_DOT_ATTRIBUTE17      => r_DOT.INFORMATION127
16581              ,P_DOT_ATTRIBUTE18      => r_DOT.INFORMATION128
16582              ,P_DOT_ATTRIBUTE19      => r_DOT.INFORMATION129
16583              ,P_DOT_ATTRIBUTE2      => r_DOT.INFORMATION112
16584              ,P_DOT_ATTRIBUTE20      => r_DOT.INFORMATION130
16585              ,P_DOT_ATTRIBUTE21      => r_DOT.INFORMATION131
16586              ,P_DOT_ATTRIBUTE22      => r_DOT.INFORMATION132
16587              ,P_DOT_ATTRIBUTE23      => r_DOT.INFORMATION133
16588              ,P_DOT_ATTRIBUTE24      => r_DOT.INFORMATION134
16589              ,P_DOT_ATTRIBUTE25      => r_DOT.INFORMATION135
16590              ,P_DOT_ATTRIBUTE26      => r_DOT.INFORMATION136
16591              ,P_DOT_ATTRIBUTE27      => r_DOT.INFORMATION137
16592              ,P_DOT_ATTRIBUTE28      => r_DOT.INFORMATION138
16593              ,P_DOT_ATTRIBUTE29      => r_DOT.INFORMATION139
16594              ,P_DOT_ATTRIBUTE3      => r_DOT.INFORMATION113
16595              ,P_DOT_ATTRIBUTE30      => r_DOT.INFORMATION140
16596              ,P_DOT_ATTRIBUTE4      => r_DOT.INFORMATION114
16597              ,P_DOT_ATTRIBUTE5      => r_DOT.INFORMATION115
16598              ,P_DOT_ATTRIBUTE6      => r_DOT.INFORMATION116
16599              ,P_DOT_ATTRIBUTE7      => r_DOT.INFORMATION117
16600              ,P_DOT_ATTRIBUTE8      => r_DOT.INFORMATION118
16601              ,P_DOT_ATTRIBUTE9      => r_DOT.INFORMATION119
16602              ,P_DOT_ATTRIBUTE_CATEGORY      => r_DOT.INFORMATION110
16603              ,P_DPNT_OTHR_PTIP_RT_ID      => l_dpnt_othr_ptip_rt_id
16604              ,P_EXCLD_FLAG      => r_DOT.INFORMATION11
16605              ,P_ORDR_NUM      => r_DOT.INFORMATION261
16606              ,P_PTIP_ID      => l_PTIP_ID
16607              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
16608              --
16609              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
16610              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
16611              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
16612              ,P_DATETRACK_MODE        => l_datetrack_mode
16613            );
16614            --
16615            end if;
16616          end if;
16617          --
16618          -- Delete the row if it is end dated.
16619          --
16620          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
16621              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
16622              trunc(l_max_eed) = r_DOT.information3) then
16623              --
16624              BEN_DPNT_OTHR_PTIP_RT_API.delete_DPNT_OTHR_PTIP_RT(
16625                 --
16626                 p_validate                       => false
16627                 ,p_dpnt_othr_ptip_rt_id                   => l_dpnt_othr_ptip_rt_id
16628                 ,p_effective_start_date           => l_effective_start_date
16629                 ,p_effective_end_date             => l_effective_end_date
16630                 ,p_object_version_number          => l_object_version_number
16631                 ,p_effective_date                 => l_max_eed
16632                 ,p_datetrack_mode                 => hr_api.g_delete
16633                 --
16634                 );
16635                 --
16636          end if;
16637          --
16638          l_prev_pk_id := l_current_pk_id ;
16639          --
16640        end if;
16641        --
16642      end if;
16643      --
16644    end loop;
16645    --
16646  exception when others then
16647     --
16648     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'DOT',r_dot.information5 );
16649     --
16650  end create_DOT_rows;
16651 
16652    ---------------------------------------------------------------
16653    ----------------------< create_DOP_rows >-----------------------
16654    ---------------------------------------------------------------
16655    --
16656    procedure create_DOP_rows
16657    (
16658          p_validate                       in  number     default 0
16659         ,p_copy_entity_txn_id             in  number
16660         ,p_effective_date                 in  date
16661         ,p_prefix_suffix_text             in  varchar2  default null
16662         ,p_reuse_object_flag              in  varchar2  default null
16663         ,p_target_business_group_id       in  varchar2  default null
16664         ,p_prefix_suffix_cd               in  varchar2  default null
16665    ) is
16666    --
16667    l_PGM_ID  number;
16668    l_VRBL_RT_PRFL_ID  number;
16669    cursor c_unique_DOP(l_table_alias varchar2) is
16670    select distinct cpe.information1,
16671      cpe.information2,
16672      cpe.information3,
16673      cpe.table_route_id
16674    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
16675         pqh_table_route tr
16676    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
16677    and   cpe.table_route_id     = tr.table_route_id
16678    -- and   tr.where_clause        = l_BEN_DPNT_CVRD_OTHR_PGM_RT_F
16679    and tr.table_alias = l_table_alias
16680    and   cpe.number_of_copies   = 1 -- ADDITION
16681    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
16682    order by information1, information2; --added for bug: 5151945
16683    --
16684    --
16685    cursor c_DOP_min_max_dates(c_table_route_id  number,
16686                 c_information1   number) is
16687    select
16688      min(cpe.information2) min_esd,
16689      max(cpe.information3) min_eed
16690    from ben_copy_entity_results cpe
16691    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
16692    and   cpe.table_route_id     = c_table_route_id
16693    and   cpe.information1       = c_information1 ;
16694    --
16695    cursor c_DOP(c_table_route_id  number,
16696                 c_information1   number,
16697                 c_information2   Date,
16698                 c_information3   Date)  is
16699    select
16700      cpe.*
16701    from ben_copy_entity_results cpe
16702    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
16703    and   cpe.table_route_id     = c_table_route_id
16704    and   cpe.information1       = c_information1
16705    and   cpe.information2       = c_information2
16706    and   cpe.information3       = c_information3
16707    and rownum = 1 ;
16708    -- Date Track target record
16709    cursor c_find_DOP_in_target(
16710                                 c_effective_start_date    date,
16711                                 c_effective_end_date      date,
16712                                 c_business_group_id       number,
16713                                 c_new_pk_id               number) is
16714    select
16715      DOP.dpnt_cvrd_othr_pgm_rt_id new_value
16716    from BEN_DPNT_CVRD_OTHR_PGM_RT_F DOP
16717    where
16718    DOP.PGM_ID     = l_PGM_ID  and
16719    DOP.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
16720    DOP.business_group_id  = c_business_group_id
16721    and   DOP.dpnt_cvrd_othr_pgm_rt_id  <> c_new_pk_id
16722 --TEMPIK
16723    and c_effective_start_date between effective_start_date
16724                             and effective_end_date ;
16725 --END TEMPIK
16726 /*TEMPIK
16727    and exists ( select null
16728                 from BEN_DPNT_CVRD_OTHR_PGM_RT_F DOP1
16729                 where
16730                 DOP1.PGM_ID     = l_PGM_ID  and
16731                 DOP1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
16732                 DOP1.business_group_id  = c_business_group_id
16733                 and   DOP1.effective_start_date <= c_effective_start_date )
16734    and exists ( select null
16735                 from BEN_DPNT_CVRD_OTHR_PGM_RT_F DOP2
16736                 where
16737                 DOP2.PGM_ID     = l_PGM_ID  and
16738                DOP2.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
16739                 DOP2.business_group_id  = c_business_group_id
16740                 and   DOP2.effective_end_date >= c_effective_end_date )
16741                 ;
16742 TEMPIK */
16743    --TEMPIK
16744    l_dt_rec_found            boolean ;
16745    --END TEMPIK
16746    --
16747    l_current_pk_id           number := null ;
16748    --UPD START
16749    --
16750    l_update                  boolean      := false ;
16751    l_datetrack_mode          varchar2(80) := hr_api.g_update;
16752    l_process_date            date;
16753    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
16754    --
16755    --UPD END
16756    l_prev_pk_id              number := null ;
16757    l_first_rec               boolean := true ;
16758    r_DOP                     c_DOP%rowtype;
16759    l_dpnt_cvrd_othr_pgm_rt_id             number ;
16760    l_object_version_number   number ;
16761    l_effective_start_date    date ;
16762    l_effective_end_date      date ;
16763    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
16764    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
16765    l_new_value               number(15);
16766    l_object_found_in_target  boolean := false ;
16767    l_min_esd                 date;
16768    l_max_eed                 date;
16769    l_effective_date          date;
16770    --
16771  begin
16772    -- Initialization
16773    l_object_found_in_target := false ;
16774    -- End Initialization
16775    -- Derive the prefix - sufix
16776    if   p_prefix_suffix_cd = 'PREFIX' then
16777      l_prefix  := p_prefix_suffix_text ;
16778    elsif p_prefix_suffix_cd = 'SUFFIX' then
16779      l_suffix   := p_prefix_suffix_text ;
16780    else
16781      l_prefix := null ;
16782      l_suffix  := null ;
16783    end if ;
16784    -- End Prefix Sufix derivation
16785    for r_DOP_unique in c_unique_DOP('DOP') loop
16786 
16787      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
16788         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
16789          r_DOP_unique.information3 >=
16790          ben_pd_copy_to_ben_one.g_copy_effective_date)
16791         ) then
16792        --
16793        hr_utility.set_location(' r_DOP_unique.table_route_id '||r_DOP_unique.table_route_id,10);
16794        hr_utility.set_location(' r_DOP_unique.information1 '||r_DOP_unique.information1,10);
16795        hr_utility.set_location( 'r_DOP_unique.information2 '||r_DOP_unique.information2,10);
16796        hr_utility.set_location( 'r_DOP_unique.information3 '||r_DOP_unique.information3,10);
16797        -- If reuse objects flag is 'Y' then check for the object in the target business group
16798        -- if found insert the record into PLSql table and exit the loop else try create the
16799        -- object in the target business group
16800        --
16801        l_object_found_in_target := false ;
16802        l_min_esd := null ;
16803        l_max_eed := null ;
16804        open c_DOP_min_max_dates(r_DOP_unique.table_route_id, r_DOP_unique.information1 ) ;
16805        fetch c_DOP_min_max_dates into l_min_esd,l_max_eed ;
16806        --
16807 
16808        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
16809             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
16810          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
16811        end if;
16812        l_min_esd := greatest(l_min_esd,r_DOP_unique.information2);
16813        open c_DOP(r_DOP_unique.table_route_id,
16814                 r_DOP_unique.information1,
16815                 r_DOP_unique.information2,
16816                 r_DOP_unique.information3 ) ;
16817        --
16818        fetch c_DOP into r_DOP ;
16819        --
16820        close c_DOP ;
16821        --
16822        -- Only For Use by Create Wizard - Same Business Group
16823        l_PGM_ID := NVL(get_fk('PGM_ID', r_DOP.information260,r_DOP_unique.dml_operation),
16824                        r_DOP.information260);
16825 
16826        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_DOP.information262,r_DOP_unique.dml_operation);
16827        --UPD START
16828        l_update := false;
16829        l_process_date := p_effective_date;
16830        l_dml_operation:= r_DOP_unique.dml_operation ;
16831        --
16832        if l_dml_operation = 'UPDATE' then
16833          --
16834          l_object_found_in_target := TRUE;
16835          --
16836          if l_process_date between r_DOP_unique.information2 and r_DOP_unique.information3 then
16837                l_update := true;
16838                if r_DOP_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
16839                  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_OTHR_PGM_RT_ID'
16840                then
16841                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'DPNT_CVRD_OTHR_PGM_RT_ID' ;
16842                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_DOP_unique.information1 ;
16843                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_DOP_unique.information1 ;
16844                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
16845                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_DOP_unique.table_route_id;
16846                   --
16847                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
16848                   --
16849                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
16850                   --
16851                   -- log_data('DOP',l_new_value,l_prefix || r_DOP_unique.name|| l_suffix,'REUSED');
16852                   --
16853                end if ;
16854                hr_utility.set_location( 'found record for update',10);
16855            --
16856          else
16857            --
16858            l_update := false;
16859            --
16860          end if;
16861        else
16862          --
16863          --UPD END
16864        if p_reuse_object_flag = 'Y' then
16865          if c_DOP_min_max_dates%found then
16866            -- cursor to find the object
16867            open c_find_DOP_in_target( l_min_esd,l_max_eed,
16868                                  p_target_business_group_id, nvl(l_dpnt_cvrd_othr_pgm_rt_id, -999)  ) ;
16869            fetch c_find_DOP_in_target into l_new_value ;
16870            if c_find_DOP_in_target%found then
16871              --
16872              --TEMPIK
16873              l_dt_rec_found :=   dt_api.check_min_max_dates
16874                  (p_base_table_name => 'BEN_DPNT_CVRD_OTHR_PGM_RT_F',
16875                   p_base_key_column => 'DPNT_CVRD_OTHR_PGM_RT_ID',
16876                   p_base_key_value  => l_new_value,
16877                   p_from_date       => l_min_esd,
16878                   p_to_date         => l_max_eed );
16879              if l_dt_rec_found THEN
16880              --END TEMPIK
16881              if r_DOP_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
16882                 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_OTHR_PGM_RT_ID'  then
16883                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'DPNT_CVRD_OTHR_PGM_RT_ID' ;
16884                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_DOP_unique.information1 ;
16885                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
16886                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
16887                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_DOP_unique.table_route_id;
16888                 --
16889                 -- 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) ;
16890                 --
16891                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
16892              end if ;
16893              --
16894              l_object_found_in_target := true ;
16895              --TEMPIK
16896              end if; -- l_dt_rec_found
16897              --END TEMPIK
16898            end if;
16899            close c_find_DOP_in_target ;
16900          --
16901          end if;
16902        end if ;
16903        --
16904        end if;
16905        close c_DOP_min_max_dates ;
16906        if not l_object_found_in_target OR l_update   then
16907          --
16908          l_current_pk_id := r_DOP.information1;
16909          --
16910          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
16911          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
16912          --
16913          if l_current_pk_id =  l_prev_pk_id  then
16914            --
16915            l_first_rec := false ;
16916            --
16917          else
16918            --
16919            l_first_rec := true ;
16920            --
16921          end if ;
16922          --
16923 
16924          l_effective_date := r_DOP.information2;
16925          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
16926               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
16927            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
16928          end if;
16929 
16930          if l_first_rec and not l_update then
16931            -- Call Create routine.
16932            hr_utility.set_location(' BEN_DPNT_CVRD_OTHR_PGM_RT_F CREATE_DPNT_CVRD_OTHR_PGM_RT ',20);
16933            BEN_DPNT_CVRD_OTHR_PGM_RT_API.CREATE_DPNT_CVRD_OTHR_PGM_RT(
16934              --
16935              P_VALIDATE               => false
16936              ,P_EFFECTIVE_DATE        => l_effective_date
16937              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
16938              --
16939               ,P_DOP_ATTRIBUTE1      => r_DOP.INFORMATION111
16940              ,P_DOP_ATTRIBUTE10      => r_DOP.INFORMATION120
16941              ,P_DOP_ATTRIBUTE11      => r_DOP.INFORMATION121
16942              ,P_DOP_ATTRIBUTE12      => r_DOP.INFORMATION122
16943              ,P_DOP_ATTRIBUTE13      => r_DOP.INFORMATION123
16944              ,P_DOP_ATTRIBUTE14      => r_DOP.INFORMATION124
16945              ,P_DOP_ATTRIBUTE15      => r_DOP.INFORMATION125
16946              ,P_DOP_ATTRIBUTE16      => r_DOP.INFORMATION126
16947              ,P_DOP_ATTRIBUTE17      => r_DOP.INFORMATION127
16948              ,P_DOP_ATTRIBUTE18      => r_DOP.INFORMATION128
16949              ,P_DOP_ATTRIBUTE19      => r_DOP.INFORMATION129
16950              ,P_DOP_ATTRIBUTE2      => r_DOP.INFORMATION112
16951              ,P_DOP_ATTRIBUTE20      => r_DOP.INFORMATION130
16952              ,P_DOP_ATTRIBUTE21      => r_DOP.INFORMATION131
16953              ,P_DOP_ATTRIBUTE22      => r_DOP.INFORMATION132
16954              ,P_DOP_ATTRIBUTE23      => r_DOP.INFORMATION133
16955              ,P_DOP_ATTRIBUTE24      => r_DOP.INFORMATION134
16956              ,P_DOP_ATTRIBUTE25      => r_DOP.INFORMATION135
16957              ,P_DOP_ATTRIBUTE26      => r_DOP.INFORMATION136
16958              ,P_DOP_ATTRIBUTE27      => r_DOP.INFORMATION137
16959              ,P_DOP_ATTRIBUTE28      => r_DOP.INFORMATION138
16960              ,P_DOP_ATTRIBUTE29      => r_DOP.INFORMATION139
16961              ,P_DOP_ATTRIBUTE3      => r_DOP.INFORMATION113
16962              ,P_DOP_ATTRIBUTE30      => r_DOP.INFORMATION140
16963              ,P_DOP_ATTRIBUTE4      => r_DOP.INFORMATION114
16964              ,P_DOP_ATTRIBUTE5      => r_DOP.INFORMATION115
16965              ,P_DOP_ATTRIBUTE6      => r_DOP.INFORMATION116
16966              ,P_DOP_ATTRIBUTE7      => r_DOP.INFORMATION117
16967              ,P_DOP_ATTRIBUTE8      => r_DOP.INFORMATION118
16968              ,P_DOP_ATTRIBUTE9      => r_DOP.INFORMATION119
16969              ,P_DOP_ATTRIBUTE_CATEGORY      => r_DOP.INFORMATION110
16970              ,P_DPNT_CVRD_OTHR_PGM_RT_ID      => l_dpnt_cvrd_othr_pgm_rt_id
16971              ,P_ENRL_DET_DT_CD      => r_DOP.INFORMATION13
16972              ,P_EXCLD_FLAG      => r_DOP.INFORMATION11
16973              ,P_ONLY_PLS_SUBJ_COBRA_FLAG      => r_DOP.INFORMATION12
16974              ,P_ORDR_NUM      => r_DOP.INFORMATION261
16975              ,P_PGM_ID      => l_PGM_ID
16976              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
16977              --
16978              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
16979              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
16980              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
16981            );
16982            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
16983            -- Update all relevent cer records with new pk_id
16984            hr_utility.set_location('Before plsql table ',222);
16985            hr_utility.set_location('new_value id '||l_dpnt_cvrd_othr_pgm_rt_id,222);
16986            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'DPNT_CVRD_OTHR_PGM_RT_ID' ;
16987            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_DOP.information1 ;
16988            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_DPNT_CVRD_OTHR_PGM_RT_ID ;
16989            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
16990            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_DOP_unique.table_route_id;
16991            hr_utility.set_location('After plsql table ',222);
16992            --
16993            -- 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 ) ;
16994            --
16995            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
16996            --
16997          else
16998            --
16999            -- Call Update routine for the pk_id created in prev run .
17000            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
17001            --UPD START
17002            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
17003            --
17004            if l_update then
17005              --
17006              l_datetrack_mode := r_DOP.datetrack_mode ;
17007              --
17008              get_dt_modes(
17009                p_effective_date        => l_process_date,
17010                p_effective_end_date    => r_DOP.information3,
17011                p_effective_start_date  => r_DOP.information2,
17012                p_dml_operation         => r_DOP.dml_operation,
17013                p_datetrack_mode        => l_datetrack_mode );
17014            --    p_update                => l_update
17015              --
17016              l_effective_date := l_process_date;
17017              l_DPNT_CVRD_OTHR_PGM_RT_ID   := r_DOP.information1;
17018              l_object_version_number := r_DOP.information265;
17019              --
17020            end if;
17021            --
17022            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
17023            --
17024            IF l_update OR l_dml_operation <> 'UPDATE' THEN
17025            --UPD END
17026            hr_utility.set_location(' BEN_DPNT_CVRD_OTHR_PGM_RT_F UPDATE_DPNT_CVRD_OTHR_PGM_RT ',30);
17027            BEN_DPNT_CVRD_OTHR_PGM_RT_API.UPDATE_DPNT_CVRD_OTHR_PGM_RT(
17028              --
17029              P_VALIDATE               => false
17030              ,P_EFFECTIVE_DATE        => l_effective_date
17031              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
17032              --
17033             ,P_DOP_ATTRIBUTE1      => r_DOP.INFORMATION111
17034              ,P_DOP_ATTRIBUTE10      => r_DOP.INFORMATION120
17035              ,P_DOP_ATTRIBUTE11      => r_DOP.INFORMATION121
17036              ,P_DOP_ATTRIBUTE12      => r_DOP.INFORMATION122
17037              ,P_DOP_ATTRIBUTE13      => r_DOP.INFORMATION123
17038              ,P_DOP_ATTRIBUTE14      => r_DOP.INFORMATION124
17039              ,P_DOP_ATTRIBUTE15      => r_DOP.INFORMATION125
17040              ,P_DOP_ATTRIBUTE16      => r_DOP.INFORMATION126
17041              ,P_DOP_ATTRIBUTE17      => r_DOP.INFORMATION127
17042              ,P_DOP_ATTRIBUTE18      => r_DOP.INFORMATION128
17043              ,P_DOP_ATTRIBUTE19      => r_DOP.INFORMATION129
17044              ,P_DOP_ATTRIBUTE2      => r_DOP.INFORMATION112
17045              ,P_DOP_ATTRIBUTE20      => r_DOP.INFORMATION130
17046              ,P_DOP_ATTRIBUTE21      => r_DOP.INFORMATION131
17047              ,P_DOP_ATTRIBUTE22      => r_DOP.INFORMATION132
17048              ,P_DOP_ATTRIBUTE23      => r_DOP.INFORMATION133
17049              ,P_DOP_ATTRIBUTE24      => r_DOP.INFORMATION134
17050              ,P_DOP_ATTRIBUTE25      => r_DOP.INFORMATION135
17051              ,P_DOP_ATTRIBUTE26      => r_DOP.INFORMATION136
17052              ,P_DOP_ATTRIBUTE27      => r_DOP.INFORMATION137
17053              ,P_DOP_ATTRIBUTE28      => r_DOP.INFORMATION138
17054              ,P_DOP_ATTRIBUTE29      => r_DOP.INFORMATION139
17055              ,P_DOP_ATTRIBUTE3      => r_DOP.INFORMATION113
17056              ,P_DOP_ATTRIBUTE30      => r_DOP.INFORMATION140
17057              ,P_DOP_ATTRIBUTE4      => r_DOP.INFORMATION114
17058              ,P_DOP_ATTRIBUTE5      => r_DOP.INFORMATION115
17059              ,P_DOP_ATTRIBUTE6      => r_DOP.INFORMATION116
17060              ,P_DOP_ATTRIBUTE7      => r_DOP.INFORMATION117
17061              ,P_DOP_ATTRIBUTE8      => r_DOP.INFORMATION118
17062              ,P_DOP_ATTRIBUTE9      => r_DOP.INFORMATION119
17063              ,P_DOP_ATTRIBUTE_CATEGORY      => r_DOP.INFORMATION110
17064              ,P_DPNT_CVRD_OTHR_PGM_RT_ID      => l_dpnt_cvrd_othr_pgm_rt_id
17065              ,P_ENRL_DET_DT_CD      => r_DOP.INFORMATION13
17066              ,P_EXCLD_FLAG      => r_DOP.INFORMATION11
17067              ,P_ONLY_PLS_SUBJ_COBRA_FLAG      => r_DOP.INFORMATION12
17068              ,P_ORDR_NUM      => r_DOP.INFORMATION261
17069              ,P_PGM_ID      => l_PGM_ID
17070              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
17071              --
17072              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
17073              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
17074              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
17075              ,P_DATETRACK_MODE        => l_datetrack_mode
17076            );
17077            --
17078            end if;
17079          end if;
17080          --
17081          -- Delete the row if it is end dated.
17082          --
17083          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
17084              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
17085              trunc(l_max_eed) = r_DOP.information3) then
17086              --
17087              BEN_DPNT_CVRD_OTHR_PGM_RT_API.delete_DPNT_CVRD_OTHR_PGM_RT(
17088                 --
17089                 p_validate                       => false
17090                 ,p_dpnt_cvrd_othr_pgm_rt_id                   => l_dpnt_cvrd_othr_pgm_rt_id
17091                 ,p_effective_start_date           => l_effective_start_date
17092                 ,p_effective_end_date             => l_effective_end_date
17093                 ,p_object_version_number          => l_object_version_number
17094                 ,p_effective_date                 => l_max_eed
17095                 ,p_datetrack_mode                 => hr_api.g_delete
17096                 --
17097                 );
17098                 --
17099          end if;
17100          --
17101          l_prev_pk_id := l_current_pk_id ;
17102          --
17103        end if;
17104        --
17105      end if;
17106      --
17107    end loop;
17108    --
17109  exception when others then
17110     --
17111     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'DOP',r_dop.information5 );
17112     --
17113  end create_DOP_rows;
17114 
17115    ---------------------------------------------------------------
17116    ----------------------< create_DCP_rows >-----------------------
17117    ---------------------------------------------------------------
17118    --
17119    procedure create_DCP_rows
17120    (
17121          p_validate                       in  number     default 0
17122         ,p_copy_entity_txn_id             in  number
17123         ,p_effective_date                 in  date
17124         ,p_prefix_suffix_text             in  varchar2  default null
17125         ,p_reuse_object_flag              in  varchar2  default null
17126         ,p_target_business_group_id       in  varchar2  default null
17127         ,p_prefix_suffix_cd               in  varchar2  default null
17128    ) is
17129    --
17130    l_PLIP_ID  number;
17131    l_VRBL_RT_PRFL_ID  number;
17132    cursor c_unique_DCP(l_table_alias varchar2) is
17133    select distinct cpe.information1,
17134      cpe.information2,
17135      cpe.information3,
17136      cpe.table_route_id
17137    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
17138         pqh_table_route tr
17139    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
17140    and   cpe.table_route_id     = tr.table_route_id
17141    -- and   tr.where_clause        = l_BEN_DPNT_CVRD_PLIP_RT_F
17142    and tr.table_alias = l_table_alias
17143    and   cpe.number_of_copies   = 1 -- ADDITION
17144    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
17145    order by information1, information2; --added for bug: 5151945
17146    --
17147    --
17148    cursor c_DCP_min_max_dates(c_table_route_id  number,
17149                 c_information1   number) is
17150    select
17151      min(cpe.information2) min_esd,
17152      max(cpe.information3) min_eed
17153    from ben_copy_entity_results cpe
17154    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
17155    and   cpe.table_route_id     = c_table_route_id
17156    and   cpe.information1       = c_information1 ;
17157    --
17158    cursor c_DCP(c_table_route_id  number,
17159                 c_information1   number,
17160                 c_information2   Date,
17161                 c_information3   Date)  is
17162    select
17163      cpe.*
17164    from ben_copy_entity_results cpe
17165    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
17166    and   cpe.table_route_id     = c_table_route_id
17167    and   cpe.information1       = c_information1
17168    and   cpe.information2       = c_information2
17169    and   cpe.information3       = c_information3
17170    and rownum = 1 ;
17171    -- Date Track target record
17172    cursor c_find_DCP_in_target(
17173                                 c_effective_start_date    date,
17174                                 c_effective_end_date      date,
17175                                 c_business_group_id       number,
17176                                 c_new_pk_id               number) is
17177    select
17178      DCP.dpnt_cvrd_plip_rt_id new_value
17179    from BEN_DPNT_CVRD_PLIP_RT_F DCP
17180    where
17181    DCP.PLIP_ID     = l_PLIP_ID  and
17182    DCP.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
17183    DCP.business_group_id  = c_business_group_id
17184    and   DCP.dpnt_cvrd_plip_rt_id  <> c_new_pk_id
17185 --TEMPIK
17186    and c_effective_start_date between effective_start_date
17187                             and effective_end_date ;
17188 --END TEMPIK
17189 /*TEMPIK
17190    and exists ( select null
17191                 from BEN_DPNT_CVRD_PLIP_RT_F DCP1
17192                 where
17193                 DCP1.PLIP_ID     = l_PLIP_ID  and
17194                 DCP1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
17195                 DCP1.business_group_id  = c_business_group_id
17196                 and   DCP1.effective_start_date <= c_effective_start_date )
17197    and exists ( select null
17198                 from BEN_DPNT_CVRD_PLIP_RT_F DCP2
17199                 where
17200                 DCP2.PLIP_ID     = l_PLIP_ID  and
17201                 DCP2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
17202                 DCP2.business_group_id  = c_business_group_id
17203                 and   DCP2.effective_end_date >= c_effective_end_date )
17204                 ;
17205 TEMPIK */
17206    --TEMPIK
17207    l_dt_rec_found            boolean ;
17208    --END TEMPIK
17209    --
17210    l_current_pk_id           number := null ;
17211    --UPD START
17212    --
17213    l_update                  boolean      := false ;
17214    l_datetrack_mode          varchar2(80) := hr_api.g_update;
17215    l_process_date            date;
17216    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
17217    --
17218    --UPD END
17219    l_prev_pk_id              number := null ;
17220    l_first_rec               boolean := true ;
17221    r_DCP                     c_DCP%rowtype;
17222    l_dpnt_cvrd_plip_rt_id             number ;
17223    l_object_version_number   number ;
17224    l_effective_start_date    date ;
17225    l_effective_end_date      date ;
17226    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
17227    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
17228    l_new_value               number(15);
17229    l_object_found_in_target  boolean := false ;
17230    l_min_esd                 date;
17231    l_max_eed                 date;
17232    l_effective_date          date;
17233    --
17234  begin
17235    -- Initialization
17236    l_object_found_in_target := false ;
17237    -- End Initialization
17238    -- Derive the prefix - sufix
17239    if   p_prefix_suffix_cd = 'PREFIX' then
17240      l_prefix  := p_prefix_suffix_text ;
17241    elsif p_prefix_suffix_cd = 'SUFFIX' then
17242      l_suffix   := p_prefix_suffix_text ;
17243    else
17244      l_prefix := null ;
17245      l_suffix  := null ;
17246    end if ;
17247    -- End Prefix Sufix derivation
17248    for r_DCP_unique in c_unique_DCP('DCP') loop
17249 
17250      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
17251         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
17252          r_DCP_unique.information3 >=
17253                  ben_pd_copy_to_ben_one.g_copy_effective_date)
17254         ) then
17255        --
17256        hr_utility.set_location(' r_DCP_unique.table_route_id '||r_DCP_unique.table_route_id,10);
17257        hr_utility.set_location(' r_DCP_unique.information1 '||r_DCP_unique.information1,10);
17258        hr_utility.set_location( 'r_DCP_unique.information2 '||r_DCP_unique.information2,10);
17259        hr_utility.set_location( 'r_DCP_unique.information3 '||r_DCP_unique.information3,10);
17260        -- If reuse objects flag is 'Y' then check for the object in the target business group
17261        -- if found insert the record into PLSql table and exit the loop else try create the
17262        -- object in the target business group
17263        --
17264        l_object_found_in_target := false ;
17265        l_min_esd := null ;
17266        l_max_eed := null ;
17267        open c_DCP_min_max_dates(r_DCP_unique.table_route_id, r_DCP_unique.information1 ) ;
17268        fetch c_DCP_min_max_dates into l_min_esd,l_max_eed ;
17269        --
17270 
17271        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
17272             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
17273          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
17274        end if;
17275        l_min_esd := greatest(l_min_esd,r_DCP_unique.information2);
17276        open c_DCP(r_DCP_unique.table_route_id,
17277                 r_DCP_unique.information1,
17278                 r_DCP_unique.information2,
17279                 r_DCP_unique.information3 ) ;
17280        --
17281        fetch c_DCP into r_DCP ;
17282        --
17283        close c_DCP ;
17284        --
17285        -- Only For Use by Create Wizard - Same Business Group
17286        l_PLIP_ID := NVL(get_fk('PLIP_ID', r_DCP.information256,r_DCP_unique.dml_operation),
17287                         r_DCP.information256);
17288 
17289        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_DCP.information262,r_DCP_unique.dml_operation);
17290        --UPD START
17291        l_update := false;
17292        l_process_date := p_effective_date;
17293        l_dml_operation:= r_DCP_unique.dml_operation ;
17294        --
17295        if l_dml_operation = 'UPDATE' then
17296          --
17297          l_object_found_in_target := TRUE;
17298          --
17299          if l_process_date between r_DCP_unique.information2 and r_DCP_unique.information3 then
17300                l_update := true;
17301                if r_DCP_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
17302                  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_PLIP_RT_ID'
17303                then
17304                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'DPNT_CVRD_PLIP_RT_ID' ;
17305                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_DCP_unique.information1 ;
17306                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_DCP_unique.information1 ;
17307                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
17308                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_DCP_unique.table_route_id;
17309                   --
17310                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
17311                   --
17312                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
17313                   --
17314                   -- log_data('DCP',l_new_value,l_prefix || r_DCP_unique.name|| l_suffix,'REUSED');
17315                   --
17316                end if ;
17317                hr_utility.set_location( 'found record for update',10);
17318            --
17319          else
17320            --
17321            l_update := false;
17322            --
17323          end if;
17324        else
17325          --
17326          --UPD END
17327        if p_reuse_object_flag = 'Y' then
17328          if c_DCP_min_max_dates%found then
17329            -- cursor to find the object
17330            open c_find_DCP_in_target( l_min_esd,l_max_eed,
17331                                  p_target_business_group_id, nvl(l_dpnt_cvrd_plip_rt_id, -999)  ) ;
17332            fetch c_find_DCP_in_target into l_new_value ;
17333            if c_find_DCP_in_target%found then
17334              --
17335              --TEMPIK
17336              l_dt_rec_found :=   dt_api.check_min_max_dates
17337                  (p_base_table_name => 'BEN_DPNT_CVRD_PLIP_RT_F',
17338                   p_base_key_column => 'DPNT_CVRD_PLIP_RT_ID',
17339                   p_base_key_value  => l_new_value,
17340                   p_from_date       => l_min_esd,
17341                   p_to_date         => l_max_eed );
17342              if l_dt_rec_found THEN
17343              --END TEMPIK
17344              if r_DCP_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
17345                 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_PLIP_RT_ID'  then
17346                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'DPNT_CVRD_PLIP_RT_ID' ;
17347                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_DCP_unique.information1 ;
17348                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
17349                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
17350                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_DCP_unique.table_route_id;
17351                 --
17352                 -- 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) ;
17353                 --
17354                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
17355              end if ;
17356              --
17357              l_object_found_in_target := true ;
17358              --TEMPIK
17359              end if; -- l_dt_rec_found
17360              --END TEMPIK
17361            end if;
17362            close c_find_DCP_in_target ;
17363          --
17364          end if;
17365        end if ;
17366        --
17367        end if;
17368        close c_DCP_min_max_dates ;
17369        if not l_object_found_in_target OR l_update   then
17370          --
17371          l_current_pk_id := r_DCP.information1;
17372          --
17373          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
17374          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
17375          --
17376          if l_current_pk_id =  l_prev_pk_id  then
17377            --
17378            l_first_rec := false ;
17379            --
17380          else
17381            --
17382            l_first_rec := true ;
17383            --
17384          end if ;
17385          --
17386 
17387          l_effective_date := r_DCP.information2;
17388          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
17389               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
17390            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
17391          end if;
17392 
17393          if l_first_rec and not l_update then
17394            -- Call Create routine.
17395            hr_utility.set_location(' BEN_DPNT_CVRD_PLIP_RT_F CREATE_DPNT_CVRD_PLIP_RT ',20);
17396            BEN_DPNT_CVRD_PLIP_RT_API.CREATE_DPNT_CVRD_PLIP_RT(
17397              --
17398              P_VALIDATE               => false
17399              ,P_EFFECTIVE_DATE        => l_effective_date
17400              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
17401              --
17402              ,P_DCP_ATTRIBUTE1      => r_DCP.INFORMATION111
17403              ,P_DCP_ATTRIBUTE10      => r_DCP.INFORMATION120
17404              ,P_DCP_ATTRIBUTE11      => r_DCP.INFORMATION121
17405              ,P_DCP_ATTRIBUTE12      => r_DCP.INFORMATION122
17406              ,P_DCP_ATTRIBUTE13      => r_DCP.INFORMATION123
17407              ,P_DCP_ATTRIBUTE14      => r_DCP.INFORMATION124
17408              ,P_DCP_ATTRIBUTE15      => r_DCP.INFORMATION125
17409              ,P_DCP_ATTRIBUTE16      => r_DCP.INFORMATION126
17410              ,P_DCP_ATTRIBUTE17      => r_DCP.INFORMATION127
17411              ,P_DCP_ATTRIBUTE18      => r_DCP.INFORMATION128
17412              ,P_DCP_ATTRIBUTE19      => r_DCP.INFORMATION129
17413              ,P_DCP_ATTRIBUTE2      => r_DCP.INFORMATION112
17414              ,P_DCP_ATTRIBUTE20      => r_DCP.INFORMATION130
17415              ,P_DCP_ATTRIBUTE21      => r_DCP.INFORMATION131
17416              ,P_DCP_ATTRIBUTE22      => r_DCP.INFORMATION132
17417              ,P_DCP_ATTRIBUTE23      => r_DCP.INFORMATION133
17418              ,P_DCP_ATTRIBUTE24      => r_DCP.INFORMATION134
17419              ,P_DCP_ATTRIBUTE25      => r_DCP.INFORMATION135
17420              ,P_DCP_ATTRIBUTE26      => r_DCP.INFORMATION136
17421              ,P_DCP_ATTRIBUTE27      => r_DCP.INFORMATION137
17422              ,P_DCP_ATTRIBUTE28      => r_DCP.INFORMATION138
17423              ,P_DCP_ATTRIBUTE29      => r_DCP.INFORMATION139
17424              ,P_DCP_ATTRIBUTE3      => r_DCP.INFORMATION113
17425              ,P_DCP_ATTRIBUTE30      => r_DCP.INFORMATION140
17426              ,P_DCP_ATTRIBUTE4      => r_DCP.INFORMATION114
17427              ,P_DCP_ATTRIBUTE5      => r_DCP.INFORMATION115
17428              ,P_DCP_ATTRIBUTE6      => r_DCP.INFORMATION116
17429              ,P_DCP_ATTRIBUTE7      => r_DCP.INFORMATION117
17430              ,P_DCP_ATTRIBUTE8      => r_DCP.INFORMATION118
17431              ,P_DCP_ATTRIBUTE9      => r_DCP.INFORMATION119
17432              ,P_DCP_ATTRIBUTE_CATEGORY      => r_DCP.INFORMATION110
17433              ,P_DPNT_CVRD_PLIP_RT_ID      => l_dpnt_cvrd_plip_rt_id
17434              ,P_ENRL_DET_DT_CD      => r_DCP.INFORMATION11
17435              ,P_EXCLD_FLAG      => r_DCP.INFORMATION12
17436              ,P_ORDR_NUM      => r_DCP.INFORMATION260
17437              ,P_PLIP_ID      => l_PLIP_ID
17438              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
17439              --
17440              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
17441              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
17442              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
17443            );
17444            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
17445            -- Update all relevent cer records with new pk_id
17446            hr_utility.set_location('Before plsql table ',222);
17447            hr_utility.set_location('new_value id '||l_dpnt_cvrd_plip_rt_id,222);
17448            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'DPNT_CVRD_PLIP_RT_ID' ;
17449            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_DCP.information1 ;
17450            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_DPNT_CVRD_PLIP_RT_ID ;
17451            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
17452            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_DCP_unique.table_route_id;
17453            hr_utility.set_location('After plsql table ',222);
17454            --
17455            -- 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 ) ;
17456            --
17457            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
17458            --
17459          else
17460            --
17461            -- Call Update routine for the pk_id created in prev run .
17462            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
17463            --UPD START
17464            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
17465            --
17466            if l_update then
17467              --
17468              l_datetrack_mode := r_DCP.datetrack_mode ;
17469              --
17470              get_dt_modes(
17471                p_effective_date        => l_process_date,
17472                p_effective_end_date    => r_DCP.information3,
17473                p_effective_start_date  => r_DCP.information2,
17474                p_dml_operation         => r_DCP.dml_operation,
17475                p_datetrack_mode        => l_datetrack_mode );
17476            --    p_update                => l_update
17477              --
17478              l_effective_date := l_process_date;
17479              l_DPNT_CVRD_PLIP_RT_ID   := r_DCP.information1;
17480              l_object_version_number := r_DCP.information265;
17481              --
17482            end if;
17483            --
17484            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
17485            --
17486            IF l_update OR l_dml_operation <> 'UPDATE' THEN
17487            --UPD END
17488            hr_utility.set_location(' BEN_DPNT_CVRD_PLIP_RT_F UPDATE_DPNT_CVRD_PLIP_RT ',30);
17489            BEN_DPNT_CVRD_PLIP_RT_API.UPDATE_DPNT_CVRD_PLIP_RT(
17490              --
17491              P_VALIDATE               => false
17492              ,P_EFFECTIVE_DATE        => l_effective_date
17493              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
17494              --
17495              ,P_DCP_ATTRIBUTE1      => r_DCP.INFORMATION111
17496              ,P_DCP_ATTRIBUTE10      => r_DCP.INFORMATION120
17497              ,P_DCP_ATTRIBUTE11      => r_DCP.INFORMATION121
17498              ,P_DCP_ATTRIBUTE12      => r_DCP.INFORMATION122
17499              ,P_DCP_ATTRIBUTE13      => r_DCP.INFORMATION123
17500              ,P_DCP_ATTRIBUTE14      => r_DCP.INFORMATION124
17501              ,P_DCP_ATTRIBUTE15      => r_DCP.INFORMATION125
17502              ,P_DCP_ATTRIBUTE16      => r_DCP.INFORMATION126
17503              ,P_DCP_ATTRIBUTE17      => r_DCP.INFORMATION127
17504              ,P_DCP_ATTRIBUTE18      => r_DCP.INFORMATION128
17505              ,P_DCP_ATTRIBUTE19      => r_DCP.INFORMATION129
17506              ,P_DCP_ATTRIBUTE2      => r_DCP.INFORMATION112
17507              ,P_DCP_ATTRIBUTE20      => r_DCP.INFORMATION130
17508              ,P_DCP_ATTRIBUTE21      => r_DCP.INFORMATION131
17509              ,P_DCP_ATTRIBUTE22      => r_DCP.INFORMATION132
17510              ,P_DCP_ATTRIBUTE23      => r_DCP.INFORMATION133
17511              ,P_DCP_ATTRIBUTE24      => r_DCP.INFORMATION134
17512              ,P_DCP_ATTRIBUTE25      => r_DCP.INFORMATION135
17513              ,P_DCP_ATTRIBUTE26      => r_DCP.INFORMATION136
17514              ,P_DCP_ATTRIBUTE27      => r_DCP.INFORMATION137
17515              ,P_DCP_ATTRIBUTE28      => r_DCP.INFORMATION138
17516              ,P_DCP_ATTRIBUTE29      => r_DCP.INFORMATION139
17517              ,P_DCP_ATTRIBUTE3      => r_DCP.INFORMATION113
17518              ,P_DCP_ATTRIBUTE30      => r_DCP.INFORMATION140
17519              ,P_DCP_ATTRIBUTE4      => r_DCP.INFORMATION114
17520              ,P_DCP_ATTRIBUTE5      => r_DCP.INFORMATION115
17521              ,P_DCP_ATTRIBUTE6      => r_DCP.INFORMATION116
17522              ,P_DCP_ATTRIBUTE7      => r_DCP.INFORMATION117
17523              ,P_DCP_ATTRIBUTE8      => r_DCP.INFORMATION118
17524              ,P_DCP_ATTRIBUTE9      => r_DCP.INFORMATION119
17525              ,P_DCP_ATTRIBUTE_CATEGORY      => r_DCP.INFORMATION110
17526              ,P_DPNT_CVRD_PLIP_RT_ID      => l_dpnt_cvrd_plip_rt_id
17527              ,P_ENRL_DET_DT_CD      => r_DCP.INFORMATION11
17528              ,P_EXCLD_FLAG      => r_DCP.INFORMATION12
17529              ,P_ORDR_NUM      => r_DCP.INFORMATION260
17530              ,P_PLIP_ID      => l_PLIP_ID
17531              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
17532              --
17533              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
17534              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
17535              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
17536              ,P_DATETRACK_MODE        => l_datetrack_mode
17537            );
17538            --
17539            end if;
17540          end if;
17541          --
17542          -- Delete the row if it is end dated.
17543          --
17544          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
17545              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
17546              trunc(l_max_eed) = r_DCP.information3) then
17547              --
17548              BEN_DPNT_CVRD_PLIP_RT_API.delete_DPNT_CVRD_PLIP_RT(
17549                 --
17550                 p_validate                       => false
17551                 ,p_dpnt_cvrd_plip_rt_id                   => l_dpnt_cvrd_plip_rt_id
17552                 ,p_effective_start_date           => l_effective_start_date
17553                 ,p_effective_end_date             => l_effective_end_date
17554                 ,p_object_version_number          => l_object_version_number
17555                 ,p_effective_date                 => l_max_eed
17556                 ,p_datetrack_mode                 => hr_api.g_delete
17557                 --
17558                 );
17559                 --
17560          end if;
17561          --
17562          l_prev_pk_id := l_current_pk_id ;
17563          --
17564        end if;
17565        --
17566      end if;
17567      --
17568    end loop;
17569    --
17570  exception when others then
17571     --
17572     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'DCP',r_dcp.information5 );
17573     --
17574  end create_DCP_rows;
17575 
17576    ---------------------------------------------------------------
17577    ----------------------< create_DCO_rows >-----------------------
17578    ---------------------------------------------------------------
17579    --
17580    procedure create_DCO_rows
17581    (
17582          p_validate                       in  number     default 0
17583         ,p_copy_entity_txn_id             in  number
17584         ,p_effective_date                 in  date
17585         ,p_prefix_suffix_text             in  varchar2  default null
17586         ,p_reuse_object_flag              in  varchar2  default null
17587         ,p_target_business_group_id       in  varchar2  default null
17588         ,p_prefix_suffix_cd               in  varchar2  default null
17589    ) is
17590    --
17591    l_PTIP_ID  number;
17592    l_VRBL_RT_PRFL_ID  number;
17593    cursor c_unique_DCO(l_table_alias varchar2) is
17594    select distinct cpe.information1,
17595      cpe.information2,
17596      cpe.information3,
17597      cpe.table_route_id
17598    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
17599         pqh_table_route tr
17600    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
17601    and   cpe.table_route_id     = tr.table_route_id
17602    -- and   tr.where_clause        = l_BEN_DPNT_CVRD_OTHR_PTIP_RT_F
17603    and tr.table_alias = l_table_alias
17604    and   cpe.number_of_copies   = 1 -- ADDITION
17605    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
17606    order by information1, information2; --added for bug: 5151945
17607    --
17608    --
17609    cursor c_DCO_min_max_dates(c_table_route_id  number,
17610                 c_information1   number) is
17611    select
17612      min(cpe.information2) min_esd,
17613      max(cpe.information3) min_eed
17614    from ben_copy_entity_results cpe
17615    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
17616    and   cpe.table_route_id     = c_table_route_id
17617    and   cpe.information1       = c_information1 ;
17618    --
17619    cursor c_DCO(c_table_route_id  number,
17620                 c_information1   number,
17621                 c_information2   Date,
17622                 c_information3   Date)  is
17623    select
17624      cpe.*
17625    from ben_copy_entity_results cpe
17626    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
17627    and   cpe.table_route_id     = c_table_route_id
17628    and   cpe.information1       = c_information1
17629    and   cpe.information2       = c_information2
17630    and   cpe.information3       = c_information3
17631    and rownum = 1 ;
17632    -- Date Track target record
17633    cursor c_find_DCO_in_target(
17634                                 c_effective_start_date    date,
17635                                 c_effective_end_date      date,
17636                                 c_business_group_id       number,
17637                                 c_new_pk_id               number) is
17638    select
17639      DCO.dpnt_cvrd_othr_ptip_rt_id new_value
17640    from BEN_DPNT_CVRD_OTHR_PTIP_RT_F DCO
17641    where
17642    DCO.PTIP_ID     = l_PTIP_ID  and
17643    DCO.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
17644    DCO.business_group_id  = c_business_group_id
17645    and   DCO.dpnt_cvrd_othr_ptip_rt_id  <> c_new_pk_id
17646 --TEMPIK
17647    and c_effective_start_date between effective_start_date
17648                             and effective_end_date ;
17649 --END TEMPIK
17650 /*TEMPIK
17651    and exists ( select null
17652                 from BEN_DPNT_CVRD_OTHR_PTIP_RT_F DCO1
17653                 where
17654                 DCO1.PTIP_ID     = l_PTIP_ID  and
17655                 DCO1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
17656                 DCO1.business_group_id  = c_business_group_id
17657                 and   DCO1.effective_start_date <= c_effective_start_date )
17658    and exists ( select null
17659                 from BEN_DPNT_CVRD_OTHR_PTIP_RT_F DCO2
17660                 where
17661                 DCO2.PTIP_ID     = l_PTIP_ID  and
17662                 DCO2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
17663                 DCO2.business_group_id  = c_business_group_id
17664                 and   DCO2.effective_end_date >= c_effective_end_date )
17665                 ;
17666 TEMPIK */
17667    --TEMPIK
17668    l_dt_rec_found            boolean ;
17669    --END TEMPIK
17670    --
17671    l_current_pk_id           number := null ;
17672    --UPD START
17673    --
17674    l_update                  boolean      := false ;
17675    l_datetrack_mode          varchar2(80) := hr_api.g_update;
17676    l_process_date            date;
17677    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
17678    --
17679    --UPD END
17680    l_prev_pk_id              number := null ;
17681    l_first_rec               boolean := true ;
17682    r_DCO                     c_DCO%rowtype;
17683    l_dpnt_cvrd_othr_ptip_rt_id             number ;
17684    l_object_version_number   number ;
17685    l_effective_start_date    date ;
17686    l_effective_end_date      date ;
17687    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
17688    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
17689    l_new_value               number(15);
17690    l_object_found_in_target  boolean := false ;
17691    l_min_esd                 date;
17692    l_max_eed                 date;
17693    l_effective_date          date;
17694    --
17695  begin
17696    -- Initialization
17697    l_object_found_in_target := false ;
17698    -- End Initialization
17699    -- Derive the prefix - sufix
17700    if   p_prefix_suffix_cd = 'PREFIX' then
17701      l_prefix  := p_prefix_suffix_text ;
17702    elsif p_prefix_suffix_cd = 'SUFFIX' then
17703      l_suffix   := p_prefix_suffix_text ;
17704    else
17705      l_prefix := null ;
17706      l_suffix  := null ;
17707    end if ;
17708    -- End Prefix Sufix derivation
17709    for r_DCO_unique in c_unique_DCO('DCO') loop
17710 
17711      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
17712         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
17713          r_DCO_unique.information3 >=
17714                  ben_pd_copy_to_ben_one.g_copy_effective_date)
17715         ) then
17716        --
17717        hr_utility.set_location(' r_DCO_unique.table_route_id '||r_DCO_unique.table_route_id,10);
17718        hr_utility.set_location(' r_DCO_unique.information1 '||r_DCO_unique.information1,10);
17719        hr_utility.set_location( 'r_DCO_unique.information2 '||r_DCO_unique.information2,10);
17720        hr_utility.set_location( 'r_DCO_unique.information3 '||r_DCO_unique.information3,10);
17721        -- If reuse objects flag is 'Y' then check for the object in the target business group
17722        -- if found insert the record into PLSql table and exit the loop else try create the
17723        -- object in the target business group
17724        --
17725        l_object_found_in_target := false ;
17726        l_min_esd := null ;
17727        l_max_eed := null ;
17728        open c_DCO_min_max_dates(r_DCO_unique.table_route_id, r_DCO_unique.information1 ) ;
17729        fetch c_DCO_min_max_dates into l_min_esd,l_max_eed ;
17730        --
17731 
17732        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
17733             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
17734          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
17735        end if;
17736        l_min_esd := greatest(l_min_esd,r_DCO_unique.information2);
17737        open c_DCO(r_DCO_unique.table_route_id,
17738                 r_DCO_unique.information1,
17739                 r_DCO_unique.information2,
17740                 r_DCO_unique.information3 ) ;
17741        --
17742        fetch c_DCO into r_DCO ;
17743        --
17744        close c_DCO ;
17745        --
17746        -- Only For Use by Create Wizard - Same Business Group
17747        l_PTIP_ID := NVL(get_fk('PTIP_ID', r_DCO.information259,r_DCO_unique.dml_operation),
17748                         r_DCO.information259);
17749 
17750        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_DCO.information262,r_DCO_unique.dml_operation);
17751        --UPD START
17752        l_update := false;
17753        l_process_date := p_effective_date;
17754        l_dml_operation:= r_DCO_unique.dml_operation ;
17755        --
17756        if l_dml_operation = 'UPDATE' then
17757          --
17758          l_object_found_in_target := TRUE;
17759          --
17760          if l_process_date between r_DCO_unique.information2 and r_DCO_unique.information3 then
17761                l_update := true;
17762                if r_DCO_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
17763                  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_OTHR_PTIP_RT_ID'
17764                then
17765                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'DPNT_CVRD_OTHR_PTIP_RT_ID' ;
17766                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_DCO_unique.information1 ;
17767                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_DCO_unique.information1 ;
17768                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
17769                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_DCO_unique.table_route_id;
17770                   --
17771                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
17772                   --
17773                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
17774                   --
17775                   -- log_data('DCO',l_new_value,l_prefix || r_DCO_unique.name|| l_suffix,'REUSED');
17776                   --
17777                end if ;
17778                hr_utility.set_location( 'found record for update',10);
17779            --
17780          else
17781            --
17782            l_update := false;
17783            --
17784          end if;
17785        else
17786          --
17787          --UPD END
17788        if p_reuse_object_flag = 'Y' then
17789          if c_DCO_min_max_dates%found then
17790            -- cursor to find the object
17791            open c_find_DCO_in_target( l_min_esd,l_max_eed,
17792                                  p_target_business_group_id, nvl(l_dpnt_cvrd_othr_ptip_rt_id, -999)  ) ;
17793            fetch c_find_DCO_in_target into l_new_value ;
17794            if c_find_DCO_in_target%found then
17795              --
17796              --TEMPIK
17797              l_dt_rec_found :=   dt_api.check_min_max_dates
17798                  (p_base_table_name => 'BEN_DPNT_CVRD_OTHR_PTIP_RT_F',
17799                   p_base_key_column => 'DPNT_CVRD_OTHR_PTIP_RT_ID',
17800                   p_base_key_value  => l_new_value,
17801                   p_from_date       => l_min_esd,
17802                   p_to_date         => l_max_eed );
17803              if l_dt_rec_found THEN
17804              --END TEMPIK
17805              if r_DCO_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
17806                 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_OTHR_PTIP_RT_ID'  then
17807                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'DPNT_CVRD_OTHR_PTIP_RT_ID' ;
17808                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_DCO_unique.information1 ;
17809                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
17810                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
17811                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_DCO_unique.table_route_id;
17812                 --
17813                 -- 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) ;
17814                 --
17815                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
17816              end if ;
17817              --
17818              l_object_found_in_target := true ;
17819              --TEMPIK
17820              end if; -- l_dt_rec_found
17821              --END TEMPIK
17822            end if;
17823            close c_find_DCO_in_target ;
17824          --
17825          end if;
17826        end if ;
17827        --
17828        end if;
17829        close c_DCO_min_max_dates ;
17830        if not l_object_found_in_target OR l_update   then
17831          --
17832          l_current_pk_id := r_DCO.information1;
17833          --
17834          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
17835          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
17836          --
17837          if l_current_pk_id =  l_prev_pk_id  then
17838            --
17839            l_first_rec := false ;
17840            --
17841          else
17842            --
17843            l_first_rec := true ;
17844            --
17845          end if ;
17846          --
17847 
17848          l_effective_date := r_DCO.information2;
17849          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
17850               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
17851            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
17852          end if;
17853 
17854          if l_first_rec and not l_update then
17855            -- Call Create routine.
17856            hr_utility.set_location(' BEN_DPNT_CVRD_OTHR_PTIP_RT_F CREATE_DPNT_CVD_O_PTIP_RT ',20);
17857            BEN_DPNT_CVD_O_PTIP_RT_API.CREATE_DPNT_CVD_O_PTIP_RT(
17858              --
17859              P_VALIDATE               => false
17860              ,P_EFFECTIVE_DATE        => l_effective_date
17861              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
17862              --
17863              ,P_DCO_ATTRIBUTE1      => r_DCO.INFORMATION111
17864              ,P_DCO_ATTRIBUTE10      => r_DCO.INFORMATION120
17865              ,P_DCO_ATTRIBUTE11      => r_DCO.INFORMATION121
17866              ,P_DCO_ATTRIBUTE12      => r_DCO.INFORMATION122
17867              ,P_DCO_ATTRIBUTE13      => r_DCO.INFORMATION123
17868              ,P_DCO_ATTRIBUTE14      => r_DCO.INFORMATION124
17869              ,P_DCO_ATTRIBUTE15      => r_DCO.INFORMATION125
17870              ,P_DCO_ATTRIBUTE16      => r_DCO.INFORMATION126
17871              ,P_DCO_ATTRIBUTE17      => r_DCO.INFORMATION127
17872              ,P_DCO_ATTRIBUTE18      => r_DCO.INFORMATION128
17873              ,P_DCO_ATTRIBUTE19      => r_DCO.INFORMATION129
17874              ,P_DCO_ATTRIBUTE2      => r_DCO.INFORMATION112
17875              ,P_DCO_ATTRIBUTE20      => r_DCO.INFORMATION130
17876              ,P_DCO_ATTRIBUTE21      => r_DCO.INFORMATION131
17877              ,P_DCO_ATTRIBUTE22      => r_DCO.INFORMATION132
17878              ,P_DCO_ATTRIBUTE23      => r_DCO.INFORMATION133
17879              ,P_DCO_ATTRIBUTE24      => r_DCO.INFORMATION134
17880              ,P_DCO_ATTRIBUTE25      => r_DCO.INFORMATION135
17881              ,P_DCO_ATTRIBUTE26      => r_DCO.INFORMATION136
17882              ,P_DCO_ATTRIBUTE27      => r_DCO.INFORMATION137
17883              ,P_DCO_ATTRIBUTE28      => r_DCO.INFORMATION138
17884              ,P_DCO_ATTRIBUTE29      => r_DCO.INFORMATION139
17885              ,P_DCO_ATTRIBUTE3      => r_DCO.INFORMATION113
17886              ,P_DCO_ATTRIBUTE30      => r_DCO.INFORMATION140
17887              ,P_DCO_ATTRIBUTE4      => r_DCO.INFORMATION114
17888              ,P_DCO_ATTRIBUTE5      => r_DCO.INFORMATION115
17889              ,P_DCO_ATTRIBUTE6      => r_DCO.INFORMATION116
17890              ,P_DCO_ATTRIBUTE7      => r_DCO.INFORMATION117
17891              ,P_DCO_ATTRIBUTE8      => r_DCO.INFORMATION118
17892              ,P_DCO_ATTRIBUTE9      => r_DCO.INFORMATION119
17893              ,P_DCO_ATTRIBUTE_CATEGORY      => r_DCO.INFORMATION110
17894              ,P_DPNT_CVRD_OTHR_PTIP_RT_ID      => l_dpnt_cvrd_othr_ptip_rt_id
17895              ,P_ENRL_DET_DT_CD      => r_DCO.INFORMATION13
17896              ,P_EXCLD_FLAG      => r_DCO.INFORMATION11
17897              ,P_ONLY_PLS_SUBJ_COBRA_FLAG      => r_DCO.INFORMATION12
17898              ,P_ORDR_NUM      => r_DCO.INFORMATION261
17899              ,P_PTIP_ID      => l_PTIP_ID
17900              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
17901              --
17902              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
17903              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
17904              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
17905            );
17906            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
17907            -- Update all relevent cer records with new pk_id
17908            hr_utility.set_location('Before plsql table ',222);
17909            hr_utility.set_location('new_value id '||l_dpnt_cvrd_othr_ptip_rt_id,222);
17910            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'DPNT_CVRD_OTHR_PTIP_RT_ID' ;
17911            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_DCO.information1 ;
17912            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_DPNT_CVRD_OTHR_PTIP_RT_ID ;
17913            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
17914            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_DCO_unique.table_route_id;
17915            hr_utility.set_location('After plsql table ',222);
17916            --
17917            -- 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 ) ;
17918            --
17919            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
17920            --
17921          else
17922            --
17923            -- Call Update routine for the pk_id created in prev run .
17924            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
17925            --UPD START
17926            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
17927            --
17928            if l_update then
17929              --
17930              l_datetrack_mode := r_DCO.datetrack_mode ;
17931              --
17932              get_dt_modes(
17933                p_effective_date        => l_process_date,
17934                p_effective_end_date    => r_DCO.information3,
17935                p_effective_start_date  => r_DCO.information2,
17936                p_dml_operation         => r_DCO.dml_operation,
17937                p_datetrack_mode        => l_datetrack_mode );
17938            --    p_update                => l_update
17939              --
17940              l_effective_date := l_process_date;
17941              l_DPNT_CVRD_OTHR_PTIP_RT_ID   := r_DCO.information1;
17942              l_object_version_number := r_DCO.information265;
17943              --
17944            end if;
17945            --
17946            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
17947            --
17948            IF l_update OR l_dml_operation <> 'UPDATE' THEN
17949            --UPD END
17950            hr_utility.set_location(' BEN_DPNT_CVRD_OTHR_PTIP_RT_F UPDATE_DPNT_CVD_O_PTIP_RT ',30);
17951            BEN_DPNT_CVD_O_PTIP_RT_API.UPDATE_DPNT_CVD_O_PTIP_RT(
17952              --
17953              P_VALIDATE               => false
17954              ,P_EFFECTIVE_DATE        => l_effective_date
17955              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
17956              --
17957              ,P_DCO_ATTRIBUTE1      => r_DCO.INFORMATION111
17958              ,P_DCO_ATTRIBUTE10      => r_DCO.INFORMATION120
17959              ,P_DCO_ATTRIBUTE11      => r_DCO.INFORMATION121
17960              ,P_DCO_ATTRIBUTE12      => r_DCO.INFORMATION122
17961              ,P_DCO_ATTRIBUTE13      => r_DCO.INFORMATION123
17962              ,P_DCO_ATTRIBUTE14      => r_DCO.INFORMATION124
17963              ,P_DCO_ATTRIBUTE15      => r_DCO.INFORMATION125
17964              ,P_DCO_ATTRIBUTE16      => r_DCO.INFORMATION126
17965              ,P_DCO_ATTRIBUTE17      => r_DCO.INFORMATION127
17966              ,P_DCO_ATTRIBUTE18      => r_DCO.INFORMATION128
17967              ,P_DCO_ATTRIBUTE19      => r_DCO.INFORMATION129
17968              ,P_DCO_ATTRIBUTE2      => r_DCO.INFORMATION112
17969              ,P_DCO_ATTRIBUTE20      => r_DCO.INFORMATION130
17970              ,P_DCO_ATTRIBUTE21      => r_DCO.INFORMATION131
17971              ,P_DCO_ATTRIBUTE22      => r_DCO.INFORMATION132
17972              ,P_DCO_ATTRIBUTE23      => r_DCO.INFORMATION133
17973              ,P_DCO_ATTRIBUTE24      => r_DCO.INFORMATION134
17974              ,P_DCO_ATTRIBUTE25      => r_DCO.INFORMATION135
17975              ,P_DCO_ATTRIBUTE26      => r_DCO.INFORMATION136
17976              ,P_DCO_ATTRIBUTE27      => r_DCO.INFORMATION137
17977              ,P_DCO_ATTRIBUTE28      => r_DCO.INFORMATION138
17978              ,P_DCO_ATTRIBUTE29      => r_DCO.INFORMATION139
17979              ,P_DCO_ATTRIBUTE3      => r_DCO.INFORMATION113
17980              ,P_DCO_ATTRIBUTE30      => r_DCO.INFORMATION140
17981              ,P_DCO_ATTRIBUTE4      => r_DCO.INFORMATION114
17982              ,P_DCO_ATTRIBUTE5      => r_DCO.INFORMATION115
17983              ,P_DCO_ATTRIBUTE6      => r_DCO.INFORMATION116
17984              ,P_DCO_ATTRIBUTE7      => r_DCO.INFORMATION117
17985              ,P_DCO_ATTRIBUTE8      => r_DCO.INFORMATION118
17986              ,P_DCO_ATTRIBUTE9      => r_DCO.INFORMATION119
17987              ,P_DCO_ATTRIBUTE_CATEGORY      => r_DCO.INFORMATION110
17988              ,P_DPNT_CVRD_OTHR_PTIP_RT_ID      => l_dpnt_cvrd_othr_ptip_rt_id
17989              ,P_ENRL_DET_DT_CD      => r_DCO.INFORMATION13
17990              ,P_EXCLD_FLAG      => r_DCO.INFORMATION11
17991              ,P_ONLY_PLS_SUBJ_COBRA_FLAG      => r_DCO.INFORMATION12
17992              ,P_ORDR_NUM      => r_DCO.INFORMATION261
17993              ,P_PTIP_ID      => l_PTIP_ID
17994              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
17995              --
17996              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
17997              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
17998              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
17999              ,P_DATETRACK_MODE        => l_datetrack_mode
18000            );
18001            --
18002            end if;
18003          end if;
18004          --
18005          -- Delete the row if it is end dated.
18006          --
18007          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
18008              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
18009              trunc(l_max_eed) = r_DCO.information3) then
18010              --
18011              BEN_DPNT_CVD_O_PTIP_RT_API.delete_DPNT_CVD_O_PTIP_RT(
18012                 --
18013                 p_validate                       => false
18014                 ,p_dpnt_cvrd_othr_ptip_rt_id                   => l_dpnt_cvrd_othr_ptip_rt_id
18015                 ,p_effective_start_date           => l_effective_start_date
18016                 ,p_effective_end_date             => l_effective_end_date
18017                 ,p_object_version_number          => l_object_version_number
18018                 ,p_effective_date                 => l_max_eed
18019                 ,p_datetrack_mode                 => hr_api.g_delete
18020                 --
18021                 );
18022                 --
18023          end if;
18024          --
18025          l_prev_pk_id := l_current_pk_id ;
18026          --
18027        end if;
18028        --
18029      end if;
18030      --
18031    end loop;
18032    --
18033  exception when others then
18034     --
18035     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'DCO',r_dco.information5 );
18036     --
18037  end create_DCO_rows;
18038 
18039    ---------------------------------------------------------------
18040    ----------------------< create_DCL_rows >-----------------------
18041    ---------------------------------------------------------------
18042    --
18043    procedure create_DCL_rows
18044    (
18045          p_validate                       in  number     default 0
18046         ,p_copy_entity_txn_id             in  number
18047         ,p_effective_date                 in  date
18048         ,p_prefix_suffix_text             in  varchar2  default null
18049         ,p_reuse_object_flag              in  varchar2  default null
18050         ,p_target_business_group_id       in  varchar2  default null
18051         ,p_prefix_suffix_cd               in  varchar2  default null
18052    ) is
18053    --
18054    l_PL_ID  number;
18055    l_VRBL_RT_PRFL_ID  number;
18056    cursor c_unique_DCL(l_table_alias varchar2) is
18057    select distinct cpe.information1,
18058      cpe.information2,
18059      cpe.information3,
18060      cpe.table_route_id
18061    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
18062         pqh_table_route tr
18063    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
18064    and   cpe.table_route_id     = tr.table_route_id
18065    -- and   tr.where_clause        = l_BEN_DPNT_CVRD_OTHR_PL_RT_F
18066    and tr.table_alias = l_table_alias
18067    and   cpe.number_of_copies   = 1 -- ADDITION
18068    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
18069    order by information1, information2; --added for bug: 5151945
18070    --
18071    --
18072    cursor c_DCL_min_max_dates(c_table_route_id  number,
18073                 c_information1   Number) is
18074    select
18075      min(cpe.information2) min_esd,
18076      max(cpe.information3) min_eed
18077    from ben_copy_entity_results cpe
18078    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
18079    and   cpe.table_route_id     = c_table_route_id
18080    and   cpe.information1       = c_information1 ;
18081    --
18082    cursor c_DCL(c_table_route_id  number,
18083                 c_information1   number,
18084                 c_information2   Date,
18085                 c_information3   Date)  is
18086    select
18087      cpe.*
18088    from ben_copy_entity_results cpe
18089    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
18090    and   cpe.table_route_id     = c_table_route_id
18091    and   cpe.information1       = c_information1
18092    and   cpe.information2       = c_information2
18093    and   cpe.information3       = c_information3
18094    and rownum = 1 ;
18095    -- Date Track target record
18096    cursor c_find_DCL_in_target(
18097                                 c_effective_start_date    date,
18098                                 c_effective_end_date      date,
18099                                 c_business_group_id       number,
18100                                 c_new_pk_id               number) is
18101    select
18102      DCL.dpnt_cvrd_othr_pl_rt_id new_value
18103    from BEN_DPNT_CVRD_OTHR_PL_RT_F DCL
18104    where
18105    DCL.PL_ID     = l_PL_ID  and
18106    DCL.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
18107    DCL.business_group_id  = c_business_group_id
18108    and   DCL.dpnt_cvrd_othr_pl_rt_id  <> c_new_pk_id
18109 --TEMPIK
18110    and c_effective_start_date between effective_start_date
18111                             and effective_end_date ;
18112 --END TEMPIK
18113 /*TEMPIK
18114    and exists ( select null
18115                 from BEN_DPNT_CVRD_OTHR_PL_RT_F DCL1
18116                 where
18117                 DCL1.PL_ID     = l_PL_ID  and
18118                 DCL1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
18119                 DCL1.business_group_id  = c_business_group_id
18120                 and   DCL1.effective_start_date <= c_effective_start_date )
18121    and exists ( select null
18122                 from BEN_DPNT_CVRD_OTHR_PL_RT_F DCL2
18123                 where
18124                 DCL2.PL_ID     = l_PL_ID  and
18125                 DCL2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
18126                 DCL2.business_group_id  = c_business_group_id
18127                 and   DCL2.effective_end_date >= c_effective_end_date )
18128                 ;
18129 TEMPIK */
18130    --TEMPIK
18131    l_dt_rec_found            boolean ;
18132    --END TEMPIK
18133    --
18134    l_current_pk_id           number := null ;
18135    --UPD START
18136    --
18137    l_update                  boolean      := false ;
18138    l_datetrack_mode          varchar2(80) := hr_api.g_update;
18139    l_process_date            date;
18140    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
18141    --
18142    --UPD END
18143    l_prev_pk_id              number := null ;
18144    l_first_rec               boolean := true ;
18145    r_DCL                     c_DCL%rowtype;
18146    l_dpnt_cvrd_othr_pl_rt_id             number ;
18147    l_object_version_number   number ;
18148    l_effective_start_date    date ;
18149    l_effective_end_date      date ;
18150    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
18151    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
18152    l_new_value               number(15);
18153    l_object_found_in_target  boolean := false ;
18154    l_min_esd                 date;
18155    l_max_eed                 date;
18156    l_effective_date          date;
18157    --
18158  begin
18159    -- Initialization
18160    l_object_found_in_target := false ;
18161    -- End Initialization
18162    -- Derive the prefix - sufix
18163    if   p_prefix_suffix_cd = 'PREFIX' then
18164      l_prefix  := p_prefix_suffix_text ;
18165    elsif p_prefix_suffix_cd = 'SUFFIX' then
18166      l_suffix   := p_prefix_suffix_text ;
18167    else
18168      l_prefix := null ;
18169      l_suffix  := null ;
18170    end if ;
18171    -- End Prefix Sufix derivation
18172    for r_DCL_unique in c_unique_DCL('DCL') loop
18173 
18174      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
18175         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
18176          r_DCL_unique.information3 >=
18177                  ben_pd_copy_to_ben_one.g_copy_effective_date)
18178         ) then
18179        --
18180        hr_utility.set_location(' r_DCL_unique.table_route_id '||r_DCL_unique.table_route_id,10);
18181        hr_utility.set_location(' r_DCL_unique.information1 '||r_DCL_unique.information1,10);
18182        hr_utility.set_location( 'r_DCL_unique.information2 '||r_DCL_unique.information2,10);
18183        hr_utility.set_location( 'r_DCL_unique.information3 '||r_DCL_unique.information3,10);
18184        -- If reuse objects flag is 'Y' then check for the object in the target business group
18185        -- if found insert the record into PLSql table and exit the loop else try create the
18186        -- object in the target business group
18187        --
18188        l_object_found_in_target := false ;
18189        l_min_esd := null ;
18190        l_max_eed := null ;
18191        open c_DCL_min_max_dates(r_DCL_unique.table_route_id, r_DCL_unique.information1 ) ;
18192        fetch c_DCL_min_max_dates into l_min_esd,l_max_eed ;
18193        --
18194 
18195        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
18196             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
18197          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
18198        end if;
18199        l_min_esd := greatest(l_min_esd,r_DCL_unique.information2);
18200        open c_DCL(r_DCL_unique.table_route_id,
18201                 r_DCL_unique.information1,
18202                 r_DCL_unique.information2,
18203                 r_DCL_unique.information3 ) ;
18204        --
18205        fetch c_DCL into r_DCL ;
18206        --
18207        close c_DCL ;
18208        --
18209        -- Only For Use by Create Wizard - Same Business Group
18210        l_PL_ID := NVL(get_fk('PL_ID', r_DCL.information261,r_DCL_unique.dml_operation),
18211                       r_DCL.information261);
18212 
18213        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_DCL.information262,r_DCL_unique.dml_operation);
18214        --UPD START
18215        l_update := false;
18216        l_process_date := p_effective_date;
18217        l_dml_operation:= r_DCL_unique.dml_operation ;
18218        --
18219        if l_dml_operation = 'UPDATE' then
18220          --
18221          l_object_found_in_target := TRUE;
18222          --
18223          if l_process_date between r_DCL_unique.information2 and r_DCL_unique.information3 then
18224                l_update := true;
18225                if r_DCL_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
18226                  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_OTHR_PL_RT_ID'
18227                then
18228                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'DPNT_CVRD_OTHR_PL_RT_ID' ;
18229                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_DCL_unique.information1 ;
18230                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_DCL_unique.information1 ;
18231                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
18232                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_DCL_unique.table_route_id;
18233                   --
18234                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
18235                   --
18236                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
18237                   --
18238                   -- log_data('DCL',l_new_value,l_prefix || r_DCL_unique.name|| l_suffix,'REUSED');
18239                   --
18240                end if ;
18241                hr_utility.set_location( 'found record for update',10);
18242            --
18243          else
18244            --
18245            l_update := false;
18246            --
18247          end if;
18248        else
18249          --
18250          --UPD END
18251        if p_reuse_object_flag = 'Y' then
18252          if c_DCL_min_max_dates%found then
18253            -- cursor to find the object
18254            open c_find_DCL_in_target( l_min_esd,l_max_eed,
18255                                  p_target_business_group_id, nvl(l_dpnt_cvrd_othr_pl_rt_id, -999)  ) ;
18256            fetch c_find_DCL_in_target into l_new_value ;
18257            if c_find_DCL_in_target%found then
18258              --
18259              --TEMPIK
18260              l_dt_rec_found :=   dt_api.check_min_max_dates
18261                  (p_base_table_name => 'BEN_DPNT_CVRD_OTHR_PL_RT_F',
18262                   p_base_key_column => 'DPNT_CVRD_OTHR_PL_RT_ID',
18263                   p_base_key_value  => l_new_value,
18264                   p_from_date       => l_min_esd,
18265                   p_to_date         => l_max_eed );
18266              if l_dt_rec_found THEN
18267              --END TEMPIK
18268              if r_DCL_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
18269                 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_OTHR_PL_RT_ID'  then
18270                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'DPNT_CVRD_OTHR_PL_RT_ID' ;
18271                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_DCL_unique.information1 ;
18272                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
18273                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
18274                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_DCL_unique.table_route_id;
18275                 --
18276                 -- 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) ;
18277                 --
18278                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
18279              end if ;
18280              --
18281              l_object_found_in_target := true ;
18282              --TEMPIK
18283              end if; -- l_dt_rec_found
18284              --END TEMPIK
18285            end if;
18286            close c_find_DCL_in_target ;
18287          --
18288          end if;
18289        end if ;
18290        --
18291        end if;
18292        close c_DCL_min_max_dates ;
18293        if not l_object_found_in_target OR l_update   then
18294          --
18295          l_current_pk_id := r_DCL.information1;
18296          --
18297          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
18298          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
18299          --
18300          if l_current_pk_id =  l_prev_pk_id  then
18301            --
18302            l_first_rec := false ;
18303            --
18304          else
18305            --
18306            l_first_rec := true ;
18307            --
18308          end if ;
18309          --
18310 
18311          l_effective_date := r_DCL.information2;
18312          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
18313               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
18314            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
18315          end if;
18316 
18317          if l_first_rec and not l_update then
18318            -- Call Create routine.
18319            hr_utility.set_location(' BEN_DPNT_CVRD_OTHR_PL_RT_F CREATE_DPNT_CVRD_OTHR_PL_RT ',20);
18320            BEN_DPNT_CVRD_OTHR_PL_RT_API.CREATE_DPNT_CVRD_OTHR_PL_RT(
18321              --
18322              P_VALIDATE               => false
18323              ,P_EFFECTIVE_DATE        => l_effective_date
18324              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
18325              --
18326              ,P_CVG_DET_DT_CD      => r_DCL.INFORMATION12
18327              ,P_DCL_ATTRIBUTE1      => r_DCL.INFORMATION111
18328              ,P_DCL_ATTRIBUTE10      => r_DCL.INFORMATION120
18329              ,P_DCL_ATTRIBUTE11      => r_DCL.INFORMATION121
18330              ,P_DCL_ATTRIBUTE12      => r_DCL.INFORMATION122
18331              ,P_DCL_ATTRIBUTE13      => r_DCL.INFORMATION123
18332              ,P_DCL_ATTRIBUTE14      => r_DCL.INFORMATION124
18333              ,P_DCL_ATTRIBUTE15      => r_DCL.INFORMATION125
18334              ,P_DCL_ATTRIBUTE16      => r_DCL.INFORMATION126
18335              ,P_DCL_ATTRIBUTE17      => r_DCL.INFORMATION127
18336              ,P_DCL_ATTRIBUTE18      => r_DCL.INFORMATION128
18337              ,P_DCL_ATTRIBUTE19      => r_DCL.INFORMATION129
18338              ,P_DCL_ATTRIBUTE2      => r_DCL.INFORMATION112
18339              ,P_DCL_ATTRIBUTE20      => r_DCL.INFORMATION130
18340              ,P_DCL_ATTRIBUTE21      => r_DCL.INFORMATION131
18341              ,P_DCL_ATTRIBUTE22      => r_DCL.INFORMATION132
18342              ,P_DCL_ATTRIBUTE23      => r_DCL.INFORMATION133
18343              ,P_DCL_ATTRIBUTE24      => r_DCL.INFORMATION134
18344              ,P_DCL_ATTRIBUTE25      => r_DCL.INFORMATION135
18345              ,P_DCL_ATTRIBUTE26      => r_DCL.INFORMATION136
18346              ,P_DCL_ATTRIBUTE27      => r_DCL.INFORMATION137
18347              ,P_DCL_ATTRIBUTE28      => r_DCL.INFORMATION138
18348              ,P_DCL_ATTRIBUTE29      => r_DCL.INFORMATION139
18349              ,P_DCL_ATTRIBUTE3      => r_DCL.INFORMATION113
18350              ,P_DCL_ATTRIBUTE30      => r_DCL.INFORMATION140
18351              ,P_DCL_ATTRIBUTE4      => r_DCL.INFORMATION114
18352              ,P_DCL_ATTRIBUTE5      => r_DCL.INFORMATION115
18353              ,P_DCL_ATTRIBUTE6      => r_DCL.INFORMATION116
18354              ,P_DCL_ATTRIBUTE7      => r_DCL.INFORMATION117
18355              ,P_DCL_ATTRIBUTE8      => r_DCL.INFORMATION118
18356              ,P_DCL_ATTRIBUTE9      => r_DCL.INFORMATION119
18357              ,P_DCL_ATTRIBUTE_CATEGORY      => r_DCL.INFORMATION110
18358              ,P_DPNT_CVRD_OTHR_PL_RT_ID      => l_dpnt_cvrd_othr_pl_rt_id
18359              ,P_EXCLD_FLAG      => r_DCL.INFORMATION11
18360              ,P_ORDR_NUM      => r_DCL.INFORMATION257
18361              ,P_PL_ID      => l_PL_ID
18362              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
18363              --
18364              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
18365              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
18366              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
18367            );
18368            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
18369            -- Update all relevent cer records with new pk_id
18370            hr_utility.set_location('Before plsql table ',222);
18371            hr_utility.set_location('new_value id '||l_dpnt_cvrd_othr_pl_rt_id,222);
18372            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'DPNT_CVRD_OTHR_PL_RT_ID' ;
18373            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_DCL.information1 ;
18374            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_DPNT_CVRD_OTHR_PL_RT_ID ;
18375            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
18376            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_DCL_unique.table_route_id;
18377            hr_utility.set_location('After plsql table ',222);
18378            --
18379            -- 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 ) ;
18380            --
18381            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
18382            --
18383          else
18384            --
18385            -- Call Update routine for the pk_id created in prev run .
18386            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
18387            --UPD START
18388            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
18389            --
18390            if l_update then
18391              --
18392              l_datetrack_mode := r_DCL.datetrack_mode ;
18393              --
18394              get_dt_modes(
18395                p_effective_date        => l_process_date,
18396                p_effective_end_date    => r_DCL.information3,
18397                p_effective_start_date  => r_DCL.information2,
18398                p_dml_operation         => r_DCL.dml_operation,
18399                p_datetrack_mode        => l_datetrack_mode );
18400            --    p_update                => l_update
18401              --
18402              l_effective_date := l_process_date;
18403              l_DPNT_CVRD_OTHR_PL_RT_ID   := r_DCL.information1;
18404              l_object_version_number := r_DCL.information265;
18405              --
18406            end if;
18407            --
18408            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
18409            --
18410            IF l_update OR l_dml_operation <> 'UPDATE' THEN
18411            --UPD END
18412            hr_utility.set_location(' BEN_DPNT_CVRD_OTHR_PL_RT_F UPDATE_DPNT_CVRD_OTHR_PL_RT ',30);
18413            BEN_DPNT_CVRD_OTHR_PL_RT_API.UPDATE_DPNT_CVRD_OTHR_PL_RT(
18414              --
18415              P_VALIDATE               => false
18416              ,P_EFFECTIVE_DATE        => l_effective_date
18417              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
18418              --
18419              ,P_CVG_DET_DT_CD      => r_DCL.INFORMATION12
18420              ,P_DCL_ATTRIBUTE1      => r_DCL.INFORMATION111
18421              ,P_DCL_ATTRIBUTE10      => r_DCL.INFORMATION120
18422              ,P_DCL_ATTRIBUTE11      => r_DCL.INFORMATION121
18423              ,P_DCL_ATTRIBUTE12      => r_DCL.INFORMATION122
18424              ,P_DCL_ATTRIBUTE13      => r_DCL.INFORMATION123
18425              ,P_DCL_ATTRIBUTE14      => r_DCL.INFORMATION124
18426              ,P_DCL_ATTRIBUTE15      => r_DCL.INFORMATION125
18427              ,P_DCL_ATTRIBUTE16      => r_DCL.INFORMATION126
18428              ,P_DCL_ATTRIBUTE17      => r_DCL.INFORMATION127
18429              ,P_DCL_ATTRIBUTE18      => r_DCL.INFORMATION128
18430              ,P_DCL_ATTRIBUTE19      => r_DCL.INFORMATION129
18431              ,P_DCL_ATTRIBUTE2      => r_DCL.INFORMATION112
18432              ,P_DCL_ATTRIBUTE20      => r_DCL.INFORMATION130
18433              ,P_DCL_ATTRIBUTE21      => r_DCL.INFORMATION131
18434              ,P_DCL_ATTRIBUTE22      => r_DCL.INFORMATION132
18435              ,P_DCL_ATTRIBUTE23      => r_DCL.INFORMATION133
18436              ,P_DCL_ATTRIBUTE24      => r_DCL.INFORMATION134
18437              ,P_DCL_ATTRIBUTE25      => r_DCL.INFORMATION135
18438              ,P_DCL_ATTRIBUTE26      => r_DCL.INFORMATION136
18439              ,P_DCL_ATTRIBUTE27      => r_DCL.INFORMATION137
18440              ,P_DCL_ATTRIBUTE28      => r_DCL.INFORMATION138
18441              ,P_DCL_ATTRIBUTE29      => r_DCL.INFORMATION139
18442              ,P_DCL_ATTRIBUTE3      => r_DCL.INFORMATION113
18443              ,P_DCL_ATTRIBUTE30      => r_DCL.INFORMATION140
18444              ,P_DCL_ATTRIBUTE4      => r_DCL.INFORMATION114
18445              ,P_DCL_ATTRIBUTE5      => r_DCL.INFORMATION115
18446              ,P_DCL_ATTRIBUTE6      => r_DCL.INFORMATION116
18447              ,P_DCL_ATTRIBUTE7      => r_DCL.INFORMATION117
18448              ,P_DCL_ATTRIBUTE8      => r_DCL.INFORMATION118
18449              ,P_DCL_ATTRIBUTE9      => r_DCL.INFORMATION119
18450              ,P_DCL_ATTRIBUTE_CATEGORY      => r_DCL.INFORMATION110
18451              ,P_DPNT_CVRD_OTHR_PL_RT_ID      => l_dpnt_cvrd_othr_pl_rt_id
18452              ,P_EXCLD_FLAG      => r_DCL.INFORMATION11
18453              ,P_ORDR_NUM      => r_DCL.INFORMATION257
18454              ,P_PL_ID      => l_PL_ID
18455              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
18456              --
18457              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
18458              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
18459              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
18460              ,P_DATETRACK_MODE        => l_datetrack_mode
18461            );
18462            --
18463            end if;
18464          end if;
18465          --
18466          -- Delete the row if it is end dated.
18467          --
18468          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
18469              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
18470              trunc(l_max_eed) = r_DCL.information3) then
18471              --
18472              BEN_DPNT_CVRD_OTHR_PL_RT_API.delete_DPNT_CVRD_OTHR_PL_RT(
18473                 --
18474                 p_validate                       => false
18475                 ,p_dpnt_cvrd_othr_pl_rt_id                   => l_dpnt_cvrd_othr_pl_rt_id
18476                 ,p_effective_start_date           => l_effective_start_date
18477                 ,p_effective_end_date             => l_effective_end_date
18478                 ,p_object_version_number          => l_object_version_number
18479                 ,p_effective_date                 => l_max_eed
18480                 ,p_datetrack_mode                 => hr_api.g_delete
18481                 --
18482                 );
18483                 --
18484          end if;
18485          --
18486          l_prev_pk_id := l_current_pk_id ;
18487          --
18488        end if;
18489        --
18490      end if;
18491      --
18492    end loop;
18493    --
18494  exception when others then
18495     --
18496     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'DCL',r_dcl.information5 );
18497     --
18498  end create_DCL_rows;
18499 
18500    ---------------------------------------------------------------
18501    ----------------------< create_TTP_rows >-----------------------
18502    ---------------------------------------------------------------
18503    --
18504    procedure create_TTP_rows
18505    (
18506          p_validate                       in  number     default 0
18507         ,p_copy_entity_txn_id             in  number
18508         ,p_effective_date                 in  date
18509         ,p_prefix_suffix_text             in  varchar2  default null
18510         ,p_reuse_object_flag              in  varchar2  default null
18511         ,p_target_business_group_id       in  varchar2  default null
18512         ,p_prefix_suffix_cd               in  varchar2  default null
18513    ) is
18514    --
18515    l_PRTT_DET_RL  number;
18516    l_VRBL_RT_PRFL_ID  number;
18517    l_PRTT_DET_CD      varchar2(100);
18518    l_EXCLD_FLAG      varchar2(100);
18519    l_MN_PRTT_NUM      number;
18520    l_MX_PRTT_NUM      number;
18521    l_NO_MN_PRTT_NUM_APLS_FLAG      varchar2(100);
18522    l_NO_MX_PRTT_NUM_APLS_FLAG      varchar2(100);
18523    --
18524    cursor c_unique_TTP(l_table_alias varchar2) is
18525    select distinct cpe.information1,
18526      cpe.information2,
18527      cpe.information3,
18528      cpe.table_route_id
18529    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
18530         pqh_table_route tr
18531    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
18532    and   cpe.table_route_id     = tr.table_route_id
18533    -- and   tr.where_clause        = l_BEN_TTL_PRTT_RT_F
18534    and tr.table_alias = l_table_alias
18535    and   cpe.number_of_copies   = 1 -- ADDITION
18536    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
18537    order by information1, information2; --added for bug: 5151945
18538    --
18539    --
18540    cursor c_TTP_min_max_dates(c_table_route_id  number,
18541                 c_information1   number) is
18542    select
18543      min(cpe.information2) min_esd,
18544      max(cpe.information3) min_eed
18545    from ben_copy_entity_results cpe
18546    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
18547    and   cpe.table_route_id     = c_table_route_id
18548    and   cpe.information1       = c_information1 ;
18549    --
18550    cursor c_TTP(c_table_route_id  number,
18551                 c_information1   number,
18552                 c_information2   Date,
18553                 c_information3   Date)  is
18554    select
18555      cpe.*
18556    from ben_copy_entity_results cpe
18557    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
18558    and   cpe.table_route_id     = c_table_route_id
18559    and   cpe.information1       = c_information1
18560    and   cpe.information2       = c_information2
18561    and   cpe.information3       = c_information3
18562    and rownum = 1 ;
18563    -- Date Track target record
18564    cursor c_find_TTP_in_target(
18565                                 c_effective_start_date    date,
18566                                 c_effective_end_date      date,
18567                                 c_business_group_id       number,
18568                                 c_new_pk_id               number) is
18569    select
18570      TTP.ttl_prtt_rt_id new_value
18571    from BEN_TTL_PRTT_RT_F TTP
18572    where
18573    TTP.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
18574    nvl(TTP.PRTT_DET_CD, '-YYYY') = nvl(l_PRTT_DET_CD, '-YYYY') and
18575    nvl(TTP.PRTT_DET_RL, -999) = nvl(l_PRTT_DET_RL , -999)and
18576    nvl(TTP.EXCLD_FLAG, '-YYYY') = nvl(l_EXCLD_FLAG, '-YYYY')     and
18577    nvl(TTP.MN_PRTT_NUM, -999) = nvl(l_MN_PRTT_NUM, -999) and
18578    nvl(TTP.MX_PRTT_NUM, -999) = nvl(l_MX_PRTT_NUM, -999) and
18579    nvl(TTP.NO_MN_PRTT_NUM_APLS_FLAG, '-YYYY') = nvl(l_NO_MN_PRTT_NUM_APLS_FLAG, '-YYYY')  and
18580    nvl(TTP.NO_MN_PRTT_NUM_APLS_FLAG, '-YYYY') = nvl(l_NO_MN_PRTT_NUM_APLS_FLAG, '-YYYY')  and
18581    TTP.business_group_id  = c_business_group_id
18582    and   TTP.ttl_prtt_rt_id  <> c_new_pk_id
18583 --TEMPIK
18584    and c_effective_start_date between effective_start_date
18585                             and effective_end_date ;
18586 --END TEMPIK
18587 /*TEMPIK
18588    and exists ( select null
18589                 from BEN_TTL_PRTT_RT_F TTP1
18590                 where
18591                 TTP1.VRBL_RT_PRFL_ID   = l_VRBL_RT_PRFL_ID  and
18592    nvl(TTP1.PRTT_DET_CD, '-YYYY') = nvl(l_PRTT_DET_CD, '-YYYY') and
18593    nvl(TTP1.PRTT_DET_RL, -999) = nvl(l_PRTT_DET_RL , -999)and
18594    nvl(TTP1.EXCLD_FLAG, '-YYYY') = nvl(l_EXCLD_FLAG, '-YYYY')     and
18595    nvl(TTP1.MN_PRTT_NUM, -999) = nvl(l_MN_PRTT_NUM, -999) and
18596    nvl(TTP1.MX_PRTT_NUM, -999) = nvl(l_MX_PRTT_NUM, -999) and
18597    nvl(TTP1.NO_MN_PRTT_NUM_APLS_FLAG, '-YYYY') = nvl(l_NO_MN_PRTT_NUM_APLS_FLAG, '-YYYY')  and
18598    nvl(TTP1.NO_MN_PRTT_NUM_APLS_FLAG, '-YYYY') = nvl(l_NO_MN_PRTT_NUM_APLS_FLAG, '-YYYY')  and
18599                 TTP1.business_group_id  = c_business_group_id
18600                 and   TTP1.effective_start_date <= c_effective_start_date )
18601    and exists ( select null
18602                 from BEN_TTL_PRTT_RT_F TTP2
18603                 where
18604                 TTP2.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
18605    nvl(TTP2.PRTT_DET_CD, '-YYYY') = nvl(l_PRTT_DET_CD, '-YYYY') and
18606    nvl(TTP2.PRTT_DET_RL, -999) = nvl(l_PRTT_DET_RL , -999)and
18607    nvl(TTP2.EXCLD_FLAG, '-YYYY') = nvl(l_EXCLD_FLAG, '-YYYY')     and
18608    nvl(TTP2.MN_PRTT_NUM, -999) = nvl(l_MN_PRTT_NUM, -999) and
18609    nvl(TTP2.MX_PRTT_NUM, -999) = nvl(l_MX_PRTT_NUM, -999) and
18610    nvl(TTP2.NO_MN_PRTT_NUM_APLS_FLAG, '-YYYY') = nvl(l_NO_MN_PRTT_NUM_APLS_FLAG, '-YYYY')  and
18611    nvl(TTP2.NO_MN_PRTT_NUM_APLS_FLAG, '-YYYY') = nvl(l_NO_MN_PRTT_NUM_APLS_FLAG, '-YYYY')  and
18612                 TTP2.business_group_id  = c_business_group_id
18613                 and   TTP2.effective_end_date >= c_effective_end_date )
18614                 ;
18615 TEMPIK */
18616    --TEMPIK
18617    l_dt_rec_found            boolean ;
18618    --END TEMPIK
18619    --
18620    l_current_pk_id           number := null ;
18621    --UPD START
18622    --
18623    l_update                  boolean      := false ;
18624    l_datetrack_mode          varchar2(80) := hr_api.g_update;
18625    l_process_date            date;
18626    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
18627    --
18628    --UPD END
18629    l_prev_pk_id              number := null ;
18630    l_first_rec               boolean := true ;
18631    r_TTP                     c_TTP%rowtype;
18632    l_ttl_prtt_rt_id             number ;
18633    l_object_version_number   number ;
18634    l_effective_start_date    date ;
18635    l_effective_end_date      date ;
18636    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
18637    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
18638    l_new_value               number(15);
18639    l_object_found_in_target  boolean := false ;
18640    l_min_esd                 date;
18641    l_max_eed                 date;
18642    l_effective_date          date;
18643    --
18644  begin
18645    -- Initialization
18646    l_object_found_in_target := false ;
18647    -- End Initialization
18648    -- Derive the prefix - sufix
18649    if   p_prefix_suffix_cd = 'PREFIX' then
18650      l_prefix  := p_prefix_suffix_text ;
18651    elsif p_prefix_suffix_cd = 'SUFFIX' then
18652      l_suffix   := p_prefix_suffix_text ;
18653    else
18654      l_prefix := null ;
18655      l_suffix  := null ;
18656    end if ;
18657    -- End Prefix Sufix derivation
18658    for r_TTP_unique in c_unique_TTP('TTP') loop
18659 
18660      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
18661         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
18662          r_TTP_unique.information3 >=
18663                  ben_pd_copy_to_ben_one.g_copy_effective_date)
18664         ) then
18665        --
18666        hr_utility.set_location(' r_TTP_unique.table_route_id '||r_TTP_unique.table_route_id,10);
18667        hr_utility.set_location(' r_TTP_unique.information1 '||r_TTP_unique.information1,10);
18668        hr_utility.set_location( 'r_TTP_unique.information2 '||r_TTP_unique.information2,10);
18669        hr_utility.set_location( 'r_TTP_unique.information3 '||r_TTP_unique.information3,10);
18670        -- If reuse objects flag is 'Y' then check for the object in the target business group
18671        -- if found insert the record into PLSql table and exit the loop else try create the
18672        -- object in the target business group
18673        --
18674        l_object_found_in_target := false ;
18675        l_min_esd := null ;
18676        l_max_eed := null ;
18677        open c_TTP_min_max_dates(r_TTP_unique.table_route_id, r_TTP_unique.information1 ) ;
18678        fetch c_TTP_min_max_dates into l_min_esd,l_max_eed ;
18679        --
18680 
18681        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
18682             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
18683          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
18684        end if;
18685        l_min_esd := greatest(l_min_esd,r_TTP_unique.information2);
18686        open c_TTP(r_TTP_unique.table_route_id,
18687                 r_TTP_unique.information1,
18688                 r_TTP_unique.information2,
18689                 r_TTP_unique.information3 ) ;
18690        --
18691        fetch c_TTP into r_TTP ;
18692        --
18693        close c_TTP ;
18694        --
18695        l_PRTT_DET_RL := get_fk('FORMULA_ID', r_TTP.information264,r_TTP_unique.dml_operation);
18696        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_TTP.information262,r_TTP_unique.dml_operation);
18697        l_EXCLD_FLAG     :=  r_TTP.information11;
18698        l_MN_PRTT_NUM    := r_TTP.information261;
18699        l_MX_PRTT_NUM    := r_TTP.information263;
18700        l_NO_MN_PRTT_NUM_APLS_FLAG      := r_TTP.information12;
18701        l_NO_MX_PRTT_NUM_APLS_FLAG      := r_TTP.information13;
18702        -- l_ORDR_NUM      := r_TTP.information260;
18703        l_PRTT_DET_CD      := r_TTP.information14;
18704        --
18705        --UPD START
18706        l_update := false;
18707        l_process_date := p_effective_date;
18708        l_dml_operation:= r_TTP_unique.dml_operation ;
18709        --
18710        if l_dml_operation = 'UPDATE' then
18711          --
18712          l_object_found_in_target := TRUE;
18713          --
18714          if l_process_date between r_TTP_unique.information2 and r_TTP_unique.information3 then
18715                l_update := true;
18716                if r_TTP_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
18717                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'TTL_PRTT_RT_ID'
18718                then
18719                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'TTL_PRTT_RT_ID' ;
18720                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_TTP_unique.information1 ;
18721                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_TTP_unique.information1 ;
18722                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
18723                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_TTP_unique.table_route_id;
18724                   --
18725                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
18726                   --
18727                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
18728                   --
18729                   -- log_data('TTP',l_new_value,l_prefix || r_TTP_unique.name|| l_suffix,'REUSED');
18730                   --
18731                end if ;
18732                hr_utility.set_location( 'found record for update',10);
18733            --
18734          else
18735            --
18736            l_update := false;
18737            --
18738          end if;
18739        else
18740          --
18741          --UPD END
18742        if p_reuse_object_flag = 'Y' then
18743          if c_TTP_min_max_dates%found then
18744            -- cursor to find the object
18745            open c_find_TTP_in_target( l_min_esd,l_max_eed,
18746                                  p_target_business_group_id, nvl(l_ttl_prtt_rt_id, -999)  ) ;
18747            fetch c_find_TTP_in_target into l_new_value ;
18748            if c_find_TTP_in_target%found then
18749              --
18750              --TEMPIK
18751              l_dt_rec_found :=   dt_api.check_min_max_dates
18752                  (p_base_table_name => 'BEN_TTL_PRTT_RT_F',
18753                   p_base_key_column => 'TTL_PRTT_RT_ID',
18754                   p_base_key_value  => l_new_value,
18755                   p_from_date       => l_min_esd,
18756                   p_to_date         => l_max_eed );
18757              if l_dt_rec_found THEN
18758              --END TEMPIK
18759              if r_TTP_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
18760                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'TTL_PRTT_RT_ID'  then
18761                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'TTL_PRTT_RT_ID' ;
18762                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_TTP_unique.information1 ;
18763                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
18764                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
18765                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_TTP_unique.table_route_id;
18766                 --
18767                 -- 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) ;
18768                 --
18769                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
18770              end if ;
18771              --
18772              l_object_found_in_target := true ;
18773              --TEMPIK
18774              end if; -- l_dt_rec_found
18775              --END TEMPIK
18776            end if;
18777            close c_find_TTP_in_target ;
18778          --
18779          end if;
18780        end if ;
18781        --
18782        end if;
18783        close c_TTP_min_max_dates ;
18784        if not l_object_found_in_target OR l_update   then
18785          --
18786          l_current_pk_id := r_TTP.information1;
18787          --
18788          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
18789          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
18790          --
18791          if l_current_pk_id =  l_prev_pk_id  then
18792            --
18793            l_first_rec := false ;
18794            --
18795          else
18796            --
18797            l_first_rec := true ;
18798            --
18799          end if ;
18800          --
18801 
18802          l_effective_date := r_TTP.information2;
18803          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
18804               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
18805            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
18806          end if;
18807 
18808          if l_first_rec and not l_update then
18809            -- Call Create routine.
18810            hr_utility.set_location(' BEN_TTL_PRTT_RT_F CREATE_TTL_PRTT_RT ',20);
18811            BEN_TTL_PRTT_RT_API.CREATE_TTL_PRTT_RT(
18812              --
18813              P_VALIDATE               => false
18814              ,P_EFFECTIVE_DATE        => l_effective_date
18815              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
18816              --
18817              ,P_EXCLD_FLAG      => r_TTP.INFORMATION11
18818              ,P_MN_PRTT_NUM      => r_TTP.INFORMATION261
18819              ,P_MX_PRTT_NUM      => r_TTP.INFORMATION263
18820              ,P_NO_MN_PRTT_NUM_APLS_FLAG      => r_TTP.INFORMATION12
18821              ,P_NO_MX_PRTT_NUM_APLS_FLAG      => r_TTP.INFORMATION13
18822              ,P_ORDR_NUM      => r_TTP.INFORMATION260
18823              ,P_PRTT_DET_CD      => r_TTP.INFORMATION14
18824              ,P_PRTT_DET_RL      => l_PRTT_DET_RL
18825              ,P_TTL_PRTT_RT_ID      => l_ttl_prtt_rt_id
18826              ,P_TTP_ATTRIBUTE1      => r_TTP.INFORMATION111
18827              ,P_TTP_ATTRIBUTE10      => r_TTP.INFORMATION120
18828              ,P_TTP_ATTRIBUTE11      => r_TTP.INFORMATION121
18829              ,P_TTP_ATTRIBUTE12      => r_TTP.INFORMATION122
18830              ,P_TTP_ATTRIBUTE13      => r_TTP.INFORMATION123
18831              ,P_TTP_ATTRIBUTE14      => r_TTP.INFORMATION124
18832              ,P_TTP_ATTRIBUTE15      => r_TTP.INFORMATION125
18833              ,P_TTP_ATTRIBUTE16      => r_TTP.INFORMATION126
18834              ,P_TTP_ATTRIBUTE17      => r_TTP.INFORMATION127
18835              ,P_TTP_ATTRIBUTE18      => r_TTP.INFORMATION128
18836              ,P_TTP_ATTRIBUTE19      => r_TTP.INFORMATION129
18837              ,P_TTP_ATTRIBUTE2      => r_TTP.INFORMATION112
18838              ,P_TTP_ATTRIBUTE20      => r_TTP.INFORMATION130
18839              ,P_TTP_ATTRIBUTE21      => r_TTP.INFORMATION131
18840              ,P_TTP_ATTRIBUTE22      => r_TTP.INFORMATION132
18841              ,P_TTP_ATTRIBUTE23      => r_TTP.INFORMATION133
18842              ,P_TTP_ATTRIBUTE24      => r_TTP.INFORMATION134
18843              ,P_TTP_ATTRIBUTE25      => r_TTP.INFORMATION135
18844              ,P_TTP_ATTRIBUTE26      => r_TTP.INFORMATION136
18845              ,P_TTP_ATTRIBUTE27      => r_TTP.INFORMATION137
18846              ,P_TTP_ATTRIBUTE28      => r_TTP.INFORMATION138
18847              ,P_TTP_ATTRIBUTE29      => r_TTP.INFORMATION139
18848              ,P_TTP_ATTRIBUTE3      => r_TTP.INFORMATION113
18849              ,P_TTP_ATTRIBUTE30      => r_TTP.INFORMATION140
18850              ,P_TTP_ATTRIBUTE4      => r_TTP.INFORMATION114
18851              ,P_TTP_ATTRIBUTE5      => r_TTP.INFORMATION115
18852              ,P_TTP_ATTRIBUTE6      => r_TTP.INFORMATION116
18853              ,P_TTP_ATTRIBUTE7      => r_TTP.INFORMATION117
18854              ,P_TTP_ATTRIBUTE8      => r_TTP.INFORMATION118
18855              ,P_TTP_ATTRIBUTE9      => r_TTP.INFORMATION119
18856              ,P_TTP_ATTRIBUTE_CATEGORY      => r_TTP.INFORMATION110
18857              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
18858              --
18859              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
18860              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
18861              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
18862            );
18863            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
18864            -- Update all relevent cer records with new pk_id
18865            hr_utility.set_location('Before plsql table ',222);
18866            hr_utility.set_location('new_value id '||l_ttl_prtt_rt_id,222);
18867            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'TTL_PRTT_RT_ID' ;
18868            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_TTP.information1 ;
18869            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_TTL_PRTT_RT_ID ;
18870            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
18871            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_TTP_unique.table_route_id;
18872            hr_utility.set_location('After plsql table ',222);
18873            --
18874            -- 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 ) ;
18875            --
18876            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
18877            --
18878          else
18879            --
18880            -- Call Update routine for the pk_id created in prev run .
18881            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
18882            --UPD START
18883            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
18884            --
18885            if l_update then
18886              --
18887              l_datetrack_mode := r_TTP.datetrack_mode ;
18888              --
18889              get_dt_modes(
18890                p_effective_date        => l_process_date,
18891                p_effective_end_date    => r_TTP.information3,
18892                p_effective_start_date  => r_TTP.information2,
18893                p_dml_operation         => r_TTP.dml_operation,
18894                p_datetrack_mode        => l_datetrack_mode );
18895            --    p_update                => l_update
18896              --
18897              l_effective_date := l_process_date;
18898              l_TTL_PRTT_RT_ID   := r_TTP.information1;
18899              l_object_version_number := r_TTP.information265;
18900              --
18901            end if;
18902            --
18903            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
18904            --
18905            IF l_update OR l_dml_operation <> 'UPDATE' THEN
18906            --UPD END
18907            hr_utility.set_location(' BEN_TTL_PRTT_RT_F UPDATE_TTL_PRTT_RT ',30);
18908            BEN_TTL_PRTT_RT_API.UPDATE_TTL_PRTT_RT(
18909              --
18910              P_VALIDATE               => false
18911              ,P_EFFECTIVE_DATE        => l_effective_date
18912              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
18913              --
18914              ,P_EXCLD_FLAG      => r_TTP.INFORMATION11
18915              ,P_MN_PRTT_NUM      => r_TTP.INFORMATION261
18916              ,P_MX_PRTT_NUM      => r_TTP.INFORMATION263
18917              ,P_NO_MN_PRTT_NUM_APLS_FLAG      => r_TTP.INFORMATION12
18918              ,P_NO_MX_PRTT_NUM_APLS_FLAG      => r_TTP.INFORMATION13
18919              ,P_ORDR_NUM      => r_TTP.INFORMATION260
18920              ,P_PRTT_DET_CD      => r_TTP.INFORMATION14
18921              ,P_PRTT_DET_RL      => l_PRTT_DET_RL
18922              ,P_TTL_PRTT_RT_ID      => l_ttl_prtt_rt_id
18923              ,P_TTP_ATTRIBUTE1      => r_TTP.INFORMATION111
18924              ,P_TTP_ATTRIBUTE10      => r_TTP.INFORMATION120
18925              ,P_TTP_ATTRIBUTE11      => r_TTP.INFORMATION121
18926              ,P_TTP_ATTRIBUTE12      => r_TTP.INFORMATION122
18927              ,P_TTP_ATTRIBUTE13      => r_TTP.INFORMATION123
18928              ,P_TTP_ATTRIBUTE14      => r_TTP.INFORMATION124
18929              ,P_TTP_ATTRIBUTE15      => r_TTP.INFORMATION125
18930              ,P_TTP_ATTRIBUTE16      => r_TTP.INFORMATION126
18931              ,P_TTP_ATTRIBUTE17      => r_TTP.INFORMATION127
18932              ,P_TTP_ATTRIBUTE18      => r_TTP.INFORMATION128
18933              ,P_TTP_ATTRIBUTE19      => r_TTP.INFORMATION129
18934              ,P_TTP_ATTRIBUTE2      => r_TTP.INFORMATION112
18935              ,P_TTP_ATTRIBUTE20      => r_TTP.INFORMATION130
18936              ,P_TTP_ATTRIBUTE21      => r_TTP.INFORMATION131
18937              ,P_TTP_ATTRIBUTE22      => r_TTP.INFORMATION132
18938              ,P_TTP_ATTRIBUTE23      => r_TTP.INFORMATION133
18939              ,P_TTP_ATTRIBUTE24      => r_TTP.INFORMATION134
18940              ,P_TTP_ATTRIBUTE25      => r_TTP.INFORMATION135
18941              ,P_TTP_ATTRIBUTE26      => r_TTP.INFORMATION136
18942              ,P_TTP_ATTRIBUTE27      => r_TTP.INFORMATION137
18943              ,P_TTP_ATTRIBUTE28      => r_TTP.INFORMATION138
18944              ,P_TTP_ATTRIBUTE29      => r_TTP.INFORMATION139
18945              ,P_TTP_ATTRIBUTE3      => r_TTP.INFORMATION113
18946              ,P_TTP_ATTRIBUTE30      => r_TTP.INFORMATION140
18947              ,P_TTP_ATTRIBUTE4      => r_TTP.INFORMATION114
18948              ,P_TTP_ATTRIBUTE5      => r_TTP.INFORMATION115
18949              ,P_TTP_ATTRIBUTE6      => r_TTP.INFORMATION116
18950              ,P_TTP_ATTRIBUTE7      => r_TTP.INFORMATION117
18951              ,P_TTP_ATTRIBUTE8      => r_TTP.INFORMATION118
18952              ,P_TTP_ATTRIBUTE9      => r_TTP.INFORMATION119
18953              ,P_TTP_ATTRIBUTE_CATEGORY      => r_TTP.INFORMATION110
18954              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
18955              --
18956              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
18957              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
18958              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
18959              ,P_DATETRACK_MODE        => l_datetrack_mode
18960            );
18961            --
18962            end if;
18963          end if;
18964          --
18965          -- Delete the row if it is end dated.
18966          --
18967          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
18968              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
18969              trunc(l_max_eed) = r_TTP.information3) then
18970              --
18971              BEN_TTL_PRTT_RT_API.delete_TTL_PRTT_RT(
18972                 --
18973                 p_validate                       => false
18974                 ,p_ttl_prtt_rt_id                   => l_ttl_prtt_rt_id
18975                 ,p_effective_start_date           => l_effective_start_date
18976                 ,p_effective_end_date             => l_effective_end_date
18977                 ,p_object_version_number          => l_object_version_number
18978                 ,p_effective_date                 => l_max_eed
18979                 ,p_datetrack_mode                 => hr_api.g_delete
18980                 --
18981                 );
18982                 --
18983          end if;
18984          --
18985          l_prev_pk_id := l_current_pk_id ;
18986          --
18987        end if;
18988        --
18989      end if;
18990      --
18991    end loop;
18992    --
18993  exception when others then
18994     --
18995     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'TTP',r_ttp.information5 );
18996     --
18997  end create_TTP_rows;
18998 
18999    --
19000    ---------------------------------------------------------------
19001    ----------------------< create_TCV_rows >-----------------------
19002    ---------------------------------------------------------------
19003    --
19004    procedure create_TCV_rows
19005    (
19006          p_validate                       in  number     default 0
19007         ,p_copy_entity_txn_id             in  number
19008         ,p_effective_date                 in  date
19009         ,p_prefix_suffix_text             in  varchar2  default null
19010         ,p_reuse_object_flag              in  varchar2  default null
19011         ,p_target_business_group_id       in  varchar2  default null
19012         ,p_prefix_suffix_cd               in  varchar2  default null
19013    ) is
19014    --
19015    l_CVG_VOL_DET_RL  number;
19016    l_VRBL_RT_PRFL_ID  number;
19017    l_CVG_VOL_DET_CD      varchar2(100);
19018    l_EXCLD_FLAG      varchar2(100);
19019    l_MN_CVG_VOL_AMT      number;
19020    l_MX_CVG_VOL_AMT      number;
19021    l_NO_MN_CVG_VOL_AMT_APLS_FLAG      varchar2(100);
19022    l_NO_MX_CVG_VOL_AMT_APLS_FLAG      varchar2(100);
19023    --
19024    cursor c_unique_TCV(l_table_alias varchar2) is
19025    select distinct cpe.information1,
19026      cpe.information2,
19027      cpe.information3,
19028      cpe.table_route_id
19029    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
19030         pqh_table_route tr
19031    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
19032    and   cpe.table_route_id     = tr.table_route_id
19033    -- and   tr.where_clause        = l_BEN_TTL_CVG_VOL_RT_F
19034    and tr.table_alias = l_table_alias
19035    and   cpe.number_of_copies   = 1 -- ADDITION
19036    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
19037    order by information1, information2; --added for bug: 5151945
19038    --
19039    --
19040    cursor c_TCV_min_max_dates(c_table_route_id  number,
19041                 c_information1   number) is
19042    select
19043      min(cpe.information2) min_esd,
19044      max(cpe.information3) min_eed
19045    from ben_copy_entity_results cpe
19046    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
19047    and   cpe.table_route_id     = c_table_route_id
19048    and   cpe.information1       = c_information1 ;
19049    --
19050    cursor c_TCV(c_table_route_id  number,
19051                 c_information1   number,
19052                 c_information2   Date,
19053                 c_information3   Date)  is
19054    select
19055      cpe.*
19056    from ben_copy_entity_results cpe
19057    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
19058    and   cpe.table_route_id     = c_table_route_id
19059    and   cpe.information1       = c_information1
19060    and   cpe.information2       = c_information2
19061    and   cpe.information3       = c_information3
19062    and rownum = 1 ;
19063    -- Date Track target record
19064    cursor c_find_TCV_in_target(
19065                                 c_effective_start_date    date,
19066                                 c_effective_end_date      date,
19067                                 c_business_group_id       number,
19068                                 c_new_pk_id               number) is
19069    select
19070      TCV.ttl_cvg_vol_rt_id new_value
19071    from BEN_TTL_CVG_VOL_RT_F TCV
19072    where
19073    TCV.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
19074    nvl(TCV.CVG_VOL_DET_CD, '-YYYY') = nvl(l_CVG_VOL_DET_CD, '-YYYY') and
19075    nvl(TCV.CVG_VOL_DET_RL, -999) = nvl(l_CVG_VOL_DET_RL , -999)and
19076    nvl(TCV.EXCLD_FLAG, '-YYYY') = nvl(l_EXCLD_FLAG, '-YYYY')     and
19077    nvl(TCV.MN_CVG_VOL_AMT, -999) = nvl(l_MN_CVG_VOL_AMT, -999) and
19078    nvl(TCV.MX_CVG_VOL_AMT, -999) = nvl(l_MX_CVG_VOL_AMT, -999) and
19079    nvl(TCV.NO_MN_CVG_VOL_AMT_APLS_FLAG, '-YYYY') = nvl(l_NO_MN_CVG_VOL_AMT_APLS_FLAG, '-YYYY') and
19080    nvl(TCV.NO_MX_CVG_VOL_AMT_APLS_FLAG, '-YYYY') = nvl(l_NO_MX_CVG_VOL_AMT_APLS_FLAG, '-YYYY') and
19081    TCV.business_group_id  = c_business_group_id
19082    and   TCV.ttl_cvg_vol_rt_id  <> c_new_pk_id
19083 --TEMPIK
19084    and c_effective_start_date between effective_start_date
19085                             and effective_end_date ;
19086 --END TEMPIK
19087 /*TEMPIK
19088    and exists ( select null
19089                 from BEN_TTL_CVG_VOL_RT_F TCV1
19090                 where
19091                 TCV1.VRBL_RT_PRFL_ID  = l_VRBL_RT_PRFL_ID  and
19092                 nvl(TCV1.CVG_VOL_DET_CD, '-YYYY') = nvl(l_CVG_VOL_DET_CD, '-YYYY') and
19093                 nvl(TCV1.CVG_VOL_DET_RL, -999) = nvl(l_CVG_VOL_DET_RL , -999)and
19094                 nvl(TCV1.EXCLD_FLAG, '-YYYY') = nvl(l_EXCLD_FLAG, '-YYYY')     and
19095                 nvl(TCV1.MN_CVG_VOL_AMT, -999) = nvl(l_MN_CVG_VOL_AMT, -999) and
19096                 nvl(TCV1.MX_CVG_VOL_AMT, -999) = nvl(l_MX_CVG_VOL_AMT, -999) and
19097                 nvl(TCV1.NO_MN_CVG_VOL_AMT_APLS_FLAG, '-YYYY') = nvl(l_NO_MN_CVG_VOL_AMT_APLS_FLAG, '-YYYY') and
19098                 nvl(TCV1.NO_MX_CVG_VOL_AMT_APLS_FLAG, '-YYYY') = nvl(l_NO_MX_CVG_VOL_AMT_APLS_FLAG, '-YYYY') and
19099                 TCV1.business_group_id  = c_business_group_id
19100                 and   TCV1.effective_start_date <= c_effective_start_date )
19101    and exists ( select null
19102                 from BEN_TTL_CVG_VOL_RT_F TCV2
19103                 where
19104                 TCV2.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
19105                 nvl(TCV2.CVG_VOL_DET_CD, '-YYYY') = nvl(l_CVG_VOL_DET_CD, '-YYYY') and
19106                 nvl(TCV2.CVG_VOL_DET_RL, -999) = nvl(l_CVG_VOL_DET_RL , -999)and
19107                 nvl(TCV2.EXCLD_FLAG, '-YYYY') = nvl(l_EXCLD_FLAG, '-YYYY')     and
19108                 nvl(TCV2.MN_CVG_VOL_AMT, -999) = nvl(l_MN_CVG_VOL_AMT, -999) and
19109                 nvl(TCV2.MX_CVG_VOL_AMT, -999) = nvl(l_MX_CVG_VOL_AMT, -999) and
19110                 nvl(TCV2.NO_MN_CVG_VOL_AMT_APLS_FLAG, '-YYYY') = nvl(l_NO_MN_CVG_VOL_AMT_APLS_FLAG, '-YYYY') and
19111                 nvl(TCV2.NO_MX_CVG_VOL_AMT_APLS_FLAG, '-YYYY') = nvl(l_NO_MX_CVG_VOL_AMT_APLS_FLAG, '-YYYY') and
19112                 TCV2.business_group_id  = c_business_group_id
19113                 and   TCV2.effective_end_date >= c_effective_end_date )
19114                 ;
19115 TEMPIK */
19116    --TEMPIK
19117    l_dt_rec_found            boolean ;
19118    --END TEMPIK
19119    --
19120    l_current_pk_id           number := null ;
19121    --UPD START
19122    --
19123    l_update                  boolean      := false ;
19124    l_datetrack_mode          varchar2(80) := hr_api.g_update;
19125    l_process_date            date;
19126    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
19127    --
19128    --UPD END
19129    l_prev_pk_id              number := null ;
19130    l_first_rec               boolean := true ;
19131    r_TCV                     c_TCV%rowtype;
19132    l_ttl_cvg_vol_rt_id             number ;
19133    l_object_version_number   number ;
19134    l_effective_start_date    date ;
19135    l_effective_end_date      date ;
19136    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
19137    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
19138    l_new_value               number(15);
19139    l_object_found_in_target  boolean := false ;
19140    l_min_esd                 date;
19141    l_max_eed                 date;
19142    l_effective_date          date;
19143    --
19144  begin
19145    -- Initialization
19146    l_object_found_in_target := false ;
19147    -- End Initialization
19148    -- Derive the prefix - sufix
19149    if   p_prefix_suffix_cd = 'PREFIX' then
19150      l_prefix  := p_prefix_suffix_text ;
19151    elsif p_prefix_suffix_cd = 'SUFFIX' then
19152      l_suffix   := p_prefix_suffix_text ;
19153    else
19154      l_prefix := null ;
19155      l_suffix  := null ;
19156    end if ;
19157    -- End Prefix Sufix derivation
19158    for r_TCV_unique in c_unique_TCV('TCV') loop
19159 
19160      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
19161         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
19162          r_TCV_unique.information3 >=
19163                  ben_pd_copy_to_ben_one.g_copy_effective_date)
19164         ) then
19165        --
19166        hr_utility.set_location(' r_TCV_unique.table_route_id '||r_TCV_unique.table_route_id,10);
19167        hr_utility.set_location(' r_TCV_unique.information1 '||r_TCV_unique.information1,10);
19168        hr_utility.set_location( 'r_TCV_unique.information2 '||r_TCV_unique.information2,10);
19169        hr_utility.set_location( 'r_TCV_unique.information3 '||r_TCV_unique.information3,10);
19170        -- If reuse objects flag is 'Y' then check for the object in the target business group
19171        -- if found insert the record into PLSql table and exit the loop else try create the
19172        -- object in the target business group
19173        --
19174        l_object_found_in_target := false ;
19175        l_min_esd := null ;
19176        l_max_eed := null ;
19177        open c_TCV_min_max_dates(r_TCV_unique.table_route_id, r_TCV_unique.information1 ) ;
19178        fetch c_TCV_min_max_dates into l_min_esd,l_max_eed ;
19179        --
19180 
19181        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
19182             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
19183          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
19184        end if;
19185        l_min_esd := greatest(l_min_esd,r_TCV_unique.information2);
19186        open c_TCV(r_TCV_unique.table_route_id,
19187                 r_TCV_unique.information1,
19188                 r_TCV_unique.information2,
19189                 r_TCV_unique.information3 ) ;
19190        --
19191        fetch c_TCV into r_TCV ;
19192        --
19193        close c_TCV ;
19194        --
19195        l_CVG_VOL_DET_RL := get_fk('FORMULA_ID', r_TCV.information261,r_TCV_unique.dml_operation);
19196        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_TCV.information262,r_TCV_unique.dml_operation);
19197        l_CVG_VOL_DET_CD      :=  r_TCV.information14;
19198        l_EXCLD_FLAG      :=  r_TCV.information11;
19199        l_MN_CVG_VOL_AMT      :=  r_TCV.information293;
19200        l_MX_CVG_VOL_AMT      :=  r_TCV.information294;
19201        l_NO_MN_CVG_VOL_AMT_APLS_FLAG      :=  r_TCV.information12;
19202        l_NO_MX_CVG_VOL_AMT_APLS_FLAG      :=  r_TCV.information13;
19203        --UPD START
19204        l_update := false;
19205        l_process_date := p_effective_date;
19206        l_dml_operation:= r_TCV_unique.dml_operation ;
19207        --
19208        if l_dml_operation = 'UPDATE' then
19209          --
19210          l_object_found_in_target := TRUE;
19211          --
19212          if l_process_date between r_TCV_unique.information2 and r_TCV_unique.information3 then
19213                l_update := true;
19214                if r_TCV_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
19215                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'TTL_CVG_VOL_RT_ID'
19216                then
19217                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'TTL_CVG_VOL_RT_ID' ;
19218                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_TCV_unique.information1 ;
19219                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_TCV_unique.information1 ;
19220                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
19221                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_TCV_unique.table_route_id;
19222                   --
19223                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
19224                   --
19225                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
19226                   --
19227                   -- log_data('TCV',l_new_value,l_prefix || r_TCV_unique.name|| l_suffix,'REUSED');
19228                   --
19229                end if ;
19230                hr_utility.set_location( 'found record for update',10);
19231            --
19232          else
19233            --
19234            l_update := false;
19235            --
19236          end if;
19237        else
19238          --
19239          --UPD END
19240        if p_reuse_object_flag = 'Y' then
19241          if c_TCV_min_max_dates%found then
19242            -- cursor to find the object
19243            open c_find_TCV_in_target( l_min_esd,l_max_eed,
19244                                  p_target_business_group_id, nvl(l_ttl_cvg_vol_rt_id, -999)  ) ;
19245            fetch c_find_TCV_in_target into l_new_value ;
19246            if c_find_TCV_in_target%found then
19247              --
19248              --TEMPIK
19249              l_dt_rec_found :=   dt_api.check_min_max_dates
19250                  (p_base_table_name => 'BEN_TTL_CVG_VOL_RT_F',
19251                   p_base_key_column => 'TTL_CVG_VOL_RT_ID',
19252                   p_base_key_value  => l_new_value,
19253                   p_from_date       => l_min_esd,
19254                   p_to_date         => l_max_eed );
19255              if l_dt_rec_found THEN
19256              --END TEMPIK
19257              if r_TCV_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
19258                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'TTL_CVG_VOL_RT_ID'  then
19259                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'TTL_CVG_VOL_RT_ID' ;
19260                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_TCV_unique.information1 ;
19261                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
19262                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
19263                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_TCV_unique.table_route_id;
19264                 --
19265                 -- 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) ;
19266                 --
19267                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
19268              end if ;
19269              --
19270              l_object_found_in_target := true ;
19271              --TEMPIK
19272              end if; -- l_dt_rec_found
19273              --END TEMPIK
19274            end if;
19275            close c_find_TCV_in_target ;
19276          --
19277          end if;
19278        end if ;
19279        --
19280        end if;
19281        close c_TCV_min_max_dates ;
19282        if not l_object_found_in_target OR l_update   then
19283          --
19284          l_current_pk_id := r_TCV.information1;
19285          --
19286          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
19287          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
19288          --
19289          if l_current_pk_id =  l_prev_pk_id  then
19290            --
19291            l_first_rec := false ;
19292            --
19293          else
19294            --
19295            l_first_rec := true ;
19296            --
19297          end if ;
19298          --
19299 
19300          l_effective_date := r_TCV.information2;
19301          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
19302               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
19303            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
19304          end if;
19305 
19306          if l_first_rec and not l_update then
19307            -- Call Create routine.
19308            hr_utility.set_location(' BEN_TTL_CVG_VOL_RT_F CREATE_TTL_CVG_VOL_RT ',20);
19309            BEN_TTL_CVG_VOL_RT_API.CREATE_TTL_CVG_VOL_RT(
19310              --
19311              P_VALIDATE               => false
19312              ,P_EFFECTIVE_DATE        => l_effective_date
19313              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
19314              --
19315              ,P_CVG_VOL_DET_CD      => r_TCV.INFORMATION14
19316              ,P_CVG_VOL_DET_RL      => l_CVG_VOL_DET_RL
19317              ,P_EXCLD_FLAG      => r_TCV.INFORMATION11
19318              ,P_MN_CVG_VOL_AMT      => r_TCV.INFORMATION293
19319              ,P_MX_CVG_VOL_AMT      => r_TCV.INFORMATION294
19320              ,P_NO_MN_CVG_VOL_AMT_APLS_FLAG      => r_TCV.INFORMATION12
19321              ,P_NO_MX_CVG_VOL_AMT_APLS_FLAG      => r_TCV.INFORMATION13
19322              ,P_ORDR_NUM      => r_TCV.INFORMATION260
19323              ,P_TCV_ATTRIBUTE1      => r_TCV.INFORMATION111
19324              ,P_TCV_ATTRIBUTE10      => r_TCV.INFORMATION120
19325              ,P_TCV_ATTRIBUTE11      => r_TCV.INFORMATION121
19326              ,P_TCV_ATTRIBUTE12      => r_TCV.INFORMATION122
19327              ,P_TCV_ATTRIBUTE13      => r_TCV.INFORMATION123
19328              ,P_TCV_ATTRIBUTE14      => r_TCV.INFORMATION124
19329              ,P_TCV_ATTRIBUTE15      => r_TCV.INFORMATION125
19330              ,P_TCV_ATTRIBUTE16      => r_TCV.INFORMATION126
19331              ,P_TCV_ATTRIBUTE17      => r_TCV.INFORMATION127
19332              ,P_TCV_ATTRIBUTE18      => r_TCV.INFORMATION128
19333              ,P_TCV_ATTRIBUTE19      => r_TCV.INFORMATION129
19334              ,P_TCV_ATTRIBUTE2      => r_TCV.INFORMATION112
19335              ,P_TCV_ATTRIBUTE20      => r_TCV.INFORMATION130
19336              ,P_TCV_ATTRIBUTE21      => r_TCV.INFORMATION131
19337              ,P_TCV_ATTRIBUTE22      => r_TCV.INFORMATION132
19338              ,P_TCV_ATTRIBUTE23      => r_TCV.INFORMATION133
19339              ,P_TCV_ATTRIBUTE24      => r_TCV.INFORMATION134
19340              ,P_TCV_ATTRIBUTE25      => r_TCV.INFORMATION135
19341              ,P_TCV_ATTRIBUTE26      => r_TCV.INFORMATION136
19342              ,P_TCV_ATTRIBUTE27      => r_TCV.INFORMATION137
19343              ,P_TCV_ATTRIBUTE28      => r_TCV.INFORMATION138
19344              ,P_TCV_ATTRIBUTE29      => r_TCV.INFORMATION139
19345              ,P_TCV_ATTRIBUTE3      => r_TCV.INFORMATION113
19346              ,P_TCV_ATTRIBUTE30      => r_TCV.INFORMATION140
19347              ,P_TCV_ATTRIBUTE4      => r_TCV.INFORMATION114
19348              ,P_TCV_ATTRIBUTE5      => r_TCV.INFORMATION115
19349              ,P_TCV_ATTRIBUTE6      => r_TCV.INFORMATION116
19350              ,P_TCV_ATTRIBUTE7      => r_TCV.INFORMATION117
19351              ,P_TCV_ATTRIBUTE8      => r_TCV.INFORMATION118
19352              ,P_TCV_ATTRIBUTE9      => r_TCV.INFORMATION119
19353              ,P_TCV_ATTRIBUTE_CATEGORY      => r_TCV.INFORMATION110
19354              ,P_TTL_CVG_VOL_RT_ID      => l_ttl_cvg_vol_rt_id
19355              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
19356              --
19357              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
19358              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
19359              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
19360            );
19361            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
19362            -- Update all relevent cer records with new pk_id
19363            hr_utility.set_location('Before plsql table ',222);
19364            hr_utility.set_location('new_value id '||l_ttl_cvg_vol_rt_id,222);
19365            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'TTL_CVG_VOL_RT_ID' ;
19366            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_TCV.information1 ;
19367            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_TTL_CVG_VOL_RT_ID ;
19368            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
19369            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_TCV_unique.table_route_id;
19370            hr_utility.set_location('After plsql table ',222);
19371            --
19372            -- 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 ) ;
19373            --
19374            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
19375            --
19376          else
19377            --
19378            -- Call Update routine for the pk_id created in prev run .
19379            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
19380             --UPD START
19381            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
19382            --
19383            if l_update then
19384              --
19385              l_datetrack_mode := r_TCV.datetrack_mode ;
19386              --
19387              get_dt_modes(
19388                p_effective_date        => l_process_date,
19389                p_effective_end_date    => r_TCV.information3,
19390                p_effective_start_date  => r_TCV.information2,
19391                p_dml_operation         => r_TCV.dml_operation,
19392                p_datetrack_mode        => l_datetrack_mode );
19393            --    p_update                => l_update
19394              --
19395              l_effective_date := l_process_date;
19396              l_TTL_CVG_VOL_RT_ID   := r_TCV.information1;
19397              l_object_version_number := r_TCV.information265;
19398              --
19399            end if;
19400            --
19401            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
19402            --
19403            IF l_update OR l_dml_operation <> 'UPDATE' THEN
19404            --UPD END
19405            hr_utility.set_location(' BEN_TTL_CVG_VOL_RT_F UPDATE_TTL_CVG_VOL_RT ',30);
19406            BEN_TTL_CVG_VOL_RT_API.UPDATE_TTL_CVG_VOL_RT(
19407              --
19408              P_VALIDATE               => false
19409              ,P_EFFECTIVE_DATE        => l_effective_date
19410              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
19411              --
19412              ,P_CVG_VOL_DET_CD      => r_TCV.INFORMATION14
19413              ,P_CVG_VOL_DET_RL      => l_CVG_VOL_DET_RL
19414              ,P_EXCLD_FLAG      => r_TCV.INFORMATION11
19415              ,P_MN_CVG_VOL_AMT      => r_TCV.INFORMATION293
19416              ,P_MX_CVG_VOL_AMT      => r_TCV.INFORMATION294
19417              ,P_NO_MN_CVG_VOL_AMT_APLS_FLAG      => r_TCV.INFORMATION12
19418              ,P_NO_MX_CVG_VOL_AMT_APLS_FLAG      => r_TCV.INFORMATION13
19419              ,P_ORDR_NUM      => r_TCV.INFORMATION260
19420              ,P_TCV_ATTRIBUTE1      => r_TCV.INFORMATION111
19421              ,P_TCV_ATTRIBUTE10      => r_TCV.INFORMATION120
19422              ,P_TCV_ATTRIBUTE11      => r_TCV.INFORMATION121
19423              ,P_TCV_ATTRIBUTE12      => r_TCV.INFORMATION122
19424              ,P_TCV_ATTRIBUTE13      => r_TCV.INFORMATION123
19425              ,P_TCV_ATTRIBUTE14      => r_TCV.INFORMATION124
19426              ,P_TCV_ATTRIBUTE15      => r_TCV.INFORMATION125
19427              ,P_TCV_ATTRIBUTE16      => r_TCV.INFORMATION126
19428              ,P_TCV_ATTRIBUTE17      => r_TCV.INFORMATION127
19429              ,P_TCV_ATTRIBUTE18      => r_TCV.INFORMATION128
19430              ,P_TCV_ATTRIBUTE19      => r_TCV.INFORMATION129
19431              ,P_TCV_ATTRIBUTE2      => r_TCV.INFORMATION112
19432              ,P_TCV_ATTRIBUTE20      => r_TCV.INFORMATION130
19433              ,P_TCV_ATTRIBUTE21      => r_TCV.INFORMATION131
19434              ,P_TCV_ATTRIBUTE22      => r_TCV.INFORMATION132
19435              ,P_TCV_ATTRIBUTE23      => r_TCV.INFORMATION133
19436              ,P_TCV_ATTRIBUTE24      => r_TCV.INFORMATION134
19437              ,P_TCV_ATTRIBUTE25      => r_TCV.INFORMATION135
19438              ,P_TCV_ATTRIBUTE26      => r_TCV.INFORMATION136
19439              ,P_TCV_ATTRIBUTE27      => r_TCV.INFORMATION137
19440              ,P_TCV_ATTRIBUTE28      => r_TCV.INFORMATION138
19441              ,P_TCV_ATTRIBUTE29      => r_TCV.INFORMATION139
19442              ,P_TCV_ATTRIBUTE3      => r_TCV.INFORMATION113
19443              ,P_TCV_ATTRIBUTE30      => r_TCV.INFORMATION140
19444              ,P_TCV_ATTRIBUTE4      => r_TCV.INFORMATION114
19445              ,P_TCV_ATTRIBUTE5      => r_TCV.INFORMATION115
19446              ,P_TCV_ATTRIBUTE6      => r_TCV.INFORMATION116
19447              ,P_TCV_ATTRIBUTE7      => r_TCV.INFORMATION117
19448              ,P_TCV_ATTRIBUTE8      => r_TCV.INFORMATION118
19449              ,P_TCV_ATTRIBUTE9      => r_TCV.INFORMATION119
19450              ,P_TCV_ATTRIBUTE_CATEGORY      => r_TCV.INFORMATION110
19451              ,P_TTL_CVG_VOL_RT_ID      => l_ttl_cvg_vol_rt_id
19452              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
19453              --
19454              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
19455              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
19456              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
19457              ,P_DATETRACK_MODE        => l_datetrack_mode
19458            );
19459            --
19460            end if;
19461          end if;
19462          --
19463          -- Delete the row if it is end dated.
19464          --
19465          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
19466              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
19467              trunc(l_max_eed) = r_TCV.information3) then
19468              --
19469              BEN_TTL_CVG_VOL_RT_API.delete_TTL_CVG_VOL_RT(
19470                 --
19471                 p_validate                       => false
19472                 ,p_ttl_cvg_vol_rt_id                   => l_ttl_cvg_vol_rt_id
19473                 ,p_effective_start_date           => l_effective_start_date
19474                 ,p_effective_end_date             => l_effective_end_date
19475                 ,p_object_version_number          => l_object_version_number
19476                 ,p_effective_date                 => l_max_eed
19477                 ,p_datetrack_mode                 => hr_api.g_delete
19478                 --
19479                 );
19480                 --
19481          end if;
19482          --
19483          l_prev_pk_id := l_current_pk_id ;
19484          --
19485        end if;
19486        --
19487      end if;
19488      --
19489    end loop;
19490    --
19491  exception when others then
19492     --
19493     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'TCV',r_tcv.information5 );
19494     --
19495  end create_TCV_rows;
19496 
19497    ---------------------------------------------------------------
19498    ----------------------< create_VPR_rows >-----------------------
19499    ---------------------------------------------------------------
19500    --
19501    procedure create_VPR_rows
19502    (
19503          p_validate                       in  number     default 0
19504         ,p_copy_entity_txn_id             in  number
19505         ,p_effective_date                 in  date
19506         ,p_prefix_suffix_text             in  varchar2  default null
19507         ,p_reuse_object_flag              in  varchar2  default null
19508         ,p_target_business_group_id       in  varchar2  default null
19509         ,p_prefix_suffix_cd               in  varchar2  default null
19510    ) is
19511    --
19512    l_FORMULA_ID  number;
19513    l_VRBL_RT_PRFL_ID  number;
19514    cursor c_unique_VPR(l_table_alias varchar2) is
19515    select distinct cpe.information1,
19516      cpe.information2,
19517      cpe.information3,
19518      cpe.table_route_id
19519    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
19520         pqh_table_route tr
19521    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
19522    and   cpe.table_route_id     = tr.table_route_id
19523    -- and   tr.where_clause        = l_BEN_VRBL_RT_PRFL_RL_F
19524    and tr.table_alias = l_table_alias
19525    and   cpe.number_of_copies   = 1 -- ADDITION
19526    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
19527    order by information1, information2; --added for bug: 5151945
19528    --
19529    --
19530    cursor c_VPR_min_max_dates(c_table_route_id  number,
19531                 c_information1   Number) is
19532    select
19533      min(cpe.information2) min_esd,
19534      max(cpe.information3) min_eed
19535    from ben_copy_entity_results cpe
19536    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
19537    and   cpe.table_route_id     = c_table_route_id
19538    and   cpe.information1       = c_information1 ;
19539    --
19540    cursor c_VPR(c_table_route_id  number,
19541                 c_information1   number,
19542                 c_information2   Date,
19543                 c_information3   Date)  is
19544    select
19545      cpe.*
19546    from ben_copy_entity_results cpe
19547    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
19548    and   cpe.table_route_id     = c_table_route_id
19549    and   cpe.information1       = c_information1
19550    and   cpe.information2       = c_information2
19551    and   cpe.information3       = c_information3
19552    and rownum = 1 ;
19553    -- Date Track target record
19554    cursor c_find_VPR_in_target(
19555                                 c_effective_start_date    date,
19556                                 c_effective_end_date      date,
19557                                 c_business_group_id       number,
19558                                 c_new_pk_id               number) is
19559    select
19560      VPR.vrbl_rt_prfl_rl_id new_value
19561    from BEN_VRBL_RT_PRFL_RL_F VPR
19562    where
19563    nvl(VPR.FORMULA_ID,-999)     = nvl(l_FORMULA_ID,-999)  and
19564    VPR.VRBL_RT_PRFL_ID   = l_VRBL_RT_PRFL_ID  and
19565    VPR.business_group_id  = c_business_group_id
19566    and   VPR.vrbl_rt_prfl_rl_id  <> c_new_pk_id
19567 --TEMPIK
19568    and c_effective_start_date between effective_start_date
19569                             and effective_end_date ;
19570 --END TEMPIK
19571 /*TEMPIK
19572    and exists ( select null
19573                 from BEN_VRBL_RT_PRFL_RL_F VPR1
19574                 where
19575                 nvl(VPR1.FORMULA_ID,-999)     = nvl(l_FORMULA_ID,-999)  and
19576                 VPR1.VRBL_RT_PRFL_ID   = l_VRBL_RT_PRFL_ID  and
19577                 VPR1.business_group_id  = c_business_group_id
19578                 and   VPR1.effective_start_date <= c_effective_start_date )
19579    and exists ( select null
19580                 from BEN_VRBL_RT_PRFL_RL_F VPR2
19581                 where
19582                 nvl(VPR2.FORMULA_ID,-999)     = nvl(l_FORMULA_ID,-999)  and
19583                 VPR2.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
19584                 VPR2.business_group_id  = c_business_group_id
19585                 and   VPR2.effective_end_date >= c_effective_end_date )
19586                 ;
19587 TEMPIK */
19588    --TEMPIK
19589    l_dt_rec_found            boolean ;
19590    --END TEMPIK
19591    --
19592    l_current_pk_id           number := null ;
19593    --UPD START
19594    --
19595    l_update                  boolean      := false ;
19596    l_datetrack_mode          varchar2(80) := hr_api.g_update;
19597    l_process_date            date;
19598    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
19599    --
19600    --UPD END
19601    l_prev_pk_id              number := null ;
19602    l_first_rec               boolean := true ;
19603    r_VPR                     c_VPR%rowtype;
19604    l_vrbl_rt_prfl_rl_id             number ;
19605    l_object_version_number   number ;
19606    l_effective_start_date    date ;
19607    l_effective_end_date      date ;
19608    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
19609    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
19610    l_new_value               number(15);
19611    l_object_found_in_target  boolean := false ;
19612    l_min_esd                 date;
19613    l_max_eed                 date;
19614    l_effective_date          date;
19615    --
19616  begin
19617    -- Initialization
19618    l_object_found_in_target := false ;
19619    -- End Initialization
19620    -- Derive the prefix - sufix
19621    if   p_prefix_suffix_cd = 'PREFIX' then
19622      l_prefix  := p_prefix_suffix_text ;
19623    elsif p_prefix_suffix_cd = 'SUFFIX' then
19624      l_suffix   := p_prefix_suffix_text ;
19625    else
19626      l_prefix := null ;
19627      l_suffix  := null ;
19628    end if ;
19629    -- End Prefix Sufix derivation
19630    for r_VPR_unique in c_unique_VPR('VPR') loop
19631 
19632      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
19633         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
19634          r_VPR_unique.information3 >=
19635                  ben_pd_copy_to_ben_one.g_copy_effective_date)
19636         ) then
19637        --
19638        hr_utility.set_location(' r_VPR_unique.table_route_id '||r_VPR_unique.table_route_id,10);
19639        hr_utility.set_location(' r_VPR_unique.information1 '||r_VPR_unique.information1,10);
19640        hr_utility.set_location( 'r_VPR_unique.information2 '||r_VPR_unique.information2,10);
19641        hr_utility.set_location( 'r_VPR_unique.information3 '||r_VPR_unique.information3,10);
19642        -- If reuse objects flag is 'Y' then check for the object in the target business group
19643        -- if found insert the record into PLSql table and exit the loop else try create the
19644        -- object in the target business group
19645        --
19646        l_object_found_in_target := false ;
19647        l_min_esd := null ;
19648        l_max_eed := null ;
19649        open c_VPR_min_max_dates(r_VPR_unique.table_route_id, r_VPR_unique.information1 ) ;
19650        fetch c_VPR_min_max_dates into l_min_esd,l_max_eed ;
19651        --
19652 
19653        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
19654             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
19655          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
19656        end if;
19657        l_min_esd := greatest(l_min_esd,r_VPR_unique.information2);
19658        open c_VPR(r_VPR_unique.table_route_id,
19659                 r_VPR_unique.information1,
19660                 r_VPR_unique.information2,
19661                 r_VPR_unique.information3 ) ;
19662        --
19663        fetch c_VPR into r_VPR ;
19664        --
19665        close c_VPR ;
19666        --
19667        l_FORMULA_ID := get_fk('FORMULA_ID', r_VPR.information251,r_VPR_unique.dml_operation);
19668        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_VPR.information262,r_VPR_unique.dml_operation);
19669        --UPD START
19670        l_update := false;
19671        l_process_date := p_effective_date;
19672        l_dml_operation:= r_VPR_unique.dml_operation ;
19673        --
19674        if l_dml_operation = 'UPDATE' then
19675          --
19676          l_object_found_in_target := TRUE;
19677          --
19678          if l_process_date between r_VPR_unique.information2 and r_VPR_unique.information3 then
19679                l_update := true;
19680                if r_VPR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
19681                  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_RL_ID'
19682                then
19683                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'VRBL_RT_PRFL_RL_ID' ;
19684                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_VPR_unique.information1 ;
19685                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_VPR_unique.information1 ;
19686                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
19687                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_VPR_unique.table_route_id;
19688                   --
19689                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
19690                   --
19691                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
19692                   --
19693                   -- log_data('VPR',l_new_value,l_prefix || r_VPR_unique.name|| l_suffix,'REUSED');
19694                   --
19695                end if ;
19696                hr_utility.set_location( 'found record for update',10);
19697            --
19698          else
19699            --
19700            l_update := false;
19701            --
19702          end if;
19703        else
19704          --
19705          --UPD END
19706        if p_reuse_object_flag = 'Y' then
19707          if c_VPR_min_max_dates%found then
19708            -- cursor to find the object
19709            open c_find_VPR_in_target( l_min_esd,l_max_eed,
19710                                  p_target_business_group_id, nvl(l_vrbl_rt_prfl_rl_id, -999)  ) ;
19711            fetch c_find_VPR_in_target into l_new_value ;
19712            if c_find_VPR_in_target%found then
19713              --TEMPIK
19714              l_dt_rec_found :=   dt_api.check_min_max_dates
19715                  (p_base_table_name => 'BEN_VRBL_RT_PRFL_RL_F',
19716                   p_base_key_column => 'VRBL_RT_PRFL_RL_ID',
19717                   p_base_key_value  => l_new_value,
19718                   p_from_date       => l_min_esd,
19719                   p_to_date         => l_max_eed );
19720              if l_dt_rec_found THEN
19721              --END TEMPIK
19722              --
19723              if r_VPR_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
19724                 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_RL_ID'  then
19725                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'VRBL_RT_PRFL_RL_ID' ;
19726                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_VPR_unique.information1 ;
19727                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
19728                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
19729                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_VPR_unique.table_route_id;
19730                 --
19731                 -- 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) ;
19732                 --
19733                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
19734              end if ;
19735              --
19736              l_object_found_in_target := true ;
19737              --TEMPIK
19738              end if; -- l_dt_rec_found
19739              --END TEMPIK
19740            end if;
19741            close c_find_VPR_in_target ;
19742          --
19743          end if;
19744        end if ;
19745        --
19746        end if ;
19747        close c_VPR_min_max_dates ;
19748        if not l_object_found_in_target OR l_update   then
19749          --
19750          l_current_pk_id := r_VPR.information1;
19751          --
19752          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
19753          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
19754          --
19755          if l_current_pk_id =  l_prev_pk_id  then
19756            --
19757            l_first_rec := false ;
19758            --
19759          else
19760            --
19761            l_first_rec := true ;
19762            --
19763          end if ;
19764          --
19765 
19766          l_effective_date := r_VPR.information2;
19767          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
19768               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
19769            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
19770          end if;
19771 
19772          if l_first_rec and not l_update then
19773            -- Call Create routine.
19774            hr_utility.set_location(' BEN_VRBL_RT_PRFL_RL_F CREATE_VRBL_RT_PRFL_RULE ',20);
19775            BEN_VRBL_RT_PRFL_RULE_API.CREATE_VRBL_RT_PRFL_RULE(
19776              --
19777              P_VALIDATE               => false
19778              ,P_EFFECTIVE_DATE        => l_effective_date
19779              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
19780              --
19781              ,P_DRVBL_FCTR_APLS_FLAG      => r_VPR.INFORMATION11
19782              ,P_FORMULA_ID      => l_FORMULA_ID
19783              ,P_ORDR_TO_APLY_NUM      => r_VPR.INFORMATION260
19784              ,P_VPR_ATTRIBUTE1      => r_VPR.INFORMATION111
19785              ,P_VPR_ATTRIBUTE10      => r_VPR.INFORMATION120
19786              ,P_VPR_ATTRIBUTE11      => r_VPR.INFORMATION121
19787              ,P_VPR_ATTRIBUTE12      => r_VPR.INFORMATION122
19788              ,P_VPR_ATTRIBUTE13      => r_VPR.INFORMATION123
19789              ,P_VPR_ATTRIBUTE14      => r_VPR.INFORMATION124
19790              ,P_VPR_ATTRIBUTE15      => r_VPR.INFORMATION125
19791              ,P_VPR_ATTRIBUTE16      => r_VPR.INFORMATION126
19792              ,P_VPR_ATTRIBUTE17      => r_VPR.INFORMATION127
19793              ,P_VPR_ATTRIBUTE18      => r_VPR.INFORMATION128
19794              ,P_VPR_ATTRIBUTE19      => r_VPR.INFORMATION129
19795              ,P_VPR_ATTRIBUTE2      => r_VPR.INFORMATION112
19796              ,P_VPR_ATTRIBUTE20      => r_VPR.INFORMATION130
19797              ,P_VPR_ATTRIBUTE21      => r_VPR.INFORMATION131
19798              ,P_VPR_ATTRIBUTE22      => r_VPR.INFORMATION132
19799              ,P_VPR_ATTRIBUTE23      => r_VPR.INFORMATION133
19800              ,P_VPR_ATTRIBUTE24      => r_VPR.INFORMATION134
19801              ,P_VPR_ATTRIBUTE25      => r_VPR.INFORMATION135
19802              ,P_VPR_ATTRIBUTE26      => r_VPR.INFORMATION136
19803              ,P_VPR_ATTRIBUTE27      => r_VPR.INFORMATION137
19804              ,P_VPR_ATTRIBUTE28      => r_VPR.INFORMATION138
19805              ,P_VPR_ATTRIBUTE29      => r_VPR.INFORMATION139
19806              ,P_VPR_ATTRIBUTE3      => r_VPR.INFORMATION113
19807              ,P_VPR_ATTRIBUTE30      => r_VPR.INFORMATION140
19808              ,P_VPR_ATTRIBUTE4      => r_VPR.INFORMATION114
19809              ,P_VPR_ATTRIBUTE5      => r_VPR.INFORMATION115
19810              ,P_VPR_ATTRIBUTE6      => r_VPR.INFORMATION116
19811              ,P_VPR_ATTRIBUTE7      => r_VPR.INFORMATION117
19812              ,P_VPR_ATTRIBUTE8      => r_VPR.INFORMATION118
19813              ,P_VPR_ATTRIBUTE9      => r_VPR.INFORMATION119
19814              ,P_VPR_ATTRIBUTE_CATEGORY      => r_VPR.INFORMATION110
19815              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
19816              ,P_VRBL_RT_PRFL_RL_ID      => l_vrbl_rt_prfl_rl_id
19817              --
19818              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
19819              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
19820              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
19821            );
19822            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
19823            -- Update all relevent cer records with new pk_id
19824            hr_utility.set_location('Before plsql table ',222);
19825            hr_utility.set_location('new_value id '||l_vrbl_rt_prfl_rl_id,222);
19826            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'VRBL_RT_PRFL_RL_ID' ;
19827            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_VPR.information1 ;
19828            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_VRBL_RT_PRFL_RL_ID ;
19829            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
19830            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_VPR_unique.table_route_id;
19831            hr_utility.set_location('After plsql table ',222);
19832            --
19833            -- 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 ) ;
19834            --
19835            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
19836            --
19837          else
19838            --
19839            -- Call Update routine for the pk_id created in prev run .
19840            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
19841            --UPD START
19842            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
19843            --
19844            if l_update then
19845              --
19846              l_datetrack_mode := r_VPR.datetrack_mode ;
19847              --
19848              get_dt_modes(
19849                p_effective_date        => l_process_date,
19850                p_effective_end_date    => r_VPR.information3,
19851                p_effective_start_date  => r_VPR.information2,
19852                p_dml_operation         => r_VPR.dml_operation,
19853                p_datetrack_mode        => l_datetrack_mode );
19854            --    p_update                => l_update
19855              --
19856              l_effective_date := l_process_date;
19857              l_VRBL_RT_PRFL_RL_ID   := r_VPR.information1;
19858              l_object_version_number := r_VPR.information265;
19859              --
19860            end if;
19861            --
19862            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
19863            --
19864            IF l_update OR l_dml_operation <> 'UPDATE' THEN
19865            --UPD END
19866            hr_utility.set_location(' BEN_VRBL_RT_PRFL_RL_F UPDATE_VRBL_RT_PRFL_RULE ',30);
19867            BEN_VRBL_RT_PRFL_RULE_API.UPDATE_VRBL_RT_PRFL_RULE(
19868              --
19869              P_VALIDATE               => false
19870              ,P_EFFECTIVE_DATE        => l_effective_date
19871              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
19872              --
19873              ,P_DRVBL_FCTR_APLS_FLAG      => r_VPR.INFORMATION11
19874              ,P_FORMULA_ID      => l_FORMULA_ID
19875              ,P_ORDR_TO_APLY_NUM      => r_VPR.INFORMATION260
19876              ,P_VPR_ATTRIBUTE1      => r_VPR.INFORMATION111
19877              ,P_VPR_ATTRIBUTE10      => r_VPR.INFORMATION120
19878              ,P_VPR_ATTRIBUTE11      => r_VPR.INFORMATION121
19879              ,P_VPR_ATTRIBUTE12      => r_VPR.INFORMATION122
19880              ,P_VPR_ATTRIBUTE13      => r_VPR.INFORMATION123
19881              ,P_VPR_ATTRIBUTE14      => r_VPR.INFORMATION124
19882              ,P_VPR_ATTRIBUTE15      => r_VPR.INFORMATION125
19883              ,P_VPR_ATTRIBUTE16      => r_VPR.INFORMATION126
19884              ,P_VPR_ATTRIBUTE17      => r_VPR.INFORMATION127
19885              ,P_VPR_ATTRIBUTE18      => r_VPR.INFORMATION128
19886              ,P_VPR_ATTRIBUTE19      => r_VPR.INFORMATION129
19887              ,P_VPR_ATTRIBUTE2      => r_VPR.INFORMATION112
19888              ,P_VPR_ATTRIBUTE20      => r_VPR.INFORMATION130
19889              ,P_VPR_ATTRIBUTE21      => r_VPR.INFORMATION131
19890              ,P_VPR_ATTRIBUTE22      => r_VPR.INFORMATION132
19891              ,P_VPR_ATTRIBUTE23      => r_VPR.INFORMATION133
19892              ,P_VPR_ATTRIBUTE24      => r_VPR.INFORMATION134
19893              ,P_VPR_ATTRIBUTE25      => r_VPR.INFORMATION135
19894              ,P_VPR_ATTRIBUTE26      => r_VPR.INFORMATION136
19895              ,P_VPR_ATTRIBUTE27      => r_VPR.INFORMATION137
19896              ,P_VPR_ATTRIBUTE28      => r_VPR.INFORMATION138
19897              ,P_VPR_ATTRIBUTE29      => r_VPR.INFORMATION139
19898              ,P_VPR_ATTRIBUTE3      => r_VPR.INFORMATION113
19899              ,P_VPR_ATTRIBUTE30      => r_VPR.INFORMATION140
19900              ,P_VPR_ATTRIBUTE4      => r_VPR.INFORMATION114
19901              ,P_VPR_ATTRIBUTE5      => r_VPR.INFORMATION115
19902              ,P_VPR_ATTRIBUTE6      => r_VPR.INFORMATION116
19903              ,P_VPR_ATTRIBUTE7      => r_VPR.INFORMATION117
19904              ,P_VPR_ATTRIBUTE8      => r_VPR.INFORMATION118
19905              ,P_VPR_ATTRIBUTE9      => r_VPR.INFORMATION119
19906              ,P_VPR_ATTRIBUTE_CATEGORY      => r_VPR.INFORMATION110
19907              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
19908              ,P_VRBL_RT_PRFL_RL_ID      => l_vrbl_rt_prfl_rl_id
19909              --
19910              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
19911              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
19912              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
19913              ,P_DATETRACK_MODE        => l_datetrack_mode
19914            );
19915            --
19916            end if;
19917          end if;
19918          --
19919          -- Delete the row if it is end dated.
19920          --
19921          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
19922              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
19923              trunc(l_max_eed) = r_VPR.information3) then
19924              --
19925              BEN_VRBL_RT_PRFL_RULE_API.delete_VRBL_RT_PRFL_RULE(
19926                 --
19927                 p_validate                       => false
19928                 ,p_vrbl_rt_prfl_rl_id                   => l_vrbl_rt_prfl_rl_id
19929                 ,p_effective_start_date           => l_effective_start_date
19930                 ,p_effective_end_date             => l_effective_end_date
19931                 ,p_object_version_number          => l_object_version_number
19932                 ,p_effective_date                 => l_max_eed
19933                 ,p_datetrack_mode                 => hr_api.g_delete
19934                 --
19935                 );
19936                 --
19937          end if;
19938          --
19939          l_prev_pk_id := l_current_pk_id ;
19940          --
19941        end if;
19942        --
19943      end if;
19944      --
19945    end loop;
19946    --
19947  exception when others then
19948     --
19949     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'VPR',r_vpr.information5 );
19950     --
19951  end create_VPR_rows;
19952 
19953    --
19954    ---------------------------------------------------------------
19955    ----------------------< create_PRT_rows >-----------------------
19956    ---------------------------------------------------------------
19957    --
19958    procedure create_PRT_rows
19959    (
19960          p_validate                       in  number     default 0
19961         ,p_copy_entity_txn_id             in  number
19962         ,p_effective_date                 in  date
19963         ,p_prefix_suffix_text             in  varchar2  default null
19964         ,p_reuse_object_flag              in  varchar2  default null
19965         ,p_target_business_group_id       in  varchar2  default null
19966         ,p_prefix_suffix_cd               in  varchar2  default null
19967    ) is
19968    --
19969    l_RNDG_RL  number;
19970    l_VRBL_RT_PRFL_ID  number;
19971    l_MN_POE_NUM      number;
19972    l_MX_POE_NUM      number;
19973    l_NO_MN_POE_FLAG      varchar2(100);
19974    l_NO_MX_POE_FLAG      varchar2(100);
19975    l_POE_NNMNTRY_UOM      varchar2(100);
19976    l_RNDG_CD      varchar2(100);
19977    cursor c_unique_PRT(l_table_alias varchar2) is
19978    select distinct cpe.information1,
19979      cpe.information2,
19980      cpe.information3,
19981      cpe.table_route_id
19982    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
19983         pqh_table_route tr
19984    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
19985    and   cpe.table_route_id     = tr.table_route_id
19986    -- and   tr.where_clause        = l_BEN_POE_RT_F
19987    and tr.table_alias = l_table_alias
19988    and   cpe.number_of_copies   = 1 -- ADDITION
19989    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
19990    order by information1, information2; --added for bug: 5151945
19991    --
19992    --
19993    cursor c_PRT_min_max_dates(c_table_route_id  number,
19994                 c_information1   Number) is
19995    select
19996      min(cpe.information2) min_esd,
19997      max(cpe.information3) min_eed
19998    from ben_copy_entity_results cpe
19999    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
20000    and   cpe.table_route_id     = c_table_route_id
20001    and   cpe.information1       = c_information1 ;
20002    --
20003    cursor c_PRT(c_table_route_id  number,
20004                 c_information1   number,
20005                 c_information2   Date,
20006                 c_information3   Date)  is
20007    select
20008      cpe.*
20009    from ben_copy_entity_results cpe
20010    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
20011    and   cpe.table_route_id     = c_table_route_id
20012    and   cpe.information1       = c_information1
20013    and   cpe.information2       = c_information2
20014    and   cpe.information3       = c_information3
20015    and rownum = 1 ;
20016    -- Date Track target record
20017    cursor c_find_PRT_in_target(
20018                                 c_effective_start_date    date,
20019                                 c_effective_end_date      date,
20020                                 c_business_group_id       number,
20021                                 c_new_pk_id               number) is
20022    select
20023      PRT.poe_rt_id new_value
20024    from BEN_POE_RT_F PRT
20025    where
20026    PRT.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
20027    nvl(PRT.RNDG_CD, 'YYYY')          = nvl(l_RNDG_CD, 'YYYY')          and
20028    nvl(PRT.RNDG_RL, -9999)          = nvl(l_RNDG_RL, -9999)          and
20029    nvl(PRT.POE_NNMNTRY_UOM, 'YYYY')  = nvl(l_POE_NNMNTRY_UOM, 'YYYY')  and
20030    nvl(PRT.NO_MX_POE_FLAG, 'YYYY')   = nvl(l_NO_MX_POE_FLAG, 'YYYY')   and
20031    nvl(PRT.NO_MN_POE_FLAG, 'YYYY')   = nvl(l_NO_MN_POE_FLAG, 'YYYY')   and
20032    nvl(PRT.MX_POE_NUM, -9999)       = nvl(l_MX_POE_NUM, -9999)       and
20033    nvl(PRT.MN_POE_NUM, -9999)       = nvl(l_MN_POE_NUM, -9999)       and
20034    PRT.business_group_id  = c_business_group_id
20035    and   PRT.poe_rt_id  <> c_new_pk_id
20036 --TEMPIK
20037    and c_effective_start_date between effective_start_date
20038                             and effective_end_date ;
20039 --END TEMPIK
20040 /*TEMPIK
20041    and exists ( select null
20042                 from BEN_POE_RT_F PRT1
20043                 where
20044                 PRT1.VRBL_RT_PRFL_ID  = l_VRBL_RT_PRFL_ID  and
20045                 nvl(PRT1.RNDG_CD, 'YYYY')          = nvl(l_RNDG_CD, 'YYYY')          and
20046                 nvl(PRT1.RNDG_RL, -9999)          = nvl(l_RNDG_RL, -9999)          and
20047                 nvl(PRT1.POE_NNMNTRY_UOM, 'YYYY')  = nvl(l_POE_NNMNTRY_UOM, 'YYYY')  and
20048                 nvl(PRT1.NO_MX_POE_FLAG, 'YYYY')   = nvl(l_NO_MX_POE_FLAG, 'YYYY')   and
20049                 nvl(PRT1.NO_MN_POE_FLAG, 'YYYY')   = nvl(l_NO_MN_POE_FLAG, 'YYYY')   and
20050                 nvl(PRT1.MX_POE_NUM, -9999)       = nvl(l_MX_POE_NUM, -9999)       and
20051                 nvl(PRT1.MN_POE_NUM, -9999)       = nvl(l_MN_POE_NUM, -9999)       and
20052                 PRT1.business_group_id  = c_business_group_id
20053                 and   PRT1.effective_start_date <= c_effective_start_date )
20054    and exists ( select null
20055                 from BEN_POE_RT_F PRT2
20056                 where
20057                 PRT2.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID  and
20058                 nvl(PRT2.RNDG_CD, 'YYYY')          = nvl(l_RNDG_CD, 'YYYY')          and
20059                 nvl(PRT2.RNDG_RL, -9999)          = nvl(l_RNDG_RL, -9999)          and
20060                 nvl(PRT2.POE_NNMNTRY_UOM, 'YYYY')  = nvl(l_POE_NNMNTRY_UOM, 'YYYY')  and
20061                 nvl(PRT2.NO_MX_POE_FLAG, 'YYYY')   = nvl(l_NO_MX_POE_FLAG, 'YYYY')   and
20062                 nvl(PRT2.NO_MN_POE_FLAG, 'YYYY')   = nvl(l_NO_MN_POE_FLAG, 'YYYY')   and
20063                 nvl(PRT2.MX_POE_NUM, -9999)       = nvl(l_MX_POE_NUM, -9999)       and
20064                 nvl(PRT2.MN_POE_NUM, -9999)       = nvl(l_MN_POE_NUM, -9999)       and
20065                 PRT2.business_group_id  = c_business_group_id
20066                 and   PRT2.effective_end_date >= c_effective_end_date )
20067                 ;
20068 TEMPIK */
20069    --TEMPIK
20070    l_dt_rec_found            boolean ;
20071    --END TEMPIK
20072    --
20073    l_current_pk_id           number := null ;
20074    --UPD START
20075    --
20076    l_update                  boolean      := false ;
20077    l_datetrack_mode          varchar2(80) := hr_api.g_update;
20078    l_process_date            date;
20079    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
20080    --
20081    --UPD END
20082    l_prev_pk_id              number := null ;
20083    l_first_rec               boolean := true ;
20084    r_PRT                     c_PRT%rowtype;
20085    l_poe_rt_id             number ;
20086    l_object_version_number   number ;
20087    l_effective_start_date    date ;
20088    l_effective_end_date      date ;
20089    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
20090    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
20091    l_new_value               number(15);
20092    l_object_found_in_target  boolean := false ;
20093    l_min_esd                 date;
20094    l_max_eed                 date;
20095    l_effective_date          date;
20096    --
20097  begin
20098    -- Initialization
20099    l_object_found_in_target := false ;
20100    -- End Initialization
20101    -- Derive the prefix - sufix
20102    if   p_prefix_suffix_cd = 'PREFIX' then
20103      l_prefix  := p_prefix_suffix_text ;
20104    elsif p_prefix_suffix_cd = 'SUFFIX' then
20105      l_suffix   := p_prefix_suffix_text ;
20106    else
20107      l_prefix := null ;
20108      l_suffix  := null ;
20109    end if ;
20110    -- End Prefix Sufix derivation
20111    for r_PRT_unique in c_unique_PRT('PRT') loop
20112 
20113      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
20114         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
20115          r_PRT_unique.information3 >=
20116                  ben_pd_copy_to_ben_one.g_copy_effective_date)
20117         ) then
20118        --
20119        hr_utility.set_location(' r_PRT_unique.table_route_id '||r_PRT_unique.table_route_id,10);
20120        hr_utility.set_location(' r_PRT_unique.information1 '||r_PRT_unique.information1,10);
20121        hr_utility.set_location( 'r_PRT_unique.information2 '||r_PRT_unique.information2,10);
20122        hr_utility.set_location( 'r_PRT_unique.information3 '||r_PRT_unique.information3,10);
20123        -- If reuse objects flag is 'Y' then check for the object in the target business group
20124        -- if found insert the record into PLSql table and exit the loop else try create the
20125        -- object in the target business group
20126        --
20127        l_object_found_in_target := false ;
20128        l_min_esd := null ;
20129        l_max_eed := null ;
20130        open c_PRT_min_max_dates(r_PRT_unique.table_route_id, r_PRT_unique.information1 ) ;
20131        fetch c_PRT_min_max_dates into l_min_esd,l_max_eed ;
20132        --
20133 
20134        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
20135             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
20136          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
20137        end if;
20138        l_min_esd := greatest(l_min_esd,r_PRT_unique.information2);
20139        open c_PRT(r_PRT_unique.table_route_id,
20140                 r_PRT_unique.information1,
20141                 r_PRT_unique.information2,
20142                 r_PRT_unique.information3 ) ;
20143        --
20144        fetch c_PRT into r_PRT ;
20145        --
20146        close c_PRT ;
20147        --
20148        l_RNDG_RL := get_fk('FORMULA_ID', r_PRT.information263,r_PRT_unique.dml_operation);
20149        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_PRT.information262,r_PRT_unique.dml_operation);
20150        l_MN_POE_NUM      := r_PRT.information260;
20151        l_MX_POE_NUM      := r_PRT.information261;
20152        l_NO_MN_POE_FLAG      := r_PRT.information13;
20153        l_NO_MX_POE_FLAG      := r_PRT.information14;
20154        l_POE_NNMNTRY_UOM      := r_PRT.information12;
20155        l_RNDG_CD      := r_PRT.information11;
20156        --UPD START
20157        l_update := false;
20158        l_process_date := p_effective_date;
20159        l_dml_operation:= r_PRT_unique.dml_operation ;
20160        --
20161        if l_dml_operation = 'UPDATE' then
20162          --
20163          l_object_found_in_target := TRUE;
20164          --
20165          if l_process_date between r_PRT_unique.information2 and r_PRT_unique.information3 then
20166                l_update := true;
20167                if r_PRT_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
20168                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'POE_RT_ID'
20169                then
20170                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'POE_RT_ID' ;
20171                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_PRT_unique.information1 ;
20172                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_PRT_unique.information1 ;
20173                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
20174                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_PRT_unique.table_route_id;
20175                   --
20176                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
20177                   --
20178                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
20179                   --
20180                   -- log_data('PRT',l_new_value,l_prefix || r_PRT_unique.name|| l_suffix,'REUSED');
20181                   --
20182                end if ;
20183                hr_utility.set_location( 'found record for update',10);
20184            --
20185          else
20186            --
20187            l_update := false;
20188            --
20189          end if;
20190        else
20191          --
20192          --UPD END
20193        if p_reuse_object_flag = 'Y' then
20194          if c_PRT_min_max_dates%found then
20195            -- cursor to find the object
20196            open c_find_PRT_in_target( l_min_esd,l_max_eed,
20197                                  p_target_business_group_id, nvl(l_poe_rt_id, -999)  ) ;
20198            fetch c_find_PRT_in_target into l_new_value ;
20199            if c_find_PRT_in_target%found then
20200              --
20201              --TEMPIK
20202              l_dt_rec_found :=   dt_api.check_min_max_dates
20203                  (p_base_table_name => 'BEN_POE_RT_F',
20204                   p_base_key_column => 'POE_RT_ID',
20205                   p_base_key_value  => l_new_value,
20206                   p_from_date       => l_min_esd,
20207                   p_to_date         => l_max_eed );
20208              if l_dt_rec_found THEN
20209              --END TEMPIK
20210              if r_PRT_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
20211                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'POE_RT_ID'  then
20212                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'POE_RT_ID' ;
20213                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_PRT_unique.information1 ;
20214                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
20215                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
20216                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PRT_unique.table_route_id;
20217                 --
20218                 -- 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) ;
20219                 --
20220                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
20221              end if ;
20222              --
20223              l_object_found_in_target := true ;
20224              --TEMPIK
20225              end if; -- l_dt_rec_found
20226              --END TEMPIK
20227            end if;
20228            close c_find_PRT_in_target ;
20229          --
20230          end if;
20231        end if ;
20232        --
20233        end if;
20234        close c_PRT_min_max_dates ;
20235        if not l_object_found_in_target OR l_update   then
20236          --
20237          l_current_pk_id := r_PRT.information1;
20238          --
20239          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
20240          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
20241          --
20242          if l_current_pk_id =  l_prev_pk_id  then
20243            --
20244            l_first_rec := false ;
20245            --
20246          else
20247            --
20248            l_first_rec := true ;
20249            --
20250          end if ;
20251          --
20252 
20253          l_effective_date := r_PRT.information2;
20254          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
20255               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
20256            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
20257          end if;
20258 
20259          if l_first_rec and not l_update then
20260            -- Call Create routine.
20261            hr_utility.set_location(' BEN_POE_RT_F CREATE_POE_RT ',20);
20262            BEN_POE_RT_API.CREATE_POE_RT(
20263              --
20264              P_VALIDATE               => false
20265              ,P_EFFECTIVE_DATE        => l_effective_date
20266              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
20267              --
20268              ,P_CBR_DSBLTY_APLS_FLAG      => r_PRT.INFORMATION15
20269              ,P_MN_POE_NUM      => r_PRT.INFORMATION260
20270              ,P_MX_POE_NUM      => r_PRT.INFORMATION261
20271              ,P_NO_MN_POE_FLAG      => r_PRT.INFORMATION13
20272              ,P_NO_MX_POE_FLAG      => r_PRT.INFORMATION14
20273              ,P_POE_NNMNTRY_UOM      => r_PRT.INFORMATION12
20274              ,P_POE_RT_ID      => l_poe_rt_id
20275              ,P_PRT_ATTRIBUTE1      => r_PRT.INFORMATION111
20276              ,P_PRT_ATTRIBUTE10      => r_PRT.INFORMATION120
20277              ,P_PRT_ATTRIBUTE11      => r_PRT.INFORMATION121
20278              ,P_PRT_ATTRIBUTE12      => r_PRT.INFORMATION122
20279              ,P_PRT_ATTRIBUTE13      => r_PRT.INFORMATION123
20280              ,P_PRT_ATTRIBUTE14      => r_PRT.INFORMATION124
20281              ,P_PRT_ATTRIBUTE15      => r_PRT.INFORMATION125
20282              ,P_PRT_ATTRIBUTE16      => r_PRT.INFORMATION126
20283              ,P_PRT_ATTRIBUTE17      => r_PRT.INFORMATION127
20284              ,P_PRT_ATTRIBUTE18      => r_PRT.INFORMATION128
20285              ,P_PRT_ATTRIBUTE19      => r_PRT.INFORMATION129
20286              ,P_PRT_ATTRIBUTE2      => r_PRT.INFORMATION112
20287              ,P_PRT_ATTRIBUTE20      => r_PRT.INFORMATION130
20288              ,P_PRT_ATTRIBUTE21      => r_PRT.INFORMATION131
20289              ,P_PRT_ATTRIBUTE22      => r_PRT.INFORMATION132
20290              ,P_PRT_ATTRIBUTE23      => r_PRT.INFORMATION133
20291              ,P_PRT_ATTRIBUTE24      => r_PRT.INFORMATION134
20292              ,P_PRT_ATTRIBUTE25      => r_PRT.INFORMATION135
20293              ,P_PRT_ATTRIBUTE26      => r_PRT.INFORMATION136
20294              ,P_PRT_ATTRIBUTE27      => r_PRT.INFORMATION137
20295              ,P_PRT_ATTRIBUTE28      => r_PRT.INFORMATION138
20296              ,P_PRT_ATTRIBUTE29      => r_PRT.INFORMATION139
20297              ,P_PRT_ATTRIBUTE3      => r_PRT.INFORMATION113
20298              ,P_PRT_ATTRIBUTE30      => r_PRT.INFORMATION140
20299              ,P_PRT_ATTRIBUTE4      => r_PRT.INFORMATION114
20300              ,P_PRT_ATTRIBUTE5      => r_PRT.INFORMATION115
20301              ,P_PRT_ATTRIBUTE6      => r_PRT.INFORMATION116
20302              ,P_PRT_ATTRIBUTE7      => r_PRT.INFORMATION117
20303              ,P_PRT_ATTRIBUTE8      => r_PRT.INFORMATION118
20304              ,P_PRT_ATTRIBUTE9      => r_PRT.INFORMATION119
20305              ,P_PRT_ATTRIBUTE_CATEGORY      => r_PRT.INFORMATION110
20306              ,P_RNDG_CD      => r_PRT.INFORMATION11
20307              ,P_RNDG_RL      => l_RNDG_RL
20308              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
20309              --
20310              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
20311              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
20312              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
20313            );
20314            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
20315            -- Update all relevent cer records with new pk_id
20316            hr_utility.set_location('Before plsql table ',222);
20317            hr_utility.set_location('new_value id '||l_poe_rt_id,222);
20318            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'POE_RT_ID' ;
20319            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_PRT.information1 ;
20320            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_POE_RT_ID ;
20321            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
20322            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PRT_unique.table_route_id;
20323            hr_utility.set_location('After plsql table ',222);
20324            --
20325            -- 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 ) ;
20326            --
20327            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
20328            --
20329          else
20330            --
20331            -- Call Update routine for the pk_id created in prev run .
20332            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
20333            --UPD START
20334            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
20335            --
20336            if l_update then
20337              --
20338              l_datetrack_mode := r_PRT.datetrack_mode ;
20339              --
20340              get_dt_modes(
20341                p_effective_date        => l_process_date,
20342                p_effective_end_date    => r_PRT.information3,
20343                p_effective_start_date  => r_PRT.information2,
20344                p_dml_operation         => r_PRT.dml_operation,
20345                p_datetrack_mode        => l_datetrack_mode );
20346            --    p_update                => l_update
20347              --
20348              l_effective_date := l_process_date;
20349              l_POE_RT_ID   := r_PRT.information1;
20350              l_object_version_number := r_PRT.information265;
20351              --
20352            end if;
20353            --
20354            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
20355            --
20356            IF l_update OR l_dml_operation <> 'UPDATE' THEN
20357            --UPD END
20358            hr_utility.set_location(' BEN_POE_RT_F UPDATE_POE_RT ',30);
20359            BEN_POE_RT_API.UPDATE_POE_RT(
20360              --
20361              P_VALIDATE               => false
20362              ,P_EFFECTIVE_DATE        => l_effective_date
20363              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
20364              --
20365             ,P_CBR_DSBLTY_APLS_FLAG      => r_PRT.INFORMATION15
20366              ,P_MN_POE_NUM      => r_PRT.INFORMATION260
20367              ,P_MX_POE_NUM      => r_PRT.INFORMATION261
20368              ,P_NO_MN_POE_FLAG      => r_PRT.INFORMATION13
20369              ,P_NO_MX_POE_FLAG      => r_PRT.INFORMATION14
20370              ,P_POE_NNMNTRY_UOM      => r_PRT.INFORMATION12
20371              ,P_POE_RT_ID      => l_poe_rt_id
20372              ,P_PRT_ATTRIBUTE1      => r_PRT.INFORMATION111
20373              ,P_PRT_ATTRIBUTE10      => r_PRT.INFORMATION120
20374              ,P_PRT_ATTRIBUTE11      => r_PRT.INFORMATION121
20375              ,P_PRT_ATTRIBUTE12      => r_PRT.INFORMATION122
20376              ,P_PRT_ATTRIBUTE13      => r_PRT.INFORMATION123
20377              ,P_PRT_ATTRIBUTE14      => r_PRT.INFORMATION124
20378              ,P_PRT_ATTRIBUTE15      => r_PRT.INFORMATION125
20379              ,P_PRT_ATTRIBUTE16      => r_PRT.INFORMATION126
20380              ,P_PRT_ATTRIBUTE17      => r_PRT.INFORMATION127
20381              ,P_PRT_ATTRIBUTE18      => r_PRT.INFORMATION128
20382              ,P_PRT_ATTRIBUTE19      => r_PRT.INFORMATION129
20383              ,P_PRT_ATTRIBUTE2      => r_PRT.INFORMATION112
20384              ,P_PRT_ATTRIBUTE20      => r_PRT.INFORMATION130
20385              ,P_PRT_ATTRIBUTE21      => r_PRT.INFORMATION131
20386              ,P_PRT_ATTRIBUTE22      => r_PRT.INFORMATION132
20387              ,P_PRT_ATTRIBUTE23      => r_PRT.INFORMATION133
20388              ,P_PRT_ATTRIBUTE24      => r_PRT.INFORMATION134
20389              ,P_PRT_ATTRIBUTE25      => r_PRT.INFORMATION135
20390              ,P_PRT_ATTRIBUTE26      => r_PRT.INFORMATION136
20391              ,P_PRT_ATTRIBUTE27      => r_PRT.INFORMATION137
20392              ,P_PRT_ATTRIBUTE28      => r_PRT.INFORMATION138
20393              ,P_PRT_ATTRIBUTE29      => r_PRT.INFORMATION139
20394              ,P_PRT_ATTRIBUTE3      => r_PRT.INFORMATION113
20395              ,P_PRT_ATTRIBUTE30      => r_PRT.INFORMATION140
20396              ,P_PRT_ATTRIBUTE4      => r_PRT.INFORMATION114
20397              ,P_PRT_ATTRIBUTE5      => r_PRT.INFORMATION115
20398              ,P_PRT_ATTRIBUTE6      => r_PRT.INFORMATION116
20399              ,P_PRT_ATTRIBUTE7      => r_PRT.INFORMATION117
20400              ,P_PRT_ATTRIBUTE8      => r_PRT.INFORMATION118
20401              ,P_PRT_ATTRIBUTE9      => r_PRT.INFORMATION119
20402              ,P_PRT_ATTRIBUTE_CATEGORY      => r_PRT.INFORMATION110
20403              ,P_RNDG_CD      => r_PRT.INFORMATION11
20404              ,P_RNDG_RL      => l_RNDG_RL
20405              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
20406              --
20407              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
20408              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
20409              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
20410              ,P_DATETRACK_MODE        => l_datetrack_mode
20411            );
20412            --
20413            end if;
20414          end if;
20415          --
20416          -- Delete the row if it is end dated.
20417          --
20418          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
20419              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
20420              trunc(l_max_eed) = r_PRT.information3) then
20421              --
20422              BEN_POE_RT_API.delete_POE_RT(
20423                 --
20424                 p_validate                       => false
20425                 ,p_poe_rt_id                   => l_poe_rt_id
20426                 ,p_effective_start_date           => l_effective_start_date
20427                 ,p_effective_end_date             => l_effective_end_date
20428                 ,p_object_version_number          => l_object_version_number
20429                 ,p_effective_date                 => l_max_eed
20430                 ,p_datetrack_mode                 => hr_api.g_delete
20431                 --
20432                 );
20433                 --
20434          end if;
20435          --
20436          l_prev_pk_id := l_current_pk_id ;
20437          --
20438        end if;
20439        --
20440      end if;
20441      --
20442    end loop;
20443    --
20444  exception when others then
20445     --
20446     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'PRT',r_prt.information5 );
20447     --
20448  end create_PRT_rows;
20449 
20450    ---------------------------------------------------------------
20451    ----------------------< create_CPN_rows >-----------------------
20452    ---------------------------------------------------------------
20453    --
20454    procedure create_CPN_rows
20455    (
20456          p_validate                       in  number     default 0
20457         ,p_copy_entity_txn_id             in  number
20458         ,p_effective_date                 in  date
20459         ,p_prefix_suffix_text             in  varchar2  default null
20460         ,p_reuse_object_flag              in  varchar2  default null
20461         ,p_target_business_group_id       in  varchar2  default null
20462         ,p_prefix_suffix_cd               in  varchar2  default null
20463    ) is
20464    --
20465    l_PYMT_MUST_BE_RCVD_RL  number;
20466    l_VRBL_RT_PRFL_ID  number;
20467    l_PYMT_MUST_BE_RCVD_NUM  number;
20468    l_PYMT_MUST_BE_RCVD_UOM  varchar2(30);
20469    --
20470    cursor c_unique_CPN(l_table_alias varchar2) is
20471    select distinct cpe.information1,
20472      cpe.information2,
20473      cpe.information3,
20474      cpe.information170 name,
20475      cpe.table_route_id
20476    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
20477         pqh_table_route tr
20478    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
20479    and   cpe.table_route_id     = tr.table_route_id
20480    -- and   tr.where_clause        = l_BEN_CNTNG_PRTN_PRFL_RT_F
20481    and tr.table_alias = l_table_alias
20482    and   cpe.number_of_copies   = 1 -- ADDITION
20483    group by cpe.information1,cpe.information2,cpe.information3, cpe.information170, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
20484    order by information1, information2; --added for bug: 5151945
20485    --
20486    --
20487    cursor c_CPN_min_max_dates(c_table_route_id  number,
20488                 c_information1   Number) is
20489    select
20490      min(cpe.information2) min_esd,
20491      max(cpe.information3) min_eed
20492    from ben_copy_entity_results cpe
20493    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
20494    and   cpe.table_route_id     = c_table_route_id
20495    and   cpe.information1       = c_information1 ;
20496    --
20497    cursor c_CPN(c_table_route_id  number,
20498                 c_information1    number,
20499                 c_information2    Date,
20500                 c_information3    Date)  is
20501    select
20502      cpe.*
20503    from ben_copy_entity_results cpe
20504    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
20505    and   cpe.table_route_id     = c_table_route_id
20506    and   cpe.information1       = c_information1
20507    and   cpe.information2       = c_information2
20508    and   cpe.information3       = c_information3
20509    and rownum = 1 ;
20510    -- Date Track target record
20511    cursor c_find_CPN_in_target(
20512                                 c_effective_start_date    date,
20513                                 c_effective_end_date      date,
20514                                 c_business_group_id       number,
20515                                 c_new_pk_id               number) is
20516    select
20517      CPN.cntng_prtn_prfl_rt_id new_value
20518    from BEN_CNTNG_PRTN_PRFL_RT_F CPN
20519    where
20520    CPN.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
20521    CPN.PYMT_MUST_BE_RCVD_NUM = l_PYMT_MUST_BE_RCVD_NUM and
20522    CPN.business_group_id  = c_business_group_id
20523    and   CPN.cntng_prtn_prfl_rt_id  <> c_new_pk_id
20524 --TEMPIK
20525    and c_effective_start_date between effective_start_date
20526                             and effective_end_date ;
20527 --END TEMPIK
20528 /*TEMPIK
20529    and exists ( select null
20530                 from BEN_CNTNG_PRTN_PRFL_RT_F CPN1
20531                 where
20532                 CPN1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
20533                 CPN1.PYMT_MUST_BE_RCVD_NUM = l_PYMT_MUST_BE_RCVD_NUM and
20534                 CPN1.business_group_id  = c_business_group_id
20535                 and   CPN1.effective_start_date <= c_effective_start_date )
20536    and exists ( select null
20537                 from BEN_CNTNG_PRTN_PRFL_RT_F CPN2
20538                 where
20539                 CPN2.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID  and
20540                 CPN2.PYMT_MUST_BE_RCVD_NUM = l_PYMT_MUST_BE_RCVD_NUM and
20541                 CPN2.business_group_id  = c_business_group_id
20542                 and   CPN2.effective_end_date >= c_effective_end_date )
20543                 ;
20544 TEMPIK */
20545    --TEMPIK
20546    l_dt_rec_found            boolean ;
20547    --END TEMPIK
20548    --
20549    l_current_pk_id           number := null ;
20550    --UPD START
20551    --
20552    l_update                  boolean      := false ;
20553    l_datetrack_mode          varchar2(80) := hr_api.g_update;
20554    l_process_date            date;
20555    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
20556    --
20557    --UPD END
20558    l_prev_pk_id              number := null ;
20559    l_first_rec               boolean := true ;
20560    r_CPN                     c_CPN%rowtype;
20561    l_cntng_prtn_prfl_rt_id             number ;
20562    l_object_version_number   number ;
20563    l_effective_start_date    date ;
20564    l_effective_end_date      date ;
20565    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
20566    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
20567    l_new_value               number(15);
20568    l_object_found_in_target  boolean := false ;
20569    l_min_esd                 date;
20570    l_max_eed                 date;
20571    l_effective_date          date;
20572    --
20573  begin
20574    -- Initialization
20575    l_object_found_in_target := false ;
20576    -- End Initialization
20577    -- Derive the prefix - sufix
20578    if   p_prefix_suffix_cd = 'PREFIX' then
20579      l_prefix  := p_prefix_suffix_text ;
20580    elsif p_prefix_suffix_cd = 'SUFFIX' then
20581      l_suffix   := p_prefix_suffix_text ;
20582    else
20583      l_prefix := null ;
20584      l_suffix  := null ;
20585    end if ;
20586    -- End Prefix Sufix derivation
20587    for r_CPN_unique in c_unique_CPN('CPN') loop
20588 
20589      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
20590         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
20591          r_CPN_unique.information3 >=
20592                  ben_pd_copy_to_ben_one.g_copy_effective_date)
20593         ) then
20594        --
20595        hr_utility.set_location(' r_CPN_unique.table_route_id '||r_CPN_unique.table_route_id,10);
20596        hr_utility.set_location(' r_CPN_unique.information1 '||r_CPN_unique.information1,10);
20597        hr_utility.set_location( 'r_CPN_unique.information2 '||r_CPN_unique.information2,10);
20598        hr_utility.set_location( 'r_CPN_unique.information3 '||r_CPN_unique.information3,10);
20599        -- If reuse objects flag is 'Y' then check for the object in the target business group
20600        -- if found insert the record into PLSql table and exit the loop else try create the
20601        -- object in the target business group
20602        --
20603        l_object_found_in_target := false ;
20604        l_min_esd := null ;
20605        l_max_eed := null ;
20606        open c_CPN_min_max_dates(r_CPN_unique.table_route_id, r_CPN_unique.information1 ) ;
20607        fetch c_CPN_min_max_dates into l_min_esd,l_max_eed ;
20608        --
20609 
20610        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
20611             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
20612          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
20613        end if;
20614        l_min_esd := greatest(l_min_esd,r_CPN_unique.information2);
20615        open c_CPN(r_CPN_unique.table_route_id,
20616                 r_CPN_unique.information1,
20617                 r_CPN_unique.information2,
20618                 r_CPN_unique.information3 ) ;
20619        --
20620        fetch c_CPN into r_CPN ;
20621        --
20622        close c_CPN ;
20623        --
20624        l_PYMT_MUST_BE_RCVD_RL := get_fk('FORMULA_ID', r_CPN.information261,r_CPN_unique.dml_operation);
20625        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_CPN.information262,r_CPN_unique.dml_operation);
20626        l_PYMT_MUST_BE_RCVD_NUM := r_CPN.information260;
20627        l_PYMT_MUST_BE_RCVD_UOM := r_CPN.information11;
20628        --UPD START
20629        l_update := false;
20630        l_process_date := p_effective_date;
20631        l_dml_operation:= r_CPN_unique.dml_operation ;
20632        --
20633        if l_dml_operation = 'UPDATE' then
20634          --
20635          l_object_found_in_target := TRUE;
20636          --
20637          if l_process_date between r_CPN_unique.information2 and r_CPN_unique.information3 then
20638                l_update := true;
20639                if r_CPN_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
20640                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'CNTNG_PRTN_PRFL_RT_ID'
20641                then
20642                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'CNTNG_PRTN_PRFL_RT_ID' ;
20643                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_CPN_unique.information1 ;
20644                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_CPN_unique.information1 ;
20645                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
20646                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_CPN_unique.table_route_id;
20647                   --
20648                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
20649                   --
20650                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
20651                   --
20652                   -- log_data('CPN',l_new_value,l_prefix || r_CPN_unique.name|| l_suffix,'REUSED');
20653                   --
20654                end if ;
20655                hr_utility.set_location( 'found record for update',10);
20656            --
20657          else
20658            --
20659            l_update := false;
20660            --
20661          end if;
20662        else
20663          --
20664          --UPD END
20665        if p_reuse_object_flag = 'Y' then
20666          if c_CPN_min_max_dates%found then
20667            -- cursor to find the object
20668            open c_find_CPN_in_target( l_min_esd,l_max_eed,
20669                                  p_target_business_group_id, nvl(l_cntng_prtn_prfl_rt_id, -999)  ) ;
20670            fetch c_find_CPN_in_target into l_new_value ;
20671            if c_find_CPN_in_target%found then
20672              --TEMPIK
20673              l_dt_rec_found :=   dt_api.check_min_max_dates
20674                  (p_base_table_name => 'BEN_CNTNG_PRTN_PRFL_RT_F',
20675                   p_base_key_column => 'CNTNG_PRTN_PRFL_RT_ID',
20676                   p_base_key_value  => l_new_value,
20677                   p_from_date       => l_min_esd,
20678                   p_to_date         => l_max_eed );
20679              if l_dt_rec_found THEN
20680              --END TEMPIK
20681              --
20682              if r_CPN_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
20683                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'CNTNG_PRTN_PRFL_RT_ID'  then
20684                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'CNTNG_PRTN_PRFL_RT_ID' ;
20685                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_CPN_unique.information1 ;
20686                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
20687                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
20688                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_CPN_unique.table_route_id;
20689                 --
20690                 -- 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) ;
20691                 --
20692                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
20693              end if ;
20694              --
20695              l_object_found_in_target := true ;
20696              --TEMPIK
20697              end if; -- l_dt_rec_found
20698              --END TEMPIK
20699            end if;
20700            close c_find_CPN_in_target ;
20701          --
20702          end if;
20703        end if ;
20704        --
20705        end if;
20706        close c_CPN_min_max_dates ;
20707        if not l_object_found_in_target OR l_update   then
20708          --
20709          l_current_pk_id := r_CPN.information1;
20710          --
20711          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
20712          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
20713          --
20714          if l_current_pk_id =  l_prev_pk_id  then
20715            --
20716            l_first_rec := false ;
20717            --
20718          else
20719            --
20720            l_first_rec := true ;
20721            --
20722          end if ;
20723          --
20724          ben_pd_copy_to_ben_one.ben_chk_col_len('NAME' ,'BEN_CNTNG_PRTN_PRFL_RT_F',l_prefix || r_CPN.information170 || l_suffix);
20725          --
20726 
20727          l_effective_date := r_CPN.information2;
20728          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
20729               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
20730            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
20731          end if;
20732 
20733          if l_first_rec and not l_update then
20734            -- Call Create routine.
20735            hr_utility.set_location(' BEN_CNTNG_PRTN_PRFL_RT_F CREATE_CNTNG_PRTN_PRFL_RT ',20);
20736            BEN_CNTNG_PRTN_PRFL_RT_API.CREATE_CNTNG_PRTN_PRFL_RT(
20737              --
20738              P_VALIDATE               => false
20739              ,P_EFFECTIVE_DATE        => l_effective_date
20740              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
20741              --
20742              ,P_CNTNG_PRTN_PRFL_RT_ID      => l_cntng_prtn_prfl_rt_id
20743              ,P_CPN_ATTRIBUTE1      => r_CPN.INFORMATION111
20744              ,P_CPN_ATTRIBUTE10      => r_CPN.INFORMATION120
20745              ,P_CPN_ATTRIBUTE11      => r_CPN.INFORMATION121
20746              ,P_CPN_ATTRIBUTE12      => r_CPN.INFORMATION122
20747              ,P_CPN_ATTRIBUTE13      => r_CPN.INFORMATION123
20748              ,P_CPN_ATTRIBUTE14      => r_CPN.INFORMATION124
20749              ,P_CPN_ATTRIBUTE15      => r_CPN.INFORMATION125
20750              ,P_CPN_ATTRIBUTE16      => r_CPN.INFORMATION126
20751              ,P_CPN_ATTRIBUTE17      => r_CPN.INFORMATION127
20752              ,P_CPN_ATTRIBUTE18      => r_CPN.INFORMATION128
20753              ,P_CPN_ATTRIBUTE19      => r_CPN.INFORMATION129
20754              ,P_CPN_ATTRIBUTE2      => r_CPN.INFORMATION112
20755              ,P_CPN_ATTRIBUTE20      => r_CPN.INFORMATION130
20756              ,P_CPN_ATTRIBUTE21      => r_CPN.INFORMATION131
20757              ,P_CPN_ATTRIBUTE22      => r_CPN.INFORMATION132
20758              ,P_CPN_ATTRIBUTE23      => r_CPN.INFORMATION133
20759              ,P_CPN_ATTRIBUTE24      => r_CPN.INFORMATION134
20760              ,P_CPN_ATTRIBUTE25      => r_CPN.INFORMATION135
20761              ,P_CPN_ATTRIBUTE26      => r_CPN.INFORMATION136
20762              ,P_CPN_ATTRIBUTE27      => r_CPN.INFORMATION137
20763              ,P_CPN_ATTRIBUTE28      => r_CPN.INFORMATION138
20764              ,P_CPN_ATTRIBUTE29      => r_CPN.INFORMATION139
20765              ,P_CPN_ATTRIBUTE3      => r_CPN.INFORMATION113
20766              ,P_CPN_ATTRIBUTE30      => r_CPN.INFORMATION140
20767              ,P_CPN_ATTRIBUTE4      => r_CPN.INFORMATION114
20768              ,P_CPN_ATTRIBUTE5      => r_CPN.INFORMATION115
20769              ,P_CPN_ATTRIBUTE6      => r_CPN.INFORMATION116
20770              ,P_CPN_ATTRIBUTE7      => r_CPN.INFORMATION117
20771              ,P_CPN_ATTRIBUTE8      => r_CPN.INFORMATION118
20772              ,P_CPN_ATTRIBUTE9      => r_CPN.INFORMATION119
20773              ,P_CPN_ATTRIBUTE_CATEGORY      => r_CPN.INFORMATION110
20774              ,P_NAME      => l_prefix || r_CPN.INFORMATION170 || l_suffix
20775              ,P_PYMT_MUST_BE_RCVD_NUM      => r_CPN.INFORMATION260
20776              ,P_PYMT_MUST_BE_RCVD_RL      => l_PYMT_MUST_BE_RCVD_RL
20777              ,P_PYMT_MUST_BE_RCVD_UOM      => r_CPN.INFORMATION11
20778              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
20779              --
20780              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
20781              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
20782              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
20783            );
20784            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
20785            -- Update all relevent cer records with new pk_id
20786            hr_utility.set_location('Before plsql table ',222);
20787            hr_utility.set_location('new_value id '||l_cntng_prtn_prfl_rt_id,222);
20788            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'CNTNG_PRTN_PRFL_RT_ID' ;
20789            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_CPN.information1 ;
20790            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_CNTNG_PRTN_PRFL_RT_ID ;
20791            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
20792            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_CPN_unique.table_route_id;
20793            hr_utility.set_location('After plsql table ',222);
20794            --
20795            -- 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 ) ;
20796            --
20797            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
20798            --
20799          else
20800            --
20801            -- Call Update routine for the pk_id created in prev run .
20802            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
20803            --UPD START
20804            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
20805            --
20806            if l_update then
20807              --
20808              l_datetrack_mode := r_CPN.datetrack_mode ;
20809              --
20810              get_dt_modes(
20811                p_effective_date        => l_process_date,
20812                p_effective_end_date    => r_CPN.information3,
20813                p_effective_start_date  => r_CPN.information2,
20814                p_dml_operation         => r_CPN.dml_operation,
20815                p_datetrack_mode        => l_datetrack_mode );
20816            --    p_update                => l_update
20817              --
20818              l_effective_date := l_process_date;
20819              l_CNTNG_PRTN_PRFL_RT_ID   := r_CPN.information1;
20820              l_object_version_number := r_CPN.information265;
20821              --
20822            end if;
20823            --
20824            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
20825            --
20826            IF l_update OR l_dml_operation <> 'UPDATE' THEN
20827            --UPD END
20828            hr_utility.set_location(' BEN_CNTNG_PRTN_PRFL_RT_F UPDATE_CNTNG_PRTN_PRFL_RT ',30);
20829            BEN_CNTNG_PRTN_PRFL_RT_API.UPDATE_CNTNG_PRTN_PRFL_RT(
20830              --
20831              P_VALIDATE               => false
20832              ,P_EFFECTIVE_DATE        => l_effective_date
20833              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
20834              --
20835               ,P_CNTNG_PRTN_PRFL_RT_ID      => l_cntng_prtn_prfl_rt_id
20836              ,P_CPN_ATTRIBUTE1      => r_CPN.INFORMATION111
20837              ,P_CPN_ATTRIBUTE10      => r_CPN.INFORMATION120
20838              ,P_CPN_ATTRIBUTE11      => r_CPN.INFORMATION121
20839              ,P_CPN_ATTRIBUTE12      => r_CPN.INFORMATION122
20840              ,P_CPN_ATTRIBUTE13      => r_CPN.INFORMATION123
20841              ,P_CPN_ATTRIBUTE14      => r_CPN.INFORMATION124
20842              ,P_CPN_ATTRIBUTE15      => r_CPN.INFORMATION125
20843              ,P_CPN_ATTRIBUTE16      => r_CPN.INFORMATION126
20844              ,P_CPN_ATTRIBUTE17      => r_CPN.INFORMATION127
20845              ,P_CPN_ATTRIBUTE18      => r_CPN.INFORMATION128
20846              ,P_CPN_ATTRIBUTE19      => r_CPN.INFORMATION129
20847              ,P_CPN_ATTRIBUTE2      => r_CPN.INFORMATION112
20848              ,P_CPN_ATTRIBUTE20      => r_CPN.INFORMATION130
20849              ,P_CPN_ATTRIBUTE21      => r_CPN.INFORMATION131
20850              ,P_CPN_ATTRIBUTE22      => r_CPN.INFORMATION132
20851              ,P_CPN_ATTRIBUTE23      => r_CPN.INFORMATION133
20852              ,P_CPN_ATTRIBUTE24      => r_CPN.INFORMATION134
20853              ,P_CPN_ATTRIBUTE25      => r_CPN.INFORMATION135
20854              ,P_CPN_ATTRIBUTE26      => r_CPN.INFORMATION136
20855              ,P_CPN_ATTRIBUTE27      => r_CPN.INFORMATION137
20856              ,P_CPN_ATTRIBUTE28      => r_CPN.INFORMATION138
20857              ,P_CPN_ATTRIBUTE29      => r_CPN.INFORMATION139
20858              ,P_CPN_ATTRIBUTE3      => r_CPN.INFORMATION113
20859              ,P_CPN_ATTRIBUTE30      => r_CPN.INFORMATION140
20860              ,P_CPN_ATTRIBUTE4      => r_CPN.INFORMATION114
20861              ,P_CPN_ATTRIBUTE5      => r_CPN.INFORMATION115
20862              ,P_CPN_ATTRIBUTE6      => r_CPN.INFORMATION116
20863              ,P_CPN_ATTRIBUTE7      => r_CPN.INFORMATION117
20864              ,P_CPN_ATTRIBUTE8      => r_CPN.INFORMATION118
20865              ,P_CPN_ATTRIBUTE9      => r_CPN.INFORMATION119
20866              ,P_CPN_ATTRIBUTE_CATEGORY      => r_CPN.INFORMATION110
20867              ,P_NAME      => l_prefix || r_CPN.INFORMATION170 || l_suffix
20868              ,P_PYMT_MUST_BE_RCVD_NUM      => r_CPN.INFORMATION260
20869              ,P_PYMT_MUST_BE_RCVD_RL      => l_PYMT_MUST_BE_RCVD_RL
20870              ,P_PYMT_MUST_BE_RCVD_UOM      => r_CPN.INFORMATION11
20871              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
20872              --
20873              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
20874              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
20875              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
20876              ,P_DATETRACK_MODE        => l_datetrack_mode
20877            );
20878            --
20879            end if;
20880          end if;
20881          --
20882          -- Delete the row if it is end dated.
20883          --
20884          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
20885              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
20886              trunc(l_max_eed) = r_CPN.information3) then
20887              --
20888              BEN_CNTNG_PRTN_PRFL_RT_API.delete_CNTNG_PRTN_PRFL_RT(
20889                 --
20890                 p_validate                       => false
20891                 ,p_cntng_prtn_prfl_rt_id                   => l_cntng_prtn_prfl_rt_id
20892                 ,p_effective_start_date           => l_effective_start_date
20893                 ,p_effective_end_date             => l_effective_end_date
20894                 ,p_object_version_number          => l_object_version_number
20895                 ,p_effective_date                 => l_max_eed
20896                 ,p_datetrack_mode                 => hr_api.g_delete
20897                 --
20898                 );
20899                 --
20900          end if;
20901          --
20902          l_prev_pk_id := l_current_pk_id ;
20903          --
20904        end if;
20905        --
20906      end if;
20907      --
20908    end loop;
20909    --
20910  exception when others then
20911     --
20912     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'CPN',l_prefix || r_CPN.information170 || l_suffix);
20913     --
20914  end create_CPN_rows;
20915 
20916    --
20917    ---------------------------------------------------------------
20918    ----------------------< create_PST_rows >-----------------------
20919    ---------------------------------------------------------------
20920    --
20921    procedure create_PST_rows
20922    (
20923          p_validate                       in  number     default 0
20924         ,p_copy_entity_txn_id             in  number
20925         ,p_effective_date                 in  date
20926         ,p_prefix_suffix_text             in  varchar2  default null
20927         ,p_reuse_object_flag              in  varchar2  default null
20928         ,p_target_business_group_id       in  varchar2  default null
20929         ,p_prefix_suffix_cd               in  varchar2  default null
20930    ) is
20931    --
20932    l_POSITION_ID  number;
20933    l_VRBL_RT_PRFL_ID  number;
20934    l_EXCLD_FLAG     varchar2(100);
20935    l_ORDR_NUM       varchar2(100);
20936    --
20937    cursor c_unique_PST(l_table_alias varchar2) is
20938    select distinct cpe.information1,
20939      cpe.information2,
20940      cpe.information3,
20941      cpe.table_route_id
20942    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
20943         pqh_table_route tr
20944    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
20945    and   cpe.table_route_id     = tr.table_route_id
20946    -- and   tr.where_clause        = l_BEN_PSTN_RT_F
20947    and tr.table_alias = l_table_alias
20948    and   cpe.number_of_copies   = 1 -- ADDITION
20949    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
20950    order by information1, information2; --added for bug: 5151945
20951    --
20952    --
20953    cursor c_PST_min_max_dates(c_table_route_id  number,
20954                 c_information1  number) is
20955    select
20956      min(cpe.information2) min_esd,
20957      max(cpe.information3) min_eed
20958    from ben_copy_entity_results cpe
20959    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
20960    and   cpe.table_route_id     = c_table_route_id
20961    and   cpe.information1       = c_information1 ;
20962    --
20963    cursor c_PST(c_table_route_id  number,
20964                 c_information1   number,
20965                 c_information2   Date,
20966                 c_information3   Date)  is
20967    select
20968      cpe.*
20969    from ben_copy_entity_results cpe
20970    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
20971    and   cpe.table_route_id     = c_table_route_id
20972    and   cpe.information1       = c_information1
20973    and   cpe.information2       = c_information2
20974    and   cpe.information3       = c_information3
20975    and rownum = 1 ;
20976    -- Date Track target record
20977    cursor c_find_PST_in_target(
20978                                 c_effective_start_date    date,
20979                                 c_effective_end_date      date,
20980                                 c_business_group_id       number,
20981                                 c_new_pk_id               number) is
20982    select
20983      PST.pstn_rt_id new_value
20984    from BEN_PSTN_RT_F PST
20985    where
20986    PST.POSITION_ID     = l_POSITION_ID  and
20987    PST.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
20988    PST.ORDR_NUM        = l_ORDR_NUM       and
20989    PST.business_group_id  = c_business_group_id
20990    and   PST.pstn_rt_id  <> c_new_pk_id
20991 --TEMPIK
20992    and c_effective_start_date between effective_start_date
20993                             and effective_end_date ;
20994 --END TEMPIK
20995 /*TEMPIK
20996    and exists ( select null
20997                 from BEN_PSTN_RT_F PST1
20998                 where
20999                 PST1.POSITION_ID     = l_POSITION_ID  and
21000                 PST1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
21001                 PST1.ORDR_NUM        = l_ORDR_NUM       and
21002                 PST1.business_group_id  = c_business_group_id
21003                 and   PST1.effective_start_date <= c_effective_start_date )
21004    and exists ( select null
21005                 from BEN_PSTN_RT_F PST2
21006                 where
21007                 PST2.POSITION_ID     = l_POSITION_ID  and
21008                 PST2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
21009                 PST2.ORDR_NUM        = l_ORDR_NUM       and
21010                 PST2.business_group_id  = c_business_group_id
21011                 and   PST2.effective_end_date >= c_effective_end_date )
21012                 ;
21013 TEMPIK */
21014    --TEMPIK
21015    l_dt_rec_found            boolean ;
21016    --END TEMPIK
21017    --
21018    l_current_pk_id           number := null ;
21019    --UPD START
21020    --
21021    l_update                  boolean      := false ;
21022    l_datetrack_mode          varchar2(80) := hr_api.g_update;
21023    l_process_date            date;
21024    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
21025    --
21026    --UPD END
21027    l_prev_pk_id              number := null ;
21028    l_first_rec               boolean := true ;
21029    r_PST                     c_PST%rowtype;
21030    l_pstn_rt_id             number ;
21031    l_object_version_number   number ;
21032    l_effective_start_date    date ;
21033    l_effective_end_date      date ;
21034    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
21035    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
21036    l_new_value               number(15);
21037    l_object_found_in_target  boolean := false ;
21038    l_min_esd                 date;
21039    l_max_eed                 date;
21040    l_effective_date          date;
21041    --
21042  begin
21043    -- Initialization
21044    l_object_found_in_target := false ;
21045    -- End Initialization
21046    -- Derive the prefix - sufix
21047    if   p_prefix_suffix_cd = 'PREFIX' then
21048      l_prefix  := p_prefix_suffix_text ;
21049    elsif p_prefix_suffix_cd = 'SUFFIX' then
21050      l_suffix   := p_prefix_suffix_text ;
21051    else
21052      l_prefix := null ;
21053      l_suffix  := null ;
21054    end if ;
21055    -- End Prefix Sufix derivation
21056    for r_PST_unique in c_unique_PST('PST') loop
21057 
21058      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
21059         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
21060          r_PST_unique.information3 >=
21061                  ben_pd_copy_to_ben_one.g_copy_effective_date)
21062         ) then
21063        --
21064        hr_utility.set_location(' r_PST_unique.table_route_id '||r_PST_unique.table_route_id,10);
21065        hr_utility.set_location(' r_PST_unique.information1 '||r_PST_unique.information1,10);
21066        hr_utility.set_location( 'r_PST_unique.information2 '||r_PST_unique.information2,10);
21067        hr_utility.set_location( 'r_PST_unique.information3 '||r_PST_unique.information3,10);
21068        -- If reuse objects flag is 'Y' then check for the object in the target business group
21069        -- if found insert the record into PLSql table and exit the loop else try create the
21070        -- object in the target business group
21071        --
21072        l_object_found_in_target := false ;
21073        l_min_esd := null ;
21074        l_max_eed := null ;
21075        open c_PST_min_max_dates(r_PST_unique.table_route_id, r_PST_unique.information1 ) ;
21076        fetch c_PST_min_max_dates into l_min_esd,l_max_eed ;
21077        --
21078 
21079        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
21080             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
21081          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
21082        end if;
21083        l_min_esd := greatest(l_min_esd,r_PST_unique.information2);
21084        open c_PST(r_PST_unique.table_route_id,
21085                 r_PST_unique.information1,
21086                 r_PST_unique.information2,
21087                 r_PST_unique.information3 ) ;
21088        --
21089        fetch c_PST into r_PST ;
21090        --
21091        close c_PST ;
21092        --
21093 
21094        if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
21095          l_POSITION_ID := r_PST.information176;
21096        else
21097          l_POSITION_ID := r_PST.information174;
21098        end if;
21099        --
21100        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_PST.information262,r_PST_unique.dml_operation);
21101        l_EXCLD_FLAG      := r_PST.information11;
21102        l_ORDR_NUM        := r_PST.INFORMATION257;
21103 
21104        if l_POSITION_ID is null then
21105          close c_PST_min_max_dates;
21106          --
21107          log_nomapping_data(p_parent_table_alias =>'VPF'
21108                      ,p_parent_pk_id         => r_PST.information262
21109                      ,p_copy_entity_txn_id   => p_copy_entity_txn_id
21110                      ,p_child_table_alias    => 'PST'
21111                      ,p_child_data           => r_PST.information173 );
21112 
21113             --
21114        else
21115        --UPD START
21116        l_update := false;
21117        l_process_date := p_effective_date;
21118        l_dml_operation:= r_PST_unique.dml_operation ;
21119        --
21120        if l_dml_operation = 'UPDATE' then
21121          --
21122          l_object_found_in_target := TRUE;
21123          --
21124          if l_process_date between r_PST_unique.information2 and r_PST_unique.information3 then
21125                l_update := true;
21126                if r_PST_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
21127                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'PSTN_RT_ID'
21128                then
21129                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'PSTN_RT_ID' ;
21130                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_PST_unique.information1 ;
21131                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_PST_unique.information1 ;
21132                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
21133                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_PST_unique.table_route_id;
21134                   --
21135                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
21136                   --
21137                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
21138                   --
21139                   -- log_data('PST',l_new_value,l_prefix || r_PST_unique.name|| l_suffix,'REUSED');
21140                   --
21141                end if ;
21142                hr_utility.set_location( 'found record for update',10);
21143            --
21144          else
21145            --
21146            l_update := false;
21147            --
21148          end if;
21149        else
21150          --
21151          --UPD END
21152          if p_reuse_object_flag = 'Y' then
21153            if c_PST_min_max_dates%found then
21154               -- cursor to find the object
21155               open c_find_PST_in_target( l_min_esd,l_max_eed,
21156                                     p_target_business_group_id, nvl(l_pstn_rt_id, -999)  ) ;
21157               fetch c_find_PST_in_target into l_new_value ;
21158               if c_find_PST_in_target%found then
21159                 --
21160              --TEMPIK
21161              l_dt_rec_found :=   dt_api.check_min_max_dates
21162                  (p_base_table_name => 'BEN_PSTN_RT_F',
21163                   p_base_key_column => 'PSTN_RT_ID',
21164                   p_base_key_value  => l_new_value,
21165                   p_from_date       => l_min_esd,
21166                   p_to_date         => l_max_eed );
21167              if l_dt_rec_found THEN
21168              --END TEMPIK
21169                 if r_PST_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
21170                    nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'PSTN_RT_ID'  then
21171                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'PSTN_RT_ID' ;
21172                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_PST_unique.information1 ;
21173                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
21174                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
21175                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PST_unique.table_route_id;
21176                    --
21177                    -- 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) ;
21178                    --
21179                    BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
21180                 end if ;
21181                 --
21182                 l_object_found_in_target := true ;
21183              --TEMPIK
21184              end if; -- l_dt_rec_found
21185              --END TEMPIK
21186               end if;
21187               close c_find_PST_in_target ;
21188            --
21189            end if;
21190          end if ;
21191          --
21192          end if;
21193          close c_PST_min_max_dates ;
21194          if not l_object_found_in_target OR l_update   then
21195            --
21196            l_current_pk_id := r_PST.information1;
21197            --
21198            hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
21199            hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
21200            --
21201            if l_current_pk_id =  l_prev_pk_id  then
21202              --
21203              l_first_rec := false ;
21204              --
21205            else
21206              --
21207              l_first_rec := true ;
21208              --
21209            end if ;
21210            --
21211 
21212            l_effective_date := r_PST.information2;
21213            if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
21214                 l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
21215              l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
21216            end if;
21217 
21218            if l_first_rec and not l_update then
21219              -- Call Create routine.
21220              hr_utility.set_location(' BEN_PSTN_RT_F CREATE_PSTN_RT ',20);
21221              BEN_PSTN_RT_API.CREATE_PSTN_RT(
21222                 --
21223                 P_VALIDATE               => false
21224                 ,P_EFFECTIVE_DATE        => l_effective_date
21225                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
21226                 --
21227              ,P_EXCLD_FLAG      => r_PST.INFORMATION11
21228              ,P_ORDR_NUM      => r_PST.INFORMATION257
21229              ,P_POSITION_ID      => l_POSITION_ID
21230              ,P_PSTN_RT_ID      => l_pstn_rt_id
21231              ,P_PST_ATTRIBUTE1      => r_PST.INFORMATION111
21232              ,P_PST_ATTRIBUTE10      => r_PST.INFORMATION120
21233              ,P_PST_ATTRIBUTE11      => r_PST.INFORMATION121
21234              ,P_PST_ATTRIBUTE12      => r_PST.INFORMATION122
21235              ,P_PST_ATTRIBUTE13      => r_PST.INFORMATION123
21236              ,P_PST_ATTRIBUTE14      => r_PST.INFORMATION124
21237              ,P_PST_ATTRIBUTE15      => r_PST.INFORMATION125
21238              ,P_PST_ATTRIBUTE16      => r_PST.INFORMATION126
21239              ,P_PST_ATTRIBUTE17      => r_PST.INFORMATION127
21240              ,P_PST_ATTRIBUTE18      => r_PST.INFORMATION128
21241              ,P_PST_ATTRIBUTE19      => r_PST.INFORMATION129
21242              ,P_PST_ATTRIBUTE2      => r_PST.INFORMATION112
21243              ,P_PST_ATTRIBUTE20      => r_PST.INFORMATION130
21244              ,P_PST_ATTRIBUTE21      => r_PST.INFORMATION131
21245              ,P_PST_ATTRIBUTE22      => r_PST.INFORMATION132
21246              ,P_PST_ATTRIBUTE23      => r_PST.INFORMATION133
21247              ,P_PST_ATTRIBUTE24      => r_PST.INFORMATION134
21248              ,P_PST_ATTRIBUTE25      => r_PST.INFORMATION135
21249              ,P_PST_ATTRIBUTE26      => r_PST.INFORMATION136
21250              ,P_PST_ATTRIBUTE27      => r_PST.INFORMATION137
21251              ,P_PST_ATTRIBUTE28      => r_PST.INFORMATION138
21252              ,P_PST_ATTRIBUTE29      => r_PST.INFORMATION139
21253              ,P_PST_ATTRIBUTE3      => r_PST.INFORMATION113
21254              ,P_PST_ATTRIBUTE30      => r_PST.INFORMATION140
21255              ,P_PST_ATTRIBUTE4      => r_PST.INFORMATION114
21256              ,P_PST_ATTRIBUTE5      => r_PST.INFORMATION115
21257              ,P_PST_ATTRIBUTE6      => r_PST.INFORMATION116
21258              ,P_PST_ATTRIBUTE7      => r_PST.INFORMATION117
21259              ,P_PST_ATTRIBUTE8      => r_PST.INFORMATION118
21260              ,P_PST_ATTRIBUTE9      => r_PST.INFORMATION119
21261              ,P_PST_ATTRIBUTE_CATEGORY      => r_PST.INFORMATION110
21262              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
21263                 --
21264                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
21265                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
21266                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
21267               );
21268               -- insert the table_name,old_pk_id,new_pk_id into a plsql record
21269               -- Update all relevent cer records with new pk_id
21270               hr_utility.set_location('Before plsql table ',222);
21271               hr_utility.set_location('new_value id '||l_pstn_rt_id,222);
21272               BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'PSTN_RT_ID' ;
21273               BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_PST.information1 ;
21274               BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_PSTN_RT_ID ;
21275               BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
21276               BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PST_unique.table_route_id;
21277               hr_utility.set_location('After plsql table ',222);
21278               --
21279               -- 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 ) ;
21280               --
21281               BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
21282               --
21283             else
21284               --
21285               -- Call Update routine for the pk_id created in prev run .
21286               -- insert the table_name,old_pk_id,new_pk_id into a plsql record
21287            --UPD START
21288            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
21289            --
21290            if l_update then
21291              --
21292              l_datetrack_mode := r_PST.datetrack_mode ;
21293              --
21294              get_dt_modes(
21295                p_effective_date        => l_process_date,
21296                p_effective_end_date    => r_PST.information3,
21297                p_effective_start_date  => r_PST.information2,
21298                p_dml_operation         => r_PST.dml_operation,
21299                p_datetrack_mode        => l_datetrack_mode );
21300            --    p_update                => l_update
21301              --
21302              l_effective_date := l_process_date;
21303              l_PSTN_RT_ID   := r_PST.information1;
21304              l_object_version_number := r_PST.information265;
21305              --
21306            end if;
21307            --
21308            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
21309            --
21310            IF l_update OR l_dml_operation <> 'UPDATE' THEN
21311            --UPD END
21312               hr_utility.set_location(' BEN_PSTN_RT_F UPDATE_PSTN_RT ',30);
21313               BEN_PSTN_RT_API.UPDATE_PSTN_RT(
21314                 --
21315                 P_VALIDATE               => false
21316                 ,P_EFFECTIVE_DATE        => l_effective_date
21317                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
21318                 --
21319              ,P_EXCLD_FLAG      => r_PST.INFORMATION11
21320              ,P_ORDR_NUM      => r_PST.INFORMATION257
21321              ,P_POSITION_ID      => l_POSITION_ID
21322              ,P_PSTN_RT_ID      => l_pstn_rt_id
21323              ,P_PST_ATTRIBUTE1      => r_PST.INFORMATION111
21324              ,P_PST_ATTRIBUTE10      => r_PST.INFORMATION120
21325              ,P_PST_ATTRIBUTE11      => r_PST.INFORMATION121
21326              ,P_PST_ATTRIBUTE12      => r_PST.INFORMATION122
21327              ,P_PST_ATTRIBUTE13      => r_PST.INFORMATION123
21328              ,P_PST_ATTRIBUTE14      => r_PST.INFORMATION124
21329              ,P_PST_ATTRIBUTE15      => r_PST.INFORMATION125
21330              ,P_PST_ATTRIBUTE16      => r_PST.INFORMATION126
21331              ,P_PST_ATTRIBUTE17      => r_PST.INFORMATION127
21332              ,P_PST_ATTRIBUTE18      => r_PST.INFORMATION128
21333              ,P_PST_ATTRIBUTE19      => r_PST.INFORMATION129
21334              ,P_PST_ATTRIBUTE2      => r_PST.INFORMATION112
21335              ,P_PST_ATTRIBUTE20      => r_PST.INFORMATION130
21336              ,P_PST_ATTRIBUTE21      => r_PST.INFORMATION131
21337              ,P_PST_ATTRIBUTE22      => r_PST.INFORMATION132
21338              ,P_PST_ATTRIBUTE23      => r_PST.INFORMATION133
21339              ,P_PST_ATTRIBUTE24      => r_PST.INFORMATION134
21340              ,P_PST_ATTRIBUTE25      => r_PST.INFORMATION135
21341              ,P_PST_ATTRIBUTE26      => r_PST.INFORMATION136
21342              ,P_PST_ATTRIBUTE27      => r_PST.INFORMATION137
21343              ,P_PST_ATTRIBUTE28      => r_PST.INFORMATION138
21344              ,P_PST_ATTRIBUTE29      => r_PST.INFORMATION139
21345              ,P_PST_ATTRIBUTE3      => r_PST.INFORMATION113
21346              ,P_PST_ATTRIBUTE30      => r_PST.INFORMATION140
21347              ,P_PST_ATTRIBUTE4      => r_PST.INFORMATION114
21348              ,P_PST_ATTRIBUTE5      => r_PST.INFORMATION115
21349              ,P_PST_ATTRIBUTE6      => r_PST.INFORMATION116
21350              ,P_PST_ATTRIBUTE7      => r_PST.INFORMATION117
21351              ,P_PST_ATTRIBUTE8      => r_PST.INFORMATION118
21352              ,P_PST_ATTRIBUTE9      => r_PST.INFORMATION119
21353              ,P_PST_ATTRIBUTE_CATEGORY      => r_PST.INFORMATION110
21354              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
21355                 --
21356                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
21357                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
21358                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
21359                 ,P_DATETRACK_MODE        => l_datetrack_mode
21360               );
21361               --
21362               end if;
21363             end if;
21364             --
21365             -- Delete the row if it is end dated.
21366             --
21367             if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
21368              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
21369                 trunc(l_max_eed) = r_PST.information3) then
21370                 --
21371                 BEN_PSTN_RT_API.delete_PSTN_RT(
21372                    --
21373                    p_validate                       => false
21374                    ,p_pstn_rt_id                   => l_pstn_rt_id
21375                    ,p_effective_start_date           => l_effective_start_date
21376                    ,p_effective_end_date             => l_effective_end_date
21377                    ,p_object_version_number          => l_object_version_number
21378                    ,p_effective_date                 => l_max_eed
21379                    ,p_datetrack_mode                 => hr_api.g_delete
21380                    --
21381                    );
21382                    --
21383             end if;
21384             --
21385             l_prev_pk_id := l_current_pk_id ;
21386             --
21387           end if;
21388           --
21389         end if;
21390         --
21391       end if;
21392       --
21393    end loop;
21394    --
21395  exception when others then
21396     --
21397     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'PST',r_pst.information5 );
21398     --
21399  end create_PST_rows;
21400 
21401    --
21402    --
21403    ---------------------------------------------------------------
21404    ----------------------< create_WLR_rows >-----------------------
21405    ---------------------------------------------------------------
21406    --
21407    procedure create_WLR_rows
21408    (
21409          p_validate                       in  number     default 0
21410         ,p_copy_entity_txn_id             in  number
21411         ,p_effective_date                 in  date
21412         ,p_prefix_suffix_text             in  varchar2  default null
21413         ,p_reuse_object_flag              in  varchar2  default null
21414         ,p_target_business_group_id       in  varchar2  default null
21415         ,p_prefix_suffix_cd               in  varchar2  default null
21416    ) is
21417    --
21418    l_LOCATION_ID  number;
21419    l_VRBL_RT_PRFL_ID  number;
21420    cursor c_unique_WLR(l_table_alias varchar2) is
21421    select distinct cpe.information1,
21422      cpe.information2,
21423      cpe.information3,
21424      cpe.table_route_id
21425    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
21426         pqh_table_route tr
21427    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
21428    and   cpe.table_route_id     = tr.table_route_id
21429    -- and   tr.where_clause        = l_BEN_WK_LOC_RT_F
21430    and tr.table_alias = l_table_alias
21431    and   cpe.number_of_copies   = 1 -- ADDITION
21432    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
21433    order by information1, information2; --added for bug: 5151945
21434    --
21435    --
21436    cursor c_WLR_min_max_dates(c_table_route_id  number,
21437                 c_information1   number) is
21438    select
21439      min(cpe.information2) min_esd,
21440      max(cpe.information3) min_eed
21441    from ben_copy_entity_results cpe
21442    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
21443    and   cpe.table_route_id     = c_table_route_id
21444    and   cpe.information1       = c_information1 ;
21445    --
21446    cursor c_WLR(c_table_route_id number,
21447                 c_information1   number,
21448                 c_information2   Date,
21449                 c_information3   Date)  is
21450    select
21451      cpe.*
21452    from ben_copy_entity_results cpe
21453    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
21454    and   cpe.table_route_id     = c_table_route_id
21455    and   cpe.information1       = c_information1
21456    and   cpe.information2       = c_information2
21457    and   cpe.information3       = c_information3
21458    and rownum = 1 ;
21459    -- Date Track target record
21460    cursor c_find_WLR_in_target(
21461                                 c_effective_start_date    date,
21462                                 c_effective_end_date      date,
21463                                 c_business_group_id       number,
21464                                 c_new_pk_id               number) is
21465    select
21466      WLR.wk_loc_rt_id new_value
21467    from BEN_WK_LOC_RT_F WLR
21468    where
21469    WLR.LOCATION_ID     = l_LOCATION_ID  and
21470    WLR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
21471    WLR.business_group_id  = c_business_group_id
21472    and   WLR.wk_loc_rt_id  <> c_new_pk_id
21473 --TEMPIK
21474    and c_effective_start_date between effective_start_date
21475                             and effective_end_date ;
21476 --END TEMPIK
21477 /*TEMPIK
21478    and exists ( select null
21479                 from BEN_WK_LOC_RT_F WLR1
21480                 where
21481                 WLR1.LOCATION_ID     = l_LOCATION_ID  and
21482                 WLR1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
21483                 WLR1.business_group_id  = c_business_group_id
21484                 and   WLR1.effective_start_date <= c_effective_start_date )
21485    and exists ( select null
21486                 from BEN_WK_LOC_RT_F WLR2
21487                 where
21488                 WLR2.LOCATION_ID     = l_LOCATION_ID  and
21489                 WLR2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
21490                 WLR2.business_group_id  = c_business_group_id
21491                 and   WLR2.effective_end_date >= c_effective_end_date )
21492                 ;
21493 TEMPIK */
21494    --TEMPIK
21495    l_dt_rec_found            boolean ;
21496    --END TEMPIK
21497    --
21498    l_current_pk_id           number := null ;
21499    --UPD START
21500    --
21501    l_update                  boolean      := false ;
21502    l_datetrack_mode          varchar2(80) := hr_api.g_update;
21503    l_process_date            date;
21504    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
21505    --
21506    --UPD END
21507    l_prev_pk_id              number := null ;
21508    l_first_rec               boolean := true ;
21509    r_WLR                     c_WLR%rowtype;
21510    l_wk_loc_rt_id             number ;
21511    l_object_version_number   number ;
21512    l_effective_start_date    date ;
21513    l_effective_end_date      date ;
21514    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
21515    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
21516    l_new_value               number(15);
21517    l_object_found_in_target  boolean := false ;
21518    l_min_esd                 date;
21519    l_max_eed                 date;
21520    l_effective_date          date;
21521    --
21522  begin
21523    -- Initialization
21524    l_object_found_in_target := false ;
21525    -- End Initialization
21526    -- Derive the prefix - sufix
21527    if   p_prefix_suffix_cd = 'PREFIX' then
21528      l_prefix  := p_prefix_suffix_text ;
21529    elsif p_prefix_suffix_cd = 'SUFFIX' then
21530      l_suffix   := p_prefix_suffix_text ;
21531    else
21532      l_prefix := null ;
21533      l_suffix  := null ;
21534    end if ;
21535    -- End Prefix Sufix derivation
21536    for r_WLR_unique in c_unique_WLR('WLR') loop
21537 
21538      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
21539         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
21540          r_WLR_unique.information3 >=
21541                  ben_pd_copy_to_ben_one.g_copy_effective_date)
21542         ) then
21543        --
21544        hr_utility.set_location(' r_WLR_unique.table_route_id '||r_WLR_unique.table_route_id,10);
21545        hr_utility.set_location(' r_WLR_unique.information1 '||r_WLR_unique.information1,10);
21546        hr_utility.set_location( 'r_WLR_unique.information2 '||r_WLR_unique.information2,10);
21547        hr_utility.set_location( 'r_WLR_unique.information3 '||r_WLR_unique.information3,10);
21548        -- If reuse objects flag is 'Y' then check for the object in the target business group
21549        -- if found insert the record into PLSql table and exit the loop else try create the
21550        -- object in the target business group
21551        --
21552        l_object_found_in_target := false ;
21553        l_min_esd := null ;
21554        l_max_eed := null ;
21555        open c_WLR_min_max_dates(r_WLR_unique.table_route_id, r_WLR_unique.information1 ) ;
21556        fetch c_WLR_min_max_dates into l_min_esd,l_max_eed ;
21557        --
21558 
21559        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
21560             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
21561          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
21562        end if;
21563        l_min_esd := greatest(l_min_esd,r_WLR_unique.information2);
21564        open c_WLR(r_WLR_unique.table_route_id,
21565                 r_WLR_unique.information1,
21566                 r_WLR_unique.information2,
21567                 r_WLR_unique.information3 ) ;
21568        --
21569        fetch c_WLR into r_WLR ;
21570        --
21571        close c_WLR ;
21572        --
21573 
21574        if BEN_PD_COPY_TO_BEN_ONE.g_mapping_done then
21575          l_LOCATION_ID := r_WLR.information176;
21576        else
21577          l_LOCATION_ID := r_WLR.information174;
21578        end if;
21579        --
21580        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_WLR.information262,r_WLR_unique.dml_operation);
21581 
21582        if l_LOCATION_ID is null then
21583          close c_WLR_min_max_dates;
21584          --
21585          log_nomapping_data(p_parent_table_alias =>'VPF'
21586                      ,p_parent_pk_id         => r_WLR.information262
21587                      ,p_copy_entity_txn_id   => p_copy_entity_txn_id
21588                      ,p_child_table_alias    => 'WLR'
21589                      ,p_child_data           => r_WLR.information173 );
21590 
21591          --
21592        else
21593        --UPD START
21594        l_update := false;
21595        l_process_date := p_effective_date;
21596        l_dml_operation:= r_WLR_unique.dml_operation ;
21597        --
21598        if l_dml_operation = 'UPDATE' then
21599          --
21600          l_object_found_in_target := TRUE;
21601          --
21602          if l_process_date between r_WLR_unique.information2 and r_WLR_unique.information3 then
21603                l_update := true;
21604                if r_WLR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
21605                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'WK_LOC_RT_ID'
21606                then
21607                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'WK_LOC_RT_ID' ;
21608                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_WLR_unique.information1 ;
21609                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_WLR_unique.information1 ;
21610                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
21611                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_WLR_unique.table_route_id;
21612                   --
21613                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
21614                   --
21615                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
21616                   --
21617                   -- log_data('WLR',l_new_value,l_prefix || r_WLR_unique.name|| l_suffix,'REUSED');
21618                   --
21619                end if ;
21620                hr_utility.set_location( 'found record for update',10);
21621            --
21622          else
21623            --
21624            l_update := false;
21625            --
21626          end if;
21627        else
21628          --
21629          --UPD END
21630          if p_reuse_object_flag = 'Y' then
21631            if c_WLR_min_max_dates%found then
21632               -- cursor to find the object
21633               open c_find_WLR_in_target( l_min_esd,l_max_eed,
21634                                     p_target_business_group_id, nvl(l_wk_loc_rt_id, -999)  ) ;
21635               fetch c_find_WLR_in_target into l_new_value ;
21636               if c_find_WLR_in_target%found then
21637                 --
21638              --TEMPIK
21639              l_dt_rec_found :=   dt_api.check_min_max_dates
21640                  (p_base_table_name => 'BEN_WK_LOC_RT_F',
21641                   p_base_key_column => 'WK_LOC_RT_ID',
21642                   p_base_key_value  => l_new_value,
21643                   p_from_date       => l_min_esd,
21644                   p_to_date         => l_max_eed );
21645              if l_dt_rec_found THEN
21646              --END TEMPIK
21647                 if r_WLR_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
21648                    nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'WK_LOC_RT_ID'  then
21649                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'WK_LOC_RT_ID' ;
21650                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_WLR_unique.information1 ;
21651                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
21652                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
21653                    BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_WLR_unique.table_route_id;
21654                    --
21655                    -- 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) ;
21656                    --
21657                    BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
21658                 end if ;
21659                 --
21660                 l_object_found_in_target := true ;
21661              --TEMPIK
21662              end if; -- l_dt_rec_found
21663              --END TEMPIK
21664               end if;
21665               close c_find_WLR_in_target ;
21666            --
21667            end if;
21668          end if ;
21669          --
21670          end if;
21671          close c_WLR_min_max_dates ;
21672          if not l_object_found_in_target OR l_update   then
21673            --
21674            l_current_pk_id := r_WLR.information1;
21675            --
21676            hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
21677            hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
21678            --
21679            if l_current_pk_id =  l_prev_pk_id  then
21680              --
21681              l_first_rec := false ;
21682              --
21683            else
21684              --
21685              l_first_rec := true ;
21686              --
21687            end if ;
21688            --
21689 
21690            l_effective_date := r_WLR.information2;
21691            if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
21692                 l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
21693              l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
21694            end if;
21695 
21696            if l_first_rec and not l_update then
21697              -- Call Create routine.
21698              hr_utility.set_location(' BEN_WK_LOC_RT_F CREATE_WORK_LOC_RATE ',20);
21699              BEN_WORK_LOC_RATE_API.CREATE_WORK_LOC_RATE(
21700                 --
21701                 P_VALIDATE               => false
21702                 ,P_EFFECTIVE_DATE        => l_effective_date
21703                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
21704                 --
21705              ,P_EXCLD_FLAG      => r_WLR.INFORMATION11
21706              ,P_LOCATION_ID      => l_LOCATION_ID
21707              ,P_ORDR_NUM      => r_WLR.INFORMATION260
21708              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
21709              ,P_WK_LOC_RT_ID      => l_wk_loc_rt_id
21710              ,P_WLR_ATTRIBUTE1      => r_WLR.INFORMATION111
21711              ,P_WLR_ATTRIBUTE10      => r_WLR.INFORMATION120
21712              ,P_WLR_ATTRIBUTE11      => r_WLR.INFORMATION121
21713              ,P_WLR_ATTRIBUTE12      => r_WLR.INFORMATION122
21714              ,P_WLR_ATTRIBUTE13      => r_WLR.INFORMATION123
21715              ,P_WLR_ATTRIBUTE14      => r_WLR.INFORMATION124
21716              ,P_WLR_ATTRIBUTE15      => r_WLR.INFORMATION125
21717              ,P_WLR_ATTRIBUTE16      => r_WLR.INFORMATION126
21718              ,P_WLR_ATTRIBUTE17      => r_WLR.INFORMATION127
21719              ,P_WLR_ATTRIBUTE18      => r_WLR.INFORMATION128
21720              ,P_WLR_ATTRIBUTE19      => r_WLR.INFORMATION129
21721              ,P_WLR_ATTRIBUTE2      => r_WLR.INFORMATION112
21722              ,P_WLR_ATTRIBUTE20      => r_WLR.INFORMATION130
21723              ,P_WLR_ATTRIBUTE21      => r_WLR.INFORMATION131
21724              ,P_WLR_ATTRIBUTE22      => r_WLR.INFORMATION132
21725              ,P_WLR_ATTRIBUTE23      => r_WLR.INFORMATION133
21726              ,P_WLR_ATTRIBUTE24      => r_WLR.INFORMATION134
21727              ,P_WLR_ATTRIBUTE25      => r_WLR.INFORMATION135
21728              ,P_WLR_ATTRIBUTE26      => r_WLR.INFORMATION136
21729              ,P_WLR_ATTRIBUTE27      => r_WLR.INFORMATION137
21730              ,P_WLR_ATTRIBUTE28      => r_WLR.INFORMATION138
21731              ,P_WLR_ATTRIBUTE29      => r_WLR.INFORMATION139
21732              ,P_WLR_ATTRIBUTE3      => r_WLR.INFORMATION113
21733              ,P_WLR_ATTRIBUTE30      => r_WLR.INFORMATION140
21734              ,P_WLR_ATTRIBUTE4      => r_WLR.INFORMATION114
21735              ,P_WLR_ATTRIBUTE5      => r_WLR.INFORMATION115
21736              ,P_WLR_ATTRIBUTE6      => r_WLR.INFORMATION116
21737              ,P_WLR_ATTRIBUTE7      => r_WLR.INFORMATION117
21738              ,P_WLR_ATTRIBUTE8      => r_WLR.INFORMATION118
21739              ,P_WLR_ATTRIBUTE9      => r_WLR.INFORMATION119
21740              ,P_WLR_ATTRIBUTE_CATEGORY      => r_WLR.INFORMATION110
21741                 --
21742                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
21743                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
21744                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
21745               );
21746               -- insert the table_name,old_pk_id,new_pk_id into a plsql record
21747               -- Update all relevent cer records with new pk_id
21748               hr_utility.set_location('Before plsql table ',222);
21749               hr_utility.set_location('new_value id '||l_wk_loc_rt_id,222);
21750               BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'WK_LOC_RT_ID' ;
21751               BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_WLR.information1 ;
21752               BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_WK_LOC_RT_ID ;
21753               BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
21754               BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_WLR_unique.table_route_id;
21755               hr_utility.set_location('After plsql table ',222);
21756               --
21757               -- 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 ) ;
21758               --
21759               BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
21760               --
21761             else
21762               --
21763               -- Call Update routine for the pk_id created in prev run .
21764               -- insert the table_name,old_pk_id,new_pk_id into a plsql record
21765            --UPD START
21766            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
21767            --
21768            if l_update then
21769              --
21770              l_datetrack_mode := r_WLR.datetrack_mode ;
21771              --
21772              get_dt_modes(
21773                p_effective_date        => l_process_date,
21774                p_effective_end_date    => r_WLR.information3,
21775                p_effective_start_date  => r_WLR.information2,
21776                p_dml_operation         => r_WLR.dml_operation,
21777                p_datetrack_mode        => l_datetrack_mode );
21778            --    p_update                => l_update
21779              --
21780              l_effective_date := l_process_date;
21781              l_WK_LOC_RT_ID   := r_WLR.information1;
21782              l_object_version_number := r_WLR.information265;
21783              --
21784            end if;
21785            --
21786            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
21787            --
21788            IF l_update OR l_dml_operation <> 'UPDATE' THEN
21789            --UPD END
21790               hr_utility.set_location(' BEN_WK_LOC_RT_F UPDATE_WORK_LOC_RATE ',30);
21791               BEN_WORK_LOC_RATE_API.UPDATE_WORK_LOC_RATE(
21792                 --
21793                 P_VALIDATE               => false
21794                 ,P_EFFECTIVE_DATE        => l_effective_date
21795                 ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
21796                 --
21797              ,P_EXCLD_FLAG      => r_WLR.INFORMATION11
21798              ,P_LOCATION_ID      => l_LOCATION_ID
21799              ,P_ORDR_NUM      => r_WLR.INFORMATION260
21800              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
21801              ,P_WK_LOC_RT_ID      => l_wk_loc_rt_id
21802              ,P_WLR_ATTRIBUTE1      => r_WLR.INFORMATION111
21803              ,P_WLR_ATTRIBUTE10      => r_WLR.INFORMATION120
21804              ,P_WLR_ATTRIBUTE11      => r_WLR.INFORMATION121
21805              ,P_WLR_ATTRIBUTE12      => r_WLR.INFORMATION122
21806              ,P_WLR_ATTRIBUTE13      => r_WLR.INFORMATION123
21807              ,P_WLR_ATTRIBUTE14      => r_WLR.INFORMATION124
21808              ,P_WLR_ATTRIBUTE15      => r_WLR.INFORMATION125
21809              ,P_WLR_ATTRIBUTE16      => r_WLR.INFORMATION126
21810              ,P_WLR_ATTRIBUTE17      => r_WLR.INFORMATION127
21811              ,P_WLR_ATTRIBUTE18      => r_WLR.INFORMATION128
21812              ,P_WLR_ATTRIBUTE19      => r_WLR.INFORMATION129
21813              ,P_WLR_ATTRIBUTE2      => r_WLR.INFORMATION112
21814              ,P_WLR_ATTRIBUTE20      => r_WLR.INFORMATION130
21815              ,P_WLR_ATTRIBUTE21      => r_WLR.INFORMATION131
21816              ,P_WLR_ATTRIBUTE22      => r_WLR.INFORMATION132
21817              ,P_WLR_ATTRIBUTE23      => r_WLR.INFORMATION133
21818              ,P_WLR_ATTRIBUTE24      => r_WLR.INFORMATION134
21819              ,P_WLR_ATTRIBUTE25      => r_WLR.INFORMATION135
21820              ,P_WLR_ATTRIBUTE26      => r_WLR.INFORMATION136
21821              ,P_WLR_ATTRIBUTE27      => r_WLR.INFORMATION137
21822              ,P_WLR_ATTRIBUTE28      => r_WLR.INFORMATION138
21823              ,P_WLR_ATTRIBUTE29      => r_WLR.INFORMATION139
21824              ,P_WLR_ATTRIBUTE3      => r_WLR.INFORMATION113
21825              ,P_WLR_ATTRIBUTE30      => r_WLR.INFORMATION140
21826              ,P_WLR_ATTRIBUTE4      => r_WLR.INFORMATION114
21827              ,P_WLR_ATTRIBUTE5      => r_WLR.INFORMATION115
21828              ,P_WLR_ATTRIBUTE6      => r_WLR.INFORMATION116
21829              ,P_WLR_ATTRIBUTE7      => r_WLR.INFORMATION117
21830              ,P_WLR_ATTRIBUTE8      => r_WLR.INFORMATION118
21831              ,P_WLR_ATTRIBUTE9      => r_WLR.INFORMATION119
21832              ,P_WLR_ATTRIBUTE_CATEGORY      => r_WLR.INFORMATION110
21833                 --
21834                 ,P_EFFECTIVE_START_DATE  => l_effective_start_date
21835                 ,P_EFFECTIVE_END_DATE    => l_effective_end_date
21836                 ,P_OBJECT_VERSION_NUMBER => l_object_version_number
21837                 ,P_DATETRACK_MODE        => l_datetrack_mode
21838               );
21839               --
21840               end if;
21841             end if;
21842             --
21843             -- Delete the row if it is end dated.
21844             --
21845             if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
21846              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
21847                 trunc(l_max_eed) = r_WLR.information3) then
21848                 --
21849                 BEN_WORK_LOC_RATE_API.delete_WORK_LOC_RATE(
21850                    --
21851                    p_validate                       => false
21852                    ,p_wk_loc_rt_id                   => l_wk_loc_rt_id
21853                    ,p_effective_start_date           => l_effective_start_date
21854                    ,p_effective_end_date             => l_effective_end_date
21855                    ,p_object_version_number          => l_object_version_number
21856                    ,p_effective_date                 => l_max_eed
21857                    ,p_datetrack_mode                 => hr_api.g_delete
21858                    --
21859                    );
21860                    --
21861             end if;
21862             --
21863             l_prev_pk_id := l_current_pk_id ;
21864             --
21865           end if;
21866           --
21867        end if;
21868        --
21869      end if;
21870      --
21871    end loop;
21872    --
21873  exception when others then
21874     --
21875     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'WLR',r_wlr.information5 );
21876     --
21877  end create_WLR_rows;
21878 
21879    --
21880    --
21881    ---------------------------------------------------------------
21882    ----------------------< create_PFR_rows >-----------------------
21883    ---------------------------------------------------------------
21884    --
21885    procedure create_PFR_rows
21886    (
21887          p_validate                       in  number     default 0
21888         ,p_copy_entity_txn_id             in  number
21889         ,p_effective_date                 in  date
21890         ,p_prefix_suffix_text             in  varchar2  default null
21891         ,p_reuse_object_flag              in  varchar2  default null
21892         ,p_target_business_group_id       in  varchar2  default null
21893         ,p_prefix_suffix_cd               in  varchar2  default null
21894    ) is
21895    --
21896    l_PCT_FL_TM_FCTR_ID  number;
21897    l_VRBL_RT_PRFL_ID  number;
21898    l_ORDR_NUM           number;
21899    cursor c_unique_PFR(l_table_alias varchar2) is
21900    select distinct cpe.information1,
21901      cpe.information2,
21902      cpe.information3,
21903      cpe.table_route_id
21904    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
21905         pqh_table_route tr
21906    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
21907    and   cpe.table_route_id     = tr.table_route_id
21908    -- and   tr.where_clause        = l_BEN_PCT_FL_TM_RT_F
21909    and tr.table_alias = l_table_alias
21910    and   cpe.number_of_copies   = 1 -- ADDITION
21911    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
21912    order by information1, information2; --added for bug: 5151945
21913    --
21914    --
21915    cursor c_PFR_min_max_dates(c_table_route_id  number,
21916                 c_information1   number) is
21917    select
21918      min(cpe.information2) min_esd,
21919      max(cpe.information3) min_eed
21920    from ben_copy_entity_results cpe
21921    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
21922    and   cpe.table_route_id     = c_table_route_id
21923    and   cpe.information1       = c_information1 ;
21924    --
21925    cursor c_PFR(c_table_route_id  number,
21926                 c_information1   number,
21927                 c_information2   Date,
21928                 c_information3   Date)  is
21929    select
21930      cpe.*
21931    from ben_copy_entity_results cpe
21932    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
21933    and   cpe.table_route_id     = c_table_route_id
21934    and   cpe.information1       = c_information1
21935    and   cpe.information2       = c_information2
21936    and   cpe.information3       = c_information3
21937    and rownum = 1 ;
21938    -- Date Track target record
21939    cursor c_find_PFR_in_target(
21940                                 c_effective_start_date    date,
21941                                 c_effective_end_date      date,
21942                                 c_business_group_id       number,
21943                                 c_new_pk_id               number) is
21944    select
21945      PFR.pct_fl_tm_rt_id new_value
21946    from BEN_PCT_FL_TM_RT_F PFR
21947    where
21948    PFR.PCT_FL_TM_FCTR_ID     = l_PCT_FL_TM_FCTR_ID  and
21949    PFR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
21950    PFR.ORDR_NUM            = l_ORDR_NUM and
21951    PFR.business_group_id  = c_business_group_id
21952    and   PFR.pct_fl_tm_rt_id  <> c_new_pk_id
21953 --TEMPIK
21954    and c_effective_start_date between effective_start_date
21955                             and effective_end_date ;
21956 --END TEMPIK
21957 /*TEMPIK
21958    and exists ( select null
21959                 from BEN_PCT_FL_TM_RT_F PFR1
21960                 where
21961                 PFR1.PCT_FL_TM_FCTR_ID     = l_PCT_FL_TM_FCTR_ID  and
21962                 PFR1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
21963                 PFR1.ORDR_NUM            = l_ORDR_NUM and
21964                 PFR1.business_group_id  = c_business_group_id
21965                 and   PFR1.effective_start_date <= c_effective_start_date )
21966    and exists ( select null
21967                 from BEN_PCT_FL_TM_RT_F PFR2
21968                 where
21969                 PFR2.PCT_FL_TM_FCTR_ID     = l_PCT_FL_TM_FCTR_ID  and
21970                 PFR2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
21971                 PFR2.ORDR_NUM            = l_ORDR_NUM and
21972                 PFR2.business_group_id  = c_business_group_id
21973                 and   PFR2.effective_end_date >= c_effective_end_date )
21974                 ;
21975 TEMPIK */
21976    --TEMPIK
21977    l_dt_rec_found            boolean ;
21978    --END TEMPIK
21979    --
21980    l_current_pk_id           number := null ;
21981    --UPD START
21982    --
21983    l_update                  boolean      := false ;
21984    l_datetrack_mode          varchar2(80) := hr_api.g_update;
21985    l_process_date            date;
21986    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
21987    --
21988    --UPD END
21989    l_prev_pk_id              number := null ;
21990    l_first_rec               boolean := true ;
21991    r_PFR                     c_PFR%rowtype;
21992    l_pct_fl_tm_rt_id             number ;
21993    l_object_version_number   number ;
21994    l_effective_start_date    date ;
21995    l_effective_end_date      date ;
21996    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
21997    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
21998    l_new_value               number(15);
21999    l_object_found_in_target  boolean := false ;
22000    l_min_esd                 date;
22001    l_max_eed                 date;
22002    l_effective_date          date;
22003    --
22004  begin
22005    -- Initialization
22006    l_object_found_in_target := false ;
22007    -- End Initialization
22008    -- Derive the prefix - sufix
22009    if   p_prefix_suffix_cd = 'PREFIX' then
22010      l_prefix  := p_prefix_suffix_text ;
22011    elsif p_prefix_suffix_cd = 'SUFFIX' then
22012      l_suffix   := p_prefix_suffix_text ;
22013    else
22014      l_prefix := null ;
22015      l_suffix  := null ;
22016    end if ;
22017    -- End Prefix Sufix derivation
22018    for r_PFR_unique in c_unique_PFR('PFR') loop
22019 
22020      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
22021         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
22022          r_PFR_unique.information3 >=
22023                  ben_pd_copy_to_ben_one.g_copy_effective_date)
22024         ) then
22025        --
22026        hr_utility.set_location(' r_PFR_unique.table_route_id '||r_PFR_unique.table_route_id,10);
22027        hr_utility.set_location(' r_PFR_unique.information1 '||r_PFR_unique.information1,10);
22028        hr_utility.set_location( 'r_PFR_unique.information2 '||r_PFR_unique.information2,10);
22029        hr_utility.set_location( 'r_PFR_unique.information3 '||r_PFR_unique.information3,10);
22030        -- If reuse objects flag is 'Y' then check for the object in the target business group
22031        -- if found insert the record into PLSql table and exit the loop else try create the
22032        -- object in the target business group
22033        --
22034        l_object_found_in_target := false ;
22035        l_min_esd := null ;
22036        l_max_eed := null ;
22037        open c_PFR_min_max_dates(r_PFR_unique.table_route_id, r_PFR_unique.information1 ) ;
22038        fetch c_PFR_min_max_dates into l_min_esd,l_max_eed ;
22039        --
22040 
22041        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
22042             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
22043          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
22044        end if;
22045        l_min_esd := greatest(l_min_esd,r_PFR_unique.information2);
22046        open c_PFR(r_PFR_unique.table_route_id,
22047                 r_PFR_unique.information1,
22048                 r_PFR_unique.information2,
22049                 r_PFR_unique.information3 ) ;
22050        --
22051        fetch c_PFR into r_PFR ;
22052        --
22053        close c_PFR ;
22054        --
22055        l_PCT_FL_TM_FCTR_ID := get_fk('PCT_FL_TM_FCTR_ID', r_PFR.information233,r_PFR_unique.dml_operation);
22056        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_PFR.information262,r_PFR_unique.dml_operation);
22057        l_ORDR_NUM := r_PFR.INFORMATION257 ;
22058        --
22059        --UPD START
22060        l_update := false;
22061        l_process_date := p_effective_date;
22062        l_dml_operation:= r_PFR_unique.dml_operation ;
22063        --
22064        if l_dml_operation = 'UPDATE' then
22065          --
22066          l_object_found_in_target := TRUE;
22067          --
22068          if l_process_date between r_PFR_unique.information2 and r_PFR_unique.information3 then
22069                l_update := true;
22070                if r_PFR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
22071                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'PCT_FL_TM_RT_ID'
22072                then
22073                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'PCT_FL_TM_RT_ID' ;
22074                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_PFR_unique.information1 ;
22075                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_PFR_unique.information1 ;
22076                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
22077                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_PFR_unique.table_route_id;
22078                   --
22079                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
22080                   --
22081                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
22082                   --
22083                   -- log_data('PFR',l_new_value,l_prefix || r_PFR_unique.name|| l_suffix,'REUSED');
22084                   --
22085                end if ;
22086                hr_utility.set_location( 'found record for update',10);
22087            --
22088          else
22089            --
22090            l_update := false;
22091            --
22092          end if;
22093        else
22094          --
22095          --UPD END
22096        if p_reuse_object_flag = 'Y' then
22097          if c_PFR_min_max_dates%found then
22098            -- cursor to find the object
22099            open c_find_PFR_in_target( l_min_esd,l_max_eed,
22100                                  p_target_business_group_id, nvl(l_pct_fl_tm_rt_id, -999)  ) ;
22101            fetch c_find_PFR_in_target into l_new_value ;
22102            if c_find_PFR_in_target%found then
22103              --TEMPIK
22104              l_dt_rec_found :=   dt_api.check_min_max_dates
22105                  (p_base_table_name => 'BEN_PCT_FL_TM_RT_F',
22106                   p_base_key_column => 'PCT_FL_TM_RT_ID',
22107                   p_base_key_value  => l_new_value,
22108                   p_from_date       => l_min_esd,
22109                   p_to_date         => l_max_eed );
22110              if l_dt_rec_found THEN
22111              --END TEMPIK
22112              --
22113              if r_PFR_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
22114                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'PCT_FL_TM_RT_ID'  then
22115                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'PCT_FL_TM_RT_ID' ;
22116                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_PFR_unique.information1 ;
22117                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
22118                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
22119                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PFR_unique.table_route_id;
22120                 --
22121                 -- 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) ;
22122                 --
22123                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
22124              end if ;
22125              --
22126              l_object_found_in_target := true ;
22127              --TEMPIK
22128              end if; -- l_dt_rec_found
22129              --END TEMPIK
22130            end if;
22131            close c_find_PFR_in_target ;
22132          --
22133          end if;
22134        end if ;
22135        --
22136        end if;
22137        close c_PFR_min_max_dates ;
22138        if not l_object_found_in_target OR l_update   then
22139          --
22140          l_current_pk_id := r_PFR.information1;
22141          --
22142          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
22143          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
22144          --
22145          if l_current_pk_id =  l_prev_pk_id  then
22146            --
22147            l_first_rec := false ;
22148            --
22149          else
22150            --
22151            l_first_rec := true ;
22152            --
22153          end if ;
22154          --
22155 
22156          l_effective_date := r_PFR.information2;
22157          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
22158               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
22159            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
22160          end if;
22161 
22162          if l_first_rec and not l_update then
22163            -- Call Create routine.
22164            hr_utility.set_location(' BEN_PCT_FL_TM_RT_F CREATE_PCT_FULL_TIME_RATE ',20);
22165            BEN_PCT_FULL_TIME_RATE_API.CREATE_PCT_FULL_TIME_RATE(
22166              --
22167              P_VALIDATE               => false
22168              ,P_EFFECTIVE_DATE        => l_effective_date
22169              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
22170              --
22171              ,P_EXCLD_FLAG      => r_PFR.INFORMATION11
22172              ,P_ORDR_NUM      => r_PFR.INFORMATION257
22173              ,P_PCT_FL_TM_FCTR_ID      => l_PCT_FL_TM_FCTR_ID
22174              ,P_PCT_FL_TM_RT_ID      => l_pct_fl_tm_rt_id
22175              ,P_PFR_ATTRIBUTE1      => r_PFR.INFORMATION111
22176              ,P_PFR_ATTRIBUTE10      => r_PFR.INFORMATION120
22177              ,P_PFR_ATTRIBUTE11      => r_PFR.INFORMATION121
22178              ,P_PFR_ATTRIBUTE12      => r_PFR.INFORMATION122
22179              ,P_PFR_ATTRIBUTE13      => r_PFR.INFORMATION123
22180              ,P_PFR_ATTRIBUTE14      => r_PFR.INFORMATION124
22181              ,P_PFR_ATTRIBUTE15      => r_PFR.INFORMATION125
22182              ,P_PFR_ATTRIBUTE16      => r_PFR.INFORMATION126
22183              ,P_PFR_ATTRIBUTE17      => r_PFR.INFORMATION127
22184              ,P_PFR_ATTRIBUTE18      => r_PFR.INFORMATION128
22185              ,P_PFR_ATTRIBUTE19      => r_PFR.INFORMATION129
22186              ,P_PFR_ATTRIBUTE2      => r_PFR.INFORMATION112
22187              ,P_PFR_ATTRIBUTE20      => r_PFR.INFORMATION130
22188              ,P_PFR_ATTRIBUTE21      => r_PFR.INFORMATION131
22189              ,P_PFR_ATTRIBUTE22      => r_PFR.INFORMATION132
22190              ,P_PFR_ATTRIBUTE23      => r_PFR.INFORMATION133
22191              ,P_PFR_ATTRIBUTE24      => r_PFR.INFORMATION134
22192              ,P_PFR_ATTRIBUTE25      => r_PFR.INFORMATION135
22193              ,P_PFR_ATTRIBUTE26      => r_PFR.INFORMATION136
22194              ,P_PFR_ATTRIBUTE27      => r_PFR.INFORMATION137
22195              ,P_PFR_ATTRIBUTE28      => r_PFR.INFORMATION138
22196              ,P_PFR_ATTRIBUTE29      => r_PFR.INFORMATION139
22197              ,P_PFR_ATTRIBUTE3      => r_PFR.INFORMATION113
22198              ,P_PFR_ATTRIBUTE30      => r_PFR.INFORMATION140
22199              ,P_PFR_ATTRIBUTE4      => r_PFR.INFORMATION114
22200              ,P_PFR_ATTRIBUTE5      => r_PFR.INFORMATION115
22201              ,P_PFR_ATTRIBUTE6      => r_PFR.INFORMATION116
22202              ,P_PFR_ATTRIBUTE7      => r_PFR.INFORMATION117
22203              ,P_PFR_ATTRIBUTE8      => r_PFR.INFORMATION118
22204              ,P_PFR_ATTRIBUTE9      => r_PFR.INFORMATION119
22205              ,P_PFR_ATTRIBUTE_CATEGORY      => r_PFR.INFORMATION110
22206              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
22207              --
22208              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
22209              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
22210              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
22211            );
22212            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
22213            -- Update all relevent cer records with new pk_id
22214            hr_utility.set_location('Before plsql table ',222);
22215            hr_utility.set_location('new_value id '||l_pct_fl_tm_rt_id,222);
22216            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'PCT_FL_TM_RT_ID' ;
22217            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_PFR.information1 ;
22218            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_PCT_FL_TM_RT_ID ;
22219            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
22220            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PFR_unique.table_route_id;
22221            hr_utility.set_location('After plsql table ',222);
22222            --
22223            -- 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 ) ;
22224            --
22225            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
22226            --
22227          else
22228            --
22229            -- Call Update routine for the pk_id created in prev run .
22230            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
22231            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
22232            --
22233            if l_update then
22234              --
22235              l_datetrack_mode := r_PFR.datetrack_mode ;
22236              --
22237              get_dt_modes(
22238                p_effective_date        => l_process_date,
22239                p_effective_end_date    => r_PFR.information3,
22240                p_effective_start_date  => r_PFR.information2,
22241                p_dml_operation         => r_PFR.dml_operation,
22242                p_datetrack_mode        => l_datetrack_mode );
22243            --    p_update                => l_update
22244              --
22245              l_effective_date := l_process_date;
22246              l_PCT_FL_TM_RT_ID   := r_PFR.information1;
22247              l_object_version_number := r_PFR.information265;
22248              --
22249            end if;
22250            --
22251            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
22252            --
22253            IF l_update OR l_dml_operation <> 'UPDATE' THEN
22254            --UPD END
22255            hr_utility.set_location(' BEN_PCT_FL_TM_RT_F UPDATE_PCT_FULL_TIME_RATE ',30);
22256            BEN_PCT_FULL_TIME_RATE_API.UPDATE_PCT_FULL_TIME_RATE(
22257              --
22258              P_VALIDATE               => false
22259              ,P_EFFECTIVE_DATE        => l_effective_date
22260              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
22261              --
22262              ,P_EXCLD_FLAG      => r_PFR.INFORMATION11
22263              ,P_ORDR_NUM      => r_PFR.INFORMATION257
22264              ,P_PCT_FL_TM_FCTR_ID      => l_PCT_FL_TM_FCTR_ID
22265              ,P_PCT_FL_TM_RT_ID      => l_pct_fl_tm_rt_id
22266              ,P_PFR_ATTRIBUTE1      => r_PFR.INFORMATION111
22267              ,P_PFR_ATTRIBUTE10      => r_PFR.INFORMATION120
22268              ,P_PFR_ATTRIBUTE11      => r_PFR.INFORMATION121
22269              ,P_PFR_ATTRIBUTE12      => r_PFR.INFORMATION122
22270              ,P_PFR_ATTRIBUTE13      => r_PFR.INFORMATION123
22271              ,P_PFR_ATTRIBUTE14      => r_PFR.INFORMATION124
22272              ,P_PFR_ATTRIBUTE15      => r_PFR.INFORMATION125
22273              ,P_PFR_ATTRIBUTE16      => r_PFR.INFORMATION126
22274              ,P_PFR_ATTRIBUTE17      => r_PFR.INFORMATION127
22275              ,P_PFR_ATTRIBUTE18      => r_PFR.INFORMATION128
22276              ,P_PFR_ATTRIBUTE19      => r_PFR.INFORMATION129
22277              ,P_PFR_ATTRIBUTE2      => r_PFR.INFORMATION112
22278              ,P_PFR_ATTRIBUTE20      => r_PFR.INFORMATION130
22279              ,P_PFR_ATTRIBUTE21      => r_PFR.INFORMATION131
22280              ,P_PFR_ATTRIBUTE22      => r_PFR.INFORMATION132
22281              ,P_PFR_ATTRIBUTE23      => r_PFR.INFORMATION133
22282              ,P_PFR_ATTRIBUTE24      => r_PFR.INFORMATION134
22283              ,P_PFR_ATTRIBUTE25      => r_PFR.INFORMATION135
22284              ,P_PFR_ATTRIBUTE26      => r_PFR.INFORMATION136
22285              ,P_PFR_ATTRIBUTE27      => r_PFR.INFORMATION137
22286              ,P_PFR_ATTRIBUTE28      => r_PFR.INFORMATION138
22287              ,P_PFR_ATTRIBUTE29      => r_PFR.INFORMATION139
22288              ,P_PFR_ATTRIBUTE3      => r_PFR.INFORMATION113
22289              ,P_PFR_ATTRIBUTE30      => r_PFR.INFORMATION140
22290              ,P_PFR_ATTRIBUTE4      => r_PFR.INFORMATION114
22291              ,P_PFR_ATTRIBUTE5      => r_PFR.INFORMATION115
22292              ,P_PFR_ATTRIBUTE6      => r_PFR.INFORMATION116
22293              ,P_PFR_ATTRIBUTE7      => r_PFR.INFORMATION117
22294              ,P_PFR_ATTRIBUTE8      => r_PFR.INFORMATION118
22295              ,P_PFR_ATTRIBUTE9      => r_PFR.INFORMATION119
22296              ,P_PFR_ATTRIBUTE_CATEGORY      => r_PFR.INFORMATION110
22297              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
22298              --
22299              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
22300              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
22301              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
22302              ,P_DATETRACK_MODE        => l_datetrack_mode
22303            );
22304            --
22305            end if;
22306          end if;
22307          --
22308          -- Delete the row if it is end dated.
22309          --
22310          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
22311              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
22312              trunc(l_max_eed) = r_PFR.information3) then
22313              --
22314              BEN_PCT_FULL_TIME_RATE_API.delete_PCT_FULL_TIME_RATE(
22315                 --
22316                 p_validate                       => false
22317                 ,p_pct_fl_tm_rt_id                   => l_pct_fl_tm_rt_id
22318                 ,p_effective_start_date           => l_effective_start_date
22319                 ,p_effective_end_date             => l_effective_end_date
22320                 ,p_object_version_number          => l_object_version_number
22321                 ,p_effective_date                 => l_max_eed
22322                 ,p_datetrack_mode                 => hr_api.g_delete
22323                 --
22324                 );
22325                 --
22326          end if;
22327          --
22328          l_prev_pk_id := l_current_pk_id ;
22329          --
22330        end if;
22331        --
22332      end if;
22333      --
22334    end loop;
22335    --
22336  exception when others then
22337     --
22338     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'PFR',r_pfr.information5 );
22339     --
22340  end create_PFR_rows;
22341 
22342    --
22343    ---------------------------------------------------------------
22344    ----------------------< create_HWR_rows >-----------------------
22345    ---------------------------------------------------------------
22346    --
22347    procedure create_HWR_rows
22348    (
22349          p_validate                       in  number     default 0
22350         ,p_copy_entity_txn_id             in  number
22351         ,p_effective_date                 in  date
22352         ,p_prefix_suffix_text             in  varchar2  default null
22353         ,p_reuse_object_flag              in  varchar2  default null
22354         ,p_target_business_group_id       in  varchar2  default null
22355         ,p_prefix_suffix_cd               in  varchar2  default null
22356    ) is
22357    --
22358    l_HRS_WKD_IN_PERD_FCTR_ID  number;
22359    l_VRBL_RT_PRFL_ID  number;
22360    l_EXCLD_FLAG       varchar2(100);
22361    l_ORDR_NUM         number;
22362    cursor c_unique_HWR(l_table_alias varchar2) is
22363    select distinct cpe.information1,
22364      cpe.information2,
22365      cpe.information3,
22366      cpe.table_route_id
22367    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
22368         pqh_table_route tr
22369    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
22370    and   cpe.table_route_id     = tr.table_route_id
22371    -- and   tr.where_clause        = l_BEN_HRS_WKD_IN_PERD_RT_F
22372    and tr.table_alias = l_table_alias
22373    and   cpe.number_of_copies   = 1 -- ADDITION
22374    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
22375    order by information1, information2; --added for bug: 5151945
22376    --
22377    --
22378    cursor c_HWR_min_max_dates(c_table_route_id  number,
22379                 c_information1   Number) is
22380    select
22381      min(cpe.information2) min_esd,
22382      max(cpe.information3) min_eed
22383    from ben_copy_entity_results cpe
22384    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
22385    and   cpe.table_route_id     = c_table_route_id
22386    and   cpe.information1       = c_information1 ;
22387    --
22388    cursor c_HWR(c_table_route_id  number,
22389                 c_information1   number,
22390                 c_information2   Date,
22391                 c_information3   Date)  is
22392    select
22393      cpe.*
22394    from ben_copy_entity_results cpe
22395    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
22396    and   cpe.table_route_id     = c_table_route_id
22397    and   cpe.information1       = c_information1
22398    and   cpe.information2       = c_information2
22399    and   cpe.information3       = c_information3
22400    and rownum = 1 ;
22401    -- Date Track target record
22402    cursor c_find_HWR_in_target(
22403                                 c_effective_start_date    date,
22404                                 c_effective_end_date      date,
22405                                 c_business_group_id       number,
22406                                 c_new_pk_id               number) is
22407    select
22408      HWR.hrs_wkd_in_perd_rt_id new_value
22409    from BEN_HRS_WKD_IN_PERD_RT_F HWR
22410    where
22411    HWR.HRS_WKD_IN_PERD_FCTR_ID     = l_HRS_WKD_IN_PERD_FCTR_ID  and
22412    HWR.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
22413    HWR.ORDR_NUM           = l_ORDR_NUM and
22414    HWR.business_group_id  = c_business_group_id
22415    and   HWR.hrs_wkd_in_perd_rt_id  <> c_new_pk_id
22416 --TEMPIK
22417    and c_effective_start_date between effective_start_date
22418                             and effective_end_date ;
22419 --END TEMPIK
22420 /*TEMPIK
22421    and exists ( select null
22422                 from BEN_HRS_WKD_IN_PERD_RT_F HWR1
22423                 where
22424                 HWR1.HRS_WKD_IN_PERD_FCTR_ID     = l_HRS_WKD_IN_PERD_FCTR_ID  and
22425                 HWR1.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
22426                 HWR1.ORDR_NUM           = l_ORDR_NUM and
22427                 HWR1.business_group_id  = c_business_group_id
22428                 and   HWR1.effective_start_date <= c_effective_start_date )
22429    and exists ( select null
22430                 from BEN_HRS_WKD_IN_PERD_RT_F HWR2
22431                 where
22432                 HWR2.HRS_WKD_IN_PERD_FCTR_ID     = l_HRS_WKD_IN_PERD_FCTR_ID  and
22433                 HWR2.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
22434                 HWR2.ORDR_NUM           = l_ORDR_NUM and
22435                 HWR2.business_group_id  = c_business_group_id
22436                 and   HWR2.effective_end_date >= c_effective_end_date )
22437                 ;
22438 TEMPIK */
22439    --TEMPIK
22440    l_dt_rec_found            boolean ;
22441    --END TEMPIK
22442    --
22443    l_current_pk_id           number := null ;
22444    --UPD START
22445    --
22446    l_update                  boolean      := false ;
22447    l_datetrack_mode          varchar2(80) := hr_api.g_update;
22448    l_process_date            date;
22449    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
22450    --
22451    --UPD END
22452    l_prev_pk_id              number := null ;
22453    l_first_rec               boolean := true ;
22454    r_HWR                     c_HWR%rowtype;
22455    l_hrs_wkd_in_perd_rt_id             number ;
22456    l_object_version_number   number ;
22457    l_effective_start_date    date ;
22458    l_effective_end_date      date ;
22459    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
22460    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
22461    l_new_value               number(15);
22462    l_object_found_in_target  boolean := false ;
22463    l_min_esd                 date;
22464    l_max_eed                 date;
22465    l_effective_date          date;
22466    --
22467  begin
22468    -- Initialization
22469    l_object_found_in_target := false ;
22470    -- End Initialization
22471    -- Derive the prefix - sufix
22472    if   p_prefix_suffix_cd = 'PREFIX' then
22473      l_prefix  := p_prefix_suffix_text ;
22474    elsif p_prefix_suffix_cd = 'SUFFIX' then
22475      l_suffix   := p_prefix_suffix_text ;
22476    else
22477      l_prefix := null ;
22478      l_suffix  := null ;
22479    end if ;
22480    -- End Prefix Sufix derivation
22481    for r_HWR_unique in c_unique_HWR('HWR') loop
22482 
22483      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
22484         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
22485          r_HWR_unique.information3 >=
22486                  ben_pd_copy_to_ben_one.g_copy_effective_date)
22487         ) then
22488        --
22489        hr_utility.set_location(' r_HWR_unique.table_route_id '||r_HWR_unique.table_route_id,10);
22490        hr_utility.set_location(' r_HWR_unique.information1 '||r_HWR_unique.information1,10);
22491        hr_utility.set_location( 'r_HWR_unique.information2 '||r_HWR_unique.information2,10);
22492        hr_utility.set_location( 'r_HWR_unique.information3 '||r_HWR_unique.information3,10);
22493        -- If reuse objects flag is 'Y' then check for the object in the target business group
22494        -- if found insert the record into PLSql table and exit the loop else try create the
22495        -- object in the target business group
22496        --
22497        l_object_found_in_target := false ;
22498        l_min_esd := null ;
22499        l_max_eed := null ;
22500        open c_HWR_min_max_dates(r_HWR_unique.table_route_id, r_HWR_unique.information1 ) ;
22501        fetch c_HWR_min_max_dates into l_min_esd,l_max_eed ;
22502        --
22503 
22504        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
22505             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
22506          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
22507        end if;
22508        l_min_esd := greatest(l_min_esd,r_HWR_unique.information2);
22509        open c_HWR(r_HWR_unique.table_route_id,
22510                 r_HWR_unique.information1,
22511                 r_HWR_unique.information2,
22512                 r_HWR_unique.information3 ) ;
22513        --
22514        fetch c_HWR into r_HWR ;
22515        --
22516        close c_HWR ;
22517        --
22518        l_HRS_WKD_IN_PERD_FCTR_ID := get_fk('HRS_WKD_IN_PERD_FCTR_ID', r_HWR.information224,r_HWR_unique.dml_operation);
22519        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_HWR.information262,r_HWR_unique.dml_operation);
22520        l_ORDR_NUM         := r_HWR.INFORMATION260;
22521        l_EXCLD_FLAG      := r_HWR.information11;
22522        --UPD START
22523        l_update := false;
22524        l_process_date := p_effective_date;
22525        l_dml_operation:= r_HWR_unique.dml_operation ;
22526        --
22527        if l_dml_operation = 'UPDATE' then
22528          --
22529          l_object_found_in_target := TRUE;
22530          --
22531          if l_process_date between r_HWR_unique.information2 and r_HWR_unique.information3 then
22532                l_update := true;
22533                if r_HWR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
22534                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'HRS_WKD_IN_PERD_RT_ID'
22535                then
22536                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'HRS_WKD_IN_PERD_RT_ID' ;
22537                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_HWR_unique.information1 ;
22538                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_HWR_unique.information1 ;
22539                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
22540                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_HWR_unique.table_route_id;
22541                   --
22542                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
22543                   --
22544                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
22545                   --
22546                   -- log_data('HWR',l_new_value,l_prefix || r_HWR_unique.name|| l_suffix,'REUSED');
22547                   --
22548                end if ;
22549                hr_utility.set_location( 'found record for update',10);
22550            --
22551          else
22552            --
22553            l_update := false;
22554            --
22555          end if;
22556        else
22557          --
22558          --UPD END
22559        if p_reuse_object_flag = 'Y' then
22560          if c_HWR_min_max_dates%found then
22561            -- cursor to find the object
22562            open c_find_HWR_in_target( l_min_esd,l_max_eed,
22563                                  p_target_business_group_id, nvl(l_hrs_wkd_in_perd_rt_id, -999)  ) ;
22564            fetch c_find_HWR_in_target into l_new_value ;
22565            if c_find_HWR_in_target%found then
22566              --
22567              --TEMPIK
22568              l_dt_rec_found :=   dt_api.check_min_max_dates
22569                  (p_base_table_name => 'BEN_HRS_WKD_IN_PERD_RT_F',
22570                   p_base_key_column => 'HRS_WKD_IN_PERD_RT_ID',
22571                   p_base_key_value  => l_new_value,
22572                   p_from_date       => l_min_esd,
22573                   p_to_date         => l_max_eed );
22574              if l_dt_rec_found THEN
22575              --END TEMPIK
22576              if r_HWR_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
22577                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'HRS_WKD_IN_PERD_RT_ID'  then
22578                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'HRS_WKD_IN_PERD_RT_ID' ;
22579                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_HWR_unique.information1 ;
22580                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
22581                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
22582                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_HWR_unique.table_route_id;
22583                 --
22584                 -- 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) ;
22585                 --
22586                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
22587              end if ;
22588              --
22589              l_object_found_in_target := true ;
22590              --TEMPIK
22591              end if; -- l_dt_rec_found
22592              --END TEMPIK
22593            end if;
22594            close c_find_HWR_in_target ;
22595          --
22596          end if;
22597        end if ;
22598        --
22599        end if;
22600        close c_HWR_min_max_dates ;
22601        if not l_object_found_in_target OR l_update   then
22602          --
22603          l_current_pk_id := r_HWR.information1;
22604          --
22605          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
22606          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
22607          --
22608          if l_current_pk_id =  l_prev_pk_id  then
22609            --
22610            l_first_rec := false ;
22611            --
22612          else
22613            --
22614            l_first_rec := true ;
22615            --
22616          end if ;
22617          --
22618 
22619          l_effective_date := r_HWR.information2;
22620          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
22621               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
22622            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
22623          end if;
22624 
22625          if l_first_rec and not l_update then
22626            -- Call Create routine.
22627            hr_utility.set_location(' BEN_HRS_WKD_IN_PERD_RT_F CREATE_HRS_WKD_IN_PERIOD_RT ',20);
22628            BEN_HRS_WKD_IN_PERIOD_RT_API.CREATE_HRS_WKD_IN_PERIOD_RT(
22629              --
22630              P_VALIDATE               => false
22631              ,P_EFFECTIVE_DATE        => l_effective_date
22632              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
22633              --
22634              ,P_EXCLD_FLAG      => r_HWR.INFORMATION11
22635              ,P_HRS_WKD_IN_PERD_FCTR_ID      => l_HRS_WKD_IN_PERD_FCTR_ID
22636              ,P_HRS_WKD_IN_PERD_RT_ID      => l_hrs_wkd_in_perd_rt_id
22637              ,P_HWR_ATTRIBUTE1      => r_HWR.INFORMATION111
22638              ,P_HWR_ATTRIBUTE10      => r_HWR.INFORMATION120
22639              ,P_HWR_ATTRIBUTE11      => r_HWR.INFORMATION121
22640              ,P_HWR_ATTRIBUTE12      => r_HWR.INFORMATION122
22641              ,P_HWR_ATTRIBUTE13      => r_HWR.INFORMATION123
22642              ,P_HWR_ATTRIBUTE14      => r_HWR.INFORMATION124
22643              ,P_HWR_ATTRIBUTE15      => r_HWR.INFORMATION125
22644              ,P_HWR_ATTRIBUTE16      => r_HWR.INFORMATION126
22645              ,P_HWR_ATTRIBUTE17      => r_HWR.INFORMATION127
22646              ,P_HWR_ATTRIBUTE18      => r_HWR.INFORMATION128
22647              ,P_HWR_ATTRIBUTE19      => r_HWR.INFORMATION129
22648              ,P_HWR_ATTRIBUTE2      => r_HWR.INFORMATION112
22649              ,P_HWR_ATTRIBUTE20      => r_HWR.INFORMATION130
22650              ,P_HWR_ATTRIBUTE21      => r_HWR.INFORMATION131
22651              ,P_HWR_ATTRIBUTE22      => r_HWR.INFORMATION132
22652              ,P_HWR_ATTRIBUTE23      => r_HWR.INFORMATION133
22653              ,P_HWR_ATTRIBUTE24      => r_HWR.INFORMATION134
22654              ,P_HWR_ATTRIBUTE25      => r_HWR.INFORMATION135
22655              ,P_HWR_ATTRIBUTE26      => r_HWR.INFORMATION136
22656              ,P_HWR_ATTRIBUTE27      => r_HWR.INFORMATION137
22657              ,P_HWR_ATTRIBUTE28      => r_HWR.INFORMATION138
22658              ,P_HWR_ATTRIBUTE29      => r_HWR.INFORMATION139
22659              ,P_HWR_ATTRIBUTE3      => r_HWR.INFORMATION113
22660              ,P_HWR_ATTRIBUTE30      => r_HWR.INFORMATION140
22661              ,P_HWR_ATTRIBUTE4      => r_HWR.INFORMATION114
22662              ,P_HWR_ATTRIBUTE5      => r_HWR.INFORMATION115
22663              ,P_HWR_ATTRIBUTE6      => r_HWR.INFORMATION116
22664              ,P_HWR_ATTRIBUTE7      => r_HWR.INFORMATION117
22665              ,P_HWR_ATTRIBUTE8      => r_HWR.INFORMATION118
22666              ,P_HWR_ATTRIBUTE9      => r_HWR.INFORMATION119
22667              ,P_HWR_ATTRIBUTE_CATEGORY      => r_HWR.INFORMATION110
22668              ,P_ORDR_NUM      => r_HWR.INFORMATION260
22669              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
22670              --
22671              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
22672              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
22673              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
22674            );
22675            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
22676            -- Update all relevent cer records with new pk_id
22677            hr_utility.set_location('Before plsql table ',222);
22678            hr_utility.set_location('new_value id '||l_hrs_wkd_in_perd_rt_id,222);
22679            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'HRS_WKD_IN_PERD_RT_ID' ;
22680            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_HWR.information1 ;
22681            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_HRS_WKD_IN_PERD_RT_ID ;
22682            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
22683            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_HWR_unique.table_route_id;
22684            hr_utility.set_location('After plsql table ',222);
22685            --
22686            -- 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 ) ;
22687            --
22688            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
22689            --
22690          else
22691            --
22692            -- Call Update routine for the pk_id created in prev run .
22693            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
22694            --UPD START
22695            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
22696            --
22697            if l_update then
22698              --
22699              l_datetrack_mode := r_HWR.datetrack_mode ;
22700              --
22701              get_dt_modes(
22702                p_effective_date        => l_process_date,
22703                p_effective_end_date    => r_HWR.information3,
22704                p_effective_start_date  => r_HWR.information2,
22705                p_dml_operation         => r_HWR.dml_operation,
22706                p_datetrack_mode        => l_datetrack_mode );
22707            --    p_update                => l_update
22708              --
22709              l_effective_date := l_process_date;
22710              l_HRS_WKD_IN_PERD_RT_ID   := r_HWR.information1;
22711              l_object_version_number := r_HWR.information265;
22712              --
22713            end if;
22714            --
22715            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
22716            --
22717            IF l_update OR l_dml_operation <> 'UPDATE' THEN
22718            --UPD END
22719            hr_utility.set_location(' BEN_HRS_WKD_IN_PERD_RT_F UPDATE_HRS_WKD_IN_PERIOD_RT ',30);
22720            BEN_HRS_WKD_IN_PERIOD_RT_API.UPDATE_HRS_WKD_IN_PERIOD_RT(
22721              --
22722              P_VALIDATE               => false
22723              ,P_EFFECTIVE_DATE        => l_effective_date
22724              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
22725              --
22726              ,P_EXCLD_FLAG      => r_HWR.INFORMATION11
22727              ,P_HRS_WKD_IN_PERD_FCTR_ID      => l_HRS_WKD_IN_PERD_FCTR_ID
22728              ,P_HRS_WKD_IN_PERD_RT_ID      => l_hrs_wkd_in_perd_rt_id
22729              ,P_HWR_ATTRIBUTE1      => r_HWR.INFORMATION111
22730              ,P_HWR_ATTRIBUTE10      => r_HWR.INFORMATION120
22731              ,P_HWR_ATTRIBUTE11      => r_HWR.INFORMATION121
22732              ,P_HWR_ATTRIBUTE12      => r_HWR.INFORMATION122
22733              ,P_HWR_ATTRIBUTE13      => r_HWR.INFORMATION123
22734              ,P_HWR_ATTRIBUTE14      => r_HWR.INFORMATION124
22735              ,P_HWR_ATTRIBUTE15      => r_HWR.INFORMATION125
22736              ,P_HWR_ATTRIBUTE16      => r_HWR.INFORMATION126
22737              ,P_HWR_ATTRIBUTE17      => r_HWR.INFORMATION127
22738              ,P_HWR_ATTRIBUTE18      => r_HWR.INFORMATION128
22739              ,P_HWR_ATTRIBUTE19      => r_HWR.INFORMATION129
22740              ,P_HWR_ATTRIBUTE2      => r_HWR.INFORMATION112
22741              ,P_HWR_ATTRIBUTE20      => r_HWR.INFORMATION130
22742              ,P_HWR_ATTRIBUTE21      => r_HWR.INFORMATION131
22743              ,P_HWR_ATTRIBUTE22      => r_HWR.INFORMATION132
22744              ,P_HWR_ATTRIBUTE23      => r_HWR.INFORMATION133
22745              ,P_HWR_ATTRIBUTE24      => r_HWR.INFORMATION134
22746              ,P_HWR_ATTRIBUTE25      => r_HWR.INFORMATION135
22747              ,P_HWR_ATTRIBUTE26      => r_HWR.INFORMATION136
22748              ,P_HWR_ATTRIBUTE27      => r_HWR.INFORMATION137
22749              ,P_HWR_ATTRIBUTE28      => r_HWR.INFORMATION138
22750              ,P_HWR_ATTRIBUTE29      => r_HWR.INFORMATION139
22751              ,P_HWR_ATTRIBUTE3      => r_HWR.INFORMATION113
22752              ,P_HWR_ATTRIBUTE30      => r_HWR.INFORMATION140
22753              ,P_HWR_ATTRIBUTE4      => r_HWR.INFORMATION114
22754              ,P_HWR_ATTRIBUTE5      => r_HWR.INFORMATION115
22755              ,P_HWR_ATTRIBUTE6      => r_HWR.INFORMATION116
22756              ,P_HWR_ATTRIBUTE7      => r_HWR.INFORMATION117
22757              ,P_HWR_ATTRIBUTE8      => r_HWR.INFORMATION118
22758              ,P_HWR_ATTRIBUTE9      => r_HWR.INFORMATION119
22759              ,P_HWR_ATTRIBUTE_CATEGORY      => r_HWR.INFORMATION110
22760              ,P_ORDR_NUM      => r_HWR.INFORMATION260
22761              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
22762              --
22763              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
22764              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
22765              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
22766              ,P_DATETRACK_MODE        => l_datetrack_mode
22767            );
22768            --
22769            end if;
22770          end if;
22771          --
22772          -- Delete the row if it is end dated.
22773          --
22774          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
22775              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
22776              trunc(l_max_eed) = r_HWR.information3) then
22777              --
22778              BEN_HRS_WKD_IN_PERIOD_RT_API.delete_HRS_WKD_IN_PERIOD_RT(
22779                 --
22780                 p_validate                       => false
22781                 ,p_hrs_wkd_in_perd_rt_id                   => l_hrs_wkd_in_perd_rt_id
22782                 ,p_effective_start_date           => l_effective_start_date
22783                 ,p_effective_end_date             => l_effective_end_date
22784                 ,p_object_version_number          => l_object_version_number
22785                 ,p_effective_date                 => l_max_eed
22786                 ,p_datetrack_mode                 => hr_api.g_delete
22787                 --
22788                 );
22789                 --
22790          end if;
22791          --
22792          l_prev_pk_id := l_current_pk_id ;
22793          --
22794        end if;
22795        --
22796      end if;
22797      --
22798    end loop;
22799    --
22800  exception when others then
22801     --
22802     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'HWR',r_hwr.information5 );
22803     --
22804  end create_HWR_rows;
22805 
22806    --
22807    ---------------------------------------------------------------
22808    ----------------------< create_CLR_rows >-----------------------
22809    ---------------------------------------------------------------
22810    --
22811    procedure create_CLR_rows
22812    (
22813          p_validate                       in  number     default 0
22814         ,p_copy_entity_txn_id             in  number
22815         ,p_effective_date                 in  date
22816         ,p_prefix_suffix_text             in  varchar2  default null
22817         ,p_reuse_object_flag              in  varchar2  default null
22818         ,p_target_business_group_id       in  varchar2  default null
22819         ,p_prefix_suffix_cd               in  varchar2  default null
22820    ) is
22821    --
22822    l_COMP_LVL_FCTR_ID  number;
22823    l_VRBL_RT_PRFL_ID  number;
22824    l_EXCLD_FLAG       varchar2(100);
22825    l_ORDR_NUM         number;
22826    cursor c_unique_CLR(l_table_alias varchar2) is
22827    select distinct cpe.information1,
22828      cpe.information2,
22829      cpe.information3,
22830      cpe.table_route_id
22831    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
22832         pqh_table_route tr
22833    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
22834    and   cpe.table_route_id     = tr.table_route_id
22835    -- and   tr.where_clause        = l_BEN_COMP_LVL_RT_F
22836    and tr.table_alias = l_table_alias
22837    and   cpe.number_of_copies   = 1 -- ADDITION
22838    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
22839    order by information1, information2; --added for bug: 5151945
22840    --
22841    --
22842    cursor c_CLR_min_max_dates(c_table_route_id  number,
22843                 c_information1   number) is
22844    select
22845      min(cpe.information2) min_esd,
22846      max(cpe.information3) min_eed
22847    from ben_copy_entity_results cpe
22848    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
22849    and   cpe.table_route_id     = c_table_route_id
22850    and   cpe.information1       = c_information1 ;
22851    --
22852    cursor c_CLR(c_table_route_id  number,
22853                 c_information1   number,
22854                 c_information2   Date,
22855                 c_information3   Date)  is
22856    select
22857      cpe.*
22858    from ben_copy_entity_results cpe
22859    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
22860    and   cpe.table_route_id     = c_table_route_id
22861    and   cpe.information1       = c_information1
22862    and   cpe.information2       = c_information2
22863    and   cpe.information3       = c_information3
22864    and rownum = 1 ;
22865    -- Date Track target record
22866    cursor c_find_CLR_in_target(
22867                                 c_effective_start_date    date,
22868                                 c_effective_end_date      date,
22869                                 c_business_group_id       number,
22870                                 c_new_pk_id               number) is
22871    select
22872      CLR.comp_lvl_rt_id new_value
22873    from BEN_COMP_LVL_RT_F CLR
22874    where
22875    CLR.COMP_LVL_FCTR_ID   = l_COMP_LVL_FCTR_ID  and
22876    CLR.VRBL_RT_PRFL_ID    = l_VRBL_RT_PRFL_ID and
22877    CLR.ORDR_NUM           = l_ORDR_NUM and
22878    CLR.business_group_id  = c_business_group_id
22879    and   CLR.comp_lvl_rt_id  <> c_new_pk_id
22880 --TEMPIK
22881    and c_effective_start_date between effective_start_date
22882                             and effective_end_date ;
22883 --END TEMPIK
22884 /*TEMPIK
22885    and exists ( select null
22886                 from BEN_COMP_LVL_RT_F CLR1
22887                 where
22888                 CLR1.COMP_LVL_FCTR_ID     = l_COMP_LVL_FCTR_ID  and
22889                 CLR1.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
22890                 CLR1.ORDR_NUM           = l_ORDR_NUM and
22891                 CLR1.business_group_id  = c_business_group_id
22892                 and   CLR1.effective_start_date <= c_effective_start_date )
22893    and exists ( select null
22894                 from BEN_COMP_LVL_RT_F CLR2
22895                 where
22896                 CLR2.COMP_LVL_FCTR_ID     = l_COMP_LVL_FCTR_ID  and
22897                 CLR2.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
22898                 CLR2.ORDR_NUM           = l_ORDR_NUM and
22899                 CLR2.business_group_id  = c_business_group_id
22900                 and   CLR2.effective_end_date >= c_effective_end_date )
22901                 ;
22902 TEMPIK */
22903    --TEMPIK
22904    l_dt_rec_found            boolean ;
22905    --END TEMPIK
22906    --
22907    l_current_pk_id           number := null ;
22908    --UPD START
22909    --
22910    l_update                  boolean      := false ;
22911    l_datetrack_mode          varchar2(80) := hr_api.g_update;
22912    l_process_date            date;
22913    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
22914    --
22915    --UPD END
22916    l_prev_pk_id              number := null ;
22917    l_first_rec               boolean := true ;
22918    r_CLR                     c_CLR%rowtype;
22919    l_comp_lvl_rt_id             number ;
22920    l_object_version_number   number ;
22921    l_effective_start_date    date ;
22922    l_effective_end_date      date ;
22923    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
22924    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
22925    l_new_value               number(15);
22926    l_object_found_in_target  boolean := false ;
22927    l_min_esd                 date;
22928    l_max_eed                 date;
22929    l_effective_date          date;
22930    --
22931  begin
22932    -- Initialization
22933    l_object_found_in_target := false ;
22934    -- End Initialization
22935    -- Derive the prefix - sufix
22936    if   p_prefix_suffix_cd = 'PREFIX' then
22937      l_prefix  := p_prefix_suffix_text ;
22938    elsif p_prefix_suffix_cd = 'SUFFIX' then
22939      l_suffix   := p_prefix_suffix_text ;
22940    else
22941      l_prefix := null ;
22942      l_suffix  := null ;
22943    end if ;
22944    -- End Prefix Sufix derivation
22945    for r_CLR_unique in c_unique_CLR('CLR') loop
22946 
22947      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
22948         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
22949          r_CLR_unique.information3 >=
22950                  ben_pd_copy_to_ben_one.g_copy_effective_date)
22951         ) then
22952        --
22953        hr_utility.set_location(' r_CLR_unique.table_route_id '||r_CLR_unique.table_route_id,10);
22954        hr_utility.set_location(' r_CLR_unique.information1 '||r_CLR_unique.information1,10);
22955        hr_utility.set_location( 'r_CLR_unique.information2 '||r_CLR_unique.information2,10);
22956        hr_utility.set_location( 'r_CLR_unique.information3 '||r_CLR_unique.information3,10);
22957        -- If reuse objects flag is 'Y' then check for the object in the target business group
22958        -- if found insert the record into PLSql table and exit the loop else try create the
22959        -- object in the target business group
22960        --
22961        l_object_found_in_target := false ;
22962        l_min_esd := null ;
22963        l_max_eed := null ;
22964        open c_CLR_min_max_dates(r_CLR_unique.table_route_id, r_CLR_unique.information1 ) ;
22965        fetch c_CLR_min_max_dates into l_min_esd,l_max_eed ;
22966        --
22967 
22968        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
22969             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
22970          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
22971        end if;
22972        l_min_esd := greatest(l_min_esd,r_CLR_unique.information2);
22973        open c_CLR(r_CLR_unique.table_route_id,
22974                 r_CLR_unique.information1,
22975                 r_CLR_unique.information2,
22976                 r_CLR_unique.information3 ) ;
22977        --
22978        fetch c_CLR into r_CLR ;
22979        --
22980        close c_CLR ;
22981        --
22982        l_COMP_LVL_FCTR_ID := get_fk('COMP_LVL_FCTR_ID', r_CLR.information254,r_CLR_unique.dml_operation);
22983        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_CLR.information262,r_CLR_unique.dml_operation);
22984        l_ORDR_NUM         := r_CLR.INFORMATION260;
22985        l_EXCLD_FLAG      := r_CLR.information11;
22986        --
22987        --UPD START
22988        l_update := false;
22989        l_process_date := p_effective_date;
22990        l_dml_operation:= r_CLR_unique.dml_operation ;
22991        --
22992        if l_dml_operation = 'UPDATE' then
22993          --
22994          l_object_found_in_target := TRUE;
22995          --
22996          if l_process_date between r_CLR_unique.information2 and r_CLR_unique.information3 then
22997                l_update := true;
22998                if r_CLR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
22999                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'COMP_LVL_RT_ID'
23000                then
23001                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'COMP_LVL_RT_ID' ;
23002                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_CLR_unique.information1 ;
23003                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_CLR_unique.information1 ;
23004                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
23005                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_CLR_unique.table_route_id;
23006                   --
23007                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
23008                   --
23009                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
23010                   --
23011                   -- log_data('CLR',l_new_value,l_prefix || r_CLR_unique.name|| l_suffix,'REUSED');
23012                   --
23013                end if ;
23014                hr_utility.set_location( 'found record for update',10);
23015            --
23016          else
23017            --
23018            l_update := false;
23019            --
23020          end if;
23021        else
23022          --
23023          --UPD END
23024        if p_reuse_object_flag = 'Y' then
23025          if c_CLR_min_max_dates%found then
23026            -- cursor to find the object
23027            open c_find_CLR_in_target( l_min_esd,l_max_eed,
23028                                  p_target_business_group_id, nvl(l_comp_lvl_rt_id, -999)  ) ;
23029            fetch c_find_CLR_in_target into l_new_value ;
23030            if c_find_CLR_in_target%found then
23031              --
23032              --TEMPIK
23033              l_dt_rec_found :=   dt_api.check_min_max_dates
23034                  (p_base_table_name => 'BEN_COMP_LVL_RT_F',
23035                   p_base_key_column => 'COMP_LVL_RT_ID',
23036                   p_base_key_value  => l_new_value,
23037                   p_from_date       => l_min_esd,
23038                   p_to_date         => l_max_eed );
23039              if l_dt_rec_found THEN
23040              --END TEMPIK
23041              if r_CLR_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
23042                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'COMP_LVL_RT_ID'  then
23043                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'COMP_LVL_RT_ID' ;
23044                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_CLR_unique.information1 ;
23045                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
23046                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
23047                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_CLR_unique.table_route_id;
23048                 --
23049                 -- 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) ;
23050                 --
23051                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
23052              end if ;
23053              --
23054              l_object_found_in_target := true ;
23055              --TEMPIK
23056              end if; -- l_dt_rec_found
23057              --END TEMPIK
23058            end if;
23059            close c_find_CLR_in_target ;
23060          --
23061          end if;
23062        end if ;
23063        --
23064        end if;
23065        close c_CLR_min_max_dates ;
23066        if not l_object_found_in_target OR l_update   then
23067          --
23068          l_current_pk_id := r_CLR.information1;
23069          --
23070          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
23071          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
23072          --
23073          if l_current_pk_id =  l_prev_pk_id  then
23074            --
23075            l_first_rec := false ;
23076            --
23077          else
23078            --
23079            l_first_rec := true ;
23080            --
23081          end if ;
23082          --
23083 
23084          l_effective_date := r_CLR.information2;
23085          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
23086               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
23087            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
23088          end if;
23089 
23090          if l_first_rec and not l_update then
23091            -- Call Create routine.
23092            hr_utility.set_location(' BEN_COMP_LVL_RT_F CREATE_COMP_LEVEL_RATE ',20);
23093            BEN_COMP_LEVEL_RATE_API.CREATE_COMP_LEVEL_RATE(
23094              --
23095              P_VALIDATE               => false
23096              ,P_EFFECTIVE_DATE        => l_effective_date
23097              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
23098              --
23099              ,P_CLR_ATTRIBUTE1      => r_CLR.INFORMATION111
23100              ,P_CLR_ATTRIBUTE10      => r_CLR.INFORMATION120
23101              ,P_CLR_ATTRIBUTE11      => r_CLR.INFORMATION121
23102              ,P_CLR_ATTRIBUTE12      => r_CLR.INFORMATION122
23103              ,P_CLR_ATTRIBUTE13      => r_CLR.INFORMATION123
23104              ,P_CLR_ATTRIBUTE14      => r_CLR.INFORMATION124
23105              ,P_CLR_ATTRIBUTE15      => r_CLR.INFORMATION125
23106              ,P_CLR_ATTRIBUTE16      => r_CLR.INFORMATION126
23107              ,P_CLR_ATTRIBUTE17      => r_CLR.INFORMATION127
23108              ,P_CLR_ATTRIBUTE18      => r_CLR.INFORMATION128
23109              ,P_CLR_ATTRIBUTE19      => r_CLR.INFORMATION129
23110              ,P_CLR_ATTRIBUTE2      => r_CLR.INFORMATION112
23111              ,P_CLR_ATTRIBUTE20      => r_CLR.INFORMATION130
23112              ,P_CLR_ATTRIBUTE21      => r_CLR.INFORMATION131
23113              ,P_CLR_ATTRIBUTE22      => r_CLR.INFORMATION132
23114              ,P_CLR_ATTRIBUTE23      => r_CLR.INFORMATION133
23115              ,P_CLR_ATTRIBUTE24      => r_CLR.INFORMATION134
23116              ,P_CLR_ATTRIBUTE25      => r_CLR.INFORMATION135
23117              ,P_CLR_ATTRIBUTE26      => r_CLR.INFORMATION136
23118              ,P_CLR_ATTRIBUTE27      => r_CLR.INFORMATION137
23119              ,P_CLR_ATTRIBUTE28      => r_CLR.INFORMATION138
23120              ,P_CLR_ATTRIBUTE29      => r_CLR.INFORMATION139
23121              ,P_CLR_ATTRIBUTE3      => r_CLR.INFORMATION113
23122              ,P_CLR_ATTRIBUTE30      => r_CLR.INFORMATION140
23123              ,P_CLR_ATTRIBUTE4      => r_CLR.INFORMATION114
23124              ,P_CLR_ATTRIBUTE5      => r_CLR.INFORMATION115
23125              ,P_CLR_ATTRIBUTE6      => r_CLR.INFORMATION116
23126              ,P_CLR_ATTRIBUTE7      => r_CLR.INFORMATION117
23127              ,P_CLR_ATTRIBUTE8      => r_CLR.INFORMATION118
23128              ,P_CLR_ATTRIBUTE9      => r_CLR.INFORMATION119
23129              ,P_CLR_ATTRIBUTE_CATEGORY      => r_CLR.INFORMATION110
23130              ,P_COMP_LVL_FCTR_ID      => l_COMP_LVL_FCTR_ID
23131              ,P_COMP_LVL_RT_ID      => l_comp_lvl_rt_id
23132              ,P_EXCLD_FLAG      => r_CLR.INFORMATION11
23133              ,P_ORDR_NUM      => r_CLR.INFORMATION260
23134              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
23135              --
23136              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
23137              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
23138              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
23139            );
23140            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
23141            -- Update all relevent cer records with new pk_id
23142            hr_utility.set_location('Before plsql table ',222);
23143            hr_utility.set_location('new_value id '||l_comp_lvl_rt_id,222);
23144            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'COMP_LVL_RT_ID' ;
23145            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_CLR.information1 ;
23146            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_COMP_LVL_RT_ID ;
23147            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
23148            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_CLR_unique.table_route_id;
23149            hr_utility.set_location('After plsql table ',222);
23150            --
23151            -- 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 ) ;
23152            --
23153            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
23154            --
23155          else
23156            --
23157            -- Call Update routine for the pk_id created in prev run .
23158            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
23159            --UPD START
23160            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
23161            --
23162            if l_update then
23163              --
23164              l_datetrack_mode := r_CLR.datetrack_mode ;
23165              --
23166              get_dt_modes(
23167                p_effective_date        => l_process_date,
23168                p_effective_end_date    => r_CLR.information3,
23169                p_effective_start_date  => r_CLR.information2,
23170                p_dml_operation         => r_CLR.dml_operation,
23171                p_datetrack_mode        => l_datetrack_mode );
23172            --    p_update                => l_update
23173              --
23174              l_effective_date := l_process_date;
23175              l_COMP_LVL_RT_ID   := r_CLR.information1;
23176              l_object_version_number := r_CLR.information265;
23177              --
23178            end if;
23179            --
23180            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
23181            --
23182            IF l_update OR l_dml_operation <> 'UPDATE' THEN
23183            --UPD END
23184            hr_utility.set_location(' BEN_COMP_LVL_RT_F UPDATE_COMP_LEVEL_RATE ',30);
23185            BEN_COMP_LEVEL_RATE_API.UPDATE_COMP_LEVEL_RATE(
23186              --
23187              P_VALIDATE               => false
23188              ,P_EFFECTIVE_DATE        => l_effective_date
23189              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
23190              --
23191             ,P_CLR_ATTRIBUTE1      => r_CLR.INFORMATION111
23192              ,P_CLR_ATTRIBUTE10      => r_CLR.INFORMATION120
23193              ,P_CLR_ATTRIBUTE11      => r_CLR.INFORMATION121
23194              ,P_CLR_ATTRIBUTE12      => r_CLR.INFORMATION122
23195              ,P_CLR_ATTRIBUTE13      => r_CLR.INFORMATION123
23196              ,P_CLR_ATTRIBUTE14      => r_CLR.INFORMATION124
23197              ,P_CLR_ATTRIBUTE15      => r_CLR.INFORMATION125
23198              ,P_CLR_ATTRIBUTE16      => r_CLR.INFORMATION126
23199              ,P_CLR_ATTRIBUTE17      => r_CLR.INFORMATION127
23200              ,P_CLR_ATTRIBUTE18      => r_CLR.INFORMATION128
23201              ,P_CLR_ATTRIBUTE19      => r_CLR.INFORMATION129
23202              ,P_CLR_ATTRIBUTE2      => r_CLR.INFORMATION112
23203              ,P_CLR_ATTRIBUTE20      => r_CLR.INFORMATION130
23204              ,P_CLR_ATTRIBUTE21      => r_CLR.INFORMATION131
23205              ,P_CLR_ATTRIBUTE22      => r_CLR.INFORMATION132
23206              ,P_CLR_ATTRIBUTE23      => r_CLR.INFORMATION133
23207              ,P_CLR_ATTRIBUTE24      => r_CLR.INFORMATION134
23208              ,P_CLR_ATTRIBUTE25      => r_CLR.INFORMATION135
23209              ,P_CLR_ATTRIBUTE26      => r_CLR.INFORMATION136
23210              ,P_CLR_ATTRIBUTE27      => r_CLR.INFORMATION137
23211              ,P_CLR_ATTRIBUTE28      => r_CLR.INFORMATION138
23212              ,P_CLR_ATTRIBUTE29      => r_CLR.INFORMATION139
23213              ,P_CLR_ATTRIBUTE3      => r_CLR.INFORMATION113
23214              ,P_CLR_ATTRIBUTE30      => r_CLR.INFORMATION140
23215              ,P_CLR_ATTRIBUTE4      => r_CLR.INFORMATION114
23216              ,P_CLR_ATTRIBUTE5      => r_CLR.INFORMATION115
23217              ,P_CLR_ATTRIBUTE6      => r_CLR.INFORMATION116
23218              ,P_CLR_ATTRIBUTE7      => r_CLR.INFORMATION117
23219              ,P_CLR_ATTRIBUTE8      => r_CLR.INFORMATION118
23220              ,P_CLR_ATTRIBUTE9      => r_CLR.INFORMATION119
23221              ,P_CLR_ATTRIBUTE_CATEGORY      => r_CLR.INFORMATION110
23222              ,P_COMP_LVL_FCTR_ID      => l_COMP_LVL_FCTR_ID
23223              ,P_COMP_LVL_RT_ID      => l_comp_lvl_rt_id
23224              ,P_EXCLD_FLAG      => r_CLR.INFORMATION11
23225              ,P_ORDR_NUM      => r_CLR.INFORMATION260
23226              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
23227              --
23228              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
23229              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
23230              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
23231              ,P_DATETRACK_MODE        => l_datetrack_mode
23232            );
23233            --
23234            end if;
23235          end if;
23236          --
23237          -- Delete the row if it is end dated.
23238          --
23239          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
23240              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
23241              trunc(l_max_eed) = r_CLR.information3) then
23242              --
23243              BEN_COMP_LEVEL_RATE_API.delete_COMP_LEVEL_RATE(
23244                 --
23245                 p_validate                       => false
23246                 ,p_comp_lvl_rt_id                   => l_comp_lvl_rt_id
23247                 ,p_effective_start_date           => l_effective_start_date
23248                 ,p_effective_end_date             => l_effective_end_date
23249                 ,p_object_version_number          => l_object_version_number
23250                 ,p_effective_date                 => l_max_eed
23251                 ,p_datetrack_mode                 => hr_api.g_delete
23252                 --
23253                 );
23254                 --
23255          end if;
23256          --
23257          l_prev_pk_id := l_current_pk_id ;
23258          --
23259        end if;
23260        --
23261      end if;
23262      --
23263    end loop;
23264    --
23265  exception when others then
23266     --
23267     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'CLR',r_clr.information5 );
23268     --
23269  end create_CLR_rows;
23270 
23271    ---------------------------------------------------------------
23272    ----------------------< create_LSR_rows >-----------------------
23273    ---------------------------------------------------------------
23274    --
23275    procedure create_LSR_rows
23276    (
23277          p_validate                       in  number     default 0
23278         ,p_copy_entity_txn_id             in  number
23279         ,p_effective_date                 in  date
23280         ,p_prefix_suffix_text             in  varchar2  default null
23281         ,p_reuse_object_flag              in  varchar2  default null
23282         ,p_target_business_group_id       in  varchar2  default null
23283         ,p_prefix_suffix_cd               in  varchar2  default null
23284    ) is
23285    --
23286    l_LOS_FCTR_ID  number;
23287    l_VRBL_RT_PRFL_ID  number;
23288    cursor c_unique_LSR(l_table_alias varchar2) is
23289    select distinct cpe.information1,
23290      cpe.information2,
23291      cpe.information3,
23292      cpe.table_route_id
23293    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
23294         pqh_table_route tr
23295    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
23296    and   cpe.table_route_id     = tr.table_route_id
23297    -- and   tr.where_clause        = l_BEN_LOS_RT_F
23298    and tr.table_alias = l_table_alias
23299    and   cpe.number_of_copies   = 1 -- ADDITION
23300    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
23301    order by information1, information2; --added for bug: 5151945
23302    --
23303    --
23304    cursor c_LSR_min_max_dates(c_table_route_id  number,
23305                 c_information1   number) is
23306    select
23307      min(cpe.information2) min_esd,
23308      max(cpe.information3) min_eed
23309    from ben_copy_entity_results cpe
23310    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
23311    and   cpe.table_route_id     = c_table_route_id
23312    and   cpe.information1       = c_information1 ;
23313    --
23314    cursor c_LSR(c_table_route_id  number,
23315                 c_information1   number,
23316                 c_information2   Date,
23317                 c_information3   Date)  is
23318    select
23319      cpe.*
23320    from ben_copy_entity_results cpe
23321    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
23322    and   cpe.table_route_id     = c_table_route_id
23323    and   cpe.information1       = c_information1
23324    and   cpe.information2       = c_information2
23325    and   cpe.information3       = c_information3
23326    and rownum = 1 ;
23327    -- Date Track target record
23328    cursor c_find_LSR_in_target(
23329                                 c_effective_start_date    date,
23330                                 c_effective_end_date      date,
23331                                 c_business_group_id       number,
23332                                 c_new_pk_id               number) is
23333    select
23334      LSR.los_rt_id new_value
23335    from BEN_LOS_RT_F LSR
23336    where
23337    LSR.LOS_FCTR_ID     = l_LOS_FCTR_ID  and
23338    LSR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
23339    LSR.business_group_id  = c_business_group_id
23340    and   LSR.los_rt_id  <> c_new_pk_id
23341 --TEMPIK
23342    and c_effective_start_date between effective_start_date
23343                             and effective_end_date ;
23344 --END TEMPIK
23345 /*TEMPIK
23346    and exists ( select null
23347                 from BEN_LOS_RT_F LSR1
23348                 where
23349                 LSR1.LOS_FCTR_ID     = l_LOS_FCTR_ID  and
23350                 LSR1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
23351                 LSR1.business_group_id  = c_business_group_id
23352                 and   LSR1.effective_start_date <= c_effective_start_date )
23353    and exists ( select null
23354                 from BEN_LOS_RT_F LSR2
23355                 where
23356                 LSR2.LOS_FCTR_ID     = l_LOS_FCTR_ID  and
23357                 LSR2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
23358                 LSR2.business_group_id  = c_business_group_id
23359                 and   LSR2.effective_end_date >= c_effective_end_date )
23360                 ;
23361 TEMPIK */
23362    --TEMPIK
23363    l_dt_rec_found            boolean ;
23364    --END TEMPIK
23365    --
23366    l_current_pk_id           number := null ;
23367    --UPD START
23368    --
23369    l_update                  boolean      := false ;
23370    l_datetrack_mode          varchar2(80) := hr_api.g_update;
23371    l_process_date            date;
23372    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
23373    --
23374    --UPD END
23375    l_prev_pk_id              number := null ;
23376    l_first_rec               boolean := true ;
23377    r_LSR                     c_LSR%rowtype;
23378    l_los_rt_id             number ;
23379    l_object_version_number   number ;
23380    l_effective_start_date    date ;
23381    l_effective_end_date      date ;
23382    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
23383    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
23384    l_new_value               number(15);
23385    l_object_found_in_target  boolean := false ;
23386    l_min_esd                 date;
23387    l_max_eed                 date;
23388    l_effective_date          date;
23389    --
23390  begin
23391    -- Initialization
23392    l_object_found_in_target := false ;
23393    -- End Initialization
23394    -- Derive the prefix - sufix
23395    if   p_prefix_suffix_cd = 'PREFIX' then
23396      l_prefix  := p_prefix_suffix_text ;
23397    elsif p_prefix_suffix_cd = 'SUFFIX' then
23398      l_suffix   := p_prefix_suffix_text ;
23399    else
23400      l_prefix := null ;
23401      l_suffix  := null ;
23402    end if ;
23403    -- End Prefix Sufix derivation
23404    for r_LSR_unique in c_unique_LSR('LSR') loop
23405 
23406      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
23407         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
23408          r_LSR_unique.information3 >=
23409                  ben_pd_copy_to_ben_one.g_copy_effective_date)
23410         ) then
23411        --
23412        hr_utility.set_location(' r_LSR_unique.table_route_id '||r_LSR_unique.table_route_id,10);
23413        hr_utility.set_location(' r_LSR_unique.information1 '||r_LSR_unique.information1,10);
23414        hr_utility.set_location( 'r_LSR_unique.information2 '||r_LSR_unique.information2,10);
23415        hr_utility.set_location( 'r_LSR_unique.information3 '||r_LSR_unique.information3,10);
23416        -- If reuse objects flag is 'Y' then check for the object in the target business group
23417        -- if found insert the record into PLSql table and exit the loop else try create the
23418        -- object in the target business group
23419        --
23420        l_object_found_in_target := false ;
23421        l_min_esd := null ;
23422        l_max_eed := null ;
23423        open c_LSR_min_max_dates(r_LSR_unique.table_route_id, r_LSR_unique.information1 ) ;
23424        fetch c_LSR_min_max_dates into l_min_esd,l_max_eed ;
23425        --
23426 
23427        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
23428             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
23429          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
23430        end if;
23431        l_min_esd := greatest(l_min_esd,r_LSR_unique.information2);
23432        open c_LSR(r_LSR_unique.table_route_id,
23433                 r_LSR_unique.information1,
23434                 r_LSR_unique.information2,
23435                 r_LSR_unique.information3 ) ;
23436        --
23437        fetch c_LSR into r_LSR ;
23438        --
23439        close c_LSR ;
23440        --
23441        l_LOS_FCTR_ID := get_fk('LOS_FCTR_ID', r_LSR.information243,r_LSR_unique.dml_operation);
23442        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_LSR.information262,r_LSR_unique.dml_operation);
23443        --UPD START
23444        l_update := false;
23445        l_process_date := p_effective_date;
23446        l_dml_operation:= r_LSR_unique.dml_operation ;
23447        --
23448        if l_dml_operation = 'UPDATE' then
23449          --
23450          l_object_found_in_target := TRUE;
23451          --
23452          if l_process_date between r_LSR_unique.information2 and r_LSR_unique.information3 then
23453                l_update := true;
23454                if r_LSR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
23455                  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'
23456                then
23457                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'VRBL_RT_PRFL_ID' ;
23458                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_LSR_unique.information1 ;
23459                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_LSR_unique.information1 ;
23460                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
23461                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_LSR_unique.table_route_id;
23462                   --
23463                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
23464                   --
23465                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
23466                   --
23467                   -- log_data('LSR',l_new_value,l_prefix || r_LSR_unique.name|| l_suffix,'REUSED');
23468                   --
23469                end if ;
23470                hr_utility.set_location( 'found record for update',10);
23471            --
23472          else
23473            --
23474            l_update := false;
23475            --
23476          end if;
23477        else
23478          --
23479          --UPD END
23480        if p_reuse_object_flag = 'Y' then
23481          if c_LSR_min_max_dates%found then
23482            -- cursor to find the object
23483            open c_find_LSR_in_target( l_min_esd,l_max_eed,
23484                                  p_target_business_group_id, nvl(l_los_rt_id, -999)  ) ;
23485            fetch c_find_LSR_in_target into l_new_value ;
23486            if c_find_LSR_in_target%found then
23487              --
23488              --TEMPIK
23489              l_dt_rec_found :=   dt_api.check_min_max_dates
23490                  (p_base_table_name => 'BEN_LOS_RT_F',
23491                   p_base_key_column => 'LOS_RT_ID',
23492                   p_base_key_value  => l_new_value,
23493                   p_from_date       => l_min_esd,
23494                   p_to_date         => l_max_eed );
23495              if l_dt_rec_found THEN
23496              --END TEMPIK
23497              if r_LSR_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
23498                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'LOS_RT_ID'  then
23499                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'LOS_RT_ID' ;
23500                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_LSR_unique.information1 ;
23501                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
23502                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
23503                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_LSR_unique.table_route_id;
23504                 --
23505                 -- 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) ;
23506                 --
23507                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
23508              end if ;
23509              --
23510              l_object_found_in_target := true ;
23511              --TEMPIK
23512              end if; -- l_dt_rec_found
23513              --END TEMPIK
23514            end if;
23515            close c_find_LSR_in_target ;
23516          --
23517          end if;
23518        end if ;
23519        --
23520        end if;
23521        close c_LSR_min_max_dates ;
23522        if not l_object_found_in_target OR l_update   then
23523          --
23524          l_current_pk_id := r_LSR.information1;
23525          --
23526          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
23527          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
23528          --
23529          if l_current_pk_id =  l_prev_pk_id  then
23530            --
23531            l_first_rec := false ;
23532            --
23533          else
23534            --
23535            l_first_rec := true ;
23536            --
23537          end if ;
23538          --
23539 
23540          l_effective_date := r_LSR.information2;
23541          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
23542               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
23543            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
23544          end if;
23545 
23546          if l_first_rec and not l_update then
23547            -- Call Create routine.
23548            hr_utility.set_location(' BEN_LOS_RT_F CREATE_LENGTH_OF_SVC_RATE ',20);
23549            BEN_LENGTH_OF_SVC_RATE_API.CREATE_LENGTH_OF_SVC_RATE(
23550              --
23551              P_VALIDATE               => false
23552              ,P_EFFECTIVE_DATE        => l_effective_date
23553              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
23554              --
23555              ,P_EXCLD_FLAG      => r_LSR.INFORMATION11
23556              ,P_LOS_FCTR_ID      => l_LOS_FCTR_ID
23557              ,P_LOS_RT_ID      => l_los_rt_id
23558              ,P_LSR_ATTRIBUTE1      => r_LSR.INFORMATION111
23559              ,P_LSR_ATTRIBUTE10      => r_LSR.INFORMATION120
23560              ,P_LSR_ATTRIBUTE11      => r_LSR.INFORMATION121
23561              ,P_LSR_ATTRIBUTE12      => r_LSR.INFORMATION122
23562              ,P_LSR_ATTRIBUTE13      => r_LSR.INFORMATION123
23563              ,P_LSR_ATTRIBUTE14      => r_LSR.INFORMATION124
23564              ,P_LSR_ATTRIBUTE15      => r_LSR.INFORMATION125
23565              ,P_LSR_ATTRIBUTE16      => r_LSR.INFORMATION126
23566              ,P_LSR_ATTRIBUTE17      => r_LSR.INFORMATION127
23567              ,P_LSR_ATTRIBUTE18      => r_LSR.INFORMATION128
23568              ,P_LSR_ATTRIBUTE19      => r_LSR.INFORMATION129
23569              ,P_LSR_ATTRIBUTE2      => r_LSR.INFORMATION112
23570              ,P_LSR_ATTRIBUTE20      => r_LSR.INFORMATION130
23571              ,P_LSR_ATTRIBUTE21      => r_LSR.INFORMATION131
23572              ,P_LSR_ATTRIBUTE22      => r_LSR.INFORMATION132
23573              ,P_LSR_ATTRIBUTE23      => r_LSR.INFORMATION133
23574              ,P_LSR_ATTRIBUTE24      => r_LSR.INFORMATION134
23575              ,P_LSR_ATTRIBUTE25      => r_LSR.INFORMATION135
23576              ,P_LSR_ATTRIBUTE26      => r_LSR.INFORMATION136
23577              ,P_LSR_ATTRIBUTE27      => r_LSR.INFORMATION137
23578              ,P_LSR_ATTRIBUTE28      => r_LSR.INFORMATION138
23579              ,P_LSR_ATTRIBUTE29      => r_LSR.INFORMATION139
23580              ,P_LSR_ATTRIBUTE3      => r_LSR.INFORMATION113
23581              ,P_LSR_ATTRIBUTE30      => r_LSR.INFORMATION140
23582              ,P_LSR_ATTRIBUTE4      => r_LSR.INFORMATION114
23583              ,P_LSR_ATTRIBUTE5      => r_LSR.INFORMATION115
23584              ,P_LSR_ATTRIBUTE6      => r_LSR.INFORMATION116
23585              ,P_LSR_ATTRIBUTE7      => r_LSR.INFORMATION117
23586              ,P_LSR_ATTRIBUTE8      => r_LSR.INFORMATION118
23587              ,P_LSR_ATTRIBUTE9      => r_LSR.INFORMATION119
23588              ,P_LSR_ATTRIBUTE_CATEGORY      => r_LSR.INFORMATION110
23589              ,P_ORDR_NUM      => r_LSR.INFORMATION260
23590              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
23591              --
23592              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
23593              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
23594              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
23595            );
23596            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
23597            -- Update all relevent cer records with new pk_id
23598            hr_utility.set_location('Before plsql table ',222);
23599            hr_utility.set_location('new_value id '||l_los_rt_id,222);
23600            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'LOS_RT_ID' ;
23601            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_LSR.information1 ;
23602            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_LOS_RT_ID ;
23603            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
23604            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_LSR_unique.table_route_id;
23605            hr_utility.set_location('After plsql table ',222);
23606            --
23607            -- 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 ) ;
23608            --
23609            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
23610            --
23611          else
23612            --
23613            -- Call Update routine for the pk_id created in prev run .
23614            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
23615            --UPD START
23616            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
23617            --
23618            if l_update then
23619              --
23620              l_datetrack_mode := r_LSR.datetrack_mode ;
23621              --
23622              get_dt_modes(
23623                p_effective_date        => l_process_date,
23624                p_effective_end_date    => r_LSR.information3,
23625                p_effective_start_date  => r_LSR.information2,
23626                p_dml_operation         => r_LSR.dml_operation,
23627                p_datetrack_mode        => l_datetrack_mode );
23628            --    p_update                => l_update
23629              --
23630              l_effective_date := l_process_date;
23631              l_VRBL_RT_PRFL_ID   := r_LSR.information1;
23632              l_object_version_number := r_LSR.information265;
23633              --
23634            end if;
23635            --
23636            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
23637            --
23638            IF l_update OR l_dml_operation <> 'UPDATE' THEN
23639            --UPD END
23640            hr_utility.set_location(' BEN_LOS_RT_F UPDATE_LENGTH_OF_SVC_RATE ',30);
23641            BEN_LENGTH_OF_SVC_RATE_API.UPDATE_LENGTH_OF_SVC_RATE(
23642              --
23643              P_VALIDATE               => false
23644              ,P_EFFECTIVE_DATE        => l_effective_date
23645              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
23646              --
23647              ,P_EXCLD_FLAG      => r_LSR.INFORMATION11
23648              ,P_LOS_FCTR_ID      => l_LOS_FCTR_ID
23649              ,P_LOS_RT_ID      => l_los_rt_id
23650              ,P_LSR_ATTRIBUTE1      => r_LSR.INFORMATION111
23651              ,P_LSR_ATTRIBUTE10      => r_LSR.INFORMATION120
23652              ,P_LSR_ATTRIBUTE11      => r_LSR.INFORMATION121
23653              ,P_LSR_ATTRIBUTE12      => r_LSR.INFORMATION122
23654              ,P_LSR_ATTRIBUTE13      => r_LSR.INFORMATION123
23655              ,P_LSR_ATTRIBUTE14      => r_LSR.INFORMATION124
23656              ,P_LSR_ATTRIBUTE15      => r_LSR.INFORMATION125
23657              ,P_LSR_ATTRIBUTE16      => r_LSR.INFORMATION126
23658              ,P_LSR_ATTRIBUTE17      => r_LSR.INFORMATION127
23659              ,P_LSR_ATTRIBUTE18      => r_LSR.INFORMATION128
23660              ,P_LSR_ATTRIBUTE19      => r_LSR.INFORMATION129
23661              ,P_LSR_ATTRIBUTE2      => r_LSR.INFORMATION112
23662              ,P_LSR_ATTRIBUTE20      => r_LSR.INFORMATION130
23663              ,P_LSR_ATTRIBUTE21      => r_LSR.INFORMATION131
23664              ,P_LSR_ATTRIBUTE22      => r_LSR.INFORMATION132
23665              ,P_LSR_ATTRIBUTE23      => r_LSR.INFORMATION133
23666              ,P_LSR_ATTRIBUTE24      => r_LSR.INFORMATION134
23667              ,P_LSR_ATTRIBUTE25      => r_LSR.INFORMATION135
23668              ,P_LSR_ATTRIBUTE26      => r_LSR.INFORMATION136
23669              ,P_LSR_ATTRIBUTE27      => r_LSR.INFORMATION137
23670              ,P_LSR_ATTRIBUTE28      => r_LSR.INFORMATION138
23671              ,P_LSR_ATTRIBUTE29      => r_LSR.INFORMATION139
23672              ,P_LSR_ATTRIBUTE3      => r_LSR.INFORMATION113
23673              ,P_LSR_ATTRIBUTE30      => r_LSR.INFORMATION140
23674              ,P_LSR_ATTRIBUTE4      => r_LSR.INFORMATION114
23675              ,P_LSR_ATTRIBUTE5      => r_LSR.INFORMATION115
23676              ,P_LSR_ATTRIBUTE6      => r_LSR.INFORMATION116
23677              ,P_LSR_ATTRIBUTE7      => r_LSR.INFORMATION117
23678              ,P_LSR_ATTRIBUTE8      => r_LSR.INFORMATION118
23679              ,P_LSR_ATTRIBUTE9      => r_LSR.INFORMATION119
23680              ,P_LSR_ATTRIBUTE_CATEGORY      => r_LSR.INFORMATION110
23681              ,P_ORDR_NUM      => r_LSR.INFORMATION260
23682              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
23683              --
23684              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
23685              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
23686              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
23687              ,P_DATETRACK_MODE        => l_datetrack_mode
23688            );
23689            --
23690            end if;
23691          end if;
23692          --
23693          -- Delete the row if it is end dated.
23694          --
23695          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
23696              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
23697              trunc(l_max_eed) = r_LSR.information3) then
23698              --
23699              BEN_LENGTH_OF_SVC_RATE_API.delete_LENGTH_OF_SVC_RATE(
23700                 --
23701                 p_validate                       => false
23702                 ,p_los_rt_id                   => l_los_rt_id
23703                 ,p_effective_start_date           => l_effective_start_date
23704                 ,p_effective_end_date             => l_effective_end_date
23705                 ,p_object_version_number          => l_object_version_number
23706                 ,p_effective_date                 => l_max_eed
23707                 ,p_datetrack_mode                 => hr_api.g_delete
23708                 --
23709                 );
23710                 --
23711          end if;
23712          --
23713          l_prev_pk_id := l_current_pk_id ;
23714          --
23715        end if;
23716        --
23717      end if;
23718      --
23719    end loop;
23720    --
23721  exception when others then
23722     --
23723     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'LSR',r_lsr.information5 );
23724     --
23725  end create_LSR_rows;
23726 
23727    --
23728    ---------------------------------------------------------------
23729    ----------------------< create_LRN_rows >-----------------------
23730    ---------------------------------------------------------------
23731    --
23732    procedure create_LRN_rows
23733    (
23734          p_validate                       in  number     default 0
23735         ,p_copy_entity_txn_id             in  number
23736         ,p_effective_date                 in  date
23737         ,p_prefix_suffix_text             in  varchar2  default null
23738         ,p_reuse_object_flag              in  varchar2  default null
23739         ,p_target_business_group_id       in  varchar2  default null
23740         ,p_prefix_suffix_cd               in  varchar2  default null
23741    ) is
23742    --
23743    l_VRBL_RT_PRFL_ID  number;
23744    l_LVG_RSN_CD     varchar2(30); -- IK Added
23745    cursor c_unique_LRN(l_table_alias varchar2) is
23746    select distinct cpe.information1,
23747      cpe.information2,
23748      cpe.information3,
23749      cpe.table_route_id
23750    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
23751         pqh_table_route tr
23752    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
23753    and   cpe.table_route_id     = tr.table_route_id
23754    -- and   tr.where_clause        = l_BEN_LVG_RSN_RT_F
23755    and tr.table_alias = l_table_alias
23756    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
23757    order by information1, information2; --added for bug: 5151945
23758    --
23759    --
23760    cursor c_LRN_min_max_dates(c_table_route_id  number,
23761                 c_information1   number) is
23762    select
23763      min(cpe.information2) min_esd,
23764      max(cpe.information3) min_eed
23765    from ben_copy_entity_results cpe
23766    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
23767    and   cpe.table_route_id     = c_table_route_id
23768    and   cpe.information1       = c_information1 ;
23769    --
23770    cursor c_LRN(c_table_route_id  number,
23771                 c_information1   number,
23772                 c_information2   Date,
23773                 c_information3   Date)  is
23774    select
23775      cpe.*
23776    from ben_copy_entity_results cpe
23777    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
23778    and   cpe.table_route_id     = c_table_route_id
23779    and   cpe.information1       = c_information1
23780    and   cpe.information2       = c_information2
23781    and   cpe.information3       = c_information3
23782    and rownum = 1 ;
23783    -- Date Track target record
23784    cursor c_find_LRN_in_target(
23785                                 c_effective_start_date    date,
23786                                 c_effective_end_date      date,
23787                                 c_business_group_id       number,
23788                                 c_new_pk_id               number) is
23789    select
23790      LRN.lvg_rsn_rt_id new_value
23791    from BEN_LVG_RSN_RT_F LRN
23792    where
23793    LRN.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
23794    LRN.LVG_RSN_CD        = l_LVG_RSN_CD and
23795    LRN.business_group_id  = c_business_group_id
23796    and   LRN.lvg_rsn_rt_id  <> c_new_pk_id
23797 --TEMPIK
23798    and c_effective_start_date between effective_start_date
23799                             and effective_end_date ;
23800 --END TEMPIK
23801 /*TEMPIK
23802    and exists ( select null
23803                 from BEN_LVG_RSN_RT_F LRN1
23804                 where
23805                 LRN1.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
23806                 LRN1.LVG_RSN_CD        = l_LVG_RSN_CD and
23807                 LRN1.business_group_id  = c_business_group_id
23808                 and   LRN1.effective_start_date <= c_effective_start_date )
23809    and exists ( select null
23810                 from BEN_LVG_RSN_RT_F LRN2
23811                 where
23812                 LRN2.VRBL_RT_PRFL_ID = l_VRBL_RT_PRFL_ID and
23813                 LRN2.LVG_RSN_CD        = l_LVG_RSN_CD and
23814                 LRN2.business_group_id  = c_business_group_id
23815                 and   LRN2.effective_end_date >= c_effective_end_date )
23816                 ;
23817 TEMPIK */
23818    --TEMPIK
23819    l_dt_rec_found            boolean ;
23820    --END TEMPIK
23821    --
23822    l_current_pk_id           number := null ;
23823    --UPD START
23824    --
23825    l_update                  boolean      := false ;
23826    l_datetrack_mode          varchar2(80) := hr_api.g_update;
23827    l_process_date            date;
23828    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
23829    --
23830    --UPD END
23831    l_prev_pk_id              number := null ;
23832    l_first_rec               boolean := true ;
23833    r_LRN                     c_LRN%rowtype;
23834    l_lvg_rsn_rt_id             number ;
23835    l_object_version_number   number ;
23836    l_effective_start_date    date ;
23837    l_effective_end_date      date ;
23838    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
23839    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
23840    l_new_value               number(15);
23841    l_object_found_in_target  boolean := false ;
23842    l_min_esd                 date;
23843    l_max_eed                 date;
23844    l_effective_date          date;
23845    --
23846  begin
23847    -- Initialization
23848    l_object_found_in_target := false ;
23849    -- End Initialization
23850    -- Derive the prefix - sufix
23851    if   p_prefix_suffix_cd = 'PREFIX' then
23852      l_prefix  := p_prefix_suffix_text ;
23853    elsif p_prefix_suffix_cd = 'SUFFIX' then
23854      l_suffix   := p_prefix_suffix_text ;
23855    else
23856      l_prefix := null ;
23857      l_suffix  := null ;
23858    end if ;
23859    -- End Prefix Sufix derivation
23860    for r_LRN_unique in c_unique_LRN('LRN') loop
23861 
23862      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
23863         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
23864          r_LRN_unique.information3 >=
23865                  ben_pd_copy_to_ben_one.g_copy_effective_date)
23866         ) then
23867        --
23868        hr_utility.set_location(' r_LRN_unique.table_route_id '||r_LRN_unique.table_route_id,10);
23869        hr_utility.set_location(' r_LRN_unique.information1 '||r_LRN_unique.information1,10);
23870        hr_utility.set_location( 'r_LRN_unique.information2 '||r_LRN_unique.information2,10);
23871        hr_utility.set_location( 'r_LRN_unique.information3 '||r_LRN_unique.information3,10);
23872        -- If reuse objects flag is 'Y' then check for the object in the target business group
23873        -- if found insert the record into PLSql table and exit the loop else try create the
23874        -- object in the target business group
23875        --
23876        l_object_found_in_target := false ;
23877        l_min_esd := null ;
23878        l_max_eed := null ;
23879        open c_LRN_min_max_dates(r_LRN_unique.table_route_id, r_LRN_unique.information1 ) ;
23880        fetch c_LRN_min_max_dates into l_min_esd,l_max_eed ;
23881        --
23882 
23883        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
23884             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
23885          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
23886        end if;
23887        l_min_esd := greatest(l_min_esd,r_LRN_unique.information2);
23888        open c_LRN(r_LRN_unique.table_route_id,
23889                 r_LRN_unique.information1,
23890                 r_LRN_unique.information2,
23891                 r_LRN_unique.information3 ) ;
23892        --
23893        fetch c_LRN into r_LRN ;
23894        --
23895        close c_LRN ;
23896        --
23897        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_LRN.information262,r_LRN_unique.dml_operation);
23898        l_LVG_RSN_CD    := r_LRN.information11;
23899        --UPD START
23900        l_update := false;
23901        l_process_date := p_effective_date;
23902        l_dml_operation:= r_LRN_unique.dml_operation ;
23903        --
23904        if l_dml_operation = 'UPDATE' then
23905          --
23906          l_object_found_in_target := TRUE;
23907          --
23908          if l_process_date between r_LRN_unique.information2 and r_LRN_unique.information3 then
23909                l_update := true;
23910                if r_LRN_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
23911                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'LVG_RSN_RT_ID'
23912                then
23913                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'LVG_RSN_RT_ID' ;
23914                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_LRN_unique.information1 ;
23915                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_LRN_unique.information1 ;
23916                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
23917                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_LRN_unique.table_route_id;
23918                   --
23919                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
23920                   --
23921                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
23922                   --
23923                   -- log_data('LRN',l_new_value,l_prefix || r_LRN_unique.name|| l_suffix,'REUSED');
23924                   --
23925                end if ;
23926                hr_utility.set_location( 'found record for update',10);
23927            --
23928          else
23929            --
23930            l_update := false;
23931            --
23932          end if;
23933        else
23934          --
23935          --UPD END
23936        if p_reuse_object_flag = 'Y' then
23937          if c_LRN_min_max_dates%found then
23938            -- cursor to find the object
23939            open c_find_LRN_in_target( l_min_esd,l_max_eed,
23940                                  p_target_business_group_id, nvl(l_lvg_rsn_rt_id, -999)  ) ;
23941            fetch c_find_LRN_in_target into l_new_value ;
23942            if c_find_LRN_in_target%found then
23943              --
23944              --TEMPIK
23945              l_dt_rec_found :=   dt_api.check_min_max_dates
23946                  (p_base_table_name => 'BEN_LVG_RSN_RT_F',
23947                   p_base_key_column => 'LVG_RSN_RT_ID',
23948                   p_base_key_value  => l_new_value,
23949                   p_from_date       => l_min_esd,
23950                   p_to_date         => l_max_eed );
23951              if l_dt_rec_found THEN
23952              --END TEMPIK
23953              if r_LRN_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
23954                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <>  'LVG_RSN_RT_ID'  then
23955                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'LVG_RSN_RT_ID' ;
23956                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_LRN_unique.information1 ;
23957                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := l_new_value ;
23958                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
23959                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_LRN_unique.table_route_id;
23960                 --
23961                 -- 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) ;
23962                 --
23963                 BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
23964              end if ;
23965              --
23966              l_object_found_in_target := true ;
23967              --TEMPIK
23968              end if; -- l_dt_rec_found
23969              --END TEMPIK
23970            end if;
23971            close c_find_LRN_in_target ;
23972          --
23973          end if;
23974        end if ;
23975        --
23976        end if;
23977        close c_LRN_min_max_dates ;
23978        if not l_object_found_in_target OR l_update   then
23979          --
23980          l_current_pk_id := r_LRN.information1;
23981          --
23982          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
23983          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
23984          --
23985          if l_current_pk_id =  l_prev_pk_id  then
23986            --
23987            l_first_rec := false ;
23988            --
23989          else
23990            --
23991            l_first_rec := true ;
23992            --
23993          end if ;
23994          --
23995 
23996          l_effective_date := r_LRN.information2;
23997          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
23998               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
23999            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
24000          end if;
24001 
24002          if l_first_rec and not l_update then
24003            -- Call Create routine.
24004            hr_utility.set_location(' BEN_LVG_RSN_RT_F CREATE_LVG_RSN_RT ',20);
24005            BEN_LVG_RSN_RT_API.CREATE_LVG_RSN_RT(
24006              --
24007              P_VALIDATE               => false
24008              ,P_EFFECTIVE_DATE        => l_effective_date
24009              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
24010              --
24011              ,P_EXCLD_FLAG      => r_LRN.INFORMATION12
24012              ,P_LRN_ATTRIBUTE1      => r_LRN.INFORMATION111
24013              ,P_LRN_ATTRIBUTE10      => r_LRN.INFORMATION120
24014              ,P_LRN_ATTRIBUTE11      => r_LRN.INFORMATION121
24015              ,P_LRN_ATTRIBUTE12      => r_LRN.INFORMATION122
24016              ,P_LRN_ATTRIBUTE13      => r_LRN.INFORMATION123
24017              ,P_LRN_ATTRIBUTE14      => r_LRN.INFORMATION124
24018              ,P_LRN_ATTRIBUTE15      => r_LRN.INFORMATION125
24019              ,P_LRN_ATTRIBUTE16      => r_LRN.INFORMATION126
24020              ,P_LRN_ATTRIBUTE17      => r_LRN.INFORMATION127
24021              ,P_LRN_ATTRIBUTE18      => r_LRN.INFORMATION128
24022              ,P_LRN_ATTRIBUTE19      => r_LRN.INFORMATION129
24023              ,P_LRN_ATTRIBUTE2      => r_LRN.INFORMATION112
24024              ,P_LRN_ATTRIBUTE20      => r_LRN.INFORMATION130
24025              ,P_LRN_ATTRIBUTE21      => r_LRN.INFORMATION131
24026              ,P_LRN_ATTRIBUTE22      => r_LRN.INFORMATION132
24027              ,P_LRN_ATTRIBUTE23      => r_LRN.INFORMATION133
24028              ,P_LRN_ATTRIBUTE24      => r_LRN.INFORMATION134
24029              ,P_LRN_ATTRIBUTE25      => r_LRN.INFORMATION135
24030              ,P_LRN_ATTRIBUTE26      => r_LRN.INFORMATION136
24031              ,P_LRN_ATTRIBUTE27      => r_LRN.INFORMATION137
24032              ,P_LRN_ATTRIBUTE28      => r_LRN.INFORMATION138
24033              ,P_LRN_ATTRIBUTE29      => r_LRN.INFORMATION139
24034              ,P_LRN_ATTRIBUTE3      => r_LRN.INFORMATION113
24035              ,P_LRN_ATTRIBUTE30      => r_LRN.INFORMATION140
24036              ,P_LRN_ATTRIBUTE4      => r_LRN.INFORMATION114
24037              ,P_LRN_ATTRIBUTE5      => r_LRN.INFORMATION115
24038              ,P_LRN_ATTRIBUTE6      => r_LRN.INFORMATION116
24039              ,P_LRN_ATTRIBUTE7      => r_LRN.INFORMATION117
24040              ,P_LRN_ATTRIBUTE8      => r_LRN.INFORMATION118
24041              ,P_LRN_ATTRIBUTE9      => r_LRN.INFORMATION119
24042              ,P_LRN_ATTRIBUTE_CATEGORY      => r_LRN.INFORMATION110
24043              ,P_LVG_RSN_CD      => r_LRN.INFORMATION11
24044              ,P_LVG_RSN_RT_ID      => l_lvg_rsn_rt_id
24045              ,P_ORDR_NUM      => r_LRN.INFORMATION257
24046              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
24047              --
24048              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
24049              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
24050              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
24051            );
24052            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
24053            -- Update all relevent cer records with new pk_id
24054            hr_utility.set_location('Before plsql table ',222);
24055            hr_utility.set_location('new_value id '||l_lvg_rsn_rt_id,222);
24056            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column := 'LVG_RSN_RT_ID' ;
24057            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value    := r_LRN.information1 ;
24058            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value    := l_LVG_RSN_RT_ID ;
24059            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type  := 'COPIED';
24060            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_LRN_unique.table_route_id;
24061            hr_utility.set_location('After plsql table ',222);
24062            --
24063            -- 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 ) ;
24064            --
24065            BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
24066            --
24067          else
24068            --
24069            -- Call Update routine for the pk_id created in prev run .
24070            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
24071            --UPD START
24072            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
24073            --
24074            if l_update then
24075              --
24076              l_datetrack_mode := r_LRN.datetrack_mode ;
24077              --
24078              get_dt_modes(
24079                p_effective_date        => l_process_date,
24080                p_effective_end_date    => r_LRN.information3,
24081                p_effective_start_date  => r_LRN.information2,
24082                p_dml_operation         => r_LRN.dml_operation,
24083                p_datetrack_mode        => l_datetrack_mode );
24084            --    p_update                => l_update
24085              --
24086              l_effective_date := l_process_date;
24087              l_LVG_RSN_RT_ID   := r_LRN.information1;
24088              l_object_version_number := r_LRN.information265;
24089              --
24090            end if;
24091            --
24092            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
24093            --
24094            IF l_update OR l_dml_operation <> 'UPDATE' THEN
24095            --UPD END
24096            hr_utility.set_location(' BEN_LVG_RSN_RT_F UPDATE_LVG_RSN_RT ',30);
24097            BEN_LVG_RSN_RT_API.UPDATE_LVG_RSN_RT(
24098              --
24099              P_VALIDATE               => false
24100              ,P_EFFECTIVE_DATE        => l_effective_date
24101              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
24102              --
24103              ,P_EXCLD_FLAG      => r_LRN.INFORMATION12
24104              ,P_LRN_ATTRIBUTE1      => r_LRN.INFORMATION111
24105              ,P_LRN_ATTRIBUTE10      => r_LRN.INFORMATION120
24106              ,P_LRN_ATTRIBUTE11      => r_LRN.INFORMATION121
24107              ,P_LRN_ATTRIBUTE12      => r_LRN.INFORMATION122
24108              ,P_LRN_ATTRIBUTE13      => r_LRN.INFORMATION123
24109              ,P_LRN_ATTRIBUTE14      => r_LRN.INFORMATION124
24110              ,P_LRN_ATTRIBUTE15      => r_LRN.INFORMATION125
24111              ,P_LRN_ATTRIBUTE16      => r_LRN.INFORMATION126
24112              ,P_LRN_ATTRIBUTE17      => r_LRN.INFORMATION127
24113              ,P_LRN_ATTRIBUTE18      => r_LRN.INFORMATION128
24114              ,P_LRN_ATTRIBUTE19      => r_LRN.INFORMATION129
24115              ,P_LRN_ATTRIBUTE2      => r_LRN.INFORMATION112
24116              ,P_LRN_ATTRIBUTE20      => r_LRN.INFORMATION130
24117              ,P_LRN_ATTRIBUTE21      => r_LRN.INFORMATION131
24118              ,P_LRN_ATTRIBUTE22      => r_LRN.INFORMATION132
24119              ,P_LRN_ATTRIBUTE23      => r_LRN.INFORMATION133
24120              ,P_LRN_ATTRIBUTE24      => r_LRN.INFORMATION134
24121              ,P_LRN_ATTRIBUTE25      => r_LRN.INFORMATION135
24122              ,P_LRN_ATTRIBUTE26      => r_LRN.INFORMATION136
24123              ,P_LRN_ATTRIBUTE27      => r_LRN.INFORMATION137
24124              ,P_LRN_ATTRIBUTE28      => r_LRN.INFORMATION138
24125              ,P_LRN_ATTRIBUTE29      => r_LRN.INFORMATION139
24126              ,P_LRN_ATTRIBUTE3      => r_LRN.INFORMATION113
24127              ,P_LRN_ATTRIBUTE30      => r_LRN.INFORMATION140
24128              ,P_LRN_ATTRIBUTE4      => r_LRN.INFORMATION114
24129              ,P_LRN_ATTRIBUTE5      => r_LRN.INFORMATION115
24130              ,P_LRN_ATTRIBUTE6      => r_LRN.INFORMATION116
24131              ,P_LRN_ATTRIBUTE7      => r_LRN.INFORMATION117
24132              ,P_LRN_ATTRIBUTE8      => r_LRN.INFORMATION118
24133              ,P_LRN_ATTRIBUTE9      => r_LRN.INFORMATION119
24134              ,P_LRN_ATTRIBUTE_CATEGORY      => r_LRN.INFORMATION110
24135              ,P_LVG_RSN_CD      => r_LRN.INFORMATION11
24136              ,P_LVG_RSN_RT_ID      => l_lvg_rsn_rt_id
24137              ,P_ORDR_NUM      => r_LRN.INFORMATION257
24138              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
24139              --
24140              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
24141              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
24142              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
24143              ,P_DATETRACK_MODE        => l_datetrack_mode
24144            );
24145            --
24146            end if;
24147          end if;
24148          --
24149          -- Delete the row if it is end dated.
24150          --
24151          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
24152              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
24153              trunc(l_max_eed) = r_LRN.information3) then
24154              --
24155              BEN_LVG_RSN_RT_API.delete_LVG_RSN_RT(
24156                 --
24157                 p_validate                       => false
24158                 ,p_lvg_rsn_rt_id                   => l_lvg_rsn_rt_id
24159                 ,p_effective_start_date           => l_effective_start_date
24160                 ,p_effective_end_date             => l_effective_end_date
24161                 ,p_object_version_number          => l_object_version_number
24162                 ,p_effective_date                 => l_max_eed
24163                 ,p_datetrack_mode                 => hr_api.g_delete
24164                 --
24165                 );
24166                 --
24167          end if;
24168          --
24169          l_prev_pk_id := l_current_pk_id ;
24170          --
24171        end if;
24172        --
24173      end if;
24174      --
24175    end loop;
24176    --
24177  exception when others then
24178     --
24179     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'LRN',r_lrn.information5 );
24180     --
24181  end create_LRN_rows;
24182 
24183    --
24184    ---------------------------------------------------------------
24185    ----------------------< create_ART_rows >-----------------------
24186    ---------------------------------------------------------------
24187    --
24188    procedure create_ART_rows
24189    (
24190          p_validate                       in  number     default 0
24191         ,p_copy_entity_txn_id             in  number
24192         ,p_effective_date                 in  date
24193         ,p_prefix_suffix_text             in  varchar2  default null
24194         ,p_reuse_object_flag              in  varchar2  default null
24195         ,p_target_business_group_id       in  varchar2  default null
24196         ,p_prefix_suffix_cd               in  varchar2  default null
24197    ) is
24198    --
24199    l_AGE_FCTR_ID      number;
24200    l_VRBL_RT_PRFL_ID  number;
24201    l_ORDR_NUM         number;
24202    --
24203    cursor c_unique_ART(l_table_alias varchar2) is
24204    select distinct cpe.information1,
24205      cpe.information2,
24206      cpe.information3,
24207      cpe.table_route_id
24208    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
24209         pqh_table_route tr
24210    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
24211    and   cpe.table_route_id     = tr.table_route_id
24212    -- and   tr.where_clause        = l_BEN_AGE_RT_F
24213    and tr.table_alias = l_table_alias
24214    and   cpe.number_of_copies   = 1 -- ADDITION
24215    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
24216    order by information1, information2; --added for bug: 5151945
24217    --
24218    --
24219    cursor c_ART_min_max_dates(c_table_route_id  number,
24220                 c_information1   number) is
24221    select
24222      min(cpe.information2) min_esd,
24223      max(cpe.information3) min_eed
24224    from ben_copy_entity_results cpe
24225    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
24226    and   cpe.table_route_id     = c_table_route_id
24227    and   cpe.information1       = c_information1 ;
24228    --
24229    cursor c_ART(c_table_route_id number,
24230                 c_information1   number,
24231                 c_information2   Date,
24232                 c_information3   Date)  is
24233    select
24234      cpe.*
24235    from ben_copy_entity_results cpe
24236    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
24237    and   cpe.table_route_id     = c_table_route_id
24238    and   cpe.information1       = c_information1
24239    and   cpe.information2       = c_information2
24240    and   cpe.information3       = c_information3
24241    and rownum = 1 ;
24242    -- Date Track target record
24243    cursor c_find_ART_in_target(
24244                                 c_effective_start_date    date,
24245                                 c_effective_end_date      date,
24246                                 c_business_group_id       number,
24247                                 c_new_pk_id               number) is
24248    select
24249      ART.age_rt_id new_value
24250    from BEN_AGE_RT_F ART
24251    where
24252    ART.AGE_FCTR_ID     = l_AGE_FCTR_ID  and
24253    ART.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
24254    ART.ORDR_NUM            = l_ORDR_NUM and
24255    ART.business_group_id  = c_business_group_id
24256    and   ART.age_rt_id  <> c_new_pk_id
24257 --TEMPIK
24258    and c_effective_start_date between effective_start_date
24259                             and effective_end_date ;
24260 --END TEMPIK
24261 /*TEMPIK
24262    and exists ( select null
24263                 from BEN_AGE_RT_F ART1
24264                 where
24265                 ART1.AGE_FCTR_ID     = l_AGE_FCTR_ID  and
24266                 ART1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
24267                 ART1.ORDR_NUM            = l_ORDR_NUM and
24268                 ART1.business_group_id  = c_business_group_id
24269                 and   ART1.effective_start_date <= c_effective_start_date )
24270    and exists ( select null
24271                 from BEN_AGE_RT_F ART2
24272                 where
24273                 ART2.AGE_FCTR_ID     = l_AGE_FCTR_ID  and
24274                 ART2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
24275                 ART2.ORDR_NUM            = l_ORDR_NUM and
24276                 ART2.business_group_id  = c_business_group_id
24277                 and   ART2.effective_end_date >= c_effective_end_date )
24278                 ;
24279 TEMPIK */
24280    --TEMPIK
24281    l_dt_rec_found            boolean ;
24282    --END TEMPIK
24283    --
24284    l_current_pk_id           number := null ;
24285    --UPD START
24286    --
24287    l_update                  boolean      := false ;
24288    l_datetrack_mode          varchar2(80) := hr_api.g_update;
24289    l_process_date            date;
24290    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
24291    --
24292    --UPD END
24293    l_prev_pk_id              number := null ;
24294    l_first_rec               boolean := true ;
24295    r_ART                     c_ART%rowtype;
24296    l_age_rt_id             number ;
24297    l_object_version_number   number ;
24298    l_effective_start_date    date ;
24299    l_effective_end_date      date ;
24300    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
24301    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
24302    l_new_value               number(15);
24303    l_object_found_in_target  boolean := false ;
24304    l_min_esd                 date;
24305    l_max_eed                 date;
24306    l_effective_date          date;
24307    --
24308  begin
24309    -- Initialization
24310    l_object_found_in_target := false ;
24311    -- End Initialization
24312    -- Derive the prefix - sufix
24313    if   p_prefix_suffix_cd = 'PREFIX' then
24314      l_prefix  := p_prefix_suffix_text ;
24315    elsif p_prefix_suffix_cd = 'SUFFIX' then
24316      l_suffix   := p_prefix_suffix_text ;
24317    else
24318      l_prefix := null ;
24319      l_suffix  := null ;
24320    end if ;
24321    -- End Prefix Sufix derivation
24322    for r_ART_unique in c_unique_ART('ART') loop
24323 
24324      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
24325         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
24326          r_ART_unique.information3 >=
24327                  ben_pd_copy_to_ben_one.g_copy_effective_date)
24328         ) then
24329        --
24330        hr_utility.set_location(' r_ART_unique.table_route_id '||r_ART_unique.table_route_id,10);
24331        hr_utility.set_location(' r_ART_unique.information1 '||r_ART_unique.information1,10);
24332        hr_utility.set_location( 'r_ART_unique.information2 '||r_ART_unique.information2,10);
24333        hr_utility.set_location( 'r_ART_unique.information3 '||r_ART_unique.information3,10);
24334        -- If reuse objects flag is 'Y' then check for the object in the target business group
24335        -- if found insert the record into PLSql table and exit the loop else try create the
24336        -- object in the target business group
24337        --
24338        l_object_found_in_target := false ;
24339        l_min_esd := null ;
24340        l_max_eed := null ;
24341        open c_ART_min_max_dates(r_ART_unique.table_route_id, r_ART_unique.information1 ) ;
24342        fetch c_ART_min_max_dates into l_min_esd,l_max_eed ;
24343        --
24344 
24345        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
24346             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
24347          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
24348        end if;
24349        l_min_esd := greatest(l_min_esd,r_ART_unique.information2);
24350        open c_ART(r_ART_unique.table_route_id,
24351                 r_ART_unique.information1,
24352                 r_ART_unique.information2,
24353                 r_ART_unique.information3 ) ;
24354        --
24355        fetch c_ART into r_ART ;
24356        --
24357        close c_ART ;
24358        --
24359        l_AGE_FCTR_ID := get_fk('AGE_FCTR_ID', r_ART.information246,r_ART_unique.dml_operation);
24360        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_ART.information262,r_ART_unique.dml_operation);
24361        l_ORDR_NUM        := r_ART.INFORMATION260 ;
24362        --
24363        --UPD START
24364        l_update := false;
24365        l_process_date := p_effective_date;
24366        l_dml_operation:= r_ART_unique.dml_operation ;
24367        --
24368        if l_dml_operation = 'UPDATE' then
24369          --
24370          l_object_found_in_target := TRUE;
24371          --
24372          if l_process_date between r_ART_unique.information2 and r_ART_unique.information3 then
24373                l_update := true;
24374                if r_ART_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
24375                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'AGE_RT_ID'
24376                then
24377                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'AGE_RT_ID' ;
24378                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_ART_unique.information1 ;
24379                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_ART_unique.information1 ;
24380                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
24381                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_ART_unique.table_route_id;
24382                   --
24383                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
24384                   --
24385                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
24386                   --
24387                   -- log_data('ART',l_new_value,l_prefix || r_ART_unique.name|| l_suffix,'REUSED');
24388                   --
24389                end if ;
24390                hr_utility.set_location( 'found record for update',10);
24391            --
24392          else
24393            --
24394            l_update := false;
24395            --
24396          end if;
24397        else
24398          --
24399          --UPD END
24400        if p_reuse_object_flag = 'Y' then
24401          if c_ART_min_max_dates%found then
24402            -- cursor to find the object
24403            open c_find_ART_in_target( l_min_esd,l_max_eed,
24404                                  p_target_business_group_id, nvl(l_age_rt_id, -999)  ) ;
24405            fetch c_find_ART_in_target into l_new_value ;
24406            if c_find_ART_in_target%found then
24407              --
24408              --TEMPIK
24409              l_dt_rec_found :=   dt_api.check_min_max_dates
24410                  (p_base_table_name => 'BEN_AGE_RT_F',
24411                   p_base_key_column => 'AGE_RT_ID',
24412                   p_base_key_value  => l_new_value,
24413                   p_from_date       => l_min_esd,
24414                   p_to_date         => l_max_eed );
24415              if l_dt_rec_found THEN
24416              --END TEMPIK
24417              if r_ART_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
24418                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'AGE_RT_ID'  then
24419                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'AGE_RT_ID' ;
24420                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_ART_unique.information1 ;
24421                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
24422                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
24423                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_ART_unique.table_route_id;
24424                 --
24425                 -- 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) ;
24426                 --
24427                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
24428              end if ;
24429              --
24430              l_object_found_in_target := true ;
24431              --TEMPIK
24432              end if; -- l_dt_rec_found
24433              --END TEMPIK
24434            end if;
24435            close c_find_ART_in_target ;
24436          --
24437          end if;
24438        end if ;
24439        --
24440        end if;
24441        close c_ART_min_max_dates ;
24442        if not l_object_found_in_target OR l_update   then
24443          --
24444          l_current_pk_id := r_ART.information1;
24445          --
24446          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
24447          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
24448          --
24449          if l_current_pk_id =  l_prev_pk_id  then
24450            --
24451            l_first_rec := false ;
24452            --
24453          else
24454            --
24455            l_first_rec := true ;
24456            --
24457          end if ;
24458          --
24459 
24460          l_effective_date := r_ART.information2;
24461          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
24462               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
24463            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
24464          end if;
24465 
24466          if l_first_rec and not l_update then
24467            -- Call Create routine.
24468            hr_utility.set_location(' BEN_AGE_RT_F CREATE_AGE_RATES ',20);
24469            BEN_AGE_RATES_API.CREATE_AGE_RATES(
24470              --
24471              P_VALIDATE               => false
24472              ,P_EFFECTIVE_DATE        => l_effective_date
24473              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
24474              --
24475              ,P_AGE_FCTR_ID      => l_AGE_FCTR_ID
24476              ,P_AGE_RT_ID      => l_age_rt_id
24477              ,P_ART_ATTRIBUTE1      => r_ART.INFORMATION111
24478              ,P_ART_ATTRIBUTE10      => r_ART.INFORMATION120
24479              ,P_ART_ATTRIBUTE11      => r_ART.INFORMATION121
24480              ,P_ART_ATTRIBUTE12      => r_ART.INFORMATION122
24481              ,P_ART_ATTRIBUTE13      => r_ART.INFORMATION123
24482              ,P_ART_ATTRIBUTE14      => r_ART.INFORMATION124
24483              ,P_ART_ATTRIBUTE15      => r_ART.INFORMATION125
24484              ,P_ART_ATTRIBUTE16      => r_ART.INFORMATION126
24485              ,P_ART_ATTRIBUTE17      => r_ART.INFORMATION127
24486              ,P_ART_ATTRIBUTE18      => r_ART.INFORMATION128
24487              ,P_ART_ATTRIBUTE19      => r_ART.INFORMATION129
24488              ,P_ART_ATTRIBUTE2      => r_ART.INFORMATION112
24489              ,P_ART_ATTRIBUTE20      => r_ART.INFORMATION130
24490              ,P_ART_ATTRIBUTE21      => r_ART.INFORMATION131
24491              ,P_ART_ATTRIBUTE22      => r_ART.INFORMATION132
24492              ,P_ART_ATTRIBUTE23      => r_ART.INFORMATION133
24493              ,P_ART_ATTRIBUTE24      => r_ART.INFORMATION134
24494              ,P_ART_ATTRIBUTE25      => r_ART.INFORMATION135
24495              ,P_ART_ATTRIBUTE26      => r_ART.INFORMATION136
24496              ,P_ART_ATTRIBUTE27      => r_ART.INFORMATION137
24497              ,P_ART_ATTRIBUTE28      => r_ART.INFORMATION138
24498              ,P_ART_ATTRIBUTE29      => r_ART.INFORMATION139
24499              ,P_ART_ATTRIBUTE3      => r_ART.INFORMATION113
24500              ,P_ART_ATTRIBUTE30      => r_ART.INFORMATION140
24501              ,P_ART_ATTRIBUTE4      => r_ART.INFORMATION114
24502              ,P_ART_ATTRIBUTE5      => r_ART.INFORMATION115
24503              ,P_ART_ATTRIBUTE6      => r_ART.INFORMATION116
24504              ,P_ART_ATTRIBUTE7      => r_ART.INFORMATION117
24505              ,P_ART_ATTRIBUTE8      => r_ART.INFORMATION118
24506              ,P_ART_ATTRIBUTE9      => r_ART.INFORMATION119
24507              ,P_ART_ATTRIBUTE_CATEGORY      => r_ART.INFORMATION110
24508              ,P_EXCLD_FLAG      => r_ART.INFORMATION11
24509              ,P_ORDR_NUM      => r_ART.INFORMATION260
24510              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
24511              --
24512              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
24513              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
24514              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
24515            );
24516            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
24517            -- Update all relevent cer records with new pk_id
24518            hr_utility.set_location('Before plsql table ',222);
24519            hr_utility.set_location('new_value id '||l_age_rt_id,222);
24520            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'AGE_RT_ID' ;
24521            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_ART.information1 ;
24522            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_AGE_RT_ID ;
24523            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
24524            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_ART_unique.table_route_id;
24525            hr_utility.set_location('After plsql table ',222);
24526            --
24527            -- 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 ) ;
24528            --
24529            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
24530            --
24531          else
24532            --
24533            -- Call Update routine for the pk_id created in prev run .
24534            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
24535            --UPD START
24536            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
24537            --
24538            if l_update then
24539              --
24540              l_datetrack_mode := r_ART.datetrack_mode ;
24541              --
24542              get_dt_modes(
24543                p_effective_date        => l_process_date,
24544                p_effective_end_date    => r_ART.information3,
24545                p_effective_start_date  => r_ART.information2,
24546                p_dml_operation         => r_ART.dml_operation,
24547                p_datetrack_mode        => l_datetrack_mode );
24548            --    p_update                => l_update
24549              --
24550              l_effective_date := l_process_date;
24551              l_AGE_RT_ID   := r_ART.information1;
24552              l_object_version_number := r_ART.information265;
24553              --
24554            end if;
24555            --
24556            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
24557            --
24558            IF l_update OR l_dml_operation <> 'UPDATE' THEN
24559            --UPD END
24560            hr_utility.set_location(' BEN_AGE_RT_F UPDATE_AGE_RATES ',30);
24561            BEN_AGE_RATES_API.UPDATE_AGE_RATES(
24562              --
24563              P_VALIDATE               => false
24564              ,P_EFFECTIVE_DATE        => l_effective_date
24565              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
24566              --
24567              ,P_AGE_FCTR_ID      => l_AGE_FCTR_ID
24568              ,P_AGE_RT_ID      => l_age_rt_id
24569              ,P_ART_ATTRIBUTE1      => r_ART.INFORMATION111
24570              ,P_ART_ATTRIBUTE10      => r_ART.INFORMATION120
24571              ,P_ART_ATTRIBUTE11      => r_ART.INFORMATION121
24572              ,P_ART_ATTRIBUTE12      => r_ART.INFORMATION122
24573              ,P_ART_ATTRIBUTE13      => r_ART.INFORMATION123
24574              ,P_ART_ATTRIBUTE14      => r_ART.INFORMATION124
24575              ,P_ART_ATTRIBUTE15      => r_ART.INFORMATION125
24576              ,P_ART_ATTRIBUTE16      => r_ART.INFORMATION126
24577              ,P_ART_ATTRIBUTE17      => r_ART.INFORMATION127
24578              ,P_ART_ATTRIBUTE18      => r_ART.INFORMATION128
24579              ,P_ART_ATTRIBUTE19      => r_ART.INFORMATION129
24580              ,P_ART_ATTRIBUTE2      => r_ART.INFORMATION112
24581              ,P_ART_ATTRIBUTE20      => r_ART.INFORMATION130
24582              ,P_ART_ATTRIBUTE21      => r_ART.INFORMATION131
24583              ,P_ART_ATTRIBUTE22      => r_ART.INFORMATION132
24584              ,P_ART_ATTRIBUTE23      => r_ART.INFORMATION133
24585              ,P_ART_ATTRIBUTE24      => r_ART.INFORMATION134
24586              ,P_ART_ATTRIBUTE25      => r_ART.INFORMATION135
24587              ,P_ART_ATTRIBUTE26      => r_ART.INFORMATION136
24588              ,P_ART_ATTRIBUTE27      => r_ART.INFORMATION137
24589              ,P_ART_ATTRIBUTE28      => r_ART.INFORMATION138
24590              ,P_ART_ATTRIBUTE29      => r_ART.INFORMATION139
24591              ,P_ART_ATTRIBUTE3      => r_ART.INFORMATION113
24592              ,P_ART_ATTRIBUTE30      => r_ART.INFORMATION140
24593              ,P_ART_ATTRIBUTE4      => r_ART.INFORMATION114
24594              ,P_ART_ATTRIBUTE5      => r_ART.INFORMATION115
24595              ,P_ART_ATTRIBUTE6      => r_ART.INFORMATION116
24596              ,P_ART_ATTRIBUTE7      => r_ART.INFORMATION117
24597              ,P_ART_ATTRIBUTE8      => r_ART.INFORMATION118
24598              ,P_ART_ATTRIBUTE9      => r_ART.INFORMATION119
24599              ,P_ART_ATTRIBUTE_CATEGORY      => r_ART.INFORMATION110
24600              ,P_EXCLD_FLAG      => r_ART.INFORMATION11
24601              ,P_ORDR_NUM      => r_ART.INFORMATION260
24602              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
24603              --
24604              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
24605              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
24606              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
24607              ,P_DATETRACK_MODE        => l_datetrack_mode
24608            );
24609            --
24610            end if;
24611          end if;
24612          --
24613          -- Delete the row if it is end dated.
24614          --
24615          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
24616              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
24617              trunc(l_max_eed) = r_ART.information3) then
24618              --
24619              BEN_AGE_RATES_API.delete_AGE_RATES(
24620                 --
24621                 p_validate                       => false
24622                 ,p_age_rt_id                   => l_age_rt_id
24623                 ,p_effective_start_date           => l_effective_start_date
24624                 ,p_effective_end_date             => l_effective_end_date
24625                 ,p_object_version_number          => l_object_version_number
24626                 ,p_effective_date                 => l_max_eed
24627                 ,p_datetrack_mode                 => hr_api.g_delete
24628                 --
24629                 );
24630                --
24631          end if;
24632          --
24633          l_prev_pk_id := l_current_pk_id ;
24634          --
24635        end if;
24636        --
24637      end if;
24638      --
24639    end loop;
24640    --
24641  exception when others then
24642     --
24643     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'ART',r_art.information5 );
24644     --
24645  end create_ART_rows;
24646 
24647    --
24648    ---------------------------------------------------------------
24649    ----------------------< create_SHR_rows >-----------------------
24650    ---------------------------------------------------------------
24651    --
24652    procedure create_SHR_rows
24653    (
24654          p_validate                       in  number     default 0
24655         ,p_copy_entity_txn_id             in  number
24656         ,p_effective_date                 in  date
24657         ,p_prefix_suffix_text             in  varchar2  default null
24658         ,p_reuse_object_flag              in  varchar2  default null
24659         ,p_target_business_group_id       in  varchar2  default null
24660         ,p_prefix_suffix_cd               in  varchar2  default null
24661    ) is
24662    --
24663    l_VRBL_RT_PRFL_ID  number;
24664    l_HRS_NUM          number;
24665    l_EXCLD_FLAG     varchar2(100);
24666    l_FREQ_CD        varchar2(100);
24667    l_DETERMINATION_CD varchar2(30);
24668    l_DETERMINATION_RL number;
24669    l_MAX_HRS_NUM number;
24670    l_ROUNDING_CD varchar2(30);
24671    l_ROUNDING_RL number;
24672    l_SCHEDD_HRS_RL number;
24673    l_ORDR_NUM number;
24674 
24675    cursor c_unique_SHR(l_table_alias varchar2) is
24676    select distinct cpe.information1,
24677      cpe.information2,
24678      cpe.information3,
24679      cpe.table_route_id
24680    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
24681         pqh_table_route tr
24682    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
24683    and   cpe.table_route_id     = tr.table_route_id
24684    -- and   tr.where_clause        = l_BEN_SCHEDD_HRS_RT_F
24685    and tr.table_alias = l_table_alias
24686    and   cpe.number_of_copies   = 1 -- ADDITION
24687    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
24688    order by information1, information2; --added for bug: 5151945
24689    --
24690    --
24691    cursor c_SHR_min_max_dates(c_table_route_id  number,
24692                 c_information1   number) is
24693    select
24694      min(cpe.information2) min_esd,
24695      max(cpe.information3) min_eed
24696    from ben_copy_entity_results cpe
24697    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
24698    and   cpe.table_route_id     = c_table_route_id
24699    and   cpe.information1       = c_information1 ;
24700    --
24701    cursor c_SHR(c_table_route_id number,
24702                 c_information1   number,
24703                 c_information2   Date,
24704                 c_information3   Date)  is
24705    select
24706      cpe.*
24707    from ben_copy_entity_results cpe
24708    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
24709    and   cpe.table_route_id     = c_table_route_id
24710    and   cpe.information1       = c_information1
24711    and   cpe.information2       = c_information2
24712    and   cpe.information3       = c_information3
24713    and rownum = 1 ;
24714    -- Date Track target record
24715    cursor c_find_SHR_in_target(
24716                                 c_effective_start_date    date,
24717                                 c_effective_end_date      date,
24718                                 c_business_group_id       number,
24719                                 c_new_pk_id               number) is
24720    select
24721      SHR.schedd_hrs_rt_id new_value
24722    from BEN_SCHEDD_HRS_RT_F SHR
24723    where
24724     SHR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
24725     NVL(SHR.HRS_NUM,-999)   = NVL(l_HRS_NUM,-999) and
24726     NVL(SHR.FREQ_CD,-999)   =  NVL(l_FREQ_CD,-999) and
24727     NVL(SHR.DETERMINATION_CD,-999) = NVL(l_DETERMINATION_CD,-999) and
24728     NVL(SHR.DETERMINATION_RL,-999) = NVL(l_DETERMINATION_RL,-999) and
24729     NVL(SHR.MAX_HRS_NUM,-999) = NVL(l_MAX_HRS_NUM,-999) and
24730     NVL(SHR.ROUNDING_CD,-999) = NVL(l_ROUNDING_CD,-999) and
24731     NVL(SHR.ROUNDING_RL,-999) = NVL(l_ROUNDING_RL,-999) and
24732     NVL(SHR.SCHEDD_HRS_RL,-999) = NVL(l_SCHEDD_HRS_RL,-999) and
24733     SHR.ORDR_NUM      = l_ORDR_NUM and
24734     SHR.business_group_id  = c_business_group_id
24735    and   SHR.schedd_hrs_rt_id  <> c_new_pk_id
24736 --TEMPIK
24737    and c_effective_start_date between effective_start_date
24738                             and effective_end_date ;
24739 --END TEMPIK
24740 /*TEMPIK
24741    and exists ( select null
24742                 from BEN_SCHEDD_HRS_RT_F SHR1
24743                 where
24744                 SHR1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
24745                 NVL(SHR1.HRS_NUM,-999)   = NVL(l_HRS_NUM,-999) and
24746                 NVL(SHR1.FREQ_CD,-999)   =  NVL(l_FREQ_CD,-999) and
24747                 NVL(SHR1.DETERMINATION_CD,-999) = NVL(l_DETERMINATION_CD,-999) and
24748                 NVL(SHR1.DETERMINATION_RL,-999) = NVL(l_DETERMINATION_RL,-999) and
24749                 NVL(SHR1.MAX_HRS_NUM,-999) = NVL(l_MAX_HRS_NUM,-999) and
24750                 NVL(SHR1.ROUNDING_CD,-999) = NVL(l_ROUNDING_CD,-999) and
24751                 NVL(SHR1.ROUNDING_RL,-999) = NVL(l_ROUNDING_RL,-999) and
24752                 NVL(SHR1.SCHEDD_HRS_RL,-999) = NVL(l_SCHEDD_HRS_RL,-999) and
24753                 SHR1.ORDR_NUM      = l_ORDR_NUM and
24754                 SHR1.business_group_id  = c_business_group_id
24755                 and   SHR1.effective_start_date <= c_effective_start_date )
24756    and exists ( select null
24757                 from BEN_SCHEDD_HRS_RT_F SHR2
24758                 where
24759                 SHR2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
24760                 NVL(SHR2.HRS_NUM,-999)   = NVL(l_HRS_NUM,-999) and
24761                 NVL(SHR2.FREQ_CD,-999)   =  NVL(l_FREQ_CD,-999) and
24762                 NVL(SHR2.DETERMINATION_CD,-999) = NVL(l_DETERMINATION_CD,-999) and
24763                 NVL(SHR2.DETERMINATION_RL,-999) = NVL(l_DETERMINATION_RL,-999) and
24764                 NVL(SHR2.MAX_HRS_NUM,-999) = NVL(l_MAX_HRS_NUM,-999) and
24765                 NVL(SHR2.ROUNDING_CD,-999) = NVL(l_ROUNDING_CD,-999) and
24766                 NVL(SHR2.ROUNDING_RL,-999) = NVL(l_ROUNDING_RL,-999) and
24767                 NVL(SHR2.SCHEDD_HRS_RL,-999) = NVL(l_SCHEDD_HRS_RL,-999)and
24768                 SHR2.ORDR_NUM      = l_ORDR_NUM and
24769                 SHR2.business_group_id  = c_business_group_id
24770                 and   SHR2.effective_end_date >= c_effective_end_date )
24771                 ;
24772 TEMPIK */
24773    --TEMPIK
24774    l_dt_rec_found            boolean ;
24775    --END TEMPIK
24776    --
24777    l_current_pk_id           number := null ;
24778    --UPD START
24779    --
24780    l_update                  boolean      := false ;
24781    l_datetrack_mode          varchar2(80) := hr_api.g_update;
24782    l_process_date            date;
24783    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
24784    --
24785    --UPD END
24786    l_prev_pk_id              number := null ;
24787    l_first_rec               boolean := true ;
24788    r_SHR                     c_SHR%rowtype;
24789    l_schedd_hrs_rt_id             number ;
24790    l_object_version_number   number ;
24791    l_effective_start_date    date ;
24792    l_effective_end_date      date ;
24793    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
24794    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
24795    l_new_value               number(15);
24796    l_object_found_in_target  boolean := false ;
24797    l_min_esd                 date;
24798    l_max_eed                 date;
24799    l_effective_date          date;
24800    --
24801  begin
24802    -- Initialization
24803    l_object_found_in_target := false ;
24804    -- End Initialization
24805    -- Derive the prefix - sufix
24806    if   p_prefix_suffix_cd = 'PREFIX' then
24807      l_prefix  := p_prefix_suffix_text ;
24808    elsif p_prefix_suffix_cd = 'SUFFIX' then
24809      l_suffix   := p_prefix_suffix_text ;
24810    else
24811      l_prefix := null ;
24812      l_suffix  := null ;
24813    end if ;
24814    -- End Prefix Sufix derivation
24815    for r_SHR_unique in c_unique_SHR('SHR') loop
24816 
24817      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
24818         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
24819          r_SHR_unique.information3 >=
24820                  ben_pd_copy_to_ben_one.g_copy_effective_date)
24821         ) then
24822        --
24823        hr_utility.set_location(' r_SHR_unique.table_route_id '||r_SHR_unique.table_route_id,10);
24824        hr_utility.set_location(' r_SHR_unique.information1 '||r_SHR_unique.information1,10);
24825        hr_utility.set_location( 'r_SHR_unique.information2 '||r_SHR_unique.information2,10);
24826        hr_utility.set_location( 'r_SHR_unique.information3 '||r_SHR_unique.information3,10);
24827        -- If reuse objects flag is 'Y' then check for the object in the target business group
24828        -- if found insert the record into PLSql table and exit the loop else try create the
24829        -- object in the target business group
24830        --
24831        l_object_found_in_target := false ;
24832        l_min_esd := null ;
24833        l_max_eed := null ;
24834        open c_SHR_min_max_dates(r_SHR_unique.table_route_id, r_SHR_unique.information1 ) ;
24835        fetch c_SHR_min_max_dates into l_min_esd,l_max_eed ;
24836        --
24837 
24838        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
24839             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
24840          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
24841        end if;
24842        l_min_esd := greatest(l_min_esd,r_SHR_unique.information2);
24843        open c_SHR(r_SHR_unique.table_route_id,
24844                 r_SHR_unique.information1,
24845                 r_SHR_unique.information2,
24846                 r_SHR_unique.information3 ) ;
24847        --
24848        fetch c_SHR into r_SHR ;
24849        --
24850        close c_SHR ;
24851        --
24852        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_SHR.information262,r_SHR_unique.dml_operation);
24853        l_EXCLD_FLAG      := r_SHR.information13;
24854        l_FREQ_CD         := r_SHR.information14;
24855        l_HRS_NUM         := r_SHR.information288;
24856        l_DETERMINATION_CD := r_SHR.information12;
24857        l_DETERMINATION_RL := get_fk('FORMULA_ID', r_SHR.information259,r_SHR_unique.dml_operation);
24858        l_ROUNDING_CD      := r_SHR.information11;
24859        l_ROUNDING_RL      := get_fk('FORMULA_ID', r_SHR.information257,r_SHR_unique.dml_operation);
24860        l_SCHEDD_HRS_RL    := get_fk('FORMULA_ID', r_SHR.information258,r_SHR_unique.dml_operation);
24861        l_MAX_HRS_NUM      := r_SHR.information287;
24862        l_ORDR_NUM         := r_SHR.INFORMATION260;
24863         --UPD STSHR
24864        l_update := false;
24865        l_process_date := p_effective_date;
24866        l_dml_operation:= r_SHR_unique.dml_operation ;
24867        --
24868        if l_dml_operation = 'UPDATE' then
24869          --
24870          l_object_found_in_target := TRUE;
24871          --
24872          if l_process_date between r_SHR_unique.information2 and r_SHR_unique.information3 then
24873                l_update := true;
24874                if r_SHR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
24875                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'SCHEDD_HRS_RT_ID'
24876                then
24877                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'SCHEDD_HRS_RT_ID' ;
24878                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_SHR_unique.information1 ;
24879                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_SHR_unique.information1 ;
24880                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
24881                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_SHR_unique.table_route_id;
24882                   --
24883                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
24884                   --
24885                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
24886                   --
24887                   -- log_data('SHR',l_new_value,l_prefix || r_SHR_unique.name|| l_suffix,'REUSED');
24888                   --
24889                end if ;
24890                hr_utility.set_location( 'found record for update',10);
24891            --
24892          else
24893            --
24894            l_update := false;
24895            --
24896          end if;
24897        else
24898          --
24899          --UPD END
24900        if p_reuse_object_flag = 'Y' then
24901          if c_SHR_min_max_dates%found then
24902            -- cursor to find the object
24903            open c_find_SHR_in_target( l_min_esd,l_max_eed,
24904                                  p_target_business_group_id, nvl(l_schedd_hrs_rt_id, -999)  ) ;
24905            fetch c_find_SHR_in_target into l_new_value ;
24906            if c_find_SHR_in_target%found then
24907              --
24908              --TEMPIK
24909              l_dt_rec_found :=   dt_api.check_min_max_dates
24910                  (p_base_table_name => 'BEN_SCHEDD_HRS_RT_F',
24911                   p_base_key_column => 'SCHEDD_HRS_RT_ID',
24912                   p_base_key_value  => l_new_value,
24913                   p_from_date       => l_min_esd,
24914                   p_to_date         => l_max_eed );
24915              if l_dt_rec_found THEN
24916              --END TEMPIK
24917              if r_SHR_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
24918                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'SCHEDD_HRS_RT_ID'  then
24919                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'SCHEDD_HRS_RT_ID' ;
24920                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_SHR_unique.information1 ;
24921                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
24922                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
24923                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_SHR_unique.table_route_id;
24924                 --
24925                 -- 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) ;
24926                 --
24927                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
24928              end if ;
24929              --
24930              l_object_found_in_target := true ;
24931              --TEMPIK
24932              end if; -- l_dt_rec_found
24933              --END TEMPIK
24934            end if;
24935            close c_find_SHR_in_target ;
24936          --
24937          end if;
24938        end if ;
24939        --
24940        end if;
24941        close c_SHR_min_max_dates ;
24942        if not l_object_found_in_target OR l_update   then
24943          --
24944          l_current_pk_id := r_SHR.information1;
24945          --
24946          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
24947          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
24948          --
24949          if l_current_pk_id =  l_prev_pk_id  then
24950            --
24951            l_first_rec := false ;
24952            --
24953          else
24954            --
24955            l_first_rec := true ;
24956            --
24957          end if ;
24958          --
24959 
24960          l_effective_date := r_SHR.information2;
24961          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
24962               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
24963            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
24964          end if;
24965 
24966          if l_first_rec and not l_update then
24967            -- Call Create routine.
24968            hr_utility.set_location(' BEN_SCHEDD_HRS_RT_F CREATE_SCHEDD_HRS_RATE ',20);
24969            BEN_SCHEDD_HRS_RATE_API.CREATE_SCHEDD_HRS_RATE(
24970              --
24971              P_VALIDATE               => false
24972              ,P_EFFECTIVE_DATE        => l_effective_date
24973              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
24974              --
24975              ,P_DETERMINATION_CD      => r_SHR.INFORMATION12
24976              ,P_DETERMINATION_RL      => l_DETERMINATION_RL
24977              ,P_EXCLD_FLAG      => r_SHR.INFORMATION13
24978              ,P_FREQ_CD      => r_SHR.INFORMATION14
24979              ,P_HRS_NUM      => r_SHR.INFORMATION288
24980              ,P_MAX_HRS_NUM      => r_SHR.INFORMATION287
24981              ,P_ORDR_NUM      => r_SHR.INFORMATION260
24982              ,P_ROUNDING_CD      => r_SHR.INFORMATION11
24983              ,P_ROUNDING_RL      => l_ROUNDING_RL
24984              ,P_SCHEDD_HRS_RL      => l_SCHEDD_HRS_RL
24985              ,P_SCHEDD_HRS_RT_ID      => l_schedd_hrs_rt_id
24986              ,P_SHR_ATTRIBUTE1      => r_SHR.INFORMATION111
24987              ,P_SHR_ATTRIBUTE10      => r_SHR.INFORMATION120
24988              ,P_SHR_ATTRIBUTE11      => r_SHR.INFORMATION121
24989              ,P_SHR_ATTRIBUTE12      => r_SHR.INFORMATION122
24990              ,P_SHR_ATTRIBUTE13      => r_SHR.INFORMATION123
24991              ,P_SHR_ATTRIBUTE14      => r_SHR.INFORMATION124
24992              ,P_SHR_ATTRIBUTE15      => r_SHR.INFORMATION125
24993              ,P_SHR_ATTRIBUTE16      => r_SHR.INFORMATION126
24994              ,P_SHR_ATTRIBUTE17      => r_SHR.INFORMATION127
24995              ,P_SHR_ATTRIBUTE18      => r_SHR.INFORMATION128
24996              ,P_SHR_ATTRIBUTE19      => r_SHR.INFORMATION129
24997              ,P_SHR_ATTRIBUTE2      => r_SHR.INFORMATION112
24998              ,P_SHR_ATTRIBUTE20      => r_SHR.INFORMATION130
24999              ,P_SHR_ATTRIBUTE21      => r_SHR.INFORMATION131
25000              ,P_SHR_ATTRIBUTE22      => r_SHR.INFORMATION132
25001              ,P_SHR_ATTRIBUTE23      => r_SHR.INFORMATION133
25002              ,P_SHR_ATTRIBUTE24      => r_SHR.INFORMATION134
25003              ,P_SHR_ATTRIBUTE25      => r_SHR.INFORMATION135
25004              ,P_SHR_ATTRIBUTE26      => r_SHR.INFORMATION136
25005              ,P_SHR_ATTRIBUTE27      => r_SHR.INFORMATION137
25006              ,P_SHR_ATTRIBUTE28      => r_SHR.INFORMATION138
25007              ,P_SHR_ATTRIBUTE29      => r_SHR.INFORMATION139
25008              ,P_SHR_ATTRIBUTE3      => r_SHR.INFORMATION113
25009              ,P_SHR_ATTRIBUTE30      => r_SHR.INFORMATION140
25010              ,P_SHR_ATTRIBUTE4      => r_SHR.INFORMATION114
25011              ,P_SHR_ATTRIBUTE5      => r_SHR.INFORMATION115
25012              ,P_SHR_ATTRIBUTE6      => r_SHR.INFORMATION116
25013              ,P_SHR_ATTRIBUTE7      => r_SHR.INFORMATION117
25014              ,P_SHR_ATTRIBUTE8      => r_SHR.INFORMATION118
25015              ,P_SHR_ATTRIBUTE9      => r_SHR.INFORMATION119
25016              ,P_SHR_ATTRIBUTE_CATEGORY      => r_SHR.INFORMATION110
25017              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
25018              --
25019              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
25020              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
25021              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
25022            );
25023            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
25024            -- Update all relevent cer records with new pk_id
25025            hr_utility.set_location('Before plsql table ',222);
25026            hr_utility.set_location('new_value id '||l_schedd_hrs_rt_id,222);
25027            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'SCHEDD_HRS_RT_ID' ;
25028            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_SHR.information1 ;
25029            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_SCHEDD_HRS_RT_ID ;
25030            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
25031            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_SHR_unique.table_route_id;
25032            hr_utility.set_location('After plsql table ',222);
25033            --
25034            -- 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 ) ;
25035            --
25036            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
25037            --
25038          else
25039            --
25040            -- Call Update routine for the pk_id created in prev run .
25041            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
25042            --UPD STSHR
25043            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
25044            --
25045            if l_update then
25046              --
25047              l_datetrack_mode := r_SHR.datetrack_mode ;
25048              --
25049              get_dt_modes(
25050                p_effective_date        => l_process_date,
25051                p_effective_end_date    => r_SHR.information3,
25052                p_effective_start_date  => r_SHR.information2,
25053                p_dml_operation         => r_SHR.dml_operation,
25054                p_datetrack_mode        => l_datetrack_mode );
25055            --    p_update                => l_update
25056              --
25057              l_effective_date := l_process_date;
25058              l_SCHEDD_HRS_RT_ID   := r_SHR.information1;
25059              l_object_version_number := r_SHR.information265;
25060              --
25061            end if;
25062            --
25063            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
25064            --
25065            IF l_update OR l_dml_operation <> 'UPDATE' THEN
25066            --UPD END
25067            hr_utility.set_location(' BEN_SCHEDD_HRS_RT_F UPDATE_SCHEDD_HRS_RATE ',30);
25068            BEN_SCHEDD_HRS_RATE_API.UPDATE_SCHEDD_HRS_RATE(
25069              --
25070              P_VALIDATE               => false
25071              ,P_EFFECTIVE_DATE        => l_effective_date
25072              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
25073              --
25074              ,P_DETERMINATION_CD      => r_SHR.INFORMATION12
25075              ,P_DETERMINATION_RL      => l_DETERMINATION_RL
25076              ,P_EXCLD_FLAG      => r_SHR.INFORMATION13
25077              ,P_FREQ_CD      => r_SHR.INFORMATION14
25078              ,P_HRS_NUM      => r_SHR.INFORMATION288
25079              ,P_MAX_HRS_NUM      => r_SHR.INFORMATION287
25080              ,P_ORDR_NUM      => r_SHR.INFORMATION260
25081              ,P_ROUNDING_CD      => r_SHR.INFORMATION11
25082              ,P_ROUNDING_RL      => l_ROUNDING_RL
25083              ,P_SCHEDD_HRS_RL      => l_SCHEDD_HRS_RL
25084              ,P_SCHEDD_HRS_RT_ID      => l_schedd_hrs_rt_id
25085              ,P_SHR_ATTRIBUTE1      => r_SHR.INFORMATION111
25086              ,P_SHR_ATTRIBUTE10      => r_SHR.INFORMATION120
25087              ,P_SHR_ATTRIBUTE11      => r_SHR.INFORMATION121
25088              ,P_SHR_ATTRIBUTE12      => r_SHR.INFORMATION122
25089              ,P_SHR_ATTRIBUTE13      => r_SHR.INFORMATION123
25090              ,P_SHR_ATTRIBUTE14      => r_SHR.INFORMATION124
25091              ,P_SHR_ATTRIBUTE15      => r_SHR.INFORMATION125
25092              ,P_SHR_ATTRIBUTE16      => r_SHR.INFORMATION126
25093              ,P_SHR_ATTRIBUTE17      => r_SHR.INFORMATION127
25094              ,P_SHR_ATTRIBUTE18      => r_SHR.INFORMATION128
25095              ,P_SHR_ATTRIBUTE19      => r_SHR.INFORMATION129
25096              ,P_SHR_ATTRIBUTE2      => r_SHR.INFORMATION112
25097              ,P_SHR_ATTRIBUTE20      => r_SHR.INFORMATION130
25098              ,P_SHR_ATTRIBUTE21      => r_SHR.INFORMATION131
25099              ,P_SHR_ATTRIBUTE22      => r_SHR.INFORMATION132
25100              ,P_SHR_ATTRIBUTE23      => r_SHR.INFORMATION133
25101              ,P_SHR_ATTRIBUTE24      => r_SHR.INFORMATION134
25102              ,P_SHR_ATTRIBUTE25      => r_SHR.INFORMATION135
25103              ,P_SHR_ATTRIBUTE26      => r_SHR.INFORMATION136
25104              ,P_SHR_ATTRIBUTE27      => r_SHR.INFORMATION137
25105              ,P_SHR_ATTRIBUTE28      => r_SHR.INFORMATION138
25106              ,P_SHR_ATTRIBUTE29      => r_SHR.INFORMATION139
25107              ,P_SHR_ATTRIBUTE3      => r_SHR.INFORMATION113
25108              ,P_SHR_ATTRIBUTE30      => r_SHR.INFORMATION140
25109              ,P_SHR_ATTRIBUTE4      => r_SHR.INFORMATION114
25110              ,P_SHR_ATTRIBUTE5      => r_SHR.INFORMATION115
25111              ,P_SHR_ATTRIBUTE6      => r_SHR.INFORMATION116
25112              ,P_SHR_ATTRIBUTE7      => r_SHR.INFORMATION117
25113              ,P_SHR_ATTRIBUTE8      => r_SHR.INFORMATION118
25114              ,P_SHR_ATTRIBUTE9      => r_SHR.INFORMATION119
25115              ,P_SHR_ATTRIBUTE_CATEGORY      => r_SHR.INFORMATION110
25116              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
25117              --
25118              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
25119              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
25120              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
25121              ,P_DATETRACK_MODE        => l_datetrack_mode
25122            );
25123            --
25124            end if;
25125          end if;
25126          --
25127          -- Delete the row if it is end dated.
25128          --
25129          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
25130              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
25131              trunc(l_max_eed) = r_SHR.information3) then
25132              --
25133              BEN_SCHEDD_HRS_RATE_API.delete_SCHEDD_HRS_RATE(
25134                 --
25135                 p_validate                       => false
25136                 ,p_schedd_hrs_rt_id                   => l_schedd_hrs_rt_id
25137                 ,p_effective_start_date           => l_effective_start_date
25138                 ,p_effective_end_date             => l_effective_end_date
25139                 ,p_object_version_number          => l_object_version_number
25140                 ,p_effective_date                 => l_max_eed
25141                 ,p_datetrack_mode                 => hr_api.g_delete
25142                 --
25143                 );
25144                 --
25145          end if;
25146          --
25147          l_prev_pk_id := l_current_pk_id ;
25148          --
25149        end if;
25150        --
25151      end if;
25152      --
25153    end loop;
25154    --
25155  exception when others then
25156     --
25157     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'SHR',r_shr.information5 );
25158     --
25159  end create_SHR_rows;
25160 
25161    --
25162    ---------------------------------------------------------------
25163    ----------------------< create_QIG_rows >-----------------------
25164    ---------------------------------------------------------------
25165    --
25166    procedure create_QIG_rows
25167    (
25168          p_validate                       in  number     default 0
25169         ,p_copy_entity_txn_id             in  number
25170         ,p_effective_date                 in  date
25171         ,p_prefix_suffix_text             in  varchar2  default null
25172         ,p_reuse_object_flag              in  varchar2  default null
25173         ,p_target_business_group_id       in  varchar2  default null
25174         ,p_prefix_suffix_cd               in  varchar2  default null
25175    ) is
25176    --
25177    l_VRBL_RT_PRFL_ID  number;
25178    l_EXCLD_FLAG     varchar2(100);
25179    l_QUAR_IN_GRADE_CD varchar2(100);
25180    l_ORDR_NUM         varchar2(100);
25181    --
25182    cursor c_unique_QIG(l_table_alias varchar2) is
25183    select distinct cpe.information1,
25184      cpe.information2,
25185      cpe.information3,
25186      cpe.table_route_id
25187    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
25188         pqh_table_route tr
25189    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
25190    and   cpe.table_route_id     = tr.table_route_id
25191    -- and   tr.where_clause        = l_BEN_QUA_IN_GR_RT_F
25192    and tr.table_alias = l_table_alias
25193    and   cpe.number_of_copies   = 1 -- ADDITION
25194    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
25195    order by information1, information2; --added for bug: 5151945
25196    --
25197    --
25198    cursor c_QIG_min_max_dates(c_table_route_id  number,
25199                 c_information1   Number) is
25200    select
25201      min(cpe.information2) min_esd,
25202      max(cpe.information3) min_eed
25203    from ben_copy_entity_results cpe
25204    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
25205    and   cpe.table_route_id     = c_table_route_id
25206    and   cpe.information1       = c_information1 ;
25207    --
25208    cursor c_QIG(c_table_route_id  number,
25209                 c_information1   number,
25210                 c_information2   Date,
25211                 c_information3   date)  is
25212    select
25213      cpe.*
25214    from ben_copy_entity_results cpe
25215    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
25216    and   cpe.table_route_id     = c_table_route_id
25217    and   cpe.information1       = c_information1
25218    and   cpe.information2       = c_information2
25219    and   cpe.information3       = c_information3
25220    and rownum = 1 ;
25221    -- Date Track target record
25222    cursor c_find_QIG_in_target(
25223                                 c_effective_start_date    date,
25224                                 c_effective_end_date      date,
25225                                 c_business_group_id       number,
25226                                 c_new_pk_id               number) is
25227    select
25228      QIG.qua_in_gr_rt_id new_value
25229    from BEN_QUA_IN_GR_RT_F QIG
25230    where
25231    QIG.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
25232    QIG.QUAR_IN_GRADE_CD     = l_QUAR_IN_GRADE_CD  and
25233    QIG.ORDR_NUM             =  l_ORDR_NUM and
25234    QIG.business_group_id  = c_business_group_id
25235    and   QIG.qua_in_gr_rt_id  <> c_new_pk_id
25236 --TEMPIK
25237    and c_effective_start_date between effective_start_date
25238                             and effective_end_date ;
25239 --END TEMPIK
25240 /*TEMPIK
25241    and exists ( select null
25242                 from BEN_QUA_IN_GR_RT_F QIG1
25243                 where
25244                 QIG1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
25245                 QIG1.QUAR_IN_GRADE_CD     = l_QUAR_IN_GRADE_CD  and
25246                 QIG1.ORDR_NUM             =  l_ORDR_NUM and
25247                 QIG1.business_group_id  = c_business_group_id
25248                 and   QIG1.effective_start_date <= c_effective_start_date )
25249    and exists ( select null
25250                 from BEN_QUA_IN_GR_RT_F QIG2
25251                 where
25252                 QIG2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
25253                 QIG2.QUAR_IN_GRADE_CD     = l_QUAR_IN_GRADE_CD  and
25254                 QIG2.ORDR_NUM             =  l_ORDR_NUM and
25255                 QIG2.business_group_id  = c_business_group_id
25256                 and   QIG2.effective_end_date >= c_effective_end_date )
25257                 ;
25258 TEMPIK */
25259    --TEMPIK
25260    l_dt_rec_found            boolean ;
25261    --END TEMPIK
25262    --
25263    l_current_pk_id           number := null ;
25264    --UPD START
25265    --
25266    l_update                  boolean      := false ;
25267    l_datetrack_mode          varchar2(80) := hr_api.g_update;
25268    l_process_date            date;
25269    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
25270    --
25271    --UPD END
25272    l_prev_pk_id              number := null ;
25273    l_first_rec               boolean := true ;
25274    r_QIG                     c_QIG%rowtype;
25275    l_qua_in_gr_rt_id             number ;
25276    l_object_version_number   number ;
25277    l_effective_start_date    date ;
25278    l_effective_end_date      date ;
25279    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
25280    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
25281    l_new_value               number(15);
25282    l_object_found_in_target  boolean := false ;
25283    l_min_esd                 date;
25284    l_max_eed                 date;
25285    l_effective_date          date;
25286    --
25287  begin
25288    -- Initialization
25289    l_object_found_in_target := false ;
25290    -- End Initialization
25291    -- Derive the prefix - sufix
25292    if   p_prefix_suffix_cd = 'PREFIX' then
25293      l_prefix  := p_prefix_suffix_text ;
25294    elsif p_prefix_suffix_cd = 'SUFFIX' then
25295      l_suffix   := p_prefix_suffix_text ;
25296    else
25297      l_prefix := null ;
25298      l_suffix  := null ;
25299    end if ;
25300    -- End Prefix Sufix derivation
25301    for r_QIG_unique in c_unique_QIG('QIG') loop
25302 
25303      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
25304         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
25305          r_QIG_unique.information3 >=
25306                  ben_pd_copy_to_ben_one.g_copy_effective_date)
25307         ) then
25308        --
25309        hr_utility.set_location(' r_QIG_unique.table_route_id '||r_QIG_unique.table_route_id,10);
25310        hr_utility.set_location(' r_QIG_unique.information1 '||r_QIG_unique.information1,10);
25311        hr_utility.set_location( 'r_QIG_unique.information2 '||r_QIG_unique.information2,10);
25312        hr_utility.set_location( 'r_QIG_unique.information3 '||r_QIG_unique.information3,10);
25313        -- If reuse objects flag is 'Y' then check for the object in the target business group
25314        -- if found insert the record into PLSql table and exit the loop else try create the
25315        -- object in the target business group
25316        --
25317        l_object_found_in_target := false ;
25318        l_min_esd := null ;
25319        l_max_eed := null ;
25320        open c_QIG_min_max_dates(r_QIG_unique.table_route_id, r_QIG_unique.information1 ) ;
25321        fetch c_QIG_min_max_dates into l_min_esd,l_max_eed ;
25322        --
25323 
25324        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
25325             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
25326          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
25327        end if;
25328         l_min_esd := greatest(l_min_esd,r_QIG_unique.information2);
25329        open c_QIG(r_QIG_unique.table_route_id,
25330                 r_QIG_unique.information1,
25331                 r_QIG_unique.information2,
25332                 r_QIG_unique.information3 ) ;
25333        --
25334        fetch c_QIG into r_QIG ;
25335        --
25336        close c_QIG ;
25337        --
25338        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_QIG.information262,r_QIG_unique.dml_operation);
25339        l_EXCLD_FLAG      := r_QIG.information12;
25340        l_QUAR_IN_GRADE_CD     := r_QIG.INFORMATION11;
25341        l_ORDR_NUM      := r_QIG.INFORMATION257;
25342        --UPD STQIG
25343        l_update := false;
25344        l_process_date := p_effective_date;
25345        l_dml_operation:= r_QIG_unique.dml_operation ;
25346        --
25347        if l_dml_operation = 'UPDATE' then
25348          --
25349          l_object_found_in_target := TRUE;
25350          --
25351          if l_process_date between r_QIG_unique.information2 and r_QIG_unique.information3 then
25352                l_update := true;
25353                if r_QIG_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
25354                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'QUA_IN_GR_RT_ID'
25355                then
25356                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'QUA_IN_GR_RT_ID' ;
25357                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_QIG_unique.information1 ;
25358                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_QIG_unique.information1 ;
25359                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
25360                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_QIG_unique.table_route_id;
25361                   --
25362                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
25363                   --
25364                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
25365                   --
25366                   -- log_data('QIG',l_new_value,l_prefix || r_QIG_unique.name|| l_suffix,'REUSED');
25367                   --
25368                end if ;
25369                hr_utility.set_location( 'found record for update',10);
25370            --
25371          else
25372            --
25373            l_update := false;
25374            --
25375          end if;
25376        else
25377          --
25378          --UPD END
25379        if p_reuse_object_flag = 'Y' then
25380          if c_QIG_min_max_dates%found then
25381            -- cursor to find the object
25382            open c_find_QIG_in_target( l_min_esd,l_max_eed,
25383                                  p_target_business_group_id, nvl(l_qua_in_gr_rt_id, -999)  ) ;
25384            fetch c_find_QIG_in_target into l_new_value ;
25385            if c_find_QIG_in_target%found then
25386              --
25387              --TEMPIK
25388              l_dt_rec_found :=   dt_api.check_min_max_dates
25389                  (p_base_table_name => 'BEN_QUA_IN_GR_RT_F',
25390                   p_base_key_column => 'QUA_IN_GR_RT_ID',
25391                   p_base_key_value  => l_new_value,
25392                   p_from_date       => l_min_esd,
25393                   p_to_date         => l_max_eed );
25394              if l_dt_rec_found THEN
25395              --END TEMPIK
25396              if r_QIG_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
25397                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'QUA_IN_GR_RT_ID'  then
25398                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'QUA_IN_GR_RT_ID' ;
25399                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_QIG_unique.information1 ;
25400                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
25401                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
25402                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_QIG_unique.table_route_id;
25403                 --
25404                 -- 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) ;
25405                 --
25406                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
25407              end if ;
25408              --
25409              l_object_found_in_target := true ;
25410              --TEMPIK
25411              end if; -- l_dt_rec_found
25412              --END TEMPIK
25413            end if;
25414            close c_find_QIG_in_target ;
25415          --
25416          end if;
25417        end if ;
25418        --
25419        end if;
25420        close c_QIG_min_max_dates ;
25421        if not l_object_found_in_target OR l_update   then
25422          --
25423          l_current_pk_id := r_QIG.information1;
25424          --
25425          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
25426          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
25427          --
25428          if l_current_pk_id =  l_prev_pk_id  then
25429            --
25430            l_first_rec := false ;
25431            --
25432          else
25433            --
25434            l_first_rec := true ;
25435            --
25436          end if ;
25437          --
25438 
25439          l_effective_date := r_QIG.information2;
25440          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
25441               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
25442            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
25443          end if;
25444 
25445          if l_first_rec and not l_update then
25446            -- Call Create routine.
25447            hr_utility.set_location(' BEN_QUA_IN_GR_RT_F CREATE_QUA_IN_GR_RT ',20);
25448            BEN_QUA_IN_GR_RT_API.CREATE_QUA_IN_GR_RT(
25449              --
25450              P_VALIDATE               => false
25451              ,P_EFFECTIVE_DATE        => l_effective_date
25452              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
25453              --
25454              ,P_EXCLD_FLAG      => r_QIG.INFORMATION12
25455              ,P_ORDR_NUM      => r_QIG.INFORMATION257
25456              ,P_QIG_ATTRIBUTE1      => r_QIG.INFORMATION111
25457              ,P_QIG_ATTRIBUTE10      => r_QIG.INFORMATION120
25458              ,P_QIG_ATTRIBUTE11      => r_QIG.INFORMATION121
25459              ,P_QIG_ATTRIBUTE12      => r_QIG.INFORMATION122
25460              ,P_QIG_ATTRIBUTE13      => r_QIG.INFORMATION123
25461              ,P_QIG_ATTRIBUTE14      => r_QIG.INFORMATION124
25462              ,P_QIG_ATTRIBUTE15      => r_QIG.INFORMATION125
25463              ,P_QIG_ATTRIBUTE16      => r_QIG.INFORMATION126
25464              ,P_QIG_ATTRIBUTE17      => r_QIG.INFORMATION127
25465              ,P_QIG_ATTRIBUTE18      => r_QIG.INFORMATION128
25466              ,P_QIG_ATTRIBUTE19      => r_QIG.INFORMATION129
25467              ,P_QIG_ATTRIBUTE2      => r_QIG.INFORMATION112
25468              ,P_QIG_ATTRIBUTE20      => r_QIG.INFORMATION130
25469              ,P_QIG_ATTRIBUTE21      => r_QIG.INFORMATION131
25470              ,P_QIG_ATTRIBUTE22      => r_QIG.INFORMATION132
25471              ,P_QIG_ATTRIBUTE23      => r_QIG.INFORMATION133
25472              ,P_QIG_ATTRIBUTE24      => r_QIG.INFORMATION134
25473              ,P_QIG_ATTRIBUTE25      => r_QIG.INFORMATION135
25474              ,P_QIG_ATTRIBUTE26      => r_QIG.INFORMATION136
25475              ,P_QIG_ATTRIBUTE27      => r_QIG.INFORMATION137
25476              ,P_QIG_ATTRIBUTE28      => r_QIG.INFORMATION138
25477              ,P_QIG_ATTRIBUTE29      => r_QIG.INFORMATION139
25478              ,P_QIG_ATTRIBUTE3      => r_QIG.INFORMATION113
25479              ,P_QIG_ATTRIBUTE30      => r_QIG.INFORMATION140
25480              ,P_QIG_ATTRIBUTE4      => r_QIG.INFORMATION114
25481              ,P_QIG_ATTRIBUTE5      => r_QIG.INFORMATION115
25482              ,P_QIG_ATTRIBUTE6      => r_QIG.INFORMATION116
25483              ,P_QIG_ATTRIBUTE7      => r_QIG.INFORMATION117
25484              ,P_QIG_ATTRIBUTE8      => r_QIG.INFORMATION118
25485              ,P_QIG_ATTRIBUTE9      => r_QIG.INFORMATION119
25486              ,P_QIG_ATTRIBUTE_CATEGORY      => r_QIG.INFORMATION110
25487              ,P_QUAR_IN_GRADE_CD      => r_QIG.INFORMATION11
25488              ,P_QUA_IN_GR_RT_ID      => l_qua_in_gr_rt_id
25489              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
25490              --
25491              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
25492              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
25493              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
25494            );
25495            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
25496            -- Update all relevent cer records with new pk_id
25497            hr_utility.set_location('Before plsql table ',222);
25498            hr_utility.set_location('new_value id '||l_qua_in_gr_rt_id,222);
25499            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'QUA_IN_GR_RT_ID' ;
25500            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_QIG.information1 ;
25501            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_QUA_IN_GR_RT_ID ;
25502            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
25503            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_QIG_unique.table_route_id;
25504            hr_utility.set_location('After plsql table ',222);
25505            --
25506            -- 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 ) ;
25507            --
25508            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
25509            --
25510          else
25511            --
25512            -- Call Update routine for the pk_id created in prev run .
25513            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
25514            --UPD STQIG
25515            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
25516            --
25517            if l_update then
25518              --
25519              l_datetrack_mode := r_QIG.datetrack_mode ;
25520              --
25521              get_dt_modes(
25522                p_effective_date        => l_process_date,
25523                p_effective_end_date    => r_QIG.information3,
25524                p_effective_start_date  => r_QIG.information2,
25525                p_dml_operation         => r_QIG.dml_operation,
25526                p_datetrack_mode        => l_datetrack_mode );
25527            --    p_update                => l_update
25528              --
25529              l_effective_date := l_process_date;
25530              l_QUA_IN_GR_RT_ID   := r_QIG.information1;
25531              l_object_version_number := r_QIG.information265;
25532              --
25533            end if;
25534            --
25535            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
25536            --
25537            IF l_update OR l_dml_operation <> 'UPDATE' THEN
25538            --UPD END
25539            hr_utility.set_location(' BEN_QUA_IN_GR_RT_F UPDATE_QUA_IN_GR_RT ',30);
25540            BEN_QUA_IN_GR_RT_API.UPDATE_QUA_IN_GR_RT(
25541              --
25542              P_VALIDATE               => false
25543              ,P_EFFECTIVE_DATE        => l_effective_date
25544              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
25545              --
25546              ,P_EXCLD_FLAG      => r_QIG.INFORMATION12
25547              ,P_ORDR_NUM      => r_QIG.INFORMATION257
25548              ,P_QIG_ATTRIBUTE1      => r_QIG.INFORMATION111
25549              ,P_QIG_ATTRIBUTE10      => r_QIG.INFORMATION120
25550              ,P_QIG_ATTRIBUTE11      => r_QIG.INFORMATION121
25551              ,P_QIG_ATTRIBUTE12      => r_QIG.INFORMATION122
25552              ,P_QIG_ATTRIBUTE13      => r_QIG.INFORMATION123
25553              ,P_QIG_ATTRIBUTE14      => r_QIG.INFORMATION124
25554              ,P_QIG_ATTRIBUTE15      => r_QIG.INFORMATION125
25555              ,P_QIG_ATTRIBUTE16      => r_QIG.INFORMATION126
25556              ,P_QIG_ATTRIBUTE17      => r_QIG.INFORMATION127
25557              ,P_QIG_ATTRIBUTE18      => r_QIG.INFORMATION128
25558              ,P_QIG_ATTRIBUTE19      => r_QIG.INFORMATION129
25559              ,P_QIG_ATTRIBUTE2      => r_QIG.INFORMATION112
25560              ,P_QIG_ATTRIBUTE20      => r_QIG.INFORMATION130
25561              ,P_QIG_ATTRIBUTE21      => r_QIG.INFORMATION131
25562              ,P_QIG_ATTRIBUTE22      => r_QIG.INFORMATION132
25563              ,P_QIG_ATTRIBUTE23      => r_QIG.INFORMATION133
25564              ,P_QIG_ATTRIBUTE24      => r_QIG.INFORMATION134
25565              ,P_QIG_ATTRIBUTE25      => r_QIG.INFORMATION135
25566              ,P_QIG_ATTRIBUTE26      => r_QIG.INFORMATION136
25567              ,P_QIG_ATTRIBUTE27      => r_QIG.INFORMATION137
25568              ,P_QIG_ATTRIBUTE28      => r_QIG.INFORMATION138
25569              ,P_QIG_ATTRIBUTE29      => r_QIG.INFORMATION139
25570              ,P_QIG_ATTRIBUTE3      => r_QIG.INFORMATION113
25571              ,P_QIG_ATTRIBUTE30      => r_QIG.INFORMATION140
25572              ,P_QIG_ATTRIBUTE4      => r_QIG.INFORMATION114
25573              ,P_QIG_ATTRIBUTE5      => r_QIG.INFORMATION115
25574              ,P_QIG_ATTRIBUTE6      => r_QIG.INFORMATION116
25575              ,P_QIG_ATTRIBUTE7      => r_QIG.INFORMATION117
25576              ,P_QIG_ATTRIBUTE8      => r_QIG.INFORMATION118
25577              ,P_QIG_ATTRIBUTE9      => r_QIG.INFORMATION119
25578              ,P_QIG_ATTRIBUTE_CATEGORY      => r_QIG.INFORMATION110
25579              ,P_QUAR_IN_GRADE_CD      => r_QIG.INFORMATION11
25580              ,P_QUA_IN_GR_RT_ID      => l_qua_in_gr_rt_id
25581              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
25582              --
25583              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
25584              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
25585              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
25586              ,P_DATETRACK_MODE        => l_datetrack_mode
25587            );
25588            --
25589            end if;
25590          end if;
25591          --
25592          -- Delete the row if it is end dated.
25593          --
25594          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
25595              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
25596              trunc(l_max_eed) = r_QIG.information3) then
25597              --
25598              BEN_QUA_IN_GR_RT_API.delete_QUA_IN_GR_RT(
25599                 --
25600                 p_validate                       => false
25601                 ,p_qua_in_gr_rt_id                   => l_qua_in_gr_rt_id
25602                 ,p_effective_start_date           => l_effective_start_date
25603                 ,p_effective_end_date             => l_effective_end_date
25604                 ,p_object_version_number          => l_object_version_number
25605                 ,p_effective_date                 => l_max_eed
25606                 ,p_datetrack_mode                 => hr_api.g_delete
25607                 --
25608                 );
25609                 --
25610          end if;
25611          --
25612          l_prev_pk_id := l_current_pk_id ;
25613          --
25614        end if;
25615        --
25616      end if;
25617      --
25618    end loop;
25619    --
25620  exception when others then
25621     --
25622     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'QIG',r_qig.information5 );
25623     --
25624  end create_QIG_rows;
25625 
25626    ---------------------------------------------------------------
25627    ----------------------< create_PRR_rows >-----------------------
25628    ---------------------------------------------------------------
25629    --
25630    procedure create_PRR_rows
25631    (
25632          p_validate                       in  number     default 0
25633         ,p_copy_entity_txn_id             in  number
25634         ,p_effective_date                 in  date
25635         ,p_prefix_suffix_text             in  varchar2  default null
25636         ,p_reuse_object_flag              in  varchar2  default null
25637         ,p_target_business_group_id       in  varchar2  default null
25638         ,p_prefix_suffix_cd               in  varchar2  default null
25639    ) is
25640    --
25641    l_VRBL_RT_PRFL_ID  number;
25642    l_EVENT_TYPE     varchar2(100);
25643    l_EXCLD_FLAG     varchar2(100);
25644    l_ORDR_NUM       number;
25645    l_PERF_RTNG_CD   varchar2(100);
25646    --
25647    cursor c_unique_PRR(l_table_alias varchar2) is
25648    select distinct cpe.information1,
25649      cpe.information2,
25650      cpe.information3,
25651      cpe.table_route_id
25652    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
25653         pqh_table_route tr
25654    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
25655    and   cpe.table_route_id     = tr.table_route_id
25656    -- and   tr.where_clause        = l_BEN_PERF_RTNG_RT_F
25657    and tr.table_alias = l_table_alias
25658    and   cpe.number_of_copies   = 1 -- ADDITION
25659    group by cpe.information1,cpe.information2,cpe.information3, cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
25660    order by information1, information2; --added for bug: 5151945
25661    --
25662    --
25663    cursor c_PRR_min_max_dates(c_table_route_id  number,
25664                 c_information1   number) is
25665    select
25666      min(cpe.information2) min_esd,
25667      max(cpe.information3) min_eed
25668    from ben_copy_entity_results cpe
25669    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
25670    and   cpe.table_route_id     = c_table_route_id
25671    and   cpe.information1       = c_information1 ;
25672    --
25673    cursor c_PRR(c_table_route_id  number,
25674                 c_information1    number,
25675                 c_information2   Date,
25676                 c_information3   Date)  is
25677    select
25678      cpe.*
25679    from ben_copy_entity_results cpe
25680    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
25681    and   cpe.table_route_id     = c_table_route_id
25682    and   cpe.information1       = c_information1
25683    and   cpe.information2       = c_information2
25684    and   cpe.information3       = c_information3
25685    and rownum = 1 ;
25686    -- Date Track target record
25687    cursor c_find_PRR_in_target(
25688                                 c_effective_start_date    date,
25689                                 c_effective_end_date      date,
25690                                 c_business_group_id       number,
25691                                 c_new_pk_id               number) is
25692    select
25693      PRR.perf_rtng_rt_id new_value
25694    from BEN_PERF_RTNG_RT_F PRR
25695    where
25696    PRR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
25697    PRR.ORDR_NUM          = l_ORDR_NUM       and
25698    PRR.EVENT_TYPE          = l_EVENT_TYPE       and
25699    PRR.PERF_RTNG_CD        = l_PERF_RTNG_CD       and
25700    PRR.business_group_id  = c_business_group_id
25701    and   PRR.perf_rtng_rt_id  <> c_new_pk_id
25702 --TEMPIK
25703    and c_effective_start_date between effective_start_date
25704                             and effective_end_date ;
25705 --END TEMPIK
25706 /*TEMPIK
25707    and exists ( select null
25708                 from BEN_PERF_RTNG_RT_F PRR1
25709                 where
25710                 PRR1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
25711                 PRR1.ORDR_NUM          = l_ORDR_NUM       and
25712                 PRR1.EVENT_TYPE          = l_EVENT_TYPE       and
25713                 PRR1.PERF_RTNG_CD        = l_PERF_RTNG_CD       and
25714                 PRR1.business_group_id  = c_business_group_id
25715                 and   PRR1.effective_start_date <= c_effective_start_date )
25716    and exists ( select null
25717                 from BEN_PERF_RTNG_RT_F PRR2
25718                 where
25719                 PRR2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
25720                 PRR2.ORDR_NUM          = l_ORDR_NUM       and
25721                 PRR2.EVENT_TYPE          = l_EVENT_TYPE       and
25722                 PRR2.PERF_RTNG_CD        = l_PERF_RTNG_CD       and
25723                 PRR2.business_group_id  = c_business_group_id
25724                 and   PRR2.effective_end_date >= c_effective_end_date )
25725                 ;
25726 TEMPIK */
25727    --TEMPIK
25728    l_dt_rec_found            boolean ;
25729    --END TEMPIK
25730    --
25731    l_current_pk_id           number := null ;
25732    --UPD START
25733    --
25734    l_update                  boolean      := false ;
25735    l_datetrack_mode          varchar2(80) := hr_api.g_update;
25736    l_process_date            date;
25737    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
25738    --
25739    --UPD END
25740    l_prev_pk_id              number := null ;
25741    l_first_rec               boolean := true ;
25742    r_PRR                     c_PRR%rowtype;
25743    l_perf_rtng_rt_id             number ;
25744    l_object_version_number   number ;
25745    l_effective_start_date    date ;
25746    l_effective_end_date      date ;
25747    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
25748    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
25749    l_new_value               number(15);
25750    l_object_found_in_target  boolean := false ;
25751    l_min_esd                 date;
25752    l_max_eed                 date;
25753    l_effective_date          date;
25754    --
25755  begin
25756    -- Initialization
25757    l_object_found_in_target := false ;
25758    -- End Initialization
25759    -- Derive the prefix - sufix
25760    if   p_prefix_suffix_cd = 'PREFIX' then
25761      l_prefix  := p_prefix_suffix_text ;
25762    elsif p_prefix_suffix_cd = 'SUFFIX' then
25763      l_suffix   := p_prefix_suffix_text ;
25764    else
25765      l_prefix := null ;
25766      l_suffix  := null ;
25767    end if ;
25768    -- End Prefix Sufix derivation
25769    for r_PRR_unique in c_unique_PRR('PRR') loop
25770 
25771      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
25772         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
25773           r_PRR_unique.information3 >=
25774                  ben_pd_copy_to_ben_one.g_copy_effective_date)
25775         ) then
25776        --
25777        hr_utility.set_location(' r_PRR_unique.table_route_id '||r_PRR_unique.table_route_id,10);
25778        hr_utility.set_location(' r_PRR_unique.information1 '||r_PRR_unique.information1,10);
25779        hr_utility.set_location( 'r_PRR_unique.information2 '||r_PRR_unique.information2,10);
25780        hr_utility.set_location( 'r_PRR_unique.information3 '||r_PRR_unique.information3,10);
25781        -- If reuse objects flag is 'Y' then check for the object in the target business group
25782        -- if found insert the record into PLSql table and exit the loop else try create the
25783        -- object in the target business group
25784        --
25785        l_object_found_in_target := false ;
25786        l_min_esd := null ;
25787        l_max_eed := null ;
25788        open c_PRR_min_max_dates(r_PRR_unique.table_route_id, r_PRR_unique.information1 ) ;
25789        fetch c_PRR_min_max_dates into l_min_esd,l_max_eed ;
25790        --
25791 
25792        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
25793             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
25794          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
25795        end if;
25796        l_min_esd := greatest(l_min_esd,r_PRR_unique.information2);
25797        open c_PRR(r_PRR_unique.table_route_id,
25798                 r_PRR_unique.information1,
25799                 r_PRR_unique.information2,
25800                 r_PRR_unique.information3 ) ;
25801        --
25802        fetch c_PRR into r_PRR ;
25803        --
25804        close c_PRR ;
25805        --
25806        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_PRR.information262,r_PRR_unique.dml_operation);
25807        l_EXCLD_FLAG      := r_PRR.INFORMATION11;
25808        l_EVENT_TYPE      := r_PRR.INFORMATION13;
25809        l_ORDR_NUM        := r_PRR.INFORMATION257;
25810        l_PERF_RTNG_CD    := r_PRR.INFORMATION12;
25811        --UPD STPRR
25812        l_update := false;
25813        l_process_date := p_effective_date;
25814        l_dml_operation:= r_PRR_unique.dml_operation ;
25815        --
25816        if l_dml_operation = 'UPDATE' then
25817          --
25818          l_object_found_in_target := TRUE;
25819          --
25820          if l_process_date between r_PRR_unique.information2 and r_PRR_unique.information3 then
25821                l_update := true;
25822                if r_PRR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
25823                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'PERF_RTNG_RT_ID'
25824                then
25825                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'PERF_RTNG_RT_ID' ;
25826                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_PRR_unique.information1 ;
25827                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_PRR_unique.information1 ;
25828                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
25829                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_PRR_unique.table_route_id;
25830                   --
25831                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
25832                   --
25833                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
25834                   --
25835                   -- log_data('PRR',l_new_value,l_prefix || r_PRR_unique.name|| l_suffix,'REUSED');
25836                   --
25837                end if ;
25838                hr_utility.set_location( 'found record for update',10);
25839            --
25840          else
25841            --
25842            l_update := false;
25843            --
25844          end if;
25845        else
25846          --
25847          --UPD END
25848        if p_reuse_object_flag = 'Y' then
25849          if c_PRR_min_max_dates%found then
25850            -- cursor to find the object
25851            open c_find_PRR_in_target( l_min_esd,l_max_eed,
25852                                  p_target_business_group_id, nvl(l_perf_rtng_rt_id, -999)  ) ;
25853            fetch c_find_PRR_in_target into l_new_value ;
25854            if c_find_PRR_in_target%found then
25855              --
25856              --TEMPIK
25857              l_dt_rec_found :=   dt_api.check_min_max_dates
25858                  (p_base_table_name => 'BEN_PERF_RTNG_RT_F',
25859                   p_base_key_column => 'PERF_RTNG_RT_ID',
25860                   p_base_key_value  => l_new_value,
25861                   p_from_date       => l_min_esd,
25862                   p_to_date         => l_max_eed );
25863              if l_dt_rec_found THEN
25864              --END TEMPIK
25865              if r_PRR_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
25866                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'PERF_RTNG_RT_ID'  then
25867                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'PERF_RTNG_RT_ID' ;
25868                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_PRR_unique.information1 ;
25869                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
25870                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
25871                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PRR_unique.table_route_id;
25872                 --
25873                 -- 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) ;
25874                 --
25875                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
25876              end if ;
25877              --
25878              l_object_found_in_target := true ;
25879              --TEMPIK
25880              end if; -- l_dt_rec_found
25881              --END TEMPIK
25882            end if;
25883            close c_find_PRR_in_target ;
25884          --
25885          end if;
25886        end if ;
25887        --
25888        end if;
25889        close c_PRR_min_max_dates ;
25890        if not l_object_found_in_target OR l_update   then
25891          --
25892          l_current_pk_id := r_PRR.information1;
25893          --
25894          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
25895          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
25896          --
25897          if l_current_pk_id =  l_prev_pk_id  then
25898            --
25899            l_first_rec := false ;
25900            --
25901          else
25902            --
25903            l_first_rec := true ;
25904            --
25905          end if ;
25906          --
25907 
25908          l_effective_date := r_PRR.information2;
25909          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
25910               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
25911            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
25912          end if;
25913 
25914          if l_first_rec and not l_update then
25915            -- Call Create routine.
25916            hr_utility.set_location(' BEN_PERF_RTNG_RT_F CREATE_PERF_RTNG_RT ',20);
25917            BEN_PERF_RTNG_RT_API.CREATE_PERF_RTNG_RT(
25918              --
25919              P_VALIDATE               => false
25920              ,P_EFFECTIVE_DATE        => l_effective_date
25921              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
25922              --
25923              ,P_EVENT_TYPE      => r_PRR.INFORMATION13
25924              ,P_EXCLD_FLAG      => r_PRR.INFORMATION11
25925              ,P_ORDR_NUM      => r_PRR.INFORMATION257
25926              ,P_PERF_RTNG_CD      => r_PRR.INFORMATION12
25927              ,P_PERF_RTNG_RT_ID      => l_perf_rtng_rt_id
25928              ,P_PRR_ATTRIBUTE1      => r_PRR.INFORMATION111
25929              ,P_PRR_ATTRIBUTE10      => r_PRR.INFORMATION120
25930              ,P_PRR_ATTRIBUTE11      => r_PRR.INFORMATION121
25931              ,P_PRR_ATTRIBUTE12      => r_PRR.INFORMATION122
25932              ,P_PRR_ATTRIBUTE13      => r_PRR.INFORMATION123
25933              ,P_PRR_ATTRIBUTE14      => r_PRR.INFORMATION124
25934              ,P_PRR_ATTRIBUTE15      => r_PRR.INFORMATION125
25935              ,P_PRR_ATTRIBUTE16      => r_PRR.INFORMATION126
25936              ,P_PRR_ATTRIBUTE17      => r_PRR.INFORMATION127
25937              ,P_PRR_ATTRIBUTE18      => r_PRR.INFORMATION128
25938              ,P_PRR_ATTRIBUTE19      => r_PRR.INFORMATION129
25939              ,P_PRR_ATTRIBUTE2      => r_PRR.INFORMATION112
25940              ,P_PRR_ATTRIBUTE20      => r_PRR.INFORMATION130
25941              ,P_PRR_ATTRIBUTE21      => r_PRR.INFORMATION131
25942              ,P_PRR_ATTRIBUTE22      => r_PRR.INFORMATION132
25943              ,P_PRR_ATTRIBUTE23      => r_PRR.INFORMATION133
25944              ,P_PRR_ATTRIBUTE24      => r_PRR.INFORMATION134
25945              ,P_PRR_ATTRIBUTE25      => r_PRR.INFORMATION135
25946              ,P_PRR_ATTRIBUTE26      => r_PRR.INFORMATION136
25947              ,P_PRR_ATTRIBUTE27      => r_PRR.INFORMATION137
25948              ,P_PRR_ATTRIBUTE28      => r_PRR.INFORMATION138
25949              ,P_PRR_ATTRIBUTE29      => r_PRR.INFORMATION139
25950              ,P_PRR_ATTRIBUTE3      => r_PRR.INFORMATION113
25951              ,P_PRR_ATTRIBUTE30      => r_PRR.INFORMATION140
25952              ,P_PRR_ATTRIBUTE4      => r_PRR.INFORMATION114
25953              ,P_PRR_ATTRIBUTE5      => r_PRR.INFORMATION115
25954              ,P_PRR_ATTRIBUTE6      => r_PRR.INFORMATION116
25955              ,P_PRR_ATTRIBUTE7      => r_PRR.INFORMATION117
25956              ,P_PRR_ATTRIBUTE8      => r_PRR.INFORMATION118
25957              ,P_PRR_ATTRIBUTE9      => r_PRR.INFORMATION119
25958              ,P_PRR_ATTRIBUTE_CATEGORY      => r_PRR.INFORMATION110
25959              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
25960              --
25961              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
25962              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
25963              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
25964            );
25965            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
25966            -- Update all relevent cer records with new pk_id
25967            hr_utility.set_location('Before plsql table ',222);
25968            hr_utility.set_location('new_value id '||l_perf_rtng_rt_id,222);
25969            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'PERF_RTNG_RT_ID' ;
25970            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_PRR.information1 ;
25971            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_PERF_RTNG_RT_ID ;
25972            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
25973            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PRR_unique.table_route_id;
25974            hr_utility.set_location('After plsql table ',222);
25975            --
25976            -- 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 ) ;
25977            --
25978            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
25979            --
25980          else
25981            --
25982            -- Call Update routine for the pk_id created in prev run .
25983            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
25984            --UPD STPRR
25985            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
25986            --
25987            if l_update then
25988              --
25989              l_datetrack_mode := r_PRR.datetrack_mode ;
25990              --
25991              get_dt_modes(
25992                p_effective_date        => l_process_date,
25993                p_effective_end_date    => r_PRR.information3,
25994                p_effective_start_date  => r_PRR.information2,
25995                p_dml_operation         => r_PRR.dml_operation,
25996                p_datetrack_mode        => l_datetrack_mode );
25997            --    p_update                => l_update
25998              --
25999              l_effective_date := l_process_date;
26000              l_PERF_RTNG_RT_ID   := r_PRR.information1;
26001              l_object_version_number := r_PRR.information265;
26002              --
26003            end if;
26004            --
26005            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
26006            --
26007            IF l_update OR l_dml_operation <> 'UPDATE' THEN
26008            --UPD END
26009            hr_utility.set_location(' BEN_PERF_RTNG_RT_F UPDATE_PERF_RTNG_RT ',30);
26010            BEN_PERF_RTNG_RT_API.UPDATE_PERF_RTNG_RT(
26011              --
26012              P_VALIDATE               => false
26013              ,P_EFFECTIVE_DATE        => l_effective_date
26014              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
26015              --
26016              ,P_EVENT_TYPE      => r_PRR.INFORMATION13
26017              ,P_EXCLD_FLAG      => r_PRR.INFORMATION11
26018              ,P_ORDR_NUM      => r_PRR.INFORMATION257
26019              ,P_PERF_RTNG_CD      => r_PRR.INFORMATION12
26020              ,P_PERF_RTNG_RT_ID      => l_perf_rtng_rt_id
26021              ,P_PRR_ATTRIBUTE1      => r_PRR.INFORMATION111
26022              ,P_PRR_ATTRIBUTE10      => r_PRR.INFORMATION120
26023              ,P_PRR_ATTRIBUTE11      => r_PRR.INFORMATION121
26024              ,P_PRR_ATTRIBUTE12      => r_PRR.INFORMATION122
26025              ,P_PRR_ATTRIBUTE13      => r_PRR.INFORMATION123
26026              ,P_PRR_ATTRIBUTE14      => r_PRR.INFORMATION124
26027              ,P_PRR_ATTRIBUTE15      => r_PRR.INFORMATION125
26028              ,P_PRR_ATTRIBUTE16      => r_PRR.INFORMATION126
26029              ,P_PRR_ATTRIBUTE17      => r_PRR.INFORMATION127
26030              ,P_PRR_ATTRIBUTE18      => r_PRR.INFORMATION128
26031              ,P_PRR_ATTRIBUTE19      => r_PRR.INFORMATION129
26032              ,P_PRR_ATTRIBUTE2      => r_PRR.INFORMATION112
26033              ,P_PRR_ATTRIBUTE20      => r_PRR.INFORMATION130
26034              ,P_PRR_ATTRIBUTE21      => r_PRR.INFORMATION131
26035              ,P_PRR_ATTRIBUTE22      => r_PRR.INFORMATION132
26036              ,P_PRR_ATTRIBUTE23      => r_PRR.INFORMATION133
26037              ,P_PRR_ATTRIBUTE24      => r_PRR.INFORMATION134
26038              ,P_PRR_ATTRIBUTE25      => r_PRR.INFORMATION135
26039              ,P_PRR_ATTRIBUTE26      => r_PRR.INFORMATION136
26040              ,P_PRR_ATTRIBUTE27      => r_PRR.INFORMATION137
26041              ,P_PRR_ATTRIBUTE28      => r_PRR.INFORMATION138
26042              ,P_PRR_ATTRIBUTE29      => r_PRR.INFORMATION139
26043              ,P_PRR_ATTRIBUTE3      => r_PRR.INFORMATION113
26044              ,P_PRR_ATTRIBUTE30      => r_PRR.INFORMATION140
26045              ,P_PRR_ATTRIBUTE4      => r_PRR.INFORMATION114
26046              ,P_PRR_ATTRIBUTE5      => r_PRR.INFORMATION115
26047              ,P_PRR_ATTRIBUTE6      => r_PRR.INFORMATION116
26048              ,P_PRR_ATTRIBUTE7      => r_PRR.INFORMATION117
26049              ,P_PRR_ATTRIBUTE8      => r_PRR.INFORMATION118
26050              ,P_PRR_ATTRIBUTE9      => r_PRR.INFORMATION119
26051              ,P_PRR_ATTRIBUTE_CATEGORY      => r_PRR.INFORMATION110
26052              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
26053              --
26054              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
26055              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
26056              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
26057              ,P_DATETRACK_MODE        => l_datetrack_mode
26058            );
26059            --
26060            end if;
26061          end if;
26062          --
26063          -- Delete the row if it is end dated.
26064          --
26065          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
26066              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
26067              trunc(l_max_eed) = r_PRR.information3) then
26068              --
26069              BEN_PERF_RTNG_RT_API.delete_PERF_RTNG_RT(
26070                 --
26071                 p_validate                       => false
26072                 ,p_perf_rtng_rt_id                   => l_perf_rtng_rt_id
26073                 ,p_effective_start_date           => l_effective_start_date
26074                 ,p_effective_end_date             => l_effective_end_date
26075                 ,p_object_version_number          => l_object_version_number
26076                 ,p_effective_date                 => l_max_eed
26077                 ,p_datetrack_mode                 => hr_api.g_delete
26078                 --
26079                 );
26080                 --
26081          end if;
26082          --
26083          l_prev_pk_id := l_current_pk_id ;
26084          --
26085        end if;
26086        --
26087      end if;
26088      --
26089    end loop;
26090    --
26091  exception when others then
26092     --
26093     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'PRR',r_prr.information5 );
26094     --
26095  end create_PRR_rows;
26096 
26097  ---------------------------------------------------------------
26098  ----------------------< create_PGR_rows >-----------------------
26099  ---------------------------------------------------------------
26100  --
26101  procedure create_PGR_rows
26102  (
26103          p_validate                       in  number     default 0
26104         ,p_copy_entity_txn_id             in  number
26105         ,p_effective_date                 in  date
26106         ,p_prefix_suffix_text             in  varchar2  default null
26107         ,p_reuse_object_flag              in  varchar2  default null
26108         ,p_target_business_group_id       in  varchar2  default null
26109         ,p_prefix_suffix_cd               in  varchar2  default null
26110  ) is
26111    --
26112    l_PEOPLE_GROUP_ID  number;
26113    l_VRBL_RT_PRFL_ID  number;
26114    --
26115   cursor c_unique_PGR(l_table_alias varchar2) is
26116    select distinct cpe.information1,
26117      cpe.information2,
26118      cpe.information3,
26119      cpe.table_route_id
26120    ,cpe.dml_operation,cpe.datetrack_mode from ben_copy_entity_results cpe,
26121         pqh_table_route tr
26122    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
26123    and   cpe.table_route_id     = tr.table_route_id
26124    -- and   tr.where_clause        = l_BEN_PPL_GRP_RT_F
26125    and   tr.table_alias = l_table_alias
26126    and   cpe.number_of_copies   = 1 -- ADDITION
26127    group by cpe.information1,cpe.information2,cpe.information3,cpe.table_route_id,cpe.dml_operation,cpe.datetrack_mode
26128    order by information1, information2; --added for bug: 5151945
26129    --
26130    --
26131    cursor c_PGR_min_max_dates(c_table_route_id  number,
26132                 c_information1   number) is
26133    select
26134      min(cpe.information2) min_esd,
26135      max(cpe.information3) min_eed
26136    from ben_copy_entity_results cpe
26137    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
26138    and   cpe.table_route_id     = c_table_route_id
26139    and   cpe.information1       = c_information1 ;
26140    --
26141    cursor c_PGR(c_table_route_id  number,
26142                 c_information1    number,
26143                 c_information2   Date,
26144                 c_information3   Date)  is
26145    select
26146      cpe.*
26147    from ben_copy_entity_results cpe
26148    where cpe.copy_entity_txn_id = p_copy_entity_txn_id
26149    and   cpe.table_route_id     = c_table_route_id
26150    and   cpe.information1       = c_information1
26151    and   cpe.information2       = c_information2
26152    and   cpe.information3       = c_information3
26153    and rownum = 1 ;
26154    -- Date Track target record
26155    cursor c_find_PGR_in_target(
26156                                 c_effective_start_date    date,
26157                                 c_effective_end_date      date,
26158                                 c_business_group_id       number,
26159                                 c_new_pk_id               number) is
26160    select
26161      PGR.ppl_grp_rt_id new_value
26162    from BEN_PPL_GRP_RT_F PGR
26163    where
26164    PGR.PEOPLE_GROUP_ID     = l_PEOPLE_GROUP_ID  and
26165    PGR.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
26166    PGR.business_group_id  = c_business_group_id
26167    and   PGR.ppl_grp_rt_id  <> c_new_pk_id
26168 --TEMPIK
26169    and c_effective_start_date between effective_start_date
26170                             and effective_end_date ;
26171 --END TEMPIK
26172 /*TEMPIK
26173    and exists ( select null
26174                 from BEN_PPL_GRP_RT_F PGR1
26175                 where
26176                 PGR1.PEOPLE_GROUP_ID     = l_PEOPLE_GROUP_ID  and
26177                 PGR1.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
26178                 PGR1.business_group_id  = c_business_group_id
26179                 and   PGR1.effective_start_date <= c_effective_start_date )
26180    and exists ( select null
26181                 from BEN_PPL_GRP_RT_F PGR2
26182                 where
26183                 PGR2.PEOPLE_GROUP_ID     = l_PEOPLE_GROUP_ID  and
26184                 PGR2.VRBL_RT_PRFL_ID     = l_VRBL_RT_PRFL_ID  and
26185                 PGR2.business_group_id  = c_business_group_id
26186                 and   PGR2.effective_end_date >= c_effective_end_date )
26187                 ;
26188 TEMPIK */
26189    --TEMPIK
26190    l_dt_rec_found            boolean ;
26191    --END TEMPIK
26192    --
26193    l_current_pk_id           number := null ;
26194    --UPD START
26195    --
26196    l_update                  boolean      := false ;
26197    l_datetrack_mode          varchar2(80) := hr_api.g_update;
26198    l_process_date            date;
26199    l_dml_operation           ben_copy_entity_results.dml_operation%TYPE ;
26200    --
26201    --UPD END
26202    l_prev_pk_id              number := null ;
26203    l_first_rec               boolean := true ;
26204    r_PGR                     c_PGR%rowtype;
26205    l_ppl_grp_rt_id             number ;
26206    l_object_version_number   number ;
26207    l_effective_start_date    date ;
26208    l_effective_end_date      date ;
26209    l_prefix                  pqh_copy_entity_attribs.information1%type := null;
26210    l_suffix                  pqh_copy_entity_attribs.information1%type := null;
26211    l_new_value               number(15);
26212    l_object_found_in_target  boolean := false ;
26213    l_min_esd                 date;
26214    l_max_eed                 date;
26215    l_effective_date          date;
26216    --
26217  begin
26218    -- Initialization
26219    l_object_found_in_target := false ;
26220    -- End Initialization
26221    -- Derive the prefix - sufix
26222    if   p_prefix_suffix_cd = 'PREFIX' then
26223      l_prefix  := p_prefix_suffix_text ;
26224    elsif p_prefix_suffix_cd = 'SUFFIX' then
26225      l_suffix   := p_prefix_suffix_text ;
26226    else
26227      l_prefix := null ;
26228      l_suffix  := null ;
26229    end if ;
26230    -- End Prefix Sufix derivation
26231    for r_PGR_unique in c_unique_PGR('PGR') loop
26232 
26233      if (ben_pd_copy_to_ben_one.g_copy_effective_date is null or
26234         (ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
26235           r_PGR_unique.information3 >=
26236                  ben_pd_copy_to_ben_one.g_copy_effective_date)
26237         ) then
26238        --
26239        hr_utility.set_location(' r_PGR_unique.table_route_id '||r_PGR_unique.table_route_id,10);
26240        hr_utility.set_location(' r_PGR_unique.information1 '||r_PGR_unique.information1,10);
26241        hr_utility.set_location( 'r_PGR_unique.information2 '||r_PGR_unique.information2,10);
26242        hr_utility.set_location( 'r_PGR_unique.information3 '||r_PGR_unique.information3,10);
26243        -- If reuse objects flag is 'Y' then check for the object in the target business group
26244        -- if found insert the record into PLSql table and exit the loop else try create the
26245        -- object in the target business group
26246        --
26247        l_object_found_in_target := false ;
26248        l_min_esd := null ;
26249        l_max_eed := null ;
26250        open c_PGR_min_max_dates(r_PGR_unique.table_route_id, r_PGR_unique.information1 ) ;
26251        fetch c_PGR_min_max_dates into l_min_esd,l_max_eed ;
26252        --
26253 
26254        if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
26255             l_min_esd < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
26256          l_min_esd := ben_pd_copy_to_ben_one.g_copy_effective_date;
26257        end if;
26258        l_min_esd := greatest(l_min_esd,r_PGR_unique.information2);
26259        open c_PGR(r_PGR_unique.table_route_id,
26260                 r_PGR_unique.information1,
26261                 r_PGR_unique.information2,
26262                 r_PGR_unique.information3 ) ;
26263        --
26264        fetch c_PGR into r_PGR ;
26265        --
26266        close c_PGR ;
26267        --
26268        l_VRBL_RT_PRFL_ID := get_fk('VRBL_RT_PRFL_ID', r_PGR.information262,r_PGR_unique.dml_operation);
26269        l_PEOPLE_GROUP_ID := NVL(get_fk('PEOPLE_GROUP_ID',r_PGR.INFORMATION257,r_PGR_unique.dml_operation),r_PGR.INFORMATION257);
26270        --UPD STPGR
26271        l_update := false;
26272        l_process_date := p_effective_date;
26273        l_dml_operation:= r_PGR_unique.dml_operation ;
26274        --
26275        if l_dml_operation = 'UPDATE' then
26276          --
26277          l_object_found_in_target := TRUE;
26278          --
26279          if l_process_date between r_PGR_unique.information2 and r_PGR_unique.information3 then
26280                l_update := true;
26281                if r_PGR_unique.information1 <> nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).old_value, -999)
26282                  or nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count-1).pk_id_column, '999') <> 'PPL_GRP_RT_ID'
26283                then
26284                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).pk_id_column    := 'PPL_GRP_RT_ID' ;
26285                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).old_value       := r_PGR_unique.information1 ;
26286                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).new_value       := r_PGR_unique.information1 ;
26287                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).copy_reuse_type := 'REUSED';
26288                   BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.g_count).table_route_id  := r_PGR_unique.table_route_id;
26289                   --
26290                   -- update_cer_with_target( g_pk_tbl(g_count),p_copy_entity_txn_id ) ;
26291                   --
26292                   BEN_PD_COPY_TO_BEN_ONE.g_count := BEN_PD_COPY_TO_BEN_ONE.g_count + 1 ;
26293                   --
26294                   -- log_data('PGR',l_new_value,l_prefix || r_PGR_unique.name|| l_suffix,'REUSED');
26295                   --
26296                end if ;
26297                hr_utility.set_location( 'found record for update',10);
26298            --
26299          else
26300            --
26301            l_update := false;
26302            --
26303          end if;
26304        else
26305          --
26306          --UPD END
26307        if p_reuse_object_flag = 'Y' then
26308          if c_PGR_min_max_dates%found then
26309            -- cursor to find the object
26310            open c_find_PGR_in_target( l_min_esd,l_max_eed,
26311                                  p_target_business_group_id, nvl(l_ppl_grp_rt_id, -999)  ) ;
26312            fetch c_find_PGR_in_target into l_new_value ;
26313            if c_find_PGR_in_target%found then
26314              --
26315              --TEMPIK
26316              l_dt_rec_found :=   dt_api.check_min_max_dates
26317                  (p_base_table_name => 'BEN_PPL_GRP_RT_F',
26318                   p_base_key_column => 'PPL_GRP_RT_ID',
26319                   p_base_key_value  => l_new_value,
26320                   p_from_date       => l_min_esd,
26321                   p_to_date         => l_max_eed );
26322              if l_dt_rec_found THEN
26323              --END TEMPIK
26324              if r_PGR_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
26325                 nvl(BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT-1).pk_id_column, '999') <>  'PPL_GRP_RT_ID'  then
26326                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column    := 'PPL_GRP_RT_ID' ;
26327                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value       := r_PGR_unique.information1 ;
26328                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value       := l_new_value ;
26329                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type := 'REUSED';
26330                 BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PGR_unique.table_route_id;
26331                 --
26332                 -- 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) ;
26333                 --
26334                 BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
26335              end if ;
26336              --
26337              l_object_found_in_target := true ;
26338              --TEMPIK
26339              end if; -- l_dt_rec_found
26340              --END TEMPIK
26341            end if;
26342            close c_find_PGR_in_target ;
26343          --
26344          end if;
26345        end if ;
26346        --
26347        end if;
26348        close c_PGR_min_max_dates ;
26349        if not l_object_found_in_target OR l_update   then
26350          --
26351          l_current_pk_id := r_PGR.information1;
26352          --
26353          hr_utility.set_location(' l_current_pk_id '||l_current_pk_id,20);
26354          hr_utility.set_location(' l_prev_pk_id '||l_prev_pk_id,20);
26355          --
26356          if l_current_pk_id =  l_prev_pk_id  then
26357            --
26358            l_first_rec := false ;
26359            --
26360          else
26361            --
26362            l_first_rec := true ;
26363            --
26364          end if ;
26365          --
26366 
26367          l_effective_date := r_PGR.information2;
26368          if ( ben_pd_copy_to_ben_one.g_copy_effective_date is not null and
26369               l_effective_date < ben_pd_copy_to_ben_one.g_copy_effective_date ) then
26370            l_effective_date := ben_pd_copy_to_ben_one.g_copy_effective_date;
26371          end if;
26372 
26373          if l_first_rec and not l_update then
26374            -- Call Create routine.
26375            hr_utility.set_location(' BEN_PPL_GRP_RT_F CREATE_PEOPLE_GROUP_RATE ',20);
26376            BEN_PEOPLE_GROUP_RATE_API.CREATE_PEOPLE_GROUP_RATE(
26377              --
26378              P_VALIDATE               => false
26379              ,P_EFFECTIVE_DATE        => l_effective_date
26380              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
26381              --
26382              ,P_EXCLD_FLAG      => r_PGR.INFORMATION11
26383              ,P_ORDR_NUM      => r_PGR.INFORMATION261
26384              ,P_PEOPLE_GROUP_ID      => l_PEOPLE_GROUP_ID
26385              ,P_PGR_ATTRIBUTE1      => r_PGR.INFORMATION111
26386              ,P_PGR_ATTRIBUTE10      => r_PGR.INFORMATION120
26387              ,P_PGR_ATTRIBUTE11      => r_PGR.INFORMATION121
26388              ,P_PGR_ATTRIBUTE12      => r_PGR.INFORMATION122
26389              ,P_PGR_ATTRIBUTE13      => r_PGR.INFORMATION123
26390              ,P_PGR_ATTRIBUTE14      => r_PGR.INFORMATION124
26391              ,P_PGR_ATTRIBUTE15      => r_PGR.INFORMATION125
26392              ,P_PGR_ATTRIBUTE16      => r_PGR.INFORMATION126
26393              ,P_PGR_ATTRIBUTE17      => r_PGR.INFORMATION127
26394              ,P_PGR_ATTRIBUTE18      => r_PGR.INFORMATION128
26395              ,P_PGR_ATTRIBUTE19      => r_PGR.INFORMATION129
26396              ,P_PGR_ATTRIBUTE2      => r_PGR.INFORMATION112
26397              ,P_PGR_ATTRIBUTE20      => r_PGR.INFORMATION130
26398              ,P_PGR_ATTRIBUTE21      => r_PGR.INFORMATION131
26399              ,P_PGR_ATTRIBUTE22      => r_PGR.INFORMATION132
26400              ,P_PGR_ATTRIBUTE23      => r_PGR.INFORMATION133
26401              ,P_PGR_ATTRIBUTE24      => r_PGR.INFORMATION134
26402              ,P_PGR_ATTRIBUTE25      => r_PGR.INFORMATION135
26403              ,P_PGR_ATTRIBUTE26      => r_PGR.INFORMATION136
26404              ,P_PGR_ATTRIBUTE27      => r_PGR.INFORMATION137
26405              ,P_PGR_ATTRIBUTE28      => r_PGR.INFORMATION138
26406              ,P_PGR_ATTRIBUTE29      => r_PGR.INFORMATION139
26407              ,P_PGR_ATTRIBUTE3      => r_PGR.INFORMATION113
26408              ,P_PGR_ATTRIBUTE30      => r_PGR.INFORMATION140
26409              ,P_PGR_ATTRIBUTE4      => r_PGR.INFORMATION114
26410              ,P_PGR_ATTRIBUTE5      => r_PGR.INFORMATION115
26411              ,P_PGR_ATTRIBUTE6      => r_PGR.INFORMATION116
26412              ,P_PGR_ATTRIBUTE7      => r_PGR.INFORMATION117
26413              ,P_PGR_ATTRIBUTE8      => r_PGR.INFORMATION118
26414              ,P_PGR_ATTRIBUTE9      => r_PGR.INFORMATION119
26415              ,P_PGR_ATTRIBUTE_CATEGORY      => r_PGR.INFORMATION110
26416              ,P_PPL_GRP_RT_ID      => l_ppl_grp_rt_id
26417              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
26418              --
26419              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
26420              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
26421              ,P_OBJECT_VERSION_NUMBER =>    l_object_version_number
26422            );
26423            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
26424            -- Update all relevent cer records with new pk_id
26425            hr_utility.set_location('Before plsql table ',222);
26426            hr_utility.set_location('new_value id '||l_ppl_grp_rt_id,222);
26427            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).pk_id_column := 'PPL_GRP_RT_ID' ;
26428            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).old_value    := r_PGR.information1 ;
26429            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).new_value    := l_PPL_GRP_RT_ID ;
26430            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).copy_reuse_type  := 'COPIED';
26431            BEN_PD_COPY_TO_BEN_ONE.g_pk_tbl(BEN_PD_COPY_TO_BEN_ONE.G_COUNT).table_route_id  := r_PGR_unique.table_route_id;
26432            hr_utility.set_location('After plsql table ',222);
26433            --
26434            -- 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 ) ;
26435            --
26436            BEN_PD_COPY_TO_BEN_ONE.G_COUNT := BEN_PD_COPY_TO_BEN_ONE.G_COUNT + 1 ;
26437            --
26438          else
26439            --
26440            -- Call Update routine for the pk_id created in prev run .
26441            -- insert the table_name,old_pk_id,new_pk_id into a plsql record
26442            --UPD STPGR
26443            hr_utility.set_location('Before call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
26444            --
26445            if l_update then
26446              --
26447              l_datetrack_mode := r_PGR.datetrack_mode ;
26448              --
26449              get_dt_modes(
26450                p_effective_date        => l_process_date,
26451                p_effective_end_date    => r_PGR.information3,
26452                p_effective_start_date  => r_PGR.information2,
26453                p_dml_operation         => r_PGR.dml_operation,
26454                p_datetrack_mode        => l_datetrack_mode );
26455            --    p_update                => l_update
26456              --
26457              l_effective_date := l_process_date;
26458              l_PPL_GRP_RT_ID   := r_PGR.information1;
26459              l_object_version_number := r_PGR.information265;
26460              --
26461            end if;
26462            --
26463            hr_utility.set_location('After call to get_dt_modes l_dt_mode'||l_datetrack_mode,5);
26464            --
26465            IF l_update OR l_dml_operation <> 'UPDATE' THEN
26466            --UPD END
26467            hr_utility.set_location(' BEN_PPL_GRP_RT_F UPDATE_PEOPLE_GROUP_RATE ',30);
26468            BEN_PEOPLE_GROUP_RATE_API.UPDATE_PEOPLE_GROUP_RATE(
26469              --
26470              P_VALIDATE               => false
26471              ,P_EFFECTIVE_DATE        => l_effective_date
26472              ,P_BUSINESS_GROUP_ID     => p_target_business_group_id
26473              --
26474              ,P_EXCLD_FLAG      => r_PGR.INFORMATION11
26475              ,P_ORDR_NUM      => r_PGR.INFORMATION261
26476              ,P_PEOPLE_GROUP_ID      => l_PEOPLE_GROUP_ID
26477              ,P_PGR_ATTRIBUTE1      => r_PGR.INFORMATION111
26478              ,P_PGR_ATTRIBUTE10      => r_PGR.INFORMATION120
26479              ,P_PGR_ATTRIBUTE11      => r_PGR.INFORMATION121
26480              ,P_PGR_ATTRIBUTE12      => r_PGR.INFORMATION122
26481              ,P_PGR_ATTRIBUTE13      => r_PGR.INFORMATION123
26482              ,P_PGR_ATTRIBUTE14      => r_PGR.INFORMATION124
26483              ,P_PGR_ATTRIBUTE15      => r_PGR.INFORMATION125
26484              ,P_PGR_ATTRIBUTE16      => r_PGR.INFORMATION126
26485              ,P_PGR_ATTRIBUTE17      => r_PGR.INFORMATION127
26486              ,P_PGR_ATTRIBUTE18      => r_PGR.INFORMATION128
26487              ,P_PGR_ATTRIBUTE19      => r_PGR.INFORMATION129
26488              ,P_PGR_ATTRIBUTE2      => r_PGR.INFORMATION112
26489              ,P_PGR_ATTRIBUTE20      => r_PGR.INFORMATION130
26490              ,P_PGR_ATTRIBUTE21      => r_PGR.INFORMATION131
26491              ,P_PGR_ATTRIBUTE22      => r_PGR.INFORMATION132
26492              ,P_PGR_ATTRIBUTE23      => r_PGR.INFORMATION133
26493              ,P_PGR_ATTRIBUTE24      => r_PGR.INFORMATION134
26494              ,P_PGR_ATTRIBUTE25      => r_PGR.INFORMATION135
26495              ,P_PGR_ATTRIBUTE26      => r_PGR.INFORMATION136
26496              ,P_PGR_ATTRIBUTE27      => r_PGR.INFORMATION137
26497              ,P_PGR_ATTRIBUTE28      => r_PGR.INFORMATION138
26498              ,P_PGR_ATTRIBUTE29      => r_PGR.INFORMATION139
26499              ,P_PGR_ATTRIBUTE3      => r_PGR.INFORMATION113
26500              ,P_PGR_ATTRIBUTE30      => r_PGR.INFORMATION140
26501              ,P_PGR_ATTRIBUTE4      => r_PGR.INFORMATION114
26502              ,P_PGR_ATTRIBUTE5      => r_PGR.INFORMATION115
26503              ,P_PGR_ATTRIBUTE6      => r_PGR.INFORMATION116
26504              ,P_PGR_ATTRIBUTE7      => r_PGR.INFORMATION117
26505              ,P_PGR_ATTRIBUTE8      => r_PGR.INFORMATION118
26506              ,P_PGR_ATTRIBUTE9      => r_PGR.INFORMATION119
26507              ,P_PGR_ATTRIBUTE_CATEGORY      => r_PGR.INFORMATION110
26508              ,P_PPL_GRP_RT_ID      => l_ppl_grp_rt_id
26509              ,P_VRBL_RT_PRFL_ID      => l_VRBL_RT_PRFL_ID
26510              --
26511              ,P_EFFECTIVE_START_DATE  => l_effective_start_date
26512              ,P_EFFECTIVE_END_DATE    => l_effective_end_date
26513              ,P_OBJECT_VERSION_NUMBER => l_object_version_number
26514              ,P_DATETRACK_MODE        => l_datetrack_mode
26515            );
26516            --
26517            end if;
26518          end if;
26519          --
26520          -- Delete the row if it is end dated.
26521          --
26522          if (trunc(l_max_eed) <> trunc(hr_api.g_eot) and
26523              trunc(l_max_eed) <> l_effective_end_date and      /* Bug 4302963 */
26524              trunc(l_max_eed) = r_PGR.information3) then
26525              --
26526              BEN_PEOPLE_GROUP_RATE_API.delete_PEOPLE_GROUP_RATE(
26527                 --
26528                 p_validate                       => false
26529                  ,p_ppl_grp_rt_id                 => l_ppl_grp_rt_id
26530                 ,p_effective_start_date           => l_effective_start_date
26531                 ,p_effective_end_date             => l_effective_end_date
26532                 ,p_object_version_number          => l_object_version_number
26533                 ,p_effective_date                 => l_max_eed
26534                 ,p_datetrack_mode                 => hr_api.g_delete
26535                 --
26536                 );
26537                 --
26538          end if;
26539          --
26540          l_prev_pk_id := l_current_pk_id ;
26541          --
26542        end if;
26543        --
26544      end if;
26545      --
26546    end loop;
26547    --
26548 exception when others then
26549     --
26550     BEN_PD_COPY_TO_BEN_ONE.raise_error_message( 'PGR',r_pgr.information5 );
26551     --
26552 end create_PGR_rows;
26553 
26554 procedure create_all_rt_prf_ben_rows
26555 (
26556    p_validate                       in  number     default 0 -- false
26557   ,p_copy_entity_txn_id             in  number
26558   ,p_effective_date                 in  date
26559   ,p_prefix_suffix_text             in  varchar2  default null
26560   ,p_reuse_object_flag              in  varchar2  default null
26561   ,p_target_business_group_id       in  varchar2  default null
26562   ,p_prefix_suffix_cd               in  varchar2  default null
26563  ) is
26564 begin
26565   --
26566   -- Initialization
26567   --
26568     -- Create all oipl rows.
26569     --
26570   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('CTY') then
26571     BEN_PD_COPY_TO_BEN_THREE.create_CTY_rows(
26572      p_validate                  => p_validate
26573     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26574     ,p_effective_date            => p_effective_date
26575     ,p_prefix_suffix_text        => p_prefix_suffix_text
26576     ,p_reuse_object_flag         => p_reuse_object_flag
26577     ,p_target_business_group_id  => p_target_business_group_id
26578     ,p_prefix_suffix_cd          => p_prefix_suffix_cd
26579     );
26580   end if;
26581     --
26582     --
26583   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('JRT') then
26584     BEN_PD_COPY_TO_BEN_THREE.create_JRT_rows(
26585     p_validate                  => p_validate
26586     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26587     ,p_effective_date            => p_effective_date
26588     ,p_prefix_suffix_text        => p_prefix_suffix_text
26589     ,p_reuse_object_flag         => p_reuse_object_flag
26590     ,p_target_business_group_id  => p_target_business_group_id
26591     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26592   end if;
26593     --
26594     --dbms_output.put_line( 'BEN_PD_COPY_TO_BEN_THREE.create_JRT_rows ');
26595     --
26596   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('HSR') then
26597     BEN_PD_COPY_TO_BEN_THREE.create_HSR_rows(
26598     p_validate                  => p_validate
26599     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26600     ,p_effective_date            => p_effective_date
26601     ,p_prefix_suffix_text        => p_prefix_suffix_text
26602     ,p_reuse_object_flag         => p_reuse_object_flag
26603     ,p_target_business_group_id  => p_target_business_group_id
26604     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26605     --
26606    end if;
26607      --dbms_output.put_line( 'BEN_PD_COPY_TO_BEN_THREE.create_HSR_rows ');
26608     --
26609   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('GRR') then
26610     BEN_PD_COPY_TO_BEN_THREE.create_GRR_rows(
26611     p_validate                  => p_validate
26612     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26613     ,p_effective_date            => p_effective_date
26614     ,p_prefix_suffix_text        => p_prefix_suffix_text
26615     ,p_reuse_object_flag         => p_reuse_object_flag
26616     ,p_target_business_group_id  => p_target_business_group_id
26617     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26618    end if;
26619     --
26620      --dbms_output.put_line( 'BEN_PD_COPY_TO_BEN_THREE.create_GRR_rows');
26621     --
26622   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('FTR') then
26623     BEN_PD_COPY_TO_BEN_THREE.create_FTR_rows(
26624     p_validate                  => p_validate
26625     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26626     ,p_effective_date            => p_effective_date
26627     ,p_prefix_suffix_text        => p_prefix_suffix_text
26628     ,p_reuse_object_flag         => p_reuse_object_flag
26629     ,p_target_business_group_id  => p_target_business_group_id
26630     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26631    end if;
26632     --
26633       --dbms_output.put_line( 'BEN_PD_COPY_TO_BEN_THREE.create_FTR_rows');
26634     --
26635   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('BUR') then
26636     BEN_PD_COPY_TO_BEN_THREE.create_BUR_rows(
26637     p_validate                  => p_validate
26638     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26639     ,p_effective_date            => p_effective_date
26640     ,p_prefix_suffix_text        => p_prefix_suffix_text
26641     ,p_reuse_object_flag         => p_reuse_object_flag
26642     ,p_target_business_group_id  => p_target_business_group_id
26643     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26644    end if;
26645     --
26646       --dbms_output.put_line( 'BEN_PD_COPY_TO_BEN_THREE.create_BUR_rows');
26647     --
26648   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('ESR') then
26649     BEN_PD_COPY_TO_BEN_THREE.create_ESR_rows(
26650     p_validate                  => p_validate
26651     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26652     ,p_effective_date            => p_effective_date
26653     ,p_prefix_suffix_text        => p_prefix_suffix_text
26654     ,p_reuse_object_flag         => p_reuse_object_flag
26655     ,p_target_business_group_id  => p_target_business_group_id
26656     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26657    end if;
26658     --
26659     --
26660   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('ASR') then
26661     BEN_PD_COPY_TO_BEN_THREE.create_ASR_rows(
26662     p_validate                  => p_validate
26663     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26664     ,p_effective_date            => p_effective_date
26665     ,p_prefix_suffix_text        => p_prefix_suffix_text
26666     ,p_reuse_object_flag         => p_reuse_object_flag
26667     ,p_target_business_group_id  => p_target_business_group_id
26668     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26669    end if;
26670     --
26671         --dbms_output.put_line( 'BEN_PD_COPY_TO_BEN_THREE.create_ASR_rows ');
26672   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('TUR') then
26673     BEN_PD_COPY_TO_BEN_THREE.create_TUR_rows(
26674     p_validate                  => p_validate
26675     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26676     ,p_effective_date            => p_effective_date
26677     ,p_prefix_suffix_text        => p_prefix_suffix_text
26678     ,p_reuse_object_flag         => p_reuse_object_flag
26679     ,p_target_business_group_id  => p_target_business_group_id
26680     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26681    end if;
26682     --
26683     --
26684   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('SAR') then
26685     BEN_PD_COPY_TO_BEN_THREE.create_SAR_rows(
26686     p_validate                  => p_validate
26687     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26688     ,p_effective_date            => p_effective_date
26689     ,p_prefix_suffix_text        => p_prefix_suffix_text
26690     ,p_reuse_object_flag         => p_reuse_object_flag
26691     ,p_target_business_group_id  => p_target_business_group_id
26692     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26693    end if;
26694     --
26695     --
26696   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('QTR') then
26697     BEN_PD_COPY_TO_BEN_THREE.create_QTR_rows(
26698     p_validate                  => p_validate
26699     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26700     ,p_effective_date            => p_effective_date
26701     ,p_prefix_suffix_text        => p_prefix_suffix_text
26702     ,p_reuse_object_flag         => p_reuse_object_flag
26703     ,p_target_business_group_id  => p_target_business_group_id
26704     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26705    end if;
26706     --
26707     --
26708   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('PZR') then
26709     BEN_PD_COPY_TO_BEN_THREE.create_PZR_rows(
26710     p_validate                  => p_validate
26711     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26712     ,p_effective_date            => p_effective_date
26713     ,p_prefix_suffix_text        => p_prefix_suffix_text
26714     ,p_reuse_object_flag         => p_reuse_object_flag
26715     ,p_target_business_group_id  => p_target_business_group_id
26716     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26717    end if;
26718     --
26719     --
26720   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('PTR') then
26721     BEN_PD_COPY_TO_BEN_THREE.create_PTR_rows(
26722     p_validate                  => p_validate
26723     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26724     ,p_effective_date            => p_effective_date
26725     ,p_prefix_suffix_text        => p_prefix_suffix_text
26726     ,p_reuse_object_flag         => p_reuse_object_flag
26727     ,p_target_business_group_id  => p_target_business_group_id
26728     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26729    end if;
26730     --
26731     --
26732   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('GNR') then
26733     BEN_PD_COPY_TO_BEN_THREE.create_GNR_rows(
26734     p_validate                  => p_validate
26735     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26736     ,p_effective_date            => p_effective_date
26737     ,p_prefix_suffix_text        => p_prefix_suffix_text
26738     ,p_reuse_object_flag         => p_reuse_object_flag
26739     ,p_target_business_group_id  => p_target_business_group_id
26740     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26741    end if;
26742     --
26743         --dbms_output.put_line( 'BEN_PD_COPY_TO_BEN_THREE.create_GNR_rows ');
26744     --
26745   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('DBR') then
26746     BEN_PD_COPY_TO_BEN_THREE.create_DBR_rows(
26747     p_validate                  => p_validate
26748     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26749     ,p_effective_date            => p_effective_date
26750     ,p_prefix_suffix_text        => p_prefix_suffix_text
26751     ,p_reuse_object_flag         => p_reuse_object_flag
26752     ,p_target_business_group_id  => p_target_business_group_id
26753     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26754    end if;
26755     --
26756 
26757 
26758     --
26759   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('LMM') then
26760     BEN_PD_COPY_TO_BEN_THREE.create_LMM_rows(
26761     p_validate                  => p_validate
26762     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26763     ,p_effective_date            => p_effective_date
26764     ,p_prefix_suffix_text        => p_prefix_suffix_text
26765     ,p_reuse_object_flag         => p_reuse_object_flag
26766     ,p_target_business_group_id  => p_target_business_group_id
26767     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26768    end if;
26769     --
26770     --
26771   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('LAR') then
26772     BEN_PD_COPY_TO_BEN_THREE.create_LAR_rows(
26773     p_validate                  => p_validate
26774     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26775     ,p_effective_date            => p_effective_date
26776     ,p_prefix_suffix_text        => p_prefix_suffix_text
26777     ,p_reuse_object_flag         => p_reuse_object_flag
26778     ,p_target_business_group_id  => p_target_business_group_id
26779     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26780    end if;
26781     --
26782     --
26783   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('OUR') then
26784     BEN_PD_COPY_TO_BEN_THREE.create_OUR_rows(
26785     p_validate                  => p_validate
26786     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26787     ,p_effective_date            => p_effective_date
26788     ,p_prefix_suffix_text        => p_prefix_suffix_text
26789     ,p_reuse_object_flag         => p_reuse_object_flag
26790     ,p_target_business_group_id  => p_target_business_group_id
26791     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26792    end if;
26793     --
26794   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('LER1') then
26795     BEN_PD_COPY_TO_BEN_THREE.create_LER1_rows(
26796     p_validate                  => p_validate
26797     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26798     ,p_effective_date            => p_effective_date
26799     ,p_prefix_suffix_text        => p_prefix_suffix_text
26800     ,p_reuse_object_flag         => p_reuse_object_flag
26801     ,p_target_business_group_id  => p_target_business_group_id
26802     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26803    end if;
26804     --
26805         --dbms_output.put_line( 'BEN_PD_COPY_TO_BEN_THREE.create_LER1_rows ');
26806     --
26807   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('PR_') then
26808     BEN_PD_COPY_TO_BEN_THREE.create_PR__rows(
26809     p_validate                  => p_validate
26810     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26811     ,p_effective_date            => p_effective_date
26812     ,p_prefix_suffix_text        => p_prefix_suffix_text
26813     ,p_reuse_object_flag         => p_reuse_object_flag
26814     ,p_target_business_group_id  => p_target_business_group_id
26815     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26816    end if;
26817     --
26818         --dbms_output.put_line( 'BEN_PD_COPY_TO_BEN_THREE.create_PR__rows');
26819     --
26820   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('PBR') then
26821     BEN_PD_COPY_TO_BEN_THREE.create_PBR_rows(
26822     p_validate                  => p_validate
26823     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26824     ,p_effective_date            => p_effective_date
26825     ,p_prefix_suffix_text        => p_prefix_suffix_text
26826     ,p_reuse_object_flag         => p_reuse_object_flag
26827     ,p_target_business_group_id  => p_target_business_group_id
26828     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26829    end if;
26830     --
26831   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('BRG') then
26832     BEN_PD_COPY_TO_BEN_THREE.create_BRG_rows(
26833     p_validate                  => p_validate
26834     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26835     ,p_effective_date            => p_effective_date
26836     ,p_prefix_suffix_text        => p_prefix_suffix_text
26837     ,p_reuse_object_flag         => p_reuse_object_flag
26838     ,p_target_business_group_id  => p_target_business_group_id
26839     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26840    end if;
26841     --
26842     --
26843   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('CMR') then
26844     BEN_PD_COPY_TO_BEN_THREE.create_CMR_rows(
26845     p_validate                  => p_validate
26846     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26847     ,p_effective_date            => p_effective_date
26848     ,p_prefix_suffix_text        => p_prefix_suffix_text
26849     ,p_reuse_object_flag         => p_reuse_object_flag
26850     ,p_target_business_group_id  => p_target_business_group_id
26851     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26852    end if;
26853     --
26854     --
26855   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('VMR') then
26856     BEN_PD_COPY_TO_BEN_THREE.create_VMR_rows(
26857     p_validate                  => p_validate
26858     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26859     ,p_effective_date            => p_effective_date
26860     ,p_prefix_suffix_text        => p_prefix_suffix_text
26861     ,p_reuse_object_flag         => p_reuse_object_flag
26862     ,p_target_business_group_id  => p_target_business_group_id
26863     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26864    end if;
26865     --
26866     --
26867   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('NOC') then
26868     BEN_PD_COPY_TO_BEN_THREE.create_NOC_rows(
26869     p_validate                  => p_validate
26870     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26871     ,p_effective_date            => p_effective_date
26872     ,p_prefix_suffix_text        => p_prefix_suffix_text
26873     ,p_reuse_object_flag         => p_reuse_object_flag
26874     ,p_target_business_group_id  => p_target_business_group_id
26875     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26876    end if;
26877     --
26878     --
26879   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('OMR') then
26880     BEN_PD_COPY_TO_BEN_THREE.create_OMR_rows(
26881     p_validate                  => p_validate
26882     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26883     ,p_effective_date            => p_effective_date
26884     ,p_prefix_suffix_text        => p_prefix_suffix_text
26885     ,p_reuse_object_flag         => p_reuse_object_flag
26886     ,p_target_business_group_id  => p_target_business_group_id
26887     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26888    end if;
26889     --
26890     --
26891   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('TTP') then
26892     BEN_PD_COPY_TO_BEN_THREE.create_TTP_rows(
26893     p_validate                  => p_validate
26894     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26895     ,p_effective_date            => p_effective_date
26896     ,p_prefix_suffix_text        => p_prefix_suffix_text
26897     ,p_reuse_object_flag         => p_reuse_object_flag
26898     ,p_target_business_group_id  => p_target_business_group_id
26899     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26900    end if;
26901     --
26902     --
26903   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('TCV') then
26904     BEN_PD_COPY_TO_BEN_THREE.create_TCV_rows(
26905     p_validate                  => p_validate
26906     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26907     ,p_effective_date            => p_effective_date
26908     ,p_prefix_suffix_text        => p_prefix_suffix_text
26909     ,p_reuse_object_flag         => p_reuse_object_flag
26910     ,p_target_business_group_id  => p_target_business_group_id
26911     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26912    end if;
26913     --
26914     --
26915   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('VPR') then
26916     BEN_PD_COPY_TO_BEN_THREE.create_VPR_rows(
26917     p_validate                  => p_validate
26918     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26919     ,p_effective_date            => p_effective_date
26920     ,p_prefix_suffix_text        => p_prefix_suffix_text
26921     ,p_reuse_object_flag         => p_reuse_object_flag
26922     ,p_target_business_group_id  => p_target_business_group_id
26923     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26924    end if;
26925     --
26926     --
26927   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('PRT') then
26928     BEN_PD_COPY_TO_BEN_THREE.create_PRT_rows(
26929     p_validate                  => p_validate
26930     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26931     ,p_effective_date            => p_effective_date
26932     ,p_prefix_suffix_text        => p_prefix_suffix_text
26933     ,p_reuse_object_flag         => p_reuse_object_flag
26934     ,p_target_business_group_id  => p_target_business_group_id
26935     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26936    end if;
26937     --
26938     --
26939   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('CPN') then
26940     BEN_PD_COPY_TO_BEN_THREE.create_CPN_rows(
26941     p_validate                  => p_validate
26942     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26943     ,p_effective_date            => p_effective_date
26944     ,p_prefix_suffix_text        => p_prefix_suffix_text
26945     ,p_reuse_object_flag         => p_reuse_object_flag
26946     ,p_target_business_group_id  => p_target_business_group_id
26947     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26948    end if;
26949     --
26950     --
26951   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('PST') then
26952     BEN_PD_COPY_TO_BEN_THREE.create_PST_rows(
26953     p_validate                  => p_validate
26954     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26955     ,p_effective_date            => p_effective_date
26956     ,p_prefix_suffix_text        => p_prefix_suffix_text
26957     ,p_reuse_object_flag         => p_reuse_object_flag
26958     ,p_target_business_group_id  => p_target_business_group_id
26959     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26960    end if;
26961     --
26962     --
26963   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('WLR') then
26964     BEN_PD_COPY_TO_BEN_THREE.create_WLR_rows(
26965     p_validate                  => p_validate
26966     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26967     ,p_effective_date            => p_effective_date
26968     ,p_prefix_suffix_text        => p_prefix_suffix_text
26969     ,p_reuse_object_flag         => p_reuse_object_flag
26970     ,p_target_business_group_id  => p_target_business_group_id
26971     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26972    end if;
26973     --
26974     --
26975   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('PFR') then
26976     BEN_PD_COPY_TO_BEN_THREE.create_PFR_rows(
26977     p_validate                  => p_validate
26978     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26979     ,p_effective_date            => p_effective_date
26980     ,p_prefix_suffix_text        => p_prefix_suffix_text
26981     ,p_reuse_object_flag         => p_reuse_object_flag
26982     ,p_target_business_group_id  => p_target_business_group_id
26983     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26984    end if;
26985     --
26986     --
26987   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('HWR') then
26988     BEN_PD_COPY_TO_BEN_THREE.create_HWR_rows(
26989     p_validate                  => p_validate
26990     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
26991     ,p_effective_date            => p_effective_date
26992     ,p_prefix_suffix_text        => p_prefix_suffix_text
26993     ,p_reuse_object_flag         => p_reuse_object_flag
26994     ,p_target_business_group_id  => p_target_business_group_id
26995     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
26996    end if;
26997     --
26998     --
26999   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('CLR') then
27000     BEN_PD_COPY_TO_BEN_THREE.create_CLR_rows(
27001     p_validate                  => p_validate
27002     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27003     ,p_effective_date            => p_effective_date
27004     ,p_prefix_suffix_text        => p_prefix_suffix_text
27005     ,p_reuse_object_flag         => p_reuse_object_flag
27006     ,p_target_business_group_id  => p_target_business_group_id
27007     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27008    end if;
27009     --
27010     --
27011   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('LSR') then
27012     BEN_PD_COPY_TO_BEN_THREE.create_LSR_rows(
27013     p_validate                  => p_validate
27014     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27015     ,p_effective_date            => p_effective_date
27016     ,p_prefix_suffix_text        => p_prefix_suffix_text
27017     ,p_reuse_object_flag         => p_reuse_object_flag
27018     ,p_target_business_group_id  => p_target_business_group_id
27019     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27020    end if;
27021     --
27022     --
27023   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('LRN') then
27024     BEN_PD_COPY_TO_BEN_THREE.create_LRN_rows(
27025     p_validate                  => p_validate
27026     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27027     ,p_effective_date            => p_effective_date
27028     ,p_prefix_suffix_text        => p_prefix_suffix_text
27029     ,p_reuse_object_flag         => p_reuse_object_flag
27030     ,p_target_business_group_id  => p_target_business_group_id
27031     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27032    end if;
27033     --
27034     --
27035   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('ART') then
27036     BEN_PD_COPY_TO_BEN_THREE.create_ART_rows(
27037     p_validate                  => p_validate
27038     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27039     ,p_effective_date            => p_effective_date
27040     ,p_prefix_suffix_text        => p_prefix_suffix_text
27041     ,p_reuse_object_flag         => p_reuse_object_flag
27042     ,p_target_business_group_id  => p_target_business_group_id
27043     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27044    end if;
27045     --
27046     --
27047   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('SHR') then
27048     BEN_PD_COPY_TO_BEN_THREE.create_SHR_rows(
27049     p_validate                  => p_validate
27050     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27051     ,p_effective_date            => p_effective_date
27052     ,p_prefix_suffix_text        => p_prefix_suffix_text
27053     ,p_reuse_object_flag         => p_reuse_object_flag
27054     ,p_target_business_group_id  => p_target_business_group_id
27055     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27056    end if;
27057     --
27058     --
27059   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('QIG') then
27060     BEN_PD_COPY_TO_BEN_THREE.create_QIG_rows(
27061     p_validate                  => p_validate
27062     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27063     ,p_effective_date            => p_effective_date
27064     ,p_prefix_suffix_text        => p_prefix_suffix_text
27065     ,p_reuse_object_flag         => p_reuse_object_flag
27066     ,p_target_business_group_id  => p_target_business_group_id
27067     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27068    end if;
27069     --
27070     --
27071   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('PRR') then
27072     BEN_PD_COPY_TO_BEN_THREE.create_PRR_rows(
27073     p_validate                  => p_validate
27074     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27075     ,p_effective_date            => p_effective_date
27076     ,p_prefix_suffix_text        => p_prefix_suffix_text
27077     ,p_reuse_object_flag         => p_reuse_object_flag
27078     ,p_target_business_group_id  => p_target_business_group_id
27079     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27080    end if;
27081     --
27082 
27083   --
27084   -- Foll. Criteria to be copied only in Create Plan Wizard flow
27085   --
27086   if BEN_PD_COPY_TO_BEN_ONE.g_transaction_category = 'BEN_PDCRWZ' then
27087     --
27088    if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('CQR') then
27089     BEN_PD_COPY_TO_BEN_THREE.create_CQR_rows(
27090     p_validate                  => p_validate
27091     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27092     ,p_effective_date            => p_effective_date
27093     ,p_prefix_suffix_text        => p_prefix_suffix_text
27094     ,p_reuse_object_flag         => p_reuse_object_flag
27095     ,p_target_business_group_id  => p_target_business_group_id
27096     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27097    end if;
27098       --
27099       --
27100    if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('PAP') then
27101     BEN_PD_COPY_TO_BEN_THREE.create_PAP_rows(
27102     p_validate                  => p_validate
27103     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27104     ,p_effective_date            => p_effective_date
27105     ,p_prefix_suffix_text        => p_prefix_suffix_text
27106     ,p_reuse_object_flag         => p_reuse_object_flag
27107     ,p_target_business_group_id  => p_target_business_group_id
27108     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27109    end if;
27110     --
27111     --
27112   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('OPR') then
27113     BEN_PD_COPY_TO_BEN_THREE.create_OPR_rows(
27114     p_validate                  => p_validate
27115     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27116     ,p_effective_date            => p_effective_date
27117     ,p_prefix_suffix_text        => p_prefix_suffix_text
27118     ,p_reuse_object_flag         => p_reuse_object_flag
27119     ,p_target_business_group_id  => p_target_business_group_id
27120     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27121    end if;
27122     --
27123     --
27124    if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('ENT') then
27125     BEN_PD_COPY_TO_BEN_THREE.create_ENT_rows(
27126     p_validate                  => p_validate
27127     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27128     ,p_effective_date            => p_effective_date
27129     ,p_prefix_suffix_text        => p_prefix_suffix_text
27130     ,p_reuse_object_flag         => p_reuse_object_flag
27131     ,p_target_business_group_id  => p_target_business_group_id
27132     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27133    end if;
27134     --
27135     --
27136    if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('ENL') then
27137     BEN_PD_COPY_TO_BEN_THREE.create_ENL_rows(
27138     p_validate                  => p_validate
27139     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27140     ,p_effective_date            => p_effective_date
27141     ,p_prefix_suffix_text        => p_prefix_suffix_text
27142     ,p_reuse_object_flag         => p_reuse_object_flag
27143     ,p_target_business_group_id  => p_target_business_group_id
27144     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27145    end if;
27146     --
27147     --
27148    if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('EAR') then
27149     BEN_PD_COPY_TO_BEN_THREE.create_EAR_rows(
27150     p_validate                  => p_validate
27151     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27152     ,p_effective_date            => p_effective_date
27153     ,p_prefix_suffix_text        => p_prefix_suffix_text
27154     ,p_reuse_object_flag         => p_reuse_object_flag
27155     ,p_target_business_group_id  => p_target_business_group_id
27156     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27157    end if;
27158     --
27159     --
27160    if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('EAO') then
27161     BEN_PD_COPY_TO_BEN_THREE.create_EAO_rows(
27162     p_validate                  => p_validate
27163     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27164     ,p_effective_date            => p_effective_date
27165     ,p_prefix_suffix_text        => p_prefix_suffix_text
27166     ,p_reuse_object_flag         => p_reuse_object_flag
27167     ,p_target_business_group_id  => p_target_business_group_id
27168     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27169    end if;
27170     --
27171    --
27172   if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('DOT') then
27173     BEN_PD_COPY_TO_BEN_THREE.create_DOT_rows(
27174     p_validate                  => p_validate
27175     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27176     ,p_effective_date            => p_effective_date
27177     ,p_prefix_suffix_text        => p_prefix_suffix_text
27178     ,p_reuse_object_flag         => p_reuse_object_flag
27179     ,p_target_business_group_id  => p_target_business_group_id
27180     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27181    end if;
27182     --
27183     --
27184    if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('DOP') then
27185     BEN_PD_COPY_TO_BEN_THREE.create_DOP_rows(
27186     p_validate                  => p_validate
27187     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27188     ,p_effective_date            => p_effective_date
27189     ,p_prefix_suffix_text        => p_prefix_suffix_text
27190     ,p_reuse_object_flag         => p_reuse_object_flag
27191     ,p_target_business_group_id  => p_target_business_group_id
27192     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27193    end if;
27194     --
27195     --
27196    if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('DCP') then
27197     BEN_PD_COPY_TO_BEN_THREE.create_DCP_rows(
27198     p_validate                  => p_validate
27199     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27200     ,p_effective_date            => p_effective_date
27201     ,p_prefix_suffix_text        => p_prefix_suffix_text
27202     ,p_reuse_object_flag         => p_reuse_object_flag
27203     ,p_target_business_group_id  => p_target_business_group_id
27204     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27205    end if;
27206     --
27207     --
27208    if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('DCO') then
27209     BEN_PD_COPY_TO_BEN_THREE.create_DCO_rows(
27210     p_validate                  => p_validate
27211     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27212     ,p_effective_date            => p_effective_date
27213     ,p_prefix_suffix_text        => p_prefix_suffix_text
27214     ,p_reuse_object_flag         => p_reuse_object_flag
27215     ,p_target_business_group_id  => p_target_business_group_id
27216     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27217    end if;
27218     --
27219     --
27220    if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('DCL') then
27221     BEN_PD_COPY_TO_BEN_THREE.create_DCL_rows(
27222     p_validate                  => p_validate
27223     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27224     ,p_effective_date            => p_effective_date
27225     ,p_prefix_suffix_text        => p_prefix_suffix_text
27226     ,p_reuse_object_flag         => p_reuse_object_flag
27227     ,p_target_business_group_id  => p_target_business_group_id
27228     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27229    end if;
27230     --
27231     --
27232    if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('EPM') then
27233     BEN_PD_COPY_TO_BEN_THREE.create_EPM_rows(
27234     p_validate                  => p_validate
27235     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27236     ,p_effective_date            => p_effective_date
27237     ,p_prefix_suffix_text        => p_prefix_suffix_text
27238     ,p_reuse_object_flag         => p_reuse_object_flag
27239     ,p_target_business_group_id  => p_target_business_group_id
27240     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27241    end if;
27242     --
27243     --
27244    if BEN_PD_COPY_TO_BEN_ONE.data_exists_for_table('PGR') then
27245     BEN_PD_COPY_TO_BEN_THREE.create_PGR_rows(
27246     p_validate                  => p_validate
27247     ,p_copy_entity_txn_id        => p_copy_entity_txn_id
27248     ,p_effective_date            => p_effective_date
27249     ,p_prefix_suffix_text        => p_prefix_suffix_text
27250     ,p_reuse_object_flag         => p_reuse_object_flag
27251     ,p_target_business_group_id  => p_target_business_group_id
27252     ,p_prefix_suffix_cd          => p_prefix_suffix_cd   );
27253    end if;
27254   end if;
27255 end create_all_rt_prf_ben_rows;
27256 --
27257 --
27258 end BEN_PD_COPY_TO_BEN_three;