DBA Data[Home] [Help]

PACKAGE BODY: APPS.PSB_HR_EXTRACT_DATA_PVT

Source


1 PACKAGE BODY PSB_HR_EXTRACT_DATA_PVT AS
2 /* $Header: PSBVHRXB.pls 120.34 2006/02/24 19:24:04 matthoma ship $ */
3 
4   G_PKG_NAME CONSTANT VARCHAR2(30):= 'PSB_HR_EXTRACT_DATA_PVT';
5   g_dbug      VARCHAR2(2000);
6 
7   TYPE TokNameArray IS TABLE OF VARCHAR2(100) INDEX BY BINARY_INTEGER;
8 
9   -- TokValArray contains values for all tokens
10 
11   TYPE TokValArray IS TABLE OF VARCHAR2(1000) INDEX BY BINARY_INTEGER;
12   -- Number of Message Tokens
13 
14   no_msg_tokens       NUMBER := 0;
15 
16   -- Message Token Name
17 
18   msg_tok_names       TokNameArray;
19 
20   -- Message Token Value
21 
22   msg_tok_val         TokValArray;
23 
24   PROCEDURE message_token
25   ( tokname  IN  VARCHAR2,
26     tokval   IN  VARCHAR2
27   );
28 
29   PROCEDURE add_message
30   (appname  IN  VARCHAR2,
31    msgname  IN  VARCHAR2);
32   TYPE g_glcostmap_rec_type IS RECORD
33        (gl_account_segment      VARCHAR2(30),
34         payroll_cost_segment    VARCHAR2(30));
35 
36   TYPE g_glcostmap_tbl_type is TABLE OF g_glcostmap_rec_type
37        INDEX BY BINARY_INTEGER;
38 
39   PROCEDURE insert_cost_distribution_row
40   ( p_assignment_id        IN   NUMBER,
41     p_cost_keyflex_id      IN   NUMBER,
42     p_business_group_id    IN   NUMBER,
43     p_costing_level        IN   VARCHAR2,
44     p_index                IN   BINARY_INTEGER,
45     p_proportion           IN   NUMBER,
46     p_start_date           IN   DATE,
47     p_end_date             IN   DATE,
48     p_data_extract_id      IN   NUMBER,
49     p_cost_segments        IN   g_glcostmap_tbl_type,
50     p_chart_of_accounts_id IN   NUMBER
51   );
52 
53   TYPE StatusTypArray IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
54   assign_stat_types       StatusTypArray;
55 
56   PROCEDURE Init
57   ( p_date IN OUT NOCOPY DATE
58   )
59 
60   -- Private API for Initialization
61   AS
62   lsession number;
63   l_cnt number;
64   BEGIN
65     if (p_date is null) then
66        p_date := trunc(sysdate);
67     end if;
68 
69     SELECT USERENV('sessionid') into
70            lsession
71       FROM dual;
72 
73    -- Set up effective Date
74     Select count(*) into l_cnt
75       from fnd_sessions
76      where session_id = lsession
77        and effective_date = p_date;
78 
79     if  (l_cnt = 0 ) then
80         INSERT INTO fnd_sessions
81         (session_id,effective_date)
82         values (lsession,p_date);
83     end if;
84 
85   END;
86 /*---------------------------------------------------------------------------*/
87 
88 
89 /*===========================================================================+
90  |                      PROCEDURE Get_Position_Information                   |
91  +===========================================================================*/
92 PROCEDURE Get_Position_Information
93 ( p_api_version         IN    NUMBER,
94   p_init_msg_list       IN    VARCHAR2 := FND_API.G_FALSE,
95   p_commit              IN    VARCHAR2 := FND_API.G_FALSE,
96   p_validation_level    IN    NUMBER   := FND_API.G_VALID_LEVEL_FULL,
97   p_return_status       OUT   NOCOPY VARCHAR2,
98   p_msg_count           OUT   NOCOPY NUMBER,
99   p_msg_data            OUT   NOCOPY VARCHAR2,
100   p_data_extract_id     IN    NUMBER,
101   -- de by org
102   p_extract_by_org      IN    VARCHAR2,
103   p_extract_method      IN    VARCHAR2,
104   p_id_flex_num         IN    NUMBER,
105   p_date                IN    DATE,
106   p_business_group_id   IN    NUMBER,
107   p_set_of_books_id     IN    NUMBER
108 )
109 IS
110   --
111   l_position_name       varchar2(240);
112   --UTF8 changes for Bug No : 2615261
113   l_employee_name       varchar2(310);
114   l_person_id           number;
115   l_position_ctr        number := 0;
116   l_fin_position_id     number := -1;
117   l_restart_position_id number := 0;
118   prev_person_id        number := -1;
119   prev_position_id      number := -1;
120   l_process_flag        varchar2(1);
121   l_last_update_date    date;
122   l_last_updated_by     number;
123   l_last_update_login   number;
124   l_creation_date       date;
125   l_created_by          number;
126   d_date_end            date;
127   --
128 
129   --
130   -- Variables for retrieving salary details of a position
131   --
132   l_grade_rule_id       number;
133   l_step_id             number;
134   l_salary_type         varchar2(15);
135   l_rate_type           varchar2(10);
136   l_rate_or_payscale_id number;
137   l_grade_step          number;
138   l_grade_spine_id      number;
139   l_pay_basis_id        number;
140   l_pay_basis           varchar2(30);
141   l_sequence            number;
142   l_value               number;
143   l_rate_cnt_flag       varchar2(1);
144   l_session_date        date;
145   l_grade_or_spinal_point_id  number;
146   l_assignment_status_type_id number;
147 
148   l_pos_id_flex_num     number;
149    l_per_index           BINARY_INTEGER;
150    tf                    BOOLEAN;
151    nsegs                 NUMBER;
152    segs                  FND_FLEX_EXT.SegmentArray;
153    possegs               FND_FLEX_EXT.SegmentArray;
154 
155    --
156    l_status              varchar2(1);
157    l_return_status       varchar2(1);
158    l_msg_count           number;
159    l_msg_data            varchar2(1000);
160    l_msg                 varchar2(2000);
161    l_status_count        number := 0;
162    l_assign_stat_cnt     number := 0;
163    -- Start bug no 3902996
164    l_parent_spine_id     NUMBER := 0;
165    -- End bug no 3902996
166 
167    --
168    --
169    -- Cursor to select filled as well as vacant positions. The First sub-query
170    -- pickes up filled positions while the other one picks up vacant ones.
171    --
172 
173   CURSOR l_positions_csr
174   IS
175   SELECT pp.position_id,
176          pp.position_definition_id,
177          pp.organization_id,
178          paf.person_id,
179          paf.primary_flag,
180          paf.assignment_status_type_id,
181          pp.name,
182          pp.business_group_id,
183          pp.date_effective,
184          pp.date_end,
185          pp.entry_grade_id,
186          pp.entry_grade_rule_id,
187          pp.entry_step_id,
188          pp.pay_basis_id,
189          pst.system_type_cd
190   FROM   fnd_sessions             fs,
191          hr_all_positions_f       pp  ,
192          per_shared_types         pst ,
193          per_all_assignments_f    paf ,
194          pay_all_payrolls_f       ppay,
195          per_pay_bases            ppb,
196          per_assignment_status_types past --bug 4020452
197   WHERE  fs.session_id = userenv('sessionid')
198   AND    fs.effective_date between pp.effective_start_date
199                            and pp.effective_end_date
200   AND    pp.business_group_id       = p_business_group_id
201   AND    pp.position_id             > l_restart_position_id
202   AND    ( (l_status_count > 0 and pst.business_group_id = p_business_group_id)
203            or
204            (l_status_count = 0 and pst.business_group_id is null) )
205   AND    pp.availability_status_id  = pst.shared_type_id
206   AND    pst.system_type_cd         in ('PROPOSED','ACTIVE', 'FROZEN')
207   AND    fs.effective_date between paf.effective_start_date
208                            and paf.effective_end_date
209   AND    paf.position_id            = pp.position_id
210   AND    paf.business_group_id      = p_business_group_id
211   AND    paf.assignment_type        = 'E'
212   /*Bug: 2109120 Start*/
213   -- AND        paf.primary_flag           = 'Y'
214   /*Bug: 2109120 End*/
215   AND    fs.effective_date between ppay.effective_start_date
216                            and ppay.effective_end_date
217   AND    ppay.payroll_id            = paf.payroll_id
218   AND    ppay.gl_set_of_books_id    = p_set_of_books_id
219   AND    paf.pay_basis_id           = ppb.pay_basis_id
220 
221   /* bug 4020452 start */
222   AND    paf.assignment_status_type_id = past.assignment_status_type_id
223   AND    past.per_system_status <> 'TERM_ASSIGN'
224   /* bug 4020452 end */
225 
226   /*
227   The following logic is used to restrict the positions for all the selected
228   organizations, if extract by org is enabled.  Otherwise, we will ignore
229   the organizations avaiable in the business group
230   */
231   AND    ( p_extract_by_org = 'N'
232            OR
233 	   (p_extract_by_org = 'Y' and pp.organization_id in
234 	                           (select organization_id
235 	                            from   psb_data_extract_orgs
236 	                            where  data_extract_id = p_data_extract_id
237 	                            and    select_flag = 'Y' )
238            )
239          )
240   UNION ALL
241   SELECT pp.position_id,
242          pp.position_definition_id,
243          pp.organization_id,
244          0,
245          'Y',
246          to_number(NULL),
247          pp.name,
248          pp.business_group_id,
249          pp.date_effective,
250          pp.date_end,
251          pp.entry_grade_id,
252          pp.entry_grade_rule_id,
253          pp.entry_step_id,
254          pp.pay_basis_id,
255          pst.system_type_cd
256   FROM   fnd_sessions             fs,
257          hr_all_positions_f       pp ,
258          per_shared_types         pst
259   WHERE  fs.session_id = userenv('sessionid')
260   AND    fs.effective_date between pp.effective_start_date
261                            and pp.effective_end_date
262   AND    pp.business_group_id       = p_business_group_id
263   AND    pp.position_id             > l_restart_position_id
264   AND    pp.availability_status_id  = pst.shared_type_id
265   AND    ( (l_status_count > 0 and pst.business_group_id = p_business_group_id)
266            OR
267            (l_status_count = 0 and pst.business_group_id is null)
268          )
269   -- for bug 4533884 .removed frozen from the IN clause so that
270   -- vacant frozen positions will not be picked up
271   -- AND    pst.system_type_cd         in ('PROPOSED','ACTIVE','FROZEN')
272   AND    pst.system_type_cd         in ('PROPOSED','ACTIVE')
273   AND    ( (NOT EXISTS
274                ( SELECT 1
275                  FROM   per_all_assignments_f pafx,
276                  -- bug 3777146 added the join with per_assignment_status_types
277                         per_assignment_status_types past
278                  WHERE  fs.session_id = userenv('sessionid')
279                  AND    fs.effective_date between pafx.effective_start_date
280                                           and pafx.effective_end_date
281                  AND pafx.assignment_status_type_id
282                                           = past.assignment_status_type_id
283                  AND    pafx.position_id       = pp.position_id
284                  -- Bug#3265678: This clause picks all occupied positions.
285       		 -- AND pafx.assignment_type <> 'A'
286       		 AND    pafx.assignment_type   = 'E'
287                  AND    past.per_system_status <> 'TERM_ASSIGN'
288                )
289            )
290            OR
291            ( ( pp.position_type <> 'SINGLE')
292              AND
293              ( nvl(pp.fte,1) >
294                ( SELECT sum(nvl(value,1))
295       	         FROM   per_assignment_budget_values_f pab,
296            	        per_all_assignments_f paf,
297                         per_assignment_status_types past
298                  -- bug 4020452 added the join with per_assignment_status_types
299      		 WHERE  fs.session_id = userenv('sessionid')
300                  AND    fs.effective_date between paf.effective_start_date
301                                           and paf.effective_end_date
302                  AND    paf.assignment_status_type_id
303                                           = past.assignment_status_type_id
304                  AND    paf.position_id = pp.position_id
305 		 AND    paf.assignment_type = 'E'
306                  AND    past.per_system_status <> 'TERM_ASSIGN' --bug 4020452
307                  /* For Bug 2891574 start*/
308                  --AND  fs.effective_date between pab.effective_start_date
309                  --     and pab.effective_end_date
310                  AND    pab.effective_start_date(+) <= fs.effective_date
311                  AND    pab.effective_end_date(+) >= fs.effective_date
312                  /* For Bug 2891574 end*/
313        		 AND    pab.assignment_id(+)  = paf.assignment_id
314        		 AND    pab.unit(+) = 'FTE'
315                )
316        	     )
317            )
318          )
319       /*
320       Logic to restrict the positions for all the selected organizations, if
321       extract by org is enabled.  Otherwise, we will ignore organizations
322       avaiable in the business group
323       */
324   AND    ( p_extract_by_org = 'N'
325            OR
326 	   (p_extract_by_org = 'Y' and pp.organization_id in
327 	                           ( select organization_id
328 	                             from psb_data_extract_orgs
329 	                             where data_extract_id = p_data_extract_id
330                                      and select_flag = 'Y'
331                                    )
332            )
333          )
334   ORDER BY 1,3,4 desc;
335 
336   Cursor C_flex_num is
337         select position_structure
338           from per_business_groups
339          where business_group_id = p_business_group_id;
340 
341   Cursor C_pos_segs is
342     select application_column_name
343       from fnd_id_flex_segments_vl
344      where id_flex_code = 'POS'
345        and id_flex_num = l_pos_id_flex_num
346        and enabled_flag = 'Y'
347     order by segment_num;
348 
349   Cursor C_rate_check is
350   Select count(*), parent_spine_id
351     from pay_rates
352    where business_group_id = p_business_group_id
353    -- Start bug no 3902996
354      and parent_spine_id = l_parent_spine_id
355    -- End bug no 3902996
356      and rate_type = 'SP'
357    group by parent_spine_id
358    having count(*) > 1;
359 
360   Cursor C_session is
361      SELECT effective_date
362        FROM FND_SESSIONS
363       WHERE session_id = USERENV('sessionid');
364 
365   Cursor C_grade_spine is
366         SELECT grade_spine_id
367           FROM per_spinal_point_steps
368          WHERE step_id = l_step_id;
369 
370   Cursor C_Pay_Grade is
371     SELECT effective_start_date,effective_end_date,
372            rate_id, grade_or_spinal_point_id, rate_type,
373            maximum,mid_value,minimum,sequence,value
374       FROM PAY_GRADE_RULES
375      WHERE business_group_id = p_business_group_id
376        AND grade_rule_id     = l_grade_rule_id;
377 
378   Cursor  C_payscale is
379      SELECT parent_spine_id
380        FROM PER_SPINAL_POINTS
381       WHERE spinal_point_id = l_grade_or_spinal_point_id
382        AND business_group_id = p_business_group_id;
383 
384   Cursor C_pay_basis is
385     SELECT pay_basis
386       FROM PER_PAY_BASES
387      WHERE pay_basis_id = l_pay_basis_id;
388 
389  --
390  -- Cursor to find the list of assignment_status types
391  -- that correspond to Terminated Assignment Status
392  --
393  /* Bug 4929586 commenting out the below cursor
394  Cursor l_assign_stat_csr is
395    Select assignment_status_type_id
396      from per_assignment_status_types
397     where (business_group_id = p_business_group_id
398        or business_group_id  is null)
399       and PER_SYSTEM_STATUS = 'TERM_ASSIGN'; */
400   --
401   l_api_name            CONSTANT VARCHAR2(30)   := 'Get_Position_Information';
402   l_api_version         CONSTANT NUMBER         := 1.0;
403   --
404 BEGIN
405 
406   -- Standard Start of API savepoint
407 
408   Savepoint Get_Position;
409 
410   -- Standard call to check for call compatibility.
411 
412   if not FND_API.Compatible_API_Call (l_api_version,
413                                       p_api_version,
414                                       l_api_name,
415                                       G_PKG_NAME)
416   then
417     raise FND_API.G_EXC_UNEXPECTED_ERROR;
418   end if;
419 
420   -- Initialize message list if p_init_msg_list is set to TRUE.
421 
422   if FND_API.to_Boolean (p_init_msg_list) then
423      FND_MSG_PUB.initialize;
424   end if;
425 
426   p_return_status := FND_API.G_RET_STS_SUCCESS;
427 
428   -- API body
429 
430   l_last_update_date  := sysdate;
431   l_last_updated_by   := FND_GLOBAL.USER_ID;
432   l_last_update_login := FND_GLOBAL.LOGIN_ID;
433   l_creation_date     := sysdate;
434   l_created_by        := FND_GLOBAL.USER_ID;
435 
436 
437   Check_Reentry
438   (p_api_version              => 1.0  ,
439    p_return_status            => l_return_status,
440    p_msg_count                => l_msg_count,
441    p_msg_data                 => l_msg_data,
442    p_data_extract_id          => p_data_extract_id,
443    p_process                  => 'Positions Interface',
444    p_status                   => l_status,
445    p_restart_id               => l_restart_position_id
446    );
447 
448   if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
449      raise FND_API.G_EXC_ERROR;
450   end if;
451 
452 
453   if (l_status <> 'C') then
454 
455   For C_flex_rec in C_flex_num
456   Loop
457     l_pos_id_flex_num := C_flex_rec.position_structure;
458   End Loop;
459 
460   -- Start bug no 3902996
461   /*l_rate_cnt_flag := 'N';
462 
463   For C_rate_check_rec in C_rate_check
464   Loop
465     l_rate_cnt_flag := 'Y' ;
466     exit;
467   End Loop;*/
468   -- End bug no 3902996
469 
470   -- Process all the positions (filled and vacant both).
471   SELECT count(*) into l_status_count
472     from per_shared_types
473    where business_group_id = p_business_group_id
474      and system_type_cd   in ('PROPOSED','ACTIVE', 'FROZEN');
475 
476   /* Bug 4929586
477   assign_stat_types.delete;
478   FOR l_assign_stat_rec in l_assign_stat_csr
479   Loop
480    l_assign_stat_cnt := l_assign_stat_cnt + 1;
481    assign_stat_types(l_assign_stat_cnt) := l_assign_stat_rec.assignment_status_type_id;
482   End Loop;  */
483 
484   FOR position_rec IN l_positions_csr
485   LOOP
486     l_position_name              := null;
487     l_person_id                  := null;
488     l_assignment_status_type_id  := null;
489 
490     l_position_name              := position_rec.name;
491     l_person_id                  := position_rec.person_id;
492 
493     l_process_flag := 'Y';
494 
495     /* Bug 4929586
496     if (l_person_id is not null) then
497        l_assignment_status_type_id  := position_rec.assignment_status_type_id;
498        For k in 1..l_assign_stat_cnt
499        Loop
500          if (assign_stat_types(k) = l_assignment_status_type_id) then
501           l_process_flag := 'N';
502          end if;
503        End Loop;
504     end if; */
505 
506 
507     if ((prev_position_id = position_rec.position_id) and
508          (prev_position_id <> -1) and
509         (prev_person_id = position_rec.person_id) and
510         (prev_person_id <> -1) and
511         (prev_person_id <> 0)) then
512 
513           l_process_flag := 'N';
514     end if;
515 
516     prev_position_id := position_rec.position_id;
517     prev_person_id := position_rec.person_id;
518 
519    if (l_process_flag = 'Y') then
520 
521     if ((position_rec.position_id <> l_fin_position_id) and (l_fin_position_id <> -1)) then
522        l_position_ctr := l_position_ctr + 1;
523     end if;
524 
525     if (l_person_id <> 0) then
526        For Emp_Name_Rec in G_Employee_Details(p_person_id => l_person_id)
527        Loop
528          l_employee_name := Emp_Name_Rec.first_name||' '||Emp_Name_Rec.last_name;
529        End Loop;
530     end if;
531 
532    if (position_rec.date_end = to_date('31124712','DDMMYYYY')) then
533        d_date_end := to_date(null);
534    else
535        d_date_end := position_rec.date_end;
536    end if;
537 
538   l_salary_type   := null;
539   l_grade_rule_id := position_rec.entry_grade_rule_id;
540   l_step_id       := position_rec.entry_step_id;
541   l_pay_basis_id  := position_rec.pay_basis_id;
542 
543   For C_Pay_Grade_Rec in C_Pay_Grade
544   Loop
545     l_rate_type                := C_Pay_Grade_Rec.rate_type;
546     if (l_rate_type = 'G') then
547        l_rate_or_payscale_id := C_Pay_Grade_Rec.rate_id;
548        l_value   := fnd_number.canonical_to_number(C_Pay_Grade_Rec.value);
549        l_salary_type   := 'RATE';
550     else
551        l_grade_or_spinal_point_id := C_Pay_Grade_Rec.grade_or_spinal_point_id;
552        l_sequence                 := C_Pay_Grade_Rec.sequence;
553        l_value   := fnd_number.canonical_to_number(C_Pay_Grade_Rec.value);
554        l_salary_type              := 'STEP';
555 
556        -- Start bug no 3902996
557        For C_Payscale_rec in C_Payscale
558        Loop
559          l_parent_spine_id := C_Payscale_rec.parent_spine_id;
560        end loop;
561 
562        l_rate_cnt_flag := 'N';
563        For C_rate_check_rec in C_rate_check
564        Loop
565          l_rate_cnt_flag := 'Y' ;
566          exit;
567        End Loop;
568        -- End bug no 3902996
569 
570        For C_grade_spine_rec in C_grade_spine
571        loop
572           l_grade_spine_id := C_grade_spine_rec.grade_spine_id;
573        end loop;
574 
575        For C_session_rec in C_session
576        Loop
577          l_session_date := C_session_rec.effective_date;
578        End Loop;
579 
580        per_spinal_point_steps_pkg.pop_flds(l_grade_step,
581                                            l_session_date,
582                                            l_grade_or_spinal_point_id,
583                                            l_grade_spine_id);
584 
585       if (l_rate_cnt_flag = 'Y') then
586          l_rate_or_payscale_id := C_Pay_Grade_Rec.rate_id;
587       else
588        -- Start bug no 3902996
589        /*For C_Payscale_rec in C_Payscale
590        Loop
591          l_rate_or_payscale_id := C_Payscale_rec.parent_spine_id;
592        end loop;*/
593        l_rate_or_payscale_id := l_parent_spine_id;
594        -- End bug no 3902996
595 
596       end if;
597     end if;
598 
599   end loop;
600 
601 
602   For C_pay_basis_rec in C_pay_basis
603   loop
604     l_pay_basis := C_pay_basis_rec.pay_basis;
605   end loop;
606 
607   tf := FND_FLEX_EXT.GET_SEGMENTS('PER', 'POS', l_pos_id_flex_num, position_rec.position_definition_id, nsegs, segs);
608   if (tf = FALSE) then
609 
610         l_msg := FND_MESSAGE.Get;
611         FND_FILE.put_line(FND_FILE.LOG,'Invalid Segments  HRMS Position: '||
612                                                     position_rec.position_id);
613         FND_FILE.put_line(FND_FILE.LOG,l_msg);
614         FND_MESSAGE.SET_NAME('PSB','PSB_POS_DEFN_VALUE_ERROR');
615         FND_MESSAGE.SET_TOKEN('POSITION_NAME',l_position_name );
616         FND_MESSAGE.SET_TOKEN('ERR_MESG',l_msg);
617         FND_MSG_PUB.Add;
618   end if;
619 
620   l_per_index := 1;
621 
622   For k in 1..30
623   Loop
624    possegs(k) := null;
625   End Loop;
626 
627   For C_pos_seg_rec in C_pos_segs
628   Loop
629       If (C_pos_seg_rec.application_column_name = 'SEGMENT1') then
630          possegs(1) := segs(l_per_index);
631          l_per_index := l_per_index + 1;
632       end if;
633       If (C_pos_seg_rec.application_column_name = 'SEGMENT2') then
634          possegs(2) := segs(l_per_index);
635          l_per_index := l_per_index + 1;
636       end if;
637       If (C_pos_seg_rec.application_column_name = 'SEGMENT3') then
638          possegs(3) := segs(l_per_index);
639          l_per_index := l_per_index + 1;
640       end if;
641       If (C_pos_seg_rec.application_column_name = 'SEGMENT4') then
642          possegs(4) := segs(l_per_index);
643          l_per_index := l_per_index + 1;
644       end if;
645       If (C_pos_seg_rec.application_column_name = 'SEGMENT5') then
646          possegs(5) := segs(l_per_index);
647          l_per_index := l_per_index + 1;
648       end if;
649       If (C_pos_seg_rec.application_column_name = 'SEGMENT6') then
650          possegs(6) := segs(l_per_index);
651          l_per_index := l_per_index + 1;
652       end if;
653       If (C_pos_seg_rec.application_column_name = 'SEGMENT7') then
654          possegs(7) := segs(l_per_index);
655          l_per_index := l_per_index + 1;
656       end if;
657       If (C_pos_seg_rec.application_column_name = 'SEGMENT8') then
658          possegs(8) := segs(l_per_index);
659          l_per_index := l_per_index + 1;
660       end if;
661       If (C_pos_seg_rec.application_column_name = 'SEGMENT9') then
662          possegs(9) := segs(l_per_index);
663          l_per_index := l_per_index + 1;
664       end if;
665       If (C_pos_seg_rec.application_column_name = 'SEGMENT10') then
666          possegs(10) := segs(l_per_index);
667          l_per_index := l_per_index + 1;
668       end if;
669       If (C_pos_seg_rec.application_column_name = 'SEGMENT11') then
670          possegs(11) := segs(l_per_index);
671          l_per_index := l_per_index + 1;
672       end if;
673       If (C_pos_seg_rec.application_column_name = 'SEGMENT12') then
674          possegs(12) := segs(l_per_index);
675          l_per_index := l_per_index + 1;
676       end if;
677       If (C_pos_seg_rec.application_column_name = 'SEGMENT13') then
678          possegs(13) := segs(l_per_index);
679          l_per_index := l_per_index + 1;
680       end if;
681       If (C_pos_seg_rec.application_column_name = 'SEGMENT14') then
682          possegs(14) := segs(l_per_index);
683          l_per_index := l_per_index + 1;
684       end if;
685       If (C_pos_seg_rec.application_column_name = 'SEGMENT15') then
686          possegs(15) := segs(l_per_index);
687          l_per_index := l_per_index + 1;
688       end if;
689       If (C_pos_seg_rec.application_column_name = 'SEGMENT16') then
690          possegs(16) := segs(l_per_index);
691          l_per_index := l_per_index + 1;
692       end if;
693       If (C_pos_seg_rec.application_column_name = 'SEGMENT17') then
694          possegs(17) := segs(l_per_index);
695          l_per_index := l_per_index + 1;
696       end if;
697       If (C_pos_seg_rec.application_column_name = 'SEGMENT18') then
698          possegs(18) := segs(l_per_index);
699          l_per_index := l_per_index + 1;
700       end if;
701       If (C_pos_seg_rec.application_column_name = 'SEGMENT19') then
702          possegs(19) := segs(l_per_index);
703          l_per_index := l_per_index + 1;
704       end if;
705       If (C_pos_seg_rec.application_column_name = 'SEGMENT20') then
706          possegs(20) := segs(l_per_index);
707          l_per_index := l_per_index + 1;
708       end if;
709       If (C_pos_seg_rec.application_column_name = 'SEGMENT21') then
710          possegs(21) := segs(l_per_index);
711          l_per_index := l_per_index + 1;
712       end if;
713       If (C_pos_seg_rec.application_column_name = 'SEGMENT22') then
714          possegs(22) := segs(l_per_index);
715          l_per_index := l_per_index + 1;
716       end if;
717       If (C_pos_seg_rec.application_column_name = 'SEGMENT23') then
718          possegs(23) := segs(l_per_index);
719          l_per_index := l_per_index + 1;
720       end if;
721       If (C_pos_seg_rec.application_column_name = 'SEGMENT24') then
722          possegs(24) := segs(l_per_index);
723          l_per_index := l_per_index + 1;
724       end if;
725       If (C_pos_seg_rec.application_column_name = 'SEGMENT25') then
726          possegs(25) := segs(l_per_index);
727          l_per_index := l_per_index + 1;
728       end if;
729       If (C_pos_seg_rec.application_column_name = 'SEGMENT26') then
730          possegs(26) := segs(l_per_index);
731          l_per_index := l_per_index + 1;
732       end if;
733       If (C_pos_seg_rec.application_column_name = 'SEGMENT27') then
734          possegs(27) := segs(l_per_index);
735          l_per_index := l_per_index + 1;
736       end if;
737       If (C_pos_seg_rec.application_column_name = 'SEGMENT28') then
738          possegs(28) := segs(l_per_index);
739          l_per_index := l_per_index + 1;
740       end if;
741       If (C_pos_seg_rec.application_column_name = 'SEGMENT29') then
742          possegs(29) := segs(l_per_index);
743          l_per_index := l_per_index + 1;
744       end if;
745       If (C_pos_seg_rec.application_column_name = 'SEGMENT30') then
746          possegs(30) := segs(l_per_index);
747          l_per_index := l_per_index + 1;
748       end if;
749 
750   End Loop;
751 
752    INSERT INTO PSB_POSITIONS_I
753    (
754     DATA_EXTRACT_ID         ,
755     BUSINESS_GROUP_ID       ,
756     HR_POSITION_ID          ,
757     HR_EMPLOYEE_ID          ,
758     HR_POSITION_NAME        ,
759     -- de by org
760     ORGANIZATION_ID         ,
761     EFFECTIVE_START_DATE    ,
762     EFFECTIVE_END_DATE      ,
763     HR_POSITION_DEFINITION_ID,
764     SUMMARY_FLAG            ,
765     ENABLED_FLAG            ,
766     ID_FLEX_NUM             ,
767     AVAILABILITY_STATUS     ,
768     SALARY_TYPE             ,
769     RATE_OR_PAYSCALE_ID     ,
770     GRADE_ID                ,
771     GRADE_STEP              ,
772     SEQUENCE_NUMBER         ,
773     VALUE                   ,
774     PAY_BASIS               ,
775     SEGMENT1                ,
776     SEGMENT2                ,
777     SEGMENT3                ,
778     SEGMENT4                ,
779     SEGMENT5                ,
780     SEGMENT6                ,
781     SEGMENT7                ,
782     SEGMENT8                ,
783     SEGMENT9                ,
784     SEGMENT10               ,
785     SEGMENT11               ,
786     SEGMENT12               ,
787     SEGMENT13               ,
788     SEGMENT14               ,
789     SEGMENT15               ,
790     SEGMENT16               ,
791     SEGMENT17               ,
792     SEGMENT18               ,
793     SEGMENT19               ,
794     SEGMENT20               ,
795     SEGMENT21               ,
796     SEGMENT22               ,
797     SEGMENT23               ,
798     SEGMENT24               ,
799     SEGMENT25               ,
800     SEGMENT26               ,
801     SEGMENT27               ,
802     SEGMENT28               ,
803     SEGMENT29               ,
804     SEGMENT30               ,
805     LAST_UPDATE_DATE        ,
806     LAST_UPDATED_BY         ,
807     LAST_UPDATE_LOGIN       ,
808     CREATED_BY              ,
809     CREATION_DATE
810    )
811    VALUES
812    (
813      p_data_extract_id,
814      position_rec.business_group_id,
815      position_rec.position_id,
816      decode(position_rec.person_id,0,null,position_rec.person_id),
817      position_rec.name,
818      -- de by org
819      position_rec.organization_id,
820      position_rec.date_effective,
821      d_date_end,
822      position_rec.position_definition_id,
823      'Y',
824      'Y',
825      p_id_flex_num,
826      position_rec.system_type_cd,
827      l_salary_type,
828      l_rate_or_payscale_id,
829      position_rec.entry_grade_id,
830      l_grade_step,
831      l_sequence,
832      l_value,
833      l_pay_basis,
834      possegs(1),
835      possegs(2),
836      possegs(3),
837      possegs(4),
838      possegs(5),
839      possegs(6),
840      possegs(7),
841      possegs(8),
842      possegs(9),
843      possegs(10),
844      possegs(11),
845      possegs(12),
846      possegs(13),
847      possegs(14),
848      possegs(15),
849      possegs(16),
850      possegs(17),
851      possegs(18),
852      possegs(19),
853      possegs(20),
854      possegs(21),
855      possegs(22),
856      possegs(23),
857      possegs(24),
858      possegs(25),
859      possegs(26),
860      possegs(27),
861      possegs(28),
862      possegs(29),
863      possegs(30),
864      l_last_update_date,
865      l_last_updated_by ,
866      l_last_update_login ,
867      l_created_by,
868      l_creation_date
869    );
870 
871   if l_position_ctr = PSB_WS_ACCT1.g_checkpoint_save then
872         Update_Reentry
873         ( p_api_version              => 1.0  ,
874           p_return_status            => l_return_status,
875           p_msg_count                => l_msg_count,
876           p_msg_data                 => l_msg_data,
877           p_data_extract_id          => p_data_extract_id,
878           p_extract_method           => p_extract_method,
879           p_process                  => 'Positions Interface',
880           p_restart_id               => position_rec.position_id
881         );
882 
883        if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
884           raise FND_API.G_EXC_ERROR;
885        end if;
886       commit work;
887       l_position_ctr := 0;
888       Savepoint Get_Position;
889     end if;
890 
891     l_fin_position_id := position_rec.position_id;
892 
893    end if;
894 
895   END LOOP; -- End processing positions.
896 
897   Update_Reentry
898   ( p_api_version              => 1.0  ,
899     p_return_status            => l_return_status,
900     p_msg_count                => l_msg_count,
901     p_msg_data                 => l_msg_data,
902     p_data_extract_id          => p_data_extract_id,
903     p_extract_method           => p_extract_method,
904     p_process                  => 'Positions Interface',
905     p_restart_id               => l_fin_position_id
906   );
907 
908   if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
909     raise FND_API.G_EXC_ERROR;
910   end if;
911 
912   Reentrant_Process
913   ( p_api_version              => 1.0  ,
914     p_return_status            => l_return_status,
915     p_msg_count                => l_msg_count,
916     p_msg_data                 => l_msg_data,
917     p_data_extract_id          => p_data_extract_id,
918     p_extract_method           => p_extract_method,
919     p_process                  => 'Positions Interface'
920   );
921 
922   if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
923      raise FND_API.G_EXC_ERROR;
924   end if;
925 
926   commit work;
927 
928   end if ; -- Checking IF (l_status <> 'C ).
929 
930   -- End of API body.
931 
932 EXCEPTION
933 
934    when FND_API.G_EXC_ERROR then
935      rollback to Get_Position;
936      p_return_status := FND_API.G_RET_STS_ERROR;
937      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
938                                  p_data  => p_msg_data);
939      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
940                                  p_data  => p_msg_data);
941      message_token('POSITION_NAME',l_position_name );
942      message_token('EMPLOYEE_NAME',l_employee_name );
943      add_message('PSB', 'PSB_POSITION_DETAILS');
944 
945    when FND_API.G_EXC_UNEXPECTED_ERROR then
946      rollback to Get_Position;
947      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
948      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
949                                  p_data  => p_msg_data);
950      message_token('POSITION_NAME',l_position_name );
951      message_token('EMPLOYEE_NAME',l_employee_name );
952      add_message('PSB', 'PSB_POSITION_DETAILS');
953 
954   WHEN OTHERS THEN
955     --
956     ROLLBACK TO Get_Position ;
957     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
958     --
959     IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
960       FND_MSG_PUB.Add_Exc_Msg ( G_PKG_NAME,
961                                 l_api_name);
962     END if;
963     --
964 
965     --
966     FND_MSG_PUB.Count_And_Get ( p_count => p_msg_count,
967                                 p_data  => p_msg_data );
968     --
969     message_token('POSITION_NAME',l_position_name );
970     message_token('EMPLOYEE_NAME',l_employee_name );
971     add_message('PSB', 'PSB_POSITION_DETAILS');
972 
973 END Get_Position_Information;
974 /*---------------------------------------------------------------------------*/
975 
976 
977 /*===========================================================================+
978  |                      PROCEDURE Get_Salary_Information                     |
979  +===========================================================================*/
980 PROCEDURE Get_Salary_Information
981 ( p_api_version         IN    NUMBER,
982   p_init_msg_list	IN    VARCHAR2 := FND_API.G_FALSE,
983   p_commit	    	IN    VARCHAR2 := FND_API.G_FALSE,
984   p_validation_level	IN    NUMBER   := FND_API.G_VALID_LEVEL_FULL,
985   p_return_status       OUT   NOCOPY VARCHAR2,
986   p_msg_count           OUT   NOCOPY NUMBER,
987   p_msg_data            OUT   NOCOPY VARCHAR2,
988   p_data_extract_id     IN    NUMBER,
989   p_extract_method      IN    VARCHAR2,
990   p_business_group_id   IN    NUMBER
991 )
992 IS
993   --
994   l_api_name		CONSTANT VARCHAR2(30)	:= 'Get_Salary_Information';
995   l_api_version         CONSTANT NUMBER 	:= 1.0;
996   --
997   l_last_update_date             date;
998   l_last_updated_by              number;
999   l_last_update_login            number;
1000   l_creation_date                date;
1001   l_created_by                   number;
1002   l_restart_grade_rule_id        number := 0;
1003   l_fin_graderule_id             number := 0;
1004   l_session_date                 date;
1005   l_salary_ctr                   number := 0;
1006   l_salary_type                  varchar2(15);
1007   l_rate_or_payscale_id          number;
1008   l_parent_spine_id              number;
1009   l_rate_or_payscale_name        varchar2(80);
1010   l_grade_step                   number;
1011   l_grade_step_id                number;
1012   l_grade_id                     number;
1013   ld_grade_id                    number;
1014   lh_grade_id                    number;
1015   l_grade_id_flex_num            number;
1016   l_grade_spine_id               number;
1017   l_grade_name                   varchar2(80);
1018   l_element_value                number;
1019   l_element_type_id              number;
1020   l_minimum_value                number;
1021   l_maximum_value                number;
1022   l_mid_value                    number;
1023   l_sequence                     number;
1024   l_rate_id                      number;
1025   l_rate_cnt_flag                varchar2(1);
1026   l_pay_basis                    varchar2(30);
1027   l_grade_or_spinal_point_id     number;
1028   l_grade_stmt                   varchar2(1000);
1029   l_status                       varchar2(1);
1030   l_return_status                varchar2(1);
1031   l_msg_count                    number;
1032   l_msg_data                     varchar2(1000);
1033   d_effective_end_date           date;
1034 /*v_gcursorid                    INTEGER;
1035   v_gdummy                       INTEGER; */
1036   --
1037   Cursor C3 is
1038        SELECT
1039              GRADE_RULE_ID ,
1040              EFFECTIVE_START_DATE ,
1041              EFFECTIVE_END_DATE,
1042              BUSINESS_GROUP_ID,
1043              RATE_ID ,
1044              GRADE_OR_SPINAL_POINT_ID,
1045              RATE_TYPE,
1046              MAXIMUM,
1047              MID_VALUE,
1048              MINIMUM,
1049              SEQUENCE,
1050              VALUE
1051        FROM  PAY_GRADE_RULES
1052       WHERE  BUSINESS_GROUP_ID = p_business_group_id
1053         AND  grade_rule_id > l_restart_grade_rule_id
1054       ORDER  BY grade_rule_id;
1055   --
1056   Cursor Cpay is
1057      SELECT pgs.grade_id,pgs.grade_spine_id,psp.step_id,psp.sequence
1058        FROM PER_GRADE_SPINES pgs,PER_SPINAL_POINT_STEPS psp
1059       WHERE pgs.parent_spine_id = l_parent_spine_id
1060         AND pgs.business_group_id = p_business_group_id
1061         AND psp.business_group_id = p_business_group_id
1062         AND pgs.grade_spine_id    = psp.grade_spine_id
1063         AND psp.spinal_point_id   = l_grade_or_spinal_point_id;
1064   --
1065   Cursor  C_payscale is
1066      SELECT parent_spine_id
1067        FROM PER_SPINAL_POINTS
1068       WHERE spinal_point_id = l_grade_or_spinal_point_id
1069        AND business_group_id = p_business_group_id;
1070   --
1071   Cursor  C_payname is
1072      SELECT name
1073        FROM PER_PARENT_SPINES
1074       WHERE parent_spine_id = l_rate_or_payscale_id
1075         AND business_group_id = p_business_group_id;
1076   --
1077   Cursor  C_paybasis is
1078      SELECT pay_basis, piv.element_type_id
1079        FROM PAY_RATES pr, PER_PAY_BASES ppb, PAY_INPUT_VALUES piv
1080       WHERE pr.parent_spine_id = l_rate_or_payscale_id
1081         AND pr.rate_id = ppb.rate_id
1082         AND pr.business_group_id = p_business_group_id
1083         AND ppb.business_group_id = p_business_group_id
1084         AND ppb.input_value_id = piv.input_value_id;
1085   --
1086   /*Cursor C_flex_num is
1087         select grade_structure
1088           from per_business_groups
1089          where business_group_id = p_business_group_id; */
1090   --
1091   Cursor C_session is
1092      SELECT effective_date
1093        FROM FND_SESSIONS
1094       WHERE session_id = USERENV('sessionid');
1095   --
1096   Cursor C_rate is
1097       SELECT name
1098         FROM PAY_RATES
1099        WHERE rate_id = l_rate_id;
1100 
1101   -- To fetch grade name from PER_GRADES
1102   -- (Bug Number 3159157)
1103   Cursor C_grade is
1104      SELECT name
1105        FROM PER_GRADES
1106       WHERE grade_id = l_grade_id;
1107 
1108   --
1109   Cursor C_rate_paybasis is
1110      SELECT ppb.pay_basis, piv.element_type_id
1111        FROM PER_PAY_BASES ppb, PAY_INPUT_VALUES piv
1112       WHERe ppb.rate_id = l_rate_id
1113         AND ppb.business_group_id = p_business_group_id
1114         AND ppb.input_value_id = piv.input_value_id;
1115   --
1116   Cursor C_rate_check is
1117   Select count(*), parent_spine_id
1118     from pay_rates
1119    where business_group_id = p_business_group_id
1120   -- Start bug no 3902996
1121      and parent_spine_id = l_parent_spine_id
1122   -- End bug no 3902996
1123      and rate_type = 'SP'
1124    group by parent_spine_id
1125    having count(*) > 1;
1126   --
1127 BEGIN
1128 
1129   -- Standard Start of API savepoint
1130   Savepoint Get_Salary;
1131 
1132   -- Standard call to check for call compatibility.
1133   if not FND_API.Compatible_API_Call (l_api_version,
1134             	    	    	      p_api_version,
1135    	       	    	 	      l_api_name,
1136 		    	    	      G_PKG_NAME)
1137   then
1138     raise FND_API.G_EXC_UNEXPECTED_ERROR;
1139   end if;
1140 
1141   -- Initialize message list if p_init_msg_list is set to TRUE.
1142   if FND_API.to_Boolean (p_init_msg_list) then
1143      FND_MSG_PUB.initialize;
1144   end if;
1145   p_return_status := FND_API.G_RET_STS_SUCCESS;
1146 
1147   l_last_update_date  := sysdate;
1148   l_last_updated_by   := FND_GLOBAL.USER_ID;
1149   l_last_update_login := FND_GLOBAL.LOGIN_ID;
1150   l_creation_date     := sysdate;
1151   l_created_by        := FND_GLOBAL.USER_ID;
1152 
1153   Check_Reentry
1154   (p_api_version              => 1.0  ,
1155    p_return_status            => l_return_status,
1156    p_msg_count                => l_msg_count,
1157    p_msg_data                 => l_msg_data,
1158    p_data_extract_id          => p_data_extract_id,
1159    p_process                  => 'Salary Interface',
1160    p_status                   => l_status,
1161    p_restart_id               => l_restart_grade_rule_id
1162    );
1163 
1164   if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1165      raise FND_API.G_EXC_ERROR;
1166   end if;
1167 
1168   -- Start bug no 3902996
1169   /*l_rate_cnt_flag := 'N';
1170 
1171   For C_rate_check_rec in C_rate_check
1172   Loop
1173     l_rate_cnt_flag := 'Y' ;
1174     exit;
1175   End Loop;*/
1176   -- End bug no 3902996
1177 
1178 /*Bug No:1954662 Start*/
1179 /*For C_flex_rec in C_flex_num
1180   Loop
1181     l_grade_id_flex_num := C_flex_rec.grade_structure;
1182   End Loop;
1183 */
1184   if (l_status <> 'C') then
1185 
1186   -- Commented out for bug number 3159157
1187   /*For C_flex_rec in C_flex_num
1188   Loop
1189     l_grade_id_flex_num := C_flex_rec.grade_structure;
1190   End Loop;
1191 
1192   if (l_grade_id_flex_num is not null) then
1193      v_gcursorid := DBMS_SQL.OPEN_CURSOR;
1194      l_grade_stmt := 'SELECT pg.grade_id,pgv.concatenated_segments
1195                         FROM PER_GRADES pg,PER_GRADE_DEFINITIONS_KFV pgv
1196                        WHERE pg.grade_id = '||':ld_grade_id'||
1197                        ' AND pg.business_group_id = '||p_business_group_id||
1198                        ' AND pg.grade_definition_id = pgv.grade_definition_id'||
1199                        ' AND pgv.id_flex_num        = '||l_grade_id_flex_num;
1200 
1201      DBMS_SQL.PARSE(v_gcursorid,l_grade_stmt,DBMS_SQL.V7);
1202      DBMS_SQL.DEFINE_COLUMN(v_gcursorid,1,lh_grade_id);
1203      DBMS_SQL.DEFINE_COLUMN(v_gcursorid,2,l_grade_name,80);
1204   end if; */
1205 /*Bug No:1954662 End*/
1206 
1207   For salary_rec IN C3 LOOP
1208      l_salary_ctr    := l_salary_ctr + 1;
1209      l_fin_graderule_id := salary_rec.grade_rule_id;
1210      l_minimum_value := 0;
1211      l_maximum_value := 0;
1212      l_mid_value     := 0;
1213      l_element_value := 0;
1214      l_grade_step    := null;
1215      l_sequence      := null;
1216      l_salary_type   := null;
1217 
1218      if (salary_rec.effective_end_date = to_date('31124712','DDMMYYYY')) then
1219          d_effective_end_date := to_date(null);
1220      else
1221          d_effective_end_date := salary_rec.effective_end_date;
1222      end if;
1223 
1224      l_grade_or_spinal_point_id := salary_rec.grade_or_spinal_point_id;
1225      l_rate_id := salary_rec.rate_id;
1226 
1227   -- If pay_grade_rules.rate_type = 'SP' then
1228   -- the salary type  is 'Grade Scale'
1229 
1230    if (salary_rec.rate_type = 'SP') then
1231 
1232       l_salary_type := 'STEP';
1233 
1234   -- The grade_or_spinal_point_id refers to
1235   -- the grade_id or spinal_point_id depending
1236   -- on the rate_type being 'Grade Rate' or 'Grade Scale' respectively.
1237   -- To get the payscale_id ..
1238 
1239 
1240     For C_payscale_rec in C_payscale
1241     Loop
1242        l_parent_spine_id := C_payscale_rec.parent_spine_id;
1243     End Loop;
1244 
1245     -- Start bug no 3902996
1246     l_rate_cnt_flag := 'N';
1247     For C_rate_check_rec in C_rate_check
1248     Loop
1249       l_rate_cnt_flag := 'Y' ;
1250       exit;
1251     End Loop;
1252     -- End bug no 3902996
1253 
1254     if (l_rate_cnt_flag = 'Y') then
1255 
1256       l_rate_or_payscale_id := salary_rec.rate_id;
1257 
1258       -- To get Grade Rate Name from pay_rates
1259       For C_rate_rec in C_rate
1260       Loop
1261          l_rate_or_payscale_name := C_rate_rec.name;
1262 
1263          -- Bug#3275104: Temporary fix.
1264          IF LENGTH(l_rate_or_payscale_name) > 30 THEN
1265            l_rate_or_payscale_name := SUBSTR(l_rate_or_payscale_name,1,30) ;
1266          END IF;
1267 
1268       End Loop;
1269 
1270       -- To get Pay Basis from per_pay_bases
1271       For C_paybasis_rec in C_rate_paybasis
1272       Loop
1273          l_pay_basis := C_paybasis_rec.pay_basis;
1274          l_element_type_id := C_paybasis_rec.element_type_id;
1275       End Loop;
1276 
1277     else
1278      l_rate_or_payscale_id := l_parent_spine_id;
1279 
1280 
1281     -- To get payscale_name from Per_Parent_Spines.
1282     For C_payname_rec in C_payname
1283     Loop
1284        l_rate_or_payscale_name := C_payname_rec.name;
1285     End Loop;
1286 
1287   -- To get Pay basis for this paysacle
1288 
1289     For C_paybasis_rec in C_paybasis
1290     Loop
1291        l_pay_basis := C_paybasis_rec.pay_basis;
1292        l_element_type_id := C_paybasis_rec.element_type_id;
1293     End Loop;
1294    end if;
1295 
1296     For Grade_rec in Cpay Loop
1297 
1298      l_grade_id := Grade_rec.grade_id;
1299      l_grade_step_id := Grade_rec.step_id;
1300      l_sequence      := Grade_rec.sequence;
1301 
1302   -- Commented out for bug number 3159157
1303      /*DBMS_SQL.BIND_VARIABLE(v_gcursorid,':ld_grade_id',l_grade_id);
1304 
1305      v_gdummy := DBMS_SQL.EXECUTE(v_gcursorid);
1306 
1307      Loop
1308         if (DBMS_SQL.FETCH_ROWS(v_gcursorid) = 0) then
1309            exit;
1310         end if;
1311 
1312         DBMS_SQL.COLUMN_VALUE(v_gcursorid,1,lh_grade_id);
1313         DBMS_SQL.COLUMN_VALUE(v_gcursorid,2,l_grade_name);
1314 
1315      End Loop; */
1316 
1317   -- To get grade name from Per_Grades
1318      For C_grade_rec in C_grade
1319      Loop
1320        l_grade_name    := C_grade_rec.name;
1321      End Loop;
1322 
1323      For C_session_rec in C_session
1324      Loop
1325        l_session_date := C_session_rec.effective_date;
1326      End Loop;
1327 
1328      per_spinal_point_steps_pkg.pop_flds(l_grade_step,
1329                                          l_session_date,
1330                                          salary_rec.grade_or_spinal_point_id,
1331                                          Grade_rec.grade_spine_id);
1332 
1333     l_element_value := fnd_number.canonical_to_number(salary_rec.value);
1334 
1335    INSERT INTO PSB_SALARY_I
1336    ( BUSINESS_GROUP_ID,
1337      DATA_EXTRACT_ID,
1338      SALARY_TYPE      ,
1339      RATE_OR_PAYSCALE_ID,
1340      RATE_OR_PAYSCALE_NAME,
1341      GRADE_ID         ,
1342      GRADE_NAME       ,
1343      GRADE_STEP       ,
1344      SEQUENCE_NUMBER  ,
1345      MINIMUM_VALUE    ,
1346      MAXIMUM_VALUE    ,
1347      MID_VALUE        ,
1348      ELEMENT_VALUE    ,
1349      ELEMENT_TYPE_ID  ,
1350      PAY_BASIS        ,
1351      EFFECTIVE_START_DATE,
1352      EFFECTIVE_END_DATE,
1353      LAST_UPDATE_DATE ,
1354      LAST_UPDATED_BY  ,
1355      LAST_UPDATE_LOGIN,
1356      CREATED_BY       ,
1357      CREATION_DATE    )
1358    VALUES
1359    (
1360      salary_rec.business_group_id,
1361      p_data_extract_id,
1362      l_salary_type,
1363      l_rate_or_payscale_id,
1364      l_rate_or_payscale_name,
1365      Grade_rec.grade_id,
1366      l_grade_name,
1367      l_grade_step,
1368      l_sequence,
1369      l_minimum_value,
1370      l_maximum_value,
1371      l_mid_value,
1372      l_element_value,
1373      l_element_type_id,
1374      l_pay_basis,
1375      salary_rec.effective_start_date,
1376      d_effective_end_date,
1377      l_last_update_date,
1378      l_last_updated_by ,
1379      l_last_update_login ,
1380      l_created_by,
1381      l_creation_date
1382      );
1383     end loop;
1384 
1385    elsif salary_rec.rate_type = 'G' then
1386       l_salary_type := 'RATE';
1387 
1388       l_grade_id := salary_rec.grade_or_spinal_point_id;
1389       l_rate_or_payscale_id := salary_rec.rate_id;
1390 
1391       -- To get Grade Rate Name from pay_rates
1392       For C_rate_rec in C_rate
1393       Loop
1394          l_rate_or_payscale_name := C_rate_rec.name;
1395 
1396          -- Bug#3275104: Temporary fix.
1397          IF LENGTH(l_rate_or_payscale_name) > 30 THEN
1398            l_rate_or_payscale_name := SUBSTR(l_rate_or_payscale_name,1,30) ;
1399          END IF;
1400       End Loop;
1401 
1402       -- To get Pay Basis from per_pay_bases
1403       For C_paybasis_rec in C_rate_paybasis
1404       Loop
1405          l_pay_basis := C_paybasis_rec.pay_basis;
1406          l_element_type_id := C_paybasis_rec.element_type_id;
1407       End Loop;
1408 
1409      -- To get grade name from Per_Grades
1410      /*DBMS_SQL.BIND_VARIABLE(v_gcursorid,':ld_grade_id',l_grade_id);
1411 
1412      v_gdummy := DBMS_SQL.EXECUTE(v_gcursorid);
1413 
1414      Loop
1415         if (DBMS_SQL.FETCH_ROWS(v_gcursorid) = 0) then
1416            exit;
1417         end if;
1418         DBMS_SQL.COLUMN_VALUE(v_gcursorid,1,lh_grade_id);
1419         DBMS_SQL.COLUMN_VALUE(v_gcursorid,2,l_grade_name);
1420      End Loop; */
1421 
1422      For C_grade_rec in C_grade
1423      Loop
1424        l_grade_name := C_grade_rec.name;
1425      End Loop;
1426 
1427      l_minimum_value := fnd_number.canonical_to_number(salary_rec.minimum);
1428      l_maximum_value := fnd_number.canonical_to_number(salary_rec.maximum);
1429      l_mid_value     := fnd_number.canonical_to_number(salary_rec.mid_value);
1430      l_element_value := fnd_number.canonical_to_number(salary_rec.value);
1431      l_sequence      := salary_rec.sequence;
1432 
1433    INSERT INTO PSB_SALARY_I
1434    ( BUSINESS_GROUP_ID,
1435      DATA_EXTRACT_ID,
1436      SALARY_TYPE      ,
1437      RATE_OR_PAYSCALE_ID,
1438      RATE_OR_PAYSCALE_NAME,
1439      GRADE_ID         ,
1440      GRADE_NAME       ,
1441      GRADE_STEP       ,
1442      SEQUENCE_NUMBER  ,
1443      MINIMUM_VALUE    ,
1444      MAXIMUM_VALUE    ,
1445      MID_VALUE        ,
1446      ELEMENT_VALUE    ,
1447      ELEMENT_TYPE_ID  ,
1448      PAY_BASIS        ,
1449      EFFECTIVE_START_DATE,
1450      EFFECTIVE_END_DATE,
1451      LAST_UPDATE_DATE ,
1452      LAST_UPDATED_BY  ,
1453      LAST_UPDATE_LOGIN,
1454      CREATED_BY       ,
1455      CREATION_DATE    )
1456    VALUES
1457    (
1458      p_business_group_id,
1459      p_data_extract_id,
1460      l_salary_type,
1461      l_rate_or_payscale_id,
1462      l_rate_or_payscale_name,
1463      l_grade_id,
1464      l_grade_name,
1465      l_grade_step,
1466      l_sequence,
1467      l_minimum_value,
1468      l_maximum_value,
1469      l_mid_value,
1470      l_element_value,
1471      l_element_type_id,
1472      l_pay_basis ,
1473      salary_rec.effective_start_date,
1474      d_effective_end_date,
1475      l_last_update_date,
1476      l_last_updated_by ,
1477      l_last_update_login ,
1478      l_created_by,
1479      l_creation_date
1480      );
1481    end if;
1482 
1483    if (l_salary_ctr = PSB_WS_ACCT1.g_checkpoint_save) then
1484       Update_Reentry
1485       ( p_api_version              => 1.0  ,
1486         p_return_status            => l_return_status,
1487         p_msg_count                => l_msg_count,
1488         p_msg_data                 => l_msg_data,
1489         p_data_extract_id          => p_data_extract_id,
1490         p_extract_method           => p_extract_method,
1491         p_process                  => 'Salary Interface',
1492         p_restart_id               => salary_rec.grade_rule_id
1493        );
1494 
1495        if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1496           raise FND_API.G_EXC_ERROR;
1497        end if;
1498       commit work;
1499       l_salary_ctr := 0;
1500       Savepoint Get_Salary;
1501    end if;
1502   END LOOP;
1503 
1504 
1505   Update_Reentry
1506   ( p_api_version              => 1.0  ,
1507     p_return_status            => l_return_status,
1508     p_msg_count                => l_msg_count,
1509     p_msg_data                 => l_msg_data,
1510     p_data_extract_id          => p_data_extract_id,
1511     p_extract_method           => p_extract_method,
1512     p_process                  => 'Salary Interface',
1513     p_restart_id               => l_fin_graderule_id
1514    );
1515 
1516    if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1517       raise FND_API.G_EXC_ERROR;
1518    end if;
1519 
1520   Reentrant_Process
1521   ( p_api_version              => 1.0  ,
1522     p_return_status            => l_return_status,
1523     p_msg_count                => l_msg_count,
1524     p_msg_data                 => l_msg_data,
1525     p_data_extract_id          => p_data_extract_id,
1526     p_extract_method           => p_extract_method,
1527     p_process                  => 'Salary Interface'
1528   );
1529 
1530   if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1531      raise FND_API.G_EXC_ERROR;
1532   end if;
1533 
1534   commit work;
1535   end if;
1536 
1537   -- End of API body.
1538 
1539 EXCEPTION
1540 
1541    when FND_API.G_EXC_ERROR then
1542 
1543      rollback to Get_Salary;
1544      p_return_status := FND_API.G_RET_STS_ERROR;
1545      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
1546                                  p_data  => p_msg_data);
1547      message_token('SALARY_TYPE',l_salary_type );
1548      message_token('RATE_OR_PAYSCALE_NAME',l_rate_or_payscale_name );
1549      message_token('GRADE_NAME',l_grade_name );
1550      message_token('GRADE_STEP',l_grade_step );
1551      message_token('GRADE_SEQUENCE',l_sequence);
1552      add_message('PSB', 'PSB_SALARY_DETAILS');
1553 
1554    when FND_API.G_EXC_UNEXPECTED_ERROR then
1555 
1556      rollback to Get_Salary;
1557      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1558      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
1559                                  p_data  => p_msg_data);
1560      message_token('SALARY_TYPE',l_salary_type );
1561      message_token('RATE_OR_PAYSCALE_NAME',l_rate_or_payscale_name );
1562      message_token('GRADE_NAME',l_grade_name );
1563      message_token('GRADE_STEP',l_grade_step );
1564      message_token('GRADE_SEQUENCE',l_sequence);
1565      add_message('PSB', 'PSB_SALARY_DETAILS');
1566 
1567    when OTHERS then
1568 
1569      rollback to Get_Salary;
1570      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1571      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
1572                                  p_data  => p_msg_data);
1573 
1574      message_token('SALARY_TYPE',l_salary_type );
1575      message_token('RATE_OR_PAYSCALE_NAME',l_rate_or_payscale_name );
1576      message_token('GRADE_NAME',l_grade_name );
1577      message_token('GRADE_STEP',l_grade_step );
1578      message_token('GRADE_SEQUENCE',l_sequence);
1579      add_message('PSB', 'PSB_SALARY_DETAILS');
1580 
1581      if FND_MSG_PUB.Check_Msg_Level
1582        (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1583      then
1584        FND_MSG_PUB.Add_Exc_Msg
1585           (p_pkg_name => G_PKG_NAME,
1586            p_procedure_name => l_api_name);
1587      end if;
1588 
1589 END Get_Salary_Information;
1590 
1591 PROCEDURE Get_Employee_Information
1592 ( p_api_version         IN    NUMBER,
1593   p_init_msg_list	IN    VARCHAR2 := FND_API.G_FALSE,
1594   p_commit	    	IN    VARCHAR2 := FND_API.G_FALSE,
1595   p_validation_level	IN    NUMBER   := FND_API.G_VALID_LEVEL_FULL,
1596   p_return_status       OUT   NOCOPY VARCHAR2,
1597   p_msg_count           OUT   NOCOPY NUMBER,
1598   p_msg_data            OUT   NOCOPY VARCHAR2,
1599   p_data_extract_id     IN    NUMBER,
1600   -- de by org
1601   p_extract_by_org      IN    VARCHAR2,
1602   p_extract_method      IN    VARCHAR2,
1603   p_date                IN    DATE,
1604   p_business_group_id   IN    NUMBER,
1605   p_set_of_books_id     IN    NUMBER,
1606   p_copy_defaults_flag  IN    VARCHAR2,
1607   p_copy_salary_flag    IN    VARCHAR2
1608 ) AS
1609 
1610     l_last_update_date    date;
1611     l_last_updated_by     number;
1612     l_last_update_login   number;
1613     l_creation_date       date;
1614     l_created_by          number;
1615     l_session_date        date;
1616     l_restart_assignment_id number := 0;
1617     l_process_flag        varchar2(1);
1618     l_hr_position_id      number;
1619     l_hr_employee_id      number;
1620     l_assign_ctr          number := 0;
1621     l_rate_cnt_flag       varchar2(1);
1622     l_dummy               number;
1623     l_salary_type          varchar2(15);
1624     l_rate_or_payscale_id number;
1625     l_grade_step          number;
1626     l_grade_spine_id      number;
1627     l_grade_id            number;
1628     l_sequence            number;
1629     l_parent_spine_id     number;
1630     l_spinal_point_id     number;
1631     l_step_id             number;
1632     l_rate_id             number;
1633     l_rate_type           varchar2(10);
1634     l_element_value       number;
1635     l_parent_spine_name   varchar2(80);
1636     l_proposed_salary     number;
1637     l_change_date         date;
1638     l_assignment_id       number;
1639     l_position_name       varchar2(240);
1640     --UTF8 changes for Bug No : 2615261
1641     l_employee_name       varchar2(310);
1642     l_rate_flag           varchar2(1) := 'N';
1643     l_status              varchar2(1);
1644     l_return_status       varchar2(1);
1645     l_msg_count           number;
1646     l_msg_data            varchar2(1000);
1647     l_assignment_status_type_id   number;
1648     l_assign_stat_cnt             number := 0;
1649 
1650     Cursor C_rate_check is
1651     Select count(*), parent_spine_id
1652       from pay_rates
1653      where business_group_id = p_business_group_id
1654      -- Start bug no 3902996
1655        and parent_spine_id = l_parent_spine_id
1656      -- End bug no 3902996
1657        and rate_type = 'SP'
1658      group by parent_spine_id
1659      having count(*) > 1;
1660 
1661     Cursor C2 is
1662          Select pp.business_group_id,
1663                 /* Start bug #4128475 */
1664                 --pp.name,
1665                 pp.hr_position_name,
1666                 /* End bug #4128475 */
1667                 pp.hr_position_id,
1668                 paf.assignment_id,
1669                 paf.primary_flag,
1670                 paf.assignment_status_type_id,
1671                 paf.person_id,
1672                 paf.organization_id,
1673                 paf.grade_id,
1674                 paf.job_id,
1675                 paf.payroll_id,
1676                 paf.people_group_id,
1677                 paf.normal_hours,
1678                 paf.frequency,
1679                 paf.set_of_books_id,
1680                 ppf.employee_number,
1681                 ppf.first_name,
1682                 ppf.full_name,
1683                 ppf.known_as,
1684                 ppf.last_name,
1685                 ppf.middle_names,
1686                 ppf.title,
1687                 /*For Bug No : 2594575 Start*/
1688                 --Stop extracting secured data of employee
1689                 --Removed the columns in psb_employees table
1690                 /*For Bug No : 2594575 End*/
1691                 ppf.effective_start_date,
1692                 ppb.pay_basis,
1693                 ppb.rate_basis,
1694                 ppb.rate_id
1695           FROM  fnd_sessions fs,
1696                 /* Start bug #4128475 */
1697                 -- psb_positions,
1698                 psb_positions_i pp,
1699                 /* End bug #4128475 */
1700                 per_all_assignments_f paf,
1701                 per_all_people_f ppf,
1702                 pay_all_payrolls_f ppay,
1703                 per_pay_bases ppb
1704           WHERE fs.session_id = userenv('sessionid')
1705             AND fs.effective_date between paf.effective_start_date and paf.effective_end_date
1706             AND pp.data_extract_id = p_data_extract_id
1707             AND pp.hr_position_id     = paf.position_id
1708             AND pp.hr_employee_id     = paf.person_id
1709             AND paf.assignment_id    > l_restart_assignment_id
1710             AND pp.business_group_id = p_business_group_id
1711                 and FS.EFFECTIve_date between ppf.effective_start_date
1712             AND ppf.effective_end_date
1713             AND paf.person_id     = ppf.person_id
1714             AND fs.effective_date between ppay.effective_start_date
1715             AND ppay.effective_end_date
1716             AND paf.payroll_id    = ppay.payroll_id
1717             AND ppay.gl_set_of_books_id = p_set_of_books_id
1718             AND paf.pay_basis_id  = ppb.pay_basis_id
1719             AND paf.assignment_type = 'E'
1720             /*For Bug No : 2109120 Start*/
1721             --AND paf.primary_flag = 'Y'
1722             /*For Bug No : 2109120 End*/
1723 
1724         -- de by org
1725 
1726         -- The following logic is used to restrict the positions for all the
1727 	-- selected organizations, if extract by org is enabled.
1728         -- Otherwise, we will ignore the organizations available
1729         -- in the business group.
1730 
1731             AND (p_extract_by_org = 'N' OR
1732                 (p_extract_by_org = 'Y' and pp.organization_id in
1733 	           (select organization_id
1734 	             from psb_data_extract_orgs
1735 	            where data_extract_id = p_data_extract_id
1736 	              and select_flag = 'Y')))
1737             ORDER BY paf.assignment_id;
1738 
1739    Cursor C_prop_sal is
1740     Select nvl(proposed_salary_n,0) proposed_salary,
1741            change_date
1742       from per_pay_proposals
1743      where assignment_id = l_assignment_id
1744        and change_date =
1745            (select max(change_date) from
1746             per_pay_proposals where
1747             assignment_id = l_assignment_id
1748             and approved = 'Y');
1749 
1750   Cursor C_step is
1751          Select step_id
1752            from Per_spinal_pt_placements_v
1753           where assignment_id = l_assignment_id;
1754 
1755   Cursor C_grade_spine is
1756         SELECT pss.grade_spine_id,pss.spinal_point_id,
1757                pss.sequence
1758           FROM per_spinal_pt_placements_v psp, per_spinal_point_steps pss
1759          WHERE psp.step_id = pss.step_id
1760            AND psp.assignment_id = l_assignment_id;
1761 
1762   Cursor C_session is
1763        SELECT effective_date
1764          FROM FND_SESSIONS
1765         WHERE session_id = USERENV('sessionid');
1766 
1767   Cursor C_grade is
1768         SELECT pgs.grade_id,pgs.parent_spine_id,
1769                pps.name
1770           FROM per_grade_spines pgs, per_parent_spines pps
1771          WHERE grade_spine_id = l_grade_spine_id
1772            and pgs.parent_spine_id = pps.parent_spine_id;
1773 
1774   /* Commented out and changed to enhance performance 23-NOV-2002*/
1775   /*Cursor C_grade_rate is
1776 	 SELECT rate_id
1777 	   FROM PAY_GRADE_RULES
1778 	  WHERE GRADE_OR_SPINAL_POINT_ID = l_grade_id
1779 	    and rate_type = l_rate_type; */
1780 
1781   Cursor C_grade_rate is
1782 	 SELECT rate_or_payscale_id
1783 	   FROM PSB_SALARY_I
1784 	  WHERE GRADE_ID = l_grade_id
1785 	    and SALARY_TYPE = l_salary_type;
1786 
1787   /* Start bug No 3902996 */
1788   CURSOR C_grade_rate_step
1789   IS
1790   SELECT rate_or_payscale_id
1791   FROM PSB_SALARY_I
1792   WHERE GRADE_ID = l_grade_id
1793   AND SALARY_TYPE = l_salary_type
1794   AND grade_step = l_grade_step;
1795   /* End bug no 3902996 */
1796 
1797 
1798   Cursor C_rate is
1799          SELECT rate_or_payscale_id,element_value,
1800                 grade_step,sequence_number
1801           FROM PSB_SALARY_I
1802           WHERE RATE_OR_PAYSCALE_ID = l_rate_id
1803             AND GRADE_ID            = l_grade_id
1804             AND SALARY_TYPE         = l_salary_type
1805             AND DATA_EXTRACT_ID     = p_data_extract_id;
1806 
1807   Cursor C_Value is
1808          SELECT element_value
1809            FROM PSB_SALARY_I
1810           WHERE RATE_OR_PAYSCALE_ID = l_rate_or_payscale_id
1811             AND GRADE_ID            = l_grade_id
1812             AND SALARY_TYPE         = l_salary_type
1813             AND GRADE_STEP          = l_grade_step
1814             AND SEQUENCE_NUMBER     = l_sequence
1815             AND DATA_EXTRACT_ID     = p_data_extract_id;
1816 
1817 
1818   Cursor l_dup_asg_cur is
1819    Select assignment_id
1820      from psb_employees_i
1821    where  hr_position_id = l_hr_position_id
1822      and  hr_employee_id = l_hr_employee_id
1823      and  data_extract_id = p_data_extract_id;
1824 
1825   --
1826   -- Cursor to find the list of assignment_status types
1827   -- that correspond to Terminated Assignment Status
1828   --
1829 
1830   /* Bug 4929586 commenting out the below cursor
1831   Cursor l_assign_stat_csr is
1832    Select assignment_status_type_id
1833      from per_assignment_status_types
1834     where (business_group_id = p_business_group_id
1835        or business_group_id  is null)
1836       and PER_SYSTEM_STATUS = 'TERM_ASSIGN'; */
1837   --
1838   l_api_name		CONSTANT VARCHAR2(30)	:= 'Get_Employee_Information';
1839   l_api_version         CONSTANT NUMBER 	:= 1.0;
1840 
1841 BEGIN
1842 
1843   -- Standard Start of API savepoint
1844 
1845   Savepoint Get_Employee;
1846 
1847   -- Standard call to check for call compatibility.
1848 
1849   if not FND_API.Compatible_API_Call (l_api_version,
1850         	  	    	      p_api_version,
1851    	       	    	 	      l_api_name,
1852 		    	    	      G_PKG_NAME)
1853   then
1854      raise FND_API.G_EXC_UNEXPECTED_ERROR;
1855   end if;
1856 
1857   -- Initialize message list if p_init_msg_list is set to TRUE.
1858 
1859   if FND_API.to_Boolean (p_init_msg_list) then
1860        FND_MSG_PUB.initialize;
1861   end if;
1862 
1863   p_return_status := FND_API.G_RET_STS_SUCCESS;
1864 
1865   -- API body
1866 
1867   l_last_update_date := sysdate;
1868   l_last_updated_by := FND_GLOBAL.USER_ID;
1869   l_last_update_login :=FND_GLOBAL.LOGIN_ID;
1870   l_creation_date     := sysdate;
1871   l_created_by        := FND_GLOBAL.USER_ID;
1872 
1873   Check_Reentry
1874   (p_api_version              => 1.0  ,
1875    p_return_status            => l_return_status,
1876    p_msg_count                => l_msg_count,
1877    p_msg_data                 => l_msg_data,
1878    p_data_extract_id          => p_data_extract_id,
1879    p_process                  => 'Employees Interface',
1880    p_status                   => l_status,
1881    p_restart_id               => l_restart_assignment_id
1882    );
1883 
1884   if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1885      raise FND_API.G_EXC_ERROR;
1886   end if;
1887 
1888   if (l_status <> 'C') then
1889 
1890 
1891   -- Start Bug No 3902996
1892  /*l_rate_cnt_flag := 'N';
1893 
1894   For C_rate_check_rec in C_rate_check
1895   Loop
1896     l_rate_cnt_flag := 'Y' ;
1897     exit;
1898   End Loop; */
1899   -- End Bug No 3902996
1900 
1901   /* Bug 4929586 commenting out the below code
1902   assign_stat_types.delete;
1903   FOR l_assign_stat_rec in l_assign_stat_csr
1904    Loop
1905      l_assign_stat_cnt := l_assign_stat_cnt + 1;
1906      assign_stat_types(l_assign_stat_cnt) := l_assign_stat_rec.assignment_status_type_id;
1907   End Loop; */
1908 l_assignment_id := 0;
1909 
1910   For employee_rec IN C2 LOOP
1911     l_assign_ctr          := l_assign_ctr + 1;
1912     l_assignment_id       := employee_rec.assignment_id;
1913     l_grade_spine_id      := null;
1914     l_spinal_point_id     := null;
1915     l_grade_step          := null;
1916     l_sequence            := null;
1917     l_grade_id            := null;
1918     l_rate_or_payscale_id := null;
1919     l_parent_spine_id     := null;
1920     l_element_value       := 0;
1921     l_proposed_salary     := 0;
1922     l_salary_type         := null;
1923     l_rate_type           := null;
1924     l_rate_id             := null;
1925     l_step_id             := null;
1926     l_position_name       := null;
1927     l_employee_name       := null;
1928     l_hr_position_id      := null;
1929     l_hr_employee_id      := null;
1930     l_hr_position_id      :=  employee_rec.hr_position_id;
1931     l_hr_employee_id      :=  employee_rec.person_id;
1932     l_assignment_status_type_id  := null;
1933     l_assignment_status_type_id := employee_rec.assignment_status_type_id;
1934 
1935     l_process_flag := 'Y';
1936 
1937     /* Bug 4929586
1938     For k in 1..l_assign_stat_cnt
1939     Loop
1940       if (assign_stat_types(k) = l_assignment_status_type_id) then
1941        l_process_flag := 'N';
1942       end if;
1943     End Loop; */
1944 
1945     For l_dup_asg_rec in l_dup_asg_cur
1946     Loop
1947        if (employee_rec.primary_flag = 'Y') then
1948           delete psb_employees_i
1949            where hr_position_id = l_hr_position_id
1950             and  hr_employee_id = l_hr_employee_id
1951             and  data_extract_id = p_data_extract_id;
1952        else
1953           l_process_flag := 'N';
1954        end if;
1955     End Loop;
1956 
1957    if (l_process_flag = 'Y') then
1958 
1959     l_employee_name := employee_rec.first_name||' '||employee_rec.last_name;
1960 
1961     if (employee_rec.hr_position_id is not null) then
1962       /* Start bug #4128475 */
1963       --l_position_name := employee_rec.name;
1964       l_position_name := employee_rec.hr_position_name;
1965       /* End bug #4128475 */
1966     end if;
1967 
1968     l_step_id := null;
1969 
1970     For C_step_rec in C_step
1971     Loop
1972         l_step_id := C_step_rec.step_id;
1973     end loop;
1974 
1975     if l_step_id is not null then
1976        -- 'Grade Scale' Method is Used
1977        l_rate_flag := 'N';
1978        l_salary_type := 'STEP';
1979        l_rate_type := 'SP';
1980 
1981        For C_grade_spine_rec in C_grade_spine
1982        Loop
1983            l_grade_spine_id  := C_grade_spine_rec.grade_spine_id;
1984            l_spinal_point_id := C_grade_spine_rec.spinal_point_id;
1985            l_sequence        := C_grade_spine_rec.sequence;
1986        end loop;
1987 
1988        For C_session_rec in C_session
1989        Loop
1990          l_session_date := C_session_rec.effective_date;
1991        End Loop;
1992 
1993        per_spinal_point_steps_pkg.pop_flds(l_grade_step,
1994                                            l_session_date,
1995                                            l_spinal_point_id,
1996                                            l_grade_spine_id);
1997 
1998       -- Getting Grade_id from per_grade_spines
1999        For C_grade_rec in C_grade
2000        Loop
2001           l_grade_id := C_grade_rec.grade_id;
2002           l_parent_spine_id := C_grade_rec.parent_spine_id;
2003           l_parent_spine_name := C_grade_rec.name;
2004        End Loop;
2005 
2006        -- Start bug no 3902996
2007        l_rate_cnt_flag := 'N';
2008        For C_rate_check_rec in C_rate_check
2009        Loop
2010          l_rate_cnt_flag := 'Y' ;
2011          exit;
2012        End Loop;
2013        -- End bug no 3902996
2014 
2015        -- Start bug no 3902996
2016        --l_rate_or_payscale_id := l_parent_spine_id;
2017        -- End  bug no 3902996
2018 
2019        if (l_rate_cnt_flag = 'Y') then
2020          -- Start bug no 3902996
2021          For C_grade_rate_rec in C_grade_rate_step
2022          Loop
2023            l_rate_or_payscale_id := C_grade_rate_rec.rate_or_payscale_id;
2024          end Loop;
2025          -- End bug no 3902996
2026 
2027          l_element_value := 0;
2028        else
2029          -- Start bug no 3902996
2030          l_rate_or_payscale_id := l_parent_spine_id;
2031          -- End  bug no 3902996
2032 
2033        For C_Value_Rec in C_value
2034        Loop
2035          l_element_value := C_value_rec.element_value;
2036        End Loop;
2037       end if; -- Multiple Rates for single payscale condition
2038 
2039     end if;
2040 
2041     if (l_step_id is null) then
2042        l_salary_type := 'RATE';
2043        l_grade_id    :=  employee_rec.grade_id;
2044        l_rate_type   := 'G';
2045 
2046        For C_grade_rate_rec in C_grade_rate
2047        Loop
2048            l_rate_id := C_grade_rate_rec.rate_or_payscale_id;
2049        End Loop;
2050 
2051        For C_rate_rec in C_rate
2052        Loop
2053        -- Getting rate_id from Psb_salary_i for employee_rec.grade_id
2054          l_rate_or_payscale_id := C_rate_rec.rate_or_payscale_id;
2055          l_element_value       := C_rate_rec.element_value;
2056          l_grade_step          := C_rate_rec.grade_step;
2057          l_sequence            := C_rate_rec.sequence_number;
2058        End Loop;
2059 
2060      end if;
2061 
2062    -- Getting proposed salary for the employee
2063    For C_prop_sal_rec in C_prop_sal
2064    Loop
2065       l_proposed_salary := C_prop_sal_rec.proposed_salary;
2066       l_change_date     := C_prop_sal_rec.change_date;
2067    End Loop;
2068 
2069    if (l_proposed_salary = 0) then
2070         l_proposed_salary := l_element_value;
2071         l_change_date     := employee_rec.effective_start_date;
2072    end if;
2073 
2074    /*For Bug No : 2594575 Start*/
2075    --Stop extracting secured data of employee
2076    --Removed the columns in psb_employees table
2077    /*For Bug No : 2594575 End*/
2078 
2079    INSERT INTO PSB_EMPLOYEES_I
2080    (HR_EMPLOYEE_ID         ,
2081     HR_POSITION_ID         ,
2082     ASSIGNMENT_ID     ,
2083     GRADE_ID          ,
2084     GRADE_STEP        ,
2085     SEQUENCE_NUMBER   ,
2086     PAY_BASIS         ,
2087     RATE_ID           ,
2088     FIRST_NAME        ,
2089     FULL_NAME         ,
2090     KNOWN_AS          ,
2091     LAST_NAME         ,
2092     MIDDLE_NAMES      ,
2093     TITLE             ,
2094     BUSINESS_GROUP_ID ,
2095     EFFECTIVE_START_DATE,
2096     SET_OF_BOOKS_ID,
2097     SALARY_TYPE ,
2098     RATE_OR_PAYSCALE_ID,
2099     ELEMENT_VALUE      ,
2100     PROPOSED_SALARY    ,
2101     CHANGE_DATE        ,
2102     EMPLOYEE_NUMBER    ,
2103     LAST_UPDATE_DATE   ,
2104     LAST_UPDATED_BY    ,
2105     LAST_UPDATE_LOGIN  ,
2106     CREATED_BY         ,
2107     CREATION_DATE      ,
2108     DATA_EXTRACT_ID    )
2109     VALUES
2110     (
2111      employee_rec.person_id,
2112      employee_rec.hr_position_id,
2113      employee_rec.assignment_id,
2114      employee_rec.grade_id,
2115      l_grade_step,
2116      l_sequence,
2117      employee_rec.pay_basis,
2118      employee_rec.rate_id,
2119      employee_rec.first_name,
2120      employee_rec.full_name,
2121      employee_rec.known_as,
2122      employee_rec.last_name,
2123      employee_rec.middle_names,
2124      employee_rec.title,
2125      employee_rec.business_group_id,
2126      employee_rec.effective_start_date,
2127      employee_rec.set_of_books_id,
2128      l_salary_type,
2129      l_rate_or_payscale_id,
2130      l_element_value,
2131      l_proposed_salary,
2132      l_change_date,
2133      employee_rec.employee_number,
2134      l_last_update_date,
2135      l_last_updated_by ,
2136      l_last_update_login ,
2137      l_created_by,
2138      l_creation_date,
2139      p_data_extract_id
2140      );
2141 
2142     if (l_assign_ctr =  PSB_WS_ACCT1.g_checkpoint_save) then
2143         Update_Reentry
2144         ( p_api_version              => 1.0  ,
2145           p_return_status            => l_return_status,
2146           p_msg_count                => l_msg_count,
2147           p_msg_data                 => l_msg_data,
2148           p_data_extract_id          => p_data_extract_id,
2149           p_extract_method           => p_extract_method,
2150           p_process                  => 'Employees Interface',
2151           p_restart_id               => employee_rec.assignment_id
2152         );
2153 
2154        if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2155           raise FND_API.G_EXC_ERROR;
2156        end if;
2157 
2158        commit work;
2159        l_assign_ctr := 0;
2160        Savepoint Get_Employee;
2161      end if;
2162     end if;
2163 
2164 
2165   END LOOP;
2166 
2167   Update_Reentry
2168   ( p_api_version              => 1.0  ,
2169     p_return_status            => l_return_status,
2170     p_msg_count                => l_msg_count,
2171     p_msg_data                 => l_msg_data,
2172     p_data_extract_id          => p_data_extract_id,
2173     p_extract_method           => p_extract_method,
2174     p_process                  => 'Employees Interface',
2175     p_restart_id               => l_assignment_id
2176    );
2177 
2178   if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2179      raise FND_API.G_EXC_ERROR;
2180   end if;
2181 
2182   Reentrant_Process
2183   ( p_api_version              => 1.0  ,
2184     p_return_status            => l_return_status,
2185     p_msg_count                => l_msg_count,
2186     p_msg_data                 => l_msg_data,
2187     p_data_extract_id          => p_data_extract_id,
2188     p_extract_method           => p_extract_method,
2189     p_process                  => 'Employees Interface'
2190   );
2191 
2192   if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2193      raise FND_API.G_EXC_ERROR;
2194   end if;
2195 
2196   commit work;
2197   end if;
2198 
2199 EXCEPTION
2200 
2201    when FND_API.G_EXC_ERROR then
2202      rollback to Get_Employee;
2203      p_return_status := FND_API.G_RET_STS_ERROR;
2204      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
2205                                  p_data  => p_msg_data);
2206      message_token('POSITION_NAME',l_position_name );
2207      message_token('EMPLOYEE_NAME',l_employee_name );
2208      add_message('PSB', 'PSB_POSITION_DETAILS');
2209 
2210    when FND_API.G_EXC_UNEXPECTED_ERROR then
2211      rollback to Get_Employee;
2212      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2213      message_token('POSITION_NAME',l_position_name );
2214      message_token('EMPLOYEE_NAME',l_employee_name );
2215      add_message('PSB', 'PSB_POSITION_DETAILS');
2216      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
2217                                  p_data  => p_msg_data);
2218 
2219 
2220    when OTHERS then
2221      rollback to Get_Employee;
2222      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2223      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
2224                                  p_data  => p_msg_data);
2225      message_token('POSITION_NAME',l_position_name );
2226      message_token('EMPLOYEE_NAME',l_employee_name );
2227      add_message('PSB', 'PSB_POSITION_DETAILS');
2228 
2229      if FND_MSG_PUB.Check_Msg_Level
2230        (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2231      then
2232        FND_MSG_PUB.Add_Exc_Msg
2233           (p_pkg_name => G_PKG_NAME,
2234            p_procedure_name => l_api_name);
2235      end if;
2236 
2237 END Get_Employee_Information;
2238 
2239 
2240 PROCEDURE Get_Costing_Information
2241 ( p_api_version         IN    NUMBER,
2242   p_init_msg_list	IN    VARCHAR2 := FND_API.G_FALSE,
2243   p_commit	    	IN    VARCHAR2 := FND_API.G_FALSE,
2244   p_validation_level	IN    NUMBER   := FND_API.G_VALID_LEVEL_FULL,
2245   p_return_status       OUT   NOCOPY VARCHAR2,
2246   p_msg_count           OUT   NOCOPY NUMBER,
2247   p_msg_data            OUT   NOCOPY VARCHAR2,
2248   p_data_extract_id     IN    NUMBER,
2249   -- de by org
2250   p_extract_by_org      IN    VARCHAR2,
2251   p_extract_method      IN    VARCHAR2,
2252   p_date                IN    DATE,
2253   p_business_group_id   IN    NUMBER,
2254   p_set_of_books_id     IN    NUMBER
2255 ) AS
2256 
2257   l_last_update_date    date;
2258   l_last_updated_by     number;
2259   l_last_update_login   number;
2260   l_creation_date       date;
2261   l_created_by          number;
2262   l_position_name       varchar2(240);
2263   --UTF8 changes for Bug No : 2615261
2264   l_employee_name       varchar2(310);
2265 
2266   l_index        BINARY_INTEGER;
2267   l_cost_segments g_glcostmap_tbl_type;
2268   l_restart_payroll_id NUMBER := 0;
2269   loop_ctr       NUMBER := 0;
2270   loop1_ctr      NUMBER := 0;
2271 
2272   /* Bug#4958997 Start*/
2273   l_yes          VARCHAR2(1)  := 'Y';
2274   l_no           VARCHAR2(1)  := 'N';
2275   /* Bug#4958997 End*/
2276 
2277   /* Start bug #4924031 */
2278   l_id_flex_code    fnd_id_flex_structures.id_flex_code%TYPE;
2279   l_application_id  fnd_id_flex_structures.application_id%TYPE;
2280   l_yes_flag        VARCHAR2(1);
2281   /* End bug #4924031 */
2282 
2283 
2284 
2285   /*  Bug#4958997 Start:
2286       The following logic is used in both queries in Cursor C4 to restrict the positions
2287       for all the selected organizations, if extract by org is enabled. Otherwise, we will
2288       ignore the organizations avaiable in the business group.
2289 
2290       AND  (p_extract_by_org = l_no
2291             OR
2292 	      (p_extract_by_org = l_yes and paf.organization_id in
2293                 (select organization_id
2294                  from psb_data_extract_orgs
2295                  where data_extract_id = p_data_extract_id
2296                  and select_flag = l_yes)))
2297 
2298   */
2299 
2300   Cursor C4 is
2301     Select paf.assignment_id,
2302            paf.position_id,
2303            paf.person_id,
2304            paf.business_group_id,
2305            paf.payroll_id,
2306            pcaf.proportion,
2307            paf.organization_id,
2308            paf.pay_basis_id,
2309            pcaf.cost_allocation_keyflex_id,
2310            pcaf.effective_start_date,
2311            pcaf.effective_end_date
2312       from fnd_sessions fs, per_all_assignments_f paf,
2313            pay_cost_allocations_f pcaf,
2314            pay_cost_allocation_keyflex pcak
2315    where   fs.session_id = userenv('sessionid')
2316      and   fs.effective_date between paf.effective_start_date and paf.effective_end_date
2317      and   paf.business_group_id = p_business_group_id
2318      and   paf.payroll_id > l_restart_payroll_id
2319      and   paf.assignment_id = pcaf.assignment_id
2320      and   pcaf.cost_allocation_keyflex_id
2321            = pcak.cost_allocation_keyflex_id
2322      AND  (p_extract_by_org = l_no OR
2323 	      (p_extract_by_org = l_yes and paf.organization_id in
2324 	         (select organization_id
2325 	           from psb_data_extract_orgs
2326 	          where data_extract_id = p_data_extract_id
2327 	           and select_flag = l_yes)))
2328 
2329     union all
2330     Select paf.assignment_id,
2331            paf.position_id,
2332            paf.person_id,
2333            paf.business_group_id,
2334            paf.payroll_id,
2335            to_number(null),
2336            paf.organization_id,
2337            paf.pay_basis_id,
2338            to_number(null),
2339            to_date(null),
2340            to_date(null)
2341       from fnd_sessions fs, per_all_assignments_f paf
2342    where   fs.session_id = userenv('sessionid')
2343      and   fs.effective_date between paf.effective_start_date and paf.effective_end_date
2344      and   paf.business_group_id = p_business_group_id
2345      and   paf.payroll_id > l_restart_payroll_id
2346      and   not exists (select 1
2347            from pay_cost_allocations_f pcax
2348            where pcax.assignment_id = paf.assignment_id
2349            and fs.session_id = userenv('sessionid')
2350      and   fs.effective_date between pcax.effective_start_date and pcax.effective_end_date)
2351      AND  (p_extract_by_org = l_no OR
2352 	       (p_extract_by_org = l_yes and paf.organization_id in
2353 	          (select organization_id
2354 	            from psb_data_extract_orgs
2355 	           where data_extract_id = p_data_extract_id
2356 	            and select_flag = l_yes)))
2357 
2358     order by  1,2;
2359 
2360     /* Bug#4958997 End */
2361 
2362     l_chart_of_accounts_id       NUMBER;
2363     l_payroll_id NUMBER;
2364     le_payroll_id NUMBER;
2365     le_assignment_id NUMBER;
2366     le_position_id NUMBER;
2367     le_organization_id NUMBER;
2368     le_pay_basis_id NUMBER;
2369     le_element_type_id NUMBER;
2370     l_costing_level varchar2(20);
2371     prev_payroll_id NUMBER := 0;
2372     prev_assignment_id NUMBER := 0;
2373     l_status   varchar2(1);
2374     l_return_status  varchar2(1);
2375     l_msg_count      number;
2376     l_msg_data       varchar2(1000);
2377 
2378    Cursor C_Assign_Check is
2379       Select assignment_id,
2380              first_name,
2381              last_name
2382         from PSB_EMPLOYEES_I
2383        where hr_position_id = le_position_id
2384          and assignment_id =  le_assignment_id
2385          and data_extract_id = p_data_extract_id;
2386 
2387     Cursor C11 is
2388       SELECT gl_account_segment,payroll_cost_segment
2389         FROM pay_payroll_gl_flex_maps
2390        WHERE payroll_id = l_payroll_id
2391          AND gl_set_of_books_id = p_set_of_books_id
2392          AND gl_account_segment in
2393         ( SELECT application_column_name
2394             FROM fnd_id_flex_segments_vl
2395            WHERE id_flex_code = l_id_flex_code      -- bug #4924031
2396              AND application_id = l_application_id  -- bug #4924031
2397              AND enabled_flag = l_yes_flag          -- bug #4924031
2398              AND id_flex_num = l_chart_of_accounts_id )
2399              ORDER BY gl_account_segment;
2400 
2401    Cursor C_chart is
2402      Select chart_of_accounts_id
2403        from gl_sets_of_books
2404       where set_of_books_id = p_set_of_books_id;
2405 
2406    Cursor C_payroll is
2407      Select pay.cost_allocation_keyflex_id ,
2408             pay.effective_start_date,
2409             pay.effective_end_date
2410        from pay_all_payrolls pay, pay_cost_allocation_keyflex pcak
2411       where pay.payroll_id = le_payroll_id
2412         and pay.cost_allocation_keyflex_id = pcak.cost_allocation_keyflex_id;
2413 
2414 
2415    Cursor C_Pay_basis is
2416      Select element_type_id
2417        from pay_input_values piv,
2418             per_pay_bases ppb
2419       where ppb.pay_basis_id = le_pay_basis_id
2420         and piv.input_value_id = ppb.input_value_id;
2421 
2422    Cursor C_Element is
2423      Select pel.cost_allocation_keyflex_id ,
2424             pel.effective_start_date,
2425             pel.effective_end_date
2426        from Pay_element_entries pee,Pay_element_links pel,
2427             pay_cost_allocation_keyflex pcak, Pay_element_types pet
2428       where pee.assignment_id   = le_assignment_id
2429         and pee.element_link_id = pel.element_link_id
2430         and pel.element_type_id = pet.element_type_id
2431         and pet.element_type_id = le_element_type_id
2432         and pel.cost_allocation_keyflex_id = pcak.cost_allocation_keyflex_id;
2433 
2434    Cursor C_Org is
2435      Select hru.cost_allocation_keyflex_id ,
2436             hru.date_from,
2437             hru.date_to
2438        from hr_organization_units hru, pay_cost_allocation_keyflex pcak
2439       where hru.organization_id =  le_organization_id
2440         and hru.cost_allocation_keyflex_id = pcak.cost_allocation_keyflex_id;
2441 
2442     Cursor C_Segcount is
2443      SELECT count(*) seg_count
2444        FROM fnd_id_flex_segments_vl
2445       WHERE id_flex_code = l_id_flex_code      -- bug #4924031
2446         AND application_id = l_application_id  -- bug #4924031
2447         AND enabled_flag = l_yes_flag          -- bug #4924031
2448         AND id_flex_num  = l_chart_of_accounts_id;
2449 
2450    Cursor C_ld_payroll is
2451     select 'exists'
2452       from psb_ld_payroll_maps
2453      where data_extract_id = p_data_extract_id;
2454 
2455    Cursor C_psp is
2456       Select nvl(effective_start_date,p_date) effective_start_date
2457         from psb_ld_payroll_maps plp
2458        where plp.payroll_id             = le_payroll_id
2459          and plp.data_extract_id        = p_data_extract_id;
2460 
2461    l_proportion NUMBER;
2462    l_exists     VARCHAR2(1);
2463    l_psp_flag   VARCHAR2(1);
2464    l_payroll_start_date   DATE;
2465    l_count      NUMBER;
2466    cost_ctr number := 0;
2467 
2468    l_api_name		CONSTANT VARCHAR2(30)	:= 'Get_Costing_Information';
2469    l_api_version        CONSTANT NUMBER 	:= 1.0;
2470 
2471 BEGIN
2472 
2473   -- Standard Start of API savepoint
2474 
2475   Savepoint Get_Costing;
2476 
2477   -- Standard call to check for call compatibility.
2478 
2479   if not FND_API.Compatible_API_Call (l_api_version,
2480             	    	    	      p_api_version,
2481    	       	    	 	      l_api_name,
2482 		    	    	      G_PKG_NAME)
2483   then
2484      raise FND_API.G_EXC_UNEXPECTED_ERROR;
2485   end if;
2486 
2487   -- Initialize message list if p_init_msg_list is set to TRUE.
2488 
2489   if FND_API.to_Boolean (p_init_msg_list) then
2490      FND_MSG_PUB.initialize;
2491   end if;
2492 
2493   p_return_status := FND_API.G_RET_STS_SUCCESS;
2494 
2495   -- API body
2496 
2497   /* Start bug #4924031 */
2498   l_id_flex_code    := 'GL#';
2499   l_application_id  := 101;
2500   l_yes_flag        := 'Y';
2501   /* End bug #4924031 */
2502 
2503   l_last_update_date := sysdate;
2504   l_last_updated_by := FND_GLOBAL.USER_ID;
2505   l_last_update_login :=FND_GLOBAL.LOGIN_ID;
2506   l_creation_date     := sysdate;
2507   l_created_by        := FND_GLOBAL.USER_ID;
2508 
2509   Check_Reentry
2510   (p_api_version              => 1.0  ,
2511    p_return_status            => l_return_status,
2512    p_msg_count                => l_msg_count,
2513    p_msg_data                 => l_msg_data,
2514    p_data_extract_id          => p_data_extract_id,
2515    p_process                  => 'Costing Interface',
2516    p_status                   => l_status,
2517    p_restart_id               => l_restart_payroll_id
2518    );
2519 
2520   if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2521      raise FND_API.G_EXC_ERROR;
2522   end if;
2523 
2524   if (l_status <> 'C') then
2525 
2526   For C_chart_rec in C_chart
2527   Loop
2528     l_chart_of_accounts_id := C_chart_rec.chart_of_accounts_id;
2529   End Loop;
2530 
2531   for C_Seg_Count_Rec in C_Segcount
2532   Loop
2533     l_count := C_Seg_Count_Rec.seg_count;
2534   End Loop;
2535 
2536   For cost_rec in C4 LOOP
2537     loop1_ctr := loop1_ctr + 1;
2538     le_payroll_id    := cost_rec.payroll_id;
2539     le_position_id   := cost_rec.position_id;
2540     le_assignment_id := cost_rec.assignment_id;
2541 
2542     For C_Assign_Rec in C_Assign_Check
2543     Loop
2544 
2545     le_organization_id := cost_rec.organization_id;
2546     le_pay_basis_id := cost_rec.pay_basis_id;
2547     l_position_name := null;
2548     l_employee_name := null;
2549 
2550 
2551     if (cost_rec.person_id is not null) then
2552         l_employee_name := C_Assign_Rec.first_name||C_Assign_Rec.last_name;
2553     end if;
2554 
2555     if (cost_rec.position_id is not null) then
2556        For Pos_Name_Rec in G_Position_Details(p_position_id => cost_rec.position_id)
2557        Loop
2558          l_position_name := Pos_Name_Rec.name;
2559        End Loop;
2560     end if;
2561 
2562     if (le_payroll_id <> prev_payroll_id)  then
2563 
2564        /* Update Reentry */
2565         Update_Reentry
2566         ( p_api_version              => 1.0  ,
2567           p_return_status            => l_return_status,
2568           p_msg_count                => l_msg_count,
2569           p_msg_data                 => l_msg_data,
2570           p_data_extract_id          => p_data_extract_id,
2571           p_extract_method           => p_extract_method,
2572           p_process                  => 'Costing Interface',
2573           p_restart_id               => prev_payroll_id
2574         );
2575 
2576         if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2577            raise FND_API.G_EXC_ERROR;
2578         end if;
2579         commit work;
2580         Savepoint Get_Costing;
2581 
2582       l_psp_flag := FND_API.G_FALSE;
2583       l_payroll_start_date := '';
2584 
2585       For C_psp_rec in C_psp
2586       Loop
2587        l_psp_flag := FND_API.G_TRUE;
2588        l_payroll_start_date := C_psp_rec.effective_start_date;
2589       End Loop;
2590     end if;
2591 
2592     For C_pay_rec in C_Pay_basis
2593     Loop
2594       le_element_type_id := C_pay_rec.element_type_id;
2595     End Loop;
2596 
2597     if not (FND_API.TO_BOOLEAN(l_psp_flag)) then
2598     If (cost_rec.payroll_id <> prev_payroll_id) then
2599         loop_ctr := 0;
2600         l_index := 0;
2601         l_payroll_id := cost_rec.payroll_id;
2602     For Cost_seg_rec in C11
2603     Loop
2604       l_index := l_index + 1;
2605       l_cost_segments(l_index).gl_account_segment := Cost_seg_rec.gl_account_segment;
2606       l_cost_segments(l_index).payroll_cost_segment := Cost_seg_rec.payroll_cost_segment;
2607       loop_ctr := loop_ctr+1;
2608 
2609      End Loop;
2610    end if;
2611 
2612    if (loop_ctr = l_count) then
2613       if (cost_rec.cost_allocation_keyflex_id is not null) then
2614       insert_cost_distribution_row(p_assignment_id => cost_rec.assignment_id,
2615                     p_cost_keyflex_id => cost_rec.cost_allocation_keyflex_id,
2616                     p_business_group_id => p_business_group_id,
2617                     p_costing_level => 'ASSIGNMENT',
2618                     p_index         => l_index,
2619                     p_proportion    => cost_rec.proportion,
2620                     p_start_date    => cost_rec.effective_start_date,
2621                     p_end_date      => cost_rec.effective_end_date,
2622                     p_data_extract_id => p_data_extract_id,
2623                     p_cost_segments   => l_cost_segments,
2624                     p_chart_of_accounts_id => l_chart_of_accounts_id);
2625      end if;
2626 
2627    if (cost_rec.assignment_id <> prev_assignment_id) then
2628    Begin
2629 
2630    For C_payroll_rec in C_payroll
2631    Loop
2632    insert_cost_distribution_row(p_assignment_id => cost_rec.assignment_id,
2633                 p_cost_keyflex_id   => C_payroll_rec.cost_allocation_keyflex_id,
2634                 p_business_group_id => p_business_group_id,
2635                 p_costing_level     => 'PAYROLL',
2636                 p_index             => l_index,
2637                 p_proportion        => 0,
2638                 p_start_date        => C_payroll_rec.effective_start_date,
2639                 p_end_date          => C_payroll_rec.effective_end_date,
2640                 p_data_extract_id   => p_data_extract_id,
2641                 p_cost_segments     => l_cost_segments,
2642                 p_chart_of_accounts_id => l_chart_of_accounts_id);
2643    End Loop;
2644 
2645  end;
2646 
2647  Begin
2648    For C_Element_rec in C_Element
2649    Loop
2650      insert_cost_distribution_row(p_assignment_id => cost_rec.assignment_id,
2651               p_cost_keyflex_id    => C_Element_rec.cost_allocation_keyflex_id,
2652               p_business_group_id  => p_business_group_id,
2653               p_costing_level      => 'ELEMENT LINK',
2654               p_index              => l_index,
2655               p_proportion         => 0,
2656               p_start_date         => C_Element_rec.effective_start_date,
2657               p_end_date           => C_Element_rec.effective_end_date,
2658               p_data_extract_id    => p_data_extract_id,
2659               p_cost_segments      => l_cost_segments,
2660               p_chart_of_accounts_id => l_chart_of_accounts_id);
2661    End Loop;
2662  end;
2663 
2664  Begin
2665    For C_org_rec in C_org
2666    Loop
2667 
2668      insert_cost_distribution_row(p_assignment_id => cost_rec.assignment_id,
2669              p_cost_keyflex_id    => C_org_rec.cost_allocation_keyflex_id,
2670              p_business_group_id  => p_business_group_id,
2671              p_costing_level      => 'ORGANIZATION',
2672              p_index              => l_index,
2673              p_proportion         => 0,
2674              p_start_date         => C_org_rec.date_from,
2675              p_end_date           => C_org_rec.date_to,
2676              p_data_extract_id    => p_data_extract_id,
2677              p_cost_segments      => l_cost_segments,
2678              p_chart_of_accounts_id => l_chart_of_accounts_id);
2679   End Loop;
2680 
2681   end;
2682 
2683  end if;
2684  end if;
2685  else
2686 
2687    Get_LD_Schedule
2688   ( p_api_version           => 1.0,
2689     p_init_msg_list	    => FND_API.G_FALSE,
2690     p_commit	    	    => FND_API.G_FALSE,
2691     p_validation_level	    => FND_API.G_VALID_LEVEL_FULL,
2692     p_return_status  	    => l_return_status,
2693     p_msg_count             => l_msg_count,
2694     p_msg_data              => l_msg_data,
2695     p_assignment_id         => cost_rec.assignment_id,
2696     p_date                  => l_payroll_start_date,
2697     p_effective_start_date  => cost_rec.effective_start_date,
2698     p_effective_end_date    => cost_rec.effective_end_date,
2699     p_chart_of_accounts_id  => l_chart_of_accounts_id,
2700     p_data_extract_id       => p_data_extract_id,
2701     p_business_group_id     => p_business_group_id,
2702     p_set_of_books_id       => p_set_of_books_id,
2703     p_mode                  => 'D');
2704 
2705    if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2706      raise FND_API.G_EXC_ERROR;
2707    end if;
2708 
2709  end if;
2710 
2711  prev_payroll_id := le_payroll_id;
2712  prev_assignment_id := cost_rec.assignment_id;
2713  end loop;
2714 end loop;
2715 
2716  Update_Reentry
2717  ( p_api_version              => 1.0  ,
2718    p_return_status            => l_return_status,
2719    p_msg_count                => l_msg_count,
2720    p_msg_data                 => l_msg_data,
2721    p_data_extract_id          => p_data_extract_id,
2722    p_extract_method           => p_extract_method,
2723    p_process                  => 'Costing Interface',
2724    p_restart_id               => prev_payroll_id
2725  );
2726 
2727  if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2728     raise FND_API.G_EXC_ERROR;
2729  end if;
2730 
2731  Reentrant_Process
2732  ( p_api_version              => 1.0  ,
2733    p_return_status            => l_return_status,
2734    p_msg_count                => l_msg_count,
2735    p_msg_data                 => l_msg_data,
2736    p_data_extract_id          => p_data_extract_id,
2737    p_extract_method           => p_extract_method,
2738    p_process                  => 'Costing Interface'
2739  );
2740 
2741  if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2742     raise FND_API.G_EXC_ERROR;
2743  end if;
2744 
2745  commit work;
2746 end if;
2747 
2748  -- End of API body.
2749 
2750 EXCEPTION
2751    /* Bug 3677529 commenting out the following exception clauses
2752    when FND_API.G_EXC_ERROR then
2753      rollback to Get_Costing;
2754      p_return_status := FND_API.G_RET_STS_ERROR;
2755      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
2756                                  p_data  => p_msg_data);
2757      message_token('POSITION_NAME',l_position_name );
2758      message_token('EMPLOYEE_NAME',l_employee_name );
2759      add_message('PSB', 'PSB_POSITION_DETAILS');
2760 
2761    when FND_API.G_EXC_UNEXPECTED_ERROR then
2762      rollback to Get_Costing;
2763      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2764      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
2765                                  p_data  => p_msg_data);
2766      message_token('POSITION_NAME',l_position_name );
2767      message_token('EMPLOYEE_NAME',l_employee_name );
2768      add_message('PSB', 'PSB_POSITION_DETAILS');  */
2769 
2770    when OTHERS then
2771      rollback to Get_Costing;
2772      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2773      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
2774                                  p_data  => p_msg_data);
2775      message_token('POSITION_NAME',l_position_name );
2776      message_token('EMPLOYEE_NAME',l_employee_name );
2777      add_message('PSB', 'PSB_POSITION_DETAILS');
2778 
2779    if FND_MSG_PUB.Check_Msg_Level
2780        (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2781      then
2782        FND_MSG_PUB.Add_Exc_Msg
2783           (p_pkg_name => G_PKG_NAME,
2784            p_procedure_name => l_api_name);
2785     end if;
2786 
2787 END Get_Costing_Information;
2788 
2789 PROCEDURE Get_LD_Schedule
2790   ( p_api_version           IN    NUMBER,
2791     p_init_msg_list	    IN    VARCHAR2 := FND_API.G_FALSE,
2792     p_commit	    	    IN    VARCHAR2 := FND_API.G_FALSE,
2793     p_validation_level	    IN    NUMBER := FND_API.G_VALID_LEVEL_FULL,
2794     p_return_status  	    OUT	  NOCOPY VARCHAR2,
2795     p_msg_count             OUT   NOCOPY NUMBER,
2796     p_msg_data              OUT   NOCOPY VARCHAR2,
2797     p_assignment_id         IN    NUMBER,
2798     p_date                  IN    DATE,
2799     p_effective_start_date  IN    DATE,
2800     p_effective_end_date    IN    DATE,
2801     p_chart_of_accounts_id  IN    NUMBER,
2802     p_data_extract_id       IN    NUMBER,
2803     p_business_group_id     IN    NUMBER,
2804     p_set_of_books_id       IN    NUMBER,
2805     p_mode                  IN    VARCHAR2 := 'D')
2806 IS
2807 
2808    l_api_name		    CONSTANT VARCHAR2(30)	:= 'Get_LD_Schedule';
2809    l_api_version            CONSTANT NUMBER 	        := 1.0;
2810 
2811    l_proc_executed          VARCHAR2(10);
2812    l_last_update_date       date;
2813    l_last_updated_by        number;
2814    l_last_update_login      number;
2815    l_creation_date          date;
2816    l_created_by             number;
2817    l_segment1               varchar2(30);
2818    l_segment2               varchar2(30);
2819    l_segment3               varchar2(30);
2820    l_segment4               varchar2(30);
2821    l_segment5               varchar2(30);
2822    l_segment6               varchar2(30);
2823    l_segment7               varchar2(30);
2824    l_segment8               varchar2(30);
2825    l_segment9               varchar2(30);
2826    l_segment10              varchar2(30);
2827    l_segment11              varchar2(30);
2828    l_segment12              varchar2(30);
2829    l_segment13              varchar2(30);
2830    l_segment14              varchar2(30);
2831    l_segment15              varchar2(30);
2832    l_segment16              varchar2(30);
2833    l_segment17              varchar2(30);
2834    l_segment18              varchar2(30);
2835    l_segment19              varchar2(30);
2836    l_segment20              varchar2(30);
2837    l_segment21              varchar2(30);
2838    l_segment22              varchar2(30);
2839    l_segment23              varchar2(30);
2840    l_segment24              varchar2(30);
2841    l_segment25              varchar2(30);
2842    l_segment26              varchar2(30);
2843    l_segment27              varchar2(30);
2844    l_segment28              varchar2(30);
2845    l_segment29              varchar2(30);
2846    l_segment30              varchar2(30);
2847    l_ld_element_type_id     NUMBER;
2848    l_return_status          varchar2(1);
2849    v_gldummy                number;
2850 
2851    Cursor C_Element_Type is
2852      Select element_type_id
2853        from fnd_sessions fs, pay_input_values piv,
2854             per_pay_bases ppb,
2855             per_all_assignments_f paf
2856       where fs.session_id = userenv('sessionid')
2857         and fs.effective_date between paf.effective_start_date and paf.effective_end_date
2858         and paf.assignment_id = p_assignment_id
2859         and ppb.pay_basis_id  = paf.pay_basis_id
2860         and piv.input_value_id = ppb.input_value_id;
2861 
2862    tf    BOOLEAN;
2863    nsegs NUMBER;
2864    segs  FND_FLEX_EXT.SegmentArray;
2865    r     VARCHAR2(500);
2866 
2867 BEGIN
2868 
2869   -- Standard Start of API savepoint
2870 
2871   Savepoint Get_LD_Schedule;
2872 
2873   -- Standard call to check for call compatibility.
2874 
2875   if not FND_API.Compatible_API_Call (l_api_version,
2876             	    	    	      p_api_version,
2877    	       	    	 	      l_api_name,
2878 		    	    	      G_PKG_NAME)
2879   then
2880      raise FND_API.G_EXC_UNEXPECTED_ERROR;
2881   end if;
2882 
2883   -- Initialize message list if p_init_msg_list is set to TRUE.
2884 
2885   if FND_API.to_Boolean (p_init_msg_list) then
2886      FND_MSG_PUB.initialize;
2887   end if;
2888 
2889   p_return_status := FND_API.G_RET_STS_SUCCESS;
2890 
2891   -- API body
2892   l_last_update_date := sysdate;
2893   l_last_updated_by := FND_GLOBAL.USER_ID;
2894   l_last_update_login :=FND_GLOBAL.LOGIN_ID;
2895   l_creation_date     := sysdate;
2896   l_created_by        := FND_GLOBAL.USER_ID;
2897 
2898   -- To obtain the element_type_id associated to the assignment
2899 
2900   For C_Element_Type_Rec in C_Element_Type
2901   Loop
2902       l_ld_element_type_id := C_Element_Type_Rec.element_type_id;
2903   End Loop;
2904 
2905   -- Call LD API to get the set of distributions for the
2906   -- assignment valid on p_date
2907 
2908   PSP_LABOR_DIST.Get_Distribution_Lines
2909     (p_proc_executed => l_proc_executed,
2910      p_person_id => null,
2911      p_sub_line_id => null,
2912      p_assignment_id => p_assignment_id,
2913      p_element_type_id => l_ld_element_type_id,
2914      p_payroll_start_date => p_date,
2915      p_daily_rate => 100,
2916      p_effective_date => p_date,
2917      p_mode => p_mode,
2918      p_business_group_id => p_business_group_id,
2919      p_set_of_books_id => p_set_of_books_id,
2920      p_return_status => l_return_status);
2921 
2922   if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2923      raise FND_API.G_EXC_ERROR;
2924   end if;
2925 
2926    For i in 1..PSP_LABOR_DIST.g_num_dist
2927    Loop
2928      l_segment1   := null;
2929      l_segment2   := null;
2930      l_segment3   := null;
2931      l_segment4   := null;
2932      l_segment5   := null;
2933      l_segment6   := null;
2934      l_segment7   := null;
2935      l_segment8   := null;
2936      l_segment9   := null;
2937      l_segment10  := null;
2938      l_segment11  := null;
2939      l_segment12  := null;
2940      l_segment13  := null;
2941      l_segment14  := null;
2942      l_segment15  := null;
2943      l_segment16  := null;
2944      l_segment17  := null;
2945      l_segment18  := null;
2946      l_segment19  := null;
2947      l_segment20  := null;
2948      l_segment21  := null;
2949      l_segment22  := null;
2950      l_segment23  := null;
2951      l_segment24  := null;
2952      l_segment25  := null;
2953      l_segment26  := null;
2954      l_segment27  := null;
2955      l_segment28  := null;
2956      l_segment29  := null;
2957      l_segment30  := null;
2958 
2959     if (PSP_LABOR_DIST.g_charging_instructions(i).gl_code_combination_id is not null)  then
2960     r   := null;
2961     tf  := FND_FLEX_EXT.GET_SEGMENTS('SQLGL','GL#',p_chart_of_accounts_id,PSP_LABOR_DIST.g_charging_instructions(i).gl_code_combination_id,nsegs,segs);
2962 
2963     if (tf) then
2964        r := 'VALID:  ';
2965        for i in 1..nsegs loop
2966           r := r|| '(' || segs(i)||')';
2967            if (i = 1) then
2968               l_segment1 := segs(i);
2969            end if;
2970            if (i = 2) then
2971               l_segment2 := segs(i);
2972            end if;
2973            if (i = 3) then
2974               l_segment3 := segs(i);
2975            end if;
2976            if (i = 4) then
2977               l_segment4 := segs(i);
2978            end if;
2979            if (i = 5) then
2980               l_segment5 := segs(i);
2981            end if;
2982            if (i = 6) then
2983               l_segment6 := segs(i);
2984            end if;
2985            if (i = 7) then
2986               l_segment7 := segs(i);
2987            end if;
2988            if (i = 8) then
2989               l_segment8 := segs(i);
2990            end if;
2991            if (i = 9) then
2992               l_segment9 := segs(i);
2993            end if;
2994            if (i = 10) then
2995               l_segment10 := segs(i);
2996            end if;
2997            if (i = 11) then
2998               l_segment11 := segs(i);
2999            end if;
3000            if (i = 12) then
3001               l_segment12 := segs(i);
3002            end if;
3003            if (i = 13) then
3004               l_segment13 := segs(i);
3005            end if;
3006            if (i = 14) then
3007               l_segment14 := segs(i);
3008            end if;
3009            if (i = 15) then
3010               l_segment15 := segs(i);
3011            end if;
3012            if (i = 16) then
3013               l_segment16 := segs(i);
3014            end if;
3015            if (i = 17) then
3016               l_segment17 := segs(i);
3017            end if;
3018            if (i = 18) then
3019               l_segment18 := segs(i);
3020            end if;
3021            if (i = 19) then
3022               l_segment19 := segs(i);
3023            end if;
3024            if (i = 20) then
3025               l_segment20 := segs(i);
3026            end if;
3027            if (i = 21) then
3028               l_segment21 := segs(i);
3029            end if;
3030            if (i = 22) then
3031               l_segment22 := segs(i);
3032            end if;
3033            if (i = 23) then
3034               l_segment23 := segs(i);
3035            end if;
3036            if (i = 24) then
3037               l_segment24 := segs(i);
3038            end if;
3039            if (i = 25) then
3040               l_segment25 := segs(i);
3041            end if;
3042            if (i = 26) then
3043               l_segment26 := segs(i);
3044            end if;
3045            if (i = 27) then
3046               l_segment27 := segs(i);
3047            end if;
3048            if (i = 28) then
3049               l_segment28 := segs(i);
3050            end if;
3051            if (i = 29) then
3052               l_segment29 := segs(i);
3053            end if;
3054            if (i = 30) then
3055               l_segment30 := segs(i);
3056            end if;
3057 
3058         end loop;
3059         end if;
3060       end if;
3061 
3062         Insert into psb_cost_distributions_i
3063                (DATA_EXTRACT_ID              ,
3064                 ASSIGNMENT_ID                ,
3065                 BUSINESS_GROUP_ID            ,
3066                 COSTING_LEVEL                ,
3067                 PROPORTION                   ,
3068                 CHART_OF_ACCOUNTS_ID         ,
3069                 EFFECTIVE_START_DATE         ,
3070                 EFFECTIVE_END_DATE           ,
3071                 SEGMENT1                     ,
3072                 SEGMENT2                     ,
3073                 SEGMENT3                     ,
3074                 SEGMENT4                     ,
3075                 SEGMENT5                     ,
3076                 SEGMENT6                     ,
3077                 SEGMENT7                     ,
3078                 SEGMENT8                     ,
3079                 SEGMENT9                     ,
3080                 SEGMENT10                    ,
3081                 SEGMENT11                    ,
3082                 SEGMENT12                    ,
3083                 SEGMENT13                    ,
3084                 SEGMENT14                    ,
3085                 SEGMENT15                    ,
3086                 SEGMENT16                    ,
3087                 SEGMENT17                    ,
3088                 SEGMENT18                    ,
3089                 SEGMENT19                    ,
3090                 SEGMENT20                    ,
3091                 SEGMENT21                    ,
3092                 SEGMENT22                    ,
3093                 SEGMENT23                    ,
3094                 SEGMENT24                    ,
3095                 SEGMENT25                    ,
3096                 SEGMENT26                    ,
3097                 SEGMENT27                    ,
3098                 SEGMENT28                    ,
3099                 SEGMENT29                    ,
3100                 SEGMENT30                    ,
3101                 LAST_UPDATE_DATE             ,
3102                 LAST_UPDATED_BY              ,
3103                 LAST_UPDATE_LOGIN            ,
3104                 CREATED_BY                   ,
3105                 CREATION_DATE                ,
3106                 PROJECT_ID                   ,
3107                 TASK_ID                      ,
3108                 AWARD_ID                     ,
3109                 EXPENDITURE_TYPE             ,
3110                 EXPENDITURE_ORGANIZATION_ID  ,
3111                 DESCRIPTION                  )
3112                 values
3113                 (
3114                   p_data_extract_id,
3115                   p_assignment_id,
3116                   p_business_group_id,
3117                   'ASSIGNMENT',
3118                   --bug 3677529 added nvl function in the following line
3119                   NVL(PSP_LABOR_DIST.g_charging_instructions(i).percent,0),
3120                   p_chart_of_accounts_id,
3121                   PSP_LABOR_DIST.g_charging_instructions(i).effective_start_date,
3122                   PSP_LABOR_DIST.g_charging_instructions(i).effective_end_date,
3123                   l_segment1,
3124                   l_segment2,
3125                   l_segment3,
3126                   l_segment4,
3127                   l_segment5,
3128                   l_segment6,
3129                   l_segment7,
3130                   l_segment8,
3131                   l_segment9,
3132                   l_segment10,
3133                   l_segment11,
3134                   l_segment12,
3135                   l_segment13,
3136                   l_segment14,
3137                   l_segment15,
3138                   l_segment16,
3139                   l_segment17,
3140                   l_segment18,
3141                   l_segment19,
3142                   l_segment20,
3143                   l_segment21,
3144                   l_segment22,
3145                   l_segment23,
3146                   l_segment24,
3147                   l_segment25,
3148                   l_segment26,
3149                   l_segment27,
3150                   l_segment28,
3151                   l_segment29,
3152                   l_segment30,
3153                   l_last_update_date,
3154                   l_last_updated_by,
3155                   l_last_update_login,
3156                   l_created_by,
3157                   l_creation_date,
3158                   PSP_LABOR_DIST.g_charging_instructions(i).project_id,
3159                   PSP_LABOR_DIST.g_charging_instructions(i).task_id,
3160                   PSP_LABOR_DIST.g_charging_instructions(i).award_id,
3161                   PSP_LABOR_DIST.g_charging_instructions(i).expenditure_type,
3162                   PSP_LABOR_DIST.g_charging_instructions(i).expenditure_organization_id,
3163                   PSP_LABOR_DIST.g_charging_instructions(i).description
3164                );
3165    End Loop;
3166 
3167   -- End of API body.
3168 
3169 
3170 EXCEPTION
3171    /* Bug 3677529 commented out the following exception clauses
3172    when FND_API.G_EXC_ERROR then
3173      rollback to Get_LD_Schedule;
3174      p_return_status := FND_API.G_RET_STS_ERROR;
3175      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
3176                                  p_data  => p_msg_data);
3177 
3178    when FND_API.G_EXC_UNEXPECTED_ERROR then
3179      rollback to Get_LD_Schedule;
3180      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3181      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
3182                                  p_data  => p_msg_data);
3183    */
3184 
3185    when OTHERS then
3186      rollback to Get_LD_Schedule;
3187      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3188      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
3189                                  p_data  => p_msg_data);
3190     /* Bug 3677529 Start */
3191     IF FND_MSG_PUB.Check_Msg_Level
3192        (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3193     THEN
3194        FND_MSG_PUB.Add_Exc_Msg
3195           (p_pkg_name => G_PKG_NAME,
3196            p_procedure_name => l_api_name);
3197     END IF;
3198     /* Bug 3677529 End */
3199 END Get_LD_Schedule;
3200 
3201 PROCEDURE insert_cost_distribution_row(
3202     P_ASSIGNMENT_ID  IN number,
3203     P_COST_KEYFLEX_ID IN number,
3204     P_BUSINESS_GROUP_ID  in number,
3205     P_COSTING_LEVEL  in varchar2,
3206     P_INDEX          in binary_integer,
3207     P_PROPORTION     in number,
3208     P_START_DATE     in date,
3209     P_END_DATE       in date,
3210     P_DATA_EXTRACT_ID    in number,
3211     P_COST_SEGMENTS in g_glcostmap_tbl_type,
3212     P_CHART_OF_ACCOUNTS_ID in number) AS
3213 
3214     l_last_update_date    date;
3215     l_last_updated_by     number;
3216     l_last_update_login   number;
3217     l_creation_date       date;
3218     l_created_by          number;
3219     l_start_date          date;
3220     l_end_date            date;
3221     l_percent             number;
3222 
3223     l_segment1            varchar2(30);
3224     l_segment2            varchar2(30);
3225     l_segment3            varchar2(30);
3226     l_segment4            varchar2(30);
3227     l_segment5            varchar2(30);
3228     l_segment6            varchar2(30);
3229     l_segment7            varchar2(30);
3230     l_segment8            varchar2(30);
3231     l_segment9            varchar2(30);
3232     l_segment10           varchar2(30);
3233     l_segment11           varchar2(30);
3234     l_segment12           varchar2(30);
3235     l_segment13           varchar2(30);
3236     l_segment14           varchar2(30);
3237     l_segment15           varchar2(30);
3238     l_segment16           varchar2(30);
3239     l_segment17           varchar2(30);
3240     l_segment18           varchar2(30);
3241     l_segment19           varchar2(30);
3242     l_segment20           varchar2(30);
3243     l_segment21           varchar2(30);
3244     l_segment22           varchar2(30);
3245     l_segment23           varchar2(30);
3246     l_segment24           varchar2(30);
3247     l_segment25           varchar2(30);
3248     l_segment26           varchar2(30);
3249     l_segment27           varchar2(30);
3250     l_segment28           varchar2(30);
3251     l_segment29           varchar2(30);
3252     l_segment30           varchar2(30);
3253 
3254 
3255  begin
3256 
3257   l_last_update_date := sysdate;
3258   l_last_updated_by := FND_GLOBAL.USER_ID;
3259   l_last_update_login :=FND_GLOBAL.LOGIN_ID;
3260   l_creation_date     := sysdate;
3261   l_created_by        := FND_GLOBAL.USER_ID;
3262 
3263   l_percent   :=  p_proportion*100;
3264   l_segment1   := null;
3265   l_segment2   := null;
3266   l_segment3   := null;
3267   l_segment4   := null;
3268   l_segment5   := null;
3269   l_segment6   := null;
3270   l_segment7   := null;
3271   l_segment8   := null;
3272   l_segment9   := null;
3273   l_segment10  := null;
3274   l_segment11  := null;
3275   l_segment12  := null;
3276   l_segment13  := null;
3277   l_segment14  := null;
3278   l_segment15  := null;
3279   l_segment16  := null;
3280   l_segment17  := null;
3281   l_segment18  := null;
3282   l_segment19  := null;
3283   l_segment20  := null;
3284   l_segment21  := null;
3285   l_segment22  := null;
3286   l_segment23  := null;
3287   l_segment24  := null;
3288   l_segment25  := null;
3289   l_segment26  := null;
3290   l_segment27  := null;
3291   l_segment28  := null;
3292   l_segment29  := null;
3293   l_segment30  := null;
3294 
3295   For K in 1..p_index loop
3296     if (p_cost_segments(K).gl_account_segment = 'SEGMENT1') then
3297        l_segment1 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3298     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT2') then
3299        l_segment2 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3300     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT3') then
3301        l_segment3 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3302     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT4') then
3303        l_segment4 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3304     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT5') then
3305        l_segment5 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3306     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT6') then
3307        l_segment6 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3308     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT7') then
3309        l_segment7 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3310     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT8') then
3311        l_segment8 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3312     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT9') then
3313        l_segment9 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3314     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT10') then
3315        l_segment10 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3316     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT11') then
3317        l_segment11 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3318     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT12') then
3319        l_segment12 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3320     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT13') then
3321        l_segment13 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3322     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT14') then
3323        l_segment14 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3324     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT15') then
3325        l_segment15 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3326     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT16') then
3327        l_segment16 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3328     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT17') then
3329        l_segment17 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3330     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT18') then
3331        l_segment18 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3332     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT19') then
3333        l_segment19 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3334     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT20') then
3335        l_segment20 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3336     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT21') then
3337        l_segment21 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3338     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT22') then
3339        l_segment22 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3340     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT23') then
3341        l_segment23 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3342     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT24') then
3343        l_segment24 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3344     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT25') then
3345        l_segment25 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3346     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT26') then
3347        l_segment26 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3348     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT27') then
3349        l_segment27 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3350     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT28') then
3351        l_segment28 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3352     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT29') then
3353        l_segment29 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3354     elsif (p_cost_segments(K).gl_account_segment = 'SEGMENT30') then
3355        l_segment30 := get_segment_val(p_cost_segments(K).payroll_cost_segment,p_cost_keyflex_id);
3356     end if;
3357   end loop;
3358 
3359   /* Change to Static Sql */
3360         Insert into psb_cost_distributions_i
3361                (DATA_EXTRACT_ID              ,
3362                 ASSIGNMENT_ID                ,
3363                 BUSINESS_GROUP_ID            ,
3364                 COSTING_LEVEL                ,
3365                 PROPORTION                   ,
3366                 CHART_OF_ACCOUNTS_ID         ,
3367                 EFFECTIVE_START_DATE         ,
3368                 EFFECTIVE_END_DATE           ,
3369                 COST_ALLOCATION_KEYFLEX_ID   ,
3370                 SEGMENT1                     ,
3371                 SEGMENT2                     ,
3372                 SEGMENT3                     ,
3373                 SEGMENT4                     ,
3374                 SEGMENT5                     ,
3375                 SEGMENT6                     ,
3376                 SEGMENT7                     ,
3377                 SEGMENT8                     ,
3378                 SEGMENT9                     ,
3379                 SEGMENT10                    ,
3380                 SEGMENT11                    ,
3381                 SEGMENT12                    ,
3382                 SEGMENT13                    ,
3383                 SEGMENT14                    ,
3384                 SEGMENT15                    ,
3385                 SEGMENT16                    ,
3386                 SEGMENT17                    ,
3387                 SEGMENT18                    ,
3388                 SEGMENT19                    ,
3389                 SEGMENT20                    ,
3390                 SEGMENT21                    ,
3391                 SEGMENT22                    ,
3392                 SEGMENT23                    ,
3393                 SEGMENT24                    ,
3394                 SEGMENT25                    ,
3395                 SEGMENT26                    ,
3396                 SEGMENT27                    ,
3397                 SEGMENT28                    ,
3398                 SEGMENT29                    ,
3399                 SEGMENT30                    ,
3400                 LAST_UPDATE_DATE             ,
3401                 LAST_UPDATED_BY              ,
3402                 LAST_UPDATE_LOGIN            ,
3403                 CREATED_BY                   ,
3404                 CREATION_DATE                )
3405                 values
3406                 (
3407                   p_data_extract_id,
3408                   p_assignment_id,
3409                   p_business_group_id,
3410                   p_costing_level,
3411                   l_percent,
3412                   p_chart_of_accounts_id,
3413                   p_start_date,
3414                   p_end_date,
3415                   p_cost_keyflex_id,
3416                   l_segment1,
3417                   l_segment2,
3418                   l_segment3,
3419                   l_segment4,
3420                   l_segment5,
3421                   l_segment6,
3422                   l_segment7,
3423                   l_segment8,
3424                   l_segment9,
3425                   l_segment10,
3426                   l_segment11,
3427                   l_segment12,
3428                   l_segment13,
3429                   l_segment14,
3430                   l_segment15,
3431                   l_segment16,
3432                   l_segment17,
3433                   l_segment18,
3434                   l_segment19,
3435                   l_segment20,
3436                   l_segment21,
3437                   l_segment22,
3438                   l_segment23,
3439                   l_segment24,
3440                   l_segment25,
3441                   l_segment26,
3442                   l_segment27,
3443                   l_segment28,
3444                   l_segment29,
3445                   l_segment30,
3446                   l_last_update_date,
3447                   l_last_updated_by,
3448                   l_last_update_login,
3449                   l_created_by,
3450                   l_creation_date
3451                );
3452  end;
3453 
3454 PROCEDURE Get_Attributes
3455 ( p_api_version         IN    NUMBER,
3456   p_init_msg_list	IN    VARCHAR2 := FND_API.G_FALSE,
3457   p_commit	    	IN    VARCHAR2 := FND_API.G_FALSE,
3458   p_validation_level	IN    NUMBER   := FND_API.G_VALID_LEVEL_FULL,
3459   p_return_status       OUT   NOCOPY VARCHAR2,
3460   p_msg_count           OUT   NOCOPY NUMBER,
3461   p_msg_data            OUT   NOCOPY VARCHAR2,
3462   p_data_extract_id     IN    NUMBER,
3463   p_extract_method      IN    VARCHAR2,
3464   p_business_group_id   IN    NUMBER
3465 ) AS
3466 
3467     l_last_update_date    date;
3468     l_last_updated_by     number;
3469     l_last_update_login   number;
3470     l_creation_date       date;
3471     l_created_by          number;
3472     l_job_id_flex_num     number;
3473     l_restart_attribute_id  number := 0;
3474     l_fin_attribute_id      number := 0;
3475     l_job_stmt            varchar2(1000);
3476 
3477     Cursor C5 is
3478           SELECT attribute_id,business_group_id,
3479                  name,definition_type,
3480                  definition_structure,
3481                  definition_table,
3482                  definition_column,
3483                  data_type,
3484                  system_attribute_type,
3485                  attribute_type_id,
3486                  value_table_flag
3487            FROM  PSB_ATTRIBUTES_VL
3488            WHERE business_group_id = p_business_group_id
3489              AND attribute_id > l_restart_attribute_id
3490            ORDER BY attribute_id;
3491 
3492     Cursor C_flex_num is
3493         Select job_structure
3494           from per_business_groups
3495          where business_group_id = p_business_group_id;
3496 
3497     Cursor C_Organizations is
3498        Select organization_id, name
3499          from hr_organization_units
3500         where business_group_id = p_business_group_id;
3501 
3502     l_lookup_type     varchar2(30);
3503     l_lookup_code     varchar2(30);
3504     l_lookup_meaning  varchar2(80);
3505 
3506     /* Increased the size of the following variable
3507        from 80 to 240 as part of bug fix 3544573 */
3508     l_description     varchar2(240);
3509 
3510    /* For Bug No. 2549515 : Start
3511       Size of following variables increased from 30 to 50 */
3512     l_select_table    varchar2(50);
3513     l_select_column   varchar2(50);
3514    /* For Bug No. 2549515 : End */
3515 
3516     v_jcursorid             INTEGER;
3517     v_jdummy                INTEGER;
3518 
3519     Cursor C6 is
3520          Select lookup_code,meaning,description
3521            from fnd_common_lookups
3522           where lookup_type = l_lookup_type;
3523 
3524     lsql_stmt                 varchar2(500);
3525     v_cursorid                integer;
3526     v_dummy                   integer;
3527     l_attribute_name          varchar2(30);
3528     l_definition_type         varchar2(10);
3529     l_definition_structure    varchar2(30);
3530     l_definition_table        varchar2(30);
3531     l_definition_column       varchar2(30);
3532     l_attribute_id            number;
3533     l_attribute_value_id      number;
3534     l_attribute_type_id       number;
3535     l_application_id          number;
3536     l_id_flex_code            varchar2(4);
3537     l_application_table_name  varchar2(30);
3538     l_set_defining_column     varchar2(30);
3539     l_id_flex_num             number;
3540     l_application_column_name varchar2(30);
3541     l_kflex_value_set_id      number;
3542     l_dflex_value_set_id      number;
3543     l_context_column_name     varchar2(30);
3544     l_desc_flex_context_code  varchar2(30);
3545     kvset                     fnd_vset.valueset_r;
3546     kfmt                      fnd_vset.valueset_dr;
3547     kfound                    BOOLEAN;
3548     krow                      NUMBER;
3549     kvalue                    fnd_vset.value_dr;
3550     dvset                     fnd_vset.valueset_r;
3551     dfmt                      fnd_vset.valueset_dr;
3552     dfound                    BOOLEAN;
3553     drow                      NUMBER;
3554     dvalue                    fnd_vset.value_dr;
3555     vdef_col1                 varchar2(100);
3556     vdef_col2                 number;
3557     vdef_col3                 date;
3558     vdef_col                  varchar2(100);
3559     l_status                  varchar2(1);
3560     l_return_status           varchar2(1);
3561     prev_attribute_id         number := -1;
3562     --UTF8 changes for Bug No : 2615261
3563     lr_attribute_value        psb_attribute_values_i.attribute_value%TYPE;
3564     lr_value_id               number := '';
3565     lr_attribute_id           number;
3566     l_attr_dummy              number := 0;
3567     l_msg_count               number;
3568     l_msg_data                varchar2(1000);
3569 
3570     /* Bug 4075170 Start */
3571     -- Local Variable that will hold the datatype of the attribute.
3572     l_data_type               psb_attributes_vl.data_type%TYPE;
3573     l_param_info              VARCHAR2(4000);
3574     l_debug_info              VARCHAR2(4000);
3575     /* Bug 4075170 End */
3576 
3577     Cursor C_table is
3578        Select name,select_column,
3579               substr(select_table,1,instr(select_table,' ',1)) select_table
3580          from psb_attribute_types
3581         where attribute_type_id = l_attribute_type_id;
3582 
3583    Cursor C_Attribute is
3584       Select attribute_value_id
3585         from psb_attribute_values
3586        where attribute_id = lr_attribute_id
3587          and attribute_value = lr_attribute_value
3588          and data_extract_id = p_data_extract_id;
3589 
3590    Cursor C_key_11 is
3591        Select application_id,id_flex_code,
3592               application_table_name,
3593               set_defining_column_name
3594         from  fnd_id_flexs
3595        where id_flex_name = l_definition_structure;
3596 
3597    Cursor C_key_22 is
3598      SELECT fstr.id_flex_num, fseg.application_column_name,
3599             fseg.flex_value_set_id
3600        FROM fnd_id_flex_structures_vl fstr,fnd_id_flex_segments_vl fseg
3601       WHERE fstr.application_id = l_application_id
3602         AND fstr.id_flex_code   = l_id_flex_code
3603         AND fstr.id_flex_structure_name = l_definition_table
3604         AND fstr.id_flex_code   = fseg.id_flex_code
3605         AND fstr.id_flex_num    = fseg.id_flex_num
3606         AND fseg.segment_name   = l_definition_column
3607         AND fstr.application_id = fseg.application_id;  -- bug #4924031;
3608 
3609    Cursor C_dff_11 is
3610      Select application_id,application_table_name,
3611             context_column_name
3612        from fnd_descriptive_flexs_vl
3613       where descriptive_flexfield_name = l_definition_structure;
3614 
3615    Cursor C_dff_22 is
3616     Select fcon.descriptive_flex_context_code,
3617            fcol.application_column_name,
3618            fcol.flex_value_set_id
3619      from  fnd_descr_flex_contexts_vl fcon,fnd_descr_flex_column_usages fcol
3620      where fcon.application_id = fcol.application_id
3621        and fcon.descriptive_flexfield_name = l_definition_structure
3622        and fcon.descriptive_flex_context_code = l_definition_table
3623        and fcon.descriptive_flexfield_name = fcol.descriptive_flexfield_name
3624     and fcon.descriptive_flex_context_code = fcol.descriptive_flex_context_code
3625     and fcol.end_user_column_name = l_definition_column;
3626 
3627    Cursor C_Qc_66 is
3628      Select lookup_type
3629        from per_common_lookup_types_v
3630       where lookup_type_meaning = l_definition_table;
3631 
3632    Cursor C_Jobs is
3633      Select job_id, name
3634        from per_jobs
3635      where  business_group_id = p_business_group_id;
3636 
3637   l_api_name		CONSTANT VARCHAR2(30)	:= 'Get_Attributes';
3638   l_api_version         CONSTANT NUMBER 	:= 1.0;
3639 
3640   l_message_text        VARCHAR2(2000);
3641 
3642 BEGIN
3643   /* Bug 4075170 Start */
3644   l_param_info := 'data_extract_id::'||p_data_extract_id
3645                    ||', extract_method::'||p_extract_method
3646                    ||', business_grp_id::'||p_business_group_id;
3647   l_debug_info := 'Starting Get_Attributes API';
3648   /* Bug 4075170 End */
3649 
3650   -- Standard Start of API savepoint
3651 
3652   Savepoint Get_Attributes;
3653 
3654   -- Standard call to check for call compatibility.
3655 
3656   if not FND_API.Compatible_API_Call (l_api_version,
3657           	    	    	      p_api_version,
3658    	       	    	 	      l_api_name,
3659 		    	    	      G_PKG_NAME)
3660   then
3661      raise FND_API.G_EXC_UNEXPECTED_ERROR;
3662   end if;
3663 
3664   -- Initialize message list if p_init_msg_list is set to TRUE.
3665 
3666   if FND_API.to_Boolean (p_init_msg_list) then
3667      FND_MSG_PUB.initialize;
3668   end if;
3669 
3670   p_return_status := FND_API.G_RET_STS_SUCCESS;
3671 
3672   -- API body
3673 
3674   l_last_update_date := sysdate;
3675   l_last_updated_by := FND_GLOBAL.USER_ID;
3676   l_last_update_login :=FND_GLOBAL.LOGIN_ID;
3677   l_creation_date     := sysdate;
3678   l_created_by        := FND_GLOBAL.USER_ID;
3679 
3680   Check_Reentry
3681   (p_api_version              => 1.0  ,
3682    p_return_status            => l_return_status,
3683    p_msg_count                => l_msg_count,
3684    p_msg_data                 => l_msg_data,
3685    p_data_extract_id          => p_data_extract_id,
3686    p_process                  => 'Attribute Values Interface',
3687    p_status                   => l_status,
3688    p_restart_id               => l_restart_attribute_id
3689    );
3690 
3691   if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3692      raise FND_API.G_EXC_ERROR;
3693   end if;
3694 
3695  if (l_status <> 'C') then
3696  For attribute_rec in C5 LOOP
3697      l_attribute_name       := null;
3698      l_definition_type      := null;
3699      l_attribute_name       := attribute_rec.name;
3700      l_definition_type      := attribute_rec.definition_type;
3701      l_definition_structure := attribute_rec.definition_structure;
3702      l_definition_table     := attribute_rec.definition_table;
3703      l_definition_column    := attribute_rec.definition_column;
3704      l_fin_attribute_id     := attribute_rec.attribute_id;
3705 
3706      /* Bug 4075170 Start */
3707      -- Assign the datatype of the current attribute.
3708      l_data_type  := attribute_rec.data_type;
3709      l_debug_info := 'Starting for attribute '||l_attribute_name
3710                      ||', of data type '||l_data_type;
3711      /* Bug 4075170 End */
3712 
3713      if ((l_fin_attribute_id <> prev_attribute_id) and (prev_attribute_id <> -1)) then
3714         Update_Reentry
3715         ( p_api_version              => 1.0  ,
3716           p_return_status            => l_return_status,
3717           p_msg_count                => l_msg_count,
3718           p_msg_data                 => l_msg_data,
3719           p_data_extract_id          => p_data_extract_id,
3720           p_extract_method           => p_extract_method,
3721           p_process                  => 'Attribute Values Interface',
3722           p_restart_id               =>  prev_attribute_id
3723         );
3724 
3725        if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3726           raise FND_API.G_EXC_ERROR;
3727        end if;
3728       commit work;
3729       Savepoint Get_Attributes;
3730     end if;
3731 
3732     if (attribute_rec.value_table_flag = 'Y') then
3733     if (attribute_rec.definition_type = 'KFF' ) then
3734        /* Bug 4075170 Start */
3735        l_debug_info := 'Starting for attribute '||l_attribute_name
3736                        ||', of data type '||l_data_type
3737                        ||' definition type KFF';
3738        /* Bug 4075170 End */
3739        For C_key_rec in C_key_11
3740        Loop
3741          l_application_id := C_key_rec.application_id;
3742          l_id_flex_code   := C_key_rec.id_flex_code;
3743          l_set_defining_column := C_key_rec.set_defining_column_name;
3744          For C_key_str_rec in C_key_22
3745          Loop
3746              l_id_flex_num := C_key_str_rec.id_flex_num;
3747              l_application_column_name := C_key_str_rec.application_column_name;
3748              l_kflex_value_set_id      := C_key_str_rec.flex_value_set_id;
3749          End Loop;
3750 
3751        End Loop;
3752 
3753    if (l_kflex_value_set_id is not null) then
3754      fnd_vset.get_valueset(l_kflex_value_set_id, kvset, kfmt);
3755 
3756    if (kvset.validation_type = 'N') then
3757       null;
3758    else
3759    fnd_vset.get_value_init(kvset,TRUE);
3760    fnd_vset.get_value(kvset, krow, kfound, kvalue);
3761    end if;
3762    WHILE(kfound) LOOP
3763       lr_attribute_id := attribute_rec.attribute_id;
3764       lr_attribute_value := kvalue.value;
3765       l_attr_dummy := 0;
3766 
3767       For C_Attribute_rec in C_Attribute
3768       Loop
3769         l_attribute_value_id := C_Attribute_rec.attribute_value_id;
3770         l_attr_dummy := 1;
3771       End Loop;
3772 
3773       if (l_attr_dummy = 0) then
3774       select psb_attribute_values_s.nextval into
3775              l_attribute_value_id from dual;
3776       end if;
3777 
3778 
3779       INSERT INTO PSB_ATTRIBUTE_VALUES_I
3780       (
3781          ATTRIBUTE_VALUE_ID     ,
3782          ATTRIBUTE_ID           ,
3783          ATTRIBUTE_VALUE        ,
3784          DESCRIPTION            ,
3785          DATA_EXTRACT_ID        ,
3786          LAST_UPDATE_DATE       ,
3787          LAST_UPDATED_BY         ,
3788          LAST_UPDATE_LOGIN       ,
3789          CREATED_BY              ,
3790          CREATION_DATE           )
3791       VALUES
3792       (
3793          l_attribute_value_id,
3794          attribute_rec.attribute_id,
3795          kvalue.value,
3796          kvalue.meaning,
3797          p_data_extract_id,
3798          l_last_update_date,
3799          l_last_updated_by ,
3800          l_last_update_login ,
3801          l_created_by,
3802          l_creation_date);
3803       fnd_vset.get_value(kvset, krow, kfound, kvalue);
3804    END LOOP;
3805    fnd_vset.get_value_end(kvset);
3806    end if;
3807    elsif (attribute_rec.definition_type = 'DFF') then
3808      /* Bug 4075170 Start */
3809      l_debug_info := 'Starting for attribute '||l_attribute_name
3810                      ||', of data type '||l_data_type
3811                      ||' definition type DFF';
3812      /* Bug 4075170 End */
3813        For C_dff_rec in C_dff_11
3814        Loop
3815          l_application_id            := C_dff_rec.application_id;
3816          l_application_table_name    := C_dff_rec.application_table_name;
3817          l_context_column_name       := C_dff_rec.context_column_name;
3818 
3819          For C_dff_str_rec in C_dff_22
3820          Loop
3821            l_desc_flex_context_code := C_dff_str_rec.descriptive_flex_context_code;
3822            l_application_column_name := C_dff_str_rec.application_column_name;
3823            l_dflex_value_set_id      := C_dff_str_rec.flex_value_set_id;
3824          End Loop;
3825 
3826        End Loop;
3827 
3828    if (l_dflex_value_set_id is not null) then
3829    fnd_vset.get_valueset(l_dflex_value_set_id, dvset, dfmt);
3830    if (dvset.validation_type = 'N') then
3831       null;
3832    else
3833    fnd_vset.get_value_init(dvset, TRUE);
3834    fnd_vset.get_value(dvset, drow, dfound, dvalue);
3835    end if;
3836    WHILE(dfound) LOOP
3837       lr_attribute_id := attribute_rec.attribute_id;
3838       lr_attribute_value := dvalue.value;
3839       l_attr_dummy := 0;
3840 
3841       For C_Attribute_rec in C_Attribute
3842       Loop
3843         l_attribute_value_id := C_Attribute_rec.attribute_value_id;
3844         l_attr_dummy := 1;
3845       End Loop;
3846 
3847       if (l_attr_dummy = 0) then
3848       select psb_attribute_values_s.nextval into
3849              l_attribute_value_id from dual;
3850       end if;
3851 
3852       /* Bug 4075170 Start */
3853       l_debug_info := 'Inserting for Atrribute Id '
3854                       ||attribute_rec.attribute_id
3855                       ||', Atrribute Data Type '||l_data_type
3856                       ||', Atrribute Value '||dvalue.value;
3857       /* Bug 4075170 End */
3858 
3859       INSERT INTO PSB_ATTRIBUTE_VALUES_I
3860       (
3861          ATTRIBUTE_VALUE_ID     ,
3862          ATTRIBUTE_ID           ,
3863          ATTRIBUTE_VALUE        ,
3864          VALUE_ID               ,
3865          DESCRIPTION            ,
3866          DATA_EXTRACT_ID        ,
3867          LAST_UPDATE_DATE       ,
3868          LAST_UPDATED_BY         ,
3869          LAST_UPDATE_LOGIN       ,
3870          CREATED_BY              ,
3871          CREATION_DATE
3872       )
3873       VALUES
3874       (
3875          l_attribute_value_id,
3876          attribute_rec.attribute_id,
3877 
3878          -- Fix for bug #4075170 changed the date format to canonical.
3879          -- But since DFF always stores date in canonical format, this conversion is not
3880          -- necessary. So removed the conversion as part for Bug #4658351.
3881          dvalue.value,
3882 
3883          dvalue.id,
3884          dvalue.meaning,
3885          p_data_extract_id,
3886          l_last_update_date,
3887          l_last_updated_by ,
3888          l_last_update_login ,
3889          l_created_by,
3890          l_creation_date);
3891       fnd_vset.get_value(dvset, drow, dfound, dvalue);
3892    END LOOP;
3893    fnd_vset.get_value_end(dvset);
3894    end if;
3895 
3896   elsif (attribute_rec.definition_type = 'QC') then
3897     /* Bug 4075170 Start */
3898     l_debug_info := 'Starting for attribute '||l_attribute_name
3899                     ||', of data type '||l_data_type
3900                     ||' definition type QC';
3901     /* Bug 4075170 End */
3902     l_attribute_type_id := attribute_rec.attribute_type_id;
3903 
3904     For C_table_rec in C_table
3905     Loop
3906        l_lookup_type := C_table_rec.name;
3907     End Loop;
3908 
3909      -- Get values for lookup_type from fnd_common_lookups
3910 
3911     Open C6;
3912     Loop
3913 
3914     Fetch  C6 into l_lookup_code,l_lookup_meaning,l_description;
3915     exit when C6%NOTFOUND;
3916       lr_attribute_id := attribute_rec.attribute_id;
3917       lr_attribute_value := l_lookup_meaning;
3918       l_attr_dummy := 0;
3919 
3920       For C_Attribute_rec in C_Attribute
3921       Loop
3922         l_attribute_value_id := C_Attribute_rec.attribute_value_id;
3923         l_attr_dummy := 1;
3924       End Loop;
3925 
3926       if (l_attr_dummy = 0) then
3927       select psb_attribute_values_s.nextval into
3928              l_attribute_value_id from dual;
3929       end if;
3930 
3931       /* Bug 4075170 Start */
3932       l_debug_info := 'Inserting for Atrribute Id '
3933                       ||attribute_rec.attribute_id
3934                       ||', Atrribute Data Type '||l_data_type
3935                       ||', Atrribute Value '||l_description;
3936       /* Bug 4075170 End */
3937 
3938       -- Bug #4658351
3939       -- Moved the date format conversion out of the insert statement.
3940 
3941       if (l_data_type = 'D') then
3942         begin
3943           l_description := Fnd_Date.Date_to_Canonical(l_description);
3944         exception
3945           when OTHERS then
3946             FND_MESSAGE.SET_NAME('PSB', 'PSB_ATTRIBUTE_VALUE_DATE_ERR');
3947             FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME', l_attribute_name);
3948             l_message_text := fnd_message.get;
3949             RAISE_APPLICATION_ERROR(-20001,l_message_text);
3950          end;
3951        end if;
3952 
3953       INSERT INTO PSB_ATTRIBUTE_VALUES_I
3954       (
3955          ATTRIBUTE_VALUE_ID     ,
3956          ATTRIBUTE_ID           ,
3957          ATTRIBUTE_VALUE        ,
3958          DESCRIPTION            ,
3959          DATA_EXTRACT_ID        ,
3960          LAST_UPDATE_DATE       ,
3961          LAST_UPDATED_BY         ,
3962          LAST_UPDATE_LOGIN       ,
3963          CREATED_BY              ,
3964          CREATION_DATE
3965       )
3966       VALUES
3967       (
3968          l_attribute_value_id,
3969          attribute_rec.attribute_id,
3970          l_lookup_meaning,
3971 
3972          -- Bug #4658351
3973          -- Moved the date format conversion out of the insert statement.
3974          l_description,
3975 
3976          p_data_extract_id,
3977          l_last_update_date,
3978          l_last_updated_by ,
3979          l_last_update_login ,
3980          l_created_by,
3981          l_creation_date);
3982 
3983     end loop;
3984 
3985     close C6;
3986 
3987   elsif (attribute_rec.definition_type = 'TABLE') then
3988     /* Bug 4075170 Start */
3989     l_debug_info := 'Starting for attribute '||l_attribute_name
3990                     ||', of data type '||l_data_type
3991                     ||' definition type TABLE ';
3992     /* Bug 4075170 End */
3993   if (attribute_rec.value_table_flag = 'Y') then
3994     l_attribute_type_id := attribute_rec.attribute_type_id;
3995     v_cursorid := dbms_sql.open_cursor;
3996 
3997     -- Build the statement
3998     For C_table_rec in C_table
3999 
4000     Loop
4001 
4002     lsql_stmt := 'Select distinct '||C_table_rec.select_column
4003                 ||' From '||C_table_rec.select_table;
4004 
4005     -- Parse the query
4006     dbms_sql.parse(v_cursorid,lsql_stmt,dbms_sql.v7);
4007     -- Define the output variables
4008     if (attribute_rec.data_type = 'C') then
4009        dbms_sql.define_column(v_cursorid,1,vdef_col1,100);
4010     elsif (attribute_rec.data_type = 'N') then
4011       dbms_sql.define_column(v_cursorid,1,vdef_col2);
4012     elsif (attribute_rec.data_type = 'D') then
4013        dbms_sql.define_column(v_cursorid,1,vdef_col3);
4014     end if;
4015 
4016     v_dummy := DBMS_SQL.EXECUTE(v_cursorid);
4017 
4018     loop
4019       if DBMS_SQL.FETCH_ROWS(v_cursorid) = 0 then
4020          exit;
4021       end if;
4022 
4023     if (attribute_rec.data_type = 'C') then
4024       DBMS_SQL.COLUMN_VALUE(v_cursorid,1,vdef_col1);
4025       vdef_col := vdef_col1;
4026     elsif (attribute_rec.data_type = 'N') then
4027       begin
4028          DBMS_SQL.COLUMN_VALUE(v_cursorid,1,vdef_col2);
4029          vdef_col := fnd_number.number_to_canonical(vdef_col2);
4030       exception
4031        when INVALID_NUMBER then
4032 
4033          -- Changed the exception part for Bug #4658351
4034          FND_MESSAGE.SET_NAME('PSB', 'PSB_ATTRIBUTE_VALUE_NUMBER_ERR');
4035          FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME', l_attribute_name);
4036          l_message_text := fnd_message.get;
4037          RAISE_APPLICATION_ERROR(-20000,l_message_text);
4038 
4039       end;
4040     elsif (attribute_rec.data_type = 'D') then
4041       begin
4042        DBMS_SQL.COLUMN_VALUE(v_cursorid,1,vdef_col3);
4043        vdef_col := fnd_date.date_to_canonical(vdef_col3);
4044       exception
4045        when OTHERS then -- Bug #4658351: Changed VALUE_ERROR to OTHERS
4046 
4047          -- Changed the exception part for Bug #4658351
4048          FND_MESSAGE.SET_NAME('PSB', 'PSB_ATTRIBUTE_VALUE_DATE_ERR');
4049          FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME', l_attribute_name);
4050          l_message_text := fnd_message.get;
4051          RAISE_APPLICATION_ERROR(-20001,l_message_text);
4052 
4053       end;
4054     end if;
4055 
4056       lr_attribute_id := attribute_rec.attribute_id;
4057       lr_attribute_value := vdef_col;
4058       l_attr_dummy := 0;
4059 
4060       For C_Attribute_rec in C_Attribute
4061       Loop
4062         l_attribute_value_id := C_Attribute_rec.attribute_value_id;
4063         l_attr_dummy := 1;
4064       End Loop;
4065 
4066       if (l_attr_dummy = 0) then
4067       select psb_attribute_values_s.nextval into
4068              l_attribute_value_id from dual;
4069       end if;
4070 
4071       INSERT INTO PSB_ATTRIBUTE_VALUES_I
4072       (
4073          ATTRIBUTE_VALUE_ID     ,
4074          ATTRIBUTE_ID           ,
4075          ATTRIBUTE_VALUE        ,
4076          DATA_EXTRACT_ID        ,
4077          LAST_UPDATE_DATE       ,
4078          LAST_UPDATED_BY         ,
4079          LAST_UPDATE_LOGIN       ,
4080          CREATED_BY              ,
4081          CREATION_DATE
4082       )
4083       VALUES
4084       (
4085          l_attribute_value_id,
4086          attribute_rec.attribute_id,
4087          vdef_col,
4088          p_data_extract_id,
4089          l_last_update_date,
4090          l_last_updated_by ,
4091          l_last_update_login ,
4092          l_created_by,
4093          l_creation_date);
4094      end loop;
4095     dbms_sql.close_cursor(v_cursorid);
4096     end loop;
4097    end if;
4098 
4099   elsif (attribute_rec.definition_type IS NULL) then
4100     /* Bug 4075170 Start */
4101     l_debug_info := 'Starting for attribute '||l_attribute_name
4102                     ||', of data type '||l_data_type
4103                     ||' definition type IS NULL'
4104                     ||' system_attr_type '
4105                     ||attribute_rec.system_attribute_type;
4106     /* Bug 4075170 End */
4107     if (attribute_rec.system_attribute_type = 'JOB_CLASS') then
4108 
4109      -- Commented out for bug number 3159157
4110      /*For C_flex_rec in C_flex_num
4111      Loop
4112        l_job_id_flex_num := C_flex_rec.job_structure;
4113      End Loop;
4114 
4115      v_jcursorid := DBMS_SQL.OPEN_CURSOR;
4116 
4117      -- Changed the job stmt for Position Control requirements .
4118      -- Job name or job_definition_id is unique within a business_group
4119      -- and so the following cursor helps in storing the job_id value
4120      -- along with the job name as the corresponding attribute_value.
4121 
4122      l_job_stmt := 'Select job_id, concatenated_segments '||
4123                    ' from per_jobs pj, per_job_definitions_kfv pjv '||
4124                    'where  pj.business_group_id = '||p_business_group_id||
4125                   '  and  pj.job_definition_id =  pjv.job_definition_id and '||
4126                    'pjv.id_flex_num = '||l_job_id_flex_num;
4127 
4128     dbms_sql.parse(v_jcursorid,l_job_stmt,dbms_sql.v7);
4129     dbms_sql.define_column(v_jcursorid,1,lr_value_id);
4130     dbms_sql.define_column(v_jcursorid,2,lr_attribute_value,80);
4131     v_jdummy := DBMS_SQL.EXECUTE(v_jcursorid);*/
4132 
4133     -- Fetching job name from PER_JOBS (Bug number 3159157)
4134     For C_job_rec in C_Jobs
4135     Loop
4136       lr_attribute_id := attribute_rec.attribute_id;
4137       lr_attribute_value := C_job_rec.name;
4138       lr_value_id        := C_job_rec.job_id;
4139       l_attr_dummy := 0;
4140 
4141       For C_Attribute_rec in C_Attribute
4142       Loop
4143         l_attribute_value_id := C_Attribute_rec.attribute_value_id;
4144         l_attr_dummy := 1;
4145       End Loop;
4146 
4147       if (l_attr_dummy = 0) then
4148       select psb_attribute_values_s.nextval into
4149              l_attribute_value_id from dual;
4150       end if;
4151 
4152       INSERT INTO PSB_ATTRIBUTE_VALUES_I
4153       (
4154          ATTRIBUTE_VALUE_ID     ,
4155          ATTRIBUTE_ID           ,
4156          ATTRIBUTE_VALUE        ,
4157          VALUE_ID               ,
4158          DATA_EXTRACT_ID        ,
4159          LAST_UPDATE_DATE       ,
4160          LAST_UPDATED_BY         ,
4161          LAST_UPDATE_LOGIN       ,
4162          CREATED_BY              ,
4163          CREATION_DATE
4164       )
4165       VALUES
4166       (
4167          l_attribute_value_id,
4168          attribute_rec.attribute_id,
4169          lr_attribute_value,
4170          lr_value_id,
4171          p_data_extract_id,
4172          l_last_update_date,
4173          l_last_updated_by ,
4174          l_last_update_login ,
4175          l_created_by,
4176          l_creation_date);
4177      End Loop;
4178 
4179    elsif (attribute_rec.system_attribute_type = 'ORG') then
4180 
4181     For C_Org_Rec in C_Organizations
4182     Loop
4183       lr_attribute_id := attribute_rec.attribute_id;
4184       lr_attribute_value := C_Org_Rec.name;
4185       lr_value_id        := C_Org_Rec.organization_id;
4186       l_attr_dummy := 0;
4187 
4188       For C_Attribute_rec in C_Attribute
4189       Loop
4190         l_attribute_value_id := C_Attribute_rec.attribute_value_id;
4191         l_attr_dummy := 1;
4192       End Loop;
4193 
4194       if (l_attr_dummy = 0) then
4195       select psb_attribute_values_s.nextval into
4196              l_attribute_value_id from dual;
4197       end if;
4198 
4199       INSERT INTO PSB_ATTRIBUTE_VALUES_I
4200       (
4201          ATTRIBUTE_VALUE_ID     ,
4202          ATTRIBUTE_ID           ,
4203          ATTRIBUTE_VALUE        ,
4204          VALUE_ID               ,
4205          DATA_EXTRACT_ID        ,
4206          LAST_UPDATE_DATE       ,
4207          LAST_UPDATED_BY         ,
4208          LAST_UPDATE_LOGIN       ,
4209          CREATED_BY              ,
4210          CREATION_DATE
4211       )
4212       VALUES
4213       (
4214          l_attribute_value_id,
4215          attribute_rec.attribute_id,
4216          lr_attribute_value,
4217          lr_value_id,
4218          p_data_extract_id,
4219          l_last_update_date,
4220          l_last_updated_by ,
4221          l_last_update_login ,
4222          l_created_by,
4223          l_creation_date);
4224      End Loop;
4225 
4226    end if; /* system attribute type */
4227   end if; /* definition type */
4228 
4229   end if; /* Value table flag */
4230   prev_attribute_id := l_fin_attribute_id;
4231   End loop;
4232 
4233   Update_Reentry
4234   ( p_api_version              => 1.0  ,
4235     p_return_status            => l_return_status,
4236     p_msg_count                => l_msg_count,
4237     p_msg_data                 => l_msg_data,
4238     p_data_extract_id          => p_data_extract_id,
4239     p_extract_method           => p_extract_method,
4240     p_process                  => 'Attribute Values Interface',
4241     p_restart_id               =>  l_fin_attribute_id
4242   );
4243 
4244   if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4245      raise FND_API.G_EXC_ERROR;
4246   end if;
4247 
4248   Reentrant_Process
4249   ( p_api_version              => 1.0  ,
4250     p_return_status            => l_return_status,
4251     p_msg_count                => l_msg_count,
4252     p_msg_data                 => l_msg_data,
4253     p_data_extract_id          => p_data_extract_id,
4254     p_extract_method           => p_extract_method,
4255     p_process                  => 'Attribute Values Interface'
4256   );
4257 
4258   if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4259      raise FND_API.G_EXC_ERROR;
4260   end if;
4261 
4262   commit work;
4263 
4264   end if;
4265 
4266   -- End of API body.
4267 
4268 EXCEPTION
4269 
4270    when FND_API.G_EXC_ERROR then
4271      /* Bug 4075170 Start */
4272      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Last Status::'||l_debug_info);
4273      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Parameter Info::'||l_param_info);
4274      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Error Type:: FND_API.G_EXC_EXC_ERROR');
4275      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Get_Attributes API '
4276                                       ||'failed due to the following error');
4277      FND_FILE.PUT_LINE(FND_FILE.LOG, sqlerrm);
4278      /* Bug 4075170 End */
4279 
4280      if C6%isopen then
4281         close C6;
4282      end if;
4283 
4284      if (dbms_sql.is_open(v_cursorid)) then
4285         dbms_sql.close_cursor(v_cursorid);
4286      end if;
4287 
4288      rollback to Get_Attributes;
4289      p_return_status := FND_API.G_RET_STS_ERROR;
4290      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
4291                                  p_data  => p_msg_data);
4292      message_token('ATTRIBUTE_NAME',l_attribute_name );
4293      message_token('DEFINITION_TYPE',l_definition_type );
4294      message_token('DEFINITION_STRUCTURE',l_definition_structure);
4295      message_token('DEFINITION_TABLE',l_definition_table);
4296      message_token('DEFINITION_COLUMN',l_definition_column);
4297      add_message('PSB', 'PSB_ATTRIBUTE_DETAILS');
4298 
4299    when FND_API.G_EXC_UNEXPECTED_ERROR then
4300      /* Bug 4075170 Start */
4301      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Last Status::'||l_debug_info);
4302      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Parameter Info::'||l_param_info);
4303      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Error Type:: FND_API.G_EXC_UNEXPECTED_ERROR');
4304      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Get_Attributes API '
4305                                      ||'failed due to the following error');
4306      FND_FILE.PUT_LINE(FND_FILE.LOG, sqlerrm);
4307      /* Bug 4075170 End */
4308 
4309      if C6%isopen then
4310         close C6;
4311      end if;
4312 
4313      if (dbms_sql.is_open(v_cursorid)) then
4314         dbms_sql.close_cursor(v_cursorid);
4315      end if;
4316 
4317      rollback to Get_Attributes;
4318      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4319      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
4320                                  p_data  => p_msg_data);
4321      message_token('ATTRIBUTE_NAME',l_attribute_name );
4322      message_token('DEFINITION_TYPE',l_definition_type );
4323      message_token('DEFINITION_STRUCTURE',l_definition_structure);
4324      message_token('DEFINITION_TABLE',l_definition_table);
4325      message_token('DEFINITION_COLUMN',l_definition_column);
4326      add_message('PSB', 'PSB_ATTRIBUTE_DETAILS');
4327 
4328    when OTHERS then
4329      /* Bug 4075170 Start */
4330      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Last Status::'||l_debug_info);
4331      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Parameter Info::'||l_param_info);
4332      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Error Type:: WHEN OTHERS');
4333      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Get_Attributes API '
4334                                       ||'failed due to the following error');
4335      FND_FILE.PUT_LINE(FND_FILE.LOG, sqlerrm);
4336      /* Bug 4075170 End */
4337 
4338      if C6%isopen then
4339         close C6;
4340      end if;
4341 
4342      if (dbms_sql.is_open(v_cursorid)) then
4343         dbms_sql.close_cursor(v_cursorid);
4344      end if;
4345 
4346      rollback to Get_Attributes;
4347      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4348      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
4349                                  p_data  => p_msg_data);
4350      message_token('ATTRIBUTE_NAME',l_attribute_name );
4351      message_token('DEFINITION_TYPE',l_definition_type );
4352      message_token('DEFINITION_STRUCTURE',l_definition_structure);
4353      message_token('DEFINITION_TABLE',l_definition_table);
4354      message_token('DEFINITION_COLUMN',l_definition_column);
4355      add_message('PSB', 'PSB_ATTRIBUTE_DETAILS');
4356      if FND_MSG_PUB.Check_Msg_level
4357        (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4358      then
4359        FND_MSG_PUB.Add_Exc_Msg
4360           (p_pkg_name => G_PKG_NAME,
4361            p_procedure_name => l_api_name);
4362     end if;
4363 
4364 End Get_Attributes;
4365 
4366 /* ----------------------------------------------------------------------- */
4367 
4368 PROCEDURE Get_Employee_Attributes
4369 ( p_api_version         IN    NUMBER,
4370   p_init_msg_list	IN    VARCHAR2 := FND_API.G_FALSE,
4371   p_commit	    	IN    VARCHAR2 := FND_API.G_FALSE,
4372   p_validation_level	IN    NUMBER   := FND_API.G_VALID_LEVEL_FULL,
4373   p_return_status       OUT   NOCOPY VARCHAR2,
4374   p_msg_count           OUT   NOCOPY NUMBER,
4375   p_msg_data            OUT   NOCOPY VARCHAR2,
4376   p_data_extract_id     IN    NUMBER,
4377   -- de by org
4378   p_extract_by_org      IN    VARCHAR2,
4379   p_extract_method      IN    VARCHAR2,
4380   p_date                IN    DATE,
4381   p_business_group_id   IN    NUMBER,
4382   p_set_of_books_id     IN    NUMBER
4383 ) AS
4384 
4385   l_restart_attribute_id    number := 0;
4386 
4387   Cursor C_Emp_Attributes is
4388      Select  attribute_id,name,definition_type,definition_structure,
4389              definition_table, definition_column,system_attribute_type,
4390              attribute_type_id,data_type
4391       from   Psb_attributes_VL
4392      where   business_group_id = p_business_group_id
4393        and   attribute_id > l_restart_attribute_id;
4394 
4395   /*For Bug No : 2370607 Start*/
4396   --changed the a.working_hours, a.frequency to
4397   --		decode statements
4398   /*For Bug No : 2642012 Start*/
4399   --replaced per_all_assignments with per_all_assignments_f  and added datetrack logic
4400   --and also added c.hr_position_name into the cursor select part
4401 
4402   Cursor C_Employees is
4403      Select b.person_id,b.assignment_id,a.position_id,
4404             b.grade_id,a.job_id,a.organization_id,
4405             nvl(a.fte,1) fte, a.earliest_hire_date,
4406             --a.working_hours,a.frequency,
4407             decode(b.frequency,'W',b.normal_hours,decode(a.frequency,'W',a.working_hours,null)) working_hours,
4408             decode(b.frequency,'W','A','P') freq_flag,
4409             a.position_type,
4410             c.hr_position_name,
4411             b.people_group_id ,
4412             b.soft_coding_keyflex_id,
4413             b.effective_start_date,
4414             b.effective_end_date,
4415             a.effective_start_date date_effective,
4416             a.effective_end_date date_end
4417       from  fnd_sessions d, per_all_assignments_f b, hr_all_positions_f a , psb_positions_i c, psb_employees_i e
4418      where  d.session_id = userenv('sessionid')
4419        and  d.effective_date between a.effective_start_date and a.effective_end_date
4420        and  d.effective_date between b.effective_start_date and b.effective_end_date
4421        and  a.business_group_id = p_business_group_id
4422        and  a.position_id = c.hr_position_id
4423        and  c.data_extract_id = p_data_extract_id
4424        and  b.assignment_id = e.assignment_id
4425        and  e.data_extract_id = p_data_extract_id
4426        and  a.position_id = b.position_id
4427        and  c.hr_employee_id = b.person_id
4428        and  b.business_group_id = p_business_group_id
4429        /*For Bug No : 2109120 Start*/
4430        --and  b.primary_flag(+) = 'Y'
4431        /*For Bug No : 2109120 End*/
4432        and  b.assignment_type = 'E'
4433         -- de by org
4434 
4435         -- The following logic is used to restrict the positions for all the
4436 	-- selected organizations, if extract by org is enabled.
4437         -- Otherwise, we will ignore the organizations available
4438         -- in the business group.
4439 
4440        and (p_extract_by_org = 'N' OR
4441            (p_extract_by_org = 'Y' and a.organization_id in
4442             (select organization_id
4443               from psb_data_extract_orgs
4444               where data_extract_id = p_data_extract_id
4445               and select_flag = 'Y')))
4446 
4447      UNION ALL
4448      Select to_number(NULL),to_number(NULL),a.position_id,
4449             to_number(NULL),a.job_id,a.organization_id,
4450             nvl(a.fte,1) fte, a.earliest_hire_date,
4451             --a.working_hours,a.frequency,
4452             decode(a.frequency,'W',a.working_hours,null) working_hours,
4453             'P' freq_flag ,
4454             a.position_type,
4455             c.hr_position_name,
4456             to_number(NULL) ,
4457             to_number(NULL),
4458             to_date(NULL),
4459             to_date(NULL),
4460             a.effective_start_date date_effective,
4461             a.effective_end_date date_end
4462       from  fnd_sessions b , hr_all_positions_f a , psb_positions_i c
4463      where  b.session_id = userenv('sessionid')
4464        and  b.effective_date between a.effective_start_date and a.effective_end_date
4465        and  a.business_group_id = p_business_group_id
4466        and  a.position_id = c.hr_position_id
4467        and  c.data_extract_id = p_data_extract_id
4468        and  c.hr_employee_id is null
4469         -- de by org
4470 
4471         -- The following logic is used to restrict the positions for all the
4472 	-- selected organizations, if extract by org is enabled.
4473         -- Otherwise, we will ignore the organizations available
4474         -- in the business group
4475 
4476        and  (p_extract_by_org = 'N' OR
4477             (p_extract_by_org = 'Y' and a.organization_id in
4478              (select organization_id
4479                from psb_data_extract_orgs
4480               where data_extract_id = p_data_extract_id
4481               and select_flag = 'Y')));
4482 
4483   /*For Bug No : 2642012 End*/
4484   /*For Bug No : 2370607 End*/
4485 
4486     l_position_name           varchar2(240);
4487 
4488         /* start bug 4153562 */
4489         -- local variables to hold the position_id
4490         -- and the effective end date
4491 	lv_position_id        number;
4492 	lv_effective_end_date date;
4493        /*  end bug 4153562 */
4494 
4495 
4496     --UTF8 changes for Bug No : 2615261
4497     l_employee_name           varchar2(310);
4498     l_person_id               number;
4499     l_definition_structure    varchar2(30);
4500     l_definition_table        varchar2(30);
4501     l_definition_column       varchar2(30);
4502     l_id_flex_code            varchar2(4);
4503     l_application_id          number;
4504     l_application_table_name  varchar2(30);
4505     l_set_defining_column     varchar2(30);
4506     l_id_flex_num             number;
4507     l_application_column_name varchar2(30);
4508     l_assignment_table        varchar2(30);
4509     l_assignment_column       varchar2(30);
4510     l_key_column              varchar2(30);
4511     l_lookup_type             varchar2(30);
4512     l_link_type               varchar2(10);
4513     l_attr_link_type          varchar2(30);
4514     l_last_update_date        date;
4515     l_last_updated_by         number;
4516     l_last_update_login       number;
4517     l_creation_date           date;
4518     l_created_by              number;
4519     l_job_name                varchar2(80);
4520     le_effective_start_date   date;
4521     le_effective_end_date     date;
4522     lemp_effective_start_date date;
4523     lemp_effective_end_date   date;
4524     lpos_effective_start_date date;
4525     lpos_effective_end_date   date;
4526     l_job_id                  number;
4527     ctr                       number := 0;
4528     l_sql_stmt                varchar2(500);
4529     stmt_flag                 varchar2(1);
4530     v_cursorid                integer;
4531     v_emp_val                 integer;
4532     v_dummy                   integer;
4533     v_segment                 varchar2(80);
4534     v_dcursorid               integer;
4535     v_ddummy                  integer;
4536     v_dsegment                varchar2(80);
4537   /*For Bug No : 2372434 Start*/
4538   --increased the size of d_sql_stmt,q_sql_stmt,o_sql_stmt
4539   --from 500 to 2000
4540     d_sql_stmt                varchar2(2000);
4541     v_qcursorid               integer;
4542     v_qdummy                  integer;
4543     v_qsegment                varchar2(80);
4544     q_sql_stmt                varchar2(2000);
4545     v_ocursorid               integer;
4546     v_odummy                  integer;
4547     v_osegment                varchar2(80);
4548     v_odate                   date;
4549     v_onumber                 number;
4550     o_sql_stmt                varchar2(2000);
4551   /*For Bug No : 2372434 End*/
4552     d_attribute_type          varchar2(30);
4553     d_attribute_type_id       number;
4554     l_emp_col                 varchar2(20);
4555     l_emp_val                 number;
4556     l_assignment_id           number;
4557     l_status                  varchar2(1);
4558     l_return_status           varchar2(1);
4559     l_msg_count               number;
4560     l_msg_data                varchar2(1000);
4561     l_alias1                  varchar2(10);
4562     l_job_stmt                varchar2(1000);
4563     v_jcursorid               integer;
4564     v_jdummy                  integer;
4565     prev_attribute_id         number := -1;
4566     l_attribute_id            number := 0;
4567     lc_assignment_id          number;
4568     lc_person_id              number;
4569     lc_position_id            number;
4570     lc_people_group_id        number;
4571     lc_soft_coding_keyflex_id number;
4572     lc_grade_id               number;
4573     lc_job_id                 number;
4574     l_fin_attribute_id        number := 0;
4575     l_organization_id         number := 0;
4576     --UTF8 changes for Bug No : 2615261
4577     l_organization_name       hr_all_organization_units.name%TYPE;
4578 
4579 
4580   Cursor C_Attribute_Types is
4581     Select name, select_table,
4582            substr(select_table,1,instr(select_table,' ',1)) select_tab,
4583            select_column,select_key,
4584            link_key,decode(link_type,'A','PER_ALL_ASSIGNMENTS','E',
4585            'PER_ALL_PEOPLE','P', 'HR_ALL_POSITIONS','PER_ALL_ASSIGNMENTS') link_type,link_type l_alias2,
4586            select_where
4587       From Psb_attribute_types
4588     Where  attribute_type = d_attribute_type
4589       and  attribute_type_id = d_attribute_type_id;
4590 
4591   Cursor C_key_33 is
4592        Select application_id,id_flex_code,
4593               application_table_name,
4594               set_defining_column_name
4595         from  fnd_id_flexs
4596        where id_flex_name = l_definition_structure;
4597 
4598   Cursor C_key_44 is
4599     SELECT fseg.application_column_name,
4600            fstr.id_flex_num
4601       FROM fnd_id_flex_structures_vl fstr,fnd_id_flex_segments_vl fseg
4602      WHERE fstr.application_id = l_application_id
4603        AND fstr.id_flex_code   = l_id_flex_code
4604        AND fstr.id_flex_structure_name = l_definition_table
4605        AND fstr.id_flex_code   = fseg.id_flex_code
4606        AND fstr.id_flex_num    = fseg.id_flex_num
4607        AND fseg.segment_name   = l_definition_column
4608 	     AND fstr.application_id = fseg.application_id;  -- bug #4924031;
4609 
4610    Cursor C_dff_33 is
4611      Select application_id,application_table_name,
4612             context_column_name
4613        from fnd_descriptive_flexs_vl
4614       where descriptive_flexfield_name = l_definition_structure;
4615 
4616    Cursor C_dff_44 is
4617     Select fcol.application_column_name
4618      from  fnd_descr_flex_contexts_vl fcon,fnd_descr_flex_column_usages fcol
4619      where fcon.application_id = fcol.application_id
4620        and fcon.descriptive_flexfield_name = l_definition_structure
4621        and fcon.descriptive_flex_context_code = l_definition_table
4622        and fcon.descriptive_flexfield_name = fcol.descriptive_flexfield_name
4623     and fcon.descriptive_flex_context_code = fcol.descriptive_flex_context_code
4624     and fcol.end_user_column_name = l_definition_column;
4625 
4626    Cursor C_Qc_55 is
4627      Select lookup_type
4628        from per_common_lookup_types_v
4629       where lookup_type_meaning = l_definition_table;
4630 
4631    Cursor C_job_structure is
4632      Select job_structure
4633        from per_business_groups
4634       where business_group_id = p_business_group_id;
4635 
4636    Cursor C_Pos_Org is
4637      Select name
4638        from hr_all_organization_units
4639       where organization_id = l_organization_id;
4640 
4641    /*For Bug No : 2109120 Start*/
4642    Cursor C_Fte is
4643      Select value
4644        from per_assignment_budget_values
4645       where assignment_id  = l_assignment_id
4646       --changed the unit value from 'F' to 'FTE'
4647         and unit = 'FTE';
4648    /*For Bug No : 2109120 End*/
4649 
4650    Cursor C_Emp_Name is
4651     Select first_name,last_name
4652       from psb_employees_i
4653      where hr_employee_id = l_person_id
4654       and  data_extract_id = p_data_extract_id;
4655 
4656    Cursor C_Hiredate is
4657      Select start_date
4658        from per_all_people
4659       where person_id   = l_person_id ;
4660 
4661    Cursor C_job_name is
4662      Select name
4663        from per_jobs
4664       where  job_id = l_job_id;
4665 
4666    /*For Bug No : 2109120 Start*/
4667    CURSOR C_check_FTE(l_pos_id NUMBER) IS
4668      SELECT sum(nvl(value,1)) sum_fte
4669        FROM fnd_sessions fs,
4670             per_assignment_budget_values pab,
4671             per_all_assignments_f paf,
4672             per_assignment_status_types past
4673       WHERE fs.session_id = userenv('sessionid')
4674         AND fs.effective_date between paf.effective_start_date
4675                           and paf.effective_end_date
4676         AND paf.position_id = l_pos_id
4677         AND paf.assignment_type = 'E'
4678         /* Bug 3796397 Start */
4679         AND paf.assignment_status_type_id
4680                           = past.assignment_status_type_id
4681         AND past.per_system_status <> 'TERM_ASSIGN'
4682         /* Bug 3796397 End */
4683         AND pab.assignment_id(+)  = paf.assignment_id
4684         AND pab.unit(+) = 'FTE';
4685    /*For Bug No : 2109120 End*/
4686 
4687   --
4688   l_attribute_name  varchar2(30);
4689   l_definition_type varchar2(10);
4690   l_average_fte     NUMBER ;
4691   l_allocated_fte   NUMBER ;
4692   l_fte             NUMBER ;
4693   lp_fte            VARCHAR2(30);
4694   l_default_weekly_hours  NUMBER;
4695   lp_default_weekly_hours VARCHAR2(30);
4696   l_hiredate        DATE;
4697   lp_hiredate       VARCHAR2(30);
4698   lk_position_id    NUMBER ;
4699   lk_effective_end_date DATE;
4700   l_message_text    VARCHAR2(2000);
4701   --
4702   l_api_name	    CONSTANT VARCHAR2(30)	:= 'Get_Employee_Attributes';
4703   l_api_version     CONSTANT NUMBER 	:= 1.0;
4704 
4705   /* Bug 4075170 Start */
4706   l_data_type       psb_attributes_vl.data_type%TYPE;
4707   l_param_info      VARCHAR2(4000);
4708   l_debug_info      VARCHAR2(4000);
4709   /* Bug 4075170 End */
4710 
4711 Begin
4712 
4713   -- Standard Start of API savepoint
4714   /* Bug 4075170 Start */
4715   l_param_info := 'data_extract_id::'||p_data_extract_id
4716                   ||', extract_method::'||p_extract_method
4717                   ||', extract_by_org::'||p_extract_by_org
4718                   ||', business_grp_id::'||p_business_group_id
4719                   ||' date::'||p_date;
4720   l_debug_info := 'Starting the Get_Employee_Attributes API';
4721   /* Bug 4075170 End */
4722 
4723   Savepoint Get_Employee_Attributes;
4724 
4725   -- Standard call to check for call compatibility.
4726 
4727   if not FND_API.Compatible_API_Call (l_api_version,
4728           	    	 	      p_api_version,
4729    	       	    	              l_api_name,
4730 		    	    	      G_PKG_NAME)
4731   then
4732      raise FND_API.G_EXC_UNEXPECTED_ERROR;
4733   end if;
4734 
4735   -- Initialize message list if p_init_msg_list is set to TRUE.
4736 
4737   if FND_API.to_Boolean (p_init_msg_list) then
4738      FND_MSG_PUB.initialize;
4739   end if;
4740 
4741   p_return_status := FND_API.G_RET_STS_SUCCESS;
4742 
4743   -- API body
4744 
4745   l_last_update_date := sysdate;
4746   l_last_updated_by := FND_GLOBAL.USER_ID;
4747   l_last_update_login :=FND_GLOBAL.LOGIN_ID;
4748   l_creation_date     := sysdate;
4749   l_created_by        := FND_GLOBAL.USER_ID;
4750 
4751   Check_Reentry
4752   (p_api_version              => 1.0  ,
4753    p_return_status            => l_return_status,
4754    p_msg_count                => l_msg_count,
4755    p_msg_data                 => l_msg_data,
4756    p_data_extract_id          => p_data_extract_id,
4757    p_process                  => 'Position Assignments Interface',
4758    p_status                   => l_status,
4759    p_restart_id               => l_restart_attribute_id
4760    );
4761 
4762   if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4763      raise FND_API.G_EXC_ERROR;
4764   end if;
4765 
4766   if (l_status <> 'C') then
4767   For Emp_attribute_rec in C_Emp_Attributes Loop
4768       l_attribute_id         := Emp_attribute_rec.attribute_id;
4769       l_attribute_name       := Emp_attribute_rec.name;
4770       l_definition_type      := Emp_attribute_rec.definition_type;
4771       l_definition_structure := Emp_attribute_rec.definition_structure;
4772       l_definition_table     := Emp_attribute_rec.definition_table;
4773       l_definition_column    := Emp_attribute_rec.definition_column;
4774       /* Bug 4075170 Start */
4775       -- Assign the datatype of the current attribute.
4776       l_data_type            := Emp_attribute_rec.data_type;
4777       /* Bug 4075170 End */
4778 
4779       if ((l_attribute_id <> prev_attribute_id) and (prev_attribute_id <> -1))
4780 then
4781         Update_Reentry
4782         ( p_api_version              => 1.0  ,
4783           p_return_status            => l_return_status,
4784           p_msg_count                => l_msg_count,
4785           p_msg_data                 => l_msg_data,
4786           p_data_extract_id          => p_data_extract_id,
4787           p_extract_method           => p_extract_method,
4788           p_process                  => 'Position Assignments Interface',
4789           p_restart_id               => prev_attribute_id
4790         );
4791 
4792        if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4793           raise FND_API.G_EXC_ERROR;
4794        end if;
4795       commit work;
4796       Savepoint Get_Employee_Attributes;
4797       end if;
4798 
4799 
4800    For Employee_rec in C_Employees Loop
4801     ctr := 0;
4802     stmt_flag := '';
4803     l_sql_stmt := '';
4804     l_position_name         := null;
4805     l_employee_name         := null;
4806     lemp_effective_start_date := to_date(null);
4807     lemp_effective_end_date   := to_date(null);
4808     lpos_effective_start_date := to_date(null);
4809     lpos_effective_end_date   := to_date(null);
4810     le_effective_start_date := to_date(null);
4811     le_effective_end_date   := to_date(null);
4812 
4813     if (Employee_rec.person_id is not null) then
4814        l_person_id               := Employee_Rec.person_id;
4815        For Emp_Name_Rec in C_Emp_Name
4816        Loop
4817          l_employee_name := Emp_Name_Rec.first_name||' '||Emp_Name_Rec.last_name;
4818        End Loop;
4819     end if;
4820 
4821     /* Bug 4075170 Start */
4822     l_debug_info := 'Starting for person_id '||l_person_id;
4823     /* Bug 4075170 End */
4824 
4825 
4826     /*For Bug No : 2642012 Start*/
4827     --coomented the following code and getting the position name
4828     --directly from the cursor itself
4829     l_position_name := Employee_rec.hr_position_name;
4830 
4831     /*
4832     if (Employee_rec.position_id is not null) then
4833        For Pos_Name_Rec in G_Position_Details(p_position_id => Employee_rec.position_id)
4834        Loop
4835          l_position_name := Pos_Name_Rec.name;
4836        End Loop;
4837     end if;
4838     */
4839     /*For Bug No : 2642012 End*/
4840 
4841     lpos_effective_start_date := Employee_rec.date_effective;
4842 
4843     if (Employee_rec.date_end = to_date('31124712','DDMMYYYY')) then
4844       lpos_effective_end_date := to_date(null);
4845     else
4846       lpos_effective_end_date   := Employee_rec.date_end;
4847     end if;
4848 
4849      lemp_effective_start_date := Employee_rec.effective_start_date;
4850      if (Employee_rec.effective_end_date = to_date('31124712','DDMMYYYY')) then
4851          lemp_effective_end_date := to_date(null);
4852      else
4853         lemp_effective_end_date   := Employee_rec.effective_end_date;
4854      end if;
4855 
4856     /* Start bug #4302946 */
4857     l_emp_val := null;
4858     /* End bug #4302946 */
4859 
4860     if (Emp_attribute_rec.definition_type = 'KFF') then
4861       /* Bug 4075170 Start */
4862       l_debug_info := 'Starting for person_id '||l_person_id||' definition type KFF';
4863       /* Bug 4075170 End */
4864 
4865    if ((l_attribute_id <> prev_attribute_id) or  (prev_attribute_id = -1)) then
4866       if dbms_sql.is_open(v_cursorid) then
4867          dbms_sql.close_cursor(v_cursorid);
4868       end if;
4869 
4870        For C_key_rec in C_key_33
4871        Loop
4872          l_application_id := C_key_rec.application_id;
4873          l_id_flex_code   := C_key_rec.id_flex_code;
4874          l_set_defining_column := C_key_rec.set_defining_column_name;
4875          For C_key_str_rec in C_key_44
4876          Loop
4877              l_application_column_name := C_key_str_rec.application_column_name;
4878              l_id_flex_num := C_key_str_rec.id_flex_num;
4879          End Loop;
4880 
4881        End Loop;
4882 
4883       v_cursorid := dbms_sql.open_cursor;
4884    end if;
4885 
4886    if (Emp_attribute_rec.definition_structure = 'Job Flexfield' ) then
4887       if (Employee_Rec.job_id is not null) then
4888           stmt_flag := 'T';
4889       end if;
4890    if ((l_attribute_id <> prev_attribute_id) or  (prev_attribute_id = -1)) then
4891          l_sql_stmt := 'Select '||l_application_column_name||
4892                     ' From  Per_jobs,per_job_definitions '||
4893                     ' Where per_jobs.job_id = '||':lc_job_id'||
4894                     '   and per_jobs.job_definition_id = '||
4895                     ' per_job_definitions.job_definition_id';
4896          dbms_sql.parse(v_cursorid,l_sql_stmt,dbms_sql.v7);
4897          dbms_sql.define_column(v_cursorid,1,v_segment,80);
4898 
4899 
4900          if (stmt_flag = 'T') then
4901             le_effective_start_date := lpos_effective_start_date;
4902             le_effective_end_date := lpos_effective_end_date;
4903             dbms_sql.bind_variable(v_cursorid,':lc_job_id',Employee_Rec.job_id);
4904          end if;
4905       else
4906          if (stmt_flag = 'T') then
4907             dbms_sql.bind_variable(v_cursorid,':lc_job_id',Employee_Rec.job_id);
4908             le_effective_start_date := lpos_effective_start_date;
4909             le_effective_end_date := lpos_effective_end_date;
4910          end if;
4911       end if;
4912   elsif (Emp_attribute_rec.definition_structure = 'Position Flexfield') then
4913       if (Employee_rec.position_id is not null) then
4914          stmt_flag := 'T';
4915       end if;
4916    if ((l_attribute_id <> prev_attribute_id) or  (prev_attribute_id = -1)) then
4917          l_sql_stmt := 'Select '||l_application_column_name||
4918                ' From  hr_positions,per_position_definitions '||
4919                ' Where hr_positions.position_id = '||':lc_position_id'||
4920                '   and hr_positions.position_definition_id = '||
4921                     ' per_position_definitions.position_definition_id';
4922          dbms_sql.parse(v_cursorid,l_sql_stmt,dbms_sql.v7);
4923          dbms_sql.define_column(v_cursorid,1,v_segment,80);
4924         if (stmt_flag = 'T') then
4925             dbms_sql.bind_variable(v_cursorid,':lc_position_id',Employee_Rec.position_id);
4926          le_effective_start_date := lpos_effective_start_date;
4927          le_effective_end_date := lpos_effective_end_date;
4928         end if;
4929       else
4930         if (stmt_flag = 'T') then
4931            dbms_sql.bind_variable(v_cursorid,':lc_position_id',Employee_Rec.position_id);
4932          le_effective_start_date := lpos_effective_start_date;
4933          le_effective_end_date := lpos_effective_end_date;
4934         end if;
4935       end if;
4936    elsif (Emp_attribute_rec.definition_structure = 'Grade Flexfield') then
4937       if (Employee_rec.grade_id is not null) then
4938           stmt_flag := 'T';
4939       end if;
4940    if ((l_attribute_id <> prev_attribute_id) or  (prev_attribute_id = -1)) then
4941          l_sql_stmt := 'Select '||l_application_column_name||
4942                ' From  Per_grades,per_grade_definitions '||
4943                ' Where per_grades.grade_id = '||':lc_grade_id'||
4944                '   and per_grades.grade_definition_id = '||
4945                     ' per_grade_definitions.grade_definition_id';
4946          dbms_sql.parse(v_cursorid,l_sql_stmt,dbms_sql.v7);
4947          dbms_sql.define_column(v_cursorid,1,v_segment,80);
4948         if (stmt_flag = 'T') then
4949             dbms_sql.bind_variable(v_cursorid,':lc_grade_id',Employee_Rec.grade_id);
4950          le_effective_start_date := lemp_effective_start_date;
4951          le_effective_end_date := lemp_effective_end_date;
4952         end if;
4953       else
4954         if (stmt_flag = 'T') then
4955            dbms_sql.bind_variable(v_cursorid,':lc_grade_id',Employee_Rec.grade_id);
4956          le_effective_start_date := lemp_effective_start_date;
4957          le_effective_end_date := lemp_effective_end_date;
4958         end if;
4959       end if;
4960   elsif (Emp_attribute_rec.definition_structure = 'People Group Flexfield') then
4961       if (Employee_rec.people_group_id is not null) then
4962         stmt_flag := 'T';
4963       end if;
4964    if ((l_attribute_id <> prev_attribute_id) or  (prev_attribute_id = -1)) then
4965          l_sql_stmt := 'Select '||l_application_column_name||
4966                ' From  Pay_People_Groups'||
4967                ' Where pay_people_groups.people_group_id = '||
4968                  ':lc_people_group_id';
4969            dbms_sql.parse(v_cursorid,l_sql_stmt,dbms_sql.v7);
4970            dbms_sql.define_column(v_cursorid,1,v_segment,80);
4971         if (stmt_flag = 'T') then
4972            dbms_sql.bind_variable(v_cursorid,':lc_people_group_id',Employee_Rec.people_group_id);
4973            le_effective_start_date := lemp_effective_start_date;
4974            le_effective_end_date := lemp_effective_end_date;
4975         end if;
4976       else
4977         if (stmt_flag = 'T') then
4978            dbms_sql.bind_variable(v_cursorid,':lc_people_group_id',Employee_Rec.people_group_id);
4979            le_effective_start_date := lemp_effective_start_date;
4980            le_effective_end_date := lemp_effective_end_date;
4981         end if;
4982       end if;
4983 elsif (Emp_attribute_rec.definition_structure = 'Cost Allocation Flexfield') then
4984       if (Employee_rec.assignment_id is not null) then
4985          stmt_flag := 'T';
4986       end if;
4987    if ((l_attribute_id <> prev_attribute_id) or  (prev_attribute_id = -1)) then
4988          l_sql_stmt := 'Select '||l_application_column_name||
4989                    ' From pay_cost_allocations,pay_cost_allocation_keyflex '||
4990                    ' Where pay_cost_allocations.assignment_id = '||
4991                      ':lc_assignment_id'||
4992              ' and pay_cost_allocations.cost_allocation_keyflex_id = '||
4993              ' pay_cost_allocation_keyflex.cost_allocation_keyflex_id '||
4994              ' order by pay_cost_allocations.proportion';
4995            dbms_sql.parse(v_cursorid,l_sql_stmt,dbms_sql.v7);
4996            dbms_sql.define_column(v_cursorid,1,v_segment,80);
4997         if (stmt_flag = 'T') then
4998            dbms_sql.bind_variable(v_cursorid,':lc_assignment_id',Employee_Rec.assignment_id);
4999            le_effective_start_date := lemp_effective_start_date;
5000            le_effective_end_date := lemp_effective_end_date;
5001         end if;
5002       else
5003         if (stmt_flag = 'T') then
5004         dbms_sql.bind_variable(v_cursorid,':lc_assignment_id',Employee_Rec.assignment_id);
5005            le_effective_start_date := lemp_effective_start_date;
5006            le_effective_end_date := lemp_effective_end_date;
5007         end if;
5008       end if;
5009 elsif (Emp_attribute_rec.definition_structure = 'Soft Coded KeyFlexfield') then
5010       if (Employee_rec.soft_coding_keyflex_id is not null) then
5011         stmt_flag := 'T';
5012       end if;
5013    if ((l_attribute_id <> prev_attribute_id) or  (prev_attribute_id = -1)) then
5014          l_sql_stmt := 'Select '||l_application_column_name||
5015                    ' From hr_soft_coding_keyflex'||
5016                    ' Where hr_soft_coding_keyflex.soft_coding_keyflex_id = '||
5017                      ':lc_soft_coding_keyflex_id';
5018         dbms_sql.parse(v_cursorid,l_sql_stmt,dbms_sql.v7);
5019         dbms_sql.define_column(v_cursorid,1,v_segment,80);
5020 
5021         if (stmt_flag = 'T') then
5022            dbms_sql.bind_variable(v_cursorid,':lc_soft_coding_keyflex_id',Employee_Rec.soft_coding_keyflex_id);
5023            le_effective_start_date := lemp_effective_start_date;
5024            le_effective_end_date := lemp_effective_end_date;
5025         end if;
5026       else
5027         if (stmt_flag = 'T') then
5028         dbms_sql.bind_variable(v_cursorid,':lc_soft_coding_keyflex_id',Employee_Rec.soft_coding_keyflex_id);
5029            le_effective_start_date := lemp_effective_start_date;
5030            le_effective_end_date := lemp_effective_end_date;
5031        end if;
5032       end if;
5033 
5034 elsif (Emp_attribute_rec.definition_structure = 'Personal Analysis Flexfield') then
5035 
5036      if (Employee_rec.person_id is not null) then
5037         stmt_flag := 'T';
5038      end if;
5039 
5040    if ((l_attribute_id <> prev_attribute_id) or  (prev_attribute_id = -1)) then
5041 
5042      l_sql_stmt := 'Select '||l_application_column_name||
5043                    ' From Per_Analysis_Criteria, Per_Person_Analyses'||
5044                    ' Where Per_Person_Analyses.person_id = :lc_person_id '||
5045                    ' And Per_person_analyses.id_flex_num = :lc_id_flex_num '||
5046                    ' And Per_person_analyses.analysis_criteria_id =  Per_analysis_criteria.analysis_criteria_id '||
5047                    ' And Per_person_analyses.id_flex_num = Per_analysis_criteria.id_flex_num';
5048 
5049         dbms_sql.parse(v_cursorid,l_sql_stmt,dbms_sql.v7);
5050         dbms_sql.define_column(v_cursorid,1,v_segment,80);
5051         dbms_sql.bind_variable(v_cursorid,':lc_id_flex_num', l_id_flex_num);
5052 
5053         if (stmt_flag = 'T') then
5054 
5055            dbms_sql.bind_variable(v_cursorid,':lc_person_id',Employee_Rec.person_id);
5056 
5057            le_effective_start_date := lemp_effective_start_date;
5058            le_effective_end_date := lemp_effective_end_date;
5059 
5060         end if;
5061      else
5062         if (stmt_flag = 'T') then
5063            dbms_sql.bind_variable(v_cursorid,':lc_person_id',Employee_Rec.person_id);
5064            le_effective_start_date := lemp_effective_start_date;
5065            le_effective_end_date := lemp_effective_end_date;
5066         end if;
5067       end if;
5068    end if;
5069 
5070    if (stmt_flag = 'T') then
5071     v_dummy := DBMS_SQL.EXECUTE(v_cursorid);
5072 
5073     loop
5074       ctr := ctr + 1;
5075       v_segment := '';
5076       if DBMS_SQL.FETCH_ROWS(v_cursorid) = 0 then
5077          exit;
5078       end if;
5079       dbms_sql.column_value(v_cursorid,1,v_segment);
5080       if (v_segment is not null) then
5081       if (ctr = 1) then
5082 
5083       INSERT INTO PSB_EMPLOYEE_ASSIGNMENTS_I
5084       ( HR_POSITION_ID  ,
5085         HR_EMPLOYEE_ID  ,
5086         DATA_EXTRACT_ID ,
5087         ATTRIBUTE_NAME  ,
5088         ATTRIBUTE_VALUE ,
5089         EFFECTIVE_START_DATE,
5090         EFFECTIVE_END_DATE ,
5091         LAST_UPDATE_DATE  ,
5092         LAST_UPDATED_BY  ,
5093         LAST_UPDATE_LOGIN ,
5094         CREATED_BY,
5095         CREATION_DATE
5096       )
5097       values
5098       (Employee_rec.position_id,
5099        Employee_rec.person_id,
5100        p_data_extract_id,
5101        Emp_attribute_rec.name,
5102        v_segment,
5103        le_effective_start_date,
5104        le_effective_end_date,
5105        l_last_update_date,
5106        l_last_updated_by,
5107        l_last_update_login,
5108        l_created_by,
5109        l_creation_date);
5110       end if;
5111       end if;
5112      end loop;
5113     end if;
5114     elsif (Emp_attribute_rec.definition_type = 'DFF') then
5115       /* Bug 4075170 Start */
5116       l_debug_info := 'Starting for person_id '||l_person_id||' definition type DFF';
5117       /* Bug 4075170 End */
5118    if ((l_attribute_id <> prev_attribute_id) or  (prev_attribute_id = -1)) then
5119 
5120       if (dbms_sql.IS_OPEN(v_dcursorid)) then
5121          dbms_sql.close_cursor(v_dcursorid);
5122       end if;
5123 
5124       l_attr_link_type := null;
5125 
5126       For C_dff_rec in C_dff_33
5127       Loop
5128          l_application_id            := C_dff_rec.application_id;
5129          l_application_table_name    := C_dff_rec.application_table_name;
5130 
5131         For C_dff_str_rec in C_dff_44
5132         Loop
5133           l_application_column_name := C_dff_str_rec.application_column_name;
5134         End Loop;
5135       End Loop;
5136 
5137     d_attribute_type := Emp_attribute_rec.definition_type;
5138     d_attribute_type_id := Emp_attribute_rec.attribute_type_id;
5139 
5140     For Attr_type_rec in C_Attribute_Types
5141     Loop
5142 
5143     Begin
5144        Select ltrim(rtrim(substr(Attr_type_rec.select_table,
5145               instr(Attr_type_rec.select_table,' ',1),
5146               length(Attr_type_rec.select_table) - instr(Attr_type_rec.select_table,' ',1) + 1))) into l_alias1
5147          from dual;
5148      end;
5149 
5150      if (Attr_type_rec.link_type = 'PER_ALL_ASSIGNMENTS') then
5151          l_emp_col := 'assignment_id';
5152          --l_emp_val := Employee_rec.assignment_id;
5153      elsif (Attr_type_rec.link_type = 'PER_ALL_PEOPLE') then
5154          l_emp_col := 'person_id';
5155          --l_emp_val := Employee_rec.person_id;
5156      elsif (Attr_type_rec.link_type = 'HR_ALL_POSITIONS') then
5157          l_emp_col := 'position_id';
5158          --l_emp_val := Employee_rec.position_id;
5159      end if;
5160      l_attr_link_type := Attr_type_rec.link_type;
5161 
5162      v_dcursorid := dbms_sql.open_cursor;
5163 
5164       /* bug no 3944599 */
5165      IF LTRIM(RTRIM(attr_type_rec.link_type)) = 'HR_ALL_POSITIONS' AND
5166         LTRIM(RTRIM(attr_type_rec.select_tab)) = 'PER_ALL_POSITIONS' AND
5167         LTRIM(RTRIM(attr_type_rec.name)) = 'PER_POSITIONS' THEN
5168 
5169          -- commented out l_alais1 as we are selecting from table HR_ALL_POSITIONS
5170        d_sql_stmt := 'Select '||/*l_alias1*/Attr_type_rec.l_alias2||'.'
5171                             ||l_application_column_name||
5172                      '  From '||Attr_type_rec.select_tab||' '||
5173                             l_alias1||' , '||
5174                      Attr_type_rec.link_type||' '||Attr_type_rec.l_alias2||
5175                      ' Where '||l_alias1||'.'||
5176                      Attr_type_rec.select_key||' = '||
5177                      Attr_type_rec.l_alias2||'.'||Attr_type_rec.link_key||
5178                      ' and '||Attr_type_rec.l_alias2||'.'||l_emp_col||
5179                      ' = '||':v_emp_val';
5180       ELSE
5181         d_sql_stmt := 'Select '||l_alias1||'.'
5182                             ||l_application_column_name||
5183                    '  From '||Attr_type_rec.select_tab||' '||
5184                             l_alias1||' , '||
5185                    Attr_type_rec.link_type||' '||Attr_type_rec.l_alias2||
5186                    ' Where '||l_alias1||'.'||
5187                      Attr_type_rec.select_key||' = '||
5188                      Attr_type_rec.l_alias2||'.'||Attr_type_rec.link_key||
5189                    ' and '||Attr_type_rec.l_alias2||'.'||l_emp_col||
5190                    ' = '||':v_emp_val';
5191      END IF;
5192      /* bug no 3944599 */
5193 
5194      if (Attr_type_rec.select_where is not null) then
5195         d_sql_stmt := d_sql_stmt||' and '||Attr_type_rec.select_where;
5196      end if;
5197 
5198     dbms_sql.parse(v_dcursorid,d_sql_stmt,dbms_sql.v7);
5199     dbms_sql.define_column(v_dcursorid,1,v_dsegment,80);
5200     end loop;
5201 
5202     /* Start bug #4302946 */
5203     IF (l_attr_link_type IS NULL) THEN
5204       FND_MESSAGE.SET_NAME('PSB','PSB_ATTR_MAPPING_NOT_FOUND');
5205       FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME', l_attribute_name);
5206       l_message_text := FND_MESSAGE.GET;
5207       FND_FILE.PUT_LINE(FND_FILE.LOG, l_message_text);
5208       RAISE FND_API.G_EXC_ERROR;
5209     END IF;
5210     /* End bug #4302946 */
5211 
5212    end if;
5213 
5214      if (l_attr_link_type = 'PER_ALL_ASSIGNMENTS') then
5215          l_emp_val := Employee_rec.assignment_id;
5216          le_effective_start_date := lemp_effective_start_date;
5217          le_effective_end_date   := lemp_effective_end_date;
5218      elsif (l_attr_link_type = 'PER_ALL_PEOPLE') then
5219          l_emp_val := Employee_rec.person_id;
5220          le_effective_start_date := lemp_effective_start_date;
5221          le_effective_end_date   := lemp_effective_end_date;
5222      elsif (l_attr_link_type = 'HR_ALL_POSITIONS') then
5223          l_emp_val := Employee_rec.position_id;
5224          le_effective_start_date := lpos_effective_start_date;
5225          le_effective_end_date   := lpos_effective_end_date;
5226      end if;
5227 
5228    if (l_emp_val is not null) then
5229     dbms_sql.bind_variable(v_dcursorid,':v_emp_val',l_emp_val);
5230 
5231     v_ddummy := DBMS_SQL.EXECUTE(v_dcursorid);
5232 
5233    loop
5234       if DBMS_SQL.FETCH_ROWS(v_dcursorid) = 0 then
5235          exit;
5236       end if;
5237 
5238       dbms_sql.column_value(v_dcursorid,1,v_dsegment);
5239 
5240      if (v_dsegment is not null) then
5241 
5242       /* Bug 4075170 Start */
5243       l_debug_info := 'Inserting for Atrribute Name '
5244                       ||Emp_attribute_rec.name
5245                       ||', Atrribute Data Type '||l_data_type
5246                       ||', Atrribute Value '||v_dsegment;
5247       /* Bug 4075170 End */
5248 
5249       INSERT INTO PSB_EMPLOYEE_ASSIGNMENTS_I
5250       ( HR_POSITION_ID  ,
5251         HR_EMPLOYEE_ID  ,
5252         DATA_EXTRACT_ID ,
5253         ATTRIBUTE_NAME  ,
5254         ATTRIBUTE_VALUE ,
5255         EFFECTIVE_START_DATE,
5256         EFFECTIVE_END_DATE ,
5257         LAST_UPDATE_DATE  ,
5258         LAST_UPDATED_BY  ,
5259         LAST_UPDATE_LOGIN ,
5260         CREATED_BY,
5261         CREATION_DATE
5262       )
5263       values
5264       (Employee_rec.position_id,
5265        Employee_rec.person_id,
5266        p_data_extract_id,
5267        Emp_attribute_rec.name,
5268 
5269        -- Fix for bug #4075170 changed the date format to canonical.
5270        -- But since DFF always stores date in canonical format, this conversion is not
5271        -- necessary. So removed the conversion as part for Bug #4658351.
5272        v_dsegment,
5273 
5274        le_effective_start_date,
5275        le_effective_end_date,
5276        l_last_update_date,
5277        l_last_updated_by,
5278        l_last_update_login,
5279        l_created_by,
5280        l_creation_date);
5281       end if;
5282     end loop;
5283    end if;
5284    elsif (Emp_attribute_rec.definition_type = 'QC') then
5285      /* Bug 4075170 Start */
5286      l_debug_info := 'Starting for person_id '||l_person_id||' definition type QC';
5287      /* Bug 4075170 End */
5288 
5289    if ((l_attribute_id <> prev_attribute_id) or (prev_attribute_id = -1)) then
5290     if dbms_sql.is_open(v_qcursorid) then
5291        dbms_sql.close_cursor(v_qcursorid);
5292     end if;
5293 
5294     d_attribute_type := Emp_attribute_rec.definition_type;
5295     d_attribute_type_id := Emp_attribute_rec.attribute_type_id;
5296 
5297     l_attr_link_type := null;
5298 
5299     For Attr_type_rec in C_Attribute_Types
5300     Loop
5301      if (Attr_type_rec.link_type = 'PER_ALL_ASSIGNMENTS') then
5302          l_emp_col := 'assignment_id';
5303          --l_emp_val := Employee_rec.assignment_id;
5304      elsif (Attr_type_rec.link_type = 'PER_ALL_PEOPLE') then
5305          l_emp_col := 'person_id';
5306          --l_emp_val := Employee_rec.person_id;
5307      elsif (Attr_type_rec.link_type = 'HR_ALL_POSITIONS') then
5308          l_emp_col := 'position_id';
5309          --l_emp_val := Employee_rec.position_id;
5310      end if;
5311 
5312      l_lookup_type := Attr_type_rec.name;
5313      l_attr_link_type := Attr_type_rec.link_type;
5314 
5315      Begin
5316        Select ltrim(rtrim(substr(Attr_type_rec.select_table,
5317               instr(Attr_type_rec.select_table,' ',1),
5318               length(Attr_type_rec.select_table) - instr(Attr_type_rec.select_table,' ',1) + 1))) into l_alias1
5319          from dual;
5320      end;
5321 
5322     --if (l_emp_val is not null) then
5323      v_qcursorid := dbms_sql.open_cursor;
5324      q_sql_stmt := 'Select a.meaning '||
5325                    '  From Fnd_Common_lookups a , '||
5326                     Attr_type_rec.select_tab||' '||l_alias1||' ,'||
5327                     Attr_type_rec.link_type||' '||Attr_type_rec.l_alias2||
5328                    ' Where a.lookup_type = '||''''||
5329                    l_lookup_type||''''||
5330                    ' and a.lookup_code = '||
5331                      l_alias1||'.'||Attr_type_rec.select_column||
5332                    ' and '||l_alias1||'.'||Attr_type_rec.select_key||
5333                    ' = '||Attr_type_rec.l_alias2||'.'||Attr_type_rec.link_key||
5334                    ' and '||Attr_type_rec.l_alias2||'.'||l_emp_col||
5335                    ' = '||':v_emp_val';
5336 
5337      if (Attr_type_rec.select_where is not null) then
5338         q_sql_stmt := q_sql_stmt||' and '||Attr_type_rec.select_where;
5339      end if;
5340 
5341     dbms_sql.parse(v_qcursorid,q_sql_stmt,dbms_sql.v7);
5342     dbms_sql.define_column(v_qcursorid,1,v_qsegment,80);
5343     end loop;
5344 
5345     /* Start bug #4302946 */
5346     IF (l_attr_link_type IS NULL) THEN
5347       FND_MESSAGE.SET_NAME('PSB','PSB_ATTR_MAPPING_NOT_FOUND');
5348       FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME', l_attribute_name);
5349       l_message_text := FND_MESSAGE.GET;
5350       FND_FILE.PUT_LINE(FND_FILE.LOG, l_message_text);
5351       RAISE FND_API.G_EXC_ERROR;
5352     END IF;
5353     /* End bug #4302946 */
5354 
5355    end if;
5356 
5357     if (l_attr_link_type = 'PER_ALL_ASSIGNMENTS') then
5358          l_emp_val := Employee_rec.assignment_id;
5359          le_effective_start_date   := lemp_effective_start_date;
5360          le_effective_end_date     := lemp_effective_end_date;
5361     elsif (l_attr_link_type = 'PER_ALL_PEOPLE') then
5362          l_emp_val := Employee_rec.person_id;
5363          le_effective_start_date   := lemp_effective_start_date;
5364          le_effective_end_date     := lemp_effective_end_date;
5365     elsif (l_attr_link_type = 'HR_ALL_POSITIONS') then
5366          l_emp_val := Employee_rec.position_id;
5367          le_effective_start_date   := lpos_effective_start_date;
5368          le_effective_end_date     := lpos_effective_end_date;
5369     end if;
5370 
5371     if (l_emp_val is not null) then
5372     dbms_sql.bind_variable(v_qcursorid,':v_emp_val',l_emp_val);
5373 
5374     v_qdummy := DBMS_SQL.EXECUTE(v_qcursorid);
5375 
5376     loop
5377       if DBMS_SQL.FETCH_ROWS(v_qcursorid) = 0 then
5378          exit;
5379       end if;
5380 
5381       dbms_sql.column_value(v_qcursorid,1,v_qsegment);
5382 
5383      if (v_qsegment is not null) then
5384 
5385       /* Bug 4075170 Start */
5386       l_debug_info := 'Inserting for Atrribute Id '
5387                       ||Emp_attribute_rec.name
5388                       ||', Atrribute Data Type '||l_data_type
5389                       ||', Atrribute Value '||v_qsegment;
5390       /* Bug 4075170 End */
5391 
5392       -- Bug #4658351
5393       -- Moved the date format conversion out of the insert statement.
5394 
5395       if (l_data_type = 'D') then
5396         begin
5397           v_qsegment := Fnd_Date.Date_to_Canonical(v_qsegment);
5398         exception
5399           when OTHERS then
5400             FND_MESSAGE.SET_NAME('PSB', 'PSB_ATTRIBUTE_VALUE_DATE_ERR');
5401             FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME', l_attribute_name);
5402             l_message_text := fnd_message.get;
5403             RAISE_APPLICATION_ERROR(-20001,l_message_text);
5404          end;
5405       end if;
5406 
5407       INSERT INTO PSB_EMPLOYEE_ASSIGNMENTS_I
5408       ( HR_POSITION_ID  ,
5409         HR_EMPLOYEE_ID  ,
5410         DATA_EXTRACT_ID ,
5411         ATTRIBUTE_NAME  ,
5412         ATTRIBUTE_VALUE ,
5413         EFFECTIVE_START_DATE,
5414         EFFECTIVE_END_DATE ,
5415         LAST_UPDATE_DATE  ,
5416         LAST_UPDATED_BY  ,
5417         LAST_UPDATE_LOGIN ,
5418         CREATED_BY,
5419         CREATION_DATE
5420       )
5421       values
5422       (Employee_rec.position_id,
5423        Employee_rec.person_id,
5424        p_data_extract_id,
5425        Emp_attribute_rec.name,
5426 
5427        -- Bug #4658351
5428        -- Moved the date format conversion out of the insert statement.
5429        v_qsegment,
5430 
5431        le_effective_start_date,
5432        le_effective_end_date,
5433        l_last_update_date,
5434        l_last_updated_by,
5435        l_last_update_login,
5436        l_created_by,
5437        l_creation_date);
5438       end if;
5439     end loop;
5440     end if;
5441   elsif (Emp_attribute_rec.definition_type = 'TABLE') then
5442     /* Bug 4075170 Start */
5443     l_debug_info := 'Starting for person_id '||l_person_id||' definition type TABLE';
5444     /* Bug 4075170 End */
5445 
5446    if ((l_attribute_id <> prev_attribute_id) or (prev_attribute_id = -1)) then
5447       if dbms_sql.is_open(v_ocursorid) then
5448          dbms_sql.close_cursor(v_ocursorid);
5449       end if;
5450 
5451    d_attribute_type := Emp_attribute_rec.definition_type;
5452    d_attribute_type_id := Emp_attribute_rec.attribute_type_id;
5453    l_attr_link_type := null;
5454 
5455    For Attr_type_rec in C_Attribute_Types
5456    Loop
5457      if (Attr_type_rec.link_type = 'PER_ALL_ASSIGNMENTS') then
5458          l_emp_col := 'assignment_id';
5459          --l_emp_val := Employee_rec.assignment_id;
5460      elsif (Attr_type_rec.link_type = 'PER_ALL_PEOPLE') then
5461          l_emp_col := 'person_id';
5462          --l_emp_val := Employee_rec.person_id;
5463      elsif (Attr_type_rec.link_type = 'HR_ALL_POSITIONS') then
5464          l_emp_col := 'position_id';
5465          --l_emp_val := Employee_rec.position_id;
5466      end if;
5467 
5468      l_attr_link_type := Attr_type_rec.link_type;
5469      v_ocursorid := dbms_sql.open_cursor;
5470      Begin
5471        Select ltrim(rtrim(substr(Attr_type_rec.select_table,
5472               instr(Attr_type_rec.select_table,' ',1),
5473               length(Attr_type_rec.select_table) - instr(Attr_type_rec.select_table,' ',1) + 1))) into l_alias1
5474          from dual;
5475      End;
5476 
5477      if (Attr_type_rec.select_table = Attr_type_rec.link_type) then
5478         o_sql_stmt := 'Select '||
5479                       Attr_type_rec.select_column||
5480                    '  From '||Attr_type_rec.select_tab||
5481                    '  Where '||Attr_type_rec.select_tab||'.'||l_emp_col||
5482                    ' = '||':v_emp_val';
5483      else
5484         o_sql_stmt := 'Select '||l_alias1||'.'||
5485                       Attr_type_rec.select_column||
5486                    '  From '||Attr_type_rec.select_tab||' '||l_alias1||' , '||
5487                       Attr_type_rec.link_type||' '||Attr_type_rec.l_alias2||
5488                     ' Where '||l_alias1||'.'||
5489                       Attr_type_rec.select_key||' = '||
5490                       Attr_type_rec.l_alias2||'.'||Attr_type_rec.link_key||
5491                     ' and '||Attr_type_rec.l_alias2||'.'||l_emp_col||
5492                     ' = '||':v_emp_val';
5493      end if;
5494 
5495      if (Attr_type_rec.select_where is not null) then
5496         o_sql_stmt := o_sql_stmt||' and '||Attr_type_rec.select_where;
5497      end if;
5498 
5499     dbms_sql.parse(v_ocursorid,o_sql_stmt,dbms_sql.v7);
5500 
5501     if (Emp_attribute_rec.data_type = 'D') then
5502        dbms_sql.define_column(v_ocursorid,1,v_odate);
5503     elsif (Emp_attribute_rec.data_type = 'N') then
5504        dbms_sql.define_column(v_ocursorid,1,v_onumber);
5505     elsif (Emp_attribute_rec.data_type = 'C') then
5506        dbms_sql.define_column(v_ocursorid,1,v_osegment,80);
5507     end if;
5508 
5509    end loop;
5510 
5511    /* Start bug #4302946 */
5512    IF (l_attr_link_type IS NULL) THEN
5513      FND_MESSAGE.SET_NAME('PSB','PSB_ATTR_MAPPING_NOT_FOUND');
5514      FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME', l_attribute_name);
5515      l_message_text := FND_MESSAGE.GET;
5516      FND_FILE.PUT_LINE(FND_FILE.LOG, l_message_text);
5517      RAISE FND_API.G_EXC_ERROR;
5518    END IF;
5519    /* End bug #4302946 */
5520 
5521   end if;
5522 
5523     if (l_attr_link_type = 'PER_ALL_ASSIGNMENTS') then
5524          l_emp_val := Employee_rec.assignment_id;
5525          le_effective_start_date   := lemp_effective_start_date;
5526          le_effective_end_date     := lemp_effective_end_date;
5527     elsif (l_attr_link_type = 'PER_ALL_PEOPLE') then
5528          l_emp_val := Employee_rec.person_id;
5529          le_effective_start_date   := lemp_effective_start_date;
5530          le_effective_end_date     := lemp_effective_end_date;
5531     elsif (l_attr_link_type = 'HR_ALL_POSITIONS') then
5532          l_emp_val := Employee_rec.position_id;
5533          le_effective_start_date   := lpos_effective_start_date;
5534          le_effective_end_date     := lpos_effective_end_date;
5535     end if;
5536 
5537    if (l_emp_val is not null) then
5538     dbms_sql.bind_variable(v_ocursorid,':v_emp_val',l_emp_val);
5539     v_odummy := DBMS_SQL.EXECUTE(v_ocursorid);
5540 
5541    loop
5542       if DBMS_SQL.FETCH_ROWS(v_ocursorid) = 0 then
5543          exit;
5544       end if;
5545       if (Emp_attribute_rec.data_type = 'D') then
5546        begin
5547          dbms_sql.column_value(v_ocursorid,1,v_odate);
5548          v_osegment := fnd_date.date_to_canonical(v_odate);
5549        exception
5550        when OTHERS then -- Bug #4658351: Changed VALUE_ERROR to OTHERS
5551 
5552          -- Changed the exception part for Bug#4658351
5553          FND_MESSAGE.SET_NAME('PSB', 'PSB_ATTRIBUTE_VALUE_DATE_ERR');
5554          FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME', l_attribute_name);
5555          l_message_text := fnd_message.get;
5556          RAISE_APPLICATION_ERROR(-20001,l_message_text);
5557 
5558       end;
5559       elsif (Emp_attribute_rec.data_type = 'N') then
5560       begin
5561          dbms_sql.column_value(v_ocursorid,1,v_onumber);
5562          v_osegment := fnd_number.number_to_canonical(v_onumber);
5563       exception
5564        when INVALID_NUMBER then
5565 
5566          -- Changed the exception part for Bug#4658351
5567          FND_MESSAGE.SET_NAME('PSB', 'PSB_ATTRIBUTE_VALUE_NUMBER_ERR');
5568          FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME', l_attribute_name);
5569          l_message_text := fnd_message.get;
5570          RAISE_APPLICATION_ERROR(-20000,l_message_text);
5571 
5572       end;
5573 
5574       elsif (Emp_attribute_rec.data_type = 'C') then
5575         dbms_sql.column_value(v_ocursorid,1,v_osegment);
5576       end if;
5577 
5578      if (v_osegment is not null) then
5579 
5580       INSERT INTO PSB_EMPLOYEE_ASSIGNMENTS_I
5581       ( HR_POSITION_ID  ,
5582         HR_EMPLOYEE_ID  ,
5583         DATA_EXTRACT_ID ,
5584         ATTRIBUTE_NAME  ,
5585         ATTRIBUTE_VALUE ,
5586         EFFECTIVE_START_DATE,
5587         EFFECTIVE_END_DATE ,
5588         LAST_UPDATE_DATE  ,
5589         LAST_UPDATED_BY  ,
5590         LAST_UPDATE_LOGIN ,
5591         CREATED_BY,
5592         CREATION_DATE
5593       )
5594       values
5595       (Employee_rec.position_id,
5596        Employee_rec.person_id,
5597        p_data_extract_id,
5598        Emp_attribute_rec.name,
5599        v_osegment,
5600        le_effective_start_date,
5601        le_effective_end_date,
5602        l_last_update_date,
5603        l_last_updated_by,
5604        l_last_update_login,
5605        l_created_by,
5606        l_creation_date);
5607       end if;
5608     end loop;
5609     end if;
5610   elsif (Emp_attribute_rec.definition_type is NULL) then
5611     /* Bug 4075170 Start */
5612     l_debug_info := 'Starting for person_id '||l_person_id
5613                     ||' definition type NULL'
5614                     ||' system_attr_type '
5615                     ||Emp_attribute_rec.system_attribute_type;
5616     /* Bug 4075170 End */
5617    if (Emp_attribute_rec.system_attribute_type = 'JOB_CLASS') then
5618 
5619    -- Commented out for bug number 3159157
5620    /*if ((l_attribute_id <> prev_attribute_id) or (prev_attribute_id = -1)) then
5621       For C_job_structure_rec in C_job_structure
5622       Loop
5623         l_id_flex_num := C_job_structure_rec.job_structure;
5624       End Loop;
5625 
5626       if dbms_sql.is_open(v_jcursorid) then
5627          dbms_sql.close_cursor(v_jcursorid);
5628       end if;
5629 
5630       v_jcursorid := DBMS_SQL.OPEN_CURSOR;
5631       l_job_stmt := 'Select concatenated_segments '||
5632                     'from per_jobs pj,per_job_definitions_kfv pjv '||
5633                     'where  pj.job_id = '||':lc_job_id'||
5634                     ' and  pj.job_definition_id = pjv.job_definition_id '||
5635                     ' and  pjv.id_flex_num = '||l_id_flex_num;
5636 
5637      dbms_sql.parse(v_jcursorid,l_job_stmt,dbms_sql.v7);
5638      dbms_sql.define_column(v_jcursorid,1,l_concatenated_segments,80);
5639    end if;*/
5640 
5641    l_job_id   := Employee_rec.job_id;
5642    le_effective_start_date   := lpos_effective_start_date;
5643    le_effective_end_date     := lpos_effective_end_date;
5644 
5645    -- Commented out for bug number 3159157
5646    /*dbms_sql.bind_variable(v_jcursorid,':lc_job_id',l_job_id);
5647    v_jdummy := DBMS_SQL.EXECUTE(v_jcursorid);*/
5648 
5649    For C_job_name_rec in C_job_name
5650    Loop
5651       l_job_name := C_job_name_rec.name;
5652    End Loop;
5653 
5654    INSERT INTO PSB_EMPLOYEE_ASSIGNMENTS_I
5655    ( HR_POSITION_ID  ,
5656      HR_EMPLOYEE_ID  ,
5657      DATA_EXTRACT_ID ,
5658      ATTRIBUTE_NAME  ,
5659      ATTRIBUTE_VALUE ,
5660      EFFECTIVE_START_DATE,
5661      EFFECTIVE_END_DATE ,
5662      LAST_UPDATE_DATE  ,
5663      LAST_UPDATED_BY  ,
5664      LAST_UPDATE_LOGIN ,
5665      CREATED_BY,
5666      CREATION_DATE
5667    )
5668    values
5669    (Employee_rec.position_id,
5670     Employee_rec.person_id,
5671     p_data_extract_id,
5672     Emp_attribute_rec.name,
5673     l_job_name,
5674     le_effective_start_date,
5675     le_effective_end_date,
5676     l_last_update_date,
5677     l_last_updated_by,
5678     l_last_update_login,
5679     l_created_by,
5680     l_creation_date);
5681    elsif (Emp_attribute_rec.system_attribute_type = 'ORG') then
5682 
5683      l_organization_id         := Employee_Rec.organization_id;
5684      le_effective_start_date   := lpos_effective_start_date;
5685      le_effective_end_date     := lpos_effective_end_date;
5686 
5687      For C_Org_Rec in C_Pos_Org
5688      Loop
5689        l_organization_name := C_Org_Rec.name;
5690      End Loop;
5691 
5692    INSERT INTO PSB_EMPLOYEE_ASSIGNMENTS_I
5693    ( HR_POSITION_ID  ,
5694      HR_EMPLOYEE_ID  ,
5695      DATA_EXTRACT_ID ,
5696      ATTRIBUTE_NAME  ,
5697      ATTRIBUTE_VALUE ,
5698      EFFECTIVE_START_DATE,
5699      EFFECTIVE_END_DATE ,
5700      LAST_UPDATE_DATE  ,
5701      LAST_UPDATED_BY  ,
5702      LAST_UPDATE_LOGIN ,
5703      CREATED_BY,
5704      CREATION_DATE
5705    )
5706    values
5707    (Employee_rec.position_id,
5708     Employee_rec.person_id,
5709     p_data_extract_id,
5710     Emp_attribute_rec.name,
5711     l_organization_name,
5712     le_effective_start_date,
5713     le_effective_end_date,
5714     l_last_update_date,
5715     l_last_updated_by,
5716     l_last_update_login,
5717     l_created_by,
5718     l_creation_date);
5719   elsif (Emp_attribute_rec.system_attribute_type = 'FTE') then
5720     -- Handle Fte Code
5721     l_fte := null;
5722     lp_fte := null;
5723     le_effective_start_date := null;
5724     le_effective_end_date   := null;
5725 
5726     /*For Bug No : 2109120 Start*/
5727     /*if (Employee_Rec.fte is not null) then
5728        l_fte                     := Employee_Rec.fte;
5729        le_effective_start_date   := lpos_effective_start_date;
5730        le_effective_end_date     := lpos_effective_end_date;
5731     else
5732        l_assignment_id := Employee_Rec.assignment_id;
5733        For C_Fte_Rec in C_Fte
5734        Loop
5735          l_fte                   := C_Fte_Rec.value;
5736          le_effective_start_date := lemp_effective_start_date;
5737          le_effective_end_date   := lemp_effective_end_date;
5738        End Loop;
5739     end if; */
5740 
5741     IF (Employee_Rec.assignment_id IS NOT NULL) THEN
5742 
5743       /* Bug 5004141 Start */
5744       -- l_fte := 1;
5745       IF Employee_Rec.position_type = 'SINGLE' THEN
5746         l_fte := Employee_Rec.fte;
5747       ELSE
5748         l_fte := 1;
5749       END IF;
5750       /* Bug 5004141 End */
5751 
5752       l_assignment_id := Employee_Rec.assignment_id;
5753       For C_Fte_Rec in C_Fte Loop
5754         l_fte                   := C_Fte_Rec.value;
5755       End Loop;
5756 
5757       le_effective_start_date := lemp_effective_start_date;
5758       le_effective_end_date   := lemp_effective_end_date;
5759 
5760     ELSIF (Employee_Rec.position_type <> 'SINGLE') THEN
5761 
5762       FOR C_check_FTE_rec IN C_check_FTE(Employee_Rec.position_id) LOOP
5763         l_fte := Employee_Rec.fte - C_check_FTE_rec.sum_fte;
5764       END LOOP;
5765 
5766       IF l_fte IS NULL THEN
5767         l_fte := Employee_Rec.fte;
5768       END IF;
5769 
5770       le_effective_start_date   := lpos_effective_start_date;
5771       le_effective_end_date     := lpos_effective_end_date;
5772 
5773     ELSE
5774 
5775       l_fte                     := Employee_Rec.fte;
5776     /* start bug 4153562 */
5777     --  The l_date_rec cursor takes position_id as the input
5778     --  and returns the start date for that position. This
5779     --  will run only for the terminated position and when the
5780     --  data extract mode is refresh. When the start date is passed
5781     --  as end date, the procedure will end date and create a new
5782     --  record for the attribute.
5783     --  le_effective_start_date   := lpos_effective_start_date;
5784     if p_extract_method = 'REFRESH' then
5785       FOR l_date_rec IN (
5786                           SELECT effective_start_date
5787                           FROM (
5788                           SELECT a.effective_start_date
5789                           FROM   per_all_assignments_f a,
5790                                  fnd_sessions b,
5791                                  per_assignment_status_types c
5792                           WHERE  a.position_id = Employee_rec.position_id
5793                           AND    a.assignment_status_type_id = c.assignment_status_type_id
5794                           AND    c.per_system_status = 'TERM_ASSIGN'
5795                           AND    b.effective_date BETWEEN a.effective_start_date
5796                                  AND to_date('31124712','DDMMYYYY')
5797                           AND    b.session_id = userenv('sessionid')
5798                           ORDER BY a.effective_start_date DESC
5799                           )
5800                           WHERE ROWNUM <= 1
5801                         ) LOOP
5802 
5803         lv_effective_end_date := l_date_rec.effective_start_date;
5804 
5805       END LOOP;
5806 
5807       IF lv_effective_end_date is not null THEN
5808         le_effective_start_date   := lv_effective_end_date;
5809       ELSE
5810         le_effective_start_date   := lpos_effective_start_date;
5811       END IF;
5812 
5813     else
5814       le_effective_start_date   := lpos_effective_start_date;
5815     end if;
5816     /* End bug 4153562 */
5817 
5818       le_effective_end_date     := lpos_effective_end_date;
5819 
5820     END IF;
5821 
5822     /*For Bug No : 2109120 End*/
5823 
5824    if (l_fte is not null) then
5825 
5826    lp_fte := fnd_number.number_to_canonical(l_fte);
5827 
5828    INSERT INTO PSB_EMPLOYEE_ASSIGNMENTS_I
5829    ( HR_POSITION_ID  ,
5830      HR_EMPLOYEE_ID  ,
5831      DATA_EXTRACT_ID ,
5832      ATTRIBUTE_NAME  ,
5833      ATTRIBUTE_VALUE ,
5834      EFFECTIVE_START_DATE,
5835      EFFECTIVE_END_DATE ,
5836      LAST_UPDATE_DATE  ,
5837      LAST_UPDATED_BY  ,
5838      LAST_UPDATE_LOGIN ,
5839      CREATED_BY,
5840      CREATION_DATE
5841    )
5842    values
5843    (Employee_rec.position_id,
5844     Employee_rec.person_id,
5845     p_data_extract_id,
5846     Emp_attribute_rec.name,
5847     lp_fte,
5848     le_effective_start_date,
5849     le_effective_end_date,
5850     l_last_update_date,
5851     l_last_updated_by,
5852     l_last_update_login,
5853     l_created_by,
5854     l_creation_date);
5855     end if;
5856   elsif (Emp_attribute_rec.system_attribute_type = 'DEFAULT_WEEKLY_HOURS') then
5857    -- Handle Default Weekly hours
5858     l_default_weekly_hours := null;
5859     lp_default_weekly_hours := null;
5860     le_effective_start_date := null;
5861     le_effective_end_date   := null;
5862 
5863     /*For Bug No : 2370607 Start*/
5864     --changed the condition from frequency to working_hours
5865     --and added the inner if condition
5866     if (Employee_Rec.working_hours is not null) then
5867        l_default_weekly_hours    := Employee_Rec.working_hours;
5868        lp_default_weekly_hours   := fnd_number.number_to_canonical(l_default_weekly_hours);
5869 
5870        if(Employee_Rec.freq_flag = 'P') then
5871 
5872          /* start bug 4153562 */
5873 
5874          --  The l_date_rec cursor takes position_id as the input
5875          --  and returns the start date for that position. This
5876          --  will run only for the terminated position and when the
5877          --  data extract mode is refresh. When the start date is passed
5878          --  as end date, the procedure will end date and create a new
5879          --  record for the attribute.
5880 
5881          if p_extract_method = 'REFRESH' AND Employee_Rec.assignment_id IS NULL then
5882            if Employee_Rec.position_type = 'SINGLE' then
5883 
5884              FOR l_date_rec IN ( SELECT effective_start_date
5885                                  FROM (
5886                                         SELECT a.effective_start_date
5887                                         FROM   per_all_assignments_f a,
5888                                                fnd_sessions b,
5889                                                per_assignment_status_types c
5890                                         WHERE  a.position_id = Employee_rec.position_id
5891                                         AND    a.assignment_status_type_id = c.assignment_status_type_id
5892                                         AND    c.per_system_status = 'TERM_ASSIGN'
5893                                         AND    b.effective_date BETWEEN a.effective_start_date
5894                                                                 AND to_date('31124712','DDMMYYYY')
5895                                         AND    b.session_id = userenv('sessionid')
5896                                         ORDER BY a.effective_start_date DESC
5897                                        )
5898                                  WHERE ROWNUM <= 1
5899                                ) LOOP
5900 
5901                lv_effective_end_date := l_date_rec.effective_start_date;
5902              END LOOP;
5903 
5904             IF lv_effective_end_date is not null THEN
5905               le_effective_start_date   := lv_effective_end_date;
5906             ELSE
5907               le_effective_start_date   := lpos_effective_start_date;
5908             END IF;
5909           else
5910             le_effective_start_date   := lpos_effective_start_date;
5911           end if;
5912          else
5913 	  le_effective_start_date   := lpos_effective_start_date;
5914          end if;
5915 
5916          -- le_effective_start_date   := lpos_effective_start_date;
5917         /* end bug 4153562 */
5918 
5919          le_effective_end_date     := lpos_effective_end_date;
5920        else
5921          le_effective_start_date   := lemp_effective_start_date;
5922          le_effective_end_date     := lemp_effective_end_date;
5923        end if;
5924 
5925     /*For Bug No : 2370607 End*/
5926 
5927        INSERT INTO PSB_EMPLOYEE_ASSIGNMENTS_I
5928        ( HR_POSITION_ID  ,
5929         HR_EMPLOYEE_ID  ,
5930         DATA_EXTRACT_ID ,
5931         ATTRIBUTE_NAME  ,
5932         ATTRIBUTE_VALUE ,
5933         EFFECTIVE_START_DATE,
5934         EFFECTIVE_END_DATE ,
5935         LAST_UPDATE_DATE  ,
5936         LAST_UPDATED_BY  ,
5937         LAST_UPDATE_LOGIN ,
5938         CREATED_BY,
5939         CREATION_DATE
5940       )
5941       values
5942       (Employee_rec.position_id,
5943        Employee_rec.person_id,
5944        p_data_extract_id,
5945        Emp_attribute_rec.name,
5946        lp_default_weekly_hours,
5947        le_effective_start_date,
5948        le_effective_end_date,
5949        l_last_update_date,
5950        l_last_updated_by,
5951        l_last_update_login,
5952        l_created_by,
5953        l_creation_date);
5954     end if;
5955   /*For Bug No : 2109120 Start*/
5956   --added the persion_id condition in the following line
5957   elsif (Emp_attribute_rec.system_attribute_type = 'HIREDATE'
5958          AND Employee_Rec.person_id IS NOT NULL) then
5959   /*For Bug No : 2109120 End*/
5960      l_hiredate := null;
5961      lp_hiredate := null;
5962 
5963      /*For Bug No : 2109120 Start*/
5964      /*if (Employee_Rec.earliest_hire_date is not null) then
5965        l_hiredate                := Employee_Rec.earliest_hire_date;
5966        le_effective_start_date   := lpos_effective_start_date;
5967        le_effective_end_date     := lpos_effective_end_date;
5968      else
5969        l_person_id               := Employee_Rec.person_id;
5970 
5971        For C_Hiredate_Rec in C_Hiredate
5972        Loop
5973           l_hiredate := C_Hiredate_Rec.start_date;
5974        End Loop;
5975 
5976        le_effective_start_date := lemp_effective_start_date;
5977        le_effective_end_date   := lemp_effective_end_date;
5978      end if;*/
5979 
5980      l_person_id               := Employee_Rec.person_id;
5981      For C_Hiredate_Rec in C_Hiredate
5982      Loop
5983        l_hiredate := C_Hiredate_Rec.start_date;
5984        le_effective_start_date := lemp_effective_start_date;
5985        le_effective_end_date   := lemp_effective_end_date;
5986      End Loop;
5987 
5988      /*For Bug No : 2109120 End*/
5989 
5990 
5991       if (l_hiredate is not null) then
5992        lp_hiredate := fnd_date.date_to_canonical(l_hiredate);
5993        INSERT INTO PSB_EMPLOYEE_ASSIGNMENTS_I
5994        ( HR_POSITION_ID  ,
5995         HR_EMPLOYEE_ID  ,
5996         DATA_EXTRACT_ID ,
5997         ATTRIBUTE_NAME  ,
5998         ATTRIBUTE_VALUE ,
5999         EFFECTIVE_START_DATE,
6000         EFFECTIVE_END_DATE ,
6001         LAST_UPDATE_DATE  ,
6002         LAST_UPDATED_BY  ,
6003         LAST_UPDATE_LOGIN ,
6004         CREATED_BY,
6005         CREATION_DATE
6006       )
6007       values
6008       (Employee_rec.position_id,
6009        Employee_rec.person_id,
6010        p_data_extract_id,
6011        Emp_attribute_rec.name,
6012        lp_hiredate,
6013        le_effective_start_date,
6014        le_effective_end_date,
6015        l_last_update_date,
6016        l_last_updated_by,
6017        l_last_update_login,
6018        l_created_by,
6019        l_creation_date);
6020     end if;
6021   end if;
6022   end if;
6023   prev_attribute_id := l_attribute_id;
6024 
6025   end loop; --C_Employees
6026 
6027 
6028   if (dbms_sql.is_open(v_cursorid)) then
6029       dbms_sql.close_cursor(v_cursorid);
6030   end if;
6031 
6032   if (dbms_sql.is_open(v_dcursorid)) then
6033       dbms_sql.close_cursor(v_dcursorid);
6034   end if;
6035 
6036   if (dbms_sql.is_open(v_qcursorid)) then
6037       dbms_sql.close_cursor(v_qcursorid);
6038   end if;
6039 
6040   if (dbms_sql.is_open(v_ocursorid)) then
6041       dbms_sql.close_cursor(v_ocursorid);
6042   end if;
6043 
6044   if (dbms_sql.is_open(v_jcursorid)) then
6045       dbms_sql.close_cursor(v_jcursorid);
6046   end if;
6047 
6048   prev_attribute_id := l_attribute_id;
6049 
6050 end loop; --C_Emp_Attributes
6051 
6052   --
6053   -- Updating 'FTE' information for the position assignments.
6054   --
6055 
6056   --
6057   -- Loop to get all the pooled position where 'FTE' is define at the
6058   -- position level. As the attribute_value will be same for all instances
6059   -- of the pooled positions, using max to pick up any one.  The HAVING
6060   -- clause ensures the query picks up pooled positions only.
6061   --
6062   l_link_type := null;
6063   FOR l_fte_link_rec IN
6064   (
6065     SELECT link_type
6066       from PSB_ATTRIBUTES_VL a, PSB_ATTRIBUTE_TYPES B
6067      WHERE a.business_group_id = p_business_group_id
6068        AND a.system_attribute_type = 'FTE'
6069        AND a.attribute_type_id = b.attribute_type_id
6070   )
6071   LOOP
6072     l_link_type := l_fte_link_rec.link_type;
6073   END LOOP;
6074 
6075 
6076   if (l_link_type  = 'P') then
6077   FOR l_emp_assgn_rec IN
6078   (
6079     SELECT hr_position_id                         ,
6080            MAX(attribute_value)   total_fte       ,
6081            COUNT(hr_employee_id)  total_employees
6082     FROM   psb_employee_assignments_i
6083     WHERE  data_extract_id = p_data_extract_id
6084     AND    attribute_value IS NOT NULL
6085     AND    hr_employee_id  IS NOT NULL
6086     AND    attribute_name IN
6087            (
6088              SELECT name
6089              FROM   psb_attributes_VL
6090              WHERE  system_attribute_type = 'FTE'
6091              AND    business_group_id     = p_business_group_id
6092            )
6093     GROUP  BY  hr_position_id
6094     HAVING COUNT(hr_position_id) > 1
6095   )
6096   LOOP
6097 
6098     -- Find the average FTE to be divided among the employees.
6099     l_average_fte := ROUND (l_emp_assgn_rec.total_fte /
6100                      l_emp_assgn_rec.total_employees, 2 )  ;
6101 
6102     l_allocated_fte := 0 ;
6103 
6104     -- Distribute average FTE to all the employees associated with the
6105     -- pooled positions.
6106     FOR l_emp_rec IN
6107     ( SELECT ROWID,
6108              ROWNUM
6109       FROM   psb_employee_assignments_i
6110       WHERE  hr_position_id = l_emp_assgn_rec.hr_position_id
6111         AND  data_extract_id = p_data_extract_id
6112         AND  attribute_value IS NOT NULL
6113         AND  hr_employee_id  IS NOT NULL
6114         AND  attribute_name IN
6115              (
6116              SELECT name
6117              FROM   psb_attributes
6118              WHERE  system_attribute_type = 'FTE'
6119              AND    business_group_id     = p_business_group_id
6120            )
6121     )
6122     LOOP
6123 
6124       --
6125       -- The allocate FTE must equal the total_fte. The following will ensure
6126       -- that the last employee will get the remaining of the FTE.
6127       --
6128       IF l_emp_rec.rownum = l_emp_assgn_rec.total_employees THEN
6129         l_fte := l_emp_assgn_rec.total_fte - l_allocated_fte ;
6130       ELSE
6131         l_fte := l_average_fte ;
6132       END IF ;
6133 
6134       -- Update the FTE information.
6135       UPDATE psb_employee_assignments_i
6136       SET    attribute_value = l_fte
6137       WHERE  rowid           = l_emp_rec.rowid ;
6138 
6139       l_allocated_fte := l_allocated_fte + l_fte ;
6140 
6141     END LOOP ; -- End distributing average FTE.
6142 
6143   END LOOP ; -- End processing all the pooled positions.
6144 
6145   --
6146   -- End updating 'FTE' information.
6147   --
6148   end if;
6149 
6150   Update_Reentry
6151  ( p_api_version              => 1.0  ,
6152    p_return_status            => l_return_status,
6153    p_msg_count                => l_msg_count,
6154    p_msg_data                 => l_msg_data,
6155    p_data_extract_id          => p_data_extract_id,
6156    p_extract_method           => p_extract_method,
6157    p_process                  => 'Position Assignments Interface',
6158    p_restart_id               => prev_attribute_id
6159   );
6160 
6161   if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6162      raise FND_API.G_EXC_ERROR;
6163   end if;
6164 
6165   Reentrant_Process
6166   ( p_api_version              => 1.0  ,
6167     p_return_status            => l_return_status,
6168     p_msg_count                => l_msg_count,
6169     p_msg_data                 => l_msg_data,
6170     p_data_extract_id          => p_data_extract_id,
6171     p_extract_method           => p_extract_method,
6172     p_process                  => 'Position Assignments Interface'
6173   );
6174 
6175   if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6176      raise FND_API.G_EXC_ERROR;
6177   end if;
6178 
6179  end if;
6180 
6181 EXCEPTION
6182 
6183    when FND_API.G_EXC_ERROR then
6184      /* Bug 4075170 Start */
6185      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Last Status::>'||l_debug_info);
6186      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Parameter Info::'||l_param_info);
6187      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Error Type:: FND_API.G_EXC_ERROR');
6188      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Get_Employee_Attributes API '
6189                                       ||'failed due to the following error');
6190      FND_FILE.PUT_LINE(FND_FILE.LOG, sqlerrm);
6191      /* Bug 4075170 End */
6192 
6193      if (dbms_sql.is_open(v_cursorid)) then
6194         dbms_sql.close_cursor(v_cursorid);
6195      end if;
6196 
6197      if (dbms_sql.is_open(v_dcursorid)) then
6198         dbms_sql.close_cursor(v_dcursorid);
6199      end if;
6200 
6201      if (dbms_sql.is_open(v_qcursorid)) then
6202         dbms_sql.close_cursor(v_qcursorid);
6203      end if;
6204 
6205      if (dbms_sql.is_open(v_ocursorid)) then
6206         dbms_sql.close_cursor(v_ocursorid);
6207      end if;
6208 
6209      if (dbms_sql.is_open(v_jcursorid)) then
6210         dbms_sql.close_cursor(v_jcursorid);
6211      end if;
6212 
6213      rollback to Get_Employee_Attributes;
6214      p_return_status := FND_API.G_RET_STS_ERROR;
6215      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
6216                                  p_data  => p_msg_data);
6217      message_token('POSITION_NAME',l_position_name );
6218      message_token('EMPLOYEE_NAME',l_employee_name );
6219      add_message('PSB', 'PSB_POSITION_DETAILS');
6220 
6221      message_token('ATTRIBUTE NAME',l_attribute_name );
6222      message_token('DEFINITION_TYPE',l_definition_type );
6223      message_token('DEFINITION_STRUCTURE',l_definition_structure);
6224      message_token('DEFINITION_TABLE',l_definition_table);
6225      message_token('DEFINITION_COLUMN',l_definition_column);
6226      add_message('PSB', 'PSB_ATTRIBUTE_DETAILS');
6227 
6228    when FND_API.G_EXC_UNEXPECTED_ERROR then
6229      /* Bug 4075170 Start */
6230      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Last Status::>'||l_debug_info);
6231      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Parameter Info::'||l_param_info);
6232      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Error Type:: FND_API.G_EXC_UNEXPECTED_ERROR');
6233      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Get_Employee_Attributes API '
6234                                       ||'failed due to the following error');
6235      FND_FILE.PUT_LINE(FND_FILE.LOG, sqlerrm);
6236      /* Bug 4075170 End */
6237 
6238      if (dbms_sql.is_open(v_cursorid)) then
6239         dbms_sql.close_cursor(v_cursorid);
6240      end if;
6241 
6242      if (dbms_sql.is_open(v_dcursorid)) then
6243         dbms_sql.close_cursor(v_dcursorid);
6244      end if;
6245 
6246      if (dbms_sql.is_open(v_qcursorid)) then
6247         dbms_sql.close_cursor(v_qcursorid);
6248      end if;
6249 
6250      if (dbms_sql.is_open(v_ocursorid)) then
6251         dbms_sql.close_cursor(v_ocursorid);
6252      end if;
6253 
6254      if (dbms_sql.is_open(v_jcursorid)) then
6255         dbms_sql.close_cursor(v_jcursorid);
6256      end if;
6257 
6258      rollback to Get_Employee_Attributes;
6259      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6260      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
6261                                  p_data  => p_msg_data);
6262      message_token('POSITION_NAME',l_position_name );
6263      message_token('EMPLOYEE_NAME',l_employee_name );
6264      add_message('PSB', 'PSB_POSITION_DETAILS');
6265 
6266      message_token('ATTRIBUTE_NAME',l_attribute_name );
6267      message_token('DEFINITION_TYPE',l_definition_type );
6268      message_token('DEFINITION_STRUCTURE',l_definition_structure);
6269      message_token('DEFINITION_TABLE',l_definition_table);
6270      message_token('DEFINITION_COLUMN',l_definition_column);
6271      add_message('PSB', 'PSB_ATTRIBUTE_DETAILS');
6272 
6273    when OTHERS then
6274      /* Bug 4075170 Start */
6275      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Last Status::>'||l_debug_info);
6276      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Parameter Info::'||l_param_info);
6277      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Error Type:: WHEN OTHERS');
6278      FND_FILE.PUT_LINE(FND_FILE.LOG, 'Get_Employee_Attributes API '
6279                                       ||'failed due to the following error');
6280      FND_FILE.PUT_LINE(FND_FILE.LOG, sqlerrm);
6281      /* Bug 4075170 End */
6282 
6283      if (dbms_sql.is_open(v_cursorid)) then
6284         dbms_sql.close_cursor(v_cursorid);
6285      end if;
6286 
6287      if (dbms_sql.is_open(v_dcursorid)) then
6288         dbms_sql.close_cursor(v_dcursorid);
6289      end if;
6290 
6291      if (dbms_sql.is_open(v_qcursorid)) then
6292         dbms_sql.close_cursor(v_qcursorid);
6293      end if;
6294 
6295      if (dbms_sql.is_open(v_ocursorid)) then
6296         dbms_sql.close_cursor(v_ocursorid);
6297      end if;
6298 
6299      if (dbms_sql.is_open(v_jcursorid)) then
6300         dbms_sql.close_cursor(v_jcursorid);
6301      end if;
6302      rollback to Get_Employee_Attributes;
6303      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6304      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
6305                                  p_data  => p_msg_data);
6306 
6307      message_token('POSITION_NAME',l_position_name );
6308      message_token('EMPLOYEE_NAME',l_employee_name );
6309      add_message('PSB', 'PSB_POSITION_DETAILS');
6310 
6311      message_token('ATTRIBUTE_NAME',l_attribute_name );
6312      message_token('DEFINITION_TYPE',l_definition_type );
6313      message_token('DEFINITION_STRUCTURE',l_definition_structure);
6314      message_token('DEFINITION_TABLE',l_definition_table);
6315      message_token('DEFINITION_COLUMN',l_definition_column);
6316      add_message('PSB', 'PSB_ATTRIBUTE_DETAILS');
6317      if FND_MSG_PUB.Check_Msg_Level
6318        (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6319      then
6320        FND_MSG_PUB.Add_Exc_Msg
6321           (p_pkg_name => G_PKG_NAME,
6322            p_procedure_name => l_api_name);
6323     end if;
6324 
6325 End Get_Employee_Attributes;
6326 
6327 PROCEDURE Check_Reentry
6328 ( p_api_version         IN    NUMBER,
6329   p_return_status       OUT   NOCOPY VARCHAR2,
6330   p_msg_count           OUT   NOCOPY NUMBER,
6331   p_msg_data            OUT   NOCOPY VARCHAR2,
6332   p_data_extract_id     IN    NUMBER,
6333   p_process             IN    VARCHAR2,
6334   p_status              OUT   NOCOPY VARCHAR2,
6335   p_restart_id          OUT   NOCOPY NUMBER
6336 ) AS
6337 
6338   Cursor C_Reentrant is
6339          Select nvl(sp1_status,'I'),
6340                 nvl(sp2_status,'I'),
6341                 nvl(sp3_status,'I'),
6342                 nvl(sp4_status,'I'),
6343                 nvl(sp5_status,'I'),
6344                 nvl(sp6_status,'I'),
6345                 nvl(sp7_status,'I'),
6346                 nvl(sp8_status,'I'),
6347                 nvl(sp9_status,'I'),
6348                 nvl(sp10_status,'I'),
6349                 nvl(sp11_status,'I'),
6350                 nvl(sp12_status,'I'),
6351                 nvl(sp13_status,'I'),
6352                 nvl(sp14_status,'I'),
6353                 nvl(sp15_status,'I'),
6354                 nvl(sp16_status,'I'),
6355                 nvl(sp17_status,'I'),
6356                 nvl(sp18_status,'I'),
6357                 nvl(sp19_status,'I'),
6358                 attribute1,
6359                 attribute2,
6360                 nvl(to_number(attribute3),0),
6361                 nvl(to_number(attribute11),0),
6362                 nvl(to_number(attribute12),0),
6363                 nvl(to_number(attribute13),0),
6364                 nvl(to_number(attribute14),0),
6365                 nvl(to_number(attribute15),0),
6366                 nvl(to_number(attribute16),0),
6367                 nvl(to_number(attribute17),0),
6368                 nvl(to_number(attribute18),0),
6369                 nvl(to_number(attribute19),0),
6370                 nvl(to_number(attribute20),0),
6371                 nvl(to_number(attribute21),0),
6372                 nvl(to_number(attribute22),0),
6373                 nvl(to_number(attribute23),0),
6374                 nvl(to_number(attribute24),0),
6375                 nvl(to_number(attribute25),0),
6376                 nvl(to_number(attribute26),0),
6377                 nvl(to_number(attribute27),0),
6378                 nvl(to_number(attribute28),0),
6379                 nvl(to_number(attribute29),0)
6380            from psb_reentrant_process_status
6381           where process_type = 'HR DATA EXTRACT'
6382             and process_uid  = p_data_extract_id;
6383 
6384   l_api_name		CONSTANT VARCHAR2(30)	:= 'Check_Reentry';
6385   l_api_version         CONSTANT NUMBER 	:= 1.0;
6386 
6387   l_status              varchar2(1);
6388   l_sp1_status          varchar2(1);
6389   l_sp2_status          varchar2(1);
6390   l_sp3_status          varchar2(1);
6391   l_sp4_status          varchar2(1);
6392   l_sp5_status          varchar2(1) ;
6393   l_sp6_status          varchar2(1) ;
6394   l_sp7_status          varchar2(1) ;
6395   l_sp8_status          varchar2(1) ;
6396   l_sp9_status          varchar2(1) ;
6397   l_sp10_status         varchar2(1) ;
6398   l_sp11_status         varchar2(1) ;
6399   l_sp12_status         varchar2(1) ;
6400   l_sp13_status         varchar2(1) ;
6401   l_sp14_status         varchar2(1) ;
6402   l_sp15_status         varchar2(1) ;
6403   l_sp16_status         varchar2(1) ;
6404   l_sp17_status         varchar2(1) ;
6405   l_sp18_status         varchar2(1) ;
6406   l_sp19_status         varchar2(1) ;
6407   l_attribute1          varchar2(30) ;
6408   l_attribute2          varchar2(30) ;
6409   l_attribute3          number ;
6410   l_attribute11         number ;
6411   l_attribute12         number ;
6412   l_attribute13         number ;
6413   l_attribute14         number ;
6414   l_attribute15         number ;
6415   l_attribute16         number ;
6416   l_attribute17         number ;
6417   l_attribute18         number ;
6418   l_attribute19         number ;
6419   l_attribute20         number ;
6420   l_attribute21         number ;
6421   l_attribute22         number ;
6422   l_attribute23         number ;
6423   l_attribute24         number ;
6424   l_attribute25         number ;
6425   l_attribute26         number ;
6426   l_attribute27         number ;
6427   l_attribute28         number ;
6428   l_attribute29         number ;
6429   l_restart_id          number := 0;
6430 
6431   Begin
6432 
6433     -- Standard call to check for call compatibility.
6434 
6435     if not FND_API.Compatible_API_Call (l_api_version,
6436             	    	    	        p_api_version,
6437    	       	    	 	        l_api_name,
6438 		    	    	        G_PKG_NAME)
6439     then
6440        raise FND_API.G_EXC_UNEXPECTED_ERROR;
6441     end if;
6442 
6443     p_return_status := FND_API.G_RET_STS_SUCCESS;
6444 
6445     -- API body
6446 
6447     Open C_Reentrant;
6448 
6449     Fetch C_Reentrant into l_sp1_status,
6450                            l_sp2_status,
6451                            l_sp3_status,
6452                            l_sp4_status,
6453                            l_sp5_status,
6454                            l_sp6_status,
6455                            l_sp7_status,
6456                            l_sp8_status,
6457                            l_sp9_status,
6458                            l_sp10_status,
6459                            l_sp11_status,
6460                            l_sp12_status,
6461                            l_sp13_status,
6462                            l_sp14_status,
6463                            l_sp15_status,
6464                            l_sp16_status,
6465                            l_sp17_status,
6466                            l_sp18_status,
6467                            l_sp19_status,
6468                            l_attribute1,
6469                            l_attribute2,
6470                            l_attribute3,
6471                            l_attribute11,
6472                            l_attribute12,
6473                            l_attribute13,
6474                            l_attribute14,
6475                            l_attribute15,
6476                            l_attribute16,
6477                            l_attribute17,
6478                            l_attribute18,
6479                            l_attribute19,
6480                            l_attribute20,
6481                            l_attribute21,
6482                            l_attribute22,
6483                            l_attribute23,
6484                            l_attribute24,
6485                            l_attribute25,
6486                            l_attribute26,
6487                            l_attribute27,
6488                            l_attribute28,
6489                            l_attribute29;
6490 
6491 
6492 
6493 
6494     if (C_Reentrant%NOTFOUND) then
6495        l_status := 'I';
6496        l_restart_id := 0;
6497     else
6498     if (p_process = 'Positions Interface') then
6499         l_status  := l_sp1_status;
6500         l_restart_id := l_attribute11;
6501     elsif (p_process = 'Salary Interface') then
6502         l_status := l_sp2_status;
6503         l_restart_id := l_attribute12;
6504     elsif (p_process = 'Employees Interface') then
6505         l_status := l_sp3_status;
6506         l_restart_id := l_attribute13;
6507     elsif (p_process = 'Costing Interface') then
6508         l_status := l_sp4_status;
6509         l_restart_id := l_attribute14;
6510     elsif (p_process = 'Attribute Values Interface') then
6511         l_status := l_sp5_status;
6512         l_restart_id := l_attribute15;
6513     elsif (p_process = 'Position Assignments Interface') then
6514         l_status := l_sp6_status;
6515         l_restart_id := l_attribute16;
6516     elsif (p_process = 'Data Extract Summary') then
6517         l_status := l_sp7_status;
6518         l_restart_id := l_attribute17;
6519     elsif (p_process = 'Validate Data Extract') then
6520         l_status := l_sp8_status;
6521         l_restart_id := l_attribute18;
6522     elsif (p_process = 'Copy Attributes') then
6523         l_status := l_sp9_status;
6524         l_restart_id := l_attribute19;
6525     elsif (p_process = 'Copy Elements') then
6526         l_status := l_sp10_status;
6527         l_restart_id := l_attribute20;
6528     elsif (p_process = 'Copy Position Sets') then
6529         l_status := l_sp11_status;
6530         l_restart_id := l_attribute21;
6531     elsif (p_process = 'Copy Default Rules') then
6532         l_status := l_sp12_status;
6533         l_restart_id := l_attribute22;
6534     elsif (p_process = 'PSB Positions') then
6535         if (l_sp1_status <> 'C') then
6536            l_status := 'D';
6537         else
6538            l_status := l_sp13_status;
6539            l_restart_id := l_attribute23;
6540         end if;
6541     elsif (p_process = 'PSB Elements') then
6542         if (l_sp2_status <> 'C') then
6543            l_status := 'D';
6544         else
6545            l_status := l_sp14_status;
6546            l_restart_id := l_attribute24;
6547         end if;
6548     elsif (p_process = 'PSB Employees') then
6549        if ((l_sp3_status  <> 'C') or (l_sp13_status <> 'C')) then
6550            l_status := 'D';
6551        else
6552           l_status := l_sp15_status;
6553           l_restart_id := l_attribute25;
6554        end if;
6555     elsif (p_process = 'PSB Costing') then
6556        if ((l_sp4_status  <> 'C') or (l_sp13_status <> 'C')) then
6557           l_status := 'D';
6558        else
6559           l_status := l_sp16_status;
6560           l_restart_id := l_attribute26;
6561        end if;
6562     elsif (p_process = 'PSB Attribute Values') then
6563        if (l_sp5_status <> 'C') then
6564           l_status := 'D';
6565        else
6566           l_status := l_sp17_status;
6567           l_restart_id := l_attribute27;
6568        end if;
6569     elsif (p_process = 'PSB Position Assignments') then
6570        if ((l_sp6_status  <> 'C') or (l_sp13_status <> 'C')) then
6571           l_status := 'D';
6572        else
6573           l_status := l_sp18_status;
6574           l_restart_id := l_attribute28;
6575        end if;
6576     elsif (p_process = 'PSB Apply Defaults') then
6577           l_status := l_sp19_status;
6578           l_restart_id := l_attribute29;
6579     end if;
6580     end if;
6581 
6582     p_status := l_status;
6583     p_restart_id := l_restart_id;
6584     Close C_Reentrant;
6585 
6586 EXCEPTION
6587 
6588    when FND_API.G_EXC_ERROR then
6589      p_return_status := FND_API.G_RET_STS_ERROR;
6590 
6591    when FND_API.G_EXC_UNEXPECTED_ERROR then
6592      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6593 
6594    when OTHERS then
6595      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6596 
6597      if FND_MSG_PUB.Check_Msg_Level
6598        (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6599      then
6600        FND_MSG_PUB.Add_Exc_Msg
6601           (p_pkg_name => G_PKG_NAME,
6602            p_procedure_name => l_api_name);
6603     end if;
6604 End Check_Reentry;
6605 
6606 
6607 Procedure Update_Reentry
6608 ( p_api_version         IN   NUMBER,
6609   p_return_status       OUT  NOCOPY VARCHAR2,
6610   p_msg_count           OUT  NOCOPY NUMBER,
6611   p_msg_data            OUT  NOCOPY VARCHAR2,
6612   p_data_extract_id     IN   NUMBER,
6613   p_extract_method      IN   VARCHAR2,
6614   p_process             IN   VARCHAR2,
6615   p_restart_id          IN   NUMBER
6616 )
6617 IS
6618 
6619   Cursor C_Reenter_Upd is
6620          Select rowid
6621            from psb_reentrant_process_status
6622           where process_type = 'HR DATA EXTRACT'
6623             and process_uid  = p_data_extract_id;
6624 
6625   -- Commenting this condition as part of DE by Org, since
6626   -- both CREATE and REFRESH methods can be present in a
6627   -- single run of the DE.
6628 
6629 --            and attribute1   = p_extract_method;
6630 
6631   l_last_update_date    date;
6632   l_last_updated_by     number;
6633   l_last_update_login   number;
6634   l_creation_date       date;
6635   l_created_by          number;
6636   l_rowid               VARCHAR2(100);
6637 
6638   l_attribute11         number ;
6639   l_attribute12         number ;
6640   l_attribute13         number ;
6641   l_attribute14         number ;
6642   l_attribute15         number ;
6643   l_attribute16         number ;
6644   l_attribute17         number ;
6645   l_attribute18         number ;
6646   l_attribute19         number ;
6647   l_attribute20         number ;
6648   l_attribute21         number ;
6649   l_attribute22         number ;
6650   l_attribute23         number ;
6651   l_attribute24         number ;
6652   l_attribute25         number ;
6653   l_attribute26         number ;
6654   l_attribute27         number ;
6655   l_attribute28         number ;
6656   l_attribute29         number ;
6657 
6658   l_api_name		CONSTANT VARCHAR2(30)	:= 'Update_Reentry';
6659   l_api_version         CONSTANT NUMBER 	:= 1.0;
6660 
6661 BEGIN
6662 
6663     -- Standard call to check for call compatibility.
6664 
6665     if not FND_API.Compatible_API_Call (l_api_version,
6666             	    	    	        p_api_version,
6667    	       	    	 	        l_api_name,
6668 		    	    	        G_PKG_NAME)
6669     then
6670        raise FND_API.G_EXC_UNEXPECTED_ERROR;
6671     end if;
6672 
6673     p_return_status := FND_API.G_RET_STS_SUCCESS;
6674 
6675     l_last_update_date  := sysdate;
6676     l_last_updated_by   := FND_GLOBAL.USER_ID;
6677     l_last_update_login := FND_GLOBAL.LOGIN_ID;
6678     l_creation_date     := sysdate;
6679     l_created_by        := FND_GLOBAL.USER_ID;
6680 
6681     if (p_process = 'Positions Interface') then
6682         l_attribute11 := p_restart_id;
6683     elsif (p_process = 'Salary Interface') then
6684         l_attribute12 := p_restart_id;
6685     elsif (p_process = 'Employees Interface') then
6686         l_attribute13 := p_restart_id;
6687     elsif (p_process = 'Costing Interface') then
6688         l_attribute14 := p_restart_id;
6689     elsif (p_process = 'Attribute Values Interface') then
6690         l_attribute15 := p_restart_id;
6691     elsif (p_process = 'Position Assignments Interface') then
6692         l_attribute16 := p_restart_id;
6693     elsif (p_process = 'Data Extract Summary') then
6694         l_attribute17 := p_restart_id;
6695     elsif (p_process = 'Validate Data Extract') then
6696         l_attribute18 := p_restart_id;
6697     elsif (p_process = 'Copy Attributes') then
6698         l_attribute19 := p_restart_id;
6699     elsif (p_process = 'Copy Elements') then
6700         l_attribute20 := p_restart_id;
6701     elsif (p_process = 'Copy Position Sets') then
6702         l_attribute21 := p_restart_id;
6703     elsif (p_process = 'Copy Default Rules') then
6704         l_attribute22 := p_restart_id;
6705     elsif (p_process = 'PSB Positions') then
6706         l_attribute23 := p_restart_id;
6707     elsif (p_process = 'PSB Elements') then
6708         l_attribute24 := p_restart_id;
6709     elsif (p_process = 'PSB Employees') then
6710         l_attribute25 := p_restart_id;
6711     elsif (p_process = 'PSB Costing') then
6712         l_attribute26 := p_restart_id;
6713     elsif (p_process = 'PSB Attribute Values') then
6714         l_attribute27 := p_restart_id;
6715     elsif (p_process = 'PSB Position Assignments') then
6716         l_attribute28 := p_restart_id;
6717     elsif (p_process = 'PSB Apply Defaults') then
6718         l_attribute29 := p_restart_id;
6719     end if;
6720 
6721     Open C_Reenter_Upd;
6722 
6723     Fetch C_Reenter_Upd into l_rowid;
6724 
6725     if C_Reenter_Upd%NOTFOUND then
6726     Insert Into Psb_Reentrant_Process_Status
6727     (process_type,
6728      process_uid,
6729      attribute1,
6730      attribute11,
6731      attribute12,
6732      attribute13,
6733      attribute14,
6734      attribute15,
6735      attribute16,
6736      attribute17,
6737      attribute18,
6738      attribute19,
6739      attribute20,
6740      attribute21,
6741      attribute22,
6742      attribute23,
6743      attribute24,
6744      attribute25,
6745      attribute26,
6746      attribute27,
6747      attribute28,
6748      attribute29)
6749     values
6750     ('HR DATA EXTRACT',
6751      p_data_extract_id,
6752      p_extract_method,
6753      l_attribute11,
6754      l_attribute12,
6755      l_attribute13,
6756      l_attribute14,
6757      l_attribute15,
6758      l_attribute16,
6759      l_attribute17,
6760      l_attribute18,
6761      l_attribute19,
6762      l_attribute20,
6763      l_attribute21,
6764      l_attribute22,
6765      l_attribute23,
6766      l_attribute24,
6767      l_attribute25,
6768      l_attribute26,
6769      l_attribute27,
6770      l_attribute28,
6771      l_attribute29);
6772    else
6773     Update Psb_Reentrant_Process_Status
6774        set attribute11  = decode(p_process,'Positions Interface',l_attribute11,attribute11),
6775            attribute12  = decode(p_process,'Salary Interface',l_attribute12,attribute12),
6776            attribute13  = decode(p_process,'Employees Interface',l_attribute13,attribute13),
6777            attribute14  = decode(p_process,'Costing Interface',l_attribute14,attribute14),
6778            attribute15  = decode(p_process,'Attribute Values Interface',l_attribute15,attribute15),
6779            attribute16  = decode(p_process,'Position Assignments Interface',l_attribute16,attribute16),
6780            attribute17  = decode(p_process,'Data Extract Summary',l_attribute17,attribute17),
6781            attribute18  = decode(p_process,'Validate Data Extract',l_attribute18,attribute18),
6782            attribute19  = decode(p_process,'Copy Attributes',l_attribute19,attribute19),
6783            attribute20  = decode(p_process,'Copy Elements',l_attribute20,attribute20),
6784            attribute21  = decode(p_process,'Copy Position Sets',l_attribute21,attribute21),
6785            attribute22  = decode(p_process,'Copy Default Rules',l_attribute22,attribute22),
6786            attribute23 = decode(p_process,'PSB Positions',l_attribute23,attribute23),
6787            attribute24 = decode(p_process,'PSB Elements',l_attribute24,attribute24),
6788            attribute25 = decode(p_process,'PSB Employees',l_attribute25,attribute25),
6789            attribute26 = decode(p_process,'PSB Costing',l_attribute26,attribute26),
6790            attribute27 = decode(p_process,'PSB Attribute Values',l_attribute27,attribute27),
6791            attribute28 = decode(p_process,'PSB Position Assignments',l_attribute28,attribute28),
6792            attribute29 = decode(p_process,'PSB Apply Defaults',l_attribute29,attribute29)
6793     where  rowid  = l_rowid;
6794 
6795    end if;
6796    Close C_Reenter_Upd;
6797 
6798 EXCEPTION
6799 
6800    when FND_API.G_EXC_ERROR then
6801      if C_Reenter_Upd%isopen then
6802         Close C_Reenter_Upd;
6803      end if;
6804      p_return_status := FND_API.G_RET_STS_ERROR;
6805 
6806    when FND_API.G_EXC_UNEXPECTED_ERROR then
6807      if C_Reenter_Upd%isopen then
6808         Close C_Reenter_Upd;
6809      end if;
6810      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6811 
6812    when OTHERS then
6813      if C_Reenter_Upd%isopen then
6814         Close C_Reenter_Upd;
6815      end if;
6816      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6817 
6818      if FND_MSG_PUB.Check_Msg_Level
6819        (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6820      then
6821        FND_MSG_PUB.Add_Exc_Msg
6822           (p_pkg_name => G_PKG_NAME,
6823            p_procedure_name => l_api_name);
6824      end if;
6825 
6826 
6827 END Update_Reentry;
6828 
6829 PROCEDURE Reentrant_Process
6830 ( p_api_version         IN   NUMBER,
6831   p_return_status       OUT  NOCOPY VARCHAR2,
6832   p_msg_count           OUT  NOCOPY NUMBER,
6833   p_msg_data            OUT  NOCOPY VARCHAR2,
6834   p_data_extract_id     IN   NUMBER,
6835   p_extract_method      IN   VARCHAR2,
6836   p_process             IN   VARCHAR2
6837 ) AS
6838 
6839   Cursor C_Reentrant is
6840          Select nvl(sp1_status,'I'),
6841                 nvl(sp2_status,'I'),
6842                 nvl(sp3_status,'I'),
6843                 nvl(sp4_status,'I'),
6844                 nvl(sp5_status,'I'),
6845                 nvl(sp6_status,'I'),
6846                 nvl(sp7_status,'I'),
6847                 nvl(sp8_status,'I'),
6848                 nvl(sp9_status,'I'),
6849                 nvl(sp10_status,'I'),
6850                 nvl(sp11_status,'I'),
6851                 nvl(sp12_status,'I'),
6852                 nvl(sp13_status,'I'),
6853                 nvl(sp14_status,'I'),
6854                 nvl(sp15_status,'I'),
6855                 nvl(sp16_status,'I'),
6856                 nvl(sp17_status,'I'),
6857                 nvl(sp18_status,'I'),
6858                 nvl(sp19_status,'I'),
6859                 attribute1,
6860                 attribute2,
6861                 nvl(to_number(attribute3),0)
6862            from psb_reentrant_process_status
6863           where process_type = 'HR DATA EXTRACT'
6864             and process_uid  = p_data_extract_id;
6865 
6866    -- Commenting this condition as part of DE by Org, since
6867    -- both CREATE and REFRESH methods can be present in a
6868    -- single run of the DE
6869 --            and attribute1   = p_extract_method;
6870 
6871 
6872   l_api_name		CONSTANT VARCHAR2(30)	:= 'Reentrant_Process';
6873   l_api_version         CONSTANT NUMBER 	:= 1.0;
6874   l_sp1_status          varchar2(1) := 'I';
6875   l_sp2_status          varchar2(1) := 'I';
6876   l_sp3_status          varchar2(1) := 'I';
6877   l_sp4_status          varchar2(1) := 'I';
6878   l_sp5_status          varchar2(1) := 'I';
6879   l_sp6_status          varchar2(1) := 'I';
6880   l_sp7_status          varchar2(1) := 'I';
6881   l_sp8_status          varchar2(1) := 'I';
6882   l_sp9_status          varchar2(1) := 'I';
6883   l_sp10_status         varchar2(1) := 'I';
6884   l_sp11_status         varchar2(1) := 'I';
6885   l_sp12_status         varchar2(1) := 'I';
6886   l_sp13_status         varchar2(1) := 'I';
6887   l_sp14_status         varchar2(1) := 'I';
6888   l_sp15_status         varchar2(1) := 'I';
6889   l_sp16_status         varchar2(1) := 'I';
6890   l_sp17_status         varchar2(1) := 'I';
6891   l_sp18_status         varchar2(1) := 'I';
6892   l_sp19_status         varchar2(1) := 'I';
6893   l_attribute1          varchar2(30) ;
6894   l_attribute2          varchar2(30) ;
6895   l_attribute3          number := 0;
6896   l_last_update_date    date;
6897   l_last_updated_by     number;
6898   l_last_update_login   number;
6899   l_creation_date       date;
6900   l_created_by          number;
6901   l_refresh_num         number := 0;
6902 
6903   Begin
6904 
6905     -- Standard call to check for call compatibility.
6906 
6907     if not FND_API.Compatible_API_Call (l_api_version,
6908             	    	    	        p_api_version,
6909    	       	    	 	        l_api_name,
6910 		    	    	        G_PKG_NAME)
6911     then
6912        raise FND_API.G_EXC_UNEXPECTED_ERROR;
6913     end if;
6914 
6915 
6916     p_return_status := FND_API.G_RET_STS_SUCCESS;
6917 
6918     l_last_update_date  := sysdate;
6919     l_last_updated_by   := FND_GLOBAL.USER_ID;
6920     l_last_update_login := FND_GLOBAL.LOGIN_ID;
6921     l_creation_date     := sysdate;
6922     l_created_by        := FND_GLOBAL.USER_ID;
6923 
6924     -- API body
6925     if (p_process = 'Positions Interface') then
6926         l_sp1_status := 'C';
6927     elsif (p_process = 'Salary Interface') then
6928         l_sp2_status := 'C';
6929     elsif (p_process = 'Employees Interface') then
6930         l_sp3_status := 'C';
6931     elsif (p_process = 'Costing Interface') then
6932         l_sp4_status := 'C';
6933     elsif (p_process = 'Attribute Values Interface') then
6934         l_sp5_status := 'C';
6935     elsif (p_process = 'Position Assignments Interface') then
6936         l_sp6_status := 'C';
6937     elsif (p_process = 'Data Extract Summary') then
6938         l_sp7_status := 'C';
6939     elsif (p_process = 'Validate Data Extract') then
6940         l_sp8_status := 'C';
6941     elsif (p_process = 'Copy Attributes') then
6942         l_sp9_status  := 'C';
6943     elsif (p_process = 'Copy Elements') then
6944         l_sp9_status   := 'C';
6945         l_sp10_status  := 'C';
6946     elsif (p_process = 'Copy Position Sets') then
6947         l_sp11_status  := 'C';
6948     elsif (p_process = 'Copy Default Rules') then
6949         l_sp12_status  := 'C';
6950     elsif (p_process = 'PSB Positions') then
6951         l_sp13_status := 'C';
6952     elsif (p_process = 'PSB Elements') then
6953         l_sp14_status := 'C';
6954     elsif (p_process = 'PSB Employees') then
6955         l_sp15_status := 'C';
6956     elsif (p_process = 'PSB Costing') then
6957         l_sp16_status := 'C';
6958     elsif (p_process = 'PSB Attribute Values') then
6959         l_sp17_status := 'C';
6960     elsif (p_process = 'PSB Position Assignments') then
6961         l_sp18_status := 'C';
6962     elsif (p_process = 'PSB Apply Defaults') then
6963         l_sp19_status := 'C';
6964     end if;
6965 
6966     Open C_Reentrant;
6967 
6968     Fetch C_Reentrant into l_sp1_status,
6969                            l_sp2_status,
6970                            l_sp3_status,
6971                            l_sp4_status,
6972                            l_sp5_status,
6973                            l_sp6_status,
6974                            l_sp7_status,
6975                            l_sp8_status,
6976                            l_sp9_status,
6977                            l_sp10_status,
6978                            l_sp11_status,
6979                            l_sp12_status,
6980                            l_sp13_status,
6981                            l_sp14_status,
6982                            l_sp15_status,
6983                            l_sp16_status,
6984                            l_sp17_status,
6985                            l_sp18_status,
6986                            l_sp19_status,
6987                            l_attribute1,
6988                            l_attribute2,
6989                            l_attribute3;
6990 
6991     if (p_extract_method <> 'CREATE') then
6992        l_refresh_num := l_attribute3 + 1;
6993     end if;
6994 
6995     if C_Reentrant%NOTFOUND then
6996     Insert Into Psb_Reentrant_Process_Status
6997     (process_type,
6998      process_uid,
6999      sp1_status,
7000      sp2_status,
7001      sp3_status,
7002      sp4_status,
7003      sp5_status,
7004      sp6_status,
7005      sp7_status,
7006      sp8_status,
7007      sp9_status,
7008      sp10_status,
7009      sp11_status,
7010      sp12_status,
7011      sp13_status,
7012      sp14_status,
7013      sp15_status,
7014      sp16_status,
7015      sp17_status,
7016      sp18_status,
7017      sp19_status,
7018      attribute1 ,
7019      attribute2 ,
7020      attribute3
7021      )
7022      values
7023      ('HR DATA EXTRACT',
7024        p_data_extract_id,
7025        l_sp1_status,
7026        l_sp2_status,
7027        l_sp3_status,
7028        l_sp4_status,
7029        l_sp5_status,
7030        l_sp6_status,
7031        l_sp7_status,
7032        l_sp8_status,
7033        l_sp9_status,
7034        l_sp10_status,
7035        l_sp11_status,
7036        l_sp12_status,
7037        l_sp13_status,
7038        l_sp14_status,
7039        l_sp15_status,
7040        l_sp16_status,
7041        l_sp17_status,
7042        l_sp18_status,
7043        l_sp19_status,
7044        p_extract_method,
7045        l_last_update_date,
7046        to_char(l_refresh_num)
7047      );
7048    else
7049     Update Psb_Reentrant_Process_Status
7050        set sp1_status  = decode(p_process,'Positions Interface','C',sp1_status),
7051            sp2_status  = decode(p_process,'Salary Interface','C',sp2_status),
7052            sp3_status  = decode(p_process,'Employees Interface','C',sp3_status),
7053            sp4_status  = decode(p_process,'Costing Interface','C',sp4_status),
7054            sp5_status  = decode(p_process,'Attribute Values Interface','C',sp5_status),
7055            sp6_status  = decode(p_process,'Position Assignments Interface','C',sp6_status),
7056            sp7_status  = decode(p_process,'Data Extract Summary','C',sp7_status),
7057            sp8_status  = decode(p_process,'Validate Data Extract','C',sp8_status),
7058            sp9_status  = decode(p_process,'Copy Elements','C',sp9_status), -- Fix for Bug #4726455.
7059            sp10_status = decode(p_process,'Copy Elements','C',sp10_status),
7060            sp11_status = decode(p_process,'Copy Position Sets','C',sp11_status),
7061            sp12_status = decode(p_process,'Copy Default Rules','C',sp12_status),
7062            sp13_status = decode(p_process,'PSB Positions','C',sp13_status),
7063            sp14_status = decode(p_process,'PSB Elements','C',sp14_status),
7064            sp15_status = decode(p_process,'PSB Employees','C',sp15_status),
7065            sp16_status = decode(p_process,'PSB Costing','C',sp16_status),
7066            sp17_status = decode(p_process,'PSB Attribute Values','C',sp17_status),
7067            sp18_status = decode(p_process,'PSB Position Assignments','C',sp18_status),
7068            sp19_status = decode(p_process,'PSB Apply Defaults','C',sp19_status),
7069            attribute2  = l_last_update_date
7070     where  process_type  = 'HR DATA EXTRACT'
7071       and  process_uid   = p_data_extract_id;
7072    -- de by org
7073 --      and  attribute1    = p_extract_method;
7074   end if;
7075 
7076   Close C_Reentrant;
7077 
7078     -- End of API body.
7079 
7080 EXCEPTION
7081 
7082    when FND_API.G_EXC_ERROR then
7083      if C_Reentrant%isopen then
7084         Close C_Reentrant;
7085      end if;
7086 
7087      p_return_status := FND_API.G_RET_STS_ERROR;
7088 
7089    when FND_API.G_EXC_UNEXPECTED_ERROR then
7090      if C_Reentrant%isopen then
7091         Close C_Reentrant;
7092      end if;
7093 
7094      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7095 
7096    when OTHERS then
7097      if C_Reentrant%isopen then
7098         Close C_Reentrant;
7099      end if;
7100 
7101      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7102 
7103      if FND_MSG_PUB.Check_Msg_Level
7104        (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
7105      then
7106        FND_MSG_PUB.Add_Exc_Msg
7107           (p_pkg_name => G_PKG_NAME,
7108            p_procedure_name => l_api_name);
7109     end if;
7110 
7111 End Reentrant_Process;
7112 
7113 
7114 PROCEDURE Validate_Attribute_Mapping
7115   ( p_api_version           IN    NUMBER,
7116     p_init_msg_list         IN    VARCHAR2 := FND_API.G_FALSE,
7117     p_commit                IN    VARCHAR2 := FND_API.G_FALSE,
7118     p_validation_level      IN    NUMBER   := FND_API.G_VALID_LEVEL_FULL,
7119     p_return_status         OUT   NOCOPY VARCHAR2,
7120     p_msg_count             OUT   NOCOPY NUMBER,
7121     p_msg_data              OUT   NOCOPY VARCHAR2,
7122     p_business_group_id     IN    NUMBER,
7123     p_attribute_type_id     IN    NUMBER,
7124     p_definition_structure  IN    VARCHAR2 ,
7125     p_definition_table      IN    VARCHAR2 ,
7126     p_definition_column     IN    VARCHAR2
7127   )
7128   AS
7129   --
7130   l_api_name          CONSTANT VARCHAR2(30)   := 'Validate_Attribute_Mapping';
7131   l_api_version       CONSTANT NUMBER         := 1.0;
7132   --
7133   /*For Bug No : 2372434 Start*/
7134   --increased the size of d_sql_stmt,q_sql_stmt,o_sql_stmt
7135   --from 500 to 2000
7136   v_dcursorid    integer;
7137   d_sql_stmt     varchar2(2000);
7138   v_qcursorid    integer;
7139 
7140   q_sql_stmt     varchar2(2000);
7141   v_ocursorid    integer;
7142   o_sql_stmt     varchar2(2000);
7143   /*For Bug No : 2372434 End*/
7144   l_emp_col      varchar2(20);
7145   v_emp_val      number;
7146 
7147   l_application_id          number;
7148   l_application_table_name  varchar2(30);
7149   l_application_column_name varchar2(30);
7150   l_lookup_type             varchar2(30);
7151   l_attr_link_type          varchar2(30);
7152   l_status                  varchar2(1);
7153   l_return_status           varchar2(1);
7154   l_msg_count               number;
7155 
7156   l_msg_data     varchar2(1000);
7157   l_alias1       varchar2(10);
7158 
7159 
7160   Cursor C_Attribute_Types is
7161     Select name, select_table,attribute_type,
7162            substr(select_table,1,instr(select_table,' ',1)) select_tab,
7163            select_column,select_key,
7164            link_key,decode(link_type,'A','PER_ALL_ASSIGNMENTS','E',
7165            'PER_ALL_PEOPLE','P', 'HR_ALL_POSITIONS','PER_ALL_ASSIGNMENTS')
7166            link_type,link_type l_alias2,
7167            select_where
7168       From Psb_attribute_types
7169      where attribute_type_id = p_attribute_type_id;
7170 
7171   Cursor C_dff_tab is
7172      Select application_id,application_table_name,
7173             context_column_name
7174        from fnd_descriptive_flexs_vl
7175       where descriptive_flexfield_name = p_definition_structure;
7176 
7177   Cursor C_dff_col is
7178     Select fcol.application_column_name
7179       from fnd_descr_flex_contexts_vl fcon,fnd_descr_flex_column_usages fcol
7180      where fcon.application_id = fcol.application_id
7181        and fcon.descriptive_flexfield_name = p_definition_structure
7182        and fcon.descriptive_flex_context_code = p_definition_table
7183        and fcon.descriptive_flexfield_name = fcol.descriptive_flexfield_name
7184     and fcon.descriptive_flex_context_code = fcol.descriptive_flex_context_code
7185     and fcol.end_user_column_name = p_definition_column;
7186 
7187 BEGIN
7188 
7189   -- Standard Start of API savepoint
7190 
7191   Savepoint Validate_Attribute_Mapping;
7192 
7193   -- Standard call to check for call compatibility.
7194 
7195 
7196   if not FND_API.Compatible_API_Call (l_api_version,
7197      p_api_version,
7198      l_api_name,
7199      G_PKG_NAME)
7200   then
7201     raise FND_API.G_EXC_UNEXPECTED_ERROR;
7202   end if;
7203 
7204   -- Initialize message list if p_init_msg_list is set to TRUE.
7205 
7206   if FND_API.to_Boolean (p_init_msg_list) then
7207      FND_MSG_PUB.initialize;
7208   end if;
7209 
7210 
7211   p_return_status := FND_API.G_RET_STS_SUCCESS;
7212 
7213   -- API body
7214 
7215   For C_Attribute_Types_Rec in C_Attribute_Types
7216   Loop
7217     Begin
7218     Select ltrim(rtrim(substr(C_Attribute_Types_Rec.select_table,
7219            instr(C_Attribute_Types_Rec.select_table,' ',1),
7220            length(C_Attribute_Types_Rec.select_table)
7221                   - instr(C_Attribute_Types_Rec.select_table,' ',1) + 1)))
7222       into l_alias1
7223       from dual;
7224      end;
7225 
7226    if (C_Attribute_Types_Rec.link_type = 'PER_ALL_ASSIGNMENTS') then
7227        l_emp_col := 'assignment_id';
7228    elsif (C_Attribute_Types_Rec.link_type = 'PER_ALL_PEOPLE') then
7229        l_emp_col := 'person_id';
7230    elsif (C_Attribute_Types_Rec.link_type = 'HR_ALL_POSITIONS') then
7231        l_emp_col := 'position_id';
7232    end if;
7233 
7234    l_attr_link_type := C_Attribute_Types_Rec.link_type;
7235 
7236    if (C_Attribute_Types_Rec.attribute_type = 'DFF') then
7237 
7238       For C_dff_rec in C_dff_tab
7239       Loop
7240          l_application_id := C_dff_rec.application_id;
7241          l_application_table_name    := C_dff_rec.application_table_name;
7242 
7243         For C_dff_str_rec in C_dff_col
7244         Loop
7245           l_application_column_name := C_dff_str_rec.application_column_name;
7246         End Loop;
7247       End Loop;
7248 
7249      v_dcursorid := dbms_sql.open_cursor;
7250 
7251      d_sql_stmt := 'Select '||l_alias1||'.' ||l_application_column_name||
7252                    '  From '||C_Attribute_Types_Rec.select_tab||' '||
7253                    l_alias1||' , '||
7254                    C_Attribute_Types_Rec.link_type||' '||
7255                    C_Attribute_Types_Rec.l_alias2||
7256                    ' Where '||l_alias1||'.'||
7257                    C_Attribute_Types_Rec.select_key||' = '||
7258                    C_Attribute_Types_Rec.l_alias2||'.'||
7259                    C_Attribute_Types_Rec.link_key||
7260                    ' and '||C_Attribute_Types_Rec.l_alias2||'.'||l_emp_col||
7261                    ' = '||':v_emp_val';
7262 
7263      if (C_Attribute_Types_Rec.select_where is not null) then
7264         d_sql_stmt := d_sql_stmt||' and '||C_Attribute_Types_Rec.select_where;
7265      end if;
7266 
7267     dbms_sql.parse(v_dcursorid,d_sql_stmt,dbms_sql.v7);
7268 
7269     -- dff code
7270     elsif (C_Attribute_Types_Rec.attribute_type = 'TABLE') then
7271      v_ocursorid := dbms_sql.open_cursor;
7272      if (C_Attribute_Types_Rec.select_table = C_Attribute_Types_Rec.link_type) then
7273         o_sql_stmt := 'Select '||
7274               C_Attribute_Types_Rec.select_column||
7275               '  From '||C_Attribute_Types_Rec.select_tab||
7276               '  Where '||C_Attribute_Types_Rec.select_tab||'.'||
7277               l_emp_col|| ' = '||':v_emp_val';
7278      else
7279         o_sql_stmt := 'Select '||l_alias1||'.'||
7280            C_Attribute_Types_Rec.select_column||
7281            '  From '||C_Attribute_Types_Rec.select_tab||' '||l_alias1||
7282            ' , '||
7283            C_Attribute_Types_Rec.link_type||' '||
7284            C_Attribute_Types_Rec.l_alias2||
7285            ' Where '||l_alias1||'.'||
7286            C_Attribute_Types_Rec.select_key||' = '||
7287            C_Attribute_Types_Rec.l_alias2||'.'||
7288            C_Attribute_Types_Rec.link_key||
7289          ' and '||C_Attribute_Types_Rec.l_alias2||'.'||l_emp_col||
7290          ' = '||':v_emp_val';
7291      end if;
7292 
7293 
7294      if (C_Attribute_Types_Rec.select_where is not null) then
7295         o_sql_stmt := o_sql_stmt||' and '||C_Attribute_Types_Rec.select_where;
7296      end if;
7297 
7298     dbms_sql.parse(v_ocursorid,o_sql_stmt,dbms_sql.v7);
7299        -- table code
7300     elsif (C_Attribute_Types_Rec.attribute_type = 'QC') then
7301      v_qcursorid := dbms_sql.open_cursor;
7302      q_sql_stmt := 'Select a.meaning '||
7303         '  From Fnd_Common_lookups a , '||
7304          C_Attribute_Types_Rec.select_tab||' '||l_alias1||' ,'||
7305          C_Attribute_Types_Rec.link_type||' '||
7306          C_Attribute_Types_Rec.l_alias2||
7307          ' Where a.lookup_type = '||''''||
7308          l_lookup_type||''''||
7309          ' and a.lookup_code = '||
7310          l_alias1||'.'||C_Attribute_Types_Rec.select_column||
7311          ' and '||l_alias1||'.'||C_Attribute_Types_Rec.select_key||
7312          ' = '||C_Attribute_Types_Rec.l_alias2||'.'||
7313          C_Attribute_Types_Rec.link_key||
7314          ' and '||C_Attribute_Types_Rec.l_alias2||'.'||l_emp_col||
7315          ' = '||':v_emp_val';
7316 
7317 
7318      if (C_Attribute_Types_Rec.select_where is not null) then
7319         q_sql_stmt := q_sql_stmt||' and '||C_Attribute_Types_Rec.select_where;
7320      end if;
7321 
7322     dbms_sql.parse(v_qcursorid,q_sql_stmt,dbms_sql.v7);
7323        -- qc code
7324     end if;
7325   End Loop;
7326   -- End of API body.
7327 
7328 EXCEPTION
7329 
7330    when FND_API.G_EXC_ERROR then
7331 
7332      rollback to Validate_Attribute_Mapping;
7333      p_return_status := FND_API.G_RET_STS_ERROR;
7334      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
7335                                 p_data  => p_msg_data);
7336      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
7337                                 p_data  => p_msg_data);
7338 
7339    when FND_API.G_EXC_UNEXPECTED_ERROR then
7340      rollback to Validate_Attribute_Mapping;
7341      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7342      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
7343                                 p_data  => p_msg_data);
7344 
7345   WHEN OTHERS THEN
7346     --
7347     ROLLBACK TO Validate_Attribute_Mapping ;
7348     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7349     --
7350     IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
7351       FND_MSG_PUB.Add_Exc_Msg ( G_PKG_NAME,
7352                                l_api_name);
7353     END if;
7354     --
7355 
7356     --
7357     FND_MSG_PUB.Count_And_Get ( p_count => p_msg_count,
7358                                 p_data  => p_msg_data );
7359     --
7360 
7361 END Validate_Attribute_Mapping;
7362 
7363 PROCEDURE Final_Process is
7364 Begin
7365 
7366   Delete fnd_sessions
7367   where session_id = (select USERENV('sessionid') from dual);
7368 
7369 End Final_Process;
7370 
7371 /* ----------------------------------------------------------------------- */
7372 
7373 FUNCTION get_segment_val(pseg_num in varchar2,
7374                 pcost_allocation_keyflex_id in number)
7375                 RETURN VARCHAR2  is
7376 s_col varchar2(30);
7377 
7378 Cursor C_segment_val is
7379   Select segment1,  segment2,  segment3,
7380          segment4,  segment5,  segment6,
7381          segment7,  segment8,  segment9,
7382          segment10, segment11, segment12,
7383          segment13, segment14, segment15,
7384          segment16, segment17, segment18,
7385          segment19, segment20, segment21,
7386          segment22, segment23, segment24,
7387          segment25, segment26, segment27,
7388          segment28, segment29, segment30
7389     from pay_cost_allocation_keyflex
7390    where cost_allocation_keyflex_id = pcost_allocation_keyflex_id;
7391 
7392 begin
7393 
7394   for C_segment_rec in C_segment_val
7395   Loop
7396        if (pseg_num = 'SEGMENT1') then
7397            s_col := C_segment_rec.segment1;
7398        elsif (pseg_num = 'SEGMENT2') then
7399            s_col := C_Segment_rec.segment2;
7400        elsif (pseg_num = 'SEGMENT3') then
7401            s_col := C_Segment_rec.segment3;
7402        elsif (pseg_num = 'SEGMENT4') then
7403            s_col := C_Segment_rec.segment4;
7404        elsif (pseg_num = 'SEGMENT5') then
7405            s_col := C_Segment_rec.segment5;
7406        elsif (pseg_num = 'SEGMENT6') then
7407            s_col := C_Segment_rec.segment6;
7408        elsif (pseg_num = 'SEGMENT7') then
7409            s_col := C_Segment_rec.segment7;
7410        elsif (pseg_num = 'SEGMENT8') then
7411            s_col := C_Segment_rec.segment8;
7412        elsif (pseg_num = 'SEGMENT9') then
7413            s_col := C_Segment_rec.segment9;
7414        elsif (pseg_num = 'SEGMENT10') then
7415            s_col := C_Segment_rec.segment10;
7416        elsif (pseg_num = 'SEGMENT11') then
7417            s_col := C_Segment_rec.segment11;
7418        elsif (pseg_num = 'SEGMENT12') then
7419            s_col := C_Segment_rec.segment12;
7420        elsif (pseg_num = 'SEGMENT13') then
7421            s_col := C_Segment_rec.segment13;
7422        elsif (pseg_num = 'SEGMENT14') then
7423            s_col := C_Segment_rec.segment14;
7424        elsif (pseg_num = 'SEGMENT15') then
7425            s_col := C_Segment_rec.segment15;
7426        elsif (pseg_num = 'SEGMENT16') then
7427            s_col := C_Segment_rec.segment16;
7428        elsif (pseg_num = 'SEGMENT17') then
7429            s_col := C_Segment_rec.segment17;
7430        elsif (pseg_num = 'SEGMENT18') then
7431            s_col := C_Segment_rec.segment18;
7432        elsif (pseg_num = 'SEGMENT19') then
7433            s_col := C_Segment_rec.segment19;
7434        elsif (pseg_num = 'SEGMENT20') then
7435            s_col := C_Segment_rec.segment20;
7436        elsif (pseg_num = 'SEGMENT21') then
7437            s_col := C_Segment_rec.segment21;
7438        elsif (pseg_num = 'SEGMENT22') then
7439            s_col := C_Segment_rec.segment22;
7440        elsif (pseg_num = 'SEGMENT23') then
7441            s_col := C_Segment_rec.segment23;
7442        elsif (pseg_num = 'SEGMENT24') then
7443            s_col := C_Segment_rec.segment24;
7444        elsif (pseg_num = 'SEGMENT25') then
7445            s_col := C_Segment_rec.segment25;
7446        elsif (pseg_num = 'SEGMENT26') then
7447            s_col := C_Segment_rec.segment26;
7448        elsif (pseg_num = 'SEGMENT27') then
7449            s_col := C_Segment_rec.segment27;
7450        elsif (pseg_num = 'SEGMENT28') then
7451            s_col := C_Segment_rec.segment28;
7452        elsif (pseg_num = 'SEGMENT29') then
7453            s_col := C_Segment_rec.segment29;
7454        elsif (pseg_num = 'SEGMENT30') then
7455            s_col := C_Segment_rec.segment30;
7456        end if;
7457   End Loop;
7458 
7459   RETURN s_col;
7460 
7461 End get_segment_val;
7462 
7463 /* ----------------------------------------------------------------------- */
7464 
7465 FUNCTION Is_LD_Enabled
7466 ( p_business_group_id IN NUMBER
7467 ) RETURN BOOLEAN
7468 IS
7469   l_plsql_block        VARCHAR2(100);
7470   l_ld_enabled         VARCHAR2(1);
7471 
7472 BEGIN
7473 
7474   --Dynamic sql statement to find whether CBC is enabled
7475 
7476   l_plsql_block := 'BEGIN :ld_enabled := PSP_GENERAL.IS_LD_Enabled(:business_group_id); END;';
7477 
7478   EXECUTE IMMEDIATE l_plsql_block USING OUT l_ld_enabled, IN p_business_group_id;
7479 
7480   if FND_API.to_Boolean(l_ld_enabled) then
7481     return TRUE;
7482   else
7483     return FALSE;
7484   end if;
7485 
7486   EXCEPTION
7487   WHEN OTHERS THEN
7488     Add_Message('PSB', 'PSB_LD_ENABLED_STATUS');
7489     RETURN FALSE;
7490 
7491 END Is_LD_Enabled;
7492 
7493 /* ----------------------------------------------------------------------- */
7494   -- Get Debug Information
7495 
7496   -- This Module is used to retrieve Debug Information for this routine. It
7497   -- prints Debug Information when run as a Batch Process from SQL*Plus. For
7498   -- the Debug Information to be printed on the Screen, the SQL*Plus parameter
7499   -- 'Serveroutput' should be set to 'ON'
7500 
7501   FUNCTION get_debug RETURN VARCHAR2 AS
7502 
7503   BEGIN
7504 
7505     return(g_dbug);
7506 
7507   END get_debug;
7508 
7509 /* ----------------------------------------------------------------------- */
7510 -- Add Token and Value to the Message Token array
7511 
7512 PROCEDURE message_token(tokname IN VARCHAR2,
7513                         tokval  IN VARCHAR2) AS
7514 
7515 BEGIN
7516 
7517   if no_msg_tokens is null then
7518     no_msg_tokens := 1;
7519   else
7520     no_msg_tokens := no_msg_tokens + 1;
7521   end if;
7522 
7523   msg_tok_names(no_msg_tokens) := tokname;
7524   msg_tok_val(no_msg_tokens) := tokval;
7525 
7526 END message_token;
7527 
7528 /* ----------------------------------------------------------------------- */
7529 
7530 -- Define a Message Token with a Value and set the Message Name
7531 
7532 -- Calls FND_MESSAGE server package to set the Message Stack. This message is
7533 -- retrieved by the calling program.
7534 
7535 PROCEDURE add_message(appname IN VARCHAR2,
7536                       msgname IN VARCHAR2) AS
7537 
7538   i  BINARY_INTEGER;
7539 
7540 BEGIN
7541 
7542   if ((appname is not null) and
7543       (msgname is not null)) then
7544 
7545     FND_MESSAGE.SET_NAME(appname, msgname);
7546 
7547     if no_msg_tokens is not null then
7548 
7549       for i in 1..no_msg_tokens loop
7550         FND_MESSAGE.SET_TOKEN(msg_tok_names(i), msg_tok_val(i));
7551       end loop;
7552 
7553     end if;
7554 
7555     FND_MSG_PUB.Add;
7556 
7557   end if;
7558 
7559   -- Clear Message Token stack
7560 
7561   no_msg_tokens := 0;
7562 
7563 END add_message;
7564 
7565 /* ----------------------------------------------------------------------- */
7566 
7567 END PSB_HR_EXTRACT_DATA_PVT;