DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_EVALUATE_ELIG_CONC

Source


1 package body ben_evaluate_elig_conc as
2 /* $Header: benunvel.pkb 120.1.12010000.2 2008/08/05 14:55:10 ubhat ship $ */
3 --
4 /* ============================================================================
5 *    Name
6 *       Eligibility Engine Concurrent Manager Processes
7 *
8 *    Purpose
9 *       This package simply houses the concurrent manager and multi-thread
10 *       processes for Eligibility Engine
11 *
12 *    History
13 *      Date        Who        Version    What?
14 *      ---------   ---------  -------    --------------------------------------
15 *      08-jul-2004 mmudigon   115.0      Created
16 *      13-jun-2005 mmudigon   115.1      Added business_group_id to where clause
17 *                                        of cursor c_ebo
18 *      01-Dec-06   rtagarra   115.2      Bug 5662220 :Added check so that when there is no condition for a person
19 *					 in person_selection_rule then skip the person.
20 * -----------------------------------------------------------------------------
21 */
22 --
23 -- Global cursor and variables declaration
24 --
25 g_package                 varchar2(80) := 'ben_evaluate_elig_conc';
26 g_persons_processed       number(9) := 0;
27 g_persons_ended           number(9) := 0;
28 g_persons_passed          number(9) := 0;
29 g_persons_errored         number(9) := 0;
30 g_max_errors_allowed      number(9) := 200;
31 g_rec                     ben_type.g_report_rec;
32 --
33 --
34 -- ============================================================================
35 --                        << Procedure: Do_Multithread >>
36 --  Description:
37 --  	this procedure is called from 'process'.  It calls the back-out routine.
38 -- ============================================================================
39 procedure do_multithread
40              (errbuf                  out nocopy    varchar2
41              ,retcode                 out nocopy    number
42              ,p_validate              in     varchar2 default 'N'
43              ,p_benefit_action_id     in     number
44              ,p_thread_id             in     number
45              ,p_effective_date        in     varchar2
46              ,p_business_group_id     in     number
47              ,p_person_id             in     number
48              ,p_assignment_type       in     varchar2
49              ,p_elig_obj_type         in     varchar2
50              ,p_elig_obj_id           in     number) is
51   --
52   -- Local variable declaration
53   --
54   l_proc                   varchar2(80) := g_package||'.do_multithread';
55   l_person_id              ben_person_actions.person_id%type;
56   l_person_action_id       ben_person_actions.person_action_id%type;
57   l_object_version_number  ben_person_actions.object_version_number%type;
58   l_range_id               ben_batch_ranges.range_id%type;
59   l_record_number          number := 0;
60   l_start_person_action_id number := 0;
61   l_end_person_action_id   number := 0;
62   l_actn                   varchar2(80);
63   l_cnt                    number(5):= 0;
64   l_chunk_size             number(15);
65   l_threads                number(15);
66   l_effective_date         date;
67   l_eligible               boolean;
68   l_commit                 number;
69   --
70   -- Cursors declaration
71   --
72   Cursor c_range_thread is
73     Select ran.range_id
74           ,ran.starting_person_action_id
75           ,ran.ending_person_action_id
76     From   ben_batch_ranges ran
77     Where  ran.range_status_cd = 'U'
78     And    ran.BENEFIT_ACTION_ID  = P_BENEFIT_ACTION_ID
79     And    rownum < 2
80     For    update of ran.range_status_cd;
81   --
82   cursor c_person_thread is
83     select ben.person_id,
84            ben.person_action_id
85     from   ben_person_actions ben
86     where  ben.benefit_action_id = p_benefit_action_id
87     and    ben.action_status_cd not in ('P','E')
88     and    ben.person_action_id
89            between l_start_person_action_id
90            and     l_end_person_action_id
91     order  by ben.person_action_id;
92   --
93   Cursor c_parameter is
94     Select *
95     From   ben_benefit_actions ben
96     Where  ben.benefit_action_id = p_benefit_action_id;
97   --
98   l_parm c_parameter%rowtype;
99   --
100   cursor c_person is
101     select ppf.*
102     from   per_all_people_f ppf
103     where  ppf.person_id = l_person_id
104       and  business_group_id = p_business_group_id
105     and    nvl(l_effective_date,trunc(sysdate))
106            between ppf.effective_start_date
107            and     ppf.effective_end_date;
108 
109   l_per_rec       per_all_people_f%rowtype;
110   l_per_dummy_rec per_all_people_f%rowtype;
111 
112   cursor c_ebo is
113   select elig_obj_id
114     from ben_elig_obj_f
115    where (p_elig_obj_id is null or
116           elig_obj_id = p_elig_obj_id)
117      and l_effective_date between effective_start_date
118      and effective_end_date
119      and business_group_id = p_business_group_id
120      and table_name = p_elig_obj_type;
121   l_ebo_rec c_ebo%rowtype;
122 
123 Begin
124   --
125   hr_utility.set_location ('Entering '||l_proc,10);
126   --
127   fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
128   fnd_message.set_token('PROC','dt_fndate.change_ses_date');
129   dt_fndate.change_ses_date
130       (p_ses_date => l_effective_date,
131        p_commit   => l_commit);
132   --
133   l_effective_date:=trunc(fnd_date.canonical_to_date(p_effective_date));
134   --
135   fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
136   fnd_message.set_token('PROC','benutils.get_parameter');
137   benutils.get_parameter(p_business_group_id  => p_business_group_id
138                         ,p_batch_exe_cd       => 'BENUNVEL'
139                         ,p_threads            => l_threads
140                         ,p_chunk_size         => l_chunk_size
141                         ,p_max_errors         => g_max_errors_allowed);
142   --
143   fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
144   fnd_message.set_token('PROC','ben_env_object.init');
145   ben_env_object.init(p_business_group_id => p_business_group_id,
146                       p_effective_date    => l_effective_date,
147                       p_thread_id         => p_thread_id,
148                       p_chunk_size        => l_chunk_size,
149                       p_threads           => l_threads,
150                       p_max_errors        => g_max_errors_allowed,
151                       p_benefit_action_id => p_benefit_action_id);
152   --
153   -- Copy benefit action id to global in benutils package
154   --
155   benutils.g_benefit_action_id := p_benefit_action_id;
156   benutils.g_thread_id         := p_thread_id;
157   g_persons_errored            := 0;
158   g_persons_processed          := 0;
159   --
160   open c_parameter;
161     --
162     fetch c_parameter into l_parm;
163     --
164   close c_parameter;
165   --
166   fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
167   fnd_message.set_token('PROC','ben_batch_utils.print_parameters');
168   ben_batch_utils.print_parameters
169           (p_thread_id                => p_thread_id
170           ,p_benefit_action_id        => p_benefit_action_id
171           ,p_validate                 => p_validate
172           ,p_business_group_id        => p_business_group_id
173           ,p_person_id                => p_person_id
174           ,p_effective_date           => l_effective_date
175           ,p_person_selection_rule_id => l_parm.person_selection_rl
176           ,p_organization_id          => l_parm.organization_id
177           ,p_benfts_grp_id            => l_parm.benfts_grp_id
178           ,p_location_id              => l_parm.location_id
179           ,p_legal_entity_id          => l_parm.legal_entity_id);
180   --
181   -- While loop to only try and fetch records while they exist
182   -- we always try and fetch the size of the chunk, if we get less
183   -- then we know that the process is finished so we end the while loop.
184   -- The process is as follows :
185   -- 1) Lock the rows that are not processed
186   -- 2) Grab as many rows as we can upto the chunk size
187   -- 3) Put each row into the person cache.
188   -- 4) Process the person cache
189   -- 5) Go to number 1 again.
190   --
191   hr_utility.set_location('getting range',10);
192   --
193   Loop
194     --
195     open c_range_thread;
196       --
197       fetch c_range_thread into l_range_id
198                                ,l_start_person_action_id
199                                ,l_end_person_action_id;
200       hr_utility.set_location('doing range fetch',10);
201       --
202       if c_range_thread%notfound then
203         --
204         hr_utility.set_location('range not Found',10);
205         --
206         exit;
207         --
208       end if;
209       --
210       hr_utility.set_location('range Found',10);
211       --
212     close c_range_thread;
213     --
214     update ben_batch_ranges ran
215     set    ran.range_status_cd = 'P'
216     where  ran.range_id = l_range_id;
217     --
218     commit;
219     --
220     -- Get person who are in the range
221     --
222     open c_person_thread;
223       --
224       loop
225         --
226         fetch c_person_thread into l_person_id,
227                                    l_person_action_id;
228         hr_utility.set_location('person id'||l_person_id,10);
229         --
230         exit when c_person_thread%notfound;
231         --
232         savepoint last_place;
233         benutils.set_cache_record_position;
234         --
235         l_per_rec := l_per_dummy_rec;
236         open c_person;
237         fetch c_person into l_per_rec;
238         close c_person;
239         --
240         begin
241           --
242           hr_utility.set_location('Before open',10);
243               --
244           open c_ebo;
245           loop
246              fetch c_ebo into l_ebo_rec;
247              if c_ebo%notfound then
248                 exit;
249              end if;
250 
251              ben_per_asg_elig.eligible
252              (p_person_id             => l_person_id
253              ,p_assignment_type       => p_assignment_type
254              ,p_elig_obj_id           => l_ebo_rec.elig_obj_id
255              ,p_effective_date        => l_effective_date
256              ,p_business_group_id     => p_business_group_id
257              ,p_save_results          => true
258              );
259           end loop;
260           close c_ebo;
261 
262           g_rec.rep_typ_cd := 'LFBO';
263           g_rec.person_id := l_person_id;
264           benutils.write(p_rec => g_rec);
265           --
266           -- If we get here it was successful.
267           --
268           update ben_person_actions
269               set   action_status_cd = 'P'
270               where person_id = l_person_id
271               and   benefit_action_id = p_benefit_action_id;
272           --
273           benutils.write(l_per_rec.full_name||' processed successfully');
274           g_persons_processed := g_persons_processed + 1;
275           --
276         exception
277           --
278           when others then
279             --
280             hr_utility.set_location('Super Error exception level',10);
281             hr_utility.set_location(sqlerrm,10);
282             rollback to last_place;
283             benutils.rollback_cache;
284             --
285             update ben_person_actions
286               set   action_status_cd = 'E'
287               where person_id = l_person_id
288               and   benefit_action_id = p_benefit_action_id;
289             --
290             commit;
291             --
292             g_persons_errored := g_persons_errored + 1;
293             g_rec.rep_typ_cd := 'ERROR_LF';
294             g_rec.person_id := l_person_id;
295             g_rec.national_identifier := l_per_rec.national_identifier;
296             g_rec.error_message_code := benutils.get_message_name;
297             g_rec.text := fnd_message.get;
298 
299             hr_utility.set_location('Error Message '||g_rec.text,10);
300             benutils.write(l_per_rec.full_name||' processed unsuccessfully');
301             benutils.write(g_rec.text);
302             benutils.write(p_rec => g_rec);
303             --
304             hr_utility.set_location('Max Errors = '||g_max_errors_allowed,10);
305             hr_utility.set_location('Num Errors = '||g_persons_errored,10);
306             if g_persons_errored > g_max_errors_allowed then
307               --
308               fnd_message.set_name('BEN','BEN_92431_BENBOCON_ERROR_LIMIT');
309               benutils.write(p_text => fnd_message.get);
310               --
311               raise;
312               --
313             end if;
314             --
315         end;
316         --
317         hr_utility.set_location('Closing c_person_thread',10);
318         --
319       end loop;
320       --
321     close c_person_thread;
322     --
323     -- Commit chunk
324     --
325     if p_validate = 'Y' then
326       --
327       hr_utility.set_location('Rolling back transaction ',10);
328       --
329       rollback;
330       --
331     end if;
332     --
333     fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
334     fnd_message.set_token('PROC','benutils.write_table_and_file');
335     benutils.write_table_and_file(p_table => TRUE, p_file  => TRUE);
336     commit;
337     --
338   end loop;
339   --
340   fnd_message.set_name('BEN','BEN_91333_CALLING_PROC');
341   fnd_message.set_token('PROC','benbatch_utils.write_logfile');
342   ben_batch_utils.write_logfile(p_num_pers_processed => g_persons_processed
343                                ,p_num_pers_errored   => g_persons_errored);
344   --
345   commit;
346   --
347   hr_utility.set_location ('Leaving '||l_proc,70);
348   --
349 Exception
350   --
351   When others then
352     --
353     hr_utility.set_location('Super Error',10);
354     hr_utility.set_location(sqlerrm,10);
355     hr_utility.set_location('Super Error',10);
356     rollback;
357     benutils.rollback_cache;
358     --
359     g_rec.rep_typ_cd := 'FATAL';
360     g_rec.text := fnd_message.get;
361     g_rec.person_id := l_person_id;
362     --
363     benutils.write(p_text => g_rec.text);
364     benutils.write(p_rec => g_rec);
365     --
366     ben_batch_utils.write_logfile(p_num_pers_processed => g_persons_processed
367                                  ,p_num_pers_errored   => g_persons_errored);
368     --
369     benutils.write_table_and_file(p_table => TRUE, p_file  => TRUE);
370     --
371     commit;
372     --
373     fnd_message.raise_error;
374     --
375 End do_multithread;
376 -- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
377 --                   << Procedure: Restart >>
378 -- *****************************************************************
379 --
380 procedure restart (errbuf                 out nocopy varchar2
381                   ,retcode                out nocopy number
382                   ,p_benefit_action_id    in  number) is
383   --
384   -- Cursor Declaration
385   --
386   cursor c_parameters is
387     Select process_date
388           ,mode_cd
389           ,validate_flag
390           ,person_id
391           ,pl_id
392           ,concat_segs
393           ,business_group_id
394           ,person_selection_rl
395           ,los_det_to_use_cd
396           ,organization_id
397           ,location_id
398           ,benfts_grp_id
399           ,legal_entity_id
400           ,debug_messages_flag
401     From  ben_benefit_actions ben
402     Where ben.benefit_action_id = p_benefit_action_id;
403   --
404   -- Local Variable declaration.
405   --
406   l_proc        varchar2(80) := g_package||'.restart';
407   l_parameters	c_parameters%rowtype;
408   l_errbuf      varchar2(80);
409   l_retcode     number;
410   --
411 Begin
412   --
413   hr_utility.set_location ('Entering '||l_proc,10);
414   --
415   -- get the parameters for a previous run and do a restart
416   --
417   open c_parameters;
418     --
419     fetch c_parameters into l_parameters;
420     If c_parameters%notfound then
421       --
422       fnd_message.set_name('BEN','BEN_91710_RESTRT_PARMS_NOT_FND');
423       fnd_message.raise_error;
424       --
425     End if;
426     --
427   close c_parameters;
428   --
429   -- Call process procedure with parameters for restart
430   --
431   process(errbuf                     => l_errbuf
432          ,retcode                    => l_retcode
433          ,p_benefit_action_id        => p_benefit_action_id
434          ,p_effective_date           => fnd_date.date_to_canonical
435                                         (l_parameters.process_date)
436          ,p_validate                 => l_parameters.validate_flag
437          ,p_business_group_id        => l_parameters.business_group_id
438          ,p_person_id                => l_parameters.person_id
439          ,p_assignment_type          => l_parameters.los_det_to_use_cd
440          ,p_elig_obj_id              => l_parameters.pl_id
441          ,p_elig_obj_type            => l_parameters.concat_segs
442          ,p_organization_id          => l_parameters.organization_id
443          ,p_location_id              => l_parameters.location_id
444          ,p_benfts_grp_id            => l_parameters.benfts_grp_id
445          ,p_legal_entity_id          => l_parameters.legal_entity_id
446          ,p_person_selection_rule_id => l_parameters.person_selection_rl
447          ,p_debug_messages           => l_parameters.debug_messages_flag);
448   --
449   hr_utility.set_location ('Leaving '||l_proc,70);
450   --
451 end restart;
452 --
453 -- *************************************************************************
454 -- *                          << Procedure: Process >>
455 -- *************************************************************************
456 --  This is what is called from the concurrent manager screen
457 --
458 procedure process(errbuf                     out nocopy    varchar2
459                  ,retcode                    out nocopy    number
460                  ,p_benefit_action_id        in     number   default null
461                  ,p_effective_date           in     varchar2
462                  ,p_validate                 in     varchar2 default 'N'
463                  ,p_business_group_id        in     number
464                  ,p_person_id                in     number
465                  ,p_assignment_type          in     varchar2
466                  ,p_elig_obj_type            in     varchar2
467                  ,p_elig_obj_id              in     number
468                  ,p_organization_id          in     number   default null
469                  ,p_location_id              in     number   default null
470                  ,p_benfts_grp_id            in     number   default null
471                  ,p_legal_entity_id          in     number   default null
472                  ,p_person_selection_rule_id in     number   default null
473                  ,p_debug_messages           in     varchar2 default 'N') is
474   --
475   l_effective_date         date;
476   l_from_ocrd_date         date;
477   l_to_ocrd_date           date;
478   l_no_one_to_process      exception;
479   --
480   -- Cursors declaration.
481   --
482   cursor c_person is
483   select ppf.person_id
484     from per_all_people_f ppf
485    where ppf.business_group_id = p_business_group_id
486      and l_effective_date between ppf.effective_start_date
487      and ppf.effective_end_date
488      and (p_person_id is null or
489           ppf.person_id = p_person_id)
490      and (p_organization_id is null
491           or exists (select null
492                       from   per_all_assignments_f paa
493                       where  paa.person_id = ppf.person_id
494                       and    l_effective_date
495                              between paa.effective_start_date
496                              and     paa.effective_end_date
497                       and    paa.business_group_id = ppf.business_group_id
498                       and    paa.primary_flag = 'Y'
499                       and    paa.organization_id = p_organization_id))
500      and   (p_location_id is null
501           or exists (select null
502                      from   per_all_assignments_f paa
503                      where  paa.person_id = ppf.person_id
504                      and    l_effective_date
505                             between paa.effective_start_date
506                             and     paa.effective_end_date
507                      and    paa.business_group_id = ppf.business_group_id
508                      and    paa.primary_flag = 'Y'
509                      and    paa.location_id = p_location_id))
510     and   (p_benfts_grp_id is null
511           or exists (select null
512                      from   per_all_people_f pap
513                      where  pap.person_id = ppf.person_id
514                      and    pap.business_group_id = ppf.business_group_id
515                      and    l_effective_date
516                             between pap.effective_start_date
517                             and     pap.effective_end_date
518                      and    pap.benefit_group_id = p_benfts_grp_id))
519     and   (p_legal_entity_id is null
520           or exists (select null
521                      from   per_assignments_f paf,
522                             hr_soft_coding_keyflex soft
523                      where  paf.person_id = ppf.person_id
524                      and    paf.assignment_type <> 'C'
525                      and    l_effective_date
526                             between paf.effective_start_date
527                             and     paf.effective_end_date
528                      and    paf.business_group_id = ppf.business_group_id
529                      and    paf.primary_flag = 'Y'
530                      and    soft.soft_coding_keyflex_id = paf.soft_coding_keyflex_id
531                      and    soft.segment1 = to_char(p_legal_entity_id))) ;
532 
533   --
534   -- local variable declaration.
535   --
536   l_request_id             number;
537   l_proc                   varchar2(80) := g_package||'.process';
538   l_benefit_action_id      ben_benefit_actions.benefit_action_id%type;
539   l_object_version_number  ben_benefit_actions.object_version_number%type;
540   l_person_id              per_people_f.person_id%type;
541   l_person_action_id       ben_person_actions.person_action_id%type;
542   l_ler_id                 ben_ler_f.ler_id%type;
543   l_range_id               ben_batch_ranges.range_id%type;
544   l_chunk_size             number := 20;
545   l_threads                number := 1;
546   l_start_person_action_id number := 0;
547   l_end_person_action_id   number := 0;
548   l_prev_person_id         number := 0;
549   rl_ret                   char(1);
550   skip                     boolean;
551   l_person_cnt             number := 0;
552   l_cnt                    number := 0;
553   l_num_range              number := 0;
554   l_chunk_num              number := 1;
555   l_num_row                number := 0;
556   l_commit number;
557   --
558 Begin
559   --
560   hr_utility.set_location ('Entering '||l_proc,10);
561   --
562   l_effective_date:=trunc(fnd_date.canonical_to_date(p_effective_date));
563   --
564   dt_fndate.change_ses_date
565       (p_ses_date => l_effective_date,
566        p_commit   => l_commit);
567   --
568   -- Get chunk_size and Thread values for multi-thread process.
569   --
570   ben_batch_utils.ini;
571   ben_batch_utils.ini(p_actn_cd => 'PROC_INFO');
572   --
573   benutils.get_parameter(p_business_group_id  => p_business_group_id
574                         ,p_batch_exe_cd       => 'BENUNVEL'
575                         ,p_threads            => l_threads
576                         ,p_chunk_size         => l_chunk_size
577                         ,p_max_errors         => g_max_errors_allowed);
578   --
579   -- Create benefit actions parameters in the benefit action table.
580   -- Do not create if a benefit action already exists, in other words
581   -- we are doing a restart.
582   --
583   If p_benefit_action_id is null then
584     hr_utility.set_location('l_effective_date '||l_effective_date,10);
585     hr_utility.set_location('p_business_group_id '||p_business_group_id,10);
586     hr_utility.set_location('p_debug_messages '||p_debug_messages,10);
587     hr_utility.set_location('p_validate '||p_validate,10);
588     hr_utility.set_location('p_person_id '||p_person_id,10);
589     --
590     ben_benefit_actions_api.create_perf_benefit_actions
591       (p_validate_flag          => p_validate
592       ,p_benefit_action_id      => l_benefit_action_id
593       ,p_process_date           => l_effective_date
594       ,p_mode_cd                => 'S'
595       ,p_derivable_factors_flag => 'N'
596       ,p_person_id              => p_person_id
597       ,p_pl_id                  => p_elig_obj_id
598       ,p_concat_segs            => p_elig_obj_type
599       ,p_person_type_id         => null
600       ,p_business_group_id      => p_business_group_id
601       ,p_no_programs_flag       => 'N'
602       ,p_no_plans_flag          => 'N'
603       ,p_audit_log_flag         => 'Y'
604       ,p_los_det_to_use_cd      => p_assignment_type
605       ,p_person_selection_rl    => p_person_selection_rule_id
606       ,p_organization_id        => p_organization_id
607       ,p_benfts_grp_id          => p_benfts_grp_id
608       ,p_location_id            => p_location_id
609       ,p_pstl_zip_rng_id        => null
610       ,p_rptg_grp_id            => null
611       ,p_eligy_prfl_id          => null
612       ,p_legal_entity_id        => p_legal_entity_id
613       ,p_debug_messages_flag    => 'N'
614       ,p_object_version_number  => l_object_version_number
615       ,p_effective_date         => l_effective_date
616       ,p_request_id             => fnd_global.conc_request_id
617       ,p_program_application_id => fnd_global.prog_appl_id
618       ,p_program_id             => fnd_global.conc_program_id
619       ,p_program_update_date    => sysdate);
620     --
621     benutils.g_benefit_action_id := l_benefit_action_id;
622     --
623     -- Delete/clear ranges from ben_batch_ranges table
624     --
625     Delete from ben_batch_ranges
626     Where  benefit_action_id = l_benefit_action_id;
627     --
628     -- Now lets create person actions for all the people we are going to
629     -- process in the Back-out life event run
630     --
631     open c_person;
632       --
633       l_person_cnt := 0;
634       l_cnt := 0;
635       --
636       loop
637         --
638         fetch c_person into l_person_id;
639         exit when c_person%notfound;
640         --
641         l_cnt := l_cnt + 1;
642         --
643         skip := false;
644         --
645         If p_person_selection_rule_id is not NULL then
646           --
647           rl_ret := ben_batch_utils.person_selection_rule
648                       (p_person_id               => l_person_id
649                       ,p_business_group_id       => p_business_group_id
650                       ,p_person_selection_rule_id=> p_person_selection_rule_id
651                       ,p_effective_date          => l_effective_date);
652           --
653 --          If rl_ret = 'N' then -- Bug 5662220
654           If rl_ret <> 'Y' then
655             --
656             skip := TRUE;
657             --
658           End if;
659           --
660         End if;
661         --
662         -- Store person_id into person actions table.
663         --
664         If (not skip) then
665           --
666           Ben_person_actions_api.create_person_actions
667             (p_validate              => false
668             ,p_person_action_id      => l_person_action_id
669             ,p_person_id             => l_person_id
670             ,p_benefit_action_id     => l_benefit_action_id
671             ,p_action_status_cd      => 'U'
672             ,p_chunk_number          => l_chunk_num
673             ,p_object_version_number => l_object_version_number
674             ,p_effective_date        => l_effective_date);
675           --
676           l_num_row := l_num_row + 1;
677           l_person_cnt := l_person_cnt + 1;
678           l_end_person_action_id := l_person_action_id;
679           --
680           If l_num_row = 1 then
681             --
682             l_start_person_action_id := l_person_action_id;
683             --
684           End if;
685           --
686           If l_num_row = l_chunk_size then
687             --
688             -- Create a range of data to be multithreaded.
689             --
690             Ben_batch_ranges_api.create_batch_ranges
691               (p_validate                  => false
692               ,p_benefit_action_id         => l_benefit_action_id
693               ,p_range_id                  => l_range_id
694               ,p_range_status_cd           => 'U'
695               ,p_starting_person_action_id => l_start_person_action_id
696               ,p_ending_person_action_id   => l_end_person_action_id
697               ,p_object_version_number     => l_object_version_number
698               ,p_effective_date            => l_effective_date);
699             --
700             l_start_person_action_id := 0;
701             l_end_person_action_id := 0;
702             l_num_row  := 0;
703             l_num_range := l_num_range + 1;
704             --
705           End if;
706           --
707         End if;
708         --
709       End loop;
710       --
711     close c_person;
712     --
713     hr_utility.set_location('l_num_row='||to_char(l_num_row),18);
714     --
715     If l_num_row <> 0 then
716       --
717       Ben_batch_ranges_api.create_batch_ranges
718         (p_validate                  => false
719         ,p_benefit_action_id         => l_benefit_action_id
720         ,p_range_id                  => l_range_id
721         ,p_range_status_cd           => 'U'
722         ,p_starting_person_action_id => l_start_person_action_id
723         ,p_ending_person_action_id   => l_end_person_action_id
724         ,p_object_version_number     => l_object_version_number
725         ,p_effective_date            => l_effective_date);
726       --
727       l_num_range := l_num_range + 1;
728       --
729     End if;
730     --
731   Else
732     --
733     l_benefit_action_id := p_benefit_action_id;
734     --
735     Ben_batch_utils.create_restart_person_actions
736      (p_benefit_action_id  => p_benefit_action_id
737      ,p_effective_date     => l_effective_date
738      ,p_chunk_size         => l_chunk_size
739      ,p_threads            => l_threads
740      ,p_num_ranges         => l_num_range
741      ,p_num_persons        => l_person_cnt);
742     --
743   End if;
744   --
745   If l_num_range > 1 then
746     --
747     For l_count in 1..least(l_threads,l_num_range)-1 loop
748       --
749       l_request_id := fnd_request.submit_request
750                        (application => 'BEN'
751                        ,program     => 'BENUNELTHRD'
752                        ,description => NULL
753                        ,sub_request => FALSE
754                        ,argument1   => p_validate
755                        ,argument2   => l_benefit_action_id
756                        ,argument3   => l_count
757                        ,argument4   => p_effective_date
758                        ,argument5   => p_business_group_id
759                        ,argument6   => p_person_id
760                        ,argument7   => p_assignment_type
761                        ,argument8   => p_elig_obj_type
762                        ,argument9   => p_elig_obj_id);
763       --
764       -- Store the request id of the concurrent request
765       --
766       ben_batch_utils.g_num_processes := ben_batch_utils.g_num_processes + 1;
767       ben_batch_utils.g_processes_tbl(ben_batch_utils.g_num_processes)
768         := l_request_id;
769       --
770     End loop;
771     --
772     commit;
773     --
774   Elsif (l_num_range = 0 ) then
775     --
776     Ben_batch_utils.print_parameters
777      (p_thread_id                => 99
778      ,p_benefit_action_id        => l_benefit_action_id
779      ,p_validate                 => p_validate
780      ,p_business_group_id        => p_business_group_id
781      ,p_effective_date           => l_effective_date
782      ,p_person_selection_rule_id => p_person_selection_rule_id
783      ,p_person_id                => p_person_id
784      ,p_organization_id          => p_organization_id
785      ,p_benfts_grp_id            => p_benfts_grp_id
786      ,p_location_id              => p_location_id
787      ,p_legal_entity_id          => p_legal_entity_id);
788     --
789     fnd_message.set_name('BEN','BEN_91769_NOONE_TO_PROCESS');
790     fnd_message.set_token('PROC' , l_proc);
791     raise l_no_one_to_process;
792   End if;
793   --
794   do_multithread(errbuf               => errbuf
795                 ,retcode              => retcode
796                 ,p_validate           => p_validate
797                 ,p_benefit_action_id  => l_benefit_action_id
798                 ,p_thread_id          => l_threads+1
799                 ,p_effective_date     => p_effective_date
800                 ,p_business_group_id  => p_business_group_id
801                 ,p_person_id          => p_person_id
802                 ,p_assignment_type    => p_assignment_type
803                 ,p_elig_obj_type      => p_elig_obj_type
804                 ,p_elig_obj_id        => p_elig_obj_id);
805   --
806   ben_batch_utils.check_all_slaves_finished(p_rpt_flag => TRUE);
807   ben_batch_utils.end_process(p_benefit_action_id => l_benefit_action_id
808                              ,p_person_selected   => l_person_cnt
809                              ,p_business_group_id => p_business_group_id);
810   hr_utility.set_location ('Leaving '||l_proc,70);
811   --
812 Exception
813   when l_no_one_to_process then
814     benutils.write(p_text => fnd_message.get);
815     benutils.write_table_and_file(p_table => TRUE, p_file  => TRUE);
816   when others then
817      --
818      hr_utility.set_location('Super Error',10);
819      rollback;
820      benutils.write(p_text => fnd_message.get);
821      benutils.write(p_text => sqlerrm);
822      benutils.write_table_and_file(p_table => TRUE, p_file  => TRUE);
823      If (l_num_range > 0) then
824        ben_batch_utils.check_all_slaves_finished(p_rpt_flag => TRUE);
825        ben_batch_utils.end_process(p_benefit_action_id => l_benefit_action_id
826                                   ,p_person_selected   => l_person_cnt
827                                   ,p_business_group_id => p_business_group_id
828        ) ;
829      End if;
830      fnd_message.raise_error;
831 End process;
832 --
833 end ben_evaluate_elig_conc;