DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_ELECTION_INFORMATION

Source


1 package body ben_election_information as
2 /* $Header: benelinf.pkb 120.43.12010000.3 2008/09/02 14:23:45 bachakra 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 Election Information
13 Purpose
14         This process creates or updates the participant's record with
15         information about plans and options elected.  This process
16         determines the effective date of new elections.  The enrollment
17         coverage end date for comp objects de-enrolled is in a later
18         function.
19 History
20      Date          Who          Version   What?
21      ----          ---          -------   -----
22      20 Apr 98     jcarpent     110.0     Created
23      06 Jun 98     jcarpent     110.1     Added call to manage_enrt_bnft
24      08 Jun 98     jcarpent     110.2     added busines group id to manage_enrt
25                                           _bnft
26      10 Jun 98     jcarpent     115.1     changed prtt_rt_val eff date to real
27                                           eff dt
28      11 Jun 98     jcarpent     115.2     On comp object ch do create then
29                                           delete enrt When delete use effective
30                                           _dt-1 for correctin
31      15 Jun 98     jcarpent     115.3     Added p_validate flag.
32                                           When delete use ed-1 for update not
33                                           correct. Make rt_strt_dt and cvg_strt
34                                           _dt required.
35      18 Jun 98     jcarpent     115.4     Added business group to everything
36                                           Changed out nocopy parameters
37      23 Jun 98     jcarpent     115.5     Check status code for per_in_ler.
38      08 Jul 98     Jmohapat     115.6     added batch who columns to api
39                                           calls(ben_prtt_enrt_result_api.
40                                           create/update_enrollment,
41                                           ben_enrt_bnft_api. updateenrt_bnft
42      24 Jul 98     jcarpent     115.7     Fixed message removed fnd_message.get
43      28 Jul 98     jcarpent     115.8     Added flex fields.
44      22 SEP 98     GPERRY       115.9     Corrected error messages
45      25 SEP 98     bbulusu      115.10    Added out nocopy parameters (warnings) at
46                                           end of election_information and in
47                                           the call to ben_ prtt_enrt_rslt_api.
48                                           create_enrollment
49      12 Oct 98     jcarpent     115.11    model changes to prv and pen
50      19 Oct 98     jcarpent     115.12    Moved rate start date calculation.
51      22 Oct 98     jcarpent     115.13    Handle SAAEAR cvg_mlt_cd
52                                           Update csd if bnft_amt changes.
53                                           Keep old orgnl_enrt_dt if plan stays
54                                           same
55      26 Oct 98     jcarpent     115.14    Updated prv to non-datetracked
56      27 Oct 98     jcarpent     115.15    Changed election_rate_information
57      29 Oct 98     jcarpent     115.16    Fixed calls to ben_prtt_rt_val_api.
58                                           Don't compare old elctns made date
59      29 Oct 98     stee         115.17    Get rt_typ_cd and rt_mlt_cd from
60                                           enrt_rt.
61      31 Oct 98     bbulusu      115.18    Added per_in_ler_d to delet_enrolment
62      04 Nov 98     jcarpent     115.19    Call annual_to_period/period_to_anual
63                                           Pass different OVN to create_enrt
64      05 Nov 98     jcarpent     115.20    Use prv_id from enrt_rt not one
65                                           passed
66      01 Dec 98     jcarpent     115.21    Made p_ovn optional (get it if null)
67      10 Dec 98     stee         115.22    Fixed bnf warning.
68      15 Dec 98     jcarpent     115.23    Added call to Create_debit_ledger..
69      31 Dec 98     lmcdonal     115.24    Better debug messages.
70      12 Jan 98     maagrawa     115.25    Modified calls to
71                                           ben_prtt_rt_val_api. (Column
72                                           acty_base_rt_id added to
73                                           table ben_prtt_rt_val).
74      01 Feb 99     jcarpent     115.26    Changed calls to update prv to use
75                                           ended_per_in_ler_id.
76      24 Feb 99     jcarpent     115.27    Changed rate cursor in ele_rt_info
77                                           to include union to join to choice
78      03 Mar 99     yrathman     115.28    Added bnft_ordr_num logic
79      04 Mar 99     jcarpent     115.29    Don't end old enrollment if it is
80                                           the interim enrollment.
81      24 Mar 99     jcarpent     115.31    Always call manage_enrt_bnft.
82                                           Delete/end date rate on bnft_amt chg
83      29 Mar 99     thayden      115.32    Added call to ben_ext_chlg.
84      05 Apr 99     mhoyes       115.33    Un-datetrack per_in_ler_f changes.
85      06 May 99     jcarpent     115.34    Write new prv if suspended
86      19 May 99     lmcdonal     115.35    Overloaded election_information to chg
87                                           which save point to set and rollback.
88                                           Because create_enrollment was also
89                                           changed, changed the call.
90      04 Jun 99     lmcdonal     115.36    Added loading of result.comp_lvl_cd
91      11 Jun 99     jcarpent     115.37    Fixed messages.
92      09 Jul 99     jcarpent     115.38    Added checks for backed out nocopy pil
93      20 Jul 99     jcarpent     115.39    New result for bnft amt change.
94      12 Aug 99     gperry       115.40    Added ben_env_object call for cases
95                                           when the process is being called
96                                           from forms. This makes all the
97                                           caching work correctly.
98      12 Aug 99     GPERRY       115.41    Backported 115.38 to add environment
99                                           package call.
100      24 Aug 99     GPERRY       115.42    Version 115.40 brought to top.
101      30 Aug 99     shdas        115.43    Added ordr_num columns to create_enrollment.
102      14 Sep 99     shdas        115.44    changed election_information to add bnft_val
103      29 Sep 99     jcarpent     115.45    If pen_id is null get from choice.
104      12 Oct 99     shdas        115.46    changed election information.
105      12-Nov-1999   jcarpent     115.47    Added enrt_bnft/choice globals
106      12-Nov-1999   jcarpent     115.48    Null out nocopy globals after calls.
107      12-Nov-1999   lmcdonal     115.49    Better debugging messages
108      17-Nov-1999   pbodla       115.50    l_acty_base_rt_id as passed to
109                                           ben_determine_date.rate_and_coverage_dates
110                                           ,ben_determine_date.main
111                                           which is used as context for rules.
112 
113      19-Nov-1999   pbodla       115.51    elig_per_elctbl_chc_id  passed to
114                                           benutils.formula.
115      29-Nov-1999   jcarpent     115.52  - Write new prv most of the time in
116                                           order to fix element entries.
117                                           bug 3556
118                                         - Write new enrollment result if bnft
119                                           amount changed, put back in because
120                                           removed in version 115.46.
121                                         - Added lee_rsn/enrt_perd to del_enrt.
122      14-Dec-1999   jcarpent     115.53  - Removed 'STRTD' restriction on pil.
123      16-Dec-1999   jcarpent     115.54  - Recompute cvg date if bnft amt chg
124      03-Jan-2000   lmcdonal     115.55    Bug 1121022. Do not re-calc rt-strt-dt
125                                           if a prtt-rt-val row exists.
126      20-Jan-2000   maagrawa     115.56   Pass payroll_id to ben_distribute_rates
127      21-Jan-2000   lmcdonal     115.57    If the rate is mult-of-cvg and cvg
128                                           can be entered at enrt, re-calc rate.
129                                           Bug 1118016.
130      25-Jan-2000   maagrawa     115.58    Pass per_in_ler_id to
131                                           create_debit_ledger_entry.
132      27-Jan-2000   thayden      115.59    New parameters for change event log.
133      02-Feb-2000   jcarpent     115.60    Remove l_effective_date adjustment.
134      24-Feb-2000   maagrawa     115.61    Re-open the rate only if the new
135                                           rate start date is before the old
136                                           rate end date.
137      26-Feb-2000   maagrawa     115.62    Added two parameters dpnt_actn_warning
138                                           and bnf_actn_warning to the procedure
139                                           update_enrollment.(1211553)
140      15-Mar-2000   shdas        115.63    Added parameters p_old_pl_id,p_old_oipl_id,
141                                           p_old_bnft_amt to log_benefit_chg(create portion)
142                                           for extract( bug 1187479).
143      20-Mar-2000   shdas        115.64    call create_debit_ledger_entry if result
144                                           is not suspndd(1217192).
145      23-Mar-2000  lmcdonal      115.65    Bug 1247110 - When calling update_
146                                           enrollment, pass eot as cvg_thru_dt.
147      30-Mar-2000  maagrawa      115.66    Re-use the enrollment result, if it
148                                           exists, when the choice is marked as
149                                           currently enrolled. (4875).
150      05-Apr-00  lmcdonal        115.67    Bug 1253007.  Using globals for epe, pil,
151                                           pel, pen, enb, asg data for performance.
152      06-Apr-2000  mmogel        115.68    Added tokens to message calls to make
153                                           the messages more meaningful
154      07-Apr-00  lmcdonal        115.69    Call 'clear_enb' procedure.
155      13-Apr-00  jcarpent        115.70    Call clear_enb cache procedure at end
156                                           and refetch after pen_api is called
157                                           to handle recursive calls.
158      13-Apr-00  lmcdonal        115.71    Change globals to locals
159      04-May-00  shdas           115.72    added parameters p_use_balance_flag
160                                           ,p_enrt_rt_id to period_to_annual and
161                                           changed cmplt_yr_flag to "N"(5043)
162      05-may-00  jcarpent        115.73    If form passes in wrong result_id,
163                                           (will somtimes pass in default/not
164                                           currently enrolled) use value from
165                                           epe.  (5073)
166      19-may-00  shdas           115.74    Always calculate period_to_annual.
167      22-May-00  lmcdonal        115.75    update enb globals right before call
168                                           to manage_enrt_bnft.
169      28-Jun-00  shdas           115.76    Alwayss calculate period to annual with
170                                           complt yr flag = yes.Calculate communicated
171                                           based on periodic value.
172      28-Jun-00  jcarpent        115.77    Bug 4936: Use new cvg_strt_dt if sched
173                                           enrt and plan is for 125 or 129
174                                           regulation.
175      19-Jul-00  rchase          115.78    Bug 5353: bug 5353 - iterim cvg not selecting
176                                           previous cvg if previous cvg exists in same
177                                           pl or pl_typ
178      20-jul-00  kmahendr        115.79    Bug5369 - Not able to save if the same plan is selected
179                                           in a new life event after electing a different plan
180                                           Result ID is assigned only when form is not sending any
181                                           result in election_information procedure
182      15-Aug-00  maagrawa        115.80    Added procedure election_information_w
183                                           (Wrapper for self-service).
184      07-Sep-00  maagrawa        115.81    Modified exception handling for
185                                           self-service wrapper.
186      09-Oct-00  maagrawa        115.82    Added checks for min/max benefit
187                                           amounts in self-service wrapper.
188                                           (1417250).
189      06-Nov-00  tilak           115.83    bug 1480407 when entr at enrl and calculation
190                                           cales the rate calculation for enterd value
191      16-Nov-00  jcarpent        115.84    Bug 1495632.  If no benefit amounts then
192                                           was always creating a new pen.
193      14-Dec-00  maagrawa        115.85    Overloaded the self-service wrapper.
194      15-dec-00  tilak           115.86    bug:1527086 funcation added to calculate the
195                                           erlst_deenrt_dt , this function called wheenever the coverage
196                                           date calcualted and the cvg date differ from cvg dt of ele_chc
197      02-Jan-01  Ikasire         115.87    Bug 1543438 Standart rate entered at enrollment is not
198                       saving inputed rate amount. Added rt_mlt_cd <> 'FLFX' for
199                                           the ben_determine_rate.main calling if condition in
200                                           election_rate_information procedure.
201      05-Jan-01  maagrawa        115.88    Added parameters p_enrt_cvg_strt_dt,
202                                           p_enrt_cvg_thru_dt for Individual
203                                           Compensation to allow user to
204                                           enter the coverage start date and
205                                           coverage through date when the codes
206                                           say they are enterable (ENTRBL).
207      08-Jan-01  maagrawa        115.89    Set the local variable
208                                           l_prtt_enrt_rslt_id to
209                                           l_global_epe_rec.epe.prtt_enrt_rslt_id
210      15-Jan-01  maagrawa        115.90    Modified the self-service wrapper
211                                           to handle multiple rates.
212      16-Jan-01  mhoyes          115.91  - Added calculate only mode parameter
213                                           to election_rate_information.
214      24-Jan-01  tilak           115.92    parent rate calucaltion is fixed
215                                           bug : 1555624
216      09-feb-01  ikasire         115.93    bug 1584238 and 1627373 remove the edit
217                                           checking rate start date always to
218                                           be after the coverage start date
219      09-feb-01  ikasire         115.94    correct the version number
220      23-Feb-01  maagrawa        115.95    Modified the error messages 92394,
221                                           92395 for self-service.
222      06-mar-01  ikasire         115.96    bug 1650517 remove the
223                                           p_complete_year_flag => 'Y' parameter
224                                           for SAREC condition for cmcd_val
225      09-Mar-01  maagrawa        115.97    Added rt_strt_dt and rt_end_dt
226                                           parameters to pass rate dates when
227                                           they are enterable.
228                                           Added support for rt_strt_dt_cd of
229                                           ENTRBL(Enterable) and rt_end_dt_cd of
230                                           WAENT(1 Prior or Enterable).
231      09-Mar-01  maagrawa        115.98    Create/Update the rate whenever the
232                                           per_in_ler_id changes.
233                                           Added check that the rate start date
234                                           should be less than or equal to rate
235                                           end date in election_rate_info...
236      17-May-01  maagrawa        115.99    Removed use of ben_comp_object and
237                                           replaced with ben_cobj_cache.
238                                           Modified calls to ben_global_enrt.
239      29-May-01  kmahendr        115.100   Modified cursor c_prv2 Bug#1771887
240      18-Jun-01  kmahendr        115.101   Bug#1830930-rate end date code is enterable
241                                           and rate start dt is not passed thro PUI then
242                                           end date is arrived as rate start dt - 1
243      20-Jun-01  ikasire         115.102   bug 1840961 added p_enrt_cvg_strt_dt and
244                                           p_enrt_cvg_thru_dt to the election_information
245                                           procedure call.
246      20-Jun-01  ikasire         115.104   this file is 115.102 after backporting version
247                                           115.103 for bug 1840961
248      25-Jun-01  kmahendr        115.105   The else condition in if code is WAENT is corrected
249      01-Jul-01  kmahendr        115.106   Unrestricted changes
250      23-Jul-01  kmahendr        115.107   Bug#1807450 - Coverage start date is not computed
251                                           if there is any waiting period attached
252      23-Jul-01  ikasire         115.108   Bug#1888085 fixed the issue of not calculating the
253                                           actual amount for 'Percent of' and
254                                           use_calc_acty_bs_rt_flag  is checked
255      24-Jul-01  mmorishi        115.109   Election_information_w: Added rt_strt_dt_cd
256                                           and person_id parms. Added call to prv_delete.
257      06-Aug-01  ikasire         115.110   Bug1913254 added a new cursor to handle the cases
258                                           for SAAEAR coverage code and the rate is not
259                                           entered at enrollment.
260      09-Aug-01  kmahendr        115.111   Bug#1890996 - Added cursor c_abr to check non recur-
261                                           ring rate and not to call update_prtt_rt_val to end
262                                           previous rate. Assign rate start date to rate end
263                                           date if the rate is non-recurring
264      17-Aug-01  maagrawa        115.112   Added parameter p_rt_update_mode
265                                           to election_information_w.
266      28-Aug-01  kmahendr        115.113   Added condition to check necessity to call update
267                                           prtt_rt_val
268      29-aug-01  tilak           115.114   bug:1949361 jurisdiction code is
269                                               derived inside benutils.formula.
270      30-aug-01  kmahendr        115.115   Already ended recurring rate is extended in the
271                                           subsequent rate - added condition to check old
272                                           rate end date
273      31-aug-01  pbodla          115.117   Version 116 is actually version 111 with changes
274                                           in version 114.
275      25-Oct-01  kmahendr        115.118   Bug#2055961-codes starting with 1 prior handled
276                                           before updating prtt_rt_val
277      5-Dec-01   dschwart        115.119   - Bug#2141172: changed call to ben_determine
278                                           _date.rate_and_coverage_dates to use life
279                                           event date.
280     18-dec-01   tjesumic        115.120   - cwb changes
281     20-dec-01   ikasire         115.121   added dbdrv lines
282     01-feb-02   ikasire         115.122   Bug 2172036 populate assignment_id in the pen records
283                                           the one available in epe record
284     12-Feb-02   ikasire         115.123   Bug 2212194 If there exist multiple rates while using
285                                           SAAREC code for Coverage Calculation.
286     12-Feb-02   ikasire         115.125   Bug 2212194 This is version 115.23 since we gave a
287                                           backport to ADS in 115.124
288     13-Feb-02   ikasire         115.126   Bug 2223694 When Rate code SAREC and the Coverage is
289                                           not enter value at enrollment, defined amount and
290                                           element entries not calculated.
291     26-Feb-02   rpillay         115.127   Bug 2093830 Changed from p_effective_date
292                                           to lf_evt_ocrd_dt in c_enrt_rt cursor
293     27-Feb-02   tjesumic        115.128   bug : 1794303 fixed by passing parameter
294                                           p_element_type_id  to annual_to_period
295     04-Mar-02   kmahendr        115.129   bug#2048236 - added cursors  - c_element_type and
296                                           if condition before update_prtt_rt_val -
297                                           removed changes made in 128 per Tilak.
298     14-Mar-02   rpillay         115.130   UTF8 Changes Bug 2254683
299     23-May-02   kmahendr        115.131   Changed logic for communicated value
300                                 115.132   No changes
301     04-Jun-02   kmahendr        115.133   Bug#2398448 and #2392732 - enrt_id is passed instead
302                                           of electable choice id for computing communicated
303                                           value.
304     08-Jun-02   pabodla         115.134   Do not select the contingent worker
305                                           assignment when assignment data is
306                                           fetched.
307     20-Jun-02   ikasire         115.135   Bug 2407041 wrong communication amount
308                                           when payroll changes.
309     06-Jun-02   ikasire         115.136   Bug 2483991 and Interim Ehancements.
310     07-Aug-02   ikasire         115.136   Bug 2483991 wrong datetrack mode was passed
311                                           to delete enrollment if the user replaces the
312                                           defaulted enrollment with the some other
313                                           compensation object.
314     08-Aug-02   ikasire         115.137   Bug 2502633 Interim enhancements.This needs to
315                                           go with the bensuenr.pkb/pkh as we are using a
316                                           package global variable here.
317     29-Aug-02   kmahendr        115.138   Bug#2207956 -sec 125 or 129 references removed and
318                                           codes added for starting a new result.
319     05-Sep-02   ikasire         115.140   Bug 2547005 and 2543071 for interim changes
320     28-Sep-02   ikasire         115.141   Bug 2600087 fixes for deenrolled result
321     28-Sep-02   ikasire         115.141   Bug 2600087 fixed error making infinit loop
322     10-Oct-02   shdas           115.143   Changed election_information_w for multirates
323     11-Oct-02   vsethi          115.144   Rates Sequence no enhancements. Modified to cater
324                                           to new column ord_num on ben_acty_base_rt_f
325     15-Oct-02   ikasire         115.145   Bug 2627078 fixes
326     28-Nov-02   lakrish         115.146   Bug 2499754, set tokens for error messages
327                                           BEN_91711_ENRT_RSLT_NOT_FND and
328                                           BEN_91453_CVG_STRT_DT_NOT_FOUN
329     02-Dec-02   kmullapu        115.147   out nocopy param added to election_information_w
330     13-Dec-02   ikasire         115.148   Bug 2675486 FSA Dont recmpute the fsa if
331                                           there is no change in the annual amount
332                                           within the plan year in the subsequent
333                                           life events
334     27-Dec-02   ikasire         115.149   Bug 2677804 override thru date changes
335     02-jan-03   hmani           115.149   Bug 2714383 - Passed pen_attributes
336        					  after checking whether its equalto hr_api.g_varchar2
337     					  Created a new function called 'decd_attribute'
338     09-jan-03   kmahendr        115.151   Bug#2734491 - Rates with child code is treated as
339                                           parent for annual target.
340     23-Jan-03   ikasire         115.152   Bug#2149438 Used the overloaded annual_to_period
341                                           procedure to determine the defined amount for
342                                           FSA calculations.
343     24-Jan-03   ikasire         115.153   Added nocopy changes
344     13-Feb-03   kmahendr        115.154   Added a parameter to call -acty_base_rt.main
345     13-feb-03   hnarayan	115.155   hr_utility.set_location - 'if g_debug' changes
346     06-Mar-03   ikasire         115.156   Bug2833116 rounding issue for FSA - annual rates
347     12-May-03   ikasire         115.157   Bug 2957028 nocopy bug fix for call to
348                                           ben_determine_activity_base_rt.main procedure
349     22-May-03   kmahendr        115.158   Fix for new rt mlt cd - ERL
350     29-May-03   ikasire         115.159   Bug 2976103 for nonrecurring element entries
351     22-Jul-03   tjesumic        115.160   rate start dt is passes as param to rate updated
352                                           when the rate strt dt is enterable
353     22-Jul-03   ikasire         115.161   brought forward 115.159 version.
354                                           DONT USE 115.160 -- BUG 3053267
355     13-Aug-03   kmahendr        115.162   Fix for new cvg_mlt_cd - ERL
356     26-Sep-03   kmahendr        115.163   Fix for new rt strt dt codes.
357     08-Oct-03   lakrish         115.164   Bug 3181158, for Enterable coverages
358                                           raise min-max error properly even if
359                                           default value is not defined for
360                                           Coverage.
361     15-Oct-03   mmudigon        115.165   Bug 2775742. Update rates for rt chg
362                                           process when element/input attached
363                                           to abr is changed.
364     30-Oct-03   tjesumic        115.165   #  2982606  new procedure backout_future_coverage added to
365                                 115.166    backout the future dated coverage and the plan in not continued
366                                           The backout caled for result level backed out
367                                           related changes in  benbolfe , bendenrr ,benleclr
368     14-Nov-03   ikasire         115.167   Bug 3253180 Get the right l_rt_val from the
369                                           annual value when p_rt_val is null for
370                                           l_enrt_rt.entr_ann_val_flag = 'Y'
371                                           also - if the same plan yr period if there is no change
372                                           in the annual contribution dont recompute the rates.
373     18-Nov-03   kmahendr        115.169   Bug#3260564 - added cursor c_future_rates to delete future
374                                           dated prtt_rt_val
375     20-Nov-03   mmudigon        115.170   Bug#3250360. Changes to
376                                           election_rate_information. cursors
377                                           c_prtt_rt_val_1 and c_prtt_rt_val_2
378                                           to pick the correct old prv
379    21-nov-03    nhunur         115.171    setting the flags to 'N' if the cursor
380                                           c_prtt_rt_val_2 does not return any rows.
381    25-nov-03    tjesumic       115.172     hr_utility.debug_enabled added to  all public procedure
382    16-Jan-04    kmahendr       115.173    Bug#3364910- added payroll change condition for
383                                           fSA plans
384    20-Jan-04    kmahendr       115.174    Bug#3378865 - added cursor c_abr to check for
385                                           ele_entry_val_cd change
386    21-Jan-04    mmudigon       115.175    Bug#3378865 - modified data type for
387                                           variable l_ele_entry_val_cd
388    03-Feb-04    kmahendr       115.176    Bug#3400822 - the subquery modified with                                                    effective_end_date condition to return only one
389                                           row - cursor c_enrt_rslt
390    16-Feb-04    mmudigon       115.177    Bug 3437083. Logic to determine abr
391                                           assignment changes
392    24-Feb-04    stee           115.178    Bug 3457483. Check the assignment to use code
393                                           in activity base rate when selecting the
394                                           assignment.
395    08-mar-04    hmani          115.179    Bug 3488286 - Added p_lf_evt_ocrd_date parameter to
396                                           BEN_DETERMINE_ACTIVITY_BASE_RT call
397    19-Mar-04    ikasire        115.180    Added new procedure call for rate_periodization_rl
398    23-Mar-04    ikasire        115.181    GSCC error
399    05-Apr-04    bmanyam        115.182    Bug: 3547233. Copied annual value to l_ann_rt_val variable
400                                           for prtt_enrt_rt record for 'Set Annual Value to Coverage'
401                     					  calculation method.
402   09-Apr-04     kmahendr       115.183    Bug#3540351 - rt_val and cmcd_val assigned
403                                           value 0 if the value is negative.
404   26-Apr-04     kmahendr       115.185    Bug#3510633 - person_id added to annual_to_period
405                                           function
406   07-jun-04      nhunur        115.186    bug 3602579 - original enrt date fix for waive oipls
407   08-jun-04     mmudigon       115.187    FONM
408   02-jul-04     rpgupt         115.188    3733745 - Do not delete future enrts. if it is an
409                                           interim.
410   15-Jul-04     kmahendr       115.189    Bug#3702090 - added enrt_mthd_cd condition while creating
411                                           new result - new flex plan enrollment is created when
412                                           override flex rate"
413   27-Jul-04     mmudigon       115.190    Bug 3797946. Logic to determine
414                                           change in extra input values
415   02-Aug-04     ikasire        115.191    Bug 3804813 to recompute the rates if
416                                           l_enrt_rt.entr_bnft_val_flag = 'Y'
417   23-Aug-04     mmudigon       115.192    CFW. Added p_act_item_flag
418                                           2534391 :NEED TO LEAVE ACTION ITEMS
419   09-sep-04     mmudigon       115.193    CFW. Continued
420   09-sep-04     mmudigon       115.194    CFW. p_act_item_flag no longer needed
421   20-Sep-04     ikasire        115.195    Bug 3787832 backout only the future results
422                                           of past life events.
423   30-sep-04     mmudigon       115.196    Bug 3854378. In proc
424                                           election_rate_information, old prv is
425                                           re-opened only when it is necessary
426  11-Oct-04     tjesumic        115.197    future backout only for a pgm, pgm_id added in validation
427  20-nov-04     nhunur          115.198    4020061 - bnft_val should be null if enrt_bnft_id is passed as null.
428  23-Nov-04     kmahendr        115.199    start_date passed for communicate val cal for fsa
429                                           to handle new rate codes
430  30-Nov-04     mmudigon        115.200    Bug 4018874. Changes to cursor
431                                           c_fut_pen in backout_future_coverage
432  01-Dec-04     ikasire         115.201    Bug 3988565 date type changed for a parameter  for SSBEN
433  12-Dec-04     vvprabhu        115.202    Bug 3980063. SSBEN Trace enhnacement. Changes to exception
434                                           handling in wrapper packages, addition of debug statements
435 					  and logic to enable trace based on profile value.
436  22-Dec-04     maagrawa        115.203    Added more parms to election_information_w
437                                           to have both procedures in sync.
438  23-Dec-04     tjesumic        115.204    new param p_prtt_enrt_rslt_id added backout_future_coverage
439                                           p_prtt_enrt_rslt_id nullified if the rslt is backedout
440  28-Dec-04     kmahendr        115.205    Bug#4078828 - element_type and input_value fetched
441                                           based on rate start date in case of start date code
442                                           based on election
443  29-Dec-04     tjesumic        115.206    continuation of 115.204 # 3945471 new cursor c_csr added
444                                           to validate the future cvrd results deleted
445  30-dec-2004    nhunur         115.207    4031733 - No need to open cursor c_state.
446  04-Jan-04     tjesumic        115.208    continuation of 115.204 # 3945471
447  04-Jan-04     tjesumic        115.209    continuation of 115.204  future backoit skipped for cwb,abs,comp ler
448  11-Jan-04     ikasire         115.210    CF Interim Suspended BUG 4064635
449  07-Feb-05     tjesumic        115.211    backout_future_result is removed, future cvg taken care
450                                           in delete_enrollment # 4118315
451  09-Feb-05     ikasire         115.212    Bug 4173505 Need to sspndd_flag to update_enrollment otherwise
452                                           suspended enrollment will be carried forward with suspend flag
453                                           checked even it is not required.
454  10-Feb-05     mmudigon         115.213   Bug 4157759. Added proc
455                                           handle_overlap_rates()
456  09-Mar-05     vvprabhu         115.214   Bug 4216475 changes to election_information_w to
457                                           validate coverage amount when default is outside
458 					  coverage range
459  13-Apr-05     ikasire          115.215   Added a new parameter to manage_enrt_bnft procedure
460  26-May-05     vborkar          115.216   Bug 4387247 : In wrapper method exception
461                                           handlers changes made to avoid null errors
462                                           on SS pages
463  01-Jun-05     vborkar          115.217   Bug 4387247 : Modifications to take care of
464                                           application exceptions.
465  17-Jun-05     vborkar          115.218   Bug 4436578 : In SS wrapper app exception
466                                           handler added generic(default) code.
467  12-jul-05     ssarkar          115.219   BUG 4203714 : Modified c_comp_obj_name for proc handle_overlap_rates.
468  29-jul-05     tjesumic         115.230   BUG 4510798 : fonm variable intialised on election information
469  11-aug-05     ssarkar          115.221   BUG 4203714 : Rtrim to chop off the trailing spaces
470  17-aug-05     kmahendr         115.222   Bug#4549089 - new result is created only
471                                           if the per_in_ler is different in sspd enroll
472  25-Aug-05     ikasire          115.223   Bug 4568911 fix
473  08-Sep-05     kmahendr         115.224   Bug#4555320 - new result is not created
474                                           if the per in ler ids are same
475  27-Sep-05     vborkar          115.225   Bug 4543745 : Avoid election-information call for
476 	                                        electable choices whose existing enrollments
477 																					cannot be changed in current LE.
478  03-Nov-05     rbingi           115.226   4710188: removed case entr_bnft_val='Y' in if condition of
479                                             call to Std rates proc. will be called only for Post-Enrollment
480  03-Nov-05     rbingi           115.227   reverted previous version changes
481  08-Nov-05     rbingi           115.228   4710188: Calling acty_base_rt proc for ERL case only if
482                                            rt value is not enterable
483  02-dec-05    ssarkar           115.229   4775760 : Creat prtt_rt_val not be to called if sspndd_flag = 'Y' and prtt_rt_val is already present.
484  12-dec-05    ssarkar           115.230   4775760,4871284 : rollback fix of 115.229 and commented the restrcition of Unrestricted.
485  11-jan-06    ikasire           115.231   4938498 fixed c_prv2 cursor to exclude voided and backedout
486                                           records.
487  16-Jan-06    abparekh          115.232   Bug 4954541 : If bnft_amt is nullified, create new enrollment
488  10-Feb-06    kmahendr          115.233   Bug#5032364 - before delete prtt row, it
489                                           is captured in ben_le_clsn_n_rstr table
490                                           for backout purpose
491  22-Mar-06    rtagarra          115.234   Bug#5099296 : Changed the sspndd_flag parameter passed to update_enrollment.
492  23-Mar-06    kmahendr          115.235   Bug#5105122 - coverage date is recomputed
493                                           before create_enrollment
494  16-Jun-06    rbingi            115.236   Bug#5259005-Moved code for calulating ann_rt_val, rt_val based in
495                                            entr_val flag to proc election_rate_information from pld.
496  09-Jul-06    rbingi            115.237   Bug#5303167-corrected if condition in proc elec_rt_info
497  17-jul-06    ssarkar           115.238   Bug 5375381 - ben_determine_activity_base_rt being called for interim.
498  03-aug-06    ssarkar           115.239   bug 5417132 - passing comp_lvl_cd to update_enrollment call
499  27-Sep-06    ikasired          115.240   Bug 5502202 fix for Interim Rule. We need to recompute the rates when
500                                           interim rule returs amounts.
501  10-Oct-06    abparekh          115.241   Bug 5572484 : Take backup in BEN_LE_CLSN_N_RSTR only if the correction
502                                                         is due to a new life event.
503  11-Oct-06    ssarkar           115.242   Bug 5555269 - commented out fix of bug 5032364 as well 5572484
504  12-Oct-06    gsehgal           115.243   Bug 5584813 - move the code to calculate rates to procedure
505 					  calc_rt_ann_rt_vals and also call this when cvg_mlt_cd='SAAEAR'
506  17-Oct-06    abparekh          115.244   Bug 5600697 - In procedure ELECTION_INFORMATION
507                                                         Set P_PRTT_ENRT_RSLT_ID only if
508                                                         PRTT_ENRT_RSLT_STAT_CD is NULL
509 20-Oct-06     bmanyam           115.245   5612091 cursor c_enrt_rt corrected.
510                                           join ecv with enb was incomplete. OR-ed with epe
511 26-Oct-06     ssarkar           115.246   5621049  : dont compare the cvg amt of option2 with option1
512 10-Nov-06     ssarkar           115.247   bug 5653168 : resetting g_use_new_result for any exception raised in election_information
513 18-nov-06     ssarkar           115.248   Bug 5717428 - passed life event occurred date to rate_and_coverage_dates
514 24-jan-07     stee              115.249   Bug 5766477 - Restore dependent
515                                           coverage when future enrollments
516                                           are deleted.
517 05-apr-07     ssarkar           115.250   bug 5942441 - overiding info to be passed to subsequent prv
518 08-may-07     gsehgal           115.251   bug 6022111 - wrong prv record was being fetched
519                                           for parent record in cursor c_prv2
520 11-May-07     ikasired          115.252   Bug 5985777. When action items are completed in future
521                                           we need to extend the suspended enrollments with future
522                                           delete store the future completed action items in
523                                           backup table for future reinstate in the event
524                                           the current life event backout.
525 25-May-07     bmanyam           115.253   6057157 : -- same as above--
526                                           Reopen future interim PRV records. This was
527                                           missed out in the prev version.
528 21-Jun-07     swjain		115.254   6067740 - Updated procedure election_rate_information for SAREC
529                                           cases.
530 26-Jun-07     sshetty		115.255   6132571--changed logic to detect the
531                                           payroll id changes by calling
532                                           get_abr_assignment for the old
533                                           rate start date
534 24-Aug-07     gsehgal           115.256   bug 6337803 - dont delete the enrollment if enrollment to be suspended has same
535                                           comp object as interim
536 05-Oct-07     swjain            115.258   Removing the fix in 6067740
537 23-Oct-07     rgajula           115.259   Bug 6503304 : Passed lf_evt_ocrd_dt instead of p_effective_date to procedures get_ptip_dets, get_plip_dets, get_oipl_dets,get_pl_dets
538                                            to get the details as of life event occured date (open life event case)
539 28-aug-08     bachakra          115.260   Bug 7206471: adjust the coverage and rates when event date life event
540                                           is processed after fonm life event in the same month.
541 */
542 
543 -------------------------------------------------------------------------------
544 --
545 -- Package Variables
546 --
547 g_debug boolean := hr_utility.debug_enabled;
548 g_package varchar2(80):='ben_election_information.';
549 -- ---------------------------------------------------------------------------
550 -- |----------------------------< calc_rt_ann_rt_vals >---------------------|
551 -- Bug: 5584813 this is a private procedure that calculates the rate values --
552 -- ---------------------------------------------------------------------------
553 --
554 PROCEDURE calc_rt_ann_rt_vals (
555    p_rt_val                  IN OUT NOCOPY  NUMBER,
556    p_ann_rt_val              IN OUT NOCOPY  NUMBER,
557    p_person_id               IN       NUMBER,
558    p_effective_date          IN       DATE,
559    p_acty_base_rt_id         IN       NUMBER,
560    p_rate_periodization_rl   IN       NUMBER,
561    p_elig_per_elctbl_chc_id    IN       NUMBER,
562    p_business_group_id       IN       NUMBER,
563    p_enrt_rt_id              IN       NUMBER,
564    p_entr_ann_val_flag       IN       VARCHAR2,
565    p_entr_val_at_enrt_flag   IN       VARCHAR2)
566 IS
567    l_assignment_id     per_all_assignments_f.assignment_id%TYPE;
568    l_payroll_id        per_all_assignments_f.payroll_id%TYPE;
569    l_organization_id   per_all_assignments_f.organization_id%TYPE;
570    --GEVITY
571    l_dfnd_dummy        NUMBER;
572    l_ann_dummy         NUMBER;
573    l_cmcd_dummy        NUMBER;
574    l_compute_val       NUMBER;
575 
576 --END GEVITY
577    l_proc                 varchar2(72) := g_package||'calc_rt_ann_rt_vals';
578 BEGIN
579    hr_utility.set_location('Entering: '||l_proc, 10);
580    IF p_entr_ann_val_flag = 'Y'
581    THEN
582       -- Enter Annual Value
583       IF     p_rate_periodization_rl IS NOT NULL
584          AND p_acty_base_rt_id IS NOT NULL
585       THEN
586          --
587          ben_element_entry.get_abr_assignment
588                                      (p_person_id                   => p_person_id,
589                                       p_effective_date              => p_effective_date,
590                                       p_acty_base_rt_id             => p_acty_base_rt_id,
591                                       p_organization_id             => l_organization_id,
592                                       p_payroll_id                  => l_payroll_id,
593                                       p_assignment_id               => l_assignment_id);
594          --
595          l_ann_dummy := p_ann_rt_val;
596          ben_distribute_rates.periodize_with_rule
597                         (p_formula_id                  => p_rate_periodization_rl,
598                          p_effective_date              => p_effective_date,
599                          p_assignment_id               => l_assignment_id,
600                          p_convert_from_val            => l_ann_dummy,
601                          p_convert_from                => 'ANNUAL',
602                          p_elig_per_elctbl_chc_id      => p_elig_per_elctbl_chc_id,
603                          p_acty_base_rt_id             => p_acty_base_rt_id,
604                          p_business_group_id           => p_business_group_id,
605                          p_enrt_rt_id                  => p_enrt_rt_id,
606                          p_ann_val                     => l_dfnd_dummy,
607                          p_cmcd_val                    => l_cmcd_dummy,
608                          p_val                         => l_compute_val);
609       --
610       ELSE
611          l_compute_val :=
612             ben_distribute_rates.annual_to_period
613                                  (p_amount                      => p_ann_rt_val,
614                                   p_enrt_rt_id                  => p_enrt_rt_id,
615                                   p_elig_per_elctbl_chc_id      => NULL,
616                                   p_acty_ref_perd_cd            => NULL,
617                                   p_business_group_id           => p_business_group_id,
618                                   p_effective_date              => p_effective_date,
619                                   p_lf_evt_ocrd_dt              => NULL,
620                                   p_complete_year_flag          => 'Y',
621                                   p_use_balance_flag            => 'Y',
622                                   p_start_date                  => NULL,
623                                   p_end_date                    => NULL);
624       --
625       END IF;                                                         --GEVITY
626 
627       p_rt_val := l_compute_val;
628    ELSIF p_entr_val_at_enrt_flag = 'Y'
629    THEN
630       --
631       IF     p_rate_periodization_rl IS NOT NULL
632          AND p_acty_base_rt_id IS NOT NULL
633       THEN
634          --
635          ben_element_entry.get_abr_assignment
636                              (p_person_id                   => p_person_id,
637                               p_effective_date              => p_effective_date,
638                               p_acty_base_rt_id             => p_acty_base_rt_id,
639                               p_organization_id             => l_organization_id,
640                               p_payroll_id                  => l_payroll_id,
641                               p_assignment_id               => l_assignment_id);
642          --
643          l_dfnd_dummy := p_rt_val;
644          --
645          ben_distribute_rates.periodize_with_rule
646                 (p_formula_id                  => p_rate_periodization_rl,
647                  p_effective_date              => p_effective_date,
648                  p_assignment_id               => l_assignment_id,
649                  p_convert_from_val            => l_dfnd_dummy,
650                  p_convert_from                => 'DEFINED',
651                  p_elig_per_elctbl_chc_id      => p_elig_per_elctbl_chc_id,
652                  p_acty_base_rt_id             => p_acty_base_rt_id,
653                  p_business_group_id           => p_business_group_id,
654                  p_enrt_rt_id                  => p_enrt_rt_id,
655                  p_ann_val                     => l_compute_val,
656                  p_cmcd_val                    => l_cmcd_dummy,
657                  p_val                         => l_cmcd_dummy);
658       --
659       ELSE
660          l_compute_val :=
661             ben_distribute_rates.period_to_annual
662                                  (p_amount                      => p_rt_val,
663                                   p_enrt_rt_id                  => p_enrt_rt_id,
664                                   p_elig_per_elctbl_chc_id      => NULL,
665                                   p_acty_ref_perd_cd            => NULL,
666                                   p_business_group_id           => p_business_group_id,
667                                   p_effective_date              => p_effective_date,
668                                   p_lf_evt_ocrd_dt              => NULL,
669                                   p_complete_year_flag          => 'Y',
670                                   p_use_balance_flag            => 'Y',
671                                   p_start_date                  => NULL,
672                                   p_end_date                    => NULL);
673       --
674       END IF;                                                         --GEVITY
675 
676       p_ann_rt_val := l_compute_val;
677    --
678    END IF;
679    hr_utility.set_location('Leaving: '||l_proc, 10);
680 END calc_rt_ann_rt_vals;
681 
682 
683 -- ---------------------------------------------------------------------------
684 -- |----------------------------< handle_overlap_rates >---------------------|
685 -- ---------------------------------------------------------------------------
686 --
687 procedure handle_overlap_rates
688   (p_acty_base_rt_id                in  number
689   ,p_prtt_enrt_rslt_id              in  number
690   ,p_prtt_rt_val_id                 in out nocopy  number
691   ,p_per_in_ler_id                  in  number
692   ,p_person_id                      in  number
693   ,p_element_type_id                in  number default null
694   ,p_element_entry_value_id         in  number
695   ,p_unrestricted                   in  varchar2 default 'N'
696   ,p_rt_strt_dt                     in  date
697   ,p_business_group_id              in  number
698   ,p_effective_date                 in  date
699   ) is
700 
701   --
702   -- pick overlapping rates for the same abr (and)
703   -- any future rates attached to the same element type
704   --
705   cursor c_future_prv(p_element_type_id number) is
706   select prv.prtt_rt_val_id,
707          prv.acty_base_rt_id,
708          prv.acty_ref_perd_cd,
709          prv.rt_strt_dt,
710          prv.object_version_number
711     from ben_prtt_rt_val prv
712    where prv.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
713      and ((prv.rt_strt_dt > p_rt_strt_dt) or -- old prv in future
714           (p_unrestricted = 'N' and          -- old prv on same date
715            prv.per_in_ler_id <> p_per_in_ler_id and
716            prv.rt_strt_dt = p_rt_strt_dt))
717      and prv.prtt_rt_val_stat_cd is null
718      and (prv.acty_base_rt_id = p_acty_base_rt_id
719           or exists
720                 (select 'x'
721                    from per_all_assignments_f asg,
722                         pay_element_links_f pel,
723                         pay_element_entries_f pee,
724                         pay_element_entry_values_f pev
725                   where pel.element_type_id = p_element_type_id
726                     and pee.element_entry_id = pev.element_entry_id
727                     and pev.element_entry_value_id = prv.element_entry_value_id
728                     and pee.element_link_id = pel.element_link_id
729                     and pee.assignment_id = asg.assignment_id
730                     and pee.creator_type ='F'
731                     and pee.creator_id = p_prtt_enrt_rslt_id
732                     and asg.person_id = p_person_id)
733          )
734   order by prv.rt_strt_dt desc;
735   --
736   l_future_prv      c_future_prv%ROWTYPE;
737   --
738   cursor c_current_prv is
739   select prtt_rt_val_id,
740          acty_base_rt_id,
741          rt_strt_dt,
742          rt_end_dt,
743          object_version_number
744     from ben_prtt_rt_val prv
745    where prv.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
746      and p_rt_strt_dt between prv.rt_strt_dt
747      and prv.rt_end_dt
748      and prv.acty_base_rt_id = l_future_prv.acty_base_rt_id
749      and prv.prtt_rt_val_stat_cd is null;
750   --
751   l_current_prv      c_current_prv%ROWTYPE;
752   --
753   -- gets element_type_id from element_entry_value_id
754   --
755   cursor c_ele_entry (p_element_entry_value_id number) is
756   select elk.element_type_id
757     from pay_element_entry_values_f elv,
758          pay_element_entries_f ele,
759          pay_element_links_f elk
760    where elv.element_entry_value_id  = p_element_entry_value_id
761      and elv.element_entry_id = ele.element_entry_id
762      and elv.effective_start_date between ele.effective_start_date
763      and ele.effective_end_date
764      and ele.element_link_id   = elk.element_link_id
765      and ele.effective_start_date between elk.effective_start_date
766      and elk.effective_end_date;
767   --
768   cursor c_comp_obj_name (p_prtt_enrt_rslt_id number)  is
769   select rtrim(substr(pln.name||' '||opt.name,1,60)) -- 4203714 rtrim to chop off the trailing spaces
770     from ben_prtt_enrt_rslt_f pen,
771          ben_pl_f pln,
772          ben_oipl_f oipl,
773          ben_opt_f opt
774    where pen.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
775      and pen.pl_id = pln.pl_id
776      and pen.oipl_id  = oipl.oipl_id(+)
777      and nvl(oipl.opt_id,0) = opt.opt_id (+)
778      and p_effective_date between pen.effective_start_date
779      and pen.effective_end_date
780      and p_effective_date between pln.effective_start_date
781      and pln.effective_end_date
782      and p_effective_date between nvl(oipl.effective_start_date,p_effective_date) --start 4203714
783      and nvl(oipl.effective_end_date,p_effective_date)
784      and p_effective_date between nvl(opt.effective_start_date,p_effective_date)
785      and nvl(opt.effective_end_date,p_effective_date); -- end 4203714
786 
787   l_dummy                varchar2(1);
788   l_comp_obj_name        varchar2(60);
789   l_proc                 varchar2(72) ;
790   l_element_type_id      number;
791 
792 begin
793   g_debug := hr_utility.debug_enabled;
794   if g_debug then
795     l_proc := g_package||'handle_overlap_rates';
796     hr_utility.set_location('Entering:'|| l_proc, 10);
797   end if;
798 
799   l_element_type_id := p_element_type_id;
800   if l_element_type_id is null then
801 
802      open c_ele_entry(p_element_entry_value_id);
803      fetch c_ele_entry into l_element_type_id ;
804      close c_ele_entry;
805 
806   end if;
807 
808 
809   open c_future_prv(l_element_type_id);
810   loop
811 
812      fetch c_future_prv into l_future_prv ;
813      if c_future_prv%notfound then
814         exit;
815      end if;
816 
817      if g_debug then
818         hr_utility.set_location('future prv='||l_future_prv.prtt_rt_val_id,15);
819      end if;
820 
821      if fnd_global.conc_request_id in ( 0,-1) then
822         --
823         -- Lets us throw a warning about the deletion of the future rate.
824         --
825         open c_comp_obj_name (p_prtt_enrt_rslt_id);
826         fetch c_comp_obj_name into l_comp_obj_name;
827         close c_comp_obj_name;
828         --
829         -- Issue a warning to the user.  This will display on the enrt
830         -- forms.
831         --
832 
833         ben_warnings.load_warning
834          (p_application_short_name  => 'BEN',
835           p_message_name            => 'BEN_93369_DEL_FUT_RATE',
836           p_parma  => fnd_date.date_to_chardate(l_future_prv.rt_strt_dt),
837           p_parmb                   => l_comp_obj_name,
838           p_person_id               => p_person_id );
839 
840      end if;
841 
842      if p_prtt_rt_val_id = l_future_prv.prtt_rt_val_id then
843         p_prtt_rt_val_id := null;
844      end if;
845      --
846      -- Call delete prv if Unrestricted, else update prv
847      --
848      if p_unrestricted = 'Y' then
849         ben_prtt_rt_val_api.delete_prtt_rt_val
850         (p_prtt_rt_val_id         => l_future_prv.prtt_rt_val_id
851         ,p_person_id              => p_person_id
852         ,p_business_group_id      => p_business_group_id
853         ,p_object_version_number  => l_future_prv.object_version_number
854         ,p_effective_date         => l_future_prv.rt_strt_dt);
855     else
856         ben_prtt_rt_val_api.update_prtt_rt_val
857         (p_validate                => false,
858          p_person_id               => p_person_id,
859          p_business_group_id       => p_business_group_id,
860          p_prtt_rt_val_id          => l_future_prv.prtt_rt_val_id,
861          p_rt_end_dt               => l_future_prv.rt_strt_dt -1,
862          p_prtt_rt_val_stat_cd     => 'BCKDT',
863          p_ended_per_in_ler_id     => p_per_in_ler_id,
864          p_object_version_number   => l_future_prv.object_version_number,
865          p_effective_date          => l_future_prv.rt_strt_dt);
866     end if;
867     --
868     -- open up the current rates that are attached to the same
869     -- element type
870     --
871     if l_future_prv.acty_base_rt_id <> p_acty_base_rt_id then
872 
873        l_current_prv := null;
874        open c_current_prv;
875        fetch c_current_prv into l_current_prv;
876        close c_current_prv;
877 
878        if g_debug then
879           hr_utility.set_location('curr prv='||l_current_prv.prtt_rt_val_id,15);
880        end if;
881 
882        if l_current_prv.rt_end_dt <> hr_api.g_eot then
883           --
884           ben_prtt_rt_val_api.update_prtt_rt_val
885           (p_prtt_rt_val_id         => l_current_prv.prtt_rt_val_id
886           ,p_person_id              => p_person_id
887           ,p_rt_end_dt              => hr_api.g_eot
888           ,p_business_group_id      => p_business_group_id
889           ,p_object_version_number  => l_current_prv.object_version_number
890           ,p_effective_date         => p_effective_date);
891           --
892        end if;
893        --
894     end if;
895 
896   end loop;
897   close c_future_prv ;
898 
899   if g_debug then
900     hr_utility.set_location(' Leaving:'||l_proc, 20);
901   end if;
902 
903 end handle_overlap_rates;
904 --
905 --
906 -- ----------------------------------------------------------------------------
907 -- |-------------------< election_rate_information >-------------------------|
908 -- ----------------------------------------------------------------------------
909 procedure election_rate_information
910   (p_calculate_only_mode in     boolean default false
911   ,p_enrt_mthd_cd        in     varchar2
912   ,p_effective_date      in     date
913   ,p_prtt_enrt_rslt_id   in     number
914   ,p_per_in_ler_id       in     number
915   ,p_person_id           in     number
916   ,p_pgm_id              in     number
917   ,p_pl_id               in     number
918   ,p_oipl_id             in     number
919   ,p_enrt_rt_id          in     number
920   ,p_prtt_rt_val_id      in out nocopy number
921   ,p_rt_val              in     number
922   ,p_ann_rt_val          in     number
923   ,p_enrt_cvg_strt_dt    in     date
924   ,p_acty_ref_perd_cd    in     varchar2
925   ,p_datetrack_mode      in     varchar2
926   ,p_business_group_id   in     number
927   ,p_bnft_amt_changed    in     boolean default false
928   ,p_ele_changed         in     boolean default null
929   ,p_rt_strt_dt          in     date    default null
930   ,p_rt_end_dt           in     date    default null
931   --
932   ,p_prv_rt_val             out nocopy number
933   ,p_prv_ann_rt_val         out nocopy number
934   )
935 is
936   --
937   -- Local variable declarations
938   --
939   l_proc         varchar2(72) := g_package||'election_rate_information';
940   --
941 
942         l_rt_val                        number;
943         l_ann_rt_val                    number;
944         l_calc_ann_val                  number;
945         l_prnt_rt_val                   number;
946         t_old_tx_typ_cd                 varchar2(30);
947         l_old_tx_typ_cd                 varchar2(30);
948         l_old_acty_typ_cd               varchar2(30);
949         l_old_mlt_cd                    varchar2(30);
950         l_old_acty_ref_perd_cd          varchar2(30);
951         l_old_rt_val                    number;
952         l_old_prtt_enrt_rslt_id         number;
953         l_old_business_group_id         number;
954         l_old_object_version_number     number;
955         l_old_rt_typ_cd                 varchar2(30);
956         l_old_rt_strt_dt                date;
957         l_old_ann_rt_val                number;
958         l_old_bnft_rt_typ_cd            varchar2(30);
959         l_old_cmcd_ref_perd_cd          varchar2(30);
960         l_old_cmcd_rt_val               number;
961         l_old_dsply_on_enrt_flag        varchar2(30);
962         l_old_cvg_amt_calc_mthd_id      number;
963         l_old_actl_prem_id              number;
964         l_old_comp_lvl_fctr_id          number;
965         l_old_rt_end_dt                 date;
966         l_old_per_in_ler_id             number := null;
967         l_effective_start_date          date;
968         l_effective_end_date            date;
969         l_elctns_made_dt                date;
970         l_rt_ovridn_flag                varchar2(30);
971         l_rt_ovridn_thru_dt             date;
972         l_element_entry_value_id        number;
973         l_old_elctns_made_dt            date;
974         l_period_type                   varchar2(30);
975         l_xenrt_cvg_strt_dt             date;
976         l_xenrt_cvg_strt_dt_cd          varchar2(30);
977         l_xenrt_cvg_strt_dt_rl          number;
978         l_xrt_strt_dt                   date;
979         l_xrt_strt_dt_cd                varchar2(30);
980         l_xrt_strt_dt_rl                number;
981         l_xenrt_cvg_end_dt              date;
982         l_xenrt_cvg_end_dt_cd           varchar2(30);
983         l_xenrt_cvg_end_dt_rl           number;
984         l_xrt_end_dt                    date;
985         l_xrt_end_dt_cd                 varchar2(30);
986         l_xrt_end_dt_rl                 number;
987         l_bnft_prvdd_ldgr_id            number;
988         l_dummy_num                     number;
989         l_dummy_varchar2                varchar2(80);
990         l_dummy_date                    date;
991         l_dummy_number                  number;
992 
993         l_lf_evt_ocrd_dt                date;
994         l_old_rt_ovridn_flag            varchar2(30) := 'N';
995         l_old_rt_ovridn_thru_dt         date;
996         l_effective_date                date ;
997         l_yp_start_date                 date;
998         l_old_element_entry_value_id    number;
999         l_element_changed               boolean := false;
1000         l_non_recurring_rt              boolean := false;
1001         l_no_end_element                boolean := false;
1002         l_processing_type               varchar2(30);
1003         l_rt_end_dt                     date := p_rt_end_dt;
1004         l_element_type_id               number;
1005         l_sarec_compute                 boolean := true ;
1006         l_prnt_ann_val                  number;
1007         l_prnt_ann_rt                   varchar2(1) := 'N';
1008         l_rounded_value                 number;
1009         l_cal_val_in                    number ;
1010         l_global_asg_rec ben_global_enrt.g_global_asg_rec_type;
1011         l_global_pen_rec ben_prtt_enrt_rslt_f%rowtype;
1012         l_ele_entry_val_cd              varchar2(30);
1013         l_new_assignment_id             number;
1014         l_new_payroll_id                number;
1015         l_new_organization_id           number;
1016         l_assignment_id                 per_all_assignments_f.assignment_id%type;
1017         l_payroll_id                    per_all_assignments_f.payroll_id%type;
1018         l_organization_id               per_all_assignments_f.organization_id%type;
1019         l_ext_inpval_tab                ben_element_entry.ext_inpval_tab_typ;
1020         l_inpval_tab                    ben_element_entry.inpval_tab_typ;
1021         l_jurisdiction_code             varchar2(30);
1022         l_subpriority                   number;
1023         l_ext_inp_changed               boolean;
1024         l_old_assignment_id             number;
1025         l_old_payroll_id                number;
1026         l_old_organization_id           number;
1027   --
1028 
1029   --
1030   -- Cursor declarations.
1031   --
1032   -- Get the enrolment rate and activity base rate values
1033   cursor c_enrt_rt is
1034         select  abr.acty_base_rt_id,
1035                 abr.ele_rqd_flag,
1036                 abr.element_type_id,
1037                 abr.input_value_id,
1038                 abr.rcrrg_cd,
1039                 abr.use_calc_Acty_bs_rt_flag,
1040                 abr.entr_val_At_enrt_flag ,
1041                 abr.rt_typ_cd abr_typ_cd,
1042                 abr.val  abr_val,
1043                 abr.rndg_cd,
1044                 abr.rndg_rl,
1045                 abr.ele_entry_val_cd,
1046                 abr.input_va_calc_rl,
1047                 abr.effective_start_date abr_esd,
1048                 abr.effective_end_date abr_eed,
1049                 er.rt_typ_cd,
1050                 er.tx_typ_cd,
1051                 er.acty_typ_cd,
1052                 er.rt_mlt_cd,
1053                 er.rt_strt_dt,
1054                 er.rt_strt_dt_cd,
1055                 er.rt_strt_dt_rl,
1056                 er.bnft_rt_typ_cd,
1057                 er.cmcd_acty_ref_perd_cd,
1058                 er.val,
1059                 er.ann_val,
1060                 er.cmcd_val,
1061                 er.dsply_on_enrt_flag,
1062                 er.cvg_amt_calc_mthd_id,
1063                 er.actl_prem_id,
1064                 er.comp_lvl_fctr_id,
1065                 er.business_group_id,
1066                 nvl(eb.elig_per_elctbl_chc_id,
1067                     er.elig_per_elctbl_chc_id) elig_per_elctbl_chc_id,
1068                 er.entr_ann_val_flag,
1069                 er.prtt_rt_val_id,
1070                 er.decr_bnft_prvdr_pool_id,
1071                 nvl(eb.enrt_bnft_id,0) enrt_bnft_id,
1072                 nvl(eb.entr_val_at_enrt_flag,'N') entr_bnft_val_flag,
1073                 er.pp_in_yr_used_num,
1074                 er.ordr_num,
1075                 eb.cvg_mlt_cd,
1076                 abr.rate_periodization_rl, --GEVITY
1077                 nvl(eb.mx_wo_ctfn_flag,'N') interim_flag  --BUG 5502202
1078         from    ben_enrt_rt er,
1079                 ben_enrt_bnft eb,
1080                 ben_acty_base_rt_f abr
1081         where   er.enrt_rt_id=p_enrt_rt_id
1082         and     eb.enrt_bnft_id(+)=er.enrt_bnft_id
1083         and     er.acty_base_rt_id=abr.acty_base_rt_id
1084         and     ( (ben_manage_life_events.fonm = 'Y' and
1085                  nvl(nvl(p_rt_strt_dt,er.rt_strt_dt),l_effective_date) between
1086                  abr.effective_start_date and  abr.effective_end_date) or
1087                   (nvl(ben_manage_life_events.fonm,'N') = 'N'
1088                    and l_effective_date between abr.effective_start_date
1089                    and  abr.effective_end_date) ) ;
1090   l_enrt_rt c_enrt_rt%rowtype;
1091 
1092   -- Get the participant rate record
1093 
1094   cursor c_prtt_rt_val_1 is
1095         select  prv.rt_typ_cd,
1096                 prv.tx_typ_cd,
1097                 prv.acty_typ_cd,
1098                 prv.mlt_cd,
1099                 prv.acty_ref_perd_cd,
1100                 prv.rt_val,
1101                 prv.prtt_enrt_rslt_id,
1102                 prv.business_group_id,
1103                 prv.object_version_number,
1104                 prv.rt_strt_dt,
1105                 prv.ann_rt_val,
1106                 prv.bnft_rt_typ_cd,
1107                 prv.cmcd_ref_perd_cd,
1108                 prv.cmcd_rt_val,
1109                 prv.dsply_on_enrt_flag,
1110                 prv.cvg_amt_calc_mthd_id,
1111                 prv.actl_prem_id,
1112                 prv.comp_lvl_fctr_id,
1113                 prv.rt_end_dt,
1114                 prv.per_in_ler_id,
1115                 prv.element_entry_value_id,
1116                 prv.elctns_made_dt,
1117                 prv.rt_ovridn_flag,
1118                 prv.rt_ovridn_thru_dt
1119         from    ben_prtt_rt_val prv
1120         where   prtt_rt_val_id=l_enrt_rt.prtt_rt_val_id and
1121                 p_business_group_id=business_group_id;
1122 
1123   cursor c_prtt_rt_val_2 is
1124         select  prv.prtt_rt_val_id,
1125                 prv.rt_typ_cd,
1126                 prv.tx_typ_cd,
1127                 prv.acty_typ_cd,
1128                 prv.mlt_cd,
1129                 prv.acty_ref_perd_cd,
1130                 prv.rt_val,
1131                 prv.prtt_enrt_rslt_id,
1132                 prv.business_group_id,
1133                 prv.object_version_number,
1134                 prv.rt_strt_dt,
1135                 prv.ann_rt_val,
1136                 prv.bnft_rt_typ_cd,
1137                 prv.cmcd_ref_perd_cd,
1138                 prv.cmcd_rt_val,
1139                 prv.dsply_on_enrt_flag,
1140                 prv.cvg_amt_calc_mthd_id,
1141                 prv.actl_prem_id,
1142                 prv.comp_lvl_fctr_id,
1143                 prv.rt_end_dt,
1144                 prv.per_in_ler_id,
1145                 prv.element_entry_value_id,
1146                 prv.elctns_made_dt,
1147                 prv.rt_ovridn_flag,
1148                 prv.rt_ovridn_thru_dt
1149          from   ben_prtt_rt_val prv
1150         where   prv.acty_base_rt_id = l_enrt_rt.acty_base_rt_id
1151           and   prv.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
1152           and   prv.prtt_rt_val_stat_cd is null
1153           and   l_enrt_rt.rt_strt_dt between prv.rt_strt_dt
1154           and   prv.rt_end_dt
1155           and   p_business_group_id=prv.business_group_id;
1156 
1157 
1158   -- Parent rate information
1159   cursor c_abr2
1160     (c_effective_date in date,
1161      c_acty_base_rt_id in number
1162     )
1163   is
1164     select abr2.entr_val_at_enrt_flag,
1165            abr2.use_calc_acty_bs_rt_flag,
1166            abr2.acty_base_rt_id,
1167            abr2.rt_mlt_cd,
1168            abr2.entr_ann_val_flag
1169     from   ben_acty_base_rt_f abr,
1170            ben_acty_base_rt_f abr2
1171     where  abr.acty_base_rt_id = c_acty_base_rt_id
1172     and    abr2.acty_base_rt_id = abr.parnt_acty_base_rt_id
1173     and    abr2.parnt_chld_cd = 'PARNT'
1174     and    c_effective_date
1175            between abr.effective_start_date
1176            and     abr.effective_end_date
1177     and    c_effective_date
1178            between abr2.effective_start_date
1179            and  abr2.effective_end_date;
1180 
1181    l_prnt_abr      c_abr2%rowtype ;
1182   --
1183   cursor c_prv2
1184     (c_prtt_enrt_rslt_id  number,
1185      c_acty_base_rt_id  number
1186     )
1187    is
1188      select rt_val,
1189             ann_rt_val
1190      from ben_prtt_rt_val
1191      where acty_base_rt_id = c_acty_base_rt_id
1192        and prtt_enrt_rslt_id = c_prtt_enrt_rslt_id
1193        and per_in_ler_id     = p_per_in_ler_id
1194          -- bug 6022111
1195          AND (   (    p_effective_date BETWEEN rt_strt_dt AND rt_end_dt
1196                   -- for recurring rate
1197                   AND rt_strt_dt < rt_end_dt
1198                  )
1199               OR (                                   -- for non-recurring rate
1200                       rt_strt_dt = rt_end_dt
1201                   AND rt_strt_dt <= p_effective_date
1202                   AND rt_strt_dt =
1203                          (SELECT MAX (rt_strt_dt)
1204                             FROM ben_prtt_rt_val
1205                            WHERE acty_base_rt_id = c_acty_base_rt_id
1206                              AND prtt_enrt_rslt_id = c_prtt_enrt_rslt_id
1207                              AND per_in_ler_id = p_per_in_ler_id
1208                              AND rt_strt_dt = rt_end_dt
1209                              AND prtt_rt_val_stat_cd IS NULL)
1210                  )
1211              )
1212          -- end bug 6022111
1213        and prtt_rt_val_stat_cd IS NULL ;  --BUG 4938498
1214   --
1215   cursor c_unrestricted is
1216                    select null
1217                    from   ben_per_in_ler pil,
1218                           ben_ler_f ler
1219                    where  pil.per_in_ler_id = p_per_in_ler_id
1220                    and    pil.ler_id = ler.ler_id
1221                    and    ler.typ_cd = 'SCHEDDU'
1222                    and    ler.business_group_id = p_business_group_id
1223                    and    p_effective_date between ler.effective_start_date
1224                           and ler.effective_end_date;
1225   --
1226   cursor c_pet is
1227      select pet.processing_type
1228      from   pay_element_types_f pet
1229      where  pet.element_type_id = l_enrt_rt.element_type_id
1230      and    l_effective_date between pet.effective_start_date
1231             and pet.effective_end_date;
1232   --
1233    cursor c_element_info (p_element_entry_value_id number,
1234                           p_prtt_enrt_rslt_id      number) is
1235       select elk.element_type_id,
1236              eev.input_value_id,
1237             -- asg.payroll_id,
1238              pee.element_entry_id,
1239             -- pee.assignment_id,
1240              pee.effective_end_date
1241       from   pay_element_links_f elk,
1242              per_all_assignments_f asg,
1243              pay_element_entries_f pee,
1244              pay_element_entry_values_f eev
1245       where  eev.element_entry_value_id = p_element_entry_value_id
1246       and    eev.element_entry_id = pee.element_entry_id
1247       and    pee.element_link_id = elk.element_link_id
1248       and    pee.effective_start_date between elk.effective_start_date
1249              and elk.effective_end_date
1250       and    eev.effective_start_date between pee.effective_start_date
1251              and pee.effective_end_date
1252       and    pee.creator_type = 'F'
1253       and    pee.creator_id = p_prtt_enrt_rslt_id
1254       and    asg.assignment_id = pee.assignment_id
1255       and    pee.effective_start_date between asg.effective_start_date
1256       and    asg.effective_end_date
1257    order by pee.effective_end_date desc ;
1258    l_element_info   c_element_info%rowtype;
1259 
1260    -- Bug 2675486
1261    CURSOR c_pl_popl_yr_period_current(cv_pl_id number,
1262                                       cv_pgm_id number,
1263                                       cv_lf_evt_ocrd_dt date ) IS
1264       SELECT   distinct yp.start_date
1265       FROM     ben_popl_yr_perd pyp, ben_yr_perd yp
1266       WHERE    ( pyp.pl_id = cv_pl_id or pyp.pgm_id = cv_pgm_id )
1267       AND      pyp.yr_perd_id = yp.yr_perd_id
1268       AND      pyp.business_group_id = p_business_group_id
1269       AND      cv_lf_evt_ocrd_dt BETWEEN yp.start_date AND yp.end_date
1270       AND      yp.business_group_id = p_business_group_id ;
1271   --
1272    cursor c_payroll_type_changed(
1273             cp_person_id number,
1274             cp_business_group_id number,
1275             cp_effective_date date,
1276             cp_orig_effective_date date
1277    ) is
1278    select pay.period_type
1279    from   per_all_assignments_f asg,
1280           pay_payrolls_f pay,
1281           per_all_assignments_f asg2,
1282           pay_payrolls_f pay2
1283    where  asg.person_id = cp_person_id
1284       and asg.assignment_type <> 'C'
1285       and asg.business_group_id = cp_business_group_id
1286       and asg.primary_flag = 'Y'
1287       and cp_effective_date between
1288           asg.effective_start_date and asg.effective_end_date
1289       and pay.payroll_id=asg.payroll_id
1290       and pay.business_group_id = asg.business_group_id
1291       and cp_effective_date between
1292           pay.effective_start_date and pay.effective_end_date
1293       and asg2.person_id = cp_person_id
1294       and   asg2.assignment_type <> 'C'
1295       and asg2.business_group_id = cp_business_group_id
1296       and asg2.primary_flag = 'Y'
1297       and cp_orig_effective_date between
1298           asg2.effective_start_date and asg2.effective_end_date
1299       and pay2.payroll_id=asg2.payroll_id
1300       and pay2.business_group_id = asg2.business_group_id
1301       and cp_orig_effective_date between
1302           pay2.effective_start_date and pay2.effective_end_date
1303       and pay2.period_type <> pay.period_type
1304       and asg.assignment_type = asg2.assignment_type ;
1305   --bug#3260564 -
1306     cursor c_future_rates (p_prtt_enrt_rslt_id number,
1307                            p_acty_base_rt_id   number,
1308                            p_rt_strt_dt        date,
1309                            p_per_in_ler_id     number) is
1310       select prv.prtt_rt_val_id,
1311              prv.rt_strt_dt,
1312              prv.acty_ref_perd_cd,
1313              prv.object_version_number
1314       from   ben_prtt_rt_val prv
1315       where  prv.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
1316       and    prv.acty_base_rt_id   = p_acty_base_rt_id
1317       and    prv.rt_strt_dt >= p_rt_strt_dt
1318       and    prv.per_in_ler_id <> p_per_in_ler_id
1319       and    prv.prtt_rt_val_stat_cd is null
1320       order  by rt_strt_dt desc;
1321   --
1322   l_future_rates    c_future_rates%rowtype;
1323   --
1324   cursor c_abr (p_acty_base_rt_id number,
1325                 p_effective_date  date) is
1326     select abr.ele_entry_val_cd,
1327            abr.element_type_id,
1328            abr.input_value_id
1329     from   ben_acty_base_rt_f abr
1330     where  abr.acty_base_rt_id = p_acty_base_rt_id
1331     and    p_effective_date between abr.effective_start_date
1332            and abr.effective_end_date;
1333   --
1334   cursor c_pl_name (p_pl_id number) is
1335     select name
1336     from  ben_pl_f pln
1337     where pln.pl_id = p_pl_id
1338     and   l_effective_date between
1339           pln.effective_start_date and pln.effective_end_date;
1340   --
1341    cursor c_epe  is
1342    select epe.fonm_cvg_strt_dt
1343      from ben_elig_per_elctbl_chc epe
1344     where epe.prtt_enrt_rslt_id  = p_prtt_enrt_rslt_id
1345       and epe.per_in_ler_id = p_per_in_ler_id;
1346 
1347 --
1348       CURSOR c_sspnd_enrt_rt (cv_elig_per_elctbl_chc_id IN NUMBER)
1349       IS
1350          SELECT abr.entr_val_at_enrt_flag, er.rt_mlt_cd,
1351                 NVL (eb.entr_val_at_enrt_flag, 'N') entr_bnft_val_flag,
1352                 eb.cvg_mlt_cd
1353            FROM ben_enrt_rt er,
1354                 ben_enrt_bnft eb,
1355                 ben_acty_base_rt_f abr,
1356                 ben_prtt_enrt_rslt_f pen
1357           WHERE eb.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
1358             AND pen.rplcs_sspndd_rslt_id = p_prtt_enrt_rslt_id
1359             AND eb.elig_per_elctbl_chc_id = cv_elig_per_elctbl_chc_id
1360             AND pen.per_in_ler_id = p_per_in_ler_id
1361             AND eb.enrt_bnft_id = er.enrt_bnft_id
1362             AND er.acty_base_rt_id = abr.acty_base_rt_id
1363             AND l_effective_date BETWEEN pen.effective_start_date
1364                                      AND pen.effective_end_date
1365             AND (   (    ben_manage_life_events.fonm = 'Y'
1366                      AND NVL (er.rt_strt_dt, l_effective_date)
1367                             BETWEEN abr.effective_start_date
1368                                 AND abr.effective_end_date
1369                     )
1370                  OR (    NVL (ben_manage_life_events.fonm, 'N') = 'N'
1371                      AND l_effective_date BETWEEN abr.effective_start_date
1372                                               AND abr.effective_end_date
1373                     )
1374                 );
1375   --
1376   -- 7206471
1377   cursor c_get_prior_per_in_ler is
1378    select 'Y'
1379    from   ben_per_in_ler pil, ben_per_in_ler pil2
1380    where  pil.per_in_ler_id <> p_per_in_ler_id
1381    and    trunc(pil.lf_evt_ocrd_dt, 'MM') = trunc(pil2.lf_evt_ocrd_dt, 'MM')
1382    and    pil2.per_in_ler_id = p_per_in_ler_id
1383    and    pil2.person_id = p_person_id
1384    and    pil.person_id = p_person_id
1385    and    pil.business_group_id = pil2.business_group_id
1386    and    pil.business_group_id = p_business_group_id
1387    and    pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT');
1388   --
1389   l_exists varchar2(2);
1390   --
1391   cursor c_get_pgm_extra_info is
1392   select pgi_information1
1393   from ben_pgm_extra_info
1394   where information_type = 'ADJ_RATE_PREV_LF_EVT'
1395   and pgm_id = p_pgm_id;
1396   --
1397   l_adjust varchar2(2);
1398   --
1399   cursor c_get_elctbl_chc is
1400    select min(ecr.rt_strt_dt) rt_strt_dt
1401          ,epe.ptip_id
1402    from ben_elig_per_elctbl_chc  epe
1403        ,ben_enrt_rt ecr
1404        ,ben_enrt_bnft enb
1405    where epe.per_in_ler_id = p_per_in_ler_id
1406    and   epe.business_group_id = p_business_group_id
1407    and   decode(ecr.enrt_bnft_id, null, ecr.elig_per_elctbl_chc_id,
1408          enb.elig_per_elctbl_chc_id) = epe.elig_per_elctbl_chc_id
1409    and   enb.enrt_bnft_id (+) = ecr.enrt_bnft_id
1410    and   ecr.rt_strt_dt is not null
1411    and   ecr.business_group_id = p_business_group_id
1412    group by epe.ptip_id;
1413    --
1414    cursor c_get_enrt_rslts(p_rt_end_dt date
1415                          ,p_ptip_id   number
1416                           ) is
1417    select prv.*
1418          ,abr.element_type_id
1419          ,abr.input_value_id
1420          ,pen.person_id
1421    from ben_prtt_enrt_rslt_f pen
1422        ,ben_prtt_rt_val prv
1423        ,ben_acty_base_rt_f abr
1424    where pen.effective_end_date = hr_api.g_eot
1425    and   pen.enrt_cvg_thru_dt <> hr_api.g_eot
1426    and   pen.prtt_enrt_rslt_stat_cd is null
1427    and   pen.person_id =  p_person_id
1428    and   pen.business_group_id = p_business_group_id
1429    and   pen.prtt_enrt_rslt_id = prv.prtt_enrt_rslt_id
1430    and   pen.ptip_id = p_ptip_id
1431    and   prv.prtt_rt_val_stat_cd is null
1432    and   prv.rt_end_dt >=  p_rt_end_dt
1433    and   prv.acty_base_rt_id = abr.acty_base_rt_id
1434    and   p_effective_date between abr.effective_start_date
1435                   and abr.effective_end_date;
1436    --
1437    cursor c_prtt_rt_val_adj (p_per_in_ler_id number,
1438                             p_prtt_rt_val_id number) is
1439    select null
1440    from ben_le_clsn_n_rstr
1441    where BKUP_TBL_TYP_CD = 'BEN_PRTT_RT_VAL_ADJ'
1442    AND   BKUP_TBL_ID = p_prtt_rt_val_id
1443    AND   PER_IN_LER_ID  = p_per_in_ler_id;
1444    --
1445    -- end 7206471
1446   l_sspnd_enrt_rt                c_sspnd_enrt_rt%ROWTYPE;
1447 
1448   l_ann_mn_elcn_val  number := 0;
1449   l_ann_mx_elcn_val  number := 0;
1450   l_ptd_balance      number := 0;
1451   l_clm_balance      number := 0;
1452   l_pl_name          varchar2(240);
1453   --GEVITY
1454   l_dfnd_dummy number;
1455   l_ann_dummy  number;
1456   l_cmcd_dummy number;
1457   --END GEVITY
1458   l_fonm_cvg_strt_dt  date;
1459   l_input_value_id    number;
1460   l_global_pil_rec    ben_global_enrt.g_global_pil_rec_type;
1461   l_unrestricted      varchar2(1) := 'N';
1462   l_compute_val       number; --
1463   l_rt_val_param      number; --| 5259005 -- New vars to hold p_rt_val, p_ann_rt_val
1464   l_ann_rt_val_param  number; --|
1465   --
1466   begin
1467 
1468     g_debug := hr_utility.debug_enabled;
1469     if g_debug then
1470        hr_utility.set_location('Entering:'||l_proc, 5);
1471        hr_utility.set_location('enrt_rt:'||p_enrt_rt_id, 5);
1472        hr_utility.set_location('p_prtt_rt_val_id:'||p_prtt_rt_val_id,5);
1473        hr_utility.set_location('p_per_in_ler_id:'||p_per_in_ler_id,5);
1474     end if;
1475     --
1476     ben_global_enrt.get_pil  -- per in ler
1477     (p_per_in_ler_id          => p_per_in_ler_id
1478     ,p_global_pil_rec         => l_global_pil_rec);
1479 
1480     l_lf_evt_ocrd_dt := l_global_pil_rec.lf_evt_ocrd_dt;
1481     --
1482     l_effective_date := nvl(l_lf_evt_ocrd_dt,p_effective_date);
1483 
1484     if l_global_pil_rec.typ_cd = 'SCHEDDU' then
1485        l_unrestricted := 'Y';
1486     end if;
1487 
1488     if ben_manage_life_events.fonm is null then
1489 
1490        open  c_epe;
1491        fetch c_epe into l_fonm_cvg_strt_dt;
1492        close c_epe;
1493 
1494        if l_fonm_cvg_strt_dt is not null then
1495           ben_manage_life_events.fonm := 'Y';
1496           ben_manage_life_events.g_fonm_cvg_strt_dt := l_fonm_cvg_strt_dt;
1497        else
1498           ben_manage_life_events.fonm := 'N';
1499           ben_manage_life_events.g_fonm_cvg_strt_dt := null;
1500           ben_manage_life_events.g_fonm_rt_strt_dt := null;
1501        end if;
1502     else
1503       if ben_manage_life_events.g_fonm_cvg_strt_dt is null and  ben_manage_life_events.fonm = 'Y'  then
1504          open  c_epe;
1505          fetch c_epe into l_fonm_cvg_strt_dt;
1506          close c_epe;
1507          ben_manage_life_events.g_fonm_cvg_strt_dt := l_fonm_cvg_strt_dt;
1508 
1509       end if ;
1510 
1511     end if;
1512     --
1513     if p_bnft_amt_changed then
1514       if g_debug then
1515         hr_utility.set_location('p_bnft_amt changed:',5);
1516       end if;
1517     end if;
1518     --
1519     ben_det_enrt_rates.set_global_enrt_rt
1520        (p_enrt_rt_id   => p_enrt_rt_id);
1521     --
1522     -- Get the new values to be stored or updated
1523     --
1524     p_prtt_rt_val_id:=null;
1525 
1526     open c_enrt_rt;
1527     fetch c_enrt_rt into l_enrt_rt;
1528     if c_enrt_rt%notfound then
1529       close c_enrt_rt;
1530       fnd_message.set_name('BEN','BEN_91825_ENRT_RT_NOT_FOUND');
1531       fnd_message.set_token('PROC',l_proc);
1532       fnd_message.set_token('ENRT_RT_ID',to_char(p_enrt_rt_id));
1533       fnd_message.set_token('BG_ID',to_char(p_business_group_id));
1534       if g_debug then
1535         hr_utility.set_location('BEN_91825_ENRT_RT_NOT_FOUND', 20);
1536       end if;
1537       fnd_message.raise_error;
1538     end if;  -- notfound
1539     close c_enrt_rt;
1540 
1541     if ben_manage_life_events.fonm = 'Y' then
1542        ben_manage_life_events.g_fonm_rt_strt_dt := nvl(p_rt_strt_dt,l_enrt_rt.rt_strt_dt);
1543        l_effective_date := nvl(ben_manage_life_events.g_fonm_rt_strt_dt,l_effective_date);
1544     end if;
1545 
1546     if g_debug then
1547       hr_utility.set_location(l_proc, 30);
1548     end if;
1549     --
1550     -- bug fix 3457483
1551     --
1552     -- Get the payroll id to be passed to ben_distribute_rates.
1553     --
1554     ben_element_entry.get_abr_assignment
1555      (p_person_id       => p_person_id
1556      ,p_effective_date  => l_effective_date
1557      ,p_acty_base_rt_id => l_enrt_rt.acty_base_rt_id
1558      ,p_organization_id => l_organization_id
1559      ,p_payroll_id      => l_payroll_id
1560      ,p_assignment_id   => l_assignment_id
1561      );
1562     -- end bug fix 3457483
1563     --
1564     if l_enrt_rt.cmcd_acty_ref_perd_cd = 'PPF' then
1565        l_element_type_id := l_enrt_rt.element_type_id;
1566     end if;
1567     --
1568     open c_pet;
1569     fetch c_pet into l_processing_type;
1570     close c_pet;
1571     --
1572     -- for non recurring rates the rate end date is assigned the rate start date
1573     --
1574     if l_processing_type = 'N' or
1575        l_enrt_rt.rcrrg_cd = 'ONCE' then
1576 
1577        l_non_recurring_rt := true;
1578        l_rt_end_dt := p_rt_strt_dt;
1579 
1580     end if;
1581     --
1582     if p_rt_strt_dt is not null and
1583        l_rt_end_dt is not null  and
1584        p_rt_strt_dt > l_rt_end_dt then
1585       --
1586       fnd_message.set_name('BEN','BEN_92688_RT_STRT_DT_GT_END_DT');
1587       fnd_message.set_token('START',p_rt_strt_dt);
1588       fnd_message.set_token('END',l_rt_end_dt);
1589       fnd_message.raise_error;
1590       --
1591     end if;
1592     --
1593     -- Get data from old rate
1594     --
1595     hr_utility.set_location(' BKKKK l_enrt_rt.prtt_rt_val_id ' || l_enrt_rt.prtt_rt_val_id, 300);
1596     hr_utility.set_location(' BKKKK p_enrt_rt_id ' || p_enrt_rt_id, 300);
1597     hr_utility.set_location(' BKKKK p_business_group_id  ' || p_business_group_id, 300);
1598     hr_utility.set_location(' BKKKK l_enrt_rt.elig_per_elctbl_chc_id ' || l_enrt_rt.elig_per_elctbl_chc_id, 300);
1599     --
1600     if l_enrt_rt.prtt_rt_val_id is not null then
1601       -- Get data from old rate
1602       open c_prtt_rt_val_1;
1603       fetch c_prtt_rt_val_1 into
1604         l_old_rt_typ_cd,
1605         l_old_tx_typ_cd,
1606         l_old_acty_typ_cd,
1607         l_old_mlt_cd,
1608         l_old_acty_ref_perd_cd,
1609         l_old_rt_val,
1610         l_old_prtt_enrt_rslt_id,
1611         l_old_business_group_id,
1612         l_old_object_version_number,
1613         l_old_rt_strt_dt,
1614         l_old_ann_rt_val,
1615         l_old_bnft_rt_typ_cd,
1616         l_old_cmcd_ref_perd_cd,
1617         l_old_cmcd_rt_val,
1618         l_old_dsply_on_enrt_flag,
1619         l_old_cvg_amt_calc_mthd_id,
1620         l_old_actl_prem_id,
1621         l_old_comp_lvl_fctr_id,
1622         l_old_rt_end_dt,
1623         l_old_per_in_ler_id,
1624         l_old_element_entry_value_id,
1625         l_old_elctns_made_dt,
1626         l_old_rt_ovridn_flag,
1627         l_old_rt_ovridn_thru_dt ;
1628 
1629       if c_prtt_rt_val_1%notfound then
1630         close c_prtt_rt_val_1;
1631         if g_debug then
1632           hr_utility.set_location('BEN_92103_NO_PRTT_RT_VAL', 35);
1633         end if;
1634         fnd_message.set_name('BEN','BEN_92103_NO_PRTT_RT_VAL');
1635         fnd_message.set_token('PROC',l_proc);
1636         fnd_message.set_token('PRTT_RT_VAL_ID',to_char(l_enrt_rt.prtt_rt_val_id));
1637         fnd_message.raise_error;
1638       end if;
1639 
1640       if g_debug then
1641          hr_utility.set_location('ll_old_rt_strt_dt'||l_old_rt_strt_dt,99);
1642          hr_utility.set_location('l_old_per_in_ler_id'||l_old_per_in_ler_id,99);
1643          hr_utility.set_location('l_old_rt end date'||l_old_rt_end_dt,99);
1644       end if;
1645       close c_prtt_rt_val_1;
1646     end if;
1647     --
1648     -- Get result information
1649     --
1650     ben_global_enrt.get_pen  -- result
1651        (p_prtt_enrt_rslt_id      => p_prtt_enrt_rslt_id
1652        ,p_effective_date         => p_effective_date
1653        ,p_global_pen_rec         => l_global_pen_rec);
1654 
1655     hr_utility.set_location('l_global_pen_rec',99);
1656     --
1657     -- determine rate start date as long as there is not an existing prtt_rt_val
1658     -- record, or if there is an exising prtt_rt_val record, that the record was
1659     -- NOT updated during this per-in-ler (bensuenr updates the rt-strt-dt).
1660     -- part of bug 1121022
1661     --
1662     if l_enrt_rt.rt_strt_dt_cd = 'ENTRBL' and p_rt_strt_dt is not null then
1663       -- The rate start date is the parameter value if the date code
1664       -- is enterable.
1665       l_enrt_rt.rt_strt_dt := p_rt_strt_dt;
1666     elsif l_enrt_rt.prtt_rt_val_id is not null and
1667           l_old_per_in_ler_id = p_per_in_ler_id and
1668           l_unrestricted = 'N' then -- #5303167
1669           hr_utility.set_location('l_global_pen_rec2',99);
1670        -- check unrestricted life event
1671        -- if l_unrestricted = 'N' then #5303167 moved this condition to above elsif
1672          --
1673          -- we already have the correct prv created
1674          --
1675          p_prtt_rt_val_id := l_enrt_rt.prtt_rt_val_id;
1676          if l_enrt_rt.rt_strt_dt_cd in ('FDPPFED','FDPPOED') then
1677            hr_utility.set_location('l_global_pen_rec3',99);
1678            ben_determine_date.main(
1679                p_date_cd                => l_enrt_rt.rt_strt_dt_cd,
1680                p_per_in_ler_id          => p_per_in_ler_id,
1681                p_person_id              => p_person_id,
1682                p_pgm_id                 => p_pgm_id,
1683                p_pl_id                  => p_pl_id,
1684                p_oipl_id                => p_oipl_id,
1685                p_business_group_id      => p_business_group_id,
1686                p_formula_id             => l_enrt_rt.rt_strt_dt_rl,
1687                p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id,
1688                p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id,
1689                p_effective_date         => p_effective_date,
1690                p_returned_date          => l_enrt_rt.rt_strt_dt
1691              );
1692          else
1693           --
1694           l_enrt_rt.rt_strt_dt := l_old_rt_strt_dt;
1695           --
1696          end if;
1697          --
1698        -- end if; #5303167
1699        --
1700     elsif l_enrt_rt.rt_strt_dt_cd is not null then
1701       if g_debug then
1702         hr_utility.set_location(l_proc, 40);
1703       end if;
1704       ben_determine_date.main(
1705         p_date_cd                => l_enrt_rt.rt_strt_dt_cd,
1706         p_per_in_ler_id          => p_per_in_ler_id,
1707         p_person_id              => p_person_id,
1708         p_pgm_id                 => p_pgm_id,
1709         p_pl_id                  => p_pl_id,
1710         p_oipl_id                => p_oipl_id,
1711         p_business_group_id      => p_business_group_id,
1712         p_formula_id             => l_enrt_rt.rt_strt_dt_rl,
1713         p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id,
1714         p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id,
1715         p_effective_date         => p_effective_date,
1716         p_returned_date          => l_enrt_rt.rt_strt_dt
1717       );
1718       --bug#4078828 - rate start date gets changed because of rate code based on election
1719       open c_abr (l_enrt_rt.acty_base_rt_id,l_enrt_rt.rt_strt_dt);
1720       fetch c_abr into l_ele_entry_val_cd, l_enrt_rt.element_type_id,
1721                         l_enrt_rt.input_value_id;
1722       close c_abr;
1723       --
1724     end if;
1725     if g_debug then
1726       hr_utility.set_location(l_proc, 45);
1727     end if;
1728     if (l_enrt_rt.rt_strt_dt is null) then
1729       if g_debug then
1730         hr_utility.set_location('BEN_91455_RT_STRT_DT_NOT_FOUND id:'||
1731           to_char(p_pl_id), 50);
1732       end if;
1733       fnd_message.set_name('BEN','BEN_91455_RT_STRT_DT_NOT_FOUND');
1734       fnd_message.set_token('PROC',l_proc);
1735       fnd_message.set_token('PLAN_ID', to_char(p_pl_id));
1736       fnd_message.raise_error;
1737     end if; -- date is null
1738 
1739     if p_prtt_rt_val_id is null then
1740 
1741        if  l_enrt_rt.prtt_rt_val_id is null or
1742            l_enrt_rt.rt_strt_dt < l_old_rt_strt_dt or
1743            l_enrt_rt.rt_strt_dt > l_old_rt_end_dt then
1744 
1745            open c_prtt_rt_val_2;
1746            fetch c_prtt_rt_val_2 into
1747            p_prtt_rt_val_id,
1748            l_old_rt_typ_cd,
1749            l_old_tx_typ_cd,
1750            l_old_acty_typ_cd,
1751            l_old_mlt_cd,
1752            l_old_acty_ref_perd_cd,
1753            l_old_rt_val,
1754            l_old_prtt_enrt_rslt_id,
1755            l_old_business_group_id,
1756            l_old_object_version_number,
1757            l_old_rt_strt_dt,
1758            l_old_ann_rt_val,
1759            l_old_bnft_rt_typ_cd,
1760            l_old_cmcd_ref_perd_cd,
1761            l_old_cmcd_rt_val,
1762            l_old_dsply_on_enrt_flag,
1763            l_old_cvg_amt_calc_mthd_id,
1764            l_old_actl_prem_id,
1765            l_old_comp_lvl_fctr_id,
1766            l_old_rt_end_dt,
1767            l_old_per_in_ler_id,
1768            l_old_element_entry_value_id,
1769            l_old_elctns_made_dt,
1770            l_old_rt_ovridn_flag,
1771            l_old_rt_ovridn_thru_dt ;
1772 
1773            if c_prtt_rt_val_2%notfound then
1774               p_prtt_rt_val_id := null;
1775               l_old_rt_typ_cd := null;
1776               l_old_tx_typ_cd := null;
1777               l_old_acty_typ_cd := null;
1778               l_old_mlt_cd := null;
1779               l_old_acty_ref_perd_cd := null;
1780               l_old_rt_val := null;
1781               l_old_prtt_enrt_rslt_id := null;
1782               l_old_business_group_id := null;
1783               l_old_object_version_number := null;
1784               l_old_rt_strt_dt := null;
1785               l_old_ann_rt_val := null;
1786               l_old_bnft_rt_typ_cd := null;
1787               l_old_cmcd_ref_perd_cd := null;
1788               l_old_cmcd_rt_val := null;
1789               l_old_dsply_on_enrt_flag := 'N' ; -- null; # 3273247
1790               l_old_cvg_amt_calc_mthd_id := null;
1791               l_old_actl_prem_id := null;
1792               l_old_comp_lvl_fctr_id := null;
1793               l_old_rt_end_dt := null;
1794               l_old_per_in_ler_id := null;
1795               l_old_element_entry_value_id := null;
1796               l_old_elctns_made_dt := null;
1797               l_old_rt_ovridn_flag := 'N' ; -- null; # 3273247
1798               l_old_rt_ovridn_thru_dt := null;
1799            end if;
1800            close c_prtt_rt_val_2;
1801        else
1802           p_prtt_rt_val_id := l_enrt_rt.prtt_rt_val_id;
1803        end if;
1804 
1805     end if;
1806     if g_debug then
1807        hr_utility.set_location('p_prtt_rt_val_id:'||p_prtt_rt_val_id, 3);
1808     end if;
1809     --
1810     --Bug#2734491 - Child rate should behave the same way as parent
1811     --
1812     if l_enrt_rt.rt_mlt_cd = 'PRNT' and l_enrt_rt.use_calc_acty_bs_rt_flag = 'Y' then
1813        open c_abr2(l_effective_date,l_enrt_rt.acty_base_rt_id ) ;
1814        fetch c_abr2 into l_prnt_abr ;
1815        if c_abr2%found then
1816          if l_prnt_abr.rt_mlt_cd = 'SAREC' or l_prnt_abr.entr_ann_val_flag = 'Y' then
1817         --- take the rate from the parent rcord
1818             l_prnt_ann_rt := 'Y';
1819             open c_prv2(p_prtt_enrt_rslt_id,l_prnt_abr.acty_base_rt_id );
1820             fetch  c_prv2 into l_prnt_rt_val ,l_prnt_ann_val;
1821             close  c_prv2 ;
1822          end if ;
1823        end if;
1824        close c_abr2;
1825     end if;
1826 
1827   -- determine new rate values
1828   -- rajkiran
1829   -- Moved part of code below from Enrollment forms PL/SQl Libraries
1830   -- to have calculated values for p_rt_val, p_ann_rt_val
1831   --
1832   -- When the user has changed the value in ann_val, (which
1833   -- is an annual value), we need to compute the per-period
1834   -- value and put it into either the pre-tax val or after
1835   -- tax val depending on which enter_val_flag is on.
1836   -- We know if the user entered the value because then the
1837   -- ann_val and ann_val_hide are different.
1838   --
1839    l_ann_rt_val_param := p_ann_rt_val ;
1840    l_rt_val_param     := p_rt_val ;
1841   --
1842   hr_utility.set_location('l_ann_rt_val_param ->'||l_ann_rt_val_param,9);
1843   hr_utility.set_location('l_rt_val_param     ->'||l_rt_val_param    ,9);
1844   hr_utility.set_location('p_ann_rt_val ->'||p_ann_rt_val,9);
1845   hr_utility.set_location('p_rt_val     ->'||p_rt_val    ,9);
1846   --
1847   hr_utility.set_location('entr_ann_val ->'||l_enrt_rt.entr_ann_val_flag, 9);
1848   hr_utility.set_location('entr_val     ->'||l_enrt_rt.entr_val_at_enrt_flag, 9);
1849   --
1850   /*
1851    -- commented for bug: 5584813
1852    -- this code moved to a procedure calc_rt_ann_rt_vals
1853   if l_enrt_rt.entr_ann_val_flag = 'Y' then
1854         -- Enter Annual Value
1855         IF l_enrt_rt.rate_periodization_rl  IS NOT NULL AND
1856            l_enrt_rt.acty_base_rt_id        IS NOT NULL THEN
1857           --
1858           ben_element_entry.get_abr_assignment
1859               (p_person_id       => p_person_id
1860               ,p_effective_date  => l_effective_date
1861               ,p_acty_base_rt_id => l_enrt_rt.acty_base_rt_id
1862               ,p_organization_id => l_organization_id
1863               ,p_payroll_id      => l_payroll_id
1864               ,p_assignment_id   => l_assignment_id
1865               );
1866           --
1867           l_ann_dummy := p_ann_rt_val;
1868           --
1869           ben_distribute_rates.periodize_with_rule(
1870               p_formula_id             => l_enrt_rt.rate_periodization_rl
1871              ,p_effective_date         => l_effective_date
1872              ,p_assignment_id          => l_assignment_id
1873              ,p_convert_from_val       => l_ann_dummy
1874              ,p_convert_from           => 'ANNUAL'
1875              ,p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id
1876              ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
1877              ,p_business_group_id      => p_business_group_id
1878              ,p_enrt_rt_id             => p_enrt_rt_id
1879              ,p_ann_val                => l_dfnd_dummy
1880              ,p_cmcd_val               => l_cmcd_dummy
1881              ,p_val                    => l_compute_val
1882           );
1883           --
1884         ELSE
1885          l_compute_val := ben_distribute_rates.annual_to_period(
1886                             p_amount  => p_ann_rt_val
1887                            ,p_enrt_rt_id => p_enrt_rt_id
1888                            ,p_elig_per_elctbl_chc_id => null
1889                            ,p_acty_ref_perd_cd => null
1890                            ,p_business_group_id => p_business_group_id
1891                            ,p_effective_date => l_effective_date
1892                            ,p_lf_evt_ocrd_dt => null
1893                            ,p_complete_year_flag => 'Y'
1894                            ,p_use_balance_flag => 'Y'
1895                            ,p_start_date => null
1896                            ,p_end_date => null);
1897          --
1898         END IF; --GEVITY
1899 	   l_rt_val_param := l_compute_val ;
1900   --
1901   -- When the user has changed the value in the pre-tax or
1902   -- after-tax columns, we must compute the annual value
1903   -- which goes into the bnft_val column.
1904   --
1905   elsif l_enrt_rt.entr_val_at_enrt_flag = 'Y' then
1906      --
1907          IF l_enrt_rt.rate_periodization_rl  IS NOT NULL AND
1908             l_enrt_rt.acty_base_rt_id        IS NOT NULL THEN
1909              --
1910              ben_element_entry.get_abr_assignment
1911               (p_person_id       => p_person_id
1912               ,p_effective_date  => l_effective_date
1913               ,p_acty_base_rt_id => l_enrt_rt.acty_base_rt_id
1914               ,p_organization_id => l_organization_id
1915               ,p_payroll_id      => l_payroll_id
1916               ,p_assignment_id   => l_assignment_id
1917               );
1918              --
1919              l_dfnd_dummy := p_rt_val;
1920              --
1921              ben_distribute_rates.periodize_with_rule(
1922                  p_formula_id             => l_enrt_rt.rate_periodization_rl
1923                 ,p_effective_date         => l_effective_date
1924                 ,p_assignment_id          => l_assignment_id
1925                 ,p_convert_from_val       => l_dfnd_dummy
1926                 ,p_convert_from           => 'DEFINED'
1927                 ,p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id
1928                 ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
1929                 ,p_business_group_id      => p_business_group_id
1930                 ,p_enrt_rt_id             => p_enrt_rt_id
1931                 ,p_ann_val                => l_compute_val
1932                 ,p_cmcd_val               => l_cmcd_dummy
1933                 ,p_val                    => l_cmcd_dummy
1934              );
1935              --
1936          ELSE
1937            l_compute_val := ben_distribute_rates.period_to_annual(
1938                             p_amount                 => p_rt_val
1939                            ,p_enrt_rt_id             => p_enrt_rt_id
1940                            ,p_elig_per_elctbl_chc_id => null
1941                            ,p_acty_ref_perd_cd       => null
1942                            ,p_business_group_id      => p_business_group_id
1943                            ,p_effective_date         => l_effective_date
1944                            ,p_lf_evt_ocrd_dt         => null
1945                            ,p_complete_year_flag     => 'Y'
1946                            ,p_use_balance_flag       => 'Y'
1947                            ,p_start_date             => null
1948                            ,p_end_date               => null);
1949          --
1950          END IF; --GEVITY
1951 	   l_ann_rt_val_param := l_compute_val;
1952       --
1953   end if;
1954   */
1955 
1956   calc_rt_ann_rt_vals (
1957    p_rt_val                  => l_rt_val_param,
1958    p_ann_rt_val              => l_ann_rt_val_param,
1959    p_person_id               => p_person_id,
1960    p_effective_date          => l_effective_date,
1961    p_acty_base_rt_id         => l_enrt_rt.acty_base_rt_id,
1962    p_rate_periodization_rl   => l_enrt_rt.rate_periodization_rl,
1963    p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id,
1964    p_business_group_id       => p_business_group_id,
1965    p_enrt_rt_id              => p_enrt_rt_id,
1966    p_entr_ann_val_flag       => l_enrt_rt.entr_ann_val_flag,
1967    p_entr_val_at_enrt_flag   => l_enrt_rt.entr_val_at_enrt_flag);
1968 
1969 
1970   hr_utility.set_location('l_ann_rt_val_param ->'||l_ann_rt_val_param,9);
1971   hr_utility.set_location('l_rt_val_param     ->'||l_rt_val_param    ,9);
1972   hr_utility.set_location('p_ann_rt_val ->'||p_ann_rt_val,9);
1973   hr_utility.set_location('p_rt_val     ->'||p_rt_val    ,9);
1974 
1975   -- rajkiran
1976 
1977     --
1978     --bug 1888085 we need to eliminate the following 'PCT' condition if
1979     --use_calc_acty_bs_rt_flag is set to 'Y'
1980     --
1981     if l_enrt_rt.rt_typ_cd = 'PCT' and l_enrt_rt.use_calc_acty_bs_rt_flag <> 'Y' then
1982       if l_enrt_rt.entr_ann_val_flag = 'Y' then
1983         --
1984         -- get values from annual value
1985         --
1986         l_ann_rt_val       := l_ann_rt_val_param; -- changed from p_ann_rt_val to l_ann_rt_val_param
1987         l_rt_val           := l_ann_rt_val_param;
1988         l_enrt_rt.cmcd_val := l_ann_rt_val_param;
1989       else
1990         --
1991         -- get values from periodic value
1992         --
1993         l_ann_rt_val       := l_rt_val_param; -- changed from p_rt_val to l_rt_val_param
1994         l_rt_val           := l_rt_val_param;
1995         l_enrt_rt.cmcd_val := l_rt_val_param;
1996         --
1997       end if;
1998       --
1999     else
2000       --
2001       if l_enrt_rt.entr_ann_val_flag = 'Y' or l_prnt_ann_rt = 'Y' then
2002         --
2003         if g_debug then
2004           hr_utility.set_location('enter annual value',100);
2005         end if;
2006         if l_rt_val_param is null then -- changed from p_rt_val to l_rt_val_param
2007           --
2008           --GEVITY
2009           --
2010           IF l_enrt_rt.rate_periodization_rl IS NOT NULL THEN
2011             --
2012             l_ann_dummy := l_ann_rt_val_param ; --p_ann_rt_val; 5259005
2013             --
2014             ben_distribute_rates.periodize_with_rule
2015                   (p_formula_id             => l_enrt_rt.rate_periodization_rl
2016                   ,p_effective_date         => l_effective_date
2017                   ,p_assignment_id          => l_assignment_id
2018                   ,p_convert_from_val       => l_ann_dummy
2019                   ,p_convert_from           => 'ANNUAL'
2020                   ,p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id
2021                   ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
2022                   ,p_business_group_id      => p_business_group_id
2023                   ,p_enrt_rt_id             => p_enrt_rt_id
2024                   ,p_ann_val                => l_ann_rt_val
2025                   ,p_cmcd_val               => l_enrt_rt.cmcd_val
2026                   ,p_val                    => l_rt_val
2027             );
2028             --
2029           ELSE
2030             -- use ann_rt_val to drive other values
2031             --
2032             --
2033             l_enrt_rt.cmcd_val := ben_distribute_rates.annual_to_period
2034                   (p_amount                  => l_ann_rt_val_param, -- p_ann_rt_val, 5259005
2035                    p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id,
2036                    p_acty_ref_perd_cd        => l_enrt_rt.cmcd_acty_ref_perd_cd,
2037                    p_business_group_id       => p_business_group_id,
2038                    p_effective_date          => l_effective_date,
2039                    p_complete_year_flag      => 'Y',
2040                    p_payroll_id              => l_payroll_id,
2041                    p_element_type_id         => l_element_type_id,
2042                    p_person_id               => p_person_id
2043                    );
2044             --Bug#3540351
2045             if l_enrt_rt.cmcd_val < 0 then
2046                l_enrt_rt.cmcd_val := 0;
2047                l_rt_val := 0;
2048             else
2049               --Bug 3253180
2050               --l_rt_val:= l_enrt_rt.cmcd_val;
2051               --
2052               l_rt_val := ben_distribute_rates.annual_to_period
2053                       (p_amount                  => l_ann_rt_val_param, --p_ann_rt_val, 5259005
2054                        p_enrt_rt_id              => p_enrt_rt_id,
2055                        p_acty_ref_perd_cd        => p_acty_ref_perd_cd,
2056                        p_business_group_id       => p_business_group_id,
2057                        p_effective_date          => l_effective_date,
2058                        p_complete_year_flag      => 'Y',
2059                        p_use_balance_flag        => 'Y',
2060                        p_payroll_id              => l_payroll_id,
2061                        p_element_type_id         => l_element_type_id,
2062                        p_rounding_flag           => 'N',
2063                        p_person_id               => p_person_id
2064                        );
2065            end if;
2066             --
2067             l_rt_val := round(l_rt_val,4);
2068             l_ann_rt_val := l_ann_rt_val_param; --p_ann_rt_val; 5259005
2069             --
2070           END IF; --GEVITY
2071           --
2072           if g_debug then
2073             hr_utility.set_location('IK p_rt_val is null l_rt_val '||l_rt_val,101);
2074             hr_utility.set_location('IK p_rt_val is null l_ann_rt_val: '||l_ann_rt_val,101);
2075             hr_utility.set_location('IK p_rt_val is null l_enrt_rt.cmcd_val'||l_enrt_rt.cmcd_val,101);
2076           end if;
2077           --
2078         else
2079           --this condition added if the l_rt_val is not gone throu the post enrl calc
2080           -- then intialised here
2081           /*
2082           if l_rt_val is null then
2083              l_rt_val:=p_rt_val;
2084              l_ann_rt_val:=p_ann_rt_val;
2085           end if ;
2086           */
2087           --
2088           l_ann_rt_val := l_ann_rt_val_param; -- p_ann_rt_val; 5259005
2089           --
2090           -- calculate annual rate for the child
2091           if l_prnt_ann_rt = 'Y' then
2092              --
2093              if g_debug then
2094                hr_utility.set_location('Annual value'||l_prnt_ann_val,11);
2095              end if;
2096              benutils.rt_typ_calc
2097               (p_rt_typ_cd      => l_enrt_rt.abr_typ_cd
2098               ,p_val            => l_enrt_rt.abr_val
2099               ,p_val_2          => l_prnt_ann_val
2100               ,p_calculated_val => l_ann_rt_val);
2101              --
2102              if (l_enrt_rt.rndg_cd is not null or
2103                    l_enrt_rt.rndg_rl is not null) then
2104                --
2105                 l_rounded_value := benutils.do_rounding
2106                   (p_rounding_cd     => l_enrt_rt.rndg_cd,
2107                    p_rounding_rl     => l_enrt_rt.rndg_rl,
2108                    p_value           => l_ann_rt_val,
2109                    p_effective_date  => l_effective_date);
2110                 l_ann_rt_val := l_rounded_value;
2111              end if;
2112              --
2113              --GEVITY
2114              --
2115              IF l_enrt_rt.rate_periodization_rl IS NOT NULL THEN
2116                --
2117                l_ann_dummy := l_ann_rt_val;
2118                --
2119                ben_distribute_rates.periodize_with_rule
2120                   (p_formula_id             => l_enrt_rt.rate_periodization_rl
2121                   ,p_effective_date         => l_effective_date
2122                   ,p_assignment_id          => l_assignment_id
2123                   ,p_convert_from_val       => l_ann_dummy
2124                   ,p_convert_from           => 'ANNUAL'
2125                   ,p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id
2126                   ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
2127                   ,p_business_group_id      => p_business_group_id
2128                   ,p_enrt_rt_id             => p_enrt_rt_id
2129                   ,p_ann_val                => l_ann_rt_val
2130                   ,p_cmcd_val               => l_enrt_rt.cmcd_val
2131                   ,p_val                    => l_rt_val
2132                );
2133                --
2134              ELSE
2135                --
2136                l_rt_val := ben_distribute_rates.annual_to_period(
2137                                       p_amount  => l_ann_rt_val
2138                                      ,p_enrt_rt_id =>p_enrt_rt_id
2139                                      ,p_elig_per_elctbl_chc_id => null
2140                                      ,p_acty_ref_perd_cd => null
2141                                      ,p_business_group_id =>p_business_group_id
2142                                      ,p_effective_date => l_effective_date
2143                                      ,p_lf_evt_ocrd_dt => null
2144                                      ,p_complete_year_flag => 'Y'
2145                                      ,p_use_balance_flag => 'Y'
2146                                      ,p_start_date => null
2147                                      ,p_end_date => null
2148                                      ,p_rounding_flag => 'N'
2149                                      ,p_person_id     => p_person_id); --Bug 2149438
2150                 --
2151                 -- Bug 2149438 I am doing it to 3 because right now we have 2 digit rouding for
2152                 -- the final value. Once we implement the rounding completely for the
2153                 -- rate value this needs to be atleast one digit more than the
2154                 -- actual rounding code dictates.
2155                 --
2156                 if l_rt_val < 0 then
2157                    l_rt_val := 0;
2158                    l_enrt_rt.cmcd_val := 0;
2159                 else
2160                   --
2161                   --
2162                   --
2163                   l_enrt_rt.cmcd_val := ben_distribute_rates.annual_to_period
2164                       (p_amount                  => l_ann_rt_val,
2165                        --p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id,
2166                        p_enrt_rt_id              => p_enrt_rt_id,
2167                        p_acty_ref_perd_cd        => l_enrt_rt.cmcd_acty_ref_perd_cd,
2168                        p_business_group_id       => p_business_group_id,
2169                        p_effective_date          => l_effective_date,
2170                        p_use_balance_flag        => 'Y',
2171                --      p_complete_year_flag      => 'Y',
2172                        p_start_date              => l_enrt_rt.rt_strt_dt,
2173                        p_payroll_id              => l_payroll_id,
2174                        p_element_type_id         => l_element_type_id,
2175                        p_person_id               => p_person_id
2176                        );
2177                 end if;
2178                 --
2179              END IF; --GEVITY
2180           else -- let us find the right l_rt_val for annual rate using proper rounding
2181             -- Bug 2833116
2182             -- Bug 2675486 fixes for FSA
2183             l_sarec_compute := true;
2184             if l_old_ann_rt_val = l_ann_rt_val and l_old_rt_strt_dt is not null
2185                and l_enrt_rt.rate_periodization_rl IS NULL then
2186               -- Case - Benefit amount not changed and currently enrolled case
2187               -- See if the current rate is started in the present popl yr period.
2188               -- If started in current yr_perd then DONT compute defined and comm amounts
2189               -- else compute the defined comm amounts.
2190               -- l_sarec_compute
2191               open c_pl_popl_yr_period_current(p_pl_id,p_pgm_id,l_effective_date);
2192                 fetch c_pl_popl_yr_period_current into l_yp_start_date ;
2193               close c_pl_popl_yr_period_current ;
2194               --
2195               if l_old_rt_strt_dt >= l_yp_start_date then
2196                 -- Already enrolled in the same yr_perd and amount not changed so
2197                 -- dont recompute the amounts
2198                   --bug#3364910 - check for payroll type change
2199                     l_period_type:=null;
2200                     open c_payroll_type_changed(
2201                           cp_person_id           =>p_person_id,
2202                           cp_business_group_id   =>p_business_group_id,
2203                           cp_effective_date      =>l_enrt_rt.rt_strt_dt,
2204                           cp_orig_effective_date =>l_old_rt_strt_dt);
2205                     fetch c_payroll_type_changed into l_period_type;
2206                     close c_payroll_type_changed;
2207                --      no change in payroll then dont recompute
2208                     if l_period_type is null then
2209 
2210                        if g_debug then
2211                          hr_utility.set_location('Same Yr Period and same rate ' ,123);
2212                        end if;
2213                        l_sarec_compute := false ;
2214                     end if;
2215               end if ;
2216               --
2217             end if ;
2218             --
2219             if l_sarec_compute then
2220               --GEVITY
2221               --
2222               IF l_enrt_rt.rate_periodization_rl IS NOT NULL THEN
2223                 --
2224                 l_ann_dummy := l_ann_rt_val;
2225                 --
2226                 ben_distribute_rates.periodize_with_rule
2227                   (p_formula_id             => l_enrt_rt.rate_periodization_rl
2228                   ,p_effective_date         => l_effective_date
2229                   ,p_assignment_id          => l_assignment_id
2230                   ,p_convert_from_val       => l_ann_dummy
2231                   ,p_convert_from           => 'ANNUAL'
2232                   ,p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id
2233                   ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
2234                   ,p_business_group_id      => p_business_group_id
2235                   ,p_enrt_rt_id             => p_enrt_rt_id
2236                   ,p_ann_val                => l_ann_rt_val
2237                   ,p_cmcd_val               => l_enrt_rt.cmcd_val
2238                   ,p_val                    => l_rt_val
2239                 );
2240                 --
2241               ELSE
2242                 --
2243                 l_rt_val := ben_distribute_rates.annual_to_period
2244                       (p_amount                  => l_ann_rt_val,
2245                        p_enrt_rt_id              => p_enrt_rt_id,
2246                        p_acty_ref_perd_cd        => p_acty_ref_perd_cd,
2247                        p_business_group_id       => p_business_group_id,
2248                        p_effective_date          => l_effective_date,
2249                        p_complete_year_flag      => 'Y',
2250                        p_use_balance_flag        => 'Y',
2251                        p_payroll_id              => l_payroll_id,
2252                        p_element_type_id         => l_element_type_id,
2253                        p_rounding_flag           => 'N',
2254                        p_person_id               => p_person_id
2255                        );
2256                 --
2257                 if l_rt_val < 0 then
2258                    l_rt_val := 0;
2259                    l_enrt_rt.cmcd_val := 0;
2260                 else
2261                   --
2262                   l_rt_val := round(l_rt_val,4);
2263                   --
2264                   l_enrt_rt.cmcd_val := ben_distribute_rates.annual_to_period
2265                         (p_amount                  => l_ann_rt_val,
2266                          --p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id,
2267                          p_enrt_rt_id              => p_enrt_rt_id,
2268                          p_acty_ref_perd_cd        => l_enrt_rt.cmcd_acty_ref_perd_cd,
2269                          p_business_group_id       => p_business_group_id,
2270                          p_effective_date          => l_effective_date,
2271                          p_use_balance_flag        => 'Y',
2272                          -- p_complete_year_flag      => 'Y',
2273                          p_start_date              => l_enrt_rt.rt_strt_dt,
2274                          p_payroll_id              => l_payroll_id,
2275                          p_element_type_id         => l_element_type_id,
2276                          p_person_id               => p_person_id
2277                          );
2278                   --
2279                 end if;
2280                 --
2281               END IF; --GEVITY
2282               --
2283               if g_debug then
2284                  hr_utility.set_location('IK p_rt_val is NOT null l_rt_val '||l_rt_val,101);
2285                  hr_utility.set_location('IK p_rt_val is NOT null l_ann_rt_val: '||l_ann_rt_val,101);
2286                  hr_utility.set_location('IK p_rt_val is NOT null l_enrt_rt.cmcd_val'||l_enrt_rt.cmcd_val,101);
2287               end if;
2288               --
2289             else
2290               --
2291               l_rt_val           := l_old_rt_val ;
2292               l_calc_ann_val     := l_ann_rt_val;
2293               l_enrt_rt.cmcd_val := l_old_cmcd_rt_val ;
2294               --
2295               if g_debug then
2296                 hr_utility.set_location('Continue old rate '||l_old_rt_val,123);
2297               end if;
2298               --
2299               if g_debug then
2300                 hr_utility.set_location(' l_old_cmcd_rt_val '||l_old_cmcd_rt_val,123);
2301               end if;
2302               --
2303             end if;  -- l_sarec_compute
2304             --
2305           end if;
2306           -- ann_rt_val and rt_val are set, set locals
2307           --
2308         end if;
2309       else
2310         --
2311         -- annual not entered
2312         --
2313        if l_enrt_rt.rt_mlt_cd <> 'SAREC' then
2314          --
2315          -- If the rate is based on coverage and the coverage value is entered
2316          -- at enrollment, we must re-calculate the rate value.
2317          --
2318          /*BUG 3804813 We don't need to check for l_enrt_rt.rt_mlt_cd <> 'FLFX'
2319            Lets recompute id entr_bnft_val_flag = 'Y' which makes perfect sense.
2320          if (l_enrt_rt.entr_bnft_val_flag = 'Y' and
2321             l_enrt_rt.rt_mlt_cd <> 'FLFX') or
2322              l_enrt_rt.rt_mlt_cd = 'ERL'or
2323              l_enrt_rt.cvg_mlt_cd = 'ERL'  then -- ERL added for canon fix
2324            if g_debug then
2325              hr_utility.set_location('p_rt_val'||to_char(p_rt_val), 312);
2326              hr_utility.set_location( 'l_global_pen_rec.bnft_am'||l_global_pen_rec.bnft_amt ,314);
2327            end if;
2328          --BUG 3804813  */
2329          --START BUG 3804813
2330          if (l_enrt_rt.entr_bnft_val_flag = 'Y' OR
2331              l_enrt_rt.interim_flag = 'Y' OR   --For Interim Rule BUG 5502202
2332              l_enrt_rt.rt_mlt_cd = 'ERL'or
2333              l_enrt_rt.cvg_mlt_cd = 'ERL') -- ERL added for canon fix
2334          and l_enrt_rt.entr_val_at_enrt_flag = 'N' then -- Bug 4710188, Calling rates pack
2335                                                         -- rate is not enterable only when
2336            if g_debug then
2337              hr_utility.set_location('p_rt_val'||to_char(p_rt_val), 312);
2338              hr_utility.set_location('l_rt_val_param'||to_char(l_rt_val_param), 312);
2339              hr_utility.set_location( 'l_global_pen_rec.bnft_am'||l_global_pen_rec.bnft_amt ,314);
2340            end if;
2341            --END BUG 3804813
2342            if l_enrt_rt.enrt_bnft_id = 0 then
2343              l_enrt_rt.enrt_bnft_id := null;
2344            end if;
2345            ben_determine_activity_base_rt.main
2346              (p_person_id                  => p_person_id
2347              ,p_elig_per_elctbl_chc_id      => l_enrt_rt.elig_per_elctbl_chc_id
2348              ,p_enrt_bnft_id                => l_enrt_rt.enrt_bnft_id
2349              ,p_acty_base_rt_id             => l_enrt_rt.acty_base_rt_id
2350              ,p_effective_date              => p_effective_date
2351              ,p_per_in_ler_id               => p_per_in_ler_id
2352              ,p_lf_evt_ocrd_dt              => l_lf_evt_ocrd_dt -- Added Bug 3488286
2353              ,p_pl_id                       => p_pl_id
2354              ,p_pgm_id                      => p_pgm_id
2355              ,p_oipl_id                     => p_oipl_id
2356              ,p_pl_typ_id                   => l_global_pen_rec.pl_typ_id
2357              ,p_ler_id                      => l_global_pen_rec.ler_id
2358              ,p_business_group_id           => p_business_group_id
2359              ,p_perform_rounding_flg        => true
2360              ,p_calc_only_rt_val_flag       => true
2361              ,p_bnft_amt                    => l_global_pen_rec.bnft_amt
2362              -- the following are all out parms:  the only ones we want are rate values.
2363              ,p_val                         => l_rt_val
2364              ,p_mn_elcn_val                 => l_dummy_num
2365              ,p_mx_elcn_val                 => l_dummy_num
2366              ,p_ann_val                     => l_ann_rt_val
2367              ,p_ann_mn_elcn_val             => l_dummy_num
2368              ,p_ann_mx_elcn_val             => l_dummy_num
2369              ,p_cmcd_val                    => l_dummy_num
2370              ,p_cmcd_mn_elcn_val            => l_dummy_num
2371              ,p_cmcd_mx_elcn_val            => l_dummy_num
2372              ,p_cmcd_acty_ref_perd_cd       => l_dummy_varchar2
2373              ,p_incrmt_elcn_val             => l_dummy_num
2374              ,p_dflt_val                    => l_dummy_num
2375              ,p_tx_typ_cd                   => l_dummy_varchar2
2376              ,p_acty_typ_cd                 => l_dummy_varchar2
2377              ,p_nnmntry_uom                 => l_dummy_varchar2
2378              ,p_entr_val_at_enrt_flag       => l_dummy_varchar2
2379              ,p_dsply_on_enrt_flag          => l_dummy_varchar2
2380              ,p_use_to_calc_net_flx_cr_flag => l_dummy_varchar2
2381              ,p_rt_usg_cd                   => l_dummy_varchar2
2382              ,p_bnft_prvdr_pool_id          => l_dummy_num
2383              ,p_actl_prem_id                => l_dummy_num
2384              ,p_cvg_calc_amt_mthd_id        => l_dummy_num
2385              ,p_bnft_rt_typ_cd              => l_dummy_varchar2
2386              ,p_rt_typ_cd                   => l_dummy_varchar2
2387              ,p_rt_mlt_cd                   => l_dummy_varchar2
2388              ,p_comp_lvl_fctr_id            => l_dummy_num
2389              ,p_entr_ann_val_flag           => l_dummy_varchar2
2390              ,p_ptd_comp_lvl_fctr_id        => l_dummy_num
2391              ,p_clm_comp_lvl_fctr_id        => l_dummy_num
2392              ,p_ann_dflt_val                => l_dummy_num
2393              ,p_rt_strt_dt                  => l_dummy_date
2394              ,p_rt_strt_dt_cd               => l_dummy_varchar2
2395              ,p_rt_strt_dt_rl               => l_dummy_num
2396              ,p_prtt_rt_val_id              => l_dummy_num
2397              ,p_dsply_mn_elcn_val           => l_dummy_num
2398              ,p_dsply_mx_elcn_val           => l_dummy_num
2399              ,p_pp_in_yr_used_num           => l_dummy_num
2400              ,p_ordr_num                => l_dummy_num
2401              ,p_iss_val                     =>l_dummy_num
2402              );
2403            if g_debug then
2404              hr_utility.set_location('l_rt_val'||to_char(l_rt_val), 312);
2405            end if;
2406 
2407          ELSE -- 5375381 :Added else part
2408 	       /* This is purely for Interim pen which has has same epe as of its Sspndd pen.
2409 	        And sspndd pen has entr_bnft_val_flag = 'Y'
2410 	       */
2411                   OPEN c_sspnd_enrt_rt (l_enrt_rt.elig_per_elctbl_chc_id);
2412                   FETCH c_sspnd_enrt_rt INTO l_sspnd_enrt_rt;
2413                   CLOSE c_sspnd_enrt_rt;
2414 
2415                   IF     l_enrt_rt.entr_val_at_enrt_flag = 'N'
2416                      AND (    (   l_sspnd_enrt_rt.entr_bnft_val_flag = 'Y'
2417                                OR l_sspnd_enrt_rt.rt_mlt_cd = 'ERL'
2418                                OR l_sspnd_enrt_rt.cvg_mlt_cd = 'ERL'
2419                               )
2420                           AND l_sspnd_enrt_rt.entr_val_at_enrt_flag = 'N'
2421                          )
2422                   THEN
2423                      IF g_debug
2424                      THEN
2425                         hr_utility.set_location (   'p_rt_val'
2426                                                  || TO_CHAR (p_rt_val),
2427                                                  555
2428                                                 );
2429                         hr_utility.set_location (   'l_rt_val_param'
2430                                                  || TO_CHAR (l_rt_val_param),
2431                                                  555
2432                                                 );
2433                         hr_utility.set_location (   'l_global_pen_rec.bnft_am'
2434                                                  || l_global_pen_rec.bnft_amt,
2435                                                  555
2436                                                 );
2437                      END IF;
2438 
2439                      IF l_enrt_rt.enrt_bnft_id = 0
2440                      THEN
2441                         l_enrt_rt.enrt_bnft_id := NULL;
2442                      END IF;
2443 
2444                      ben_determine_activity_base_rt.main (p_person_id                        => p_person_id,
2445                                                           p_elig_per_elctbl_chc_id           => l_enrt_rt.elig_per_elctbl_chc_id,
2446                                                           p_enrt_bnft_id                     => l_enrt_rt.enrt_bnft_id,
2447                                                           p_acty_base_rt_id                  => l_enrt_rt.acty_base_rt_id,
2448                                                           p_effective_date                   => p_effective_date,
2449                                                           p_per_in_ler_id                    => p_per_in_ler_id,
2450                                                           p_lf_evt_ocrd_dt                   => l_lf_evt_ocrd_dt, -- Added Bug 3488286
2451 
2452                                                           p_pl_id                            => p_pl_id,
2453                                                           p_pgm_id                           => p_pgm_id,
2454                                                           p_oipl_id                          => p_oipl_id,
2455                                                           p_pl_typ_id                        => l_global_pen_rec.pl_typ_id,
2456                                                           p_ler_id                           => l_global_pen_rec.ler_id,
2457                                                           p_business_group_id                => p_business_group_id,
2458                                                           p_perform_rounding_flg             => TRUE,
2459                                                           p_calc_only_rt_val_flag            => TRUE,
2460                                                           p_bnft_amt                         => l_global_pen_rec.bnft_amt,-- the following are all out parms:  the only ones we want are rate values.
2461 
2462                                                           p_val                              => l_rt_val,
2463                                                           p_mn_elcn_val                      => l_dummy_num,
2464                                                           p_mx_elcn_val                      => l_dummy_num,
2465                                                           p_ann_val                          => l_ann_rt_val,
2466                                                           p_ann_mn_elcn_val                  => l_dummy_num,
2467                                                           p_ann_mx_elcn_val                  => l_dummy_num,
2468                                                           p_cmcd_val                         => l_dummy_num,
2469                                                           p_cmcd_mn_elcn_val                 => l_dummy_num,
2470                                                           p_cmcd_mx_elcn_val                 => l_dummy_num,
2471                                                           p_cmcd_acty_ref_perd_cd            => l_dummy_varchar2,
2472                                                           p_incrmt_elcn_val                  => l_dummy_num,
2473                                                           p_dflt_val                         => l_dummy_num,
2474                                                           p_tx_typ_cd                        => l_dummy_varchar2,
2475                                                           p_acty_typ_cd                      => l_dummy_varchar2,
2476                                                           p_nnmntry_uom                      => l_dummy_varchar2,
2477                                                           p_entr_val_at_enrt_flag            => l_dummy_varchar2,
2478                                                           p_dsply_on_enrt_flag               => l_dummy_varchar2,
2479                                                           p_use_to_calc_net_flx_cr_flag      => l_dummy_varchar2,
2480                                                           p_rt_usg_cd                        => l_dummy_varchar2,
2481                                                           p_bnft_prvdr_pool_id               => l_dummy_num,
2482                                                           p_actl_prem_id                     => l_dummy_num,
2483                                                           p_cvg_calc_amt_mthd_id             => l_dummy_num,
2484                                                           p_bnft_rt_typ_cd                   => l_dummy_varchar2,
2485                                                           p_rt_typ_cd                        => l_dummy_varchar2,
2486                                                           p_rt_mlt_cd                        => l_dummy_varchar2,
2487                                                           p_comp_lvl_fctr_id                 => l_dummy_num,
2488                                                           p_entr_ann_val_flag                => l_dummy_varchar2,
2489                                                           p_ptd_comp_lvl_fctr_id             => l_dummy_num,
2490                                                           p_clm_comp_lvl_fctr_id             => l_dummy_num,
2491                                                           p_ann_dflt_val                     => l_dummy_num,
2492                                                           p_rt_strt_dt                       => l_dummy_date,
2493                                                           p_rt_strt_dt_cd                    => l_dummy_varchar2,
2494                                                           p_rt_strt_dt_rl                    => l_dummy_num,
2495                                                           p_prtt_rt_val_id                   => l_dummy_num,
2496                                                           p_dsply_mn_elcn_val                => l_dummy_num,
2497                                                           p_dsply_mx_elcn_val                => l_dummy_num,
2498                                                           p_pp_in_yr_used_num                => l_dummy_num,
2499                                                           p_ordr_num                         => l_dummy_num,
2500                                                           p_iss_val                          => l_dummy_num
2501                                                          );
2502 
2503                      IF g_debug
2504                      THEN
2505                         hr_utility.set_location (   'l_rt_val'
2506                                                  || TO_CHAR (l_rt_val),
2507                                                  556
2508                                                 );
2509                      END IF;
2510                   ELSE
2511                      l_ann_rt_val := l_ann_rt_val_param; -- p_ann_rt_val; 5259005
2512                      l_rt_val := l_rt_val_param; --p_rt_val; 5259005
2513                   END IF;
2514          end if;
2515          --- bug : 1555624 if the parent defined as entr_val_At_enrt_flag and use_calc_acty_bs_rt_flag
2516          --- then call the rate calcualtion
2517          if l_enrt_rt.rt_mlt_cd in ('PRNT','PRNTANDCVG') then
2518              open c_abr2(l_effective_date,l_enrt_rt.acty_base_rt_id ) ;
2519              fetch c_abr2 into l_prnt_abr ;
2520              --- take the rate from the parent rcord
2521              if c_abr2%found then
2522                 open c_prv2(p_prtt_enrt_rslt_id,l_prnt_abr.acty_base_rt_id );
2523                 fetch  c_prv2 into l_prnt_rt_val ,l_prnt_ann_val;
2524                 close  c_prv2 ;
2525              end if ;
2526              close c_abr2 ;
2527          end if ;
2528 
2529          --
2530          --  bug 1480407
2531          --
2532          if g_debug then
2533            hr_utility.set_location('entr_val_At_enrt_flag '||l_enrt_rt.entr_val_At_enrt_flag ,407);
2534            hr_utility.set_location('use_calc_acty_bs_rt_flag '||l_enrt_rt.use_calc_acty_bs_rt_flag ,407);
2535            hr_utility.set_location('l_enrt_rt.rt_mlt_cd' ||l_enrt_rt.rt_mlt_cd , 407);
2536          end if;
2537          --
2538          -- tilak :Rate calclation is called either the std rate  entr_val_At_enrt_flag is on and
2539          -- use_calc_acty_bs_rt_flag is on for coverage and other
2540          -- OR  std rate has parent and the parent's entr_val_At_enrt_flag is on
2541          -- and use_calc_acty_bs_rt_flag is on so the parent calcialted then the child
2542 
2543        if l_enrt_rt.entr_val_At_enrt_flag  = 'Y'
2544             or nvl(l_prnt_abr.entr_val_at_enrt_flag,'N')  = 'Y'  then
2545            --
2546            -- get values from annual value
2547            --
2548           If ( l_enrt_rt.entr_val_At_enrt_flag  = 'Y'
2549               and l_enrt_rt.use_calc_acty_bs_rt_flag = 'Y'
2550               and l_enrt_rt.rt_mlt_cd in('CVG','CL','PRNT','AP') )
2551              or
2552               (nvl(l_prnt_abr.entr_val_at_enrt_flag,'N')  = 'Y'
2553               and nvl(l_prnt_abr.use_calc_acty_bs_rt_flag,'N')  = 'Y'
2554               and l_enrt_rt.rt_mlt_cd in('PRNT','PRNTANDCVG')  ) then
2555 
2556              if g_debug then
2557                hr_utility.set_location(' calllign rate '||l_rt_val  ,407);
2558              end if;
2559              --
2560              -- NOCOPY ISSUE
2561              l_cal_val_in := l_rt_val ;
2562              -- END NOCOPY ISSUE
2563              --
2564              BEN_DETERMINE_ACTIVITY_BASE_RT.main
2565                (p_person_id                  => p_person_id
2566                ,p_elig_per_elctbl_chc_id      => l_enrt_rt.elig_per_elctbl_chc_id
2567                ,p_enrt_bnft_id                => l_enrt_rt.enrt_bnft_id
2568                ,p_acty_base_rt_id             => l_enrt_rt.acty_base_rt_id
2569                ,p_effective_date              => p_effective_date
2570                ,p_per_in_ler_id               => p_per_in_ler_id
2571                ,p_lf_evt_ocrd_dt              => l_lf_evt_ocrd_dt -- Added Bug 3488286
2572                ,p_pl_id                       => p_pl_id
2573                ,p_pgm_id                      => p_pgm_id
2574                ,p_oipl_id                     => p_oipl_id
2575                ,p_pl_typ_id                   => l_global_pen_rec.pl_typ_id
2576                ,p_ler_id                      => l_global_pen_rec.ler_id
2577                ,p_business_group_id           => p_business_group_id
2578                ,p_perform_rounding_flg        => true
2579                ,p_calc_only_rt_val_flag       => true
2580                ,p_bnft_amt                    => l_global_pen_rec.bnft_amt
2581                ,p_cal_val                     => l_cal_val_in -- NOCOPY ISSUE l_rt_val
2582                ,p_parent_val                  => l_prnt_rt_val
2583                ,p_val                         => l_rt_val
2584                ,p_mn_elcn_val                 => l_dummy_num
2585                ,p_mx_elcn_val                 => l_dummy_num
2586                ,p_ann_val                     => l_ann_rt_val
2587                ,p_ann_mn_elcn_val             => l_dummy_num
2588                ,p_ann_mx_elcn_val             => l_dummy_num
2589                ,p_cmcd_val                    => l_dummy_num
2590                ,p_cmcd_mn_elcn_val            => l_dummy_num
2591                ,p_cmcd_mx_elcn_val            => l_dummy_num
2592                ,p_cmcd_acty_ref_perd_cd       => l_dummy_varchar2
2593                ,p_incrmt_elcn_val             => l_dummy_num
2594                ,p_dflt_val                    => l_dummy_num
2595                ,p_tx_typ_cd                   => l_dummy_varchar2
2596                ,p_acty_typ_cd                 => l_dummy_varchar2
2597                ,p_nnmntry_uom                 => l_dummy_varchar2
2598                ,p_entr_val_at_enrt_flag       => l_dummy_varchar2
2599                ,p_dsply_on_enrt_flag          => l_dummy_varchar2
2600                ,p_use_to_calc_net_flx_cr_flag => l_dummy_varchar2
2601                ,p_rt_usg_cd                   => l_dummy_varchar2
2602                ,p_bnft_prvdr_pool_id          => l_dummy_num
2603                ,p_actl_prem_id                => l_dummy_num
2604                ,p_cvg_calc_amt_mthd_id        => l_dummy_num
2605                ,p_bnft_rt_typ_cd              => l_dummy_varchar2
2606                ,p_rt_typ_cd                   => l_dummy_varchar2
2607                ,p_rt_mlt_cd                   => l_dummy_varchar2
2608                ,p_comp_lvl_fctr_id            => l_dummy_num
2609                ,p_entr_ann_val_flag           => l_dummy_varchar2
2610                ,p_ptd_comp_lvl_fctr_id        => l_dummy_num
2611                ,p_clm_comp_lvl_fctr_id        => l_dummy_num
2612                ,p_ann_dflt_val                => l_dummy_num
2613                ,p_rt_strt_dt                  => l_dummy_date
2614                ,p_rt_strt_dt_cd               => l_dummy_varchar2
2615                ,p_rt_strt_dt_rl               => l_dummy_num
2616                ,p_prtt_rt_val_id              => l_dummy_num
2617                ,p_dsply_mn_elcn_val           => l_dummy_num
2618                ,p_dsply_mx_elcn_val           => l_dummy_num
2619                ,p_pp_in_yr_used_num           => l_dummy_num
2620                ,p_ordr_num                    => l_dummy_num
2621                ,p_iss_val                     => l_dummy_num
2622                );
2623              if g_debug then
2624                hr_utility.set_location(' rate ' ||l_rt_val,407);
2625              end if;
2626            End if ;
2627          end if;
2628          --
2629          --GEVITY
2630          --
2631          IF l_enrt_rt.rate_periodization_rl IS NOT NULL THEN
2632            --
2633            l_dfnd_dummy := l_rt_val;
2634            --
2635            ben_distribute_rates.periodize_with_rule
2636                   (p_formula_id             => l_enrt_rt.rate_periodization_rl
2637                   ,p_effective_date         => l_effective_date
2638                   ,p_assignment_id          => l_assignment_id
2639                   ,p_convert_from_val       => l_dfnd_dummy
2640                   ,p_convert_from           => 'DEFINED'
2641                   ,p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id
2642                   ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
2643                   ,p_business_group_id      => p_business_group_id
2644                   ,p_enrt_rt_id             => p_enrt_rt_id
2645                   ,p_ann_val                => l_ann_rt_val
2646                   ,p_cmcd_val               => l_enrt_rt.cmcd_val
2647                   ,p_val                    => l_rt_val
2648             );
2649             --
2650          ELSE
2651            --
2652            l_ann_rt_val := ben_distribute_rates.period_to_annual
2653                            (p_amount                  => l_rt_val
2654                            ,p_enrt_rt_id              => p_enrt_rt_id
2655                            ,p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id
2656                            ,p_acty_ref_perd_cd        => p_acty_ref_perd_cd
2657                            ,p_business_group_id       => p_business_group_id
2658                            ,p_effective_date          => l_effective_date
2659                            ,p_complete_year_flag      => 'Y'
2660                            ,p_use_balance_flag        => 'Y'
2661                            ,p_payroll_id              => l_payroll_id
2662                            );
2663            --
2664            -- always compute the cmcd rate based on the annual value
2665            --
2666            l_calc_ann_val := ben_distribute_rates.period_to_annual
2667                              (p_amount                  => l_rt_val
2668                              ,p_enrt_rt_id              => p_enrt_rt_id
2669                              ,p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id
2670                              ,p_acty_ref_perd_cd        => p_acty_ref_perd_cd
2671                              ,p_business_group_id       => p_business_group_id
2672                              ,p_effective_date          => l_effective_date
2673                              ,p_complete_year_flag      => 'Y'
2674                              ,p_payroll_id              => l_payroll_id
2675                              );
2676            --
2677            l_enrt_rt.cmcd_val := ben_distribute_rates.annual_to_period
2678                                  (p_amount                  => l_calc_ann_val
2679                                  ,p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id
2680                                  ,p_acty_ref_perd_cd        => l_enrt_rt.cmcd_acty_ref_perd_cd
2681                                  ,p_business_group_id       => p_business_group_id
2682                                  ,p_effective_date          => l_effective_date
2683                                  ,p_complete_year_flag      => 'Y'
2684                                  ,p_payroll_id              => l_payroll_id
2685                                  ,p_element_type_id         => l_element_type_id
2686                                  ,p_person_id               => p_person_id
2687                                  );
2688            --
2689          END IF; --GEVITY
2690        if g_debug then
2691          hr_utility.set_location('ann val'||l_ann_rt_val||'cal ann val'||l_calc_ann_val,100);
2692           hr_utility.set_location('communicated val'||l_enrt_rt.cmcd_val,101);
2693        end if;
2694     else  --mlt_cd='SAREC'
2695         if l_enrt_rt.entr_bnft_val_flag = 'Y' then
2696            if g_debug then
2697              hr_utility.set_location('p_rt_val'||to_char(p_rt_val), 319);
2698              hr_utility.set_location('p_ann_rt_val'||to_char(p_ann_rt_val), 319);
2699              hr_utility.set_location('l_rt_val_param'||to_char(l_rt_val_param), 319);          -- 5259005
2700              hr_utility.set_location('l_ann_rt_val_param'||to_char(l_ann_rt_val_param), 319);  -- 5259005
2701              hr_utility.set_location('bnft_val'||to_char(l_global_pen_rec.bnft_amt), 319);
2702            end if;
2703           --
2704           l_ann_rt_val := l_global_pen_rec.bnft_amt;
2705           -- Bug 2675486 fixes for FSA
2706           if l_old_ann_rt_val = l_ann_rt_val and l_old_rt_strt_dt is not null then
2707             -- Case - Benefit amount not changed and currently enrolled case
2708             -- See if the current rate is started in the present popl yr period.
2709             -- If started in current yr_perd then DONT compute defined and comm amounts
2710             -- else compute the defined comm amounts.
2711             -- l_sarec_compute
2712             open c_pl_popl_yr_period_current(p_pl_id,p_pgm_id,l_effective_date);
2713               fetch c_pl_popl_yr_period_current into l_yp_start_date ;
2714             close c_pl_popl_yr_period_current ;
2715             --
2716             if l_old_rt_strt_dt >= l_yp_start_date then
2717               -- Already enrolled in the same yr_perd and amount not changed so
2718               -- dont recompute the amounts
2719                   --bug#3364910 - check for payroll type change
2720                     l_period_type:=null;
2721                     open c_payroll_type_changed(
2722                           cp_person_id           =>p_person_id,
2723                           cp_business_group_id   =>p_business_group_id,
2724                           cp_effective_date      =>l_enrt_rt.rt_strt_dt,
2725                           cp_orig_effective_date =>l_old_rt_strt_dt);
2726                     fetch c_payroll_type_changed into l_period_type;
2727                     close c_payroll_type_changed;
2728                --      no change in payroll then dont recompute
2729                     if l_period_type is null then
2730 
2731                        if g_debug then
2732                          hr_utility.set_location('Same Yr Period and same rate ' ,124);
2733                        end if;
2734                        l_sarec_compute := false ;
2735                     end if;
2736             end if ;
2737             --
2738           end if ;
2739           --
2740           --l_ann_rt_val := l_global_pen_rec.bnft_amt;
2741           -- ikasire commented p_complete_year_flag => 'Y' per Bug 1650517
2742           if l_sarec_compute then
2743             --GEVITY
2744             --
2745             IF l_enrt_rt.rate_periodization_rl IS NOT NULL THEN
2746               --
2747               l_ann_dummy := l_ann_rt_val;
2748               --
2749               ben_distribute_rates.periodize_with_rule
2750                   (p_formula_id             => l_enrt_rt.rate_periodization_rl
2751                   ,p_effective_date         => l_effective_date
2752                   ,p_assignment_id          => l_assignment_id
2753                   ,p_convert_from_val       => l_ann_dummy
2754                   ,p_convert_from           => 'ANNUAL'
2755                   ,p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id
2756                   ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
2757                   ,p_business_group_id      => p_business_group_id
2758                   ,p_enrt_rt_id             => p_enrt_rt_id
2759                   ,p_ann_val                => l_ann_rt_val
2760                   ,p_cmcd_val               => l_enrt_rt.cmcd_val
2761                   ,p_val                    => l_rt_val
2762                 );
2763                 --
2764             ELSE
2765                 --
2766               l_rt_val := ben_distribute_rates.annual_to_period
2767                     (p_amount                  => l_ann_rt_val,
2768                      p_enrt_rt_id              => p_enrt_rt_id,
2769                      p_acty_ref_perd_cd        => p_acty_ref_perd_cd,
2770                      p_business_group_id       => p_business_group_id,
2771                      p_effective_date          => l_effective_date,
2772                      p_complete_year_flag      => 'Y',
2773                      p_use_balance_flag        => 'Y',
2774                      p_payroll_id              => l_payroll_id,
2775                      p_element_type_id         => l_element_type_id,
2776                      p_rounding_flag           => 'N',
2777                      p_person_id               => p_person_id
2778                      );
2779               if g_debug then
2780                 hr_utility.set_location(' IK l_rt_val '||l_rt_val,123);
2781               end if;
2782               --
2783               -- Bug 2149438 I am doing it to 3 because right now we have 2 digit rouding for
2784               -- the final value. Once we implement the rounding completely for the
2785               -- rate value this needs to be atleast one digit more than the
2786               -- actual rounding code dictates.
2787               --
2788               l_rt_val := round(l_rt_val,4);
2789               --
2790               if g_debug then
2791                 hr_utility.set_location(' IK2 rounded l_rt_val '||l_rt_val,123);
2792               end if;
2793               /**
2794                when annual value is passed there is no need to compute the annual value
2795                from defined value - bug#2398448 and bug#2392732
2796               l_calc_ann_val := ben_distribute_rates.period_to_annual
2797                     (p_amount                  => l_rt_val,
2798                      p_enrt_rt_id              => p_enrt_rt_id,
2799                      p_acty_ref_perd_cd        => p_acty_ref_perd_cd,
2800                      p_business_group_id       => p_business_group_id,
2801                      p_effective_date          => l_effective_date,
2802                      p_complete_year_flag      => 'Y',
2803                      p_payroll_id              => l_payroll_id);
2804               **/
2805               l_calc_ann_val  := l_ann_rt_val;
2806                if g_debug then
2807                  hr_utility.set_location('annval'||to_char(l_calc_ann_val), 319);
2808                end if;
2809                if g_debug then
2810                  hr_utility.set_location('rt val'||l_rt_val, 319);
2811                end if;
2812                --Bug#3540351
2813                if l_rt_val < 0 then
2814                   l_rt_val := 0;
2815                   l_enrt_rt.cmcd_val := 0;
2816                   ben_distribute_rates.compare_balances
2817                     (p_person_id            => p_person_id
2818                     ,p_effective_date       => l_effective_date
2819                     ,p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id
2820                     ,p_acty_base_rt_id      => l_enrt_rt.acty_base_rt_id
2821                     ,p_ann_mn_val           => l_ann_mn_elcn_val
2822                     ,p_ann_mx_val           => l_ann_mx_elcn_val
2823                     ,p_perform_edit_flag    => 'N'
2824                     ,p_entered_ann_val      => l_ann_rt_val
2825                     ,p_ptd_balance          => l_ptd_balance
2826                     ,p_clm_balance          => l_clm_balance ) ;
2827                  --
2828                  if l_ann_rt_val < l_ptd_balance then
2829                    --
2830                    open c_pl_name (p_pl_id);
2831                    fetch c_pl_name into l_pl_name;
2832                    close c_pl_name;
2833                    --
2834                    ben_warnings.load_warning
2835                      (p_application_short_name  => 'BEN',
2836                       p_message_name            => 'BEN_93951_BELOW_PTD',
2837                       p_parma => l_pl_name,
2838                       p_parm1 => l_ann_rt_val,
2839                       p_parm2 => l_ptd_balance,
2840                       p_person_id => p_person_id);
2841                  end if;
2842                else
2843                  --
2844                   l_enrt_rt.cmcd_val := ben_distribute_rates.annual_to_period
2845                     (p_amount                  => l_calc_ann_val,
2846                     -- p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id,
2847                      p_enrt_rt_id              => p_enrt_rt_id,
2848                      p_acty_ref_perd_cd        => l_enrt_rt.cmcd_acty_ref_perd_cd,
2849                      p_business_group_id       => p_business_group_id,
2850                      p_effective_date          => l_effective_date,
2851                      p_use_balance_flag        => 'Y',
2852                     -- p_complete_year_flag      => 'Y',
2853                      p_start_date              => l_enrt_rt.rt_strt_dt,
2854                      p_payroll_id              => l_payroll_id,
2855                      p_element_type_id         => l_element_type_id,
2856                      p_person_id               => p_person_id
2857                      );
2858                end if;
2859                --
2860             END IF; --GEVITY
2861           else
2862             --
2863             l_rt_val := l_old_rt_val ;
2864             l_calc_ann_val  := l_ann_rt_val;
2865             l_enrt_rt.cmcd_val := l_old_cmcd_rt_val ;
2866             if g_debug then
2867               hr_utility.set_location('Continue old rate '||l_old_rt_val,123);
2868             end if;
2869             if g_debug then
2870               hr_utility.set_location(' l_old_cmcd_rt_val '||l_old_cmcd_rt_val,123);
2871             end if;
2872             --
2873           end if ;
2874         else
2875           -- Bug 2223694 when the coverage is not enter value at enrollment
2876           -- we are not getting the defined amount and element entries.
2877           if g_debug then
2878             hr_utility.set_location('IK l_enrt_rt.val '||l_enrt_rt.val ,99);
2879             hr_utility.set_location('IK l_enrt_rt.ann_val '||l_enrt_rt.ann_val,99);
2880             hr_utility.set_location('IK l_enrt_rt.cmcd_val '||l_enrt_rt.cmcd_val,99);
2881           end if;
2882           l_rt_val  := l_enrt_rt.val ;
2883           l_calc_ann_val := l_enrt_rt.ann_val ;
2884           --  3547233. Copy annual value to l_ann_rt_val for prtt_rt_val record.
2885           l_ann_rt_val := l_enrt_rt.ann_val;
2886           --
2887        end if;
2888     end if;
2889    end if;
2890   end if;
2891   --
2892   -- determine if element type/input val changed
2893   --
2894   if p_prtt_rt_val_id is not null then
2895      if p_ele_changed is null then
2896 
2897         if l_old_element_entry_value_id is not null then
2898            open c_element_info (l_old_element_entry_value_id,
2899                                 p_prtt_enrt_rslt_id);
2900            fetch c_element_info into l_element_info;
2901            close c_element_info;
2902            --
2903            --bug#3378865
2904            --
2905            if not (l_old_rt_strt_dt between l_enrt_rt.abr_esd and
2906               l_enrt_rt.abr_eed) then
2907               open c_abr(l_enrt_rt.acty_base_rt_id, l_old_rt_strt_dt);
2908               fetch c_abr into l_ele_entry_val_cd,l_element_type_id,l_input_value_id;
2909               close c_abr;
2910            else
2911               l_ele_entry_val_cd := l_enrt_rt.ele_entry_val_cd;
2912            end if;
2913            --
2914         end if;
2915         --
2916         --get the new abr assignment and payroll
2917         --
2918         ben_element_entry.get_abr_assignment
2919         (p_person_id       => p_person_id,
2920          p_effective_date  => l_enrt_rt.rt_strt_dt,
2921          p_acty_base_rt_id => l_enrt_rt.acty_base_rt_id,
2922          p_assignment_id   => l_new_assignment_id,
2923          p_payroll_id      => l_new_payroll_id,
2924          p_organization_id => l_new_organization_id);
2925 
2926  /* Adding this call below to fix a bug 6132571. When there are two
2927  * rates having same element type, the first input value is updated
2928  * with value zero along with element entry. This while processing the second
2929  * rate,the cursor c_element_info gets the latest payroll id, which while
2930  * processing the second rate does not set the flag l_element_changed
2931  * in the condition below, which impact all further processing */
2932 
2933         ben_element_entry.get_abr_assignment
2934         (p_person_id       => p_person_id,
2935          p_effective_date  => l_old_rt_strt_dt,
2936          p_acty_base_rt_id => l_enrt_rt.acty_base_rt_id,
2937          p_assignment_id   => l_old_assignment_id,
2938          p_payroll_id      => l_old_payroll_id,
2939          p_organization_id => l_old_organization_id);
2940 
2941 
2942         hr_utility.set_location('ben_element_entry.get_abr_assignment
2943                                 -Old Assignment Id' ||l_old_assignment_id ,101);
2944         hr_utility.set_location('ben_element_entry.get_abr_assignment
2945                                 -Old Payroll Id' ||l_old_payroll_id ,101);
2946         hr_utility.set_location('ben_element_entry.get_abr_assignment
2947                                 -Old Org Id' ||l_old_organization_id ,101);
2948 
2949         l_element_changed :=
2950             (l_old_element_entry_value_id is not null and
2951             l_enrt_rt.ele_rqd_flag = 'N') or
2952            (l_enrt_rt.ele_rqd_flag = 'Y' and
2953             ((nvl(l_element_info.input_value_id,-1) <>
2954               l_enrt_rt.input_value_id) or
2955              (nvl(l_element_info.element_type_id,-1) <>
2956               l_enrt_rt.element_type_id) or
2957              (not l_non_recurring_rt and
2958               l_element_info.effective_end_date < l_enrt_rt.rt_strt_dt) or
2959              (l_old_assignment_id <> nvl(l_new_assignment_id,-1)) or
2960              (nvl(l_old_payroll_id,-1) <> nvl(l_new_payroll_id,-1)) or
2961              (nvl(l_enrt_rt.ele_entry_val_cd,'PP') <>
2962                 nvl(l_ele_entry_val_cd,'PP'))));
2963         --
2964         -- determine if extra input values changed
2965         --
2966         if not l_element_changed then
2967 
2968            l_ext_inpval_tab.delete;
2969            ben_element_entry.get_extra_ele_inputs
2970            (p_effective_date         => l_enrt_rt.rt_strt_dt
2971            ,p_person_id              => p_person_id
2972            ,p_business_group_id      => p_business_group_id
2973            ,p_assignment_id          => l_new_assignment_id
2974            ,p_element_link_id        => null
2975            ,p_entry_type             => 'E'
2976            ,p_input_value_id1        => null
2977            ,p_entry_value1           => null
2978            ,p_element_entry_id       => null
2979            ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
2980            ,p_input_va_calc_rl       => l_enrt_rt.input_va_calc_rl
2981            ,p_abs_ler                => null
2982            ,p_organization_id        => l_new_organization_id
2983            ,p_payroll_id             => l_new_payroll_id
2984            ,p_pgm_id                 => l_global_pen_rec.pgm_id
2985            ,p_pl_id                  => l_global_pen_rec.pl_id
2986            ,p_pl_typ_id              => l_global_pen_rec.pl_typ_id
2987            ,p_opt_id                 => null
2988            ,p_ler_id                 => l_global_pen_rec.ler_id
2989            ,p_dml_typ                => 'C'
2990            ,p_jurisdiction_code      => l_jurisdiction_code
2991            ,p_ext_inpval_tab         => l_ext_inpval_tab
2992            ,p_subpriority            => l_subpriority
2993            );
2994 
2995            l_inpval_tab.delete;
2996            ben_element_entry.get_inpval_tab
2997            (p_element_entry_id   => l_element_info.element_entry_id
2998            ,p_effective_date     => l_enrt_rt.rt_strt_dt
2999            ,p_inpval_tab         => l_inpval_tab);
3000 
3001            l_ext_inp_changed := false;
3002            for i in 1..l_ext_inpval_tab.count
3003            loop
3004               for j in 1..l_inpval_tab.count
3005               loop
3006                   if (l_ext_inpval_tab(i).input_value_id =
3007                      l_inpval_tab(j).input_value_id) and
3008                      (nvl(l_ext_inpval_tab(i).return_value,'-1')  <>
3009                      nvl(l_inpval_tab(j).value,'-1')) then
3010                      l_ext_inp_changed := true;
3011                      exit;
3012                   end if;
3013               end loop;
3014               if l_ext_inp_changed then
3015                  exit;
3016               end if;
3017            end loop;
3018 
3019            l_element_changed := l_ext_inp_changed;
3020 
3021         end if;
3022      else
3023         l_element_changed := p_ele_changed;
3024      end if;
3025   end if;
3026   --
3027   -- delete any future dated rates
3028   --
3029   handle_overlap_rates
3030   (p_acty_base_rt_id                => l_enrt_rt.acty_base_rt_id
3031   ,p_prtt_enrt_rslt_id              => p_prtt_enrt_rslt_id
3032   ,p_prtt_rt_val_id                 => p_prtt_rt_val_id
3033   ,p_per_in_ler_id                  => p_per_in_ler_id
3034   ,p_person_id                      => p_person_id
3035   ,p_element_type_id                => l_element_info.element_type_id
3036   ,p_element_entry_value_id         => l_old_element_entry_value_id
3037   ,p_unrestricted                   => l_unrestricted
3038   ,p_rt_strt_dt                     => l_enrt_rt.rt_strt_dt
3039   ,p_business_group_id              => p_business_group_id
3040   ,p_effective_date                 => p_effective_date);
3041   --
3042   -- if a prtt_rt_val_id is found get the old values
3043   --
3044   if p_prtt_rt_val_id is not null then
3045      --
3046      if g_debug then
3047         hr_utility.set_location(l_proc, 85);
3048      end if;
3049       --
3050       -- compare old and new values if changed do update
3051       --
3052       --
3053       -- date compare below will fix bug 3556
3054       -- whenever the rate start date changes create a new prv
3055       -- this will force the element entries to be updated.
3056       --
3057       --
3058       -- Always update per_in_ler_id and create a new rate
3059       -- when per_in_ler_id changes.
3060       --
3061       if ((nvl(l_old_rt_typ_cd,hr_api.g_varchar2)<>
3062                 nvl(l_enrt_rt.rt_typ_cd,hr_api.g_varchar2)) or
3063         (nvl(l_old_tx_typ_cd,hr_api.g_varchar2)<>
3064                 nvl(l_enrt_rt.tx_typ_cd,hr_api.g_varchar2)) or
3065         (nvl(l_old_acty_typ_cd,hr_api.g_varchar2)<>
3066                 nvl(l_enrt_rt.acty_typ_cd,hr_api.g_varchar2)) or
3067         (nvl(l_old_mlt_cd,hr_api.g_varchar2)<>
3068                 nvl(l_enrt_rt.rt_mlt_cd,hr_api.g_varchar2)) or
3069         (nvl(l_old_acty_ref_perd_cd,hr_api.g_varchar2)<>
3070                 nvl(p_acty_ref_perd_cd,hr_api.g_varchar2)) or
3071         (nvl(l_old_rt_val,hr_api.g_number)<>
3072                 nvl(l_rt_val,hr_api.g_number)) or
3073         (nvl(l_old_ann_rt_val,hr_api.g_number) <>
3074                 nvl(l_ann_rt_val,hr_api.g_number)) or
3075         (nvl(l_old_bnft_rt_typ_cd,hr_api.g_varchar2) <>
3076                 nvl(l_enrt_rt.bnft_rt_typ_cd,hr_api.g_varchar2)) or
3077         (nvl(l_old_cmcd_ref_perd_cd,hr_api.g_varchar2) <>
3078                 nvl(l_enrt_rt.cmcd_acty_ref_perd_cd,hr_api.g_varchar2)) or
3079         (nvl(l_old_cmcd_rt_val,hr_api.g_number) <>
3080                 nvl(l_enrt_rt.cmcd_val,hr_api.g_number)) or
3081         (nvl(l_old_dsply_on_enrt_flag,hr_api.g_varchar2) <>
3082                 nvl(l_enrt_rt.dsply_on_enrt_flag,hr_api.g_varchar2)) or
3083         (nvl(l_old_cvg_amt_calc_mthd_id,hr_api.g_number) <>
3084                 nvl(l_enrt_rt.cvg_amt_calc_mthd_id,hr_api.g_number)) or
3085         (nvl(l_old_actl_prem_id,hr_api.g_number) <>
3086                 nvl(l_enrt_rt.actl_prem_id,hr_api.g_number)) or
3087         (nvl(l_old_comp_lvl_fctr_id,hr_api.g_number) <>
3088                 nvl(l_enrt_rt.comp_lvl_fctr_id,hr_api.g_number)) or
3089         (nvl(l_old_prtt_enrt_rslt_id,hr_api.g_number) <>
3090                 nvl(p_prtt_enrt_rslt_id,hr_api.g_number)) or
3091         (nvl(l_old_rt_strt_dt,hr_api.g_date) <>
3092                 nvl(l_enrt_rt.rt_strt_dt,hr_api.g_date)) or
3093         (nvl(l_old_per_in_ler_id,hr_api.g_number) <>
3094                 nvl(p_per_in_ler_id,hr_api.g_number)) or
3095         l_global_pen_rec.sspndd_flag = 'Y'  or /*4775760 */
3096         p_bnft_amt_changed=TRUE or
3097         l_element_changed ) then
3098         --
3099         -- handle old rate
3100        if g_debug then
3101          hr_utility.set_location(l_proc||'In the TRUE', 1330);
3102        end if;
3103         --
3104        -- if l_unrestricted = 'Y' and -- commented for 4775760,4871284
3105         if   l_old_rt_strt_dt >= l_enrt_rt.rt_strt_dt then
3106           --
3107           -- delete future dated rate
3108           --
3109           if not p_calculate_only_mode then
3110             --
3111             ben_prtt_rt_val_api.delete_prtt_rt_val
3112               (p_prtt_rt_val_id                => p_prtt_rt_val_id
3113               ,p_enrt_rt_id                    => p_enrt_rt_id
3114               ,p_person_id                     => p_person_id
3115               ,p_business_group_id             => l_enrt_rt.business_group_id
3116               ,p_object_version_number         => l_old_object_version_number
3117               ,p_effective_date                => p_effective_date
3118               );
3119             --
3120           end if;
3121           --
3122         else
3123           --
3124           -- set the rate end date on the old one
3125           --
3126           if g_debug then
3127              hr_utility.set_location('BEF ben_determine_date.rate_and_coverage_dates',1999);
3128              hr_utility.set_location('l_enrt_rt.elig_per_elctbl_chc_id'||l_enrt_rt.elig_per_elctbl_chc_id,1999);
3129              hr_utility.set_location('l_xenrt_cvg_strt_dt'||l_xenrt_cvg_strt_dt,1999);
3130              hr_utility.set_location('l_xenrt_cvg_strt_dt_cd'||l_xenrt_cvg_strt_dt_cd,1999);
3131              hr_utility.set_location('l_xenrt_cvg_strt_dt_rl'||l_xenrt_cvg_strt_dt_rl,1999);
3132              hr_utility.set_location('l_xrt_strt_dt'||l_xrt_strt_dt,1999);
3133              hr_utility.set_location('l_xrt_strt_dt_cd'||l_xrt_strt_dt_cd,1999);
3134              hr_utility.set_location('l_xenrt_cvg_end_dt'||l_xenrt_cvg_end_dt,1999);
3135              hr_utility.set_location('l_xenrt_cvg_end_dt_cd'||l_xenrt_cvg_end_dt_cd,1999);
3136              hr_utility.set_location('l_xrt_end_dt'||l_xrt_end_dt,1999);
3137              hr_utility.set_location('l_xrt_end_dt_cd'||l_xrt_end_dt_cd,1999);
3138              hr_utility.set_location('l_enrt_rt.acty_base_rt_id'||l_enrt_rt.acty_base_rt_id,1999);
3139             hr_utility.set_location('p_effective_date'||p_effective_date,1999);
3140           end if;
3141 
3142           ben_determine_date.rate_and_coverage_dates
3143             (p_which_dates_cd         => 'R'
3144             ,p_business_group_id      => p_business_group_id
3145             ,p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id
3146             ,p_enrt_cvg_strt_dt       => l_xenrt_cvg_strt_dt
3147             ,p_enrt_cvg_strt_dt_cd    => l_xenrt_cvg_strt_dt_cd
3148             ,p_enrt_cvg_strt_dt_rl    => l_xenrt_cvg_strt_dt_rl
3149             ,p_rt_strt_dt             => l_xrt_strt_dt
3150             ,p_rt_strt_dt_cd          => l_xrt_strt_dt_cd
3151             ,p_rt_strt_dt_rl          => l_xrt_strt_dt_rl
3152             ,p_enrt_cvg_end_dt        => l_xenrt_cvg_end_dt
3153             ,p_enrt_cvg_end_dt_cd     => l_xenrt_cvg_end_dt_cd
3154             ,p_enrt_cvg_end_dt_rl     => l_xenrt_cvg_end_dt_rl
3155             ,p_rt_end_dt              => l_xrt_end_dt
3156             ,p_rt_end_dt_cd           => l_xrt_end_dt_cd
3157             ,p_rt_end_dt_rl           => l_xrt_end_dt_rl
3158             ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
3159             ,p_effective_date         => p_effective_date
3160 	    ,p_lf_evt_ocrd_dt         => l_lf_evt_ocrd_dt); -- bug 5717428
3161           --
3162           -- If the rate end date code is '1 Prior or Enterable' (WAENT),
3163           -- then the rate end date is 1 Less than the rate start date.
3164           --
3165           if l_xrt_end_dt_cd = 'WAENT' and
3166              p_rt_strt_dt is not null then
3167              l_xrt_end_dt := p_rt_strt_dt -1;
3168           elsif l_xrt_end_dt_cd = 'WAENT' and p_rt_strt_dt is null then
3169              l_xrt_end_dt := l_xrt_strt_dt -1;
3170           end if;
3171           --
3172           -- If the rate end date code is '1 prior or Later of Event ..etc or
3173           -- codes start with W or LW need to be ended 1 day before rate start date
3174           -- bug#2055961
3175           if  (substr(nvl(l_xrt_end_dt_cd, 'X'), 1, 1) = 'W' or
3176                 substr(nvl(l_xrt_end_dt_cd, 'X'), 1, 2) = 'LW' or
3177                 l_xrt_end_dt_cd in ('LDPPFEFD','LDPPOEFD')) and
3178                 not (l_xrt_end_dt_cd = 'WAENT') then
3179               l_xrt_end_dt := l_xrt_strt_dt -1;
3180           end if;
3181 
3182           if g_debug then
3183             hr_utility.set_location('p rate strt date'||p_rt_strt_dt,111);
3184           end if;
3185           if p_rt_strt_dt > l_old_rt_end_dt then
3186              l_xrt_end_dt := l_old_rt_end_dt;
3187           end if;
3188 
3189           --
3190           if g_debug then
3191              hr_utility.set_location('After call to ben_determine_date.rate_and_coverage_dates',1999);
3192              hr_utility.set_location('l_enrt_rt.elig_per_elctbl_chc_id'||l_enrt_rt.elig_per_elctbl_chc_id,1999);
3193              hr_utility.set_location('l_xenrt_cvg_strt_dt'||l_xenrt_cvg_strt_dt,1999);
3194              hr_utility.set_location('l_xenrt_cvg_strt_dt_cd'||l_xenrt_cvg_strt_dt_cd,1999);
3195              hr_utility.set_location('l_xenrt_cvg_strt_dt_rl'||l_xenrt_cvg_strt_dt_rl,1999);
3196              hr_utility.set_location('l_xrt_strt_dt'||l_xrt_strt_dt,1999);
3197              hr_utility.set_location('l_xrt_strt_dt_cd'||l_xrt_strt_dt_cd,1999);
3198              hr_utility.set_location('l_xenrt_cvg_end_dt'||l_xenrt_cvg_end_dt,1999);
3199              hr_utility.set_location('l_xenrt_cvg_end_dt_cd'||l_xenrt_cvg_end_dt_cd,1999);
3200              hr_utility.set_location('l_xrt_end_dt'||l_xrt_end_dt,1999);
3201              hr_utility.set_location('l_xrt_end_dt_cd'||l_xrt_end_dt_cd,1999);
3202              hr_utility.set_location('l_enrt_rt.acty_base_rt_id'||l_enrt_rt.acty_base_rt_id,1999);
3203              hr_utility.set_location('p_effective_date'||p_effective_date,1999);
3204           end if;
3205         --
3206         -- bnft amt changed and entr val flag is N then election rate
3207         -- information is called after delete enrollment
3208         --
3209         if l_old_rt_end_dt < l_xrt_end_dt then
3210           --
3211           if not p_calculate_only_mode then
3212             --
3213             --Bug 2976103 Non Recurring rates are getting opened when called
3214             --from benraten. This needs to happed only for recurring rates.
3215             --
3216             if not l_non_recurring_rt then
3217               --
3218               ben_prtt_rt_val_api.update_prtt_rt_val
3219               (p_prtt_rt_val_id                 => p_prtt_rt_val_id
3220               ,p_rt_end_dt                      => hr_api.g_eot
3221               ,p_acty_base_rt_id                => l_enrt_rt.acty_base_rt_id
3222               ,p_input_value_id                 => l_enrt_rt.input_value_id
3223               ,p_element_type_id                => l_enrt_rt.element_type_id
3224               ,p_person_id                      => p_person_id
3225               ,p_ended_per_in_ler_id            => null
3226               ,p_business_group_id              => l_enrt_rt.business_group_id
3227               ,p_object_version_number          => l_old_object_version_number
3228               ,p_effective_date                 => p_effective_date
3229               );
3230               --
3231             end if;
3232             --
3233           end if;
3234           --
3235         end if;
3236 
3237         l_no_end_element := (not l_element_changed) and
3238                             (l_old_rt_val=l_rt_val);
3239 
3240         if p_bnft_amt_changed and l_enrt_rt.entr_val_At_enrt_flag = 'Y' then
3241 
3242           if g_debug then
3243             hr_utility.set_location('p_bnft_amt_changed',1999);
3244           end if;
3245           if not p_calculate_only_mode then
3246             --
3247              --
3248             ben_prtt_rt_val_api.update_prtt_rt_val
3249               (p_prtt_rt_val_id                => p_prtt_rt_val_id
3250               ,p_rt_end_dt                     => l_xrt_end_dt
3251               ,p_ended_per_in_ler_id           => p_per_in_ler_id
3252               ,p_acty_base_rt_id               => l_enrt_rt.acty_base_rt_id
3253               ,p_input_value_id                => l_enrt_rt.input_value_id
3254               ,p_element_type_id               => l_enrt_rt.element_type_id
3255               ,p_person_id                     => p_person_id
3256               ,p_business_group_id             => l_enrt_rt.business_group_id
3257               ,p_object_version_number         => l_old_object_version_number
3258               ,p_effective_date                => p_effective_date
3259               ,p_no_end_element                => l_no_end_element
3260               );
3261             --
3262           end if;
3263           --
3264         elsif p_bnft_amt_changed = FALSE then
3265           --
3266           -- p_amt_changed is false
3267           --
3268           if g_debug then
3269             hr_utility.set_location('bnft amount false',1999);
3270           end if;
3271           if not p_calculate_only_mode then
3272             --
3273             if  not l_non_recurring_rt then
3274               if l_old_rt_end_dt <> l_xrt_end_dt then
3275                 if g_debug then
3276                   hr_utility.set_location('processing type recurring ',1999);
3277                 end if;
3278                 --
3279 
3280                 ben_prtt_rt_val_api.update_prtt_rt_val
3281                   (p_prtt_rt_val_id                => p_prtt_rt_val_id
3282                   ,p_rt_end_dt                     => l_xrt_end_dt
3283                   ,p_ended_per_in_ler_id           => p_per_in_ler_id
3284                   ,p_acty_base_rt_id               => l_enrt_rt.acty_base_rt_id
3285                   ,p_input_value_id                => l_enrt_rt.input_value_id
3286                   ,p_element_type_id               => l_enrt_rt.element_type_id
3287                   ,p_person_id                     => p_person_id
3288                   ,p_business_group_id             => l_enrt_rt.business_group_id
3289                   ,p_object_version_number         => l_old_object_version_number
3290                   ,p_effective_date                => p_effective_date
3291                   ,p_no_end_element                => l_no_end_element
3292                   );
3293                end if;
3294             --
3295             end if;
3296             --
3297           end if;
3298 
3299          end if;
3300         end if;
3301         --
3302         -- update rate
3303         --
3304         if g_debug then
3305           hr_utility.set_location(l_proc, 130);
3306         end if;
3307         --
3308         if not p_calculate_only_mode then
3309           --
3310           -- Bug 2677804 if the rate has override thru date in the previous
3311           -- prv and the thru date is on or after the l_enrt_rt.rt_strt_dt
3312           -- we need to carry forward the information for going forward
3313           --        l_old_rt_ovridn_flag            varchar2(30);
3314           --        l_old_rt_ovridn_thru_dt         date;
3315           if l_old_rt_ovridn_flag = 'Y' and
3316              nvl(l_old_rt_ovridn_thru_dt, l_enrt_rt.rt_strt_dt+1 ) < l_enrt_rt.rt_strt_dt  then -- bug 5942441
3317             --
3318             l_old_rt_ovridn_flag := 'N' ;
3319             l_old_rt_ovridn_thru_dt := null ;
3320             --
3321           end if ;
3322 
3323  -- 7206471 Check if the rates should be adjusted.
3324   --
3325   --
3326   --  Check if there is a life event in the same month.
3327   --
3328   open c_get_prior_per_in_ler;
3329   fetch c_get_prior_per_in_ler into l_exists;
3330   if c_get_prior_per_in_ler%found then
3331     --
3332       --
3333       open c_get_pgm_extra_info;
3334       fetch c_get_pgm_extra_info into l_adjust;
3335       if c_get_pgm_extra_info%found then
3336         --
3337         if l_adjust = 'Y' then
3338           --
3339           --  Get rt end dt
3340           --
3341           for l_epe in c_get_elctbl_chc loop
3342             --
3343             --  Get all results that were de-enrolled for the event.
3344             --
3345             for l_pen in c_get_enrt_rslts(l_epe.rt_strt_dt
3346                                        ,l_epe.ptip_id ) loop
3347               hr_utility.set_location('Adjusting rate '||l_epe.rt_strt_dt,111);
3348               --
3349               open c_prtt_rt_val_adj(p_per_in_ler_id,l_pen.prtt_rt_val_id);
3350               fetch c_prtt_rt_val_adj into l_exists;
3351               if c_prtt_rt_val_adj%notfound then
3352                 insert into BEN_LE_CLSN_N_RSTR (
3353                         BKUP_TBL_TYP_CD,
3354                         BKUP_TBL_ID,
3355                         per_in_ler_id,
3356                         person_id,
3357                         RT_END_DT,
3358                         business_group_id,
3359                         object_version_number)
3360                       values (
3361                         'BEN_PRTT_RT_VAL_ADJ',
3362                         l_pen.prtt_rt_val_id,
3363                         p_per_in_ler_id,
3364                         l_pen.person_id,
3365                         l_pen.rt_end_dt,
3366                         p_business_group_id,
3367                         l_pen.object_version_number
3368                       );
3369               end if;
3370               close c_prtt_rt_val_adj;
3371                --
3372               ben_prtt_rt_val_api.update_prtt_rt_val
3373                (P_VALIDATE                => FALSE
3374                ,P_PRTT_RT_VAL_ID          => l_pen.prtt_rt_val_id
3375                ,P_RT_END_DT               => l_epe.rt_strt_dt - 1
3376                ,p_person_id               => l_pen.person_id
3377                ,p_input_value_id          => l_pen.input_value_id
3378                ,p_element_type_id         => l_pen.element_type_id
3379                ,p_business_group_id       => p_business_group_id
3380                ,P_OBJECT_VERSION_NUMBER   => l_pen.object_version_number
3381                ,P_EFFECTIVE_DATE          => p_effective_date
3382                );
3383             end loop;  -- c_get_enrt_rslts
3384           end loop; -- c_get_elctbl_chc
3385         end if;  -- l_adjust = 'Y'
3386       end if;  -- c_get_pgm_extra_info
3387       close c_get_pgm_extra_info;
3388     end if;
3389     close c_get_prior_per_in_ler;
3390     -- end 7206471
3391 
3392           ben_prtt_rt_val_api.create_prtt_rt_val
3393             (p_prtt_rt_val_id                 => p_prtt_rt_val_id
3394             ,p_enrt_rt_id                     => p_enrt_rt_id
3395             ,p_per_in_ler_id                  => p_per_in_ler_id
3396             ,p_rt_typ_cd                      => l_enrt_rt.rt_typ_cd
3397             ,p_tx_typ_cd                      => l_enrt_rt.tx_typ_cd
3398             ,p_acty_typ_cd                    => l_enrt_rt.acty_typ_cd
3399             ,p_mlt_cd                         => l_enrt_rt.rt_mlt_cd
3400             ,p_acty_ref_perd_cd               => p_acty_ref_perd_cd
3401             ,p_rt_val                         => l_rt_val
3402             ,p_rt_strt_dt                     => l_enrt_rt.rt_strt_dt
3403             ,p_rt_end_dt                      => hr_api.g_eot
3404             ,p_ann_rt_val                     => l_ann_rt_val
3405             ,p_bnft_rt_typ_cd                 => l_enrt_rt.bnft_rt_typ_cd
3406             ,p_cmcd_ref_perd_cd               => l_enrt_rt.cmcd_acty_ref_perd_cd
3407             ,p_cmcd_rt_val                    => l_enrt_rt.cmcd_val
3408             ,p_dsply_on_enrt_flag             => l_enrt_rt.dsply_on_enrt_flag
3409             ,p_elctns_made_dt                 => p_effective_date
3410             ,p_cvg_amt_calc_mthd_id           => l_enrt_rt.cvg_amt_calc_mthd_id
3411             ,p_actl_prem_id                   => l_enrt_rt.actl_prem_id
3412             ,p_comp_lvl_fctr_id               => l_enrt_rt.comp_lvl_fctr_id
3413             ,p_prtt_enrt_rslt_id              => p_prtt_enrt_rslt_id
3414             ,p_business_group_id              => l_enrt_rt.business_group_id
3415             ,p_object_version_number          => l_old_object_version_number
3416             ,p_effective_date                 => p_effective_date
3417             ,p_acty_base_rt_id                => l_enrt_rt.acty_base_rt_id
3418             ,p_input_value_id                 => l_enrt_rt.input_value_id
3419             ,p_element_type_id                => l_enrt_rt.element_type_id
3420             ,p_person_id                      => p_person_id
3421             ,p_pp_in_yr_used_num              => l_enrt_rt.pp_in_yr_used_num
3422             ,p_ordr_num                       => l_enrt_rt.ordr_num
3423             -- Bug 2677804
3424             ,p_rt_ovridn_flag                 => l_old_rt_ovridn_flag
3425             ,p_rt_ovridn_thru_dt              => l_old_rt_ovridn_thru_dt
3426             --
3427             );
3428           if g_debug then
3429             hr_utility.set_location(l_proc, 135);
3430           end if;
3431         end if;
3432         --
3433       else
3434         --
3435         -- Check for old rate being reused, set end dt to eot.
3436         -- Re-use the rate only if the rate is continuous (maagrawa 2/24/00)
3437         --
3438         if l_old_rt_end_dt is not null and
3439            l_old_rt_end_dt <> hr_api.g_eot and
3440            l_enrt_rt.rt_strt_dt <= l_old_rt_end_dt then
3441           --
3442           if not p_calculate_only_mode then
3443             --
3444             --Bug 2976103 Non Recurring rates are getting opened when called
3445             --from benraten. This needs to happed only for recurring rates.
3446             --
3447             if not l_non_recurring_rt then
3448               --
3449               ben_prtt_rt_val_api.update_prtt_rt_val
3450               (p_prtt_rt_val_id                 => p_prtt_rt_val_id
3451               ,p_rt_end_dt                      => hr_api.g_eot
3452               ,p_acty_base_rt_id                => l_enrt_rt.acty_base_rt_id
3453               ,p_input_value_id                 => l_enrt_rt.input_value_id
3454               ,p_element_type_id                => l_enrt_rt.element_type_id
3455               ,p_person_id                      => p_person_id
3456               ,p_ended_per_in_ler_id            => null
3457               ,p_business_group_id              => l_enrt_rt.business_group_id
3458               ,p_object_version_number          => l_old_object_version_number
3459               ,p_effective_date                 => p_effective_date
3460               );
3461               --
3462             end if;
3463             --
3464           end if;
3465           --
3466         end if;
3467 
3468         if g_debug then
3469            hr_utility.set_location(l_proc||'Do nothing if old prv is fine ', 1330);
3470         end if;
3471 
3472       end if;
3473 
3474     else
3475       if g_debug then
3476         hr_utility.set_location(l_proc, 140);
3477       end if;
3478       --
3479       if not p_calculate_only_mode then
3480         --
3481         -- Bug 2677804 if the rate has override thru date in the previous
3482         -- prv and the thru date is on or after the l_enrt_rt.rt_strt_dt
3483         -- we need to carry forward the information for going forward
3484         --        l_old_rt_ovridn_flag            varchar2(30);
3485         --        l_old_rt_ovridn_thru_dt         date;
3486         if l_old_rt_ovridn_flag = 'Y' and
3487             nvl(l_old_rt_ovridn_thru_dt, l_enrt_rt.rt_strt_dt+1 ) < l_enrt_rt.rt_strt_dt then -- bug 5942441
3488           --
3489           l_old_rt_ovridn_flag := 'N' ;
3490           l_old_rt_ovridn_thru_dt := null ;
3491           --
3492         end if ;
3493 	-- 7206471 Check if the rates should be adjusted.
3494   --
3495   --
3496   --  Check if there is a life event in the same month.
3497   --
3498   open c_get_prior_per_in_ler;
3499   fetch c_get_prior_per_in_ler into l_exists;
3500   if c_get_prior_per_in_ler%found then
3501     --
3502       --
3503       open c_get_pgm_extra_info;
3504       fetch c_get_pgm_extra_info into l_adjust;
3505       if c_get_pgm_extra_info%found then
3506         --
3507         if l_adjust = 'Y' then
3508           --
3509           --  Get rt end dt
3510           --
3511           for l_epe in c_get_elctbl_chc loop
3512             --
3513             --  Get all results that were de-enrolled for the event.
3514             --
3515             for l_pen in c_get_enrt_rslts(l_epe.rt_strt_dt
3516                                        ,l_epe.ptip_id ) loop
3517               hr_utility.set_location('Adjusting rate '||l_epe.rt_strt_dt,111);
3518               --
3519               open c_prtt_rt_val_adj(p_per_in_ler_id,l_pen.prtt_rt_val_id);
3520               fetch c_prtt_rt_val_adj into l_exists;
3521               if c_prtt_rt_val_adj%notfound then
3522                 insert into BEN_LE_CLSN_N_RSTR (
3523                         BKUP_TBL_TYP_CD,
3524                         BKUP_TBL_ID,
3525                         per_in_ler_id,
3526                         person_id,
3527                         RT_END_DT,
3528                         business_group_id,
3529                         object_version_number)
3530                       values (
3531                         'BEN_PRTT_RT_VAL_ADJ',
3532                         l_pen.prtt_rt_val_id,
3533                         p_per_in_ler_id,
3534                         l_pen.person_id,
3535                         l_pen.rt_end_dt,
3536                         p_business_group_id,
3537                         l_pen.object_version_number
3538                       );
3539               end if;
3540               close c_prtt_rt_val_adj;
3541                --
3542               ben_prtt_rt_val_api.update_prtt_rt_val
3543                (P_VALIDATE                => FALSE
3544                ,P_PRTT_RT_VAL_ID          => l_pen.prtt_rt_val_id
3545                ,P_RT_END_DT               => l_epe.rt_strt_dt - 1
3546                ,p_person_id               => l_pen.person_id
3547                ,p_input_value_id          => l_pen.input_value_id
3548                ,p_element_type_id         => l_pen.element_type_id
3549                ,p_business_group_id       => p_business_group_id
3550                ,P_OBJECT_VERSION_NUMBER   => l_pen.object_version_number
3551                ,P_EFFECTIVE_DATE          => p_effective_date
3552                );
3553             end loop;  -- c_get_enrt_rslts
3554           end loop; -- c_get_elctbl_chc
3555         end if;  -- l_adjust = 'Y'
3556       end if;  -- c_get_pgm_extra_info
3557       close c_get_pgm_extra_info;
3558     end if;
3559     close c_get_prior_per_in_ler;
3560     -- end 7206471
3561         -- if no prtt_rt_val_id passed do insert
3562         ben_prtt_rt_val_api.create_prtt_rt_val
3563           (p_prtt_rt_val_id                 => p_prtt_rt_val_id
3564           ,p_enrt_rt_id                     => p_enrt_rt_id
3565           ,p_per_in_ler_id                  => p_per_in_ler_id
3566           ,p_rt_typ_cd                      => l_enrt_rt.rt_typ_cd
3567           ,p_tx_typ_cd                      => l_enrt_rt.tx_typ_cd
3568           ,p_acty_typ_cd                    => l_enrt_rt.acty_typ_cd
3569           ,p_mlt_cd                         => l_enrt_rt.rt_mlt_cd
3570           ,p_acty_ref_perd_cd               => p_acty_ref_perd_cd
3571           ,p_rt_val                         => l_rt_val
3572           ,p_rt_strt_dt                     => l_enrt_rt.rt_strt_dt
3573           ,p_rt_end_dt                      => hr_api.g_eot
3574           ,p_ann_rt_val                     => l_ann_rt_val
3575           ,p_bnft_rt_typ_cd                 => l_enrt_rt.bnft_rt_typ_cd
3576           ,p_cmcd_ref_perd_cd               => l_enrt_rt.cmcd_acty_ref_perd_cd
3577           ,p_cmcd_rt_val                    => l_enrt_rt.cmcd_val
3578           ,p_dsply_on_enrt_flag             => l_enrt_rt.dsply_on_enrt_flag
3579           ,p_elctns_made_dt                 => p_effective_date
3580           ,p_cvg_amt_calc_mthd_id           => l_enrt_rt.cvg_amt_calc_mthd_id
3581           ,p_actl_prem_id                   => l_enrt_rt.actl_prem_id
3582           ,p_comp_lvl_fctr_id               => l_enrt_rt.comp_lvl_fctr_id
3583           ,p_prtt_enrt_rslt_id              => p_prtt_enrt_rslt_id
3584           ,p_business_group_id              => l_enrt_rt.business_group_id
3585           ,p_object_version_number          => l_old_object_version_number
3586           ,p_effective_date                 => p_effective_date
3587           ,p_acty_base_rt_id                => l_enrt_rt.acty_base_rt_id
3588           ,p_input_value_id                 => l_enrt_rt.input_value_id
3589           ,p_element_type_id                => l_enrt_rt.element_type_id
3590           ,p_person_id                      => p_person_id
3591           ,p_pp_in_yr_used_num              => l_enrt_rt.pp_in_yr_used_num
3592           ,p_ordr_num               => l_enrt_rt.ordr_num
3593           -- Bug 2677804
3594           ,p_rt_ovridn_flag                 => l_old_rt_ovridn_flag
3595           ,p_rt_ovridn_thru_dt              => l_old_rt_ovridn_thru_dt
3596           --
3597           );
3598         if g_debug then
3599           hr_utility.set_location(l_proc, 145);
3600         end if;
3601       end if;
3602     end if;
3603     --
3604     -- Check of the rate end date is passed in as parameter.
3605     -- If Yes, then check for the rate end date code.
3606     -- If it is WAENT, then the rate has to be ended with the
3607     -- parameter end date.
3608     --
3609     if not p_calculate_only_mode and
3610        l_rt_end_dt is not null and
3611        l_rt_end_dt <> hr_api.g_eot then
3612       --
3613       if l_xrt_end_dt_cd is null then
3614         ben_determine_date.rate_and_coverage_dates
3615           (p_which_dates_cd         => 'R'
3616           ,p_compute_dates_flag     => 'N'
3617           ,p_business_group_id      => p_business_group_id
3618           ,p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id
3619           ,p_enrt_cvg_strt_dt       => l_xenrt_cvg_strt_dt
3620           ,p_enrt_cvg_strt_dt_cd    => l_xenrt_cvg_strt_dt_cd
3621           ,p_enrt_cvg_strt_dt_rl    => l_xenrt_cvg_strt_dt_rl
3622           ,p_rt_strt_dt             => l_xrt_strt_dt
3623           ,p_rt_strt_dt_cd          => l_xrt_strt_dt_cd
3624           ,p_rt_strt_dt_rl          => l_xrt_strt_dt_rl
3625           ,p_enrt_cvg_end_dt        => l_xenrt_cvg_end_dt
3626           ,p_enrt_cvg_end_dt_cd     => l_xenrt_cvg_end_dt_cd
3627           ,p_enrt_cvg_end_dt_rl     => l_xenrt_cvg_end_dt_rl
3628           ,p_rt_end_dt              => l_xrt_end_dt
3629           ,p_rt_end_dt_cd           => l_xrt_end_dt_cd
3630           ,p_rt_end_dt_rl           => l_xrt_end_dt_rl
3631           ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
3632           ,p_effective_date         => p_effective_date);
3633       end if;
3634       --
3635       if l_xrt_end_dt_cd = 'WAENT' then
3636         ben_prtt_rt_val_api.update_prtt_rt_val
3637           (p_prtt_rt_val_id                => p_prtt_rt_val_id
3638           ,p_rt_end_dt                     => l_rt_end_dt
3639           ,p_ended_per_in_ler_id           => p_per_in_ler_id
3640           ,p_acty_base_rt_id               => l_enrt_rt.acty_base_rt_id
3641           ,p_input_value_id                => l_enrt_rt.input_value_id
3642           ,p_element_type_id               => l_enrt_rt.element_type_id
3643           ,p_person_id                     => p_person_id
3644           ,p_business_group_id             => l_enrt_rt.business_group_id
3645           ,p_object_version_number         => l_old_object_version_number
3646           ,p_effective_date                => p_effective_date);
3647       end if;
3648       --
3649     end if;
3650 
3651     if l_enrt_rt.decr_bnft_prvdr_pool_id is not null
3652        and l_global_pen_rec.sspndd_flag = 'N' then
3653       --
3654       if not p_calculate_only_mode then
3655         --
3656         ben_provider_pools.create_debit_ledger_entry
3657           (p_person_id               => p_person_id
3658           ,p_per_in_ler_id           => p_per_in_ler_id
3659           ,p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id
3660           ,p_prtt_enrt_rslt_id       => p_prtt_enrt_rslt_id
3661           ,p_decr_bnft_prvdr_pool_id => l_enrt_rt.decr_bnft_prvdr_pool_id
3662           ,p_acty_base_rt_id         => l_enrt_rt.acty_base_rt_id
3663           ,p_prtt_rt_val_id          => p_prtt_rt_val_id
3664           ,p_enrt_mthd_cd            => p_enrt_mthd_cd
3665           ,p_val                     => l_rt_val
3666           ,p_bnft_prvdd_ldgr_id      => l_bnft_prvdd_ldgr_id
3667           ,p_business_group_id       => p_business_group_id
3668           ,p_effective_date          => p_effective_date
3669           --
3670           ,p_bpl_used_val            => l_dummy_number
3671           );
3672         --
3673       end if;
3674       --
3675     end if;
3676     --
3677     if g_debug then
3678       hr_utility.set_location('Leaving:'||l_proc, 99);
3679     end if;
3680 
3681   ben_manage_life_events.fonm := null;
3682   ben_manage_life_events.g_fonm_cvg_strt_dt := null;
3683   ben_manage_life_events.g_fonm_rt_strt_dt := null;
3684   --
3685   -- Set OUT parameters
3686   --
3687   p_prv_rt_val     := l_rt_val;
3688   p_prv_ann_rt_val := l_ann_rt_val;
3689   --
3690 end election_rate_information;
3691 --
3692 -- ----------------------------------------------------------------------------
3693 -- |--------------------------< election_information >-------------------------|
3694 -- ----------------------------------------------------------------------------
3695 -- OVERLOADED, SEE BELOW.
3696 -- Do not add new flags to this procedure unless forms need to pass them.
3697 --
3698 procedure election_information
3699   (p_validate               in boolean default FALSE
3700   ,p_elig_per_elctbl_chc_id in number
3701   ,p_prtt_enrt_rslt_id      in out nocopy number
3702   ,p_effective_date         in date
3703   ,p_enrt_mthd_cd           in varchar2
3704   ,p_enrt_bnft_id           in number
3705   ,p_bnft_val               in number default null
3706   ,p_enrt_cvg_strt_dt       in  date  default null
3707   ,p_enrt_cvg_thru_dt       in  date  default null
3708   ,p_enrt_rt_id1            in number default null
3709   ,p_prtt_rt_val_id1        in out nocopy number
3710   ,p_rt_val1                in number default null
3711   ,p_ann_rt_val1            in number default null
3712   ,p_rt_strt_dt1            in date   default null
3713   ,p_rt_end_dt1             in date   default null
3714   ,p_enrt_rt_id2            in number default null
3715   ,p_prtt_rt_val_id2        in out nocopy number
3716   ,p_rt_val2                in number default null
3717   ,p_ann_rt_val2            in number default null
3718   ,p_rt_strt_dt2            in date   default null
3719   ,p_rt_end_dt2             in date   default null
3720   ,p_enrt_rt_id3            in number default null
3721   ,p_prtt_rt_val_id3        in out nocopy number
3722   ,p_rt_val3                in number default null
3723   ,p_ann_rt_val3            in number default null
3724   ,p_rt_strt_dt3            in date   default null
3725   ,p_rt_end_dt3             in date   default null
3726   ,p_enrt_rt_id4            in number default null
3727   ,p_prtt_rt_val_id4        in out nocopy number
3728   ,p_rt_val4                in number default null
3729   ,p_ann_rt_val4            in number default null
3730   ,p_rt_strt_dt4            in date   default null
3731   ,p_rt_end_dt4             in date   default null
3732   ,p_enrt_rt_id5            in number default null
3733   ,p_prtt_rt_val_id5        in out nocopy number
3734   ,p_rt_val5                in number default null
3735   ,p_ann_rt_val5            in number default null
3736   ,p_rt_strt_dt5            in date   default null
3737   ,p_rt_end_dt5             in date   default null
3738   ,p_enrt_rt_id6            in number default null
3739   ,p_prtt_rt_val_id6        in out nocopy number
3740   ,p_rt_val6                in number default null
3741   ,p_ann_rt_val6            in number default null
3742   ,p_rt_strt_dt6            in date   default null
3743   ,p_rt_end_dt6             in date   default null
3744   ,p_enrt_rt_id7            in number default null
3745   ,p_prtt_rt_val_id7        in out nocopy number
3746   ,p_rt_val7                in number default null
3747   ,p_ann_rt_val7            in number default null
3748   ,p_rt_strt_dt7            in date   default null
3749   ,p_rt_end_dt7             in date   default null
3750   ,p_enrt_rt_id8            in number default null
3751   ,p_prtt_rt_val_id8        in out nocopy number
3752   ,p_rt_val8                in number default null
3753   ,p_ann_rt_val8            in number default null
3754   ,p_rt_strt_dt8            in date   default null
3755   ,p_rt_end_dt8             in date   default null
3756   ,p_enrt_rt_id9            in number default null
3757   ,p_prtt_rt_val_id9        in out nocopy number
3758   ,p_rt_val9                in number default null
3759   ,p_ann_rt_val9            in number default null
3760   ,p_rt_strt_dt9            in date   default null
3761   ,p_rt_end_dt9             in date   default null
3762   ,p_enrt_rt_id10           in number default null
3763   ,p_prtt_rt_val_id10       in out nocopy number
3764   ,p_rt_val10               in number default null
3765   ,p_ann_rt_val10           in number default null
3766   ,p_rt_strt_dt10           in date   default null
3767   ,p_rt_end_dt10            in date   default null
3768   ,p_datetrack_mode         in varchar2
3769   ,p_suspend_flag           in out nocopy varchar2
3770   ,p_effective_start_date   out nocopy date
3771   ,p_effective_end_date     out nocopy date
3772   ,p_object_version_number  in out nocopy number
3773   ,p_prtt_enrt_interim_id   out nocopy number
3774   ,p_business_group_id      in  number
3775   ,p_pen_attribute_category in  varchar2  default hr_api.g_varchar2
3776   ,p_pen_attribute1         in  varchar2  default hr_api.g_varchar2
3777   ,p_pen_attribute2         in  varchar2  default hr_api.g_varchar2
3778   ,p_pen_attribute3         in  varchar2  default hr_api.g_varchar2
3779   ,p_pen_attribute4         in  varchar2  default hr_api.g_varchar2
3780   ,p_pen_attribute5         in  varchar2  default hr_api.g_varchar2
3781   ,p_pen_attribute6         in  varchar2  default hr_api.g_varchar2
3782   ,p_pen_attribute7         in  varchar2  default hr_api.g_varchar2
3783   ,p_pen_attribute8         in  varchar2  default hr_api.g_varchar2
3784   ,p_pen_attribute9         in  varchar2  default hr_api.g_varchar2
3785   ,p_pen_attribute10        in  varchar2  default hr_api.g_varchar2
3786   ,p_pen_attribute11        in  varchar2  default hr_api.g_varchar2
3787   ,p_pen_attribute12        in  varchar2  default hr_api.g_varchar2
3788   ,p_pen_attribute13        in  varchar2  default hr_api.g_varchar2
3789   ,p_pen_attribute14        in  varchar2  default hr_api.g_varchar2
3790   ,p_pen_attribute15        in  varchar2  default hr_api.g_varchar2
3791   ,p_pen_attribute16        in  varchar2  default hr_api.g_varchar2
3792   ,p_pen_attribute17        in  varchar2  default hr_api.g_varchar2
3793   ,p_pen_attribute18        in  varchar2  default hr_api.g_varchar2
3794   ,p_pen_attribute19        in  varchar2  default hr_api.g_varchar2
3795   ,p_pen_attribute20        in  varchar2  default hr_api.g_varchar2
3796   ,p_pen_attribute21        in  varchar2  default hr_api.g_varchar2
3797   ,p_pen_attribute22        in  varchar2  default hr_api.g_varchar2
3798   ,p_pen_attribute23        in  varchar2  default hr_api.g_varchar2
3799   ,p_pen_attribute24        in  varchar2  default hr_api.g_varchar2
3800   ,p_pen_attribute25        in  varchar2  default hr_api.g_varchar2
3801   ,p_pen_attribute26        in  varchar2  default hr_api.g_varchar2
3802   ,p_pen_attribute27        in  varchar2  default hr_api.g_varchar2
3803   ,p_pen_attribute28        in  varchar2  default hr_api.g_varchar2
3804   ,p_pen_attribute29        in  varchar2  default hr_api.g_varchar2
3805   ,p_pen_attribute30        in  varchar2  default hr_api.g_varchar2
3806   ,p_dpnt_actn_warning      out nocopy boolean
3807   ,p_bnf_actn_warning       out nocopy boolean
3808   ,p_ctfn_actn_warning      out nocopy boolean)
3809 is
3810 BEGIN
3811   --
3812   -- Created this procedure so we could add flags to the proc that the
3813   -- forms do not need to pass.  They will call this original spec'ed
3814   -- proc.  The batch processes can call the other one if new flags are needed.
3815   --
3816 
3817   g_debug := hr_utility.debug_enabled;
3818 --hr_utility. set_location( ' p_rt_val1 '||p_rt_val1 , 211);
3819 --hr_utility. set_location( ' p_ann_rt_val1 '||p_ann_rt_val1,211);
3820   -- please mark new flags with a comment.
3821  election_information
3822   (p_validate               => p_validate
3823   ,p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id
3824   ,p_prtt_enrt_rslt_id      => p_prtt_enrt_rslt_id
3825   ,p_effective_date         => p_effective_date
3826   ,p_enrt_mthd_cd           => p_enrt_mthd_cd
3827   ,p_enrt_bnft_id           => p_enrt_bnft_id
3828   ,p_bnft_val               => p_bnft_val
3829   ,p_enrt_cvg_strt_dt       => p_enrt_cvg_strt_dt -- bug 1840961
3830   ,p_enrt_cvg_thru_dt       => p_enrt_cvg_thru_dt -- bug 1840961
3831   ,p_enrt_rt_id1            => p_enrt_rt_id1
3832   ,p_prtt_rt_val_id1        => p_prtt_rt_val_id1
3833   ,p_rt_val1                => p_rt_val1
3834   ,p_ann_rt_val1            => p_ann_rt_val1
3835   ,p_rt_strt_dt1            => p_rt_strt_dt1
3836   ,p_rt_end_dt1             => p_rt_end_dt1
3837   ,p_enrt_rt_id2            => p_enrt_rt_id2
3838   ,p_prtt_rt_val_id2        => p_prtt_rt_val_id2
3839   ,p_rt_val2                => p_rt_val2
3840   ,p_ann_rt_val2            => p_ann_rt_val2
3841   ,p_rt_strt_dt2            => p_rt_strt_dt2
3842   ,p_rt_end_dt2             => p_rt_end_dt2
3843   ,p_enrt_rt_id3            => p_enrt_rt_id3
3844   ,p_prtt_rt_val_id3        => p_prtt_rt_val_id3
3845   ,p_rt_val3                => p_rt_val3
3846   ,p_ann_rt_val3            => p_ann_rt_val3
3847   ,p_rt_strt_dt3            => p_rt_strt_dt3
3848   ,p_rt_end_dt3             => p_rt_end_dt3
3849   ,p_enrt_rt_id4            => p_enrt_rt_id4
3850   ,p_prtt_rt_val_id4        => p_prtt_rt_val_id4
3851   ,p_rt_val4                => p_rt_val4
3852   ,p_ann_rt_val4            => p_ann_rt_val4
3853   ,p_rt_strt_dt4            => p_rt_strt_dt4
3854   ,p_rt_end_dt4             => p_rt_end_dt4
3855   ,p_enrt_rt_id5            => p_enrt_rt_id5
3856   ,p_prtt_rt_val_id5        => p_prtt_rt_val_id5
3857   ,p_rt_val5                => p_rt_val5
3858   ,p_ann_rt_val5            => p_ann_rt_val5
3859   ,p_rt_strt_dt5            => p_rt_strt_dt5
3860   ,p_rt_end_dt5             => p_rt_end_dt5
3861   ,p_enrt_rt_id6            => p_enrt_rt_id6
3862   ,p_prtt_rt_val_id6        => p_prtt_rt_val_id6
3863   ,p_rt_val6                => p_rt_val6
3864   ,p_ann_rt_val6            => p_ann_rt_val6
3865   ,p_rt_strt_dt6            => p_rt_strt_dt6
3866   ,p_rt_end_dt6             => p_rt_end_dt6
3867   ,p_enrt_rt_id7            => p_enrt_rt_id7
3868   ,p_prtt_rt_val_id7        => p_prtt_rt_val_id7
3869   ,p_rt_val7                => p_rt_val7
3870   ,p_ann_rt_val7            => p_ann_rt_val7
3871   ,p_rt_strt_dt7            => p_rt_strt_dt7
3872   ,p_rt_end_dt7             => p_rt_end_dt7
3873   ,p_enrt_rt_id8            => p_enrt_rt_id8
3874   ,p_prtt_rt_val_id8        => p_prtt_rt_val_id8
3875   ,p_rt_val8                => p_rt_val8
3876   ,p_ann_rt_val8            => p_ann_rt_val8
3877   ,p_rt_strt_dt8            => p_rt_strt_dt8
3878   ,p_rt_end_dt8             => p_rt_end_dt8
3879   ,p_enrt_rt_id9            => p_enrt_rt_id9
3880   ,p_prtt_rt_val_id9        => p_prtt_rt_val_id9
3881   ,p_rt_val9                => p_rt_val9
3882   ,p_ann_rt_val9            => p_ann_rt_val9
3883   ,p_rt_strt_dt9            => p_rt_strt_dt9
3884   ,p_rt_end_dt9             => p_rt_end_dt9
3885   ,p_enrt_rt_id10           => p_enrt_rt_id10
3886   ,p_prtt_rt_val_id10       => p_prtt_rt_val_id10
3887   ,p_rt_val10               => p_rt_val10
3888   ,p_ann_rt_val10           => p_ann_rt_val10
3889   ,p_rt_strt_dt10           => p_rt_strt_dt10
3890   ,p_rt_end_dt10            => p_rt_end_dt10
3891   ,p_datetrack_mode         => p_datetrack_mode
3892   ,p_suspend_flag           => p_suspend_flag
3893   ,p_called_from_sspnd      => 'N'               -- flag not in this spec
3894   ,p_effective_start_date   => p_effective_start_date
3895   ,p_effective_end_date     => p_effective_end_date
3896   ,p_object_version_number  => p_object_version_number
3897   ,p_prtt_enrt_interim_id   => p_prtt_enrt_interim_id
3898   ,p_business_group_id      =>  p_business_group_id
3899   ,p_pen_attribute_category =>  p_pen_attribute_category
3900   ,p_pen_attribute1         =>  p_pen_attribute1
3901   ,p_pen_attribute2         =>  p_pen_attribute2
3902   ,p_pen_attribute3         =>  p_pen_attribute3
3903   ,p_pen_attribute4         =>  p_pen_attribute4
3904   ,p_pen_attribute5         =>  p_pen_attribute5
3905   ,p_pen_attribute6         =>  p_pen_attribute6
3906   ,p_pen_attribute7         =>  p_pen_attribute7
3907   ,p_pen_attribute8         =>  p_pen_attribute8
3908   ,p_pen_attribute9         =>  p_pen_attribute9
3909   ,p_pen_attribute10        =>  p_pen_attribute10
3910   ,p_pen_attribute11        =>  p_pen_attribute11
3911   ,p_pen_attribute12        =>  p_pen_attribute12
3912   ,p_pen_attribute13        =>  p_pen_attribute13
3913   ,p_pen_attribute14        =>  p_pen_attribute14
3914   ,p_pen_attribute15        =>  p_pen_attribute15
3915   ,p_pen_attribute16        =>  p_pen_attribute16
3916   ,p_pen_attribute17        =>  p_pen_attribute17
3917   ,p_pen_attribute18        =>  p_pen_attribute18
3918   ,p_pen_attribute19        =>  p_pen_attribute19
3919   ,p_pen_attribute20        =>  p_pen_attribute20
3920   ,p_pen_attribute21        =>  p_pen_attribute21
3921   ,p_pen_attribute22        =>  p_pen_attribute22
3922   ,p_pen_attribute23        =>  p_pen_attribute23
3923   ,p_pen_attribute24        =>  p_pen_attribute24
3924   ,p_pen_attribute25        =>  p_pen_attribute25
3925   ,p_pen_attribute26        =>  p_pen_attribute26
3926   ,p_pen_attribute27        =>  p_pen_attribute27
3927   ,p_pen_attribute28        =>  p_pen_attribute28
3928   ,p_pen_attribute29        =>  p_pen_attribute29
3929   ,p_pen_attribute30        =>  p_pen_attribute30
3930   ,p_dpnt_actn_warning      =>  p_dpnt_actn_warning
3931   ,p_bnf_actn_warning       =>  p_bnf_actn_warning
3932   ,p_ctfn_actn_warning      =>  p_ctfn_actn_warning);
3933 
3934 
3935 END election_information;
3936 -- ----------------------------------------------------------------------------
3937 -- |--------------------------< decd_attribute >-------------------------|
3938 -- ----------------------------------------------------------------------------
3939 -- This function is used to assign null value to attribute columns
3940 -- if it contains the value $Sys_Def$
3941 -- created for bug# 2714383
3942 function decd_attribute(l_attribute in varchar2) return varchar2 is
3943      begin
3944      if l_attribute = hr_api.g_varchar2 then
3945      	return null;
3946      else
3947      	return l_attribute;
3948      end if;
3949 end decd_attribute;
3950 
3951 -- ----------------------------------------------------------------------------
3952 -- |--------------------------< determine_erlst_deenrt_dt >-------------------------|
3953 -- ----------------------------------------------------------------------------
3954 
3955 
3956 procedure determine_erlst_deenrt_date(p_oipl_id            in   number,
3957                                  p_pl_id                 in   number  ,
3958                                  p_pl_typ_id             in   number  ,
3959                                  p_ptip_id               in   number  ,
3960                                  p_pgm_id                in   number  ,
3961                                  p_ler_id                in   number   ,
3962                                  p_effective_date        in   date  ,
3963                                  p_business_group_id     in   number    ,
3964                                  p_orgnl_enrt_dt         in   date   ,
3965                                  p_person_id             in   number   ,
3966                                  p_lf_evt_ocrd_dt        in   date   ,
3967                                  p_enrt_cvg_strt_dt      in   date  ,
3968                                  p_return_date           in out nocopy date   )
3969 
3970 is
3971 
3972 
3973     CURSOR c_pl_popl_yr_period_current IS
3974       SELECT   yp.end_date,
3975                pyp.ordr_num
3976       FROM     ben_popl_yr_perd pyp, ben_yr_perd yp
3977       WHERE    pyp.pl_id = p_pl_id
3978       AND      pyp.yr_perd_id = yp.yr_perd_id
3979       AND      pyp.business_group_id = p_business_group_id
3980       AND      p_lf_evt_ocrd_dt BETWEEN yp.start_date AND yp.end_date
3981       AND      yp.business_group_id = p_business_group_id;
3982 
3983 
3984     Cursor c_oipl is
3985        select opt_id
3986        from ben_oipl_f
3987        where oipl_id = p_oipl_id
3988         and  business_group_id = p_business_group_id
3989         and   p_effective_date between EFFECTIVE_START_DATE
3990         AND  EFFECTIVE_END_DATE;
3991 
3992     cursor c_asg is
3993     select asg.assignment_id ,
3994            asg.organization_id
3995     from   per_all_assignments_f asg
3996     where  asg.person_id    = p_person_id
3997     and    asg.assignment_type <> 'C'
3998     and    asg.primary_flag = 'Y'
3999     and    p_effective_date between
4000            asg.effective_start_date and asg.effective_end_date;
4001 
4002      CURSOR c_state IS
4003       SELECT   loc.region_2
4004       FROM     hr_locations_all loc, per_all_assignments_f asg
4005       WHERE    loc.location_id = asg.location_id
4006       AND      asg.person_id = p_person_id
4007       and      asg.assignment_type <> 'C'
4008       AND      asg.primary_flag = 'Y'
4009       AND      p_lf_evt_ocrd_dt BETWEEN asg.effective_start_date
4010                    AND asg.effective_end_date
4011       AND      asg.business_group_id = p_business_group_id;
4012     --
4013     l_state                    c_state%ROWTYPE;
4014 
4015 
4016      l_opt_id                       number(15) ;
4017      l_level                       varchar2(5) ;
4018      l_rqd_perd_enrt_nenrt_uom      VARCHAR2(30);
4019      l_rqd_perd_enrt_nenrt_val      NUMBER;
4020      l_rqd_perd_enrt_nenrt_rl       NUMBER;
4021      l_erlst_deenrt_calc_dt         date  ;
4022      l_jurisdiction_code            VARCHAR2(30);
4023      l_popl_yr_perd_ordr_num        NUMBER;
4024      l_yr_perd_end_date             DATE;
4025      l_rec_assignment_id            NUMBER;
4026      l_rec_organization_id          NUMBER;
4027 
4028 
4029 begin
4030 
4031   g_debug := hr_utility.debug_enabled;
4032   if p_oipl_id is not  null then
4033      open c_oipl ;
4034      fetch c_oipl  into l_opt_id ;
4035      close c_oipl ;
4036   end if ;
4037 
4038 -- 4031733 - Cursor c_state populates l_state variable which is no longer
4039 -- used in the package. Cursor can be commented
4040 /*
4041   OPEN c_state;
4042   FETCH c_state INTO l_state;
4043   CLOSE c_state;
4044 */
4045   --IF l_state.region_2 IS NOT NULL THEN
4046   --    l_jurisdiction_code :=
4047   --     pay_mag_utils.lookup_jurisdiction_code(p_state => l_state.region_2);
4048   --END IF;
4049 
4050   OPEN c_asg;
4051   FETCH c_asg INTO l_rec_assignment_id, l_rec_organization_id;
4052   close c_asg;
4053 
4054 
4055    OPEN c_pl_popl_yr_period_current;
4056     --
4057    FETCH c_pl_popl_yr_period_current INTO  l_yr_perd_end_date,
4058                                            l_popl_yr_perd_ordr_num;
4059    CLOSE c_pl_popl_yr_period_current;
4060 
4061 
4062   ben_enrolment_requirements.find_rqd_perd_enrt(
4063       p_oipl_id                 => p_oipl_id,
4064       p_opt_id                  => l_opt_id,
4065       p_pl_id                   => p_pl_id,
4066       p_ptip_id                 => p_ptip_id,
4067       p_effective_date          => p_effective_date,
4068       p_business_group_id       => p_business_group_id,
4069       p_rqd_perd_enrt_nenrt_uom => l_rqd_perd_enrt_nenrt_uom,
4070       p_rqd_perd_enrt_nenrt_val => l_rqd_perd_enrt_nenrt_val,
4071       p_rqd_perd_enrt_nenrt_rl  => l_rqd_perd_enrt_nenrt_rl,
4072       p_level                   => l_level);
4073 
4074 
4075      l_erlst_deenrt_calc_dt   :=   p_enrt_cvg_strt_dt ;
4076   If l_level is not null and l_level not in('OPT','OIPL') then
4077      l_erlst_deenrt_calc_dt := nvl(p_orgnl_enrt_dt,p_enrt_cvg_strt_dt );
4078   end if ;
4079 
4080   if g_debug then
4081     hr_utility.set_location('uom'||l_rqd_perd_enrt_nenrt_uom ,8086.1);
4082   end if;
4083   if g_debug then
4084     hr_utility.set_location('val'||l_rqd_perd_enrt_nenrt_val ,8086.1);
4085   end if;
4086   if g_debug then
4087     hr_utility.set_location('cvg_dt '||l_erlst_deenrt_calc_dt  ,8086.1);
4088   end if;
4089   if g_debug then
4090     hr_utility.set_location('date before calca'||p_return_date ,8086.1);
4091   end if;
4092   if (l_rqd_perd_enrt_nenrt_val is  not null and l_rqd_perd_enrt_nenrt_uom is not null )
4093      or l_rqd_perd_enrt_nenrt_rl is not null then
4094        p_return_date :=
4095        ben_enrolment_requirements.determine_erlst_deenrt_dt(
4096          l_erlst_deenrt_calc_dt,
4097          l_rqd_perd_enrt_nenrt_val,
4098          l_rqd_perd_enrt_nenrt_uom,
4099          l_rqd_perd_enrt_nenrt_rl,
4100          p_oipl_id,
4101          p_pl_id,
4102          p_pl_typ_id,
4103          l_opt_id,
4104          p_pgm_id,
4105          p_ler_id,
4106          l_popl_yr_perd_ordr_num,
4107          l_yr_perd_end_date,
4108          p_effective_date,
4109          p_lf_evt_ocrd_dt,
4110          p_person_id,
4111          p_business_group_id,
4112          l_rec_assignment_id,
4113          l_rec_organization_id,
4114          l_jurisdiction_code);
4115   end if ;
4116   if g_debug then
4117     hr_utility.set_location('date after  calca'||p_return_date ,8086.1);
4118   end if;
4119 
4120 END determine_erlst_deenrt_date ;
4121 
4122 
4123 
4124 
4125 
4126 
4127 -- ----------------------------------------------------------------------------
4128 -- |--------------------------< election_information >-------------------------|
4129 -- ----------------------------------------------------------------------------
4130 -- OVERLOADED, SEE ABOVE.
4131 -- If new flags are need for the rco flow and not needed => forms, add them to
4132 -- this procedure.
4133 --
4134 procedure election_information
4135   (p_validate               in boolean default FALSE
4136   ,p_elig_per_elctbl_chc_id in number
4137   ,p_prtt_enrt_rslt_id      in out nocopy number
4138   ,p_effective_date         in date
4139   ,p_enrt_mthd_cd           in varchar2
4140   ,p_enrt_bnft_id           in number
4141   ,p_bnft_val               in number default null
4142   ,p_enrt_cvg_strt_dt       in  date  default null
4143   ,p_enrt_cvg_thru_dt       in  date  default null
4144   ,p_enrt_rt_id1            in number default null
4145   ,p_prtt_rt_val_id1        in out nocopy number
4146   ,p_rt_val1                in number default null
4147   ,p_ann_rt_val1            in number default null
4148   ,p_rt_strt_dt1            in date   default null
4149   ,p_rt_end_dt1             in date   default null
4150   ,p_enrt_rt_id2            in number default null
4151   ,p_prtt_rt_val_id2        in out nocopy number
4152   ,p_rt_val2                in number default null
4153   ,p_ann_rt_val2            in number default null
4154   ,p_rt_strt_dt2            in date   default null
4155   ,p_rt_end_dt2             in date   default null
4156   ,p_enrt_rt_id3            in number default null
4157   ,p_prtt_rt_val_id3        in out nocopy number
4158   ,p_rt_val3                in number default null
4159   ,p_ann_rt_val3            in number default null
4160   ,p_rt_strt_dt3            in date   default null
4161   ,p_rt_end_dt3             in date   default null
4162   ,p_enrt_rt_id4            in number default null
4163   ,p_prtt_rt_val_id4        in out nocopy number
4164   ,p_rt_val4                in number default null
4165   ,p_ann_rt_val4            in number default null
4166   ,p_rt_strt_dt4            in date   default null
4167   ,p_rt_end_dt4             in date   default null
4168   ,p_enrt_rt_id5            in number default null
4169   ,p_prtt_rt_val_id5        in out nocopy number
4170   ,p_rt_val5                in number default null
4171   ,p_ann_rt_val5            in number default null
4172   ,p_rt_strt_dt5            in date   default null
4173   ,p_rt_end_dt5             in date   default null
4174   ,p_enrt_rt_id6            in number default null
4175   ,p_prtt_rt_val_id6        in out nocopy number
4176   ,p_rt_val6                in number default null
4177   ,p_ann_rt_val6            in number default null
4178   ,p_rt_strt_dt6            in date   default null
4179   ,p_rt_end_dt6             in date   default null
4180   ,p_enrt_rt_id7            in number default null
4181   ,p_prtt_rt_val_id7        in out nocopy number
4182   ,p_rt_val7                in number default null
4183   ,p_ann_rt_val7            in number default null
4184   ,p_rt_strt_dt7            in date   default null
4185   ,p_rt_end_dt7             in date   default null
4186   ,p_enrt_rt_id8            in number default null
4187   ,p_prtt_rt_val_id8        in out nocopy number
4188   ,p_rt_val8                in number default null
4189   ,p_ann_rt_val8            in number default null
4190   ,p_rt_strt_dt8            in date   default null
4191   ,p_rt_end_dt8             in date   default null
4192   ,p_enrt_rt_id9            in number default null
4193   ,p_prtt_rt_val_id9        in out nocopy number
4194   ,p_rt_val9                in number default null
4195   ,p_ann_rt_val9            in number default null
4196   ,p_rt_strt_dt9            in date   default null
4197   ,p_rt_end_dt9             in date   default null
4198   ,p_enrt_rt_id10           in number default null
4199   ,p_prtt_rt_val_id10       in out nocopy number
4200   ,p_rt_val10               in number default null
4201   ,p_ann_rt_val10           in number default null
4202   ,p_rt_strt_dt10           in date   default null
4203   ,p_rt_end_dt10            in date   default null
4204   ,p_datetrack_mode         in varchar2
4205   ,p_suspend_flag           in out nocopy varchar2
4206   ,p_called_from_sspnd      in varchar2          -- flag not other spec
4207   ,p_effective_start_date   out nocopy date
4208   ,p_effective_end_date     out nocopy date
4209   ,p_object_version_number  in out nocopy number
4210   ,p_prtt_enrt_interim_id   out nocopy number
4211   ,p_business_group_id      in  number
4212   ,p_pen_attribute_category in  varchar2  default hr_api.g_varchar2
4213   ,p_pen_attribute1         in  varchar2  default hr_api.g_varchar2
4214   ,p_pen_attribute2         in  varchar2  default hr_api.g_varchar2
4215   ,p_pen_attribute3         in  varchar2  default hr_api.g_varchar2
4216   ,p_pen_attribute4         in  varchar2  default hr_api.g_varchar2
4217   ,p_pen_attribute5         in  varchar2  default hr_api.g_varchar2
4218   ,p_pen_attribute6         in  varchar2  default hr_api.g_varchar2
4219   ,p_pen_attribute7         in  varchar2  default hr_api.g_varchar2
4220   ,p_pen_attribute8         in  varchar2  default hr_api.g_varchar2
4221   ,p_pen_attribute9         in  varchar2  default hr_api.g_varchar2
4222   ,p_pen_attribute10        in  varchar2  default hr_api.g_varchar2
4223   ,p_pen_attribute11        in  varchar2  default hr_api.g_varchar2
4224   ,p_pen_attribute12        in  varchar2  default hr_api.g_varchar2
4225   ,p_pen_attribute13        in  varchar2  default hr_api.g_varchar2
4226   ,p_pen_attribute14        in  varchar2  default hr_api.g_varchar2
4227   ,p_pen_attribute15        in  varchar2  default hr_api.g_varchar2
4228   ,p_pen_attribute16        in  varchar2  default hr_api.g_varchar2
4229   ,p_pen_attribute17        in  varchar2  default hr_api.g_varchar2
4230   ,p_pen_attribute18        in  varchar2  default hr_api.g_varchar2
4231   ,p_pen_attribute19        in  varchar2  default hr_api.g_varchar2
4232   ,p_pen_attribute20        in  varchar2  default hr_api.g_varchar2
4233   ,p_pen_attribute21        in  varchar2  default hr_api.g_varchar2
4234   ,p_pen_attribute22        in  varchar2  default hr_api.g_varchar2
4235   ,p_pen_attribute23        in  varchar2  default hr_api.g_varchar2
4236   ,p_pen_attribute24        in  varchar2  default hr_api.g_varchar2
4237   ,p_pen_attribute25        in  varchar2  default hr_api.g_varchar2
4238   ,p_pen_attribute26        in  varchar2  default hr_api.g_varchar2
4239   ,p_pen_attribute27        in  varchar2  default hr_api.g_varchar2
4240   ,p_pen_attribute28        in  varchar2  default hr_api.g_varchar2
4241   ,p_pen_attribute29        in  varchar2  default hr_api.g_varchar2
4242   ,p_pen_attribute30        in  varchar2  default hr_api.g_varchar2
4243   ,p_dpnt_actn_warning      out nocopy boolean
4244   ,p_bnf_actn_warning       out nocopy boolean
4245   ,p_ctfn_actn_warning      out nocopy boolean)
4246 is
4247   -- Local variable Declarations
4248 
4249   l_prtt_enrt_rslt_id                 number;
4250   l_old_bnft_val                      number;
4251   l_old_enrt_cvg_strt_dt              date;
4252   l_old_enrt_cvg_thru_dt              date;
4253   l_old_erlst_deenrt_dt               date ;
4254   l_old_pl_id                         number;
4255   l_old_oipl_id                       number;
4256   l_old_per_in_ler_id                 number;
4257   l_old_ovn                           number;
4258 --  l_prtt_is_cvrd_flag               varchar2(30);
4259   l_orgnl_enrt_dt                     date;
4260   l_old_orgnl_enrt_dt                 date;
4261   l_enrt_mthd_cd                      varchar2(30);
4262   l_enrt_ovridn_flag                  varchar2(30);
4263   l_enrt_ovrid_rsn_cd                 varchar2(30);
4264   l_enrt_ovrid_thru_dt                date;
4265   l_enrt_cvg_thru_dt                  date;
4266   l_enrt_cvg_strt_dt                  date;
4267 
4268 l_global_epe_rec ben_global_enrt.g_global_epe_rec_type;
4269 l_global_pel_rec ben_global_enrt.g_global_pel_rec_type;
4270 l_global_pil_rec ben_global_enrt.g_global_pil_rec_type;
4271 l_global_enb_rec ben_global_enrt.g_global_enb_rec_type;
4272 l_global_pen_rec ben_prtt_enrt_rslt_f%rowtype;
4273 
4274   l_xenrt_cvg_strt_dt                 date;
4275   l_xenrt_cvg_strt_dt_cd              varchar2(30);
4276   l_xenrt_cvg_strt_dt_rl              number;
4277   l_xrt_strt_dt                       date;
4278   l_xrt_strt_dt_cd                    varchar2(30);
4279   l_xrt_strt_dt_rl                    number;
4280   l_xenrt_cvg_end_dt                  date;
4281   l_xenrt_cvg_end_dt_cd               varchar2(30);
4282   l_xenrt_cvg_end_dt_rl               number;
4283   l_xrt_end_dt                        date;
4284   l_xrt_end_dt_cd                     varchar2(30);
4285   l_xrt_end_dt_rl                     number;
4286   l_prtt_enrt_interim_id              number;
4287   l_dpnt_actn_warning                 boolean := FALSE;
4288   l_bnf_actn_warning                  boolean := FALSE;
4289   l_ctfn_actn_warning                 boolean := FALSE;
4290   l_action                            varchar2(30);
4291   --
4292   l_pl_rec         ben_cobj_cache.g_pl_inst_row;
4293   l_oipl_rec       ben_cobj_cache.g_oipl_inst_row;
4294   l_plip_rec       ben_cobj_cache.g_plip_inst_row;
4295   l_ptip_rec       ben_cobj_cache.g_ptip_inst_row;
4296   --
4297   l_bnft_amt_changed                  boolean := FALSE;
4298   l_use_new_result                    boolean := FALSE;
4299   l_crntly_enrd_rslt_exists           boolean := false;
4300   l_elect_cvg_strt_dt                 date    ;
4301   l_datetrack_mode                    varchar2(30);
4302   --
4303   l_proc                              varchar2(72) :=
4304                                          g_package||'election_information';
4305   l_object_version_number             number;
4306   l_dummy_number                      number;
4307   --
4308   -- current result info
4309   -- ben_sspndd_enrollment.g_use_new_result
4310   --
4311   cursor c_current_result_info(v_prtt_enrt_rslt_id number) is
4312     select pen.enrt_cvg_strt_dt,
4313            pen.enrt_cvg_thru_dt,
4314            pen.bnft_amt,
4315            pen.pl_id,
4316            pen.oipl_id,
4317            pen.orgnl_enrt_dt,
4318            pen.per_in_ler_id,
4319            pen.object_version_number,
4320            pen.erlst_deenrt_dt ,
4321            pen.enrt_ovrid_thru_dt,
4322            pen.enrt_ovrid_rsn_cd,
4323            pen.enrt_ovridn_flag,
4324            pen.sspndd_flag
4325     from   ben_prtt_enrt_rslt_f pen
4326     where  pen.prtt_enrt_rslt_id=v_prtt_enrt_rslt_id and
4327            pen.business_group_id=p_business_group_id and
4328            pen.prtt_enrt_rslt_stat_cd is null        and
4329            p_effective_date between
4330              pen.effective_start_date and pen.effective_end_date
4331     ;
4332   --
4333   l_crntly_enrd_rslt_rec  c_current_result_info%rowtype;
4334   -- Bug 2627078 fixes
4335   cursor c_delink_interim(v_prtt_enrt_rslt_id number, v_sspnd_result_id number ) is
4336     select pen.prtt_enrt_rslt_id ,
4337            pen.object_version_number
4338     from   ben_prtt_enrt_rslt_f pen
4339     where  pen.rplcs_sspndd_rslt_id = v_prtt_enrt_rslt_id and
4340            pen.prtt_enrt_rslt_id = v_sspnd_result_id and
4341            p_effective_date between
4342              pen.effective_start_date and pen.effective_end_date
4343     ;
4344   --
4345   l_delink_interim    c_delink_interim%rowtype ;
4346   --
4347   cursor oipl_ordr_num_c (p_oipl_id number) is
4348      select ordr_num
4349        from ben_oipl_f
4350       where oipl_id = p_oipl_id and
4351             business_group_id   = p_business_group_id and
4352             p_effective_date between
4353                      effective_start_date and effective_end_date
4354     ;
4355     cursor c_regn_125_or_129 is
4356       select   'Y'
4357       from     ben_pl_regn_f prg,
4358                ben_regn_f regn
4359       where    prg.pl_id=l_global_epe_rec.pl_id
4360            and p_effective_date between
4361                prg.effective_start_date and prg.effective_end_date
4362            and prg.business_group_id=p_business_group_id
4363            and regn.regn_id=prg.regn_id
4364            and regn.name in ('IRC Section 125','IRC Section 129')
4365            and p_effective_date between
4366                regn.effective_start_date and regn.effective_end_date
4367            and regn.business_group_id=p_business_group_id
4368       ;
4369     l_regn_125_or_129_flag         varchar2(30);
4370     l_ret number;
4371     -- Bug 1913254
4372     -- Following cursor is for getting the annual val for
4373     -- cvg_mlt_cd of SAAEAR and enter value at enrollment is not checked.
4374 /*
4375     cursor c_ert is
4376       select  ann_val
4377       from    ben_enrt_rt ert
4378       where   ert.enrt_bnft_id = p_enrt_bnft_id
4379          and  ENTR_VAL_AT_ENRT_FLAG = 'N'
4380          and  ann_val is not null ;
4381     l_ann_enrt_rt number ;
4382 */
4383     -- Bug 2212194 to fix the issue of having multiple rates associated
4384     -- with the comp object.
4385     --
4386     -- changed, bug: 5584813
4387     cursor c_ert is
4388       select  ert.ann_val,ert.ENTR_VAL_AT_ENRT_FLAG,
4389 	      abr.acty_base_rt_id,
4390 	      abr.rate_periodization_rl,
4391 	      enb.elig_per_elctbl_chc_id,
4392 	      ert.entr_ann_val_flag
4393       from    ben_enrt_rt ert,
4394               ben_acty_base_rt_f abr,
4395 	      ben_enrt_bnft enb
4396       where  enb.enrt_bnft_id = p_enrt_bnft_id
4397          and ert.enrt_bnft_id = enb.enrt_bnft_id
4398          and nvl(abr.PARNT_CHLD_CD,'PARNT') = 'PARNT'
4399          and abr.acty_base_rt_id = ert.acty_base_rt_id
4400          and p_effective_date between abr.effective_start_date
4401              and abr.effective_end_date
4402          and ert.acty_typ_cd not like 'PRD%'
4403          and ert.acty_typ_cd <> 'PRFRFS' ;
4404          -- and  ENTR_VAL_AT_ENRT_FLAG = 'Y'
4405          -- and  ann_val is not null ;
4406     l_ert c_ert%rowtype;
4407     l_dummy_rt_val NUMBER;
4408     --
4409     --Bug 2172036 populating the assignment_id in the pen
4410     cursor c_epe is
4411       select epe.assignment_id ,
4412              epe.fonm_cvg_strt_dt
4413       from ben_elig_per_elctbl_chc epe
4414       where epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id ;
4415     --
4416     cursor c_enb_pen is
4417       select enb.prtt_enrt_rslt_id
4418       from ben_enrt_bnft enb,
4419            ben_prtt_enrt_rslt_f pen
4420       where enb.enrt_bnft_id = p_enrt_bnft_id
4421         and enb.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
4422         and pen.effective_end_date = hr_api.g_eot
4423         and pen.enrt_cvg_thru_dt = hr_api.g_eot
4424         and pen.prtt_enrt_rslt_stat_cd is NULL
4425         ;
4426     --
4427     -- Bug 2600087 fixes to open future dated coverage
4428     cursor c_enrt_rslt is
4429       select pen.*
4430       from   ben_prtt_enrt_rslt_f pen
4431       where  pen.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
4432       and    pen.prtt_enrt_rslt_stat_cd is null
4433       and    pen.effective_end_date = (select pen2.effective_start_date - 1
4434       from   ben_prtt_enrt_rslt_f pen2
4435       where    pen2.enrt_cvg_thru_dt <> hr_api.g_eot
4436       and    pen2.effective_end_date = hr_api.g_eot
4437       and    pen2.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
4438       and    pen2.prtt_enrt_rslt_stat_cd is null);
4439    --
4440    --bug#5032364
4441     cursor c_enrt_rslt2 is
4442       select pen.*
4443       from   ben_prtt_enrt_rslt_f pen
4444       where  pen.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
4445       and    pen.prtt_enrt_rslt_stat_cd is null
4446       and    pen.effective_end_date = hr_api.g_eot;
4447    --
4448     l_enrt_rslt2   c_enrt_rslt2%rowtype;
4449    --
4450    -- 5612091 - Added OR condition with p_elig_per_elctbl_chc_id
4451     cursor c_enrt_rt (p_acty_base_rt_id number) is
4452       select enrt_rt_id
4453       from ben_enrt_rt ecr
4454       where (ecr.enrt_bnft_id = p_enrt_bnft_id
4455        or ecr.ELIG_PER_ELCTBL_CHC_ID = p_elig_per_elctbl_chc_id)
4456       and ecr.acty_base_rt_id = p_acty_base_rt_id;
4457    --
4458     cursor c_prtt_rt_val_id is
4459       select prv.prtt_rt_val_id,
4460              prv.acty_base_rt_id
4461       from ben_prtt_rt_val prv
4462       where prv.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
4463         and prv.prtt_rt_val_stat_cd is null
4464         order by prv.rt_strt_dt asc;
4465     --
4466     -- Bug 5766477.
4467     --
4468     cursor c_get_dpnt(p_effective_date in date) is
4469       select pdp.*
4470       from   ben_elig_cvrd_dpnt_f pdp
4471       where  pdp.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
4472       and    pdp.cvg_thru_dt is not null
4473       and    p_effective_date
4474              between pdp.effective_start_date
4475              and pdp.effective_end_date;
4476     --
4477     cursor c_pen_exists(v_prtt_enrt_rslt_id number) is
4478       select 'x'
4479     from  ben_prtt_enrt_rslt_f pen
4480     where pen.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
4481      and  pen.business_group_id = p_business_group_id
4482      and  p_effective_date between pen.effective_start_date
4483                   and pen.effective_end_date ;
4484 
4485     cursor c_wv_opt (p_oipl_id number ) is
4486        select opt.invk_wv_opt_flag
4487          from ben_opt_f opt , ben_oipl_f oipl
4488         where oipl.oipl_id = p_oipl_id
4489          and  oipl.opt_id = opt.opt_id
4490          and  oipl.business_group_id   = p_business_group_id
4491          and  p_effective_date between  oipl.effective_start_date and oipl.effective_end_date
4492          and  p_effective_date between  opt.effective_start_date and opt.effective_end_date ;
4493 
4494     -- to check the future coverage deleted
4495     l_wv_flag      varchar2(30);
4496     l_dummy_char   varchar2(30) ;
4497     l_enrt_rslt    c_enrt_rslt%rowtype;
4498     l_enrt_rt_id    number;
4499     l_prtt_rt_val_id  number;
4500     l_assignment_id number(15);
4501     l_start_new_result     boolean := false;
4502     l_object_version_number2 number := p_object_version_number;
4503     l_effective_start_date  date;
4504     l_effective_end_date    date;
4505     l_acty_base_rt_id2   number;
4506     l_dlink_effective_start_date  date;
4507     l_dlink_effective_end_date    date;
4508     l_old_enrt_ovrid_thru_dt      date;
4509     l_old_enrt_ovrid_rsn_cd       varchar2(30);
4510     l_old_enrt_ovridn_flag        varchar2(30) := 'N' ;
4511     l_old_sspndd_flag             varchar2(30);
4512     l_new_cvg_strt_dt             date;
4513     l_fonm_cvg_strt_dt            date ;
4514     l_fonm_flag                   varchar2(30) := 'N' ;
4515   --
4516     l_interim_count number;--3733745
4517     --
4518     l_enb_prtt_enrt_rslt_id number ;
4519     --
4520     -- Bug 5600697
4521     --
4522     cursor c_is_pen_valid(cv_prtt_enrt_rslt_id number) is
4523       select pen.prtt_enrt_Rslt_stat_Cd
4524       from   ben_prtt_enrt_rslt_f pen
4525       where  pen.prtt_enrt_rslt_id = cv_prtt_enrt_rslt_id and
4526              pen.business_group_id= p_business_group_id and
4527              p_effective_date between pen.effective_start_date and pen.effective_end_date;
4528     --
4529     l_pen_stat_cd varchar2(30);
4530     --
4531     cursor c_pen_curr(v_prtt_enrt_rslt_id number,
4532                          p_effective_date date) is
4533       select pen.*
4534       from   ben_prtt_enrt_rslt_f pen
4535       where  pen.prtt_enrt_rslt_id = v_prtt_enrt_rslt_id
4536       and    p_effective_date between
4537              pen.effective_start_date and pen.effective_end_date
4538       and    pen.effective_end_date <> hr_api.g_eot
4539       and    pen.prtt_enrt_rslt_stat_cd is null
4540       and    pen.business_group_id = p_business_group_id
4541       order by pen.effective_start_date desc ;
4542     --
4543     l_pen_curr    c_pen_curr%rowtype;
4544     l_pen_curr_interim c_pen_curr%rowtype;
4545     --
4546     cursor c_prv(p_prtt_enrt_rslt_id number, p_per_in_ler_id number) is
4547     select prv.*
4548       from ben_prtt_rt_val prv
4549      where prv.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
4550        and prv.per_in_ler_id = p_per_in_ler_id
4551        and prv.prtt_rt_val_stat_cd is NULL ;
4552     --
4553     cursor c_ecr(p_prtt_rt_val_id number) is
4554     select ecr.rt_strt_dt,
4555            ecr.rt_strt_dt_cd,
4556            ecr.rt_strt_dt_rl,
4557            nvl(ecr.elig_per_elctbl_chc_id,enb.elig_per_elctbl_chc_id) elig_per_elctbl_chc_id
4558      from ben_enrt_rt ecr,
4559           ben_enrt_bnft enb
4560     where ecr.prtt_rt_val_id = p_prtt_rt_val_id
4561       and ecr.enrt_bnft_id = enb.enrt_bnft_id (+) ;
4562     --
4563     l_ecr   c_ecr%rowtype;
4564     -- bug 5621049
4565      cursor c_validate_epe_pen(cv_elig_per_elctblc_chc_id number,cv_prtt_enrt_rslt_id number ) is
4566      select null
4567      from ben_elig_per_elctbl_chc
4568      where elig_per_elctbl_chc_id = cv_elig_per_elctblc_chc_id
4569      and prtt_enrt_rslt_id = cv_prtt_enrt_rslt_id;
4570 
4571      -- Added for bug 7206471
4572   --
4573    cursor c_get_prior_per_in_ler is
4574    select 'Y'
4575    from   ben_elig_per_elctbl_chc epe, ben_per_in_ler pil,
4576           ben_per_in_ler pil2
4577    where  epe.elig_per_elctbl_chc_id=p_elig_per_elctbl_chc_id
4578    and    pil.per_in_ler_id <> epe.per_in_ler_id
4579    and    trunc(pil.lf_evt_ocrd_dt, 'MM') = trunc(pil2.lf_evt_ocrd_dt, 'MM')
4580    and    pil2.per_in_ler_id = epe.per_in_ler_id
4581    and    pil.business_group_id = pil2.business_group_id
4582    and    pil.business_group_id = p_business_group_id
4583    and    pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT');
4584    --
4585    l_exists varchar2(2);
4586    --
4587   cursor c_get_pgm is
4588   select distinct epe.pgm_id
4589   from ben_elig_per_elctbl_chc epe
4590   where epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id;
4591   --
4592   cursor c_get_pgm_extra_info_cvg(p_pgm_id number) is
4593   select pgi_information1
4594   from ben_pgm_extra_info
4595   where information_type = 'ADJ_CVG_PREV_LF_EVT'
4596   and pgm_id = p_pgm_id;
4597   --
4598   l_cvg_adjust varchar2(2);
4599   --
4600   cursor c_get_elctbl_chc_for_cvg is
4601    select min(epe.enrt_cvg_strt_dt) enrt_cvg_strt_dt
4602          ,epe.ptip_id
4603    from ben_elig_per_elctbl_chc  epe
4604    where epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
4605    and   epe.business_group_id = p_business_group_id
4606    group by epe.ptip_id;
4607    --
4608    cursor c_get_enrt_rslts_for_pen(p_cvg_end_dt date
4609                          ,p_ptip_id   number
4610                           ) is
4611    select pen.*, epe.per_in_ler_id pil_id
4612    from ben_prtt_enrt_rslt_f pen
4613        ,ben_ptip_f ptip
4614        ,ben_per_in_ler pil
4615        ,ben_elig_per_elctbl_chc epe
4616    where pen.effective_end_date = hr_api.g_eot -- '31-dec-4712'
4617    and   pen.enrt_cvg_thru_dt <> hr_api.g_eot -- '31-dec-4712'
4618    and   pen.prtt_enrt_rslt_stat_cd is null
4619    and   pen.person_id =  pil.person_id -- 318321
4620    and   pen.business_group_id = p_business_group_id -- 81545
4621    and   pen.ptip_id = p_ptip_id -- 54444
4622    and   pen.enrt_cvg_thru_dt >=  p_cvg_end_dt -- '20-jan-2008'
4623    and   pen.ptip_id = ptip.ptip_id
4624    and   pil.per_in_ler_id = epe.per_in_ler_id
4625    and   epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
4626    and   p_effective_date between ptip.effective_start_date
4627                   and ptip.effective_end_date;
4628    --
4629    cursor c_prtt_enrt_rslt_adj (p_prtt_enrt_rslt_id number) is
4630    select null
4631    from  ben_le_clsn_n_rstr leclr, ben_elig_per_elctbl_chc epe
4632    where leclr.BKUP_TBL_TYP_CD = 'BEN_PRTT_ENRT_RSLT_F_ADJ'
4633    AND   leclr.BKUP_TBL_ID = p_prtt_enrt_rslt_id
4634    AND   leclr.PER_IN_LER_ID  = epe.per_in_ler_id
4635    AND   epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id;
4636    --
4637    -- end 7206471
4638   --  ------------------------------------------------------------
4639 BEGIN
4640     g_debug := hr_utility.debug_enabled;
4641     if g_debug then
4642       hr_utility.set_location('Entering:'||l_proc, 5);
4643     end if;
4644     if g_debug then
4645       hr_utility.set_location(' chc:'|| to_char(p_elig_per_elctbl_chc_id)||' rslt:'|| to_char(p_prtt_enrt_rslt_id), 5);
4646     end if;
4647     if g_debug then
4648       hr_utility.set_location('p_enrt_rt_id1'||p_enrt_rt_id1,1999);
4649     end if;
4650 
4651   --
4652   -- Work out if we are being called from a concurrent program
4653   -- otherwise we need to initialize the environment
4654   --
4655   if fnd_global.conc_request_id = -1 then
4656     --
4657     ben_env_object.init(p_business_group_id  => p_business_group_id,
4658                         p_effective_date     => p_effective_date,
4659                         p_thread_id          => 1,
4660                         p_chunk_size         => 1,
4661                         p_threads            => 1,
4662                         p_max_errors         => 1,
4663                         p_benefit_action_id  => null);
4664     --
4665   end if;
4666   --
4667   --
4668   -- Issue a savepoint depending on where we are called from.  We
4669   -- must do this because election_information calls create_enrollment
4670   -- which calls Determine_other_action_items which calls Suspend_enrollment
4671   -- Which might create an interim result by calling election_information.
4672   -- When it does, it would reset this save point.
4673   --
4674   -- This flag is also passed to create_enrollment
4675   --
4676   if p_called_from_sspnd = 'N' then
4677      savepoint election_information_savepoint;
4678   else
4679      savepoint election_information_sspnd;
4680   end if;
4681 
4682   --
4683   -- For the case where this is creating an interim enrollment
4684   -- and the interim choice is the same as the original then
4685   -- we should create a new result.
4686   --
4687   if p_called_from_sspnd = 'Y' then
4688     if g_elig_per_elctbl_chc_id=p_elig_per_elctbl_chc_id then
4689       if g_debug then
4690         hr_utility.set_location(' l_use_new_result:=true ',1223);
4691       end if;
4692       l_use_new_result:=true;
4693     end if;
4694   end if;
4695   --
4696   -- set globals to be used by bensuenr, suspend enrollment
4697   --
4698   g_enrt_bnft_id:=p_enrt_bnft_id;
4699   g_bnft_val:=p_bnft_val;
4700   g_elig_per_elctbl_chc_id:=p_elig_per_elctbl_chc_id;
4701   --
4702   -- begin by getting the choice, bnft, per in ler and pil popl information
4703   --
4704   ben_global_enrt.get_epe  -- choice
4705        (p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id
4706        ,p_global_epe_rec         => l_global_epe_rec);
4707 
4708   ben_global_enrt.get_pel  -- pil popl
4709        (p_pil_elctbl_chc_popl_id => l_global_epe_rec.pil_elctbl_chc_popl_id
4710        ,p_global_pel_rec         => l_global_pel_rec);
4711 
4712   ben_global_enrt.get_pil  -- per in ler
4713        (p_per_in_ler_id          => l_global_epe_rec.per_in_ler_id
4714        ,p_global_pil_rec         => l_global_pil_rec);
4715 
4716 --Bug#5099296
4717   if l_global_epe_rec.prtt_enrt_rslt_id is not null then
4718     ben_global_enrt.get_pen
4719        (p_prtt_enrt_rslt_id      => l_global_epe_rec.prtt_enrt_rslt_id
4720        ,p_effective_date         => p_effective_date
4721        ,p_global_pen_rec         => l_global_pen_rec);
4722   end if;
4723 --Bug#5099296
4724 
4725   if p_enrt_bnft_id is not null then
4726      ben_global_enrt.get_enb   -- enrt bnft
4727        (p_enrt_bnft_id           => p_enrt_bnft_id
4728        ,p_global_enb_rec         => l_global_enb_rec);
4729   else
4730      ben_global_enrt.clear_enb
4731        (p_global_enb_rec         => l_global_enb_rec);
4732   end if;
4733 
4734   if l_global_epe_rec.oipl_id is not null and p_enrt_bnft_id is null then
4735         open oipl_ordr_num_c(p_oipl_id => l_global_epe_rec.oipl_id);
4736         fetch oipl_ordr_num_c into l_global_enb_rec.ordr_num;
4737         close oipl_ordr_num_c;
4738   end if;
4739 
4740   if g_debug then
4741     hr_utility.set_location(l_proc, 15);
4742   end if;
4743 
4744 
4745   --- determine FONM for election information  # 4510798
4746 
4747   open c_epe ;
4748   fetch c_epe into l_assignment_id ,
4749                     l_fonm_cvg_strt_dt;
4750   close c_epe ;
4751 
4752   if l_fonm_cvg_strt_dt is not null then
4753      l_fonm_flag :=  'Y'  ;
4754      ben_manage_life_events.fonm := 'Y';
4755      ben_manage_life_events.g_fonm_cvg_strt_dt := l_fonm_cvg_strt_dt;
4756   else
4757       l_fonm_flag :=  'N'  ;
4758       ben_manage_life_events.fonm := 'N';
4759       ben_manage_life_events.g_fonm_cvg_strt_dt := null ;
4760   end if ;
4761   hr_utility.set_location (' FONM ' ||  ben_manage_life_events.fonm , 99 ) ;
4762   hr_utility.set_location (' FONM CVG  ' ||  ben_manage_life_events.g_fonm_cvg_strt_dt , 99 ) ;
4763 
4764   --
4765   -- If form code is too lazy to pass in the result id
4766   -- then get it from the choice.  Note will be null if
4767   -- the choice has not previously been enrolled in.
4768   --
4769   -- Assign only if result id is null - Bug#5369
4770   -- Bug 2547005 and 2543071 This needs to checked first. In Enter value at enrollment case
4771   -- with benefit restriction we get the right penid here.
4772   -- We may have two benefit rows one having the penid and other not. If
4773   -- we are using the one without penid we can not use the penid from epe
4774   -- which is not right.
4775   --
4776   if g_debug then
4777     hr_utility.set_location('p_prtt_enrt_rslt_id '||p_prtt_enrt_rslt_id ,9999);
4778   end if;
4779   if g_debug then
4780     hr_utility.set_location('l_global_epe_rec.p_e_r_id '||l_global_epe_rec.prtt_enrt_rslt_id,9999);
4781   end if;
4782   if g_debug then
4783     hr_utility.set_location('p_enrt_bnft_id '||p_enrt_bnft_id,9999);
4784   end if;
4785   --
4786   if p_enrt_bnft_id is not null then
4787     open  c_enb_pen ;
4788     fetch c_enb_pen into l_enb_prtt_enrt_rslt_id;
4789     close c_enb_pen ;
4790   end if;
4791   --
4792   if p_enrt_bnft_id is not null and p_prtt_enrt_rslt_id is null then
4793     --
4794     p_prtt_enrt_rslt_id := l_enb_prtt_enrt_rslt_id ;
4795     --
4796   elsif l_global_epe_rec.prtt_enrt_rslt_id is not null and p_prtt_enrt_rslt_id is null then
4797     --
4798     -- Bug 5600697 - In cases like FONM, if we delete enrollment for a subsequent life event, then
4799     --               EPE would still hold the PEN_ID but with BCKDT status. So if we again decide
4800     --               to enrol then 91711 error would occur while querying cursor C_CURRENT_RESULT_INFO
4801     --               I believe we should set P_PRTT_ENRT_RSLT_ID only if PRTT_ENRT_RSLT_STAT_CD is NULL
4802     --
4803     open c_is_pen_valid(l_global_epe_rec.prtt_enrt_rslt_id);
4804       --
4805       fetch c_is_pen_valid into l_pen_stat_cd;
4806       --
4807       if c_is_pen_valid%found and l_pen_stat_cd is null
4808       then
4809         --
4810         p_prtt_enrt_rslt_id := l_global_epe_rec.prtt_enrt_rslt_id;
4811         --
4812       end if;
4813       --
4814     close c_is_pen_valid;
4815     --
4816     --
4817   end if;
4818   --
4819   if l_enb_prtt_enrt_rslt_id IS NOT NULL and l_global_epe_rec.prtt_enrt_rslt_id <> l_enb_prtt_enrt_rslt_id THEN
4820     --
4821     l_global_epe_rec.prtt_enrt_rslt_id := l_enb_prtt_enrt_rslt_id  ;
4822     --
4823   end if;
4824   --
4825   hr_utility.set_location('l_enb_prtt_enrt_rslt_id'||l_enb_prtt_enrt_rslt_id,222);
4826   hr_utility.set_location('l_global_epe_rec.prtt_enrt_rslt_id'||l_global_epe_rec.prtt_enrt_rslt_id,222);
4827   --
4828   l_prtt_enrt_rslt_id := l_global_epe_rec.prtt_enrt_rslt_id;
4829   --
4830   if g_debug then
4831     hr_utility.set_location(l_proc, 16);
4832   end if;
4833   --
4834   -- override the bnft_val if it's annualized and entered at enrt
4835   --
4836   -- Bug 1913254 Present logic works only for enter value at enrollment is
4837   -- checked for rate. Now added a new cursor to get the annual value for
4838   -- SAAEAR if the rate is not entered at enrollment.
4839   --
4840   --hr_utility. set_location(' cvg_mlt_cd Code '||l_global_enb_rec.cvg_mlt_cd , 17);
4841   --hr_utility. set_location(' p_ann_rt_val1 '||p_ann_rt_val1 ,18);
4842   --hr_utility. set_location(' p_bnft_val '||p_bnft_val ,19);
4843   --hr_utility. set_location(' p_enrt_rt_id1 '||p_enrt_rt_id1 ,19);
4844   --hr_utility. set_location(' p_enrt_bnft_id '||p_enrt_bnft_id , 20);
4845   --
4846   -- Bug 2212194 fixes
4847   --
4848   if l_global_enb_rec.cvg_mlt_cd='SAAEAR' then
4849     --
4850     open c_ert ;
4851     fetch c_ert into l_ert ; --l_ann_enrt_rt ;
4852     if c_ert%found then
4853       --
4854       if l_ert.ENTR_VAL_AT_ENRT_FLAG = 'Y' then
4855         --
4856 	-- changed for bug: 5584813
4857 	  if l_ert.entr_ann_val_flag = 'Y' then
4858 		l_global_enb_rec.val:= p_ann_rt_val1;
4859           else
4860 	        l_dummy_rt_val := p_rt_val1;
4861 		calc_rt_ann_rt_vals (
4862 		   p_rt_val                  => l_dummy_rt_val,
4863 		   p_ann_rt_val              => l_global_enb_rec.val,
4864 		   p_person_id               => l_global_pil_rec.person_id,
4865 		   p_effective_date          => p_effective_date,
4866 		   p_acty_base_rt_id         => l_ert.acty_base_rt_id,
4867 		   p_rate_periodization_rl   => l_ert.rate_periodization_rl,
4868 		   p_elig_per_elctbl_chc_id  => l_ert.elig_per_elctbl_chc_id,
4869 		   p_business_group_id       => p_business_group_id,
4870 		   p_enrt_rt_id              => p_enrt_rt_id1,
4871 		   p_entr_ann_val_flag       => NULL,
4872 		   p_entr_val_at_enrt_flag   => l_ert.entr_val_at_enrt_flag);
4873           end if;
4874 
4875 	-- l_global_enb_rec.val:=p_ann_rt_val1;
4876         --
4877       else
4878         --
4879         l_global_enb_rec.val:= l_ert.ann_val ; -- l_ann_enrt_rt ;
4880 
4881         --
4882       end if;
4883       --
4884     /*
4885     open c_ert ;
4886     fetch c_ert into l_ann_enrt_rt ;
4887     if c_ert%found then
4888       --
4889       l_global_enb_rec.val:= l_ann_enrt_rt ;
4890       --
4891     */
4892     else
4893       --
4894       l_global_enb_rec.val:=p_ann_rt_val1;
4895       --
4896     end if;
4897     close c_ert ;
4898     --
4899   elsif p_bnft_val is not null then
4900     l_global_enb_rec.val := p_bnft_val;
4901   end if;
4902   -- Added for bug 4020061
4903   if p_bnft_val = 0 and p_enrt_bnft_id is null
4904   then
4905       l_global_enb_rec.val := null ;
4906       hr_utility.set_location(' new clause --- l_global_enb_rec.val' || l_global_enb_rec.val , 50);
4907   end if;
4908 
4909   if g_debug then
4910     hr_utility.set_location(l_proc, 50);
4911   end if;
4912   --
4913   -- if changing a result get old info
4914   --
4915   if g_debug then
4916     hr_utility.set_location('prtt_enrt_rslt_id'||p_prtt_enrt_rslt_id ,8086.1);
4917     hr_utility.set_location('new coverage date '||l_global_pil_rec.lf_evt_ocrd_dt ,8086.1);
4918   end if;
4919   if p_prtt_enrt_rslt_id is not null then
4920     if g_debug then
4921       hr_utility.set_location(l_proc,51);
4922     end if;
4923     open c_current_result_info(p_prtt_enrt_rslt_id);
4924     if g_debug then
4925       hr_utility.set_location(l_proc,52);
4926     end if;
4927     fetch c_current_result_info into
4928       l_old_enrt_cvg_strt_dt,
4929       l_old_enrt_cvg_thru_dt,
4930       l_old_bnft_val,
4931       l_old_pl_id,
4932       l_old_oipl_id,
4933       l_old_orgnl_enrt_dt,
4934       l_old_per_in_ler_id,
4935       l_old_ovn,
4936       l_old_erlst_deenrt_dt,
4937       l_old_enrt_ovrid_thru_dt,
4938       l_old_enrt_ovrid_rsn_cd,
4939       l_old_enrt_ovridn_flag,
4940       l_old_sspndd_flag ;
4941     if g_debug then
4942       hr_utility.set_location(l_proc,53);
4943       hr_utility.set_location(l_global_epe_rec.enrt_cvg_strt_dt,53);
4944     end if;
4945     if c_current_result_info%notfound then
4946        -- make sure it is not deleted for fiture coverage
4947           -- null globals to prevent bleeding
4948           --
4949           close c_current_result_info;
4950           --
4951           g_enrt_bnft_id:=null;
4952           g_bnft_val:=null;
4953           g_elig_per_elctbl_chc_id:=null;
4954           --
4955           if g_debug then
4956             hr_utility.set_location('BEN_91711_ENRT_RSLT_NOT_FND'|| to_char(p_prtt_enrt_rslt_id),54);
4957           end if;
4958           fnd_message.set_name('BEN','BEN_91711_ENRT_RSLT_NOT_FND');
4959           fnd_message.set_token('PROC',l_proc);
4960           fnd_message.set_token('ID', to_char(p_prtt_enrt_rslt_id));
4961           fnd_message.set_token('PERSON_ID', to_char(l_global_pil_rec.person_id));
4962           fnd_message.set_token('LER_ID', to_char(l_global_pil_rec.ler_id));
4963           fnd_message.set_token('EFFECTIVE_DATE',to_char(p_effective_date));
4964           fnd_message.raise_error;
4965     else
4966     --
4967     close c_current_result_info;
4968     --
4969     --IF NVL(ben_sspndd_enrollment.g_cfw_flag,'N') = 'N' THEN
4970       --
4971       -- BUG 5985777 This is the case where action items from the past life event
4972       -- are completed in future.
4973       --
4974       open c_pen_curr(p_prtt_enrt_rslt_id,l_global_pil_rec.lf_evt_ocrd_dt);
4975         fetch c_pen_curr into l_pen_curr;
4976       close c_pen_curr ;
4977       --
4978       IF l_pen_curr.sspndd_flag='Y' AND l_old_sspndd_flag='N' THEN
4979         --
4980         --This is the action item completion in future case.
4981         --
4982         ben_prtt_enrt_result_api.delete_prtt_enrt_result
4983               (p_validate                => false,
4984                p_prtt_enrt_rslt_id       => p_prtt_enrt_rslt_id,
4985                p_effective_start_date    => l_effective_start_date,
4986                p_effective_end_date      => l_effective_end_date,
4987                p_object_version_number   => l_pen_curr.object_version_number,
4988                p_effective_date          => l_pen_curr.effective_end_date,
4989                p_datetrack_mode          => hr_api.g_future_change,
4990                p_multi_row_validate      => FALSE);
4991         --
4992         for l_rec in c_prv(l_pen_curr.prtt_enrt_rslt_id,l_pen_curr.per_in_ler_id) loop
4993             --
4994             open c_ecr(l_rec.prtt_rt_val_id);
4995               fetch c_ecr into l_ecr;
4996             close c_ecr;
4997             -- if rate start date found.. use it else call bendetdt to compute the date
4998             IF l_ecr.rt_strt_dt IS NOT NULL THEN
4999               null ;
5000             ELSE
5001               --call bendetdt
5002               ben_determine_date.main(
5003                p_date_cd                => l_ecr.rt_strt_dt_cd,
5004                p_per_in_ler_id          => l_pen_curr.per_in_ler_id,  --Previous Per in ler
5005                p_person_id              => l_global_pil_rec.person_id,
5006                p_pgm_id                 => l_global_epe_rec.pgm_id,
5007                p_pl_id                  => l_global_epe_rec.pl_id,
5008                p_oipl_id                => l_global_epe_rec.oipl_id,
5009                p_business_group_id      => p_business_group_id,
5010                p_formula_id             => l_ecr.rt_strt_dt_rl,
5011                p_acty_base_rt_id        => l_rec.acty_base_rt_id,
5012                p_elig_per_elctbl_chc_id => l_ecr.elig_per_elctbl_chc_id,
5013                p_effective_date         => p_effective_date,
5014                p_returned_date          => l_ecr.rt_strt_dt
5015              );
5016               --
5017             END IF;
5018             --
5019             ben_prtt_rt_val_api.update_prtt_rt_val
5020               (p_validate                => false,
5021                p_person_id               => l_global_pil_rec.person_id,
5022                p_business_group_id       => p_business_group_id,
5023                p_prtt_rt_val_id          => l_rec.prtt_rt_val_id,
5024                p_rt_strt_dt              => nvl(l_ecr.rt_strt_dt,l_rec.rt_strt_dt),
5025                p_rt_end_dt               => hr_api.g_eot,
5026                p_object_version_number   => l_rec.object_version_number,
5027                p_effective_date          => p_effective_date );
5028             --
5029         end loop;
5030         --
5031         --Interim Enrollment
5032         --
5033         IF l_pen_curr.rplcs_sspndd_rslt_id is not null THEN
5034              --
5035              hr_utility.set_location(' Extend Interim Row',99);
5036              --
5037              open c_pen_curr(l_pen_curr.rplcs_sspndd_rslt_id,l_global_pil_rec.lf_evt_ocrd_dt);
5038                 -- 6057157 : Changed the cursor variable to l_pen_curr_interim
5039                fetch c_pen_curr into l_pen_curr_interim;
5040              close c_pen_curr;
5041              --
5042              --
5043              hr_utility.set_location('l_pen_curr.prtt_enrt_rslt_id ' || l_pen_curr_interim.prtt_enrt_rslt_id,99);
5044              --
5045           IF l_pen_curr_interim.prtt_enrt_rslt_id IS NOT NULL THEN
5046                ben_prtt_enrt_result_api.delete_prtt_enrt_result
5047                 (p_validate                => false,
5048                  p_prtt_enrt_rslt_id       => l_pen_curr_interim.prtt_enrt_rslt_id,
5049                  p_effective_start_date    => l_effective_start_date,
5050                  p_effective_end_date      => l_effective_end_date,
5051                  p_object_version_number   => l_pen_curr_interim.object_version_number,
5052                  p_effective_date          => l_pen_curr_interim.effective_end_date,
5053                  p_datetrack_mode          => hr_api.g_future_change,
5054                  p_multi_row_validate      => FALSE);
5055           END IF;
5056           --
5057             -- 6057157 : Reset the Rate End to EOT, as PEN records are done similarly above.
5058             --
5059             for l_rec in c_prv(l_pen_curr_interim.prtt_enrt_rslt_id, l_pen_curr_interim.per_in_ler_id)
5060             loop
5061                 --
5062                 hr_utility.set_location('Interim l_rec.prtt_rt_val_id ' || l_rec.prtt_rt_val_id,99);
5063                 hr_utility.set_location('l_rec.rt_end_dt ' || l_rec.rt_end_dt,99);
5064                 --
5065                 ben_prtt_rt_val_api.update_prtt_rt_val
5066                   (p_validate                => false,
5067                    p_person_id               => l_global_pil_rec.person_id,
5068                    p_business_group_id       => p_business_group_id,
5069                    p_prtt_rt_val_id          => l_rec.prtt_rt_val_id,
5070                    p_rt_end_dt               => hr_api.g_eot,
5071                    p_object_version_number   => l_rec.object_version_number,
5072                    p_effective_date          => p_effective_date );
5073                 --
5074             end loop;
5075           --
5076         END IF ;
5077         --
5078         open c_current_result_info(p_prtt_enrt_rslt_id);
5079         if g_debug then
5080           hr_utility.set_location(l_proc,52.2);
5081         end if;
5082         fetch c_current_result_info into
5083           l_old_enrt_cvg_strt_dt,
5084           l_old_enrt_cvg_thru_dt,
5085           l_old_bnft_val,
5086           l_old_pl_id,
5087           l_old_oipl_id,
5088           l_old_orgnl_enrt_dt,
5089           l_old_per_in_ler_id,
5090           l_old_ovn,
5091           l_old_erlst_deenrt_dt,
5092           l_old_enrt_ovrid_thru_dt,
5093           l_old_enrt_ovrid_rsn_cd,
5094           l_old_enrt_ovridn_flag,
5095           l_old_sspndd_flag ;
5096         close c_current_result_info;
5097         --
5098       END IF;
5099     --END IF;
5100     --
5101     -- begin bug 5621049
5102     /* when u r changing from 'option1 to option2' or 'plan1 to plan2' and 'option1 nd opton2' ,or , 'plan1 nd plan2'
5103     have same benefit amount then we should not compare the bnft amount of option1 nd option2 . for this bug
5104     param p_elig_per_elctbl_chc_id belongs to option2/plan2 and
5105     param p_prtt_enrt_rslt_id belongs to option1/plan1
5106     */
5107      if l_old_bnft_val is not NULL
5108      then
5109          open c_validate_epe_pen(p_elig_per_elctbl_chc_id,p_prtt_enrt_rslt_id);
5110          fetch c_validate_epe_pen into l_dummy_char;
5111             if c_validate_epe_pen%notfound then
5112                l_old_bnft_val := null;
5113              end if ;
5114           close c_validate_epe_pen;
5115       end if ;
5116 
5117       -- end bug 5621049
5118 
5119      end if;
5120 
5121     if g_debug then
5122       hr_utility.set_location(  p_prtt_enrt_rslt_id || ' '|| l_proc,55);
5123     end if;
5124     if l_old_ovn is not null then
5125       if g_debug then
5126         hr_utility.set_location(l_proc,56);
5127       end if;
5128       p_object_version_number:=l_old_ovn;
5129     end if;
5130     if g_debug then
5131       hr_utility.set_location(l_proc,57);
5132     end if;
5133     -- close c_current_result_info;
5134     if g_debug then
5135       hr_utility.set_location(l_proc,58);
5136     end if;
5137   end if;
5138   --
5139   -- Replacing sec 129 logic to start a new enrollment if the enrollment code is CCKCSNCC
5140   -- bendenrr populates the new coverage start date
5141   --
5142    if (  p_prtt_enrt_rslt_id is not null and
5143         l_global_epe_rec.prtt_enrt_rslt_id is not null and
5144         l_global_epe_rec.prtt_enrt_rslt_id=p_prtt_enrt_rslt_id and
5145         (( ben_sspndd_enrollment.g_use_new_result=false and
5146         nvl(l_old_bnft_val,hr_api.g_number)=
5147            nvl(l_global_enb_rec.val,hr_api.g_number)) or
5148          l_old_sspndd_flag = 'Y')) then
5149       if g_debug then
5150         hr_utility.set_location('enrt cvg strt dt'||l_global_epe_rec.enrt_cvg_strt_dt,111);
5151       end if;
5152       --bug#3702090 - override enrollment not to create new result
5153       --bug#4549089 - added per in ler for suspended enrollment
5154       --bug#4555320 - added per in ler for cvg strt dt also
5155       if ( (l_global_epe_rec.enrt_cvg_strt_dt <> l_old_enrt_cvg_strt_dt and
5156             l_old_per_in_ler_id <> l_global_epe_rec.per_in_ler_id)
5157             OR
5158            (l_old_sspndd_flag = 'Y' and l_old_per_in_ler_id <>
5159              l_global_epe_rec.per_in_ler_id))
5160             and nvl(p_enrt_mthd_cd, 'z') <> 'O' then
5161          if g_debug then
5162            hr_utility.set_location('start new result',112);
5163          end if;
5164          l_start_new_result := true;
5165       end if;
5166    end if;
5167 
5168   -- if currently enrolled do an update, else create a new result.
5169   -- If the particpant is staying in the same plan and option, i.e.
5170   -- (ELIG PER ELCTBL CHC: CRNTLY ENRD FLAG = Y) do not
5171   -- write a new row.  Do update the  PRTT ENRT RSLT: ENRT MTHD CD
5172   -- to ENRT MTHD CD parameter (Currently, Explicit if updating from
5173   -- form or  Default if updatingfrom the default process).
5174   --
5175   -- If benefit amount changed treat as comp object change
5176   --
5177     if g_debug then
5178       hr_utility.set_location('l_global_epe_rec.enrt_cvg_strt_dt'||l_global_epe_rec.enrt_cvg_strt_dt,8086.1);
5179     end if;
5180     if g_debug then
5181       hr_utility.set_location('l_old_enrt_cvg_strt_dt'||l_old_enrt_cvg_strt_dt,8086.1);
5182     end if;
5183     if g_debug then
5184       hr_utility.set_location('l_global_epe_rec.erslt_deenrt_dt'||l_global_epe_rec.erlst_deenrt_dt,8086.1);
5185     end if;
5186     if g_debug then
5187       hr_utility.set_location('l_old_erlst_deenrt_dt '||l_old_erlst_deenrt_dt,8086.1);
5188     end if;
5189   if g_debug then
5190     hr_utility.set_location('l_old_bnft_val='||l_old_bnft_val,1963);
5191   end if;
5192   if g_debug then
5193     hr_utility.set_location('l_bnft_val='||l_global_enb_rec.val,1963);
5194   end if;
5195   --
5196   -- Added condition p_enrt_cvg_thru_dt is null. (maagrawa Jan 05,2001)
5197   -- p_enrt_cvg_thru_dt will be null in normal cases, but it will be populated
5198   -- when called from individual comp. api's when it is allowed to be enterable
5199   -- In such cases, we need to call delete_enrollment, to update the result
5200   -- with the new cvg_thru_dt.
5201   --
5202   if (  p_prtt_enrt_rslt_id is not null and
5203         l_global_epe_rec.prtt_enrt_rslt_id is not null and
5204         l_global_epe_rec.prtt_enrt_rslt_id=p_prtt_enrt_rslt_id and
5205         -- l_use_new_result=false and
5206         ben_sspndd_enrollment.g_use_new_result=false and /*ENH*/
5207         nvl(l_old_bnft_val,hr_api.g_number)= nvl(l_global_enb_rec.val,hr_api.g_number) and
5208         p_enrt_cvg_thru_dt is null  and
5209         l_start_new_result  = false ) then
5210     if g_debug then
5211       hr_utility.set_location(l_proc, 80);
5212     end if;
5213     --
5214     l_prtt_enrt_rslt_id:=p_prtt_enrt_rslt_id;
5215     --
5216     -- if sched mode and l_crnt_enrt_cvg_strt_dt is not null then
5217     -- see if plan has regulation of IRC Section 125 or 129.
5218     --
5219 
5220     if g_debug then
5221       hr_utility.set_location('if part ' , 8086.1);
5222     end if;
5223 
5224     l_regn_125_or_129_flag:='N';
5225    /*
5226     if l_global_pel_rec.enrt_perd_id is not null and -- same as p_run_mode='C'
5227        l_old_enrt_cvg_strt_dt is not null then
5228       open c_regn_125_or_129;
5229       fetch c_regn_125_or_129 into l_regn_125_or_129_flag;
5230       hr_utility. set_location('regn_125_or_129='||l_regn_125_or_129_flag,10);
5231       close c_regn_125_or_129;
5232     end if;
5233     */
5234     if l_regn_125_or_129_flag='N' then
5235       l_global_epe_rec.enrt_cvg_strt_dt:=l_old_enrt_cvg_strt_dt;
5236       l_global_epe_rec.erlst_deenrt_dt :=nvl(l_old_erlst_deenrt_dt,
5237                                              l_global_epe_rec.erlst_deenrt_dt);
5238     end if;
5239     --
5240     if l_global_epe_rec.enrt_cvg_strt_dt_cd = 'ENTRBL' and
5241        p_enrt_cvg_strt_dt is not null then
5242       l_global_epe_rec.enrt_cvg_strt_dt := p_enrt_cvg_strt_dt;
5243     end if;
5244 
5245     --
5246     --Bug 2600087
5247     open c_enrt_rslt;
5248     fetch c_enrt_rslt into l_enrt_rslt;
5249     if c_enrt_rslt%found then
5250        if g_debug then
5251          hr_utility.set_location('Effectve date'||l_enrt_rslt.effective_end_date,11);
5252        end if;
5253        if g_debug then
5254          hr_utility.set_location('object number '||l_enrt_rslt.object_version_number,11);
5255        end if;
5256        -- 3733745
5257        select count(*)
5258        into   l_interim_count
5259        from   ben_prtt_enrt_rslt_f pen
5260        where  pen.rplcs_sspndd_rslt_id = p_prtt_enrt_rslt_id
5261        and    nvl(pen.sspndd_flag , 'N') = 'Y'
5262        and    p_effective_date
5263              between pen.effective_start_date and pen.effective_end_date;
5264        if l_interim_count = 0 then
5265        -- end 3733745
5266        /* bug 5555269
5267        commented the 5032364 fix as well 5572484. This code became redundant after
5268        introduction of ben_reopen_ended_results.reopen_routine in benmngle
5269        package.
5270        */
5271        /*
5272        --bug#5032364
5273              open c_enrt_rslt2;
5274              fetch c_enrt_rslt2 into l_enrt_rslt2;
5275              close c_enrt_rslt2;
5276              --
5277              -- Bug 5572484 : Take backup in BEN_LE_CLSN_N_RSTR only if the correction
5278              --               is due to a new life event. E.g. If you de-enrol in a life
5279              --               event and again enrol in the same life event, then we need
5280              --               not take backup of the de-enrolled PEN
5281              --
5282              if nvl(l_old_per_in_ler_id, -999) <> l_global_epe_rec.per_in_ler_id
5283              then
5284                --
5285                insert into BEN_LE_CLSN_N_RSTR (
5286                      BKUP_TBL_TYP_CD,
5287                      COMP_LVL_CD,
5288                      LCR_ATTRIBUTE16,
5289                      LCR_ATTRIBUTE17,
5290                      LCR_ATTRIBUTE18,
5291                      LCR_ATTRIBUTE19,
5292                      LCR_ATTRIBUTE20,
5293                      LCR_ATTRIBUTE21,
5294                      LCR_ATTRIBUTE22,
5295                      LCR_ATTRIBUTE23,
5296                      LCR_ATTRIBUTE24,
5297                      LCR_ATTRIBUTE25,
5298                      LCR_ATTRIBUTE26,
5299                      LCR_ATTRIBUTE27,
5300                      LCR_ATTRIBUTE28,
5301                      LCR_ATTRIBUTE29,
5302                      LCR_ATTRIBUTE30,
5303                      LAST_UPDATE_DATE,
5304                      LAST_UPDATED_BY,
5305                      LAST_UPDATE_LOGIN,
5306                      CREATED_BY,
5307                      CREATION_DATE,
5308                      REQUEST_ID,
5309                      PROGRAM_APPLICATION_ID,
5310                      PROGRAM_ID,
5311                      PROGRAM_UPDATE_DATE,
5312                      OBJECT_VERSION_NUMBER,
5313                      BKUP_TBL_ID, -- PRTT_ENRT_RSLT_ID,
5314                      EFFECTIVE_START_DATE,
5315                      EFFECTIVE_END_DATE,
5316                      ENRT_CVG_STRT_DT,
5317                      ENRT_CVG_THRU_DT,
5318                      SSPNDD_FLAG,
5319                      PRTT_IS_CVRD_FLAG,
5320                      BNFT_AMT,
5321                      BNFT_NNMNTRY_UOM,
5322                      BNFT_TYP_CD,
5323                      UOM,
5324                      ORGNL_ENRT_DT,
5325                      ENRT_MTHD_CD,
5326                      ENRT_OVRIDN_FLAG,
5327                      ENRT_OVRID_RSN_CD,
5328                      ERLST_DEENRT_DT,
5329                      ENRT_OVRID_THRU_DT,
5330                      NO_LNGR_ELIG_FLAG,
5331                      BNFT_ORDR_NUM,
5332                      PERSON_ID,
5333                      ASSIGNMENT_ID,
5334                      PGM_ID,
5335                      PRTT_ENRT_RSLT_STAT_CD,
5336                      PL_ID,
5337                      OIPL_ID,
5338                      PTIP_ID,
5339                      PL_TYP_ID,
5340                      LER_ID,
5341                      PER_IN_LER_ID,
5342                      RPLCS_SSPNDD_RSLT_ID,
5343                      BUSINESS_GROUP_ID,
5344                      LCR_ATTRIBUTE_CATEGORY,
5345                      LCR_ATTRIBUTE1,
5346                      LCR_ATTRIBUTE2,
5347                      LCR_ATTRIBUTE3,
5348                      LCR_ATTRIBUTE4,
5349                      LCR_ATTRIBUTE5,
5350                      LCR_ATTRIBUTE6,
5351                      LCR_ATTRIBUTE7,
5352                      LCR_ATTRIBUTE8,
5353                      LCR_ATTRIBUTE9,
5354                      LCR_ATTRIBUTE10,
5355                      LCR_ATTRIBUTE11,
5356                      LCR_ATTRIBUTE12,
5357                      LCR_ATTRIBUTE13,
5358                      LCR_ATTRIBUTE14,
5359                      LCR_ATTRIBUTE15 ,
5360                      PER_IN_LER_ENDED_ID,
5361                      PL_ORDR_NUM,
5362                      PLIP_ORDR_NUM,
5363                      PTIP_ORDR_NUM,
5364                      OIPL_ORDR_NUM)
5365                    values (
5366                     'BEN_PRTT_ENRT_RSLT_F_CORR',
5367                     l_enrt_rslt2.COMP_LVL_CD,
5368                     l_enrt_rslt2.PEN_ATTRIBUTE16,
5369                     l_enrt_rslt2.PEN_ATTRIBUTE17,
5370                     l_enrt_rslt2.PEN_ATTRIBUTE18,
5371                     l_enrt_rslt2.PEN_ATTRIBUTE19,
5372                     l_enrt_rslt2.PEN_ATTRIBUTE20,
5373                     l_enrt_rslt2.PEN_ATTRIBUTE21,
5374                     l_enrt_rslt2.PEN_ATTRIBUTE22,
5375                     l_enrt_rslt2.PEN_ATTRIBUTE23,
5376                     l_enrt_rslt2.PEN_ATTRIBUTE24,
5377                     l_enrt_rslt2.PEN_ATTRIBUTE25,
5378                     l_enrt_rslt2.PEN_ATTRIBUTE26,
5379                     l_enrt_rslt2.PEN_ATTRIBUTE27,
5380                     l_enrt_rslt2.PEN_ATTRIBUTE28,
5381                     l_enrt_rslt2.PEN_ATTRIBUTE29,
5382                     l_enrt_rslt2.PEN_ATTRIBUTE30,
5383                     l_enrt_rslt2.LAST_UPDATE_DATE,
5384                     l_enrt_rslt2.LAST_UPDATED_BY,
5385                     l_enrt_rslt2.LAST_UPDATE_LOGIN,
5386                     l_enrt_rslt2.CREATED_BY,
5387                     l_enrt_rslt2.CREATION_DATE,
5388                     l_enrt_rslt2.REQUEST_ID,
5389                     l_enrt_rslt2.PROGRAM_APPLICATION_ID,
5390                     l_enrt_rslt2.PROGRAM_ID,
5391                     l_enrt_rslt2.PROGRAM_UPDATE_DATE,
5392                     l_enrt_rslt2.OBJECT_VERSION_NUMBER,
5393                     l_enrt_rslt2.PRTT_ENRT_RSLT_ID,
5394                     l_enrt_rslt2.EFFECTIVE_START_DATE,
5395                     l_enrt_rslt2.EFFECTIVE_END_DATE,
5396                     l_enrt_rslt2.ENRT_CVG_STRT_DT,
5397                     l_enrt_rslt2.ENRT_CVG_THRU_DT,
5398                     l_enrt_rslt2.SSPNDD_FLAG,
5399                     l_enrt_rslt2.PRTT_IS_CVRD_FLAG,
5400                     l_enrt_rslt2.BNFT_AMT,
5401                     l_enrt_rslt2.BNFT_NNMNTRY_UOM,
5402                     l_enrt_rslt2.BNFT_TYP_CD,
5403                     l_enrt_rslt2.UOM,
5404                     l_enrt_rslt2.ORGNL_ENRT_DT,
5405                     l_enrt_rslt2.ENRT_MTHD_CD,
5406                     l_enrt_rslt2.ENRT_OVRIDN_FLAG,
5407                     l_enrt_rslt2.ENRT_OVRID_RSN_CD,
5408                     l_enrt_rslt2.ERLST_DEENRT_DT,
5409                     l_enrt_rslt2.ENRT_OVRID_THRU_DT,
5410                     l_enrt_rslt2.NO_LNGR_ELIG_FLAG,
5411                     l_enrt_rslt2.BNFT_ORDR_NUM,
5412                     l_enrt_rslt2.PERSON_ID,
5413                     l_enrt_rslt2.ASSIGNMENT_ID,
5414                     l_enrt_rslt2.PGM_ID,
5415                     l_enrt_rslt2.PRTT_ENRT_RSLT_STAT_CD,
5416                     l_enrt_rslt2.PL_ID,
5417                     l_enrt_rslt2.OIPL_ID,
5418                     l_enrt_rslt2.PTIP_ID,
5419                     l_enrt_rslt2.PL_TYP_ID,
5420                     l_enrt_rslt2.LER_ID,
5421                     l_enrt_rslt2.PER_IN_LER_ID,
5422                     l_enrt_rslt2.RPLCS_SSPNDD_RSLT_ID,
5423                     l_enrt_rslt2.BUSINESS_GROUP_ID,
5424                     l_enrt_rslt2.PEN_ATTRIBUTE_CATEGORY,
5425                     l_enrt_rslt2.PEN_ATTRIBUTE1,
5426                     l_enrt_rslt2.PEN_ATTRIBUTE2,
5427                     l_enrt_rslt2.PEN_ATTRIBUTE3,
5428                     l_enrt_rslt2.PEN_ATTRIBUTE4,
5429                     l_enrt_rslt2.PEN_ATTRIBUTE5,
5430                     l_enrt_rslt2.PEN_ATTRIBUTE6,
5431                     l_enrt_rslt2.PEN_ATTRIBUTE7,
5432                     l_enrt_rslt2.PEN_ATTRIBUTE8,
5433                     l_enrt_rslt2.PEN_ATTRIBUTE9,
5434                     l_enrt_rslt2.PEN_ATTRIBUTE10,
5435                     l_enrt_rslt2.PEN_ATTRIBUTE11,
5436                     l_enrt_rslt2.PEN_ATTRIBUTE12,
5437                     l_enrt_rslt2.PEN_ATTRIBUTE13,
5438                     l_enrt_rslt2.PEN_ATTRIBUTE14,
5439                     l_enrt_rslt2.PEN_ATTRIBUTE15,
5440                     l_global_epe_rec.per_in_ler_id ,
5441                     l_enrt_rslt2.PL_ORDR_NUM,
5442                     l_enrt_rslt2.PLIP_ORDR_NUM,
5443                     l_enrt_rslt2.PTIP_ORDR_NUM,
5444                     l_enrt_rslt2.OIPL_ORDR_NUM
5445                 );
5446                --
5447              end if;
5448              --
5449 	     */
5450 	      -- end of bug 5555269
5451 
5452           ben_prtt_enrt_result_api.delete_prtt_enrt_result
5453               (p_validate                => false,
5454                p_prtt_enrt_rslt_id       => p_prtt_enrt_rslt_id,
5455                p_effective_start_date    => l_effective_start_date,
5456                p_effective_end_date      => l_effective_end_date,
5457                p_object_version_number   => l_enrt_rslt.object_version_number,
5458                p_effective_date          => l_enrt_rslt.effective_end_date,
5459                p_datetrack_mode          => hr_api.g_future_change,
5460                p_multi_row_validate      => FALSE);
5461       p_object_version_number := l_enrt_rslt.object_version_number;
5462       --
5463       --  Bug 5766477  Also re-open dependent coverage.
5464       --
5465       for l_dpnt_rec in  c_get_dpnt(l_enrt_rslt.effective_end_date) loop
5466       ben_elig_cvrd_dpnt_api.delete_elig_cvrd_dpnt
5467         (p_validate                => false,
5468          p_elig_cvrd_dpnt_id       => l_dpnt_rec.elig_cvrd_dpnt_id,
5469          p_effective_start_date    => l_effective_start_date,
5470          p_effective_end_date      => l_effective_end_date,
5471          p_object_version_number   => l_dpnt_rec.object_version_number,
5472          p_business_group_id       => p_business_group_id,
5473          p_effective_date          => l_enrt_rslt.effective_end_date,
5474          p_datetrack_mode          => hr_api.g_future_change,
5475          p_multi_row_actn          => FALSE);
5476       end loop;
5477 
5478       if (g_debug) then
5479           hr_utility.set_location('BKKK p_prtt_enrt_rslt_id '|| p_prtt_enrt_rslt_id, 100);
5480       end if;
5481       --
5482       open c_prtt_rt_val_id;
5483       fetch c_prtt_rt_val_id into l_prtt_rt_val_id, l_acty_base_rt_id2;
5484       loop
5485         if c_prtt_rt_val_id%notfound then
5486            exit;
5487         end if;
5488         --
5489         if (g_debug) then
5490             hr_utility.set_location('BKKK l_prtt_rt_val_id '|| l_prtt_rt_val_id, 100);
5491             hr_utility.set_location('BKKK l_acty_base_rt_id2 '|| l_acty_base_rt_id2, 100);
5492             hr_utility.set_location('BKKK p_elig_per_elctbl_chc_id  '|| p_elig_per_elctbl_chc_id, 100);
5493             hr_utility.set_location('BKKK p_enrt_bnft_id '|| p_enrt_bnft_id, 100);
5494             hr_utility.set_location('BKKK l_enrt_rt_id '|| l_enrt_rt_id, 100);
5495         end if;
5496         --
5497         open c_enrt_rt(l_acty_base_rt_id2);
5498         fetch c_enrt_rt into l_enrt_rt_id;
5499         if c_enrt_rt%found then
5500           update ben_enrt_rt
5501                set prtt_rt_val_id = l_prtt_rt_val_id
5502           where enrt_rt_id = l_enrt_rt_id;
5503           --
5504           if (g_debug) then
5505             hr_utility.set_location('BKKK l_enrt_rt_id '|| l_enrt_rt_id, 200);
5506           end if;
5507           --
5508         end if;
5509         close c_enrt_rt;
5510         fetch c_prtt_rt_val_id into l_prtt_rt_val_id, l_acty_base_rt_id2;
5511       end loop;
5512 
5513       close c_prtt_rt_val_id;
5514       --
5515       --
5516       end if ;--l_interim_count > 0--3733745
5517     end if;
5518     close c_enrt_rslt;
5519     --
5520     if g_debug then
5521       hr_utility.set_location('bef update cvg '|| l_global_epe_rec.enrt_cvg_strt_dt,8086.2);
5522     end if;
5523     if g_debug then
5524       hr_utility.set_location('bef update erly '||l_global_epe_rec.erlst_deenrt_dt,8086.2);
5525     end if;
5526     --Override code
5527     if l_old_enrt_ovrid_thru_dt is not null then
5528       --
5529       if g_debug then
5530         hr_utility.set_location(' enrt_cvg_strt_dt_cd '||l_global_epe_rec.enrt_cvg_strt_dt_cd,123);
5531       end if;
5532       if g_debug then
5533         hr_utility.set_location(' p_elig_per_elctbl_chc_id '||p_elig_per_elctbl_chc_id,123);
5534       end if;
5535       if l_global_epe_rec.enrt_cvg_strt_dt_cd is not null then
5536         ben_determine_date.main(
5537           p_date_cd            => l_global_epe_rec.enrt_cvg_strt_dt_cd,
5538           p_per_in_ler_id      => l_global_epe_rec.per_in_ler_id,
5539           p_person_id          => l_global_pil_rec.person_id,
5540           p_pgm_id             => l_global_epe_rec.pgm_id,
5541           p_pl_id              => l_global_epe_rec.pl_id,
5542           p_oipl_id            => l_global_epe_rec.oipl_id,
5543           p_business_group_id  => l_global_epe_rec.business_group_id,
5544           p_formula_id         => l_global_epe_rec.enrt_cvg_strt_dt_rl,
5545           p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
5546           p_effective_date     => p_effective_date,
5547           p_returned_date      => l_new_cvg_strt_dt
5548           );
5549       else
5550         --
5551         l_new_cvg_strt_dt := l_global_pil_rec.lf_evt_ocrd_dt ;
5552         --
5553       end if;
5554       --
5555       if l_new_cvg_strt_dt > l_old_enrt_ovrid_thru_dt then
5556         --
5557         l_old_enrt_ovrid_thru_dt := null;
5558         l_old_enrt_ovrid_rsn_cd  := null;
5559         l_old_enrt_ovridn_flag   := 'N';
5560         --
5561       end if;
5562     end if;
5563     -- end overrdie code
5564 
5565     ben_PRTT_ENRT_RESULT_api.update_enrollment(
5566           p_prtt_enrt_rslt_id        => p_prtt_enrt_rslt_id
5567         ,p_effective_start_date      => p_effective_start_date
5568         ,p_effective_end_date        => p_effective_end_date
5569         ,p_enrt_mthd_cd              => p_enrt_mthd_cd
5570         ,p_enrt_cvg_strt_dt          => l_global_epe_rec.enrt_cvg_strt_dt
5571         ,p_enrt_cvg_thru_dt          => hr_api.g_eot
5572         ,p_enrt_ovrid_thru_dt        => l_old_enrt_ovrid_thru_dt
5573         ,p_enrt_ovrid_rsn_cd         => l_old_enrt_ovrid_rsn_cd
5574         ,p_enrt_ovridn_flag          => l_old_enrt_ovridn_flag
5575         ,p_object_version_number     => p_object_version_number
5576         ,p_effective_date            => p_effective_date
5577         ,p_datetrack_mode            => p_datetrack_mode
5578         ,p_pgm_id                    => l_global_epe_rec.pgm_id
5579         ,p_ptip_id                   => l_global_epe_rec.ptip_id
5580         ,p_pl_typ_id                 => l_global_epe_rec.pl_typ_id
5581         ,p_pl_id                     => l_global_epe_rec.pl_id
5582         ,p_oipl_id                   => l_global_epe_rec.oipl_id
5583         ,p_enrt_bnft_id              => p_enrt_bnft_id
5584         ,p_business_group_id         => p_business_group_id
5585         ,p_erlst_deenrt_dt           => l_global_epe_rec.erlst_deenrt_dt
5586         ,p_per_in_ler_id             => l_global_epe_rec.per_in_ler_id
5587 --        ,p_sspndd_flag               => nvl(l_old_sspndd_flag,'N')          --Bug#5099296
5588         ,p_sspndd_flag               => nvl(l_global_pen_rec.sspndd_flag,'N') --Bug#5099296
5589         ,p_multi_row_validate        => FALSE
5590 
5591       -- derive from per_in_ler_id
5592         ,p_ler_id                    =>  l_global_pil_rec.ler_id
5593         ,p_person_id                 =>  l_global_pil_rec.person_id
5594         ,p_bnft_amt                  =>  l_global_enb_rec.val
5595         ,p_uom                       =>  l_global_pel_rec.uom
5596         ,p_bnft_nnmntry_uom          =>  l_global_enb_rec.nnmntry_uom
5597         ,p_bnft_typ_cd               =>  l_global_enb_rec.bnft_typ_cd
5598         ,p_bnft_ordr_num             =>  l_global_enb_rec.ordr_num
5599         ,p_suspend_flag              =>  p_suspend_flag
5600         ,p_prtt_enrt_interim_id      =>  l_prtt_enrt_interim_id
5601 	,p_comp_lvl_cd               =>  l_global_pen_rec.comp_lvl_cd -- bug 5417132
5602         ,p_program_application_id    => fnd_global.prog_appl_id
5603         ,p_program_id                => fnd_global.conc_program_id
5604         ,p_request_id                => fnd_global.conc_request_id
5605         ,p_program_update_date       => sysdate
5606         ,p_pen_attribute_category    => p_pen_attribute_category
5607         ,p_pen_attribute1            => p_pen_attribute1
5608         ,p_pen_attribute2            => p_pen_attribute2
5609         ,p_pen_attribute3            => p_pen_attribute3
5610         ,p_pen_attribute4            => p_pen_attribute4
5611         ,p_pen_attribute5            => p_pen_attribute5
5612         ,p_pen_attribute6            => p_pen_attribute6
5613         ,p_pen_attribute7            => p_pen_attribute7
5614         ,p_pen_attribute8            => p_pen_attribute8
5615         ,p_pen_attribute9            => p_pen_attribute9
5616         ,p_pen_attribute10           => p_pen_attribute10
5617         ,p_pen_attribute11           => p_pen_attribute11
5618         ,p_pen_attribute12           => p_pen_attribute12
5619         ,p_pen_attribute13           => p_pen_attribute13
5620         ,p_pen_attribute14           => p_pen_attribute14
5621         ,p_pen_attribute15           => p_pen_attribute15
5622         ,p_pen_attribute16           => p_pen_attribute16
5623         ,p_pen_attribute17           => p_pen_attribute17
5624         ,p_pen_attribute18           => p_pen_attribute18
5625         ,p_pen_attribute19           => p_pen_attribute19
5626         ,p_pen_attribute20           => p_pen_attribute20
5627         ,p_pen_attribute21           => p_pen_attribute21
5628         ,p_pen_attribute22           => p_pen_attribute22
5629         ,p_pen_attribute23           => p_pen_attribute23
5630         ,p_pen_attribute24           => p_pen_attribute24
5631         ,p_pen_attribute25           => p_pen_attribute25
5632         ,p_pen_attribute26           => p_pen_attribute26
5633         ,p_pen_attribute27           => p_pen_attribute27
5634         ,p_pen_attribute28           => p_pen_attribute28
5635         ,p_pen_attribute29           => p_pen_attribute29
5636         ,p_pen_attribute30           => p_pen_attribute30
5637         ,p_dpnt_actn_warning         => l_dpnt_actn_warning
5638         ,p_bnf_actn_warning          => l_bnf_actn_warning
5639         ,p_ctfn_actn_warning         => l_ctfn_actn_warning
5640     );
5641     p_prtt_enrt_interim_id:=l_prtt_enrt_interim_id;
5642     if g_debug then
5643       hr_utility.set_location(l_proc, 90);
5644     end if;
5645   --
5646   -- (maagrawa Jan 05,2001).
5647   -- Replaced this else with elsif. Normal processing will go as normal as
5648   -- the p_enrt_cvg_thru_dt will be null.
5649   -- The additional condition has been added to handle special case in
5650   -- Individual Comp. when the user enters both the coverage start date
5651   -- and the coverage through date when creating the result for the
5652   -- first time. In this case, we want to create a new enrollment and
5653   -- call delete enrollment in the end to update the coverage through date.
5654   -- If the result_id already exists and the enrt_thru_dt is not null, it means
5655   -- we do not have to create a new result, we need to just update the
5656   -- result record with the entered coverage through date, which will be
5657   -- done when delete_enrollment is called at the end.
5658   --
5659   elsif (l_global_epe_rec.prtt_enrt_rslt_id is null or
5660          p_enrt_cvg_thru_dt is null) then
5661     --
5662     if g_debug then
5663       hr_utility.set_location('elese part ' , 8086.1);
5664     end if;
5665     l_crntly_enrd_rslt_exists := false;
5666     --
5667     if l_global_epe_rec.prtt_enrt_rslt_id is not null then
5668       open  c_current_result_info(l_global_epe_rec.prtt_enrt_rslt_id);
5669       fetch c_current_result_info into l_crntly_enrd_rslt_rec;
5670       if c_current_result_info%found then
5671         l_crntly_enrd_rslt_exists := true;
5672       end if;
5673       close c_current_result_info;
5674     end if;
5675     --
5676     --Override code
5677     if l_crntly_enrd_rslt_rec.enrt_ovrid_thru_dt is not null then
5678       --
5679       if l_global_epe_rec.enrt_cvg_strt_dt_cd is not null then
5680         --
5681         ben_determine_date.main(
5682           p_date_cd            => l_global_epe_rec.enrt_cvg_strt_dt_cd,
5683           p_per_in_ler_id      => l_global_epe_rec.per_in_ler_id,
5684           p_person_id          => l_global_pil_rec.person_id,
5685           p_pgm_id             => l_global_epe_rec.pgm_id,
5686           p_pl_id              => l_global_epe_rec.pl_id,
5687           p_oipl_id            => l_global_epe_rec.oipl_id,
5688           p_business_group_id  => l_global_epe_rec.business_group_id,
5689           p_formula_id         => l_global_epe_rec.enrt_cvg_strt_dt_rl,
5690           p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
5691           p_effective_date     => p_effective_date,
5692           p_returned_date      => l_new_cvg_strt_dt
5693         );
5694         --
5695       else
5696         --
5697         l_new_cvg_strt_dt := l_global_pil_rec.lf_evt_ocrd_dt ;
5698         --
5699       end if;
5700       --
5701       if l_new_cvg_strt_dt > l_crntly_enrd_rslt_rec.enrt_ovrid_thru_dt then
5702         --
5703         l_crntly_enrd_rslt_rec.enrt_ovrid_thru_dt := null;
5704         l_crntly_enrd_rslt_rec.enrt_ovrid_rsn_cd  := null;
5705         l_crntly_enrd_rslt_rec.enrt_ovridn_flag   := 'N';
5706         --
5707       end if;
5708       --
5709     end if;
5710     -- end overrdie code
5711     --
5712     if l_global_epe_rec.crntly_enrd_flag = 'Y' and
5713        l_global_epe_rec.prtt_enrt_rslt_id is not null and
5714        l_crntly_enrd_rslt_exists and
5715        -- l_use_new_result=false and
5716        ben_sspndd_enrollment.g_use_new_result=false and /*ENH*/
5717        nvl(l_crntly_enrd_rslt_rec.bnft_amt,hr_api.g_number)=
5718            nvl(l_global_enb_rec.val,hr_api.g_number) and
5719        /* Bug 4954541 - We also need to check if old coverage was non-null and new coverage is null
5720        nvl(l_crntly_enrd_rslt_rec.bnft_amt,hr_api.g_number)=
5721            nvl(l_global_enb_rec.val,nvl(l_crntly_enrd_rslt_rec.bnft_amt,
5722                                             hr_api.g_number)) and
5723        */
5724        l_start_new_result = false and
5725        l_global_epe_rec.enrt_cvg_strt_dt = l_crntly_enrd_rslt_rec.enrt_cvg_strt_dt then  --BUG 4568911
5726       -- RCHASE Bug#5353 alteration
5727       --     nvl(l_global_enb_rec.val,hr_api.g_number) then
5728       --
5729       -- If they are not staying in the same plan and option
5730       --  and ELIG PER ELCTBL CHC: CRNTLY ENRD FLAG = Y  then
5731       -- re-use the enrollment result.
5732       --
5733       if g_debug then
5734         hr_utility.set_location(l_proc, 95);
5735       end if;
5736       --
5737       l_prtt_enrt_rslt_id     := l_global_epe_rec.prtt_enrt_rslt_id;
5738       --
5739       -- if sched mode and l_crnt_enrt_cvg_strt_dt is not null then
5740       -- see if plan has regulation of IRC Section 125 or 129.
5741       --
5742       l_regn_125_or_129_flag:='N';
5743      /*
5744       if l_global_pel_rec.enrt_perd_id is not null and -- same as p_run_mode='C'
5745          l_old_enrt_cvg_strt_dt is not null then
5746         open c_regn_125_or_129;
5747         fetch c_regn_125_or_129 into l_regn_125_or_129_flag;
5748         hr_utility. set_location('regn_125_or_129='||l_regn_125_or_129_flag,10);
5749         close c_regn_125_or_129;
5750       end if;
5751     */
5752       if l_regn_125_or_129_flag='N' then
5753         l_global_epe_rec.enrt_cvg_strt_dt:= l_crntly_enrd_rslt_rec.enrt_cvg_strt_dt;
5754         l_global_epe_rec.erlst_deenrt_dt := nvl(l_crntly_enrd_rslt_rec.erlst_deenrt_dt,
5755                                                 l_global_epe_rec.erlst_deenrt_dt);
5756       end if;
5757       --
5758       if l_global_epe_rec.enrt_cvg_strt_dt_cd = 'ENTRBL' and
5759          p_enrt_cvg_strt_dt is not null then
5760         l_global_epe_rec.enrt_cvg_strt_dt := p_enrt_cvg_strt_dt;
5761       end if;
5762       --
5763       l_object_version_number := l_crntly_enrd_rslt_rec.object_version_number;
5764       --
5765       if g_debug then
5766         hr_utility.set_location('bef update cvg '|| l_global_epe_rec.enrt_cvg_strt_dt,8086.2);
5767       end if;
5768       if g_debug then
5769         hr_utility.set_location('bef update erly '||l_global_epe_rec.erlst_deenrt_dt,8086.2);
5770       end if;
5771       ben_PRTT_ENRT_RESULT_api.update_enrollment(
5772            p_prtt_enrt_rslt_id         => l_prtt_enrt_rslt_id
5773           ,p_effective_start_date      => p_effective_start_date
5774           ,p_effective_end_date        => p_effective_end_date
5775           ,p_enrt_mthd_cd              => p_enrt_mthd_cd
5776           ,p_enrt_cvg_strt_dt          => l_global_epe_rec.enrt_cvg_strt_dt
5777           ,p_enrt_cvg_thru_dt          => hr_api.g_eot
5778           ,p_enrt_ovrid_thru_dt        => l_crntly_enrd_rslt_rec.enrt_ovrid_thru_dt
5779           ,p_enrt_ovrid_rsn_cd         => l_crntly_enrd_rslt_rec.enrt_ovrid_rsn_cd
5780           ,p_enrt_ovridn_flag          => l_crntly_enrd_rslt_rec.enrt_ovridn_flag
5781           ,p_object_version_number     => l_object_version_number
5782           ,p_effective_date            => p_effective_date
5783           ,p_datetrack_mode            => p_datetrack_mode
5784           ,p_pgm_id                    => l_global_epe_rec.pgm_id
5785           ,p_ptip_id                   => l_global_epe_rec.ptip_id
5786           ,p_pl_typ_id                 => l_global_epe_rec.pl_typ_id
5787           ,p_pl_id                     => l_global_epe_rec.pl_id
5788           ,p_oipl_id                   => l_global_epe_rec.oipl_id
5789           ,p_enrt_bnft_id              => p_enrt_bnft_id
5790           ,p_business_group_id         => l_global_epe_rec.business_group_id
5791           ,p_erlst_deenrt_dt           => l_global_epe_rec.erlst_deenrt_dt
5792           ,p_per_in_ler_id             => l_global_epe_rec.per_in_ler_id
5793 --          ,p_sspndd_flag               => nvl(l_old_sspndd_flag,'N')        --Bug#5099296
5794         ,p_sspndd_flag               => nvl(l_global_pen_rec.sspndd_flag,'N') --Bug#5099296
5795           ,p_multi_row_validate        => FALSE
5796 
5797         -- derive from per_in_ler_id
5798           ,p_ler_id                    =>  l_global_pil_rec.ler_id
5799           ,p_person_id                 =>  l_global_pil_rec.person_id
5800           ,p_bnft_amt                  =>  l_global_enb_rec.val
5801         ,p_uom                       =>  l_global_pel_rec.uom
5802         ,p_bnft_nnmntry_uom          =>  l_global_enb_rec.nnmntry_uom
5803         ,p_bnft_typ_cd               =>  l_global_enb_rec.bnft_typ_cd
5804         ,p_bnft_ordr_num             =>  l_global_enb_rec.ordr_num
5805           ,p_suspend_flag              =>  p_suspend_flag
5806           ,p_prtt_enrt_interim_id      =>  l_prtt_enrt_interim_id
5807 	  ,p_comp_lvl_cd               =>  l_global_pen_rec.comp_lvl_cd  -- 5417132
5808           ,p_program_application_id    => fnd_global.prog_appl_id
5809           ,p_program_id                => fnd_global.conc_program_id
5810           ,p_request_id                => fnd_global.conc_request_id
5811           ,p_program_update_date       => sysdate
5812           ,p_pen_attribute_category    => p_pen_attribute_category
5813           ,p_pen_attribute1            => p_pen_attribute1
5814           ,p_pen_attribute2            => p_pen_attribute2
5815           ,p_pen_attribute3            => p_pen_attribute3
5816           ,p_pen_attribute4            => p_pen_attribute4
5817           ,p_pen_attribute5            => p_pen_attribute5
5818           ,p_pen_attribute6            => p_pen_attribute6
5819           ,p_pen_attribute7            => p_pen_attribute7
5820           ,p_pen_attribute8            => p_pen_attribute8
5821           ,p_pen_attribute9            => p_pen_attribute9
5822           ,p_pen_attribute10           => p_pen_attribute10
5823           ,p_pen_attribute11           => p_pen_attribute11
5824           ,p_pen_attribute12           => p_pen_attribute12
5825           ,p_pen_attribute13           => p_pen_attribute13
5826           ,p_pen_attribute14           => p_pen_attribute14
5827           ,p_pen_attribute15           => p_pen_attribute15
5828           ,p_pen_attribute16           => p_pen_attribute16
5829           ,p_pen_attribute17           => p_pen_attribute17
5830           ,p_pen_attribute18           => p_pen_attribute18
5831           ,p_pen_attribute19           => p_pen_attribute19
5832           ,p_pen_attribute20           => p_pen_attribute20
5833           ,p_pen_attribute21           => p_pen_attribute21
5834           ,p_pen_attribute22           => p_pen_attribute22
5835           ,p_pen_attribute23           => p_pen_attribute23
5836           ,p_pen_attribute24           => p_pen_attribute24
5837           ,p_pen_attribute25           => p_pen_attribute25
5838           ,p_pen_attribute26           => p_pen_attribute26
5839           ,p_pen_attribute27           => p_pen_attribute27
5840           ,p_pen_attribute28           => p_pen_attribute28
5841           ,p_pen_attribute29           => p_pen_attribute29
5842           ,p_pen_attribute30           => p_pen_attribute30
5843           ,p_dpnt_actn_warning         => l_dpnt_actn_warning
5844           ,p_bnf_actn_warning          => l_bnf_actn_warning
5845           ,p_ctfn_actn_warning         => l_ctfn_actn_warning
5846       );
5847       p_prtt_enrt_interim_id:=l_prtt_enrt_interim_id; --CFW
5848       -- RCHASE Bug#5353 No interim is being passed back
5849       l_prtt_enrt_interim_id:=nvl(l_prtt_enrt_interim_id,l_prtt_enrt_rslt_id); --CFW
5850       if g_debug then
5851         hr_utility.set_location(l_proc, 97);
5852       end if;
5853       -- Bug 2627078 fixes
5854       -- Now If the User selected the Interim as the Main enrollment while
5855       -- replacing the suspended enrollment, delink the interim from the
5856       -- suspended enrollment which is going to get deleted. So that it
5857       -- can become the original enrollment
5858       open c_delink_interim(l_global_epe_rec.prtt_enrt_rslt_id,p_prtt_enrt_rslt_id );
5859         fetch c_delink_interim into
5860               l_delink_interim.prtt_enrt_rslt_id,
5861               l_delink_interim.object_version_number ;
5862         if c_delink_interim%found then
5863             ben_prtt_enrt_result_api.update_prtt_enrt_result
5864               (p_validate                 => FALSE,
5865                p_prtt_enrt_rslt_id        => l_delink_interim.prtt_enrt_rslt_id,
5866                p_effective_start_date     => l_dlink_effective_start_date,
5867                p_effective_end_date       => l_dlink_effective_end_date,
5868                p_business_group_id        => p_business_group_id,
5869                p_RPLCS_SSPNDD_RSLT_ID     => null,
5870                p_object_version_number    => l_delink_interim.object_version_number,
5871                p_effective_date           => p_effective_date,
5872                p_datetrack_mode           => hr_api.g_correction,
5873                p_multi_row_validate       => FALSE,
5874                p_program_application_id   => fnd_global.prog_appl_id,
5875                p_program_id               => fnd_global.conc_program_id,
5876                p_request_id               => fnd_global.conc_request_id,
5877                p_program_update_date      => sysdate);
5878             --
5879             p_object_version_number := l_delink_interim.object_version_number ;
5880         end if ;
5881       close c_delink_interim ;
5882     else
5883       if g_debug then
5884         hr_utility.set_location(l_proc, 100);
5885       end if;
5886       -- If they are not staying in the same plan and option
5887       -- (ELIG PER ELCTBL CHC: CRNTLY ENRD FLAG = N) and
5888       -- no replacement result is specified, then create a new
5889       -- enrolment.
5890 
5891       -- need to create a new result
5892 
5893       -- first, resolve previously unknown values.
5894 
5895       if (l_global_epe_rec.enrt_cvg_strt_dt_cd is not null) then
5896         if g_debug then
5897           hr_utility.set_location(l_proc, 130);
5898         end if;
5899         l_elect_cvg_strt_dt   := l_global_epe_rec.enrt_cvg_strt_dt    ;
5900         --
5901         if l_global_epe_rec.enrt_cvg_strt_dt_cd = 'ENTRBL' and
5902            p_enrt_cvg_strt_dt is not null then
5903           l_global_epe_rec.enrt_cvg_strt_dt := p_enrt_cvg_strt_dt;
5904         end if;
5905         --
5906 
5907 
5908         ben_determine_date.main(
5909           p_date_cd            => l_global_epe_rec.enrt_cvg_strt_dt_cd,
5910           p_per_in_ler_id      => l_global_epe_rec.per_in_ler_id,
5911           p_person_id          => l_global_pil_rec.person_id,
5912           p_pgm_id             => l_global_epe_rec.pgm_id,
5913           p_pl_id              => l_global_epe_rec.pl_id,
5914           p_oipl_id            => l_global_epe_rec.oipl_id,
5915           p_business_group_id  => l_global_epe_rec.business_group_id,
5916           p_formula_id         => l_global_epe_rec.enrt_cvg_strt_dt_rl,
5917           p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
5918           p_effective_date     => p_effective_date,
5919         --  p_returned_date      => l_global_epe_rec.enrt_cvg_strt_dt
5920           p_returned_date      => l_enrt_cvg_strt_dt
5921         );
5922 
5923        if g_debug then
5924            hr_utility.set_location('calc date' || l_enrt_cvg_strt_dt,8086.1);
5925            hr_utility.set_location('prev calc date' || l_global_epe_rec.enrt_cvg_strt_dt,8086.1);
5926        end if;
5927        -- 2982606 when the first time enrolled in waiting plan,after save thge enrollment the date changed back to
5928        --even date
5929        if l_enrt_cvg_strt_dt > l_global_epe_rec.enrt_cvg_strt_dt
5930           -- if the coverage start dt code is election then take the current cacluated code
5931           OR l_global_epe_rec.enrt_cvg_strt_dt_cd in  ('ODEWM','AFDELD','FDMELD')  then
5932            l_global_epe_rec.enrt_cvg_strt_dt := l_enrt_cvg_strt_dt;
5933            hr_utility.set_location('after comparison  calc date' || l_global_epe_rec.enrt_cvg_strt_dt,8086.1);
5934        end if;
5935 
5936 
5937         if g_debug then
5938            hr_utility.set_location('denrt at elec' ||l_global_epe_rec.erlst_deenrt_dt,8086.1);
5939          end if;
5940          if g_debug then
5941            hr_utility.set_location('prt rslt deent '||l_old_erlst_deenrt_dt , 8086.1);
5942          end if;
5943          if g_debug then
5944            hr_utility.set_location('before calc cvg'||l_elect_cvg_strt_dt,8086.1);
5945          end if;
5946 
5947         ---calcualte the function to call the erls_denrt_dt
5948         --- l_old_erlst_deenrt_dt is decide the previous enrolment
5949         -- bal_epe_rec.epe.erlst_deenrt_dt decide the whether erlst_deenrt_dt is to be calc
5950         if l_old_erlst_deenrt_dt is null and
5951            l_global_epe_rec.erlst_deenrt_dt is not null and
5952            nvl(l_elect_cvg_strt_dt,hr_api.g_eot)
5953                   <> l_global_epe_rec.enrt_cvg_strt_dt  then
5954            if g_debug then
5955              hr_utility.set_location('CALLINGH ERLST DATE ' , 8086.1);
5956            end if;
5957            determine_erlst_deenrt_date(p_oipl_id        => l_global_epe_rec.oipl_id,
5958                                  p_pl_id                => l_global_epe_rec.pl_id,
5959                                  p_pl_typ_id            => l_global_epe_rec.pl_typ_id ,
5960                                  p_ptip_id              => l_global_epe_rec.ptip_id,
5961                                  p_pgm_id               => l_global_epe_rec.pgm_id,
5962                                  p_ler_id               => l_global_pil_rec.ler_id ,
5963                                  p_effective_date       => p_effective_date,
5964                                  p_business_group_id    => p_business_group_id,
5965                                  p_orgnl_enrt_dt        => l_old_orgnl_enrt_dt,
5966                                  p_person_id            => l_global_pil_rec.person_id,
5967                                  p_lf_evt_ocrd_dt       => p_effective_date,
5968                                  p_enrt_cvg_strt_dt     => l_global_epe_rec.enrt_cvg_strt_dt,
5969                                  p_return_date          => l_global_epe_rec.erlst_deenrt_dt);
5970         else
5971             l_global_epe_rec.erlst_deenrt_dt := nvl(l_old_erlst_deenrt_dt,
5972                                                         l_global_epe_rec.erlst_deenrt_dt) ;
5973         end if ;
5974       end if;
5975 
5976       if g_debug then
5977         hr_utility.set_location('l_global_epe_recerslt_deenrt_dt'||l_global_epe_rec.erlst_deenrt_dt,8086.1);
5978       end if;
5979       if g_debug then
5980         hr_utility.set_location('l_global_epe_recerslt_deenrt_dt'||l_global_epe_rec.enrt_cvg_strt_dt,8086.1);
5981       end if;
5982       if g_debug then
5983         hr_utility.set_location('l_old_erlst_deenrt_dt '||l_old_erlst_deenrt_dt,8086.1);
5984       end if;
5985       if g_debug then
5986         hr_utility.set_location(l_proc, 150);
5987       end if;
5988       if (l_global_epe_rec.enrt_cvg_strt_dt is null) then
5989         --
5990         -- null globals to prevent bleeding
5991         --
5992         g_enrt_bnft_id:=null;
5993         g_bnft_val:=null;
5994         g_elig_per_elctbl_chc_id:=null;
5995         --
5996         if g_debug then
5997           hr_utility.set_location('BEN_91453_CVG_STRT_DT_NOT_FOUN id:'|| to_char(l_global_epe_rec.pl_id), 169);
5998         end if;
5999         fnd_message.set_name('BEN','BEN_91453_CVG_STRT_DT_NOT_FOUN');
6000         fnd_message.set_token('PROC',l_proc);
6001         fnd_message.set_token('PERSON_ID',to_char(l_global_pil_rec.person_id));
6002         fnd_message.set_token('PGM_ID',to_char(l_global_epe_rec.pgm_id));
6003         fnd_message.set_token('PLAN_ID',to_char(l_global_epe_rec.pl_id));
6004         fnd_message.set_token('OIPL_ID',to_char(l_global_epe_rec.oipl_id));
6005         fnd_message.raise_error;
6006       end if; -- date is null
6007       if g_debug then
6008         hr_utility.set_location(l_proc, 170);
6009       end if;
6010       if (nvl(l_old_bnft_val,hr_api.g_number)<>
6011              nvl(l_global_enb_rec.val,hr_api.g_number)
6012          -- Bug#1807450 added and condition
6013           and p_prtt_enrt_rslt_id is not null) or
6014          -- Added for Interim Coverage /*ENH*/
6015          ben_sspndd_enrollment.g_use_new_result  or
6016          (l_global_epe_rec.crntly_enrd_flag = 'Y' and
6017              p_prtt_enrt_rslt_id is null) or  -- bug#5105122-called from backout
6018          l_start_new_result  then
6019         l_bnft_amt_changed:= TRUE;
6020         ben_determine_date.rate_and_coverage_dates
6021               (p_which_dates_cd         => 'C'
6022               ,p_business_group_id      => l_global_epe_rec.business_group_id
6023               ,p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id
6024    --           ,p_enrt_cvg_strt_dt       => l_global_epe_rec.enrt_cvg_strt_dt
6025               ,p_enrt_cvg_strt_dt       =>l_enrt_cvg_strt_dt
6026               ,p_enrt_cvg_strt_dt_cd    => l_xenrt_cvg_strt_dt_cd
6027               ,p_enrt_cvg_strt_dt_rl    => l_xenrt_cvg_strt_dt_rl
6028               ,p_rt_strt_dt             => l_xrt_strt_dt
6029               ,p_rt_strt_dt_cd          => l_xrt_strt_dt_cd
6030               ,p_rt_strt_dt_rl          => l_xrt_strt_dt_rl
6031               ,p_enrt_cvg_end_dt        => l_xenrt_cvg_end_dt
6032               ,p_enrt_cvg_end_dt_cd     => l_xenrt_cvg_end_dt_cd
6033               ,p_enrt_cvg_end_dt_rl     => l_xenrt_cvg_end_dt_rl
6034               ,p_rt_end_dt              => l_xrt_end_dt
6035               ,p_rt_end_dt_cd           => l_xrt_end_dt_cd
6036               ,p_rt_end_dt_rl           => l_xrt_end_dt_rl
6037               ,p_acty_base_rt_id        => null
6038               ,p_effective_date         => p_effective_date
6039               /* Start of Changes for WWBUG: 2141172: added line                */
6040               ,p_lf_evt_ocrd_dt         => l_global_pil_rec.lf_evt_ocrd_dt
6041               /* End of Changes for WWBUG: 2141172: added line                  */
6042         );
6043         -- if there is any waiting period, the start date returned above override the coverage
6044         -- start date arrived in the benmngle - bug#1807450
6045         --
6046        hr_utility.set_location( 'l_global_epe_rec.enrt_cvg_strt_dt'||l_global_epe_rec.enrt_cvg_strt_dt,444);
6047        hr_utility.set_location( 'l_enrt_cvg_strt_dt'||l_enrt_cvg_strt_dt,444);
6048         if l_enrt_cvg_strt_dt > l_global_epe_rec.enrt_cvg_strt_dt then
6049            l_global_epe_rec.enrt_cvg_strt_dt := l_enrt_cvg_strt_dt;
6050         end if;
6051         --
6052       end if;
6053       --
6054       if l_global_epe_rec.enrt_cvg_strt_dt_cd = 'ENTRBL' and
6055          p_enrt_cvg_strt_dt is not null then
6056         l_global_epe_rec.enrt_cvg_strt_dt := p_enrt_cvg_strt_dt;
6057       end if;
6058       --
6059       --
6060       -- if staying in same plan use the old original enrt date
6061       --
6062       if (l_old_pl_id=l_global_epe_rec.pl_id) then
6063         l_orgnl_enrt_dt:=l_old_orgnl_enrt_dt;
6064           -- Bug 3602579 - now check if previous enrollment was in waive option
6065          if l_old_oipl_id is not null and l_global_epe_rec.oipl_id is not null then
6066             hr_utility.set_location( 'Into the new clause l_old_oipl_id '|| l_old_oipl_id ,999);
6067             hr_utility.set_location( 'Into the new clause l_global_epe_rec.oipl_id '|| l_global_epe_rec.oipl_id ,999);
6068            if (l_old_oipl_id <> l_global_epe_rec.oipl_id) then
6069                hr_utility.set_location( 'Into the new clause ',999);
6070                -- check if old oipl is waive.
6071                open c_wv_opt (l_old_oipl_id);
6072                fetch c_wv_opt into l_wv_flag ;
6073                close  c_wv_opt ;
6074                hr_utility.set_location( 'Into the new clause l_wv_flag '|| l_wv_flag ,999);
6075                if nvl(l_wv_flag,'N') = 'Y' then
6076                   l_wv_flag := 'N' ;
6077                   l_orgnl_enrt_dt := l_global_epe_rec.enrt_cvg_strt_dt;
6078                end if ;
6079            end if ;
6080          end if ;
6081       else
6082         l_orgnl_enrt_dt:=l_global_epe_rec.enrt_cvg_strt_dt;
6083       end if;
6084       --
6085       hr_utility.set_location( 'l_global_pil_rec.lf_evt_ocrd_dt '|| l_global_pil_rec.lf_evt_ocrd_dt ,999);
6086 
6087       -- create the enrolment result
6088       if l_global_epe_rec.ptip_id is not null then
6089         ben_cobj_cache.get_ptip_dets
6090           (p_business_group_id => p_business_group_id
6091           ,p_effective_date    => l_global_pil_rec.lf_evt_ocrd_dt --Bug 6503304
6092           ,p_ptip_id           => l_global_epe_rec.ptip_id
6093           ,p_inst_row          => l_ptip_rec);
6094       end if;
6095       if l_global_epe_rec.plip_id is not null then
6096         ben_cobj_cache.get_plip_dets
6097           (p_business_group_id => p_business_group_id
6098           ,p_effective_date    => l_global_pil_rec.lf_evt_ocrd_dt --Bug 6503304
6099           ,p_plip_id           => l_global_epe_rec.plip_id
6100           ,p_inst_row          => l_plip_rec);
6101       end if;
6102       if l_global_epe_rec.oipl_id is not null then
6103         ben_cobj_cache.get_oipl_dets
6104            (p_business_group_id => p_business_group_id
6105            ,p_effective_date    => l_global_pil_rec.lf_evt_ocrd_dt --Bug 6503304
6106            ,p_oipl_id           => l_global_epe_rec.oipl_id
6107            ,p_inst_row          => l_oipl_rec);
6108       end if;
6109       if l_global_epe_rec.pl_id is not null then
6110         ben_cobj_cache.get_pl_dets
6111           (p_business_group_id => p_business_group_id
6112           ,p_effective_date    => l_global_pil_rec.lf_evt_ocrd_dt --Bug 6503304
6113           ,p_pl_id             => l_global_epe_rec.pl_id
6114           ,p_inst_row          => l_pl_rec);
6115       end if;
6116   --
6117   -- unrestricted changes
6118 
6119      if p_prtt_enrt_rslt_id is not null then
6120         l_datetrack_mode := hr_api.g_update;
6121      else
6122         l_datetrack_mode := p_datetrack_mode;
6123      end if;
6124      -- Bug 2172036 pass assignment_id also to create pen
6125      -- cursor moved 4510798
6126      --open c_epe ;
6127      --fetch c_epe into l_assignment_id;
6128      --close c_epe ;
6129      if g_debug then
6130        hr_utility.set_location( 'l_assignment_id '||l_assignment_id,12);
6131        hr_utility.set_location( 'l_global_epe_rec.enrt_cvg_strt_dt'||l_global_epe_rec.enrt_cvg_strt_dt,12);
6132      end if;
6133      --
6134      --  Bug 7206471. Check if the coverage should be adjusted.
6135     --
6136     open c_get_prior_per_in_ler;
6137     fetch c_get_prior_per_in_ler into l_exists;
6138     if c_get_prior_per_in_ler%found then
6139   --
6140      for l_pgm in c_get_pgm loop
6141       --
6142       open c_get_pgm_extra_info_cvg(l_pgm.pgm_id);
6143       fetch c_get_pgm_extra_info_cvg into l_cvg_adjust;
6144       if c_get_pgm_extra_info_cvg%found then
6145         --
6146         if l_cvg_adjust = 'Y' then
6147           --
6148 	  hr_utility.set_location('l_cvg_adjust '||l_cvg_adjust,44333);
6149 	  --
6150           --  Get cvg end dt
6151 	  --
6152 	  for l_get_elctbl_chc_for_cvg in c_get_elctbl_chc_for_cvg loop
6153 	  --
6154           --  Get all results that were de-enrolled for the event.
6155 	  --
6156           for l_get_enrt_rslts_for_pen in c_get_enrt_rslts_for_pen(l_get_elctbl_chc_for_cvg.enrt_cvg_strt_dt
6157                                        ,l_get_elctbl_chc_for_cvg.ptip_id ) loop
6158               hr_utility.set_location('Adjusting Coverage for '||l_get_elctbl_chc_for_cvg.enrt_cvg_strt_dt,44333);
6159               --
6160 	      open c_prtt_enrt_rslt_adj(l_get_enrt_rslts_for_pen.prtt_enrt_rslt_id);
6161               fetch c_prtt_enrt_rslt_adj into l_exists;
6162               if c_prtt_enrt_rslt_adj%notfound then
6163                 insert into BEN_LE_CLSN_N_RSTR (
6164                         BKUP_TBL_TYP_CD,
6165                         BKUP_TBL_ID,
6166                         per_in_ler_id,
6167                         person_id,
6168                         ENRT_CVG_THRU_DT,
6169                         business_group_id,
6170                         object_version_number)
6171                       values (
6172                         'BEN_PRTT_ENRT_RSLT_F_ADJ',
6173                         l_get_enrt_rslts_for_pen.prtt_enrt_rslt_id,
6174                         l_get_enrt_rslts_for_pen.pil_id,
6175                         l_get_enrt_rslts_for_pen.person_id,
6176                         l_get_enrt_rslts_for_pen.enrt_cvg_thru_dt,
6177                         p_business_group_id,
6178                         l_get_enrt_rslts_for_pen.object_version_number
6179                       );
6180               end if;
6181               close c_prtt_enrt_rslt_adj;
6182                --
6183 	        ben_prtt_enrt_result_api.update_prtt_enrt_result
6184                (p_validate                 => FALSE,
6185                p_prtt_enrt_rslt_id        => l_get_enrt_rslts_for_pen.prtt_enrt_rslt_id,
6186                p_effective_start_date     => l_effective_start_date,
6187                p_effective_end_date       => l_effective_end_date,
6188                p_business_group_id        => p_business_group_id,
6189                p_object_version_number    => l_get_enrt_rslts_for_pen.object_version_number,
6190                p_effective_date           => p_effective_date,
6191                p_datetrack_mode           => hr_api.g_correction,
6192                p_multi_row_validate       => FALSE,
6193 	       p_enrt_cvg_thru_dt         => l_get_elctbl_chc_for_cvg.enrt_cvg_strt_dt - 1
6194                );
6195             end loop;  -- c_get_enrt_rslts_for_pen
6196           end loop; -- c_get_elctbl_chc_for_cvg
6197         end if;  -- l_cvg_adjust = 'Y'
6198       end if;  -- c_get_pgm_extra_info_cvg
6199       close c_get_pgm_extra_info_cvg;
6200     end loop; -- c_get_pgm
6201     end if;
6202     close c_get_prior_per_in_ler;
6203     --
6204     -- End bug 7206471
6205     --
6206       ben_PRTT_ENRT_RESULT_api.create_enrollment
6207         (p_prtt_enrt_rslt_id              =>  l_prtt_enrt_rslt_id
6208         ,P_prtt_enrt_rslt_id_o            =>  p_prtt_enrt_rslt_id
6209         ,p_elig_per_elctbl_chc_id         =>  p_elig_per_elctbl_chc_id
6210         ,p_assignment_id                  =>  l_assignment_id  --Bug 2172036
6211         ,p_effective_start_date           =>  p_effective_start_date
6212         ,p_effective_end_date             =>  p_effective_end_date
6213         ,p_pgm_id                         =>  l_global_epe_rec.pgm_id
6214         ,p_ptip_id                        =>  l_global_epe_rec.ptip_id
6215         ,p_pl_typ_id                      =>  l_global_epe_rec.pl_typ_id
6216         ,p_pl_id                          =>  l_global_epe_rec.pl_id
6217         ,p_oipl_id                        =>  l_global_epe_rec.oipl_id
6218         ,p_pl_ordr_num                    =>  l_pl_rec.ordr_num
6219         ,p_plip_ordr_num                  =>  l_plip_rec.ordr_num
6220         ,p_ptip_ordr_num                  =>  l_ptip_rec.ordr_num
6221         ,p_oipl_ordr_num                  =>  l_oipl_rec.ordr_num
6222         ,p_business_group_id              =>  l_global_epe_rec.business_group_id
6223         ,p_erlst_deenrt_dt                =>  l_global_epe_rec.erlst_deenrt_dt
6224         ,p_enrt_mthd_cd                   =>  p_enrt_mthd_cd
6225         --
6226         -- derive from per_in_ler_id
6227         --
6228         ,p_ler_id                         =>  l_global_pil_rec.ler_id
6229         ,p_person_id                      =>  l_global_pil_rec.person_id
6230         ,p_per_in_ler_id                  =>  l_global_epe_rec.per_in_ler_id
6231         ,p_bnft_amt                     =>  l_global_enb_rec.val
6232         ,p_uom                          =>  l_global_pel_rec.uom
6233         ,p_bnft_nnmntry_uom             =>  l_global_enb_rec.nnmntry_uom
6234         ,p_comp_lvl_cd                  =>  l_global_epe_rec.comp_lvl_cd
6235         ,p_bnft_typ_cd                  =>  l_global_enb_rec.bnft_typ_cd
6236         ,p_bnft_ordr_num                =>  l_global_enb_rec.ordr_num
6237         ,p_enrt_cvg_strt_dt             =>  l_global_epe_rec.enrt_cvg_strt_dt
6238         ,p_orgnl_enrt_dt                =>  l_orgnl_enrt_dt
6239         ,p_object_version_number        =>  l_object_version_number
6240         ,p_effective_date               =>  p_effective_date
6241         ,p_suspend_flag                 =>  p_suspend_flag
6242         ,p_called_from_sspnd            => p_called_from_sspnd
6243         ,p_prtt_enrt_interim_id         =>  l_prtt_enrt_interim_id
6244         ,p_datetrack_mode               =>  l_datetrack_mode
6245         ,p_multi_row_validate           => FALSE
6246         ,p_program_application_id       => fnd_global.prog_appl_id
6247         ,p_program_id                   => fnd_global.conc_program_id
6248         ,p_request_id                   => fnd_global.conc_request_id
6249         ,p_program_update_date          => sysdate
6250          -- Bug #2714383
6251       -- Passing null if the attribute value is $Sys_Def$
6252         ,p_pen_attribute_category       => decd_attribute(p_pen_attribute_category)
6253         ,p_pen_attribute1               => decd_attribute(p_pen_attribute1)
6254         ,p_pen_attribute2               => decd_attribute(p_pen_attribute2)
6255         ,p_pen_attribute3               => decd_attribute(p_pen_attribute3)
6256         ,p_pen_attribute4               => decd_attribute(p_pen_attribute4)
6257         ,p_pen_attribute5               => decd_attribute(p_pen_attribute5)
6258         ,p_pen_attribute6               => decd_attribute(p_pen_attribute6)
6259         ,p_pen_attribute7               => decd_attribute(p_pen_attribute7)
6260         ,p_pen_attribute8               => decd_attribute(p_pen_attribute8)
6261         ,p_pen_attribute9               => decd_attribute(p_pen_attribute9)
6262         ,p_pen_attribute10              => decd_attribute(p_pen_attribute10)
6263         ,p_pen_attribute11              => decd_attribute(p_pen_attribute11)
6264         ,p_pen_attribute12              => decd_attribute(p_pen_attribute12)
6265         ,p_pen_attribute13              => decd_attribute(p_pen_attribute13)
6266         ,p_pen_attribute14              => decd_attribute(p_pen_attribute14)
6267         ,p_pen_attribute15              => decd_attribute(p_pen_attribute15)
6268         ,p_pen_attribute16              => decd_attribute(p_pen_attribute16)
6269         ,p_pen_attribute17              => decd_attribute(p_pen_attribute17)
6270         ,p_pen_attribute18              => decd_attribute(p_pen_attribute18)
6271         ,p_pen_attribute19              => decd_attribute(p_pen_attribute19)
6272         ,p_pen_attribute20              => decd_attribute(p_pen_attribute20)
6273         ,p_pen_attribute21              => decd_attribute(p_pen_attribute21)
6274         ,p_pen_attribute22              => decd_attribute(p_pen_attribute22)
6275         ,p_pen_attribute23              => decd_attribute(p_pen_attribute23)
6276         ,p_pen_attribute24              => decd_attribute(p_pen_attribute24)
6277         ,p_pen_attribute25              => decd_attribute(p_pen_attribute25)
6278         ,p_pen_attribute26              => decd_attribute(p_pen_attribute26)
6279         ,p_pen_attribute27              => decd_attribute(p_pen_attribute27)
6280         ,p_pen_attribute28              => decd_attribute(p_pen_attribute28)
6281         ,p_pen_attribute29              => decd_attribute(p_pen_attribute29)
6282         ,p_pen_attribute30              => decd_attribute(p_pen_attribute30)
6283         ,p_dpnt_actn_warning            => l_dpnt_actn_warning
6284         ,p_bnf_actn_warning             => l_bnf_actn_warning
6285         ,p_ctfn_actn_warning            => l_ctfn_actn_warning
6286         ,p_enrt_bnft_id                 => p_enrt_bnft_id
6287         ,p_source                       => 'benelinf'
6288       );
6289         if g_debug then
6290           hr_utility.set_location( 'l_global_epe_rec.erlst_deenrt_dt'||l_global_epe_rec.erlst_deenrt_dt,1233);
6291         end if;
6292         if g_debug then
6293           hr_utility.set_location( 'l_global_epe_rec.per_in_ler_id'||l_global_epe_rec.per_in_ler_id,1233);
6294         end if;
6295         if g_debug then
6296           hr_utility.set_location( 'l_prtt_enrt_rslt_id '||l_prtt_enrt_rslt_id,1233);
6297         end if;
6298         if g_debug then
6299           hr_utility.set_location( 'p_prtt_enrt_rslt_id '||p_prtt_enrt_rslt_id,1233);
6300         end if;
6301         if g_debug then
6302           hr_utility.set_location( 'p_datetrack_mode '||p_datetrack_mode,1233);
6303         end if;
6304         if g_debug then
6305           hr_utility.set_location( 'p_effective_date '||p_effective_date,1233);
6306         end if;
6307         --
6308         -- write to the change event log.  thayden.  such a mess!
6309         --
6310         if l_global_epe_rec.pl_id <> nvl(l_old_pl_id,l_global_epe_rec.pl_id) or
6311            l_global_epe_rec.oipl_id <>
6312            nvl(l_old_oipl_id,l_global_epe_rec.oipl_id) then
6313           ben_ext_chlg.log_benefit_chg
6314           (p_action                      =>  'UPDATE' --plan and option changes
6315           ,p_pl_id                       =>  l_global_epe_rec.pl_id
6316           ,p_old_pl_id                   =>  l_old_pl_id
6317           ,p_oipl_id                     =>  l_global_epe_rec.oipl_id
6318           ,p_old_oipl_id                 =>  l_old_oipl_id
6319           ,p_enrt_cvg_strt_dt            =>  l_global_epe_rec.enrt_cvg_strt_dt
6320           ,p_old_enrt_cvg_strt_dt        =>  l_old_enrt_cvg_strt_dt
6321           ,p_old_enrt_cvg_end_dt         =>  l_old_enrt_cvg_thru_dt
6322           ,p_prtt_enrt_rslt_id           =>  l_prtt_enrt_rslt_id
6323           ,p_old_prtt_enrt_rslt_id       =>  p_prtt_enrt_rslt_id
6324           ,p_per_in_ler_id               =>  l_global_epe_rec.per_in_ler_id
6325           ,p_old_per_in_ler_id           =>  l_old_per_in_ler_id
6326           ,p_person_id                   =>  l_global_pil_rec.person_id
6327           ,p_business_group_id           =>  l_global_epe_rec.business_group_id
6328           ,p_effective_date              =>  p_effective_date
6329           );
6330         else
6331           ben_ext_chlg.log_benefit_chg
6332           (p_action                      =>  'CREATE'  -- new enrollment
6333           ,p_pl_id                       =>  l_global_epe_rec.pl_id
6334           ,p_old_pl_id                   =>  l_old_pl_id
6335           ,p_oipl_id                     =>  l_global_epe_rec.oipl_id
6336           ,p_old_oipl_id                 =>  l_old_oipl_id
6337           ,p_old_bnft_amt                =>  l_old_bnft_val
6338           ,p_bnft_amt                    =>  l_global_enb_rec.val
6339           ,p_enrt_cvg_strt_dt            =>  l_global_epe_rec.enrt_cvg_strt_dt
6340           ,p_enrt_cvg_end_dt             =>  hr_api.g_eot  --?
6341           ,p_prtt_enrt_rslt_id           =>  l_prtt_enrt_rslt_id
6342           ,p_per_in_ler_id               =>  l_global_epe_rec.per_in_ler_id
6343           ,p_person_id                   =>  l_global_pil_rec.person_id
6344           ,p_business_group_id           =>  l_global_epe_rec.business_group_id
6345           ,p_effective_date              =>  p_effective_date
6346           );
6347         end if;
6348         --
6349         ben_ext_chlg.log_benefit_chg
6350           (p_action                      =>  l_action
6351           ,p_pl_id                       =>  l_global_epe_rec.pl_id
6352           ,p_old_pl_id                   =>  l_old_pl_id
6353           ,p_oipl_id                     =>  l_global_epe_rec.oipl_id
6354           ,p_old_oipl_id                 =>  l_old_oipl_id
6355           ,p_enrt_cvg_strt_dt            =>  l_global_epe_rec.enrt_cvg_strt_dt
6356           ,p_old_enrt_cvg_strt_dt        =>  l_old_enrt_cvg_strt_dt
6357           ,p_old_enrt_cvg_end_dt         =>  l_old_enrt_cvg_thru_dt
6358           ,p_prtt_enrt_rslt_id           =>  l_prtt_enrt_rslt_id
6359           ,p_old_prtt_enrt_rslt_id       =>  p_prtt_enrt_rslt_id
6360           ,p_per_in_ler_id               =>  l_global_epe_rec.per_in_ler_id
6361           ,p_person_id                   =>  l_global_pil_rec.person_id
6362           ,p_business_group_id           =>  l_global_epe_rec.business_group_id
6363           ,p_effective_date              =>  p_effective_date
6364           );
6365 
6366       p_prtt_enrt_interim_id:=l_prtt_enrt_interim_id;
6367       --
6368     end if;
6369     --
6370     if g_debug then
6371       hr_utility.set_location(l_proc, 330);
6372     end if;
6373     --
6374     if p_prtt_enrt_rslt_id is not null -- and
6375        -- l_use_new_result=false then
6376        -- ben_sspndd_enrollment.g_use_new_result=false) Bug 2543071 Needs to delete if the interim
6377        -- is the old enrollment.We create a new enrollment for interim.
6378        or l_start_new_result then /*ENH*/
6379       --
6380       -- If the old enrollment is now the interim coverage
6381       -- then don't end it, leave it be.
6382       --
6383       hr_utility.set_location('ben_sspndd_enrollment.g_sspnded_rslt_id ' || ben_sspndd_enrollment.g_sspnded_rslt_id, 1212);
6384       hr_utility.set_location('l_prtt_enrt_interim_id ' || l_prtt_enrt_interim_id, 1212);
6385       hr_utility.set_location('p_prtt_enrt_rslt_id ' || p_prtt_enrt_rslt_id, 1212);
6386       if (l_prtt_enrt_interim_id is null or
6387          l_prtt_enrt_interim_id <> p_prtt_enrt_rslt_id)
6388          -- 6337803
6389          and p_prtt_enrt_rslt_id <> nvl(ben_sspndd_enrollment.g_sspnded_rslt_id,-1)
6390          then
6391         --
6392         -- deenrol
6393         --
6394         if g_debug then
6395           hr_utility.set_location(l_proc, 115);
6396         end if;
6397         if g_debug then
6398           hr_utility.set_location( 'p_datetrack_mode '||p_datetrack_mode,1234);
6399         end if;
6400         if g_debug then
6401           hr_utility.set_location( 'p_effective_date '||p_effective_date,1234);
6402         end if;
6403         -- Bug 2627078 fixes
6404         -- Don't try to delete if the result is already got deleted by the earlier
6405         -- process.
6406         open c_pen_exists(p_prtt_enrt_rslt_id);
6407         fetch c_pen_exists into l_dummy_char ;
6408         if c_pen_exists%found then
6409           --
6410           ben_PRTT_ENRT_RESULT_api.delete_enrollment(
6411              p_prtt_enrt_rslt_id          => p_prtt_enrt_rslt_id
6412             ,p_per_in_ler_id              => l_global_epe_rec.per_in_ler_id
6413             ,p_business_group_id          => l_global_epe_rec.business_group_id
6414             ,p_effective_start_date       => p_effective_start_date
6415             ,p_effective_end_date         => p_effective_end_date
6416             ,p_object_version_number      => p_object_version_number
6417             ,p_effective_date             => p_effective_date
6418             ,p_datetrack_mode             => nvl(l_datetrack_mode, p_datetrack_mode) /*2483991*/
6419             ,p_multi_row_validate         => FALSE
6420             ,p_source                     => 'benelinf'
6421             ,p_lee_rsn_id                 => l_global_pel_rec.lee_rsn_id
6422             ,p_enrt_perd_id               => l_global_pel_rec.enrt_perd_id
6423           );
6424           --
6425           -- after delete enrollment the fonm flag back
6426           -- when the plan replcaed  the dele_enroll might have reset the fonm flag
6427           ben_manage_life_events.fonm := l_fonm_flag ;
6428           ben_manage_life_events.g_fonm_cvg_strt_dt := l_fonm_cvg_strt_dt;
6429 
6430           hr_utility.set_location (' aftr del_enrl  FONM ' ||  ben_manage_life_events.fonm , 99 ) ;
6431           hr_utility.set_location (' FONM CVG  ' ||  ben_manage_life_events.g_fonm_cvg_strt_dt , 99 ) ;
6432 
6433 
6434         end if;
6435         --
6436         close c_pen_exists ;
6437         if g_debug then
6438           hr_utility.set_location(l_proc, 109);
6439         end if;
6440       end if;
6441       if g_debug then
6442         hr_utility.set_location(l_proc, 110);
6443       end if;
6444       -- 6337803 unsetting the pen id to be suspended
6445       ben_sspndd_enrollment.g_sspnded_rslt_id := null;
6446       --
6447     end if;
6448     --
6449     -- For the create return the new ovn
6450     --
6451     p_object_version_number:=l_object_version_number;
6452   end if;
6453   if g_debug then
6454     hr_utility.set_location(l_proc, 340);
6455   end if;
6456 
6457   p_prtt_enrt_rslt_id:=l_prtt_enrt_rslt_id;
6458 
6459   -- update, create and delete enrolloment may all change the enrt_bnft row.
6460   if p_enrt_bnft_id is not null then
6461      ben_global_enrt.get_enb -- enrt bnft  --CHANGE TO RELOAD_ENB if it's created.
6462         (p_enrt_bnft_id           => p_enrt_bnft_id
6463         ,p_global_enb_rec         => l_global_enb_rec);
6464   else ben_global_enrt.clear_enb
6465         (p_global_enb_rec         => l_global_enb_rec);
6466   end if;
6467 
6468   -- update benefit fk in enrt_bnft
6469   if g_debug then
6470     hr_utility.set_location(l_proc, 342);
6471   end if;
6472   manage_enrt_bnft(
6473         p_enrt_bnft_id               => p_enrt_bnft_id,
6474         p_effective_date             => p_effective_date,
6475         p_object_version_number      => l_global_enb_rec.object_version_number,
6476         p_business_group_id          => p_business_group_id,
6477         p_prtt_enrt_rslt_id          => l_prtt_enrt_rslt_id,
6478         p_per_in_ler_id              => l_global_epe_rec.per_in_ler_id,
6479         p_creation_date              => null,
6480         p_created_by                 => null
6481   );
6482   if g_debug then
6483     hr_utility.set_location(l_proc, 346);
6484   end if;
6485 
6486   -- process all rates
6487 
6488   if p_enrt_rt_id1 is not null then
6489     if g_debug then
6490       hr_utility.set_location(l_proc, 350);
6491     end if;
6492     election_rate_information(
6493         p_enrt_mthd_cd            => p_enrt_mthd_cd,
6494         p_effective_date          => p_effective_date,
6495         p_prtt_enrt_rslt_id       => p_prtt_enrt_rslt_id,
6496         p_per_in_ler_id           => l_global_epe_rec.per_in_ler_id,
6497         p_person_id               => l_global_pil_rec.person_id,
6498         p_pgm_id                  => l_global_epe_rec.pgm_id,
6499         p_pl_id                   => l_global_epe_rec.pl_id,
6500         p_oipl_id                 => l_global_epe_rec.oipl_id,
6501         p_enrt_rt_id              => p_enrt_rt_id1,
6502         p_prtt_rt_val_id          => p_prtt_rt_val_id1,
6503         p_rt_val                  => p_rt_val1,
6504         p_ann_rt_val              => p_ann_rt_val1,
6505         p_enrt_cvg_strt_dt        => l_global_epe_rec.enrt_cvg_strt_dt,
6506         p_acty_ref_perd_cd        => l_global_pel_rec.acty_ref_perd_cd,
6507         p_datetrack_mode          => p_datetrack_mode,
6508         p_business_group_id       => p_business_group_id,
6509         p_bnft_amt_changed        => l_bnft_amt_changed,
6510         p_rt_strt_dt              => p_rt_strt_dt1,
6511         p_rt_end_dt               => p_rt_end_dt1,
6512         --
6513         p_prv_rt_val              => l_dummy_number,
6514         p_prv_ann_rt_val          => l_dummy_number);
6515     if g_debug then
6516       hr_utility.set_location(l_proc, 360);
6517     end if;
6518   end if;
6519 
6520   if g_debug then
6521     hr_utility.set_location(l_proc, 370);
6522   end if;
6523 
6524   if p_enrt_rt_id2 is not null then
6525     if g_debug then
6526       hr_utility.set_location(l_proc, 380);
6527     end if;
6528     election_rate_information(
6529         p_enrt_mthd_cd           => p_enrt_mthd_cd,
6530         p_effective_date         => p_effective_date,
6531         p_prtt_enrt_rslt_id      => p_prtt_enrt_rslt_id,
6532         p_per_in_ler_id          => l_global_epe_rec.per_in_ler_id,
6533         p_person_id              => l_global_pil_rec.person_id,
6534         p_pgm_id                 => l_global_epe_rec.pgm_id,
6535         p_pl_id                  => l_global_epe_rec.pl_id,
6536         p_oipl_id                => l_global_epe_rec.oipl_id,
6537         p_enrt_rt_id             => p_enrt_rt_id2,
6538         p_prtt_rt_val_id         => p_prtt_rt_val_id2,
6539         p_rt_val                 => p_rt_val2,
6540         p_ann_rt_val             => p_ann_rt_val2,
6541         p_enrt_cvg_strt_dt       => l_global_epe_rec.enrt_cvg_strt_dt,
6542         p_acty_ref_perd_cd       => l_global_pel_rec.acty_ref_perd_cd,
6543         p_datetrack_mode         => p_datetrack_mode,
6544         p_business_group_id      => p_business_group_id,
6545         p_bnft_amt_changed       => l_bnft_amt_changed,
6546         p_rt_strt_dt             => p_rt_strt_dt2,
6547         p_rt_end_dt              => p_rt_end_dt2,
6548         --
6549         p_prv_rt_val             => l_dummy_number,
6550         p_prv_ann_rt_val         => l_dummy_number);
6551     if g_debug then
6552       hr_utility.set_location(l_proc, 390);
6553     end if;
6554   end if;
6555   if g_debug then
6556     hr_utility.set_location(l_proc, 395);
6557   end if;
6558 
6559 
6560   if p_enrt_rt_id3 is not null then
6561     if g_debug then
6562       hr_utility.set_location(l_proc, 400);
6563     end if;
6564     election_rate_information(
6565         p_enrt_mthd_cd            => p_enrt_mthd_cd,
6566         p_effective_date          => p_effective_date,
6567         p_prtt_enrt_rslt_id       => p_prtt_enrt_rslt_id,
6568         p_per_in_ler_id           => l_global_epe_rec.per_in_ler_id,
6569         p_person_id               => l_global_pil_rec.person_id,
6570         p_pgm_id                  => l_global_epe_rec.pgm_id,
6571         p_pl_id                   => l_global_epe_rec.pl_id,
6572         p_oipl_id                 => l_global_epe_rec.oipl_id,
6573         p_enrt_rt_id              => p_enrt_rt_id3,
6574         p_prtt_rt_val_id          => p_prtt_rt_val_id3,
6575         p_rt_val                  => p_rt_val3,
6576         p_ann_rt_val              => p_ann_rt_val3,
6577         p_enrt_cvg_strt_dt        => l_global_epe_rec.enrt_cvg_strt_dt,
6578         p_acty_ref_perd_cd        => l_global_pel_rec.acty_ref_perd_cd,
6579         p_datetrack_mode          => p_datetrack_mode,
6580         p_business_group_id       => p_business_group_id,
6581         p_bnft_amt_changed        => l_bnft_amt_changed,
6582         p_rt_strt_dt              => p_rt_strt_dt3,
6583         p_rt_end_dt               => p_rt_end_dt3,
6584         --
6585         p_prv_rt_val              => l_dummy_number,
6586         p_prv_ann_rt_val          => l_dummy_number);
6587     if g_debug then
6588       hr_utility.set_location(l_proc, 410);
6589     end if;
6590   end if;
6591   if g_debug then
6592     hr_utility.set_location(l_proc, 420);
6593   end if;
6594 
6595 
6596   if p_enrt_rt_id4 is not null then
6597     if g_debug then
6598       hr_utility.set_location(l_proc, 430);
6599     end if;
6600     election_rate_information(
6601         p_enrt_mthd_cd             => p_enrt_mthd_cd,
6602         p_effective_date           => p_effective_date,
6603         p_prtt_enrt_rslt_id        => p_prtt_enrt_rslt_id,
6604         p_per_in_ler_id            => l_global_epe_rec.per_in_ler_id,
6605         p_person_id                => l_global_pil_rec.person_id,
6606         p_pgm_id                   => l_global_epe_rec.pgm_id,
6607         p_pl_id                    => l_global_epe_rec.pl_id,
6608         p_oipl_id                  => l_global_epe_rec.oipl_id,
6609         p_enrt_rt_id               => p_enrt_rt_id4,
6610         p_prtt_rt_val_id           => p_prtt_rt_val_id4,
6611         p_rt_val                   => p_rt_val4,
6612         p_ann_rt_val               => p_ann_rt_val4,
6613         p_enrt_cvg_strt_dt         => l_global_epe_rec.enrt_cvg_strt_dt,
6614         p_acty_ref_perd_cd         => l_global_pel_rec.acty_ref_perd_cd,
6615         p_datetrack_mode           => p_datetrack_mode,
6616         p_business_group_id        => p_business_group_id,
6617         p_bnft_amt_changed         => l_bnft_amt_changed,
6618         p_rt_strt_dt               => p_rt_strt_dt4,
6619         p_rt_end_dt                => p_rt_end_dt4,
6620         --
6621         p_prv_rt_val               => l_dummy_number,
6622         p_prv_ann_rt_val           => l_dummy_number);
6623     if g_debug then
6624       hr_utility.set_location(l_proc, 440);
6625     end if;
6626   end if;
6627   if g_debug then
6628     hr_utility.set_location(l_proc, 450);
6629   end if;
6630 
6631 
6632   if p_enrt_rt_id5 is not null then
6633     if g_debug then
6634       hr_utility.set_location(l_proc, 460);
6635     end if;
6636     election_rate_information(
6637         p_enrt_mthd_cd             => p_enrt_mthd_cd,
6638         p_effective_date           => p_effective_date,
6639         p_prtt_enrt_rslt_id        => p_prtt_enrt_rslt_id,
6640         p_per_in_ler_id            => l_global_epe_rec.per_in_ler_id,
6641         p_person_id                => l_global_pil_rec.person_id,
6642         p_pgm_id                   => l_global_epe_rec.pgm_id,
6643         p_pl_id                    => l_global_epe_rec.pl_id,
6644         p_oipl_id                  => l_global_epe_rec.oipl_id,
6645         p_enrt_rt_id               => p_enrt_rt_id5,
6646         p_prtt_rt_val_id           => p_prtt_rt_val_id5,
6647         p_rt_val                   => p_rt_val5,
6648         p_ann_rt_val               => p_ann_rt_val5,
6649         p_enrt_cvg_strt_dt         => l_global_epe_rec.enrt_cvg_strt_dt,
6650         p_acty_ref_perd_cd         => l_global_pel_rec.acty_ref_perd_cd,
6651         p_datetrack_mode           => p_datetrack_mode,
6652         p_business_group_id        => p_business_group_id,
6653         p_bnft_amt_changed         => l_bnft_amt_changed,
6654         p_rt_strt_dt               => p_rt_strt_dt5,
6655         p_rt_end_dt                => p_rt_end_dt5,
6656         --
6657         p_prv_rt_val               => l_dummy_number,
6658         p_prv_ann_rt_val           => l_dummy_number);
6659     if g_debug then
6660       hr_utility.set_location(l_proc, 470);
6661     end if;
6662   end if;
6663   if g_debug then
6664     hr_utility.set_location(l_proc, 480);
6665   end if;
6666 
6667 
6668   if p_enrt_rt_id6 is not null then
6669     if g_debug then
6670       hr_utility.set_location(l_proc, 490);
6671     end if;
6672     election_rate_information(
6673         p_enrt_mthd_cd             => p_enrt_mthd_cd,
6674         p_effective_date           => p_effective_date,
6675         p_prtt_enrt_rslt_id        => p_prtt_enrt_rslt_id,
6676         p_per_in_ler_id            => l_global_epe_rec.per_in_ler_id,
6677         p_person_id                => l_global_pil_rec.person_id,
6678         p_pgm_id                   => l_global_epe_rec.pgm_id,
6679         p_pl_id                    => l_global_epe_rec.pl_id,
6680         p_oipl_id                  => l_global_epe_rec.oipl_id,
6681         p_enrt_rt_id               => p_enrt_rt_id6,
6682         p_prtt_rt_val_id           => p_prtt_rt_val_id6,
6683         p_rt_val                   => p_rt_val6,
6684         p_ann_rt_val               => p_ann_rt_val6,
6685         p_enrt_cvg_strt_dt         => l_global_epe_rec.enrt_cvg_strt_dt,
6686         p_acty_ref_perd_cd         => l_global_pel_rec.acty_ref_perd_cd,
6687         p_datetrack_mode           => p_datetrack_mode,
6688         p_business_group_id        => p_business_group_id,
6689         p_bnft_amt_changed         => l_bnft_amt_changed,
6690         p_rt_strt_dt               => p_rt_strt_dt6,
6691         p_rt_end_dt                => p_rt_end_dt6,
6692         --
6693         p_prv_rt_val               => l_dummy_number,
6694         p_prv_ann_rt_val           => l_dummy_number);
6695     if g_debug then
6696       hr_utility.set_location(l_proc, 500);
6697     end if;
6698   end if;
6699   if g_debug then
6700     hr_utility.set_location(l_proc, 510);
6701   end if;
6702 
6703 
6704   if p_enrt_rt_id7 is not null then
6705     if g_debug then
6706       hr_utility.set_location(l_proc, 520);
6707     end if;
6708     election_rate_information(
6709         p_enrt_mthd_cd             => p_enrt_mthd_cd,
6710         p_effective_date           => p_effective_date,
6711         p_prtt_enrt_rslt_id        => p_prtt_enrt_rslt_id,
6712         p_per_in_ler_id            => l_global_epe_rec.per_in_ler_id,
6713         p_person_id                => l_global_pil_rec.person_id,
6714         p_pgm_id                   => l_global_epe_rec.pgm_id,
6715         p_pl_id                    => l_global_epe_rec.pl_id,
6716         p_oipl_id                  => l_global_epe_rec.oipl_id,
6717         p_enrt_rt_id               => p_enrt_rt_id7,
6718         p_prtt_rt_val_id           => p_prtt_rt_val_id7,
6719         p_rt_val                   => p_rt_val7,
6720         p_ann_rt_val               => p_ann_rt_val7,
6721         p_enrt_cvg_strt_dt         => l_global_epe_rec.enrt_cvg_strt_dt,
6722         p_acty_ref_perd_cd         => l_global_pel_rec.acty_ref_perd_cd,
6723         p_datetrack_mode           => p_datetrack_mode,
6724         p_business_group_id        => p_business_group_id,
6725         p_bnft_amt_changed         => l_bnft_amt_changed,
6726         p_rt_strt_dt               => p_rt_strt_dt7,
6727         p_rt_end_dt                => p_rt_end_dt7,
6728         --
6729         p_prv_rt_val               => l_dummy_number,
6730         p_prv_ann_rt_val           => l_dummy_number);
6731     if g_debug then
6732       hr_utility.set_location(l_proc, 530);
6733     end if;
6734   end if;
6735   if g_debug then
6736     hr_utility.set_location(l_proc, 540);
6737   end if;
6738 
6739 
6740   if p_enrt_rt_id8 is not null then
6741     if g_debug then
6742       hr_utility.set_location(l_proc, 550);
6743     end if;
6744     election_rate_information(
6745         p_enrt_mthd_cd             => p_enrt_mthd_cd,
6746         p_effective_date           => p_effective_date,
6747         p_prtt_enrt_rslt_id        => p_prtt_enrt_rslt_id,
6748         p_per_in_ler_id            => l_global_epe_rec.per_in_ler_id,
6749         p_person_id                => l_global_pil_rec.person_id,
6750         p_pgm_id                   => l_global_epe_rec.pgm_id,
6751         p_pl_id                    => l_global_epe_rec.pl_id,
6752         p_oipl_id                  => l_global_epe_rec.oipl_id,
6753         p_enrt_rt_id               => p_enrt_rt_id8,
6754         p_prtt_rt_val_id           => p_prtt_rt_val_id8,
6755         p_rt_val                   => p_rt_val8,
6756         p_ann_rt_val               => p_ann_rt_val8,
6757         p_enrt_cvg_strt_dt         => l_global_epe_rec.enrt_cvg_strt_dt,
6758         p_acty_ref_perd_cd         => l_global_pel_rec.acty_ref_perd_cd,
6759         p_datetrack_mode           => p_datetrack_mode,
6760         p_business_group_id        => p_business_group_id,
6761         p_bnft_amt_changed         => l_bnft_amt_changed,
6762         p_rt_strt_dt               => p_rt_strt_dt8,
6763         p_rt_end_dt                => p_rt_end_dt8,
6764         --
6765         p_prv_rt_val               => l_dummy_number,
6766         p_prv_ann_rt_val           => l_dummy_number);
6767     if g_debug then
6768       hr_utility.set_location(l_proc, 560);
6769     end if;
6770   end if;
6771   if g_debug then
6772     hr_utility.set_location(l_proc, 570);
6773   end if;
6774 
6775 
6776   if p_enrt_rt_id9 is not null then
6777     if g_debug then
6778       hr_utility.set_location(l_proc, 580);
6779     end if;
6780     election_rate_information(
6781         p_enrt_mthd_cd             => p_enrt_mthd_cd,
6782         p_effective_date           => p_effective_date,
6783         p_prtt_enrt_rslt_id        => p_prtt_enrt_rslt_id,
6784         p_per_in_ler_id            => l_global_epe_rec.per_in_ler_id,
6785         p_person_id                => l_global_pil_rec.person_id,
6786         p_pgm_id                   => l_global_epe_rec.pgm_id,
6787         p_pl_id                    => l_global_epe_rec.pl_id,
6788         p_oipl_id                  => l_global_epe_rec.oipl_id,
6789         p_enrt_rt_id               => p_enrt_rt_id9,
6790         p_prtt_rt_val_id           => p_prtt_rt_val_id9,
6791         p_rt_val                   => p_rt_val9,
6792         p_ann_rt_val               => p_ann_rt_val9,
6793         p_enrt_cvg_strt_dt         => l_global_epe_rec.enrt_cvg_strt_dt,
6794         p_acty_ref_perd_cd         => l_global_pel_rec.acty_ref_perd_cd,
6795         p_datetrack_mode           => p_datetrack_mode,
6796         p_business_group_id        => p_business_group_id,
6797         p_bnft_amt_changed         => l_bnft_amt_changed,
6798         p_rt_strt_dt               => p_rt_strt_dt9,
6799         p_rt_end_dt                => p_rt_end_dt9,
6800         --
6801         p_prv_rt_val               => l_dummy_number,
6802         p_prv_ann_rt_val           => l_dummy_number);
6803     if g_debug then
6804       hr_utility.set_location(l_proc, 590);
6805     end if;
6806   end if;
6807   if g_debug then
6808     hr_utility.set_location(l_proc, 600);
6809   end if;
6810 
6811 
6812   if p_enrt_rt_id10 is not null then
6813     if g_debug then
6814       hr_utility.set_location(l_proc, 610);
6815     end if;
6816     election_rate_information(
6817         p_enrt_mthd_cd              => p_enrt_mthd_cd,
6818         p_effective_date            => p_effective_date,
6819         p_prtt_enrt_rslt_id         => p_prtt_enrt_rslt_id,
6820         p_per_in_ler_id             => l_global_epe_rec.per_in_ler_id,
6821         p_person_id                 => l_global_pil_rec.person_id,
6822         p_pgm_id                    => l_global_epe_rec.pgm_id,
6823         p_pl_id                     => l_global_epe_rec.pl_id,
6824         p_oipl_id                   => l_global_epe_rec.oipl_id,
6825         p_enrt_rt_id                => p_enrt_rt_id10,
6826         p_prtt_rt_val_id            => p_prtt_rt_val_id10,
6827         p_rt_val                    => p_rt_val10,
6828         p_ann_rt_val                => p_ann_rt_val10,
6829         p_enrt_cvg_strt_dt          => l_global_epe_rec.enrt_cvg_strt_dt,
6830         p_acty_ref_perd_cd          => l_global_pel_rec.acty_ref_perd_cd,
6831         p_datetrack_mode            => p_datetrack_mode,
6832         p_business_group_id         => p_business_group_id,
6833         p_bnft_amt_changed          => l_bnft_amt_changed,
6834         p_rt_strt_dt                => p_rt_strt_dt10,
6835         p_rt_end_dt                 => p_rt_end_dt10,
6836         --
6837         p_prv_rt_val                => l_dummy_number,
6838         p_prv_ann_rt_val            => l_dummy_number);
6839     if g_debug then
6840       hr_utility.set_location(l_proc, 620);
6841     end if;
6842   end if;
6843   --
6844   -- If the coverage through date has been passed in, it means we have to update
6845   -- the result record with the same.
6846   --
6847   if p_enrt_cvg_thru_dt is not null and
6848      p_prtt_enrt_rslt_id is not null then
6849      --
6850      -- If the result was created in the same run, then the mode will be insert.
6851      -- In this case, we can only do update in correction mode.
6852      --
6853      if p_datetrack_mode = hr_api.g_insert then
6854         l_datetrack_mode := hr_api.g_correction;
6855      else
6856         l_datetrack_mode := p_datetrack_mode;
6857      end if;
6858      --
6859      ben_PRTT_ENRT_RESULT_api.delete_enrollment(
6860         p_prtt_enrt_rslt_id          => p_prtt_enrt_rslt_id
6861        ,p_per_in_ler_id              => l_global_epe_rec.per_in_ler_id
6862        ,p_business_group_id          => l_global_epe_rec.business_group_id
6863        ,p_effective_start_date       => p_effective_start_date
6864        ,p_effective_end_date         => p_effective_end_date
6865        ,p_object_version_number      => p_object_version_number
6866        ,p_effective_date             => p_effective_date
6867        ,p_datetrack_mode             => p_datetrack_mode
6868        ,p_multi_row_validate         => FALSE
6869        ,p_source                     => 'benelinf'
6870        ,p_lee_rsn_id                 => l_global_pel_rec.lee_rsn_id
6871        ,p_enrt_perd_id               => l_global_pel_rec.enrt_perd_id
6872        ,p_enrt_cvg_thru_dt           => p_enrt_cvg_thru_dt
6873        ,p_mode                       => 'CVG_END_DATE_ENTERABLE'
6874      );
6875   end if;
6876   --
6877   ben_det_enrt_rates.set_global_enrt_rslt
6878      (p_prtt_enrt_rslt_id         => p_prtt_enrt_rslt_id);
6879   --
6880   -- Set the out parameters
6881   --
6882   p_dpnt_actn_warning := l_dpnt_actn_warning;
6883   p_bnf_actn_warning := l_bnf_actn_warning;
6884   p_ctfn_actn_warning := l_ctfn_actn_warning;
6885   --
6886   -- null globals to prevent bleeding
6887   --
6888   g_enrt_bnft_id:=null;
6889   g_bnft_val:=null;
6890   g_elig_per_elctbl_chc_id:=null;
6891   ben_global_enrt.clear_enb
6892        (p_global_enb_rec         => l_global_enb_rec);
6893   --
6894   -- When in validation only mode raise the Validate_Enabled exception
6895   --
6896   if p_validate then
6897     raise hr_api.validate_enabled;
6898   end if;
6899 
6900   if g_debug then
6901     hr_utility.set_location('Leaving:'||l_proc, 999);
6902   end if;
6903 
6904 exception
6905   --
6906   when hr_api.validate_enabled then
6907     --
6908     -- As the Validate_Enabled exception has been raised
6909     -- we must rollback to the savepoint
6910     --
6911     if p_called_from_sspnd = 'N' then
6912        ROLLBACK TO election_information_savepoint;
6913     else
6914        ROLLBACK TO election_information_sspnd;
6915     end if;
6916 
6917     --
6918     -- Only set output warning arguments
6919     -- (Any key or derived arguments must be set to null
6920     -- when validation only mode is being used.)
6921     --
6922     p_prtt_enrt_interim_id:=null;
6923    ben_sspndd_enrollment.g_use_new_result :=false  ; -- bug 5653168
6924 
6925     if g_debug then
6926       hr_utility.set_location(' Leaving:'||l_proc, 80);
6927     end if;
6928     --
6929   when others then
6930     --
6931     -- A validation or unexpected error has occured
6932     --
6933     --
6934     -- null globals to prevent bleeding
6935     --
6936     g_enrt_bnft_id:=null;
6937     g_bnft_val:=null;
6938     g_elig_per_elctbl_chc_id:=null;
6939     ben_sspndd_enrollment.g_use_new_result:=false;   -- bug 5653168
6940     --
6941     if p_called_from_sspnd = 'N' then
6942        ROLLBACK TO election_information_savepoint;
6943     else
6944        ROLLBACK TO election_information_sspnd;
6945     end if;
6946     raise;
6947     --
6948 
6949 end election_information;
6950 -- ----------------------------------------------------------------------------
6951 -- |-----------------------------< MANAGE_ENRT_BNFT >-------------------------|
6952 -- ----------------------------------------------------------------------------
6953 procedure MANAGE_ENRT_BNFT
6954               (p_prtt_enrt_rslt_id     IN     number
6955               ,p_enrt_bnft_id          IN     number default null
6956               ,p_object_version_number in out nocopy number
6957               ,p_business_group_id     in     number
6958               ,p_effective_date        in     date
6959               ,p_per_in_ler_id         in     number
6960               ,p_created_by            in     varchar2 default null
6961               ,p_creation_date         in     date     default null
6962               )IS
6963   l_proc         varchar2(72) ;
6964   cursor c1 is
6965         select ebr.enrt_bnft_id,
6966                ebr.object_version_number
6967           from ben_enrt_bnft ebr,
6968                ben_elig_per_elctbl_chc epe,
6969                ben_per_in_ler pil
6970          where ebr.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id and
6971                ( p_enrt_bnft_id is null OR
6972                  ebr.enrt_bnft_id <> p_enrt_bnft_id )
6973                and epe.elig_per_elctbl_chc_id=ebr.elig_per_elctbl_chc_id
6974                and pil.per_in_ler_id=epe.per_in_ler_id
6975                and pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT')
6976                and pil.per_in_ler_id = p_per_in_ler_id ;
6977   BEGIN
6978     g_debug := hr_utility.debug_enabled;
6979     if g_debug then
6980       l_proc          := g_package||'manage_enrt_bnft';
6981       hr_utility.set_location('Entering:'||l_proc, 5);
6982     end if;
6983     if g_debug then
6984       hr_utility.set_location(' bnft:'|| to_char(p_enrt_bnft_id), 5);
6985     end if;
6986     if g_debug then
6987       hr_utility.set_location(' rslt:'|| to_char(p_prtt_enrt_rslt_id), 15);
6988     end if;
6989     if g_debug then
6990       hr_utility.set_location(' enb_ovn:'|| to_char(p_object_version_number), 15);
6991     end if;
6992 
6993     for rec in c1 loop
6994         if g_debug then
6995           hr_utility.set_location(l_proc, 10);
6996         end if;
6997         -- Update any enrollment benefit records that may have had the result id
6998         -- on them from previous enrollments.  Set rslt id = null.
6999         ben_enrt_bnft_api.update_enrt_bnft
7000                 (p_enrt_bnft_id           => rec.enrt_bnft_id
7001                 ,p_effective_date         => p_effective_date
7002                 ,p_object_version_number  => rec.object_version_number
7003                 ,p_business_group_id      => p_business_group_id
7004                 ,p_prtt_enrt_rslt_id      => NULL
7005                 ,p_program_application_id =>fnd_global.prog_appl_id
7006                 ,p_program_id             =>fnd_global.conc_program_id
7007                 ,p_request_id             =>fnd_global.conc_request_id
7008                 ,p_program_update_date    =>sysdate
7009                 );
7010         if g_debug then
7011           hr_utility.set_location(l_proc, 15);
7012         end if;
7013     end loop;
7014     if g_debug then
7015       hr_utility.set_location(l_proc, 20);
7016     end if;
7017 
7018     -- need this for the new enrolment
7019 
7020     if (p_enrt_bnft_id is not NULL) then
7021         if g_debug then
7022           hr_utility.set_location(l_proc, 30);
7023         end if;
7024         ben_enrt_bnft_api.update_enrt_bnft
7025                 (p_enrt_bnft_id           => p_enrt_bnft_id
7026                 ,p_effective_date         => p_effective_date
7027                 ,p_object_version_number  => p_object_version_number
7028                 ,p_business_group_id      => p_business_group_id
7029                 ,p_prtt_enrt_rslt_id      => p_prtt_enrt_rslt_id
7030                 ,p_program_application_id => fnd_global.prog_appl_id
7031                 ,p_program_id             => fnd_global.conc_program_id
7032                 ,p_request_id             => fnd_global.conc_request_id
7033                 ,p_program_update_date    => sysdate
7034                 );
7035         if g_debug then
7036           hr_utility.set_location(l_proc, 40);
7037         end if;
7038     end if;
7039     if g_debug then
7040       hr_utility.set_location('Leaving:'||l_proc, 99);
7041     end if;
7042 END MANAGE_ENRT_BNFT;
7043 --
7044 --
7045 procedure election_information_w
7046   (p_validate               in varchar2 default 'N'
7047   ,p_elig_per_elctbl_chc_id in number
7048   ,p_prtt_enrt_rslt_id      in number
7049   ,p_effective_date         in date
7050   ,p_enrt_mthd_cd           in varchar2
7051   ,p_enrt_bnft_id           in number
7052   ,p_bnft_val               in number default null
7053   ,p_enrt_rt_id             in number default null
7054   ,p_prtt_rt_val_id         in number
7055   ,p_rt_val                 in number default null
7056   ,p_ann_rt_val             in number default null
7057   ,p_datetrack_mode         in varchar2
7058   ,p_suspend_flag           in varchar2
7059   ,p_effective_start_date   in date
7060   ,p_object_version_number  in number
7061   ,p_business_group_id      in  number
7062   ,p_enrt_rt_id2            in number default null
7063   ,p_prtt_rt_val_id2        in number
7064   ,p_rt_val2                in number default null
7065   ,p_ann_rt_val2            in number default null
7066   ,p_enrt_rt_id3            in number default null
7067   ,p_prtt_rt_val_id3        in number
7068   ,p_rt_val3                in number default null
7069   ,p_ann_rt_val3            in number default null
7070   ,p_enrt_rt_id4            in number default null
7071   ,p_prtt_rt_val_id4        in number
7072   ,p_rt_val4                in number default null
7073   ,p_ann_rt_val4            in number default null
7074   ,p_person_id              in number default null
7075   ,p_enrt_cvg_strt_dt       in date   default null
7076   ,p_enrt_cvg_thru_dt       in date   default null
7077   ,p_rt_update_mode         in varchar2 default null
7078   ,p_rt_strt_dt1            in date   default null
7079   ,p_rt_end_dt1             in date   default null
7080   ,p_rt_strt_dt_cd1         in varchar2 default null
7081   ,p_return_status          out nocopy varchar2
7082   ) is
7083 
7084   --
7085   l_effective_date       date := trunc(sysdate);
7086   l_effective_start_date date := p_effective_start_date;
7087   l_api_error            boolean;
7088   l_proc                 varchar2(60) := 'ben_election_information.election_information_w outer';
7089   l_trace_param          varchar2(30);
7090   l_trace_on             boolean;
7091 
7092   --
7093 begin
7094   l_trace_param := null;
7095   l_trace_on := false;
7096   --
7097   fnd_msg_pub.initialize;
7098 --  hr_utility.trace_on(null,'BENELINF');
7099 
7100   l_trace_param := fnd_profile.value('BEN_SS_TRACE_VALUE');
7101 
7102   --
7103   if l_trace_param = 'BENELINF' then
7104      l_trace_on := true;
7105   else
7106      l_trace_on := false;
7107   end if;
7108   --
7109   if l_trace_on then
7110     hr_utility.trace_on(null,'BENELINF');
7111   end if;
7112   --
7113   hr_utility.set_location('Entering:'||l_proc, 5);
7114   hr_utility.set_location('l_trace_param : '|| l_trace_param, 5);
7115   --
7116   if p_effective_date is not null then
7117   --  l_effective_date := to_date(p_effective_date, 'YYYY/MM/DD');
7118     l_effective_date := p_effective_date;
7119   end if;
7120   --
7121   election_information_w
7122    (p_validate               => p_validate
7123    ,p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id
7124    ,p_prtt_enrt_rslt_id      => p_prtt_enrt_rslt_id
7125    ,p_effective_date         => l_effective_date
7126    ,p_enrt_mthd_cd           => p_enrt_mthd_cd
7127    ,p_enrt_bnft_id           => p_enrt_bnft_id
7128    ,p_bnft_val               => p_bnft_val
7129    ,p_enrt_rt_id1            => p_enrt_rt_id
7130    ,p_prtt_rt_val_id1        => p_prtt_rt_val_id
7131    ,p_rt_val1                => p_rt_val
7132    ,p_ann_rt_val1            => p_ann_rt_val
7133    ,p_enrt_rt_id2            => p_enrt_rt_id2
7134    ,p_prtt_rt_val_id2        => p_prtt_rt_val_id2
7135    ,p_rt_val2                => p_rt_val2
7136    ,p_ann_rt_val2            => p_ann_rt_val2
7137    ,p_enrt_rt_id3            => p_enrt_rt_id3
7138    ,p_prtt_rt_val_id3        => p_prtt_rt_val_id3
7139    ,p_rt_val3                => p_rt_val3
7140    ,p_ann_rt_val3            => p_ann_rt_val3
7141    ,p_enrt_rt_id4            => p_enrt_rt_id4
7142    ,p_prtt_rt_val_id4        => p_prtt_rt_val_id4
7143    ,p_rt_val4                => p_rt_val4
7144    ,p_ann_rt_val4            => p_ann_rt_val4
7145    ,p_datetrack_mode         => p_datetrack_mode
7146    ,p_suspend_flag           => p_suspend_flag
7147    ,p_effective_start_date   => l_effective_start_date
7148    ,p_object_version_number  => p_object_version_number
7149    ,p_business_group_id      => p_business_group_id
7150    ,p_person_id              => p_person_id
7151    ,p_enrt_cvg_strt_dt       => p_enrt_cvg_strt_dt
7152    ,p_enrt_cvg_thru_dt       => p_enrt_cvg_thru_dt
7153    ,p_rt_update_mode         => p_rt_update_mode
7154    ,p_rt_strt_dt1            => p_rt_strt_dt1
7155    ,p_rt_end_dt1             => p_rt_end_dt1
7156    ,p_rt_strt_dt_cd1         => p_rt_strt_dt_cd1
7157    ,p_api_error              => l_api_error);
7158 
7159    IF (l_api_error)
7160     THEN
7161       p_return_status :='E';
7162    ELSE
7163       p_return_status :='S';
7164    END IF;
7165    --
7166    hr_utility.set_location('Leaving:'||l_proc, 10);
7167    --
7168    if l_trace_on then
7169      hr_utility.trace_off;
7170      l_trace_param := null;
7171      l_trace_on := false;
7172    end if;
7173 --
7174 exception
7175   --
7176   when app_exception.application_exception then	--Bug 4387247
7177     p_return_status := 'E';
7178     fnd_msg_pub.add;
7179     --Bug 4436578
7180     ben_det_enrt_rates.clear_globals;
7181     if l_trace_on then
7182       hr_utility.trace_off;
7183       l_trace_on := false;
7184       l_trace_param := null;
7185     end if;
7186   when others then
7187     p_return_status := 'E';
7188     --Bug 4387247
7189     fnd_message.set_name('PER','FFU10_GENERAL_ORACLE_ERROR');
7190     fnd_message.set_token('2',substr(sqlerrm,1,200));
7191     fnd_msg_pub.add;
7192     ben_det_enrt_rates.clear_globals;
7193     if l_trace_on then
7194       hr_utility.trace_off;
7195       l_trace_on := false;
7196       l_trace_param := null;
7197     end if;
7198 end election_information_w;
7199 --
7200 --
7201 procedure election_information_w
7202   (p_validate               in varchar2 default 'N'
7203   ,p_elig_per_elctbl_chc_id in number
7204   ,p_prtt_enrt_rslt_id      in number
7205   ,p_effective_date         in date
7206   ,p_person_id              in number default null
7207   ,p_enrt_mthd_cd           in varchar2
7208   ,p_enrt_bnft_id           in number
7209   ,p_bnft_val               in number default null
7210   ,p_enrt_rt_id1            in number default null
7211   ,p_prtt_rt_val_id1        in number default null
7212   ,p_rt_val1                in number default null
7213   ,p_ann_rt_val1            in number default null
7214   ,p_rt_strt_dt1            in date   default null
7215   ,p_rt_end_dt1             in date   default null
7216   ,p_rt_strt_dt_cd1         in varchar2 default null
7217   ,p_enrt_rt_id2            in number default null
7218   ,p_prtt_rt_val_id2        in number default null
7219   ,p_rt_val2                in number default null
7220   ,p_ann_rt_val2            in number default null
7221   ,p_rt_strt_dt2            in date   default null
7222   ,p_rt_end_dt2             in date   default null
7223   ,p_enrt_rt_id3            in number default null
7224   ,p_prtt_rt_val_id3        in number default null
7225   ,p_rt_val3                in number default null
7226   ,p_ann_rt_val3            in number default null
7227   ,p_rt_strt_dt3            in date   default null
7228   ,p_rt_end_dt3             in date   default null
7229   ,p_enrt_rt_id4            in number default null
7230   ,p_prtt_rt_val_id4        in number default null
7231   ,p_rt_val4                in number default null
7232   ,p_ann_rt_val4            in number default null
7233   ,p_rt_strt_dt4            in date   default null
7234   ,p_rt_end_dt4             in date   default null
7235   ,p_datetrack_mode         in varchar2
7236   ,p_suspend_flag           in varchar2
7237   ,p_effective_start_date   in date
7238   ,p_object_version_number  in number
7239   ,p_business_group_id      in number
7240   ,p_enrt_cvg_strt_dt       in date
7241   ,p_enrt_cvg_thru_dt       in date
7242   ,p_rt_update_mode         in varchar2 default null
7243   ,p_api_error              out nocopy boolean)
7244 is
7245   l_validate boolean := false;
7246   l_datetrack_mode   varchar2(30) := p_datetrack_mode;
7247   l_suspend_flag     varchar2(30) := p_suspend_flag;
7248   l_dpnt_actn_warning boolean;
7249   l_bnf_actn_warning  boolean;
7250   l_ctfn_actn_warning boolean;
7251   l_object_version_number number := p_object_version_number;
7252   l_prtt_enrt_rslt_id number := p_prtt_enrt_rslt_id;
7253   l_prtt_rt_val_id1   number := p_prtt_rt_val_id1;
7254   l_prtt_rt_val_id2   number := p_prtt_rt_val_id2;
7255   l_prtt_rt_val_id3   number := p_prtt_rt_val_id3;
7256   l_prtt_rt_val_id4   number;
7257   l_prtt_rt_val_id5   number;
7258   l_prtt_rt_val_id6   number;
7259   l_prtt_rt_val_id7   number;
7260   l_prtt_rt_val_id8   number;
7261   l_prtt_rt_val_id9   number;
7262   l_prtt_rt_val_id10  number;
7263   l_prtt_enrt_interim_id number;
7264   l_effective_start_date date;
7265   l_effective_end_date   date;
7266   --
7267     -- Bug 4216475
7268   -- Changing the cursor to bring up val alone for validation
7269   -- to handle cases where the default is outside the coverage
7270   -- range and the benefit val is not defined (Enterable)
7271 
7272   cursor c_bnft is
7273      select enb.val val,-- nvl(enb.val, enb.dflt_val) val, Bug 4216475
7274             enb.mn_val,
7275             enb.mx_val,
7276             enb.incrmt_val
7277      from   ben_enrt_bnft enb
7278      where  enb.enrt_bnft_id = p_enrt_bnft_id;
7279   --
7280   -- open c_pl_opt_name cursor only if error needs to be displayed.
7281   --
7282   cursor c_pl_opt_name is
7283      select pln.name || ' '|| opt.name
7284      from   ben_elig_per_elctbl_chc epe,
7285             ben_pl_f                pln,
7286             ben_oipl_f              oipl,
7287             ben_opt_f               opt
7288      where  epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
7289      and    epe.pl_id                  = pln.pl_id
7290      and    epe.oipl_id                = oipl.oipl_id(+)
7291      and    oipl.opt_id                = opt.opt_id(+)
7292      and    p_effective_date between
7293             pln.effective_start_date and pln.effective_end_date
7294      and    p_effective_date between
7295             oipl.effective_start_date(+) and oipl.effective_end_date(+)
7296      and    p_effective_date between
7297             opt.effective_start_date(+) and opt.effective_end_date(+);
7298 	--
7299 	-- 4543745
7300 	cursor c_elinf is
7301 	   select epe.crntly_enrd_flag
7302            ,epe.elctbl_flag
7303            ,epe.mndtry_flag
7304 		 from		ben_elig_per_elctbl_chc epe
7305 		 where	epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id;
7306   --
7307   l_bnft              c_bnft%rowtype;
7308 	l_elinf							c_elinf%rowtype;
7309   l_pl_opt_name       varchar2(600) := null; -- UTF8 Change Bug 2254683
7310   l_proc              varchar2(60)  := 'ben_election_information.election_information_w inner';
7311   --
7312 begin
7313   --
7314   hr_utility.set_location('Entering : '||l_proc, 10);
7315   p_api_error := false;
7316   --
7317 	-- 4543745
7318 	--
7319 	open c_elinf;
7320 	fetch c_elinf into l_elinf;
7321   close c_elinf;
7322 
7323 	if (l_elinf.crntly_enrd_flag = 'Y' and l_elinf.elctbl_flag = 'N' and l_elinf.mndtry_flag = 'N') then
7324     hr_utility.set_location('Returning without calling election_information for cannot change enrollment', 80.1);
7325 	  return;
7326 	end if;
7327 
7328   if p_validate = 'Y' then
7329     l_validate := true;
7330   end if;
7331   --
7332   if l_datetrack_mode = hr_api.g_correction then
7333     if p_effective_date = p_effective_start_date then
7334       null;
7335     else
7336       l_datetrack_mode := hr_api.g_update;
7337     end if;
7338   end if;
7339   --
7340   ben_env_object.init(p_business_group_id  => p_business_group_id,
7341                         p_effective_date     => p_effective_date,
7342                         p_thread_id          => 1,
7343                         p_chunk_size         => 1,
7344                         p_threads            => 1,
7345                         p_max_errors         => 1,
7346                         p_benefit_action_id  => null);
7347 
7348   --
7349   if p_enrt_bnft_id is not null and p_bnft_val is not null then
7350     --
7351     open c_bnft;
7352     fetch c_bnft into l_bnft;
7353     close c_bnft;
7354     --
7355     if nvl(l_bnft.val,-999) <> p_bnft_val then
7356       --
7357       --  Bug 3181158, added nvl in 'if' to handle
7358       --  'EnrtValAtEnrt + no default value' condition
7359       --
7360       if ((l_bnft.mn_val is not null and p_bnft_val < l_bnft.mn_val) or
7361           (l_bnft.mx_val is not null and p_bnft_val > l_bnft.mx_val)) then
7362         --
7363         -- Open the c_pl_opt_name cursor only if error needs to be displayed.
7364         --
7365         open  c_pl_opt_name;
7366         fetch c_pl_opt_name into l_pl_opt_name;
7367         close c_pl_opt_name;
7368         --
7369         fnd_message.set_name('BEN','BEN_92394_OUT_OF_RANGE');
7370         fnd_message.set_token('MINIMUM', l_bnft.mn_val);
7371         fnd_message.set_token('MAXIMUM', l_bnft.mx_val);
7372         fnd_message.set_token('PLAN', l_pl_opt_name);
7373         fnd_message.raise_error;
7374         --
7375       end if;
7376       --
7377       if l_bnft.mn_val is not null and
7378          l_bnft.incrmt_val is not null and
7379          mod(p_bnft_val-l_bnft.mn_val, l_bnft.incrmt_val) <> 0 then
7380         --
7381         -- Open the c_pl_opt_name cursor only if error needs to be displayed.
7382         --
7383         open  c_pl_opt_name;
7384         fetch c_pl_opt_name into l_pl_opt_name;
7385         close c_pl_opt_name;
7386         --
7387         fnd_message.set_name('BEN','BEN_92395_NOT_IN_INCR');
7388         fnd_message.set_token('INCREMENT', l_bnft.incrmt_val);
7389         fnd_message.set_token('PLAN', l_pl_opt_name);
7390         fnd_message.raise_error;
7391         --
7392       end if;
7393       --
7394     end if;
7395     --
7396   end if;
7397   --
7398 
7399  if p_prtt_rt_val_id1 is not null and
7400      p_rt_strt_dt_cd1 is not null and
7401      p_rt_strt_dt_cd1 = 'ENTRBL'        then
7402 
7403     ben_determine_rate_chg.prv_delete
7404       (p_prtt_rt_val_id     => p_prtt_rt_val_id1
7405       ,p_enrt_rt_id         => p_enrt_rt_id1
7406       ,p_rt_val             => p_rt_val1
7407       ,p_rt_strt_dt         => p_rt_strt_dt1
7408       ,p_business_group_id  => p_business_group_id
7409       ,p_prtt_enrt_rslt_id  => p_prtt_enrt_rslt_id
7410       ,p_person_id          => p_person_id
7411       ,p_effective_date     => p_effective_date
7412       ,p_mode               => p_rt_update_mode);
7413  end if;
7414  --
7415  ben_election_information.election_information
7416   (p_validate               => l_validate
7417   ,p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id
7418   ,p_prtt_enrt_rslt_id      => l_prtt_enrt_rslt_id
7419   ,p_effective_date         => p_effective_date
7420   ,p_enrt_mthd_cd           => p_enrt_mthd_cd
7421   ,p_enrt_bnft_id           => p_enrt_bnft_id
7422   ,p_bnft_val               => p_bnft_val
7423   ,p_enrt_cvg_strt_dt       => p_enrt_cvg_strt_dt
7424   ,p_enrt_cvg_thru_dt       => p_enrt_cvg_thru_dt
7425   ,p_enrt_rt_id1            => p_enrt_rt_id1
7426   ,p_prtt_rt_val_id1        => l_prtt_rt_val_id1
7427   ,p_rt_val1                => p_rt_val1
7428   ,p_ann_rt_val1            => p_ann_rt_val1
7429   ,p_rt_strt_dt1            => p_rt_strt_dt1
7430   ,p_rt_end_dt1             => p_rt_end_dt1
7431   ,p_enrt_rt_id2            => p_enrt_rt_id2
7432   ,p_prtt_rt_val_id2        => l_prtt_rt_val_id2
7433   ,p_rt_val2                => p_rt_val2
7434   ,p_ann_rt_val2            => p_ann_rt_val2
7435   ,p_rt_strt_dt2            => p_rt_strt_dt2
7436   ,p_rt_end_dt2             => p_rt_end_dt2
7437   ,p_enrt_rt_id3            => p_enrt_rt_id3
7438   ,p_prtt_rt_val_id3        => l_prtt_rt_val_id3
7439   ,p_rt_val3                => p_rt_val3
7440   ,p_ann_rt_val3            => p_ann_rt_val3
7441   ,p_rt_strt_dt3            => p_rt_strt_dt3
7442   ,p_rt_end_dt3             => p_rt_end_dt3
7443   ,p_enrt_rt_id4            => p_enrt_rt_id4
7444   ,p_prtt_rt_val_id4        => l_prtt_rt_val_id4
7445   ,p_rt_val4                => p_rt_val4
7446   ,p_ann_rt_val4            => p_ann_rt_val4
7447   ,p_rt_strt_dt4            => p_rt_strt_dt4
7448   ,p_rt_end_dt4             => p_rt_end_dt4
7449   ,p_enrt_rt_id5            => null
7450   ,p_prtt_rt_val_id5        => l_prtt_rt_val_id5
7451   ,p_rt_val5                => null
7452   ,p_ann_rt_val5            => null
7453   ,p_enrt_rt_id6            => null
7454   ,p_prtt_rt_val_id6        => l_prtt_rt_val_id6
7455   ,p_rt_val6                => null
7456   ,p_ann_rt_val6            => null
7457   ,p_enrt_rt_id7            => null
7458   ,p_prtt_rt_val_id7        => l_prtt_rt_val_id7
7459   ,p_rt_val7                => null
7460   ,p_ann_rt_val7            => null
7461   ,p_enrt_rt_id8            => null
7462   ,p_prtt_rt_val_id8        => l_prtt_rt_val_id8
7463   ,p_rt_val8                => null
7464   ,p_ann_rt_val8            => null
7465   ,p_enrt_rt_id9            => null
7466   ,p_prtt_rt_val_id9        => l_prtt_rt_val_id9
7467   ,p_rt_val9                => null
7468   ,p_ann_rt_val9            => null
7469   ,p_enrt_rt_id10           => null
7470   ,p_prtt_rt_val_id10       => l_prtt_rt_val_id10
7471   ,p_rt_val10               => null
7472   ,p_ann_rt_val10           => null
7473   ,p_datetrack_mode         => l_datetrack_mode
7474   ,p_suspend_flag           => l_suspend_flag
7475   ,p_called_from_sspnd      => 'N'
7476   ,p_effective_start_date   => l_effective_start_date
7477   ,p_effective_end_date     => l_effective_end_date
7478   ,p_object_version_number  => l_object_version_number
7479   ,p_prtt_enrt_interim_id   => l_prtt_enrt_interim_id
7480   ,p_business_group_id      => p_business_group_id
7481   ,p_pen_attribute_category =>  null
7482   ,p_pen_attribute1         =>  null
7483   ,p_pen_attribute2         =>  null
7484   ,p_pen_attribute3         =>  null
7485   ,p_pen_attribute4         =>  null
7486   ,p_pen_attribute5         =>  null
7487   ,p_pen_attribute6         =>  null
7488   ,p_pen_attribute7         =>  null
7489   ,p_pen_attribute8         =>  null
7490   ,p_pen_attribute9         =>  null
7491   ,p_pen_attribute10        =>  null
7492   ,p_pen_attribute11        =>  null
7493   ,p_pen_attribute12        =>  null
7494   ,p_pen_attribute13        =>  null
7495   ,p_pen_attribute14        =>  null
7496   ,p_pen_attribute15        =>  null
7497   ,p_pen_attribute16        =>  null
7498   ,p_pen_attribute17        =>  null
7499   ,p_pen_attribute18        =>  null
7500   ,p_pen_attribute19        =>  null
7501   ,p_pen_attribute20        =>  null
7502   ,p_pen_attribute21        =>  null
7503   ,p_pen_attribute22        =>  null
7504   ,p_pen_attribute23        =>  null
7505   ,p_pen_attribute24        =>  null
7506   ,p_pen_attribute25        =>  null
7507   ,p_pen_attribute26        =>  null
7508   ,p_pen_attribute27        =>  null
7509   ,p_pen_attribute28        =>  null
7510   ,p_pen_attribute29        =>  null
7511   ,p_pen_attribute30        =>  null
7512   ,p_dpnt_actn_warning      =>  l_dpnt_actn_warning
7513   ,p_bnf_actn_warning       =>  l_bnf_actn_warning
7514   ,p_ctfn_actn_warning      =>  l_ctfn_actn_warning);
7515 
7516   hr_utility.set_location('Leaving:'||l_proc, 20);
7517   --
7518 end election_information_w;
7519 
7520 end ben_election_information;