DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_ENROLMENT_REQUIREMENTS

Source


1 PACKAGE BODY ben_enrolment_requirements AS
2 /* $Header: bendenrr.pkb 120.32.12020000.5 2012/10/18 05:48:19 pvelvano ship $ */
3 -------------------------------------------------------------------------------
4 /*
5 +=============================================================================+
6 |                       Copyright (c) 1998 Oracle Corporation                 |
7 |                          Redwood Shores, California, USA                    |
8 |                               All rights reserved.                          |
9 +=============================================================================+
10 --
11 Name
12   Determine Enrolment Requirements
13 Purpose
14   This package is used to create enrolment choice entries for all choices
15   which a person may elect.
16 History
17      Date       Who          Version   What?
18      ----       ---          -------   -----
19      18 Mar 98  jcarpent     110.0     Created
20      05 Jun 98  jcarpent     110.1     Compensated for null pl_id
21      06 Jun 98  jcarpent     110.2     Changed order of heirarchy for date cd
22                                        Save pl_typ_cd in epe.
23      08 Jun 98  jcarpent     110.3     Changed default_flag processing
24                                        added new dflt_enrt_cd code hanlers
25      09 Jun 98  thayden      110.4     Added batch who columns.
26      10 Jun 98  jcarpent     110.5     Changed rule execution routines
27      11 Jun 98  jcarpent     110.6     Fixed wrong error messag for rt_strt_dt
28      17 Jun 98  jcarpent     110.7     Some business_group_id checks added
29      29 Jun 98  jcarpent     110.8     Check invk_imptd/flxcr flag
30                                        nvl on dys_aftr_end_to_dflt
31                                        nvl on addit_procg_dys_num
32                                        Changed tco_chg_enrt to check enrt
33      01 Jul 98  jcarpent     110.9     Added return to determine
34                                        erlst_deenrt_dt
35      01 Jul 98  jcarpent     110.10    Changed enrt_cd handling for unenrolled
36      08 Jul 98  jcarpent     110.11    Fixed pgm level sched enrt perd
37                                        added p_popl_enrt_typ_cycl_id arg
38      21 Jul 98  jcarpent     110.12    Added/changed some messages
39      18 Aug 98  jcarpent     110.13    Put in substr on write calls
40      27 Aug 98  G Perry      115.12    Formatted and used values from benmngle
41                                        global structures
42      27 Aug 98  jcarpent     115.14    Create plan choice if elig and oipl
43                                        created. If plan has oipls then
44                                        create no choice.
45      28 Aug 98  G Perry      115.15    Added use of global
46                                        g_electable_choice_created to test when
47                                        an electable choice has been created.
48      22 Sep 98  jcarpent     115.16    added 'STRTD' restriction
49      25 Sep 98  jcarpent     115.17    added ler_chg_ptip.
50                                        look at ler_chc* for open enrt
51                                        enrt_perd+lee_rsn passed to epe api
52                                        handle plans in multiple programs
53                                        removed rt_strt_dt form epe api call
54      15 Oct 98  G Perry      115.21    Added in auto enrt stuff, corrected a
55                                        few cursor bugs.
56      15 Oct 98  G Perry      115.22    Defaulted mndtry_flag.
57      16 Oct 98  jcarpent     115.23    Fixed auto_enrt_flag or oipls
58      19 Oct 98  jcarpent     115.24    Use plip enrt info. Use pl.enrt_rl.
59                                        Provide acty_ref_perd_cd/uom.
60      20 Oct 98  jcarpent     115.25    default oipl_auto_flag to 'N'
61      21 Oct 98  jcarpent     115.26    Added l_rec_auto_enrt_flag
62                                        Support for unrestricted enrt.
63                                        Removed all rt_strt_dt logic.
64                                        use enrt_perd_for_pl_f for csd calc.
65      28 Oct 98  jcarpent     115.27    Set l_rec_cls_enrt_dt_to_use_cd
66                                        Check pgm_id on all ben_elig_per_f sql
67      28 Oct 98  G Perry      115.28    Fixed all ben_elig_per_f references in
68                                        cursors as they were all ropey.
69      30 Oct 98  G Perry      115.30    Fixed how parameter
70                                        popl_enrt_typ_cycl_id works to support
71                                        multiple scheduled enrollment.
72      12 Dec 98  jcarpent     115.31    Create epe when dependent change
73                                        allowed.  Changed all pen cursors to
74                                        check csd+ced
75      15 Dec 98  G Perry      115.32    Added in call to electbl choice
76                                        reporting stuff for the audit log.
77      18 Dec 98  jcarpent     115.33    Changed ler_chg_enrt heirarchy.
78      20 Dec 98  G Perry      115.34    Plan electablce cache entry no longer
79                                        contains option details.
80      23 Dec 98  jcarpent     115.35    Handle overridden results.
81                                        Fixed c_oipl_enrolment_info cursor
82                                        to check cvg dates.
83                                        Changed default enrt cd processing
84      04 Jan 99  jcarpent     115.36    Return value for all functions.
85      14 Jan 99  jcarpent     115.37    Use current enrt_cvg_strt_dt if !null
86      18 Jan 99  G Perry      115.38    LED V ED
87      27 Jan 99  jcarpent     115.39    Changed erlst_deenrt_dt logic.
88      03 Feb 99  jcarpent     115.40    Support for Level jumping restrictions
89                                        Get erlst_deenrt_dt from opt,pl,oipl too
90      25 Mar 99  jcarpent     115.42    Added assignment_id to rule contexts
91      01 Apr 99  jcarpent     115.43    Remove exit point when currently enrd,
92                                        no dpnt chg allowed, not electable.
93      09 Apr 99  stee         115.44    Change ben_per_in_ler_f to
94                                        ben_per_in_ler.
95      28 Apr 99  shdas	     115.45    Added more contexts in rule calls.
96      28 Apr 99  jcarpent     115.46    When no lee_rsn exists exist don't error
97                                        exit without creating choice.
98      28 Apr 99  jcarpent     115.47    Init perd_for_pgm_found to 'N'
99      29 Apr 99  lmcdonal     115.48    prtt_enrt_rslt now has a status code.
100      04 May 99  shdas	     115.49    Added jurisdiction code.
101      06 May 99  jcarpent     115.50    Fork off version 115.39 to do below chg
102      06 May 99  jcarpent     115.51    Call new hashing procedure
103      07 May 99  jcarpent     115.52    Pass greater(elig_strt_dt,lf_evt_oc_dt)
104                                        into start date routines.
105      11 May 99  jcarpent     115.53    Made all lf_evt_ocrd_dt change.
106      20 May 99  jcarpent     115.54    Backed out nocopy lf_evt chg for enrollment.
107                                        because eff dates based on eff dt.
108      21 May 99  jcarpent     115.55    Error if cls_enrt_dt_to_use_cd is null
109                                        fix assignment messages.
110      24 May 99  jcarpent     115.56    Make sure comp objects exist as of
111                                        enrt_perd_strt_dt.  Pgm,pl_typ,pl,opt,
112                                        oipl,plip,ptip,lee_rsn,ler.
113      24 Jun 99  maagrawa     115.57    invk_imptd_incm_pl_flag changed to
114                                        imptd_incm_calc_cd.
115      24 Jun 99  maagrawa     115.57    invk_imptd_incm_pl_flag changed to
116                                        imptd_incm_calc_cd.
117      05 Jul 99  stee         115.58    COBRA changes.  Check for coverage
118                                        in a plan when evaluating enrollment
119                                        code.  Also evaluate the
120                                        cvg_incr_r_decr_only_code at the plip
121                                        level.
122      12 Jul 99  jcarpent     115.59    Added checks for backed out nocopy pil.
123      12 Jul 99  moyes        115.60  - Added trace messages.
124                                      - Removed + 0s from all cursors.
125      20-JUL-99  Gperry       115.61    genutils -> benutils package rename.
126      21-JUL-99  mhoyes       115.62  - Added trace messages.
127      30-JUL-99  mhoyes       115.63  - Added trace messages.
128      02-Aug-99  tguy         115.64    Added spouse and dependent for imputed
129                                        incomes.
130      04-Aug-99  jcarpent     115.65  - Fixed level jumping signs
131      10-Aug-99  tmathers     115.66  - Fixed formula returning date
132                                        code.
133      23-Aug-99  shdas        115.67  - Added codes for pl_ordr_num,plip_ordr_num,
134                                        ptip_ordr_num,oipl_ordr_num.
135      31-Aug-99  jcarpent     115.68  - Update to look at ptip enrollment cols.
136                                        Use new ler_chg_pgm_enrt_f table.
137                                        Added dflt_enrt_cd/rl hierarchy.
138      07-Sep-99  tguy         115.69    fixed call to pay_mag_util
139      09-Sep-99  jcarpent     115.70  - Turn off auto flag for plan choices
140                                        created due to auto oipl.
141      09-Sep-99  stee         115.71  - Add new cvg_incr_r_decr_only codes
142                                        MNAVLO and MXAVLO.
143      21-Sep-99  jcarpent     115.72  - Added dflt_enrt_cds nncsedr, ndcsedr
144      22-Sep-99  jcarpent     115.73  - Changed calls to auto_enrt_(mthd)_rl
145                                        Combined calls for ler_chg and non-ler
146                                        chg to call determine_enrolment once.
147      23-Sep-99  jcarpent     115.74  - Renamed l_enrt_rl to l_ler_enrt_rl.
148      24-Sep-99  jcarpent     115.75  - Changed auto_enrt_cd/flag processing.
149                                        Consolidated *electable_flag variables
150                                        and parameters to be more consistent.
151      25-Sep-99  stee         115.76  - Added pgm_typ_cd to elctbl_chc_api.
152      01-Oct-99  tguy         115.77  - Fixed level jumping issues
153      01-Oct-99  jcarpent     115.78  - Added oipl.enrt_cd/rl
154      03-Oct-99  tguy         115.79  - New fixes to level jumping.
155      06-Oct-99  tguy         115.80  - added new checks for level jumping.
156      14-Oct-99  jcarpent     115.81  - Allow enrt_cd to control elctbl_flag
157                                        for automatic enrollments.
158      19-Oct-99  pbodla       115.82  - At Level : Period for program found
159                                        in call to ben_determine_date.main
160                                        l_pgme_enrt_perd_end_dt_rl is modified
161                                        to l_pgme_enrt_perd_strt_dt_rl
162      26-Oct-99  maagrawa     115.83  - Level jumping fixed for persons, who
163                                        are not previously enrolled. i.e. when
164                                        enrd_ordr_num is null.
165      02-Nov-99  maagrawa     115.84  - Level jumping restrictions removed at
166                                        plip level.
167      12-Nov-99  mhoyes       115.85  - Fixed bug 3630. Invalid number problem
168                                        in cursor c_ler_chg_enrt_info.
169      16-Nov-99  jcarpent     115.86  - Changed c_ler_chg_enrt_info again
170                                        problem was with decode for dflt_enrt_rl
171                                      - Also Added determine_dflt_enrt_cd
172                                      - Also added new global
173                                      - Fixed auto enrt rule execution.
174                                        was never running auto enrt rule.
175      03-Dec-99 lmcdonal      115.87    stl_elig...flag was being passed
176                                        incorrectly to determine_enrollment.
177      08-Dec-99 jcarpent      115.88  - Change hierarchy for enrt_mthd_cd/rl.
178                                      - Fix oipl enrt_cd bug. Rl overwrote cd.
179      01-Jan-00 pbodla        115.89  - Automatic enrollment rule is executed,
180                                        even if the enrt_mthd_cd is null.
181      05-Jan-00 jcarpent      115.90  - Added procs find_rqd_perd_enrt and
182                                        find_enrt_at_same_level
183      13-Jan-00 shdas         115.91  - added code so that choices for flx and
184                                        imptd inc plans are created irrespective
185                                        of whether they are configured  to be
186                                        electable for each life event or not.
187      21-Jan-00 pbodla        115.92  - p_elig-per_id is added to
188                                        execute_enrt_rule, determine_enrolment
189                                        and passes to benutils.formula
190      05-Jan-00 maagrawa      115.93  - Get the auto enrollment flag from oipl's
191                                        ler record, if availabe (Bug 4290).
192                                      - If the choice is automatic, it cannot
193                                        be default. (Bug 1175262).
194      07-Jan-00 jcarpent      115.94  - Subtract 1 day from date when checking
195                                        prev enrollment for tco-chg logic.
196                                        (bug 1120686/4145)
197      15-Feb-00 jcarpent      115.95  - Subtract 1 day from all enrollment chks
198                                      - Added plip level jumping restrictsions
199                                        back in. (bug 1146785/4153)
200      07-Mar-00 jcarpent      115.96  - De-enroll if "Lose only". bug 1217196
201      16-Mar-00 stee          115.97  - Remove program restriction if
202                                        cvg_incr_r_decr_only_cd is specified at
203                                        the plip level.
204      23-Mar-00 jcarpent      115.98  - Fix enrt_mthd_rule use.  Removed
205                                        l_auto_enrt_rl (use l_ler_auto_enrt_rl)
206                                        Bug 1246785/4922.
207      29-Mar-00  lmcdonal   115.66    Bug 1247115 - do not subtract 1 from
208                                           life event ocrd dt when looking for
209                                           esd/eed.  Only when looking for cvg
210                                           strt/end dates.  Did this to all
211                                           cursors that had the -1 except those
212                                           looking at elig_per tables.
213      06-Apr-00  mmogel       115.100 - Added tokens to message calls to make
214                                        the messages more meaningful to the user
215      11-Apr-00  maagrawa     115.101 - Start the enrollment period on the
216                                        effective date if there is an conflicting
217                                        life event between the enrollment period
218                                        start date and the effective date.
219                                        Bug 4988.
220      18-Apr-00  maagrawa     115.102   Backport to 115.100
221      18-Apr-00  lmcdonal     115.103   Fido Bug 6176:  When looking for current
222                                        enrollments, no longer look for
223                                        nvl(lf_evt_orcd_dt, eff dt) between esd and eed
224                                        instead look for eed = eot.
225      20-Apr-00  mhoyes       115.104 - Added profiling messages.
226      03-May-00  pbodla       115.105 - Task 131 : execute_enrt_rule modified
227                                      - If elig dependent rows are already created
228                                        then pass the elig dependent id as input
229                                        values to rule.
230      12-May-00  mhoyes       115.106 - Added profiling messages.
231      13-May-00  jcarpent     115.107 - Modified enrt_perd_strt_dt logic for
232                                        reinstated le's (4988,1269016)
233      15-May-00  mhoyes       115.108 - Called create EPE performance cover.
234      16-May-00  mhoyes       115.109 - Added profiling messages.
235      18-May-00  jcarpent     115.110 - Modified c_get_latest_procd_dt to
236                                        ignore backed out nocopy pils (4988,1269016)
237      23-May-00  mhoyes       115.113 - General tuning of SQL by dharris.
238                                      - Added p_comp_obj_tree_row to
239                                        enrolment_requirements.
240      24-May-00  mhoyes       115.114 - Added/removed trace messages.
241                                      - Enabled cache mode for rates_and_coverage
242                                        dates. This caches the per in ler.
243      25-May-00  jcarpent     115.115 - Added logic to have crnt_enrt_prclds_chg
244                                        work for entire ptip. (5216,1308627)
245      29-May-00  mhoyes       115.116 - Commented out nocopy hr_utility calls for
246                                        performance in highly executed logic.
247                                      - Tuning by dharris.
248      31-May-00  mhoyes       115.117 - Passed through current comp object
249                                        row parameters to avoid cache calls.
250                                      - Passed comp object rows to
251                                        rate_and_coverage_dates to avoid cursor
252                                        executions.
253      09-Jun-00  pbodla       115.118 - Bug 5272 : A fix to cursors
254                                        c_sched_enrol_period_for_plan,
255                                        c_sched_enrol_period_for_pgm in version
256                                        115.113 caused this bug. These cursors
257                                        are fixed.
258      23-Jun-00  pbodla       115.119 - Fix to check enrollment results as
259                                        of the life event occurred date instead
260                                        of life event occurred -1 when
261                                        determining the default flag. Bug 5241.
262      28-Jun-00  shdas        115.120 - Added procedure execute_auto_dflt_enrt_rule.
263      28-Jun-00  jcarpent     115.121 - Bug 4936: Use new cvg_strt_dt if sched
264                                        enrt and plan is for 125 or 129
265                                        regulation.
266      29-Jun-00  mhoyes       115.122 - Reworked cursors c_nenrt and c_pl_bnft_rstrn
267                                        as PLSQL.
268      30-Jun-00  mhoyes       115.123 - Fired cursor c_nenrt when context parameters
269                                        are not set.
270      05-Jul-00  mhoyes       115.124 - Added context parameters.
271      13-Jul-00  mhoyes       115.125 - Removed context parameters.
272      19-Jul-00  jcarpent     115.126 - 5241,1343362. Added update_defaults
273      03-Aug-00  jcarpent     115.127 - 5429. Fixed reinstate dependent logic.
274      04-Aug-00  pbodla       115.128 - 4871(1255493) : After mndtry_rl executed
275                                        it's out nocopy put is not used.
276      31-Aug-00  jcarpent     115.129 - Comp object changes were causing
277                                        non-date effective error.  Added
278                                        requery logic.  WWbug 1394507.
279      05-sep-00  pbodla       115.130 - Bug 5422 : Allow different enrollment periods
280                                        for programs for a scheduled  enrollment.
281                                        p_popl_enrt_typ_cycl_id is removed.
282      14-Sep-00  jcarpent     115.131 - Leapfrog version based on 115.129.
283                                        Bug 1401098.  Added logic to update_
284                                        defaults to change elctbl_flag also.
285                                        Needed for rules which use enrol/elig
286                                        in other plans for electablility.
287      14-Sep-00  jcarpent     115.132 - Merged version of 115.131 with 130.
288      25-Sep-00  mhoyes       115.133 - Removed hr_utility.set_locations.
289      07-Nov-00  mhoyes       115.134 - Added hr_utility.set_locations for
290                                        profiling.
291                                      - Modified update_defaults to use the
292                                        electable choice performance API.
293     15-dec-00   tilak        115.135   bug: 1527086 early denenrollment date carried forward
294                                        for future enrolment ,oipl_id condtion addded in cursor wich
295                                        take the information ofexisting enrolment for OPT level
296     04-jan-01   jcarpent     115.136 - Bug 1568555.  Removed +1 from enrt
297                                        period logic.
298     01-feb-01   kmahendr     115.137 - Bug 1621593 - If plan is savings and has options attached
299                                        then previous enrollment is checked and prtt_enrt_rslt_id
300                                        is assigned
301     08-feb-01   tilak        115.138   find_enrt_at_same_level changed to return the correct row
302                                        bug : 1620161
303     26-feb-01   kmahendr     115.139 - unrestricted process changes - if future enrollments exists
304                                        then treat it as not currently enrolled
305     27-feb-01   thayden     115.140  - change unrestricted enrolment period end date to end of time.
306     08-jun-01   kmahendr    115.141  - Bug#1811636 - For level jumping logical order number is used
307                                        in place of database ordr_num
308     08-jun-01   kmahendr    115.142  - Effective date condition added to cursor c_opt_level
309     26-jul-01   ikasire     115.143    bug1895874 added new nip_dflt_flag to ben_pl_f table.
310                                        In the internal procedure determine_dflt_enrt_cd
311                                        added to parameters p_pgm_rec,p_ptip_rec,p_plip_rec,
312                                        p_oipl_rec,p_pl_rec to get the data from the already
313                                        cached records. Also removed the calls to ben_cobj_cache
314                                        from internal determine_dflt_enrt_cd procedure as this
315                                        can not be used here.
316     27-aug-01  tilak        115.144   bug:1949361 jurisdiction code is
317                                       derived inside benutils.formula.
318     13-Nov-01  kmahendr     115.145   bug#2080856 - in determine_dflt_flag procedure, coverage is
319                                       checked at ptip level if plan level fails.
320     15-Nov-01  kmahendr     115.146   Bug#2080856 - if dflt_enrt_cd is null then default flag
321                                       is set to 'N' - changed the assignment in determine_dflt_flag
322     07-Dec-01  mhoyes       115.146  - Added p_per_in_ler_id to enrolment_requirements.
323     11-Dec-01  mhoyes       115.147  - Added p_per_in_ler_id to update_defaults.
324     18-Dec-01  kmahendr     115.148  - Comp. work bench changes
325     19-Dec-01  kmahendr     115.149  - put the end if before elig_flag for p_run_mode = 'W'
326     29-Dec-01  pbodla       115.152  - CWB Changes : Initialised package
327                                        globals g_ple_hrchy_to_use_cd,
328                                        g_ple_pos_structure_version_id
329                                        to use later in benmngle.
330     29-Dec-01  pbodla       115.153  - CWB Changes : hierarchy to use code
331                                        lookup codes changed to match ones in
332                                        seed115, extended C mode to W.
333     03-Jan-02  rpillay      115.154  - Applied nvl function to all flag-type parameters
334                                        passed in the call to create_perf_elig_per_elc_chc
335                                        from enrolment_requirements Bug# 2141756
336     04-jan-02  pbodla       115.155  - CWB Changes : hierarchy table is
337                                        populated after epe row is created.
338     11-Jan-02  ikasire      115.156    CWB Changes Bug 2172036 addition of new column
339                                        assignment_id to epe table
340     29-Jan-02  kmahendr     115.157    Bug#2108168 - Added a cursor c_ptip_waive_enrolment_info
341                                        in the procedure - determine_enrollment to check for
342                                        current enrollment in a waive plan
343     12-feb-02  pbodla       115.158  - CWB Changes : 2213828 - No need to
344                                        determine the enrt_perd_strt_dt,
345                                        enrt_perd_end_dt if the mode is W.
346     12-feb-02  pbodla       115.159  - CWB Changes : 2230922 : If ws manager id
347                                        not found then default to supervisor if
348                                        position heirarchy is used.
349     27-Feb-02  rpillay      115.160  - CWB Bug 2241010 Made changes to set elctbl_flag
350                                        and elig_flag to 'N' when person is ineligible
351     01-Apr-02  ikasire      115.161    Bug 229032 if the enrollment starts in a future
352                                        date, for unrestricted, user cannot get the enrollment
353                                        record for correction causing problems.
354     17-Apr-02  kmahendr     115.162    Bug#2328029 - previous eligibility must be arrived based
355                                        on life event occurred date or effective date-changed
356                                        l_effective_date_1 in enrollment_requirements and update
357                                        default procedures.
358     02-May-02  hnarayan     115.163    bug 2008871 - commented the return and included it
359                                        inside the requery cursor if block
360     				       since it affects positive cases of electability
361     14-May-02  ikasire      115.164    Bug 2374403 electable choices for the imputed
362                                        income type of spouse is not getting created
363                                        properly. IMPTD_INCM_CALC_CD of SPSL is used
364                                        instead of using SPS
365     19-May-02  ikasire      115.165    Bug 2200139 Override Enrollment changes
366     08-Jun-02  pabodla      115.164    Do not select the contingent worker
367                                        assignment when assignment data is
368                                        fetched.
369     20-Jun-02  ikasire      115.167    Bug 2404008 fixed by passing lf_evt_ocrd_dt rather
370                                        than p_effective_date to determine_dflt_enrt_cd call
371     14-Jul-02  pbodla       115.168    ABSENCES - Added absences mode M.
372                                        This mode is similar to mode L.
373     05-Aug-02  mmudigon     115.169    ABSENCES - do not look at backed out nocopy and
374                                        processed lers for determining enrollment
375                                        period
376    08-Aug-02  tjesumic      115.170    # 2500805 certain situation,where  2 option in same plan
377                                        became defaulted if the coverage start date is not controlled
378                                        Pls See the bug for the test case.
379                                        cursors c_plan_enrolment_info,c_oipl_enrolment_info in
380                                        procedure determine_dflt_flag validatd for cvg_strt_dt
381    21-Aug-02  pbodla        115.171    Bug 2503570 - CWB electable flag always set Y
382    29-Aug-02  kmahendr      115.172    Bug#2207956 - new enrollment code added and references
383                                        to sec129 or 125 is removed.
384    13-Sep-02  tjesumic      115.173    # 2534744  to fix the issue of defaulting past enrolled
385                                        elected value  new retutn values introduced in formula
386                                        AUTO_DFLT_ELCN_VAL in  execute_auto_dflt_enrt_rule
387                                        formula type auto enrollment
388                                        Which return elected value which is used by bencvrge to
389                                        populated the default benefit
390    28-Sep-02 pbodla         115.174    Bug 2600087 added order by clause to
391                                        c_oipl_enrolment_info and c_plan_enrolment_info
392    20-Oct-02  mhoyes        115.175  - Phased in call to ben_pep_cache.get_currpepepo_dets.
393                                      - Phased out nocopy previous eligibility cursors and
394                                        pointed to the previous eligibility cache.
395    01-Nov-02  mmudigon      115.176  - CWB: Bug 2526595 Bypass creation of epe
396                                        if trk_inelig is set to No and the person
397                                        is not eligible
398    01-Nov-02  tjesumic      115.177  - # 2542162 enrt_perd_strt_dt send  as param to the rule which
399                                        Calculate the enrt_perd_end_dt
400    01-Dec-02  pabodla       115.178  - Arcsing the file with CWB itemization code as commented.
401    04-Dec-02  rpillay       115.179  - CWB: Bug 2684227 - If a position is vacant climb the
402                                        position hierarchy till a person is found
403    09-Dec-02  mmudigon      115.180  - CWB itemization code uncommented.
404    16 Dec 02  hnarayan      115.181    Added NOCOPY hint
405    27 Dec 02  ikasire       115.182    Bug 2677804 changes.for Override thru date
406    03 Jan 03  tjesumic      115.183    bug # 2685018 if the formula return the result  id then
407                                        the result id will be catcated wiht dpnt carry forawrd  to store
408    07 Dec 03  tjesumic      115.184    New return value added in default enrollment formula 'PREV_PRTT_ENRT_RSLT_ID'
409                                        This value  added to the value of CARRY_FORWARD_ELIG_DPNT for storage
410    10 jan 03  pbodla        115.18?    GRADE/STEP : Added code to support
411                                        grade step progression process.
412    24-Feb-03  mmudigon      115.185  - CWB itemization : implement trk_inelig
413                                        flag at oipl level
414    12-Mar-03  ikasire       115.186    Bug 2827121 Contingent worker issue for
415                                        cwb
416    17-Mar-03  vsethi        115.187  - Bug 2650247 -passing the value for inelg_rsn_cd in call to
417   				       elig per elctbl chc api
418    10-Apr-03  rpgupta       115.188  - Bug 2746865
419    				       Enrollment period window enhancement
420    				       Changed the logic for arriving at the enrollment period start
421    				       and end dates
422    20-Jun-03  kmahendr      115.189  - Bug#2980560 - date passed to get_pilepo was changed to
423                                        l_effective_date_1
424    14-Jul-03  ikasire       115.190  - Bug 3044311 to get valid manager
425                                        for cwb position hierarchy.
426    11-Aug-03  ikasire       115.191    Bug 3058189 use l_lf_evt_ocrd_dt for the unrestricted cursors
427                                        while getting the pen info.
428    11-Aug-03  tjesumic      115.192    # 3086161 whne the LE reprocedd ,the Enrt Dt determined as of the
429                                        Previous LE Processed Date. if the nerollment made on the same date
430                                        the Exisiting results are updated in correction mode(same date).
431                                        Whne the cirrent LE backedout the previous LE results are lost
432                                        because the per_in_ler id updated in correction mode updated
433                                        This is fixed : if the  max enrollment date is  higer than the
434                                        max processed date then  max enrollment dt + 1 used for enrt_prd_strt_dt
435    12-Aug-03  vsethi        115.193    Bug 3063867, Changed enrt_perd_strt_dt When a prior life event has been
436    				       VOIDD, the enrollment period start date should not be set as the last
437    				       backed out date instead retain the original enrt window.
438    28-Aug-03  tjesumic      115.194    115.192 fix is reversed for # 3086161
439    25-Sep-03  rpillay       115.195    GRADE/STEP: Changes to enrolment_requirements
440                                        to not throw error for G mode when year periods
441                                        are not set up
442    07-oct-03  hmani         115.196    Bug 3137519 - Modified the c_get_latest_enrt_dt cursor
443    21-oct-03  hmani         115.197    Bug 3177401 - Changed p_date_mandatory_flag to 'Y'
444    28-Oct-03  tjesumic      115.198    #  2982606 when the coverage start date of the prev LE is in future
445                                        and current LE is current or earlier than previous one
446                                        create new result and set  currently enrolled flag to 'N'
447                                        related changes in  benbolfe  , benelinf ,benleclr
448    11-oct-03  hmani	    115.199    reversing the change done in 115.197. Changing the flag again.
449    18-Nov-03  tjesumic      115.200    # 3248770 Voided per in ler is not considered to find the enrollment period date
450    14-Jan-04  pbodla        115.201    GLOBALCWB : moved the heirarchy data
451                                        population to benptnle (on to ben_per_in_ler)
452    15-Mar-04  pbodla        115.202    GLOBALCWB : Bug 3502094  : For FP-F trk
453                                        inelig flag do not have any significance.
454                                        For july FP : final functionality will be
455                                        decided later.
456    15-Mar-04  pbodla        115.203    GLOBALCWB : Bug 3502094  : Commented end if
457                                        properly
458    18-Mar-04  rpgupta       115.204    3510229 - Allow system to pick up the
459    					default enrollment code from higher
460    					levels if not found in the lowest level
461    13-Apr-04  kmahendr      115.205    FONM changes.
462    29-Apr-04  mmudigon      115.206    Bug 3595902. Changes to cursors
463                                        c_plan_enrolment_info_unrst and
464                                        c_plan_enrolment_info in proc
465                                        enrolment_requirements
466    15-Jun-04  mmudigon      115.207    Bug 3685228. Merged cursors
467                                        c_plan_enrolment_info_unrst and
468                                        c_plan_enrolment_info in proc
469                                        enrolment_requirements. Treating 'M'
470                                        mode similar to 'U' mode for these
471                                        cursors.
472    29-Jun-04  kmahendr      115.208    Bug#3726552 - added call for updating dflt flag on
473                                        enrt bnft in update_defaults
474    13-Jul-04  kmahendr      115.209    Bug#3697378 - modified cursor-c_get_latest_enrt_dt
475    23-Aug-04  mmudigon      115.210    CFW : 2534391 :NEED TO LEAVE ACTION ITEMS
476                                        CERTIFICATIONS on subsequent events
477    27-Sep-04  pbodla        115.211    iRec : Avoid iRec life events similar to
478                                        gsp events.
479    30-Sep-04  abparekh      115.212    iRec : While picking assignments for iRec do not compare
480                                        primary flag. Extend / Exclude processing for iRec like GSP.
481    21-Oct-04  tjesumic      115.213    # 3936695 Enrollment_cd fixed by cheking the level of the setup
482    26-Oct-04  tjesumic      115.214    # 3936695
483    29-Oct-04  ikasire       115.215    Bugs 3972973 and 3978745 fixes
484    15-nov-04  kmahendr      115.216    Unrest. enh changes
485    17-Nov-04  tjesumic      115.217    # 4008380 fixed. fixed default flag validations
486    22-Nov-04 abparekh       115.218    Bug 4023880 : Fixed code to create elctbl chc at PLAN level if
487                                        they dont exist while creating elctbl chc at OIPL level.
488    01-Dec-04  kmahendr      115.219    Unrest. enh changes
489    30-dec-04    nhunur      115.49     4031733 - No need to open cursor c_state.
490    04-Jan-04  kmahendr      115.221   Bug#4096382 - condition added to return if comp.
491                                       objects are in pending or suspended in U or R mode
492    05-Jan-05  ikasire       115.222   Bug 4106760 fix
493    11-Jan-05  ikasire       115.223   BUG 4064635 CF Suspended Interim Changes
494    26-Jan-05  ikasire       115.224   BUG 4064635 CF Suspended Interim Changes
495    02-Feb-05  ikasire       115.225   BUG 4064635 CF Suspended Interim Changes
496    18-Apr-05  tjesumic      115.226   GHR enhancement to add number of days in enrt perd codeds
497    29-Apr-05  kmahendr      115.227   Added a parameter - update_def_elct_flag to
498                                       determine_enrolment - bug#4338685
499    24-May-05  bmanyam       115.228   Bug 4388226 : Changed c_get_latest_enrt_dt to
500                                       pick up valid enrollments only.
501    08-Jul-05  rbingi        115.229   Bug 4447114 : assigning Global value of
502                                       ben_evaluate_elig_profiles.g_inelg_rsn_cd
503                                       to l_inelg_rsn_cd in case of CWB run mode
504    12-Jul-05  pbodla        115.230   Populating data into ben_cwb_hrchy is
505                                       completely removed.
506    21-Jul-05  kmahendr      115.231   Bug#4478186 - added codes to procedure
507                                       enrt_perd_strt_dt
508    10-Nov-05  tjesumic      115.233   fix 115.232 (4571771) is reversed as the benauten  electable flag
509                                       validation is reverted
510    18-Jan-06  rbingi        115.234   Bug-4717052: Calling update_elig_per_elctbl when epe
511                                       existing for PLAN record for update of pen_id.
512    15-Feb-06  rbingi        115.235   Bug-5035423: contd from prev fix, calling Update_epe
513                                        only when epe exists for PLAN
514    03-Mar-06  kmahendr      115.236   Added new enrollment codes
515    14-Mar-06  ssarkar       115.237   5092244 - populating g_egd_table in update_defaults
516    04-Apr-06  rbingi        115.238   5029028: Added UNIONs to select the enrolment codes
517                                        from respective tables if ler_chg records not defined
518    26-Jun-06  swjain        115.239   5331889 - Added person_id param in calls to benutils.formula
519    30-Jun-06  swjain        115.240   Commented out show errors
520    01-sep-06  ssarkar       115.241   Bug 5491475 - reverted 5029028 fix
521    26-Sep-06  abparekh      115.242   Bug 5555402 - While determining DFLT_ENRT_CD, consider code
522                                                     at PL_NIP level for enrollment at PLIP level
523    28-Sep-06  abparekh      115.243   Bug 5569758 - Get OIPL details correctly in procedure
524                                                     DETERMINE_DFLT_ENRT_CD (1)
525    27-Sep-06  stee          115.244   Bug 5650482  - For scheduled mode, change the processing
526                                       end date to not slide if the event is backed out and
527                                       reprocessed at a later date.
528    05-Dec-06  stee          115.245   Bug 5650482  - If ENRT_PERD_DET_OVRLP_BCKDT_CD
529                                       = L_EPSD_PEPD then slide the processing date.
530    06-Jan-06  bmanyam       115.246   5736589: Increase/Decrease Requires certification
531                                       for Option Restrictions
532    08-Jan-06  bmanyam       115.247   5736589: Increase/Decrease Requires certification
533                                       for Option Restrictions
534    12-Jan-07  gsehgal       115.248   Bug 5644451 - Defaults are not getting created properly.
535 				                              See bug details for test case. Also local procedure
536 				                              determine_dflt_enrt_cd moved at top of the package as this
537 				                              is now used in ben_enrolment_requirements.enrolment_requirements
538    10-Feb-07  stee           115.249   Added a check for g_debug for trace statements.
539    22-Jan-07  rtagarra      115.249   -- ICM Changes for 'D' Mode.
540    28-May-07 rgajula        115.250   Bug 6061856 -- Modified the procedure determine_dflt_enrt_cd such that
541                                       Default Enrollment Codes at LER level Override Default Enrollment Codes at OIPL level.
542    20-Dec-07 sagnanas		      Included fix 6281735 and 6519487 for 12.1
543    15-Apr-09 ksridhar       115.255   Bug 7452061 : Reverting back the fix 5644451 for the bug 7452061
544    23-Apr-09 skameswa       115.257   Bug 8228639 : Modified the fix 7507714,restricted the fix to Unrestricted LE.
545    04-May-09 sallumwa       115.258   Bug 8453712 : Restricted the fix done in 6519487,when the plans corresponding to past and current
546                                       Life events are different.
547    08-Jun-09 sagnanas       115.259   Bug 8399189 - Modified cursor c_plan_enrolment_info
548    21-Aug-09 sallumwa       115.260   Bug 8768050 : Restricted the fix done in 6519487,when the plans corresponding to past and current
549                                                     Life events are different,when the plan has options.
550    24-Jun-09 sallumwa       115.262   Bug 8846328 : Modified the fix done for the bug 6519487 so that currently enrolled flags are set
551                                                     for the suspended and interim elections.
552    02-Dec-10 sagnanas       115.263   Bug 10211081: Modified cursor c_future_results to have oipl check
553    27-jun-11 usaraswa	    115.264   Bug 12621882  Modified procedures enrolment_requirements and update_defaults such that For evaluating
554                                                     Defualt enrollment code Added the check again at oipl level after Rule is evaluated.
555    25-Nov-11 sagnanas   120.24.12010000.9 12690264:Modified cursor c_pl_enrolment_info for erlst_deenrt_dt check
556    23-Sep-12 amnaraya 120.24.12010000.10 Bug 14661357: In procedures enrolment_requirements and update_defaults below changes are done
557                                          regarding Default Enrollment.
558                                          a) When the dflt_enrt_cd is RL and default level is IN ('LER_OIPL','OIPL') then the checking of
559                                          "Assign on Default" Flag is skipped.
560                                          b) When the dflt_enrt_cd is RL and default level NOT in ('LER_OIPL','OIPL') then the
561                                          "Assign on Default" Flag is evaluated first from the LER level and then if not found from the
562                                          General setup.
563    23-Sep-12 amnaraya 120.24.12010000.11 Bug 14661357: In procedures enrolment_requirements and update_defaults updated the cursor name
564                                          from c_ler_oipl_dflt_cd to c_ler_oipl_dflt_flag, and then closed the cursor.
565    28-Sep-12 amnaraya 120.24.12010000.12 Bug 14653541: Reverting the Fixes done for bugs 12621882 and 14661357.
566                                          When a rule is attached at Plan or Plan Type Level; then the ff rule should be smart enough
567                                          to return Y or N for the concern option. Should not check for "Assign on Default" Flag.
568    18-oct-12 velvanop 120.24.12010000.13 Bug 14768372: Added parameter p_elig_per_id in proc determine_dflt_flag. p_elig_per_id is used as Context for
569                                       Default Enrollment rule type. Parameter is passed for procedure execute_auto_dflt_enrt_rule
570 */
571 ---------------------------------------------------------------------------------------------------
572   g_package VARCHAR2(80)                := 'ben_enrolment_requirements';
573   g_rec     benutils.g_batch_elctbl_rec;
574   g_ptip_id NUMBER;
575 --
576 --
577 -- internal version below for update_defaults
578 -- bug 5644451. Move at top of the package
579 procedure determine_dflt_enrt_cd
580   (p_oipl_id           in     number
581   ,p_oipl_rec          in     ben_oipl_f%rowtype
582   ,p_plip_id           in     number
583   ,p_plip_rec          in     ben_plip_f%rowtype
584   ,p_pl_id             in     number
585   ,p_pl_rec            in     ben_pl_f%rowtype
586   ,p_ptip_id           in     number
587   ,p_ptip_rec          in     ben_ptip_f%rowtype
588   ,p_pgm_id            in     number
589   ,p_pgm_rec           in     ben_pgm_f%rowtype
590   ,p_ler_id            in     number
591   ,p_business_group_id in     number
592   ,p_effective_date    in     date
593   ,p_dflt_enrt_cd         out nocopy varchar2
594   ,p_dflt_enrt_rl         out nocopy number
595   ,p_level                out nocopy varchar2
596   ,p_ler_dflt_flag   out nocopy varchar2
597   )
598 IS
599     --
600     -- NOTE:
601     --
602     --   This procedure is also callable from other RCOs
603     --   Please do not remove get_object calls since they
604     --   may be needed if not called from bendenrr.
605     --
606     l_proc         VARCHAR2(80)       := g_package || '.determine_dflt_enrt_cd';
607     --
608     CURSOR c_ler_oipl_dflt_cd IS
609       SELECT   leo.dflt_enrt_cd,
610                leo.dflt_enrt_rl,
611                leo.dflt_flag
612       FROM     ben_ler_chg_oipl_enrt_f leo
613       WHERE    p_oipl_id = leo.oipl_id
614       AND      p_ler_id = leo.ler_id
615       AND      p_effective_date BETWEEN leo.effective_start_date
616                    AND leo.effective_end_date;
617     --
618     -- Use cache for oipl, don't need cursor
619     --
620     CURSOR c_ler_pl_nip_dflt_cd IS
621       SELECT   len.dflt_enrt_cd,
622                len.dflt_enrt_rl,
623                len.dflt_flag
624       FROM     ben_ler_chg_pl_nip_enrt_f len
625       WHERE    p_pl_id = len.pl_id
626       AND      p_ler_id = len.ler_id
627       AND      p_effective_date BETWEEN len.effective_start_date
628                    AND len.effective_end_date;
629     --
630     CURSOR c_ler_plip_dflt_cd IS
631       SELECT   lep.dflt_enrt_cd,
632                lep.dflt_enrt_rl,
633                lep.dflt_flag
634       FROM     ben_ler_chg_plip_enrt_f lep
635       WHERE    p_plip_id = lep.plip_id
636       AND      p_ler_id = lep.ler_id
637       AND      p_effective_date BETWEEN lep.effective_start_date
638                    AND lep.effective_end_date;
639     --
640     CURSOR c_ler_ptip_dflt_cd IS
641       SELECT   lep.dflt_enrt_cd,
642                lep.dflt_enrt_rl
643       FROM     ben_ler_chg_ptip_enrt_f lep
644       WHERE    p_ptip_id = lep.ptip_id
645       AND      p_ler_id = lep.ler_id
646       AND      p_effective_date BETWEEN lep.effective_start_date
647                    AND lep.effective_end_date;
648     --
649     CURSOR c_ler_pgm_dflt_cd IS
650       SELECT   lep.dflt_enrt_cd,
651                lep.dflt_enrt_rl
652       FROM     ben_ler_chg_pgm_enrt_f lep
653       WHERE    p_pgm_id = lep.pgm_id
654       AND      p_ler_id = lep.ler_id
655       AND      p_effective_date BETWEEN lep.effective_start_date
656                    AND lep.effective_end_date;
657     --
658     CURSOR c_pl_nip_dflt_cd IS
659       SELECT   pln.nip_dflt_enrt_cd,
660                pln.nip_dflt_enrt_det_rl,
661                pln.nip_dflt_flag
662       FROM     ben_pl_f pln
663       WHERE    p_pl_id = pln.pl_id
664       AND      p_effective_date BETWEEN pln.effective_start_date
665                    AND pln.effective_end_date;
666     --
667     CURSOR c_plip_dflt_cd IS
668       SELECT   plp.dflt_enrt_cd,
669                plp.dflt_enrt_det_rl
670       FROM     ben_plip_f plp
671       WHERE    p_plip_id = plp.plip_id
672       AND      p_effective_date BETWEEN plp.effective_start_date
673                    AND plp.effective_end_date;
674     --
675     CURSOR c_ptip_dflt_cd IS
676       SELECT   ptp.dflt_enrt_cd,
677                ptp.dflt_enrt_det_rl
678       FROM     ben_ptip_f ptp
679       WHERE    p_ptip_id = ptp.ptip_id
680       AND      p_effective_date BETWEEN ptp.effective_start_date
681                    AND ptp.effective_end_date;
682     --
683     l_dflt_enrt_cd VARCHAR2(30);
684     l_dflt_enrt_rl NUMBER;
685     l_plan_rec     ben_pl_f%ROWTYPE;
686     l_oipl_rec     ben_cobj_cache.g_oipl_inst_row;
687     l_ler_dflt_flag varchar2(30); -- 3510229
688   BEGIN
689     --
690     g_debug := hr_utility.debug_enabled;
691     --
692     if g_debug then
693     hr_utility.set_location('Entering: ' || l_proc, 10);
694     end if;
695     --
696     l_dflt_enrt_cd :=  NULL;
697     --
698     --Start Bug 6061856 -- Modified the Ordering, moved oipl to 6
699     -- Hierarchy
700     --
701     -- 1  if oipl     ben_ler_chg_oipl_enrt_f
702     -- 2  if no pgm   ben_ler_chg_pl_nip_enrt_f
703     -- 3  if pgm      ben_ler_chg_plip_enrt_f
704     -- 4  if pgm      ben_ler_chg_ptip_enrt_f
705     -- 5  if pgm      ben_ler_chg_pgm_enrt_f
706     --
707     -- 6  if oipl     ben_oipl_f (from cache)
708 
709     -- 7  if no pgm   ben_pl_f
710     -- 8  if pgm      ben_plip_f
711     -- 9  if pgm      ben_ptip_f
712     --
713 --End Bug 6061856
714     IF p_oipl_id IS NOT NULL THEN
715       --
716       -- 1
717       --
718       OPEN c_ler_oipl_dflt_cd;
719       FETCH c_ler_oipl_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl, l_ler_dflt_flag;
720                                     --p_ler_dflt_flag; 3510229
721       CLOSE c_ler_oipl_dflt_cd;
722       if /*l_dflt_enrt_cd 3510229*/l_ler_dflt_flag is not null then
723         p_level:='LER_OIPL';
724         p_ler_dflt_flag := l_ler_dflt_flag; -- 3510229
725         l_ler_dflt_flag := null ; --3510229
726       end if;
727       --
728      /* IF l_dflt_enrt_cd IS NULL THEN
729         --
730         -- 2
731         --
732 	if g_debug then
733         hr_utility.set_location('In the case 2 ' , 100);
734 	end if;
735         --
736         --l_dflt_enrt_cd :=  ben_cobj_cache.g_oipl_currow.dflt_enrt_cd;
737         --l_dflt_enrt_rl :=  ben_cobj_cache.g_oipl_currow.dflt_enrt_det_rl;
738         --
739         l_dflt_enrt_cd := p_oipl_rec.dflt_enrt_cd ;
740         l_dflt_enrt_rl := p_oipl_rec.dflt_enrt_det_rl ;
741 
742         --hr_utility.set_location(' p_oipl_rec.oipl_id '||p_oipl_rec.oipl_id ,110);
743         --hr_utility.set_location(' p_oipl_rec.dflt_enrt_cd '||p_oipl_rec.dflt_enrt_cd ,110);
744         --hr_utility.set_location(' p_oipl_rec.dflt_flag '||p_oipl_rec.dflt_flag, 110)  ;
745         --
746       if l_dflt_enrt_cd is not null
747          and p_level is null then -- 3510229
748         p_level:='OIPL';
749       end if;
750       --
751       END IF;*/
752     END IF;
753 
754     IF     p_pgm_id IS NULL
755        AND l_dflt_enrt_cd IS NULL THEN
756       --
757       -- 2
758       --
759       OPEN c_ler_pl_nip_dflt_cd;
760       FETCH c_ler_pl_nip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl,l_ler_dflt_flag; --3510229
761                                     --p_ler_dflt_flag;
762       CLOSE c_ler_pl_nip_dflt_cd;
763       if l_dflt_enrt_cd is not null
764          and p_level is null then -- 3510229
765         p_level:='LER_PL_NIP';
766         -- 3510229 start
767         -- there could be default flag without default code , so this s moved down - 	4008380
768         --if p_ler_dflt_flag is null then
769         --  p_ler_dflt_flag := l_ler_dflt_flag;
770         --end if;
771         --l_ler_dflt_flag := null ;
772 	if g_debug then
773         hr_utility.set_location('after LER pNip chk p_ler_dflt_flag:  '||p_ler_dflt_flag , 100);
774 	end if;
775         -- 3510229 end
776 
777       end if;
778       -- there could be default flag without default code 4008380
779       if p_ler_dflt_flag is null and l_ler_dflt_flag is not null  then
780           p_ler_dflt_flag := l_ler_dflt_flag ;
781       end if ;
782       if g_debug then
783       hr_utility.set_location('l_ler_dflt_flag ' || l_ler_dflt_flag ,40);
784       hr_utility.set_location(l_dflt_enrt_cd,40);
785       end if;
786 
787     ELSIF     p_pgm_id IS NOT NULL
788           AND l_dflt_enrt_cd IS NULL THEN
789       --
790       -- 3
791       --
792       OPEN c_ler_plip_dflt_cd;
793       FETCH c_ler_plip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl, l_ler_dflt_flag; --3510229
794                                     --p_ler_dflt_flag;
795       CLOSE c_ler_plip_dflt_cd;
796       if l_dflt_enrt_cd is not null
797          and p_level is null then -- 3510229
798         p_level:='LER_PLIP';
799 
800         -- 3510229 start
801         --  4008380
802         --if p_ler_dflt_flag is null then
803         --  p_ler_dflt_flag := l_ler_dflt_flag;
804         --end if;
805 	if g_debug then
806         hr_utility.set_location('after LER PLIP chk p_ler_dflt_flag:  '||p_ler_dflt_flag , 100);
807 	end if;
808         --l_ler_dflt_flag := null ;
809         -- 3510229 end
810 
811       end if;
812       --  4008380
813       if p_ler_dflt_flag is null and l_ler_dflt_flag is not null  then
814           p_ler_dflt_flag := l_ler_dflt_flag ;
815       end if ;
816       if g_debug then
817       hr_utility.set_location('l_ler_dflt_flag ' || l_ler_dflt_flag ,50);
818       hr_utility.set_location(l_dflt_enrt_cd,50);
819       end if;
820       --  4008380
821       --  there could be plip but the setup may be in plan  ler level
822       IF l_dflt_enrt_cd IS NULL THEN
823 
824          OPEN c_ler_pl_nip_dflt_cd;
825          FETCH c_ler_pl_nip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl,l_ler_dflt_flag;
826          CLOSE c_ler_pl_nip_dflt_cd;
827 
828          if l_dflt_enrt_cd is not null
829             and p_level is null then -- 3510229
830             p_level:='LER_PL';
831          if g_debug then
832             hr_utility.set_location('after LER Plan  chk p_ler_dflt_flag:  '||p_ler_dflt_flag , 100);
833          end if;
834          end if;
835          -- there could be default flag without default code 4008380
836          if p_ler_dflt_flag is null and l_ler_dflt_flag is not null  then
837             p_ler_dflt_flag := l_ler_dflt_flag ;
838          end if ;
839 	 if g_debug then
840          hr_utility.set_location('l_ler_dflt_flag ' || l_ler_dflt_flag ,40);
841          hr_utility.set_location(l_dflt_enrt_cd,40);
842 	 end if;
843       end if ;
844 
845 
846 
847       --- ptip level
848       IF l_dflt_enrt_cd IS NULL THEN
849         --
850         -- 4
851         --
852         OPEN c_ler_ptip_dflt_cd;
853         FETCH c_ler_ptip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
854         CLOSE c_ler_ptip_dflt_cd;
855       if l_dflt_enrt_cd is not null
856          and p_level is null then -- 3510229
857         p_level:='LER_PTIP';
858       end if;
859         --  hr_utility.set_location(l_dflt_enrt_cd,60);
860         IF l_dflt_enrt_cd IS NULL THEN
861           --
862           -- 5
863           --
864           OPEN c_ler_pgm_dflt_cd;
865           FETCH c_ler_pgm_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
866           CLOSE c_ler_pgm_dflt_cd;
867       if l_dflt_enrt_cd is not null
868          and p_level is null then --3510229
869         p_level:='LER_PTIP'; --Bug 6281735
870       end if;
871         END IF;
872       END IF;
873     END IF;
874 --Start Bug 6061856
875 --Default Codes LER override OIPL Level
876     if p_oipl_id is not null then
877       IF l_dflt_enrt_cd IS NULL THEN
878         --
879         -- 6
880         --
881         hr_utility.set_location('In the case 2 ' , 100);
882         --
883         --l_dflt_enrt_cd :=  ben_cobj_cache.g_oipl_currow.dflt_enrt_cd;
884         --l_dflt_enrt_rl :=  ben_cobj_cache.g_oipl_currow.dflt_enrt_det_rl;
885         --
886         l_dflt_enrt_cd := p_oipl_rec.dflt_enrt_cd ;
887         l_dflt_enrt_rl := p_oipl_rec.dflt_enrt_det_rl ;
888 
889         --hr_utility.set_location(' p_oipl_rec.oipl_id '||p_oipl_rec.oipl_id ,110);
890         --hr_utility.set_location(' p_oipl_rec.dflt_enrt_cd '||p_oipl_rec.dflt_enrt_cd ,110);
891         --hr_utility.set_location(' p_oipl_rec.dflt_flag '||p_oipl_rec.dflt_flag, 110)  ;
892         --
893       if l_dflt_enrt_cd is not null
894          and p_level is null then -- 3510229
895         p_level:='OIPL';
896       end if;
897       --
898       END IF;
899      end if;
900 --End Bug 6061856
901 
902     --  hr_utility.set_location(l_dflt_enrt_cd,80);
903     IF     p_pgm_id IS NULL
904        AND l_dflt_enrt_cd IS NULL THEN
905       --
906       -- 7
907       --
908       -- Bug 1895874
909       -- l_dflt_enrt_cd :=  ben_cobj_cache.g_pl_currow.nip_dflt_enrt_cd;
910       -- l_dflt_enrt_rl :=  ben_cobj_cache.g_pl_currow.nip_dflt_enrt_det_rl;
911       --
912       if g_debug then
913       hr_utility.set_location(' p_pl_rec.pl_id '||p_oipl_rec.oipl_id ,110);
914       hr_utility.set_location(' p_pl_rec.nip_dflt_enrt_cd '||p_pl_rec.nip_dflt_enrt_cd ,110);
915       hr_utility.set_location(' p_pl_rec.nip_dflt_flag '||p_pl_rec.nip_dflt_flag, 110)  ;
916       end if;
917       --
918       l_dflt_enrt_cd := p_pl_rec.nip_dflt_enrt_cd ;
919       l_dflt_enrt_rl := p_pl_rec.nip_dflt_enrt_det_rl ;
920       if p_ler_dflt_flag is null then -- 3510229
921         p_ler_dflt_flag := p_pl_rec.nip_dflt_flag ;
922       end if;
923 
924 /*
925       OPEN c_pl_nip_dflt_cd;
926       FETCH c_pl_nip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl,
927                                     p_ler_dflt_flag;
928       CLOSE c_pl_nip_dflt_cd;
929 */
930       --
931       if l_dflt_enrt_cd is not null
932          and p_level is null then -- 3510229
933         p_level:='PL';
934       end if;
935       --
936     --  hr_utility.set_location(l_dflt_enrt_cd,90);
937 
938     ELSIF     p_pgm_id IS NOT NULL
939           AND l_dflt_enrt_cd IS NULL THEN
940       --
941       -- 8
942       --
943       l_dflt_enrt_cd := p_plip_rec.dflt_enrt_cd ;
944       l_dflt_enrt_rl := p_plip_rec.dflt_enrt_det_rl ;
945 /*
946       OPEN c_plip_dflt_cd;
947       FETCH c_plip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
948       CLOSE c_plip_dflt_cd;
949 */
950       if l_dflt_enrt_cd is not null
951          and p_level is null then -- 3510229
952         p_level:='PLIP';
953       end if;
954        if g_debug then
955        hr_utility.set_location(l_dflt_enrt_cd,100);
956        end if;
957         --
958       IF l_dflt_enrt_cd IS NULL THEN
959         --
960         -- 9
961         --
962       l_dflt_enrt_cd := p_ptip_rec.dflt_enrt_cd ;
963       l_dflt_enrt_rl := p_ptip_rec.dflt_enrt_det_rl ;
964 /*
965         OPEN c_ptip_dflt_cd;
966         FETCH c_ptip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
967         CLOSE c_ptip_dflt_cd;
968 */
969       if l_dflt_enrt_cd is not null
970          and p_level is null then -- 3510229
971         p_level:='PTIP';
972       end if;
973       if g_debug then
974       hr_utility.set_location(l_dflt_enrt_cd,110);
975       end if;
976         --
977       END IF;
978     END IF;
979   --
980    if g_debug then
981     hr_utility.set_location(' p_pgm_id '||p_pgm_id||' pl_id '||p_pl_id||' oipl '||p_oipl_id||
982                             ' plip '||p_plip_id||' ptip '||p_ptip_id,130);
983     hr_utility.set_location('dflt_enrt_cd= '||l_dflt_enrt_cd,130);
984     hr_utility.set_location('dflt_enrt_rl= '||l_dflt_enrt_rl,140);
985     hr_utility.set_location('p_ler_dflt_flag= '||p_ler_dflt_flag ,140);
986    end if;
987     p_dflt_enrt_cd :=  l_dflt_enrt_cd;
988     p_dflt_enrt_rl :=  l_dflt_enrt_rl;
989     if g_debug then
990     hr_utility.set_location('Leaving: ' || l_proc, 150);
991     end if;
992   exception
993     --
994     when others then
995       --
996       p_dflt_enrt_cd        := null;
997       p_dflt_enrt_rl        := null;
998       p_level               := null;
999       p_ler_dflt_flag       := null;
1000       raise;
1001       --
1002   END;
1003 -- end internal determine_dflt_enrt_cd
1004   PROCEDURE determine_ben_settings(
1005     p_pl_id                     IN     ben_ler_chg_pl_nip_enrt_f.pl_id%TYPE,
1006     p_ler_id                    IN     ben_ler_chg_pl_nip_enrt_f.ler_id%TYPE,
1007     p_lf_evt_ocrd_dt            IN     DATE,
1008     p_ptip_id                   IN     ben_ler_chg_ptip_enrt_f.ptip_id%TYPE,
1009     p_pgm_id                    IN     ben_ler_chg_pgm_enrt_f.pgm_id%TYPE,
1010     p_plip_id                   IN     ben_ler_chg_plip_enrt_f.plip_id%TYPE,
1011     p_oipl_id                   IN     ben_ler_chg_oipl_enrt_f.oipl_id%TYPE,
1012     p_just_prclds_chg_flag      IN     BOOLEAN DEFAULT FALSE,
1013     p_enrt_cd                   OUT NOCOPY    ben_ler_chg_oipl_enrt_f.enrt_cd%TYPE,
1014     p_enrt_rl                   OUT NOCOPY    ben_ler_chg_oipl_enrt_f.enrt_rl%TYPE,
1015     p_auto_enrt_mthd_rl         OUT NOCOPY    ben_ler_chg_oipl_enrt_f.auto_enrt_mthd_rl%TYPE,
1016     p_crnt_enrt_prclds_chg_flag OUT NOCOPY    ben_ler_chg_oipl_enrt_f.crnt_enrt_prclds_chg_flag%TYPE,
1017     p_dflt_flag                 OUT NOCOPY    ben_ler_chg_oipl_enrt_f.dflt_flag%TYPE,
1018     p_enrt_mthd_cd              OUT NOCOPY    ben_ler_chg_pgm_enrt_f.enrt_mthd_cd%TYPE,
1019     p_stl_elig_cant_chg_flag    OUT NOCOPY    ben_ler_chg_oipl_enrt_f.stl_elig_cant_chg_flag%TYPE,
1020     p_tco_chg_enrt_cd           OUT NOCOPY    ben_ler_chg_ptip_enrt_f.tco_chg_enrt_cd%TYPE,
1021     p_ler_chg_oipl_found_flag   OUT NOCOPY    VARCHAR2,
1022     p_ler_chg_found_flag        OUT NOCOPY    VARCHAR2,
1023     p_enrt_cd_level             OUT NOCOPY    VARCHAR2 ) IS
1024     -- ========================
1025     -- define the local cursors
1026     -- ========================
1027     -- Bug 5029028: Added UNIONs for all cursors to select the codes from respective
1028     -- tables if ler_chg records not defined.
1029    -- ssarkar 5491475 : roll back 5029028
1030     CURSOR csr_oipl IS
1031       SELECT   oipl.auto_enrt_flag,
1032                oipl.auto_enrt_mthd_rl,
1033                oipl.crnt_enrt_prclds_chg_flag,
1034                oipl.dflt_flag,
1035                oipl.enrt_cd,
1036                oipl.enrt_rl,
1037                oipl.ler_chg_oipl_enrt_id,
1038                oipl.stl_elig_cant_chg_flag
1039       FROM     ben_ler_chg_oipl_enrt_f oipl
1040       WHERE    oipl.oipl_id = p_oipl_id
1041       AND      oipl.ler_id = p_ler_id
1042       AND      p_lf_evt_ocrd_dt BETWEEN oipl.effective_start_date
1043                    AND oipl.effective_end_date;
1044     --
1045     CURSOR csr_pgm IS
1046       SELECT   pgm.auto_enrt_mthd_rl,
1047                pgm.crnt_enrt_prclds_chg_flag,
1048                pgm.enrt_cd,
1049                pgm.enrt_mthd_cd,
1050                pgm.enrt_rl,
1051                pgm.ler_chg_pgm_enrt_id,
1052                pgm.stl_elig_cant_chg_flag
1053       FROM     ben_ler_chg_pgm_enrt_f pgm
1054       WHERE    pgm.pgm_id = p_pgm_id
1055       AND      pgm.ler_id = p_ler_id
1056       AND      p_lf_evt_ocrd_dt BETWEEN pgm.effective_start_date
1057                    AND pgm.effective_end_date;
1058     --
1059     CURSOR csr_ptip IS
1060       SELECT   ptip.crnt_enrt_prclds_chg_flag,
1061                ptip.enrt_cd,
1062                ptip.enrt_mthd_cd,
1063                ptip.enrt_rl,
1064                ptip.ler_chg_ptip_enrt_id,
1065                ptip.stl_elig_cant_chg_flag,
1066                ptip.tco_chg_enrt_cd
1067       FROM     ben_ler_chg_ptip_enrt_f ptip
1068       WHERE    ptip.ptip_id = p_ptip_id
1069       AND      ptip.ler_id = p_ler_id
1070       AND      p_lf_evt_ocrd_dt BETWEEN ptip.effective_start_date
1071                    AND ptip.effective_end_date;
1072     --
1073     CURSOR csr_plip IS
1074       SELECT   plip.auto_enrt_mthd_rl,
1075                plip.crnt_enrt_prclds_chg_flag,
1076                plip.dflt_flag,
1077                plip.enrt_cd,
1078                plip.enrt_mthd_cd,
1079                plip.enrt_rl,
1080                plip.ler_chg_plip_enrt_id,
1081                plip.stl_elig_cant_chg_flag,
1082                plip.tco_chg_enrt_cd
1083       FROM     ben_ler_chg_plip_enrt_f plip
1084       WHERE    plip.plip_id = p_plip_id
1085       AND      plip.ler_id = p_ler_id
1086       AND      p_lf_evt_ocrd_dt BETWEEN plip.effective_start_date
1087                    AND plip.effective_end_date;
1088     --
1089     CURSOR csr_pl_nip IS
1090       SELECT   pl_nip.auto_enrt_mthd_rl,
1091                pl_nip.crnt_enrt_prclds_chg_flag,
1092                pl_nip.dflt_flag,
1093                pl_nip.enrt_cd,
1094                pl_nip.enrt_mthd_cd,
1095                pl_nip.enrt_rl,
1096                pl_nip.ler_chg_pl_nip_enrt_id,
1097                pl_nip.stl_elig_cant_chg_flag,
1098                pl_nip.tco_chg_enrt_cd
1099       FROM     ben_ler_chg_pl_nip_enrt_f pl_nip
1100       WHERE    pl_nip.pl_id = p_pl_id
1101       AND      pl_nip.ler_id = p_ler_id
1102       AND      p_lf_evt_ocrd_dt BETWEEN pl_nip.effective_start_date
1103                    AND pl_nip.effective_end_date;
1104     -- ======================
1105     -- define local variables
1106     -- ======================
1107     oipl_auto_enrt_flag            ben_ler_chg_oipl_enrt_f.auto_enrt_flag%TYPE;
1108     oipl_auto_enrt_mthd_rl         ben_ler_chg_oipl_enrt_f.auto_enrt_mthd_rl%TYPE;
1109     oipl_crnt_enrt_prclds_chg_flag ben_ler_chg_oipl_enrt_f.crnt_enrt_prclds_chg_flag%TYPE;
1110     oipl_dflt_flag                 ben_ler_chg_oipl_enrt_f.dflt_flag%TYPE;
1111     oipl_enrt_cd                   ben_ler_chg_oipl_enrt_f.enrt_cd%TYPE;
1112     oipl_enrt_rl                   ben_ler_chg_oipl_enrt_f.enrt_rl%TYPE;
1113     oipl_ler_chg_oipl_enrt_id      ben_ler_chg_oipl_enrt_f.ler_chg_oipl_enrt_id%TYPE;
1114     oipl_stl_elig_cant_chg_flag    ben_ler_chg_oipl_enrt_f.stl_elig_cant_chg_flag%TYPE;
1115     pgm_auto_enrt_mthd_rl          ben_ler_chg_pgm_enrt_f.auto_enrt_mthd_rl%TYPE;
1116     pgm_crnt_enrt_prclds_chg_flag  ben_ler_chg_pgm_enrt_f.crnt_enrt_prclds_chg_flag%TYPE;
1117     pgm_enrt_cd                    ben_ler_chg_pgm_enrt_f.enrt_cd%TYPE;
1118     pgm_enrt_mthd_cd               ben_ler_chg_pgm_enrt_f.enrt_mthd_cd%TYPE;
1119     pgm_enrt_rl                    ben_ler_chg_pgm_enrt_f.enrt_rl%TYPE;
1120     pgm_ler_chg_pgm_enrt_id        ben_ler_chg_pgm_enrt_f.ler_chg_pgm_enrt_id%TYPE;
1121     pgm_stl_elig_cant_chg_flag     ben_ler_chg_pgm_enrt_f.stl_elig_cant_chg_flag%TYPE;
1122     pnip_auto_enrt_mthd_rl         ben_ler_chg_pl_nip_enrt_f.auto_enrt_mthd_rl%TYPE;
1123     pnip_crnt_enrt_prclds_chg_flag ben_ler_chg_pl_nip_enrt_f.crnt_enrt_prclds_chg_flag%TYPE;
1124     pnip_dflt_flag                 ben_ler_chg_pl_nip_enrt_f.dflt_flag%TYPE;
1125     pnip_enrt_cd                   ben_ler_chg_pl_nip_enrt_f.enrt_cd%TYPE;
1126     pnip_enrt_mthd_cd              ben_ler_chg_pl_nip_enrt_f.enrt_mthd_cd%TYPE;
1127     pnip_enrt_rl                   ben_ler_chg_pl_nip_enrt_f.enrt_rl%TYPE;
1128     pnip_ler_chg_pnip_enrt_id      ben_ler_chg_pl_nip_enrt_f.ler_chg_pl_nip_enrt_id%TYPE;
1129     pnip_stl_elig_cant_chg_flag    ben_ler_chg_pl_nip_enrt_f.stl_elig_cant_chg_flag%TYPE;
1130     pnip_tco_chg_enrt_cd           ben_ler_chg_pl_nip_enrt_f.tco_chg_enrt_cd%TYPE;
1131     plip_auto_enrt_mthd_rl         ben_ler_chg_plip_enrt_f.auto_enrt_mthd_rl%TYPE;
1132     plip_crnt_enrt_prclds_chg_flag ben_ler_chg_plip_enrt_f.crnt_enrt_prclds_chg_flag%TYPE;
1133     plip_dflt_flag                 ben_ler_chg_plip_enrt_f.dflt_flag%TYPE;
1134     plip_enrt_cd                   ben_ler_chg_plip_enrt_f.enrt_cd%TYPE;
1135     plip_enrt_mthd_cd              ben_ler_chg_plip_enrt_f.enrt_mthd_cd%TYPE;
1136     plip_enrt_rl                   ben_ler_chg_plip_enrt_f.enrt_rl%TYPE;
1137     plip_ler_chg_plip_enrt_id      ben_ler_chg_plip_enrt_f.ler_chg_plip_enrt_id%TYPE;
1138     plip_stl_elig_cant_chg_flag    ben_ler_chg_plip_enrt_f.stl_elig_cant_chg_flag%TYPE;
1139     plip_tco_chg_enrt_cd           ben_ler_chg_plip_enrt_f.tco_chg_enrt_cd%TYPE;
1140     ptip_crnt_enrt_prclds_chg_flag ben_ler_chg_ptip_enrt_f.crnt_enrt_prclds_chg_flag%TYPE;
1141     ptip_enrt_cd                   ben_ler_chg_ptip_enrt_f.enrt_cd%TYPE;
1142     ptip_enrt_mthd_cd              ben_ler_chg_ptip_enrt_f.enrt_mthd_cd%TYPE;
1143     ptip_enrt_rl                   ben_ler_chg_ptip_enrt_f.enrt_rl%TYPE;
1144     ptip_ler_chg_ptip_enrt_id      ben_ler_chg_ptip_enrt_f.ler_chg_ptip_enrt_id%TYPE;
1145     ptip_stl_elig_cant_chg_flag    ben_ler_chg_ptip_enrt_f.stl_elig_cant_chg_flag%TYPE;
1146     ptip_tco_chg_enrt_cd           ben_ler_chg_ptip_enrt_f.tco_chg_enrt_cd%TYPE;
1147     l_temp                         number; -- 5029028
1148   BEGIN
1149   -- ============================================
1150   -- open,fetch and close each cursor if required
1151   -- ============================================
1152     IF p_ler_id IS NOT NULL THEN
1153       IF p_oipl_id IS NOT NULL THEN
1154         OPEN csr_oipl;
1155         FETCH csr_oipl INTO oipl_auto_enrt_flag,
1156                             oipl_auto_enrt_mthd_rl,
1157                             oipl_crnt_enrt_prclds_chg_flag,
1158                             oipl_dflt_flag,
1159                             oipl_enrt_cd,
1160                             oipl_enrt_rl,
1161                             oipl_ler_chg_oipl_enrt_id,
1162                             oipl_stl_elig_cant_chg_flag;
1163                             --l_temp;
1164         CLOSE csr_oipl;
1165       END IF;
1166       IF p_pl_id IS NOT NULL THEN
1167         OPEN csr_pl_nip;
1168         FETCH csr_pl_nip INTO pnip_auto_enrt_mthd_rl,
1169                               pnip_crnt_enrt_prclds_chg_flag,
1170                               pnip_dflt_flag,
1171                               pnip_enrt_cd,
1172                               pnip_enrt_mthd_cd,
1173                               pnip_enrt_rl,
1174                               pnip_ler_chg_pnip_enrt_id,
1175                               pnip_stl_elig_cant_chg_flag,
1176                               pnip_tco_chg_enrt_cd;
1177                               --l_temp;
1178         CLOSE csr_pl_nip;
1179       END IF;
1180       IF p_plip_id IS NOT NULL THEN
1181         OPEN csr_plip;
1182         FETCH csr_plip INTO plip_auto_enrt_mthd_rl,
1183                             plip_crnt_enrt_prclds_chg_flag,
1184                             plip_dflt_flag,
1185                             plip_enrt_cd,
1186                             plip_enrt_mthd_cd,
1187                             plip_enrt_rl,
1188                             plip_ler_chg_plip_enrt_id,
1189                             plip_stl_elig_cant_chg_flag,
1190                             plip_tco_chg_enrt_cd;
1191                             --l_temp;
1192         CLOSE csr_plip;
1193       END IF;
1194       IF p_ptip_id IS NOT NULL THEN
1195         OPEN csr_ptip;
1196         FETCH csr_ptip INTO ptip_crnt_enrt_prclds_chg_flag,
1197                             ptip_enrt_cd,
1198                             ptip_enrt_mthd_cd,
1199                             ptip_enrt_rl,
1200                             ptip_ler_chg_ptip_enrt_id,
1201                             ptip_stl_elig_cant_chg_flag,
1202                             ptip_tco_chg_enrt_cd;
1203                             --l_temp;
1204         CLOSE csr_ptip;
1205       END IF;
1206       IF p_pgm_id IS NOT NULL THEN
1207         OPEN csr_pgm;
1208         FETCH csr_pgm INTO pgm_auto_enrt_mthd_rl,
1209                            pgm_crnt_enrt_prclds_chg_flag,
1210                            pgm_enrt_cd,
1211                            pgm_enrt_mthd_cd,
1212                            pgm_enrt_rl,
1213                            pgm_ler_chg_pgm_enrt_id,
1214                            pgm_stl_elig_cant_chg_flag;
1215                            --l_temp;
1216         CLOSE csr_pgm;
1217       END IF;
1218       -- ==========================================
1219       -- determine and SET the OUT parameter values
1220       -- ==========================================
1221       -- --------------------------------
1222       -- set: p_crnt_enrt_prclds_chg_flag
1223       -- --------------------------------
1224       IF oipl_crnt_enrt_prclds_chg_flag IS NULL THEN
1225         IF pnip_crnt_enrt_prclds_chg_flag IS NULL THEN
1226           IF plip_crnt_enrt_prclds_chg_flag IS NULL THEN
1227             IF ptip_crnt_enrt_prclds_chg_flag IS NULL THEN
1228               p_crnt_enrt_prclds_chg_flag :=  pgm_crnt_enrt_prclds_chg_flag;
1229             ELSE
1230               p_crnt_enrt_prclds_chg_flag :=  ptip_crnt_enrt_prclds_chg_flag;
1231             END IF;
1232           ELSE
1233             p_crnt_enrt_prclds_chg_flag :=  plip_crnt_enrt_prclds_chg_flag;
1234           END IF;
1235         ELSE
1236           p_crnt_enrt_prclds_chg_flag :=  pnip_crnt_enrt_prclds_chg_flag;
1237         END IF;
1238       ELSE
1239         p_crnt_enrt_prclds_chg_flag :=  oipl_crnt_enrt_prclds_chg_flag;
1240       END IF;
1241       -- test to see if only the p_crnt_enrt_prclds_chg_flag is required
1242       --IF p_just_prclds_chg_flag THEN
1243       --  RETURN;
1244       --END IF;
1245       -- ----------------------------
1246       -- set: p_enrt_cd and p_enrt_rl
1247       -- ----------------------------
1248 
1249      ----
1250      hr_utility.set_location( 'oipl' || oipl_enrt_cd , 10) ;
1251      hr_utility.set_location( 'pl' || pnip_enrt_cd , 10) ;
1252      hr_utility.set_location( 'plip' || plip_enrt_cd , 10);
1253      hr_utility.set_location( 'ptip' || ptip_enrt_cd , 10) ;
1254 
1255 
1256 
1257      hr_utility.set_location( 'oipl id ' || p_oipl_id , 10) ;
1258      hr_utility.set_location( 'ptip id ' || p_ptip_id , 10) ;
1259      hr_utility.set_location( 'plip id ' || p_plip_id , 10) ;
1260      hr_utility.set_location( 'pl id   ' || p_pl_id   , 10) ;
1261      ---
1262 
1263 
1264       IF oipl_enrt_cd IS NULL THEN
1265         IF pnip_enrt_cd IS NULL THEN
1266           IF plip_enrt_cd IS NULL THEN
1267             IF ptip_enrt_cd IS NULL THEN
1268               p_enrt_cd      :=  pgm_enrt_cd;
1269               p_enrt_rl      :=  pgm_enrt_rl;
1270               p_enrt_cd_level:= 'PGM' ;
1271             ELSE
1272               p_enrt_cd :=  ptip_enrt_cd;
1273               p_enrt_rl :=  ptip_enrt_rl;
1274               p_enrt_cd_level := 'PTIP' ;
1275             END IF;
1276           ELSE
1277             p_enrt_cd :=  plip_enrt_cd;
1278             p_enrt_rl :=  plip_enrt_rl;
1279             p_enrt_cd_level := 'PLIP' ;
1280           END IF;
1281         ELSE
1282           p_enrt_cd :=  pnip_enrt_cd;
1283           p_enrt_rl :=  pnip_enrt_rl;
1284           p_enrt_cd_level := 'PL' ;
1285         END IF;
1286       ELSE
1287         p_enrt_cd :=  oipl_enrt_cd;
1288         p_enrt_rl :=  oipl_enrt_rl;
1289         p_enrt_cd_level := 'OIPL' ;
1290       END IF;
1291       hr_utility.set_location( 'p_enrt_cd_level  ' || p_enrt_cd_level , 10) ;
1292 
1293        IF p_just_prclds_chg_flag THEN
1294         RETURN;
1295       END IF;
1296 
1297 
1298 
1299       -- ------------------------
1300       -- set: p_auto_enrt_mthd_rl
1301       -- ------------------------
1302       IF oipl_auto_enrt_mthd_rl IS NULL THEN
1303         IF pnip_auto_enrt_mthd_rl IS NULL THEN
1304           IF plip_auto_enrt_mthd_rl IS NULL THEN
1305             p_auto_enrt_mthd_rl :=  pgm_auto_enrt_mthd_rl;
1306           ELSE
1307             p_auto_enrt_mthd_rl :=  plip_auto_enrt_mthd_rl;
1308           END IF;
1309         ELSE
1310           p_auto_enrt_mthd_rl :=  pnip_auto_enrt_mthd_rl;
1311         END IF;
1312       ELSE
1313         p_auto_enrt_mthd_rl :=  oipl_auto_enrt_mthd_rl;
1314       END IF;
1315       -- ----------------
1316       -- set: p_dflt_flag
1317       -- ----------------
1318       IF oipl_dflt_flag IS NULL THEN
1319         IF pnip_dflt_flag IS NULL THEN
1320           p_dflt_flag :=  plip_dflt_flag;
1321         ELSE
1322           p_dflt_flag :=  pnip_dflt_flag;
1323         END IF;
1324       ELSE
1325         p_dflt_flag :=  oipl_dflt_flag;
1326       END IF;
1327       -- -------------------
1328       -- set: p_enrt_mthd_cd
1329       -- -------------------
1330       IF oipl_auto_enrt_flag = 'Y' THEN
1331         p_enrt_mthd_cd :=  'A';
1332       ELSIF oipl_auto_enrt_flag = 'N' THEN
1333         p_enrt_mthd_cd :=  'E';
1334       ELSE
1335         IF pnip_enrt_mthd_cd IS NULL THEN
1336           IF plip_enrt_mthd_cd IS NULL THEN
1337             IF ptip_enrt_mthd_cd IS NULL THEN
1338               p_enrt_mthd_cd :=  pgm_enrt_mthd_cd;
1339             ELSE
1340               p_enrt_mthd_cd :=  ptip_enrt_mthd_cd;
1341             END IF;
1342           ELSE
1343             p_enrt_mthd_cd :=  plip_enrt_mthd_cd;
1344           END IF;
1345         ELSE
1346           p_enrt_mthd_cd :=  pnip_enrt_mthd_cd;
1347         END IF;
1348       END IF;
1349       -- -----------------------------
1350       -- set: p_stl_elig_cant_chg_flag
1351       -- -----------------------------
1352       IF oipl_stl_elig_cant_chg_flag IS NULL THEN
1353         IF pnip_stl_elig_cant_chg_flag IS NULL THEN
1354           IF plip_stl_elig_cant_chg_flag IS NULL THEN
1355             IF ptip_stl_elig_cant_chg_flag IS NULL THEN
1356               p_stl_elig_cant_chg_flag :=  pgm_stl_elig_cant_chg_flag;
1357             ELSE
1358               p_stl_elig_cant_chg_flag :=  ptip_stl_elig_cant_chg_flag;
1359             END IF;
1360           ELSE
1361             p_stl_elig_cant_chg_flag :=  plip_stl_elig_cant_chg_flag;
1362           END IF;
1363         ELSE
1364           p_stl_elig_cant_chg_flag :=  pnip_stl_elig_cant_chg_flag;
1365         END IF;
1366       ELSE
1367         p_stl_elig_cant_chg_flag :=  oipl_stl_elig_cant_chg_flag;
1368       END IF;
1369       -- ----------------------
1370       -- set: p_tco_chg_enrt_cd
1371       -- ----------------------
1372       IF pnip_tco_chg_enrt_cd IS NULL THEN
1373         IF plip_tco_chg_enrt_cd IS NULL THEN
1374           p_tco_chg_enrt_cd :=  ptip_tco_chg_enrt_cd;
1375         ELSE
1376           p_tco_chg_enrt_cd :=  plip_tco_chg_enrt_cd;
1377         END IF;
1378       ELSE
1379         p_tco_chg_enrt_cd :=  pnip_tco_chg_enrt_cd;
1380       END IF;
1381       -- -------------------------------------------------------
1382       -- set: p_ler_chg_oipl_found_flag and p_ler_chg_found_flag
1383       -- -------------------------------------------------------
1384       IF oipl_ler_chg_oipl_enrt_id IS NULL THEN
1385         p_ler_chg_oipl_found_flag :=  'N';
1386         IF     plip_ler_chg_plip_enrt_id IS NULL
1387            AND ptip_ler_chg_ptip_enrt_id IS NULL
1388            AND pnip_ler_chg_pnip_enrt_id IS NULL
1389            AND pgm_ler_chg_pgm_enrt_id IS NULL THEN
1390           p_ler_chg_found_flag :=  'N';
1391         ELSE
1392           p_ler_chg_found_flag :=  'Y';
1393         END IF;
1394       ELSE
1395         p_ler_chg_oipl_found_flag :=  'Y';
1396         p_ler_chg_found_flag :=       'Y';
1397       END IF;
1398     END IF;
1399     hr_utility.set_location( 'p_enrt_cd_level  ' || p_enrt_cd_level , 10) ;
1400   exception
1401     --
1402     when others then
1403       --
1404       p_enrt_cd                   := null;
1405       p_enrt_rl                   := null;
1406       p_auto_enrt_mthd_rl         := null;
1407       p_crnt_enrt_prclds_chg_flag := null;
1408       p_dflt_flag                 := null;
1409       p_enrt_mthd_cd              := null;
1410       p_stl_elig_cant_chg_flag    := null;
1411       p_tco_chg_enrt_cd           := null;
1412       p_ler_chg_oipl_found_flag   := null;
1413       p_ler_chg_found_flag        := null;
1414       raise;
1415       --
1416   END determine_ben_settings;
1417   --
1418   PROCEDURE determine_enrolment(
1419     p_previous_eligibility       VARCHAR2,
1420     p_crnt_enrt_cvg_strt_dt      DATE,
1421     p_dpnt_cvrd_flag             VARCHAR2,
1422     p_enrt_cd                    VARCHAR2,
1423     p_enrt_rl                    NUMBER,
1424     p_enrt_mthd_cd               VARCHAR2,
1425     p_auto_enrt_mthd_rl          NUMBER,
1426     p_effective_date             DATE,
1427     p_lf_evt_ocrd_dt             DATE DEFAULT NULL,
1428     p_elig_per_id                NUMBER DEFAULT NULL,
1429     p_enrt_prclds_chg_flag       VARCHAR2 DEFAULT 'N',
1430     p_stl_elig_cant_chg_flag     VARCHAR2 DEFAULT 'N',
1431     p_tco_chg_enrt_cd            VARCHAR2 DEFAULT 'CPOO',
1432     p_pl_id                      NUMBER,
1433     p_pgm_id                     NUMBER,
1434     p_oipl_id                    NUMBER,
1435     p_opt_id                     NUMBER,
1436     p_pl_typ_id                  NUMBER,
1437     p_person_id                  NUMBER,
1438     p_ler_id                     NUMBER,
1439     p_business_group_id          NUMBER,
1440     p_electable_flag         OUT NOCOPY VARCHAR2,
1441     p_assignment_id              NUMBER,
1442     p_run_mode                   varchar2 default null,  /* iRec : Added p_run_mode */
1443     p_update_def_elct_flag       varchar2) IS
1444     --
1445     l_proc                     VARCHAR2(80)
1446                                           := g_package ||
1447                                                '.determine_enrolment';
1448     --
1449     l_result_flag              VARCHAR2(30);
1450     l_crnt_pl_enrt_cvg_strt_dt DATE;
1451     l_crnt_opt_cvg_strt_dt     DATE;
1452     l_pgm_rec                  ben_pgm_f%ROWTYPE;
1453     l_jurisdiction_code        VARCHAR2(30);
1454     --
1455     l_lf_evt_ocrd_dt           DATE := NVL(p_lf_evt_ocrd_dt, p_effective_date);
1456     l_lf_evt_ocrd_dt_1         DATE                     := l_lf_evt_ocrd_dt -
1457                                                              1;
1458     l_enrt_cd                  ben_ler_chg_oipl_enrt_f.enrt_cd%TYPE;
1459     l_enrt_rl                  ben_ler_chg_oipl_enrt_f.enrt_rl%TYPE;
1460     l_auto_enrt_mthd_rl        ben_ler_chg_oipl_enrt_f.auto_enrt_mthd_rl%TYPE;
1461     l_dflt_flag                ben_ler_chg_oipl_enrt_f.dflt_flag%TYPE;
1462     l_enrt_mthd_cd             ben_ler_chg_pgm_enrt_f.enrt_mthd_cd%TYPE;
1463     l_stl_elig_cant_chg_flag   ben_ler_chg_oipl_enrt_f.stl_elig_cant_chg_flag%TYPE;
1464     l_tco_chg_enrt_cd          ben_ler_chg_ptip_enrt_f.tco_chg_enrt_cd%TYPE;
1465     l_ler_chg_oipl_found_flag  VARCHAR2(30);
1466     l_ler_chg_found_flag       VARCHAR2(30);
1467     --
1468     -- Gets the enrollments in the ptip and option
1469     --
1470     -- --
1471     CURSOR c_enrolled_opts_in_pl_typ IS
1472       SELECT   pen.enrt_cvg_strt_dt enrt_cvg_strt_dt
1473       FROM     ben_prtt_enrt_rslt_f pen, ben_pl_f pl, ben_oipl_f oipl
1474       WHERE    pen.person_id = p_person_id
1475       AND      pen.business_group_id = p_business_group_id
1476       AND      pen.effective_end_date = hr_api.g_eot
1477       AND      l_lf_evt_ocrd_dt_1 BETWEEN pen.enrt_cvg_strt_dt
1478                    AND pen.enrt_cvg_thru_dt
1479       AND      pl.pl_id = pen.pl_id
1480       AND      pl.business_group_id = p_business_group_id
1481       AND      pl.pl_typ_id = p_pl_typ_id
1482       AND      oipl.oipl_id = pen.oipl_id
1483       AND      oipl.opt_id = p_opt_id
1484       AND      l_lf_evt_ocrd_dt BETWEEN pl.effective_start_date
1485                    AND pl.effective_end_date
1486       AND      l_lf_evt_ocrd_dt BETWEEN oipl.effective_start_date
1487                    AND oipl.effective_end_date
1488       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
1489       AND      pen.sspndd_flag = 'N'
1490       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
1491       AND      oipl.business_group_id = p_business_group_id
1492       AND      (
1493                     (    pen.pgm_id = p_pgm_id
1494                      AND p_pgm_id IS NOT NULL)
1495                  OR (    pen.pgm_id IS NULL
1496                      AND p_pgm_id IS NULL));
1497     --
1498     -- Gets the enrollments in the ptip and option
1499     --
1500     --
1501     CURSOR c_cvrd_opts_in_pl_typ IS
1502       SELECT   pen.enrt_cvg_strt_dt enrt_cvg_strt_dt
1503       FROM     ben_prtt_enrt_rslt_f pen,
1504                ben_pl_f pl,
1505                ben_oipl_f oipl,
1506                ben_elig_cvrd_dpnt_f pdp
1507       WHERE    pdp.dpnt_person_id = p_person_id
1508       AND      l_lf_evt_ocrd_dt_1 BETWEEN pdp.cvg_strt_dt AND pdp.cvg_thru_dt
1509       AND      pen.effective_end_date = hr_api.g_eot
1510       AND      pdp.effective_end_date = hr_api.g_eot
1511       AND      pdp.business_group_id = p_business_group_id
1512       AND      pdp.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
1513       AND      pen.business_group_id = p_business_group_id
1514       AND      l_lf_evt_ocrd_dt_1 BETWEEN pen.enrt_cvg_strt_dt
1515                    AND pen.enrt_cvg_thru_dt
1516       AND      pl.pl_id = pen.pl_id
1517       AND      pl.business_group_id = p_business_group_id
1518       AND      pl.pl_typ_id = p_pl_typ_id
1519       AND      oipl.oipl_id = pen.oipl_id
1520       AND      oipl.opt_id = p_opt_id
1521       AND      l_lf_evt_ocrd_dt BETWEEN pl.effective_start_date
1522                    AND pl.effective_end_date
1523       AND      l_lf_evt_ocrd_dt BETWEEN oipl.effective_start_date
1524                    AND oipl.effective_end_date
1525       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
1526       AND      pen.sspndd_flag = 'N'
1527       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
1528       AND      oipl.business_group_id = p_business_group_id
1529       AND      (
1530                     (    pen.pgm_id = p_pgm_id
1531                      AND p_pgm_id IS NOT NULL)
1532                  OR (    pen.pgm_id IS NULL
1533                      AND p_pgm_id IS NULL));
1534     --
1535     --
1536     CURSOR c_state IS
1537       SELECT   loc.region_2
1538       FROM     hr_locations_all loc, per_all_assignments_f asg
1539       WHERE    loc.location_id = asg.location_id
1540       AND      asg.person_id = p_person_id
1541       and      asg.assignment_type <> 'C'
1542       AND      asg.primary_flag = 'Y'
1543       AND      l_lf_evt_ocrd_dt BETWEEN asg.effective_start_date
1544                    AND asg.effective_end_date
1545       AND      asg.business_group_id = p_business_group_id;
1546     --
1547     l_state                    c_state%ROWTYPE;
1548     --
1549     --
1550     CURSOR c_asg IS
1551       SELECT   asg.assignment_id,
1552                asg.organization_id
1553       FROM     per_all_assignments_f asg
1554       WHERE    person_id = p_person_id
1555       and      asg.assignment_type <> 'C'
1556       AND      asg.primary_flag = decode(p_run_mode, 'I',asg.primary_flag, 'Y')   -- iRec
1557       AND      l_lf_evt_ocrd_dt BETWEEN asg.effective_start_date
1558                    AND asg.effective_end_date;
1559     --
1560     l_asg                      c_asg%ROWTYPE;
1561     -- Gets the enrolment information for this plan
1562     --
1563     --
1564     CURSOR c_plan_enrolment_info IS
1565       SELECT   pen.enrt_cvg_strt_dt enrt_cvg_strt_dt
1566       FROM     ben_prtt_enrt_rslt_f pen
1567       WHERE    pen.person_id = p_person_id
1568       AND      pen.business_group_id = p_business_group_id
1569       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
1570 --      AND      pen.sspndd_flag = 'N' --CFW
1571       AND      (pen.sspndd_flag = 'N' --CFW
1572                  OR (pen.sspndd_flag = 'Y' and
1573                      pen.enrt_cvg_thru_dt = hr_api.g_eot
1574                     )
1575                )
1576       AND      pen.effective_end_date = hr_api.g_eot
1577       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
1578       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
1579       AND      p_pl_id = pen.pl_id
1580       AND      (
1581                     (    pen.pgm_id = p_pgm_id
1582                      AND p_pgm_id IS NOT NULL)
1583                  OR (    pen.pgm_id IS NULL
1584                      AND p_pgm_id IS NULL));
1585 
1586     -- added for level
1587 
1588      CURSOR c_plip_enrolment_info IS
1589       SELECT   pen.enrt_cvg_strt_dt enrt_cvg_strt_dt
1590       FROM     ben_prtt_enrt_rslt_f pen
1591       WHERE    pen.person_id = p_person_id
1592       AND      pen.business_group_id = p_business_group_id
1593       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
1594 --      AND      pen.sspndd_flag = 'N' --CFW
1595       AND      (pen.sspndd_flag = 'N' --CFW
1596                  OR (pen.sspndd_flag = 'Y' and
1597                      pen.enrt_cvg_thru_dt = hr_api.g_eot
1598                     )
1599                )
1600       AND      pen.effective_end_date = hr_api.g_eot
1601       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
1602       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
1603       AND      p_pl_id = pen.pl_id
1604       AND      pen.pgm_id = p_pgm_id ;
1605 
1606     --
1607 
1608      CURSOR c_ptip_2_enrolment_info IS
1609       SELECT   pen.enrt_cvg_strt_dt enrt_cvg_strt_dt
1610       FROM     ben_prtt_enrt_rslt_f pen
1611       WHERE    pen.person_id = p_person_id
1612       AND      pen.business_group_id = p_business_group_id
1613       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
1614       AND      pen.effective_end_date = hr_api.g_eot
1615       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
1616       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
1617       AND      g_ptip_id   = pen.ptip_id
1618       AND      pen.pgm_id = p_pgm_id ;
1619 
1620    ---
1621 
1622      CURSOR c_pgm_enrolment_info IS
1623       SELECT   pen.enrt_cvg_strt_dt enrt_cvg_strt_dt
1624       FROM     ben_prtt_enrt_rslt_f pen
1625       WHERE    pen.person_id = p_person_id
1626       AND      pen.business_group_id = p_business_group_id
1627       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
1628       AND      pen.effective_end_date = hr_api.g_eot
1629       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
1630       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
1631       AND      pen.pgm_id = p_pgm_id ;
1632 
1633 
1634     -- Bug#2108168 - Check for current enrollment in a waive plan
1635     CURSOR c_ptip_waive_enrolment_info IS
1636       SELECT   pen.enrt_cvg_strt_dt
1637       FROM     ben_prtt_enrt_rslt_f pen, ben_pl_f pln
1638       WHERE    pen.person_id = p_person_id
1639       AND      pen.business_group_id = p_business_group_id
1640       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
1641       AND      pen.sspndd_flag = 'N'
1642       AND      pen.effective_end_date = hr_api.g_eot
1643       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
1644       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
1645       AND      g_ptip_id = pen.ptip_id
1646       AND      pln.pl_id = pen.pl_id
1647       AND      pln.invk_dcln_prtn_pl_flag = 'Y'
1648       AND      l_lf_evt_ocrd_dt BETWEEN pln.effective_start_date
1649                    AND pln.effective_end_date;
1650 
1651     -- Gets the enrolment information for this plan
1652     --
1653     --
1654     CURSOR c_plan_cvg_info IS
1655       SELECT   pen.enrt_cvg_strt_dt enrt_cvg_strt_dt
1656       FROM     ben_prtt_enrt_rslt_f pen, ben_elig_cvrd_dpnt_f pdp
1657       WHERE    pdp.dpnt_person_id = p_person_id
1658       AND      pen.effective_end_date = hr_api.g_eot
1659       AND      pdp.effective_end_date = hr_api.g_eot
1660       AND      l_lf_evt_ocrd_dt_1 BETWEEN pdp.cvg_strt_dt AND pdp.cvg_thru_dt
1661       AND      pdp.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
1662       AND      pen.business_group_id = p_business_group_id
1663       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
1664       -- AND      pen.sspndd_flag = 'N'
1665       AND      (pen.sspndd_flag = 'N' --CFW
1666                  OR (pen.sspndd_flag = 'Y' and
1667                      pen.enrt_cvg_thru_dt = hr_api.g_eot
1668                     )
1669                )
1670       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
1671       AND      pen.enrt_cvg_thru_dt < pen.effective_end_date
1672       AND      p_pl_id = pen.pl_id
1673       AND      (
1674                     (    pen.pgm_id = p_pgm_id
1675                      AND p_pgm_id IS NOT NULL)
1676                  OR (    pen.pgm_id IS NULL
1677                      AND p_pgm_id IS NULL));
1678     --
1679     -- Gets the enrolment information for the ptip in which the plan belongs
1680     --
1681     CURSOR c_ptip_enrolment_info IS
1682       SELECT   pen.pl_id,
1683                pen.oipl_id,
1684                plip.plip_id
1685       FROM     ben_prtt_enrt_rslt_f pen, ben_plip_f plip
1686       WHERE    pen.person_id = p_person_id
1687       AND      pen.business_group_id = p_business_group_id
1688       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
1689       --AND      pen.sspndd_flag = 'N'
1690       AND      (pen.sspndd_flag = 'N' --CFW
1691                  OR (pen.sspndd_flag = 'Y' and
1692                      pen.enrt_cvg_thru_dt = hr_api.g_eot
1693                     )
1694                )
1695       AND      pen.effective_end_date = hr_api.g_eot
1696       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
1697       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
1698       AND      g_ptip_id = pen.ptip_id
1699       AND      plip.pgm_id = pen.pgm_id
1700       AND      plip.pl_id = pen.pl_id
1701       AND      l_lf_evt_ocrd_dt BETWEEN plip.effective_start_date
1702                    AND plip.effective_end_date;
1703     --
1704      CURSOR c_plip_info IS
1705       SELECT   bpf.plip_id
1706       FROM     ben_plip_f bpf
1707       WHERE    bpf.pl_id = p_pl_id
1708       AND      bpf.pgm_id = p_pgm_id
1709       AND      bpf.business_group_id = p_business_group_id
1710       AND      l_lf_evt_ocrd_dt BETWEEN bpf.effective_start_date
1711                    AND bpf.effective_end_date;
1712 
1713     --
1714     l_plip_id                  number ;
1715     l_enrolled_ptip            c_ptip_enrolment_info%ROWTYPE;
1716     --
1717     /*
1718     cursor c_prclds_flag
1719     is
1720     select
1721            nvl(oipl.crnt_enrt_prclds_chg_flag,
1722              nvl(pl_nip.crnt_enrt_prclds_chg_flag,
1723                nvl(plip.crnt_enrt_prclds_chg_flag,
1724                  nvl(ptip.crnt_enrt_prclds_chg_flag,
1725                      pgm.crnt_enrt_prclds_chg_flag)))) crnt_enrt_prclds_chg_flag
1726     from   dual,
1727            ben_ler_chg_pl_nip_enrt_f pl_nip,
1728            ben_ler_chg_pgm_enrt_f    pgm,
1729            ben_ler_chg_ptip_enrt_f   ptip,
1730            ben_ler_chg_plip_enrt_f   plip,
1731            ben_ler_chg_oipl_enrt_f   oipl
1732     where
1733            pl_nip.pl_id(+)=l_enrolled_ptip.pl_id and
1734            pl_nip.business_group_id(+)=p_business_group_id and
1735            pl_nip.ler_id(+)=decode(dual.dummy,dual.dummy,p_ler_id,dual.dummy) and
1736            l_lf_evt_ocrd_dt between
1737              pl_nip.effective_start_date(+) and pl_nip.effective_end_date(+) and
1738            ptip.ptip_id(+)=g_ptip_id and
1739            ptip.business_group_id(+)=p_business_group_id and
1740            ptip.ler_id(+)=decode(dual.dummy,dual.dummy,p_ler_id,dual.dummy) and
1741            l_lf_evt_ocrd_dt between
1742              ptip.effective_start_date(+) and ptip.effective_end_date(+) and
1743            pgm.pgm_id(+)=p_pgm_id and
1744            pgm.business_group_id(+)=p_business_group_id and
1745            pgm.ler_id(+)=decode(dual.dummy,dual.dummy,p_ler_id,dual.dummy) and
1746            l_lf_evt_ocrd_dt between
1747              pgm.effective_start_date(+) and pgm.effective_end_date(+) and
1748            plip.plip_id(+)=l_enrolled_ptip.plip_id and
1749            plip.business_group_id(+)=p_business_group_id and
1750            plip.ler_id(+)=decode(dual.dummy,dual.dummy,p_ler_id,dual.dummy) and
1751            l_lf_evt_ocrd_dt between
1752              plip.effective_start_date(+) and plip.effective_end_date(+) and
1753            oipl.oipl_id(+) = l_enrolled_ptip.oipl_id and
1754            oipl.business_group_id(+) = p_business_group_id and
1755            oipl.ler_id(+)=decode(dual.dummy,dual.dummy,p_ler_id,dual.dummy) and
1756            l_lf_evt_ocrd_dt between
1757              oipl.effective_start_date(+) and oipl.effective_end_date(+);
1758     */
1759     l_ptip_prclds_flag         VARCHAR2(30);
1760     l_enrt_cd_level            VARCHAR2(30);
1761     l_enrt_cvg_date            date ;
1762 
1763     --- determine the current enrollment according to the level
1764 
1765 
1766   --
1767   BEGIN
1768   g_debug := hr_utility.debug_enabled;
1769   if g_debug then
1770     hr_utility.set_location('Entering: ' || l_proc, 10);
1771   end if;
1772 --  hr_utility.set_location('enrt_mthd_cd='||p_enrt_mthd_cd,11);
1773 --  hr_utility.set_location('auto_enrt_mthd_rl='||p_auto_enrt_mthd_rl,13);
1774 --  hr_utility.set_location('enrt_cd='||p_enrt_cd,12);
1775   --
1776   --  Get program record.
1777   --
1778     IF p_pgm_id IS NOT NULL THEN
1779       ben_comp_object.get_object(p_pgm_id => p_pgm_id, p_rec => l_pgm_rec);
1780       if g_debug then
1781       hr_utility.set_location('Done PGM NN: ' || l_proc, 10);
1782       end if;
1783     END IF;
1784 --
1785 -- Check the tco_chg_enrt_cd if this comp object can be changed
1786 --
1787 -- Note: "enrolled in option" only includes option within plans of
1788 --       the same plan type.
1789 --
1790 --              | Is enrolled | Is Not         | Is enrolled | Is not enrolled
1791 -- Level TCO_CD | in plan     | enrolled in pl | in option   | in option
1792 -- ----- -------+-------------+----------------+-------------+----------------
1793 -- oipl  CPOO   | Y           | Y              | Y           | Y
1794 -- oipl  CPNO   | n/a         | n/a            | Y           | N
1795 -- oipl  CONP   | Y           | N              | n/a         | n/a
1796 -- ----- -------+-------------+----------------+-------------+----------------
1797 -- pl    CPOO   | Y           | Y              | Y           | Y
1798 -- pl    CPNO   | Y           | Y              | Y           | Y
1799 -- pl    CONP   | Y           | N              | n/a         | n/a
1800 --
1801 /* -- 4031733 - Cursor c_state populates l_state variable which is no longer
1802    -- used in the package. Cursor can be commented
1803 
1804     IF p_person_id IS NOT NULL THEN
1805       OPEN c_state;
1806       FETCH c_state INTO l_state;
1807       CLOSE c_state;
1808       hr_utility.set_location('close c_state: ' || l_proc, 9999);
1809       --IF l_state.region_2 IS NOT NULL THEN
1810       --  l_jurisdiction_code :=
1811       --    pay_mag_utils.lookup_jurisdiction_code(p_state => l_state.region_2);
1812       --END IF;
1813     END IF;
1814 */
1815 
1816     OPEN c_asg;
1817     FETCH c_asg INTO l_asg;
1818     IF c_asg%NOTFOUND THEN
1819       CLOSE c_asg;
1820       fnd_message.set_name('BEN', 'BEN_92106_PRTT_NO_ASGN');
1821       fnd_message.set_token('PROC', l_proc);
1822       fnd_message.set_token('PERSON_ID', TO_CHAR(p_person_id));
1823       fnd_message.set_token('LF_EVT_OCRD_DT', TO_CHAR(p_lf_evt_ocrd_dt));
1824       fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
1825       RAISE ben_manage_life_events.g_record_error;
1826     END IF;
1827     CLOSE c_asg;
1828     if g_debug then
1829     hr_utility.set_location('close c_asg: ' || l_proc, 10);
1830     end if;
1831     IF p_oipl_id IS NOT NULL THEN
1832       IF p_tco_chg_enrt_cd = 'CONP' THEN
1833         --
1834         OPEN c_plan_enrolment_info;
1835         FETCH c_plan_enrolment_info INTO l_crnt_pl_enrt_cvg_strt_dt;
1836         IF c_plan_enrolment_info%NOTFOUND THEN
1837           --
1838           open c_ptip_waive_enrolment_info;
1839           fetch c_ptip_waive_enrolment_info into l_crnt_pl_enrt_cvg_strt_dt;
1840           if c_ptip_waive_enrolment_info%NOTFOUND then
1841             IF p_pgm_id IS NOT NULL THEN
1842                 --
1843                 --  When processing the COBRA, also check the elig_cvrd_dpnt
1844                 --  table as dependents can make independent elections.
1845                 --
1846               IF l_pgm_rec.pgm_typ_cd LIKE 'COBRA%' THEN
1847                 OPEN c_plan_cvg_info;
1848                 FETCH c_plan_cvg_info INTO l_crnt_pl_enrt_cvg_strt_dt;
1849                 CLOSE c_plan_cvg_info;
1850               END IF;
1851             END IF;
1852             --
1853           end if;
1854           close c_ptip_waive_enrolment_info;
1855         END IF;
1856         --
1857         CLOSE c_plan_enrolment_info;
1858       --
1859       ELSIF p_tco_chg_enrt_cd = 'CPNO' THEN
1860         --
1861 	if g_debug then
1862         hr_utility.set_location('pl_typ_id=' || p_pl_typ_id, 1963);
1863         hr_utility.set_location('opt_id=' || p_opt_id, 1963);
1864         hr_utility.set_location(
1865           'crnt_opt_cvg_strt_dt=' || l_crnt_opt_cvg_strt_dt,
1866           1963);
1867         end if;
1868         OPEN c_enrolled_opts_in_pl_typ;
1869         FETCH c_enrolled_opts_in_pl_typ INTO l_crnt_opt_cvg_strt_dt;
1870 	if g_debug then
1871         hr_utility.set_location(
1872           'crnt_opt_cvg_strt_dt=' || l_crnt_opt_cvg_strt_dt,
1873           1963);
1874         end if;
1875         IF c_enrolled_opts_in_pl_typ%NOTFOUND THEN
1876           IF p_pgm_id IS NOT NULL THEN
1877             --
1878             --  When processing the COBRA, also check the elig_cvrd_dpnt
1879             --  table as dependents can make independent elections.
1880             --
1881             IF l_pgm_rec.pgm_typ_cd LIKE 'COBRA%' THEN
1882               OPEN c_cvrd_opts_in_pl_typ;
1883               FETCH c_cvrd_opts_in_pl_typ INTO l_crnt_opt_cvg_strt_dt;
1884 	      if g_debug then
1885               hr_utility.set_location(
1886                 'crnt_opt_cvg_strt_dt=' || l_crnt_opt_cvg_strt_dt,
1887                 1963);
1888               end if;
1889               CLOSE c_cvrd_opts_in_pl_typ;
1890             END IF;
1891           END IF;
1892         END IF;
1893         CLOSE c_enrolled_opts_in_pl_typ;
1894       END IF;
1895     --
1896     END IF;
1897     if g_debug then
1898     hr_utility.set_location('Done p_oipl NN ' || l_proc, 10);
1899     end if;
1900     --
1901     IF NOT (
1902                 (                                                  -- eval oipl
1903                       p_oipl_id IS NOT NULL
1904                   AND (                         -- can change plan or option or
1905                            p_tco_chg_enrt_cd = 'CPOO'
1906                         OR (           -- change plan only and enrolled in oipl
1907                                  p_tco_chg_enrt_cd = 'CPNO'
1908                              AND l_crnt_opt_cvg_strt_dt IS NOT NULL)
1909                         OR (         -- change option only and enrolled in plan
1910                                  p_tco_chg_enrt_cd = 'CONP'
1911                              AND l_crnt_pl_enrt_cvg_strt_dt IS NOT NULL)))
1912              OR (                                                    -- eval pl
1913                       p_oipl_id IS NULL
1914                   AND (                            -- change plan or/not option
1915                            p_tco_chg_enrt_cd IN ('CPOO', 'CPNO')
1916                         OR (         -- change option only and enrolled in plan
1917                                  p_tco_chg_enrt_cd = 'CONP'
1918                              AND (
1919                                       p_crnt_enrt_cvg_strt_dt IS NOT NULL
1920                                    OR p_dpnt_cvrd_flag = 'Y'))))) THEN
1921       --
1922       p_electable_flag :=  'N';
1923       --
1924       if g_debug then
1925       hr_utility.set_location(' Leaving:' || l_proc, 5);
1926       end if;
1927       --
1928       RETURN;
1929     --
1930     END IF;
1931     --
1932     -- If stl_elig_cant_chg_flag is set to Y and
1933     -- previous_eligibility is true, Done, not electable.
1934     --
1935     IF (    p_stl_elig_cant_chg_flag = 'Y'
1936         AND p_previous_eligibility = 'Y') THEN
1937       --
1938       p_electable_flag :=  'N';
1939       --
1940       if g_debug then
1941       hr_utility.set_location(' Leaving:' || l_proc, 10);
1942       end if;
1943       --
1944       RETURN;
1945     --
1946     END IF;
1947     -- if P_ENRT_PRCLDS_CHG_FLAG is true and person is
1948     -- currently enrolled, this choice is NOT electable.  DONE.
1949     -- bug 5216 - check across ptip for enrollment.  If enrolled
1950     -- in ptip then use this flag from that comp object.
1951     -- if set to Y then nothing in ptip is electable.
1952     --
1953     IF (    p_enrt_prclds_chg_flag = 'Y'
1954         AND p_crnt_enrt_cvg_strt_dt IS NOT NULL) THEN
1955       --
1956       p_electable_flag :=  'N';
1957       --
1958       if g_debug then
1959       hr_utility.set_location(' Returning:' || l_proc, 15);
1960       end if;
1961       --
1962       RETURN;
1963     --
1964     ELSE
1965       -- get the plip id from the pgm and pl not from the enrollment data
1966       open c_plip_info ;
1967       fetch c_plip_info into l_plip_id ;
1968       close c_plip_info ;
1969 
1970        determine_ben_settings(
1971           p_pl_id                     => p_pl_id,         --l_enrolled_ptip.pl_id,
1972           p_ler_id                    => p_ler_id,
1973           p_lf_evt_ocrd_dt            => l_lf_evt_ocrd_dt,
1974           p_ptip_id                   => g_ptip_id,
1975           p_pgm_id                    => p_pgm_id,
1976           p_plip_id                   => l_plip_id ,     --l_enrolled_ptip.plip_id,
1977           p_oipl_id                   => p_oipl_id ,     --l_enrolled_ptip.oipl_id,
1978           p_just_prclds_chg_flag      => TRUE,
1979           p_enrt_cd                   => l_enrt_cd,
1980           p_enrt_rl                   => l_enrt_rl,
1981           p_auto_enrt_mthd_rl         => l_auto_enrt_mthd_rl,
1982           p_crnt_enrt_prclds_chg_flag => l_ptip_prclds_flag,
1983           p_dflt_flag                 => l_dflt_flag,
1984           p_enrt_mthd_cd              => l_enrt_mthd_cd,
1985           p_stl_elig_cant_chg_flag    => l_stl_elig_cant_chg_flag,
1986           p_tco_chg_enrt_cd           => l_tco_chg_enrt_cd,
1987           p_ler_chg_oipl_found_flag   => l_ler_chg_oipl_found_flag,
1988           p_ler_chg_found_flag        => l_ler_chg_found_flag,
1989           p_enrt_cd_level             => l_enrt_cd_level );
1990 
1991           if g_debug then
1992           hr_utility.set_location( 'l_enrt_cd_level ' || l_enrt_cd_level , 99 );
1993           hr_utility.set_location( 'enrt_cd ' || p_enrt_cd  , 99 );
1994           end if;
1995           --- check the level of enrollment code and intialise the coverage date
1996           if  l_enrt_cd_level = 'OIPL'   then
1997               l_enrt_cvg_date := p_crnt_enrt_cvg_strt_dt ;
1998           elsif  l_enrt_cd_level = 'PL'  then
1999               if p_oipl_id is null then
2000                  l_enrt_cvg_date := p_crnt_enrt_cvg_strt_dt ;
2001               else
2002                  OPEN c_plan_enrolment_info;
2003                  FETCH c_plan_enrolment_info INTO l_enrt_cvg_date;
2004                  close  c_plan_enrolment_info ;
2005               end if ;
2006           elsif  l_enrt_cd_level = 'PLIP'  then
2007                  OPEN  c_plip_enrolment_info;
2008                  FETCH c_plip_enrolment_info INTO l_enrt_cvg_date;
2009                  close c_plip_enrolment_info ;
2010           elsif  l_enrt_cd_level = 'PTIP'  then
2011                  OPEN  c_ptip_2_enrolment_info;
2012                  FETCH c_ptip_2_enrolment_info INTO l_enrt_cvg_date;
2013                  close c_ptip_2_enrolment_info ;
2014           elsif  l_enrt_cd_level = 'PGM'  then
2015                  OPEN  c_pgm_enrolment_info;
2016                  FETCH c_pgm_enrolment_info INTO l_enrt_cvg_date;
2017                  close c_pgm_enrolment_info ;
2018           else
2019                 l_enrt_cvg_date := p_crnt_enrt_cvg_strt_dt ;
2020           end if ;
2021 	  if g_debug then
2022           hr_utility.set_location( 'l_enrt_cvg_date ' || l_enrt_cvg_date , 99 );
2023 	  end if;
2024           ----
2025 
2026 
2027       -- check if enrolled in ptip
2028       if g_debug then
2029       hr_utility.set_location(' Op c_ptip_enr_inf'||l_proc, 15);
2030       end if;
2031       OPEN c_ptip_enrolment_info;
2032       FETCH c_ptip_enrolment_info INTO l_enrolled_ptip;
2033       if g_debug then
2034       hr_utility.set_location(' Dn Fet c_ptip_enr_inf'||l_proc, 15);
2035       end if;
2036       IF c_ptip_enrolment_info%FOUND THEN
2037       if g_debug then
2038          hr_utility.set_location('CHKPTIPENRT found', 10);
2039       end if;
2040          IF l_ptip_prclds_flag = 'Y' THEN
2041 	 if g_debug then
2042             hr_utility.set_location('CHKPTIPENRT prclds', 10);
2043          end if;
2044             p_electable_flag :=  'N';
2045             --
2046 	    if g_debug then
2047             hr_utility.set_location(' Leaving:' || l_proc, 19);
2048 	    end if;
2049             --
2050             RETURN;
2051             --
2052          END IF;
2053       END IF;
2054       CLOSE c_ptip_enrolment_info;
2055     END IF;
2056     -- If the enrt_cd is rule
2057     if g_debug then
2058     hr_utility.set_location('EC=RL: ' || l_proc, 10);
2059     end if;
2060     IF (p_enrt_cd = 'RL') THEN
2061       -- 5092244 : commented the following code
2062      /* if p_update_def_elct_flag is not null then -- don't reevaluate the rule again
2063         --
2064         p_electable_flag := p_update_def_elct_flag;
2065         RETURN;
2066         --
2067       end if;*/
2068       l_result_flag :=
2069        execute_enrt_rule(
2070          p_opt_id            => p_opt_id,
2071          p_pl_id             => p_pl_id,
2072          p_pgm_id            => p_pgm_id,
2073          p_rule_id           => p_enrt_rl,
2074          p_ler_id            => p_ler_id,
2075          p_pl_typ_id         => p_pl_typ_id,
2076          p_business_group_id => p_business_group_id,
2077          p_effective_date    => p_effective_date,
2078          p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
2079          p_elig_per_id       => p_elig_per_id,
2080          p_assignment_id     => p_assignment_id,
2081          p_organization_id   => l_asg.organization_id,
2082          p_jurisdiction_code => l_jurisdiction_code,
2083 	 p_person_id         => p_person_id              -- Bug 5331889
2084 	 );
2085       --
2086       IF (l_result_flag = 'N') THEN
2087         --
2088         p_electable_flag :=  'N';
2089         --
2090 	if g_debug then
2091         hr_utility.set_location(' Leaving:' || l_proc, 20);
2092 	end if;
2093         --
2094         RETURN;
2095       --
2096       ELSIF l_result_flag = 'L' THEN
2097         --
2098         -- L will be used for Lose only functionality.
2099         --
2100         p_electable_flag :=  'L';
2101 	if g_debug then
2102         hr_utility.set_location(' Leaving:' || l_proc, 21);
2103 	end if;
2104         --
2105         RETURN;
2106       --
2107       END IF;
2108     --
2109     ELSIF    p_enrt_cd = 'CLONN'
2110           OR (
2111                    p_enrt_cd in ('CLNCC','CNNA')
2112                AND  l_enrt_cvg_date IS NOT NULL
2113                AND p_dpnt_cvrd_flag = 'N') THEN
2114       --
2115       -- Just return L.  This will trigger
2116       -- call to ben_newly_ineligible.
2117       -- which will either do nothing or deenroll
2118       --
2119       p_electable_flag :=  'L';
2120       --
2121       RETURN;
2122     --
2123     ELSE                                                    -- p_enrt_cd = 'RL'
2124     if g_debug then
2125       hr_utility.set_location('Else EC=RL: ' || l_proc, 10);
2126     end if;
2127 -- If the combination of enrt_cd and eligibility status is YES in the
2128 -- following matrix then the choice is electable
2129 -- (continue to create choice),
2130 -- else it is not electable.  (DONE).
2131 --
2132 --                   Create Choice?
2133 -- ENRT_CD     Not enrolled     Enrolled  Note
2134 -- CKNCC           YES             NO
2135 -- CCONCC          YES             YES    Duplicate with below
2136 -- CCKCNCC         YES             YES    Duplicate with above
2137 -- CCKCSNCC        YES             YES    Duplicate with above
2138 -- CLNCC           YES             NO     *Should not be eligible
2139 -- CCKCNN          NO              YES    Duplicate with below
2140 -- CCONN           NO              YES    Duplicate with above
2141 -- CKNN            NO              NO
2142 -- CLONN           NO              NO     *Should not be eligible
2143 --
2144 -- particles
2145 --
2146 -- Part   Description
2147 -- CCKC   current can keep or choose
2148 -- CCO    Same as above
2149 -- CK     current must keep
2150 -- CL     current will loose
2151 -- CLO    Same as above
2152 -- NCC    new can choose
2153 -- NN     new cannot choose
2154 --
2155       IF NOT (                               -- currently enrolled and eligible
2156                   (
2157                         (
2158                               l_enrt_cvg_date IS NOT NULL
2159                           OR p_dpnt_cvrd_flag = 'Y')
2160                     AND p_enrt_cd IN ('CCONCC', 'CCKCNN', 'CCONN', 'CCKCNCC','CCKCSNCC'))
2161                OR
2162                   -- not enrolled, but eligible
2163                   (
2164                         (
2165                                l_enrt_cvg_date IS NULL
2166                           AND p_dpnt_cvrd_flag = 'N')
2167                     AND p_enrt_cd IN ('CKNCC', 'CCONCC', 'CLNCC', 'CCKCNCC','CCKCSNCC'))) THEN
2168         --
2169         p_electable_flag :=  'N';
2170         --
2171 	if g_debug then
2172         hr_utility.set_location(' Leaving:' || l_proc, 25);
2173 	end if;
2174         --
2175         RETURN;
2176       --
2177       END IF;                                                  -- enrt_cd table
2178     --
2179     END IF;                                                     -- p_enrt_cd=RL
2180     --
2181     p_electable_flag :=  'Y';
2182     --
2183     if g_debug then
2184     hr_utility.set_location(' Leaving:' || l_proc, 30);
2185     end if;
2186     --
2187     RETURN;
2188   --
2189   exception  -- nocopy changes
2190     --
2191     when others then
2192       --
2193       p_electable_flag := null;
2194       raise;
2195       --
2196   END determine_enrolment;
2197 --
2198 -- cwb changes
2199 procedure get_cwb_manager_and_assignment
2200              (p_person_id in number,
2201               p_hrchy_to_use_cd in varchar2,
2202               p_pos_structure_version_id in number,
2203               p_effective_date in date,
2204               p_manager_id out nocopy number,
2205               p_assignment_id out nocopy number )
2206   is
2207   --
2208   --Bug 2827121 Manager can be a contingent worker also.
2209   cursor c_get_assignment is
2210     select assignment_id,
2211            position_id,
2212            supervisor_id
2213     from per_all_assignments_f
2214     where person_id = p_person_id
2215     and primary_flag = 'Y'
2216     and assignment_type in ( 'E','C' )  -- Bug 2827121
2217     and p_effective_date
2218       between effective_start_date and effective_end_date;
2219   --
2220   l_get_assignment   c_get_assignment%rowtype;
2221   --
2222   cursor c_parent_position_id (p_position_id number)
2223     is
2224     select parent_position_id
2225     from per_pos_structure_elements
2226     where subordinate_position_id = p_position_id
2227     and   pos_structure_version_id = p_pos_structure_version_id;
2228   --
2229   cursor c_manager_id (p_position_id number)
2230     is
2231     select person_id
2232     from per_all_assignments_f ass,
2233          per_assignment_status_types ast
2234     where  ass.position_id = p_position_id
2235     and    ass.primary_flag = 'Y'
2236     and ass.assignment_type in ( 'E' , 'C' ) -- Bug 2827121
2237     and p_effective_date
2238       between ass.effective_start_date and ass.effective_end_date
2239     --Bug 3044311 -- Need to verify what other system types should be considered.
2240     and ass.assignment_status_type_id = ast.assignment_status_type_id
2241     -- and ast.active_flag = 'Y'
2242     and ast.per_system_status in ('ACTIVE_ASSIGN','SUSP_ASSIGN') ;
2243     --
2244   --
2245   l_parent_position_id   number(15);
2246   l_manager_id           number(15);
2247   l_assignment_id        number(15);
2248 
2249   l_position_id          number(15);
2250 Begin
2251   --
2252   g_debug := hr_utility.debug_enabled;
2253   open c_get_assignment;
2254   fetch c_get_assignment into l_get_assignment;
2255   close c_get_assignment;
2256   --
2257   l_assignment_id := l_get_assignment.assignment_id;
2258   --
2259   if p_hrchy_to_use_cd = 'S' then
2260     l_manager_id := l_get_assignment.supervisor_id;
2261   elsif p_hrchy_to_use_cd = 'P' then
2262 
2263     -- Start Bug 2684227
2264     -- Upon a vacancy, continue to climb the position hierarchy
2265     -- until a person is found
2266 
2267     l_position_id :=  l_get_assignment.position_id;
2268 
2269     loop
2270       open c_parent_position_id(l_position_id);
2271       fetch c_parent_position_id into l_parent_position_id;
2272       exit when c_parent_position_id%notfound;
2273       close c_parent_position_id;
2274       if l_parent_position_id is not null then
2275         open c_manager_id (l_parent_position_id);
2276         fetch c_manager_id into l_manager_id;
2277         close c_manager_id;
2278         if  l_manager_id is not null then
2279           exit;
2280         end if;
2281       end if;
2282 
2283       l_position_id := l_parent_position_id;
2284     end loop;
2285 
2286     -- End Bug 2684227
2287     --
2288     --
2289     -- Bug 2230922 : If manager id not found then default to supervisor.
2290     --
2291     if l_manager_id is null then
2292        --
2293        l_manager_id := l_get_assignment.supervisor_id;
2294        --
2295     end if;
2296     --
2297  end if;
2298  --
2299  p_manager_id := l_manager_id;
2300  p_assignment_id := l_assignment_id;
2301  --
2302 exception  -- nocopy changes
2303   --
2304   when others then
2305     --
2306     p_manager_id:= null;
2307     p_assignment_id := null;
2308     raise;
2309     --
2310 end get_cwb_manager_and_assignment;
2311 -------------------------
2312 -- 2746865
2313 -- separate procedure instead of inline code
2314 procedure enrt_perd_strt_dt
2315   (p_person_id 				in 	number
2316    ,p_lf_evt_ocrd_dt 			in 	date
2317    ,p_enrt_perd_det_ovrlp_bckdt_cd 	in 	varchar2
2318    ,p_business_group_id                 in      number
2319    ,p_ler_id                            in      number
2320    ,p_effective_date                    in      date
2321    ,p_rec_enrt_perd_strt_dt 		in out 	nocopy date
2322    )
2323 IS
2324   -- local variables
2325   l_proc             varchar2 (72) := g_package || 'enrt_perd_strt_dt';
2326   l_latest_procd_dt  date;
2327   l_backed_out_date  date;
2328   l_latest_enrt_dt   date;
2329   l_lf_evt_ocrd_dt   date := NVL(p_lf_evt_ocrd_dt, p_effective_date);
2330   -- store sysdate sans the time component into a local variable for once
2331   l_sysdate          date := trunc(sysdate);
2332   -- define cursors
2333   CURSOR c_get_latest_procd_dt IS
2334     SELECT   MAX(pil.procd_dt)
2335     FROM     ben_per_in_ler pil
2336             -- CWB changes
2337             ,ben_ler_f      ler
2338     WHERE    pil.person_id = p_person_id
2339     AND      pil.ler_id    = ler.ler_id
2340     and      ler.typ_cd   not in ('COMP','ABS', 'GSP', 'IREC','SCHEDDU')
2341     and      l_lf_evt_ocrd_dt between
2342              ler.effective_start_date and ler.effective_end_date
2343     AND      pil.business_group_id = p_business_group_id
2344     AND      pil.per_in_ler_stat_cd NOT IN ('BCKDT', 'VOIDD')
2345     AND      pil.procd_dt IS NOT NULL;
2346   --
2347   CURSOR c_backed_out_ler IS
2348     SELECT   MAX(pil.bckt_dt)
2349     FROM     ben_per_in_ler pil
2350             -- CWB changes
2351             ,ben_ler_f      ler
2352             ,ben_ptnl_ler_for_per  plr
2353     WHERE    pil.person_id = p_person_id
2354     AND      pil.ler_id    = ler.ler_id
2355     and      ler.typ_cd   not in ('COMP','ABS', 'GSP', 'IREC','SCHEDDU')
2356     and      l_lf_evt_ocrd_dt between
2357              ler.effective_start_date and ler.effective_end_date
2358     AND      pil.business_group_id = p_business_group_id
2359     AND      pil.ler_id = p_ler_id
2360     AND      pil.lf_evt_ocrd_dt = p_lf_evt_ocrd_dt
2361     AND      pil.bckt_dt IS NOT NULL
2362     and      pil.per_in_ler_stat_cd = 'BCKDT' -- 3063867
2363     and      pil.ptnl_ler_for_per_id   = plr.ptnl_ler_for_per_id  --3248770
2364     and      plr.ptnl_ler_for_per_stat_cd <> 'VOIDD' ;
2365   --
2366 
2367   -- 2746865
2368   -- cursor to select a person's maximum enrollment start date
2369   -- Changed the following cursor for bug 3137519 to exclude GSP/ABS/COMP ler types.
2370   -- Also included status no in backdt/voidd clause
2371   --bug#3697378 - discussed with Phil why we add + 1 to the latest enrollment
2372   --however he wanted this to be removed so that self service open enrollment
2373   --will not be impacted and asked find ways to show history on enrollment results later
2374   cursor c_get_latest_enrt_dt is
2375     select max(rslt.effective_start_date)
2376     from   ben_prtt_enrt_rslt_f rslt,ben_ler_f ler
2377      where  rslt.person_id = p_person_id
2378     and ler.ler_id=rslt.ler_id
2379   --  and rslt.prtt_enrt_rslt_stat_cd NOT IN ('BCKDT', 'VOIDD')
2380     and rslt.prtt_enrt_rslt_stat_cd is null
2381     and   ler.typ_cd   not in ('COMP','ABS', 'GSP', 'IREC','SCHEDDU' )
2382     and    rslt.business_group_id = p_business_group_id
2383     and rslt.enrt_cvg_thru_dt = hr_api.g_eot; -- Bug 4388226 - End-dated suspended enrl shudn't be picked up.
2384 
2385   --
2386 
2387   begin
2388 
2389   -- following are the 4 codes used for enrt. period determination
2390   -------------------------------------------------------------------------
2391   -- L_EPSD_PEPD 	- Later of Enrollment period start date and
2392   --		 	  prior event processed date
2393   -- L_EPSD_PEESD 	- Later of Enrollment period start date and
2394   --		 	  One day after prior event elections start date
2395   -- L_EPSD_PEESD_BCKDT - Later of Enrollment period start date and One
2396   --			  day after prior event elections start date and
2397   --			  current events backed out date
2398   -- L_EPSD_PEESD_SYSDT - Later of Enrollment period start date and One
2399   --			  day after prior event elections start date
2400   --			  and system date
2401   -------------------------------------------------------------------------
2402   -- if cd is L_EPSD_PEPD, use the old logic
2403   hr_utility.set_location(' Entering '||l_proc, 10);
2404   --
2405   -- remove all these debug messages
2406   hr_utility.set_location(' p_enrt_perd_det_ovrlp_bckdt_cd is  '||p_enrt_perd_det_ovrlp_bckdt_cd, 987);
2407   hr_utility.set_location(' p_person_id '||p_person_id, 10);
2408   hr_utility.set_location(' p_lf_evt_ocrd_dt '||p_lf_evt_ocrd_dt, 10);
2409   hr_utility.set_location(' p_ler_id '||p_ler_id, 10);
2410   hr_utility.set_location(' p_effective_date '||p_effective_date, 10);
2411   hr_utility.set_location(' p_rec_enrt_perd_strt_dt '||p_rec_enrt_perd_strt_dt, 10);
2412   --
2413 
2414   IF nvl(p_enrt_perd_det_ovrlp_bckdt_cd, 'L_EPSD_PEPD') = 'L_EPSD_PEPD' THEN
2415     --
2416     hr_utility.set_location(' L_EPSD_PEPD', 987);
2417     OPEN c_get_latest_procd_dt;
2418     FETCH c_get_latest_procd_dt INTO l_latest_procd_dt;
2419     -- new epsd is greater of epsd or latest_procd_dt
2420     -- IF c_get_latest_procd_dt%FOUND THEN
2421     IF l_latest_procd_dt IS NOT NULL THEN
2422       hr_utility.set_location(' c_get_latest_procd_dt%found', 987);
2423       hr_utility.set_location('l_latest_procd_dt is '||l_latest_procd_dt, 987);
2424       -- jcarpent 1/4/2001 bug 1568555, removed +1 from line below
2425       IF p_rec_enrt_perd_strt_dt < l_latest_procd_dt THEN
2426         hr_utility.set_location('l_latest_procd_dt made enrt strt dt ', 987);
2427         -- jcarpent 1/4/2001 bug 1568555, removed +1 from line below
2428         p_rec_enrt_perd_strt_dt :=  l_latest_procd_dt;
2429         -- if the enrollment  exist for the previous LE
2430         -- start the window latest_procd_dt + 1
2431         -- or the previous enrollment will be updated in correction mode
2432         -- and backout of this LE will remove the previous LE results
2433         --the  changes are backedout  3086161
2434         --
2435         --Bugs 3972973 and 3978745 fixes.
2436         --If the enrollment starts after the processed date we need to consider the
2437         --latest enrollment date.
2438         --
2439       End IF;
2440       --bug#4478186 - enrl start date should always be equal or greater to latest
2441       --enrt dt
2442       OPEN c_get_latest_enrt_dt;
2443       FETCH c_get_latest_enrt_dt into l_latest_enrt_dt;
2444       close c_get_latest_enrt_dt ;
2445       --
2446       if l_latest_enrt_dt is not null and  l_latest_enrt_dt > p_rec_enrt_perd_strt_dt then
2447          p_rec_enrt_perd_strt_dt := l_latest_enrt_dt ;
2448       end if ;
2449         --
2450     END IF;
2451     CLOSE c_get_latest_procd_dt;
2452     -- 4 is new epsd <= p_lf_evt_ocrd_dt?
2453     IF p_rec_enrt_perd_strt_dt <= p_lf_evt_ocrd_dt THEN
2454       -- 5 is there a backed out le for the current ler and ...
2455       OPEN c_backed_out_ler;
2456       FETCH c_backed_out_ler INTO l_backed_out_date;
2457       --IF c_backed_out_ler%FOUND THEN
2458       IF l_backed_out_date is NOT NULL THEN
2459         hr_utility.set_location(' c_backed_out_ler%found', 987);
2460         hr_utility.set_location('l_backed_out_date is '||l_backed_out_date, 987);
2461         -- 5a ... and is the backed-out date > than the new epsd?
2462         IF l_backed_out_date > p_rec_enrt_perd_strt_dt THEN
2463           hr_utility.set_location('l_backed_out_date made enrt strt dt ', 987);
2464           -- 6 it is the new epsd.
2465           p_rec_enrt_perd_strt_dt :=  l_backed_out_date;
2466         END IF;
2467       END IF;
2468       CLOSE c_backed_out_ler;
2469     END IF;
2470     -- 2746865
2471     -- if cd is L_EPSD_PEESD%, use the new logic
2472   ELSIF p_enrt_perd_det_ovrlp_bckdt_cd like  'L_EPSD_PEESD%' THEN
2473     hr_utility.set_location('  L_EPSD_PEESD%', 987);
2474     -- get the person's latest enrollment start date +1
2475     OPEN c_get_latest_enrt_dt;
2476       FETCH c_get_latest_enrt_dt into l_latest_enrt_dt;
2477       -- IF c_get_latest_enrt_dt%FOUND THEN --changed as its always found
2478       IF l_latest_enrt_dt is not null THEN
2479         hr_utility.set_location(' c_get_latest_enrt_dt%FOUND', 987);
2480         hr_utility.set_location('l_latest_enrt_dt is '||l_latest_enrt_dt, 987);
2481         -- if latest enrt dt is greater than epsd, make it the epsd
2482         IF l_latest_enrt_dt > p_rec_enrt_perd_strt_dt THEN
2483           p_rec_enrt_perd_strt_dt := l_latest_enrt_dt;
2484           hr_utility.set_location('l_latest_enrt_dt substituted', 987);
2485         END IF;
2486       END IF;
2487       CLOSE c_get_latest_enrt_dt;
2488       -- cd is 2 find the bckdt out dt
2489       IF p_enrt_perd_det_ovrlp_bckdt_cd = 'L_EPSD_PEESD_BCKDT' THEN
2490         hr_utility.set_location('L_EPSD_PEESD_BCKDT entered', 987);
2491         -- get the backed out date
2492         OPEN c_backed_out_ler;
2493         FETCH c_backed_out_ler INTO l_backed_out_date;
2494         hr_utility.set_location('l_backed_out_date is '||l_backed_out_date, 987);
2495         --IF c_backed_out_ler%FOUND THEN -- changed as its of no use
2496         IF l_backed_out_date is not null THEN
2497           hr_utility.set_location('bckdt%found', 987);
2498           -- if bckdt out dt is greater than epsd, make it the epsd
2499           IF l_backed_out_date > p_rec_enrt_perd_strt_dt THEN
2500             p_rec_enrt_perd_strt_dt := l_backed_out_date;
2501             hr_utility.set_location('l_backed_out_date substituted', 987);
2502           END IF;
2503         END IF;
2504         CLOSE c_backed_out_ler;
2505       -- if cd is 4, compare epsd with sysdate
2506       ELSIF p_enrt_perd_det_ovrlp_bckdt_cd = 'L_EPSD_PEESD_SYSDT' THEN
2507         hr_utility.set_location('L_EPSD_PEESD_SYSDT entered', 987);
2508         -- if sysdate is lis greater than epsd, make it the epsd
2509         IF l_sysdate > p_rec_enrt_perd_strt_dt THEN
2510           p_rec_enrt_perd_strt_dt := l_sysdate;
2511           hr_utility.set_location('sysdate substituted', 987);
2512         END IF;
2513       END IF;
2514     -- end 2746865
2515   END IF;
2516   end; --procedure
2517 --
2518 -------------------------
2519 
2520 procedure enrolment_requirements
2521   (p_comp_obj_tree_row      in     ben_manage_life_events.g_cache_proc_objects_rec
2522   ,p_run_mode               in     varchar2
2523   ,p_business_group_id      in     number
2524   ,p_effective_date         in     date
2525   ,p_lf_evt_ocrd_dt         in     date default null
2526   ,p_ler_id                 in     number
2527   ,p_per_in_ler_id          in     number
2528   ,p_person_id              in     number
2529   ,p_pl_id                  in     number
2530   ,p_pgm_id                 in     number default null
2531   ,p_oipl_id                in     number default null
2532   ,p_create_anyhow_flag     in     varchar2 default 'N'
2533   -- 5422 : PB ,p_popl_enrt_typ_cycl_id  in     number default null
2534   --
2535   ,p_asnd_lf_evt_dt         in     date default null
2536   ,p_electable_flag            out nocopy varchar2
2537   ,p_elig_per_elctbl_chc_id    out nocopy number
2538   )
2539 IS
2540   --
2541   l_currpep_dets     ben_pep_cache.g_pep_rec;
2542   l_currepe_dets ben_epe_cache.g_pilepe_inst_row;
2543   --
2544   l_prevepo_rec      ben_derive_part_and_rate_facts.g_cache_structure;
2545   l_prevpep_rec      ben_derive_part_and_rate_facts.g_cache_structure;
2546   --
2547     l_dummy                        varchar2(30);
2548     l_dummy_rt_strt_dt             DATE;
2549     l_dummy_rt_strt_dt_cd          VARCHAR2(30);
2550     l_dummy_rt_strt_dt_rl          NUMBER;
2551     l_dummy_enrt_cvg_end_dt        DATE;
2552     l_dummy_enrt_cvg_end_dt_cd     VARCHAR2(30);
2553     l_dummy_enrt_cvg_end_dt_rl     NUMBER;
2554     l_dummy_rt_end_dt              DATE;
2555     l_dummy_rt_end_dt_cd           VARCHAR2(30);
2556     l_dummy_rt_end_dt_rl           NUMBER;
2557     l_dummy_enrt_cvg_strt_dt_cd    VARCHAR2(30);
2558     l_dummy_enrt_cvg_strt_dt_rl    NUMBER;
2559 
2560 
2561 --l_overide_enrt_cvg_strt_dt_cd varchar2(30);
2562 --l_overide_enrt_cvg_strt_dt_rl number;
2563     l_pl_id                        NUMBER;
2564     l_prereq_electable_flag        VARCHAR2(30);
2565     l_oipl_name                    ben_opt_f.name%TYPE;
2566     l_pl_name                      ben_pl_f.name%TYPE;
2567     l_ler_name                     ben_ler_f.name%TYPE;
2568     l_must_enrl_anthr_pl_id        NUMBER;
2569     l_auto_enrt_flag               VARCHAR2(30)                 := 'N';
2570     l_rec_auto_enrt_flag           VARCHAR2(30)                 := 'N';
2571     l_comp_lvl_cd                  VARCHAR2(30);
2572     l_prtt_enrt_rslt_id            NUMBER;
2573     l_prtt_enrt_rslt_id_2          NUMBER;
2574     l_object_version_number        NUMBER;
2575     l_popl_yr_perd_id              NUMBER;
2576     l_yr_perd_strt_date            DATE;
2577     l_yr_perd_end_date             DATE;
2578     l_popl_yr_perd_ordr_num        NUMBER;
2579     l_yr_perd_id                   NUMBER;
2580     l_elig_per_elctbl_chc_id       NUMBER;
2581     l_tco_chg_enrt_cd              VARCHAR2(30)                 := 'CPOO';
2582     l_opt_id                       NUMBER;
2583     l_ptip_id                      NUMBER;
2584     l_ptip_ordr_num                NUMBER;
2585     l_plip_ordr_num                NUMBER;
2586     l_ptip_esd                     DATE;
2587     l_ptip_eed                     DATE;
2588     l_per_in_ler_id                NUMBER;
2589     l_alws_unrstrctd_enrt_flag     VARCHAR2(30)                 := 'N';
2590     l_plip_id                      NUMBER;
2591     l_plip_esd                     DATE;
2592     l_plip_eed                     DATE;
2593     l_plip_dflt_flag               VARCHAR2(30);
2594     l_plip_enrt_cd                 VARCHAR2(30);
2595     l_plip_enrt_rl                 NUMBER;
2596     l_oipl_dflt_flag               VARCHAR2(30);
2597     l_elig_per_id                  NUMBER;
2598     l_current_eligibility          VARCHAR2(30);
2599     l_prtn_strt_dt                 DATE;
2600     l_previous_eligibility         VARCHAR2(30);
2601     l_pl_typ_id                    NUMBER;
2602     l_proc                         VARCHAR2(72)
2603                                        := g_package ||
2604                                             '.enrolment_requirements';
2605     l_pl_enrt_cd                   VARCHAR2(30);
2606 --L_PL_ENRT_CVG_STRT_DT_CD      varchar2(30);
2607 --L_PL_ENRT_CVG_STRT_DT_RL      number;
2608     l_pl_enrt_mthd_cd              VARCHAR2(30);
2609     l_plip_enrt_mthd_cd            VARCHAR2(30);
2610     l_crnt_enrt_cvg_strt_dt        DATE;
2611     l_crnt_enrt_cvg_thru_dt        DATE;    --BUG 6519487 fix
2612     l_mndtry_flag                  VARCHAR2(30)                 := 'N';
2613     l_mndtry_rl                    NUMBER;
2614     l_choice_exists_flag           VARCHAR2(30);
2615     l_lf_evt_ocrd_dt_fetch         DATE;
2616     l_rqd_perd_enrt_nenrt_uom      VARCHAR2(30);
2617     l_ler_typ_cd                   VARCHAR2(30);
2618     l_ler_chg_found_flag           VARCHAR2(30);
2619     l_ler_chg_oipl_found_flag      VARCHAR2(30);
2620     l_ler_enrt_prclds_chg_flag     VARCHAR2(30);
2621     l_ler_dflt_flag                VARCHAR2(30);
2622     l_ler_enrt_cd                  VARCHAR2(30);
2623     l_ple_dys_aftr_end_to_dflt_num NUMBER;
2624     l_perd_for_plan_found          VARCHAR2(30)                 := 'N';
2625     l_rqd_perd_enrt_nenrt_val      NUMBER;
2626     l_rqd_perd_enrt_nenrt_rl       NUMBER;
2627     l_ler_enrt_mthd_cd             VARCHAR2(30);
2628     l_ler_enrt_rl                  NUMBER;
2629     l_ple_enrt_perd_end_dt_rl      NUMBER;
2630 --L_PLE_ENRT_CVG_STRT_DT_CD     varchar2(30);
2631     l_use_dflt_enrt_cd             VARCHAR2(30);
2632     l_use_dflt_enrt_rl             NUMBER;
2633     l_use_dflt_flag                VARCHAR2(30);
2634     l_ler_stl_elig_cant_chg_flag   VARCHAR2(30);
2635     l_pl_enrt_rl                   NUMBER;
2636     l_ple_enrt_perd_strt_dt_rl     NUMBER;
2637     l_ple_enrt_perd_strt_days     NUMBER;
2638     l_ple_enrt_perd_end_days     NUMBER;
2639     l_pgme_dys_aftr_end_to_dflt    NUMBER;
2640     l_perd_for_program_found       VARCHAR2(30)                 := 'N';
2641     l_ple_enrt_perd_end_dt_cd      VARCHAR2(30);
2642     l_pgme_enrt_perd_end_dt_rl     NUMBER;
2643     l_ple_enrt_perd_strt_dt        DATE;
2644     l_rec_enrt_cvg_strt_dt_cd      VARCHAR2(30);
2645     l_rec_enrt_cvg_strt_dt_rl      NUMBER;
2646     l_ple_enrt_perd_strt_dt_cd     VARCHAR2(30);
2647     l_pgme_enrt_perd_strt_dt_rl    NUMBER;
2648     l_pgme_enrt_perd_strt_days    NUMBER;
2649     l_pgme_enrt_perd_end_days    NUMBER;
2650     l_ple_enrt_perd_end_dt         DATE;
2651     l_pgme_enrt_perd_strt_dt       DATE;
2652     l_rec_enrt_cvg_strt_dt         DATE;
2653     l_pgme_enrt_perd_end_dt_cd     VARCHAR2(30);
2654     l_ple_procg_end_dt             DATE;
2655     l_pgme_enrt_perd_end_dt        DATE;
2656     l_rec_mndtry_flag              VARCHAR2(30)                 := 'N';
2657     l_rec_elctbl_flag              VARCHAR2(30)                 := 'Y';
2658     l_exists_flag                  VARCHAR2(30);
2659     l_pgme_enrt_perd_strt_dt_cd    VARCHAR2(30);
2660     l_ple_dflt_enrt_dt             DATE;
2661     l_pgme_procg_end_dt            DATE;
2662     l_ple_enrt_typ_cycl_cd         VARCHAR2(30);
2663     l_rec_crntly_enrd_flag         VARCHAR2(30);
2664     l_pgme_dflt_enrt_dt            DATE;
2665     l_rec_enrt_typ_cycl_cd         VARCHAR2(30);
2666     l_pgme_enrt_typ_cycl_cd        VARCHAR2(30);
2667     l_dflt_flag                    VARCHAR2(30);
2668     l_rec_enrt_perd_strt_dt        DATE;
2669     l_erlst_deenrt_calc_dt         date ;         /*used for determine erly_deenrt_dt accroing level */
2670     l_orgnl_enrt_dt                date ;
2671     l_rec_enrt_perd_end_dt         DATE;
2672     l_ple_addit_procg_dys_num      NUMBER;
2673     l_rec_dflt_asnmt_dt            DATE;
2674     l_rec_procg_end_dt             DATE;
2675     l_crnt_erlst_deenrt_dt         DATE;
2676     l_rec_roll_crs_only_flag       VARCHAR2(30);
2677     l_rec_elctns_made_flag         VARCHAR2(30);
2678     l_rec_assignment_id            NUMBER;
2679     l_rec_organization_id          NUMBER;
2680     l_pgme_addit_procg_dys_num     NUMBER;
2681     l_rec_erlst_deenrt_dt          DATE;
2682     l_plip_auto_enrt_rl            NUMBER;
2683     l_pl_auto_enrt_rl              NUMBER;
2684     l_ler_auto_enrt_rl             NUMBER;
2685     l_invk_flx_cr_pl_flag          VARCHAR2(30);
2686     l_imptd_incm_calc_cd           VARCHAR2(30);
2687     l_pl_trk_inelig_per_flag       VARCHAR2(30);
2688     l_oipl_trk_inelig_per_flag     VARCHAR2(30);
2689     l_ple_enrt_perd_id             NUMBER;
2690     l_pgme_enrt_perd_id            NUMBER;
2691     l_rec_enrt_perd_id             NUMBER;
2692     l_rec_lee_rsn_id               NUMBER;
2693     l_rec_lee_rsn_esd              DATE;
2694     l_rec_lee_rsn_eed              DATE;
2695     l_ple_lee_rsn_id               NUMBER;
2696     l_pgme_lee_rsn_id              NUMBER;
2697     l_rec_acty_ref_perd_cd         VARCHAR2(30);
2698     l_rec_cls_enrt_dt_to_use_cd    VARCHAR2(30);
2699     l_rec_uom                      VARCHAR2(30);
2700     l_oipl_auto_enrt_flag          VARCHAR2(30)                 := 'N';
2701     l_oipl_auto_enrt_mthd_rl       NUMBER;
2702     l_unrestricted_enrt_flag       VARCHAR2(30)                 := 'N';
2703     l_enrt_ovridn_flag             VARCHAR2(30);
2704     l_enrt_ovrid_thru_dt           DATE;
2705     l_oipl_ordr_num                NUMBER;
2706     l_boo_rstrctn_cd               VARCHAR2(30);
2707     l_mn_ordr_num                  ben_oipl_f.ordr_num%TYPE;
2708     l_mx_ordr_num                  ben_oipl_f.ordr_num%TYPE;
2709     l_enrd_ordr_num                NUMBER;
2710     l_level                        VARCHAR2(30);
2711     l_plan_rec                     ben_pl_f%ROWTYPE;
2712     l_pgm_rec                      ben_pgm_f%ROWTYPE;
2713     l_oipl_rec                     ben_cobj_cache.g_oipl_inst_row;
2714     l_pen_rec                      ben_prtt_enrt_rslt_f%ROWTYPE;
2715     l_pl_typ_esd                   DATE;
2716     l_pl_typ_eed                   DATE;
2717     l_ler_esd                      DATE;
2718     l_ler_eed                      DATE;
2719     l_dpnt_cvrd_flag               VARCHAR2(1)                  := 'N';
2720     l_ptip_enrt_cd                 VARCHAR2(30);
2721     l_ptip_enrt_rl                 NUMBER;
2722     l_ptip_enrt_mthd_cd            VARCHAR2(30);
2723     l_ptip_auto_enrt_rl            NUMBER;
2724     l_jurisdiction_code            VARCHAR2(30);
2725     l_ctfn_rqd_flag                VARCHAR2(30)                 := 'N';
2726     l_reinstt_flag                 VARCHAR2(30);
2727     l_reinstt_cd                   VARCHAR2(30);
2728     --
2729     l_cvg_incr_r_decr_only_cd      VARCHAR2(30);
2730     l_mx_cvg_mlt_incr_num          NUMBER;
2731     l_mx_cvg_mlt_incr_wcf_num      NUMBER;
2732     l_tmp_level                    VARCHAR2(30);
2733     l_restriction_pgm_id           NUMBER;
2734     l_regn_125_or_129_flag         varchar2(30);
2735     --
2736     l_lf_evt_ocrd_dt               DATE
2737                                     := NVL(p_lf_evt_ocrd_dt, p_effective_date);
2738     l_lf_evt_ocrd_dt_1             DATE                 := l_lf_evt_ocrd_dt - 1;
2739   --  l_effective_date_1             DATE                 := p_effective_date - --  1;
2740   --  Bug#2328029
2741     l_effective_date_1     date :=
2742            least(p_effective_date, nvl(p_lf_evt_ocrd_dt,p_effective_date)) -1;
2743     --
2744 
2745     --
2746     l_ple_hrchy_to_use_cd          varchar2(30);
2747     l_ple_pos_structure_version_id    number;
2748     l_ws_mgr_id                    number;
2749     l_elig_flag                    varchar2(30);
2750     l_assignment_id                number(15);
2751     -- 2746865 -- variable for new column
2752     l_enrt_perd_det_ovrlp_bckdt_cd varchar2(30);
2753     l_fonm_cvg_strt_dt             date;
2754     l_epe_exists                   number ;
2755     --
2756     -- bug: 5644451
2757     l_oipl_record   ben_oipl_f%ROWTYPE;
2758     l_plip_record   ben_plip_f%ROWTYPE;
2759     l_ptip_record   ben_ptip_f%ROWTYPE;
2760     l_dflt_level    varchar2(30);
2761     --
2762     -- define all cursors
2763     --
2764     --
2765     ------------Bug 8846328
2766     l_fut_rslt_exist boolean := false;
2767     l_crnt_enrt_sspndd_flag varchar2(10) := 'N';
2768     ------------Bug 8846328
2769     CURSOR c_pl_typ IS
2770       SELECT   bpt.effective_start_date,
2771                bpt.effective_end_date
2772       FROM     ben_pl_typ_f bpt
2773       WHERE    bpt.pl_typ_id = l_pl_typ_id
2774       AND      l_lf_evt_ocrd_dt BETWEEN bpt.effective_start_date
2775                    AND bpt.effective_end_date
2776       AND      bpt.business_group_id = p_business_group_id;
2777     --
2778     CURSOR c_state IS
2779       SELECT   loc.region_2
2780       FROM     hr_locations_all loc, per_all_assignments_f asg
2781       WHERE    loc.location_id = asg.location_id
2782       AND      asg.person_id = p_person_id
2783       and      asg.assignment_type <> 'C'
2784       AND      asg.primary_flag = 'Y'
2785       AND      l_lf_evt_ocrd_dt BETWEEN asg.effective_start_date
2786                    AND asg.effective_end_date
2787       AND      asg.business_group_id = p_business_group_id;
2788     --
2789     l_state                        c_state%ROWTYPE;
2790     --
2791     CURSOR c_asg IS
2792       SELECT   asg.assignment_id,
2793                asg.organization_id
2794       FROM     per_all_assignments_f asg
2795       WHERE    asg.person_id = p_person_id
2796       and      asg.assignment_type <> 'C'
2797       AND      asg.primary_flag = decode (p_run_mode, 'I', asg.primary_flag, 'Y')-- iREC
2798       AND      l_lf_evt_ocrd_dt BETWEEN asg.effective_start_date
2799                    AND asg.effective_end_date;
2800   --
2801   --
2802   -- Enrt_perd_for_pl info
2803   --
2804 --cursor c_enrt_perd_for_pl_info is
2805 --  select epp.enrt_cvg_strt_dt_cd,
2806 --         epp.enrt_cvg_strt_dt_rl
2807 --  from   ben_enrt_perd_for_pl_f epp
2808 --  where  epp.pl_id=l_pl_id and
2809 --         (epp.enrt_perd_id=l_pgme_enrt_perd_id or
2810 --          epp.lee_rsn_id=l_pgme_lee_rsn_id) and
2811 --         nvl(p_lf_evt_ocrd_dt,p_effective_date) between
2812 --           epp.effective_start_date and epp.effective_end_date and
2813 --         epp.business_group_id =p_business_group_id
2814 --  ;
2815   --
2816   -- Determine the current popl_yr_period
2817   --
2818     CURSOR c_pl_popl_yr_period_current IS
2819       SELECT   pyp.yr_perd_id,
2820                pyp.popl_yr_perd_id,
2821                yp.start_date,
2822                yp.end_date,
2823                pyp.ordr_num
2824       FROM     ben_popl_yr_perd pyp, ben_yr_perd yp
2825       WHERE    pyp.pl_id = l_pl_id
2826       AND      pyp.yr_perd_id = yp.yr_perd_id
2827       AND      pyp.business_group_id = p_business_group_id
2828       AND      l_lf_evt_ocrd_dt BETWEEN yp.start_date AND yp.end_date
2829       AND      yp.business_group_id = p_business_group_id;
2830     --
2831     -- see if the elig_per_elctbl_chc record already exists
2832     --
2833     --
2834     CURSOR c_choice_exists_for_option IS
2835       SELECT   NULL
2836       FROM     ben_elig_per_elctbl_chc epe
2837       WHERE    epe.oipl_id = p_oipl_id
2838       -- added 9/25/98 to handle plans in mult progs
2839       AND      (
2840                     (    epe.pgm_id = p_pgm_id
2841                      AND p_pgm_id IS NOT NULL)
2842                  OR (    epe.pgm_id IS NULL
2843                      AND p_pgm_id IS NULL))
2844       AND      epe.per_in_ler_id = l_per_in_ler_id
2845       AND      epe.business_group_id = p_business_group_id;
2846     --
2847     -- see if the elig_per_elctbl_chc record already exists
2848     --
2849     --
2850     CURSOR c_choice_exists_for_plan(pp_pl_id NUMBER) IS
2851       SELECT   elig_per_elctbl_chc_id
2852       FROM     ben_elig_per_elctbl_chc epe
2853       WHERE    epe.pl_id = pp_pl_id
2854       AND      epe.oipl_id IS NULL
2855       -- added 9/25/98 to handle plans in mult progs
2856       AND      (
2857                     (    epe.pgm_id = p_pgm_id
2858                      AND p_pgm_id IS NOT NULL)
2859                  OR (    epe.pgm_id IS NULL
2860                      AND p_pgm_id IS NULL))
2861       AND      epe.per_in_ler_id = l_per_in_ler_id
2862       AND      epe.business_group_id = p_business_group_id;
2863     --
2864     -- Gets the enrolment information for this plan
2865     --
2866     --
2867     --8399189
2868     CURSOR c_plan_enrolment_info(p_cvg_dt date,p_run_mode varchar2) IS
2869       SELECT   pen.enrt_cvg_strt_dt,
2870                pen.erlst_deenrt_dt,
2871                pen.prtt_enrt_rslt_id,
2872                pen.enrt_ovridn_flag,
2873                pen.enrt_ovrid_thru_dt,
2874                pen.orgnl_enrt_dt,
2875                pen.enrt_cvg_thru_dt,
2876                pen.pl_typ_id
2877       FROM     ben_prtt_enrt_rslt_f pen
2878       WHERE    pen.person_id = p_person_id
2879       AND      pen.business_group_id = p_business_group_id
2880       AND      (pen.sspndd_flag = 'N' --CFW
2881                  OR (pen.sspndd_flag = 'Y' and
2882                      pen.enrt_cvg_thru_dt = hr_api.g_eot
2883                     )
2884                )
2885       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
2886       --8399189
2887       AND      ((pen.effective_end_date = hr_api.g_eot
2888       and      p_run_mode <> 'U')
2889        or      ( p_effective_date between pen.effective_start_date and pen.effective_end_date
2890       and       p_run_mode = 'U'))
2891       --8399189
2892       AND      p_cvg_dt <= pen.enrt_cvg_thru_dt
2893       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
2894       AND      pen.oipl_id IS NULL
2895       AND      l_pl_id = pen.pl_id
2896       AND      (
2897                     (    pen.pgm_id = p_pgm_id
2898                      AND p_pgm_id IS NOT NULL)
2899                  OR (    pen.pgm_id IS NULL
2900                      AND p_pgm_id IS NULL))
2901       order by pen.enrt_cvg_strt_dt,decode(pen.sspndd_flag,'Y',1,2) ;
2902     --
2903     -- Bug 2600087
2904     --
2905     -- Gets the enrolment information for this oipl
2906     --
2907     --
2908      CURSOR c_oipl_enrolment_info(p_cvg_dt date,p_run_mode varchar2) IS
2909       SELECT   pen.enrt_cvg_strt_dt,
2910                pen.erlst_deenrt_dt,
2911                pen.prtt_enrt_rslt_id,
2912                pen.enrt_ovridn_flag,
2913                pen.enrt_ovrid_thru_dt,
2914                pen.enrt_cvg_thru_dt,
2915 	       pen.sspndd_flag,   ---------Bug 8846328
2916                pen.pl_typ_id
2917       FROM     ben_prtt_enrt_rslt_f pen
2918       WHERE    pen.person_id = p_person_id
2919       AND      pen.business_group_id = p_business_group_id
2920       AND      (pen.sspndd_flag = 'N' --CFW
2921                  OR (pen.sspndd_flag = 'Y' and
2922                      pen.enrt_cvg_thru_dt = hr_api.g_eot
2923                     )
2924                )
2925       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
2926       ------Bug 8228639,modified the fix 7507714
2927       AND      ((pen.effective_end_date = hr_api.g_eot
2928       and      p_run_mode <> 'U')
2929        or      ( p_effective_date between pen.effective_start_date and pen.effective_end_date
2930       and       p_run_mode = 'U'))
2931       ------Bug 8228639,modified the fix 7507714
2932       AND      p_cvg_dt <= pen.enrt_cvg_thru_dt
2933       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
2934       AND      p_oipl_id = pen.oipl_id
2935       AND      (
2936                     (    pen.pgm_id = p_pgm_id
2937                      AND p_pgm_id IS NOT NULL)
2938                  OR (    pen.pgm_id IS NULL
2939                      AND p_pgm_id IS NULL))
2940     -- Bug 2600087
2941     order by pen.enrt_cvg_strt_dt,decode(pen.sspndd_flag,'Y',1,2);
2942     --
2943     --BUG 6519487 fix
2944     --
2945     CURSOR c_future_results (p_person_id in number,
2946                              p_enrt_cvg_thru_dt  in date,
2947                              p_pgm_id            in number,
2948                              p_pl_typ_id         in number) is
2949    SELECT   pen.* ----'Y',Bug 8453712
2950      FROM   ben_prtt_enrt_rslt_f pen
2951     WHERE   pen.person_id  = p_person_id
2952     AND     pen.effective_end_date = hr_api.g_eot
2953     AND     pen.enrt_cvg_strt_dt > p_enrt_cvg_thru_dt
2954     ANd     pen.pl_typ_id       = p_pl_typ_id
2955     and     nvl(pen.sspndd_flag,'N') = 'N'
2956     AND    (
2957                     (    pen.pgm_id = p_pgm_id
2958                      AND p_pgm_id IS NOT NULL)
2959                  OR (    pen.pgm_id IS NULL
2960                      AND p_pgm_id IS NULL))
2961     AND     pen.prtt_enrt_rslt_stat_cd is null;
2962 
2963     l_future_results c_future_results%rowtype;--Bug 8453712
2964     --
2965     --BUG 6519487 fix
2966     --
2967     -- Gets the coverage information for this plan
2968     --
2969     --
2970     CURSOR c_plan_cvg_info IS
2971       SELECT   'Y'
2972       FROM     ben_prtt_enrt_rslt_f pen, ben_elig_cvrd_dpnt_f pdp
2973       WHERE    pdp.dpnt_person_id = p_person_id
2974       AND      pdp.effective_end_date = hr_api.g_eot
2975       AND      l_lf_evt_ocrd_dt_1 BETWEEN pdp.cvg_strt_dt AND pdp.cvg_thru_dt
2976       AND      pdp.business_group_id = p_business_group_id
2977       AND      pdp.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
2978       AND      pen.business_group_id = p_business_group_id
2979       AND      pen.sspndd_flag = 'N'
2980       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
2981       AND      pen.effective_end_date = hr_api.g_eot
2982       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
2983       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
2984       AND      l_pl_id = pen.pl_id
2985       AND      (
2986                     (    pen.pgm_id = p_pgm_id
2987                      AND p_pgm_id IS NOT NULL)
2988                  OR (    pen.pgm_id IS NULL
2989                      AND p_pgm_id IS NULL));
2990     --
2991     -- Gets the coverage information for this oipl
2992     --
2993     --
2994     CURSOR c_oipl_cvg_info IS
2995       SELECT   'Y'
2996       FROM     ben_prtt_enrt_rslt_f pen, ben_elig_cvrd_dpnt_f pdp
2997       WHERE    pdp.dpnt_person_id = p_person_id
2998       AND      pdp.effective_end_date = hr_api.g_eot
2999       AND      l_lf_evt_ocrd_dt_1 BETWEEN pdp.cvg_strt_dt AND pdp.cvg_thru_dt
3000       AND      pdp.business_group_id = p_business_group_id
3001       AND      pdp.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
3002       AND      pen.business_group_id = p_business_group_id
3003       AND      pen.sspndd_flag = 'N'
3004       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
3005       AND      pen.effective_end_date = hr_api.g_eot
3006       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
3007       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
3008       AND      p_oipl_id = pen.oipl_id
3009       AND      (
3010                     (    pen.pgm_id = p_pgm_id
3011                      AND p_pgm_id IS NOT NULL)
3012                  OR (    pen.pgm_id IS NULL
3013                      AND p_pgm_id IS NULL));
3014     --
3015     -- Determines the current eligibility for an option
3016     --
3017     CURSOR c_current_elig_for_option IS
3018       SELECT   ep.elig_per_id,
3019                epo.elig_flag,
3020                ep.must_enrl_anthr_pl_id,
3021                epo.prtn_strt_dt
3022       FROM     ben_elig_per_f ep, ben_elig_per_opt_f epo, ben_per_in_ler pil
3023       WHERE    ep.person_id = p_person_id
3024       AND      ep.pl_id = l_pl_id
3025       AND      (
3026                     (    ep.pgm_id = p_pgm_id
3027                      AND p_pgm_id IS NOT NULL)
3028                  OR (    ep.pgm_id IS NULL
3029                      AND p_pgm_id IS NULL))
3030       AND      ep.business_group_id = p_business_group_id
3031       AND      p_effective_date BETWEEN ep.effective_start_date
3032                    AND ep.effective_end_date
3033       AND      ep.elig_per_id = epo.elig_per_id
3034       AND      epo.opt_id = l_opt_id
3035       AND      epo.business_group_id = p_business_group_id
3036       AND      p_effective_date BETWEEN epo.effective_start_date
3037                    AND epo.effective_end_date
3038       AND      pil.per_in_ler_id (+) = epo.per_in_ler_id
3039       AND      pil.business_group_id (+) = epo.business_group_id
3040       AND      (
3041                     pil.per_in_ler_stat_cd NOT IN
3042                                         (
3043                                           'VOIDD',
3044                                           'BCKDT')       -- found row condition
3045                  OR pil.per_in_ler_stat_cd IS NULL);    -- outer join condition
3046     -- Determines the previous eligibility for an option
3047     --
3048     CURSOR c_previous_elig_for_option IS
3049       SELECT   epo.elig_flag
3050       FROM     ben_elig_per_f ep, ben_elig_per_opt_f epo, ben_per_in_ler pil
3051       WHERE    ep.person_id = p_person_id
3052       AND      ep.pl_id = l_pl_id
3053       AND      (
3054                     (    ep.pgm_id = p_pgm_id
3055                      AND p_pgm_id IS NOT NULL)
3056                  OR (    ep.pgm_id IS NULL
3057                      AND p_pgm_id IS NULL))
3058       AND      ep.business_group_id = p_business_group_id
3059       AND      p_effective_date - 1 BETWEEN ep.effective_start_date
3060                    AND ep.effective_end_date
3061       AND      ep.elig_per_id = epo.elig_per_id
3062       AND      epo.opt_id = l_opt_id
3063       AND      epo.business_group_id = p_business_group_id
3064       AND      l_effective_date_1 BETWEEN epo.effective_start_date
3065                    AND epo.effective_end_date
3066       AND      pil.per_in_ler_id (+) = epo.per_in_ler_id
3067       AND      pil.business_group_id (+) = epo.business_group_id
3068       AND      (
3069                     pil.per_in_ler_stat_cd NOT IN
3070                                         (
3071                                           'VOIDD',
3072                                           'BCKDT')       -- found row condition
3073                  OR pil.per_in_ler_stat_cd IS NULL);    -- outer join condition
3074     --
3075     -- Determines the current eligibility for a plan
3076     --
3077     CURSOR c_current_elig_for_plan
3078     is
3079       SELECT   pep.elig_per_id,
3080                pep.elig_flag,
3081                pep.must_enrl_anthr_pl_id,
3082                pep.prtn_strt_dt,
3083                pep.inelg_rsn_cd -- 2650247
3084       FROM     ben_elig_per_f pep, ben_per_in_ler pil
3085       WHERE    pep.person_id = p_person_id
3086       AND      pep.pl_id = l_pl_id
3087       AND      (
3088                     (    pep.pgm_id = p_pgm_id
3089                      AND p_pgm_id IS NOT NULL)
3090                  OR (    pep.pgm_id IS NULL
3091                      AND p_pgm_id IS NULL))
3092       AND      pep.business_group_id = p_business_group_id
3093       AND      p_effective_date BETWEEN pep.effective_start_date
3094                    AND pep.effective_end_date
3095       AND      pil.per_in_ler_id (+) = pep.per_in_ler_id
3096       AND      pil.business_group_id (+) = pep.business_group_id
3097       AND      (
3098                     pil.per_in_ler_stat_cd NOT IN
3099                                         (
3100                                           'VOIDD',
3101                                           'BCKDT')       -- found row condition
3102                  OR pil.per_in_ler_stat_cd IS NULL);    -- outer join condition
3103     --
3104     -- Determines the previous eligibility for a plan
3105     --
3106     CURSOR c_previous_elig_for_plan IS
3107       SELECT   pep.elig_flag
3108       FROM     ben_elig_per_f pep, ben_per_in_ler pil
3109       WHERE    pep.person_id = p_person_id
3110       AND      pep.pl_id = l_pl_id
3111       AND      (
3112                     (    pep.pgm_id = p_pgm_id
3113                      AND p_pgm_id IS NOT NULL)
3114                  OR (    pep.pgm_id IS NULL
3115                      AND p_pgm_id IS NULL))
3116       AND      pep.business_group_id = p_business_group_id
3117       AND      l_effective_date_1 BETWEEN pep.effective_start_date
3118                    AND pep.effective_end_date
3119       AND      pil.per_in_ler_id (+) = pep.per_in_ler_id
3120       AND      pil.business_group_id (+) = pep.business_group_id
3121       AND      (
3122                     pil.per_in_ler_stat_cd NOT IN
3123                                         (
3124                                           'VOIDD',
3125                                           'BCKDT')       -- found row condition
3126                  OR pil.per_in_ler_stat_cd IS NULL);    -- outer join condition
3127     -- Determines the per_in_ler and gets associated info
3128     --
3129     CURSOR c_per_in_ler_info IS
3130       SELECT   pil.per_in_ler_id,
3131                ler.typ_cd,
3132                ler.name,
3133                pil.lf_evt_ocrd_dt,
3134                ler.effective_start_date,
3135                ler.effective_end_date
3136       FROM     ben_per_in_ler pil, ben_ler_f ler
3137       WHERE    pil.person_id = p_person_id
3138       AND      pil.business_group_id = p_business_group_id
3139       AND      pil.ler_id = p_ler_id
3140       AND      pil.per_in_ler_stat_cd = 'STRTD'
3141       AND      ler.business_group_id = p_business_group_id
3142       AND      pil.ler_id = ler.ler_id
3143       AND      l_lf_evt_ocrd_dt BETWEEN ler.effective_start_date
3144                    AND ler.effective_end_date
3145       and      nvl(pil.assignment_id, -9999) = decode (p_run_mode,
3146                                            'I',
3147 					   ben_manage_life_events.g_irec_ass_rec.assignment_id,
3148 					   nvl(pil.assignment_id, -9999) );            -- iRec
3149     --
3150     -- Bug 2200139 Get new the per_in_ler info for the Override Election.
3151     --
3152     CURSOR c_ovrd_per_in_ler_info IS
3153       SELECT   pil.per_in_ler_id,
3154                ler.typ_cd,
3155                ler.name,
3156                pil.lf_evt_ocrd_dt,
3157                ler.effective_start_date,
3158                ler.effective_end_date
3159       FROM     ben_per_in_ler pil, ben_ler_f ler
3160       WHERE    pil.per_in_ler_id = p_per_in_ler_id
3161       AND      pil.business_group_id = p_business_group_id
3162 --     AND      pil.ler_id = p_ler_id
3163 --     AND      pil.per_in_ler_stat_cd = 'STRTD'
3164       AND      ler.business_group_id = p_business_group_id
3165       AND      pil.ler_id = ler.ler_id
3166       AND      l_lf_evt_ocrd_dt BETWEEN ler.effective_start_date
3167                    AND ler.effective_end_date;
3168     -- end Override Election
3169     -- This cursor gets the enrolment period for scheduled
3170     -- elections for plan level
3171     --
3172     -- Bug 5272 : To get the enrolment period get the
3173     -- enrollment strt_dt and use it to get the programs enrollment
3174     -- period data.
3175     --
3176     CURSOR c_sched_enrol_period_for_plan IS
3177       SELECT   enrtp.enrt_perd_id,
3178                enrtp.strt_dt,
3179                enrtp.end_dt,
3180                enrtp.procg_end_dt,
3181                enrtp.dflt_enrt_dt,
3182                petc.enrt_typ_cycl_cd,
3183                enrtp.cls_enrt_dt_to_use_cd,
3184                enrtp.hrchy_to_use_cd,
3185                enrtp.pos_structure_version_id,
3186                /* bug 2746865  */
3187                enrtp.enrt_perd_det_ovrlp_bckdt_cd
3188       FROM     ben_popl_enrt_typ_cycl_f petc,
3189                ben_enrt_perd enrtp,
3190                 ben_ler_f ler
3191       WHERE    petc.pl_id = l_pl_id
3192       AND      petc.business_group_id = p_business_group_id
3193       AND      l_lf_evt_ocrd_dt BETWEEN petc.effective_start_date
3194                    AND petc.effective_end_date
3195       AND      petc.enrt_typ_cycl_cd <> 'L'
3196       AND      enrtp.business_group_id = p_business_group_id
3197       AND      enrtp.asnd_lf_evt_dt  = p_lf_evt_ocrd_dt
3198       /* PB :5422 AND      enrtp.strt_dt=enrtp1.strt_dt
3199       AND      enrtp1.popl_enrt_typ_cycl_id = p_popl_enrt_typ_cycl_id
3200       AND      enrtp1.business_group_id     = p_business_group_id */
3201       AND      enrtp.popl_enrt_typ_cycl_id  = petc.popl_enrt_typ_cycl_id
3202       -- comp work bench changes
3203       and      ler.ler_id (+) = enrtp.ler_id
3204       and      ler.ler_id (+) = p_ler_id
3205       and      l_lf_evt_ocrd_dt between ler.effective_start_date (+)
3206                                     and ler.effective_end_date (+);
3207 
3208     -- This cursor gets the enrolment period for scheduled
3209     -- elections for program level
3210     --
3211     -- Bug 5272 : To get the enrolment period,  get the
3212     -- enrollment strt_dt and use it to get the plans enrollment
3213     -- period data.
3214     --
3215     CURSOR c_sched_enrol_period_for_pgm IS
3216       SELECT   enrtp.enrt_perd_id,
3217                enrtp.strt_dt,
3218                enrtp.end_dt,
3219                enrtp.procg_end_dt,
3220                enrtp.dflt_enrt_dt,
3221                petc.enrt_typ_cycl_cd,
3222                enrtp.cls_enrt_dt_to_use_cd,
3223                enrtp.hrchy_to_use_cd,
3224                enrtp.pos_structure_version_id,
3225                /* bug 2746865*/
3226                enrtp.enrt_perd_det_ovrlp_bckdt_cd
3227       FROM     ben_popl_enrt_typ_cycl_f petc,
3228                ben_enrt_perd enrtp,
3229                ben_ler_f ler
3230       WHERE    petc.pgm_id = p_pgm_id
3231       AND      petc.business_group_id = p_business_group_id
3232       AND      l_lf_evt_ocrd_dt BETWEEN petc.effective_start_date
3233                    AND petc.effective_end_date
3234       AND      petc.enrt_typ_cycl_cd <> 'L'
3235       AND      enrtp.business_group_id = p_business_group_id
3236       AND      enrtp.asnd_lf_evt_dt  = p_lf_evt_ocrd_dt
3237       /* PB :5422 AND      enrtp1.business_group_id = p_business_group_id
3238       AND      enrtp.strt_dt= enrtp1.strt_dt
3239       AND      enrtp1.enrt_perd_id = p_popl_enrt_typ_cycl_id */
3240       AND      enrtp.popl_enrt_typ_cycl_id = petc.popl_enrt_typ_cycl_id
3241       -- comp work bench
3242       and      ler.ler_id (+) = enrtp.ler_id
3243       and      ler.ler_id (+) = p_ler_id
3244       and      l_lf_evt_ocrd_dt between ler.effective_start_date (+)
3245                                     and ler.effective_end_date (+);
3246 
3247     -- This cursor gets information used to determine the
3248     -- enrolment period for life event driven elections
3249     --
3250     CURSOR c_lee_period_for_plan IS
3251       SELECT   leer.dys_aftr_end_to_dflt_num,
3252                leer.enrt_perd_end_dt_rl,
3253                leer.enrt_perd_strt_dt_rl,
3254                leer.enrt_perd_end_dt_cd,
3255                leer.enrt_perd_strt_dt_cd,
3256                leer.addl_procg_dys_num,
3257                petc.enrt_typ_cycl_cd,
3258                leer.lee_rsn_id,
3259                leer.cls_enrt_dt_to_use_cd,
3260                leer.effective_start_date,
3261                leer.effective_end_date,
3262                leer.enrt_perd_strt_days,
3263                leer.enrt_perd_end_days,
3264                /* bug 2746865*/
3265                leer.enrt_perd_det_ovrlp_bckdt_cd
3266       FROM     ben_lee_rsn_f leer, ben_popl_enrt_typ_cycl_f petc
3267       WHERE    leer.ler_id = p_ler_id
3268       AND      leer.business_group_id = p_business_group_id
3269       AND      l_lf_evt_ocrd_dt BETWEEN leer.effective_start_date
3270                    AND leer.effective_end_date
3271       AND      leer.popl_enrt_typ_cycl_id = petc.popl_enrt_typ_cycl_id
3272       AND      petc.pl_id = l_pl_id
3273       AND      petc.enrt_typ_cycl_cd = 'L'                        -- life event
3274       AND      petc.business_group_id = p_business_group_id
3275       AND      l_lf_evt_ocrd_dt BETWEEN petc.effective_start_date
3276                    AND petc.effective_end_date;
3277     -- This cursor gets information used to determine the
3278     -- enrolment period for life event driven elections
3279     --
3280     CURSOR c_lee_period_for_program IS
3281       SELECT   leer.dys_aftr_end_to_dflt_num,
3282                leer.enrt_perd_end_dt_rl,
3283                leer.enrt_perd_strt_dt_rl,
3284                leer.enrt_perd_end_dt_cd,
3285                leer.enrt_perd_strt_dt_cd,
3286                leer.addl_procg_dys_num,
3287                petc.enrt_typ_cycl_cd,
3288                leer.lee_rsn_id,
3289                leer.cls_enrt_dt_to_use_cd,
3290                leer.effective_start_date,
3291                leer.effective_end_date ,
3292                leer.enrt_perd_strt_days,
3293                leer.enrt_perd_end_days,
3294                /* bug 2746865*/
3295                leer.enrt_perd_det_ovrlp_bckdt_cd
3296       FROM     ben_lee_rsn_f leer, ben_popl_enrt_typ_cycl_f petc
3297       WHERE    leer.ler_id = p_ler_id
3298       AND      leer.business_group_id = p_business_group_id
3299       AND      l_lf_evt_ocrd_dt BETWEEN leer.effective_start_date
3300                    AND leer.effective_end_date
3301       AND      leer.popl_enrt_typ_cycl_id = petc.popl_enrt_typ_cycl_id
3302       AND      petc.pgm_id = p_pgm_id
3303       AND      petc.enrt_typ_cycl_cd = 'L'
3304       AND      petc.business_group_id = p_business_group_id
3305       AND      l_lf_evt_ocrd_dt BETWEEN petc.effective_start_date
3306                    AND petc.effective_end_date;
3307     -- Gets all information on the plip which is needed
3308     --
3309     CURSOR c_plip_info IS
3310       SELECT   bpf.plip_id,
3311                bpf.dflt_flag,
3312                bpf.enrt_cd,
3313                bpf.enrt_rl,
3314                bpf.enrt_mthd_cd,
3315                bpf.auto_enrt_mthd_rl,
3316                bpf.alws_unrstrctd_enrt_flag,
3317                bpf.effective_start_date,
3318                bpf.effective_end_date,
3319                bpf.ordr_num
3320       FROM     ben_plip_f bpf
3321       WHERE    bpf.pl_id = l_pl_id
3322       AND      bpf.pgm_id = p_pgm_id
3323       AND      bpf.business_group_id = p_business_group_id
3324       AND      l_lf_evt_ocrd_dt BETWEEN bpf.effective_start_date
3325                    AND bpf.effective_end_date;
3326     -- Gets all information on the ptip which is needed
3327     --
3328     CURSOR c_ptip_info IS
3329       SELECT   ptip.ptip_id,
3330                ptip.enrt_cd,
3331                ptip.enrt_rl,
3332                ptip.enrt_mthd_cd,
3333                ptip.auto_enrt_mthd_rl,
3334                ptip.effective_start_date,
3335                ptip.effective_end_date,
3336                ptip.ordr_num
3337       FROM     ben_ptip_f ptip
3338       WHERE    ptip.pl_typ_id = l_pl_typ_id
3339       AND      ptip.pgm_id = p_pgm_id
3340       AND      ptip.business_group_id = p_business_group_id
3341       AND      l_lf_evt_ocrd_dt BETWEEN ptip.effective_start_date
3342                    AND ptip.effective_end_date;
3343     --
3344     -- Returns one row if any oipls exist for the plan
3345     --
3346     CURSOR c_any_oipl_for_plan IS                                -- oipl exists
3347       SELECT   NULL
3348       FROM     ben_oipl_f cop
3349       WHERE    cop.pl_id = l_pl_id
3350       AND      business_group_id = p_business_group_id
3351       AND      l_lf_evt_ocrd_dt BETWEEN cop.effective_start_date
3352                    AND cop.effective_end_date;
3353     --
3354     -- Get level restriction
3355     --
3356     --
3357     CURSOR c_ler_bnft_rstrn IS
3358       SELECT   '4',
3359                plip.pgm_id,
3360                oipl.ordr_num,
3361                plip.bnft_or_option_rstrctn_cd,
3362                lbr.cvg_incr_r_decr_only_cd,
3363                lbr.mx_cvg_mlt_incr_num,
3364                lbr.mx_cvg_mlt_incr_wcf_num
3365       FROM     ben_oipl_f oipl, ben_ler_bnft_rstrn_f lbr, ben_plip_f plip
3366       WHERE    plip.plip_id = l_plip_id
3367       AND      plip.business_group_id = p_business_group_id
3368       AND      plip.bnft_or_option_rstrctn_cd = 'OPT'
3369       AND      l_lf_evt_ocrd_dt BETWEEN plip.effective_start_date
3370                    AND plip.effective_end_date
3371       AND      oipl.oipl_id = p_oipl_id
3372       AND      oipl.pl_id = plip.pl_id
3373       AND      oipl.business_group_id = p_business_group_id
3374       AND      l_lf_evt_ocrd_dt BETWEEN oipl.effective_start_date
3375                    AND oipl.effective_end_date
3376       AND      lbr.plip_id = plip.plip_id
3377       AND      lbr.ler_id = p_ler_id
3378       AND      lbr.business_group_id = p_business_group_id
3379       AND      l_lf_evt_ocrd_dt BETWEEN lbr.effective_start_date
3380                    AND lbr.effective_end_date
3381       UNION ALL
3382       SELECT   '3',
3383                TO_NUMBER(NULL),
3384                oipl.ordr_num,
3385                pl.bnft_or_option_rstrctn_cd,
3386                lbr.cvg_incr_r_decr_only_cd,
3387                lbr.mx_cvg_mlt_incr_num,
3388                lbr.mx_cvg_mlt_incr_wcf_num
3389       FROM     ben_oipl_f oipl, ben_ler_bnft_rstrn_f lbr, ben_pl_f pl
3390       WHERE    pl.pl_id = l_pl_id
3391       AND      pl.business_group_id = p_business_group_id
3392       AND      l_lf_evt_ocrd_dt BETWEEN pl.effective_start_date
3393                    AND pl.effective_end_date
3394       AND      oipl.oipl_id = p_oipl_id
3395       AND      oipl.pl_id = pl.pl_id
3396       AND      oipl.business_group_id = p_business_group_id
3397       AND      l_lf_evt_ocrd_dt BETWEEN oipl.effective_start_date
3398                    AND oipl.effective_end_date
3399       AND      lbr.pl_id = pl.pl_id
3400       AND      lbr.plip_id IS NULL
3401       AND      lbr.ler_id = p_ler_id
3402       AND      pl.bnft_or_option_rstrctn_cd = 'OPT'
3403       AND      lbr.business_group_id = p_business_group_id
3404       AND      l_lf_evt_ocrd_dt BETWEEN lbr.effective_start_date
3405                    AND lbr.effective_end_date;
3406     --
3407     --
3408     /*
3409         --
3410         CURSOR c_pl_bnft_rstrn IS
3411           SELECT   '2',
3412                    plip.pgm_id,
3413                    oipl.ordr_num,
3414                    plip.bnft_or_option_rstrctn_cd,
3415                    plip.cvg_incr_r_decr_only_cd,
3416                    plip.mx_cvg_mlt_incr_num,
3417                    plip.mx_cvg_mlt_incr_wcf_num
3418           FROM     ben_oipl_f oipl, ben_plip_f plip
3419           WHERE    plip.plip_id = l_plip_id
3420           AND      plip.bnft_or_option_rstrctn_cd = 'OPT'
3421           AND      plip.business_group_id = p_business_group_id
3422           AND      l_lf_evt_ocrd_dt BETWEEN plip.effective_start_date
3423                        AND plip.effective_end_date
3424           AND      oipl.oipl_id = p_oipl_id
3425           AND      oipl.pl_id = plip.pl_id
3426           AND      oipl.business_group_id = p_business_group_id
3427           AND      l_lf_evt_ocrd_dt BETWEEN oipl.effective_start_date
3428                        AND oipl.effective_end_date
3429           UNION ALL
3430           SELECT   '1',
3431                    TO_NUMBER(NULL),
3432                    oipl.ordr_num,
3433                    pl.bnft_or_option_rstrctn_cd,
3434                    pl.cvg_incr_r_decr_only_cd,
3435                    pl.mx_cvg_mlt_incr_num,
3436                    pl.mx_cvg_mlt_incr_wcf_num
3437           FROM     ben_oipl_f oipl, ben_pl_f pl
3438           WHERE    pl.pl_id = l_pl_id
3439           AND      pl.bnft_or_option_rstrctn_cd = 'OPT'
3440           AND      pl.business_group_id = p_business_group_id
3441           AND      l_lf_evt_ocrd_dt BETWEEN pl.effective_start_date
3442                        AND pl.effective_end_date
3443           AND      oipl.oipl_id = p_oipl_id
3444           AND      oipl.pl_id = pl.pl_id
3445           AND      oipl.business_group_id = p_business_group_id
3446           AND      l_lf_evt_ocrd_dt BETWEEN oipl.effective_start_date
3447                        AND oipl.effective_end_date;
3448         --**
3449     */
3450 --**
3451   --
3452   -- get the oipl enrollment for this plan (may not be this oipl)
3453   --
3454   --
3455     CURSOR c_oipl_enrt_in_pl IS
3456       SELECT   enrd_oipl.ordr_num
3457       FROM     ben_prtt_enrt_rslt_f pen, ben_oipl_f enrd_oipl
3458       WHERE
3459                -- get result for plan if exists
3460                pen.person_id = p_person_id
3461       AND      pen.business_group_id = p_business_group_id
3462       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
3463       AND      pen.sspndd_flag = 'N'
3464       AND      pen.effective_end_date = hr_api.g_eot
3465       AND      pen.enrt_cvg_thru_dt >= l_lf_evt_ocrd_dt_1
3466       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
3467       AND      pen.pl_id = l_pl_id
3468       -- get enrolled oipl
3469       AND      enrd_oipl.oipl_id = pen.oipl_id
3470       AND      enrd_oipl.business_group_id = p_business_group_id
3471       AND      l_lf_evt_ocrd_dt BETWEEN enrd_oipl.effective_start_date
3472                    AND enrd_oipl.effective_end_date;
3473     --
3474     -- get the oipl coverage for this plan (may not be this oipl)
3475     --
3476     --
3477     CURSOR c_oipl_cvg_in_pl IS
3478       SELECT   enrd_oipl.ordr_num
3479       FROM     ben_prtt_enrt_rslt_f pen,
3480                ben_elig_cvrd_dpnt_f pdp,
3481                ben_oipl_f enrd_oipl
3482       WHERE    pdp.dpnt_person_id = p_person_id
3483       AND      pdp.effective_end_date = hr_api.g_eot
3484       AND      l_lf_evt_ocrd_dt_1 BETWEEN pdp.cvg_strt_dt AND pdp.cvg_thru_dt
3485       AND      pdp.business_group_id = p_business_group_id
3486       AND      pdp.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
3487       -- get result for plan if exists
3488       AND      pen.business_group_id = p_business_group_id
3489       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
3490       AND      pen.sspndd_flag = 'N'
3491       AND      pen.effective_end_date = hr_api.g_eot
3492       AND      pen.enrt_cvg_thru_dt >= l_lf_evt_ocrd_dt_1
3493       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
3494       AND      pen.pl_id = l_pl_id
3495       -- get enrolled oipl
3496       AND      enrd_oipl.oipl_id = pen.oipl_id
3497       AND      enrd_oipl.business_group_id = p_business_group_id
3498       AND      l_lf_evt_ocrd_dt BETWEEN enrd_oipl.effective_start_date
3499                    AND enrd_oipl.effective_end_date;
3500     --
3501     --
3502     CURSOR c_get_min_max_ordr_num IS
3503       SELECT   MIN(cop.ordr_num),
3504                MAX(cop.ordr_num)
3505       FROM     ben_oipl_f cop
3506       WHERE    cop.pl_id = l_pl_id
3507       AND      l_lf_evt_ocrd_dt BETWEEN cop.effective_start_date
3508                    AND cop.effective_end_date
3509       AND      cop.business_group_id = p_business_group_id;
3510     --
3511     l_latest_procd_dt              DATE;
3512     l_backed_out_date              DATE;
3513     l_orig_epsd                    DATE;
3514     --
3515 /*
3516     cursor c_regn_125_or_129 is
3517       select   'Y'
3518       from     ben_pl_regn_f prg,
3519                ben_regn_f regn
3520       where    prg.pl_id=l_pl_id
3521            and p_effective_date between
3522                prg.effective_start_date and prg.effective_end_date
3523            and prg.business_group_id=p_business_group_id
3524            and regn.regn_id=prg.regn_id
3525            and regn.name in ('IRC Section 125','IRC Section 129')
3526            and p_effective_date between
3527                regn.effective_start_date and regn.effective_end_date
3528            and regn.business_group_id=p_business_group_id
3529       ;
3530 */
3531   --
3532   -- following requery logic added for bug 1394507 - 9 cursors
3533   --
3534   cursor c_pgm_requery(p_id number,p_ed date) is
3535     select 'Y'
3536     from ben_pgm_f pgm
3537     where pgm_id=p_id and
3538           business_group_id=p_business_group_id and
3539           p_ed between effective_start_date and effective_end_date
3540     ;
3541   --
3542   cursor c_plip_requery(p_id number,p_ed date) is
3543     select 'Y'
3544     from ben_plip_f plip
3545     where plip_id=p_id and
3546           business_group_id=p_business_group_id and
3547           p_ed between effective_start_date and effective_end_date
3548     ;
3549   --
3550   cursor c_ptip_requery(p_id number,p_ed date) is
3551     select 'Y'
3552     from ben_ptip_f ptip
3553     where ptip_id=p_id and
3554           business_group_id=p_business_group_id and
3555           p_ed between effective_start_date and effective_end_date
3556     ;
3557   --
3558   cursor c_oipl_requery(p_id number,p_ed date) is
3559     select 'Y'
3560     from ben_oipl_f oipl
3561     where oipl_id=p_id and
3562           business_group_id=p_business_group_id and
3563           p_ed between effective_start_date and effective_end_date
3564     ;
3565   --
3566   cursor c_opt_requery(p_id number,p_ed date) is
3567     select 'Y'
3568     from ben_opt_f opt
3569     where opt_id=p_id and
3570           business_group_id=p_business_group_id and
3571           p_ed between effective_start_date and effective_end_date
3572     ;
3573   --
3574   cursor c_plan_requery(p_id number,p_ed date) is
3575     select 'Y'
3576     from ben_pl_f plan
3577     where pl_id=p_id and
3578           business_group_id=p_business_group_id and
3579           p_ed between effective_start_date and effective_end_date
3580     ;
3581   --
3582   cursor c_pl_typ_requery(p_id number,p_ed date) is
3583     select 'Y'
3584     from ben_pl_typ_f pl_typ
3585     where pl_typ_id=p_id and
3586           business_group_id=p_business_group_id and
3587           p_ed between effective_start_date and effective_end_date
3588     ;
3589   --
3590   cursor c_lee_rsn_requery(p_id number,p_ed date) is
3591     select 'Y'
3592     from ben_lee_rsn_f lee_rsn
3593     where lee_rsn_id=p_id and
3594           business_group_id=p_business_group_id and
3595           p_ed between effective_start_date and effective_end_date
3596     ;
3597   --
3598   cursor c_ler_requery(p_id number,p_ed date) is
3599     select 'Y'
3600     from ben_ler_f ler
3601     where ler_id=p_id and
3602           business_group_id=p_business_group_id and
3603           p_ed between effective_start_date and effective_end_date
3604     ;
3605   --
3606   -- unrestricted process change
3607   cursor c_prtt_enrt_rslt(l_prtt_enrt_rslt_id number) is
3608     select min(effective_start_date)
3609     from   ben_prtt_enrt_rslt_f
3610     where  prtt_enrt_rslt_id = l_prtt_enrt_rslt_id;
3611   l_effective_start_date date;
3612   --
3613   cursor c_opt_level is
3614     select oipl2.ordr_num
3615     from   ben_oipl_f oipl,
3616            ben_oipl_f oipl2
3617     where  oipl.oipl_id  = p_oipl_id
3618     and    oipl.pl_id   = oipl2.pl_id
3619     and    oipl2.oipl_stat_cd = 'A'
3620     and    oipl.business_group_id = p_business_group_id
3621     and    l_lf_evt_ocrd_dt BETWEEN oipl.effective_start_date
3622                    AND oipl.effective_end_date
3623     and    oipl2.business_group_id = p_business_group_id
3624     and      l_lf_evt_ocrd_dt BETWEEN oipl2.effective_start_date
3625                    AND oipl2.effective_end_date
3626     order by 1;
3627   --
3628 
3629   --
3630   l_cnt          number := 0;
3631   l_oipl_seq_num number ;
3632   l_enrd_seq_num number ;
3633   l_found        boolean := FALSE;
3634   l_opt_level    number;
3635   l_new_cvg_strt  varchar2(1) := 'N';
3636   l_cvg_dt       date;
3637   l_enrt_cd_level varchar2(30);
3638 
3639 
3640   --
3641   -- CWB Chnages.
3642   --
3643   l_emp_epe_id   number;
3644   l_inelg_rsn_cd ben_elig_per_f.inelg_rsn_cd%type; -- 2650247
3645 
3646   -- CWBITEM
3647   l_emp_pel_id   number;
3648   l_pel_id       number;
3649   --
3650 
3651   -- CWBITEM
3652 /*  cursor c_cwb_hrchy(cv_emp_epe_id in number) is
3653    select emp_elig_per_elctbl_chc_id
3654    from ben_cwb_mgr_hrchy
3655    where emp_elig_per_elctbl_chc_id = cv_emp_epe_id; */
3656   --
3657   cursor c_hrchy(cv_emp_epe_id number) is
3658    select hrc.emp_pil_elctbl_chc_popl_id,
3659           pel.pil_elctbl_chc_popl_id
3660    from ben_elig_per_elctbl_chc epe,
3661         ben_pil_elctbl_chc_popl pel,
3662         ben_cwb_hrchy hrc
3663    where pel.pil_elctbl_chc_popl_id = epe.pil_elctbl_chc_popl_id
3664      and epe.elig_per_elctbl_chc_id = cv_emp_epe_id
3665      and hrc.emp_pil_elctbl_chc_popl_id(+) = pel.pil_elctbl_chc_popl_id;
3666   --
3667   -- BUG 6519487 fix
3668   l_dummy_varchar varchar2(30);
3669   l_current_pl_typ_id number;
3670   --END BUG 6519487 fix
3671   /*Start AMN Bug 14653541: Commenting the below fixes
3672   --Start AMN Bug 14661357
3673   CURSOR c_ler_oipl_dflt_flag IS
3674     SELECT   leo.dflt_flag
3675     FROM     ben_ler_chg_oipl_enrt_f leo
3676     WHERE    p_oipl_id = leo.oipl_id
3677     AND      p_ler_id = leo.ler_id
3678     AND      p_effective_date BETWEEN leo.effective_start_date
3679                  AND leo.effective_end_date;
3680   l_ler_oipl_dflt_flag varchar2(30);
3681   --End AMN Bug 14661357
3682   End AMN Bug 14653541: Commenting the below fixes*/
3683   BEGIN
3684     --
3685     g_debug := hr_utility.debug_enabled;
3686     hr_utility.set_location('Entering:' || l_proc, 10);
3687     --
3688     -- If the run_mode is not "life event" or "scheduled" DONE
3689     -- Bug 2200139 Added 'V' mode for override
3690     -- ABSENCES - added absence mode. Added GRADE/STEP
3691     -- iRec - Added mode 'I'
3692     --
3693     IF p_run_mode NOT IN ('L', 'C', 'U','W','V', 'M','G', 'I','D') THEN
3694       --
3695       fnd_message.set_name('BEN', 'BEN_91458_DENRR_MODE_INVALID');
3696       fnd_message.set_token('PROC', l_proc);
3697       fnd_message.set_token('MODE', p_run_mode);
3698       fnd_message.set_token('PERSON_ID', TO_CHAR(p_person_id));
3699       RAISE ben_manage_life_events.g_record_error;
3700     --
3701     END IF;
3702     --
3703     -- Get option information if an oipl_id is passed,
3704     -- need to do this before getting oipl eligibility.
3705     --
3706     IF (p_oipl_id IS NOT NULL) THEN
3707       --
3708       -- get oipl information
3709       --
3710       if g_debug then
3711       hr_utility.set_location('OIPL NN: ' || l_proc, 10);
3712       end if;
3713       --
3714       -- Bug 2200139 For Override call the cache routine else call the benmnglecache
3715       -- this is not required as the data is fetched on the benovrrd.pkb
3716       --IF p_run_mode = 'V' THEN
3717       --  --
3718       --  ben_cobj_cache.get_oipl_dets (
3719       --     p_business_group_id => p_business_group_id
3720       --    ,p_effective_date    => p_effective_date
3721       --    ,p_oipl_id           => p_oipl_id
3722       --    ,p_inst_row          => l_oipl_rec
3723       --    ) ;
3724       --  --
3725       --ELSE
3726         --
3727         l_oipl_rec := ben_cobj_cache.g_oipl_currow;
3728         l_oipl_name :=               ben_cobj_cache.g_opt_currow.name;
3729         --
3730       --END IF;
3731       --
3732       l_pl_id :=                   l_oipl_rec.pl_id;
3733       l_oipl_dflt_flag :=          l_oipl_rec.dflt_flag;
3734       l_opt_id :=                  l_oipl_rec.opt_id;
3735       l_mndtry_flag :=             l_oipl_rec.mndtry_flag;
3736       l_mndtry_rl :=               l_oipl_rec.mndtry_rl;
3737       l_oipl_auto_enrt_flag :=     l_oipl_rec.auto_enrt_flag;
3738       l_oipl_auto_enrt_mthd_rl :=  l_oipl_rec.auto_enrt_mthd_rl;
3739       l_oipl_trk_inelig_per_flag := l_oipl_rec.trk_inelig_per_flag;
3740       --
3741       -- l_oipl_name :=               ben_cobj_cache.g_opt_currow.name;
3742       if g_debug then
3743       hr_utility.set_location('DONE OIPL NN: ' || l_proc, 10);
3744       end if;
3745     --
3746     ELSE
3747       --
3748       l_pl_id :=  p_pl_id;
3749     --
3750     END IF;
3751     --
3752     -- get plan cache row
3753     --
3754     ben_comp_object.get_object(p_pl_id => l_pl_id, p_rec => l_plan_rec);
3755     if g_debug then
3756     hr_utility.set_location('Done PLN cac: ' || l_proc, 10);
3757     hr_utility.set_location(
3758       'Plan name is ' || SUBSTR(l_plan_rec.name, 1, 30),
3759       17);
3760     end if;
3761     --
3762     -- Get pgm cache row if needed
3763     --
3764     IF p_pgm_id IS NOT NULL THEN
3765     if g_debug then
3766       hr_utility.set_location('PGM NN 2: ' || l_proc, 10);
3767     end if;
3768       ben_comp_object.get_object(p_pgm_id => p_pgm_id, p_rec => l_pgm_rec);
3769       if g_debug then
3770       hr_utility.set_location('Done PGM NN 2: ' || l_proc, 10);
3771       hr_utility.set_location(
3772         'Pgm name is ' || SUBSTR(l_pgm_rec.name, 1, 30),
3773         18);
3774       end if;
3775     END IF;
3776     --
3777     -- Check required parameters of run_mode, person_id, pl_id or oipl_id,
3778     -- business_group_id, and ler_id.
3779     --
3780     IF (
3781             p_run_mode IS NULL
3782          OR p_business_group_id IS NULL
3783          OR p_effective_date IS NULL
3784          OR p_ler_id IS NULL
3785          OR p_person_id IS NULL
3786          OR l_pl_id IS NULL) THEN
3787       --
3788       if g_debug then
3789       hr_utility.set_location('error', 19);
3790       end if;
3791       fnd_message.set_name('BEN', 'BEN_91737_ENRT_REQ_MISS_PARM');
3792       fnd_message.set_token('PROC', l_proc);
3793       fnd_message.set_token('MODE', p_run_mode);
3794       fnd_message.set_token('BG_ID', TO_CHAR(p_business_group_id));
3795       fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
3796       fnd_message.set_token('LER_ID', TO_CHAR(p_ler_id));
3797       fnd_message.set_token('PERSON_ID', TO_CHAR(p_person_id));
3798       fnd_message.set_token('PL_ID', TO_CHAR(l_pl_id));
3799       RAISE ben_manage_life_events.g_record_error;
3800     --
3801     END IF;
3802     --
3803 /*  -- 4031733 - Cursor c_state populates l_state variable which is no longer
3804     -- used in the package. Cursor can be commented
3805 
3806     IF p_person_id IS NOT NULL THEN
3807       OPEN c_state;
3808       FETCH c_state INTO l_state;
3809       CLOSE c_state;
3810       hr_utility.set_location('close c_state: ' || l_proc, 10);
3811       --
3812       --IF l_state.region_2 IS NOT NULL THEN
3813         --
3814       --  l_jurisdiction_code :=
3815       --    pay_mag_utils.lookup_jurisdiction_code(p_state => l_state.region_2);
3816       --
3817      -- END IF;
3818     --
3819     END IF;
3820 */
3821     --
3822     OPEN c_asg;
3823     FETCH c_asg INTO l_rec_assignment_id, l_rec_organization_id;
3824     IF c_asg%NOTFOUND THEN
3825       CLOSE c_asg;
3826       hr_utility.set_location('error', 20);
3827       fnd_message.set_name('BEN', 'BEN_92106_PRTT_NO_ASGN');
3828       fnd_message.set_token('PROC', l_proc);
3829       fnd_message.set_token('PERSON_ID', TO_CHAR(p_person_id));
3830       fnd_message.set_token('LF_EVT_OCRD_DT', TO_CHAR(p_lf_evt_ocrd_dt));
3831       fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
3832       RAISE ben_manage_life_events.g_record_error;
3833     END IF;
3834     CLOSE c_asg;
3835     hr_utility.set_location('close c_asg: ' || l_proc, 10);
3836     --
3837     -- Determine if the person is currently enrolled and if so
3838     -- determine the coverage start date.
3839     --
3840     IF p_run_mode in ('M','U') then
3841        l_cvg_dt := l_lf_evt_ocrd_dt;
3842     ELSE
3843        l_cvg_dt := l_lf_evt_ocrd_dt_1;
3844     END IF;
3845 
3846   IF p_run_mode <> 'D' THEN
3847    --
3848     ------------Bug 8846328
3849     l_fut_rslt_exist := false;
3850     l_crnt_enrt_sspndd_flag := 'N';
3851     -------------Bug 8846328
3852     IF (p_oipl_id IS NULL)  THEN
3853       --
3854       --8399189
3855       OPEN c_plan_enrolment_info(l_cvg_dt,p_run_mode);
3856       --
3857       FETCH c_plan_enrolment_info INTO l_crnt_enrt_cvg_strt_dt,
3858                                      l_crnt_erlst_deenrt_dt,
3859                                      l_prtt_enrt_rslt_id,
3860                                      l_enrt_ovridn_flag,
3861                                      l_enrt_ovrid_thru_dt,
3862                                      l_orgnl_enrt_dt,
3863                                      l_crnt_enrt_cvg_thru_dt,  --BUG 6519487 fix
3864                                      l_current_pl_typ_id ;  --BUG 6519487 fix
3865       --
3866       IF c_plan_enrolment_info%NOTFOUND THEN
3867         --
3868         l_crnt_enrt_cvg_strt_dt :=  NULL;
3869         --
3870         --  Check if person is a covered dependent - COBRA.
3871         --
3872         IF p_pgm_id IS NOT NULL THEN
3873           IF l_pgm_rec.pgm_typ_cd LIKE 'COBRA%' THEN
3874             OPEN c_plan_cvg_info;
3875             FETCH c_plan_cvg_info INTO l_dpnt_cvrd_flag;
3876             CLOSE c_plan_cvg_info;
3877           END IF;
3878         END IF;
3879       --
3880       ELSE
3881         --BUG 6519487 fix
3882         IF l_crnt_enrt_cvg_thru_dt <> hr_api.g_eot THEN
3883           OPEN c_future_results (p_person_id ,
3884                              l_crnt_enrt_cvg_thru_dt,
3885                              p_pgm_id   ,
3886                              l_current_pl_typ_id) ;
3887           --
3888           FETCH c_future_results INTO l_future_results;--Bug 8453712,l_dummy_varchar;
3889           IF c_future_results%FOUND THEN
3890 	    if l_future_results.pl_id <> l_pl_id then
3891 	    hr_utility.set_location('in if',10.1);
3892              --
3893              l_crnt_enrt_cvg_strt_dt := null;
3894              l_crnt_erlst_deenrt_dt := null;
3895              l_prtt_enrt_rslt_id := null;
3896              l_enrt_ovridn_flag := null;
3897              l_enrt_ovrid_thru_dt := null;
3898              l_crnt_enrt_cvg_thru_dt := null;
3899              --
3900 	    else  --Bug 8453712
3901 	     hr_utility.set_location('in else',10.1);
3902 	     l_fut_rslt_exist := true;  -------------Bug 8846328
3903 	     l_crnt_enrt_cvg_strt_dt := l_future_results.enrt_cvg_strt_dt;
3904              l_crnt_erlst_deenrt_dt := l_future_results.erlst_deenrt_dt;
3905              l_prtt_enrt_rslt_id := l_future_results.prtt_enrt_rslt_id;
3906              l_enrt_ovridn_flag := l_future_results.enrt_ovridn_flag;
3907              l_enrt_ovrid_thru_dt := l_future_results.enrt_ovrid_thru_dt;
3908              l_crnt_enrt_cvg_thru_dt := l_future_results.enrt_cvg_thru_dt;
3909 	    end if;
3910           END IF;
3911           --
3912           CLOSE c_future_results ;
3913         END IF;
3914         --END BUG 6519487 fix
3915         --
3916       END IF;
3917       --
3918       CLOSE c_plan_enrolment_info;
3919       if g_debug then
3920       hr_utility.set_location('close c_PEI: ' || l_proc, 10);
3921       end if;
3922     --
3923     ELSE
3924       --
3925       OPEN c_oipl_enrolment_info(l_cvg_dt,p_run_mode);
3926       --
3927       FETCH c_oipl_enrolment_info INTO l_crnt_enrt_cvg_strt_dt,
3928                                        l_crnt_erlst_deenrt_dt,
3929                                        l_prtt_enrt_rslt_id,
3930                                        l_enrt_ovridn_flag,
3931                                        l_enrt_ovrid_thru_dt,
3932                                        l_crnt_enrt_cvg_thru_dt, --BUG 6519487 fix
3933 				       l_crnt_enrt_sspndd_flag,  ------------Bug 8846328
3934                                        l_current_pl_typ_id;   --BUG 6519487 fix      --
3935       IF c_oipl_enrolment_info%NOTFOUND THEN
3936         --
3937         l_crnt_enrt_cvg_strt_dt :=  NULL;
3938         --
3939         --  Check if person is a covered dependent - COBRA.
3940         --
3941         IF p_pgm_id IS NOT NULL THEN
3942           IF l_pgm_rec.pgm_typ_cd LIKE 'COBRA%' THEN
3943             OPEN c_oipl_cvg_info;
3944             FETCH c_oipl_cvg_info INTO l_dpnt_cvrd_flag;
3945             CLOSE c_oipl_cvg_info;
3946           END IF;
3947         END IF;
3948       --
3949       ELSE
3950       ----BUG 6519487 fix
3951         IF l_crnt_enrt_cvg_thru_dt <> hr_api.g_eot THEN
3952           OPEN c_future_results (p_person_id ,
3953                                l_crnt_enrt_cvg_thru_dt,
3954                                p_pgm_id   ,
3955                                l_current_pl_typ_id) ;
3956           --
3957           FETCH c_future_results INTO l_future_results ;-----Bug 8453712,l_dummy_varchar;
3958           IF c_future_results%FOUND THEN
3959              if (l_future_results.pl_id <> l_pl_id -------Bug 8768050
3960 	         or
3961 		 l_future_results.pl_id = l_pl_id and l_future_results.oipl_id <> p_oipl_id) then  --10211081
3962 
3963 	     hr_utility.set_location('in if',10.1);
3964              --
3965              l_crnt_enrt_cvg_strt_dt := null;
3966              l_crnt_erlst_deenrt_dt := null;
3967              l_prtt_enrt_rslt_id := null;
3968              l_enrt_ovridn_flag := null;
3969              l_enrt_ovrid_thru_dt := null;
3970              l_crnt_enrt_cvg_thru_dt := null;
3971            else  ----Bug 8768050
3972 	     hr_utility.set_location('in else',10.1);
3973 	     l_fut_rslt_exist := true;  -------------Bug 8846328
3974 	     l_crnt_enrt_cvg_strt_dt := l_future_results.enrt_cvg_strt_dt;
3975              l_crnt_erlst_deenrt_dt := l_future_results.erlst_deenrt_dt;
3976              l_prtt_enrt_rslt_id := l_future_results.prtt_enrt_rslt_id;
3977              l_enrt_ovridn_flag := l_future_results.enrt_ovridn_flag;
3978              l_enrt_ovrid_thru_dt := l_future_results.enrt_ovrid_thru_dt;
3979              l_crnt_enrt_cvg_thru_dt := l_future_results.enrt_cvg_thru_dt;
3980 	    end if; -------Bug 8768050
3981           END IF;
3982           CLOSE c_future_results ;
3983         END IF;
3984         --END BUG 6519487 fix
3985       --
3986       END IF;
3987       --
3988       CLOSE c_oipl_enrolment_info;
3989       if g_debug then
3990       hr_utility.set_location('close c_OIEI: ' || l_proc, 10);
3991       end if;
3992     --
3993     END IF;
3994     --
3995   END IF;
3996     -- Bug 2200139 For Override don't associate the current enrollment
3997     --
3998     if p_run_mode = 'V' then
3999       --
4000       l_crnt_enrt_cvg_strt_dt := null;
4001       l_prtt_enrt_rslt_id := null;
4002       --
4003     end if;
4004     --
4005     -- unrestricted process changes
4006     -- if mode is unrestricted and crnt_enrt_strt_date > p_effective_date assign null
4007     -- as unrestricted may be processed before the previously processed life event
4008     --
4009     if p_run_mode = 'U' then
4010         --
4011         if l_crnt_enrt_cvg_strt_dt is not null  then
4012             --
4013             --  Bug 2290302 see the Bug for datails. We cann't have this
4014             -- condition as user may have the coverage started in future
4015             -- for the current enrollment.
4016             -- if l_crnt_enrt_cvg_strt_dt > p_effective_date then
4017             --    l_crnt_enrt_cvg_strt_dt := null;
4018             --    l_prtt_enrt_rslt_id := null;
4019             --
4020             -- else
4021                --
4022                open c_prtt_enrt_rslt(l_prtt_enrt_rslt_id);
4023                fetch c_prtt_enrt_rslt into l_effective_start_date;
4024                close c_prtt_enrt_rslt;
4025                --
4026                if l_effective_start_date > p_effective_date then
4027                   l_crnt_enrt_cvg_strt_dt := null;
4028                   l_prtt_enrt_rslt_id := null;
4029                end if;
4030               --
4031             --  end if;
4032         end if;
4033     end if;
4034     --
4035     -- Determine if the person is eligible for this compensation object.
4036     --
4037     ben_pep_cache.get_currpepepo_dets
4038       (p_comp_obj_tree_row => p_comp_obj_tree_row
4039       ,p_per_in_ler_id     => p_per_in_ler_id
4040       ,p_effective_date    => p_effective_date
4041       ,p_pgm_id            => p_pgm_id
4042       ,p_pl_id             => l_pl_id
4043       ,p_oipl_id           => p_oipl_id
4044       ,p_opt_id            => l_opt_id
4045       --
4046       ,p_inst_row          => l_currpep_dets
4047       );
4048     --
4049     IF l_currpep_dets.elig_per_id is null THEN
4050       --
4051       l_current_eligibility :=  'N';
4052       --
4053       If NVL(l_currpep_dets.inelg_rsn_cd, 'OTH') = 'OTH'
4054         and nvl(ben_evaluate_elig_profiles.g_inelg_rsn_cd,'OTH') <> 'OTH'
4055         and p_run_mode = 'W'
4056       then     -- Bug 4447114, If condition added
4057           l_inelg_rsn_cd	      := ben_evaluate_elig_profiles.g_inelg_rsn_cd ;
4058       else
4059           l_inelg_rsn_cd	      := l_currpep_dets.inelg_rsn_cd ;
4060       end if;
4061       --
4062     else
4063       --
4064       l_elig_per_id           := l_currpep_dets.elig_per_id;
4065       l_current_eligibility   := l_currpep_dets.elig_flag;
4066       l_must_enrl_anthr_pl_id := l_currpep_dets.must_enrl_anthr_pl_id;
4067       l_prtn_strt_dt          := l_currpep_dets.prtn_strt_dt;
4068       --l_inelg_rsn_cd	      := l_currpep_dets.inelg_rsn_cd;      -- 2650247
4069       --
4070       If NVL(l_currpep_dets.inelg_rsn_cd, 'OTH') = 'OTH'
4071         and nvl(ben_evaluate_elig_profiles.g_inelg_rsn_cd,'OTH') <> 'OTH'
4072         and p_run_mode = 'W'
4073       then  -- Bug 4447114, If condition added
4074           l_inelg_rsn_cd	      := ben_evaluate_elig_profiles.g_inelg_rsn_cd ;
4075       else
4076           l_inelg_rsn_cd	      := l_currpep_dets.inelg_rsn_cd ;
4077       end if;
4078       --
4079     END IF;
4080     if g_debug then
4081     hr_utility.set_location('Got passed initial comp loads', 21);
4082     end if;
4083     --
4084     -- If the current_eligibility is N, DONE, no choice is required.
4085     --  ...(12/23/1998 except when overridden, and thru date >= ed jcarpent)
4086     --
4087     -- combine both ovrid(n) fields into one as to simplify for use
4088     -- further down in the code.
4089     --
4090     IF (
4091              l_enrt_ovridn_flag = 'Y'
4092          AND l_enrt_ovrid_thru_dt >= NVL(p_lf_evt_ocrd_dt, p_effective_date)) THEN
4093       l_enrt_ovridn_flag :=  'Y';
4094     ELSE
4095       l_enrt_ovridn_flag :=  'N';
4096     END IF;
4097     --
4098     -- Now, can we elect?
4099     --
4100      --cwb changes
4101      --Bug 2200139 Override Enrollment Changes
4102     IF l_current_eligibility = 'N'
4103        AND l_enrt_ovridn_flag = 'N' and p_run_mode <> 'W' and p_run_mode <> 'V' THEN
4104       --
4105       p_electable_flag :=  'N';
4106       --
4107       if g_debug then
4108       hr_utility.set_location(' Leaving:' || l_proc, 15);
4109       end if;
4110       --
4111       RETURN;
4112     --
4113     END IF;
4114     --
4115     --
4116     -- Determine if the person was previously eligible for this comp object.
4117     --
4118   IF p_run_mode <> 'D' THEN
4119    --
4120     IF (p_oipl_id IS NULL) THEN
4121       --
4122       ben_pep_cache.get_pilpep_dets
4123         (p_person_id         => p_person_id
4124         ,p_business_group_id => p_business_group_id
4125         ,p_effective_date    => l_effective_date_1
4126         ,p_pgm_id            => p_pgm_id
4127         ,p_pl_id             => l_pl_id
4128         ,p_plip_id           => null
4129         ,p_ptip_id           => null
4130         ,p_inst_row          => l_prevpep_rec
4131         );
4132       --
4133       if l_prevpep_rec.elig_flag is null
4134       then
4135         --
4136         l_previous_eligibility := 'N';
4137         --
4138       else
4139         --
4140         l_previous_eligibility := l_prevpep_rec.elig_flag;
4141         --
4142       end if;
4143       --
4144       if g_debug then
4145       hr_utility.set_location('close c_PEFP: ' || l_proc, 10);
4146       end if;
4147       --
4148     ELSE
4149       --
4150       ben_pep_cache.get_pilepo_dets
4151         (p_person_id         => p_person_id
4152         ,p_business_group_id => p_business_group_id
4153         ,p_effective_date    => l_effective_date_1 --p_effective_date
4154         ,p_pgm_id            => p_comp_obj_tree_row.par_pgm_id
4155         ,p_pl_id             => p_comp_obj_tree_row.par_pl_id
4156         ,p_opt_id            => p_comp_obj_tree_row.par_opt_id
4157         --
4158         ,p_inst_row          => l_prevepo_rec
4159         );
4160       --
4161       if l_prevepo_rec.elig_flag is null
4162       then
4163         --
4164         l_previous_eligibility := 'N';
4165         --
4166       else
4167         --
4168         l_previous_eligibility := l_prevepo_rec.elig_flag;
4169         --
4170       end if;
4171       --
4172       if g_debug then
4173       hr_utility.set_location('close c_PEFO: ' || l_proc, 10);
4174       end if;
4175       --
4176     END IF;
4177     --
4178   END IF;  --'D' mode
4179   if g_debug then
4180     hr_utility.set_location('get plan info', 10);
4181   end if;
4182     --
4183     -- get plan_info
4184     --
4185     l_pl_name :=                  l_plan_rec.name;
4186     l_pl_typ_id :=                l_plan_rec.pl_typ_id;
4187     l_pl_enrt_cd :=               l_plan_rec.enrt_cd;
4188     l_pl_enrt_rl :=               l_plan_rec.enrt_rl;
4189     l_pl_enrt_mthd_cd :=          l_plan_rec.enrt_mthd_cd;
4190     l_pl_auto_enrt_rl :=          l_plan_rec.auto_enrt_mthd_rl;
4191     l_invk_flx_cr_pl_flag :=      l_plan_rec.invk_flx_cr_pl_flag;
4192     l_imptd_incm_calc_cd :=       l_plan_rec.imptd_incm_calc_cd;
4193     l_pl_trk_inelig_per_flag :=   l_plan_rec.trk_inelig_per_flag;
4194     --
4195     -- If a pgm_id was passed
4196     --
4197     IF (p_pgm_id IS NOT NULL) THEN
4198       --
4199       -- Find the plip and get its needed attributes.
4200       --
4201       OPEN c_plip_info;
4202       --
4203       FETCH c_plip_info INTO l_plip_id,
4204                              l_plip_dflt_flag,
4205                              l_plip_enrt_cd,
4206                              l_plip_enrt_rl,
4207                              l_plip_enrt_mthd_cd,
4208                              l_plip_auto_enrt_rl,
4209                              l_alws_unrstrctd_enrt_flag,
4210                              l_plip_esd,
4211                              l_plip_eed,
4212                              l_plip_ordr_num;
4213       IF c_plip_info%NOTFOUND THEN
4214         --
4215         fnd_message.set_name('BEN', 'BEN_91461_PLIP_MISSING');
4216         fnd_message.set_token('PROC', l_proc);
4217         fnd_message.set_token('PGM_ID', TO_CHAR(p_pgm_id));
4218         fnd_message.set_token('PL_ID', TO_CHAR(l_pl_id));
4219         fnd_message.set_token('BG_ID', TO_CHAR(p_business_group_id));
4220         RAISE ben_manage_life_events.g_record_error;
4221       --
4222       END IF;
4223       --
4224       CLOSE c_plip_info;
4225       if g_debug then
4226       hr_utility.set_location('close c_plip_info: ' || l_proc, 10);
4227       end if;
4228       --
4229       -- Find the ptip and get its needed attributes.
4230       --
4231       OPEN c_ptip_info;
4232       --
4233       FETCH c_ptip_info INTO l_ptip_id,
4234                              l_ptip_enrt_cd,
4235                              l_ptip_enrt_rl,
4236                              l_ptip_enrt_mthd_cd,
4237                              l_ptip_auto_enrt_rl,
4238                              l_ptip_esd,
4239                              l_ptip_eed,
4240                              l_ptip_ordr_num;
4241       --
4242       IF c_ptip_info%NOTFOUND THEN
4243         --
4244         fnd_message.set_name('BEN', 'BEN_91462_PTIP_MISSING');
4245         fnd_message.set_token('PROC', l_proc);
4246         fnd_message.set_token('PGM_ID', TO_CHAR(p_pgm_id));
4247         fnd_message.set_token('PL_TYP_ID', TO_CHAR(l_pl_typ_id));
4248         fnd_message.set_token('BG_ID', TO_CHAR(p_business_group_id));
4249         RAISE ben_manage_life_events.g_record_error;
4250       --
4251       END IF;
4252       --
4253       CLOSE c_ptip_info;
4254       if g_debug then
4255       hr_utility.set_location('close c_ptip_info: ' || l_proc, 10);
4256       end if;
4257     --
4258     END IF;
4259 --
4260 -- Unrestricted processing
4261 --   for mode of U only let qualified plans through
4262 --   for other modes if plan is unrestricted process
4263 --   as normally do (i.e. set l_unrestricted_enrt_flag
4264 --   to 'N')
4265 --
4266 -- mode=U   unres_flag=Y   set flag   return
4267 --    N          N            N          N
4268 --    N          Y            N          N
4269 --    Y          N            n/a        Y
4270 --    Y          Y            Y          N
4271 --
4272     IF (p_pgm_id IS NULL) THEN
4273       l_alws_unrstrctd_enrt_flag :=  l_plan_rec.alws_unrstrctd_enrt_flag;
4274       if g_debug then
4275       hr_utility.set_location(
4276         'alws_unres_flag=' || l_alws_unrstrctd_enrt_flag,
4277         10);
4278       end if;
4279     END IF;
4280     --
4281     -- all that to do this
4282     --
4283     IF p_run_mode in ('U','D') THEN
4284       IF l_alws_unrstrctd_enrt_flag = 'Y' THEN
4285         l_unrestricted_enrt_flag :=  'Y';
4286 	if g_debug then
4287         hr_utility.set_location(
4288           'Unrestricted mode in force for this plan',
4289           10);
4290         end if;
4291       ELSE
4292         p_electable_flag :=  'N';
4293 	if g_debug then
4294         hr_utility.set_location('Unrestricted mode not for regular plans', 10);
4295 	end if;
4296         RETURN;
4297       END IF;
4298     ELSE
4299       l_unrestricted_enrt_flag :=  'N';
4300     END IF;
4301     --
4302     if g_debug then
4303     hr_utility.set_location('per in ler info', 20);
4304     end if;
4305     --
4306     -- Bug 2200139  this cursor is getting the Started Perinler info.
4307     -- for Override Mode we get the info of the p_ler_in_ler_id
4308     if p_run_mode = 'V' then
4309       OPEN c_ovrd_per_in_ler_info;
4310       --
4311       FETCH c_ovrd_per_in_ler_info INTO l_per_in_ler_id,
4312                                    l_ler_typ_cd,
4313                                    l_ler_name,
4314                                    l_lf_evt_ocrd_dt_fetch,
4315                                    l_ler_esd,
4316                                    l_ler_eed;
4317       --
4318       IF c_ovrd_per_in_ler_info%NOTFOUND THEN
4319         --
4320         fnd_message.set_name('BEN', 'BEN_91272_PER_IN_LER_MISSING');
4321         fnd_message.set_token('PROC', l_proc);
4322         fnd_message.set_token('PERSON_ID', TO_CHAR(p_person_id));
4323         fnd_message.set_token('LER_ID', TO_CHAR(p_ler_id));
4324         fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
4325         fnd_message.set_token('BG_ID', TO_CHAR(p_business_group_id));
4326         RAISE ben_manage_life_events.g_record_error;
4327       --
4328       END IF;
4329       --
4330       CLOSE c_ovrd_per_in_ler_info;
4331       if g_debug then
4332       hr_utility.set_location('close c_PILI: ' || l_proc, 10);
4333       end if;
4334       --
4335     else
4336       --
4337       OPEN c_per_in_ler_info;
4338       --
4339       FETCH c_per_in_ler_info INTO l_per_in_ler_id,
4340                                  l_ler_typ_cd,
4341                                  l_ler_name,
4342                                  l_lf_evt_ocrd_dt_fetch,
4343                                  l_ler_esd,
4344                                  l_ler_eed;
4345       --
4346       IF c_per_in_ler_info%NOTFOUND THEN
4347         --
4348         fnd_message.set_name('BEN', 'BEN_91272_PER_IN_LER_MISSING');
4349         fnd_message.set_token('PROC', l_proc);
4350         fnd_message.set_token('PERSON_ID', TO_CHAR(p_person_id));
4351         fnd_message.set_token('LER_ID', TO_CHAR(p_ler_id));
4352         fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
4353         fnd_message.set_token('BG_ID', TO_CHAR(p_business_group_id));
4354         RAISE ben_manage_life_events.g_record_error;
4355       --
4356       END IF;
4357       --
4358       CLOSE c_per_in_ler_info;
4359     end if;
4360     if g_debug then
4361     hr_utility.set_location('close c_PILI: ' || l_proc, 10);
4362     end if;
4363     --
4364 
4365     OPEN c_pl_popl_yr_period_current;
4366     --
4367     FETCH c_pl_popl_yr_period_current INTO l_yr_perd_id,
4368                                            l_popl_yr_perd_id,
4369                                            l_yr_perd_strt_date,
4370                                            l_yr_perd_end_date,
4371                                            l_popl_yr_perd_ordr_num;
4372     --
4373     IF ((c_pl_popl_yr_period_current%NOTFOUND) and (p_run_mode not in ('G','D'))) THEN
4374       --
4375       fnd_message.set_name('BEN', 'BEN_91334_PLAN_YR_PERD');
4376       fnd_message.set_token('PROC', l_proc);
4377       RAISE ben_manage_life_events.g_record_error;
4378     --
4379     END IF;
4380     --
4381     CLOSE c_pl_popl_yr_period_current;
4382     if g_debug then
4383     hr_utility.set_location('close c_PPYPC: ' || l_proc, 10);
4384     --
4385     hr_utility.set_location('oipl id is null', 20);
4386     end if;
4387     ben_epe_cache.get_pilcobjepe_dets
4388       (p_per_in_ler_id => p_per_in_ler_id
4389       ,p_pgm_id        => p_pgm_id
4390       ,p_pl_id         => l_pl_id
4391       ,p_oipl_id       => p_oipl_id
4392       --
4393       ,p_inst_row      => l_currepe_dets
4394       );
4395     --
4396     IF l_currepe_dets.elig_per_elctbl_chc_id is not null and
4397          p_run_mode not in ('U','R','D') THEN
4398       --
4399       fnd_message.set_name('BEN', 'BEN_91463_ELCTBL_CHC_EXISTS');
4400       fnd_message.set_token('PROC', l_proc);
4401       benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
4402       if g_debug then
4403       hr_utility.set_location('Leaving: ' || l_proc, 20);
4404       end if;
4405       p_electable_flag :=  'N';
4406       RETURN;
4407       --
4408     --bug#4096382
4409     elsif  l_currepe_dets.elig_per_elctbl_chc_id is not null and
4410          p_run_mode in ('U','R') THEN
4411        --
4412        l_epe_exists :=  ben_manage_unres_life_events.epe_exists
4413                          (p_per_in_ler_id => l_per_in_ler_id,
4414                           p_pgm_id => p_pgm_id,
4415                           p_pl_id  => l_pl_id,
4416                           p_oipl_id =>p_oipl_id);
4417        --
4418        if l_epe_Exists is null then  -- comp object in pgm/plnot in pgm  is in pending or suspended status
4419          --
4420           p_electable_flag :=  'N';
4421           RETURN;
4422          --
4423        end if;
4424        --
4425     END IF;
4426     --
4427     -- do prerequisite check if not overridden.
4428     --
4429     if g_debug then
4430     hr_utility.set_location('enroll another plan', 20);
4431     end if;
4432     IF     l_must_enrl_anthr_pl_id IS NOT NULL
4433        AND l_enrt_ovridn_flag = 'N'
4434     THEN
4435       --
4436       -- Get the current electable choice info for the comp object
4437       --
4438       ben_epe_cache.get_pilcobjepe_dets
4439         (p_per_in_ler_id => p_per_in_ler_id
4440         ,p_pgm_id        => p_pgm_id
4441         ,p_pl_id         => l_must_enrl_anthr_pl_id
4442         ,p_oipl_id       => null
4443         --
4444         ,p_inst_row      => l_currepe_dets
4445         );
4446       --
4447       IF l_currepe_dets.elig_per_elctbl_chc_id is null THEN
4448         --
4449         -- prereq not found recurse.
4450         --
4451         enrolment_requirements
4452           (p_comp_obj_tree_row      => p_comp_obj_tree_row
4453           ,p_run_mode               => p_run_mode
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_per_in_ler_id          => p_per_in_ler_id
4459           ,p_person_id              => p_person_id
4460           ,p_pl_id                  => l_must_enrl_anthr_pl_id
4461           ,p_pgm_id                 => p_pgm_id
4462           ,p_oipl_id                => NULL
4463           ,p_elig_per_elctbl_chc_id => l_elig_per_elctbl_chc_id
4464           ,p_electable_flag         => l_prereq_electable_flag
4465           -- ,p_popl_enrt_typ_cycl_id  => p_popl_enrt_typ_cycl_id
4466           );
4467       if g_debug then
4468         hr_utility.set_location('Dn Sub BENDENRR: ' || l_proc, 99);
4469       end if;
4470         --
4471         IF l_prereq_electable_flag = 'N' THEN
4472           --
4473           p_electable_flag :=  'N';
4474 	  if g_debug then
4475           hr_utility.set_location('Not electable since prereq is not.', 10);
4476 	  end if;
4477           RETURN;
4478         --
4479         END IF;
4480       --
4481       END IF;
4482       --
4483       if g_debug then
4484       hr_utility.set_location('close c_CHEFP: ' || l_proc, 10);
4485       --
4486       hr_utility.set_location('found prereq plan choice', 10);
4487     --
4488       end if;
4489     END IF;                                                   -- prereq exists.
4490     --
4491     -- Determine if the compensation object requires or allows an election change
4492     -- If life event mode
4493     --
4494     if g_debug then
4495     hr_utility.set_location('ler change stuff', 20);
4496     end if;
4497     l_ler_chg_found_flag :=       'N';
4498     l_ler_chg_oipl_found_flag :=  'N';
4499     --
4500     -- See if there is a life event reason to change
4501     --
4502     if g_debug then
4503     hr_utility.set_location('ler change stuff not null stuff', 20);
4504     hr_utility.set_location(' Op c_lce_info: ' || l_proc, 10);
4505     end if;
4506     --
4507  IF p_run_mode <> 'D' THEN
4508   --
4509     determine_ben_settings(
4510       p_pl_id                     => l_pl_id,
4511       p_ler_id                    => p_ler_id,
4512       p_lf_evt_ocrd_dt            => l_lf_evt_ocrd_dt,
4513       p_ptip_id                   => l_ptip_id,
4514       p_pgm_id                    => p_pgm_id,
4515       p_plip_id                   => l_plip_id,
4516       p_oipl_id                   => p_oipl_id,
4517       p_just_prclds_chg_flag      => FALSE,
4518       p_enrt_cd                   => l_ler_enrt_cd,
4519       p_enrt_rl                   => l_ler_enrt_rl,
4520       p_auto_enrt_mthd_rl         => l_ler_auto_enrt_rl,
4521       p_crnt_enrt_prclds_chg_flag => l_ler_enrt_prclds_chg_flag,
4522       p_dflt_flag                 => l_ler_dflt_flag,
4523       p_enrt_mthd_cd              => l_ler_enrt_mthd_cd,
4524       p_stl_elig_cant_chg_flag    => l_ler_stl_elig_cant_chg_flag,
4525       p_tco_chg_enrt_cd           => l_tco_chg_enrt_cd,
4526       p_ler_chg_oipl_found_flag   => l_ler_chg_oipl_found_flag,
4527       p_ler_chg_found_flag        => l_ler_chg_found_flag,
4528       p_enrt_cd_level             => l_enrt_cd_level );
4529    --
4530    if g_debug then
4531     hr_utility.set_location(' Cl c_lce_info: ' || l_proc, 10);
4532    end if;
4533     --
4534       -- Determine enrt codes/rules method codes/rules then
4535     -- figure out if electable.
4536     --
4537     --
4538     -- Initially set to ler_chg values if not null
4539     --
4540     IF l_ler_enrt_cd IS NOT NULL THEN
4541       l_pl_enrt_cd :=  l_ler_enrt_cd;
4542       l_pl_enrt_rl :=  l_ler_enrt_rl;
4543     ELSIF l_oipl_rec.enrt_cd IS NOT NULL THEN
4544       l_pl_enrt_cd :=  l_oipl_rec.enrt_cd;
4545       l_pl_enrt_rl :=  l_oipl_rec.enrt_rl;
4546     END IF;
4547     IF p_oipl_id IS NULL THEN
4548       IF    l_ler_enrt_mthd_cd IS NOT NULL
4549          OR l_ler_auto_enrt_rl IS NOT NULL THEN
4550         l_pl_enrt_mthd_cd :=  l_ler_enrt_mthd_cd;
4551         l_pl_auto_enrt_rl :=  l_ler_auto_enrt_rl;
4552       END IF;
4553     ELSE
4554       --
4555       -- below, if ler_chg row found then code will always
4556       -- be not null since comes from a decode of the flag.
4557       --
4558       IF l_ler_chg_oipl_found_flag = 'Y' THEN
4559         l_pl_enrt_mthd_cd :=  l_ler_enrt_mthd_cd;
4560         l_pl_auto_enrt_rl :=  l_ler_auto_enrt_rl;
4561         --
4562         IF l_ler_enrt_mthd_cd = 'A' THEN
4563           --
4564           l_oipl_auto_enrt_flag :=  'Y';
4565         --
4566         ELSE
4567           --
4568           l_oipl_auto_enrt_flag :=  'N';
4569         --
4570         END IF;
4571       --
4572       ELSE
4573         IF l_oipl_auto_enrt_flag = 'Y' THEN
4574           l_pl_enrt_mthd_cd :=  'A';
4575         ELSE
4576           l_pl_enrt_mthd_cd :=  'E';
4577         END IF;
4578         l_pl_auto_enrt_rl :=  l_oipl_auto_enrt_mthd_rl;
4579       END IF;
4580     END IF;
4581     --
4582     -- If the ler_chg values were null then now have plan values
4583     --
4584     -- Update if still null with values from above in hierarchy
4585     --
4586     IF     l_pl_enrt_cd IS NULL
4587        AND p_pgm_id IS NOT NULL THEN
4588       l_pl_enrt_cd :=  l_plip_enrt_cd;
4589       l_pl_enrt_rl :=  l_plip_enrt_rl;
4590     END IF;
4591     IF     l_pl_enrt_mthd_cd IS NULL
4592        AND p_pgm_id IS NOT NULL THEN
4593       l_pl_enrt_mthd_cd :=  l_plip_enrt_mthd_cd;
4594       l_pl_auto_enrt_rl :=  l_plip_auto_enrt_rl;
4595     END IF;
4596     --
4597     -- overlay ptip if value is still null
4598     --
4599     IF     l_pl_enrt_cd IS NULL
4600        AND p_pgm_id IS NOT NULL THEN
4601       l_pl_enrt_cd :=  l_ptip_enrt_cd;
4602       l_pl_enrt_rl :=  l_ptip_enrt_rl;
4603     END IF;
4604     IF     l_pl_enrt_mthd_cd IS NULL
4605        AND p_pgm_id IS NOT NULL THEN
4606       l_pl_enrt_mthd_cd :=  l_ptip_enrt_mthd_cd;
4607       l_pl_auto_enrt_rl :=  l_ptip_auto_enrt_rl;
4608     END IF;
4609     --
4610     -- get from program level if not at plan or plip or ptip levels
4611     --
4612     IF     l_pl_enrt_cd IS NULL
4613        AND p_pgm_id IS NOT NULL THEN
4614       l_pl_enrt_cd :=  l_pgm_rec.enrt_cd;
4615       l_pl_enrt_rl :=  l_pgm_rec.enrt_rl;
4616     END IF;
4617     IF     l_pl_enrt_mthd_cd IS NULL
4618        AND p_pgm_id IS NOT NULL THEN
4619       l_pl_enrt_mthd_cd :=  l_pgm_rec.enrt_mthd_cd;
4620       l_pl_auto_enrt_rl :=  l_pgm_rec.auto_enrt_mthd_rl;
4621     END IF;
4622     --
4623     -- Catch all default to explicit
4624     --
4625     --
4626     -- evaluate the rule and see what it returns that
4627     -- will take precedence over previous value.
4628     --
4629     IF l_pl_auto_enrt_rl IS NOT NULL THEN
4630       --
4631       -- Use the results of the enrt_mthd_rl as the code
4632       --
4633       if g_debug then
4634       hr_utility.set_location(' Exe enrt rl: ' || l_proc, 10);
4635       end if;
4636        execute_auto_dflt_enrt_rule(
4637          p_opt_id            => l_opt_id,
4638          p_pl_id             => l_pl_id,
4639          p_pgm_id            => p_pgm_id,
4640          p_rule_id           => l_pl_auto_enrt_rl,
4641          p_ler_id            => p_ler_id,
4642          p_pl_typ_id         => l_pl_typ_id,
4643          p_business_group_id => p_business_group_id,
4644          p_effective_date    => p_effective_date,
4645          p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
4646          p_elig_per_id       => l_elig_per_id,
4647          p_assignment_id     => l_rec_assignment_id,
4648          p_organization_id   => l_rec_organization_id,
4649          p_jurisdiction_code => l_jurisdiction_code,
4650 	 p_person_id         => p_person_id,            -- Bug 5331889
4651          p_enrt_mthd         => l_pl_enrt_mthd_cd,
4652          p_reinstt_dpnt      => l_reinstt_flag
4653          );
4654      if g_debug then
4655       hr_utility.set_location(' Dn Exe enrt rl: ' || l_proc, 10);
4656      end if;
4657         --
4658       l_reinstt_cd := l_reinstt_flag;
4659       --
4660       -- Following if for backward compatability only
4661       -- in future will return A/E.
4662       --
4663       IF l_pl_enrt_mthd_cd = 'N' THEN
4664         --
4665         l_pl_enrt_mthd_cd :=  'E';
4666       ELSIF l_pl_enrt_mthd_cd = 'Y' THEN
4667         l_pl_enrt_mthd_cd :=  'A';
4668       END IF;
4669       --
4670       IF p_oipl_id IS NOT NULL THEN
4671         IF l_pl_enrt_mthd_cd = 'A' THEN
4672           l_oipl_auto_enrt_flag :=  'Y';
4673         ELSE
4674           l_oipl_auto_enrt_flag :=  'N';
4675         END IF;
4676       END IF;
4677     END IF;
4678     --
4679     IF l_pl_enrt_mthd_cd IS NULL THEN
4680       l_pl_enrt_mthd_cd :=  'E';
4681     END IF;
4682     --
4683 END IF; -- 'D' Mode
4684     -- New Enrollment Code for changing coverage start date for currently enrolled comp.objects
4685     if l_pl_enrt_cd = 'CCKCSNCC' then
4686       l_new_cvg_strt := 'Y';
4687     end if;
4688     -- Don't check electability if automatic enrollment or
4689     --   only check it if explicit enrollment
4690     --
4691     -- Bug 2200139 for Override don't check electability but
4692     -- set the electable flag to 'N' so that users don't see these
4693     -- choices in the view person life events and enrollment forms.
4694     --
4695     if p_run_mode = 'V' then
4696       --
4697       l_rec_elctbl_flag := 'N' ;
4698       --
4699     else
4700       --
4701       --
4702       if g_debug then
4703       hr_utility.set_location('H', 20);
4704       hr_utility.set_location('Call detenr 2: ' || l_proc, 10);
4705       end if;
4706       g_ptip_id :=                  l_ptip_id;
4707       --
4708       --Bug 2677804 We dont need to get electable flag for the
4709       --pl/oipl if l_enrt_ovridn_flag is 'Y'
4710       --We need to make it electable
4711       --
4712       if l_enrt_ovridn_flag = 'Y' then
4713         --
4714 	if g_debug then
4715         hr_utility.set_location('First Electable Due to Override ' ,123);
4716 	end if;
4717         l_rec_elctbl_flag :=  'Y' ;
4718         --
4719       else
4720         --
4721         determine_enrolment(
4722           p_previous_eligibility   => l_previous_eligibility,
4723           p_crnt_enrt_cvg_strt_dt  => l_crnt_enrt_cvg_strt_dt,
4724           p_dpnt_cvrd_flag         => l_dpnt_cvrd_flag,
4725           p_person_id              => p_person_id,
4726           p_ler_id                 => p_ler_id,
4727           p_enrt_cd                => l_pl_enrt_cd,
4728           p_enrt_rl                => l_pl_enrt_rl,
4729           p_enrt_mthd_cd           => l_pl_enrt_mthd_cd,
4730           p_auto_enrt_mthd_rl      => l_pl_auto_enrt_rl,
4731           p_effective_date         => p_effective_date,
4732           p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
4733           p_enrt_prclds_chg_flag   => NVL(l_ler_enrt_prclds_chg_flag, 'N'),
4734           p_stl_elig_cant_chg_flag => NVL(l_ler_stl_elig_cant_chg_flag, 'N'),
4735           p_tco_chg_enrt_cd        => NVL(l_tco_chg_enrt_cd, 'CPOO'),
4736           p_pl_id                  => l_pl_id,
4737           p_pgm_id                 => p_pgm_id,
4738           p_oipl_id                => p_oipl_id,
4739           p_opt_id                 => l_opt_id,
4740           p_pl_typ_id              => l_pl_typ_id,
4741           p_business_group_id      => p_business_group_id,
4742           p_electable_flag         => l_rec_elctbl_flag,
4743           p_assignment_id          => l_rec_assignment_id,
4744           p_run_mode               => p_run_mode);   -- iRec
4745      if g_debug then
4746         hr_utility.set_location('Dn detenr 2: ' || l_proc, 10);
4747      end if;
4748       end if;
4749       -- End Bug 2677804
4750       IF l_rec_elctbl_flag = 'Y' THEN
4751         --
4752         -- continue
4753         --
4754         NULL;
4755       --
4756       ELSIF l_rec_elctbl_flag = 'L' THEN
4757         --
4758         -- Lose only condition.
4759         -- If enrolled will deenroll.
4760         --
4761         ben_newly_ineligible.main(
4762           p_person_id         => p_person_id,
4763           p_pgm_id            => p_pgm_id,
4764           p_pl_id             => p_pl_id,
4765           p_oipl_id           => p_oipl_id,
4766           p_business_group_id => p_business_group_id,
4767           p_ler_id            => p_ler_id,
4768           p_effective_date    => p_effective_date);
4769         p_electable_flag :=  'N';
4770 	if g_debug then
4771         hr_utility.set_location('Dn BNI_MN: ' || l_proc, 10);
4772 	end if;
4773         RETURN;
4774         --
4775       ELSIF l_pl_enrt_mthd_cd = 'A' THEN
4776         --
4777         -- Leave as choice and use elctbl_flag
4778         --
4779         NULL;
4780         --
4781       ELSIF l_crnt_enrt_cvg_strt_dt IS NOT NULL THEN
4782         --
4783         -- if currently enrolled then create the choice
4784         -- and don't exit
4785         --
4786         l_rec_elctbl_flag :=  'N';
4787         --
4788       ELSIF    l_plan_rec.invk_flx_cr_pl_flag = 'Y'
4789             OR l_plan_rec.imptd_incm_calc_cd IN ('PRTT', 'DPNT', 'SPS') THEN
4790         l_rec_elctbl_flag :=  'N';
4791         --
4792       ELSE
4793         --
4794         p_electable_flag :=  'N';
4795         RETURN;
4796         --
4797       END IF;                                          -- determine_enrolment='Y'
4798       --
4799     end if;  -- Override Enrollment endif
4800     --
4801     -- Set p_electable flag back to 'N' if we are dealing with an automatic
4802     -- enrollment
4803     --
4804     IF l_pl_enrt_mthd_cd = 'A' THEN
4805       --
4806       l_auto_enrt_flag :=  'Y';
4807     --
4808     END IF;
4809     --
4810     -- Check level jumping restrictions
4811     --
4812     if g_debug then
4813     hr_utility.set_location(l_proc || ' Lev Jump OIPL ', 12);
4814     end if;
4815     IF p_oipl_id IS NOT NULL AND p_run_mode <> 'D' THEN
4816       --
4817       if g_debug then
4818       hr_utility.set_location('get ler bnft_rstrns ', 12);
4819       hr_utility.set_location(l_proc || ' Op c_ler_bnft_rstrn ', 12);
4820       end if;
4821       OPEN c_ler_bnft_rstrn;
4822       FETCH c_ler_bnft_rstrn INTO l_tmp_level,
4823                                   l_restriction_pgm_id,
4824                                   l_oipl_ordr_num,
4825                                   l_boo_rstrctn_cd,
4826                                   l_cvg_incr_r_decr_only_cd,
4827                                   l_mx_cvg_mlt_incr_num,
4828                                   l_mx_cvg_mlt_incr_wcf_num;
4829       --
4830       IF c_ler_bnft_rstrn%NOTFOUND THEN
4831         --
4832         CLOSE c_ler_bnft_rstrn;
4833         -- Romoved the commented code
4834         IF     ben_cobj_cache.g_plip_currow.plip_id = l_plip_id
4835            AND ben_cobj_cache.g_plip_currow.bnft_or_option_rstrctn_cd = 'OPT'
4836            AND l_lf_evt_ocrd_dt >= ben_cobj_cache.g_plip_currow.effective_start_date
4837            AND l_lf_evt_ocrd_dt <= ben_cobj_cache.g_plip_currow.effective_end_date
4838            AND ben_cobj_cache.g_oipl_currow.oipl_id = p_oipl_id
4839            AND ben_cobj_cache.g_oipl_currow.pl_id = ben_cobj_cache.g_plip_currow.pl_id
4840            AND l_lf_evt_ocrd_dt >= ben_cobj_cache.g_oipl_currow.effective_start_date
4841            AND l_lf_evt_ocrd_dt <= ben_cobj_cache.g_oipl_currow.effective_end_date THEN
4842           --
4843           l_tmp_level                := 2;
4844           l_restriction_pgm_id       := ben_cobj_cache.g_plip_currow.pgm_id;
4845           l_oipl_ordr_num            := ben_cobj_cache.g_oipl_currow.ordr_num;
4846           l_boo_rstrctn_cd           :=
4847                                        ben_cobj_cache.g_plip_currow.bnft_or_option_rstrctn_cd;
4848           l_cvg_incr_r_decr_only_cd  := ben_cobj_cache.g_plip_currow.cvg_incr_r_decr_only_cd;
4849           l_mx_cvg_mlt_incr_num      := ben_cobj_cache.g_plip_currow.mx_cvg_mlt_incr_num;
4850           l_mx_cvg_mlt_incr_wcf_num  := ben_cobj_cache.g_plip_currow.mx_cvg_mlt_incr_wcf_num;
4851         --
4852         ELSIF     ben_cobj_cache.g_pl_currow.pl_id = l_pl_id
4853               AND ben_cobj_cache.g_pl_currow.bnft_or_option_rstrctn_cd = 'OPT'
4854               AND l_lf_evt_ocrd_dt >= ben_cobj_cache.g_pl_currow.effective_start_date
4855               AND l_lf_evt_ocrd_dt <= ben_cobj_cache.g_pl_currow.effective_end_date
4856               AND ben_cobj_cache.g_oipl_currow.oipl_id = p_oipl_id
4857               AND ben_cobj_cache.g_oipl_currow.pl_id = ben_cobj_cache.g_pl_currow.pl_id
4858               AND l_lf_evt_ocrd_dt >= ben_cobj_cache.g_oipl_currow.effective_start_date
4859               AND l_lf_evt_ocrd_dt <= ben_cobj_cache.g_oipl_currow.effective_end_date THEN
4860           --
4861           l_tmp_level                := 1;
4862           l_restriction_pgm_id       := NULL;
4863           l_oipl_ordr_num            := ben_cobj_cache.g_oipl_currow.ordr_num;
4864           l_boo_rstrctn_cd           := ben_cobj_cache.g_pl_currow.bnft_or_option_rstrctn_cd;
4865           l_cvg_incr_r_decr_only_cd  := ben_cobj_cache.g_pl_currow.cvg_incr_r_decr_only_cd;
4866           l_mx_cvg_mlt_incr_num      := ben_cobj_cache.g_pl_currow.mx_cvg_mlt_incr_num;
4867           l_mx_cvg_mlt_incr_wcf_num  := ben_cobj_cache.g_pl_currow.mx_cvg_mlt_incr_wcf_num;
4868         --
4869         END IF;
4870       ELSE
4871         --
4872         CLOSE c_ler_bnft_rstrn;
4873       --
4874       END IF;
4875       if g_debug then
4876       hr_utility.set_location(l_proc || ' c_ler_bnft_rstrn ', 12);
4877       end if;
4878 /*  uncomment these for debuggin only
4879   hr_utility.set_location('l_plip_id -> '||l_plip_id,11);
4880   hr_utility.set_location('p_pgm_id -> '||p_pgm_id,11);
4881   hr_utility.set_location('l_restriction_pgm_id -> '||l_restriction_pgm_id,11);
4882   hr_utility.set_location('l_tmp_level -> '||l_tmp_level,11);
4883   hr_utility.set_location('l_oipl_ordr_num -> '||l_oipl_ordr_num,12);
4884   hr_utility.set_location('l_boo_rstrctn_cd -> '||l_boo_rstrctn_cd,12);
4885   hr_utility.set_location('l_cvg_incr_r_decr_only_cd -> '||l_cvg_incr_r_decr_only_cd,12);
4886   hr_utility.set_location('l_mx_cvg_mlt_incr_num -> '||l_mx_cvg_mlt_incr_num,12);
4887   hr_utility.set_location('l_mx_cvg_mlt_incr_wcf_num -> '||l_mx_cvg_mlt_incr_wcf_num,12);
4888 */
4889       IF l_boo_rstrctn_cd IS NOT NULL THEN
4890         --
4891         OPEN c_oipl_enrt_in_pl;
4892         FETCH c_oipl_enrt_in_pl INTO l_enrd_ordr_num;
4893         --
4894         --  For COBRA, also check elig_cvrd_dpnt as the person
4895         --  may be a dependent.
4896         --
4897         IF c_oipl_enrt_in_pl%NOTFOUND THEN
4898           IF p_pgm_id IS NOT NULL THEN
4899             IF l_pgm_rec.pgm_typ_cd LIKE 'COBRA%' THEN
4900               OPEN c_oipl_cvg_in_pl;
4901               FETCH c_oipl_cvg_in_pl INTO l_enrd_ordr_num;
4902               CLOSE c_oipl_cvg_in_pl;
4903             END IF;
4904           END IF;
4905         END IF;
4906         CLOSE c_oipl_enrt_in_pl;
4907         --
4908         -- convert ordr_num to logical orD number
4909         l_cnt := 1;
4910         if l_oipl_ordr_num is not null then
4911           open c_opt_level;
4912           loop
4913             fetch c_opt_level into l_opt_level;
4914             if c_opt_level%Notfound then
4915                exit;
4916             end if;
4917          --   hr_utility.set_location('opt level'||l_opt_level,111);
4918 
4919             if l_opt_level = l_oipl_ordr_num then
4920                l_oipl_seq_num := l_cnt;
4921                l_found  := TRUE;
4922                exit;
4923             end if;
4924             l_cnt := l_cnt + 1;
4925           end loop;
4926           close c_opt_level;
4927           if not l_found then
4928              fnd_message.set_name('BEN','BEN_92699_SEQ_NUM_NOT_EXST');
4929              fnd_message.raise_error;
4930           end if;
4931         end if;
4932         --
4933         l_cnt := 1;
4934         l_found := FALSE;
4935         if l_enrd_ordr_num is not null then
4936           open c_opt_level;
4937           loop
4938             fetch c_opt_level into l_opt_level;
4939             if c_opt_level%Notfound then
4940                exit;
4941             end if;
4942          if g_debug then
4943             hr_utility.set_location('Enrd Ord'||l_enrd_ordr_num,113);
4944          end if;
4945             if l_opt_level = l_enrd_ordr_num then
4946                l_enrd_seq_num := l_cnt;
4947                l_found  := TRUE;
4948                exit;
4949             end if;
4950             l_cnt := l_cnt + 1;
4951           end loop;
4952           close c_opt_level;
4953           if not l_found then
4954              fnd_message.set_name('BEN','BEN_92699_SEQ_NUM_NOT_EXST');
4955              fnd_message.raise_error;
4956           end if;
4957         end if;
4958        --     End of Logical Ordr Num
4959 
4960         -- Check for conditions where no choice should be created (N above)
4961         --
4962         IF l_cvg_incr_r_decr_only_cd = 'MNAVLO' THEN
4963           --
4964           --  Minimum available.
4965           --
4966           OPEN c_get_min_max_ordr_num;
4967           FETCH c_get_min_max_ordr_num INTO l_mn_ordr_num, l_mx_ordr_num;
4968           CLOSE c_get_min_max_ordr_num;
4969           --
4970           IF l_oipl_ordr_num <> l_mn_ordr_num THEN
4971 	  if g_debug then
4972             hr_utility.set_location(
4973               'Level jumping to this object not allowed',
4974               12);
4975           end if;
4976             p_electable_flag :=  'N';
4977             RETURN;
4978           END IF;
4979 	  if g_debug then
4980           hr_utility.set_location('min avail', 12);
4981 	  end if;
4982         --
4983         ELSIF l_cvg_incr_r_decr_only_cd = 'MXAVLO' THEN
4984           --
4985           --  Maximum available.
4986           --
4987           OPEN c_get_min_max_ordr_num;
4988           FETCH c_get_min_max_ordr_num INTO l_mn_ordr_num, l_mx_ordr_num;
4989           CLOSE c_get_min_max_ordr_num;
4990           --
4991           IF l_oipl_ordr_num <> l_mx_ordr_num THEN
4992 	  if g_debug then
4993             hr_utility.set_location(
4994               'Level jumping to this object not allowed',
4995               12);
4996           end if;
4997             p_electable_flag :=  'N';
4998             RETURN;
4999           END IF;
5000 	  if g_debug then
5001           hr_utility.set_location('max avail', 12);
5002 	  end if;
5003         --
5004         ELSIF l_enrd_ordr_num IS NULL THEN
5005           --
5006           -- When person is not previously enrolled.
5007           --
5008 	  if g_debug then
5009           hr_utility.set_location('person not prev enrolled', 12);
5010 	  end if;
5011           p_electable_flag :=  'Y';
5012         --
5013         ELSIF (
5014                    (
5015                          l_cvg_incr_r_decr_only_cd = 'INCRO'
5016                      AND l_oipl_ordr_num <= l_enrd_ordr_num)
5017                 OR (
5018                          l_cvg_incr_r_decr_only_cd = 'EQINCR'
5019                      AND l_oipl_ordr_num < l_enrd_ordr_num)
5020                 OR (
5021                          l_cvg_incr_r_decr_only_cd = 'DECRO'
5022                      AND l_oipl_ordr_num >= l_enrd_ordr_num)
5023                 OR (
5024                          l_cvg_incr_r_decr_only_cd = 'EQDECR'
5025                      AND l_oipl_ordr_num > l_enrd_ordr_num)) THEN
5026           --
5027 	  if g_debug then
5028           hr_utility.set_location('incr or decr check failed, no choice', 12);
5029 	  end if;
5030           --
5031           p_electable_flag :=  'N';
5032           --
5033           RETURN;
5034         --
5035         ELSIF (
5036                    l_cvg_incr_r_decr_only_cd IS NULL
5037                 OR l_cvg_incr_r_decr_only_cd = 'NR'
5038                 OR (
5039                          l_cvg_incr_r_decr_only_cd = 'INCRO'
5040                      AND l_oipl_ordr_num > l_enrd_ordr_num)
5041                 OR (
5042                          l_cvg_incr_r_decr_only_cd = 'EQINCR'
5043                      AND l_oipl_ordr_num >= l_enrd_ordr_num)
5044                 OR (
5045                          l_cvg_incr_r_decr_only_cd = 'DECRO'
5046                      AND l_oipl_ordr_num < l_enrd_ordr_num)
5047                 OR (
5048                          l_cvg_incr_r_decr_only_cd = 'EQDECR'
5049                      AND l_oipl_ordr_num <= l_enrd_ordr_num)
5050                 OR l_cvg_incr_r_decr_only_cd IN ('INCRCTF', 'DECRCTF', 'DECINCCTF')) THEN
5051          --
5052 /*   uncomment these for debugging only
5053          hr_utility.set_location('Level jumping passed incr or decr check',12);
5054          hr_utility.set_location('now check max incr and max wctfn incr',12);
5055          hr_utility.set_location('l_mx_cvg_mlt_incr_wcf_num -> '||l_mx_cvg_mlt_incr_wcf_num,12);
5056          hr_utility.set_location('l_mx_cvg_mlt_incr_num -> '||l_mx_cvg_mlt_incr_num,12);
5057          hr_utility.set_location('current enrolled order num -> '||l_enrd_ordr_num,12);
5058 */
5059 -- logical ordr number is used rather database ordr num
5060           --
5061           IF     l_oipl_seq_num >
5062                                   (
5063                                     l_mx_cvg_mlt_incr_wcf_num +
5064                                       l_enrd_seq_num)
5065              AND l_mx_cvg_mlt_incr_wcf_num IS NOT NULL THEN
5066             --
5067 	    if g_debug then
5068             hr_utility.set_location('can not jump here 1', 12);
5069 	    end if;
5070             p_electable_flag :=  'N';
5071             RETURN;
5072           --
5073           ELSIF     (
5074                       l_oipl_seq_num >
5075                                       (
5076                                         l_mx_cvg_mlt_incr_num +
5077                                           l_enrd_seq_num))
5078                 AND l_mx_cvg_mlt_incr_num IS NOT NULL
5079                 AND l_mx_cvg_mlt_incr_wcf_num IS NULL THEN
5080             --
5081 	    if g_debug then
5082             hr_utility.set_location('can not jump here 2', 12);
5083 	    end if;
5084             p_electable_flag :=  'N';
5085             RETURN;
5086           --
5087           ELSIF     (
5088                       l_oipl_seq_num >
5089                               (
5090                                 NVL(l_mx_cvg_mlt_incr_num, 0) +
5091                                   l_enrd_seq_num))
5092                 AND (
5093                       l_oipl_seq_num <=
5094                                   (
5095                                     l_mx_cvg_mlt_incr_wcf_num +
5096                                       l_enrd_seq_num))
5097                 AND l_mx_cvg_mlt_incr_wcf_num IS NOT NULL THEN
5098             --
5099 	    if g_debug then
5100             hr_utility.set_location('set ctfn rqd flag to true ', 12);
5101 	    end if;
5102             p_electable_flag :=  'Y';
5103             l_ctfn_rqd_flag :=   'Y';
5104           ELSE
5105             --
5106             p_electable_flag :=  'Y';
5107             --
5108           END IF;
5109         --
5110           -- 5736589: Increase/Decrease Requires certification for Option Restrictions
5111 	  if g_debug then
5112             hr_utility.set_location('Opt.Rest. Incr/Dec.Req.Cert.  ' || l_cvg_incr_r_decr_only_cd, 12);
5113           end if;
5114             IF (l_cvg_incr_r_decr_only_cd  = 'INCRCTF'
5115                 and l_oipl_ordr_num > l_enrd_ordr_num) THEN
5116               --
5117               l_ctfn_rqd_flag :=  'Y';
5118           --
5119             ELSIF (l_cvg_incr_r_decr_only_cd  = 'DECRCTF'
5120                 and l_oipl_ordr_num < l_enrd_ordr_num) THEN
5121               --
5122               l_ctfn_rqd_flag :=  'Y';
5123               --
5124             ELSIF (l_cvg_incr_r_decr_only_cd  = 'DECINCCTF'
5125                 and l_oipl_ordr_num <> l_enrd_ordr_num) THEN
5126               --
5127               l_ctfn_rqd_flag :=  'Y';
5128           END IF;
5129         --
5130 	if g_debug then
5131             hr_utility.set_location('Opt.Rest. Cert Flag  ' || l_ctfn_rqd_flag, 12);
5132         end if;
5133           --
5134         ELSE
5135           --
5136         if g_debug then
5137           hr_utility.set_location('Level jumping success', 0);
5138         end if;
5139           p_electable_flag :=  'Y';
5140         --
5141         END IF;
5142       --
5143       END IF;
5144     --
5145     END IF;
5146     --
5147 
5148     -- Determine the enrt_cvg_strt_dt_cd and enrt_cvg_end_dt_cd
5149     -- (rules as well), and dates
5150     -- use the new determine date function
5151     -- Get it from the lee_rsn_f for the plan, if not set get it from the plan,
5152     -- if not set get it from the lee_rsn_f at the pgm level,
5153     -- if not set get it from the pgm, if not set report and error.
5154     -- (end date is optional is used at the same level as the start)
5155     --
5156     if g_debug then
5157     hr_utility.set_location('J', 20);
5158     hr_utility.set_location(l_proc || ' RMODE=L ', 12);
5159     end if;
5160     --
5161     -- ABSENCES : absence processing is similar to life event processing
5162     -- GRADE/STEP : GS progression process is similar to life event
5163     -- iREC : Added mode 'I'
5164     --
5165 -- IF p_run_mode <> 'D' then
5166   --
5167     IF (    p_run_mode in  ('L', 'M', 'G', 'I')
5168         AND l_unrestricted_enrt_flag = 'N') THEN
5169       --
5170       if g_debug then
5171       hr_utility.set_location('K', 20);
5172       hr_utility.set_location(l_proc || ' RMODE=L UEF=N ', 12);
5173       end if;
5174       OPEN c_lee_period_for_plan;
5175       --
5176       FETCH c_lee_period_for_plan INTO l_ple_dys_aftr_end_to_dflt_num,
5177                                        l_ple_enrt_perd_end_dt_rl,
5178                                        l_ple_enrt_perd_strt_dt_rl,
5179                                        l_ple_enrt_perd_end_dt_cd,
5180                                        l_ple_enrt_perd_strt_dt_cd,
5181 --                                     l_ple_enrt_cvg_strt_dt_cd,
5182 --                                     l_ple_enrt_cvg_strt_dt_rl,
5183                                        l_ple_addit_procg_dys_num,
5184                                        l_ple_enrt_typ_cycl_cd,
5185                                        l_ple_lee_rsn_id,
5186                                        l_rec_cls_enrt_dt_to_use_cd,
5187                                        l_rec_lee_rsn_esd,
5188                                        l_rec_lee_rsn_eed,
5189                                        l_ple_enrt_perd_strt_days,
5190                                        l_ple_enrt_perd_end_days,
5191                                        /* bug 2746865*/
5192                                        l_enrt_perd_det_ovrlp_bckdt_cd;
5193       --
5194       IF c_lee_period_for_plan%FOUND THEN
5195         --
5196         l_perd_for_plan_found :=  'Y';
5197       --
5198       ELSE
5199         --
5200         l_perd_for_plan_found :=  'N';
5201       --
5202       END IF;                                                          -- found
5203       --
5204       CLOSE c_lee_period_for_plan;
5205       if g_debug then
5206       hr_utility.set_location(l_proc || ' Cl c_lpfpln ', 12);
5207       --
5208       hr_utility.set_location('L', 20);
5209       end if;
5210       -- Get pgm level enrt period if it is needed
5211       -- Program must exist and
5212       -- Needed when can't find record at plan level or
5213       -- Need it to determine the enrt_perd_strt_dt_cd
5214       --
5215       IF (
5216                p_pgm_id IS NOT NULL
5217            AND (
5218                     l_perd_for_plan_found = 'N'
5219                  OR (l_ple_enrt_perd_strt_dt_cd IS NULL))) THEN
5220         --
5221         OPEN c_lee_period_for_program;
5222         --
5223         FETCH c_lee_period_for_program INTO l_pgme_dys_aftr_end_to_dflt,
5224                                             l_pgme_enrt_perd_end_dt_rl,
5225                                             l_pgme_enrt_perd_strt_dt_rl,
5226                                             l_pgme_enrt_perd_end_dt_cd,
5227                                             l_pgme_enrt_perd_strt_dt_cd,
5228 --                                            l_pgme_enrt_cvg_strt_dt_cd,
5229 --                                            l_pgme_enrt_cvg_strt_dt_rl,
5230                                             l_pgme_addit_procg_dys_num,
5231                                             l_pgme_enrt_typ_cycl_cd,
5232                                             l_pgme_lee_rsn_id,
5233                                             l_rec_cls_enrt_dt_to_use_cd,
5234                                             l_rec_lee_rsn_esd,
5235                                             l_rec_lee_rsn_eed,
5236                                             l_pgme_enrt_perd_strt_days,
5237                                             l_pgme_enrt_perd_end_days,
5238                                             /* bug 2746865 */
5239                                             l_enrt_perd_det_ovrlp_bckdt_cd;
5240         --
5241         IF c_lee_period_for_program%FOUND THEN
5242           --
5243           l_perd_for_program_found :=  'Y';
5244         --
5245         ELSE
5246           --
5247           l_perd_for_program_found :=  'N';
5248         --
5249         END IF;                                                        -- Found
5250         --
5251         CLOSE c_lee_period_for_program;
5252 	if g_debug then
5253         hr_utility.set_location(l_proc || ' Cl c_lpfprg ', 12);
5254 	end if;
5255       --
5256       -- If there is a plan level enrt_perd_for_pl use it's value (if not null)
5257       --
5258 --      open c_enrt_perd_for_pl_info;
5259 --      fetch c_enrt_perd_for_pl_info into
5260 --        l_overide_enrt_cvg_strt_dt_cd,
5261 --        l_overide_enrt_cvg_strt_dt_rl;
5262 --      close c_enrt_perd_for_pl_info;
5263 --      if l_overide_enrt_cvg_strt_dt_cd is not null then
5264 --        l_pgme_enrt_cvg_strt_dt_cd:=l_overide_enrt_cvg_strt_dt_cd;
5265 --        l_pgme_enrt_cvg_strt_dt_rl:=l_overide_enrt_cvg_strt_dt_rl;
5266 --      end if;
5267       --
5268       END IF;                -- Need to get program level enrolment period info
5269     --
5270     ELSIF (   ( p_run_mode = 'C'or p_run_mode = 'W')
5271            AND l_unrestricted_enrt_flag = 'N') THEN
5272       --
5273       if g_debug then
5274       hr_utility.set_location(l_proc || ' RMODE=C UEF=N ', 12);
5275       end if;
5276       OPEN c_sched_enrol_period_for_plan;
5277       --
5278       FETCH c_sched_enrol_period_for_plan INTO l_ple_enrt_perd_id,
5279                                                l_ple_enrt_perd_strt_dt,
5280                                                l_ple_enrt_perd_end_dt,
5281                                                l_ple_procg_end_dt,
5282                                                l_ple_dflt_enrt_dt,
5283 --                                             l_ple_enrt_cvg_strt_dt_cd,
5284 --                                             l_ple_enrt_cvg_strt_dt_rl,
5285                                                l_ple_enrt_typ_cycl_cd,
5286                                                l_rec_cls_enrt_dt_to_use_cd,
5287                                                l_ple_hrchy_to_use_cd,
5288                                                l_ple_pos_structure_version_id,
5289                                                /* bug 2746865 */
5290                                                l_enrt_perd_det_ovrlp_bckdt_cd;
5291 
5292       --
5293       IF c_sched_enrol_period_for_plan%FOUND THEN
5294         --
5295         l_perd_for_plan_found :=  'Y';
5296       --
5297       ELSE
5298         --
5299         l_perd_for_plan_found :=  'N';
5300       --
5301       END IF;                                                          -- found
5302       --
5303       CLOSE c_sched_enrol_period_for_plan;
5304       --
5305       -- Get pgm level enrt period if it is needed
5306       -- Program must exist and
5307       -- Needed when can't find record at plan level or
5308       -- Need it to determine the enrt_perd_strt_dt_cd
5309       --
5310       IF (
5311                p_pgm_id IS NOT NULL
5312            AND (
5313                     l_perd_for_plan_found = 'N'
5314                  OR (l_ple_enrt_perd_strt_dt IS NULL))) THEN
5315         --
5316         OPEN c_sched_enrol_period_for_pgm;
5317         --
5318         FETCH c_sched_enrol_period_for_pgm INTO l_pgme_enrt_perd_id,
5319                                                 l_pgme_enrt_perd_strt_dt,
5320                                                 l_pgme_enrt_perd_end_dt,
5321                                                 l_pgme_procg_end_dt,
5322                                                 l_pgme_dflt_enrt_dt,
5323 --                                                l_pgme_enrt_cvg_strt_dt_cd,
5324 --                                                l_pgme_enrt_cvg_strt_dt_rl,
5325                                                 l_pgme_enrt_typ_cycl_cd,
5326                                                 l_rec_cls_enrt_dt_to_use_cd,
5327                                                 l_ple_hrchy_to_use_cd,
5328                                                 l_ple_pos_structure_version_id,
5329                                                 /* bug 2746865 */
5330                                                 l_enrt_perd_det_ovrlp_bckdt_cd;
5331         --
5332         IF c_sched_enrol_period_for_pgm%FOUND THEN
5333           --
5334           l_perd_for_program_found :=  'Y';
5335         --
5336         ELSE
5337           --
5338           l_perd_for_program_found :=  'N';
5339         --
5340         END IF;                                                        -- Found
5341         --
5342         CLOSE c_sched_enrol_period_for_pgm;
5343       --
5344       -- If there is a plan level enrt_perd_for_pl use it's value (if not null)
5345       --
5346       --
5347       END IF;                -- Need to get program level enrolment period info
5348     -- Bug 2200139 Override Enrollments
5349     ELSIF l_unrestricted_enrt_flag = 'Y' OR p_run_mode = 'V'  THEN
5350       l_rec_enrt_perd_strt_dt :=      l_lf_evt_ocrd_dt_fetch;
5351       l_rec_enrt_perd_end_dt :=       hr_api.g_eot;
5352       l_rec_procg_end_dt :=           hr_api.g_eot;
5353       l_rec_dflt_asnmt_dt :=          l_lf_evt_ocrd_dt_fetch;
5354       l_rec_enrt_typ_cycl_cd :=       'U';
5355       l_rec_cls_enrt_dt_to_use_cd :=  'ELCNSMADE';
5356     END IF;                                                   -- run_mode cases
5357     --
5358     -- One of the levels must have been found
5359     --
5360     if g_debug then
5361     hr_utility.set_location('M', 20);
5362     hr_utility.set_location(
5363       'l_perd_for_plan_found=' || l_perd_for_plan_found,
5364       20);
5365     hr_utility.set_location(
5366       'l_perd_for_program_found=' || l_perd_for_program_found,
5367       20);
5368     hr_utility.set_location(
5369       'l_unrestricted_enrt_flag=' || l_unrestricted_enrt_flag,
5370       20);
5371     hr_utility.set_location('l_pfpf=N ' || l_proc, 10);
5372     end if;
5373     --Bug 2200139 Override Enrollment
5374     IF (
5375              l_perd_for_plan_found = 'N'
5376          AND l_perd_for_program_found = 'N'
5377          AND l_unrestricted_enrt_flag = 'N'
5378          AND nvl(p_run_mode,'X') not in ('V','D') ) THEN -- For 'D' Mode we dont set code for periods
5379       --
5380       -- ABSENCES : absence processing is similar to life event processing.
5381       -- iRec : Added mode 'I'
5382       IF p_run_mode in ('L', 'M','G', 'I') THEN
5383       if g_debug then
5384         hr_utility.set_location(' Leaving:' || l_proc, 981);
5385       end if;
5386         p_electable_flag :=  'N';
5387         RETURN;
5388       ELSE
5389       if g_debug then
5390         hr_utility.set_location('Did not find enrt_perd, raise error', 982);
5391       end if;
5392         fnd_message.set_name('BEN', 'BEN_91335_PLAN_YR_ENRT_PERD');
5393         fnd_message.set_token('PROC', l_proc);
5394         fnd_message.set_token('PGM_ID', TO_CHAR(p_pgm_id));
5395         fnd_message.set_token('PL_ID', TO_CHAR(l_pl_id));
5396         fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
5397         fnd_message.set_token('LF_EVT_OCRD_DT', TO_CHAR(p_lf_evt_ocrd_dt));
5398         RAISE ben_manage_life_events.g_record_error;
5399       END IF;
5400     --
5401     END IF;                                         -- no enrt_perd info found.
5402     --
5403     if g_debug then
5404     hr_utility.set_location('P', 20);
5405     --
5406     -- Determine the mndtry_flag
5407     -- If the comp object is an OIPL
5408     --
5409     hr_utility.set_location('Ch oipl_id NN ' || l_proc, 10);
5410     end if;
5411     IF (p_oipl_id IS NOT NULL AND p_run_mode <> 'D') THEN
5412       --
5413       -- If the mndtry_rl is not null, execute it to determine
5414       -- if the oipl is mandatory.
5415       --
5416       IF l_mndtry_rl IS NOT NULL THEN
5417         --
5418         l_mndtry_flag :=
5419          execute_enrt_rule(
5420            p_opt_id            => l_opt_id,
5421            p_pl_id             => l_pl_id,
5422            p_pgm_id            => p_pgm_id,
5423            p_rule_id           => l_mndtry_rl,
5424            p_ler_id            => p_ler_id,
5425            p_pl_typ_id         => l_pl_typ_id,
5426            p_business_group_id => p_business_group_id,
5427            p_effective_date    => p_effective_date,
5428            p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
5429            p_assignment_id     => l_rec_assignment_id,
5430            p_organization_id   => l_rec_organization_id,
5431            p_jurisdiction_code => l_jurisdiction_code,
5432 	   p_person_id         => p_person_id);          -- Bug 5331889
5433         --
5434         l_rec_mndtry_flag :=  l_mndtry_flag;
5435         --
5436       --
5437       -- If the mndtry_rl is null, use the mndtry_flag to
5438       -- determine if the oipl is mandatory.
5439       --
5440       ELSE
5441         --
5442         l_rec_mndtry_flag :=  l_mndtry_flag;
5443       --
5444       END IF;
5445     --
5446     END IF;
5447     --
5448     -- Determine the elctbl_flag
5449     -- If the comp object is an OIPL
5450     --
5451     if g_debug then
5452     hr_utility.set_location('R', 20);
5453     hr_utility.set_location('Ch oipl_id1 NN ' || l_proc, 10);
5454     end if;
5455     --
5456     -- CWBITEM : do not check for CWB plans, goahead and create the epe.
5457     --
5458     IF (p_oipl_id IS NULL and p_run_mode not in ('W','D')) THEN
5459       --
5460       -- Only check to see if we have to create electable choice for plan if
5461       -- the enrt pl opt flag is set
5462       --
5463       IF l_plan_rec.enrt_pl_opt_flag = 'N' THEN
5464         --
5465         OPEN c_any_oipl_for_plan;
5466         --
5467         FETCH c_any_oipl_for_plan INTO l_exists_flag;
5468 	if g_debug then
5469         hr_utility.set_location('Fet c_aofp ' || l_proc, 10);
5470 	end if;
5471         --
5472         IF c_any_oipl_for_plan%FOUND THEN
5473           --
5474           p_electable_flag :=  'N';
5475           RETURN;
5476         --
5477         END IF;
5478         --
5479         CLOSE c_any_oipl_for_plan;
5480       --
5481       END IF;
5482     --
5483     END IF;
5484     --
5485     if g_debug then
5486     hr_utility.set_location('S', 20);
5487     -- Determine the enrt_typ_cycl_cd
5488     -- Find the lee_rsn_f and related popl_enrt_typ_cycl_f for the plan.
5489     --
5490     hr_utility.set_location('l_PFPF=Y ' || l_proc, 10);
5491     end if;
5492   IF p_run_mode <> 'D' THEN
5493     IF (    l_perd_for_plan_found = 'Y'
5494         AND l_ple_enrt_typ_cycl_cd IS NOT NULL) THEN
5495       -- If found use it's enrt_typ_cycl_cd
5496       l_rec_enrt_typ_cycl_cd :=  l_ple_enrt_typ_cycl_cd;
5497     -- If not found then find the lee_rsn_f and related
5498     -- popl_enrt_typ_cycl_f for the program.
5499     --
5500     ELSIF (
5501                 l_perd_for_program_found = 'Y'
5502             AND l_pgme_enrt_typ_cycl_cd IS NOT NULL) THEN
5503       -- If found use it's enrt_typ_cycl_cd
5504       l_rec_enrt_typ_cycl_cd :=  l_pgme_enrt_typ_cycl_cd;
5505     -- Bug 2200139 Override Enrollment
5506     ELSIF l_unrestricted_enrt_flag = 'N' and nvl(p_run_mode,'X') <> 'V' THEN
5507       -- If nothing found report an error.
5508       fnd_message.set_name('BEN', 'BEN_91464_ENRT_TYP_CYCL_CD');
5509       fnd_message.set_token('PROC', l_proc);
5510       fnd_message.set_token('PGM_ID', TO_CHAR(p_pgm_id));
5511       fnd_message.set_token('PGM_ENRT_TYP_CYCL_CD', l_pgme_enrt_typ_cycl_cd);
5512       fnd_message.set_token('PL_ID', TO_CHAR(l_pl_id));
5513       fnd_message.set_token('PL_ENRT_TYP_CYCL_CD', l_ple_enrt_typ_cycl_cd);
5514       RAISE ben_manage_life_events.g_record_error;
5515     --
5516     END IF;
5517     --
5518   END IF; -- 'D' Mode
5519     -- Determine the crntly_enrd_flag
5520     -- Set it to the currently_enrolled parameter.
5521     --
5522     IF l_crnt_enrt_cvg_strt_dt IS NOT NULL THEN
5523       --
5524       l_rec_crntly_enrd_flag :=  'Y';
5525     --
5526     ELSE
5527       --
5528       l_rec_crntly_enrd_flag :=  'N';
5529     --
5530     END IF;
5531     --
5532     -- get the dflt_enrt_cd/rule
5533     --
5534     if g_debug then
5535     hr_utility.set_location('DrtDEC ' || l_proc, 10);
5536     -- start bug 5644451
5537         hr_utility.set_location('Determine with new call 5644451 ' || l_proc, 10);
5538     end if;
5539 	IF (p_oipl_id IS NOT NULL)
5540 	THEN
5541 	-- get oipl information
5542 	ben_comp_object.get_object (p_oipl_id                     => p_oipl_id,
5543 				  p_rec                         => l_oipl_record);
5544 	l_oipl_auto_enrt_flag := l_oipl_rec.auto_enrt_flag;
5545 	END IF;
5546 	-- Get ptip cache row if needed
5547 	IF l_ptip_id IS NOT NULL
5548 	THEN
5549 	ben_comp_object.get_object (p_ptip_id                     => l_ptip_id,
5550 				  p_rec                         => l_ptip_record);
5551 	END IF;
5552 	-- Get plip cache row if needed
5553 	IF l_plip_id IS NOT NULL
5554 	THEN
5555 	ben_comp_object.get_object (p_plip_id                     => l_plip_id,
5556 				  p_rec                         => l_plip_record);
5557 	END IF;
5558 
5559 
5560     /*
5561     determine_dflt_enrt_cd
5562       (p_oipl_id           => p_oipl_id
5563       ,p_plip_id           => l_plip_id
5564       ,p_pl_id             => l_pl_id
5565       ,p_ptip_id           => l_ptip_id
5566       ,p_pgm_id            => p_pgm_id
5567       ,p_ler_id            => p_ler_id
5568       ,p_dflt_enrt_cd      => l_use_dflt_enrt_cd
5569       ,p_dflt_enrt_rl      => l_use_dflt_enrt_rl
5570       ,p_business_group_id => p_business_group_id
5571       ,p_effective_date    => p_effective_date
5572       );
5573       */
5574     IF p_run_mode <> 'D' THEN
5575      --
5576       determine_dflt_enrt_cd
5577         (p_oipl_id           => p_oipl_id
5578         ,p_oipl_rec          => l_oipl_record
5579         ,p_plip_id           => l_plip_id
5580         ,p_plip_rec          => l_plip_record
5581         ,p_pl_id             => l_pl_id
5582         ,p_pl_rec            => l_plan_rec
5583         ,p_ptip_id           => l_ptip_id
5584         ,p_ptip_rec          => l_ptip_record
5585         ,p_pgm_id            => p_pgm_id
5586         ,p_pgm_rec           => l_pgm_rec
5587         ,p_ler_id            => p_ler_id
5588         ,p_dflt_enrt_cd      => l_use_dflt_enrt_cd
5589         ,p_dflt_enrt_rl      => l_use_dflt_enrt_rl
5590         ,p_business_group_id => p_business_group_id
5591         ,p_effective_date    => l_lf_evt_ocrd_dt
5592         ,p_level             => l_dflt_level
5593         ,p_ler_dflt_flag     => l_ler_dflt_flag
5594       );
5595 
5596      -- end bug 5644451
5597    if g_debug then
5598     hr_utility.set_location('Dn DrtDEC ' || l_proc, 10);
5599    end if;
5600     --
5601     -- Set the values for the dflt_flag
5602     --
5603     l_use_dflt_flag :=            NULL;
5604     IF l_ler_chg_found_flag = 'Y' THEN
5605       IF    l_ler_chg_oipl_found_flag = 'Y'
5606          OR (    l_ler_chg_oipl_found_flag = 'N'
5607              AND p_oipl_id IS NULL) THEN
5608         --
5609         -- Use flag only if at appropriate level
5610         --
5611         l_use_dflt_flag :=  l_ler_dflt_flag;
5612       END IF;
5613     END IF;
5614   if g_debug then
5615     hr_utility.set_location('U', 20);
5616   end if;
5617     --
5618     -- oipl level default code/flag
5619     --
5620     IF p_oipl_id IS NOT NULL THEN
5621       IF l_use_dflt_flag IS NULL THEN
5622         --
5623         -- use oipl level flag
5624         --
5625         l_use_dflt_flag :=  l_oipl_dflt_flag;
5626       END IF;
5627     END IF;
5628   if g_debug then
5629     hr_utility.set_location('U3', 30);
5630   end if;
5631     --
5632     -- plip level default code/flag
5633     --
5634     IF l_plip_id IS NOT NULL THEN
5635       IF l_use_dflt_flag IS NULL THEN
5636         l_use_dflt_flag :=  l_plip_dflt_flag;
5637       END IF;
5638     END IF;
5639     --
5640     if g_debug then
5641     hr_utility.set_location('V', 20);
5642     end if;
5643     --
5644     -- If no default flag is set then make it not a default.
5645     --
5646     IF l_use_dflt_flag IS NULL THEN
5647       --
5648       l_use_dflt_flag :=  'N';
5649     --
5650     END IF;
5651     if g_debug then
5652     hr_utility.set_location('  l_use_dflt_flag  ' ||  l_use_dflt_flag, 10);
5653     end if;
5654      determine_dflt_flag(
5655        l_use_dflt_flag,
5656        l_use_dflt_enrt_cd,
5657        l_crnt_enrt_cvg_strt_dt,
5658        l_previous_eligibility,
5659        l_use_dflt_enrt_rl,
5660        p_oipl_id,
5661        l_pl_id,
5662        p_pgm_id,
5663        p_effective_date,
5664        p_lf_evt_ocrd_dt,
5665        p_ler_id,
5666        l_opt_id,
5667        l_pl_typ_id,
5668        l_ptip_id,
5669        p_person_id,
5670        p_business_group_id,
5671        l_rec_assignment_id,
5672        l_dflt_flag,
5673        l_reinstt_flag,
5674        -- bug 5644451
5675        l_dflt_level,
5676        p_run_mode,           -- iRec
5677        l_elig_per_id   -- Bug 14768372
5678        );
5679      if l_reinstt_cd is null then
5680         l_reinstt_cd := l_reinstt_flag;
5681      end if;
5682    if g_debug then
5683     hr_utility.set_location(' Dn det_dflt_flag ' || l_proc, 10);
5684     hr_utility.set_location(' l_dflt_flag   ' ||  l_dflt_flag , 10);
5685     hr_utility.set_location(' l_dflt_level   ' ||  l_dflt_level , 10);--AMN Bug 14661357
5686    end if;
5687    /*Start AMN Bug 14653541: Commenting the below fixes
5688     --
5689     --Bug# 12621882 For a Comp.object After the rule evalutes the default enrolment flag,
5690     --              if l_dflt_flag = 'Y' then it again checks at the oipl level.
5691     --              Means option which is set as default at oipl level should only be defaulted.
5692     --ud changes start
5693     hr_utility.set_location(' l_use_dflt_enrt_cd   ' ||  l_use_dflt_enrt_cd , 10);
5694 
5695     IF l_use_dflt_enrt_cd ='RL' then
5696 
5697 	hr_utility.set_location(' l_use_dflt_enrt_cd   ' ||  l_use_dflt_enrt_cd , 10);
5698 	hr_utility.set_location(' p_oipl_id   ' ||  p_oipl_id , 10);
5699 
5700 	IF l_dflt_flag = 'Y' and p_oipl_id IS NOT NULL and l_dflt_level not in ('LER_OIPL','OIPL') then --AMN Bug 14661357
5701 
5702 		hr_utility.set_location(' p_oipl_id   ' ||  p_oipl_id , 10);
5703 		hr_utility.set_location(' l_oipl_dflt_flag   ' ||  l_oipl_dflt_flag , 10);
5704                 --Start AMN Bug 14661357
5705                 open c_ler_oipl_dflt_flag;
5706                 fetch c_ler_oipl_dflt_flag into l_ler_oipl_dflt_flag;
5707                 if c_ler_oipl_dflt_flag%notfound then
5708                         l_ler_oipl_dflt_flag := l_oipl_dflt_flag;
5709                 end if;
5710                 close c_ler_oipl_dflt_flag;
5711                 hr_utility.set_location(' l_ler_oipl_dflt_flag   ' ||  l_ler_oipl_dflt_flag , 10);
5712                 --End AMN Bug 14661357
5713 		If l_ler_oipl_dflt_flag = 'N' then --AMN Bug 14661357
5714 			l_dflt_flag := 'N';
5715 			hr_utility.set_location('l_dflt_flag ' || l_dflt_flag, 40);
5716 
5717 		end if;
5718 	end if;
5719     end if;
5720     --
5721     --ud changes end
5722     --Bug# 12621882
5723   End AMN Bug 14653541*/
5724     IF (l_dflt_flag = 'DEFER') THEN
5725       --
5726       l_dflt_flag :=  l_use_dflt_flag;
5727     --
5728     END IF;
5729     --Bug 2200139 Override Enrollment changes
5730     IF p_run_mode = 'V' then
5731       --
5732       l_dflt_flag := 'N' ;
5733       --
5734     end if;
5735     --
5736  END IF;
5737     -- Determine the enrt_perd_strt_dt and enrt_perd_end_dt.
5738     -- Determine the dflt_asnmt_dt
5739     -- Determine the procg_end_dt.
5740     -- GRADE/STEP : Extend L mode to cater Grade step process.
5741     -- iRec : Added mode 'I'
5742     --
5743     IF (p_run_mode in ('L', 'G', 'I')  AND p_run_mode <> 'D'
5744         AND l_unrestricted_enrt_flag = 'N') THEN
5745       --
5746       -- Get it from the lee_rsn_f for the plan (or program if not set)
5747       -- enrt_perd_strt_dt_cd and enrt_perd_end_dt_cd (and rules)
5748       -- What domain is this?  Determine the date using the code/rule.
5749       -- If Life event mode, set dflt_asnmt_dt to the
5750       -- enrt_perd_end_dt + dys_aftr_end_to_dflt_num.
5751       --
5752    if g_debug then
5753       hr_utility.set_location(' RM L UEF N ' || l_proc, 10);
5754    end if;
5755       IF (
5756                l_perd_for_plan_found = 'Y'
5757            AND l_ple_enrt_perd_strt_dt_cd IS NOT NULL) THEN
5758         --
5759         ben_determine_date.main(
5760           p_date_cd           => l_ple_enrt_perd_strt_dt_cd,
5761           p_per_in_ler_id     => l_per_in_ler_id,
5762           p_person_id         => p_person_id,
5763           p_pgm_id            => p_pgm_id,
5764           p_pl_id             => l_pl_id,
5765           p_oipl_id           => p_oipl_id,
5766           p_business_group_id => p_business_group_id,
5767           p_formula_id        => l_ple_enrt_perd_strt_dt_rl,
5768           p_effective_date    => p_effective_date,
5769           p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
5770           p_returned_date     => l_rec_enrt_perd_strt_dt);
5771 
5772          -- GHR enhancment
5773          if  l_ple_enrt_perd_strt_dt_cd  in ( 'NUMDOE', 'NUMDON','NUMDOEN') then
5774              l_rec_enrt_perd_strt_dt := l_rec_enrt_perd_strt_dt + nvl(l_ple_enrt_perd_strt_days,0) ;
5775          end if ;
5776         --
5777         -- The following logic was added by jcarpent for bug 4988/1269016
5778         -- based on tech design of maagrawa (1-6, 2 is done above)
5779         -- NOTE: please see identical logic for other modes.  Code added
5780         -- inline since we don't want to add additional function calls
5781         -- for performance reasons.
5782         --
5783       if g_debug then
5784         hr_utility.set_location(' PLS BLK 1 ' || l_proc, 10);
5785       end if;
5786         BEGIN
5787 	if g_debug then
5788           hr_utility.set_location(' entering ' || l_proc, 10);
5789         end if;
5790           -- jcarpent 1/4/2001 bug 1568555, removed +1 from line below
5791           -- 1 get latest processed date
5792           l_orig_epsd :=  l_rec_enrt_perd_strt_dt;
5793           --
5794           -- GRADE/STEP  : Following code is only applicable for L mode
5795           --
5796           if p_run_mode  = 'L' then
5797             -- 2746865
5798             -- call the enrt_perd_strt_dt procedure to compute the epsd and eped
5799             -- according to the enrt. period determination code
5800             -- removed inline code and made it a procedure
5801 	    if g_debug then
5802             hr_utility.set_location(' calling new proc ' , 20);
5803 	    end if;
5804             enrt_perd_strt_dt
5805             ( p_person_id => p_person_id
5806               , p_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt
5807               , p_enrt_perd_det_ovrlp_bckdt_cd => l_enrt_perd_det_ovrlp_bckdt_cd
5808               , p_rec_enrt_perd_strt_dt => l_rec_enrt_perd_strt_dt
5809               , p_ler_id => p_ler_id
5810               , p_business_group_id => p_business_group_id
5811               , p_effective_date => p_effective_date
5812               );
5813           end if;
5814 	  if g_debug then
5815           hr_utility.set_location(' l_rec_enrt_perd_strt_dt is '|| l_rec_enrt_perd_strt_dt , 876);
5816 	  end if;
5817         END;                                           -- of special epsd logic
5818 	if g_debug then
5819         hr_utility.set_location(' Dn PLS BLK 1 ' || l_proc, 10);
5820 	end if;
5821         ben_determine_date.main(
5822           p_date_cd           => l_ple_enrt_perd_end_dt_cd,
5823           p_start_date        => l_orig_epsd,
5824           p_per_in_ler_id     => l_per_in_ler_id,
5825           p_person_id         => p_person_id,
5826           p_pgm_id            => p_pgm_id,
5827           p_pl_id             => l_pl_id,
5828           p_oipl_id           => p_oipl_id,
5829           p_business_group_id => p_business_group_id,
5830           p_formula_id        => l_ple_enrt_perd_end_dt_rl,
5831           p_effective_date    => p_effective_date,
5832           p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
5833           p_param1            => 'ENRT_PERD_START_DATE',
5834           p_param1_value      => fnd_date.date_to_canonical(l_rec_enrt_perd_strt_dt),
5835           p_returned_date     => l_rec_enrt_perd_end_dt);
5836 
5837 
5838          -- GHR enhancment
5839          if  l_ple_enrt_perd_end_dt_cd  in ( 'NUMDOE', 'NUMDON','NUMDOEN') then
5840              l_rec_enrt_perd_end_dt := l_rec_enrt_perd_end_dt + nvl(l_ple_enrt_perd_end_days,0) ;
5841          end if ;
5842 
5843         --
5844 	if g_debug then
5845           hr_utility.set_location(' l_rec_enrt_perd_end_dt is '|| l_rec_enrt_perd_end_dt , 876);
5846         end if;
5847        --
5848        -- 2746865
5849 
5850        -- if cd is L_EPSD_PEPD or null, proceed as before
5851        IF ( nvl(l_enrt_perd_det_ovrlp_bckdt_cd,'L_EPSD_PEPD') = 'L_EPSD_PEPD') THEN
5852            hr_utility.set_location('L_EPSD_PEPD' , 765);
5853          l_rec_enrt_perd_end_dt :=
5854                 l_rec_enrt_perd_end_dt + (l_rec_enrt_perd_strt_dt - l_orig_epsd);
5855        -- 2746865
5856        ELSE
5857          -- for other codes
5858          -- if end dt is less than the start dt, make the strt dt as the end dt
5859          IF l_rec_enrt_perd_end_dt < l_rec_enrt_perd_strt_dt THEN
5860 	 if g_debug then
5861            hr_utility.set_location(' end dt < strt dt ', 876);
5862          end if;
5863          l_rec_enrt_perd_end_dt := l_rec_enrt_perd_strt_dt;
5864          END IF;
5865        END IF;
5866 	--
5867         l_rec_dflt_asnmt_dt :=
5868               l_rec_enrt_perd_end_dt + NVL(l_ple_dys_aftr_end_to_dflt_num, 0);
5869         -- Set it to the enrt_perd_end_dt + addt_procg_dys_num.
5870         l_rec_procg_end_dt :=
5871                    l_rec_enrt_perd_end_dt + NVL(l_ple_addit_procg_dys_num, 0);
5872         --
5873         l_rec_lee_rsn_id :=        l_ple_lee_rsn_id;
5874         --
5875 	if g_debug then
5876         hr_utility.set_location(' Dn RM L UEF N ' || l_proc, 10);
5877 	end if;
5878       ELSIF (
5879                   l_perd_for_program_found = 'Y'
5880               AND l_pgme_enrt_perd_strt_dt_cd IS NOT NULL) THEN
5881         --
5882 	if g_debug then
5883         hr_utility.set_location(' BDD_MN PFPF=Y ' || l_proc, 10);
5884 	end if;
5885         ben_determine_date.main(
5886           p_date_cd           => l_pgme_enrt_perd_strt_dt_cd,
5887           p_per_in_ler_id     => l_per_in_ler_id,
5888           p_person_id         => p_person_id,
5889           p_pgm_id            => p_pgm_id,
5890           p_pl_id             => l_pl_id,
5891           p_oipl_id           => p_oipl_id,
5892           p_business_group_id => p_business_group_id,
5893           p_formula_id        => l_pgme_enrt_perd_strt_dt_rl,
5894           p_effective_date    => p_effective_date,
5895           p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
5896           p_returned_date     => l_rec_enrt_perd_strt_dt);
5897 
5898 
5899         -- GHR enhancment
5900         if  l_pgme_enrt_perd_strt_dt_cd  in ( 'NUMDOE', 'NUMDON','NUMDOEN') then
5901             l_rec_enrt_perd_strt_dt := l_rec_enrt_perd_strt_dt + nvl(l_pgme_enrt_perd_strt_days,0) ;
5902         end if ;
5903 
5904         --
5905         -- The following logic was added by jcarpent for bug 4988/1269016
5906         -- based on tech design of maagrawa (1-6, 2 is done above)
5907         -- NOTE: please see identical logic for other modes.  Code added
5908         -- inline since we don't want to add additional function calls
5909         -- for performance reasons.
5910         --
5911         BEGIN
5912           -- jcarpent 1/4/2001 bug 1568555, removed +1 from line below
5913           -- 1 get latest processed date
5914           l_orig_epsd :=  l_rec_enrt_perd_strt_dt;
5915           --
5916           if p_run_mode  = 'L' then
5917           -- 2746865
5918           -- call the enrt_perd_strt_dt procedure
5919 	  -- removed inline code and made it a procedure
5920 	     enrt_perd_strt_dt
5921 	                ( p_person_id => p_person_id
5922 	                , p_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt
5923 	                , p_enrt_perd_det_ovrlp_bckdt_cd => l_enrt_perd_det_ovrlp_bckdt_cd
5924 	                , p_rec_enrt_perd_strt_dt => l_rec_enrt_perd_strt_dt
5925 	                , p_ler_id => p_ler_id
5926                         , p_business_group_id => p_business_group_id
5927                         , p_effective_date => p_effective_date
5928                         );
5929           --
5930 	  end if;
5931         END;                                           -- of special epsd logic
5932 	if g_debug then
5933         hr_utility.set_location(' Bef BDD_Mn ' || l_proc, 10);
5934 	end if;
5935         ben_determine_date.main(
5936           p_date_cd           => l_pgme_enrt_perd_end_dt_cd,
5937           p_start_date        => l_orig_epsd,
5938           p_per_in_ler_id     => l_per_in_ler_id,
5939           p_person_id         => p_person_id,
5940           p_pgm_id            => p_pgm_id,
5941           p_pl_id             => l_pl_id,
5942           p_oipl_id           => p_oipl_id,
5943           p_business_group_id => p_business_group_id,
5944           p_formula_id        => l_pgme_enrt_perd_end_dt_rl,
5945           p_effective_date    => p_effective_date,
5946           p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
5947           p_param1            => 'ENRT_PERD_START_DATE',
5948           p_param1_value      => fnd_date.date_to_canonical(l_rec_enrt_perd_strt_dt),
5949           p_returned_date     => l_rec_enrt_perd_end_dt);
5950           --
5951 
5952           -- GHR enhancment
5953           if  l_pgme_enrt_perd_end_dt_cd  in ( 'NUMDOE', 'NUMDON','NUMDOEN') then
5954               l_rec_enrt_perd_end_dt := l_rec_enrt_perd_end_dt + nvl(l_pgme_enrt_perd_end_days,0) ;
5955           end if ;
5956 
5957 
5958           -- 2746865
5959           -- if cd is L_EPSD_PEPD, proceed as before
5960           IF ( nvl(l_enrt_perd_det_ovrlp_bckdt_cd,'L_EPSD_PEPD') = 'L_EPSD_PEPD') THEN
5961             hr_utility.set_location('L_EPSD_PEPD' , 765);
5962             l_rec_enrt_perd_end_dt :=
5963                    l_rec_enrt_perd_end_dt + (l_rec_enrt_perd_strt_dt - l_orig_epsd);
5964           -- 2746865
5965           ELSE
5966             -- for other codes
5967             -- if end dt is less than the start dt, make the strt dt as the end dt
5968             IF l_rec_enrt_perd_end_dt < l_rec_enrt_perd_strt_dt THEN
5969 	    if g_debug then
5970               hr_utility.set_location(' end dt < strt dt ', 876);
5971             end if;
5972             l_rec_enrt_perd_end_dt := l_rec_enrt_perd_strt_dt;
5973             END IF;
5974           END IF;
5975 
5976         --
5977         l_rec_dflt_asnmt_dt :=
5978                  l_rec_enrt_perd_end_dt + NVL(l_pgme_dys_aftr_end_to_dflt, 0);
5979         -- Set it to the enrt_perd_end_dt + addt_procg_dys_num.
5980         l_rec_procg_end_dt :=
5981                   l_rec_enrt_perd_end_dt + NVL(l_pgme_addit_procg_dys_num, 0);
5982         --
5983         l_rec_lee_rsn_id :=        l_pgme_lee_rsn_id;
5984         --
5985 	if g_debug then
5986         hr_utility.set_location(' Dn PFPF=Y ' || l_proc, 10);
5987 	end if;
5988       ELSE
5989         --
5990         fnd_message.set_name('BEN', 'BEN_91335_PLAN_YR_ENRT_PERD');
5991         fnd_message.set_token('PROC', l_proc);
5992         fnd_message.set_token('PGM_ID', TO_CHAR(p_pgm_id));
5993         fnd_message.set_token('PL_ID', TO_CHAR(l_pl_id));
5994         fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
5995         fnd_message.set_token('LF_EVT_OCRD_DT', TO_CHAR(p_lf_evt_ocrd_dt));
5996         RAISE ben_manage_life_events.g_record_error;
5997       --
5998       END IF;                             -- perd found and strt_dt_cd not null
5999     --
6000     ELSIF (    p_run_mode in ( 'C', 'W') AND p_run_mode <> 'D'
6001            AND l_unrestricted_enrt_flag = 'N') THEN
6002       -- If scheduled mode, use enrt_perd.dflt_enrt_dt to determine dflt_asnmt_dt.
6003       IF (    l_perd_for_plan_found = 'Y'
6004           AND l_ple_enrt_perd_strt_dt IS NOT NULL) THEN
6005         --
6006         l_rec_enrt_perd_strt_dt :=  l_ple_enrt_perd_strt_dt;
6007         --
6008         -- The following logic was added by jcarpent for bug 4988/1269016
6009         -- based on tech design of maagrawa (1-6, 2 is done above)
6010         -- NOTE: please see identical logic for other modes.  Code added
6011         -- inline since we don't want to add additional function calls
6012         -- for performance reasons.
6013         --
6014         BEGIN
6015          -- jcarpent 1/4/2001 bug 1568555, removed +1 from line below
6016          -- 1 get latest processed date
6017          l_orig_epsd :=  l_rec_enrt_perd_strt_dt;
6018          --
6019          -- Comp work bench
6020          -- ABSENCES : do not reset the enrt perd.
6021          --
6022          if p_run_mode <> 'W' then
6023            --
6024            -- 2746865
6025 	   -- call the enrt_perd_strt_dt procedure
6026 	   -- removed inline code and made it a procedure
6027 	   enrt_perd_strt_dt
6028 	   ( p_person_id => p_person_id
6029 	   , p_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt
6030 	   , p_enrt_perd_det_ovrlp_bckdt_cd => l_enrt_perd_det_ovrlp_bckdt_cd
6031 	   , p_rec_enrt_perd_strt_dt => l_rec_enrt_perd_strt_dt
6032 	   , p_ler_id => p_ler_id
6033            , p_business_group_id => p_business_group_id
6034            , p_effective_date => p_effective_date
6035            );
6036            --
6037          end if; -- p_mode <> 'W'
6038         END;                                           -- of special epsd logic
6039         --
6040         -- 2746865
6041         -- if cd is L_EPSD_PEPD, proceed as before
6042 	if g_debug then
6043         hr_utility.set_location('l_ple_enrt_perd_end_dt ' ||l_ple_enrt_perd_end_dt, 765);
6044         hr_utility.set_location('l_rec_enrt_perd_end_dt ' ||l_rec_enrt_perd_end_dt, 765);
6045 	end if;
6046 
6047         IF ( nvl(l_enrt_perd_det_ovrlp_bckdt_cd,'L_EPSD_PEPD') = 'L_EPSD_PEPD') THEN
6048 	if g_debug then
6049           hr_utility.set_location('L_EPSD_PEPD' , 765);
6050         end if;
6051           l_rec_enrt_perd_end_dt :=
6052                 l_ple_enrt_perd_end_dt + (l_rec_enrt_perd_strt_dt - l_orig_epsd);
6053           --
6054           l_rec_procg_end_dt :=
6055                   l_ple_procg_end_dt + (l_rec_enrt_perd_strt_dt - l_orig_epsd);
6056         -- 2746865
6057         ELSE
6058           -- for other codes
6059 
6060           -- end dt is the greatest of start date and orig. end date
6061           /*IF l_ple_enrt_perd_end_dt < l_rec_enrt_perd_strt_dt THEN
6062             hr_utility.set_location(' end dt < strt dt ', 876);
6063             l_rec_enrt_perd_end_dt := l_rec_enrt_perd_strt_dt;
6064           ELSE
6065             l_rec_enrt_perd_end_dt := l_ple_enrt_perd_end_dt;
6066           END IF;
6067           */
6068 
6069           l_rec_enrt_perd_end_dt := greatest (l_rec_enrt_perd_strt_dt, l_ple_enrt_perd_end_dt);
6070 	  if g_debug then
6071           hr_utility.set_location('l_rec_enrt_perd_end_dt ' ||l_rec_enrt_perd_end_dt, 765);
6072 	  end if;
6073           --
6074           --  Bug 5650482.  If the enrollment period end date is greater that the
6075           --  processing end date, set processing end date to the enrollment
6076           --  period end date.
6077           --
6078           IF l_rec_enrt_perd_end_dt >=  l_ple_procg_end_dt then
6079             l_rec_procg_end_dt := l_rec_enrt_perd_end_dt;
6080           ELSE
6081             l_rec_procg_end_dt := l_ple_procg_end_dt;
6082           END IF;
6083           --
6084         END IF;
6085 	if g_debug then
6086         hr_utility.set_location('l_rec_procg_end_dt ' ||l_rec_procg_end_dt, 765);
6087 	end if;
6088         --
6089         l_rec_dflt_asnmt_dt :=
6090                   l_ple_dflt_enrt_dt + (l_rec_enrt_perd_strt_dt - l_orig_epsd);
6091         --
6092         /* l_rec_procg_end_dt :=
6093                   l_ple_procg_end_dt + (l_rec_enrt_perd_strt_dt - l_orig_epsd); */
6094         l_rec_enrt_perd_id :=       l_ple_enrt_perd_id;
6095       --
6096       ELSIF (
6097                   l_perd_for_program_found = 'Y'
6098               AND l_pgme_enrt_perd_strt_dt IS NOT NULL) THEN
6099         --
6100         l_rec_enrt_perd_strt_dt :=  l_pgme_enrt_perd_strt_dt;
6101         --
6102         -- The following logic was added by jcarpent for bug 4988/1269016
6103         -- based on tech design of maagrawa (1-6, 2 is done above)
6104         -- NOTE: please see identical logic for other modes.  Code added
6105         -- inline since we don't want to add additional function calls
6106         -- for performance reasons.
6107         --
6108         BEGIN
6109           -- jcarpent 1/4/2001 bug 1568555, removed +1 from line below
6110           -- 1 get latest processed date
6111           l_orig_epsd :=  l_rec_enrt_perd_strt_dt;
6112           -- 2746865
6113 	  -- call the enrt_perd_strt_dt procedure
6114 	  -- removed inline code and made it a procedure
6115 	  enrt_perd_strt_dt
6116 	  ( p_person_id => p_person_id
6117 	  , p_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt
6118 	  , p_enrt_perd_det_ovrlp_bckdt_cd => l_enrt_perd_det_ovrlp_bckdt_cd
6119 	  , p_rec_enrt_perd_strt_dt => l_rec_enrt_perd_strt_dt
6120 	  , p_ler_id => p_ler_id
6121           , p_business_group_id => p_business_group_id
6122           , p_effective_date => p_effective_date
6123 	  );
6124           --
6125         END;                                           -- of special epsd logic
6126 
6127         -- 2746865
6128         -- if cd is L_EPSD_PEPD, proceed as before
6129         if g_debug then
6130         hr_utility.set_location('l_ple_enrt_perd_end_dt ' ||l_ple_enrt_perd_end_dt, 765);
6131         hr_utility.set_location('l_rec_enrt_perd_end_dt ' ||l_rec_enrt_perd_end_dt, 765);
6132 	end if;
6133 
6134         IF ( nvl(l_enrt_perd_det_ovrlp_bckdt_cd,'L_EPSD_PEPD') = 'L_EPSD_PEPD') THEN
6135 	if g_debug then
6136           hr_utility.set_location('L_EPSD_PEPD' , 765);
6137         end if;
6138           l_rec_enrt_perd_end_dt :=
6139                l_pgme_enrt_perd_end_dt + (l_rec_enrt_perd_strt_dt - l_orig_epsd);
6140           l_rec_procg_end_dt :=
6141                  l_pgme_procg_end_dt + (l_rec_enrt_perd_strt_dt - l_orig_epsd);
6142         ELSE
6143           -- 2746865
6144           -- for other codes
6145           -- end dt is the greatest of start date and original end date
6146           l_rec_enrt_perd_end_dt := greatest ( l_pgme_enrt_perd_end_dt, l_rec_enrt_perd_strt_dt);
6147           --
6148           --  Bug 5650482.  If the enrollment period end date is greater that the
6149           --  processing end date, set processing end date to the enrollment
6150           --  period end date.
6151           --
6152           IF l_rec_enrt_perd_end_dt >=  l_pgme_procg_end_dt then
6153             l_rec_procg_end_dt := l_rec_enrt_perd_end_dt;
6154           ELSE
6155             l_rec_procg_end_dt := l_pgme_procg_end_dt;
6156           END IF;
6157           --
6158         END IF;
6159 	if g_debug then
6160         hr_utility.set_location('l_rec_procg_end_dt ' ||l_rec_procg_end_dt, 765);
6161         hr_utility.set_location('l_rec_enrt_perd_end_dt ' ||l_rec_enrt_perd_end_dt, 765);
6162 	end if;
6163         --
6164         l_rec_dflt_asnmt_dt :=
6165                  l_pgme_dflt_enrt_dt + (l_rec_enrt_perd_strt_dt - l_orig_epsd);
6166         --
6167         l_rec_enrt_perd_id :=       l_pgme_enrt_perd_id;
6168       --
6169       ELSE
6170         --
6171         fnd_message.set_name('BEN', 'BEN_91335_PLAN_YR_ENRT_PERD');
6172         fnd_message.set_token('PROC', l_proc);
6173         fnd_message.set_token('PGM_ID', TO_CHAR(p_pgm_id));
6174         fnd_message.set_token('PL_ID', TO_CHAR(l_pl_id));
6175         fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
6176         fnd_message.set_token('LF_EVT_OCRD_DT', TO_CHAR(p_lf_evt_ocrd_dt));
6177         RAISE ben_manage_life_events.g_record_error;
6178       --
6179       END IF;                             -- perd found and strt_dt_cd not null
6180     ELSIF (p_run_mode =  'M' AND l_unrestricted_enrt_flag = 'N') THEN  -- ABS processing
6181       --
6182       -- Get it from the lee_rsn_f for the plan
6183       -- enrt_perd_strt_dt_cd and enrt_perd_end_dt_cd (and rules)
6184       -- What domain is this?  Determine the date using the code/rule.
6185       -- set dflt_asnmt_dt to the
6186       -- enrt_perd_end_dt + dys_aftr_end_to_dflt_num.
6187       --
6188       if g_debug then
6189       hr_utility.set_location(' RM L UEF N ' || l_proc, 20);
6190       end if;
6191       IF ( l_perd_for_plan_found = 'Y'
6192            AND l_ple_enrt_perd_strt_dt_cd IS NOT NULL) THEN
6193         --
6194         ben_determine_date.main(
6195           p_date_cd           => l_ple_enrt_perd_strt_dt_cd,
6196           p_per_in_ler_id     => l_per_in_ler_id,
6197           p_person_id         => p_person_id,
6198           p_pgm_id            => p_pgm_id,
6199           p_pl_id             => l_pl_id,
6200           p_oipl_id           => p_oipl_id,
6201           p_business_group_id => p_business_group_id,
6202           p_formula_id        => l_ple_enrt_perd_strt_dt_rl,
6203           p_effective_date    => p_effective_date,
6204           p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
6205           p_returned_date     => l_rec_enrt_perd_strt_dt);
6206 
6207         -- GHR enhancment
6208         if  l_ple_enrt_perd_strt_dt_cd  in ( 'NUMDOE', 'NUMDON','NUMDOEN') then
6209             l_rec_enrt_perd_strt_dt := l_rec_enrt_perd_strt_dt + nvl(l_ple_enrt_perd_strt_days,0) ;
6210         end if ;
6211         --
6212         ben_determine_date.main(
6213           p_date_cd           => l_ple_enrt_perd_end_dt_cd,
6214           p_start_date        => l_orig_epsd,
6215           p_per_in_ler_id     => l_per_in_ler_id,
6216           p_person_id         => p_person_id,
6217           p_pgm_id            => p_pgm_id,
6218           p_pl_id             => l_pl_id,
6219           p_oipl_id           => p_oipl_id,
6220           p_business_group_id => p_business_group_id,
6221           p_formula_id        => l_ple_enrt_perd_end_dt_rl,
6222           p_effective_date    => p_effective_date,
6223           p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
6224           p_param1            => 'ENRT_PERD_START_DATE',
6225           p_param1_value      => fnd_date.date_to_canonical(l_rec_enrt_perd_strt_dt),
6226           p_returned_date     => l_rec_enrt_perd_end_dt);
6227 
6228 
6229         -- GHR enhancment
6230         if  l_ple_enrt_perd_end_dt_cd  in ( 'NUMDOE', 'NUMDON','NUMDOEN') then
6231             l_rec_enrt_perd_end_dt := l_rec_enrt_perd_end_dt + nvl(l_ple_enrt_perd_end_days,0) ;
6232         end if ;
6233 
6234         --
6235         l_rec_dflt_asnmt_dt :=
6236               l_rec_enrt_perd_end_dt + NVL(l_ple_dys_aftr_end_to_dflt_num, 0);
6237         -- Set it to the enrt_perd_end_dt + addt_procg_dys_num.
6238         l_rec_procg_end_dt :=
6239                    l_rec_enrt_perd_end_dt + NVL(l_ple_addit_procg_dys_num, 0);
6240         --
6241         l_rec_lee_rsn_id :=        l_ple_lee_rsn_id;
6242         --
6243 	if g_debug then
6244         hr_utility.set_location(' Dn RM L UEF N ' || l_proc, 20);
6245 	end if;
6246       ELSE
6247         --
6248         fnd_message.set_name('BEN', 'BEN_91335_PLAN_YR_ENRT_PERD');
6249         fnd_message.set_token('PROC', l_proc);
6250         fnd_message.set_token('PGM_ID', TO_CHAR(p_pgm_id));
6251         fnd_message.set_token('PL_ID', TO_CHAR(l_pl_id));
6252         fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
6253         fnd_message.set_token('LF_EVT_OCRD_DT', TO_CHAR(p_lf_evt_ocrd_dt));
6254         RAISE ben_manage_life_events.g_record_error;
6255       --
6256       END IF;                             -- perd found and strt_dt_cd not null
6257     --
6258     END IF;                                                         -- run mode
6259 -- END IF;
6260   if g_debug then
6261     hr_utility.set_location(' start DATE  ' || l_rec_enrt_perd_strt_dt, 92);
6262     hr_utility.set_location(' END DATE  ' || l_rec_enrt_perd_end_dt, 92);
6263   end if;
6264     -- Check to see if the start date is before the end date
6265     IF l_rec_enrt_perd_strt_dt > l_rec_enrt_perd_end_dt THEN
6266       --
6267       fnd_message.set_name('BEN', 'BEN_91735_END_BEFORE_STRT_DT');
6268       fnd_message.set_token('PROC', l_proc);
6269       fnd_message.set_token(
6270         'ENRT_PERD_STRT_DT',
6271         TO_CHAR(l_rec_enrt_perd_strt_dt));
6272       fnd_message.set_token(
6273         'ENRT_PERD_END_DT',
6274         TO_CHAR(l_rec_enrt_perd_end_dt));
6275       RAISE ben_manage_life_events.g_record_error;
6276     --
6277     END IF;
6278     --
6279     -- if sched mode and l_crnt_enrt_cvg_strt_dt is not null then
6280     -- see if plan has regulation of IRC Section 125 or 129.
6281     --
6282    /*
6283     l_regn_125_or_129_flag:='N';
6284     if p_run_mode='C' and
6285        l_crnt_enrt_cvg_strt_dt is not null then
6286       open c_regn_125_or_129;
6287       fetch c_regn_125_or_129 into l_regn_125_or_129_flag;
6288       hr_utility.set_location('regn_125_or_129='||l_regn_125_or_129_flag,10);
6289       close c_regn_125_or_129;
6290     end if;
6291  */
6292 --hr_utility.set_location('p_run_mode='||p_run_mode,1776);
6293 --hr_utility.set_location('l_crnt_enrt_cvg_strt_dt='||l_crnt_enrt_cvg_strt_dt,1776);
6294 --hr_utility.set_location('l_regn_125_or_129_flag='||l_regn_125_or_129_flag,1776);
6295     --
6296     -- Determine the enrolment coverage codes/rules
6297     -- If currently enrolled get from old enrollment.
6298     --
6299     IF l_crnt_enrt_cvg_strt_dt IS NOT NULL and
6300        l_new_cvg_strt='N' THEN
6301       l_rec_enrt_cvg_strt_dt :=  l_crnt_enrt_cvg_strt_dt;
6302 
6303        -- 2982606 when the coverage start date of the prev LE is in future
6304        -- and current LE is current or earlier than previous one
6305        -- create new result and not currently enrolled - two plan
6306      if g_debug then
6307        hr_utility.set_location('l_crnt_enrt_cvg_strt_dt='||
6308                                 l_crnt_enrt_cvg_strt_dt,1777);
6309      end if;
6310        if l_crnt_enrt_cvg_strt_dt > p_lf_evt_ocrd_dt then
6311             ben_determine_date.rate_and_coverage_dates
6312              (p_cache_mode          => TRUE
6313              ,p_per_in_ler_id       => l_per_in_ler_id
6314              ,p_person_id           => p_person_id
6315              ,p_pgm_id              => p_pgm_id
6316              ,p_pl_id               => l_pl_id
6317              ,p_oipl_id             => p_oipl_id
6318              ,p_par_ptip_id         => p_comp_obj_tree_row.par_ptip_id
6319              ,p_par_plip_id         => p_comp_obj_tree_row.par_plip_id
6320              ,p_lee_rsn_id          => l_rec_lee_rsn_id
6321              ,p_enrt_perd_id        => l_rec_enrt_perd_id
6322              ,p_business_group_id   => p_business_group_id
6323              ,p_which_dates_cd      => 'C'
6324              ,p_date_mandatory_flag => 'N'
6325              ,p_compute_dates_flag  => 'Y'
6326              ,p_enrt_cvg_strt_dt    => l_rec_enrt_cvg_strt_dt
6327              ,p_enrt_cvg_strt_dt_cd => l_dummy_enrt_cvg_strt_dt_cd
6328              ,p_enrt_cvg_strt_dt_rl => l_dummy_enrt_cvg_strt_dt_rl
6329              ,p_rt_strt_dt          => l_dummy_rt_strt_dt
6330              ,p_rt_strt_dt_cd       => l_dummy_rt_strt_dt_cd
6331              ,p_rt_strt_dt_rl       => l_dummy_rt_strt_dt_rl
6332              ,p_enrt_cvg_end_dt     => l_dummy_enrt_cvg_end_dt
6333              ,p_enrt_cvg_end_dt_cd  => l_dummy_enrt_cvg_end_dt_cd
6334              ,p_enrt_cvg_end_dt_rl  => l_dummy_enrt_cvg_end_dt_rl
6335              ,p_rt_end_dt           => l_dummy_rt_end_dt
6336              ,p_rt_end_dt_cd        => l_dummy_rt_end_dt_cd
6337              ,p_rt_end_dt_rl        => l_dummy_rt_end_dt_rl
6338              ,p_effective_date      => p_effective_date
6339             ,p_lf_evt_ocrd_dt       => GREATEST(
6340                                         NVL(p_lf_evt_ocrd_dt, l_prtn_strt_dt),
6341                                         NVL(l_prtn_strt_dt, p_lf_evt_ocrd_dt))
6342              );
6343 	     if g_debug then
6344              hr_utility.set_location('Done RACD:' || l_proc, 11);
6345 	     end if;
6346 
6347 	     if  l_rec_enrt_cvg_strt_dt >=   l_crnt_enrt_cvg_strt_dt then
6348                  l_rec_enrt_cvg_strt_dt :=  l_crnt_enrt_cvg_strt_dt;
6349              else
6350                  l_rec_enrt_cvg_strt_dt_cd   := L_dummy_enrt_cvg_strt_dt_cd ;
6351                  l_rec_enrt_cvg_strt_dt_rl   := l_dummy_enrt_cvg_strt_dt_rl ;
6352                  if (l_fut_rslt_exist) or nvl(l_crnt_enrt_sspndd_flag,'N') = 'Y' then  -------------Bug 8846328
6353 		 hr_utility.set_location('fur rslt exist or sspndd rec', 11);
6354                     ---Do nothing
6355 		 else
6356 		   hr_utility.set_location('fur rslt not exist', 11);
6357 		   l_rec_crntly_enrd_flag      := 'N' ;
6358 		 end if;
6359             end if;
6360 	    if g_debug then
6361             hr_utility.set_location('l_rec_enrt_cvg_strt_dt RACD:'|| l_rec_enrt_cvg_strt_dt, 11);
6362 	    end if;
6363 
6364        end if ;
6365        ---2982606
6366 
6367     ELSE
6368     if g_debug then
6369       hr_utility.set_location(' RACD:' || l_proc, 10);
6370     end if;
6371       ben_determine_date.rate_and_coverage_dates
6372         (p_cache_mode          => TRUE
6373         ,p_per_in_ler_id       => l_per_in_ler_id
6374         ,p_person_id           => p_person_id
6375         ,p_pgm_id              => p_pgm_id
6376         ,p_pl_id               => l_pl_id
6377         ,p_oipl_id             => p_oipl_id
6378         ,p_par_ptip_id         => p_comp_obj_tree_row.par_ptip_id
6379         ,p_par_plip_id         => p_comp_obj_tree_row.par_plip_id
6380         ,p_lee_rsn_id          => l_rec_lee_rsn_id
6381         ,p_enrt_perd_id        => l_rec_enrt_perd_id
6382 
6383         ,p_business_group_id   => p_business_group_id
6384         ,p_which_dates_cd      => 'C'
6385         ,p_date_mandatory_flag => 'N'
6386         ,p_compute_dates_flag  => 'Y'
6387         ,p_enrt_cvg_strt_dt    => l_rec_enrt_cvg_strt_dt
6388         ,p_enrt_cvg_strt_dt_cd => l_rec_enrt_cvg_strt_dt_cd
6389         ,p_enrt_cvg_strt_dt_rl => l_rec_enrt_cvg_strt_dt_rl
6390         ,p_rt_strt_dt          => l_dummy_rt_strt_dt
6391         ,p_rt_strt_dt_cd       => l_dummy_rt_strt_dt_cd
6392         ,p_rt_strt_dt_rl       => l_dummy_rt_strt_dt_rl
6393         ,p_enrt_cvg_end_dt     => l_dummy_enrt_cvg_end_dt
6394         ,p_enrt_cvg_end_dt_cd  => l_dummy_enrt_cvg_end_dt_cd
6395         ,p_enrt_cvg_end_dt_rl  => l_dummy_enrt_cvg_end_dt_rl
6396         ,p_rt_end_dt           => l_dummy_rt_end_dt
6397         ,p_rt_end_dt_cd        => l_dummy_rt_end_dt_cd
6398         ,p_rt_end_dt_rl        => l_dummy_rt_end_dt_rl
6399         ,p_effective_date      => p_effective_date
6400         ,p_lf_evt_ocrd_dt      => GREATEST(
6401                                    NVL(p_lf_evt_ocrd_dt, l_prtn_strt_dt),
6402                                    NVL(l_prtn_strt_dt, p_lf_evt_ocrd_dt))
6403         );
6404    if g_debug then
6405       hr_utility.set_location('Done RACD:' || l_proc, 10);
6406    end if;
6407     END IF;
6408     --
6409     -- Determine the erlst_deenrt_dt
6410     --
6411     if g_debug then
6412     hr_utility.set_location('AB', 20);
6413     end if;
6414     --
6415  IF p_run_mode <> 'D' THEN
6416     -- Find the required period of enrollment code/rule/uom/level defined at
6417     --
6418     find_rqd_perd_enrt(
6419       p_oipl_id                 => p_oipl_id,
6420       p_opt_id                  => l_opt_id,
6421       p_pl_id                   => l_pl_id,
6422       p_ptip_id                 => l_ptip_id,
6423 /*
6424       p_parptip_row             => p_parptip_row,
6425       p_parpl_row               => p_parpl_row,
6426       p_paropt_row              => p_paropt_row,
6427       p_paroipl_row             => p_paroipl_row,
6428 */
6429       p_effective_date          => NVL(p_lf_evt_ocrd_dt, p_effective_date),
6430       p_business_group_id       => p_business_group_id,
6431       p_rqd_perd_enrt_nenrt_uom => l_rqd_perd_enrt_nenrt_uom,
6432       p_rqd_perd_enrt_nenrt_val => l_rqd_perd_enrt_nenrt_val,
6433       p_rqd_perd_enrt_nenrt_rl  => l_rqd_perd_enrt_nenrt_rl,
6434       p_level                   => l_level);
6435     --
6436     -- If don't have an existing erlst_deenrt_dt and
6437     -- there is a code defined at some level
6438     -- then see if the date is set on some pen row at that level
6439     -- levels are OIPL, OPT, PL, PTIP.
6440     --
6441     IF     l_crnt_erlst_deenrt_dt IS NULL
6442        AND l_level IS NOT NULL THEN
6443       find_enrt_at_same_level(
6444         p_person_id         => p_person_id,
6445         p_opt_id            => l_opt_id,
6446         p_oipl_id           => p_oipl_id,
6447         p_pl_id             => l_pl_id,
6448         p_ptip_id           => l_ptip_id,
6449         p_pl_typ_id         => l_pl_typ_id,
6450         p_pgm_id            => p_pgm_id,
6451         p_effective_date    => NVL(p_lf_evt_ocrd_dt, p_effective_date),
6452         p_business_group_id => p_business_group_id,
6453         p_prtt_enrt_rslt_id => -1,
6454         p_level             => l_level,
6455         p_pen_rec           => l_pen_rec);
6456         l_crnt_erlst_deenrt_dt :=  l_pen_rec.erlst_deenrt_dt;
6457 	if g_debug then
6458         hr_utility.set_location('l_crnt_erlst_deenrt_dt' || l_crnt_erlst_deenrt_dt,8086.0);
6459 	end if;
6460     END IF;
6461     --if elst_deenrt_dt is plan leven use original entrol date or
6462     -- option level  use coverage date
6463     l_erlst_deenrt_calc_dt   := l_rec_enrt_cvg_strt_dt  ;
6464     if l_level is not null then
6465       if l_level not in ('OPT','OIPL') then
6466          l_erlst_deenrt_calc_dt   := nvl(l_orgnl_enrt_dt,l_rec_enrt_cvg_strt_dt );
6467       end if ;
6468     end if ;
6469     if g_debug then
6470     hr_utility.set_location('l_erlst_deenrt_calc_dt' || l_erlst_deenrt_calc_dt ,8086);
6471     hr_utility.set_location('l_rec_enrt_cvg_strt_dt' || l_rec_enrt_cvg_strt_dt ,8086);
6472     end if;
6473     --
6474     -- if the enrt_cvg_strt_dt cannot be determined or
6475     -- the current enrt erlst_deenrt_dt is not null then
6476     -- use the old one
6477     --
6478     --IF ( l_rec_enrt_cvg_strt_dt IS NULL
6479     IF ( l_erlst_deenrt_calc_dt IS NULL
6480         OR l_crnt_erlst_deenrt_dt IS NOT NULL) THEN
6481       -- use the erlst_deenrt_dt from the current enrolment
6482       l_rec_erlst_deenrt_dt :=  l_crnt_erlst_deenrt_dt;
6483       --
6484     --
6485     -- else if the new enrolment cvg_strt_dt is set
6486     -- and the ptip.rqd_perd_enrt_nenrt_val is set then
6487     -- compute a new value
6488     --
6489     ELSIF (
6490                 l_erlst_deenrt_calc_dt IS NOT NULL
6491             AND (
6492                      (
6493                            l_rqd_perd_enrt_nenrt_val IS NOT NULL
6494                        AND l_rqd_perd_enrt_nenrt_uom IS NOT NULL)
6495                   OR l_rqd_perd_enrt_nenrt_rl IS NOT NULL)) THEN
6496       --
6497       -- compute the date based on the enrt_cvg_strt_dt and the
6498       -- rqd_perd_enrt_nenrt_val/uom.
6499       --
6500       l_rec_erlst_deenrt_dt :=
6501        determine_erlst_deenrt_dt(
6502          l_erlst_deenrt_calc_dt,
6503          l_rqd_perd_enrt_nenrt_val,
6504          l_rqd_perd_enrt_nenrt_uom,
6505          l_rqd_perd_enrt_nenrt_rl,
6506          p_oipl_id,
6507          l_pl_id,
6508          l_pl_typ_id,
6509          l_opt_id,
6510          p_pgm_id,
6511          p_ler_id,
6512          l_popl_yr_perd_ordr_num,
6513          l_yr_perd_end_date,
6514          p_effective_date,
6515          p_lf_evt_ocrd_dt,
6516          p_person_id,
6517          p_business_group_id,
6518          l_rec_assignment_id,
6519          l_rec_organization_id,
6520          l_jurisdiction_code);
6521     --
6522     ELSE
6523       -- Leave it blank.
6524       l_rec_erlst_deenrt_dt :=  NULL;
6525     --
6526     END IF;
6527   if g_debug then
6528     hr_utility.set_location('l_rec_erlst_deenrt_dt' || l_rec_erlst_deenrt_dt  ,8086);
6529   end if;
6530     --
6531 END IF; --'D' Mode
6532     -- set the comp_lvl_cd
6533     --
6534     IF (p_oipl_id IS NULL) THEN
6535       --
6536       IF l_invk_flx_cr_pl_flag = 'Y' THEN
6537         --
6538         l_rec_elctbl_flag :=  'N';
6539         l_comp_lvl_cd :=      'PLANFC';
6540       --
6541       ELSIF l_imptd_incm_calc_cd IN ('PRTT', 'DPNT', 'SPS') THEN
6542         --
6543         l_rec_elctbl_flag :=  'N';
6544         l_comp_lvl_cd :=      'PLANIMP';
6545       --
6546       ELSE
6547         --
6548         l_comp_lvl_cd :=  'PLAN';
6549       --
6550       END IF;
6551     --
6552     ELSE
6553       --
6554       l_comp_lvl_cd :=  'OIPL';
6555     --
6556     END IF;
6557     --
6558     -- Default the remaining fields
6559     -- roll_crs_only_flag to N
6560     --
6561     l_rec_roll_crs_only_flag :=   'N';
6562     -- elctns_made_flag to N
6563     l_rec_elctns_made_flag :=     'N';
6564     --
6565     -- Check all comp objects for existance when enrt perd starts
6566     --
6567     -- Start with pgm related things
6568     --
6569     --
6570     -- following requery logic added for bug 1394507 - for all plan design
6571     -- objects
6572     --
6573     IF p_pgm_id IS NOT NULL THEN
6574       --
6575       -- check pgm
6576       --
6577       IF (
6578            l_rec_enrt_perd_strt_dt NOT BETWEEN l_pgm_rec.effective_start_date
6579                AND l_pgm_rec.effective_end_date) THEN
6580         open c_pgm_requery(p_pgm_id,l_rec_enrt_perd_strt_dt);
6581         fetch c_pgm_requery into l_dummy;
6582         if c_pgm_requery%notfound then
6583 	if g_debug then
6584           hr_utility.set_location(
6585             'Program not date effective on period start',
6586             10);
6587         end if;
6588           fnd_message.set_name('BEN', 'BEN_92214_PGM_NOT_EFF_ON_STRT');
6589           fnd_message.set_token('PROC', l_proc);
6590           fnd_message.set_token(
6591             'ENRT_PERD_STRT_DT',
6592             TO_CHAR(l_rec_enrt_perd_strt_dt));
6593           fnd_message.set_token(
6594             'PGM_STRT_DT',
6595             TO_CHAR(l_pgm_rec.effective_start_date));
6596           fnd_message.set_token(
6597             'PGM_END_DT',
6598             TO_CHAR(l_pgm_rec.effective_end_date));
6599           benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
6600           p_electable_flag :=  'N';
6601           RETURN;
6602         end if;
6603         close c_pgm_requery;
6604       END IF;
6605       --
6606       -- check plip
6607       --
6608       IF (l_rec_enrt_perd_strt_dt NOT BETWEEN l_plip_esd AND l_plip_eed) THEN
6609         open c_plip_requery(l_plip_id,l_rec_enrt_perd_strt_dt);
6610         fetch c_plip_requery into l_dummy;
6611         if c_plip_requery%notfound then
6612 	if g_debug then
6613           hr_utility.set_location('Plip not date effective on period start', 10);
6614         end if;
6615           fnd_message.set_name('BEN', 'BEN_92208_PLIP_NOT_EFF_ON_STRT');
6616           fnd_message.set_token('PROC', l_proc);
6617           fnd_message.set_token(
6618             'ENRT_PERD_STRT_DT',
6619             TO_CHAR(l_rec_enrt_perd_strt_dt));
6620           fnd_message.set_token('PLIP_STRT_DT', TO_CHAR(l_plip_esd));
6621           fnd_message.set_token('PLIP_END_DT', TO_CHAR(l_plip_eed));
6622           benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
6623           p_electable_flag :=  'N';
6624           RETURN;
6625         end if;
6626         close c_plip_requery;
6627       END IF;
6628 
6629    if g_debug then
6630       hr_utility.set_location('NHK: l_lf_evt_ocrd_dt ' || l_lf_evt_ocrd_dt , 10);
6631       hr_utility.set_location('NHK: l_rec_enrt_perd_strt_dt ' || l_rec_enrt_perd_strt_dt , 20);
6632       hr_utility.set_location('NHK: l_ptip_esd ' || l_ptip_esd , 30);
6633       hr_utility.set_location('NHK: l_ptip_eed ' || l_ptip_eed , 40);
6634       hr_utility.set_location('NHK: p_electable_flag ' || p_electable_flag , 50);
6635       --
6636    end if;
6637       -- check ptip
6638       --
6639       IF (l_rec_enrt_perd_strt_dt NOT BETWEEN l_ptip_esd AND l_ptip_eed) THEN
6640       if g_debug then
6641         hr_utility.set_location('NHK: p_electable_flag ' || p_electable_flag , 60);
6642 	end if;
6643         open c_ptip_requery(l_ptip_id,l_rec_enrt_perd_strt_dt);
6644         fetch c_ptip_requery into l_dummy;
6645         if c_ptip_requery%notfound then
6646 	if g_debug then
6647           hr_utility.set_location('Ptip not date effective on period start', 10);
6648         end if;
6649           fnd_message.set_name('BEN', 'BEN_92213_PTIP_NOT_EFF_ON_STRT');
6650           fnd_message.set_token('PROC', l_proc);
6651           fnd_message.set_token(
6652             'ENRT_PERD_STRT_DT',
6653             TO_CHAR(l_rec_enrt_perd_strt_dt));
6654           fnd_message.set_token('PTIP_STRT_DT', TO_CHAR(l_ptip_esd));
6655           fnd_message.set_token('PTIP_END_DT', TO_CHAR(l_ptip_eed));
6656           benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
6657           p_electable_flag :=  'N';
6658           -- Bug fix 2008871 -- hnarayan
6659           close c_ptip_requery;
6660           RETURN;
6661           -- End fix 2008871
6662 	  if g_debug then
6663           hr_utility.set_location('NHK: p_electable_flag ' || p_electable_flag , 70);
6664 	  end if;
6665         end if;
6666         close c_ptip_requery;
6667 	if g_debug then
6668         hr_utility.set_location('NHK: p_electable_flag ' || p_electable_flag , 80);
6669 	end if;
6670         -- Bug fix 2008871 -- hnarayan -- commented the return and included it above
6671         --  			since it affects positive cases of electability
6672         --			when l_rec_enrt_perd_strt_dt is not between the
6673         --			active ptip record which is effective (retrieved in c_ptip_requery also)
6674         --			as per the l_lf_ocrd_dt.
6675         -- RETURN;
6676       END IF;
6677     END IF;
6678     --
6679     -- Continue with option related things
6680     --
6681     IF p_oipl_id IS NOT NULL THEN
6682       --
6683       -- check oipl
6684       --
6685       IF (
6686            l_rec_enrt_perd_strt_dt NOT BETWEEN l_oipl_rec.effective_start_date
6687                AND l_oipl_rec.effective_end_date) THEN
6688         open c_oipl_requery(p_oipl_id,l_rec_enrt_perd_strt_dt);
6689         fetch c_oipl_requery into l_dummy;
6690         if c_oipl_requery%notfound then
6691 	if g_debug then
6692         hr_utility.set_location('Oipl not date effective on period start', 10);
6693 	end if;
6694         fnd_message.set_name('BEN', 'BEN_92207_OIPL_NOT_EFF_ON_STRT');
6695         fnd_message.set_token('PROC', l_proc);
6696         fnd_message.set_token(
6697           'ENRT_PERD_STRT_DT',
6698           TO_CHAR(l_rec_enrt_perd_strt_dt));
6699         fnd_message.set_token(
6700           'OIPL_STRT_DT',
6701           TO_CHAR(l_oipl_rec.effective_start_date));
6702         fnd_message.set_token(
6703           'OIPL_END_DT',
6704           TO_CHAR(l_oipl_rec.effective_end_date));
6705         benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
6706         p_electable_flag :=  'N';
6707         RETURN;
6708         end if;
6709         close c_oipl_requery;
6710       END IF;
6711       --
6712       -- check opt
6713       --
6714       IF (
6715            l_rec_enrt_perd_strt_dt NOT BETWEEN ben_cobj_cache.g_opt_currow.effective_start_date
6716                AND ben_cobj_cache.g_opt_currow.effective_end_date) THEN
6717         open c_opt_requery(l_opt_id,l_rec_enrt_perd_strt_dt);
6718         fetch c_opt_requery into l_dummy;
6719         if c_opt_requery%notfound then
6720 	if g_debug then
6721         hr_utility.set_location(
6722           'Option not date effective on period start',
6723           10);
6724         end if;
6725         fnd_message.set_name('BEN', 'BEN_92212_OPT_NOT_EFF_ON_STRT');
6726         fnd_message.set_token('PROC', l_proc);
6727         fnd_message.set_token(
6728           'ENRT_PERD_STRT_DT',
6729           TO_CHAR(l_rec_enrt_perd_strt_dt));
6730         fnd_message.set_token(
6731           'OPT_STRT_DT',
6732           TO_CHAR(ben_cobj_cache.g_opt_currow.effective_start_date));
6733         fnd_message.set_token(
6734           'OPT_END_DT',
6735           TO_CHAR(ben_cobj_cache.g_opt_currow.effective_end_date));
6736         benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
6737         p_electable_flag :=  'N';
6738         RETURN;
6739         end if;
6740         close c_opt_requery;
6741       END IF;
6742     END IF;
6743     --
6744     -- check plan
6745     --
6746     IF (
6747          l_rec_enrt_perd_strt_dt NOT BETWEEN l_plan_rec.effective_start_date
6748              AND l_plan_rec.effective_end_date) THEN
6749         open c_plan_requery(l_pl_id,l_rec_enrt_perd_strt_dt);
6750         fetch c_plan_requery into l_dummy;
6751         if c_plan_requery%notfound then
6752      if g_debug then
6753       hr_utility.set_location('Plan not date effective on period start', 10);
6754       hr_utility.set_location('perd_strt_dt=' || l_rec_enrt_perd_strt_dt, 1);
6755       hr_utility.set_location('strt_dt=' || l_plan_rec.effective_start_date, 1);
6756       hr_utility.set_location('end_dt=' || l_plan_rec.effective_end_date, 1);
6757      end if;
6758       fnd_message.set_name('BEN', 'BEN_92211_PLAN_NOT_EFF_ON_STRT');
6759       fnd_message.set_token('PROC', l_proc);
6760       fnd_message.set_token(
6761         'ENRT_PERD_STRT_DT',
6762         TO_CHAR(l_rec_enrt_perd_strt_dt));
6763       fnd_message.set_token(
6764         'PL_STRT_DT',
6765         TO_CHAR(l_plan_rec.effective_start_date));
6766       fnd_message.set_token(
6767         'PL_END_DT',
6768         TO_CHAR(l_plan_rec.effective_end_date));
6769       benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
6770       p_electable_flag :=  'N';
6771       RETURN;
6772         end if;
6773         close c_plan_requery;
6774     END IF;
6775     --
6776     -- check pl_typ
6777     --
6778     OPEN c_pl_typ;
6779     FETCH c_pl_typ INTO l_pl_typ_esd, l_pl_typ_eed;
6780     CLOSE c_pl_typ;
6781     if g_debug then
6782     hr_utility.set_location('close c_pl_typ:' || l_proc, 10);
6783     end if;
6784     IF (l_rec_enrt_perd_strt_dt NOT BETWEEN l_pl_typ_esd AND l_pl_typ_eed) THEN
6785         open c_pl_typ_requery(l_pl_typ_id,l_rec_enrt_perd_strt_dt);
6786         fetch c_pl_typ_requery into l_dummy;
6787         if c_pl_typ_requery%notfound then
6788       if g_debug then
6789       hr_utility.set_location('Pl_typ not date effective on period start', 10);
6790       end if;
6791       fnd_message.set_name('BEN', 'BEN_92206_PL_TYP_NOT_EFF_ON_ST');
6792       fnd_message.set_token('PROC', l_proc);
6793       fnd_message.set_token(
6794         'ENRT_PERD_STRT_DT',
6795         TO_CHAR(l_rec_enrt_perd_strt_dt));
6796       fnd_message.set_token('PL_TYP_STRT_DT', TO_CHAR(l_pl_typ_esd));
6797       fnd_message.set_token('PL_TYP_END_DT', TO_CHAR(l_pl_typ_eed));
6798       benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
6799       p_electable_flag :=  'N';
6800       RETURN;
6801         end if;
6802         close c_pl_typ_requery;
6803     END IF;
6804     --
6805     -- check lee_rsn
6806     --
6807     IF (
6808          l_rec_enrt_perd_strt_dt NOT BETWEEN l_rec_lee_rsn_esd
6809              AND l_rec_lee_rsn_eed) THEN
6810         open c_lee_rsn_requery(l_rec_lee_rsn_id,l_rec_enrt_perd_strt_dt);
6811         fetch c_lee_rsn_requery into l_dummy;
6812         if c_lee_rsn_requery%notfound then
6813     if g_debug then
6814       hr_utility.set_location(
6815         'Lee_rsn not date effective on period start',
6816         10);
6817     end if;
6818       fnd_message.set_name('BEN', 'BEN_92210_LEE_RSN_NOT_EFF_ON_S');
6819       fnd_message.set_token('PROC', l_proc);
6820       fnd_message.set_token(
6821         'ENRT_PERD_STRT_DT',
6822         TO_CHAR(l_rec_enrt_perd_strt_dt));
6823       fnd_message.set_token('LEE_RSN_STRT_DT', TO_CHAR(l_rec_lee_rsn_esd));
6824       fnd_message.set_token('LEE_RSN_END_DT', TO_CHAR(l_rec_lee_rsn_eed));
6825       benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
6826       p_electable_flag :=  'N';
6827       RETURN;
6828         end if;
6829         close c_lee_rsn_requery;
6830     END IF;
6831     --
6832     -- check ler
6833     --
6834     IF (l_rec_enrt_perd_strt_dt NOT BETWEEN l_ler_esd AND l_ler_eed) THEN
6835         open c_ler_requery(p_ler_id,l_rec_enrt_perd_strt_dt);
6836         fetch c_ler_requery into l_dummy;
6837         if c_ler_requery%notfound then
6838     if g_debug then
6839       hr_utility.set_location('Ler not date effective on period start', 10);
6840     end if;
6841       fnd_message.set_name('BEN', 'BEN_92209_LER_NOT_EFF_ON_STRT');
6842       fnd_message.set_token('PROC', l_proc);
6843       fnd_message.set_token(
6844         'ENRT_PERD_STRT_DT',
6845         TO_CHAR(l_rec_enrt_perd_strt_dt));
6846       fnd_message.set_token('LER_STRT_DT', TO_CHAR(l_ler_esd));
6847       fnd_message.set_token('LER_END_DT', TO_CHAR(l_ler_eed));
6848       benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
6849       p_electable_flag :=  'N';
6850       RETURN;
6851         end if;
6852         close c_ler_requery;
6853     END IF;
6854     --
6855     -- set the acty_ref_perd_cd and uom
6856     --
6857     IF p_pgm_id IS NOT NULL THEN
6858       l_rec_acty_ref_perd_cd :=  l_pgm_rec.acty_ref_perd_cd;
6859       l_rec_uom :=               l_pgm_rec.pgm_uom;
6860     ELSE                                                        -- use the plan
6861       l_rec_acty_ref_perd_cd :=  l_plan_rec.nip_acty_ref_perd_cd;
6862       l_rec_uom :=               l_plan_rec.nip_pl_uom;
6863     END IF;
6864     --
6865     -- Set the auto_enrt_flag based on which comp level is being created
6866     --
6867     IF p_oipl_id IS NOT NULL THEN
6868       l_rec_auto_enrt_flag :=  l_oipl_auto_enrt_flag;
6869     ELSE
6870       l_rec_auto_enrt_flag :=  l_auto_enrt_flag;
6871     END IF;
6872     --
6873     --Based on automatic enrollment codes, the auto enrt flag needs to
6874     --be overridden
6875     If l_pl_enrt_cd = 'CANA' then
6876       --
6877       l_rec_auto_enrt_flag := 'Y' ;
6878       --
6879     elsif l_pl_enrt_cd = 'CANN' and l_rec_crntly_enrd_flag = 'Y' then
6880       --
6881       l_rec_auto_enrt_flag := 'Y' ;
6882       --
6883     elsif l_pl_enrt_cd = 'CANN' and l_rec_crntly_enrd_flag = 'N' then
6884       --
6885       l_rec_auto_enrt_flag := 'N';
6886       --
6887     elsif l_pl_enrt_cd = 'CNNA' and nvl(l_rec_crntly_enrd_flag,'N') = 'N' then
6888       --
6889       l_rec_auto_enrt_flag := 'Y';
6890       --
6891     elsif l_pl_enrt_cd = 'CNNA' and l_rec_crntly_enrd_flag = 'Y' then
6892       --
6893       l_rec_auto_enrt_flag := 'N';
6894       --
6895     end if;
6896 
6897       --
6898 
6899     -- Choice can be either automatic or default, not both.
6900     --
6901     IF l_rec_auto_enrt_flag = 'Y' THEN
6902       --
6903       l_dflt_flag :=  'N';
6904     --
6905     END IF;
6906     --
6907     -- Validate cls_enrt_dt_to_use_cd is defined
6908     --
6909     IF l_rec_cls_enrt_dt_to_use_cd IS NULL THEN
6910       --
6911 --      hr_utility.set_location('Invalid cls_enrt_dt_cd', 10);
6912       --
6913       fnd_message.set_name('BEN', 'BEN_91905_INVLD_CLS_ENRT_DT_CD');
6914       fnd_message.set_token('PROC', l_proc);
6915       fnd_message.set_token(
6916         'CLS_ENRT_DT_TO_USE_CD',
6917         l_rec_cls_enrt_dt_to_use_cd);
6918       RAISE ben_manage_life_events.g_record_error;
6919     --
6920     END IF;
6921     --
6922     -- We need to determine if an electable choice has been written or not
6923     --
6924 --    hr_utility.set_location('AG', 20);
6925     IF p_ler_id IS NOT NULL THEN
6926       --
6927       g_any_choice_created :=  TRUE;
6928       IF l_rec_elctbl_flag = 'Y' THEN
6929         g_electable_choice_created :=  TRUE;
6930       END IF;
6931       IF l_rec_auto_enrt_flag = 'Y' THEN
6932         g_auto_choice_created :=  TRUE;
6933       END IF;
6934     --
6935     END IF;
6936     -- cwb changes
6937     if p_run_mode = 'W' then
6938 
6939        g_ple_hrchy_to_use_cd       := l_ple_hrchy_to_use_cd;
6940        g_ple_pos_structure_version_id := l_ple_pos_structure_version_id;
6941        --
6942        /*
6943        -- For GLOBALCWB : this call is moved to benptnle
6944        get_cwb_manager_and_assignment(p_person_id => p_person_id,
6945                                       p_hrchy_to_use_cd => l_ple_hrchy_to_use_cd,
6946                                       p_pos_structure_version_id => l_ple_pos_structure_version_id,
6947                                       p_effective_date => p_effective_date,
6948                                       p_manager_id     => l_ws_mgr_id,
6949                                       p_assignment_id  => l_assignment_id ) ;
6950        */
6951        --
6952     end if;
6953 
6954     -- Bug 2503570
6955     -- 1. Irrespective of a person is eligible or not Elctble_flag is set to Y
6956     -- in case of CWB electable choices. Electable choices created for
6957     -- managers will always have Elctble_flag set to N.
6958     -- 2. If person is not eligible then elig_flag will be set to N else Y.
6959     --
6960     if p_run_mode = 'W' then
6961        l_rec_elctbl_flag := 'Y';
6962     end if;
6963 
6964     if l_current_eligibility = 'Y' then
6965        l_elig_flag := 'Y';
6966     else
6967        l_elig_flag  := 'N';
6968     end if;
6969 --
6970 --    hr_utility.set_location('Calling Create Api', 10);
6971 --    hr_utility.set_location('p_enrt_perd_id ' || l_rec_enrt_perd_id, 10);
6972 --    hr_utility.set_location('p_lee_rsn_id ' || l_rec_lee_rsn_id, 10);
6973 --    hr_utility.set_location('l_per_in_ler_id ' || l_per_in_ler_id, 10);
6974 --    hr_utility.set_location('l_prtt_enrt_rslt_id ' || l_prtt_enrt_rslt_id, 10);
6975     --
6976     /* if p_run_mode = 'W'
6977     then  Bug 3502094  : For FP-F this flag do not have any significance.
6978                            For july FP : final functionality will be decided.
6979       and l_elig_flag = 'N' and
6980        ( (p_oipl_id is null and
6981           nvl(l_pl_trk_inelig_per_flag,'N') = 'N') or
6982          (p_oipl_id is not null and
6983           nvl(l_oipl_trk_inelig_per_flag,'N') = 'N') ) then
6984        hr_utility.set_location('By passing creation of epe for CWB'||l_proc,10);
6985     else
6986     */
6987        if ben_manage_life_events.fonm = 'Y' then
6988        if g_debug then
6989           hr_utility.set_location('fonm cvr strt dt',100);
6990        end if;
6991           l_fonm_cvg_strt_dt := ben_manage_life_events.g_fonm_cvg_strt_dt;
6992        end if;
6993        if g_debug then
6994        hr_utility.set_location('EPEC_CRE: ' || l_proc, 10);
6995        end if;
6996        /* unrestricted Enh*/
6997        if p_run_mode in ('U','R') then
6998        if g_debug then
6999           hr_utility.set_location('before epe exists',11);
7000        end if;
7001          --
7002          l_epe_exists :=  ben_manage_unres_life_events.epe_exists
7003                   (p_per_in_ler_id => l_per_in_ler_id,
7004                    p_pgm_id => p_pgm_id,
7005                    p_pl_id  => l_pl_id,
7006                    p_oipl_id =>p_oipl_id);
7007          if l_epe_exists is not null then
7008             ben_manage_unres_life_events.update_elig_per_elctbl_choice
7009             (
7010              p_elig_per_elctbl_chc_id => l_epe_exists,
7011              p_business_group_id      => p_business_group_id,
7012              p_auto_enrt_flag         => NVL(l_rec_auto_enrt_flag,'N'),
7013              p_per_in_ler_id          => l_per_in_ler_id,
7014              p_yr_perd_id             => l_yr_perd_id,
7015              p_pl_id                  => l_pl_id,
7016              p_pl_typ_id              => l_pl_typ_id,
7017              p_oipl_id                => p_oipl_id,
7018              p_pgm_id                 => p_pgm_id,
7019              p_pgm_typ_cd             => l_pgm_rec.pgm_typ_cd,
7020              p_must_enrl_anthr_pl_id  => l_must_enrl_anthr_pl_id,
7021              p_plip_id                => l_plip_id,
7022              p_ptip_id                => l_ptip_id,
7023              p_prtt_enrt_rslt_id      => l_prtt_enrt_rslt_id,
7024              p_comp_lvl_cd            => l_comp_lvl_cd,
7025              p_enrt_cvg_strt_dt_cd    => l_rec_enrt_cvg_strt_dt_cd,
7026              p_enrt_perd_end_dt       => l_rec_enrt_perd_end_dt,
7027              p_enrt_perd_strt_dt      => l_rec_enrt_perd_strt_dt,
7028              p_enrt_cvg_strt_dt_rl    => l_rec_enrt_cvg_strt_dt_rl,
7029              p_roll_crs_flag          => 'N',
7030              p_ctfn_rqd_flag          => NVL(l_ctfn_rqd_flag,'N'),
7031              p_crntly_enrd_flag       => NVL(l_rec_crntly_enrd_flag,'N'),
7032              p_dflt_flag              => NVL(l_dflt_flag,'N'),
7033              p_elctbl_flag            => NVL(l_rec_elctbl_flag,'N'),
7034              p_mndtry_flag            => NVL(l_rec_mndtry_flag,'N'),
7035              p_dflt_enrt_dt           => l_rec_dflt_asnmt_dt,
7036              p_dpnt_cvg_strt_dt_cd    => NULL,
7037              p_dpnt_cvg_strt_dt_rl    => NULL,
7038              p_enrt_cvg_strt_dt       => l_rec_enrt_cvg_strt_dt,
7039              p_alws_dpnt_dsgn_flag    => 'N',
7040              p_erlst_deenrt_dt        => l_rec_erlst_deenrt_dt,
7041              p_procg_end_dt           => l_rec_procg_end_dt,
7042              p_pl_ordr_num            => l_plan_rec.ordr_num,
7043              p_plip_ordr_num          => l_plip_ordr_num,
7044              p_ptip_ordr_num          => l_ptip_ordr_num,
7045              p_oipl_ordr_num          => l_oipl_rec.ordr_num,
7046              --p_object_version_number  => l_object_version_number,
7047              p_effective_date         => p_effective_date,
7048              p_enrt_perd_id           => l_rec_enrt_perd_id,
7049              p_lee_rsn_id             => l_rec_lee_rsn_id,
7050              p_cls_enrt_dt_to_use_cd  => l_rec_cls_enrt_dt_to_use_cd,
7051              p_uom                    => l_rec_uom,
7052              p_acty_ref_perd_cd       => l_rec_acty_ref_perd_cd,
7053              p_cryfwd_elig_dpnt_cd    => l_reinstt_cd,
7054              p_ws_mgr_id              => l_ws_mgr_id,
7055              p_elig_flag              => NVL(l_elig_flag,'Y'),
7056              p_assignment_id          => l_assignment_id ,
7057              p_fonm_cvg_strt_dt       => l_fonm_cvg_strt_dt,
7058              p_inelig_rsn_cd	  => l_inelg_rsn_cd);
7059              --
7060              l_elig_per_elctbl_chc_id := l_epe_exists;
7061           end if;
7062          --
7063        end if;
7064        if l_epe_exists is null then
7065          ben_elig_per_elc_chc_api.create_perf_elig_per_elc_chc(
7066          p_elig_per_elctbl_chc_id => l_elig_per_elctbl_chc_id,
7067          p_business_group_id      => p_business_group_id,
7068          p_auto_enrt_flag         => NVL(l_rec_auto_enrt_flag,'N'),
7069          p_per_in_ler_id          => l_per_in_ler_id,
7070          p_yr_perd_id             => l_yr_perd_id,
7071          p_pl_id                  => l_pl_id,
7072          p_pl_typ_id              => l_pl_typ_id,
7073          p_oipl_id                => p_oipl_id,
7074          p_pgm_id                 => p_pgm_id,
7075          p_pgm_typ_cd             => l_pgm_rec.pgm_typ_cd,
7076          p_must_enrl_anthr_pl_id  => l_must_enrl_anthr_pl_id,
7077          p_plip_id                => l_plip_id,
7078          p_ptip_id                => l_ptip_id,
7079          p_prtt_enrt_rslt_id      => l_prtt_enrt_rslt_id,
7080          p_enrt_typ_cycl_cd       => l_rec_enrt_typ_cycl_cd,
7081          p_comp_lvl_cd            => l_comp_lvl_cd,
7082          p_enrt_cvg_strt_dt_cd    => l_rec_enrt_cvg_strt_dt_cd,
7083          p_enrt_perd_end_dt       => l_rec_enrt_perd_end_dt,
7084          p_enrt_perd_strt_dt      => l_rec_enrt_perd_strt_dt,
7085          p_enrt_cvg_strt_dt_rl    => l_rec_enrt_cvg_strt_dt_rl,
7086          p_roll_crs_flag          => 'N',
7087          p_ctfn_rqd_flag          => NVL(l_ctfn_rqd_flag,'N'),
7088          p_crntly_enrd_flag       => NVL(l_rec_crntly_enrd_flag,'N'),
7089          p_dflt_flag              => NVL(l_dflt_flag,'N'),
7090          p_elctbl_flag            => NVL(l_rec_elctbl_flag,'N'),
7091          p_mndtry_flag            => NVL(l_rec_mndtry_flag,'N'),
7092          p_dflt_enrt_dt           => l_rec_dflt_asnmt_dt,
7093          p_dpnt_cvg_strt_dt_cd    => NULL,
7094          p_dpnt_cvg_strt_dt_rl    => NULL,
7095          p_enrt_cvg_strt_dt       => l_rec_enrt_cvg_strt_dt,
7096          p_alws_dpnt_dsgn_flag    => 'N',
7097          p_erlst_deenrt_dt        => l_rec_erlst_deenrt_dt,
7098          p_procg_end_dt           => l_rec_procg_end_dt,
7099          p_pl_ordr_num            => l_plan_rec.ordr_num,
7100          p_plip_ordr_num          => l_plip_ordr_num,
7101          p_ptip_ordr_num          => l_ptip_ordr_num,
7102          p_oipl_ordr_num          => l_oipl_rec.ordr_num,
7103          p_object_version_number  => l_object_version_number,
7104          p_effective_date         => p_effective_date,
7105          p_program_application_id => fnd_global.prog_appl_id,
7106          p_program_id             => fnd_global.conc_program_id,
7107          p_request_id             => fnd_global.conc_request_id,
7108          p_program_update_date    => SYSDATE,
7109          p_enrt_perd_id           => l_rec_enrt_perd_id,
7110          p_lee_rsn_id             => l_rec_lee_rsn_id,
7111          p_cls_enrt_dt_to_use_cd  => l_rec_cls_enrt_dt_to_use_cd,
7112          p_uom                    => l_rec_uom,
7113          p_acty_ref_perd_cd       => l_rec_acty_ref_perd_cd,
7114          p_cryfwd_elig_dpnt_cd    => l_reinstt_cd,
7115          -- added for cwb
7116          p_ws_mgr_id              => l_ws_mgr_id,
7117          p_elig_flag              => NVL(l_elig_flag,'Y'),
7118          p_assignment_id          => l_assignment_id ,
7119          p_fonm_cvg_strt_dt       => l_fonm_cvg_strt_dt,
7120          p_inelig_rsn_cd	  => l_inelg_rsn_cd); -- 2650247
7121 
7122       if g_debug then
7123          hr_utility.set_location('Done EPEC_CRE: ' || l_proc, 10);
7124       end if;
7125        end if;
7126     --
7127     -- As part GLOBALCWB populating data into heirachy table
7128     -- is moved to per in ler table
7129     --
7130 /*
7131        --
7132        -- CWBITEM : Code moved to beepeapi.pkb
7133        --
7134     if p_run_mode = 'W' and l_elig_per_elctbl_chc_id is not null then
7135 
7136        --
7137        -- Populate the heirarchy table.
7138        --
7139        --
7140        open c_hrchy(l_elig_per_elctbl_chc_id);
7141        fetch c_hrchy into l_emp_pel_id, l_pel_id;
7142        --
7143        if l_pel_id is not null and l_emp_pel_id is null then
7144           --
7145           insert into ben_cwb_hrchy (
7146              emp_pil_elctbl_chc_popl_id,
7147              mgr_pil_elctbl_chc_popl_id,
7148              lvl_num  )
7149           values(
7150              l_pel_id,
7151              -1,
7152              -1);
7153           --
7154        end if;
7155        --
7156        close c_hrchy;
7157        --
7158     end if;
7159 */
7160     --
7161     p_elig_per_elctbl_chc_id :=   l_elig_per_elctbl_chc_id;
7162     --
7163     g_rec.person_id :=            p_person_id;
7164     g_rec.pgm_id :=               p_pgm_id;
7165     g_rec.pl_id :=                p_pl_id;
7166     g_rec.oipl_id :=              p_oipl_id;
7167     g_rec.enrt_cvg_strt_dt :=     l_rec_enrt_cvg_strt_dt;
7168     g_rec.enrt_perd_strt_dt :=    l_rec_enrt_perd_strt_dt;
7169     g_rec.enrt_perd_end_dt :=     l_rec_enrt_perd_end_dt;
7170     g_rec.erlst_deenrt_dt :=      l_rec_erlst_deenrt_dt;
7171     g_rec.dflt_enrt_dt :=         l_rec_dflt_asnmt_dt;
7172     g_rec.enrt_typ_cycl_cd :=     l_rec_enrt_typ_cycl_cd;
7173     g_rec.comp_lvl_cd :=          l_comp_lvl_cd;
7174     g_rec.mndtry_flag :=          l_rec_mndtry_flag;
7175     g_rec.dflt_flag :=            l_dflt_flag;
7176     g_rec.business_group_id :=    p_business_group_id;
7177     g_rec.effective_date :=       p_effective_date;
7178     --
7179     benutils.write(p_rec => g_rec);
7180     if g_debug then
7181     hr_utility.set_location('FND mess: ' || l_proc, 10);
7182     end if;
7183     --
7184     fnd_message.set_name('BEN', 'BEN_91736_EPE_CHC_CREATED');
7185     fnd_message.set_token('PERSON_ID', p_person_id);
7186     fnd_message.set_token('LER_NAME', l_ler_name);
7187     fnd_message.set_token('COMP_LVL_CD', l_comp_lvl_cd);
7188     fnd_message.set_token('PLAN_NAME', l_pl_name);
7189     fnd_message.set_token('OIPL_NAME', l_oipl_name);
7190     --
7191     if g_debug then
7192     hr_utility.set_location('Dn FND mess: ' || l_proc, 10);
7193     end if;
7194     benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
7195     --
7196     -- if choice is created for an oipl create one for plan it belongs to
7197     -- first find out if it already exists.
7198     --
7199     if g_debug then
7200     hr_utility.set_location('(p_oipl_id NN): ' || l_proc, 10);
7201     end if;
7202     IF (p_oipl_id IS NOT NULL) THEN
7203       --
7204       OPEN c_choice_exists_for_plan(l_pl_id);
7205       --
7206       FETCH c_choice_exists_for_plan INTO l_choice_exists_flag;
7207       --
7208       IF c_choice_exists_for_plan%NOTFOUND  or p_run_mode not in ('U','R') THEN
7209         --
7210         OPEN c_current_elig_for_plan;
7211         --
7212         FETCH c_current_elig_for_plan INTO l_elig_per_id,
7213                                            l_current_eligibility,
7214                                            l_must_enrl_anthr_pl_id,
7215                                            l_prtn_strt_dt,
7216                                            l_inelg_rsn_cd; -- 2650247
7217         --
7218         IF c_current_elig_for_plan%NOTFOUND THEN
7219           --
7220           l_current_eligibility :=  'N';
7221         --
7222         END IF;
7223         --
7224         CLOSE c_current_elig_for_plan;
7225       --
7226       END IF;
7227       --
7228       if g_debug then
7229       hr_utility.set_location('CREL=Y ' || l_proc, 10);
7230       end if;
7231       -- IF    ( c_choice_exists_for_plan%NOTFOUND or p_run_mode not in ('U','R')) /* Bug 4023880 : Commented */
7232       IF    ( c_choice_exists_for_plan%NOTFOUND  or l_plan_rec.svgs_pl_flag = 'Y') -- Bug 4717052 added or
7233          AND l_current_eligibility = 'Y' THEN
7234         --
7235 --  if the plan is savings , as it is electable even if the plan is having options, check for any previous
7236 --  enrollment
7237         --
7238         if l_plan_rec.svgs_pl_flag = 'Y' then
7239 	   --
7240 	   --8399189
7241            OPEN c_plan_enrolment_info(l_lf_evt_ocrd_dt_1,p_run_mode);
7242 
7243            --
7244            FETCH c_plan_enrolment_info INTO l_crnt_enrt_cvg_strt_dt,
7245                                        l_crnt_erlst_deenrt_dt,
7246                                        l_prtt_enrt_rslt_id,
7247                                        l_enrt_ovridn_flag,
7248                                        l_enrt_ovrid_thru_dt,
7249                                        l_orgnl_enrt_dt,
7250                                        l_crnt_enrt_cvg_thru_dt,    --BUG 6519487 fix
7251                                        l_current_pl_typ_id ;   --BUG 6519487 fix
7252           if c_plan_enrolment_info%found then
7253              l_prtt_enrt_rslt_id_2 := l_prtt_enrt_rslt_id;
7254           end if;
7255           --
7256           CLOSE c_plan_enrolment_info;
7257           --
7258         end if;
7259         --
7260         l_epe_exists := null;
7261         if p_run_mode in ('U','R') then
7262 	if g_debug then
7263           hr_utility.set_location('before epe exists',11);
7264         end if;
7265          --
7266          l_epe_exists :=  ben_manage_unres_life_events.epe_exists
7267                   (p_per_in_ler_id => l_per_in_ler_id,
7268                    p_pgm_id => p_pgm_id,
7269                    p_pl_id  => l_pl_id,
7270                    p_oipl_id =>-1);
7271          if l_epe_exists is not null or (l_plan_rec.svgs_pl_flag = 'Y' and -- Bug 4717052 added or
7272                                           (--l_prtt_enrt_rslt_id_2 is not null or - bug 5035423
7273                                           c_choice_exists_for_plan%FOUND) )
7274           then
7275          --
7276          -- Bug 4717052, epe_exists will get from the global plsql table g_unrest_epe_instance
7277          -- which was populated during reuse of PIL,
7278          -- If its the new PIL, epe_exists will b null, but if exists in the DB,
7279          -- then just update it.
7280          -- for savings plan: PLAN epe shd be updated with pen_id
7281          --
7282             ben_manage_unres_life_events.update_elig_per_elctbl_choice
7283             (p_elig_per_elctbl_chc_id => nvl(l_epe_exists,l_choice_exists_flag),
7284              p_business_group_id      => p_business_group_id,
7285              p_auto_enrt_flag         => 'N',
7286              p_per_in_ler_id          => l_per_in_ler_id,
7287              p_yr_perd_id             => l_yr_perd_id,
7288              p_pl_id                  => l_pl_id,
7289              p_pl_typ_id              => l_pl_typ_id,
7290              p_oipl_id                => NULL,               -- this is the kicker
7291              p_pgm_id                 => p_pgm_id,
7292              p_pgm_typ_cd             => l_pgm_rec.pgm_typ_cd,
7293              p_must_enrl_anthr_pl_id  => NULL,
7294              p_plip_id                => l_plip_id,
7295              p_ptip_id                => l_ptip_id,
7296              p_prtt_enrt_rslt_id      => l_prtt_enrt_rslt_id_2,  -- NULL was before
7297              p_comp_lvl_cd            => 'PLAN',
7298              p_enrt_cvg_strt_dt_cd    => l_rec_enrt_cvg_strt_dt_cd,
7299              p_enrt_perd_end_dt       => l_rec_enrt_perd_end_dt,
7300              p_enrt_perd_strt_dt      => l_rec_enrt_perd_strt_dt,
7301              p_enrt_cvg_strt_dt_rl    => l_rec_enrt_cvg_strt_dt_rl,
7302              p_roll_crs_flag          => 'N',
7303              p_ctfn_rqd_flag          => NVL(l_ctfn_rqd_flag,'N'),
7304              p_crntly_enrd_flag       => 'N',
7305              p_dflt_flag              => 'N',
7306              p_elctbl_flag            => 'N',
7307              p_mndtry_flag            => NVL(l_rec_mndtry_flag,'N'),
7308              p_dflt_enrt_dt           => NULL,
7309              p_dpnt_cvg_strt_dt_cd    => NULL,
7310              p_dpnt_cvg_strt_dt_rl    => NULL,
7311              p_enrt_cvg_strt_dt       => l_rec_enrt_cvg_strt_dt,
7312              p_alws_dpnt_dsgn_flag    => 'N',
7313              p_erlst_deenrt_dt        => l_rec_erlst_deenrt_dt,
7314              p_procg_end_dt           => l_rec_procg_end_dt,
7315              p_pl_ordr_num            => l_plan_rec.ordr_num,
7316              p_plip_ordr_num          => l_plip_ordr_num,
7317              p_ptip_ordr_num          => l_ptip_ordr_num,
7318              p_oipl_ordr_num          => l_oipl_rec.ordr_num,
7319              p_effective_date         => p_effective_date,
7320              p_enrt_perd_id           => l_rec_enrt_perd_id,
7321              p_lee_rsn_id             => l_rec_lee_rsn_id,
7322              p_cls_enrt_dt_to_use_cd  => l_rec_cls_enrt_dt_to_use_cd,
7323              p_uom                    => l_rec_uom,
7324              p_acty_ref_perd_cd       => l_rec_acty_ref_perd_cd,
7325              p_cryfwd_elig_dpnt_cd    => l_reinstt_cd,
7326              p_fonm_cvg_strt_dt       => l_fonm_cvg_strt_dt,
7327              p_inelig_rsn_cd          => l_inelg_rsn_cd);
7328              --
7329              l_elig_per_elctbl_chc_id := nvl(l_epe_exists,l_choice_exists_flag);
7330           end if;
7331           --
7332         end if;
7333         --
7334         if l_epe_exists is null and c_choice_exists_for_plan%NOTFOUND then
7335             -- Bug4717052, added choices_exists_for_plan not found
7336              ben_elig_per_elc_chc_api.create_perf_elig_per_elc_chc(
7337              p_elig_per_elctbl_chc_id => l_elig_per_elctbl_chc_id,
7338              p_business_group_id      => p_business_group_id,
7339              p_auto_enrt_flag         => 'N',
7340              p_per_in_ler_id          => l_per_in_ler_id,
7341              p_yr_perd_id             => l_yr_perd_id,
7342              p_pl_id                  => l_pl_id,
7343              p_pl_typ_id              => l_pl_typ_id,
7344              p_oipl_id                => NULL,               -- this is the kicker
7345              p_pgm_id                 => p_pgm_id,
7346              p_pgm_typ_cd             => l_pgm_rec.pgm_typ_cd,
7347              p_must_enrl_anthr_pl_id  => NULL,
7348              p_plip_id                => l_plip_id,
7349              p_ptip_id                => l_ptip_id,
7350              p_prtt_enrt_rslt_id      => l_prtt_enrt_rslt_id_2,  -- NULL was before
7351              p_enrt_typ_cycl_cd       => l_rec_enrt_typ_cycl_cd,
7352              p_comp_lvl_cd            => 'PLAN',
7353              p_enrt_cvg_strt_dt_cd    => l_rec_enrt_cvg_strt_dt_cd,
7354              p_enrt_perd_end_dt       => l_rec_enrt_perd_end_dt,
7355              p_enrt_perd_strt_dt      => l_rec_enrt_perd_strt_dt,
7356              p_enrt_cvg_strt_dt_rl    => l_rec_enrt_cvg_strt_dt_rl,
7357              p_roll_crs_flag          => 'N',
7358              p_ctfn_rqd_flag          => NVL(l_ctfn_rqd_flag,'N'),
7359              p_crntly_enrd_flag       => 'N',
7360              p_dflt_flag              => 'N',
7361              p_elctbl_flag            => 'N',
7362              p_mndtry_flag            => NVL(l_rec_mndtry_flag,'N'),
7363              p_dflt_enrt_dt           => NULL,
7364              p_dpnt_cvg_strt_dt_cd    => NULL,
7365              p_dpnt_cvg_strt_dt_rl    => NULL,
7366              p_enrt_cvg_strt_dt       => l_rec_enrt_cvg_strt_dt,
7367              p_alws_dpnt_dsgn_flag    => 'N',
7368              p_erlst_deenrt_dt        => l_rec_erlst_deenrt_dt,
7369              p_procg_end_dt           => l_rec_procg_end_dt,
7370              p_pl_ordr_num            => l_plan_rec.ordr_num,
7371              p_plip_ordr_num          => l_plip_ordr_num,
7372              p_ptip_ordr_num          => l_ptip_ordr_num,
7373              p_oipl_ordr_num          => l_oipl_rec.ordr_num,
7374              p_object_version_number  => l_object_version_number,
7375              p_effective_date         => p_effective_date,
7376              p_program_application_id => fnd_global.prog_appl_id,
7377              p_program_id             => fnd_global.conc_program_id,
7378              p_request_id             => fnd_global.conc_request_id,
7379              p_program_update_date    => SYSDATE,
7380              p_enrt_perd_id           => l_rec_enrt_perd_id,
7381              p_lee_rsn_id             => l_rec_lee_rsn_id,
7382              p_cls_enrt_dt_to_use_cd  => l_rec_cls_enrt_dt_to_use_cd,
7383              p_uom                    => l_rec_uom,
7384              p_acty_ref_perd_cd       => l_rec_acty_ref_perd_cd,
7385              p_cryfwd_elig_dpnt_cd    => l_reinstt_cd,
7386              p_fonm_cvg_strt_dt       => l_fonm_cvg_strt_dt,
7387              p_inelig_rsn_cd	   => l_inelg_rsn_cd); -- 2650247
7388 	     if g_debug then
7389              hr_utility.set_location('Done EPEC_CRE1: ' || l_proc, 10);
7390 	     end if;
7391              --
7392         end if;
7393         --
7394         g_rec.person_id :=          p_person_id;
7395         g_rec.pgm_id :=             p_pgm_id;
7396         g_rec.pl_id :=              l_pl_id;
7397         g_rec.oipl_id :=            NULL;
7398         g_rec.enrt_cvg_strt_dt :=   l_rec_enrt_cvg_strt_dt;
7399         g_rec.enrt_perd_strt_dt :=  l_rec_enrt_perd_strt_dt;
7400         g_rec.enrt_perd_end_dt :=   l_rec_enrt_perd_end_dt;
7401         g_rec.erlst_deenrt_dt :=    l_rec_erlst_deenrt_dt;
7402         g_rec.dflt_enrt_dt :=       NULL;
7403         g_rec.enrt_typ_cycl_cd :=   l_rec_enrt_typ_cycl_cd;
7404         g_rec.comp_lvl_cd :=        'PLAN';
7405         g_rec.mndtry_flag :=        l_rec_mndtry_flag;
7406         g_rec.dflt_flag :=          'N';
7407         g_rec.business_group_id :=  p_business_group_id;
7408         g_rec.effective_date :=     p_effective_date;
7409         --
7410         benutils.write(p_rec => g_rec);
7411         --
7412 	if g_debug then
7413         hr_utility.set_location('FND Mess: ' || l_proc, 10);
7414 	end if;
7415         fnd_message.set_name('BEN', 'BEN_91736_EPE_CHC_CREATED');
7416         fnd_message.set_token('PERSON_ID', p_person_id);
7417         fnd_message.set_token('LER_NAME', l_ler_name);
7418         fnd_message.set_token('COMP_LVL_CD', l_comp_lvl_cd);
7419         fnd_message.set_token('PLAN_NAME', l_pl_name);
7420         fnd_message.set_token('OIPL_NAME', ' ');
7421 	if g_debug then
7422         hr_utility.set_location('Dn FND Mess: ' || l_proc, 10);
7423 	end if;
7424         benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
7425 	if g_debug then
7426         hr_utility.set_location('Dn FND GetMess: ' || l_proc, 10);
7427 	end if;
7428       --
7429       END IF;                                                          -- found
7430       --
7431       CLOSE c_choice_exists_for_plan;
7432       if g_debug then
7433       hr_utility.set_location('close CEFP: ' || l_proc, 10);
7434       end if;
7435     --
7436     END IF;
7437     --
7438     --
7439     -- Set return value
7440     p_electable_flag := l_rec_elctbl_flag;
7441     --
7442     if g_debug then
7443     hr_utility.set_location(' Leaving:' || l_proc, 70);
7444     end if;
7445   --
7446   exception  -- nocopy changes
7447     --
7448     when others then
7449       --
7450       p_electable_flag := null;
7451       p_elig_per_elctbl_chc_id := null;
7452       raise;
7453       --
7454   END enrolment_requirements;
7455 
7456  PROCEDURE execute_auto_dflt_enrt_rule(
7457     p_opt_id            NUMBER,
7458     p_pl_id             NUMBER,
7459     p_pgm_id            NUMBER,
7460     p_rule_id           NUMBER,
7461     p_ler_id            NUMBER,
7462     p_pl_typ_id         NUMBER,
7463     p_business_group_id NUMBER,
7464     p_effective_date    DATE,
7465     p_lf_evt_ocrd_dt    DATE DEFAULT NULL,
7466     p_elig_per_id       NUMBER DEFAULT NULL,
7467     p_assignment_id     NUMBER,
7468     p_organization_id   NUMBER,
7469     p_jurisdiction_code VARCHAR2,
7470     p_person_id         NUMBER,               -- Bug 5331889
7471     p_enrt_mthd         out nocopy varchar2,
7472     p_reinstt_dpnt      out nocopy varchar2
7473     ) IS
7474     --
7475     l_package       VARCHAR2(80)      := g_package || '.execute_auto_dflt_enrt_rule';
7476     l_outputs       ff_exec.outputs_t;
7477     --
7478     l_param1        VARCHAR2(30);
7479     l_param1_value  VARCHAR2(30);
7480     l_param2        VARCHAR2(30);
7481     l_param2_value  VARCHAR2(30);
7482     l_param3        VARCHAR2(30);
7483     l_param3_value  VARCHAR2(30);
7484     l_param4        VARCHAR2(30);
7485     l_param4_value  VARCHAR2(30);
7486     l_param5        VARCHAR2(30);
7487     l_param5_value  VARCHAR2(30);
7488     l_param6        VARCHAR2(30);
7489     l_param6_value  VARCHAR2(30);
7490     l_param7        VARCHAR2(30);
7491     l_param7_value  VARCHAR2(30);
7492     l_param8        VARCHAR2(30);
7493     l_param8_value  VARCHAR2(30);
7494     l_param9        VARCHAR2(30);
7495     l_param9_value  VARCHAR2(30);
7496     l_param10       VARCHAR2(30);
7497     l_param10_value VARCHAR2(30);
7498     l_param11       VARCHAR2(30);
7499     l_param11_value VARCHAR2(30);
7500     l_param12       VARCHAR2(30);
7501     l_param12_value VARCHAR2(30);
7502     l_param13       VARCHAR2(30);
7503     l_param13_value VARCHAR2(30);
7504     l_param14       VARCHAR2(30);
7505     l_param14_value VARCHAR2(30);
7506     l_param15       VARCHAR2(30);
7507     l_param15_value VARCHAR2(30);
7508     l_param16       VARCHAR2(30);
7509     l_param16_value VARCHAR2(30);
7510     l_param17       VARCHAR2(30);
7511     l_param17_value VARCHAR2(30);
7512     l_param18       VARCHAR2(30);
7513     l_param18_value VARCHAR2(30);
7514     l_param19       VARCHAR2(30);
7515     l_param19_value VARCHAR2(30);
7516     l_param20       VARCHAR2(30);
7517     l_param20_value VARCHAR2(30);
7518     l_num_elig_dpnt NUMBER;
7519     l_prev_prtt_enrt_rslt_id  VARCHAR2(30);
7520   --
7521   BEGIN
7522     --
7523     g_debug := hr_utility.debug_enabled;
7524     if g_debug then
7525     hr_utility.set_location('Entering ' || l_package, 10);
7526     end if;
7527     --
7528     IF p_rule_id IS NULL THEN
7529       --
7530       p_enrt_mthd := 'Y';
7531       p_reinstt_dpnt := 'CFWP';
7532     --
7533     END IF;
7534     --
7535     if g_debug then
7536     hr_utility.set_location(
7537       'Organization_id ' || TO_CHAR(p_organization_id),
7538       10);
7539     hr_utility.set_location('assignment_id ' || TO_CHAR(p_assignment_id), 15);
7540     hr_utility.set_location(
7541       'Business_group_id ' || TO_CHAR(p_business_group_id),
7542       20);
7543     hr_utility.set_location('pgm_id ' || TO_CHAR(p_pgm_id), 30);
7544     hr_utility.set_location('pl_id ' || TO_CHAR(p_pl_id), 40);
7545     hr_utility.set_location('pl_typ_id ' || TO_CHAR(p_pl_typ_id), 50);
7546     hr_utility.set_location('opt_id ' || TO_CHAR(p_opt_id), 60);
7547     hr_utility.set_location('ler_id ' || TO_CHAR(p_ler_id), 70);
7548     end if;
7549     --
7550     -- Task 131 :If elig dependent rows are already crteated then
7551     -- pass the elig dependent id as input values to
7552     -- rule.
7553     --
7554     l_num_elig_dpnt :=
7555                       NVL(ben_determine_dpnt_eligibility.g_egd_table.LAST, 0);
7556     --
7557     IF NVL(ben_determine_dpnt_eligibility.g_egd_table.LAST, 0) > 0 THEN
7558       FOR l_curr_count IN
7559         ben_determine_dpnt_eligibility.g_egd_table.FIRST .. ben_determine_dpnt_eligibility.g_egd_table.LAST LOOP
7560         --
7561         -- Currently we are passing only 20 input values.
7562         -- Only 20 elig_dpnt_id are passed as input values.
7563         --
7564         EXIT WHEN l_curr_count > 20;
7565         --
7566         -- Update the egd row with electable choice id.
7567         --
7568         IF l_curr_count = 1 THEN
7569           l_param1 :=        'ELIG_DPNT_ID1';
7570           l_param1_value :=
7571            TO_CHAR(
7572              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7573         ELSIF l_curr_count = 2 THEN
7574           l_param2 :=        'ELIG_DPNT_ID2';
7575           l_param2_value :=
7576            TO_CHAR(
7577              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7578         ELSIF l_curr_count = 3 THEN
7579           l_param3 :=        'ELIG_DPNT_ID3';
7580           l_param3_value :=
7581            TO_CHAR(
7582              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7583         ELSIF l_curr_count = 4 THEN
7584           l_param4 :=        'ELIG_DPNT_ID4';
7585           l_param4_value :=
7586            TO_CHAR(
7587              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7588         ELSIF l_curr_count = 5 THEN
7589            l_param5 :=        'ELIG_DPNT_ID5';
7590           l_param5_value :=
7591            TO_CHAR(
7592              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7593         ELSIF l_curr_count = 6 THEN
7594           l_param6 :=        'ELIG_DPNT_ID6';
7595           l_param6_value :=
7596            TO_CHAR(
7597              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7598         ELSIF l_curr_count = 7 THEN
7599           l_param7 :=        'ELIG_DPNT_ID7';
7600           l_param7_value :=
7601            TO_CHAR(
7602              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7603         ELSIF l_curr_count = 8 THEN
7604           l_param8 :=        'ELIG_DPNT_ID8';
7605           l_param8_value :=
7606            TO_CHAR(
7607              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7608         ELSIF l_curr_count = 9 THEN
7609           l_param9 :=        'ELIG_DPNT_ID9';
7610           l_param9_value :=
7611            TO_CHAR(
7612              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7613         ELSIF l_curr_count = 10 THEN
7614           l_param10 :=        'ELIG_DPNT_ID10';
7615           l_param10_value :=
7616             TO_CHAR(
7617              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7618         ELSIF l_curr_count = 11 THEN
7619           l_param11 :=        'ELIG_DPNT_ID11';
7620           l_param11_value :=
7621            TO_CHAR(
7622              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7623         ELSIF l_curr_count = 12 THEN
7624           l_param12 :=        'ELIG_DPNT_ID12';
7625           l_param12_value :=
7626            TO_CHAR(
7627              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7628         ELSIF l_curr_count = 13 THEN
7629           l_param13 :=        'ELIG_DPNT_ID13';
7630           l_param13_value :=
7631            TO_CHAR(
7632              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7633         ELSIF l_curr_count = 14 THEN
7634           l_param14 :=        'ELIG_DPNT_ID14';
7635           l_param14_value :=
7636            TO_CHAR(
7637              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7638         ELSIF l_curr_count = 15 THEN
7639           l_param15 :=        'ELIG_DPNT_ID15';
7640           l_param15_value :=
7641            TO_CHAR(
7642              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7643         ELSIF l_curr_count = 16 THEN
7644            l_param16 :=        'ELIG_DPNT_ID16';
7645           l_param16_value :=
7646            TO_CHAR(
7647              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7648         ELSIF l_curr_count = 17 THEN
7649           l_param17 :=        'ELIG_DPNT_ID17';
7650           l_param17_value :=
7651            TO_CHAR(
7652              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7653         ELSIF l_curr_count = 18 THEN
7654           l_param18 :=        'ELIG_DPNT_ID18';
7655           l_param18_value :=
7656            TO_CHAR(
7657              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7658         ELSIF l_curr_count = 19 THEN
7659           l_param19 :=        'ELIG_DPNT_ID19';
7660           l_param19_value :=
7661            TO_CHAR(
7662              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7663         ELSIF l_curr_count = 20 THEN
7664           l_param20 :=        'ELIG_DPNT_ID20';
7665           l_param20_value :=
7666            TO_CHAR(
7667              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7668         END IF;
7669       --
7670       END LOOP;
7671     --
7672     END IF;
7673     --
7674     if g_debug then
7675     hr_utility.set_location(' Fire Rule ' || l_package, 10);
7676     end if;
7677     l_outputs :=
7678      benutils.formula(
7679        p_opt_id            => p_opt_id,
7680        p_pl_id             => p_pl_id,
7681        p_pgm_id            => p_pgm_id,
7682        p_formula_id        => p_rule_id,
7683        p_ler_id            => p_ler_id,
7684        p_elig_per_id       => p_elig_per_id,
7685        p_pl_typ_id         => p_pl_typ_id,
7686        p_assignment_id     => p_assignment_id,
7687        p_business_group_id => p_business_group_id,
7688        p_organization_id   => p_organization_id,
7689        p_jurisdiction_code => p_jurisdiction_code,
7690        p_effective_date    => NVL(p_lf_evt_ocrd_dt, p_effective_date),
7691        p_param1            => l_param1,
7692        p_param1_value      => l_param1_value,
7693        p_param2            => l_param2,
7694        p_param2_value      => l_param2_value,
7695        p_param3            => l_param3,
7696        p_param3_value      => l_param3_value,
7697        p_param4            => l_param4,
7698        p_param4_value      => l_param4_value,
7699        p_param5            => l_param5,
7700        p_param5_value      => l_param5_value,
7701        p_param6            => l_param6,
7702        p_param6_value      => l_param6_value,
7703        p_param7            => l_param7,
7704        p_param7_value      => l_param7_value,
7705        p_param8            => l_param8,
7706        p_param8_value      => l_param8_value,
7707        p_param9            => l_param9,
7708        p_param9_value      => l_param9_value,
7709        p_param10           => l_param10,
7710        p_param10_value     => l_param10_value,
7711        p_param11           => l_param11,
7712        p_param11_value     => l_param11_value,
7713        p_param12           => l_param12,
7714        p_param12_value     => l_param12_value,
7715        p_param13           => l_param13,
7716        p_param13_value     => l_param13_value,
7717        p_param14           => l_param14,
7718        p_param14_value     => l_param14_value,
7719        p_param15           => l_param15,
7720        p_param15_value     => l_param15_value,
7721        p_param16           => l_param16,
7722        p_param16_value     => l_param16_value,
7723        p_param17           => l_param17,
7724        p_param17_value     => l_param17_value,
7725        p_param18           => l_param18,
7726        p_param18_value     => l_param18_value,
7727        p_param19           => l_param19,
7728        p_param19_value     => l_param19_value,
7729        p_param20           => l_param20,
7730        p_param20_value     => l_param20_value,
7731        p_param21           => 'NUM_ELIG_DPNT',
7732        p_param21_value     => TO_CHAR(l_num_elig_dpnt),
7733        p_param22           => 'BEN_IV_PERSON_ID',            -- Bug 5331889 : Added person_id param as well
7734        p_param22_value     => to_char(p_person_id));
7735   if g_debug then
7736     hr_utility.set_location(' Dn Fire Rule ' || l_package, 10);
7737   end if;
7738     --
7739   for l_count in l_outputs.first..l_outputs.last loop
7740    begin
7741         --
7742         if l_outputs(l_count).name = 'AUTO_DFLT_VAL' then
7743            p_enrt_mthd := l_outputs(l_count).VALUE;
7744         elsif l_outputs(l_count).name = 'CARRY_FORWARD_ELIG_DPNT' then
7745            p_reinstt_dpnt := l_outputs(l_count).VALUE;
7746         elsif l_outputs(l_count).name = 'AUTO_DFLT_ELCN_VAL' then
7747            g_dflt_elcn_val := l_outputs(l_count).VALUE;
7748 	   if g_debug then
7749            hr_utility.set_location ('formula default='||g_dflt_elcn_val,744);
7750            hr_utility.set_location ('formula default='||p_opt_id,744);
7751            end if;
7752         elsif l_outputs(l_count).name =  'PREV_PRTT_ENRT_RSLT_ID' then
7753            l_prev_prtt_enrt_rslt_id   := l_outputs(l_count).VALUE ;
7754 	   if g_debug then
7755            hr_utility.set_location ('formula PREV_PRTT_ENRT_RSLT_ID ='||l_prev_prtt_enrt_rslt_id,744);
7756 	   end if;
7757 
7758         end if;
7759     end;
7760    end loop;
7761    --- if the formula return the result id , concate the result with p_reinstt_dpnt  # 2685018
7762    if l_prev_prtt_enrt_rslt_id is not null then
7763       p_reinstt_dpnt := nvl(p_reinstt_dpnt,'') ||'^'||l_prev_prtt_enrt_rslt_id ;
7764    end if ;
7765 
7766   --
7767   if g_debug then
7768     hr_utility.set_location(' Leaving ' || l_package, 10);
7769   end if;
7770 
7771   exception  -- nocopy changes
7772     --
7773     when others then
7774       --
7775       p_enrt_mthd := null;
7776       p_reinstt_dpnt := null;
7777       raise;
7778       --
7779   END execute_auto_dflt_enrt_rule;
7780 
7781   FUNCTION execute_enrt_rule(
7782     p_opt_id            NUMBER,
7783     p_pl_id             NUMBER,
7784     p_pgm_id            NUMBER,
7785     p_rule_id           NUMBER,
7786     p_ler_id            NUMBER,
7787     p_pl_typ_id         NUMBER,
7788     p_business_group_id NUMBER,
7789     p_effective_date    DATE,
7790     p_lf_evt_ocrd_dt    DATE DEFAULT NULL,
7791     p_elig_per_id       NUMBER DEFAULT NULL,
7792     p_assignment_id     NUMBER,
7793     p_organization_id   NUMBER,
7794     p_jurisdiction_code VARCHAR2,
7795     p_person_id         NUMBER)         -- Bug 5331889
7796     RETURN VARCHAR2 IS
7797     --
7798     l_package       VARCHAR2(80)      := g_package || '.execute_enrt_rule';
7799     l_outputs       ff_exec.outputs_t;
7800     --
7801     l_param1        VARCHAR2(30);
7802     l_param1_value  VARCHAR2(30);
7803     l_param2        VARCHAR2(30);
7804     l_param2_value  VARCHAR2(30);
7805     l_param3        VARCHAR2(30);
7806     l_param3_value  VARCHAR2(30);
7807     l_param4        VARCHAR2(30);
7808     l_param4_value  VARCHAR2(30);
7809     l_param5        VARCHAR2(30);
7810     l_param5_value  VARCHAR2(30);
7811     l_param6        VARCHAR2(30);
7812     l_param6_value  VARCHAR2(30);
7813     l_param7        VARCHAR2(30);
7814     l_param7_value  VARCHAR2(30);
7815     l_param8        VARCHAR2(30);
7816     l_param8_value  VARCHAR2(30);
7817     l_param9        VARCHAR2(30);
7818     l_param9_value  VARCHAR2(30);
7819     l_param10       VARCHAR2(30);
7820     l_param10_value VARCHAR2(30);
7821     l_param11       VARCHAR2(30);
7822     l_param11_value VARCHAR2(30);
7823     l_param12       VARCHAR2(30);
7824     l_param12_value VARCHAR2(30);
7825     l_param13       VARCHAR2(30);
7826     l_param13_value VARCHAR2(30);
7827     l_param14       VARCHAR2(30);
7828     l_param14_value VARCHAR2(30);
7829     l_param15       VARCHAR2(30);
7830     l_param15_value VARCHAR2(30);
7831     l_param16       VARCHAR2(30);
7832     l_param16_value VARCHAR2(30);
7833     l_param17       VARCHAR2(30);
7834     l_param17_value VARCHAR2(30);
7835     l_param18       VARCHAR2(30);
7836     l_param18_value VARCHAR2(30);
7837     l_param19       VARCHAR2(30);
7838     l_param19_value VARCHAR2(30);
7839     l_param20       VARCHAR2(30);
7840     l_param20_value VARCHAR2(30);
7841     l_num_elig_dpnt NUMBER;
7842   --
7843   BEGIN
7844     --
7845    if g_debug then
7846     hr_utility.set_location('Entering ' || l_package, 10);
7847    end if;
7848     --
7849     IF p_rule_id IS NULL THEN
7850       --
7851       RETURN 'Y';
7852     --
7853     END IF;
7854     --
7855     if g_debug then
7856     hr_utility.set_location(
7857       'Organization_id ' || TO_CHAR(p_organization_id),
7858       10);
7859     hr_utility.set_location('assignment_id ' || TO_CHAR(p_assignment_id), 15);
7860     hr_utility.set_location(
7861       'Business_group_id ' || TO_CHAR(p_business_group_id),
7862       20);
7863     hr_utility.set_location('pgm_id ' || TO_CHAR(p_pgm_id), 30);
7864     hr_utility.set_location('pl_id ' || TO_CHAR(p_pl_id), 40);
7865     hr_utility.set_location('pl_typ_id ' || TO_CHAR(p_pl_typ_id), 50);
7866     hr_utility.set_location('opt_id ' || TO_CHAR(p_opt_id), 60);
7867     hr_utility.set_location('ler_id ' || TO_CHAR(p_ler_id), 70);
7868     end if;
7869     --
7870     -- Task 131 :If elig dependent rows are already crteated then
7871     -- pass the elig dependent id as input values to
7872     -- rule.
7873     --
7874     l_num_elig_dpnt :=
7875                       NVL(ben_determine_dpnt_eligibility.g_egd_table.LAST, 0);
7876     --
7877     IF NVL(ben_determine_dpnt_eligibility.g_egd_table.LAST, 0) > 0 THEN
7878       FOR l_curr_count IN
7879          ben_determine_dpnt_eligibility.g_egd_table.FIRST .. ben_determine_dpnt_eligibility.g_egd_table.LAST LOOP
7880         --
7881         -- Currently we are passing only 20 input values.
7882         -- Only 20 elig_dpnt_id are passed as input values.
7883         --
7884         EXIT WHEN l_curr_count > 20;
7885         --
7886         -- Update the egd row with electable choice id.
7887         --
7888         IF l_curr_count = 1 THEN
7889           l_param1 :=        'ELIG_DPNT_ID1';
7890           l_param1_value :=
7891            TO_CHAR(
7892              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7893         ELSIF l_curr_count = 2 THEN
7894           l_param2 :=        'ELIG_DPNT_ID2';
7895           l_param2_value :=
7896            TO_CHAR(
7897              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7898         ELSIF l_curr_count = 3 THEN
7899           l_param3 :=        'ELIG_DPNT_ID3';
7900           l_param3_value :=
7901            TO_CHAR(
7902              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7903         ELSIF l_curr_count = 4 THEN
7904           l_param4 :=        'ELIG_DPNT_ID4';
7905           l_param4_value :=
7906            TO_CHAR(
7907              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7908         ELSIF l_curr_count = 5 THEN
7909           l_param5 :=        'ELIG_DPNT_ID5';
7910           l_param5_value :=
7911            TO_CHAR(
7912              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7913         ELSIF l_curr_count = 6 THEN
7914           l_param6 :=        'ELIG_DPNT_ID6';
7915           l_param6_value :=
7916            TO_CHAR(
7917              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7918         ELSIF l_curr_count = 7 THEN
7919           l_param7 :=        'ELIG_DPNT_ID7';
7920           l_param7_value :=
7921            TO_CHAR(
7922              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7923         ELSIF l_curr_count = 8 THEN
7924           l_param8 :=        'ELIG_DPNT_ID8';
7925           l_param8_value :=
7926            TO_CHAR(
7927              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7928         ELSIF l_curr_count = 9 THEN
7929           l_param9 :=        'ELIG_DPNT_ID9';
7930           l_param9_value :=
7931            TO_CHAR(
7932              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7933         ELSIF l_curr_count = 10 THEN
7934           l_param10 :=        'ELIG_DPNT_ID10';
7935           l_param10_value :=
7936            TO_CHAR(
7937              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7938         ELSIF l_curr_count = 11 THEN
7939           l_param11 :=        'ELIG_DPNT_ID11';
7940           l_param11_value :=
7941            TO_CHAR(
7942              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7943         ELSIF l_curr_count = 12 THEN
7944           l_param12 :=        'ELIG_DPNT_ID12';
7945           l_param12_value :=
7946            TO_CHAR(
7947              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7948         ELSIF l_curr_count = 13 THEN
7949           l_param13 :=        'ELIG_DPNT_ID13';
7950           l_param13_value :=
7951            TO_CHAR(
7952              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7953         ELSIF l_curr_count = 14 THEN
7954           l_param14 :=        'ELIG_DPNT_ID14';
7955           l_param14_value :=
7956            TO_CHAR(
7957              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7958         ELSIF l_curr_count = 15 THEN
7959           l_param15 :=        'ELIG_DPNT_ID15';
7960           l_param15_value :=
7961            TO_CHAR(
7962              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7963         ELSIF l_curr_count = 16 THEN
7964           l_param16 :=        'ELIG_DPNT_ID16';
7965           l_param16_value :=
7966            TO_CHAR(
7967              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7968         ELSIF l_curr_count = 17 THEN
7969           l_param17 :=        'ELIG_DPNT_ID17';
7970           l_param17_value :=
7971            TO_CHAR(
7972              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7973         ELSIF l_curr_count = 18 THEN
7974           l_param18 :=        'ELIG_DPNT_ID18';
7975           l_param18_value :=
7976            TO_CHAR(
7977              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7978         ELSIF l_curr_count = 19 THEN
7979           l_param19 :=        'ELIG_DPNT_ID19';
7980           l_param19_value :=
7981            TO_CHAR(
7982              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7983         ELSIF l_curr_count = 20 THEN
7984           l_param20 :=        'ELIG_DPNT_ID20';
7985           l_param20_value :=
7986            TO_CHAR(
7987              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7988         END IF;
7989       --
7990       END LOOP;
7991     --
7992     END IF;
7993     --
7994     l_outputs :=
7995      benutils.formula(
7996        p_opt_id            => p_opt_id,
7997        p_pl_id             => p_pl_id,
7998        p_pgm_id            => p_pgm_id,
7999        p_formula_id        => p_rule_id,
8000        p_ler_id            => p_ler_id,
8001        p_elig_per_id       => p_elig_per_id,
8002        p_pl_typ_id         => p_pl_typ_id,
8003        p_assignment_id     => p_assignment_id,
8004        p_business_group_id => p_business_group_id,
8005        p_organization_id   => p_organization_id,
8006        p_jurisdiction_code => p_jurisdiction_code,
8007        p_effective_date    => NVL(p_lf_evt_ocrd_dt, p_effective_date),
8008        p_param1            => l_param1,
8009        p_param1_value      => l_param1_value,
8010        p_param2            => l_param2,
8011        p_param2_value      => l_param2_value,
8012        p_param3            => l_param3,
8013        p_param3_value      => l_param3_value,
8014        p_param4            => l_param4,
8015        p_param4_value      => l_param4_value,
8016        p_param5            => l_param5,
8017        p_param5_value      => l_param5_value,
8018        p_param6            => l_param6,
8019        p_param6_value      => l_param6_value,
8020        p_param7            => l_param7,
8021        p_param7_value      => l_param7_value,
8022        p_param8            => l_param8,
8023        p_param8_value      => l_param8_value,
8024        p_param9            => l_param9,
8025        p_param9_value      => l_param9_value,
8026        p_param10           => l_param10,
8027        p_param10_value     => l_param10_value,
8028        p_param11           => l_param11,
8029        p_param11_value     => l_param11_value,
8030        p_param12           => l_param12,
8031        p_param12_value     => l_param12_value,
8032        p_param13           => l_param13,
8033        p_param13_value     => l_param13_value,
8034        p_param14           => l_param14,
8035        p_param14_value     => l_param14_value,
8036        p_param15           => l_param15,
8037        p_param15_value     => l_param15_value,
8038        p_param16           => l_param16,
8039        p_param16_value     => l_param16_value,
8040        p_param17           => l_param17,
8041        p_param17_value     => l_param17_value,
8042        p_param18           => l_param18,
8043        p_param18_value     => l_param18_value,
8044        p_param19           => l_param19,
8045        p_param19_value     => l_param19_value,
8046        p_param20           => l_param20,
8047        p_param20_value     => l_param20_value,
8048        p_param21           => 'NUM_ELIG_DPNT',
8049        p_param21_value     => TO_CHAR(l_num_elig_dpnt),
8050        p_param22           => 'BEN_IV_PERSON_ID',            -- Bug 5331889 : Added person_id param as well
8051        p_param22_value     => to_char(p_person_id));
8052     --
8053     RETURN l_outputs(l_outputs.FIRST).VALUE;
8054   --
8055   END execute_enrt_rule;
8056 --
8057   PROCEDURE determine_dflt_flag(
8058     p_dflt_flag             VARCHAR2,
8059     p_dflt_enrt_cd          VARCHAR2,
8060     p_crnt_enrt_cvg_strt_dt DATE,
8061     -- above is no longer used
8062     p_previous_eligibility  VARCHAR2,
8063     p_dflt_enrt_rl          NUMBER,
8064     p_oipl_id               NUMBER,
8065     p_pl_id                 NUMBER,
8066     p_pgm_id                NUMBER,
8067     p_effective_date        DATE,
8068     p_lf_evt_ocrd_dt        DATE DEFAULT NULL,
8069     p_ler_id                NUMBER,
8070     p_opt_id                NUMBER,
8071     p_pl_typ_id             NUMBER,
8072     p_ptip_id               NUMBER,
8073     p_person_id             NUMBER,
8074     p_business_group_id     NUMBER,
8075     p_assignment_id         NUMBER,
8076     p_deflt_flag            out nocopy VARCHAR2,
8077     p_reinstt_flag          out nocopy VARCHAR2,
8078     -- added bug 5644451
8079     p_default_level         VARCHAR2 default null,
8080     p_run_mode              varchar2 default null, /* iRec : Added p_run_mode */
8081     p_elig_per_id           number default null)  --Bug 14768372
8082     IS
8083     --
8084     l_defer_flag           VARCHAR2(30)    := 'N';
8085     l_dflt_flag            VARCHAR2(30);
8086     l_reinstt_flag         VARCHAR2(30);
8087     l_next_level_enrt_flag VARCHAR2(30)    := 'N';
8088     l_jurisdiction_code    VARCHAR2(30);
8089     --
8090     l_lf_evt_ocrd_dt       DATE     := NVL(p_lf_evt_ocrd_dt, p_effective_date);
8091     l_lf_evt_ocrd_dt_1     DATE            := l_lf_evt_ocrd_dt - 1;
8092     l_covered_flag         varchar2(30):='N';
8093     --
8094     -- Gets the enrolment information for the plan in which the oipl belongs
8095     --
8096     --
8097     CURSOR c_plan_enrolment_info IS
8098       SELECT   'Y'
8099       FROM     ben_prtt_enrt_rslt_f pen
8100       WHERE    pen.person_id = p_person_id
8101       AND      pen.business_group_id = p_business_group_id
8102       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
8103 --      AND      pen.sspndd_flag = 'N' --CFW
8104       AND      (pen.sspndd_flag = 'N' --CFW
8105                  OR (pen.sspndd_flag = 'Y' and
8106                      pen.enrt_cvg_thru_dt = hr_api.g_eot
8107                     )
8108                )
8109       AND      pen.effective_end_date = hr_api.g_eot
8110       AND      l_lf_evt_ocrd_dt <= pen.enrt_cvg_thru_dt
8111       AND      l_lf_evt_ocrd_dt >= pen.enrt_cvg_strt_dt
8112       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
8113       AND      p_pl_id = pen.pl_id
8114       AND      (
8115                     (    pen.pgm_id = p_pgm_id
8116                      AND p_pgm_id IS NOT NULL)
8117                  OR (    pen.pgm_id IS NULL
8118                      AND p_pgm_id IS NULL));
8119     --
8120     -- Gets the enrolment information for this oipl
8121     --
8122     --
8123     CURSOR c_oipl_enrolment_info IS
8124       SELECT   'Y'
8125       FROM     ben_prtt_enrt_rslt_f pen
8126       WHERE    pen.person_id = p_person_id
8127       AND      pen.business_group_id = p_business_group_id
8128 --      AND      pen.sspndd_flag = 'N' --CFW
8129       AND      (pen.sspndd_flag = 'N' --CFW
8130                  OR (pen.sspndd_flag = 'Y' and
8131                      pen.enrt_cvg_thru_dt = hr_api.g_eot
8132                     )
8133                )
8134       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
8135       AND      pen.effective_end_date = hr_api.g_eot
8136       AND      l_lf_evt_ocrd_dt <= pen.enrt_cvg_thru_dt
8137       AND      l_lf_evt_ocrd_dt >= pen.enrt_cvg_strt_dt
8138       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
8139       AND      p_oipl_id = pen.oipl_id
8140       AND      (
8141                     (    pen.pgm_id = p_pgm_id
8142                      AND p_pgm_id IS NOT NULL)
8143                  OR (    pen.pgm_id IS NULL
8144                      AND p_pgm_id IS NULL));
8145     --
8146     -- Gets the enrolment information for the ptip in which the plan belongs
8147     --
8148     CURSOR c_ptip_enrolment_info IS
8149       SELECT   'Y'
8150       FROM     ben_prtt_enrt_rslt_f pen
8151       WHERE    pen.person_id = p_person_id
8152       AND      pen.business_group_id = p_business_group_id
8153       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
8154       -- AND      pen.sspndd_flag = 'N'
8155       AND      (pen.sspndd_flag = 'N' --CFW
8156                  OR (pen.sspndd_flag = 'Y' and
8157                      pen.enrt_cvg_thru_dt = hr_api.g_eot
8158                     )
8159                )
8160       AND      pen.effective_end_date = hr_api.g_eot
8161       AND
8162                --   nvl(p_lf_evt_ocrd_dt,p_effective_date) between
8163                --      pen.effective_start_date and pen.effective_end_date and
8164                l_lf_evt_ocrd_dt <= pen.enrt_cvg_thru_dt
8165       AND      l_lf_evt_ocrd_dt >= pen.enrt_cvg_strt_dt
8166       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
8167       AND      p_ptip_id = pen.ptip_id;
8168 
8169     --
8170     CURSOR c_state IS
8171       SELECT   loc.region_2
8172       FROM     hr_locations_all loc, per_all_assignments_f asg
8173       WHERE    loc.location_id = asg.location_id
8174       AND      asg.person_id = p_person_id
8175       and      asg.assignment_type <> 'C'
8176       AND      asg.primary_flag = 'Y'
8177       AND      l_lf_evt_ocrd_dt BETWEEN asg.effective_start_date
8178                    AND asg.effective_end_date
8179       AND      asg.business_group_id = p_business_group_id;
8180 
8181     l_state                c_state%ROWTYPE;
8182     CURSOR c_asg IS
8183       SELECT   asg.assignment_id,
8184                asg.organization_id
8185       FROM     per_all_assignments_f asg
8186       WHERE    asg.person_id = p_person_id
8187       and      asg.assignment_type <> 'C'
8188       AND      asg.primary_flag = decode(p_run_mode, 'I',asg.primary_flag, 'Y')  -- iRec
8189       AND      l_lf_evt_ocrd_dt BETWEEN asg.effective_start_date
8190                    AND asg.effective_end_date;
8191     l_asg                  c_asg%ROWTYPE;
8192     l_proc                 VARCHAR2(80)   := g_package ||
8193                                                '.determine_dflt_flag';
8194   --
8195   BEGIN
8196   g_debug := hr_utility.debug_enabled;
8197   if g_debug then
8198     hr_utility.set_location('Entering: ' || l_proc, 10);
8199     hr_utility.set_location('p_dflt_flag' || p_dflt_flag, 121.121);
8200     hr_utility.set_location('p_dflt_enrt_cd' || p_dflt_enrt_cd, 121.121);
8201     hr_utility.set_location('p_oipl_id' || p_oipl_id, 121.121);
8202     hr_utility.set_location('p_pl_id' || p_pl_id, 121.121);
8203     hr_utility.set_location('p_ptip_id' || p_ptip_id, 121.121);
8204     hr_utility.set_location('p_default_level' || p_default_level, 121.121);
8205   end if;
8206 
8207 -- If the dflt_enrt_cd and enrollment status combination in the following
8208 -- matrix is YES set the dflt_flag to Y, if it is NO set it to N,
8209 -- if it is Flag use the dflt_flag.
8210 --
8211 --
8212 -- For Plan
8213 --                                              enrd in ptip and
8214 -- DFLT_ENRT_CD    not enrd ptip   enrd pl      not enrd pl
8215 ---------------------------------------------------------------
8216 -- NSDCSD          Flag            Flag         Flag
8217 -- NSDCS           Flag            YES          NO(X)
8218 -- NDCSEDR         Flag            YES          NO(X)
8219 -- NNCS            NO              YES          NO
8220 -- NNCSEDR         NO              YES          NO
8221 -- NNCN            NO              NO           NO
8222 -- NNCD            NO              Flag         Flag(X)
8223 -- NDCN            Flag            NO           NO(X)
8224 --
8225 -- For Oipl
8226 --                                              enrd in pl and
8227 -- DFLT_ENRT_CD    not enrd pl     enrd oipl    not enrd oipl
8228 ---------------------------------------------------------------
8229 -- NSDCSD          Flag            Flag         Flag
8230 -- NSDCS           Flag            YES          NO(X)
8231 -- NDCSEDR         Flag            YES          NO(X)
8232 -- NNCS            NO              YES          NO
8233 -- NNCSEDR         NO              YES          NO
8234 -- NNCN            NO              NO           NO
8235 -- NNCD            NO              Flag         Flag(X)
8236 -- NDCN            Flag            NO           NO(X)
8237 --
8238 /*  -- 4031733 - Cursor c_state populates l_state variable which is no longer
8239     -- used in the package. Cursor can be commented
8240 
8241     IF p_person_id IS NOT NULL THEN
8242       OPEN c_state;
8243       FETCH c_state INTO l_state;
8244       CLOSE c_state;
8245       --IF l_state.region_2 IS NOT NULL THEN
8246       --  l_jurisdiction_code :=
8247       --    pay_mag_utils.lookup_jurisdiction_code(p_state => l_state.region_2);
8248       --END IF;
8249     END IF;
8250 */
8251     OPEN c_asg;
8252     FETCH c_asg INTO l_asg;
8253     IF c_asg%NOTFOUND THEN
8254       CLOSE c_asg;
8255       fnd_message.set_name('BEN', 'BEN_92106_PRTT_NO_ASGN');
8256       fnd_message.set_token('PROC', l_proc);
8257       fnd_message.set_token('PERSON_ID', TO_CHAR(p_person_id));
8258       fnd_message.set_token('LF_EVT_OCRD_DT', TO_CHAR(p_lf_evt_ocrd_dt));
8259       fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
8260       RAISE ben_manage_life_events.g_record_error;
8261     END IF;
8262     CLOSE c_asg;
8263     IF (p_oipl_id IS NULL) THEN
8264       --
8265       OPEN c_plan_enrolment_info;
8266       --
8267       FETCH c_plan_enrolment_info INTO l_covered_flag;
8268       --
8269       CLOSE c_plan_enrolment_info;
8270     --
8271     ELSE
8272       --
8273       OPEN c_oipl_enrolment_info;
8274       --
8275       FETCH c_oipl_enrolment_info INTO l_covered_flag;
8276       --
8277       CLOSE c_oipl_enrolment_info;
8278     --
8279     END IF;
8280     IF l_covered_flag='Y' THEN
8281       --
8282       -- enrolled in oipl/pl
8283       --
8284       IF p_dflt_enrt_cd IN ('NSDCS', 'NDCSEDR', 'NNCS', 'NNCSEDR') THEN
8285         l_dflt_flag :=  'Y';
8286       ELSIF p_dflt_enrt_cd IN ('NNCN', 'NDCN') THEN
8287         l_dflt_flag :=  'N';
8288       ELSE
8289         l_defer_flag :=  'Y';
8290       END IF;
8291     ELSE
8292       --
8293       -- not enrolled in oipl/pl must check for plan/ptip enrt
8294       -- Note: to speed processing if enrt does not matter set
8295       --   l_next_level_enrt_flag='Y'
8296       -- Note: for plans not in program don't have next level so
8297       --   not enrolled means not enrolled, set next level='N'
8298       --
8299       if g_debug then
8300       hr_utility.set_location(l_proc, 50);
8301       end if;
8302 /*
8303       IF p_dflt_enrt_cd IN ('RL', 'NSDCSD', 'NNCS', 'NNCSEDR', 'NNCN') THEN
8304         l_next_level_enrt_flag :=  'Y';
8305       ELSIF p_oipl_id IS NOT NULL THEN
8306         OPEN c_plan_enrolment_info;
8307         FETCH c_plan_enrolment_info INTO l_next_level_enrt_flag;
8308         CLOSE c_plan_enrolment_info;
8309       ELSIF p_ptip_id IS NOT NULL THEN
8310         OPEN c_ptip_enrolment_info;
8311         FETCH c_ptip_enrolment_info INTO l_next_level_enrt_flag;
8312         CLOSE c_ptip_enrolment_info;
8313       ELSE
8314         l_next_level_enrt_flag :=  'N';
8315       END IF;
8316       --
8317 */
8318 --bug#2080856 - need to check at ptip level if not enrolled in plan- the above code was
8319 --skipping to check ptip level if oipl_id is not null
8320      IF p_dflt_enrt_cd IN ('RL', 'NSDCSD', 'NNCS', 'NNCSEDR', 'NNCN') THEN
8321         l_next_level_enrt_flag :=  'Y';
8322      ELSE
8323         if p_oipl_id IS NOT NULL THEN
8324 	if g_debug then
8325 	  hr_utility.set_location('p_oipl_id IS NOT NULL THEN',121.121);
8326         end if;
8327           OPEN c_plan_enrolment_info;
8328           FETCH c_plan_enrolment_info INTO l_next_level_enrt_flag;
8329           CLOSE c_plan_enrolment_info;
8330 	  if g_debug then
8331 	  hr_utility.set_location('l_next_level_enrt_flag '||nvl(l_next_level_enrt_flag,'-')|| '  ' ,121.121);
8332 	  end if;
8333         end if;
8334         if l_next_level_enrt_flag <>'Y' then
8335 	if g_debug then
8336 	   hr_utility.set_location('l_next_level_enrt_flag <>Y ',121.121);
8337         end if;
8338            if  p_ptip_id IS NOT NULL THEN
8339 	   if g_debug then
8340 	     hr_utility.set_location('p_ptip_id IS NOT NULL  ',121.121);
8341 	     hr_utility.set_location('Checking p_default level  ' || p_default_level,121.121);
8342 	     end if;
8343            ---Reverting back the fix 5644451 for the bug 7452061
8344 	    /* IF p_default_level IN('PTIP','LER_PTIP')
8345 	     THEN*/
8346                OPEN c_ptip_enrolment_info;
8347                   FETCH c_ptip_enrolment_info INTO l_next_level_enrt_flag;
8348                CLOSE c_ptip_enrolment_info;
8349 	    -- END IF; ---Reverting back the fix 5644451 for the bug 7452061
8350            ELSE
8351              l_next_level_enrt_flag :=  'N';
8352            end if;
8353          end if;
8354       END if;
8355 
8356 
8357       --
8358       IF l_next_level_enrt_flag = 'Y' THEN
8359         --
8360         -- Enrolled in plan/ptip and not oipl/plan
8361         --
8362 	if g_debug then
8363 	hr_utility.set_location('l_next_level_enrt_flag = Y 2 ',121.121);
8364 	end if;
8365         IF p_dflt_enrt_cd IN (
8366                                'NSDCS',
8367                                'NDCSEDR',
8368                                'NNCS',
8369                                'NNCSEDR',
8370                                'NNCN',
8371                                'NDCN') THEN
8372           l_dflt_flag :=  'N';
8373         ELSE
8374           l_defer_flag :=  'Y';
8375         END IF;
8376       ELSE
8377         --
8378         -- Not enrolled in plan/ptip
8379         --
8380         IF p_dflt_enrt_cd IN ('NNCS', 'NNCSEDR', 'NNCN', 'NNCD') THEN
8381           l_dflt_flag :=  'N';
8382         ELSE
8383           l_defer_flag :=  'Y';
8384         END IF;
8385       END IF;
8386     END IF;
8387     --
8388     -- If the dflt_enrt_cd is RL then execute the rule,
8389     -- it will determine the value for the dflt_flag.
8390     --
8391     IF p_dflt_enrt_cd = 'RL' THEN
8392       --
8393       if g_debug then
8394       hr_utility.set_location(' EER ' || l_proc, 190);
8395       end if;
8396        execute_auto_dflt_enrt_rule(
8397          p_opt_id            => p_opt_id,
8398          p_pl_id             => p_pl_id,
8399          p_pgm_id            => p_pgm_id,
8400          p_rule_id           => p_dflt_enrt_rl,
8401          p_ler_id            => p_ler_id,
8402          p_pl_typ_id         => p_pl_typ_id,
8403          p_business_group_id => p_business_group_id,
8404          p_effective_date    => NVL(p_lf_evt_ocrd_dt, p_effective_date),
8405          p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
8406          p_assignment_id     => p_assignment_id,
8407          p_organization_id   => l_asg.organization_id,
8408          p_jurisdiction_code => l_jurisdiction_code,
8409 	 p_person_id         => p_person_id,          -- Bug 5331889
8410          p_enrt_mthd         => l_dflt_flag,
8411          p_reinstt_dpnt      => l_reinstt_flag,
8412 	 p_elig_per_id => p_elig_per_id -- Bug 14768372
8413          );
8414      if g_debug then
8415       hr_utility.set_location(' Dn EER ' || l_proc, 190);
8416      end if;
8417       --
8418       l_defer_flag :=  'N';
8419     ELSIF (    p_dflt_enrt_cd IS NULL
8420            AND p_dflt_flag IS NOT NULL) THEN
8421       --
8422       -- If the dflt_enrt_cd is null and the dflt_flag is not
8423       -- null set the dflt_flag to it's value.
8424       --
8425       l_dflt_flag :=  'N'; -- p_dflt_flag - Bug#2080856
8426       l_defer_flag :=  'N';
8427     --
8428     END IF;
8429    if g_debug then
8430     hr_utility.set_location(l_proc, 200);
8431    end if;
8432     --
8433     IF l_defer_flag = 'Y' THEN
8434       --
8435        l_dflt_flag := 'DEFER';
8436     --
8437     END IF;
8438     if g_debug then
8439     hr_utility.set_location('Leaving: ' || l_proc, 235);
8440     end if;
8441     --
8442     p_deflt_flag := l_dflt_flag;
8443     p_reinstt_flag := l_reinstt_flag;
8444   --
8445   exception  -- nocopy changes
8446     --
8447     when others then
8448       --
8449       p_deflt_flag := null;
8450       p_reinstt_flag := null;
8451       raise;
8452       --
8453   END;                                                              -- Function
8454 --
8455   FUNCTION determine_erlst_deenrt_dt(
8456     p_enrt_cvg_strt_dt           DATE,
8457     p_rqd_perd_enrt_nenrt_val    NUMBER,
8458     p_rqd_perd_enrt_nenrt_tm_uom VARCHAR2,
8459     p_rqd_perd_enrt_nenrt_rl     NUMBER,
8460     p_oipl_id                    NUMBER,
8461     p_pl_id                      NUMBER,
8462     p_pl_typ_id                  NUMBER,
8463     p_opt_id                     NUMBER,
8464     p_pgm_id                     NUMBER,
8465     p_ler_id                     NUMBER,
8466     p_popl_yr_perd_ordr_num      NUMBER,
8467     p_yr_end_dt                  DATE,
8468     p_effective_date             DATE,
8469     p_lf_evt_ocrd_dt             DATE DEFAULT NULL,
8470     p_person_id                  NUMBER,
8471     p_business_group_id          NUMBER,
8472     p_assignment_id              NUMBER,
8473     p_organization_id            NUMBER,
8474     p_jurisdiction_code          VARCHAR2)
8475     RETURN DATE IS
8476     --
8477     -- local variables
8478     --
8479     l_deenrt_dt       DATE;
8480     l_yr_perd_id      NUMBER;
8481     l_popl_yr_perd_id NUMBER;
8482     l_start_date      DATE;
8483     l_end_date        DATE;
8484     l_outputs         ff_exec.outputs_t;
8485     -- Determine a future popl_yr_period
8486     CURSOR c_pl_popl_yr_period_future(p_order_num NUMBER) IS
8487       SELECT   pyp.yr_perd_id,
8488                pyp.popl_yr_perd_id,
8489                yp.start_date,
8490                yp.end_date
8491       FROM     ben_popl_yr_perd pyp, ben_yr_perd yp
8492       WHERE    pyp.pl_id = p_pl_id
8493       AND      pyp.business_group_id = p_business_group_id
8494       AND      pyp.ordr_num = p_popl_yr_perd_ordr_num
8495       AND      yp.business_group_id = p_business_group_id
8496       AND      pyp.yr_perd_id = yp.yr_perd_id;
8497   --
8498   BEGIN
8499     IF p_rqd_perd_enrt_nenrt_rl IS NOT NULL THEN
8500     if g_debug then
8501       hr_utility.set_location(
8502         'Organization_id ' || TO_CHAR(p_organization_id),
8503         10);
8504       hr_utility.set_location(
8505         'assignment_id ' || TO_CHAR(p_assignment_id),
8506         15);
8507       hr_utility.set_location(
8508         'Business_group_id ' || TO_CHAR(p_business_group_id),
8509         20);
8510       hr_utility.set_location('pgm_id ' || TO_CHAR(p_pgm_id), 30);
8511       hr_utility.set_location('pl_id ' || TO_CHAR(p_pl_id), 40);
8512       hr_utility.set_location('pl_typ_id ' || TO_CHAR(p_pl_typ_id), 50);
8513       hr_utility.set_location('opt_id ' || TO_CHAR(p_opt_id), 60);
8514       hr_utility.set_location('ler_id ' || TO_CHAR(p_ler_id), 70);
8515     end if;
8516       l_outputs :=
8517        benutils.formula(
8518          p_formula_id        => p_rqd_perd_enrt_nenrt_rl,
8519          p_effective_date    => NVL(p_lf_evt_ocrd_dt, p_effective_date),
8520          p_business_group_id => p_business_group_id,
8521          p_assignment_id     => p_assignment_id,
8522          p_organization_id   => p_organization_id,
8523          p_pl_id             => p_pl_id,
8524          p_pgm_id            => p_pgm_id,
8525          p_opt_id            => p_opt_id,
8526          p_pl_typ_id         => p_pl_typ_id,
8527          p_ler_id            => p_ler_id,
8528          p_jurisdiction_code => p_jurisdiction_code,
8529          p_param1            => 'BEN_IV_PERSON_ID',        -- Bug 5331889 : Added person_id param as well
8530          p_param1_value      => to_char(p_person_id));
8531       --
8532       -- Reformat Canonical Character output to be a date
8533       --
8534       l_deenrt_dt :=
8535                 fnd_date.canonical_to_date(l_outputs(l_outputs.FIRST).VALUE);
8536     ELSE
8537       -- Code     Meaning
8538       -- D     Days
8539       -- W     Weeks
8540       -- M     Months
8541       -- PPLYRQ     Program or Plan Year Quarters
8542       -- Q     Quarters
8543       -- Y     Years
8544       -- PPLYR     Program or Plan Years
8545       IF (p_rqd_perd_enrt_nenrt_tm_uom IN ('D', 'DY')) THEN
8546         --
8547         l_deenrt_dt :=  p_enrt_cvg_strt_dt + p_rqd_perd_enrt_nenrt_val - 1;
8548       --
8549       ELSIF (p_rqd_perd_enrt_nenrt_tm_uom IN ('W', 'WK')) THEN
8550         --
8551         l_deenrt_dt :=  p_enrt_cvg_strt_dt + (p_rqd_perd_enrt_nenrt_val * 7) -
8552                           1;
8553       --
8554       ELSIF (p_rqd_perd_enrt_nenrt_tm_uom IN ('M', 'MO')) THEN
8555         --
8556         l_deenrt_dt :=
8557                  ADD_MONTHS(p_enrt_cvg_strt_dt, p_rqd_perd_enrt_nenrt_val) - 1;
8558       --
8559       ELSIF (p_rqd_perd_enrt_nenrt_tm_uom IN ('Q', 'QTR')) THEN
8560         --
8561         l_deenrt_dt :=
8562              ADD_MONTHS(p_enrt_cvg_strt_dt, p_rqd_perd_enrt_nenrt_val * 3) - 1;
8563       --
8564       ELSIF (p_rqd_perd_enrt_nenrt_tm_uom IN ('PPLYR')) THEN
8565         --
8566         -- program/plan years based on passed in current popl_yr_perd
8567         --
8568         IF p_rqd_perd_enrt_nenrt_val = 1 THEN
8569           --
8570           l_deenrt_dt :=  p_yr_end_dt;
8571         --
8572         ELSE
8573           --
8574           OPEN c_pl_popl_yr_period_future(
8575             p_popl_yr_perd_ordr_num + p_rqd_perd_enrt_nenrt_val - 1);
8576           --
8577           FETCH c_pl_popl_yr_period_future INTO l_yr_perd_id,
8578                                                 l_popl_yr_perd_id,
8579                                                 l_start_date,
8580                                                 l_end_date;
8581           l_deenrt_dt :=  l_end_date;
8582           --
8583           CLOSE c_pl_popl_yr_period_future;
8584         --
8585         END IF;
8586       --
8587       ELSIF (p_rqd_perd_enrt_nenrt_tm_uom IN ('Y', 'YR')) THEN
8588         --
8589         l_deenrt_dt :=
8590                ADD_MONTHS(p_enrt_cvg_strt_dt, p_rqd_perd_enrt_nenrt_val * 12);
8591       --
8592       ELSE
8593         --
8594         l_deenrt_dt :=  NULL;
8595       --
8596       END IF;
8597     END IF;
8598     --
8599     RETURN l_deenrt_dt;
8600   --
8601   END;
8602 --
8603   FUNCTION should_create_dpnt_dummy(
8604     p_pl_id             NUMBER,
8605     p_pl_typ_id         NUMBER,
8606     p_opt_id            NUMBER,
8607     p_ler_id            NUMBER,
8608     p_ptip_id           NUMBER,
8609     p_effective_date    DATE,
8610     p_lf_evt_ocrd_dt    DATE DEFAULT NULL,
8611     p_pgm_id            NUMBER,
8612     p_person_id         NUMBER,
8613     p_business_group_id NUMBER,
8614     p_assignment_id     NUMBER,
8615     p_organization_id   NUMBER,
8616     p_jurisdiction_code VARCHAR2)
8617     RETURN BOOLEAN IS
8618     l_level          NUMBER;
8619     l_dpnt_cvg_cd    VARCHAR2(30);
8620     l_dpnt_cvg_rl    NUMBER;
8621     l_outputs        ff_exec.outputs_t;
8622     --
8623     l_lf_evt_ocrd_dt DATE           := NVL(p_lf_evt_ocrd_dt, p_effective_date);
8624     -- Cursor to get the ler_chg_dpnt_f row to
8625     --   see if the choice needs to be created
8626     --   for dpnt reasons
8627     -- Walk up heirarchy - pl, ptip, then pgm.
8628     --
8629     CURSOR c_ler_chg_dep IS
8630       SELECT   '1',
8631                ldc.ler_chg_dpnt_cvg_cd,
8632                ldc.ler_chg_dpnt_cvg_rl
8633       FROM     ben_ler_chg_dpnt_cvg_f ldc
8634       WHERE    ldc.ler_id = p_ler_id
8635       AND      ldc.business_group_id = p_business_group_id
8636       AND      ldc.pl_id = p_pl_id
8637       AND      l_lf_evt_ocrd_dt BETWEEN ldc.effective_start_date
8638                    AND ldc.effective_end_date
8639       AND      ldc.ler_chg_dpnt_cvg_cd IS NOT NULL
8640       UNION ALL
8641       SELECT   '2',
8642                ldc.ler_chg_dpnt_cvg_cd,
8643                ldc.ler_chg_dpnt_cvg_rl
8644       FROM     ben_ler_chg_dpnt_cvg_f ldc
8645       WHERE    ldc.ler_id = p_ler_id
8646       AND      ldc.business_group_id = p_business_group_id
8647       AND      ldc.ptip_id = p_ptip_id
8648       AND      l_lf_evt_ocrd_dt BETWEEN ldc.effective_start_date
8649                    AND ldc.effective_end_date
8650       AND      ldc.ler_chg_dpnt_cvg_cd IS NOT NULL
8651       UNION ALL
8652       SELECT   '3',
8653                ldc.ler_chg_dpnt_cvg_cd,
8654                ldc.ler_chg_dpnt_cvg_rl
8655       FROM     ben_ler_chg_dpnt_cvg_f ldc
8656       WHERE    ldc.ler_id = p_ler_id
8657       AND      ldc.business_group_id = p_business_group_id
8658       AND      ldc.pgm_id = p_pgm_id
8659       AND      l_lf_evt_ocrd_dt BETWEEN ldc.effective_start_date
8660                    AND ldc.effective_end_date
8661       AND      ldc.ler_chg_dpnt_cvg_cd IS NOT NULL;
8662   BEGIN
8663     OPEN c_ler_chg_dep;
8664     FETCH c_ler_chg_dep INTO l_level, l_dpnt_cvg_cd, l_dpnt_cvg_rl;
8665     IF c_ler_chg_dep%NOTFOUND THEN
8666       RETURN FALSE;
8667     ELSE
8668       IF l_dpnt_cvg_cd = 'RL' THEN
8669         -- Evaluate the rule
8670       if g_debug then
8671         hr_utility.set_location(
8672           'Organization_id ' || TO_CHAR(p_organization_id),
8673           10);
8674         hr_utility.set_location(
8675           'assignment_id ' || TO_CHAR(p_assignment_id),
8676           15);
8677         hr_utility.set_location(
8678           'Business_group_id ' || TO_CHAR(p_business_group_id),
8679           20);
8680         hr_utility.set_location('pgm_id ' || TO_CHAR(p_pgm_id), 30);
8681         hr_utility.set_location('pl_id ' || TO_CHAR(p_pl_id), 40);
8682         hr_utility.set_location('pl_typ_id ' || TO_CHAR(p_pl_typ_id), 50);
8683         hr_utility.set_location('opt_id ' || TO_CHAR(p_opt_id), 60);
8684         hr_utility.set_location('ler_id ' || TO_CHAR(p_ler_id), 70);
8685       end if;
8686         l_outputs :=
8687          benutils.formula(
8688            p_formula_id        => l_dpnt_cvg_rl,
8689            p_effective_date    => NVL(p_lf_evt_ocrd_dt, p_effective_date),
8690            p_business_group_id => p_business_group_id,
8691            p_assignment_id     => p_assignment_id,
8692            p_organization_id   => p_organization_id,
8693            p_pl_id             => p_pl_id,
8694            p_pgm_id            => p_pgm_id,
8695            p_opt_id            => p_opt_id,
8696            p_pl_typ_id         => p_pl_typ_id,
8697            p_ler_id            => p_ler_id,
8698            p_jurisdiction_code => p_jurisdiction_code);
8699         l_dpnt_cvg_cd :=  l_outputs(l_outputs.FIRST).VALUE;
8700       END IF;
8701       --
8702       -- For MNANRD (May not add nor removed dependents)
8703       -- don't need choice, all other codes do need it.
8704       --
8705       IF l_dpnt_cvg_cd = 'MNANRD' THEN
8706         RETURN FALSE;
8707       END IF;
8708     END IF;
8709     CLOSE c_ler_chg_dep;
8710     RETURN TRUE;
8711   END;
8712 --
8713 procedure determine_dflt_enrt_cd
8714   (p_oipl_id           in     number
8715   ,p_plip_id           in     number
8716   ,p_pl_id             in     number
8717   ,p_ptip_id           in     number
8718   ,p_pgm_id            in     number
8719   ,p_ler_id            in     number
8720   ,p_business_group_id in     number
8721   ,p_effective_date    in     date
8722   ,p_dflt_enrt_cd         out nocopy varchar2
8723   ,p_dflt_enrt_rl         out nocopy number
8724   )
8725 IS
8726     --
8727     -- NOTE:
8728     --
8729     --   This procedure is also callable from other RCOs
8730     --   Please do not remove get_object calls since they
8731     --   may be needed if not called from bendenrr.
8732     --
8733     l_proc         VARCHAR2(80)       := g_package || '.determine_dflt_enrt_cd';
8734     --
8735     CURSOR c_ler_oipl_dflt_cd IS
8736       SELECT   leo.dflt_enrt_cd,
8737                leo.dflt_enrt_rl
8738       FROM     ben_ler_chg_oipl_enrt_f leo
8739       WHERE    p_oipl_id = leo.oipl_id
8740       AND      p_ler_id = leo.ler_id
8741       AND      p_effective_date BETWEEN leo.effective_start_date
8742                    AND leo.effective_end_date;
8743     --
8744     -- Use cache for oipl, don't need cursor
8745     --
8746     CURSOR c_ler_pl_nip_dflt_cd IS
8747       SELECT   len.dflt_enrt_cd,
8748                len.dflt_enrt_rl
8749       FROM     ben_ler_chg_pl_nip_enrt_f len
8750       WHERE    p_pl_id = len.pl_id
8751       AND      p_ler_id = len.ler_id
8752       AND      p_effective_date BETWEEN len.effective_start_date
8753                    AND len.effective_end_date;
8754     --
8755     CURSOR c_ler_plip_dflt_cd IS
8756       SELECT   lep.dflt_enrt_cd,
8757                lep.dflt_enrt_rl
8758       FROM     ben_ler_chg_plip_enrt_f lep
8759       WHERE    p_plip_id = lep.plip_id
8760       AND      p_ler_id = lep.ler_id
8761       AND      p_effective_date BETWEEN lep.effective_start_date
8762                    AND lep.effective_end_date;
8763     --
8764     CURSOR c_ler_ptip_dflt_cd IS
8765       SELECT   lep.dflt_enrt_cd,
8766                lep.dflt_enrt_rl
8767       FROM     ben_ler_chg_ptip_enrt_f lep
8768       WHERE    p_ptip_id = lep.ptip_id
8769       AND      p_ler_id = lep.ler_id
8770       AND      p_effective_date BETWEEN lep.effective_start_date
8771                    AND lep.effective_end_date;
8772     --
8773     CURSOR c_ler_pgm_dflt_cd IS
8774       SELECT   lep.dflt_enrt_cd,
8775                lep.dflt_enrt_rl
8776       FROM     ben_ler_chg_pgm_enrt_f lep
8777       WHERE    p_pgm_id = lep.pgm_id
8778       AND      p_ler_id = lep.ler_id
8779       AND      p_effective_date BETWEEN lep.effective_start_date
8780                    AND lep.effective_end_date;
8781     --
8782     CURSOR c_pl_nip_dflt_cd IS
8783       SELECT   pln.nip_dflt_enrt_cd,
8784                pln.nip_dflt_enrt_det_rl
8785       FROM     ben_pl_f pln
8786       WHERE    p_pl_id = pln.pl_id
8787       AND      p_effective_date BETWEEN pln.effective_start_date
8788                    AND pln.effective_end_date;
8789     --
8790     CURSOR c_plip_dflt_cd IS
8791       SELECT   plp.dflt_enrt_cd,
8792                plp.dflt_enrt_det_rl
8793       FROM     ben_plip_f plp
8794       WHERE    p_plip_id = plp.plip_id
8795       AND      p_effective_date BETWEEN plp.effective_start_date
8796                    AND plp.effective_end_date;
8797     --
8798     CURSOR c_ptip_dflt_cd IS
8799       SELECT   ptp.dflt_enrt_cd,
8800                ptp.dflt_enrt_det_rl
8801       FROM     ben_ptip_f ptp
8802       WHERE    p_ptip_id = ptp.ptip_id
8803       AND      p_effective_date BETWEEN ptp.effective_start_date
8804                    AND ptp.effective_end_date;
8805     --
8806     l_dflt_enrt_cd VARCHAR2(30);
8807     l_dflt_enrt_rl NUMBER;
8808     l_plan_rec     ben_pl_f%ROWTYPE;
8809     l_oipl_rec     ben_cobj_cache.g_oipl_inst_row;
8810     l_pl_rec       ben_cobj_cache.g_pl_inst_row;
8811   BEGIN
8812   g_debug := hr_utility.debug_enabled;
8813   if g_debug then
8814     hr_utility.set_location('Entering: ' || l_proc, 10);
8815   end if;
8816     --
8817     l_dflt_enrt_cd :=  NULL;
8818     --
8819     -- Hierarchy
8820     --
8821     -- 1  if oipl     ben_ler_chg_oipl_enrt_f
8822     -- 2  if oipl     ben_oipl_f (from cache)
8823     --
8824     -- 3  if no pgm   ben_ler_chg_pl_nip_enrt_f
8825     -- 4  if pgm      ben_ler_chg_plip_enrt_f
8826     -- 4.5 if pgm     ben_ler_chg_pl_nip_enrt_f
8827     -- 5  if pgm      ben_ler_chg_ptip_enrt_f
8828     -- 6  if pgm      ben_ler_chg_pgm_enrt_f
8829     --
8830     -- 7  if no pgm   ben_pl_f
8831     -- 8  if pgm      ben_plip_f
8832     -- 9  if pgm      ben_ptip_f
8833     --
8834     IF p_oipl_id IS NOT NULL THEN
8835       --
8836       -- 1
8837       --
8838       OPEN c_ler_oipl_dflt_cd;
8839       FETCH c_ler_oipl_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
8840       CLOSE c_ler_oipl_dflt_cd;
8841       --
8842       -- hr_utility.set_location(l_dflt_enrt_cd,20);
8843       IF l_dflt_enrt_cd IS NULL THEN
8844         --
8845         -- 2
8846         -- Bug 5569758
8847         --
8848         ben_cobj_cache.get_oipl_dets (p_business_group_id => p_business_group_id,
8849                                       p_effective_date    => p_effective_date,
8850                                       p_oipl_id           => p_oipl_id,
8851                                       p_inst_row	  => l_oipl_rec
8852                                       );
8853         --
8854         l_dflt_enrt_cd :=  l_oipl_rec.dflt_enrt_cd;
8855         l_dflt_enrt_rl :=  l_oipl_rec.dflt_enrt_det_rl;
8856       --
8857       END IF;
8858     END IF;
8859     -- hr_utility.set_location(l_dflt_enrt_cd,30);
8860     IF     p_pgm_id IS NULL
8861        AND l_dflt_enrt_cd IS NULL THEN
8862       --
8863       -- 3
8864       --
8865       OPEN c_ler_pl_nip_dflt_cd;
8866       FETCH c_ler_pl_nip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
8867       CLOSE c_ler_pl_nip_dflt_cd;
8868     --  hr_utility.set_location(l_dflt_enrt_cd,40);
8869     ELSIF     p_pgm_id IS NOT NULL
8870           AND l_dflt_enrt_cd IS NULL THEN
8871       --
8872       -- 4
8873       --
8874       OPEN c_ler_plip_dflt_cd;
8875       FETCH c_ler_plip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
8876       CLOSE c_ler_plip_dflt_cd;
8877       --  hr_utility.set_location(l_dflt_enrt_cd,50);
8878       -- Bug 5555402
8879       IF l_dflt_enrt_cd IS NULL THEN
8880         --
8881         -- 4.5
8882         --
8883         OPEN c_ler_pl_nip_dflt_cd;
8884         FETCH c_ler_pl_nip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
8885         CLOSE c_ler_pl_nip_dflt_cd;
8886         --
8887         IF l_dflt_enrt_cd IS NULL THEN
8888           --
8889           -- 5
8890           --
8891           OPEN c_ler_ptip_dflt_cd;
8892           FETCH c_ler_ptip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
8893           CLOSE c_ler_ptip_dflt_cd;
8894           --  hr_utility.set_location(l_dflt_enrt_cd,60);
8895           IF l_dflt_enrt_cd IS NULL THEN
8896             --
8897             -- 6
8898             --
8899             OPEN c_ler_pgm_dflt_cd;
8900             FETCH c_ler_pgm_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
8901             CLOSE c_ler_pgm_dflt_cd;
8902           END IF;
8903         END IF;
8904         --
8905       END IF;
8906       --
8907     END IF;
8908     --  hr_utility.set_location(l_dflt_enrt_cd,80);
8909     IF     p_pgm_id IS NULL
8910        AND l_dflt_enrt_cd IS NULL THEN
8911       --
8912       -- 7
8913       --
8914       ben_cobj_cache.get_pl_dets (p_business_group_id => p_business_group_id,
8915                                     p_effective_date  => p_effective_date,
8916                                     p_pl_id           => p_pl_id,
8917                                     p_inst_row	      => l_pl_rec
8918                                     );
8919       --
8920       l_dflt_enrt_cd :=  l_pl_rec.nip_dflt_enrt_cd;
8921       l_dflt_enrt_rl :=  l_pl_rec.nip_dflt_enrt_det_rl;
8922       --
8923       --  hr_utility.set_location(l_dflt_enrt_cd,90);
8924     ELSIF     p_pgm_id IS NOT NULL
8925           AND l_dflt_enrt_cd IS NULL THEN
8926       --
8927       -- 8
8928       --
8929       OPEN c_plip_dflt_cd;
8930       FETCH c_plip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
8931       CLOSE c_plip_dflt_cd;
8932       --  hr_utility.set_location(l_dflt_enrt_cd,100);
8933         --
8934       IF l_dflt_enrt_cd IS NULL THEN
8935         --
8936         -- 9
8937         --
8938         OPEN c_ptip_dflt_cd;
8939         FETCH c_ptip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
8940         CLOSE c_ptip_dflt_cd;
8941      --  hr_utility.set_location(l_dflt_enrt_cd,110);
8942         --
8943       END IF;
8944     END IF;
8945     --
8946     p_dflt_enrt_cd :=  l_dflt_enrt_cd;
8947     p_dflt_enrt_rl :=  l_dflt_enrt_rl;
8948     --
8949     if g_debug then
8950     hr_utility.set_location(l_dflt_enrt_cd,145);
8951     hr_utility.set_location('Leaving: ' || l_proc, 150);
8952     end if;
8953     --
8954   exception
8955     --
8956     when others then
8957       --
8958       p_dflt_enrt_cd        := null;
8959       p_dflt_enrt_rl        := null;
8960       raise;
8961       --
8962   END;
8963 --
8964 /*
8965 This Procedure is moved at the top of the Package
8966 -- internal version below for update_defaults
8967 --
8968 procedure determine_dflt_enrt_cd
8969   (p_oipl_id           in     number
8970   ,p_oipl_rec          in     ben_oipl_f%rowtype
8971   ,p_plip_id           in     number
8972   ,p_plip_rec          in     ben_plip_f%rowtype
8973   ,p_pl_id             in     number
8974   ,p_pl_rec            in     ben_pl_f%rowtype
8975   ,p_ptip_id           in     number
8976   ,p_ptip_rec          in     ben_ptip_f%rowtype
8977   ,p_pgm_id            in     number
8978   ,p_pgm_rec           in     ben_pgm_f%rowtype
8979   ,p_ler_id            in     number
8980   ,p_business_group_id in     number
8981   ,p_effective_date    in     date
8982   ,p_dflt_enrt_cd         out nocopy varchar2
8983   ,p_dflt_enrt_rl         out nocopy number
8984   ,p_level                out nocopy varchar2
8985   ,p_ler_dflt_flag   out nocopy varchar2
8986   )
8987 IS
8988     --
8989     -- NOTE:
8990     --
8991     --   This procedure is also callable from other RCOs
8992     --   Please do not remove get_object calls since they
8993     --   may be needed if not called from bendenrr.
8994     --
8995     l_proc         VARCHAR2(80)       := g_package || '.determine_dflt_enrt_cd';
8996     --
8997     CURSOR c_ler_oipl_dflt_cd IS
8998       SELECT   leo.dflt_enrt_cd,
8999                leo.dflt_enrt_rl,
9000                leo.dflt_flag
9001       FROM     ben_ler_chg_oipl_enrt_f leo
9002       WHERE    p_oipl_id = leo.oipl_id
9003       AND      p_ler_id = leo.ler_id
9004       AND      p_effective_date BETWEEN leo.effective_start_date
9005                    AND leo.effective_end_date;
9006     --
9007     -- Use cache for oipl, don't need cursor
9008     --
9009     CURSOR c_ler_pl_nip_dflt_cd IS
9010       SELECT   len.dflt_enrt_cd,
9011                len.dflt_enrt_rl,
9012                len.dflt_flag
9013       FROM     ben_ler_chg_pl_nip_enrt_f len
9014       WHERE    p_pl_id = len.pl_id
9015       AND      p_ler_id = len.ler_id
9016       AND      p_effective_date BETWEEN len.effective_start_date
9017                    AND len.effective_end_date;
9018     --
9019     CURSOR c_ler_plip_dflt_cd IS
9020       SELECT   lep.dflt_enrt_cd,
9021                lep.dflt_enrt_rl,
9022                lep.dflt_flag
9023       FROM     ben_ler_chg_plip_enrt_f lep
9024       WHERE    p_plip_id = lep.plip_id
9025       AND      p_ler_id = lep.ler_id
9026       AND      p_effective_date BETWEEN lep.effective_start_date
9027                    AND lep.effective_end_date;
9028     --
9029     CURSOR c_ler_ptip_dflt_cd IS
9030       SELECT   lep.dflt_enrt_cd,
9031                lep.dflt_enrt_rl
9032       FROM     ben_ler_chg_ptip_enrt_f lep
9033       WHERE    p_ptip_id = lep.ptip_id
9034       AND      p_ler_id = lep.ler_id
9035       AND      p_effective_date BETWEEN lep.effective_start_date
9036                    AND lep.effective_end_date;
9037     --
9038     CURSOR c_ler_pgm_dflt_cd IS
9039       SELECT   lep.dflt_enrt_cd,
9040                lep.dflt_enrt_rl
9041       FROM     ben_ler_chg_pgm_enrt_f lep
9042       WHERE    p_pgm_id = lep.pgm_id
9043       AND      p_ler_id = lep.ler_id
9044       AND      p_effective_date BETWEEN lep.effective_start_date
9045                    AND lep.effective_end_date;
9046     --
9047     CURSOR c_pl_nip_dflt_cd IS
9048       SELECT   pln.nip_dflt_enrt_cd,
9049                pln.nip_dflt_enrt_det_rl,
9050                pln.nip_dflt_flag
9051       FROM     ben_pl_f pln
9052       WHERE    p_pl_id = pln.pl_id
9053       AND      p_effective_date BETWEEN pln.effective_start_date
9054                    AND pln.effective_end_date;
9055     --
9056     CURSOR c_plip_dflt_cd IS
9057       SELECT   plp.dflt_enrt_cd,
9058                plp.dflt_enrt_det_rl
9059       FROM     ben_plip_f plp
9060       WHERE    p_plip_id = plp.plip_id
9061       AND      p_effective_date BETWEEN plp.effective_start_date
9062                    AND plp.effective_end_date;
9063     --
9064     CURSOR c_ptip_dflt_cd IS
9065       SELECT   ptp.dflt_enrt_cd,
9066                ptp.dflt_enrt_det_rl
9067       FROM     ben_ptip_f ptp
9068       WHERE    p_ptip_id = ptp.ptip_id
9069       AND      p_effective_date BETWEEN ptp.effective_start_date
9070                    AND ptp.effective_end_date;
9071     --
9072     l_dflt_enrt_cd VARCHAR2(30);
9073     l_dflt_enrt_rl NUMBER;
9074     l_plan_rec     ben_pl_f%ROWTYPE;
9075     l_oipl_rec     ben_cobj_cache.g_oipl_inst_row;
9076     l_ler_dflt_flag varchar2(30); -- 3510229
9077   BEGIN
9078     hr_utility.set_location('Entering: ' || l_proc, 10);
9079     --
9080     l_dflt_enrt_cd :=  NULL;
9081     --
9082     -- Hierarchy
9083     --
9084     -- 1  if oipl     ben_ler_chg_oipl_enrt_f
9085     -- 2  if oipl     ben_oipl_f (from cache)
9086     --
9087     -- 3  if no pgm   ben_ler_chg_pl_nip_enrt_f
9088     -- 4  if pgm      ben_ler_chg_plip_enrt_f
9089     -- 5  if pgm      ben_ler_chg_ptip_enrt_f
9090     -- 6  if pgm      ben_ler_chg_pgm_enrt_f
9091     --
9092     -- 7  if no pgm   ben_pl_f
9093     -- 8  if pgm      ben_plip_f
9094     -- 9  if pgm      ben_ptip_f
9095     --
9096     IF p_oipl_id IS NOT NULL THEN
9097       --
9098       -- 1
9099       --
9100       OPEN c_ler_oipl_dflt_cd;
9101       FETCH c_ler_oipl_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl, l_ler_dflt_flag;
9102                                     --p_ler_dflt_flag; 3510229
9103       CLOSE c_ler_oipl_dflt_cd;
9104       if
9105 			-- l_dflt_enrt_cd 3510229
9106 			l_ler_dflt_flag is not null then
9107         p_level:='LER_OIPL';
9108         p_ler_dflt_flag := l_ler_dflt_flag; -- 3510229
9109         l_ler_dflt_flag := null ; --3510229
9110       end if;
9111       --
9112       IF l_dflt_enrt_cd IS NULL THEN
9113         --
9114         -- 2
9115         --
9116         hr_utility.set_location('In the case 2 ' , 100);
9117         --
9118         --l_dflt_enrt_cd :=  ben_cobj_cache.g_oipl_currow.dflt_enrt_cd;
9119         --l_dflt_enrt_rl :=  ben_cobj_cache.g_oipl_currow.dflt_enrt_det_rl;
9120         --
9121         l_dflt_enrt_cd := p_oipl_rec.dflt_enrt_cd ;
9122         l_dflt_enrt_rl := p_oipl_rec.dflt_enrt_det_rl ;
9123 
9124         --hr_utility.set_location(' p_oipl_rec.oipl_id '||p_oipl_rec.oipl_id ,110);
9125         --hr_utility.set_location(' p_oipl_rec.dflt_enrt_cd '||p_oipl_rec.dflt_enrt_cd ,110);
9126         --hr_utility.set_location(' p_oipl_rec.dflt_flag '||p_oipl_rec.dflt_flag, 110)  ;
9127         --
9128       if l_dflt_enrt_cd is not null
9129          and p_level is null then -- 3510229
9130         p_level:='OIPL';
9131       end if;
9132       --
9133       END IF;
9134     END IF;
9135 
9136     IF     p_pgm_id IS NULL
9137        AND l_dflt_enrt_cd IS NULL THEN
9138       --
9139       -- 3
9140       --
9141       OPEN c_ler_pl_nip_dflt_cd;
9142       FETCH c_ler_pl_nip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl,l_ler_dflt_flag; --3510229
9143                                     --p_ler_dflt_flag;
9144       CLOSE c_ler_pl_nip_dflt_cd;
9145       if l_dflt_enrt_cd is not null
9146          and p_level is null then -- 3510229
9147         p_level:='LER_PL_NIP';
9148         -- 3510229 start
9149         -- there could be default flag without default code , so this s moved down - 	4008380
9150         --if p_ler_dflt_flag is null then
9151         --  p_ler_dflt_flag := l_ler_dflt_flag;
9152         --end if;
9153         --l_ler_dflt_flag := null ;
9154         hr_utility.set_location('after LER pNip chk p_ler_dflt_flag:  '||p_ler_dflt_flag , 100);
9155         -- 3510229 end
9156 
9157       end if;
9158       -- there could be default flag without default code 4008380
9159       if p_ler_dflt_flag is null and l_ler_dflt_flag is not null  then
9160           p_ler_dflt_flag := l_ler_dflt_flag ;
9161       end if ;
9162       hr_utility.set_location('l_ler_dflt_flag ' || l_ler_dflt_flag ,40);
9163       hr_utility.set_location(l_dflt_enrt_cd,40);
9164 
9165 
9166     ELSIF     p_pgm_id IS NOT NULL
9167           AND l_dflt_enrt_cd IS NULL THEN
9168       --
9169       -- 4
9170       --
9171       OPEN c_ler_plip_dflt_cd;
9172       FETCH c_ler_plip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl, l_ler_dflt_flag; --3510229
9173                                     --p_ler_dflt_flag;
9174       CLOSE c_ler_plip_dflt_cd;
9175       if l_dflt_enrt_cd is not null
9176          and p_level is null then -- 3510229
9177         p_level:='LER_PLIP';
9178 
9179         -- 3510229 start
9180         --  4008380
9181         --if p_ler_dflt_flag is null then
9182         --  p_ler_dflt_flag := l_ler_dflt_flag;
9183         --end if;
9184         hr_utility.set_location('after LER PLIP chk p_ler_dflt_flag:  '||p_ler_dflt_flag , 100);
9185         --l_ler_dflt_flag := null ;
9186         -- 3510229 end
9187 
9188       end if;
9189       --  4008380
9190       if p_ler_dflt_flag is null and l_ler_dflt_flag is not null  then
9191           p_ler_dflt_flag := l_ler_dflt_flag ;
9192       end if ;
9193       hr_utility.set_location('l_ler_dflt_flag ' || l_ler_dflt_flag ,50);
9194       hr_utility.set_location(l_dflt_enrt_cd,50);
9195 
9196       --  4008380
9197       --  there could be plip but the setup may be in plan  ler level
9198       IF l_dflt_enrt_cd IS NULL THEN
9199 
9200          OPEN c_ler_pl_nip_dflt_cd;
9201          FETCH c_ler_pl_nip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl,l_ler_dflt_flag;
9202          CLOSE c_ler_pl_nip_dflt_cd;
9203 
9204          if l_dflt_enrt_cd is not null
9205             and p_level is null then -- 3510229
9206             p_level:='LER_PL';
9207             hr_utility.set_location('after LER Plan  chk p_ler_dflt_flag:  '||p_ler_dflt_flag , 100);
9208          end if;
9209          -- there could be default flag without default code 4008380
9210          if p_ler_dflt_flag is null and l_ler_dflt_flag is not null  then
9211             p_ler_dflt_flag := l_ler_dflt_flag ;
9212          end if ;
9213          hr_utility.set_location('l_ler_dflt_flag ' || l_ler_dflt_flag ,40);
9214          hr_utility.set_location(l_dflt_enrt_cd,40);
9215       end if ;
9216 
9217 
9218 
9219       --- ptip level
9220       IF l_dflt_enrt_cd IS NULL THEN
9221         --
9222         -- 5
9223         --
9224         OPEN c_ler_ptip_dflt_cd;
9225         FETCH c_ler_ptip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
9226         CLOSE c_ler_ptip_dflt_cd;
9227       if l_dflt_enrt_cd is not null
9228          and p_level is null then -- 3510229
9229         p_level:='LER_PTIP';
9230       end if;
9231         --  hr_utility.set_location(l_dflt_enrt_cd,60);
9232         IF l_dflt_enrt_cd IS NULL THEN
9233           --
9234           -- 6
9235           --
9236           OPEN c_ler_pgm_dflt_cd;
9237           FETCH c_ler_pgm_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
9238           CLOSE c_ler_pgm_dflt_cd;
9239       if l_dflt_enrt_cd is not null
9240          and p_level is null then --3510229
9241         p_level:='LER_PGM';
9242       end if;
9243         END IF;
9244       END IF;
9245     END IF;
9246     --  hr_utility.set_location(l_dflt_enrt_cd,80);
9247     IF     p_pgm_id IS NULL
9248        AND l_dflt_enrt_cd IS NULL THEN
9249       --
9250       -- 7
9251       --
9252       -- Bug 1895874
9253       -- l_dflt_enrt_cd :=  ben_cobj_cache.g_pl_currow.nip_dflt_enrt_cd;
9254       -- l_dflt_enrt_rl :=  ben_cobj_cache.g_pl_currow.nip_dflt_enrt_det_rl;
9255       --
9256       hr_utility.set_location(' p_pl_rec.pl_id '||p_oipl_rec.oipl_id ,110);
9257       hr_utility.set_location(' p_pl_rec.nip_dflt_enrt_cd '||p_pl_rec.nip_dflt_enrt_cd ,110);
9258       hr_utility.set_location(' p_pl_rec.nip_dflt_flag '||p_pl_rec.nip_dflt_flag, 110)  ;
9259       --
9260       l_dflt_enrt_cd := p_pl_rec.nip_dflt_enrt_cd ;
9261       l_dflt_enrt_rl := p_pl_rec.nip_dflt_enrt_det_rl ;
9262       if p_ler_dflt_flag is null then -- 3510229
9263         p_ler_dflt_flag := p_pl_rec.nip_dflt_flag ;
9264       end if;
9265 
9266 /*
9267       OPEN c_pl_nip_dflt_cd;
9268       FETCH c_pl_nip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl,
9269                                     p_ler_dflt_flag;
9270       CLOSE c_pl_nip_dflt_cd;
9271 * /
9272       --
9273       if l_dflt_enrt_cd is not null
9274          and p_level is null then -- 3510229
9275         p_level:='PL';
9276       end if;
9277       --
9278     --  hr_utility.set_location(l_dflt_enrt_cd,90);
9279 
9280     ELSIF     p_pgm_id IS NOT NULL
9281           AND l_dflt_enrt_cd IS NULL THEN
9282       --
9283       -- 8
9284       --
9285       l_dflt_enrt_cd := p_plip_rec.dflt_enrt_cd ;
9286       l_dflt_enrt_rl := p_plip_rec.dflt_enrt_det_rl ;
9287 /*
9288       OPEN c_plip_dflt_cd;
9289       FETCH c_plip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
9290       CLOSE c_plip_dflt_cd;
9291 * /
9292       if l_dflt_enrt_cd is not null
9293          and p_level is null then -- 3510229
9294         p_level:='PLIP';
9295       end if;
9296        hr_utility.set_location(l_dflt_enrt_cd,100);
9297         --
9298       IF l_dflt_enrt_cd IS NULL THEN
9299         --
9300         -- 9
9301         --
9302       l_dflt_enrt_cd := p_ptip_rec.dflt_enrt_cd ;
9303       l_dflt_enrt_rl := p_ptip_rec.dflt_enrt_det_rl ;
9304 /*
9305         OPEN c_ptip_dflt_cd;
9306         FETCH c_ptip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
9307         CLOSE c_ptip_dflt_cd;
9308 * /
9309       if l_dflt_enrt_cd is not null
9310          and p_level is null then -- 3510229
9311         p_level:='PTIP';
9312       end if;
9313       hr_utility.set_location(l_dflt_enrt_cd,110);
9314         --
9315       END IF;
9316     END IF;
9317   --
9318     hr_utility.set_location(' p_pgm_id '||p_pgm_id||' pl_id '||p_pl_id||' oipl '||p_oipl_id||
9319                             ' plip '||p_plip_id||' ptip '||p_ptip_id,130);
9320     hr_utility.set_location('dflt_enrt_cd= '||l_dflt_enrt_cd,130);
9321     hr_utility.set_location('dflt_enrt_rl= '||l_dflt_enrt_rl,140);
9322     hr_utility.set_location('p_ler_dflt_flag= '||p_ler_dflt_flag ,140);
9323     p_dflt_enrt_cd :=  l_dflt_enrt_cd;
9324     p_dflt_enrt_rl :=  l_dflt_enrt_rl;
9325     hr_utility.set_location('Leaving: ' || l_proc, 150);
9326   exception
9327     --
9328     when others then
9329       --
9330       p_dflt_enrt_cd        := null;
9331       p_dflt_enrt_rl        := null;
9332       p_level               := null;
9333       p_ler_dflt_flag       := null;
9334       raise;
9335       --
9336   END;
9337   --
9338 */
9339 
9340   -- Find the required period of enrollment.  Code/rule/value and level.
9341   --
9342 procedure find_rqd_perd_enrt
9343   (p_oipl_id                 in     number
9344   ,p_opt_id                  in     number
9345   ,p_pl_id                   in     number
9346   ,p_ptip_id                 in     number
9347   ,p_effective_date          in     date
9348   ,p_business_group_id       in     number
9349   ,p_rqd_perd_enrt_nenrt_uom    out nocopy varchar2
9350   ,p_rqd_perd_enrt_nenrt_val    out nocopy number
9351   ,p_rqd_perd_enrt_nenrt_rl     out nocopy number
9352   ,p_level                      out nocopy varchar2
9353   )
9354 IS
9355     --
9356     -- THIS SQL STATEMENT HAS BEEN COMMENTED OUT AND REPLACED BY THE IF LOGIC
9357     --
9358     -- get rqd_perd_enrt_nenrt heirarchy
9359     --
9360     CURSOR c_nenrt IS
9361       SELECT   '1',
9362                bo.rqd_perd_enrt_nenrt_uom,
9363                bo.rqd_perd_enrt_nenrt_val,
9364                bo.rqd_perd_enrt_nenrt_rl
9365       FROM     ben_oipl_f bo
9366       WHERE    bo.oipl_id = p_oipl_id
9367       AND      p_effective_date BETWEEN bo.effective_start_date
9368                    AND bo.effective_end_date
9369       AND      bo.business_group_id = p_business_group_id
9370       AND      (
9371                     (
9372                           bo.rqd_perd_enrt_nenrt_uom IS NOT NULL
9373                       AND bo.rqd_perd_enrt_nenrt_val IS NOT NULL)
9374                  OR bo.rqd_perd_enrt_nenrt_rl IS NOT NULL)
9375       UNION ALL
9376       SELECT   '2',
9377                bo.rqd_perd_enrt_nenrt_uom,
9378                bo.rqd_perd_enrt_nenrt_val,
9379                bo.rqd_perd_enrt_nenrt_rl
9380       FROM     ben_opt_f bo
9381       WHERE    bo.opt_id = p_opt_id
9382       AND      p_effective_date BETWEEN bo.effective_start_date
9383                    AND bo.effective_end_date
9384       AND      bo.business_group_id = p_business_group_id
9385       AND      (
9386                     (
9387                           bo.rqd_perd_enrt_nenrt_uom IS NOT NULL
9388                       AND bo.rqd_perd_enrt_nenrt_val IS NOT NULL)
9389                  OR bo.rqd_perd_enrt_nenrt_rl IS NOT NULL)
9390       UNION ALL
9391       SELECT   '3',
9392                bp.rqd_perd_enrt_nenrt_uom,
9393                bp.rqd_perd_enrt_nenrt_val,
9394                bp.rqd_perd_enrt_nenrt_rl
9395       FROM     ben_pl_f bp
9396       WHERE    bp.pl_id = p_pl_id
9397       AND      p_effective_date BETWEEN bp.effective_start_date
9398                    AND bp.effective_end_date
9399       AND      bp.business_group_id = p_business_group_id
9400       AND      (
9401                     (
9402                           bp.rqd_perd_enrt_nenrt_uom IS NOT NULL
9403                       AND bp.rqd_perd_enrt_nenrt_val IS NOT NULL)
9404                  OR bp.rqd_perd_enrt_nenrt_rl IS NOT NULL)
9405       UNION ALL
9406       SELECT   '4',
9407                bp.rqd_perd_enrt_nenrt_tm_uom,
9408                bp.rqd_perd_enrt_nenrt_val,
9409                bp.rqd_perd_enrt_nenrt_rl
9410       FROM     ben_ptip_f bp
9411       WHERE    bp.ptip_id = p_ptip_id
9412       AND      p_effective_date BETWEEN bp.effective_start_date
9413                    AND bp.effective_end_date
9414       AND      bp.business_group_id = p_business_group_id
9415       AND      (
9416                     (
9417                           bp.rqd_perd_enrt_nenrt_tm_uom IS NOT NULL
9418                       AND bp.rqd_perd_enrt_nenrt_val IS NOT NULL)
9419                  OR bp.rqd_perd_enrt_nenrt_rl IS NOT NULL);
9420     l_level varchar2(30);
9421   BEGIN
9422     --
9423     -- Check if context parameters are set. When context parameters are
9424     -- not set then fire cursor
9425     --
9426     if ben_cobj_cache.g_ptip_currow.ptip_id is not null
9427       or ben_cobj_cache.g_pl_currow.pl_id is not null
9428       or ben_cobj_cache.g_opt_currow.opt_id is not null
9429       or ben_cobj_cache.g_oipl_currow.oipl_id is not null
9430     then
9431       --
9432       IF     ben_cobj_cache.g_oipl_currow.oipl_id = p_oipl_id
9433          AND (
9434                   (
9435                         ben_cobj_cache.g_oipl_currow.rqd_perd_enrt_nenrt_uom IS NOT NULL
9436                     AND ben_cobj_cache.g_oipl_currow.rqd_perd_enrt_nenrt_val IS NOT NULL)
9437                OR ben_cobj_cache.g_oipl_currow.rqd_perd_enrt_nenrt_rl IS NOT NULL) THEN
9438         --
9439         p_level                    := 'OIPL';
9440         p_rqd_perd_enrt_nenrt_uom  := ben_cobj_cache.g_oipl_currow.rqd_perd_enrt_nenrt_uom;
9441         p_rqd_perd_enrt_nenrt_val  := ben_cobj_cache.g_oipl_currow.rqd_perd_enrt_nenrt_val;
9442         p_rqd_perd_enrt_nenrt_rl   := ben_cobj_cache.g_oipl_currow.rqd_perd_enrt_nenrt_rl;
9443       ELSIF     ben_cobj_cache.g_opt_currow.opt_id = p_opt_id
9444             AND (
9445                      (
9446                            ben_cobj_cache.g_opt_currow.rqd_perd_enrt_nenrt_uom IS NOT NULL
9447                        AND ben_cobj_cache.g_opt_currow.rqd_perd_enrt_nenrt_val IS NOT NULL)
9448                   OR ben_cobj_cache.g_opt_currow.rqd_perd_enrt_nenrt_rl IS NOT NULL) THEN
9449         --
9450         p_level                    := 'OPT';
9451         p_rqd_perd_enrt_nenrt_uom  := ben_cobj_cache.g_opt_currow.rqd_perd_enrt_nenrt_uom;
9452         p_rqd_perd_enrt_nenrt_val  := ben_cobj_cache.g_opt_currow.rqd_perd_enrt_nenrt_val;
9453         p_rqd_perd_enrt_nenrt_rl   := ben_cobj_cache.g_opt_currow.rqd_perd_enrt_nenrt_rl;
9454       ELSIF     ben_cobj_cache.g_pl_currow.pl_id = p_pl_id
9455             AND (
9456                      (
9457                            ben_cobj_cache.g_pl_currow.rqd_perd_enrt_nenrt_uom IS NOT NULL
9458                        AND ben_cobj_cache.g_pl_currow.rqd_perd_enrt_nenrt_val IS NOT NULL)
9459                   OR ben_cobj_cache.g_pl_currow.rqd_perd_enrt_nenrt_rl IS NOT NULL) THEN
9460         --
9461         p_level                    := 'PL';
9462         p_rqd_perd_enrt_nenrt_uom  := ben_cobj_cache.g_pl_currow.rqd_perd_enrt_nenrt_uom;
9463         p_rqd_perd_enrt_nenrt_val  := ben_cobj_cache.g_pl_currow.rqd_perd_enrt_nenrt_val;
9464         p_rqd_perd_enrt_nenrt_rl   := ben_cobj_cache.g_pl_currow.rqd_perd_enrt_nenrt_rl;
9465       ELSIF     ben_cobj_cache.g_ptip_currow.ptip_id = p_ptip_id
9466             AND (
9467                      (
9468                            ben_cobj_cache.g_ptip_currow.rqd_perd_enrt_nenrt_tm_uom IS NOT NULL
9469                        AND ben_cobj_cache.g_ptip_currow.rqd_perd_enrt_nenrt_val IS NOT NULL)
9470                   OR ben_cobj_cache.g_ptip_currow.rqd_perd_enrt_nenrt_rl IS NOT NULL) THEN
9471         --
9472         p_level                    := 'PTIP';
9473         p_rqd_perd_enrt_nenrt_uom  := ben_cobj_cache.g_ptip_currow.rqd_perd_enrt_nenrt_tm_uom;
9474         p_rqd_perd_enrt_nenrt_val  := ben_cobj_cache.g_ptip_currow.rqd_perd_enrt_nenrt_val;
9475         p_rqd_perd_enrt_nenrt_rl   := ben_cobj_cache.g_ptip_currow.rqd_perd_enrt_nenrt_rl;
9476       END IF;
9477       --
9478     else
9479       --
9480       OPEN c_nenrt;
9481       FETCH c_nenrt INTO l_level,
9482                          p_rqd_perd_enrt_nenrt_uom,
9483                          p_rqd_perd_enrt_nenrt_val,
9484                          p_rqd_perd_enrt_nenrt_rl;
9485       CLOSE c_nenrt;
9486       IF l_level IS NOT NULL THEN
9487         IF l_level = 1 THEN
9488           p_level  := 'OIPL';
9489         ELSIF l_level = 2 THEN
9490           p_level  := 'OPT';
9491         ELSIF l_level = 3 THEN
9492           p_level  := 'PL';
9493         ELSIF l_level = 4 THEN
9494           p_level  := 'PTIP';
9495         END IF;
9496       END IF;
9497       --
9498     end if;
9499     if g_debug then
9500     hr_utility.set_location('level ' ||  p_level , 8086);
9501     end if;
9502     --
9503   exception
9504     --
9505     when others then
9506       --
9507       p_rqd_perd_enrt_nenrt_uom   := null;
9508       p_rqd_perd_enrt_nenrt_val   := null;
9509       p_rqd_perd_enrt_nenrt_rl    := null;
9510       p_level                     := null;
9511       raise;
9512       --
9513   END find_rqd_perd_enrt;
9514 --
9515 -- find an enrollment at the give level.
9516 --
9517   PROCEDURE find_enrt_at_same_level(
9518     p_person_id         IN     NUMBER,
9519     p_opt_id            IN     NUMBER,
9520     p_oipl_id           IN     NUMBER,
9521     p_pl_id             IN     NUMBER,
9522     p_ptip_id           IN     NUMBER,
9523     p_pl_typ_id         IN     NUMBER,
9524     p_pgm_id            IN     NUMBER,
9525     p_effective_date    IN     DATE,
9526     p_business_group_id IN     NUMBER,
9527     p_prtt_enrt_rslt_id IN     NUMBER,
9528     p_level             IN     VARCHAR2,
9529     p_pen_rec           OUT NOCOPY    ben_prtt_enrt_rslt_f%ROWTYPE) IS
9530     --
9531     l_effective_date_1 DATE := p_effective_date - 1;
9532     --
9533     -- Gets the enrolment information for the ptip
9534     --
9535     -- Notes:
9536     --   <> pen_id checks are for enrollment time use not bendenrr use
9537     -- bug : 1620162 ig the send even the option saved then replaces with other option
9538     -- the chek l_effective_date_1 <= pen.enrt_cvg_thru_dt became true
9539     -- so changed to l_effective_date_1 < pen.enrt_cvg_thru_dt
9540     CURSOR c_ptip_enrolment_info IS
9541       SELECT   *
9542       FROM     ben_prtt_enrt_rslt_f pen
9543       WHERE    pen.person_id = p_person_id
9544       AND      pen.business_group_id = p_business_group_id
9545       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
9546       AND      pen.sspndd_flag = 'N'
9547       AND      pen.effective_end_date = hr_api.g_eot
9548       AND      l_effective_date_1 < pen.enrt_cvg_thru_dt
9549       AND      pen.prtt_enrt_rslt_id <> p_prtt_enrt_rslt_id
9550       AND      (
9551                     (    pen.pgm_id = p_pgm_id
9552                      AND p_pgm_id IS NOT NULL)
9553                  OR (    pen.pgm_id IS NULL
9554                      AND p_pgm_id IS NOT NULL))
9555       AND      pen.comp_lvl_cd NOT IN ('PLANFC', 'PLANIMP')
9556       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
9557       AND      pen.ptip_id = p_ptip_id;
9558     --
9559     -- Gets the enrolment information for the oipl
9560     --
9561     CURSOR c_oipl_enrolment_info IS
9562       SELECT   *
9563       FROM     ben_prtt_enrt_rslt_f pen
9564       WHERE    pen.person_id = p_person_id
9565       AND      pen.business_group_id = p_business_group_id
9566       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
9567 --      AND      pen.sspndd_flag = 'N' --CFW
9568       AND      pen.effective_end_date = hr_api.g_eot
9569       AND      l_effective_date_1 < pen.enrt_cvg_thru_dt
9570       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
9571       AND      pen.prtt_enrt_rslt_id <> p_prtt_enrt_rslt_id
9572       AND      (
9573                     (    pen.pgm_id = p_pgm_id
9574                      AND p_pgm_id IS NOT NULL)
9575                  OR (    pen.pgm_id IS NULL
9576                      AND p_pgm_id IS NOT NULL))
9577       AND      pen.comp_lvl_cd NOT IN ('PLANFC', 'PLANIMP')
9578       AND      pen.oipl_id = p_oipl_id;
9579     --
9580     -- Gets the enrolment information for the pl
9581     --
9582     CURSOR c_pl_enrolment_info IS
9583       SELECT   *
9584       FROM     ben_prtt_enrt_rslt_f pen
9585       WHERE    pen.person_id = p_person_id
9586       AND      pen.business_group_id = p_business_group_id
9587       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
9588       AND      pen.sspndd_flag = 'N'
9589       AND      pen.effective_end_date = hr_api.g_eot
9590       AND      l_effective_date_1 < pen.enrt_cvg_thru_dt
9591       AND      (pen.erlst_deenrt_dt IS NULL
9592                 OR  (     pen.erlst_deenrt_dt IS NOT NULL
9593                      AND  pen.enrt_cvg_thru_dt > pen.erlst_deenrt_dt))
9594       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
9595       AND      pen.prtt_enrt_rslt_id <> p_prtt_enrt_rslt_id
9596       AND      (
9597                     (    pen.pgm_id = p_pgm_id
9598                      AND p_pgm_id IS NOT NULL)
9599                  OR (    pen.pgm_id IS NULL
9600                      AND p_pgm_id IS NOT NULL))
9601       AND      pen.comp_lvl_cd NOT IN ('PLANFC', 'PLANIMP')
9602       AND      pen.pl_id = p_pl_id;
9603     --
9604     -- Gets the enrolment information for the opt
9605     --
9606     CURSOR c_opt_enrolment_info IS
9607       SELECT   pen.*
9608       FROM     ben_prtt_enrt_rslt_f pen, ben_pl_f pl, ben_oipl_f oipl
9609       WHERE    pen.person_id = p_person_id
9610       AND      pen.business_group_id = p_business_group_id
9611       AND      pen.effective_end_date = hr_api.g_eot
9612       AND      l_effective_date_1 BETWEEN pen.enrt_cvg_strt_dt
9613                AND pen.enrt_cvg_thru_dt
9614       AND      pl.pl_id = pen.pl_id
9615       and      pen.oipl_id  = p_oipl_id       /* bug 1527086 */
9616       AND      pl.business_group_id = p_business_group_id
9617       AND      pl.pl_typ_id = p_pl_typ_id
9618       AND      oipl.pl_id = pl.pl_id
9619       AND      oipl.opt_id = p_opt_id
9620       AND      p_effective_date BETWEEN pl.effective_start_date
9621                    AND pl.effective_end_date
9622       AND      p_effective_date BETWEEN oipl.effective_start_date
9623                    AND oipl.effective_end_date
9624       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
9625       AND      pen.sspndd_flag = 'N'
9626       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
9627       AND      oipl.business_group_id = p_business_group_id
9628       AND      pen.prtt_enrt_rslt_id <> p_prtt_enrt_rslt_id
9629       AND      (
9630                     (    pen.pgm_id = p_pgm_id
9631                      AND p_pgm_id IS NOT NULL)
9632                  OR (    pen.pgm_id IS NULL
9633                      AND p_pgm_id IS NOT NULL))
9634       AND      pen.comp_lvl_cd NOT IN ('PLANFC', 'PLANIMP');
9635 
9636 
9637 
9638   BEGIN
9639     IF p_level = 'PL' THEN
9640       OPEN c_pl_enrolment_info;
9641       FETCH c_pl_enrolment_info INTO p_pen_rec;
9642       CLOSE c_pl_enrolment_info;
9643     ELSIF p_level = 'OPT' THEN
9644       OPEN c_opt_enrolment_info;
9645       FETCH c_opt_enrolment_info INTO p_pen_rec;
9646       CLOSE c_opt_enrolment_info;
9647     ELSIF p_level = 'OIPL' THEN
9648       OPEN c_oipl_enrolment_info;
9649       FETCH c_oipl_enrolment_info INTO p_pen_rec;
9650       CLOSE c_oipl_enrolment_info;
9651     ELSIF p_level = 'PTIP' THEN
9652       OPEN c_ptip_enrolment_info;
9653       FETCH c_ptip_enrolment_info INTO p_pen_rec;
9654       CLOSE c_ptip_enrolment_info;
9655     END IF;
9656   exception
9657     --
9658     when others then
9659       --
9660       p_pen_rec := null;
9661       raise;
9662       --
9663   END find_enrt_at_same_level;
9664 --
9665 procedure update_defaults
9666   (p_run_mode               in     varchar2
9667   ,p_business_group_id      in     number
9668   ,p_effective_date         in     date
9669   ,p_lf_evt_ocrd_dt         in     date default null
9670   ,p_ler_id                 in     number
9671   ,p_person_id              in     number
9672   ,p_per_in_ler_id          in     number
9673   )
9674 IS
9675   --
9676   l_oipl_id_va       benutils.g_number_table := benutils.g_number_table();
9677   l_pl_id_va         benutils.g_number_table := benutils.g_number_table();
9678   l_pgm_id_va        benutils.g_number_table := benutils.g_number_table();
9679   l_ptip_id_va       benutils.g_number_table := benutils.g_number_table();
9680   l_plip_id_va       benutils.g_number_table := benutils.g_number_table();
9681   l_epe_dflt_flag_va benutils.g_v2_30_table := benutils.g_v2_30_table();
9682   l_ELCTBL_FLAG_va   benutils.g_v2_30_table := benutils.g_v2_30_table();
9683   l_epe_id_va        benutils.g_number_table := benutils.g_number_table();
9684   l_epe_ovn_va       benutils.g_number_table := benutils.g_number_table();
9685   --
9686   l_prevepo_rec      ben_derive_part_and_rate_facts.g_cache_structure;
9687   l_prevpep_rec      ben_derive_part_and_rate_facts.g_cache_structure;
9688   --
9689   l_rec_assignment_id number;
9690   l_rec_organization_id number;
9691   l_dflt_flag      varchar2(30);
9692   l_use_dflt_flag  varchar2(30);
9693   l_oipl_rec ben_oipl_f%rowtype;
9694   l_empty_oipl ben_oipl_f%rowtype;
9695   l_plan_rec ben_pl_f%rowtype;
9696   l_pgm_rec  ben_pgm_f%rowtype;
9697   l_empty_pgm  ben_pgm_f%rowtype;
9698   l_plip_rec  ben_plip_f%rowtype;
9699   l_empty_plip  ben_plip_f%rowtype;
9700   l_ptip_rec  ben_ptip_f%rowtype;
9701   l_empty_ptip  ben_ptip_f%rowtype;
9702   l_use_dflt_enrt_cd varchar2(30);
9703   l_use_dflt_enrt_rl varchar2(30);
9704   l_reinstt_flag varchar2(30);
9705   l_dflt_level varchar2(30);
9706   l_lf_evt_ocrd_dt date;
9707   l_lf_evt_ocrd_dt_1 date;
9708   l_effective_date_1 date;
9709   l_ler_dflt_flag varchar2(30):=null;
9710   l_proc         VARCHAR2(80)       := g_package || '.update_defaults';
9711   --
9712   -- Choice population
9713   --   Auto enrollments are never defaulted.
9714   --
9715   cursor c_choices
9716     (c_lf_evt_ocrd_dt date
9717     ,c_per_in_ler_id  number
9718     )
9719   is
9720   select epe.oipl_id,
9721          epe.pl_id,
9722          epe.pgm_id,
9723          epe.ptip_id,
9724          epe.plip_id,
9725          epe.dflt_flag,
9726          epe.ELCTBL_FLAG,
9727          epe.ELIG_PER_ELCTBL_CHC_ID,
9728          epe.OBJECT_VERSION_NUMBER
9729   from   ben_elig_per_elctbl_chc epe,
9730 /*
9731          ben_per_in_ler pil,
9732 */
9733          ben_pl_f pln
9734   where  epe.auto_enrt_flag = 'N'
9735   and    epe.per_in_ler_id  = c_per_in_ler_id
9736 /*
9737     and  pil.person_id = p_person_id
9738     and  pil.per_in_ler_id = epe.per_in_ler_id
9739     and  pil.per_in_ler_stat_cd = 'STRTD'
9740 */
9741     and  pln.pl_id=epe.pl_id
9742     and  c_lf_evt_ocrd_dt
9743       between pln.effective_start_date and pln.effective_end_date
9744     and  nvl(pln.imptd_incm_calc_cd,'x') NOT IN ('PRTT', 'DPNT', 'SPS')
9745     and  invk_flx_cr_pl_flag='N'
9746     and  (epe.oipl_id is not null or
9747           not exists
9748             (select null
9749              from   ben_oipl_f oipl
9750              where  c_lf_evt_ocrd_dt
9751                between oipl.effective_start_date and oipl.effective_end_date
9752              and oipl.pl_id=epe.pl_id
9753             )
9754          );
9755   --
9756   -- Gets all information on the plip which is needed
9757   --
9758   CURSOR c_plip_info(p_pl_id number,p_pgm_id number) IS
9759       SELECT   bpf.dflt_flag
9760       FROM     ben_plip_f bpf
9761       WHERE    bpf.pl_id = p_pl_id
9762       AND      bpf.pgm_id = p_pgm_id
9763       AND      bpf.business_group_id = p_business_group_id
9764       AND      l_lf_evt_ocrd_dt BETWEEN bpf.effective_start_date
9765                    AND bpf.effective_end_date;
9766   CURSOR c_asg IS
9767       SELECT   asg.assignment_id,
9768                asg.organization_id
9769       FROM     per_all_assignments_f asg
9770       WHERE    asg.person_id = p_person_id
9771       and      asg.assignment_type <> 'C'
9772       AND      asg.primary_flag =  decode(p_run_mode, 'I',asg.primary_flag,'Y')  -- iRec
9773       AND      l_lf_evt_ocrd_dt BETWEEN asg.effective_start_date
9774                    AND asg.effective_end_date
9775   ;
9776   l_new_elctbl_flag              VARCHAR2(30)                 := 'Y';
9777   l_tco_chg_enrt_cd              VARCHAR2(30)                 := 'CPOO';
9778   l_previous_eligibility         VARCHAR2(30);
9779   l_pl_enrt_cd                   VARCHAR2(30);
9780   l_crnt_enrt_cvg_strt_dt        DATE;
9781   l_ler_enrt_prclds_chg_flag     VARCHAR2(30);
9782   l_ler_stl_elig_cant_chg_flag   VARCHAR2(30);
9783   l_pl_enrt_rl                   NUMBER;
9784   l_dpnt_cvrd_flag               VARCHAR2(1)                  := 'N';
9785   l_crnt_erlst_deenrt_dt         date;
9786   l_prtt_enrt_rslt_id            number;
9787   l_enrt_ovridn_flag             varchar2(30);
9788   l_enrt_ovrid_thru_dt           date;
9789   l_ler_chg_found_flag           varchar2(30);
9790   l_ler_chg_oipl_found_flag      varchar2(30);
9791   --
9792   l_ler_enrt_cd                  varchar2(30);
9793   l_ler_enrt_rl                  number;
9794   l_ler_auto_enrt_rl             number;
9795   l_ler_enrt_mthd_cd             varchar2(30);
9796   l_oipl_auto_enrt_flag          varchar2(30);
9797   l_pl_enrt_mthd_cd              varchar2(30);
9798   l_pl_auto_enrt_rl              number;
9799   --
9800   l_oipl_id                      number;
9801   l_pl_id                        number;
9802   l_pgm_id                       number;
9803   l_ptip_id                      number;
9804   l_plip_id                      number;
9805   l_epe_dflt_flag                varchar2(30);
9806   l_ELCTBL_FLAG                  varchar2(30);
9807   l_epe_id                       number;
9808   l_epe_ovn                      number;
9809   --
9810     -- Gets the enrolment information for this plan
9811     --
9812     --
9813     CURSOR c_plan_enrolment_info IS
9814       SELECT   pen.enrt_cvg_strt_dt,
9815                pen.erlst_deenrt_dt,
9816                pen.prtt_enrt_rslt_id,
9817                pen.enrt_ovridn_flag,
9818                pen.enrt_ovrid_thru_dt
9819       FROM     ben_prtt_enrt_rslt_f pen
9820       WHERE    pen.person_id = p_person_id
9821       AND      pen.business_group_id = p_business_group_id
9822 --      AND      pen.sspndd_flag = 'N' --CFW
9823       AND      (pen.sspndd_flag = 'N' --CFW
9824                  OR (pen.sspndd_flag = 'Y' and
9825                      pen.enrt_cvg_thru_dt = hr_api.g_eot
9826                     )
9827                )
9828       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
9829       AND      pen.effective_end_date = hr_api.g_eot
9830       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
9831       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
9832       AND      l_plan_rec.pl_id = pen.pl_id
9833       AND      (
9834                     (    pen.pgm_id = l_pgm_rec.pgm_id
9835                      AND l_pgm_rec.pgm_id IS NOT NULL)
9836                  OR (    pen.pgm_id IS NULL
9837                      AND l_pgm_rec.pgm_id IS NULL));
9838     --
9839     -- Gets the enrolment information for this oipl
9840     --
9841     --
9842     CURSOR c_oipl_enrolment_info IS
9843       SELECT   pen.enrt_cvg_strt_dt,
9844                pen.erlst_deenrt_dt,
9845                pen.prtt_enrt_rslt_id,
9846                pen.enrt_ovridn_flag,
9847                pen.enrt_ovrid_thru_dt
9848       FROM     ben_prtt_enrt_rslt_f pen
9849       WHERE    pen.person_id = p_person_id
9850       AND      pen.business_group_id = p_business_group_id
9851 --      AND      pen.sspndd_flag = 'N' --CFW
9852       AND      (pen.sspndd_flag = 'N' --CFW
9853                  OR (pen.sspndd_flag = 'Y' and
9854                      pen.enrt_cvg_thru_dt = hr_api.g_eot
9855                     )
9856                )
9857       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
9858       AND      pen.effective_end_date = hr_api.g_eot
9859       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
9860       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
9861       AND      l_oipl_rec.oipl_id = pen.oipl_id
9862       AND      (
9863                     (    pen.pgm_id = l_pgm_rec.pgm_id
9864                      AND l_pgm_rec.pgm_id IS NOT NULL)
9865                  OR (    pen.pgm_id IS NULL
9866                      AND l_pgm_rec.pgm_id IS NULL));
9867     --
9868     -- Gets the coverage information for this plan
9869     --
9870     --
9871     CURSOR c_plan_cvg_info IS
9872       SELECT   'Y'
9873       FROM     ben_prtt_enrt_rslt_f pen, ben_elig_cvrd_dpnt_f pdp
9874       WHERE    pdp.dpnt_person_id = p_person_id
9875       AND      pdp.effective_end_date = hr_api.g_eot
9876       AND      l_lf_evt_ocrd_dt_1 BETWEEN pdp.cvg_strt_dt AND pdp.cvg_thru_dt
9877       AND      pdp.business_group_id = p_business_group_id
9878       AND      pdp.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
9879       AND      pen.business_group_id = p_business_group_id
9880       AND      pen.sspndd_flag = 'N'
9881       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
9882       AND      pen.effective_end_date = hr_api.g_eot
9883       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
9884       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
9885       AND      l_plan_rec.pl_id = pen.pl_id
9886       AND      (
9887                     (    pen.pgm_id = l_pgm_rec.pgm_id
9888                      AND l_pgm_rec.pgm_id IS NOT NULL)
9889                  OR (    pen.pgm_id IS NULL
9890                      AND l_pgm_rec.pgm_id IS NULL));
9891     --
9892     -- Gets the coverage information for this oipl
9893     --
9894     --
9895     CURSOR c_oipl_cvg_info IS
9896       SELECT   'Y'
9897       FROM     ben_prtt_enrt_rslt_f pen, ben_elig_cvrd_dpnt_f pdp
9898       WHERE    pdp.dpnt_person_id = p_person_id
9899       AND      pdp.effective_end_date = hr_api.g_eot
9900       AND      l_lf_evt_ocrd_dt_1 BETWEEN pdp.cvg_strt_dt AND pdp.cvg_thru_dt
9901       AND      pdp.business_group_id = p_business_group_id
9902       AND      pdp.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
9903       AND      pen.business_group_id = p_business_group_id
9904 --      AND      pen.sspndd_flag = 'N'
9905       AND      (pen.sspndd_flag = 'N' --CFW
9906                  OR (pen.sspndd_flag = 'Y' and
9907                      pen.enrt_cvg_thru_dt = hr_api.g_eot
9908                     )
9909                )
9910       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
9911       AND      pen.effective_end_date = hr_api.g_eot
9912       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
9913       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
9914       AND      l_oipl_rec.oipl_id = pen.oipl_id
9915       AND      (
9916                     (    pen.pgm_id = l_pgm_rec.pgm_id
9917                      AND l_pgm_rec.pgm_id IS NOT NULL)
9918                  OR (    pen.pgm_id IS NULL
9919                      AND l_pgm_rec.pgm_id IS NULL));
9920     -- Determines the previous eligibility for an option
9921     --
9922     CURSOR c_previous_elig_for_option IS
9923       SELECT   epo.elig_flag
9924       FROM     ben_elig_per_f ep, ben_elig_per_opt_f epo, ben_per_in_ler pil
9925       WHERE    ep.person_id = p_person_id
9926       AND      ep.pl_id = l_plan_rec.pl_id
9927       AND      (
9928                     (    ep.pgm_id = l_pgm_rec.pgm_id
9929                      AND l_pgm_rec.pgm_id IS NOT NULL)
9930                  OR (    ep.pgm_id IS NULL
9931                      AND l_pgm_rec.pgm_id IS NULL))
9932       AND      ep.business_group_id = p_business_group_id
9933       AND      p_effective_date - 1 BETWEEN ep.effective_start_date
9934                    AND ep.effective_end_date
9935       AND      ep.elig_per_id = epo.elig_per_id
9936       AND      epo.opt_id = l_oipl_rec.opt_id
9937       AND      epo.business_group_id = p_business_group_id
9938       AND      l_effective_date_1 BETWEEN epo.effective_start_date
9939                    AND epo.effective_end_date
9940       AND      pil.per_in_ler_id (+) = epo.per_in_ler_id
9941       AND      pil.business_group_id (+) = epo.business_group_id
9942       AND      (
9943                     pil.per_in_ler_stat_cd NOT IN
9944                                         (
9945                                           'VOIDD',
9946                                           'BCKDT')       -- found row condition
9947                  OR pil.per_in_ler_stat_cd IS NULL);    -- outer join condition
9948     -- Determines the previous eligibility for a plan
9949     --
9950     CURSOR c_previous_elig_for_plan IS
9951       SELECT   pep.elig_flag
9952       FROM     ben_elig_per_f pep, ben_per_in_ler pil
9953       WHERE    pep.person_id = p_person_id
9954       AND      pep.pl_id = l_plan_rec.pl_id
9955       AND      (
9956                     (    pep.pgm_id = l_pgm_rec.pgm_id
9957                      AND l_pgm_rec.pgm_id IS NOT NULL)
9958                  OR (    pep.pgm_id IS NULL
9959                      AND l_pgm_rec.pgm_id IS NULL))
9960       AND      pep.business_group_id = p_business_group_id
9961       AND      l_effective_date_1 BETWEEN pep.effective_start_date
9962                    AND pep.effective_end_date
9963       AND      pil.per_in_ler_id (+) = pep.per_in_ler_id
9964       AND      pil.business_group_id (+) = pep.business_group_id
9965       AND      (
9966                     pil.per_in_ler_stat_cd NOT IN
9967                                         (
9968                                           'VOIDD',
9969                                           'BCKDT')       -- found row condition
9970                  OR pil.per_in_ler_stat_cd IS NULL);    -- outer join condition
9971   --
9972   cursor c_enrt_bnft (p_elctbl_chc_id number) is
9973     select enb.enrt_bnft_id,
9974            enb.object_version_number
9975     from   ben_enrt_bnft enb
9976     where  enb.elig_per_elctbl_chc_id = p_elctbl_chc_id
9977     and    enb.dflt_flag = 'N'
9978     and    (exists  (select null from
9979                     ben_enrt_bnft enb2
9980                     where enb2.enrt_bnft_id = enb.enrt_bnft_id
9981                     and   enb2.dflt_val = enb2.val)
9982            or enb.cvg_mlt_cd not in ('FLRNG', 'CLRNG','FLPCLRNG','CLPFLRNG'));
9983   l_enrt_bnft    c_enrt_bnft%rowtype;
9984   l_enrt_cd_level varchar2(30) ;
9985   -- 5092244
9986   CURSOR c_elig_dpnt (v_epe_id NUMBER)
9987    IS
9988       SELECT egd.elig_dpnt_id, egd.object_version_number
9989         FROM ben_elig_dpnt egd, ben_per_in_ler pil
9990        WHERE elig_per_elctbl_chc_id = v_epe_id
9991          AND pil.per_in_ler_id = egd.per_in_ler_id
9992          AND pil.per_in_ler_stat_cd = 'STRTD';
9993 
9994    l_elig_dpnt   c_elig_dpnt%ROWTYPE;
9995    l_next_row    NUMBER;
9996    /*Start AMN Bug 14653541: Commenting the below fixes
9997    --Start AMN Bug 14661357
9998    CURSOR c_ler_oipl_dflt_flag IS
9999     SELECT   leo.dflt_flag
10000     FROM     ben_ler_chg_oipl_enrt_f leo
10001     WHERE    l_oipl_id = leo.oipl_id
10002     AND      p_ler_id = leo.ler_id
10003     AND      p_effective_date BETWEEN leo.effective_start_date
10004                  AND leo.effective_end_date;
10005    l_ler_oipl_dflt_flag varchar2(30);
10006    --End AMN Bug 14661357
10007    End AMN Bug 14653541: Commenting the below fixes*/
10008   --
10009 begin
10010   --
10011   g_debug := hr_utility.debug_enabled;
10012   --
10013 if g_debug then
10014   hr_utility.set_location('Entering: '||l_proc,10);
10015   end if;
10016   --l_effective_date_1:=p_effective_date-1;
10017   --Bug#2328029
10018   l_effective_date_1:=
10019            least(p_effective_date, nvl(p_lf_evt_ocrd_dt,p_effective_date)) -1;
10020   --
10021   if p_lf_evt_ocrd_dt is not null then
10022     l_lf_evt_ocrd_dt:=p_lf_evt_ocrd_dt;
10023   else
10024     l_lf_evt_ocrd_dt:=p_effective_date;
10025   end if;
10026   l_lf_evt_ocrd_dt_1:=l_lf_evt_ocrd_dt-1;
10027   --
10028   open c_choices
10029     (c_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt
10030     ,c_per_in_ler_id  => p_per_in_ler_id
10031     );
10032   fetch c_choices BULK COLLECT INTO l_oipl_id_va,
10033                                     l_pl_id_va,
10034                                     l_pgm_id_va,
10035                                     l_ptip_id_va,
10036                                     l_plip_id_va,
10037                                     l_epe_dflt_flag_va,
10038                                     l_ELCTBL_FLAG_va,
10039                                     l_epe_id_va,
10040                                     l_epe_ovn_va;
10041   close c_choices;
10042   --
10043   if l_epe_id_va.count > 0 then
10044     --
10045     for epeele_num in l_epe_id_va.first..l_epe_id_va.last
10046     loop
10047       --
10048       l_oipl_id        := l_oipl_id_va(epeele_num);
10049       l_pl_id          := l_pl_id_va(epeele_num);
10050       l_pgm_id         := l_pgm_id_va(epeele_num);
10051       l_ptip_id        := l_ptip_id_va(epeele_num);
10052       l_plip_id        := l_plip_id_va(epeele_num);
10053       l_epe_dflt_flag  := l_epe_dflt_flag_va(epeele_num);
10054       l_ELCTBL_FLAG    := l_ELCTBL_FLAG_va(epeele_num);
10055       l_epe_id         := l_epe_id_va(epeele_num);
10056       l_epe_ovn        := l_epe_ovn_va(epeele_num);
10057       --
10058 /*
10059   for l_rec in c_choices
10060     (c_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt
10061     ,c_per_in_ler_id  => p_per_in_ler_id
10062     )
10063   loop
10064 */
10065     if g_debug then
10066       hr_utility.set_location(l_proc||' ST c_choices loop: ',10);
10067     end if;
10068       --
10069       -- init flags
10070       --
10071       l_dflt_flag:='N';
10072       l_use_dflt_flag:='N';
10073       --
10074       -- Get option information if an oipl_id is passed,
10075       -- need to do this before getting oipl eligibility.
10076       --
10077       IF (l_oipl_id IS NOT NULL) THEN
10078         --
10079         -- get oipl information
10080         --
10081         ben_comp_object.get_object(p_oipl_id => l_oipl_id, p_rec =>l_oipl_rec);
10082         l_oipl_auto_enrt_flag:=l_oipl_rec.auto_enrt_flag;
10083       else
10084         l_oipl_rec:=l_empty_oipl;
10085       end if;
10086       --
10087       -- get plan cache row
10088       --
10089       ben_comp_object.get_object(p_pl_id => l_pl_id, p_rec => l_plan_rec);
10090       l_pl_enrt_mthd_cd :=          l_plan_rec.enrt_mthd_cd;
10091       l_pl_auto_enrt_rl :=          l_plan_rec.auto_enrt_mthd_rl;
10092       --
10093       -- Get pgm cache row if needed
10094       --
10095       IF l_pgm_id IS NOT NULL THEN
10096         ben_comp_object.get_object(p_pgm_id => l_pgm_id, p_rec => l_pgm_rec);
10097       else
10098         l_pgm_rec:=l_empty_pgm;
10099       END IF;
10100       --
10101       -- Get ptip cache row if needed
10102       --
10103       IF l_ptip_id IS NOT NULL THEN
10104         ben_comp_object.get_object(p_ptip_id => l_ptip_id,
10105                                    p_rec => l_ptip_rec);
10106       else
10107         l_ptip_rec:=l_empty_ptip;
10108       END IF;
10109       --
10110       -- Get plip cache row if needed
10111       --
10112       IF l_pgm_id IS NOT NULL THEN
10113         ben_comp_object.get_object(p_plip_id => l_plip_id,
10114                                    p_rec => l_plip_rec);
10115       else
10116         l_plip_rec:=l_empty_plip;
10117       END IF;
10118       --
10119       -- get the dflt_enrt_cd/rule
10120       --
10121       if g_debug then
10122       hr_utility.set_location('DDEC: '||l_proc,10);
10123       end if;
10124       determine_dflt_enrt_cd
10125         (p_oipl_id           => l_oipl_id
10126         ,p_oipl_rec          => l_oipl_rec
10127         ,p_plip_id           => l_plip_id
10128         ,p_plip_rec          => l_plip_rec
10129         ,p_pl_id             => l_pl_id
10130         ,p_pl_rec            => l_plan_rec
10131         ,p_ptip_id           => l_ptip_id
10132         ,p_ptip_rec          => l_ptip_rec
10133         ,p_pgm_id            => l_pgm_id
10134         ,p_pgm_rec           => l_pgm_rec
10135         ,p_ler_id            => p_ler_id
10136         ,p_dflt_enrt_cd      => l_use_dflt_enrt_cd
10137         ,p_dflt_enrt_rl      => l_use_dflt_enrt_rl
10138         ,p_business_group_id => p_business_group_id
10139         ,p_effective_date    => l_lf_evt_ocrd_dt -- Bug 2404008 p_effective_date
10140         ,p_level             => l_dflt_level
10141         ,p_ler_dflt_flag     => l_ler_dflt_flag
10142       );
10143       --hr_utility.set_location('After call to determine_dflt_enrt_cd ' , 5553);
10144       --hr_utility.set_location('l_pgm_id '||l_pgm_id,5554);
10145       if g_debug then
10146       hr_utility.set_location('l_oipl_id '||l_oipl_id ,5555);
10147       hr_utility.set_location('l_pl_id '||l_pl_id ,5556);
10148       --hr_utility.set_location('l_dflt_flag='||l_dflt_flag,5557);
10149       hr_utility.set_location('l_ler_dflt_flag '||l_ler_dflt_flag ,5555);
10150       hr_utility.set_location(' l_epe_dflt_flag='|| l_epe_dflt_flag,5558);
10151       hr_utility.set_location(' l_dflt_level ='|| l_dflt_level ,5558);
10152       end if;
10153       --hr_utility.set_location(' ---- ' ,5559);
10154       --
10155       -- Set the values for the dflt_flag
10156       --
10157       --
10158       l_use_dflt_flag :=            NULL;
10159       IF l_ler_dflt_flag is not null and
10160          (l_dflt_level='LER_OIPL' or
10161           l_oipl_id is null) then
10162         l_use_dflt_flag:=l_ler_dflt_flag;
10163       end if;
10164       --
10165       -- oipl level default code/flag
10166       --
10167       IF l_oipl_id IS NOT NULL THEN
10168         IF l_use_dflt_flag IS NULL THEN
10169           --
10170           -- use oipl level flag
10171           --
10172           l_use_dflt_flag :=  l_oipl_rec.dflt_flag;
10173         END IF;
10174       END IF;
10175       --
10176       -- plip level default code/flag
10177       --
10178       IF l_plip_id IS NOT NULL THEN
10179         IF l_use_dflt_flag IS NULL THEN
10180           --
10181           -- Find the plip and get its needed attributes.
10182           --
10183           OPEN c_plip_info(l_pl_id,l_pgm_id);
10184           --
10185           FETCH c_plip_info INTO l_use_dflt_flag;
10186           IF c_plip_info%NOTFOUND THEN
10187             --
10188             fnd_message.set_name('BEN', 'BEN_91461_PLIP_MISSING');
10189             fnd_message.set_token('PROC', l_proc);
10190             fnd_message.set_token('PGM_ID', TO_CHAR(l_pgm_id));
10191             fnd_message.set_token('PL_ID', TO_CHAR(l_pl_id));
10192             fnd_message.set_token('BG_ID', TO_CHAR(p_business_group_id));
10193             RAISE ben_manage_life_events.g_record_error;
10194           --
10195           END IF;
10196           --
10197           CLOSE c_plip_info;
10198         END IF;
10199       END IF;
10200       --
10201       -- If no default flag is set then make it not a default.
10202       --
10203       IF l_use_dflt_flag IS NULL THEN
10204         --
10205         l_use_dflt_flag :=  'N';
10206       --
10207       END IF;
10208       OPEN c_asg;
10209       FETCH c_asg INTO l_rec_assignment_id, l_rec_organization_id;
10210       IF c_asg%NOTFOUND THEN
10211           CLOSE c_asg;
10212 	  if g_debug then
10213           hr_utility.set_location('error', 20);
10214 	  end if;
10215           fnd_message.set_name('BEN', 'BEN_92106_PRTT_NO_ASGN');
10216           fnd_message.set_token('PROC', l_proc);
10217           fnd_message.set_token('PERSON_ID', TO_CHAR(p_person_id));
10218           fnd_message.set_token('LF_EVT_OCRD_DT', TO_CHAR(p_lf_evt_ocrd_dt));
10219           fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
10220           RAISE ben_manage_life_events.g_record_error;
10221       END IF;
10222       CLOSE c_asg;
10223       --hr_utility.set_location('Before call to l_use_dflt_flag ',5550);
10224       if g_debug then
10225       hr_utility.set_location(' l_use_dflt_flag ',5550);
10226       hr_utility.set_location(' l_use_dflt_enrt_cd ',5550);
10227       end if;
10228       determine_dflt_flag(
10229          l_use_dflt_flag,
10230          l_use_dflt_enrt_cd,
10231          null, --not used
10232          null, --not used
10233          l_use_dflt_enrt_rl,
10234          l_oipl_id,
10235          l_pl_id,
10236          l_pgm_id,
10237          p_effective_date,
10238          p_lf_evt_ocrd_dt,
10239          p_ler_id,
10240          l_oipl_rec.opt_id,
10241          l_plan_rec.pl_typ_id,
10242          l_ptip_id,
10243          p_person_id,
10244          p_business_group_id,
10245          l_rec_assignment_id,
10246          l_dflt_flag,
10247          l_reinstt_flag,
10248 	 -- added bug 5644451
10249 	 l_dflt_level,
10250 	 p_run_mode           /* iRec : Added p_run_mode */
10251       );
10252       --
10253       if g_debug then
10254       hr_utility.set_location(' l_dflt_flag '|| l_dflt_flag ,5550);
10255       hr_utility.set_location(' l_dflt_level '|| l_dflt_level ,5550);--AMN Bug 14661357
10256       end if;
10257       /*Start AMN Bug 14653541: Commenting the below fixes
10258       --Bug# 12621882 For a Comp.object After the rule evalutes the default enrolment flag,
10259       --              if l_dflt_flag = 'Y' then it checks again at the oipl level.
10260       --              Means option which is set as default at oipl level should only be defaulted.
10261 
10262       --ud changes start
10263       hr_utility.set_location(' l_use_dflt_enrt_cd   ' ||  l_use_dflt_enrt_cd , 10);
10264 
10265       IF l_use_dflt_enrt_cd ='RL' then
10266 
10267           hr_utility.set_location(' l_use_dflt_enrt_cd   ' ||  l_use_dflt_enrt_cd , 10);
10268           hr_utility.set_location(' l_oipl_id   ' ||  l_oipl_id , 10);
10269 
10270           IF l_dflt_flag = 'Y' and l_oipl_id IS NOT NULL and l_dflt_level not in ('LER_OIPL','OIPL') then --AMN Bug 14661357
10271 
10272              hr_utility.set_location(' l_oipl_id   ' ||  l_oipl_id , 10);
10273              hr_utility.set_location(' l_oipl_rec.dflt_flag   ' ||  l_oipl_rec.dflt_flag , 10);
10274              --Start AMN Bug 14661357
10275              open c_ler_oipl_dflt_flag;
10276              fetch c_ler_oipl_dflt_flag into l_ler_oipl_dflt_flag;
10277              if c_ler_oipl_dflt_flag%notfound then
10278               l_ler_oipl_dflt_flag := l_oipl_rec.dflt_flag;
10279              end if;
10280              close c_ler_oipl_dflt_flag;
10281              hr_utility.set_location(' l_ler_oipl_dflt_flag   ' ||  l_ler_oipl_dflt_flag , 10);
10282              --Start AMN Bug 14661357
10283 
10284 	     If l_ler_oipl_dflt_flag = 'N' then --AMN Bug 14661357
10285                  l_dflt_flag := 'N';
10286                  hr_utility.set_location('l_dflt_flag ' || l_dflt_flag, 40);
10287 
10288              end if;
10289           end if;
10290       end if;
10291     --
10292     --ud changes end
10293     -- Bug# 12621882
10294     End AMN Bug 14653541*/
10295       IF (l_dflt_flag = 'DEFER') THEN
10296         --
10297         l_dflt_flag :=  l_use_dflt_flag;
10298       --
10299       END IF;
10300       --hr_utility.set_location('After call to determine_dflt_flag ' , 5553);
10301       --hr_utility.set_location('l_pgm_id '||l_pgm_id,5554);
10302       --hr_utility.set_location('l_oipl_id '||l_oipl_id ,5555);
10303       if g_debug then
10304       hr_utility.set_location('l_pl_id '||l_pl_id ,5556);
10305       hr_utility.set_location('l_dflt_flag='||l_dflt_flag,5557);
10306       hr_utility.set_location(' l_epe_dflt_flag='|| l_epe_dflt_flag,5558);
10307       end if;
10308       --
10309       -- Done with default flag now see if electable flag should be changed
10310       --
10311       -- Determine if the person is currently enrolled and if so
10312       -- determine the coverage start date.
10313       --
10314       if ( l_ELCTBL_FLAG='Y') then
10315         IF (l_oipl_id IS NULL) THEN
10316           --
10317           OPEN c_plan_enrolment_info;
10318           --
10319           FETCH c_plan_enrolment_info INTO l_crnt_enrt_cvg_strt_dt,
10320                                            l_crnt_erlst_deenrt_dt,
10321                                            l_prtt_enrt_rslt_id,
10322                                            l_enrt_ovridn_flag,
10323                                            l_enrt_ovrid_thru_dt;
10324           --
10325           IF c_plan_enrolment_info%NOTFOUND THEN
10326             --
10327             l_crnt_enrt_cvg_strt_dt :=  NULL;
10328             --
10329             --  Check if person is a covered dependent - COBRA.
10330             --
10331             IF l_pgm_id IS NOT NULL THEN
10332               IF l_pgm_rec.pgm_typ_cd LIKE 'COBRA%' THEN
10333                 OPEN c_plan_cvg_info;
10334                 FETCH c_plan_cvg_info INTO l_dpnt_cvrd_flag;
10335                 CLOSE c_plan_cvg_info;
10336               END IF;
10337             END IF;
10338           --
10339           END IF;
10340           --
10341           CLOSE c_plan_enrolment_info;
10342 	  if g_debug then
10343           hr_utility.set_location('close c_PEI: ' || l_proc, 10);
10344 	  end if;
10345         --
10346         ELSE
10347           --
10348           OPEN c_oipl_enrolment_info;
10349           --
10350           FETCH c_oipl_enrolment_info INTO l_crnt_enrt_cvg_strt_dt,
10351                                            l_crnt_erlst_deenrt_dt,
10352                                            l_prtt_enrt_rslt_id,
10353                                            l_enrt_ovridn_flag,
10354                                            l_enrt_ovrid_thru_dt;
10355           --
10356           IF c_oipl_enrolment_info%NOTFOUND THEN
10357             --
10358             l_crnt_enrt_cvg_strt_dt :=  NULL;
10359             --
10360             --  Check if person is a covered dependent - COBRA.
10361             --
10362             IF l_pgm_id IS NOT NULL THEN
10363               IF l_pgm_rec.pgm_typ_cd LIKE 'COBRA%' THEN
10364                 OPEN c_oipl_cvg_info;
10365                 FETCH c_oipl_cvg_info INTO l_dpnt_cvrd_flag;
10366                 CLOSE c_oipl_cvg_info;
10367               END IF;
10368             END IF;
10369           --
10370           END IF;
10371           --
10372           CLOSE c_oipl_enrolment_info;
10373 	  if g_debug then
10374           hr_utility.set_location('close c_OIEI: ' || l_proc, 10);
10375 	  end if;
10376         --
10377         END IF;
10378 	if g_debug then
10379         hr_utility.set_location('determine prev elig', 10);
10380 	end if;
10381         --
10382         -- Bug 2677804 We need to see the override case here.
10383         IF ( l_enrt_ovridn_flag = 'Y' AND l_enrt_ovrid_thru_dt >= l_lf_evt_ocrd_dt)  THEN
10384            l_enrt_ovridn_flag :=  'Y';
10385         ELSE
10386            l_enrt_ovridn_flag :=  'N';
10387         END IF;
10388         --
10389         -- Determine if the person was previously eligible for this comp object.
10390         --
10391         IF (l_oipl_id IS NULL) THEN
10392           --
10393           ben_pep_cache.get_pilpep_dets
10394             (p_person_id         => p_person_id
10395             ,p_business_group_id => p_business_group_id
10396             ,p_effective_date    => l_effective_date_1
10397             ,p_pgm_id            => l_pgm_rec.pgm_id
10398             ,p_pl_id             => l_plan_rec.pl_id
10399             ,p_plip_id           => null
10400             ,p_ptip_id           => null
10401             ,p_inst_row          => l_prevpep_rec
10402             );
10403           --
10404           if l_prevpep_rec.elig_flag is null
10405           then
10406             --
10407             l_previous_eligibility := 'N';
10408             --
10409           else
10410             --
10411             l_previous_eligibility := l_prevpep_rec.elig_flag;
10412             --
10413           end if;
10414           --
10415 	  if g_debug then
10416           hr_utility.set_location('close c_PEFP: ' || l_proc, 10);
10417 	  end if;
10418         --
10419         ELSE
10420           --
10421           ben_pep_cache.get_pilepo_dets
10422             (p_person_id         => p_person_id
10423             ,p_business_group_id => p_business_group_id
10424             ,p_effective_date    => l_effective_date_1 --p_effective_date
10425             ,p_pgm_id            => l_pgm_rec.pgm_id
10426             ,p_pl_id             => l_plan_rec.pl_id
10427             ,p_opt_id            => l_oipl_rec.opt_id
10428             --
10429             ,p_inst_row          => l_prevepo_rec
10430             );
10431           --
10432           if l_prevepo_rec.elig_flag is null
10433           then
10434             --
10435             l_previous_eligibility := 'N';
10436             --
10437           else
10438             --
10439             l_previous_eligibility := l_prevepo_rec.elig_flag;
10440             --
10441           end if;
10442           --
10443 	  if g_debug then
10444           hr_utility.set_location('close c_PEFO: ' || l_proc, 10);
10445 	  end if;
10446           --
10447         END IF;
10448         l_pl_enrt_cd :=               l_plan_rec.enrt_cd;
10449         l_pl_enrt_rl :=               l_plan_rec.enrt_rl;
10450         --
10451         -- Determine if the compensation object requires or allows
10452         -- an election change If life event mode
10453         --
10454 	if g_debug then
10455         hr_utility.set_location('ler change stuff', 20);
10456 	end if;
10457         l_ler_chg_found_flag :=       'N';
10458         l_ler_chg_oipl_found_flag :=  'N';
10459         --
10460         -- See if there is a life event reason to change
10461         --
10462 	if g_debug then
10463         hr_utility.set_location('ler change stuff not null stuff', 20);
10464         hr_utility.set_location(' Op c_lce_info: ' || l_proc, 10);
10465 	end if;
10466         --
10467         determine_ben_settings(
10468           p_pl_id                     => l_pl_id,
10469           p_ler_id                    => p_ler_id,
10470           p_lf_evt_ocrd_dt            => l_lf_evt_ocrd_dt,
10471           p_ptip_id                   => l_ptip_id,
10472           p_pgm_id                    => l_pgm_id,
10473           p_plip_id                   => l_plip_id,
10474           p_oipl_id                   => l_oipl_id,
10475           p_just_prclds_chg_flag      => FALSE,
10476           p_enrt_cd                   => l_ler_enrt_cd,
10477           p_enrt_rl                   => l_ler_enrt_rl,
10478           p_auto_enrt_mthd_rl         => l_ler_auto_enrt_rl,
10479           p_crnt_enrt_prclds_chg_flag => l_ler_enrt_prclds_chg_flag,
10480           p_dflt_flag                 => l_ler_dflt_flag,
10481           p_enrt_mthd_cd              => l_ler_enrt_mthd_cd,
10482           p_stl_elig_cant_chg_flag    => l_ler_stl_elig_cant_chg_flag,
10483           p_tco_chg_enrt_cd           => l_tco_chg_enrt_cd,
10484           p_ler_chg_oipl_found_flag   => l_ler_chg_oipl_found_flag,
10485           p_ler_chg_found_flag        => l_ler_chg_found_flag,
10486           p_enrt_cd_level             => l_enrt_cd_level);
10487       if g_debug then
10488         hr_utility.set_location(' Cl c_lce_info: ' || l_proc, 10);
10489       end if;
10490         --
10491         -- Determine enrt codes/rules method codes/rules then
10492         -- figure out if electable.
10493         --
10494         -- Initially set to ler_chg values if not null
10495         --
10496         IF l_ler_enrt_cd IS NOT NULL THEN
10497           l_pl_enrt_cd :=  l_ler_enrt_cd;
10498           l_pl_enrt_rl :=  l_ler_enrt_rl;
10499         ELSIF l_oipl_rec.enrt_cd IS NOT NULL THEN
10500           l_pl_enrt_cd :=  l_oipl_rec.enrt_cd;
10501           l_pl_enrt_rl :=  l_oipl_rec.enrt_rl;
10502         END IF;
10503         IF l_oipl_id IS NULL THEN
10504           IF    l_ler_enrt_mthd_cd IS NOT NULL
10505              OR l_ler_auto_enrt_rl IS NOT NULL THEN
10506             l_pl_enrt_mthd_cd :=  l_ler_enrt_mthd_cd;
10507             l_pl_auto_enrt_rl :=  l_ler_auto_enrt_rl;
10508           END IF;
10509         ELSE
10510           --
10511           -- below, if ler_chg row found then code will always
10512           -- be not null since comes from a decode of the flag.
10513           --
10514           IF l_ler_chg_oipl_found_flag = 'Y' THEN
10515             l_pl_enrt_mthd_cd :=  l_ler_enrt_mthd_cd;
10516             l_pl_auto_enrt_rl :=  l_ler_auto_enrt_rl;
10517             --
10518             IF l_ler_enrt_mthd_cd = 'A' THEN
10519               --
10520               l_oipl_auto_enrt_flag :=  'Y';
10521             --
10522             ELSE
10523               --
10524               l_oipl_auto_enrt_flag :=  'N';
10525             --
10526             END IF;
10527           --
10528           ELSE
10529             IF l_oipl_auto_enrt_flag = 'Y' THEN
10530               l_pl_enrt_mthd_cd :=  'A';
10531             ELSE
10532               l_pl_enrt_mthd_cd :=  'E';
10533             END IF;
10534             l_pl_auto_enrt_rl :=  l_oipl_rec.auto_enrt_mthd_rl;
10535           END IF;
10536         END IF;
10537         --
10538         -- If the ler_chg values were null then now have plan values
10539         --
10540         -- Update if still null with values from above in hierarchy
10541         --
10542         IF     l_pl_enrt_cd IS NULL
10543            AND l_pgm_id IS NOT NULL THEN
10544           l_pl_enrt_cd :=  l_plip_rec.enrt_cd;
10545           l_pl_enrt_rl :=  l_plip_rec.enrt_rl;
10546         END IF;
10547         IF     l_pl_enrt_mthd_cd IS NULL
10548            AND l_pgm_id IS NOT NULL THEN
10549           l_pl_enrt_mthd_cd :=  l_plip_rec.enrt_mthd_cd;
10550           l_pl_auto_enrt_rl :=  l_plip_rec.auto_enrt_mthd_rl;
10551         END IF;
10552         --
10553         -- overlay ptip if value is still null
10554         --
10555         IF     l_pl_enrt_cd IS NULL
10556            AND l_pgm_id IS NOT NULL THEN
10557           l_pl_enrt_cd :=  l_ptip_rec.enrt_cd;
10558           l_pl_enrt_rl :=  l_ptip_rec.enrt_rl;
10559         END IF;
10560         IF     l_pl_enrt_mthd_cd IS NULL
10561            AND l_pgm_id IS NOT NULL THEN
10562           l_pl_enrt_mthd_cd :=  l_ptip_rec.enrt_mthd_cd;
10563           l_pl_auto_enrt_rl :=  l_ptip_rec.auto_enrt_mthd_rl;
10564         END IF;
10565         --
10566         -- get from program level if not at plan or plip or ptip levels
10567         --
10568         IF     l_pl_enrt_cd IS NULL
10569            AND l_pgm_id IS NOT NULL THEN
10570           l_pl_enrt_cd :=  l_pgm_rec.enrt_cd;
10571           l_pl_enrt_rl :=  l_pgm_rec.enrt_rl;
10572         END IF;
10573         IF     l_pl_enrt_mthd_cd IS NULL
10574            AND l_pgm_id IS NOT NULL THEN
10575           l_pl_enrt_mthd_cd :=  l_pgm_rec.enrt_mthd_cd;
10576           l_pl_auto_enrt_rl :=  l_pgm_rec.auto_enrt_mthd_rl;
10577         END IF;
10578 
10579         g_ptip_id :=                  l_ptip_id;
10580   --  hr_utility.set_location('l_previous_eligibility='||l_previous_eligibility,1064);
10581   --  hr_utility.set_location('l_crnt_enrt_cvg_strt_dt='||l_crnt_enrt_cvg_strt_dt,1064);
10582   --  hr_utility.set_location('l_dpnt_cvrd_flag='||l_dpnt_cvrd_flag,1064);
10583   --  hr_utility.set_location('p_person_id='||p_person_id,1064);
10584   --  hr_utility.set_location('p_ler_id='||p_ler_id,1064);
10585   --  hr_utility.set_location('l_pl_enrt_cd='||l_pl_enrt_cd,1064);
10586   --  hr_utility.set_location('l_pl_enrt_rl='||l_pl_enrt_rl,1064);
10587   --  hr_utility.set_location('p_effective_date='||p_effective_date,1064);
10588   --  hr_utility.set_location('p_lf_evt_ocrd_dt='||p_lf_evt_ocrd_dt,1064);
10589   --  hr_utility.set_location('l_ler_enrt_prclds_chg_flag='||l_ler_enrt_prclds_chg_flag,1064);
10590   --  hr_utility.set_location('l_ler_stl_elig_cant_chg_flag='||l_ler_stl_elig_cant_chg_flag,1064);
10591   --  hr_utility.set_location('l_tco_chg_enrt_cd='||l_tco_chg_enrt_cd,1064);
10592   --  hr_utility.set_location('l_pl_id='||l_pl_id,1064);
10593   --  hr_utility.set_location('l_pgm_id='||l_pgm_id,1064);
10594   --  hr_utility.set_location('l_oipl_id='||l_oipl_id,1064);
10595   --  hr_utility.set_location('l_oipl_rec.opt_id='||l_oipl_rec.opt_id,1064);
10596   --  hr_utility.set_location('l_plan_rec.pl_typ_id='||l_plan_rec.pl_typ_id,1064);
10597   --  hr_utility.set_location('p_business_group_id='||p_business_group_id,1064);
10598   --  hr_utility.set_location('l_new_elctbl_flag='||l_new_elctbl_flag,1064);
10599   --  hr_utility.set_location('l_rec_assignment_id='||l_rec_assignment_id,1064);
10600   --      hr_utility.set_location('l_previous_eligibility='||l_previous_eligibility,1064);
10601        if g_debug then
10602         hr_utility.set_location(' Dn Det 1: ' || l_proc, 10);
10603        end if;
10604         -- Bug 2677804
10605         if l_enrt_ovridn_flag = 'Y' then
10606           --
10607 	  if g_debug then
10608           hr_utility.set_location(' Electable Due to Override ' ,123);
10609 	  end if;
10610           l_new_elctbl_flag := 'Y' ;
10611           --
10612         else
10613           -- start 5092244
10614 
10615           IF NVL (l_pl_enrt_cd, '-1') = 'RL'
10616           THEN
10617              ben_determine_dpnt_eligibility.g_egd_table.DELETE;
10618              ben_determine_dpnt_eligibility.g_egd_table :=
10619 			      ben_determine_dpnt_eligibility.g_egd_table_temp;
10620              OPEN c_elig_dpnt (l_epe_id);
10621 	     if g_debug then
10622              hr_utility.set_location('SS Populating g_egd_table',9909);
10623 	     end if;
10624              LOOP
10625 	        FETCH c_elig_dpnt INTO l_elig_dpnt;
10626 	        EXIT WHEN c_elig_dpnt%NOTFOUND;
10627 	        l_next_row :=
10628 		             NVL (ben_determine_dpnt_eligibility.g_egd_table.LAST, 0)
10629 		            + 1;
10630 	        ben_determine_dpnt_eligibility.g_egd_table (l_next_row).object_version_number :=
10631 					        l_elig_dpnt.object_version_number;
10632 	        ben_determine_dpnt_eligibility.g_egd_table (l_next_row).elig_dpnt_id :=
10633 						      l_elig_dpnt.elig_dpnt_id;
10634              END LOOP;
10635 
10636              CLOSE c_elig_dpnt;
10637          END IF;
10638          -- end 5092244
10639           determine_enrolment(
10640             p_previous_eligibility   => l_previous_eligibility,
10641             p_crnt_enrt_cvg_strt_dt  => l_crnt_enrt_cvg_strt_dt,
10642             p_dpnt_cvrd_flag         => l_dpnt_cvrd_flag,
10643             p_person_id              => p_person_id,
10644             p_ler_id                 => p_ler_id,
10645             p_enrt_cd                => l_pl_enrt_cd,
10646             p_enrt_rl                => l_pl_enrt_rl,
10647             p_enrt_mthd_cd           => null,
10648             p_auto_enrt_mthd_rl      => null,
10649             p_effective_date         => p_effective_date,
10650             p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
10651             p_enrt_prclds_chg_flag   => NVL(l_ler_enrt_prclds_chg_flag, 'N'),
10652             p_stl_elig_cant_chg_flag => NVL(l_ler_stl_elig_cant_chg_flag, 'N'),
10653             p_tco_chg_enrt_cd        => NVL(l_tco_chg_enrt_cd, 'CPOO'),
10654             p_pl_id                  => l_pl_id,
10655             p_pgm_id                 => l_pgm_id,
10656             p_oipl_id                => l_oipl_id,
10657             p_opt_id                 => l_oipl_rec.opt_id,
10658             p_pl_typ_id              => l_plan_rec.pl_typ_id,
10659             p_business_group_id      => p_business_group_id,
10660             p_electable_flag         => l_new_elctbl_flag,
10661             p_assignment_id          => l_rec_assignment_id,
10662 	    p_run_mode               => p_run_mode,            /* iRec : Added p_run_mode */
10663             p_update_def_elct_flag   => l_ELCTBL_FLAG -- 5092244 : this parameter is no longer needed.
10664           );
10665         end if ;
10666         --
10667 	if g_debug then
10668         hr_utility.set_location(' Dn Det Enr 1: ' || l_proc, 10);
10669 	end if;
10670         IF l_new_elctbl_flag = 'Y' THEN
10671           --
10672           -- continue
10673           --
10674           NULL;
10675         --
10676         ELSIF l_new_elctbl_flag = 'L' THEN
10677           --
10678           -- Lose only condition.
10679           -- If enrolled will deenroll.
10680           --
10681           ben_newly_ineligible.main(
10682             p_person_id         => p_person_id,
10683             p_pgm_id            => l_pgm_id,
10684             p_pl_id             => l_pl_id,
10685             p_oipl_id           => l_oipl_id,
10686             p_business_group_id => p_business_group_id,
10687             p_ler_id            => p_ler_id,
10688             p_effective_date    => p_effective_date);
10689         if g_debug then
10690           hr_utility.set_location(' BNI_MN 1: ' || l_proc, 10);
10691         end if;
10692           l_new_elctbl_flag :=  'N';
10693         end if;
10694       else
10695         l_new_elctbl_flag:='N';
10696       end if;
10697     if g_debug then
10698       hr_utility.set_location(' Bef dflt flag chk: ' || l_proc, 10);
10699     end if;
10700   --    hr_utility.set_location('l_new_elctbl_flag='||l_new_elctbl_flag,1064);
10701       --
10702       -- update the choice if it needs it.
10703       --
10704     if g_debug then
10705       hr_utility.set_location('Dflt flag is '|| l_epe_dflt_flag,2121);
10706       hr_utility.set_location('l_dflt_flag is '||l_dflt_flag,2121);
10707     end if;
10708       if l_dflt_flag<> l_epe_dflt_flag or
10709          l_new_elctbl_flag <>  l_ELCTBL_FLAG then
10710   --      hr_utility.set_location('Dflt flag changed to '||l_dflt_flag,2121);
10711   --      hr_utility.set_location('Elct flag changed to '||l_new_elctbl_flag,2121);
10712   --      hr_utility.set_location('l_pl_id='||l_pl_id,2121);
10713   --      hr_utility.set_location('l_oipl_id='||l_oipl_id,2121);
10714         IF p_ler_id IS NOT NULL and
10715            l_new_elctbl_flag = 'Y' and
10716             l_ELCTBL_FLAG = 'N' THEN
10717           g_electable_choice_created :=  TRUE;
10718         END IF;
10719 	if g_debug then
10720         hr_utility.set_location(' BEPECA_UEPEC 1: ' || l_proc, 10);
10721 	end if;
10722         ben_elig_per_elc_chc_api.update_perf_elig_per_elc_chc
10723           (p_elig_per_elctbl_chc_id  => l_epe_id,
10724            p_dflt_flag               => l_dflt_flag,
10725            p_elctbl_flag             => l_new_elctbl_flag,
10726            p_object_version_number   => l_epe_ovn,
10727            p_effective_date          => p_effective_date,
10728            p_program_application_id  => fnd_global.prog_appl_id,
10729            p_program_id              => fnd_global.conc_program_id,
10730            p_request_id              => fnd_global.conc_request_id,
10731            p_program_update_date     => sysdate
10732         );
10733 	if g_debug then
10734         hr_utility.set_location(' Dn BEPECA_UEPEC 1: ' || l_proc, 10);
10735 	end if;
10736         --
10737         --bug#3726552 - update the default flag on benefit row
10738         l_enrt_bnft.enrt_bnft_id  := null;
10739         open c_enrt_bnft(l_epe_id);
10740         fetch c_enrt_bnft into l_enrt_bnft;
10741         close c_enrt_bnft;
10742         if l_enrt_bnft.enrt_bnft_id is not null then
10743           --
10744           ben_enrt_bnft_api.update_enrt_bnft
10745             (p_enrt_bnft_id      => l_enrt_bnft.enrt_bnft_id
10746             ,p_dflt_flag         => 'Y'
10747             ,p_object_version_number => l_enrt_bnft.object_version_number
10748             ,p_effective_date        => p_effective_date);
10749         end if;
10750         --
10751       end if;
10752       if g_debug then
10753       hr_utility.set_location(l_proc||' End c_choices loop: ',10);
10754       end if;
10755     end loop;
10756     --
10757   end if;
10758   if g_debug then
10759   hr_utility.set_location('Leaving: '||l_proc,10);
10760   end if;
10761 END update_defaults;
10762 -- end of package, below
10763 END ben_enrolment_requirements;