DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_BACK_OUT_LIFE_EVENT

Source


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