DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_MANAGE_LIFE_EVENTS

Source


1 package body ben_manage_life_events as
2 /* $Header: benmngle.pkb 120.28.12010000.3 2008/08/12 13:06:59 pvelugul ship $ */
3 --
4 /*
5 +========================================================================+
6 |             Copyright (c) 1997 Oracle Corporation                      |
7 |                Redwood Shores, California, USA                         |
8 |                      All rights reserved.                              |
9 +========================================================================+
10 */
11 /*
12 Name
13     Manage Life Events
14 Purpose
15         This package is used to check validity of parameters passed in via SRS
16         or via a PL/SQL function or procedure. This package will then run the
17         BENMNGLE process.
18 History
19      Date             Who        Version    What?
20      ----             ---        -------    -----
21      14 Dec 97        G Perry    110.0      Created.
22      15 Dec 97        G Perry    110.1      Changed call to
23                                             derive_rates_and_facts.
24      04 Jan 98        G Perry    110.2      Added in exception handling
25                                             and log file reporting.
26      05 Jan 98        G Perry    110.3      Altered parameters so that
27                                             they are in a more logical
28                                             order.
29      07 Jan 98        lmcdonal   110.4      Added call to
30                                             create_related_person_ler
31      13 Jan 98        G Perry    110.5      Fixed parameter names in main
32                                             process_life_events procedure.
33                                             Added extra parameters for
34                                             person_selection_rule_id and
35                                             comp_selection_rule_id in to
36                                             called PL/SQL process.
37      14 Jan 98        G Perry    110.6      Added caching of comp object
38                                             types and messages.
39      14 Jan 98        T Mathers  110.7      Added calls to Pate04r5.
40      15 Jan 98        G Perry    110.8      Changed cache objects
41                                             variables to match real
42                                             lookup codes.
43      15 Jan 98        G Perry    110.9      Changed p_validate from a
44                                             boolean to a character due
45                                             to SRS not supporting boolean.
46      15 Jan 98        lmcdonal   110.10     Added call to
47                                             determine_eligibility.
48      16 Jan 98        G Perry    110.11     Added retcode and errbuf
49                                             which are needed by SRS.
50      18 Jan 98        G Perry    110.12     Added in real messages now
51                                             seeded in seed11.
52      19 Jan 98        lmcdonal   110.13     Created globals for person,
53                                             assignment and life event name.
54                                             Add get_ler_name.
55      21 Jan 98        G Perry    110.14     Created globals
56                                             g_last_person_failed
57                                             g_last_plan_failed
58                                             g_last_prog_failed
59                                             to handle propergation of comp
60                                             object failures.
61      22 Jan 98        lmcdonal   110.15     Uncomment determine elig.
62      24 Jan 98        G Perry    110.16     Fixed call to determine elig
63                                             so runs in every mode bar
64                                             derivable factor mode.
65                                             Added id function which
66                                             returns a bracketed number.
67      25 Jan 98        G Perry    110.17     Added banner for lers.
68      25 Jan 98        G Perry    110.18     Added app_exception exception
69                                             handler for row handler errors.
70      25 Jan 98        lmcdonal   110.19     Add setting of g_last...failed
71                                             to exception routine.
72                                             Change 6 locals from number(38)
73                                             to number.
74      26 Jan 98        lmcdonal   110.20     Call determine elig and evaluate
75                                             lers only if person has changed.
76      27 Jan 98        G Perry    110.21     Set g_person_changed so that it
77                                             takes into account when we get
78                                             several identical person_ids
79                                             and ler_ids.
80      27 Jan 98        G Perry    110.22     Changed commit_all_data proc.
81      02 Feb 98        G Perry    110.23     Moved Commit into C code and
82                                             passed p_validate to C code.
83      02 Feb 98        G Perry    110.24     Changed exception app_exception
84                                             call so it just raises an error.
85      03 Feb 98        G Perry    110.25     Completely removed
86                                             app_exception call and capture
87                                             via when others call.
88      06 Mar 98        G Perry    110.26     Removed commit_all_data procedure
89                                             Added log_benmngle_statistics
90                                             Restart, removed lots of logging
91                                             messages. Chng looping mechanism
92                                             for comp objects so they are done
93                                             in one call rather than lots of
94                                             seperate calls. Added lots of
95                                             caching routines.
96      16 Mar 98        G Perry    110.27     Added prtn_eff_strt_dt_rl and
97                                             prtn_eff_end_dt_rl into object
98                                             cache structure for pl,pgm,oipl.
99      08 Apr 98        G Perry    110.28     Added all multithread logic into
100                                             package. Added Conc defintion
101                                             to allow restart and multithread.
102                                             Cached objects only once now.
103      09 Apr 98        G Perry    110.29     Backport for BD2.
104      09 Apr 98        G Perry    110.30     remove commit in logging part.
105      13 Apr 98        G Perry    110.31     Added logging to PLSQL.
106      20 Apr 98        G Perry    110.32     Fixed cache errors.
107                                             Added error handling to trap
108                                             where error occured.
109                                             Added exception g_life_event
110                                             _after Clears cache each time.
111      21 Apr 98        G Perry    110.33     Fixed problem with restart.
112      18 May 98        G Perry    110.34     dbsynch up.
113      21 May 98        jcarpent   110.35     Added determine enrolment rqmts
114      27 May 98        G Perry    110.36     Added in fast formula cover calls.
115      27 May 98        jcarpent   110.38     Added elig_per_elctbl_chc_id arg.
116      04 Jun 98        G Perry    110.39     Added in reference to fte_value
117                                             and total_fte_value. This way we
118                                             can cache full time equivalents
119                                             this can be used by BENDRPAR.
120      04 Jun 98       jcarpent    110.40     Restricted call to bendenrr.
121      04 Jun 98       G Perry     110.41     Fixed compilation error and
122                                             moved output string to correct
123                                             position following change 110.40
124      05 Jun 98       G Perry     110.42     Add last place variable to
125                                             call before deenrollment.
126      07 Jun 98       G Perry     110.43     Changed name of package/proc for
127                                             dependent eligibility Added
128                                             global for last_pgm_id.
129                                             Fixed elig_to_prte_rsn_f bug,
130                                             this is only derived in life
131                                             event mode.
132      07 Jun 98       Ty Hayden   110.44     Added call to ben_determine_coverage
133      07 Jun 98       G Perry     110.46     Added in scheduled enrollment
134                                             logic.
135      08 Jun 98       G Perry     110.47     Removed exit statement.
136      08 Jun 98       G Perry     110.48     Fixed skipping of comp objects
137                                             when eligibility fails for a plan
138                                             or program.
139      11 Jun 98       G Perry     110.49     Including logic for temporal
140                                             life event processing.
141      12 Jun 98       Ty Hayden   110.50     Added call to ben_determine_rates
142      12 Jun 98       G Perry     110.51     Fixed error when defaulting
143                                             person types for contacts.
144      13 Jun 98       G Perry     110.52     Added Message names
145                                             Added parameter output.
146      14 Jun 98       G Perry     110.53     Added procedure
147                                             ben_determine_elct_chc_flx_imp.
148      14 Jun 98       G Perry     110.54     Improved life event cursor.
149      18 Jun 98       G Perry     110.55     Fixed when ineligible for
150                                             program ineligible for plan.
151                                             Fixed so that scheduled life
152                                             event is not commited.
153      08 Jul 98       jcarpent    110.56     Added p_popl_enrt_typ_cycl_id arg
154      21 Jul 98       G Perry     110.57     Fixed c_person_life cursor so
155                                             subselect only picks up detected
156                                             or unprocessed life events.
157      30 Jul 98       G Perry     110.58     Fixed cursor for percent full
158                                             time stuff from budget values.
159                                             Removed hr_lookups from
160                                             assignment cursor, this is not
161                                             needed.
162      03 Aug 98       F Martin    110.59     Reordered queries for greater
163                                             efficiency. These now utilise
164                                             more efficient indexes.
165      06 Aug 98       G Perry     110.60     Added check_business_rules
166                                             procedure to easily collate all
167                                             business rules.
168                                             Fixed bugs 490,491,492,493,494
169      10 Aug 98       G Perry     110.61     Added in concurrent request
170                                             columns to create_benefit
171                                             _actions_api call.
172      11 Aug 98       G Perry     110.62     Validate mode now multi-threads.
173                                             Moved person_actions code to
174                                             new module benbatpe.pkb.
175      24 Aug 98       G Perry     110.63     Added new globals to structure
176                                             for use in bendenrr.
177      26 Aug 98       G Perry     115.33     Moved person_selection_rule
178                                             into benbatpe.pkb.
179                                             Fixed wwbug 1129.
180      27 Aug 98       G Perry     115.34     Fixed bug 608.
181                                             problem was outer-join to
182                                             per_assignment_budget_values.
183      28 Aug 98       G Perry     115.35     Added check to test for whether
184                                             electable choices were written
185                                             for a life event that was being
186                                             processed.
187      28 Aug 98       G Perry     115.36     Removed logic where we store all
188                                             old potential life event info.
189      23 Sep 98       G Perry     115.37     Split up code so Prasad can do
190                                             his whatif functionality in
191                                             stages.
192      24 Sep 98       G Perry     115.38     Added in code to copy action id
193                                             to global structure for Prasad.
194      07 Oct 98       G Perry     115.39     Corrections following schema
195                                             issues. Added slave logic.
196      15 Oct 98       G Perry     115.40     Added new cache info for oipl.
197      20 Oct 98       J Carpenter 115.41     Added new cache info for pl+pgm.
198      20 Oct 98       J Carpenter 115.42     Added new columns to pgm cache
199      24 Oct 98       T Guy       115.43     Moved call to ben_determine_rate
200                                             inside people loop.  Added column
201                                             person_id to call.
202      25 Oct 98       G Perry     115.45     Added ben_generate_communications
203      26 Oct 98       G Perry     115.46     Added hourly_salaried_code to
204                                             assignment select to go in cache
205      30 Oct 98       G Perry     115.47     Added in logic for unrestricted
206                                             enrollment and multiple scheduled
207                                             enrollment.
208      31 Oct 98       G Perry     115.49     Fixed error messages.
209      02 Nov 98       G Perry     115.50     Used new call to get parameters.
210      10 Nov 98       G Perry     115.51     Validate mode now regularly
211                                             commits to the logfile. All
212                                             modes now use true
213                                             multithreading. Made master
214                                             process drive from a cursor
215                                             rather than a global. Used
216                                             new mathod of writing to cache
217                                             structure rather than
218                                             ben_reporting table.
219      23 Nov 98       G Perry     115.52     Added support for rates and
220                                             factors which means that call
221                                             to determine_elig_prfls and
222                                             derive_rates_and_factors have
223                                             new parameters.
224      07 Dec 98       G Perry     115.53     Added support for object
225                                             selection rule.
226      17 Dec 98       G Perry     115.54     Added caching logic for logging
227                                             info.
228      21 Dec 98       G Perry     115.55     Fixed cussor to just bring back
229                                             unrestricted for unrestricted
230                                             mode.
231      22 Dec 98       T Guy       115.56     Added ben_determine_rate_chg
232 
233      28 Dec 98       J Lamoureux 115.57     Commented out nocopy parameters dflt_
234                                             enrt_dt and elcn_made_dt in call
235                                             to person_life_event.
236      31 Dec 98       G Perry     115.58     Added people group to cache
237                                             and commented out nocopy rate change
238                                             call. tanie to fix.
239      01 Jan 99       G Perry     115.59     Global g_number_proc_objects was
240                                             not being reset to 0 in multi-
241                                             thread process.
242      02 Jan 99       G Perry     115.60     Added call to ben_cel_cache proc.
243      02 Jan 99       G Perry     115.61     Fixed cache_person_ler_information.
244      18 Jan 99       G Perry     115.62     LED V ED
245      18 Jan 99       T Guy       115.63     added lf_evt_ocrd_dt to rate change
246                                             call.
247      25 Jan 99       G Perry     115.64     Added p_mode variable so that
248                                             we only call certain stuff under
249                                             certain conditions. Makes the
250                                             run faster.
251      08 Feb 99       G Perry     115.65     Added in parameter
252                                             ptnl_ler_trtmt_cd in call to
253                                             derive rates and factors.
254      11 Feb 99       G Perry     115.66     Fixed error trace message prior
255                                             to evaluate life events call.
256      17 Feb 99       G Perry     115.67     Added once_r_cntug_cd and elig
257                                             flag param to determine_elig_
258                                             prfls and derive_part_and_rate_
259                                             facts.
260      18 Feb 99       G Perry     115.68     Support for canonical dates.
261      24 Feb 99       G Perry     115.69     Support for restart process.
262      26 Feb 99       T Guy       115.70     Added ben_determine_chc_ctfn
263      27 Feb 99       G Perry     115.71     Added Concurrent request id to
264                                             log. Added business_group_id
265                                             parameter to check_all_slaves
266                                             _finished procedure.
267      03 Mar 99       G Perry     115.72     Fixed unrestricted mode so it
268                                             creates batch_ler_info record.
269      09 Mar 99       G Perry     115.73     Changed c_pln cursor so it
270                                             picks up all plans if none are
271                                             specified for an enrollment
272                                             period. Bug 1924.
273      15 Mar 99       G Perry     115.75     Changed parameter order of
274                                             process procedure per bug 1529.
275      22 Mar 99       Tmathers    115.76     Changed -MON- to /MM/
276      05 Apr 99       mhoyes      115.78   - Un-datetrack of per_in_ler_f changes
277                                           - Removed DT restriction from
278                                             process_rows/c_ler_exists.
279                                           - Modified calls to per_in_ler and
280                                             ptnl_ler_for_per APIs
281      16-mar-99       pbodla      115.79   - If the supplied mode  and mode of
282                                             winning life event differ, raise
283                                             error. p_enrt_perd_id parameter
284                                             added to create_ptnl_ler_for_per
285                                             in C mode.
286      21-APR-99       mhoyes      115.80   - Added p_popl_enrt_typ_cycl_id to
287                                             all calls to create_ptnl_ler_for_per
288      22-APR-99       GPerry      115.81     Added call set_potential_ler_id.
289                                             for temporal mode.
290      22-APR-99       mhoyes      115.82   - Modified call to
291                                             create_ptnl_ler_for_per and
292                                             update_ptnl_ler_for_per
293      23-APR-99       GPerry      115.83     Added p_mode to evaluate life
294                                             event call.
295      22-APR-99       mhoyes      115.84     Modified per in ler calls.
296      29-APR-99       shdas       115.85     Added to parameter list of
297                                             benutils.formula.
298      06-May-99       TGuy        115.86     uncommented rate change call
299      06-MAY-99       shdas       115.87     Added jurisdiction_code.
300      06-May-99       bbulusu     115.89     Added original_hire_date to the
301                                             person cache.
302      06-May-99       GPerry      115.90     Backport for Fidelity.
303      06-May-99       GPerry      115.91     Leapfrog from 115.89
304      10-May-99       GPerry      115.92     Backport Fix.
305      10-May-99       GPerry      115.93     Leapfrog from 115.91
306      14-May-99       GPerry      115.94     Support for PLIP and PTIP.
307      15-May-99       GPerry      115.95     Fix for Bug 2107. Ensure only
308                                             active comp objects are included.
309      18-May-99       GPerry      115.96     Added calls to environment routine.
310                                             Now we capture the message correctly
311                                             through the app_exception and
312                                             g_record_error exceptions.
313                      lmcdonal    115.97     Added rudimentary p_comp_object_name
314                                             for ptip and plip.  Also increase
315                                             length of comp object name in log.
316      20-May-99       jcarpent    115.98     Change enrt_perd_for_pl query to
317                                             handle no record condition and
318                                             allow no rows for flex and impt inc
319      27-May-99       G Perry     115.99     Changed c_pgm cursor so we pick
320                                             up cobra programs last.
321      02-May-99       bbulusu     115.100    Added 3 columns to c_person cursor
322                                             to fetch into the g_cache_person.
323      06-Jun-99       stee        115.101    Added 3 new cursors,c_pgm2,c_pln2,
324                                             c_oipl2 to build_comp_object
325                                             to process the COBRA program last.
326      09-Jun-99       stee        115.102    Only process COBRA last if in
327                                             life event or unrestricted mode.
328      16-Jun-99       bbulusu     115.103    Added call to ben_person_object to
329                                             cache info for person being procssed
330      18-Jun-99       G Perry     115.104    Removed FTE code and derived factor
331                                             life event stuff. This is all
332                                             cache on demand in the
333                                             ben_person_object and
334                                             ben_seeddata_object packages.
335      21-Jun-99       mhoyes      115.105    Added new trace messages.
336      23-Jun-99       G Perry     115.106    Added resetting calls to setenv
337                                             so that flags are reset correctly.
338      25-Jun-99       G Perry     115.107    Added call to ben_life_object.
339                                             Removed ben_person_object routine
340                                             as cache is cache on demand.
341      25-Jun-99       G Perry     115.108    Added p_rec to ben_comp_object.
342                                             set_object call.
343      28-Jun-99       mhoyes      115.109    Added new trace messages.
344      28-Jun-99       tguy        115.110    Added new call to
345                                             ben_determine_actual_premium.main
346      01-JUL-99       pbodla      115.111    Changes related with << Life Event Collision >>
347                                             added call to get_ori_bckdt_pil()
348                                             added call to p_lf_evt_clps_restore()
349      05-JUL-99       mhoyes      115.112  - Externalised c_pln_nip to
350                                             ben_pln_cache.nipplnpln_getdets.
351                                           - Added new trace messages.
352      07-JUL-99       mhoyes      115.113  - Backed out nocopy c_pln_nip cache.
353      07-JUL-99       shdas       115.114    Added setenv for business_group in evaluate_life_events.
354      08-JUL-99       mhoyes      115.115  - Added new trace messages.
355      09-JUL-99       mhoyes      115.116  - Added new trace messages.
356                                           - Removed + 0s from all cursors.
357      19-JUL-99       stee        115.117  - Fixed c_pln cursor to limit
358                                             check for enrd_perd_for_pl by
359                                             business_group_id. Also, do
360                                             not call actual premium if
361                                             no choices are created.
362      20-JUL-99       GPerry      115.118    genutils -> benutils package rename
363      26-JUL-99       GPerry      115.119    Removed ben_timing stuff.
364      26-JUL-99       GPerry      115.120    Added calls to dt_fndate.
365                                             Added call to new
366                                             create_perf_benefit_actions to
367                                             reduce bottleneck.
368                                             Added call to clear_down_cache in
369                                             benutils package.
370      26-JUL-99       GPerry      115.121    Removed setenv for business_group
371                                             in evaluate_life_events.
372      27-JUL-99       mhoyes      115.122  - Fixed genutil problems.
373      29-JUL-99       mhoyes      115.123  - Assigned globals to locals in
374                                             process_comp_objects.
375                                           - Added new trace messages.
376                                           - Modified references to benutils.
377                                             to bentype.
378      10-AUG-99       Gperry      115.124    Removed global references to
379                                             g_cache_person and the like.
380                                             Rewrote person_header.
381      24-AUG-99       Gperry      115.125    Fixed p_no_plans flag so it
382                                             only applies to plans not in
383                                             programs.
384      26-AUG-99       Gperry      115.126    Added call to benefits assignment
385                                             if employee assignment is null.
386      31-AUG-99       Gperry      115.127    Changed call to ptnl_ler_for_per.
387      31-AUG-99       mhoyes      115.128  - Added new trace message.
388      01-SEP-99       Gperry      115.129    Changed call to determine
389                                             eligibility.
390      14-SEP-99       Gperry      115.130    Fixed bug 2907. Life event occurred
391                                             date is now passed to automatic
392                                             enrollment routine.
393      15-SEP-99       Gperry      115.131    Added audit log flag to main
394                                             process procedure.
395      28-SEP-99       Stee        115.132    Changed where clause to select
396                                             COBRA pgms with a pgm_typ like
397                                             'COBRA%' instead of COBRA.
398      28-SEP-99       tguy        115.133    Moved closing of per_in_ler to
399                                             after rate change check.  This
400                                             allows us to avoid duplication
401                                             and throughing off counts for
402                                             reporting purposes
403      04-OCT-99       mhoyes      115.134  - Tuned build_comp_object_list.
404                                             Replaced c_pln and c_oipl with
405                                             bgpcpp_getdets and bgpcop_getdets.
406      04-OCT-99       stee        115.135  - Added ptip_id to
407                                             g_cache_person_prtn.
408      04-OCT-99       mhoyes      115.136  - Added calls to flush_global_structures
409                                             to clear build_comp_object_list
410                                             plip and oipl caches.
411      08-OCT-99       jcarpent    115.137  - Moved auto_enrt to after rates
412                                             are created. Fixed some calling_
413                                             proc tokens
414      13-OCT-99       gperry      115.138    Fix bug 2703.
415      13-OCT-99       gperry      115.139    Fix bug 2960.
416      25-OCT-99       gperry      115.140    Fix bug 3103.
417      03-NOV-99       mhoyes      115.141  - Added comp object filtering
418                                             to improve performance. After
419                                             BENDETEL when the comp object
420                                             for the person is still in-eligible
421                                             or first time in-eligible then all
422                                             other processing in the loop is
423                                             skipped.
424      13-NOV-99       mhoyes      115.142  - Added trace messages.
425      14-NOV-99       gperry      115.143    Added mode to ben_batch_reporting
426                                             package call.
427      19-NOV-99       GPERRY      115.144    Added new flags.
428      22-NOV-99       PBODLA      115.145    Bug : 3511 : When a potential already
429                                             sitting and benmngle is ran in scheduled
430                                             mode with a effective date other than
431                                             life event occured date a duplicate
432                                             potential is being created and benmngle
433                                             is stopping. Use lf_evt_ocrd_dt instead
434                                             of effective_date in the where clause
435                                             of c_ler_exists.
436      24-NOV-99       mhoyes      115.146  - Bug : 3511 : Modified c_ler_exists
437                                             to restict by not in VOIDD and PROCD
438                                             rather than only DTCTD or UNPROCD
439                                           - Removed obsolete c_ler_exists cursor
440                                             from c_ler_exists.
441      24-NOV-99       jcarpent    115.147  - Added more bendenrr globals so pil can
442                                             be closed when no auto/electable epes
443                                             are created.
444      12-DEC-99       pbodla      115.148  - Modified c_ler_exists to look for
445                                             DTCTD or UNPROCD ( chaged not in to in
446                                             part of where clause)
447      22-DEC-99       gperry      115.149    Modified create_life_person_actions
448                                             call which occurred due to fix in
449                                             1096742.
450      30-DEC-99       maagrawa    115.150    Added parameter business_group_id.
451                                             to ben_determine_rate_chg.main
452      03-FEB-00       mhoyes      115.156  - Added HPAPRTTDE and HPADPNTLC to
453                                             call to generate communications.
454                                           - Modified process_comp_object to
455                                             process local l_comp_obj_tree.
456                                           - Fixed problem with app_exception. The
457                                             error from process_life_events is
458                                             now suppressed rather than raised. The
459                                             error is raised when max errors is
460                                             reached.
461                                           - Rolled back to pre-filtering.
462      07-FEB-00       mhoyes      115.157  - Modified/Added trace messages for
463                                             profiling.
464                                           - Fixed bug 1178659. Error was being
465                                             raised from the g_record_error
466                                             exception because life event occured
467                                             date had not been derived. Set the
468                                             life event occured date to the
469                                             effective date.
470      10-FEB-00       mhoyes      115.158  - Fixed bug 1169238. The eligibility
471                                             profile cache was not being cleared
472                                             down from build_comp_object_list.
473                                             Called ben_elp_cache.clear_down_cache
474                                             when comp object list is re-built.
475                                           - Added clear_init_benmngle_caches to
476                                             clear caches and globals at the
477                                             benmngle level. This should also be
478                                             called from on-line benmngle.
479                                           - Added call to
480                                             ben_person_object.clear_down_cache
481                                             from flush_global_structures. This
482                                             means that person cache information
483                                             is cleared between multiple benmngle
484                                             runs.
485      21-Feb-00     lmcdonal      115.159    load ptip id thru calls to setenv.
486                                             Bug 1179550.
487      25-Feb-00     mhoyes        115.160  - Added trace messages.
488                                           - Bug 1179550. Nullified ptip id and
489                                             plip_id values to avoid multiple
490                                             program issues.
491                                           - Revamped elig flags to uses a local
492                                             record structure rather than globals.
493                                           - Passed p_comp_obj_tree_row into
494                                             determine_eligibility. Currently
495                                             dual supporting ben_env_object
496                                             comp object globals in parallel
497                                             with p_comp_obj_tree_row. Bendrpar
498                                             totally uses p_comp_obj_tree_row but
499                                             bendetel, bendete2 and benwtprc still
500                                             need to be moved over.
501      27-Feb-00     stee         115.161  -  Added new parameter,
502                                             p_cbr_tmprl_evt_flag.
503      28-Feb-00     stee         115.162  -  Pass p_cbr_tmprl_evt_flag to
504                                             update benefits action.
505      28-Feb-00     stee         115.163  -  Pass p_cbr_tmprl_evt_flag to
506                                             all relevant procedures.
507      01-MAR-00     pbodla       115.164  -  Bug 4186 : Added csd_by_ptnl_ler_for_per
508                                             to create_related_person_ler call.
509      01-MAR-00     pbodla       115.165  -  Do not run restore if electable choices
510                                             are not created
511      01-MAR-00     pbodla       115.166  -  Bug : 4293/1172230 : Message to indicate
512                                             in what mode benmngle to run in case the
513                                             supplied mode is different.
514      02-MAR-00     stee         115.167  -  Update COBRA qualified beneficiary
515                                             information if COBRA electable
516                                             choices exist.
517      03-MAR-00     mhoyes       115.168  -  Phased out nocopy ben_env_object for comp
518                                             objects.
519      04-MAR-00     mhoyes       115.169  -  Added comp object cache parameters to
520                                             load_cache.
521                                          -  Stored parent comp object ID values
522                                             on the comp object cache.
523                                          -  Added support for elig_tran_state.
524                                             Phased out nocopy first_inelig and
525                                             still_inelig flags.
526      04-MAR-00     mhoyes       115.170  -  Modified build_comp_object_list to
527                                             process one comp object per cache
528                                             row.
529                                          -  Revamped comp object list to reflect
530                                             the new cache struture.
531      04-MAR-00     mhoyes       115.171  -  Fixed problem with parent elig flag
532                                             at ptip and plip levels.
533      05-MAR-00     mhoyes       115.172  -  Fixed problem with cobra oipls
534                                             in build comp object list. The
535                                             parent comp object information
536                                             was not being populated.
537      05-MAR-00     stee         115.173  -  Update cobra eligibility
538                                             only in life event or
539                                             unrestricted mode.
540      06-MAR-00     gperry       115.174     Changed process_life_events to use
541                                             nocopy so that we can use locals
542                                             to trap the number of errors.
543                                             Also made sure that when max errors
544                                             is hit the process stops.
545      07-MAR-00     mhoyes       115.175   - Moved build comp object list out
546                                             to ben_comp_object_list package
547                                             file bebmbcol.pkh.
548      08-MAR-00     mhoyes       115.176   - Added trace messages for profiling.
549      13-MAR-00     mhoyes       115.177   - Phase 5 performance. Implemented
550                                             PTIP level comp object filtering
551                                             in process_comp_objects.
552      14-MAR-00     mhoyes       115.178   - Phase 7 performance. Implemented
553                                             PLIP level comp object filtering
554                                             in process_comp_objects.
555                                           - Initialised comp object cache
556                                             global from
557                                             clear_init_benmngle_caches.
558                                           - Phase 8 performance. Implemented
559                                             plan and oipl level comp object
560                                             filtering in process_comp_objects.
561                                           - created set_up_cobj_part_elig and
562                                             moved set_up_part_elig from
563                                             build comp object list to
564                                             process comp objects.
565      15-MAR-00     mhoyes       115.179   - Modified get_comp_object_name so
566                                             that comp object ids are not
567                                             truncated from the audit log.
568      17-MAR-00     mhoyes       115.190   - Fixed eligible parent flag problems.
569      18-MAR-00     mhoyes       115.181   - Fixed filtering problems at PTIP
570                                             and PLIP levels.
571      21-MAR-00     pbodla       115.182   - Bug : 4919 :  c_ler_exists modified
572                                            ; do not create potential even if a
573                                             processed potetial exists.
574      23-MAR-00     mhoyes       115.183   - Bug : 4965 :  Fixed PLIP and Plan
575                                             level newly in-eligible problems.
576                                           - Fixes COBRA related coverage problem.
577      24-MAR-00     mmogel       115.184   - Added p_ntfn_dt to the call to
578                                             ben_ptnl_ler_for_per_api.create_
579                                             ptnl_ler_for_per in Procedure
580                                             evaluate_life_events (bug 4806/
581                                             1247107)
582      28-MAR-00     mhoyes       115.185   - Fixed benmngle caching issue. Added
583                                             pgm_id restriction to plan and oipl
584                                             level restrictions when checking
585                                             previous eligibility in
586                                             check_prevelig_compobj.
587      29-MAR-00     mhoyes       115.186   - Fixed 5009. Modified cursors in
588                                             check_prevelig_compobj to use
589                                             par_pgm_id rather than pgm_id.
590      30-MAR-00     mhoyes       115.187   - Fixed 1190876. Added logic and
591                                             routines to eliminate duplicate
592                                             PTIP processing.
593                                           - Turned off filtering in temporal
594                                             mode.
595      30-Mar-00     maagrawa     115.188   - For reporting purposes, to get
596                                             total person persons processed, add
597                                             persons processed successfully
598                                             and persons errored. (1133281).
599      31-Mar-00     gperry       115.189     Added oiplip support.
600      31-Mar-00     gperry       115.190     Fixed WWBUG 1178676.
601      01-Apr-00     stee         115.191     Create benefit assignment
602                                             for dependent if he/she
603                                             is found ineligible.
604      04-Apr-00     mhoyes       115.192   - Fixed duplicate PTIP problem at
605                                             PTIP filtering level for multiple
606                                             PTIPs wnen track in-eligibility is
607                                             Y.
608     06-Apr-00      lmcdonal     115.193     debugging messages.
609     06-Apr-00      stee         115.194     Check cobra requirements even
610                                             if choices are not electable.
611     10-Apr-00      stee         115.195     Only update cobra eligibility
612                                             dates if event is a cobra qualifying
613                                             event.
614     12-Apr-00      mhoyes       115.196   - Fixed 5075. Initialised eligible flag
615                                             on the duplicate PTIP global in
616                                             check_dupproc_ptip so that
617                                             it defaults to false. This prevents
618                                             parent eligibility flags being set
619                                             incorrectly when the PTIP is filtered.
620                                             Previously un-initialised the value
621                                             defaulted to true causing the PTIP
622                                             to be filtered and the plip below to be
623                                             processed.
624     14-Apr-00      pbodla       115.197   - Fixed 5093 : When unrestircted ptnl's
625                                             created notification date is populated.
626     14-Apr-00      stee         115.198     Update cobra info if mode is
627                                             Unrestricted( for core customers).
628     21-Apr-00      gperry       115.199     Fixed bug 5062 by testing for
629                                             whether a PTIP has been found when
630                                             filtering happened at the PTIP
631                                             level.
632     01 May 00      pbodla       115.200  -  Task 131 : Elig dependent rows are
633                                             created before creating the electable
634                                             choice rows. Called procedures
635                                             ben_determine_dpnt_eligibility.main()after
636                                             calling ben_determine_eligibility.determine_elig_prfls.
637                                             p_upd_egd_with_epe_id called after
638                                             electable choice is created to set
639                                             electable choice id on dependent rows.
640     12 May 00      mhoyes       115.201  -  Pulled filtering out nocopy of benmngle into
641                                             ben_comp_obj_filter.
642     12 May 00      stee         115.202  -  Fix c_get_inelig_dpnt_info cursor.
643     15 May 00      mhoyes       115.203  -  Called get_comp_object_name
644                                             procedure only when audit log flag
645                                             is Y.
646     22 May 00      mhoyes       115.204  -  Revamped set_up_cobj_part_elig so that
647                                             cached current and parent rows are
648                                             passed down through bendetel and
649                                             bendete2.
650     23 May 00      mhoyes       115.205  -  Passed p_comp_obj_tree_row into
651                                             enrolment_requirements.
652     24 May 00      mhoyes       115.206  -  Called ben_pil_object.clear_down_cache
653                                             from flush_global_structures.
654     26 May 00      pbodla       115.207  -  Bug 5123 : Added p_run_mode, p_enrt_perd_id
655                                             parameters to determine_elig_prfl proc.
656     31-May-00      gperry       115.208     BP of 115.198 with thread fix.
657     31 May 00      mhoyes       115.209  -  Passed through cuurent comp object rows
658                                             into bendenrr.
659     05 Jun 00      stee         115.210  -  Move electable chc certification
660                                             process into the comp object loop.
661                                             wwbug #1308629.
662     22 Jun 00     kmahendr      115.211  -  Added a cursor in process_comp_objects procedure
663                                             to check whether pil_elctbl_popl_stat is to be
664                                             updated to PROCD - wwbug #1277369
665     26 Jun 00     stee          115.212  -  Change p_derivable_factors to a
666                                             code.
667     27 Jun 00     mhoyes        115.213  -  Fixed temporal mode audit log problem.
668                                          -  Moved person cache calls out nocopy of bendetel
669                                             and into process_comp_objects.
670     28 Jun 00     jcarpent      115.214  -  Bug 5176, 1329041. Pass more args
671                                             to bebmfilt.pkb filter_comp_objects.
672     29 Jun 00     mhoyes        115.215  -  Passed mode_cd to create_normal_person_actions.
673     05 Jul 00     mhoyes        115.216  -  Passed context parameters through to bendrpar.
674     10 Jul 00     mhoyes        115.217  -  Bypassed filtering in temporal mode.
675     13 Jul 00     mhoyes        115.218  -  Removed context parameters.
676     19 Jul 00     jcarpent      115.218  -  5241,1343362. Added update_defaults
677     26 Jul 00     gperry        115.219     Fixed BUG 5422/1365397.
678                                             SCheduled enrollment now voided
679                                             when no changes made to elig,
680                                             elect, rates, etc.
681     02 Aug 00     mhoyes        115.220  -  Moved call to set_temporal_ler_id
682                                             outside of process_comp_object loop.
683 
684     24 Aug 00     mhoyes        115.221  -  Memory leaking fixes for bug 1387371.
685     05 Sep 00     pbodla        115.222  -  Bug 5422 : Allow different enrollment periods
686                                             for programs for a scheduled  enrollment.
687                                             p_popl_enrt_typ_cycl_id is removed.
688     06 Sep 00     jcarpent      115.223  -  Leapfrog version based on 115.221
689                                             Fixes bug 1398444.  Participation
690                                             cache was not cleared between people
691     06 Sep 00     jcarpent      115.224  -  Merged version of 115.222 with 115.223.
692     18-Sep-00     pbodla        115.225  - Healthnet changes : PB : Added parameter
693                                            p_lmt_prpnip_by_org_typ_id to
694                                            Comp objects are now selected based on person's
695                                            organization id if p_lmt_prpnip_by_org_typ_id is
696                                            Y.
697     22-Sep-00     gperry        115.226    Added back param
698                                            p_popl_enrt_typ_cycl_id as otherwise
699                                            do_multithread bombs.
700                                            WWBUG 1412825.
701     25-Sep-00     gperry        115.227    Added call to reset life event
702                                            occurred date when BENMNGLE errors
703                                            in eveluate_life_events procedure.
704                                            WWBUG 1412614.
705     26-Sep-00     gperry        115.228    Fixed WWBUG 1412808.
706                                            Clear pil_cache for cases where a
707                                            backout may have occurred that
708                                            called communications.
709 
710     27 Sep 00     pbodla        115.229    - Code added due to BUG 5422/1365397,
711                                             in version 115.219 is removed.
712                                            - Pil no longer required to be voided
713                                              if there is no impact of it on
714                                              eligibility, rates etc.,. It should
715                                              become processed.
716     05 Oct 00     gperry        115.230    Fixed call to ben_determine_eligibility
717                                            so that it passes the life event
718                                            occurred date as p_effective_date
719                                            when run in selection mode. This
720                                            is due to how least work in bendete2
721                                            for Prasads fixes.
722     06 Oct 00     pbodla        115.231    -- Above fix is removed as, the
723                                            fix should be in bendete2.pkb
724     13 Oct 00     rchase        115.232    ensure caches are cleared properly
725                                            when processing comp objects.
726     19 OCT 00     rchase        115.233    wwBug1427383 - return correct date for
727                                            creating dependent benefit assignment
728     07 Nov 00     mhoyes        115.234  - Added comp object loop electable choice
729                                            context global.
730                                          - Added clear down cache call for the
731                                            electable choice list.
732     08 Nov 00     vputtiga      115.235  - Fixed Bug 1485814.
733                                            g_enrollment_change global set to FALSE.
734                                            added a call at end of process_comp_objects to
735                        ben_prtt_enrt_result.update_person_type_usages
736                                            Leapfrog based on 115.233.
737     15 Nov 00     jcarpent      115.236    Merged version of 115.235 and 115.234
738     22 Nov 00     tmathers      115.238    Merged version of 115.236 and 115.237
739     05 Jan 01     kmahendr      115.239    Unrestricted life event process changes
740     16 Jan 01     mhoyes        115.240  - Raised the oracle error code for the
741                                            generic 91665 error.
742     18 Jan 01     mhoyes        115.242  - Leapfrog of 115.240.
743     23 Jan 01     mhoyes        115.242  - Modified the call to coverage for EFC.
744     22 Mar 01     mhoyes        115.244  - Fixed multi-threading problem with
745                                            g_ler_id which was only being set in
746                                            the master and not the slaves.
747     28 Mar 01     gvenkata      115.245  - Bug 1696526.  Was using lf_evt_ocrd_dt
748                                            from previous person for caching assignment.
749                                          - Bug 1636071.  In call to benmgle from
750                                            benauthe g_modified_mode was not being
751                                            used so open events were not working.
752    09 Apr  01    kmahendr       115.246  - Bug 1543462 - If life event is opened and closed
753                                            in the same run, benmngle is to use least of sysdate or
754                                            effective_date to update processed date for active
755                                            life event
756    23 May  01    mhoyes         115.247  - Added refresh cache call for benelmen cache.
757    01 Jul  01    kmahendr       115.248  - Unrestricted process changes
758    18 Jul  01    ikasire        115.249    Commented the call to default enrollment
759                                            see details in bug 1874263 or in this
760                                            package at the place of call to
761                                            ben_manage_default_enrt.Process_default_enrt
762   19 Jul  01     kmahendr        115.250 - Bug#1871579- Effective date is greater
763                                            than unrestricted life event started date
764                                            benmngle errors out. made changes to
765                                            call ben_person_object.get_object and
766                                            ben_determine_derive_factors
767   30 Jul  01     pbodla          115.251 - Bug : 1894718 Also treat the electable
768                                            choices associated with suspended
769                                            enrollments as in pending work flow.
770                                            In other words do not delete the electable
771                                            choices data and other data if the
772                                            enrollment is in suspended state.
773   02-Aug-01      ikasire         115.251   Bug 1895846 added two new procedures
774                                            delete_in_pndg_elig_dpnt and
775                                            reset_elctbl_chc_inpng_flag
776                                            see bug for more details
777   28-Aug-01      kmahendr        115.252   updating of ben_enrt_rt in U mode
778                                            removed - Bug#1936976
779   11-Aug-01      kmahendr        115.253   Bug#1900657-Added codes in procedure
780                                            process_comp_objects
781   25-Sep-01      kmahendr        115.254   Made changes for R mode - private
782                                            procedure update_elig_row added
783   26-Sep-01      kmahendr        115.255   In R mode report for error not called
784   26-Sep-01      kmahendr        115.256   Only Activity Summary not called
785   05-Oct-01      kmahendr        115.257   Bug#2032672-added l_mode = C before
786                                            checking of electbl choice created
787                                            call
788   08-Oct-01      kmahendr        115.259   115.257 brought forward as version
789                                            115.258 was a leap frog version of
790                                            115.251 and fix of 115.257
791   26-Oct-01      maagrawa        115.260   Backported to 115.252
792                                            Do not create choices for "Save for
793                                            Later" ICD entries.
794   26-Oct-01      maagrawa        115.261   115.259 + 115.260.
795   09-Nov-01      mhoyes          115.262 - Fixed 2105125. Added hint to always
796                                            use index in cursor c_range_thread.
797                                            This avoids a full table lock on
798                                            ben_batch_ranges when running
799                                            multi-threaded.
800   30-Nov-01      mhoyes          115.263 - Made p_benefit_action_id in/out on
801                                            process.
802   03-Dec-01      mhoyes          115.264 - Re-enabled mode validation.
803   03-Dec-01      mhoyes          115.265 - dbdrv line.
804   04-Dec-01      kmahendr        115.266 - Bug#2097833 - parameter -p_per_in_ler_id
805                                            is added to ben_determine_dpnt_eligibility.
806                                            main call
807   06-Dec-01      mhoyes          115.267 - Fixed concurrent manager problem
808                                            with new CAGR OUT NOCOPY parameter on process.
809                                            Added new routine inner_process.
810   07-Dec-01      mhoyes          115.268 - Passed p_per_in_ler_id to
811                                            enrolment_requirements.
812   11-Dec-01      mhoyes          115.269 - Passed p_per_in_ler_id to
813                                            update_defaults.
814   19-Dec-01      pbodla          115.270 - CWB Changes : New mode W added for
815                                            processing comp work bench events.
816   27-Dec-01      pbodla          115.271 - CWB Changes : Added
817                                            popu_cross_gb_epe_data - to create
818                                            pil, epe, pel, ecr data for managers
819                                            who are in different business group
820                  ikasire         115.271 - CWB Changes : Added popu_epe_heir
821                                            to populate performace table.
822   04-Jan-02      pbodla          115.272 - CWB Changes : Call procedure
823                                            popu_cross_gb_epe_data only in W
824                                            mode
825   07-Jan-02      rpillay         115.273 - Added Set Verify Off.
826   07-Jan-02      pbodla          115.274 - CWB Changes : Also delete the rows
827                                            for employees who do not have
828                                            subordinates and with level -1
829   08-Jan-02      ikasire         115.275   Bug 2172031 changes the order of
830                                            parameters in cwb_process
831   11-Jan-02      ikasire         115.276   Added a new public procedure
832                                            rebuild_heirarchy for rebuilding
833                                            the CWB hierarchy.
834   11-Jan-02      ikasire         115.277   More changes to popu_epe_heir and
835                                            rebuild_heirarchy
836   11-Jan-02      ikasire         115.278   Bug 2172036 changed a call to
837                                            after making it from function to
838                                            procedure with extra assignment_id
839                                            column.
840   18-Jan-02      mhoyes          115.279 - Fixed restart null benefit action
841                                            problem. Introduced by CAGR.
842   01-Feb-02      stee            115.280 - Update cobra information for
843                                            a life event type of 'ENDDSBLTY'.
844                                            Bug#2068332.
845   12-Feb-02      mhoyes          115.281 - Added write_bft_statistics and
846                                            init_bft_statistics.
847                                          - Moved delete_elctbl_choice and
848                                            update_in_pend_flag to
849                                            ben_manage_unres_life_events.
850   12-Feb-02      mhoyes          115.282 - Removed dbms_output.
851   15-Feb-02      rpillay         115.283 - Bug# 2214961 removed check for
852                                            Ineligibility (l_continue_loop)
853                                            for CWB (l_mode = 'W')
854   19-Feb-02     ikasire          115.284   Bug 2172036 and 2231371 fixes
855                                            popu_cross_gb_epe_data was not
856                                            passing assignment_id in the
857                                            creation of epe
858   27-Feb-02     pabodla          115.285   Bug 2237993 CWB - moved
859                                            popu_cross_gb_epe_data call form
860                                            process_rows to internal_process
861                                            to avoid creating duplicate records
862                                            for the cross business group.
863   11-Mar-02     mhoyes           115.286   Dependent eligibility tuning.
864   20 Mar 02     tjesumic         115.287   PTIP caching data is refreshed when the
865                                            current row ptip_id is not matching with
866                                            cached ptip_id  bug 2228464
867   25-Mar-02     rpillay          115.289   Fixed CWB Bugs 2270672 and 2275257
868   13-Jun-02     mhoyes           115.290 - Test harness changes for family Pack C.
869                                            Called populate_benmngle_rbvs.
870   15-Jul-02     mhoyes           115.291 - Moved out nocopy start_slaves, grab_next_batch_range
871                                            and check_all_slaves_finished to
872                                            ben_maintain_benefit_actions.
873   26-Jul-02     pbodla           115.292 - ABSENCES - Added procedure abse_process
874                                            to process absences. All the changes for
875                                            absence processing are identified with
876                                            ABSENCES tag.
877   17-Jul-02     kmahendr         115.293 - ABSENCES - Added looping in process_rows.
878   24-Jul-02     mmudigon         115.294 - ABSENCES - Added logic for exiting out nocopy of loop
879                                            in case of error
880   14-Aug-02     stee             115.295   COBRA: If person is no longer
881                                            enrolled in a COBRA program and
882                                            has no enrollment opportunity,
883                                            terminate COBRA eligibility.
884                                            Bug: 1794808.
885   30-Aug-02     ikasire          115.296   CWB Hierarcy changes Bugs 2541072 and 2541065
886   05-Sep-02     lakrish          115.297   Exception g_record_error handled in do_multithread
887                                            - raised by build_comp_object_list
888   13-Sep-02     pbodla           115.298   2288042 Create 0 level heirarchy data if
889                                            manager is processed first and
890                                            employee is processed later benmngle run.
891   18-Sep-02     pbodla           115.299   2288042 Create 0 level heirarchy :
892                                            tested in hrcwbdvl.
893   25-Sep-02     pbodla           115.300   Bug 2574791 : modified popu_hrchy and
894                                            rebuild_hrchy to make reassign employee
895                                            work.
896   28-Oct-02     kmahendr         115.301   Bug#2638681 - effective date is passed instead
897                                            of lf_evt_ocrd_dt for creating person actions
898   29-Oct-02     mmudigon         115.302   CWB: Bug 2526595 Added proc
899                                            del_cwb_pil()
900   18-Nov-02     pbodla           115.303   ABSE: 2673323 For every absence life event
901                                            recache the person data.
902                                            In absence mode several life events
903                                            may be processed in single run, so
904                                            lf_evt_ocrd_dt may change, so recache
905                                            the person data as of current life
906                                            event otherwise leads to inconsistent
907                                            eligibility.
908   01-Dec-02     pabodla          115.304   Arcsing the file with CWB itemization
909                                            code as commented.
910   09-Dec-02     mmudigon         115.305   CWB itemization code uncommented.
911   18-Dec-02     kmahendr         115.306   Bug#2718215 - logic for updating elcns_made_dt
912                                            in update_enrt_rt procedure changed
913   31-Dec-02     pbodla           115.307   Bug#2712602 - CWB : When a comp
914                                            per in ler is backed out nocopy and rerun
915                                            again rebuild the heirarchy.
916   23-Jan-03     mmudigon         115.308   CWB itemization: Added rt edits.
917   25-Jan-03     pbodla           115.309   GRADE/STEP : added code to support
918                                            grade/step processing.
919   25-Jan-03     pbodla           115.310   Modified cursor c3 to remove errors.
920   29-Jan-03     kmahendr         115.311   Added a wrapper for Personnel Action Mode
921   30-Jan-03     pbodla           115.312   Added a wrapper for Grade/step
922                                            progression participation process.
923   06-feb-2003   nhunur           115.313   Commented cursor c2 and an validation in
924                                            check_business_rules for bug - 2784150
925   10-feb-2003   pbodla           115.314   GRADE/STEP : Added code to support
926                                            grade/step processing.
927   14-Feb-2003   mmudigon         115.315   CWB itemization: bug fix 2793785
928                                            modified cursor c5 in check_business
929   14-Feb-2003   rpillay          115.316   HRMS Debug Performance changes to
930                                            hr_utility.set_location calls
931   24-Feb-2003   mmudigon         115.317   CWB itemization: Bug fix 2801671
932                                            Make ineligible for plan if not elig
933                                            for any options
934   07-Mar-2003   nhunur           115.318   Modified code to handle error messages
935                                            properly. Bug - 2836770.
936   14-Mar-2003   lakrish          115.319   Bug 2840078 check that cwb plans/options
937                                            do not have coverages attached
938   10-Apr-2003   mhoyes           115.320 - Bug 2900255 - enabled baseline mode
939                                            for the test harness.
940   11-Apr-2003   tjesumic         115.321 - # 2899702 if the setup is auto enrollment Person Type usages
941                                             are not create.created in close enrollement
942                                             because the multi edit is not called , Person Type usages
943                                             created in multiedit
944                                             autoenrollment calls update_person_type_usages
945                                             with  g_enrollment_change true
946   27-Apr-03     mmudigon         115.322 - Absences July FP enhancements.
947                                            Additional param p_abs_historical_mode
948   01-Aug-03     rpgupta		 115.323 - 2940151 Grade/ step
949   					   1. added some parameters to grade_step_process
950   					   2. Added some checks to procedure
951   					      check_business_rules
952   19-Aug-03     ikasire          115.324   2940151 GSP Added New Procedure gsp_proc_dflt_auten
953                                            and call after determine_rates.
954                                            Need to include pqgspdef.pkh and pqhgsppp.pkh files
955                                            along with this version.
956   20-Aug-03     rpgupta		 115.325 - 2940151 Grade/ step
957   					   Fixed issues in check_business_rule
958   21-Aug-03     mmudigon         115.326 - 2940151 Grade/ step. Loop through
959                                            all GSP potential LEs
960   01-Sep-03     hmani            115.327 - 3087889 Passed lf_evt_ocrd_dt to
961 					   set_up_cobj_part_elig proc instead of effective_date
962   16-Sep-03     pbodla           115.328 - GSP : mode specific get_active_life_
963                                            event procedure is called.
964   22-Sep-03     rpgupta          115.329 - GSP: Passed GSP parameters from procedure
965                                                 grade_step_process to procedure
966 process
967   26-Sep-03     stee             115.330 - 2894200: If derivable factors
968                                            parameter is 'NONE' and there are
969                                            derived factors attached to a
970                                            compensation object, set it to the
971                                            default parameter.
972   11-Nov-03     ikasire          115.331   setting g_no_ptnl_ler_id to evaluate in drpar
973                                            not to trigger potential life events for
974                                            U,M,W,I,P,A Modes - BUG 3243960
975   26-Nov-03     pbodla           115.332   3216667 : iss_val, mx_elcn_val,
976                                            mn_elcn_val are passed to cloned rows.
977   22-Dec-03     Indrasen         115.333   CWBGLOBAL New Procedure
978   10-Jan-04     tjesumic         115.334   new cursor c9 added in check_business_rule to validate
979                                            the cwb task for the budget flag
980   20-Jan-04     ikasire      115.335/338   ben_pep_cache.clear_down_cache called after call to
981                                            ben_enrolment_requirements.update_defaults as it uses
982                                            a different effective date
983   21-Jan-04     ikasire          115.339   Added p_trace_plans_flag to CWBGLOBAL procedure
984 
985   02-Feb-04     pbodla           115.340   GLOBALCWB : Error
986                                            BEN_91769_NOONE_TO_PROCESS is not
987                                            relevant for CWB.
988                                            Cursor C5 modified such that
989                                            worksheet rates are not relevant for
990                                            group plan.
991  16-Feb-04      kmahendr         115.341   Bug#3420298 - dpnt_eligibility calls made in R
992                                            mode
993  17-Feb-04      kmahendr         115.343   Leapfrog version of 115.341
994  18-Feb-04      tjesumic         115.344   cwb edit , cursor c10,c11 created , c5 edited
995  18-Feb-04      tjesumic         115.345   cwb edit
996  23-Feb-04      mmudigon         115.346   GSP: Selective Eligibility evaluation
997                                            Changes in process_comp_objects proc
998  27-Feb-04      pbodla           115.347   GLOBALCWB: procedure update_cwb_epe
999                                            modified not to delete the epe,
1000                                            calls to del_cwb_pil etc are commented.
1001  02-Mar-04      tjesumic         115.348   cwb cursor c6 validation removed
1002  08-Mar-04      abparekh         115.349   Modified Cursor c2 in check_business_rules to check
1003                                            that more than one similar type of CWB Rates (except
1004                                            CWBAHE, CWBGP, CWBRA)  are not attached to the same
1005                                            Plan : Bug 3482033
1006  07-Apr-04      pbodla           115.350   FONM : Added fonm functionality.
1007                 Tilak
1008  12-Apr-2004    nhunur           115.351   Bypass generate_communication for GSP mode.
1009  22-Apr-2004    pbodla           115.352   FONM : clear the caches if previous
1010                                            coverage date is different from current.
1011                                            New GLOBALCWB messages  added.
1012                                            Some Commented code is deleted.
1013  28-May-04      mmudigon         115.353   OSP fixes to process multiple LEs
1014  31-May-04      abparekh         115.354   Bug : 3658807 Set the message name in evaluate_life_events
1015                                            before raising exception g_record_error.
1016  16-Jun-04      mmudigon         115.355   GSP fixes to process multiple LEs
1017  18 Aug 04      tjesumic         115.356   ptip_id  parameter added for csd_rsd determination
1018                                            fonm validated for every comp object
1019  23 Aug 04      mmudigon         115.357   CFW. Call to ben_carry_forward
1020                                            2534391 :NEED TO LEAVE ACTION ITEMS
1021  03-Sep-04      abparekh         115.358   3870204 : Don't error out when criteria does not select
1022                                            any person. Give message in audit log and complete with Normal status.
1023  28-Sep-04      hmani            115.359   IREC - Front Port of 115.343.15102.4
1024  30-Sep-04      abparekh         115.360   IREC - Set G_LER_ID in do_multithread for subsequent use.
1025  15-Oct-04      abparekh         115.361   GSP Rate Sync changes
1026  18-Oct-04      abparekh         115.362   GSP Rate Sync changes
1027  18-Oct-04      abparekh         115.363   Bug 3964719 : GSP : Get employee step only when progression style
1028                                            is not Grade Progression.
1029  03-Nov-04      abparekh         115.364   Bug 3975857 Changed definition and usage of cursor C2 in
1030                                            check_business_rules procedure so that validation works correctly
1031  03-Nov-04      kmahendr         115.365   Bug#3903126 - global variable g_derivable_factor
1032                                            assigned value inside do_multithread procedure
1033  03-Nov-04      pbodla           115.366   GLOBALCWB :Bug#3968065-Added call to
1034                                            sum_oipl_rates_and_upd_pl_rate
1035  15-Nov-04      kmahendr         115.367   Unrest. enh changes
1036  03-Dec-04      ikasire          115.368   BUG 4046914
1037  14-Dec-04      pbodla           115.369   bug 4040013 - when sum_oipl_rates_an...
1038                                            procedure is called, plan id is going as null
1039                                            so l_cwb_pl_id is passed.
1040  06-Jan-05      ikasire          115.370   Bug 4064635 a call to new Procedure got added
1041                                            Look for dependent package changes
1042  31-Jan-05      abparekh         115.371   Bug 4149182 Commented the check to prevent rates at plan level
1043                                            when options attached to the plan.
1044  14-Jan-05      bmanyam          115.372/373 Bug: 4128034. CWB Mode fnd_session needs to be set.
1045  22-feb-05      nhunur           115.374   Bug : 4199099 - Task for group plan need not be 'A'
1046  24-feb-05      tjesumic         115.375   Bug : 4204020 - cache_person_information called after determing LE date
1047  25-Feb-05      abparekh         115.376   Added procedure person_header_new and called it
1048                                            from process_life_events to separate caching from peson header
1049  29-Feb-05      pbodla           115.377   4214845 : To not skip the comp object
1050                                            processing if parent object is ineligible.
1051  08-mar-05      nhunur           115.378   GSI Netherlands issue. Added condition to get GRE info
1052                                            only for US leg code.
1053  10-Mar-05      mmudigon         115.380   Bug 4194337. Added calls to
1054                                            set_parent_elig_flags in proc
1055                                            update_elig_per_rows
1056  24-Mar-05      pbodla           115.381   Bug 4258498 - Moved the carry forward results call
1057                                            after the reinstate call, so that reinstate first
1058                                            attempt to get back the enrollments first.
1059  25-Mar-05      abparekh         115.382   Bug 4245975 : Rollback in exception g_life_event_after
1060                                            only for G, M modes
1061  07-Apr-05      mmudigon         115.383   Bug 4234501. Removed Rollback in
1062                                            exception  g_life_event_after
1063  14-Apr-05      kmahendr         115.384   Bug#4291122 - added newly_ineligible condition
1064                                            to call enrolment_requirement
1065  22-apr-05      nhunur           115.385   All threads should have fnd_sessions populated for FF.
1066  05-May-05      tjesumic         115.386   Fonm Clearing cache for fonm date date is fixed
1067  23-May-05      mmudigon         115.387   Rank and Score Call added
1068  01-jun-05      pbodla           115.388   Bug 4258200 : Budget and reserve rates
1069                                            can be attached to local plans so that the
1070                                            data is copied over in the event of
1071                                            cloning of cwb data.
1072  28-jun-05      nhunur           115.389   for GSP chk elig at PGM level for all prog styles.
1073  26-jul-05      ssarkar          115.390   Bug 4496944 : Handled exception thrown by person_header_new .
1074  03-Aug-05      rbingi           115.391   Bug 4394545: Erroring if cwb_process(BENCOMOD) is submitted through SRS
1075                                                         (Not by other Conc Request)
1076  12-Sep-05      ikasire          115.392   Bug 4463267 added new procedure call update_susp_if_ctfn_flag
1077  22-sep-05      ssarkar          115.393   Bug 4621751 irec2 -- offer assignment
1078  06-Oct-05      rbingi           115.394   Bug 4640014 Added call to ben_manage_unres_life_events.clear_epe_cache
1079  10-nov-05      ssarkar          115.395   IREC2: Called post_irec_process_update.
1080  17-nov-05      nhunur           115.396   bug - 4743143 - gsp changes in check_business_rules, grade_step_process.
1081  03-Jan-06      nhunur           115.397   cwb - changes for person type param.
1082  02-Feb-06      swjain           115.398   CWB Thread Num Enhancement
1083  08-Feb-06      abparekh         115.399   Bug 4875181 - Added p_run_rollup_only to cwb_global_process
1084  28-Feb-06      kmahendr         115.400   Added ben_reopen_ended_result call for
1085                                            GM issue - Fidelity
1086  14-mar-06      nhunur           115.401   bug 5090149 for cwb
1087  16-Mar-06      kmahendr         115.402   Bug#5089721-added codes to update_elig_per
1088                                            proc
1089  23-Mar-06      kmahendr         115.403   Bug#5100083 - added parameters to call
1090                                            ben_reopen_ended_result
1091  04-APR-06      ssarkar          115.404   Bug 5055119 - added end_date_elig_per_rows
1092  22-May-06      pbodla           115.405   Bug 5232223 - Added code to handle the trk inelig flag
1093                                            If trk inelig flag is set to N at group plan level
1094                                            then do not create cwb per in ler and all associated data.
1095  29-jul-06      nhunur           115.406   CAGR fix for person selection
1096  20-Sep-06      abparekh         115.407   Bug 5550359 : Passed p_validate correctly to benptnle
1097                                                          Added p_validate to PROCESS_LIFE_EVENTS
1098                                                          and EVALUATE_LIFE_EVENTS
1099  21-sep-06      nhunur           115.408   bug 5534550 - call reopen only for L or C modes
1100  17-oct-06      stee             115.409   bug 5364920 - pass per_in_ler_id to
1101                                            ben_generate_communication.
1102  30-oct-06      gsehgal          115.410   bug 5618436 - changed in print parameters
1103  16-Nov-06      maagrawa         115.411   5666180. Remove the cwb check (c7)
1104                                            which prevented plan with only one
1105                                            salary component.
1106  22-Jan-07      rtagarra         115.412   ICM Changes.
1107  06-Aug-07      rtagarra         115.415   Bug 6321565 : For 'R' mode corrected the if condition to call benutils.get_ler.
1108  04-Dec-07	krupani		 115.419   Incorporated changes of defer deenrollment, Bug 6519622, Bug 6373951,
1109 					   Bug 6373951 and Bug 6390880 from branchline to mainline
1110  10-Mar-08      krupani          115.421   Bug 6404338.  Min Max enhancement incorporated in R12 mainline
1111  12-Aug-08      pvelugul         120.28.12010000.2 Bug 6872010: Cleared global variables
1112                                            g_fonm_cvg_strt_dt and  g_fonm_rt_strt_dt
1113                                            in clear_init_benmngle_caches
1114  12-Aug-08      pvelugul         120.28.12010000.3 Bug 6806014: While processing open, if the winner life event is
1115                                            a normal life event(mode 'L'), then change the mode on the fly
1116                                            to 'L' from 'C', instead of raising an exception
1117 */
1118 --------------------------------------------------------------------------------
1119 --
1120 g_package             varchar2(80) := 'ben_manage_life_events';
1121 g_max_errors_allowed  number;
1122 --
1123 -- Process information
1124 --
1125 g_proc_rec ben_type.g_batch_proc_rec;
1126 g_action_rec ben_type.g_batch_action_rec;
1127 g_strt_tm_numeric number;
1128 g_end_tm_numeric number;
1129 g_prev_sysdate date := sysdate;
1130 g_opt_exists boolean;
1131 --
1132 -- Bug 2574791
1133 --
1134 g_rebuild_pl_id            number := null;
1135 g_rebuild_lf_evt_ocrd_dt   date := null;
1136 g_rebuild_business_group_id   number := null;
1137 --
1138 g_debug boolean := hr_utility.debug_enabled;
1139 --
1140 
1141 procedure clear_init_benmngle_caches
1142   (p_business_group_id in     number
1143   ,p_effective_date    in     date
1144   ,p_threads           in     number default null
1145   ,p_chunk_size        in     number default null
1146   ,p_max_errors        in     number default null
1147   ,p_benefit_action_id in     number default null
1148   ,p_thread_id         in     number default null
1149   )
1150 
1151 is
1152   --
1153 begin
1154   g_debug := hr_utility.debug_enabled;
1155   --
1156   -- Set up benefits environment
1157   --
1158   ben_env_object.init
1159     (p_business_group_id => p_business_group_id
1160     ,p_effective_date    => p_effective_date
1161     ,p_thread_id         => p_thread_id
1162     ,p_chunk_size        => p_chunk_size
1163     ,p_threads           => p_threads
1164     ,p_max_errors        => p_max_errors
1165     ,p_benefit_action_id => p_benefit_action_id
1166     );
1167   --
1168   -- Reset value of globals
1169   --
1170   g_elig_for_pgm_flag   := null;
1171   g_elig_for_pl_flag    := null;
1172   g_trk_inelig_flag     := null;
1173   g_last_pgm_id         := null;
1174   g_output_string       := null;
1175   --
1176   -- Flush all global structures
1177   --
1178   -- bug 6872010
1179   g_fonm_cvg_strt_dt    := null;
1180   g_fonm_rt_strt_dt     := null;
1181   -- bug 6872010
1182 
1183   flush_global_structures;
1184   benutils.g_benefit_action_id := p_benefit_action_id;
1185   benutils.g_thread_id := p_thread_id;
1186   --
1187   -- Initialise comp object list globals
1188   --
1189   ben_comp_object_list.init_comp_object_list_globals;
1190   --
1191 end clear_init_benmngle_caches;
1192 --
1193 /*  GSP Rate Sync */
1194 procedure get_grade_step_placement
1195   (p_person_id          in number,
1196    p_assignment_id      in number,
1197    p_business_group_id  in number,
1198    p_effective_date     in date,
1199    p_gsp_pgm_id         out nocopy number,
1200    p_gsp_plip_id        out nocopy number,
1201    p_gsp_oipl_id        out nocopy number,
1202    p_prgr_style         out nocopy varchar2,
1203    p_gsp_emp_step_id    out nocopy number,
1204    p_gsp_num_incr       out nocopy number) is
1205 --
1206 l_proc          varchar2(80);
1207 l_exc_grade     EXCEPTION;
1208 l_exc_step      EXCEPTION;
1209 --
1210 begin
1211   --
1212   l_proc := g_package || '.get_grade_step_placement';
1213   --
1214   hr_utility.set_location('Entering : ' || l_proc, 10);
1215   --
1216   -- Get Grade Ladder (PGM_ID) and Grade (PLIP_ID) placement
1217   pqh_gsp_post_process.get_persons_gl_and_grade
1218   (p_person_id            => p_person_id,
1219    p_business_group_id    => p_business_group_id,
1220    p_effective_date       => p_effective_date,
1221    p_persons_pgm_id       => p_gsp_pgm_id,
1222    p_persons_plip_id      => p_gsp_plip_id,
1223    p_prog_style           => p_prgr_style);
1224 
1225   if p_prgr_style not in ('PQH_GSP_GP')
1226   then
1227     --
1228     -- Get Step placement
1229     pqh_gsp_default.get_emp_step_placement
1230     (p_assignment_id        => p_assignment_id,
1231      p_effective_date       => p_effective_date,
1232      p_emp_step_id          => p_gsp_emp_step_id,
1233      p_num_incr             => p_gsp_num_incr);
1234 
1235     -- Get the OIPL_ID (Step)
1236     p_gsp_oipl_id := pqh_gsp_hr_to_stage.get_oipl_for_step
1237                              (p_step_id        => p_gsp_emp_step_id,
1238                               p_effective_date => p_effective_date);
1239     --
1240   end if;
1241   --
1242   hr_utility.set_location('Leaving : ' || l_proc, 20);
1243   --
1244 exception
1245   --
1246   when others
1247   then
1248     --
1249     if p_gsp_plip_id is null or p_gsp_pgm_id is null
1250     then
1251       --
1252       fnd_message.set_name('BEN','BEN_94094_PERSON_GRADE_NOT_FND');
1253       --
1254     elsif p_gsp_emp_step_id is null or p_gsp_oipl_id is null
1255     then
1256       --
1257       fnd_message.set_name('BEN','BEN_94095_PERSON_STEP_NOT_FND');
1258       --
1259     end if;
1260     --
1261     raise g_record_error;
1262     --
1263 end get_grade_step_placement;
1264 --
1265 procedure check_business_rules
1266     (p_business_group_id        in number,
1267      p_derivable_factors        in varchar2,
1268      p_validate                 in varchar2,
1269      p_no_programs              in varchar2,
1270      p_no_plans                 in varchar2,
1271      p_mode                     in varchar2,
1272      p_effective_date           in date,
1273      p_person_id                in number,
1274      p_person_selection_rule_id in number,
1275      p_person_type_id           in number,
1276      p_pgm_id                   in number,
1277      p_pl_id                    in number,
1278      p_ler_id                   in number,
1279      p_pl_typ_id                in number,
1280      p_opt_id                   in number,
1281      p_lf_evt_ocrd_dt           in date,
1282      p_org_heirarchy_id         in number   default null,
1283      p_org_starting_node_id     in number   default null,
1284      p_asg_events_to_all_sel_dt in date   default null,
1285      p_per_sel_dt_cd            in varchar2   default null,
1286      p_per_sel_dt_from          in date default null,
1287      p_per_sel_dt_to            in date default null,
1288      p_year_from                in number default null,
1289      p_year_to                  in number default null,
1290      p_qual_type                in number default null,
1291      p_qual_status              in varchar2 default null,
1292      p_lf_evt_oper_cd           in varchar2 default null
1293   ) is
1294      -- PB : 5422 :
1295      -- p_popl_enrt_typ_cycl_id    in number) is
1296   --
1297   l_package               varchar2(80) := g_package||'.check_business_rules';
1298   l_dummy                 varchar2(1);
1299   l_rec                   benutils.g_active_life_event;
1300   l_ler_rec               benutils.g_ler;
1301   l_effective_start_date  date;
1302   l_effective_end_date    date;
1303   l_ptnl_ler_for_per_id   number;
1304   l_object_version_number number;
1305   l_per_in_ler_id         number;
1306   l_opt_count             number;
1307   l_cwbdb_count           number;
1308   l_cwbwb_count           number;
1309   l_cwbr_count            number;
1310 
1311   --
1312   cursor c1 is
1313     select null
1314     from   per_person_type_usages_f ppu
1315     where  ppu.person_id = p_person_id
1316     and    ppu.person_type_id = p_person_type_id
1317     and    p_effective_date
1318            between ppu.effective_start_date
1319            and     ppu.effective_end_date;
1320   --
1321   -- CWB Change Bug 2275257
1322   --
1323   --Bug : 3482033
1324   cursor c2 is
1325     select null
1326     from ben_acty_base_rt_f abr
1327     where abr.pl_id = p_pl_id
1328     and abr.acty_typ_cd like 'CWB%'
1329     and abr.acty_typ_cd not in ('CWBAHE')    -- Bug 3975857 - Removed codes CWBRA,CWBGP
1330     and abr.acty_base_rt_stat_cd = 'A'
1331     and abr.business_group_id = p_business_group_id
1332     and nvl(p_lf_evt_ocrd_dt,p_effective_date)
1333         between abr.effective_start_date
1334         and     abr.effective_end_date
1335     group by abr.acty_typ_cd
1336     having count(*) > 1;
1337   --Bug : 3482033
1338   --
1339   cursor c3 is
1340   select enp.uses_bdgt_flag,
1341          enp.prsvr_bdgt_cd,
1342          DECODE(pln.pl_id,pln.group_pl_id,'Y','N') Group_plan
1343     from ben_enrt_perd enp,
1344          ben_popl_enrt_typ_cycl_f pet,
1345          ben_pl_f  pln
1346    where pet.pl_id = p_pl_id
1347      and pet.business_group_id = p_business_group_id
1348      and enp.popl_enrt_typ_cycl_id = pet.popl_enrt_typ_cycl_id
1349      and enp.asnd_lf_evt_dt  = p_lf_evt_ocrd_dt
1350      and pln.pl_id   = p_pl_id
1351      and nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1352          pet.effective_start_date and pet.effective_end_date
1353      and nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1354          pln.effective_start_date and pln.effective_end_date
1355      ;
1356   c3_rec c3%rowtype;
1357 
1358   cursor c4 is
1359   select count(decode(abr.acty_typ_cd,'CWBDB',1,0)),
1360          count(decode(abr.acty_typ_cd,'CWBWB',1,0)),
1361          count(decode(abr.acty_typ_cd,'CWBR',1,0))
1362     from ben_acty_base_rt_f abr
1363    where abr.acty_typ_cd in ('CWBDB','CWBWB','CWBR')
1364      and abr.acty_base_rt_stat_cd = 'A'
1365      and abr.business_group_id = p_business_group_id
1366      and nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1367          abr.effective_start_date and abr.effective_end_date
1368      and (abr.pl_id = p_pl_id or
1369           abr.oipl_id in
1370               (select oipl.oipl_id
1371                  from ben_oipl_f oipl
1372                 where oipl.pl_id = p_pl_id
1373                   and oipl.business_group_id = p_business_group_id
1374                   and nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1375                       oipl.effective_start_date and oipl.effective_end_date
1376               )
1377          );
1378 
1379   --if plan or option has CWBDB and it should have CWBWB
1380   cursor c5 is
1381   select 'x'
1382     from ben_acty_base_rt_f abr1
1383    where
1384     ( abr1.acty_typ_cd in ('CWBDB')
1385       and abr1.acty_base_rt_stat_cd = 'A'
1386       and abr1.business_group_id = p_business_group_id
1387       and nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1388          abr1.effective_start_date and abr1.effective_end_date
1389       and (abr1.pl_id = p_pl_id or
1390           abr1.oipl_id in
1391               (select oipl.oipl_id
1392                  from ben_oipl_f oipl
1393                 where oipl.pl_id = p_pl_id
1394                   and oipl.business_group_id = p_business_group_id
1395                   and nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1396                       oipl.effective_start_date and oipl.effective_end_date
1397               )
1398          )
1399       and not exists
1400          (select 'x'
1401             from ben_acty_base_rt_f abr2
1402            where abr2.acty_typ_cd = 'CWBWB'
1403              and abr2.acty_base_rt_stat_cd = 'A'
1404              and abr2.business_group_id = p_business_group_id
1405              and nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1406                  abr2.effective_start_date and abr2.effective_end_date
1407              and nvl(abr2.pl_id,-1) = nvl(abr1.pl_id,-1)
1408              and nvl(abr2.oipl_id,-1) = nvl(abr1.oipl_id,-1)
1409          )
1410       ) OR
1411      --if plan or option has CWBWB and it should have CWBDB
1412      ( abr1.acty_typ_cd in ('CWBWB')
1413       and abr1.acty_base_rt_stat_cd = 'A'
1414       and abr1.business_group_id = p_business_group_id
1415       and nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1416          abr1.effective_start_date and abr1.effective_end_date
1417       and (abr1.pl_id = p_pl_id or
1418           abr1.oipl_id in
1419               (select oipl.oipl_id
1420                  from ben_oipl_f oipl
1421                 where oipl.pl_id = p_pl_id
1422                   and oipl.business_group_id = p_business_group_id
1423                   and nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1424                       oipl.effective_start_date and oipl.effective_end_date
1425               )
1426          )
1427       and not exists
1428          (select 'x'
1429             from ben_acty_base_rt_f abr2
1430            where abr2.acty_typ_cd = 'CWBDB'
1431              and abr2.acty_base_rt_stat_cd = 'A'
1432              and abr2.business_group_id = p_business_group_id
1433              and nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1434                  abr2.effective_start_date and abr2.effective_end_date
1435              and nvl(abr2.pl_id,-1) = nvl(abr1.pl_id,-1)
1436              and nvl(abr2.oipl_id,-1) = nvl(abr1.oipl_id,-1)
1437          )
1438       )  ;
1439 
1440 
1441   cursor c6 is
1442   select 'x'
1443     from ben_acty_base_rt_f abr1
1444    where abr1.acty_typ_cd in ('CWBDB')
1445      and abr1.acty_base_rt_stat_cd = 'A'
1446      and abr1.business_group_id = p_business_group_id
1447      and nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1448          abr1.effective_start_date and abr1.effective_end_date
1449      and (abr1.pl_id = p_pl_id or
1450           abr1.oipl_id in
1451               (select oipl.oipl_id
1452                  from ben_oipl_f oipl
1453                 where oipl.pl_id = p_pl_id
1454                   and oipl.business_group_id = p_business_group_id
1455                   and nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1456                       oipl.effective_start_date and oipl.effective_end_date
1457               )
1458          )
1459      and not exists
1460          (select 'x'
1461             from ben_acty_base_rt_f abr2
1462            where abr2.acty_typ_cd in ('CWBES')
1463              and abr2.acty_base_rt_stat_cd = 'A'
1464              and abr2.business_group_id = p_business_group_id
1465              and nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1466                  abr2.effective_start_date and abr2.effective_end_date
1467              and nvl(abr2.pl_id,-1) = nvl(abr1.pl_id,-1)
1468              and nvl(abr2.oipl_id,-1) = nvl(abr1.oipl_id,-1)
1469          );
1470 
1471   cursor c7 is
1472   select count(opt.opt_id)
1473     from ben_opt_f opt
1474    where opt.component_reason is not null
1475      and nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1476          opt.effective_start_date and opt.effective_end_date
1477      and opt.opt_id in
1478          (select oipl.opt_id
1479             from ben_oipl_f oipl
1480            where oipl.pl_id = p_pl_id
1481              and oipl.business_group_id = p_business_group_id
1482              and nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1483                  oipl.effective_start_date and oipl.effective_end_date);
1484 
1485  --
1486  -- Cursor c8 added for Bug 2840078
1487  --
1488  cursor c8 is
1489  select 'x' found
1490    from ben_cvg_amt_calc_mthd_f ccm,
1491         ben_pl_typ_f pt,
1492         ben_pl_f pl
1493   where pl.pl_id  =  p_pl_id
1494     and pt.pl_typ_id =  pl.pl_typ_id
1495     and pt.opt_typ_cd = 'CWB'
1496     and (ccm.pl_id = pl.pl_id or
1497            ccm.oipl_id in
1498               (select oipl.oipl_id
1499                  from ben_oipl_f oipl
1500                 where oipl.pl_id = pl.pl_id
1501                   and oipl.business_group_id = p_business_group_id
1502                   and nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1503                       oipl.effective_start_date and oipl.effective_end_date
1504               )
1505         )
1506     and ccm.business_group_id = p_business_group_id
1507     and nvl(p_lf_evt_ocrd_dt,p_effective_date) between ccm.effective_start_date and ccm.effective_end_date
1508     and pl.business_group_id = p_business_group_id
1509     and nvl(p_lf_evt_ocrd_dt,p_effective_date) between pl.effective_start_date and pl.effective_end_date
1510     and pt.business_group_id = p_business_group_id
1511     and nvl(p_lf_evt_ocrd_dt,p_effective_date) between pt.effective_start_date and pt.effective_end_date;
1512 
1513 
1514    cursor c9 is
1515    select 'x'
1516      from  ben_cwb_wksht_grp cwg
1517     where  cwg.pl_id = p_pl_id ;
1518       -- and  cwg.status_cd = 'A'  ; bug 4199099
1519 
1520    -- to find wheether there is any option
1521   cursor c10 is
1522     select 'x' found
1523     from   ben_oipl_f oipl
1524     where  oipl.pl_id = p_pl_id
1525       and  oipl.business_group_id = p_business_group_id
1526       and  nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1527            oipl.effective_start_date and oipl.effective_end_date ;
1528 
1529 
1530   -- rate is attached to plan
1531   cursor c11 is
1532   select  'x' found
1533     from ben_acty_base_rt_f abr
1534    where abr.acty_typ_cd in ('CWBDB','CWBWB','CWBR')
1535      and abr.acty_base_rt_stat_cd = 'A'
1536      and abr.business_group_id = p_business_group_id
1537      and nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1538          abr.effective_start_date and abr.effective_end_date
1539      and abr.pl_id = p_pl_id
1540          ;
1541  -- iRec
1542  cursor c_irec_rptg_grp is
1543  select null
1544    from ben_rptg_grp bnr
1545   where bnr.business_group_id = p_business_group_id
1546     and bnr.rptg_prps_cd = 'IREC';
1547  --
1548 
1549  -- GSP Rate Sync
1550  cursor c_gsp_rate_sync_ler is
1551  select null
1552    from ben_ler_f ler
1553   where ler.typ_cd = 'GSP'
1554     and ler.lf_evt_oper_cd = 'SYNC'
1555     and ler.business_group_id = p_business_group_id
1556     and p_effective_date between ler.effective_start_date
1557                              and ler.effective_end_date;
1558  --
1559 begin
1560   --
1561   if g_debug then
1562     hr_utility.set_location ('Entering '||l_package,10);
1563   end if;
1564   --
1565   -- This procedure checks validity of parameters that have been passed to the
1566   -- BENMNGLE process.
1567   --
1568   -- Check if mandatory arguments have been stipulated
1569   --
1570   hr_api.mandatory_arg_error(p_api_name       => l_package,
1571                              p_argument       => 'p_business_group_id',
1572                              p_argument_value => p_business_group_id);
1573   --
1574   hr_api.mandatory_arg_error(p_api_name       => l_package,
1575                              p_argument       => 'p_mode',
1576                              p_argument_value => p_mode);
1577   --
1578   hr_api.mandatory_arg_error(p_api_name       => l_package,
1579                              p_argument       => 'p_effective_date',
1580                              p_argument_value => p_effective_date);
1581   --
1582   --
1583   hr_api.mandatory_arg_error(p_api_name       => l_package,
1584                              p_argument       => 'p_no_programs',
1585                              p_argument_value => p_no_programs);
1586   --
1587   hr_api.mandatory_arg_error(p_api_name       => l_package,
1588                              p_argument       => 'p_no_plans',
1589                              p_argument_value => p_no_plans);
1590   --
1591   hr_api.mandatory_arg_error(p_api_name       => l_package,
1592                              p_argument       => 'p_validate',
1593                              p_argument_value => p_validate);
1594   --
1595   -- Business Rule Checks
1596   --
1597   -- p_no_plans and p_no_programs can not be both 'Y'
1598   --
1599   if p_no_plans = 'Y' and
1600      p_no_programs = 'Y' then
1601     --
1602     fnd_message.set_name('BEN','BEN_91391_NO_PLAN_PROG');
1603     fnd_message.raise_error;
1604     --
1605   end if;
1606   --
1607   -- p_person_selection_rule_id and p_person_id are mutually exclusive
1608   --
1609   if p_person_id is not null and
1610      p_person_selection_rule_id is not null then
1611     --
1612     fnd_message.set_name('BEN','BEN_91745_RULE_AND_PERSON');
1613     fnd_message.raise_error;
1614     --
1615   end if;
1616   --
1617   -- p_no_plans = 'Y' then p_pl_id and p_opt_id must be null
1618   --
1619   if p_no_plans = 'Y' and
1620     (p_pl_id is not null or
1621      p_opt_id is not null) then
1622     --
1623     fnd_message.set_name('BEN','BEN_91746_PROGRAMS_ONLY');
1624     fnd_message.raise_error;
1625     --
1626   end if;
1627   --
1628   -- p_no_programs = 'Y' then p_pgm_id must be null
1629   --
1630   if p_no_programs = 'Y' and
1631      p_pgm_id is not null then
1632     --
1633     fnd_message.set_name('BEN','BEN_91747_PLANS_ONLY');
1634     fnd_message.raise_error;
1635     --
1636   end if;
1637   --
1638   -- p_person_id must be of p_person_type_id
1639   --
1640   if p_person_id is not null and
1641      p_person_type_id is not null then
1642     --
1643     -- Make sure person is of type person type
1644     --
1645     open c1;
1646       --
1647       fetch c1 into l_dummy;
1648       if c1%notfound then
1649         --
1650         close c1;
1651         fnd_message.set_name('BEN','BEN_91748_PERSON_TYPE');
1652         fnd_message.raise_error;
1653         --
1654       end if;
1655       --
1656     close c1;
1657     if g_debug then
1658       hr_utility.set_location ('close c1: '||l_package,50);
1659     end if;
1660     --
1661   end if;
1662   --
1663   -- p_pl_typ_id not null then no_plans, plan and option name must be blank
1664   --
1665   if p_pl_typ_id is not null and
1666     (p_no_plans = 'Y' or
1667      p_opt_id is not null or
1668      p_pl_id is not null) then
1669     --
1670     fnd_message.set_name('BEN','BEN_91749_PLAN_TYPE');
1671     fnd_message.raise_error;
1672     --
1673   end if;
1674   --
1675   -- p_mode = 'C' and p_popl_enrt_typ_cycl_id is null
1676   --
1677   -- CWB Changes
1678   --
1679   if p_mode in  ('C', 'W') and
1680     -- PB : 5422 :
1681     -- Now check for p_lf_evt_ocrd_dt
1682     --
1683     --  p_popl_enrt_typ_cycl_id is null then
1684     p_lf_evt_ocrd_dt is null then
1685      --
1686     fnd_message.set_name('BEN','BEN_91667_SCHED_NO_POPL_ENRT');
1687     fnd_message.raise_error;
1688     --
1689   end if;
1690   --
1691   -- CWB Changes
1692   --
1693   if p_mode = 'W' and p_pl_id is null then
1694      --
1695      fnd_message.set_name('BEN','BEN_91667_SCHED_NO_POPL_ENRT');
1696      fnd_message.raise_error;
1697      --
1698   end if;
1699 
1700   --
1701   -- CWB Changes Bug 2270672
1702   -- Effective date must be greater than or equal to Life Event Occurred Date
1703   --
1704   if p_mode = 'W' and p_effective_date < p_lf_evt_ocrd_dt then
1705     --
1706     fnd_message.set_name('BEN','BEN_93017_INVALID_EFF_DATE');
1707     fnd_message.raise_error;
1708     --
1709   end if;
1710 
1711   --
1712   -- CWB Changes Bug 2275257
1713   -- There must be exactly one rate defined for a Plan with the Activity Type
1714   -- of 'CWBWS'
1715   --
1716   if p_mode = 'W' then
1717 
1718     --Bug : 3482033
1719     --For a plan or option, you cannot have more than one of each of the following rates:  CWB
1720     --Worksheet Budget, CWB Distribution Budget, CWB Reserve, CWB Worksheet Amount, CWB Eligible
1721     --Salary, CWB Stated Salary, CWB Other Salary, CWB Total Compensation, CWB Misc Rate 1, CWB
1722     --Misc Rate 2, CWB Misc Rate 3.
1723     open c2;
1724     --
1725     fetch c2 into l_dummy;
1726     if c2%found then    -- Bug 3975857 Changed "notfound" to "found"
1727       --
1728       close c2;
1729       fnd_message.set_name('BEN','BEN_93015_CWB_NO_WS_RATE');
1730       fnd_message.raise_error;
1731       --
1732     end if;
1733     --
1734     close c2;
1735     --Bug : 3482033
1736 
1737     -- if plan or option rate  has CWBDB and it should have CWBWB
1738     -- if plan or option rqte  has CWBWB and it should have CWBDB
1739     open c5;
1740     fetch c5 into l_dummy;
1741     if c5%found then
1742       --
1743       close c5;
1744       fnd_message.set_name('BEN','BEN_93968_CWB_BDGT_RT_AMT_CB');
1745       fnd_message.raise_error;
1746       --
1747     end if;
1748     close c5;
1749     --
1750 
1751 
1752     open c3;
1753     fetch c3 into c3_rec;
1754     close c3;
1755 
1756     open c4;
1757     fetch c4 into l_cwbdb_count,l_cwbwb_count,l_cwbr_count;
1758     close c4;
1759 
1760     -- the assumption is if the plan is group then option is group so plan alone is checked
1761     -- whether it is group or not. verified with manish
1762 
1763     if c3_rec.group_plan = 'Y' then
1764 
1765        /* Bug 4149182 : Commented the following Check
1766        *
1767        * -- if the groip plan has option then the rate should be attached to option
1768        * open c10 ;
1769        * fetch c10 into  l_dummy ;
1770        * if c10%found then
1771        *     open c11 ;
1772        *     fetch c11 into  l_dummy ;
1773        *     if c11%found then
1774        *        close c11 ;
1775        *        close c10 ;
1776        *        fnd_message.set_name('BEN','BEN_93742_CWB_RATE_TO_CHILD');
1777        *        fnd_message.raise_error;
1778        *     end if ;
1779        *     close c11 ;
1780        * end if ;
1781        * close c10 ;
1782        */
1783 
1784 
1785        -- if the budget flag is 'y'  there should be a rate
1786        if c3_rec.uses_bdgt_flag = 'Y' then
1787           if l_cwbdb_count < 1 or
1788              l_cwbwb_count < 1 then
1789             --
1790             fnd_message.set_name('BEN','BEN_93967_CWB_BDGT_RT_PLAN_CB');
1791             fnd_message.raise_error;
1792             --
1793           end if;
1794        end if ;
1795  /*    -- bug 5090149
1796        -- if the budget flag is 'y' there should be  budget task
1797        open c9 ;
1798        fetch c9 into  l_dummy ;
1799        if c9%notfound then
1800           close c9 ;
1801           fnd_message.set_name('BEN','BEN_93740_CWB_BDGT_TASK_NOT');
1802           fnd_message.raise_error;
1803        end if ;
1804        close c9 ;
1805  */
1806 
1807     /*
1808       Bug 4258200 : Budget and reserve rates can be attached to local plans
1809       so that the data is copied over in the event of cloning of cwb data.
1810 
1811     else
1812        -- if the  plan is not group and date DB/WB/reserve attached then error
1813        if l_cwbdb_count > 0 or
1814           l_cwbwb_count > 0 or
1815           l_cwbr_count  > 0  then
1816           fnd_message.set_name('BEN','BEN_93743_CWB_RATE_TO_GROUP');
1817           fnd_message.raise_error;
1818        end if ;
1819     */
1820     end if ;
1821     --
1822 
1823     /* elibile salary are attached to actual plan and DB are attached to group pls
1824       this condition is no more valid
1825     if c3_rec.prsvr_bdgt_cd = 'P' then
1826        open c6;
1827        fetch c6 into l_dummy;
1828        if c6%found then
1829          --
1830          close c6;
1831          fnd_message.set_name('BEN','BEN_93319_CWB_BDGT_RT_SAL');
1832          fnd_message.raise_error;
1833          --
1834        end if;
1835        --
1836        close c6;
1837     end if;
1838     */
1839 
1840     /* Bug 5666180
1841     Allow customers to setup salary plan with only one salary component.
1842     In this case, customers uses salary components but the other
1843     components come from some other place or is entered by admin
1844 
1845     Removing the below check.
1846 
1847     open c7;
1848     fetch c7 into l_opt_count;
1849     close c7;
1850 
1851     if l_opt_count = 1 then
1852        fnd_message.set_name('BEN','BEN_93320_CWB_OPT_COMP_RSN');
1853        fnd_message.raise_error;
1854     end if;
1855     */
1856 
1857     --
1858     -- Bug 2840078 check that cwb plans/options do not have coverages,
1859     -- raise error if coverages are attached.
1860     --
1861     open c8;
1862     fetch c8 into l_dummy;
1863     if c8%found then
1864       --
1865       close c8;
1866       fnd_message.set_name('BEN','BEN_93356_CWB_NO_CVG');
1867       fnd_message.raise_error;
1868       --
1869     end if;
1870     --
1871     close c8;
1872 
1873     -- End of fix Bug 2840078
1874 
1875   end if;
1876 
1877   --
1878   -- iRec : For p_mode = I : iRecruitment, check that atleast one Reporting Group
1879   -- with purpose "iRecruitment" exists in the Business Group.
1880   --
1881   if p_mode = 'I' then
1882     --
1883     open c_irec_rptg_grp;
1884       --
1885       fetch c_irec_rptg_grp into l_dummy;
1886       if c_irec_rptg_grp%notfound then
1887         --
1888         close c_irec_rptg_grp;
1889         fnd_message.set_name('BEN','BEN_94026_NO_RPTG_GRP_DFND');
1890         fnd_message.raise_error;
1891         --
1892       end if;
1893       --
1894     close c_irec_rptg_grp;
1895     --
1896   end if;
1897   -- iRec
1898 
1899   -- GSP Rate Sync
1900   -- If for GSP, the operation code = Rate Synchronization, then check that one Life event
1901   -- of type GSP with operation code = SYNC exists in the Business Group
1902   if p_mode = 'G' and p_lf_evt_oper_cd = 'SYNC'
1903   then
1904     --
1905     open c_gsp_rate_sync_ler;
1906      --
1907      fetch c_gsp_rate_sync_ler into l_dummy;
1908      if c_gsp_rate_sync_ler%notfound
1909      then
1910        --
1911        close c_gsp_rate_sync_ler;
1912        fnd_message.set_name('BEN','BEN_94090_NO_GSP_RS_LER_DFND');
1913        fnd_message.raise_error;
1914        --
1915      end if;
1916      --
1917    close c_gsp_rate_sync_ler;
1918    --
1919   end if;
1920   -- GSP Rate Sync
1921   --
1922 
1923   -- p_mode = 'U' make sure any open life event is an unrestricted one -modified
1924   -- any open unrestricted life event on the same day will be checked at the client side
1925   --
1926   --
1927   -- p_mode not in L,S,C,U
1928   --
1929   if g_debug then
1930     hr_utility.set_location ('BEN_BENMNGLE_MD '||l_package,50);
1931   end if;
1932   --
1933   if hr_api.not_exists_in_hr_lookups
1934      (p_lookup_type    => 'BEN_BENMNGLE_MD',
1935       p_lookup_code    => p_mode,
1936       p_effective_date => p_effective_date) then
1937     --
1938     fnd_message.set_name('BEN','BEN_91326_MODE_INVALID');
1939     fnd_message.raise_error;
1940     --
1941   end if;
1942   --
1943   -- 2940151 grade/step
1944   -- 1. If business rule param is null and business rule strt or end dts
1945   -- are not null, raise error
1946   if p_per_sel_dt_cd is null and
1947     ( p_per_sel_dt_from is not null or
1948       p_per_sel_dt_to is not null) then
1949 
1950         fnd_message.set_name('PER','HR_289506_SPP_BR_NULL');
1951         fnd_message.raise_error;
1952   end if;
1953 
1954   -- 2. If business rule param is not null and business rule strt or end dts
1955   -- are null, raise error
1956   if p_per_sel_dt_cd is not null and
1957       ( p_per_sel_dt_from is null or
1958         p_per_sel_dt_to is null) then
1959 
1960           fnd_message.set_name('PER','HR_289510_SPP_BR_DATE_NULL');
1961           fnd_message.raise_error;
1962   end if;
1963   --
1964   -- 3. If business rule param is neither of the four values, raise error
1965 
1966   if p_per_sel_dt_cd  not in  ('AOJ', 'DOB', 'ASD', 'LHD') then
1967     fnd_message.set_name('PER','HR_289507_SPP_BR_INVALID');
1968     fnd_message.raise_error;
1969   end if;
1970   --
1971   -- 4. If date from is greater than date to, raise error
1972 
1973   if p_per_sel_dt_from > p_per_sel_dt_to then
1974     fnd_message.set_name('PER','HR_289500_SPP_BR_DATE');
1975     fnd_message.raise_error;
1976   end if;
1977   --
1978   -- 5. If the dates are more than 12 months apart, raise error
1979 
1980   if ( months_between( p_per_sel_dt_to, p_per_sel_dt_from) > 12 ) then
1981     fnd_message.set_name('PER','HR_289501_SPP_BR_YEAR_GREATER');
1982     fnd_message.raise_error;
1983   end if;
1984   --
1985   -- 6. If effective date does not fall between the from and to dates, raise error
1986 
1987   if not ( p_effective_date between  p_per_sel_dt_from and p_per_sel_dt_to ) then
1988     fnd_message.set_name('PER','HR_289503_SPP_EFF_BR_DATE');
1989     fnd_message.raise_error;
1990   end if;
1991   --
1992   -- 7. If year from is greater than year to, raise error
1993 
1994   if p_year_from > p_year_to then
1995     fnd_message.set_name('PER','HR_289504_SPP_BR_YEAR_FROM_TO');
1996     fnd_message.raise_error;
1997   end if;
1998   --
1999   -- end 2940151
2000 
2001   --
2002   if g_debug then
2003     hr_utility.set_location ('Leaving '||l_package,10);
2004   end if;
2005   --
2006 end check_business_rules;
2007 --
2008 procedure update_elig_per_rows
2009 (p_comp_obj_tree_row  in ben_manage_life_events.g_cache_proc_objects_rec
2010 ,p_comp_rec           in ben_derive_part_and_rate_facts.g_cache_structure
2011 ,p_person_id          in number
2012 ,p_par_elig_state     in out nocopy ben_comp_obj_filter.g_par_elig_state_rec
2013 ,p_treeele_num        in number
2014 ,p_business_group_id  in number
2015 ,p_effective_date     in date
2016 ,p_lf_evt_ocrd_dt     in date
2017 ,p_per_in_ler_id      in number
2018 ,p_continue_loop      out nocopy boolean) is
2019 --
2020   l_envpgm_id   number := p_comp_obj_tree_row.par_pgm_id;
2021   l_envptip_id  number := p_comp_obj_tree_row.par_ptip_id;
2022   l_envplip_id  number := p_comp_obj_tree_row.par_plip_id;
2023   l_envpl_id    number := p_comp_obj_tree_row.par_pl_id;
2024   l_oipl_id     number := p_comp_obj_tree_row.oipl_id;
2025   l_pl_id       number := p_comp_obj_tree_row.pl_id;
2026   l_oiplip_id   number := p_comp_obj_tree_row.oiplip_id;
2027   l_plip_id     number := p_comp_obj_tree_row.plip_id;
2028   l_ptip_id     number := p_comp_obj_tree_row.ptip_id;
2029 
2030   l_elig_per_id               ben_elig_per_f.elig_per_id%TYPE;
2031   l_object_version_number     ben_elig_per_f.object_version_number%TYPE;
2032   l_object_version_number_opt ben_elig_per_opt_f.object_version_number%type;
2033   l_effective_start_date      date;
2034   l_effective_end_date        date;
2035   l_datetrack_mode            varchar2(100);
2036   l_elig_per_opt_id           ben_elig_per_opt_f.elig_per_opt_id%type;
2037   l_elig_per_oiplip_id        ben_elig_per_opt_f.elig_per_opt_id%type;
2038   l_effective_start_date_opt  date;
2039   l_effective_end_date_opt    date;
2040   l_correction                boolean;
2041   l_update                    boolean;
2042   l_update_override           boolean;
2043   l_update_change_insert      boolean;
2044 
2045   --
2046   CURSOR c_prev_elig_check
2047     (c_person_id      in number
2048     ,c_pgm_id         in number
2049     ,c_pl_id          in number
2050     ,c_ptip_id        in number
2051     ,c_effective_date in date
2052     )
2053   IS
2054     select pep.elig_per_id,
2055            pep.elig_flag,
2056            pep.prtn_strt_dt,
2057            pep.prtn_end_dt,
2058            pep.per_in_ler_id,
2059            pep.object_version_number
2060     from   ben_elig_per_f pep,
2061            ben_per_in_ler pil
2062     where  pep.person_id = c_person_id
2063     and    nvl(pep.pgm_id,-1)  = c_pgm_id
2064     and    nvl(pep.pl_id,-1)   = c_pl_id
2065     and    pep.plip_id is null
2066     and    nvl(pep.ptip_id,-1) = c_ptip_id
2067     and    c_effective_date
2068            between pep.effective_start_date
2069            and pep.effective_end_date
2070     and    pil.per_in_ler_id(+)=pep.per_in_ler_id
2071     and    pil.business_group_id(+)=pep.business_group_id
2072     and    (   pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT') -- found row condition
2073             or pil.per_in_ler_stat_cd is null                  -- outer join condition
2074            )
2075   ;
2076   --
2077   cursor c_prev_opt_elig_check
2078     (c_person_id      in number
2079     ,c_effective_date in date
2080     ,c_pl_id          in number
2081     ,c_opt_id         in number
2082     )
2083   is
2084     select epo.elig_per_opt_id,
2085            epo.elig_flag,
2086            epo.prtn_strt_dt,
2087            epo.prtn_end_dt,
2088            epo.object_version_number,
2089            pep.elig_per_id,
2090            epo.per_in_ler_id,
2091            pep.prtn_strt_dt strt_dt,
2092            pep.prtn_end_dt end_dt
2093     from   ben_elig_per_opt_f epo,
2094            ben_per_in_ler pil,
2095            ben_elig_per_f pep
2096     where  pep.person_id   = c_person_id
2097     and    pep.pl_id = c_pl_id
2098     and    epo.opt_id = c_opt_id
2099     and    pep.elig_per_id = epo.elig_per_id
2100     and    pep.pgm_id is null
2101     and    c_effective_date
2102            between pep.effective_start_date
2103            and pep.effective_end_date
2104     and    c_effective_date
2105            between epo.effective_start_date
2106            and epo.effective_end_date
2107     and    pil.per_in_ler_id(+)=epo.per_in_ler_id
2108     and    pil.business_group_id(+)=epo.business_group_id
2109     and    (   pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT')
2110             or pil.per_in_ler_stat_cd is null);
2111    --
2112    cursor c_epe (p_pgm_id number) is
2113      select null
2114      from ben_elig_per_f
2115      where person_id = p_person_id
2116      and   p_effective_date between effective_start_date and
2117            effective_end_date
2118      and   per_in_ler_id is null
2119      and   pgm_id = p_pgm_id;
2120   --
2121   cursor c_epe2 (p_pl_id number) is
2122      select null
2123      from ben_elig_per_f
2124      where person_id = p_person_id
2125      and   p_effective_date between effective_start_date and
2126            effective_end_date
2127      and   per_in_ler_id is null
2128      and   pgm_id is null
2129      and   pl_id = p_pl_id;
2130   --
2131   cursor c_epo (p_pgm_id number) is
2132     select null
2133     from ben_elig_per_opt_f epo
2134     where epo.per_in_ler_id is null
2135     and   p_effective_date between epo.effective_start_date
2136           and epo.effective_end_date
2137     and   epo.elig_per_id in
2138          (select elig_per_id
2139           from ben_elig_per_f
2140           where person_id = p_person_id
2141           and   p_effective_date between effective_start_date and
2142                 effective_end_date
2143           and   per_in_ler_id = p_per_in_ler_id
2144           and   pgm_id = p_pgm_id);
2145   --
2146   cursor c_epo2 (p_pl_id number) is
2147     select null
2148     from ben_elig_per_opt_f epo
2149     where epo.per_in_ler_id is null
2150     and   p_effective_date between epo.effective_start_date
2151           and epo.effective_end_date
2152     and   epo.elig_per_id in
2153          (select elig_per_id
2154           from ben_elig_per_f
2155           where person_id = p_person_id
2156           and   p_effective_date between effective_start_date and
2157                 effective_end_date
2158           and   per_in_ler_id = p_per_in_ler_id
2159           and   pgm_id is null
2160           and   pl_id = p_pl_id);
2161 
2162    l_prev_opt_elig_check       c_prev_opt_elig_check%rowtype;
2163    l_prev_elig_check           c_prev_elig_check%rowtype;
2164    l_oipl_rec                  ben_cobj_cache.g_oipl_inst_row;
2165    l_epo_row                   ben_derive_part_and_rate_facts.g_cache_structure;
2166    l_pep_row                   ben_derive_part_and_rate_facts.g_cache_structure;
2167    l_proc                         VARCHAR2(72);
2168    l_par_elig_state ben_comp_obj_filter.g_par_elig_state_rec := p_par_elig_state;
2169    l_dummy      varchar2(100);
2170    --
2171 
2172 begin
2173   --
2174   p_continue_loop := false;
2175   if g_debug then
2176     l_proc := g_package ||'.update_elig_per_rows';
2177     hr_utility.set_location('Entering:' || l_proc, 10);
2178   end if;
2179   --
2180   if l_envpgm_id is not null then
2181     --
2182     open c_epe (l_envpgm_id);
2183     fetch c_epe into l_dummy;
2184     if c_epe%found then
2185       --
2186       update ben_elig_per_f pep set per_in_ler_id = p_per_in_ler_id
2187         where pep.person_id = p_person_id
2188         and   pep.per_in_ler_id is null
2189         and   pep.pgm_id = l_envpgm_id
2190         and   p_effective_date between pep.effective_start_date
2191             and pep.effective_end_date;
2192       ben_pep_cache.clear_down_pepcache;
2193     end if;
2194     close c_epe;
2195     --
2196     if l_oipl_id is not null then
2197      --
2198       open c_epo(l_envpgm_id);
2199       fetch c_epo into l_dummy;
2200       if c_epo%found then
2201         l_oipl_rec := ben_cobj_cache.g_oipl_currow;
2202         --
2203         update ben_elig_per_opt_f epo
2204           set per_in_ler_id = p_per_in_ler_id
2205           where epo.per_in_ler_id is null
2206           and   epo.elig_per_id in
2207                  (select elig_per_id from ben_elig_per_f pep
2208                   where pep.pgm_id = l_envpgm_id
2209                   and pep.per_in_ler_id = p_per_in_ler_id
2210                   and p_effective_date between pep.effective_start_date
2211                   and pep.effective_end_date)
2212          and   p_effective_date between epo.effective_start_date and
2213                epo.effective_end_date
2214          and   epo.opt_id = l_oipl_rec.opt_id;
2215         ben_pep_cache.clear_down_epocache;
2216       end if;
2217       close c_epo;
2218     end if;
2219     --
2220   else
2221     --
2222     open c_epe2(l_envpl_id);
2223     fetch c_epe2 into l_dummy;
2224     if c_epe2%found then
2225       --
2226       update ben_elig_per_f pep set per_in_ler_id = p_per_in_ler_id
2227         where pep.person_id = p_person_id
2228         and   pep.per_in_ler_id is null
2229         and   pep.pgm_id is null
2230         and   pep.pl_id = l_envpl_id
2231         and   p_effective_date between pep.effective_start_date
2232               and pep.effective_end_date;
2233       ben_pep_cache.clear_down_pepcache;
2234     end if;
2235     close c_epe2;
2236     --
2237     if l_oipl_id is not null then
2238      --
2239       open c_epo2(l_envpl_id);
2240       fetch c_epo2 into l_dummy;
2241       if c_epo2%found then
2242 
2243         l_oipl_rec := ben_cobj_cache.g_oipl_currow;
2244         --
2245         update ben_elig_per_opt_f epo
2246           set per_in_ler_id = p_per_in_ler_id
2247           where epo.per_in_ler_id is null
2248           and   epo.elig_per_id in
2249                     (select elig_per_id from ben_elig_per_f pep
2250                      where pep.pgm_id is null
2251                      and pep.pl_id = l_envpl_id
2252                      and pep.per_in_ler_id = p_per_in_ler_id
2253                      and p_effective_date between pep.effective_start_date
2254                      and pep.effective_end_date)
2255          and   p_effective_date between epo.effective_start_date and
2256                epo.effective_end_date
2257          and   epo.opt_id = l_oipl_rec.opt_id;
2258          ben_pep_cache.clear_down_epocache;
2259       end if;
2260       close c_epo2;
2261       --
2262     end if;
2263     --
2264   end if;
2265   --
2266   if l_oipl_id is not null then
2267      --
2268      hr_utility.set_location('OIPL ID-update'||l_oipl_id,111);
2269      l_oipl_rec := ben_cobj_cache.g_oipl_currow;
2270      if l_envpgm_id is not null then
2271       --
2272         ben_pep_cache.get_pilepo_dets
2273         (p_person_id         => p_person_id
2274         ,p_business_group_id => p_business_group_id
2275         ,p_effective_date    => p_effective_date
2276         ,p_pgm_id            => l_envpgm_id
2277         ,p_pl_id             => l_envpl_id
2278         ,p_opt_id            => l_oipl_rec.opt_id
2279         ,p_inst_row          => l_epo_row
2280         );
2281       --
2282       --
2283       if l_epo_row.elig_per_opt_id is null then
2284          p_continue_loop := false;
2285          hr_utility.set_location('elig per id is null' ||l_oipl_id,111);
2286          return;
2287       else
2288         l_elig_per_opt_id           := l_epo_row.elig_per_opt_id;
2289         l_object_version_number_opt := l_epo_row.object_version_number;
2290         l_elig_per_id               := l_epo_row.elig_per_id;
2291 
2292       end if;
2293     else  -- pgm_id is null
2294        open c_prev_opt_elig_check
2295         (c_person_id      => p_person_id
2296         ,c_effective_date => p_effective_date
2297         ,c_pl_id          => l_envpl_id
2298         ,c_opt_id         => l_oipl_rec.opt_id
2299         );
2300       if g_debug then
2301         hr_utility.set_location('fetch c_prvoptelch ' || l_proc, 10);
2302       end if;
2303       fetch c_prev_opt_elig_check into l_prev_opt_elig_check;
2304       if c_prev_opt_elig_check%notfound then
2305         --
2306         close c_prev_opt_elig_check;
2307         p_continue_loop := false;
2308         return;
2309         --
2310       else
2311         --
2312         l_elig_per_opt_id           := l_prev_opt_elig_check.elig_per_opt_id;
2313         l_object_version_number_opt := l_prev_opt_elig_check.object_version_number;
2314         l_elig_per_id               := l_prev_opt_elig_check.elig_per_id;
2315         --
2316       end if;
2317       close c_prev_opt_elig_check;
2318 
2319 
2320     end if;
2321     p_continue_loop := true;
2322 
2323    else  -- oipl_id is null
2324     --
2325     -- Check for a plan in program
2326     --
2327     if l_envpgm_id is not null and
2328          l_pl_id is not null
2329     then
2330       --
2331       if g_debug then
2332         hr_utility.set_location(' before pilpep  ',111);
2333       end if;
2334       ben_pep_cache.get_pilpep_dets
2335         (p_person_id         => p_person_id
2336         ,p_business_group_id => p_business_group_id
2337         ,p_effective_date    => p_effective_date
2338         ,p_pgm_id            => l_envpgm_id
2339         ,p_pl_id             => l_pl_id
2340         ,p_plip_id           => l_plip_id
2341         ,p_inst_row          => l_pep_row
2342         );
2343       --
2344       if  l_pep_row.elig_per_id is not null then
2345          --
2346          l_elig_per_id           := l_pep_row.elig_per_id;
2347          l_object_version_number := l_pep_row.object_version_number;
2348          --
2349          if l_pep_row.elig_flag = 'Y' then
2350             ben_comp_obj_filter.set_parent_elig_flags
2351             (p_comp_obj_tree_row => p_comp_obj_tree_row
2352             ,p_eligible          => TRUE
2353             ,p_treeele_num       => p_treeele_num
2354             ,p_par_elig_state    => l_par_elig_state
2355             );
2356          else
2357             ben_comp_obj_filter.set_parent_elig_flags
2358             (p_comp_obj_tree_row => p_comp_obj_tree_row
2359             ,p_eligible          => FALSE
2360             ,p_treeele_num       => p_treeele_num
2361             ,p_par_elig_state    => l_par_elig_state
2362             );
2363          end if;
2364       else
2365         --
2366         p_continue_loop := false;
2367         return;
2368         --
2369       end if;
2370       --
2371     else -- pgm_id is null
2372       --
2373       open c_prev_elig_check
2374         (c_person_id      => p_person_id
2375         ,c_pgm_id         => nvl(l_envpgm_id,-1)
2376         ,c_pl_id          => nvl(l_pl_id,-1)
2377         ,c_ptip_id        => nvl(l_ptip_id,-1)
2378         ,c_effective_date => p_effective_date
2379         );
2380       fetch c_prev_elig_check into l_prev_elig_check;
2381       --
2382       if c_prev_elig_check%found then
2383         l_elig_per_id           := l_prev_elig_check.elig_per_id;
2384         l_object_version_number := l_prev_elig_check.object_version_number;
2385 
2386         if l_prev_elig_check.elig_flag = 'Y' then
2387            ben_comp_obj_filter.set_parent_elig_flags
2388            (p_comp_obj_tree_row => p_comp_obj_tree_row
2389            ,p_eligible          => TRUE
2390            ,p_treeele_num       => p_treeele_num
2391            ,p_par_elig_state    => l_par_elig_state
2392            );
2393         else
2394            ben_comp_obj_filter.set_parent_elig_flags
2395            (p_comp_obj_tree_row => p_comp_obj_tree_row
2396            ,p_eligible          => FALSE
2397            ,p_treeele_num       => p_treeele_num
2398            ,p_par_elig_state    => l_par_elig_state
2399            );
2400          end if;
2401       else
2402         close c_prev_elig_check;
2403         p_continue_loop := false;
2404         return;
2405         --
2406       end if;
2407       --
2408     end if;
2409      --
2410     p_continue_loop := true;
2411 
2412   end if;
2413    --
2414   p_par_elig_state := l_par_elig_state;
2415    if g_debug then
2416      hr_utility.set_location('Leaving:' || l_proc, 10);
2417    end if;
2418 end;
2419 --
2420 procedure update_enrt_rt (p_per_in_ler_id number) is
2421   --
2422    cursor c_enrt_rt is
2423     select *
2424     from ben_enrt_rt
2425     where elig_per_elctbl_chc_id in
2426        (select elig_per_elctbl_chc_id from ben_elig_per_elctbl_chc
2427           where per_in_ler_id = p_per_in_ler_id)
2428   union
2429     select *
2430     from ben_enrt_rt
2431      where enrt_bnft_id in
2432        (select enrt_bnft_id from ben_enrt_bnft
2433           where elig_per_elctbl_chc_id in
2434           (select elig_per_elctbl_chc_id from ben_elig_per_elctbl_chc
2435              where per_in_ler_id = p_per_in_ler_id));
2436 
2437   --
2438   cursor c_pil_popl is
2439     select *
2440     from ben_pil_elctbl_chc_popl
2441     where per_in_ler_id = p_per_in_ler_id;
2442   --
2443   --bug#2718215
2444   cursor c_result_pgm (p_pgm_id number) is
2445     select effective_start_date
2446     from ben_prtt_enrt_rslt_f pen,
2447          ben_per_in_ler pil
2448     where pen.pgm_id = p_pgm_id
2449     and   pen.person_id = pil.person_id
2450     and   pil.per_in_ler_id = p_per_in_ler_id
2451     and   pen.prtt_enrt_rslt_stat_cd is null
2452     and   pen.effective_end_date = hr_api.g_eot;
2453  --
2454   cursor c_result_pln (p_pl_id number) is
2455     select effective_start_date
2456     from ben_prtt_enrt_rslt_f pen,
2457          ben_per_in_ler pil
2458     where pen.pl_id = p_pl_id
2459     and   pen.person_id = pil.person_id
2460     and   pil.per_in_ler_id = p_per_in_ler_id
2461     and   pen.prtt_enrt_rslt_stat_cd is null
2462     and   pen.effective_end_date = hr_api.g_eot;
2463   --
2464   l_effective_start_date date;
2465 
2466 begin
2467   --
2468   if g_debug then
2469     hr_utility.set_location('Entering ',10);
2470   end if;
2471 /*
2472 bug#1936976 prtt_rt_val_id is already populated in benactbr - this process is redundant
2473 and if coverage is %rng multiple rate for same acty_base_rt is possible
2474   for i in c_enrt_rt loop
2475     --
2476       if g_debug then
2477         hr_utility.set_location('Entering ',10);
2478       end if;
2479     if ben_manage_life_events.g_enrt_rt_tbl.count = 0 then
2480        return;
2481     end if;
2482     --
2483     for j in ben_manage_life_events.g_enrt_rt_tbl.first .. ben_manage_life_events.g_enrt_rt_tbl.last loop
2484       --
2485        if g_debug then
2486          hr_utility.set_location('Entering ',10);
2487        end if;
2488       if i.acty_base_rt_id = ben_manage_life_events.g_enrt_rt_tbl(j).acty_base_rt_id then
2489          --
2490          if ben_manage_life_events.g_enrt_rt_tbl(j).prtt_rt_val_id is not null then
2491             update ben_enrt_rt
2492               set prtt_rt_val_id =  ben_manage_life_events.g_enrt_rt_tbl(j).prtt_rt_val_id
2493               where enrt_rt_id = i.enrt_rt_id;
2494          end if;
2495          --
2496          exit;
2497          --
2498        end if;
2499       --
2500      end loop;
2501       --
2502   end loop;
2503 */
2504   --
2505   for i in c_pil_popl  loop
2506     --
2507     /* The logic of updating the elections made date is changed to take care of situations
2508        after running recalculate process and after conversion  because after conversion
2509        there is no pil elctble choice record.  Now, the cursors fetch the election made
2510        date from enrollment result table.
2511 
2512       if g_debug then
2513         hr_utility.set_location('Entering  popl update',10);
2514       end if;
2515     if ben_manage_life_events.g_pil_popl_tbl.count = 0 then
2516        return;
2517     end if;
2518     --
2519     for j in ben_manage_life_events.g_pil_popl_tbl.first .. ben_manage_life_events.g_pil_popl_tbl.last loop
2520       --
2521       if i.pgm_id = ben_manage_life_events.g_pil_popl_tbl(j).pgm_id or
2522           i.pl_id = ben_manage_life_events.g_pil_popl_tbl(j).pl_id then
2523          --
2524             update ben_pil_elctbl_chc_popl
2525               set elcns_made_dt =  ben_manage_life_events.g_pil_popl_tbl(j).elcns_made_dt
2526               where pil_elctbl_chc_popl_id  = i.pil_elctbl_chc_popl_id;
2527          --
2528          --
2529          --
2530        end if;
2531       --
2532      end loop;
2533       --
2534      */
2535      if i.pgm_id is not null then
2536         open c_result_pgm (i.pgm_id);
2537         fetch c_result_pgm into l_effective_start_date;
2538         if c_result_pgm%found then
2539            update ben_pil_elctbl_chc_popl
2540              set elcns_made_dt = l_effective_start_date
2541              where pil_elctbl_chc_popl_id  = i.pil_elctbl_chc_popl_id;
2542         end if;
2543         close c_result_pgm;
2544      elsif i.pl_id is not null then
2545         open c_result_pln (i.pl_id);
2546         fetch c_result_pln into l_effective_start_date;
2547         if c_result_pln%found then
2548            update ben_pil_elctbl_chc_popl
2549              set elcns_made_dt = l_effective_start_date
2550              where pil_elctbl_chc_popl_id  = i.pil_elctbl_chc_popl_id;
2551         end if;
2552         close c_result_pln;
2553      end if;
2554 
2555   end loop;
2556 
2557   if g_debug then
2558     hr_utility.set_location('Leaving update enrt',10);
2559   end if;
2560 end;
2561 -- GSP New Procedure for updating the epe for default/auto
2562 -- enrollments.
2563 procedure gsp_proc_dflt_auten(p_per_in_ler_id number,
2564                               p_effective_date date ) is
2565   --local variables
2566   l_package               varchar2(80) := g_package||'.gsp_proc_dflt_auten';
2567   l_return_cd                varchar2(30);
2568   l_elig_per_elctbl_chc_id   number(15);
2569   l_dflt_flag                varchar2(30) := 'N';
2570   l_auto_enrt_flag           varchar2(30) := 'N';
2571   --cursors
2572   cursor c_epe is
2573     select elig_per_elctbl_chc_id,
2574            object_version_number
2575     from ben_elig_per_elctbl_chc epe
2576     where elig_per_elctbl_chc_id = l_elig_per_elctbl_chc_id
2577       and per_in_ler_id          = p_per_in_ler_id ;
2578   --
2579   l_epe                      c_epe%ROWTYPE;
2580   --
2581 begin
2582   --
2583   hr_utility.set_location('Entering '||l_package,10);
2584   --
2585   --Call the GSP Default procedure to get the epe and return code
2586   pqh_gsp_default.get_def_auto_code(
2587     p_per_in_ler_id       => p_per_in_ler_id,
2588     p_effective_date      => p_effective_date,
2589     p_return_code         => l_return_cd,
2590     p_electbl_chc_id       => l_elig_per_elctbl_chc_id
2591   );
2592   --
2593   if l_elig_per_elctbl_chc_id is not null then
2594     --
2595     open c_epe ;
2596       fetch c_epe into l_epe ;
2597     close c_epe ;
2598     --
2599     if l_return_cd = 'D' then
2600       --
2601       l_dflt_flag   := 'Y' ;
2602       --
2603     elsif l_return_cd = 'A' then
2604       --
2605       l_auto_enrt_flag := 'Y' ;
2606       l_dflt_flag      := 'Y' ;
2607       --
2608     end if;
2609     --
2610     if l_epe.elig_per_elctbl_chc_id is not null then
2611       ben_elig_per_elc_chc_api.update_perf_ELIG_PER_ELC_CHC
2612         (p_elig_per_elctbl_chc_id    => l_epe.elig_per_elctbl_chc_id
2613         ,p_object_version_number     => l_epe.object_version_number
2614         ,p_dflt_flag                 => l_dflt_flag
2615         ,p_auto_enrt_flag            => l_auto_enrt_flag
2616         ,p_effective_date            => p_effective_date
2617       );
2618       --
2619       --Call the GSP Post process for Automatic enrollment
2620       if l_auto_enrt_flag = 'Y' then
2621         --
2622         pqh_gsp_post_process.Call_PP_From_Benmngle(
2623            P_Effective_Date            =>p_effective_date,
2624            P_Elig_per_Elctbl_Chc_Id    =>l_epe.elig_per_elctbl_chc_id
2625         )   ;
2626         --
2627       end if;
2628       --
2629     end if;
2630     --
2631   end if;
2632   --
2633   hr_utility.set_location('Leaving '||l_package,20);
2634   --
2635 end gsp_proc_dflt_auten ;
2636 --
2637 -- Bug 1895846
2638 procedure reset_elctbl_chc_inpng_flag(p_per_in_ler_id number,
2639                                       p_effective_date date ) is
2640   --
2641   l_object_version_number number ;
2642   l_package               varchar2(100);
2643   cursor c_epe is
2644   select
2645     elig_per_elctbl_chc_id
2646   from
2647     ben_elig_per_elctbl_chc epe
2648   where
2649     per_in_ler_id = p_per_in_ler_id and
2650     in_pndg_wkflow_flag = 'S';
2651   --
2652 begin
2653   --
2654 /*
2655   update ben_elig_per_elctbl_chc
2656   set in_pndg_wkflow_flag = 'N'
2657   where in_pndg_wkflow_flag = 'S'
2658   and per_in_ler_id = p_per_in_ler_id;
2659 */
2660   if g_debug then
2661     l_package := 'reset_elctbl_chc_inpng_flag' ;
2662     hr_utility.set_location('Entering '||l_package , 10);
2663   end if;
2664   --
2665   for l_epe in c_epe loop
2666     --
2667     ben_elig_per_elc_chc_api.update_perf_ELIG_PER_ELC_CHC
2668       (p_elig_per_elctbl_chc_id    => l_epe.elig_per_elctbl_chc_id
2669       ,p_object_version_number      => l_object_version_number
2670       ,p_in_pndg_wkflow_flag        => 'N'
2671       ,p_effective_date             => p_effective_date
2672     );
2673     --
2674   end loop ;
2675   --
2676   if g_debug then
2677     hr_utility.set_location('Leaving '||l_package , 10);
2678   end if;
2679   --
2680 end;
2681 --
2682 -- Bug 1895846
2683 procedure delete_in_pndg_elig_dpnt( p_per_in_ler_id in number,
2684                                     p_effective_date     in date) is
2685   l_object_version_number number ;
2686   l_package               varchar2(100);
2687   --
2688   cursor c_in_pndg_edg is
2689   select
2690     elig_dpnt_id
2691   from
2692     ben_elig_dpnt egd
2693   where
2694     egd.per_in_ler_id = p_per_in_ler_id and
2695     egd.elig_per_elctbl_chc_id is null ;
2696 
2697 begin
2698   --
2699   if g_debug then
2700     l_package := 'delete_in_pndg_elig_dpnt' ;
2701     hr_utility.set_location('Entering '||l_package , 10);
2702   end if;
2703   for l_in_pndg_edg in c_in_pndg_edg loop
2704     --
2705     ben_elig_dpnt_api.delete_elig_dpnt
2706       (p_elig_dpnt_id                   => l_in_pndg_edg.elig_dpnt_id
2707       ,p_object_version_number          => l_object_version_number
2708       ,p_effective_date                 => p_effective_date
2709       ) ;
2710     --
2711   end loop;
2712   --
2713   if g_debug then
2714     hr_utility.set_location('Leaving '||l_package , 10);
2715   end if;
2716 end ;
2717 --
2718 procedure write_logfile(p_benefit_action_id   in number,
2719                         p_thread_id           in number,
2720                         p_validate            in varchar2,
2721                         p_person_count        in number,
2722                         p_error_person_count  in number) is
2723   --
2724   l_package        varchar2(80);
2725   --
2726   table_full EXCEPTION;
2727   index_full EXCEPTION;
2728   pragma exception_init(table_full,-1653);
2729   pragma exception_init(index_full,-1654);
2730 begin
2731   --
2732   if g_debug then
2733     l_package := g_package||'.write_logfile';
2734     hr_utility.set_location ('Entering '||l_package,10);
2735   end if;
2736   --
2737   benutils.write(p_text => benutils.g_banner_minus);
2738   benutils.write(p_text => 'Benefits Statistical Information');
2739   benutils.write(p_text => benutils.g_banner_minus);
2740   benutils.write(p_text => 'Processed persons     '||p_person_count);
2741   benutils.write(p_text => 'Errored persons       '||p_error_person_count);
2742   benutils.write(p_text => benutils.g_banner_minus);
2743   --
2744   benutils.write_table_and_file(p_table => true,
2745                                 p_file  => true);
2746   commit;
2747   --
2748   if g_debug then
2749     hr_utility.set_location ('Leaving '||l_package,10);
2750   end if;
2751   --
2752 exception
2753   --
2754  --
2755  when table_full then
2756    benutils.write(fnd_message.get);
2757    fnd_message.raise_error;
2758  when index_full then
2759    benutils.write(fnd_message.get);
2760    fnd_message.raise_error;
2761  --
2762   when others then
2763     --
2764     fnd_message.set_name('BEN','BEN_91663_BENMNGLE_LOGGING');
2765     benutils.write(fnd_message.get);
2766     fnd_message.raise_error;
2767     --
2768 end write_logfile;
2769 --
2770 procedure flush_global_structures is
2771   --
2772   l_package varchar2(80);
2773   --
2774 begin
2775   --
2776   g_debug := hr_utility.debug_enabled;
2777   if g_debug then
2778     l_package := g_package||'.flush_global_structures';
2779     hr_utility.set_location ('Entering '||l_package,10);
2780   end if;
2781   --
2782   g_cache_person_process.delete;
2783   benutils.clear_down_cache;
2784   benutils.g_batch_param_table_object.delete;
2785   ben_elig_rl_cache.clear_down_cache;
2786   ben_location_object.clear_down_cache;
2787   ben_org_object.clear_down_cache;
2788   ben_life_object.clear_down_cache;
2789   --
2790   -- Clear down comp object cache
2791   --
2792   ben_pln_cache.clear_down_cache;
2793   ben_cop_cache.clear_down_cache;
2794   ben_cobj_cache.clear_down_cache;
2795   ben_element_entry.clear_down_cache;
2796   --
2797   -- Clear down person object caches
2798   --
2799   ben_person_object.clear_down_cache;
2800   ben_batch_dt_api.clear_down_cache;
2801   --
2802   ben_pil_object.clear_down_cache;
2803   --
2804   if g_debug then
2805     hr_utility.set_location ('Leaving '||l_package,10);
2806   end if;
2807   --
2808 end flush_global_structures;
2809 --
2810 procedure print_parameters
2811    (p_benefit_action_id in number) is
2812   --
2813   l_package varchar2(80);
2814   l_rec     benutils.g_batch_param_rec;
2815   -- added bug: 5618436
2816   CURSOR c_conc_pgm_name is
2817   SELECT fcp.concurrent_program_name
2818     FROM ben_benefit_actions bft, fnd_concurrent_programs fcp
2819    WHERE bft.program_id = fcp.concurrent_program_id
2820      AND bft.benefit_action_id = p_benefit_action_id;
2821 
2822   l_source_program fnd_concurrent_programs.concurrent_program_name%TYPE;
2823   --
2824 begin
2825   --
2826   if g_debug then
2827     l_package := g_package||'.print_parameters';
2828     hr_utility.set_location ('Entering '||l_package,10);
2829   end if;
2830   open c_conc_pgm_name;
2831   fetch c_conc_pgm_name into l_source_program;
2832   close c_conc_pgm_name;
2833   --
2834   if fnd_global.conc_request_id = -1 then
2835     return;
2836   end if;
2837   --
2838   benutils.get_batch_parameters
2839     (p_benefit_action_id => p_benefit_action_id,
2840      p_rec               => l_rec);
2841   --
2842   fnd_file.put_line(which => fnd_file.log,
2843                     buff  => 'Runtime Parameters');
2844   fnd_file.put_line(which => fnd_file.log,
2845                     buff  => '------------------');
2846   fnd_file.put_line(which => fnd_file.log,
2847                     buff  => 'Concurrent Request ID      :'||
2848                     fnd_global.conc_request_id);
2849   fnd_file.put_line(which => fnd_file.log,
2850                     buff  => 'Run Mode                   :'||
2851                     hr_general.decode_lookup('BEN_BENMNGLE_MD',l_rec.mode_cd));
2852   fnd_file.put_line(which => fnd_file.log,
2853                     buff  => 'Validation Mode            :'||
2854                     hr_general.decode_lookup('YES_NO',l_rec.validate_flag));
2855   -- bug: 5618436
2856   if l_source_program
2857 	not in ('BENLIMOD','BENSCMOD','BENSEMOD','BENPAMOD','BENGSMOD','BENTEMOD')
2858 	then
2859 		  fnd_file.put_line(which => fnd_file.log,
2860                     buff  => 'Limit By Person''s Organization :'||
2861                     hr_general.decode_lookup('YES_NO',l_rec.lmt_prpnip_by_org_flag));
2862   end if;
2863 
2864   fnd_file.put_line(which => fnd_file.log,
2865                     buff  => 'Benefit Action ID          :'||
2866                     p_benefit_action_id);
2867   fnd_file.put_line(which => fnd_file.log,
2868                     buff  => 'Effective Date             :'||
2869                     to_char(l_rec.process_date,'DD/MM/YYYY'));
2870   fnd_file.put_line(which => fnd_file.log,
2871                     buff  => 'Derivable Factors          :'||
2872                     hr_general.decode_lookup('BEN_DTCT_TMPRL_LER_TYP',l_rec.derivable_factors_flag));
2873   fnd_file.put_line(which => fnd_file.log,
2874                     buff  => 'Business Group ID          :'||
2875                     l_rec.business_group_id);
2876   fnd_file.put_line(which => fnd_file.log,
2877                     buff  => 'Program ID                 :'||
2878                     benutils.iftrue
2879                      (p_expression => l_rec.pgm_id is null,
2880                       p_true       => 'All',
2881                       p_false      => l_rec.pgm_id));
2882   fnd_file.put_line(which => fnd_file.log,
2883                     buff  => 'Plan ID                    :'||
2884                     benutils.iftrue
2885                      (p_expression => l_rec.pl_id is null,
2886                       p_true       => 'All',
2887                       p_false      => l_rec.pl_id));
2888   fnd_file.put_line(which => fnd_file.log,
2889                     buff  => 'Plan Type ID               :'||
2890                     benutils.iftrue
2891                      (p_expression => l_rec.pl_typ_id is null,
2892                       p_true       => 'All',
2893                       p_false      => l_rec.pl_typ_id));
2894   fnd_file.put_line(which => fnd_file.log,
2895                     buff  => 'Option ID                  :'||
2896                     benutils.iftrue
2897                      (p_expression => l_rec.opt_id is null,
2898                       p_true       => 'All',
2899                       p_false      => l_rec.opt_id));
2900   --
2901   -- PB : 5422 : Need to dump the lf_evt_dt
2902   -- popl_enrt_typ_cycl_id is no longer available.
2903   --
2904   /*
2905   fnd_file.put_line(which => fnd_file.log,
2906                     buff  => 'Enrollment Type Cycle      :'||
2907                     benutils.iftrue
2908                      (p_expression => l_rec.popl_enrt_typ_cycl_id is null,
2909                       p_true       => 'All',
2910                       p_false      => l_rec.popl_enrt_typ_cycl_id));
2911   */
2912   fnd_file.put_line(which => fnd_file.log,
2913                     buff  => 'Just Plans not in Programs :'||
2914                     hr_general.decode_lookup('YES_NO',l_rec.no_programs_flag));
2915   fnd_file.put_line(which => fnd_file.log,
2916                     buff  => 'Just Programs              :'||
2917                     hr_general.decode_lookup('YES_NO',l_rec.no_plans_flag));
2918   fnd_file.put_line(which => fnd_file.log,
2919                     buff  => 'Reporting Group            :'||
2920                     benutils.iftrue
2921                      (p_expression => l_rec.rptg_grp_id is null,
2922                       p_true       => 'All',
2923                       p_false      => l_rec.rptg_grp_id));
2924   fnd_file.put_line(which => fnd_file.log,
2925                     buff  => 'Eligiblity Profile         :'||
2926                     benutils.iftrue
2927                      (p_expression => l_rec.eligy_prfl_id is null,
2928                       p_true       => 'All',
2929                       p_false      => l_rec.eligy_prfl_id));
2930   fnd_file.put_line(which => fnd_file.log,
2931                     buff  => 'Variable Rate Profile      :'||
2932                     benutils.iftrue
2933                      (p_expression => l_rec.vrbl_rt_prfl_id is null,
2934                       p_true       => 'All',
2935                       p_false      => l_rec.vrbl_rt_prfl_id));
2936   fnd_file.put_line(which => fnd_file.log,
2937                     buff  => 'Person Selection Rule      :'||
2938                     benutils.iftrue
2939                      (p_expression => l_rec.person_selection_rl is null,
2940                       p_true       => 'None',
2941                       p_false      => l_rec.person_selection_rl));
2942   fnd_file.put_line(which => fnd_file.log,
2943                     buff  => 'Comp Object Selection Rule :'||
2944                     benutils.iftrue
2945                      (p_expression => l_rec.comp_selection_rl is null,
2946                       p_true       => 'None',
2947                       p_false      => l_rec.comp_selection_rl));
2948   --
2949   if g_debug then
2950     hr_utility.set_location ('Leaving '||l_package,10);
2951   end if;
2952   --
2953 end print_parameters;
2954 --
2955 -- CWBITEM
2956 --
2957 --
2958 -- CWB Procedure for population of the CWB Hierarchy table
2959 --
2960 procedure popu_pel_heir is
2961   --
2962   l_proc         VARCHAR2(80);
2963   l_level        number             := 1 ;
2964   l_emp_pel           number ;
2965   l_mgr_pel           number ;
2966   l_mgr_person_id     number ;
2967   l_mgr_person_id_out number ;
2968   l_business_group_id number ;
2969   l_pl_id             number;
2970   l_lf_evt_ocrd_dt    date;
2971   l_ler_id            number;
2972   l_rec             benutils.g_batch_param_rec;
2973   lv_pl_id          number;
2974   lv_business_group_id number;
2975   lv_ler_id            number;
2976   lv_lf_evt_ocrd_dt date;
2977   --
2978   -- Bug 2288042 : Create 0 level heirarchy data if manager is
2979   -- is processed first and employee is processed later.
2980   --
2981   cursor c_no_0_hrchy(p_pl_id number,
2982                       p_lf_evt_ocrd_dt date,
2983                       p_business_group_id number) is
2984   select unique pel_0.mgr_pil_elctbl_chc_popl_id
2985   from ben_cwb_hrchy pel_0,
2986      ben_pil_elctbl_chc_popl mgr_pel_0,
2987      ben_per_in_ler pil_0
2988   where
2989       mgr_pel_0.pil_elctbl_chc_popl_id = pel_0.mgr_pil_elctbl_chc_popl_id
2990       and mgr_pel_0.per_in_ler_id = pil_0.per_in_ler_id
2991       and mgr_pel_0.pl_id         = p_pl_id
2992       and pil_0.lf_evt_ocrd_dt = p_lf_evt_ocrd_dt
2993       -- and pil_0.ler_id = p_ler_id
2994       and pil_0.business_group_id = p_business_group_id
2995       and pil_0.per_in_ler_stat_cd = 'STRTD'
2996   and pel_0.lvl_num > 0
2997   and pel_0.mgr_pil_elctbl_chc_popl_id not in
2998   ( select mgr_pel.pil_elctbl_chc_popl_id
2999     from ben_cwb_hrchy hrh,
3000          ben_pil_elctbl_chc_popl mgr_pel,
3001          ben_per_in_ler pil
3002     where hrh.mgr_pil_elctbl_chc_popl_id =
3003                         hrh.emp_pil_elctbl_chc_popl_id
3004       and mgr_pel.pil_elctbl_chc_popl_id = hrh.mgr_pil_elctbl_chc_popl_id
3005       and hrh.lvl_num = 0
3006       and mgr_pel.per_in_ler_id = pil.per_in_ler_id
3007       and mgr_pel.pl_id         = p_pl_id
3008       and pil.lf_evt_ocrd_dt = p_lf_evt_ocrd_dt
3009       -- and pil.ler_id         = p_ler_id
3010       and pil.business_group_id = p_business_group_id
3011       and pil.per_in_ler_stat_cd = 'STRTD'
3012   );
3013   --
3014   -- Cursor to select the pel records for emp
3015   -- These are the records created initially with mgr_pil_elctbl_chc_popl_id and
3016   -- lvl_num as '-1'
3017   --
3018   cursor c_pel(cv_pl_id number, cv_lf_evt_ocrd_dt date) is
3019     select
3020       cwb.emp_pil_elctbl_chc_popl_id,
3021       pel.ws_mgr_id
3022     from
3023       ben_cwb_hrchy  cwb,
3024       ben_pil_elctbl_chc_popl pel ,
3025       ben_per_in_ler pil
3026     where
3027           cwb.mgr_pil_elctbl_chc_popl_id = -1
3028       and pel.pil_elctbl_chc_popl_id = cwb.emp_pil_elctbl_chc_popl_id
3029       --
3030       -- Bug 2541072 : Do not consider all per in ler's.
3031       --
3032       and pel.per_in_ler_id = pil.per_in_ler_id
3033       and pil.per_in_ler_stat_cd = 'STRTD'
3034       and ((cv_pl_id = -1 and cv_lf_evt_ocrd_dt = hr_api.g_eot)
3035             or
3036            (pil.lf_evt_ocrd_dt = cv_lf_evt_ocrd_dt and pel.pl_id = cv_pl_id)
3037           )
3038       and cwb.lvl_num = -1;
3039   --
3040   -- To get the pl_id, lf_evt_ocrd_dt, ler_id and business_group_id of the first records.
3041   -- This is the criteria used for finding the pel records in the hierarchy.
3042   --
3043   cursor c_pl_ler(p_pil_elctbl_chc_popl_id number) is
3044     select
3045       pel.pl_id,
3046       pil.lf_evt_ocrd_dt,
3047       pil.ler_id,
3048       pil.business_group_id
3049     from
3050       ben_pil_elctbl_chc_popl pel,
3051       ben_per_in_ler pil
3052     where
3053        pel.per_in_ler_id = pil.per_in_ler_id
3054    and pel.pil_elctbl_chc_popl_id = p_pil_elctbl_chc_popl_id
3055    and pil.per_in_ler_stat_cd = 'STRTD';
3056   --
3057   -- This private procedure determines the Manager pel
3058   -- This will get the manager pel record for a given emp - cascading
3059   procedure mgr( p_person_id number,
3060                 p_business_group_id number,
3061                 p_pl_id number,
3062                 p_lf_evt_ocrd_dt date,
3063                 p_ler_id number,
3064                 p_ws_mgr_id out nocopy number,
3065                 p_pil_elctbl_chc_popl_id out nocopy number ) is
3066     --
3067     cursor c_mgr(p_person_id number,
3068                  p_pl_id number,
3069                  p_lf_evt_ocrd_dt date,
3070                  p_ler_id number,
3071                  p_business_group_id number) is
3072       select pel.ws_mgr_id,
3073              pel.pil_elctbl_chc_popl_id
3074       from ben_pil_elctbl_chc_popl pel,
3075            ben_per_in_ler pil
3076       where pel.per_in_ler_id = pil.per_in_ler_id
3077       and   pel.pl_id         = p_pl_id
3078       and   pil.lf_evt_ocrd_dt = p_lf_evt_ocrd_dt
3079       and   pil.ler_id        = p_ler_id
3080       and   pil.person_id     = p_person_id
3081       and   pil.business_group_id = p_business_group_id
3082       and   pil.per_in_ler_stat_cd = 'STRTD';
3083     --
3084   l_ws_mgr_id number := null ;
3085   l_pil_elctbl_chc_popl_id number := null ;
3086   begin
3087     --
3088     g_debug := hr_utility.debug_enabled;
3089     if g_debug then
3090       hr_utility.set_location('MGR p_person_id '||p_person_id,22);
3091       hr_utility.set_location('MGR p_business_group_id '||p_business_group_id,23);
3092     end if;
3093     --
3094     open c_mgr (p_person_id,p_pl_id,p_lf_evt_ocrd_dt,p_ler_id,p_business_group_id);
3095     fetch c_mgr into l_ws_mgr_id,l_pil_elctbl_chc_popl_id ;
3096     close c_mgr ;
3097     --
3098     if g_debug then
3099       hr_utility.set_location('MGR OUT l_pil_elctbl_chc_popl_id '||l_pil_elctbl_chc_popl_id,30);
3100       hr_utility.set_location('MGR OUT l_ws_mgr_id '||l_ws_mgr_id,40);
3101     end if;
3102     --
3103     p_pil_elctbl_chc_popl_id := l_pil_elctbl_chc_popl_id ;
3104     p_ws_mgr_id := l_ws_mgr_id ;
3105   end;
3106   --
3107   -- This procedure inserts records into hierarchy table
3108   --
3109   procedure insert_mgr_hrchy ( p_emp_pil_elctbl_chc_popl_id number,
3110                                p_mgr_pil_elctbl_chc_popl_id number,
3111                                p_lvl_num number ) is
3112   begin
3113     --
3114     if g_debug then
3115       hr_utility.set_location('insert_mgr_hrchy p_emp_pil_elctbl_chc_popl_id '
3116                                      ||p_emp_pil_elctbl_chc_popl_id,10);
3117       hr_utility.set_location('insert_mgr_hrchy p_mgr_pil_elctbl_chc_popl_id '
3118                                      ||p_mgr_pil_elctbl_chc_popl_id || ' lvl = ' || p_lvl_num, 20);
3119     end if;
3120     insert into ben_cwb_hrchy (
3121           emp_pil_elctbl_chc_popl_id,
3122           mgr_pil_elctbl_chc_popl_id,
3123           lvl_num  )
3124     values (
3125           p_emp_pil_elctbl_chc_popl_id,
3126           p_mgr_pil_elctbl_chc_popl_id,
3127           p_lvl_num );
3128     --
3129   exception when others then
3130     --
3131     -- raise;
3132     null; -- For Bug 2712602
3133     --
3134   end insert_mgr_hrchy;
3135   --
3136   procedure update_init_pel(cv_pl_id number, cv_lf_evt_ocrd_dt date)  is
3137     --
3138     -- CWB bug : 2712602
3139     --
3140     cursor c_cwh is
3141      select rowid
3142      from ben_cwb_hrchy cwh
3143            where cwh.lvl_num = -1 and
3144              cwh.mgr_pil_elctbl_chc_popl_id = -1
3145          --
3146          -- Bug 2541072 : Do not consider all per in ler's.
3147          --
3148         and exists
3149          (select null
3150           from ben_pil_elctbl_chc_popl pel ,
3151                ben_per_in_ler pil
3152           where pel.pil_elctbl_chc_popl_id = cwh.emp_pil_elctbl_chc_popl_id
3153           and   pel.per_in_ler_id          = pil.per_in_ler_id
3154           and   pil.per_in_ler_stat_cd = 'STRTD'
3155           and ((cv_pl_id = -1 and cv_lf_evt_ocrd_dt = hr_api.g_eot)
3156                  or
3157                (pil.lf_evt_ocrd_dt = cv_lf_evt_ocrd_dt and pel.pl_id = cv_pl_id)
3158               )
3159          ) ;
3160     --
3161     begin
3162       --
3163       -- Also delete the rows for employees who do not have
3164       -- subordinates and with level -1 .
3165       -- And also the last subordinate is now reporting to another manager
3166       -- we need to delete the pel,0,0 row of the employee.
3167       --
3168       delete
3169       from ben_cwb_hrchy cwh
3170       where (( cwh.lvl_num = -1
3171               and cwh.mgr_pil_elctbl_chc_popl_id = -1) OR
3172              ( cwh.lvl_num = 0 and
3173               cwh.mgr_pil_elctbl_chc_popl_id = cwh.emp_pil_elctbl_chc_popl_id ) )
3174         and not exists
3175         (select null
3176          from ben_cwb_hrchy cwh1
3177          where cwh1.mgr_pil_elctbl_chc_popl_id = cwh.emp_pil_elctbl_chc_popl_id
3178          and cwh1.lvl_num <> 0
3179         )
3180          --
3181          -- Bug 2541072 : Do not consider all per in ler's.
3182          --
3183         and exists
3184          (select null
3185           from ben_pil_elctbl_chc_popl pel ,
3186                ben_per_in_ler pil
3187           where pel.pil_elctbl_chc_popl_id = cwh.emp_pil_elctbl_chc_popl_id
3188           and   pel.per_in_ler_id          = pil.per_in_ler_id
3189           and   pil.per_in_ler_stat_cd = 'STRTD'
3190           and ((cv_pl_id = -1 and cv_lf_evt_ocrd_dt = hr_api.g_eot)
3191                  or
3192                (pil.lf_evt_ocrd_dt = cv_lf_evt_ocrd_dt and pel.pl_id = cv_pl_id)
3193               )
3194          ) ;
3195       --
3196       -- Bug 2712602
3197       --
3198       for l_cwh in c_cwh loop
3199         --
3200         begin
3201           --
3202           update ben_cwb_hrchy cwh
3203           set cwh.mgr_pil_elctbl_chc_popl_id = cwh.emp_pil_elctbl_chc_popl_id,
3204               cwh.lvl_num = 0
3205           where cwh.lvl_num = -1
3206             and cwh.mgr_pil_elctbl_chc_popl_id = -1
3207             and cwh.rowid = l_cwh.rowid;
3208         exception
3209          when others then
3210            delete from ben_cwb_hrchy where rowid = l_cwh.rowid;null;
3211         end;
3212         --
3213       end loop;
3214       --
3215     exception when others then
3216       raise ;
3217     end ;
3218   --
3219 begin
3220   --
3221   if g_debug then
3222     l_proc := g_package||  '.popu_pel_heir';
3223     hr_utility.set_location('Entering: '||l_proc,10);
3224   end if;
3225   --
3226   lv_pl_id := -1;
3227   lv_lf_evt_ocrd_dt := hr_api.g_eot;
3228   --
3229   if benutils.g_benefit_action_id is not null then
3230      --
3231      benutils.get_batch_parameters
3232       (p_benefit_action_id => benutils.g_benefit_action_id,
3233        p_rec               => l_rec);
3234      --
3235      lv_pl_id             := l_rec.pl_id;
3236      lv_lf_evt_ocrd_dt    := l_rec.lf_evt_ocrd_dt;
3237      lv_business_group_id := l_rec.business_group_id;
3238      lv_ler_id            := l_rec.ler_id;
3239      --
3240   -- Bug 2574791
3241   else
3242      --
3243      lv_pl_id             := g_rebuild_pl_id;
3244      lv_lf_evt_ocrd_dt    := g_rebuild_lf_evt_ocrd_dt;
3245      lv_business_group_id := g_rebuild_business_group_id;
3246      --
3247   end if;
3248   --
3249   if g_debug then
3250     hr_utility.set_location(l_proc || ' lv_pl_id = ' || lv_pl_id, 9876);
3251     hr_utility.set_location(l_proc || ' lv_lf_evt_ocrd_dt = ' || lv_lf_evt_ocrd_dt, 9876);
3252     hr_utility.set_location(l_proc || ' lv_business_group_id = ' || lv_business_group_id, 9876);
3253     hr_utility.set_location(l_proc || ' lv_ler_id = ' || lv_ler_id, 9876);
3254   end if;
3255   open c_pel(lv_pl_id, lv_lf_evt_ocrd_dt);
3256   fetch c_pel into l_emp_pel,l_mgr_person_id ;
3257   --
3258   if g_debug then
3259     hr_utility.set_location(' l_emp_pel '||l_emp_pel,99);
3260     hr_utility.set_location(' l_mgr_person_id '||l_mgr_person_id,99);
3261   end if;
3262   if c_pel%found then
3263     --
3264     open c_pl_ler(l_emp_pel);
3265     fetch c_pl_ler into l_pl_id, l_lf_evt_ocrd_dt, l_ler_id, l_business_group_id ;
3266     close c_pl_ler ;
3267     --
3268   end if;
3269   --
3270   if g_debug then
3271     hr_utility.set_location(' l_pl_id '||l_pl_id,99);
3272     hr_utility.set_location(' l_lf_evt_ocrd_dt '||l_lf_evt_ocrd_dt,99);
3273     hr_utility.set_location(' l_ler_id '||l_ler_id,99);
3274     hr_utility.set_location(' l_business_group_id '||l_business_group_id,99);
3275   end if;
3276   <<pel>>
3277   loop
3278     --
3279     exit pel when c_pel%notfound ;
3280     l_level := 1 ;
3281       --
3282       <<mgr_loop>>
3283       loop
3284         --
3285         if g_debug then
3286           hr_utility.set_location('Before mgr l_mgr_person_id '||l_mgr_person_id,10);
3287         end if;
3288         mgr(l_mgr_person_id,
3289             l_business_group_id,
3290             l_pl_id,
3291             l_lf_evt_ocrd_dt,
3292             l_ler_id,
3293             l_mgr_person_id_out,
3294             l_mgr_pel);
3295         if g_debug then
3296           hr_utility.set_location('After Mgr l_mgr_person_id '||l_mgr_person_id,20);
3297           hr_utility.set_location('After Mgr l_mgr_person_id_out '||l_mgr_person_id_out,20);
3298           hr_utility.set_location('After Mgr l_mgr_pel '||l_mgr_pel,30);
3299         end if;
3300         --
3301         if l_mgr_pel is not null then
3302           --
3303           insert_mgr_hrchy(l_emp_pel,l_mgr_pel,l_level);
3304           --
3305         end if;
3306         --
3307         exit mgr_loop when (l_mgr_person_id = l_mgr_person_id_out
3308                             OR l_mgr_person_id_out is null ) ;
3309         --call to insert routne
3310         if g_debug then
3311           hr_utility.set_location('Emp EPE '||l_emp_pel , 20);
3312           hr_utility.set_location('Mgr EPE '||l_mgr_pel , 30);
3313           hr_utility.set_location('Level   '||l_level   , 40);
3314         end if;
3315         --
3316         -- insert_mgr_hrchy(l_emp_pel,l_mgr_pel,l_level);
3317         --
3318         --after call to insert routine
3319         --
3320         l_mgr_person_id := l_mgr_person_id_out ;
3321         l_level         := l_level + 1 ;
3322         l_mgr_pel       := null ;
3323         --
3324       end loop mgr_loop;
3325     --
3326     fetch c_pel into l_emp_pel,l_mgr_person_id ;
3327     --
3328     if c_pel%found then
3329       --
3330       open c_pl_ler(l_emp_pel);
3331       fetch c_pl_ler into l_pl_id, l_lf_evt_ocrd_dt, l_ler_id, l_business_group_id ;
3332       close c_pl_ler ;
3333       --
3334     end if;
3335     --
3336     if g_debug then
3337       hr_utility.set_location(' End of mgr_loop ',99);
3338     end if;
3339   end loop pel ;
3340   --
3341   close c_pel ;
3342   --
3343   --call to delete the intial pel records
3344   if g_debug then
3345     hr_utility.set_location('Before call to delete_init_pel',10);
3346   end if;
3347   update_init_pel(lv_pl_id, lv_lf_evt_ocrd_dt) ;
3348   if g_debug then
3349     hr_utility.set_location('After  call to delete_init_pel',10);
3350   end if;
3351   --
3352   -- CWB 2712602 : Delete all the hrchy data linked to backed out per in ler.
3353   --
3354   delete from ben_cwb_hrchy
3355   where emp_pil_elctbl_chc_popl_id in (
3356      select pel.pil_elctbl_chc_popl_id
3357      from ben_pil_elctbl_chc_popl pel,
3358           ben_per_in_ler pil
3359      where pel.pl_id = lv_pl_id
3360        and pil.lf_evt_ocrd_dt = lv_lf_evt_ocrd_dt
3361        and pil.per_in_ler_id  = pel.per_in_ler_id
3362        and pil.per_in_ler_stat_cd = 'BCKDT');
3363   --
3364   delete from ben_cwb_hrchy
3365   where mgr_pil_elctbl_chc_popl_id in (
3366      select pel.pil_elctbl_chc_popl_id
3367      from ben_pil_elctbl_chc_popl pel,
3368           ben_per_in_ler pil
3369      where pel.pl_id = lv_pl_id
3370        and pil.lf_evt_ocrd_dt = lv_lf_evt_ocrd_dt
3371        and pil.per_in_ler_id  = pel.per_in_ler_id
3372        and pil.per_in_ler_stat_cd = 'BCKDT');
3373   --
3374   -- After testing on hrcwbdvl uncomment the code.
3375   --
3376   -- Bug 2288042
3377   -- Create 0 level heirarchy data for managers for whom this data
3378   -- is missing.
3379   --
3380   for l_no_0_hrchy in  c_no_0_hrchy(lv_pl_id, lv_lf_evt_ocrd_dt, lv_business_group_id) loop
3381       --
3382       begin
3383         --
3384         insert into ben_cwb_hrchy (
3385           emp_pil_elctbl_chc_popl_id,
3386           mgr_pil_elctbl_chc_popl_id,
3387           lvl_num  )
3388         values (
3389           l_no_0_hrchy.mgr_pil_elctbl_chc_popl_id,
3390           l_no_0_hrchy.mgr_pil_elctbl_chc_popl_id,
3391           0 );
3392         --
3393       exception when others then
3394         null;
3395       end;
3396       --
3397   end loop;
3398   if g_debug then
3399     hr_utility.set_location('Leaving: '||l_proc,10);
3400   end if;
3401   --
3402 end popu_pel_heir;
3403 --
3404 --
3405 -- CWB Procedure for population of the CWB Hierarchy table
3406 --
3407 /*
3408 procedure popu_epe_heir is
3409   --
3410   l_proc         VARCHAR2(80);
3411   l_level        number             := 1 ;
3412   l_emp_epe           number ;
3413   l_mgr_epe           number ;
3414   l_mgr_person_id     number ;
3415   l_mgr_person_id_out number ;
3416   l_business_group_id number ;
3417   l_pl_id             number;
3418   l_lf_evt_ocrd_dt    date;
3419   l_ler_id            number;
3420   l_rec             benutils.g_batch_param_rec;
3421   lv_pl_id          number;
3422   lv_business_group_id number;
3423   lv_ler_id            number;
3424   lv_lf_evt_ocrd_dt date;
3425   --
3426   -- Bug 2288042 : Create 0 level heirarchy data if manager is
3427   -- is processed first and employee is processed later.
3428   --
3429   cursor c_no_0_hrchy(p_pl_id number,
3430                       p_lf_evt_ocrd_dt date,
3431                       p_business_group_id number) is
3432   select unique epe_0.mgr_elig_per_elctbl_chc_id
3433   from ben_cwb_mgr_hrchy epe_0,
3434      ben_elig_per_elctbl_chc mgr_epe_0,
3435      ben_per_in_ler pil_0
3436   where
3437       mgr_epe_0.elig_per_elctbl_chc_id = epe_0.mgr_elig_per_elctbl_chc_id
3438       and mgr_epe_0.per_in_ler_id = pil_0.per_in_ler_id
3439       and mgr_epe_0.pl_id         = p_pl_id
3440       and pil_0.lf_evt_ocrd_dt = p_lf_evt_ocrd_dt
3441       -- and pil_0.ler_id = p_ler_id
3442       and pil_0.business_group_id = p_business_group_id
3443       and pil_0.per_in_ler_stat_cd = 'STRTD'
3444   and epe_0.lvl_num > 0
3445   and epe_0.mgr_elig_per_elctbl_chc_id not in
3446   ( select mgr_epe.elig_per_elctbl_chc_id
3447     from ben_cwb_mgr_hrchy hrh,
3448          ben_elig_per_elctbl_chc mgr_epe,
3449          ben_per_in_ler pil
3450     where hrh.mgr_elig_per_elctbl_chc_id =
3451                         hrh.emp_elig_per_elctbl_chc_id
3452       and mgr_epe.elig_per_elctbl_chc_id = hrh.mgr_elig_per_elctbl_chc_id
3453       and hrh.lvl_num = 0
3454       and mgr_epe.per_in_ler_id = pil.per_in_ler_id
3455       and mgr_epe.pl_id         = p_pl_id
3456       and pil.lf_evt_ocrd_dt = p_lf_evt_ocrd_dt
3457       -- and pil.ler_id         = p_ler_id
3458       and pil.business_group_id = p_business_group_id
3459       and pil.per_in_ler_stat_cd = 'STRTD'
3460   );
3461   --
3462   -- Cursor to select the epe records for emp
3463   -- These are the records created initially with mgr_elig_per_elctbl_chc_id and
3464   -- lvl_num as '-1'
3465   --
3466   cursor c_epe(cv_pl_id number, cv_lf_evt_ocrd_dt date) is
3467     select
3468       cwb.emp_elig_per_elctbl_chc_id,
3469       epe.ws_mgr_id
3470     from
3471       ben_cwb_mgr_hrchy  cwb,
3472       ben_elig_per_elctbl_chc epe ,
3473       ben_per_in_ler pil
3474     where
3475           cwb.mgr_elig_per_elctbl_chc_id = -1
3476       and epe.elig_per_elctbl_chc_id = cwb.emp_elig_per_elctbl_chc_id
3477       --
3478       -- Bug 2541072 : Do not consider all per in ler's.
3479       --
3480       and epe.per_in_ler_id = pil.per_in_ler_id
3481       and pil.per_in_ler_stat_cd = 'STRTD'
3482       and ((cv_pl_id = -1 and cv_lf_evt_ocrd_dt = hr_api.g_eot)
3483             or
3484            (pil.lf_evt_ocrd_dt = cv_lf_evt_ocrd_dt and epe.pl_id = cv_pl_id)
3485           )
3486       and cwb.lvl_num = -1;
3487   --
3488   -- To get the pl_id, lf_evt_ocrd_dt, ler_id and business_group_id of the first records.
3489   -- This is the criteria used for finding the epe records in the hierarchy.
3490   --
3491   cursor c_pl_ler(p_elig_per_elctbl_chc_id number) is
3492     select
3493       epe.pl_id,
3494       pil.lf_evt_ocrd_dt,
3495       pil.ler_id,
3496       pil.business_group_id
3497     from
3498       ben_elig_per_elctbl_chc epe,
3499       ben_per_in_ler pil
3500     where
3501        epe.per_in_ler_id = pil.per_in_ler_id
3502    and epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
3503    and pil.per_in_ler_stat_cd = 'STRTD';
3504   --
3505   -- This private procedure determines the Manager epe
3506   -- This will get the manager epe record for a given emp - cascading
3507   procedure mgr( p_person_id number,
3508                 p_business_group_id number,
3509                 p_pl_id number,
3510                 p_lf_evt_ocrd_dt date,
3511                 p_ler_id number,
3512                 p_ws_mgr_id out nocopy number,
3513                 p_elig_per_elctbl_chc_id out nocopy number ) is
3514     --
3515     cursor c_mgr(p_person_id number,
3516                  p_pl_id number,
3517                  p_lf_evt_ocrd_dt date,
3518                  p_ler_id number,
3519                  p_business_group_id number) is
3520       select epe.ws_mgr_id,
3521              epe.elig_per_elctbl_chc_id
3522       from ben_elig_per_elctbl_chc epe,
3523            ben_per_in_ler pil
3524       where epe.per_in_ler_id = pil.per_in_ler_id
3525       and   epe.pl_id         = p_pl_id
3526       and   pil.lf_evt_ocrd_dt = p_lf_evt_ocrd_dt
3527       and   pil.ler_id        = p_ler_id
3528       and   pil.person_id     = p_person_id
3529       and   pil.business_group_id = p_business_group_id
3530       and   pil.per_in_ler_stat_cd = 'STRTD';
3531     --
3532   l_ws_mgr_id number := null ;
3533   l_elig_per_elctbl_chc_id number := null ;
3534   begin
3535     --
3536     if g_debug then
3537       hr_utility.set_location('MGR p_person_id '||p_person_id,22);
3538       hr_utility.set_location('MGR p_business_group_id '||p_business_group_id,23);
3539     end if;
3540     --
3541     open c_mgr (p_person_id,p_pl_id,p_lf_evt_ocrd_dt,p_ler_id,p_business_group_id);
3542     fetch c_mgr into l_ws_mgr_id,l_elig_per_elctbl_chc_id ;
3543     close c_mgr ;
3544     --
3545     if g_debug then
3546       hr_utility.set_location('MGR OUT  l_elig_per_elctbl_chc_id '||l_elig_per_elctbl_chc_id,30);
3547       hr_utility.set_location('MGR OUT  l_ws_mgr_id '||l_ws_mgr_id,40);
3548     end if;
3549     --
3550     p_elig_per_elctbl_chc_id := l_elig_per_elctbl_chc_id ;
3551     p_ws_mgr_id := l_ws_mgr_id ;
3552   end;
3553   --
3554   -- This procedure inserts records into hierarchy table
3555   --
3556   procedure insert_mgr_hrchy ( p_emp_elig_per_elctbl_chc_id number,
3557                                p_mgr_elig_per_elctbl_chc_id number,
3558                                p_lvl_num number ) is
3559   begin
3560     --
3561     if g_debug then
3562       hr_utility.set_location('insert_mgr_hrchy p_emp_elig_per_elctbl_chc_id '
3563                                      ||p_emp_elig_per_elctbl_chc_id,10);
3564       hr_utility.set_location('insert_mgr_hrchy p_mgr_elig_per_elctbl_chc_id '
3565                                      ||p_mgr_elig_per_elctbl_chc_id || ' lvl = ' || p_lvl_num, 20);
3566     end if;
3567     insert into ben_cwb_mgr_hrchy (
3568           emp_elig_per_elctbl_chc_id,
3569           mgr_elig_per_elctbl_chc_id,
3570           lvl_num  )
3571     values (
3572           p_emp_elig_per_elctbl_chc_id,
3573           p_mgr_elig_per_elctbl_chc_id,
3574           p_lvl_num );
3575     --
3576   exception when others then
3577     --
3578     raise;
3579     --
3580   end insert_mgr_hrchy;
3581   --
3582   procedure update_init_epe(cv_pl_id number, cv_lf_evt_ocrd_dt date)  is
3583     begin
3584       --
3585       -- Also delete the rows for employees who do not have
3586       -- subordinates and with level -1 .
3587       -- And also the last subordinate is now reporting to another manager
3588       -- we need to delete the epe,0,0 row of the employee.
3589       --
3590       delete
3591       from ben_cwb_mgr_hrchy cwh
3592       where (( cwh.lvl_num = -1
3593               and cwh.mgr_elig_per_elctbl_chc_id = -1) OR
3594              ( cwh.lvl_num = 0 and
3595               cwh.mgr_elig_per_elctbl_chc_id = cwh.emp_elig_per_elctbl_chc_id ) )
3596         and not exists
3597         (select null
3598          from ben_cwb_mgr_hrchy cwh1
3599          where cwh1.mgr_elig_per_elctbl_chc_id = cwh.emp_elig_per_elctbl_chc_id
3600          and cwh1.lvl_num <> 0
3601         )
3602          --
3603          -- Bug 2541072 : Do not consider all per in ler's.
3604          --
3605         and exists
3606          (select null
3607           from ben_elig_per_elctbl_chc epe ,
3608                ben_per_in_ler pil
3609           where epe.elig_per_elctbl_chc_id = cwh.emp_elig_per_elctbl_chc_id
3610           and   epe.per_in_ler_id          = pil.per_in_ler_id
3611           and   pil.per_in_ler_stat_cd = 'STRTD'
3612           and ((cv_pl_id = -1 and cv_lf_evt_ocrd_dt = hr_api.g_eot)
3613                  or
3614                (pil.lf_evt_ocrd_dt = cv_lf_evt_ocrd_dt and epe.pl_id = cv_pl_id)
3615               )
3616          ) ;
3617       --
3618       update ben_cwb_mgr_hrchy cwh
3619        set cwh.mgr_elig_per_elctbl_chc_id = cwh.emp_elig_per_elctbl_chc_id,
3620            cwh.lvl_num = 0
3621        where cwh.lvl_num = -1 and
3622              cwh.mgr_elig_per_elctbl_chc_id = -1
3623          --
3624          -- Bug 2541072 : Do not consider all per in ler's.
3625          --
3626         and exists
3627          (select null
3628           from ben_elig_per_elctbl_chc epe ,
3629                ben_per_in_ler pil
3630           where epe.elig_per_elctbl_chc_id = cwh.emp_elig_per_elctbl_chc_id
3631           and   epe.per_in_ler_id          = pil.per_in_ler_id
3632           and   pil.per_in_ler_stat_cd = 'STRTD'
3633           and ((cv_pl_id = -1 and cv_lf_evt_ocrd_dt = hr_api.g_eot)
3634                  or
3635                (pil.lf_evt_ocrd_dt = cv_lf_evt_ocrd_dt and epe.pl_id = cv_pl_id)
3636               )
3637          ) ;
3638       --
3639     exception when others then
3640       raise ;
3641     end ;
3642   --
3643 begin
3644   --
3645   if g_debug then
3646     l_proc := g_package||  '.popu_epe_heir';
3647     hr_utility.set_location('Entering: '||l_proc,10);
3648   end if;
3649   --
3650   lv_pl_id := -1;
3651   lv_lf_evt_ocrd_dt := hr_api.g_eot;
3652   --
3653   if benutils.g_benefit_action_id is not null then
3654      --
3655      benutils.get_batch_parameters
3656       (p_benefit_action_id => benutils.g_benefit_action_id,
3657        p_rec               => l_rec);
3658      --
3659      lv_pl_id             := l_rec.pl_id;
3660      lv_lf_evt_ocrd_dt    := l_rec.lf_evt_ocrd_dt;
3661      lv_business_group_id := l_rec.business_group_id;
3662      lv_ler_id            := l_rec.ler_id;
3663      --
3664   -- Bug 2574791
3665   else
3666      --
3667      lv_pl_id             := g_rebuild_pl_id;
3668      lv_lf_evt_ocrd_dt    := g_rebuild_lf_evt_ocrd_dt;
3669      lv_business_group_id := g_rebuild_business_group_id;
3670      --
3671   end if;
3672   --
3673   if g_debug then
3674     hr_utility.set_location(l_proc || ' lv_pl_id = ' || lv_pl_id, 9876);
3675     hr_utility.set_location(l_proc || ' lv_lf_evt_ocrd_dt = ' || lv_lf_evt_ocrd_dt, 9876);
3676     hr_utility.set_location(l_proc || ' lv_business_group_id = ' || lv_business_group_id, 9876);
3677     hr_utility.set_location(l_proc || ' lv_ler_id = ' || lv_ler_id, 9876);
3678   end if;
3679   open c_epe(lv_pl_id, lv_lf_evt_ocrd_dt);
3680   fetch c_epe into l_emp_epe,l_mgr_person_id ;
3681   --
3682   if g_debug then
3683     hr_utility.set_location(' l_emp_epe '||l_emp_epe,99);
3684     hr_utility.set_location(' l_mgr_person_id '||l_mgr_person_id,99);
3685   end if;
3686   if c_epe%found then
3687     --
3688     open c_pl_ler(l_emp_epe);
3689     fetch c_pl_ler into l_pl_id, l_lf_evt_ocrd_dt, l_ler_id, l_business_group_id ;
3690     close c_pl_ler ;
3691     --
3692   end if;
3693   --
3694   if g_debug then
3695     hr_utility.set_location(' l_pl_id '||l_pl_id,99);
3696     hr_utility.set_location(' l_lf_evt_ocrd_dt '||l_lf_evt_ocrd_dt,99);
3697     hr_utility.set_location(' l_ler_id '||l_ler_id,99);
3698     hr_utility.set_location(' l_business_group_id '||l_business_group_id,99);
3699   end if;
3700   <<epe>>
3701   loop
3702     --
3703     exit epe when c_epe%notfound ;
3704     l_level := 1 ;
3705       --
3706       <<mgr_loop>>
3707       loop
3708         --
3709         if g_debug then
3710           hr_utility.set_location('Before mgr l_mgr_person_id '||l_mgr_person_id,10);
3711         end if;
3712         mgr(l_mgr_person_id,
3713             l_business_group_id,
3714             l_pl_id,
3715             l_lf_evt_ocrd_dt,
3716             l_ler_id,
3717             l_mgr_person_id_out,
3718             l_mgr_epe);
3719         if g_debug then
3720           hr_utility.set_location('After Mgr l_mgr_person_id '||l_mgr_person_id,20);
3721           hr_utility.set_location('After Mgr l_mgr_person_id_out '||l_mgr_person_id_out,20);
3722           hr_utility.set_location('After Mgr l_mgr_epe '||l_mgr_epe,30);
3723         end if;
3724         --
3725         if l_mgr_epe is not null then
3726           --
3727           insert_mgr_hrchy(l_emp_epe,l_mgr_epe,l_level);
3728           --
3729         end if;
3730         --
3731         exit mgr_loop when (l_mgr_person_id = l_mgr_person_id_out
3732                             OR l_mgr_person_id_out is null ) ;
3733         --call to insert routne
3734         if g_debug then
3735           hr_utility.set_location('Emp EPE '||l_emp_epe , 20);
3736           hr_utility.set_location('Mgr EPE '||l_mgr_epe , 30);
3737           hr_utility.set_location('Level   '||l_level   , 40);
3738         end if;
3739         --
3740         -- insert_mgr_hrchy(l_emp_epe,l_mgr_epe,l_level);
3741         --
3742         --after call to insert routine
3743         --
3744         l_mgr_person_id := l_mgr_person_id_out ;
3745         l_level         := l_level + 1 ;
3746         l_mgr_epe       := null ;
3747         --
3748       end loop mgr_loop;
3749     --
3750     fetch c_epe into l_emp_epe,l_mgr_person_id ;
3751     --
3752     if c_epe%found then
3753       --
3754       open c_pl_ler(l_emp_epe);
3755       fetch c_pl_ler into l_pl_id, l_lf_evt_ocrd_dt, l_ler_id, l_business_group_id ;
3756       close c_pl_ler ;
3757       --
3758     end if;
3759     --
3760     if g_debug then
3761       hr_utility.set_location(' End of mgr_loop ',99);
3762     end if;
3763   end loop epe ;
3764   --
3765   close c_epe ;
3766   --
3767   --call to delete the intial epe records
3768   if g_debug then
3769     hr_utility.set_location('Before call to delete_init_epe',10);
3770   end if;
3771   update_init_epe(lv_pl_id, lv_lf_evt_ocrd_dt) ;
3772   if g_debug then
3773     hr_utility.set_location('After  call to delete_init_epe',10);
3774   end if;
3775   -- After testing on hrcwbdvl uncomment the code.
3776   --
3777   -- Bug 2288042
3778   -- Create 0 level heirarchy data for managers for whom this data
3779   -- is missing.
3780   --
3781   for l_no_0_hrchy in  c_no_0_hrchy(lv_pl_id, lv_lf_evt_ocrd_dt, lv_business_group_id) loop
3782       --
3783       begin
3784         --
3785         insert into ben_cwb_mgr_hrchy (
3786           emp_elig_per_elctbl_chc_id,
3787           mgr_elig_per_elctbl_chc_id,
3788           lvl_num  )
3789         values (
3790           l_no_0_hrchy.mgr_elig_per_elctbl_chc_id,
3791           l_no_0_hrchy.mgr_elig_per_elctbl_chc_id,
3792           0 );
3793         --
3794       exception when others then
3795         null;
3796       end;
3797       --
3798   end loop;
3799   if g_debug then
3800     hr_utility.set_location('Leaving: '||l_proc,10);
3801   end if;
3802   --
3803 end popu_epe_heir;
3804 --
3805 */
3806 procedure popu_cross_gb_epe_pel_data(
3807          p_mode                     in varchar2,
3808          p_person_id                in number,
3809          p_business_group_id        in number,
3810          p_ler_id                   in number,
3811          p_pl_id                    in number,
3812          p_effective_date           in date,
3813          p_lf_evt_ocrd_dt           in date
3814 ) is
3815  --
3816  l_package varchar2(80);
3817  --
3818  l_rec                        benutils.g_active_life_event;
3819  l_mgr_rec                    benutils.g_active_life_event;
3820  l_mgr_rec_temp               benutils.g_active_life_event;
3821  l_effective_date             date := nvl(p_lf_evt_ocrd_dt, p_effective_date);
3822  l_procd_dt                   date;
3823  l_strtd_dt                   date;
3824  l_voidd_dt                   date;
3825  l_ptnl_ler_for_per_id        number;
3826  l_object_version_number      number;
3827  l_dummy_per_in_ler_id        number;
3828  l_mgr_per_in_ler_not_found   boolean;
3829  l_mgr_person_id              number;
3830  l_mgr_person_id_temp         number;
3831  l_assignment_id              number;
3832  l_elig_per_elctbl_chc_id     number;
3833  --
3834  l_created_by                 ben_elig_per_elctbl_chc.created_by%TYPE;
3835  l_creation_date              ben_elig_per_elctbl_chc.creation_date%TYPE;
3836  l_last_update_date           ben_elig_per_elctbl_chc.last_update_date%TYPE;
3837  l_last_updated_by            ben_elig_per_elctbl_chc.last_updated_by%TYPE;
3838  l_last_update_login          ben_elig_per_elctbl_chc.last_update_login%TYPE;
3839  -- CWBITEM
3840  l_emp_pel_id                 number;
3841  l_pel_id                     number;
3842  --
3843  -- 9999 Why not use the pl_id, so that the data from the
3844  -- other conc program will not be picked up.
3845  --
3846  cursor c_pel(cv_per_in_ler_id in number) is
3847   select pel.dflt_enrt_dt,
3848          pel.cls_enrt_dt_to_use_cd,
3849          pel.enrt_typ_cycl_cd,
3850          pel.enrt_perd_strt_dt,
3851          pel.enrt_perd_end_dt,
3852          pel.lee_rsn_id,
3853          pel.enrt_perd_id,
3854          pel.uom,
3855          pel.acty_ref_perd_cd,
3856          pel.business_group_id per_business_group_id,
3857          per.business_group_id mgr_business_group_id,
3858          pel.ws_mgr_id
3859   from   ben_pil_elctbl_chc_popl pel,
3860          per_all_people_f per
3861   where  pel.per_in_ler_id = cv_per_in_ler_id
3862     and  pel.ws_mgr_id     = per.person_id (+)
3863     and  l_effective_date between effective_start_date
3864                               and effective_end_date;
3865  --
3866  cursor c_epe(cv_per_in_ler_id in number) is
3867   select epe.* ,
3868          pel.dflt_enrt_dt,
3869          pel.cls_enrt_dt_to_use_cd,
3870          pel.enrt_typ_cycl_cd,
3871          pel.enrt_perd_strt_dt,
3872          pel.enrt_perd_end_dt,
3873          pel.lee_rsn_id,
3874          pel.enrt_perd_id,
3875          pel.uom,
3876          pel.acty_ref_perd_cd,
3877          epe.business_group_id per_business_group_id,
3878          per.business_group_id mgr_business_group_id
3879   from   ben_elig_per_elctbl_chc epe,
3880          ben_pil_elctbl_chc_popl pel,
3881          per_all_people_f per
3882   where  epe.per_in_ler_id = cv_per_in_ler_id
3883     and  epe.per_in_ler_id = pel.per_in_ler_id
3884     and  epe.pl_id         = pel.pl_id
3885     and  epe.ws_mgr_id     = per.person_id (+)
3886     and  l_effective_date between effective_start_date
3887                               and effective_end_date;
3888  --
3889  cursor c_ecr(cv_elig_per_elctbl_chc_id in number) is
3890    select ecr.*
3891    from ben_enrt_rt ecr
3892    where ecr.elig_per_elctbl_chc_id = cv_elig_per_elctbl_chc_id;
3893  --
3894  l_curr_pel c_pel%rowtype;
3895  l_curr_epe c_epe%rowtype;
3896  --
3897  -- Gets the enrolment information for this plan
3898  --
3899  CURSOR c_plan_enrolment_info(cv_person_id in number,
3900                               cv_business_group_id in number,
3901                               cv_lf_evt_ocrd_dt    in date,
3902                               cv_pl_id             in number,
3903                               cv_pgm_id            in number)
3904  IS
3905       SELECT   pen.prtt_enrt_rslt_id
3906       FROM     ben_prtt_enrt_rslt_f pen
3907       WHERE    pen.person_id         = cv_person_id
3908       AND      pen.business_group_id = cv_business_group_id
3909       AND      pen.sspndd_flag       = 'N'
3910       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
3911       AND      pen.effective_end_date = hr_api.g_eot
3912       AND      cv_lf_evt_ocrd_dt <= pen.enrt_cvg_thru_dt
3913       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
3914       AND      cv_pl_id = pen.pl_id
3915       AND      (
3916                     (    pen.pgm_id = cv_pgm_id
3917                      AND cv_pgm_id IS NOT NULL)
3918                  OR (    pen.pgm_id IS NULL
3919                      AND cv_pgm_id IS NULL));
3920  --
3921  l_prtt_enrt_rslt_id number := null;
3922  --
3923  l_emp_epe_id   number;
3924  --
3925  cursor c_cwb_hrchy(cv_emp_epe_id in number) is
3926    select emp_elig_per_elctbl_chc_id
3927    from ben_cwb_mgr_hrchy
3928    where emp_elig_per_elctbl_chc_id = cv_emp_epe_id;
3929   --
3930   cursor c_hrchy(cv_emp_epe_id in number) is
3931    select hrc.emp_pil_elctbl_chc_popl_id,
3932           epe.pil_elctbl_chc_popl_id
3933    from ben_elig_per_elctbl_chc epe,
3934         ben_cwb_hrchy hrc
3935    where epe.elig_per_elctbl_chc_id = cv_emp_epe_id
3936      and hrc.emp_pil_elctbl_chc_popl_id(+) = epe.pil_elctbl_chc_popl_id;
3937   --
3938 begin
3939  --
3940  if g_debug then
3941    l_package := g_package||'.popu_cross_gb_epe_data';
3942    hr_utility.set_location ('Entering '||l_package,10);
3943  end if;
3944  --
3945  benutils.get_active_life_event
3946    (p_person_id         => p_person_id,
3947    p_business_group_id => p_business_group_id,
3948    p_effective_date    => p_effective_date,
3949    p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
3950    p_ler_id            => p_ler_id,
3951    p_rec               => l_rec);
3952  --
3953  -- Get the manager information.
3954  --
3955  open c_pel(l_rec.per_in_ler_id);
3956  fetch c_pel into l_curr_pel;
3957  close c_pel;
3958  --
3959  -- Now loop through the manager heirarchy and duplicate the data.
3960  --
3961  l_mgr_per_in_ler_not_found := true;
3962  l_mgr_person_id            := l_curr_pel.ws_mgr_id;
3963  --
3964  while l_mgr_per_in_ler_not_found loop
3965    --
3966    -- Get per in ler for manager in per_business_group_id.
3967    --
3968    l_mgr_rec       := l_mgr_rec_temp;
3969    --
3970    benutils.get_active_life_event
3971        (p_person_id         => l_mgr_person_id,
3972         p_business_group_id => l_curr_pel.per_business_group_id,
3973         p_effective_date    => p_effective_date,
3974         p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
3975         p_ler_id            => p_ler_id,
3976         p_rec               => l_mgr_rec);
3977    --
3978    if l_mgr_rec.per_in_ler_id is not null  or l_mgr_person_id is null then
3979          l_mgr_per_in_ler_not_found := false;
3980    else
3981      --
3982      -- Now duplicate the pil, pel, epe, ecr data.
3983      --
3984      l_mgr_per_in_ler_not_found := true;
3985      --
3986      -- Need to copy potential ler for per.
3987      --
3988      ben_ptnl_ler_for_per_api.create_ptnl_ler_for_per_perf
3989            (p_validate                 => false,
3990             p_ptnl_ler_for_per_id      => l_ptnl_ler_for_per_id,
3991             p_lf_evt_ocrd_dt           => l_effective_date,
3992             p_ptnl_ler_for_per_stat_cd => 'PROCD' ,
3993                                           --l_ptnl_ler_for_per_stat_cd_use,
3994             p_ler_id                   => p_ler_id,
3995             p_person_id                => l_mgr_person_id,
3996             p_ntfn_dt                  => p_effective_date, -- l_ntfn_dt,
3997             p_procd_dt                 => p_effective_date,
3998             p_dtctd_dt                 => p_effective_date,
3999             p_business_group_id        => l_curr_pel.per_business_group_id,
4000             p_object_version_number    => l_object_version_number,
4001             p_effective_date           => l_effective_date,
4002             p_program_application_id   => fnd_global.prog_appl_id,
4003             p_program_id               => fnd_global.conc_program_id,
4004             p_request_id               => fnd_global.conc_request_id,
4005             p_program_update_date      => l_effective_date);
4006      --
4007      ben_Person_Life_Event_api.create_Person_Life_Event_perf
4008            (p_validate                => false
4009            ,p_per_in_ler_id           => l_dummy_per_in_ler_id
4010            ,p_ler_id                  => p_ler_id
4011            ,p_person_id               => l_mgr_person_id
4012            ,p_per_in_ler_stat_cd      => 'STRTD'
4013            ,p_ptnl_ler_for_per_id     => l_ptnl_ler_for_per_id
4014            ,p_lf_evt_ocrd_dt          => p_lf_evt_ocrd_dt
4015            ,p_business_group_id       => l_curr_pel.per_business_group_id
4016            ,p_ntfn_dt                 => trunc(sysdate)
4017            ,p_object_version_number   => l_object_version_number
4018            ,p_effective_date          => l_effective_date
4019            ,p_program_application_id  => fnd_global.prog_appl_id
4020            ,p_program_id              => fnd_global.conc_program_id
4021            ,p_request_id              => fnd_global.conc_request_id
4022            ,p_program_update_date     => trunc(sysdate)
4023            ,p_procd_dt                => l_procd_dt
4024            ,p_strtd_dt                => l_strtd_dt
4025            ,p_voidd_dt                => l_voidd_dt);
4026      --
4027      --
4028      -- Now get the manager for l_mgr_person_id.
4029      --
4030      -- But 2172036 addition of assignment_id to epe
4031      --
4032      ben_enrolment_requirements.get_cwb_manager_and_assignment(
4033              p_person_id                => l_mgr_person_id,
4034              p_hrchy_to_use_cd          =>
4035                   ben_enrolment_requirements.g_ple_hrchy_to_use_cd,
4036              p_pos_structure_version_id =>
4037                   ben_enrolment_requirements.g_ple_pos_structure_version_id,
4038              p_effective_date            => l_effective_date,
4039              p_manager_id                => l_mgr_person_id_temp,
4040              p_assignment_id             => l_assignment_id );
4041      --
4042      l_prtt_enrt_rslt_id  := null;
4043      --
4044      -- Now loop through all the epe's associated with current pel and
4045      -- duplicate the data.
4046      --
4047      for l_curr_epe in c_epe(l_rec.per_in_ler_id) loop
4048          --
4049          if g_debug then
4050            hr_utility.set_location('EPEC_CRE: Cross BG ' || l_package, 10);
4051          end if;
4052          ben_elig_per_elc_chc_api.create_perf_elig_per_elc_chc(
4053            p_elig_per_elctbl_chc_id => l_elig_per_elctbl_chc_id,
4054            p_business_group_id      => l_curr_epe.per_business_group_id,
4055            p_auto_enrt_flag         => l_curr_epe.auto_enrt_flag,
4056            p_per_in_ler_id          => l_dummy_per_in_ler_id,
4057            p_yr_perd_id             => l_curr_epe.yr_perd_id,
4058            p_pl_id                  => l_curr_epe.pl_id,
4059            p_pl_typ_id              => l_curr_epe.pl_typ_id,
4060            p_oipl_id                => l_curr_epe.oipl_id,
4061            p_pgm_id                 => l_curr_epe.pgm_id,
4062            -- p_pgm_typ_cd             => l_curr_epe.pgm_typ_cd,
4063            p_must_enrl_anthr_pl_id  => l_curr_epe.must_enrl_anthr_pl_id,
4064            p_plip_id                => l_curr_epe.plip_id,
4065            p_ptip_id                => l_curr_epe.ptip_id,
4066            -- As per CWB team l_prtt_enrt_rslt_id can go as null.
4067            p_prtt_enrt_rslt_id      => l_prtt_enrt_rslt_id,
4068            --
4069            p_enrt_typ_cycl_cd       => l_curr_epe.enrt_typ_cycl_cd,
4070            p_comp_lvl_cd            => l_curr_epe.comp_lvl_cd,
4071            p_enrt_cvg_strt_dt_cd    => l_curr_epe.enrt_cvg_strt_dt_cd,
4072            p_enrt_perd_end_dt       => l_curr_epe.enrt_perd_end_dt,
4073            p_enrt_perd_strt_dt      => l_curr_epe.enrt_perd_strt_dt,
4074            p_enrt_cvg_strt_dt_rl    => l_curr_epe.enrt_cvg_strt_dt_rl,
4075            p_roll_crs_flag          => 'N',
4076            p_ctfn_rqd_flag          => l_curr_epe.ctfn_rqd_flag,
4077            p_crntly_enrd_flag       => 'N',-- l_curr_epe.crntly_enrd_flag,
4078            p_dflt_flag              => l_curr_epe.dflt_flag,
4079            p_elctbl_flag            => 'N',-- l_curr_epe.elctbl_flag,
4080            p_mndtry_flag            => l_curr_epe.mndtry_flag,
4081            p_dflt_enrt_dt           => l_curr_epe.dflt_enrt_dt,
4082            p_dpnt_cvg_strt_dt_cd    => NULL,
4083            p_dpnt_cvg_strt_dt_rl    => NULL,
4084            p_enrt_cvg_strt_dt       => l_curr_epe.enrt_cvg_strt_dt,
4085            p_alws_dpnt_dsgn_flag    => 'N',
4086            p_erlst_deenrt_dt        => l_curr_epe.erlst_deenrt_dt,
4087            p_procg_end_dt           => l_curr_epe.procg_end_dt,
4088            p_pl_ordr_num            => l_curr_epe.pl_ordr_num,
4089            p_plip_ordr_num          => l_curr_epe.plip_ordr_num,
4090            p_ptip_ordr_num          => l_curr_epe.ptip_ordr_num,
4091            p_oipl_ordr_num          => l_curr_epe.oipl_ordr_num,
4092            p_object_version_number  => l_object_version_number,
4093            p_effective_date         => l_effective_date,
4094            p_program_application_id => fnd_global.prog_appl_id,
4095            p_program_id             => fnd_global.conc_program_id,
4096            p_request_id             => fnd_global.conc_request_id,
4097            p_program_update_date    => trunc(SYSDATE),
4098            p_enrt_perd_id           => l_curr_epe.enrt_perd_id,
4099            p_lee_rsn_id             => l_curr_epe.lee_rsn_id,
4100            p_cls_enrt_dt_to_use_cd  => l_curr_epe.cls_enrt_dt_to_use_cd,
4101            p_uom                    => l_curr_epe.uom,
4102            p_acty_ref_perd_cd       => l_curr_epe.acty_ref_perd_cd,
4103            p_cryfwd_elig_dpnt_cd    => l_curr_epe.cryfwd_elig_dpnt_cd,
4104            -- added for cwb
4105            p_mode                   => p_mode,
4106            p_ws_mgr_id              => l_mgr_person_id_temp,
4107            p_elig_flag              => 'N',
4108            p_assignment_id          => l_assignment_id  ); -- l_curr_epe.elig_flag);
4109          -- Bug 2172036 and 2231371 added assignment_id in the above call
4110          --
4111          -- Populate the heirarchy table.
4112          --
4113          open c_hrchy(l_elig_per_elctbl_chc_id);
4114          fetch c_hrchy into l_emp_pel_id, l_pel_id;
4115          --
4116          if l_pel_id is not null and l_emp_pel_id is null then
4117             --
4118             begin
4119               insert into ben_cwb_hrchy (
4120                emp_pil_elctbl_chc_popl_id,
4121                mgr_pil_elctbl_chc_popl_id,
4122                lvl_num  )
4123               values(
4124                l_pel_id,
4125                -1,
4126                -1);
4127             exception
4128               when others then
4129                    null; -- For 2712602
4130             end;
4131             --
4132          end if;
4133          --
4134          close c_hrchy;
4135          --
4136          if g_debug then
4137            hr_utility.set_location('Done EPEC_CRE Cross BG : ' || l_package, 10);
4138          end if;
4139          --
4140          for l_ecr_rec in c_ecr(l_curr_epe.elig_per_elctbl_chc_id)
4141          loop
4142             --
4143                   INSERT INTO ben_enrt_rt
4144                   (
4145                     enrt_rt_id,
4146                     acty_typ_cd,
4147                     tx_typ_cd,
4148                     ctfn_rqd_flag,
4149                     dflt_flag,
4150                     dflt_pndg_ctfn_flag,
4151                     dsply_on_enrt_flag,
4152                     use_to_calc_net_flx_cr_flag,
4153                     entr_val_at_enrt_flag,
4154                     asn_on_enrt_flag,
4155                     rl_crs_only_flag,
4156                     dflt_val,
4157                     ann_val,
4158                     ann_mn_elcn_val,
4159                     ann_mx_elcn_val,
4160                     val,
4161                     ISS_VAL,
4162                     nnmntry_uom,
4163                     mx_elcn_val,
4164                     mn_elcn_val,
4165                     incrmt_elcn_val,
4166                     cmcd_acty_ref_perd_cd,
4167                     cmcd_mn_elcn_val,
4168                     cmcd_mx_elcn_val,
4169                     cmcd_val,
4170                     cmcd_dflt_val,
4171                     rt_usg_cd,
4172                     ann_dflt_val,
4173                     bnft_rt_typ_cd,
4174                     rt_mlt_cd,
4175                     dsply_mn_elcn_val,
4176                     dsply_mx_elcn_val,
4177                     entr_ann_val_flag,
4178                     rt_strt_dt,
4179                     rt_strt_dt_cd,
4180                     rt_strt_dt_rl,
4181                     rt_typ_cd,
4182                     elig_per_elctbl_chc_id,
4183                     acty_base_rt_id,
4184                     spcl_rt_enrt_rt_id,
4185                     enrt_bnft_id,
4186                     prtt_rt_val_id,
4187                     decr_bnft_prvdr_pool_id,
4188                     cvg_amt_calc_mthd_id,
4189                     actl_prem_id,
4190                     comp_lvl_fctr_id,
4191                     ptd_comp_lvl_fctr_id,
4192                     clm_comp_lvl_fctr_id,
4193                     business_group_id,
4194                     ecr_attribute_category,
4195                     ecr_attribute1,
4196                     ecr_attribute2,
4197                     ecr_attribute3,
4198                     ecr_attribute4,
4199                     ecr_attribute5,
4200                     ecr_attribute6,
4201                     ecr_attribute7,
4202                     ecr_attribute8,
4203                     ecr_attribute9,
4204                     ecr_attribute10,
4205                     ecr_attribute11,
4206                     ecr_attribute12,
4207                     ecr_attribute13,
4208                     ecr_attribute14,
4209                     ecr_attribute15,
4210                     ecr_attribute16,
4211                     ecr_attribute17,
4212                     ecr_attribute18,
4213                     ecr_attribute19,
4214                     ecr_attribute20,
4215                     ecr_attribute21,
4216                     ecr_attribute22,
4217                     ecr_attribute23,
4218                     ecr_attribute24,
4219                     ecr_attribute25,
4220                     ecr_attribute26,
4221                     ecr_attribute27,
4222                     ecr_attribute28,
4223                     ecr_attribute29,
4224                     ecr_attribute30,
4225                     last_update_login,
4226                     created_by,
4227                     creation_date,
4228                     last_updated_by,
4229                     last_update_date,
4230                     request_id,
4231                     program_application_id,
4232                     program_id,
4233                     program_update_date,
4234                     object_version_number)
4235            VALUES(
4236              ben_enrt_rt_s.nextval,
4237              l_ecr_rec.acty_typ_cd,
4238              l_ecr_rec.tx_typ_cd,
4239              l_ecr_rec.ctfn_rqd_flag,
4240              l_ecr_rec.dflt_flag,
4241              l_ecr_rec.dflt_pndg_ctfn_flag,
4242              l_ecr_rec.dsply_on_enrt_flag,
4243              l_ecr_rec.use_to_calc_net_flx_cr_flag,
4244              l_ecr_rec.entr_val_at_enrt_flag,
4245              l_ecr_rec.asn_on_enrt_flag,
4246              l_ecr_rec.rl_crs_only_flag,
4247              l_ecr_rec.dflt_val,
4248              l_ecr_rec.ann_val,
4249              l_ecr_rec.ann_mn_elcn_val,
4250              l_ecr_rec.ann_mx_elcn_val,
4251              l_ecr_rec.val,
4252              -- 3216667 : iss_val, mx_elcn_val, mn_elcn_val are passed to
4253              -- cloned rows.
4254              l_ecr_rec.ISS_VAL,
4255              l_ecr_rec.nnmntry_uom,
4256              -- Initially they have to go null.
4257              l_ecr_rec.mx_elcn_val,
4258              l_ecr_rec.mn_elcn_val,
4259              l_ecr_rec.incrmt_elcn_val,
4260              l_ecr_rec.cmcd_acty_ref_perd_cd,
4261              -- Initially they have to go null.
4262              null, --l_ecr_rec.cmcd_mn_elcn_val,
4263              null, --l_ecr_rec.cmcd_mx_elcn_val,
4264              l_ecr_rec.cmcd_val,
4265              null,
4266              l_ecr_rec.rt_usg_cd,
4267              l_ecr_rec.ann_dflt_val,
4268              l_ecr_rec.bnft_rt_typ_cd,
4269              l_ecr_rec.rt_mlt_cd,
4270              -- Initially they have to go null.
4271              null, -- l_ecr_rec.dsply_mn_elcn_val,
4272              null, -- l_ecr_rec.dsply_mx_elcn_val,
4273              l_ecr_rec.entr_ann_val_flag,
4274              l_ecr_rec.rt_strt_dt,
4275              l_ecr_rec.rt_strt_dt_cd,
4276              l_ecr_rec.rt_strt_dt_rl,
4277              l_ecr_rec.rt_typ_cd,
4278              l_elig_per_elctbl_chc_id,
4279              l_ecr_rec.acty_base_rt_id,
4280              null,
4281              null, -- enrt_bnft_id : Should be null
4282              null, -- prtt_rt_val_id : should be null
4283              l_ecr_rec.decr_bnft_prvdr_pool_id,
4284              l_ecr_rec.cvg_amt_calc_mthd_id,
4285              l_ecr_rec.actl_prem_id,
4286              l_ecr_rec.comp_lvl_fctr_id,
4287              l_ecr_rec.ptd_comp_lvl_fctr_id,
4288              l_ecr_rec.clm_comp_lvl_fctr_id,
4289              l_curr_epe.per_business_group_id,
4290              l_ecr_rec.ecr_attribute_category,
4291              l_ecr_rec.ecr_attribute1,
4292              l_ecr_rec.ecr_attribute2,
4293              l_ecr_rec.ecr_attribute3,
4294              l_ecr_rec.ecr_attribute4,
4295              l_ecr_rec.ecr_attribute5,
4296              l_ecr_rec.ecr_attribute6,
4297              l_ecr_rec.ecr_attribute7,
4298              l_ecr_rec.ecr_attribute8,
4299              l_ecr_rec.ecr_attribute9,
4300              l_ecr_rec.ecr_attribute10,
4301              l_ecr_rec.ecr_attribute11,
4302              l_ecr_rec.ecr_attribute12,
4303              l_ecr_rec.ecr_attribute13,
4304              l_ecr_rec.ecr_attribute14,
4305              l_ecr_rec.ecr_attribute15,
4306              l_ecr_rec.ecr_attribute16,
4307              l_ecr_rec.ecr_attribute17,
4308              l_ecr_rec.ecr_attribute18,
4309              l_ecr_rec.ecr_attribute19,
4310              l_ecr_rec.ecr_attribute20,
4311              l_ecr_rec.ecr_attribute21,
4312              l_ecr_rec.ecr_attribute22,
4313              l_ecr_rec.ecr_attribute23,
4314              l_ecr_rec.ecr_attribute24,
4315              l_ecr_rec.ecr_attribute25,
4316              l_ecr_rec.ecr_attribute26,
4317              l_ecr_rec.ecr_attribute27,
4318              l_ecr_rec.ecr_attribute28,
4319              l_ecr_rec.ecr_attribute29,
4320              l_ecr_rec.ecr_attribute30,
4321              l_last_update_login,
4322              l_created_by,
4323              l_creation_date,
4324              l_last_updated_by,
4325              trunc(SYSDATE),
4326              fnd_global.conc_request_id,
4327              fnd_global.prog_appl_id,
4328              fnd_global.conc_program_id,
4329              trunc(SYSDATE),
4330              l_object_version_number);
4331             --
4332          end loop; -- Rates for loop
4333          --
4334      end loop; -- epe for loop
4335      l_mgr_person_id          := l_mgr_person_id_temp;
4336      --
4337    end if;
4338    --
4339  end loop; -- while loop
4340  --
4341  if g_debug then
4342    hr_utility.set_location ('Leaving '||l_package,10);
4343  end if;
4344  --
4345 end popu_cross_gb_epe_pel_data;
4346 --
4347 /*
4348 procedure popu_cross_gb_epe_data(
4349          p_mode                     in varchar2,
4350          p_person_id                in number,
4351          p_business_group_id        in number,
4352          p_ler_id                   in number,
4353          p_pl_id                    in number,
4354          p_effective_date           in date,
4355          p_lf_evt_ocrd_dt           in date
4356 ) is
4357  --
4358  l_package               varchar2(80);
4359  --
4360  l_rec                        benutils.g_active_life_event;
4361  l_mgr_rec                    benutils.g_active_life_event;
4362  l_mgr_rec_temp               benutils.g_active_life_event;
4363  l_effective_date             date := nvl(p_lf_evt_ocrd_dt, p_effective_date);
4364  l_procd_dt                   date;
4365  l_strtd_dt                   date;
4366  l_voidd_dt                   date;
4367  l_ptnl_ler_for_per_id        number;
4368  l_object_version_number      number;
4369  l_dummy_per_in_ler_id        number;
4370  l_mgr_per_in_ler_not_found   boolean;
4371  l_mgr_person_id              number;
4372  l_mgr_person_id_temp         number;
4373  l_assignment_id              number;
4374  l_elig_per_elctbl_chc_id     number;
4375  --
4376  l_created_by             ben_elig_per_elctbl_chc.created_by%TYPE;
4377  l_creation_date          ben_elig_per_elctbl_chc.creation_date%TYPE;
4378  l_last_update_date       ben_elig_per_elctbl_chc.last_update_date%TYPE;
4379  l_last_updated_by        ben_elig_per_elctbl_chc.last_updated_by%TYPE;
4380  l_last_update_login      ben_elig_per_elctbl_chc.last_update_login%TYPE;
4381  --
4382  cursor c_epe(cv_per_in_ler_id in number) is
4383   select epe.* ,
4384          pel.dflt_enrt_dt,
4385          pel.cls_enrt_dt_to_use_cd,
4386          pel.enrt_typ_cycl_cd,
4387          pel.enrt_perd_strt_dt,
4388          pel.enrt_perd_end_dt,
4389          pel.lee_rsn_id,
4390          pel.enrt_perd_id,
4391          pel.uom,
4392          pel.acty_ref_perd_cd,
4393          epe.business_group_id per_business_group_id,
4394          per.business_group_id mgr_business_group_id
4395   from   ben_elig_per_elctbl_chc epe,
4396          ben_pil_elctbl_chc_popl pel,
4397          per_all_people_f per
4398   where  epe.per_in_ler_id = cv_per_in_ler_id
4399     and  epe.per_in_ler_id = pel.per_in_ler_id
4400     and  epe.pl_id         = pel.pl_id
4401     and  epe.ws_mgr_id     = per.person_id (+)
4402     and  l_effective_date between effective_start_date
4403                               and effective_end_date;
4404  --
4405  cursor c_ecr(cv_elig_per_elctbl_chc_id in number) is
4406    select ecr.*
4407    from ben_enrt_rt ecr
4408    where ecr.elig_per_elctbl_chc_id = cv_elig_per_elctbl_chc_id;
4409  --
4410  l_curr_epe c_epe%rowtype;
4411  --
4412  -- Gets the enrolment information for this plan
4413  --
4414  CURSOR c_plan_enrolment_info(cv_person_id in number,
4415                               cv_business_group_id in number,
4416                               cv_lf_evt_ocrd_dt    in date,
4417                               cv_pl_id             in number,
4418                               cv_pgm_id            in number)
4419  IS
4420       SELECT   pen.prtt_enrt_rslt_id
4421       FROM     ben_prtt_enrt_rslt_f pen
4422       WHERE    pen.person_id         = cv_person_id
4423       AND      pen.business_group_id = cv_business_group_id
4424       AND      pen.sspndd_flag       = 'N'
4425       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
4426       AND      pen.effective_end_date = hr_api.g_eot
4427       AND      cv_lf_evt_ocrd_dt <= pen.enrt_cvg_thru_dt
4428       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
4429       AND      cv_pl_id = pen.pl_id
4430       AND      (
4431                     (    pen.pgm_id = cv_pgm_id
4432                      AND cv_pgm_id IS NOT NULL)
4433                  OR (    pen.pgm_id IS NULL
4434                      AND cv_pgm_id IS NULL));
4435  --
4436  l_prtt_enrt_rslt_id number := null;
4437  --
4438  l_emp_epe_id   number;
4439  --
4440  cursor c_cwb_hrchy(cv_emp_epe_id in number) is
4441    select emp_elig_per_elctbl_chc_id
4442    from ben_cwb_mgr_hrchy
4443    where emp_elig_per_elctbl_chc_id = cv_emp_epe_id;
4444   --
4445 begin
4446  --
4447  if g_debug then
4448    l_package := g_package||'.popu_cross_gb_epe_data';
4449    hr_utility.set_location ('Entering '||l_package,10);
4450  end if;
4451  --
4452  benutils.get_active_life_event
4453    (p_person_id         => p_person_id,
4454    p_business_group_id => p_business_group_id,
4455    p_effective_date    => p_effective_date,
4456    p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
4457    p_ler_id            => p_ler_id,
4458    p_rec               => l_rec);
4459  --
4460  -- Get the manager information.
4461  --
4462  open c_epe(l_rec.per_in_ler_id);
4463  fetch c_epe into l_curr_epe;
4464  close c_epe;
4465  --
4466  -- Bug 2541072 for person selection rule dummy le is not created. We need to
4467  -- do this for same business group also.
4468  --
4469  -- if l_curr_epe.per_business_group_id <> l_curr_epe.mgr_business_group_id
4470  -- then
4471     --
4472     -- Now loop through the manager heirarchy and duplicate the data.
4473     --
4474     l_mgr_per_in_ler_not_found := true;
4475     l_mgr_person_id            := l_curr_epe.ws_mgr_id;
4476     --
4477     while l_mgr_per_in_ler_not_found loop
4478       --
4479       -- Get per in ler for manager in per_business_group_id.
4480       --
4481       l_mgr_rec       := l_mgr_rec_temp;
4482       --
4483       benutils.get_active_life_event
4484        (p_person_id         => l_mgr_person_id,
4485         p_business_group_id => l_curr_epe.per_business_group_id,
4486         p_effective_date    => p_effective_date,
4487         p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
4488         p_ler_id            => p_ler_id,
4489         p_rec               => l_mgr_rec);
4490       --
4491       if l_mgr_rec.per_in_ler_id is not null  or l_mgr_person_id is null then
4492          l_mgr_per_in_ler_not_found := false;
4493       else
4494          --
4495          -- Now duplicate the pil, pel, epe, ecr data.
4496          --
4497          l_mgr_per_in_ler_not_found := true;
4498          --
4499          -- Need to copy potential ler for per.
4500          --
4501          ben_ptnl_ler_for_per_api.create_ptnl_ler_for_per_perf
4502            (p_validate                 => false,
4503             p_ptnl_ler_for_per_id      => l_ptnl_ler_for_per_id,
4504             p_lf_evt_ocrd_dt           => l_effective_date,
4505             p_ptnl_ler_for_per_stat_cd => 'PROCD' ,
4506                                           --l_ptnl_ler_for_per_stat_cd_use,
4507             p_ler_id                   => p_ler_id,
4508             p_person_id                => l_mgr_person_id,
4509             p_ntfn_dt                  => p_effective_date, -- l_ntfn_dt,
4510             p_procd_dt                 => p_effective_date,
4511             p_dtctd_dt                 => p_effective_date,
4512             p_business_group_id        => l_curr_epe.per_business_group_id,
4513             p_object_version_number    => l_object_version_number,
4514             p_effective_date           => l_effective_date,
4515             p_program_application_id   => fnd_global.prog_appl_id,
4516             p_program_id               => fnd_global.conc_program_id,
4517             p_request_id               => fnd_global.conc_request_id,
4518             p_program_update_date      => l_effective_date);
4519          --
4520          ben_Person_Life_Event_api.create_Person_Life_Event_perf
4521            (p_validate                => false
4522            ,p_per_in_ler_id           => l_dummy_per_in_ler_id
4523            ,p_ler_id                  => p_ler_id
4524            ,p_person_id               => l_mgr_person_id
4525            ,p_per_in_ler_stat_cd      => 'STRTD'
4526            ,p_ptnl_ler_for_per_id     => l_ptnl_ler_for_per_id
4527            ,p_lf_evt_ocrd_dt          => p_lf_evt_ocrd_dt
4528            ,p_business_group_id       => l_curr_epe.per_business_group_id
4529            ,p_ntfn_dt                 => trunc(sysdate)
4530            ,p_object_version_number   => l_object_version_number
4531            ,p_effective_date          => l_effective_date
4532            ,p_program_application_id  => fnd_global.prog_appl_id
4533            ,p_program_id              => fnd_global.conc_program_id
4534            ,p_request_id              => fnd_global.conc_request_id
4535            ,p_program_update_date     => trunc(sysdate)
4536            ,p_procd_dt                => l_procd_dt
4537            ,p_strtd_dt                => l_strtd_dt
4538            ,p_voidd_dt                => l_voidd_dt);
4539          --
4540          --
4541          -- Now get the manager for l_mgr_person_id.
4542          --
4543 
4544          --l_mgr_person_id_temp := ben_enrolment_requirements.get_manager_id(
4545          --    p_person_id             => l_mgr_person_id,
4546          --    p_hrchy_to_use_cd       =>
4547          --         ben_enrolment_requirements.g_ple_hrchy_to_use_cd,
4548          --    p_pos_structure_version_id =>
4549          --         ben_enrolment_requirements.g_ple_pos_structure_version_id,
4550          --    p_effective_date        => l_effective_date);
4551 
4552          -- But 2172036 addition of assignment_id to epe
4553          --
4554          ben_enrolment_requirements.get_cwb_manager_and_assignment(
4555              p_person_id                => l_mgr_person_id,
4556              p_hrchy_to_use_cd          =>
4557                   ben_enrolment_requirements.g_ple_hrchy_to_use_cd,
4558              p_pos_structure_version_id =>
4559                   ben_enrolment_requirements.g_ple_pos_structure_version_id,
4560              p_effective_date            => l_effective_date,
4561              p_manager_id                => l_mgr_person_id_temp,
4562              p_assignment_id             => l_assignment_id );
4563          --
4564          l_prtt_enrt_rslt_id  := null;
4565          --
4566          -- For Dummy rows no need to determine previous result
4567          -- open c_plan_enrolment_info(
4568          --   cv_person_id         => l_mgr_person_id,
4569          --   cv_business_group_id => l_curr_epe.mgr_business_group_id,
4570          --   cv_lf_evt_ocrd_dt    => l_effective_date,
4571          --   cv_pl_id             => l_curr_epe.pl_id,
4572          --   cv_pgm_id            => l_curr_epe.pgm_id);
4573          -- fetch c_plan_enrolment_info into l_prtt_enrt_rslt_id;
4574          -- close c_plan_enrolment_info;
4575          --
4576          if g_debug then
4577            hr_utility.set_location('EPEC_CRE: Cross BG ' || l_package, 10);
4578          end if;
4579          ben_elig_per_elc_chc_api.create_perf_elig_per_elc_chc(
4580            p_elig_per_elctbl_chc_id => l_elig_per_elctbl_chc_id,
4581            p_business_group_id      => l_curr_epe.per_business_group_id,
4582            p_auto_enrt_flag         => l_curr_epe.auto_enrt_flag,
4583            p_per_in_ler_id          => l_dummy_per_in_ler_id,
4584            p_yr_perd_id             => l_curr_epe.yr_perd_id,
4585            p_pl_id                  => l_curr_epe.pl_id,
4586            p_pl_typ_id              => l_curr_epe.pl_typ_id,
4587            p_oipl_id                => l_curr_epe.oipl_id,
4588            p_pgm_id                 => l_curr_epe.pgm_id,
4589            -- p_pgm_typ_cd             => l_curr_epe.pgm_typ_cd,
4590            p_must_enrl_anthr_pl_id  => l_curr_epe.must_enrl_anthr_pl_id,
4591            p_plip_id                => l_curr_epe.plip_id,
4592            p_ptip_id                => l_curr_epe.ptip_id,
4593            -- As per CWB team l_prtt_enrt_rslt_id can go as null.
4594            p_prtt_enrt_rslt_id      => l_prtt_enrt_rslt_id,
4595            --
4596            p_enrt_typ_cycl_cd       => l_curr_epe.enrt_typ_cycl_cd,
4597            p_comp_lvl_cd            => l_curr_epe.comp_lvl_cd,
4598            p_enrt_cvg_strt_dt_cd    => l_curr_epe.enrt_cvg_strt_dt_cd,
4599            p_enrt_perd_end_dt       => l_curr_epe.enrt_perd_end_dt,
4600            p_enrt_perd_strt_dt      => l_curr_epe.enrt_perd_strt_dt,
4601            p_enrt_cvg_strt_dt_rl    => l_curr_epe.enrt_cvg_strt_dt_rl,
4602            p_roll_crs_flag          => 'N',
4603            p_ctfn_rqd_flag          => l_curr_epe.ctfn_rqd_flag,
4604            p_crntly_enrd_flag       => 'N',-- l_curr_epe.crntly_enrd_flag,
4605            p_dflt_flag              => l_curr_epe.dflt_flag,
4606            p_elctbl_flag            => 'N',-- l_curr_epe.elctbl_flag,
4607            p_mndtry_flag            => l_curr_epe.mndtry_flag,
4608            p_dflt_enrt_dt           => l_curr_epe.dflt_enrt_dt,
4609            p_dpnt_cvg_strt_dt_cd    => NULL,
4610            p_dpnt_cvg_strt_dt_rl    => NULL,
4611            p_enrt_cvg_strt_dt       => l_curr_epe.enrt_cvg_strt_dt,
4612            p_alws_dpnt_dsgn_flag    => 'N',
4613            p_erlst_deenrt_dt        => l_curr_epe.erlst_deenrt_dt,
4614            p_procg_end_dt           => l_curr_epe.procg_end_dt,
4615            p_pl_ordr_num            => l_curr_epe.pl_ordr_num,
4616            p_plip_ordr_num          => l_curr_epe.plip_ordr_num,
4617            p_ptip_ordr_num          => l_curr_epe.ptip_ordr_num,
4618            p_oipl_ordr_num          => l_curr_epe.oipl_ordr_num,
4619            p_object_version_number  => l_object_version_number,
4620            p_effective_date         => l_effective_date,
4621            p_program_application_id => fnd_global.prog_appl_id,
4622            p_program_id             => fnd_global.conc_program_id,
4623            p_request_id             => fnd_global.conc_request_id,
4624            p_program_update_date    => trunc(SYSDATE),
4625            p_enrt_perd_id           => l_curr_epe.enrt_perd_id,
4626            p_lee_rsn_id             => l_curr_epe.lee_rsn_id,
4627            p_cls_enrt_dt_to_use_cd  => l_curr_epe.cls_enrt_dt_to_use_cd,
4628            p_uom                    => l_curr_epe.uom,
4629            p_acty_ref_perd_cd       => l_curr_epe.acty_ref_perd_cd,
4630            p_cryfwd_elig_dpnt_cd    => l_curr_epe.cryfwd_elig_dpnt_cd,
4631            -- added for cwb
4632            p_mode                   => p_mode,
4633            p_ws_mgr_id              => l_mgr_person_id_temp,
4634            p_elig_flag              => 'N',
4635            p_assignment_id          => l_assignment_id  ); -- l_curr_epe.elig_flag);
4636          -- Bug 2172036 and 2231371 added assignment_id in the above call
4637          --
4638          -- Populate the heirarchy table.
4639          --
4640          open c_cwb_hrchy(l_elig_per_elctbl_chc_id);
4641          fetch c_cwb_hrchy into l_emp_epe_id;
4642          --
4643          if c_cwb_hrchy%notfound then
4644           --
4645           insert into ben_cwb_mgr_hrchy (
4646              emp_elig_per_elctbl_chc_id,
4647              mgr_elig_per_elctbl_chc_id,
4648              lvl_num  )
4649           values(
4650              l_elig_per_elctbl_chc_id,
4651              -1,
4652              -1);
4653           --
4654          end if;
4655          --
4656          close c_cwb_hrchy;
4657          --
4658          if g_debug then
4659            hr_utility.set_location('Done EPEC_CRE Cross BG : ' || l_package, 10);
4660          end if;
4661          --
4662          for l_ecr_rec in c_ecr(l_curr_epe.elig_per_elctbl_chc_id)
4663          loop
4664             --
4665                   INSERT INTO ben_enrt_rt
4666                   (
4667                     enrt_rt_id,
4668                     acty_typ_cd,
4669                     tx_typ_cd,
4670                     ctfn_rqd_flag,
4671                     dflt_flag,
4672                     dflt_pndg_ctfn_flag,
4673                     dsply_on_enrt_flag,
4674                     use_to_calc_net_flx_cr_flag,
4675                     entr_val_at_enrt_flag,
4676                     asn_on_enrt_flag,
4677                     rl_crs_only_flag,
4678                     dflt_val,
4679                     ann_val,
4680                     ann_mn_elcn_val,
4681                     ann_mx_elcn_val,
4682                     val,
4683                     nnmntry_uom,
4684                     mx_elcn_val,
4685                     mn_elcn_val,
4686                     incrmt_elcn_val,
4687                     cmcd_acty_ref_perd_cd,
4688                     cmcd_mn_elcn_val,
4689                     cmcd_mx_elcn_val,
4690                     cmcd_val,
4691                     cmcd_dflt_val,
4692                     rt_usg_cd,
4693                     ann_dflt_val,
4694                     bnft_rt_typ_cd,
4695                     rt_mlt_cd,
4696                     dsply_mn_elcn_val,
4697                     dsply_mx_elcn_val,
4698                     entr_ann_val_flag,
4699                     rt_strt_dt,
4700                     rt_strt_dt_cd,
4701                     rt_strt_dt_rl,
4702                     rt_typ_cd,
4703                     elig_per_elctbl_chc_id,
4704                     acty_base_rt_id,
4705                     spcl_rt_enrt_rt_id,
4706                     enrt_bnft_id,
4707                     prtt_rt_val_id,
4708                     decr_bnft_prvdr_pool_id,
4709                     cvg_amt_calc_mthd_id,
4710                     actl_prem_id,
4711                     comp_lvl_fctr_id,
4712                     ptd_comp_lvl_fctr_id,
4713                     clm_comp_lvl_fctr_id,
4714                     business_group_id,
4715                     ecr_attribute_category,
4716                     ecr_attribute1,
4717                     ecr_attribute2,
4718                     ecr_attribute3,
4719                     ecr_attribute4,
4720                     ecr_attribute5,
4721                     ecr_attribute6,
4722                     ecr_attribute7,
4723                     ecr_attribute8,
4724                     ecr_attribute9,
4725                     ecr_attribute10,
4726                     ecr_attribute11,
4727                     ecr_attribute12,
4728                     ecr_attribute13,
4729                     ecr_attribute14,
4730                     ecr_attribute15,
4731                     ecr_attribute16,
4732                     ecr_attribute17,
4733                     ecr_attribute18,
4734                     ecr_attribute19,
4735                     ecr_attribute20,
4736                     ecr_attribute21,
4737                     ecr_attribute22,
4738                     ecr_attribute23,
4739                     ecr_attribute24,
4740                     ecr_attribute25,
4741                     ecr_attribute26,
4742                     ecr_attribute27,
4743                     ecr_attribute28,
4744                     ecr_attribute29,
4745                     ecr_attribute30,
4746                     last_update_login,
4747                     created_by,
4748                     creation_date,
4749                     last_updated_by,
4750                     last_update_date,
4751                     request_id,
4752                     program_application_id,
4753                     program_id,
4754                     program_update_date,
4755                     object_version_number)
4756            VALUES(
4757              ben_enrt_rt_s.nextval,
4758              l_ecr_rec.acty_typ_cd,
4759              l_ecr_rec.tx_typ_cd,
4760              l_ecr_rec.ctfn_rqd_flag,
4761              l_ecr_rec.dflt_flag,
4762              l_ecr_rec.dflt_pndg_ctfn_flag,
4763              l_ecr_rec.dsply_on_enrt_flag,
4764              l_ecr_rec.use_to_calc_net_flx_cr_flag,
4765              l_ecr_rec.entr_val_at_enrt_flag,
4766              l_ecr_rec.asn_on_enrt_flag,
4767              l_ecr_rec.rl_crs_only_flag,
4768              l_ecr_rec.dflt_val,
4769              l_ecr_rec.ann_val,
4770              l_ecr_rec.ann_mn_elcn_val,
4771              l_ecr_rec.ann_mx_elcn_val,
4772              l_ecr_rec.val,
4773              l_ecr_rec.nnmntry_uom,
4774              -- Initially they have to go null.
4775              null, -- l_ecr_rec.mx_elcn_val,
4776              null, -- l_ecr_rec.mn_elcn_val,
4777              l_ecr_rec.incrmt_elcn_val,
4778              l_ecr_rec.cmcd_acty_ref_perd_cd,
4779              -- Initially they have to go null.
4780              null, --l_ecr_rec.cmcd_mn_elcn_val,
4781              null, --l_ecr_rec.cmcd_mx_elcn_val,
4782              l_ecr_rec.cmcd_val,
4783              null,
4784              l_ecr_rec.rt_usg_cd,
4785              l_ecr_rec.ann_dflt_val,
4786              l_ecr_rec.bnft_rt_typ_cd,
4787              l_ecr_rec.rt_mlt_cd,
4788              -- Initially they have to go null.
4789              null, -- l_ecr_rec.dsply_mn_elcn_val,
4790              null, -- l_ecr_rec.dsply_mx_elcn_val,
4791              l_ecr_rec.entr_ann_val_flag,
4792              l_ecr_rec.rt_strt_dt,
4793              l_ecr_rec.rt_strt_dt_cd,
4794              l_ecr_rec.rt_strt_dt_rl,
4795              l_ecr_rec.rt_typ_cd,
4796              l_elig_per_elctbl_chc_id,
4797              l_ecr_rec.acty_base_rt_id,
4798              null,
4799              null, -- enrt_bnft_id : Should be null
4800              null, -- prtt_rt_val_id : should be null
4801              l_ecr_rec.decr_bnft_prvdr_pool_id,
4802              l_ecr_rec.cvg_amt_calc_mthd_id,
4803              l_ecr_rec.actl_prem_id,
4804              l_ecr_rec.comp_lvl_fctr_id,
4805              l_ecr_rec.ptd_comp_lvl_fctr_id,
4806              l_ecr_rec.clm_comp_lvl_fctr_id,
4807              l_curr_epe.per_business_group_id,
4808              l_ecr_rec.ecr_attribute_category,
4809              l_ecr_rec.ecr_attribute1,
4810              l_ecr_rec.ecr_attribute2,
4811              l_ecr_rec.ecr_attribute3,
4812              l_ecr_rec.ecr_attribute4,
4813              l_ecr_rec.ecr_attribute5,
4814              l_ecr_rec.ecr_attribute6,
4815              l_ecr_rec.ecr_attribute7,
4816              l_ecr_rec.ecr_attribute8,
4817              l_ecr_rec.ecr_attribute9,
4818              l_ecr_rec.ecr_attribute10,
4819              l_ecr_rec.ecr_attribute11,
4820              l_ecr_rec.ecr_attribute12,
4821              l_ecr_rec.ecr_attribute13,
4822              l_ecr_rec.ecr_attribute14,
4823              l_ecr_rec.ecr_attribute15,
4824              l_ecr_rec.ecr_attribute16,
4825              l_ecr_rec.ecr_attribute17,
4826              l_ecr_rec.ecr_attribute18,
4827              l_ecr_rec.ecr_attribute19,
4828              l_ecr_rec.ecr_attribute20,
4829              l_ecr_rec.ecr_attribute21,
4830              l_ecr_rec.ecr_attribute22,
4831              l_ecr_rec.ecr_attribute23,
4832              l_ecr_rec.ecr_attribute24,
4833              l_ecr_rec.ecr_attribute25,
4834              l_ecr_rec.ecr_attribute26,
4835              l_ecr_rec.ecr_attribute27,
4836              l_ecr_rec.ecr_attribute28,
4837              l_ecr_rec.ecr_attribute29,
4838              l_ecr_rec.ecr_attribute30,
4839              l_last_update_login,
4840              l_created_by,
4841              l_creation_date,
4842              l_last_updated_by,
4843              trunc(SYSDATE),
4844              fnd_global.conc_request_id,
4845              fnd_global.prog_appl_id,
4846              fnd_global.conc_program_id,
4847              trunc(SYSDATE),
4848              l_object_version_number);
4849             --
4850          end loop;
4851          --
4852          l_mgr_person_id          := l_mgr_person_id_temp;
4853          --
4854       end if;
4855     end loop;
4856  -- end if;
4857  --
4858  if g_debug then
4859    hr_utility.set_location ('Leaving '||l_package,10);
4860  end if;
4861  --
4862 end popu_cross_gb_epe_data;
4863 */
4864 --
4865 -- checks if there are any eligible options for the plan
4866 -- if No then
4867 --    if trk_inelig_flag is set to 'N' at plan level then
4868 --       delete the elctbl chc for the plan
4869 --    else if trk_inelig_flag is set to 'Y' at plan level then
4870 --       update the elctbl chc for the plan to ineligible
4871 --    end
4872 --  end
4873 --
4874 procedure update_cwb_epe
4875 (p_per_in_ler_id number,
4876  p_effective_date date) is
4877 
4878   l_elig_per_elctbl_chc_id   number;
4879   l_ovn number;
4880   l_pl_id number;
4881   l_dummy varchar2(1);
4882   l_package varchar2(80) := g_package||'.update_cwb_epe';
4883 
4884   cursor c_pln is
4885   select pl.trk_inelig_per_flag
4886     from ben_pl_f pl
4887    where pl.pl_id = l_pl_id
4888      and p_effective_date between pl.effective_start_date and
4889          pl.effective_end_date;
4890 
4891   cursor c_pln_opt is
4892   select 'x'
4893     from ben_oipl_f oipl
4894    where oipl.pl_id = l_pl_id
4895      and p_effective_date between oipl.effective_start_date and
4896          oipl.effective_end_date;
4897 
4898   cursor c_epe1 is
4899   select epe1.elig_per_elctbl_chc_id,
4900          epe1.object_version_number,
4901          epe1.pl_id
4902     from ben_elig_per_elctbl_chc epe1
4903    where epe1.per_in_ler_id = p_per_in_ler_id
4904      and epe1.pl_id is not null
4905      and epe1.oipl_id is null;
4906 
4907   cursor c_epe2 is
4908   select 'x'
4909     from ben_elig_per_elctbl_chc epe2
4910    where epe2.per_in_ler_id = p_per_in_ler_id
4911      and epe2.oipl_id is not null
4912      and epe2.pl_id = l_pl_id
4913      and epe2.elig_flag ='Y';
4914 
4915 
4916 begin
4917 
4918   if g_debug then
4919      hr_utility.set_location ('Entering '||l_package,10);
4920   end if;
4921 
4922   open c_epe1;
4923   fetch c_epe1 into
4924   l_elig_per_elctbl_chc_id,
4925   l_ovn,
4926   l_pl_id;
4927   if c_epe1%notfound then
4928      return;
4929   end if;
4930   close c_epe1;
4931 
4932   if g_trk_inelig_flag is null then
4933      open c_pln;
4934      fetch c_pln into g_trk_inelig_flag;
4935      close c_pln;
4936   end if;
4937 
4938   if g_opt_exists is null then
4939      open c_pln_opt;
4940      fetch c_pln_opt into l_dummy;
4941      g_opt_exists := c_pln_opt%found;
4942      close c_pln_opt;
4943   end if;
4944 
4945   if g_opt_exists then
4946      open c_epe2;
4947      fetch c_epe2 into l_dummy;
4948      if c_epe2%notfound then
4949         if g_trk_inelig_flag ='N' then
4950           /* GLOBALCWB : If this data is deleted then no cwb rates are written
4951              co do not delete
4952           ben_elig_per_elc_chc_api.delete_ELIG_PER_ELC_CHC
4953           (p_elig_per_elctbl_chc_id   => l_elig_per_elctbl_chc_id
4954           ,p_object_version_number    => l_ovn
4955           ,p_effective_date           => p_effective_date);
4956           */
4957           null;
4958         else
4959           ben_elig_per_elc_chc_api.update_perf_ELIG_PER_ELC_CHC
4960           (p_elig_per_elctbl_chc_id   => l_elig_per_elctbl_chc_id
4961           ,p_elig_flag                => 'N'
4962           ,p_inelig_rsn_cd            => 'OTH'
4963           ,p_object_version_number    => l_ovn
4964           ,p_effective_date           => p_effective_date);
4965         end if;
4966      end if;
4967      close c_epe2;
4968   end if;
4969 
4970   if g_debug then
4971      hr_utility.set_location ('Leaving '||l_package,10);
4972   end if;
4973 
4974 exception
4975   when others then
4976        if c_epe2%isopen then
4977           close c_epe2;
4978        end if;
4979        raise;
4980 end;
4981 
4982 --
4983 -- deletes per in ler for people with no elctble chc when
4984 -- trk_inelig_per_flag is set to N
4985 --
4986 procedure del_cwb_pil
4987 (p_person_id      in  number,
4988  p_pl_id          in  number,
4989  p_effective_date in  date,
4990  p_ler_id         in  number,
4991  p_lf_evt_ocrd_dt in  date) is
4992 
4993 cursor c_pil is
4994 select pil.per_in_ler_id,
4995        ptnl.ptnl_ler_for_per_id,
4996        ptnl.object_version_number ptnl_ovn,
4997        pil.object_version_number pil_ovn
4998   from ben_per_in_ler pil,
4999        ben_ptnl_ler_for_per ptnl
5000  where pil.ler_id = p_ler_id
5001    and pil.lf_evt_ocrd_dt = p_lf_evt_ocrd_dt
5002    and pil.person_id = p_person_id
5003    and ptnl.ptnl_ler_for_per_id = pil.ptnl_ler_for_per_id
5004    and not exists
5005        (select 'x'
5006           from ben_elig_per_elctbl_chc epe
5007          where epe.per_in_ler_id = pil.per_in_ler_id);
5008 l_pil_rec c_pil%rowtype;
5009 
5010 cursor c_popl is
5011 select pil_elctbl_chc_popl_id,
5012        object_version_number
5013   from ben_pil_elctbl_chc_popl
5014  where per_in_ler_id = l_pil_rec.per_in_ler_id;
5015 l_popl_rec c_popl%rowtype;
5016 
5017 l_package varchar2(80);
5018 
5019 begin
5020 
5021    if g_debug then
5022      l_package := g_package||'.del_cwb_pil';
5023      hr_utility.set_location ('Entering '||l_package,10);
5024    end if;
5025 
5026    open c_pil;
5027    fetch c_pil into l_pil_rec;
5028    if c_pil%found then
5029 
5030       open c_popl;
5031       loop
5032            fetch c_popl into l_popl_rec;
5033            if c_popl%notfound then
5034               exit;
5035            end if;
5036 
5037            ben_Pil_Elctbl_chc_Popl_api.delete_Pil_Elctbl_chc_Popl
5038           (p_pil_elctbl_chc_popl_id   => l_popl_rec.pil_elctbl_chc_popl_id,
5039            p_object_version_number  => l_popl_rec.object_version_number,
5040            p_effective_date         => p_effective_date);
5041 
5042       end loop;
5043       close c_popl;
5044 
5045       ben_Person_Life_Event_api.delete_Person_Life_Event
5046      (p_per_in_ler_id          => l_pil_rec.per_in_ler_id,
5047       p_object_version_number  => l_pil_rec.pil_ovn,
5048       p_effective_date         => p_effective_date);
5049 
5050       ben_ptnl_ler_for_per_api.delete_ptnl_ler_for_per
5051      (p_ptnl_ler_for_per_id    => l_pil_rec.ptnl_ler_for_per_id,
5052       p_object_version_number  => l_pil_rec.ptnl_ovn,
5053       p_effective_date         => p_effective_date);
5054 
5055    end if;
5056    close c_pil;
5057 
5058    if g_debug then
5059      hr_utility.set_location ('Leaving '||l_package,10);
5060    end if;
5061 
5062 end;
5063 --
5064 procedure process_rows(p_benefit_action_id        in number,
5065                        p_start_person_action_id   in number,
5066                        p_end_person_action_id     in number,
5067                        p_business_group_id        in number,
5068                        p_mode                     in varchar2,
5069                        p_person_selection_rule_id in number,
5070                        p_comp_selection_rule_id   in number,
5071                        -- PB : 5422 :
5072                --  p_popl_enrt_typ_cycl_id    in number,
5073                        p_derivable_factors        in varchar2,
5074                        p_cbr_tmprl_evt_flag       in varchar2,
5075                        p_person_count             in out nocopy number,
5076                        p_error_person_count       in out nocopy number,
5077                        p_thread_id                in number,
5078                        p_validate                 in varchar2,
5079                        p_effective_date           in date,
5080                        p_lf_evt_ocrd_dt           in date,
5081                        p_gsp_eval_elig_flag       in varchar2 default null,      /* GSP Rate Sync */
5082                        p_lf_evt_oper_cd           in varchar2 default null       /* GSP Rate Sync */
5083                        ) is
5084   --
5085   l_ler_id                ben_person_actions.ler_id%type;
5086   l_person_id             ben_person_actions.person_id%type;
5087   l_person_action_id      ben_person_actions.person_action_id%type;
5088   l_object_version_number ben_person_actions.object_version_number%type;
5089   l_ptnl_ler_for_per_id   ben_ptnl_ler_for_per.ptnl_ler_for_per_id%type;
5090   l_effective_start_date  date;
5091   l_effective_end_date    date;
5092   l_dummy                 varchar2(1);
5093   l_count                 number := 0;
5094   l_threads               number;
5095   l_chunk_size            number;
5096   l_max_errors            number;
5097   l_package               varchar2(80);
5098   l_mnl_dt date;
5099   l_dtctd_dt   date;
5100   l_procd_dt   date;
5101   l_unprocd_dt date;
5102   l_voidd_dt   date;
5103   l_rec                   ben_env_object.g_global_env_rec_type;
5104   --
5105   cursor c_person_thread is
5106     select ben.person_id,
5107            ben.person_action_id,
5108            ben.object_version_number,
5109            ben.ler_id
5110     from   ben_person_actions ben
5111     where  ben.benefit_action_id = p_benefit_action_id
5112     and    ben.action_status_cd <> 'P'
5113     and    ben.person_action_id
5114            between p_start_person_action_id
5115            and     p_end_person_action_id
5116     order  by ben.person_action_id;
5117   --
5118   -- absences,gsp
5119   --
5120   cursor c_potential (p_person_id number) is
5121     select ptnl_ler_for_per_id
5122     from ben_ptnl_ler_for_per pfl,
5123          ben_ler_f ler
5124     where  pfl.ptnl_ler_for_per_stat_cd not in ('VOIDD','PROCD')
5125     and    pfl.person_id = p_person_id
5126     and    pfl.ler_id = ler.ler_id
5127     and    p_effective_date
5128            between ler.effective_start_date
5129            and     ler.effective_end_date
5130     and    pfl.lf_evt_ocrd_dt <= p_effective_date
5131     and    ler.typ_cd = decode(p_mode,'M','ABS','G','GSP',null)
5132     order  by pfl.lf_evt_ocrd_dt asc, ler.lf_evt_oper_cd desc;
5133 
5134   cursor c_pil (p_person_id number) is
5135     select 'x'
5136       from ben_per_in_ler pil,
5137            ben_ler_f ler
5138      where pil.per_in_ler_stat_cd = 'STRTD'
5139      and   pil.person_id = p_person_id
5140      and   pil.ler_id = ler.ler_id
5141      and   p_effective_date between ler.effective_start_date
5142      and   ler.effective_end_date
5143      and   ler.typ_cd = decode(p_mode,'M','ABS','G','GSP',null);
5144 
5145   l_potential_o number ;
5146   l_potential   number ;
5147 
5148 begin
5149   --
5150   if g_debug then
5151     l_package := g_package||'.process_rows';
5152     hr_utility.set_location ('Entering '||l_package,10);
5153   end if;
5154   --
5155   open c_person_thread;
5156     --
5157     loop
5158       --
5159       if g_debug then
5160         hr_utility.set_location (l_package||' Start c_person_thread ',20);
5161       end if;
5162       fetch c_person_thread into l_person_id,
5163                                  l_person_action_id,
5164                                  l_object_version_number,
5165                                  l_ler_id;
5166       if g_debug then
5167         hr_utility.set_location (l_package||' fetch c_person_thread ',20);
5168       end if;
5169       exit when c_person_thread%notfound;
5170       --
5171       l_count := l_count + 1;
5172       --
5173       -- absence changes
5174       l_potential_o := null;
5175       l_potential := null;
5176 
5177       Loop
5178         --
5179         process_life_events
5180           (p_person_id                => l_person_id,
5181            p_person_action_id         => l_person_action_id,
5182            p_object_version_number    => l_object_version_number,
5183            p_business_group_id        => p_business_group_id,
5184            p_mode                     => p_mode,
5185            p_ler_id                   => l_ler_id,
5186            p_person_selection_rule_id => p_person_selection_rule_id,
5187            p_comp_selection_rule_id   => p_comp_selection_rule_id,
5188            p_derivable_factors        => p_derivable_factors,
5189            p_cbr_tmprl_evt_flag       => p_cbr_tmprl_evt_flag,
5190            p_person_count             => p_person_count,
5191            p_error_person_count       => p_error_person_count,
5192            p_effective_date           => p_effective_date,
5193            p_lf_evt_ocrd_dt           => p_lf_evt_ocrd_dt,
5194            p_validate                 => p_validate,                /* Bug 5550359 */
5195            p_gsp_eval_elig_flag       => p_gsp_eval_elig_flag,      /* GSP Rate Sync */
5196            p_lf_evt_oper_cd           => p_lf_evt_oper_cd           /* GSP Rate Sync */
5197            );
5198         --
5199         if p_mode in ('G','M') then
5200           -- absence mode loop
5201           -- if there are no ABS life events unprocessed
5202           --                   (or)
5203           -- if the processing of previous life event errored,
5204           -- then exit out of the loop
5205           open c_potential ( l_person_id );
5206           fetch c_potential into l_potential;
5207           if c_potential%notfound or
5208              l_potential = l_potential_o then
5209              close c_potential;
5210              exit;
5211           else
5212              open c_pil(l_person_id);
5213              fetch c_pil into l_dummy;
5214              if c_pil%found then
5215                 close c_potential;
5216                 close c_pil;
5217                 exit;
5218              end if;
5219              close c_pil;
5220           end if;
5221           close c_potential;
5222           l_potential_o := l_potential;
5223         else
5224           -- exit out of the loop after one iteration
5225           exit;
5226         end if;
5227         --
5228       End loop;
5229       --
5230       --
5231       if g_debug then
5232         hr_utility.set_location('End c_person_thread loop '||l_package,10);
5233       end if;
5234       --
5235       -- We need to commit the validate mode stuff to the log and
5236       -- table at regular intervals, that way users can view the log
5237       -- before the process has finished
5238          --
5239          -- Populate rollback value tables
5240          --
5241          ben_populate_rbv.populate_benmngle_rbvs
5242            (p_benefit_action_id => p_benefit_action_id
5243            ,p_person_action_id  => l_person_action_id
5244            ,p_validate_flag     => p_validate
5245            );
5246          --
5247     end loop;
5248     --
5249   close c_person_thread;
5250   if g_debug then
5251     hr_utility.set_location (l_package||' close c_person_thread ',20);
5252   end if;
5253   --
5254   if ben_populate_rbv.validate_mode
5255     (p_validate => p_validate
5256     )
5257   then
5258     --
5259     rollback;
5260     --
5261   end if;
5262   --
5263 /*
5264   if p_validate in ('Y','C')
5265   then
5266     --
5267     rollback;
5268     --
5269   end if;
5270   --
5271 */
5272   if g_debug then
5273     hr_utility.set_location (l_package||' Write TAF ',20);
5274   end if;
5275   benutils.write_table_and_file(p_table => true,
5276                                 p_file  => true);
5277   commit;
5278   --
5279   if g_debug then
5280     hr_utility.set_location ('Leaving '||l_package,10);
5281   end if;
5282   --
5283 end process_rows;
5284 --
5285 
5286 procedure set_up_cobj_part_elig
5287   (p_comp_obj_tree_row in out NOCOPY ben_manage_life_events.g_cache_proc_objects_rec
5288   ,p_ler_id            in     number
5289   ,p_business_group_id in     number
5290   ,p_effective_date    in     date
5291   )
5292 is
5293   --
5294   l_proc varchar2(80);
5295   --
5296 begin
5297   --
5298   if g_debug then
5299     l_proc := g_package || '.set_up_cobj_part_elig';
5300     hr_utility.set_location('Entering '||l_proc,10);
5301   end if;
5302   if p_comp_obj_tree_row.pgm_id is not null then
5303     --
5304     if g_debug then
5305       hr_utility.set_location('Setting up eligibility at the PGM level',10);
5306     end if;
5307     --
5308     ben_cobj_cache.get_pgm_dets
5309       (p_business_group_id => p_business_group_id
5310       ,p_effective_date    => p_effective_date
5311       ,p_pgm_id            => p_comp_obj_tree_row.pgm_id
5312       ,p_inst_row      => ben_cobj_cache.g_pgm_currow
5313       );
5314     --
5315     ben_cobj_cache.get_etpr_dets
5316       (p_business_group_id => p_business_group_id
5317       ,p_effective_date    => p_effective_date
5318       ,p_ler_id            => p_ler_id
5319       ,p_pgm_id            => p_comp_obj_tree_row.pgm_id
5320       ,p_inst_row      => ben_cobj_cache.g_pgmetpr_currow
5321       );
5322     --
5323     ben_cobj_cache.get_prel_dets
5324       (p_business_group_id => p_business_group_id
5325       ,p_effective_date    => p_effective_date
5326       ,p_pgm_id            => p_comp_obj_tree_row.pgm_id
5327       ,p_inst_row      => ben_cobj_cache.g_pgmprel_currow
5328       );
5329     --
5330     if g_debug then
5331       hr_utility.set_location('Done pgm setobjs '||l_proc,20);
5332     end if;
5333     --
5334   elsif p_comp_obj_tree_row.ptip_id is not null then
5335     --
5336     if g_debug then
5337       hr_utility.set_location('Setting up eligibility at the PTIP level',10);
5338     end if;
5339     --
5340     ben_cobj_cache.get_ptip_dets
5341       (p_business_group_id => p_business_group_id
5342       ,p_effective_date    => p_effective_date
5343       ,p_ptip_id           => p_comp_obj_tree_row.ptip_id
5344       ,p_inst_row      => ben_cobj_cache.g_ptip_currow
5345       );
5346     --
5347     ben_cobj_cache.get_etpr_dets
5348       (p_business_group_id => p_business_group_id
5349       ,p_effective_date    => p_effective_date
5350       ,p_ler_id            => p_ler_id
5351       ,p_ptip_id           => p_comp_obj_tree_row.ptip_id
5352       ,p_inst_row      => ben_cobj_cache.g_ptipetpr_currow
5353       );
5354     --
5355     ben_cobj_cache.get_prel_dets
5356       (p_business_group_id => p_business_group_id
5357       ,p_effective_date    => p_effective_date
5358       ,p_ptip_id           => p_comp_obj_tree_row.ptip_id
5359       ,p_inst_row      => ben_cobj_cache.g_ptipprel_currow
5360       );
5361     --
5362   elsif p_comp_obj_tree_row.plip_id is not null then
5363     --
5364     if g_debug then
5365       hr_utility.set_location('Setting up eligibility at the PLIP level',10);
5366     end if;
5367     --
5368     ben_cobj_cache.get_plip_dets
5369       (p_business_group_id => p_business_group_id
5370       ,p_effective_date    => p_effective_date
5371       ,p_plip_id           => p_comp_obj_tree_row.plip_id
5372       ,p_inst_row      => ben_cobj_cache.g_plip_currow
5373       );
5374     --
5375     ben_cobj_cache.get_etpr_dets
5376       (p_business_group_id => p_business_group_id
5377       ,p_effective_date    => p_effective_date
5378       ,p_ler_id            => p_ler_id
5379       ,p_plip_id           => p_comp_obj_tree_row.plip_id
5380       ,p_inst_row      => ben_cobj_cache.g_plipetpr_currow
5381       );
5382     --
5383     ben_cobj_cache.get_prel_dets
5384       (p_business_group_id => p_business_group_id
5385       ,p_effective_date    => p_effective_date
5386       ,p_plip_id           => p_comp_obj_tree_row.plip_id
5387       ,p_inst_row      => ben_cobj_cache.g_plipprel_currow
5388       );
5389     --
5390     if g_debug then
5391       hr_utility.set_location(' current ptip ' ||  p_comp_obj_tree_row.par_ptip_id, 99 );
5392       hr_utility.set_location(' current hash ' ||  ben_cobj_cache.g_ptip_currow.ptip_id, 99 ) ;
5393     end if;
5394     ---- bug : 2228464  tilak
5395     ---- Compensation object tree was populated in PGM,PL name  order
5396     ---- there cane a possibility of ptip falls in different levl
5397     ---- PRG1    MEDICAL ptip   mediacl plan1
5398     ---- PRG1    DEntal  ptip   DEntal Plan 1
5399     ---  PRG1    MEDICAL Ptip   Medical Plan2
5400     ---- in the above case of Medical Plan2  cached ptip is DENTAL but the current ptip is
5401     ---  Medical so the eligibility of PTIP validated for DENTAL not for MEDIACL
5402     ---  so if the ptip_id of current row is not matching with cached  then PTIP level
5403     ---  is refreshed , discussed with martin and he agreed that
5404 
5405 
5406     if p_comp_obj_tree_row.par_ptip_id <> ben_cobj_cache.g_ptip_currow.ptip_id then
5407         ben_cobj_cache.get_ptip_dets
5408           (p_business_group_id => p_business_group_id
5409           ,p_effective_date    => p_effective_date
5410           ,p_ptip_id           => p_comp_obj_tree_row.par_ptip_id
5411           ,p_inst_row      => ben_cobj_cache.g_ptip_currow
5412           );
5413         --
5414          ben_cobj_cache.get_etpr_dets
5415           (p_business_group_id => p_business_group_id
5416           ,p_effective_date    => p_effective_date
5417           ,p_ler_id            => p_ler_id
5418           ,p_ptip_id           => p_comp_obj_tree_row.par_ptip_id
5419           ,p_inst_row      => ben_cobj_cache.g_ptipetpr_currow
5420           );
5421          --
5422         ben_cobj_cache.get_prel_dets
5423           (p_business_group_id => p_business_group_id
5424           ,p_effective_date    => p_effective_date
5425           ,p_ptip_id           => p_comp_obj_tree_row.par_ptip_id
5426           ,p_inst_row      => ben_cobj_cache.g_ptipprel_currow
5427           );
5428     end if ;
5429 
5430     if g_debug then
5431       hr_utility.set_location('Done PLIP '||l_proc,30);
5432     end if;
5433     --
5434   elsif p_comp_obj_tree_row.pl_id is not null then
5435     --
5436     if g_debug then
5437       hr_utility.set_location('Setting up eligibility at the PLN level',10);
5438     end if;
5439     --
5440     ben_cobj_cache.get_pl_dets
5441       (p_business_group_id => p_business_group_id
5442       ,p_effective_date    => p_effective_date
5443       ,p_pl_id             => p_comp_obj_tree_row.pl_id
5444       ,p_inst_row      => ben_cobj_cache.g_pl_currow
5445       );
5446     --
5447     ben_cobj_cache.get_etpr_dets
5448       (p_business_group_id => p_business_group_id
5449       ,p_effective_date    => p_effective_date
5450       ,p_ler_id            => p_ler_id
5451       ,p_pl_id             => p_comp_obj_tree_row.pl_id
5452       ,p_inst_row      => ben_cobj_cache.g_pletpr_currow
5453       );
5454     --
5455     ben_cobj_cache.get_prel_dets
5456       (p_business_group_id => p_business_group_id
5457       ,p_effective_date    => p_effective_date
5458       ,p_pl_id             => p_comp_obj_tree_row.pl_id
5459       ,p_inst_row      => ben_cobj_cache.g_plprel_currow
5460       );
5461     --
5462     if g_debug then
5463       hr_utility.set_location('Done pln setobjs '||l_proc,20);
5464     end if;
5465     --
5466   elsif p_comp_obj_tree_row.oipl_id is not null then
5467     --
5468     if g_debug then
5469       hr_utility.set_location(l_proc||' OIPL NN ',20);
5470     end if;
5471     --
5472     ben_cobj_cache.get_oipl_dets
5473       (p_business_group_id => p_business_group_id
5474       ,p_effective_date    => p_effective_date
5475       ,p_oipl_id           => p_comp_obj_tree_row.oipl_id
5476       ,p_inst_row      => ben_cobj_cache.g_oipl_currow
5477       );
5478     --
5479     ben_cobj_cache.get_opt_dets
5480       (p_business_group_id => p_business_group_id
5481       ,p_effective_date    => p_effective_date
5482       ,p_opt_id            => ben_cobj_cache.g_oipl_currow.opt_id
5483       ,p_inst_row      => ben_cobj_cache.g_opt_currow
5484       );
5485     --
5486     ben_cobj_cache.get_etpr_dets
5487       (p_business_group_id => p_business_group_id
5488       ,p_effective_date    => p_effective_date
5489       ,p_ler_id            => p_ler_id
5490       ,p_oipl_id           => p_comp_obj_tree_row.oipl_id
5491       ,p_inst_row      => ben_cobj_cache.g_oipletpr_currow
5492       );
5493     --
5494     ben_cobj_cache.get_prel_dets
5495       (p_business_group_id => p_business_group_id
5496       ,p_effective_date    => p_effective_date
5497       ,p_oipl_id           => p_comp_obj_tree_row.oipl_id
5498       ,p_inst_row      => ben_cobj_cache.g_oiplprel_currow
5499       );
5500     --
5501     -- Check oiplip stuff
5502     --
5503     if p_comp_obj_tree_row.oiplip_id is not null then
5504       --
5505       ben_cobj_cache.get_oiplip_dets
5506         (p_business_group_id => p_business_group_id
5507         ,p_effective_date    => p_effective_date
5508         ,p_oiplip_id         => p_comp_obj_tree_row.oiplip_id
5509         ,p_inst_row      => ben_cobj_cache.g_oiplip_currow
5510         );
5511       --
5512     end if;
5513     --
5514     if g_debug then
5515       hr_utility.set_location('Done oipl setobjs '||l_proc,20);
5516     end if;
5517     --
5518   end if;
5519   --
5520   if g_debug then
5521     hr_utility.set_location('Leaving '||l_proc,10);
5522   end if;
5523   --
5524 end set_up_cobj_part_elig;
5525 --
5526 procedure set_up_list_part_elig
5527   (p_ler_id            in number
5528   ,p_business_group_id in number
5529   ,p_effective_date    in date
5530   )
5531 is
5532   --
5533   l_proc varchar2(80);
5534   --
5535   l_rec  ben_elig_to_prte_rsn_f%rowtype;
5536   --
5537 begin
5538   --
5539   if g_debug then
5540     l_proc := g_package || '.set_up_list_part_elig';
5541     hr_utility.set_location('Entering '||l_proc,10);
5542   end if;
5543   --
5544   -- Loop through all comp objects and making a call to set up the eligibility
5545   -- cache.
5546   --
5547   for l_count in g_cache_proc_object.first..g_cache_proc_object.last loop
5548     --
5549     if g_debug then
5550       hr_utility.set_location('Start loop '||l_proc,20);
5551     end if;
5552     if g_cache_proc_object(l_count).pgm_id is not null then
5553       --
5554       if g_debug then
5555         hr_utility.set_location('Setting up eligibility at the PGM level',10);
5556       end if;
5557       --
5558       ben_elig_object.set_object
5559           (p_pgm_id            => g_cache_proc_object(l_count).pgm_id,
5560            p_ler_id            => p_ler_id,
5561            p_business_group_id => p_business_group_id,
5562            p_effective_date    => p_effective_date
5563           ,p_rec               => l_rec
5564            );
5565       --
5566       ben_elig_object.set_object
5567           (p_pgm_id            => g_cache_proc_object(l_count).pgm_id,
5568            p_business_group_id => p_business_group_id,
5569            p_effective_date    => p_effective_date);
5570 
5571       if g_debug then
5572         hr_utility.set_location('Done pgm setobjs '||l_proc,20);
5573       end if;
5574       --
5575     elsif g_cache_proc_object(l_count).pl_id is not null then
5576       --
5577       if g_debug then
5578         hr_utility.set_location('Setting up eligibility at the PLN level',10);
5579       end if;
5580       --
5581       ben_elig_object.set_object
5582           (p_pl_id             => g_cache_proc_object(l_count).pl_id,
5583            p_ler_id            => p_ler_id,
5584            p_business_group_id => p_business_group_id,
5585            p_effective_date    => p_effective_date
5586           ,p_rec               => l_rec
5587           );
5588       --
5589       ben_elig_object.set_object
5590           (p_pl_id             => g_cache_proc_object(l_count).pl_id,
5591            p_business_group_id => p_business_group_id,
5592            p_effective_date    => p_effective_date);
5593       if g_debug then
5594         hr_utility.set_location('Done pln setobjs '||l_proc,20);
5595       end if;
5596       --
5597     --
5598     elsif g_cache_proc_object(l_count).plip_id is not null then
5599       --
5600       if g_debug then
5601         hr_utility.set_location('Setting up eligibility at the PLIP level',10);
5602       end if;
5603       --
5604       ben_elig_object.set_object
5605           (p_plip_id           => g_cache_proc_object(l_count).plip_id,
5606            p_ler_id            => p_ler_id,
5607            p_business_group_id => p_business_group_id,
5608            p_effective_date    => p_effective_date
5609           ,p_rec               => l_rec
5610           );
5611       --
5612       if g_debug then
5613         hr_utility.set_location('Done plip ler sobjs '||l_proc,20);
5614       end if;
5615       ben_elig_object.set_object
5616           (p_plip_id           => g_cache_proc_object(l_count).plip_id,
5617            p_business_group_id => p_business_group_id,
5618            p_effective_date    => p_effective_date);
5619       --
5620       if g_debug then
5621         hr_utility.set_location('Done PLIP '||l_proc,30);
5622       end if;
5623       --
5624     elsif g_cache_proc_object(l_count).ptip_id is not null then
5625       --
5626       if g_debug then
5627         hr_utility.set_location('Setting up eligibility at the PTIP level',10);
5628         hr_utility.set_location('Current PTIP = '||
5629                               g_cache_proc_object(l_count).ptip_id,10);
5630         --
5631         hr_utility.set_location('ELOBJ_SOBJ '||l_proc,30);
5632       end if;
5633       ben_elig_object.set_object
5634           (p_ptip_id           => g_cache_proc_object(l_count).ptip_id,
5635            p_ler_id            => p_ler_id,
5636            p_business_group_id => p_business_group_id,
5637            p_effective_date    => p_effective_date
5638           ,p_rec               => l_rec
5639           );
5640       --
5641       ben_elig_object.set_object
5642           (p_ptip_id           => g_cache_proc_object(l_count).ptip_id,
5643            p_business_group_id => p_business_group_id,
5644            p_effective_date    => p_effective_date);
5645       --
5646     elsif g_cache_proc_object(l_count).oipl_id is not null then
5647       --
5648       if g_debug then
5649         hr_utility.set_location('Setting up eligibility at the OIPL level',10);
5650       end if;
5651       --
5652       if g_debug then
5653         hr_utility.set_location(l_proc||' OIPL NN ',20);
5654       end if;
5655       ben_elig_object.set_object
5656           (p_oipl_id           => g_cache_proc_object(l_count).oipl_id,
5657            p_ler_id            => p_ler_id,
5658            p_business_group_id => p_business_group_id,
5659            p_effective_date    => p_effective_date
5660           ,p_rec               => l_rec
5661           );
5662       --
5663       ben_elig_object.set_object
5664           (p_oipl_id           => g_cache_proc_object(l_count).oipl_id,
5665            p_business_group_id => p_business_group_id,
5666            p_effective_date    => p_effective_date);
5667       if g_debug then
5668         hr_utility.set_location('Done oipl setobjs '||l_proc,20);
5669       end if;
5670       --
5671     end if;
5672     --
5673   end loop;
5674   --
5675   if g_debug then
5676     hr_utility.set_location('Leaving '||l_proc,10);
5677   end if;
5678   --
5679 end set_up_list_part_elig;
5680 --
5681 procedure do_multithread
5682   (errbuf                     out nocopy varchar2,
5683    retcode                    out nocopy number,
5684    p_validate                 in varchar2,
5685    p_benefit_action_id        in number,
5686    p_effective_date           in varchar2,
5687    p_pgm_id                   in number,
5688    p_business_group_id        in number,
5689    p_pl_id                    in number,
5690    -- PB : 5422 :
5691    p_popl_enrt_typ_cycl_id    in number,
5692    p_no_programs              in varchar2,
5693    p_no_plans                 in varchar2,
5694    p_rptg_grp_id              in number,
5695    p_pl_typ_id                in number,
5696    p_opt_id                   in number,
5697    p_eligy_prfl_id            in number,
5698    p_vrbl_rt_prfl_id          in number,
5699    p_mode                     in varchar2,
5700    p_person_selection_rule_id in number,
5701    p_comp_selection_rule_id   in number,
5702    p_derivable_factors        in varchar2,
5703    p_thread_id                in number,
5704    p_lf_evt_ocrd_dt           in varchar2,
5705    p_cbr_tmprl_evt_flag       in varchar2,
5706    p_lmt_prpnip_by_org_flag   in varchar2,
5707    p_gsp_eval_elig_flag       in varchar2 default null,      /* GSP Rate Sync */
5708    p_lf_evt_oper_cd           in varchar2 default null       /* GSP Rate Sync */
5709    ) is
5710   --
5711   l_package                varchar2(80);
5712   l_row_id                 rowid;
5713   l_rows_found             boolean := false;
5714   l_record_number          number := 0;
5715   l_start_person_action_id number := 0;
5716   l_end_person_action_id   number := 0;
5717   l_person_count           number := 0;
5718   l_error_person_count     number := 0;
5719   l_chunk_size             number := 0;
5720   l_threads                number := 0;
5721   --
5722   l_effective_date         date;
5723   l_lf_evt_ocrd_dt         date;
5724   l_max_errors             number;
5725   l_commit                 number;
5726   l_slave_errored          boolean := false;
5727   --
5728   l_ler_rec                benutils.g_ler;
5729   --
5730 begin
5731   --
5732   g_debug := hr_utility.debug_enabled;
5733   if g_debug then
5734     l_package := g_package||'.do_multithread';
5735     hr_utility.set_location ('Entering '||l_package,10);
5736     hr_utility.set_location ('p_mode : '||p_mode,20);
5737   end if;
5738   --
5739   -- Convert varchar2 dates to real dates
5740   -- 1) First remove time component
5741   -- 2) Next convert format
5742   --
5743   /*
5744   l_effective_date := to_date(p_effective_date,'YYYY/MM/DD HH24:MI:SS');
5745   l_effective_date := to_date(to_char(trunc(l_effective_date),'DD/MM/RRRR'),'DD/MM/RRRR');
5746   l_lf_evt_ocrd_dt := to_date(p_lf_evt_ocrd_dt,'YYYY/MM/DD HH24:MI:SS');
5747   l_lf_evt_ocrd_dt := to_date(to_char(trunc(l_lf_evt_ocrd_dt),'DD/MM/RRRR'),'DD/MM/RRRR');
5748   */
5749   l_effective_date := trunc(fnd_date.canonical_to_date(p_effective_date));
5750   l_lf_evt_ocrd_dt := trunc(fnd_date.canonical_to_date(p_lf_evt_ocrd_dt));
5751   --
5752   benutils.get_ler
5753     (p_business_group_id     => p_business_group_id
5754     ,p_typ_cd                => 'SCHEDDU'
5755     ,p_effective_date        => l_effective_date
5756     ,p_rec                   => l_ler_rec
5757     );
5758   --
5759   g_ler_id := l_ler_rec.ler_id;
5760   g_derivable_factors := p_derivable_factors;
5761   --
5762   -- iRec
5763   if p_mode = 'I' then
5764     --
5765     -- Set G_LER_ID to iRecruitment LER_ID for subsequent use in ben_evaluate_ptnl_lf_evt
5766     --
5767     benutils.get_ler (p_business_group_id      => p_business_group_id,
5768     		    p_typ_cd                 => 'IREC',
5769     		    p_effective_date         => l_effective_date,
5770     		    p_rec                    => l_ler_rec
5771     		   );
5772     --
5773     g_ler_id := l_ler_rec.ler_id;
5774     --
5775   end if;
5776   -- iRec
5777   benutils.get_parameter
5778     (p_business_group_id => p_business_group_id,
5779      p_batch_exe_cd      => 'BENMNGLE',
5780      p_threads           => l_threads,
5781      p_chunk_size        => l_chunk_size,
5782      p_max_errors        => g_max_errors_allowed);
5783 
5784   if g_debug then
5785     hr_utility.set_location ('Dn get_parameter '||l_package,10);
5786   end if;
5787   --
5788   -- Clear benmngle level caches
5789   --
5790   ben_manage_life_events.clear_init_benmngle_caches
5791     (p_business_group_id => p_business_group_id
5792     ,p_effective_date    => l_effective_date
5793     ,p_threads           => l_threads
5794     ,p_chunk_size        => l_chunk_size
5795     ,p_max_errors        => g_max_errors_allowed
5796     ,p_benefit_action_id => p_benefit_action_id
5797     ,p_thread_id         => p_thread_id
5798     );
5799   --
5800   print_parameters
5801      (p_benefit_action_id        => p_benefit_action_id);
5802   --
5803   -- Bug: 4128034. CWB Mode fnd_session needs to be set.
5804   if p_mode in ('L' , 'W' ) then
5805     dt_fndate.change_ses_date
5806       (p_ses_date => l_effective_date
5807       ,p_commit   => l_commit
5808       );
5809   end if;
5810   --
5811   if p_mode in ('A','P','S','T') then
5812     --
5813     dt_fndate.change_ses_date
5814       (p_ses_date => l_effective_date
5815       ,p_commit   => l_commit
5816       );
5817     --
5818     -- PB : Healthnet changes
5819     -- Build the comp object list in evaluate_life_events
5820     -- if comp objects selection is based on person's org id.
5821     --
5822     if p_lmt_prpnip_by_org_flag = 'N' then
5823        --
5824        if g_debug then
5825          hr_utility.set_location (' Temp BCOL '||l_package,10);
5826        end if;
5827        ben_comp_object_list.build_comp_object_list
5828          (p_benefit_action_id      => p_benefit_action_id
5829          ,p_comp_selection_rule_id => p_comp_selection_rule_id
5830          ,p_effective_date         => l_effective_date
5831          ,p_pgm_id                 => p_pgm_id
5832          ,p_business_group_id      => p_business_group_id
5833          ,p_pl_id                  => p_pl_id
5834 
5835          -- PB : 5422 :
5836          -- Pass on the asnd_lf_evt_dt
5837          --
5838          ,p_asnd_lf_evt_dt         => null
5839          -- ,p_popl_enrt_typ_cycl_id  => p_popl_enrt_typ_cycl_id
5840          ,p_no_programs            => p_no_programs
5841          ,p_no_plans               => p_no_plans
5842          ,p_rptg_grp_id            => p_rptg_grp_id
5843          ,p_pl_typ_id              => p_pl_typ_id
5844          ,p_opt_id                 => p_opt_id
5845          ,p_eligy_prfl_id          => p_eligy_prfl_id
5846          ,p_vrbl_rt_prfl_id        => p_vrbl_rt_prfl_id
5847          ,p_thread_id              => p_thread_id
5848          ,p_mode                   => p_mode
5849          );
5850        --
5851        -- Set up participation eligibility for all comp objects in the list
5852        --
5853        set_up_list_part_elig
5854          (p_ler_id            => null
5855          ,p_business_group_id => p_business_group_id
5856          ,p_effective_date    => l_effective_date
5857          );
5858        if g_debug then
5859          hr_utility.set_location (' Dn Temp BCOL '||l_package,10);
5860        end if;
5861        --
5862     end if;
5863     --
5864   end if;
5865   --
5866   -- Non Validate Mode process
5867   -- -------------------------
5868   -- The process is as follows :
5869   -- 1) Lock the rows that are not processed
5870   -- 2) Grab the start and end person action id.
5871   -- 3) Process the person range
5872   -- 4) Go to number 1 again.
5873   --
5874   loop
5875     if g_debug then
5876       hr_utility.set_location (l_package||' START process_rows loop  ',20);
5877     end if;
5878     --
5879     -- Chunk scheduling changes
5880     --
5881     if g_debug then
5882       hr_utility.set_location (l_package||' open c_range_thread  ',22);
5883     end if;
5884     ben_maintain_benefit_actions.grab_next_batch_range
5885       (p_benefit_action_id      => p_benefit_action_id
5886       --
5887       ,p_start_person_action_id => l_start_person_action_id
5888       ,p_end_person_action_id   => l_end_person_action_id
5889       ,p_rows_found             => l_rows_found
5890       );
5891     --
5892     if g_debug then
5893       hr_utility.set_location (l_package||' Done c_range_thread ',25);
5894     end if;
5895     --
5896     if not l_rows_found then
5897       --
5898       exit;
5899       --
5900     end if;
5901     --
5902     commit;
5903     --
5904     -- Bug 1387371: Added to cure memory leaking problems.
5905     --              The date dependent comp object list caches are flushed
5906     --              every 15 minutes.
5907     --
5908     if (sysdate-g_prev_sysdate) > (1/96) then
5909       --
5910       ben_pln_cache.clear_down_cache;
5911       ben_cop_cache.clear_down_cache;
5912       --
5913       g_prev_sysdate := sysdate;
5914       --
5915     end if;
5916     --
5917     if g_debug then
5918       hr_utility.set_location ('p_mode : '||p_mode,25);
5919     end if;
5920     process_rows
5921       (p_benefit_action_id        => p_benefit_action_id,
5922        p_start_person_action_id   => l_start_person_action_id,
5923        p_end_person_action_id     => l_end_person_action_id,
5924        p_business_group_id        => p_business_group_id,
5925        p_mode                     => p_mode,
5926        p_person_selection_rule_id => p_person_selection_rule_id,
5927        p_comp_selection_rule_id   => p_comp_selection_rule_id,
5928        --
5929        -- PB : 5422 :
5930        -- Following parameter is no longer needed,
5931        --
5932        -- p_popl_enrt_typ_cycl_id    => p_popl_enrt_typ_cycl_id,
5933        p_derivable_factors        => p_derivable_factors,
5934        p_cbr_tmprl_evt_flag       => p_cbr_tmprl_evt_flag,
5935        p_person_count             => l_person_count,
5936        p_error_person_count       => l_error_person_count,
5937        p_thread_id                => p_thread_id,
5938        p_validate                 => p_validate,
5939        p_effective_date           => l_effective_date,
5940        p_lf_evt_ocrd_dt           => l_lf_evt_ocrd_dt,
5941        p_gsp_eval_elig_flag       => p_gsp_eval_elig_flag,      /* GSP Rate Sync */
5942        p_lf_evt_oper_cd           => p_lf_evt_oper_cd           /* GSP Rate Sync */
5943        );
5944     --
5945     if g_debug then
5946       hr_utility.set_location (l_package||' END process_rows loop  ',50);
5947     end if;
5948   end loop;
5949   if g_debug then
5950     hr_utility.set_location (l_package||' Dn process_rows loop  ',50);
5951   end if;
5952   --
5953   -- Output log information to log file
5954   --
5955   write_logfile(p_benefit_action_id  => p_benefit_action_id,
5956                 p_thread_id          => p_thread_id,
5957                 p_validate           => p_validate,
5958                 p_person_count       => l_person_count,
5959                 p_error_person_count => l_error_person_count);
5960   --
5961   ben_maintain_benefit_actions.check_all_slaves_finished
5962     (p_benefit_action_id => p_benefit_action_id
5963     ,p_business_group_id => p_business_group_id
5964     ,p_slave_errored     => l_slave_errored
5965     );
5966   --
5967   if l_slave_errored  then
5968     --
5969     fnd_message.raise_error;
5970     --
5971   end if;
5972   --
5973   if g_debug then
5974     hr_utility.set_location ('Leaving '||l_package,10);
5975   end if;
5976   --
5977 exception
5978   --
5979   when g_record_error then
5980      if g_debug then
5981        hr_utility.set_location (l_package||' Exception g_record_error ',50);
5982      end if;
5983      benutils.write(p_text => fnd_message.get);
5984       --
5985       -- Write the last bit of information for the thread
5986       --
5987       benutils.write_table_and_file(p_table => true,
5988                                     p_file  => true);
5989       commit;
5990       --
5991       -- Output log information to log file
5992       --
5993       write_logfile(p_benefit_action_id  => p_benefit_action_id,
5994                     p_thread_id          => p_thread_id,
5995                     p_validate           => 'Y',
5996                     p_person_count       => l_person_count,
5997                     p_error_person_count => l_error_person_count);
5998 
5999       ben_maintain_benefit_actions.check_all_slaves_finished
6000         (p_benefit_action_id => p_benefit_action_id
6001         ,p_business_group_id => p_business_group_id
6002         ,p_slave_errored     => l_slave_errored
6003         );
6004   --
6005   when others then
6006     --
6007     if not l_slave_errored then
6008       --
6009       if g_debug then
6010         hr_utility.set_location (l_package||' OTHERS Exc ',60);
6011       end if;
6012       rollback;
6013       if g_debug then
6014         hr_utility.set_location ('BENMNGLE Super Error '||l_package,10);
6015       end if;
6016       g_rec.rep_typ_cd := 'FATAL';
6017       g_rec.text := nvl(fnd_message.get,sqlerrm);
6018       if g_debug then
6019         hr_utility.set_location(substr(g_rec.text,1,100),10);
6020       end if;
6021       benutils.write(p_rec => g_rec);
6022       --
6023       -- Output log information to log file
6024       --
6025       write_logfile(p_benefit_action_id  => p_benefit_action_id,
6026                     p_thread_id          => p_thread_id,
6027                     p_validate           => 'Y',
6028                     p_person_count       => l_person_count,
6029                     p_error_person_count => l_error_person_count);
6030       --
6031       ben_maintain_benefit_actions.check_all_slaves_finished
6032         (p_benefit_action_id => p_benefit_action_id
6033         ,p_business_group_id => p_business_group_id
6034         ,p_slave_errored     => l_slave_errored
6035         );
6036       --
6037     end if;
6038     --
6039     -- Set generic system error with oracle SQLCODE as the token
6040     --
6041     fnd_message.set_name('BEN','BEN_91665_BENMNGLE_ERRORED');
6042     fnd_message.set_token('ORA_ERRCODE',SQLCODE);
6043     --
6044     benutils.write(p_text => fnd_message.get);
6045     benutils.write_table_and_file(p_table => true,
6046                                   p_file  => true);
6047     commit;
6048     if g_debug then
6049       hr_utility.set_location ('Others error '||l_package,100);
6050     end if;
6051     fnd_message.raise_error;
6052     --
6053 end do_multithread;
6054 --
6055 procedure restart
6056           (errbuf                     out nocopy varchar2,
6057            retcode                    out nocopy number,
6058            p_benefit_action_id        in  number) is
6059   --
6060   l_package        varchar2(80);
6061   --
6062   cursor c_parameters is
6063     select process_date,
6064            mode_cd,
6065            derivable_factors_flag,
6066            validate_flag,
6067            person_id,
6068            person_type_id,
6069            pgm_id,
6070            business_group_id,
6071            pl_id,
6072            --
6073            -- PB : 5422 : No longer needed.
6074            -- popl_enrt_typ_cycl_id,
6075            --
6076            no_programs_flag,
6077            no_plans_flag,
6078            comp_selection_rl,
6079            person_selection_rl,
6080            ler_id,
6081            organization_id,
6082            benfts_grp_id,
6083            location_id,
6084            pstl_zip_rng_id,
6085            rptg_grp_id,
6086            pl_typ_id,
6087            opt_id,
6088            eligy_prfl_id,
6089            vrbl_rt_prfl_id,
6090            legal_entity_id,
6091            payroll_id,
6092            audit_log_flag,
6093            debug_messages_flag,
6094            -- PB : 5422 :
6095            -- Add lf_evt_ocrd_dt
6096            lf_evt_ocrd_dt,
6097            lmt_prpnip_by_org_flag,
6098            inelg_action_cd
6099     from   ben_benefit_actions ben
6100     where  ben.benefit_action_id = p_benefit_action_id;
6101   --
6102   l_parameters c_parameters%rowtype;
6103   l_errbuf     varchar2(80);
6104   l_retcode    number;
6105   --
6106 begin
6107   --
6108   g_debug := hr_utility.debug_enabled;
6109   if g_debug then
6110     l_package := g_package||'.restart';
6111     hr_utility.set_location ('Entering '||l_package,10);
6112   end if;
6113   --
6114   -- get the parameters for a previous run and do a restart
6115   --
6116   open c_parameters;
6117     --
6118     fetch c_parameters into l_parameters;
6119     if c_parameters%notfound then
6120       --
6121       fnd_message.set_name('BEN','BEN_91666_BENMNGLE_NO_RESTART');
6122       fnd_message.raise_error;
6123       --
6124     end if;
6125     --
6126   close c_parameters;
6127   --
6128   -- Call process procedure with parameters for restart
6129   --
6130   process
6131     (errbuf                     => l_errbuf,
6132      retcode                    => l_retcode,
6133      p_benefit_action_id        => p_benefit_action_id,
6134      p_effective_date           => fnd_date.date_to_canonical(l_parameters.process_date),
6135      p_mode                     => l_parameters.mode_cd,
6136      p_derivable_factors        => l_parameters.derivable_factors_flag,
6137      p_validate                 => l_parameters.validate_flag,
6138      p_person_id                => l_parameters.person_id,
6139      p_person_type_id           => l_parameters.person_type_id,
6140      p_pgm_id                   => l_parameters.pgm_id,
6141      p_business_group_id        => l_parameters.business_group_id,
6142      p_pl_id                    => l_parameters.pl_id,
6143      -- PB : 5422 :
6144      -- p_popl_enrt_typ_cycl_id    => l_parameters.popl_enrt_typ_cycl_id,
6145      p_no_programs              => l_parameters.no_programs_flag,
6146      p_no_plans                 => l_parameters.no_plans_flag,
6147      p_comp_selection_rule_id   => l_parameters.comp_selection_rl,
6148      p_person_selection_rule_id => l_parameters.person_selection_rl,
6149      p_ler_id                   => l_parameters.ler_id,
6150      p_organization_id          => l_parameters.organization_id,
6151      p_benfts_grp_id            => l_parameters.benfts_grp_id,
6152      p_location_id              => l_parameters.location_id,
6153      p_pstl_zip_rng_id          => l_parameters.pstl_zip_rng_id,
6154      p_rptg_grp_id              => l_parameters.rptg_grp_id,
6155      p_pl_typ_id                => l_parameters.pl_typ_id,
6156      p_opt_id                   => l_parameters.opt_id,
6157      p_eligy_prfl_id            => l_parameters.eligy_prfl_id,
6158      p_vrbl_rt_prfl_id          => l_parameters.vrbl_rt_prfl_id,
6159      p_legal_entity_id          => l_parameters.legal_entity_id,
6160      p_payroll_id               => l_parameters.payroll_id,
6161      p_commit_data              => 'Y',
6162      p_audit_log_flag           => l_parameters.audit_log_flag,
6163      p_cbr_tmprl_evt_flag       => l_parameters.debug_messages_flag,--cobra
6164      p_abs_historical_mode      => l_parameters.inelg_action_cd,
6165      p_lmt_prpnip_by_org_flag   => l_parameters.lmt_prpnip_by_org_flag,
6166      -- PB : 5422 :
6167      -- Now pass on the lf_evt_ocrd_dt
6168      p_lf_evt_ocrd_dt           => fnd_date.date_to_canonical(l_parameters.lf_evt_ocrd_dt));
6169   --
6170   -- The p_lf_evt_ocrd_dt needs to use lf_evt_ocrd_dt but that needs a schema
6171   -- change.
6172   --
6173   if g_debug then
6174     hr_utility.set_location ('Leaving '||l_package,10);
6175   end if;
6176   --
6177 end restart;
6178 --
6179 -- wrapper for procedure process
6180 --
6181 procedure cwb_process
6182           (errbuf                     out nocopy varchar2,
6183            retcode                    out nocopy number,
6184            p_benefit_action_id        in number   default null,
6185            p_effective_date           in varchar2,
6186            p_mode                     in varchar2 default 'W',
6187            p_derivable_factors        in varchar2 default 'ASC',
6188            p_validate                 in varchar2 default 'N',
6189            p_person_id                in number   default null,
6190            p_pgm_id                   in number   default null,
6191            p_business_group_id        in number,
6192            p_pl_id                    in number   default null,
6193            p_popl_enrt_typ_cycl_id    in number   default null,
6194            p_lf_evt_ocrd_dt           in varchar2 default null,
6195            p_person_type_id           in number   default null,
6196            p_no_programs              in varchar2 default 'N',
6197            p_no_plans                 in varchar2 default 'N',
6198            p_comp_selection_rule_id   in number   default null,
6199            p_person_selection_rule_id in number   default null,
6200            p_ler_id                   in number   default null,
6201            p_organization_id          in number   default null,
6202            p_benfts_grp_id            in number   default null,
6203            p_location_id              in number   default null,
6204            p_pstl_zip_rng_id          in number   default null,
6205            p_rptg_grp_id              in number   default null,
6206            p_pl_typ_id                in number   default null,
6207            p_opt_id                   in number   default null,
6208            p_eligy_prfl_id            in number   default null,
6209            p_vrbl_rt_prfl_id          in number   default null,
6210            p_legal_entity_id          in number   default null,
6211            p_payroll_id               in number   default null,
6212            p_commit_data              in varchar2 default 'Y',
6213            p_audit_log_flag           in varchar2 default 'N',
6214            p_lmt_prpnip_by_org_flag   in varchar2 default 'N',
6215            p_cbr_tmprl_evt_flag       in varchar2 default 'N',
6216 	   p_cwb_person_type          in varchar2 default null) is
6217   --
6218   l_retcode number;
6219   l_errbuf  varchar2(1000);
6220   -- Bug 4394545 . This program is now cannot be submitted directly through SRS.
6221   l_exc_no_parent_req exception ;
6222   l_parent_req_id number ;
6223   l_temp BOOLEAN ;
6224   l_text varchar2(1000) ;
6225   --
6226   cursor c_get_parent_req_id is
6227    select parent_request_id
6228    from fnd_concurrent_requests
6229    where request_id = fnd_global.conc_request_id;
6230   --
6231 begin
6232   --
6233   g_debug := hr_utility.debug_enabled;
6234   --
6235     open c_get_parent_req_id ;
6236     fetch c_get_parent_req_id into l_parent_req_id ;
6237     close c_get_parent_req_id ;
6238     -- Check for Parent request 4394545
6239     if l_parent_req_id is not null and
6240        l_parent_req_id = '-1' then
6241       -- Submitted by user
6242       raise l_exc_no_parent_req;
6243       --
6244     else
6245      -- Submitted by another Conc program, Continue processing
6246       process
6247           (errbuf                     =>l_errbuf,
6248            retcode                    =>l_retcode,
6249            p_benefit_action_id        =>p_benefit_action_id ,
6250            p_effective_date           =>p_effective_date,
6251            p_mode                     =>p_mode,
6252            p_derivable_factors        =>p_derivable_factors,
6253            p_validate                 =>p_validate,
6254            p_person_id                =>p_person_id,
6255            p_person_type_id           =>p_person_type_id,
6256            p_pgm_id                   =>p_pgm_id,
6257            p_business_group_id        =>p_business_group_id,
6258            p_pl_id                    =>p_pl_id,
6259            p_popl_enrt_typ_cycl_id    =>p_popl_enrt_typ_cycl_id,
6260            p_lf_evt_ocrd_dt           =>p_lf_evt_ocrd_dt,
6261            p_no_programs              =>p_no_programs,
6262            p_no_plans                 =>p_no_plans,
6263            p_comp_selection_rule_id   =>p_comp_selection_rule_id,
6264            p_person_selection_rule_id =>p_person_selection_rule_id,
6265            p_ler_id                   =>p_ler_id,
6266            p_organization_id          =>p_organization_id,
6267            p_benfts_grp_id            =>p_benfts_grp_id,
6268            p_location_id              =>p_location_id,
6269            p_pstl_zip_rng_id          =>p_pstl_zip_rng_id,
6270            p_rptg_grp_id              =>p_rptg_grp_id,
6271            p_pl_typ_id                =>p_pl_typ_id,
6272            p_opt_id                   =>p_opt_id,
6273            p_eligy_prfl_id            =>p_eligy_prfl_id,
6274            p_vrbl_rt_prfl_id          =>p_vrbl_rt_prfl_id,
6275            p_legal_entity_id          =>p_legal_entity_id,
6276            p_payroll_id               =>p_payroll_id,
6277            p_commit_data              =>p_commit_data,
6278            p_audit_log_flag           =>p_audit_log_flag,
6279            p_lmt_prpnip_by_org_flag   =>p_lmt_prpnip_by_org_flag,
6280            p_cbr_tmprl_evt_flag       =>p_cbr_tmprl_evt_flag ,
6281 	   p_cwb_person_type          => p_cwb_person_type);
6282     --
6283     end if;
6284   --
6285 Exception
6286 when l_exc_no_parent_req then
6287   -- 4394545
6288   fnd_message.set_name('BEN','BEN_94272_COMOD_NO_SRS_SUBMIT');
6289   l_text := fnd_message.get ;
6290   FND_FILE.PUT_LINE(FND_FILE.LOG, l_text);
6291   l_temp := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR', l_text) ;
6292   --
6293 end cwb_process;
6294 --
6295 -- wrapper for CWB GLOBAL procedure process
6296 --
6297 procedure cwb_global_process
6298           (errbuf                     out nocopy varchar2,
6299            retcode                    out nocopy number,
6300            p_benefit_action_id        in number   default null,
6301            p_effective_date           in varchar2,
6302            p_mode                     in varchar2 default 'W',
6303            p_derivable_factors        in varchar2 default 'ASC',
6304            p_validate                 in varchar2 default 'N',
6305            p_person_id                in number   default null,
6306            p_pgm_id                   in number   default null,
6307            p_business_group_id        in number,
6308            p_pl_id                    in number   default null,
6309            p_popl_enrt_typ_cycl_id    in number   default null,
6310            p_lf_evt_ocrd_dt           in varchar2 default null,
6311            p_person_type_id           in number   default null,
6312            p_no_programs              in varchar2 default 'N',
6313            p_no_plans                 in varchar2 default 'N',
6314            p_comp_selection_rule_id   in number   default null,
6315            p_person_selection_rule_id in number   default null,
6316            p_ler_id                   in number   default null,
6317            p_organization_id          in number   default null,
6318            p_benfts_grp_id            in number   default null,
6319            p_location_id              in number   default null,
6320            p_pstl_zip_rng_id          in number   default null,
6321            p_rptg_grp_id              in number   default null,
6322            p_pl_typ_id                in number   default null,
6323            p_opt_id                   in number   default null,
6324            p_eligy_prfl_id            in number   default null,
6325            p_vrbl_rt_prfl_id          in number   default null,
6326            p_legal_entity_id          in number   default null,
6327            p_payroll_id               in number   default null,
6328            p_commit_data              in varchar2 default 'Y',
6329            p_audit_log_flag           in varchar2 default 'N',
6330            p_lmt_prpnip_by_org_flag   in varchar2 default 'N',
6331            p_cbr_tmprl_evt_flag       in varchar2 default 'N',
6332            p_trace_plans_flag         in varchar2 default 'N',
6333 	   p_cwb_person_type          in varchar2 default null,
6334            p_run_rollup_only          in varchar2 default 'N'    /* Bug 4875181 */
6335            ) is
6336   --
6337   l_retcode number;
6338   l_errbuf  varchar2(1000);
6339   l_commit number;
6340 begin
6341   --
6342   g_debug := hr_utility.debug_enabled;
6343   --
6344   -- Bug: 4128034. CWB Mode fnd_session needs to be set.
6345   if p_mode = 'W' then
6346     dt_fndate.change_ses_date
6347       (p_ses_date => fnd_date.canonical_to_date(p_effective_date)
6348       ,p_commit   => l_commit
6349       );
6350   end if;
6351   --
6352   ben_manage_cwb_life_events.global_process
6353           (errbuf                     =>l_errbuf,
6354            retcode                    =>l_retcode,
6355            p_benefit_action_id        =>p_benefit_action_id ,
6356            p_effective_date           =>p_effective_date,
6357            p_mode                     =>p_mode,
6358            p_derivable_factors        =>p_derivable_factors,
6359            p_validate                 =>p_validate,
6360            p_person_id                =>p_person_id,
6361            p_person_type_id           =>p_person_type_id,
6362            p_pgm_id                   =>p_pgm_id,
6363            p_business_group_id        =>p_business_group_id,
6364            p_pl_id                    =>p_pl_id,
6365            p_popl_enrt_typ_cycl_id    =>p_popl_enrt_typ_cycl_id,
6366            p_lf_evt_ocrd_dt           =>p_lf_evt_ocrd_dt,
6367            p_no_programs              =>p_no_programs,
6368            p_no_plans                 =>p_no_plans,
6369            p_comp_selection_rule_id   =>p_comp_selection_rule_id,
6370            p_person_selection_rule_id =>p_person_selection_rule_id,
6371            p_ler_id                   =>p_ler_id,
6372            p_organization_id          =>p_organization_id,
6373            p_benfts_grp_id            =>p_benfts_grp_id,
6374            p_location_id              =>p_location_id,
6375            p_pstl_zip_rng_id          =>p_pstl_zip_rng_id,
6376            p_rptg_grp_id              =>p_rptg_grp_id,
6377            p_pl_typ_id                =>p_pl_typ_id,
6378            p_opt_id                   =>p_opt_id,
6379            p_eligy_prfl_id            =>p_eligy_prfl_id,
6380            p_vrbl_rt_prfl_id          =>p_vrbl_rt_prfl_id,
6381            p_legal_entity_id          =>p_legal_entity_id,
6382            p_payroll_id               =>p_payroll_id,
6383            p_commit_data              =>p_commit_data,
6384            p_audit_log_flag           =>p_audit_log_flag,
6385            p_lmt_prpnip_by_org_flag   =>p_lmt_prpnip_by_org_flag,
6386            p_cbr_tmprl_evt_flag       =>p_cbr_tmprl_evt_flag,
6387            p_trace_plans_flag         =>p_trace_plans_flag,
6388 	   p_cwb_person_type          => p_cwb_person_type,
6389            p_run_rollup_only          =>p_run_rollup_only        /* Bug 4875181 */
6390            );
6391     --
6392 end cwb_global_process;
6393 --
6394 -- GRADE/STEP : wrapper header for G mode Operation Code = Progression
6395 --
6396 procedure grade_step_process
6397   (errbuf                        out nocopy varchar2
6398   ,retcode                       out nocopy number
6399   ,p_benefit_action_id        in     number   default null
6400   ,p_effective_date           in     varchar2
6401   ,p_mode                     in     varchar2 default 'G'
6402   ,p_derivable_factors        in     varchar2 default 'ASC'
6403   ,p_validate                 in     varchar2 default 'N'
6404   ,p_person_id                in     number   default null
6405   ,p_pgm_id                   in     number   default null
6406   ,p_business_group_id        in     number
6407   ,p_pl_id                    in     number   default null
6408   ,p_popl_enrt_typ_cycl_id    in     number   default null
6409   ,p_lf_evt_ocrd_dt           in     varchar2 default null
6410   ,p_person_type_id           in     number   default null
6411   ,p_no_programs              in     varchar2 default 'N'
6412   ,p_no_plans                 in     varchar2 default 'N'
6413   ,p_comp_selection_rule_id   in     number   default null
6414   ,p_person_selection_rule_id in     number   default null
6415   ,p_ler_id                   in     number   default null
6416   ,p_organization_id          in     number   default null
6417   ,p_benfts_grp_id            in     number   default null
6418   ,p_location_id              in     number   default null
6419   ,p_pstl_zip_rng_id          in     number   default null
6420   ,p_rptg_grp_id              in     number   default null
6421   ,p_pl_typ_id                in     number   default null
6422   ,p_opt_id                   in     number   default null
6423   ,p_eligy_prfl_id            in     number   default null
6424   ,p_vrbl_rt_prfl_id          in     number   default null
6425   ,p_legal_entity_id          in     number   default null
6426   ,p_payroll_id               in     number   default null
6427   -- GRADE/STEP : Added for grade/step benmngle
6428   ,p_org_heirarchy_id         in     number   default null
6429   ,p_org_starting_node_id     in     number   default null
6430   ,p_grade_ladder_id          in     number   default null
6431   ,p_asg_events_to_all_sel_dt in     varchar2 default null
6432   ,p_rate_id                  in     number   default null -- pay scale
6433   ,p_per_sel_dt_cd            in     varchar2 default null -- business rule
6434   ,p_per_sel_dt_from          in     varchar2 default null -- business rule date from
6435   ,p_per_sel_dt_to            in     varchar2 default null -- business rule date to
6436   ,p_per_sel_freq_cd          in     varchar2 default null -- 2940151
6437   ,p_year_from                in     number   default null -- business rule year from
6438   ,p_year_to                  in     number   default null -- business rule year to
6439   ,p_cagr_id                  in     number   default null -- Coll agreement id
6440   ,p_qual_type                in     number   default null
6441   ,p_qual_status              in     varchar2 default null
6442   -- 2940151
6443   ,p_id_flex_num              in     number   default null
6444   ,p_concat_segs              in     varchar2 default null
6445   -- end 2940151
6446   -- GRADE/STEP : End
6447   ,p_commit_data              in     varchar2 default 'Y'
6448   ,p_audit_log_flag           in     varchar2 default 'N'
6449   ,p_lmt_prpnip_by_org_flag   in     varchar2 default 'N'
6450   ,p_cbr_tmprl_evt_flag       in     varchar2 default 'N'
6451   )is
6452   --
6453   l_bin  binary_integer ;
6454   l_retcode number;
6455   l_errbuf  varchar2(1000);
6456 
6457 begin
6458   --
6459 --  hr_utility.trace_on(null, 'GSPRS');
6460   g_debug := hr_utility.debug_enabled;
6461 /*
6462 fnd_file.put_line(fnd_file.log,'p_benefit_action_id '||nvl(p_benefit_action_id, -1));
6463 fnd_file.put_line(fnd_file.log,'p_effective_date '||p_effective_date);
6464 fnd_file.put_line(fnd_file.log,'p_mode '||nvl(p_mode,'null'));
6465 fnd_file.put_line(fnd_file.log,'p_business_group_id '||p_business_group_id);
6466 fnd_file.put_line(fnd_file.log,'p_business_group_id '||p_business_group_id);
6467 fnd_file.put_line(fnd_file.log,'p_business_group_id '||p_business_group_id);
6468 fnd_file.put_line(fnd_file.log,'p_business_group_id '||p_business_group_id);
6469 fnd_file.put_line(fnd_file.log,'p_business_group_id '||p_business_group_id);
6470 fnd_file.put_line(fnd_file.log,'p_business_group_id '||p_business_group_id);
6471 fnd_file.put_line(fnd_file.log,'p_business_group_id '||p_business_group_id);
6472 fnd_file.put_line(fnd_file.log,'p_business_group_id '||p_business_group_id);
6473 fnd_file.put_line(fnd_file.log,'p_business_group_id '||p_business_group_id);
6474 fnd_file.put_line(fnd_file.log,'p_business_group_id '||p_business_group_id);
6475 fnd_file.put_line(fnd_file.log,'p_business_group_id '||p_business_group_id);
6476 fnd_file.put_line(fnd_file.log,'p_business_group_id '||p_business_group_id);
6477 fnd_file.put_line(fnd_file.log,'p_business_group_id '||p_business_group_id);
6478 
6479 
6480   hr_utility.set_location ('Before Step 1',20);
6481   hr_utility.set_location ('p_effective_date '||p_effective_date,20);
6482   hr_utility.set_location ('p_business_group_id '||p_business_group_id,20);
6483   hr_utility.set_location ('p_commit_data '||p_commit_data,20);
6484   hr_utility.set_location ('p_audit_log_flag '||p_audit_log_flag,20);
6485   hr_utility.set_location ('p_lmt_prpnip_by_org_flag '||p_lmt_prpnip_by_org_flag,20);
6486 */
6487   --
6488   process
6489           (errbuf                     =>l_errbuf,
6490            retcode                    =>l_retcode,
6491            p_benefit_action_id        =>p_benefit_action_id ,
6492            p_effective_date           =>p_effective_date,
6493            p_mode                     =>p_mode,
6494            p_derivable_factors        =>p_derivable_factors,
6495            p_validate                 =>p_validate,
6496            p_person_id                =>p_person_id,
6497            p_person_type_id           =>p_person_type_id,
6498            p_pgm_id                   =>p_pgm_id,
6499            p_business_group_id        =>p_business_group_id,
6500            p_pl_id                    =>p_pl_id,
6501            p_popl_enrt_typ_cycl_id    =>p_popl_enrt_typ_cycl_id,
6502            p_lf_evt_ocrd_dt           =>p_lf_evt_ocrd_dt,
6503            p_no_programs              =>p_no_programs,
6504            p_no_plans                 =>p_no_plans,
6505            p_comp_selection_rule_id   =>p_comp_selection_rule_id,
6506            p_person_selection_rule_id =>p_person_selection_rule_id,
6507            p_ler_id                   =>p_ler_id,
6508            p_organization_id          =>p_organization_id,
6509            p_benfts_grp_id            =>p_benfts_grp_id,
6510            p_location_id              =>p_location_id,
6511            p_pstl_zip_rng_id          =>p_pstl_zip_rng_id,
6512            p_rptg_grp_id              =>p_rptg_grp_id,
6513            p_pl_typ_id                =>p_pl_typ_id,
6514            p_opt_id                   =>p_opt_id,
6515            p_eligy_prfl_id            =>p_eligy_prfl_id,
6516            p_vrbl_rt_prfl_id          =>p_vrbl_rt_prfl_id,
6517            p_legal_entity_id          =>p_legal_entity_id,
6518            p_payroll_id               =>p_payroll_id,
6519            p_commit_data              =>p_commit_data,
6520            p_audit_log_flag           =>p_audit_log_flag,
6521            p_lmt_prpnip_by_org_flag   =>p_lmt_prpnip_by_org_flag,
6522            p_cbr_tmprl_evt_flag       =>p_cbr_tmprl_evt_flag ,
6523            -- passed these gsp parameters
6524            -- version 115.329
6525            p_org_heirarchy_id	      =>p_org_heirarchy_id,
6526            p_org_starting_node_id     =>p_org_starting_node_id,
6527            p_grade_ladder_id	      =>p_grade_ladder_id,
6528            p_asg_events_to_all_sel_dt =>p_asg_events_to_all_sel_dt,
6529            p_rate_id		      =>p_rate_id,
6530            p_per_sel_dt_cd	      =>p_per_sel_dt_cd,
6531            p_per_sel_dt_from	      => fnd_date.canonical_to_date(p_per_sel_dt_from),
6532            p_per_sel_dt_to	      => fnd_date.canonical_to_date(p_per_sel_dt_to),
6533            p_year_from		      =>p_year_from,
6534            p_year_to		      =>p_year_to,
6535            p_cagr_id		      =>p_cagr_id,
6536            p_qual_type		      =>p_qual_type,
6537            p_qual_status	      =>p_qual_status,
6538            -- 2940151
6539            p_per_sel_freq_cd      =>p_per_sel_freq_cd,
6540 	   p_concat_segs 	      =>p_concat_segs,
6541            p_gsp_eval_elig_flag       => 'Y',      /* GSP Rate Sync */
6542            p_lf_evt_oper_cd           => 'PROG'    /* GSP Rate Sync */
6543            -- end 2940151
6544            );
6545     --
6546 end grade_step_process;
6547 --
6548 -- GRADE/STEP : wrapper header for G mode Operation Code = Rate Synchronization
6549 -- GSP Rate Sync
6550 procedure grade_step_rate_sync_process
6551   (errbuf                        out nocopy varchar2
6552   ,retcode                       out nocopy number
6553   ,p_benefit_action_id        in     number   default null
6554   ,p_effective_date           in     varchar2
6555   ,p_mode                     in     varchar2 default 'G'
6556   ,p_derivable_factors        in     varchar2 default 'ASC'
6557   ,p_validate                 in     varchar2 default 'N'
6558   ,p_person_id                in     number   default null
6559   ,p_pgm_id                   in     number   default null
6560   ,p_business_group_id        in     varchar2
6561   ,p_person_type_id           in     number   default null
6562   ,p_comp_selection_rule_id   in     number   default null
6563   ,p_person_selection_rule_id in     number   default null
6564   ,p_organization_id          in     number   default null
6565   ,p_benfts_grp_id            in     number   default null
6566   ,p_location_id              in     number   default null
6567   ,p_pstl_zip_rng_id          in     number   default null
6568   ,p_rptg_grp_id              in     number   default null
6569   ,p_legal_entity_id          in     number   default null
6570   ,p_payroll_id               in     number   default null
6571   ,p_org_heirarchy_id         in     number   default null
6572   ,p_org_starting_node_id     in     number   default null
6573   ,p_grade_ladder_id          in     number   default null
6574   ,p_rate_id                  in     number   default null -- pay scale
6575   ,p_per_sel_dt_cd            in     varchar2 default null -- business rule
6576   ,p_per_sel_dt_from          in     varchar2 default null -- business rule date from
6577   ,p_per_sel_dt_to            in     varchar2 default null -- business rule date to
6578   ,p_per_sel_freq_cd          in     varchar2 default null -- 2940151
6579   ,p_year_from                in     number   default null -- business rule year from
6580   ,p_year_to                  in     number   default null -- business rule year to
6581   ,p_cagr_id                  in     number   default null -- Coll agreement id
6582   ,p_qual_type                in     number   default null
6583   ,p_qual_status              in     varchar2 default null
6584   ,p_id_flex_num              in     number   default null
6585   ,p_concat_segs              in     varchar2 default null
6586   ,p_commit_data              in     varchar2 default 'Y'
6587   ,p_gsp_eval_elig_flag       in     varchar2 default 'N' -- Evaluate Eligibility
6588   ,p_audit_log_flag           in     varchar2 default 'N'
6589   ,p_lmt_prpnip_by_org_flag   in     varchar2 default 'N'
6590   )is
6591   --
6592   l_bin  binary_integer ;
6593   l_retcode number;
6594   l_errbuf  varchar2(1000);
6595 
6596 begin
6597   --
6598 --  hr_utility.trace_on(null, 'GSPRS');
6599   g_debug := hr_utility.debug_enabled;
6600   --
6601   process
6602           (errbuf                     => l_errbuf,
6603            retcode                    => l_retcode,
6604            p_benefit_action_id        => p_benefit_action_id,
6605            p_effective_date           => p_effective_date,
6606            p_mode                     => p_mode,
6607            p_derivable_factors        => p_derivable_factors,
6608            p_validate                 => p_validate,
6609            p_person_id                => p_person_id,
6610            p_pgm_id                   => p_pgm_id,
6611            p_business_group_id        => p_business_group_id,
6612            p_person_type_id           => p_person_type_id,
6613            p_comp_selection_rule_id   => p_comp_selection_rule_id,
6614            p_person_selection_rule_id => p_person_selection_rule_id,
6615            p_organization_id          => p_organization_id,
6616            p_benfts_grp_id            => p_benfts_grp_id,
6617            p_location_id              => p_location_id,
6618            p_pstl_zip_rng_id          => p_pstl_zip_rng_id,
6619            p_rptg_grp_id              => p_rptg_grp_id,
6620            p_legal_entity_id          => p_legal_entity_id,
6621            p_payroll_id               => p_payroll_id,
6622            p_org_heirarchy_id	      => p_org_heirarchy_id,
6623            p_org_starting_node_id     => p_org_starting_node_id,
6624            p_grade_ladder_id	      => p_grade_ladder_id,
6625            p_rate_id		      => p_rate_id,
6626            p_per_sel_dt_cd	      => p_per_sel_dt_cd,
6627            p_per_sel_dt_from	      => p_per_sel_dt_from,
6628            p_per_sel_dt_to	      => p_per_sel_dt_to,
6629            p_per_sel_freq_cd          => p_per_sel_freq_cd,
6630            p_year_from		      => p_year_from,
6631            p_year_to		      => p_year_to,
6632            p_cagr_id		      => p_cagr_id,
6633            p_qual_type		      => p_qual_type,
6634            p_qual_status	      => p_qual_status,
6635 	   p_concat_segs 	      => p_concat_segs,
6636            p_commit_data              => p_commit_data,
6637            p_audit_log_flag           => p_audit_log_flag,
6638            p_lmt_prpnip_by_org_flag   => p_lmt_prpnip_by_org_flag,
6639            p_asg_events_to_all_sel_dt => p_effective_date, -- Pass Effective Date as PTNL Life Event Occurred Date
6640            p_gsp_eval_elig_flag       => p_gsp_eval_elig_flag,
6641            p_lf_evt_oper_cd           => 'SYNC'    -- Life Event Operation code for Rate Synchronization
6642            );
6643     hr_utility.trace_off;
6644     --
6645 end grade_step_rate_sync_process;
6646 --
6647 -- wrapper for procedure process - ABSENCES
6648 --
6649 procedure abse_process
6650           (errbuf                     out nocopy varchar2,
6651            retcode                    out nocopy number,
6652            p_benefit_action_id        in number   default null,
6653            p_effective_date           in varchar2,
6654            p_mode                     in varchar2 default 'M',
6655            p_derivable_factors        in varchar2 default 'ASC',
6656            p_validate                 in varchar2 default 'N',
6657            p_person_id                in number   default null,
6658            p_pgm_id                   in number   default null,
6659            p_business_group_id        in number,
6660            p_pl_id                    in number   default null,
6661            p_popl_enrt_typ_cycl_id    in number   default null,
6662            p_lf_evt_ocrd_dt           in varchar2 default null,
6663            p_person_type_id           in number   default null,
6664            p_no_programs              in varchar2 default 'N',
6665            p_no_plans                 in varchar2 default 'N',
6666            p_comp_selection_rule_id   in number   default null,
6667            p_person_selection_rule_id in number   default null,
6668            p_ler_id                   in number   default null,
6669            p_organization_id          in number   default null,
6670            p_benfts_grp_id            in number   default null,
6671            p_location_id              in number   default null,
6672            p_pstl_zip_rng_id          in number   default null,
6673            p_rptg_grp_id              in number   default null,
6674            p_pl_typ_id                in number   default null,
6675            p_opt_id                   in number   default null,
6676            p_eligy_prfl_id            in number   default null,
6677            p_vrbl_rt_prfl_id          in number   default null,
6678            p_legal_entity_id          in number   default null,
6679            p_payroll_id               in number   default null,
6680            p_commit_data              in varchar2 default 'Y',
6681            p_audit_log_flag           in varchar2 default 'N',
6682            p_lmt_prpnip_by_org_flag   in varchar2 default 'N',
6683            p_abs_historical_mode      in varchar2 default 'N',
6684            p_cbr_tmprl_evt_flag       in varchar2 default 'N') is
6685   --
6686   l_retcode number;
6687   l_errbuf  varchar2(1000);
6688 begin
6689   --
6690   g_debug := hr_utility.debug_enabled;
6691   --
6692   process
6693           (errbuf                     =>l_errbuf,
6694            retcode                    =>l_retcode,
6695            p_benefit_action_id        =>p_benefit_action_id ,
6696            p_effective_date           =>p_effective_date,
6697            p_mode                     =>p_mode,
6698            p_derivable_factors        =>p_derivable_factors,
6699            p_validate                 =>p_validate,
6700            p_person_id                =>p_person_id,
6701            p_person_type_id           =>p_person_type_id,
6702            p_pgm_id                   =>p_pgm_id,
6703            p_business_group_id        =>p_business_group_id,
6704            p_pl_id                    =>p_pl_id,
6705            p_popl_enrt_typ_cycl_id    =>p_popl_enrt_typ_cycl_id,
6706            p_lf_evt_ocrd_dt           =>p_lf_evt_ocrd_dt,
6707            p_no_programs              =>p_no_programs,
6708            p_no_plans                 =>p_no_plans,
6709            p_comp_selection_rule_id   =>p_comp_selection_rule_id,
6710            p_person_selection_rule_id =>p_person_selection_rule_id,
6711            p_ler_id                   =>p_ler_id,
6712            p_organization_id          =>p_organization_id,
6713            p_benfts_grp_id            =>p_benfts_grp_id,
6714            p_location_id              =>p_location_id,
6715            p_pstl_zip_rng_id          =>p_pstl_zip_rng_id,
6716            p_rptg_grp_id              =>p_rptg_grp_id,
6717            p_pl_typ_id                =>p_pl_typ_id,
6718            p_opt_id                   =>p_opt_id,
6719            p_eligy_prfl_id            =>p_eligy_prfl_id,
6720            p_vrbl_rt_prfl_id          =>p_vrbl_rt_prfl_id,
6721            p_legal_entity_id          =>p_legal_entity_id,
6722            p_payroll_id               =>p_payroll_id,
6723            p_commit_data              =>p_commit_data,
6724            p_audit_log_flag           =>p_audit_log_flag,
6725            p_lmt_prpnip_by_org_flag   =>p_lmt_prpnip_by_org_flag,
6726            p_cbr_tmprl_evt_flag       =>p_cbr_tmprl_evt_flag,
6727            p_abs_historical_mode      =>p_abs_historical_mode);
6728     --
6729 end abse_process;
6730 --
6731 -- iRec
6732 -- wrapper for procedure internal_process - iRecruitment
6733 --
6734 procedure irec_process
6735           (errbuf                     out nocopy varchar2,
6736            retcode                    out nocopy number,
6737            p_effective_date           in varchar2,
6738            p_mode                     in varchar2 default 'I',
6739            p_derivable_factors        in varchar2 default 'ASC',
6740            p_validate                 in varchar2 default 'N',
6741            p_person_id                in number   default null,
6742            p_pgm_id                   in number   default null,
6743            p_business_group_id        in number,
6744            p_pl_id                    in number   default null,
6745            p_popl_enrt_typ_cycl_id    in number   default null,
6746            p_lf_evt_ocrd_dt           in varchar2 default null,
6747            p_person_type_id           in number   default null,
6748            p_no_programs              in varchar2 default 'N',
6749            p_no_plans                 in varchar2 default 'N',
6750            p_comp_selection_rule_id   in number   default null,
6751            p_person_selection_rule_id in number   default null,
6752            p_ler_id                   in number   default null,
6753            p_organization_id          in number   default null,
6754            p_benfts_grp_id            in number   default null,
6755            p_location_id              in number   default null,
6756            p_pstl_zip_rng_id          in number   default null,
6757            p_rptg_grp_id              in number   default null,
6758            p_pl_typ_id                in number   default null,
6759            p_opt_id                   in number   default null,
6760            p_eligy_prfl_id            in number   default null,
6761            p_vrbl_rt_prfl_id          in number   default null,
6762            p_legal_entity_id          in number   default null,
6763            p_payroll_id               in number   default null,
6764            p_commit_data              in varchar2 default 'Y',
6765            p_audit_log_flag           in varchar2 default 'N',
6766            p_lmt_prpnip_by_org_flag   in varchar2 default 'N',
6767            p_abs_historical_mode      in varchar2 default 'N',
6768            p_cbr_tmprl_evt_flag       in varchar2 default 'N',
6769            p_assignment_id            in number   default null,
6770            p_offer_assignment_rec     in  per_all_assignments_f%rowtype) ----bug 4621751 irec2
6771        is
6772   --
6773   l_retcode     number;
6774   l_errbuf      varchar2(1000);
6775   l_benefit_action_id   number;
6776   l_old_data_migrator_mode varchar2(1) ;-- irec2
6777 
6778   --
6779   cursor c_irec_ass_rec is
6780   select ass.*
6781     from per_all_assignments_F ass
6782    where assignment_id = p_assignment_id
6783      and to_date(p_effective_date,'YYYY/MM/DD HH24:MI:SS') between ass.effective_start_date
6784                                                                and ass.effective_end_date;
6785 
6786   cursor c_irec_ass_rec_upd is
6787   select ass.*
6788     from per_all_assignments_F ass
6789    where assignment_id = p_assignment_id
6790      and to_date(p_effective_date,'YYYY/MM/DD HH24:MI:SS') between ass.effective_start_date
6791                                                                and ass.effective_end_date;
6792 
6793   --
6794 begin
6795   --
6796   g_debug := hr_utility.debug_enabled;
6797   --
6798   -- Bug 5857493
6799   if p_audit_log_flag ='Y' then
6800      ben_benbatch_persons.g_audit_flag := true;
6801   else
6802      ben_benbatch_persons.g_audit_flag := false;
6803   end if;
6804   --
6805   -- Populate global assignment record of the applicant being processed
6806   -- by BENMNGLE in mode I into g_irec_ass_rec
6807   -- irec2 : 1.  copy c_irec_ass_rec to g_irec_old_ass_rec
6808   --         2.  update per_all_assignments_F with p_offer_assignment_rec
6809   open c_irec_ass_rec;
6810     --
6811     fetch c_irec_ass_rec into ben_manage_life_events.g_irec_old_ass_rec; -- irec2
6812     if c_irec_ass_rec%notfound then
6813       --
6814       close c_irec_ass_rec;
6815       fnd_message.set_name('BEN','BEN_94027_NO_ACT_APL_ASS_FOUND');
6816       fnd_message.raise_error;
6817       --
6818     else -- begin irec2
6819      begin
6820      l_old_data_migrator_mode := hr_general.g_data_migrator_mode ;
6821      hr_general.g_data_migrator_mode := 'Y' ;
6822      -- update starts
6823      update per_all_assignments_F
6824         set
6825   BUSINESS_GROUP_ID              =   p_offer_assignment_rec.BUSINESS_GROUP_ID
6826  ,RECRUITER_ID                   =   p_offer_assignment_rec.RECRUITER_ID
6827  ,GRADE_ID                       =   p_offer_assignment_rec.GRADE_ID
6828  ,POSITION_ID                    =   p_offer_assignment_rec.POSITION_ID
6829  ,JOB_ID                         =   p_offer_assignment_rec.JOB_ID
6830  ,ASSIGNMENT_STATUS_TYPE_ID      =   p_offer_assignment_rec.ASSIGNMENT_STATUS_TYPE_ID
6831  ,PAYROLL_ID                     =   p_offer_assignment_rec.PAYROLL_ID
6832  ,LOCATION_ID                    =   p_offer_assignment_rec.LOCATION_ID
6833  ,PERSON_REFERRED_BY_ID          =   p_offer_assignment_rec.PERSON_REFERRED_BY_ID
6834  ,SUPERVISOR_ID                  =   p_offer_assignment_rec.SUPERVISOR_ID
6835  ,SPECIAL_CEILING_STEP_ID        =   p_offer_assignment_rec.SPECIAL_CEILING_STEP_ID
6836  ,PERSON_ID                      =   p_offer_assignment_rec.PERSON_ID
6837  ,RECRUITMENT_ACTIVITY_ID        =   p_offer_assignment_rec.RECRUITMENT_ACTIVITY_ID
6838  ,SOURCE_ORGANIZATION_ID         =   p_offer_assignment_rec.SOURCE_ORGANIZATION_ID
6839  ,ORGANIZATION_ID                =   p_offer_assignment_rec.ORGANIZATION_ID
6840  ,PEOPLE_GROUP_ID                =   p_offer_assignment_rec.PEOPLE_GROUP_ID
6841  ,SOFT_CODING_KEYFLEX_ID         =   p_offer_assignment_rec.SOFT_CODING_KEYFLEX_ID
6842  ,VACANCY_ID                     =   p_offer_assignment_rec.VACANCY_ID
6843  ,PAY_BASIS_ID                   =   p_offer_assignment_rec.PAY_BASIS_ID
6844  ,ASSIGNMENT_SEQUENCE		 =   p_offer_assignment_rec.ASSIGNMENT_SEQUENCE
6845  ,APPLICATION_ID                 =   p_offer_assignment_rec.APPLICATION_ID
6846  ,ASSIGNMENT_NUMBER              =   p_offer_assignment_rec.ASSIGNMENT_NUMBER
6847  ,CHANGE_REASON                  =   p_offer_assignment_rec.CHANGE_REASON
6848  ,COMMENT_ID                     =   p_offer_assignment_rec.COMMENT_ID
6849  ,DATE_PROBATION_END             =   p_offer_assignment_rec.DATE_PROBATION_END
6850  ,DEFAULT_CODE_COMB_ID           =   p_offer_assignment_rec.DEFAULT_CODE_COMB_ID
6851  ,EMPLOYMENT_CATEGORY            =   p_offer_assignment_rec.EMPLOYMENT_CATEGORY
6852  ,FREQUENCY                      =   p_offer_assignment_rec.FREQUENCY
6853  ,INTERNAL_ADDRESS_LINE          =   p_offer_assignment_rec.INTERNAL_ADDRESS_LINE
6854  ,MANAGER_FLAG                   =   p_offer_assignment_rec.MANAGER_FLAG
6855  ,NORMAL_HOURS                   =   p_offer_assignment_rec.NORMAL_HOURS
6856  ,PERF_REVIEW_PERIOD             =   p_offer_assignment_rec.PERF_REVIEW_PERIOD
6857  ,PERF_REVIEW_PERIOD_FREQUENCY   =   p_offer_assignment_rec.PERF_REVIEW_PERIOD_FREQUENCY
6858  ,PERIOD_OF_SERVICE_ID           =   p_offer_assignment_rec.PERIOD_OF_SERVICE_ID
6859  ,PROBATION_PERIOD               =   p_offer_assignment_rec.PROBATION_PERIOD
6860  ,PROBATION_UNIT                 =   p_offer_assignment_rec.PROBATION_UNIT
6861  ,SAL_REVIEW_PERIOD              =   p_offer_assignment_rec.SAL_REVIEW_PERIOD
6862  ,SAL_REVIEW_PERIOD_FREQUENCY    =   p_offer_assignment_rec.SAL_REVIEW_PERIOD_FREQUENCY
6863  ,SET_OF_BOOKS_ID                =   p_offer_assignment_rec.SET_OF_BOOKS_ID
6864  ,SOURCE_TYPE                    =   p_offer_assignment_rec.SOURCE_TYPE
6865  ,TIME_NORMAL_FINISH             =   p_offer_assignment_rec.TIME_NORMAL_FINISH
6866  ,TIME_NORMAL_START              =   p_offer_assignment_rec.TIME_NORMAL_START
6867  ,REQUEST_ID                     =   p_offer_assignment_rec.REQUEST_ID
6868  ,PROGRAM_APPLICATION_ID         =   p_offer_assignment_rec.PROGRAM_APPLICATION_ID
6869  ,PROGRAM_ID                     =   p_offer_assignment_rec.PROGRAM_ID
6870  ,PROGRAM_UPDATE_DATE            =   p_offer_assignment_rec.PROGRAM_UPDATE_DATE
6871  ,ASS_ATTRIBUTE_CATEGORY         =   p_offer_assignment_rec.ASS_ATTRIBUTE_CATEGORY
6872  ,ASS_ATTRIBUTE1                 =   p_offer_assignment_rec.ASS_ATTRIBUTE1
6873  ,ASS_ATTRIBUTE2                 =   p_offer_assignment_rec.ASS_ATTRIBUTE2
6874  ,ASS_ATTRIBUTE3                 =   p_offer_assignment_rec.ASS_ATTRIBUTE3
6875  ,ASS_ATTRIBUTE4                 =   p_offer_assignment_rec.ASS_ATTRIBUTE4
6876  ,ASS_ATTRIBUTE5                 =   p_offer_assignment_rec.ASS_ATTRIBUTE5
6877  ,ASS_ATTRIBUTE6                 =   p_offer_assignment_rec.ASS_ATTRIBUTE6
6878  ,ASS_ATTRIBUTE7                 =   p_offer_assignment_rec.ASS_ATTRIBUTE7
6879  ,ASS_ATTRIBUTE8                 =   p_offer_assignment_rec.ASS_ATTRIBUTE8
6880  ,ASS_ATTRIBUTE9                 =   p_offer_assignment_rec.ASS_ATTRIBUTE9
6881  ,ASS_ATTRIBUTE10                =   p_offer_assignment_rec.ASS_ATTRIBUTE10
6882  ,ASS_ATTRIBUTE11                =   p_offer_assignment_rec.ASS_ATTRIBUTE11
6883  ,ASS_ATTRIBUTE12                =   p_offer_assignment_rec.ASS_ATTRIBUTE12
6884  ,ASS_ATTRIBUTE13                =   p_offer_assignment_rec.ASS_ATTRIBUTE13
6885  ,ASS_ATTRIBUTE14                =   p_offer_assignment_rec.ASS_ATTRIBUTE14
6886  ,ASS_ATTRIBUTE15                =   p_offer_assignment_rec.ASS_ATTRIBUTE15
6887  ,ASS_ATTRIBUTE16                =   p_offer_assignment_rec.ASS_ATTRIBUTE16
6888  ,ASS_ATTRIBUTE17                =   p_offer_assignment_rec.ASS_ATTRIBUTE17
6889  ,ASS_ATTRIBUTE18                =   p_offer_assignment_rec.ASS_ATTRIBUTE18
6890  ,ASS_ATTRIBUTE19                =   p_offer_assignment_rec.ASS_ATTRIBUTE19
6891  ,ASS_ATTRIBUTE20                =   p_offer_assignment_rec.ASS_ATTRIBUTE20
6892  ,ASS_ATTRIBUTE21                =   p_offer_assignment_rec.ASS_ATTRIBUTE21
6893  ,ASS_ATTRIBUTE22                =   p_offer_assignment_rec.ASS_ATTRIBUTE22
6894  ,ASS_ATTRIBUTE23                =   p_offer_assignment_rec.ASS_ATTRIBUTE23
6895  ,ASS_ATTRIBUTE24                =   p_offer_assignment_rec.ASS_ATTRIBUTE24
6896  ,ASS_ATTRIBUTE25                =   p_offer_assignment_rec.ASS_ATTRIBUTE25
6897  ,ASS_ATTRIBUTE26                =   p_offer_assignment_rec.ASS_ATTRIBUTE26
6898  ,ASS_ATTRIBUTE27                =   p_offer_assignment_rec.ASS_ATTRIBUTE27
6899  ,ASS_ATTRIBUTE28                =   p_offer_assignment_rec.ASS_ATTRIBUTE28
6900  ,ASS_ATTRIBUTE29                =   p_offer_assignment_rec.ASS_ATTRIBUTE29
6901  ,ASS_ATTRIBUTE30                =   p_offer_assignment_rec.ASS_ATTRIBUTE30
6902  ,TITLE                          =   p_offer_assignment_rec.TITLE
6903  ,OBJECT_VERSION_NUMBER          =   p_offer_assignment_rec.OBJECT_VERSION_NUMBER
6904  ,BARGAINING_UNIT_CODE           =   p_offer_assignment_rec.BARGAINING_UNIT_CODE
6905  ,LABOUR_UNION_MEMBER_FLAG       =   p_offer_assignment_rec.LABOUR_UNION_MEMBER_FLAG
6906  ,HOURLY_SALARIED_CODE           =   p_offer_assignment_rec.HOURLY_SALARIED_CODE
6907  ,CONTRACT_ID                    =   p_offer_assignment_rec.CONTRACT_ID
6908  ,COLLECTIVE_AGREEMENT_ID        =   p_offer_assignment_rec.COLLECTIVE_AGREEMENT_ID
6909  ,CAGR_ID_FLEX_NUM               =   p_offer_assignment_rec.CAGR_ID_FLEX_NUM
6910  ,CAGR_GRADE_DEF_ID              =   p_offer_assignment_rec.CAGR_GRADE_DEF_ID
6911  ,ESTABLISHMENT_ID               =   p_offer_assignment_rec.ESTABLISHMENT_ID
6912  ,NOTICE_PERIOD                  =   p_offer_assignment_rec.NOTICE_PERIOD
6913  ,NOTICE_PERIOD_UOM              =   p_offer_assignment_rec.NOTICE_PERIOD_UOM
6914  ,EMPLOYEE_CATEGORY              =   p_offer_assignment_rec.EMPLOYEE_CATEGORY
6915  ,WORK_AT_HOME                   =   p_offer_assignment_rec.WORK_AT_HOME
6916  ,JOB_POST_SOURCE_NAME           =   p_offer_assignment_rec.JOB_POST_SOURCE_NAME
6917  ,POSTING_CONTENT_ID             =   p_offer_assignment_rec.POSTING_CONTENT_ID
6918  ,PERIOD_OF_PLACEMENT_DATE_START =   p_offer_assignment_rec.PERIOD_OF_PLACEMENT_DATE_START
6919  ,VENDOR_ID                      =   p_offer_assignment_rec.VENDOR_ID
6920  ,VENDOR_EMPLOYEE_NUMBER         =   p_offer_assignment_rec.VENDOR_EMPLOYEE_NUMBER
6921  ,VENDOR_ASSIGNMENT_NUMBER       =   p_offer_assignment_rec.VENDOR_ASSIGNMENT_NUMBER
6922  ,ASSIGNMENT_CATEGORY            =   p_offer_assignment_rec.ASSIGNMENT_CATEGORY
6923  ,PROJECT_TITLE                  =   p_offer_assignment_rec.PROJECT_TITLE
6924  ,APPLICANT_RANK                 =   p_offer_assignment_rec.APPLICANT_RANK
6925  ,GRADE_LADDER_PGM_ID            =   p_offer_assignment_rec.GRADE_LADDER_PGM_ID
6926  ,SUPERVISOR_ASSIGNMENT_ID       =   p_offer_assignment_rec.SUPERVISOR_ASSIGNMENT_ID
6927  ,VENDOR_SITE_ID                 =   p_offer_assignment_rec.VENDOR_SITE_ID
6928  ,PO_HEADER_ID                   =   p_offer_assignment_rec.PO_HEADER_ID
6929  ,PO_LINE_ID                     =   p_offer_assignment_rec.PO_LINE_ID
6930  ,PROJECTED_ASSIGNMENT_END       =   p_offer_assignment_rec.PROJECTED_ASSIGNMENT_END
6931 
6932  where assignment_id = p_assignment_id ;
6933  -- update ends
6934  hr_general.g_data_migrator_mode := l_old_data_migrator_mode ;
6935 
6936   -- move updated per_all_assignments_f record to g_irec_ass_rec.
6937   open c_irec_ass_rec_upd;
6938   fetch c_irec_ass_rec_upd into g_irec_ass_rec;
6939   close c_irec_ass_rec_upd;
6940 
6941   -- end irec2
6942   exception
6943     when others then
6944       raise;
6945   end;
6946 
6947  end if;
6948     --
6949   close c_irec_ass_rec;
6950   --
6951   --
6952   internal_process
6953           (errbuf                     =>l_errbuf,
6954            retcode                    =>l_retcode,
6955            p_benefit_action_id        =>l_benefit_action_id ,
6956            p_effective_date           =>p_effective_date,
6957            p_mode                     =>p_mode,
6958            p_derivable_factors        =>p_derivable_factors,
6959            p_validate                 =>p_validate,
6960            p_person_id                =>p_person_id,
6961            p_person_type_id           =>p_person_type_id,
6962            p_pgm_id                   =>p_pgm_id,
6963            p_business_group_id        =>p_business_group_id,
6964            p_pl_id                    =>p_pl_id,
6965            p_popl_enrt_typ_cycl_id    =>p_popl_enrt_typ_cycl_id,
6966            p_lf_evt_ocrd_dt           =>p_lf_evt_ocrd_dt,
6967            p_no_programs              =>p_no_programs,
6968            p_no_plans                 =>p_no_plans,
6969            p_comp_selection_rule_id   =>p_comp_selection_rule_id,
6970            p_person_selection_rule_id =>p_person_selection_rule_id,
6971            p_ler_id                   =>p_ler_id,
6972            p_organization_id          =>p_organization_id,
6973            p_benfts_grp_id            =>p_benfts_grp_id,
6974            p_location_id              =>p_location_id,
6975            p_pstl_zip_rng_id          =>p_pstl_zip_rng_id,
6976            p_rptg_grp_id              =>p_rptg_grp_id,
6977            p_pl_typ_id                =>p_pl_typ_id,
6978            p_opt_id                   =>p_opt_id,
6979            p_eligy_prfl_id            =>p_eligy_prfl_id,
6980            p_vrbl_rt_prfl_id          =>p_vrbl_rt_prfl_id,
6981            p_legal_entity_id          =>p_legal_entity_id,
6982            p_payroll_id               =>p_payroll_id,
6983            p_commit_data              =>p_commit_data,
6984            p_audit_log_flag           =>p_audit_log_flag,
6985            p_lmt_prpnip_by_org_flag   =>p_lmt_prpnip_by_org_flag,
6986            p_cbr_tmprl_evt_flag       =>p_cbr_tmprl_evt_flag,
6987            p_abs_historical_mode      =>p_abs_historical_mode
6988 	   );
6989     --
6990 end irec_process;
6991 --
6992 --
6993 procedure rebuild_heirarchy
6994           (p_pil_elctbl_chc_popl_id in number ) is
6995   --
6996   l_package    varchar2(80) := g_package||'.rebuild_heirarchy' ;
6997   -- Bug 2574791
6998   cursor c_pel is
6999      select pel.pl_id, pil.lf_evt_ocrd_dt, pel.business_group_id
7000      from ben_pil_elctbl_chc_popl pel
7001           ,ben_per_in_ler pil
7002      where pel.per_in_ler_id = pil.per_in_ler_id
7003        and pel.pil_elctbl_chc_popl_id = p_pil_elctbl_chc_popl_id;
7004   --
7005 begin
7006   --
7007   g_debug := hr_utility.debug_enabled;
7008   --
7009   -- Steps
7010   --
7011   -- 1. create pel,-1,-1 record for the p_pil_elctbl_chc_popl_id.
7012   -- 2. create pel,-1,-1 records for
7013   --    empoyees whose mgr_pel is = to  p_pil_elctbl_chc_popl_id.
7014   -- 3. Delete all records from hierarchy table of the managers of the
7015   --    p_pil_elctbl_chc_popl_id and the employees reporting to this
7016   --    p_pil_elctbl_chc_popl_id.
7017   -- 4. call the popu_pel_heir to rebuild the table.
7018   --
7019   -- 5. When the first direct reportee is added to a new Manager
7020   --    we need two insert a mgr_pel,0,0 with level 1
7021   --
7022  if p_pil_elctbl_chc_popl_id is not null then
7023   --
7024   -- Bug 2574791
7025   open c_pel;
7026   fetch c_pel into g_rebuild_pl_id, g_rebuild_lf_evt_ocrd_dt, g_rebuild_business_group_id;
7027   close c_pel;
7028 
7029   if g_debug then
7030     hr_utility.set_location ('Before Step 1',20);
7031   end if;
7032   --
7033   -- Step 1
7034   begin
7035     --
7036     insert into ben_cwb_hrchy (
7037        emp_pil_elctbl_chc_popl_id,
7038        mgr_pil_elctbl_chc_popl_id,
7039        lvl_num  )
7040     values (
7041        p_pil_elctbl_chc_popl_id,
7042        -1,
7043        -1 );
7044     --
7045     exception when no_data_found then
7046       --
7047       null;
7048       --
7049     when others then
7050     --
7051     null; -- raise ;
7052     --
7053   end;
7054   --
7055   if g_debug then
7056     hr_utility.set_location ('After Step 1',20);
7057     --
7058     hr_utility.set_location ('Before Step 2 ',20);
7059   end if;
7060   --
7061   --Step 2
7062   -- Don't insert for the pel,0,0 record since it is
7063   -- Already handled in Step 1 above.
7064   --
7065   declare
7066     cursor c_emp_repo is
7067               select
7068           emp_pil_elctbl_chc_popl_id
7069        from ben_cwb_hrchy
7070        where mgr_pil_elctbl_chc_popl_id = p_pil_elctbl_chc_popl_id
7071        and  lvl_num > 0;
7072   begin
7073     --
7074      for r_emp_repo in c_emp_repo loop
7075        --
7076        begin
7077        -- Bug 2574791
7078        insert into ben_cwb_hrchy (
7079           emp_pil_elctbl_chc_popl_id,
7080           mgr_pil_elctbl_chc_popl_id,
7081           lvl_num  )  values (r_emp_repo.emp_pil_elctbl_chc_popl_id, -1, -1);
7082        exception when others then
7083          null;
7084        end;
7085      end loop;
7086     --
7087   exception when no_data_found then
7088       --
7089       null;
7090       --
7091     when others then
7092     --
7093     raise ;
7094     --
7095   end;
7096   --
7097   if g_debug then
7098     hr_utility.set_location ('After Step 2 ',20);
7099     --
7100     hr_utility.set_location ('Before Step 3 ',20);
7101   end if;
7102   --
7103   begin
7104     --
7105     --First Delete the Managers in the Hierarchy
7106     --
7107     delete from ben_cwb_hrchy
7108     where emp_pil_elctbl_chc_popl_id = p_pil_elctbl_chc_popl_id
7109     and lvl_num >= 0;
7110     --
7111     -- Now delete the Employees reporting to this manager(if he is a manager).
7112     --
7113     delete from ben_cwb_hrchy
7114     where emp_pil_elctbl_chc_popl_id in (
7115                 select emp_pil_elctbl_chc_popl_id
7116                 from ben_cwb_hrchy
7117                 where mgr_pil_elctbl_chc_popl_id = p_pil_elctbl_chc_popl_id )
7118     and lvl_num >= 0;
7119     --
7120   exception when others then
7121     --
7122     raise ;
7123     --
7124   end;
7125   --
7126   if g_debug then
7127     hr_utility.set_location ('After  Step 3 ',20);
7128     --
7129     hr_utility.set_location ('Before Calling popu_pel_heir',20);
7130   end if;
7131   begin
7132     --
7133     ben_manage_life_events.popu_pel_heir ;
7134     --
7135   exception when others then
7136     --
7137     raise ;
7138     --
7139   end;
7140   --
7141   if g_debug then
7142     hr_utility.set_location ('Before Step 5',20);
7143   end if;
7144   --
7145   begin
7146     --
7147     insert into ben_cwb_hrchy(
7148        emp_pil_elctbl_chc_popl_id,
7149        mgr_pil_elctbl_chc_popl_id,
7150        lvl_num  )
7151       select
7152        distinct emp_pil_elctbl_chc_popl_id,
7153        emp_pil_elctbl_chc_popl_id,
7154        0
7155       from ben_cwb_hrchy cwb1
7156       where emp_pil_elctbl_chc_popl_id =
7157                    ( select mgr_pil_elctbl_chc_popl_id from ben_cwb_hrchy
7158                      where emp_pil_elctbl_chc_popl_id = p_pil_elctbl_chc_popl_id
7159                      and lvl_num = 1 )
7160       and not exists ( select null from ben_cwb_hrchy cwb2
7161                      where cwb1.emp_pil_elctbl_chc_popl_id = cwb2.emp_pil_elctbl_chc_popl_id
7162                      and lvl_num  = 0 ) ;
7163     --
7164     exception when no_data_found then
7165       --
7166       null;
7167       --
7168     when others then
7169     --
7170     raise ;
7171     --
7172   end;
7173   --
7174   -- Bug 2574791
7175   g_rebuild_pl_id            := null;
7176   g_rebuild_lf_evt_ocrd_dt   := null;
7177   g_rebuild_business_group_id := null;
7178   --
7179  end if;
7180   --
7181   if g_debug then
7182     hr_utility.set_location ('Afert Step 5',20);
7183     hr_utility.set_location ('After Calling popu_pel_heir',20);
7184   end if;
7185   --
7186   --
7187 end rebuild_heirarchy ;
7188 
7189 --
7190 -- Wrapper for Personnel Action mode
7191 
7192 procedure Personnel_action_process
7193           (errbuf                     out nocopy varchar2,
7194            retcode                    out nocopy number,
7195            p_benefit_action_id        in number   default null,
7196            p_effective_date           in varchar2,
7197            p_mode                     in varchar2,
7198            p_derivable_factors        in varchar2 default 'ASC',
7199            p_validate                 in varchar2 default 'N',
7200            p_person_id                in number   default null,
7201            p_person_type_id           in number   default null,
7202            p_pgm_id                   in number   default null,
7203            p_business_group_id        in number,
7204            p_pl_id                    in number   default null,
7205            p_popl_enrt_typ_cycl_id    in number   default null,
7206            p_lf_evt_ocrd_dt           in varchar2 default null,
7207            p_no_programs              in varchar2 default 'N',
7208            p_no_plans                 in varchar2 default 'N',
7209            p_comp_selection_rule_id   in number   default null,
7210            p_person_selection_rule_id in number   default null,
7211            p_ler_id                   in number   default null,
7212            p_organization_id          in number   default null,
7213            p_benfts_grp_id            in number   default null,
7214            p_location_id              in number   default null,
7215            p_pstl_zip_rng_id          in number   default null,
7216            p_rptg_grp_id              in number   default null,
7217            p_pl_typ_id                in number   default null,
7218            p_opt_id                   in number   default null,
7219            p_eligy_prfl_id            in number   default null,
7220            p_vrbl_rt_prfl_id          in number   default null,
7221            p_legal_entity_id          in number   default null,
7222            p_payroll_id               in number   default null,
7223            p_commit_data              in varchar2 default 'Y',
7224            p_audit_log_flag           in varchar2 default 'N',
7225            p_lmt_prpnip_by_org_flag   in varchar2 default 'N',
7226            p_cbr_tmprl_evt_flag       in varchar2 default 'N') is
7227   --
7228   l_retcode number;
7229   l_errbuf  varchar2(1000);
7230   --
7231 begin
7232   --
7233   g_debug := hr_utility.debug_enabled;
7234   --
7235   process
7236           (errbuf                     =>l_errbuf,
7237            retcode                    =>l_retcode,
7238            p_benefit_action_id        => null,
7239            p_effective_date           =>p_effective_date,
7240            p_mode                     =>p_mode,
7241            p_derivable_factors        =>'ASC',
7242            p_validate                 =>p_validate,
7243            p_person_id                =>p_person_id,
7244            p_person_type_id           =>p_person_type_id,
7245            p_pgm_id                   =>p_pgm_id,
7246            p_business_group_id        =>p_business_group_id,
7247            p_pl_id                    =>p_pl_id,
7248            p_popl_enrt_typ_cycl_id    =>p_popl_enrt_typ_cycl_id,
7249            p_lf_evt_ocrd_dt           =>p_lf_evt_ocrd_dt,
7250            p_no_programs              =>p_no_programs,
7251            p_no_plans                 =>p_no_plans,
7252            p_comp_selection_rule_id   =>p_comp_selection_rule_id,
7253            p_person_selection_rule_id =>p_person_selection_rule_id,
7254            p_ler_id                   =>p_ler_id,
7255            p_organization_id          =>p_organization_id,
7256            p_benfts_grp_id            =>p_benfts_grp_id,
7257            p_location_id              =>p_location_id,
7258            p_pstl_zip_rng_id          =>p_pstl_zip_rng_id,
7259            p_rptg_grp_id              =>p_rptg_grp_id,
7260            p_pl_typ_id                =>p_pl_typ_id,
7261            p_opt_id                   =>p_opt_id,
7262            p_eligy_prfl_id            =>p_eligy_prfl_id,
7263            p_vrbl_rt_prfl_id          =>p_vrbl_rt_prfl_id,
7264            p_legal_entity_id          =>p_legal_entity_id,
7265            p_payroll_id               =>p_payroll_id,
7266            p_commit_data              =>p_commit_data,
7267            p_audit_log_flag           =>p_audit_log_flag,
7268            p_lmt_prpnip_by_org_flag   =>p_lmt_prpnip_by_org_flag,
7269            p_cbr_tmprl_evt_flag       =>p_cbr_tmprl_evt_flag );
7270 end;
7271 ----
7272 procedure process_recalculate
7273           (errbuf                     out nocopy varchar2,
7274            retcode                    out nocopy number,
7275            p_benefit_action_id        in number   default null,
7276            p_effective_date           in varchar2,
7277            p_mode                     in varchar2,
7278            p_derivable_factors        in varchar2 default 'ASC',
7279            p_validate                 in varchar2 default 'N',
7280            p_person_id                in number   default null,
7281            p_person_type_id           in number   default null,
7282            p_pgm_id                   in number   default null,
7283            p_business_group_id        in number,
7284            p_pl_id                    in number   default null,
7285            p_popl_enrt_typ_cycl_id    in number   default null,
7286            p_lf_evt_ocrd_dt           in varchar2 default null,
7287            p_no_programs              in varchar2 default 'N',
7288            p_no_plans                 in varchar2 default 'N',
7289            p_comp_selection_rule_id   in number   default null,
7290            p_person_selection_rule_id in number   default null,
7291            p_ler_id                   in number   default null,
7292            p_organization_id          in number   default null,
7293            p_benfts_grp_id            in number   default null,
7294            p_location_id              in number   default null,
7295            p_pstl_zip_rng_id          in number   default null,
7296            p_rptg_grp_id              in number   default null,
7297            p_pl_typ_id                in number   default null,
7298            p_opt_id                   in number   default null,
7299            p_eligy_prfl_id            in number   default null,
7300            p_vrbl_rt_prfl_id          in number   default null,
7301            p_legal_entity_id          in number   default null,
7302            p_payroll_id               in number   default null,
7303            p_commit_data              in varchar2 default 'Y',
7304            p_audit_log_flag           in varchar2 default 'N',
7305            p_lmt_prpnip_by_org_flag   in varchar2 default 'N',
7306            p_cbr_tmprl_evt_flag       in varchar2 default 'N') is
7307   --
7308   l_retcode number;
7309   l_errbuf  varchar2(1000);
7310   --
7311 begin
7312   --
7313   g_debug := hr_utility.debug_enabled;
7314   --
7315   process
7316           (errbuf                     =>l_errbuf,
7317            retcode                    =>l_retcode,
7318            p_benefit_action_id        => null,
7319            p_effective_date           =>p_effective_date,
7320            p_mode                     =>p_mode,
7321            p_derivable_factors        =>'NONE',
7322            p_validate                 =>p_validate,
7323            p_person_id                =>p_person_id,
7324            p_person_type_id           =>p_person_type_id,
7325            p_pgm_id                   =>p_pgm_id,
7326            p_business_group_id        =>p_business_group_id,
7327            p_pl_id                    =>p_pl_id,
7328            p_popl_enrt_typ_cycl_id    =>p_popl_enrt_typ_cycl_id,
7329            p_lf_evt_ocrd_dt           =>p_lf_evt_ocrd_dt,
7330            p_no_programs              =>p_no_programs,
7331            p_no_plans                 =>p_no_plans,
7332            p_comp_selection_rule_id   =>p_comp_selection_rule_id,
7333            p_person_selection_rule_id =>p_person_selection_rule_id,
7334            p_ler_id                   =>p_ler_id,
7335            p_organization_id          =>p_organization_id,
7336            p_benfts_grp_id            =>p_benfts_grp_id,
7337            p_location_id              =>p_location_id,
7338            p_pstl_zip_rng_id          =>p_pstl_zip_rng_id,
7339            p_rptg_grp_id              =>p_rptg_grp_id,
7340            p_pl_typ_id                =>p_pl_typ_id,
7341            p_opt_id                   =>p_opt_id,
7342            p_eligy_prfl_id            =>p_eligy_prfl_id,
7343            p_vrbl_rt_prfl_id          =>p_vrbl_rt_prfl_id,
7344            p_legal_entity_id          =>p_legal_entity_id,
7345            p_payroll_id               =>p_payroll_id,
7346            p_commit_data              =>p_commit_data,
7347            p_audit_log_flag           =>p_audit_log_flag,
7348            p_lmt_prpnip_by_org_flag   =>p_lmt_prpnip_by_org_flag,
7349            p_cbr_tmprl_evt_flag       =>p_cbr_tmprl_evt_flag );
7350     --
7351   end;
7352 
7353 ----
7354     procedure internal_process
7355       (errbuf                        out nocopy varchar2
7356       ,retcode                       out nocopy number
7357       ,p_benefit_action_id        in out nocopy number
7358       ,p_effective_date           in     varchar2
7359       ,p_mode                     in     varchar2
7360       ,p_derivable_factors        in     varchar2 default 'ASC'
7361       ,p_validate                 in     varchar2 default 'N'
7362       ,p_person_id                in     number   default null
7363       ,p_person_type_id           in     number   default null
7364       ,p_pgm_id                   in     number   default null
7365       ,p_business_group_id        in     number
7366       ,p_pl_id                    in     number   default null
7367       ,p_popl_enrt_typ_cycl_id    in     number   default null
7368       ,p_lf_evt_ocrd_dt           in     varchar2 default null
7369       ,p_no_programs              in     varchar2 default 'N'
7370       ,p_no_plans                 in     varchar2 default 'N'
7371       ,p_comp_selection_rule_id   in     number   default null
7372       ,p_person_selection_rule_id in     number   default null
7373       ,p_ler_id                   in     number   default null
7374       ,p_organization_id          in     number   default null
7375       ,p_benfts_grp_id            in     number   default null
7376       ,p_location_id              in     number   default null
7377       ,p_pstl_zip_rng_id          in     number   default null
7378       ,p_rptg_grp_id              in     number   default null
7379       ,p_pl_typ_id                in     number   default null
7380       ,p_opt_id                   in     number   default null
7381       ,p_eligy_prfl_id            in     number   default null
7382       ,p_vrbl_rt_prfl_id          in     number   default null
7383       ,p_legal_entity_id          in     number   default null
7384       ,p_payroll_id               in     number   default null
7385       ,p_commit_data              in     varchar2 default 'Y'
7386       ,p_audit_log_flag           in     varchar2 default 'N'
7387       ,p_lmt_prpnip_by_org_flag   in     varchar2 default 'N'
7388       ,p_cbr_tmprl_evt_flag       in     varchar2 default 'N'
7389           -- GRADE/STEP : Added for grade/step benmngle
7390       ,p_org_heirarchy_id         in     number   default null
7391       ,p_org_starting_node_id     in     number   default null
7392       ,p_grade_ladder_id          in     number   default null
7393       ,p_asg_events_to_all_sel_dt in     varchar2 default null
7394       ,p_rate_id                  in     number   default null -- pay scale
7395       ,p_per_sel_dt_cd            in     varchar2 default null -- business rule
7396       ,p_per_sel_dt_from          in     date     default null -- business rule date from
7397       ,p_per_sel_dt_to            in     date     default null -- business rule date to
7398       ,p_year_from                in     number   default null -- business rule year from
7399       ,p_year_to                  in     number   default null -- business rule year to
7400       ,p_cagr_id                  in     number   default null -- Coll agreement id
7401       ,p_qual_type                in     number   default null
7402       ,p_qual_status              in     varchar2 default null
7403       -- 2940151
7404       ,p_per_sel_freq_cd          in     varchar2 default null
7405       ,p_concat_segs              in     varchar2 default null
7406       -- end 2940151
7407       ,p_abs_historical_mode      in     varchar2 default 'N'
7408       ,p_gsp_eval_elig_flag       in     varchar2 default null -- GSP Rate Sync : Evaluate Eligibility
7409       ,p_lf_evt_oper_cd           in     varchar2 default null -- GSP Rate Sync : Life Event Operation code
7410       ,p_cwb_person_type          in     varchar2 default null
7411       )
7412     is
7413       --
7414       l_package                varchar2(80);
7415       --
7416       l_effective_date         date;
7417       l_lf_evt_ocrd_dt         date;
7418       l_asg_events_to_all_sel_dt date;
7419       l_per_sel_dt_from          date;
7420       l_per_sel_dt_to            date;
7421       l_commit                 number;
7422       l_gsp_eval_elig_flag     varchar2(30);
7423       --
7424           -- Bug:2237993 CWB
7425           --
7426           l_person_id      per_all_people_f.person_id%type;
7427           cursor c_person_info is
7428            select person_id
7429            from ben_person_actions
7430            where benefit_action_id = p_benefit_action_id
7431                  and action_status_cd = 'P';
7432 
7433           cursor c_pln is
7434           select pl.trk_inelig_per_flag
7435             from ben_pl_f pl
7436            where pl.pl_id = p_pl_id
7437              and l_effective_date between pl.effective_start_date and
7438                  pl.effective_end_date;
7439           --
7440       cursor c_popl_enrt_typ_cycl is
7441         select ler.ler_id, pet.popl_enrt_typ_cycl_id
7442         from   ben_popl_enrt_typ_cycl_f pet,
7443            ben_enrt_perd enp,
7444            ben_ler_f ler
7445         where  enp.business_group_id  = p_business_group_id
7446         -- PB : 5422 :
7447         and    enp.asnd_lf_evt_dt  = l_lf_evt_ocrd_dt
7448         -- and    enp.enrt_perd_id = p_popl_enrt_typ_cycl_id
7449         and    enp.popl_enrt_typ_cycl_id = pet.popl_enrt_typ_cycl_id
7450         and    pet.business_group_id  = enp.business_group_id
7451         and    l_effective_date
7452            between pet.effective_start_date
7453            and     pet.effective_end_date
7454         -- CWB Changes
7455         and    ((ler.typ_cd = 'SCHEDD'||pet.enrt_typ_cycl_cd and p_mode = 'C')  or
7456             (ler.typ_cd = 'COMP' and p_mode = 'W')
7457            )
7458         -- CWB Changes end
7459         and    ler.business_group_id  = pet.business_group_id
7460         and    l_effective_date
7461            between ler.effective_start_date
7462            and     ler.effective_end_date
7463         -- CWB Change
7464         and    ((p_mode = 'W' and ler.ler_id = enp.ler_id
7465              and pet.pl_id = p_pl_id) or p_mode <> 'W');
7466       -- 2940151
7467       -- Grade Step- cursor for fetching people group kff structure
7468       --
7469       l_popl_enrt_typ_cycl_id number ;
7470       --
7471       cursor c_people_group_structure is
7472       select people_group_structure
7473       from per_business_groups
7474       where business_group_id = p_business_group_id;
7475       --
7476       l_id_flex_num per_business_groups.people_group_structure%TYPE;
7477       --
7478       --
7479       l_ler_override_id        number;
7480           l_trk_inelig_per_flag    ben_pl_f.trk_inelig_per_flag%type;
7481       l_request_id             number;
7482       l_object_version_number  ben_benefit_actions.object_version_number%type;
7483       l_benefit_action_id      ben_benefit_actions.benefit_action_id%type;
7484       l_chunk_size             number;
7485       l_threads                number;
7486       l_max_errors             number;
7487       l_num_ranges             number := 0;
7488       l_num_persons            number := 0;
7489       l_person_action_id       number;
7490       l_range_id               number;
7491       l_ler_rec                benutils.g_ler;
7492       l_retcode                number;
7493       l_errbuf                 varchar2(1000);
7494       l_no_one_to_process      exception;          -- Bug 3870204
7495       -- iRec
7496       l_ler_id                 number;
7497       --
7498       --
7499     begin
7500       --
7501         g_debug := hr_utility.debug_enabled;
7502         l_package := g_package||'.internal_process';
7503         if g_debug then
7504           hr_utility.set_location ('Entering '||l_package,10);
7505           hr_utility.set_location ('p_mode : '||p_mode,5);
7506         end if;
7507         --
7508         g_derivable_factors := p_derivable_factors;
7509       --
7510       -- Convert varchar2 dates to real dates
7511       -- 1) First remove time component
7512       -- 2) Next convert format
7513       /*
7514       l_effective_date := to_date(p_effective_date,'YYYY/MM/DD HH24:MI:SS');
7515       l_effective_date := to_date(to_char(trunc(l_effective_date),'DD/MM/RRRR'),'DD/MM/RRRR');
7516       l_lf_evt_ocrd_dt := to_date(p_lf_evt_ocrd_dt,'YYYY/MM/DD HH24:MI:SS');
7517       l_lf_evt_ocrd_dt := to_date(to_char(trunc(l_lf_evt_ocrd_dt),'DD/MM/RRRR'),'DD/MM/RRRR');
7518       */
7519       l_effective_date := trunc(fnd_date.canonical_to_date(p_effective_date));
7520       l_lf_evt_ocrd_dt := trunc(fnd_date.canonical_to_date(p_lf_evt_ocrd_dt));
7521           --
7522           if p_asg_events_to_all_sel_dt is not null then
7523              /*
7524              l_asg_events_to_all_sel_dt := to_date(p_asg_events_to_all_sel_dt,'YYYY/MM/DD HH24:MI:SS');
7525              l_asg_events_to_all_sel_dt := to_date(to_char(trunc(l_asg_events_to_all_sel_dt),'DD/MM/RRRR'),'DD/MM/RRRR');
7526              */
7527              l_asg_events_to_all_sel_dt := trunc(fnd_date.canonical_to_date(p_asg_events_to_all_sel_dt));
7528              --
7529           end if;
7530           --
7531           if p_per_sel_dt_from is not null then
7532              --
7533              /*
7534              l_per_sel_dt_from := to_date(p_per_sel_dt_from,'YYYY/MM/DD HH24:MI:SS');
7535              l_per_sel_dt_from := to_date(to_char(trunc(l_per_sel_dt_from),'DD/MM/RRRR'),'DD/MM/RRRR');
7536              */
7537              l_per_sel_dt_from :=trunc(p_per_sel_dt_from);
7538              --
7539           end if;
7540           --
7541           if p_per_sel_dt_to is not null then
7542              --
7543              /*
7544              l_per_sel_dt_to := to_date(p_per_sel_dt_to,'YYYY/MM/DD HH24:MI:SS');
7545              l_per_sel_dt_to := to_date(to_char(trunc(l_per_sel_dt_to),'DD/MM/RRRR'),'DD/MM/RRRR');
7546              */
7547              l_per_sel_dt_to := trunc(p_per_sel_dt_to);
7548              --
7549           end if;
7550       --
7551       -- Put row in fnd_sessions
7552       --
7553       dt_fndate.change_ses_date
7554         (p_ses_date => nvl(l_lf_evt_ocrd_dt,l_effective_date),
7555          p_commit   => l_commit);
7556       --
7557       -- Log start time of process
7558       --
7559           ben_manage_life_events.init_bft_statistics
7560             (p_business_group_id => p_business_group_id
7561             );
7562       -- GSP Rate Sync
7563       if p_mode = 'G' and p_gsp_eval_elig_flag is null
7564       then
7565         --
7566 	if p_lf_evt_oper_cd = 'SYNC'
7567 	then
7568 	  l_gsp_eval_elig_flag := 'N';
7569 	else
7570 	  l_gsp_eval_elig_flag := 'Y';
7571 	end if;
7572 	--
7573       else
7574         --
7575 	l_gsp_eval_elig_flag := p_gsp_eval_elig_flag;
7576 	--
7577       end if;
7578       --
7579       --
7580       -- Check that business rules that apply to BENMNGLE are being adhered to.
7581       --
7582       check_business_rules
7583         (p_business_group_id        => p_business_group_id,
7584          p_derivable_factors        => p_derivable_factors,
7585          p_validate                 => p_validate,
7586          p_no_programs              => p_no_programs,
7587          p_no_plans                 => p_no_plans,
7588          p_mode                     => p_mode,
7589          p_effective_date           => l_effective_date,
7590          p_person_id                => p_person_id,
7591          p_person_selection_rule_id => p_person_selection_rule_id,
7592          p_person_type_id           => p_person_type_id,
7593          p_pgm_id                   => p_pgm_id,
7594          p_pl_id                    => p_pl_id,
7595          p_ler_id                   => p_ler_id,
7596          p_pl_typ_id                => p_pl_typ_id,
7597          p_opt_id                   => p_opt_id,
7598          p_lf_evt_ocrd_dt           => l_lf_evt_ocrd_dt,
7599              -- Grade/Step progression
7600              p_org_heirarchy_id         => p_org_heirarchy_id,
7601              p_org_starting_node_id     => p_org_starting_node_id,
7602              p_asg_events_to_all_sel_dt => l_asg_events_to_all_sel_dt,
7603              p_per_sel_dt_cd            => p_per_sel_dt_cd,
7604              p_per_sel_dt_from          => l_per_sel_dt_from,
7605              p_per_sel_dt_to            => l_per_sel_dt_to,
7606              p_year_from                => p_year_from,
7607              p_year_to                  => p_year_to,
7608              p_qual_type                => p_qual_type,
7609              p_qual_status              => p_qual_status,
7610              p_lf_evt_oper_cd           => p_lf_evt_oper_cd    /* GSP Rate Sync */
7611             );
7612 
7613          -- p_popl_enrt_typ_cycl_id    => p_popl_enrt_typ_cycl_id);
7614         if g_debug then
7615         hr_utility.set_location (l_package||' Check business rules',20);
7616         end if;
7617       --
7618       -- Get ler_id for Unrestricted Mode and store it in globle variable so that procedures down the road can
7619       -- access it
7620        --
7621        benutils.get_ler
7622           (p_business_group_id     => p_business_group_id,
7623            p_typ_cd                => 'SCHEDDU',
7624            p_effective_date        => l_effective_date,
7625            p_rec                   => l_ler_rec);
7626         --
7627         g_ler_id := l_ler_rec.ler_id;
7628        --
7629      -- iRec
7630       if p_mode = 'I' then
7631         --
7632         -- Set G_LER_ID to iRecruitment LER_ID for subsequent use in ben_evaluate_ptnl_lf_evt
7633          --
7634         benutils.get_ler (p_business_group_id      => p_business_group_id,
7635                           p_typ_cd                 => 'IREC',
7636                           p_effective_date         => l_effective_date,
7637                           p_rec                    => l_ler_rec
7638                          );
7639         --
7640        g_ler_id := l_ler_rec.ler_id;
7641         --
7642       end if;
7643       -- iRec
7644       --
7645       -- Get override ler_id for Scheduled mode.
7646       --
7647       -- CWB Changes
7648       --
7649       if p_mode in  ('C', 'W') and
7650         p_lf_evt_ocrd_dt is not null then
7651         -- PB : 5422 :
7652         -- p_popl_enrt_typ_cycl_id is not null then
7653         --
7654         open c_popl_enrt_typ_cycl;
7655           --
7656           fetch c_popl_enrt_typ_cycl into l_ler_override_id, l_popl_enrt_typ_cycl_id;
7657           if c_popl_enrt_typ_cycl%notfound then
7658         --
7659         close c_popl_enrt_typ_cycl;
7660         fnd_message.set_name('BEN','BEN_91668_NO_FIND_POPL_ENRT');
7661         fnd_message.raise_error;
7662         --
7663           end if;
7664           --
7665         close c_popl_enrt_typ_cycl;
7666 
7667           if g_debug then
7668           hr_utility.set_location (l_popl_enrt_typ_cycl_id || ' Done c_popl_enrt_typ_cycl ',30);
7669           hr_utility.set_location (p_popl_enrt_typ_cycl_id || ' Done c_popl_enrt_typ_cycl ',30);
7670           end if;
7671         --
7672       end if;
7673       --
7674       -- Get ler id for unrestricted
7675       --
7676       if p_mode in ('U','D') then
7677         --
7678         benutils.get_ler
7679           (p_business_group_id     => p_business_group_id,
7680            p_typ_cd                => 'SCHEDDU',
7681            p_effective_date        => l_effective_date,
7682            p_rec                   => l_ler_rec);
7683         --
7684         l_ler_override_id := l_ler_rec.ler_id;
7685 	--
7686           if g_debug then
7687           hr_utility.set_location (l_package||' benutils.get_ler ',30);
7688           end if;
7689         --
7690       end if;
7691 /*
7692           --
7693           -- Get ler id for Grade/Step
7694           --
7695           if p_mode = 'G' then
7696             --
7697             benutils.get_ler
7698               (p_business_group_id     => p_business_group_id,
7699                p_typ_cd                => 'GSP',
7700                p_effective_date        => l_effective_date,
7701                p_rec                   => l_ler_rec);
7702             --
7703             l_ler_override_id := l_ler_rec.ler_id;
7704             --
7705             if g_debug then
7706               hr_utility.set_location (l_package||' benutils.get_ler ',31);
7707             end if;
7708           end if;
7709 */
7710       --
7711       -- Get parameters so we know how many slaves to start and what size the
7712       -- chunk size we will be processing is.
7713       --
7714         if g_debug then
7715         hr_utility.set_location (l_package||' get_parameter',20);
7716         end if;
7717        /* Start: CWB Thread Num Enhancement */
7718         if(p_mode = 'W') then
7719           benutils.get_parameter(p_business_group_id => p_business_group_id,
7720                                  p_batch_exe_cd      => 'BENGCMOD',
7721                                  p_threads           => l_threads,
7722                                  p_chunk_size        => l_chunk_size,
7723                                  p_max_errors        => l_max_errors);
7724         else
7725           benutils.get_parameter(p_business_group_id => p_business_group_id,
7726 		  	         p_batch_exe_cd      => 'BENMNGLE',
7727 		                 p_threads           => l_threads,
7728 		                 p_chunk_size        => l_chunk_size,
7729 		                 p_max_errors        => l_max_errors);
7730         end if;
7731        /* End: CWB Thread Num Enhancement */
7732         if g_debug then
7733         hr_utility.set_location (l_package||' Done get pm ',30);
7734         --
7735         hr_utility.set_location('Num Threads = '||l_threads,10);
7736         hr_utility.set_location('Chunk Size = '||l_chunk_size,10);
7737         hr_utility.set_location('Max Errors = '||l_max_errors,10);
7738         --
7739         end if;
7740       --
7741       benutils.g_benefit_action_id := l_benefit_action_id;  -- Bug 3870204
7742       --
7743       -- Create benefit actions parameters in the benefit action table.
7744       -- Do not create if a benefit action already exists, in other words
7745       -- we are doing a restart.
7746       --
7747       if p_benefit_action_id is null then
7748         --
7749           if g_debug then
7750           hr_utility.set_location (l_package||' Create BFT ',30);
7751           end if;
7752         --
7753         --
7754         ben_benefit_actions_api.create_perf_benefit_actions
7755           (p_validate               => false,
7756            p_benefit_action_id      => l_benefit_action_id,
7757            p_process_date           => l_effective_date,
7758            p_mode_cd                => p_mode,
7759            p_derivable_factors_flag => p_derivable_factors,
7760            p_validate_flag          => p_validate,
7761            p_person_id              => p_person_id,
7762            p_person_type_id         => p_person_type_id,
7763            p_pgm_id                 => p_pgm_id,
7764            p_business_group_id      => p_business_group_id,
7765            p_pl_id                  => p_pl_id,
7766            -- PB : 5422 :
7767            -- No longer needed.
7768            --  p_popl_enrt_typ_cycl_id  => p_popl_enrt_typ_cycl_id,
7769            p_no_programs_flag       => p_no_programs,
7770            p_no_plans_flag          => p_no_plans,
7771            p_comp_selection_rl      => p_comp_selection_rule_id,
7772            p_person_selection_rl    => p_person_selection_rule_id,
7773            p_ler_id                 => p_ler_id,
7774            p_organization_id        => p_organization_id,
7775            p_benfts_grp_id          => p_benfts_grp_id,
7776            p_location_id            => p_location_id,
7777            p_pstl_zip_rng_id        => p_pstl_zip_rng_id,
7778            p_rptg_grp_id            => p_rptg_grp_id,
7779            p_pl_typ_id              => p_pl_typ_id,
7780            p_opt_id                 => p_opt_id,
7781            p_eligy_prfl_id          => p_eligy_prfl_id,
7782            p_vrbl_rt_prfl_id        => p_vrbl_rt_prfl_id,
7783            p_legal_entity_id        => p_legal_entity_id,
7784            p_payroll_id             => p_payroll_id,
7785            p_debug_messages_flag    => p_cbr_tmprl_evt_flag,
7786            p_audit_log_flag         => p_audit_log_flag,
7787            --
7788            -- PB : Healthnet change : Limit comp object selection
7789            -- based on the org id.
7790            --
7791            p_lmt_prpnip_by_org_flag => p_lmt_prpnip_by_org_flag,
7792                --
7793                -- GRADE/STEP : Reuse date_from to store l_asg_events_to_all_sel_dt
7794                -- Later add this column to bft table use proper column
7795                -- We may need to add other grade/step paramters to this table
7796                -- for now just reuse.
7797                --
7798                p_date_from              => l_asg_events_to_all_sel_dt,
7799            p_request_id             => fnd_global.conc_request_id,
7800            p_program_application_id => fnd_global.prog_appl_id,
7801            p_program_id             => fnd_global.conc_program_id,
7802            p_program_update_date    => sysdate,
7803            p_object_version_number  => l_object_version_number,
7804            p_lf_evt_ocrd_dt         => l_lf_evt_ocrd_dt,
7805            p_inelg_action_cd        => p_abs_historical_mode,
7806            p_effective_date         => l_effective_date,
7807            -- 2940151
7808            p_org_hierarchy_id         => p_org_heirarchy_id, -- note the spelling for hierarchy
7809            p_org_starting_node_id     => p_org_starting_node_id,
7810            p_grade_ladder_id          => p_grade_ladder_id,
7811            p_asg_events_to_all_sel_dt => p_asg_events_to_all_sel_dt,
7812            p_rate_id                  => p_rate_id,
7813            p_per_sel_dt_cd            => p_per_sel_dt_cd,
7814            p_per_sel_dt_from          => p_per_sel_dt_from,
7815            p_per_sel_dt_to            => p_per_sel_dt_to,
7816            p_year_from                => p_year_from,
7817            p_year_to                  => p_year_to,
7818            p_cagr_id                  => p_cagr_id,
7819            p_qual_type                => p_qual_type,
7820            p_qual_status              => p_qual_status,
7821            p_per_sel_freq_cd          => p_per_sel_freq_cd ,
7822            p_concat_segs 	      => p_concat_segs
7823            -- end 2940151
7824            );
7825           --
7826           benutils.g_benefit_action_id := l_benefit_action_id;  -- Bug 3870204
7827           --
7828           if g_debug then
7829           hr_utility.set_location (l_package||' Dn Create BFT ',20);
7830           end if;
7831         --
7832         -- This must be committed to the database
7833         --
7834         if p_commit_data = 'Y' then
7835           --
7836           commit;
7837           --
7838         end if;
7839         --
7840         -- Now lets create person actions for all the people we are going to
7841         -- process in the BENMNGLE run.
7842             --
7843             -- ABSENCES mode M added. Added GRADE/STEP mode
7844         --
7845         if p_mode in ('L','M', 'G', 'I', 'A') then
7846           --
7847             -- iRec
7848 	    if p_mode = 'I' then
7849 	      --
7850 	      l_ler_id := g_ler_id;
7851 	      --
7852 	    else
7853 	      --
7854 	      l_ler_id := p_ler_id;
7855 	      --
7856 	    end if;
7857 	    --
7858 
7859             -- 2940151
7860             -- get the people group kff structure and pass it
7861 
7862             open c_people_group_structure;
7863             fetch c_people_group_structure into l_id_flex_num;
7864             close c_people_group_structure;
7865 
7866             if g_debug then
7867             hr_utility.set_location (l_package||' Create L PER ACTs ',20);
7868             hr_utility.set_location ('p_mode : '||p_mode,6);
7869             end if;
7870           ben_benbatch_persons.create_life_person_actions
7871         (p_benefit_action_id        => l_benefit_action_id,
7872          p_business_group_id        => p_business_group_id,
7873          p_person_id                => p_person_id,
7874          p_ler_id                   => nvl(l_ler_id,l_ler_override_id),   -- irec
7875          p_person_type_id           => p_person_type_id,
7876          p_benfts_grp_id            => p_benfts_grp_id,
7877          p_location_id              => p_location_id,
7878          p_legal_entity_id          => p_legal_entity_id,
7879          p_payroll_id               => p_payroll_id,
7880          p_pstl_zip_rng_id          => p_pstl_zip_rng_id,
7881          p_organization_id          => p_organization_id,
7882          p_person_selection_rule_id => p_person_selection_rule_id,
7883          -- GRADE/STEP
7884          p_org_heirarchy_id         => p_org_heirarchy_id,
7885          p_org_starting_node_id     => p_org_starting_node_id,
7886          p_grade_ladder_id          => p_grade_ladder_id,
7887          p_asg_events_to_all_sel_dt => l_asg_events_to_all_sel_dt,
7888          p_rate_id                  => p_rate_id,
7889          p_per_sel_dt_cd            => p_per_sel_dt_cd,
7890          p_per_sel_dt_from          => l_per_sel_dt_from,
7891          p_per_sel_dt_to            => l_per_sel_dt_to,
7892          p_year_from                => p_year_from,
7893          p_year_to                  => p_year_to,
7894          p_cagr_id                  => p_cagr_id,
7895          p_qual_type                => p_qual_type,
7896          p_qual_status              => p_qual_status,
7897          -- 2940151
7898          p_per_sel_freq_cd    =>p_per_sel_freq_cd,
7899 	 p_id_flex_num	      =>l_id_flex_num,
7900 	 p_concat_segs 	      =>p_concat_segs,
7901          -- end 2940151
7902          -- End GRADE/STEP
7903          p_effective_date           => l_effective_date,
7904          p_chunk_size               => l_chunk_size,
7905          p_threads                  => l_threads,
7906          p_num_ranges               => l_num_ranges,
7907          p_num_persons              => l_num_persons,
7908          --
7909          -- PB : Healthnet change : Limit comp object selection
7910          -- based on the org id.
7911          --
7912          p_lmt_prpnip_by_org_flag   => p_lmt_prpnip_by_org_flag,
7913          p_commit_data              => p_commit_data,
7914                  -- ABSENCES : p_mode added
7915          p_mode                     => p_mode,
7916          p_lf_evt_oper_cd           => p_lf_evt_oper_cd   /* GSP Rate Sync */
7917          );
7918 
7919             if g_debug then
7920             hr_utility.set_location (l_package||' Dn Create L PER ACTs ',20);
7921             end if;
7922           --
7923         elsif p_mode in ('U','D') then
7924           --
7925           benutils.get_ler
7926         (p_business_group_id     => p_business_group_id,
7927          p_typ_cd                => 'SCHEDDU',
7928          p_effective_date        => l_effective_date,
7929          p_rec                   => l_ler_rec);
7930           --
7931           -- A bit of a hack to force the creation of a person action as we
7932           -- don't have a potential life event at this point and we want to be
7933           -- able to safely roll the person back should an error occur.
7934           --
7935           ben_person_actions_api.create_person_actions
7936         (p_validate              => false,
7937          p_person_action_id      => l_person_action_id,
7938          p_person_id             => p_person_id,
7939          p_ler_id                => l_ler_rec.ler_id,
7940          p_benefit_action_id     => l_benefit_action_id,
7941          p_action_status_cd      => 'U',
7942          p_chunk_number          => 1,
7943          p_object_version_number => l_object_version_number,
7944          p_effective_date        => l_effective_date);
7945           --
7946           ben_batch_ranges_api.create_batch_ranges
7947         (p_validate                  => false,
7948          p_benefit_action_id         => l_benefit_action_id,
7949          p_range_id                  => l_range_id,
7950          p_range_status_cd           => 'U',
7951          p_starting_person_action_id => l_person_action_id,
7952          p_ending_person_action_id   => l_person_action_id,
7953          p_object_version_number     => l_object_version_number,
7954          p_effective_date            => l_effective_date);
7955           --
7956           l_num_ranges := 1;
7957           l_num_persons := 1;
7958           --
7959 	else
7960           --
7961           ben_benbatch_persons.create_normal_person_actions
7962         (p_benefit_action_id        => l_benefit_action_id
7963         --
7964         ,p_mode_cd                  => p_mode
7965         --
7966         ,p_business_group_id        => p_business_group_id
7967         ,p_person_id                => p_person_id
7968         ,p_ler_id                   => p_ler_id
7969         ,p_person_type_id           => p_person_type_id
7970         ,p_benfts_grp_id            => p_benfts_grp_id
7971         ,p_location_id              => p_location_id
7972         ,p_legal_entity_id          => p_legal_entity_id
7973         ,p_payroll_id               => p_payroll_id
7974         ,p_pstl_zip_rng_id          => p_pstl_zip_rng_id
7975         ,p_organization_id          => p_organization_id
7976         ,p_ler_override_id          => l_ler_override_id
7977         ,p_person_selection_rule_id => p_person_selection_rule_id
7978         --
7979         -- PB : Healthnet Change
7980         -- Pass the l_lf_evt_ocrd_dt for scheduled mode
7981         -- Bug#2638681 - Healthnet change reversed
7982         --,p_effective_date           => nvl(l_lf_evt_ocrd_dt, l_effective_date)
7983         ,p_effective_date           => l_effective_date
7984         ,p_lmt_prpnip_by_org_flag   => p_lmt_prpnip_by_org_flag
7985         ,p_mode                     => p_mode
7986         ,p_chunk_size               => l_chunk_size
7987         ,p_threads                  => l_threads
7988         ,p_num_ranges               => l_num_ranges
7989         ,p_num_persons              => l_num_persons
7990         ,p_commit_data              => p_commit_data
7991 	,p_popl_enrt_typ_cycl_id  => l_popl_enrt_typ_cycl_id
7992 	,p_cwb_person_type          => p_cwb_person_type
7993 	,p_lf_evt_ocrd_dt           => l_lf_evt_ocrd_dt
7994         );
7995           --
7996         end if;
7997         --
7998       else
7999         --
8000         ben_benbatch_persons.create_restart_person_actions
8001           (p_benefit_action_id        => p_benefit_action_id,
8002            p_effective_date           => l_effective_date,
8003            p_chunk_size               => l_chunk_size,
8004            p_threads                  => l_threads,
8005            p_num_ranges               => l_num_ranges,
8006            p_num_persons              => l_num_persons,
8007            p_commit_data              => p_commit_data);
8008         --
8009         l_benefit_action_id := p_benefit_action_id;
8010         --
8011       end if;
8012         if g_debug then
8013         hr_utility.set_location (l_package,30);
8014         end if;
8015       --
8016       if l_num_ranges = 0 then
8017         --
8018         if nvl(p_mode, 'X') <> 'W' then
8019            fnd_message.set_name('BEN','BEN_91769_NOONE_TO_PROCESS');
8020            -- Bug 3870204 : If no persons are selected then, dont error out, but just write the message
8021            -- in Audit Log and finish the process with Status = Normal
8022            -- fnd_message.raise_error;
8023            fnd_message.set_token('PROC' , l_package);
8024            raise l_no_one_to_process;
8025         end if;
8026         --
8027       end if;
8028       --
8029 
8030       -- No point in starting of ten threads if there is only one range of data.
8031       --
8032       -- Only run this if we are using concurrent manager and not doing WHAT IF
8033       -- Functionality
8034       --
8035 
8036       if p_commit_data = 'Y' then
8037         --
8038           if g_debug then
8039           hr_utility.set_location ('Threads = '||l_threads,10);
8040           hr_utility.set_location ('Ranges = '||l_num_ranges,10);
8041           end if;
8042         --
8043         -- Set l_threads = l_threads - 1 as the master becomes a thread
8044         --
8045         commit;
8046         --
8047         l_threads := least(l_threads,l_num_ranges)-1;
8048         --
8049         ben_maintain_benefit_actions.start_slaves
8050               (p_threads                  => l_threads
8051               ,p_num_ranges               => l_num_ranges
8052               ,p_validate                 => p_validate
8053               ,p_benefit_action_id        => l_benefit_action_id
8054               ,p_effective_date           => p_effective_date
8055               ,p_pgm_id                   => p_pgm_id
8056               ,p_business_group_id        => p_business_group_id
8057               ,p_pl_id                    => p_pl_id
8058               ,p_no_programs              => p_no_programs
8059               ,p_no_plans                 => p_no_plans
8060               ,p_rptg_grp_id              => p_rptg_grp_id
8061               ,p_pl_typ_id                => p_pl_typ_id
8062               ,p_opt_id                   => p_opt_id
8063               ,p_eligy_prfl_id            => p_eligy_prfl_id
8064               ,p_vrbl_rt_prfl_id          => p_vrbl_rt_prfl_id
8065               ,p_mode                     => p_mode
8066               ,p_person_selection_rule_id => p_person_selection_rule_id
8067               ,p_comp_selection_rule_id   => p_comp_selection_rule_id
8068               ,p_derivable_factors        => p_derivable_factors
8069               ,p_cbr_tmprl_evt_flag       => p_cbr_tmprl_evt_flag
8070               ,p_lmt_prpnip_by_org_flag   => p_lmt_prpnip_by_org_flag
8071               ,p_lf_evt_ocrd_dt           => p_lf_evt_ocrd_dt
8072 	      ,p_gsp_eval_elig_flag       => l_gsp_eval_elig_flag     /* GSP Rate Sync */
8073 	      ,p_lf_evt_oper_cd           => p_lf_evt_oper_cd         /* GSP Rate Sync */
8074               );
8075         --
8076         -- Always carry on with the master but make the master act as a slave
8077         -- as well. Only this thread can see the cache structure that we use to
8078         -- store the concurrent request id's. This ensures that the master thread
8079         -- always finishes last. GOOD THREADS ALWAYS FINISH LAST.
8080         --
8081         do_multithread
8082           (errbuf                     => l_errbuf,
8083            retcode                    => l_retcode,
8084            p_validate                 => p_validate,
8085            p_benefit_action_id        => l_benefit_action_id,
8086            p_effective_date           => p_effective_date,
8087            p_pgm_id                   => p_pgm_id,
8088            p_business_group_id        => p_business_group_id,
8089            p_pl_id                    => p_pl_id,
8090            -- PB : 5422 :
8091            p_popl_enrt_typ_cycl_id    => p_popl_enrt_typ_cycl_id,
8092            p_no_programs              => p_no_programs,
8093            p_no_plans                 => p_no_plans,
8094            p_rptg_grp_id              => p_rptg_grp_id,
8095            p_pl_typ_id                => p_pl_typ_id,
8096            p_opt_id                   => p_opt_id,
8097            p_eligy_prfl_id            => p_eligy_prfl_id,
8098            p_vrbl_rt_prfl_id          => p_vrbl_rt_prfl_id,
8099            p_mode                     => p_mode,
8100            p_person_selection_rule_id => p_person_selection_rule_id,
8101            p_comp_selection_rule_id   => p_comp_selection_rule_id,
8102            p_derivable_factors        => p_derivable_factors,
8103            p_thread_id                => l_threads+1,
8104            p_lf_evt_ocrd_dt           => p_lf_evt_ocrd_dt,
8105            p_lmt_prpnip_by_org_flag   => p_lmt_prpnip_by_org_flag,
8106            p_cbr_tmprl_evt_flag       => p_cbr_tmprl_evt_flag,
8107 	   p_gsp_eval_elig_flag       => l_gsp_eval_elig_flag,    /* GSP Rate Sync */
8108 	   p_lf_evt_oper_cd           => p_lf_evt_oper_cd         /* GSP Rate Sync */
8109 	   );
8110         --
8111       end if;
8112       --
8113       -- Prasad special case
8114       --
8115       benutils.g_benefit_action_id := l_benefit_action_id;
8116       p_benefit_action_id := l_benefit_action_id;
8117       --
8118       /* GLOBALCWB : The issue of track ineligible flag have to be addressed
8119          later after drop 3, currently it has no meaning
8120           -- CWB Changes.
8121           -- Populate the heirarchy table.
8122           --
8123           if p_mode = 'W' then
8124             --
8125             open c_pln;
8126             fetch c_pln into l_trk_inelig_per_flag;
8127             close c_pln;
8128 
8129             if nvl(l_trk_inelig_per_flag,'N') = 'N' then
8130                for l_person_rec in c_person_info
8131                loop
8132                   --
8133                   del_cwb_pil
8134                  (l_person_rec.person_id,
8135                   p_pl_id,
8136                   l_effective_date,
8137                   l_ler_override_id,
8138                   l_lf_evt_ocrd_dt);
8139                   --
8140                end loop;
8141             end if;
8142 
8143             -- Bug 2237993 CWB fix: moved popu_cross_gb_epe_data call form
8144             -- process_rows to internal_process to avoid creating duplicate records
8145             -- for the cross business group.
8146             --
8147             for l_per_rec in c_person_info loop
8148                --
8149                --popu_cross_gb_epe_data(
8150                --   p_mode                     => p_mode,
8151                --   p_person_id                => l_per_rec.person_id,
8152                --   p_business_group_id        => p_business_group_id,
8153                --   p_ler_id                   => l_ler_override_id,
8154                --   p_pl_id                    => null, -- Currently not used by proc
8155                --   p_effective_date           => l_effective_date,
8156                --   p_lf_evt_ocrd_dt           => l_lf_evt_ocrd_dt
8157                -- );
8158                --
8159                popu_cross_gb_epe_pel_data(
8160                   p_mode                     => p_mode,
8161                   p_person_id                => l_per_rec.person_id,
8162                   p_business_group_id        => p_business_group_id,
8163                   p_ler_id                   => l_ler_override_id,
8164                   p_pl_id                    => null, -- Currently not used by proc
8165                   p_effective_date           => l_effective_date,
8166                   p_lf_evt_ocrd_dt           => l_lf_evt_ocrd_dt
8167                 );
8168                --
8169             end loop;
8170             --
8171             --CWBITEM
8172             --popu_epe_heir();
8173             --CWBITEM
8174             popu_pel_heir();
8175             --
8176           end if;
8177           */
8178           --
8179           if p_commit_data = 'Y' then
8180              --
8181              commit;
8182              --
8183           end if;
8184           --
8185         if g_debug then
8186         hr_utility.set_location ('Leaving '||l_package,10);
8187         end if;
8188       --
8189       exception
8190          -- Bug 3870204
8191          when l_no_one_to_process then
8192             benutils.write(p_text => fnd_message.get);
8193             benutils.write_table_and_file(p_table => TRUE, p_file  => TRUE);
8194             rollback;
8195     end internal_process;
8196     --
8197     procedure process
8198       (errbuf                        out nocopy varchar2
8199       ,retcode                       out nocopy number
8200       ,p_benefit_action_id        in     number
8201       ,p_effective_date           in     varchar2
8202       ,p_mode                     in     varchar2
8203       ,p_derivable_factors        in     varchar2 default 'ASC'
8204       ,p_validate                 in     varchar2 default 'N'
8205       ,p_person_id                in     number   default null
8206       ,p_person_type_id           in     number   default null
8207       ,p_pgm_id                   in     number   default null
8208       ,p_business_group_id        in     number
8209       ,p_pl_id                    in     number   default null
8210       ,p_popl_enrt_typ_cycl_id    in     number   default null
8211       ,p_lf_evt_ocrd_dt           in     varchar2 default null
8212       ,p_no_programs              in     varchar2 default 'N'
8213       ,p_no_plans                 in     varchar2 default 'N'
8214       ,p_comp_selection_rule_id   in     number   default null
8215       ,p_person_selection_rule_id in     number   default null
8216       ,p_ler_id                   in     number   default null
8217       ,p_organization_id          in     number   default null
8218       ,p_benfts_grp_id            in     number   default null
8219       ,p_location_id              in     number   default null
8220       ,p_pstl_zip_rng_id          in     number   default null
8221       ,p_rptg_grp_id              in     number   default null
8222       ,p_pl_typ_id                in     number   default null
8223       ,p_opt_id                   in     number   default null
8224       ,p_eligy_prfl_id            in     number   default null
8225       ,p_vrbl_rt_prfl_id          in     number   default null
8226       ,p_legal_entity_id          in     number   default null
8227       ,p_payroll_id               in     number   default null
8228       ,p_commit_data              in     varchar2 default 'Y'
8229       ,p_audit_log_flag           in     varchar2 default 'N'
8230       ,p_lmt_prpnip_by_org_flag   in     varchar2 default 'N'
8231       ,p_cbr_tmprl_evt_flag       in     varchar2 default 'N'
8232       -- GRADE/STEP : Added for grade/step benmngle
8233       ,p_org_heirarchy_id         in     number   default null
8234       ,p_org_starting_node_id     in     number   default null
8235       ,p_grade_ladder_id          in     number   default null
8236       ,p_asg_events_to_all_sel_dt in     varchar2 default null
8237       ,p_rate_id                  in     number   default null -- pay scale
8238       ,p_per_sel_dt_cd            in     varchar2 default null -- business rule
8239       ,p_per_sel_dt_from          in     date     default null -- business rule date from
8240       ,p_per_sel_dt_to            in     date     default null -- business rule date to
8241       ,p_year_from                in     number   default null -- business rule year from
8242       ,p_year_to                  in     number   default null -- business rule year to
8243       ,p_cagr_id                  in     number   default null -- Coll agreement id
8244       ,p_qual_type                in     number   default null
8245       ,p_qual_status              in     varchar2 default null
8246       -- 2940151
8247       ,p_per_sel_freq_cd    	  in     varchar2 default null
8248       ,p_concat_segs              in     varchar2 default null
8249       -- end 2940151
8250       ,p_abs_historical_mode      in     varchar2 default 'N'
8251       ,p_gsp_eval_elig_flag       in     varchar2 default null  -- GSP Rate Sync : Evaluate Eligibility
8252       ,p_lf_evt_oper_cd           in     varchar2 default null  -- GSP Rate Sync : Life Event Operation code
8253       ,p_cwb_person_type          in     varchar2 default null)
8254     is
8255       --
8256       l_package                varchar2(80);
8257       --
8258       l_bft_id                 number;
8259       --
8260     begin
8261       --
8262         g_debug := hr_utility.debug_enabled;
8263         if g_debug then
8264           l_package := g_package||'.process';
8265         hr_utility.set_location ('Entering '||l_package,10);
8266         end if;
8267       --
8268       l_bft_id := p_benefit_action_id;
8269       --
8270         if g_debug then
8271         hr_utility.set_location ('p_mode : '||p_mode,4);
8272 	end if;
8273         -- Bug 5857493
8274 	if p_audit_log_flag ='Y' then
8275           ben_benbatch_persons.g_audit_flag := true;
8276         else
8277           ben_benbatch_persons.g_audit_flag := false;
8278         end if;
8279       internal_process
8280         (errbuf                     => errbuf
8281         ,retcode                    => retcode
8282         ,p_benefit_action_id        => l_bft_id
8283         ,p_effective_date           => p_effective_date
8284         ,p_mode                     => p_mode
8285         ,p_derivable_factors        => p_derivable_factors
8286         ,p_validate                 => p_validate
8287         ,p_person_id                => p_person_id
8288         ,p_person_type_id           => p_person_type_id
8289         ,p_pgm_id                   => p_pgm_id
8290         ,p_business_group_id        => p_business_group_id
8291         ,p_pl_id                    => p_pl_id
8292         ,p_popl_enrt_typ_cycl_id    => p_popl_enrt_typ_cycl_id
8293         ,p_lf_evt_ocrd_dt           => p_lf_evt_ocrd_dt
8294         ,p_no_programs              => p_no_programs
8295         ,p_no_plans                 => p_no_plans
8296         ,p_comp_selection_rule_id   => p_comp_selection_rule_id
8297         ,p_person_selection_rule_id => p_person_selection_rule_id
8298         ,p_ler_id                   => p_ler_id
8299         ,p_organization_id          => p_organization_id
8300         ,p_benfts_grp_id            => p_benfts_grp_id
8301         ,p_location_id              => p_location_id
8302         ,p_pstl_zip_rng_id          => p_pstl_zip_rng_id
8303         ,p_rptg_grp_id              => p_rptg_grp_id
8304         ,p_pl_typ_id                => p_pl_typ_id
8305         ,p_opt_id                   => p_opt_id
8306         ,p_eligy_prfl_id            => p_eligy_prfl_id
8307         ,p_vrbl_rt_prfl_id          => p_vrbl_rt_prfl_id
8308         ,p_legal_entity_id          => p_legal_entity_id
8309         ,p_payroll_id               => p_payroll_id
8310         ,p_commit_data              => p_commit_data
8311         ,p_audit_log_flag           => p_audit_log_flag
8312         ,p_lmt_prpnip_by_org_flag   => p_lmt_prpnip_by_org_flag
8313         ,p_cbr_tmprl_evt_flag       => p_cbr_tmprl_evt_flag
8314         -- GRADE/STEP : Added for grade/step benmngle
8315         ,p_org_heirarchy_id         => p_org_heirarchy_id
8316         ,p_org_starting_node_id     => p_org_starting_node_id
8317         ,p_grade_ladder_id          => p_grade_ladder_id
8318         ,p_asg_events_to_all_sel_dt => p_asg_events_to_all_sel_dt
8319         ,p_rate_id                  => p_rate_id
8320         ,p_per_sel_dt_cd            => p_per_sel_dt_cd
8321         ,p_per_sel_dt_from          => p_per_sel_dt_from
8322         ,p_per_sel_dt_to            => p_per_sel_dt_to
8323         ,p_year_from                => p_year_from
8324         ,p_year_to                  => p_year_to
8325         ,p_cagr_id                  => p_cagr_id
8326         ,p_qual_type                => p_qual_type
8327         ,p_qual_status              => p_qual_status
8328         ,p_abs_historical_mode      => p_abs_historical_mode
8329         -- 2940151
8330         ,p_per_sel_freq_cd    	    => p_per_sel_freq_cd
8331         ,p_concat_segs 	            => p_concat_segs
8332         -- end 2940151
8333         ,p_gsp_eval_elig_flag       => p_gsp_eval_elig_flag         -- GSP Rate Sync : Evaluate Eligibility
8334         ,p_lf_evt_oper_cd           => p_lf_evt_oper_cd             -- GSP Rate Sync : Life Event Operation code
8335         ,p_cwb_person_type          => p_cwb_person_type);
8336       --
8337   if g_debug then
8338     hr_utility.set_location ('Leaving '||l_package,10);
8339   end if;
8340   --
8341 end process;
8342 --
8343 -- This procedure caches comp object names which can be referenced by
8344 -- all other batch processes
8345 --
8346 procedure get_comp_object_name
8347   (p_oipl_id           in     number
8348   ,p_pgm_id            in     number
8349   ,p_pl_id             in     number
8350   ,p_plip_id           in     number
8351   ,p_ptip_id           in     number
8352   ,p_pl_nip            in     varchar2
8353   ,p_comp_object_name     out nocopy varchar2
8354   ,p_comp_object_value    out nocopy varchar2
8355   )
8356 is
8357   --
8358   l_package           varchar2(80);
8359   l_comp_object_name  varchar2(80);
8360   l_pgm_rec           ben_pgm_f%rowtype;
8361   l_pl_rec            ben_pl_f%rowtype;
8362   l_oipl_rec          ben_oipl_f%rowtype;
8363   l_opt_rec           ben_opt_f%rowtype;
8364   l_plip_rec          ben_plip_f%rowtype;
8365   l_ptip_rec          ben_ptip_f%rowtype;
8366   --
8367 begin
8368   --
8369   if g_debug then
8370     l_package := g_package||'.get_comp_object_name';
8371     hr_utility.set_location ('Entering '||l_package,10);
8372   end if;
8373   --
8374   if p_oipl_id is not null then
8375     --
8376     p_comp_object_value := g_cache_comp_objects.oipl;
8377     --
8378     ben_comp_object.get_object(p_rec     => l_oipl_rec,
8379                                p_oipl_id => p_oipl_id);
8380     ben_comp_object.get_object(p_rec     => l_opt_rec,
8381                                p_opt_id  => l_oipl_rec.opt_id);
8382     p_comp_object_name := rpad(substr(l_opt_rec.name,1,18),18,' ')||
8383                           benutils.id(p_oipl_id);
8384     --
8385   elsif p_pl_id is not null then
8386     --
8387     -- Test if plan is in program or not
8388     --
8389     if p_pl_nip = 'Y' then
8390       --
8391       p_comp_object_value := g_cache_comp_objects.pl;
8392       --
8393     else
8394       --
8395       p_comp_object_value := g_cache_comp_objects.plip;
8396       --
8397     end if;
8398     --
8399     ben_comp_object.get_object(p_rec   => l_pl_rec,
8400                                p_pl_id => p_pl_id);
8401     p_comp_object_name := rpad(substr(l_pl_rec.name,1,18),18,' ')||
8402                           benutils.id(p_pl_id);
8403     --
8404   elsif p_pgm_id is not null then
8405     --
8406     p_comp_object_value := g_cache_comp_objects.pgm;
8407     --
8408     ben_comp_object.get_object(p_rec    => l_pgm_rec,
8409                                p_pgm_id => p_pgm_id);
8410     p_comp_object_name := rpad(substr(l_pgm_rec.name,1,18),18,' ')||
8411                           benutils.id(p_pgm_id);
8412     --
8413   elsif p_plip_id is not null then
8414     --
8415     p_comp_object_value := g_cache_comp_objects.plip;
8416     --
8417     p_comp_object_name := rpad('Plip',15,' ')||
8418                           benutils.id(p_plip_id);
8419     --
8420   elsif p_ptip_id is not null then
8421     --
8422     p_comp_object_value := g_cache_comp_objects.ptip;
8423     --
8424     p_comp_object_name := rpad('Ptip',15,' ')||
8425                           benutils.id(p_ptip_id);
8426     --
8427   end if;
8428   --
8429   if g_debug then
8430     hr_utility.set_location ('Leaving '||l_package,10);
8431   end if;
8432   --
8433 end get_comp_object_name;
8434 --
8435 procedure cache_person_information
8436         (p_person_id         in number,
8437          p_business_group_id in number,
8438          p_effective_date    in date) is
8439   --
8440   cursor c_person_prtn is
8441     select pen.pl_id,
8442            pen.oipl_id,
8443            pen.pgm_id,
8444            pen.ptip_id,
8445            pen.enrt_cvg_strt_dt,
8446            pen.enrt_cvg_thru_dt
8447     from   ben_prtt_enrt_rslt_f pen
8448     where  pen.person_id = p_person_id
8449     and    pen.business_group_id  = p_business_group_id
8450     and    p_effective_date
8451            between pen.enrt_cvg_strt_dt
8452            and     pen.enrt_cvg_thru_dt
8453     and    pen.enrt_cvg_thru_dt <= pen.effective_end_date
8454     and    pen.prtt_enrt_rslt_stat_cd is null
8455     and    pen.sspndd_flag = 'N';
8456   --
8457   l_package     varchar2(80);
8458   l_count       number(9) := 0;
8459   l_person_prtn c_person_prtn%rowtype;
8460   --
8461 begin
8462   --
8463   g_debug := hr_utility.debug_enabled;
8464   if g_debug then
8465     l_package := g_package||'.cache_person_information';
8466     hr_utility.set_location ('Entering '||l_package,10);
8467     hr_utility.set_location ('Entering '||p_effective_date,10);
8468   end if;
8469   --
8470   -- Open cursor to see if the person holds emp person type status
8471   --
8472   g_cache_person_prtn.delete;
8473   --
8474   l_count := 0;
8475   --
8476   open c_person_prtn;
8477     --
8478     loop
8479       --
8480       fetch c_person_prtn into l_person_prtn;
8481       exit when c_person_prtn%notfound;
8482       l_count := l_count + 1;
8483       --
8484       g_cache_person_prtn(l_count).pl_id
8485         := l_person_prtn.pl_id;
8486       g_cache_person_prtn(l_count).oipl_id
8487         := l_person_prtn.oipl_id;
8488       g_cache_person_prtn(l_count).pgm_id
8489         := l_person_prtn.pgm_id;
8490       g_cache_person_prtn(l_count).ptip_id
8491         := l_person_prtn.ptip_id;
8492       g_cache_person_prtn(l_count).enrt_cvg_strt_dt
8493         := l_person_prtn.enrt_cvg_strt_dt;
8494       g_cache_person_prtn(l_count).enrt_cvg_thru_dt
8495         := l_person_prtn.enrt_cvg_thru_dt;
8496       --
8497     end loop;
8498     --
8499   close c_person_prtn;
8500 
8501   if g_debug then
8502     hr_utility.set_location ('Done c_person_prtn '||l_package,40);
8503   end if;
8504   --
8505   -- We need to do the assignment stuff seperately as we can't outer join
8506   -- as we need assignments with primary flags and applicants have non
8507   -- primary flag assignments so the hack is to do the select in two
8508   -- statements, although a fix could be to do a union to get the value
8509   -- for the assignment id.
8510   --
8511   if g_debug then
8512     hr_utility.set_location ('Leaving '||l_package,100);
8513   end if;
8514   --
8515 end cache_person_information;
8516 -- ---------------------------------------------------------------------
8517 procedure person_header
8518   (p_person_id                in number default null,
8519    p_business_group_id        in number,
8520    p_effective_date           in date) is
8521   --
8522   l_package           varchar2(80);
8523   l_output_string     varchar2(100);
8524   l_per_rec           per_all_people_f%rowtype;
8525   l_ass_rec           per_all_assignments_f%rowtype;
8526   l_bus_rec           per_business_groups%rowtype;
8527   l_org_rec           hr_all_organization_units%rowtype;
8528   l_org2_rec          hr_all_organization_units%rowtype;
8529   l_pad_rec           per_addresses%rowtype;
8530   l_loc_rec           hr_locations_all%rowtype;
8531   l_pay_rec           pay_all_payrolls_f%rowtype;
8532   l_ben_rec           ben_benfts_grp%rowtype;
8533   l_hsc_rec           hr_soft_coding_keyflex%rowtype;
8534   l_typ_rec           ben_person_object.g_cache_typ_table;
8535   --
8536 begin
8537   --
8538   g_debug := hr_utility.debug_enabled;
8539   if g_debug then
8540     l_package := g_package||'.person_header';
8541     hr_utility.set_location ('Entering '||l_package,10);
8542   end if;
8543   --
8544   -- Cache person data
8545   --
8546   cache_person_information
8547     (p_person_id         => p_person_id,
8548      p_business_group_id => p_business_group_id,
8549      p_effective_date    => p_effective_date);
8550     if g_debug then
8551       hr_utility.set_location ('Dn Cac Per Inf '||l_package,10);
8552     end if;
8553   --
8554   -- This should display something like this
8555   --
8556   -- *********************************************************************
8557   -- Name : John Smith (100) Type : Employee (1)  Grp : Benefits Group (1)
8558   -- BG   : Freds BG   (100) Org  : Freds Org(1)  GRE : Retiree
8559   -- Loc  : HQ         (100) Pst  : 86727         Pyr : Payroll 3B     (1)
8560   --
8561   ben_person_object.get_object(p_person_id => p_person_id,
8562                                p_rec       => l_per_rec);
8563   --
8564   if l_per_rec.benefit_group_id is not null then
8565     --
8566     ben_org_object.get_object(p_benfts_grp_id => l_per_rec.benefit_group_id,
8567                               p_rec           => l_ben_rec);
8568     --
8569   end if;
8570   --
8571   ben_person_object.get_object(p_person_id => p_person_id,
8572                                p_rec       => l_ass_rec);
8573   --
8574   if l_ass_rec.assignment_id is null then
8575     --
8576     ben_person_object.get_benass_object(p_person_id => p_person_id,
8577                                         p_rec       => l_ass_rec);
8578     --
8579   end if;
8580   --
8581   if l_ass_rec.location_id is not null then
8582     --
8583     ben_location_object.get_object(p_location_id => l_ass_rec.location_id,
8584                                    p_rec         => l_loc_rec);
8585     --
8586   end if;
8587   --
8588   if l_ass_rec.organization_id is not null then
8589     --
8590     ben_org_object.get_object(p_organization_id => l_ass_rec.organization_id,
8591                               p_rec             => l_org_rec);
8592     --
8593   end if;
8594   --
8595   if l_ass_rec.payroll_id is not null then
8596     --
8597     ben_org_object.get_object(p_payroll_id => l_ass_rec.payroll_id,
8598                               p_rec        => l_pay_rec);
8599     --
8600   end if;
8601   --
8602   if l_ass_rec.soft_coding_keyflex_id is not null then
8603     --
8604     ben_person_object.get_object
8605        (p_soft_coding_keyflex_id => l_ass_rec.soft_coding_keyflex_id,
8606         p_rec                    => l_hsc_rec);
8607     --
8608     if l_hsc_rec.segment1 is not null and hr_api.return_legislation_code(p_business_group_id) = 'US'
8609     then
8610       --
8611       ben_org_object.get_object(p_organization_id => l_hsc_rec.segment1,
8612                                 p_rec             => l_org2_rec);
8613       --
8614     end if;
8615     --
8616   end if;
8617   --
8618     if g_debug then
8619       hr_utility.set_location ('BPO_GO PAD '||l_package,10);
8620     end if;
8621   ben_person_object.get_object(p_person_id => p_person_id,
8622                                p_rec       => l_pad_rec);
8623   --
8624   ben_person_object.get_object(p_person_id => p_person_id,
8625                                p_rec       => l_typ_rec);
8626   --
8627   ben_org_object.get_object(p_business_group_id => p_business_group_id,
8628                             p_rec               => l_bus_rec);
8629   --
8630   benutils.write(p_text => benutils.g_banner_asterix);
8631   l_output_string := 'Name: '||
8632                      substr(l_per_rec.full_name,1,45)||
8633                      benutils.id(p_person_id);
8634   benutils.write(p_text => l_output_string);
8635   l_output_string := ' Typ: '||
8636                      substr(l_typ_rec(1).user_person_type,1,45);
8637   --
8638   -- loop through the rest of the person_types
8639   --
8640   for l_count in 2..l_typ_rec.last loop
8641     --
8642     l_output_string := rpad(' ',6,' ');
8643     l_output_string := l_output_string||
8644                        substr(l_typ_rec(l_count).user_person_type,1,45);
8645     benutils.write(l_output_string);
8646     --
8647   end loop;
8648   l_output_string := 'Grp:  '||
8649                      substr(l_ben_rec.name,1,45)||
8650                      benutils.id(l_per_rec.benefit_group_id);
8651   benutils.write(p_text => l_output_string);
8652   --
8653   l_output_string := 'BG:   '||
8654                      substr(l_bus_rec.name,1,45)||
8655                      benutils.id(p_business_group_id);
8656   benutils.write(p_text => l_output_string);
8657   --
8658   l_output_string := 'Org:  '||
8659                      substr(l_org_rec.name,1,45)||
8660                      benutils.id(l_ass_rec.organization_id);
8661   benutils.write(p_text => l_output_string);
8662   --
8663   if hr_api.return_legislation_code(p_business_group_id) = 'US'
8664   then
8665     l_output_string := 'Gre:  '||
8666                      substr(l_org2_rec.name,1,45);
8667     benutils.write(p_text => l_output_string);
8668   else
8669     l_output_string := 'Gre:  '|| 'Not applicable' ;
8670     benutils.write(p_text => l_output_string);
8671   end if;
8672   --
8673   l_output_string := 'Loc:  '||
8674                      substr(l_loc_rec.address_line_1,1,45)||
8675                      benutils.id(l_loc_rec.location_id);
8676   benutils.write(p_text => l_output_string);
8677   --
8678   l_output_string := 'Pst:  '||
8679                      substr(l_pad_rec.postal_code,1,45);
8680   benutils.write(p_text => l_output_string);
8681   --
8682   l_output_string := 'Pyr:  '||
8683                      substr(l_pay_rec.payroll_name,1,45)||
8684                      benutils.id(l_pay_rec.payroll_id);
8685   benutils.write(p_text => l_output_string);
8686   --
8687   if g_debug then
8688     hr_utility.set_location ('Leaving '||l_package,10);
8689   end if;
8690   --
8691 end person_header;
8692 --
8693 --
8694 ----------------------------------------------------------
8695 -----------------< person_header_new >--------------------
8696 ----------------------------------------------------------
8697 --
8698 -- This is same procedure as PERSON_HEADER except that the call to
8699 -- CACHE_PERSON_INFORMATION was removed to separate CACHE Logic
8700 -- from displaying of person header
8701 --
8702 PROCEDURE person_header_new (
8703    p_person_id           IN   NUMBER DEFAULT NULL,
8704    p_business_group_id   IN   NUMBER
8705 )
8706 IS
8707    --
8708    l_package         VARCHAR2 (80);
8709    l_output_string   VARCHAR2 (100);
8710    l_per_rec         per_all_people_f%ROWTYPE;
8711    l_ass_rec         per_all_assignments_f%ROWTYPE;
8712    l_bus_rec         per_business_groups%ROWTYPE;
8713    l_org_rec         hr_all_organization_units%ROWTYPE;
8714    l_org2_rec        hr_all_organization_units%ROWTYPE;
8715    l_pad_rec         per_addresses%ROWTYPE;
8716    l_loc_rec         hr_locations_all%ROWTYPE;
8717    l_pay_rec         pay_all_payrolls_f%ROWTYPE;
8718    l_ben_rec         ben_benfts_grp%ROWTYPE;
8719    l_hsc_rec         hr_soft_coding_keyflex%ROWTYPE;
8720    l_typ_rec         ben_person_object.g_cache_typ_table;
8721 --
8722 BEGIN
8723    --
8724    g_debug := hr_utility.debug_enabled;
8725 
8726    IF g_debug
8727    THEN
8728       l_package := g_package || '.person_header';
8729       hr_utility.set_location ('Entering ' || l_package, 10);
8730    END IF;
8731 
8732 --
8733 -- This should display something like this
8734 --
8735 -- *********************************************************************
8736 -- Name : John Smith (100) Type : Employee (1)  Grp : Benefits Group (1)
8737 -- BG   : Freds BG   (100) Org  : Freds Org(1)  GRE : Retiree
8738 -- Loc  : HQ         (100) Pst  : 86727         Pyr : Payroll 3B     (1)
8739 --
8740    ben_person_object.get_object (p_person_id      => p_person_id,
8741                                  p_rec            => l_per_rec
8742                                 );
8743 
8744    --
8745    IF l_per_rec.benefit_group_id IS NOT NULL
8746    THEN
8747       --
8748       ben_org_object.get_object (p_benfts_grp_id      => l_per_rec.benefit_group_id,
8749                                  p_rec                => l_ben_rec
8750                                 );
8751    --
8752    END IF;
8753 
8754    --
8755    ben_person_object.get_object (p_person_id      => p_person_id,
8756                                  p_rec            => l_ass_rec
8757                                 );
8758 
8759    --
8760    IF l_ass_rec.assignment_id IS NULL
8761    THEN
8762       --
8763       ben_person_object.get_benass_object (p_person_id      => p_person_id,
8764                                            p_rec            => l_ass_rec
8765                                           );
8766    --
8767    END IF;
8768 
8769    --
8770    IF l_ass_rec.location_id IS NOT NULL
8771    THEN
8772       --
8773       ben_location_object.get_object (p_location_id      => l_ass_rec.location_id,
8774                                       p_rec              => l_loc_rec
8775                                      );
8776    --
8777    END IF;
8778 
8779    --
8780    IF l_ass_rec.organization_id IS NOT NULL
8781    THEN
8782       --
8783       ben_org_object.get_object (p_organization_id      => l_ass_rec.organization_id,
8784                                  p_rec                  => l_org_rec
8785                                 );
8786    --
8787    END IF;
8788 
8789    --
8790    IF l_ass_rec.payroll_id IS NOT NULL
8791    THEN
8792       --
8793       ben_org_object.get_object (p_payroll_id      => l_ass_rec.payroll_id,
8794                                  p_rec             => l_pay_rec
8795                                 );
8796    --
8797    END IF;
8798 
8799    --
8800    IF l_ass_rec.soft_coding_keyflex_id IS NOT NULL
8801    THEN
8802       --
8803       ben_person_object.get_object (p_soft_coding_keyflex_id      => l_ass_rec.soft_coding_keyflex_id,
8804                                     p_rec                         => l_hsc_rec
8805                                    );
8806 
8807       --
8808       IF l_hsc_rec.segment1 IS NOT NULL and hr_api.return_legislation_code(p_business_group_id) = 'US'
8809       THEN
8810          --
8811          ben_org_object.get_object (p_organization_id      => l_hsc_rec.segment1,
8812                                     p_rec                  => l_org2_rec
8813                                    );
8814       --
8815       END IF;
8816    --
8817    END IF;
8818 
8819    --
8820    IF g_debug
8821    THEN
8822       hr_utility.set_location ('BPO_GO PAD ' || l_package, 10);
8823    END IF;
8824 
8825    ben_person_object.get_object (p_person_id      => p_person_id,
8826                                  p_rec            => l_pad_rec
8827                                 );
8828    --
8829    ben_person_object.get_object (p_person_id      => p_person_id,
8830                                  p_rec            => l_typ_rec
8831                                 );
8832    --
8833    ben_org_object.get_object (p_business_group_id      => p_business_group_id,
8834                               p_rec                    => l_bus_rec
8835                              );
8836    --
8837    benutils.WRITE (p_text => benutils.g_banner_asterix);
8838    --
8839    l_output_string :=
8840           'Name: '
8841        || SUBSTR (l_per_rec.full_name, 1, 45)
8842        || benutils.ID (p_person_id);
8843    --
8844    benutils.WRITE (p_text => l_output_string);
8845    --
8846    l_output_string :=
8847                      ' Typ: '
8848                      || SUBSTR (l_typ_rec (1).user_person_type, 1, 45);
8849 
8850    --
8851    -- loop through the rest of the person_types
8852    --
8853    FOR l_count IN 2 .. l_typ_rec.LAST
8854    LOOP
8855       --
8856       l_output_string := RPAD (' ', 6, ' ');
8857       l_output_string :=
8858              l_output_string
8859           || SUBSTR (l_typ_rec (l_count).user_person_type, 1, 45);
8860       benutils.WRITE (l_output_string);
8861    --
8862    END LOOP;
8863 
8864    l_output_string :=
8865           'Grp:  '
8866        || SUBSTR (l_ben_rec.NAME, 1, 45)
8867        || benutils.ID (l_per_rec.benefit_group_id);
8868    benutils.WRITE (p_text => l_output_string);
8869    --
8870    l_output_string :=
8871           'BG:   '
8872        || SUBSTR (l_bus_rec.NAME, 1, 45)
8873        || benutils.ID (p_business_group_id);
8874    benutils.WRITE (p_text => l_output_string);
8875    --
8876    l_output_string :=
8877           'Org:  '
8878        || SUBSTR (l_org_rec.NAME, 1, 45)
8879        || benutils.ID (l_ass_rec.organization_id);
8880    benutils.WRITE (p_text => l_output_string);
8881    --
8882    if hr_api.return_legislation_code(p_business_group_id) = 'US'
8883    then
8884        l_output_string := 'Gre:  ' || SUBSTR (l_org2_rec.NAME, 1, 45);
8885        benutils.WRITE (p_text => l_output_string);
8886    else
8887        l_output_string := 'Gre:  ' || 'Not applicable' ;
8888        benutils.WRITE (p_text => l_output_string);
8889    end if;
8890    --
8891    l_output_string :=
8892           'Loc:  '
8893        || SUBSTR (l_loc_rec.address_line_1, 1, 45)
8894        || benutils.ID (l_loc_rec.location_id);
8895    benutils.WRITE (p_text => l_output_string);
8896    --
8897    l_output_string := 'Pst:  ' || SUBSTR (l_pad_rec.postal_code, 1, 45);
8898    benutils.WRITE (p_text => l_output_string);
8899    --
8900    l_output_string :=
8901           'Pyr:  '
8902        || SUBSTR (l_pay_rec.payroll_name, 1, 45)
8903        || benutils.ID (l_pay_rec.payroll_id);
8904    benutils.WRITE (p_text => l_output_string);
8905 
8906    --
8907    IF g_debug
8908    THEN
8909       hr_utility.set_location ('Leaving ' || l_package, 10);
8910    END IF;
8911 --
8912 END person_header_new;
8913 --
8914 --
8915 procedure evaluate_life_events
8916   (p_person_id                in number default null,
8917    p_business_group_id        in number,
8918    p_mode                     in varchar2,
8919    p_ler_id                   in out nocopy number,
8920    -- PB : 5422 :
8921    -- p_popl_enrt_typ_cycl_id    in number,
8922    p_lf_evt_ocrd_dt           in date,
8923    p_effective_date           in date,
8924    p_validate                 in varchar2 default 'N',           /* Bug 5550359 */
8925    p_gsp_eval_elig_flag       in varchar2 default null,          /* GSP Rate Sync */
8926    p_lf_evt_oper_cd           in varchar2 default null) is       /* GSP Rate Sync */
8927   --
8928   l_package               varchar2(80);
8929   l_created_ler_id        ben_ler_f.ler_id%type := null;
8930   l_per_in_ler_id         ben_per_in_ler.per_in_ler_id%type;
8931   l_ptnl_ler              benutils.g_ptnl_ler;
8932   l_effective_start_date  date;
8933   l_effective_end_date    date;
8934   l_rec                   benutils.g_active_life_event;
8935   l_param_rec             benutils.g_batch_param_rec;
8936   l_ler_rec               benutils.g_ler;
8937   l_ler_batch_rec         benutils.g_batch_ler_rec;
8938   l_ptnl_ler_for_per_id   number;
8939   l_object_version_number number;
8940   l_ovn                   number;
8941   l_commit                number;
8942   l_mnl_dt                date;
8943   l_dtctd_dt              date;
8944   l_procd_dt              date;
8945   l_unprocd_dt            date;
8946   l_voidd_dt              date;
8947   l_strtd_dt              date;
8948   l_dummy                 varchar2(1);
8949   --
8950   -- Bug : 3511 : When a potential already sitting and
8951   --       benmngle is ran in scheduled mode with a effective
8952   --       date other than life event occured date a duplicate
8953   --       potential is being created and benmngle is stopping.
8954   --       Use lf_evt_ocrd_dt instead of effective_date in the
8955   --       where clause of c_ler_exists.
8956   -- Bug : 4919 : When a open potential is processed, do not create
8957   --       a new potential, the processed one will be backed out and it will
8958   --       be used for the current run.
8959   --
8960   -- Unrestricted enrollment enhancement-there can be more than one life event on the same day
8961   --
8962   cursor c_ler_exists(cv_ler_id in number,
8963                        cv_person_id in number,
8964                        cv_business_group_id in number,
8965                        cv_lf_evt_ocrd_dt in date) is
8966     select ptn.ptnl_ler_for_per_id
8967     from   ben_ptnl_ler_for_per ptn
8968     where  ptn.ler_id = cv_ler_id
8969     and    ptn.person_id = cv_person_id
8970     and    ptn.business_group_id  = cv_business_group_id
8971     and    ptn.lf_evt_ocrd_dt = cv_lf_evt_ocrd_dt
8972     and    ptn.ptnl_ler_for_per_stat_cd in ('DTCTD','UNPROCD', 'PROCD');
8973   --
8974   l_use_mode          varchar2(80);
8975   l_asnd_lf_evt_dt    date;
8976   l_cv_ler_id         number;
8977   l_cv_lf_evt_ocrd_dt date;
8978   l_gsp_ler_rec           benutils.g_ler;
8979   l_validate         boolean;
8980   --
8981 begin
8982   --
8983   g_debug := hr_utility.debug_enabled;
8984   if g_debug then
8985     l_package := g_package||'.evaluate_life_events';
8986     hr_utility.set_location ('Entering ' || l_package,10);
8987     hr_utility.set_location ('p_mode : ' || p_mode,10);
8988   end if;
8989   --
8990   -- Method of Operation
8991   -- ===================
8992   --
8993   -- In life event mode it is imperative that we recreate the set of comp
8994   -- objects for each person based on the life event occured date of the
8995   -- persons life event. To do this we simply rebuild the set of comp objects
8996   -- using the life event occured on date to derive which objects to use.
8997   -- Certain operations must be done using the life event occured date and
8998   -- certain operations must be done using the effective date. In general when
8999   -- creating records we use the effective date but when looking at reference
9000   -- information we use the life event occured date.
9001   --
9002   -- (1) Log the life event we are attempting to process
9003   -- (2) Evaluate the potential life events
9004   -- (3) If a new winning life event is found then log it
9005   --
9006   ben_env_object.setenv(p_person_id => p_person_id);
9007 
9008   -- Bug 1696526.  Added by Gopal Venkataraman 3/20/01 - This is was done
9009   -- to set the p_lf_evt_ocrd_dt until the real one is determined.
9010   -- Better than using the one from the previous person as is what happens
9011   -- without this.
9012   ben_env_object.setenv(p_lf_evt_ocrd_dt => p_effective_date);
9013   -- Add ended
9014   --
9015   benutils.get_batch_parameters
9016     (p_benefit_action_id => benutils.g_benefit_action_id
9017     ,p_rec               => l_param_rec
9018     );
9019   --
9020   benutils.get_batch_parameters
9021       (p_benefit_action_id => benutils.g_benefit_action_id
9022       ,p_rec               => l_param_rec
9023       );
9024   --
9025   -- CWB Changes : Added mode ABSENCES mode(M) added. Added GRADE/STEP mode
9026   -- added irec mode also
9027   if p_mode in ('G', 'L','C','U','R', 'W', 'M','I','D') then
9028     --
9029     -- CWB Changes : Added mode
9030     -- added irec mode
9031     if p_mode in ('G', 'L','C','W', 'M','I') then
9032       --
9033       --
9034       -- Create life event if person does not currently have an open
9035       -- enrollment.
9036       --
9037       -- CWB Changes : Added mode
9038       -- For Grade/Step : If the date is not null then create potential
9039       -- life events to every one.
9040       --
9041       if (p_mode in ('C', 'W')) or
9042          (p_mode = 'G' and l_param_rec.date_from is not null) then
9043         --
9044         if g_debug then
9045           hr_utility.set_location('Create potential',10);
9046         end if;
9047         if p_mode in ('C', 'W') then
9048            --
9049            l_cv_ler_id := p_ler_id;
9050            l_cv_lf_evt_ocrd_dt := nvl(p_lf_evt_ocrd_dt,
9051                                       p_effective_date);
9052            --
9053         elsif p_mode = 'G' then
9054            --
9055            benutils.get_ler
9056               (p_business_group_id     => p_business_group_id,
9057                p_typ_cd                => 'GSP',
9058                p_effective_date        => p_effective_date,
9059                p_lf_evt_oper_cd        => p_lf_evt_oper_cd,          /* GSP Rate Sync */
9060                p_rec                   => l_gsp_ler_rec);
9061            --
9062            l_cv_ler_id        := l_gsp_ler_rec.ler_id;
9063            --
9064            -- Here date_from is mapped to asg_events_to_all_sel_dt
9065            -- When all GRADE/STEP parameters are added to bft table use
9066            -- the actual column.
9067            --
9068            l_cv_lf_evt_ocrd_dt := l_param_rec.date_from;
9069            --
9070         end if;
9071         --
9072         open c_ler_exists(l_cv_ler_id,
9073                        p_person_id,
9074                        p_business_group_id,
9075                        l_cv_lf_evt_ocrd_dt);
9076           --
9077           fetch c_ler_exists into l_ptnl_ler_for_per_id;
9078           if c_ler_exists%notfound then
9079             --
9080             -- Create potential life event
9081             --
9082             if g_debug then
9083               hr_utility.set_location('Really created GSP potential',10);
9084             end if;
9085             ben_ptnl_ler_for_per_api.create_ptnl_ler_for_per
9086              (p_validate                 => false
9087              ,p_ptnl_ler_for_per_id      => l_ptnl_ler_for_per_id
9088              ,p_lf_evt_ocrd_dt           => l_cv_lf_evt_ocrd_dt
9089              --
9090              -- PB : 5422 : need to modify the form.
9091              -- 99999 Will this affect any where
9092              --
9093              ,p_enrt_perd_id             => null --  p_popl_enrt_typ_cycl_id
9094              ,p_ptnl_ler_for_per_stat_cd => 'DTCTD'
9095              ,p_ntfn_dt                  => trunc(sysdate)
9096              ,p_ler_id                   => l_cv_ler_id
9097              ,p_person_id                => p_person_id
9098              ,p_business_group_id        => p_business_group_id
9099              ,p_object_version_number    => l_ovn
9100              ,p_effective_date           => p_effective_date
9101              ,p_dtctd_dt                 => p_effective_date);
9102              --
9103              if g_debug then
9104                hr_utility.set_location('Finished created potential',10);
9105              end if;
9106              --
9107           end if;
9108           --
9109         close c_ler_exists;
9110         --
9111       end if;
9112       --
9113       fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
9114       --
9115       -- CWB Changes : Added mode
9116       --
9117       if p_mode in ('C', 'L') then
9118          --
9119          if g_debug then
9120            hr_utility.set_location('Evaluate potential',10);
9121          end if;
9122          fnd_message.set_token('PROC','ben_evaluate_ptnl_lf_evt');
9123          --
9124          if p_validate = 'Y'
9125          then
9126            l_validate := TRUE;
9127          else
9128            l_validate := FALSE;
9129          end if;
9130          --
9131          ben_evaluate_ptnl_lf_evt.eval_ptnl_per_for_ler
9132         (p_validate            => l_validate,   /* Bug 5550359 */
9133          p_person_id           => p_person_id,
9134          p_business_group_id   => p_business_group_id,
9135          p_ler_id              => p_ler_id,
9136          p_mode                => p_mode,
9137          p_effective_date      => p_effective_date,
9138          p_created_ler_id      => l_created_ler_id);
9139       --
9140        --
9141       elsif p_mode = 'I' then
9142          --
9143          -- iRec
9144          if g_debug then
9145            hr_utility.set_location('Evaluate iRec Potential LER',10);
9146          end if;
9147 	 --
9148          fnd_message.set_token('PROC','ben_evaluate_ptnl_lf_evt');
9149          --
9150          ben_evaluate_ptnl_lf_evt.irec_eval_ptnl_per_for_ler
9151 		(p_validate            => false,
9152 		 p_person_id           => p_person_id,
9153 		 p_business_group_id   => p_business_group_id,
9154 		 p_ler_id              => g_ler_id,
9155 		 p_mode                => p_mode,
9156 		 p_effective_date      => p_effective_date,
9157 		 p_lf_evt_ocrd_dt      => p_effective_date,
9158 		 p_assignment_id       => g_irec_ass_rec.assignment_id,
9159 		 p_ptnl_ler_for_per_id => null,
9160 		 p_created_ler_id      => l_created_ler_id);
9161 	 --
9162 	 -- iRec
9163       --
9164       --
9165       elsif p_mode = 'W' then
9166          --
9167          if g_debug then
9168            hr_utility.set_location('CWB Evaluate potential',10);
9169          end if;
9170          fnd_message.set_token('PROC','cwb_eval_ptnl_per_for_ler');
9171          --
9172          ben_evaluate_ptnl_lf_evt.cwb_eval_ptnl_per_for_ler
9173         (p_validate            => false,
9174          p_person_id           => p_person_id,
9175          p_business_group_id   => p_business_group_id,
9176          p_ler_id              => p_ler_id,
9177          p_mode                => p_mode,
9178          p_effective_date      => p_effective_date,
9179          p_lf_evt_ocrd_dt      => nvl(p_lf_evt_ocrd_dt,
9180                                                 p_effective_date),
9181          p_ptnl_ler_for_per_id => l_ptnl_ler_for_per_id,
9182          p_created_ler_id      => l_created_ler_id);
9183          --
9184       --
9185       -- ABSENCES mode
9186       --
9187       elsif p_mode = 'M' then
9188          --
9189          ben_evaluate_ptnl_lf_evt.absences_eval_ptnl_per_for_ler
9190         (p_validate            => false,
9191          p_person_id           => p_person_id,
9192          p_business_group_id   => p_business_group_id,
9193          p_ler_id              => p_ler_id,
9194          p_mode                => p_mode,
9195          p_effective_date      => p_effective_date,
9196          p_created_ler_id      => l_created_ler_id);
9197          --
9198       -- GRADE/STEP mode
9199       --
9200       elsif p_mode = 'G' then
9201          --
9202           ben_evaluate_ptnl_lf_evt.grd_stp_eval_ptnl_per_for_ler
9203          (p_validate            => false,
9204           p_person_id           => p_person_id,
9205           p_business_group_id   => p_business_group_id,
9206           p_ler_id              => p_ler_id,
9207           p_mode                => p_mode,
9208           p_effective_date      => p_effective_date,
9209           p_created_ler_id      => l_created_ler_id,
9210           p_lf_evt_oper_cd      => p_lf_evt_oper_cd);   /* GSP Rate Sync */
9211           --
9212       end if;
9213       --
9214     -- Unrestricted Mode should ignore active or potential non-unrestricted mode
9215     -- the following common codes for L,C or U mode is now made only for L or C mode
9216     --
9217     -- CWB Changes 9999 GRADE???? Need a seperate proc?
9218     --
9219     if p_mode <> 'W' then
9220        --
9221        if p_mode = 'G' then
9222           --
9223           benutils.get_active_life_event
9224           (p_person_id         => p_person_id,
9225            p_business_group_id => p_business_group_id,
9226            p_effective_date    => p_effective_date,
9227            p_lf_event_mode   => 'G',
9228            p_rec               => l_rec);
9229           --
9230        elsif p_mode = 'M' then
9231           --
9232           benutils.get_active_life_event
9233           (p_person_id         => p_person_id,
9234            p_business_group_id => p_business_group_id,
9235            p_effective_date    => p_effective_date,
9236            p_lf_event_mode   => 'M',
9237            p_rec               => l_rec);
9238           --
9239        elsif p_mode = 'I' then
9240           --
9241           -- iRec
9242           benutils.get_active_life_event
9243           (p_person_id         => p_person_id,
9244            p_business_group_id => p_business_group_id,
9245            p_effective_date    => p_effective_date,
9246            p_lf_event_mode     => 'I',
9247            p_rec               => l_rec);
9248           --
9249        else
9250           --
9251           benutils.get_active_life_event
9252          (p_person_id             => p_person_id,
9253           p_business_group_id     => p_business_group_id,
9254           p_effective_date        => p_effective_date,
9255           p_rec                   => l_rec);
9256           --
9257        end if;
9258        --
9259     else
9260       --
9261       -- Is it necessary in this procedure as this proc may not be called in W mode.
9262        benutils.get_active_life_event
9263       (p_person_id             => p_person_id,
9264        p_business_group_id     => p_business_group_id,
9265        p_effective_date        => p_effective_date,
9266        p_lf_evt_ocrd_dt        => p_lf_evt_ocrd_dt,
9267        p_ler_id                => p_ler_id,
9268        p_rec                   => l_rec);
9269       --
9270     end if;
9271     --
9272     if g_debug then
9273       hr_utility.set_location ('Done get ale ' || l_package,30);
9274     end if;
9275     --
9276     -- For life event collision detect any life event
9277     -- which was backed out and occured on same day.
9278     --
9279     g_bckdt_per_in_ler_id  := null;
9280     --
9281     -- CWB Changes ABSENCES changes  , GRADE/STEP no restore for Grade life events
9282     -- added irec
9283     if p_mode not in ('W', 'M', 'G','I') then
9284        --
9285        ben_lf_evt_clps_restore.get_ori_bckdt_pil(
9286                             p_person_id            => p_person_id
9287                             ,p_business_group_id   => p_business_group_id
9288                             ,p_ler_id              => l_rec.ler_id
9289                             ,p_effective_date      => l_rec.lf_evt_ocrd_dt
9290                             ,p_bckdt_per_in_ler_id => g_bckdt_per_in_ler_id
9291                            );
9292     end if;
9293     --
9294     if g_debug then
9295       hr_utility.set_location ('Dn BLECR_GOBP ' || l_package,30);
9296     end if;
9297     --
9298     -- PB : 5422 :
9299     -- Now if benmngle is run in Life event mode and the winner
9300     -- is open then change the mode of benmngle run for this
9301     -- person and proceed. Means the mode to be changed on the fly.
9302     --
9303     if (p_mode = 'L' and l_rec.typ_cd in ('SCHEDDO', 'SCHEDDA'))
9304     then
9305        --
9306        ben_manage_life_events.g_modified_mode := 'C';
9307        --
9308     -- 6806014
9309 
9310     -- Now if benmngle is run in Open mode (C) and the winner
9311     -- is a normal life event (which would be processed in mode 'L')
9312     -- then change the mode of benmngle run from 'C' to 'L'  for this
9313     -- person and proceed. Means the mode to be changed on the fly.
9314 
9315     elsif (p_mode = 'C' and l_rec.typ_cd not like 'SCHEDD%') then
9316 
9317        ben_manage_life_events.g_modified_mode := 'L';
9318     -- 6806014
9319     end if;
9320     --
9321     -- PB : If the supplied mode  and mode of winning life event
9322     --      differ, raise error.
9323     --
9324     -- if (p_mode = 'U' and l_rec.typ_cd <> 'SCHEDDU') or
9325     --
9326     if /*(p_mode = 'C' and l_rec.typ_cd not like 'SCHEDD%') or --commented for bug 6806014 */
9327        (p_mode = 'L' and l_rec.typ_cd in ('SCHEDDU','UNRSTR'))
9328        -- PB : 5422 :
9329        -- If benmngle is run in Life event mode and the winner
9330        -- is open then still proceed further.
9331        --
9332        -- PB : 5422 : (p_mode = 'L' and l_rec.typ_cd in ('SCHEDDO', 'SCHEDDA','SCHEDDU','UNRSTR'))
9333     then
9334       --
9335       benutils.write(p_text => 'Winner Life Event : '|| l_rec.name||
9336                                benutils.id(l_rec.ler_id) ||
9337                                ' , Supplied Mode : ' || p_mode);
9338       --
9339       -- Raise error for this person.
9340       --
9341       if (l_rec.typ_cd like 'SCHEDD%' or l_rec.typ_cd = 'UNRSTR') then
9342          l_use_mode := 'Scheduled mode';
9343       else
9344          l_use_mode := 'Life event mode';
9345       end if;
9346       fnd_message.set_name('BEN','BEN_92145_MODE_LE_DIFFER');
9347       fnd_message.set_token('MODE',l_use_mode);
9348       --
9349       -- Bug 2836770
9350       -- Set proper values to global variables before raising error
9351       -- Once value is retrieved from fnd_message.get, the next call
9352       -- return null value. Hence set the values.
9353       --
9354       g_rec.text := fnd_message.get;
9355       g_rec.error_message_code := 'BEN_92145_MODE_LE_DIFFER';
9356       benutils.write(p_text => g_rec.text );
9357       --
9358       -- Bug 2836770
9359       --
9360       -- Bug : 3658807
9361       -- Set the message name so that correct message is displayed in
9362       -- BENAUTHE.pld (Life Events Evaluation Processing Summary) - Messages
9363       --
9364       fnd_message.set_name('BEN','BEN_92145_MODE_LE_DIFFER');
9365       fnd_message.set_token('MODE',l_use_mode);
9366       raise g_record_error;
9367       --
9368     end if;
9369     --
9370     benutils.write(p_text => 'Life Event Occured Date: '||
9371                               l_rec.lf_evt_ocrd_dt);
9372     if l_created_ler_id <> nvl(p_ler_id,-1) then
9373       --
9374       -- Get life event name we are dealing with, put in global structure
9375       --
9376       p_ler_id := l_created_ler_id;
9377       benutils.write(p_text => 'Winner Life Event : '||
9378                                 l_rec.name||
9379                                 benutils.id(l_rec.ler_id));
9380       --
9381     end if;
9382     --
9383     ben_env_object.setenv(p_lf_evt_ocrd_dt => l_rec.lf_evt_ocrd_dt);
9384     dt_fndate.change_ses_date
9385       (p_ses_date => l_rec.lf_evt_ocrd_dt,
9386        p_commit   => l_commit);
9387     fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
9388     fnd_message.set_token('PROC','ben_related_person_ler_api');
9389     if g_debug then
9390       hr_utility.set_location (l_package||' create_rel_per_ler ' ,20);
9391     end if;
9392     --
9393     -- CWB Changes ABSENCES , GRADE/STEP : no need to create related ler's
9394     --
9395     if p_mode not in ('W', 'M', 'G','I') then
9396       --
9397       ben_related_person_ler_api.create_related_person_ler
9398       (p_validate          => false,
9399        p_person_id         => p_person_id,
9400        p_ler_id            => p_ler_id,
9401        p_effective_date    => p_effective_date,
9402        p_business_group_id => p_business_group_id,
9403        p_csd_by_ptnl_ler_for_per_id => l_rec.ptnl_ler_for_per_id,
9404        p_from_form         => 'N' );
9405       --
9406     end if;
9407     --
9408     -- CWB Changes
9409     --
9410     if nvl(ben_manage_life_events.g_modified_mode, p_mode) in ('C','W') then
9411        l_asnd_lf_evt_dt := l_rec.lf_evt_ocrd_dt;
9412     end if;
9413     --
9414     if p_mode = 'G' and p_lf_evt_oper_cd = 'SYNC'
9415     then
9416       --
9417       -- GSP Rate Sync : For this case we would not build compensation object list, but get current grade ladder / grade step
9418       -- and populate g_cache_proc_object in procedure process_comp_objects later
9419       hr_utility.set_location('GSP Rate Sync : Do not build comp obj list here', 23);
9420       --
9421     else
9422       if g_debug then
9423         hr_utility.set_location (l_package||' Bef BCOL ' ,25);
9424       end if;
9425 
9426       ben_comp_object_list.build_comp_object_list
9427         (p_benefit_action_id      => benutils.g_benefit_action_id
9428         ,p_comp_selection_rule_id => l_param_rec.comp_selection_rl
9429         ,p_effective_date         => l_rec.lf_evt_ocrd_dt
9430         ,p_pgm_id                 => l_param_rec.pgm_id
9431         ,p_business_group_id      => l_param_rec.business_group_id
9432         ,p_pl_id                  => l_param_rec.pl_id
9433         -- PB : 5422 :
9434         -- ,p_popl_enrt_typ_cycl_id  => l_param_rec.popl_enrt_typ_cycl_id
9435         ,p_asnd_lf_evt_dt         => l_asnd_lf_evt_dt
9436         ,p_no_programs            => l_param_rec.no_programs_flag
9437         ,p_no_plans               => l_param_rec.no_plans_flag
9438         ,p_rptg_grp_id            => l_param_rec.rptg_grp_id
9439         ,p_pl_typ_id              => l_param_rec.pl_typ_id
9440         ,p_opt_id                 => l_param_rec.opt_id
9441         ,p_eligy_prfl_id          => l_param_rec.eligy_prfl_id
9442         ,p_vrbl_rt_prfl_id        => l_param_rec.vrbl_rt_prfl_id
9443         ,p_thread_id              => benutils.g_thread_id
9444         -- PB : 5422 :
9445         ,p_mode                   => nvl(ben_manage_life_events.g_modified_mode,l_param_rec.mode_cd)
9446         -- ,p_mode                   => l_param_rec.mode_cd
9447         ,p_lmt_prpnip_by_org_flag => l_param_rec.lmt_prpnip_by_org_flag
9448         ,p_person_id              => p_person_id
9449         );
9450       if g_debug then
9451         hr_utility.set_location (l_package||' Dn BCOL ' ,27);
9452       end if;
9453       --
9454     end if;
9455       --
9456       -- if mode is 'U' unrestricted
9457       -- Get life event reason information for the passed in typ_cd.
9458       --
9459     elsif (p_mode = 'U' or p_mode = 'R' or p_mode = 'D') then /* IF p_mode IN ('G', 'L', 'C', 'U', 'R', 'W', 'M', 'I') */
9460       --
9461      if p_mode = 'D' then
9462       --
9463     benutils.get_active_life_event
9464        (p_person_id         => p_person_id,
9465         p_business_group_id => p_business_group_id,
9466         p_effective_date    => p_effective_date,
9467         p_lf_event_mode     => 'U',
9468         p_rec               => l_rec);
9469        --
9470      else
9471       --
9472       ben_manage_unres_life_events.delete_elctbl_choice
9473         (p_person_id         => p_person_id
9474         ,p_effective_date    => p_effective_date
9475         ,p_business_group_id => p_business_group_id
9476         ,p_rec               => l_rec
9477         );
9478       --
9479    end if;
9480     --
9481 --   if p_mode in ('U','D') then -- Bug 6321565
9482       --
9483       benutils.get_ler
9484           (p_business_group_id     => p_business_group_id,
9485            p_typ_cd                => 'SCHEDDU',
9486            p_effective_date        => p_effective_date,
9487            p_rec                   => l_ler_rec);
9488       --
9489   --  end if;
9490     --
9491      if l_rec.per_in_ler_id is null then
9492          --
9493          ben_ptnl_ler_for_per_api.create_ptnl_ler_for_per
9494              (p_validate                 => false
9495              ,p_ptnl_ler_for_per_id      => l_ptnl_ler_for_per_id
9496                 --
9497                 -- PB : 5422 : need to modify the form.
9498                 --
9499              ,p_enrt_perd_id             => null  -- p_popl_enrt_typ_cycl_id
9500              ,p_lf_evt_ocrd_dt           => p_effective_date
9501              ,p_ptnl_ler_for_per_stat_cd => 'DTCTD'
9502              ,p_ler_id                   => l_ler_rec.ler_id
9503              ,p_person_id                => p_person_id
9504              ,p_business_group_id        => p_business_group_id
9505              ,p_object_version_number    => l_object_version_number
9506              ,p_effective_date           => p_effective_date
9507              ,p_ntfn_dt                  => trunc(sysdate)
9508              ,p_dtctd_dt                 => p_effective_date);
9509          --
9510          l_rec.ptnl_ler_for_per_id := l_ptnl_ler_for_per_id;
9511          --
9512       end if;
9513       --
9514       -- Update the ptnl per for ler for the person
9515       --
9516       if p_ler_id is null then
9517          p_ler_id := l_ler_rec.ler_id;
9518       end if;
9519       --
9520       ben_ptnl_ler_for_per_api.update_ptnl_ler_for_per
9521         (p_validate                 => false
9522         ,p_object_version_number    => l_object_version_number
9523         ,p_ptnl_ler_for_per_id      => l_rec.ptnl_ler_for_per_id
9524         ,p_lf_evt_ocrd_dt           => p_effective_date
9525         ,p_ptnl_ler_for_per_stat_cd => 'PROCD'
9526         ,p_ler_id                   => p_ler_id
9527         ,p_person_id                => p_person_id
9528         ,p_business_group_id        => p_business_group_id
9529         ,p_effective_date           => p_effective_date
9530         ,p_program_application_id   => fnd_global.prog_appl_id
9531         ,p_program_id               => fnd_global.conc_program_id
9532         ,p_request_id               => fnd_global.conc_request_id
9533         ,p_program_update_date      => sysdate
9534         ,p_ntfn_dt                  => trunc(sysdate)
9535         ,p_procd_dt                 => p_effective_date);
9536       --
9537       -- Since this process does not go through the evaluate life event
9538       -- process we need to make this the active life event
9539       --
9540       l_ler_batch_rec.person_id := p_person_id;
9541       l_ler_batch_rec.ler_id := p_ler_id;
9542       l_ler_batch_rec.lf_evt_ocrd_dt := p_effective_date;
9543       l_ler_batch_rec.replcd_flag := 'N';
9544       l_ler_batch_rec.crtd_flag := 'Y';
9545       l_ler_batch_rec.tmprl_flag := 'N';
9546       l_ler_batch_rec.dltd_flag := 'N';
9547       l_ler_batch_rec.open_and_clsd_flag := 'N';
9548       l_ler_batch_rec.not_crtd_flag := 'N';
9549       l_ler_batch_rec.clsd_flag := 'N';
9550       l_ler_batch_rec.stl_actv_flag := 'N';
9551       l_ler_batch_rec.clpsd_flag := 'N';
9552       l_ler_batch_rec.clsn_flag := 'N';
9553       l_ler_batch_rec.no_effect_flag := 'N';
9554       l_ler_batch_rec.cvrge_rt_prem_flag := 'N';
9555       l_ler_batch_rec.business_group_id := p_business_group_id;
9556       l_ler_batch_rec.effective_date := p_effective_date;
9557       --
9558       benutils.write(p_rec => l_ler_batch_rec);
9559       if g_debug then
9560         hr_utility.set_location (l_package,60);
9561       end if;
9562       if l_rec.per_in_ler_id is null then
9563          ben_person_life_event_api.create_person_life_Event
9564            (p_validate                => false,
9565             p_per_in_ler_id           => l_per_in_ler_id,
9566             p_ler_id                  => p_ler_id,
9567             p_person_id               => p_person_id,
9568             p_ptnl_ler_for_per_id     => l_ptnl_ler_for_per_id,
9569             p_per_in_ler_stat_cd      => 'STRTD',
9570             p_lf_evt_ocrd_dt          => p_effective_date,
9571             p_business_group_id       => p_business_group_id,
9572             p_object_version_number   => l_object_version_number,
9573             p_effective_date          => p_effective_date,
9574             p_program_application_id  => fnd_global.prog_appl_id,
9575             p_program_id              => fnd_global.conc_program_id,
9576             p_request_id              => fnd_global.conc_request_id,
9577             p_program_update_date     => sysdate
9578            ,p_procd_dt                => l_procd_dt
9579            ,p_strtd_dt                => l_strtd_dt
9580            ,p_voidd_dt                => l_voidd_dt
9581            );
9582           -- only one started unrestricted for a person
9583           if p_mode = 'U' then
9584             commit;
9585           end if;
9586        else
9587           ben_person_life_event_api.update_person_life_event
9588             (p_per_in_ler_id           => l_rec.per_in_ler_id,
9589              p_per_in_ler_stat_cd      => 'STRTD',
9590              p_object_version_number   => l_rec.object_version_number,
9591              p_lf_evt_ocrd_dt          => p_effective_date,
9592              p_effective_date          => p_effective_date,
9593              p_procd_dt                => l_procd_dt,
9594              p_strtd_dt                => l_strtd_dt,
9595              p_voidd_dt                => l_voidd_dt);
9596        end if;
9597        --
9598        if p_mode = 'R' then
9599          --
9600           ben_comp_object_list.build_comp_object_list
9601          (p_benefit_action_id      => benutils.g_benefit_action_id
9602          ,p_comp_selection_rule_id => l_param_rec.comp_selection_rl
9603          ,p_effective_date         => p_effective_date
9604          ,p_pgm_id                 => l_param_rec.pgm_id
9605          ,p_business_group_id      => l_param_rec.business_group_id
9606          ,p_pl_id                  => l_param_rec.pl_id
9607          ,p_asnd_lf_evt_dt         => l_asnd_lf_evt_dt
9608          ,p_no_programs            => l_param_rec.no_programs_flag
9609          ,p_no_plans               => l_param_rec.no_plans_flag
9610          ,p_rptg_grp_id            => l_param_rec.rptg_grp_id
9611          ,p_pl_typ_id              => l_param_rec.pl_typ_id
9612          ,p_opt_id                 => l_param_rec.opt_id
9613          ,p_eligy_prfl_id          => l_param_rec.eligy_prfl_id
9614          ,p_vrbl_rt_prfl_id        => l_param_rec.vrbl_rt_prfl_id
9615          ,p_thread_id              => benutils.g_thread_id
9616          ,p_mode                   => 'U'
9617          ,p_lmt_prpnip_by_org_flag => l_param_rec.lmt_prpnip_by_org_flag
9618          ,p_person_id              => p_person_id
9619          );
9620         --
9621       end if;
9622       --
9623     end if;
9624     --
9625     fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
9626     fnd_message.set_token('PROC','benutils.get_batch_parameters');
9627     ben_enrolment_requirements.g_electable_choice_created := false;
9628     ben_enrolment_requirements.g_any_choice_created := false;
9629     ben_enrolment_requirements.g_auto_choice_created := false;
9630     ben_determine_dpnt_eligibility.g_dpnt_ineligible := false;
9631     --
9632   elsif l_param_rec.lmt_prpnip_by_org_flag = 'Y'
9633         and p_mode in ('A','P','S','T') then
9634     --
9635     -- PB : Healthnet changes
9636     -- Build the comp object list in evaluate_life_events
9637     -- if comp objects selection is based on person's org id.
9638     --
9639     if g_debug then
9640       hr_utility.set_location (' Temp BCOL '||l_package,10);
9641     end if;
9642     ben_comp_object_list.build_comp_object_list
9643       (p_benefit_action_id      => benutils.g_benefit_action_id
9644       ,p_comp_selection_rule_id => l_param_rec.comp_selection_rl
9645       ,p_effective_date         => p_effective_date
9646       ,p_pgm_id                 => l_param_rec.pgm_id
9647       ,p_business_group_id      => l_param_rec.business_group_id
9648       ,p_pl_id                  => l_param_rec.pl_id
9649       -- PB : 5422 :
9650       -- ,p_popl_enrt_typ_cycl_id  => l_param_rec.popl_enrt_typ_cycl_id
9651       ,p_asnd_lf_evt_dt         => null
9652       ,p_no_programs            => l_param_rec.no_programs_flag
9653       ,p_no_plans               => l_param_rec.no_plans_flag
9654       ,p_rptg_grp_id            => l_param_rec.rptg_grp_id
9655       ,p_pl_typ_id              => l_param_rec.pl_typ_id
9656       ,p_opt_id                 => l_param_rec.opt_id
9657       ,p_eligy_prfl_id          => l_param_rec.eligy_prfl_id
9658       ,p_vrbl_rt_prfl_id        => l_param_rec.vrbl_rt_prfl_id
9659       ,p_thread_id              => benutils.g_thread_id
9660       -- PB : 5422 :
9661       ,p_mode                   => p_mode
9662       -- ,p_mode                   => l_param_rec.mode_cd
9663       ,p_lmt_prpnip_by_org_flag => l_param_rec.lmt_prpnip_by_org_flag
9664       ,p_person_id              => p_person_id
9665       );
9666     --
9667     -- Set up participation eligibility for all comp objects in the list
9668     --
9669     set_up_list_part_elig
9670          (p_ler_id            => null
9671          ,p_business_group_id => p_business_group_id
9672          ,p_effective_date    => p_effective_date
9673          );
9674     if g_debug then
9675       hr_utility.set_location (' Dn Temp BCOL '||l_package,10);
9676     end if;
9677     --
9678   end if;
9679   --
9680   if g_debug then
9681     hr_utility.set_location ('Leaving '||l_package,10);
9682   end if;
9683   --
9684   exception
9685     --
9686     when others then
9687       raise;
9688     --
9689 end evaluate_life_events;
9690 --
9691 procedure process_comp_objects
9692   (p_person_id                in number default null
9693   ,p_person_action_id         in number
9694   ,p_object_version_number    in out nocopy number
9695   ,p_business_group_id        in number
9696   ,p_mode                     in varchar2
9697   ,p_ler_id                   in number default null
9698   ,p_derivable_factors        in varchar2 default 'ASC'
9699   ,p_cbr_tmprl_evt_flag       in varchar2 default 'N'
9700   ,p_person_count             in out nocopy number
9701   -- PB : 5422 :
9702   ,p_lf_evt_ocrd_dt           in date default null
9703   -- ,p_popl_enrt_typ_cycl_id    in number
9704   ,p_effective_date           in date
9705   ,p_gsp_eval_elig_flag       in varchar2 default null      /* GSP Rate Sync */
9706   ,p_lf_evt_oper_cd           in varchar2 default null      /* GSP Rate Sync */
9707   )
9708 is
9709   --
9710   -- PB : 5422 :
9711   -- This is not being used
9712   --
9713   /*
9714   cursor c_strt_dt is
9715     select strt_dt
9716     from   ben_enrt_perd
9717     where  enrt_perd_id = p_popl_enrt_typ_cycl_id;
9718   */
9719   --
9720   cursor c_get_inelig_dpnt_info(p_per_in_ler_id in number) is
9721   -- RCHASE - wwBug1427383 - return correct date for creating dependent benefit assignment
9722     select pdp.dpnt_person_id, min(egd.elig_thru_dt) cvg_thru_dt--min(pdp.cvg_thru_dt) cvg_thru_dt
9723     from   ben_elig_cvrd_dpnt_f pdp
9724           ,ben_elig_dpnt egd
9725           ,ben_prtt_enrt_rslt_f pen
9726     where pdp.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
9727     and   pen.person_id = p_person_id
9728     and   pen.effective_end_date = hr_api.g_eot
9729     and   pen.business_group_id = p_business_group_id
9730     and   nvl(pdp.cvg_thru_dt,hr_api.g_eot) <> hr_api.g_eot
9731     and   pdp.business_group_id = pen.business_group_id
9732     and   pdp.elig_cvrd_dpnt_id = egd.elig_cvrd_dpnt_id
9733     and   egd.dpnt_inelig_flag = 'Y'
9734     and   egd.per_in_ler_id = p_per_in_ler_id
9735     and   egd.business_group_id = pdp.business_group_id
9736     group by pdp.dpnt_person_id;
9737   --
9738   cursor c_pil_elctbl_chc_popl (p_per_in_ler_id in number) is
9739    select popl.pil_elctbl_chc_popl_id,
9740           popl.object_version_number
9741    from   ben_pil_elctbl_chc_popl popl
9742    where  per_in_ler_id =  p_per_in_ler_id
9743    and    not exists
9744           (select null
9745            from ben_elig_per_elctbl_chc epe
9746            where epe.pil_elctbl_chc_popl_id = popl.pil_elctbl_chc_popl_id
9747            and   elctbl_flag = 'Y');
9748   --
9749   cursor c_pil (p_per_in_ler_id number, p_pgm_id number, p_pl_id number) is
9750     select 'Y'
9751     from ben_pil_elctbl_chc_popl popl
9752     where  per_in_ler_id =  p_per_in_ler_id
9753     and    (popl.pgm_id = p_pgm_id  or
9754             popl.pl_id  = p_pl_id);
9755   --
9756   l_rec                        benutils.g_active_life_event;
9757   l_lf_rec                     benutils.g_active_life_event;
9758   --
9759   cursor c_ptnl is
9760     select a.ptnl_ler_for_per_id ptnl_ler_for_per_id,
9761            a.object_version_number object_version_number
9762     from   ben_ptnl_ler_for_per a,
9763            ben_per_in_ler b
9764     where  b.per_in_ler_id = l_rec.per_in_ler_id
9765     and    b.ptnl_ler_for_per_id = a.ptnl_ler_for_per_id;
9766   --
9767   cursor c_ptip_pl_id(p_gsp_pgm_id  number,
9768                       p_gsp_plip_id number) is
9769   select ptip.ptip_id,
9770          pln.pl_id
9771     from ben_ptip_f ptip,
9772          ben_pl_f pln,
9773          ben_plip_f plip
9774    where plip.plip_id = p_gsp_plip_id
9775      and plip.pgm_id = p_gsp_pgm_id
9776      and p_effective_date between plip.effective_start_date
9777      and plip.effective_end_date
9778      and pln.pl_id = plip.pl_id
9779      and plip.effective_start_date between pln.effective_start_date
9780      and pln.effective_end_date
9781      and ptip.pl_typ_id = pln.pl_typ_id
9782      and ptip.pgm_id = p_gsp_pgm_id
9783      and p_effective_date between ptip.effective_start_date
9784      and ptip.effective_end_date;
9785   --
9786   --  Min Max enhancement.
9787   --
9788   cursor c_get_ended_enrt_rslts(p_per_in_ler_id number) is
9789     select pen.*
9790     from ben_prtt_enrt_rslt_f pen
9791     where pen.person_id = p_person_id
9792     and pen.prtt_enrt_rslt_stat_cd is null
9793     and pen.sspndd_flag = 'N'
9794     and pen.enrt_cvg_thru_dt <> hr_api.g_eot
9795     and pen.effective_end_date = hr_api.g_eot
9796     and p_effective_date between pen.effective_start_date
9797                              and pen.effective_end_date
9798     and pen.business_group_id = p_business_group_id
9799     and pen.comp_lvl_cd not in ('PLANFC', 'PLANIMP')
9800     and pen.per_in_ler_id = p_per_in_ler_id
9801     ;
9802   cursor c_get_ptip_tot_enrd(p_ptip_id number) is
9803     select count(*)
9804     from ben_prtt_enrt_rslt_f pen
9805     where pen.person_id = p_person_id
9806     and pen.prtt_enrt_rslt_stat_cd is null
9807     and pen.sspndd_flag = 'N'
9808     and pen.ptip_id = p_ptip_id
9809     and pen.comp_lvl_cd not in ('PLANFC', 'PLANIMP')
9810     and (   pen.enrt_cvg_thru_dt =  hr_api.g_eot
9811          or (    pen.enrt_cvg_thru_dt >= p_effective_date
9812              and nvl(pen.enrt_ovridn_flag,'N') = 'Y'
9813             )
9814         )
9815     and pen.effective_end_date = hr_api.g_eot
9816     and p_effective_date between pen.effective_start_date
9817                              and pen.effective_end_date
9818     and pen.business_group_id = p_business_group_id
9819     ;
9820 
9821   cursor c_get_ptip(p_ptip_id number) is
9822     select ptip.ptip_id,
9823            ptip.pgm_id,
9824            ptip.pl_typ_id,
9825            ptip.Mx_ENRD_ALWD_OVRID_NUM,
9826            ptip.no_mx_pl_typ_ovrid_flag,
9827            ptip.MN_ENRD_RQD_OVRID_NUM,
9828            ptip.no_mn_pl_typ_overid_flag,
9829            plt.name,
9830            Plt.MN_ENRL_RQD_NUM,
9831            plt.MX_ENRL_ALWD_NUM
9832       from ben_ptip_f ptip
9833          , ben_pl_typ_f plt
9834      where ptip.ptip_id = p_ptip_id
9835        and ptip.pl_typ_id = plt.pl_typ_id
9836        and ptip.business_group_id = p_business_group_id
9837        and p_effective_date between
9838                ptip.effective_start_date and ptip.effective_end_date
9839        and p_effective_date between
9840                plt.effective_start_date and plt.effective_end_date
9841            ;
9842   --
9843   cursor c_get_ptip_elig(p_ptip_id       number
9844                         ,p_per_in_ler_id number
9845                          ) is
9846     select pep.elig_flag
9847       from ben_elig_per_f pep
9848      where pep.per_in_ler_id = p_per_in_ler_id
9849        and pep.ptip_id = p_ptip_id
9850        and pep.business_group_id = p_business_group_id
9851        and p_effective_date between pep.effective_start_date
9852                             and pep.effective_end_date
9853            ;
9854 
9855   l_ptip_rec                   c_get_ptip%rowtype;
9856   l_count                      number(15);
9857   l_pep_row                    ben_derive_part_and_rate_facts.g_cache_structure;
9858   l_chk_min_max                varchar2(30);
9859   l_ptip_elig_flag             varchar2(30);
9860   l_MN_ENRD_RQD_OVRID_NUM      ben_ptip_f.MN_ENRD_RQD_OVRID_NUM%type;
9861   --
9862   -- End Min Max enhancement.
9863   --
9864   l_rec_ptnl_ler_for_per_id number;
9865   l_rec_object_version_number number;
9866   --
9867   l_package                    varchar2(80);
9868   --
9869   l_enb_valrow                 ben_determine_coverage.ENBValType;
9870   --
9871   l_env                        ben_env_object.g_global_env_rec_type;
9872   l_comp_obj_tree              ben_manage_life_events.g_cache_proc_object_table;
9873   l_par_elig_state             ben_comp_obj_filter.g_par_elig_state_rec;
9874   l_comp_obj_tree_row          ben_manage_life_events.g_cache_proc_objects_rec;
9875   l_parpepgm_row               ben_prtn_elig_f%rowtype;
9876   l_parpeptip_row              ben_prtn_elig_f%rowtype;
9877   l_parpeplip_row              ben_prtn_elig_f%rowtype;
9878   l_parpepl_row                ben_prtn_elig_f%rowtype;
9879   l_paretprpgm_row             ben_elig_to_prte_rsn_f%rowtype;
9880   l_paretprptip_row            ben_elig_to_prte_rsn_f%rowtype;
9881   l_paretprplip_row            ben_elig_to_prte_rsn_f%rowtype;
9882   l_paretprpl_row              ben_elig_to_prte_rsn_f%rowtype;
9883   l_currpe_row                 ben_prtn_elig_f%rowtype;
9884   l_curretpr_row               ben_elig_to_prte_rsn_f%rowtype;
9885   l_currpgm_row                ben_pgm_f%rowtype;
9886   l_currptip_row               ben_ptip_f%rowtype;
9887   l_currplip_row               ben_plip_f%rowtype;
9888   l_currpl_row                 ben_pl_f%rowtype;
9889   l_curroipl_row               ben_cobj_cache.g_oipl_inst_row;
9890   l_curroiplip_row             ben_cobj_cache.g_oiplip_inst_row;
9891   l_parpgm_row                 ben_pgm_f%rowtype;
9892   l_parptip_row                ben_ptip_f%rowtype;
9893   l_parplip_row                ben_plip_f%rowtype;
9894   l_parpl_row                  ben_pl_f%rowtype;
9895   l_paropt_row                 ben_cobj_cache.g_opt_inst_row;
9896   l_paroipl_row                ben_cobj_cache.g_oipl_inst_row;
9897   l_per_row                    per_all_people_F%rowtype;
9898   l_pil_row                    ben_per_in_ler%rowtype;
9899   l_empasg_row                 per_all_assignments_f%rowtype;
9900   l_benasg_row                 per_all_assignments_f%rowtype;
9901   l_appasg_row                 ben_person_object.g_cache_ass_table;
9902   l_empasgast_row              per_assignment_status_types%rowtype;
9903   l_benasgast_row              per_assignment_status_types%rowtype;
9904   --
9905   l_comp_object_value          varchar2(80);
9906   l_comp_object_name           varchar2(80);
9907   l_output_string              varchar2(100);
9908   l_per_grade                  number := null;
9909   l_per_job                    number := null;
9910   l_per_per_typ                varchar2(30) := null;
9911   l_per_pay_basis_id           number := null;
9912   l_per_benfts_grp_id          number := null;
9913   l_per_pyrl_id                number := null;
9914   l_per_location_id            number := null;
9915   l_per_org_id                 number := null;
9916   l_per_peo_group_id           number := null;
9917   l_postal_code                varchar2(30) := null;
9918   l_py_freq                    varchar2(30) := null;
9919   l_normal_hours               number := null;
9920   l_frequency                  varchar2(30) := null;
9921   l_bargaining_unit_code       varchar2(30) := null;
9922   l_assignment_status_type_id  number := null;
9923   l_change_rsn                 varchar2(30) := null;
9924   l_gre_cd                     varchar2(150) := null;
9925   l_enrlt_pl_id                number := null;
9926   l_employment_category        varchar2(30) := null;
9927   l_prtt_is_cvrd_flag          varchar2(30) := null;
9928   l_sspndd_flag                varchar2(30) := null;
9929   l_electable_flag             varchar2(30) := null;
9930   l_once_r_cntug_cd            varchar2(30) := null;
9931   l_elig_flag                  varchar2(30) := null;
9932   l_elig_per_elctbl_chc_id     number :=null;
9933   l_strt_dt                    date :=null;
9934   l_effective_start_date       date;
9935   l_effective_end_date         date;
9936   l_loop_count                 number;
9937   l_commit                     number;
9938   l_procd_dt                   date;
9939   l_voidd_dt                   date;
9940   l_strtd_dt                   date;
9941   l_pl_id                      number;
9942   l_cwb_pl_id                  number;
9943   l_plip_id                    number;
9944   l_ptip_id                    number;
9945   l_pgm_id                     number;
9946   l_oipl_id                    number;
9947   --
9948   l_newly_elig    boolean;
9949   l_newly_inelig  boolean;
9950   l_first_elig    boolean;
9951   l_first_inelig  boolean;
9952   l_still_elig    boolean;
9953   l_still_inelig  boolean;
9954   l_continue_loop boolean;
9955   l_eligible      boolean;
9956   l_not_eligible  boolean;
9957   l_elig_state_change boolean := false;
9958   --
9959   l_pl_nip         varchar2(30);
9960   --
9961   l_treeele_num    pls_integer;
9962   l_maxtreeele_num pls_integer;
9963   l_treeloop       boolean;
9964   l_boundary       boolean;
9965   l_comp_rec       ben_derive_part_and_rate_facts.g_cache_structure;
9966   l_d_comp_rec       ben_derive_part_and_rate_facts.g_cache_structure;
9967   l_oiplip_rec     ben_derive_part_and_rate_facts.g_cache_structure;
9968   l_d_oiplip_rec     ben_derive_part_and_rate_facts.g_cache_structure;
9969   --
9970   l_object_version_number number;
9971   l_perhasmultptus        boolean;
9972   l_assignment_id         number;
9973   l_pil_elctbl_chc_popl  c_pil_elctbl_chc_popl%rowtype;
9974   l_asnd_lf_evt_dt        date;
9975   --
9976   l_mode                varchar2(1); -- Added by Gopal Venkataraman 3/27/01 bug 1636071.
9977   l_pil                  varchar2(1);
9978   l_gsp_pgm_id           number;
9979   l_gsp_ptip_id          number;
9980   l_gsp_plip_id          number;
9981   l_gsp_pl_id            number;
9982   l_prgr_style           varchar2(30);
9983   l_evaluate_eligibility boolean := true;
9984 
9985   --
9986   -- FONM : Begin
9987   --
9988   l_rec_enrt_cvg_strt_dt         DATE;
9989   l_fonm_cvg_strt_dt             DATE;
9990   l_dummy_rt_strt_dt             DATE;
9991   l_dummy_rt_strt_dt_cd          VARCHAR2(30);
9992   l_dummy_rt_strt_dt_rl          NUMBER;
9993   l_dummy_enrt_cvg_end_dt        DATE;
9994   l_dummy_enrt_cvg_end_dt_cd     VARCHAR2(30);
9995   l_dummy_enrt_cvg_end_dt_rl     NUMBER;
9996   l_dummy_rt_end_dt              DATE;
9997   l_dummy_rt_end_dt_cd           VARCHAR2(30);
9998   l_dummy_rt_end_dt_rl           NUMBER;
9999   l_dummy_enrt_cvg_strt_dt_cd    VARCHAR2(30);
10000   l_dummy_enrt_cvg_strt_dt_rl    NUMBER;
10001   l_rec_lee_rsn_id               NUMBER;
10002   l_rec_enrt_perd_id             NUMBER;
10003   l_dummy                        VARCHAR2(30);
10004 
10005   l_old_data_migrator_mode varchar2(1) ;-- irec2
10006 
10007   -- to get the le_resn id
10008   cursor c_lee_rsn(c_pl_id number ,
10009                    c_pgm_id number,
10010                    c_effective_date date) is
10011   select 1 ordr_num ,
10012          leer.lee_rsn_id,
10013         NVL(leer.defer_deenrol_flag,'N')
10014     FROM     ben_lee_rsn_f leer, ben_popl_enrt_typ_cycl_f petc
10015       WHERE    leer.ler_id = p_ler_id
10016       AND      leer.business_group_id = p_business_group_id
10017       AND      c_effective_date BETWEEN leer.effective_start_date
10018                    AND leer.effective_end_date
10019       AND      leer.popl_enrt_typ_cycl_id = petc.popl_enrt_typ_cycl_id
10020       AND      petc.pl_id = c_pl_id
10021       AND      petc.enrt_typ_cycl_cd = 'L'                        -- life event
10022       AND      petc.business_group_id = p_business_group_id
10023       AND      c_effective_date BETWEEN petc.effective_start_date
10024                    AND petc.effective_end_date
10025    UNION
10026     select 2 ordr_num ,
10027          leer.lee_rsn_id,
10028         NVL(leer.defer_deenrol_flag,'N')
10029      FROM     ben_lee_rsn_f leer, ben_popl_enrt_typ_cycl_f petc
10030       WHERE    leer.ler_id = p_ler_id
10031       AND      leer.business_group_id = p_business_group_id
10032       AND      c_effective_date BETWEEN leer.effective_start_date
10033                    AND leer.effective_end_date
10034       AND      leer.popl_enrt_typ_cycl_id = petc.popl_enrt_typ_cycl_id
10035       AND      petc.pgm_id = c_pgm_id
10036       AND      petc.enrt_typ_cycl_cd = 'L'                        -- life event
10037       AND      petc.business_group_id = p_business_group_id
10038       AND      c_effective_date BETWEEN petc.effective_start_date
10039                    AND petc.effective_end_date
10040    order by 1 ;
10041 
10042   -- to get the enrol_period id
10043   cursor c_enrt_perd_id (c_pl_id number ,
10044                    c_pgm_id number,
10045                    c_effective_date date) is
10046    select 1 ordr_num ,
10047           enrtp.enrt_perd_id,
10048           NVL(enrtp.defer_deenrol_flag,'N')
10049     FROM  ben_popl_enrt_typ_cycl_f petc,
10050           ben_enrt_perd enrtp,
10051                 ben_ler_f ler
10052    WHERE  petc.pl_id = c_pl_id
10053      AND  petc.business_group_id = p_business_group_id
10054      AND  c_effective_date BETWEEN petc.effective_start_date
10055           AND petc.effective_end_date
10056      AND  petc.enrt_typ_cycl_cd <> 'L'
10057      AND  enrtp.business_group_id = p_business_group_id
10058      AND  enrtp.asnd_lf_evt_dt  = c_effective_date
10059      AND  enrtp.popl_enrt_typ_cycl_id  = petc.popl_enrt_typ_cycl_id
10060      -- comp work bench changes
10061      and  ler.ler_id (+) = enrtp.ler_id
10062      and  ler.ler_id (+) = p_ler_id
10063      and  c_effective_date between ler.effective_start_date (+)
10064           and ler.effective_end_date (+)
10065    UNION
10066    select 2 ordr_num ,
10067           enrtp.enrt_perd_id,
10068           NVL(enrtp.defer_deenrol_flag,'N')
10069     FROM  ben_popl_enrt_typ_cycl_f petc,
10070           ben_enrt_perd enrtp,
10071                 ben_ler_f ler
10072    WHERE  petc.pgm_id = c_pgm_id
10073      AND  petc.business_group_id = p_business_group_id
10074      AND  c_effective_date BETWEEN petc.effective_start_date
10075           AND petc.effective_end_date
10076      AND  petc.enrt_typ_cycl_cd <> 'L'
10077      AND  enrtp.business_group_id = p_business_group_id
10078      AND  enrtp.asnd_lf_evt_dt  = c_effective_date
10079      AND  enrtp.popl_enrt_typ_cycl_id  = petc.popl_enrt_typ_cycl_id
10080      -- comp work bench changes
10081      and  ler.ler_id (+) = enrtp.ler_id
10082      and  ler.ler_id (+) = p_ler_id
10083      and  c_effective_date between ler.effective_start_date (+)
10084           and ler.effective_end_date (+)
10085     order by 1 ;
10086 
10087 
10088   --
10089   l_last_ptip_id    number  ;
10090   l_pgm_fonm   varchar2(1) ;
10091   l_ptip_fonm  varchar2(1) ;
10092   -- FONM : End
10093 
10094   --
10095   -- GSP Rate Sync
10096   l_gsp_emp_step_id                     number(30);
10097   l_gsp_num_incr                        number(30);
10098   l_gsp_oipl_id                         number(30);
10099   l_gsp_oiplip_id                       number(30);
10100   l_gsp_opt_id                          number(30);
10101   --
10102   cursor c_get_oiplip_opt_id (cv_oipl_id number,
10103                               cv_plip_id number) is
10104     select opp.oiplip_id, opt_id
10105       from ben_oiplip_f opp, ben_oipl_f cop
10106      where opp.oipl_id = cv_oipl_id
10107        and opp.plip_id = cv_plip_id
10108        and p_effective_date between opp.effective_start_date and opp.effective_end_date
10109        and cop.oipl_id = opp.oipl_id
10110        and p_effective_date between cop.effective_start_date and cop.effective_end_date;
10111   -- GSP Rate Sync
10112   --
10113 -- Defer ENH.
10114   cursor c_pel_defer(p_pgm_id number,p_per_in_ler_id in number) is
10115     select pel.*
10116     from   ben_pil_elctbl_chc_popl pel
10117     where  pel.pgm_id = p_pgm_id
10118      and   pel.pl_id is null
10119      and   pel.pil_elctbl_popl_stat_cd not in ('VOIDD','BCKDT')
10120      and   pel.per_in_ler_id = p_per_in_ler_id;
10121   --
10122   l_pel_defer c_pel_defer%ROWTYPE;
10123   --
10124   cursor c_pel_pnip_defer (p_pl_id number,p_per_in_ler_id in number) is
10125   --
10126     select  pel.*
10127     from    ben_pil_elctbl_chc_popl pel
10128     where   pel.pl_id = p_pl_id
10129      and    pel.pgm_id is null
10130      and    pel.pil_elctbl_popl_stat_cd not in ('VOIDD','BCKDT')
10131      and    pel.per_in_ler_id = p_per_in_ler_id;
10132   --
10133  l_pel_pnip_defer c_pel_pnip_defer%ROWTYPE;
10134  l_defer_popl_id NUMBER;
10135  l_defer_popl_ovn NUMBER;
10136 
10137  type l_defer_deenrl_rec is record
10138   (pl_id               ben_pl_f.pl_id%type
10139   ,pgm_id              ben_pgm_f.pgm_id%type
10140   ,chc_exists          boolean
10141   ,newly_inelig_exists boolean
10142   );
10143 
10144   type l_defer_deenrl_table is table of l_defer_deenrl_rec
10145   index by binary_integer;
10146 
10147 l_defer_deenrl_tbl l_defer_deenrl_table;
10148 l_defer_count number := 0;
10149 
10150   --
10151 -- Defer ENH.
10152 begin
10153   --
10154   g_debug := hr_utility.debug_enabled;
10155   if g_debug then
10156     l_package :=g_package||'.process_comp_objects';
10157     hr_utility.set_location ('Entering '||l_package,10);
10158   end if;
10159   --
10160   -- Start -  Added by Gopal Venkataraman 3/27/01 bug 1636071
10161   -- also changed all following p_mode to l_mode.
10162   l_mode := nvl(ben_manage_life_events.g_modified_mode,p_mode);
10163   l_defer_deenrl_tbl.delete;
10164   -- End
10165   dbms_session.free_unused_user_memory;
10166   --
10167   -- ben_prtt_enrt_result_api.g_enrollment_change := FALSE; -- VP 11/08/00
10168   -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
10169   if l_mode not in ('A','P','S','T') then
10170     -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
10171     if g_debug then
10172       hr_utility.set_location('mode'||l_mode,11);
10173     end if;
10174     --
10175     -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
10176     if (l_mode = 'U'or l_mode = 'R' or l_mode = 'D') then
10177      --
10178      if l_mode <> 'D' then
10179       benutils.get_active_life_event
10180       (p_person_id         => p_person_id,
10181        p_business_group_id => p_business_group_id,
10182        p_effective_date    => p_effective_date,
10183        p_lf_event_mode   =>  'U',
10184        p_rec               => l_rec);
10185       --
10186      else
10187       --
10188       benutils.get_active_life_event
10189       (p_person_id         => p_person_id,
10190        p_business_group_id => p_business_group_id,
10191        p_effective_date    => p_effective_date,
10192        p_lf_event_mode   =>  'D',
10193        p_rec               => l_rec);
10194      --
10195     end if;
10196      --
10197        benutils.get_active_life_event
10198        (p_person_id         => p_person_id,
10199         p_business_group_id => p_business_group_id,
10200         p_effective_date    => p_effective_date,
10201         p_rec               => l_lf_rec);
10202 
10203     --
10204     else
10205       --
10206       -- CWB Changes .
10207       --
10208      if l_mode = 'W' then
10209        --
10210        benutils.get_active_life_event
10211       (p_person_id             => p_person_id,
10212        p_business_group_id     => p_business_group_id,
10213        p_effective_date        => p_effective_date,
10214        p_lf_evt_ocrd_dt        => p_lf_evt_ocrd_dt,
10215        p_ler_id                => p_ler_id,
10216        p_rec                   => l_rec);
10217       --
10218      elsif l_mode = 'G' then
10219       --
10220       benutils.get_active_life_event
10221       (p_person_id         => p_person_id,
10222        p_business_group_id => p_business_group_id,
10223        p_effective_date    => p_effective_date,
10224        p_lf_event_mode   => 'G',
10225        p_rec               => l_rec);
10226       --
10227      elsif l_mode = 'M' then
10228       --
10229       benutils.get_active_life_event
10230       (p_person_id         => p_person_id,
10231        p_business_group_id => p_business_group_id,
10232        p_effective_date    => p_effective_date,
10233        p_lf_event_mode   => 'M',
10234        p_rec               => l_rec);
10235       --
10236     elsif l_mode = 'I' then
10237       --
10238       -- iRec
10239       benutils.get_active_life_event
10240       (p_person_id         => p_person_id,
10241        p_business_group_id => p_business_group_id,
10242        p_effective_date    => p_effective_date,
10243        p_lf_event_mode     => 'I',
10244        p_rec               => l_rec);
10245       --
10246      else
10247        --
10248        benutils.get_active_life_event
10249        (p_person_id         => p_person_id,
10250         p_business_group_id => p_business_group_id,
10251         p_effective_date    => p_effective_date,
10252         p_rec               => l_rec);
10253        --
10254      end if;
10255      --
10256     end if;
10257     if g_debug then
10258       hr_utility.set_location('Current OVN '||l_rec.object_version_number,10);
10259       hr_utility.set_location('lf evt date '||l_rec.lf_evt_ocrd_dt,11);
10260     end if;
10261   end if;
10262   --
10263   -- Setup environment for person being processed.
10264   --
10265   if g_debug then
10266     hr_utility.set_location (l_package||' Set env ',20);
10267   end if;
10268   ben_env_object.setenv(p_lf_evt_ocrd_dt => l_rec.lf_evt_ocrd_dt);
10269   --
10270   -- Clear eligibility caches
10271   --
10272   ben_pep_cache.clear_down_cache;
10273   ben_epe_cache.clear_down_cache;
10274   --
10275   dt_fndate.change_ses_date
10276     (p_ses_date => nvl(l_rec.lf_evt_ocrd_dt,p_effective_date)
10277     ,p_commit   => l_commit
10278     );
10279   --
10280   -- Get environment values
10281   --
10282   ben_env_object.get
10283     (p_rec => l_env
10284     );
10285   --
10286   -- Get person info
10287   --
10288   ben_person_object.get_object
10289     (p_person_id => p_person_id
10290     ,p_rec       => l_per_row
10291     );
10292   --
10293   ben_person_object.get_object
10294     (p_person_id => p_person_id
10295     ,p_rec       => l_empasg_row
10296     );
10297   --
10298   if l_empasg_row.assignment_id is not null then
10299     --
10300     ben_person_object.get_object
10301       (p_assignment_status_type_id => l_empasg_row.assignment_status_type_id
10302       ,p_rec                       => l_empasgast_row
10303       );
10304     --
10305   end if;
10306   --
10307   ben_person_object.get_benass_object
10308     (p_person_id => p_person_id
10309     ,p_rec       => l_benasg_row
10310     );
10311   --
10312   if l_benasg_row.assignment_id is not null then
10313     --
10314     ben_person_object.get_object
10315       (p_assignment_status_type_id => l_benasg_row.assignment_status_type_id
10316       ,p_rec                       => l_benasgast_row
10317       );
10318     --
10319   end if;
10320   --
10321   -- If benefit assignment not found, get applicant assignment.
10322   --
10323   if l_benasg_row.assignment_id is null then
10324     --
10325     ben_person_object.get_object
10326       (p_person_id => p_person_id
10327       ,p_rec       => l_appasg_row
10328       );
10329     --
10330   end if;
10331   --
10332   -- Fixes WWBUG 1412808.
10333   -- In case a backout has occurred that uses communications we need to
10334   -- reset the cache for ther person life event object
10335   --
10336   ben_person_object.g_cache_last_pil_rec := l_pil_row;
10337   ben_person_object.g_cache_pil_rec.delete;
10338   --
10339   ben_person_object.get_object
10340     (p_person_id => p_person_id
10341 --  unrestricted  change
10342     ,p_per_in_ler_id =>l_rec.per_in_ler_id
10343     ,p_rec       => l_pil_row
10344     );
10345   --
10346   if g_debug then
10347     hr_utility.set_location ('Life event occured datee'||l_pil_row.lf_evt_ocrd_dt,11);
10348   end if;
10349   -- Assign comp object cache to a local variable
10350   --
10351   l_comp_obj_tree  := g_cache_proc_object;
10352   --
10353   -- Flush duplicate ptip list
10354   --
10355   ben_comp_obj_filter.flush_dupproc_ptip_list;
10356   --
10357   l_treeele_num    := l_comp_obj_tree.first;
10358   l_treeloop       := TRUE;
10359   l_maxtreeele_num := l_comp_obj_tree.last;
10360   --
10361   -- If we are running in temporal mode then we may only want to
10362   -- create certain temporal events so set the temporal ler id we
10363   -- want to test
10364   --
10365   -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
10366   --
10367   ben_derive_part_and_rate_facts.g_no_ptnl_ler_id := null ;
10368   --
10369   if l_mode = 'T' then
10370     --
10371     ben_derive_part_and_rate_facts.g_temp_ler_id  := p_ler_id;
10372     --
10373   else
10374     --
10375     --For unrestricted enrollment we dont want to trigger the pdpar potentials
10376     --Also don't trigger potentials for the following modes
10377     --
10378     if l_mode in ('U','W','M','I','P','A','D') then
10379       ben_derive_part_and_rate_facts.g_no_ptnl_ler_id := p_ler_id ;
10380     end if;
10381     --
10382     -- Globals are kept for a session so reset the global in the package
10383     --
10384     ben_derive_part_and_rate_facts.g_temp_ler_id  := null;
10385     --
10386   end if;
10387   --
10388   --GSP: do not need to evaluate eligibility for entire comp object list
10389   --
10390   if l_mode ='G' then
10391      /* GSP Rate Sync
10392      *  The following function fetches current Grade Ladder and Grade for a person being processed
10393      *  If the person does not have any assigned grade ladder or grade, then default grade ladder and grade
10394      *  for the business group are returned. In case of GSP Rate Sync, always current (assigned) Grade Ladder and Grade
10395      *  will be returned because GSP Rate Sync process will reach here only if person has GSP Prog processed once
10396      *  in the past.
10397      */
10398      get_grade_step_placement
10399           (p_person_id          => p_person_id,
10400            p_assignment_id      => l_empasg_row.assignment_id,
10401            p_business_group_id  => p_business_group_id,
10402            p_effective_date     => p_effective_date,
10403            p_gsp_pgm_id         => l_gsp_pgm_id,
10404            p_gsp_plip_id        => l_gsp_plip_id,
10405            p_gsp_oipl_id        => l_gsp_oipl_id,
10406            p_prgr_style         => l_prgr_style,
10407            p_gsp_emp_step_id    => l_gsp_emp_step_id,
10408            p_gsp_num_incr       => l_gsp_num_incr);
10409      /*
10410      pqh_gsp_post_process.get_persons_gl_and_grade
10411      (p_person_id            => p_person_id,
10412       p_business_group_id    => p_business_group_id,
10413       p_effective_date       => p_effective_date,
10414       p_persons_pgm_id       => l_gsp_pgm_id,
10415       p_persons_plip_id      => l_gsp_plip_id,
10416       p_prog_style           => l_prgr_style);
10417      */
10418      if g_debug then
10419         hr_utility.set_location('p_persons_pgm_id :'||l_gsp_pgm_id,20);
10420         hr_utility.set_location('p_persons_plip_id :'||l_gsp_plip_id,20);
10421         hr_utility.set_location('p_prog_style :'||l_prgr_style,20);
10422         hr_utility.set_location('l_gsp_oipl_id :' || l_gsp_oipl_id,20);
10423      end if;
10424      --
10425      -- no grade ladder defined (or) no grade, then skip the person
10426      --
10427      if l_gsp_pgm_id is null or
10428         l_gsp_plip_id is null
10429      then
10430         hr_utility.set_location('Current GSP Grade Ladder / Grade / PLIP for person not found', 15);
10431         fnd_message.set_name('BEN','BEN_94094_PERSON_GRADE_NOT_FND');
10432         raise g_record_error;
10433      elsif l_prgr_style not in ('PQH_GSP_GP') and l_gsp_oipl_id is null  /* Bug 3964719 */
10434      then
10435         hr_utility.set_location('Current GSP OIPL for person not found', 15);
10436         fnd_message.set_name('BEN','BEN_94095_PERSON_STEP_NOT_FND');
10437         raise g_record_error;
10438      end if;
10439      --
10440      open c_ptip_pl_id(l_gsp_pgm_id,l_gsp_plip_id);
10441        fetch c_ptip_pl_id into l_gsp_ptip_id,l_gsp_pl_id;
10442      close c_ptip_pl_id;
10443      --
10444      if l_prgr_style not in ('PQH_GSP_GP')
10445      then
10446        --
10447        open c_get_oiplip_opt_id(l_gsp_plip_id,l_gsp_oipl_id );
10448          fetch c_get_oiplip_opt_id into l_gsp_oiplip_id, l_gsp_opt_id;
10449        close c_get_oiplip_opt_id;
10450        --
10451      end if;
10452      --
10453      /*
10454      *  The following call will populate G_CACHE_PROC_OBJECT with the PGM_ID, PL_ID, PLIP_ID and OIPL_ID records
10455      *  corresponding to the current Grade / Step Placement of the person.
10456      */
10457      if p_lf_evt_oper_cd = 'SYNC'
10458      then
10459        --
10460        ben_comp_object_list.build_gsp_rate_sync_coobj_list
10461          (p_effective_date         => p_effective_date
10462          ,p_business_group_id      => p_business_group_id
10463          ,p_pgm_id                 => l_gsp_pgm_id
10464          ,p_pl_id                  => l_gsp_pl_id
10465          ,p_opt_id                 => l_gsp_opt_id
10466          ,p_plip_id                => l_gsp_plip_id
10467          ,p_ptip_id                => l_gsp_ptip_id
10468          ,p_oipl_id                => l_gsp_oipl_id
10469          ,p_oiplip_id              => l_gsp_oiplip_id
10470          ,p_person_id              => p_person_id
10471          ) ;
10472        --
10473        l_comp_obj_tree  := g_cache_proc_object;
10474        l_treeele_num    := l_comp_obj_tree.first;
10475        l_treeloop       := TRUE;
10476        l_maxtreeele_num := l_comp_obj_tree.last;
10477        --
10478      end if;
10479      --
10480   end if;
10481   --
10482   fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
10483   fnd_message.set_token('PROC','BEN_CARRY_FORWARD_ITEMS');
10484   --
10485   -- If the event is staying open, then delete the suspended enrollments
10486   -- and action items
10487   --
10488   if l_mode = 'L' or l_mode = 'C' then
10489     if p_ler_id is not null then
10490          --
10491          ben_carry_forward_items.main
10492          (p_effective_date => p_effective_date
10493          ,p_lf_evt_ocrd_dt => l_rec.lf_evt_ocrd_dt
10494          ,p_per_in_ler_id  => l_rec.per_in_ler_id
10495          ,p_ler_id  => p_ler_id
10496          ,p_business_group_id => p_business_group_id
10497          ,p_person_id => p_person_id);
10498         --
10499     end if;
10500   end if;
10501   --
10502   loop
10503     if g_debug then
10504       hr_utility.set_location (l_package||' Start Proc loop ',20);
10505     end if;
10506     --
10507     -- Comp object filtering. Navigate to the next comp object to be processed
10508     -- We do not need to filter in temporal mode because we do not check
10509     -- eligibility.
10510     --
10511     -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
10512     if l_mode <> 'T' then
10513       --
10514       if g_debug then
10515         hr_utility.set_location (l_package||' Filtering ',20);
10516       end if;
10517       -- Bug#1900657
10518       if l_mode in ('U','D') then
10519         if l_lf_rec.per_in_ler_id is not null then
10520           loop
10521             --
10522             open c_pil(l_lf_rec.per_in_ler_id,
10523                        l_comp_obj_tree(l_treeele_num).par_pgm_id,
10524                        l_comp_obj_tree(l_treeele_num).par_pl_id);
10525             fetch c_pil into l_pil;
10526             if c_pil%found then
10527               close c_pil;
10528               if l_treeele_num = l_maxtreeele_num then
10529                 --
10530                 l_treeloop := FALSE;
10531                 exit;
10532                 --
10533               else
10534                 --
10535                 l_treeele_num := l_treeele_num+1;
10536                 --
10537               end if;
10538               --
10539             else
10540               close c_pil;
10541               exit;
10542             end if;
10543             --
10544           end loop;
10545           --
10546         end if;
10547         --
10548       end if;
10549       --
10550       if not l_treeloop then
10551          exit;
10552       end if;
10553       --
10554       -- GLOBALCWB : Bug 4214845 : All comp objects must be processed, in
10555       -- cwb mode as data have to be created with elig flag = N in case of in-eligibility.
10556       --
10557       if l_mode <> 'W' then
10558         --
10559         ben_comp_obj_filter.filter_comp_objects
10560         (p_comp_obj_tree         => l_comp_obj_tree
10561         -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
10562         ,p_mode                  => l_mode
10563         ,p_person_id             => p_person_id
10564         ,p_effective_date        => nvl(l_rec.lf_evt_ocrd_dt,p_effective_date)
10565         ,p_maxtreeele_num        => l_maxtreeele_num
10566         --
10567         ,p_par_elig_state        => l_par_elig_state
10568         ,p_treeele_num           => l_treeele_num
10569         --
10570         ,p_treeloop              => l_treeloop
10571         ,p_ler_id                => p_ler_id
10572         -- PB : 5422 :
10573         ,p_lf_evt_ocrd_dt        => p_lf_evt_ocrd_dt
10574         -- ,p_popl_enrt_typ_cycl_id => p_popl_enrt_typ_cycl_id
10575         ,p_business_group_id     => p_business_group_id
10576         );
10577         --
10578       end if;
10579       if g_debug then
10580         hr_utility.set_location (l_package||' Dn Filtering ',20);
10581       end if;
10582       --
10583     end if;
10584     --
10585     -- Check if the end of the comp object list was reached
10586     -- otherwise refresh environment globals. These globals
10587     -- are referenced in BENDETE2.
10588     --
10589     if not l_treeloop then
10590       --
10591       exit;
10592       --
10593     else
10594       --
10595       -- Reset locals to new tree location values
10596       --
10597       l_pgm_id            := l_comp_obj_tree(l_treeele_num).pgm_id;
10598       l_ptip_id           := l_comp_obj_tree(l_treeele_num).ptip_id;
10599       l_plip_id           := l_comp_obj_tree(l_treeele_num).plip_id;
10600       l_pl_id             := l_comp_obj_tree(l_treeele_num).pl_id;
10601       l_oipl_id           := l_comp_obj_tree(l_treeele_num).oipl_id;
10602       l_pl_nip            := l_comp_obj_tree(l_treeele_num).pl_nip;
10603       l_comp_obj_tree_row := l_comp_obj_tree(l_treeele_num);
10604       --
10605     end if;
10606     --
10607 
10608     -- bof  FONM  Determine whther the  pgm/pl set for FONM
10609 
10610    if g_debug then
10611      hr_utility.set_location ('OIpl Id '||l_oipl_id,31);
10612      hr_utility.set_location (' l_pl_nip ' || l_pl_nip,30);
10613      hr_utility.set_location (' g_last_pgm_id ' || g_last_pgm_id,30);
10614      hr_utility.set_location (' l_last_ptip_id ' || l_last_ptip_id,30);
10615      hr_utility.set_location (' pgm ' ||l_comp_obj_tree(l_treeele_num).par_pgm_id ,30);
10616      hr_utility.set_location (' ptip ' ||l_comp_obj_tree(l_treeele_num).par_ptip_id ,30);
10617      hr_utility.set_location (' pl ' ||l_comp_obj_tree(l_treeele_num).par_pl_id ,30);
10618      hr_utility.set_location (' plip ' ||l_comp_obj_tree(l_treeele_num).par_plip_id ,30);
10619      hr_utility.set_location ('Old fonm ' ||ben_manage_life_events.fonm ,30);
10620      hr_utility.set_location ('Old pgm fonm ' || l_pgm_fonm ,30);
10621      hr_utility.set_location ('Old ptip fonm ' || l_ptip_fonm ,30);
10622    end if;
10623    -- FONM II
10624    if l_pl_nip = 'Y'
10625          -- whne the new program
10626       or (  nvl(g_last_pgm_id,-1) <>  l_comp_obj_tree(l_treeele_num).par_pgm_id )
10627          -- if the pgm level fonm determined as no  then dont look below
10628          -- and if there is ptip then look @ ptip , there can be one ptip fonm other non fonm
10629          -- that case pgm is allways FONM
10630       or (  nvl(g_last_pgm_id,-1) =  l_comp_obj_tree(l_treeele_num).par_pgm_id and
10631             l_pgm_fonm  = 'Y'  and l_ptip_fonm is  null
10632           )
10633          -- new ptip
10634          -- when the pgm is fonm then validate for ptip fonm
10635       or ( l_pgm_fonm  = 'Y'  and
10636            (  l_ptip_fonm   =  'Y' or nvl(l_last_ptip_id,-1) <>  l_comp_obj_tree(l_treeele_num).par_ptip_id
10637            )
10638          )
10639       or ben_manage_life_events.fonm is null then
10640 
10641             hr_utility.set_location (' calling  fonm status  ' ,30);
10642             ben_use_cvg_rt_date.get_csd_rsd_Status
10643                                    (p_pgm_id         => l_comp_obj_tree(l_treeele_num).par_pgm_id
10644                                    ,p_ptip_id        => l_comp_obj_tree(l_treeele_num).par_ptip_id
10645                                    ,p_plip_id        => l_comp_obj_tree(l_treeele_num).par_plip_id
10646                                    ,p_pl_id          => l_comp_obj_tree(l_treeele_num).par_pl_id
10647                                    ,p_effective_date => p_effective_date
10648                                    ,p_status         => ben_manage_life_events.fonm
10649                                    ) ;
10650              hr_utility.set_location (' fonm ' ||ben_manage_life_events.fonm ,30);
10651    end if ;
10652    -- eof FONM
10653 
10654     -- Set up environment for retrieval of comp object information
10655     --
10656     if l_pl_nip = 'Y' then
10657       --
10658       g_last_pgm_id := null;
10659       --
10660     elsif l_comp_obj_tree(l_treeele_num).par_pgm_id is not null then
10661       --
10662       g_last_pgm_id := l_comp_obj_tree(l_treeele_num).par_pgm_id;
10663 
10664       hr_utility.set_location (' fonm ptip ' || l_comp_obj_tree(l_treeele_num).par_ptip_id ,30);
10665 
10666       if l_comp_obj_tree(l_treeele_num).par_ptip_id is not null then
10667          l_last_ptip_id := l_comp_obj_tree(l_treeele_num).par_ptip_id ;
10668          hr_utility.set_location (' fonm plip ' ||l_comp_obj_tree(l_treeele_num).par_plip_id ,30);
10669          -- if the plip is null then the fonm for ptio
10670          if l_comp_obj_tree(l_treeele_num).par_plip_id is  null then
10671 
10672             l_ptip_fonm := ben_manage_life_events.fonm ;
10673          end if ;
10674       else
10675          l_pgm_fonm     := ben_manage_life_events.fonm ;
10676          l_ptip_fonm    := null ;
10677       end if ;
10678       --
10679     end if;
10680     --
10681     -- Check if the audit log flag is on
10682     --
10683     if g_debug then
10684       hr_utility.set_location (l_package||' get_comp_object_name ',30);
10685     end if;
10686     if l_env.audit_log_flag = 'Y' then
10687       --
10688       get_comp_object_name
10689         (p_oipl_id           => l_oipl_id
10690         ,p_pgm_id            => l_pgm_id
10691         ,p_pl_id             => l_pl_id
10692         ,p_plip_id           => l_plip_id
10693         ,p_ptip_id           => l_ptip_id
10694         ,p_pl_nip            => l_pl_nip
10695         ,p_comp_object_name  => l_comp_object_name
10696         ,p_comp_object_value => l_comp_object_value
10697         );
10698       --
10699       g_output_string := rpad(l_comp_object_value,21,' ')||rpad(l_comp_object_name,30,' ');
10700     end if;
10701 
10702     l_evaluate_eligibility := true;
10703 
10704     if l_mode ='G' then
10705 
10706 /*      l_evaluate_eligibility := (l_comp_obj_tree_row.par_pgm_id = l_gsp_pgm_id)
10707                                 and
10708                                 (    (nvl(l_prgr_style,'PQH_GSP_SP') <> 'PQH_GSP_SP')
10709                                   or (     l_comp_obj_tree_row.par_ptip_id = l_gsp_ptip_id
10710                                        and nvl(l_comp_obj_tree_row.par_plip_id,l_gsp_plip_id) = l_gsp_plip_id
10711                                        and nvl(l_comp_obj_tree_row.par_pl_id,l_gsp_pl_id) = l_gsp_pl_id
10712                                       )
10713                                 );
10714 */
10715       l_evaluate_eligibility :=  ( (nvl(l_prgr_style,'PQH_GSP_SP') = 'PQH_GSP_SP' )
10716                                    and
10717 				   ( l_comp_obj_tree_row.par_pgm_id = l_gsp_pgm_id
10718 				     and nvl(l_comp_obj_tree_row.par_ptip_id,l_gsp_ptip_id) = l_gsp_ptip_id
10719                                      and nvl(l_comp_obj_tree_row.par_plip_id,l_gsp_plip_id) = l_gsp_plip_id
10720                                      and nvl(l_comp_obj_tree_row.par_pl_id,l_gsp_pl_id) = l_gsp_pl_id )
10721 				  or
10722 				   ( nvl(l_prgr_style,'PQH_GSP_SP') <> 'PQH_GSP_SP' )
10723                                        and ( l_comp_obj_tree_row.par_pgm_id = l_gsp_pgm_id )
10724 				   );
10725 
10726       if g_debug then
10727          if l_evaluate_eligibility then
10728             hr_utility.set_location('Processing '||l_comp_obj_tree_row.par_pgm_id||','||l_comp_obj_tree_row.par_ptip_id||','||l_comp_obj_tree_row.par_plip_id||','||l_comp_obj_tree_row.par_pl_id||','||l_oipl_id,80);
10729          else
10730             hr_utility.set_location('Skipping '||l_comp_obj_tree_row.par_pgm_id||','||l_comp_obj_tree_row.par_ptip_id||','||l_comp_obj_tree_row.par_plip_id||','||l_comp_obj_tree_row.par_pl_id||','||l_oipl_id,80);
10731          end if;
10732       end if;
10733 
10734     end if;
10735 
10736     /* GSP Rate Sync */
10737     if p_mode = 'G' and p_lf_evt_oper_cd = 'SYNC' and p_gsp_eval_elig_flag = 'N'
10738     then
10739       --
10740       /* GSP Rate Sync :
10741       *  If Evaluate Eligibility is No, then do not go through evaluate eligibility process
10742       *  If Evaluate Eligibility is Yes, then through evaluate eligibility process for current
10743       *                                  grade ladder, grade and step
10744       *  Make a call to PQHGSP package, that will create electable choices and rates.
10745       */
10746       hr_utility.set_location('GSP Rate Sync Do Not Evaluate Eligibility', 45);
10747       hr_utility.set_location('GSPRS p_effective_date = ' || p_effective_date, 45);
10748       hr_utility.set_location('GSPRS l_pil_row.per_in_ler_id = ' || l_pil_row.per_in_ler_id, 45);
10749       hr_utility.set_location('GSPRS p_person_id = ' || p_person_id, 45);
10750       hr_utility.set_location('GSPRS l_empasg_row.assignment_id = ' || l_empasg_row.assignment_id, 45);
10751       --
10752 
10753       -- This procedure will create Electable Choices and Rates
10754       pqh_gsp_post_process.gsp_rate_sync
10755         (p_effective_date     => p_effective_date
10756         ,p_per_in_ler_id      => l_pil_row.per_in_ler_id
10757         ,p_person_id          => p_person_id
10758         ,p_assignment_id      => l_empasg_row.assignment_id
10759         );
10760 
10761       -- This procedure will update salary if at all new salary has changed from current salary
10762       pqh_gsp_post_process.update_rate_sync_salary
10763          (p_per_in_ler_id   => l_pil_row.per_in_ler_id
10764          ,p_effective_date  => p_effective_date
10765          );
10766 
10767       --
10768       p_person_count := p_person_count +1;
10769       --
10770       g_action_rec.person_action_id := p_person_action_id;
10771       g_action_rec.action_status_cd := 'P';
10772       g_action_rec.ler_id := p_ler_id;
10773       g_action_rec.object_version_number := p_object_version_number;
10774       g_action_rec.effective_date := p_effective_date;
10775       --
10776       benutils.write(p_rec => g_action_rec);
10777       --
10778       return;
10779       --
10780     elsif l_evaluate_eligibility
10781     then
10782 
10783       --
10784       -- Set up participation eligibility
10785       --
10786       if g_debug then
10787          hr_utility.set_location (l_package||' Set Part Elig  ',80);
10788       end if;
10789       --
10790       -- Set up comp object context rows
10791       --
10792       -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
10793       if l_mode <> 'T' then
10794         --
10795         set_up_cobj_part_elig
10796         (p_comp_obj_tree_row => l_comp_obj_tree_row
10797         ,p_ler_id            => p_ler_id
10798         ,p_business_group_id => p_business_group_id
10799         -- Bug 3087889 Passing lf_evt_ocrd_dt
10800       	,p_effective_date        => nvl(l_rec.lf_evt_ocrd_dt,p_effective_date)
10801         -- End of Bug 3087889
10802           );
10803         --
10804       end if;
10805       --
10806       if l_mode in ('L', 'C', 'A') then
10807        --
10808        g_defer_deenrol_flag := 'N';
10809        --
10810 	 if  l_mode in  ('L') then
10811 
10812               open  c_lee_rsn(c_pl_id => l_comp_obj_tree(l_treeele_num).par_pl_id,
10813                         c_pgm_id=> l_comp_obj_tree(l_treeele_num).par_pgm_id,
10814                         c_effective_date => nvl(l_rec.lf_evt_ocrd_dt, p_effective_date)
10815                         ) ;
10816               fetch c_lee_rsn into l_dummy , l_rec_lee_rsn_id ,g_defer_deenrol_flag ;
10817               close  c_lee_rsn  ;
10818 
10819          elsif l_mode in ( 'C' , 'A') then
10820               open  c_enrt_perd_id(c_pl_id => l_comp_obj_tree(l_treeele_num).par_pl_id,
10821                         c_pgm_id=> l_comp_obj_tree(l_treeele_num).par_pgm_id,
10822                         c_effective_date => nvl(l_rec.lf_evt_ocrd_dt, p_effective_date)
10823                         ) ;
10824               fetch c_enrt_perd_id into l_dummy ,l_rec_enrt_perd_id ,g_defer_deenrol_flag  ;
10825               close c_enrt_perd_id ;
10826         --
10827 	end if ;
10828       --
10829     end if;
10830      --
10831     if g_debug then
10832       hr_utility.set_location(' g_defer_deenrol_flag' || g_defer_deenrol_flag, 9653);
10833     end if;
10834       hr_utility.set_location (' FONM : ' || ben_manage_life_events.fonm  ,80);
10835       -- BOF  FONM
10836     if  l_mode in ('L','C') and -- Bug 6390880
10837         ben_manage_life_events.fonm = 'Y'   then
10838 
10839            hr_utility.set_location (' FONM : Begin  ',80);
10840             hr_utility.set_location(' l_pgm_id = ' || l_pgm_id, 4444);
10841             hr_utility.set_location(' l_pl_id = ' || l_pl_id, 4444);
10842             hr_utility.set_location(' l_oipl_id = ' || l_oipl_id, 4444);
10843             hr_utility.set_location(' l_ptip_id = ' || l_ptip_id, 4444);
10844             hr_utility.set_location(' l_plip_id = ' || l_plip_id, 4444);
10845           if g_debug then
10846             hr_utility.set_location('p_pgm_id'||l_comp_obj_tree(l_treeele_num).par_pgm_id,1234);
10847             hr_utility.set_location('p_pl_id'||l_comp_obj_tree(l_treeele_num).par_pl_id,1234);
10848             hr_utility.set_location('p_plip_id'||l_comp_obj_tree(l_treeele_num).par_plip_id,1234);
10849             hr_utility.set_location('p_ptip_id'||l_comp_obj_tree(l_treeele_num).par_ptip_id,1234);
10850             hr_utility.set_location('p_oipl_id'||l_oipl_id,1234);
10851           end if;
10852 
10853        /*   if  l_mode in  ('L') then
10854 
10855               open  c_lee_rsn(c_pl_id => l_comp_obj_tree(l_treeele_num).par_pl_id,
10856                         c_pgm_id=> l_comp_obj_tree(l_treeele_num).par_pgm_id,
10857                         c_effective_date => nvl(l_rec.lf_evt_ocrd_dt, p_effective_date)
10858                         ) ;
10859               fetch c_lee_rsn into l_dummy , l_rec_lee_rsn_id ;
10860               close  c_lee_rsn  ;
10861 
10862           elsif l_mode in ( 'C' , 'A') then
10863               open  c_enrt_perd_id(c_pl_id => l_comp_obj_tree(l_treeele_num).par_pl_id,
10864                         c_pgm_id=> l_comp_obj_tree(l_treeele_num).par_pgm_id,
10865                         c_effective_date => nvl(l_rec.lf_evt_ocrd_dt, p_effective_date)
10866                         ) ;
10867               fetch c_enrt_perd_id into l_dummy ,l_rec_enrt_perd_id  ;
10868               close c_enrt_perd_id ;
10869 
10870 
10871           end if ;*/
10872           hr_utility.set_location(' l_rec_lee_rsn_id ' || l_rec_lee_rsn_id, 99 );
10873           hr_utility.set_location(' c_enrt_perd_id '   || l_rec_enrt_perd_id , 99 );
10874           hr_utility.set_location(' p_ler_id  '   || p_ler_id , 99 );
10875           hr_utility.set_location(' p_pgm_id  '   || l_comp_obj_tree(l_treeele_num).par_pgm_id , 99 );
10876           hr_utility.set_location(' p_pl_id  '   || l_comp_obj_tree(l_treeele_num).par_pl_id , 99 );
10877           hr_utility.set_location(' p_ptip  '   ||  l_comp_obj_tree(l_treeele_num).par_ptip_id , 99 );
10878           hr_utility.set_location(' p_plip  '   ||  l_comp_obj_tree(l_treeele_num).par_plip_id , 99 );
10879           hr_utility.set_location(' p_oipl  '   ||  l_oipl_id , 99 );
10880 
10881            ben_determine_date.rate_and_coverage_dates
10882              (p_cache_mode          => TRUE
10883              ,p_per_in_ler_id       => l_rec.per_in_ler_id
10884              ,p_person_id           => p_person_id
10885              ,p_pgm_id              => l_comp_obj_tree(l_treeele_num).par_pgm_id
10886              ,p_pl_id               => l_comp_obj_tree(l_treeele_num).par_pl_id
10887              ,p_oipl_id             => l_oipl_id
10888              ,p_par_ptip_id         => l_comp_obj_tree(l_treeele_num).par_ptip_id
10889              ,p_par_plip_id         => l_comp_obj_tree(l_treeele_num).par_plip_id
10890              ,p_lee_rsn_id          => l_rec_lee_rsn_id
10891              ,p_enrt_perd_id        => l_rec_enrt_perd_id
10892              ,p_business_group_id   => p_business_group_id
10893              ,p_which_dates_cd      => 'C'
10894              ,p_date_mandatory_flag => 'N'
10895              ,p_compute_dates_flag  => 'Y'
10896              ,p_enrt_cvg_strt_dt    => l_rec_enrt_cvg_strt_dt
10897              ,p_enrt_cvg_strt_dt_cd => l_dummy_enrt_cvg_strt_dt_cd
10898              ,p_enrt_cvg_strt_dt_rl => l_dummy_enrt_cvg_strt_dt_rl
10899              ,p_rt_strt_dt          => l_dummy_rt_strt_dt
10900              ,p_rt_strt_dt_cd       => l_dummy_rt_strt_dt_cd
10901              ,p_rt_strt_dt_rl       => l_dummy_rt_strt_dt_rl
10902              ,p_enrt_cvg_end_dt     => l_dummy_enrt_cvg_end_dt
10903              ,p_enrt_cvg_end_dt_cd  => l_dummy_enrt_cvg_end_dt_cd
10904              ,p_enrt_cvg_end_dt_rl  => l_dummy_enrt_cvg_end_dt_rl
10905              ,p_rt_end_dt           => l_dummy_rt_end_dt
10906              ,p_rt_end_dt_cd        => l_dummy_rt_end_dt_cd
10907              ,p_rt_end_dt_rl        => l_dummy_rt_end_dt_rl
10908              ,p_effective_date      => p_effective_date
10909              ,p_lf_evt_ocrd_dt      => nvl(l_rec.lf_evt_ocrd_dt, p_effective_date)
10910              );
10911            hr_utility.set_location('l_rec_enrt_cvg_strt_dt = ' || l_rec_enrt_cvg_strt_dt, 4444);
10912            hr_utility.set_location('l_dummy_rt_strt_dt = ' || l_dummy_rt_strt_dt, 4444);
10913            hr_utility.set_location('l_dummy_rt_strt_dt_cd = ' || l_dummy_rt_strt_dt_cd, 4444);
10914            hr_utility.set_location('l_dummy_rt_strt_dt_rl = ' || l_dummy_rt_strt_dt_rl, 4444);
10915            hr_utility.set_location('l_dummy_enrt_cvg_end_dt = ' || l_dummy_enrt_cvg_end_dt, 4444);
10916            hr_utility.set_location('l_dummy_enrt_cvg_end_dt_cd = ' || l_dummy_enrt_cvg_end_dt_cd, 4444);
10917            hr_utility.set_location('l_dummy_enrt_cvg_end_dt_rl = ' || l_dummy_enrt_cvg_end_dt_rl, 4444);
10918            hr_utility.set_location('l_dummy_rt_end_dt = ' || l_dummy_rt_end_dt, 4444);
10919            hr_utility.set_location('l_dummy_rt_end_dt_cd = ' || l_dummy_rt_end_dt_cd, 4444);
10920            hr_utility.set_location('l_dummy_rt_end_dt_rl = ' || l_dummy_rt_end_dt_rl, 4444);
10921            --
10922            -- If previous cvg start date and current date is different then
10923            -- clear the caches.
10924            --
10925            if nvl(l_fonm_cvg_strt_dt, hr_api.g_sot) <>
10926               l_rec_enrt_cvg_strt_dt
10927            then
10928              --
10929              hr_utility.set_location('clearing cache bnmngle '||l_fonm_cvg_strt_dt || '  / ' || l_rec_enrt_cvg_strt_dt  ,10);
10930              ben_use_cvg_rt_date.fonm_clear_down_cache;
10931              --
10932            end if;
10933            --
10934            ben_manage_life_events.g_fonm_cvg_strt_dt := l_rec_enrt_cvg_strt_dt ;
10935            l_fonm_cvg_strt_dt := l_rec_enrt_cvg_strt_dt ;
10936            --
10937            hr_utility.set_location(' g_fonm_cvg_strt_dt '||g_fonm_cvg_strt_dt,110);
10938            --
10939       end if;
10940         --
10941       -- EOF  FONM
10942       if g_debug then
10943         hr_utility.set_location (l_package||' FND Mess  ',80);
10944         hr_utility.set_location ('p_derivable_factors '||p_derivable_factors,80);
10945       end if;
10946       l_comp_rec:=l_d_comp_rec;
10947       l_oiplip_rec:=l_d_oiplip_rec;
10948        --
10949       if p_derivable_factors <> 'NONE' then
10950         --
10951         if g_debug then
10952           hr_utility.set_location (l_package||' fnd_message_call ',30);
10953         end if;
10954         fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
10955         fnd_message.set_token('PROC','ben_derive_part_and_rate_facts');
10956         if g_debug then
10957           hr_utility.set_location (l_package||' done fnd_message_call ',30);
10958           hr_utility.set_location (l_package||' DRAF ',15);
10959         end if;
10960         ben_derive_part_and_rate_facts.derive_rates_and_factors
10961           (p_comp_obj_tree_row         => l_comp_obj_tree_row
10962           --
10963           ,p_per_row                   => l_per_row
10964           ,p_empasg_row                => l_empasg_row
10965           ,p_benasg_row                => l_benasg_row
10966           ,p_pil_row                   => l_pil_row
10967           --
10968           -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
10969           ,p_mode                      => l_mode
10970           --
10971           ,p_person_id                 => p_person_id
10972           ,p_business_group_id         => p_business_group_id
10973           ,p_pgm_id                    => l_pgm_id
10974           ,p_pl_id                     => l_pl_id
10975           ,p_oipl_id                   => l_oipl_id
10976           ,p_plip_id                   => l_plip_id
10977           ,p_ptip_id                   => l_ptip_id
10978           ,p_ptnl_ler_trtmt_cd         => l_rec.ptnl_ler_trtmt_cd
10979           ,p_derivable_factors         => p_derivable_factors
10980           ,p_comp_rec                  => l_comp_rec
10981           ,p_oiplip_rec                => l_oiplip_rec
10982         --  ,p_effective_date            => p_effective_date
10983           ,p_effective_date           => least(p_effective_date, nvl(l_rec.lf_evt_ocrd_dt,p_effective_date))
10984           ,p_lf_evt_ocrd_dt            => nvl(l_rec.lf_evt_ocrd_dt,p_effective_date)
10985           );
10986         if g_debug then
10987           hr_utility.set_location (l_package||' Done DRAF ',15);
10988         end if;
10989         --
10990       else
10991         --
10992         -- Derive factor direct from the previous eligibility records.
10993         --
10994         if g_debug then
10995           hr_utility.set_location (l_package||' Ass Der facts  ',50);
10996         end if;
10997         --
10998         ben_derive_part_and_rate_facts.cache_data_structures
10999           (p_comp_obj_tree_row => l_comp_obj_tree_row
11000           --
11001           ,p_empasg_row        => l_empasg_row
11002           ,p_benasg_row        => l_benasg_row
11003           ,p_pil_row           => l_pil_row
11004           --
11005           ,p_business_group_id => p_business_group_id
11006           ,p_person_id         => p_person_id
11007           ,p_pgm_id            => l_pgm_id
11008           ,p_pl_id             => l_pl_id
11009           ,p_oipl_id           => l_oipl_id
11010           ,p_plip_id           => l_plip_id
11011           ,p_ptip_id           => l_ptip_id
11012           ,p_comp_rec          => l_comp_rec
11013           ,p_oiplip_rec        => l_oiplip_rec
11014           ,p_effective_date    => p_effective_date);
11015         --
11016       end if;
11017       --
11018       -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
11019       if l_mode not in ('R','T') then
11020         --
11021         fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
11022         fnd_message.set_token('PROC','ben_determine_eligibility');
11023         if g_debug then
11024           hr_utility.set_location (l_package||' Dn FND Mess  ',80);
11025         end if;
11026         --
11027         -- Initialise the dependent eligibility related globals.
11028         -- They should be initialised for every comp object.
11029         -- All these globals are used in bendepen.pkb.
11030         --
11031         ben_determine_dpnt_eligibility.g_egd_table.delete;
11032         ben_determine_dpnt_eligibility.g_egd_table :=
11033                                  ben_determine_dpnt_eligibility.g_egd_table_temp;
11034         --
11035         if g_debug then
11036           hr_utility.set_location (l_package||' BENDETEL  ',80);
11037         end if;
11038         --
11039         ben_determine_eligibility.determine_elig_prfls
11040           (p_comp_obj_tree_row         => l_comp_obj_tree_row
11041           ,p_par_elig_state            => l_par_elig_state
11042           --
11043           ,p_per_row                   => l_per_row
11044           ,p_empasg_row                => l_empasg_row
11045           ,p_benasg_row                => l_benasg_row
11046           ,p_appasg_row                => l_appasg_row
11047           ,p_empasgast_row             => l_empasgast_row
11048           ,p_benasgast_row             => l_benasgast_row
11049           ,p_pil_row                   => l_pil_row
11050           --
11051           ,p_person_id                 => p_person_id
11052           ,p_business_group_id         => p_business_group_id
11053           ,p_effective_date            => p_effective_date
11054           ,p_lf_evt_ocrd_dt            => l_rec.lf_evt_ocrd_dt
11055           ,p_pl_id                     => l_pl_id
11056           ,p_pgm_id                    => l_pgm_id
11057           ,p_oipl_id                   => l_oipl_id
11058           ,p_plip_id                   => l_plip_id
11059           ,p_ptip_id                   => l_ptip_id
11060           ,p_ler_id                    => p_ler_id
11061           ,p_comp_rec                  => l_comp_rec
11062           ,p_oiplip_rec                => l_oiplip_rec
11063           --
11064           ,p_eligible                  => l_eligible
11065           ,p_not_eligible              => l_not_eligible
11066           --
11067           ,p_newly_elig                => l_newly_elig
11068           ,p_newly_inelig              => l_newly_inelig
11069           ,p_first_elig                => l_first_elig
11070           ,p_first_inelig              => l_first_inelig
11071           ,p_still_elig                => l_still_elig
11072           ,p_still_inelig              => l_still_inelig
11073           );
11074         if g_debug then
11075           hr_utility.set_location (l_package||' Done BENDETEL  ',85);
11076         end if;
11077         --
11078         -- Bug 5232223
11079         --
11080         if l_not_eligible and l_mode = 'W'
11081            and ben_manage_cwb_life_events.g_cache_group_plan_rec.trk_inelig_per_flag = 'N'
11082            and l_oipl_id is null and l_pl_id is not null
11083            and fnd_global.conc_request_id > 0
11084         then
11085           --
11086           --  No need to write the data.
11087           --
11088           raise g_cwb_trk_ineligible;
11089           --
11090         end if;
11091         --
11092         -- Set comp object parent eligibility flags
11093         --
11094         if l_eligible then
11095           --
11096           ben_comp_obj_filter.set_parent_elig_flags
11097             (p_comp_obj_tree_row => l_comp_obj_tree_row
11098             ,p_eligible          => TRUE
11099             ,p_treeele_num       => l_treeele_num
11100             --
11101             ,p_par_elig_state    => l_par_elig_state
11102             );
11103           --
11104           if g_debug then
11105             hr_utility.set_location('p_pgm_id'||l_comp_obj_tree(l_treeele_num).par_pgm_id,1234);
11106             hr_utility.set_location('p_pl_id'||l_comp_obj_tree(l_treeele_num).par_pl_id,1234);
11107             hr_utility.set_location('p_plip_id'||l_comp_obj_tree(l_treeele_num).par_plip_id,1234);
11108             hr_utility.set_location('p_ptip_id'||l_comp_obj_tree(l_treeele_num).par_ptip_id,1234);
11109             hr_utility.set_location('p_oipl_id'||l_oipl_id,1234);
11110           end if;
11111           --
11112           -- Don't run enrolment_requirements for levels other than plan and oipl.
11113           -- Don't run it if the ler_id is null.
11114           --
11115           if (l_pl_id is not null
11116               or l_oipl_id is not null)
11117             and p_ler_id is not null
11118             and not nvl(l_first_inelig, FALSE)
11119             and not nvl(l_still_inelig, FALSE)
11120             --
11121             -- CWB Changes.ABSENCES, GRADE/STEP avoid dependent eligibility
11122             -- added irec
11123             and l_mode not in ( 'W', 'M', 'G','I','D')
11124           then
11125             --
11126             --
11127             -- Task 131 : Eligible dependent rows are already created.
11128             -- Now update them with electable choice id.
11129             --
11130             if g_debug then
11131               hr_utility.set_location (l_package||' St BENDEPEN  ',85);
11132             end if;
11133             ben_determine_dpnt_eligibility.main
11134               (p_pgm_id            => l_comp_obj_tree(l_treeele_num).par_pgm_id
11135               ,p_pl_id             => l_comp_obj_tree(l_treeele_num).par_pl_id
11136               ,p_plip_id           => l_comp_obj_tree(l_treeele_num).par_plip_id
11137               ,p_ptip_id           => l_comp_obj_tree(l_treeele_num).par_ptip_id
11138               ,p_oipl_id           => l_oipl_id
11139               ,p_pl_typ_id         => null
11140               ,p_business_group_id => p_business_group_id
11141               ,p_person_id         => p_person_id
11142               ,p_effective_date    => p_effective_date
11143               ,p_per_in_ler_id     => l_rec.per_in_ler_id
11144               ,p_elig_per_id       => l_comp_obj_tree_row.elig_per_id
11145               ,p_elig_per_opt_id   => l_comp_obj_tree_row.elig_per_opt_id
11146               ,p_lf_evt_ocrd_dt    => l_rec.lf_evt_ocrd_dt
11147               );
11148             if g_debug then
11149               hr_utility.set_location (l_package||' Dn BENDEPEN  ',85);
11150             end if;
11151              --
11152           end if;
11153           --
11154         elsif l_not_eligible then
11155           --
11156           ben_comp_obj_filter.set_parent_elig_flags
11157             (p_comp_obj_tree_row => l_comp_obj_tree_row
11158             ,p_eligible          => FALSE
11159             ,p_treeele_num       => l_treeele_num
11160             --
11161             ,p_par_elig_state    => l_par_elig_state
11162             );
11163           --
11164         end if;
11165         --
11166         if l_first_inelig then
11167           --
11168           --l_elig_state_change := true;
11169           l_comp_obj_tree(l_treeele_num).elig_tran_state := 'FT_INELIG';
11170           --
11171         elsif l_still_inelig then
11172           --
11173           l_comp_obj_tree(l_treeele_num).elig_tran_state := 'ST_INELIG';
11174           --
11175         elsif l_newly_inelig then
11176           --
11177           l_elig_state_change := true;
11178           l_comp_obj_tree(l_treeele_num).elig_tran_state := 'NW_INELIG';
11179           --
11180         elsif l_first_elig then
11181           --
11182           l_comp_obj_tree(l_treeele_num).elig_tran_state := 'FT_ELIG';
11183           --
11184         elsif l_still_elig then
11185           --
11186           l_comp_obj_tree(l_treeele_num).elig_tran_state := 'ST_ELIG';
11187           --
11188         elsif l_newly_elig then
11189           --
11190           l_elig_state_change := true;
11191           l_comp_obj_tree(l_treeele_num).elig_tran_state := 'NW_ELIG';
11192           --
11193         end if;
11194         --
11195       end if;
11196     end if;
11197     --
11198     -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
11199     if l_mode not in ('R','T') then
11200       --
11201       -- Check for first in-eligible or still in-eligible
11202       --
11203       l_continue_loop := false;
11204       --
11205       if l_comp_obj_tree(l_treeele_num).elig_tran_state = 'FT_INELIG'
11206         or l_comp_obj_tree(l_treeele_num).elig_tran_state = 'ST_INELIG'
11207         or l_comp_obj_tree(l_treeele_num).elig_tran_state = 'NW_INELIG'
11208         or not l_evaluate_eligibility
11209       then
11210         --
11211         if g_debug then
11212           hr_utility.set_location (' First In-Eligible  BENMNGLE ',85);
11213         end if;
11214         --
11215         l_continue_loop := false;
11216         --
11217       else
11218         --
11219         if g_debug then
11220           hr_utility.set_location (' Non-filter eligibility  BENMNGLE ',85);
11221         end if;
11222         --
11223         l_continue_loop := true;
11224         --
11225       end if;
11226       --
11227       -- Defer Deenrollment cases
11228         -- If defer_deenrol_flag is set at len/enp, then
11229         -- populate pl/sql table l_defer_deenrl_tbl with pgm_id/pl_id
11230         -- if any comp.obj has newly_inligible status, update newly_inelig_exists to true.
11231         -- if any epe was created in pgm/pnip, update chc_exists to true
11232         --
11233         if (g_defer_deenrol_flag = 'Y') then
11234             -- Add pgm/pln to cache
11235             if (g_debug) then
11236                 hr_utility.set_location('DEFER Starts', 1039);
11237                 hr_utility.set_location('DEFER l_defer_count ' || l_defer_count , 1039);
11238                 hr_utility.set_location('DEFER par_pl_id ' || l_comp_obj_tree(l_treeele_num).par_pl_id , 1039);
11239                 hr_utility.set_location('DEFER pl_id ' || l_comp_obj_tree(l_treeele_num).pl_id , 1039);
11240                 hr_utility.set_location('DEFER par_pgm_id ' || l_comp_obj_tree(l_treeele_num).par_pgm_id , 1039);
11241                 hr_utility.set_location('DEFER pgm_id ' || l_comp_obj_tree(l_treeele_num).pgm_id , 1039);
11242             end if;
11243             --
11244             if (l_defer_deenrl_tbl.COUNT > 0) then
11245                 if (l_comp_obj_tree(l_treeele_num).pl_nip <> 'Y') then
11246                     --
11247                     if (g_debug) then
11248                         hr_utility.set_location('DEFER tab_pgm_id '
11249                                 || l_defer_deenrl_tbl(l_defer_count).pgm_id , 1039);
11250                     end if;
11251                     --
11252                     if (NVL(l_defer_deenrl_tbl(l_defer_count).pgm_id,-1) <>
11253                            NVL(l_comp_obj_tree(l_treeele_num).par_pgm_id,
11254                                     l_comp_obj_tree(l_treeele_num).pgm_id) ) then
11255                         --
11256                         l_defer_count := l_defer_count +1;
11257                         l_defer_deenrl_tbl(l_defer_count).pgm_id :=
11258                                          l_comp_obj_tree(l_treeele_num).par_pgm_id;
11259                         l_defer_deenrl_tbl(l_defer_count).pl_id := null;
11260                         l_defer_deenrl_tbl(l_defer_count).chc_exists := false;
11261                         l_defer_deenrl_tbl(l_defer_count).newly_inelig_exists := false;
11262                         --
11263                     end if;
11264                  else
11265                     --
11266                     if (g_debug) then
11267                         hr_utility.set_location('DEFER tab_pl_id '
11268                             || l_defer_deenrl_tbl(l_defer_count).pl_id , 1039);
11269                     end if;
11270                     --
11271                     if (NVL(l_defer_deenrl_tbl(l_defer_count).pl_id,-1) <>
11272                             NVL(l_comp_obj_tree(l_treeele_num).par_pl_id,
11273                                    l_comp_obj_tree(l_treeele_num).pl_id)) then
11274                         --
11275                         l_defer_count := l_defer_count +1;
11276                         l_defer_deenrl_tbl(l_defer_count).pl_id :=
11277                                          l_comp_obj_tree(l_treeele_num).par_pl_id;
11278                         l_defer_deenrl_tbl(l_defer_count).pgm_id := null;
11279                         l_defer_deenrl_tbl(l_defer_count).chc_exists := false;
11280                         l_defer_deenrl_tbl(l_defer_count).newly_inelig_exists := false;
11281                         --
11282                     end if;
11283                 end if;
11284             else
11285                 hr_utility.set_location('DEFER First PGM/PLN '  , 1039);
11286                 --
11287                 l_defer_count := l_defer_count +1;
11288                 if (l_comp_obj_tree(l_treeele_num).pl_nip <> 'Y') then
11289                     l_defer_deenrl_tbl(l_defer_count).pgm_id :=
11290                                         NVL(l_comp_obj_tree(l_treeele_num).par_pgm_id,
11291                                                l_comp_obj_tree(l_treeele_num).pgm_id);
11292                     l_defer_deenrl_tbl(l_defer_count).pl_id := null;
11293                 else
11294                     l_defer_deenrl_tbl(l_defer_count).pgm_id := null;
11295                     l_defer_deenrl_tbl(l_defer_count).pl_id :=
11296                                         NVL(l_comp_obj_tree(l_treeele_num).par_pl_id,
11297                                                l_comp_obj_tree(l_treeele_num).pl_id);
11298                 end if;
11299                 l_defer_deenrl_tbl(l_defer_count).chc_exists := false;
11300                 l_defer_deenrl_tbl(l_defer_count).newly_inelig_exists := false;
11301             end if;
11302             --
11303             -- If Newly Inelig set Flag
11304             if (l_comp_obj_tree(l_treeele_num).elig_tran_state = 'NW_INELIG' ) then
11305                 l_defer_deenrl_tbl(l_defer_count).newly_inelig_exists := true;
11306                 hr_utility.set_location('DEFER NEWLY INELIG ' , 1039);
11307             end if;
11308             --
11309         end if;
11310         -- Defer enrollments ends;
11311 
11312       --
11313       -- Don't run enrolment_requirements for levels other than plan and oipl.
11314       -- Don't run it if the ler_id is null.
11315       --
11316       if g_debug then
11317         hr_utility.set_location ('Before enrollment call. pl id :'||l_pl_id,10);
11318         hr_utility.set_location ('Before enrollment call. oipl id :'||l_oipl_id,10);
11319         hr_utility.set_location ('Before enrollment call. ler id :'||p_ler_id,10);
11320         hr_utility.set_location ('Before enrollment call. l_mode :'||l_mode,10);
11321       end if;
11322       if (l_pl_id is not null
11323           or l_oipl_id is not null)
11324         and p_ler_id is not null
11325         and ((l_continue_loop and l_mode <> 'W') or (l_mode = 'W')) --Changed for Bug #2214961
11326       then
11327         --
11328         -- Initialise the current EPE row for the comp object loop
11329         --
11330         ben_epe_cache.init_context_cobj_pileperow;
11331         --
11332         if g_debug then
11333           hr_utility.set_location (l_package||' FND Bf BENDENRR ',85);
11334         end if;
11335         fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
11336         fnd_message.set_token('PROC','ben_enrolment_requirements');
11337         --
11338         -- p_mode changed to l_mode in following line by Gopal Venkataraman
11339         -- 3/27/01 bug 1636071
11340         --
11341         -- CWB Change
11342         --
11343         if l_mode in ('C', 'W') then
11344            l_asnd_lf_evt_dt := l_rec.lf_evt_ocrd_dt;
11345            if l_mode = 'W' and l_cwb_pl_id is null then
11346               l_cwb_pl_id := l_pl_id;
11347            end if;
11348         end if;
11349         --
11350         if g_debug then
11351           hr_utility.set_location (l_package||' FND Af BENDENRR  ',100);
11352         end if;
11353         ben_enrolment_requirements.enrolment_requirements
11354           (p_comp_obj_tree_row         => l_comp_obj_tree_row
11355           -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
11356           ,p_run_mode                  => l_mode
11357           ,p_business_group_id         => p_business_group_id
11358           ,p_effective_date            => p_effective_date
11359           ,p_lf_evt_ocrd_dt            => l_rec.lf_evt_ocrd_dt
11360           ,p_ler_id                    => p_ler_id
11361           ,p_per_in_ler_id             => l_pil_row.per_in_ler_id
11362           ,p_person_id                 => p_person_id
11363           ,p_pl_id                     => l_pl_id
11364           ,p_pgm_id                    => l_comp_obj_tree(l_treeele_num).par_pgm_id
11365           ,p_oipl_id                   => l_oipl_id
11366           ,p_elig_per_elctbl_chc_id    => l_elig_per_elctbl_chc_id
11367           ,p_electable_flag            => l_electable_flag
11368           -- PB : 5422 :
11369           --  ,p_popl_enrt_typ_cycl_id => p_popl_enrt_typ_cycl_id
11370           ,p_asnd_lf_evt_dt            => l_asnd_lf_evt_dt
11371           );
11372         if g_debug then
11373           hr_utility.set_location (l_package||' Dn BENDENRR  ',100);
11374         end if;
11375         --
11376         -- If choice has not been created don't do dependent stuff
11377         --
11378         if l_elig_per_elctbl_chc_id is not null then
11379         --
11380             -- Defer Deenrollment
11381             if (g_defer_deenrol_flag = 'Y') then
11382                 hr_utility.set_location('DEFER CHOICE EXISTS ' , 1039);
11383                 l_defer_deenrl_tbl(l_defer_count).chc_exists := true;
11384             end if;
11385           --
11386           -- Set electable choice context row details
11387           --
11388           ben_epe_cache.g_currcobjepe_row.ler_id := p_ler_id;
11389           ben_epe_cache.g_currcobjepe_row.opt_id := l_comp_obj_tree(l_treeele_num).par_opt_id;
11390           --
11391           fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
11392           fnd_message.set_token('PROC','ben_determine_dpnt_eligibility');
11393           --
11394           if g_debug then
11395             hr_utility.set_location (l_package||' BDDE_PUEWEID ',110);
11396           end if;
11397           --
11398           -- Task 131 : Eligible dependent rows are already created.
11399           -- Now update them with electable choice id.
11400           --
11401           --
11402           -- CWB Changes. ABSENCES : Dependents are not processed
11403           --
11404           if l_mode not in ('W', 'M','I','D') then
11405              --
11406              ben_determine_dpnt_eligibility.p_upd_egd_with_epe_id
11407                (p_elig_per_elctbl_chc_id => l_elig_per_elctbl_chc_id
11408                ,p_person_id              => p_person_id
11409                ,p_effective_date         => p_effective_date
11410                ,p_lf_evt_ocrd_dt         => l_rec.lf_evt_ocrd_dt
11411                );
11412              --
11413           end if;
11414           --
11415           fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
11416           fnd_message.set_token('PROC','BEN_DETERMINE_CHC_CTFN');
11417           --
11418           if g_debug then
11419             hr_utility.set_location ('BDCC_MN '||l_package,10);
11420           end if;
11421 	  if l_mode <> 'D' then
11422           ben_determine_chc_ctfn.main
11423             (p_effective_date         => p_effective_date,
11424              p_person_id              => p_person_id,
11425              p_elig_per_elctbl_chc_id => l_elig_per_elctbl_chc_id,
11426              p_mode                   => l_mode);
11427 	  end if;
11428           if g_debug then
11429             hr_utility.set_location ('Dn BDCC_MN '||l_package,10);
11430           end if;
11431           --
11432           fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
11433           fnd_message.set_token('PROC','ben_determine_coverage');
11434           --
11435           if g_debug then
11436             hr_utility.set_location (l_package||' ben_determine_coverage.main  ',110);
11437           end if;
11438           --
11439 	  if l_mode <> 'D' then
11440           ben_determine_coverage.main
11441             (p_elig_per_elctbl_chc_id => l_elig_per_elctbl_chc_id
11442             ,p_effective_date         => p_effective_date
11443             ,p_lf_evt_ocrd_dt         => l_rec.lf_evt_ocrd_dt
11444             ,p_perform_rounding_flg   => true
11445             --
11446             ,p_enb_valrow             => l_enb_valrow
11447             );
11448         end if;
11449           if g_debug then
11450             hr_utility.set_location (l_package||' Dn DetCov_MN ',110);
11451           end if;
11452           --
11453           -- Initialise the current EPE row for the comp object loop
11454           --
11455           ben_epe_cache.init_context_cobj_pileperow;
11456           --
11457         end if;
11458         --
11459       end if; -- pl_id is not null
11460       --
11461     end if;
11462     --
11463     if l_mode = 'R' then
11464        --
11465        update_elig_per_rows
11466          (p_comp_obj_tree_row          => l_comp_obj_tree_row
11467           ,p_comp_rec                  => l_comp_rec
11468           ,p_person_id                 => p_person_id
11469           ,p_treeele_num               => l_treeele_num
11470           ,p_par_elig_state            => l_par_elig_state
11471           ,p_business_group_id         => p_business_group_id
11472           ,p_effective_date            => p_effective_date
11473           ,p_lf_evt_ocrd_dt            => l_rec.lf_evt_ocrd_dt
11474           ,p_per_in_ler_id             => l_pil_row.per_in_ler_id
11475           ,p_continue_loop             => l_continue_loop);
11476        --
11477        if (l_pl_id is not null
11478           or l_oipl_id is not null)
11479           and p_ler_id is not null
11480           and l_continue_loop
11481          then
11482          --
11483          -- Initialise the current EPE row for the comp object loop
11484          --
11485          ben_epe_cache.init_context_cobj_pileperow;
11486          --
11487          if g_debug then
11488            hr_utility.set_location (l_package||' FND Bf BENDENRR ',86);
11489            hr_utility.set_location ('l_oipl_id' ||l_oipl_id,87);
11490          end if;
11491          fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
11492          fnd_message.set_token('PROC','ben_enrolment_requirements');
11493          --
11494          ben_enrolment_requirements.enrolment_requirements
11495           (p_comp_obj_tree_row         => l_comp_obj_tree_row
11496           ,p_run_mode                  => 'U'  --l_mode
11497           ,p_business_group_id         => p_business_group_id
11498           ,p_effective_date            => p_effective_date
11499           ,p_lf_evt_ocrd_dt            => l_rec.lf_evt_ocrd_dt
11500           ,p_ler_id                    => p_ler_id
11501           ,p_per_in_ler_id             => l_pil_row.per_in_ler_id
11502           ,p_person_id                 => p_person_id
11503           ,p_pl_id                     => l_pl_id
11504           ,p_pgm_id                    => l_comp_obj_tree(l_treeele_num).par_pgm_id
11505           ,p_oipl_id                   => l_oipl_id
11506           ,p_elig_per_elctbl_chc_id    => l_elig_per_elctbl_chc_id
11507           ,p_electable_flag            => l_electable_flag
11508           ,p_asnd_lf_evt_dt            => l_asnd_lf_evt_dt
11509           );
11510          if g_debug then
11511            hr_utility.set_location (l_package||' Dn BENDENRR  ',200);
11512          end if;
11513         --
11514         -- If choice has not been created don't do dependent stuff
11515         --
11516         if l_elig_per_elctbl_chc_id is not null then
11517           --
11518           -- Set electable choice context row details
11519           --
11520           ben_epe_cache.g_currcobjepe_row.ler_id := p_ler_id;
11521           ben_epe_cache.g_currcobjepe_row.opt_id := l_comp_obj_tree(l_treeele_num).par_opt_id;
11522           --bug#3420298
11523           ben_determine_dpnt_eligibility.g_egd_table.delete;
11524           ben_determine_dpnt_eligibility.g_egd_table :=
11525                                ben_determine_dpnt_eligibility.g_egd_table_temp;
11526           --
11527           ben_determine_dpnt_eligibility.main
11528             (p_pgm_id            => l_comp_obj_tree(l_treeele_num).par_pgm_id
11529             ,p_pl_id             => l_comp_obj_tree(l_treeele_num).par_pl_id
11530             ,p_plip_id           => l_comp_obj_tree(l_treeele_num).par_plip_id
11531             ,p_ptip_id           => l_comp_obj_tree(l_treeele_num).par_ptip_id
11532             ,p_oipl_id           => l_oipl_id
11533             ,p_pl_typ_id         => null
11534             ,p_business_group_id => p_business_group_id
11535             ,p_person_id         => p_person_id
11536             ,p_effective_date    => p_effective_date
11537             ,p_per_in_ler_id     => l_pil_row.per_in_ler_id
11538             ,p_elig_per_id       => l_comp_obj_tree_row.elig_per_id
11539             ,p_elig_per_opt_id   => l_comp_obj_tree_row.elig_per_opt_id
11540             ,p_lf_evt_ocrd_dt    => l_rec.lf_evt_ocrd_dt
11541             );
11542           --
11543 
11544           ben_determine_dpnt_eligibility.p_upd_egd_with_epe_id
11545                (p_elig_per_elctbl_chc_id => l_elig_per_elctbl_chc_id
11546                ,p_person_id              => p_person_id
11547                ,p_effective_date         => p_effective_date
11548                ,p_lf_evt_ocrd_dt         => l_rec.lf_evt_ocrd_dt
11549                );
11550           -- end of bug#3420298
11551           ben_determine_coverage.main
11552             (p_elig_per_elctbl_chc_id => l_elig_per_elctbl_chc_id
11553             ,p_effective_date         => p_effective_date
11554             ,p_lf_evt_ocrd_dt         => l_rec.lf_evt_ocrd_dt
11555             ,p_perform_rounding_flg   => true
11556             ,p_enb_valrow             => l_enb_valrow
11557             );
11558           --
11559           -- Initialise the current EPE row for the comp object loop
11560           --
11561           ben_epe_cache.init_context_cobj_pileperow;
11562           --
11563         end if;
11564         --
11565       end if;
11566       --
11567    end if;
11568    -- end of mode 'R'
11569     benutils.write(p_text => g_output_string);
11570     --
11571     -- Check if the last row of the comp object list has been reached
11572     -- otherwise navigate to the next row
11573     --
11574     if l_treeele_num = l_maxtreeele_num then
11575       --
11576       l_treeloop := FALSE;
11577       exit;
11578       --
11579     else
11580       --
11581       l_treeele_num := l_treeele_num+1;
11582       --
11583     end if;
11584     --
11585     if g_debug then
11586       hr_utility.set_location (l_package||' End Proc loop ',20);
11587     end if;
11588     --
11589   end loop;
11590   --
11591   if g_debug then
11592     hr_utility.set_location (l_package||' OUT  Proc loop ',25);
11593   end if;
11594     --
11595     -- Defer Deenrollment
11596     -- 1. Loop thru the l_defer_deenrl_tbl
11597     -- 2. If any choice was created in pgm/pnip and
11598     --      if any pl/oipl was newly_ineligible and we deferred the de-enrollment
11599     --     then update corresponding PEL record with defer_deenrol_flag = Y
11600     -- 3. If no choice was created in pgm/pnip, then run newly_ineligible.main
11601     --      and de-enroll immediately.
11602     --
11603     if (l_defer_deenrl_tbl.COUNT > 0) then
11604         --
11605         for defer_indx in l_defer_deenrl_tbl.FIRST..l_defer_deenrl_tbl.LAST loop
11606             --
11607             hr_utility.set_location ('DEFER loop '|| defer_indx, 1039);
11608             --
11609             if l_defer_deenrl_tbl(defer_indx).chc_exists then
11610                 --
11611                 hr_utility.set_location ('DEFER chc_exists' ,9653);
11612                 --
11613                 if l_defer_deenrl_tbl(defer_indx).newly_inelig_exists then
11614                     --
11615                     l_defer_popl_id := null;
11616                     l_defer_popl_ovn := null;
11617                     hr_utility.set_location ('DEFER newly_inelig_exists' ,9653);
11618 
11619                     --
11620                     if (l_defer_deenrl_tbl(defer_indx).pgm_id is not null) then
11621                         --
11622                         hr_utility.set_location ('DEFER INSIDE PGM ' ,9653);
11623                         open c_pel_defer (l_defer_deenrl_tbl(defer_indx).pgm_id, l_rec.per_in_ler_id);
11624                         fetch c_pel_defer into l_pel_defer;
11625                         if c_pel_defer%FOUND then
11626                             --
11627                             l_defer_popl_id := l_pel_defer.pil_elctbl_chc_popl_id;
11628                             l_defer_popl_ovn := l_pel_defer.object_version_number;
11629                             --
11630                         end if;
11631                         close c_pel_defer;
11632                         hr_utility.set_location ('DEFER PGM' || l_pel_defer.pgm_id,9653);
11633                         --
11634                     elsif (l_defer_deenrl_tbl(defer_indx).pl_id is not null) then
11635                         --
11636                         hr_utility.set_location ('DEFER INSIDE PLN ' ,9653);
11637 
11638                         open c_pel_pnip_defer (l_defer_deenrl_tbl(defer_indx).pl_id, l_rec.per_in_ler_id);
11639                         fetch c_pel_pnip_defer into l_pel_pnip_defer;
11640                         if c_pel_pnip_defer%FOUND then
11641                             --
11642                             l_defer_popl_id := l_pel_pnip_defer.pil_elctbl_chc_popl_id;
11643                             l_defer_popl_ovn := l_pel_pnip_defer.object_version_number;
11644                             --
11645                         end if;
11646                         close c_pel_pnip_defer;
11647                         hr_utility.set_location ('DEFER PL' || l_pel_pnip_defer.pl_id,9653);
11648                         --
11649                     end if;
11650                     --
11651                     if l_defer_popl_id IS NOT NULL then
11652                         --
11653                         hr_utility.set_location ('DEFER UPDATED ' || l_defer_popl_id,9653);
11654                         hr_utility.set_location ('DEFER OVN ' || l_defer_popl_ovn,9653);
11655                         --
11656                         ben_pil_elctbl_chc_popl_api.update_pil_elctbl_chc_popl
11657                            (p_validate                    => FALSE,
11658                             p_pil_elctbl_chc_popl_id      => l_defer_popl_id,
11659                             p_object_version_number       => l_defer_popl_ovn,
11660                             p_effective_date              => p_effective_date,
11661                             p_defer_deenrol_flag          => 'Y'
11662                             );
11663                     end if;
11664                     --
11665                 end if;
11666             else
11667                 --
11668                 hr_utility.set_location ('DEFER NEWLYINELIG ' ,9653);
11669                 --
11670                 if l_defer_deenrl_tbl(defer_indx).newly_inelig_exists then
11671                     ben_newly_ineligible.main
11672                         (p_person_id              => p_person_id,
11673                         p_pgm_id                 => l_defer_deenrl_tbl(defer_indx).pgm_id,
11674                         p_pl_id                  => l_defer_deenrl_tbl(defer_indx).pl_id,
11675                         p_oipl_id                => NULL,
11676                         p_business_group_id      => p_business_group_id,
11677                         p_ler_id                 => p_ler_id,
11678                         p_effective_date         => p_effective_date
11679                         );
11680                 end if;
11681                  --
11682             end if;
11683             --
11684             hr_utility.set_location ('DEFER End loop ' ,9653);
11685             --
11686         end loop;
11687         --
11688     end if;
11689     -- Defer Deenrollment ends
11690 
11691   if l_mode = 'W' then
11692 
11693      update_cwb_epe
11694     (p_per_in_ler_id => l_rec.per_in_ler_id
11695     ,p_effective_date => p_effective_date);
11696 
11697   end if;
11698 
11699   --
11700   -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
11701   if l_mode <> 'T' then
11702     --
11703     -- Clear eligibility caches
11704     --
11705     ben_pep_cache.clear_down_cache;
11706     ben_epe_cache.clear_down_cache;
11707     --
11708     -- PB : 5422 :
11709     -- l_strt_dt is not being used by the process to which it is passed.
11710     -- May be necessary to remove this code.
11711     --
11712     /*
11713     open c_strt_dt;
11714       --
11715       fetch c_strt_dt into l_strt_dt;
11716       --
11717     close c_strt_dt;
11718     */
11719     --
11720     --  Start 5055119
11721      IF l_mode IN ('U', 'R', 'S', 'P','D')
11722 
11723       THEN
11724       hr_utility.set_location('SSARKAR p_person_id '|| p_person_id,9909);
11725       hr_utility.set_location('SSARKAR l_pil_row.per_in_ler_id '|| l_pil_row.per_in_ler_id,9909);
11726       hr_utility.set_location('SSARKAR p_effective_date '|| p_effective_date,9909);
11727 
11728          ben_manage_unres_life_events.end_date_elig_per_rows (p_person_id           => p_person_id,
11729                                                               p_per_in_ler_id       => l_pil_row.per_in_ler_id,
11730                                                               p_effective_date      => p_effective_date
11731                                                              );
11732       END IF;
11733     -- End 5055119
11734     -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
11735     if l_mode not in ('A','P','S','T') then
11736       -- Bug 4640014, deleting EPEs before update_defaults
11737       if l_mode in ('U','R') then
11738         --
11739         ben_manage_unres_life_events.clear_epe_cache ;
11740         --
11741       end if;
11742       --
11743       -- If defaults have changed due to deenrollments then
11744       -- check to see if choice defaults have changed.
11745       --
11746       if ben_enrolment_requirements.g_any_choice_created then
11747       if l_mode <> 'D' then
11748         ben_enrolment_requirements.update_defaults
11749           (p_run_mode               => l_mode
11750           ,p_business_group_id      => p_business_group_id
11751           ,p_effective_date         => p_effective_date
11752           ,p_lf_evt_ocrd_dt         => l_rec.lf_evt_ocrd_dt
11753           ,p_ler_id                 => p_ler_id
11754           ,p_person_id              => p_person_id
11755           ,p_per_in_ler_id          => l_pil_row.per_in_ler_id
11756           );
11757 	  end if;
11758       end if;
11759       --BUG 4463267 Need to update the flag
11760       if l_mode <> 'D' then
11761       --
11762       BEN_DETERMINE_CHC_CTFN.update_susp_if_ctfn_flag
11763         (p_effective_date         => p_effective_date,
11764          p_lf_evt_ocrd_dt         => l_rec.lf_evt_ocrd_dt,
11765          p_person_id              => p_person_id,
11766          p_per_in_ler_id          => l_pil_row.per_in_ler_id
11767         );
11768       -- 1895846 call
11769       -- to delete the egd records create for the suspended pen or in pending wkflow epe records
11770       --
11771       fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
11772       fnd_message.set_token('PROC','delete_in_pndg_elig_dpnt');
11773       --
11774       delete_in_pndg_elig_dpnt( l_rec.per_in_ler_id,p_effective_date ) ;
11775       --
11776      end if;
11777       fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
11778       fnd_message.set_token('PROC','ben_determine_elct_chc_flx_imp');
11779       if g_debug then
11780         hr_utility.set_location('lf evt ocrd dt'||l_rec.lf_evt_ocrd_dt,11);
11781       end if;
11782       --
11783       -- CWB Changes. ABSENCES, GRADE/STEP  : no need to run flex logic
11784       -- added irec
11785       if l_mode not in ( 'W', 'M', 'G','I','D') then
11786          --
11787          ben_determine_elct_chc_flx_imp.main
11788            (p_person_id         => p_person_id,
11789             p_business_group_id => p_business_group_id,
11790             p_per_in_ler_id     => l_rec.per_in_ler_id,
11791             p_lf_evt_ocrd_dt    => l_rec.lf_evt_ocrd_dt,
11792             p_enrt_perd_strt_dt => l_strt_dt,
11793             p_effective_date    => p_effective_date,
11794             p_mode              => l_mode);
11795          --
11796       end if;
11797       --
11798       -- Assumption is that ben_determine_actual_premium.main and
11799       -- ben_determine_rates.main do not perform any updates to
11800       -- electable choices. Be aware of this assumption when modifying
11801       -- ben_determine_actual_premium and ben_determine_rates.
11802       --
11803       -- Clear electability caches
11804       --
11805       ben_epe_cache.clear_down_cache;
11806       --
11807       -- Clear Elig per Cache as ben_enrolment_requirements.update_defaults
11808       -- build the cache for previous eligibility.
11809       -- And in the benrates we need the current elig records.
11810       --
11811       ben_pep_cache.clear_down_cache;
11812       --
11813       -- Clear distribute rates function caches
11814       --
11815       ben_distribute_rates.clear_down_cache;
11816       --
11817       -- Do premium stuff if choices are created.
11818       --
11819       -- CWB Changes. ABSENCES ,GRADE/STEP : No need to run premium logic
11820       --
11821       if ben_enrolment_requirements.g_any_choice_created
11822          and l_mode not in( 'W', 'M', 'G','I','D')   -- added irec
11823       then
11824         if g_debug then
11825           hr_utility.set_location (l_package||'.ben_determine_actual_premium ',10);
11826         end if;
11827         fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
11828         fnd_message.set_token('PROC','ben_determine_actual_premium');
11829         --
11830         ben_determine_actual_premium.main
11831           (p_person_id         => p_person_id,
11832            p_effective_date    => p_effective_date,
11833         -- added per_in_ler_id for unrestricted enhancement
11834            p_per_in_ler_id     => l_rec.per_in_ler_id,
11835            p_lf_evt_ocrd_dt    => l_rec.lf_evt_ocrd_dt,
11836            p_mode              => l_mode
11837         );
11838         --
11839       end if;
11840       --
11841       -- Do rates stuff
11842       --
11843       if g_debug then
11844         hr_utility.set_location ('FND mess '||l_package,10);
11845       end if;
11846       fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
11847       fnd_message.set_token('PROC','ben_determine_rates');
11848       --
11849       if g_debug then
11850         hr_utility.set_location ('ben_determine_rates '||l_package,10);
11851       end if;
11852       ben_determine_rates.main
11853         (p_effective_date => p_effective_date,
11854          p_lf_evt_ocrd_dt => l_rec.lf_evt_ocrd_dt,
11855          p_person_id      => p_person_id,
11856          p_mode           => l_mode,
11857          -- added per_in_ler_id for unrestricted enhancement
11858          p_per_in_ler_id  => l_rec.per_in_ler_id);
11859       --
11860       -- Bug 3968065 : in CWB mode summ the rates defined at oipls and
11861       -- write into ben_cwb_person_rates.
11862       --
11863       if l_mode = 'W' then
11864          --
11865          BEN_MANAGE_CWB_LIFE_EVENTS.sum_oipl_rates_and_upd_pl_rate (
11866             p_pl_id          => l_cwb_pl_id,
11867             p_group_pl_id    => ben_manage_cwb_life_events.g_cache_group_plan_rec.group_pl_id,
11868             p_lf_evt_ocrd_dt => ben_manage_cwb_life_events.g_cache_group_plan_rec.group_lf_evt_ocrd_dt,
11869             p_person_id      => p_person_id,
11870             p_assignment_id  => null
11871             );
11872          --
11873       end if;
11874       --
11875       /* GSP Rate Sync */
11876       if l_mode = 'G'
11877       then
11878         --
11879         if p_lf_evt_oper_cd = 'SYNC'
11880         then
11881           --
11882           hr_utility.set_location('Calling GSP Rate Sync Post Process in PQH', 45);
11883           pqh_gsp_post_process.update_rate_sync_salary
11884             (p_per_in_ler_id   => l_pil_row.per_in_ler_id
11885             ,p_effective_date  => p_effective_date
11886             );
11887           --
11888         else /* p_lf_evt_oper_cd = 'PROG' */
11889           --
11890           gsp_proc_dflt_auten(l_rec.per_in_ler_id, p_effective_date) ;
11891           --
11892         end if;
11893       end if ;
11894       --
11895       if l_mode in ('U', 'R') then
11896         --
11897         update_enrt_rt (p_per_in_ler_id => l_rec.per_in_ler_id);
11898         ben_manage_unres_life_events.clear_cache;
11899         --
11900       end if;
11901       if g_debug then
11902         hr_utility.set_location ('ben_determine_rate_chg '||l_package,10);
11903       end if;
11904       fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
11905       fnd_message.set_token('PROC','ben_determine_rate_chg');
11906       --
11907       -- Turn off distribute rates function caching because cached information
11908       -- is updated in later RCOs. Any further RCOs will hit the DB rather the
11909       -- function cache.
11910       --
11911       ben_distribute_rates.set_no_cache_context;
11912       --
11913       --
11914       -- CWB Changes. ABSENCES, GRADE/STEP
11915       -- added irec
11916       if l_mode not in ('W', 'M', 'G','I','D')  then
11917          --
11918          ben_determine_rate_chg.main
11919            (p_effective_date    => p_effective_date,
11920             p_lf_evt_ocrd_dt    => l_rec.lf_evt_ocrd_dt,
11921             p_business_group_id => p_business_group_id,
11922             p_person_id         => p_person_id,
11923              -- added per_in_ler_id for unrestricted enhancement
11924             p_per_in_ler_id     => l_rec.per_in_ler_id,
11925             p_mode              => l_mode);
11926          --
11927       end if;
11928       --
11929     end if;
11930     --
11931     fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
11932     fnd_message.set_token('PROC','reset_elctbl_chc_inpng_flag');
11933     --
11934     -- Reset the in_pndg_wkflow_flag to 'N' for the suspended enrollment cases
11935     --
11936     reset_elctbl_chc_inpng_flag(l_rec.per_in_ler_id,p_effective_date );
11937     -- reopen already ended results if elecatble choice with flag Y
11938     -- Fidelity GM issue
11939     --
11940     -- bug 5534550 - call reopen only for L or C modes
11941     if  l_mode in ('L', 'C')  then
11942     --
11943     ben_reopen_ended_results.reopen_routine(
11944           p_per_in_ler_id     => l_rec.per_in_ler_id,
11945           p_business_group_id => p_business_group_id,
11946           p_lf_evt_ocrd_dt    => l_rec.lf_evt_ocrd_dt,
11947           p_person_id         => p_person_id,
11948           p_effective_date    => l_rec.lf_evt_ocrd_dt);
11949     --
11950     end if;
11951     --
11952     fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
11953     fnd_message.set_token('PROC','ben_automatic_enrollments');
11954     --
11955     -- Do the automatic enrollments
11956     --
11957     -- CWB Changes.
11958     --
11959     if g_debug then
11960       hr_utility.set_location ('BENAUTEN '||l_package,10);
11961     end if;
11962     if ben_enrolment_requirements.g_auto_choice_created
11963        and l_mode not in ('W','D')
11964     then
11965       ben_automatic_enrollments.main(
11966          p_person_id         => p_person_id,
11967          p_ler_id            => p_ler_id,
11968          p_business_group_id => p_business_group_id,
11969          -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
11970          p_mode              => l_mode,
11971          p_effective_date    => l_rec.lf_evt_ocrd_dt
11972       );
11973     end if;
11974     if g_debug then
11975       hr_utility.set_location ('Dn BENAUTEN '||l_package,10);
11976     end if;
11977     --
11978     --
11979     -- Check for reqired communications
11980     --
11981     fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
11982     fnd_message.set_token('PROC','ben_generate_communications');
11983     --
11984     if g_debug then
11985       hr_utility.set_location ('Comms '||l_package,10);
11986     end if;
11987     --
11988     -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
11989     -- CWB Changes.
11990     --
11991     if l_mode in ('C', 'W') then
11992        l_asnd_lf_evt_dt := l_rec.lf_evt_ocrd_dt;
11993     end if;
11994     --
11995     -- call communications for all modes other than GSP
11996     -- bypass communications call for irec
11997     if l_mode not in ( 'G','I','D') then
11998     --
11999     ben_generate_communications.main
12000       (p_person_id             => p_person_id,
12001        p_ler_id                => p_ler_id,
12002        p_per_in_ler_id         => l_rec.per_in_ler_id,
12003        p_prtt_enrt_actn_id     => null,
12004        p_bnf_person_id         => null,
12005        p_dpnt_person_id        => null,
12006        -- PB : 5422 :
12007        -- As enrt_perd_id is not passed, so pass the null value.
12008        --
12009        -- p_enrt_perd_id          => p_popl_enrt_typ_cycl_id,
12010        p_asnd_lf_evt_dt        => l_asnd_lf_evt_dt,
12011        p_actn_typ_id           => null,
12012        p_enrt_mthd_cd          => null,
12013        p_business_group_id     => p_business_group_id,
12014        -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
12015        p_proc_cd1              => benutils.iftrue(l_mode = 'U'
12016                                                  ,null
12017                                                  ,'MLEPECP'),
12018        -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
12019        p_proc_cd2              => benutils.iftrue(l_mode = 'U'
12020                                                  ,null
12021                                                  ,'MLEAUTOENRT'),
12022        -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
12023        p_proc_cd3              => benutils.iftrue(l_mode = 'U'
12024                                                  ,null
12025                                                  ,'MLERTCHG'),
12026        p_proc_cd4              => 'MLEENDENRT',
12027        -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
12028        p_proc_cd5              => benutils.iftrue(l_mode = 'U'
12029                                                  ,null
12030                                                  ,'MLENOIMP'),
12031        p_proc_cd6              => 'MLEELIG',
12032        p_proc_cd7              => 'MLEINELIG',
12033        p_proc_cd8              => 'HPAPRTTDE',
12034        p_proc_cd9              => 'HPADPNTLC',
12035        p_proc_cd10             => null,
12036        p_effective_date        => p_effective_date,
12037        p_lf_evt_ocrd_dt        => l_rec.lf_evt_ocrd_dt
12038     );
12039    --
12040    end if;
12041    --
12042     if g_debug then
12043       hr_utility.set_location ('Dn Comms '||l_package,10);
12044     end if;
12045     --
12046     --  Create benefit assignment for dependents if they were
12047     --  found ineligible.
12048     --
12049     -- CWB Changes. ABSENCES, GRADE/STEP
12050     -- added irec
12051     if ben_determine_dpnt_eligibility.g_dpnt_ineligible
12052        and (l_mode not in ( 'W', 'M', 'G','I','D'))
12053     then
12054       if g_debug then
12055         hr_utility.set_location ('Dpnt ineligible '||l_package,10);
12056       end if;
12057       for l_dpnt_rec in c_get_inelig_dpnt_info(l_rec.per_in_ler_id) loop
12058         if g_debug then
12059           hr_utility.set_location ('Dpnt person_id '||l_dpnt_rec.dpnt_person_id,10);
12060           hr_utility.set_location ('cvg_thru_dt '||l_dpnt_rec.cvg_thru_dt,10);
12061         end if;
12062         ben_assignment_internal.copy_empasg_to_benasg
12063           (p_person_id             => p_person_id
12064           ,p_dpnt_person_id        => l_dpnt_rec.dpnt_person_id
12065           ,p_effective_date        => l_dpnt_rec.cvg_thru_dt + 1
12066           ,p_assignment_id         => l_assignment_id
12067           ,p_object_version_number => l_object_version_number
12068           ,p_perhasmultptus        => l_perhasmultptus
12069           );
12070       end loop;
12071     end if;
12072     --
12073     -- COBRA:  If person is no longer enrolled in the COBRA program and has no
12074     -- opportunity to elect then, end COBRA eligibility.
12075     --
12076     if ben_cobra_requirements.g_cobra_enrollment_change then
12077       ben_cobra_requirements.end_prtt_cobra_eligibility
12078         (p_per_in_ler_id     => l_rec.per_in_ler_id
12079         ,p_person_id         => p_person_id
12080         ,p_business_group_id => p_business_group_id
12081         ,p_effective_date    => p_effective_date
12082         );
12083     end if;
12084     -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
12085     if l_mode in ('L','U') then
12086       --
12087       --  If electable choices are created, check if we need to create
12088       --  cobra qualified beneficiaries.
12089       --
12090       if (p_ler_id is not null and
12091           (l_rec.qualg_evt_flag = 'Y' or
12092            l_rec.typ_cd = 'ENDDSBLTY' or
12093            -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
12094            l_mode = 'U')) then
12095         ben_cobra_requirements.update_cobra_elig_info
12096         (p_person_id         => p_person_id
12097         ,p_per_in_ler_id     => l_rec.per_in_ler_id
12098         ,p_lf_evt_ocrd_dt    => l_rec.lf_evt_ocrd_dt
12099         ,p_effective_date    => p_effective_date
12100         ,p_business_group_id => p_business_group_id
12101         );
12102       end if;
12103     end if;
12104     --
12105   -- if condition added for unrestricted enhancement
12106     -- p_mode changed to l_mode in following line by Gopal Venkataraman 3/27/01 bug 1636071
12107    --
12108    -- iRec (OI) : Even if the person is not eligible to any plan, still the Life Event status in PIL
12109    -- should be Started (and should not be changed to Processed). Hence mode iRecruitment (I) not
12110    -- added in the following "if statement".
12111 
12112    -- ABSENCES : Close the life event.
12113    --
12114    if l_mode = 'L' or l_mode = 'C' or l_mode = 'M' then
12115     if (p_ler_id is not null and
12116       not ben_enrolment_requirements.g_electable_choice_created and
12117       not ben_enrolment_requirements.g_auto_choice_created ) or (l_mode = 'M')
12118     then
12119       --
12120       -- Set life event to processed, only update the per_in_ler_stat_cd
12121       --
12122       if l_mode = 'M' then
12123          --
12124          benutils.get_active_life_event
12125          (p_person_id         => p_person_id,
12126           p_business_group_id => p_business_group_id,
12127           p_effective_date    => p_effective_date,
12128           p_lf_event_mode   => 'M',
12129           p_rec               => l_rec);
12130          --
12131       else
12132          --
12133          benutils.get_active_life_event
12134         (p_person_id         => p_person_id,
12135          p_business_group_id => p_business_group_id,
12136          p_effective_date    => p_effective_date,
12137          p_rec               => l_rec);
12138          --
12139       end if;
12140       --
12141       if l_rec.lf_evt_ocrd_dt is not null then
12142         --
12143         if g_debug then
12144           hr_utility.set_location('processing event',10);
12145         end if;
12146         ben_person_life_event_api.update_person_life_event
12147             (p_per_in_ler_id           => l_rec.per_in_ler_id,
12148              p_per_in_ler_stat_cd      => 'PROCD',
12149              p_object_version_number   => l_rec.object_version_number,
12150              -- p_effective_date          => p_effective_date,
12151              -- Bug#1543462
12152              p_effective_date          => least(p_effective_date,trunc(sysdate)),
12153              p_procd_dt                => l_procd_dt,
12154              p_strtd_dt                => l_strtd_dt,
12155              p_voidd_dt                => l_voidd_dt);
12156         --
12157         --  Bug 6404338.  Min Max enhancement.
12158         l_chk_min_max := fnd_profile.value('BEN_CHK_MIN_MAX');
12159         --
12160         if g_debug then
12161           hr_utility.set_location ('l_chk_min_max '||l_chk_min_max,10);
12162         end if;
12163         --
12164         if l_chk_min_max = 'Y' then
12165           --
12166           --  Check if coverage was terminated in this event.
12167           --
12168           if ben_prtt_enrt_result_api.g_enrollment_change = true then
12169             if g_debug then
12170               hr_utility.set_location ('Enrollment ended ',10);
12171             end if;
12172             for l_rslt_rec in c_get_ended_enrt_rslts(l_rec.per_in_ler_id) loop
12173               --
12174               --  Check if person is still eligible for the plan type in
12175               --  program.
12176               --
12177               l_ptip_elig_flag := 'N';
12178               open c_get_ptip_elig(l_rslt_rec.ptip_id, l_rec.per_in_ler_id);
12179               fetch c_get_ptip_elig into l_ptip_elig_flag;
12180               close c_get_ptip_elig;
12181               --
12182               if g_debug then
12183                 hr_utility.set_location (' Elig flag '||l_ptip_elig_flag,10);
12184               end if;
12185              --
12186               if l_ptip_elig_flag = 'Y' then
12187                 --
12188                 --  Get the ptip min and max.
12189                 --
12190                 open c_get_ptip(l_rslt_rec.ptip_id);
12191                 fetch c_get_ptip into l_ptip_rec;
12192                 if c_get_ptip%notfound then
12193                   close c_get_ptip;
12194                   fnd_message.set_name('BEN','BEN_91462_PTIP_MISSING');
12195                   fnd_message.set_token('ID', to_char(l_rslt_rec.ptip_id) );
12196                   fnd_message.raise_error;
12197                 end if;
12198                 --
12199                 close c_get_ptip;
12200                 --
12201                 if (l_ptip_rec.no_mn_pl_typ_overid_flag = 'Y' or
12202                     (l_ptip_rec.no_mn_pl_typ_overid_flag = 'N' and
12203                     l_ptip_rec.MN_ENRD_RQD_OVRID_NUM is null)) then
12204                   l_mn_enrd_rqd_ovrid_num := l_ptip_rec.MN_ENRL_RQD_NUM;
12205                 else
12206                   l_mn_enrd_rqd_ovrid_num := l_ptip_rec.MN_ENRD_RQD_OVRID_NUM;
12207                 end if;
12208                 --
12209                 --  Get the total enrolled in the ptip
12210                 --
12211                 open c_get_ptip_tot_enrd(l_rslt_rec.ptip_id);
12212                 fetch c_get_ptip_tot_enrd into l_count;
12213                 close c_get_ptip_tot_enrd;
12214                 hr_utility.set_location (' MN_ENRD_RQD_OVRID_NUM '||l_ptip_rec.MN_ENRD_RQD_OVRID_NUM,10);
12215                 if (l_count < l_MN_ENRD_RQD_OVRID_NUM ) then
12216                   hr_utility.set_location (' error '||l_count,10);
12217                   fnd_message.set_name('BEN','BEN_91588_PL_ENRD_LT_MN_RQD');
12218                   fnd_message.set_token('MN_ENRL', to_char(l_MN_ENRD_RQD_OVRID_NUM));
12219                   fnd_message.set_token('PL_TYP_NAME', l_ptip_rec.name);
12220                   fnd_message.raise_error;
12221                 end if;
12222               end if;
12223             end loop;
12224           end if;
12225         end if; -- l_chk_min_max = 'Y'
12226          --
12227          -- End min max enhancement.
12228          --
12229       end if;
12230       --
12231       -- Update status of life event to opened and closed as this is what has
12232       -- happened unless the life event was replaced.
12233       --
12234       benutils.update_life_event_cache(p_open_and_closed => 'Y');
12235       --
12236     end if;
12237     --
12238     if (p_ler_id is not null and
12239         ben_enrolment_requirements.g_electable_choice_created ) or
12240         l_mode = 'M' -- ABSENCES : close life event in absences mode.
12241     then
12242        open c_pil_elctbl_chc_popl(l_rec.per_in_ler_id);
12243        loop
12244           fetch c_pil_elctbl_chc_popl into l_pil_elctbl_chc_popl;
12245           if c_pil_elctbl_chc_popl%notfound then
12246             close c_pil_elctbl_chc_popl;
12247             exit;
12248           else
12249             ben_pil_elctbl_chc_popl_api.update_pil_elctbl_chc_popl
12250               (p_pil_elctbl_chc_popl_id     => l_pil_elctbl_chc_popl.pil_elctbl_chc_popl_id
12251               ,p_pil_elctbl_popl_stat_cd    => 'PROCD'
12252               ,p_business_group_id          => p_business_group_id
12253               ,p_object_version_number      => l_pil_elctbl_chc_popl.object_version_number
12254               ,p_effective_date             => p_effective_date);
12255           end if;
12256        end loop;
12257     end if;
12258 
12259   end if;
12260   --
12261   -- Do not run restore if electable choices are not created.
12262   --
12263   -- CWB Changes. -- ABSENCES : no restore logic.
12264   -- added irec
12265   if g_bckdt_per_in_ler_id is not null and
12266      ben_enrolment_requirements.g_electable_choice_created and
12267      l_mode not in ('W', 'M','I','D')
12268   then
12269     --
12270     ben_lf_evt_clps_restore.p_lf_evt_clps_restore
12271       (p_person_id              => p_person_id
12272       ,p_business_group_id      => p_business_group_id
12273       ,p_effective_date         => p_effective_date
12274       ,p_per_in_ler_id          => l_rec.per_in_ler_id
12275       ,p_bckdt_per_in_ler_id    => g_bckdt_per_in_ler_id);
12276     --
12277   end if;
12278   --
12279   -- Bug 4258498 : moved carry forward after reinstate, so that reinstate
12280   -- try to restore back what was previous state first.
12281   --Bug 4064635. New Procedure call to carry forward suspended enrollments
12282   --
12283   if l_mode not in ('W', 'M', 'G','I','D')  then
12284       --
12285       if g_debug then
12286         hr_utility.set_location ('carry_farward_results '||l_package,10);
12287       end if;
12288       --
12289       ben_carry_forward_items.carry_farward_results(
12290                 p_person_id           => p_person_id
12291                ,p_per_in_ler_id       => l_rec.per_in_ler_id
12292                ,p_ler_id              => p_ler_id
12293                ,p_business_group_id   => p_business_group_id
12294                ,p_mode                => l_mode
12295                ,p_effective_date      => p_effective_date
12296                 );
12297       --
12298       if g_debug then
12299         hr_utility.set_location ('Dn carry_farward_results '||l_package,10);
12300       end if;
12301       --
12302   end if;
12303   --
12304   end if;
12305   --
12306   -- GRADE/STEP - Bypass this for absences and grade modes V.Puttigampala 11/08/00
12307   -- added irec
12308   if l_mode not in  ('W', 'M', 'G','I','D') then
12309     --
12310      --- # 2899702 if the setup is autoenrollment Person Type usages are not create
12311      --- because the multi edit is not called , Person Type usages created in multiedit
12312      --- this is called for autoenrollment to created person type usaged
12313      if ben_enrolment_requirements.g_auto_choice_created
12314        and l_mode <> 'W' then
12315 
12316          ben_prtt_enrt_result_api.g_enrollment_change := true ;
12317     end if ;
12318 
12319     ben_prtt_enrt_result_api.update_person_type_usages
12320     (p_person_id        => p_person_id
12321     ,p_business_group_id    => p_business_group_id
12322     ,p_effective_date   => p_effective_date
12323     );
12324     --
12325   end if;
12326   -- bug 4621751 irec2 updating per_all_assignments_f with g_irec_old_ass_rec
12327   if l_mode = 'I' then
12328    begin
12329         -- dbms_output.put_line('***  G_IREC_OLD_ASS_REC.assignment_id '||G_IREC_OLD_ASS_REC.assignment_id);
12330     ben_irc_util.post_irec_process_update
12331     (p_person_id          => p_person_id,
12332      p_business_group_id  => p_business_group_id,
12333      p_assignment_id      => G_IREC_OLD_ASS_REC.assignment_id,
12334      p_effective_date     => p_effective_date);
12335 
12336     l_old_data_migrator_mode := hr_general.g_data_migrator_mode ;
12337     hr_general.g_data_migrator_mode := 'Y' ;
12338 
12339      -- update starts
12340      update per_all_assignments_F
12341      set
12342   BUSINESS_GROUP_ID              =   G_IREC_OLD_ASS_REC.BUSINESS_GROUP_ID
12343  ,RECRUITER_ID                   =   G_IREC_OLD_ASS_REC.RECRUITER_ID
12344  ,GRADE_ID                       =   G_IREC_OLD_ASS_REC.GRADE_ID
12345  ,POSITION_ID                    =   G_IREC_OLD_ASS_REC.POSITION_ID
12346  ,JOB_ID                         =   G_IREC_OLD_ASS_REC.JOB_ID
12347  ,ASSIGNMENT_STATUS_TYPE_ID      =   G_IREC_OLD_ASS_REC.ASSIGNMENT_STATUS_TYPE_ID
12348  ,PAYROLL_ID                     =   G_IREC_OLD_ASS_REC.PAYROLL_ID
12349  ,LOCATION_ID                    =   G_IREC_OLD_ASS_REC.LOCATION_ID
12350  ,PERSON_REFERRED_BY_ID          =   G_IREC_OLD_ASS_REC.PERSON_REFERRED_BY_ID
12351  ,SUPERVISOR_ID                  =   G_IREC_OLD_ASS_REC.SUPERVISOR_ID
12352  ,SPECIAL_CEILING_STEP_ID        =   G_IREC_OLD_ASS_REC.SPECIAL_CEILING_STEP_ID
12353  ,PERSON_ID                      =   G_IREC_OLD_ASS_REC.PERSON_ID
12354  ,RECRUITMENT_ACTIVITY_ID        =   G_IREC_OLD_ASS_REC.RECRUITMENT_ACTIVITY_ID
12355  ,SOURCE_ORGANIZATION_ID         =   G_IREC_OLD_ASS_REC.SOURCE_ORGANIZATION_ID
12356  ,ORGANIZATION_ID                =   G_IREC_OLD_ASS_REC.ORGANIZATION_ID
12357  ,PEOPLE_GROUP_ID                =   G_IREC_OLD_ASS_REC.PEOPLE_GROUP_ID
12358  ,SOFT_CODING_KEYFLEX_ID         =   G_IREC_OLD_ASS_REC.SOFT_CODING_KEYFLEX_ID
12359  ,VACANCY_ID                     =   G_IREC_OLD_ASS_REC.VACANCY_ID
12360  ,PAY_BASIS_ID                   =   G_IREC_OLD_ASS_REC.PAY_BASIS_ID
12361  ,ASSIGNMENT_SEQUENCE		 =   G_IREC_OLD_ASS_REC.ASSIGNMENT_SEQUENCE
12362  ,APPLICATION_ID                 =   G_IREC_OLD_ASS_REC.APPLICATION_ID
12363  ,ASSIGNMENT_NUMBER              =   G_IREC_OLD_ASS_REC.ASSIGNMENT_NUMBER
12364  ,CHANGE_REASON                  =   G_IREC_OLD_ASS_REC.CHANGE_REASON
12365  ,COMMENT_ID                     =   G_IREC_OLD_ASS_REC.COMMENT_ID
12366  ,DATE_PROBATION_END             =   G_IREC_OLD_ASS_REC.DATE_PROBATION_END
12367  ,DEFAULT_CODE_COMB_ID           =   G_IREC_OLD_ASS_REC.DEFAULT_CODE_COMB_ID
12368  ,EMPLOYMENT_CATEGORY            =   G_IREC_OLD_ASS_REC.EMPLOYMENT_CATEGORY
12369  ,FREQUENCY                      =   G_IREC_OLD_ASS_REC.FREQUENCY
12370  ,INTERNAL_ADDRESS_LINE          =   G_IREC_OLD_ASS_REC.INTERNAL_ADDRESS_LINE
12371  ,MANAGER_FLAG                   =   G_IREC_OLD_ASS_REC.MANAGER_FLAG
12372  ,NORMAL_HOURS                   =   G_IREC_OLD_ASS_REC.NORMAL_HOURS
12373  ,PERF_REVIEW_PERIOD             =   G_IREC_OLD_ASS_REC.PERF_REVIEW_PERIOD
12374  ,PERF_REVIEW_PERIOD_FREQUENCY   =   G_IREC_OLD_ASS_REC.PERF_REVIEW_PERIOD_FREQUENCY
12375  ,PERIOD_OF_SERVICE_ID           =   G_IREC_OLD_ASS_REC.PERIOD_OF_SERVICE_ID
12376  ,PROBATION_PERIOD               =   G_IREC_OLD_ASS_REC.PROBATION_PERIOD
12377  ,PROBATION_UNIT                 =   G_IREC_OLD_ASS_REC.PROBATION_UNIT
12378  ,SAL_REVIEW_PERIOD              =   G_IREC_OLD_ASS_REC.SAL_REVIEW_PERIOD
12379  ,SAL_REVIEW_PERIOD_FREQUENCY    =   G_IREC_OLD_ASS_REC.SAL_REVIEW_PERIOD_FREQUENCY
12380  ,SET_OF_BOOKS_ID                =   G_IREC_OLD_ASS_REC.SET_OF_BOOKS_ID
12381  ,SOURCE_TYPE                    =   G_IREC_OLD_ASS_REC.SOURCE_TYPE
12382  ,TIME_NORMAL_FINISH             =   G_IREC_OLD_ASS_REC.TIME_NORMAL_FINISH
12383  ,TIME_NORMAL_START              =   G_IREC_OLD_ASS_REC.TIME_NORMAL_START
12384  ,REQUEST_ID                     =   G_IREC_OLD_ASS_REC.REQUEST_ID
12385  ,PROGRAM_APPLICATION_ID         =   G_IREC_OLD_ASS_REC.PROGRAM_APPLICATION_ID
12386  ,PROGRAM_ID                     =   G_IREC_OLD_ASS_REC.PROGRAM_ID
12387  ,PROGRAM_UPDATE_DATE            =   G_IREC_OLD_ASS_REC.PROGRAM_UPDATE_DATE
12388  ,ASS_ATTRIBUTE_CATEGORY         =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE_CATEGORY
12389  ,ASS_ATTRIBUTE1                 =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE1
12390  ,ASS_ATTRIBUTE2                 =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE2
12391  ,ASS_ATTRIBUTE3                 =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE3
12392  ,ASS_ATTRIBUTE4                 =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE4
12393  ,ASS_ATTRIBUTE5                 =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE5
12394  ,ASS_ATTRIBUTE6                 =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE6
12395  ,ASS_ATTRIBUTE7                 =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE7
12396  ,ASS_ATTRIBUTE8                 =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE8
12397  ,ASS_ATTRIBUTE9                 =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE9
12398  ,ASS_ATTRIBUTE10                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE10
12399  ,ASS_ATTRIBUTE11                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE11
12400  ,ASS_ATTRIBUTE12                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE12
12401  ,ASS_ATTRIBUTE13                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE13
12402  ,ASS_ATTRIBUTE14                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE14
12403  ,ASS_ATTRIBUTE15                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE15
12404  ,ASS_ATTRIBUTE16                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE16
12405  ,ASS_ATTRIBUTE17                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE17
12406  ,ASS_ATTRIBUTE18                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE18
12407  ,ASS_ATTRIBUTE19                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE19
12408  ,ASS_ATTRIBUTE20                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE20
12409  ,ASS_ATTRIBUTE21                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE21
12410  ,ASS_ATTRIBUTE22                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE22
12411  ,ASS_ATTRIBUTE23                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE23
12412  ,ASS_ATTRIBUTE24                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE24
12413  ,ASS_ATTRIBUTE25                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE25
12414  ,ASS_ATTRIBUTE26                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE26
12415  ,ASS_ATTRIBUTE27                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE27
12416  ,ASS_ATTRIBUTE28                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE28
12417  ,ASS_ATTRIBUTE29                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE29
12418  ,ASS_ATTRIBUTE30                =   G_IREC_OLD_ASS_REC.ASS_ATTRIBUTE30
12419  ,TITLE                          =   G_IREC_OLD_ASS_REC.TITLE
12420  ,OBJECT_VERSION_NUMBER          =   G_IREC_OLD_ASS_REC.OBJECT_VERSION_NUMBER
12421  ,BARGAINING_UNIT_CODE           =   G_IREC_OLD_ASS_REC.BARGAINING_UNIT_CODE
12422  ,LABOUR_UNION_MEMBER_FLAG       =   G_IREC_OLD_ASS_REC.LABOUR_UNION_MEMBER_FLAG
12423  ,HOURLY_SALARIED_CODE           =   G_IREC_OLD_ASS_REC.HOURLY_SALARIED_CODE
12424  ,CONTRACT_ID                    =   G_IREC_OLD_ASS_REC.CONTRACT_ID
12425  ,COLLECTIVE_AGREEMENT_ID        =   G_IREC_OLD_ASS_REC.COLLECTIVE_AGREEMENT_ID
12426  ,CAGR_ID_FLEX_NUM               =   G_IREC_OLD_ASS_REC.CAGR_ID_FLEX_NUM
12427  ,CAGR_GRADE_DEF_ID              =   G_IREC_OLD_ASS_REC.CAGR_GRADE_DEF_ID
12428  ,ESTABLISHMENT_ID               =   G_IREC_OLD_ASS_REC.ESTABLISHMENT_ID
12429  ,NOTICE_PERIOD                  =   G_IREC_OLD_ASS_REC.NOTICE_PERIOD
12430  ,NOTICE_PERIOD_UOM              =   G_IREC_OLD_ASS_REC.NOTICE_PERIOD_UOM
12431  ,EMPLOYEE_CATEGORY              =   G_IREC_OLD_ASS_REC.EMPLOYEE_CATEGORY
12432  ,WORK_AT_HOME                   =   G_IREC_OLD_ASS_REC.WORK_AT_HOME
12433  ,JOB_POST_SOURCE_NAME           =   G_IREC_OLD_ASS_REC.JOB_POST_SOURCE_NAME
12434  ,POSTING_CONTENT_ID             =   G_IREC_OLD_ASS_REC.POSTING_CONTENT_ID
12435  ,PERIOD_OF_PLACEMENT_DATE_START =   G_IREC_OLD_ASS_REC.PERIOD_OF_PLACEMENT_DATE_START
12436  ,VENDOR_ID                      =   G_IREC_OLD_ASS_REC.VENDOR_ID
12437  ,VENDOR_EMPLOYEE_NUMBER         =   G_IREC_OLD_ASS_REC.VENDOR_EMPLOYEE_NUMBER
12438  ,VENDOR_ASSIGNMENT_NUMBER       =   G_IREC_OLD_ASS_REC.VENDOR_ASSIGNMENT_NUMBER
12439  ,ASSIGNMENT_CATEGORY            =   G_IREC_OLD_ASS_REC.ASSIGNMENT_CATEGORY
12440  ,PROJECT_TITLE                  =   G_IREC_OLD_ASS_REC.PROJECT_TITLE
12441  ,APPLICANT_RANK                 =   G_IREC_OLD_ASS_REC.APPLICANT_RANK
12442  ,GRADE_LADDER_PGM_ID            =   G_IREC_OLD_ASS_REC.GRADE_LADDER_PGM_ID
12443  ,SUPERVISOR_ASSIGNMENT_ID       =   G_IREC_OLD_ASS_REC.SUPERVISOR_ASSIGNMENT_ID
12444  ,VENDOR_SITE_ID                 =   G_IREC_OLD_ASS_REC.VENDOR_SITE_ID
12445  ,PO_HEADER_ID                   =   G_IREC_OLD_ASS_REC.PO_HEADER_ID
12446  ,PO_LINE_ID                     =   G_IREC_OLD_ASS_REC.PO_LINE_ID
12447  ,PROJECTED_ASSIGNMENT_END       =   G_IREC_OLD_ASS_REC.PROJECTED_ASSIGNMENT_END
12448 
12449  where assignment_id = G_IREC_OLD_ASS_REC.assignment_id ;
12450  -- update ends
12451 hr_general.g_data_migrator_mode := l_old_data_migrator_mode ;
12452 
12453  exception
12454     when others then
12455       raise;
12456   end;
12457 end if; --end irec2
12458   --
12459   benutils.write(p_text => benutils.g_banner_asterix);
12460   --
12461   p_person_count := p_person_count +1;
12462   --
12463   g_action_rec.person_action_id := p_person_action_id;
12464   g_action_rec.action_status_cd := 'P';
12465   g_action_rec.ler_id := p_ler_id;
12466   g_action_rec.object_version_number := p_object_version_number;
12467   g_action_rec.effective_date := p_effective_date;
12468   --
12469   benutils.write(p_rec => g_action_rec);
12470   --
12471   if g_debug then
12472     hr_utility.set_location ('Leaving '||l_package,10);
12473   end if;
12474   --
12475 end process_comp_objects;
12476 --
12477 procedure process_life_events
12478   (p_person_id                in number default null,
12479    p_person_action_id         in number default null,
12480    p_object_version_number    in out nocopy number,
12481    p_business_group_id        in number,
12482    p_mode                     in varchar2,
12483    p_ler_id                   in number default null,
12484    p_person_selection_rule_id in number default null,
12485    p_comp_selection_rule_id   in number default null,
12486    -- PB : 5422 :
12487    --    p_popl_enrt_typ_cycl_id    in number default null,
12488    p_derivable_factors        in varchar2 default 'ASC',
12489    p_cbr_tmprl_evt_flag       in varchar2 default 'N',
12490    p_person_count             in out nocopy number,
12491    p_error_person_count       in out nocopy number,
12492    p_lf_evt_ocrd_dt           in date,
12493    p_effective_date           in date,
12494    p_validate                 in varchar2 default 'N',       /* Bug 5550359 */
12495    p_gsp_eval_elig_flag       in varchar2 default null,      /* GSP Rate Sync */
12496    p_lf_evt_oper_cd           in varchar2 default null       /* GSP Rate Sync */
12497    ) is
12498   --
12499   l_package           varchar2(80);
12500   l_ler_id            number := p_ler_id;
12501   l_rec               benutils.g_active_life_event;
12502   l_env               ben_env_object.g_global_env_rec_type;
12503   l_encoded_message   varchar2(2000);
12504   l_app_short_name    varchar2(2000);
12505   l_message_name      varchar2(2000);
12506   l_per_rec           per_all_people_f%rowtype;
12507   p_prtt_cache        varchar2(1) ;
12508   l_module            varchar2(30);
12509   --
12510 begin
12511   --
12512   g_debug := hr_utility.debug_enabled;
12513   if g_debug then
12514     l_package := g_package||'.process_life_events';
12515     hr_utility.set_location ('Entering '||l_package,10);
12516   end if;
12517   --
12518   -- Create savepoint for error handling purposes
12519   --
12520   savepoint process_life_event_savepoint;
12521   benutils.set_cache_record_position;
12522 
12523   -- iRec
12524   -- In iRecruitment mode, as multiple life events for a person could be processed for
12525   -- single person on a given day, clear down person cache. This change is necessary as
12526   -- same session could be used to process the person using different applicant assignments.
12527   if p_mode = 'I' then
12528     --
12529     ben_person_object.clear_down_cache;
12530     --
12531   end if;
12532   --
12533   -- iRec
12534 
12535   --
12536   if g_debug then
12537     hr_utility.set_location (l_package||' Bef evaluate_life_events ',13);
12538   end if;
12539   --
12540   -- PB : 5422 :
12541   -- Now if benmngle is run in Life event mode and the winner
12542   -- is open then change the mode of benmngle run for this
12543   -- person and proceed. Means the mode to be changed on the fly.
12544   -- To make above logic work store the mode in global. Which
12545   -- may change later.
12546   --
12547   ben_manage_life_events.g_modified_mode := p_mode;
12548   --
12549   /* GSP Rate Sync */
12550   p_prtt_cache := 'N'  ;
12551   -- begin 4496944
12552   begin
12553        person_header_new
12554             (p_person_id            => p_person_id,
12555              p_business_group_id    => p_business_group_id);
12556   exception
12557      when others then
12558              --
12559          if g_debug then
12560            hr_utility.set_location ('Not Logging Person Header information for person_id : '||p_person_id ||' p_business_group_id : '||p_business_group_id,12);
12561          end if;
12562 
12563   end;
12564   -- end 4496944
12565   if g_cache_person_prtn.last is not null  then
12566      p_prtt_cache := 'Y'  ;
12567   end if ;
12568 
12569   evaluate_life_events
12570     (p_person_id                => p_person_id,
12571      p_business_group_id        => p_business_group_id,
12572      p_mode                     => p_mode,
12573      p_ler_id                   => l_ler_id,
12574      -- PB : 5422 :
12575      -- p_popl_enrt_typ_cycl_id    => p_popl_enrt_typ_cycl_id,
12576      p_lf_evt_ocrd_dt           => p_lf_evt_ocrd_dt,
12577      p_effective_date           => p_effective_date,
12578      p_validate                 => p_validate,                /* Bug 5550359 */
12579      p_gsp_eval_elig_flag       => p_gsp_eval_elig_flag,      /* GSP Rate Sync */
12580      p_lf_evt_oper_cd           => p_lf_evt_oper_cd           /* GSP Rate Sync */
12581      );
12582 
12583   if g_debug then
12584     hr_utility.set_location (l_package||' Dn evaluate_life_events ',15);
12585   end if;
12586   --
12587   if p_mode not in ('A','P','S','T') then
12588     --
12589     if p_mode in ( 'R', 'U') then
12590       --
12591       benutils.get_active_life_event
12592       (p_person_id         => p_person_id,
12593        p_business_group_id => p_business_group_id,
12594        p_effective_date    => p_effective_date,
12595        p_lf_event_mode   => 'U',
12596        p_rec               => l_rec);
12597     else
12598       --
12599       --
12600       -- CWB Changes .
12601       --
12602       if p_mode = 'W' then
12603        --
12604        benutils.get_active_life_event
12605        (p_person_id         => p_person_id,
12606         p_business_group_id => p_business_group_id,
12607         p_effective_date    => p_effective_date,
12608         p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
12609         p_ler_id            => p_ler_id,
12610         p_rec               => l_rec);
12611        --
12612       elsif p_mode = 'G' then
12613        --
12614        benutils.get_active_life_event
12615        (p_person_id         => p_person_id,
12616         p_business_group_id => p_business_group_id,
12617         p_effective_date    => p_effective_date,
12618         p_lf_event_mode     => 'G',
12619         p_rec               => l_rec);
12620        --
12621       elsif p_mode = 'M' then
12622        --
12623        benutils.get_active_life_event
12624        (p_person_id         => p_person_id,
12625         p_business_group_id => p_business_group_id,
12626         p_effective_date    => p_effective_date,
12627         p_lf_event_mode     => 'M',
12628         p_rec               => l_rec);
12629        --
12630       else
12631        --
12632        benutils.get_active_life_event
12633        (p_person_id         => p_person_id,
12634         p_business_group_id => p_business_group_id,
12635         p_effective_date    => p_effective_date,
12636         p_rec               => l_rec);
12637        --
12638       end if;
12639       --
12640       if g_debug then
12641         hr_utility.set_location (l_package||' Dn get_active_life_event ',17);
12642       end if;
12643       --
12644    end if;
12645    --
12646   end if;
12647   --
12648   -- ABSE : 2652690 : For every absence life event recache the person data.
12649   --
12650   if nvl(ben_manage_life_events.g_modified_mode, p_mode) in ('G', 'M') then
12651      --
12652      ben_person_object.clear_down_cache;
12653      --
12654   end if;
12655   --
12656 
12657 
12658   --- build comp object clear the person level cacahe
12659   --  then build it again 4204020
12660   --if p_prtt_cache = 'Y' and   g_cache_person_prtn.last is  null then
12661      cache_person_information
12662       (p_person_id         => p_person_id,
12663        p_business_group_id => p_business_group_id,
12664        p_effective_date    => nvl(l_rec.lf_evt_ocrd_dt,p_effective_date));
12665 
12666     if g_debug then
12667       hr_utility.set_location ('Dn Cac Per Inf '||l_package,10);
12668     end if;
12669   --
12670   --end if ;
12671 
12672 
12673   /* Moved call to person_header before evaluate_life_events
12674   person_header
12675        (p_person_id            => p_person_id,
12676         p_business_group_id    => p_business_group_id,
12677         p_effective_date       => nvl(l_rec.lf_evt_ocrd_dt,p_effective_date));
12678   */
12679   --
12680   if g_debug then
12681     hr_utility.set_location (l_package||' Bef process_comp_objects ',17);
12682   end if;
12683   process_comp_objects
12684     (p_person_id                => p_person_id,
12685      p_person_action_id         => p_person_action_id,
12686      p_object_version_number    => p_object_version_number,
12687      p_business_group_id        => p_business_group_id,
12688      p_mode                     => nvl(ben_manage_life_events.g_modified_mode, p_mode),
12689      p_ler_id                   => l_ler_id,
12690      p_derivable_factors        => g_derivable_factors,
12691      p_cbr_tmprl_evt_flag       => p_cbr_tmprl_evt_flag,
12692      p_person_count             => p_person_count,
12693      -- PB : 5422 :
12694      p_lf_evt_ocrd_dt           => p_lf_evt_ocrd_dt,
12695      -- p_popl_enrt_typ_cycl_id    => p_popl_enrt_typ_cycl_id,
12696      p_effective_date           => p_effective_date,
12697      p_gsp_eval_elig_flag       => p_gsp_eval_elig_flag,      /* GSP Rate Sync */
12698      p_lf_evt_oper_cd           => p_lf_evt_oper_cd           /* GSP Rate Sync */
12699      );
12700   --
12701   if p_mode in ('W','G') then
12702      if p_mode = 'W' then
12703         l_module := 'CWB';
12704      elsif p_mode = 'G' then
12705         l_module := 'GSP';
12706      end if;
12707      --
12708      if g_debug then
12709         hr_utility.set_location ('Calling pqh ranking proc ',10);
12710         hr_utility.set_location ('p_benefit_action_id=>'||benutils.g_benefit_action_id,10);
12711         hr_utility.set_location ('p_module=>'||l_module,10);
12712         hr_utility.set_location ('p_per_in_ler_id=>'||l_rec.per_in_ler_id,10);
12713         hr_utility.set_location ('p_person_id=>'||p_person_id,10);
12714         hr_utility.set_location ('p_effective_date=>'||l_rec.lf_evt_ocrd_dt,10);
12715      end if;
12716      --
12717      pqh_ranking.compute_total_score (
12718        p_benefit_action_id =>  benutils.g_benefit_action_id
12719       ,p_module         => l_module
12720       ,p_per_in_ler_id  => l_rec.per_in_ler_id
12721       ,p_person_id      => p_person_id
12722       ,p_effective_date => l_rec.lf_evt_ocrd_dt );
12723      --
12724   end if;
12725   if g_debug then
12726     hr_utility.set_location ('Leaving '||l_package,10);
12727   end if;
12728   --
12729 exception
12730   --
12731   when g_record_error then
12732     --
12733     if g_debug then
12734       hr_utility.set_location ('PLE g_record_error '||l_package,10);
12735     end if;
12736     --
12737     -- An error has occured so rollback anything that could have been
12738     -- inserted into tables at this point.
12739     --
12740     if g_debug then
12741       hr_utility.set_location ('PERSON ERROR '||l_package,10);
12742     end if;
12743     rollback to process_life_event_savepoint;
12744     --
12745     -- Roll cache to savepoint
12746     --
12747     benutils.rollback_cache;
12748     --
12749     -- WW1178659 - Set the life event occured date to the effective
12750     -- date because the life event occured date may not have been
12751     -- derived. We can do this because national identifier is
12752     -- non-updateable so the effective date is irrelevant when
12753     -- getting person information.
12754     --
12755     ben_env_object.setenv(p_lf_evt_ocrd_dt => p_effective_date);
12756     ben_env_object.get(p_rec => l_env);
12757     ben_person_object.get_object(p_person_id => p_person_id,
12758                                  p_rec       => l_per_rec);
12759 
12760     g_rec.person_id := p_person_id;
12761     g_rec.pgm_id := l_env.pgm_id;
12762     g_rec.pl_id := l_env.pl_id;
12763     g_rec.oipl_id := l_env.oipl_id;
12764     l_encoded_message := fnd_message.get_encoded;
12765     fnd_message.parse_encoded(encoded_message => l_encoded_message,
12766                               app_short_name  => l_app_short_name,
12767                               message_name    => l_message_name);
12768     fnd_message.set_encoded(encoded_message => l_encoded_message);
12769 
12770     g_rec.rep_typ_cd := 'ERROR';
12771     g_rec.national_identifier := l_per_rec.national_identifier;
12772 
12773     -- Bug 2836770
12774     -- Added nvl's for l_message_name and fnd_message.get
12775     -- made call to write_table_and_file
12776     --
12777     g_rec.error_message_code := nvl(l_message_name , g_rec.error_message_code);
12778     g_rec.text := nvl(fnd_message.get , g_rec.text );
12779     --
12780     --benutils.write(p_text => g_rec.text); /* GSP Rate Sync */
12781     benutils.write(p_rec => g_rec);
12782     --
12783     -- benutils.write_table_and_file(p_table => true,
12784     --                              p_file  => true);
12785 
12786     -- Bug 2836770
12787     g_action_rec.person_action_id := p_person_action_id;
12788     g_action_rec.action_status_cd := 'E';
12789     g_action_rec.ler_id := p_ler_id;
12790     g_action_rec.object_version_number := p_object_version_number;
12791     g_action_rec.effective_date := p_effective_date;
12792     --
12793     benutils.write(p_rec => g_action_rec);
12794     --
12795     p_error_person_count := p_error_person_count +1;
12796     --
12797     if p_error_person_count = g_max_errors_allowed then
12798       --
12799       fnd_message.set_name('BEN','BEN_91662_BENMNGLE_ERROR_LIMIT');
12800       benutils.write(p_text => fnd_message.get);
12801       if g_debug then
12802         hr_utility.set_location ('PLE g_record_error Err Lim '||l_package,10);
12803       end if;
12804       --
12805       -- Write the last bit of information for the thread before
12806       -- the rollback fires when we raise the error.
12807       --
12808       benutils.write_table_and_file(p_table => true,
12809                                     p_file  => true);
12810       commit;
12811       --
12812       raise;
12813       --
12814     end if;
12815     --
12816     -- Bug 5232223
12817     --
12818   when g_cwb_trk_ineligible then
12819     --
12820     if g_debug then
12821       hr_utility.set_location ('PLE g_life_event_after '||l_package,10);
12822     end if;
12823     --
12824     rollback to process_life_event_savepoint;
12825     --
12826     -- process.
12827     --
12828     g_action_rec.person_action_id := p_person_action_id;
12829     g_action_rec.action_status_cd := 'P';
12830     g_action_rec.ler_id := p_ler_id;
12831     g_action_rec.object_version_number := p_object_version_number;
12832     g_action_rec.effective_date := p_effective_date;
12833     --
12834     benutils.write(p_rec => g_action_rec);
12835     --
12836     p_person_count := p_person_count +1;
12837     --
12838   when g_life_event_after then
12839     --
12840     if g_debug then
12841       hr_utility.set_location ('PLE g_life_event_after '||l_package,10);
12842     end if;
12843     --
12844     -- We don't want to roll back the transaction, just carry on with the
12845     -- process.
12846     --
12847     g_action_rec.person_action_id := p_person_action_id;
12848     g_action_rec.action_status_cd := 'P';
12849     g_action_rec.ler_id := p_ler_id;
12850     g_action_rec.object_version_number := p_object_version_number;
12851     g_action_rec.effective_date := p_effective_date;
12852     --
12853     benutils.write(p_rec => g_action_rec);
12854     --
12855     p_person_count := p_person_count +1;
12856     --
12857   when app_exception.application_exception then
12858     --
12859     if g_debug then
12860       hr_utility.set_location ('PLE application_exception '||l_package,12);
12861     end if;
12862     --
12863     -- Update person action to errored as record has an error
12864     --
12865     rollback to process_life_event_savepoint;
12866     benutils.rollback_cache;
12867     --
12868     -- Roll cache to savepoint
12869     --
12870     ben_env_object.setenv(p_lf_evt_ocrd_dt => p_effective_date);
12871     ben_env_object.get(p_rec => l_env);
12872     ben_person_object.get_object(p_person_id => p_person_id,
12873                                  p_rec       => l_per_rec);
12874     g_rec.person_id := p_person_id;
12875     g_rec.pgm_id := l_env.pgm_id;
12876     g_rec.pl_id := l_env.pl_id;
12877     g_rec.oipl_id := l_env.oipl_id;
12878     l_encoded_message := fnd_message.get_encoded;
12879     fnd_message.parse_encoded(encoded_message => l_encoded_message,
12880                               app_short_name  => l_app_short_name,
12881                               message_name    => l_message_name);
12882     fnd_message.set_encoded(encoded_message => l_encoded_message);
12883     g_rec.rep_typ_cd := 'ERROR';
12884     g_rec.error_message_code := l_message_name;
12885     g_rec.national_identifier := l_per_rec.national_identifier;
12886     g_rec.text := fnd_message.get;
12887     benutils.write(p_text => g_rec.text);
12888     benutils.write(p_rec => g_rec);
12889     --
12890     g_action_rec.person_action_id := p_person_action_id;
12891     g_action_rec.action_status_cd := 'E';
12892     g_action_rec.ler_id := p_ler_id;
12893     g_action_rec.object_version_number := p_object_version_number;
12894     g_action_rec.effective_date := p_effective_date;
12895     --
12896     benutils.write(p_rec => g_action_rec);
12897     --
12898     p_error_person_count := p_error_person_count +1;
12899     --
12900     if p_error_person_count = g_max_errors_allowed then
12901       --
12902       fnd_message.set_name('BEN','BEN_91662_BENMNGLE_ERROR_LIMIT');
12903       benutils.write(p_text => fnd_message.get);
12904       --
12905       -- Write the last bit of information for the thread before
12906       -- the rollback fires when we raise the error.
12907       --
12908       benutils.write_table_and_file(p_table => true,
12909                                     p_file  => true);
12910       commit;
12911       --
12912       raise;
12913       --
12914     end if;
12915     --
12916   when others then
12917     --
12918     if g_debug then
12919       hr_utility.set_location ('SERIOUS Error '||l_package,10);
12920     end if;
12921     --
12922     -- Update person action to errored as record has an error
12923     --
12924     rollback to process_life_event_savepoint;
12925     benutils.rollback_cache;
12926     --
12927     g_rec.rep_typ_cd := 'FATAL';
12928     g_rec.text := sqlerrm;
12929     benutils.write(p_rec => g_rec);
12930     --
12931     g_action_rec.person_action_id := p_person_action_id;
12932     g_action_rec.action_status_cd := 'E';
12933     g_action_rec.ler_id := p_ler_id;
12934     g_action_rec.object_version_number := p_object_version_number;
12935     g_action_rec.effective_date := p_effective_date;
12936     --
12937     benutils.write(p_rec => g_action_rec);
12938     --
12939     p_error_person_count := p_error_person_count +1;
12940     --
12941     raise;
12942     --
12943 end process_life_events;
12944 --
12945 procedure init_bft_statistics
12946   (p_business_group_id in number
12947   )
12948 is
12949   --
12950   l_proc varchar2(80) := g_package||'.init_bft_statistics';
12951   --
12952 begin
12953   --
12954   g_debug := hr_utility.debug_enabled;
12955   --
12956   g_proc_rec.business_group_id := p_business_group_id;
12957   g_proc_rec.strt_dt := sysdate;
12958   g_proc_rec.strt_tm := to_char(sysdate,'HH24:MI:SS');
12959   g_strt_tm_numeric := dbms_utility.get_time;
12960   --
12961 end init_bft_statistics;
12962 --
12963 procedure write_bft_statistics
12964   (p_business_group_id in number
12965   ,p_benefit_action_id in number
12966   )
12967 is
12968   --
12969   l_proc varchar2(80);
12970   --
12971   cursor c_person_actions(p_status_cd varchar2) is
12972     select count(*)
12973     from   ben_person_actions pac
12974     where  pac.benefit_action_id = p_benefit_action_id
12975     and    pac.action_status_cd = nvl(p_status_cd,pac.action_status_cd);
12976   --
12977 begin
12978   --
12979   g_debug := hr_utility.debug_enabled;
12980   --
12981   g_proc_rec.end_dt := sysdate;
12982   g_proc_rec.end_tm := to_char(sysdate,'HH24:MI:SS');
12983   g_end_tm_numeric := dbms_utility.get_time;
12984   g_proc_rec.elpsd_tm := (g_end_tm_numeric-g_strt_tm_numeric)/100;
12985   --
12986   if g_debug then
12987     l_proc := g_package||'.write_bft_statistics';
12988     hr_utility.set_location (l_proc||' Master process ',30);
12989   end if;
12990   open c_person_actions(null);
12991     fetch c_person_actions into g_proc_rec.per_slctd;
12992   close c_person_actions;
12993   if g_debug then
12994     hr_utility.set_location (l_proc||' c_person_actions(null)',31);
12995   end if;
12996   --
12997   open c_person_actions('E');
12998     fetch c_person_actions into g_proc_rec.per_err;
12999   close c_person_actions;
13000   if g_debug then
13001     hr_utility.set_location (l_proc||' c_person_actions(E) ',32);
13002   end if;
13003   --
13004   open c_person_actions('P');
13005     fetch c_person_actions into g_proc_rec.per_proc_succ;
13006   close c_person_actions;
13007   if g_debug then
13008     hr_utility.set_location (l_proc||' c_person_actions(P) ',33);
13009   end if;
13010   --
13011   open c_person_actions('U');
13012     fetch c_person_actions into g_proc_rec.per_unproc;
13013   close c_person_actions;
13014   --
13015   if g_debug then
13016     hr_utility.set_location (l_proc||' Done c_person_actions ',35);
13017   end if;
13018   g_proc_rec.business_group_id := p_business_group_id;
13019   g_proc_rec.per_proc := nvl(g_proc_rec.per_proc_succ,0)+
13020                          nvl(g_proc_rec.per_err,0);
13021   --
13022   if g_debug then
13023     hr_utility.set_location (l_proc||' Write ',35);
13024   end if;
13025   benutils.write(p_rec => g_proc_rec);
13026   --
13027 end write_bft_statistics;
13028 --
13029 end ben_manage_life_events;