DBA Data[Home] [Help]

PACKAGE BODY: APPS.PSB_HR_POPULATE_DATA_PVT

Source


1 PACKAGE BODY PSB_HR_POPULATE_DATA_PVT AS
2 /* $Header: PSBVHRPB.pls 120.43 2006/01/09 06:06:08 maniskum ship $ */
3 
4   G_PKG_NAME CONSTANT VARCHAR2(30):= 'PSB_HR_POPULATE_DATA_PVT';
5   g_dbug      VARCHAR2(15000);
6 
7   TYPE g_glcostmap_rec_type IS RECORD
8 	(gl_account_segment      VARCHAR2(30),
9 	payroll_cost_segment    VARCHAR2(30));
10 
11   TYPE g_glcostmap_tbl_type IS TABLE OF g_glcostmap_rec_type
12   INDEX BY BINARY_INTEGER;
13 
14  -- de by org
15  TYPE g_org_status_tbl_type IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
16 
17  g_org_status g_org_status_tbl_type;
18 
19   PROCEDURE Create_Salary_Distributions
20   (p_return_status       OUT  NOCOPY  VARCHAR2,
21    p_data_extract_id     IN   NUMBER,
22    p_extract_method      IN   VARCHAR2,
23    p_restart_position_id IN   NUMBER,
24    -- de by org
25    p_extract_by_org      IN   VARCHAR2
26   );
27 
28   PROCEDURE Create_Salary_Dist_Pos
29   ( p_return_status        OUT  NOCOPY  VARCHAR2,
30     p_data_extract_id      IN   NUMBER,
31     p_position_id          IN   NUMBER,
32     p_position_start_DATE  IN   DATE,
33     p_position_END_DATE    IN   DATE
34   );
35 
36   FUNCTION check_vacancy(p_position_id in NUMBER,
37 			 p_data_extract_id in NUMBER)
38   RETURN VARCHAR2;
39 
40 
41  PROCEDURE Populate_Salary_Assignments
42  ( p_return_status       OUT  NOCOPY VARCHAR2,
43    p_position_id         in  NUMBER,
44    p_date_effective      in  DATE,
45    p_date_end            in  DATE,
46    p_data_extract_id     in  NUMBER,
47    p_business_group_id   in  NUMBER,
48    p_set_of_books_id     in  NUMBER,
49    p_entry_grade_rule_id in  NUMBER,
50    p_entry_step_id       in  NUMBER := FND_API.G_MISS_NUM,
51    p_entry_grade_id      in  NUMBER,
52    p_pay_basis_id        in  NUMBER);
53 
54  PROCEDURE Update_Worksheet_Values
55  ( p_return_status            OUT  NOCOPY  VARCHAR2,
56    p_position_id               in  NUMBER ,
57    p_org_id                    in  NUMBER);
58 
59  -- de by org
60  PROCEDURE Cache_Org_Status
61  ( p_return_status          OUT NOCOPY VARCHAR2,
62    p_data_extract_id        IN         NUMBER,
63    p_extract_by_org         IN         VARCHAR2);
64 /*---------------------------------------------------------------------------*/
65 
66 
67 /*===========================================================================+
68  |                             PROCEDURE pd                                  |
69  +===========================================================================*/
70 -- API to print debug information used during only development.
71 PROCEDURE pd( p_message   IN     VARCHAR2)
72 IS
73 BEGIN
74   NULL ;
75   --DBMS_OUTPUT.Put_Line(p_message) ;
76 END pd ;
77 /*---------------------------------------------------------------------------*/
78 
79 
80 /*===========================================================================+
81  |                          PROCEDURE Process_Exception                      |
82  +===========================================================================*/
83 -- Bug#3109841: Added to return error message as per HR forms requirements.
84 PROCEDURE Process_Exception ( p_api_name   IN     VARCHAR2)
85 IS
86   l_msg_count              NUMBER ;
87   l_msg_data               VARCHAR2(1000) ;
88 BEGIN
89   --
90   IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
91     FND_MSG_PUB.Add_Exc_Msg ( G_PKG_NAME ,
92                               p_api_name ) ;
93   END IF;
94   --
95   FND_MSG_PUB.Get( p_msg_index     => 1               ,
96                    p_encoded       => FND_API.G_FALSE ,
97                    p_data          => l_msg_data      ,
98                    p_msg_index_out => l_msg_count
99                  ) ;
100   --
101   FND_MESSAGE.SET_NAME ('PSB',    'PSB_DEBUG_MESSAGE') ;
102   FND_MESSAGE.SET_TOKEN('MESSAGE', l_msg_data ) ;
103   FND_MESSAGE.RAISE_ERROR;
104   --
105 END Process_Exception ;
106 /*---------------------------------------------------------------------------*/
107 
108 
109 /*---------------------------------------------------------------------------*/
110 -- de by org
111 --
112 -- This Procedure caches the status of all the organizations selected for a
113 -- data extract run when extract by org flag is enabled. If extract by org
114 -- is not enabled it caches the statuses of all organizations pertaining to the
115 -- Business Group
116 --
117 PROCEDURE Cache_Org_Status
118 ( p_return_status           OUT NOCOPY    VARCHAR2,
119   p_data_extract_id         IN  NUMBER,
120   p_extract_by_org          IN  VARCHAR2)
121 AS
122 
123  Cursor C_org_status is
124   SELECT organization_id,
125          decode(completion_status,'C','REFRESH','CREATE') extract_method
126     FROM psb_data_extract_orgs
127    WHERE data_extract_id = p_data_extract_id
128      AND (p_extract_by_org = 'N'
129       OR (p_extract_by_org = 'Y' AND select_flag = 'Y'));
130 
131  TYPE l_org_status_tbl_type IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
132  l_org_status l_org_status_tbl_type;
133 
134 
135  TYPE l_organization_id_tbl_type IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
136  l_organization_id l_organization_id_tbl_type;
137 
138  i BINARY_INTEGER;
139 
140 BEGIN
141 
142 -- Initialize API return status to success
143   p_return_status := FND_API.G_RET_STS_SUCCESS;
144 
145    Open C_org_Status;
146    Fetch C_org_Status BULK collect into
147    l_organization_id,l_org_status;
148    Close C_org_status;
149 
150    FOR i in l_organization_id.first..l_organization_id.last LOOP
151      g_org_status(l_organization_id(i)) := l_org_status(i);
152    END LOOP;
153 
154 EXCEPTION
155 
156 WHEN OTHERS THEN
157   p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
158 
159 END cache_org_status;
160 
161 PROCEDURE set_global(g_var_name IN VARCHAR2,
162 		     g_var_value IN VARCHAR2)
163 AS
164 Begin
165   if (g_var_name = 'G_PSB_BUDGET_GROUP_ID') then
166      g_psb_budget_group_id := to_number(g_var_value);
167   elsif (g_var_name = 'G_PSB_WORKSHEET_ID') then
168      g_psb_worksheet_id := to_number(g_var_value);
169   elsif (g_var_name = 'G_PSB_DATA_EXTRACT_ID') then
170      g_psb_data_extract_id := to_number(g_var_value);
171   elsif (g_var_name = 'G_PSB_BUSINESS_GROUP_ID') then
172      g_psb_business_group_id := to_number(g_var_value);
173   elsif (g_var_name = 'G_PSB_CURRENT_FORM') then
174      g_psb_current_form := g_var_value;
175   elsif (g_var_name = 'G_PSB_APPLICATION_ID') then
176      g_psb_application_id := to_number(g_var_value);
177   elsif (g_var_name = 'G_PSB_ORG_ID') then
178      g_psb_org_id := to_number(g_var_value);
179   elsif (g_var_name = 'G_PSB_REVISION_START_DATE') then
180      g_psb_revision_start_date := fnd_date.chardate_to_date(g_var_value) ;
181   elsif (g_var_name = 'G_PSB_REVISION_END_DATE') then
182      g_psb_revision_end_date := fnd_date.chardate_to_date(g_var_value) ;
183   end if;
184 END set_global;
185 
186 Function get_global(g_var_name IN VARCHAR2) return varchar2
187 AS
188 Begin
189   if (g_var_name = 'G_PSB_BUDGET_GROUP_ID') then
190      return to_char(g_psb_budget_group_id) ;
191   elsif (g_var_name = 'G_PSB_WORKSHEET_ID') then
192      return to_char(g_psb_worksheet_id) ;
193   elsif (g_var_name = 'G_PSB_DATA_EXTRACT_ID') then
194      return to_char(g_psb_data_extract_id);
195   elsif (g_var_name = 'G_PSB_BUSINESS_GROUP_ID') then
196      return to_char(g_psb_business_group_id) ;
197   elsif (g_var_name = 'G_PSB_CURRENT_FORM') then
198      return g_psb_current_form ;
199   elsif (g_var_name = 'G_PSB_APPLICATION_ID') then
200      return g_psb_application_id ;
201   elsif (g_var_name = 'G_PSB_ORG_ID') then
202      return g_psb_org_id ;
203   elsif (g_var_name = 'G_PSB_REVISION_START_DATE') then
204      return g_psb_revision_start_date ;
205   elsif (g_var_name = 'G_PSB_REVISION_END_DATE') then
206      return g_psb_revision_end_date ;
207   end if;
208 
209 END get_global;
210 
211 PROCEDURE Populate_Salary_Assignments
212 ( p_return_status       OUT  NOCOPY VARCHAR2,
213   p_position_id         in  NUMBER,
214   p_date_effective      in  DATE,
215   p_date_end            in  DATE,
216   p_data_extract_id     in  NUMBER,
217   p_business_group_id   in  NUMBER,
218   p_set_of_books_id     in  NUMBER,
219   p_entry_grade_rule_id in  NUMBER,
220   p_entry_step_id       in  NUMBER := FND_API.G_MISS_NUM,
221   p_entry_grade_id      in  NUMBER,
222   p_pay_basis_id        in  NUMBER)
223 IS
224    --
225    -- Variables for retrieving salary details of a position
226    --
227   l_rowid               VARCHAR2(100);
228   l_grade_rule_id       number;
229   l_grade_id_flex_num   number;
230   l_step_id             number;
231   l_salary_type         varchar2(15);
232   l_rate_type           varchar2(10);
233   l_rate_or_payscale_id number;
234   l_grade_step          number;
235   l_grade_spine_id      number;
236   l_pay_basis_id        number;
237   l_pay_basis           varchar2(30);
238   l_sequence            number;
239   l_value               number;
240   l_session_date        date;
241   l_grade_or_spinal_point_id number;
242   l_rate_or_payscale_name varchar2(30);
243   l_grade_id            number;
244   l_grade_name          varchar2(80);
245 
246   l_position_assignment_id number := 0;
247   l_pay_element_id         number;
248   l_pay_element_option_id  number;
249   l_pay_element_rate_id    number;
250   l_currency_code          varchar2(30) := '';
251   l_return_status          varchar2(1);
252   l_msg_count              number;
253   l_msg_data               varchar2(1000);
254   l_msg                    varchar2(2000);
255   -- dynamic sql
256  /* l_sql_stmt                varchar2(500);
257   TYPE C_gradeCurTyp IS REF CURSOR;
258   c_grade_cv    C_gradeCurTyp; */
259 
260 
261   Cursor C_session is
262     SELECT effective_date
263       FROM FND_SESSIONS
264      WHERE session_id = USERENV('sessionid');
265 
266   Cursor C_grade_spine is
267      SELECT grade_spine_id
268 	  FROM per_spinal_point_steps
269 	 WHERE step_id = p_entry_step_id;
270 
271   Cursor C_Pay_Grade is
272     SELECT effective_start_date,
273 	   effective_end_date,
274 	   rate_id,
275 	   grade_or_spinal_point_id,
276 	   rate_type,
277 	   maximum,
278 	   mid_value,
279 	   minimum,
280 	   sequence,
281 	   value
282       FROM PAY_GRADE_RULES
283      WHERE business_group_id = p_business_group_id
284        AND grade_rule_id     = p_entry_grade_rule_id;
285 
286   Cursor  C_payscale is
287     SELECT parent_spine_id
288       FROM PER_SPINAL_POINTS
289      WHERE spinal_point_id = l_grade_or_spinal_point_id
290        AND business_group_id = p_business_group_id;
291 
292   Cursor C_pay_basis is
293     SELECT pay_basis
294       FROM PER_PAY_BASES
295      WHERE pay_basis_id = p_pay_basis_id;
296 
297   Cursor  C_payname is
298      SELECT name
299        FROM PER_PARENT_SPINES
300       WHERE parent_spine_id = l_rate_or_payscale_id
301 	AND business_group_id = p_business_group_id;
302 
303   Cursor C_rate is
304       SELECT name
305 	FROM PAY_RATES
306        WHERE rate_id = l_rate_or_payscale_id;
307 
308   Cursor C_flex_num is
309 	select grade_structure
310 	  from per_business_groups
311 	 where business_group_id = p_business_group_id;
312 
313   Cursor C_Currency is
314      Select currency_code
315        from gl_sets_of_books
316       where set_of_books_id = p_set_of_books_id;
317 
318   Cursor C_grade is
319      SELECT grade_id,name
320        FROM PER_GRADES
321       WHERE grade_id = p_entry_grade_id
322 	AND business_group_id = p_business_group_id;
323 
324   Cursor C_pay_elements_step IS
325      Select ppe.pay_element_id ,ppe.salary_type,
326 	    ppo.pay_element_option_id
327        FROM psb_pay_elements ppe,
328 	    psb_pay_element_options ppo
329       WHERE ppe.data_extract_id = p_data_extract_id
330 	AND ppe.salary_type     = 'STEP'
331 	AND ppe.name            = l_rate_or_payscale_name
332 	AND ppe.pay_element_id  = ppo.pay_element_id
333 	AND ppo.name            = l_grade_name
334 	AND ppo.grade_step      = l_grade_step
335 	AND ppo.sequence_number = l_sequence;
336 
337   Cursor C_pay_elements_rate IS
338      Select ppe.pay_element_id ,ppe.salary_type,
339 	    ppo.pay_element_option_id
340        FROM psb_pay_elements ppe,
341 	    psb_pay_element_options ppo
342       WHERE ppe.data_extract_id = p_data_extract_id
343 	AND ppe.salary_type     = 'RATE'
344 	AND ppe.name            = l_rate_or_payscale_name
345 	AND ppe.pay_element_id  = ppo.pay_element_id
346 	AND ppo.name            = l_grade_name;
347 
348   Cursor C_pay_element_rates IS
349      Select pay_element_rate_id,
350 	    effective_start_DATE,
351 	    effective_END_DATE,
352 	    element_value,
353 	    currency_code
354        FROM psb_pay_element_rates
355       WHERE pay_element_id        = l_pay_element_id
356 	AND pay_element_option_id = l_pay_element_option_id;
357 
358   l_last_update_date    DATE;
359   l_last_updated_BY     number;
360   l_last_update_login   number;
361   l_creation_date       DATE;
362   l_created_by          number;
363 
364 BEGIN
365   /* Bug 4222417 Start */
366   l_last_update_date  := SYSDATE;
367   l_last_updated_BY   := FND_GLOBAL.USER_ID;
368   l_last_update_login := FND_GLOBAL.LOGIN_ID;
369   l_creation_date     := SYSDATE;
370   l_created_by        := FND_GLOBAL.USER_ID;
371   /* Bug 4222417 End */
372 
373    --hr_utility.trace_on;
374    hr_utility.set_location(' Inside Salary Assignment',333);
375 
376    For C_flex_rec in C_flex_num
377    Loop
378      l_grade_id_flex_num := C_flex_rec.grade_structure;
379    End Loop;
380 
381    hr_utility.set_location(' date_effective XX '||p_date_effective,333);
382    hr_utility.set_location(' date_end XX '||p_date_end,333);
383    hr_utility.set_location(' dtxid XX '||p_data_extract_id,333);
384    hr_utility.set_location(' bSid XX '||p_business_group_id,333);
385    hr_utility.set_location(' sob XX '||p_set_of_books_id,333);
386    hr_utility.set_location(' entry grade rule XX '||p_entry_grade_rule_id,333);
387    hr_utility.set_location(' step XX '||p_entry_step_id,333);
388    hr_utility.set_location(' grade id XX '||p_entry_grade_id,333);
389    hr_utility.set_location(' pay basis XX '||p_pay_basis_id,333);
390    hr_utility.set_location(' -----------------------------',333);
391 
392    For C_Pay_Grade_Rec in C_Pay_Grade
393    Loop
394 
395      l_rate_type := C_Pay_Grade_Rec.rate_type;
396      For C_Grade_Rec in C_Grade
397      Loop
398        l_grade_id   := C_Grade_Rec.grade_id;
399        l_grade_name := C_Grade_Rec.name;
400      End Loop;
401 
402     --+ grade name using dynamic sql
403    /* l_sql_stmt :=
404 	 'SELECT pg.grade_id,pgv.concatenated_segments '||
405 	 '  FROM PER_GRADES pg,PER_GRADE_DEFINITIONS_KFV pgv ' ||
406 	 ' WHERE pg.grade_id =  ' || p_entry_grade_id ||
407 	 '   AND pg.business_group_id = ' || p_business_group_id ||
408 	 '   AND pg.grade_definition_id = pgv.grade_definition_id ' ||
409 	 '   AND pgv.id_flex_num        = ' || l_grade_id_flex_num   ;
410      OPEN c_grade_cv FOR l_sql_stmt;
411      LOOP
412        FETCH c_grade_cv into l_grade_id,l_grade_name ;
413        EXIT WHEN c_grade_cv%NOTFOUND;
414      END LOOP;
415      CLOSE c_grade_cv;  */
416 
417      hr_utility.set_location(' cursor grade name '||l_grade_name,335);
418 
419      For C_pay_basis_rec in C_pay_basis
420      Loop
421        l_pay_basis := C_pay_basis_rec.pay_basis;
422      End Loop;
423 
424      hr_utility.set_location(' pay basis '||l_pay_basis ||
425 			     ' ratetype ' || l_rate_type,336);
426 
427      if (l_rate_type = 'G') then
428 	l_rate_or_payscale_id := C_Pay_Grade_Rec.rate_id;
429 	l_value     := fnd_number.canonical_to_number(C_Pay_Grade_Rec.value);
430 	l_salary_type         := 'RATE';
431 
432 	hr_utility.set_location(' payscale '||l_rate_or_payscale_id,335);
433 	For C_Rate_Rec in C_Rate
434 	Loop
435 	  l_rate_or_payscale_name := C_Rate_Rec.name;
436 	  hr_utility.set_location(' Inside ZZ2 '||l_rate_or_payscale_id,335);
437 	End Loop;
438 
439 	FOR C_pay_elements_rate_rec in C_pay_elements_rate
440 	LOOP
441 	 l_pay_element_id        := C_pay_elements_rate_rec.pay_element_id;
442 	 l_salary_type           := C_pay_elements_rate_rec.salary_type;
443 	 l_pay_element_option_id := C_pay_elements_rate_rec.pay_element_option_id;
444 	END LOOP;
445 
446      else
447 	l_grade_or_spinal_point_id := C_Pay_Grade_Rec.grade_or_spinal_point_id;
448 	l_sequence := C_Pay_Grade_Rec.sequence;
449 	l_value := fnd_number.canonical_to_number( C_Pay_Grade_Rec.value);
450 	l_salary_type := 'STEP';
451 
452 	For C_grade_spine_rec in C_grade_spine
453 	Loop
454 	  l_grade_spine_id := C_grade_spine_rec.grade_spine_id;
455 	End Loop;
456 
457 	For C_session_rec in C_session
458 	Loop
459 	  l_session_date := C_session_rec.effective_date;
460 	end Loop;
461 
462 	hr_utility.set_location('  ZZ9 session date '||l_session_date ,336);
463 	per_spinal_point_steps_pkg.pop_flds(l_grade_step,
464 					    l_session_date,
465 					    l_grade_or_spinal_point_id,
466 					    l_grade_spine_id);
467 
468 	hr_utility.set_location('  after pop_flds ' ,336);
469 	For C_Payscale_rec in C_Payscale
470 	Loop
471 	  l_rate_or_payscale_id := C_Payscale_rec.parent_spine_id;
472 	End Loop;
473 
474 	FOR C_Payname_Rec in C_Payname
475 	LOOP
476 	  l_rate_or_payscale_name := C_Payname_Rec.name;
477 	END LOOP;
478 
479 	FOR C_pay_elements_step_rec in C_pay_elements_step
480 	LOOP
481 	  l_pay_element_id        := C_pay_elements_step_rec.pay_element_id;
482 	  l_pay_element_option_id :=
483 			      C_pay_elements_step_rec.pay_element_option_id;
484 	END LOOP;
485 
486      end if;
487 
488    if (l_pay_element_id is null) then
489      Select psb_pay_elements_s.nextval INTO l_pay_element_id
490      FROM   dual;
491 
492      PSB_PAY_ELEMENTS_PVT.INSERT_ROW
493      ( p_api_version             =>  1.0,
494        p_init_msg_lISt           => NULL,
495        p_commit                  => NULL,
496        p_validation_level        => NULL,
497        p_return_status           => l_return_status,
498        p_msg_count               => l_msg_count,
499        p_msg_data                     => l_msg_data,
500        p_row_id                  => l_rowid,
501        p_pay_element_id          => l_pay_element_id,
502        p_business_group_id       => p_business_group_id,
503        p_data_extract_id         => p_data_extract_id,
504        p_name                    => l_rate_or_payscale_name,
505        p_description             => NULL,
506        p_element_value_type      => 'A',
507        p_formula_id              => NULL,
508        p_overwrite_flag          => 'Y',
509        p_required_flag           => NULL,
510        p_follow_salary           => NULL,
511        p_pay_basis               => l_pay_basis,
512        p_start_date              => p_date_effective,
513        p_end_date                => NULL,
514        p_processing_type         => 'R',
515        p_period_type             => NULL,
516        p_process_period_type     => NULL,
517        p_max_element_value_type  => NULL,
518        p_max_element_value       => NULL,
519        p_salary_flag             => 'Y',
520        p_salary_type             => l_salary_type,
521        p_option_flag             => 'N',
522        p_hr_element_type_id      => NULL,
523        p_attribute_category      => NULL,
524        p_attribute1              => NULL,
525        p_attribute2              => NULL,
526        p_attribute3              => NULL,
527        p_attribute4              => NULL,
528        p_attribute5              => NULL,
529        p_attribute6              => NULL,
530        p_attribute7              => NULL,
531        p_attribute8              => NULL,
532        p_attribute9              => NULL,
533        p_attribute10             => NULL,
534        p_last_update_date        => l_last_update_date,
535        p_last_updated_by         => l_last_updated_by,
536        p_last_update_login       => l_last_update_login,
537        p_created_by              => l_created_by,
538        p_creation_date           => l_creation_date
539        );
540 
541        iF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
542 	    RAISE FND_API.G_EXC_ERROR;
543        END IF;
544        end if;
545 
546        If (l_pay_element_option_id is null) then
547 
548            -- Bug 4222417 moved the following statements
549            -- to the beginning of the api
550         /* l_last_update_date  := sysdate;
551 	   l_last_updated_BY   := FND_GLOBAL.USER_ID;
552 	   l_last_update_login := FND_GLOBAL.LOGIN_ID;
553 	   l_creation_date     := sysdate;
554 	   l_created_by        := FND_GLOBAL.USER_ID; */
555 
556 	  Select psb_pay_element_options_s.nextval
557 	     INTO l_pay_element_option_id
558 	     FROM dual;
559 
560 	  PSB_PAY_ELEMENT_OPTIONS_PVT.INSERT_ROW
561 	  ( p_api_version             =>  1.0,
562 	    p_init_msg_list           => NULL,
563 	    p_commit                  => NULL,
564 	    p_validation_level        => NULL,
565 	    p_return_status           => l_return_status,
566 	    p_msg_count               => l_msg_count,
567 	    p_msg_data                => l_msg_data,
568 	    p_pay_element_option_id   => l_pay_element_option_id,
569 	    p_pay_element_id          => l_pay_element_id,
570 	    p_name                    => l_grade_name,
571 	    p_grade_step              => l_grade_step,
572 	    p_sequence_number         => l_sequence,
573 	    p_last_update_date        => l_last_update_date,
574 	    p_last_updated_by         => l_last_updated_by,
575 	    p_last_update_login       => l_last_update_login,
576 	    p_created_by              => l_created_by,
577 	    p_creation_date           => l_creation_date
578 	   );
579 
580 	   IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
581 	     RAISE FND_API.G_EXC_ERROR;
582 	   END IF;
583 
584 
585 	   Select psb_pay_element_rates_s.nextval
586 	     INTO l_pay_element_rate_id
587 	     FROM dual;
588 
589 	  For C_Currency_Rec in C_Currency
590 	  Loop
591 	    l_currency_code := C_Currency_Rec.currency_code;
592 	  End Loop;
593 
594 	  PSB_PAY_ELEMENT_RATES_PVT.INSERT_ROW
595 	  ( p_api_version             =>  1.0,
596 	    p_init_msg_list           => NULL,
597 	    p_commit                  => NULL,
598 	    p_validation_level        => NULL,
599 	    p_return_status           => l_return_status,
600 	    p_msg_count               => l_msg_count,
601 	    p_msg_data                => l_msg_data,
602 	    p_pay_element_rate_id     => l_pay_element_rate_id,
603 	    p_pay_element_option_id   => l_pay_element_option_id,
604 	    p_pay_element_id          => l_pay_element_id,
605 	    p_effective_start_date    => p_date_effective,
606 	    p_effective_END_DATE      => p_date_end,
607 	    p_worksheet_id            => NULL,
608 	    p_element_value_type      => 'A',
609 	    p_element_value           =>
610                    fnd_number.canonical_to_number(C_Pay_Grade_Rec.value),
611 	    p_pay_basIS               => l_pay_basis,
612 	    p_FORmula_id              => NULL,
613 	    p_maximum_value           =>
614                    fnd_number.canonical_to_number(C_Pay_Grade_Rec.maximum),
615 	    p_mid_value               =>
616                    fnd_number.canonical_to_number(C_Pay_Grade_Rec.mid_value),
617 	    p_minimum_value           =>
618                    fnd_number.canonical_to_number(C_Pay_Grade_Rec.minimum),
619 	    p_currency_code           => l_currency_code,
620 	    p_last_update_date        => l_last_update_date,
621 	    p_last_updated_by         => l_last_updated_by,
622 	    p_last_update_login       => l_last_update_login,
623 	    p_created_by              => l_created_by,
624 	    p_creation_date           => l_creation_date
625 	   ) ;
626 
627 	   IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
628 	     RAISE FND_API.G_EXC_ERROR;
629 	   END IF;
630 
631    end if;
632    End Loop;
633 
634    FOR C_pay_element_rates_rec in C_pay_element_rates
635    LOOP
636     l_pay_element_rate_id  := C_pay_element_rates_rec.pay_element_rate_id;
637     l_currency_code        := C_pay_element_rates_rec.currency_code;
638    END LOOP;
639 
640    IF l_pay_element_id is null and
641       l_pay_element_option_id is null  and
642       l_value is null then
643 
644       null;
645       hr_utility.set_location('  """ :: ele and option id is NULLLLL   ' ,336);
646       -- do not insert if there is nothing to insert
647    ELSE
648 
649       hr_utility.set_location('  ::: > before ASSinsert  ' ,336);
650 
651       PSB_POSITION_ASSIGNMENTS_PVT.INSERT_ROW
652       (
653      p_api_version             => 1,
654      p_init_msg_list           => NULL,
655      p_commit                  => NULL,
656      p_validation_level        => NULL,
657      p_return_status           => l_return_status,
658      p_msg_count               => l_msg_count,
659      p_msg_data                => l_msg_data,
660      p_rowid                   => l_rowid,
661      p_position_assignment_id  => l_position_assignment_id,
662      p_data_extract_id         => p_data_extract_id,
663      p_worksheet_id            => NULL,
664      p_position_id             => p_position_id,
665      p_assignment_type         => 'ELEMENT',
666      p_attribute_id            => NULL,
667      p_attribute_value_id      => NULL,
668      p_attribute_value         => NULL,
669      p_pay_element_id          => l_pay_element_id,
670      p_pay_element_option_id   => l_pay_element_option_id,
671      p_effective_start_date    => p_date_effective,
672      p_effective_END_DATE      => p_date_end,
673      p_element_value_type      => 'A',
674      p_element_value           => l_value,
675      p_currency_code           => l_currency_code,
676      p_pay_basIS               => l_pay_basis,
677      p_employee_id             => NULL,
678      p_primary_employee_flag   => NULL,
679      p_global_default_flag     => NULL,
680      p_assignment_default_rule_id => NULL,
681      p_modify_flag             => NULL,
682      p_mode                    => 'R'
683      );
684 
685       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
686 	 hr_utility.set_location('fail insert assignments - stat is ' ||
687 				l_return_status,983);
688 	 RAISE FND_API.G_EXC_ERROR;
689       END IF;
690 
691       if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
692 	  raise FND_API.G_EXC_ERROR;
693       end if;
694 
695     END IF;
696 
697    hr_utility.set_location(' -------E N D  S U CESS-------',333);
698   -- Initialize API return status to success
699   p_return_status := FND_API.G_RET_STS_SUCCESS;
700 
701   --hr_utility.trace_off;
702 EXCEPTION
703 
704   WHEN FND_API.G_EXC_ERROR THEN
705     hr_utility.set_location(' salary G_EXC_ERROR ----------',333);
706     --hr_utility.trace_off;
707     p_return_status := FND_API.G_RET_STS_ERROR;
708 
709   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
710     hr_utility.set_location(' G_EXC_UNEXPECTED_ERROR ------',333);
711     --hr_utility.trace_off;
712     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
713 
714   WHEN OTHERS THEN
715     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
716     --hr_utility.trace_off;
717     hr_utility.set_location(' G_RET_STS_UNEXP_ERRORR ------',333);
718 
719 End Populate_Salary_Assignments;
720 /*---------------------------------------------------------------------------*/
721 
722 
723 /*===========================================================================+
724  |                   PROCEDURE Populate_Attribute_Assignments (Pvt)          |
725  +===========================================================================*/
726 PROCEDURE Populate_Attribute_Assignments
727 (
728   p_return_status            OUT NOCOPY  VARCHAR2,
729   p_new_position_id          IN          NUMBER ,
730   p_position_id              IN          NUMBER := FND_API.G_MISS_NUM,
731   p_position_transaction_id  IN          NUMBER := FND_API.G_MISS_NUM,
732   p_job_id                   IN          NUMBER ,
733   p_organization_id          IN          NUMBER ,
734   p_fte                      IN          NUMBER ,
735   p_frequency                IN          VARCHAR2,
736   p_working_hours            IN          NUMBER ,
737   p_earliest_hire_date       IN          DATE,
738   p_entry_grade_id           IN          NUMBER ,
739   p_date_effective           IN          DATE,
740   p_date_end                 IN          DATE,
741   p_data_extract_id          IN          NUMBER,
742   p_business_group_id        IN          NUMBER
743 )
744 IS
745   l_definition_structure    varchar2(30);
746   l_definition_table        varchar2(30);
747   l_definition_column       varchar2(30);
748   l_id_flex_code            varchar2(4);
749   l_application_id          number;
750   l_application_table_name  varchar2(30);
751   l_set_defining_column     varchar2(30);
752   l_id_flex_num             number;
753   l_job_id_flex_num         number;
754   l_application_column_name varchar2(30);
755   l_definition_type         varchar2(30);
756   --UTF8 changes for Bug No : 2615261
757   lp_attribute_value        psb_attribute_values.attribute_value%TYPE;
758   l_attribute_id            number;
759   l_attribute_type_id       number;
760   l_attribute_name          varchar2(30);
761   l_attribute_value_id      number;
762   --UTF8 changes for Bug No : 2615261
763   l_attribute_value         psb_attribute_values.attribute_value%TYPE;
764   l_position_assignment_id number := 0;
765 
766   l_select_tab              varchar2(30);
767   l_select_key              varchar2(30);
768   l_param_value             number;
769 
770   l_sql_stmt                varchar2(1000);
771   v_cursorid                integer;
772   v_dummy                   integer;
773   v_segment                 varchar2(80);
774   v_dcursorid               integer;
775   v_ddummy                  integer;
776   v_dsegment                varchar2(80);
777   d_sql_stmt                varchar2(500);
778   v_qcursorid               integer;
779   v_qdummy                  integer;
780   v_qsegment                varchar2(80);
781   q_sql_stmt                varchar2(500);
782   v_ocursorid               integer;
783   v_odummy                  integer;
784   v_osegment                varchar2(80);
785   v_odate                   date;
786   v_onumber                 number;
787   o_sql_stmt                varchar2(500);
788   l_alias1                  varchar2(10);
789   l_value_table_flag        varchar2(1);
790   l_lookup_type             varchar2(30);
791 
792   l_return_status          varchar2(1);
793   l_msg_count              number;
794   l_msg_data               varchar2(1000);
795   l_message_text           varchar2(2000);
796   l_rowid                  varchar2(100);
797 
798   l_last_update_date    DATE;
799   l_last_updated_BY     number;
800   l_last_update_login   number;
801   l_creation_date       DATE;
802   l_created_by          number;
803   l_valid_attribute     varchar2(1) := 'N';
804 
805  Cursor C_Attributes is
806    Select  attribute_id,name,definition_type,definition_structure,
807 	   definition_table, definition_column,system_attribute_type,
808 	   attribute_type_id,data_type,
809 	   nvl(value_table_flag,'N') value_table_flag
810     from psb_attributes_vl
811    where business_group_id = p_business_group_id
812      -- Added for Bug#2820825
813      and (system_attribute_type is null OR system_attribute_type <> 'HIREDATE');
814 
815  Cursor C_Attribute_Type is
816     Select name, select_table,
817            /*For Bug No : 2820825 Start*/
818 	   substr(select_table,1,instr(select_table,' ',1)-1) select_tab,
819            /*For Bug No : 2820825 End*/
820 	   select_column,select_key,
821 	   link_key,decode(link_type,'A','PER_ALL_ASSIGNMENTS','E',
822 	   'PER_ALL_PEOPLE','P', 'HR_ALL_POSITIONS','PER_ALL_ASSIGNMENTS')
823 	   link_type,link_type l_alias2,
824 	   select_where
825       From Psb_attribute_types
826     Where  attribute_type = l_definition_type
827       and  attribute_type_id = l_attribute_type_id;
828 
829  Cursor C_job_structure is
830     Select job_structure
831       from per_business_groups
832      where business_group_id = p_business_group_id;
833 
834  Cursor C_Pos_Job is
835     Select name
836       from per_jobs
837      where job_id = p_job_id;
838 
839  Cursor C_Pos_Org is
840     Select name
841       from hr_all_organization_units
842      where organization_id = p_organization_id;
843 
844   Cursor C_pos_values is
845     Select attribute_value_id
846       FROM psb_attribute_values
847      WHERE attribute_id = l_attribute_id
848        AND decode(l_definition_type, 'DFF',hr_value_id,
849 		  attribute_value) = lp_attribute_value
850        AND data_extract_id  = p_data_extract_id;
851 
852   Cursor C_key_33 is
853        Select application_id,id_flex_code,
854 	      application_table_name,
855 	      set_defining_column_name
856 	from  fnd_id_flexs
857        where id_flex_name = l_definition_structure;
858 
859   Cursor C_key_44 is
860     SELECT fseg.application_column_name
861 	    FROM fnd_id_flex_structures_vl fstr,fnd_id_flex_segments_vl fseg
862      WHERE fstr.application_id = l_application_id
863 	     AND fstr.id_flex_code   = l_id_flex_code
864 	     AND fstr.id_flex_structure_name = l_definition_table
865 	     AND fstr.id_flex_code   = fseg.id_flex_code
866 	     AND fstr.id_flex_num    = fseg.id_flex_num
867 	     AND fseg.segment_name   = l_definition_column
868 	     AND fstr.application_id = fseg.application_id;  -- bug #4924031
869 
870    Cursor C_dff_33 is
871      Select application_id,application_table_name,
872 	    context_column_name
873        from fnd_descriptive_flexs_vl
874       where descriptive_flexfield_name = l_definition_structure;
875 
876    Cursor C_dff_44 is
877     Select fcol.application_column_name
878      from  fnd_descr_flex_contexts_vl fcon,fnd_descr_flex_column_usages fcol
879      where fcon.application_id = fcol.application_id
880        and fcon.descriptive_flexfield_name = l_definition_structure
881        and fcon.descriptive_flex_context_code = l_definition_table
882        and fcon.descriptive_flexfield_name = fcol.descriptive_flexfield_name
883     and fcon.descriptive_flex_context_code = fcol.descriptive_flex_context_code
884     and fcol.end_user_column_name = l_definition_column;
885 
886    Cursor C_Qc_55 is
887      Select lookup_type
888        from per_common_lookup_types_v
889       where lookup_type_meaning = l_definition_table;
890 
891 BEGIN
892 
893   -- Initialize the standard parameters.
894   -- p_return_status := FND_API.G_RET_STS_SUCCESS ;
895 
896   -- This procedure will create assignments from incremental data extract. If
897   -- it is a system_attribute_type, then it is a candidate for adding to the
898   -- position_assignments.
899   -- If it is not system_attributes, then only when the definition types meet
900   -- certain conditions will the attribute be added to the positions i.e., if
901   -- KFF, structure should either be 'Job Flexfield','Position Flexfield' or ,
902   -- 'Grade Flexfield. In both cases, attribute will be written to position
903   -- assgn only if either attribute_value_id or attribute_value is not null.
904 
905   --hr_utility.trace_on;
906 
907   For C_Attribute_Rec in C_Attributes
908   Loop -- L1
909 
910 
911     lp_attribute_value     := NULL;
912     l_attribute_type_id    := C_Attribute_Rec.attribute_type_id;
913     l_attribute_id         := C_Attribute_Rec.attribute_id;
914     l_attribute_name       := C_Attribute_Rec.name;
915     l_definition_type      := C_Attribute_Rec.definition_type;
916     l_definition_structure := C_Attribute_Rec.definition_structure;
917     l_definition_table     := C_Attribute_Rec.definition_table;
918     l_definition_column    := C_Attribute_Rec.definition_column;
919 
920     hr_utility.set_location(' Attribute tuype  '||
921 			    C_Attribute_Rec.system_attribute_type ,888);
922 
923     l_valid_attribute := 'N' ; -- initial setting for each record
924 
925     if (C_Attribute_Rec.system_attribute_type is not null) then --I1
926       if (C_Attribute_Rec.system_attribute_type = 'JOB_CLASS') then --I2
927 
928 	 l_valid_attribute := 'Y' ;
929 	 For C_job_structure_rec in C_job_structure
930 	 Loop
931 	   l_job_id_flex_num := C_job_structure_rec.job_structure;
932 	 End Loop;
933 
934 	 For C_Pos_Job_Rec in C_Pos_Job
935 	 Loop
936 	   lp_attribute_value := C_Pos_Job_Rec.name;
937 	 End Loop;
938 
939       elsif (C_Attribute_Rec.system_attribute_type = 'ORG') then
940 
941 	 l_valid_attribute := 'Y' ;
942 	 For C_Org_Rec in C_Pos_Org
943 	 Loop
944 	   lp_attribute_value := C_Org_Rec.name;
945 	 End Loop;
946 	 hr_utility.set_location(' JOB value '||l_attribute_value,888);
947 
948       elsif (C_Attribute_Rec.system_attribute_type = 'FTE') then
949 	 hr_utility.set_location(' FTE value ',888);
950 	 lp_attribute_value := p_fte;
951 	 l_valid_attribute := 'Y' ;
952 
953       elsif C_Attribute_Rec.system_attribute_type = 'DEFAULT_WEEKLY_HOURS' then
954 	if (p_frequency = 'W') then
955 	 lp_attribute_value := fnd_number.number_to_canonical(p_working_hours);
956 	end if;
957 	 l_valid_attribute := 'Y' ;
958       -- Bug#2109120: Commenting
959       /*
960          elsif (C_Attribute_Rec.system_attribute_type = 'HIREDATE') then
961 	 lp_attribute_value :=fnd_date.date_to_canonical(p_earliest_hire_date);
962 	 l_valid_attribute := 'Y' ;
963       */
964       end if; -- I2
965     else
966      -- ++ start of non-system attributes
967      -- ++ C_Attribute_Rec.system_attribute_type is null)
968 
969      l_select_tab := NULL;
970      l_select_key := NULL;
971      l_param_value   := NULL;
972 
973      if (l_definition_type = 'KFF') then
974        if (l_definition_structure in
975                       ('Job Flexfield','Position Flexfield','Grade Flexfield'))
976        then
977 	l_valid_attribute := 'Y' ;
978 	For C_key_rec in C_key_33
979 	Loop
980 	   l_application_id      := C_key_rec.application_id;
981 	   l_id_flex_code        := C_key_rec.id_flex_code;
982 	   l_set_defining_column := C_key_rec.set_defining_column_name;
983 	   For C_key_str_rec in C_key_44
984 	   Loop
985 	      l_application_column_name :=
986 			 C_key_str_rec.application_column_name;
987 	   End Loop;
988 	End Loop;
989 
990 	--hr_utility.set_location(' Attribute Struct '||
991 	--                            l_definition_structure,666);
992 
993 	v_cursorid := dbms_sql.open_cursor;
994 	if (l_definition_structure = 'Job Flexfield') then
995 	    l_sql_stmt := 'Select '||l_application_column_name||
996 			 ' From  Per_jobs,per_job_definitions '||
997 			 ' Where per_jobs.job_id = '||p_job_id||
998 			 '   and per_jobs.job_definition_id = '||
999 			 ' per_job_definitions.job_definition_id';
1000 
1001 	    dbms_sql.parse(v_cursorid,l_sql_stmt,dbms_sql.v7);
1002 	    dbms_sql.define_column(v_cursorid,1,v_segment,80);
1003 	elsif (l_definition_structure = 'Position Flexfield') then
1004 	 if (p_position_id = FND_API.G_MISS_NUM) then
1005 	     l_select_tab := 'PQH_POSITION_TRANSACTIONS';
1006 	     l_select_key := 'POSITION_TRANSACTION_ID';
1007 	     l_param_value   := p_position_transaction_id;
1008 	 else
1009 	     l_select_tab := 'HR_ALL_POSITIONS';
1010 	     l_select_key := 'POSITION_ID';
1011 	     l_param_value   := p_position_id;
1012 	 end if;
1013 
1014 	 /* Bug 3504183 Added a space after AND in line 1029 */
1015 	 /*For Bug No : 2991818 Start*/
1016 	 l_sql_stmt := 'Select '||l_application_column_name||
1017 		  ' From '||l_select_tab||','||'per_position_definitions '||
1018 		  ' Where '||l_select_tab||'.'||l_select_key||' = '||
1019 		    ' :v_param_value and '||
1020 		    l_select_tab||'.'||'position_definition_id = '||
1021 		    ' per_position_definitions.position_definition_id';
1022 
1023 	   dbms_sql.parse(v_cursorid,l_sql_stmt,dbms_sql.v7);
1024 	   dbms_sql.bind_variable(v_cursorid,':v_param_value',l_param_value);
1025 	   /*For Bug No : 2991818 End*/
1026 	   dbms_sql.define_column(v_cursorid,1,v_segment,80);
1027 
1028 	elsif (l_definition_structure = 'Grade Flexfield') then
1029 	 l_sql_stmt := 'Select '||l_application_column_name||
1030 	       ' From  Per_grades,per_grade_definitions '||
1031 	       ' Where per_grades.grade_id = '||p_entry_grade_id||
1032 	       '   and per_grades.grade_definition_id = '||
1033 		    ' per_grade_definitions.grade_definition_id';
1034 	 dbms_sql.parse(v_cursorid,l_sql_stmt,dbms_sql.v7);
1035 	 dbms_sql.define_column(v_cursorid,1,v_segment,80);
1036 	end if;
1037 	v_dummy := DBMS_SQL.EXECUTE(v_cursorid);
1038 
1039 	loop
1040 	  v_segment := '';
1041 	  if DBMS_SQL.FETCH_ROWS(v_cursorid) = 0 then
1042 	     exit;
1043 	  end if;
1044 	  dbms_sql.column_value(v_cursorid,1,v_segment);
1045 	  lp_attribute_value := v_segment;
1046 	end loop;
1047 
1048 	--hr_utility.set_location('Attribute Success'||lp_attribute_value,666);
1049        end if;
1050       elsif (l_definition_type = 'DFF') then
1051 	 For Attr_Type_Rec in C_Attribute_Type
1052 	 Loop
1053 	   if ((Attr_Type_Rec.link_type = 'HR_ALL_POSITIONS')
1054 	       and (Attr_Type_Rec.select_tab = 'HR_ALL_POSITIONS')) then
1055 
1056 	       l_valid_attribute := 'Y' ;
1057 
1058 	      if (p_position_id = FND_API.G_MISS_NUM) then
1059 		 l_select_tab := 'PQH_POSITION_TRANSACTIONS';
1060 		 l_select_key := 'POSITION_TRANSACTION_ID';
1061 		 l_param_value   := p_position_transaction_id;
1062 	      else
1063 		 l_select_tab := 'HR_ALL_POSITIONS';
1064 		 l_select_key := 'POSITION_ID';
1065 		 l_param_value   := p_position_id;
1066 	      end if;
1067 
1068 	      if (dbms_sql.IS_OPEN(v_dcursorid)) then
1069 		 dbms_sql.close_cursor(v_dcursorid);
1070 	      end if;
1071 
1072 	      For C_dff_rec in C_dff_33
1073 	      Loop
1074 		l_application_id          := C_dff_rec.application_id;
1075 		l_application_table_name  := C_dff_rec.application_table_name;
1076 
1077 		For C_dff_str_rec in C_dff_44
1078 		Loop
1079 		  l_application_column_name :=
1080 				C_dff_str_rec.application_column_name;
1081 		End Loop;
1082 	      End Loop;
1083 	      Begin
1084 		Select ltrim(rtrim(substr(Attr_type_rec.select_table,
1085 		       instr(Attr_type_rec.select_table,' ',1),
1086 		       length(Attr_type_rec.select_table)
1087 		       - instr(Attr_type_rec.select_table,' ',1) + 1)))
1088 		  into l_alias1
1089 		  from dual;
1090 	      end;
1091 	      v_dcursorid := dbms_sql.open_cursor;
1092               /* For Bug No. 2991818 Start */
1093 	      d_sql_stmt := 'Select '||l_alias1||'.'
1094 			    ||l_application_column_name||
1095 		   '  From '||l_select_tab||' '||
1096 			    l_alias1||' , '||
1097 		   ' Where '||l_alias1||'.'||
1098 		     l_select_key||' = :v_param_value';
1099 
1100 	      if (Attr_type_rec.select_where is not null) then
1101 		 d_sql_stmt := d_sql_stmt||' and '||Attr_type_rec.select_where;
1102 	      end if;
1103 
1104 	      dbms_sql.parse(v_dcursorid,d_sql_stmt,dbms_sql.v7);
1105        	      dbms_sql.bind_variable(v_dcursorid,':v_param_value',
1106                                                    l_param_value);
1107               /*For Bug No : 2991818 End*/
1108 	      dbms_sql.define_column(v_dcursorid,1,v_dsegment,80);
1109 
1110 
1111 	      v_ddummy := DBMS_SQL.EXECUTE(v_dcursorid);
1112 
1113 	     loop
1114 
1115 	       if DBMS_SQL.FETCH_ROWS(v_dcursorid) = 0 then
1116 		  exit;
1117 	       end if;
1118 
1119 	      dbms_sql.column_value(v_dcursorid,1,v_dsegment);
1120 	      lp_attribute_value := v_dsegment;
1121 	     end loop;
1122 
1123 	  end if;
1124 	  end loop;
1125 
1126       elsif (l_definition_type = 'QC') then
1127 
1128 	For Attr_Type_Rec in C_Attribute_Type
1129 	 Loop
1130 	   if ((Attr_Type_Rec.link_type = 'HR_ALL_POSITIONS') and
1131 	       (Attr_Type_Rec.select_tab = 'HR_ALL_POSITIONS')) then
1132 
1133 	      l_valid_attribute := 'Y' ;
1134 	      if (p_position_id = FND_API.G_MISS_NUM) then
1135 		 l_select_tab := 'PQH_POSITION_TRANSACTIONS';
1136 		 l_select_key := 'POSITION_TRANSACTION_ID';
1137 		 l_param_value   := p_position_transaction_id;
1138 	      else
1139 		 l_select_tab := 'HR_ALL_POSITIONS';
1140 		 l_select_key := 'POSITION_ID';
1141 		 l_param_value   := p_position_id;
1142 	      end if;
1143 
1144 	   if dbms_sql.is_open(v_qcursorid) then
1145 	      dbms_sql.close_cursor(v_qcursorid);
1146 	   end if;
1147 
1148 	   l_lookup_type := Attr_type_rec.name;
1149 
1150 	   Begin
1151 	     Select ltrim(rtrim(substr(Attr_type_rec.select_table,
1152 		    instr(Attr_type_rec.select_table,' ',1),
1153 		   length(Attr_type_rec.select_table)
1154 		    - instr(Attr_type_rec.select_table,' ',1) + 1)))
1155 	      into l_alias1
1156 	      from dual;
1157 	   end;
1158 
1159 
1160 	   v_qcursorid := dbms_sql.open_cursor;
1161 	  /* For Bug No. 2991818 Start */
1162 	   q_sql_stmt := 'Select a.meaning '||
1163 			 '  From Fnd_Common_lookups a , '||
1164 			      l_select_tab||' '||l_alias1||
1165 		   ' Where a.lookup_type = '||''''||
1166 		   l_lookup_type||''''||
1167 		   ' and a.lookup_code = '||
1168 		     l_alias1||'.'||Attr_type_rec.select_column||
1169 		   ' and '||l_alias1||'.'||l_select_key||
1170 		   ' = :v_param_value';
1171 
1172 	   if (Attr_type_rec.select_where is not null) then
1173 	      q_sql_stmt := q_sql_stmt||' and '||Attr_type_rec.select_where;
1174 	   end if;
1175 
1176 	   dbms_sql.parse(v_qcursorid,q_sql_stmt,dbms_sql.v7);
1177            dbms_sql.bind_variable(v_qcursorid,':v_param_value',l_param_value);
1178            /*For Bug No : 2991818 End*/
1179  	   dbms_sql.define_column(v_qcursorid,1,v_qsegment,80);
1180 
1181 	   v_qdummy := DBMS_SQL.EXECUTE(v_qcursorid);
1182 
1183 	   loop
1184 
1185 	    if DBMS_SQL.FETCH_ROWS(v_qcursorid) = 0 then
1186 	       exit;
1187 	    end if;
1188 
1189 	    dbms_sql.column_value(v_qcursorid,1,v_qsegment);
1190 	    lp_attribute_value := v_qsegment;
1191 	   end loop;
1192 
1193 	  end if;
1194 	  end loop;
1195 
1196       elsif (l_definition_type = 'TABLE') then
1197       -- Handle table defn types
1198        For Attr_Type_Rec in C_Attribute_Type
1199        Loop
1200 
1201        if ((Attr_Type_Rec.link_type = 'HR_ALL_POSITIONS')
1202 	   and (Attr_Type_Rec.select_tab = 'HR_ALL_POSITIONS')) then
1203 
1204 	    l_valid_attribute := 'Y' ;
1205 	    if (p_position_id = FND_API.G_MISS_NUM) then
1206 	       l_select_tab := 'PQH_POSITION_TRANSACTIONS';
1207 	       l_select_key := 'POSITION_TRANSACTION_ID';
1208 	       l_param_value   := p_position_transaction_id;
1209 	    else
1210 	       l_select_tab := 'HR_ALL_POSITIONS';
1211 	       l_select_key := 'POSITION_ID';
1212 	       l_param_value   := p_position_id;
1213 	    end if;
1214 
1215 	   if dbms_sql.is_open(v_ocursorid) then
1216 	      dbms_sql.close_cursor(v_ocursorid);
1217 	   end if;
1218 
1219 	   v_ocursorid := dbms_sql.open_cursor;
1220 	   Begin
1221 	     Select ltrim(rtrim(substr(Attr_type_rec.select_table,
1222 		    instr(Attr_type_rec.select_table,' ',1),
1223 		    length(Attr_type_rec.select_table)
1224 	     - instr(Attr_type_rec.select_table,' ',1) + 1))) into l_alias1
1225 	      from dual;
1226 	   End;
1227 
1228 	   /*For Bug No : 2991818 Start*/
1229 	   o_sql_stmt := 'Select '||
1230 		      Attr_type_rec.select_column||
1231 		   '  From '||l_select_tab||' '||l_alias1||
1232 		   '  Where '||l_alias1||'.'||l_select_key||
1233 		   ' = :v_param_value';
1234 
1235 	  if (Attr_type_rec.select_where is not null) then
1236 	      o_sql_stmt := o_sql_stmt||' and '||Attr_type_rec.select_where;
1237 	  end if;
1238 
1239 	  dbms_sql.parse(v_ocursorid,o_sql_stmt,dbms_sql.v7);
1240           dbms_sql.bind_variable(v_ocursorid,':v_param_value',l_param_value);
1241           /*For Bug No : 2991818 End*/
1242 
1243 	  if (C_Attribute_Rec.data_type = 'D') then
1244 	      dbms_sql.define_column(v_ocursorid,1,v_odate);
1245 	  elsif (C_Attribute_Rec.data_type = 'N') then
1246 	     dbms_sql.define_column(v_ocursorid,1,v_onumber);
1247 	  elsif (C_Attribute_Rec.data_type = 'C') then
1248 	     dbms_sql.define_column(v_ocursorid,1,v_osegment,80);
1249 	  end if;
1250 
1251 	  v_odummy := DBMS_SQL.EXECUTE(v_ocursorid);
1252 
1253 	  loop
1254 
1255 	     if DBMS_SQL.FETCH_ROWS(v_ocursorid) = 0 then
1256 		exit;
1257 	     end if;
1258 
1259 	     if (C_Attribute_Rec.data_type = 'D') then
1260 	     begin
1261 	       dbms_sql.column_value(v_ocursorid,1,v_odate);
1262 	       v_osegment := fnd_date.date_to_canonical(v_odate);
1263 	       exception
1264 	       when OTHERS then -- Bug #4658351: Changed VALUE_ERROR to OTHERS
1265 
1266                  -- Changed the exception part for Bug#4658351
1267                  FND_MESSAGE.SET_NAME('PSB', 'PSB_ATTRIBUTE_VALUE_DATE_ERR');
1268                  FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME', l_attribute_name);
1269                  l_message_text := fnd_message.get;
1270                  RAISE_APPLICATION_ERROR(-20001,l_message_text);
1271 
1272 	    end;
1273 	    elsif (C_Attribute_Rec.data_type = 'N') then
1274 	    begin
1275 	      dbms_sql.column_value(v_ocursorid,1,v_onumber);
1276 	      v_osegment := fnd_number.number_to_canonical(v_onumber);
1277 	      exception
1278 	      when INVALID_NUMBER then
1279 
1280                 -- Changed the exception part for Bug#4658351
1281                 FND_MESSAGE.SET_NAME('PSB', 'PSB_ATTRIBUTE_VALUE_NUMBER_ERR');
1282                 FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME', l_attribute_name);
1283                 l_message_text := fnd_message.get;
1284                 RAISE_APPLICATION_ERROR(-20000,l_message_text);
1285 
1286 	    end;
1287 
1288 	   elsif (C_Attribute_Rec.data_type = 'C') then
1289 	     dbms_sql.column_value(v_ocursorid,1,v_osegment);
1290 	   end if;
1291 	   lp_attribute_value := v_osegment;
1292 	   end loop;
1293 	 end if;
1294 	 end loop;
1295       end if; /* if KFF */
1296     end if; -- I1
1297 
1298     -- Process only if it's one of the tested attributes i.e., people kff,
1299     -- other info dff are not to be processed; only position related
1300 
1301     hr_utility.set_location(' %% VALID AttrValue '||l_valid_attribute,888);
1302 
1303     --++ proceed only if a valid attribute;
1304 
1305     IF l_valid_attribute =  'Y'  THEN
1306 
1307     hr_utility.set_location(' Attribute Value '||lp_attribute_value,888);
1308     hr_utility.set_location(' Attribute ID '||C_Attribute_Rec.attribute_id,888);
1309     hr_utility.set_location(' name '||C_Attribute_Rec.name,888);
1310 
1311     l_attribute_id     := C_Attribute_Rec.attribute_id;
1312     l_value_table_flag := C_Attribute_Rec.value_table_flag;
1313     l_definition_type  := C_Attribute_Rec.definition_type;
1314 
1315     l_attribute_value_id := NULL;
1316     l_attribute_value    := NULL;
1317 
1318     IF (l_value_table_flag = 'Y') THEN
1319 
1320       -- Find the attribute_value_id based on the current attribute_name
1321       -- AND attribute_value FROM psb_attribute_values table.
1322 
1323 	FOR C_pos_value_rec in C_pos_values
1324 	LOOP
1325 	  l_attribute_value_id := C_pos_value_rec.attribute_value_id;
1326 	END LOOP;
1327 
1328 	IF (l_attribute_value_id IS NULL) THEN
1329 	    l_last_update_date  := sysdate;
1330 	    l_last_updated_BY   := FND_GLOBAL.USER_ID;
1331 	    l_last_update_login := FND_GLOBAL.LOGIN_ID;
1332 	    l_creation_date     := sysDATE;
1333 	    l_created_by        := FND_GLOBAL.USER_ID;
1334 
1335 	  -- Insert the new value in PSB_ATTRIBUTE_VALUES
1336 	  select psb_attribute_values_s.nextval into
1337 	     l_attribute_value_id from dual;
1338 
1339 	  PSB_ATTRIBUTE_VALUES_PVT.INSERT_ROW
1340 	  ( p_api_version             =>  1.0,
1341 	    p_init_msg_lISt           => NULL,
1342 	    p_commit                  => NULL,
1343 	    p_validation_level        => NULL,
1344 	    p_return_status           => l_return_status,
1345 	    p_msg_count               => l_msg_count,
1346 	    p_msg_data                => l_msg_data,
1347 	    p_rowid                   => l_rowid,
1348 	    p_attribute_value_id      => l_attribute_value_id,
1349 	    p_attribute_id            => l_attribute_id,
1350 	    p_attribute_value         => lp_attribute_value,
1351 	    p_hr_value_id             => NULL,
1352 	    p_description             => NULL,
1353 	    p_data_extract_id         => p_data_extract_id,
1354 	    p_context                 => NULL,
1355 	    p_attribute1              => NULL,
1356 	    p_attribute2              => NULL,
1357 	    p_attribute3              => NULL,
1358 	    p_attribute4              => NULL,
1359 	    p_attribute5              => NULL,
1360 	    p_attribute6              => NULL,
1361 	    p_attribute7              => NULL,
1362 	    p_attribute8              => NULL,
1363 	    p_attribute9              => NULL,
1364 	    p_attribute10             => NULL,
1365 	    p_attribute11             => NULL,
1366 	    p_attribute12             => NULL,
1367 	    p_attribute13             => NULL,
1368 	    p_attribute14             => NULL,
1369 	    p_attribute15             => NULL,
1370 	    p_attribute16             => NULL,
1371 	    p_attribute17             => NULL,
1372 	    p_attribute18             => NULL,
1373 	    p_attribute19             => NULL,
1374 	    p_attribute20             => NULL,
1375 	    p_attribute21             => NULL,
1376 	    p_attribute22             => NULL,
1377 	    p_attribute23             => NULL,
1378 	    p_attribute24             => NULL,
1379 	    p_attribute25             => NULL,
1380 	    p_attribute26             => NULL,
1381 	    p_attribute27             => NULL,
1382 	    p_attribute28             => NULL,
1383 	    p_attribute29             => NULL,
1384 	    p_attribute30             => NULL,
1385 	    p_last_upDATE_DATE        => l_last_update_date,
1386 	    p_last_upDATEd_BY         => l_last_updated_BY,
1387 	    p_last_upDATE_login       => l_last_update_login,
1388 	    p_created_BY              => l_created_by,
1389 	    p_creation_DATE           => l_creation_date
1390 	   ) ;
1391 
1392 	  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1393 	     RAISE FND_API.G_EXC_ERROR;
1394 	  END IF;
1395 
1396 	  l_attribute_value := lp_attribute_value;
1397 	else
1398 	  l_attribute_value := NULL;
1399 	END IF;
1400 
1401     else
1402 
1403 	l_attribute_value_id := NULL;
1404 	l_attribute_value := lp_attribute_value;
1405 
1406     END IF;  -- END IF ( l_value_table_flag = 'Y')
1407 
1408     IF l_attribute_value_id is not null or
1409        l_attribute_value is not null THEN
1410 
1411       PSB_POSITION_ASSIGNMENTS_PVT.INSERT_ROW
1412       (
1413 	 p_api_version             => 1,
1414 	 p_init_msg_list           => NULL,
1415 	 p_commit                  => NULL,
1416 	 p_validation_level        => NULL,
1417 	 p_return_status           => l_return_status,
1418 	 p_msg_count               => l_msg_count,
1419 	 p_msg_data                => l_msg_data,
1420 	 p_rowid                   => l_rowid,
1421 	 p_position_assignment_id  => l_position_assignment_id,
1422 	 p_data_extract_id         => p_data_extract_id,
1423 	 p_worksheet_id            => NULL,
1424 	 p_position_id             => p_new_position_id,
1425 	 p_assignment_type         => 'ATTRIBUTE',
1426 	 p_attribute_id            => l_attribute_id,
1427 	 p_attribute_value_id      => l_attribute_value_id,
1428 	 p_attribute_value         => l_attribute_value,
1429 	 p_pay_element_id          => NULL,
1430 	 p_pay_element_option_id   => NULL,
1431 	 p_effective_start_date    => p_date_effective,
1432 	 p_effective_end_date      => p_date_end,
1433 	 p_element_value_type      => NULL,
1434 	 p_element_value           => NULL,
1435 	 p_currency_code           => NULL,
1436 	 p_pay_basis               => NULL,
1437 	 p_employee_id             => NULL,
1438 	 p_primary_employee_flag   => NULL,
1439 	 p_global_default_flag     => NULL,
1440 	 p_assignment_default_rule_id => NULL,
1441 	 p_modify_flag             => NULL,
1442 	 p_mode                    => 'R'
1443       ) ;
1444 
1445 	IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1446 	  RAISE FND_API.G_EXC_ERROR;
1447 	END IF;
1448 
1449     END IF; -- end of l_valid_attribute
1450     END IF; -- test of attribute val/id
1451 
1452     hr_utility.set_location(' Attribute Assign Success YYY',999);
1453   End Loop; --L1
1454   --hr_utility.trace_off;
1455 
1456 END Populate_Attribute_Assignments;
1457 /*---------------------------------------------------------------------------*/
1458 
1459 
1460 /*===========================================================================+
1461  |                       PROCEDURE Insert_Position_Txn_Info                  |
1462  +===========================================================================*/
1463 PROCEDURE Insert_Position_Txn_Info
1464 (
1465  p_position_transaction_id        in number ,
1466  p_action_date                    in date ,
1467  p_position_id                    in number ,
1468  p_availability_status_id         in number ,
1469  p_business_group_id              in number ,
1470  p_entry_step_id                  in number ,
1471  p_entry_grade_rule_id            in number ,
1472  p_job_id                         in number ,
1473  p_location_id                    in number ,
1474  p_organization_id                in number ,
1475  p_pay_freq_payroll_id            in number ,
1476  p_position_definition_id         in number ,
1477  p_prior_position_id              in number ,
1478  p_relief_position_id             in number ,
1479  p_entry_grade_id                 in number ,
1480  p_successor_position_id          in number ,
1481  p_supervisor_position_id         in number ,
1482  p_amendment_date                 in date ,
1483  p_amendment_recommendation       in varchar2 ,
1484  p_amendment_ref_number           in varchar2 ,
1485  p_avail_status_prop_end_date     in date ,
1486  p_bargaining_unit_cd             in varchar2 ,
1487  p_comments                       in long ,
1488  p_country1                       in varchar2 ,
1489  p_country2                       in varchar2 ,
1490  p_country3                       in varchar2 ,
1491  p_current_job_prop_end_date      in date ,
1492  p_current_org_prop_end_date      in date ,
1493  p_date_effective                 in date ,
1494  p_date_end                       in date ,
1495  p_earliest_hire_date             in date ,
1496  p_fill_by_date                   in date ,
1497  p_frequency                      in varchar2 ,
1498  p_fte                            in number ,
1499  p_location1                      in varchar2 ,
1500  p_location2                      in varchar2 ,
1501  p_location3                      in varchar2 ,
1502  p_max_persons                    in number ,
1503  p_name                           in varchar2 ,
1504  p_other_requirements             in varchar2 ,
1505  p_overlap_period                 in number ,
1506  p_overlap_unit_cd                in varchar2 ,
1507  p_passport_required              in varchar2 ,
1508  p_pay_term_end_day_cd            in varchar2 ,
1509  p_pay_term_end_month_cd          in varchar2 ,
1510  p_permanent_temporary_flag       in varchar2 ,
1511  p_permit_recruitment_flag        in varchar2 ,
1512  p_position_type                  in varchar2 ,
1513  p_posting_description            in varchar2 ,
1514  p_probation_period               in number ,
1515  p_probation_period_unit_cd       in varchar2 ,
1516  p_relocate_domestically          in varchar2 ,
1517  p_relocate_internationally       in varchar2 ,
1518  p_replacement_required_flag      in varchar2 ,
1519  p_review_flag                    in varchar2 ,
1520  p_seasonal_flag                  in varchar2 ,
1521  p_security_requirements          in varchar2 ,
1522  p_service_minimum                in varchar2 ,
1523  p_term_start_day_cd              in varchar2 ,
1524  p_term_start_month_cd            in varchar2 ,
1525  p_time_normal_finish             in varchar2 ,
1526  p_time_normal_start              in varchar2 ,
1527  p_transaction_status             in varchar2 ,
1528  p_travel_required                in varchar2 ,
1529  p_working_hours                  in number ,
1530  p_works_council_approval_flag    in varchar2 ,
1531  p_work_any_country               in varchar2 ,
1532  p_work_any_location              in varchar2 ,
1533  p_work_period_type_cd            in varchar2 ,
1534  p_work_schedule                  in varchar2 ,
1535  p_work_term_end_day_cd           in varchar2 ,
1536  p_work_term_end_month_cd         in varchar2 ,
1537  p_proposed_fte_for_layoff        in  number,
1538  p_proposed_date_for_layoff       in  date,
1539  p_information1                   in varchar2 ,
1540  p_information2                   in varchar2 ,
1541  p_information3                   in varchar2 ,
1542  p_information4                   in varchar2 ,
1543  p_information5                   in varchar2 ,
1544  p_information6                   in varchar2 ,
1545  p_information7                   in varchar2 ,
1546  p_information8                   in varchar2 ,
1547  p_information9                   in varchar2 ,
1548  p_information10                  in varchar2 ,
1549  p_information11                  in varchar2 ,
1550  p_information12                  in varchar2 ,
1551  p_information13                  in varchar2 ,
1552  p_information14                  in varchar2 ,
1553  p_information15                  in varchar2 ,
1554  p_information16                  in varchar2 ,
1555  p_information17                  in varchar2 ,
1556  p_information18                  in varchar2 ,
1557  p_information19                  in varchar2 ,
1558  p_information20                  in varchar2 ,
1559  p_information21                  in varchar2 ,
1560  p_information22                  in varchar2 ,
1561  p_information23                  in varchar2 ,
1562  p_information24                  in varchar2 ,
1563  p_information25                  in varchar2 ,
1564  p_information26                  in varchar2 ,
1565  p_information27                  in varchar2 ,
1566  p_information28                  in varchar2 ,
1567  p_information29                  in varchar2 ,
1568  p_information30                  in varchar2 ,
1569  p_information_category           in varchar2 ,
1570  p_attribute1                     in varchar2 ,
1571  p_attribute2                     in varchar2 ,
1572  p_attribute3                     in varchar2 ,
1573  p_attribute4                     in varchar2 ,
1574  p_attribute5                     in varchar2 ,
1575  p_attribute6                     in varchar2 ,
1576  p_attribute7                     in varchar2 ,
1577  p_attribute8                     in varchar2 ,
1578  p_attribute9                     in varchar2 ,
1579  p_attribute10                    in varchar2 ,
1580  p_attribute11                    in varchar2 ,
1581  p_attribute12                    in varchar2 ,
1582  p_attribute13                    in varchar2 ,
1583  p_attribute14                    in varchar2 ,
1584  p_attribute15                    in varchar2 ,
1585  p_attribute16                    in varchar2 ,
1586  p_attribute17                    in varchar2 ,
1587  p_attribute18                    in varchar2 ,
1588  p_attribute19                    in varchar2 ,
1589  p_attribute20                    in varchar2 ,
1590  p_attribute21                    in varchar2 ,
1591  p_attribute22                    in varchar2 ,
1592  p_attribute23                    in varchar2 ,
1593  p_attribute24                    in varchar2 ,
1594  p_attribute25                    in varchar2 ,
1595  p_attribute26                    in varchar2 ,
1596  p_attribute27                    in varchar2 ,
1597  p_attribute28                    in varchar2 ,
1598  p_attribute29                    in varchar2 ,
1599  p_attribute30                    in varchar2 ,
1600  p_attribute_category             in varchar2 ,
1601  p_object_version_number          in number ,
1602  p_effective_date                 in date ,
1603  p_pay_basis_id                   in number ,
1604  p_supervisor_id                  in number
1605 )
1606 IS
1607   --
1608   l_api_name         CONSTANT VARCHAR2(30)  := 'Insert_Position_Txn_Info';
1609   l_api_version      CONSTANT NUMBER        := 1.0;
1610   --
1611   l_rowid                varchar2(100);
1612   l_vacant_position_flag varchar2(1);
1613   l_date_end             date;
1614   l_data_extract_id      number ;
1615   l_set_of_books_id      number;
1616   l_position_id_flex_num number;
1617   segs                   FND_FLEX_EXT.SegmentArray;
1618   isegs                  FND_FLEX_EXT.SegmentArray;
1619   l_init_index           BINARY_INTEGER;
1620   l_pos_index            BINARY_INTEGER;
1621   l_ccid                 number;
1622   l_position_id          number;
1623   l_concat_pos_name      varchar2(240);
1624   l_availability_status  varchar2(30);
1625 
1626   /*For Bug No : 2602027 Start*/
1627   l_pos_id_flex_num     number;
1628   l_per_index           BINARY_INTEGER;
1629   tf                    BOOLEAN;
1630   nsegs                 NUMBER;
1631   possegs               FND_FLEX_EXT.SegmentArray;
1632   /*For Bug No : 2602027 End*/
1633 
1634   l_return_status          varchar2(1);
1635   l_validity_date          date := null;
1636   l_msg_count              number;
1637   l_msg_data               varchar2(1000);
1638   l_msg                    varchar2(2000);
1639 
1640   Cursor C_avail_status is
1641  /*For Bug No : 1527423 Start*/
1642   --SELECT shared_type_name
1643     SELECT system_type_cd
1644  /*For Bug No : 1527423 End*/
1645       FROM per_shared_types
1646      WHERE lookup_type = 'POSITION_AVAILABILITY_STATUS'
1647        AND shared_type_id = p_availability_status_id;
1648 
1649   Cursor C_data_extract is
1650     SELECT business_group_id,
1651 	   set_of_books_id,
1652 	   position_id_flex_num,
1653 	   req_data_as_of_date
1654       FROM psb_data_extracts
1655      WHERE data_extract_id = l_data_extract_id;
1656 
1657   /*For Bug No : 2602027 Start*/
1658   Cursor C_flex_num is
1659 	select position_structure
1660 	  from per_business_groups
1661 	 where business_group_id = p_business_group_id;
1662 
1663   Cursor C_pos_segs is
1664     select application_column_name
1665       from fnd_id_flex_segments_vl
1666      where id_flex_code = 'POS'
1667        and id_flex_num = l_pos_id_flex_num
1668        and enabled_flag = 'Y'
1669     order by segment_num;
1670   /*For Bug No : 2602027 End*/
1671   --
1672 BEGIN
1673   --hr_utility.trace_on;
1674   hr_utility.set_location('>> insert position trans',777);
1675 
1676   if (get_global('G_PSB_APPLICATION_ID') = 8401) then
1677     hr_utility.set_location('>> appl id is 8401',777);
1678 
1679     if (get_global('G_PSB_CURRENT_FORM') in ('PSBMNPOS', 'PSBBGRVS','PSBWMPMD'))
1680     then
1681       if (p_date_end = to_date('31124712','DDMMYYYY')) then
1682         l_date_end := to_date(null);
1683       else
1684         l_date_end := p_date_end;
1685       end if;
1686 
1687       -- Get Data Extract Id value from Global.
1688       l_data_extract_id := get_global('G_PSB_DATA_EXTRACT_ID');
1689       For C_data_extract_rec in C_data_extract
1690       Loop
1691         l_set_of_books_id      := C_data_extract_rec.set_of_books_id;
1692         l_position_id_flex_num := C_data_extract_rec.position_id_flex_num;
1693       End Loop;
1694 
1695       /*For Bug No : 2602027 Start*/
1696       For C_flex_rec in C_flex_num
1697       Loop
1698         l_pos_id_flex_num := C_flex_rec.position_structure;
1699       End Loop;
1700 
1701       tf := FND_FLEX_EXT.GET_SEGMENTS('PER', 'POS', l_pos_id_flex_num,
1702                                        p_position_definition_id, nsegs, segs);
1703       if (tf = FALSE) then
1704         l_msg := FND_MESSAGE.Get;
1705         FND_MESSAGE.SET_NAME('PSB','PSB_POS_DEFN_VALUE_ERROR');
1706         FND_MESSAGE.SET_TOKEN('POSITION_NAME',p_name );
1707         FND_MESSAGE.SET_TOKEN('ERR_MESG',l_msg);
1708         FND_MSG_PUB.Add;
1709         hr_utility.set_location('error in get segments',9867);
1710         RAISE FND_API.G_EXC_ERROR;
1711       end if;
1712 
1713       l_per_index := 1;
1714       l_init_index := 0;
1715 
1716       For k in 1..30
1717       Loop
1718         possegs(k) := null;
1719       End Loop;
1720 
1721       For C_pos_seg_rec in C_pos_segs
1722       Loop
1723       l_init_index := l_init_index + 1;
1724 
1725       If (C_pos_seg_rec.application_column_name = 'SEGMENT1') then
1726          possegs(1) := segs(l_per_index);
1727 	 l_per_index := l_per_index + 1;
1728       end if;
1729       If (C_pos_seg_rec.application_column_name = 'SEGMENT2') then
1730 	 possegs(2) := segs(l_per_index);
1731 	 l_per_index := l_per_index + 1;
1732       end if;
1733       If (C_pos_seg_rec.application_column_name = 'SEGMENT3') then
1734 	 possegs(3) := segs(l_per_index);
1735 	 l_per_index := l_per_index + 1;
1736       end if;
1737       If (C_pos_seg_rec.application_column_name = 'SEGMENT4') then
1738 	 possegs(4) := segs(l_per_index);
1739 	 l_per_index := l_per_index + 1;
1740       end if;
1741       If (C_pos_seg_rec.application_column_name = 'SEGMENT5') then
1742 	 possegs(5) := segs(l_per_index);
1743 	 l_per_index := l_per_index + 1;
1744       end if;
1745       If (C_pos_seg_rec.application_column_name = 'SEGMENT6') then
1746 	 possegs(6) := segs(l_per_index);
1747 	 l_per_index := l_per_index + 1;
1748       end if;
1749       If (C_pos_seg_rec.application_column_name = 'SEGMENT7') then
1750 	 possegs(7) := segs(l_per_index);
1751 	 l_per_index := l_per_index + 1;
1752       end if;
1753       If (C_pos_seg_rec.application_column_name = 'SEGMENT8') then
1754 	 possegs(8) := segs(l_per_index);
1755 	 l_per_index := l_per_index + 1;
1756       end if;
1757       If (C_pos_seg_rec.application_column_name = 'SEGMENT9') then
1758 	 possegs(9) := segs(l_per_index);
1759 	 l_per_index := l_per_index + 1;
1760       end if;
1761       If (C_pos_seg_rec.application_column_name = 'SEGMENT10') then
1762 	 possegs(10) := segs(l_per_index);
1763 	 l_per_index := l_per_index + 1;
1764       end if;
1765       If (C_pos_seg_rec.application_column_name = 'SEGMENT11') then
1766 	 possegs(11) := segs(l_per_index);
1767 	 l_per_index := l_per_index + 1;
1768       end if;
1769       If (C_pos_seg_rec.application_column_name = 'SEGMENT12') then
1770 	 possegs(12) := segs(l_per_index);
1771 	 l_per_index := l_per_index + 1;
1772       end if;
1773       If (C_pos_seg_rec.application_column_name = 'SEGMENT13') then
1774 	 possegs(13) := segs(l_per_index);
1775 	 l_per_index := l_per_index + 1;
1776       end if;
1777       If (C_pos_seg_rec.application_column_name = 'SEGMENT14') then
1778 	 possegs(14) := segs(l_per_index);
1779 	 l_per_index := l_per_index + 1;
1780       end if;
1781       If (C_pos_seg_rec.application_column_name = 'SEGMENT15') then
1782 	 possegs(15) := segs(l_per_index);
1783 	 l_per_index := l_per_index + 1;
1784       end if;
1785       If (C_pos_seg_rec.application_column_name = 'SEGMENT16') then
1786 	 possegs(16) := segs(l_per_index);
1787 	 l_per_index := l_per_index + 1;
1788       end if;
1789       If (C_pos_seg_rec.application_column_name = 'SEGMENT17') then
1790 	 possegs(17) := segs(l_per_index);
1791 	 l_per_index := l_per_index + 1;
1792       end if;
1793       If (C_pos_seg_rec.application_column_name = 'SEGMENT18') then
1794 	 possegs(18) := segs(l_per_index);
1795 	 l_per_index := l_per_index + 1;
1796       end if;
1797       If (C_pos_seg_rec.application_column_name = 'SEGMENT19') then
1798 	 possegs(19) := segs(l_per_index);
1799 	 l_per_index := l_per_index + 1;
1800       end if;
1801       If (C_pos_seg_rec.application_column_name = 'SEGMENT20') then
1802 	 possegs(20) := segs(l_per_index);
1803 	 l_per_index := l_per_index + 1;
1804       end if;
1805       If (C_pos_seg_rec.application_column_name = 'SEGMENT21') then
1806 	 possegs(21) := segs(l_per_index);
1807 	 l_per_index := l_per_index + 1;
1808       end if;
1809       If (C_pos_seg_rec.application_column_name = 'SEGMENT22') then
1810 	 possegs(22) := segs(l_per_index);
1811 	 l_per_index := l_per_index + 1;
1812       end if;
1813       If (C_pos_seg_rec.application_column_name = 'SEGMENT23') then
1814 	 possegs(23) := segs(l_per_index);
1815 	 l_per_index := l_per_index + 1;
1816       end if;
1817       If (C_pos_seg_rec.application_column_name = 'SEGMENT24') then
1818 	 possegs(24) := segs(l_per_index);
1819 	 l_per_index := l_per_index + 1;
1820       end if;
1821       If (C_pos_seg_rec.application_column_name = 'SEGMENT25') then
1822 	 possegs(25) := segs(l_per_index);
1823 	 l_per_index := l_per_index + 1;
1824       end if;
1825       If (C_pos_seg_rec.application_column_name = 'SEGMENT26') then
1826 	 possegs(26) := segs(l_per_index);
1827 	 l_per_index := l_per_index + 1;
1828       end if;
1829       If (C_pos_seg_rec.application_column_name = 'SEGMENT27') then
1830 	 possegs(27) := segs(l_per_index);
1831 	 l_per_index := l_per_index + 1;
1832       end if;
1833       If (C_pos_seg_rec.application_column_name = 'SEGMENT28') then
1834 	 possegs(28) := segs(l_per_index);
1835 	 l_per_index := l_per_index + 1;
1836       end if;
1837       If (C_pos_seg_rec.application_column_name = 'SEGMENT29') then
1838 	 possegs(29) := segs(l_per_index);
1839 	 l_per_index := l_per_index + 1;
1840       end if;
1841       If (C_pos_seg_rec.application_column_name = 'SEGMENT30') then
1842 	 possegs(30) := segs(l_per_index);
1843 	 l_per_index := l_per_index + 1;
1844       end if;
1845       End Loop;
1846       /*For Bug No : 2602027 End*/
1847 
1848       For k in 1..30
1849       Loop
1850         isegs(k) := null;
1851       End Loop;
1852 
1853       l_pos_index := 0;
1854 
1855       FOR C_flex_rec in
1856       (
1857         Select application_column_name
1858         FROM   fnd_id_flex_segments_vl
1859         WHERE  id_flex_code = 'BPS'
1860         AND    id_flex_num  = l_position_id_flex_num
1861         AND    enabled_flag = 'Y'
1862         ORDER  BY segment_num
1863       )
1864       LOOP
1865 	l_pos_index := l_pos_index + 1;
1866 	isegs(l_pos_index) := NULL;
1867 
1868 	IF (C_flex_rec.application_column_name = 'SEGMENT1') THEN
1869 	    isegs(l_pos_index)   := possegs(1);
1870 	END IF;
1871 	IF (C_flex_rec.application_column_name = 'SEGMENT2') THEN
1872 	    isegs(l_pos_index)   := possegs(2);
1873 	END IF;
1874 	IF (C_flex_rec.application_column_name = 'SEGMENT3') THEN
1875 	    isegs(l_pos_index)   := possegs(3);
1876 	END IF;
1877 	IF (C_flex_rec.application_column_name = 'SEGMENT4') THEN
1878 	    isegs(l_pos_index)   := possegs(4);
1879 	END IF;
1880 	IF (C_flex_rec.application_column_name = 'SEGMENT5') THEN
1881 	    isegs(l_pos_index)   := possegs(5);
1882 	END IF;
1883 	IF (C_flex_rec.application_column_name = 'SEGMENT6') THEN
1884 	    isegs(l_pos_index)   := possegs(6);
1885 	END IF;
1886 	IF (C_flex_rec.application_column_name = 'SEGMENT7') THEN
1887 	    isegs(l_pos_index)   := possegs(7);
1888 	END IF;
1889 	IF (C_flex_rec.application_column_name = 'SEGMENT8') THEN
1890 	    isegs(l_pos_index)   := possegs(8);
1891 	END IF;
1892 	IF (C_flex_rec.application_column_name = 'SEGMENT9') THEN
1893 	    isegs(l_pos_index)   := possegs(9);
1894 	END IF;
1895 	IF (C_flex_rec.application_column_name = 'SEGMENT10') THEN
1896 	    isegs(l_pos_index)   := possegs(10);
1897 	END IF;
1898 	IF (C_flex_rec.application_column_name = 'SEGMENT11') THEN
1899 	    isegs(l_pos_index)   := possegs(11);
1900 	END IF;
1901 	IF (C_flex_rec.application_column_name = 'SEGMENT12') THEN
1902 	    isegs(l_pos_index)   := possegs(12);
1903 	END IF;
1904 	IF (C_flex_rec.application_column_name = 'SEGMENT13') THEN
1905 	    isegs(l_pos_index)   := possegs(13);
1906 	END IF;
1907 	IF (C_flex_rec.application_column_name = 'SEGMENT14') THEN
1908 	    isegs(l_pos_index)   := possegs(14);
1909 	END IF;
1910 	IF (C_flex_rec.application_column_name = 'SEGMENT15') THEN
1911 	    isegs(l_pos_index)   := possegs(15);
1912 	END IF;
1913 	IF (C_flex_rec.application_column_name = 'SEGMENT16') THEN
1914 	    isegs(l_pos_index)   := possegs(16);
1915 	END IF;
1916 	IF (C_flex_rec.application_column_name = 'SEGMENT17') THEN
1917 	    isegs(l_pos_index)   := possegs(17);
1918 	END IF;
1919 	IF (C_flex_rec.application_column_name = 'SEGMENT18') THEN
1920 	    isegs(l_pos_index)   := possegs(18);
1921 	END IF;
1922 	IF (C_flex_rec.application_column_name = 'SEGMENT19') THEN
1923 	    isegs(l_pos_index)   := possegs(19);
1924 	END IF;
1925 	IF (C_flex_rec.application_column_name = 'SEGMENT20') THEN
1926 	    isegs(l_pos_index)   := possegs(20);
1927 	END IF;
1928 	IF (C_flex_rec.application_column_name = 'SEGMENT21') THEN
1929 	    isegs(l_pos_index)   := possegs(21);
1930 	END IF;
1931 	IF (C_flex_rec.application_column_name = 'SEGMENT22') THEN
1932 	    isegs(l_pos_index)   := possegs(22);
1933 	END IF;
1934 	IF (C_flex_rec.application_column_name = 'SEGMENT23') THEN
1935 	    isegs(l_pos_index)   := possegs(23);
1936 	END IF;
1937 	IF (C_flex_rec.application_column_name = 'SEGMENT24') THEN
1938 	    isegs(l_pos_index)   := possegs(24);
1939 	END IF;
1940 	IF (C_flex_rec.application_column_name = 'SEGMENT25') THEN
1941 	    isegs(l_pos_index)   := possegs(25);
1942 	END IF;
1943 	IF (C_flex_rec.application_column_name = 'SEGMENT26') THEN
1944 	    isegs(l_pos_index)   := possegs(26);
1945 	END IF;
1946 	IF (C_flex_rec.application_column_name = 'SEGMENT27') THEN
1947 	    isegs(l_pos_index)   := possegs(27);
1948 	END IF;
1949 	IF (C_flex_rec.application_column_name = 'SEGMENT28') THEN
1950 	    isegs(l_pos_index)   := possegs(28);
1951 	END IF;
1952 	IF (C_flex_rec.application_column_name = 'SEGMENT29') THEN
1953 	    isegs(l_pos_index)   := possegs(29);
1954 	END IF;
1955 	IF (C_flex_rec.application_column_name = 'SEGMENT30') THEN
1956 	    isegs(l_pos_index)   := possegs(30);
1957 	END IF;
1958 
1959       END LOOP; -- END LOOP ( C_flex_rec in C_flex )
1960 
1961       l_msg := null;
1962       if not fnd_flex_ext.Get_combination_id
1963              ( application_short_name => 'PSB',
1964                key_flex_code => 'BPS',
1965                structure_number => l_position_id_flex_num,
1966                validation_date => sysdate,
1967                n_segments => l_pos_index,
1968                segments => isegs,
1969                combination_id => l_ccid
1970              )
1971       then
1972         l_msg := FND_MESSAGE.get;
1973         FND_MSG_PUB.Add;
1974         FND_MESSAGE.SET_NAME('PSB', 'PSB_INCREMENTAL_CCID_FAILURE');
1975         FND_MESSAGE.SET_TOKEN('ERRMESG',l_msg);
1976         hr_utility.set_location('error in get combination id',9867);
1977         RAISE FND_API.G_EXC_ERROR;
1978       end if;
1979 
1980       l_concat_pos_name := null;
1981       l_concat_pos_name := FND_FLEX_EXT.Get_Segs
1982                            ( application_short_name => 'PSB',
1983                              key_flex_code          => 'BPS',
1984                              structure_number       => l_position_id_flex_num,
1985                              combination_id         => l_ccid
1986                            );
1987       For C_avail_status_rec in C_avail_status
1988       Loop
1989         -- For Bug No 1527423
1990         /* l_availability_status := C_avail_status_rec.shared_type_name; */
1991         l_availability_status := C_avail_status_rec.system_type_cd;
1992       End loop;
1993 
1994       -- Create new position in PSB
1995       SELECT psb_positions_s.nextval INTO l_position_id
1996       FROM   dual;
1997 
1998       PSB_POSITIONS_PVT.INSERT_ROW
1999       (
2000         p_api_version            => 1.0,
2001         p_init_msg_list          => NULL,
2002         p_commit                 => NULL,
2003         p_validation_level       => NULL,
2004         p_return_status          => l_return_status,
2005         p_msg_count              => l_msg_count,
2006         p_msg_data               => l_msg_data,
2007         p_rowid                  => l_rowid,
2008         p_position_id            => l_position_id,
2009         -- de by org
2010         p_organization_id        => p_organization_id,
2011         p_data_extract_id        => l_data_extract_id,
2012         p_position_definition_id => l_ccid,
2013         p_hr_position_id         => p_position_id,
2014         p_hr_employee_id         => NULL,
2015         p_business_group_id      => p_business_group_id,
2016         p_effective_start_date   => p_date_effective,
2017         p_effective_end_date     => l_date_end,
2018         p_set_of_books_id        => l_set_of_books_id,
2019         p_vacant_position_flag   => 'Y',
2020         p_availability_status    => l_availability_status,
2021         p_transaction_id         => p_position_transaction_id,
2022         p_transaction_status     => p_transaction_status,
2023         p_new_position_flag      => 'Y',
2024         p_attribute1             => NULL,
2025         p_attribute2             => NULL,
2026         p_attribute3             => NULL,
2027         p_attribute4             => NULL,
2028         p_attribute5             => NULL,
2029         p_attribute6             => NULL,
2030         p_attribute7             => NULL,
2031         p_attribute8             => NULL,
2032         p_attribute9             => NULL,
2033         p_attribute10            => NULL,
2034         p_attribute11            => NULL,
2035         p_attribute12            => NULL,
2036         p_attribute13            => NULL,
2037         p_attribute14            => NULL,
2038         p_attribute15            => NULL,
2039         p_attribute16            => NULL,
2040         p_attribute17            => NULL,
2041         p_attribute18            => NULL,
2042         p_attribute19            => NULL,
2043         p_attribute20            => NULL,
2044         p_attribute_category     => NULL,
2045         p_name                   => l_concat_pos_name,
2046         p_mode                   => 'R'
2047       );
2048       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2049         FND_MESSAGE.SET_NAME('PSB', 'PSB_PQH_INSERT_FAILURE');
2050         RAISE FND_API.G_EXC_ERROR;
2051       END IF;
2052 
2053       -- Addto position sets for WS recalc
2054       PSB_Budget_Position_Pvt.Add_Position_To_Position_Sets
2055       (
2056         p_api_version       => 1.0,
2057         p_init_msg_list     => FND_API.G_TRUE,
2058         p_commit            => NULL,
2059         p_validation_level  => NULL,
2060         p_return_status     => l_return_status,
2061         p_msg_count         => l_msg_count,
2062         p_msg_data          => l_msg_data,
2063         p_position_id       => l_position_id
2064       ) ;
2065 
2066       hr_utility.set_location('>> added to pos set id ' || l_position_id,876);
2067       hr_utility.set_location('>> stat is ' || l_return_status,877);
2068 
2069       -- Populate Salary Assignments
2070 
2071       Populate_Salary_Assignments
2072       ( p_return_status   =>  l_return_status,
2073         p_position_id     =>  l_position_id,
2074         p_date_effective  =>  p_date_effective,
2075         p_date_end        =>  l_date_end,
2076         p_data_extract_id =>  l_data_extract_id,
2077         p_business_group_id =>  p_business_group_id,
2078         p_set_of_books_id   =>  l_set_of_books_id,
2079         p_entry_grade_rule_id  => p_entry_grade_rule_id,
2080         p_entry_step_id   => p_entry_step_id,
2081         p_entry_grade_id  => p_entry_grade_id,
2082         p_pay_basis_id    => p_pay_basis_id
2083       );
2084       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2085         FND_MESSAGE.SET_NAME('PSB', 'PSB_INCREMENTAL_SALARY_FAILURE');
2086         RAISE FND_API.G_EXC_ERROR;
2087       END IF;
2088 
2089       Populate_Attribute_Assignments
2090       ( p_return_status            =>  l_return_status,
2091         p_new_position_id          =>  l_position_id,
2092         p_position_transaction_id  =>  p_position_transaction_id,
2093         p_job_id                   =>  p_job_id,
2094         p_organization_id          =>  p_organization_id,
2095         p_fte                      =>  p_fte,
2096         p_frequency                =>  p_frequency,
2097         p_working_hours            =>  p_working_hours,
2098         p_earliest_hire_date       =>  p_earliest_hire_date,
2099         p_entry_grade_id           =>  p_entry_grade_id,
2100         p_date_effective           =>  p_date_effective,
2101         p_date_end                 =>  l_date_end,
2102         p_data_extract_id          =>  l_data_extract_id,
2103         p_business_group_id        =>  p_business_group_id
2104       ) ;
2105       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2106         FND_MESSAGE.SET_NAME('PSB', 'PSB_INCREMENTAL_ATTRIBUTE_FAIL');
2107         RAISE FND_API.G_EXC_ERROR;
2108       END IF;
2109 
2110       -- Update WS/BR; do only in add since org is cannot be diff than input
2111       Update_Worksheet_Values ( p_return_status => l_return_status,
2112                                 p_position_id   => l_position_id,
2113                                 p_org_id        => p_organization_id
2114                               ) ;
2115       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2116         hr_utility.set_location(' fail to update ws value ',888);
2117         FND_MESSAGE.SET_NAME('PSB', 'PSB_INCREMENTAL_WS_FAILURE'  );
2118         RAISE FND_API.G_EXC_ERROR;
2119       END IF;
2120 
2121       hr_utility.set_location('>> END insert position trans',777);
2122       --hr_utility.trace_off;
2123 
2124     end if;
2125     -- End checking G_PSB_CURRENT_FORM.
2126 
2127   end if;
2128   -- End checking G_PSB_APPLICATION_ID.
2129 
2130 EXCEPTION
2131   --
2132   WHEN OTHERS THEN
2133     Process_Exception( l_api_name ) ;
2134   --
2135 END Insert_Position_Txn_Info;
2136 /*---------------------------------------------------------------------------*/
2137 
2138 
2139 /*===========================================================================+
2140  |                      PROCEDURE Update_Position_Txn_Info                   |
2141  +===========================================================================*/
2142 PROCEDURE Update_Position_Txn_Info
2143 (p_position_transaction_id     in NUMBER,
2144  p_action_date                 in DATE ,
2145  p_position_id                 in NUMBER,
2146  p_availability_status_id      in NUMBER,
2147  p_business_group_id           in NUMBER,
2148  p_entry_step_id               in NUMBER,
2149  p_entry_grade_rule_id         in NUMBER,
2150  p_job_id                      in NUMBER,
2151  p_location_id                 in NUMBER,
2152  p_organization_id             in NUMBER,
2153  p_pay_freq_payroll_id         in NUMBER,
2154  p_position_definition_id      in NUMBER,
2155  p_entry_grade_id              in NUMBER,
2156  p_bargaining_unit_cd          in VARCHAR2,
2157  p_date_effective              in DATE,
2158  p_date_end                    in DATE,
2159  p_earliest_hire_date          in DATE,
2160  p_frequency                   in VARCHAR2,
2161  p_fte                         in NUMBER,
2162  p_name                        in VARCHAR2,
2163  p_position_type               in VARCHAR2,
2164  p_transaction_status          in VARCHAR2,
2165  p_working_hours               in NUMBER,
2166  p_pay_basis_id_o              in NUMBER,
2167  p_object_version_number       in NUMBER,
2168  p_effective_date              in DATE
2169 )
2170 IS
2171   --
2172   l_api_name         CONSTANT VARCHAR2(30)  := 'Update_Position_Txn_Info' ;
2173   l_api_version      CONSTANT NUMBER        := 1.0 ;
2174   --
2175   l_data_extract_id     number := 0;
2176   l_position_id_flex_num number;
2177   segs                  FND_FLEX_EXT.SegmentArray;
2178   l_init_index          BINARY_INTEGER;
2179   l_ccid                number;
2180   l_position_id         number;
2181   -- de by org
2182   l_organization_id     number;
2183   l_concat_pos_name     varchar2(240);
2184 
2185   Cursor C_trn_exist is
2186      Select 'Position Transaction Exists in PSB'
2187        from dual
2188       where exists
2189     (Select 1
2190        from psb_positions
2191       where transaction_id = p_position_transaction_id);
2192 
2193   Cursor C_pos_trx is
2194      Select *
2195        from psb_positions
2196       where transaction_id = p_position_transaction_id;
2197 
2198   Cursor C_availability_status  is
2199  /*For Bug No : 1527423 Start*/
2200   --select shared_type_name
2201     select system_type_cd
2202  /*For Bug No : 1527423 End*/
2203       from per_shared_types
2204      where lookup_type = 'POSITION_AVAILABILITY_STATUS'
2205        and shared_type_id = p_availability_status_id;
2206 
2207   Cursor C_data_extract is
2208     SELECT req_data_as_of_date,
2209 	   set_of_books_id,
2210 	   position_id_flex_num,
2211 	   business_group_id
2212       FROM psb_data_extracts
2213      WHERE data_extract_id = l_data_extract_id;
2214 
2215   l_trn_exist              VARCHAR2(1) := FND_API.G_FALSE;
2216   l_psb_position_id        number := '';
2217   l_set_of_books_id        number := '';
2218   l_validity_date          date := null;
2219   l_availability_status    varchar2(30);
2220   l_return_status          varchar2(1);
2221   l_msg_count              number;
2222   l_msg_data               varchar2(1000);
2223   l_msg                    varchar2(2000);
2224 
2225   /*For Bug No : 2602027 Start*/
2226   l_pos_id_flex_num     number;
2227   l_per_index           BINARY_INTEGER;
2228   l_pos_index           BINARY_INTEGER;
2229   tf                    BOOLEAN;
2230   nsegs                 NUMBER;
2231   possegs               FND_FLEX_EXT.SegmentArray;
2232   isegs                 FND_FLEX_EXT.SegmentArray;
2233   /*For Bug No : 2602027 End*/
2234 
2235   cursor c_ws_positions is
2236     select wpl.position_line_id, wlp.worksheet_id
2237       from psb_ws_position_lines  wpl,
2238            psb_ws_lines_positions wlp,
2239            psb_worksheets         ws
2240      where wpl.position_id = l_psb_position_id
2241        and wlp.position_line_id = wpl.position_line_id
2242        and ws.worksheet_id = wlp.worksheet_id
2243        and ws.global_worksheet_flag = 'Y';
2244 
2245   Cursor C_br_positions is
2246     Select brp.budget_revision_pos_line_id, brpl.budget_revision_id
2247       from psb_budget_revision_positions brp, psb_budget_revision_pos_lines brpl
2248      where brp.position_id = l_psb_position_id
2249        and brpl.budget_revision_pos_line_id = brp.budget_revision_pos_line_id;
2250 
2251   /*For Bug No : 2602027 Start*/
2252   Cursor C_flex_num is
2253 	select position_structure
2254 	  from per_business_groups
2255 	 where business_group_id = p_business_group_id;
2256 
2257   Cursor C_pos_segs is
2258     select application_column_name
2259       from fnd_id_flex_segments_vl
2260      where id_flex_code = 'POS'
2261        and id_flex_num = l_pos_id_flex_num
2262        and enabled_flag = 'Y'
2263     order by segment_num;
2264   /*For Bug No : 2602027 End*/
2265 
2266 Begin
2267 
2268   --hr_utility.trace_on;
2269   hr_utility.set_location('>> update position trans',777);
2270   hr_utility.set_location('>> p_position_transaction_id' || p_position_transaction_id,777);
2271 
2272  for c_trn_exist_rec in c_trn_exist loop
2273        l_trn_exist := FND_API.G_TRUE;
2274  end loop;
2275 
2276  if fnd_api.to_Boolean(l_trn_exist) THEN
2277  --++ main if ... do not process transaction if trn not in psb
2278  --++ update psb if called from create position and for apply process
2279  --++ for name and hr position id update  (a)
2280 
2281   /*For Bug No : 2738939 Start*/
2282   --added the TERMINATE in the following condition
2283   if ( (get_global('G_PSB_APPLICATION_ID') = 8401  and
2284 	p_transaction_status not in ('REJECT','TERMINATE'))
2285      )  OR
2286        (p_transaction_status =  'APPLIED' ) then
2287   /*For Bug No : 2738939 End*/
2288 
2289     hr_utility.set_location('>> applid 8401 ' ,1777);
2290 
2291     For C_pos_trx_rec in C_pos_trx        -- psb_positions
2292     Loop
2293        l_psb_position_id := C_pos_trx_rec.position_id;
2294        -- de by org
2295        l_organization_id  := C_pos_trx_rec.organization_id;
2296        l_availability_status := null;
2297        l_data_extract_id := C_pos_trx_rec.data_extract_id;
2298 
2299        For C_data_extract_rec in C_data_extract
2300        Loop
2301 	 l_set_of_books_id := C_data_extract_rec.set_of_books_id;
2302 	 l_position_id_flex_num := C_data_extract_rec.position_id_flex_num;
2303        End Loop;
2304 
2305        hr_utility.set_location('>> l_position_id_flex_num '||
2306 				   l_position_id_flex_num,777);
2307 
2308        For C_Avail_Status_Rec in C_Availability_Status
2309        Loop
2310 	/*For Bug No 1527423 Start */
2311 	--l_availability_status := C_avail_status_rec.shared_type_name;
2312 	l_availability_status := C_avail_status_rec.system_type_cd;
2313 	/*For Bug No 1527423 End */
2314        End loop;
2315 
2316        --++ restructure position name
2317 
2318      /*For Bug No : 2602027 Start*/
2319 
2320      For C_flex_rec in C_flex_num
2321      Loop
2322        l_pos_id_flex_num := C_flex_rec.position_structure;
2323      End Loop;
2324 
2325      tf := FND_FLEX_EXT.GET_SEGMENTS('PER', 'POS', l_pos_id_flex_num, p_position_definition_id, nsegs, segs);
2326 
2327      if (tf = FALSE) then
2328 	l_msg := FND_MESSAGE.Get;
2329 	FND_MESSAGE.SET_NAME('PSB','PSB_POS_DEFN_VALUE_ERROR');
2330 	FND_MESSAGE.SET_TOKEN('POSITION_NAME',p_name );
2331 	FND_MESSAGE.SET_TOKEN('ERR_MESG',l_msg);
2332 	FND_MSG_PUB.Add;
2333 	hr_utility.set_location('error in get segments',9850);
2334 	RAISE FND_API.G_EXC_ERROR;
2335      end if;
2336 
2337      l_per_index := 1;
2338      l_init_index := 0;
2339 
2340      For k in 1..30
2341      Loop
2342       possegs(k) := null;
2343      End Loop;
2344 
2345      For C_pos_seg_rec in C_pos_segs
2346      Loop
2347 
2348       l_init_index := l_init_index + 1;
2349 
2350       If (C_pos_seg_rec.application_column_name = 'SEGMENT1') then
2351 	 possegs(1) := segs(l_per_index);
2352 	 l_per_index := l_per_index + 1;
2353       end if;
2354       If (C_pos_seg_rec.application_column_name = 'SEGMENT2') then
2355 	 possegs(2) := segs(l_per_index);
2356 	 l_per_index := l_per_index + 1;
2357       end if;
2358       If (C_pos_seg_rec.application_column_name = 'SEGMENT3') then
2359 	 possegs(3) := segs(l_per_index);
2360 	 l_per_index := l_per_index + 1;
2361       end if;
2362       If (C_pos_seg_rec.application_column_name = 'SEGMENT4') then
2363 	 possegs(4) := segs(l_per_index);
2364 	 l_per_index := l_per_index + 1;
2365       end if;
2366       If (C_pos_seg_rec.application_column_name = 'SEGMENT5') then
2367 	 possegs(5) := segs(l_per_index);
2368 	 l_per_index := l_per_index + 1;
2369       end if;
2370       If (C_pos_seg_rec.application_column_name = 'SEGMENT6') then
2371 	 possegs(6) := segs(l_per_index);
2372 	 l_per_index := l_per_index + 1;
2373       end if;
2374       If (C_pos_seg_rec.application_column_name = 'SEGMENT7') then
2375 	 possegs(7) := segs(l_per_index);
2376 	 l_per_index := l_per_index + 1;
2377       end if;
2378       If (C_pos_seg_rec.application_column_name = 'SEGMENT8') then
2379 	 possegs(8) := segs(l_per_index);
2380 	 l_per_index := l_per_index + 1;
2381       end if;
2382       If (C_pos_seg_rec.application_column_name = 'SEGMENT9') then
2383 	 possegs(9) := segs(l_per_index);
2384 	 l_per_index := l_per_index + 1;
2385       end if;
2386       If (C_pos_seg_rec.application_column_name = 'SEGMENT10') then
2387 	 possegs(10) := segs(l_per_index);
2388 	 l_per_index := l_per_index + 1;
2389       end if;
2390       If (C_pos_seg_rec.application_column_name = 'SEGMENT11') then
2391 	 possegs(11) := segs(l_per_index);
2392 	 l_per_index := l_per_index + 1;
2393       end if;
2394       If (C_pos_seg_rec.application_column_name = 'SEGMENT12') then
2395 	 possegs(12) := segs(l_per_index);
2396 	 l_per_index := l_per_index + 1;
2397       end if;
2398       If (C_pos_seg_rec.application_column_name = 'SEGMENT13') then
2399 	 possegs(13) := segs(l_per_index);
2400 	 l_per_index := l_per_index + 1;
2401       end if;
2402       If (C_pos_seg_rec.application_column_name = 'SEGMENT14') then
2403 	 possegs(14) := segs(l_per_index);
2404 	 l_per_index := l_per_index + 1;
2405       end if;
2406       If (C_pos_seg_rec.application_column_name = 'SEGMENT15') then
2407 	 possegs(15) := segs(l_per_index);
2408 	 l_per_index := l_per_index + 1;
2409       end if;
2410       If (C_pos_seg_rec.application_column_name = 'SEGMENT16') then
2411 	 possegs(16) := segs(l_per_index);
2412 	 l_per_index := l_per_index + 1;
2413       end if;
2414       If (C_pos_seg_rec.application_column_name = 'SEGMENT17') then
2415 	 possegs(17) := segs(l_per_index);
2416 	 l_per_index := l_per_index + 1;
2417       end if;
2418       If (C_pos_seg_rec.application_column_name = 'SEGMENT18') then
2419 	 possegs(18) := segs(l_per_index);
2420 	 l_per_index := l_per_index + 1;
2421       end if;
2422       If (C_pos_seg_rec.application_column_name = 'SEGMENT19') then
2423 	 possegs(19) := segs(l_per_index);
2424 	 l_per_index := l_per_index + 1;
2425       end if;
2426       If (C_pos_seg_rec.application_column_name = 'SEGMENT20') then
2427 	 possegs(20) := segs(l_per_index);
2428 	 l_per_index := l_per_index + 1;
2429       end if;
2430       If (C_pos_seg_rec.application_column_name = 'SEGMENT21') then
2431 	 possegs(21) := segs(l_per_index);
2432 	 l_per_index := l_per_index + 1;
2433       end if;
2434       If (C_pos_seg_rec.application_column_name = 'SEGMENT22') then
2435 	 possegs(22) := segs(l_per_index);
2436 	 l_per_index := l_per_index + 1;
2437       end if;
2438       If (C_pos_seg_rec.application_column_name = 'SEGMENT23') then
2439 	 possegs(23) := segs(l_per_index);
2440 	 l_per_index := l_per_index + 1;
2441       end if;
2442       If (C_pos_seg_rec.application_column_name = 'SEGMENT24') then
2443 	 possegs(24) := segs(l_per_index);
2444 	 l_per_index := l_per_index + 1;
2445       end if;
2446       If (C_pos_seg_rec.application_column_name = 'SEGMENT25') then
2447 	 possegs(25) := segs(l_per_index);
2448 	 l_per_index := l_per_index + 1;
2449       end if;
2450       If (C_pos_seg_rec.application_column_name = 'SEGMENT26') then
2451 	 possegs(26) := segs(l_per_index);
2452 	 l_per_index := l_per_index + 1;
2453       end if;
2454       If (C_pos_seg_rec.application_column_name = 'SEGMENT27') then
2455 	 possegs(27) := segs(l_per_index);
2456 	 l_per_index := l_per_index + 1;
2457       end if;
2458       If (C_pos_seg_rec.application_column_name = 'SEGMENT28') then
2459 	 possegs(28) := segs(l_per_index);
2460 	 l_per_index := l_per_index + 1;
2461       end if;
2462       If (C_pos_seg_rec.application_column_name = 'SEGMENT29') then
2463 	 possegs(29) := segs(l_per_index);
2464 	 l_per_index := l_per_index + 1;
2465       end if;
2466       If (C_pos_seg_rec.application_column_name = 'SEGMENT30') then
2467 	 possegs(30) := segs(l_per_index);
2468 	 l_per_index := l_per_index + 1;
2469       end if;
2470 
2471      End Loop;
2472     /*For Bug No : 2602027 End*/
2473 
2474    For k in 1..30
2475    Loop
2476       isegs(k) := null;
2477    End Loop;
2478 
2479    l_pos_index := 0;
2480 
2481    FOR C_flex_rec in
2482    (
2483 	Select application_column_name
2484 	FROM   fnd_id_flex_segments_vl
2485 	WHERE  id_flex_code = 'BPS'
2486 	AND    id_flex_num  = l_position_id_flex_num
2487 	AND    enabled_flag = 'Y'
2488 	ORDER  BY segment_num
2489    )
2490    LOOP
2491 	l_pos_index := l_pos_index + 1;
2492 	isegs(l_pos_index) := NULL;
2493 
2494 	IF (C_flex_rec.application_column_name = 'SEGMENT1') THEN
2495 	    isegs(l_pos_index)   := possegs(1);
2496 	END IF;
2497 	IF (C_flex_rec.application_column_name = 'SEGMENT2') THEN
2498 	    isegs(l_pos_index)   := possegs(2);
2499 	END IF;
2500 	IF (C_flex_rec.application_column_name = 'SEGMENT3') THEN
2501 	    isegs(l_pos_index)   := possegs(3);
2502 	END IF;
2503 	IF (C_flex_rec.application_column_name = 'SEGMENT4') THEN
2504 	    isegs(l_pos_index)   := possegs(4);
2505 	END IF;
2506 	IF (C_flex_rec.application_column_name = 'SEGMENT5') THEN
2507 	    isegs(l_pos_index)   := possegs(5);
2508 	END IF;
2509 	IF (C_flex_rec.application_column_name = 'SEGMENT6') THEN
2510 	    isegs(l_pos_index)   := possegs(6);
2511 	END IF;
2512 	IF (C_flex_rec.application_column_name = 'SEGMENT7') THEN
2513 	    isegs(l_pos_index)   := possegs(7);
2514 	END IF;
2515 	IF (C_flex_rec.application_column_name = 'SEGMENT8') THEN
2516 	    isegs(l_pos_index)   := possegs(8);
2517 	END IF;
2518 	IF (C_flex_rec.application_column_name = 'SEGMENT9') THEN
2519 	    isegs(l_pos_index)   := possegs(9);
2520 	END IF;
2521 	IF (C_flex_rec.application_column_name = 'SEGMENT10') THEN
2522 	    isegs(l_pos_index)   := possegs(10);
2523 	END IF;
2524 	IF (C_flex_rec.application_column_name = 'SEGMENT11') THEN
2525 	    isegs(l_pos_index)   := possegs(11);
2526 	END IF;
2527 	IF (C_flex_rec.application_column_name = 'SEGMENT12') THEN
2528 	    isegs(l_pos_index)   := possegs(12);
2529 	END IF;
2530 	IF (C_flex_rec.application_column_name = 'SEGMENT13') THEN
2531 	    isegs(l_pos_index)   := possegs(13);
2532 	END IF;
2533 	IF (C_flex_rec.application_column_name = 'SEGMENT14') THEN
2534 	    isegs(l_pos_index)   := possegs(14);
2535 	END IF;
2536 	IF (C_flex_rec.application_column_name = 'SEGMENT15') THEN
2537 	    isegs(l_pos_index)   := possegs(15);
2538 	END IF;
2539 	IF (C_flex_rec.application_column_name = 'SEGMENT16') THEN
2540 	    isegs(l_pos_index)   := possegs(16);
2541 	END IF;
2542 	IF (C_flex_rec.application_column_name = 'SEGMENT17') THEN
2543 	    isegs(l_pos_index)   := possegs(17);
2544 	END IF;
2545 	IF (C_flex_rec.application_column_name = 'SEGMENT18') THEN
2546 	    isegs(l_pos_index)   := possegs(18);
2547 	END IF;
2548 	IF (C_flex_rec.application_column_name = 'SEGMENT19') THEN
2549 	    isegs(l_pos_index)   := possegs(19);
2550 	END IF;
2551 	IF (C_flex_rec.application_column_name = 'SEGMENT20') THEN
2552 	    isegs(l_pos_index)   := possegs(20);
2553 	END IF;
2554 	IF (C_flex_rec.application_column_name = 'SEGMENT21') THEN
2555 	    isegs(l_pos_index)   := possegs(21);
2556 	END IF;
2557 	IF (C_flex_rec.application_column_name = 'SEGMENT22') THEN
2558 	    isegs(l_pos_index)   := possegs(22);
2559 	END IF;
2560 	IF (C_flex_rec.application_column_name = 'SEGMENT23') THEN
2561 	    isegs(l_pos_index)   := possegs(23);
2562 	END IF;
2563 	IF (C_flex_rec.application_column_name = 'SEGMENT24') THEN
2564 	    isegs(l_pos_index)   := possegs(24);
2565 	END IF;
2566 	IF (C_flex_rec.application_column_name = 'SEGMENT25') THEN
2567 	    isegs(l_pos_index)   := possegs(25);
2568 	END IF;
2569 	IF (C_flex_rec.application_column_name = 'SEGMENT26') THEN
2570 	    isegs(l_pos_index)   := possegs(26);
2571 	END IF;
2572 	IF (C_flex_rec.application_column_name = 'SEGMENT27') THEN
2573 	    isegs(l_pos_index)   := possegs(27);
2574 	END IF;
2575 	IF (C_flex_rec.application_column_name = 'SEGMENT28') THEN
2576 	    isegs(l_pos_index)   := possegs(28);
2577 	END IF;
2578 	IF (C_flex_rec.application_column_name = 'SEGMENT29') THEN
2579 	    isegs(l_pos_index)   := possegs(29);
2580 	END IF;
2581 	IF (C_flex_rec.application_column_name = 'SEGMENT30') THEN
2582 	    isegs(l_pos_index)   := possegs(30);
2583 	END IF;
2584 
2585       END LOOP; -- END LOOP ( C_flex_rec in C_flex )
2586 
2587    l_msg := null;
2588    if not fnd_flex_ext.Get_combination_id
2589 	  ( application_short_name => 'PSB',
2590 	    key_flex_code => 'BPS',
2591 	    structure_number => l_position_id_flex_num,
2592 	    validation_date => sysdate,
2593 	    n_segments => l_pos_index,
2594 	    segments => isegs,
2595 	    combination_id => l_ccid)
2596    then
2597       l_msg := FND_MESSAGE.get;
2598       FND_MSG_PUB.Add;
2599       FND_MESSAGE.SET_NAME('PSB', 'PSB_INCREMENTAL_CCID_FAILURE');
2600       FND_MESSAGE.SET_TOKEN('ERRMESG',l_msg);
2601       hr_utility.set_location('error in get combination id',9867);
2602       RAISE FND_API.G_EXC_ERROR;
2603    end if;
2604 
2605    l_concat_pos_name := null;
2606    l_concat_pos_name := FND_FLEX_EXT.Get_Segs
2607 			(application_short_name => 'PSB',
2608 			 key_flex_code => 'BPS',
2609 			 structure_number => l_position_id_flex_num,
2610 			 combination_id => l_ccid);
2611 
2612   hr_utility.set_location('>> l_ccid '|| l_ccid,777);
2613 
2614   --++ end restructure
2615 
2616   PSB_POSITIONS_PVT.UPDATE_ROW
2617 	  (
2618 	    p_api_version            => 1.0,
2619 	    p_init_msg_lISt          => FND_API.G_FALSE,
2620 	    p_commit                 => FND_API.G_FALSE,
2621 	    p_validation_level       => FND_API.G_VALID_LEVEL_FULL,
2622 	    p_return_status          => l_return_status,
2623 	    p_msg_count              => l_msg_count,
2624 	    p_msg_data               => l_msg_data,
2625 	    p_position_id            => l_psb_position_id,
2626             -- de by org
2627             p_organization_id        => l_organization_id,
2628 	    p_data_extract_id        => c_pos_trx_rec.data_extract_id,
2629 	    p_position_definition_id => l_ccid,
2630 	    p_hr_position_id         => p_position_id,
2631 	    p_hr_employee_id         => c_pos_trx_rec.hr_employee_id,
2632 	    p_business_group_id      => p_business_group_id,
2633 	    p_effective_start_DATE   => p_effective_date,
2634 	    p_effective_END_DATE     => p_date_end,
2635 	    p_set_of_books_id        => c_pos_trx_rec.set_of_books_id,
2636 	    p_vacant_position_flag   => c_pos_trx_rec.vacant_position_flag,
2637 	    p_availability_status    => l_availability_status,
2638 	    p_transaction_id         => p_position_transaction_id,
2639 	    p_transaction_status     => p_transaction_status,
2640 	    p_new_position_flag      => c_pos_trx_rec.new_position_flag ,
2641 	    p_attribute1             => NULL,
2642 	    p_attribute2             => NULL,
2643 	    p_attribute3             => NULL,
2644 	    p_attribute4             => NULL,
2645 	    p_attribute5             => NULL,
2646 	    p_attribute6             => NULL,
2647 	    p_attribute7             => NULL,
2648 	    p_attribute8             => NULL,
2649 	    p_attribute9             => NULL,
2650 	    p_attribute10            => NULL,
2651 	    p_attribute11            => NULL,
2652 	    p_attribute12            => NULL,
2653 	    p_attribute13            => NULL,
2654 	    p_attribute14            => NULL,
2655 	    p_attribute15            => NULL,
2656 	    p_attribute16            => NULL,
2657 	    p_attribute17            => NULL,
2658 	    p_attribute18            => NULL,
2659 	    p_attribute19            => NULL,
2660 	    p_attribute20            => NULL,
2661 	    p_attribute_category     => NULL,
2662 	    p_name                   => l_concat_pos_name,
2663 	    p_mode                   => 'R'
2664 	  );
2665 
2666    --++ update name and hr_position_id; when applied hr_position_id is set
2667    --++ to hr's position id
2668 
2669    IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2670       FND_MESSAGE.SET_NAME('PSB', 'PSB_PQH_UPDATE_FAILURE'  );
2671 
2672       RAISE FND_API.G_EXC_ERROR;
2673    END IF;
2674 
2675    IF (p_transaction_status <>  'APPLIED') then
2676 
2677    hr_utility.set_location('>> DELETING records to recreate .... ' ,1777);
2678    Delete psb_position_assignments
2679     where position_id = l_psb_position_id;
2680 
2681    Populate_Salary_Assignments
2682      ( p_return_status   =>  l_return_status,
2683        p_position_id     =>  l_psb_position_id,
2684        p_date_effective  =>  p_date_effective,
2685        p_date_end        =>  p_date_end,
2686        p_data_extract_id =>  c_pos_trx_rec.data_extract_id,
2687        p_business_group_id => p_business_group_id,
2688        p_set_of_books_id   =>  l_set_of_books_id,
2689        p_entry_grade_rule_id  => p_entry_grade_rule_id,
2690        p_entry_step_id   => p_entry_step_id,
2691        p_entry_grade_id  => p_entry_grade_id,
2692        p_pay_basis_id    => p_pay_basis_id_o);
2693 
2694    if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2695       FND_MESSAGE.SET_NAME('PSB', 'PSB_INCREMENTAL_SALARY_FAILURE'  );
2696 
2697       RAISE FND_API.G_EXC_ERROR;
2698    end if;
2699 
2700    Populate_Attribute_Assignments
2701    ( p_return_status            =>  l_return_status,
2702      p_new_position_id          =>  l_psb_position_id,
2703      p_position_transaction_id  =>  p_position_transaction_id,
2704      p_job_id                   =>  p_job_id,
2705      p_organization_id          =>  p_organization_id,
2706      p_fte                      =>  p_fte,
2707      p_frequency                =>  p_frequency,
2708      p_working_hours            =>  p_working_hours,
2709      p_earliest_hire_date       =>  p_earliest_hire_date,
2710      p_entry_grade_id           =>  p_entry_grade_id,
2711      p_date_effective           =>  p_date_effective,
2712      p_date_end                 =>  p_date_end,
2713      p_data_extract_id          =>  c_pos_trx_rec.data_extract_id,
2714      p_business_group_id        =>  p_business_group_id);
2715 
2716    if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2717      FND_MESSAGE.SET_NAME('PSB', 'PSB_INCREMENTAL_ATTRIBUTE_FAIL'  );
2718      RAISE FND_API.G_EXC_ERROR;
2719    end if;
2720 
2721    end if; --end of p_transaction_status <> applied
2722 
2723    End Loop;
2724 
2725   end if;
2726   --++ end process of modification
2727 
2728   --++ R e j e c t   process
2729 
2730   hr_utility.set_location('>> ....1 continue .... ' ,1777);
2731 
2732   /*For Bug No : 2738939 Start*/
2733   --included the TERMINATE also in the following check
2734   if (p_transaction_status in ('REJECT','TERMINATE'))
2735   then
2736   /*For Bug No : 2738939 End*/
2737     hr_utility.set_location('>> '||p_transaction_status ,1777);
2738     hr_utility.set_location('>> p_position_transaction_id' || p_position_transaction_id,777);
2739     For C_pos_trx_rec in C_pos_trx
2740     Loop
2741       l_psb_position_id := C_pos_trx_rec.position_id;
2742       hr_utility.set_location('>> l_psb_position_id '|| l_psb_position_id,1777);
2743     End Loop;
2744 
2745    if l_psb_position_id is not null then
2746     For c_ws_positions_rec in c_ws_positions loop
2747 
2748       PSB_WORKSHEET.Delete_WPL
2749 	 (p_api_version => 1.0,
2750 	  p_return_status => l_return_status,
2751 	  p_worksheet_id => c_ws_positions_rec.worksheet_id,
2752 	  p_position_line_id => c_ws_positions_rec.position_line_id);
2753 
2754     end loop;
2755 
2756     For c_br_positions_rec in c_br_positions loop
2757 
2758       PSB_BUDGET_REVISIONS_PVT.Delete_Revision_Positions
2759 	 (p_api_version => 1.0,
2760 	  p_return_status => l_return_status,
2761 	  p_msg_count => l_msg_count,
2762 	  p_msg_data => l_msg_data,
2763 	  p_budget_revision_id => c_br_positions_rec.budget_revision_id,
2764 	  p_budget_revision_pos_line_id => c_br_positions_rec.budget_revision_pos_line_id);
2765 
2766     end loop;
2767 
2768     delete from psb_position_assignments
2769     where position_id = l_psb_position_id;
2770 
2771     if sql%notfound then
2772        null;
2773     end if;
2774 
2775     PSB_POSITIONS_PVT.DELETE_ROW
2776     (
2777      p_api_version            => 1.0,
2778      p_init_msg_liSt          => FND_API.G_FALSE,
2779      p_commit                 => FND_API.G_FALSE,
2780      p_validation_level       => FND_API.G_VALID_LEVEL_FULL,
2781      p_return_status          => l_return_status,
2782      p_msg_count              => l_msg_count,
2783      p_msg_data               => l_msg_data,
2784      p_position_id            => l_psb_position_id);
2785 
2786     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2787        hr_utility.set_location('>> pos delete row Error ' ,1777);
2788        RAISE FND_API.G_EXC_ERROR;
2789     END IF;
2790    end if; -- end of rejecct
2791 
2792   end if; -- end of application_id test
2793   end if; -- end of test l_trn_exist (a)
2794   --hr_utility.trace_off;
2795 
2796 EXCEPTION
2797   --
2798   WHEN OTHERS THEN
2799     Process_Exception( l_api_name ) ;
2800   --
2801 END Update_Position_Txn_Info;
2802 /*---------------------------------------------------------------------------*/
2803 
2804 
2805 /*===========================================================================+
2806  |                      PROCEDURE Insert_Position_Info                       |
2807  +===========================================================================*/
2808 PROCEDURE Insert_Position_Info
2809 (p_position_id                in NUMBER ,
2810  p_effective_start_date       in DATE   ,
2811  p_effective_end_date         in DATE   ,
2812  p_availability_status_id     in NUMBER ,
2813  p_business_group_id          in NUMBER ,
2814  p_entry_step_id              in NUMBER ,
2815  p_entry_grade_rule_id        in NUMBER ,
2816  p_job_id                     in NUMBER ,
2817  p_location_id                in NUMBER ,
2818  p_organization_id            in NUMBER ,
2819  p_position_definition_id     in NUMBER ,
2820  p_position_transaction_id    in NUMBER ,
2821  p_entry_grade_id             in NUMBER ,
2822  p_bargaining_unit_cd         in VARCHAR2 ,
2823  p_date_effective             in DATE   ,
2824  p_date_end                   in DATE   ,
2825  p_earliest_hire_date         in DATE   ,
2826  p_fill_by_date               in DATE   ,
2827  p_frequency                  in VARCHAR2  ,
2828  p_working_hours              in NUMBER ,
2829  p_fte                        in NUMBER    ,
2830  p_name                       in VARCHAR2  ,
2831  p_position_type              in VARCHAR2  ,
2832  p_pay_basis_id               in NUMBER    ,
2833  p_object_version_number      in NUMBER
2834 )
2835 IS
2836   --
2837   l_api_name            CONSTANT VARCHAR2(30)   := 'Insert_Position_Info';
2838   l_api_version         CONSTANT NUMBER         := 1.0;
2839   --
2840   l_rowid               varchar2(100);
2841   l_vacant_position_flag varchar2(1);
2842   l_date_end            date := to_date(null);
2843   l_data_extract_id     number := 0;
2844   l_validity_date       date := null;
2845   l_set_of_books_id     NUMBER;
2846   l_position_id_flex_num  number;
2847   segs                  FND_FLEX_EXT.SegmentArray;
2848   isegs                 FND_FLEX_EXT.SegmentArray;
2849   l_init_index          BINARY_INTEGER;
2850   l_pos_index           BINARY_INTEGER;
2851   l_ccid                NUMBER;
2852   l_position_id         NUMBER;
2853   l_concat_pos_name     varchar2(240);
2854   l_availability_status varchar2(30);
2855 
2856   /*For Bug No : 2602027 Start*/
2857   l_pos_id_flex_num     number;
2858   l_per_index           BINARY_INTEGER;
2859   tf                    BOOLEAN;
2860   nsegs                 NUMBER;
2861   possegs               FND_FLEX_EXT.SegmentArray;
2862   /*For Bug No : 2602027 End*/
2863 
2864   l_return_status          varchar2(1);
2865   l_msg_count              number;
2866   l_msg_data               varchar2(1000);
2867   l_msg                    varchar2(2000);
2868 
2869   Cursor C_avail_status is
2870    /*For Bug No : 1527423 Start*/
2871   --SELECT shared_type_name
2872     SELECT system_type_cd
2873    /*For Bug No : 1527423 End*/
2874       FROM per_shared_types
2875      WHERE lookup_type = 'POSITION_AVAILABILITY_STATUS'
2876        AND shared_type_id = p_availability_status_id;
2877 
2878   Cursor C_data_extract is
2879     SELECT business_group_id,
2880 	   set_of_books_id,
2881 	   position_id_flex_num,
2882 	   req_data_as_of_date
2883       FROM psb_data_extracts
2884      WHERE data_extract_id = l_data_extract_id;
2885 
2886   /*For Bug No : 2602027 Start*/
2887   Cursor C_flex_num is
2888 	select position_structure
2889 	  from per_business_groups
2890 	 where business_group_id = p_business_group_id;
2891 
2892   Cursor C_pos_segs is
2893     select application_column_name
2894       from fnd_id_flex_segments_vl
2895      where id_flex_code = 'POS'
2896        and id_flex_num = l_pos_id_flex_num
2897        and enabled_flag = 'Y'
2898     order by segment_num;
2899   /*For Bug No : 2602027 End*/
2900 
2901 Begin
2902 
2903 /* For Bug No : 2739450 Start*/
2904 IF (p_position_transaction_id IS NULL) THEN
2905 /*For Bug No. 2739450 End*/
2906   --hr_utility.trace_on;
2907    hr_utility.set_location(' Start Insert Position',777);
2908 
2909    hr_utility.set_location(' position_id '||p_position_id,881);
2910    hr_utility.set_location(' effective_start_date'||p_effective_start_date,881);
2911    hr_utility.set_location(' effective_end  _date '||p_effective_end_date,881);
2912    hr_utility.set_location(' availability stat '||p_availability_status_id,881);
2913    hr_utility.set_location(' business group stat '||p_business_group_id,881);
2914    hr_utility.set_location(' entry step id '||p_entry_step_id,881);
2915    hr_utility.set_location(' entry grade rule id '||p_entry_grade_rule_id,881);
2916    hr_utility.set_location(' entry job id '||p_job_id,881);
2917    hr_utility.set_location(' entry location id '||p_location_id,881);
2918    hr_utility.set_location(' entry org id '||p_organization_id,881);
2919    hr_utility.set_location(' pos definitio'||p_position_definition_id,881);
2920    hr_utility.set_location(' pos trans id'||p_position_transaction_id,881);
2921    hr_utility.set_location(' entry grage id'||p_entry_grade_id,881);
2922    hr_utility.set_location(' barganingin  d'||p_bargaining_unit_cd,881);
2923    hr_utility.set_location(' date eff   '||p_date_effective,881);
2924    hr_utility.set_location(' date end   '||p_date_end,881);
2925    hr_utility.set_location(' earliest hire date '||p_earliest_hire_date,881);
2926    hr_utility.set_location(' earliest fill date '||p_fill_by_date,881);
2927    hr_utility.set_location(' frequency '||p_frequency,881);
2928    hr_utility.set_location(' working hours '||p_working_hours,881);
2929    hr_utility.set_location(' fte '||p_fte,881);
2930    hr_utility.set_location(' name '||p_name,881);
2931    hr_utility.set_location(' position type '||p_position_type,881);
2932    hr_utility.set_location(' pay basis '||p_pay_basis_id,881);
2933    hr_utility.set_location(' object version # '||p_object_version_number,881);
2934    hr_utility.set_location(' applid >> '||get_global('G_PSB_APPLICATION_ID'),881);
2935    hr_utility.set_location(' revS   >> '||get_global('G_PSB_REVISION_START_DATE'),881);
2936    hr_utility.set_location(' revE   >> '||get_global('G_PSB_REVISION_END_DATE'),881);
2937 
2938    ---++++  start of code
2939 
2940    if (get_global('G_PSB_APPLICATION_ID') = 8401) then
2941 
2942    if (p_date_end = to_date('31124712','DDMMYYYY')) then
2943        l_date_end := to_date(null);
2944    else
2945        l_date_end := p_date_end;
2946    end if;
2947 
2948    l_data_extract_id := get_global('G_PSB_DATA_EXTRACT_ID');
2949    hr_utility.set_location(' Extract Id'||l_data_extract_id,881);
2950 
2951    For C_data_extract_rec in C_data_extract
2952    Loop
2953       l_set_of_books_id := C_data_extract_rec.set_of_books_id;
2954       l_position_id_flex_num := C_data_extract_rec.position_id_flex_num;
2955       --l_validity_date := C_data_extract_rec.req_data_as_of_date;
2956    End Loop;
2957 
2958    hr_utility.set_location(' Validity Date '||l_validity_date,881);
2959    hr_utility.set_location(' After Validity Date '||l_validity_date,881);
2960 
2961   /*For Bug No : 2602027 Start*/
2962   For C_flex_rec in C_flex_num
2963   Loop
2964     l_pos_id_flex_num := C_flex_rec.position_structure;
2965   End Loop;
2966 
2967   tf := FND_FLEX_EXT.GET_SEGMENTS('PER', 'POS', l_pos_id_flex_num, p_position_definition_id, nsegs, segs);
2968   if (tf = FALSE) then
2969 	l_msg := FND_MESSAGE.Get;
2970 	FND_MESSAGE.SET_NAME('PSB','PSB_POS_DEFN_VALUE_ERROR');
2971 	FND_MESSAGE.SET_TOKEN('POSITION_NAME',p_name );
2972 	FND_MESSAGE.SET_TOKEN('ERR_MESG',l_msg);
2973 	FND_MSG_PUB.Add;
2974         hr_utility.set_location('error in get segments',9850);
2975 	RAISE FND_API.G_EXC_ERROR;
2976   end if;
2977 
2978   l_per_index := 1;
2979   l_init_index := 0;
2980   For k in 1..30
2981   Loop
2982    possegs(k) := null;
2983   End Loop;
2984 
2985   For C_pos_seg_rec in C_pos_segs
2986   Loop
2987       l_init_index := l_init_index + 1;
2988 
2989       If (C_pos_seg_rec.application_column_name = 'SEGMENT1') then
2990 	 possegs(1) := segs(l_per_index);
2991 	 l_per_index := l_per_index + 1;
2992       end if;
2993       If (C_pos_seg_rec.application_column_name = 'SEGMENT2') then
2994 	 possegs(2) := segs(l_per_index);
2995 	 l_per_index := l_per_index + 1;
2996       end if;
2997       If (C_pos_seg_rec.application_column_name = 'SEGMENT3') then
2998 	 possegs(3) := segs(l_per_index);
2999 	 l_per_index := l_per_index + 1;
3000       end if;
3001       If (C_pos_seg_rec.application_column_name = 'SEGMENT4') then
3002 	 possegs(4) := segs(l_per_index);
3003 	 l_per_index := l_per_index + 1;
3004       end if;
3005       If (C_pos_seg_rec.application_column_name = 'SEGMENT5') then
3006 	 possegs(5) := segs(l_per_index);
3007 	 l_per_index := l_per_index + 1;
3008       end if;
3009       If (C_pos_seg_rec.application_column_name = 'SEGMENT6') then
3010 	 possegs(6) := segs(l_per_index);
3011 	 l_per_index := l_per_index + 1;
3012       end if;
3013       If (C_pos_seg_rec.application_column_name = 'SEGMENT7') then
3014 	 possegs(7) := segs(l_per_index);
3015 	 l_per_index := l_per_index + 1;
3016       end if;
3017       If (C_pos_seg_rec.application_column_name = 'SEGMENT8') then
3018 	 possegs(8) := segs(l_per_index);
3019 	 l_per_index := l_per_index + 1;
3020       end if;
3021       If (C_pos_seg_rec.application_column_name = 'SEGMENT9') then
3022 	 possegs(9) := segs(l_per_index);
3023 	 l_per_index := l_per_index + 1;
3024       end if;
3025       If (C_pos_seg_rec.application_column_name = 'SEGMENT10') then
3026 	 possegs(10) := segs(l_per_index);
3027 	 l_per_index := l_per_index + 1;
3028       end if;
3029       If (C_pos_seg_rec.application_column_name = 'SEGMENT11') then
3030 	 possegs(11) := segs(l_per_index);
3031 	 l_per_index := l_per_index + 1;
3032       end if;
3033       If (C_pos_seg_rec.application_column_name = 'SEGMENT12') then
3034 	 possegs(12) := segs(l_per_index);
3035 	 l_per_index := l_per_index + 1;
3036       end if;
3037       If (C_pos_seg_rec.application_column_name = 'SEGMENT13') then
3038 	 possegs(13) := segs(l_per_index);
3039       end if;
3040       If (C_pos_seg_rec.application_column_name = 'SEGMENT14') then
3041 	 possegs(14) := segs(l_per_index);
3042 	 l_per_index := l_per_index + 1;
3043       end if;
3044       If (C_pos_seg_rec.application_column_name = 'SEGMENT15') then
3045 	 possegs(15) := segs(l_per_index);
3046 	 l_per_index := l_per_index + 1;
3047       end if;
3048       If (C_pos_seg_rec.application_column_name = 'SEGMENT16') then
3049 	 possegs(16) := segs(l_per_index);
3050 	 l_per_index := l_per_index + 1;
3051       end if;
3052       If (C_pos_seg_rec.application_column_name = 'SEGMENT17') then
3053 	 possegs(17) := segs(l_per_index);
3054 	 l_per_index := l_per_index + 1;
3055       end if;
3056       If (C_pos_seg_rec.application_column_name = 'SEGMENT18') then
3057 	 possegs(18) := segs(l_per_index);
3058 	 l_per_index := l_per_index + 1;
3059       end if;
3060       If (C_pos_seg_rec.application_column_name = 'SEGMENT19') then
3061 	 possegs(19) := segs(l_per_index);
3062 	 l_per_index := l_per_index + 1;
3063       end if;
3064       If (C_pos_seg_rec.application_column_name = 'SEGMENT20') then
3065 	 possegs(20) := segs(l_per_index);
3066 	 l_per_index := l_per_index + 1;
3067       end if;
3068       If (C_pos_seg_rec.application_column_name = 'SEGMENT21') then
3069 	 possegs(21) := segs(l_per_index);
3070 	 l_per_index := l_per_index + 1;
3071       end if;
3072       If (C_pos_seg_rec.application_column_name = 'SEGMENT22') then
3073 	 possegs(22) := segs(l_per_index);
3074 	 l_per_index := l_per_index + 1;
3075       end if;
3076       If (C_pos_seg_rec.application_column_name = 'SEGMENT23') then
3077 	 possegs(23) := segs(l_per_index);
3078 	 l_per_index := l_per_index + 1;
3079       end if;
3080       If (C_pos_seg_rec.application_column_name = 'SEGMENT24') then
3081 	 possegs(24) := segs(l_per_index);
3082 	 l_per_index := l_per_index + 1;
3083       end if;
3084       If (C_pos_seg_rec.application_column_name = 'SEGMENT25') then
3085 	 possegs(25) := segs(l_per_index);
3086 	 l_per_index := l_per_index + 1;
3087       end if;
3088       If (C_pos_seg_rec.application_column_name = 'SEGMENT26') then
3089 	 possegs(26) := segs(l_per_index);
3090 	 l_per_index := l_per_index + 1;
3091       end if;
3092       If (C_pos_seg_rec.application_column_name = 'SEGMENT27') then
3093 	 possegs(27) := segs(l_per_index);
3094 	 l_per_index := l_per_index + 1;
3095       end if;
3096       If (C_pos_seg_rec.application_column_name = 'SEGMENT28') then
3097 	 possegs(28) := segs(l_per_index);
3098 	 l_per_index := l_per_index + 1;
3099       end if;
3100       If (C_pos_seg_rec.application_column_name = 'SEGMENT29') then
3101 	 possegs(29) := segs(l_per_index);
3102 	 l_per_index := l_per_index + 1;
3103       end if;
3104       If (C_pos_seg_rec.application_column_name = 'SEGMENT30') then
3105 	 possegs(30) := segs(l_per_index);
3106 	 l_per_index := l_per_index + 1;
3107       end if;
3108 
3109    End Loop;
3110   /*For Bug No : 2602027 End*/
3111 
3112    For k in 1..30
3113    Loop
3114       isegs(k) := null;
3115    End Loop;
3116 
3117    l_pos_index := 0;
3118 
3119    FOR C_flex_rec in
3120    (
3121 	Select application_column_name
3122 	FROM   fnd_id_flex_segments_vl
3123 	WHERE  id_flex_code = 'BPS'
3124 	AND    id_flex_num  = l_position_id_flex_num
3125 	AND    enabled_flag = 'Y'
3126 	ORDER  BY segment_num
3127    )
3128    LOOP
3129 	l_pos_index := l_pos_index + 1;
3130 	isegs(l_pos_index) := NULL;
3131 
3132 	IF (C_flex_rec.application_column_name = 'SEGMENT1') THEN
3133 	    isegs(l_pos_index)   := possegs(1);
3134 	END IF;
3135 	IF (C_flex_rec.application_column_name = 'SEGMENT2') THEN
3136 	    isegs(l_pos_index)   := possegs(2);
3137 	END IF;
3138 	IF (C_flex_rec.application_column_name = 'SEGMENT3') THEN
3139 	    isegs(l_pos_index)   := possegs(3);
3140 	END IF;
3141 	IF (C_flex_rec.application_column_name = 'SEGMENT4') THEN
3142 	    isegs(l_pos_index)   := possegs(4);
3143 	END IF;
3144 	IF (C_flex_rec.application_column_name = 'SEGMENT5') THEN
3145 	    isegs(l_pos_index)   := possegs(5);
3146 	END IF;
3147 	IF (C_flex_rec.application_column_name = 'SEGMENT6') THEN
3148 	    isegs(l_pos_index)   := possegs(6);
3149 	END IF;
3150 	IF (C_flex_rec.application_column_name = 'SEGMENT7') THEN
3151 	    isegs(l_pos_index)   := possegs(7);
3152 	END IF;
3153 	IF (C_flex_rec.application_column_name = 'SEGMENT8') THEN
3154 	    isegs(l_pos_index)   := possegs(8);
3155 	END IF;
3156 	IF (C_flex_rec.application_column_name = 'SEGMENT9') THEN
3157 	    isegs(l_pos_index)   := possegs(9);
3158 	END IF;
3159 	IF (C_flex_rec.application_column_name = 'SEGMENT10') THEN
3160 	    isegs(l_pos_index)   := possegs(10);
3161 	END IF;
3162 	IF (C_flex_rec.application_column_name = 'SEGMENT11') THEN
3163 	    isegs(l_pos_index)   := possegs(11);
3164 	END IF;
3165 	IF (C_flex_rec.application_column_name = 'SEGMENT12') THEN
3166 	    isegs(l_pos_index)   := possegs(12);
3167 	END IF;
3168 	IF (C_flex_rec.application_column_name = 'SEGMENT13') THEN
3169 	    isegs(l_pos_index)   := possegs(13);
3170 	END IF;
3171 	IF (C_flex_rec.application_column_name = 'SEGMENT14') THEN
3172 	    isegs(l_pos_index)   := possegs(14);
3173 	END IF;
3174 	IF (C_flex_rec.application_column_name = 'SEGMENT15') THEN
3175 	    isegs(l_pos_index)   := possegs(15);
3176 	END IF;
3177 	IF (C_flex_rec.application_column_name = 'SEGMENT16') THEN
3178 	    isegs(l_pos_index)   := possegs(16);
3179 	END IF;
3180 	IF (C_flex_rec.application_column_name = 'SEGMENT17') THEN
3181 	    isegs(l_pos_index)   := possegs(17);
3182 	END IF;
3183 	IF (C_flex_rec.application_column_name = 'SEGMENT18') THEN
3184 	    isegs(l_pos_index)   := possegs(18);
3185 	END IF;
3186 	IF (C_flex_rec.application_column_name = 'SEGMENT19') THEN
3187 	    isegs(l_pos_index)   := possegs(19);
3188 	END IF;
3189 	IF (C_flex_rec.application_column_name = 'SEGMENT20') THEN
3190 	    isegs(l_pos_index)   := possegs(20);
3191 	END IF;
3192 	IF (C_flex_rec.application_column_name = 'SEGMENT21') THEN
3193 	    isegs(l_pos_index)   := possegs(21);
3194 	END IF;
3195 	IF (C_flex_rec.application_column_name = 'SEGMENT22') THEN
3196 	    isegs(l_pos_index)   := possegs(22);
3197 	END IF;
3198 	IF (C_flex_rec.application_column_name = 'SEGMENT23') THEN
3199 	    isegs(l_pos_index)   := possegs(23);
3200 	END IF;
3201 	IF (C_flex_rec.application_column_name = 'SEGMENT24') THEN
3202 	    isegs(l_pos_index)   := possegs(24);
3203 	END IF;
3204 	IF (C_flex_rec.application_column_name = 'SEGMENT25') THEN
3205 	    isegs(l_pos_index)   := possegs(25);
3206 	END IF;
3207 	IF (C_flex_rec.application_column_name = 'SEGMENT26') THEN
3208 	    isegs(l_pos_index)   := possegs(26);
3209 	END IF;
3210 	IF (C_flex_rec.application_column_name = 'SEGMENT27') THEN
3211 	    isegs(l_pos_index)   := possegs(27);
3212 	END IF;
3213 	IF (C_flex_rec.application_column_name = 'SEGMENT28') THEN
3214 	    isegs(l_pos_index)   := possegs(28);
3215 	END IF;
3216 	IF (C_flex_rec.application_column_name = 'SEGMENT29') THEN
3217 	    isegs(l_pos_index)   := possegs(29);
3218 	END IF;
3219 	IF (C_flex_rec.application_column_name = 'SEGMENT30') THEN
3220 	    isegs(l_pos_index)   := possegs(30);
3221 	END IF;
3222 
3223       END LOOP; -- END LOOP ( C_flex_rec in C_flex )
3224 
3225    l_msg := null;
3226    if not fnd_flex_ext.Get_combination_id
3227 	  ( application_short_name => 'PSB',
3228 	    key_flex_code => 'BPS',
3229 	    structure_number => l_position_id_flex_num,
3230 	    validation_date => sysdate,
3231 	    n_segments => l_pos_index,
3232 	    segments => isegs,
3233 	    combination_id => l_ccid)
3234    then
3235       l_msg := FND_MESSAGE.get;
3236       FND_MSG_PUB.ADD;
3237       FND_MESSAGE.SET_NAME('PSB', 'PSB_INCREMENTAL_CCID_FAILURE');
3238       FND_MESSAGE.SET_TOKEN('ERRMESG',l_msg);
3239       hr_utility.set_location('error in get combination id',9867);
3240       RAISE FND_API.G_EXC_ERROR;
3241    end if;
3242 
3243    hr_utility.set_location('pos id flex num in '||
3244 		    l_position_id_flex_num || ' ccid ' || l_ccid ,9867);
3245 
3246    l_concat_pos_name := null;
3247    l_concat_pos_name := FND_FLEX_EXT.Get_Segs
3248 			(application_short_name => 'PSB',
3249 			 key_flex_code => 'BPS',
3250 			 structure_number => l_position_id_flex_num,
3251 			 combination_id => l_ccid);
3252 
3253    hr_utility.set_location('concat pos name is '|| l_concat_pos_name,9877);
3254 
3255    For C_avail_status_rec in C_avail_status
3256    Loop
3257      /*For Bug No 1527423 Start */
3258      --l_availability_status := C_avail_status_rec.shared_type_name;
3259      l_availability_status := C_avail_status_rec.system_type_cd;
3260      /*For Bug No 1527423 End */
3261    End loop;
3262 
3263    -- Create new position in PSB
3264       select psb_positions_s.nextval INTO l_position_id
3265 	from dual;
3266 
3267       hr_utility.set_location('l_position_id '||l_position_id  ,9833);
3268       hr_utility.set_location('l_data_extract_id '||l_data_extract_id,   9833);
3269       hr_utility.set_location('l_ccid '||l_ccid  ,9833);
3270       hr_utility.set_location('p_position_id '||p_position_id  ,9833);
3271       hr_utility.set_location('p_business_group_id '||p_business_group_id,9833);
3272       hr_utility.set_location('p_date_effective, '||p_date_effective,   9833);
3273       hr_utility.set_location('l_date_end '||l_date_end  ,9833);
3274       hr_utility.set_location('l_set_of_books_id '||l_set_of_books_id  ,9833);
3275       hr_utility.set_location('l_vacant_position_flag '||
3276 			       l_vacant_position_flag  ,9833);
3277       hr_utility.set_location('_availability_status '||
3278 			       l_availability_status  ,9833);
3279       hr_utility.set_location('l_concat_pos_name '||l_concat_pos_name  ,9833);
3280 
3281     PSB_POSITIONS_PVT.INSERT_ROW
3282 	(
3283 	  p_api_version            => 1.0,
3284 	  p_init_msg_lISt          => NULL,
3285 	  p_commit                 => NULL,
3286 	  p_validation_level       => NULL,
3287 	  p_return_status          => l_return_status,
3288 	  p_msg_count              => l_msg_count,
3289 	  p_msg_data               => l_msg_data,
3290 	  p_rowid                  => l_rowid,
3291 	  p_position_id            => l_position_id,
3292           -- de by org
3293           p_organization_id        => p_organization_id,
3294 	  p_data_extract_id        => l_data_extract_id,
3295 	  p_position_definition_id => l_ccid,
3296 	  p_hr_position_id         => p_position_id,
3297 	  p_hr_employee_id         => NULL,
3298 	  p_business_group_id      => p_business_group_id,
3299 	  p_effective_start_DATE   => p_date_effective,
3300 	  p_effective_END_DATE     => l_date_end,
3301 	  p_set_of_books_id        => l_set_of_books_id,
3302 	  p_vacant_position_flag   => 'Y',
3303 	  p_availability_status    => l_availability_status,
3304 	  p_transaction_id         => null,
3305 	  p_transaction_status     => 'SUCCESS',
3306 	  p_new_position_flag      => 'Y',
3307 	  p_attribute1             => NULL,
3308 	  p_attribute2             => NULL,
3309 	  p_attribute3             => NULL,
3310 	  p_attribute4             => NULL,
3311 	  p_attribute5             => NULL,
3312 	  p_attribute6             => NULL,
3313 	  p_attribute7             => NULL,
3314 	  p_attribute8             => NULL,
3315 	  p_attribute9             => NULL,
3316 	  p_attribute10            => NULL,
3317 	  p_attribute11            => NULL,
3318 	  p_attribute12            => NULL,
3319 	  p_attribute13            => NULL,
3320 	  p_attribute14            => NULL,
3321 	  p_attribute15            => NULL,
3322 	  p_attribute16            => NULL,
3323 	  p_attribute17            => NULL,
3324 	  p_attribute18            => NULL,
3325 	  p_attribute19            => NULL,
3326 	  p_attribute20            => NULL,
3327 	  p_attribute_category     => NULL,
3328 	  p_name                   => l_concat_pos_name,
3329 	  p_mode                   => 'R'
3330 	);
3331 
3332    IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3333       hr_utility.set_location('error in insert position',9877);
3334       FND_MESSAGE.SET_NAME('PSB', 'PSB_POS_INSERT_FAILURE'  );
3335 
3336       RAISE FND_API.G_EXC_ERROR;
3337    END IF;
3338 
3339    --++ add  to position sets for WS recalc
3340 
3341    PSB_Budget_Position_Pvt.Add_Position_To_Position_Sets (
3342 	    p_api_version       => 1.0,
3343 	    p_init_msg_list     => FND_API.G_TRUE,
3344 	    p_commit            => NULL,
3345 	    p_validation_level  => NULL,
3346 	    p_return_status     => l_return_status,
3347 	    p_msg_count         => l_msg_count,
3348 	    p_msg_data          => l_msg_data,
3349 	    p_position_id       => l_position_id
3350 	  ) ;
3351 
3352    hr_utility.set_location(' end add psb positions'||l_position_id,1333);
3353 
3354    -- Populate Salary Assignments
3355    hr_utility.set_location(' Before Salary Assignment'||l_position_id,333);
3356 
3357    Populate_Salary_Assignments
3358      ( p_return_status   =>  l_return_status,
3359        p_position_id     =>  l_position_id,
3360        p_date_effective  =>  p_date_effective,
3361        p_date_end        =>  p_date_end,
3362        p_data_extract_id =>  l_data_extract_id,
3363        p_business_group_id => p_business_group_id,
3364        p_set_of_books_id   =>  l_set_of_books_id,
3365        p_entry_grade_rule_id  => p_entry_grade_rule_id,
3366        p_entry_step_id   => p_entry_step_id,
3367        p_entry_grade_id  => p_entry_grade_id,
3368        p_pay_basis_id    => p_pay_basis_id);
3369 
3370    IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3371       FND_MESSAGE.SET_NAME('PSB', 'PSB_INCREMENTAL_SALARY_FAILURE'  );
3372 
3373       RAISE FND_API.G_EXC_ERROR;
3374    END IF;
3375 
3376    Populate_Attribute_Assignments
3377    ( p_return_status            =>  l_return_status,
3378      p_new_position_id          =>  l_position_id,
3379      p_position_id              =>  p_position_id,
3380      p_job_id                   =>  p_job_id,
3381      p_organization_id          =>  p_organization_id,
3382      p_fte                      =>  p_fte,
3383      p_frequency                =>  p_frequency,
3384      p_working_hours            =>  p_working_hours,
3385      p_earliest_hire_date       =>  p_earliest_hire_date,
3386      p_entry_grade_id           =>  p_entry_grade_id,
3387      p_date_effective           =>  p_date_effective,
3388      p_date_end                 =>  l_date_end,
3389      p_data_extract_id          =>  l_data_extract_id,
3390      p_business_group_id        =>  p_business_group_id
3391    ) ;
3392    --
3393    IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3394      FND_MESSAGE.SET_NAME('PSB', 'PSB_INCREMENTAL_ATTRIBUTE_FAIL'  );
3395      RAISE FND_API.G_EXC_ERROR;
3396    END IF;
3397 
3398     hr_utility.set_location(' org id is ' || get_global('G_PSB_ORG_ID')  ,888);
3399     hr_utility.set_location(' bg id is ' || get_global('G_PSB_BUDGET_GROUP_ID')  ,888);
3400     hr_utility.set_location(' ws id is ' || get_global('G_PSB_WORKSHEET_ID')  ,888);
3401 
3402     Update_Worksheet_Values ( p_return_status  => l_return_status,
3403 			      p_position_id    => l_position_id,
3404 			      p_org_id         => p_organization_id);
3405 
3406    IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3407       hr_utility.set_location(' fail to update ws value ',888);
3408       FND_MESSAGE.SET_NAME('PSB', 'PSB_INCREMENTAL_WS_FAILURE'  );
3409       RAISE FND_API.G_EXC_ERROR;
3410 
3411       RAISE FND_API.G_EXC_ERROR;
3412    END IF;
3413    hr_utility.set_location(' Insert Position Info Success',555);
3414 
3415  end if;
3416 
3417   --hr_utility.trace_off;
3418 /* For Bug No : 2739450 Start*/
3419  END IF;
3420 /* For Bug No : 2739450 End*/
3421 
3422 EXCEPTION
3423   --
3424   WHEN OTHERS THEN
3425     Process_Exception( l_api_name ) ;
3426   --
3427 END Insert_Position_Info;
3428 /*---------------------------------------------------------------------------*/
3429 
3430 
3431 /*===========================================================================+
3432  |                       PROCEDURE Update_Position_Info                      |
3433  +===========================================================================*/
3434 PROCEDURE Update_Position_Info
3435 (p_position_id                in NUMBER ,
3436  p_effective_start_date       in DATE   ,
3437  p_effective_end_date         in DATE   ,
3438  p_availability_status_id     in NUMBER ,
3439  p_business_group_id_o        in NUMBER ,
3440  p_entry_step_id              in NUMBER ,
3441  p_entry_grade_rule_id        in NUMBER ,
3442  p_job_id_o                   in NUMBER ,
3443  p_location_id                in NUMBER ,
3444  p_organization_id_o          in NUMBER ,
3445  p_position_definition_id     in NUMBER ,
3446  p_position_transaction_id    in NUMBER ,
3447  p_entry_grade_id             in NUMBER ,
3448  p_bargaining_unit_cd         in VARCHAR2 ,
3449  p_date_effective             in DATE   ,
3450  p_date_end                   in DATE   ,
3451  p_earliest_hire_date         in DATE   ,
3452  p_fill_by_date               in DATE   ,
3453  p_frequency                  in VARCHAR2  ,
3454  p_working_hours              in NUMBER,
3455  p_fte                        in NUMBER    ,
3456  p_name                       in VARCHAR2  ,
3457  p_position_type              in VARCHAR2  ,
3458  p_pay_basis_id               in NUMBER    ,
3459  p_object_version_number      in NUMBER    ,
3460  p_effective_date             in DATE
3461 )
3462 IS
3463   --
3464   l_api_name            CONSTANT VARCHAR2(30)   := 'Update_Position_Info' ;
3465   l_api_version         CONSTANT NUMBER         := 1.0 ;
3466   --
3467   l_data_extract_id NUMBER := 0;
3468   l_position_id_flex_num  number;
3469   l_concat_pos_name     varchar2(240);
3470   l_init_index          BINARY_INTEGER;
3471   l_ccid                number;
3472   segs                  FND_FLEX_EXT.SegmentArray;
3473 
3474   /*For Bug No : 2602027 Start*/
3475   l_pos_id_flex_num     number;
3476   l_per_index           BINARY_INTEGER;
3477   l_pos_index           BINARY_INTEGER;
3478   tf                    BOOLEAN;
3479   nsegs                 NUMBER;
3480   possegs               FND_FLEX_EXT.SegmentArray;
3481   isegs                 FND_FLEX_EXT.SegmentArray;
3482   /*For Bug No : 2602027 End*/
3483 
3484   Cursor C_pos_trx is
3485      Select *
3486        from psb_positions
3487       where hr_position_id  = p_position_id
3488 	and data_extract_id = l_data_extract_id;
3489 
3490   Cursor C_availability_status  is
3491    /*For Bug No : 1527423 Start*/
3492   --select shared_type_name
3493     select system_type_cd
3494    /*For Bug No : 1527423 End*/
3495       from per_shared_types
3496      where lookup_type = 'POSITION_AVAILABILITY_STATUS'
3497        and shared_type_id = p_availability_status_id;
3498 
3499   Cursor C_data_extract is
3500     --SELECT req_data_as_of_date
3501     SELECT business_group_id,
3502 	   set_of_books_id,
3503 	   position_id_flex_num,
3504 	   req_data_as_of_date
3505       FROM psb_data_extracts
3506      WHERE data_extract_id = l_data_extract_id;
3507 
3508   /*For Bug No : 2602027 Start*/
3509   Cursor C_flex_num is
3510 	select position_structure
3511 	  from per_business_groups
3512 	 where business_group_id = p_business_group_id_o;
3513 
3514   Cursor C_pos_segs is
3515     select application_column_name
3516       from fnd_id_flex_segments_vl
3517      where id_flex_code = 'POS'
3518        and id_flex_num = l_pos_id_flex_num
3519        and enabled_flag = 'Y'
3520     order by segment_num;
3521   /*For Bug No : 2602027 End*/
3522 
3523   l_psb_position_id        number := '';
3524   -- de by org
3525   l_organization_id        number;
3526   l_validity_date          date := null;
3527   l_availability_status    varchar2(30);
3528   l_return_status          varchar2(1);
3529   l_msg_count              number;
3530   l_msg_data               varchar2(1000);
3531   l_msg                    varchar2(2000);
3532 
3533 Begin
3534 
3535 /* For Bug No : 2739450 Start*/
3536 IF (p_position_transaction_id IS NULL) THEN
3537 /*For Bug No. 2739450 End*/
3538   --hr_utility.trace_on;
3539   hr_utility.set_location(' position_id '||p_position_id,881);
3540    hr_utility.set_location(' effective_start_date '||p_effective_start_date,881);
3541    hr_utility.set_location(' effective_end  _date '||p_effective_end_date,881);
3542    hr_utility.set_location(' availability stat '||p_availability_status_id,881);
3543    hr_utility.set_location(' business group stat '||p_business_group_id_o,881);
3544    hr_utility.set_location(' entry step id '||p_entry_step_id,881);
3545    hr_utility.set_location(' entry grade rule id '||p_entry_grade_rule_id,881);
3546    hr_utility.set_location(' entry job id '||p_job_id_o,881);
3547    hr_utility.set_location(' entry location id '||p_location_id,881);
3548    hr_utility.set_location(' entry org id '||p_organization_id_o,881);
3549    hr_utility.set_location(' pos definitio'||p_position_definition_id,881);
3550    hr_utility.set_location(' pos trans id'||p_position_transaction_id,881);
3551    hr_utility.set_location(' entry grage id'||p_entry_grade_id,881);
3552    hr_utility.set_location(' barganingin  d'||p_bargaining_unit_cd,881);
3553    hr_utility.set_location(' date eff   '||p_date_effective,881);
3554    hr_utility.set_location(' date end   '||p_date_end,881);
3555    hr_utility.set_location(' earliest hire date '||p_earliest_hire_date,881);
3556    hr_utility.set_location(' earliest fill date '||p_fill_by_date,881);
3557    hr_utility.set_location(' frequency '||p_frequency,881);
3558    hr_utility.set_location(' working hours '||p_working_hours,881);
3559    hr_utility.set_location(' fte '||p_fte,881);
3560    hr_utility.set_location(' name '||p_name,881);
3561    hr_utility.set_location(' position type '||p_position_type,881);
3562    hr_utility.set_location(' pay basis '||p_pay_basis_id,881);
3563    hr_utility.set_location(' object version # '||p_object_version_number,881);
3564    hr_utility.set_location(' p_effective_date '||p_effective_date, 8887);
3565    hr_utility.set_location(' *****************set up ************', 8887);
3566    hr_utility.set_location(' ****  in update position info',777);
3567 
3568    if (get_global('G_PSB_APPLICATION_ID') = 8401) then
3569 
3570     l_data_extract_id := get_global('G_PSB_DATA_EXTRACT_ID');
3571     hr_utility.set_location(' l_data_extract '||l_data_extract_id, 8887);
3572 
3573     For C_data_extract_rec in C_data_extract
3574     Loop
3575       l_validity_date := C_data_extract_rec.req_data_as_of_date;
3576       l_position_id_flex_num := C_data_extract_rec.position_id_flex_num;
3577     End Loop;
3578 
3579   For C_pos_trx_rec in C_pos_trx
3580   Loop
3581     l_psb_position_id := C_pos_trx_rec.position_id;
3582     l_organization_id := C_pos_trx_rec.organization_id;
3583     l_availability_status := null;
3584 
3585     For C_Avail_Status_Rec in C_Availability_Status
3586     Loop
3587      /*For Bug No 1527423 Start */
3588      --l_availability_status := C_avail_status_rec.shared_type_name;
3589      l_availability_status := C_avail_status_rec.system_type_cd;
3590      /*For Bug No 1527423 End */
3591     End loop;
3592 
3593     /*For Bug No : 2602027 Start*/
3594     For C_flex_rec in C_flex_num
3595     Loop
3596       l_pos_id_flex_num := C_flex_rec.position_structure;
3597     End Loop;
3598 
3599     tf := FND_FLEX_EXT.GET_SEGMENTS('PER', 'POS', l_pos_id_flex_num, p_position_definition_id, nsegs, segs);
3600     if (tf = FALSE) then
3601 	l_msg := FND_MESSAGE.Get;
3602 	FND_MESSAGE.SET_NAME('PSB','PSB_POS_DEFN_VALUE_ERROR');
3603 	FND_MESSAGE.SET_TOKEN('POSITION_NAME',p_name );
3604 	FND_MESSAGE.SET_TOKEN('ERR_MESG',l_msg);
3605 	FND_MSG_PUB.Add;
3606 	hr_utility.set_location('error in get segments',9850);
3607 	RAISE FND_API.G_EXC_ERROR;
3608     end if;
3609 
3610     l_per_index := 1;
3611     l_init_index := 0;
3612 
3613     For k in 1..30
3614     Loop
3615      possegs(k) := null;
3616     End Loop;
3617 
3618     For C_pos_seg_rec in C_pos_segs
3619     Loop
3620       l_init_index := l_init_index + 1;
3621 
3622       If (C_pos_seg_rec.application_column_name = 'SEGMENT1') then
3623 	 possegs(1) := segs(l_per_index);
3624 	 l_per_index := l_per_index + 1;
3625       end if;
3626       If (C_pos_seg_rec.application_column_name = 'SEGMENT2') then
3627 	 possegs(2) := segs(l_per_index);
3628 	 l_per_index := l_per_index + 1;
3629       end if;
3630       If (C_pos_seg_rec.application_column_name = 'SEGMENT3') then
3631 	 possegs(3) := segs(l_per_index);
3632 	 l_per_index := l_per_index + 1;
3633       end if;
3634       If (C_pos_seg_rec.application_column_name = 'SEGMENT4') then
3635 	 possegs(4) := segs(l_per_index);
3636 	 l_per_index := l_per_index + 1;
3637       end if;
3638       If (C_pos_seg_rec.application_column_name = 'SEGMENT5') then
3639 	 possegs(5) := segs(l_per_index);
3640 	 l_per_index := l_per_index + 1;
3641       end if;
3642       If (C_pos_seg_rec.application_column_name = 'SEGMENT6') then
3643 	 possegs(6) := segs(l_per_index);
3644 	 l_per_index := l_per_index + 1;
3645       end if;
3646       If (C_pos_seg_rec.application_column_name = 'SEGMENT7') then
3647 	 possegs(7) := segs(l_per_index);
3648 	 l_per_index := l_per_index + 1;
3649       end if;
3650       If (C_pos_seg_rec.application_column_name = 'SEGMENT8') then
3651 	 possegs(8) := segs(l_per_index);
3652 	 l_per_index := l_per_index + 1;
3653       end if;
3654       If (C_pos_seg_rec.application_column_name = 'SEGMENT9') then
3655 	 possegs(9) := segs(l_per_index);
3656 	 l_per_index := l_per_index + 1;
3657       end if;
3658       If (C_pos_seg_rec.application_column_name = 'SEGMENT10') then
3659 	 possegs(10) := segs(l_per_index);
3660 	 l_per_index := l_per_index + 1;
3661       end if;
3662       If (C_pos_seg_rec.application_column_name = 'SEGMENT11') then
3663 	 possegs(11) := segs(l_per_index);
3664 	 l_per_index := l_per_index + 1;
3665       end if;
3666       If (C_pos_seg_rec.application_column_name = 'SEGMENT12') then
3667 	 possegs(12) := segs(l_per_index);
3668 	 l_per_index := l_per_index + 1;
3669       end if;
3670       If (C_pos_seg_rec.application_column_name = 'SEGMENT13') then
3671 	 possegs(13) := segs(l_per_index);
3672 	 l_per_index := l_per_index + 1;
3673       end if;
3674       If (C_pos_seg_rec.application_column_name = 'SEGMENT14') then
3675 	 possegs(14) := segs(l_per_index);
3676 	 l_per_index := l_per_index + 1;
3677       end if;
3678       If (C_pos_seg_rec.application_column_name = 'SEGMENT15') then
3679 	 possegs(15) := segs(l_per_index);
3680 	 l_per_index := l_per_index + 1;
3681       end if;
3682       If (C_pos_seg_rec.application_column_name = 'SEGMENT16') then
3683 	 possegs(16) := segs(l_per_index);
3684 	 l_per_index := l_per_index + 1;
3685       end if;
3686       If (C_pos_seg_rec.application_column_name = 'SEGMENT17') then
3687 	 possegs(17) := segs(l_per_index);
3688 	 l_per_index := l_per_index + 1;
3689       end if;
3690       If (C_pos_seg_rec.application_column_name = 'SEGMENT18') then
3691 	 possegs(18) := segs(l_per_index);
3692 	 l_per_index := l_per_index + 1;
3693       end if;
3694       If (C_pos_seg_rec.application_column_name = 'SEGMENT19') then
3695 	 possegs(19) := segs(l_per_index);
3696 	 l_per_index := l_per_index + 1;
3697       end if;
3698       If (C_pos_seg_rec.application_column_name = 'SEGMENT20') then
3699 	 possegs(20) := segs(l_per_index);
3700 	 l_per_index := l_per_index + 1;
3701       end if;
3702       If (C_pos_seg_rec.application_column_name = 'SEGMENT21') then
3703 	 possegs(21) := segs(l_per_index);
3704 	 l_per_index := l_per_index + 1;
3705       end if;
3706       If (C_pos_seg_rec.application_column_name = 'SEGMENT22') then
3707 	 possegs(22) := segs(l_per_index);
3708 	 l_per_index := l_per_index + 1;
3709       end if;
3710       If (C_pos_seg_rec.application_column_name = 'SEGMENT23') then
3711 	 possegs(23) := segs(l_per_index);
3712 	 l_per_index := l_per_index + 1;
3713       end if;
3714       If (C_pos_seg_rec.application_column_name = 'SEGMENT24') then
3715 	 possegs(24) := segs(l_per_index);
3716 	 l_per_index := l_per_index + 1;
3717       end if;
3718       If (C_pos_seg_rec.application_column_name = 'SEGMENT25') then
3719 	 possegs(25) := segs(l_per_index);
3720 	 l_per_index := l_per_index + 1;
3721       end if;
3722       If (C_pos_seg_rec.application_column_name = 'SEGMENT26') then
3723 	 possegs(26) := segs(l_per_index);
3724 	 l_per_index := l_per_index + 1;
3725       end if;
3726       If (C_pos_seg_rec.application_column_name = 'SEGMENT27') then
3727 	 possegs(27) := segs(l_per_index);
3728 	 l_per_index := l_per_index + 1;
3729       end if;
3730       If (C_pos_seg_rec.application_column_name = 'SEGMENT28') then
3731 	 possegs(28) := segs(l_per_index);
3732 	 l_per_index := l_per_index + 1;
3733       end if;
3734       If (C_pos_seg_rec.application_column_name = 'SEGMENT29') then
3735 	 possegs(29) := segs(l_per_index);
3736 	 l_per_index := l_per_index + 1;
3737       end if;
3738       If (C_pos_seg_rec.application_column_name = 'SEGMENT30') then
3739 	 possegs(30) := segs(l_per_index);
3740 	 l_per_index := l_per_index + 1;
3741       end if;
3742 
3743     End Loop;
3744    /*For Bug No : 2602027 End*/
3745 
3746    For k in 1..30
3747    Loop
3748       isegs(k) := null;
3749    End Loop;
3750 
3751    l_pos_index := 0;
3752 
3753    FOR C_flex_rec in
3754    (
3755 	Select application_column_name
3756 	FROM   fnd_id_flex_segments_vl
3757 	WHERE  id_flex_code = 'BPS'
3758 	AND    id_flex_num  = l_position_id_flex_num
3759 	AND    enabled_flag = 'Y'
3760 	ORDER  BY segment_num
3761    )
3762    LOOP
3763 	l_pos_index := l_pos_index + 1;
3764 	isegs(l_pos_index) := NULL;
3765 
3766 	IF (C_flex_rec.application_column_name = 'SEGMENT1') THEN
3767 	    isegs(l_pos_index)   := possegs(1);
3768 	END IF;
3769 	IF (C_flex_rec.application_column_name = 'SEGMENT2') THEN
3770 	    isegs(l_pos_index)   := possegs(2);
3771 	END IF;
3772 	IF (C_flex_rec.application_column_name = 'SEGMENT3') THEN
3773 	    isegs(l_pos_index)   := possegs(3);
3774 	END IF;
3775 	IF (C_flex_rec.application_column_name = 'SEGMENT4') THEN
3776 	    isegs(l_pos_index)   := possegs(4);
3777 	END IF;
3778 	IF (C_flex_rec.application_column_name = 'SEGMENT5') THEN
3779 	    isegs(l_pos_index)   := possegs(5);
3780 	END IF;
3781 	IF (C_flex_rec.application_column_name = 'SEGMENT6') THEN
3782 	    isegs(l_pos_index)   := possegs(6);
3783 	END IF;
3784 	IF (C_flex_rec.application_column_name = 'SEGMENT7') THEN
3785 	    isegs(l_pos_index)   := possegs(7);
3786 	END IF;
3787 	IF (C_flex_rec.application_column_name = 'SEGMENT8') THEN
3788 	    isegs(l_pos_index)   := possegs(8);
3789 	END IF;
3790 	IF (C_flex_rec.application_column_name = 'SEGMENT9') THEN
3791 	    isegs(l_pos_index)   := possegs(9);
3792 	END IF;
3793 	IF (C_flex_rec.application_column_name = 'SEGMENT10') THEN
3794 	    isegs(l_pos_index)   := possegs(10);
3795 	END IF;
3796 	IF (C_flex_rec.application_column_name = 'SEGMENT11') THEN
3797 	    isegs(l_pos_index)   := possegs(11);
3798 	END IF;
3799 	IF (C_flex_rec.application_column_name = 'SEGMENT12') THEN
3800 	    isegs(l_pos_index)   := possegs(12);
3801 	END IF;
3802 	IF (C_flex_rec.application_column_name = 'SEGMENT13') THEN
3803 	    isegs(l_pos_index)   := possegs(13);
3804 	END IF;
3805 	IF (C_flex_rec.application_column_name = 'SEGMENT14') THEN
3806 	    isegs(l_pos_index)   := possegs(14);
3807 	END IF;
3808 	IF (C_flex_rec.application_column_name = 'SEGMENT15') THEN
3809 	    isegs(l_pos_index)   := possegs(15);
3810 	END IF;
3811 	IF (C_flex_rec.application_column_name = 'SEGMENT16') THEN
3812 	    isegs(l_pos_index)   := possegs(16);
3813 	END IF;
3814 	IF (C_flex_rec.application_column_name = 'SEGMENT17') THEN
3815 	    isegs(l_pos_index)   := possegs(17);
3816 	END IF;
3817 	IF (C_flex_rec.application_column_name = 'SEGMENT18') THEN
3818 	    isegs(l_pos_index)   := possegs(18);
3819 	END IF;
3820 	IF (C_flex_rec.application_column_name = 'SEGMENT19') THEN
3821 	    isegs(l_pos_index)   := possegs(19);
3822 	END IF;
3823 	IF (C_flex_rec.application_column_name = 'SEGMENT20') THEN
3824 	    isegs(l_pos_index)   := possegs(20);
3825 	END IF;
3826 	IF (C_flex_rec.application_column_name = 'SEGMENT21') THEN
3827 	    isegs(l_pos_index)   := possegs(21);
3828 	END IF;
3829 	IF (C_flex_rec.application_column_name = 'SEGMENT22') THEN
3830 	    isegs(l_pos_index)   := possegs(22);
3831 	END IF;
3832 	IF (C_flex_rec.application_column_name = 'SEGMENT23') THEN
3833 	    isegs(l_pos_index)   := possegs(23);
3834 	END IF;
3835 	IF (C_flex_rec.application_column_name = 'SEGMENT24') THEN
3836 	    isegs(l_pos_index)   := possegs(24);
3837 	END IF;
3838 	IF (C_flex_rec.application_column_name = 'SEGMENT25') THEN
3839 	    isegs(l_pos_index)   := possegs(25);
3840 	END IF;
3841 	IF (C_flex_rec.application_column_name = 'SEGMENT26') THEN
3842 	    isegs(l_pos_index)   := possegs(26);
3843 	END IF;
3844 	IF (C_flex_rec.application_column_name = 'SEGMENT27') THEN
3845 	    isegs(l_pos_index)   := possegs(27);
3846 	END IF;
3847 	IF (C_flex_rec.application_column_name = 'SEGMENT28') THEN
3848 	    isegs(l_pos_index)   := possegs(28);
3849 	END IF;
3850 	IF (C_flex_rec.application_column_name = 'SEGMENT29') THEN
3851 	    isegs(l_pos_index)   := possegs(29);
3852 	END IF;
3853 	IF (C_flex_rec.application_column_name = 'SEGMENT30') THEN
3854 	    isegs(l_pos_index)   := possegs(30);
3855 	END IF;
3856 
3857     END LOOP; -- END LOOP ( C_flex_rec in C_flex )
3858 
3859    l_msg := null;
3860 
3861    if not fnd_flex_ext.Get_combination_id
3862 	  ( application_short_name => 'PSB',
3863 	    key_flex_code => 'BPS',
3864 	    structure_number => l_position_id_flex_num,
3865 	    validation_date => sysdate,
3866 	    n_segments => l_pos_index,
3867 	    segments => isegs,
3868 	    combination_id => l_ccid)
3869    then
3870       l_msg := FND_MESSAGE.get;
3871       FND_MSG_PUB.Add;
3872       FND_MESSAGE.SET_NAME('PSB', 'PSB_INCREMENTAL_CCID_FAILURE');
3873       FND_MESSAGE.SET_TOKEN('ERRMESG',l_msg);
3874       hr_utility.set_location('error in get combination id',9867);
3875       RAISE FND_API.G_EXC_ERROR;
3876    end if;
3877 
3878    hr_utility.set_location('pos id flex num in '||
3879                          l_position_id_flex_num || ' ccid ' || l_ccid ,9867);
3880 
3881    l_concat_pos_name := null;
3882    l_concat_pos_name := FND_FLEX_EXT.Get_Segs
3883 			(application_short_name => 'PSB',
3884 			 key_flex_code => 'BPS',
3885 			 structure_number => l_position_id_flex_num,
3886 			 combination_id => l_ccid);
3887    hr_utility.set_location('concat pos name is '|| l_concat_pos_name,9877);
3888    hr_utility.set_location(' before insert ' ,881);
3889    hr_utility.set_location(' l_psb_position_id '|| l_psb_position_id , 881);
3890    hr_utility.set_location(' l_data_extract_id '|| l_data_extract_id ,881);
3891    hr_utility.set_location(' p_position_definition_id '|| p_position_definition_id ,881);
3892    hr_utility.set_location(' p_position_id '|| p_position_id ,881);
3893    hr_utility.set_location(' c_pos_trx_rec.hr_employee_id '||
3894 			     c_pos_trx_rec.hr_employee_id ,881);
3895    hr_utility.set_location(' p_business_group_id_o '|| p_business_group_id_o ,881);
3896    hr_utility.set_location(' p_effective_dat '|| p_effective_date ,881);
3897    hr_utility.set_location(' p_date_end '|| p_date_end ,881);
3898    hr_utility.set_location(' c_pos_trx_rec.set_of_books_id '||
3899 			     c_pos_trx_rec.set_of_books_id ,881);
3900    hr_utility.set_location(' c_pos_trx_rec.vacant_position_flag '||
3901 			     c_pos_trx_rec.vacant_position_flag ,881);
3902    hr_utility.set_location(' l_availability_status '|| l_availability_status ,881);
3903    hr_utility.set_location(' c_pos_trx_rec.transaction_id '||
3904 			     c_pos_trx_rec.transaction_id ,881);
3905    hr_utility.set_location(' c_pos_trx_rec.transaction_status '||
3906 			     c_pos_trx_rec.transaction_status ,881);
3907    hr_utility.set_location('  p_name '||p_name,881);
3908 
3909    hr_utility.set_location(' before update position', 1887);
3910    -- ++++++
3911 
3912    PSB_POSITIONS_PVT.UPDATE_ROW
3913        (
3914 	 p_api_version            => 1.0,
3915 	 p_init_msg_lISt          => FND_API.G_FALSE,
3916 	 p_commit                 => FND_API.G_FALSE,
3917 	 p_validation_level       => FND_API.G_VALID_LEVEL_FULL,
3918 	 p_return_status          => l_return_status,
3919 	 p_msg_count              => l_msg_count,
3920 	 p_msg_data               => l_msg_data,
3921 	 p_position_id            => l_psb_position_id,
3922          -- de by org
3923          p_organization_id        => p_organization_id_o,
3924 	 p_data_extract_id        => l_data_extract_id,
3925 	 p_position_definition_id => l_ccid,
3926 	 p_hr_position_id         => p_position_id,
3927 	 p_hr_employee_id         => c_pos_trx_rec.hr_employee_id,
3928 	 p_business_group_id      => p_business_group_id_o,
3929 	 p_effective_start_DATE   => p_effective_date,
3930 	 p_effective_END_DATE     => p_date_end,
3931 	 p_set_of_books_id        => c_pos_trx_rec.set_of_books_id,
3932 	 p_vacant_position_flag   => c_pos_trx_rec.vacant_position_flag,
3933 	 p_availability_status    => l_availability_status,
3934 	 p_transaction_id         => c_pos_trx_rec.transaction_id,
3935 	 p_transaction_status     => c_pos_trx_rec.transaction_status,
3936 	 p_new_position_flag      => c_pos_trx_rec.new_position_flag ,
3937 	 p_attribute1             => NULL,
3938 	 p_attribute2             => NULL,
3939 	 p_attribute3             => NULL,
3940 	 p_attribute4             => NULL,
3941 	 p_attribute5             => NULL,
3942 	 p_attribute6             => NULL,
3943 	 p_attribute7             => NULL,
3944 	 p_attribute8             => NULL,
3945 	 p_attribute9             => NULL,
3946 	 p_attribute10            => NULL,
3947 	 p_attribute11            => NULL,
3948 	 p_attribute12            => NULL,
3949 	 p_attribute13            => NULL,
3950 	 p_attribute14            => NULL,
3951 	 p_attribute15            => NULL,
3952 	 p_attribute16            => NULL,
3953 	 p_attribute17            => NULL,
3954 	 p_attribute18            => NULL,
3955 	 p_attribute19            => NULL,
3956 	 p_attribute20            => NULL,
3957 	 p_attribute_category     => NULL,
3958 	 p_name                   => l_concat_pos_name,
3959 	 p_mode                   => 'R'
3960        );
3961 
3962    hr_utility.set_location(' after update position', 1887);
3963 
3964    IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3965       hr_utility.set_location(' posb fail after update position', 1887);
3966       FND_MESSAGE.SET_NAME('PSB', 'PSB_POS_UPDATE_FAILURE'  );
3967 
3968       RAISE FND_API.G_EXC_ERROR;
3969    END IF;
3970 
3971    Delete psb_position_assignments
3972     where position_id = l_psb_position_id;
3973 
3974    Populate_Salary_Assignments
3975      ( p_return_status   =>  l_return_status,
3976        p_position_id     =>  l_psb_position_id,
3977        p_date_effective  =>  p_date_effective,
3978        p_date_end        =>  p_date_end,
3979        p_data_extract_id =>  c_pos_trx_rec.data_extract_id,
3980        p_business_group_id => p_business_group_id_o,
3981        p_set_of_books_id   =>  c_pos_trx_rec.set_of_books_id,
3982        p_entry_grade_rule_id  => p_entry_grade_rule_id,
3983        p_entry_step_id   => p_entry_step_id,
3984        p_entry_grade_id  => p_entry_grade_id,
3985        p_pay_basis_id    => p_pay_basis_id);
3986 
3987    IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3988       FND_MESSAGE.SET_NAME('PSB', 'PSB_INCREMENTAL_SALARY_FAILURE'  );
3989 
3990       RAISE FND_API.G_EXC_ERROR;
3991    END IF;
3992 
3993  Populate_Attribute_Assignments
3994  ( p_return_status            =>  l_return_status,
3995    p_new_position_id          =>  l_psb_position_id,
3996    p_position_id              =>  p_position_id,
3997    p_job_id                   =>  p_job_id_o,
3998    p_organization_id          =>  p_organization_id_o,
3999    p_fte                      =>  p_fte,
4000    p_frequency                =>  p_frequency,
4001    p_working_hours            =>  p_working_hours,
4002    p_earliest_hire_date       =>  p_earliest_hire_date,
4003    p_entry_grade_id           =>  p_entry_grade_id,
4004    p_date_effective           =>  p_date_effective,
4005    p_date_end                 =>  p_date_end,
4006    p_data_extract_id          =>  c_pos_trx_rec.data_extract_id,
4007    p_business_group_id        =>  p_business_group_id_o);
4008 
4009    IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4010       RAISE FND_API.G_EXC_ERROR;
4011       FND_MESSAGE.SET_NAME('PSB', 'PSB_INCREMENTAL_ATTRIBUTE_FAIL'  );
4012 
4013    END IF;
4014 
4015    End Loop;
4016 
4017    Update_Worksheet_Values ( p_return_status   => l_return_status,
4018 			      p_position_id    => l_psb_position_id,
4019 			      p_org_id         => p_organization_id_o);
4020 
4021    IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4022       hr_utility.set_location(' fail to update ws value ',888);
4023       FND_MESSAGE.SET_NAME('PSB', 'PSB_INCREMENTAL_WS_FAILURE'  );
4024       RAISE FND_API.G_EXC_ERROR;
4025 
4026       RAISE FND_API.G_EXC_ERROR;
4027    END IF;
4028 
4029   end if;
4030 
4031   --hr_utility.trace_off;
4032 /* For Bug No : 2739450 Start*/
4033  END IF;
4034 /* For Bug No : 2739450 End*/
4035 
4036 EXCEPTION
4037   --
4038   WHEN OTHERS THEN
4039     Process_Exception( l_api_name ) ;
4040   --
4041 END Update_Position_Info;
4042 /*---------------------------------------------------------------------------*/
4043 
4044 
4045 /*---------------------------------------------------------------------------*/
4046 -- Update worksheet if incremental called from worksheet or budget revision
4047 PROCEDURE Update_Worksheet_Values
4048  ( p_return_status            OUT  NOCOPY  VARCHAR2,
4049    p_position_id               in  NUMBER ,
4050    p_org_id                    in  NUMBER)
4051 AS
4052   l_position_line_id number;
4053   l_return_status          varchar2(1);
4054   l_msg_count              number;
4055   l_msg_data               varchar2(1000);
4056 
4057   l_org_budget_group_id    number;
4058   l_in_org_id              number;
4059   l_in_bg_id               number;
4060   l_budget_rev_pos_line_id    NUMBER;
4061 
4062   -- start bug 3253644
4063   l_budget_group_id        NUMBER;
4064   l_budget_revision_id     NUMBER;
4065   l_root_budget_group 	   VARCHAR2(1);
4066   -- end bug 3253644
4067 
4068   cursor bgorg is
4069      select budget_group_id
4070      from psb_budget_groups
4071      where (organization_id = l_in_org_id or
4072 	    business_group_id = l_in_org_id   )
4073      start with budget_group_id = l_in_bg_id
4074      connect by prior budget_group_id = parent_budget_group_id;
4075 
4076 BEGIN
4077 
4078   --hr_utility.trace_on;
4079   IF get_global('G_PSB_CURRENT_FORM') <>  'PSBWMPMD'  and
4080      get_global('G_PSB_CURRENT_FORM') <>  'PSBBGRVS' THEN
4081      hr_utility.set_location(' exiting.. not from ws/bg',333);
4082      RETURN;
4083   END IF;
4084 
4085    hr_utility.set_location(' Inside update ws values',333);
4086    hr_utility.set_location(' WS id' || PSB_HR_POPULATE_DATA_PVT.get_global('G_PSB_WORKSHEET_ID'),333);
4087    hr_utility.set_location(' BG id' || PSB_HR_POPULATE_DATA_PVT.get_global('G_PSB_BUDGET_GROUP_ID'),333);
4088    hr_utility.set_location(' org id is ' || get_global('G_PSB_ORG_ID')  ,888);
4089    hr_utility.set_location(' positionid  ' || p_position_id ,888);
4090 
4091    -- get first budget group associated to input organization starting within the input bg's hierarchy
4092    -- use position's org id
4093    --l_in_org_id := get_global('G_PSB_ORG_ID');
4094 
4095    l_in_org_id := p_org_id;
4096    l_in_bg_id  := get_global('G_PSB_BUDGET_GROUP_ID');
4097 
4098    open bgorg;
4099    fetch bgorg into l_org_budget_group_id;
4100    if (bgorg%notfound) then
4101       close bgorg;
4102       raise FND_API.G_EXC_ERROR ;
4103    end if;
4104    close bgorg;
4105 
4106 
4107    hr_utility.set_location(' out org id   ' || l_org_budget_group_id ,888);
4108    IF get_global('G_PSB_CURRENT_FORM') = 'PSBWMPMD' THEN
4109       PSB_WS_POSITION_CR_LINES_I_PVT.Insert_Row
4110 	    (
4111 	    p_api_version                =>    1.0,
4112 	    p_init_msg_list              =>    FND_API.G_TRUE,
4113 	    p_commit                     =>    FND_API.G_FALSE,
4114 	    p_validation_level           =>    FND_API.G_VALID_LEVEL_FULL,
4115 	    p_return_status              =>    l_return_status,
4116 	    p_msg_count                  =>    l_msg_count,
4117 	    p_msg_data                   =>    l_msg_data,
4118 	    p_worksheet_id               =>    PSB_HR_POPULATE_DATA_PVT.get_global('G_PSB_WORKSHEET_ID'),
4119 	    p_position_id                =>    p_position_id,
4120 	    p_budget_group_id            =>    l_org_budget_group_id,
4121 	    p_position_line_id           =>    l_position_line_id);
4122 
4123       hr_utility.set_location(' l_position_line_id is ' || l_position_line_id,333);
4124 
4125       IF l_return_status <> FND_API.G_RET_STS_SUCCESS then
4126 	   hr_utility.set_location(' fail to insert row ',888);
4127 	   --hr_utility.trace_off;
4128 	 FND_MESSAGE.SET_NAME('PSB', 'PSB_INCR_INSERT_POS_WS_FAIL');
4129 	 raise FND_API.G_EXC_ERROR;
4130       END IF;
4131     --++ end ws
4132     ELSE
4133 
4134       PSB_BUDGET_REVISIONS_PVT.Create_Revision_Positions
4135 	    (p_api_version => 1.0,
4136 	     p_return_status => l_return_status,
4137 	     p_msg_count => l_msg_count,
4138 	     p_msg_data => l_msg_data,
4139 	     p_budget_revision_id =>  PSB_HR_POPULATE_DATA_PVT.get_global('G_PSB_WORKSHEET_ID'),
4140 	     p_budget_revision_pos_line_id => l_budget_rev_pos_line_id,
4141 	     p_position_id => p_position_id,
4142 	     p_budget_group_id => l_org_budget_group_id,
4143 	     p_effective_start_date =>
4144 				   PSB_HR_POPULATE_DATA_PVT.get_global('G_PSB_REVISION_START_DATE'),
4145 	     p_effective_end_date => PSB_HR_POPULATE_DATA_PVT.get_global('G_PSB_REVISION_END_DATE'),
4146 	     p_revision_type => null,
4147 	     p_revision_value_type => null,
4148 	     p_revision_value => null,
4149 	     p_note_id => null,
4150 	     p_freeze_flag => 'N',
4151 	     p_view_line_flag => 'Y');
4152 
4153       if l_return_status <> FND_API.G_RET_STS_SUCCESS then
4154 	FND_MESSAGE.SET_NAME('PSB', 'PSB_INCR_INSERT_POS_REV_FAIL');
4155 	raise FND_API.G_EXC_ERROR;
4156       else
4157         -- update the position table for system data extract with budget group ID
4158 	-- start bug 3253644
4159 
4160 	l_budget_revision_id := PSB_HR_POPULATE_DATA_PVT.get_global('G_PSB_WORKSHEET_ID');
4161 
4162         FOR l_bud_group_csr IN (
4163             SELECT a.budget_group_id, b.root_budget_group
4164   	      FROM psb_budget_revisions a,
4165                    psb_budget_groups b
4166   	     WHERE a.budget_revision_id = l_budget_revision_id
4167                AND a.budget_group_id = b.budget_group_id) lOOP
4168 
4169 	  l_budget_group_id   := l_bud_group_csr.budget_group_id;
4170 	  l_root_budget_group := l_bud_group_csr.root_budget_group;
4171 
4172         END LOOP;
4173 
4174 	IF NVL(l_root_budget_group, 'N') = 'Y' THEN
4175 	  UPDATE psb_positions
4176 	     SET budget_group_id = l_org_budget_group_id
4177 	   WHERE position_id = p_position_id;
4178         ELSE
4179 	  UPDATE psb_positions
4180 	     SET budget_group_id = l_budget_group_id
4181 	   WHERE position_id = p_position_id;
4182         END IF;
4183 	-- end bug 3253644
4184       end if;
4185 
4186    END IF;
4187 
4188    p_return_status := FND_API.G_RET_STS_SUCCESS;
4189    --hr_utility.trace_off;
4190 
4191 EXCEPTION
4192 
4193   WHEN FND_API.G_EXC_ERROR THEN
4194     p_return_status := FND_API.G_RET_STS_ERROR;
4195    --hr_utility.trace_off;
4196 
4197   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4198     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4199    --hr_utility.trace_off;
4200 
4201   WHEN OTHERS THEN
4202     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4203    --hr_utility.trace_off;
4204 
4205 END Update_Worksheet_Values;
4206 
4207 /* ----------------------------------------------------------------------- */
4208 
4209 PROCEDURE Create_Salary_Distributions
4210 ( p_return_status       OUT  NOCOPY  VARCHAR2,
4211   p_data_extract_id     IN   NUMBER,
4212   p_extract_method      IN   VARCHAR2,
4213   p_restart_position_id IN   NUMBER,
4214   -- de by org
4215   p_extract_by_org      IN   VARCHAR2
4216 ) AS
4217 
4218   l_return_status    VARCHAR2(1);
4219   l_msg_data         VARCHAR2(1000);
4220   l_msg_count        number;
4221   l_position_name    varchar2(240);
4222   --UTF8 changes for Bug#2615261
4223   l_employee_name    varchar2(310);
4224   l_position_ctr     number := 0;
4225   l_fin_position_id  number := 0;
4226 
4227   -- Bug#3615301: Perf issue.
4228   -- Bug#3073519: Modified cursor.
4229   CURSOR c_Positions IS
4230   SELECT PP.position_id,
4231          -- de by org
4232          PP.organization_id,
4233          PP.hr_employee_id,
4234          PP.effective_start_DATE,
4235          PP.effective_END_DATE
4236   FROM   PSB_POSITIONS PP,
4237          PSB_POSITIONS_I PPI
4238   WHERE  PP.data_extract_id = p_data_extract_id
4239   AND    PP.data_extract_id = PPI.data_extract_id
4240   AND    PP.position_id     > p_restart_position_id
4241   AND    PP.hr_position_id = PPI.hr_position_id
4242   AND    PP.hr_employee_id = PPI.hr_employee_id
4243   AND    ( PP.vacant_position_flag IS NULL OR PP.vacant_position_flag = 'N' )
4244   ORDER BY position_id;
4245 
4246 BEGIN
4247 
4248   -- Create salary dIStribution FOR all the positions.
4249   FOR c_Positions_Rec in c_Positions
4250   LOOP
4251     l_position_ctr := l_position_ctr + 1;
4252     l_fin_position_id := c_Positions_Rec.position_id;
4253 
4254     l_position_name := NULL;
4255     l_employee_name := NULL;
4256 
4257     IF (c_Positions_Rec.position_id IS NOT NULL) THEN
4258       FOR Pos_Name_Rec in G_Position_Details(p_position_id => c_Positions_Rec.position_id)
4259       LOOP
4260     	l_position_name := Pos_Name_Rec.name;
4261       END LOOP;
4262     END IF;
4263 
4264     IF (c_Positions_Rec.hr_employee_id IS NOT NULL) THEN
4265       FOR Emp_Name_Rec in G_Employee_Details(p_person_id => c_Positions_rec.hr_employee_id)
4266       LOOP
4267 	l_employee_name := Emp_Name_Rec.first_name||' '||Emp_Name_Rec.last_name;
4268       END LOOP;
4269     END IF;
4270 
4271     Create_Salary_Dist_Pos
4272     ( p_return_status       => l_return_status,
4273       p_data_extract_id     => p_data_extract_id,
4274       p_position_id         => c_Positions_Rec.position_id,
4275       p_position_start_DATE => c_Positions_Rec.effective_start_DATE,
4276       p_position_END_DATE   => c_Positions_Rec.effective_END_DATE
4277     );
4278 
4279     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4280       RAISE FND_API.G_EXC_ERROR;
4281     END IF;
4282 
4283     if l_position_ctr = PSB_WS_ACCT1.g_checkpoint_save then
4284     PSB_HR_EXTRACT_DATA_PVT.Update_Reentry
4285     ( p_api_version              => 1.0  ,
4286       p_return_status            => l_return_status,
4287       p_msg_count                => l_msg_count,
4288       p_msg_data                 => l_msg_data,
4289       p_data_extract_id          => p_data_extract_id,
4290       p_extract_method           => p_extract_method,
4291       p_process                  => 'PSB Costing',
4292       p_restart_id               => c_Positions_Rec.position_id
4293     );
4294 
4295     if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4296        raise FND_API.G_EXC_ERROR;
4297     end if;
4298     commit work;
4299     /*For Bug No : 2642012 Start*/
4300     l_position_ctr := 0;
4301     /*For Bug No : 2642012 End*/
4302     Savepoint Populate_Costing;
4303   end if;
4304 
4305   END LOOP;
4306 
4307   PSB_HR_EXTRACT_DATA_PVT.Update_Reentry
4308   ( p_api_version              => 1.0  ,
4309     p_return_status            => l_return_status,
4310     p_msg_count                => l_msg_count,
4311     p_msg_data                 => l_msg_data,
4312     p_data_extract_id          => p_data_extract_id,
4313     p_extract_method           => p_extract_method,
4314     p_process                  => 'PSB Costing',
4315     p_restart_id               => l_fin_position_id
4316   );
4317 
4318   if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4319      raise FND_API.G_EXC_ERROR;
4320   end if;
4321 
4322   -- Initialize API return status to success
4323   p_return_status := FND_API.G_RET_STS_SUCCESS;
4324 
4325 EXCEPTION
4326 
4327   WHEN FND_API.G_EXC_ERROR THEN
4328     p_return_status := FND_API.G_RET_STS_ERROR;
4329     FND_MESSAGE.SET_NAME('PSB', 'PSB_POSITION_DETAILS');
4330     FND_MESSAGE.SET_TOKEN('POSITION_NAME',l_position_name );
4331     FND_MESSAGE.SET_TOKEN('EMPLOYEE_NAME',l_employee_name );
4332     FND_MSG_PUB.Add;
4333 
4334   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4335     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4336     FND_MESSAGE.SET_NAME('PSB', 'PSB_POSITION_DETAILS');
4337     FND_MESSAGE.SET_TOKEN('POSITION_NAME',l_position_name );
4338     FND_MESSAGE.SET_TOKEN('EMPLOYEE_NAME',l_employee_name );
4339     FND_MSG_PUB.Add;
4340 
4341   WHEN OTHERS THEN
4342     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4343     FND_MESSAGE.SET_NAME('PSB', 'PSB_POSITION_DETAILS');
4344     FND_MESSAGE.SET_TOKEN('POSITION_NAME',l_position_name );
4345     FND_MESSAGE.SET_TOKEN('EMPLOYEE_NAME',l_employee_name );
4346     FND_MSG_PUB.Add;
4347 
4348 END Create_Salary_Distributions;
4349 /*---------------------------------------------------------------------------*/
4350 
4351 
4352 /*---------------------------------------------------------------------------*/
4353 PROCEDURE Create_Salary_Dist_Pos
4354 ( p_return_status        OUT  NOCOPY  VARCHAR2,
4355   p_data_extract_id      IN   NUMBER,
4356   p_position_id          IN   NUMBER,
4357   p_position_start_date  IN   DATE,
4358   p_position_end_date    IN   DATE
4359 )
4360 AS
4361 
4362   TYPE l_assignment_rec_type IS RECORD
4363   ( chart_of_accounts_id  NUMBER,
4364     proportion            NUMBER,
4365     effective_start_date  DATE,
4366     project_id            NUMBER,
4367     task_id               NUMBER,
4368     award_id              NUMBER,
4369     expenditure_type      VARCHAR2(30),
4370     expenditure_org_id    NUMBER,
4371     --UTF8 changes for Bug No : 2615261
4372     description           psb_cost_distributions_i.description%TYPE,
4373     cost_allocation_keyflex_id NUMBER,
4374     segment1  VARCHAR2(25), segment2  VARCHAR2(25), segment3  VARCHAR2(25),
4375     segment4  VARCHAR2(25), segment5  VARCHAR2(25), segment6  VARCHAR2(25),
4376     segment7  VARCHAR2(25), segment8  VARCHAR2(25), segment9  VARCHAR2(25),
4377     segment10  VARCHAR2(25), segment11  VARCHAR2(25), segment12  VARCHAR2(25),
4378     segment13  VARCHAR2(25), segment14  VARCHAR2(25), segment15  VARCHAR2(25),
4379     segment16  VARCHAR2(25), segment17  VARCHAR2(25), segment18  VARCHAR2(25),
4380     segment19  VARCHAR2(25), segment20  VARCHAR2(25), segment21  VARCHAR2(25),
4381     segment22  VARCHAR2(25), segment23  VARCHAR2(25), segment24  VARCHAR2(25),
4382     segment25  VARCHAR2(25), segment26  VARCHAR2(25), segment27  VARCHAR2(25),
4383     segment28  VARCHAR2(25), segment29  VARCHAR2(25), segment30  VARCHAR2(25)
4384   );
4385   --
4386   TYPE l_assignment_tbl_type IS TABLE OF l_assignment_rec_type
4387       INDEX BY BINARY_INTEGER;
4388 
4389   l_assignment               l_assignment_tbl_type;
4390   l_num_assignment           NUMBER := 0;
4391   l_num_organization         NUMBER := 0;
4392   l_num_payroll              NUMBER := 0;
4393   l_num_element              NUMBER := 0;
4394   l_process_num              NUMBER := 0;
4395   l_proportion               NUMBER := 0;
4396   l_project_id               NUMBER(15);
4397   l_task_id                  NUMBER(15);
4398   l_award_id                 NUMBER(15);
4399   l_expenditure_type         VARCHAR2(30);
4400   l_expenditure_org_id       NUMBER(15);
4401   l_error_message            VARCHAR2(100);
4402 
4403   -- UTF8 changes for Bug No : 2615261
4404   l_description              psb_cost_distributions_i.description%TYPE;
4405   l_position_name            VARCHAR2(240);
4406   l_process_start_date       DATE;
4407   l_default_start_date       DATE := fnd_date.canonical_to_date('1941/01/01');
4408   l_rep_req_id               NUMBER;
4409   l_reqid                    NUMBER;
4410   l_userid                   NUMBER;
4411   lh_distribution            gl_distribution_tbl_type;
4412   i                          number := 0;
4413 
4414   TYPE l_payroll_rec_type IS RECORD
4415   ( chart_of_accounts_id  NUMBER,
4416     effective_start_date  DATE,
4417     cost_allocation_keyflex_id NUMBER,
4418     segment1  VARCHAR2(25), segment2  VARCHAR2(25), segment3  VARCHAR2(25),
4419     segment4  VARCHAR2(25), segment5  VARCHAR2(25), segment6  VARCHAR2(25),
4420     segment7  VARCHAR2(25), segment8  VARCHAR2(25), segment9  VARCHAR2(25),
4421     segment10  VARCHAR2(25), segment11  VARCHAR2(25), segment12  VARCHAR2(25),
4422     segment13  VARCHAR2(25), segment14  VARCHAR2(25), segment15  VARCHAR2(25),
4423     segment16  VARCHAR2(25), segment17  VARCHAR2(25), segment18  VARCHAR2(25),
4424     segment19  VARCHAR2(25), segment20  VARCHAR2(25), segment21  VARCHAR2(25),
4425     segment22  VARCHAR2(25), segment23  VARCHAR2(25), segment24  VARCHAR2(25),
4426     segment25  VARCHAR2(25), segment26  VARCHAR2(25), segment27  VARCHAR2(25),
4427     segment28  VARCHAR2(25), segment29  VARCHAR2(25), segment30  VARCHAR2(25)
4428   );
4429   --
4430   TYPE l_payroll_tbl_type IS TABLE OF l_payroll_rec_type
4431       INDEX BY BINARY_INTEGER;
4432   --
4433   l_payroll                  l_payroll_tbl_type;
4434 
4435   TYPE l_org_rec_type IS RECORD
4436   ( chart_of_accounts_id  NUMBER,
4437     effective_start_date  DATE,
4438     cost_allocation_keyflex_id NUMBER,
4439     segment1  VARCHAR2(25), segment2  VARCHAR2(25), segment3  VARCHAR2(25),
4440     segment4  VARCHAR2(25), segment5  VARCHAR2(25), segment6  VARCHAR2(25),
4441     segment7  VARCHAR2(25), segment8  VARCHAR2(25), segment9  VARCHAR2(25),
4442     segment10  VARCHAR2(25), segment11  VARCHAR2(25), segment12  VARCHAR2(25),
4443     segment13  VARCHAR2(25), segment14  VARCHAR2(25), segment15  VARCHAR2(25),
4444     segment16  VARCHAR2(25), segment17  VARCHAR2(25), segment18  VARCHAR2(25),
4445     segment19  VARCHAR2(25), segment20  VARCHAR2(25), segment21  VARCHAR2(25),
4446     segment22  VARCHAR2(25), segment23  VARCHAR2(25), segment24  VARCHAR2(25),
4447     segment25  VARCHAR2(25), segment26  VARCHAR2(25), segment27  VARCHAR2(25),
4448     segment28  VARCHAR2(25), segment29  VARCHAR2(25), segment30  VARCHAR2(25)
4449   );
4450   --
4451   TYPE l_org_tbl_type IS TABLE OF l_org_rec_type
4452       INDEX BY BINARY_INTEGER;
4453   --
4454   l_organization             l_org_tbl_type;
4455 
4456   TYPE l_elemlink_rec_type IS RECORD
4457   ( chart_of_accounts_id  NUMBER,
4458     effective_start_date  DATE,
4459     cost_allocation_keyflex_id NUMBER,
4460     segment1  VARCHAR2(25), segment2  VARCHAR2(25), segment3  VARCHAR2(25),
4461     segment4  VARCHAR2(25), segment5  VARCHAR2(25), segment6  VARCHAR2(25),
4462     segment7  VARCHAR2(25), segment8  VARCHAR2(25), segment9  VARCHAR2(25),
4463     segment10  VARCHAR2(25), segment11  VARCHAR2(25), segment12  VARCHAR2(25),
4464     segment13  VARCHAR2(25), segment14  VARCHAR2(25), segment15  VARCHAR2(25),
4465     segment16  VARCHAR2(25), segment17  VARCHAR2(25), segment18  VARCHAR2(25),
4466     segment19  VARCHAR2(25), segment20  VARCHAR2(25), segment21  VARCHAR2(25),
4467     segment22  VARCHAR2(25), segment23  VARCHAR2(25), segment24  VARCHAR2(25),
4468     segment25  VARCHAR2(25), segment26  VARCHAR2(25), segment27  VARCHAR2(25),
4469     segment28  VARCHAR2(25), segment29  VARCHAR2(25), segment30  VARCHAR2(25)
4470   );
4471   --
4472   TYPE l_elemlink_tbl_type IS TABLE OF l_elemlink_rec_type
4473        INDEX BY BINARY_INTEGER;
4474   --
4475   l_element_link             l_elemlink_tbl_type;
4476   l_ccid_val                 FND_FLEX_EXT.SegmentArray;
4477   l_ccid                     NUMBER;
4478   l_init_index               BINARY_INTEGER;
4479   l_assign_index             BINARY_INTEGER;
4480   l_segment_index            BINARY_INTEGER;
4481   l_flex_code                NUMBER;
4482   l_msg_count                NUMBER;
4483   l_msg_data                 VARCHAR2(2000);
4484   l_msg                      VARCHAR2(5000);
4485   l_msg_buf                  VARCHAR2(1000);
4486   l_return_status            VARCHAR2(1);
4487   l_dIStribution_id          NUMBER;
4488   l_rowid                    VARCHAR2(100);
4489   tf                         boolean;
4490 
4491   -- Bug#3467512: Group costing info to avoid duplicate distribution lines.
4492   CURSOR l_dist_csr
4493   IS
4494   SELECT a.costing_level,
4495          a.proportion,
4496          a.chart_of_accounts_id,
4497          a.project_id,
4498          a.task_id,
4499          a.award_id,
4500          a.expenditure_type,
4501          a.expenditure_organization_id,
4502          a.description,
4503          a.cost_allocation_keyflex_id,
4504          a.segment1,  a.segment2,  a.segment3,  a.segment4,  a.segment5,
4505          a.segment6,  a.segment7,  a.segment8,  a.segment9,  a.segment10,
4506          a.segment11, a.segment12, a.segment13, a.segment14, a.segment15,
4507          a.segment16, a.segment17, a.segment18, a.segment19, a.segment20,
4508          a.segment21, a.segment22, a.segment23, a.segment24, a.segment25,
4509          a.segment26, a.segment27, a.segment28, a.segment29, a.segment30,
4510          a.effective_start_date
4511   FROM   psb_cost_distributions_i a,
4512          psb_employees_i          b,
4513          psb_employees            be,
4514          psb_positions            c,
4515          psb_position_assignments d
4516   WHERE  a.assignment_id         = b.assignment_id
4517   AND    a.data_extract_id       = p_data_extract_id
4518   AND    b.hr_position_id        = c.hr_position_id
4519   AND    b.hr_employee_id        = be.hr_employee_id
4520   AND    b.data_extract_id       = p_data_extract_id
4521   AND    be.data_extract_id      = p_data_extract_id
4522   AND    c.data_extract_id       = p_data_extract_id
4523   AND    c.position_id           = p_position_id
4524   AND    c.position_id           = d.position_id
4525   AND    be.employee_id          = d.employee_id
4526   AND    d.primary_employee_flag = 'Y'
4527   AND    d.assignment_type       = 'EMPLOYEE'
4528   ORDER BY a.chart_of_accounts_id;
4529   --
4530   l_use_account_generator_flag  VARCHAR2(1);
4531   l_appl_short_name             VARCHAR2(2000);
4532   l_message_name                VARCHAR2(2000);
4533   l_message_text                VARCHAR2(2000);
4534   l_ccid_exists                 BOOLEAN;
4535   --
4536 BEGIN
4537 
4538   --
4539   -- Find if account generator process is to be used to generate ccids from
4540   -- the POETA information. The default value is 'Y'.
4541   --
4542   FND_PROFILE.GET ( name => 'PSB_USE_ACCOUNT_GENERATOR_FOR_DE' ,
4543 		    val  => l_use_account_generator_flag );
4544 
4545   -- The default value is 'Y'.
4546   IF l_use_account_generator_flag IS NULL THEN
4547      l_use_account_generator_flag := 'Y';
4548   END IF;
4549 
4550   if lh_distribution.count > 0 then
4551      lh_distribution.delete;
4552      i := 0;
4553   end if;
4554 
4555   l_assignment(1).effective_start_date := NULL;
4556   l_assignment(1).chart_of_accounts_id := NULL;
4557   l_assignment(1).project_id := NULL;
4558   l_assignment(1).task_id    := NULL;
4559   l_assignment(1).award_id    := NULL;
4560   l_assignment(1).expenditure_type := NULL;
4561   l_assignment(1).expenditure_org_id := NULL;
4562   l_assignment(1).description := NULL;
4563   l_assignment(1).cost_allocation_keyflex_id := NULL;
4564   l_assignment(1).segment1  := NULL;
4565   l_assignment(1).segment2  := NULL;
4566   l_assignment(1).segment3  := NULL;
4567   l_assignment(1).segment4  := NULL;
4568   l_assignment(1).segment5  := NULL;
4569   l_assignment(1).segment6  := NULL;
4570   l_assignment(1).segment7  := NULL;
4571   l_assignment(1).segment8  := NULL;
4572   l_assignment(1).segment9  := NULL;
4573   l_assignment(1).segment10 := NULL;
4574   l_assignment(1).segment11 := NULL;
4575   l_assignment(1).segment12 := NULL;
4576   l_assignment(1).segment13 := NULL;
4577   l_assignment(1).segment14 := NULL;
4578   l_assignment(1).segment15 := NULL;
4579   l_assignment(1).segment16 := NULL;
4580   l_assignment(1).segment17 := NULL;
4581   l_assignment(1).segment18 := NULL;
4582   l_assignment(1).segment19 := NULL;
4583   l_assignment(1).segment20 := NULL;
4584   l_assignment(1).segment21 := NULL;
4585   l_assignment(1).segment22 := NULL;
4586   l_assignment(1).segment23 := NULL;
4587   l_assignment(1).segment24 := NULL;
4588   l_assignment(1).segment25 := NULL;
4589   l_assignment(1).segment26 := NULL;
4590   l_assignment(1).segment27 := NULL;
4591   l_assignment(1).segment28 := NULL;
4592   l_assignment(1).segment29 := NULL;
4593   l_assignment(1).segment30 := NULL;
4594 
4595 
4596   l_payroll(1).chart_of_accounts_id := NULL;
4597   l_payroll(1).effective_start_date := NULL;
4598   l_payroll(1).cost_allocation_keyflex_id := NULL;
4599 
4600   l_payroll(1).segment1  := NULL;
4601   l_payroll(1).segment2  := NULL;
4602   l_payroll(1).segment3  := NULL;
4603   l_payroll(1).segment4  := NULL;
4604   l_payroll(1).segment5  := NULL;
4605   l_payroll(1).segment6  := NULL;
4606   l_payroll(1).segment7  := NULL;
4607   l_payroll(1).segment8  := NULL;
4608   l_payroll(1).segment9  := NULL;
4609   l_payroll(1).segment10 := NULL;
4610   l_payroll(1).segment11 := NULL;
4611   l_payroll(1).segment12 := NULL;
4612   l_payroll(1).segment13 := NULL;
4613   l_payroll(1).segment14 := NULL;
4614   l_payroll(1).segment15 := NULL;
4615   l_payroll(1).segment16 := NULL;
4616   l_payroll(1).segment17 := NULL;
4617   l_payroll(1).segment18 := NULL;
4618   l_payroll(1).segment19 := NULL;
4619   l_payroll(1).segment20 := NULL;
4620   l_payroll(1).segment21 := NULL;
4621   l_payroll(1).segment22 := NULL;
4622   l_payroll(1).segment23 := NULL;
4623   l_payroll(1).segment24 := NULL;
4624   l_payroll(1).segment25 := NULL;
4625   l_payroll(1).segment26 := NULL;
4626   l_payroll(1).segment27 := NULL;
4627   l_payroll(1).segment28 := NULL;
4628   l_payroll(1).segment29 := NULL;
4629   l_payroll(1).segment30 := NULL;
4630 
4631   l_element_link(1).chart_of_accounts_id := NULL;
4632   l_element_link(1).effective_start_date := NULL;
4633   l_element_link(1).cost_allocation_keyflex_id := NULL;
4634 
4635   l_element_link(1).segment1  := NULL;
4636   l_element_link(1).segment2  := NULL;
4637   l_element_link(1).segment3  := NULL;
4638   l_element_link(1).segment4  := NULL;
4639   l_element_link(1).segment5  := NULL;
4640   l_element_link(1).segment6  := NULL;
4641   l_element_link(1).segment7  := NULL;
4642   l_element_link(1).segment8  := NULL;
4643   l_element_link(1).segment9  := NULL;
4644   l_element_link(1).segment10 := NULL;
4645   l_element_link(1).segment11 := NULL;
4646   l_element_link(1).segment12 := NULL;
4647   l_element_link(1).segment13 := NULL;
4648   l_element_link(1).segment14 := NULL;
4649   l_element_link(1).segment15 := NULL;
4650   l_element_link(1).segment16 := NULL;
4651   l_element_link(1).segment17 := NULL;
4652   l_element_link(1).segment18 := NULL;
4653   l_element_link(1).segment19 := NULL;
4654   l_element_link(1).segment20 := NULL;
4655   l_element_link(1).segment21 := NULL;
4656   l_element_link(1).segment22 := NULL;
4657   l_element_link(1).segment23 := NULL;
4658   l_element_link(1).segment24 := NULL;
4659   l_element_link(1).segment25 := NULL;
4660   l_element_link(1).segment26 := NULL;
4661   l_element_link(1).segment27 := NULL;
4662   l_element_link(1).segment28 := NULL;
4663   l_element_link(1).segment29 := NULL;
4664   l_element_link(1).segment30 := NULL;
4665 
4666   l_organization(1).chart_of_accounts_id := NULL;
4667   l_organization(1).effective_start_date := NULL;
4668   l_organization(1).cost_allocation_keyflex_id := NULL;
4669 
4670   l_organization(1).segment1  := NULL;
4671   l_organization(1).segment2  := NULL;
4672   l_organization(1).segment3  := NULL;
4673   l_organization(1).segment4  := NULL;
4674   l_organization(1).segment5  := NULL;
4675   l_organization(1).segment6  := NULL;
4676   l_organization(1).segment7  := NULL;
4677   l_organization(1).segment8  := NULL;
4678   l_organization(1).segment9  := NULL;
4679   l_organization(1).segment10 := NULL;
4680   l_organization(1).segment11 := NULL;
4681   l_organization(1).segment12 := NULL;
4682   l_organization(1).segment13 := NULL;
4683   l_organization(1).segment14 := NULL;
4684   l_organization(1).segment15 := NULL;
4685   l_organization(1).segment16 := NULL;
4686   l_organization(1).segment17 := NULL;
4687   l_organization(1).segment18 := NULL;
4688   l_organization(1).segment19 := NULL;
4689   l_organization(1).segment20 := NULL;
4690   l_organization(1).segment21 := NULL;
4691   l_organization(1).segment22 := NULL;
4692   l_organization(1).segment23 := NULL;
4693   l_organization(1).segment24 := NULL;
4694   l_organization(1).segment25 := NULL;
4695   l_organization(1).segment26 := NULL;
4696   l_organization(1).segment27 := NULL;
4697   l_organization(1).segment28 := NULL;
4698   l_organization(1).segment29 := NULL;
4699   l_organization(1).segment30 := NULL;
4700 
4701 
4702   -- Processing cost distribution data from interface.
4703   FOR l_dist_rec in l_dist_csr LOOP
4704 
4705     IF l_dist_rec.costing_level = 'ASSIGNMENT' THEN
4706 
4707       l_num_assignment := nvl(l_num_assignment, 0) + 1;
4708 
4709       l_assignment(l_num_assignment).chart_of_accounts_id :=
4710 					 l_dist_rec.chart_of_accounts_id;
4711       l_assignment(l_num_assignment).proportion := l_dist_rec.proportion;
4712       l_assignment(l_num_assignment).project_id := l_dist_rec.project_id;
4713       l_assignment(l_num_assignment).task_id    := l_dist_rec.task_id;
4714       l_assignment(l_num_assignment).expenditure_type :=
4715 					 l_dist_rec.expenditure_type;
4716       l_assignment(l_num_assignment).expenditure_org_id :=
4717 					 l_dist_rec.expenditure_organization_id;
4718       l_assignment(l_num_assignment).award_id :=
4719 					 l_dist_rec.award_id;
4720       l_assignment(l_num_assignment).description := l_dist_rec.description;
4721       l_assignment(l_num_assignment).cost_allocation_keyflex_id :=
4722 					 l_dist_rec.cost_allocation_keyflex_id;
4723       l_assignment(l_num_assignment).effective_start_date :=
4724 					 l_dist_rec.effective_start_date;
4725       l_assignment(l_num_assignment).segment1 := l_dist_rec.segment1;
4726       l_assignment(l_num_assignment).segment2 := l_dist_rec.segment2;
4727       l_assignment(l_num_assignment).segment3 := l_dist_rec.segment3;
4728       l_assignment(l_num_assignment).segment4 := l_dist_rec.segment4;
4729       l_assignment(l_num_assignment).segment5 := l_dist_rec.segment5;
4730       l_assignment(l_num_assignment).segment6 := l_dist_rec.segment6;
4731       l_assignment(l_num_assignment).segment7 := l_dist_rec.segment7;
4732       l_assignment(l_num_assignment).segment8 := l_dist_rec.segment8;
4733       l_assignment(l_num_assignment).segment9 := l_dist_rec.segment9;
4734       l_assignment(l_num_assignment).segment10 := l_dist_rec.segment10;
4735       l_assignment(l_num_assignment).segment11 := l_dist_rec.segment11;
4736       l_assignment(l_num_assignment).segment12 := l_dist_rec.segment12;
4737       l_assignment(l_num_assignment).segment13 := l_dist_rec.segment13;
4738       l_assignment(l_num_assignment).segment14 := l_dist_rec.segment14;
4739       l_assignment(l_num_assignment).segment15 := l_dist_rec.segment15;
4740       l_assignment(l_num_assignment).segment16 := l_dist_rec.segment16;
4741       l_assignment(l_num_assignment).segment17 := l_dist_rec.segment17;
4742       l_assignment(l_num_assignment).segment18 := l_dist_rec.segment18;
4743       l_assignment(l_num_assignment).segment19 := l_dist_rec.segment19;
4744       l_assignment(l_num_assignment).segment20 := l_dist_rec.segment20;
4745       l_assignment(l_num_assignment).segment21 := l_dist_rec.segment21;
4746       l_assignment(l_num_assignment).segment22 := l_dist_rec.segment22;
4747       l_assignment(l_num_assignment).segment23 := l_dist_rec.segment23;
4748       l_assignment(l_num_assignment).segment24 := l_dist_rec.segment24;
4749       l_assignment(l_num_assignment).segment25 := l_dist_rec.segment25;
4750       l_assignment(l_num_assignment).segment26 := l_dist_rec.segment26;
4751       l_assignment(l_num_assignment).segment27 := l_dist_rec.segment27;
4752       l_assignment(l_num_assignment).segment28 := l_dist_rec.segment28;
4753       l_assignment(l_num_assignment).segment29 := l_dist_rec.segment29;
4754       l_assignment(l_num_assignment).segment30 := l_dist_rec.segment30;
4755 
4756     ELSIF l_dist_rec.costing_level = 'PAYROLL' THEN
4757 
4758       l_num_payroll  := 1;
4759       l_payroll(1).chart_of_accounts_id := l_dist_rec.chart_of_accounts_id;
4760       l_payroll(1).cost_allocation_keyflex_id :=
4761 				     l_dist_rec.cost_allocation_keyflex_id;
4762       l_payroll(1).segment1 := l_dist_rec.segment1;
4763       l_payroll(1).segment2 := l_dist_rec.segment2;
4764       l_payroll(1).segment3 := l_dist_rec.segment3;
4765       l_payroll(1).segment4 := l_dist_rec.segment4;
4766       l_payroll(1).segment5 := l_dist_rec.segment5;
4767       l_payroll(1).segment6 := l_dist_rec.segment6;
4768       l_payroll(1).segment7 := l_dist_rec.segment7;
4769       l_payroll(1).segment8 := l_dist_rec.segment8;
4770       l_payroll(1).segment9 := l_dist_rec.segment9;
4771       l_payroll(1).segment10 := l_dist_rec.segment10;
4772       l_payroll(1).segment11 := l_dist_rec.segment11;
4773       l_payroll(1).segment12 := l_dist_rec.segment12;
4774       l_payroll(1).segment13 := l_dist_rec.segment13;
4775       l_payroll(1).segment14 := l_dist_rec.segment14;
4776       l_payroll(1).segment15 := l_dist_rec.segment15;
4777       l_payroll(1).segment16 := l_dist_rec.segment16;
4778       l_payroll(1).segment17 := l_dist_rec.segment17;
4779       l_payroll(1).segment18 := l_dist_rec.segment18;
4780       l_payroll(1).segment19 := l_dist_rec.segment19;
4781       l_payroll(1).segment20 := l_dist_rec.segment20;
4782       l_payroll(1).segment21 := l_dist_rec.segment21;
4783       l_payroll(1).segment22 := l_dist_rec.segment22;
4784       l_payroll(1).segment23 := l_dist_rec.segment23;
4785       l_payroll(1).segment24 := l_dist_rec.segment24;
4786       l_payroll(1).segment25 := l_dist_rec.segment25;
4787       l_payroll(1).segment26 := l_dist_rec.segment26;
4788       l_payroll(1).segment27 := l_dist_rec.segment27;
4789       l_payroll(1).segment28 := l_dist_rec.segment28;
4790       l_payroll(1).segment29 := l_dist_rec.segment29;
4791       l_payroll(1).segment30 := l_dist_rec.segment30;
4792 
4793     ELSIF l_dist_rec.costing_level = 'ORGANIZATION' THEN
4794 
4795       l_num_organization  := 1;
4796       l_organization(1).chart_of_accounts_id := l_dist_rec.chart_of_accounts_id;
4797       l_organization(1).cost_allocation_keyflex_id :=
4798 			l_dist_rec.cost_allocation_keyflex_id;
4799       l_organization(1).segment1 := l_dist_rec.segment1;
4800       l_organization(1).segment2 := l_dist_rec.segment2;
4801       l_organization(1).segment3 := l_dist_rec.segment3;
4802       l_organization(1).segment4 := l_dist_rec.segment4;
4803       l_organization(1).segment5 := l_dist_rec.segment5;
4804       l_organization(1).segment6 := l_dist_rec.segment6;
4805       l_organization(1).segment7 := l_dist_rec.segment7;
4806       l_organization(1).segment8 := l_dist_rec.segment8;
4807       l_organization(1).segment9 := l_dist_rec.segment9;
4808       l_organization(1).segment10 := l_dist_rec.segment10;
4809       l_organization(1).segment11 := l_dist_rec.segment11;
4810       l_organization(1).segment12 := l_dist_rec.segment12;
4811       l_organization(1).segment13 := l_dist_rec.segment13;
4812       l_organization(1).segment14 := l_dist_rec.segment14;
4813       l_organization(1).segment15 := l_dist_rec.segment15;
4814       l_organization(1).segment16 := l_dist_rec.segment16;
4815       l_organization(1).segment17 := l_dist_rec.segment17;
4816       l_organization(1).segment18 := l_dist_rec.segment18;
4817       l_organization(1).segment19 := l_dist_rec.segment19;
4818       l_organization(1).segment20 := l_dist_rec.segment20;
4819       l_organization(1).segment21 := l_dist_rec.segment21;
4820       l_organization(1).segment22 := l_dist_rec.segment22;
4821       l_organization(1).segment23 := l_dist_rec.segment23;
4822       l_organization(1).segment24 := l_dist_rec.segment24;
4823       l_organization(1).segment25 := l_dist_rec.segment25;
4824       l_organization(1).segment26 := l_dist_rec.segment26;
4825       l_organization(1).segment27 := l_dist_rec.segment27;
4826       l_organization(1).segment28 := l_dist_rec.segment28;
4827       l_organization(1).segment29 := l_dist_rec.segment29;
4828       l_organization(1).segment30 := l_dist_rec.segment30;
4829 
4830     ELSIF l_dist_rec.costing_level = 'ELEMENT LINK' THEN
4831 
4832       l_num_element   := 1;
4833       l_element_link(1).chart_of_accounts_id := l_dist_rec.chart_of_accounts_id;
4834       l_element_link(1).cost_allocation_keyflex_id :=
4835 					  l_dist_rec.cost_allocation_keyflex_id;
4836       l_element_link(1).segment1 := l_dist_rec.segment1;
4837       l_element_link(1).segment2 := l_dist_rec.segment2;
4838       l_element_link(1).segment3 := l_dist_rec.segment3;
4839       l_element_link(1).segment4 := l_dist_rec.segment4;
4840       l_element_link(1).segment5 := l_dist_rec.segment5;
4841       l_element_link(1).segment6 := l_dist_rec.segment6;
4842       l_element_link(1).segment7 := l_dist_rec.segment7;
4843       l_element_link(1).segment8 := l_dist_rec.segment8;
4844       l_element_link(1).segment9 := l_dist_rec.segment9;
4845       l_element_link(1).segment10 := l_dist_rec.segment10;
4846       l_element_link(1).segment11 := l_dist_rec.segment11;
4847       l_element_link(1).segment12 := l_dist_rec.segment12;
4848       l_element_link(1).segment13 := l_dist_rec.segment13;
4849       l_element_link(1).segment14 := l_dist_rec.segment14;
4850       l_element_link(1).segment15 := l_dist_rec.segment15;
4851       l_element_link(1).segment16 := l_dist_rec.segment16;
4852       l_element_link(1).segment17 := l_dist_rec.segment17;
4853       l_element_link(1).segment18 := l_dist_rec.segment18;
4854       l_element_link(1).segment19 := l_dist_rec.segment19;
4855       l_element_link(1).segment20 := l_dist_rec.segment20;
4856       l_element_link(1).segment21 := l_dist_rec.segment21;
4857       l_element_link(1).segment22 := l_dist_rec.segment22;
4858       l_element_link(1).segment23 := l_dist_rec.segment23;
4859       l_element_link(1).segment24 := l_dist_rec.segment24;
4860       l_element_link(1).segment25 := l_dist_rec.segment25;
4861       l_element_link(1).segment26 := l_dist_rec.segment26;
4862       l_element_link(1).segment27 := l_dist_rec.segment27;
4863       l_element_link(1).segment28 := l_dist_rec.segment28;
4864       l_element_link(1).segment29 := l_dist_rec.segment29;
4865       l_element_link(1).segment30 := l_dist_rec.segment30;
4866 
4867     END IF;
4868 
4869   END LOOP;
4870 
4871   IF (l_num_assignment > 0) THEN
4872     l_process_num := l_num_assignment;
4873   ELSIF (l_num_payroll > 0) THEN
4874     l_process_num := l_num_payroll;
4875     l_flex_code   := l_payroll(1).chart_of_accounts_id;
4876     l_proportion  := 100;
4877   ELSIF (l_num_organization > 0) THEN
4878     l_process_num := l_num_organization;
4879     l_flex_code   := l_organization(1).chart_of_accounts_id;
4880     l_proportion  := 100;
4881   ELSIF (l_num_element > 0) THEN
4882     l_process_num := l_num_element;
4883     l_flex_code   := l_element_link(1).chart_of_accounts_id;
4884     l_proportion  := 100;
4885   END IF;
4886 
4887   FOR l_assign_index in 1..l_process_num LOOP
4888 
4889     IF l_num_assignment > 0 THEN
4890       l_flex_code          := l_assignment(l_assign_index).chart_of_accounts_id;
4891       l_proportion         := l_assignment(l_assign_index).proportion;
4892       l_project_id         := l_assignment(l_assign_index).project_id;
4893       l_task_id            := l_assignment(l_assign_index).task_id;
4894       l_expenditure_type   := l_assignment(l_assign_index).expenditure_type;
4895       l_expenditure_org_id := l_assignment(l_assign_index).expenditure_org_id;
4896       l_award_id           := l_assignment(l_assign_index).award_id;
4897       l_description        := l_assignment(l_assign_index).description;
4898     END IF;
4899 
4900     l_ccid := NULL;
4901 
4902     --
4903     -- Check project_id, if it is not null means we have POETA information
4904     -- available. Call Account Generator API to generate CCID from the POETA.
4905     --
4906     IF l_assignment(l_assign_index).project_id IS NOT NULL THEN
4907 
4908       --
4909       -- Generate accounts as per the profile value defined by the user. The
4910       -- l_use_account_generator_flag is populated at the beginning of this API.
4911       --
4912       IF l_use_account_generator_flag = 'Y' THEN
4913         --
4914         PSB_Workflow_Pvt.Generate_Account
4915         (  p_api_version                 => 1.0,
4916            p_return_status               => l_return_status,
4917            p_msg_count                   => l_msg_count,
4918            p_msg_data                    => l_msg_data,
4919            p_project_id                  => l_project_id,
4920            p_task_id                     => l_task_id,
4921            p_award_id                    => l_award_id,
4922            p_expenditure_type            => l_expenditure_type,
4923            p_expenditure_organization_id => l_expenditure_org_id,
4924            p_chart_of_accounts_id        => l_flex_code,
4925            p_description                 => l_description,
4926            p_code_combination_id         => l_ccid,
4927            p_error_message               => l_error_message
4928         );
4929 	-- If API did not complete normally, raise error coming from called API.
4930 	IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4931 	  RAISE FND_API.G_EXC_ERROR;
4932 	END IF ;
4933 
4934         -- Check if CCID got generated.
4935 	IF l_ccid IS NULL THEN
4936 
4937 	  -- Fetching position name to be used for messaging.
4938 	  IF p_position_id IS NOT NULL THEN
4939 	    FOR Pos_Name_Rec IN
4940               G_Position_Details(p_position_id => p_position_id)
4941 	    LOOP
4942 	      l_position_name := Pos_Name_Rec.name;
4943 	    END LOOP;
4944 	  END IF;
4945 
4946 	  --
4947 	  -- Decode l_error_message as l_error_message is always supposed to be
4948 	  -- in encoded format only as per Workflow Account Generator standards.
4949 	  --
4950 	  fnd_message.parse_encoded( l_error_message   ,
4951                                      l_appl_short_name ,
4952                                      l_message_name
4953                                    ) ;
4954 	  l_message_text := fnd_message.get_string( l_appl_short_name,
4955                                                     l_message_name);
4956 	  -- End encoding the messages retrieved as l_error_message.
4957 
4958 	  FND_MESSAGE.SET_NAME('PSB', 'PSB_POETA_TO_CCID_FAILURE');
4959 	  FND_MESSAGE.SET_TOKEN('POSITION_NAME',    l_position_name );
4960 	  FND_MESSAGE.SET_TOKEN('PROJECT_ID',       l_project_id );
4961 	  FND_MESSAGE.SET_TOKEN('TASK_ID',          l_task_id );
4962 	  FND_MESSAGE.SET_TOKEN('AWARD_ID',         l_award_id );
4963 	  FND_MESSAGE.SET_TOKEN('EXPENDITURE_TYPE', l_expenditure_type );
4964 	  FND_MESSAGE.SET_TOKEN('EXPENDITURE_ORGANIZATION_ID',
4965 						  l_expenditure_org_id );
4966 	  FND_MSG_PUB.ADD;
4967 
4968 	  -- Added an extra message as one message was getting truncated in
4969 	  -- the request out file.
4970 	  FND_MESSAGE.SET_NAME('PSB', 'PSB_POETA_AG_ERROR_MESSAGE');
4971 	  FND_MESSAGE.SET_TOKEN('ERROR_MESSAGE',    l_message_text);
4972 	  FND_MSG_PUB.ADD;
4973 
4974         END IF;
4975         -- End checking if CCID got generated.
4976 
4977       END IF; -- End ( IF l_use_account_generator_flag = 'Y' )
4978       --
4979 
4980     -- If project_id is null, we generate CCID out of segment information.
4981     ELSIF (l_assignment(l_assign_index).project_id IS NULL) THEN
4982 
4983       IF l_flex_code <> NVL(PSB_WS_ACCT1.g_flex_code, FND_API.G_MISS_NUM) THEN
4984         --
4985         PSB_WS_ACCT1.Flex_Info
4986         ( p_flex_code     => l_flex_code,
4987           p_return_status => l_return_status
4988         ) ;
4989 	IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4990 	  RAISE FND_API.G_EXC_ERROR;
4991 	END IF;
4992         --
4993       END IF;
4994 
4995       -- Concatenate cost_allocation_keyflex_id and store it in description.
4996       l_description := NULL;
4997 
4998       IF l_assignment(l_assign_index).cost_allocation_keyflex_id IS NOT NULL
4999       THEN
5000 	 l_description := l_description || '#A;' ||
5001 	       to_char(l_assignment(l_assign_index).cost_allocation_keyflex_id)
5002 		      || ';' ;
5003       END IF;
5004 
5005       IF l_organization(1).cost_allocation_keyflex_id IS NOT NULL THEN
5006 	 l_description := l_description || 'O;' ||
5007 	       to_char(l_organization(1).cost_allocation_keyflex_id) || ';';
5008       END IF;
5009 
5010       IF l_element_link(1).cost_allocation_keyflex_id IS NOT NULL THEN
5011 	 l_description := l_description || 'E;' ||
5012 	       to_char(l_element_link(1).cost_allocation_keyflex_id) || ';';
5013       END IF;
5014 
5015       IF l_payroll(1).cost_allocation_keyflex_id IS NOT NULL THEN
5016 	 l_description := l_description || 'P;' ||
5017 	       to_char(l_payroll(1).cost_allocation_keyflex_id) || ';#';
5018       END IF;
5019 
5020       FOR l_init_index in 1..PSB_WS_ACCT1.g_num_segs LOOP
5021 	l_ccid_val(l_init_index) := NULL;
5022       END LOOP;
5023 
5024       FOR l_segment_index in 1..PSB_WS_ACCT1.g_num_segs
5025       LOOP
5026 
5027 	IF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT1' THEN
5028 
5029 	  IF l_assignment(l_assign_index).segment1 IS NOT NULL THEN
5030 	    l_ccid_val(l_segment_index) :=
5031 					 l_assignment(l_assign_index).segment1;
5032 	  ELSIF (l_organization(1).segment1 IS NOT NULL) THEN
5033 	    l_ccid_val(l_segment_index) := l_organization(1).segment1;
5034 	  ELSIF (l_element_link(1).segment1 IS NOT NULL) THEN
5035 	    l_ccid_val(l_segment_index) := l_element_link(1).segment1;
5036 	  ELSIF (l_payroll(1).segment1 IS NOT NULL) THEN
5037 	    l_ccid_val(l_segment_index) := l_payroll(1).segment1;
5038 	  END IF;
5039 
5040 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT2' THEN
5041 
5042 	  IF l_assignment(l_assign_index).segment2 IS NOT NULL THEN
5043 	    l_ccid_val(l_segment_index) :=
5044 					 l_assignment(l_assign_index).segment2;
5045 	  ELSIF (l_organization(1).segment2 IS NOT NULL) THEN
5046 	    l_ccid_val(l_segment_index) := l_organization(1).segment2;
5047 	  ELSIF (l_element_link(1).segment2 IS NOT NULL) THEN
5048 	    l_ccid_val(l_segment_index) := l_element_link(1).segment2;
5049 	  ELSIF (l_payroll(1).segment2 IS NOT NULL) THEN
5050 	    l_ccid_val(l_segment_index) := l_payroll(1).segment2;
5051 	  END IF;
5052 
5053 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT3' THEN
5054 
5055 	  IF l_assignment(l_assign_index).segment3 IS NOT NULL THEN
5056 	    l_ccid_val(l_segment_index) :=
5057 					 l_assignment(l_assign_index).segment3;
5058 	  ELSIF (l_organization(1).segment3 IS NOT NULL) THEN
5059 	    l_ccid_val(l_segment_index) := l_organization(1).segment3;
5060 	  ELSIF (l_element_link(1).segment3 IS NOT NULL) THEN
5061 	    l_ccid_val(l_segment_index) := l_element_link(1).segment3;
5062 	  ELSIF (l_payroll(1).segment3 IS NOT NULL) THEN
5063 	    l_ccid_val(l_segment_index) := l_payroll(1).segment3;
5064 	  END IF;
5065 
5066 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT4' THEN
5067 
5068 	  IF l_assignment(l_assign_index).segment4 IS NOT NULL THEN
5069 	    l_ccid_val(l_segment_index) :=
5070 					 l_assignment(l_assign_index).segment4;
5071 	  ELSIF (l_organization(1).segment4 IS NOT NULL) THEN
5072 	    l_ccid_val(l_segment_index) := l_organization(1).segment4;
5073 	  ELSIF (l_element_link(1).segment4 IS NOT NULL) THEN
5074 	    l_ccid_val(l_segment_index) := l_element_link(1).segment4;
5075 	  ELSIF (l_payroll(1).segment4 IS NOT NULL) THEN
5076 	    l_ccid_val(l_segment_index) := l_payroll(1).segment4;
5077 	  END IF;
5078 
5079 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT5' THEN
5080 
5081 	  IF l_assignment(l_assign_index).segment5 IS NOT NULL THEN
5082 	    l_ccid_val(l_segment_index) :=
5083 					 l_assignment(l_assign_index).segment5;
5084 	  ELSIF (l_organization(1).segment5 IS NOT NULL) THEN
5085 	    l_ccid_val(l_segment_index) := l_organization(1).segment5;
5086 	  ELSIF (l_element_link(1).segment5 IS NOT NULL) THEN
5087 	    l_ccid_val(l_segment_index) := l_element_link(1).segment5;
5088 	  ELSIF (l_payroll(1).segment5 IS NOT NULL) THEN
5089 	    l_ccid_val(l_segment_index) := l_payroll(1).segment5;
5090 	  END IF;
5091 
5092 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT6' THEN
5093 
5094 	  IF l_assignment(l_assign_index).segment6 IS NOT NULL THEN
5095 	    l_ccid_val(l_segment_index) :=
5096 					 l_assignment(l_assign_index).segment6;
5097 	  ELSIF (l_organization(1).segment6 IS NOT NULL) THEN
5098 	    l_ccid_val(l_segment_index) := l_organization(1).segment6;
5099 	  ELSIF (l_element_link(1).segment6 IS NOT NULL) THEN
5100 	    l_ccid_val(l_segment_index) := l_element_link(1).segment6;
5101 	  ELSIF (l_payroll(1).segment6 IS NOT NULL) THEN
5102 	    l_ccid_val(l_segment_index) := l_payroll(1).segment6;
5103 	  END IF;
5104 
5105 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT7' THEN
5106 
5107 	  IF l_assignment(l_assign_index).segment7 IS NOT NULL THEN
5108 	    l_ccid_val(l_segment_index) :=
5109 					 l_assignment(l_assign_index).segment7;
5110 	  ELSIF (l_organization(1).segment7 IS NOT NULL) THEN
5111 	    l_ccid_val(l_segment_index) := l_organization(1).segment7;
5112 	  ELSIF (l_element_link(1).segment7 IS NOT NULL) THEN
5113 	    l_ccid_val(l_segment_index) := l_element_link(1).segment7;
5114 	  ELSIF (l_payroll(1).segment7 IS NOT NULL) THEN
5115 	    l_ccid_val(l_segment_index) := l_payroll(1).segment7;
5116 	  END IF;
5117 
5118 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT8' THEN
5119 
5120 	  IF l_assignment(l_assign_index).segment8 IS NOT NULL THEN
5121 	    l_ccid_val(l_segment_index) :=
5122 					 l_assignment(l_assign_index).segment8;
5123 	  ELSIF (l_organization(1).segment8 IS NOT NULL) THEN
5124 	    l_ccid_val(l_segment_index) := l_organization(1).segment8;
5125 	  ELSIF (l_element_link(1).segment8 IS NOT NULL) THEN
5126 	    l_ccid_val(l_segment_index) := l_element_link(1).segment8;
5127 	  ELSIF (l_payroll(1).segment8 IS NOT NULL) THEN
5128 	    l_ccid_val(l_segment_index) := l_payroll(1).segment8;
5129 	  END IF;
5130 
5131 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT9' THEN
5132 
5133 	  IF l_assignment(l_assign_index).segment9 IS NOT NULL THEN
5134 	    l_ccid_val(l_segment_index) :=
5135 					 l_assignment(l_assign_index).segment9;
5136 	  ELSIF (l_organization(1).segment9 IS NOT NULL) THEN
5137 	    l_ccid_val(l_segment_index) := l_organization(1).segment9;
5138 	  ELSIF (l_element_link(1).segment9 IS NOT NULL) THEN
5139 	    l_ccid_val(l_segment_index) := l_element_link(1).segment9;
5140 	  ELSIF (l_payroll(1).segment9 IS NOT NULL) THEN
5141 	    l_ccid_val(l_segment_index) := l_payroll(1).segment9;
5142 	  END IF;
5143 
5144 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT10' THEN
5145 
5146 	  IF l_assignment(l_assign_index).segment10 IS NOT NULL THEN
5147 	    l_ccid_val(l_segment_index) :=
5148 					l_assignment(l_assign_index).segment10;
5149 	  ELSIF (l_organization(1).segment10 IS NOT NULL) THEN
5150 	    l_ccid_val(l_segment_index) := l_organization(1).segment10;
5151 	  ELSIF (l_element_link(1).segment10 IS NOT NULL) THEN
5152 	    l_ccid_val(l_segment_index) := l_element_link(1).segment10;
5153 	  ELSIF (l_payroll(1).segment10 IS NOT NULL) THEN
5154 	    l_ccid_val(l_segment_index) := l_payroll(1).segment10;
5155 	  END IF;
5156 
5157 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT11' THEN
5158 
5159 	  IF l_assignment(l_assign_index).segment11 IS NOT NULL THEN
5160 	    l_ccid_val(l_segment_index) :=
5161 					l_assignment(l_assign_index).segment11;
5162 	  ELSIF (l_organization(1).segment11 IS NOT NULL) THEN
5163 	    l_ccid_val(l_segment_index) := l_organization(1).segment11;
5164 	  ELSIF (l_element_link(1).segment11 IS NOT NULL) THEN
5165 	    l_ccid_val(l_segment_index) := l_element_link(1).segment11;
5166 	  ELSIF (l_payroll(1).segment11 IS NOT NULL) THEN
5167 	    l_ccid_val(l_segment_index) := l_payroll(1).segment11;
5168 	  END IF;
5169 
5170 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT12' THEN
5171 
5172 	  IF l_assignment(l_assign_index).segment12 IS NOT NULL THEN
5173 	    l_ccid_val(l_segment_index) :=
5174 					l_assignment(l_assign_index).segment12;
5175 	  ELSIF (l_organization(1).segment12 IS NOT NULL) THEN
5176 	    l_ccid_val(l_segment_index) := l_organization(1).segment12;
5177 	  ELSIF (l_element_link(1).segment12 IS NOT NULL) THEN
5178 	    l_ccid_val(l_segment_index) := l_element_link(1).segment12;
5179 	  ELSIF (l_payroll(1).segment12 IS NOT NULL) THEN
5180 	    l_ccid_val(l_segment_index) := l_payroll(1).segment12;
5181 	  END IF;
5182 
5183 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT13' THEN
5184 
5185 	  IF l_assignment(l_assign_index).segment13 IS NOT NULL THEN
5186 	    l_ccid_val(l_segment_index) :=
5187 					l_assignment(l_assign_index).segment13;
5188 	  ELSIF (l_organization(1).segment13 IS NOT NULL) THEN
5189 	    l_ccid_val(l_segment_index) := l_organization(1).segment13;
5190 	  ELSIF (l_element_link(1).segment13 IS NOT NULL) THEN
5191 	    l_ccid_val(l_segment_index) := l_element_link(1).segment13;
5192 	  ELSIF (l_payroll(1).segment13 IS NOT NULL) THEN
5193 	    l_ccid_val(l_segment_index) := l_payroll(1).segment13;
5194 	  END IF;
5195 
5196 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT14' THEN
5197 
5198 	  IF l_assignment(l_assign_index).segment14 IS NOT NULL THEN
5199 	    l_ccid_val(l_segment_index) :=
5200 				       l_assignment(l_assign_index).segment14;
5201 	  ELSIF (l_organization(1).segment14 IS NOT NULL) THEN
5202 	    l_ccid_val(l_segment_index) := l_organization(1).segment14;
5203 	  ELSIF (l_element_link(1).segment14 IS NOT NULL) THEN
5204 	    l_ccid_val(l_segment_index) := l_element_link(1).segment14;
5205 	  ELSIF (l_payroll(1).segment14 IS NOT NULL) THEN
5206 	    l_ccid_val(l_segment_index) := l_payroll(1).segment14;
5207 	  END IF;
5208 
5209 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT15' THEN
5210 
5211 	  IF l_assignment(l_assign_index).segment15 IS NOT NULL THEN
5212 	    l_ccid_val(l_segment_index) :=
5213 				       l_assignment(l_assign_index).segment15;
5214 	  ELSIF (l_organization(1).segment15 IS NOT NULL) THEN
5215 	    l_ccid_val(l_segment_index) := l_organization(1).segment15;
5216 	  ELSIF (l_element_link(1).segment15 IS NOT NULL) THEN
5217 	    l_ccid_val(l_segment_index) := l_element_link(1).segment15;
5218 	  ELSIF (l_payroll(1).segment15 IS NOT NULL) THEN
5219 	    l_ccid_val(l_segment_index) := l_payroll(1).segment15;
5220 	  END IF;
5221 
5222 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT16' THEN
5223 
5224 	  IF l_assignment(l_assign_index).segment16 IS NOT NULL THEN
5225 	    l_ccid_val(l_segment_index) :=
5226 				       l_assignment(l_assign_index).segment16;
5227 	  ELSIF (l_organization(1).segment16 IS NOT NULL) THEN
5228 	    l_ccid_val(l_segment_index) := l_organization(1).segment16;
5229 	  ELSIF (l_element_link(1).segment16 IS NOT NULL) THEN
5230 	    l_ccid_val(l_segment_index) := l_element_link(1).segment16;
5231 	  ELSIF (l_payroll(1).segment16 IS NOT NULL) THEN
5232 	    l_ccid_val(l_segment_index) := l_payroll(1).segment16;
5233 	  END IF;
5234 
5235 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT17' THEN
5236 
5237 	  IF l_assignment(l_assign_index).segment17 IS NOT NULL THEN
5238 	    l_ccid_val(l_segment_index) :=
5239 				       l_assignment(l_assign_index).segment17;
5240 	  ELSIF (l_organization(1).segment17 IS NOT NULL) THEN
5241 	    l_ccid_val(l_segment_index) := l_organization(1).segment17;
5242 	  ELSIF (l_element_link(1).segment17 IS NOT NULL) THEN
5243 	    l_ccid_val(l_segment_index) := l_element_link(1).segment17;
5244 	  ELSIF (l_payroll(1).segment17 IS NOT NULL) THEN
5245 	    l_ccid_val(l_segment_index) := l_payroll(1).segment17;
5246 	  END IF;
5247 
5248 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT18' THEN
5249 
5250 	  IF l_assignment(l_assign_index).segment18 IS NOT NULL THEN
5251 	    l_ccid_val(l_segment_index) :=
5252 				       l_assignment(l_assign_index).segment18;
5253 	  ELSIF (l_organization(1).segment18 IS NOT NULL) THEN
5254 	    l_ccid_val(l_segment_index) := l_organization(1).segment18;
5255 	  ELSIF (l_element_link(1).segment18 IS NOT NULL) THEN
5256 	    l_ccid_val(l_segment_index) := l_element_link(1).segment18;
5257 	  ELSIF (l_payroll(1).segment18 IS NOT NULL) THEN
5258 	  l_ccid_val(l_segment_index) := l_payroll(1).segment18;
5259 	    END IF;
5260 
5261 	  ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT19' THEN
5262 
5263 	  IF l_assignment(l_assign_index).segment19 IS NOT NULL THEN
5264 	    l_ccid_val(l_segment_index) :=
5265 				       l_assignment(l_assign_index).segment19;
5266 	  ELSIF (l_organization(1).segment19 IS NOT NULL) THEN
5267 	    l_ccid_val(l_segment_index) := l_organization(1).segment19;
5268 	  ELSIF (l_element_link(1).segment19 IS NOT NULL) THEN
5269 	    l_ccid_val(l_segment_index) := l_element_link(1).segment19;
5270 	  ELSIF (l_payroll(1).segment19 IS NOT NULL) THEN
5271 	    l_ccid_val(l_segment_index) := l_payroll(1).segment19;
5272 	  END IF;
5273 
5274 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT20' THEN
5275 
5276 	  IF l_assignment(l_assign_index).segment20 IS NOT NULL THEN
5277 	    l_ccid_val(l_segment_index) :=
5278 				       l_assignment(l_assign_index).segment20;
5279 	  ELSIF (l_organization(1).segment20 IS NOT NULL) THEN
5280 	    l_ccid_val(l_segment_index) := l_organization(1).segment20;
5281 	  ELSIF (l_element_link(1).segment20 IS NOT NULL) THEN
5282 	    l_ccid_val(l_segment_index) := l_element_link(1).segment20;
5283 	  ELSIF (l_payroll(1).segment20 IS NOT NULL)  THEN
5284 	      l_ccid_val(l_segment_index) := l_payroll(1).segment20;
5285 	  END IF;
5286 
5287 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT21' THEN
5288 
5289 	  IF l_assignment(l_assign_index).segment21 IS NOT NULL THEN
5290 	    l_ccid_val(l_segment_index) :=
5291 				       l_assignment(l_assign_index).segment21;
5292 	  ELSIF (l_organization(1).segment21 IS NOT NULL) THEN
5293 	    l_ccid_val(l_segment_index) := l_organization(1).segment21;
5294 	  ELSIF (l_element_link(1).segment21 IS NOT NULL) THEN
5295 	    l_ccid_val(l_segment_index) := l_element_link(1).segment21;
5296 	  ELSIF (l_payroll(1).segment21 IS NOT NULL) THEN
5297 	    l_ccid_val(l_segment_index) := l_payroll(1).segment21;
5298 	  END IF;
5299 
5300 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT22' THEN
5301 
5302 	  IF l_assignment(l_assign_index).segment22 IS NOT NULL THEN
5303 	    l_ccid_val(l_segment_index) :=
5304 				       l_assignment(l_assign_index).segment22;
5305 	  ELSIF (l_organization(1).segment22 IS NOT NULL) THEN
5306 	    l_ccid_val(l_segment_index) := l_organization(1).segment22;
5307 	  ELSIF (l_element_link(1).segment22 IS NOT NULL) THEN
5308 	    l_ccid_val(l_segment_index) := l_element_link(1).segment22;
5309 	  ELSIF (l_payroll(1).segment22 IS NOT NULL) THEN
5310 	    l_ccid_val(l_segment_index) := l_payroll(1).segment22;
5311 	  END IF;
5312 
5313 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT23' THEN
5314 
5315 	  IF l_assignment(l_assign_index).segment23 IS NOT NULL THEN
5316 	    l_ccid_val(l_segment_index) :=
5317 				       l_assignment(l_assign_index).segment23;
5318 	  ELSIF (l_organization(1).segment23 IS NOT NULL) THEN
5319 	    l_ccid_val(l_segment_index) := l_organization(1).segment23;
5320 	  ELSIF (l_element_link(1).segment23 IS NOT NULL) THEN
5321 	    l_ccid_val(l_segment_index) := l_element_link(1).segment23;
5322 	  ELSIF (l_payroll(1).segment23 IS NOT NULL) THEN
5323 	    l_ccid_val(l_segment_index) := l_payroll(1).segment23;
5324 	  END IF;
5325 
5326 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT24' THEN
5327 
5328 	  IF l_assignment(l_assign_index).segment24 IS NOT NULL THEN
5329 	    l_ccid_val(l_segment_index) :=
5330 				       l_assignment(l_assign_index).segment24;
5331 	  ELSIF (l_organization(1).segment24 IS NOT NULL) THEN
5332 	    l_ccid_val(l_segment_index) := l_organization(1).segment24;
5333 	  ELSIF (l_element_link(1).segment24 IS NOT NULL) THEN
5334 	    l_ccid_val(l_segment_index) := l_element_link(1).segment24;
5335 	  ELSIF (l_payroll(1).segment24 IS NOT NULL) THEN
5336 	    l_ccid_val(l_segment_index) := l_payroll(1).segment24;
5337 	  END IF;
5338 
5339 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT25' THEN
5340 
5341 	  IF l_assignment(l_assign_index).segment25 IS NOT NULL THEN
5342 	    l_ccid_val(l_segment_index) :=
5343 				       l_assignment(l_assign_index).segment25;
5344 	  ELSIF (l_organization(1).segment25 IS NOT NULL) THEN
5345 	    l_ccid_val(l_segment_index) := l_organization(1).segment25;
5346 	  ELSIF (l_element_link(1).segment25 IS NOT NULL) THEN
5347 	    l_ccid_val(l_segment_index) := l_element_link(1).segment25;
5348 	  ELSIF (l_payroll(1).segment25 IS NOT NULL) THEN
5349 	    l_ccid_val(l_segment_index) := l_payroll(1).segment25;
5350 	  END IF;
5351 
5352 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT26' THEN
5353 
5354 	  IF l_assignment(l_assign_index).segment26 IS NOT NULL THEN
5355 	    l_ccid_val(l_segment_index) :=
5356 				       l_assignment(l_assign_index).segment26;
5357 	  ELSIF (l_organization(1).segment26 IS NOT NULL) THEN
5358 	    l_ccid_val(l_segment_index) := l_organization(1).segment26;
5359 	  ELSIF (l_element_link(1).segment26 IS NOT NULL) THEN
5360 	    l_ccid_val(l_segment_index) := l_element_link(1).segment26;
5361 	  ELSIF (l_payroll(1).segment26 IS NOT NULL) THEN
5362 	    l_ccid_val(l_segment_index) := l_payroll(1).segment26;
5363 	  END IF;
5364 
5365 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT27' THEN
5366 
5367 	  IF l_assignment(l_assign_index).segment27 IS NOT NULL THEN
5368 	    l_ccid_val(l_segment_index) :=
5369 				       l_assignment(l_assign_index).segment27;
5370 	  ELSIF (l_organization(1).segment27 IS NOT NULL) THEN
5371 	    l_ccid_val(l_segment_index) := l_organization(1).segment27;
5372 	  ELSIF (l_element_link(1).segment27 IS NOT NULL) THEN
5373 	    l_ccid_val(l_segment_index) := l_element_link(1).segment27;
5374 	  ELSIF (l_payroll(1).segment27 IS NOT NULL) THEN
5375 	    l_ccid_val(l_segment_index) := l_payroll(1).segment27;
5376 	  END IF;
5377 
5378 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT28' THEN
5379 
5380 	  IF l_assignment(l_assign_index).segment28 IS NOT NULL THEN
5381 	    l_ccid_val(l_segment_index) :=
5382 				       l_assignment(l_assign_index).segment28;
5383 	  ELSIF (l_organization(1).segment28 IS NOT NULL) THEN
5384 	    l_ccid_val(l_segment_index) := l_organization(1).segment28;
5385 	  ELSIF (l_element_link(1).segment28 IS NOT NULL) THEN
5386 	    l_ccid_val(l_segment_index) := l_element_link(1).segment28;
5387 	  ELSIF (l_payroll(1).segment28 IS NOT NULL) THEN
5388 	    l_ccid_val(l_segment_index) := l_payroll(1).segment28;
5389 	  END IF;
5390 
5391 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT29' THEN
5392 
5393 	  IF l_assignment(l_assign_index).segment29 IS NOT NULL THEN
5394 	    l_ccid_val(l_segment_index) :=
5395 				       l_assignment(l_assign_index).segment29;
5396 	  ELSIF (l_organization(1).segment29 IS NOT NULL) THEN
5397 	    l_ccid_val(l_segment_index) := l_organization(1).segment29;
5398 	  ELSIF (l_element_link(1).segment29 IS NOT NULL) THEN
5399 	    l_ccid_val(l_segment_index) := l_element_link(1).segment29;
5400 	  ELSIF (l_payroll(1).segment29 IS NOT NULL) THEN
5401 	    l_ccid_val(l_segment_index) := l_payroll(1).segment29;
5402 	  END IF;
5403 
5404 	ELSIF PSB_WS_ACCT1.g_seg_name(l_segment_index) = 'SEGMENT30' THEN
5405 
5406 	  IF l_assignment(l_assign_index).segment30 IS NOT NULL THEN
5407 	    l_ccid_val(l_segment_index) :=
5408 				       l_assignment(l_assign_index).segment30;
5409 	  ELSIF (l_organization(1).segment30 IS NOT NULL) THEN
5410 	    l_ccid_val(l_segment_index) := l_organization(1).segment30;
5411 	  ELSIF (l_element_link(1).segment30 IS NOT NULL) THEN
5412 	    l_ccid_val(l_segment_index) := l_element_link(1).segment30;
5413 	  ELSIF (l_payroll(1).segment30 IS NOT NULL) THEN
5414 	    l_ccid_val(l_segment_index) := l_payroll(1).segment30;
5415 	  END IF;
5416 
5417 	END IF;
5418 
5419       END LOOP;
5420 
5421       IF (p_position_id IS NOT NULL) THEN
5422 	FOR Pos_Name_Rec in G_Position_Details(p_position_id => p_position_id)
5423 	LOOP
5424 	  l_position_name := Pos_Name_Rec.name;
5425 	END LOOP;
5426       END IF;
5427 
5428       IF NOT FND_FLEX_EXT.Get_Combination_ID
5429       ( application_short_name => 'SQLGL',
5430 	key_flex_code          => 'GL#',
5431 	structure_number       => l_flex_code,
5432 	validation_date        => sysdate,
5433 	n_segments             => PSB_WS_ACCT1.g_num_segs,
5434 	segments               => l_ccid_val,
5435 	combination_id         => l_ccid
5436       )
5437       THEN
5438         --
5439 	FND_FILE.put_line(FND_FILE.LOG,
5440 			  'Cannot create CCID FOR position '|| p_position_id);
5441 	l_msg := FND_MESSAGE.Get;
5442 	FND_FILE.put_line(FND_FILE.LOG,l_msg);
5443 	FND_MESSAGE.SET_NAME('PSB','PSB_POSITION_COST_CCID_FAILURE');
5444 	FND_MESSAGE.SET_TOKEN('POSITION_NAME',l_position_name );
5445 	FND_MESSAGE.SET_TOKEN('ERR_MESG',l_msg);
5446 	FND_MSG_PUB.Add;
5447 	RETURN;
5448         --
5449       END IF;
5450 
5451     END IF ;
5452     -- End generating CCID from POETA or segments.
5453 
5454     IF (l_process_num > 1) THEN
5455       l_payroll(l_process_num).effective_start_date := NULL;
5456       l_organization(l_process_num).effective_start_date := NULL;
5457       l_element_link(l_process_num).effective_start_date := NULL;
5458     END IF;
5459 
5460     l_process_start_date :=
5461 	    greatest( nvl(l_payroll(l_process_num).effective_start_date,
5462 					    l_default_start_date),
5463 	    nvl(l_assignment(l_process_num).effective_start_date,
5464 	    l_default_start_date),
5465 	    nvl(l_organization(l_process_num).effective_start_date,
5466 	    l_default_start_date),
5467 	    nvl(l_element_link(l_process_num).effective_start_date,
5468 	    l_default_start_date),
5469 	    p_position_start_date);
5470 
5471     --
5472     -- Bug#3467512: As psb_cost_distributions_i is open interface table, it can
5473     -- be populated with duplicate records where CCID and Effective start dates
5474     -- are same but percent is different as reported in bug. To fix this, we
5475     -- need to consolidate percent by CCID and Effective start date.
5476     --
5477     l_ccid_exists := FALSE;
5478     FOR j IN 1..i LOOP
5479       --
5480       IF lh_distribution(j).ccid = l_ccid
5481          AND
5482          lh_distribution(j).effective_start_date = l_process_start_date
5483       THEN
5484         lh_distribution(j).distr_percent := NVL(l_proportion, 0)    +
5485                            NVL(lh_distribution(j).distr_percent, 0) ;
5486         --
5487         IF  lh_distribution(j).distr_percent > 100 THEN
5488           lh_distribution(j).distr_percent := 100 ;
5489         END IF;
5490         --
5491         l_ccid_exists := TRUE;
5492         EXIT;
5493       END IF;
5494       --
5495     END LOOP;
5496 
5497     IF NOT l_ccid_exists THEN
5498       i := i + 1 ;
5499       lh_distribution(i).ccid                 := l_ccid;
5500       lh_distribution(i).distr_percent        := l_proportion;
5501       lh_distribution(i).effective_start_date := l_process_start_date;
5502       lh_distribution(i).effective_end_date   := p_position_end_date;
5503       lh_distribution(i).project_id           := l_project_id;
5504       lh_distribution(i).task_id              := l_task_id;
5505       lh_distribution(i).award_id             := l_award_id;
5506       lh_distribution(i).expenditure_type     := l_expenditure_type;
5507       lh_distribution(i).expenditure_org_id   := l_expenditure_org_id;
5508       lh_distribution(i).exist_flag           := 'N';
5509       lh_distribution(i).description          := l_description;
5510     END IF;
5511     -- Bug#3467512: End
5512 
5513   END LOOP;
5514   -- End processing l_dist_csr cursor.
5515 
5516   PSB_POSITION_PAY_DISTR_PVT.Modify_Extract_Distribution
5517   ( p_api_version          => 1.0,
5518     p_init_msg_list        => FND_API.G_FALSE,
5519     p_commit               => FND_API.G_FALSE,
5520     p_validation_level     => FND_API.G_VALID_LEVEL_FULL,
5521     p_return_status        => l_return_status,
5522     p_msg_count            => l_msg_count,
5523     p_msg_data             => l_msg_data,
5524     p_position_id          => p_position_id,
5525     p_data_extract_id      => p_data_extract_id,
5526     p_chart_of_accounts_id => l_flex_code,
5527     p_distribution         => lh_distribution
5528   ) ;
5529   --
5530   IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5531     RAISE FND_API.G_EXC_ERROR;
5532   END IF;
5533 
5534   -- Initialize API return status to success
5535   p_return_status := FND_API.G_RET_STS_SUCCESS;
5536 
5537 EXCEPTION
5538 
5539   WHEN FND_API.G_EXC_ERROR THEN
5540     p_return_status := FND_API.G_RET_STS_ERROR;
5541 
5542   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5543     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5544 
5545   WHEN OTHERS THEN
5546     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5547 
5548 END Create_Salary_Dist_Pos;
5549 /*---------------------------------------------------------------------------*/
5550 
5551 
5552 /*===========================================================================+
5553  |                     PROCEDURE Populate_Position_Information               |
5554  +===========================================================================*/
5555 PROCEDURE Populate_Position_Information
5556 ( p_api_version         IN         NUMBER,
5557   p_init_msg_lISt       IN         VARCHAR2 := FND_API.G_FALSE,
5558   p_commit              IN         VARCHAR2 := FND_API.G_FALSE,
5559   p_validation_level    IN         NUMBER   := FND_API.G_VALID_LEVEL_FULL,
5560   p_return_status       OUT NOCOPY VARCHAR2,
5561   p_msg_count           OUT NOCOPY NUMBER,
5562   p_msg_data            OUT NOCOPY VARCHAR2,
5563   p_data_extract_id     IN         NUMBER,
5564   -- DE by Org
5565   p_extract_by_org      IN         VARCHAR2,
5566   p_extract_method      IN         VARCHAR2,
5567   p_business_group_id   IN         NUMBER,
5568   p_set_of_books_id     IN         NUMBER
5569 )
5570 IS
5571   --
5572   l_api_name            CONSTANT VARCHAR2(30) :='Populate_Position_Information';
5573   l_api_version         CONSTANT NUMBER       := 1.0;
5574 
5575   l_last_update_date    DATE;
5576   l_last_updated_by     number;
5577   l_last_update_login   number;
5578   l_creation_date       DATE;
5579   l_created_BY          number;
5580   segs                  FND_FLEX_EXT.SegmentArray;
5581   tf                    boolean;
5582   l_ccid                NUMBER;
5583   l_id_flex_num         NUMBER;
5584   l_concat_pos_name     varchar2(240);
5585 
5586   l_init_index          BINARY_INTEGER;
5587   l_status              varchar2(1);
5588 
5589   l_rowid                  varchar2(100);
5590   l_position_name          varchar2(240);
5591   l_employee_name          varchar2(310);
5592   l_urowid                 varchar2(100);
5593   l_dummy                  number := 0;
5594   l_elem_assign_dummy      number := 0;
5595   l_position_assignment_id number := 0;
5596   r_count                  number := 0;
5597   l_restart_hr_position_id number := 0;
5598   l_hr_position_ctr        number := 0;
5599   prev_hr_position_id      number := -1;
5600   l_position_id            number;
5601   l_vacant_position_flag   varchar2(1);
5602   l_return_status          varchar2(1);
5603   l_msg_count              number;
5604   l_msg_data               varchar2(1000);
5605   l_msg                    varchar2(2000);
5606 
5607   l_rate_or_payscale_id   number := -1;
5608   l_rate_or_payscale_name varchar2(30);
5609   l_grade_step            number;
5610   l_grade_id              number;
5611   l_grade_name            varchar2(80);
5612   l_sequence_number       number;
5613 
5614   l_pay_element_id         number;
5615   l_pay_element_option_id  number;
5616   l_pay_element_rate_id    number;
5617   l_element_value          number;
5618   l_effective_start_date   date;
5619   l_effective_end_date     date;
5620   l_salary_type            varchar2(10);
5621   l_currency_code          varchar2(30);
5622 
5623   -- DE by Org
5624   l_extract_method         varchar2(30);
5625   l_status_flag            varchar2(1):='C';
5626   l_update_flag            varchar2(1):='N';
5627   l_last_success_flag      varchar2(1):='Y';
5628   --
5629   Cursor C_salary IS
5630      Select rate_or_payscale_name,grade_name
5631        FROM psb_salary_i
5632       WHERE rate_or_payscale_id  = l_rate_or_payscale_id
5633 	AND grade_id             = l_grade_id
5634 	AND grade_step           = l_grade_step
5635 	AND sequence_number      = l_sequence_number
5636 	AND data_extract_id      = p_data_extract_id;
5637 
5638   Cursor C_rate_salary IS
5639      Select rate_or_payscale_name,grade_name
5640        FROM psb_salary_i
5641       WHERE rate_or_payscale_id = l_rate_or_payscale_id
5642 	AND grade_id            = l_grade_id
5643 	AND data_extract_id     = p_data_extract_id;
5644 
5645   Cursor C_pay_elements_step IS
5646      Select ppe.pay_element_id ,ppe.salary_type,
5647 	    ppo.pay_element_option_id
5648        FROM psb_pay_elements ppe,
5649 	    psb_pay_element_options ppo
5650       WHERE ppe.data_extract_id = p_data_extract_id
5651 	AND ppe.salary_type     = 'STEP'
5652 	AND ppe.name            = l_rate_or_payscale_name
5653 	AND ppe.pay_element_id  = ppo.pay_element_id
5654 	AND ppo.name            = l_grade_name
5655 	AND ppo.grade_step      = l_grade_step
5656 	AND ppo.sequence_number = l_sequence_number;
5657 
5658   Cursor C_pay_elements_rate IS
5659      Select ppe.pay_element_id ,ppe.salary_type,
5660 	    ppo.pay_element_option_id
5661        FROM psb_pay_elements ppe,
5662 	    psb_pay_element_options ppo
5663       WHERE ppe.data_extract_id = p_data_extract_id
5664 	AND ppe.salary_type     = 'RATE'
5665 	AND ppe.name            = l_rate_or_payscale_name
5666 	AND ppe.pay_element_id  = ppo.pay_element_id
5667 	AND ppo.name            = l_grade_name;
5668 
5669   Cursor C_pay_element_rates IS
5670      Select pay_element_rate_id,
5671 	    effective_start_date,
5672 	    effective_end_date,
5673 	    element_value,
5674 	    currency_code
5675        FROM psb_pay_element_rates
5676       WHERE pay_element_id        = l_pay_element_id
5677 	AND pay_element_option_id = l_pay_element_option_id;
5678 
5679   /* start bug 4213882 */
5680   -- Bug # 4886277: Changed the cursor name from l_elm_asign_csr
5681   --                to l_elem_assign_csr
5682   Cursor l_elem_assign_csr(vc_position_id IN NUMBER)
5683   IS
5684     SELECT pas.position_assignment_id
5685     FROM   psb_position_assignments pas, -- bug #4886277: Used the table
5686                                          -- instead of View.
5687            psb_pay_elements pe
5688     WHERE  pas.pay_element_id = pe.pay_element_id (+)
5689     AND   pas.assignment_type = 'ELEMENT'
5690     AND   pas.data_extract_id = p_data_extract_id
5691     AND   pas.position_id     = vc_position_id
5692     AND   NVL(pe.salary_flag, 'Y')  = 'Y'
5693     ORDER BY pe.PAY_ELEMENT_ID;
5694 
5695   /* end bug 4213882 */
5696 
5697   /* Bug 3417868 Start */
5698 
5699   CURSOR l_position_source IS
5700   SELECT * FROM psb_positions_i
5701    WHERE data_extract_id = p_data_extract_id
5702      AND hr_position_id  > l_restart_hr_position_id
5703    ORDER BY hr_position_id,
5704             hr_employee_id;
5705 
5706   l_pos_record l_position_source%rowtype;
5707 
5708   -- bug 4551061 added the column availability_status in the
5709   -- following record
5710   TYPE l_position_i_rec_type IS RECORD
5711     (hr_position_id        NUMBER,
5712      hr_employee_id        NUMBER,
5713      organization_id       NUMBER,
5714      rate_or_payscale_id   NUMBER,
5715      grade_id              NUMBER,
5716      grade_step            NUMBER,
5717      sequence_number       NUMBER,
5718      salary_type           VARCHAR2(10),
5719      hr_position_name      VARCHAR2(240),
5720      id_flex_num           NUMBER,
5721      effective_start_date  DATE,
5722      effective_end_date    DATE,
5723      transaction_id        NUMBER,
5724      transaction_status    VARCHAR2(30),
5725      pay_basis             VARCHAR2(30),
5726      value                 NUMBER,
5727      segment1              VARCHAR2(60),
5728      segment2              VARCHAR2(60),
5729      segment3              VARCHAR2(60),
5730      segment4              VARCHAR2(60),
5731      segment5              VARCHAR2(60),
5732      segment6              VARCHAR2(60),
5733      segment7              VARCHAR2(60),
5734      segment8              VARCHAR2(60),
5735      segment9              VARCHAR2(60),
5736      segment10             VARCHAR2(60),
5737      segment11             VARCHAR2(60),
5738      segment12             VARCHAR2(60),
5739      segment13             VARCHAR2(60),
5740      segment14             VARCHAR2(60),
5741      segment15             VARCHAR2(60),
5742      segment16             VARCHAR2(60),
5743      segment17             VARCHAR2(60),
5744      segment18             VARCHAR2(60),
5745      segment19             VARCHAR2(60),
5746      segment20             VARCHAR2(60),
5747      segment21             VARCHAR2(60),
5748      segment22             VARCHAR2(60),
5749      segment23             VARCHAR2(60),
5750      segment24             VARCHAR2(60),
5751      segment25             VARCHAR2(60),
5752      segment26             VARCHAR2(60),
5753      segment27             VARCHAR2(60),
5754      segment28             VARCHAR2(60),
5755      segment29             VARCHAR2(60),
5756      segment30             VARCHAR2(60),
5757      availability_status   VARCHAR2(30),
5758      update_insert_flag    VARCHAR2(1),
5759      position_id           NUMBER
5760     );
5761 
5762   TYPE l_position_i_tbl_type IS TABLE OF l_position_i_rec_type
5763        INDEX BY BINARY_INTEGER;
5764 
5765   --bug#4166493, rec type modified to add additional columns necessary to update
5766   --psb positions in refresh mode.
5767 
5768   TYPE l_position_rec_type IS RECORD
5769     ( hr_position_id  NUMBER,
5770       hr_employee_id  NUMBER,
5771       position_id     NUMBER,
5772       update_insert_flag VARCHAR2(1),
5773       organization_id NUMBER,
5774       effective_start_date DATE,
5775       effective_end_date DATE,
5776       position_definition_id NUMBER,
5777       transaction_id NUMBER,
5778       transaction_status VARCHAR2(30),
5779       name  VARCHAR2(240)
5780     );
5781 
5782   TYPE l_position_tbl_type IS TABLE OF l_position_rec_type
5783        INDEX BY BINARY_INTEGER;
5784 
5785   l_source_cache_count      NUMBER;
5786   l_target_cache_count      NUMBER;
5787   l_last_hr_position_id     NUMBER(20);
5788   l_position_i_cache        l_position_i_tbl_type;
5789   l_position_cache          l_position_tbl_type;
5790   /* Bug 3417868 End */
5791 
5792   /* start bug 4213882 */
5793   l_assignment_rec_no		NUMBER := 0;
5794   l_eff_start_date			DATE;
5795   l_eff_end_date			DATE;
5796   l_assignment_exists		BOOLEAN := FALSE;
5797   /* end bug 4213882 */
5798 
5799 
5800 BEGIN
5801   --
5802   Savepoint Populate_Position;
5803   IF NOT FND_API.Compatible_API_Call (l_api_version,
5804 				      p_api_version,
5805 				      l_api_name,
5806 				      G_PKG_NAME)
5807   THEN
5808     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5809   END IF;
5810   --
5811   IF FND_API.to_Boolean (p_init_msg_lISt) THEN
5812     FND_MSG_PUB.initialize;
5813   END IF;
5814   p_return_status := FND_API.G_RET_STS_SUCCESS;
5815 
5816   -- for bug 4213882
5817   PSB_HR_POPULATE_DATA_PVT.g_extract_method := p_extract_method;
5818   PSB_HR_POPULATE_DATA_PVT.g_pop_assignment := 'Y';
5819 
5820   -- Populate WHO columns.
5821   l_last_update_date  := sysdate;
5822   l_last_updated_BY   := FND_GLOBAL.USER_ID;
5823   l_last_update_login := FND_GLOBAL.LOGIN_ID;
5824   l_creation_date     := sysdate;
5825   l_created_BY        := FND_GLOBAL.USER_ID;
5826 
5827   -- DE by Org
5828   -- If extract_method is REFRESH do nothing.
5829   -- Else use the appropriate extract_method based on  the organization's
5830   -- extract status. cache_org_status caches statuses of all organizations.
5831 
5832   IF (p_extract_by_org = 'N' OR p_extract_method = 'REFRESH') THEN
5833     l_extract_method := p_extract_method;
5834   ELSE
5835     cache_org_status
5836     ( l_return_status,
5837       p_data_extract_id,
5838       p_extract_by_org
5839     ) ;
5840     --
5841     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5842       RAISE FND_API.G_EXC_ERROR;
5843     END IF;
5844     --
5845   END IF;
5846 
5847   PSB_HR_EXTRACT_DATA_PVT.Check_Reentry
5848   (  p_api_version              => 1.0  ,
5849      p_return_status            => l_return_status,
5850      p_msg_count                => l_msg_count,
5851      p_msg_data                 => l_msg_data,
5852      p_data_extract_id          => p_data_extract_id,
5853      p_process                  => 'PSB Positions',
5854      p_status                   => l_status,
5855      p_restart_id               => l_restart_hr_position_id
5856   ) ;
5857   --
5858   IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5859     RAISE FND_API.G_EXC_ERROR;
5860   END IF;
5861 
5862   -- SR:For testing only.
5863   -- l_status := 'I'; l_restart_hr_position_id := 0;
5864 
5865   IF (l_status = 'I') THEN
5866 
5867   /*Bug 3417868 Start */
5868   OPEN l_position_source;
5869   LOOP
5870   FETCH l_position_source INTO l_pos_record;
5871 
5872   IF   (l_last_hr_position_id <> l_pos_record.hr_position_id
5873     AND l_last_hr_position_id IS NOT NULL)
5874     OR  l_position_source%NOTFOUND
5875   THEN
5876 
5877     l_position_cache.delete;
5878     l_target_cache_count := 0;
5879 
5880     --populating target pl/sql table
5881     FOR position_target_rec in
5882     (
5883       --Bug#4166493, picking up additonal data, necessary for updating psb_positions.
5884       Select hr_position_id,
5885              hr_employee_id,
5886              position_id,
5887              organization_id,
5888              effective_start_date,
5889              effective_end_date,
5890              position_definition_id,
5891              transaction_id,
5892              transaction_status,
5893              name
5894       FROM   psb_positions
5895       WHERE  data_extract_id = p_data_extract_id
5896       AND    hr_position_id  = l_last_hr_position_id
5897       ORDER BY hr_position_id,
5898                hr_employee_id
5899     )
5900     LOOP
5901 
5902       l_target_cache_count := nvl(l_target_cache_count,0) + 1;
5903       l_position_cache(l_target_cache_count).hr_position_id
5904                       := position_target_rec.hr_position_id;
5905       l_position_cache(l_target_cache_count).hr_employee_id
5906                       := position_target_rec.hr_employee_id;
5907       l_position_cache(l_target_cache_count).position_id
5908                       := position_target_rec.position_id;
5909       l_position_cache(l_target_cache_count).organization_id
5910                       := position_target_rec.organization_id;
5911       l_position_cache(l_target_cache_count).effective_start_date
5912                       := position_target_rec.effective_start_date;
5913       l_position_cache(l_target_cache_count).effective_end_date
5914                       := position_target_rec.effective_end_date;
5915       l_position_cache(l_target_cache_count).position_definition_id
5916                       := position_target_rec.position_definition_id;
5917       l_position_cache(l_target_cache_count).transaction_id
5918                       := position_target_rec.transaction_id;
5919       l_position_cache(l_target_cache_count).transaction_status
5920                       := position_target_rec.transaction_status;
5921       l_position_cache(l_target_cache_count).name
5922                       := position_target_rec.name;
5923 
5924     END LOOP;
5925 
5926     --code for comparing similar records
5927     FOR i in 1..l_position_i_cache.count
5928     LOOP
5929 
5930       FOR j in 1..l_position_cache.count
5931       LOOP
5932 
5933         IF  NVL(l_position_i_cache(i).hr_employee_id,-9999)
5934           = NVL(l_position_cache(j).hr_employee_id,-9999)
5935         AND l_position_cache(j).position_id IS NOT NULL
5936         AND l_position_cache(j).update_insert_flag IS NULL
5937         AND l_position_i_cache(i).update_insert_flag IS NULL THEN
5938 
5939           l_position_cache(j).update_insert_flag   := 'U';
5940           l_position_i_cache(i).update_insert_flag := 'U';
5941           l_position_i_cache(i).position_id
5942                       := l_position_cache(j).position_id;
5943 
5944         END IF;
5945 
5946       END LOOP;
5947 
5948     END LOOP;
5949 
5950   --code for comparing modified and new records
5951   FOR i in 1..l_position_i_cache.count
5952   LOOP
5953 
5954     FOR j in 1..l_position_cache.count
5955     LOOP
5956 
5957 
5958     IF l_position_i_cache(i).hr_employee_id IS NOT NULL
5959     AND l_position_cache(j).hr_employee_id IS NULL
5960     AND l_position_cache(j).update_insert_flag IS NULL
5961     AND l_position_cache(j).position_id IS NOT NULL
5962     AND l_position_i_cache(i).update_insert_flag IS NULL THEN
5963 
5964       l_position_cache(j).update_insert_flag   := 'U';
5965       l_position_i_cache(i).update_insert_flag := 'U';
5966       l_position_i_cache(i).position_id := l_position_cache(j).position_id;
5967 
5968     ELSIF l_position_i_cache(i).hr_employee_id IS NULL
5969     AND l_position_cache(j).hr_employee_id IS NOT NULL
5970     AND l_position_cache(j).update_insert_flag IS NULL
5971     AND l_position_cache(j).position_id IS NOT NULL
5972     AND l_position_i_cache(i).update_insert_flag IS NULL THEN
5973 
5974       l_position_cache(j).update_insert_flag   := 'U';
5975       l_position_i_cache(i).update_insert_flag := 'U';
5976       l_position_i_cache(i).position_id := l_position_cache(j).position_id;
5977 
5978     ELSIF l_position_i_cache(i).hr_employee_id IS NOT NULL
5979     AND l_position_cache(j).hr_employee_id IS NOT NULL
5980     AND l_position_cache(j).update_insert_flag IS NULL
5981     AND l_position_cache(j).position_id IS NOT NULL
5982     AND l_position_i_cache(i).update_insert_flag IS NULL THEN
5983 
5984       l_position_cache(j).update_insert_flag   := 'U';
5985       l_position_i_cache(i).update_insert_flag := 'U';
5986       l_position_i_cache(i).position_id := l_position_cache(j).position_id;
5987 
5988     END IF;
5989 
5990     END LOOP;
5991 
5992   END LOOP;
5993 
5994   FOR i in 1..l_position_i_cache.count
5995   LOOP
5996     IF l_position_i_cache(i).hr_position_id IS NOT NULL
5997     AND l_position_i_cache(i).update_insert_flag IS NULL THEN
5998       l_position_i_cache(i).update_insert_flag := 'I';
5999     END IF;
6000   END LOOP;
6001   /* Bug 3417868 End */
6002 
6003   /*Bug#4166493, , if we reach this stage and
6004   still have update_insert_flag as null for the data in PSB,
6005   then these are terminated records and we need to update the employee id
6006   as null in PSB. Note that for shared positions, we would have created multiple
6007   position records in PSB for the same position in HR,
6008   if there are multiple assignments in HR. This scenario is only applicable during
6009   REFRESH, but we do not need any additional condition to prevent, this for CREATE */
6010 
6011   FOR j in 1..l_position_cache.count
6012   LOOP
6013 
6014      IF l_position_cache(j).update_insert_flag IS NULL THEN
6015 
6016       -- Only thing we update here is the employee_id to NULL,
6017       --rest of the data remains same.
6018             PSB_POSITIONS_PVT.UPDATE_ROW
6019             (
6020             p_api_version            => 1.0,
6021             p_init_msg_lISt          => FND_API.G_FALSE,
6022             p_commit                 => FND_API.G_FALSE,
6023             p_validation_level       => FND_API.G_VALID_LEVEL_FULL,
6024             p_return_status          => l_return_status,
6025             p_msg_count              => l_msg_count,
6026             p_msg_data               => l_msg_data,
6027             p_position_id            => l_position_cache(j).position_id,
6028             -- de by org
6029             p_organization_id        => l_position_cache(j).organization_id,
6030             p_data_extract_id        => p_data_extract_id,
6031             p_position_definition_id => l_position_cache(j).position_definition_id,
6032             p_hr_position_id         => l_position_cache(j).hr_position_id,
6033             p_hr_employee_id         => NULL,
6034             p_business_group_id      => p_business_group_id,
6035             p_effective_start_date   => l_position_cache(j).effective_start_date,
6036             p_effective_end_date     => l_position_cache(j).effective_end_date,
6037             p_set_of_books_id        => p_set_of_books_id,
6038             p_vacant_position_flag   => 'Y',
6039             p_transaction_id         => l_position_cache(j).transaction_id,
6040             p_transaction_status     => l_position_cache(j).transaction_status,
6041             p_attribute1             => NULL,
6042             p_attribute2             => NULL,
6043             p_attribute3             => NULL,
6044             p_attribute4             => NULL,
6045             p_attribute5             => NULL,
6046             p_attribute6             => NULL,
6047             p_attribute7             => NULL,
6048             p_attribute8             => NULL,
6049             p_attribute9             => NULL,
6050             p_attribute10            => NULL,
6051             p_attribute11            => NULL,
6052             p_attribute12            => NULL,
6053             p_attribute13            => NULL,
6054             p_attribute14            => NULL,
6055             p_attribute15            => NULL,
6056             p_attribute16            => NULL,
6057             p_attribute17            => NULL,
6058             p_attribute18            => NULL,
6059             p_attribute19            => NULL,
6060             p_attribute20            => NULL,
6061             p_attribute_category     => NULL,
6062             p_name                   => l_position_cache(j).name,
6063             p_mode                   => 'R'
6064             ) ;
6065 
6066      END IF;
6067 
6068   END LOOP;
6069 
6070   FOR i in 1..l_position_i_cache.count
6071   LOOP
6072       --
6073       -- DE by Org
6074       --
6075       -- If extract method is not REFRESH, get the status of the organization
6076       -- to which the position belongs from the already cached organization
6077       -- statuses.
6078       IF p_extract_method <> 'REFRESH' and p_extract_by_org = 'Y' THEN
6079         l_extract_method := g_org_status(l_position_i_cache(i).organization_id);
6080       END IF;
6081 
6082       IF (l_position_i_cache(i).hr_employee_id IS NOT NULL) THEN
6083         l_vacant_position_flag :=  'N';
6084       ELSE
6085         l_vacant_position_flag   := 'Y';
6086 	l_rate_or_payscale_name  := NULL;
6087 	l_grade_name             := NULL;
6088 	l_rate_or_payscale_id    := l_position_i_cache(i).rate_or_payscale_id;
6089 	l_grade_id               := l_position_i_cache(i).grade_id;
6090 	l_grade_step             := l_position_i_cache(i).grade_step;
6091 	l_sequence_number        := l_position_i_cache(i).sequence_number;
6092 	l_pay_element_id         := NULL;
6093 	l_pay_element_option_id  := NULL;
6094 
6095         IF (l_position_i_cache(i).salary_type = 'STEP') THEN
6096           --
6097 	  FOR C_Sal_Rec in C_salary
6098 	  LOOP
6099 	    l_rate_or_payscale_name := C_Sal_Rec.rate_or_payscale_name;
6100 	    l_grade_name            := C_Sal_Rec.grade_name;
6101 	  END LOOP;
6102           --
6103 	  FOR C_pay_elements_step_rec in C_pay_elements_step
6104 	  LOOP
6105 	   l_pay_element_id        := C_pay_elements_step_rec.pay_element_id;
6106 	   l_salary_type           := C_pay_elements_step_rec.salary_type;
6107 	   l_pay_element_option_id :=
6108                                C_pay_elements_step_rec.pay_element_option_id;
6109 	  END LOOP;
6110           --
6111         END IF;
6112 
6113 	IF (l_position_i_cache(i).salary_type = 'RATE') THEN
6114           --
6115 	  FOR C_Sal_Rate_Rec in C_rate_salary
6116 	  LOOP
6117 	    l_rate_or_payscale_name := C_Sal_Rate_Rec.rate_or_payscale_name;
6118 	    l_grade_name            := C_Sal_Rate_Rec.grade_name;
6119 	  END LOOP;
6120           --
6121 	  FOR C_pay_elements_rate_rec in C_pay_elements_rate
6122 	  LOOP
6123 	   l_pay_element_id        := C_pay_elements_rate_rec.pay_element_id;
6124 	   l_salary_type           := C_pay_elements_rate_rec.salary_type;
6125 	   l_pay_element_option_id :=
6126                                 C_pay_elements_rate_rec.pay_element_option_id;
6127 	  END LOOP;
6128           --
6129 	END IF;
6130 
6131 	FOR C_pay_element_rates_rec in C_pay_element_rates
6132 	LOOP
6133 	l_pay_element_rate_id  := C_pay_element_rates_rec.pay_element_rate_id;
6134 	l_effective_start_date := C_pay_element_rates_rec.effective_start_date;
6135 	l_effective_end_date   := C_pay_element_rates_rec.effective_end_date;
6136 	l_element_value        := C_pay_element_rates_rec.element_value;
6137 	l_currency_code        := C_pay_element_rates_rec.currency_code;
6138 	END LOOP;
6139 	-- Handle Grade,salary assignments for Position
6140       END IF;
6141 
6142       l_employee_name := NULL;
6143       l_position_name := NULL;
6144 
6145       if ((l_position_i_cache(i).hr_position_id <> prev_hr_position_id)
6146            and (prev_hr_position_id <> -1))
6147       then
6148         --l_hr_position_ctr := l_hr_position_ctr + 1; /* For Bug: 3066598 */
6149         /* Do Update_Reentry only at the time of the first failure
6150            with the last successful position or when the record
6151            count reaches g_checkpoint_save with no failed positions */
6152 
6153 	if ((l_hr_position_ctr = PSB_WS_ACCT1.g_checkpoint_save) AND (l_status_flag <> 'I'))
6154             OR
6155             (l_last_success_flag = 'N')
6156         then
6157 	  PSB_HR_EXTRACT_DATA_PVT.Update_Reentry
6158           ( p_api_version              => 1.0  ,
6159   	    p_return_status            => l_return_status,
6160 	    p_msg_count                => l_msg_count,
6161   	    p_msg_data                 => l_msg_data,
6162 	    p_data_extract_id          => p_data_extract_id,
6163 	    p_extract_method           => p_extract_method,
6164 	    p_process                  => 'PSB Positions',
6165 	    p_restart_id               => prev_hr_position_id
6166 	  ) ;
6167           --
6168           if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6169 	    raise FND_API.G_EXC_ERROR;
6170           end if;
6171           COMMIT WORK;
6172           l_last_success_flag := 'Y';
6173           l_hr_position_ctr := 0;
6174           Savepoint Populate_Position;
6175           --
6176         end if;
6177       end if;
6178 
6179       IF (l_position_i_cache(i).hr_employee_id IS NOT NULL) THEN
6180         FOR Emp_Name_Rec in G_Employee_Details(p_person_id =>
6181 					       l_position_i_cache(i).hr_employee_id)
6182 	LOOP
6183 	  l_employee_name := Emp_Name_Rec.first_name || ' ' ||
6184                              Emp_Name_Rec.last_name;
6185 	END LOOP;
6186       END IF;
6187 
6188       l_position_name := l_position_i_cache(i).hr_position_name;
6189       l_init_index    := 0;
6190       l_id_flex_num   := l_position_i_cache(i).id_flex_num;
6191 
6192       FOR C_flex_rec in
6193       (
6194 	Select application_column_name
6195 	FROM   fnd_id_flex_segments_vl
6196 	WHERE  id_flex_code = 'BPS'
6197 	AND    id_flex_num  = l_id_flex_num
6198 	AND    enabled_flag = 'Y'
6199 	ORDER  BY segment_num
6200       )
6201       LOOP
6202 	l_init_index := l_init_index + 1;
6203 	segs(l_init_index) := NULL;
6204 
6205 	IF (C_flex_rec.application_column_name = 'SEGMENT1') THEN
6206 	    segs(l_init_index)   := l_position_i_cache(i).segment1;
6207 	END IF;
6208 	IF (C_flex_rec.application_column_name = 'SEGMENT2') THEN
6209 	   segs(l_init_index)   := l_position_i_cache(i).segment2;
6210 	END IF;
6211 	IF (C_flex_rec.application_column_name = 'SEGMENT3') THEN
6212 	   segs(l_init_index)   := l_position_i_cache(i).segment3;
6213 	END IF;
6214 	IF (C_flex_rec.application_column_name = 'SEGMENT4') THEN
6215 	   segs(l_init_index)   := l_position_i_cache(i).segment4;
6216 	END IF;
6217 	IF (C_flex_rec.application_column_name = 'SEGMENT5') THEN
6218 	   segs(l_init_index)   := l_position_i_cache(i).segment5;
6219 	END IF;
6220 	IF (C_flex_rec.application_column_name = 'SEGMENT6') THEN
6221 	   segs(l_init_index)   := l_position_i_cache(i).segment6;
6222 	END IF;
6223 	IF (C_flex_rec.application_column_name = 'SEGMENT7') THEN
6224 	   segs(l_init_index)   := l_position_i_cache(i).segment7;
6225 	END IF;
6226 	IF (C_flex_rec.application_column_name = 'SEGMENT8') THEN
6227 	   segs(l_init_index)   := l_position_i_cache(i).segment8;
6228 	END IF;
6229 	IF (C_flex_rec.application_column_name = 'SEGMENT9') THEN
6230 	   segs(l_init_index)   := l_position_i_cache(i).segment9;
6231 	END IF;
6232 	IF (C_flex_rec.application_column_name = 'SEGMENT10') THEN
6233 	   segs(l_init_index)   := l_position_i_cache(i).segment10;
6234 	END IF;
6235 	IF (C_flex_rec.application_column_name = 'SEGMENT11') THEN
6236 	   segs(l_init_index)   := l_position_i_cache(i).segment11;
6237 	END IF;
6238 	IF (C_flex_rec.application_column_name = 'SEGMENT12') THEN
6239 	   segs(l_init_index)   := l_position_i_cache(i).segment12;
6240 	END IF;
6241 	IF (C_flex_rec.application_column_name = 'SEGMENT13') THEN
6242 	   segs(l_init_index)   := l_position_i_cache(i).segment13;
6243 	END IF;
6244 	IF (C_flex_rec.application_column_name = 'SEGMENT14') THEN
6245 	   segs(l_init_index)   := l_position_i_cache(i).segment14;
6246 	END IF;
6247 	IF (C_flex_rec.application_column_name = 'SEGMENT15') THEN
6248 	   segs(l_init_index)   := l_position_i_cache(i).segment15;
6249 	END IF;
6250 	IF (C_flex_rec.application_column_name = 'SEGMENT16') THEN
6251 	   segs(l_init_index)   := l_position_i_cache(i).segment16;
6252 	END IF;
6253 	IF (C_flex_rec.application_column_name = 'SEGMENT17') THEN
6254 	   segs(l_init_index)   := l_position_i_cache(i).segment17;
6255 	END IF;
6256 	IF (C_flex_rec.application_column_name = 'SEGMENT18') THEN
6257 	   segs(l_init_index)   := l_position_i_cache(i).segment18;
6258 	END IF;
6259 	IF (C_flex_rec.application_column_name = 'SEGMENT19') THEN
6260 	   segs(l_init_index)   := l_position_i_cache(i).segment19;
6261 	END IF;
6262 	IF (C_flex_rec.application_column_name = 'SEGMENT20') THEN
6263 	   segs(l_init_index)   := l_position_i_cache(i).segment20;
6264 	END IF;
6265 	IF (C_flex_rec.application_column_name = 'SEGMENT21') THEN
6266 	   segs(l_init_index)   := l_position_i_cache(i).segment21;
6267 	END IF;
6268 	IF (C_flex_rec.application_column_name = 'SEGMENT22') THEN
6269 	   segs(l_init_index)   := l_position_i_cache(i).segment22;
6270 	END IF;
6271 	IF (C_flex_rec.application_column_name = 'SEGMENT23') THEN
6272 	   segs(l_init_index)   := l_position_i_cache(i).segment23;
6273 	END IF;
6274 	IF (C_flex_rec.application_column_name = 'SEGMENT24') THEN
6275 	   segs(l_init_index)   := l_position_i_cache(i).segment24;
6276 	END IF;
6277 	IF (C_flex_rec.application_column_name = 'SEGMENT25') THEN
6278 	   segs(l_init_index)   := l_position_i_cache(i).segment25;
6279 	END IF;
6280 	IF (C_flex_rec.application_column_name = 'SEGMENT26') THEN
6281 	   segs(l_init_index)   := l_position_i_cache(i).segment26;
6282 	END IF;
6283 	IF (C_flex_rec.application_column_name = 'SEGMENT27') THEN
6284 	   segs(l_init_index)   := l_position_i_cache(i).segment27;
6285 	END IF;
6286 	IF (C_flex_rec.application_column_name = 'SEGMENT28') THEN
6287 	   segs(l_init_index)   := l_position_i_cache(i).segment28;
6288 	END IF;
6289 	IF (C_flex_rec.application_column_name = 'SEGMENT29') THEN
6290 	   segs(l_init_index)   := l_position_i_cache(i).segment29;
6291 	END IF;
6292 	IF (C_flex_rec.application_column_name = 'SEGMENT30') THEN
6293 	   segs(l_init_index)   := l_position_i_cache(i).segment30;
6294 	END IF;
6295 
6296       END LOOP; -- END LOOP ( C_flex_rec in C_flex )
6297 
6298       IF NOT FND_FLEX_EXT.Get_Combination_ID
6299 	( application_short_name => 'PSB',
6300 	  key_flex_code          => 'BPS',
6301 	  structure_number       =>  l_position_i_cache(i).id_flex_num,
6302 	  validation_date        =>  SYSDATE,
6303 	  n_segments             =>  l_init_index,
6304 	  segments               =>  segs,
6305 	  combination_id         =>  l_ccid)
6306       THEN
6307         /* Whenever a failure occurs set the l_status_flag to 'I' and
6308            set the l_last_success_flag to 'N' but continue the extract
6309            process */
6310         /* For Bug No: 3066598 Start */
6311         IF l_status_flag <> 'I' THEN
6312           l_status_flag := 'I';
6313           l_last_success_flag := 'N';
6314         END IF;
6315         /* For Bug No: 3066598 End */
6316 
6317         l_msg := FND_MESSAGE.Get;
6318 	FND_FILE.put_line(FND_FILE.LOG, 'Cannot import HRMS Position: '||
6319                                          l_position_i_cache(i).hr_position_id) ;
6320 	FND_FILE.put_line(FND_FILE.LOG,l_msg);
6321 	FND_MESSAGE.SET_NAME('PSB','PSB_POSITION_CCID_FAILURE');
6322 	FND_MESSAGE.SET_TOKEN('POSITION_NAME',l_position_name );
6323 	FND_MESSAGE.SET_TOKEN('ERR_MESG',l_msg);
6324 
6325        /* start bug no 4170600 */
6326         l_msg := FND_MESSAGE.GET;
6327         INSERT INTO PSB_ERROR_MESSAGES (
6328             CONCURRENT_REQUEST_ID,
6329             PROCESS_ID,
6330             SOURCE_PROCESS,
6331             SEQUENCE_NUMBER,
6332             DESCRIPTION,
6333             CREATION_DATE,
6334             CREATED_BY)
6335         VALUES (
6336         -4712, -4712, 'XXX', null, l_msg, SYSDATE, -1);
6337        /* end bug no 4170600 */
6338 
6339 	FND_MSG_PUB.Add;
6340         --RAISE FND_API.G_EXC_ERROR;
6341 
6342       ELSE
6343 
6344         /* For Bug No: 3066598 Start */
6345         IF ((l_position_i_cache(i).hr_position_id <> prev_hr_position_id)
6346              AND (prev_hr_position_id <> -1))
6347         THEN
6348           l_hr_position_ctr := l_hr_position_ctr + 1;
6349         END IF;
6350         /* For Bug No: 3066598 End */
6351         l_concat_pos_name := NULL;
6352 
6353         l_concat_pos_name := FND_FLEX_EXT.Get_Segs
6354 			   (application_short_name => 'PSB',
6355 			    key_flex_code          => 'BPS',
6356 			    structure_number       =>  l_position_i_cache(i).id_flex_num,
6357 			    combination_id         =>  l_ccid);
6358 
6359 
6360 -- commented out the old refresh cursor
6361 /*      --
6362         -- Update the position in 'REFRESH' mode.
6363         --
6364         -- DE by Org
6365         --
6366         -- l_extract_method contains the organization's status. Hence using it
6367         -- in lieu of p_extract_method
6368         --
6369         IF (l_extract_method = 'REFRESH')  or (l_update_flag = 'Y') THEN
6370 
6371 	  -- Variable to determine whether 'REFRESH' occurred or NOT.
6372 	  l_dummy := 0;
6373 
6374 	  FOR C_Refresh_Rec in
6375 	  (
6376 	    SELECT position_id,organization_id
6377 	    FROM   psb_positions
6378 	    WHERE  hr_position_id  = position_rec.hr_position_id
6379 	    AND    ( NVL(hr_employee_id,-1)=NVL(position_rec.hr_employee_id,-1)
6380                                         OR
6381                      ( hr_employee_id IS NULL
6382                        AND
6383                        NOT EXISTS
6384                        ( SELECT 1
6385                          FROM   psb_positions
6386                          WHERE  hr_position_id = position_rec.hr_position_id
6387                          AND    hr_employee_id = position_rec.hr_employee_id
6388                          AND    data_extract_id = p_data_extract_id
6389                        )
6390                      )
6391 
6392                      OR
6393                      ( hr_employee_id IS NOT NULL
6394                        AND
6395                        NOT EXISTS
6396                        ( SELECT 1
6397                          FROM   psb_positions
6398                          WHERE  hr_position_id = position_rec.hr_position_id
6399                          AND    hr_employee_id  IS NULL
6400                          AND    data_extract_id = p_data_extract_id
6401                        )
6402                      )
6403 
6404                    )
6405 	   AND     data_extract_id   = p_data_extract_id
6406 	   AND     business_group_id = p_business_group_id
6407 	  )
6408           LOOP
6409 	    l_dummy := 1;
6410 
6411 */
6412     /* Bug 3417868 Start */
6413     IF l_position_i_cache(i).update_insert_flag = 'U' THEN
6414     /* Bug 3417868 End */
6415 
6416 
6417             -- bug 4551061 added the in parameter p_availability_status
6418 	    PSB_POSITIONS_PVT.UPDATE_ROW
6419 	    (
6420 	    p_api_version            => 1.0,
6421 	    p_init_msg_lISt          => FND_API.G_FALSE,
6422     	    p_commit                 => FND_API.G_FALSE,
6423 	    p_validation_level       => FND_API.G_VALID_LEVEL_FULL,
6424 	    p_return_status          => l_return_status,
6425 	    p_msg_count              => l_msg_count,
6426 	    p_msg_data               => l_msg_data,
6427 	    p_position_id            => l_position_i_cache(i).position_id,
6428             -- de by org
6429             p_organization_id        => l_position_i_cache(i).organization_id,
6430 	    p_data_extract_id        => p_data_extract_id,
6431 	    p_position_definition_id => l_ccid,
6432 	    p_hr_position_id         => l_position_i_cache(i).hr_position_id,
6433 	    p_hr_employee_id         => l_position_i_cache(i).hr_employee_id,
6434 	    p_business_group_id      => p_business_group_id,
6435 	    p_effective_start_date   => l_position_i_cache(i).effective_start_date,
6436 	    p_effective_end_date     => l_position_i_cache(i).effective_end_date,
6437 	    p_set_of_books_id        => p_set_of_books_id,
6438 	    p_vacant_position_flag   => l_vacant_position_flag,
6439             p_availability_status    => l_position_i_cache(i).availability_status,
6440 	    p_transaction_id         => l_position_i_cache(i).transaction_id,
6441 	    p_transaction_status     => l_position_i_cache(i).transaction_status,
6442 	    p_attribute1             => NULL,
6443 	    p_attribute2             => NULL,
6444 	    p_attribute3             => NULL,
6445 	    p_attribute4             => NULL,
6446 	    p_attribute5             => NULL,
6447 	    p_attribute6             => NULL,
6448 	    p_attribute7             => NULL,
6449 	    p_attribute8             => NULL,
6450 	    p_attribute9             => NULL,
6451 	    p_attribute10            => NULL,
6452 	    p_attribute11            => NULL,
6453 	    p_attribute12            => NULL,
6454 	    p_attribute13            => NULL,
6455 	    p_attribute14            => NULL,
6456 	    p_attribute15            => NULL,
6457 	    p_attribute16            => NULL,
6458 	    p_attribute17            => NULL,
6459 	    p_attribute18            => NULL,
6460 	    p_attribute19            => NULL,
6461 	    p_attribute20            => NULL,
6462 	    p_attribute_category     => NULL,
6463 	    p_name                   => l_concat_pos_name,
6464 	    p_mode                   => 'R'
6465 	    ) ;
6466             --
6467 	    l_elem_assign_dummy := 0;
6468 	    l_position_id       := l_position_i_cache(i).position_id;
6469 
6470             /* start bug no 4213882 */
6471 		l_assignment_rec_no := 0;
6472 		l_assignment_exists := FALSE;
6473 
6474 		-- Bug # 4886277: Used psb_data_extracts instead of
6475                 -- fnd_sessions to get req_data_as_of_date.
6476                 FOR l_assignment_rec IN
6477                     (SELECT a.effective_start_date,
6478                             a.effective_end_date
6479                      FROM per_all_assignments_f a,
6480                           psb_data_extracts b
6481                      WHERE a.position_id =l_position_i_cache(i).hr_position_id
6482                      AND a.person_id = l_position_i_cache(i).hr_employee_id
6483                      AND b.data_extract_id = p_data_extract_id
6484                      AND b.req_data_as_of_date between
6485                          a.effective_start_date AND a.effective_end_date)
6486 		LOOP
6487 		   l_assignment_exists := TRUE;
6488 		   l_eff_start_date := l_assignment_rec.effective_start_date;
6489 
6490 		   IF (l_assignment_rec.effective_end_date =
6491                              to_date('31124712','DDMMYYYY')) THEN
6492        	             l_eff_end_date := to_date(null);
6493    		   ELSE
6494                      l_eff_end_date := l_assignment_rec.effective_end_date;
6495                    END IF;
6496 		END LOOP;
6497 
6498 		IF NOT l_assignment_exists THEN
6499 		 -- Bug # 4886277: Used psb_data_extracts instead of
6500                  -- fnd_sessions to get req_data_as_of_date.
6501                  FOR l_hr_position_rec IN
6502                      (SELECT a.effective_start_date,
6503                              a.effective_end_date
6504                       FROM hr_all_positions_f a,
6505                            psb_data_extracts b
6506                       WHERE a.position_id =l_position_i_cache(i).hr_position_id
6507                       AND b.data_extract_id = p_data_extract_id
6508                       AND b.req_data_as_of_date between
6509                           a.effective_start_date AND a.effective_end_date)
6510 		 LOOP
6511 		   l_eff_start_date := l_hr_position_rec.effective_start_date;
6512 		   IF (l_hr_position_rec.effective_end_date =
6513                           to_date('31124712','DDMMYYYY')) THEN
6514        	             l_eff_end_date := to_date(null);
6515    		   ELSE
6516                      l_eff_end_date := l_hr_position_rec.effective_end_date;
6517                   END IF;
6518 		 END LOOP;
6519 		END IF;
6520 
6521 	    /* end bug no 4213882 */
6522 
6523             -- for bug 4213882
6524 	    -- changed the query to fetch from the table and moved the
6525             -- change from
6526 	    -- from view to local cursor l_elm_asign_csr
6527 
6528 	    -- Bug # 4886277: Changed the cursor name from l_elm_asign_csr
6529             --                to l_elem_assign_csr
6530 	    For C_Pos_Elem_Rec in l_elem_assign_csr
6531                   (l_position_i_cache(i).position_id)
6532             LOOP
6533 	      l_elem_assign_dummy := 1;
6534 
6535               /* start bug no 4213882 */
6536 	      l_assignment_rec_no := l_assignment_rec_no + 1;
6537 	      /* end bug no 4213882 */
6538 
6539 	      /* start bug no 4213882 */
6540 	      if l_assignment_rec_no < 2 then
6541 	      /* end bug no 4213882 */
6542 
6543               PSB_POSITIONS_PVT.ModIFy_Assignment(
6544 	      p_api_version            => 1.0,
6545 	      p_return_status          => l_return_status,
6546 	      p_msg_count              => l_msg_count,
6547 	      p_msg_data               => l_msg_data,
6548 	      p_position_assignment_id => C_Pos_Elem_Rec.position_assignment_id,
6549 	      p_data_extract_id        => p_data_extract_id,
6550 	      p_worksheet_id           => NULL,
6551 	      p_position_id            => l_position_i_cache(i).position_id,
6552 	      p_assignment_type        => 'ELEMENT',
6553 	      p_attribute_id           => NULL,
6554 	      p_attribute_value_id     => NULL,
6555 	      p_attribute_value        => NULL,
6556 	      p_pay_element_id         => l_pay_element_id,
6557 	      p_pay_element_option_id  => l_pay_element_option_id,
6558 	      p_effective_start_DATE   => l_eff_start_date,
6559 	      p_effective_END_DATE     => l_eff_end_date,
6560 	      p_element_value_type     => 'A',
6561 	      p_element_value          => l_element_value,
6562 	      p_currency_code          => NULL,
6563 	      p_pay_basIS              => l_position_i_cache(i).pay_basis,
6564 	      p_global_default_flag    => NULL,
6565 	      p_assignment_default_rule_id => NULL,
6566 	      p_modIFy_flag            => NULL,
6567 	      p_rowid                  => l_rowid,
6568 	      p_employee_id            => NULL,
6569 	      p_primary_employee_flag  => NULL
6570 	      );
6571               --
6572 	      IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6573 	        RAISE FND_API.G_EXC_ERROR;
6574 	      END IF;
6575               --
6576 
6577               /* start bug no 4213882 */
6578 	      end if;
6579 	      /* end bug no 4213882 */
6580 
6581             END LOOP;
6582 
6583 
6584 
6585 /*          END LOOP;  -- END LOOP ( C_Refresh_Rec in C_Refresh )
6586 
6587 	 -- l_update_flag := 'N';
6588         END IF; -- END IF (l_extract_method = 'REFRESH').
6589 
6590         --
6591 
6592 */
6593 
6594 /*      -- Create new position in 'CREATE' mode.
6595         --
6596         IF ((l_extract_method = 'CREATE') or (l_dummy = 0))
6597           AND (l_update_flag <> 'Y')
6598 */
6599 --        THEN /* For Bug No: 3066598 */
6600           --
6601     /* Bug 3417868 Start */
6602     ELSIF l_position_i_cache(i).update_insert_flag = 'I' THEN
6603     /* Bug 3417868 End */
6604           SELECT psb_positions_s.nextval INTO l_position_id
6605 	  FROM   dual;
6606 
6607           -- bug 4551061 added the in parameter p_availability_status
6608 	  PSB_POSITIONS_PVT.INSERT_ROW
6609 	  (
6610 	  p_api_version            => 1.0,
6611 	  p_init_msg_lISt          => NULL,
6612 	  p_commit                 => NULL,
6613 	  p_validation_level       => NULL,
6614 	  p_return_status          => l_return_status,
6615 	  p_msg_count              => l_msg_count,
6616 	  p_msg_data               => l_msg_data,
6617 	  p_rowid                  => l_rowid,
6618 	  p_position_id            => l_position_id,
6619           -- de by org
6620           p_organization_id        => l_position_i_cache(i).organization_id,
6621 	  p_data_extract_id        => p_data_extract_id,
6622 	  p_position_definition_id => l_ccid,
6623 	  p_hr_position_id         => l_position_i_cache(i).hr_position_id,
6624 	  p_hr_employee_id         => l_position_i_cache(i).hr_employee_id,
6625 	  p_business_group_id      => p_business_group_id,
6626 	  p_effective_start_date   => l_position_i_cache(i).effective_start_date,
6627 	  p_effective_END_date     => l_position_i_cache(i).effective_END_date,
6628 	  p_set_of_books_id        => p_set_of_books_id,
6629 	  p_vacant_position_flag   => l_vacant_position_flag,
6630           p_availability_status    => l_position_i_cache(i).availability_status,
6631 	  p_transaction_id         => l_position_i_cache(i).transaction_id,
6632 	  p_transaction_status     => l_position_i_cache(i).transaction_status,
6633 	  p_new_position_flag      => 'N',
6634 	  p_attribute1             => NULL,
6635 	  p_attribute2             => NULL,
6636 	  p_attribute3             => NULL,
6637 	  p_attribute4             => NULL,
6638 	  p_attribute5             => NULL,
6639 	  p_attribute6             => NULL,
6640 	  p_attribute7             => NULL,
6641 	  p_attribute8             => NULL,
6642 	  p_attribute9             => NULL,
6643 	  p_attribute10            => NULL,
6644 	  p_attribute11            => NULL,
6645 	  p_attribute12            => NULL,
6646 	  p_attribute13            => NULL,
6647 	  p_attribute14            => NULL,
6648 	  p_attribute15            => NULL,
6649 	  p_attribute16            => NULL,
6650 	  p_attribute17            => NULL,
6651 	  p_attribute18            => NULL,
6652 	  p_attribute19            => NULL,
6653 	  p_attribute20            => NULL,
6654 	  p_attribute_category     => NULL,
6655 	  p_name                   => l_concat_pos_name,
6656 	  p_mode                   => 'R'
6657 	  ) ;
6658 	/*
6659         -- if vacant position
6660         END IF;  -- END FOR IF (p_extract_method = 'CREATE') or (l_dummy = 0)).
6661         */
6662 
6663         if (l_vacant_position_flag = 'Y') then
6664 
6665           IF l_position_i_cache(i).update_insert_flag = 'I' OR
6666             ((l_elem_assign_dummy = 0) and (l_pay_element_id is not null)) THEN
6667           --
6668         /*   if (((l_extract_method = 'CREATE') or (l_dummy = 0)) AND l_update_flag <> 'Y' )
6669              or ((l_elem_assign_dummy = 0) and (l_pay_element_id is not null))
6670              then  */
6671             --
6672             PSB_POSITION_ASSIGNMENTS_PVT.INSERT_ROW
6673 	    (
6674 	      p_api_version             => 1,
6675 	      p_init_msg_lISt           => NULL,
6676     	      p_commit                  => NULL,
6677 	      p_validation_level        => NULL,
6678 	      p_return_status           => l_return_status,
6679 	      p_msg_count               => l_msg_count,
6680 	      p_msg_data                => l_msg_data,
6681 	      p_rowid                   => l_rowid,
6682 	      p_position_assignment_id  => l_position_assignment_id,
6683 	      p_data_extract_id         => p_data_extract_id,
6684 	      p_worksheet_id            => NULL,
6685 	      p_position_id             => l_position_id,
6686 	      p_assignment_type         => 'ELEMENT',
6687 	      p_attribute_id            => NULL,
6688 	      p_attribute_value_id      => NULL,
6689 	      p_attribute_value         => NULL,
6690 	      p_pay_element_id          => l_pay_element_id,
6691 	      p_pay_element_option_id   => l_pay_element_option_id,
6692 	      p_effective_start_date    => l_position_i_cache(i).effective_start_date,
6693 	      p_effective_END_date      => l_position_i_cache(i).effective_end_date,
6694 	      p_element_value_type      => 'A',
6695 	      p_element_value           => l_position_i_cache(i).value,
6696 	      p_currency_code           => l_currency_code,
6697 	      p_pay_basIS               => l_position_i_cache(i).pay_basis,
6698 	      p_employee_id             => NULL,
6699 	      p_primary_employee_flag   => NULL,
6700 	      p_global_default_flag     => NULL,
6701 	      p_assignment_default_rule_id => NULL,
6702 	      p_modIFy_flag             => NULL,
6703 	      p_mode                    => 'R'
6704 	    ) ;
6705             --
6706             IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6707               RAISE FND_API.G_EXC_ERROR;
6708             END IF;
6709 
6710 	  END IF;
6711 
6712         END IF; -- l_vacant_position_flag = 'Y'
6713         prev_hr_position_id := l_position_i_cache(i).hr_position_id;
6714         --
6715       END IF;  -- l_position_i_cache(i).update_insert_flag = 'U'
6716       END IF;  -- IF NOT FND_FLEX_EXT.Get_Combination_ID
6717 
6718     END LOOP;  --    FOR i in 1..l_position_i_cache.count
6719     END IF;    --    IF   (l_last_hr_position_id <> l_pos_record.hr_position_id
6720 
6721   -- populating the source pl/sql table
6722   /* Bug 3417868 Start */
6723   IF l_last_hr_position_id <> l_pos_record.hr_position_id
6724     OR l_last_hr_position_id IS NULL THEN
6725     l_position_i_cache.delete;
6726     l_source_cache_count := 0;
6727   END IF;
6728 
6729     l_source_cache_count := nvl(l_source_cache_count,0) + 1;
6730 
6731     l_position_i_cache(l_source_cache_count).hr_position_id
6732                                    := l_pos_record.hr_position_id;
6733     l_position_i_cache(l_source_cache_count).hr_employee_id
6734                                    := l_pos_record.hr_employee_id;
6735     l_position_i_cache(l_source_cache_count).organization_id
6736                                    := l_pos_record.organization_id;
6737     l_position_i_cache(l_source_cache_count).rate_or_payscale_id
6738                                   := l_pos_record.rate_or_payscale_id;
6739     l_position_i_cache(l_source_cache_count).grade_id
6740                                   := l_pos_record.grade_id;
6741     l_position_i_cache(l_source_cache_count).grade_step
6742                                   := l_pos_record.grade_step;
6743     l_position_i_cache(l_source_cache_count).sequence_number
6744                                   := l_pos_record.sequence_number;
6745     l_position_i_cache(l_source_cache_count).salary_type
6746                                   := l_pos_record.salary_type;
6747     l_position_i_cache(l_source_cache_count).hr_position_name
6748                                   := l_pos_record.hr_position_name;
6749     l_position_i_cache(l_source_cache_count).id_flex_num
6750                                   := l_pos_record.id_flex_num;
6751     l_position_i_cache(l_source_cache_count).effective_start_date
6752                                   := l_pos_record.effective_start_date;
6753     l_position_i_cache(l_source_cache_count).effective_end_date
6754                                   := l_pos_record.effective_end_date;
6755     l_position_i_cache(l_source_cache_count).transaction_id
6756                                   := l_pos_record.transaction_id;
6757     l_position_i_cache(l_source_cache_count).transaction_status
6758                                   := l_pos_record.transaction_status;
6759     l_position_i_cache(l_source_cache_count).pay_basis   := l_pos_record.pay_basis;
6760     l_position_i_cache(l_source_cache_count).value       := l_pos_record.value;
6761     l_position_i_cache(l_source_cache_count).segment1    := l_pos_record.segment1;
6762     l_position_i_cache(l_source_cache_count).segment2    := l_pos_record.segment2;
6763     l_position_i_cache(l_source_cache_count).segment3    := l_pos_record.segment3;
6764     l_position_i_cache(l_source_cache_count).segment4    := l_pos_record.segment4;
6765     l_position_i_cache(l_source_cache_count).segment5    := l_pos_record.segment5;
6766     l_position_i_cache(l_source_cache_count).segment6    := l_pos_record.segment6;
6767     l_position_i_cache(l_source_cache_count).segment7    := l_pos_record.segment7;
6768     l_position_i_cache(l_source_cache_count).segment8    := l_pos_record.segment8;
6769     l_position_i_cache(l_source_cache_count).segment9    := l_pos_record.segment9;
6770     l_position_i_cache(l_source_cache_count).segment10   := l_pos_record.segment10;
6771     l_position_i_cache(l_source_cache_count).segment11   := l_pos_record.segment11;
6772     l_position_i_cache(l_source_cache_count).segment12   := l_pos_record.segment12;
6773     l_position_i_cache(l_source_cache_count).segment13   := l_pos_record.segment13;
6774     l_position_i_cache(l_source_cache_count).segment14   := l_pos_record.segment14;
6775     l_position_i_cache(l_source_cache_count).segment15   := l_pos_record.segment15;
6776     l_position_i_cache(l_source_cache_count).segment16   := l_pos_record.segment16;
6777     l_position_i_cache(l_source_cache_count).segment17   := l_pos_record.segment17;
6778     l_position_i_cache(l_source_cache_count).segment18   := l_pos_record.segment18;
6779     l_position_i_cache(l_source_cache_count).segment19   := l_pos_record.segment19;
6780     l_position_i_cache(l_source_cache_count).segment20   := l_pos_record.segment20;
6781     l_position_i_cache(l_source_cache_count).segment21   := l_pos_record.segment21;
6782     l_position_i_cache(l_source_cache_count).segment22   := l_pos_record.segment22;
6783     l_position_i_cache(l_source_cache_count).segment23   := l_pos_record.segment23;
6784     l_position_i_cache(l_source_cache_count).segment24   := l_pos_record.segment24;
6785     l_position_i_cache(l_source_cache_count).segment25   := l_pos_record.segment25;
6786     l_position_i_cache(l_source_cache_count).segment26   := l_pos_record.segment26;
6787     l_position_i_cache(l_source_cache_count).segment27   := l_pos_record.segment27;
6788     l_position_i_cache(l_source_cache_count).segment28   := l_pos_record.segment28;
6789     l_position_i_cache(l_source_cache_count).segment29   := l_pos_record.segment29;
6790     l_position_i_cache(l_source_cache_count).segment30   := l_pos_record.segment30;
6791 
6792     /* Bug 4551061 Start */
6793     l_position_i_cache(l_source_cache_count).availability_status
6794                                   := l_pos_record.availability_status;
6795     /* Bug 4551061 End */
6796 
6797   IF l_position_source%NOTFOUND THEN
6798     EXIT;
6799   END IF;
6800 
6801     l_last_hr_position_id:= l_pos_record.hr_position_id;
6802 
6803   END LOOP; -- END processing all the positions FROM psb_positions_i table.
6804   CLOSE l_position_source;
6805   /* Bug 3417868 End */
6806 
6807     /* For Bug No: 3066598 Start */
6808     IF (l_status_flag <> 'I' ) or (l_last_success_flag = 'N') THEN
6809       --
6810       PSB_HR_EXTRACT_DATA_PVT.Update_Reentry
6811       ( p_api_version      =>  1.0  ,
6812         p_return_status    =>  l_return_status,
6813         p_msg_count        =>  l_msg_count,
6814         p_msg_data         =>  l_msg_data,
6815         p_data_extract_id  =>  p_data_extract_id,
6816         p_extract_method   =>  p_extract_method,
6817         p_process          =>  'PSB Positions',
6818         p_restart_id       =>  prev_hr_position_id
6819       );
6820       --
6821       if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6822         raise FND_API.G_EXC_ERROR;
6823       end if;
6824       --
6825     END IF;
6826 
6827     /* For Bug No: 3066598  Start*/
6828     IF (l_status_flag <> 'I' ) THEN
6829       --
6830       PSB_HR_EXTRACT_DATA_PVT.Reentrant_Process
6831       ( p_api_version     => 1.0  ,
6832         p_return_status   => l_return_status,
6833         p_msg_count       => l_msg_count,
6834         p_msg_data        => l_msg_data,
6835         p_data_extract_id => p_data_extract_id,
6836         p_extract_method  => p_extract_method,
6837         p_process         => 'PSB Positions'
6838       );
6839       --
6840       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6841         RAISE FND_API.G_EXC_ERROR;
6842       END IF;
6843       --
6844     END IF;
6845 
6846     COMMIT WORK;
6847 
6848   END IF; -- Check IF (l_status = 'I')
6849   --
6850   -- for bug 4213882
6851   PSB_HR_POPULATE_DATA_PVT.g_extract_method := null;
6852   PSB_HR_POPULATE_DATA_PVT.g_pop_assignment := null;
6853 
6854 EXCEPTION
6855   --
6856   WHEN FND_API.G_EXC_ERROR THEN
6857     --
6858     ROLLBACK to Populate_Position;
6859     p_return_status := FND_API.G_RET_STS_ERROR;
6860     FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
6861 		               p_data  => p_msg_data);
6862     FND_MESSAGE.SET_NAME('PSB', 'PSB_POSITION_DETAILS');
6863     FND_MESSAGE.SET_TOKEN('POSITION_NAME',l_position_name );
6864     FND_MESSAGE.SET_TOKEN('EMPLOYEE_NAME',l_employee_name );
6865     FND_MSG_PUB.Add;
6866   --
6867   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6868     ROLLBACK to Populate_Position;
6869     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6870     FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
6871                                p_data  => p_msg_data);
6872     FND_MESSAGE.SET_NAME('PSB', 'PSB_POSITION_DETAILS');
6873     FND_MESSAGE.SET_TOKEN('POSITION_NAME',l_position_name );
6874     FND_MESSAGE.SET_TOKEN('EMPLOYEE_NAME',l_employee_name );
6875     FND_MSG_PUB.Add;
6876   --
6877   WHEN OTHERS THEN
6878     --
6879     ROLLBACK to Populate_Position;
6880     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6881     FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
6882                                p_data  => p_msg_data);
6883 
6884     FND_MESSAGE.SET_NAME('PSB', 'PSB_POSITION_DETAILS');
6885     FND_MESSAGE.SET_TOKEN('POSITION_NAME',l_position_name );
6886     FND_MESSAGE.SET_TOKEN('EMPLOYEE_NAME',l_employee_name );
6887     FND_MSG_PUB.Add;
6888 
6889     IF FND_MSG_PUB.Check_Msg_Level
6890       (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6891     THEN
6892       FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME ,
6893 	                       l_api_name ) ;
6894     END IF;
6895     --
6896 END Populate_Position_Information;
6897 /*---------------------------------------------------------------------------*/
6898 
6899 
6900 /* ----------------------------------------------------------------------- */
6901 PROCEDURE Populate_Employee_Information
6902 ( p_api_version         IN      NUMBER,
6903   p_init_msg_lISt       IN      VARCHAR2 := FND_API.G_FALSE,
6904   p_commit              IN      VARCHAR2 := FND_API.G_FALSE,
6905   p_validation_level    IN      NUMBER   := FND_API.G_VALID_LEVEL_FULL,
6906   p_return_status       OUT  NOCOPY     VARCHAR2,
6907   p_msg_count           OUT  NOCOPY     NUMBER,
6908   p_msg_data            OUT  NOCOPY     VARCHAR2,
6909   p_data_extract_id     IN      NUMBER,
6910   -- de by org
6911   p_extract_by_org      IN      VARCHAR2,
6912   p_extract_method      IN      VARCHAR2,
6913   p_business_group_id   IN      NUMBER,
6914   p_set_of_books_id     IN      NUMBER
6915 ) AS
6916 
6917   l_last_update_date    DATE;
6918   l_last_upDATEd_BY     number;
6919   l_last_upDATE_login   number;
6920   l_creation_DATE       DATE;
6921   l_created_BY          number;
6922   l_employee_id         number;
6923   l_position_name       varchar2(240);
6924   --UTF8 changes for Bug No : 2615261
6925   l_employee_name       varchar2(310);
6926   l_status              varchar2(1);
6927   l_restart_hr_position_id number := 0;
6928   l_hr_postion_ctr      number := 0;
6929   -- de by org
6930   l_extract_method      varchar2(30);
6931 
6932   l_api_name            CONSTANT VARCHAR2(30)   := 'Populate_Employee';
6933   l_api_version         CONSTANT NUMBER         := 1.0;
6934 
6935   -- Outer join IS NOT needed FOR ( pe.hr_employee_id  = pp.hr_employee_id)
6936   -- because psb_positions IS populated with proper hr_employee_id prior to
6937   -- running thIS process.
6938   /*For Bug No : 2594575 Start*/
6939   --Stop extracting secured data of employee
6940   --Removed the columns in psb_employees table
6941   /*For Bug No : 2594575 End*/
6942 
6943   Cursor C_Employees IS
6944     Select pe.hr_employee_id,
6945 	   pe.hr_position_id,
6946 	   position_id,
6947            -- de by org
6948            organization_id,
6949 	   assignment_id,first_name,
6950 	   full_name, known_as,
6951 	   last_name, middle_names, title,
6952 	   pe.effective_start_DATE,
6953 	   pe.change_DATE,
6954 	   grade_id,grade_step,sequence_number,
6955 	   pay_basIS,rate_id,
6956 	   salary_type,rate_or_payscale_id,
6957 	   element_value,proposed_salary,
6958 	   employee_number,
6959 	   pp.set_of_books_id
6960       FROM psb_employees_i  pe,
6961 	   psb_positions    pp
6962      WHERE pe.data_extract_id = p_data_extract_id
6963        AND pe.data_extract_id = pp.data_extract_id
6964        AND pe.hr_position_id  = pp.hr_position_id
6965        AND pe.hr_employee_id  = pp.hr_employee_id
6966        AND pe.hr_position_id > l_restart_hr_position_id
6967      ORDER BY pe.hr_position_id, proposed_salary;
6968 
6969 
6970   /*Cursor Added for Bug#4135280 */
6971   /*Modified the cursor for Bug#4166493, to take care of date tracked HR data*/
6972    CURSOR C_Terminated_Employees IS
6973    SELECT distinct position_assignment_id,pp.position_id,pe.hr_employee_id
6974       FROM psb_position_assignments ppa,psb_positions pp,psb_employees pe,
6975            per_all_assignments_f paf
6976       WHERE ppa.position_id=pp.position_id
6977       AND ppa.data_extract_id=p_data_extract_id
6978       AND pp.hr_position_id > l_restart_hr_position_id
6979       AND paf.position_id=pp.hr_position_id
6980       AND paf.person_id=pe.hr_employee_id
6981       AND paf.person_id not in
6982                              (select person_id
6983                               from   per_all_assignments_f paf2,fnd_sessions fs
6984                               where  fs.effective_date between paf2.effective_start_date
6985                                                              and paf2.effective_end_date
6986                               and assignment_type='E' and position_id=paf.position_id
6987                               and fs.session_id=USERENV('sessionid'))
6988       AND paf.assignment_type='E'
6989       AND pp.hr_employee_id IS NULL
6990       AND ppa.assignment_type='EMPLOYEE';
6991 
6992 /*      SELECT distinct position_assignment_id,pp.position_id,pe.hr_employee_id
6993       FROM psb_position_assignments ppa,psb_positions pp,psb_employees pe,
6994            per_all_assignments_f paf
6995       WHERE ppa.position_id=pp.position_id
6996       AND ppa.data_extract_id=p_data_extract_id
6997       AND pp.hr_position_id > l_restart_hr_position_id
6998       AND paf.position_id=pp.hr_position_id
6999       AND paf.person_id=pe.hr_employee_id
7000       AND not exists (select fs.session_id from fnd_sessions fs
7001                       where fs.effective_date between paf.effective_start_date
7002                          and paf.effective_end_date
7003                       and fs.session_id=USERENV('sessionid') )
7004       AND paf.assignment_type='E'
7005       AND pp.hr_employee_id IS NULL
7006       AND ppa.assignment_type ='EMPLOYEE'; */
7007 
7008     refresh_employee_id        number ;
7009     prev_hr_position_id        number := -1;
7010     prev_rate_or_payscale_id   number := -1;
7011     prev_rate_or_payscale_name varchar2(30);
7012     prev_grade_step            number;
7013     prev_grade_id              number;
7014     prev_grade_name            varchar2(80);
7015     prev_sequence_number       number;
7016     prev_element_value         number;
7017     prev_proposed_salary       number;
7018     prev_change_DATE           DATE;
7019     prev_pay_basIS             varchar2(30);
7020     prev_salary_type           varchar2(10);
7021 
7022     l_rowid                    varchar2(100);
7023     lr_position_id             number;
7024     lr_position_assignment_id  number;
7025     l_position_assignment_id   number;
7026     l_ppay_element_id          number;
7027     ln_pay_element_id          number := 0;
7028     l_ppay_element_option_id   number;
7029     l_ppay_element_rate_id     number;
7030     l_peffective_start_DATE    DATE;
7031     l_peffective_END_DATE      DATE;
7032     l_pelement_value           number;
7033     l_proposed_salary          number;
7034     l_currency_code            varchar2(30);
7035     l_return_status            varchar2(1);
7036     l_salary_type              varchar2(10);
7037     l_msg_count                number;
7038     l_msg_data                 varchar2(2000);
7039     l_employee_dummy           number := 1 ;
7040     l_element_dummy            number := 1 ;
7041     l_non_grade_salary         varchar2(1) := 'N';
7042     l_tmp                      varchar2(1);
7043     l_non_grade_salary_name    varchar2(30);
7044     l_hr_position_ctr        number := 0;
7045 
7046     Cursor C_currency IS
7047        Select currency_code
7048 	 FROM gl_sets_of_books
7049 	WHERE set_of_books_id = p_set_of_books_id;
7050 
7051     Cursor C_salary IS
7052        Select rate_or_payscale_name,grade_name
7053 	 FROM psb_salary_i
7054 	WHERE rate_or_payscale_id  = prev_rate_or_payscale_id
7055 	  AND grade_id             = prev_grade_id
7056 	  AND grade_step           = prev_grade_step
7057 	  AND sequence_number      = prev_sequence_number
7058 	  AND data_extract_id      = p_data_extract_id;
7059 
7060     Cursor C_rate_salary IS
7061        Select rate_or_payscale_name,grade_name
7062 	 FROM psb_salary_i
7063 	WHERE rate_or_payscale_id = prev_rate_or_payscale_id
7064 	  AND grade_id            = prev_grade_id
7065 	  AND data_extract_id     = p_data_extract_id;
7066 
7067     Cursor C_pay_elements_step IS
7068        Select ppe.pay_element_id ,ppe.salary_type,
7069 	      ppo.pay_element_option_id
7070 	 FROM psb_pay_elements ppe,
7071 	      psb_pay_element_options ppo
7072 	WHERE ppe.data_extract_id = p_data_extract_id
7073 	  AND ppe.salary_type     = 'STEP'
7074 	  AND ppe.name            = prev_rate_or_payscale_name
7075 	  AND ppe.pay_element_id  = ppo.pay_element_id
7076 	  AND ppo.name            = prev_grade_name
7077 	  AND ppo.grade_step      = prev_grade_step
7078 	  AND ppo.sequence_number = prev_sequence_number;
7079 
7080     Cursor C_pay_elements_rate IS
7081        Select ppe.pay_element_id ,ppe.salary_type,
7082 	      ppo.pay_element_option_id
7083 	 FROM psb_pay_elements ppe,
7084 	      psb_pay_element_options ppo
7085 	WHERE ppe.data_extract_id = p_data_extract_id
7086 	  AND ppe.salary_type     = 'RATE'
7087 	  AND ppe.name            = prev_rate_or_payscale_name
7088 	  AND ppe.pay_element_id  = ppo.pay_element_id
7089 	  AND ppo.name            = prev_grade_name;
7090 
7091     /*Cursor C_pay_element_options IS
7092        Select pay_element_option_id
7093 	 FROM psb_pay_element_options
7094 	WHERE pay_element_id  = l_ppay_element_id
7095 	  AND name            = prev_grade_name
7096 	  AND grade_step      = prev_grade_step
7097 	  AND sequence_number = prev_sequence_number;
7098 
7099     Cursor C_pay_element_rate_options IS
7100        Select pay_element_option_id
7101 	 FROM psb_pay_element_options
7102 	WHERE pay_element_id  = l_ppay_element_id
7103 	  AND name            = prev_grade_name; */
7104 
7105     Cursor C_pay_element_rates IS
7106        Select pay_element_rate_id,
7107 	      effective_start_DATE,
7108 	      effective_END_DATE,
7109 	      element_value,
7110 	      currency_code
7111 	 FROM psb_pay_element_rates
7112 	WHERE pay_element_id        = l_ppay_element_id
7113 	  AND pay_element_option_id = l_ppay_element_option_id;
7114 
7115     Cursor C_non_grade_salary IS
7116        Select pay_element_id
7117 	 FROM psb_pay_elements
7118 	WHERE data_extract_id = p_data_extract_id
7119 	  AND option_flag    = 'N'
7120 	  AND overwrite_flag = 'Y'
7121 	  AND name           = l_non_grade_salary_name;
7122 
7123 BEGIN
7124 
7125   Savepoint Populate_Employee;
7126 
7127   l_last_upDATE_DATE  := sysDATE;
7128   l_last_upDATEd_BY   := FND_GLOBAL.USER_ID;
7129   l_last_upDATE_login := FND_GLOBAL.LOGIN_ID;
7130   l_creation_DATE     := sysDATE;
7131   l_created_BY        := FND_GLOBAL.USER_ID;
7132 
7133   -- StANDard call to check FOR call compatibility.
7134 
7135   IF NOT FND_API.Compatible_API_Call (l_api_version,
7136 					p_api_version,
7137 					l_api_name,
7138 					G_PKG_NAME)
7139   THEN
7140     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7141   END IF;
7142 
7143   -- Initialize message lISt IF p_init_msg_lISt IS set to TRUE.
7144 
7145   IF FND_API.to_Boolean (p_init_msg_lISt) THEN
7146     FND_MSG_PUB.initialize;
7147   END IF;
7148 
7149   -- Initialize API return status to success
7150 
7151   p_return_status := FND_API.G_RET_STS_SUCCESS;
7152 
7153   -- API body
7154 
7155   -- de by org
7156 
7157   --  If extract_method is REFRESH do nothing.
7158   --  Else use the appropriate extract_method based on  the organization's
7159   --  extract status. cache_org_status caches statuses of all organizations.
7160 
7161   IF (p_extract_by_org = 'N' OR p_extract_method = 'REFRESH') THEN
7162      l_extract_method := p_extract_method;
7163   ELSE
7164      cache_org_status
7165          ( l_return_status,
7166            p_data_extract_id,
7167            p_extract_by_org
7168           );
7169 
7170      IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7171        RAISE FND_API.G_EXC_ERROR;
7172      END IF;
7173 
7174   END IF;
7175 
7176 
7177 
7178   PSB_HR_EXTRACT_DATA_PVT.Check_Reentry
7179   (  p_api_version              => 1.0  ,
7180      p_return_status            => l_return_status,
7181      p_msg_count                => l_msg_count,
7182      p_msg_data                 => l_msg_data,
7183      p_data_extract_id          => p_data_extract_id,
7184      p_process                  => 'PSB Employees',
7185      p_status                   => l_status,
7186      p_restart_id               => l_restart_hr_position_id
7187     );
7188 
7189   IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7190     RAISE FND_API.G_EXC_ERROR;
7191   END IF;
7192 
7193   IF (l_status = 'I') THEN
7194 
7195     -- Retrieve currency_code FOR the extract related set_of_books_id.
7196     FOR C_currency_rec in C_currency
7197     LOOP
7198       l_currency_code := C_currency_rec.currency_code;
7199     END LOOP;
7200 
7201     FOR employee_rec in C_Employees
7202     LOOP
7203 
7204       -- Initialize the local variables.
7205       prev_rate_or_payscale_name := NULL;
7206       prev_grade_name            := NULL;
7207       prev_rate_or_payscale_id := employee_rec.rate_or_payscale_id;
7208       prev_grade_id            := employee_rec.grade_id;
7209       prev_grade_step          := employee_rec.grade_step;
7210       prev_sequence_number     := employee_rec.sequence_number;
7211       prev_proposed_salary     := employee_rec.proposed_salary;
7212       prev_element_value       := employee_rec.element_value;
7213       prev_change_DATE         := employee_rec.change_DATE;
7214       prev_pay_basIS           := employee_rec.pay_basIS;
7215       prev_salary_type         := employee_rec.salary_type;
7216       l_position_name          := NULL;
7217       l_employee_name          := NULL;
7218 
7219     -- de by org
7220     -- If extract method is not REFRESH, get the status of the organization
7221     -- to which the employee belongs from the already cached organization
7222     -- statuses.
7223 
7224       IF p_extract_method <> 'REFRESH' and p_extract_by_org = 'Y' THEN
7225         l_extract_method := g_org_status(employee_rec.organization_id);
7226       END IF;
7227 
7228 
7229       IF (employee_rec.hr_employee_id IS NOT NULL) THEN
7230        FOR Emp_Name_Rec in G_Employee_Details(p_person_id => employee_rec.hr_employee_id)
7231        LOOP
7232 	 l_employee_name := Emp_Name_Rec.first_name||' '||Emp_Name_Rec.last_name;
7233        END LOOP;
7234       END IF;
7235 
7236       IF (employee_rec.position_id IS NOT NULL) THEN
7237        FOR Pos_Name_Rec in G_Position_Details(p_position_id => employee_rec.position_id)
7238        LOOP
7239 	 l_position_name := Pos_Name_Rec.name;
7240        END LOOP;
7241       END IF;
7242 
7243       l_non_grade_salary       := 'N';
7244       l_ppay_element_id        := 0;
7245       l_ppay_element_option_id := 0;
7246       l_ppay_element_rate_id   := 0;
7247 
7248       if ((employee_rec.hr_position_id <> prev_hr_position_id)
7249 	and (prev_hr_position_id <> -1)) then
7250 	l_hr_position_ctr := l_hr_position_ctr + 1;
7251 
7252        if l_hr_position_ctr = PSB_WS_ACCT1.g_checkpoint_save then
7253 	   PSB_HR_EXTRACT_DATA_PVT.Update_Reentry
7254 	   ( p_api_version              => 1.0  ,
7255 	     p_return_status            => l_return_status,
7256 	     p_msg_count                => l_msg_count,
7257 	     p_msg_data                 => l_msg_data,
7258 	     p_data_extract_id          => p_data_extract_id,
7259              p_extract_method           => p_extract_method,
7260 	     p_process                  => 'PSB Employees',
7261 	     p_restart_id               => prev_hr_position_id
7262 	  );
7263 	  if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7264 	     raise FND_API.G_EXC_ERROR;
7265 	  end if;
7266 	  commit work;
7267 	  l_hr_position_ctr := 0;
7268 	  Savepoint Populate_Employee;
7269        end if;
7270       end if;
7271 
7272       /*IF (p_extract_method <> 'CREATE') THEN
7273 
7274 	-- Store the employee_id FOR which refreshing will take place.
7275 	-- Note thIS refresh_employee_id also points to a unique position.
7276 	refresh_employee_id := employee_rec.hr_employee_id ;
7277 
7278 	-- To refresh, first remove refresh employee_id related assignments.
7279 	-- Note these assignments will be created/upDATEd later as part of
7280 	-- refreshing.
7281 	Begin
7282 
7283 	  -- Delete 'ELEMENT' assignments.
7284 	  Delete Psb_Position_Assignments
7285 	   WHERE position_id     = employee_rec.position_id
7286 	     AND data_extract_id = p_data_extract_id
7287 	     AND assignment_type = 'ELEMENT';
7288 
7289 	  -- Delete 'ATTRIBUTE' assignments.
7290 	  Delete Psb_Position_Assignments
7291 	   WHERE position_id     = employee_rec.position_id
7292 	     AND data_extract_id = p_data_extract_id
7293 	     AND assignment_type = 'ATTRIBUTE';
7294 
7295 	EXCEPTION
7296 	  WHEN NO_DATA_FOUND THEN
7297 	    NULL;
7298 	END; -- END remove FOR the refresh employe related assignments..
7299 
7300       END IF; -- END (p_extract_method <> 'CREATE') FOR Remove phase.*/
7301 
7302       -- Check whether the salary IS Grade one or NOT.
7303       IF ((prev_rate_or_payscale_id IS NULL) or (prev_rate_or_payscale_id = 0)
7304 	 or (prev_grade_id IS NULL) or (prev_grade_id = 0))
7305       THEN
7306 
7307 	l_non_grade_salary := 'Y';
7308 	ln_pay_element_id := 0;
7309 	l_non_grade_salary_name := '';
7310 	fnd_message.set_name('PSB','PSB_NON_GRADE_SALARY');
7311 	l_non_grade_salary_name  := FND_MESSAGE.GET;
7312 	prev_rate_or_payscale_name := l_non_grade_salary_name;
7313 
7314 	FOR C_non_grade_salary_rec in C_non_grade_salary
7315 	LOOP
7316 	  ln_pay_element_id := C_non_grade_salary_rec.pay_element_id;
7317 	END LOOP;
7318 
7319 	-- Create a pay element.
7320 	IF (ln_pay_element_id = 0) THEN
7321 
7322 	  Select psb_pay_elements_s.nextval INTO ln_pay_element_id
7323 	  FROM   dual;
7324 
7325 	  PSB_PAY_ELEMENTS_PVT.INSERT_ROW
7326 	  ( p_api_version             =>  1.0,
7327 	    p_init_msg_lISt           => NULL,
7328 	    p_commit                  => NULL,
7329 	    p_validation_level        => NULL,
7330 	    p_return_status           => l_return_status,
7331 	    p_msg_count               => l_msg_count,
7332 	    p_msg_data                => l_msg_data,
7333 	    p_row_id                  => l_rowid,
7334 	    p_pay_element_id          => ln_pay_element_id,
7335 	    p_business_group_id       => p_business_group_id,
7336 	    p_data_extract_id         => p_data_extract_id,
7337 	    p_name                    => l_non_grade_salary_name,
7338 	    p_description             => NULL,
7339 	    p_element_value_type      => 'A',
7340 	    p_FORmula_id              => NULL,
7341 	    p_overwrite_flag          => 'Y',
7342 	    p_required_flag           => NULL,
7343 	    p_follow_salary           => NULL,
7344 	    p_pay_basIS               => prev_pay_basIS,
7345 	    p_start_DATE              => prev_change_DATE,
7346 	    p_END_DATE                => NULL,
7347 	    p_processing_type         => 'R',
7348 	    p_period_type             => NULL,
7349 	    p_process_period_type     => NULL,
7350 	    p_max_element_value_type  => NULL,
7351 	    p_max_element_value       => NULL,
7352 	    p_salary_flag             => 'Y',
7353 	    p_salary_type             => 'VALUE',
7354 	    p_option_flag             => 'N',
7355 	    p_hr_element_type_id      => NULL,
7356 	    p_attribute_category      => NULL,
7357 	    p_attribute1              => NULL,
7358 	    p_attribute2              => NULL,
7359 	    p_attribute3              => NULL,
7360 	    p_attribute4              => NULL,
7361 	    p_attribute5              => NULL,
7362 	    p_attribute6              => NULL,
7363 	    p_attribute7              => NULL,
7364 	    p_attribute8              => NULL,
7365 	    p_attribute9              => NULL,
7366 	    p_attribute10             => NULL,
7367 	    p_last_upDATE_DATE        => l_last_update_date,
7368 	    p_last_upDATEd_BY         => l_last_upDATEd_BY,
7369 	    p_last_upDATE_login       => l_last_upDATE_login,
7370 	    p_created_BY              => l_created_BY,
7371 	    p_creation_DATE           => l_creation_DATE
7372 	  );
7373 
7374 	  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7375 	    RAISE FND_API.G_EXC_ERROR;
7376 	  END IF;
7377 
7378 	END IF; -- Check IF (ln_pay_element_id = 0) to create a pay element.
7379 
7380       END IF; -- ENd checking whether the salary IS Grade one or NOT.
7381 
7382       IF (l_non_grade_salary = 'N') THEN
7383 
7384 	IF (prev_salary_type = 'STEP') THEN
7385 	  FOR C_Sal_Rec in C_salary
7386 	    LOOP
7387 	      prev_rate_or_payscale_name := C_Sal_Rec.rate_or_payscale_name;
7388 	      prev_grade_name            := C_Sal_Rec.grade_name;
7389 	  END LOOP;
7390 	  FOR C_pay_elements_step_rec in C_pay_elements_step
7391 	  LOOP
7392 	   l_ppay_element_id        := C_pay_elements_step_rec.pay_element_id;
7393 	   l_salary_type            := C_pay_elements_step_rec.salary_type;
7394 	   l_ppay_element_option_id := C_pay_elements_step_rec.pay_element_option_id;
7395 	  END LOOP;
7396 	END IF;
7397 
7398 	IF (prev_salary_type = 'RATE') THEN
7399 	  FOR C_Sal_Rate_Rec in C_rate_salary
7400 	  LOOP
7401 	    prev_rate_or_payscale_name :=
7402 				      C_Sal_Rate_Rec.rate_or_payscale_name;
7403 	    prev_grade_name            := C_Sal_Rate_Rec.grade_name;
7404 	  END LOOP;
7405 	  FOR C_pay_elements_rate_rec in C_pay_elements_rate
7406 	  LOOP
7407 	   l_ppay_element_id        := C_pay_elements_rate_rec.pay_element_id;
7408 	   l_salary_type            := C_pay_elements_rate_rec.salary_type;
7409 	   l_ppay_element_option_id := C_pay_elements_rate_rec.pay_element_option_id;
7410 	  END LOOP;
7411 	END IF;
7412 
7413 	FOR C_pay_element_rates_rec in C_pay_element_rates
7414 	LOOP
7415 	  l_ppay_element_rate_id :=
7416 				C_pay_element_rates_rec.pay_element_rate_id;
7417 	  l_peffective_start_DATE :=
7418 			       C_pay_element_rates_rec.effective_start_DATE;
7419 	  l_peffective_END_DATE := C_pay_element_rates_rec.effective_END_DATE;
7420 	  l_pelement_value      := C_pay_element_rates_rec.element_value;
7421 	  l_currency_code       := C_pay_element_rates_rec.currency_code;
7422 	END LOOP;
7423 
7424       else
7425 
7426 	l_ppay_element_id := ln_pay_element_id;
7427 
7428       END IF; -- IF (l_non_grade_salary = 'N') clause.
7429 
7430 
7431 
7432 
7433       --
7434       -- UpDATE 'EMPLOYEE' type assignments in 'REFRESH' mode..
7435       -- UpDATE psb_employees table as well.
7436       --
7437       -- de by org
7438       --
7439       -- l_extract_method contains the organization's status. Hence using it
7440       -- in lieu of p_extract_method
7441 
7442       IF (l_extract_method = 'REFRESH') THEN
7443 
7444          /*For Bug No : 2594575 Start*/
7445          --Stop extracting secured data of employee
7446          --Removed the columns in psb_employees table
7447          /*For Bug No : 2594575 End*/
7448 
7449 	 -- UpDATE psb_employees table.
7450 	 UpDATE Psb_Employees
7451 	     set first_name           = employee_rec.first_name,
7452 		 full_name            = employee_rec.full_name,
7453 		 known_as             = employee_rec.known_as,
7454 		 last_name            = employee_rec.last_name,
7455 		 middle_names         = employee_rec.middle_names,
7456 		 title                = employee_rec.title,
7457 		 last_upDATE_DATE     = l_last_update_date,
7458 		 last_upDATEd_BY      = l_last_upDATEd_BY,
7459 		 last_upDATE_login    = l_last_upDATE_login,
7460 		 created_BY           = l_created_BY,
7461 		 creation_DATE        = l_creation_DATE
7462 	   WHERE hr_employee_id       = employee_rec.hr_employee_id
7463 	     AND data_extract_id      = p_data_extract_id
7464 	     AND business_group_id    = p_business_group_id;
7465 
7466 	--
7467 	l_employee_dummy := 0;
7468 
7469 	-- UpDATE position related assignment
7470 	-- (position_id = hr_employee_id + hr_position_id)
7471 	FOR l_pos_assignment_rec in
7472 	(
7473 	  Select employee_id, position_assignment_id
7474 	  FROM   psb_position_assignments
7475 	  WHERE  data_extract_id = p_data_extract_id
7476 	  AND    assignment_type = 'EMPLOYEE'
7477 	  AND    position_id     = employee_rec.position_id
7478 	)
7479 	LOOP
7480 
7481 	  l_employee_dummy := 1;
7482 
7483 	  PSB_POSITIONS_PVT.ModIFy_Assignment
7484 	  (
7485 	    p_api_version             => 1.0,
7486 	    p_return_status           => l_return_status,
7487 	    p_msg_count               => l_msg_count,
7488 	    p_msg_data                => l_msg_data,
7489 	    p_position_assignment_id  =>
7490 				 l_pos_assignment_rec.position_assignment_id,
7491 	    p_data_extract_id         => p_data_extract_id,
7492 	    p_worksheet_id            => NULL,
7493 	    p_position_id             => employee_rec.position_id,
7494 	    p_assignment_type         => 'EMPLOYEE',
7495 	    p_attribute_id            => NULL,
7496 	    p_attribute_value_id      => NULL,
7497 	    p_attribute_value         => NULL,
7498 	    p_pay_element_id          => NULL,
7499 	    p_pay_element_option_id   => NULL,
7500 	    p_effective_start_DATE    => employee_rec.effective_start_DATE,
7501 	    p_effective_END_DATE      => NULL,
7502 	    p_element_value_type      => NULL,
7503 	    p_element_value           => NULL,
7504 	    p_currency_code           => NULL,
7505 	    p_pay_basIS               => NULL,
7506 	    p_global_default_flag     => NULL,
7507 	    p_assignment_default_rule_id => NULL,
7508 	    p_modIFy_flag             => NULL,
7509 	    p_rowid                   => l_rowid,
7510 	    p_employee_id             => l_pos_assignment_rec.employee_id,
7511 	    p_primary_employee_flag   => 'Y'
7512 	  );
7513 
7514 	  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7515 	    RAISE FND_API.G_EXC_ERROR;
7516 	  END IF;
7517 
7518 	END LOOP; -- END upDATE position related assignment.
7519 
7520       END IF; -- END updating 'EMPLOYEE' type assignments in 'REFRESH' mode.
7521 
7522       --
7523       -- UpDATE 'ELEMENT' type assignments in 'REFRESH' mode..
7524       --
7525       -- de by org
7526       --
7527       -- l_extract_method contains the organization's status. Hence using it
7528       -- in lieu of p_extract_method
7529 
7530       IF (l_extract_method = 'REFRESH') THEN
7531 
7532 	-- l_element_dummy determines whether at least one record got refreshed
7533 	-- or NOT. If NOT, we consider 'CREATE' mode later FOR updation etc.
7534 	l_element_dummy := 0;
7535 
7536 	-- Refresh position element assignments with the new element value.
7537 	FOR C_element_assignments_rec in
7538 	(
7539 	   Select position_assignment_id,
7540 		  employee_id
7541 	   FROM   psb_position_assign_element_v
7542 	   WHERE  data_extract_id = p_data_extract_id
7543 	   AND    position_id     = employee_rec.position_id
7544 	   AND    salary_flag     = 'Y'
7545 	)
7546 	LOOP
7547 
7548 	  l_element_dummy := 1;
7549 
7550 	  IF ((prev_element_value is not null) and (prev_proposed_salary = prev_element_value)) THEN
7551 	    l_proposed_salary := NULL;
7552 	  else
7553 	    l_proposed_salary := prev_proposed_salary;
7554 	  END IF;
7555 
7556 	  PSB_POSITION_ASSIGNMENTS_PVT.UPDATE_ROW
7557 	  (
7558 	    p_api_version             => 1,
7559 	    p_init_msg_lISt           => NULL,
7560 	    p_commit                  => NULL,
7561 	    p_validation_level        => NULL,
7562 	    p_return_status           => l_return_status,
7563 	    p_msg_count               => l_msg_count,
7564 	    p_msg_data                => l_msg_data,
7565 	    p_position_assignment_id  =>
7566 			      C_element_assignments_rec.position_assignment_id,
7567 	    p_pay_element_id          => l_ppay_element_id,
7568 	    p_pay_element_option_id   => l_ppay_element_option_id,
7569 	    p_attribute_value_id      => NULL,
7570 	    p_attribute_value         => NULL,
7571 	    p_effective_END_DATE      => NULL,
7572 	    p_element_value_type      => 'A',
7573 	    p_element_value           => l_proposed_salary,
7574 	    p_pay_basIS               => prev_pay_basIS,
7575 	    p_employee_id             => C_element_assignments_rec.employee_id,
7576 	    p_primary_employee_flag   => NULL,
7577 	    p_global_default_flag     => NULL,
7578 	    p_assignment_default_rule_id => NULL,
7579 	    p_modIFy_flag             => NULL,
7580 	    p_mode                    => 'R'
7581 	  ) ;
7582 
7583 	  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7584 	    RAISE FND_API.G_EXC_ERROR;
7585 	  END IF;
7586 
7587 	END LOOP; -- END refreshing position element assignments.
7588 
7589       END IF; -- Check (p_extract_method = 'REFRESH') to refresh element_value.
7590 
7591       --
7592       -- Create 'EMPLOYEE' assignments in 'CREATE' mode.
7593       -- Populate employees in psb_employees table as well.
7594       --
7595       IF (l_extract_method = 'CREATE' or l_employee_dummy = 0) THEN
7596 
7597 	Select psb_employees_s.nextval INTO l_employee_id
7598 	FROM   dual;
7599 
7600         /*For Bug No : 2594575 Start*/
7601         --Stop extracting secured data of employee
7602         --Removed the columns in psb_employees table
7603         /*For Bug No : 2594575 End*/
7604 
7605 	-- Populate PSB_EMPLOOYEES table as it IS 'CREATE' mode.
7606 	INSERT INTO PSB_EMPLOYEES
7607 	( EMPLOYEE_ID       ,
7608 	  HR_EMPLOYEE_ID    ,
7609 	  EMPLOYEE_NUMBER   ,
7610 	  FIRST_NAME        ,
7611 	  FULL_NAME         ,
7612 	  KNOWN_AS          ,
7613 	  LAST_NAME         ,
7614 	  MIDDLE_NAMES      ,
7615 	  TITLE             ,
7616 	  BUSINESS_GROUP_ID ,
7617 	  LAST_UPDATE_DATE   ,
7618 	  LAST_UPDATED_BY    ,
7619 	  LAST_UPDATE_LOGIN  ,
7620 	  CREATED_BY         ,
7621 	  CREATION_DATE      ,
7622 	  DATA_EXTRACT_ID    )
7623 	VALUES
7624 	( l_employee_id,
7625 	  employee_rec.hr_employee_id,
7626 	  employee_rec.employee_number,
7627 	  employee_rec.first_name,
7628 	  employee_rec.full_name,
7629 	  employee_rec.known_as,
7630 	  employee_rec.last_name,
7631 	  employee_rec.middle_names,
7632 	  employee_rec.title,
7633 	  p_business_group_id,
7634 	  l_last_update_date,
7635 	  l_last_upDATEd_BY ,
7636 	  l_last_upDATE_login ,
7637 	  l_created_BY,
7638 	  l_creation_DATE,
7639 	  p_data_extract_id
7640 	);
7641 
7642 	-- Create an 'EMPLOYEE' assignment FOR the related position_id.
7643 	PSB_POSITION_ASSIGNMENTS_PVT.INSERT_ROW
7644 	(
7645 	  p_api_version             => 1,
7646 	  p_init_msg_lISt           => NULL,
7647 	  p_commit                  => NULL,
7648 	  p_validation_level        => NULL,
7649 	  p_return_status           => l_return_status,
7650 	  p_msg_count               => l_msg_count,
7651 	  p_msg_data                => l_msg_data,
7652 	  p_rowid                   => l_rowid,
7653 	  p_position_assignment_id  => l_position_assignment_id,
7654 	  p_data_extract_id         => p_data_extract_id,
7655 	  p_worksheet_id            => NULL,
7656 	  p_position_id             => employee_rec.position_id,
7657 	  p_assignment_type         => 'EMPLOYEE',
7658 	  p_attribute_id            => NULL,
7659 	  p_attribute_value_id      => NULL,
7660 	  p_attribute_value         => NULL,
7661 	  p_pay_element_id          => NULL,
7662 	  p_pay_element_option_id   => NULL,
7663 	  p_effective_start_DATE    => employee_rec.effective_start_DATE,
7664 	  p_effective_END_DATE      => NULL,
7665 	  p_element_value_type      => NULL,
7666 	  p_element_value           => NULL,
7667 	  p_currency_code           => NULL,
7668 	  p_pay_basIS               => NULL,
7669 	  p_employee_id             => l_employee_id,
7670 	  p_primary_employee_flag   => 'Y' ,
7671 	  p_global_default_flag     => NULL,
7672 	  p_assignment_default_rule_id => NULL,
7673 	  p_modIFy_flag             => NULL,
7674 	  p_mode                    => 'R'
7675 	) ;
7676 
7677 	IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7678 	  RAISE FND_API.G_EXC_ERROR;
7679 	END IF;
7680 
7681       END IF; -- END creating 'EMPLOYEE' assignments in 'CREATE' mode.
7682 
7683       --
7684       -- Create 'ELEMENT' type assignments in 'CREATE' mode.
7685       --
7686       IF ( l_extract_method = 'CREATE' or l_element_dummy = 0 ) THEN
7687 
7688 	IF ((prev_element_value is not null) and (prev_proposed_salary = prev_element_value)) THEN
7689 	  l_proposed_salary := NULL;
7690 	else
7691 	  l_proposed_salary := prev_proposed_salary;
7692 	END IF;
7693 
7694 	PSB_POSITION_ASSIGNMENTS_PVT.INSERT_ROW
7695 	(
7696 	  p_api_version             => 1,
7697 	  p_init_msg_lISt           => NULL,
7698 	  p_commit                  => NULL,
7699 	  p_validation_level        => NULL,
7700 	  p_return_status           => l_return_status,
7701 	  p_msg_count               => l_msg_count,
7702 	  p_msg_data                => l_msg_data,
7703 	  p_rowid                   => l_rowid,
7704 	  p_position_assignment_id  => l_position_assignment_id,
7705 	  p_data_extract_id         => p_data_extract_id,
7706 	  p_worksheet_id            => NULL,
7707 	  p_position_id             => employee_rec.position_id,
7708 	  p_assignment_type         => 'ELEMENT',
7709 	  p_attribute_id            => NULL,
7710 	  p_attribute_value_id      => NULL,
7711 	  p_attribute_value         => NULL,
7712 	  p_pay_element_id          => l_ppay_element_id,
7713 	  p_pay_element_option_id   => l_ppay_element_option_id,
7714 	  p_effective_start_DATE    => prev_change_DATE,
7715 	  p_effective_END_DATE      => NULL,
7716 	  p_element_value_type      => 'A',
7717 	  p_element_value           => l_proposed_salary,
7718 	  p_currency_code           => l_currency_code,
7719 	  p_pay_basIS               => prev_pay_basIS,
7720 	  p_employee_id             => l_employee_id,
7721 	  p_primary_employee_flag   => NULL,
7722 	  p_global_default_flag     => NULL,
7723 	  p_assignment_default_rule_id => NULL,
7724 	  p_modIFy_flag             => NULL,
7725 	  p_mode                    => 'R'
7726 	) ;
7727 
7728 	IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7729 	  RAISE FND_API.G_EXC_ERROR;
7730 	END IF;
7731 
7732       END IF; -- END creating 'ELEMENT' type assignments in 'CREATE' mode..
7733 
7734       prev_hr_position_id := employee_rec.hr_position_id;
7735 
7736     END LOOP; -- FOR employee_rec in C_Employees
7737 
7738     --Logic added to fix bug#4135280
7739         --Delete the employee related assignments for terminated employees.
7740         -- Assumption is such employee's hr_employee_id column of position
7741         -- records will already be updated  to NULL
7742         --This is applicable only while refreshing the DE.
7743 
7744     IF (l_extract_method = 'REFRESH') THEN
7745 
7746        FOR terminated_rec IN C_Terminated_Employees
7747        LOOP
7748 
7749           PSB_POSITION_ASSIGNMENTS_PVT.Delete_Row
7750             ( p_api_version => 1.0,
7751               p_return_status => l_return_status,
7752               p_msg_count => l_msg_count,
7753               p_msg_data => l_msg_data,
7754               p_position_assignment_id =>terminated_rec.position_assignment_id);
7755 
7756           --Delete the terminated and to be orphanned record in psb_employees
7757           --Note that we are deleting for the DE and hence all the
7758           -- worksheets for this DE.
7759 
7760          delete from psb_employees
7761          where hr_employee_id=terminated_rec.hr_employee_id
7762          and data_extract_id=p_data_extract_id;
7763 
7764       END LOOP; -- FOR terminated_rec
7765     END IF;
7766 
7767    PSB_HR_EXTRACT_DATA_PVT.Update_Reentry
7768    ( p_api_version              => 1.0  ,
7769      p_return_status            => l_return_status,
7770      p_msg_count                => l_msg_count,
7771      p_msg_data                 => l_msg_data,
7772      p_data_extract_id          => p_data_extract_id,
7773      p_extract_method           => p_extract_method,
7774      p_process                  => 'PSB Employees',
7775      p_restart_id               => prev_hr_position_id
7776    );
7777    if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7778       raise FND_API.G_EXC_ERROR;
7779     end if;
7780 
7781     PSB_HR_EXTRACT_DATA_PVT.Reentrant_Process
7782     ( p_api_version              => 1.0  ,
7783       p_return_status            => l_return_status,
7784       p_msg_count                => l_msg_count,
7785       p_msg_data                 => l_msg_data,
7786       p_data_extract_id          => p_data_extract_id,
7787       p_extract_method           => p_extract_method,
7788       p_process                  => 'PSB Employees'
7789     );
7790 
7791     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7792       RAISE FND_API.G_EXC_ERROR;
7793     END IF;
7794 
7795     commit work;
7796 
7797   END IF;
7798 
7799   -- END of API body.
7800 
7801   EXCEPTION
7802 
7803    WHEN FND_API.G_EXC_ERROR THEN
7804      ROLLBACK to Populate_Employee;
7805      p_return_status := FND_API.G_RET_STS_ERROR;
7806      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
7807 				 p_data  => p_msg_data);
7808      FND_MESSAGE.SET_NAME('PSB', 'PSB_POSITION_DETAILS');
7809      FND_MESSAGE.SET_TOKEN('POSITION_NAME',l_position_name );
7810      FND_MESSAGE.SET_TOKEN('EMPLOYEE_NAME',l_employee_name );
7811      FND_MSG_PUB.Add;
7812 
7813    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7814      ROLLBACK to Populate_Employee;
7815      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7816      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
7817 				 p_data  => p_msg_data);
7818      FND_MESSAGE.SET_NAME('PSB', 'PSB_POSITION_DETAILS');
7819      FND_MESSAGE.SET_TOKEN('POSITION_NAME',l_position_name );
7820      FND_MESSAGE.SET_TOKEN('EMPLOYEE_NAME',l_employee_name );
7821      FND_MSG_PUB.Add;
7822 
7823    WHEN OTHERS THEN
7824      ROLLBACK to Populate_Employee;
7825      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7826      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
7827 				 p_data  => p_msg_data);
7828 
7829      FND_MESSAGE.SET_NAME('PSB', 'PSB_POSITION_DETAILS');
7830      FND_MESSAGE.SET_TOKEN('POSITION_NAME',l_position_name );
7831      FND_MESSAGE.SET_TOKEN('EMPLOYEE_NAME',l_employee_name );
7832      FND_MSG_PUB.Add;
7833 
7834      IF FND_MSG_PUB.Check_Msg_Level
7835        (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
7836      THEN
7837        FND_MSG_PUB.Add_Exc_Msg
7838 	  (p_pkg_name => G_PKG_NAME,
7839 	   p_procedure_name => l_api_name);
7840      END IF;
7841 
7842 END Populate_Employee_Information;
7843 
7844 /* ----------------------------------------------------------------------- */
7845 
7846 PROCEDURE Populate_Element_Information
7847 ( p_api_version         IN      NUMBER,
7848   p_init_msg_lISt       IN      VARCHAR2 := FND_API.G_FALSE,
7849   p_commit              IN      VARCHAR2 := FND_API.G_FALSE,
7850   p_validation_level    IN      NUMBER   := FND_API.G_VALID_LEVEL_FULL,
7851   p_return_status       OUT  NOCOPY     VARCHAR2,
7852   p_msg_count           OUT  NOCOPY     NUMBER,
7853   p_msg_data            OUT  NOCOPY     VARCHAR2,
7854   p_data_extract_id     IN      NUMBER,
7855   p_extract_method      IN      VARCHAR2,
7856   p_business_group_id   IN      NUMBER,
7857   p_set_of_books_id     IN      NUMBER
7858 ) AS
7859 
7860   l_last_update_date        DATE;
7861   l_last_upDATEd_BY         number;
7862   l_last_upDATE_login       number;
7863   l_creation_DATE           DATE;
7864   l_created_BY              number;
7865   l_dummy                   number;
7866   l_option_dummy            number;
7867   l_status                  varchar2(1);
7868   lr_rate_or_payscale_name  varchar2(30);
7869   lr_salary_type            varchar2(10);
7870   lr_grade_name             varchar2(240);
7871   lr_grade_step             number;
7872   lr_sequence_number        number;
7873   lm_rate_or_payscale_name  varchar2(30);
7874   lm_salary_type            varchar2(10);
7875   lm_grade_name             varchar2(240);
7876   lm_grade_step             number;
7877   lm_sequence_number        number;
7878   l_restart_salary_id       number := 0;
7879   l_api_name            CONSTANT VARCHAR2(30)   := 'Populate_Element';
7880   l_api_version         CONSTANT NUMBER         := 1.0;
7881 
7882   Cursor C_Elements IS
7883     Select salary_type, rate_or_payscale_id,
7884 	   rate_or_payscale_name, grade_id,
7885 	   grade_name, grade_step, sequence_number,
7886 	   minimum_value, maximum_value,
7887 	   mid_value, element_value,pay_basIS,
7888 	   element_type_id,
7889 	   effective_start_DATE, effective_END_DATE
7890       FROM psb_salary_i
7891      WHERE data_extract_id   = p_data_extract_id
7892        AND rate_or_payscale_id > l_restart_salary_id
7893      ORDER BY rate_or_payscale_id, salary_type;
7894 
7895   Cursor C_Refresh IS
7896      Select rowid,pay_element_id, budget_set_id,period_type
7897        FROM psb_pay_elements
7898       WHERE data_extract_id   = p_data_extract_id
7899 	AND name              = lr_rate_or_payscale_name
7900 	AND salary_type       = lr_salary_type;
7901 
7902   Cursor C_currency IS
7903      Select currency_code
7904        FROM gl_sets_of_books
7905       WHERE set_of_books_id = p_set_of_books_id;
7906 
7907     l_rowid varchar2(100);
7908     l_orowid varchar2(100);
7909     l_rrowid varchar2(100);
7910     l_return_status     varchar2(1);
7911     l_pay_element_option_id number;
7912     l_pay_element_rate_id   number;
7913     l_pay_element_id  number;
7914     l_msg_count number;
7915     l_msg_data  varchar2(2000);
7916     prev_rate_or_payscale_id number := -1;
7917     prev_salary_type varchar2(10) := 'X';
7918     l_currency_code varchar2(30);
7919     l_salary_ctr number := 0;
7920 
7921   Cursor C_Ref_Option IS
7922      Select rowid, pay_element_option_id
7923        FROM PSB_PAY_ELEMENT_OPTIONS
7924       WHERE pay_element_id = l_pay_element_id
7925 	AND name = lr_grade_name
7926 	AND grade_step = lr_grade_step
7927 	AND sequence_number = lr_sequence_number;
7928 
7929   Cursor C_Ref_Rate_Option IS
7930      Select rowid, pay_element_option_id
7931        FROM PSB_PAY_ELEMENT_OPTIONS
7932       WHERE pay_element_id = l_pay_element_id
7933 	AND name = lr_grade_name;
7934 Begin
7935 
7936     Savepoint Populate_Element;
7937     l_last_update_date := sysDATE;
7938     l_last_upDATEd_BY := FND_GLOBAL.USER_ID;
7939     l_last_upDATE_login :=FND_GLOBAL.LOGIN_ID;
7940     l_creation_DATE     := sysDATE;
7941     l_created_BY        := FND_GLOBAL.USER_ID;
7942 
7943 
7944     IF NOT FND_API.Compatible_API_Call (l_api_version,
7945 					p_api_version,
7946 					l_api_name,
7947 					G_PKG_NAME)
7948     THEN
7949        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7950     END IF;
7951 
7952 
7953     -- Initialize message lISt IF p_init_msg_lISt IS set to TRUE.
7954 
7955     IF FND_API.to_Boolean (p_init_msg_lISt) THEN
7956        FND_MSG_PUB.initialize;
7957     END IF;
7958 
7959     -- Initialize API return status to success
7960     p_return_status := FND_API.G_RET_STS_SUCCESS;
7961 
7962     -- API body
7963 
7964 
7965     PSB_HR_EXTRACT_DATA_PVT.Check_Reentry
7966     (p_api_version              => 1.0  ,
7967      p_return_status            => l_return_status,
7968      p_msg_count                => l_msg_count,
7969      p_msg_data                 => l_msg_data,
7970      p_data_extract_id          => p_data_extract_id,
7971      p_process                  => 'PSB Elements',
7972      p_status                   => l_status,
7973      p_restart_id               => l_restart_salary_id
7974     );
7975 
7976     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7977        RAISE FND_API.G_EXC_ERROR;
7978     END IF;
7979 
7980     IF (l_status = 'I') THEN
7981        FOR C_currency_rec in C_currency
7982        LOOP
7983 	 l_currency_code := C_currency_rec.currency_code;
7984        END LOOP;
7985 
7986        FOR C_Element_Rec in C_Elements
7987        LOOP
7988 	  lm_rate_or_payscale_name := NULL;
7989 	  lm_salary_type           := NULL;
7990 	  lm_grade_name            := NULL;
7991 	  lm_grade_step            := NULL;
7992 	  lm_sequence_number       := NULL;
7993 
7994 	  lm_rate_or_payscale_name := C_Element_Rec.rate_or_payscale_name;
7995 	  lm_salary_type           := C_Element_Rec.salary_type;
7996 	  lm_grade_name            := C_Element_Rec.grade_name;
7997 	  lm_grade_step            := C_Element_Rec.grade_step;
7998 	  lm_sequence_number       := C_Element_Rec.sequence_number;
7999 
8000 	if ((C_Element_Rec.rate_or_payscale_id <> prev_rate_or_payscale_id) and
8001 	   (prev_rate_or_payscale_id <> -1)) then
8002 	   l_salary_ctr  := l_salary_ctr + 1;
8003 	   if l_salary_ctr = PSB_WS_ACCT1.g_checkpoint_save then
8004 	      PSB_HR_EXTRACT_DATA_PVT.Update_Reentry
8005 	      ( p_api_version              => 1.0  ,
8006 		p_return_status            => l_return_status,
8007 		p_msg_count                => l_msg_count,
8008 		p_msg_data                 => l_msg_data,
8009 		p_data_extract_id          => p_data_extract_id,
8010 		p_extract_method           => p_extract_method,
8011 		p_process                  => 'PSB Elements',
8012 		p_restart_id               => prev_rate_or_payscale_id
8013 	      );
8014 
8015 	     if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8016 		raise FND_API.G_EXC_ERROR;
8017 	     end if;
8018 	     commit work;
8019 	     l_salary_ctr := 0;
8020 	     Savepoint Populate_Element;
8021 	   end if;
8022        end if;
8023 
8024        IF (p_extract_method = 'REFRESH') THEN
8025 	  lr_rate_or_payscale_name :=  C_Element_Rec.rate_or_payscale_name;
8026 	  lr_salary_type := C_Element_Rec.salary_type;
8027 	  l_dummy := 0;
8028 	  FOR C_Refresh_Rec in C_Refresh
8029 	  LOOP
8030 	  l_dummy := 1;
8031 	  IF ((C_Element_Rec.rate_or_payscale_id <> prev_rate_or_payscale_id)
8032 	      or (C_Element_Rec.salary_type <> prev_salary_type)
8033 	      or (prev_salary_type = 'X')
8034 	      or (prev_rate_or_payscale_id = -1)) THEN
8035 	  PSB_PAY_ELEMENTS_PVT.UPDATE_ROW
8036 	  ( p_api_version             =>  1.0,
8037 	    p_init_msg_lISt           => NULL,
8038 	    p_commit                  => NULL,
8039 	    p_validation_level        => NULL,
8040 	    p_return_status           => l_return_status,
8041 	    p_msg_count               => l_msg_count,
8042 	    p_msg_data                => l_msg_data,
8043 	    p_row_id                  => C_Refresh_Rec.rowid,
8044 	    p_pay_element_id          => C_Refresh_Rec.pay_element_id,
8045 	    p_budget_set_id           => C_Refresh_Rec.budget_set_id,
8046 	    p_business_group_id       => p_business_group_id,
8047 	    p_data_extract_id         => p_data_extract_id,
8048 	    p_name                    => lr_rate_or_payscale_name,
8049 	    p_description             => NULL,
8050 	    p_element_value_type      => 'A',
8051 	    p_FORmula_id              => NULL,
8052 	    p_overwrite_flag          => NULL,
8053 	    p_required_flag           => NULL,
8054 	    p_follow_salary           => NULL,
8055 	    p_pay_basIS               => C_Element_Rec.pay_basIS,
8056 	    p_start_DATE              => C_Element_Rec.effective_start_DATE,
8057 	    p_END_DATE                => C_Element_Rec.effective_END_DATE,
8058 	    p_processing_type         => 'R',
8059     	/*
8060 	   Pass the existing period_type istead of NULL to resolve the issue in Bug No: 2852998
8061 	   We should not set/override the period_type to NULL in case of REFRESH mode,
8062       since the period_type    doesn't come from HR
8063 	   */
8064 	    p_period_type             => C_Refresh_Rec.period_type,
8065 	    p_process_period_type     => NULL,
8066 	    p_max_element_value_type  => NULL,
8067 	    p_max_element_value       => NULL,
8068 	    p_salary_flag             => 'Y',
8069 	    p_salary_type             => C_Element_Rec.salary_type,
8070 	    p_option_flag             => 'Y',
8071 	    p_hr_element_type_id      => C_Element_Rec.element_type_id,
8072 	    p_attribute_category      => NULL,
8073 	    p_attribute1              => NULL,
8074 	    p_attribute2              => NULL,
8075 	    p_attribute3              => NULL,
8076 	    p_attribute4              => NULL,
8077 	    p_attribute5              => NULL,
8078 	    p_attribute6              => NULL,
8079 	    p_attribute7              => NULL,
8080 	    p_attribute8              => NULL,
8081 	    p_attribute9              => NULL,
8082 	    p_attribute10             => NULL,
8083 	    p_last_upDATE_DATE        => l_last_update_date,
8084 	    p_last_upDATEd_BY         => l_last_upDATEd_BY,
8085 	    p_last_upDATE_login       => l_last_upDATE_login
8086 	  );
8087 
8088 	   IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8089 	     RAISE FND_API.G_EXC_ERROR;
8090 	   END IF;
8091 	 END IF;
8092 
8093 	 lr_grade_name := C_Element_Rec.grade_name;
8094 	 lr_grade_step := C_Element_Rec.grade_step;
8095 	 lr_sequence_number := C_Element_Rec.sequence_number;
8096 	 l_pay_element_id := C_Refresh_Rec.pay_element_id;
8097 
8098 	 l_option_dummy := 0;
8099 
8100 	 IF (C_Element_Rec.salary_type = 'STEP') THEN
8101 	 FOR C_Ref_Option_Rec in C_Ref_Option
8102 	 LOOP
8103 	  l_option_dummy := 1;
8104 	  l_pay_element_option_id := C_Ref_Option_Rec.pay_element_option_id;
8105 	  PSB_PAY_ELEMENT_OPTIONS_PVT.UPDATE_ROW
8106 	  ( p_api_version             =>  1.0,
8107 	    p_init_msg_lISt           => NULL,
8108 	    p_commit                  => NULL,
8109 	    p_validation_level        => NULL,
8110 	    p_return_status           => l_return_status,
8111 	    p_msg_count               => l_msg_count,
8112 	    p_msg_data                => l_msg_data,
8113 	    p_pay_element_option_id   => C_Ref_Option_Rec.pay_element_option_id,
8114 	    p_pay_element_id          => C_Refresh_Rec.pay_element_id,
8115 	    p_name                    => C_Element_Rec.grade_name,
8116 	    p_grade_step              => C_Element_Rec.grade_step,
8117 	    p_sequence_number         => C_Element_Rec.sequence_number,
8118 	    p_last_upDATE_DATE        => l_last_update_date,
8119 	    p_last_upDATEd_BY         => l_last_upDATEd_BY,
8120 	    p_last_upDATE_login       => l_last_upDATE_login
8121 	 );
8122 
8123 	   IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8124 	     RAISE FND_API.G_EXC_ERROR;
8125 	   END IF;
8126 	  END LOOP;
8127 	 END IF;
8128 
8129 	 IF (C_Element_Rec.salary_type = 'RATE') THEN
8130 	 FOR C_Ref_Rate_Rec in C_Ref_Rate_Option
8131 	 LOOP
8132 	  l_option_dummy := 1;
8133 	  l_pay_element_option_id := C_Ref_Rate_Rec.pay_element_option_id;
8134 	  PSB_PAY_ELEMENT_OPTIONS_PVT.UPDATE_ROW
8135 	  ( p_api_version             =>  1.0,
8136 	    p_init_msg_lISt           => NULL,
8137 	    p_commit                  => NULL,
8138 	    p_validation_level        => NULL,
8139 	    p_return_status           => l_return_status,
8140 	    p_msg_count               => l_msg_count,
8141 	    p_msg_data                => l_msg_data,
8142 	    p_pay_element_option_id   => C_Ref_Rate_Rec.pay_element_option_id,
8143 	    p_pay_element_id          => C_Refresh_Rec.pay_element_id,
8144 	    p_name                    => C_Element_Rec.grade_name,
8145 	    p_grade_step              => C_Element_Rec.grade_step,
8146 	    p_sequence_number         => C_Element_Rec.sequence_number,
8147 	    p_last_upDATE_DATE        => l_last_update_date,
8148 	    p_last_upDATEd_BY         => l_last_upDATEd_BY,
8149 	    p_last_upDATE_login       => l_last_upDATE_login
8150 	 );
8151 
8152 	   IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8153 	     RAISE FND_API.G_EXC_ERROR;
8154 	   END IF;
8155 	  END LOOP;
8156 	 END IF;
8157 
8158 	IF (l_option_dummy = 0) THEN
8159 	   Select psb_pay_element_options_s.nextval
8160 	     INTO l_pay_element_option_id
8161 	     FROM dual;
8162 
8163 	  PSB_PAY_ELEMENT_OPTIONS_PVT.INSERT_ROW
8164 	  ( p_api_version             =>  1.0,
8165 	    p_init_msg_lISt           => NULL,
8166 	    p_commit                  => NULL,
8167 	    p_validation_level        => NULL,
8168 	    p_return_status           => l_return_status,
8169 	    p_msg_count               => l_msg_count,
8170 	    p_msg_data                => l_msg_data,
8171 	    p_pay_element_option_id   => l_pay_element_option_id,
8172 	    p_pay_element_id          => l_pay_element_id,
8173 	    p_name                    => C_Element_Rec.grade_name,
8174 	    p_grade_step              => C_Element_Rec.grade_step,
8175 	    p_sequence_number         => C_Element_Rec.sequence_number,
8176 	    p_last_upDATE_DATE        => l_last_update_date,
8177 	    p_last_upDATEd_BY         => l_last_upDATEd_BY,
8178 	    p_last_upDATE_login       => l_last_upDATE_login,
8179 	    p_created_BY              => l_created_BY,
8180 	    p_creation_DATE           => l_creation_DATE
8181 	   );
8182 
8183 	  END IF;
8184 
8185 	   PSB_PAY_ELEMENT_RATES_PVT.ModIFy_Element_Rates
8186 	  ( p_api_version             =>  1.0,
8187 	    p_init_msg_lISt           => NULL,
8188 	    p_commit                  => NULL,
8189 	    p_validation_level        => NULL,
8190 	    p_return_status           => l_return_status,
8191 	    p_msg_count               => l_msg_count,
8192 	    p_msg_data                => l_msg_data,
8193 	    p_pay_element_id          => l_pay_element_id,
8194 	    p_pay_element_option_id   => l_pay_element_option_id,
8195 	    p_effective_start_DATE    => C_Element_Rec.effective_start_DATE,
8196 	    p_effective_END_DATE      => NULL,
8197 	    p_worksheet_id            => NULL,
8198 	    p_element_value_type      => 'A',
8199 	    p_element_value           => C_Element_Rec.element_value,
8200 	    p_pay_basIS               => C_Element_Rec.pay_basIS,
8201 	    p_FORmula_id              => NULL,
8202 	    p_maximum_value           => C_Element_Rec.maximum_value,
8203 	    p_mid_value               => C_Element_Rec.mid_value,
8204 	    p_minimum_value           => C_Element_Rec.minimum_value,
8205 	    p_currency_code           => l_currency_code
8206 	  );
8207 
8208 	   IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8209 	     RAISE FND_API.G_EXC_ERROR;
8210 	   END IF;
8211 	END LOOP;
8212        END IF;
8213 
8214 	IF ((p_extract_method = 'CREATE') or (l_dummy = 0)) THEN
8215 	  IF ((C_Element_Rec.rate_or_payscale_id <> prev_rate_or_payscale_id)
8216 	      or (C_Element_Rec.salary_type <> prev_salary_type)
8217 	      or (prev_salary_type = 'X')
8218 	      or (prev_rate_or_payscale_id = -1)) THEN
8219 
8220 	   Select psb_pay_elements_s.nextval
8221 	     INTO l_pay_element_id
8222 	     FROM dual;
8223 
8224 	  PSB_PAY_ELEMENTS_PVT.INSERT_ROW
8225 	  ( p_api_version             =>  1.0,
8226 	    p_init_msg_lISt           => NULL,
8227 	    p_commit                  => NULL,
8228 	    p_validation_level        => NULL,
8229 	    p_return_status           => l_return_status,
8230 	    p_msg_count               => l_msg_count,
8231 	    p_msg_data                => l_msg_data,
8232 	    p_row_id                  => l_rowid,
8233 	    p_pay_element_id          => l_pay_element_id,
8234 	    p_business_group_id       => p_business_group_id,
8235 	    p_data_extract_id         => p_data_extract_id,
8236 	    p_name                    => C_Element_Rec.rate_or_payscale_name,
8237 	    p_description             => NULL,
8238 	    p_element_value_type      => 'A',
8239 	    p_FORmula_id              => NULL,
8240 	    p_overwrite_flag          => NULL,
8241 	    p_required_flag           => NULL,
8242 	    p_follow_salary           => NULL,
8243 	    p_pay_basIS               => C_Element_Rec.pay_basIS,
8244 	    p_start_DATE              => C_Element_Rec.effective_start_DATE,
8245 	    p_END_DATE                => C_Element_Rec.effective_END_DATE,
8246 	    p_processing_type         => 'R',
8247 	    p_period_type             => NULL,
8248 	    p_process_period_type     => NULL,
8249 	    p_max_element_value_type  => NULL,
8250 	    p_max_element_value       => NULL,
8251 	    p_salary_flag             => 'Y',
8252 	    p_salary_type             => C_Element_Rec.salary_type,
8253 	    p_option_flag             => 'Y',
8254 	    p_hr_element_type_id      => C_Element_Rec.element_type_id,
8255 	    p_attribute_category      => NULL,
8256 	    p_attribute1              => NULL,
8257 	    p_attribute2              => NULL,
8258 	    p_attribute3              => NULL,
8259 	    p_attribute4              => NULL,
8260 	    p_attribute5              => NULL,
8261 	    p_attribute6              => NULL,
8262 	    p_attribute7              => NULL,
8263 	    p_attribute8              => NULL,
8264 	    p_attribute9              => NULL,
8265 	    p_attribute10             => NULL,
8266 	    p_last_upDATE_DATE        => l_last_update_date,
8267 	    p_last_upDATEd_BY         => l_last_upDATEd_BY,
8268 	    p_last_upDATE_login       => l_last_upDATE_login,
8269 	    p_created_BY              => l_created_BY,
8270 	    p_creation_DATE           => l_creation_DATE
8271 	  );
8272 
8273 	   IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8274 	     RAISE FND_API.G_EXC_ERROR;
8275 	   END IF;
8276 	  END IF;
8277 
8278 	   Select psb_pay_element_options_s.nextval
8279 	     INTO l_pay_element_option_id
8280 	     FROM dual;
8281 
8282 	  PSB_PAY_ELEMENT_OPTIONS_PVT.INSERT_ROW
8283 	  ( p_api_version             =>  1.0,
8284 	    p_init_msg_lISt           => NULL,
8285 	    p_commit                  => NULL,
8286 	    p_validation_level        => NULL,
8287 	    p_return_status           => l_return_status,
8288 	    p_msg_count               => l_msg_count,
8289 	    p_msg_data                => l_msg_data,
8290 	    p_pay_element_option_id   => l_pay_element_option_id,
8291 	    p_pay_element_id          => l_pay_element_id,
8292 	    p_name                    => C_Element_Rec.grade_name,
8293 	    p_grade_step              => C_Element_Rec.grade_step,
8294 	    p_sequence_number         => C_Element_Rec.sequence_number,
8295 	    p_last_upDATE_DATE        => l_last_update_date,
8296 	    p_last_upDATEd_BY         => l_last_upDATEd_BY,
8297 	    p_last_upDATE_login       => l_last_upDATE_login,
8298 	    p_created_BY              => l_created_BY,
8299 	    p_creation_DATE           => l_creation_DATE
8300 	 );
8301 
8302 	   IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8303 	     RAISE FND_API.G_EXC_ERROR;
8304 	   END IF;
8305 
8306 
8307 	   Select psb_pay_element_rates_s.nextval
8308 	     INTO l_pay_element_rate_id
8309 	     FROM dual;
8310 
8311 	  PSB_PAY_ELEMENT_RATES_PVT.INSERT_ROW
8312 	  ( p_api_version             =>  1.0,
8313 	    p_init_msg_lISt           => NULL,
8314 	    p_commit                  => NULL,
8315 	    p_validation_level        => NULL,
8316 	    p_return_status           => l_return_status,
8317 	    p_msg_count               => l_msg_count,
8318 	    p_msg_data                => l_msg_data,
8319 	    p_pay_element_rate_id     => l_pay_element_rate_id,
8320 	    p_pay_element_option_id   => l_pay_element_option_id,
8321 	    p_pay_element_id          => l_pay_element_id,
8322 	    p_effective_start_DATE    => C_Element_Rec.effective_start_DATE,
8323 	    p_effective_END_DATE      => C_Element_Rec.effective_END_DATE,
8324 	    p_worksheet_id            => NULL,
8325 	    p_element_value_type      => 'A',
8326 	    p_element_value           => C_Element_Rec.element_value,
8327 	    p_pay_basIS               => C_Element_Rec.pay_basIS,
8328 	    p_FORmula_id              => NULL,
8329 	    p_maximum_value           => C_Element_Rec.maximum_value,
8330 	    p_mid_value               => C_Element_Rec.mid_value,
8331 	    p_minimum_value           => C_Element_Rec.minimum_value,
8332 	    p_currency_code           => l_currency_code,
8333 	    p_last_upDATE_DATE        => l_last_update_date,
8334 	    p_last_upDATEd_BY         => l_last_upDATEd_BY,
8335 	    p_last_upDATE_login       => l_last_upDATE_login,
8336 	    p_created_BY              => l_created_BY,
8337 	    p_creation_DATE           => l_creation_DATE
8338 	   ) ;
8339 
8340 	   IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8341 	     RAISE FND_API.G_EXC_ERROR;
8342 	   END IF;
8343        END IF;
8344 
8345      prev_rate_or_payscale_id := C_Element_Rec.rate_or_payscale_id;
8346      prev_salary_type := C_Element_Rec.salary_type;
8347      END LOOP;
8348 
8349      PSB_HR_EXTRACT_DATA_PVT.Update_Reentry
8350      ( p_api_version              => 1.0  ,
8351        p_return_status            => l_return_status,
8352        p_msg_count                => l_msg_count,
8353        p_msg_data                 => l_msg_data,
8354        p_data_extract_id          => p_data_extract_id,
8355        p_extract_method           => p_extract_method,
8356        p_process                  => 'PSB Elements',
8357        p_restart_id               => prev_rate_or_payscale_id
8358      );
8359 
8360     if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8361        raise FND_API.G_EXC_ERROR;
8362     end if;
8363 
8364     PSB_HR_EXTRACT_DATA_PVT.Reentrant_Process
8365     ( p_api_version              => 1.0  ,
8366       p_return_status            => l_return_status,
8367       p_msg_count                => l_msg_count,
8368       p_msg_data                 => l_msg_data,
8369       p_data_extract_id          => p_data_extract_id,
8370       p_extract_method           => p_extract_method,
8371       p_process                  => 'PSB Elements'
8372     );
8373 
8374     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8375        RAISE FND_API.G_EXC_ERROR;
8376     END IF;
8377 
8378    commit work;
8379    END IF;
8380     -- END of API body.
8381 
8382   EXCEPTION
8383 
8384    WHEN FND_API.G_EXC_ERROR THEN
8385      ROLLBACK to Populate_Element;
8386      p_return_status := FND_API.G_RET_STS_ERROR;
8387      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
8388 				 p_data  => p_msg_data);
8389      FND_MESSAGE.SET_NAME('PSB', 'PSB_SALARY_DETAILS');
8390      FND_MESSAGE.SET_TOKEN('SALARY_TYPE',lm_salary_type );
8391      FND_MESSAGE.SET_TOKEN('RATE_OR_PAYSCALE_NAME',lm_rate_or_payscale_name );
8392      FND_MESSAGE.SET_TOKEN('GRADE_NAME',lm_grade_name );
8393      FND_MESSAGE.SET_TOKEN('GRADE_STEP',lm_grade_step );
8394      FND_MESSAGE.SET_TOKEN('GRADE_SEQUENCE',lm_sequence_number);
8395      FND_MSG_PUB.Add;
8396 
8397    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8398      ROLLBACK to Populate_Element;
8399      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8400      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
8401 				 p_data  => p_msg_data);
8402      FND_MESSAGE.SET_NAME('PSB', 'PSB_SALARY_DETAILS');
8403      FND_MESSAGE.SET_TOKEN('SALARY_TYPE',lm_salary_type );
8404      FND_MESSAGE.SET_TOKEN('RATE_OR_PAYSCALE_NAME',lm_rate_or_payscale_name );
8405      FND_MESSAGE.SET_TOKEN('GRADE_NAME',lm_grade_name );
8406      FND_MESSAGE.SET_TOKEN('GRADE_STEP',lm_grade_step );
8407      FND_MESSAGE.SET_TOKEN('GRADE_SEQUENCE',lm_sequence_number);
8408      FND_MSG_PUB.Add;
8409 
8410    WHEN OTHERS THEN
8411      ROLLBACK to Populate_Element;
8412      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8413      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
8414 				 p_data  => p_msg_data);
8415 
8416      FND_MESSAGE.SET_NAME('PSB', 'PSB_SALARY_DETAILS');
8417      FND_MESSAGE.SET_TOKEN('SALARY_TYPE',lm_salary_type );
8418      FND_MESSAGE.SET_TOKEN('RATE_OR_PAYSCALE_NAME',lm_rate_or_payscale_name );
8419      FND_MESSAGE.SET_TOKEN('GRADE_NAME',lm_grade_name );
8420      FND_MESSAGE.SET_TOKEN('GRADE_STEP',lm_grade_step );
8421      FND_MESSAGE.SET_TOKEN('GRADE_SEQUENCE',lm_sequence_number);
8422      FND_MSG_PUB.Add;
8423 
8424      IF FND_MSG_PUB.Check_Msg_Level
8425        (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
8426      THEN
8427        FND_MSG_PUB.Add_Exc_Msg
8428 	  (p_pkg_name => G_PKG_NAME,
8429 	   p_procedure_name => l_api_name);
8430     END IF;
8431 
8432 END Populate_Element_Information;
8433 
8434 /* ----------------------------------------------------------------------- */
8435 
8436 FUNCTION check_vacancy(p_position_id in NUMBER,
8437 		       p_data_extract_id in NUMBER)
8438 	 RETURN VARCHAR2 AS
8439 
8440  lcount number := 0;
8441  vacancy_flag  varchar2(1) := 'N';
8442 
8443 BEGIN
8444   Select count(*) INTO lcount
8445     FROM psb_employees_i
8446    WHERE hr_position_id = p_position_id
8447      AND data_extract_id = p_data_extract_id;
8448 
8449  IF (lcount >= 1) THEN
8450     vacancy_flag := 'N';
8451  else
8452     vacancy_flag := 'Y';
8453  END IF;
8454 
8455  return  vacancy_flag;
8456 
8457 END;
8458 
8459 /* ----------------------------------------------------------------------- */
8460 
8461 PROCEDURE Populate_Attribute_Values
8462 ( p_api_version         IN      NUMBER,
8463   p_init_msg_lISt       IN      VARCHAR2 := FND_API.G_FALSE,
8464   p_commit              IN      VARCHAR2 := FND_API.G_FALSE,
8465   p_validation_level    IN      NUMBER   := FND_API.G_VALID_LEVEL_FULL,
8466   p_return_status       OUT  NOCOPY     VARCHAR2,
8467   p_msg_count           OUT  NOCOPY     NUMBER,
8468   p_msg_data            OUT  NOCOPY     VARCHAR2,
8469   p_data_extract_id     IN      NUMBER,
8470   p_extract_method      IN      VARCHAR2,
8471   p_business_group_id   IN      NUMBER
8472 ) AS
8473 
8474   l_last_update_date    DATE;
8475   l_last_upDATEd_BY     number;
8476   l_last_upDATE_login   number;
8477   l_creation_DATE       DATE;
8478   l_created_BY          number;
8479   l_dummy               number;
8480   l_rowid               varchar2(100);
8481   l_return_status       varchar2(1);
8482   l_msg_count           number;
8483   l_msg_data            varchar2(2000);
8484   l_status              varchar2(1);
8485   lr_attribute_id       number;
8486   --UTF8 changes for Bug No : 2615261
8487   lr_attribute_value    psb_attribute_values.attribute_value%TYPE;
8488   l_attr_dummy          number := 1;
8489   l_attribute_name      varchar2(30);
8490   --UTF8 changes for Bug No : 2615261
8491   l_attribute_value     psb_attribute_values.attribute_value%TYPE;
8492   l_attribute_value_id  NUMBER;
8493   l_restart_attribute_value_id number := 0;
8494   l_fin_attribute_value_id number := 0;
8495   l_attr_val_ctr         number := 0;
8496 
8497   l_api_name            CONSTANT VARCHAR2(30)   := 'Populate_Attribute_Values';
8498   l_api_version         CONSTANT NUMBER         := 1.0;
8499 
8500   Cursor C_Attrval IS
8501     Select b.attribute_value_id,b.attribute_id,
8502 	   a.name, b.attribute_value,b.description,b.value_id
8503       FROM psb_attribute_values_i b, psb_attributes_vl a
8504      WHERE data_extract_id = p_data_extract_id
8505        AND b.attribute_id  = a.attribute_id
8506        AND b.attribute_value_id > l_restart_attribute_value_id
8507      order by b.attribute_value_id;
8508 
8509   Cursor C_ref_attr IS
8510     Select attribute_value_id
8511       FROM psb_attribute_values
8512      WHERE attribute_id = lr_attribute_id
8513        AND attribute_value = lr_attribute_value
8514        AND data_extract_id = p_data_extract_id;
8515 
8516 BEGIN
8517 
8518     Savepoint Populate_Attributes;
8519 
8520     l_last_update_date := sysDATE;
8521     l_last_upDATEd_BY := FND_GLOBAL.USER_ID;
8522     l_last_upDATE_login :=FND_GLOBAL.LOGIN_ID;
8523     l_creation_DATE     := sysDATE;
8524     l_created_BY        := FND_GLOBAL.USER_ID;
8525 
8526 
8527     IF NOT FND_API.Compatible_API_Call (l_api_version,
8528 					p_api_version,
8529 					l_api_name,
8530 					G_PKG_NAME)
8531     THEN
8532        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8533     END IF;
8534 
8535     -- Initialize message lISt IF p_init_msg_lISt IS set to TRUE.
8536 
8537     IF FND_API.to_Boolean (p_init_msg_lISt) THEN
8538        FND_MSG_PUB.initialize;
8539     END IF;
8540 
8541     -- Initialize API return status to success
8542 
8543     p_return_status := FND_API.G_RET_STS_SUCCESS;
8544 
8545     -- API body
8546     PSB_HR_EXTRACT_DATA_PVT.Check_Reentry
8547     (p_api_version              => 1.0  ,
8548      p_return_status            => l_return_status,
8549      p_msg_count                => l_msg_count,
8550      p_msg_data                 => l_msg_data,
8551      p_data_extract_id          => p_data_extract_id,
8552      p_process                  => 'PSB Attribute Values',
8553      p_status                   => l_status,
8554      p_restart_id               => l_restart_attribute_value_id
8555     );
8556 
8557     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8558        RAISE FND_API.G_EXC_ERROR;
8559     END IF;
8560 
8561     IF (l_status = 'I') THEN
8562 
8563     FOR C_Attribute_Rec in C_Attrval
8564     LOOP
8565       l_attribute_name     := NULL;
8566       l_attribute_value    := NULL;
8567       l_attribute_name     := C_Attribute_Rec.name;
8568       l_attribute_value    := C_Attribute_Rec.attribute_value;
8569       l_fin_attribute_value_id := C_Attribute_Rec.attribute_value_id;
8570       l_attr_val_ctr       := l_attr_val_ctr + 1;
8571 
8572       IF (p_extract_method = 'REFRESH') THEN
8573 	 l_attr_dummy       := 0;
8574 	 lr_attribute_id    := C_Attribute_Rec.attribute_id;
8575 	 lr_attribute_value := C_Attribute_Rec.attribute_value;
8576 
8577 	 FOR C_ref_attr_rec in C_ref_attr
8578 	 LOOP
8579 	  l_attr_dummy := 1;
8580 	  PSB_ATTRIBUTE_VALUES_PVT.UPDATE_ROW
8581 	  ( p_api_version             =>  1.0,
8582 	    p_init_msg_lISt           => NULL,
8583 	    p_commit                  => NULL,
8584 	    p_validation_level        => NULL,
8585 	    p_return_status           => l_return_status,
8586 	    p_msg_count               => l_msg_count,
8587 	    p_msg_data                => l_msg_data,
8588 	    p_attribute_value_id      => C_ref_attr_rec.attribute_value_id,
8589 	    p_attribute_id            => C_Attribute_Rec.attribute_id,
8590 	    p_attribute_value         => C_Attribute_Rec.attribute_value,
8591 	    p_hr_value_id             => C_Attribute_Rec.value_id,
8592 	    p_description             => C_Attribute_Rec.description,
8593 	    p_data_extract_id         => p_data_extract_id,
8594 	    p_context                 => NULL,
8595 	    p_attribute1              => NULL,
8596 	    p_attribute2              => NULL,
8597 	    p_attribute3              => NULL,
8598 	    p_attribute4              => NULL,
8599 	    p_attribute5              => NULL,
8600 	    p_attribute6              => NULL,
8601 	    p_attribute7              => NULL,
8602 	    p_attribute8              => NULL,
8603 	    p_attribute9              => NULL,
8604 	    p_attribute10             => NULL,
8605 	    p_attribute11             => NULL,
8606 	    p_attribute12             => NULL,
8607 	    p_attribute13             => NULL,
8608 	    p_attribute14             => NULL,
8609 	    p_attribute15             => NULL,
8610 	    p_attribute16             => NULL,
8611 	    p_attribute17             => NULL,
8612 	    p_attribute18             => NULL,
8613 	    p_attribute19             => NULL,
8614 	    p_attribute20             => NULL,
8615 	    p_attribute21             => NULL,
8616 	    p_attribute22             => NULL,
8617 	    p_attribute23             => NULL,
8618 	    p_attribute24             => NULL,
8619 	    p_attribute25             => NULL,
8620 	    p_attribute26             => NULL,
8621 	    p_attribute27             => NULL,
8622 	    p_attribute28             => NULL,
8623 	    p_attribute29             => NULL,
8624 	    p_attribute30             => NULL,
8625 	    p_last_upDATE_DATE        => l_last_update_date,
8626 	    p_last_upDATEd_BY         => l_last_upDATEd_BY,
8627 	    p_last_upDATE_login       => l_last_upDATE_login
8628 	  );
8629 	 END LOOP;
8630       END IF;
8631 
8632       IF ((p_extract_method = 'CREATE') or (l_attr_dummy = 0)) THEN
8633 
8634 	 /* The following code(check for the attribute_value and update_row if
8635 	    it exists else use insert_row. Insert_row was already existing)
8636 	    has been added to fix the unique
8637 	    constraint violation error as mentioned in bug 1735018.
8638 	    Fixed by Siva Annamalai on 30 Apr 2001 */
8639 
8640 	 l_attribute_value_id := NULL;
8641 	 lr_attribute_id    := C_Attribute_Rec.attribute_id;
8642 	 lr_attribute_value := C_Attribute_Rec.attribute_value;
8643 
8644 	 FOR C_ref_attr_rec in C_ref_attr
8645 	 LOOP
8646 	    l_attribute_value_id := c_ref_attr_rec.attribute_value_id;
8647 	 END LOOP;
8648 
8649 	 IF l_attribute_value_id IS NOT NULL THEN
8650 	   PSB_ATTRIBUTE_VALUES_PVT.UPDATE_ROW
8651 	   ( p_api_version             =>  1.0,
8652 	    p_init_msg_lISt           => NULL,
8653 	    p_commit                  => NULL,
8654 	    p_validation_level        => NULL,
8655 	    p_return_status           => l_return_status,
8656 	    p_msg_count               => l_msg_count,
8657 	    p_msg_data                => l_msg_data,
8658 	    p_attribute_value_id      => l_attribute_value_id,
8659 	    p_attribute_id            => C_Attribute_Rec.attribute_id,
8660 	    p_attribute_value         => C_Attribute_Rec.attribute_value,
8661 	    p_hr_value_id             => C_Attribute_Rec.value_id,
8662 	    p_description             => C_Attribute_Rec.description,
8663 	    p_data_extract_id         => p_data_extract_id,
8664 	    p_context                 => NULL,
8665 	    p_attribute1              => NULL,
8666 	    p_attribute2              => NULL,
8667 	    p_attribute3              => NULL,
8668 	    p_attribute4              => NULL,
8669 	    p_attribute5              => NULL,
8670 	    p_attribute6              => NULL,
8671 	    p_attribute7              => NULL,
8672 	    p_attribute8              => NULL,
8673 	    p_attribute9              => NULL,
8674 	    p_attribute10             => NULL,
8675 	    p_attribute11             => NULL,
8676 	    p_attribute12             => NULL,
8677 	    p_attribute13             => NULL,
8678 	    p_attribute14             => NULL,
8679 	    p_attribute15             => NULL,
8680 	    p_attribute16             => NULL,
8681 	    p_attribute17             => NULL,
8682 	    p_attribute18             => NULL,
8683 	    p_attribute19             => NULL,
8684 	    p_attribute20             => NULL,
8685 	    p_attribute21             => NULL,
8686 	    p_attribute22             => NULL,
8687 	    p_attribute23             => NULL,
8688 	    p_attribute24             => NULL,
8689 	    p_attribute25             => NULL,
8690 	    p_attribute26             => NULL,
8691 	    p_attribute27             => NULL,
8692 	    p_attribute28             => NULL,
8693 	    p_attribute29             => NULL,
8694 	    p_attribute30             => NULL,
8695 	    p_last_upDATE_DATE        => l_last_update_date,
8696 	    p_last_upDATEd_BY         => l_last_upDATEd_BY,
8697 	    p_last_upDATE_login       => l_last_upDATE_login
8698 	  );
8699 
8700 	  ELSE
8701 
8702 	   PSB_ATTRIBUTE_VALUES_PVT.INSERT_ROW
8703 	   ( p_api_version             =>  1.0,
8704 	    p_init_msg_lISt           => NULL,
8705 	    p_commit                  => NULL,
8706 	    p_validation_level        => NULL,
8707 	    p_return_status           => l_return_status,
8708 	    p_msg_count               => l_msg_count,
8709 	    p_msg_data                => l_msg_data,
8710 	    p_rowid                   => l_rowid,
8711 	    p_attribute_value_id      => C_Attribute_Rec.attribute_value_id,
8712 	    p_attribute_id            => C_Attribute_Rec.attribute_id,
8713 	    p_attribute_value         => C_Attribute_Rec.attribute_value,
8714 	    p_hr_value_id             => C_Attribute_Rec.value_id,
8715 	    p_description             => C_Attribute_Rec.description,
8716 	    p_data_extract_id         => p_data_extract_id,
8717 	    p_context                 => NULL,
8718 	    p_attribute1              => NULL,
8719 	    p_attribute2              => NULL,
8720 	    p_attribute3              => NULL,
8721 	    p_attribute4              => NULL,
8722 	    p_attribute5              => NULL,
8723 	    p_attribute6              => NULL,
8724 	    p_attribute7              => NULL,
8725 	    p_attribute8              => NULL,
8726 	    p_attribute9              => NULL,
8727 	    p_attribute10             => NULL,
8728 	    p_attribute11             => NULL,
8729 	    p_attribute12             => NULL,
8730 	    p_attribute13             => NULL,
8731 	    p_attribute14             => NULL,
8732 	    p_attribute15             => NULL,
8733 	    p_attribute16             => NULL,
8734 	    p_attribute17             => NULL,
8735 	    p_attribute18             => NULL,
8736 	    p_attribute19             => NULL,
8737 	    p_attribute20             => NULL,
8738 	    p_attribute21             => NULL,
8739 	    p_attribute22             => NULL,
8740 	    p_attribute23             => NULL,
8741 	    p_attribute24             => NULL,
8742 	    p_attribute25             => NULL,
8743 	    p_attribute26             => NULL,
8744 	    p_attribute27             => NULL,
8745 	    p_attribute28             => NULL,
8746 	    p_attribute29             => NULL,
8747 	    p_attribute30             => NULL,
8748 	    p_last_upDATE_DATE        => l_last_update_date,
8749 	    p_last_upDATEd_BY         => l_last_upDATEd_BY,
8750 	    p_last_upDATE_login       => l_last_upDATE_login,
8751 	    p_created_BY              => l_created_BY,
8752 	    p_creation_DATE           => l_creation_DATE
8753 	   ) ;
8754 	END IF;
8755 
8756       END IF;
8757 
8758       if l_attr_val_ctr = PSB_WS_ACCT1.g_checkpoint_save then
8759       PSB_HR_EXTRACT_DATA_PVT.Update_Reentry
8760       ( p_api_version              => 1.0  ,
8761 	p_return_status            => l_return_status,
8762 	p_msg_count                => l_msg_count,
8763 	p_msg_data                 => l_msg_data,
8764 	p_data_extract_id          => p_data_extract_id,
8765 	p_extract_method           => p_extract_method,
8766 	p_process                  => 'PSB Attribute Values',
8767 	p_restart_id               => C_Attribute_Rec.attribute_value_id
8768       );
8769 
8770       if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8771 	 raise FND_API.G_EXC_ERROR;
8772       end if;
8773       commit work;
8774       Savepoint Populate_Attributes;
8775       l_attr_val_ctr := 0;
8776       end if;
8777 
8778     END LOOP;
8779 
8780     PSB_HR_EXTRACT_DATA_PVT.Update_Reentry
8781     ( p_api_version              => 1.0  ,
8782       p_return_status            => l_return_status,
8783       p_msg_count                => l_msg_count,
8784       p_msg_data                 => l_msg_data,
8785       p_data_extract_id          => p_data_extract_id,
8786       p_extract_method           => p_extract_method,
8787       p_process                  => 'PSB Attribute Values',
8788       p_restart_id               => l_fin_attribute_value_id
8789     );
8790 
8791     if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8792        raise FND_API.G_EXC_ERROR;
8793     end if;
8794 
8795     PSB_HR_EXTRACT_DATA_PVT.Reentrant_Process
8796     ( p_api_version              => 1.0  ,
8797       p_return_status            => l_return_status,
8798       p_msg_count                => l_msg_count,
8799       p_msg_data                 => l_msg_data,
8800       p_data_extract_id          => p_data_extract_id,
8801       p_extract_method           => p_extract_method,
8802       p_process                  => 'PSB Attribute Values'
8803     );
8804 
8805     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8806        RAISE FND_API.G_EXC_ERROR;
8807     END IF;
8808 
8809     commit work;
8810 
8811     END IF;
8812    -- END of API body.
8813 
8814   EXCEPTION
8815 
8816    WHEN FND_API.G_EXC_ERROR THEN
8817      ROLLBACK to Populate_Attributes;
8818      p_return_status := FND_API.G_RET_STS_ERROR;
8819      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
8820 				 p_data  => p_msg_data);
8821      FND_MESSAGE.SET_NAME('PSB','PSB_ATTRIBUTE_NAME');
8822      FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME',l_attribute_name);
8823      FND_MESSAGE.SET_TOKEN('ATTRIBUTE_VALUE',l_attribute_value);
8824      FND_MSG_PUB.Add;
8825 
8826    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8827      ROLLBACK to Populate_Attributes;
8828      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8829      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
8830 				 p_data  => p_msg_data);
8831      FND_MESSAGE.SET_NAME('PSB','PSB_ATTRIBUTE_NAME');
8832      FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME',l_attribute_name);
8833      FND_MESSAGE.SET_TOKEN('ATTRIBUTE_VALUE',l_attribute_value);
8834      FND_MSG_PUB.Add;
8835 
8836    WHEN OTHERS THEN
8837      ROLLBACK to Populate_Attributes;
8838      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8839      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
8840 				 p_data  => p_msg_data);
8841 
8842      FND_MESSAGE.SET_NAME('PSB','PSB_ATTRIBUTE_NAME');
8843      FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME',l_attribute_name);
8844      FND_MESSAGE.SET_TOKEN('ATTRIBUTE_VALUE',l_attribute_value);
8845      FND_MSG_PUB.Add;
8846 
8847      IF FND_MSG_PUB.Check_Msg_Level
8848        (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
8849      THEN
8850        FND_MSG_PUB.Add_Exc_Msg
8851 	  (p_pkg_name => G_PKG_NAME,
8852 	   p_procedure_name => l_api_name);
8853     END IF;
8854 
8855 END Populate_Attribute_Values;
8856 
8857 /* ----------------------------------------------------------------------- */
8858 
8859 PROCEDURE Populate_Costing_Information
8860 ( p_api_version         IN      NUMBER,
8861   p_init_msg_lISt       IN      VARCHAR2 := FND_API.G_FALSE,
8862   p_commit              IN      VARCHAR2 := FND_API.G_FALSE,
8863   p_validation_level    IN      NUMBER   := FND_API.G_VALID_LEVEL_FULL,
8864   p_return_status       OUT  NOCOPY     VARCHAR2,
8865   p_msg_count           OUT  NOCOPY     NUMBER,
8866   p_msg_data            OUT  NOCOPY     VARCHAR2,
8867   p_data_extract_id     IN      NUMBER,
8868   -- de by org
8869   p_extract_by_org      IN      VARCHAR2,
8870   p_extract_method      IN      VARCHAR2,
8871   p_business_group_id   IN      NUMBER
8872 ) AS
8873 
8874  l_return_status  varchar2(1);
8875  l_msg_count      number;
8876  l_msg_data       varchar2(1000);
8877  l_status         varchar2(1);
8878  l_restart_position_id number := 0;
8879  l_api_name       CONSTANT VARCHAR2(30) := 'Populate_Costing';
8880  l_api_version    CONSTANT NUMBER       := 1.0;
8881 
8882 Begin
8883 
8884   Savepoint Populate_Costing;
8885 
8886   IF NOT FND_API.Compatible_API_Call (l_api_version,
8887 				      p_api_version,
8888 				      l_api_name,
8889 				      G_PKG_NAME)
8890   THEN
8891     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8892   END IF;
8893 
8894   -- Initialize message lISt IF p_init_msg_lISt IS set to TRUE.
8895 
8896   IF FND_API.to_Boolean (p_init_msg_lISt) THEN
8897     FND_MSG_PUB.initialize;
8898   END IF;
8899 
8900   -- Initialize API return status to success
8901 
8902   p_return_status := FND_API.G_RET_STS_SUCCESS;
8903 
8904   -- API body
8905 
8906   PSB_HR_EXTRACT_DATA_PVT.Check_Reentry
8907   (  p_api_version              => 1.0  ,
8908      p_return_status            => l_return_status,
8909      p_msg_count                => l_msg_count,
8910      p_msg_data                 => l_msg_data,
8911      p_data_extract_id          => p_data_extract_id,
8912      p_process                  => 'PSB Costing',
8913      p_status                   => l_status,
8914      p_restart_id               => l_restart_position_id
8915   );
8916 
8917   IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8918     RAISE FND_API.G_EXC_ERROR;
8919   END IF;
8920 
8921   IF (l_status = 'I') THEN
8922     --
8923     Create_Salary_Distributions
8924     (
8925       p_return_status   => l_return_status,
8926       p_data_extract_id => p_data_extract_id,
8927       p_extract_method  => p_extract_method,
8928       p_restart_position_id => l_restart_position_id,
8929       -- de by org
8930       p_extract_by_org  => p_extract_by_org
8931     );
8932 
8933     IF (l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
8934       --
8935       PSB_HR_EXTRACT_DATA_PVT.Reentrant_Process
8936       ( p_api_version              => 1.0  ,
8937 	p_return_status            => l_return_status,
8938 	p_msg_count                => l_msg_count,
8939 	p_msg_data                 => l_msg_data,
8940 	p_data_extract_id          => p_data_extract_id,
8941 	p_extract_method           => p_extract_method,
8942 	p_process                  => 'PSB Costing'
8943       );
8944 
8945       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8946 	 RAISE FND_API.G_EXC_ERROR;
8947       END IF;
8948     else
8949       RAISE FND_API.G_EXC_ERROR;
8950     END IF;
8951     commit work;
8952   END IF;
8953 
8954   EXCEPTION
8955 
8956    WHEN FND_API.G_EXC_ERROR THEN
8957      ROLLBACK to Populate_Costing;
8958      p_return_status := FND_API.G_RET_STS_ERROR;
8959      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
8960 				 p_data  => p_msg_data);
8961 
8962    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8963      ROLLBACK to Populate_Costing;
8964      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8965      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
8966 				 p_data  => p_msg_data);
8967 
8968    WHEN OTHERS THEN
8969      ROLLBACK to Populate_Costing;
8970      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8971      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
8972 				 p_data  => p_msg_data);
8973 
8974      IF FND_MSG_PUB.Check_Msg_Level
8975        (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
8976      THEN
8977        FND_MSG_PUB.Add_Exc_Msg
8978 	  (p_pkg_name => G_PKG_NAME,
8979 	   p_procedure_name => l_api_name);
8980     END IF;
8981 
8982 END Populate_Costing_Information;
8983 
8984 /* ----------------------------------------------------------------------- */
8985 
8986 PROCEDURE Populate_Pos_Assignments
8987 ( p_api_version         IN      NUMBER,
8988   p_init_msg_lISt       IN      VARCHAR2 := FND_API.G_FALSE,
8989   p_commit              IN      VARCHAR2 := FND_API.G_FALSE,
8990   p_validation_level    IN      NUMBER   := FND_API.G_VALID_LEVEL_FULL,
8991   p_return_status       OUT  NOCOPY     VARCHAR2,
8992   p_msg_count           OUT  NOCOPY     NUMBER,
8993   p_msg_data            OUT  NOCOPY     VARCHAR2,
8994   p_data_extract_id     IN      NUMBER,
8995   -- de by org
8996   p_extract_by_org      IN      VARCHAR2,
8997   p_extract_method      IN      VARCHAR2,
8998   p_business_group_id   IN      NUMBER,
8999   p_set_of_books_id     IN      NUMBER
9000 ) AS
9001 
9002   l_last_update_date    DATE;
9003   l_last_upDATEd_BY     number;
9004   l_last_upDATE_login   number;
9005   l_creation_DATE       DATE;
9006   l_created_BY          number;
9007   l_dummy               number;
9008   l_rowid               varchar2(100);
9009   l_return_status       varchar2(1);
9010   l_msg_count           number;
9011   l_msg_data            varchar2(2000);
9012   l_position_assignment_id number;
9013   lp_attribute_name     varchar2(30);
9014   --UTF8 changes for Bug No : 2615261
9015   lp_attribute_value    psb_attribute_values.attribute_value%TYPE;
9016   lp_position_id        number;
9017   l_attribute_id        number;
9018   l_attribute_value_id  number;
9019   --UTF8 changes for Bug No : 2615261
9020   l_attribute_value     psb_attribute_values.attribute_value%TYPE;
9021   lr_attribute_id       number;
9022   lr_attribute_value_id number;
9023   --UTF8 changes for Bug No : 2615261
9024   lr_attribute_value    psb_attribute_values.attribute_value%TYPE;
9025   lr_position_id        number;
9026   lm_position_assignment_id number;
9027   lr_max_dummy          number := 0;
9028   lp_max_flag           varchar2(1);
9029   l_value_table_flag    varchar2(1);
9030   l_currency_code       varchar2(30);
9031   l_definition_type     varchar2(30);
9032   l_status              varchar2(1);
9033   l_position_name       varchar2(240);
9034   --UTF8 changes for Bug No : 2615261
9035   l_employee_name       varchar2(310);
9036   l_pos_assign_ctr      number := 0;
9037   lp_hr_position_id     number := 0;
9038   l_fin_hr_position_id  number := 0;
9039   l_restart_hr_position_id number := 0;
9040   prev_hr_position_id   number := -1;
9041   -- de by org
9042   l_extract_method      varchar2(30);
9043 
9044   l_debug VARCHAR2(1) := 'N';
9045 
9046   l_api_name    CONSTANT VARCHAR2(30)   := 'Populate_Position_Assignment';
9047   l_api_version CONSTANT NUMBER         := 1.0;
9048 
9049   Cursor C_currency IS
9050     Select currency_code
9051       FROM gl_sets_of_books
9052      WHERE set_of_books_id = p_set_of_books_id;
9053 
9054   Cursor C_pos_values IS
9055     Select attribute_value_id
9056       FROM psb_attribute_values
9057      WHERE attribute_id = l_attribute_id
9058        AND decode(l_definition_type, 'DFF',hr_value_id,
9059 		  attribute_value) = lp_attribute_value
9060        AND data_extract_id  = p_data_extract_id;
9061 
9062 BEGIN
9063 
9064   Savepoint Populate_Position_Assignments;
9065 
9066   l_last_update_date  := sysDATE;
9067   l_last_upDATEd_BY   := FND_GLOBAL.USER_ID;
9068   l_last_upDATE_login := FND_GLOBAL.LOGIN_ID;
9069   l_creation_DATE     := sysDATE;
9070   l_created_BY        := FND_GLOBAL.USER_ID;
9071 
9072   /* start bug 4153562 */
9073   -- initialize the packaged varible with the extract method.
9074   PSB_HR_POPULATE_DATA_PVT.g_extract_method := p_extract_method;
9075   /* end bug 4153562 */
9076 
9077   IF NOT FND_API.Compatible_API_Call (l_api_version,
9078 				      p_api_version,
9079 				      l_api_name,
9080 				      G_PKG_NAME)
9081   THEN
9082     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9083   END IF;
9084 
9085   -- Initialize message lISt IF p_init_msg_lISt IS set to TRUE.
9086 
9087   IF FND_API.to_Boolean (p_init_msg_lISt) THEN
9088     FND_MSG_PUB.initialize;
9089   END IF;
9090 
9091   -- Initialize API return status to success
9092 
9093   p_return_status := FND_API.G_RET_STS_SUCCESS;
9094 
9095   -- API body
9096 
9097   -- de by org
9098   --
9099   -- If extract_method is REFRESH do nothing.
9100   -- Else use the appropriate extract_method based on  the organization's
9101   -- extract status. cache_org_status caches statuses of all organizations.
9102 
9103   IF (p_extract_by_org = 'N' OR p_extract_method = 'REFRESH') THEN
9104         l_extract_method := p_extract_method;
9105     ELSE
9106         cache_org_status
9107          (l_return_status,
9108            p_data_extract_id,
9109            p_extract_by_org
9110          );
9111 
9112         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9113         RAISE FND_API.G_EXC_ERROR;
9114         END IF;
9115     END IF;
9116 
9117 
9118   PSB_HR_EXTRACT_DATA_PVT.Check_Reentry
9119   (  p_api_version              => 1.0  ,
9120      p_return_status            => l_return_status,
9121      p_msg_count                => l_msg_count,
9122      p_msg_data                 => l_msg_data,
9123      p_data_extract_id          => p_data_extract_id,
9124      p_process                  => 'PSB Position Assignments',
9125      p_status                   => l_status,
9126      p_restart_id               => l_restart_hr_position_id
9127   );
9128 
9129   IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9130     RAISE FND_API.G_EXC_ERROR;
9131   END IF;
9132 
9133   IF (l_status = 'I') THEN
9134 
9135     -- Retrieve currency inFORmation.
9136     FOR C_currency_rec in C_currency
9137     LOOP
9138       l_currency_code := C_currency_rec.currency_code;
9139     END LOOP;
9140     --
9141     -- Process all the employees FROM psb_employees along with their ATTRIBUTE
9142     -- assignment inFORmation FROM psb_employee_assignments_i
9143     --
9144     FOR C_Assignment_Rec in
9145     (
9146       /*For Bug No : 2109120 Start*/
9147       /*Select pe.employee_id,
9148 	     pea.hr_position_id,
9149 	     pea.hr_employee_id,
9150 	     pea.attribute_name,
9151 	     pea.attribute_value,
9152 	     pea.effective_start_DATE,
9153 	     pea.effective_END_DATE
9154 	FROM psb_employee_assignments_i pea,
9155 	     psb_employees              pe
9156        WHERE pea.data_extract_id   = p_data_extract_id
9157 	 AND pe.hr_employee_id(+)  = pea.hr_employee_id
9158 	 AND pe.data_extract_id(+) = p_data_extract_id
9159 	 AND pea.hr_position_id    > l_restart_hr_position_id
9160        ORDER by pea.hr_position_id*/
9161 
9162       SELECT ppa.employee_id,
9163              -- de by org
9164              pp.organization_id,
9165 	     pea.hr_position_id,
9166 	     pea.hr_employee_id,
9167 	     pea.attribute_name,
9168 	     pea.attribute_value,
9169 	     pea.effective_start_DATE,
9170 	     pea.effective_END_DATE
9171 	FROM psb_positions pp,
9172 	     psb_position_assignments ppa,
9173 	     psb_employee_assignments_i pea
9174        WHERE pp.data_extract_id = p_data_extract_id
9175 	 AND pp.position_id = ppa.position_id
9176 	 AND ppa.assignment_type = 'EMPLOYEE'
9177 	 AND ppa.employee_id IS NOT NULL
9178 	 AND pp.hr_position_id = pea.hr_position_id
9179 	 AND pp.hr_employee_id = pea.hr_employee_id
9180 	 AND pea.data_extract_id = p_data_extract_id
9181 	 AND pea.hr_position_id    > l_restart_hr_position_id
9182    UNION ALL
9183       SELECT to_number(NULL),
9184              -- de by org
9185              pp.organization_id,
9186 	     pea.hr_position_id,
9187              pea.hr_employee_id,
9188 	     pea.attribute_name,
9189 	     pea.attribute_value,
9190 	     pea.effective_start_DATE,
9191 	     pea.effective_END_DATE
9192       	FROM psb_employee_assignments_i pea,
9193              psb_positions pp
9194        WHERE pea.data_extract_id   = p_data_extract_id
9195          AND pea.hr_position_id = pp.hr_position_id
9196 	 AND pea.hr_employee_id IS NULL
9197 	 AND pp.hr_employee_id IS NULL
9198          AND pp.data_extract_id = p_data_extract_id
9199 	 AND pea.hr_position_id    > l_restart_hr_position_id
9200        ORDER by 3
9201       /*For Bug No : 2109120 End*/
9202     )
9203     LOOP
9204       lp_hr_position_id  := C_Assignment_rec.hr_position_id;
9205       lp_attribute_name  := C_Assignment_Rec.attribute_name;
9206       lp_attribute_value := C_Assignment_Rec.attribute_value;
9207 
9208     -- de by org
9209     -- If extract method is not REFRESH, get the status of the organization
9210     -- to which the employee belongs from the already cached organization
9211     -- statuses.
9212 
9213       IF p_extract_method <> 'REFRESH' and p_extract_by_org = 'Y' THEN
9214          l_extract_method := g_org_status(c_assignment_rec.organization_id);
9215       END IF;
9216 
9217       if ((lp_hr_position_id <> prev_hr_position_id) and (prev_hr_position_id <> -1)) then
9218 	 l_pos_assign_ctr   := l_pos_assign_ctr + 1;
9219 	 if l_pos_assign_ctr = PSB_WS_ACCT1.g_checkpoint_save then
9220 	    PSB_HR_EXTRACT_DATA_PVT.Update_Reentry
9221 	    ( p_api_version              => 1.0  ,
9222 	      p_return_status            => l_return_status,
9223 	      p_msg_count                => l_msg_count,
9224 	      p_msg_data                 => l_msg_data,
9225 	      p_data_extract_id          => p_data_extract_id,
9226 	      p_extract_method           => p_extract_method,
9227 	      p_process                  => 'PSB Position Assignments',
9228 	      p_restart_id               => C_Assignment_Rec.hr_position_id
9229 	    );
9230 
9231 
9232 	 if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9233 	    raise FND_API.G_EXC_ERROR;
9234 	 end if;
9235 	 commit work;
9236 	 /*For Bug No : 2642012 Start*/
9237 	 l_pos_assign_ctr := 0;
9238 	 /*For Bug No : 2642012 End*/
9239 	 Savepoint Populate_Position_Assignments;
9240        end if;
9241       end if;
9242 
9243       IF (c_Assignment_Rec.hr_employee_id IS NOT NULL) THEN
9244        FOR Emp_Name_Rec in G_Employee_Details(p_person_id => c_Assignment_Rec.hr_employee_id)
9245 	LOOP
9246 	  l_employee_name := Emp_Name_Rec.first_name||' '||Emp_Name_Rec.last_name;
9247 	END LOOP;
9248       END IF;
9249 
9250       -- lp_max_flag determines whether a position_id exISts FOR the current
9251       -- C_Assignment_Rec.hr_employee_id.
9252       lp_max_flag := 'N';
9253       -- Find attribute inFORmation FROM psb_attributes_vl based on current
9254       -- attribute name.
9255       FOR C_pos_attr_rec in
9256       (
9257 	Select attribute_id                                ,
9258 	       nvl(value_table_flag ,'N') value_table_flag ,
9259 	       definition_type
9260 	  FROM psb_attributes_VL
9261 	 WHERE business_group_id = p_business_group_id
9262 	   AND name              = lp_attribute_name
9263       )
9264       LOOP
9265 	l_attribute_id     := C_pos_attr_rec.attribute_id;
9266 	l_value_table_flag := C_pos_attr_rec.value_table_flag;
9267 	l_definition_type  := C_pos_attr_rec.definition_type;
9268       END LOOP;
9269       l_attribute_value_id := NULL;
9270       l_attribute_value    := NULL;
9271 
9272       IF (l_value_table_flag = 'Y') THEN
9273 
9274 	-- Find the attribute_value_id based on the current attribute_name
9275 	-- AND attribute_value FROM psb_attribute_values table.
9276 	FOR C_pos_value_rec in C_pos_values
9277 	LOOP
9278 	  l_attribute_value_id := C_pos_value_rec.attribute_value_id;
9279 	END LOOP;
9280 
9281 	IF (l_attribute_value_id IS NULL) THEN
9282 	  l_attribute_value := C_Assignment_rec.attribute_value;
9283 	else
9284 	  l_attribute_value := NULL;
9285 	END IF;
9286 
9287       else
9288 
9289 	l_attribute_value_id := NULL;
9290 	l_attribute_value := C_Assignment_rec.attribute_value;
9291 
9292       END IF;  -- END IF ( l_value_table_flag = 'Y')
9293       -- Find the position_id to be upDATEd FOR.
9294       IF (C_Assignment_rec.hr_employee_id IS NULL) THEN
9295 
9296 	-- As hr_employee_id IS NULL, retrieve position_id FROM psb_positions.
9297 	FOR C_max_pos_rec in
9298 	(
9299 	  Select position_id
9300 	    FROM psb_positions
9301 	   WHERE data_extract_id = p_data_extract_id
9302 	     AND hr_position_id  = C_Assignment_rec.hr_position_id
9303              AND hr_employee_id is null
9304 	)
9305 	LOOP
9306 	  lp_position_id := C_max_pos_rec.position_id;
9307 	  lp_max_flag := 'Y';
9308 	END LOOP;
9309 
9310       else
9311 
9312        -- To handle  positions with non null hr_employee_id
9313 
9314 	FOR C_max_rec in
9315 	(
9316 	  Select position_id
9317 	    FROM psb_positions
9318 	   WHERE data_extract_id = p_data_extract_id
9319 	     AND hr_position_id  = C_Assignment_rec.hr_position_id
9320 	     AND hr_employee_id     = C_Assignment_rec.hr_employee_id
9321 	)
9322 	LOOP
9323 	  lp_position_id  := C_max_rec.position_id;
9324 	  lp_max_flag := 'Y';
9325 	END LOOP;
9326 
9327       END IF; -- Check IF (C_Assignment_rec.hr_employee_id IS NULL)
9328 
9329       -- debug('(lp_max_flag : ' || lp_max_flag );
9330 
9331       --
9332       -- We can only INSERT/upDATE position assignments WHEN we find a
9333       -- matching position_id corresponding to the current employee in the
9334       -- C_Assignment_rec rec. The lp_max_flag = 'Y' means we found a match.
9335       --
9336       IF (lp_position_id IS NOT NULL) THEN
9337        FOR Pos_Name_Rec in G_Position_Details(p_position_id => lp_position_id)
9338 	LOOP
9339 	  l_position_name := Pos_Name_Rec.name;
9340 	END LOOP;
9341       END IF;
9342       IF (lp_max_flag = 'Y') THEN
9343 
9344       -- de by org
9345       --
9346       -- l_extract_method contains the organization's status. Hence using it
9347       -- in lieu of p_extract_method.
9348 
9349 	IF (l_extract_method = 'REFRESH') THEN
9350 
9351 	  lr_max_dummy := 0;
9352 	  lr_position_id        := lp_position_id;
9353 	  lr_attribute_value_id := l_attribute_value_id;
9354 	  lr_attribute_value    := l_attribute_value;
9355 	  lr_attribute_id       := l_attribute_id;
9356 
9357 	  -- Find all the assignments as per the current position_id.
9358 	  FOR C_ref_assign_rec in
9359 	  (
9360 	     Select position_assignment_id
9361 	       FROM psb_position_assignments
9362 	      WHERE data_extract_id = p_data_extract_id
9363 		AND position_id     = lr_position_id
9364 		AND attribute_id    = lr_attribute_id
9365 		AND assignment_type = 'ATTRIBUTE'
9366 	  )
9367 	  LOOP
9368 	    lr_max_dummy := 1;
9369 
9370 	    PSB_POSITIONS_PVT.ModIFy_Assignment
9371 	    (
9372 	      p_api_version            => 1.0,
9373 	      p_return_status          => l_return_status,
9374 	      p_msg_count              => l_msg_count,
9375 	      p_msg_data               => l_msg_data,
9376 	      p_position_assignment_id => lm_position_assignment_id,
9377 	      p_data_extract_id        => p_data_extract_id,
9378 	      p_worksheet_id           => NULL,
9379 	      p_position_id            => lr_position_id,
9380 	      p_assignment_type        => 'ATTRIBUTE',
9381 	      p_attribute_id           => lr_attribute_id,
9382 	      p_attribute_value_id     => lr_attribute_value_id,
9383 	      p_attribute_value        => lr_attribute_value,
9384 	      p_pay_element_id         => NULL,
9385 	      p_pay_element_option_id  => NULL,
9386 	      p_effective_start_DATE   => C_Assignment_Rec.effective_start_DATE,
9387 	      p_effective_END_DATE     => C_Assignment_Rec.effective_end_DATE,
9388 	      p_element_value_type     => NULL,
9389 	      p_element_value          => NULL,
9390 	      p_currency_code          => NULL,
9391 	      p_pay_basIS              => NULL,
9392 	      p_global_default_flag    => NULL,
9393 	      p_assignment_default_rule_id => NULL,
9394 	      p_modIFy_flag            => NULL,
9395 	      p_rowid                  => l_rowid,
9396 	      p_employee_id            => NULL,
9397 	      p_primary_employee_flag  => NULL
9398 	    );
9399 
9400 	    IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9401 	      RAISE FND_API.G_EXC_ERROR;
9402 	    END IF;
9403 
9404 	  END LOOP;
9405 
9406 	END IF; -- END creating 'ATTRIBUTE' type assignment in 'REFRESH' mode.
9407 	IF (l_extract_method = 'CREATE' OR lr_max_dummy = 0 ) THEN
9408 	  --
9409 	  PSB_POSITION_ASSIGNMENTS_PVT.INSERT_ROW
9410 	  (
9411 	     p_api_version             => 1,
9412 	     p_init_msg_lISt           => NULL,
9413 	     p_commit                  => NULL,
9414 	     p_validation_level        => NULL,
9415 	     p_return_status           => l_return_status,
9416 	     p_msg_count               => l_msg_count,
9417 	     p_msg_data                => l_msg_data,
9418 	     p_rowid                   => l_rowid,
9419 	     p_position_assignment_id  => l_position_assignment_id,
9420 	     p_data_extract_id         => p_data_extract_id,
9421 	     p_worksheet_id            => NULL,
9422 	     p_position_id             => lp_position_id,
9423 	     p_assignment_type         => 'ATTRIBUTE',
9424 	     p_attribute_id            => l_attribute_id,
9425 	     p_attribute_value_id      => l_attribute_value_id,
9426 	     p_attribute_value         => l_attribute_value,
9427 	     p_pay_element_id          => NULL,
9428 	     p_pay_element_option_id   => NULL,
9429 	     p_effective_start_DATE    => C_Assignment_Rec.effective_start_DATE,
9430 	     p_effective_END_DATE      => C_Assignment_Rec.effective_END_DATE,
9431 	     p_element_value_type      => NULL,
9432 	     p_element_value           => NULL,
9433 	     p_currency_code           => NULL,
9434 	     p_pay_basIS               => NULL,
9435 	     p_employee_id             => NULL,
9436 	     p_primary_employee_flag   => NULL,
9437 	     p_global_default_flag     => NULL,
9438 	     p_assignment_default_rule_id => NULL,
9439 	     p_modIFy_flag             => NULL,
9440 	     p_mode                    => 'R'
9441 	  ) ;
9442 	  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9443 	    RAISE FND_API.G_EXC_ERROR;
9444 	  END IF;
9445 	END IF; -- END creating 'ATTRIBUTE' type assignment in 'CREATE' mode.
9446 
9447       END IF; -- Check IF (lp_max_flag = 'Y').
9448 
9449       prev_hr_position_id := lp_hr_position_id;
9450     END LOOP; -- END processing all the employees thru C_Assignment_Rec.
9451    PSB_HR_EXTRACT_DATA_PVT.Update_Reentry
9452    ( p_api_version              => 1.0  ,
9453      p_return_status            => l_return_status,
9454      p_msg_count                => l_msg_count,
9455      p_msg_data                 => l_msg_data,
9456      p_data_extract_id          => p_data_extract_id,
9457      p_extract_method           => p_extract_method,
9458      p_process                  => 'PSB Position Assignments',
9459      p_restart_id               => lp_hr_position_id
9460    );
9461 
9462    if l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9463       raise FND_API.G_EXC_ERROR;
9464    end if;
9465 
9466     PSB_HR_EXTRACT_DATA_PVT.Reentrant_Process
9467     ( p_api_version              => 1.0  ,
9468       p_return_status            => l_return_status,
9469       p_msg_count                => l_msg_count,
9470       p_msg_data                 => l_msg_data,
9471       p_data_extract_id          => p_data_extract_id,
9472       p_extract_method           => p_extract_method,
9473       p_process                  => 'PSB Position Assignments'
9474     );
9475 
9476     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9477        RAISE FND_API.G_EXC_ERROR;
9478     END IF;
9479 
9480    /* start bug 4153562 */
9481    -- re-initialize the packaged variable back to null
9482    -- at the end of the populate_position_assignment API.
9483    PSB_HR_POPULATE_DATA_PVT.g_extract_method := null;
9484    /* end bug 4153562 */
9485 
9486     commit work;
9487   END IF;
9488   -- END of API body.
9489   EXCEPTION
9490 
9491    WHEN FND_API.G_EXC_ERROR THEN
9492      ROLLBACK to Populate_Position_Assignments;
9493      p_return_status := FND_API.G_RET_STS_ERROR;
9494      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
9495 				 p_data  => p_msg_data);
9496      FND_MESSAGE.SET_NAME('PSB', 'PSB_POSITION_DETAILS');
9497      FND_MESSAGE.SET_TOKEN('POSITION_NAME',l_position_name );
9498      FND_MESSAGE.SET_TOKEN('EMPLOYEE_NAME',l_employee_name );
9499      FND_MSG_PUB.Add;
9500      FND_MESSAGE.SET_NAME('PSB','PSB_ATTRIBUTE_NAME');
9501      FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME',lp_attribute_name);
9502      FND_MESSAGE.SET_TOKEN('ATTRIBUTE_VALUE',lp_attribute_value);
9503      FND_MSG_PUB.Add;
9504 
9505    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
9506      ROLLBACK to Populate_Position_Assignments;
9507      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9508      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
9509 				 p_data  => p_msg_data);
9510      FND_MESSAGE.SET_NAME('PSB', 'PSB_POSITION_DETAILS');
9511      FND_MESSAGE.SET_TOKEN('POSITION_NAME',l_position_name );
9512      FND_MESSAGE.SET_TOKEN('EMPLOYEE_NAME',l_employee_name );
9513      FND_MSG_PUB.Add;
9514      FND_MESSAGE.SET_NAME('PSB','PSB_ATTRIBUTE_NAME');
9515      FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME',lp_attribute_name);
9516      FND_MESSAGE.SET_TOKEN('ATTRIBUTE_VALUE',lp_attribute_value);
9517      FND_MSG_PUB.Add;
9518 
9519    WHEN OTHERS THEN
9520      ROLLBACK to Populate_Position_Assignments;
9521      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9522      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
9523 				 p_data  => p_msg_data);
9524      FND_MESSAGE.SET_NAME('PSB', 'PSB_POSITION_DETAILS');
9525      FND_MESSAGE.SET_TOKEN('POSITION_NAME',l_position_name );
9526      FND_MESSAGE.SET_TOKEN('EMPLOYEE_NAME',l_employee_name );
9527      FND_MSG_PUB.Add;
9528      FND_MESSAGE.SET_NAME('PSB','PSB_ATTRIBUTE_NAME');
9529      FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME',lp_attribute_name);
9530      FND_MESSAGE.SET_TOKEN('ATTRIBUTE_VALUE',lp_attribute_value);
9531      FND_MSG_PUB.Add;
9532 
9533      IF FND_MSG_PUB.Check_Msg_Level
9534        (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
9535      THEN
9536        FND_MSG_PUB.Add_Exc_Msg
9537 	  (p_pkg_name => G_PKG_NAME,
9538 	   p_procedure_name => l_api_name);
9539     END IF;
9540 
9541 END Populate_Pos_Assignments;
9542 
9543 /* ----------------------------------------------------------------------- */
9544 
9545 /* Bug 4649730 reverted back the changes done for MPA as
9546    the following api will be called only
9547    as part of Extract process */
9548 
9549 PROCEDURE Apply_Defaults
9550 ( p_api_version         IN      NUMBER,
9551   p_init_msg_lISt       IN      VARCHAR2 := FND_API.G_FALSE,
9552   p_commit              IN      VARCHAR2 := FND_API.G_FALSE,
9553   p_validation_level    IN      NUMBER   := FND_API.G_VALID_LEVEL_FULL,
9554   p_return_status       OUT  NOCOPY     VARCHAR2,
9555   p_msg_count           OUT  NOCOPY     NUMBER,
9556   p_msg_data            OUT  NOCOPY     VARCHAR2,
9557   p_data_extract_id     IN      NUMBER,
9558   p_extract_method      IN      VARCHAR2
9559 ) AS
9560 
9561   l_last_update_date    DATE;
9562   l_last_upDATEd_BY     number;
9563   l_last_upDATE_login   number;
9564   l_creation_DATE       DATE;
9565   l_created_BY          number;
9566   l_status              varchar2(1);
9567   l_msg_count           NUMBER;
9568   l_msg_data            VARCHAR2(1000);
9569   l_return_status       varchar2(1);
9570   l_restart_id          NUMBER := 0;
9571 
9572   l_api_name            CONSTANT VARCHAR2(30) := 'Apply_Defaults';
9573   l_api_version         CONSTANT NUMBER      := 1.0;
9574 
9575 Begin
9576 
9577     -- StANDard Start of API savepoint
9578 
9579     Savepoint Apply_Defaults;
9580 
9581     l_last_upDATE_DATE := sysDATE;
9582     l_last_upDATEd_BY := FND_GLOBAL.USER_ID;
9583     l_last_upDATE_login :=FND_GLOBAL.LOGIN_ID;
9584     l_creation_DATE     := sysDATE;
9585     l_created_BY        := FND_GLOBAL.USER_ID;
9586 
9587     -- StANDard call to check FOR call compatibility.
9588 
9589     IF NOT FND_API.Compatible_API_Call (l_api_version,
9590 					p_api_version,
9591 					l_api_name,
9592 					G_PKG_NAME)
9593     THEN
9594        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9595     END IF;
9596 
9597     -- Initialize message lISt IF p_init_msg_lISt IS set to TRUE.
9598 
9599     IF FND_API.to_Boolean (p_init_msg_lISt) THEN
9600        FND_MSG_PUB.initialize;
9601     END IF;
9602 
9603     p_return_status := FND_API.G_RET_STS_SUCCESS;
9604     -- API body
9605 
9606     PSB_HR_EXTRACT_DATA_PVT.Check_Reentry
9607     (p_api_version              => 1.0  ,
9608      p_return_status            => l_return_status,
9609      p_msg_count                => l_msg_count,
9610      p_msg_data                 => l_msg_data,
9611      p_data_extract_id          => p_data_extract_id,
9612      p_process                  => 'PSB Apply Defaults',
9613      p_status                   => l_status,
9614      p_restart_id               => l_restart_id
9615     );
9616 
9617     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9618        RAISE FND_API.G_EXC_ERROR;
9619     END IF;
9620 
9621     IF (l_status = 'I') THEN
9622 
9623 
9624        PSB_POSITIONS_PVT.Create_Default_Assignments
9625        ( p_api_version              =>  1.0,
9626 	 p_commit                   =>  FND_API.G_FALSE,
9627 	 p_validation_level         =>  FND_API.G_VALID_LEVEL_FULL,
9628 	 p_init_msg_lISt            =>  FND_API.G_FALSE,
9629 	 p_return_status            =>  l_return_status,
9630 	 p_msg_count                =>  l_msg_count,
9631 	 p_msg_data                 =>  l_msg_data,
9632 	 p_data_extract_id          =>  p_data_extract_id,
9633 	 p_position_id              =>  FND_API.G_MISS_NUM,
9634 	 p_position_start_DATE      =>  FND_API.G_MISS_DATE,
9635 	 p_position_END_DATE        =>  FND_API.G_MISS_DATE,
9636          p_ruleset_id               =>  NULL  -- Bug 4649730
9637        );
9638 
9639       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9640 	 RAISE FND_API.G_EXC_ERROR;
9641       END IF;
9642 
9643     PSB_HR_EXTRACT_DATA_PVT.Reentrant_Process
9644     ( p_api_version              => 1.0  ,
9645       p_return_status            => l_return_status,
9646       p_msg_count                => l_msg_count,
9647       p_msg_data                 => l_msg_data,
9648       p_data_extract_id          => p_data_extract_id,
9649       p_extract_method           => p_extract_method,
9650       p_process                  => 'PSB Apply Defaults'
9651     );
9652 
9653     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9654        RAISE FND_API.G_EXC_ERROR;
9655     END IF;
9656 
9657     UpDATE PSB_DATA_EXTRACTS
9658        set default_data_status  = 'C'
9659        WHERE data_extract_id = p_data_extract_id;
9660 
9661     commit work;
9662     END IF;
9663 
9664    -- END of API body.
9665 
9666   EXCEPTION
9667 
9668    WHEN FND_API.G_EXC_ERROR THEN
9669      ROLLBACK to Apply_Defaults;
9670      p_return_status := FND_API.G_RET_STS_ERROR;
9671      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
9672 				 p_data  => p_msg_data);
9673 
9674    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
9675      ROLLBACK to Apply_Defaults;
9676      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9677      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
9678 				 p_data  => p_msg_data);
9679 
9680    WHEN OTHERS THEN
9681      ROLLBACK to Apply_Defaults;
9682      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9683      FND_MSG_PUB.Count_And_Get (p_count => p_msg_count,
9684 				 p_data  => p_msg_data);
9685 
9686      IF FND_MSG_PUB.Check_Msg_Level
9687        (p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
9688      THEN
9689        FND_MSG_PUB.Add_Exc_Msg
9690 	  (p_pkg_name => G_PKG_NAME,
9691 	   p_procedure_name => l_api_name);
9692     END IF;
9693 
9694 END Apply_Defaults;
9695 /*---------------------------------------------------------------------------*/
9696 
9697 
9698 /*---------------------------------------------------------------------------*/
9699 -- Get Debug Information
9700 FUNCTION get_debug RETURN VARCHAR2 AS
9701 BEGIN
9702   RETURN(g_dbug);
9703 END get_debug;
9704 /*---------------------------------------------------------------------------*/
9705 
9706 
9707 END PSB_HR_POPULATE_DATA_PVT;