DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_BACK_OUT_LIFE_EVENT

Source


4 /*
1 package body ben_back_out_life_event as
2 /* $Header: benbolfe.pkb 120.59 2011/12/13 11:43:25 amnaraya noship $ */
3 --------------------------------------------------------------------------------
5 +==============================================================================+
6 |			Copyright (c) 1997 Oracle Corporation		       |
7 |			   Redwood Shores, California, USA		       |
8 |			        All rights reserved.			       |
9 +==============================================================================+
10 --
11 Name
12 	Back Out Life Event
13 Purpose
14         This package is used to back out all information that is related to
15         a particular life event.
16 History
17         Date             Who        Version    What?
18         ----             ---        -------    -----
19         07-JUN-1998      GPERRY     110.0      Created.
20                                                Waiting for element_entries
21                                                API call from TM.
22         12-JUN-1998      GPERRY     110.1      Added in Element Entries API
23                                                Call.
24         14-JUN-1998      GPERRY     110.2      Fixed type in if statement.
25         22-SEP-1998      GPERRY     115.3      Fixed error in SQL statements
26                                                where previously looking for
27                                                per_in_ler_stat_cd = 'A' now
28                                                per_in_ler_stat_cd = 'STRTD'.
29         12-OCT-1998      MAAGRAWA   115.4      Added parameter business_group_id
30                                                in calls to delete procedures
31                                                for elig_cvrd_dpnt and pl_bnf.
32         26-OCT-1998      JCARPENT   115.5      Made prv non datetracked
33         30-OCT-1998      GPERRY     115.6      Performance changes, made all
34                                                SQL statements use unions
35                                                instead of exists, that way we
36                                                can use the indexes.
37        30-Oct-1998      lmcdonal    115.7      The delete-choice api now deletes
38                                                associated ctfn, rates and bnfts
42        30-Oct-1998      lmcdonal    115.8      Remove ben_enrt_cm_prvdd logic.
39                                                so removed those deletes from here.
40                                                Also removed the join from choice
41                                                to result from the choice cursor.
43                                                We need to replace with new cm
44                                                tables.
45                                                Added multi-row parm to rslt call
46        31-Dec-98        maagrawa    115.9      Added new delete sections for
47                                                BEN_PIL_ELCTBL_CHC_POPL
48                                                BEN_PER_CM_F
49                                                    - BEN_PER_CM_PRVDD_F
50                                                    - BEN_PER_CM_TRGR_F
51                                                    - BEN_PER_CM_USG_F
52                                                BEN_BNFT_PRVDD_LDGR_F
53                                                BEN_PRMRY_CARE_PRVDR_F
54                                                Delete logic changed for
55                                                  BEN_PRTT_ENRT_RSLT_F
56                                                  BEN_ELIG_CVRD_DPNT_F
57                                                  BEN_PL_BNF_F
58                                                  BEN_PRTT_RT_VAL and
59                                                  communication tables
60                                                to use datetrack mode as future
61                                                delete if past records exist
62                                                for a different per_in_ler.
63       12-Jan-99        maagrawa   115.10       p_acty_base_rt_id removed from
64                                                delete_prtt_rt_val.
65       01-Feb-99        jcarpent   115.11       Changed update_prtt_rt_val to use
66                                                ended_per_in_ler_id.
67       09-Apr-99        jcarpent   115.12       Only communication with
68                                                to_be_sent_dt >= today deleted
69                                                removed per_cm_usg/trgr delete
70                                                since per_cm api cascade deletes
71       24-Apr-99        lmcdonal   115.13       prtt-rt-val now has a status code.
72       11-May-99        lmcdonal   115.14       1. Check status of per-in-ler before
73                                                backing it out.
74                                                2. When looking for children to
75                                                delete or backout, do not check for
76                                                per-in-ler-status of 'STRTD'.
77                                                3. Remove per-in-ler parm from
78                                                c_prv_of_previous_pil cursor.
79                                                4. We are no longer zapping results,
80                                                rates, dpnts, bnfs, actns, ctfns when
81                                                backing out a life event.  We either
82                                                mark it as 'backed out' or we leave the
83                                                data alone, if it's parent is marked
84                                                'backed out'.  Issue_97.doc.
85       25-jun-99        jcarpent   115.15       Back out bpl using pil_id.
86       08-jul-99        jcarpent   115.16       Added ben_prtt_prem, ben_elig_per,
87                                                ben_elig_per_opt.  Removed ben_epe,
88                                                bnft_prvdd_ldgr, prtt_enrt_actn,
89                                                prtt_enrt_ctfn_prvdd,cvrd_dpnt_ctfn_prvdd,
90                                                pl_bnf_ctfn_prvdd,all per_cm% tables.
91                                                Removed because of per_in_ler status checks
92       08-jul-99        pbodla     115.17       Code to backup data from ben_pl_bnf_f, BEN_PRTT_RT_VAL,
93                                                ben_prtt_prem, ben_elig_per, ben_elig_per_opt
94                                                ben_elig_cvrd_dpnt_f, ben_pil_elctbl_chc_popl,
95                                                ben_prtt_enrt_rslt_f added.
96       09-jul-99        shdas      115.18       Moved unprocess_ptnl_ler proc here from benptnle.
97       15-jul-99        jcarpent   115.19       Added calls to ben_ext_chlg.log_benefit_chg
98       24-Aug-99        maagrawa   115.20       Dependents table changes.
99       31-Aug-99        gperry     115.21       Changed call to ptnl_ler_for_per
100       22-Sep-99        pbodla     115.22       per in ler which causes this
101                                                per in ler to back out is
102                                                (bckt_per_in_ler_id) added.
103       04-Oct-99        Gperry     115.23       Added p_bckt_stat_cd to
104                                                unprocess_ptnl_ler procedure.
105       12-Oct-99        Tmathers   115.24       removed val form ben_prtt_prem_f
106       12-Oct-99        pbodla     115.25       Added code to insert link data
107                                                 between pen and epe into lcr
108                                                 table when the enrt results are
109                                                 deleted.
110       25-Oct-99        pbodla     115.26       When backing out epe data
111                                                l_epe.elig_per_elctbl_chc_id,is
112                                                passed as bkup_tbl_id
113       11-Nov-99        pbodla     115.27       When prv data written to lcr
114                                                per_in_ler_id is also written.
115       13-Nov-99        pbodla     115.28       When backing out epe data
116                                                l_epe.elig_per_elctbl_chc_id,is
117                                                passed as bkup_tbl_id
121                                                dt_api.object... function used to get
118       14-Nov-99        pbodla     115.29       When prv data is backed out, write
119                                                ecr data to backup table to restore
120                                                the ecr data when bchdt row is reinstated.
122                                                the latest object version number.
123       29-Nov-99        jcarpent   115.30     - Added person_id to call to update_prv
124       15-Dec-99        maagrawa   115.31     - Function used to fetch the
125                                                object version number for prv
126                                                record moved up, before insert
127                                                into temporary table.
128       17-Jan-00        pbodla     115.32     - Bug : 1143673(4287) changes look in the
129                                                code for further comments.
130       25-Jan-00        thayden    115.33     - Add parameters to call to ben_ext_chlg.
131       05-Feb-00        stee       115.34     - Back out cobra qualified
132                                                beneficiary. WWBUG#1178633.
133                                              - Bug 4661 : When rates are backed out
134                                                use the effective_start_date of the
135                                                enrollment result as p_effective_date.
136       16-Feb-00        stee       115.35     - Back out all cobra qualified
137                                                beneficiaries.
138       26-Feb-00        pbodla     115.36     - Bug 4785 Fixed, see comment below
139       01-MAR-00        pbodla     115.37     - Bug 4186 : Added procedure
140                                                p_backout_contact_pils to back out
141                                                the related person life events.
142       03-MAR-00        pbodla     115.38     - Bug : 4822 when past pil records's max esd
143                                                is fetched do not use the effective_date
144       04-APR-00        mmogel     115.39     - Added tokens to messages to make
145                                                the messages more meaningful to
146                                                the user
147       15-APR-00        pbodla     115.40     - Bug Reported by Fidelity :
148                                                When date track rows are deleted
149                                                by future change, this should
150                                                happen only once for a given
151                                                primary key. See example below.
152 
153 row   per_in_ler_id   enrt_rslt_id  ovn effective_start_date effective_end_date
154 
155 1     1               9             1   01/01/00             01/15/00
156 2     2               9             2   01/16/00             01/25/00
157 3     2               9             3   01/26/00             EOT
158 
159    When per in ler 2 is backed out row 1 is un end dated and rows 2 and 3
160    are deleted by using the FUTURE_CHANGE logic. When cursor like c_prtt_enrt_rslt_f
161    hits row 2, due to FUTURE_CHANGE delete on row 1, row 2 and 3 are deleted.
162    When cursor next fetches row 3, just skip the FUTURE_CHANGE delete logic.
163 
164       24-APR-00        pbodla     115.41     - Bug 5138 : c_prv_of_previous_pil
165                                                select only null status records.
166       05-JUN-00        pbodla     115.42     - Bug 5222 : Removed the effective date check.
167       19-JUN-00        pbodla     115.43     - Bug 1146792 (4285) : If a
168                                                potential for given lf_evt_ocrd_dt,
169                                                ler_id, ntfn_dt exists then
170                                                voidd the potetial associated
171                                                with the backing out per in ler.
172                                              - In other words, do not make it
173                                                unprocessed potential.
174       22-JUN-00        pbodla     115.44     - Fixed the c_ptnl_exist cursor :
175                                                used the person_id.
176       19-JUL-00        pbodla     115.45     - Bug 5372 Code which writes the link between
177                                                elig per elctbl chc and enrollment
178                                                results into ben_le_clps_n_rstr is
179                                                removed as it's no longer needed.
180       21-JUL-00        rchase     115.47     - Bug#5364
181                                                Update elig cursors in delete_routine
182                                                to use lf_evt_ocrd_dt instead
183                                                of p_effective date
184       28-JUL-00        rchase     115.48     - Bug#5364 continuation
185                                                Update the c_epo_max_esd_of_past_pil
186                                                cursor in the delete_routine
187                                                to fetch the appropriate
188                                                dates for deleting ben_elig_per_opt_f
189                                                rows
190       03-AUG-00        pbodla     115.49     - Removed the effective date usage
191                                                from the cursors -
192                                                c_ben_ELIG_PER_OPT_f,
193                                                c_epo_max_esd_of_past_pil,
194                                                c_ben_elig_per_f,
195                                                c_ben_prtt_prem_f,
196                                                c_ben_pl_bnf_f,
197                                                c_ben_prmry_care_prvdr_f
198       31-AUG-00       jcarpent    115.50       OraBug# 4988. Added logic to
202                                                l_effective_date passed is
199                       cdaniels                 skip the call to the delete
200                                                routine associated with most
201                                                of the p_routines when
203                                                not EOT.
204                                                Affect p_routines:
205                                                BEN_ELIG_CVRD_DPNT_F
206                                                BEN_ELIG_PER_F
207                                                BEN_ELIG_PER_OPT_F
208                                                BEN_PRTT_PREM_F
209                                                BEN_PL_BNF_F
210                                                BEN_PRTT_ENRT_RSLT_F
211       14-Sep-2000     jcarpent    115.51       Bug 1269016.  added bolfe
212                                                effective_date global.
213       27-SEP-2000     cdaniels    115.52     - Tar# 1090241.996. Eliminated test
214                                                for not NULL l_person_id prior to
215                                                opening cursor c_prv_of_previous_
216                                                pil. Also modified c_prv_of_
217                                                previous_pil to include join to
218                                                ben_per_in_ler to get l_person_id
219                                                based on this cursor rather than
220                                                c_ben_prtt_rt_val.
221       03-JAN-01        tilak      115.53     - Bug 1182293  reimburement reqist table added
222       09-feb-01        ikasire    115.54       Bug 1627373 and 1584238 to fix the
223                                                issue - can't backout if the
224                                                rate start date < life event occured date
225 
226       15-FEB-2001     pbodla      115.56     - Fix in 115.55 is put back in.
227                                                This is next version of 115.54
228       21-MAR-2001     kmahendr    115.57     - Bug 1690358 - for ben_prmry_care_prvdr_f delete
229                                                routine, effective_start_date of the row is sent
230                                                as effective_date
231       15-May-2001     kmahendr    115.58     - Bug#1653733 - Rate change only event is not cal-
232                                                culating prtt_rt_val if event is backed out and
233                                                reprocessed - added delete_routine for the table
234                                                ben_bnft_prvdd_ldgr_f
235       06-Jun-2001     pbodla      115.59     - Bug 1814166 : Causing primary key violation.
236                                                Commented pep, epo backup as data is not used
237                                                by benleclr.pkb
238       16-Jul-01       kmahendr    115.60     - Unrestricted life event not be backedout - added
239                                                cursor c_ler_typ
240       19-jul-01       tilak       115.61     - typo in closing the cursor c_ler_typ corrected
241       06-Nov-01       pbbodla     115.62     - bug 2097880 :Before writing into backup tables
242                                                check whether rows already exists.
243       13-Nov-01       tjesumic    115.63     - l_ecr.enrt_rt_id is intialised before the
244                                                c_ecr cursor to avoid the old data carried forward
245                                                if c_ecr fails
246      14-Dec-01        kmahendr    115.64     - initialise g_backout_flag
247      22-Jan-02        kmahendr    115.65     - Added if condition to check previous pk id
248                                                before calling delete_benefit_ledger-
249                                                bug#2194632
250      04-Mar-02        shdas       115.66     - Created self-service wrapper for
251                                                running backout life events.
252      13-Mar-02        ikasire     115.67       UTF8 Changes
253      18-May-02	      hnarayan    115.69     - Bug 2223214 - added condition in cursor c_prc
254      					       of delete_routine procedure to not consider
255      					       voided claims during backout
256      30-May-02        ikasire     115.70       Bug 2386000 Added p_called_from parameter to
257                                                delete_elig_cvrd_dpnt calll
258      22-Aug-02        ikasire     115.71       Bug 2526994 g_backout_flag needs to be reset
259      23-Aug-02	      hnarayan    115.72     - Bug 2518955 - modified delete_routine for
260      						BEN_PRTT_REIMBMT_RQST_F to show custom message
261      12-sep-02        vsethi      115.73     - Bug 2552295 to ben_plan_beneficiary_api passing
262 				    	       p_multi_row_actn as False.
263      24-Sep-02        kmahendr    115.74     -Bug2592783 - per_in_stat_cd added to cursor
264                                               c_bpl_max_esd_of_past_pil.
265      10-oct-02        tjesumic    115.75     -Bug 2546259 When the Result is future dated  and
266                                   115.76      Deenrolled, the cverd dpnd is deleted with
267                                   115,77      Delete  mode, this result into single row
268                                               with effective end date to effective date
269                                               PDP table does not have any status to track
270                                               if the LE which end date the result is backedout
271                                               the Covered Dpnt row left as it is without extending
272                                               End date to EOT. This is because the PDP row is not
276     28-oct-02         kmahendr    115.78      Bug#2646851 - cursor modified with order by clause and
273                                               date tracked and there is relation between the PIL
274                                               and end dated PDP row. To extend the Effective end
275                                               date  new cursor added in delte_rutine procedure
277                                               max function removed
278 
279     28-dec-2002       nhunur      115.79      nocopy changes.
280     31-dec-2002       pbodla      115.80      Bug 2712602 CWB : When comp per in
281                                               ler is backed out modify and
282                                               remove heirarchy data.
283     11-mar-2003       kmahendr    115.81      Bug#2821279 : Removed the max functions and logic
284                                               is based on order by clause.
285     10-mar-2003       pbodla      115.82      Bug 2695023 CWB : If pay proposal is
286                                               associated with rate remove it also.
287     20-mar-2003       ikasire     115.83      Bug 2847654 adding more hr_utility to isolate
288                                               an issue in the hrqa115m which is not replicable
289     20-mar-2003       ikasire     115.84      Bug 2847654 fix removed the use of p_effective_date
290                                               removed the hr_utility
291     16-Apr-2003       tjesumic    115.85      Bug # 2899702 manage_per_type_usage is called while
292                                               deleting result to delete the parttn usage
293     24-Jun-2003       tjesumic    115,86      c_futur_del_dpnt cursor is closed
294     28-Aug-2003       tjesumic    115.87      bug # 3086161 whne the open LE reprocessed on the same day of
295                                               the previous LE process date. the previous LE result are
296                                               updated with open per in ler id. if the open LE is backedout
297                                               then the result of  previous LE are lost. this is
298                                               fixed by copying the result of  LE to backop table and copy
299                                               back to result when the opne is backed out
300                                               New three cursor created for copying back result , dpnt and bnf
301     03-Sep-2003       rpgupta     115.88      3136058 Grade Step Backout
302     26-Sep-2003       kmahendr    115.89      Modified cursor c_ben_prtt_rt_val for GHR fix
303     29-Oct-2003       tjesumic    115.90      #  2982606 Result level backup added, new parameter
304                                               p_bckdt_prtt_enrt_rslt_id added for the purpose. if the param is not null
305                                               only the result of the p_bckdt_prtt_enrt_rslt_id is backed out
306                                               if the per_in_ler careated the result level backout then
307                                               backing out the per inler reinstate the result
308                                               realted chagnes in bendenrr , benelinf ,benleclr
309    30-Oct-2003        tjesumic    115.91      fix of 3086161 not allowing to reinstate the per in ler id which
310                                               created the corrected result, this results are required to
311                                               restore the corrected per_in_ler_id. # 3175382 fix allows to
312                                               created the result into backout table but not allows to be deleted
313                                               new cursor c_corr_rslt_esist creted
314     03-Sep-2003       rpgupta     115.92      CWBGLOBAL : CWB Global backout changes
315     20-Feb-2004       kmahendr    115.94      Bug#3442729 - cursor c_ppe_max_esd_of_past_pi
316                                               modified and l_effective_date initialised
317     09-Mar-2004       ikasire     115.95      Bug 3495372 We can have multiple tables with coverage
318                                               restrictions when there is an interim with the
319                                               same comp object. This happens when the coverage is
320                                               enter value at enrollment.
321     15-Mar-2004       ikasire     115.96      Bug 3507554 performance changes
322     04-Apr-2004       ikasire     115.97      Bug 3550789 Added two new procedures
323                                               restore_prev_pep and restore_prev_epo
324     21-Apr-2004       ikasire     115.98      Bug 3550789 Added datetrack mode for PEP and EPO
325                                               corrections. also two more missing paramaters in the
326                                               PEP and EPO calls
327     23-May-2004       ikasire     115.99      CWBGLOBAL changes should not go into
328                                               2004 july FP and 11.5.10 so, CWBGLOBAL
329                                               changes are commented.
330     21 Jun 2004       kmahendr    115.100     Bug#3702033 - when backed out result is
331                                               corrected with previous per in ler, the row in
332                                               ben_le_cl_n_rstr updated
333     29 Jun 2004       ikasire     115.101     Bug3709516 we are zaping ben_prmry_care_prvdr_f
334                                               commented the delete_routine for this as we
335                                               need to reinstate them.
336     15 Jul 2004       kmahendr    115.102     Bug#3702090 - added exists condition for
337                                               c_ben_bnft_prvdd_ldgr_f
338     16 Aug 2004       pbodla      115.103     IREC : Avoid backing out contact pils
339                                               iRec mode p_backout_contact_pils
340     25 Aug 2004       pbodla      115.104     CFW : 2534391 :NEED TO LEAVE ACTION
341                                               ITEMS CERTIFICATIONS on subsequent
345     31 Aug 2004       pbodla      115.106     CFW : sspnd_flag is fetched from
342                                               events
343     30 Aug 2004       pbodla      115.105     CFW : modified cursor c_get_past_pil
344                                               not to consider backed out event
346                                               old result.
347     02 Sep 2004       pbodla      115.107     CFW : Removed usage of
348                                               l_sspnd_flag
349     16 Sep 2004       mmudigon    115.108     Bug fix 3859152
350     30-Sep-2004       hmani       115.109     If iRec then backout to VOIDD
351     30-Nov-2004       kmahendr    115.110     Bug#3964234 - Modified cursor
352                                               c_BEN_LE_CLSN_N_RSTR_corr
353     20-Dec-2004       tjesumic    115.111     cursor  c_BEN_LE_CLSN_N_RSTR_dpnt modifued to
354                                               use table instead of view
355     08-Feb-2005       tjesumic    115.112     copy_oly parameter added to copy the date to backup table
356                                               #4118315
357     15-Feb-2005       kmahendr    115.113     Bug#4172989 - multi_row_actn parameter added
358                                               to delete_elig_cvrd_dpnt
359     16-Feb-2005       mmudigon    115.114     Bug 4157759. Changes to
360                                               cursor c_prv_of_previous_pil
361     09-Mar-2005       kmahendr    115.115     Bug#4206567 - rate update is called only
362                                               if result exists
363     28-mar-2005       ikasire     115.116     Bug 4241413
364     23-Aug-2005       pbodla      115.117     Bug 4396096 - Many delete procedures
365                                               are not relevant for CWB and GSP
366                                               life events.
367     31-Aug-2005       ikasire     115.118     BUG 4558512 need to process the completed action items
368                                               properly in the reinstate
369     15-Sep-2005       kmahendr    115.119     Bug#4597122 - modified cursor c_get
370                                               _contact_pils to use lf_evt_ocrd_dt
371     22-Sep-2005       kmahendr    115.120     Bug#4597122 - modified cursor c_ler_typ
372                                               to use lf_evt_ocrd_dt
373     30-sep-05         ssarkar     115.121    Bug : 4615207 - Mulitple Rate chk to be performed only for GHR
374     06-Oct-2005       abparekh    115.123     Bug 4642315 : In procedure UNPROCESS_SUSP_ENRT_PAST_PIL,
375                                                             while deleting PEA, call API only once for
376                                                             every PEA_Id
377     06-Oct-2005       stee        115.124     Bug Bug#4486609 - Back up the quald_bnf_flag
378                                               and inelg_rsn_cd for BEN_CBR_QUALD_BNF.  Also,
379                                               set the quald_bnf_flag = 'Y' and inelg_rsn_cd
380                                               to null when an event is backed out.
381    07-oct-05         ssarkar     115.125     bug: 4615207 - Mulitple Rate chk to be performed only for GHR
382    02-Jan-2006       abparekh    115.126     Bug 4919951 : Reset G_BACKOUT_FLAG in case of any exception
383    10-Feb-2006       kmahendr    115.127     Bug#5032364-added delete_enrollment
384                                              to ben_prtt_enrt_rslt_F delete routine
385    28-Feb-2006       kmahendr    115.128     Added cursor c_BEN_LE_CLSN_N_RSTR_del
386    08-mar-2006       nhunur      115.129     skip pep, epo for cwb global backout.
387    11-Apr-2006       rbingi      115.130     5148936: Added order by to cursor c_actn_item_for_past_pil
388    27-apr-06         ssarkar     115.131     5187145 : added sub_query to cursor c_actn_item_for_past_pil
389    06-Sep-2006       abparekh    115.132     Bug 5500864 : Added code for reinstatement of BPL records
390    29-Sep-2006       kmahendr    115.133     Added Adj_prv_rate for Fidelity Enh
391    08-Nov-2006       ssarkar     115.134     bug 5649636 c_pbn_max_esd_of_past_pil is modified
392    28-Nov-2006       gsehgal     115.135     bug 5668052 deleting person type usage for beneficiary
393    23-feb-2007       ssarkar     115.136     bug 5895645 typo fix for c_pbn_max_esd_of_past_pil
394    	                                         and dependent when back out life event
395    09-May-2007       swjain      115.137     Bug 6034585: Updated procedure delete_routine -
396                                              p_routine = 'BEN_PRTT_ENRT_RSLT_F'
397    11-May-2007       ikasired    115.138     Bug 5985777 Added new procedure to reinstate the
398                                              completed actions items from the last life event.
399    26-Jun-2007       mkommuri    115.139     Bug6152593 updated cursor
400                                              c_pep_max_esd_of_past_pil
401    16-Jul-2007       sshetty     115.140     Bug 6216828, Added a cursor to
402                                              fetch future dated LE.
403    26-Jul-2007       sshetty     115.141     Bug 6216828, Fixed status code
404                                              issue in enrollment results table
405    04-Sep-2007       swjain      115.142     Bug 6376239 : Made changes in delete_routine for
406                                              p_routine = 'BEN_BNFT_PRVDD_LDGR_F'
407    07-Dec-2007       rtagarra    115.143     Bug 6489602 :Modified the cursor c_BEN_LE_CLSN_N_RSTR_corr.
408    22-Feb-2008       rtagarra    115.144     6840074
409    29-feb-2008       bachakra    115.146     Bug 6620291: Modified Cursor get_contacts_pils.
410    03-mar-2008       bachakra    115.147     Bug 6632568: Modified Cursor c_corr_result_exist
411                                              so that when _corr result exisits for previous pil,
412 					     current pil pen records get backed out correctly.
413 
414    18-mar-2008       bachakra    115.148     Bug 6882159: Added order by clause in cursor
415                                              get_fut_dtd_cntct_pils, to ensure the backing out
416 					     of life events in correct order.
420 					     the enrollments were corrected by the next pil. On top of bug 6903766
417    17-Jun-2008       bachakra    115.154     Bug 7137371: Enrollment method code are not updated corectly
418                                                           from the backup table where a correction result exists.
419    19-Jun-2008       bachakra    115.155     Bug 7039025: Insert a correction row before updation as if,
421 					     where enrollments were not getting restored if an intervening life
422 					     event did not offer electability to a plan type enrolled in the
423 					     previous life event.
424    16-jul-2008       bachakra                Bug 7176884: after corrected rows are rstored for backing
425                                              out subsequent life event, they are updated instead of deleting.
426                                              Removed a part of 6034585 fix for this.
427    24-jul-2008       bachakra                Bug 7206471: Added Adj_pen_cvg to handle overlapping coverages.
428    06-oct-2008       sallumwa    115.156     Bug 7133998:Handled Backout process for premium records.
429    15-oct-2008       stee        115.157     Bug 7197868: If there is a correction and an update
430                                              to the enrollment results, delete future dated rows.
431    16-Feb-2009       velvanop    115.158     Bug 8234902: When the certification is received, a new rate is created and
432                                              existing rates for current life event get ended by same life event.
433                                              Hence while backing out the life event these ended rates are reopened
434 					     till EOT causing valid rates to be tied to backed out event.
435    19-Feb-2009       stee        115.159     Bug 8199189:  When correction rows are updated, also update
436    21-Mar-2009       stee        115.160     Bug 8199189:  Remove the per_in_ler_id and prtt_enrt_rslt_stat_cd
437                                                            from c_get_cvg_thru_dt.
438    11-May-2009       velvanop    115.161     Bug 8495014:  Potential life  event on the dependent is voided when a life event is
439                                              processed on the participant on a date prior to the dependent's potential
440 					     life event occurred date.
441    25-May-2009       velvanop    115.162     Bug 8507247: Fixes done on top of Bug 7206471
442    17-Aug-2009       velvanop    115.163     Bug 8604243: When a lifeevent is being backed out and the previous LE
443                                              does not have electability and there are no enrollment results for the
444 					     previous LE, enrollments results of the LE for which enrollments are ended should
445 					     be reopened. In this case previous LE status will not be updated to 'STARTED' status and then
446 					     FORCE close the LE.
447    11-Nov-2009       velvanop    115.165     Bug 9095753: APP-PAY-07187 error when backing out the Life Event.
448                                              Fixed cursor c_future_pen to check whether future enrolments exists for
449 					     previous Life Event.
450    18-Nov-2009       velvanop    115.166     Bug 8984394: Update the prtt_enrt_rslt_id on epe_id of previous pil epe's
451                                              when results of previous pil are reopened after backing out the LE
452    08-Jan-2010       velvanop    115.167     Bug 9236429: Update the prtt_enrt_rslt_id on the epe table for the previous Life Event
453                                              when the present life event is backedout
454    30-Mar-2010       stee        115.168     Bug 8896851:  Get the prtt_rt_val from the backup table.
455    05-Jul-2010       velvanop    115.169     Bug 9664943:  While adjusting the coverage on backing out a Life Event,
456                                              check whether the the effective_start_date is not null before adjusting coverage
457    21-Sep-2010       sagnanas    115.170     Bug 10024680: While getting prv from backup table, order by pen_id, rt_strt_dt and then abr_id
458    14-Oct-2010       velvanop    115.171     Bug 9580432: New procedure created to update the epe table with the prtt_enrt_rslt_id of
459                                              the reopened result when a LE is backed out. When a LE is backedout, epe record of the
460                                              previous LE should be updated with the prtt_enrt_rslt_id of the reopened result
461    03-Aug-2011       velvanop    115.172     Bug 12576710: Adjust coverage/rate if there exists adjustment records in the backup table for the records
462                                              that are ended by the backedout per_in_ler_id
463    18-Oct-2011       velvanop    115.173     Bug 12963718:When backout package is called for backing out a single enrollment result(ie p_bckdt_prtt_enrt_rslt_id
464                                              will not be NULL), do not call delete enrollment for backup records that exists in the backup table
465    25-Oct-2011       velvanop    115.174	     Bug 13050813: Added below 'if' condition.When backout package is called for backing out a single enrollment result(ie p_bckdt_prtt_enrt_rslt_id
466                                              will not be NULL), do not adjust the coverage's for the pen records in backup table(_ADJ records)
467    22-Dec-2011		 amnaraya	 115.175	 Bug 12732878: Changed code to restore the elig_per_f and elig_per_opt_f records from back up table
468 
469    */
470 ----------------------------------------------------------------------------------------------------------
471 --
472 g_package varchar2(80) := 'ben_back_out_life_event';
473 
474 --Start AMN bug 12732878
475 /*Added a global record to keep track of the old elig_per_id to new elig_per_id mapping.
476 This is used while creating elig_per_opt_f record.*/
477 type g_eper_old_new_rec is record
478 (
479 	old_elig_per_id	ben_elig_per_f.elig_per_id%TYPE,
480 	new_elig_per_id ben_elig_per_f.elig_per_id%TYPE
481 );
482 type g_eper_old_new_tbl is table of g_eper_old_new_rec;
483 g_eper_map_rec g_eper_old_new_tbl := g_eper_old_new_tbl();
484 g_epe_map_count number := 0;
485 function get_new_elig_per_id(old_elig_per_id in number) return number is
486 begin
487 	for i in 1..g_eper_map_rec.count loop
491 	end loop;
488 		if g_eper_map_rec(i).old_elig_per_id = old_elig_per_id then
489 			return g_eper_map_rec(i).new_elig_per_id;
490 		end if;
492 	return -1;
493 end;
494 --End AMN bug 12732878
495 /*Bug 9580432: New procedure created to update the epe table with the prtt_enrt_rslt_id of
496 the reopened result when a LE is backed out. When a LE is backedout, epe record of the
497 previous LE should be updated with the prtt_enrt_rslt_id of the reopened result*/
498 procedure update_epe(p_prtt_enrt_rslt_id number,
499                      p_effective_date date,p_per_in_ler_id number ) is
500 cursor c_get_pil_id(c_prtt_enrt_rslt_id number) is
501   select pen.per_in_ler_id,
502          epe.elig_per_elctbl_chc_id,
503 	 epe.object_version_number,
504 	 epe.prtt_enrt_rslt_id
505     from
506          ben_prtt_enrt_rslt_f pen,
507 	 ben_per_in_ler pil,
508 	 ben_elig_per_elctbl_chc epe
509   where pen.prtt_enrt_rslt_id  = c_prtt_enrt_rslt_id
510        and pen.effective_end_date = hr_api.g_eot
511        and pen.enrt_cvg_thru_dt = hr_api.g_eot
512        and pen.prtt_enrt_rslt_stat_cd is null
513        and pen.per_in_ler_id = pil.per_in_ler_id
514        and pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT')
515        and epe.per_in_ler_id = pil.per_in_ler_id
516        and nvl(epe.pgm_id,-1) = nvl(pen.pgm_id,-1)
517        and epe.pl_id = pen.pl_id
518        and epe.pl_typ_id = pen.pl_typ_id
519        and nvl(epe.oipl_id,-1) = nvl(pen.oipl_id,-1);
520 
521   l_upd_epe c_get_pil_id%rowtype;
522 
523   cursor c_prev_pil_id  is
524   select per_in_ler_id
525     from ben_per_in_ler pil,
526          ben_ler_f ler
527    where pil.per_in_ler_id <> p_per_in_ler_id
528      and pil.per_in_ler_stat_cd not in  ('VOIDD','BCKDT')
529      and pil.person_id  =  (select person_id from ben_per_in_ler where
530                              per_in_ler_id = p_per_in_ler_id)
531      and pil.ler_id = ler.ler_id
532      and ler.typ_cd not in ('COMP', 'ABS', 'GSP', 'IREC')
533      and p_effective_date between ler.effective_start_date and ler.effective_end_date
534      order by lf_evt_ocrd_dt desc ;
535 
536  l_prev_pil_id number;
537 begin
538 hr_utility.set_location( 'Entering ben_back_out_life_event.update_epe', 1999 );
539 hr_utility.set_location( 'p_prtt_enrt_rslt_id '||p_prtt_enrt_rslt_id, 1999 );
540 hr_utility.set_location( 'p_effective_date'||p_effective_date, 1999 );
541       open c_get_pil_id(p_prtt_enrt_rslt_id);
542 		  fetch  c_get_pil_id into l_upd_epe;
543        if(c_get_pil_id%found) then
544 		          hr_utility.set_location( 'epe found ', 1999 );
545 		          open c_prev_pil_id;
546 						  fetch c_prev_pil_id into l_prev_pil_id;
547 						  close c_prev_pil_id;
548 						  hr_utility.set_location( 'l_prev_pil_id '||l_prev_pil_id, 1999 );
549 						  hr_utility.set_location( 'l_upd_epe.per_in_ler_id '||l_upd_epe.per_in_ler_id, 1999 );
550 						  hr_utility.set_location( 'l_upd_epe.prtt_enrt_rslt_id '||l_upd_epe.prtt_enrt_rslt_id, 1999 );
551 						  if(l_prev_pil_id <> l_upd_epe.per_in_ler_id and l_upd_epe.prtt_enrt_rslt_id is NULL) then
552 							  hr_utility.set_location( 'l_pil_id '||l_upd_epe.per_in_ler_id,101);
553 							  hr_utility.set_location( 'l_epe_id '||l_upd_epe.elig_per_elctbl_chc_id,101);
554 							  hr_utility.set_location( 'l_epe_ovn '||l_upd_epe.object_version_number,101);
555 
556 							  ben_ELIG_PER_ELC_CHC_api.update_ELIG_PER_ELC_CHC
557 									(p_validate                => FALSE
558 									 ,p_elig_per_elctbl_chc_id  => l_upd_epe.elig_per_elctbl_chc_id
559 									 ,p_prtt_enrt_rslt_id       => p_prtt_enrt_rslt_id
560 									 ,p_object_version_number   => l_upd_epe.object_version_number
561 									 ,p_effective_date          => p_effective_date
562 									 );
563 						   elsif(l_prev_pil_id = l_upd_epe.per_in_ler_id and l_upd_epe.prtt_enrt_rslt_id is null) then
564 							  hr_utility.set_location( 'l_pil_id '||l_upd_epe.per_in_ler_id,102);
565 							  hr_utility.set_location( 'l_epe_id '||l_upd_epe.elig_per_elctbl_chc_id,102);
566 							  hr_utility.set_location( 'l_epe_ovn '||l_upd_epe.object_version_number,102);
567 
568 							  ben_ELIG_PER_ELC_CHC_api.update_ELIG_PER_ELC_CHC
569 									(p_validate                => FALSE
570 									 ,p_elig_per_elctbl_chc_id  => l_upd_epe.elig_per_elctbl_chc_id
571 									 ,p_prtt_enrt_rslt_id       => p_prtt_enrt_rslt_id
572 									 ,p_object_version_number   => l_upd_epe.object_version_number
573 									 ,p_effective_date          => p_effective_date
574 									 );
575 
576 						end if;
577 		 end if;
578 		 close c_get_pil_id;
579 exception
580 when others then
581   raise;
582 end update_epe;
583 
584 procedure p_backout_contact_pils(p_person_id          in number,
585                                  p_business_group_id  in number,
586                                  p_per_in_ler_id      in number,
587                                  p_bckt_stat_cd       in varchar2,
588                                  p_csd_by_ptnl_ler_for_per_id in number,
589                                  p_effective_date     in date) is
590   --
591   cursor get_contacts_pils(cv_person_id in number,
592                            cv_csd_by_ptnl_ler_for_per_id in number) is
593   select pil.*
594   from per_contact_relationships pcr,
595        ben_per_in_ler pil,
596        ben_PTNL_LER_FOR_PER ppl
597   where --pcr.contact_person_id   = cv_person_id
598         pcr.person_id   = cv_person_id -- Bug 6620291
599     and pcr.business_group_id   = p_business_group_id
600     and pil.lf_evt_ocrd_dt between nvl(pcr.date_start,pil.lf_evt_ocrd_dt)
601                              and nvl(pcr.date_end,pil.lf_evt_ocrd_dt)
602     and pcr.personal_flag       = 'Y'
603     --and pil.person_id           = pcr.person_id
604     and pil.person_id           = pcr.contact_person_id -- Bug 6620291
605     and pil.per_in_ler_stat_cd in ('STRTD', 'PROCD')
609   --
606     and pil.ptnl_ler_for_per_id = ppl.ptnl_ler_for_per_id
607     and ppl.ptnl_ler_for_per_src_cd in ('SYSGND')
608     and ppl.csd_by_ptnl_ler_for_per_id = cv_csd_by_ptnl_ler_for_per_id;
610 
611 -- Bug:6216828 This cursor is added for fidelity bug where the future date
612 --Life event for the contacts are checked and backed out
613 --when the participant's life event that triggered temporal life event
614 --for the contacts and participant's LE is backed out.
615 
616    cursor get_fut_dtd_cntct_pils(cv_person_id in number
617                            ) is
618    select pil.*
619   from per_contact_relationships pcr,
620        ben_per_in_ler pil,
621        ben_PTNL_LER_FOR_PER ppl
622   where pcr.contact_person_id   = cv_person_id
623     and pcr.business_group_id   = p_business_group_id
624     and pil.lf_evt_ocrd_dt > (Select pil1.lf_evt_ocrd_dt
625                                  from ben_per_in_ler pil1
626                                 where pil1.per_in_ler_id= p_per_in_ler_id)
627     and pcr.personal_flag       = 'Y'
628     and pil.person_id           = pcr.person_id
629     and pil.per_in_ler_stat_cd in ('STRTD', 'PROCD')
630     and pil.ptnl_ler_for_per_id = ppl.ptnl_ler_for_per_id
631   order by pil.lf_evt_ocrd_dt desc; -- Bug 6882159
632 
633   cursor get_contacts_ptnls(cv_person_id in number,
634                             cv_csd_by_ptnl_ler_for_per_id in number) is
635   select con_ppl.*
636   from ben_ptnl_ler_for_per con_ppl,
637        per_contact_relationships pcr
638   where con_ppl.csd_by_ptnl_ler_for_per_id = cv_csd_by_ptnl_ler_for_per_id
639     and con_ppl.PERSON_ID       =  pcr.person_id
640     and con_ppl.ptnl_ler_for_per_src_cd in ('SYSGND')
641     and pcr.contact_person_id   = p_person_id;
642   --
643   l_ptnls_procd boolean;
644   l_le_evt_ocrd_dt date;
645   l_proc        varchar2(72) := g_package||'p_backout_contact_pils';
646   --
647 begin
648   --
649   hr_utility.set_location('Entering:'|| l_proc, 10);
650   hr_utility.set_location('p_bckt_stat_cd:'|| p_bckt_stat_cd, 10);
651   hr_utility.set_location('p_csd_by_ptnl_ler_for_per_id:'|| p_csd_by_ptnl_ler_for_per_id, 10);
652   --
653   -- First check any potentials of detected or unprocessed
654   -- exists. then void them.
655   --
656   for l_con_ptnls_rec in get_contacts_ptnls(p_person_id, p_csd_by_ptnl_ler_for_per_id)
657   loop
658       --
659       if l_con_ptnls_rec.ptnl_ler_for_per_stat_cd in ('UNPROCD', 'DTCTD') then
660          --
661          -- Give messages idicating related potentials are voided
662          -- due to back out of pil which created them.
663          --
664 	 hr_utility.set_location(' In VOIDD loop '|| l_con_ptnls_rec.ptnl_ler_for_per_id, 10);
665 	 /*Bug 8495014: Potential LE's triggered on the dependent should not be backedout to VOID'ed state
666 	  while backing out the LifeEvent the on the Pariticipant.
667 	  Commented the call to 'update_ptnl_ler_for_per_perf' */
668 
669 	 /*ben_ptnl_ler_for_per_api.update_ptnl_ler_for_per_perf
670           (p_validate                 => false
671           ,p_ptnl_ler_for_per_id      => l_con_ptnls_rec.ptnl_ler_for_per_id
672           ,p_ptnl_ler_for_per_stat_cd => 'VOIDD'
673           ,p_object_version_number    => l_con_ptnls_rec.object_version_number
674           ,p_effective_date           => p_effective_date
675           ,p_program_application_id   => fnd_global.prog_appl_id
676           ,p_program_id               => fnd_global.conc_program_id
677           ,p_request_id               => fnd_global.conc_request_id
678           ,p_program_update_date      => sysdate
679           ,p_voidd_dt                 => p_effective_date);
680          --
681          -- write log message indicating related person potentials are
682          -- are voided.
683          --
684          fnd_message.set_name('BEN','BEN_92507_CON_PTNLS_VOIDD');
685          benutils.write(p_text => fnd_message.get);*/
686          --
687       elsif l_con_ptnls_rec.ptnl_ler_for_per_stat_cd in
688                               ('VOIDD',  'MNL', 'BCKDT', 'MNLO')
689          then
690          --
691          -- Give messages idicating related potentials are already voided
692          -- It may be due to collapse of LE for contact or time out or
693          -- used explicitly set it to void.
694          -- so manual interpretation required to deal with them.
695          --
696          -- write log message indicating some of the related person potentials are
697          -- are already set to voided or manual or manual override or backed out.
698          --
699          fnd_message.set_name('BEN','BEN_92508_CON_PTNLS_VMBMO');
700          benutils.write(p_text => fnd_message.get);
701          --
702       elsif l_con_ptnls_rec.ptnl_ler_for_per_stat_cd = 'PROCD'
703          then
704          --
705          l_ptnls_procd := TRUE;
706          --
707       end if;
708       --
709   end loop;
710   --
711   -- Now check any pils exists, if so back out them.
712   --
713   if l_ptnls_procd then
714      --
715      --Bug 6216828 change made by sshetty
716 
717      for l_fut_dtd_cntct_pils_rec in get_fut_dtd_cntct_pils
718                                     (p_person_id)
719      loop
720       ben_back_out_life_event.back_out_life_events
721         (p_per_in_ler_id         => l_fut_dtd_cntct_pils_rec.per_in_ler_id,
722          p_bckt_per_in_ler_id    => p_per_in_ler_id,
723          p_bckt_stat_cd          => p_bckt_stat_cd,
724          p_business_group_id     => p_business_group_id,
725          p_effective_date        => p_effective_date);
726       end loop;
727 
728      for l_contacts_pils_rec in  get_contacts_pils(p_person_id, p_csd_by_ptnl_ler_for_per_id)
729      loop
730         --
731         ben_back_out_life_event.back_out_life_events
735          p_business_group_id     => p_business_group_id,
732         (p_per_in_ler_id         => l_contacts_pils_rec.per_in_ler_id,
733          p_bckt_per_in_ler_id    => p_per_in_ler_id,
734          p_bckt_stat_cd          => p_bckt_stat_cd,
736          p_effective_date        => p_effective_date);
737         --
738         -- write log message indicating some of the related person
739         -- per in lers are backed out.
740         --
741         fnd_message.set_name('BEN','BEN_92509_CON_PILS_VOIDD');
742         benutils.write(p_text => fnd_message.get);
743         --
744      end loop;
745 
746 
747      --
748   end if;
749   --
750   hr_utility.set_location('Leaving:'|| l_proc, 10);
751   --
752 end p_backout_contact_pils;
753 --
754 -- ----------------------------------------------------------------------------
755 -- |------------------------< unprocess_ptnl_ler >-----------------------------|
756 -- ----------------------------------------------------------------------------
757 procedure unprocess_ptnl_ler(p_per_in_ler in  out nocopy BEN_PER_IN_LER%ROWTYPE
758                             ,p_bckt_stat_cd   in varchar2
759                             ,p_effective_date in date) is
760   --
761   l_proc varchar2(72) := g_package||'unprocess_ptnl_ler';
762   --
763   l_mnl_dt     date;
764   l_unprocd_dt date;
765   l_voidd_dt   date;
766   l_object_version_number number;
767   --
768   cursor c_ptnl is
769      select ppl.*
770      from   ben_ptnl_ler_for_per ppl
771      where  ppl.ptnl_ler_for_per_id = p_per_in_ler.ptnl_ler_for_per_id
772      and    ppl.business_group_id = p_per_in_ler.business_group_id;
773   --
774   l_procd_ppl_rec c_ptnl%rowtype;
775   --
776   -- Bug 1146792 (4285) : If a potential for given
777   -- lf_evt_ocrd_dt, ler_id, ntfn_dt exists then voidd the
778   -- potetial associated with the backing out per in ler.
779   -- In other words, do not make it unprocessed potential.
780   --
781   cursor c_ptnl_exist(cv_lf_evt_ocrd_dt date,
782                       cv_business_group_id number,
783                       cv_ler_id number,
784                       cv_ntfn_dt date,
785                       cv_procd_ptnl_ler_for_per_id number)
786   is
787      select ppl.*
788      from   ben_ptnl_ler_for_per ppl
789      where  ppl.lf_evt_ocrd_dt = cv_lf_evt_ocrd_dt
790        and  ppl.business_group_id = cv_business_group_id
791        and  ppl.ler_id = cv_ler_id
792        and  ppl.ptnl_ler_for_per_id <> cv_procd_ptnl_ler_for_per_id
793        and  ppl.person_id = p_per_in_ler.person_id
794        -- and  nvl(ppl.ntfn_dt, trunc(sysdate)) = nvl(cv_ntfn_dt, trunc(sysdate))
795        and  ppl.PTNL_LER_FOR_PER_STAT_CD in ('DTCTD', 'UNPROCD', 'MNL', 'MNLO');
796   --
797   l_existing_ppl_rec c_ptnl_exist%rowtype;
798   l_bckt_stat_cd hr_lookups.lookup_code%TYPE  := p_bckt_stat_cd; --UTF8
799   --
800 begin
801   --
802   hr_utility.set_location('Entering:'|| l_proc, 10);
803   --
804   l_unprocd_dt := trunc(sysdate);
805   --
806   open  c_ptnl;
807     --
808     fetch c_ptnl into l_procd_ppl_rec;
809     --
810   close c_ptnl;
811   --
812   open c_ptnl_exist(l_procd_ppl_rec.lf_evt_ocrd_dt,
813                     l_procd_ppl_rec.business_group_id,
814                     l_procd_ppl_rec.ler_id,
815                     l_procd_ppl_rec.ntfn_dt,
816                     l_procd_ppl_rec.ptnl_ler_for_per_id);
817   fetch c_ptnl_exist into l_existing_ppl_rec;
818   --
819   if c_ptnl_exist%found then
820      --
821      -- A similar potential already exists, so just
822      -- void the current potential, instead of making it
823      -- into unprocessed.
824      --
825      hr_utility.set_location('Changing status to VOIDD as a potential ' ||
826                              'already exists',10);
827      l_bckt_stat_cd := 'VOIDD';
828      --
829   end if;
830   close c_ptnl_exist;
831   --
832 
833   if l_bckt_stat_cd = 'UNPROCD' then
834     --
835     l_unprocd_dt := p_effective_date;
836     --
837   elsif l_bckt_stat_cd = 'VOIDD' then
838     --
839     l_voidd_dt := p_effective_date;
840     --
841   elsif l_bckt_stat_cd = 'MNL' then
842     --
843     l_mnl_dt := p_effective_date;
844     --
845   end if;
846   --
847   hr_utility.set_location('Setting status to '||l_bckt_stat_cd,10);
848   ben_ptnl_ler_for_per_api.update_ptnl_ler_for_per
849     (p_validate                 => false
850     ,p_ptnl_ler_for_per_id      => p_per_in_ler.ptnl_ler_for_per_id
851     ,p_ptnl_ler_for_per_stat_cd => l_bckt_stat_cd
852     ,p_object_version_number    => l_procd_ppl_rec.object_version_number
853     ,p_effective_date           => p_effective_date
854     ,p_program_application_id   => fnd_global.prog_appl_id
855     ,p_program_id               => fnd_global.conc_program_id
856     ,p_request_id               => fnd_global.conc_request_id
857     ,p_program_update_date      => sysdate
858     ,p_unprocd_dt               => l_unprocd_dt
859     ,p_voidd_dt                 => l_voidd_dt
860     ,p_mnl_dt                   => l_mnl_dt);
861   --
862   hr_utility.set_location('Leaving:'|| l_proc, 90);
863   --
864 end unprocess_ptnl_ler;
865 --
866 
867 --
868 procedure restore_prev_pep
869   (p_per_in_ler_id in number
870   ) is
871     --
872     l_proc varchar2(72) := g_package||'restore_prev_pep';
873     --
874     cursor c_restore_pep( p_pil_id number ) IS
875       select *
879     --
876         from ben_le_clsn_n_rstr elig
877        where elig.per_in_ler_ended_id = p_pil_id
878          and elig.BKUP_TBL_TYP_CD = 'BEN_ELIG_PER_F_CORRECT' ;
880     cursor c_pep(p_elig_per_id number,p_effective_date date) IS
881       select object_version_number
882         from ben_elig_per_f pep
883        where pep.elig_per_id = p_elig_per_id
884          and p_effective_date between pep.effective_start_date
885                                   and pep.effective_end_date ;
886     --
887     l_effective_date date ;
888     l_correction                boolean;
889     l_update                    boolean;
890     l_update_override           boolean;
891     l_update_change_insert      boolean;
892     l_datetrack_mode            varchar2(100);
893     --
894 	--Start AMN bug 12732878
895 	l_elig_per_id				ben_elig_per_f.elig_per_id%TYPE;
896 	l_effective_start_date		date;
897 	l_effective_end_date		date;
898 	l_object_version_number		ben_elig_per_f.object_version_number%type;
899 	--End AMN bug 12732878
900   begin
901     --
902     hr_utility.set_location ('Entering '||l_proc,10);
903     --
904     FOR l_rec IN c_restore_pep(p_per_in_ler_id) LOOP
905       --
906       l_effective_date := l_rec.effective_start_date;
907       --
908       open c_pep(l_rec.BKUP_TBL_ID,l_effective_date);
909       fetch c_pep INTO l_rec.object_version_number;
910       IF c_pep%FOUND THEN
911       --Get the Datetrack Mode
912       dt_api.find_dt_upd_modes
913         (p_effective_date       => l_effective_date,
914          p_base_table_name      => 'BEN_ELIG_PER_F',
915          p_base_key_column      => 'elig_per_id',
916          p_base_key_value       => l_rec.BKUP_TBL_ID,
917          p_correction           => l_correction,
918          p_update               => l_update,
919          p_update_override      => l_update_override,
920          p_update_change_insert => l_update_change_insert);
921       --
922       if l_update_override then
923         --
924         l_datetrack_mode := hr_api.g_update_override;
925         --
926       elsif l_update then
927         --
928         l_datetrack_mode := hr_api.g_update;
929         --
930       else
931         --
932         l_datetrack_mode := hr_api.g_correction;
933         --
934       end if;
935       --
936       ben_Eligible_Person_perf_api.update_perf_Eligible_Person
937         (p_validate                     => FALSE,
938          p_elig_per_id                  => l_rec.BKUP_TBL_ID,
939          p_per_in_ler_id                => l_rec.per_in_ler_id,
940          p_effective_start_date         => l_rec.effective_start_date,
941          p_effective_end_date           => l_rec.effective_end_date,
942          p_elig_flag                    => l_rec.elig_flag,
943          p_prtn_strt_dt                 => l_rec.prtn_strt_dt,
944          p_prtn_end_dt                  => l_rec.prtn_end_dt,
945          p_prtn_ovridn_flag             => l_rec.prtn_ovridn_flag,
946          p_prtn_ovridn_thru_dt          => l_rec.prtn_ovridn_thru_dt,
947          p_rt_comp_ref_amt              => l_rec.rt_comp_ref_amt,
948          p_rt_cmbn_age_n_los_val        => l_rec.rt_cmbn_age_n_los_val,
949          p_rt_comp_ref_uom              => l_rec.rt_comp_ref_uom,
950          p_rt_age_val                   => l_rec.rt_age_val,
951          p_rt_los_val                   => l_rec.rt_los_val,
952          p_rt_hrs_wkd_val               => l_rec.rt_hrs_wkd_val,
953          p_rt_hrs_wkd_bndry_perd_cd     => l_rec.rt_hrs_wkd_bndry_perd_cd,
954          p_rt_age_uom                   => l_rec.rt_age_uom,
955          p_rt_los_uom                   => l_rec.rt_los_uom,
956          p_rt_pct_fl_tm_val             => l_rec.rt_pct_fl_tm_val,
957          p_rt_frz_los_flag              => l_rec.rt_frz_los_flag, -- 'N',
958          p_rt_frz_age_flag              => l_rec.rt_frz_age_flag, --'N',
959          p_rt_frz_cmp_lvl_flag          => l_rec.rt_frz_cmp_lvl_flag, -- 'N',
960          p_rt_frz_pct_fl_tm_flag        => l_rec.rt_frz_pct_fl_tm_flag, -- 'N',
961          p_rt_frz_hrs_wkd_flag          => l_rec.rt_frz_hrs_wkd_flag, -- 'N',
962          p_rt_frz_comb_age_and_los_flag => l_rec.rt_frz_comb_age_and_los_flag, -- 'N',
963          p_once_r_cntug_cd              => l_rec.once_r_cntug_cd,
964          p_comp_ref_amt                 => l_rec.comp_ref_amt,
965          p_cmbn_age_n_los_val           => l_rec.cmbn_age_n_los_val,
966          p_comp_ref_uom                 => l_rec.comp_ref_uom,
967          p_age_val                      => l_rec.age_val,
968          p_los_val                      => l_rec.los_val,
969          p_hrs_wkd_val                  => l_rec.hrs_wkd_val,
970          p_hrs_wkd_bndry_perd_cd        => l_rec.hrs_wkd_bndry_perd_cd,
971          p_age_uom                      => l_rec.age_uom,
972          p_los_uom                      => l_rec.los_uom,
973          p_pct_fl_tm_val                => l_rec.pct_fl_tm_val,
974          p_frz_los_flag                 => l_rec.frz_los_flag, -- 'N',
975          p_frz_age_flag                 => l_rec.frz_age_flag, -- 'N',
976          p_frz_cmp_lvl_flag             => l_rec.frz_cmp_lvl_flag, -- 'N',
977          p_frz_pct_fl_tm_flag           => l_rec.frz_pct_fl_tm_flag, -- 'N',
978          p_frz_hrs_wkd_flag             => l_rec.frz_hrs_wkd_flag, -- 'N',
979          p_frz_comb_age_and_los_flag    => l_rec.frz_comb_age_and_los_flag, -- 'N',
980      --    p_wait_perd_cmpltn_dt          => l_wait_perd_cmpltn_dt,
981      --    p_wait_perd_strt_dt            => l_wait_perd_strt_dt,
982          p_object_version_number        => l_rec.object_version_number,
983          --
984          p_effective_date               => l_effective_date,
988          p_request_id                   => fnd_global.conc_request_id,
985          p_datetrack_mode               => l_datetrack_mode,
986          p_program_application_id       => fnd_global.prog_appl_id,
987          p_program_id                   => fnd_global.conc_program_id,
989          p_program_update_date          => sysdate);
990          --
991       ELSE
992         NULL;
993         --Do we need to Create one ?
994         --Start AMN bug 12732878 Creating a elig_per_f record
995 		hr_utility.set_location('Start Restoring elig_per_id ',48);
996       	ben_Eligible_Person_perf_api.create_perf_Eligible_Person
997 	        (p_validate                     => FALSE,
998 	         p_elig_per_id                  => l_elig_per_id,
999 	         p_effective_start_date         => l_effective_start_date,
1000 	         p_effective_end_date           => l_effective_end_date,
1001 	         p_business_group_id            => l_rec.business_group_id,
1005 	         p_pgm_id                       => l_rec.pgm_id,
1002 	         p_pl_id                        => l_rec.pl_id,
1003 	         p_plip_id                      => l_rec.plip_id,
1004 	         p_ptip_id                      => l_rec.ptip_id,
1006 	         p_ler_id                       => l_rec.ler_id,
1007 	         p_person_id                    => l_rec.person_id,
1008 	         p_per_in_ler_id                => l_rec.per_in_ler_id,
1009 	         p_dpnt_othr_pl_cvrd_rl_flag    => l_rec.dpnt_othr_pl_cvrd_rl_flag,
1010 	         p_pl_key_ee_flag               => l_rec.pl_key_ee_flag,
1011 	         p_pl_hghly_compd_flag          => l_rec.pl_hghly_compd_flag,
1012 	         p_prtn_ovridn_flag             => l_rec.prtn_ovridn_flag,
1013 	         p_prtn_ovridn_thru_dt          => l_rec.prtn_ovridn_thru_dt,
1014 	         p_no_mx_prtn_ovrid_thru_flag   => l_rec.no_mx_prtn_ovrid_thru_flag,
1015 	         p_prtn_strt_dt                 => l_rec.prtn_strt_dt,
1016 	         p_dstr_rstcn_flag              => l_rec.dstr_rstcn_flag,
1017 	         p_pl_wvd_flag                  => l_rec.pl_wvd_flag,
1018 --	         p_wait_perd_cmpltn_dt          => l_rec.wait_perd_cmpltn_dt,
1019 --	         p_wait_perd_strt_dt            => l_rec.wait_perd_strt_dt,
1020 	         p_elig_flag                    => l_rec.elig_flag,
1021 	         p_comp_ref_amt                 => l_rec.comp_ref_amt,
1022 	         p_cmbn_age_n_los_val           => l_rec.cmbn_age_n_los_val,
1023 	         p_comp_ref_uom                 => l_rec.comp_ref_uom,
1024 	         p_age_val                      => l_rec.age_val,
1025 	         p_age_uom                      => l_rec.age_uom,
1026 	         p_los_val                      => l_rec.los_val,
1027 	         p_los_uom                      => l_rec.los_uom,
1028 	         p_hrs_wkd_val                  => l_rec.hrs_wkd_val,
1029 	         p_hrs_wkd_bndry_perd_cd        => l_rec.hrs_wkd_bndry_perd_cd,
1030 	         p_pct_fl_tm_val                => l_rec.pct_fl_tm_val,
1031 	         p_frz_los_flag                 => l_rec.frz_los_flag,
1032 	         p_frz_age_flag                 => l_rec.frz_age_flag,
1033 	         p_frz_cmp_lvl_flag             => l_rec.frz_cmp_lvl_flag,
1034 	         p_frz_pct_fl_tm_flag           => l_rec.frz_pct_fl_tm_flag,
1035 	         p_frz_hrs_wkd_flag             => l_rec.frz_hrs_wkd_flag,
1036 	         p_frz_comb_age_and_los_flag    => l_rec.frz_comb_age_and_los_flag,
1037 	         p_rt_comp_ref_amt              => l_rec.rt_comp_ref_amt,
1038 	         p_rt_cmbn_age_n_los_val        => l_rec.rt_cmbn_age_n_los_val,
1039 	         p_rt_comp_ref_uom              => l_rec.rt_comp_ref_uom,
1040 	         p_rt_age_val                   => l_rec.rt_age_val,
1041 	         p_rt_age_uom                   => l_rec.rt_age_uom,
1042 	         p_rt_los_val                   => l_rec.rt_los_val,
1043 	         p_rt_los_uom                   => l_rec.rt_los_uom,
1044 	         p_rt_hrs_wkd_val               => l_rec.rt_hrs_wkd_val,
1045 	         p_rt_hrs_wkd_bndry_perd_cd     => l_rec.rt_hrs_wkd_bndry_perd_cd,
1046 	         p_rt_pct_fl_tm_val             => l_rec.rt_pct_fl_tm_val,
1047 	         p_rt_frz_los_flag              => l_rec.rt_frz_los_flag,
1048 	         p_rt_frz_age_flag              => l_rec.rt_frz_age_flag,
1049 	         p_rt_frz_cmp_lvl_flag          => l_rec.rt_frz_cmp_lvl_flag,
1050 	         p_rt_frz_pct_fl_tm_flag        => l_rec.rt_frz_pct_fl_tm_flag,
1051 	         p_rt_frz_hrs_wkd_flag          => l_rec.rt_frz_hrs_wkd_flag,
1052 	         p_rt_frz_comb_age_and_los_flag => l_rec.rt_frz_comb_age_and_los_flag,
1053 	         p_once_r_cntug_cd              => l_rec.once_r_cntug_cd,
1054 	         p_pl_ordr_num                  => l_rec.pl_ordr_num,
1055 	         p_plip_ordr_num                => l_rec.plip_ordr_num,
1056 	         p_ptip_ordr_num                => l_rec.ptip_ordr_num,
1057 	         p_object_version_number        => l_object_version_number,
1058 	         p_effective_date               => l_effective_date,
1059 	         p_program_application_id       => fnd_global.prog_appl_id,
1060 	         p_program_id                   => fnd_global.conc_program_id,
1061 	         p_request_id                   => fnd_global.conc_request_id,
1065 			);
1062 	         p_program_update_date          => sysdate,
1063 	         p_override_validation          => TRUE,
1064 	         p_defer                        => false
1066 
1067 			g_eper_map_rec.extend;
1068 			g_epe_map_count := g_eper_map_rec.last;
1069 			g_eper_map_rec(g_epe_map_count).old_elig_per_id := l_rec.BKUP_TBL_ID;
1070 			g_eper_map_rec(g_epe_map_count).new_elig_per_id := l_elig_per_id;
1071 			--hr_utility.set_location('g_epe_map_count '||g_epe_map_count,48);
1072 			--hr_utility.set_location('g_eper_map_rec(g_epe_map_count).old_elig_per_id '||g_eper_map_rec(g_epe_map_count).old_elig_per_id,48);
1073 			--hr_utility.set_location('g_eper_map_rec(g_epe_map_count).new_elig_per_id '||g_eper_map_rec(g_epe_map_count).new_elig_per_id,48);
1074 			--End AMN bug 12732878
1075         --
1076       END IF;
1077       --
1078       close c_pep;
1079       --
1080     END LOOP;
1081     --
1082     --Now Delete the records from ben_le_clsn_n_rstr
1083     --
1084     delete from ben_le_clsn_n_rstr elig
1085      where elig.per_in_ler_ended_id = p_per_in_ler_id
1086        and elig.BKUP_TBL_TYP_CD = 'BEN_ELIG_PER_F_CORRECT' ;
1087     --
1088     hr_utility.set_location ('Leaving '||l_proc,10);
1089     --
1090 end restore_prev_pep ;
1091 --
1092 procedure restore_cert_completion
1093   (p_per_in_ler_id in number
1094   ) is
1095     --
1096     l_proc varchar2(72) := g_package||'restore_cert_completion';
1097     --
1098     cursor c_restore_pcs( p_pil_id number) IS
1099      select pcs.*
1100         from ben_le_clsn_n_rstr pcs,
1101              ben_le_clsn_n_rstr pea
1102        where pcs.per_in_ler_ended_id = p_pil_id
1103          and pea.per_in_ler_ended_id = p_pil_id
1104          and pea.BKUP_TBL_TYP_CD = 'BEN_PRTT_ENRT_ACTN_F_UPD'
1105          and pcs.BKUP_TBL_TYP_CD = 'BEN_PRTT_ENRT_CTFN_PRVDD_F_UPD'
1106          and pea.BKUP_TBL_ID = pcs.PGM_ID ; --PRTT_ENRT_ACTN_ID
1107     --
1108     cursor c_pcs(p_prtt_enrt_ctfn_prvdd_id number,
1109                  p_effective_date date ) IS
1110       select pcs.object_version_number
1111         from ben_prtt_enrt_ctfn_prvdd_f pcs,
1112              ben_prtt_enrt_actn_f pea
1113        where pcs.prtt_enrt_ctfn_prvdd_id = p_prtt_enrt_ctfn_prvdd_id
1114          and pea.prtt_enrt_actn_id = pcs.prtt_enrt_actn_id
1115          and p_effective_date between pcs.effective_start_date
1116                                   and pcs.effective_end_date
1117          and p_effective_date between pea.effective_start_date
1118                                   and pea.effective_end_date;
1119     --
1120     l_object_version_number     number;
1121     l_effective_date date ;
1122     l_correction                boolean;
1123     l_update                    boolean;
1124     l_update_override           boolean;
1125     l_update_change_insert      boolean;
1126     l_datetrack_mode            varchar2(100);
1127     --
1128   begin
1129     --
1130     hr_utility.set_location ('Entering '||l_proc,10);
1131     --
1132     FOR l_rec IN c_restore_pcs(p_per_in_ler_id) LOOP
1133       --
1134       l_effective_date := l_rec.effective_start_date;
1135       --
1136       open c_pcs(l_rec.BKUP_TBL_ID,l_effective_date);
1137       fetch c_pcs INTO l_rec.object_version_number;
1138       IF c_pcs%FOUND THEN
1139         --Get the Datetrack Mode
1140         dt_api.find_dt_upd_modes
1141           (p_effective_date       => l_effective_date,
1142            p_base_table_name      => 'BEN_PRTT_ENRT_CTFN_PRVDD_F',
1143            p_base_key_column      => 'PRTT_ENRT_CTFN_PRVDD_ID',
1144            p_base_key_value       => l_rec.BKUP_TBL_ID,
1145            p_correction           => l_correction,
1146            p_update               => l_update,
1147            p_update_override      => l_update_override,
1148            p_update_change_insert => l_update_change_insert);
1149         --
1150         if l_update_override then
1151           --
1152           l_datetrack_mode := hr_api.g_update_override;
1153           --
1154         elsif l_update then
1155           --
1156           l_datetrack_mode := hr_api.g_update;
1157           --
1158         else
1159           --
1160           l_datetrack_mode := hr_api.g_correction;
1161           --
1162         end if;
1163         --
1164         BEN_prtt_enrt_ctfn_prvdd_API.update_prtt_enrt_ctfn_prvdd
1165           (p_validate => FALSE
1166           ,p_PRTT_ENRT_CTFN_PRVDD_ID => l_rec.BKUP_TBL_ID
1167           ,p_EFFECTIVE_START_DATE =>    l_rec.EFFECTIVE_START_DATE
1168           ,p_EFFECTIVE_END_DATE =>      l_rec.EFFECTIVE_END_DATE
1169           ,p_ENRT_CTFN_RQD_FLAG =>      l_rec.PRTT_IS_CVRD_FLAG
1170           ,p_ENRT_CTFN_TYP_CD =>        l_rec.COMP_LVL_CD
1171           ,p_ENRT_CTFN_RECD_DT =>       l_rec.ENRT_CVG_THRU_DT
1172           ,p_ENRT_CTFN_DND_DT =>        l_rec.ENRT_OVRID_THRU_DT
1173           ,p_ENRT_R_BNFT_CTFN_CD =>     l_rec.BNFT_TYP_CD
1174           ,p_PRTT_ENRT_RSLT_ID =>       l_rec.PRTT_ENRT_RSLT_ID
1175           ,p_PRTT_ENRT_ACTN_ID =>       l_rec.PGM_ID
1176           ,p_BUSINESS_GROUP_ID =>       l_rec.BUSINESS_GROUP_ID
1177           ,p_PCS_ATTRIBUTE_CATEGORY =>  l_rec.LCR_ATTRIBUTE_CATEGORY
1178           ,p_PCS_ATTRIBUTE1 =>          l_rec.LCR_ATTRIBUTE1
1179           ,p_PCS_ATTRIBUTE2 =>          l_rec.LCR_ATTRIBUTE2
1180           ,p_PCS_ATTRIBUTE3 =>          l_rec.LCR_ATTRIBUTE3
1181           ,p_PCS_ATTRIBUTE4 =>          l_rec.LCR_ATTRIBUTE4
1182           ,p_PCS_ATTRIBUTE5 =>          l_rec.LCR_ATTRIBUTE5
1183           ,p_PCS_ATTRIBUTE6 =>          l_rec.LCR_ATTRIBUTE6
1184           ,p_PCS_ATTRIBUTE7 =>          l_rec.LCR_ATTRIBUTE7
1185           ,p_PCS_ATTRIBUTE8 =>          l_rec.LCR_ATTRIBUTE8
1186           ,p_PCS_ATTRIBUTE9 =>          l_rec.LCR_ATTRIBUTE9
1187           ,p_PCS_ATTRIBUTE10 =>         l_rec.LCR_ATTRIBUTE10
1188           ,p_PCS_ATTRIBUTE11 =>         l_rec.LCR_ATTRIBUTE11
1192           ,p_PCS_ATTRIBUTE15 =>         l_rec.LCR_ATTRIBUTE15
1189           ,p_PCS_ATTRIBUTE12 =>         l_rec.LCR_ATTRIBUTE12
1190           ,p_PCS_ATTRIBUTE13 =>         l_rec.LCR_ATTRIBUTE13
1191           ,p_PCS_ATTRIBUTE14 =>         l_rec.LCR_ATTRIBUTE14
1193           ,p_PCS_ATTRIBUTE16 =>         l_rec.LCR_ATTRIBUTE16
1194           ,p_PCS_ATTRIBUTE17 =>         l_rec.LCR_ATTRIBUTE17
1195           ,p_PCS_ATTRIBUTE18 =>         l_rec.LCR_ATTRIBUTE18
1196           ,p_PCS_ATTRIBUTE19 =>         l_rec.LCR_ATTRIBUTE19
1197           ,p_PCS_ATTRIBUTE20 =>         l_rec.LCR_ATTRIBUTE20
1198           ,p_PCS_ATTRIBUTE21 =>         l_rec.LCR_ATTRIBUTE21
1199           ,p_PCS_ATTRIBUTE22 =>         l_rec.LCR_ATTRIBUTE22
1200           ,p_PCS_ATTRIBUTE23 =>         l_rec.LCR_ATTRIBUTE23
1201           ,p_PCS_ATTRIBUTE24 =>         l_rec.LCR_ATTRIBUTE24
1202           ,p_PCS_ATTRIBUTE25 =>         l_rec.LCR_ATTRIBUTE25
1203           ,p_PCS_ATTRIBUTE26 =>         l_rec.LCR_ATTRIBUTE26
1204           ,p_PCS_ATTRIBUTE27 =>         l_rec.LCR_ATTRIBUTE27
1205           ,p_PCS_ATTRIBUTE28 =>         l_rec.LCR_ATTRIBUTE28
1206           ,p_PCS_ATTRIBUTE29 =>         l_rec.LCR_ATTRIBUTE29
1207           ,p_PCS_ATTRIBUTE30 =>         l_rec.LCR_ATTRIBUTE30
1208           ,p_OBJECT_VERSION_NUMBER =>   l_rec.object_version_number
1209           ,p_effective_date =>          l_effective_date
1210           ,p_datetrack_mode =>          l_datetrack_mode
1211         );
1212         --
1213       ELSE
1214         NULL;
1215         --Do we need to Create one ?
1216         --
1217       END IF;
1218       --
1219       close c_pcs;
1220       --
1221     END LOOP;
1222     --
1223     --Now Delete the records from ben_le_clsn_n_rstr
1224     --
1225     delete from ben_le_clsn_n_rstr pcs
1226      where pcs.per_in_ler_ended_id = p_per_in_ler_id
1227        and pcs.BKUP_TBL_TYP_CD = 'BEN_PRTT_ENRT_CTFN_PRVDD_F_UPD' ;
1228     --
1229     delete from ben_le_clsn_n_rstr pcs
1230      where pcs.per_in_ler_ended_id = p_per_in_ler_id
1231        and pcs.BKUP_TBL_TYP_CD = 'BEN_PRTT_ENRT_ACTN_F_UPD' ;
1232     --
1233     hr_utility.set_location ('Leaving '||l_proc,10);
1234     --
1235 end restore_cert_completion ;
1236 --
1237 --
1238 procedure restore_prev_epo
1239   (p_per_in_ler_id in number
1240   ) is
1241     --
1242     l_proc varchar2(72) := g_package||'restore_prev_epo';
1243     --
1244     cursor c_restore_epo( p_pil_id number ) IS
1245       select *
1246         from ben_le_clsn_n_rstr elig
1247        where elig.per_in_ler_ended_id = p_pil_id
1248          and elig.BKUP_TBL_TYP_CD = 'BEN_ELIG_PER_OPT_F_CORRECT' ;
1249     --
1250     cursor c_epo(p_elig_per_opt_id number,p_effective_date date) IS
1251       select object_version_number
1252         from ben_elig_per_opt_f epo
1253        where epo.elig_per_opt_id = p_elig_per_opt_id
1254          and p_effective_date between epo.effective_start_date
1255                                   and epo.effective_end_date ;
1256     --
1257     l_effective_date date ;
1258     l_correction                boolean;
1259     l_update                    boolean;
1260     l_update_override           boolean;
1261     l_update_change_insert      boolean;
1262     l_datetrack_mode            varchar2(100);
1263     --
1264 	--Start AMN bug 12732878
1265 	l_elig_per_opt_id			ben_elig_per_opt_f.elig_per_opt_id%TYPE;
1266 	l_effective_start_date		date;
1267 	l_effective_end_date		date;
1268 	l_object_version_number		ben_elig_per_opt_f.object_version_number%type;
1269 	l_new_elig_per_id 			ben_elig_per_opt_f.elig_per_opt_id%TYPE;
1270 	--End AMN bug 12732878
1271   begin
1272     --
1273     hr_utility.set_location ('Entering '||l_proc,10);
1274     --
1275     FOR l_rec IN c_restore_epo(p_per_in_ler_id) LOOP
1276       --
1277       l_effective_date := l_rec.effective_start_date;
1278       --
1279       open c_epo(l_rec.BKUP_TBL_ID,l_effective_date);
1280       fetch c_epo INTO l_rec.object_version_number;
1281       IF c_epo%FOUND THEN
1282       --
1283       --Get the Datetrack Mode
1284       dt_api.find_dt_upd_modes
1285         (p_effective_date       => l_effective_date,
1286          p_base_table_name      => 'BEN_ELIG_PER_OPT_F',
1287          p_base_key_column      => 'elig_per_opt_id',
1288          p_base_key_value       => l_rec.BKUP_TBL_ID,
1289          p_correction           => l_correction,
1290          p_update               => l_update,
1291          p_update_override      => l_update_override,
1292          p_update_change_insert => l_update_change_insert);
1293       --
1294       if l_update_override then
1295         --
1296         l_datetrack_mode := hr_api.g_update_override;
1297         --
1298       elsif l_update then
1299         --
1300         l_datetrack_mode := hr_api.g_update;
1301         --
1302       else
1303         --
1304         l_datetrack_mode := hr_api.g_correction;
1305         --
1306       end if;
1307       --
1308       ben_Eligible_Person_perf_api.update_perf_Elig_Person_Option
1309         (p_validate                     => FALSE,
1310          p_elig_per_opt_id              => l_rec.BKUP_TBL_ID,
1311          p_elig_per_id                  => l_rec.elig_per_id,
1312          p_effective_start_date         => l_rec.effective_start_date,
1313          p_effective_end_date           => l_rec.effective_end_date,
1314          p_per_in_ler_id                => l_rec.per_in_ler_id,
1315          p_elig_flag                    => l_rec.elig_flag,
1316          p_prtn_strt_dt                 => l_rec.prtn_strt_dt,
1317          p_prtn_end_dt                  => l_rec.prtn_end_dt,
1318          p_prtn_ovridn_flag             => l_rec.prtn_ovridn_flag,
1319          p_prtn_ovridn_thru_dt          => l_rec.prtn_ovridn_thru_dt,
1320          p_rt_comp_ref_amt              => l_rec.rt_comp_ref_amt,
1321          p_rt_cmbn_age_n_los_val        => l_rec.rt_cmbn_age_n_los_val,
1325          p_rt_hrs_wkd_val               => l_rec.rt_hrs_wkd_val,
1322          p_rt_comp_ref_uom              => l_rec.rt_comp_ref_uom,
1323          p_rt_age_val                   => l_rec.rt_age_val,
1324          p_rt_los_val                   => l_rec.rt_los_val,
1326          p_rt_hrs_wkd_bndry_perd_cd     => l_rec.rt_hrs_wkd_bndry_perd_cd,
1327          p_rt_age_uom                   => l_rec.rt_age_uom,
1328          p_rt_los_uom                   => l_rec.rt_los_uom,
1329          p_rt_pct_fl_tm_val             => l_rec.rt_pct_fl_tm_val,
1330          p_rt_frz_los_flag              => l_rec.rt_frz_los_flag, -- 'N',
1331          p_rt_frz_age_flag              => l_rec.rt_frz_age_flag, -- 'N',
1332          p_rt_frz_cmp_lvl_flag          => l_rec.rt_frz_cmp_lvl_flag, -- 'N',
1333          p_rt_frz_pct_fl_tm_flag        => l_rec.rt_frz_pct_fl_tm_flag, -- 'N',
1334          p_rt_frz_hrs_wkd_flag          => l_rec.rt_frz_hrs_wkd_flag, -- 'N',
1335          p_rt_frz_comb_age_and_los_flag => l_rec.rt_frz_comb_age_and_los_flag, -- 'N',
1336          p_once_r_cntug_cd              => l_rec.once_r_cntug_cd,
1337          p_comp_ref_amt                 => l_rec.comp_ref_amt,
1338          p_cmbn_age_n_los_val           => l_rec.cmbn_age_n_los_val,
1339          p_comp_ref_uom                 => l_rec.comp_ref_uom,
1340          p_age_val                      => l_rec.age_val,
1341          p_los_val                      => l_rec.los_val,
1342          p_hrs_wkd_val                  => l_rec.hrs_wkd_val,
1343          p_hrs_wkd_bndry_perd_cd        => l_rec.hrs_wkd_bndry_perd_cd,
1344          p_age_uom                      => l_rec.age_uom,
1345          p_los_uom                      => l_rec.los_uom,
1346          p_pct_fl_tm_val                => l_rec.pct_fl_tm_val,
1347          p_frz_los_flag                 => l_rec.frz_los_flag, -- 'N',
1348          p_frz_age_flag                 => l_rec.frz_age_flag, -- 'N',
1349          p_frz_cmp_lvl_flag             => l_rec.frz_cmp_lvl_flag, -- 'N',
1350          p_frz_pct_fl_tm_flag           => l_rec.frz_pct_fl_tm_flag, -- 'N',
1351          p_frz_hrs_wkd_flag             => l_rec.frz_hrs_wkd_flag, -- 'N',
1352          p_frz_comb_age_and_los_flag    => l_rec.frz_comb_age_and_los_flag, -- 'N',
1353       --   p_wait_perd_cmpltn_dt          => l_rec.wait_perd_cmpltn_dt,
1354       --   p_wait_perd_strt_dt            => l_rec.wait_perd_strt_dt,
1355          --
1356          p_effective_date               => l_effective_date,
1357          p_object_version_number        => l_rec.object_version_number,
1358          p_datetrack_mode               => l_datetrack_mode,
1359          p_program_application_id       => fnd_global.prog_appl_id,
1360          p_program_id                   => fnd_global.conc_program_id,
1361          p_request_id                   => fnd_global.conc_request_id,
1362          p_program_update_date          => sysdate);
1363       ELSE
1364         NULL;
1365         --Do we need to Create one ?
1366         --AMN Start bug 12732878 Create elig_per_opt_id
1367 		l_new_elig_per_id := get_new_elig_per_id(l_rec.elig_per_id);
1368 		hr_utility.set_location('Start Restoring elig_per_opt_id '||l_elig_per_opt_id,48);
1369 		--hr_utility.set_location('l_rec.elig_per_id '||l_rec.elig_per_id,48);
1370 		--hr_utility.set_location('l_new_elig_per_id '||l_new_elig_per_id,48);
1371       	ben_Eligible_Person_perf_api.create_perf_Elig_Person_Option
1372 	       	(p_validate                     => FALSE,
1373 	         p_elig_per_opt_id              => l_elig_per_opt_id,
1374 	         p_elig_per_id                  => l_new_elig_per_id,
1375 	         p_per_in_ler_id                => l_rec.per_in_ler_id,
1376 	         p_prtn_ovridn_flag             => l_rec.prtn_ovridn_flag,
1377 	         p_prtn_ovridn_thru_dt          => l_rec.prtn_ovridn_thru_dt,
1378 	         p_no_mx_prtn_ovrid_thru_flag   => l_rec.no_mx_prtn_ovrid_thru_flag,
1379 	         p_elig_flag                    => l_rec.elig_flag,
1380 	         p_prtn_strt_dt                 => l_rec.prtn_strt_dt,
1381 	         p_opt_id                       => l_rec.opt_id,
1382 	         p_rt_comp_ref_amt              => l_rec.rt_comp_ref_amt,
1383 	         p_rt_cmbn_age_n_los_val        => l_rec.rt_cmbn_age_n_los_val,
1384 	         p_rt_comp_ref_uom              => l_rec.rt_comp_ref_uom,
1385 	         p_rt_age_val                   => l_rec.rt_age_val,
1386 	         p_rt_los_val                   => l_rec.rt_los_val,
1387 	         p_rt_hrs_wkd_val               => l_rec.rt_hrs_wkd_val,
1388 	         p_rt_hrs_wkd_bndry_perd_cd     => l_rec.rt_hrs_wkd_bndry_perd_cd,
1389 	         p_rt_age_uom                   => l_rec.rt_age_uom,
1390 	         p_rt_los_uom                   => l_rec.rt_los_uom,
1391 	         p_rt_pct_fl_tm_val             => l_rec.rt_pct_fl_tm_val,
1392 	         p_rt_frz_los_flag              => l_rec.rt_frz_los_flag,
1393 	         p_rt_frz_age_flag              => l_rec.rt_frz_age_flag,
1394 	         p_rt_frz_cmp_lvl_flag          => l_rec.rt_frz_cmp_lvl_flag,
1395 	         p_rt_frz_pct_fl_tm_flag        => l_rec.rt_frz_pct_fl_tm_flag,
1396 	         p_rt_frz_hrs_wkd_flag          => l_rec.rt_frz_hrs_wkd_flag,
1397 	         p_rt_frz_comb_age_and_los_flag => l_rec.rt_frz_comb_age_and_los_flag,
1398 	         p_once_r_cntug_cd              => l_rec.once_r_cntug_cd,
1399 	         p_comp_ref_amt                 => l_rec.comp_ref_amt,
1400 	         p_cmbn_age_n_los_val           => l_rec.cmbn_age_n_los_val,
1401 	         p_comp_ref_uom                 => l_rec.comp_ref_uom,
1402 	         p_age_val                      => l_rec.age_val,
1403 	         p_los_val                      => l_rec.los_val,
1404 	         p_hrs_wkd_val                  => l_rec.hrs_wkd_val,
1405 	         p_hrs_wkd_bndry_perd_cd        => l_rec.hrs_wkd_bndry_perd_cd,
1406 	         p_age_uom                      => l_rec.age_uom,
1407 	         p_los_uom                      => l_rec.los_uom,
1408 	         p_pct_fl_tm_val                => l_rec.pct_fl_tm_val,
1409 	         p_frz_los_flag                 => l_rec.frz_los_flag,
1410 	         p_frz_age_flag                 => l_rec.frz_age_flag,
1411 	         p_frz_cmp_lvl_flag             => l_rec.frz_cmp_lvl_flag,
1412 	         p_frz_pct_fl_tm_flag           => l_rec.frz_pct_fl_tm_flag,
1416 	         --p_wait_perd_cmpltn_date        => l_rec.wait_perd_cmpltn_dt,
1413 	         p_frz_hrs_wkd_flag             => l_rec.frz_hrs_wkd_flag,
1414 	         p_frz_comb_age_and_los_flag    => l_rec.frz_comb_age_and_los_flag,
1415 	         --p_wait_perd_cmpltn_dt          => l_rec.wait_perd_cmpltn_dt,
1417 	         --p_wait_perd_strt_dt            => l_rec.wait_perd_strt_dt,
1418 	         p_effective_start_date         => l_effective_start_date,
1419 	         p_effective_end_date           => l_effective_end_date,
1420 	         p_object_version_number        => l_object_version_number,
1421 	         p_oipl_ordr_num                => l_rec.oipl_ordr_num,
1422 	         p_business_group_id            => l_rec.business_group_id,
1423 	         p_program_application_id       => fnd_global.prog_appl_id,
1424 	         p_program_id                   => fnd_global.conc_program_id,
1425 	         p_request_id                   => fnd_global.conc_request_id,
1426 	         p_program_update_date          => sysdate,
1427 	         p_effective_date               => l_effective_date,
1428 	         p_override_validation          => TRUE
1429         );
1430 		--AMN End bug 12732878
1431         --
1432       END IF;
1433       --
1434       close c_epo;
1435       --
1436     END LOOP;
1437     --
1438     --
1439     --Now Delete the records from ben_le_clsn_n_rstr
1440     --
1441     delete from ben_le_clsn_n_rstr elig
1442           where elig.per_in_ler_ended_id = p_per_in_ler_id
1443             and elig.BKUP_TBL_TYP_CD = 'BEN_ELIG_PER_OPT_F_CORRECT';
1444     --
1445     hr_utility.set_location ('Leaving '||l_proc,10);
1446     --
1447 END  restore_prev_epo ;
1448 --
1449 -- This procedure is the main call that does the calls to back out the
1450 -- neccessary information due to a life event being removed.
1451 --
1452 procedure back_out_life_events
1453   (p_per_in_ler_id         in number,
1454    p_bckt_per_in_ler_id    in number ,
1455    p_bckt_stat_cd          in varchar2 ,
1456    p_business_group_id     in number,
1457    p_bckdt_prtt_enrt_rslt_id in number default null,
1458    p_copy_only              in varchar2  default null,
1459    p_effective_date        in date
1460    ) is
1461    ---- two plan 2982606 column added
1462    cursor c_pil_stat is
1463     select pil.per_in_ler_stat_cd,
1464            pil.object_version_number,
1465            pil.ptnl_ler_for_per_id,
1466            pil.person_id,
1467            pil.lf_evt_ocrd_dt,
1468            pil.ler_id
1469     from   ben_per_in_ler pil
1470     where  pil.per_in_ler_id = p_per_in_ler_id;
1471 
1472 
1473 
1474   cursor c_get_all_per_in_ler is
1475     select *
1476     from   ben_per_in_ler pil
1477     where  pil.per_in_ler_id = p_per_in_ler_id and
1478            pil.business_group_id=p_business_group_id
1479     ;
1480 
1481   cursor c_get_ler_info(v_ler_id number) is
1482     select ler.typ_cd
1483     from   ben_ler_f ler
1484     where  ler.ler_id = v_ler_id
1485    /* and    ler.business_group_id = p_business_group_id*/ -- CWBGLOBAL
1486     and    p_effective_date between
1487            ler.effective_start_date and ler.effective_end_date;
1488 --
1489   cursor c_ler_typ is
1490     select ler.typ_cd
1491     from   ben_ler_f ler,
1492            ben_per_in_ler pil
1493     where  pil.per_in_ler_id = p_per_in_ler_id
1494     and    ler.ler_id = pil.ler_id
1495     /*and    ler.business_group_id = p_business_group_id*/ --CWBGLOBAL
1496     and    pil.lf_evt_ocrd_Dt between
1497            ler.effective_start_date and ler.effective_end_date;
1498 
1499   --
1500   -- CWB Bug 2712602
1501   --
1502   cursor c_pel is
1503     select pil_elctbl_chc_popl_id
1504           from ben_pil_elctbl_chc_popl
1505           where per_in_ler_id =  p_per_in_ler_id;
1506   --
1507   l_pil_elctbl_chc_popl_id number;
1508 
1509   --
1510   -- 2982606
1511   cursor c_prev_pil_id (p_person_id  number, p_lf_evt_ocrd_dt date) is
1512   select per_in_ler_id ,
1513          lf_evt_ocrd_dt
1514     from ben_per_in_ler
1515    where per_in_ler_id <> p_per_in_ler_id
1516      and per_in_ler_stat_cd = 'PROCD'
1517      and person_id          =  p_person_id
1518      and lf_evt_ocrd_dt    <= p_lf_evt_ocrd_dt
1519      order by lf_evt_ocrd_dt desc ;
1520   --
1521    cursor c_prv_rslt_lvl_bckdt( p_pil_id number,
1522                                p_lf_evt_ocrd_dt date) is
1523    select effective_start_date
1524      from  ben_le_clsn_n_rstr  pen
1525     where  per_in_ler_id = p_pil_id
1526       AND  pen.business_group_id = p_business_group_id
1527       AND  pen.prtt_enrt_rslt_stat_cd IS NULL
1528       AND  pen.effective_end_date = hr_api.g_eot
1529       AND  pen.enrt_cvg_strt_dt > p_lf_evt_ocrd_dt
1530       AND  pen.enrt_cvg_strt_dt < pen.effective_end_date;
1531 
1532  /* Added for Bug 8604243 */
1533 
1534  cursor c_chk_enrt_prev_le(c_per_in_ler_id number) is
1535  select 'Y' from ben_prtt_enrt_rslt_f pen
1536  where prtt_enrt_rslt_stat_cd is null
1537        and per_in_ler_id = c_per_in_ler_id
1538        and enrt_cvg_strt_dt < enrt_cvg_thru_dt;
1539 
1540  cursor c_prv_pil(p_person_id  number, p_lf_evt_ocrd_dt date) is
1541   select per_in_ler_id ,
1542          lf_evt_ocrd_dt
1543     from ben_per_in_ler pil,
1544           ben_ler_f ler
1545    where per_in_ler_id <> p_per_in_ler_id
1546      and per_in_ler_stat_cd = 'PROCD'
1547      and person_id          =  p_person_id
1548      and lf_evt_ocrd_dt    <= p_lf_evt_ocrd_dt
1549      and pil.ler_id = ler.ler_id
1550      and p_effective_date between
1551            ler.effective_start_date and ler.effective_end_date
1552      and  ler.typ_cd not in ('IREC', 'SCHEDDU', 'COMP', 'GSP', 'ABS')
1553      and exists
1554           (select 'Y' from ben_prtt_enrt_rslt_f pen
1555             where pen.per_in_ler_id = pil.per_in_ler_id
1559 
1556             and pen.prtt_enrt_rslt_stat_cd is null
1557             and pen.enrt_cvg_strt_dt < pen.enrt_cvg_thru_dt)
1558      order by lf_evt_ocrd_dt desc ;
1560   l_exists_flag varchar2(1) default 'N';
1561   l_new_prev_pil number;
1562   l_new_date date;
1563 
1564   /* End of Bug 8604243 */
1565 
1566 
1567  -- added here bug 7039025
1568 
1569       cursor c_prior_to_prv_rslt_lvl_bckdt( p_pil_id number,
1570                                p_lf_evt_ocrd_dt date) is
1571    select leclr.*
1572      from  ben_le_clsn_n_rstr  leclr,
1573            ben_prtt_enrt_rslt_f pen
1574     where  leclr.per_in_ler_id <> p_pil_id
1575       AND  leclr.business_group_id = p_business_group_id
1576       AND  leclr.prtt_enrt_rslt_stat_cd IS NULL
1577       AND  leclr.effective_end_date = hr_api.g_eot
1578       AND  leclr.enrt_cvg_strt_dt > p_lf_evt_ocrd_dt
1579       AND  leclr.enrt_cvg_strt_dt < leclr.effective_end_date
1580       AND  leclr.bkup_tbl_typ_cd = 'BEN_PRTT_ENRT_RSLT_F'
1581       AND  leclr.bkup_tbl_id = pen.prtt_enrt_rslt_id
1582       AND  pen.per_in_ler_id = p_per_in_ler_id
1583       AND  pen.prtt_enrt_rslt_stat_cd = 'BCKDT'
1584       AND  pen.effective_end_date = hr_api.g_eot
1585       AND  pen.enrt_cvg_strt_dt > p_lf_evt_ocrd_dt
1586       AND  pen.enrt_cvg_strt_dt < pen.effective_end_date;
1587 
1588      --
1589      -- added till here bug 7039025
1590 
1591 
1592   --  2982606
1593   cursor c_chr is
1594     select rowid
1595         from ben_cwb_hrchy
1596         where mgr_pil_elctbl_chc_popl_id = l_pil_elctbl_chc_popl_id;
1597   --
1598   l_pil_stat c_pil_stat%rowtype;
1599   l_per_in_ler c_get_all_per_in_ler%rowtype;
1600   l_ler_info  c_get_ler_info%rowtype;
1601   l_date      date;
1602   l_ler_typ   varchar2(200);
1603   l_package   varchar2(80) := g_package||'.back_out_life_events';
1604   -- 2982606
1605   l_prv_per_in_ler_id  number ;
1606   l_prv_lf_evt_ocrd_dt       date ;
1607   l_prv_effective_start_date date ;
1608   l_dummy              varchar2(1) ;
1609 
1610   --
1611 begin
1612   --
1613   hr_utility.set_location ('Entering '||l_package,10);
1614   --
1615   -- unrestricted life event not to be backed out
1616   open  c_ler_typ;
1617   fetch c_ler_typ into l_ler_typ;
1618   close c_ler_typ;
1619   if l_ler_typ = 'SCHEDDU' then
1620     -- do nothing
1621     return;
1622   end if;
1623 
1624 
1625   -- There are a series of deleting steps and these muse be done in
1626   -- order as otherwise we will get foreign key issues and the like.
1627   --
1628   -- Tables that will be deleted from include and must be deleted from in
1629   -- a bottom to top fashion :
1630   --
1631   -- BEN_PER_IN_LER (PIL)
1632   -- BEN_PRTT_ENRT_RSLT_F (PEN)
1633   -- BEN_PL_BNF_F (PBN) (join to pil to check status)
1634   -- BEN_PRTT_ENRT_ACTN_F (PEA) (join to pil to check status)
1635   -- BEN_BNFT_PRVDD_LDGR_F (BPL)(join to pil to check status)
1636   -- BEN_PRTT_RT_VAL (PRV)
1637   -- BEN_PRTT_REIMBMT_RQST_F
1638   -- BEN_PL_BNF_CTFN_PRVDD_F (PBC)(join to pil to check status)
1639   -- BEN_PRTT_ENRT_CTFN_PRVDD_F (PCS)(join to pil to check status)
1640   -- BEN_ELIG_PER_ELCTBL_CHC (EPE) (not deleted, join to pil to check status)
1641      -- BEN_ENRT_BNFT (ENB)          (cascade delete in epe api, but epe not deleted)
1642      -- BEN_ENRT_RT (ECR)            (cascade delete in epe api, but epe not deleted)
1643      -- BEN_ENRT_CVG_N_RT_CTFN (ECC) (cascade delete in epe api, but epe not deleted)
1644   -- BEN_ELIG_CVRD_DPNT_F (PDP)
1645   -- BEN_ELIG_PER_F (PEP)
1646   -- BEN_ELIG_PER_OPT_F (EPO)
1647   -- BEN_CVRD_DPNT_CTFN_PRVDD_F (CCP)
1648   -- BEN_PER_CM_F (PCM) (join to pil to check status)
1649      -- BEN_PER_CM_USG_F (PCU) (join to pil to check status)
1650      -- BEN_PER_CM_TRGR_F (PCR) (join to pil to check status)
1651      -- BEN_PER_CM_PRVDD_F (PCD) (join to pil to check status)
1652   -- PAY_ELEMENT_ENTRIES_F (PEE)
1653   -- PAY_ELEMENT_ENTRY_VALUES_F (PEV)
1654   -- BEN_PRTT_PREM_F (PPE)
1655   -- BEN_CBR_QUALD_BNF (CQB) - (not deleted, if it is the initial qualifying event, join
1656   --                            to pil to check status. If it is not the initial
1657   --                            qualifying event, restore the prior eligibility end date.)
1658   -- BEN_CBR_PER_IN_LER (CRP) - (not deleted, join to pil to check status).
1659   --
1660   --                     PIL
1661   --                      |
1662   --    ---------------------------------
1663   --    |                               |
1664   --    |                              PEN
1665   --    |                               |
1666   --    |--------------------------------------------------------------
1667   --    | |  |      |                   |         |       |     |     |
1668   --    | | PRV    PBN                 PEA        |      PEE   PPE    |
1669   --    | |  |      |                   |         |                   |
1670   --    | |  |      | --------------------------- |                   |
1671   --    | |  |      | |                 |       | |                   |
1672   --    | |  |      PBC                 |       PCS                   |
1673   --    | |  |                          |                             |
1674   --    EPE  |                          |                             |
1675   --     |   |                          |                             |
1676   --   ---------------------------------------------------------------|
1677   --   |  |  |                          |                             |
1678   -- ENB  |  |                          |---------------------------- PDP
1679   --   |  |  |                                                      | |
1680   --  --- | /                                                       CCP
1681   --  | | |/
1682   --  | ECR
1683   --  | |
1684   --  ECC
1685   --
1686   --
1687   --
1688   --
1692   open c_pil_stat;
1689   -- first check that per in ler is not already backed out.
1690   --
1691 
1693   fetch c_pil_stat into l_pil_stat;
1694   close c_pil_stat;
1695   --
1696   if l_pil_stat.per_in_ler_stat_cd <> 'BCKDT' then
1697 
1698 
1699       -- 2982606 if any results backed out  restore the  results
1700       open c_prev_pil_id (l_pil_stat.person_id , l_pil_stat.lf_evt_ocrd_dt)  ;
1701       fetch c_prev_pil_id into l_prv_per_in_ler_id,l_prv_lf_evt_ocrd_dt ;
1702       close c_prev_pil_id ;
1703 
1704         hr_utility.set_location ('prv_per_in_ler_id' || l_prv_per_in_ler_id, 99 );
1705         hr_utility.set_location ('l_lf_evt_ocrd_dt'  || l_prv_lf_evt_ocrd_dt, 99 );
1706      -- First back out contact persons per in ler's
1707      -- if they are created by the per in ler which is
1708      -- # 2982606 Total of Two Plan Resulkt level backedout introduced
1709      if  p_bckdt_prtt_enrt_rslt_id is null then
1710          -- 3136058
1711         -- Dont backout in case ler is of type grade step.
1712         if l_ler_typ not in ('GSP','IREC', 'COMP', 'ABS') then
1713            p_backout_contact_pils(p_person_id         => l_pil_stat.person_id
1714                               ,p_business_group_id => p_business_group_id
1715                               ,p_per_in_ler_id     => p_per_in_ler_id
1716                               ,p_bckt_stat_cd      => p_bckt_stat_cd
1717                               ,p_csd_by_ptnl_ler_for_per_id => l_pil_stat.ptnl_ler_for_per_id
1718                               ,p_effective_date    => p_effective_date);
1719         end if;
1720      end if ;
1721      --
1722      -- un-end dependents that have been ended.  Leave other dependents
1723      -- alone, they will be ignored if their per-in-ler is 'backed out'
1724      -- g_backout_flag is assigned value to bypass suspend enrollment
1725      g_backout_flag  := 'Y';
1726      --
1727      --CWBGLOBAL : No need to backout in case of CWB backout
1728      if l_ler_typ not in ('GSP', 'COMP') then
1729        -- CFW
1730        IF fnd_global.conc_request_id = -1 THEN
1731          --
1732          ben_env_object.init(p_business_group_id  => p_business_group_id,
1733                              p_effective_date     => p_effective_date,
1734                              p_thread_id          => 1,
1735                              p_chunk_size         => 1,
1736                              p_threads            => 1,
1737                              p_max_errors         => 1,
1738                              p_benefit_action_id  => NULL);
1739          --
1740        END IF ;
1741        -- CFW
1742        delete_routine(p_routine           => 'BEN_ELIG_CVRD_DPNT_F',
1743                  p_per_in_ler_id     => p_per_in_ler_id,
1744                  p_business_group_id => p_business_group_id,
1745                  p_bckdt_prtt_enrt_rslt_id => p_bckdt_prtt_enrt_rslt_id,
1746                  p_copy_only         =>  p_copy_only,
1747                  p_effective_date    => p_effective_date);
1748 
1749        --  (404) Until we recognize that pcp's aren't valid if their per-in-ler isn't
1750        -- we need to still delete them.  Need to change views?  or add per in ler id.
1751        hr_utility.set_location('Effective Date'||p_effective_date,10);
1752 
1753        delete_routine(p_routine           => 'BEN_PRMRY_CARE_PRVDR_F',
1754                  p_per_in_ler_id     => p_per_in_ler_id,
1755                  p_business_group_id => p_business_group_id,
1756                  p_bckdt_prtt_enrt_rslt_id => p_bckdt_prtt_enrt_rslt_id,
1757                  p_copy_only         =>  p_copy_only,
1758                  p_effective_date    => p_effective_date);
1759 
1760         -- un-end beneficiaries that have been ended.  Leave other beneficiaries
1761         -- alone, they will be ignored if their per-in-ler is 'backed out'
1762         delete_routine(p_routine           => 'BEN_PL_BNF_F',
1763                  p_per_in_ler_id     => p_per_in_ler_id,
1764                  p_business_group_id => p_business_group_id,
1765                  p_bckdt_prtt_enrt_rslt_id => p_bckdt_prtt_enrt_rslt_id,
1766                  p_copy_only         =>  p_copy_only,
1767                  p_effective_date    => p_effective_date);
1768 
1769 
1770 
1771         delete_routine(p_routine          => 'BEN_PRTT_REIMBMT_RQST',
1772                  p_per_in_ler_id     => p_per_in_ler_id,
1773                  p_business_group_id => p_business_group_id,
1774                  p_bckdt_prtt_enrt_rslt_id => p_bckdt_prtt_enrt_rslt_id,
1775                  p_copy_only         =>  p_copy_only,
1776                  p_effective_date    => p_effective_date);
1777 
1778         -- delete credit ledger rows
1779         delete_routine(p_routine           => 'BEN_BNFT_PRVDD_LDGR_F',
1780                  p_per_in_ler_id     => p_per_in_ler_id,
1781                  p_business_group_id => p_business_group_id,
1782                  p_bckdt_prtt_enrt_rslt_id => p_bckdt_prtt_enrt_rslt_id,
1783                  p_copy_only         =>  p_copy_only,
1784                  p_effective_date    => p_effective_date);
1785 
1786         hr_utility.set_location('BEN_PRTT_RT_VAL p_effective_date'||p_effective_date,1999);
1787         -- mark rates 'backed out'
1788         delete_routine(p_routine           => 'BEN_PRTT_RT_VAL',
1789                  p_per_in_ler_id     => p_per_in_ler_id,
1790                  p_business_group_id => p_business_group_id,
1791                  p_bckdt_prtt_enrt_rslt_id => p_bckdt_prtt_enrt_rslt_id,
1792                  p_copy_only         =>  p_copy_only,
1793                  p_effective_date    => p_effective_date);
1794 
1795        -- mark prtt_prem's 'backed out'
1796        delete_routine(p_routine           => 'BEN_PRTT_PREM_F',
1797                  p_per_in_ler_id     => p_per_in_ler_id,
1798                  p_business_group_id => p_business_group_id,
1799                  p_bckdt_prtt_enrt_rslt_id => p_bckdt_prtt_enrt_rslt_id,
1800                  p_copy_only         =>  p_copy_only,
1801                  p_effective_date    => p_effective_date);
1805                  p_per_in_ler_id     => p_per_in_ler_id,
1802 
1803        -- mark results 'backed out'
1804        delete_routine(p_routine           => 'BEN_PRTT_ENRT_RSLT_F',
1806                  p_business_group_id => p_business_group_id,
1807                  p_bckdt_prtt_enrt_rslt_id => p_bckdt_prtt_enrt_rslt_id,
1808                  p_copy_only         =>  p_copy_only,
1809                  p_effective_date    => p_effective_date);
1810      end if;
1811 
1812      if  p_bckdt_prtt_enrt_rslt_id is null then
1813          -- mark pil popl's 'backed out'
1814          delete_routine(p_routine           => 'BEN_PIL_ELCTBL_CHC_POPL',
1815                  p_per_in_ler_id     => p_per_in_ler_id,
1816                  p_business_group_id => p_business_group_id,
1817                  p_copy_only         =>  p_copy_only,
1818                  p_effective_date    => p_effective_date);
1819 
1820          --CWBGLOBAL : No need to backout in case of CWB backout
1821          if l_ler_typ not in ('COMP') then
1822          -- mark elig_per opts's 'backed out'
1823          delete_routine(p_routine           => 'BEN_ELIG_PER_OPT_F',
1824                  p_per_in_ler_id     => p_per_in_ler_id,
1825                  p_business_group_id => p_business_group_id,
1826                  p_copy_only         =>  p_copy_only,
1827                  p_effective_date    => p_effective_date);
1828 
1829          -- mark elig_per's 'backed out'
1830          delete_routine(p_routine           => 'BEN_ELIG_PER_F',
1831                  p_per_in_ler_id     => p_per_in_ler_id,
1832                  p_business_group_id => p_business_group_id,
1833                  p_copy_only         =>  p_copy_only,
1834                  p_effective_date    => p_effective_date);
1835          end if;
1836          --
1837          if l_ler_typ not in ('GSP', 'ABS', 'IREC', 'COMP') then
1838             --
1839             -- If applicable, update the eligibility end date to the eligibility
1840             -- end date of the prior event.
1841             --
1842             delete_routine(p_routine           => 'BEN_CBR_QUALD_BNF',
1843                     p_per_in_ler_id     => p_per_in_ler_id,
1844                     p_business_group_id => p_business_group_id,
1845                     p_copy_only         =>  p_copy_only,
1846                     p_effective_date    => p_effective_date);
1847 
1848          end if;
1849 
1850 
1851 
1852          -- update ptnl to unprocessed, when the ler is not unrestricted.
1853             --
1854             open c_get_all_per_in_ler;
1855             fetch c_get_all_per_in_ler into l_per_in_ler;
1856             close c_get_all_per_in_ler;
1857            --
1858             open  c_get_ler_info(l_per_in_ler.ler_id);
1859             fetch c_get_ler_info into l_ler_info;
1860             close c_get_ler_info;
1861             --
1862             if l_ler_info.typ_cd =  'SCHEDDU' then
1863                --
1864                -- Unrestricted ler, so nothing needs to be done.
1865                --
1866                null;
1867                --
1868             else
1869                --
1870                -- Update ptnl as unprocessed.
1871                --
1872                unprocess_ptnl_ler
1873                  (p_per_in_ler     => l_per_in_ler
1874                  ,p_bckt_stat_cd   => p_bckt_stat_cd
1875                  ,p_effective_date => p_effective_date);
1876                --
1877             end if;
1878 
1879          -- 3136058
1880          -- In case ler is of type grade step, mark it as voided, else backed out  -- Added IREC
1881          if l_ler_typ in ( 'GSP', 'IREC')  then
1882             ben_Person_Life_Event_api.update_person_life_event
1883               (p_per_in_ler_id         => p_per_in_ler_id
1884               ,p_bckt_per_in_ler_id    => p_bckt_per_in_ler_id
1885               ,p_per_in_ler_stat_cd    => 'VOIDD'
1886               ,p_prvs_stat_cd          => l_pil_stat.per_in_ler_stat_cd
1887               ,p_object_version_number => l_pil_stat.object_version_number
1888               ,p_effective_date        => p_effective_date
1889               ,P_PROCD_DT              => l_date  -- outputs
1890               ,P_STRTD_DT              => l_date
1891               ,P_VOIDD_DT              => l_date  );
1892 
1893          else
1894             --
1895             -- Finally, mark the per-in-ler as backed out.
1896             ben_Person_Life_Event_api.update_person_life_event
1897               (p_per_in_ler_id         => p_per_in_ler_id
1898               ,p_bckt_per_in_ler_id    => p_bckt_per_in_ler_id
1899               ,p_per_in_ler_stat_cd    => 'BCKDT'
1900               ,p_prvs_stat_cd          => l_pil_stat.per_in_ler_stat_cd
1901               ,p_object_version_number => l_pil_stat.object_version_number
1902               ,p_effective_date        => p_effective_date
1903               ,P_PROCD_DT              => l_date  -- outputs
1904               ,P_STRTD_DT              => l_date
1905               ,P_VOIDD_DT              => l_date  );
1906          end if;
1907         --
1908 
1909         -- Bug 2526994 This needs to be reset once the process is done.
1910         g_backout_flag  := null ;
1911 
1912         /*
1913         -- 2982606 if any results backed out  restore the  results
1914         open c_prev_pil_id (l_pil_stat.person_id , l_pil_stat.lf_evt_ocrd_dt)  ;
1915         fetch c_prev_pil_id into l_prv_per_in_ler_id,l_prv_lf_evt_ocrd_dt ;
1916         close c_prev_pil_id ;
1917         */
1918 
1919         hr_utility.set_location ('prv_per_in_ler_id' || l_prv_per_in_ler_id, 199 );
1920         hr_utility.set_location ('l_lf_evt_ocrd_dt'  || l_prv_lf_evt_ocrd_dt, 199 );
1921         --
1922         --IK START
1923         -- Get all the BEN_ELIG_PER_F_CORRECTION and BEN_ELIG_PER_OPT_F_CORRECTION
1924         -- records from BEN_LE_CLSN_N_RSTR table for the per_in_ler being backed out
1928         -- Collapse and restore table.
1925         -- and update the records with PEP and EPO records with the restored date
1926         -- in correction mode.
1927         -- After API call to Corrrect the PEP and EPO records delete the data from
1929         IF p_per_in_ler_id IS NOT NULL  and l_ler_typ not in ('COMP', 'ABS', 'GSP', 'IREC') THEN
1930           --
1931           g_eper_map_rec.delete;--AMN bug 12732878
1932           restore_prev_pep(p_per_in_ler_id);
1933           restore_prev_epo(p_per_in_ler_id);
1934           --
1935         END IF;
1936         --IK END
1937         if l_prv_per_in_ler_id is not null
1938            and l_ler_typ not in ('COMP', 'ABS', 'GSP', 'IREC')
1939         then
1940            -- Look if there is any backedout result for the future dated coverage
1941 
1942 	      /*Bug 8604243: Added 'if' condition. While backing out a LE,if previous LE does not have
1943               electability and no enrollments results then previous per_in_ler_id should be
1944 	      of the LE for which enrollment results are ended. Check if enrollments results exists for previous LE
1945 	      (Cursor c_chk_enrt_prev_le). If enrollment results does not exist the get the per_in_ler_id of the LE
1946               for which enrollment results are ended (Cursor c_prv_pil);
1947 	      */
1948 
1949            /* Commented below code for Bug 8604243*/
1950 	   /*open c_prv_rslt_lvl_bckdt(l_prv_per_in_ler_id,l_prv_lf_evt_ocrd_dt );
1951            fetch c_prv_rslt_lvl_bckdt into l_prv_effective_start_date ;
1952            close c_prv_rslt_lvl_bckdt ;*/
1953 
1954 
1955 	   g_no_reopen_flag := 'N';
1956 	   open c_chk_enrt_prev_le(l_prv_per_in_ler_id);
1957 	   fetch c_chk_enrt_prev_le into l_exists_flag;
1958 	   if(c_chk_enrt_prev_le%notfound) then
1959 	      l_new_prev_pil := l_prv_per_in_ler_id;
1960 	      l_new_date := l_prv_lf_evt_ocrd_dt;
1961 
1962 	      open c_prv_pil(l_pil_stat.person_id , l_pil_stat.lf_evt_ocrd_dt);
1963 	      fetch c_prv_pil into l_prv_per_in_ler_id,l_prv_lf_evt_ocrd_dt;
1964 	      close c_prv_pil;
1965 
1966 	       -- Look if there is any backedout result for the future dated coverage
1967 	       open c_prv_rslt_lvl_bckdt(l_prv_per_in_ler_id,l_prv_lf_evt_ocrd_dt );
1968 	       fetch c_prv_rslt_lvl_bckdt into l_prv_effective_start_date ;
1969 	       close c_prv_rslt_lvl_bckdt ;
1970 	       hr_utility.set_location ('l_prv_effective_start_date'  || l_prv_effective_start_date, 99 );
1971 	       g_no_reopen_flag := 'Y';
1972 	    else
1973                open c_prv_rslt_lvl_bckdt(l_prv_per_in_ler_id,l_prv_lf_evt_ocrd_dt );
1974                fetch c_prv_rslt_lvl_bckdt into l_prv_effective_start_date ;
1978 	   close c_chk_enrt_prev_le;
1975                close c_prv_rslt_lvl_bckdt ;
1976 	       hr_utility.set_location ('l_prv_effective_start_date'  || l_prv_effective_start_date, 199 );
1977 	    end if;
1979 	   /* Ended for Bug 8604243*/
1980 
1981            hr_utility.set_location ('l_prv_eff dt'  || l_prv_effective_start_date, 99 );
1982            hr_utility.set_location ('l_prv_per_in_ler_id'  || l_prv_per_in_ler_id, 99 );
1983 
1984            if l_prv_effective_start_date is not null then
1985               hr_utility.set_location ('status to started' , 99 );
1986 
1987 	       -- added here bug 7039025
1988 	   For l_prior_to_prv_rslt_lvl_bckdt in c_prior_to_prv_rslt_lvl_bckdt(l_prv_per_in_ler_id,l_prv_lf_evt_ocrd_dt)
1989 	   loop
1990 	   --
1991            hr_utility.set_location ('prior to prev life event found in bkup table',44333);
1992            --
1993 	   -- Insert a correction row before updation as if, the enrollments were corrected by the next pil.
1994            INSERT INTO ben_le_clsn_n_rstr
1995 		(COMP_LVL_CD,
1996 		DSPLY_ON_ENRT_FLAG,
1997 		RT_OVRIDN_FLAG,
1998 		ACTY_REF_PERD_CD,
1999 		ACTY_TYP_CD,
2000 		ANN_RT_VAL,
2001 		BNFT_RT_TYP_CD,
2002 		CMCD_REF_PERD_CD,
2003 		CMCD_RT_VAL,
2004 		ELCNS_MADE_DT,
2005 		MLT_CD,
2006 		PRTT_RT_VAL_STAT_CD,
2007 		RT_OVRIDN_THRU_DT,
2008 		RT_VAL,
2009 		TX_TYP_CD,
2010 		INELG_RSN_CD,
2011 		RT_COMP_REF_AMT,
2012 		RT_CMBN_AGE_N_LOS_VAL,
2013 		RT_COMP_REF_UOM,
2014 		RT_AGE_VAL,
2015 		RT_LOS_VAL,
2016 		RT_HRS_WKD_VAL,
2017 		RT_HRS_WKD_BNDRY_PERD_CD,
2018 		RT_AGE_UOM,
2019 		RT_LOS_UOM,
2020 		RT_PCT_FL_TM_VAL,
2021 		RT_FRZ_LOS_FLAG,
2022 		RT_FRZ_AGE_FLAG,
2023 		RT_FRZ_CMP_LVL_FLAG,
2024 		RT_FRZ_PCT_FL_TM_FLAG,
2025 		RT_FRZ_HRS_WKD_FLAG,
2026 		RT_FRZ_COMB_AGE_AND_LOS_FLAG,
2027 		AGE_UOM,
2028 		AGE_VAL,
2029 		CMBN_AGE_N_LOS_VAL,
2030 		COMP_REF_AMT,
2031 		COMP_REF_UOM,
2032 		DPNT_OTHER_PL_CVRD_RL_FLAG,
2033 		DSTR_RSTCN_FLAG,
2034 		FRZ_AGE_FLAG,
2035 		FRZ_CMP_LVL_FLAG,
2036 		FRZ_COMB_AGE_AND_LOS_FLAG,
2037 		FRZ_HRS_WKD_FLAG,
2038 		FRZ_LOS_FLAG,
2039 		FRZ_PCT_FL_TM_FLAG,
2040 		HRS_WKD_BNDRY_PERD_CD,
2044 		NO_MX_PRTN_OVRID_THRU_FLAG,
2041 		HRS_WKD_VAL,
2042 		LOS_UOM,
2043 		LOS_VAL,
2045 		OVRID_SVC_DT,
2046 		PCT_FL_TM_VAL,
2047 		PL_HGHLY_COMPD_FLAG,
2048 		PL_KEY_EE_FLAG,
2049 		PL_WVD_FLAG,
2050 		PRTN_END_DT,
2051 		PRTN_OVRIDN_FLAG,
2052 		PRTN_OVRIDN_RSN_CD,
2053 		PRTN_OVRIDN_THRU_DT,
2054 		PRTN_STRT_DT,
2055 		WAIT_PERD_CMPLTN_DT,
2056 		WV_CTFN_TYP_CD,
2057 		WV_PRTN_RSN_CD,
2058 		PERSON_ID,
2059 		PL_ID,
2060 		LER_ID,
2061 		PTIP_ID,
2062 		PLIP_ID,
2063 		OTHR_PL_ENRLD_ID,
2064 		PGM_ID,
2065 		ELIG_PER_ID,
2066 		OPT_ID,
2067 		ORGANIZATION_ID,
2068 		PRTT_ENRT_RSLT_ID,
2069 		PERSON_TTEE_ID,
2070 		ELIG_PER_ELCTBL_CHC_ID,
2071 		PERSON_DPNT_ID,
2072 		ELEMENT_ENTRY_VALUE_ID,
2073 		PER_IN_LER_ENDED_ID,
2074 		CVG_AMT_CALC_MTHD_ID,
2075 		ENRT_RT_ID,
2076 		ACTY_BASE_RT_ID,
2077 		OIPL_ID,
2078 		COMP_LVL_FCTR_ID,
2079 		PL_TYP_ID,
2080 		ACTL_PREM_ID,
2081 		PRTT_ENRT_RSLT_SSPNDD_ID,
2082 		ASSIGNMENT_ID,
2083 		ENRT_BNFT_ID,
2084 		BUSINESS_GROUP_ID,
2085 		LCR_ATTRIBUTE_CATEGORY,
2086 		LCR_ATTRIBUTE1,
2087 		LCR_ATTRIBUTE2,
2088 		LCR_ATTRIBUTE3,
2089 		LCR_ATTRIBUTE4,
2090 		LCR_ATTRIBUTE5,
2091 		LCR_ATTRIBUTE6,
2092 		LCR_ATTRIBUTE7,
2093 		LCR_ATTRIBUTE8,
2094 		LCR_ATTRIBUTE9,
2095 		LCR_ATTRIBUTE10,
2096 		LCR_ATTRIBUTE11,
2097 		LCR_ATTRIBUTE12,
2098 		LCR_ATTRIBUTE13,
2099 		LCR_ATTRIBUTE14,
2100 		LCR_ATTRIBUTE15,
2101 		LCR_ATTRIBUTE16,
2102 		LCR_ATTRIBUTE17,
2103 		LCR_ATTRIBUTE18,
2104 		LCR_ATTRIBUTE19,
2105 		LCR_ATTRIBUTE20,
2106 		LCR_ATTRIBUTE21,
2107 		LCR_ATTRIBUTE22,
2108 		LCR_ATTRIBUTE23,
2109 		LCR_ATTRIBUTE24,
2110 		LCR_ATTRIBUTE25,
2111 		LCR_ATTRIBUTE26,
2112 		LCR_ATTRIBUTE27,
2113 		LCR_ATTRIBUTE28,
2114 		LCR_ATTRIBUTE29,
2115 		BKUP_TBL_ID,
2116 		BKUP_TBL_TYP_CD,
2117 		PER_IN_LER_ID,
2118 		EFFECTIVE_START_DATE,
2119 		EFFECTIVE_END_DATE,
2120 		ENRT_CVG_STRT_DT,
2121 		ENRT_CVG_THRU_DT,
2122 		BNFT_AMT,
2123 		BNFT_NNMNTRY_UOM,
2124 		BNFT_ORDR_NUM,
2125 		BNFT_TYP_CD,
2126 		ENRT_MTHD_CD,
2127 		ENRT_OVRID_RSN_CD,
2128 		ENRT_OVRID_THRU_DT,
2129 		ENRT_OVRIDN_FLAG,
2130 		ERLST_DEENRT_DT,
2131 		NO_LNGR_ELIG_FLAG,
2132 		ORGNL_ENRT_DT,
2133 		PRTT_ENRT_RSLT_STAT_CD,
2134 		PRTT_IS_CVRD_FLAG,
2135 		SSPNDD_FLAG,
2136 		UOM,
2137 		ADDL_INSTRN_TXT,
2138 		AMT_DSGD_VAL,
2139 		AMT_DSGD_UOM,
2140 		DSGN_STRT_DT,
2141 		DSGN_THRU_DT,
2142 		PCT_DSGD_NUM,
2143 		PRMRY_CNTNGNT_CD,
2144 		CVG_PNDG_FLAG,
2145 		CVRD_FLAG,
2146 		ELIG_FLAG,
2147 		OVRDN_FLAG,
2148 		CVG_STRT_DT,
2149 		CVG_THRU_DT,
2150 		ELIG_STRT_DT,
2151 		ELIG_THRU_DT,
2152 		OVRDN_THRU_DT,
2153 		RT_STRT_DT,
2154 		RT_END_DT,
2155 		LCR_ATTRIBUTE30,
2156 		LAST_UPDATE_DATE,
2157 		LAST_UPDATED_BY,
2158 		LAST_UPDATE_LOGIN,
2159 		CREATED_BY,
2160 		CREATION_DATE,
2161 		REQUEST_ID,
2162 		PROGRAM_APPLICATION_ID,
2163 		PROGRAM_ID,
2164 		PROGRAM_UPDATE_DATE,
2165 		OBJECT_VERSION_NUMBER,
2166 		TTEE_PERSON_ID,
2167 		DPNT_PERSON_ID,
2168 		ONCE_R_CNTUG_CD,
2169 		DPNT_OTHR_PL_CVRD_RL_FLAG,
2170 		MUST_ENRL_ANTHR_PL_ID,
2171 		PL_ORDR_NUM,
2172 		PLIP_ORDR_NUM,
2173 		PTIP_ORDR_NUM,
2174 		OIPL_ORDR_NUM,
2175 		BNF_PERSON_ID,
2176 		RPLCS_SSPNDD_RSLT_ID,
2177 		VAL,
2178 		STD_PREM_VAL,
2179 		STD_PREM_UOM)
2180 	VALUES
2181 	       (l_prior_to_prv_rslt_lvl_bckdt.COMP_LVL_CD,
2182 		l_prior_to_prv_rslt_lvl_bckdt.DSPLY_ON_ENRT_FLAG,
2183 		l_prior_to_prv_rslt_lvl_bckdt.RT_OVRIDN_FLAG,
2184 		l_prior_to_prv_rslt_lvl_bckdt.ACTY_REF_PERD_CD,
2185 		l_prior_to_prv_rslt_lvl_bckdt.ACTY_TYP_CD,
2186 		l_prior_to_prv_rslt_lvl_bckdt.ANN_RT_VAL,
2187 		l_prior_to_prv_rslt_lvl_bckdt.BNFT_RT_TYP_CD,
2188 		l_prior_to_prv_rslt_lvl_bckdt.CMCD_REF_PERD_CD,
2189 		l_prior_to_prv_rslt_lvl_bckdt.CMCD_RT_VAL,
2190 		l_prior_to_prv_rslt_lvl_bckdt.ELCNS_MADE_DT,
2191 		l_prior_to_prv_rslt_lvl_bckdt.MLT_CD,
2192 		l_prior_to_prv_rslt_lvl_bckdt.PRTT_RT_VAL_STAT_CD,
2193 		l_prior_to_prv_rslt_lvl_bckdt.RT_OVRIDN_THRU_DT,
2194 		l_prior_to_prv_rslt_lvl_bckdt.RT_VAL,
2195 		l_prior_to_prv_rslt_lvl_bckdt.TX_TYP_CD,
2196 		l_prior_to_prv_rslt_lvl_bckdt.INELG_RSN_CD,
2197 		l_prior_to_prv_rslt_lvl_bckdt.RT_COMP_REF_AMT,
2198 		l_prior_to_prv_rslt_lvl_bckdt.RT_CMBN_AGE_N_LOS_VAL,
2199 		l_prior_to_prv_rslt_lvl_bckdt.RT_COMP_REF_UOM,
2200 		l_prior_to_prv_rslt_lvl_bckdt.RT_AGE_VAL,
2201 		l_prior_to_prv_rslt_lvl_bckdt.RT_LOS_VAL,
2202 		l_prior_to_prv_rslt_lvl_bckdt.RT_HRS_WKD_VAL,
2203 		l_prior_to_prv_rslt_lvl_bckdt.RT_HRS_WKD_BNDRY_PERD_CD,
2204 		l_prior_to_prv_rslt_lvl_bckdt.RT_AGE_UOM,
2205 		l_prior_to_prv_rslt_lvl_bckdt.RT_LOS_UOM,
2206 		l_prior_to_prv_rslt_lvl_bckdt.RT_PCT_FL_TM_VAL,
2207 		l_prior_to_prv_rslt_lvl_bckdt.RT_FRZ_LOS_FLAG,
2208 		l_prior_to_prv_rslt_lvl_bckdt.RT_FRZ_AGE_FLAG,
2209 		l_prior_to_prv_rslt_lvl_bckdt.RT_FRZ_CMP_LVL_FLAG,
2210 		l_prior_to_prv_rslt_lvl_bckdt.RT_FRZ_PCT_FL_TM_FLAG,
2211 		l_prior_to_prv_rslt_lvl_bckdt.RT_FRZ_HRS_WKD_FLAG,
2212 		l_prior_to_prv_rslt_lvl_bckdt.RT_FRZ_COMB_AGE_AND_LOS_FLAG,
2213 		l_prior_to_prv_rslt_lvl_bckdt.AGE_UOM,
2214 		l_prior_to_prv_rslt_lvl_bckdt.AGE_VAL,
2215 		l_prior_to_prv_rslt_lvl_bckdt.CMBN_AGE_N_LOS_VAL,
2216 		l_prior_to_prv_rslt_lvl_bckdt.COMP_REF_AMT,
2217 		l_prior_to_prv_rslt_lvl_bckdt.COMP_REF_UOM,
2218 		l_prior_to_prv_rslt_lvl_bckdt.DPNT_OTHER_PL_CVRD_RL_FLAG,
2219 		l_prior_to_prv_rslt_lvl_bckdt.DSTR_RSTCN_FLAG,
2223 		l_prior_to_prv_rslt_lvl_bckdt.FRZ_HRS_WKD_FLAG,
2220 		l_prior_to_prv_rslt_lvl_bckdt.FRZ_AGE_FLAG,
2221 		l_prior_to_prv_rslt_lvl_bckdt.FRZ_CMP_LVL_FLAG,
2222 		l_prior_to_prv_rslt_lvl_bckdt.FRZ_COMB_AGE_AND_LOS_FLAG,
2224 		l_prior_to_prv_rslt_lvl_bckdt.FRZ_LOS_FLAG,
2225 		l_prior_to_prv_rslt_lvl_bckdt.FRZ_PCT_FL_TM_FLAG,
2226 		l_prior_to_prv_rslt_lvl_bckdt.HRS_WKD_BNDRY_PERD_CD,
2227 		l_prior_to_prv_rslt_lvl_bckdt.HRS_WKD_VAL,
2228 		l_prior_to_prv_rslt_lvl_bckdt.LOS_UOM,
2229 		l_prior_to_prv_rslt_lvl_bckdt.LOS_VAL,
2230 		l_prior_to_prv_rslt_lvl_bckdt.NO_MX_PRTN_OVRID_THRU_FLAG,
2231 		l_prior_to_prv_rslt_lvl_bckdt.OVRID_SVC_DT,
2232 		l_prior_to_prv_rslt_lvl_bckdt.PCT_FL_TM_VAL,
2233 		l_prior_to_prv_rslt_lvl_bckdt.PL_HGHLY_COMPD_FLAG,
2234 		l_prior_to_prv_rslt_lvl_bckdt.PL_KEY_EE_FLAG,
2235 		l_prior_to_prv_rslt_lvl_bckdt.PL_WVD_FLAG,
2236 		l_prior_to_prv_rslt_lvl_bckdt.PRTN_END_DT,
2237 		l_prior_to_prv_rslt_lvl_bckdt.PRTN_OVRIDN_FLAG,
2238 		l_prior_to_prv_rslt_lvl_bckdt.PRTN_OVRIDN_RSN_CD,
2239 		l_prior_to_prv_rslt_lvl_bckdt.PRTN_OVRIDN_THRU_DT,
2240 		l_prior_to_prv_rslt_lvl_bckdt.PRTN_STRT_DT,
2241 		l_prior_to_prv_rslt_lvl_bckdt.WAIT_PERD_CMPLTN_DT,
2242 		l_prior_to_prv_rslt_lvl_bckdt.WV_CTFN_TYP_CD,
2243 		l_prior_to_prv_rslt_lvl_bckdt.WV_PRTN_RSN_CD,
2244 		l_prior_to_prv_rslt_lvl_bckdt.PERSON_ID,
2245 		l_prior_to_prv_rslt_lvl_bckdt.PL_ID,
2246 		l_prior_to_prv_rslt_lvl_bckdt.LER_ID,
2247 		l_prior_to_prv_rslt_lvl_bckdt.PTIP_ID,
2248 		l_prior_to_prv_rslt_lvl_bckdt.PLIP_ID,
2249 		l_prior_to_prv_rslt_lvl_bckdt.OTHR_PL_ENRLD_ID,
2250 		l_prior_to_prv_rslt_lvl_bckdt.PGM_ID,
2251 		l_prior_to_prv_rslt_lvl_bckdt.ELIG_PER_ID,
2252 		l_prior_to_prv_rslt_lvl_bckdt.OPT_ID,
2253 		l_prior_to_prv_rslt_lvl_bckdt.ORGANIZATION_ID,
2254 		l_prior_to_prv_rslt_lvl_bckdt.PRTT_ENRT_RSLT_ID,
2255 		l_prior_to_prv_rslt_lvl_bckdt.PERSON_TTEE_ID,
2256 		l_prior_to_prv_rslt_lvl_bckdt.ELIG_PER_ELCTBL_CHC_ID,
2257 		l_prior_to_prv_rslt_lvl_bckdt.PERSON_DPNT_ID,
2258 		l_prior_to_prv_rslt_lvl_bckdt.ELEMENT_ENTRY_VALUE_ID,
2259 		l_prv_per_in_ler_id,
2260 		l_prior_to_prv_rslt_lvl_bckdt.CVG_AMT_CALC_MTHD_ID,
2261 		l_prior_to_prv_rslt_lvl_bckdt.ENRT_RT_ID,
2262 		l_prior_to_prv_rslt_lvl_bckdt.ACTY_BASE_RT_ID,
2263 		l_prior_to_prv_rslt_lvl_bckdt.OIPL_ID,
2264 		l_prior_to_prv_rslt_lvl_bckdt.COMP_LVL_FCTR_ID,
2265 		l_prior_to_prv_rslt_lvl_bckdt.PL_TYP_ID,
2266 		l_prior_to_prv_rslt_lvl_bckdt.ACTL_PREM_ID,
2267 		l_prior_to_prv_rslt_lvl_bckdt.PRTT_ENRT_RSLT_SSPNDD_ID,
2268 		l_prior_to_prv_rslt_lvl_bckdt.ASSIGNMENT_ID,
2269 		l_prior_to_prv_rslt_lvl_bckdt.ENRT_BNFT_ID,
2270 		l_prior_to_prv_rslt_lvl_bckdt.BUSINESS_GROUP_ID,
2271 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE_CATEGORY,
2272 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE1,
2273 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE2,
2274 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE3,
2275 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE4,
2276 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE5,
2277 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE6,
2278 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE7,
2279 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE8,
2280 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE9,
2281 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE10,
2282 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE11,
2283 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE12,
2284 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE13,
2285 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE14,
2286 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE15,
2287 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE16,
2288 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE17,
2289 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE18,
2290 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE19,
2291 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE20,
2292 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE21,
2293 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE22,
2294 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE23,
2295 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE24,
2296 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE25,
2297 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE26,
2298 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE27,
2299 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE28,
2300 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE29,
2301 		l_prior_to_prv_rslt_lvl_bckdt.BKUP_TBL_ID,
2302 		'BEN_PRTT_ENRT_RSLT_F_CORR',
2303 		l_prior_to_prv_rslt_lvl_bckdt.PER_IN_LER_ID,
2304 		l_prior_to_prv_rslt_lvl_bckdt.EFFECTIVE_START_DATE,
2305 		l_prior_to_prv_rslt_lvl_bckdt.EFFECTIVE_END_DATE,
2306 		l_prior_to_prv_rslt_lvl_bckdt.ENRT_CVG_STRT_DT,
2307 		l_prior_to_prv_rslt_lvl_bckdt.ENRT_CVG_THRU_DT,
2308 		l_prior_to_prv_rslt_lvl_bckdt.BNFT_AMT,
2309 		l_prior_to_prv_rslt_lvl_bckdt.BNFT_NNMNTRY_UOM,
2310 		l_prior_to_prv_rslt_lvl_bckdt.BNFT_ORDR_NUM,
2311 		l_prior_to_prv_rslt_lvl_bckdt.BNFT_TYP_CD,
2312 		l_prior_to_prv_rslt_lvl_bckdt.ENRT_MTHD_CD,
2313 		l_prior_to_prv_rslt_lvl_bckdt.ENRT_OVRID_RSN_CD,
2314 		l_prior_to_prv_rslt_lvl_bckdt.ENRT_OVRID_THRU_DT,
2315 		l_prior_to_prv_rslt_lvl_bckdt.ENRT_OVRIDN_FLAG,
2316 		l_prior_to_prv_rslt_lvl_bckdt.ERLST_DEENRT_DT,
2317 		l_prior_to_prv_rslt_lvl_bckdt.NO_LNGR_ELIG_FLAG,
2318 		l_prior_to_prv_rslt_lvl_bckdt.ORGNL_ENRT_DT,
2319 		l_prior_to_prv_rslt_lvl_bckdt.PRTT_ENRT_RSLT_STAT_CD,
2320 		l_prior_to_prv_rslt_lvl_bckdt.PRTT_IS_CVRD_FLAG,
2321 		l_prior_to_prv_rslt_lvl_bckdt.SSPNDD_FLAG,
2322 		l_prior_to_prv_rslt_lvl_bckdt.UOM,
2323 		l_prior_to_prv_rslt_lvl_bckdt.ADDL_INSTRN_TXT,
2324 		l_prior_to_prv_rslt_lvl_bckdt.AMT_DSGD_VAL,
2325 		l_prior_to_prv_rslt_lvl_bckdt.AMT_DSGD_UOM,
2326 		l_prior_to_prv_rslt_lvl_bckdt.DSGN_STRT_DT,
2327 		l_prior_to_prv_rslt_lvl_bckdt.DSGN_THRU_DT,
2328 		l_prior_to_prv_rslt_lvl_bckdt.PCT_DSGD_NUM,
2329 		l_prior_to_prv_rslt_lvl_bckdt.PRMRY_CNTNGNT_CD,
2330 		l_prior_to_prv_rslt_lvl_bckdt.CVG_PNDG_FLAG,
2331 		l_prior_to_prv_rslt_lvl_bckdt.CVRD_FLAG,
2332 		l_prior_to_prv_rslt_lvl_bckdt.ELIG_FLAG,
2333 		l_prior_to_prv_rslt_lvl_bckdt.OVRDN_FLAG,
2334 		l_prior_to_prv_rslt_lvl_bckdt.CVG_STRT_DT,
2335 		l_prior_to_prv_rslt_lvl_bckdt.CVG_THRU_DT,
2339 		l_prior_to_prv_rslt_lvl_bckdt.RT_STRT_DT,
2336 		l_prior_to_prv_rslt_lvl_bckdt.ELIG_STRT_DT,
2337 		l_prior_to_prv_rslt_lvl_bckdt.ELIG_THRU_DT,
2338 		l_prior_to_prv_rslt_lvl_bckdt.OVRDN_THRU_DT,
2340 		l_prior_to_prv_rslt_lvl_bckdt.RT_END_DT,
2341 		l_prior_to_prv_rslt_lvl_bckdt.LCR_ATTRIBUTE30,
2342 		l_prior_to_prv_rslt_lvl_bckdt.LAST_UPDATE_DATE,
2343 		l_prior_to_prv_rslt_lvl_bckdt.LAST_UPDATED_BY,
2344 		l_prior_to_prv_rslt_lvl_bckdt.LAST_UPDATE_LOGIN,
2345 		l_prior_to_prv_rslt_lvl_bckdt.CREATED_BY,
2346 		l_prior_to_prv_rslt_lvl_bckdt.CREATION_DATE,
2347 		l_prior_to_prv_rslt_lvl_bckdt.REQUEST_ID,
2348 		l_prior_to_prv_rslt_lvl_bckdt.PROGRAM_APPLICATION_ID,
2349 		l_prior_to_prv_rslt_lvl_bckdt.PROGRAM_ID,
2350 		l_prior_to_prv_rslt_lvl_bckdt.PROGRAM_UPDATE_DATE,
2351 		l_prior_to_prv_rslt_lvl_bckdt.OBJECT_VERSION_NUMBER,
2352 		l_prior_to_prv_rslt_lvl_bckdt.TTEE_PERSON_ID,
2353 		l_prior_to_prv_rslt_lvl_bckdt.DPNT_PERSON_ID,
2354 		l_prior_to_prv_rslt_lvl_bckdt.ONCE_R_CNTUG_CD,
2355 		l_prior_to_prv_rslt_lvl_bckdt.DPNT_OTHR_PL_CVRD_RL_FLAG,
2356 		l_prior_to_prv_rslt_lvl_bckdt.MUST_ENRL_ANTHR_PL_ID,
2357 		l_prior_to_prv_rslt_lvl_bckdt.PL_ORDR_NUM,
2358 		l_prior_to_prv_rslt_lvl_bckdt.PLIP_ORDR_NUM,
2359 		l_prior_to_prv_rslt_lvl_bckdt.PTIP_ORDR_NUM,
2360 		l_prior_to_prv_rslt_lvl_bckdt.OIPL_ORDR_NUM,
2361 		l_prior_to_prv_rslt_lvl_bckdt.BNF_PERSON_ID,
2362 		l_prior_to_prv_rslt_lvl_bckdt.RPLCS_SSPNDD_RSLT_ID,
2363 		l_prior_to_prv_rslt_lvl_bckdt.VAL,
2364 		l_prior_to_prv_rslt_lvl_bckdt.STD_PREM_VAL,
2365 		l_prior_to_prv_rslt_lvl_bckdt.STD_PREM_UOM);
2366 		--
2367 		hr_utility.set_location('Inserted corrected Row', 44333);
2368 		--
2369 	   UPDATE ben_le_clsn_n_rstr
2370 	   SET    per_in_ler_id = l_prv_per_in_ler_id
2371 	   WHERE  per_in_ler_id = l_prior_to_prv_rslt_lvl_bckdt.per_in_ler_id
2372 	   AND    bkup_tbl_id = l_prior_to_prv_rslt_lvl_bckdt.bkup_tbl_id
2373 	   AND    bkup_tbl_typ_cd = 'BEN_PRTT_ENRT_RSLT_F'
2374 	   AND    business_group_id = p_business_group_id
2375 	   AND    prtt_enrt_rslt_stat_cd IS NULL
2376 	   AND    effective_end_date = hr_api.g_eot
2377            AND    enrt_cvg_strt_dt > l_prv_lf_evt_ocrd_dt
2378            AND    enrt_cvg_strt_dt <  effective_end_date;
2379 	   --
2380 	   hr_utility.set_location ('updated bkup table table with prev per_in_ler', 44333);
2381 	   --
2382 
2383 	 end loop;
2384 
2385 	      -- added till here bug 7039025
2386 
2387 
2388               hr_utility.set_location ('restoring result ' , 99 );
2389               ben_lf_evt_clps_restore.reinstate_the_prev_enrt_rslt(
2390                              p_person_id           => l_pil_stat.person_id
2391                             ,p_business_group_id   => p_business_group_id
2392                             ,p_ler_id              => l_pil_stat.ler_id
2393                             ,p_effective_date      => l_prv_lf_evt_ocrd_dt
2394                             ,p_per_in_ler_id       => l_prv_per_in_ler_id
2395                             ,p_bckdt_per_in_ler_id => l_prv_per_in_ler_id
2396                            )  ;
2397               -- once the result level backedout data is restored
2398               -- delete the data from the backout table
2399               delete from  ben_le_clsn_n_rstr
2400               where  per_in_ler_id = l_prv_per_in_ler_id
2401               AND  business_group_id = p_business_group_id ;
2402 
2403 
2404               hr_utility.set_location ('status to closed' , 99 );
2405            end if ;
2406            --
2407            --Restore Future completed Action Items
2408            --
2409            restore_cert_completion(p_per_in_ler_id);
2410            --
2411         end if ;
2412         -- 2982606
2413 
2414       end if;  -- p_bckdt_prtt_enrt_rslt_id
2415       -- Bug 2526994 This needs to be reset once the process is done.
2416       g_backout_flag  := null ;
2417       --
2418   end if;
2419   hr_utility.set_location ('Leaving '||l_package,99);
2420   --
2421 exception
2422   when others then
2423       --
2424       -- Bug 4919951 - Reset the flag if any exception raised
2425       --
2426       g_backout_flag  := null ;
2427       hr_utility.set_location('Flag g_backout_flag Reset', 9999);
2428       raise;
2429       --
2430    --
2431 end back_out_life_events;
2432 --
2433 procedure unprocess_susp_enrt_past_pil(p_prtt_enrt_rslt_id in number,
2434                                        p_per_in_ler_id     in number,
2435                                        p_business_group_id in number) is
2436 --
2437   cursor c_get_past_pil (p_per_in_ler_id number) is
2438   select max(pea.per_in_ler_id)
2439   from   ben_prtt_enrt_actn_f pea,
2440          ben_per_in_ler pil
2441   where  pea.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
2442   and    pea.per_in_ler_id <> p_per_in_ler_id
2443   and    pea.business_group_id = p_business_group_id
2444   and    pea.per_in_ler_id = pil.per_in_ler_id
2445   and    pil.per_in_ler_stat_cd not in ('BCKDT', 'VOIDD');
2446   --bug 5187145 added subquery
2447   CURSOR c_actn_item_for_past_pil (p_per_in_ler_id NUMBER)
2448    IS
2449       SELECT   prtt_enrt_actn_id, effective_start_date,
2450                object_version_number
2451           FROM ben_prtt_enrt_actn_f
2452          WHERE per_in_ler_id = p_per_in_ler_id
2453            AND prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
2454            AND effective_end_date < hr_api.g_eot
2455            AND business_group_id = p_business_group_id
2456            AND prtt_enrt_actn_id not in
2457                   (SELECT prtt_enrt_actn_id
2458                      FROM ben_prtt_enrt_actn_f
2459                     WHERE per_in_ler_id = p_per_in_ler_id
2460                       AND prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
2461                       AND cmpltd_dt IS NOT NULL)
2462       ORDER BY prtt_enrt_actn_id;
2463   l_actn_item                     c_actn_item_for_past_pil%rowtype;
2464   --
2468   where  prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
2465   cursor c_enrt_ctfn_for_past_pil (p_prtt_enrt_actn_id number) is
2466   select prtt_enrt_ctfn_prvdd_id, effective_start_date, object_version_number
2467   from   ben_prtt_enrt_ctfn_prvdd_f
2469   and    prtt_enrt_actn_id = p_prtt_enrt_actn_id
2470   and    effective_end_date < hr_api.g_eot
2471   and    business_group_id = p_business_group_id;
2472   l_enrt_ctfn                     c_enrt_ctfn_for_past_pil%rowtype;
2473   --
2474   cursor c_check_prem_active is
2475   select 1
2476   from   ben_prtt_prem_f
2477   where  prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
2478   and    effective_end_date = hr_api.g_eot;
2479   l_check_prem_active             c_check_prem_active%rowtype;
2480   --
2481   cursor c_ended_prem_details is
2482   select ppm.prtt_prem_id, ppm.effective_start_date, ppm.object_version_number
2483   from   ben_prtt_prem_f ppm
2487                      from   ben_prtt_prem_f ppm2
2484   where  ppm.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
2485   and    ppm.effective_end_date <> hr_api.g_eot
2486   and    not exists (select 1
2488                      where  ppm2.prtt_prem_id = ppm.prtt_prem_id
2489                      and    ppm2.effective_end_date > ppm.effective_end_date)
2490   order by effective_start_date desc;
2491   l_ended_prem_details            c_ended_prem_details%rowtype;
2492   --
2493   l_proc                          varchar2(80) := g_package||'.unprocess_susp_enrt_past_pil';
2494   l_per_in_ler_id                 number;
2495   l_prtt_enrt_actn_id             number;
2496   l_effective_start_date          date;
2497   l_effective_end_date            date;
2498   l_object_version_number         number;
2499   l_ppe_object_version_number     number;
2500   l_prev_prtt_enrt_actn_id        number;
2501   l_prev_enrt_ctfn_prvdd_id       number;
2502   --
2503 begin
2504   --
2505   hr_utility.set_location ('Entering ' || l_proc , 1230);
2506   l_per_in_ler_id := p_per_in_ler_id;
2507   --
2508   l_prev_prtt_enrt_actn_id := -1;
2509   l_prev_enrt_ctfn_prvdd_id := -1;
2510   --
2511   for l_actn_item in c_actn_item_for_past_pil (l_per_in_ler_id) loop
2512   --
2513      l_prtt_enrt_actn_id := l_actn_item.prtt_enrt_actn_id;
2514      --
2515      -- Un-enddate action item record
2516      --
2517      l_object_version_number := l_actn_item.object_version_number;
2518      --
2519      hr_utility.set_location('ACE l_prev_prtt_enrt_actn_id = ' || l_prev_prtt_enrt_actn_id, 9999);
2520      hr_utility.set_location('ACE l_prtt_enrt_actn_id = ' || l_prtt_enrt_actn_id, 9999);
2521      if l_prev_prtt_enrt_actn_id <> l_prtt_enrt_actn_id
2522      then
2523        --
2524        -- Bug 4642315 : Cursor C_ACTN_ITEM_FOR_PAST_PIL will pick up multiple datetracked
2525        --               records for same PRTT_ENRT_ACTN_ID. So once we modify one PEA record
2526        --               it will be valid till EOT and other datetracked records would have
2527        --               been deleted. Hence call DEL only once for a PEA_Id
2528        --
2529        l_prev_prtt_enrt_actn_id := l_prtt_enrt_actn_id;
2530        --
2531        ben_pea_del.del(
2532                        p_prtt_enrt_actn_id => l_actn_item.prtt_enrt_actn_id,
2533                        p_effective_start_date => l_effective_start_date,
2534                        p_effective_end_date => l_effective_end_date,
2535                        p_object_version_number => l_object_version_number,
2536                        p_effective_date => l_actn_item.effective_start_date,
2537                        p_datetrack_mode => hr_api.g_future_change);
2538        --
2539      end if;
2540      --
2541      hr_utility.set_location('ACE l_actn_item.prtt_enrt_actn_id = ' || l_actn_item.prtt_enrt_actn_id, 8888);
2542      --
2543      -- Un-enddate enrollment certification record(s)
2544      --
2545      l_prev_enrt_ctfn_prvdd_id := -1;
2546      --
2547      for l_enrt_ctfn in c_enrt_ctfn_for_past_pil (l_prtt_enrt_actn_id) loop
2548      --
2549         l_object_version_number := l_enrt_ctfn.object_version_number;
2550         --
2551         if l_prev_enrt_ctfn_prvdd_id <> l_enrt_ctfn.prtt_enrt_ctfn_prvdd_id
2552         then
2553           --
2554           -- Bug Bug 4642315 :
2555           --
2556           l_prev_enrt_ctfn_prvdd_id := l_enrt_ctfn.prtt_enrt_ctfn_prvdd_id;
2557           --
2558           ben_pcs_del.del(
2559                           p_prtt_enrt_ctfn_prvdd_id => l_enrt_ctfn.prtt_enrt_ctfn_prvdd_id,
2560                           p_effective_start_date => l_effective_start_date,
2561                           p_effective_end_date => l_effective_end_date,
2562                           p_object_version_number => l_object_version_number,
2563                           p_effective_date => l_enrt_ctfn.effective_start_date,
2564                           p_datetrack_mode => hr_api.g_future_change);
2565           --
2566         end if;
2570   --
2567         --
2568      --
2569      end loop;
2571   end loop;
2572   --
2573   -- Process premium, if ended (will be needed for ineligible/due date past cases)
2574   --
2575   open c_check_prem_active;
2576   fetch c_check_prem_active into l_check_prem_active;
2577   if c_check_prem_active%notfound then
2578      --
2579      -- Unend most recent premiums
2580      --
2581      for l_ended_prem_details in c_ended_prem_details loop
2582         l_ppe_object_version_number := l_ended_prem_details.object_version_number;
2583         ben_ppe_del.del(
2584                         p_prtt_prem_id => l_ended_prem_details.prtt_prem_id,
2585                         p_effective_start_date => l_effective_start_date,
2586                         p_effective_end_date => l_effective_end_date,
2587                         p_object_version_number => l_ppe_object_version_number,
2588                         p_effective_date => l_ended_prem_details.effective_start_date,
2589                         p_datetrack_mode => hr_api.g_future_change);
2590      end loop;
2591      --
2592   end if;
2593   close c_check_prem_active;
2594   --
2595   hr_utility.set_location ('Leaving ' || l_proc, 1230);
2596 end unprocess_susp_enrt_past_pil;
2597 -- CFW
2598 --
2599 -- This function has been added as part of fix for bug 2518955
2600 --
2601 -- ----------------------------------------------------------------------------
2602 -- |------------------------< get_msg_name  >---------------------------------|
2603 -- ----------------------------------------------------------------------------
2604 FUNCTION get_msg_name RETURN VARCHAR2 IS
2605 
2606   l_encoded_msg		VARCHAR2(3000);
2607   l_msg_name		VARCHAR2(30);
2608   l_msg_app		VARCHAR2(50);
2609   l_proc 		VARCHAR2(72) := g_package||'get_msg_name';
2610 
2611 BEGIN
2612   -- hr_utility.set_location('Entering:'|| l_proc, 10);
2613 
2614   l_encoded_msg := fnd_message.get_encoded();
2615   fnd_message.parse_encoded(
2616                 	    encoded_message => l_encoded_msg
2617                 	   ,app_short_name  => l_msg_app      -- OUT
2618                 	   ,message_name    => l_msg_name     -- OUT
2619                 	   );
2620 
2621   -- hr_utility.set_location('Leaving:'|| l_proc, 20);
2622 
2623   RETURN l_msg_name;
2624 
2625 END; -- get_msg_name
2626 
2627 procedure adj_prv_rate (p_person_id  number,
2628                         p_prtt_rt_val_id  number,
2629                         p_rt_end_dt     date,
2630                         p_object_version_number number,
2631                         p_business_group_id number,
2632                         p_effective_date date) is
2633 --
2634  cursor c_future_prv is
2635    select prv.*
2636    from ben_prtt_rt_val prv,
2637         ben_prtt_enrt_rslt_f pen,
2638         ben_acty_base_rt_f abr
2642    and   prv.rt_strt_dt > p_rt_end_dt
2639    where prv.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
2640    and   pen.person_id = p_person_id
2641    and   prv.prtt_rt_val_stat_cd is null
2643    and   pen.prtt_enrt_rslt_stat_cd is null
2644    and   prv.acty_base_rt_id = abr.acty_base_rt_id
2645    and   abr.element_type_id =
2646         (select element_type_id  from ben_acty_base_rt_f abr2,
2647                                       ben_prtt_rt_val prv2
2648          where abr2.acty_base_rt_id = prv2.acty_base_rt_id
2649          and   prv2.prtt_rt_val_id = p_prtt_rt_val_id
2650          and   prv2.rt_strt_dt between abr2.effective_start_date
2651                and abr2.effective_end_date)
2652   and   prv.rt_strt_dt between abr.effective_start_date
2653                and abr.effective_end_date
2654   and   pen.effective_end_Date = hr_api.g_eot;
2655  --
2656  l_prv  c_future_prv%rowtype;
2657  --
2658  cursor c_element (p_element_entry_value_id number) is
2659    select pee.element_entry_id,
2660           pee.effective_start_date,
2661           pee.effective_end_date,
2662           pee.object_version_number
2663    from   pay_element_entries_f pee,
2664        pay_element_entry_values_f pev
2665    where pev.element_entry_value_id = p_element_entry_value_id
2666    and   pev.element_entry_id = pee.element_entry_id
2667    order by pee.effective_start_date;
2668  --
2669  l_element   c_element%rowtype;
2670  l_delete_warning  boolean;
2671  l_object_version_number number;
2672  l_dummy_number    number;
2673  l_element_start_date date;
2674  --
2675 begin
2676   --
2677   hr_utility.set_location('Entering Adj Prv rate',10);
2678   open c_future_prv;
2679   fetch c_future_prv into l_prv;
2680   close c_future_prv;
2681   --
2682   if l_prv.element_entry_value_id is not null then
2683      --
2687      close c_element;
2684      hr_utility.set_location('value Id is not null',11);
2685      open c_element (l_prv.element_entry_value_id);
2686      fetch c_element into l_element;
2688      --
2689      hr_utility.set_location('effective date'||l_element.effective_start_date,10);
2690      l_element_start_date := l_element.effective_start_date;
2691      py_element_entry_api.delete_element_entry
2692         (p_validate => false
2693         ,p_datetrack_delete_mode => hr_api.g_zap
2694         ,p_effective_date        => l_element_start_date
2695         ,p_element_entry_id      => l_element.element_entry_id
2696         ,p_object_version_number => l_element.object_version_number
2697         ,p_effective_start_date  => l_element.effective_start_date
2698         ,p_effective_end_date    => l_element.effective_end_date
2699         ,p_delete_warning        => l_delete_warning
2700         );
2701     --
2702   end if;
2703   -- adjust the rate
2704   l_object_version_number := p_object_version_number;
2705   hr_utility.set_location ('Adjust old rate',12);
2706   ben_prtt_rt_val_api.update_prtt_rt_val
2707            (P_PRTT_RT_VAL_ID          => p_prtt_rt_val_id
2708            ,P_RT_END_DT               => p_rt_END_DT
2709            ,p_person_id               => p_person_id
2710            ,p_business_group_id       => p_business_group_id
2711            ,P_OBJECT_VERSION_NUMBER   => l_object_version_number
2712            ,P_EFFECTIVE_DATE          => p_effective_date
2713            );
2714         --
2715 
2716   if l_prv.element_entry_value_id is not null then
2717     --
2718     hr_utility.set_location ('Recreate element ',14);
2719     ben_element_entry.create_enrollment_element
2720      (p_business_group_id        => p_business_group_id
2721      ,p_prtt_rt_val_id           => l_prv.prtt_rt_val_id
2722      ,p_person_id                => p_person_id
2723      ,p_acty_ref_perd            => l_prv.acty_ref_perd_cd
2724      ,p_acty_base_rt_id          => l_prv.acty_base_rt_id
2725      ,p_enrt_rslt_id             => l_prv.prtt_enrt_rslt_id
2726      ,p_rt_start_date            => l_prv.rt_strt_dt
2727      ,p_rt                       => l_prv.rt_val
2728      ,p_cmncd_rt                 => l_prv.cmcd_rt_val
2729      ,p_ann_rt                   => l_prv.ann_rt_val
2730     -- ,p_input_value_id           => p_input_value_id
2731     -- ,p_element_type_id          => p_element_type_id
2732      ,p_prv_object_version_number=> l_prv.object_version_number
2733      ,p_effective_date           => l_prv.rt_strt_dt
2734      ,p_eev_screen_entry_value   => l_dummy_number
2735      ,p_element_entry_value_id   => l_dummy_number
2736       );
2737     --
2738   end if;
2739   hr_utility.set_location ('Leaving Adjust rate',15);
2740 end;
2741 --
2742 -- Added for bug 7206471
2743 --
2744 procedure adj_pen_cvg (p_person_id  number,
2745                         p_prtt_enrt_rslt_id number,
2746                         p_cvg_end_dt     date,
2747                         p_object_version_number number,
2748                         p_business_group_id number,
2749                         p_effective_date date) is
2750   --
2751 
2752   --
2753  l_object_version_number number;
2754  l_dummy_number          number;
2755  l_effective_start_date  date;
2756  l_effective_end_date    date;
2757  --
2758  --
2759 begin
2760   --
2761   hr_utility.set_location('Entering Adj Pen Cvg',44333);
2762   --
2763   --
2764 -- adjust the coverage
2765   l_object_version_number := p_object_version_number;
2766   hr_utility.set_location ('Adjust old coverage',44333);
2767  ben_prtt_enrt_result_api.update_prtt_enrt_result
2768               (p_validate                 => FALSE,
2769                p_prtt_enrt_rslt_id        => p_prtt_enrt_rslt_id,
2770                p_effective_start_date     => l_effective_start_date,
2771                p_effective_end_date       => l_effective_end_date,
2772                p_business_group_id        => p_business_group_id,
2773                p_object_version_number    => l_object_version_number,
2774                p_effective_date           => p_effective_date,
2775                p_datetrack_mode           => hr_api.g_correction,
2776                p_multi_row_validate       => FALSE,
2777 	       p_enrt_cvg_thru_dt         => p_cvg_end_dt
2778                );
2779         --
2780 hr_utility.set_location ('Leaving Adj Pen Cvg',44333);
2781 end;
2782 -- End bug 7206471
2783 
2784 -- When  Open LE processed then a LE processed before open starts
2785 -- then Open is reprocessed on the same date LE is processed
2786 -- open enrolled in the same date. in this case LE result is
2787 -- updated with Open PIL_ID. if open  backedout again, result of the LE
2788 -- is last. this is fixed by copying LE result into backup table
2789 -- and copied back if open is backedout  - tilak
2790 
2791 
2792 --
2793 -- Split the routine into operations that way it can be called by any
2794 -- external routine. Simply pass the tablename and the deletes will
2798 procedure delete_routine(p_routine                in varchar2,
2795 -- happen, a tad dangerous as you must do the deletes in the correct
2796 -- order as otherwise FK's will be hanging.
2797 --
2799                          p_per_in_ler_id          in number,
2800                          p_business_group_id      in number,
2801                          p_bckdt_prtt_enrt_rslt_id in number default null,
2802                          p_copy_only               in varchar2 default null,
2803                          p_effective_date          in date) is
2804   --
2805   l_package   varchar2(80) := g_package||'.delete_routine';
2806   --
2807   --
2808   -- START ----> DELETE ROUTINE FOR BEN_ELIG_PER_OPT_F
2809   --
2810   -- Source Table
2811   -- BEN_PER_IN_LER
2812   --
2813   cursor c_ben_ELIG_PER_OPT_f is
2814     select epo.ELIG_PER_OPT_id,
2815            epo.object_version_number,
2816 		   epo.effective_start_date --AMN bug 12732878
2817     from   ben_ELIG_PER_OPT_f epo,
2818            ben_per_in_ler pil
2819     where  pil.per_in_ler_id = p_per_in_ler_id
2820     and    pil.business_group_id = p_business_group_id
2821     and    epo.per_in_ler_id = pil.per_in_ler_id
2822     and    epo.business_group_id = pil.business_group_id
2823     --
2824     -- Do not use the effective date check, see
2825     -- comments at c_ben_prtt_enrt_rslt_f
2826     -- Rows should be selected based on per in ler only.
2827     --
2828     /*
2829     -- RCHASE Bug#5364 Must use pil.lf_evt_ocrd_dt instead of p_effective_date
2830     -- and    p_effective_date
2831     and    pil.lf_evt_ocrd_dt
2832            between epo.effective_start_date
2833            and     epo.effective_end_date */
2834     order by 1;
2835   --
2836   -- The cursor gets the maximum effective end date for the dependents
2837   -- with past per_in_ler 's
2838   --
2839   -- RCHASE 5364 - Update cursor to fetch appropriate rows
2840   -- Previous cursor definition
2841   --cursor c_epo_max_esd_of_past_pil(v_ELIG_PER_OPT_id in number) is
2842   --  select max(effective_end_date), max(object_version_number)
2843   --  from   ben_ELIG_PER_OPT_f
2844   --  where  ELIG_PER_OPT_id       =  v_ELIG_PER_OPT_id
2845   --  and    nvl(per_in_ler_id , -1) <> p_per_in_ler_id
2846   --  and    business_group_id   =  p_business_group_id;
2847     -- and    effective_end_date      <  p_effective_date;
2848   -- New cursor definition
2849 /*
2850     cursor c_epo_max_esd_of_past_pil(v_ELIG_PER_OPT_id in number) is
2851     select max(epo.effective_end_date), max(epo.object_version_number)
2852     from   ben_ELIG_PER_OPT_f epo
2853     where  epo.ELIG_PER_OPT_id       =  v_ELIG_PER_OPT_id
2854     --RCHASE 5364
2855     and    nvl(per_in_ler_id , -1) <> p_per_in_ler_id
2856     and    epo.business_group_id   =  p_business_group_id;
2857     --
2858     -- Do not use the effective date check, see
2859     -- comments at c_ben_prtt_enrt_rslt_f
2860     -- Rows should be selected based on per in ler only.
2861     --
2862 */
2863     /*
2864     --RCHASE 5364
2865     and    epo.effective_end_date <= (select lf_evt_ocrd_dt
2866                                         from ben_per_in_ler
2867                                        where per_in_ler_id = p_per_in_ler_id); */
2868   --
2869   cursor c_epo_max_esd_of_past_pil(v_ELIG_PER_OPT_id in number) is
2870      select epo.effective_end_date, epo.object_version_number
2871      from   ben_ELIG_PER_OPT_f epo,
2872             ben_per_in_ler pil
2873      where  epo.ELIG_PER_OPT_id       =  v_ELIG_PER_OPT_id
2874      and    nvl(epo.per_in_ler_id , -1) <> p_per_in_ler_id
2875      and    epo.business_group_id   =  p_business_group_id
2876      and    epo.per_in_ler_id = pil.per_in_ler_id
2877      and    pil.per_in_ler_stat_cd not in ('BCKDT','VOIDD')
2878      order by epo.effective_end_date desc;
2879 
2880   --
2881   -- Move deleted records to backup table
2882   --
2883   cursor c_deleted_epo(v_elig_per_opt_id in number,
2884                        v_effective_date    in date) is
2885     select *
2886     from   ben_elig_per_opt_f
2887     where  elig_per_opt_id         =  v_elig_per_opt_id
2891 
2888     and    nvl(per_in_ler_id , -1) =  p_per_in_ler_id
2889     and    business_group_id   =  p_business_group_id
2890     and    effective_end_date      > v_effective_date;
2892 
2893   --
2894   -- END ----> DELETE ROUTINE FOR BEN_ELIG_PER_OPT_F
2895   --
2896   -- START ----> DELETE ROUTINE FOR BEN_ELIG_PER_F
2897   --
2898   -- Source Table
2899   -- BEN_PER_IN_LER
2900   --
2901   cursor c_ben_elig_per_f is
2902     select pep.elig_per_id,
2903            pep.object_version_number,
2904 		   pep.effective_start_date --AMN bug 12732878
2905     from   ben_elig_per_f pep,
2906            ben_per_in_ler pil
2907     where  pil.per_in_ler_id = p_per_in_ler_id
2908     and    pil.business_group_id = p_business_group_id
2909     and    pep.per_in_ler_id = pil.per_in_ler_id
2910     and    pep.business_group_id = pil.business_group_id
2911     --
2912     -- Do not use the effective date check, see
2913     -- comments at c_ben_prtt_enrt_rslt_f
2914     -- Rows should be selected based on per in ler only.
2915     --
2916     /*
2917     -- RCHASE Bug#5364 Must use pil.lf_evt_ocrd_dt instead of p_effective_date
2918     -- and    p_effective_date
2919     and    pil.lf_evt_ocrd_dt
2920            between pep.effective_start_date
2921            and     pep.effective_end_date
2922     */
2923     order by 1;
2924   --
2925   -- The cursor gets the maximum effective end date for the dependents
2926   -- with past per_in_ler 's
2927   --
2928 /*
2929   cursor c_pep_max_esd_of_past_pil(v_elig_per_id in number) is
2930     select max(effective_end_date), max(object_version_number)
2931     from   ben_elig_per_f
2932     where  elig_per_id       =  v_elig_per_id
2933     and    nvl(per_in_ler_id , -1) <> p_per_in_ler_id
2934     and    business_group_id   =  p_business_group_id;
2935     -- and    effective_end_date      <  p_effective_date;
2936 */
2937   cursor c_pep_max_esd_of_past_pil(v_elig_per_id in number) is
2938      select pep.effective_end_date, pep.object_version_number
2939      from   ben_elig_per_f pep,
2940             ben_per_in_ler pil
2941      where  pep.elig_per_id       =  v_elig_per_id
2942      and ((pep.per_in_ler_id <> p_per_in_ler_id
2943          and pep.per_in_ler_id is not null)
2944        or
2945          (pep.per_in_ler_id is null)
2946         )
2947      and    pep.business_group_id   =  p_business_group_id
2948      and    pep.per_in_ler_id = pil.per_in_ler_id
2949      and    pil.per_in_ler_stat_cd not in ('BCKDT','VOIDD')
2950      order by pep.effective_end_date desc;
2951 
2952 -- changed 7176884 begin
2953 Cursor c_get_enrt_mthd_cd(c_prtt_enrt_rslt_id in number) is
2954 select enrt_mthd_cd
2955 from ben_prtt_enrt_rslt_f
2956 where prtt_enrt_rslt_id = c_prtt_enrt_rslt_id
2957 and   per_in_ler_id     = p_per_in_ler_id
2958 and   business_group_id = p_business_group_id
2959 and   prtt_enrt_rslt_stat_cd is null
2960 order by effective_start_date desc;
2961 
2962 l_get_enrt_mthd_cd ben_prtt_enrt_rslt_f.enrt_mthd_cd%type;
2963 -- changed 7176884 end
2964 --
2965 --  Bug 8199189
2966 --
2967 Cursor c_get_cvg_thru_dt (p_prtt_enrt_rslt_id in number
2968                          ,p_effective_date in date) is
2969 select enrt_cvg_thru_dt
2970       ,prtt_enrt_rslt_stat_cd
2971 from ben_prtt_enrt_rslt_f pen
2972 where pen.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
2973 and   pen.business_group_id = p_business_group_id
2974 and   pen.enrt_cvg_thru_dt <> hr_api.g_eot
2975 -- and   pen.prtt_enrt_rslt_stat_cd is null
2976 and   p_effective_date
2977 between  pen.effective_start_date
2978          and pen.effective_end_date;
2979 
2980 l_cvg_thru_dt ben_prtt_enrt_rslt_f.enrt_cvg_thru_dt%type;
2981 l_prtt_enrt_rslt_stat_cd ben_prtt_enrt_rslt_f.prtt_enrt_rslt_stat_cd%type;
2982 --   end 8199189
2983   --
2984   -- Move deleted records to backup table
2985   --
2986   cursor c_deleted_pep(v_elig_per_id in number,
2987                        v_effective_date    in date) is
2988     select *
2989     from   ben_elig_per_f
2990     where  elig_per_id             =  v_elig_per_id
2991     and    nvl(per_in_ler_id , -1) =  p_per_in_ler_id
2992     and    business_group_id   =  p_business_group_id
2993     and    effective_end_date      > v_effective_date;
2994   --
2995   -- END ----> DELETE ROUTINE FOR BEN_ELIG_PER_F
2996   -- START ----> DELETE ROUTINE FOR BEN_PRTT_PREM_F
2997   --
2998   -- Source Table
2999   -- BEN_PER_IN_LER
3000   --
3001   ----7133998
3002   cursor c_ben_prtt_prem_f_corr is
3003     select ppe.*
3004     from   ben_prtt_prem_f ppe,
3005            ben_per_in_ler pil,
3006 	   BEN_LE_CLSN_N_RSTR bkup
3007     where  pil.per_in_ler_id = p_per_in_ler_id
3008     and    pil.business_group_id = p_business_group_id
3009     and    ppe.per_in_ler_id = pil.per_in_ler_id
3010     and    ppe.business_group_id = pil.business_group_id
3011     and   (p_bckdt_prtt_enrt_rslt_id is null
3012            or p_bckdt_prtt_enrt_rslt_id = ppe.prtt_enrt_rslt_id
3013           )
3014     AND   bkup.BKUP_TBL_TYP_CD = 'BEN_PRTT_PREM_F_CORR'
3015     AND   bkup.BKUP_TBL_ID = ppe.prtt_prem_id
3016     and   bkup.effective_start_date = ppe.effective_start_date
3017     and   bkup.effective_end_date = ppe.effective_end_date
3018     and   bkup.per_in_ler_ended_id = pil.per_in_ler_id;
3019 
3020   cursor c_bkp_prem_row(cv_BKUP_TBL_TYP_CD in varchar2,
3021                cv_BKUP_TBL_ID     in number,
3022                cv_effective_start_date in date,
3023 	       cv_effective_end_date in date) is
3024     select bkup.*,bkup.rowid
3025     from BEN_LE_CLSN_N_RSTR bkup
3026     where BKUP_TBL_TYP_CD = cv_BKUP_TBL_TYP_CD
3027       and BKUP_TBL_ID     = cv_BKUP_TBL_ID
3028       and effective_start_date = cv_effective_start_date
3029       and effective_end_date = cv_effective_end_date
3033   cursor c_ben_prtt_prem_f is
3030       and per_in_ler_ended_id = p_per_in_ler_id
3031     order by effective_start_date;
3032   --------7133998
3034     select ppe.prtt_prem_id,
3035            ppe.object_version_number
3036     from   ben_prtt_prem_f ppe,
3037            ben_per_in_ler pil
3038     where  pil.per_in_ler_id = p_per_in_ler_id
3039     and    pil.business_group_id = p_business_group_id
3040     and    ppe.per_in_ler_id = pil.per_in_ler_id
3041     and    ppe.business_group_id = pil.business_group_id
3042     --
3043     -- Do not use the effective date check, see
3044     -- comments at c_ben_prtt_enrt_rslt_f
3045     -- Rows should be selected based on per in ler only.
3046     --
3047     /*
3048     and    p_effective_date
3049            between ppe.effective_start_date
3050            and     ppe.effective_end_date */
3051     --    # 2982606 added for result level backout
3052     and   (p_bckdt_prtt_enrt_rslt_id is null
3053            or p_bckdt_prtt_enrt_rslt_id = ppe.prtt_enrt_rslt_id
3054           )
3055     order by 1;
3056   --
3057   -- The cursor gets the maximum effective end date for the dependents
3058   -- with past per_in_ler 's
3059   --
3060   /*
3061   cursor c_ppe_max_esd_of_past_pil(v_prtt_prem_id in number) is
3062     select max(effective_end_date), max(object_version_number)
3063     from   ben_prtt_prem_f
3064     where  prtt_prem_id       =  v_prtt_prem_id
3065     and    nvl(per_in_ler_id , -1) <> p_per_in_ler_id
3066     and    business_group_id   =  p_business_group_id;
3067     -- and    effective_end_date      <  p_effective_date;
3068  */
3069   cursor c_ppe_max_esd_of_past_pil(v_prtt_prem_id in number) is
3070     select prm.effective_end_date, prm.object_version_number
3071     from   ben_prtt_prem_f prm,
3072            ben_per_in_ler pil
3073      where  prm.prtt_prem_id  =  v_prtt_prem_id
3074      and    nvl(prm.per_in_ler_id , -1) <> p_per_in_ler_id
3075      and    prm.business_group_id   =  p_business_group_id
3076      and    prm.per_in_ler_id = pil.per_in_ler_id
3077      and    pil.per_in_ler_stat_cd not in ('BCKDT','VOIDD')
3078      order by prm.effective_end_date desc;
3079 
3080 
3081   cursor c_deleted_ppe(v_prtt_prem_id in number,
3082                        v_effective_date    in date) is
3083     select *
3084     from   ben_prtt_prem_f
3085     where  prtt_prem_id            =  v_prtt_prem_id
3086     and    nvl(per_in_ler_id , -1) =  p_per_in_ler_id
3087     and    business_group_id   =  p_business_group_id
3088     and    effective_end_date      > v_effective_date;
3089 
3090   --
3091   -- END ----> DELETE ROUTINE FOR BEN_PRTT_PREM_F
3092   --
3093   -- START ----> DELETE ROUTINE FOR BEN_ELIG_CVRD_DPNT_F
3094   --
3095   -- Source Table
3096   -- BEN_PER_IN_LER
3097   --
3098   -- Bug 5222 : Removed the effective date check.
3099   -- See comments at c_ben_prtt_enrt_rslt_f cursor.
3100   --
3101   cursor c_ben_elig_cvrd_dpnt_f is
3102     select pdp.elig_cvrd_dpnt_id,
3103            pdp.object_version_number,
3104 					 -- bug 5668052
3105 					 pdp.effective_start_date
3106     from   ben_elig_cvrd_dpnt_f pdp,
3107            ben_per_in_ler pil
3108     where  pil.per_in_ler_id = p_per_in_ler_id
3109     and    pil.business_group_id = p_business_group_id
3110     and    pdp.per_in_ler_id = pil.per_in_ler_id
3111     and    pdp.business_group_id = pil.business_group_id
3112     --    # 2982606 added for result level backout
3113     and   (p_bckdt_prtt_enrt_rslt_id is null
3114            or p_bckdt_prtt_enrt_rslt_id = pdp.prtt_enrt_rslt_id
3115           )
3116     order by 1;
3117 		-- bug 5668052
3118 		l_dpnt_eff_start_date date;
3119   --
3120   -- The cursor gets the maximum effective end date for the dependents
3121   -- with past per_in_ler 's
3122   --
3123 /*
3124   cursor c_pdp_max_esd_of_past_pil(v_elig_cvrd_dpnt_id in number) is
3125     select max(effective_end_date), max(object_version_number)
3126     from   ben_elig_cvrd_dpnt_f
3127     where  elig_cvrd_dpnt_id       =  v_elig_cvrd_dpnt_id
3128     and    nvl(per_in_ler_id , -1) <> p_per_in_ler_id
3129     and    business_group_id   =  p_business_group_id;
3130     -- and    effective_end_date      <  p_effective_date;
3131 */
3132    cursor c_pdp_max_esd_of_past_pil(v_elig_cvrd_dpnt_id in number) is
3133      select pdp.effective_end_date, pdp.object_version_number
3134      from   ben_elig_cvrd_dpnt_f pdp,
3135             ben_per_in_ler pil
3136      where  pdp.elig_cvrd_dpnt_id       =  v_elig_cvrd_dpnt_id
3137      and    nvl(pdp.per_in_ler_id , -1) <> p_per_in_ler_id
3138      and    pdp.business_group_id   =  p_business_group_id
3139      and    pdp.per_in_ler_id = pil.per_in_ler_id
3140      and    pil.per_in_ler_stat_cd not in ('BCKDT','VOIDD')
3141      order by pdp.effective_end_date desc;
3142 
3143   --
3144   -- Move deleted records to backup table
3145   --
3146   cursor c_deleted_pdp(v_elig_cvrd_dpnt_id in number,
3147                        v_effective_date    in date) is
3148     select *
3149     from   ben_elig_cvrd_dpnt_f
3150     where  elig_cvrd_dpnt_id       =  v_elig_cvrd_dpnt_id
3151     and    nvl(per_in_ler_id , -1) =  p_per_in_ler_id
3152     and    business_group_id   =  p_business_group_id
3153     and    effective_end_date      > v_effective_date;
3154 
3155   --
3156   -- END ----> DELETE ROUTINE FOR BEN_ELIG_CVRD_DPNT_F
3157   --
3158   -- START ----> DELETE ROUTINE FOR BEN_PL_BNF_F
3159   --
3160   -- Source Table
3161   -- BEN_PER_IN_LER
3162   --
3163   cursor c_ben_pl_bnf_f is
3164     select pbn.pl_bnf_id,
3165            pbn.object_version_number,
3166 					 -- bug 5668052
3167 					 pbn.effective_start_date
3168     from   ben_pl_bnf_f pbn,
3172     and    pbn.per_in_ler_id = pil.per_in_ler_id
3169            ben_per_in_ler pil
3170     where  pil.per_in_ler_id = p_per_in_ler_id
3171     and    pil.business_group_id = p_business_group_id
3173     and    pbn.business_group_id = pil.business_group_id
3174     --
3175     -- Do not use the effective date check, see
3176     -- comments at c_ben_prtt_enrt_rslt_f
3177     -- Rows should be selected based on per in ler only.
3178     --
3179     /*
3180     and    p_effective_date
3181            between pbn.effective_start_date
3182            and     pbn.effective_end_date
3183     */
3184     --    # 2982606 added for result level backout
3185     and    (p_bckdt_prtt_enrt_rslt_id is null
3186             or p_bckdt_prtt_enrt_rslt_id = pbn.prtt_enrt_rslt_id
3187            )
3188     order by 1;
3189 		-- bug 5668052
3190 		l_bnf_effective_start_date date;
3191   --
3192   -- The cursor gets the maximum effective end date for the beneficiary
3193   -- with past per_in_ler 's
3194   --
3195   -- 5649636 : c_pbn_max_esd_of_past_pil is modified
3196   /* cursor c_pbn_max_esd_of_past_pil(v_pl_bnf_id in number) is
3197     select max(effective_end_date), max(object_version_number)
3198     from   ben_pl_bnf_f
3199     where  pl_bnf_id       =  v_pl_bnf_id
3200     and    nvl(per_in_ler_id , -1) <> p_per_in_ler_id
3201     and    business_group_id   =  p_business_group_id;
3202     -- and    effective_end_date      <  p_effective_date;
3203     */
3204    -- 5895645 : typo fix
3205 cursor c_pbn_max_esd_of_past_pil(v_pl_bnf_id in number) is
3206      select pbn.effective_end_date, pbn.object_version_number
3207      from   ben_pl_bnf_f pbn,
3208             ben_per_in_ler pil
3209      where  pbn.pl_bnf_id           =  v_pl_bnf_id
3210      and    nvl(pbn.per_in_ler_id , -1) <> p_per_in_ler_id
3211      and    pbn.business_group_id   =  p_business_group_id
3212      and    pbn.per_in_ler_id = pil.per_in_ler_id
3213      and    pil.per_in_ler_stat_cd not in ('BCKDT','VOIDD')
3214      order by pbn.effective_end_date desc;
3215 
3216   --
3217   -- Move deleted records to backup table
3218   --
3219   cursor c_deleted_pbn(v_pl_bnf_id in number,
3220                        v_effective_date    in date) is
3221     select *
3222     from   ben_pl_bnf_f
3223     where  pl_bnf_id               =  v_pl_bnf_id
3224     and    nvl(per_in_ler_id , -1) =  p_per_in_ler_id
3225     and    business_group_id   =  p_business_group_id
3226     and    effective_end_date      > v_effective_date;
3227   --
3228   --
3229   -- END ----> DELETE ROUTINE FOR BEN_PL_BNF_F
3230   --
3231   -- START ----> DELETE ROUTINE FOR BEN_PRMRY_CARE_PRVDR_F
3232   --
3233   -- Source Table
3234   -- BEN_PER_IN_LER
3235   -- Drive Routes
3236   -- BEN_PRTT_ENRT_RSLT_F
3237   --
3238   --
3239   cursor c_ben_prmry_care_prvdr_f is
3240     select ppr.prmry_care_prvdr_id,
3241            ppr.effective_start_date,
3242            ppr.object_version_number
3243     from   ben_prmry_care_prvdr_f ppr,
3244            ben_prtt_enrt_rslt_f pen,
3245            ben_per_in_ler pil
3246     where  pil.per_in_ler_id = p_per_in_ler_id
3247     and    pil.business_group_id = p_business_group_id
3248     and    pen.per_in_ler_id = pil.per_in_ler_id
3249     and    pen.business_group_id = pil.business_group_id
3250     and    ppr.effective_start_date
3251            between pen.effective_start_date
3252            and     pen.effective_end_date
3253     and    ppr.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
3254     and    ppr.business_group_id = pen.business_group_id
3255     --
3256     -- Do not use the effective date check, see
3257     -- comments at c_ben_prtt_enrt_rslt_f
3258     -- Rows should be selected based on per in ler only.
3259     --
3260     /*
3261     and    p_effective_date
3262            between ppr.effective_start_date
3263            and     ppr.effective_end_date
3264     */
3265     --    # 2982606 added for result level backout
3266     and   (p_bckdt_prtt_enrt_rslt_id is null
3267            or p_bckdt_prtt_enrt_rslt_id = ppr.prtt_enrt_rslt_id
3268           )
3269     order by 1;
3270   --
3271   -- END ----> DELETE ROUTINE FOR BEN_PRMRY_CARE_PRVDR_F
3272   --
3273   -- START ----> DELETE ROUTINE FOR BEN_PRTT_RT_VAL
3274   --
3275   -- Source Table
3276   -- BEN_PER_IN_LER
3277   --
3278   cursor c_ben_prtt_rt_val is
3279     select prv.prtt_rt_val_id,
3280            prv.object_version_number,
3281            pil.person_id,
3282            prv.rt_strt_dt,
3283            prv.acty_ref_perd_cd,
3284            prv.prtt_enrt_rslt_id,
3285            prv.pk_id,
3286            prv.pk_id_table_name
3287     from   ben_prtt_rt_val prv,
3288            ben_per_in_ler pil
3289     where  pil.per_in_ler_id = p_per_in_ler_id
3290     and    pil.business_group_id = p_business_group_id
3291     and    prv.prtt_rt_val_stat_cd is null
3292     and    prv.per_in_ler_id = pil.per_in_ler_id
3293     and    prv.business_group_id = pil.business_group_id
3294     --    # 2982606 added for result level backout
3295     and   (p_bckdt_prtt_enrt_rslt_id is null
3296            or p_bckdt_prtt_enrt_rslt_id = prv.prtt_enrt_rslt_id
3297           )
3298     order  by prv.rt_strt_dt desc;
3299   --
3300   cursor c_prv_of_previous_pil is
3301     select prv.prtt_rt_val_id,
3302            prv.object_version_number,
3303            prv.rt_end_dt,
3304            prv.rt_strt_dt,
3305            prv.per_in_ler_id,
3306            prv.prtt_enrt_rslt_id,
3307            prv.acty_base_rt_id,
3308            prv.prtt_rt_val_stat_cd, -- 8896851
3309            pil.person_id,
3310 	   decode( (select '1' from dual
3311                    where exists (select '1' from ben_le_clsn_n_rstr bkp
3312                                 where bkp.per_in_ler_ended_id = p_per_in_ler_id
3316                    ), '1',2,1 ) adj_rec /* Bug 12576710: Added decode statement*/
3313                                 and bkp.BKUP_TBL_ID = prv.prtt_rt_val_id
3314                                 and bkp.BKUP_TBL_TYP_CD = 'BEN_PRTT_RT_VAL_ADJ'
3315                                 )
3317     from   ben_prtt_rt_val  prv,
3318            ben_per_in_ler pil
3319     where  prv.ended_per_in_ler_id = pil.per_in_ler_id
3320     and    prv.ended_per_in_ler_id = p_per_in_ler_id
3321     and    prv.per_in_ler_id <> p_per_in_ler_id -- Bug 8234902, not to consider the
3322                                                 -- rates of backed out LifeEvent when determining previous pil
3323     and    nvl(prv.prtt_rt_val_stat_cd,'BCKDT') ='BCKDT'
3324     and    prv.business_group_id = p_business_group_id
3325     and    prv.business_group_id = pil.business_group_id
3326     and   (p_bckdt_prtt_enrt_rslt_id is null
3327            or p_bckdt_prtt_enrt_rslt_id = prv.prtt_enrt_rslt_id)
3328   -- order by prv.acty_base_rt_id,prv.rt_strt_dt asc;
3329   -- order by prv.prtt_enrt_rslt_id, prv.acty_base_rt_id, prv.rt_strt_dt asc; -- 8896851
3330   order by adj_rec desc, prv.prtt_enrt_rslt_id, prv.rt_strt_dt asc, prv.acty_base_rt_id; --10024680
3331   --
3332   l_prv_bckdt      c_prv_of_previous_pil%rowtype;
3333   --
3334   cursor c_next_prv is
3335     select prv.prtt_rt_val_id,
3336            prv.rt_strt_dt,
3337            prv.per_in_ler_id
3338     from   ben_prtt_rt_val  prv
3339     where  prv.ended_per_in_ler_id = p_per_in_ler_id
3340     and    prv.prtt_rt_val_stat_cd ='BCKDT'
3341     and    prv.per_in_ler_id <> p_per_in_ler_id -- Bug 8234902, not to consider the rates of backed out LifeEvent
3342     and    prv.prtt_enrt_rslt_id = l_prv_bckdt.prtt_enrt_rslt_id
3343     and    prv.acty_base_rt_id = l_prv_bckdt.acty_base_rt_id
3344     and    prv.prtt_rt_val_id <> l_prv_bckdt.prtt_rt_val_id
3345     and    prv.rt_strt_dt >= l_prv_bckdt.rt_strt_dt
3346     and   (p_bckdt_prtt_enrt_rslt_id is null
3347            or p_bckdt_prtt_enrt_rslt_id = prv.prtt_enrt_rslt_id)
3348   order by prv.rt_strt_dt asc;
3349   l_next_prv      c_next_prv%rowtype;
3350   --
3351   -- 8896851
3352   --
3353   cursor c_get_bckdt_prv(p_prtt_rt_val_id number) is
3354     select lcr.rt_end_dt,
3355            lcr.per_in_ler_ended_id
3356     from   ben_le_clsn_n_rstr  lcr
3357     where  lcr.per_in_ler_id = p_per_in_ler_id
3358     and    bkup_tbl_typ_cd = 'BEN_PRTT_RT_VAL'
3359     and    bkup_tbl_id = p_prtt_rt_val_id;
3360   --
3361   l_bckdt_prv_rec     c_get_bckdt_prv%rowtype;
3362   --
3363   --  end 8896851
3364   --
3365   cursor c_prtt_rt_val_adj (p_per_in_ler_id number) is
3366    select *
3367    from ben_le_clsn_n_rstr
3368    where BKUP_TBL_TYP_CD = 'BEN_PRTT_RT_VAL_ADJ'
3369    AND   PER_IN_LER_ID  = p_per_in_ler_id;
3370   --
3371   l_rt_adj  c_prtt_rt_val_adj%rowtype;
3372   --
3373   cursor c_prv_ovn (p_prtt_rt_val_id in number) is
3374     select object_version_number
3375     from ben_prtt_rt_val
3376     where prtt_rt_val_id = p_prtt_rt_val_id;
3377     --
3378     -- Added for bug 7206471
3379   cursor c_prtt_enrt_rslt_adj (p_per_in_ler_id in number) is
3380 	   select *
3381 	   from ben_le_clsn_n_rstr
3382 	   where BKUP_TBL_TYP_CD = 'BEN_PRTT_ENRT_RSLT_F_ADJ'
3383 	   AND   PER_IN_LER_ID  = p_per_in_ler_id;
3384 
3385 /*Added cursors for Bug 12576710: Check whether there is any coverage,rate record is end by the backed out per_in_ler_id */
3386 cursor c_adj_rec_curr_per_in_ler (p_per_in_ler_id in number) is
3387 	   select *
3388 	   from ben_le_clsn_n_rstr
3389 	   where BKUP_TBL_TYP_CD = 'BEN_PRTT_ENRT_RSLT_F_ADJ'
3390 	     AND   per_in_ler_ended_id  = p_per_in_ler_id;
3391 
3392  cursor c_adj_rate_curr_per_in_ler (p_per_in_ler_id number,p_bkp_prv_id number) is
3393    select *
3394    from ben_le_clsn_n_rstr
3395    where BKUP_TBL_TYP_CD = 'BEN_PRTT_RT_VAL_ADJ'
3396    AND   per_in_ler_ended_id  = p_per_in_ler_id
3397    and   BKUP_TBL_ID = nvl(p_bkp_prv_id,BKUP_TBL_ID);
3398 	   --
3399  l_cvg_adj  c_prtt_enrt_rslt_adj%rowtype;
3400 	   --
3401   cursor c_pen_ovn (p_prtt_enrt_rslt_id in number) is
3402 	    select object_version_number,
3403 	    effective_start_date -- Bug 8507247:
3404 	    --APP-PAY-07155 error on backing out the life event which has created coverage adjustment records if
3405 	    --there are date track records for the enrollment after SYSDATE
3406 	    from ben_prtt_enrt_rslt_f
3407 	    where prtt_enrt_rslt_id=p_prtt_enrt_rslt_id
3408 	    and   effective_end_date = hr_api.g_eot
3409 	    and   prtt_enrt_rslt_stat_cd is null;
3410   -- End bug 7206471
3411   --
3412   -- Bug : 4661 Cursor to select the prtt_enrt_rslt record associated
3413   -- with current prtt_rt_val record, this records effective_start_date
3414   -- is used as effective_date for rate val record.
3415   --
3416   cursor c_prv_pen(cp_prtt_enrt_rslt_id in number, cv_rt_strt_dt in date) is
3417     select pen.prtt_enrt_rslt_id,
3418            pen.object_version_number,
3419            pen.effective_end_date,
3420            pen.effective_start_date
3421     from   ben_prtt_enrt_rslt_f pen
3422     where  pen.business_group_id = p_business_group_id
3423     and    pen.prtt_enrt_rslt_id = cp_prtt_enrt_rslt_id
3424 -- Commented per bug 1584238 and 1627373
3425 --    and    cv_rt_strt_dt >= pen.enrt_cvg_strt_dt
3426     and   pen.prtt_enrt_rslt_stat_cd is null
3427     order by pen.effective_start_date asc;
3428   --
3429   -- Bug 3495372 We can have multiple tables with coverage restrictions
3430   -- when there is an interim with the same comp object. This happens
3431   -- when the coverage is enter value at enrollment
3432   --
3433   /* BUG 3507554 Performance Changes
3434   cursor c_multiple_rate is
3435     select 'Y'
3439     and    pil.business_group_id = p_business_group_id
3436     from   ben_prtt_rt_val prv,
3437            ben_per_in_ler pil
3438     where  pil.per_in_ler_id = p_per_in_ler_id
3440     and    prv.prtt_rt_val_stat_cd is null
3441     and    prv.per_in_ler_id = pil.per_in_ler_id
3442     and    prv.business_group_id = pil.business_group_id
3443     --START BUG 3495372
3444     and    prv.prtt_enrt_rslt_id in
3445               (select prtt_enrt_rslt_id
3446                  from  ben_prtt_enrt_rslt_f
3447                  where prtt_enrt_rslt_stat_cd is not null
3448                    and sspndd_flag = 'N'
3449                       ) -- to leave out Suspended results
3450     --END BUG 3495372
3451     and    not exists (select null from ben_prtt_enrt_rslt_f where
3452                    prtt_enrt_rslt_id = prv.prtt_enrt_rslt_id
3453                     and prtt_enrt_rslt_stat_cd is not null ) -- to leave out VOIDD results
3454     group by prv.acty_base_rt_id
3455     having count(*) > 1;
3456   */
3457   --
3458   --BUG 3507554 Performance Changes
3459   --
3460   cursor c_multiple_rate is
3461     select 'Y'
3462     from   ben_prtt_rt_val prv
3463     where  prv.per_in_ler_id = p_per_in_ler_id
3464     and    prv.prtt_rt_val_stat_cd is null
3465     and    exists (select null
3466                      from ben_prtt_enrt_rslt_f pen
3467                     where pen.prtt_enrt_rslt_id = prv.prtt_enrt_rslt_id
3468                       and pen.prtt_enrt_rslt_stat_cd is null
3469                       and pen.sspndd_flag = 'N' ) -- to select only not voided and unsuspended results
3470     group by prv.acty_base_rt_id,prv.rt_strt_dt   --BUG 4558512 otherwise.. we get into issue with FLAT RANGE
3471                                                   --and Enter Benefit at enrollment cert completion cases
3472     having count(*) > 1;
3473   --
3474   l_multiple_rate        varchar2(1) := 'N';
3475   l_status			varchar2(1);
3476   l_industry			varchar2(1);
3477   l_oracle_schema		varchar2(30);
3478 
3479   l_prv_pen      c_prv_pen%rowtype;
3480   --
3481   -- Pbodla : Link between prv and ecr needs to be stored as this
3482   -- information is required to restore the enrollment data as
3483   -- part of life event restoration.
3484   -- Get the ecr info to store the link between ecr and prv rows.
3485   --
3486   cursor c_ecr(v_prtt_rt_val_id in number) is
3487      select ecr.*
3488      from   ben_enrt_rt ecr
3489      where  ecr.prtt_rt_val_id      =  v_prtt_rt_val_id
3490      and    ecr.business_group_id   =  p_business_group_id;
3491   --
3492   l_ecr      c_ecr%rowtype;
3493 
3494 
3495 
3496   --
3497   --
3498   -- END ----> DELETE ROUTINE FOR BEN_PRTT_RT_VAL
3499   --
3500   -- START ----> DELETE ROUTINE FOR BEN_PRTT_ENRT_RSLT_F
3501   --
3502   -- Source Table
3503   -- BEN_PER_IN_LER
3504   --
3505 
3506 
3507   cursor c_ben_prtt_enrt_rslt_f is
3508     select pen.prtt_enrt_rslt_id,
3509            pen.object_version_number,
3510            pen.pl_id,
3511            pen.oipl_id,
3512            pen.enrt_cvg_strt_dt,
3513            pen.person_id,
3514            pen.enrt_cvg_thru_dt,
3515            pen.effective_end_date,
3516            pen.effective_start_date,
3517            pen.per_in_ler_id
3518            ,pil.lf_evt_ocrd_dt
3519     from   ben_prtt_enrt_rslt_f pen,
3520            ben_per_in_ler pil
3521     where  pil.per_in_ler_id = p_per_in_ler_id
3522     and    pil.business_group_id = p_business_group_id
3523     and    pen.per_in_ler_id = pil.per_in_ler_id
3524     and    pen.business_group_id = pil.business_group_id
3525     --    # 2982606 added for result level backout
3526     and   (p_bckdt_prtt_enrt_rslt_id is null
3527            or p_bckdt_prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
3528           )
3529     order by 1;
3530 
3531     ---  make sure results of prev per in ler id
3532     ---  currected by curr per_in_ler_id due to same date enrollment
3533     ---  are not backedout  bug # 3086161
3534     ---  after the # 3175382 new cursor created and the validation moved
3535     --  from c_ben_prtt_enrt_rslt_f. because for current per in ler id the backout entry has to be created
3536     --- unless the current per_in_ler can not be reinstated. so the cursor created to  validate
3537     --- the delting part ofthe result. the result can not be deleted because the prev correctecd
3538     --- result has to be restored with the prev per in ler id
3539 
3540     cursor  c_corr_result_exist (l_per_in_ler_id     number ,
3541                                  l_prtt_enrt_rslt_id number ) is
3542     select 'x'
3543     from BEN_LE_CLSN_N_RSTR  lcnr
3544          ,BEN_PRTT_ENRT_RSLT_F pen   -- Bug 6632568
3545     where lcnr.bkup_tbl_id          = pen.prtt_enrt_rslt_id -- Bug 6632568
3546       and pen.prtt_enrt_rslt_id     = l_prtt_enrt_rslt_id  -- Bug 6632568
3547       and lcnr.BKUP_TBL_TYP_CD      = 'BEN_PRTT_ENRT_RSLT_F_CORR'
3548       and lcnr.enrt_cvg_thru_dt = hr_api.g_eot  --bug#5032364
3549       and  lcnr.per_in_ler_ended_id = pen.per_in_ler_id -- Bug 6632568
3550       and  pen.per_in_ler_id  = l_per_in_ler_id -- Bug 6632568
3551       and  lcnr.effective_start_date between pen.effective_start_date  -- Bug 6632568
3552 				     and  pen.effective_end_date;
3553 
3554 
3555     /* -- Bug : 1143673(4287)
3556        -- No ed clause required. Consider the following scenario.
3557           result 1 created as of 06/16/99,
3558           result 2 created as of 06/17/99,
3559           result 3 created as of 06/18/99 - EOT.
3560           If the back out with effective date of 06/20/99 is
3561           called from BENDSPLE to voidd the potential,
3562           then this process only catches the 3rd record, other two
3563           stays as. If a life event is processed as of 06/17/99 then
3564           a result will be created with cvg_strt_dt and orgnl_strt_dt
3568            between pen.effective_start_date
3565           of 06/16/99. To avoid this set all the results to BCKDT.
3566        --
3567     and    p_effective_date
3569            and     pen.effective_end_date;
3570     */
3571    -- bug # 3086161
3572    cursor c_BEN_LE_CLSN_N_RSTR_corr  (c_pil_id  number)
3573           is
3574     select lcnr.bkup_tbl_id,
3575            lcnr.effective_start_date,
3576            lcnr.effective_end_date,
3577            lcnr.per_in_ler_id,
3578            lcnr.ler_id,
3579            lcnr.enrt_cvg_thru_dt,
3580            lcnr.prtt_enrt_rslt_stat_cd,
3581            lcnr.sspndd_flag,
3582 	   lcnr.enrt_mthd_cd, -- Bug 7137371
3583            pen.effective_end_date pen_effective_end_date, -- Bug 7197868
3584            pen.object_version_number
3585     from   BEN_LE_CLSN_N_RSTR lcnr,
3586            ben_prtt_enrt_rslt_f  pen
3587     where  lcnr.BKUP_TBL_TYP_CD = 'BEN_PRTT_ENRT_RSLT_F_CORR'
3588       and  lcnr.Per_in_ler_ended_id = c_pil_id
3589       and  pen.prtt_enrt_rslt_id = lcnr.bkup_tbl_id
3590       --bug#5032364
3591       --and  (pen.per_in_ler_id     =  lcnr.per_in_ler_ended_id
3592       --      or pen.per_in_ler_id = lcnr.per_in_ler_id)
3593  --Bug 6489602
3594       and   (p_bckdt_prtt_enrt_rslt_id is null
3595            or p_bckdt_prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
3596           )
3597   --Bug 6489602
3598       and  lcnr.effective_start_date between
3599            pen.effective_start_date and pen.effective_end_date
3600      order by lcnr.bkup_tbl_id;
3601    --
3602 
3603    cursor c_BEN_LE_CLSN_N_RSTR_del  (c_pil_id  number)
3604           is
3605     select lcnr.bkup_tbl_id,
3606            lcnr.effective_start_date,
3607            lcnr.effective_end_date,
3608            lcnr.per_in_ler_id,
3609            lcnr.ler_id,
3610            lcnr.enrt_cvg_thru_dt,
3611            lcnr.prtt_enrt_rslt_stat_cd,
3612            lcnr.sspndd_flag,
3613            pen.object_version_number
3614     from   BEN_LE_CLSN_N_RSTR lcnr,
3615            ben_prtt_enrt_rslt_f  pen
3616     where  lcnr.BKUP_TBL_TYP_CD = 'BEN_PRTT_ENRT_RSLT_F_DEL'
3617       and  lcnr.Per_in_ler_ended_id = c_pil_id
3618       and  pen.prtt_enrt_rslt_id = lcnr.bkup_tbl_id
3619       --bug#5032364
3620       --and  (pen.per_in_ler_id     =  lcnr.per_in_ler_ended_id
3621       --      or pen.per_in_ler_id = lcnr.per_in_ler_id)
3622       and  lcnr.effective_start_date between
3623            pen.effective_start_date and pen.effective_end_date
3624      order by lcnr.bkup_tbl_id;
3625 
3626 
3627      cursor c_BEN_LE_CLSN_N_RSTR_dpnt  (c_pil_id  number)
3628           is
3629     select lcnr.bkup_tbl_id,
3630            pdp.effective_start_date,
3631            pdp.effective_end_date,
3632            lcnr.per_in_ler_id,
3633            lcnr.ler_id,
3634            lcnr.enrt_cvg_thru_dt,
3635            lcnr.prtt_enrt_rslt_stat_cd,
3636            lcnr.effective_start_date bkp_effective_start_date, -- 7197868
3637            lcnr.effective_end_date bkp_effective_end_date, -- 7197868
3638            pdp.object_version_number,
3639            pdp.elig_cvrd_dpnt_id
3640     from   BEN_LE_CLSN_N_RSTR lcnr,
3641            ben_elig_cvrd_dpnt_f  pdp
3642     where  lcnr.BKUP_TBL_TYP_CD = 'BEN_PRTT_ENRT_RSLT_F_CORR'
3643       and  lcnr.Per_in_ler_ended_id = c_pil_id
3644       and  pdp.prtt_enrt_rslt_id = lcnr.bkup_tbl_id
3645       and  (pdp.per_in_ler_id     =  lcnr.per_in_ler_ended_id
3646            or  pdp.per_in_ler_id     =  lcnr.per_in_ler_id )
3647       and  pdp.prtt_enrt_rslt_id =  lcnr.bkup_tbl_id
3648       and  lcnr.effective_start_date between
3649            pdp.effective_start_date and pdp.effective_end_date
3650       order by pdp.elig_cvrd_dpnt_id;
3651 
3652   cursor c_BEN_LE_CLSN_N_RSTR_pbn  (c_pil_id  number)
3653           is
3654     select lcnr.bkup_tbl_id,
3655            pbn.effective_start_date,
3656            pbn.effective_end_date,
3657            lcnr.per_in_ler_id,
3658            lcnr.ler_id,
3659            lcnr.enrt_cvg_thru_dt,
3660            lcnr.prtt_enrt_rslt_stat_cd,
3661            pbn.object_version_number,
3662            pbn.pl_bnf_id
3663     from   BEN_LE_CLSN_N_RSTR lcnr,
3664            ben_pl_bnf_f  pbn
3665     where  lcnr.BKUP_TBL_TYP_CD = 'BEN_PRTT_ENRT_RSLT_F_CORR'
3666       and  lcnr.Per_in_ler_ended_id = c_pil_id
3667       and  pbn.prtt_enrt_rslt_id = lcnr.bkup_tbl_id
3668       and  (pbn.per_in_ler_id     =  lcnr.per_in_ler_ended_id
3669            or  pbn.per_in_ler_id     =  lcnr.per_in_ler_id )
3670       and  pbn.prtt_enrt_rslt_id =  lcnr.bkup_tbl_id
3671       and  lcnr.effective_start_date between
3672            pbn.effective_start_date and pbn.effective_end_date;
3673 
3674 
3675 
3676   --
3677   -- The cursor gets the maximum effective end date for the enrollment
3678   -- result with past per_in_ler 's
3679   --
3680   -- Bug#2821279 : Removed the max functions and logic is based
3681   -- on order by clause.
3682   cursor c_pen_max_esd_of_past_pil(v_prtt_enrt_rslt_id in number) is
3683     select pen.effective_end_date,pen.object_version_number, pen.per_in_ler_id
3684     from   ben_prtt_enrt_rslt_f pen,
3685            ben_per_in_ler pil
3686     where  prtt_enrt_rslt_id       =  v_prtt_enrt_rslt_id
3687     and    nvl(pen.per_in_ler_id , -1) <> p_per_in_ler_id
3688     and    pen.business_group_id   =  p_business_group_id
3689     and    pen.per_in_ler_id = pil.per_in_ler_id
3690     and    pen.prtt_enrt_rslt_stat_cd is null
3691     and    pil.per_in_ler_stat_cd not in ('BCKDT','VOIDD')
3692     order by pen.effective_end_date desc;
3693   --
3694     --
3695     l_prev_per_in_ler_id             ben_prtt_enrt_rslt_f.per_in_ler_id%type;
3696     --
3697     -- CFW
3698   -- Move deleted records to backup table
3699   --
3700   cursor c_deleted_pen(v_prtt_enrt_rslt_id in number,
3704     where  prtt_enrt_rslt_id       =  v_prtt_enrt_rslt_id
3701                        v_effective_date    in date) is
3702     select *
3703     from   ben_prtt_enrt_rslt_f
3705     and    nvl(per_in_ler_id , -1) =  p_per_in_ler_id
3706     and    business_group_id   =  p_business_group_id
3707     and    effective_end_date      > v_effective_date;
3708    --
3709    -- Pbodla : Link between pen and epe needs to be stored as this
3710    -- information is required to restore the enrollment data as
3711    -- part of life event restoration.
3712    -- Get the epe info to store the link between epe and pen rows.
3713    --
3714    cursor c_epe(v_prtt_enrt_rslt_id in number, v_per_in_ler_id in number) is
3715      select epe.*
3716      from   ben_elig_per_elctbl_chc epe
3717      where  epe.prtt_enrt_rslt_id       =  v_prtt_enrt_rslt_id
3718      and    nvl(epe.per_in_ler_id , -1) =  nvl(v_per_in_ler_id, -1)
3719      and    epe.business_group_id   =  p_business_group_id;
3720    --
3721    l_epe      c_epe%rowtype;
3722    --
3723   --
3724   -- END ----> DELETE ROUTINE FOR BEN_PRTT_ENRT_RSLT_F
3725   --
3726   --
3727   -- START ----> DELETE ROUTINE FOR BEN_BNFT_PRVDD_LDGR_F
3728    cursor c_ben_bnft_prvdd_ldgr_f(p_bnft_prvdd_ldgr_id number) is
3729     select bpl.bnft_prvdd_ldgr_id,
3730            bpl.object_version_number,
3731            bpl.acty_base_rt_id,
3732            bpl.effective_end_date,
3733            bpl.effective_start_date,
3734            bpl.per_in_ler_id
3735     from   ben_bnft_prvdd_ldgr_f  bpl,
3736            ben_per_in_ler pil
3737     where  pil.per_in_ler_id = p_per_in_ler_id
3738     and    pil.business_group_id = p_business_group_id
3739     and    bpl.per_in_ler_id = pil.per_in_ler_id
3740     and    bpl.business_group_id = pil.business_group_id
3741     --    # 2982606 added for result level backout
3742     --    # Bug 6376239 Instead of pen_id, check against bpl_id passed
3743     and   (p_bnft_prvdd_ldgr_id is null
3744            or p_bnft_prvdd_ldgr_id = bpl.bnft_prvdd_ldgr_id
3745           )
3746     --bug#3702090
3747     and   exists (select null from ben_prtt_enrt_rslt_f pen
3748                   where pen.prtt_enrt_rslt_id = bpl.prtt_enrt_rslt_id)
3749     order by 1;
3750     --
3751     l_bpl      c_ben_bnft_prvdd_ldgr_f%rowtype;
3752     --
3753     -- Bug 6376239
3754     cursor c_bpl_from_pen is
3755     select bpl.bnft_prvdd_ldgr_id
3756       from ben_bnft_prvdd_ldgr_f bpl, ben_prtt_rt_val prv
3757      where prv.prtt_enrt_rslt_id = p_bckdt_prtt_enrt_rslt_id
3758        and prv.acty_base_rt_id = bpl.acty_base_rt_id
3759        and bpl.per_in_ler_id = p_per_in_ler_id
3760        and prv.per_in_ler_id = bpl.per_in_ler_id
3761        and bpl.business_group_id = p_business_group_id
3762        and prv.business_group_id = p_business_group_id;
3763     prev_bnft_prvdd_ldgr_id number;
3764     -- End 6376239
3765     --
3766     -- Bug 5500864
3767     --
3768     CURSOR c_bpl_from_backup
3769     IS
3770        SELECT bpl.*
3771          FROM ben_le_clsn_n_rstr bpl
3772         WHERE bkup_tbl_typ_cd = 'BEN_BNFT_PRVDD_LDGR_F'
3773           AND per_in_ler_id = p_per_in_ler_id
3774           AND effective_end_date = hr_api.g_eot;
3775     --
3776     l_bpl_from_backup   c_bpl_from_backup%ROWTYPE;
3777     --
3778     -- Bug 5500864
3779     --
3780    -- Bug#2592783 - per_in_ler_stat_cd is checked
3781    -- Bug#2646851 - cursor modified with order by clause and max function removed
3782    cursor c_bpl_max_esd_of_past_pil(v_bnft_prvdd_ldgr_id in number) is
3783       select bpl.effective_end_date, bpl.object_version_number
3784       from   ben_bnft_prvdd_ldgr_f bpl,
3785              ben_per_in_ler pil
3786       where  bpl.bnft_prvdd_ldgr_id       =  v_bnft_prvdd_ldgr_id
3787       and    nvl(bpl.per_in_ler_id , -1) <> p_per_in_ler_id
3788       and    bpl.business_group_id   =  p_business_group_id
3789       and    bpl.per_in_ler_id = pil.per_in_ler_id
3790       and    pil.per_in_ler_stat_cd not in ('BCKDT','VOIDD')
3791       order by bpl.effective_end_date desc;
3792   -- END   ---> DELETE ROUTINE FOR BEN_BNFT_PRVDD_LDGR_F
3793 
3794   -- START ----> DELETE ROUTINE FOR BEN_PIL_ELCTBL_CHC_POPL
3795   -- -- Source Table -- BEN_PER_IN_LER --
3796   cursor c_ben_pil_elctbl_chc_popl is
3797     select pel.pil_elctbl_chc_popl_id,
3798            pel.object_version_number
3799     from   ben_pil_elctbl_chc_popl pel,
3800            ben_per_in_ler pil
3801     where  pil.per_in_ler_id = p_per_in_ler_id
3802     and    pil.business_group_id = p_business_group_id
3803     and    pel.per_in_ler_id = pil.per_in_ler_id
3804     and    pel.business_group_id = pil.business_group_id;
3805   --
3806   -- END ----> DELETE ROUTINE FOR BEN_PIL_ELCTBL_CHC_POPL
3807   --
3808   -- BEN_CBR_QUALD_BNF
3809   --
3810   cursor c_get_cbr_quald_bnf is
3811     select cqb.*,crp.prvs_elig_perd_end_dt
3812     from   ben_cbr_quald_bnf cqb
3813           ,ben_cbr_per_in_ler crp
3814     where  cqb.cbr_quald_bnf_id = crp.cbr_quald_bnf_id
3815     and    cqb.business_group_id = p_business_group_id
3816     and    cqb.business_group_id = crp.business_group_id
3817     and    crp.per_in_ler_id = p_per_in_ler_id
3818     and    crp.init_evt_flag = 'N';
3819 
3820   -- PRTT_REIMBMT_RQST
3821   -- bug fix 2223214
3822   -- added a condition to ignore VOIDED participant reimbursement claims
3823   -- since it prevents backout
3824   --
3825   cursor c_prc is
3826     select prc.PRTT_REIMBMT_RQST_ID
3827           ,prc.OBJECT_VERSION_NUMBER
3828           ,prc.effective_start_date
3829           ,pil.person_id
3830     from  ben_prtt_reimbmt_rqst_f prc
3831          ,ben_prtt_rt_val prv
3832          ,ben_per_in_ler pil
3833     where prv.per_in_ler_id = p_per_in_ler_id
3834     and   prv.PRTT_REIMBMT_RQST_id = prc.PRTT_REIMBMT_RQST_id
3835     and   pil.per_in_ler_id = p_per_in_ler_id
3839     and   (p_bckdt_prtt_enrt_rslt_id is null
3836     -- hnarayan -- bug 2223214
3837     and   prc.prtt_reimbmt_rqst_stat_cd not in ('VOIDED')
3838     --    # 2982606 added for result level backout
3840            or p_bckdt_prtt_enrt_rslt_id = prc.prtt_enrt_rslt_id
3841           )
3842  ;
3843   --
3844   --
3845   -- Check existence of backup data
3846   --
3847   cursor c_bkp_row(cv_BKUP_TBL_TYP_CD in varchar2,
3848                cv_PER_IN_LER_ID   in number,
3849                cv_BKUP_TBL_ID     in number,
3850                cv_object_version_number in number) is
3851     select rowid
3852     from BEN_LE_CLSN_N_RSTR
3853     where BKUP_TBL_TYP_CD = cv_BKUP_TBL_TYP_CD
3854       and PER_IN_LER_ID   = cv_PER_IN_LER_ID
3855       and BKUP_TBL_ID     = cv_BKUP_TBL_ID
3856       and object_version_number = cv_object_version_number;
3857 
3858   --# bug 2546259 this cursor find the result voided by the LE
3859 
3860   cursor c_futur_pen is
3861   select pen.prtt_enrt_rslt_id  from  ben_prtt_enrt_rslt_f pen
3862   where per_in_ler_id = p_per_in_ler_id
3863     and pen.prtt_enrt_rslt_stat_cd = 'VOIDD'
3864     and pen.effective_start_date < pen.enrt_cvg_strt_dt
3865     /* Bug 9095753: When checking for future pen records check whether the enrollments of previous life event are end dated.
3866     If Open is the first LE,pen.effective_start_date < pen.enrt_cvg_strt_dt holds good for enrollment records that are VOIDD and tries to do delete future
3867     changes which raises APP-PAY-07187  error.So check whether enrolment records exists for previous LE*/
3868     and exists
3869              (select '1' from ben_prtt_enrt_rslt_f pen1,
3870 	                      (select per_in_ler_id from ben_per_in_ler pil,
3871 				      ben_ler_f ler
3872 				      where pil.person_id = (select person_id
3873                                                             from ben_per_in_ler pil2
3874                                                             where pil2.per_in_ler_id=p_per_in_ler_id)
3875 				      and pil.per_in_ler_id <> p_per_in_ler_id
3876 				      and pil.ler_id = ler.ler_id
3877 				      and p_effective_date between
3878 					  ler.effective_start_date and ler.effective_end_date
3879 				      and pil.per_in_ler_stat_cd not in ('BCKDT','VOIDD')
3880 				      and ler.typ_cd not in ('IREC', 'SCHEDDU', 'COMP', 'GSP', 'ABS')
3881 				      and pil.lf_evt_ocrd_dt < (select lf_evt_ocrd_dt from
3882 							       ben_per_in_ler pil1
3883 							       where pil1.per_in_ler_id = p_per_in_ler_id)
3884 				      order by per_in_ler_id desc) prev_pil
3885                 where pen1.per_in_ler_id = prev_pil.per_in_ler_id
3886 		      and pen1.effective_start_date < pen1.enrt_cvg_strt_dt
3887 		      and pen1.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
3888 	      );
3889 
3890  -- # bug 2546259 this cursor find the dpnt row end dated by the LE
3891   cursor c_futur_del_dpnt (v_prtt_enrt_rslt_id number) is
3892   select pdp.elig_cvrd_dpnt_id,
3893          pdp.object_version_number,
3894          pdp.effective_end_date
3895     from   ben_elig_cvrd_dpnt_f pdp
3896     where  pdp.effective_end_date  <>  hr_api.g_eot
3897     and    pdp.prtt_enrt_rslt_id  = v_prtt_enrt_rslt_id
3898     and    pdp.business_group_id = p_business_group_id
3899     order by 1;
3900 
3901   --
3902   cursor c_pay_proposal (cv_pay_proposal_id number) is
3903   select ppp.object_version_number
3904     from per_pay_proposals ppp
3905     where ppp.pay_proposal_id = cv_pay_proposal_id;
3906   --
3907   cursor c_pen_sus is
3908   select pen.prtt_enrt_rslt_id,
3909          pen.per_in_ler_id
3910     from ben_prtt_enrt_rslt_f pen,
3911          ben_per_in_ler pil
3912    where pen.sspndd_flag = 'Y'
3913      and pen.per_in_ler_id <> pil.per_in_ler_id
3914      and pil.per_in_ler_id = p_per_in_ler_id
3915      and pen.person_id = pil.person_id
3916      and pen.prtt_enrt_rslt_stat_cd is null
3917      and pen.effective_end_date = hr_api.g_eot
3918      and pen.enrt_cvg_thru_dt = hr_api.g_eot;
3919   l_pen_sus c_pen_sus%rowtype;
3920 
3921 
3922   l_salary_warning             boolean;
3923   l_salary_proposal_ovn        number;
3924   l_row_id                     rowid;
3925   --
3926   l_pk_id                      number;
3927   l_pil_id                     number;
3928   l_rt_end_dt                  date;
3929   l_person_id                  number;
3930   l_acty_base_rt_id            number;
3931   l_acty_ref_perd_cd           hr_lookups.lookup_code%TYPE; -- UTF8
3932   l_business_group_id          number;
3933   l_object_version_number      number;
3934   l_effective_start_date       date;
3935   l_effective_end_date         date;
3936   l_prtt_enrt_rslt_id          number;
3937   l_rslt_object_version_number number;
3938   l_effective_date             date;
3939   l_max_object_version_number  number;
3940   l_datetrack_mode             varchar2(80) := null;
3941   l_cm_object_version_number   number;
3942   l_lf_evt_ocrd_dt             date;
3943   l_per_in_ler_id              number;
3944   l_to_be_sent_date            date;
3945   l_child_left                 boolean;
3946   l_rt_strt_dt                 date;
3947   l_prv_prtt_enrt_rslt_id      number;
3948   l_ref_obj_pk_id              number;
3949   l_ref_obj_table_name         varchar2(100);
3950   l_pl_id                      number;
3951   l_oipl_id                    number;
3952   l_enrt_cvg_strt_dt           date;
3953   l_pen_eed                    date;
3954   l_pen_esd                    date;
3955   l_pen_pil_id                 number;
3956   l_enrt_cvg_thru_dt           date;
3957   l_prv_effective_date         date;
3958   l_prev_pk_id                 number;
3959   l_prc_rec                    c_prc%rowtype ;
3960   l_bpl_effective_date         date;
3961   l_dummy                      varchar2(1) ;
3962   l_prev_elig_cvrd_dpnt_id     number := 0;
3966   l_effective_date_new         date;
3963   l_prev_bkup_tbl_id           number := 0;
3964   l_ended_per_in_ler_id        number;
3965   l_cvg_adj_effective_date date;
3967   --
3968 begin
3969   --
3970   hr_utility.set_location ('Entering '||l_package,10);
3971   hr_utility.set_location ('Start of '||p_routine,10);
3972   --
3973   -- check which routine we are calling
3974   --
3975   if p_routine = 'BEN_ELIG_CVRD_DPNT_F' then
3976 
3977     -- For dependents, we want to 'un-end' any dpnt records that were ENDED
3978     -- due to the per-in-ler.  The 'future-change' date track mode will do that
3979     -- for us.
3980     -- Other dpnts can be left alone because their FK to per-in-ler will indicate
3981     -- that they are really 'backed out'.
3982 
3983     l_prev_pk_id := -1; -- like null
3984 
3985     --
3986     open c_ben_elig_cvrd_dpnt_f;
3987       --
3988       loop
3989         --
3990         fetch c_ben_elig_cvrd_dpnt_f into l_pk_id,
3991                                           l_object_version_number,
3992 																					-- bug 5668052
3993 																					l_dpnt_eff_start_date;
3994         exit when c_ben_elig_cvrd_dpnt_f%notfound;
3995         --
3996         -- Get the maximum of effective end date for the dependents
3997         -- with past per_in_ler 's.
3998         --
3999         hr_utility.set_location ('with in loop  '||l_pk_id,10);
4000         --
4001         l_effective_date := null;
4002 
4003         open  c_pdp_max_esd_of_past_pil(l_pk_id);
4004         fetch c_pdp_max_esd_of_past_pil into l_effective_date,
4005                                              l_max_object_version_number;
4006         close c_pdp_max_esd_of_past_pil;
4007         --
4008         -- The group function "max" returns null when no records found,
4009         -- so check l_effective_date is null to find whether any
4010         -- past records were found.
4011         --
4012         --
4013         if l_effective_date is not null then
4014 
4015          --
4016          -- Do not process the row as it is already processed(deleted).
4017          --
4018          if l_prev_pk_id <> l_pk_id then
4019 
4020            -- now backup all the deleted enrollment rows
4021            --
4022            for l_deleted_pdp_rec in c_deleted_pdp(l_pk_id, l_effective_date)
4023            loop
4024               --
4025               open c_bkp_row('BEN_ELIG_CVRD_DPNT_F',
4026                              l_deleted_pdp_rec.per_in_ler_id,
4027                              l_deleted_pdp_rec.ELIG_CVRD_DPNT_ID,
4028                              l_deleted_pdp_rec.object_version_number);
4029               fetch c_bkp_row into l_row_id;
4030               --
4031               if c_bkp_row%notfound
4032               then
4033                   hr_utility.set_location ('backup notfound  '||l_effective_date,10);
4034                   --
4035                   close c_bkp_row;
4036                   --
4037                   insert into BEN_LE_CLSN_N_RSTR (
4038                      BKUP_TBL_TYP_CD,
4039                      CVG_STRT_DT,
4040                      CVG_THRU_DT,
4041                      CVG_PNDG_FLAG,
4042                      OVRDN_FLAG,
4043                      OVRDN_THRU_DT,
4044                      PRTT_ENRT_RSLT_ID,
4045                      DPNT_PERSON_ID,
4046                      PER_IN_LER_ID,
4047                      BUSINESS_GROUP_ID,
4048                      LCR_ATTRIBUTE_CATEGORY,
4049                      LCR_ATTRIBUTE1,
4050                      LCR_ATTRIBUTE2,
4051                      LCR_ATTRIBUTE3,
4052                      LCR_ATTRIBUTE4,
4053                      LCR_ATTRIBUTE5,
4054                      LCR_ATTRIBUTE6,
4055                      LCR_ATTRIBUTE7,
4056                      LCR_ATTRIBUTE8,
4057                      LCR_ATTRIBUTE9,
4058                      LCR_ATTRIBUTE10,
4059                      LCR_ATTRIBUTE11,
4060                      LCR_ATTRIBUTE12,
4061                      LCR_ATTRIBUTE13,
4062                      LCR_ATTRIBUTE14,
4063                      LCR_ATTRIBUTE15,
4064                      LCR_ATTRIBUTE16,
4065                      LCR_ATTRIBUTE17,
4066                      LCR_ATTRIBUTE18,
4067                      LCR_ATTRIBUTE19,
4068                      LCR_ATTRIBUTE20,
4069                      LCR_ATTRIBUTE21,
4070                      LCR_ATTRIBUTE22,
4071                      LCR_ATTRIBUTE23,
4072                      LCR_ATTRIBUTE24,
4073                      LCR_ATTRIBUTE25,
4074                      LCR_ATTRIBUTE26,
4075                      LCR_ATTRIBUTE27,
4076                      LCR_ATTRIBUTE28,
4077                      LCR_ATTRIBUTE29,
4078                      LCR_ATTRIBUTE30,
4079                      LAST_UPDATE_DATE,
4080                      LAST_UPDATED_BY,
4081                      LAST_UPDATE_LOGIN,
4082                      CREATED_BY,
4083                      CREATION_DATE,
4084                      REQUEST_ID,
4085                      PROGRAM_APPLICATION_ID,
4086                      PROGRAM_ID,
4087                      PROGRAM_UPDATE_DATE,
4088                      OBJECT_VERSION_NUMBER,
4089                      BKUP_TBL_ID,
4090                      EFFECTIVE_START_DATE,
4091                      EFFECTIVE_END_DATE)
4092                  values (
4093                      'BEN_ELIG_CVRD_DPNT_F',
4094                     l_deleted_pdp_rec.CVG_STRT_DT,
4095                     l_deleted_pdp_rec.CVG_THRU_DT,
4096                     l_deleted_pdp_rec.CVG_PNDG_FLAG,
4097                     l_deleted_pdp_rec.OVRDN_FLAG,
4098                     l_deleted_pdp_rec.OVRDN_THRU_DT,
4099                     l_deleted_pdp_rec.PRTT_ENRT_RSLT_ID,
4100                     l_deleted_pdp_rec.DPNT_PERSON_ID,
4101                     l_deleted_pdp_rec.PER_IN_LER_ID,
4105                     l_deleted_pdp_rec.PDP_ATTRIBUTE2,
4102                     l_deleted_pdp_rec.BUSINESS_GROUP_ID,
4103                     l_deleted_pdp_rec.PDP_ATTRIBUTE_CATEGORY,
4104                     l_deleted_pdp_rec.PDP_ATTRIBUTE1,
4106                     l_deleted_pdp_rec.PDP_ATTRIBUTE3,
4107                     l_deleted_pdp_rec.PDP_ATTRIBUTE4,
4108                     l_deleted_pdp_rec.PDP_ATTRIBUTE5,
4109                     l_deleted_pdp_rec.PDP_ATTRIBUTE6,
4110                     l_deleted_pdp_rec.PDP_ATTRIBUTE7,
4111                     l_deleted_pdp_rec.PDP_ATTRIBUTE8,
4112                     l_deleted_pdp_rec.PDP_ATTRIBUTE9,
4113                     l_deleted_pdp_rec.PDP_ATTRIBUTE10,
4114                     l_deleted_pdp_rec.PDP_ATTRIBUTE11,
4115                     l_deleted_pdp_rec.PDP_ATTRIBUTE12,
4116                     l_deleted_pdp_rec.PDP_ATTRIBUTE13,
4117                     l_deleted_pdp_rec.PDP_ATTRIBUTE14,
4118                     l_deleted_pdp_rec.PDP_ATTRIBUTE15,
4119                     l_deleted_pdp_rec.PDP_ATTRIBUTE16,
4120                     l_deleted_pdp_rec.PDP_ATTRIBUTE17,
4121                     l_deleted_pdp_rec.PDP_ATTRIBUTE18,
4122                     l_deleted_pdp_rec.PDP_ATTRIBUTE19,
4123                     l_deleted_pdp_rec.PDP_ATTRIBUTE20,
4124                     l_deleted_pdp_rec.PDP_ATTRIBUTE21,
4125                     l_deleted_pdp_rec.PDP_ATTRIBUTE22,
4126                     l_deleted_pdp_rec.PDP_ATTRIBUTE23,
4127                     l_deleted_pdp_rec.PDP_ATTRIBUTE24,
4128                     l_deleted_pdp_rec.PDP_ATTRIBUTE25,
4129                     l_deleted_pdp_rec.PDP_ATTRIBUTE26,
4130                     l_deleted_pdp_rec.PDP_ATTRIBUTE27,
4131                     l_deleted_pdp_rec.PDP_ATTRIBUTE28,
4132                     l_deleted_pdp_rec.PDP_ATTRIBUTE29,
4133                     l_deleted_pdp_rec.PDP_ATTRIBUTE30,
4134                     l_deleted_pdp_rec.LAST_UPDATE_DATE,
4135                     l_deleted_pdp_rec.LAST_UPDATED_BY,
4136                     l_deleted_pdp_rec.LAST_UPDATE_LOGIN,
4137                     l_deleted_pdp_rec.CREATED_BY,
4138                     l_deleted_pdp_rec.CREATION_DATE,
4139                     l_deleted_pdp_rec.REQUEST_ID,
4140                     l_deleted_pdp_rec.PROGRAM_APPLICATION_ID,
4141                     l_deleted_pdp_rec.PROGRAM_ID,
4142                     l_deleted_pdp_rec.PROGRAM_UPDATE_DATE,
4143                     l_deleted_pdp_rec.OBJECT_VERSION_NUMBER,
4144                     l_deleted_pdp_rec.ELIG_CVRD_DPNT_ID,
4145                     l_deleted_pdp_rec.EFFECTIVE_START_DATE,
4146                     l_deleted_pdp_rec.EFFECTIVE_END_DATE
4147                   );
4148                   --
4149               else
4150                   --
4151                   close c_bkp_row;
4152                   --
4153                   update BEN_LE_CLSN_N_RSTR set
4154                      -- BKUP_TBL_TYP_CD          = 'BEN_ELIG_CVRD_DPNT_F'
4155                      CVG_STRT_DT              = l_deleted_pdp_rec.CVG_STRT_DT,
4156                      CVG_THRU_DT              = l_deleted_pdp_rec.CVG_THRU_DT,
4157                      CVG_PNDG_FLAG            = l_deleted_pdp_rec.CVG_PNDG_FLAG,
4158                      OVRDN_FLAG               = l_deleted_pdp_rec.OVRDN_FLAG,
4159                      OVRDN_THRU_DT            = l_deleted_pdp_rec.OVRDN_THRU_DT,
4160                      PRTT_ENRT_RSLT_ID        = l_deleted_pdp_rec.PRTT_ENRT_RSLT_ID,
4161                      DPNT_PERSON_ID           = l_deleted_pdp_rec.DPNT_PERSON_ID,
4162                      -- PER_IN_LER_ID            = l_deleted_pdp_rec.PER_IN_LER_ID,
4163                      BUSINESS_GROUP_ID        = l_deleted_pdp_rec.BUSINESS_GROUP_ID,
4164                      LCR_ATTRIBUTE_CATEGORY   = l_deleted_pdp_rec.PDP_ATTRIBUTE_CATEGORY,
4165                      LCR_ATTRIBUTE1           = l_deleted_pdp_rec.PDP_ATTRIBUTE1,
4166                      LCR_ATTRIBUTE2           = l_deleted_pdp_rec.PDP_ATTRIBUTE2,
4167                      LCR_ATTRIBUTE3           = l_deleted_pdp_rec.PDP_ATTRIBUTE3,
4168                      LCR_ATTRIBUTE4           = l_deleted_pdp_rec.PDP_ATTRIBUTE4,
4169                      LCR_ATTRIBUTE5           = l_deleted_pdp_rec.PDP_ATTRIBUTE5,
4170                      LCR_ATTRIBUTE6           = l_deleted_pdp_rec.PDP_ATTRIBUTE6,
4171                      LCR_ATTRIBUTE7           = l_deleted_pdp_rec.PDP_ATTRIBUTE7,
4172                      LCR_ATTRIBUTE8           = l_deleted_pdp_rec.PDP_ATTRIBUTE8,
4173                      LCR_ATTRIBUTE9           = l_deleted_pdp_rec.PDP_ATTRIBUTE9,
4174                      LCR_ATTRIBUTE10          = l_deleted_pdp_rec.PDP_ATTRIBUTE10,
4175                      LCR_ATTRIBUTE11          = l_deleted_pdp_rec.PDP_ATTRIBUTE11,
4176                      LCR_ATTRIBUTE12          = l_deleted_pdp_rec.PDP_ATTRIBUTE12,
4177                      LCR_ATTRIBUTE13          = l_deleted_pdp_rec.PDP_ATTRIBUTE13,
4178                      LCR_ATTRIBUTE14          = l_deleted_pdp_rec.PDP_ATTRIBUTE14,
4179                      LCR_ATTRIBUTE15          = l_deleted_pdp_rec.PDP_ATTRIBUTE15,
4180                      LCR_ATTRIBUTE16          = l_deleted_pdp_rec.PDP_ATTRIBUTE16,
4181                      LCR_ATTRIBUTE17          = l_deleted_pdp_rec.PDP_ATTRIBUTE17,
4182                      LCR_ATTRIBUTE18          = l_deleted_pdp_rec.PDP_ATTRIBUTE18,
4183                      LCR_ATTRIBUTE19          = l_deleted_pdp_rec.PDP_ATTRIBUTE19,
4184                      LCR_ATTRIBUTE20          = l_deleted_pdp_rec.PDP_ATTRIBUTE20,
4185                      LCR_ATTRIBUTE21          = l_deleted_pdp_rec.PDP_ATTRIBUTE21,
4186                      LCR_ATTRIBUTE22          = l_deleted_pdp_rec.PDP_ATTRIBUTE22,
4187                      LCR_ATTRIBUTE23          = l_deleted_pdp_rec.PDP_ATTRIBUTE23,
4188                      LCR_ATTRIBUTE24          = l_deleted_pdp_rec.PDP_ATTRIBUTE24,
4189                      LCR_ATTRIBUTE25          = l_deleted_pdp_rec.PDP_ATTRIBUTE25,
4190                      LCR_ATTRIBUTE26          = l_deleted_pdp_rec.PDP_ATTRIBUTE26,
4191                      LCR_ATTRIBUTE27          = l_deleted_pdp_rec.PDP_ATTRIBUTE27,
4195                      LAST_UPDATE_DATE         = l_deleted_pdp_rec.LAST_UPDATE_DATE,
4192                      LCR_ATTRIBUTE28          = l_deleted_pdp_rec.PDP_ATTRIBUTE28,
4193                      LCR_ATTRIBUTE29          = l_deleted_pdp_rec.PDP_ATTRIBUTE29,
4194                      LCR_ATTRIBUTE30          = l_deleted_pdp_rec.PDP_ATTRIBUTE30,
4196                      LAST_UPDATED_BY          = l_deleted_pdp_rec.LAST_UPDATED_BY,
4197                      LAST_UPDATE_LOGIN        = l_deleted_pdp_rec.LAST_UPDATE_LOGIN,
4198                      CREATED_BY               = l_deleted_pdp_rec.CREATED_BY,
4199                      CREATION_DATE            = l_deleted_pdp_rec.CREATION_DATE,
4200                      REQUEST_ID               = l_deleted_pdp_rec.REQUEST_ID,
4201                      PROGRAM_APPLICATION_ID   = l_deleted_pdp_rec.PROGRAM_APPLICATION_ID,
4202                      PROGRAM_ID               = l_deleted_pdp_rec.PROGRAM_ID,
4203                      PROGRAM_UPDATE_DATE      = l_deleted_pdp_rec.PROGRAM_UPDATE_DATE,
4204                      -- OBJECT_VERSION_NUMBER    = l_deleted_pdp_rec.OBJECT_VERSION_NUMBER,
4205                      -- BKUP_TBL_ID              = l_deleted_pdp_rec.CVG_STRT_DT,
4206                      EFFECTIVE_START_DATE     = l_deleted_pdp_rec.EFFECTIVE_START_DATE,
4207                      EFFECTIVE_END_DATE       = l_deleted_pdp_rec.EFFECTIVE_END_DATE
4208                  where rowid = l_row_id;
4209               end if;
4210            end loop;
4211            --
4212            -- Past records exist. So datetrack mode FUTURE_CHANGE.
4213            --
4214            l_datetrack_mode := hr_api.g_future_change;
4215            l_object_version_number := l_max_object_version_number;
4216            --
4217            -- pass the real effective_date also
4218            --
4219            g_bolfe_effective_date:=p_effective_date;
4220            --
4221            -- Delete from the appropriate API.
4222            --
4223            if l_effective_date <> hr_api.g_eot and nvl(p_copy_only,'N') <>  'Y' then
4224              ben_elig_cvrd_dpnt_api.delete_elig_cvrd_dpnt
4225               (p_validate                => false,
4226                p_elig_cvrd_dpnt_id       => l_pk_id,
4227                p_effective_start_date    => l_effective_start_date,
4228                p_effective_end_date      => l_effective_end_date,
4229                p_object_version_number   => l_object_version_number,
4230                p_business_group_id       => p_business_group_id,
4231                p_effective_date          => l_effective_date,
4232                p_datetrack_mode          => l_datetrack_mode,
4233                p_multi_row_actn          =>  false,
4234                p_called_from             => 'benbolfe');
4235            end if;
4236            --
4237            -- null out to prevent bleeding.
4238            -- also do this in the error handler.
4239            --
4240            g_bolfe_effective_date:=null;
4241            --
4242            l_prev_pk_id := l_pk_id;
4243            --
4244            end if; -- l_prev_pk_id <> l_pk_id
4245           -- bud 5668052
4246          else
4247 				  hr_utility.set_location('Effective date is null ',121);
4248           BEN_ELIG_CVRD_DPNT_API.remove_usage(
4249 					        p_validate              => FALSE
4250                  ,p_elig_cvrd_dpnt_id     => l_pk_id
4251                  ,p_cvg_thru_dt           => NULL
4252                  ,p_effective_date        => l_dpnt_eff_start_date
4253                  ,p_datetrack_mode        => hr_api.g_zap
4254                  );
4255 
4256         end if;
4257         --
4258       end loop;
4259       --
4260       --
4261       ---- # bug 2546259 when the PEN coverage is future dated and
4262       ---  deenreolled, the pen result is voided  and PDP result is
4263       ---  End dated in Delete mode, so no date track record is created
4264       ---  there is no relation between PIL and the end dated PDP is maintained
4265       ---  PDP does not have any status too
4266       ---- when the LE is backedout  the PDP is not reinstated becasue there is not
4267       ---- relation between PIL and the PDP record. This fix reinstate the PDP record
4268       ---- first cursor find all the result voided by the PIL and coverage is future dtd
4269       ---- Second cursor find the PDP record end dated for the result
4270       if   nvl(p_copy_only,'N') <>  'Y' then
4271         for l_f_pen  in  c_futur_pen  loop
4272            hr_utility.set_location ('with in future loop  '||l_f_pen.prtt_enrt_rslt_id,10);
4273            open c_futur_del_dpnt (l_f_pen.prtt_enrt_rslt_id ) ;
4274            Loop
4275               fetch c_futur_del_dpnt into l_pk_id,l_object_version_number,l_effective_date ;
4276               exit when c_futur_del_dpnt%notfound;
4277 
4278 
4279               l_datetrack_mode := hr_api.g_future_change;
4280                ben_elig_cvrd_dpnt_api.delete_elig_cvrd_dpnt
4281                  (p_validate                => false,
4282                   p_elig_cvrd_dpnt_id       => l_pk_id,
4283                   p_effective_start_date    => l_effective_start_date,
4284                   p_effective_end_date      => l_effective_end_date,
4285                   p_object_version_number   => l_object_version_number,
4286                   p_business_group_id       => p_business_group_id,
4287                   p_effective_date          => l_effective_date,
4288                   p_datetrack_mode          => l_datetrack_mode,
4289                   p_called_from             => 'benbolfe');
4290 
4291 
4292            end loop ;
4293            close c_futur_del_dpnt ;
4294         --
4295 
4296         end loop  ;
4297      end if ;
4298 
4299       ---- if any of the result in corrected and stored in backp table for correction
4300       ---- correct the per_in_ler_id of related the dpnt table too  bug # 3086161
4301 
4302       for i in c_BEN_LE_CLSN_N_RSTR_dpnt(p_per_in_ler_id )
4303       Loop
4304           if l_prev_elig_cvrd_dpnt_id <> i.elig_cvrd_dpnt_id then
4308                   (p_validate                => FALSE
4305                l_object_version_number := i.object_version_number ;
4306                  hr_utility.set_location(' correcting  ' || i.elig_cvrd_dpnt_id, 999 );
4307                ben_elig_cvrd_dpnt_api.update_elig_cvrd_dpnt
4309                   ,p_business_group_id       => p_business_group_id
4310                   ,p_elig_cvrd_dpnt_id       => i.elig_cvrd_dpnt_id
4311                   ,p_effective_start_date    => l_effective_start_date
4312                   ,p_effective_end_date      => l_effective_end_date
4313                   ,p_cvg_thru_dt             => i.enrt_cvg_thru_dt
4314                   ,p_per_in_ler_id           => i.per_in_ler_id
4315                   ,p_object_version_number   => l_object_version_number
4316                   ,p_effective_date          => i.effective_start_date
4317                   ,p_datetrack_mode          => hr_api.g_correction
4318                   ,p_multi_row_actn          => FALSE);
4319            l_prev_elig_cvrd_dpnt_id := i.elig_cvrd_dpnt_id;
4320                --
4321                --  Correct the effective end date.  7197868
4322                --
4323                if (i.bkp_effective_end_date =  hr_api.g_eot
4324                    and i.effective_end_date <> i.bkp_effective_end_date) then
4325                  --
4326                  --  Delete future dated rows.
4327                  --
4328                  ben_elig_cvrd_dpnt_api.delete_elig_cvrd_dpnt
4329                    (p_validate                => false,
4330                     p_elig_cvrd_dpnt_id       => i.elig_cvrd_dpnt_id,
4331                     p_effective_start_date    => l_effective_start_date,
4332                     p_effective_end_date      => l_effective_end_date,
4333                     p_object_version_number   => l_object_version_number,
4334                     p_business_group_id       => p_business_group_id,
4335                     p_effective_date          => i.bkp_effective_start_date,
4336                     p_datetrack_mode          => hr_api.g_future_change,
4337                     p_called_from             => 'benbolfe');
4338                end if;
4339                  --
4340                  --   End 7197868
4341                  --
4342           end if;
4343       --
4344 
4345 
4346       end loop ;
4347 
4348 
4349 
4350       l_prev_pk_id := -1;
4351       --
4352 
4353     close c_ben_elig_cvrd_dpnt_f;
4354     --
4355   elsif p_routine = 'BEN_ELIG_PER_F' then
4356 
4357     -- For elig_per, we want to 'un-end' any records that were ENDED
4358     -- due to the per-in-ler.  The 'future-change' date track mode will do that
4359     -- for us.
4360     -- Others can be left alone because their FK to per-in-ler will indicate
4361     -- that they are really 'backed out'.
4362 
4363     l_prev_pk_id := -1; -- like null
4364 
4365     --
4366     open c_ben_elig_per_f;
4367       --
4368       loop
4369         --
4370         fetch c_ben_elig_per_f into l_pk_id,
4371 									l_object_version_number,
4372 									l_effective_date_new;
4373 		--hr_utility.set_location('ben_elig_per_id '||l_pk_id,48);
4374 		--hr_utility.set_location('l_effective_date_new '||l_effective_date_new,48);
4375         exit when c_ben_elig_per_f%notfound;
4376         --
4377         -- Get the maximum of effective end date
4378         -- with past per_in_ler 's.
4379         --
4380         l_effective_date := null;
4381         open  c_pep_max_esd_of_past_pil(l_pk_id);
4382         fetch c_pep_max_esd_of_past_pil into l_effective_date,
4383                                              l_max_object_version_number;
4384         close c_pep_max_esd_of_past_pil;
4385         --
4386         -- The group function "max" returns null when no records found,
4387         -- so check l_effective_date is null to find whether any
4388         -- past records were found.
4389         --
4390         --
4391         if l_effective_date is not null then
4392 
4393          --
4394          -- Do not process the row as it is already processed(deleted).
4395          --
4396          if l_prev_pk_id <> l_pk_id then
4397            --
4398            -- Bug 1814166 : Causing primary key violation
4399            -- Commented as the data is not used by benleclr.pkb
4400            --
4401            null;
4402            --
4403            /*
4404            -- now backup all the deleted enrollment rows
4405            --
4406            for l_deleted_pep_rec in c_deleted_pep(l_pk_id, l_effective_date)
4407            loop
4408              --
4409               insert into BEN_LE_CLSN_N_RSTR (
4410                   BKUP_TBL_TYP_CD,
4411                   PLIP_ID,
4412                   PTIP_ID,
4413                   WAIT_PERD_CMPLTN_DT,
4414                   PER_IN_LER_ID,
4415                   RT_FRZ_PCT_FL_TM_FLAG,
4416                   RT_FRZ_HRS_WKD_FLAG,
4417                   RT_FRZ_COMB_AGE_AND_LOS_FLAG,
4418                   ONCE_R_CNTUG_CD,
4419                   BKUP_TBL_ID,         -- ELIG_PER_ID,
4420                   EFFECTIVE_START_DATE,
4421                   EFFECTIVE_END_DATE,
4422                   BUSINESS_GROUP_ID,
4423                   PL_ID,
4424                   PGM_ID,
4425                   LER_ID,
4426                   PERSON_ID,
4427                   DPNT_OTHR_PL_CVRD_RL_FLAG,
4428                   PRTN_OVRIDN_THRU_DT,
4429                   PL_KEY_EE_FLAG,
4430                   PL_HGHLY_COMPD_FLAG,
4431                   ELIG_FLAG,
4432                   COMP_REF_AMT,
4433                   CMBN_AGE_N_LOS_VAL,
4434                   COMP_REF_UOM,
4435                   AGE_VAL,
4436                   LOS_VAL,
4437                   PRTN_END_DT,
4438                   PRTN_STRT_DT,
4439                   WV_CTFN_TYP_CD,
4440                   HRS_WKD_VAL,
4444                   PRTN_OVRIDN_RSN_CD,
4441                   HRS_WKD_BNDRY_PERD_CD,
4442                   PRTN_OVRIDN_FLAG,
4443                   NO_MX_PRTN_OVRID_THRU_FLAG,
4445                   AGE_UOM,
4446                   LOS_UOM,
4447                   OVRID_SVC_DT,
4448                   FRZ_LOS_FLAG,
4449                   FRZ_AGE_FLAG,
4450                   FRZ_CMP_LVL_FLAG,
4451                   FRZ_PCT_FL_TM_FLAG,
4452                   FRZ_HRS_WKD_FLAG,
4453                   FRZ_COMB_AGE_AND_LOS_FLAG,
4454                   DSTR_RSTCN_FLAG,
4455                   PCT_FL_TM_VAL,
4456                   WV_PRTN_RSN_CD,
4457                   PL_WVD_FLAG,
4458                   LCR_ATTRIBUTE_CATEGORY,
4459                   LCR_ATTRIBUTE1,
4460                   LCR_ATTRIBUTE2,
4461                   LCR_ATTRIBUTE3,
4462                   LCR_ATTRIBUTE4,
4463                   LCR_ATTRIBUTE5,
4464                   LCR_ATTRIBUTE6,
4465                   LCR_ATTRIBUTE7,
4466                   LCR_ATTRIBUTE8,
4467                   LCR_ATTRIBUTE9,
4468                   LCR_ATTRIBUTE10,
4469                   LCR_ATTRIBUTE11,
4470                   LCR_ATTRIBUTE12,
4471                   LCR_ATTRIBUTE13,
4472                   LCR_ATTRIBUTE14,
4473                   LCR_ATTRIBUTE15,
4474                   LCR_ATTRIBUTE16,
4475                   LCR_ATTRIBUTE17,
4476                   LCR_ATTRIBUTE18,
4477                   LCR_ATTRIBUTE19,
4478                   LCR_ATTRIBUTE20,
4479                   LCR_ATTRIBUTE21,
4480                   LCR_ATTRIBUTE22,
4481                   LCR_ATTRIBUTE23,
4482                   LCR_ATTRIBUTE24,
4483                   LCR_ATTRIBUTE25,
4484                   LCR_ATTRIBUTE26,
4485                   LCR_ATTRIBUTE27,
4486                   LCR_ATTRIBUTE28,
4487                   LCR_ATTRIBUTE29,
4488                   LCR_ATTRIBUTE30,
4489                   LAST_UPDATE_DATE,
4490                   LAST_UPDATED_BY,
4491                   LAST_UPDATE_LOGIN,
4492                   CREATED_BY,
4493                   CREATION_DATE,
4494                   REQUEST_ID,
4495                   PROGRAM_APPLICATION_ID,
4496                   PROGRAM_ID,
4497                   PROGRAM_UPDATE_DATE,
4498                   OBJECT_VERSION_NUMBER,
4499                   MUST_ENRL_ANTHR_PL_ID,
4500                   RT_COMP_REF_AMT,
4501                   RT_CMBN_AGE_N_LOS_VAL,
4502                   RT_COMP_REF_UOM,
4503                   RT_AGE_VAL,
4504                   RT_LOS_VAL,
4505                   RT_HRS_WKD_VAL,
4506                   RT_HRS_WKD_BNDRY_PERD_CD,
4507                   RT_AGE_UOM,
4508                   RT_LOS_UOM,
4509                   RT_PCT_FL_TM_VAL,
4510                   RT_FRZ_LOS_FLAG,
4511                   RT_FRZ_AGE_FLAG,
4512                   RT_FRZ_CMP_LVL_FLAG,
4513                   INELG_RSN_CD,
4514                   PL_ORDR_NUM,
4515                   PLIP_ORDR_NUM,
4516                   PTIP_ORDR_NUM  )
4517               values (
4518                  'BEN_ELIG_PER_F',
4519                  l_deleted_pep_rec.PLIP_ID,
4520                  l_deleted_pep_rec.PTIP_ID,
4521                  l_deleted_pep_rec.WAIT_PERD_CMPLTN_DT,
4522                  l_deleted_pep_rec.PER_IN_LER_ID,
4523                  l_deleted_pep_rec.RT_FRZ_PCT_FL_TM_FLAG,
4524                  l_deleted_pep_rec.RT_FRZ_HRS_WKD_FLAG,
4525                  l_deleted_pep_rec.RT_FRZ_COMB_AGE_AND_LOS_FLAG,
4526                  l_deleted_pep_rec.ONCE_R_CNTUG_CD,
4527                  l_deleted_pep_rec.ELIG_PER_ID,
4528                  l_deleted_pep_rec.EFFECTIVE_START_DATE,
4529                  l_deleted_pep_rec.EFFECTIVE_END_DATE,
4530                  l_deleted_pep_rec.BUSINESS_GROUP_ID,
4531                  l_deleted_pep_rec.PL_ID,
4532                  l_deleted_pep_rec.PGM_ID,
4533                  l_deleted_pep_rec.LER_ID,
4534                  l_deleted_pep_rec.PERSON_ID,
4535                  l_deleted_pep_rec.DPNT_OTHR_PL_CVRD_RL_FLAG,
4536                  l_deleted_pep_rec.PRTN_OVRIDN_THRU_DT,
4537                  l_deleted_pep_rec.PL_KEY_EE_FLAG,
4538                  l_deleted_pep_rec.PL_HGHLY_COMPD_FLAG,
4539                  l_deleted_pep_rec.ELIG_FLAG,
4540                  l_deleted_pep_rec.COMP_REF_AMT,
4541                  l_deleted_pep_rec.CMBN_AGE_N_LOS_VAL,
4542                  l_deleted_pep_rec.COMP_REF_UOM,
4543                  l_deleted_pep_rec.AGE_VAL,
4544                  l_deleted_pep_rec.LOS_VAL,
4545                  l_deleted_pep_rec.PRTN_END_DT,
4546                  l_deleted_pep_rec.PRTN_STRT_DT,
4547                  l_deleted_pep_rec.WV_CTFN_TYP_CD,
4548                  l_deleted_pep_rec.HRS_WKD_VAL,
4549                  l_deleted_pep_rec.HRS_WKD_BNDRY_PERD_CD,
4550                  l_deleted_pep_rec.PRTN_OVRIDN_FLAG,
4551                  l_deleted_pep_rec.NO_MX_PRTN_OVRID_THRU_FLAG,
4552                  l_deleted_pep_rec.PRTN_OVRIDN_RSN_CD,
4553                  l_deleted_pep_rec.AGE_UOM,
4554                  l_deleted_pep_rec.LOS_UOM,
4555                  l_deleted_pep_rec.OVRID_SVC_DT,
4556                  l_deleted_pep_rec.FRZ_LOS_FLAG,
4557                  l_deleted_pep_rec.FRZ_AGE_FLAG,
4558                  l_deleted_pep_rec.FRZ_CMP_LVL_FLAG,
4559                  l_deleted_pep_rec.FRZ_PCT_FL_TM_FLAG,
4560                  l_deleted_pep_rec.FRZ_HRS_WKD_FLAG,
4561                  l_deleted_pep_rec.FRZ_COMB_AGE_AND_LOS_FLAG,
4562                  l_deleted_pep_rec.DSTR_RSTCN_FLAG,
4563                  l_deleted_pep_rec.PCT_FL_TM_VAL,
4564                  l_deleted_pep_rec.WV_PRTN_RSN_CD,
4565                  l_deleted_pep_rec.PL_WVD_FLAG,
4566                  l_deleted_pep_rec.PEP_ATTRIBUTE_CATEGORY,
4567                  l_deleted_pep_rec.PEP_ATTRIBUTE1,
4568                  l_deleted_pep_rec.PEP_ATTRIBUTE2,
4572                  l_deleted_pep_rec.PEP_ATTRIBUTE6,
4569                  l_deleted_pep_rec.PEP_ATTRIBUTE3,
4570                  l_deleted_pep_rec.PEP_ATTRIBUTE4,
4571                  l_deleted_pep_rec.PEP_ATTRIBUTE5,
4573                  l_deleted_pep_rec.PEP_ATTRIBUTE7,
4574                  l_deleted_pep_rec.PEP_ATTRIBUTE8,
4575                  l_deleted_pep_rec.PEP_ATTRIBUTE9,
4576                  l_deleted_pep_rec.PEP_ATTRIBUTE10,
4577                  l_deleted_pep_rec.PEP_ATTRIBUTE11,
4578                  l_deleted_pep_rec.PEP_ATTRIBUTE12,
4579                  l_deleted_pep_rec.PEP_ATTRIBUTE13,
4580                  l_deleted_pep_rec.PEP_ATTRIBUTE14,
4581                  l_deleted_pep_rec.PEP_ATTRIBUTE15,
4582                  l_deleted_pep_rec.PEP_ATTRIBUTE16,
4583                  l_deleted_pep_rec.PEP_ATTRIBUTE17,
4584                  l_deleted_pep_rec.PEP_ATTRIBUTE18,
4585                  l_deleted_pep_rec.PEP_ATTRIBUTE19,
4586                  l_deleted_pep_rec.PEP_ATTRIBUTE20,
4587                  l_deleted_pep_rec.PEP_ATTRIBUTE21,
4588                  l_deleted_pep_rec.PEP_ATTRIBUTE22,
4589                  l_deleted_pep_rec.PEP_ATTRIBUTE23,
4590                  l_deleted_pep_rec.PEP_ATTRIBUTE24,
4591                  l_deleted_pep_rec.PEP_ATTRIBUTE25,
4592                  l_deleted_pep_rec.PEP_ATTRIBUTE26,
4593                  l_deleted_pep_rec.PEP_ATTRIBUTE27,
4594                  l_deleted_pep_rec.PEP_ATTRIBUTE28,
4595                  l_deleted_pep_rec.PEP_ATTRIBUTE29,
4596                  l_deleted_pep_rec.PEP_ATTRIBUTE30,
4597                  l_deleted_pep_rec.LAST_UPDATE_DATE,
4598                  l_deleted_pep_rec.LAST_UPDATED_BY,
4599                  l_deleted_pep_rec.LAST_UPDATE_LOGIN,
4600                  l_deleted_pep_rec.CREATED_BY,
4601                  l_deleted_pep_rec.CREATION_DATE,
4602                  l_deleted_pep_rec.REQUEST_ID,
4603                  l_deleted_pep_rec.PROGRAM_APPLICATION_ID,
4604                  l_deleted_pep_rec.PROGRAM_ID,
4605                  l_deleted_pep_rec.PROGRAM_UPDATE_DATE,
4606                  l_deleted_pep_rec.OBJECT_VERSION_NUMBER,
4607                  l_deleted_pep_rec.MUST_ENRL_ANTHR_PL_ID,
4608                  l_deleted_pep_rec.RT_COMP_REF_AMT,
4609                  l_deleted_pep_rec.RT_CMBN_AGE_N_LOS_VAL,
4610                  l_deleted_pep_rec.RT_COMP_REF_UOM,
4611                  l_deleted_pep_rec.RT_AGE_VAL,
4612                  l_deleted_pep_rec.RT_LOS_VAL,
4613                  l_deleted_pep_rec.RT_HRS_WKD_VAL,
4614                  l_deleted_pep_rec.RT_HRS_WKD_BNDRY_PERD_CD,
4615                  l_deleted_pep_rec.RT_AGE_UOM,
4616                  l_deleted_pep_rec.RT_LOS_UOM,
4617                  l_deleted_pep_rec.RT_PCT_FL_TM_VAL,
4618                  l_deleted_pep_rec.RT_FRZ_LOS_FLAG,
4619                  l_deleted_pep_rec.RT_FRZ_AGE_FLAG,
4620                  l_deleted_pep_rec.RT_FRZ_CMP_LVL_FLAG,
4621                  l_deleted_pep_rec.INELG_RSN_CD,
4622                  l_deleted_pep_rec.PL_ORDR_NUM,
4623                  l_deleted_pep_rec.PLIP_ORDR_NUM,
4624                  l_deleted_pep_rec.PTIP_ORDR_NUM
4625                );
4626 
4627              --
4628            end loop;
4629            */
4630            --
4631            -- Past records exist. So datetrack mode FUTURE_CHANGE.
4632            --
4633            l_datetrack_mode := hr_api.g_delete_next_change;
4634            l_object_version_number := l_max_object_version_number;
4635           --
4636           -- Delete from the appropriate API.
4637           --
4638           if l_effective_date <> hr_api.g_eot  and nvl(p_copy_only,'N') <>  'Y'  then
4639             ben_eligible_person_api.delete_eligible_person
4640               (p_validate                => false,
4641                p_elig_per_id       => l_pk_id,
4642                p_effective_start_date    => l_effective_start_date,
4643                p_effective_end_date      => l_effective_end_date,
4644                p_object_version_number   => l_object_version_number,
4645                p_effective_date          => l_effective_date,
4646                p_datetrack_mode          => l_datetrack_mode);
4647           end if;
4648           --
4649           l_prev_pk_id := l_pk_id;
4650           --
4651          end if; -- l_prev_pk_id <> l_pk_id
4652 
4653         end if;
4654         --
4655       end loop;
4656       --
4657       --
4658       l_prev_pk_id := -1;
4659       --
4660 
4661     close c_ben_elig_per_f;
4662     --
4663   elsif p_routine = 'BEN_ELIG_PER_OPT_F'
4664   then
4665     -- we want to 'un-end' any records that were ENDED
4666     -- due to the per-in-ler.  The 'future-change' date track mode will do that
4667     -- for us.
4668     -- Others can be left alone because their FK to per-in-ler will indicate
4669     -- that they are really 'backed out'.
4670 
4671     l_prev_pk_id := -1; -- like null
4672 
4673     --
4674     open c_ben_elig_per_opt_f;
4675       --
4676       loop
4677         --
4678         fetch c_ben_elig_per_opt_f into l_pk_id,
4679  										l_object_version_number,
4680  										l_effective_date_new;
4681         exit when c_ben_elig_per_opt_f%notfound;
4682         --
4683         -- Get the maximum of effective end date for the dependents
4684         -- with past per_in_ler 's.
4685         --
4686         l_effective_date := null;
4687         open  c_epo_max_esd_of_past_pil(l_pk_id);
4688         fetch c_epo_max_esd_of_past_pil into l_effective_date,
4689                                              l_max_object_version_number;
4690         close c_epo_max_esd_of_past_pil;
4691         --
4692         -- The group function "max" returns null when no records found,
4693         -- so check l_effective_date is null to find whether any
4694         -- past records were found.
4695         --
4696         --
4700          --
4697         if l_effective_date is not null then
4698          --
4699          -- Do not process the row as it is already processed(deleted).
4701          if l_prev_pk_id <> l_pk_id then
4702            --
4703            -- Bug 1814166 : Causing primary key violation
4704            -- Commented as the data is not used by benleclr.pkb
4705            --
4706            null;
4707            --
4708            /*
4709            -- now backup all the to be deleted enrollment rows
4710            --
4711            for l_deleted_epo_rec in c_deleted_epo(l_pk_id, l_effective_date)
4712            loop
4713              --
4714              insert into BEN_LE_CLSN_N_RSTR (
4715                  BKUP_TBL_TYP_CD,
4716                  INELG_RSN_CD,
4717                  PER_IN_LER_ID,
4718                  AGE_UOM,
4719                  LOS_UOM,
4720                  FRZ_LOS_FLAG,
4721                  FRZ_AGE_FLAG,
4722                  FRZ_CMP_LVL_FLAG,
4723                  FRZ_PCT_FL_TM_FLAG,
4724                  FRZ_HRS_WKD_FLAG,
4725                  FRZ_COMB_AGE_AND_LOS_FLAG,
4726                  OVRID_SVC_DT,
4727                  WAIT_PERD_CMPLTN_DT,
4728                  COMP_REF_AMT,
4729                  CMBN_AGE_N_LOS_VAL,
4730                  COMP_REF_UOM,
4731                  AGE_VAL,
4732                  LOS_VAL,
4733                  HRS_WKD_VAL,
4734                  HRS_WKD_BNDRY_PERD_CD,
4735                  RT_COMP_REF_AMT,
4736                  RT_CMBN_AGE_N_LOS_VAL,
4737                  RT_COMP_REF_UOM,
4738                  RT_AGE_VAL,
4739                  RT_LOS_VAL,
4740                  RT_HRS_WKD_VAL,
4741                  RT_HRS_WKD_BNDRY_PERD_CD,
4742                  RT_AGE_UOM,
4743                  RT_LOS_UOM,
4744                  RT_PCT_FL_TM_VAL,
4745                  RT_FRZ_LOS_FLAG,
4746                  RT_FRZ_AGE_FLAG,
4747                  RT_FRZ_CMP_LVL_FLAG,
4748                  RT_FRZ_PCT_FL_TM_FLAG,
4749                  RT_FRZ_HRS_WKD_FLAG,
4750                  RT_FRZ_COMB_AGE_AND_LOS_FLAG,
4751                  BKUP_TBL_ID,   -- ELIG_PER_OPT_ID,
4752                  ELIG_PER_ID,
4753                  EFFECTIVE_START_DATE,
4754                  EFFECTIVE_END_DATE,
4755                  PRTN_OVRIDN_FLAG,
4756                  PRTN_OVRIDN_THRU_DT,
4757                  NO_MX_PRTN_OVRID_THRU_FLAG,
4758                  ELIG_FLAG,
4759                  PRTN_STRT_DT,
4760                  PRTN_OVRIDN_RSN_CD,
4761                  PCT_FL_TM_VAL,
4762                  OPT_ID,
4763                  BUSINESS_GROUP_ID,
4764                  LCR_ATTRIBUTE_CATEGORY,
4765                  LCR_ATTRIBUTE1,
4766                  LCR_ATTRIBUTE2,
4767                  LCR_ATTRIBUTE3,
4768                  LCR_ATTRIBUTE4,
4769                  LCR_ATTRIBUTE5,
4770                  LCR_ATTRIBUTE6,
4771                  LCR_ATTRIBUTE7,
4772                  LCR_ATTRIBUTE8,
4773                  LCR_ATTRIBUTE9,
4774                  LCR_ATTRIBUTE10,
4775                  LCR_ATTRIBUTE11,
4776                  LCR_ATTRIBUTE12,
4777                  LCR_ATTRIBUTE13,
4778                  LCR_ATTRIBUTE14,
4779                  LCR_ATTRIBUTE15,
4780                  LCR_ATTRIBUTE16,
4781                  LCR_ATTRIBUTE17,
4782                  LCR_ATTRIBUTE18,
4783                  LCR_ATTRIBUTE19,
4784                  LCR_ATTRIBUTE20,
4785                  LCR_ATTRIBUTE21,
4786                  LCR_ATTRIBUTE22,
4787                  LCR_ATTRIBUTE23,
4788                  LCR_ATTRIBUTE24,
4789                  LCR_ATTRIBUTE25,
4790                  LCR_ATTRIBUTE26,
4791                  LCR_ATTRIBUTE27,
4792                  LCR_ATTRIBUTE28,
4793                  LCR_ATTRIBUTE29,
4794                  LCR_ATTRIBUTE30,
4795                  LAST_UPDATE_DATE,
4796                  LAST_UPDATED_BY,
4797                  LAST_UPDATE_LOGIN,
4798                  CREATED_BY,
4799                  CREATION_DATE,
4800                  REQUEST_ID,
4801                  PROGRAM_APPLICATION_ID,
4802                  PROGRAM_ID,
4803                  PROGRAM_UPDATE_DATE,
4804                  OBJECT_VERSION_NUMBER,
4805                  ONCE_R_CNTUG_CD,
4806                  OIPL_ORDR_NUM,
4807                  PRTN_END_DT  )
4808              values (
4809                 'BEN_ELIG_PER_OPT_F',
4810                 l_deleted_epo_rec.INELG_RSN_CD,
4811                 l_deleted_epo_rec.PER_IN_LER_ID,
4812                 l_deleted_epo_rec.AGE_UOM,
4813                 l_deleted_epo_rec.LOS_UOM,
4814                 l_deleted_epo_rec.FRZ_LOS_FLAG,
4815                 l_deleted_epo_rec.FRZ_AGE_FLAG,
4816                 l_deleted_epo_rec.FRZ_CMP_LVL_FLAG,
4817                 l_deleted_epo_rec.FRZ_PCT_FL_TM_FLAG,
4818                 l_deleted_epo_rec.FRZ_HRS_WKD_FLAG,
4819                 l_deleted_epo_rec.FRZ_COMB_AGE_AND_LOS_FLAG,
4820                 l_deleted_epo_rec.OVRID_SVC_DT,
4821                 l_deleted_epo_rec.WAIT_PERD_CMPLTN_DATE,
4822                 l_deleted_epo_rec.COMP_REF_AMT,
4823                 l_deleted_epo_rec.CMBN_AGE_N_LOS_VAL,
4824                 l_deleted_epo_rec.COMP_REF_UOM,
4825                 l_deleted_epo_rec.AGE_VAL,
4826                 l_deleted_epo_rec.LOS_VAL,
4827                 l_deleted_epo_rec.HRS_WKD_VAL,
4828                 l_deleted_epo_rec.HRS_WKD_BNDRY_PERD_CD,
4829                 l_deleted_epo_rec.RT_COMP_REF_AMT,
4830                 l_deleted_epo_rec.RT_CMBN_AGE_N_LOS_VAL,
4831                 l_deleted_epo_rec.RT_COMP_REF_UOM,
4832                 l_deleted_epo_rec.RT_AGE_VAL,
4833                 l_deleted_epo_rec.RT_LOS_VAL,
4834                 l_deleted_epo_rec.RT_HRS_WKD_VAL,
4835                 l_deleted_epo_rec.RT_HRS_WKD_BNDRY_PERD_CD,
4839                 l_deleted_epo_rec.RT_FRZ_LOS_FLAG,
4836                 l_deleted_epo_rec.RT_AGE_UOM,
4837                 l_deleted_epo_rec.RT_LOS_UOM,
4838                 l_deleted_epo_rec.RT_PCT_FL_TM_VAL,
4840                 l_deleted_epo_rec.RT_FRZ_AGE_FLAG,
4841                 l_deleted_epo_rec.RT_FRZ_CMP_LVL_FLAG,
4842                 l_deleted_epo_rec.RT_FRZ_PCT_FL_TM_FLAG,
4843                 l_deleted_epo_rec.RT_FRZ_HRS_WKD_FLAG,
4844                 l_deleted_epo_rec.RT_FRZ_COMB_AGE_AND_LOS_FLAG,
4845                 l_deleted_epo_rec.ELIG_PER_OPT_ID,
4846                 l_deleted_epo_rec.ELIG_PER_ID,
4847                 l_deleted_epo_rec.EFFECTIVE_START_DATE,
4848                 l_deleted_epo_rec.EFFECTIVE_END_DATE,
4849                 l_deleted_epo_rec.PRTN_OVRIDN_FLAG,
4850                 l_deleted_epo_rec.PRTN_OVRIDN_THRU_DT,
4851                 l_deleted_epo_rec.NO_MX_PRTN_OVRID_THRU_FLAG,
4852                 l_deleted_epo_rec.ELIG_FLAG,
4853                 l_deleted_epo_rec.PRTN_STRT_DT,
4854                 l_deleted_epo_rec.PRTN_OVRIDN_RSN_CD,
4855                 l_deleted_epo_rec.PCT_FL_TM_VAL,
4856                 l_deleted_epo_rec.OPT_ID,
4857                 l_deleted_epo_rec.BUSINESS_GROUP_ID,
4858                 l_deleted_epo_rec.EPO_ATTRIBUTE_CATEGORY,
4859                 l_deleted_epo_rec.EPO_ATTRIBUTE1,
4860                 l_deleted_epo_rec.EPO_ATTRIBUTE2,
4861                 l_deleted_epo_rec.EPO_ATTRIBUTE3,
4862                 l_deleted_epo_rec.EPO_ATTRIBUTE4,
4863                 l_deleted_epo_rec.EPO_ATTRIBUTE5,
4864                 l_deleted_epo_rec.EPO_ATTRIBUTE6,
4865                 l_deleted_epo_rec.EPO_ATTRIBUTE7,
4866                 l_deleted_epo_rec.EPO_ATTRIBUTE8,
4867                 l_deleted_epo_rec.EPO_ATTRIBUTE9,
4868                 l_deleted_epo_rec.EPO_ATTRIBUTE10,
4869                 l_deleted_epo_rec.EPO_ATTRIBUTE11,
4870                 l_deleted_epo_rec.EPO_ATTRIBUTE12,
4871                 l_deleted_epo_rec.EPO_ATTRIBUTE13,
4872                 l_deleted_epo_rec.EPO_ATTRIBUTE14,
4873                 l_deleted_epo_rec.EPO_ATTRIBUTE15,
4874                 l_deleted_epo_rec.EPO_ATTRIBUTE16,
4875                 l_deleted_epo_rec.EPO_ATTRIBUTE17,
4876                 l_deleted_epo_rec.EPO_ATTRIBUTE18,
4877                 l_deleted_epo_rec.EPO_ATTRIBUTE19,
4878                 l_deleted_epo_rec.EPO_ATTRIBUTE20,
4879                 l_deleted_epo_rec.EPO_ATTRIBUTE21,
4880                 l_deleted_epo_rec.EPO_ATTRIBUTE22,
4881                 l_deleted_epo_rec.EPO_ATTRIBUTE23,
4882                 l_deleted_epo_rec.EPO_ATTRIBUTE24,
4883                 l_deleted_epo_rec.EPO_ATTRIBUTE25,
4884                 l_deleted_epo_rec.EPO_ATTRIBUTE26,
4885                 l_deleted_epo_rec.EPO_ATTRIBUTE27,
4886                 l_deleted_epo_rec.EPO_ATTRIBUTE28,
4887                 l_deleted_epo_rec.EPO_ATTRIBUTE29,
4888                 l_deleted_epo_rec.EPO_ATTRIBUTE30,
4889                 l_deleted_epo_rec.LAST_UPDATE_DATE,
4890                 l_deleted_epo_rec.LAST_UPDATED_BY,
4891                 l_deleted_epo_rec.LAST_UPDATE_LOGIN,
4892                 l_deleted_epo_rec.CREATED_BY,
4893                 l_deleted_epo_rec.CREATION_DATE,
4894                 l_deleted_epo_rec.REQUEST_ID,
4895                 l_deleted_epo_rec.PROGRAM_APPLICATION_ID,
4896                 l_deleted_epo_rec.PROGRAM_ID,
4897                 l_deleted_epo_rec.PROGRAM_UPDATE_DATE,
4898                 l_deleted_epo_rec.OBJECT_VERSION_NUMBER,
4899                 l_deleted_epo_rec.ONCE_R_CNTUG_CD,
4900                 l_deleted_epo_rec.OIPL_ORDR_NUM,
4901                 l_deleted_epo_rec.PRTN_END_DT
4902              );
4903              --
4904            end loop;
4905            */
4906            --
4907            -- Past records exist. So datetrack mode FUTURE_CHANGE.
4908            --
4909            l_datetrack_mode := hr_api.g_future_change;
4910            l_object_version_number := l_max_object_version_number;
4911           --
4912           -- Delete from the appropriate API.
4913           --
4914           if l_effective_date <> hr_api.g_eot  and nvl(p_copy_only,'N') <>  'Y'  then
4918                p_effective_start_date    => l_effective_start_date,
4915             ben_elig_person_option_api.delete_elig_person_option
4916               (p_validate                => false,
4917                p_elig_per_opt_id       => l_pk_id,
4919                p_effective_end_date      => l_effective_end_date,
4920                p_object_version_number   => l_object_version_number,
4921                p_effective_date          => l_effective_date,
4922                p_datetrack_mode          => l_datetrack_mode);
4923           end if;
4924           --
4925           l_prev_pk_id := l_pk_id;
4926           --
4927 
4928          end if; -- l_prev_pk_id <> l_pk_id
4929 
4930         end if;
4931         --
4932       end loop;
4933       --
4937     close c_ben_elig_per_opt_f;
4934       l_prev_pk_id := -1;
4935       --
4936 
4938     --
4939   elsif p_routine = 'BEN_PRTT_PREM_F' then
4940     -------------Bug 7133998
4941     for l_prtt_prem_corr in c_ben_prtt_prem_f_corr loop
4942       hr_utility.set_location('l_prtt_prem_corr.PRTT_PREM_ID : '||l_prtt_prem_corr.PRTT_PREM_ID,1);
4943       hr_utility.set_location('ESD : '||l_prtt_prem_corr.effective_start_date,1);
4944       hr_utility.set_location('EED : '||l_prtt_prem_corr.effective_end_date,1);
4945       for l_bkp_prem_row in c_bkp_prem_row('BEN_PRTT_PREM_F_CORR',
4946                              l_prtt_prem_corr.PRTT_PREM_ID,
4947                              l_prtt_prem_corr.effective_start_date,
4948 			     l_prtt_prem_corr.effective_end_date) loop
4949 	  hr_utility.set_location('ESD,in loop : '||l_prtt_prem_corr.effective_start_date,1);
4950           ben_prtt_prem_api.update_prtt_prem
4951                 ( p_validate                => FALSE
4952                  ,p_prtt_prem_id            => l_prtt_prem_corr.prtt_prem_id
4953                  ,p_effective_start_date    => l_effective_start_date
4954                  ,p_effective_end_date      => l_effective_end_date
4955                  ,p_per_in_ler_id           => l_bkp_prem_row.per_in_ler_id
4956                  ,p_business_group_id       => l_prtt_prem_corr.business_group_id
4957                  ,p_object_version_number   => l_prtt_prem_corr.object_version_number
4958 		 ,p_prtt_enrt_rslt_id       => l_bkp_prem_row.PRTT_ENRT_RSLT_ID
4959                  ,p_request_id              => fnd_global.conc_request_id
4960                  ,p_program_application_id  => fnd_global.prog_appl_id
4961                  ,p_program_id              => fnd_global.conc_program_id
4962                  ,p_program_update_date     => sysdate
4963                  ,p_effective_date           => l_prtt_prem_corr.effective_start_date
4964                  ,p_datetrack_mode          => 'CORRECTION'
4965 
4966              );
4967 	   --delete the rows from back-up table once the record is restored
4968 	   delete from ben_le_clsn_n_rstr cls
4969 	     where  rowid = l_bkp_prem_row.rowid;
4970       end loop;
4971      end loop;
4972   -----------7133998
4973     -- we want to 'un-end' any records that were ENDED
4974     -- due to the per-in-ler.  The 'future-change' date track mode will do that
4975     -- for us.
4976     -- Others can be left alone because their FK to per-in-ler will indicate
4977     -- that they are really 'backed out'.
4978 
4979     l_prev_pk_id := -1; -- like null
4980 
4981     --
4982     open c_ben_prtt_prem_f;
4983       --
4984       loop
4985         --
4986         fetch c_ben_prtt_prem_f into l_pk_id,
4987                                           l_object_version_number;
4988         exit when c_ben_prtt_prem_f%notfound;
4989         --
4990         -- Get the maximum of effective end date for the dependents
4991         -- with past per_in_ler 's.
4992         --
4993         l_effective_date := null;
4994         open  c_ppe_max_esd_of_past_pil(l_pk_id);
4995         fetch c_ppe_max_esd_of_past_pil into l_effective_date,
4996                                              l_max_object_version_number;
4997         close c_ppe_max_esd_of_past_pil;
4998         --
4999         -- The group function "max" returns null when no records found,
5000         -- so check l_effective_date is null to find whether any
5001         -- past records were found.
5002         --
5003         --
5004         if l_effective_date is not null then
5005          --
5006          -- Do not process the row as it is already processed(deleted).
5007          --
5008          if l_prev_pk_id <> l_pk_id then
5009 
5010            -- now backup all the deleted enrollment rows
5011            --
5012            for l_deleted_ppe_rec in c_deleted_ppe(l_pk_id, l_effective_date)
5013            loop
5014               --
5015               open c_bkp_row('BEN_PRTT_PREM_F',
5016                              l_deleted_ppe_rec.per_in_ler_id,
5017                              l_deleted_ppe_rec.PRTT_PREM_ID,
5018                              l_deleted_ppe_rec.object_version_number);
5019               fetch c_bkp_row into l_row_id;
5020               --
5021               if c_bkp_row%notfound
5022               then
5023                   --
5024                   close c_bkp_row;
5025                   --
5026                   insert into BEN_LE_CLSN_N_RSTR (
5027                       BKUP_TBL_TYP_CD,
5028                       LCR_ATTRIBUTE6,
5029                       LCR_ATTRIBUTE7,
5030                       LCR_ATTRIBUTE8,
5031                       LCR_ATTRIBUTE9,
5032                       LCR_ATTRIBUTE10,
5033                       LCR_ATTRIBUTE11,
5034                       LCR_ATTRIBUTE12,
5035                       LCR_ATTRIBUTE13,
5036                       LCR_ATTRIBUTE14,
5037                       LCR_ATTRIBUTE15,
5038                       LCR_ATTRIBUTE16,
5039                       LCR_ATTRIBUTE17,
5040                       LCR_ATTRIBUTE18,
5041                       LCR_ATTRIBUTE19,
5042                       LCR_ATTRIBUTE20,
5043                       LCR_ATTRIBUTE21,
5044                       LCR_ATTRIBUTE22,
5045                       LCR_ATTRIBUTE23,
5046                       LCR_ATTRIBUTE24,
5047                       LCR_ATTRIBUTE25,
5048                       LCR_ATTRIBUTE26,
5049                       LCR_ATTRIBUTE27,
5050                       LCR_ATTRIBUTE28,
5051                       LCR_ATTRIBUTE29,
5052                       LCR_ATTRIBUTE30,
5053                       LAST_UPDATE_DATE,
5054                       LAST_UPDATED_BY,
5055                       LAST_UPDATE_LOGIN,
5059                       REQUEST_ID,
5056                       CREATED_BY,
5057                       CREATION_DATE,
5058                       OBJECT_VERSION_NUMBER,
5060                       PROGRAM_APPLICATION_ID,
5061                       PROGRAM_ID,
5062                       PROGRAM_UPDATE_DATE,
5063                       PER_IN_LER_ID,
5064                       BKUP_TBL_ID, -- PRTT_PREM_ID,
5068                       STD_PREM_VAL,
5065                       EFFECTIVE_START_DATE,
5066                       EFFECTIVE_END_DATE,
5067                       STD_PREM_UOM,
5069                       ACTL_PREM_ID,
5070                       PRTT_ENRT_RSLT_ID,
5071                       BUSINESS_GROUP_ID,
5072                       LCR_ATTRIBUTE_CATEGORY,
5073                       LCR_ATTRIBUTE1,
5074                       LCR_ATTRIBUTE2,
5075                       LCR_ATTRIBUTE3,
5076                       LCR_ATTRIBUTE4,
5077                       LCR_ATTRIBUTE5
5078                       )
5079                   values (
5080                       'BEN_PRTT_PREM_F',
5081                      l_deleted_ppe_rec.PPE_ATTRIBUTE6,
5082                      l_deleted_ppe_rec.PPE_ATTRIBUTE7,
5083                      l_deleted_ppe_rec.PPE_ATTRIBUTE8,
5084                      l_deleted_ppe_rec.PPE_ATTRIBUTE9,
5085                      l_deleted_ppe_rec.PPE_ATTRIBUTE10,
5086                      l_deleted_ppe_rec.PPE_ATTRIBUTE11,
5087                      l_deleted_ppe_rec.PPE_ATTRIBUTE12,
5088                      l_deleted_ppe_rec.PPE_ATTRIBUTE13,
5089                      l_deleted_ppe_rec.PPE_ATTRIBUTE14,
5090                      l_deleted_ppe_rec.PPE_ATTRIBUTE15,
5091                      l_deleted_ppe_rec.PPE_ATTRIBUTE16,
5092                      l_deleted_ppe_rec.PPE_ATTRIBUTE17,
5093                      l_deleted_ppe_rec.PPE_ATTRIBUTE18,
5094                      l_deleted_ppe_rec.PPE_ATTRIBUTE19,
5095                      l_deleted_ppe_rec.PPE_ATTRIBUTE20,
5096                      l_deleted_ppe_rec.PPE_ATTRIBUTE21,
5097                      l_deleted_ppe_rec.PPE_ATTRIBUTE22,
5098                      l_deleted_ppe_rec.PPE_ATTRIBUTE23,
5099                      l_deleted_ppe_rec.PPE_ATTRIBUTE24,
5100                      l_deleted_ppe_rec.PPE_ATTRIBUTE25,
5101                      l_deleted_ppe_rec.PPE_ATTRIBUTE26,
5102                      l_deleted_ppe_rec.PPE_ATTRIBUTE27,
5103                      l_deleted_ppe_rec.PPE_ATTRIBUTE28,
5104                      l_deleted_ppe_rec.PPE_ATTRIBUTE29,
5105                      l_deleted_ppe_rec.PPE_ATTRIBUTE30,
5106                      l_deleted_ppe_rec.LAST_UPDATE_DATE,
5107                      l_deleted_ppe_rec.LAST_UPDATED_BY,
5108                      l_deleted_ppe_rec.LAST_UPDATE_LOGIN,
5109                      l_deleted_ppe_rec.CREATED_BY,
5110                      l_deleted_ppe_rec.CREATION_DATE,
5111                      l_deleted_ppe_rec.OBJECT_VERSION_NUMBER,
5112                      l_deleted_ppe_rec.REQUEST_ID,
5113                      l_deleted_ppe_rec.PROGRAM_APPLICATION_ID,
5114                      l_deleted_ppe_rec.PROGRAM_ID,
5115                      l_deleted_ppe_rec.PROGRAM_UPDATE_DATE,
5116                      l_deleted_ppe_rec.PER_IN_LER_ID,
5117                      l_deleted_ppe_rec.PRTT_PREM_ID,
5118                      l_deleted_ppe_rec.EFFECTIVE_START_DATE,
5119                      l_deleted_ppe_rec.EFFECTIVE_END_DATE,
5120                      l_deleted_ppe_rec.STD_PREM_UOM,
5121                      l_deleted_ppe_rec.STD_PREM_VAL,
5122                      l_deleted_ppe_rec.ACTL_PREM_ID,
5123                      l_deleted_ppe_rec.PRTT_ENRT_RSLT_ID,
5124                      l_deleted_ppe_rec.BUSINESS_GROUP_ID,
5125                      l_deleted_ppe_rec.PPE_ATTRIBUTE_CATEGORY,
5126                      l_deleted_ppe_rec.PPE_ATTRIBUTE1,
5127                      l_deleted_ppe_rec.PPE_ATTRIBUTE2,
5128                      l_deleted_ppe_rec.PPE_ATTRIBUTE3,
5129                      l_deleted_ppe_rec.PPE_ATTRIBUTE4,
5130                      l_deleted_ppe_rec.PPE_ATTRIBUTE5
5131                   );
5132                   --
5133               else
5134                   --
5135                   close c_bkp_row;
5136                   --
5137                   update BEN_LE_CLSN_N_RSTR set
5138                       -- BKUP_TBL_TYP_CD,
5139                       LCR_ATTRIBUTE6         = l_deleted_ppe_rec.PPE_ATTRIBUTE6,
5140                       LCR_ATTRIBUTE7         = l_deleted_ppe_rec.PPE_ATTRIBUTE7,
5141                       LCR_ATTRIBUTE8         = l_deleted_ppe_rec.PPE_ATTRIBUTE8,
5142                       LCR_ATTRIBUTE9         = l_deleted_ppe_rec.PPE_ATTRIBUTE9,
5143                       LCR_ATTRIBUTE10         = l_deleted_ppe_rec.PPE_ATTRIBUTE10,
5144                       LCR_ATTRIBUTE11         = l_deleted_ppe_rec.PPE_ATTRIBUTE11,
5145                       LCR_ATTRIBUTE12         = l_deleted_ppe_rec.PPE_ATTRIBUTE12,
5146                       LCR_ATTRIBUTE13         = l_deleted_ppe_rec.PPE_ATTRIBUTE13,
5150                       LCR_ATTRIBUTE17         = l_deleted_ppe_rec.PPE_ATTRIBUTE17,
5147                       LCR_ATTRIBUTE14         = l_deleted_ppe_rec.PPE_ATTRIBUTE14,
5148                       LCR_ATTRIBUTE15         = l_deleted_ppe_rec.PPE_ATTRIBUTE15,
5149                       LCR_ATTRIBUTE16         = l_deleted_ppe_rec.PPE_ATTRIBUTE16,
5151                       LCR_ATTRIBUTE18         = l_deleted_ppe_rec.PPE_ATTRIBUTE18,
5152                       LCR_ATTRIBUTE19         = l_deleted_ppe_rec.PPE_ATTRIBUTE19,
5153                       LCR_ATTRIBUTE20         = l_deleted_ppe_rec.PPE_ATTRIBUTE20,
5154                       LCR_ATTRIBUTE21         = l_deleted_ppe_rec.PPE_ATTRIBUTE21,
5155                       LCR_ATTRIBUTE22         = l_deleted_ppe_rec.PPE_ATTRIBUTE22,
5156                       LCR_ATTRIBUTE23         = l_deleted_ppe_rec.PPE_ATTRIBUTE23,
5157                       LCR_ATTRIBUTE24         = l_deleted_ppe_rec.PPE_ATTRIBUTE24,
5158                       LCR_ATTRIBUTE25         = l_deleted_ppe_rec.PPE_ATTRIBUTE25,
5159                       LCR_ATTRIBUTE26         = l_deleted_ppe_rec.PPE_ATTRIBUTE26,
5160                       LCR_ATTRIBUTE27         = l_deleted_ppe_rec.PPE_ATTRIBUTE27,
5161                       LCR_ATTRIBUTE28         = l_deleted_ppe_rec.PPE_ATTRIBUTE28,
5162                       LCR_ATTRIBUTE29         = l_deleted_ppe_rec.PPE_ATTRIBUTE29,
5163                       LCR_ATTRIBUTE30         = l_deleted_ppe_rec.PPE_ATTRIBUTE30,
5164                       LAST_UPDATE_DATE        =l_deleted_ppe_rec.LAST_UPDATE_DATE,
5165                       LAST_UPDATED_BY         =l_deleted_ppe_rec.LAST_UPDATED_BY,
5166                       LAST_UPDATE_LOGIN       =l_deleted_ppe_rec.LAST_UPDATE_LOGIN,
5167                       CREATED_BY              =l_deleted_ppe_rec.CREATED_BY,
5168                       CREATION_DATE           =l_deleted_ppe_rec.CREATION_DATE,
5169                       -- OBJECT_VERSION_NUMBER   =l_deleted_ppe_rec.OBJECT_VERSION_NUMBER,
5170                       REQUEST_ID              =l_deleted_ppe_rec.REQUEST_ID,
5171                       PROGRAM_APPLICATION_ID  =l_deleted_ppe_rec.PROGRAM_APPLICATION_ID,
5172                       PROGRAM_ID              =l_deleted_ppe_rec.PROGRAM_ID,
5173                       PROGRAM_UPDATE_DATE     =l_deleted_ppe_rec.PROGRAM_UPDATE_DATE,
5174                       -- PER_IN_LER_ID           =l_deleted_ppe_rec.PER_IN_LER_ID,
5175                       -- BKUP_TBL_ID, -- PRTT_PREM_ID,
5179                       STD_PREM_VAL            =l_deleted_ppe_rec.STD_PREM_VAL,
5176                       EFFECTIVE_START_DATE    =l_deleted_ppe_rec.EFFECTIVE_START_DATE,
5177                       EFFECTIVE_END_DATE      =l_deleted_ppe_rec.EFFECTIVE_END_DATE,
5178                       STD_PREM_UOM            =l_deleted_ppe_rec.STD_PREM_UOM,
5180                       ACTL_PREM_ID            =l_deleted_ppe_rec.ACTL_PREM_ID,
5181                       PRTT_ENRT_RSLT_ID       =l_deleted_ppe_rec.PRTT_ENRT_RSLT_ID,
5182                       BUSINESS_GROUP_ID       =l_deleted_ppe_rec.BUSINESS_GROUP_ID,
5183                       LCR_ATTRIBUTE_CATEGORY  =l_deleted_ppe_rec.PPE_ATTRIBUTE_CATEGORY,
5184                       LCR_ATTRIBUTE1          =l_deleted_ppe_rec.PPE_ATTRIBUTE1,
5185                       LCR_ATTRIBUTE2          =l_deleted_ppe_rec.PPE_ATTRIBUTE2,
5186                       LCR_ATTRIBUTE3          =l_deleted_ppe_rec.PPE_ATTRIBUTE3,
5187                       LCR_ATTRIBUTE4          =l_deleted_ppe_rec.PPE_ATTRIBUTE4,
5188                       LCR_ATTRIBUTE5          = l_deleted_ppe_rec.PPE_ATTRIBUTE5
5189                    where rowid = l_row_id;
5190               end if;
5191            end loop;
5192            --
5193            -- Past records exist. So datetrack mode FUTURE_CHANGE.
5194            --
5195            l_datetrack_mode := hr_api.g_future_change;
5196            l_object_version_number := l_max_object_version_number;
5197           --
5198           -- Delete from the appropriate API.
5199           --
5200           if l_effective_date <> hr_api.g_eot  and nvl(p_copy_only,'N') <>  'Y'  then
5201             ben_prtt_prem_api.delete_prtt_prem
5202               (p_validate                => false,
5203                p_prtt_prem_id       => l_pk_id,
5204                p_effective_start_date    => l_effective_start_date,
5205                p_effective_end_date      => l_effective_end_date,
5206                p_object_version_number   => l_object_version_number,
5207                p_effective_date          => l_effective_date,
5208                p_datetrack_mode          => l_datetrack_mode);
5209           end if;
5210           --
5211           l_prev_pk_id := l_pk_id;
5212           --
5213 
5214          end if; -- l_prev_pk_id <> l_pk_id
5215 
5216         end if;
5217         --
5218       end loop;
5219       --
5220       l_prev_pk_id := -1;
5221       --
5222 
5223     close c_ben_prtt_prem_f;
5224     --
5225   elsif p_routine = 'BEN_PL_BNF_F' then
5226 
5227 
5228     -- For beneficiaries, we want to 'un-end' any bnf records that were ENDED
5229     -- due to the per-in-ler.  The 'future-change' date track mode will do that
5230     -- for us.
5231     -- Other bnfs can be left alone because their FK to per-in-ler
5232     -- will indicate that they are really 'backed out'.
5233 
5234     l_prev_pk_id := -1; -- like null
5235 
5236     open c_ben_pl_bnf_f;
5237 
5238       loop
5239 
5240         fetch c_ben_pl_bnf_f into l_pk_id,
5241                                   l_object_version_number,
5242 																	l_bnf_effective_start_date;
5246         -- with past per_in_ler 's.
5243         exit when c_ben_pl_bnf_f%notfound;
5244         --
5245         -- Get the maximum of effective end date for the beneficiary
5247         --
5248         l_effective_date := null;
5249         open  c_pbn_max_esd_of_past_pil(l_pk_id);
5250         fetch c_pbn_max_esd_of_past_pil into l_effective_date,
5251                                              l_max_object_version_number;
5252         close c_pbn_max_esd_of_past_pil;
5253         --
5254         -- The group function "max" returns null when no records found,
5255         -- so check l_effective_date is null to find whether any
5256         -- past records were found.
5257         --
5258         --
5259         if l_effective_date is not null then
5260          --
5261          -- Do not process the row as it is already processed(deleted).
5262          --
5263          if l_prev_pk_id <> l_pk_id then
5264 
5265            -- now backup all the deleted pbn rows
5266            --
5267            for l_deleted_pbn_rec in c_deleted_pbn(l_pk_id, l_effective_date)
5268            loop
5269               --
5270               --
5271               open c_bkp_row('BEN_PL_BNF_F',
5272                              l_deleted_pbn_rec.per_in_ler_id,
5273                              l_deleted_pbn_rec.PL_BNF_ID,
5274                              l_deleted_pbn_rec.object_version_number);
5275               fetch c_bkp_row into l_row_id;
5276               --
5277               if c_bkp_row%notfound
5278               then
5279                  --
5280                  close c_bkp_row;
5281                  --
5282                  insert into BEN_LE_CLSN_N_RSTR (
5283                   BKUP_TBL_TYP_CD,
5284                   LCR_ATTRIBUTE1,
5285                   LCR_ATTRIBUTE2,
5286                   LCR_ATTRIBUTE3,
5287                   LCR_ATTRIBUTE4,
5288                   LCR_ATTRIBUTE5,
5289                   LCR_ATTRIBUTE6,
5290                   LCR_ATTRIBUTE7,
5291                   LCR_ATTRIBUTE8,
5292                   LCR_ATTRIBUTE9,
5293                   LCR_ATTRIBUTE10,
5294                   LCR_ATTRIBUTE11,
5295                   LCR_ATTRIBUTE12,
5296                   LCR_ATTRIBUTE13,
5297                   LCR_ATTRIBUTE14,
5298                   LCR_ATTRIBUTE15,
5299                   LCR_ATTRIBUTE16,
5300                   LCR_ATTRIBUTE17,
5301                   LCR_ATTRIBUTE18,
5302                   LCR_ATTRIBUTE19,
5303                   LCR_ATTRIBUTE20,
5304                   LCR_ATTRIBUTE21,
5305                   LCR_ATTRIBUTE22,
5306                   LCR_ATTRIBUTE23,
5307                   LCR_ATTRIBUTE24,
5308                   LCR_ATTRIBUTE25,
5309                   LCR_ATTRIBUTE26,
5310                   LCR_ATTRIBUTE27,
5311                   LCR_ATTRIBUTE28,
5312                   LCR_ATTRIBUTE29,
5313                   LCR_ATTRIBUTE30,
5314                   LAST_UPDATE_DATE,
5315                   LAST_UPDATED_BY,
5316                   LAST_UPDATE_LOGIN,
5317                   CREATED_BY,
5318                   CREATION_DATE,
5319                   REQUEST_ID,
5320                   PROGRAM_APPLICATION_ID,
5321                   PROGRAM_ID,
5322                   PROGRAM_UPDATE_DATE,
5323                   OBJECT_VERSION_NUMBER,
5324                   BKUP_TBL_ID, -- PL_BNF_ID,
5325                   EFFECTIVE_START_DATE,
5326                   EFFECTIVE_END_DATE,
5327                   PRMRY_CNTNGNT_CD,
5328                   PCT_DSGD_NUM,
5329                   AMT_DSGD_VAL,
5330                   AMT_DSGD_UOM,
5331                   ADDL_INSTRN_TXT,
5332                   DSGN_THRU_DT,
5333                   DSGN_STRT_DT,
5334                   PRTT_ENRT_RSLT_ID,
5335                   ORGANIZATION_ID,
5336                   BNF_PERSON_ID,
5337                   PERSON_TTEE_ID,  -- TTEE_PERSON_ID,
5338                   BUSINESS_GROUP_ID,
5339                   PER_IN_LER_ID,
5340                   LCR_ATTRIBUTE_CATEGORY )
5341              values (
5342                  'BEN_PL_BNF_F',
5343                  l_deleted_pbn_rec.PBN_ATTRIBUTE1,
5344                  l_deleted_pbn_rec.PBN_ATTRIBUTE2,
5345                  l_deleted_pbn_rec.PBN_ATTRIBUTE3,
5346                  l_deleted_pbn_rec.PBN_ATTRIBUTE4,
5347                  l_deleted_pbn_rec.PBN_ATTRIBUTE5,
5348                  l_deleted_pbn_rec.PBN_ATTRIBUTE6,
5349                  l_deleted_pbn_rec.PBN_ATTRIBUTE7,
5350                  l_deleted_pbn_rec.PBN_ATTRIBUTE8,
5351                  l_deleted_pbn_rec.PBN_ATTRIBUTE9,
5352                  l_deleted_pbn_rec.PBN_ATTRIBUTE10,
5353                  l_deleted_pbn_rec.PBN_ATTRIBUTE11,
5354                  l_deleted_pbn_rec.PBN_ATTRIBUTE12,
5355                  l_deleted_pbn_rec.PBN_ATTRIBUTE13,
5356                  l_deleted_pbn_rec.PBN_ATTRIBUTE14,
5357                  l_deleted_pbn_rec.PBN_ATTRIBUTE15,
5358                  l_deleted_pbn_rec.PBN_ATTRIBUTE16,
5359                  l_deleted_pbn_rec.PBN_ATTRIBUTE17,
5360                  l_deleted_pbn_rec.PBN_ATTRIBUTE18,
5361                  l_deleted_pbn_rec.PBN_ATTRIBUTE19,
5362                  l_deleted_pbn_rec.PBN_ATTRIBUTE20,
5363                  l_deleted_pbn_rec.PBN_ATTRIBUTE21,
5364                  l_deleted_pbn_rec.PBN_ATTRIBUTE22,
5365                  l_deleted_pbn_rec.PBN_ATTRIBUTE23,
5366                  l_deleted_pbn_rec.PBN_ATTRIBUTE24,
5367                  l_deleted_pbn_rec.PBN_ATTRIBUTE25,
5368                  l_deleted_pbn_rec.PBN_ATTRIBUTE26,
5369                  l_deleted_pbn_rec.PBN_ATTRIBUTE27,
5370                  l_deleted_pbn_rec.PBN_ATTRIBUTE28,
5371                  l_deleted_pbn_rec.PBN_ATTRIBUTE29,
5372                  l_deleted_pbn_rec.PBN_ATTRIBUTE30,
5373                  l_deleted_pbn_rec.LAST_UPDATE_DATE,
5374                  l_deleted_pbn_rec.LAST_UPDATED_BY,
5378                  l_deleted_pbn_rec.REQUEST_ID,
5375                  l_deleted_pbn_rec.LAST_UPDATE_LOGIN,
5376                  l_deleted_pbn_rec.CREATED_BY,
5377                  l_deleted_pbn_rec.CREATION_DATE,
5379                  l_deleted_pbn_rec.PROGRAM_APPLICATION_ID,
5380                  l_deleted_pbn_rec.PROGRAM_ID,
5381                  l_deleted_pbn_rec.PROGRAM_UPDATE_DATE,
5382                  l_deleted_pbn_rec.OBJECT_VERSION_NUMBER,
5383                  l_deleted_pbn_rec.PL_BNF_ID,
5384                  l_deleted_pbn_rec.EFFECTIVE_START_DATE,
5385                  l_deleted_pbn_rec.EFFECTIVE_END_DATE,
5386                  l_deleted_pbn_rec.PRMRY_CNTNGNT_CD,
5387                  l_deleted_pbn_rec.PCT_DSGD_NUM,
5388                  l_deleted_pbn_rec.AMT_DSGD_VAL,
5389                  l_deleted_pbn_rec.AMT_DSGD_UOM,
5390                  l_deleted_pbn_rec.ADDL_INSTRN_TXT,
5391                  l_deleted_pbn_rec.DSGN_THRU_DT,
5392                  l_deleted_pbn_rec.DSGN_STRT_DT,
5393                  l_deleted_pbn_rec.PRTT_ENRT_RSLT_ID,
5394                  l_deleted_pbn_rec.ORGANIZATION_ID,
5395                  l_deleted_pbn_rec.BNF_PERSON_ID,
5396                  l_deleted_pbn_rec.TTEE_PERSON_ID,
5397                  l_deleted_pbn_rec.BUSINESS_GROUP_ID,
5398                  l_deleted_pbn_rec.PER_IN_LER_ID,
5399                  l_deleted_pbn_rec.PBN_ATTRIBUTE_CATEGORY
5400               );
5401               --
5402             else
5403               --
5404               close c_bkp_row;
5405               --
5406               update BEN_LE_CLSN_N_RSTR set
5407                   LCR_ATTRIBUTE1         = l_deleted_pbn_rec.PBN_ATTRIBUTE1,
5408                   LCR_ATTRIBUTE2         = l_deleted_pbn_rec.PBN_ATTRIBUTE2,
5409                   LCR_ATTRIBUTE3         = l_deleted_pbn_rec.PBN_ATTRIBUTE3,
5410                   LCR_ATTRIBUTE4         = l_deleted_pbn_rec.PBN_ATTRIBUTE4,
5411                   LCR_ATTRIBUTE5         = l_deleted_pbn_rec.PBN_ATTRIBUTE5,
5412                   LCR_ATTRIBUTE6         = l_deleted_pbn_rec.PBN_ATTRIBUTE6,
5413                   LCR_ATTRIBUTE7         = l_deleted_pbn_rec.PBN_ATTRIBUTE7,
5414                   LCR_ATTRIBUTE8         = l_deleted_pbn_rec.PBN_ATTRIBUTE8,
5415                   LCR_ATTRIBUTE9         = l_deleted_pbn_rec.PBN_ATTRIBUTE9,
5416                   LCR_ATTRIBUTE10        = l_deleted_pbn_rec.PBN_ATTRIBUTE10,
5417                   LCR_ATTRIBUTE11        = l_deleted_pbn_rec.PBN_ATTRIBUTE11,
5418                   LCR_ATTRIBUTE12        = l_deleted_pbn_rec.PBN_ATTRIBUTE12,
5419                   LCR_ATTRIBUTE13        = l_deleted_pbn_rec.PBN_ATTRIBUTE13,
5420                   LCR_ATTRIBUTE14        = l_deleted_pbn_rec.PBN_ATTRIBUTE14,
5421                   LCR_ATTRIBUTE15        = l_deleted_pbn_rec.PBN_ATTRIBUTE15,
5422                   LCR_ATTRIBUTE16        = l_deleted_pbn_rec.PBN_ATTRIBUTE16,
5423                   LCR_ATTRIBUTE17        = l_deleted_pbn_rec.PBN_ATTRIBUTE17,
5424                   LCR_ATTRIBUTE18        = l_deleted_pbn_rec.PBN_ATTRIBUTE18,
5425                   LCR_ATTRIBUTE19        = l_deleted_pbn_rec.PBN_ATTRIBUTE19,
5426                   LCR_ATTRIBUTE20        = l_deleted_pbn_rec.PBN_ATTRIBUTE20,
5427                   LCR_ATTRIBUTE21        = l_deleted_pbn_rec.PBN_ATTRIBUTE21,
5428                   LCR_ATTRIBUTE22        = l_deleted_pbn_rec.PBN_ATTRIBUTE22,
5429                   LCR_ATTRIBUTE23        = l_deleted_pbn_rec.PBN_ATTRIBUTE23,
5430                   LCR_ATTRIBUTE24        = l_deleted_pbn_rec.PBN_ATTRIBUTE24,
5431                   LCR_ATTRIBUTE25        = l_deleted_pbn_rec.PBN_ATTRIBUTE25,
5432                   LCR_ATTRIBUTE26        = l_deleted_pbn_rec.PBN_ATTRIBUTE26,
5433                   LCR_ATTRIBUTE27        = l_deleted_pbn_rec.PBN_ATTRIBUTE27,
5434                   LCR_ATTRIBUTE28        = l_deleted_pbn_rec.PBN_ATTRIBUTE28,
5435                   LCR_ATTRIBUTE29        = l_deleted_pbn_rec.PBN_ATTRIBUTE29,
5436                   LCR_ATTRIBUTE30        = l_deleted_pbn_rec.PBN_ATTRIBUTE30,
5437                   LAST_UPDATE_DATE       = l_deleted_pbn_rec.LAST_UPDATE_DATE,
5438                   LAST_UPDATED_BY        = l_deleted_pbn_rec.LAST_UPDATED_BY,
5439                   LAST_UPDATE_LOGIN      = l_deleted_pbn_rec.LAST_UPDATE_LOGIN,
5440                   CREATED_BY             = l_deleted_pbn_rec.CREATED_BY,
5441                   CREATION_DATE          = l_deleted_pbn_rec.CREATION_DATE,
5442                   REQUEST_ID             = l_deleted_pbn_rec.REQUEST_ID,
5443                   PROGRAM_APPLICATION_ID = l_deleted_pbn_rec.PROGRAM_APPLICATION_ID,
5444                   PROGRAM_ID             = l_deleted_pbn_rec.PROGRAM_ID,
5445                   PROGRAM_UPDATE_DATE    = l_deleted_pbn_rec.PROGRAM_UPDATE_DATE,
5446                   -- OBJECT_VERSION_NUMBER  = l_deleted_pbn_rec.OBJECT_VERSION_NUMBER,
5447                   -- BKUP_TBL_ID         = l_deleted_pbn_rec.PL_BNF_ID,
5448                   EFFECTIVE_START_DATE   = l_deleted_pbn_rec.EFFECTIVE_START_DATE,
5449                   EFFECTIVE_END_DATE     = l_deleted_pbn_rec.EFFECTIVE_END_DATE,
5450                   PRMRY_CNTNGNT_CD       = l_deleted_pbn_rec.PRMRY_CNTNGNT_CD,
5451                   PCT_DSGD_NUM           = l_deleted_pbn_rec.PCT_DSGD_NUM,
5452                   AMT_DSGD_VAL           = l_deleted_pbn_rec.AMT_DSGD_VAL,
5453                   AMT_DSGD_UOM           = l_deleted_pbn_rec.AMT_DSGD_UOM,
5454                   ADDL_INSTRN_TXT        = l_deleted_pbn_rec.ADDL_INSTRN_TXT,
5455                   DSGN_THRU_DT           = l_deleted_pbn_rec.DSGN_THRU_DT,
5456                   DSGN_STRT_DT           = l_deleted_pbn_rec.DSGN_STRT_DT,
5457                   PRTT_ENRT_RSLT_ID      = l_deleted_pbn_rec.PRTT_ENRT_RSLT_ID,
5458                   ORGANIZATION_ID        = l_deleted_pbn_rec.ORGANIZATION_ID,
5459                   BNF_PERSON_ID          = l_deleted_pbn_rec.BNF_PERSON_ID,
5460                   PERSON_TTEE_ID         = l_deleted_pbn_rec.TTEE_PERSON_ID,
5461                   BUSINESS_GROUP_ID      = l_deleted_pbn_rec.BUSINESS_GROUP_ID,
5462                   --PER_IN_LER_ID          = l_deleted_pbn_rec.PER_IN_LER_ID,
5466            end loop;
5463                   LCR_ATTRIBUTE_CATEGORY = l_deleted_pbn_rec.PBN_ATTRIBUTE_CATEGORY
5464                where rowid = l_row_id;
5465             end if;
5467            --
5468            -- Past records exist. So datetrack mode FUTURE_CHANGE.
5469            --
5470            l_datetrack_mode := hr_api.g_future_change;
5471            l_object_version_number := l_max_object_version_number;
5472           --
5473           -- Delete from the appropriate API.
5474           --
5475           if l_effective_date <> hr_api.g_eot  and nvl(p_copy_only,'N') <>  'Y'  then
5476             ben_plan_beneficiary_api.delete_plan_beneficiary
5477               (p_validate                => false,
5478                p_pl_bnf_id               => l_pk_id,
5479                p_effective_start_date    => l_effective_start_date,
5480                p_effective_end_date      => l_effective_end_date,
5481                p_object_version_number   => l_object_version_number,
5482                p_business_group_id       => p_business_group_id,
5483                p_effective_date          => l_effective_date,
5484                p_datetrack_mode          => l_datetrack_mode,
5485                p_multi_row_actn          => FALSE);  -- 2552295
5486           end if;
5487           --
5488           l_prev_pk_id := l_pk_id;
5489           --
5490          end if; -- l_prev_pk_id <> l_pk_id
5491 				else
5492 				 -- -- bug 5668052
5493 				 hr_utility.set_location('effective date null  ' ,12.12);
5494 				 			BEN_PLAN_BENEFICIARY_API.remove_usage (
5495 										 p_validate          => FALSE
5496 										,p_pl_bnf_id         => l_pk_id
5497 										,p_effective_date    => l_bnf_effective_start_date
5498 										,p_datetrack_mode    => hr_api.g_zap
5499 										,p_business_group_id => p_business_group_id
5500 										,p_dsgn_thru_dt      => NULL);
5501 
5502 
5503         end if;
5504       end loop;
5505 
5506 
5507      --
5508      -- if any of the result in corrected and stored in backp table for corrn
5509      -- correct the per_in_ler_id of related the dpnt table too bug # 3086161
5510 
5511       for i in c_BEN_LE_CLSN_N_RSTR_pbn(p_per_in_ler_id )
5512       Loop
5513                l_object_version_number := i.object_version_number ;
5514                ben_plan_beneficiary_api.update_plan_beneficiary
5515                   (p_validate                => FALSE
5516                   ,p_business_group_id       => p_business_group_id
5517                   ,p_pl_bnf_id               => i.pl_bnf_id
5518                   ,p_effective_start_date    => l_effective_start_date
5519                   ,p_effective_end_date      => l_effective_end_date
5520                   ,p_dsgn_thru_dt            => i.enrt_cvg_thru_dt
5521                   ,p_per_in_ler_id           => i.per_in_ler_id
5522                   ,p_object_version_number   => l_object_version_number
5523                   ,p_effective_date          => i.effective_start_date
5524                   ,p_datetrack_mode          => hr_api.g_correction
5525                   ,p_multi_row_actn          => FALSE);
5526 
5527       end loop ;
5528 
5529 
5530       --
5531       l_prev_pk_id := -1;
5532       --
5533 
5534     close c_ben_pl_bnf_f;
5535   elsif p_routine = 'BEN_PRMRY_CARE_PRVDR_F' then
5536     --
5537     l_prev_pk_id := -1; -- like null
5538     --
5539     /* Why are we deleting these records. Bug 3709516
5540     --
5541     open c_ben_prmry_care_prvdr_f;
5542       --
5543       loop
5544         --
5545         fetch c_ben_prmry_care_prvdr_f into l_pk_id,l_effective_date,
5546                                             l_object_version_number;
5547         exit when c_ben_prmry_care_prvdr_f%notfound;
5548         --
5549         -- Do not process the row as it is already processed(deleted).
5550         --
5551         if l_prev_pk_id <> l_pk_id  and nvl(p_copy_only,'N') <>  'Y'  then
5552 
5553            --
5554            -- Delete from the appropriate API.
5555            --
5556            ben_prmry_care_prvdr_api.delete_prmry_care_prvdr
5557              (p_validate                => false,
5558               p_prmry_care_prvdr_id     => l_pk_id,
5559               p_effective_start_date    => l_effective_start_date,
5560               p_effective_end_date      => l_effective_end_date,
5561               p_object_version_number   => l_object_version_number,
5562               p_effective_date          => l_effective_date,
5563               p_datetrack_mode          => 'ZAP');
5564            --
5565            l_prev_pk_id := l_pk_id;
5566            --
5567         end if; -- l_prev_pk_id <> l_pk_id
5568       --
5569       end loop;
5570       --
5571       l_prev_pk_id := -1;
5572       --
5573     close c_ben_prmry_care_prvdr_f;
5574     */
5575 
5576   elsif p_routine = 'BEN_PRTT_REIMBMT_RQST' then
5577      open c_prc ;
5578      --
5579      -- bug 2518955 - added exception handling for showing customized message
5580      -- for specific case of presence of Approved claims preventing back-out of LE
5581      --
5582      -- enclosed the loop with a begin - exception - end block and check for
5583      -- BEN_92705_REIMB_RQST_APPROVD message in exception and show the message
5584      -- BEN_93185_APRVD_CLM_NO_BCKOUT instead of that.
5585      declare
5586        l_msg_name  varchar2(80);
5587        l_err_num   number;
5588      begin
5589        loop
5590           fetch c_prc into l_prc_rec ;
5591           exit when c_prc%notfound ;
5592           hr_utility.set_location('calling date ' || p_effective_date , 293);
5593           hr_utility.set_location('calling id  ' || l_prc_rec.PRTT_REIMBMT_RQST_ID , 293);
5594 
5595           BEN_prtt_reimbmt_rqst_API.delete_prtt_reimbmt_rqst
5596                                   (p_validate => FALSE
5600                                   ,p_OBJECT_VERSION_NUMBER=> l_prc_rec.OBJECT_VERSION_NUMBER
5597                                   ,p_PRTT_REIMBMT_RQST_ID => l_prc_rec.PRTT_REIMBMT_RQST_ID
5598                                   ,p_EFFECTIVE_START_DATE => l_effective_start_date
5599                                   ,p_EFFECTIVE_END_DATE   => l_effective_end_date
5601                                   ,p_effective_date       => l_prc_rec.effective_start_date
5602                                   ,p_datetrack_mode       => 'ZAP'
5603                                   ,p_SUBMITTER_PERSON_ID  => l_prc_rec.person_id );
5604 
5605        end loop ;
5606        --
5607      exception
5608        --
5609        when OTHERS then  -- exception number raised when FND_MESSAGE.raise_error is called
5610          --
5611          l_err_num := SQLCODE ;
5612          --
5613          if l_err_num = -20001 then
5614            --
5615            l_msg_name := get_msg_name();
5616 
5617            if l_msg_name = 'BEN_92705_REIMB_RQST_APPROVD' then
5618              --
5619              -- set our own message name and raise the exception again
5620              --
5621              fnd_message.set_name('BEN', 'BEN_93188_APRVD_CLM_NO_BCKOUT');
5622              fnd_message.raise_error;
5623              --
5624            else
5625              --
5626              fnd_message.raise_error;
5627              --
5628            end if;
5629            --
5630          end if;
5631          --
5632      end;
5633      --
5634      -- end fix 2518955
5635      --
5636      close c_prc;
5637 
5638     --
5639   elsif p_routine = 'BEN_PRTT_RT_VAL' then
5640 
5641     -- Rates need to be marked 'backed out' if they were created due to this per-in-ler.
5642     -- the first loop does that.
5643     -- The second loop handles 'un-ending' rates that were ended due to this per-in-ler.
5644 
5645     -- -- bug 4615207 : added GHR product installation chk -Multiple Rate chk to be performed only for GHR
5646 
5647    IF (fnd_installation.get_app_info('GHR',l_status, l_industry, l_oracle_schema)) THEN
5648 
5649     if l_status = 'I' then
5650     hr_utility.set_location('FOUND GHR',9909);
5651     open c_multiple_rate;
5652     fetch c_multiple_rate into l_multiple_rate;
5653     if c_multiple_rate%found then
5654       --
5655       hr_utility.set_location('Multiple rate',111);
5656       insert into BEN_LE_CLSN_N_RSTR (
5657                     BKUP_TBL_TYP_CD,
5658                     BKUP_TBL_ID,
5659                     per_in_ler_id,
5660                     business_group_id,
5661                     object_version_number)
5662                   values (
5663                     'MULTIPLE_RATE',
5664                     9999999999,
5665                     p_per_in_ler_id,
5666                     p_business_group_id,
5667                     999999999
5668                   );
5669     end if;
5670     close c_multiple_rate;
5671     end if; --if l_status
5672    end if;
5673 
5674     --
5675     open c_ben_prtt_rt_val;
5676       loop
5677         fetch c_ben_prtt_rt_val into l_pk_id,
5678                                      l_object_version_number,
5679                                      l_person_id,
5680                                      l_rt_strt_dt,
5681                                      l_acty_ref_perd_cd,
5682                                      l_prv_prtt_enrt_rslt_id,
5683                                      l_ref_obj_pk_id,
5684                                      l_ref_obj_table_name;
5685         exit when c_ben_prtt_rt_val%notfound;
5686         --
5687         -- Pbodla : Now insert the link between ben_enrt_rt and
5688         -- ben_prtt_rt_val into bacup table lcr
5689         -- as this info is lost when the prv rows are set to BCKDT status.
5690         --tilak: in case the cursor fails the previous data carried forward
5691         -- to avoid this the data is initialised
5692         l_ecr.enrt_rt_id := null ;
5693         open c_ecr(l_pk_id);
5694         fetch c_ecr into l_ecr;
5695         close c_ecr;
5696         --
5697         -- Bug 4661 : update the rate value as of the effective_start_date of
5698         -- the concerned result row.
5699         -- Consider the following scenario :
5700         -- Result row with PK id 1 - (01-jan-00 to 14-jan-00)
5701         -- Above result have one rate row attached.
5702         -- Result row with PK id 1 - (15-jan-00 to 24-jan-00)
5703         -- Above result have one rate row attached.
5704         -- Result row with PK id 1 - (25-jan-00 to EOT)
5705         -- Above result have one rate row attached.
5706         -- When Result row 1's rate row is backed out it checks
5707         -- whether the result row is suspended. So we need to pass
5708         -- result rows effective_start date to correctly identify it.
5709         --
5710         open c_prv_pen(l_prv_prtt_enrt_rslt_id, l_rt_strt_dt);
5711         fetch c_prv_pen into l_prv_pen;
5712         close c_prv_pen;
5713         --
5714         -- Bug : 4785.
5715         -- Using just l_prv_pen.effective_start_date to update
5716         -- rate value causes problem for backing out of open
5717         -- enrollment per in ler's. Result effective start date
5718         -- may be 11-nov-99, but the rate may start on 01-jan-00.
5719         -- Passing 11-nov-99 as effective date may cause no
5720         -- element entry row found problems.
5721         --
5722         hr_utility.set_location('l_prv_pen.effective_start_date'||l_prv_pen.effective_start_date,1999);
5723         hr_utility.set_location('l_rt_strt_dt'||l_rt_strt_dt,1999);
5724         if l_prv_pen.effective_start_date < l_rt_strt_dt then
5725            l_prv_effective_date := l_rt_strt_dt;
5726         else
5727            l_prv_effective_date := l_prv_pen.effective_start_date;
5728         end if;
5729         --
5733           ben_prtt_rt_val_api.update_prtt_rt_val
5730         -- Delete from the appropriate API.
5731         --
5732         if  nvl(p_copy_only,'N') <>  'Y' then
5734           (p_validate                => false,
5735            p_business_group_id       => p_business_group_id,
5736            p_prtt_rt_val_id          => l_pk_id,
5737            p_rt_end_dt               => (l_rt_strt_dt -1),
5738            p_prtt_rt_val_stat_cd     => 'BCKDT',
5739            p_acty_ref_perd_cd        => l_acty_ref_perd_cd,
5740            p_person_id               => l_person_id,
5741            p_object_version_number   => l_object_version_number,
5742            p_effective_date          => l_prv_effective_date);
5743         --
5744           if l_ref_obj_pk_id is not null and l_ref_obj_table_name = 'PER_PAY_PROPOSALS'
5745             then
5746            --
5747            l_salary_proposal_ovn := null;
5748            open c_pay_proposal(l_ref_obj_pk_id);
5749            fetch c_pay_proposal into l_salary_proposal_ovn;
5750            close c_pay_proposal;
5751            --
5752            if l_salary_proposal_ovn is not null then
5753              --
5754              -- Delete the per pay proposals.
5755              --
5756              hr_maintain_proposal_api.delete_salary_proposal(
5757                 p_pay_proposal_id       => l_ref_obj_pk_id
5758                ,p_business_group_id     => p_business_group_id
5759                ,p_object_version_number => l_salary_proposal_ovn
5760                ,p_validate              => FALSE
5761                ,p_salary_warning        => l_salary_warning);
5762              --
5763            end if;
5764            --
5765           end if;
5766 
5767         end if ;  --- p_copy only
5768         --
5769         if l_ecr.enrt_rt_id is not null  then
5770            --
5771            -- Get the object version number for the update
5772            --
5773            l_ecr.object_version_number :=
5774                         dt_api.get_object_version_number
5775                          (p_base_table_name => 'ben_enrt_rt',
5776                           p_base_key_column => 'enrt_rt_id',
5777                           p_base_key_value  => l_ecr.enrt_rt_id)-1;
5778 
5779           --
5780           open c_bkp_row('BEN_ENRT_RT',
5781                          p_per_in_ler_id,
5782                          l_ecr.enrt_rt_id,
5783                          l_ecr.object_version_number);
5784           fetch c_bkp_row into l_row_id;
5785           --
5786           if c_bkp_row%notfound
5787           then
5788             --
5789             close c_bkp_row;
5790             --
5791             insert into BEN_LE_CLSN_N_RSTR (
5792                     BKUP_TBL_TYP_CD,
5793                     BKUP_TBL_ID,
5794                     prtt_enrt_rslt_id, -- Used for prtt_rt_val_id,
5795                     per_in_ler_id,
5796                     business_group_id,
5797                     object_version_number)
5798                   values (
5799                     'BEN_ENRT_RT',
5800                     l_ecr.enrt_rt_id,
5801                     l_ecr.prtt_rt_val_id,
5802                     p_per_in_ler_id,
5803                     l_ecr.business_group_id,
5804                     l_ecr.object_version_number
5805                   );
5806            else
5807                   --
5808                   close c_bkp_row;
5809                   --
5810                  update BEN_LE_CLSN_N_RSTR set
5811                      prtt_enrt_rslt_id = l_ecr.prtt_rt_val_id,
5812                      business_group_id = l_ecr.business_group_id
5813                  where rowid = l_row_id;
5814                  --
5815            end if;
5816            --
5817         end if;
5818         --
5819       end loop;
5820 
5821     close c_ben_prtt_rt_val;
5822 
5823     /* Bug 8507247:First Adjust the rates and then open the backed out rates till EOT. This issue resolves Bug 8293106.
5824      Fix for Bug 8293106 is handled through Bug 8507247*/
5825 
5826    -- adjust the rate end for already adjusted rate
5827     open c_prtt_rt_val_adj (p_per_in_ler_id);
5828     loop
5829       fetch c_prtt_rt_val_adj into l_rt_adj;
5830       if c_prtt_rt_val_adj%found then
5831         --
5832         open c_prv_ovn (l_rt_adj.bkup_tbl_id);
5833         fetch c_prv_ovn into l_object_version_number;
5834         close c_prv_ovn;
5835         hr_utility.set_location('Ajdust rate end date'||l_rt_adj.bkup_tbl_id,10);
5836 	hr_utility.set_location('p_effective_date '||p_effective_date,10);
5837 	hr_utility.set_location('l_rt_adj'||l_rt_adj.effective_start_date,10);
5838 	hr_utility.set_location('l_object_version_number'||l_object_version_number,10);
5839         --
5840         adj_prv_rate (p_person_id  => l_rt_adj.person_id,
5841                         p_prtt_rt_val_id  => l_rt_adj.bkup_tbl_id,
5842                         p_rt_end_dt =>    l_rt_adj.RT_END_DT,
5843                         p_object_version_number => l_object_version_number,
5844                         p_business_group_id => p_business_group_id,
5845                         p_effective_date => p_effective_date);
5846         --
5847       else   --not found
5848         exit;
5849       end if;
5850     end loop;
5851     close c_prtt_rt_val_adj;
5852     /* End of Bug 8507247*/
5853 
5854     --
5855     -- Reset the rate end date for the original rates.
5856     --
5857     l_prv_bckdt := null;
5858     l_ended_per_in_ler_id := null;
5859 
5860     open  c_prv_of_previous_pil;
5861     loop
5862        fetch c_prv_of_previous_pil into l_prv_bckdt;
5863        exit when c_prv_of_previous_pil%notfound;
5864        --
5865        hr_utility.set_location('prv 0 '||l_prv_bckdt.prtt_rt_val_id,10);
5866        hr_utility.set_location('prv 1 '||l_prv_bckdt.acty_base_rt_id,10);
5870        close c_prv_pen;
5867        l_prv_pen.effective_start_date := null;
5868        open c_prv_pen(l_prv_bckdt.prtt_enrt_rslt_id, l_prv_bckdt.rt_strt_dt);
5869        fetch c_prv_pen into l_prv_pen;
5871        --update only if the result exists - bug#4206567
5872       if l_prv_pen.effective_start_date is not null then
5873        -- Update rate end date to end of time.
5874        --
5875         if  nvl(p_copy_only,'N') <>  'Y'  then
5876 
5877           l_next_prv := null;
5878           open c_next_prv;
5879           fetch c_next_prv into l_next_prv;
5880           close c_next_prv;
5881 
5882 /*
5883           if l_prev_prv_bckdt.acty_base_rt_id = l_prv_bckdt.acty_base_rt_id then
5884               l_rt_end_dt := l_prev_prv_bckdt.rt_strt_dt -1;
5885               l_ended_per_in_ler_id := l_prev_prv_bckdt.per_in_ler_id;
5886           else
5887               l_rt_end_dt := hr_api.g_eot;
5888               l_ended_per_in_ler_id := null;
5889           end if;
5890 */
5891 
5892            if l_next_prv.prtt_rt_val_id is not null then
5893               l_rt_end_dt := l_next_prv.rt_strt_dt -1;
5894               l_ended_per_in_ler_id := l_next_prv.per_in_ler_id;
5895            else
5896               l_rt_end_dt := hr_api.g_eot;
5897               l_ended_per_in_ler_id := null;
5898               --
5899               --  8896851
5900               --
5901               if l_prv_bckdt.prtt_rt_val_stat_cd is null then
5902                --
5903                --  Check if it is a correction from the prior event
5904                --
5905                open c_get_bckdt_prv(l_prv_bckdt.prtt_rt_val_id);
5906                fetch c_get_bckdt_prv into l_bckdt_prv_rec;
5907                if c_get_bckdt_prv%found then
5908                  l_rt_end_dt := l_bckdt_prv_rec.rt_end_dt;
5909                  l_ended_per_in_ler_id := l_bckdt_prv_rec.per_in_ler_ended_id;
5910                  hr_utility.set_location('l_rt_end_dt '||l_rt_end_dt,10);
5911                  hr_utility.set_location('l_ended_per_in_ler_id '||l_ended_per_in_ler_id,10);
5912                end if;
5913                close c_get_bckdt_prv;
5914               end if;
5915               --
5916               -- end 8896851
5917               --
5918            end if;
5919 
5920            ben_prtt_rt_val_api.update_prtt_rt_val
5921           (p_validate               => FALSE
5922           ,p_prtt_rt_val_id         => l_prv_bckdt.prtt_rt_val_id
5923           ,p_object_version_number  => l_prv_bckdt.object_version_number
5924           ,p_rt_end_dt              => l_rt_end_dt
5925           ,p_prtt_rt_val_stat_cd    => null
5926           ,p_ended_per_in_ler_id    => l_ended_per_in_ler_id
5927           ,p_person_id              => l_prv_bckdt.person_id
5928           ,p_business_group_id      => p_business_group_id
5929           ,p_effective_date         => l_prv_pen.effective_start_date);
5930 
5931 	  /* added 'if' condition for Bug 12576710. Adjust the rate from the backup table after rate is updated */
5932 	  if(l_prv_bckdt.adj_rec =  2 )then
5933 	         hr_utility.set_location('Ajdust rate end date'||l_prv_bckdt.prtt_rt_val_id,10);
5934 	         open c_adj_rate_curr_per_in_ler (p_per_in_ler_id,l_prv_bckdt.prtt_rt_val_id);
5935                  fetch c_adj_rate_curr_per_in_ler into l_rt_adj;
5936 		 if(c_adj_rate_curr_per_in_ler%found) then
5937 			open c_prv_ovn (l_rt_adj.bkup_tbl_id);
5938 			fetch c_prv_ovn into l_object_version_number;
5939 			close c_prv_ovn;
5940 			hr_utility.set_location('Ajdust rate end date'||l_rt_adj.bkup_tbl_id,10);
5941 			--
5942 			adj_prv_rate (p_person_id  => l_rt_adj.person_id,
5943 					p_prtt_rt_val_id  => l_rt_adj.bkup_tbl_id,
5944 					p_rt_end_dt =>    l_rt_adj.RT_END_DT,
5945 					p_object_version_number => l_object_version_number,
5946 					p_business_group_id => p_business_group_id,
5947 					p_effective_date => p_effective_date);
5948 		end if;
5949 		close c_adj_rate_curr_per_in_ler;
5950 	  end if;
5951 
5952        end if ; -- p_copy only
5953        --
5954       end if;
5955 
5956 
5957     end loop;
5958     close c_prv_of_previous_pil;
5959 
5960     /* Bug 8507247: Commented the code here and moved it before the reopening the dates to EOT.
5961      First Adjust the rates and then open the backed out rates till EOT. This issue resolves Bug 8293106.
5962      Fix for Bug 8293106 is handled through Bug 8507247*/
5963 
5964     /*-- adjust the rate end for already adjusted rate
5965     open c_prtt_rt_val_adj (p_per_in_ler_id);
5966     loop
5967       fetch c_prtt_rt_val_adj into l_rt_adj;
5968       if c_prtt_rt_val_adj%found then
5969         --
5970         open c_prv_ovn (l_rt_adj.bkup_tbl_id);
5971         fetch c_prv_ovn into l_object_version_number;
5972         close c_prv_ovn;
5973         hr_utility.set_location('Ajdust rate end date'||l_rt_adj.bkup_tbl_id,10);
5974         --
5975         adj_prv_rate (p_person_id  => l_rt_adj.person_id,
5976                         p_prtt_rt_val_id  => l_rt_adj.bkup_tbl_id,
5977                         p_rt_end_dt =>    l_rt_adj.RT_END_DT,
5978                         p_object_version_number => l_object_version_number,
5979                         p_business_group_id => p_business_group_id,
5980                         p_effective_date => p_effective_date);
5981         --
5982       else   --not found
5983         exit;
5984       end if;
5985     end loop;
5986     close c_prtt_rt_val_adj;*/
5987     --
5988 
5989   elsif p_routine = 'BEN_PRTT_ENRT_RSLT_F' then
5990 
5991      hr_utility.set_location( 'backing out BEN_PRTT_ENRT_RSLT_F ' || p_per_in_ler_id   , 99 );
5992      hr_utility.set_location( 'p_bckdt_prtt_enrt_rslt_id ' || p_bckdt_prtt_enrt_rslt_id , 99 );
5993     -- Results need to be 'un-ended' if they were ended due to this
5994     -- per-in-ler.  The 'future change' date track mode handles that.
5995 
5999     -- subsequent LE, they need to be re-opened. This is for the case when pen
5996     -- Results that were created due to this per-in-ler need to be marked 'backed out'.
5997     --
5998     -- CFW. As Action items are always end dated when benmngle is run for the
6000     -- is not updated with subsequent LE but pea are end dated.
6001     --
6002     if  nvl(p_copy_only,'N') <>  'Y' then
6003     open c_pen_sus;
6004     loop
6005          fetch c_pen_sus into l_pen_sus;
6006          if c_pen_sus%notfound then
6007             exit;
6008          end if;
6009 
6010          unprocess_susp_enrt_past_pil
6011          (l_pen_sus.prtt_enrt_rslt_id,
6012           l_pen_sus.per_in_ler_id,
6013           p_business_group_id);
6014 
6015     end loop;
6016     close c_pen_sus;
6017     end if ;
6018 
6019     l_prev_pk_id := -1; -- like null
6020     g_enrt_made_flag := 'N';
6021     open c_ben_prtt_enrt_rslt_f;
6022       loop
6023 
6024         fetch c_ben_prtt_enrt_rslt_f into l_pk_id,
6025                                           l_object_version_number,
6026                                           l_pl_id,
6027                                           l_oipl_id,
6028                                           l_enrt_cvg_strt_dt,
6029                                           l_person_id,
6030                                           l_enrt_cvg_thru_dt,
6031                                           l_pen_eed,
6032                                           l_pen_esd,
6033                                           l_pen_pil_id,
6034                                           -- CFW
6035                                           l_lf_evt_ocrd_dt;
6036                                           -- CFW
6037         if c_ben_prtt_enrt_rslt_f%found then
6038            g_enrt_made_flag := 'Y';
6039         end if;
6040         exit when c_ben_prtt_enrt_rslt_f%notfound;
6041 
6042         -- Get the maximum of effective end date for the enrollment
6043         -- result with past per_in_ler 's.
6044         --
6045         l_effective_date := null;
6046         open  c_pen_max_esd_of_past_pil(l_pk_id);
6047         fetch c_pen_max_esd_of_past_pil into l_effective_date,
6048                                              l_max_object_version_number,
6049                                              l_prev_per_in_ler_id;
6050         close c_pen_max_esd_of_past_pil;
6051 
6052         -- Group function removed
6053         -- The group function "max" returns null when no records found,
6054         -- so check l_effective_date is null to find whether any
6055         -- past records were found.
6056         --
6057         hr_utility.set_location( 'Effective_date ' || l_effective_date , 99 );
6058         hr_utility.set_location( 'l_prev_pk_id ' || l_prev_pk_id , 99 );
6059         hr_utility.set_location( 'l_pk_id ' || l_pk_id , 99 );
6060 	 -- changed 7176884 begin
6061 	  --
6062 	  hr_utility.set_location( 'p_per_in_ler_id ' ||  p_per_in_ler_id , 44333 );
6063 	  hr_utility.set_location( 'l_pk_id ' ||  l_pk_id , 44333 );
6064 	  --
6065 	  open c_get_enrt_mthd_cd(l_pk_id);
6066 	  fetch c_get_enrt_mthd_cd into l_get_enrt_mthd_cd;
6067 	  close c_get_enrt_mthd_cd;
6068 	  --
6069 	  hr_utility.set_location( 'l_get_enrt_mthd_cd ' ||  l_get_enrt_mthd_cd , 44333 );
6070 	  -- changed 7176884 end
6071 
6072         if l_effective_date is not null then
6073          --
6074          -- Do not process the row as it is already processed(deleted).
6075          --
6076          if l_prev_pk_id <> l_pk_id then
6077 
6078            hr_utility.set_location('l_prev_pk_id <> l_pk_id = ' || l_prev_pk_id || ' <> ' ||  l_pk_id, 999);
6079            hr_utility.set_location( 'l_effective_date ' || l_effective_date , 99 );
6080 
6081            -- now backup all the deleted enrollment rows
6082            --
6083            for l_deleted_pen_rec in c_deleted_pen(l_pk_id, l_effective_date)
6084            loop
6085               --
6086               --
6087                hr_utility.set_location( ' backup pil  ' ||  l_deleted_pen_rec.PER_IN_LER_ID , 99 );
6088                hr_utility.set_location( ' backup pen  ' ||  l_deleted_pen_rec.PRTT_ENRT_RSLT_ID , 99 );
6089               open c_bkp_row('BEN_PRTT_ENRT_RSLT_F',
6090                              l_deleted_pen_rec.PER_IN_LER_ID,
6091                              l_deleted_pen_rec.PRTT_ENRT_RSLT_ID,
6092                              l_deleted_pen_rec.object_version_number);
6093               fetch c_bkp_row into l_row_id;
6094               --
6095               if c_bkp_row%notfound
6096               then
6097                   --
6098                    hr_utility.set_location( ' copying ' ||  l_deleted_pen_rec.PRTT_ENRT_RSLT_ID , 99 );
6099                   close c_bkp_row;
6100                   --
6101                   insert into BEN_LE_CLSN_N_RSTR (
6102                    BKUP_TBL_TYP_CD,
6103                    COMP_LVL_CD,
6104                    LCR_ATTRIBUTE16,
6105                    LCR_ATTRIBUTE17,
6106                    LCR_ATTRIBUTE18,
6107                    LCR_ATTRIBUTE19,
6108                    LCR_ATTRIBUTE20,
6109                    LCR_ATTRIBUTE21,
6110                    LCR_ATTRIBUTE22,
6111                    LCR_ATTRIBUTE23,
6112                    LCR_ATTRIBUTE24,
6113                    LCR_ATTRIBUTE25,
6114                    LCR_ATTRIBUTE26,
6115                    LCR_ATTRIBUTE27,
6116                    LCR_ATTRIBUTE28,
6117                    LCR_ATTRIBUTE29,
6118                    LCR_ATTRIBUTE30,
6119                    LAST_UPDATE_DATE,
6120                    LAST_UPDATED_BY,
6121                    LAST_UPDATE_LOGIN,
6122                    CREATED_BY,
6123                    CREATION_DATE,
6124                    REQUEST_ID,
6125                    PROGRAM_APPLICATION_ID,
6129                    BKUP_TBL_ID, -- PRTT_ENRT_RSLT_ID,
6126                    PROGRAM_ID,
6127                    PROGRAM_UPDATE_DATE,
6128                    OBJECT_VERSION_NUMBER,
6130                    EFFECTIVE_START_DATE,
6131                    EFFECTIVE_END_DATE,
6132                    ENRT_CVG_STRT_DT,
6133                    ENRT_CVG_THRU_DT,
6134                    SSPNDD_FLAG,
6135                    PRTT_IS_CVRD_FLAG,
6136                    BNFT_AMT,
6137                    BNFT_NNMNTRY_UOM,
6138                    BNFT_TYP_CD,
6139                    UOM,
6140                    ORGNL_ENRT_DT,
6141                    ENRT_MTHD_CD,
6142                    ENRT_OVRIDN_FLAG,
6143                    ENRT_OVRID_RSN_CD,
6144                    ERLST_DEENRT_DT,
6145                    ENRT_OVRID_THRU_DT,
6146                    NO_LNGR_ELIG_FLAG,
6147                    BNFT_ORDR_NUM,
6148                    PERSON_ID,
6149                    ASSIGNMENT_ID,
6150                    PGM_ID,
6151                    PRTT_ENRT_RSLT_STAT_CD,
6152                    PL_ID,
6153                    OIPL_ID,
6154                    PTIP_ID,
6155                    PL_TYP_ID,
6156                    LER_ID,
6157                    PER_IN_LER_ID,
6158                    RPLCS_SSPNDD_RSLT_ID,
6159                    BUSINESS_GROUP_ID,
6160                    LCR_ATTRIBUTE_CATEGORY,
6161                    LCR_ATTRIBUTE1,
6162                    LCR_ATTRIBUTE2,
6163                    LCR_ATTRIBUTE3,
6164                    LCR_ATTRIBUTE4,
6165                    LCR_ATTRIBUTE5,
6166                    LCR_ATTRIBUTE6,
6167                    LCR_ATTRIBUTE7,
6168                    LCR_ATTRIBUTE8,
6169                    LCR_ATTRIBUTE9,
6170                    LCR_ATTRIBUTE10,
6171                    LCR_ATTRIBUTE11,
6172                    LCR_ATTRIBUTE12,
6173                    LCR_ATTRIBUTE13,
6174                    LCR_ATTRIBUTE14,
6175                    LCR_ATTRIBUTE15 ,
6176                    PL_ORDR_NUM,
6177                    PLIP_ORDR_NUM,
6178                    PTIP_ORDR_NUM,
6179                    OIPL_ORDR_NUM)
6180               values (
6181                   'BEN_PRTT_ENRT_RSLT_F',
6182                   l_deleted_pen_rec.COMP_LVL_CD,
6183                   l_deleted_pen_rec.PEN_ATTRIBUTE16,
6184                   l_deleted_pen_rec.PEN_ATTRIBUTE17,
6185                   l_deleted_pen_rec.PEN_ATTRIBUTE18,
6186                   l_deleted_pen_rec.PEN_ATTRIBUTE19,
6187                   l_deleted_pen_rec.PEN_ATTRIBUTE20,
6188                   l_deleted_pen_rec.PEN_ATTRIBUTE21,
6189                   l_deleted_pen_rec.PEN_ATTRIBUTE22,
6190                   l_deleted_pen_rec.PEN_ATTRIBUTE23,
6191                   l_deleted_pen_rec.PEN_ATTRIBUTE24,
6192                   l_deleted_pen_rec.PEN_ATTRIBUTE25,
6193                   l_deleted_pen_rec.PEN_ATTRIBUTE26,
6194                   l_deleted_pen_rec.PEN_ATTRIBUTE27,
6195                   l_deleted_pen_rec.PEN_ATTRIBUTE28,
6196                   l_deleted_pen_rec.PEN_ATTRIBUTE29,
6197                   l_deleted_pen_rec.PEN_ATTRIBUTE30,
6198                   l_deleted_pen_rec.LAST_UPDATE_DATE,
6199                   l_deleted_pen_rec.LAST_UPDATED_BY,
6200                   l_deleted_pen_rec.LAST_UPDATE_LOGIN,
6201                   l_deleted_pen_rec.CREATED_BY,
6202                   l_deleted_pen_rec.CREATION_DATE,
6203                   l_deleted_pen_rec.REQUEST_ID,
6204                   l_deleted_pen_rec.PROGRAM_APPLICATION_ID,
6205                   l_deleted_pen_rec.PROGRAM_ID,
6206                   l_deleted_pen_rec.PROGRAM_UPDATE_DATE,
6207                   l_deleted_pen_rec.OBJECT_VERSION_NUMBER,
6208                   l_deleted_pen_rec.PRTT_ENRT_RSLT_ID,
6209                   l_deleted_pen_rec.EFFECTIVE_START_DATE,
6210                   l_deleted_pen_rec.EFFECTIVE_END_DATE,
6211                   l_deleted_pen_rec.ENRT_CVG_STRT_DT,
6212                   l_deleted_pen_rec.ENRT_CVG_THRU_DT,
6213                   l_deleted_pen_rec.SSPNDD_FLAG,
6214                   l_deleted_pen_rec.PRTT_IS_CVRD_FLAG,
6215                   l_deleted_pen_rec.BNFT_AMT,
6216                   l_deleted_pen_rec.BNFT_NNMNTRY_UOM,
6217                   l_deleted_pen_rec.BNFT_TYP_CD,
6218                   l_deleted_pen_rec.UOM,
6219                   l_deleted_pen_rec.ORGNL_ENRT_DT,
6220                   l_deleted_pen_rec.ENRT_MTHD_CD,
6221                   l_deleted_pen_rec.ENRT_OVRIDN_FLAG,
6222                   l_deleted_pen_rec.ENRT_OVRID_RSN_CD,
6223                   l_deleted_pen_rec.ERLST_DEENRT_DT,
6224                   l_deleted_pen_rec.ENRT_OVRID_THRU_DT,
6225                   l_deleted_pen_rec.NO_LNGR_ELIG_FLAG,
6226                   l_deleted_pen_rec.BNFT_ORDR_NUM,
6227                   l_deleted_pen_rec.PERSON_ID,
6228                   l_deleted_pen_rec.ASSIGNMENT_ID,
6229                   l_deleted_pen_rec.PGM_ID,
6230                   l_deleted_pen_rec.PRTT_ENRT_RSLT_STAT_CD,
6231                   l_deleted_pen_rec.PL_ID,
6232                   l_deleted_pen_rec.OIPL_ID,
6233                   l_deleted_pen_rec.PTIP_ID,
6234                   l_deleted_pen_rec.PL_TYP_ID,
6235                   l_deleted_pen_rec.LER_ID,
6236                   l_deleted_pen_rec.PER_IN_LER_ID,
6237                   l_deleted_pen_rec.RPLCS_SSPNDD_RSLT_ID,
6238                   l_deleted_pen_rec.BUSINESS_GROUP_ID,
6239                   l_deleted_pen_rec.PEN_ATTRIBUTE_CATEGORY,
6240                   l_deleted_pen_rec.PEN_ATTRIBUTE1,
6241                   l_deleted_pen_rec.PEN_ATTRIBUTE2,
6242                   l_deleted_pen_rec.PEN_ATTRIBUTE3,
6243                   l_deleted_pen_rec.PEN_ATTRIBUTE4,
6244                   l_deleted_pen_rec.PEN_ATTRIBUTE5,
6245                   l_deleted_pen_rec.PEN_ATTRIBUTE6,
6246                   l_deleted_pen_rec.PEN_ATTRIBUTE7,
6247                   l_deleted_pen_rec.PEN_ATTRIBUTE8,
6251                   l_deleted_pen_rec.PEN_ATTRIBUTE12,
6248                   l_deleted_pen_rec.PEN_ATTRIBUTE9,
6249                   l_deleted_pen_rec.PEN_ATTRIBUTE10,
6250                   l_deleted_pen_rec.PEN_ATTRIBUTE11,
6252                   l_deleted_pen_rec.PEN_ATTRIBUTE13,
6253                   l_deleted_pen_rec.PEN_ATTRIBUTE14,
6254                   l_deleted_pen_rec.PEN_ATTRIBUTE15,
6255                   l_deleted_pen_rec.PL_ORDR_NUM,
6256                   l_deleted_pen_rec.PLIP_ORDR_NUM,
6257                   l_deleted_pen_rec.PTIP_ORDR_NUM,
6258                   l_deleted_pen_rec.OIPL_ORDR_NUM
6259               );
6260              --
6261             else
6262               --
6263               close c_bkp_row;
6264               --
6265               update BEN_LE_CLSN_N_RSTR set
6266                    COMP_LVL_CD                  = l_deleted_pen_rec.COMP_LVL_CD,
6267                    LCR_ATTRIBUTE16              = l_deleted_pen_rec.PEN_ATTRIBUTE16,
6268                    LCR_ATTRIBUTE17              = l_deleted_pen_rec.PEN_ATTRIBUTE17,
6269                    LCR_ATTRIBUTE18              = l_deleted_pen_rec.PEN_ATTRIBUTE18,
6270                    LCR_ATTRIBUTE19              = l_deleted_pen_rec.PEN_ATTRIBUTE19,
6271                    LCR_ATTRIBUTE20              = l_deleted_pen_rec.PEN_ATTRIBUTE20,
6272                    LCR_ATTRIBUTE21              = l_deleted_pen_rec.PEN_ATTRIBUTE21,
6273                    LCR_ATTRIBUTE22              = l_deleted_pen_rec.PEN_ATTRIBUTE22,
6274                    LCR_ATTRIBUTE23              = l_deleted_pen_rec.PEN_ATTRIBUTE23,
6275                    LCR_ATTRIBUTE24              = l_deleted_pen_rec.PEN_ATTRIBUTE24,
6276                    LCR_ATTRIBUTE25              = l_deleted_pen_rec.PEN_ATTRIBUTE25,
6277                    LCR_ATTRIBUTE26              = l_deleted_pen_rec.PEN_ATTRIBUTE26,
6278                    LCR_ATTRIBUTE27              = l_deleted_pen_rec.PEN_ATTRIBUTE27,
6279                    LCR_ATTRIBUTE28              = l_deleted_pen_rec.PEN_ATTRIBUTE28,
6280                    LCR_ATTRIBUTE29              = l_deleted_pen_rec.PEN_ATTRIBUTE29,
6281                    LCR_ATTRIBUTE30              = l_deleted_pen_rec.PEN_ATTRIBUTE30,
6282                    LAST_UPDATE_DATE             = l_deleted_pen_rec.LAST_UPDATE_DATE,
6283                    LAST_UPDATED_BY              = l_deleted_pen_rec.LAST_UPDATED_BY,
6284                    LAST_UPDATE_LOGIN            = l_deleted_pen_rec.LAST_UPDATE_LOGIN,
6285                    CREATED_BY                   = l_deleted_pen_rec.CREATED_BY,
6286                    CREATION_DATE                = l_deleted_pen_rec.CREATION_DATE,
6287                    REQUEST_ID                   = l_deleted_pen_rec.REQUEST_ID,
6288                    PROGRAM_APPLICATION_ID       = l_deleted_pen_rec.PROGRAM_APPLICATION_ID,
6289                    PROGRAM_ID                   = l_deleted_pen_rec.PROGRAM_ID,
6290                    PROGRAM_UPDATE_DATE          = l_deleted_pen_rec.PROGRAM_UPDATE_DATE,
6291                    EFFECTIVE_START_DATE         = l_deleted_pen_rec.EFFECTIVE_START_DATE,
6292                    EFFECTIVE_END_DATE           = l_deleted_pen_rec.EFFECTIVE_END_DATE,
6293                    ENRT_CVG_STRT_DT             = l_deleted_pen_rec.ENRT_CVG_STRT_DT,
6294                    ENRT_CVG_THRU_DT             = l_deleted_pen_rec.ENRT_CVG_THRU_DT,
6295                    SSPNDD_FLAG                  = l_deleted_pen_rec.SSPNDD_FLAG,
6296                    PRTT_IS_CVRD_FLAG            = l_deleted_pen_rec.PRTT_IS_CVRD_FLAG,
6297                    BNFT_AMT                     = l_deleted_pen_rec.BNFT_AMT,
6298                    BNFT_NNMNTRY_UOM             = l_deleted_pen_rec.BNFT_NNMNTRY_UOM,
6299                    BNFT_TYP_CD                  = l_deleted_pen_rec.BNFT_TYP_CD,
6300                    UOM                          = l_deleted_pen_rec.UOM,
6301                    ORGNL_ENRT_DT                = l_deleted_pen_rec.ORGNL_ENRT_DT,
6302                    ENRT_MTHD_CD                 = l_deleted_pen_rec.ENRT_MTHD_CD,
6303                    ENRT_OVRIDN_FLAG             = l_deleted_pen_rec.ENRT_OVRIDN_FLAG,
6304                    ENRT_OVRID_RSN_CD            = l_deleted_pen_rec.ENRT_OVRID_RSN_CD,
6305                    ERLST_DEENRT_DT              = l_deleted_pen_rec.ERLST_DEENRT_DT,
6306                    ENRT_OVRID_THRU_DT           = l_deleted_pen_rec.ENRT_OVRID_THRU_DT,
6307                    NO_LNGR_ELIG_FLAG            = l_deleted_pen_rec.NO_LNGR_ELIG_FLAG,
6308                    BNFT_ORDR_NUM                = l_deleted_pen_rec.BNFT_ORDR_NUM,
6309                    PERSON_ID                    = l_deleted_pen_rec.PERSON_ID,
6310                    ASSIGNMENT_ID                = l_deleted_pen_rec.ASSIGNMENT_ID,
6311                    PGM_ID                       = l_deleted_pen_rec.PGM_ID,
6312                    PRTT_ENRT_RSLT_STAT_CD       = l_deleted_pen_rec.PRTT_ENRT_RSLT_STAT_CD,
6313                    PL_ID                        = l_deleted_pen_rec.PL_ID,
6314                    OIPL_ID                      = l_deleted_pen_rec.OIPL_ID,
6315                    PTIP_ID                      = l_deleted_pen_rec.PTIP_ID,
6316                    PL_TYP_ID                    = l_deleted_pen_rec.PL_TYP_ID,
6317                    LER_ID                       = l_deleted_pen_rec.LER_ID,
6318                    RPLCS_SSPNDD_RSLT_ID         = l_deleted_pen_rec.RPLCS_SSPNDD_RSLT_ID,
6319                    BUSINESS_GROUP_ID            = l_deleted_pen_rec.BUSINESS_GROUP_ID,
6320                    LCR_ATTRIBUTE_CATEGORY       = l_deleted_pen_rec.PEN_ATTRIBUTE_CATEGORY,
6321                    LCR_ATTRIBUTE1               = l_deleted_pen_rec.PEN_ATTRIBUTE1,
6322                    LCR_ATTRIBUTE2               = l_deleted_pen_rec.PEN_ATTRIBUTE2,
6323                    LCR_ATTRIBUTE3               = l_deleted_pen_rec.PEN_ATTRIBUTE3,
6324                    LCR_ATTRIBUTE4               = l_deleted_pen_rec.PEN_ATTRIBUTE4,
6325                    LCR_ATTRIBUTE5               = l_deleted_pen_rec.PEN_ATTRIBUTE5,
6326                    LCR_ATTRIBUTE6               = l_deleted_pen_rec.PEN_ATTRIBUTE6,
6327                    LCR_ATTRIBUTE7               = l_deleted_pen_rec.PEN_ATTRIBUTE7,
6328                    LCR_ATTRIBUTE8               = l_deleted_pen_rec.PEN_ATTRIBUTE8,
6332                    LCR_ATTRIBUTE12              = l_deleted_pen_rec.PEN_ATTRIBUTE12,
6329                    LCR_ATTRIBUTE9               = l_deleted_pen_rec.PEN_ATTRIBUTE9,
6330                    LCR_ATTRIBUTE10              = l_deleted_pen_rec.PEN_ATTRIBUTE10,
6331                    LCR_ATTRIBUTE11              = l_deleted_pen_rec.PEN_ATTRIBUTE11,
6333                    LCR_ATTRIBUTE13              = l_deleted_pen_rec.PEN_ATTRIBUTE13,
6334                    LCR_ATTRIBUTE14              = l_deleted_pen_rec.PEN_ATTRIBUTE14,
6335                    LCR_ATTRIBUTE15              = l_deleted_pen_rec.PEN_ATTRIBUTE15,
6336                    PL_ORDR_NUM                  = l_deleted_pen_rec.PL_ORDR_NUM,
6337                    PLIP_ORDR_NUM                = l_deleted_pen_rec.PLIP_ORDR_NUM,
6338                    PTIP_ORDR_NUM                = l_deleted_pen_rec.PTIP_ORDR_NUM,
6339                    OIPL_ORDR_NUM                = l_deleted_pen_rec.OIPL_ORDR_NUM
6340               where rowid = l_row_id;
6341               --
6342             end if;
6343            end loop;
6344 
6345            -- Past records exist. So datetrack mode FUTURE_CHANGE.
6346            --
6347            l_datetrack_mode := hr_api.g_future_change;
6348            l_object_version_number := l_max_object_version_number;
6349            --
6350 
6351           -- Delete from the appropriate API.
6352           --
6353           --
6354           -- if the same result in the corrected result row dont delete the resutl
6355           -- that will be updated with the previous per_ler_id to reinstate the previous
6356           --  per_in_ler id of the same date. # 3086161
6357           l_dummy := null ;
6358           open  c_corr_result_exist (p_per_in_ler_id ,
6359                                    l_pk_id  ) ;
6360           fetch c_corr_result_exist into l_dummy ;
6361           close c_corr_result_exist ;
6362           hr_utility.set_location( 'corrected result exist ' ||  l_dummy , 99 );
6363 
6364           if l_effective_date <> hr_api.g_eot and l_dummy is null  and nvl(p_copy_only,'N') <>  'Y'  then
6365             ben_prtt_enrt_result_api.delete_prtt_enrt_result
6366               (p_validate                => false,
6367                p_prtt_enrt_rslt_id       => l_pk_id,
6368                p_effective_start_date    => l_effective_start_date,
6369                p_effective_end_date      => l_effective_end_date,
6370                p_object_version_number   => l_object_version_number,
6371                p_effective_date          => l_effective_date,
6372                p_datetrack_mode          => l_datetrack_mode,
6373                p_multi_row_validate      => FALSE);
6374           end if;
6375 
6376 	   /* Added for Bug 8984394 */
6377 	   hr_utility.set_location( 'l_pk_id ' ||  l_pk_id , 1999 );
6378 	   hr_utility.set_location( 'l_effective_end_date ' ||  l_effective_end_date , 1999 );
6379 	  if(l_effective_end_date = hr_api.g_eot) then
6380 	       /*Bug 9580432: Call update_epe procedure to update the epe record. Deleted the code and made a call
6381 	       to the procedure update_epe as the deleted code and procedure do the same thing ie update epe record
6382 	       with the prtt_enrt_rslt_id*/
6383 	       hr_utility.set_location(' Calling update_epe  ',1999);
6384                update_epe(p_prtt_enrt_rslt_id=> l_pk_id,
6385                           p_effective_date => l_effective_start_date,
6386                           p_per_in_ler_id => p_per_in_ler_id) ;
6387 	  end if;
6388 	  /* End of Bug 8984394 */
6389 
6390           --
6391           l_prev_pk_id := l_pk_id;
6392           --
6393           -- check if the cvg was ended or the row was just dt ended
6394           --
6395           if nvl(l_enrt_cvg_thru_dt,hr_api.g_eot)<>hr_api.g_eot or
6396              l_pen_eed<>hr_api.g_eot  and nvl(p_copy_only,'N') <>  'Y'  then
6397             --
6398             -- The ended row is being removed, effectively creating it.
6399             -- else it's just and update.
6400             --
6401             ben_ext_chlg.log_benefit_chg(
6402                p_action                      => 'CREATE'
6403               ,p_pl_id                       =>  l_pl_id
6404               ,p_oipl_id                     =>  l_oipl_id
6405               ,p_enrt_cvg_strt_dt            =>  l_enrt_cvg_strt_dt
6406               ,p_prtt_enrt_rslt_id           =>  l_pk_id
6407               ,p_per_in_ler_id               =>  l_pen_pil_id
6408               ,p_person_id                   =>  l_person_id
6409               ,p_business_group_id           =>  p_business_group_id
6410               ,p_effective_date              =>  l_effective_date
6411             );
6412           end if;
6413           -- CFW
6414           -- Unprocess for past pil after future_change delete is over
6415           --
6416           unprocess_susp_enrt_past_pil (l_pk_id,
6417                                         l_prev_per_in_ler_id,
6418                                         p_business_group_id);
6419           -- CFW
6420 
6421          end if; -- l_prev_pk_id <> l_pk_id
6422         else
6423            --
6424            -- No past records, so just update the record to 'backed out'.
6425            --
6426 /*
6427            -- This call is commented as the result rows are always updated with correction
6428            --
6429            ben_prtt_enrt_result_api.get_ben_pen_upd_dt_mode
6430            (p_effective_date         => p_effective_date
6431            ,p_base_key_value         => l_pk_id
6432            ,P_desired_datetrack_mode => hr_api.g_update
6433            ,P_datetrack_allow        => l_datetrack_mode
6434            );
6435 */
6436 
6437           -- 2982606 if the update for the result level then copy the  record to the
6438           -- backup table
6442 
6439           if p_bckdt_prtt_enrt_rslt_id is not null then
6440                 hr_utility.set_location('l_pk_id = ' || l_pk_id ,99);
6441                 hr_utility.set_location('l_pen_esd = ' || l_pen_esd ,99);
6443                 -- now backup all the deleted enrollment rows
6444                 --
6445                 for l_deleted_pen_rec in c_deleted_pen(l_pk_id, l_pen_esd)
6446                 loop
6447                    --
6448                    --
6449                    open c_bkp_row('BEN_PRTT_ENRT_RSLT_F',
6450                              l_deleted_pen_rec.PER_IN_LER_ID,
6451                              l_deleted_pen_rec.PRTT_ENRT_RSLT_ID,
6452                              l_deleted_pen_rec.object_version_number);
6453                    fetch c_bkp_row into l_row_id;
6454                    --
6455                    if c_bkp_row%notfound
6456                    then
6457                        --
6458                      close c_bkp_row;
6459                        hr_utility.set_location(' creating backup  ' ||  l_pk_id, 999);
6460                        insert into BEN_LE_CLSN_N_RSTR (
6461                         BKUP_TBL_TYP_CD,
6462                         COMP_LVL_CD,
6463                         LCR_ATTRIBUTE16,
6464                         LCR_ATTRIBUTE17,
6465                         LCR_ATTRIBUTE18,
6466                         LCR_ATTRIBUTE19,
6467                         LCR_ATTRIBUTE20,
6468                         LCR_ATTRIBUTE21,
6469                         LCR_ATTRIBUTE22,
6470                         LCR_ATTRIBUTE23,
6471                         LCR_ATTRIBUTE24,
6472                         LCR_ATTRIBUTE25,
6473                         LCR_ATTRIBUTE26,
6474                         LCR_ATTRIBUTE27,
6475                         LCR_ATTRIBUTE28,
6476                         LCR_ATTRIBUTE29,
6477                         LCR_ATTRIBUTE30,
6478                         LAST_UPDATE_DATE,
6479                         LAST_UPDATED_BY,
6480                         LAST_UPDATE_LOGIN,
6481                         CREATED_BY,
6482                         CREATION_DATE,
6483                         REQUEST_ID,
6484                         PROGRAM_APPLICATION_ID,
6485                         PROGRAM_ID,
6486                         PROGRAM_UPDATE_DATE,
6487                         OBJECT_VERSION_NUMBER,
6488                         BKUP_TBL_ID, -- PRTT_ENRT_RSLT_ID,
6489                         EFFECTIVE_START_DATE,
6490                         EFFECTIVE_END_DATE,
6491                         ENRT_CVG_STRT_DT,
6492                         ENRT_CVG_THRU_DT,
6493                         SSPNDD_FLAG,
6494                         PRTT_IS_CVRD_FLAG,
6495                         BNFT_AMT,
6496                         BNFT_NNMNTRY_UOM,
6497                         BNFT_TYP_CD,
6498                         UOM,
6499                         ORGNL_ENRT_DT,
6500                         ENRT_MTHD_CD,
6501                         ENRT_OVRIDN_FLAG,
6502                         ENRT_OVRID_RSN_CD,
6503                         ERLST_DEENRT_DT,
6504                         ENRT_OVRID_THRU_DT,
6505                         NO_LNGR_ELIG_FLAG,
6506                         BNFT_ORDR_NUM,
6507                         PERSON_ID,
6508                         ASSIGNMENT_ID,
6509                         PGM_ID,
6510                         PRTT_ENRT_RSLT_STAT_CD,
6511                         PL_ID,
6512                         OIPL_ID,
6513                         PTIP_ID,
6514                         PL_TYP_ID,
6515                         LER_ID,
6516                         PER_IN_LER_ID,
6517                         RPLCS_SSPNDD_RSLT_ID,
6518                         BUSINESS_GROUP_ID,
6519                         LCR_ATTRIBUTE_CATEGORY,
6520                         LCR_ATTRIBUTE1,
6521                         LCR_ATTRIBUTE2,
6522                         LCR_ATTRIBUTE3,
6523                         LCR_ATTRIBUTE4,
6524                         LCR_ATTRIBUTE5,
6525                         LCR_ATTRIBUTE6,
6526                         LCR_ATTRIBUTE7,
6527                         LCR_ATTRIBUTE8,
6528                         LCR_ATTRIBUTE9,
6529                         LCR_ATTRIBUTE10,
6530                         LCR_ATTRIBUTE11,
6531                         LCR_ATTRIBUTE12,
6532                         LCR_ATTRIBUTE13,
6533                         LCR_ATTRIBUTE14,
6534                         LCR_ATTRIBUTE15 ,
6535                         PL_ORDR_NUM,
6536                         PLIP_ORDR_NUM,
6537                         PTIP_ORDR_NUM,
6538                         OIPL_ORDR_NUM)
6539                    values (
6540                        'BEN_PRTT_ENRT_RSLT_F',
6541                        l_deleted_pen_rec.COMP_LVL_CD,
6542                        l_deleted_pen_rec.PEN_ATTRIBUTE16,
6543                        l_deleted_pen_rec.PEN_ATTRIBUTE17,
6544                        l_deleted_pen_rec.PEN_ATTRIBUTE18,
6545                        l_deleted_pen_rec.PEN_ATTRIBUTE19,
6546                        l_deleted_pen_rec.PEN_ATTRIBUTE20,
6547                        l_deleted_pen_rec.PEN_ATTRIBUTE21,
6548                        l_deleted_pen_rec.PEN_ATTRIBUTE22,
6549                        l_deleted_pen_rec.PEN_ATTRIBUTE23,
6550                        l_deleted_pen_rec.PEN_ATTRIBUTE24,
6551                        l_deleted_pen_rec.PEN_ATTRIBUTE25,
6552                        l_deleted_pen_rec.PEN_ATTRIBUTE26,
6553                        l_deleted_pen_rec.PEN_ATTRIBUTE27,
6554                        l_deleted_pen_rec.PEN_ATTRIBUTE28,
6555                        l_deleted_pen_rec.PEN_ATTRIBUTE29,
6556                        l_deleted_pen_rec.PEN_ATTRIBUTE30,
6557                        l_deleted_pen_rec.LAST_UPDATE_DATE,
6558                        l_deleted_pen_rec.LAST_UPDATED_BY,
6559                        l_deleted_pen_rec.LAST_UPDATE_LOGIN,
6560                        l_deleted_pen_rec.CREATED_BY,
6564                        l_deleted_pen_rec.PROGRAM_ID,
6561                        l_deleted_pen_rec.CREATION_DATE,
6562                        l_deleted_pen_rec.REQUEST_ID,
6563                        l_deleted_pen_rec.PROGRAM_APPLICATION_ID,
6565                        l_deleted_pen_rec.PROGRAM_UPDATE_DATE,
6566                        l_deleted_pen_rec.OBJECT_VERSION_NUMBER,
6567                        l_deleted_pen_rec.PRTT_ENRT_RSLT_ID,
6568                        l_deleted_pen_rec.EFFECTIVE_START_DATE,
6569                        l_deleted_pen_rec.EFFECTIVE_END_DATE,
6570                        l_deleted_pen_rec.ENRT_CVG_STRT_DT,
6571                        l_deleted_pen_rec.ENRT_CVG_THRU_DT,
6572                        l_deleted_pen_rec.SSPNDD_FLAG,
6573                        l_deleted_pen_rec.PRTT_IS_CVRD_FLAG,
6574                        l_deleted_pen_rec.BNFT_AMT,
6575                        l_deleted_pen_rec.BNFT_NNMNTRY_UOM,
6576                        l_deleted_pen_rec.BNFT_TYP_CD,
6577                        l_deleted_pen_rec.UOM,
6578                        l_deleted_pen_rec.ORGNL_ENRT_DT,
6579                        l_deleted_pen_rec.ENRT_MTHD_CD,
6580                        l_deleted_pen_rec.ENRT_OVRIDN_FLAG,
6581                        l_deleted_pen_rec.ENRT_OVRID_RSN_CD,
6582                        l_deleted_pen_rec.ERLST_DEENRT_DT,
6583                        l_deleted_pen_rec.ENRT_OVRID_THRU_DT,
6584                        l_deleted_pen_rec.NO_LNGR_ELIG_FLAG,
6585                        l_deleted_pen_rec.BNFT_ORDR_NUM,
6586                        l_deleted_pen_rec.PERSON_ID,
6587                        l_deleted_pen_rec.ASSIGNMENT_ID,
6588                        l_deleted_pen_rec.PGM_ID,
6589                        l_deleted_pen_rec.PRTT_ENRT_RSLT_STAT_CD,
6590                        l_deleted_pen_rec.PL_ID,
6591                        l_deleted_pen_rec.OIPL_ID,
6592                        l_deleted_pen_rec.PTIP_ID,
6593                        l_deleted_pen_rec.PL_TYP_ID,
6594                        l_deleted_pen_rec.LER_ID,
6595                        l_deleted_pen_rec.PER_IN_LER_ID,
6596                        l_deleted_pen_rec.RPLCS_SSPNDD_RSLT_ID,
6597                        l_deleted_pen_rec.BUSINESS_GROUP_ID,
6598                        l_deleted_pen_rec.PEN_ATTRIBUTE_CATEGORY,
6599                        l_deleted_pen_rec.PEN_ATTRIBUTE1,
6600                        l_deleted_pen_rec.PEN_ATTRIBUTE2,
6601                        l_deleted_pen_rec.PEN_ATTRIBUTE3,
6602                        l_deleted_pen_rec.PEN_ATTRIBUTE4,
6603                        l_deleted_pen_rec.PEN_ATTRIBUTE5,
6604                        l_deleted_pen_rec.PEN_ATTRIBUTE6,
6605                        l_deleted_pen_rec.PEN_ATTRIBUTE7,
6606                        l_deleted_pen_rec.PEN_ATTRIBUTE8,
6607                        l_deleted_pen_rec.PEN_ATTRIBUTE9,
6608                        l_deleted_pen_rec.PEN_ATTRIBUTE10,
6609                        l_deleted_pen_rec.PEN_ATTRIBUTE11,
6610                        l_deleted_pen_rec.PEN_ATTRIBUTE12,
6611                        l_deleted_pen_rec.PEN_ATTRIBUTE13,
6612                        l_deleted_pen_rec.PEN_ATTRIBUTE14,
6613                        l_deleted_pen_rec.PEN_ATTRIBUTE15,
6614                        l_deleted_pen_rec.PL_ORDR_NUM,
6615                        l_deleted_pen_rec.PLIP_ORDR_NUM,
6616                        l_deleted_pen_rec.PTIP_ORDR_NUM,
6617                        l_deleted_pen_rec.OIPL_ORDR_NUM
6618                    );
6619                   --
6620                  else
6621                    --
6622                    close c_bkp_row;
6623                    --
6624                    update BEN_LE_CLSN_N_RSTR set
6625                         COMP_LVL_CD                  = l_deleted_pen_rec.COMP_LVL_CD,
6626                         LCR_ATTRIBUTE16              = l_deleted_pen_rec.PEN_ATTRIBUTE16,
6627                         LCR_ATTRIBUTE17              = l_deleted_pen_rec.PEN_ATTRIBUTE17,
6628                         LCR_ATTRIBUTE18              = l_deleted_pen_rec.PEN_ATTRIBUTE18,
6629                         LCR_ATTRIBUTE19              = l_deleted_pen_rec.PEN_ATTRIBUTE19,
6630                         LCR_ATTRIBUTE20              = l_deleted_pen_rec.PEN_ATTRIBUTE20,
6631                         LCR_ATTRIBUTE21              = l_deleted_pen_rec.PEN_ATTRIBUTE21,
6632                         LCR_ATTRIBUTE22              = l_deleted_pen_rec.PEN_ATTRIBUTE22,
6633                         LCR_ATTRIBUTE23              = l_deleted_pen_rec.PEN_ATTRIBUTE23,
6634                         LCR_ATTRIBUTE24              = l_deleted_pen_rec.PEN_ATTRIBUTE24,
6635                         LCR_ATTRIBUTE25              = l_deleted_pen_rec.PEN_ATTRIBUTE25,
6636                         LCR_ATTRIBUTE26              = l_deleted_pen_rec.PEN_ATTRIBUTE26,
6637                         LCR_ATTRIBUTE27              = l_deleted_pen_rec.PEN_ATTRIBUTE27,
6638                         LCR_ATTRIBUTE28              = l_deleted_pen_rec.PEN_ATTRIBUTE28,
6639                         LCR_ATTRIBUTE29              = l_deleted_pen_rec.PEN_ATTRIBUTE29,
6640                         LCR_ATTRIBUTE30              = l_deleted_pen_rec.PEN_ATTRIBUTE30,
6641                         LAST_UPDATE_DATE             = l_deleted_pen_rec.LAST_UPDATE_DATE,
6642                         LAST_UPDATED_BY              = l_deleted_pen_rec.LAST_UPDATED_BY,
6643                         LAST_UPDATE_LOGIN            = l_deleted_pen_rec.LAST_UPDATE_LOGIN,
6644                         CREATED_BY                   = l_deleted_pen_rec.CREATED_BY,
6645                         CREATION_DATE                = l_deleted_pen_rec.CREATION_DATE,
6646                         REQUEST_ID                   = l_deleted_pen_rec.REQUEST_ID,
6647                         PROGRAM_APPLICATION_ID       = l_deleted_pen_rec.PROGRAM_APPLICATION_ID,
6648                         PROGRAM_ID                   = l_deleted_pen_rec.PROGRAM_ID,
6649                         PROGRAM_UPDATE_DATE          = l_deleted_pen_rec.PROGRAM_UPDATE_DATE,
6650                         EFFECTIVE_START_DATE         = l_deleted_pen_rec.EFFECTIVE_START_DATE,
6651                         EFFECTIVE_END_DATE           = l_deleted_pen_rec.EFFECTIVE_END_DATE,
6655                         PRTT_IS_CVRD_FLAG            = l_deleted_pen_rec.PRTT_IS_CVRD_FLAG,
6652                         ENRT_CVG_STRT_DT             = l_deleted_pen_rec.ENRT_CVG_STRT_DT,
6653                         ENRT_CVG_THRU_DT             = l_deleted_pen_rec.ENRT_CVG_THRU_DT,
6654                         SSPNDD_FLAG                  = l_deleted_pen_rec.SSPNDD_FLAG,
6656                         BNFT_AMT                     = l_deleted_pen_rec.BNFT_AMT,
6657                         BNFT_NNMNTRY_UOM             = l_deleted_pen_rec.BNFT_NNMNTRY_UOM,
6658                         BNFT_TYP_CD                  = l_deleted_pen_rec.BNFT_TYP_CD,
6659                         UOM                          = l_deleted_pen_rec.UOM,
6660                         ORGNL_ENRT_DT                = l_deleted_pen_rec.ORGNL_ENRT_DT,
6661                         ENRT_MTHD_CD                 = l_deleted_pen_rec.ENRT_MTHD_CD,
6662                         ENRT_OVRIDN_FLAG             = l_deleted_pen_rec.ENRT_OVRIDN_FLAG,
6663                         ENRT_OVRID_RSN_CD            = l_deleted_pen_rec.ENRT_OVRID_RSN_CD,
6664                         ERLST_DEENRT_DT              = l_deleted_pen_rec.ERLST_DEENRT_DT,
6665                         ENRT_OVRID_THRU_DT           = l_deleted_pen_rec.ENRT_OVRID_THRU_DT,
6666                         NO_LNGR_ELIG_FLAG            = l_deleted_pen_rec.NO_LNGR_ELIG_FLAG,
6667                         BNFT_ORDR_NUM                = l_deleted_pen_rec.BNFT_ORDR_NUM,
6668                         PERSON_ID                    = l_deleted_pen_rec.PERSON_ID,
6669                         ASSIGNMENT_ID                = l_deleted_pen_rec.ASSIGNMENT_ID,
6670                         PGM_ID                       = l_deleted_pen_rec.PGM_ID,
6671                         PRTT_ENRT_RSLT_STAT_CD       = l_deleted_pen_rec.PRTT_ENRT_RSLT_STAT_CD,
6672                         PL_ID                        = l_deleted_pen_rec.PL_ID,
6673                         OIPL_ID                      = l_deleted_pen_rec.OIPL_ID,
6674                         PTIP_ID                      = l_deleted_pen_rec.PTIP_ID,
6675                         PL_TYP_ID                    = l_deleted_pen_rec.PL_TYP_ID,
6676                         LER_ID                       = l_deleted_pen_rec.LER_ID,
6677                         RPLCS_SSPNDD_RSLT_ID         = l_deleted_pen_rec.RPLCS_SSPNDD_RSLT_ID,
6678                         BUSINESS_GROUP_ID            = l_deleted_pen_rec.BUSINESS_GROUP_ID,
6679                         LCR_ATTRIBUTE_CATEGORY       = l_deleted_pen_rec.PEN_ATTRIBUTE_CATEGORY,
6680                         LCR_ATTRIBUTE1               = l_deleted_pen_rec.PEN_ATTRIBUTE1,
6681                         LCR_ATTRIBUTE2               = l_deleted_pen_rec.PEN_ATTRIBUTE2,
6682                         LCR_ATTRIBUTE3               = l_deleted_pen_rec.PEN_ATTRIBUTE3,
6683                         LCR_ATTRIBUTE4               = l_deleted_pen_rec.PEN_ATTRIBUTE4,
6684                         LCR_ATTRIBUTE5               = l_deleted_pen_rec.PEN_ATTRIBUTE5,
6685                         LCR_ATTRIBUTE6               = l_deleted_pen_rec.PEN_ATTRIBUTE6,
6686                         LCR_ATTRIBUTE7               = l_deleted_pen_rec.PEN_ATTRIBUTE7,
6687                         LCR_ATTRIBUTE8               = l_deleted_pen_rec.PEN_ATTRIBUTE8,
6688                         LCR_ATTRIBUTE9               = l_deleted_pen_rec.PEN_ATTRIBUTE9,
6689                         LCR_ATTRIBUTE10              = l_deleted_pen_rec.PEN_ATTRIBUTE10,
6690                         LCR_ATTRIBUTE11              = l_deleted_pen_rec.PEN_ATTRIBUTE11,
6691                         LCR_ATTRIBUTE12              = l_deleted_pen_rec.PEN_ATTRIBUTE12,
6692                         LCR_ATTRIBUTE13              = l_deleted_pen_rec.PEN_ATTRIBUTE13,
6693                         LCR_ATTRIBUTE14              = l_deleted_pen_rec.PEN_ATTRIBUTE14,
6694                         LCR_ATTRIBUTE15              = l_deleted_pen_rec.PEN_ATTRIBUTE15,
6695                         PL_ORDR_NUM                  = l_deleted_pen_rec.PL_ORDR_NUM,
6696                         PLIP_ORDR_NUM                = l_deleted_pen_rec.PLIP_ORDR_NUM,
6697                         PTIP_ORDR_NUM                = l_deleted_pen_rec.PTIP_ORDR_NUM,
6698                         OIPL_ORDR_NUM                = l_deleted_pen_rec.OIPL_ORDR_NUM
6699                    where rowid = l_row_id;
6700                    --
6701                  end if;
6702              end loop;
6703           end if ;
6704           --
6705           -- Bug : 1143673 : use correction and use records eed as effective
6706           -- date to do it. If UPDATE mode is used as determined by
6707           -- get_ben_pen_upd_dt_mode, then one row will sit with status code as
6708           -- null, which causes the above bug situation.
6709           --
6710          if   nvl(p_copy_only,'N') <>  'Y' then
6711           --
6712           --  If corrected row exist, do not update the enrollment result.
6713           --  Bug 7197868
6714           --
6715           l_dummy := null;
6716           open  c_corr_result_exist (p_per_in_ler_id ,
6717                                    l_pk_id  ) ;
6718           fetch c_corr_result_exist into l_dummy ;
6719           close c_corr_result_exist ;
6720           if l_dummy is null then
6721           ben_prtt_enrt_result_api.update_prtt_enrt_result
6722             (p_validate               => FALSE
6723             ,p_prtt_enrt_rslt_id      => l_pk_id
6724             ,p_effective_start_date   => l_effective_start_date
6725             ,p_effective_end_date     => l_effective_end_date
6726             ,p_business_group_id      => p_business_group_id
6727             ,p_object_version_number  => l_object_version_number
6728             ,p_prtt_enrt_rslt_stat_cd => 'BCKDT'
6729             ,p_effective_date         => l_pen_esd  --  p_effective_date
6730             ,p_datetrack_mode         => hr_api.g_correction -- l_datetrack_mode
6731             ,p_multi_row_validate     => FALSE);
6732           --
6733           ben_ext_chlg.log_benefit_chg(
6734             p_action                      => 'DELETE'
6735            ,p_old_pl_id                   =>  l_pl_id
6736            ,p_old_oipl_id                 =>  l_oipl_id
6737            ,p_old_enrt_cvg_strt_dt        =>  l_enrt_cvg_strt_dt
6741            ,p_enrt_cvg_strt_dt            =>  l_enrt_cvg_strt_dt
6738            ,p_old_enrt_cvg_end_dt         =>  l_enrt_cvg_thru_dt
6739            ,p_pl_id                       =>  l_pl_id
6740            ,p_oipl_id                     =>  l_oipl_id
6742            ,p_enrt_cvg_end_dt             =>  (l_enrt_cvg_strt_dt-1)
6743            ,p_prtt_enrt_rslt_id           =>  l_pk_id
6744            ,p_per_in_ler_id               =>  l_pen_pil_id
6745            ,p_person_id                   =>  l_person_id
6746            ,p_business_group_id           =>  p_business_group_id
6747            ,p_effective_date              =>  l_pen_eed
6748           );
6749            end if; -- l_dummy is null
6750         end if ; --- copy only
6751 
6752         end if;
6753 
6754       end loop;
6755       --
6756       l_prev_pk_id := -1;
6757       --
6758     close c_ben_prtt_enrt_rslt_f;
6759     -- after result backed out  determine the person type usage
6760     -- since the backout not calling the multiedit
6761     -- person type usage is not updated  # 2899702
6762     ben_pen_bus.manage_per_type_usages
6763                  ( p_person_id          => l_person_id
6764                   ,p_business_group_id  => p_business_group_id
6765                   ,p_effective_date     => p_effective_date
6766                   ) ;
6767       --
6768       l_prev_pk_id := -1;
6769 
6770 
6771      --- if result for the per_in_ler_id is found in 'BEN_PRTT_ENRT_RSLT_F_CORR
6772      --- correct the result with  with per_in_ler_id and coverage dates bug # 3086161
6773      for i  in  c_BEN_LE_CLSN_N_RSTR_corr(p_per_in_ler_id)
6774      Loop
6775           --
6776           --  Get the enrollment coverage end date --  bug 8199189
6777           --
6778           open c_get_cvg_thru_dt(i.bkup_tbl_id
6779                                 ,i.effective_start_date);
6780           fetch c_get_cvg_thru_dt into l_cvg_thru_dt, l_prtt_enrt_rslt_stat_cd;
6781           if c_get_cvg_thru_dt%notfound then
6782             hr_utility.set_location(' not found ' || l_cvg_thru_dt, 99 );
6783             l_cvg_thru_dt := i.enrt_cvg_thru_dt;
6784             l_prtt_enrt_rslt_stat_cd := i.prtt_enrt_rslt_stat_cd;
6785           end if;
6786           close c_get_cvg_thru_dt;
6787           --
6788          hr_utility.set_location(' l_cvg_thru_dt ' || l_cvg_thru_dt, 99 );
6789          hr_utility.set_location(' l_prtt_enrt_rslt_stat_cd' || l_prtt_enrt_rslt_stat_cd, 99 );
6790           --
6791           -- end 8199189
6792           --
6793          hr_utility.set_location(' corrected result ' || i.bkup_tbl_id, 99 );
6794         if l_prev_bkup_tbl_id <> i.bkup_tbl_id  and nvl(p_copy_only,'N') <>  'Y'  then
6795 
6796           l_object_version_number := i.object_version_number ;
6797          --bug#5032364
6798          if i.enrt_cvg_thru_dt <> hr_api.g_eot then
6799            --
6800            ben_prtt_enrt_result_api.delete_enrollment
6801            (p_validate              => false ,
6802            p_prtt_enrt_rslt_id     => i.bkup_tbl_id,
6803              p_per_in_ler_id         => i.per_in_ler_id,
6804            p_business_group_id     => p_business_group_id ,
6805            p_effective_start_date  => l_effective_start_date,
6806            p_effective_end_date    => l_effective_end_date,
6807            p_object_version_number => l_object_version_number,
6808            p_effective_date        => i.effective_start_date,
6809            p_datetrack_mode        => 'DELETE',
6810            p_enrt_cvg_thru_dt     => i.enrt_cvg_thru_dt,
6811            p_multi_row_validate    => false);
6812 
6813 
6814          else
6815            --
6816            --  When updating the corrected row, also correct the effective end date.
6817            --  Bug 7197868
6818            --
6819            if (i.effective_end_date =  hr_api.g_eot
6820                and i.pen_effective_end_date <> i.effective_end_date) then
6821              hr_utility.set_location(' correcting  ' || i.bkup_tbl_id, 999 );
6822              --
6823              --  Bug 7197868
6824              --
6825              -- Delete future dated records.
6826              --
6827              ben_prtt_enrt_result_api.delete_prtt_enrt_result
6828               (p_validate              => false ,
6829                p_prtt_enrt_rslt_id     => i.bkup_tbl_id,
6830                p_effective_start_date  => l_effective_start_date,
6831                p_effective_end_date    => l_effective_end_date,
6832                p_object_version_number => l_object_version_number,
6833                p_effective_date        => i.effective_start_date,
6834                p_datetrack_mode        => hr_api.g_future_change,
6835                p_multi_row_validate    => false);
6836            end if;
6837            --
6838            ben_prtt_enrt_result_api.update_prtt_enrt_result
6839                (p_validate                => FALSE
6840                ,p_prtt_enrt_rslt_id       => i.bkup_tbl_id
6841                ,p_effective_start_date    => l_effective_start_date
6842                ,p_effective_end_date      => l_effective_end_date
6843                ,p_per_in_ler_id           => i.per_in_ler_id
6844                ,p_ler_id                  => i.ler_id
6845                ,p_enrt_cvg_thru_dt        => i.enrt_cvg_thru_dt
6846                ,p_object_version_number   => l_object_version_number
6847                ,p_effective_date          => i.effective_start_date
6848                ,p_prtt_enrt_rslt_stat_cd  => i.prtt_enrt_rslt_stat_cd
6849 	       ,p_enrt_mthd_cd            => i.enrt_mthd_cd -- Bug 7137371
6850                ,p_datetrack_mode          => hr_api.g_correction
6851                ,p_sspndd_flag            => i.sspndd_flag
6852                ,p_multi_row_validate      => FALSE
6853                ,p_business_group_id       => p_business_group_id
6854             );
6855           end if;
6856 
6857 	       /*Bug 9580432 :Call the procedure update_epe to update the epe record of the previous Life Event
6861                           p_effective_date => i.effective_start_date,
6858 	       with the prtt_enrt_rslt_id of the reopened result */
6859 	       hr_utility.set_location(' Calling update_epe  ',1998);
6860                update_epe(p_prtt_enrt_rslt_id=> i.bkup_tbl_id,
6862                           p_per_in_ler_id => p_per_in_ler_id) ;
6863 
6864 	  --
6865           -- Bug 6034585 Moved delete code inside the if so that it execute
6866 	  -- only when p_copy_only = 'N' and l_prev_bkup_tbl_id <> i.bkup_tbl_id
6867 	  --changed 7176884 begin
6868           -- delete the row from the  backup table  -- 7197868
6869           --
6870           if ((i.effective_end_date = hr_api.g_eot
6871                and i.pen_effective_end_date <> i.effective_end_date)
6872               or (l_prtt_enrt_rslt_stat_cd = 'VOIDD')) then  -- 8199189
6873              hr_utility.set_location(' correcting  ' || i.bkup_tbl_id, 999 );
6874              hr_utility.set_location(' i.per_in_ler_id  ' || i.per_in_ler_id, 999 );
6875              hr_utility.set_location(' p_per_in_ler_id  ' || p_per_in_ler_id, 999 );
6876              delete from ben_le_clsn_n_rstr cqb
6877                    where cqb.per_in_ler_id       = i.per_in_ler_id
6878                      and cqb.per_in_ler_ended_id = p_per_in_ler_id
6879                      and cqb.bkup_tbl_id         = i.bkup_tbl_id ;
6880           else
6881              hr_utility.set_location(' enrt_rslt_id' || i.bkup_tbl_id, 999 );
6882              hr_utility.set_location(' p_per_in_ler_id  ' || p_per_in_ler_id, 999 );
6883              hr_utility.set_location(' i.effective_start_date  ' || i.effective_start_date, 999 );
6884 	--
6885         update ben_le_clsn_n_rstr cqb
6886         set    cqb.per_in_ler_id       = p_per_in_ler_id
6887 	       , cqb.per_in_ler_ended_id = null
6888 	       , cqb.BKUP_TBL_TYP_CD = 'BEN_PRTT_ENRT_RSLT_F'
6889 	       , cqb.enrt_mthd_cd    = l_get_enrt_mthd_cd
6890                , cqb.enrt_cvg_thru_dt = l_cvg_thru_dt  -- Bug 8199189
6891 	where  cqb.per_in_ler_id       = i.per_in_ler_id
6892         and    cqb.per_in_ler_ended_id = p_per_in_ler_id
6893         and    cqb.bkup_tbl_id         = i.bkup_tbl_id ;
6894           end if;  -- bug 7197868
6895 	-- changed 7176884 end
6896           end if;
6897           l_prev_bkup_tbl_id := i.bkup_tbl_id;
6898 	  --
6899     /* Bug 6034585 : Commented out the update statement as it was
6900        updating per_in_ler_id field with the incorrect per_in_ler_id
6901      --bug#3702033 - for reinstate retain the row with necessary updates
6902       update ben_le_clsn_n_rstr cqb
6903           set cqb.per_in_ler_id = p_per_in_ler_id,
6904               cqb.per_in_ler_ended_id = null,
6905               cqb.BKUP_TBL_TYP_CD = 'BEN_PRTT_ENRT_RSLT_F'
6906           where cqb.per_in_ler_id       = i.per_in_ler_id
6907           and cqb.per_in_ler_ended_id = p_per_in_ler_id
6908           and cqb.bkup_tbl_id         = i.bkup_tbl_id ;
6909       --
6910      */
6911      end loop ;
6912      --
6913      l_prev_bkup_tbl_id := -1;
6914      --
6915      /*Bug 12963718: When backout package is called for backing out a single enrollment result(ie p_bckdt_prtt_enrt_rslt_id
6916      will not be NULL), do not call delete enrollment for backup records that exists in the backup table */
6917      if(p_bckdt_prtt_enrt_rslt_id is NULL) then
6918 	     for i  in  c_BEN_LE_CLSN_N_RSTR_del(p_per_in_ler_id)
6919 	     Loop
6920 		 hr_utility.set_location(' delete result ' || i.bkup_tbl_id, 99 );
6921 		if l_prev_bkup_tbl_id <> i.bkup_tbl_id  then
6922 
6923 		  l_object_version_number := i.object_version_number ;
6924 		 --bug#5032364
6925 		   --
6926 		   ben_prtt_enrt_result_api.delete_enrollment
6927 		   (p_validate              => false ,
6928 		   p_prtt_enrt_rslt_id     => i.bkup_tbl_id,
6929 		   p_per_in_ler_id         => i.per_in_ler_id,
6930 		   p_business_group_id     => p_business_group_id ,
6931 		   p_effective_start_date  => l_effective_start_date,
6932 		   p_effective_end_date    => l_effective_end_date,
6933 		   p_object_version_number => l_object_version_number,
6934 		   p_effective_date        => i.effective_start_date,
6935 		   p_datetrack_mode        => 'DELETE',
6936 		   p_enrt_cvg_thru_dt     => i.enrt_cvg_thru_dt,
6937 		   p_multi_row_validate    => false);
6938 		   --
6939 		end if;
6940 		--
6941 		l_prev_bkup_tbl_id := i.bkup_tbl_id;
6942 		--
6943 	    end loop;
6944      end if;
6945 
6946     /*Bug 13050813: Added below 'if' condition.When backout package is called for backing out a single enrollment result(ie p_bckdt_prtt_enrt_rslt_id
6947       will not be NULL), do not adjust the coverage's for the pen records in backup table(_ADJ records) */
6948     if(p_bckdt_prtt_enrt_rslt_id is NULL) then
6949     --
6950     -- Added for bug 7206471
6951     -- adjust the coverage end for already adjusted coverage
6952 	open c_prtt_enrt_rslt_adj (p_per_in_ler_id);
6953 	loop
6954 	      fetch c_prtt_enrt_rslt_adj into l_cvg_adj;
6955 	      --
6956 	      if c_prtt_enrt_rslt_adj%found then
6957 	        --
6958 		l_cvg_adj_effective_date := null;
6959 		open c_pen_ovn (l_cvg_adj.bkup_tbl_id);
6960 		fetch c_pen_ovn into l_object_version_number,l_cvg_adj_effective_date;
6961 		close c_pen_ovn;
6962 		hr_utility.set_location('Ajdust coverage for '||l_cvg_adj.bkup_tbl_id,44333);
6963 		hr_utility.set_location('l_rt_adj'||l_cvg_adj_effective_date,44333);
6964 	        hr_utility.set_location('l_object_version_number'||l_object_version_number,44333);
6965 		--
6966 		--
6967 		/*Bug 9664943: Check l_cvg_adj_effective_date is not null before adjusting coverage*/
6968 		if l_cvg_adj_effective_date is not null then
6969 			adj_pen_cvg (p_person_id  => l_cvg_adj.person_id,
6970 					p_prtt_enrt_rslt_id  => l_cvg_adj.bkup_tbl_id,
6971 					p_cvg_end_dt =>    l_cvg_adj.enrt_cvg_thru_dt,
6972 					p_object_version_number => l_object_version_number,
6973 					p_business_group_id => p_business_group_id,
6974 					p_effective_date => l_cvg_adj_effective_date); -- Bug 8507247:
6978 		--
6975 			/* Changed parameter value passed to l_cvg_adj_effective_date.Effective start datewhich is picked
6976 			for Adjustment should be passed to 'adj_pen_cvg' instead of p_effective_date*/
6977 	       end if;
6979 		else   --not found
6980 		exit;
6981 	      end if;
6982 	    end loop;
6983 	    close c_prtt_enrt_rslt_adj;
6984     --
6985     -- End bug 7206471
6986 
6987     /* added for Bug 12576710: If coverage records exists for the backed out per_in_ler_id for adjustement,
6988        adjust the coverage*/
6989       open c_adj_rec_curr_per_in_ler (p_per_in_ler_id);
6990 	loop
6991 	      fetch c_adj_rec_curr_per_in_ler into l_cvg_adj;
6992 	      --
6993 	      if c_adj_rec_curr_per_in_ler%found then
6994 	        --
6995 		open c_pen_ovn (l_cvg_adj.bkup_tbl_id);
6996 		fetch c_pen_ovn into l_object_version_number,l_cvg_adj_effective_date;
6997 		close c_pen_ovn;
6998 		hr_utility.set_location('Ajdust coverage for ended per_in_ler'||l_cvg_adj.bkup_tbl_id,44333);
6999 		hr_utility.set_location('l_rt_adj'||l_cvg_adj_effective_date,44333);
7000 	        hr_utility.set_location('l_object_version_number'||l_object_version_number,44333);
7001 		--
7002 		--
7003 		adj_pen_cvg (p_person_id  => l_cvg_adj.person_id,
7004 			        p_prtt_enrt_rslt_id  => l_cvg_adj.bkup_tbl_id,
7005 				p_cvg_end_dt =>    l_cvg_adj.enrt_cvg_thru_dt,
7006 				p_object_version_number => l_object_version_number,
7007 				p_business_group_id => p_business_group_id,
7008 				p_effective_date => l_cvg_adj_effective_date);
7009 		else   --not found
7010 		   exit;
7011 	      end if;
7012 	    end loop;
7013       close c_adj_rec_curr_per_in_ler;
7014 
7015       end if;
7016 
7017   elsif p_routine = 'BEN_BNFT_PRVDD_LDGR_F' then
7018     --
7019     -- Bug 5500864
7020     -- This part of code has been added to take care of reinstatements of BPLs that have been END-DATED
7021     -- Such BPL Records have been backed up in BEN_LE_CLSN_N_RSTR. See BEN_BPL_DEL.POST_DELETE
7022     -- The part of the code below (which queries cursor c_ben_bnft_prvdd_ldgr_f) takes care of rest
7023     -- of the scenarios and voiding of BPL associated with the life-event being backed out.
7024     --
7025     hr_utility.set_location('ACE p_per_in_ler_id = ' || p_per_in_ler_id, 9999);
7026     --
7027     for l_bpl_from_backup in c_bpl_from_backup
7028     loop
7029       --
7030       hr_utility.set_location('ACE l_bpl_from_backup.bnft_prvdd_ldgr_id = ' || l_bpl_from_backup.BKUP_TBL_ID, 9999);
7031       --
7032       ben_Benefit_Prvdd_Ledger_api.delete_Benefit_Prvdd_Ledger
7033                (
7034                 p_bnft_prvdd_ldgr_id      => l_bpl_from_backup.BKUP_TBL_ID,
7035                 p_effective_start_date    => l_effective_start_date,
7036                 p_effective_end_date      => l_effective_end_date,
7037                 p_object_version_number   => l_bpl_from_backup.object_version_number,
7038                 p_effective_date          => l_bpl_from_backup.effective_start_date,
7039                 p_datetrack_mode          => hr_api.g_FUTURE_CHANGE,
7040                 p_business_group_id       => p_business_group_id
7041                );
7042       hr_utility.set_location('ACE Reopened = ' || l_bpl_from_backup.BKUP_TBL_ID, 9999);
7043       --
7044       -- Bug 6376239 : Remove the rows from backup table once the ledger rows are restored
7045       --
7046       delete from ben_le_clsn_n_rstr cls
7047              where cls.per_in_ler_id      = l_bpl_from_backup.per_in_ler_id
7048               and cls.bkup_tbl_id         = l_bpl_from_backup.bkup_tbl_id
7049 	      and cls.bkup_tbl_typ_cd     = 'BEN_BNFT_PRVDD_LDGR_F'
7050 	      and effective_start_date    = l_bpl_from_backup.effective_start_date
7051               and effective_end_date      = hr_api.g_eot;
7052     --
7053     -- End Bug 6376239
7054     --
7055     end loop;
7056     --
7057     -- Bug 5500864
7058     --
7059     l_prev_pk_id := -1; -- like null
7060     --
7061     -- Start Bug 6376239
7062     --
7063     if p_bckdt_prtt_enrt_rslt_id is not null then
7064        open c_bpl_from_pen;
7065        fetch c_bpl_from_pen into prev_bnft_prvdd_ldgr_id;
7066        close c_bpl_from_pen;
7067     end if;
7068     --
7069     -- End Bug 6376239
7070     --
7071     open c_ben_bnft_prvdd_ldgr_f(prev_bnft_prvdd_ldgr_id);
7072     loop
7073        l_effective_date := null;
7074        fetch c_ben_bnft_prvdd_ldgr_f into l_bpl;
7075        exit when c_ben_bnft_prvdd_ldgr_f%notfound;
7076        l_pk_id := l_bpl.bnft_prvdd_ldgr_id;
7077        open  c_bpl_max_esd_of_past_pil(l_pk_id);
7078        fetch c_bpl_max_esd_of_past_pil into l_effective_date,
7079                                              l_max_object_version_number;
7080        close c_bpl_max_esd_of_past_pil;
7081        if l_effective_date is not null then
7082          if l_prev_pk_id <> l_pk_id then
7083            -- Past records exist. So datetrack mode FUTURE_CHANGE.
7084            --
7085              l_datetrack_mode := hr_api.g_future_change;
7086              l_object_version_number := l_max_object_version_number;
7087              --
7088              if l_effective_date <> hr_api.g_eot  and nvl(p_copy_only,'N') <>  'Y'  then
7089                --
7090                hr_utility.set_location('Deleting ledger='||to_char(l_bpl.bnft_prvdd_ldgr_id), 50);
7091                --
7092                ben_Benefit_Prvdd_Ledger_api.delete_Benefit_Prvdd_Ledger(
7093                  p_bnft_prvdd_ldgr_id      => l_bpl.bnft_prvdd_ldgr_id,
7094                  p_effective_start_date    => l_bpl.effective_start_date,
7095                  p_effective_end_date      => l_bpl.effective_end_date,
7096                  p_object_version_number   => l_max_object_version_number,
7097                  p_effective_date          => l_effective_date,
7098                  p_datetrack_mode          => l_datetrack_mode,
7099                  p_business_group_id       => p_business_group_id
7103              l_prev_pk_id := l_pk_id;
7100                  );
7101 
7102              end if;
7104           end if;
7105         else
7106            --
7107            --
7108            -- added if condition to check if there is any update for the same per_in_ler
7109            if l_prev_pk_id <> l_pk_id  and nvl(p_copy_only,'N') <>  'Y' then
7110              --
7111                l_bpl_effective_date := l_bpl.effective_start_date ;
7112                hr_utility.set_location('ledger Id'||l_bpl.bnft_prvdd_ldgr_id,11);
7113                hr_utility.set_location('ovn Id'||l_bpl.object_version_number,11);
7114                --
7115                ben_Benefit_Prvdd_Ledger_api.delete_Benefit_Prvdd_Ledger(
7116                  p_bnft_prvdd_ldgr_id      => l_bpl.bnft_prvdd_ldgr_id,
7117                  p_effective_start_date    => l_bpl.effective_start_date,
7118                  p_effective_end_date      => l_bpl.effective_end_date,
7119                  p_object_version_number   => l_bpl.object_version_number,
7120                  p_effective_date          => l_bpl_effective_date,
7121                  p_datetrack_mode          => hr_api.g_zap,
7122                  p_business_group_id       => p_business_group_id
7123                  );
7124                l_prev_pk_id := l_pk_id;
7125            end if;
7126         end if;
7127      end loop;
7128      --
7129      close c_ben_bnft_prvdd_ldgr_f;
7130      --
7131   elsif p_routine = 'BEN_PIL_ELCTBL_CHC_POPL' then
7132 
7133     -- pil popl's are updated to 'backed out'
7134    if  nvl(p_copy_only,'N') <>  'Y' then
7135     open c_ben_pil_elctbl_chc_popl;
7136 
7137       loop
7138 
7139         fetch c_ben_pil_elctbl_chc_popl into l_pk_id,
7140                                              l_object_version_number;
7141         exit when c_ben_pil_elctbl_chc_popl%notfound;
7142         --
7143         -- Delete from the appropriate API.
7144         --
7145         ben_pil_elctbl_chc_popl_api.update_pil_elctbl_chc_popl
7146           (p_validate                => false,
7147            p_pil_elctbl_chc_popl_id  => l_pk_id,
7148            p_pil_elctbl_popl_stat_cd => 'BCKDT',
7149            p_object_version_number   => l_object_version_number,
7150            p_effective_date          => p_effective_date);
7151 
7152       end loop;
7153 
7154     close c_ben_pil_elctbl_chc_popl;
7155   end if ;
7156   --
7157   elsif p_routine = 'BEN_CBR_QUALD_BNF' then
7158     --
7159     -- Restore prior cobra eligibility end date.
7160     --
7161 
7162     for l_cqb_rec in c_get_cbr_quald_bnf loop
7163       --
7164       l_object_version_number := l_cqb_rec.object_version_number;
7165       --
7166      if  nvl(p_copy_only,'N') <>  'Y' then
7167       ben_cbr_quald_bnf_api.update_cbr_quald_bnf
7168         (p_validate              => false
7169         ,p_cbr_quald_bnf_id      => l_cqb_rec.cbr_quald_bnf_id
7170         ,p_quald_bnf_flag        => 'Y'
7171         ,p_cbr_elig_perd_end_dt  => l_cqb_rec.prvs_elig_perd_end_dt
7172         ,p_cbr_inelg_rsn_cd      => null
7173         ,p_business_group_id     => p_business_group_id
7174         ,p_object_version_number => l_object_version_number
7175         ,p_effective_date        => p_effective_date
7176         );
7177       --
7178       --  Copy to backup table to restore if neccessary.
7179       --
7180       --
7181      end if ;
7182       open c_bkp_row('BEN_CBR_QUALD_BNF',
7183                      p_per_in_ler_id,
7184                      l_cqb_rec.cbr_quald_bnf_id,
7185                      l_object_version_number);
7186       fetch c_bkp_row into l_row_id;
7187       --
7188       if c_bkp_row%notfound
7189       then
7190         --
7191         close c_bkp_row;
7192         --
7193         insert into BEN_LE_CLSN_N_RSTR(
7194         bkup_tbl_typ_cd,
7195         bkup_tbl_id,
7196         elig_flag,
7197         elig_strt_dt,
7198         elig_thru_dt,
7199         inelg_rsn_cd,
7200         per_in_ler_id,
7201         business_group_id,
7202         object_version_number
7203         )
7204         values (
7205         'BEN_CBR_QUALD_BNF',
7206         l_cqb_rec.cbr_quald_bnf_id,
7207         l_cqb_rec.quald_bnf_flag,
7208         l_cqb_rec.cbr_elig_perd_strt_dt,
7209         l_cqb_rec.cbr_elig_perd_end_dt,
7210         l_cqb_rec.cbr_inelg_rsn_cd,
7211         p_per_in_ler_id,
7212         l_cqb_rec.business_group_id,
7213         l_object_version_number
7214         );
7215       --
7216      else
7217       --
7218       close c_bkp_row;
7219       --
7220       update BEN_LE_CLSN_N_RSTR set
7221         elig_flag = l_cqb_rec.quald_bnf_flag,
7222         elig_strt_dt = l_cqb_rec.cbr_elig_perd_strt_dt,
7223         elig_thru_dt = l_cqb_rec.cbr_elig_perd_end_dt,
7224         inelg_rsn_cd = l_cqb_rec.cbr_inelg_rsn_cd,
7225         business_group_id = l_cqb_rec.business_group_id
7226       where rowid = l_row_id;
7227      end if;
7228     end loop;
7229     --
7230 
7231   else
7232     fnd_message.set_name('BEN','BEN_92535_UNKNOWN_DELETE_RTN');
7233     fnd_message.set_token('PROC',l_package);
7234     fnd_message.set_token('ROUTINE',p_routine);
7235     fnd_message.set_token('PER_IN_LER_ID',to_char(p_per_in_ler_id));
7236     fnd_message.set_token('BG_ID',to_char(p_business_group_id));
7237     fnd_message.set_token('EFFECTIVE_DATE',to_char(p_effective_date));
7238     raise ben_manage_life_events.g_record_error;
7239 
7240   end if;
7241   --
7242   hr_utility.set_location ('End of '||p_routine,10);
7243   hr_utility.set_location ('Leaving '||l_package,10);
7244   --
7245 exception
7246   when others then
7247     --
7251     g_bolfe_effective_date:=null;
7248     -- null out to prevent bleeding.
7249     -- also do this in the error handler.
7250     --
7252     --
7253     -- Handle closing of cursors in case of exception in delete routines
7254     --
7255     if c_ben_elig_cvrd_dpnt_f%isopen then
7256       --
7257       close c_ben_elig_cvrd_dpnt_f;
7258       --
7259     end if;
7260     --
7261     if c_ben_elig_per_f%isopen then
7262       --
7263       close c_ben_elig_per_f;
7264       --
7265     end if;
7266     --
7267     if c_ben_elig_per_opt_f%isopen then
7268       --
7269       close c_ben_elig_per_opt_f;
7270       --
7271     end if;
7272     --
7273     if c_ben_prtt_prem_f%isopen then
7274       --
7275       close c_ben_prtt_prem_f;
7276       --
7277     end if;
7278     --
7279     if c_ben_pl_bnf_f%isopen then
7280       --
7281       close c_ben_pl_bnf_f;
7282       --
7283     end if;
7284     --
7285     if c_ben_prmry_care_prvdr_f%isopen then
7286       --
7287       close c_ben_prmry_care_prvdr_f;
7288       --
7289     end if;
7290     --
7291     if c_ben_prtt_rt_val%isopen then
7292       --
7293       close c_ben_prtt_rt_val;
7294       --
7295     end if;
7296     --
7297     if c_prv_of_previous_pil%isopen then
7298       --
7299       close c_prv_of_previous_pil;
7300       --
7301     end if;
7302     --
7303     if c_ben_prtt_enrt_rslt_f%isopen then
7304       --
7305       close c_ben_prtt_enrt_rslt_f;
7306       --
7307     end if;
7308     --
7309     if c_ben_pil_elctbl_chc_popl%isopen then
7310       --
7311       close c_ben_pil_elctbl_chc_popl;
7312       --
7313     end if;
7314     --
7315     raise;
7316     --
7317 end delete_routine;
7318 
7319 --
7320 -- self-service wrapper to run backout
7321 --
7322 procedure back_out_life_events_ss
7323   (p_per_in_ler_id         in number,
7324    p_bckt_per_in_ler_id    in number ,
7325    p_bckt_stat_cd          in varchar2 ,
7326    p_business_group_id     in number,
7327    p_effective_date        in date) is
7328   --
7329 begin
7330  back_out_life_events
7331   (p_per_in_ler_id         =>p_per_in_ler_id,
7332    p_bckt_per_in_ler_id    =>p_bckt_per_in_ler_id,
7333    p_bckt_stat_cd          =>p_bckt_stat_cd,
7334    p_business_group_id     =>p_business_group_id,
7335    p_effective_date        =>p_effective_date);
7336 --
7337 commit;
7338 --
7339 exception
7340   when others then
7341     fnd_msg_pub.add;
7342 --
7343 end back_out_life_events_ss;
7344 --
7345 end ben_back_out_life_event;