DBA Data[Home] [Help]

PACKAGE BODY: APPS.PA_CONTROL_API_PUB

Source


1 package body PA_CONTROL_API_PUB as
2 /*$Header: PACIAMPB.pls 120.1 2006/11/24 09:05:31 vgottimu noship $*/
3 
4 
5 g_module_name     VARCHAR2(100) := 'pa.plsql.PA_CONTROL_API_PUB';
6 
7 
8 l_debug_mode                 VARCHAR2(1);
9 l_debug_level3               CONSTANT NUMBER := 3;
10 
11 
12 
13 
14 CURSOR Check_Valid_CI (c_Ci_Id NUMBER) IS
15         SELECT ci_id
16         FROM pa_control_items
17         WHERE ci_id = c_Ci_Id;
18 
19 /*
20         Cursor Get_CI_Data.
21         To get the PROJECT_ID, STATUS_CODE, CI_TYPE_CLASS_CODE
22         and RECORD_VERSION_NUMBER for the given Ci_Id.
23 */
24 CURSOR Get_CI_Data (c_Ci_Id NUMBER) IS
25         SELECT ci.project_id,
26         s.project_system_status_code,
27         cib.ci_type_class_code,
28         ci.record_version_number
29         FROM pa_control_items ci,
30         pa_ci_types_b cib,
31         (select
32         project_status_code,
33         project_system_status_code
34         from pa_project_statuses
35         where status_type = 'CONTROL_ITEM') s
36         WHERE ci.ci_id = c_Ci_Id
37         AND ci.ci_type_id = cib.ci_type_id
38         AND ci.status_code = s.project_status_code;
39 
40 /*
41         Cursor Check_Workflow_On_CI.
42         To check whether Workflow is running on the Ci_Id that
43         is passed in.
44 */
45 CURSOR Check_Workflow_On_CI (c_Ci_Id NUMBER) IS
46         SELECT ci.ci_id
47         FROM pa_project_statuses pps, pa_control_items ci
48         WHERE pps.status_type = 'CONTROL_ITEM'
49         AND pps.project_status_code = ci.status_code
50         AND pps.enable_wf_flag = 'Y'
51         AND pps.wf_success_status_code is not null
52         AND pps.wf_failure_status_code is not null
53         AND ci.ci_id = c_Ci_Id;
54 
55 /*
56 	Cursor Get_CI_Type_Class_Code
57 	To get the CI_Type_Class_Code of the Control Item (ISSUE, CHANGE_REQUEST
58 	or CHANGE_ORDER) for a particular Control Item.
59 */
60 CURSOR Get_CI_Type_Class_Code (c_Ci_Id NUMBER) IS
61 	SELECT pcit.ci_type_class_code
62 	FROM pa_control_items pci, pa_ci_types_b pcit
63 	WHERE pci.ci_id = c_Ci_Id
64 	AND pcit.ci_type_id = pci.ci_type_id;
65 
66 /*Procedure to add workplan impact*/
67 Procedure Add_Workplan_Impact (
68         p_commit               IN          VARCHAR2 := FND_API.G_FALSE,
69         p_init_msg_list        IN          VARCHAR2 := FND_API.G_FALSE,
70         p_api_version_number   IN          NUMBER,
71         x_return_status        OUT NOCOPY  VARCHAR2,
72         x_msg_count            OUT NOCOPY  NUMBER,
73         x_msg_data             OUT NOCOPY  VARCHAR2,
74         p_ci_id                IN          NUMBER   := G_PA_MISS_NUM,
75         p_impact_description   IN          VARCHAR2 := G_PA_MISS_CHAR,
76         x_impact_id            OUT NOCOPY  NUMBER
77         )
78 IS
79        --Declaring local Variables
80         l_impact_type_code        pa_ci_impacts.impact_type_code%TYPE:='WORKPLAN';
81         l_msg_count               NUMBER := 0;
82         l_data                    VARCHAR2(2000);
83         l_msg_data                VARCHAR2(2000);
84         l_msg_index_out           NUMBER;
85         l_module_name             VARCHAR2(200):='PA_CONTROL_API_PUB.Add_Workplan_Impact';
86 BEGIN
87 
88         x_return_status := FND_API.G_RET_STS_SUCCESS;
89         x_msg_count := 0;
90         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
91 
92         IF l_debug_mode = 'Y' THEN
93                 PA_DEBUG.set_curr_function(p_function => 'Add_Workplan_Impact', p_debug_mode => l_debug_mode);
94         END IF;
95 
96         --initializing the message stack.
97         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
98                 FND_MSG_PUB.initialize;
99         END IF;
100 
101         IF p_commit = FND_API.G_TRUE THEN
102                 savepoint ADD_WORKPLAN_IMPACT_SVPT;
103         END IF;
104 
105         IF l_debug_mode = 'Y' THEN
106                 pa_debug.write(l_module_name, 'Start of Add Workplan Impact', l_debug_level3);
107         END IF;
108 
109         /*validating the CI_ID for null value*/
110         if  p_ci_id is null or p_ci_id = G_PA_MISS_NUM then
111                  PA_UTILS.ADD_MESSAGE(p_app_short_name  => 'PA',
112                                       p_msg_name        => 'PA_CI_MISS_CI_ID');
113                  if l_debug_mode = 'Y' then
114                         pa_debug.g_err_stage:= 'The ci_id is null';
115                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
116                  end if;
117                  raise FND_API.G_EXC_ERROR;
118         end if;
119 
120         /*Calling the private API
121         This update_impacts will do all the necessary validations and call
122         other procedure to insert the details*/
123         if l_debug_mode = 'Y' then
124                pa_debug.g_err_stage:= 'Before Calling the Private API PA_CONTROL_API_PVT.update_impacts';
125                pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
126         end if;
127 
128 
129         PA_CONTROL_API_PVT.update_impacts(
130                   p_ci_id               =>  p_ci_id,
131                   x_ci_impact_id        =>  x_impact_id,
132                   p_impact_type_code    =>  l_impact_type_code,
133                   p_impact_description  =>  p_impact_description,
134                   p_api_version_number  =>  p_api_version_number ,
135                   p_commit              =>  p_commit,
136                   p_init_msg_list       =>  p_init_msg_list,
137                   p_mode                =>  'INSERT',
138                   x_return_status       =>  x_return_status,
139                   x_msg_count           =>  x_msg_count,
140                   x_msg_data            =>  x_msg_data
141                   );
142 
143         IF p_commit = FND_API.G_TRUE and  x_return_status = FND_API.G_RET_STS_SUCCESS THEN
144                  COMMIT;
145         END IF;
146          --Reset the stack
147          if l_debug_mode = 'Y' then
148                   Pa_Debug.reset_curr_function;
149          end if;
150 
151 Exception
152 when FND_API.G_EXC_ERROR then
153 
154         x_return_status := FND_API.G_RET_STS_ERROR;
155         l_msg_count := FND_MSG_PUB.count_msg;
156 
157         IF p_commit = FND_API.G_TRUE THEN
158                 ROLLBACK TO ADD_WORKPLAN_IMPACT_SVPT;
159         END IF;
160         if l_msg_count = 1 then
161               pa_interface_utils_pub.get_messages
162                             (p_encoded        => fnd_api.g_false,
163                              p_msg_index      => 1,
164                              p_msg_count      => l_msg_count ,
165                              p_msg_data       => l_msg_data ,
166                              p_data           => l_data,
167                              p_msg_index_out  => l_msg_index_out );
168               x_msg_data  := l_data;
169               x_msg_count := l_msg_count;
170          else
171               x_msg_count := l_msg_count;
172          end if;
173 
174          --Reset the stack
175          if l_debug_mode = 'Y' then
176                   Pa_Debug.reset_curr_function;
177          end if;
178 
179 when others then
180 
181          x_return_status := fnd_api.g_ret_sts_unexp_error;
182          x_msg_data      := substr(SQLERRM,1,240);
183 
184          IF p_commit = FND_API.G_TRUE THEN
185                 ROLLBACK TO ADD_WORKPLAN_IMPACT_SVPT;
186          END IF;
187          fnd_msg_pub.add_exc_msg ( p_pkg_name        => 'PA_CONTROL_API_PUB',
188                                    p_procedure_name  => 'Add_Workplan_Impact',
189                                    p_error_text      => x_msg_data);
190          x_msg_count     := FND_MSG_PUB.count_msg;
191          if l_debug_mode = 'Y' then
192                  pa_debug.reset_err_stack;
193          end if;
194 
195 End Add_Workplan_Impact;
196 
197 
198 /*Procedure to add Staffing impact*/
199 Procedure Add_Staffing_Impact(
200         p_commit               IN          VARCHAR2 := FND_API.G_FALSE,
201         p_init_msg_list        IN          VARCHAR2 := FND_API.G_FALSE,
202         p_api_version_number   IN          NUMBER,
203         x_return_status        OUT NOCOPY  VARCHAR2,
204         x_msg_count            OUT NOCOPY  NUMBER,
205         x_msg_data             OUT NOCOPY  VARCHAR2,
206         p_ci_id                IN          NUMBER   := G_PA_MISS_NUM,
207         p_impact_description   IN          VARCHAR2 := G_PA_MISS_CHAR,
208         x_impact_id            OUT NOCOPY  NUMBER
209         )
210 IS
211        --Declaring local Variables
212   l_impact_type_code          pa_ci_impacts.impact_type_code%TYPE:='STAFFING';
213   l_msg_count                 NUMBER := 0;
214   l_data                      VARCHAR2(2000);
215   l_msg_data                  VARCHAR2(2000);
216   l_msg_index_out             NUMBER;
217   l_module_name             VARCHAR2(200):='PA_CONTROL_API_PUB.Add_Staffing_Impact';
218 BEGIN
219 
220         x_return_status := FND_API.G_RET_STS_SUCCESS;
221         x_msg_count := 0;
222         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
223 
224         IF l_debug_mode = 'Y' THEN
225                 PA_DEBUG.set_curr_function(p_function => 'Add_Staffing_Impact', p_debug_mode => l_debug_mode);
226         END IF;
227 
228         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
229                 FND_MSG_PUB.initialize;
230         END IF;
231 
232         IF p_commit = FND_API.G_TRUE THEN
233                 savepoint ADD_STAFFING_IMPACT_SVPT;
234         END IF;
235 
236         IF l_debug_mode = 'Y' THEN
237                 pa_debug.write(l_module_name, 'Start of Add Staffing Impact', l_debug_level3);
238         END IF;
239 
240         /*validating the CI_ID for null value*/
241         if  p_ci_id is null or p_ci_id = G_PA_MISS_NUM then
242                  PA_UTILS.ADD_MESSAGE(p_app_short_name  => 'PA',
243                                       p_msg_name        => 'PA_CI_MISS_CI_ID');
244                  if l_debug_mode = 'Y' then
245                         pa_debug.g_err_stage:= 'The ci_id is null';
246                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
247                  end if;
248                  raise FND_API.G_EXC_ERROR;
249         end if;
250 
251         /*Calling the private API
252         This update_impacts will do all the necessary validations and call
253         other procedure to insert the details*/
254         if l_debug_mode = 'Y' then
255                pa_debug.g_err_stage:= 'Before Calling the Private API PA_CONTROL_API_PVT.update_impacts';
256                pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
257         end if;
258         PA_CONTROL_API_PVT.update_impacts(
259                   p_ci_id               =>  p_ci_id,
260                   x_ci_impact_id        =>  x_impact_id,
261                   p_impact_type_code    =>  l_impact_type_code,
262                   p_impact_description  =>  p_impact_description,
263                   p_api_version_number  =>  p_api_version_number ,
264                   p_commit              =>  p_commit,
265                   p_init_msg_list       =>  p_init_msg_list,
266                   p_mode                =>  'INSERT',
267                   x_return_status       =>  x_return_status,
268                   x_msg_count           =>  x_msg_count,
269                   x_msg_data            =>  x_msg_data
270                   );
271 
272         IF p_commit = FND_API.G_TRUE and  x_return_status = FND_API.G_RET_STS_SUCCESS THEN
273                  COMMIT;
274         END IF;
275          --Reset the stack
276          if l_debug_mode = 'Y' then
277                   Pa_Debug.reset_curr_function;
278          end if;
279 
280 Exception
281 when FND_API.G_EXC_ERROR then
282 
283         x_return_status := FND_API.G_RET_STS_ERROR;
284         l_msg_count := FND_MSG_PUB.count_msg;
285 
286         IF p_commit = FND_API.G_TRUE THEN
287                 ROLLBACK TO ADD_STAFFING_IMPACT_SVPT;
288         END IF;
289 
290        if l_msg_count = 1 then
291               pa_interface_utils_pub.get_messages
292                             (p_encoded        => fnd_api.g_false,
293                              p_msg_index      => 1,
294                              p_msg_count      => l_msg_count ,
295                              p_msg_data       => l_msg_data ,
296                              p_data           => l_data,
297                              p_msg_index_out  => l_msg_index_out );
298               x_msg_data  := l_data;
299               x_msg_count := l_msg_count;
300       else
301               x_msg_count := l_msg_count;
302       end if;
303       --Reset the stack
304       if l_debug_mode = 'Y' then
305               Pa_Debug.reset_curr_function;
306       end if;
307 
308 when others then
309       x_return_status := fnd_api.g_ret_sts_unexp_error;
310       x_msg_data      := substr(SQLERRM,1,240);
311       IF p_commit = FND_API.G_TRUE THEN
312              ROLLBACK TO ADD_STAFFING_IMPACT_SVPT;
313       END IF;
314       fnd_msg_pub.add_exc_msg ( p_pkg_name        => 'PA_CONTROL_API_PUB',
315                                 p_procedure_name  => 'Add_Staffing_Impact',
316                                 p_error_text      => x_msg_data);
317       x_msg_count     := FND_MSG_PUB.count_msg;
318       if l_debug_mode = 'Y' then
319               pa_debug.reset_err_stack;
320       end if;
321 
322  End Add_Staffing_Impact;
323 
324 
325 
326 /*Procedure to add Contract impact*/
327 Procedure Add_Contract_Impact(
328         p_commit               IN          VARCHAR2 := FND_API.G_FALSE,
329         p_init_msg_list        IN          VARCHAR2 := FND_API.G_FALSE,
330         p_api_version_number   IN          NUMBER,
331         x_return_status        OUT NOCOPY  VARCHAR2,
332         x_msg_count            OUT NOCOPY  NUMBER,
333         x_msg_data             OUT NOCOPY  VARCHAR2,
334         p_ci_id                IN          NUMBER   := G_PA_MISS_NUM,
335         p_impact_description   IN          VARCHAR2 := G_PA_MISS_CHAR,
336         x_impact_id            OUT NOCOPY  NUMBER
337         )
338 IS
339        --Declaring local Variables
340     l_impact_type_code      pa_ci_impacts.impact_type_code%TYPE:='CONTRACT';
341     l_msg_count            NUMBER := 0;
342     l_data                 VARCHAR2(2000);
343     l_msg_data             VARCHAR2(2000);
344     l_msg_index_out        NUMBER;
345     l_module_name             VARCHAR2(200):='PA_CONTROL_API_PUB.Add_Contract_Impact';
346 BEGIN
347 
348         x_return_status := FND_API.G_RET_STS_SUCCESS;
349         x_msg_count := 0;
350         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
351 
352         IF l_debug_mode = 'Y' THEN
353                 PA_DEBUG.set_curr_function(p_function => 'Add_Contract_Impact', p_debug_mode => l_debug_mode);
354         END IF;
355 
356         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
357                 FND_MSG_PUB.initialize;
358         END IF;
359 
360         IF p_commit = FND_API.G_TRUE THEN
361                 savepoint ADD_CONTRACT_IMPACT_SVPT;
362         END IF;
363 
364         IF l_debug_mode = 'Y' THEN
365                 pa_debug.write(l_module_name, 'Start of Add Contract Impact', l_debug_level3);
366         END IF;
367 
368         /*validating the CI_ID for null value*/
369         if  p_ci_id is null or p_ci_id = G_PA_MISS_NUM then
370                  PA_UTILS.ADD_MESSAGE(p_app_short_name  => 'PA',
371                                       p_msg_name        => 'PA_CI_MISS_CI_ID');
372                  if l_debug_mode = 'Y' then
373                         pa_debug.g_err_stage:= 'The ci_id is null';
374                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
375                  end if;
376                  raise FND_API.G_EXC_ERROR;
377         end if;
378 
379         /*Calling the private API
380         This update_impacts will do all the necessary validations and call
381         other procedure to insert the details*/
382         if l_debug_mode = 'Y' then
383                pa_debug.g_err_stage:= 'Before Calling the Private API PA_CONTROL_API_PVT.update_impacts';
384                pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
385         end if;
386 
387         PA_CONTROL_API_PVT.update_impacts(
388                   p_ci_id               =>  p_ci_id,
389                   x_ci_impact_id        =>  x_impact_id,
390                   p_impact_type_code    =>  l_impact_type_code,
391                   p_impact_description  =>  p_impact_description,
392                   p_api_version_number  =>  p_api_version_number ,
393                   p_commit              =>  p_commit,
394                   p_init_msg_list       =>  p_init_msg_list,
395                   p_mode                =>  'INSERT',
396                   x_return_status       =>  x_return_status,
397                   x_msg_count           =>  x_msg_count,
398                   x_msg_data            =>  x_msg_data
399                   );
400 
401         IF p_commit = FND_API.G_TRUE and  x_return_status = FND_API.G_RET_STS_SUCCESS THEN
402                  COMMIT;
403         END IF;
404          --Reset the stack
405          if l_debug_mode = 'Y' then
406                   Pa_Debug.reset_curr_function;
407          end if;
408 Exception
409 when FND_API.G_EXC_ERROR then
410 
411         x_return_status := FND_API.G_RET_STS_ERROR;
412         l_msg_count := FND_MSG_PUB.count_msg;
413 
414         IF p_commit = FND_API.G_TRUE THEN
415                 ROLLBACK TO ADD_CONTRACT_IMPACT_SVPT;
416         END IF;
417         if l_msg_count = 1 then
418               pa_interface_utils_pub.get_messages
419                             (p_encoded        => fnd_api.g_false,
420                              p_msg_index      => 1,
421                              p_msg_count      => l_msg_count ,
422                              p_msg_data       => l_msg_data ,
423                              p_data           => l_data,
424                              p_msg_index_out  => l_msg_index_out );
425               x_msg_data  := l_data;
426               x_msg_count := l_msg_count;
427         else
428               x_msg_count := l_msg_count;
429         end if;
430         --Reset the stack
431         if l_debug_mode = 'Y' then
432                  Pa_Debug.reset_curr_function;
433         end if;
434 
435 when others then
436         x_return_status := fnd_api.g_ret_sts_unexp_error;
437         x_msg_data      := substr(SQLERRM,1,240);
438 
439         IF p_commit = FND_API.G_TRUE THEN
440                ROLLBACK TO ADD_CONTRACT_IMPACT_SVPT;
441         END IF;
442         fnd_msg_pub.add_exc_msg ( p_pkg_name        => 'PA_CONTROL_API_PUB',
443                                    p_procedure_name  => 'Add_Contract_Impact',
444                                    p_error_text      => x_msg_data);
445         x_msg_count     := FND_MSG_PUB.count_msg;
446         if l_debug_mode = 'Y' then
447                  pa_debug.reset_err_stack;
448          end if;
449 End Add_Contract_Impact;
450 
451 /*Procedure to add Other impact*/
452 Procedure Add_Other_Impact(
453         p_commit               IN          VARCHAR2 := FND_API.G_FALSE,
454         p_init_msg_list        IN          VARCHAR2 := FND_API.G_FALSE,
455         p_api_version_number   IN          NUMBER,
456         x_return_status        OUT NOCOPY  VARCHAR2,
457         x_msg_count            OUT NOCOPY  NUMBER,
458         x_msg_data             OUT NOCOPY  VARCHAR2,
459         p_ci_id                IN          NUMBER   := G_PA_MISS_NUM,
460         p_impact_description   IN          VARCHAR2 := G_PA_MISS_CHAR,
461         x_impact_id            OUT NOCOPY  NUMBER
462         )
463 IS
464        --Declaring local Variables
465         l_impact_type_code       pa_ci_impacts.impact_type_code%TYPE:='OTHER';
466         l_msg_count              NUMBER := 0;
467         l_data                   VARCHAR2(2000);
468         l_msg_data               VARCHAR2(2000);
469         l_msg_index_out          NUMBER;
470         l_module_name             VARCHAR2(200):='PA_CONTROL_API_PUB.Add_Other_Impact';
471 BEGIN
472 
473         x_return_status := FND_API.G_RET_STS_SUCCESS;
474         x_msg_count := 0;
475         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
476 
477         IF l_debug_mode = 'Y' THEN
478                 PA_DEBUG.set_curr_function(p_function => 'Add_Other_Impact', p_debug_mode => l_debug_mode);
479         END IF;
480 
481         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
482                 FND_MSG_PUB.initialize;
483         END IF;
484 
485         IF p_commit = FND_API.G_TRUE THEN
486                 savepoint ADD_OTHER_IMPACT_SVPT;
487         END IF;
488 
489         IF l_debug_mode = 'Y' THEN
490                 pa_debug.write(l_module_name, 'Start of Add Other Impact', l_debug_level3);
491         END IF;
492 
493         /*validating the CI_ID for null value*/
494         if  p_ci_id is null or p_ci_id = G_PA_MISS_NUM then
495                  PA_UTILS.ADD_MESSAGE(p_app_short_name  => 'PA',
496                                       p_msg_name        => 'PA_CI_MISS_CI_ID');
497                  if l_debug_mode = 'Y' then
498                         pa_debug.g_err_stage:= 'The ci_id is null';
499                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
500                  end if;
501                  raise FND_API.G_EXC_ERROR;
502         end if;
503 
504         /*Calling the private API
505         This update_impacts will do all the necessary validations and call
506         other procedure to insert the details*/
507         if l_debug_mode = 'Y' then
508                pa_debug.g_err_stage:= 'Before Calling the Private API PA_CONTROL_API_PVT.update_impacts';
509                pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
510         end if;
511 
512         PA_CONTROL_API_PVT.update_impacts(
513                   p_ci_id               =>  p_ci_id,
514                   x_ci_impact_id        =>  x_impact_id,
515                   p_impact_type_code    =>  l_impact_type_code,
516                   p_impact_description  =>  p_impact_description,
517                   p_api_version_number  =>  p_api_version_number ,
518                   p_commit              =>  p_commit,
519                   p_init_msg_list       =>  p_init_msg_list,
520                   p_mode                =>  'INSERT',
521                   x_return_status       =>  x_return_status,
522                   x_msg_count           =>  x_msg_count,
523                   x_msg_data            =>  x_msg_data
524                   );
525 
526        IF p_commit = FND_API.G_TRUE and  x_return_status = FND_API.G_RET_STS_SUCCESS THEN
527                  COMMIT;
528         END IF;
529          --Reset the stack
530          if l_debug_mode = 'Y' then
531                   Pa_Debug.reset_curr_function;
532          end if;
533 Exception
534 when FND_API.G_EXC_ERROR then
535 
536         x_return_status := FND_API.G_RET_STS_ERROR;
537         l_msg_count := FND_MSG_PUB.count_msg;
538 
539         IF p_commit = FND_API.G_TRUE THEN
540                 ROLLBACK TO ADD_OTHER_IMPACT_SVPT;
541         END IF;
542         if l_msg_count = 1 then
543               pa_interface_utils_pub.get_messages
544                             (p_encoded        => fnd_api.g_false,
545                              p_msg_index      => 1,
546                              p_msg_count      => l_msg_count ,
547                              p_msg_data       => l_msg_data ,
548                              p_data           => l_data,
549                              p_msg_index_out  => l_msg_index_out );
550               x_msg_data  := l_data;
551               x_msg_count := l_msg_count;
552         else
553               x_msg_count := l_msg_count;
554         end if;
555         --Reset the stack
556         if l_debug_mode = 'Y' then
557                  Pa_Debug.reset_curr_function;
558         end if;
559 
560 when others then
561          x_return_status := fnd_api.g_ret_sts_unexp_error;
562          x_msg_data      := substr(SQLERRM,1,240);
563 
564          IF p_commit = FND_API.G_TRUE THEN
565                 ROLLBACK TO ADD_OTHER_IMPACT_SVPT;
566          END IF;
567          fnd_msg_pub.add_exc_msg ( p_pkg_name        => 'PA_CONTROL_API_PUB',
568                                    p_procedure_name  => 'Add_Other_Impact',
569                                    p_error_text      => x_msg_data);
570          x_msg_count     := FND_MSG_PUB.count_msg;
571 
572         if l_debug_mode = 'Y' then
573                  pa_debug.reset_err_stack;
574         end if;
575 End Add_Other_Impact;
576 
577 /*Procedure to add Supplier impact ,
578 including the supplier details passed as a table type parameter*/
579 Procedure Add_Supplier_Impact (
580         p_commit               IN          VARCHAR2 := FND_API.G_FALSE,
581         p_init_msg_list        IN          VARCHAR2 := FND_API.G_FALSE,
582         p_api_version_number   IN          NUMBER,
583         x_return_status        OUT NOCOPY  VARCHAR2,
584         x_msg_count            OUT NOCOPY  NUMBER,
585         x_msg_data             OUT NOCOPY  VARCHAR2,
586         p_ci_id                IN          NUMBER   := G_PA_MISS_NUM,
587         p_impact_description   IN          VARCHAR2 := G_PA_MISS_CHAR,
588         p_supplier_det_tbl     IN          SUPP_DET_TBL_TYPE,    --Table with supplier details
589         x_impact_id            OUT NOCOPY  NUMBER
590         )
591 IS
592   --Declaring local Variables
593   l_impact_type_code       pa_ci_impacts.impact_type_code%TYPE:='SUPPLIER';
594   l_msg_count              NUMBER := 0;
595   l_data                   VARCHAR2(2000);
596   l_msg_data               VARCHAR2(2000);
597   l_msg_index_out          NUMBER;
598   l_module_name             VARCHAR2(200):='PA_CONTROL_API_PUB.Add_Supplier_Impact';
599   l_any_error_flag         VARCHAR2(1):= null;
600 
601 --Supplier Details
602   l_change_type            VARCHAR2(100);
603   l_change_description     VARCHAR2(2000);
604   l_vendor_id              VARCHAR2(240);
605   l_po_header_id           NUMBER;
606   l_po_number              VARCHAR2(40);
607   l_po_line_id             NUMBER;
608   l_po_line_num            NUMBER;
609   l_currency               VARCHAR2(15);
610   l_change_amount          NUMBER;
611 
612 
613 BEGIN
614         x_return_status := FND_API.G_RET_STS_SUCCESS;
615         x_msg_count := 0;
616         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
617 
618         IF l_debug_mode = 'Y' THEN
619                 PA_DEBUG.set_curr_function(p_function => 'Add_Supplier_Impact', p_debug_mode => l_debug_mode);
620         END IF;
621 
622         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
623                 FND_MSG_PUB.initialize;
624         END IF;
625 
626         IF p_commit = FND_API.G_TRUE THEN
627                 savepoint ADD_SUPPLIER_IMPACT_SVPT;
628         END IF;
629 
630         IF l_debug_mode = 'Y' THEN
631                 pa_debug.write(l_module_name, 'Start of Add_Supplier_Impact', l_debug_level3);
632         END IF;
633 
634          /*validating the CI_ID for null value*/
635          if  p_ci_id is null or p_ci_id = G_PA_MISS_NUM then
636                  PA_UTILS.ADD_MESSAGE(p_app_short_name  => 'PA',
637                                       p_msg_name        => 'PA_CI_MISS_CI_ID');
638                  if l_debug_mode = 'Y' then
639                         pa_debug.g_err_stage:= 'The ci_id is null';
640                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
641                  end if;
642                  raise FND_API.G_EXC_ERROR;
643         end if;
644          if l_debug_mode = 'Y' then
645                pa_debug.g_err_stage:= 'Before Calling the Private API PA_CONTROL_API_PVT.update_impacts';
646                pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
647         end if;
648         /*Calling the private API
649         This update_impacts will do all the necessary validations and call
650         other procedure to insert the details*/
651         PA_CONTROL_API_PVT.update_impacts(
652                   p_ci_id               =>  p_ci_id,
653                   x_ci_impact_id        =>  x_impact_id,
654                   p_impact_type_code    =>  l_impact_type_code,
655                   p_impact_description  =>  p_impact_description,
656                   p_api_version_number  =>  p_api_version_number ,
657                   p_mode                => 'INSERT',
658                   x_return_status       =>  x_return_status,
659                   x_msg_count           =>  x_msg_count,
660                   x_msg_data            =>  x_msg_data
661                   );
662 
663         /* Adding the details of suppliers.*/
664         if l_debug_mode = 'Y' then
665                pa_debug.g_err_stage:= 'Created the supplier impact and calling the supplier details API.';
666                pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
667         end if;
668         /*Calling the supplier details API  add Supplier details procedure.
669         If any of the details did not get inserted successfully then roll back
670           them including the  impact.*/
671         if  x_return_status = FND_API.G_RET_STS_SUCCESS and x_impact_id is not null and p_supplier_det_tbl is not null then
672 
673             PA_CONTROL_API_PVT.Add_supplier_details(
674                         p_ci_id                =>    p_ci_id,
675                         p_ci_impact_id         =>    x_impact_id,
676                         p_supplier_det_tbl     =>    p_supplier_det_tbl,
677                         x_return_status        =>    x_return_status,
678                         x_msg_count            =>    x_msg_count,
679                         x_msg_data             =>    x_msg_data
680                         );
681 
682         end if;
683 
684 
685         IF p_commit = FND_API.G_TRUE and  x_return_status = FND_API.G_RET_STS_SUCCESS THEN
686                  COMMIT;
687         END IF;
688          --Reset the stack
689          if l_debug_mode = 'Y' then
690                   Pa_Debug.reset_curr_function;
691          end if;
692 
693 Exception
694 when FND_API.G_EXC_ERROR then
695 
696          x_return_status := fnd_api.g_ret_sts_error;
697          l_msg_count := fnd_msg_pub.count_msg;
698 
699           IF p_commit = 'T' THEN
700             ROLLBACK to ADD_SUPPLIER_IMPACT_SVPT;
701           END IF;
702 
703 
704          if l_msg_count = 1 then
705               pa_interface_utils_pub.get_messages
706                             (p_encoded        => fnd_api.g_false,
707                              p_msg_index      => 1,
708                              p_msg_count      => l_msg_count ,
709                              p_msg_data       => l_msg_data ,
710                              p_data           => l_data,
711                              p_msg_index_out  => l_msg_index_out );
712               x_msg_data  := x_msg_data || l_data;
713               x_msg_count := l_msg_count;
714 
715          else
716               x_msg_count := l_msg_count;
717          end if;
718 
719          --Reset the stack
720          if l_debug_mode = 'Y' then
721                   Pa_Debug.reset_curr_function;
722          end if;
723 
724 when others then
725 
726          x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
727          x_msg_data      := substr(SQLERRM,1,240);
728          IF p_commit = FND_API.G_TRUE THEN
729                 ROLLBACK TO ADD_SUPPLIER_IMPACT_SVPT;
730          END IF;
731          fnd_msg_pub.add_exc_msg ( p_pkg_name        => 'PA_CONTROL_API_PUB',
732                                    p_procedure_name  => 'Add_Supplier_Impact',
733                                    p_error_text      => x_msg_data);
734         x_msg_count     := FND_MSG_PUB.count_msg;
735         --Reset the stack
736          if l_debug_mode = 'Y' then
737                   Pa_Debug.reset_curr_function;
738          end if;
739 End Add_Supplier_Impact;
740 
741 
742 
743 /*Procedure to update or implement the Workplan impact*/
744 Procedure  Update_Workplan_Impact (
745         p_commit               IN         VARCHAR2 := FND_API.G_FALSE,
746         p_init_msg_list        IN         VARCHAR2 := FND_API.G_FALSE,
747         p_api_version_number   IN         NUMBER,
748         x_return_status        OUT NOCOPY VARCHAR2,
749         x_msg_count            OUT NOCOPY NUMBER,
750         x_msg_data             OUT NOCOPY VARCHAR2,
751         p_ci_id                IN          NUMBER   := G_PA_MISS_NUM,
752         p_impact_description   IN          VARCHAR2 := G_PA_MISS_CHAR
753         )
754 IS
755         --Declaring local Variables
756         l_impact_type_code        pa_ci_impacts.impact_type_code%TYPE:='WORKPLAN';
757         l_ci_impact_id            pa_ci_impacts.ci_impact_id%Type;
758         l_msg_count               NUMBER := 0;
759         l_data                    VARCHAR2(2000);
760         l_msg_data                VARCHAR2(2000);
761         l_msg_index_out           NUMBER;
762         l_module_name             VARCHAR2(200):='PA_CONTROL_API_PUB.Update_Workplan_Impact';
763 BEGIN
764 
765         x_return_status := FND_API.G_RET_STS_SUCCESS;
766         x_msg_count := 0;
767         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
768 
769         IF l_debug_mode = 'Y' THEN
770                 PA_DEBUG.set_curr_function(p_function => 'Update_Workplan_Impact', p_debug_mode => l_debug_mode);
771         END IF;
772 
773         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
774                 FND_MSG_PUB.initialize;
775         END IF;
776 
777         IF p_commit = FND_API.G_TRUE THEN
778                 savepoint UPDATE_WORKPLAN_IMPACT_SVPT;
779         END IF;
780 
781         IF l_debug_mode = 'Y' THEN
782                 pa_debug.write(l_module_name, 'Start of Update_Workplan_Impact', l_debug_level3);
783         END IF;
784 
785          /*validating the CI_ID for null value*/
786          if  p_ci_id is null or p_ci_id = G_PA_MISS_NUM then
787                  PA_UTILS.ADD_MESSAGE(p_app_short_name  => 'PA',
788                                       p_msg_name        => 'PA_CI_MISS_CI_ID');
789                  if l_debug_mode = 'Y' then
790                         pa_debug.g_err_stage:= 'The ci_id is null';
791                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
792                  end if;
793                  raise FND_API.G_EXC_ERROR;
794         end if;
795 
796 
797         /*Calling the private API
798         This update_impacts will do all the necessary validations and call
799         other procedure to insert the details*/
800          if l_debug_mode = 'Y' then
801                pa_debug.g_err_stage:= 'Before Calling the Private API PA_CONTROL_API_PVT.update_impacts';
802                pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
803         end if;
804 
805          PA_CONTROL_API_PVT.update_impacts(
806                 p_ci_id                   => p_ci_id       ,
807                 p_impact_type_code        => l_impact_type_code,
808                 p_impact_description      => p_impact_description,
809                 p_api_version_number      => p_api_version_number ,
810                 p_mode                    => 'UPDATE',
811                 x_ci_impact_id            => l_ci_impact_id,
812                 x_return_status           => x_return_status,
813                 x_msg_count               => x_msg_count,
814                 x_msg_data                => x_msg_data
815                 );
816 
817            IF p_commit = FND_API.G_TRUE and  x_return_status = FND_API.G_RET_STS_SUCCESS THEN
818                  COMMIT;
819            END IF;
820             --Reset the stack
821          if l_debug_mode = 'Y' then
822                   Pa_Debug.reset_curr_function;
823          end if;
824 
825 Exception
826 when FND_API.G_EXC_ERROR then
827 
828          x_return_status := fnd_api.g_ret_sts_error;
829          l_msg_count := fnd_msg_pub.count_msg;
830 
831           IF p_commit = 'T' THEN
832             ROLLBACK to UPDATE_WORKPLAN_IMPACT_SVPT;
833           END IF;
834 
835          if l_msg_count = 1 then
836               pa_interface_utils_pub.get_messages
837                             (p_encoded        => fnd_api.g_false,
838                              p_msg_index      => 1,
839                              p_msg_count      => l_msg_count ,
840                              p_msg_data       => l_msg_data ,
841                              p_data           => l_data,
842                              p_msg_index_out  => l_msg_index_out );
843               x_msg_data  :=  l_data;
844               x_msg_count := l_msg_count;
845          else
846               x_msg_count := l_msg_count;
847          end if;
848 
849          --Reset the stack
850          if l_debug_mode = 'Y' then
851                   Pa_Debug.reset_curr_function;
852          end if;
853 
854 when others then
855 
856          x_return_status := fnd_api.g_ret_sts_unexp_error;
857          x_msg_data      := substr(SQLERRM,1,240);
858          IF p_commit = FND_API.G_TRUE THEN
859                 ROLLBACK TO UPDATE_WORKPLAN_IMPACT_SVPT;
860          END IF;
861 
862 
863          fnd_msg_pub.add_exc_msg ( p_pkg_name        => 'PA_CONTROL_API_PUB',
864                                    p_procedure_name  => 'UPDATE_WORKPLAN_IMPACT',
865                                    p_error_text      => x_msg_data);
866         x_msg_count     := FND_MSG_PUB.count_msg;
867         --Reset the stack
868          if l_debug_mode = 'Y' then
869                   Pa_Debug.reset_curr_function;
870          end if;
871 
872 End Update_Workplan_Impact;
873 
874 /*Procedure to update or implement the Staffing impact*/
875 Procedure   Update_Staffing_Impact(
876         p_commit               IN         VARCHAR2 := FND_API.G_FALSE,
877         p_init_msg_list        IN         VARCHAR2 := FND_API.G_FALSE,
878         p_api_version_number   IN         NUMBER,
879         x_return_status        OUT NOCOPY VARCHAR2,
880         x_msg_count            OUT NOCOPY NUMBER,
881         x_msg_data             OUT NOCOPY VARCHAR2,
882         p_ci_id                IN          NUMBER   := G_PA_MISS_NUM,
883         p_impact_description   IN          VARCHAR2 := G_PA_MISS_CHAR
884         )
885 IS
886   --Declaring local Variables
887         l_impact_type_code        pa_ci_impacts.impact_type_code%TYPE:='STAFFING';
888         l_ci_impact_id            pa_ci_impacts.ci_impact_id%Type;
889         l_msg_count               NUMBER := 0;
890         l_data                    VARCHAR2(2000);
891         l_msg_data                VARCHAR2(2000);
892         l_msg_index_out           NUMBER;
893         l_module_name             VARCHAR2(200):='PA_CONTROL_API_PUB.Update_Staffing_Impact';
894 
895 BEGIN
896 
897         x_return_status := FND_API.G_RET_STS_SUCCESS;
898         x_msg_count := 0;
899         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
900 
901         IF l_debug_mode = 'Y' THEN
902                 PA_DEBUG.set_curr_function(p_function => 'Update_Staffing_Impact', p_debug_mode => l_debug_mode);
903         END IF;
904 
905         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
906                 FND_MSG_PUB.initialize;
907         END IF;
908 
909         IF p_commit = FND_API.G_TRUE THEN
910                 savepoint UPDATE_STAFFING_IMPACT_SVPT;
911         END IF;
912 
913         IF l_debug_mode = 'Y' THEN
914                 pa_debug.write(l_module_name, 'Start of Update_Staffing_Impact', l_debug_level3);
915         END IF;
916 
917           /*validating the CI_ID for null value*/
918          if  p_ci_id is null or p_ci_id = G_PA_MISS_NUM then
919                  PA_UTILS.ADD_MESSAGE(p_app_short_name  => 'PA',
920                                       p_msg_name        => 'PA_CI_MISS_CI_ID');
921                  if l_debug_mode = 'Y' then
922                         pa_debug.g_err_stage:= 'The ci_id is null';
923                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
924                  end if;
925                  raise FND_API.G_EXC_ERROR;
926         end if;
927 
928 
929 
930         /*Calling the private API
931         This update_impacts will do all the necessary validations and call
932         other procedure to insert the details*/
933          if l_debug_mode = 'Y' then
934                pa_debug.g_err_stage:= 'Before Calling the Private API PA_CONTROL_API_PVT.update_impacts';
935                pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
936         end if;
937 
938          PA_CONTROL_API_PVT.update_impacts(
939                 p_ci_id                   => p_ci_id       ,
940                 p_impact_type_code        => l_impact_type_code,
941                 p_impact_description      => p_impact_description,
942                 p_api_version_number      => p_api_version_number ,
943                 p_mode                    => 'UPDATE',
944                 x_ci_impact_id            => l_ci_impact_id,
945                 x_return_status           => x_return_status,
946                 x_msg_count               => x_msg_count,
947                 x_msg_data                => x_msg_data
948                 );
949 
950            IF p_commit = FND_API.G_TRUE and  x_return_status = FND_API.G_RET_STS_SUCCESS THEN
951                  COMMIT;
952            END IF;
953             --Reset the stack
954          if l_debug_mode = 'Y' then
955                   Pa_Debug.reset_curr_function;
956          end if;
957 
958 Exception
959 when FND_API.G_EXC_ERROR then
960 
961          x_return_status := fnd_api.g_ret_sts_error;
962          l_msg_count := fnd_msg_pub.count_msg;
963 
964           IF p_commit = 'T' THEN
965             ROLLBACK to UPDATE_STAFFING_IMPACT_SVPT;
966           END IF;
967 
968          if l_msg_count = 1 then
969               pa_interface_utils_pub.get_messages
970                             (p_encoded        => fnd_api.g_false,
971                              p_msg_index      => 1,
972                              p_msg_count      => l_msg_count ,
973                              p_msg_data       => l_msg_data ,
974                              p_data           => l_data,
975                              p_msg_index_out  => l_msg_index_out );
976               x_msg_data  :=  l_data;
977               x_msg_count := l_msg_count;
978          else
979               x_msg_count := l_msg_count;
980          end if;
981 
982          --Reset the stack
983          if l_debug_mode = 'Y' then
984                   Pa_Debug.reset_curr_function;
985          end if;
986 
987 when others then
988 
989          x_return_status := fnd_api.g_ret_sts_unexp_error;
990          x_msg_data      := substr(SQLERRM,1,240);
991          IF p_commit = FND_API.G_TRUE THEN
992                 ROLLBACK TO UPDATE_STAFFING_IMPACT_SVPT;
993          END IF;
994 
995 
996          fnd_msg_pub.add_exc_msg ( p_pkg_name        => 'PA_CONTROL_API_PUB',
997                                    p_procedure_name  => 'UPDATE_STAFFING_IMPACT',
998                                    p_error_text      => x_msg_data);
999         x_msg_count     := FND_MSG_PUB.count_msg;
1000         --Reset the stack
1001          if l_debug_mode = 'Y' then
1002                   Pa_Debug.reset_curr_function;
1003          end if;
1004 
1005 End Update_Staffing_Impact;
1006 
1007 
1008 /*Procedure to update or implement the Contract impact*/
1009 Procedure Update_Contract_Impact(
1010         p_commit               IN         VARCHAR2 := FND_API.G_FALSE,
1011         p_init_msg_list        IN         VARCHAR2 := FND_API.G_FALSE,
1012         p_api_version_number   IN         NUMBER,
1013         x_return_status        OUT NOCOPY VARCHAR2,
1014         x_msg_count            OUT NOCOPY NUMBER,
1015         x_msg_data             OUT NOCOPY VARCHAR2,
1016         p_ci_id                IN          NUMBER   := G_PA_MISS_NUM,
1017         p_impact_description   IN          VARCHAR2 := G_PA_MISS_CHAR
1018         )
1019 IS
1020  --Declaring local Variables
1021         l_impact_type_code              pa_ci_impacts.impact_type_code%TYPE:='CONTRACT';
1022         l_ci_impact_id pa_ci_impacts.ci_impact_id%Type;
1023         l_msg_count                              NUMBER := 0;
1024         l_data                                   VARCHAR2(2000);
1025         l_msg_data                               VARCHAR2(2000);
1026         l_msg_index_out                          NUMBER;
1027         l_module_name             VARCHAR2(200):='PA_CONTROL_API_PUB.Update_Contract_Impact';
1028 
1029 BEGIN
1030 
1031         x_return_status := FND_API.G_RET_STS_SUCCESS;
1032         x_msg_count := 0;
1033         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
1034 
1035         IF l_debug_mode = 'Y' THEN
1036                 PA_DEBUG.set_curr_function(p_function => 'Update_Contract_Impact', p_debug_mode => l_debug_mode);
1037         END IF;
1038 
1039         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
1040                 FND_MSG_PUB.initialize;
1041         END IF;
1042 
1043         IF p_commit = FND_API.G_TRUE THEN
1044                 savepoint UPDATE_CONTRACT_IMPACT_SVPT;
1045         END IF;
1046 
1047         IF l_debug_mode = 'Y' THEN
1048                 pa_debug.write(l_module_name, 'Start of Update_Contract_Impact', l_debug_level3);
1049         END IF;
1050 
1051           /*validating the CI_ID for null value*/
1052         if  p_ci_id is null or p_ci_id = G_PA_MISS_NUM then
1053                  PA_UTILS.ADD_MESSAGE(p_app_short_name  => 'PA',
1054                                       p_msg_name        => 'PA_CI_MISS_CI_ID');
1055                  if l_debug_mode = 'Y' then
1056                         pa_debug.g_err_stage:= 'The ci_id is null';
1057                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1058                  end if;
1059                  raise FND_API.G_EXC_ERROR;
1060         end if;
1061 
1062 
1063         /*Calling the private API
1064         This update_impacts will do all the necessary validations and call
1065         other procedure to insert the details*/
1066          if l_debug_mode = 'Y' then
1067                pa_debug.g_err_stage:= 'Before Calling the Private API PA_CONTROL_API_PVT.update_impacts';
1068                pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1069         end if;
1070 
1071          PA_CONTROL_API_PVT.update_impacts(
1072                 p_ci_id                   => p_ci_id       ,
1073                 p_impact_type_code        => l_impact_type_code,
1074                 p_impact_description      => p_impact_description,
1075                 p_api_version_number      => p_api_version_number ,
1076                 p_mode                    => 'UPDATE',
1077                 x_ci_impact_id            => l_ci_impact_id,
1078                 x_return_status           => x_return_status,
1079                 x_msg_count               => x_msg_count,
1080                 x_msg_data                => x_msg_data
1081                 );
1082 
1083          IF p_commit = FND_API.G_TRUE and  x_return_status = FND_API.G_RET_STS_SUCCESS THEN
1084                 COMMIT;
1085          END IF;
1086             --Reset the stack
1087          if l_debug_mode = 'Y' then
1088                   Pa_Debug.reset_curr_function;
1089          end if;
1090 
1091 Exception
1092 when FND_API.G_EXC_ERROR then
1093 
1094          x_return_status := fnd_api.g_ret_sts_error;
1095          l_msg_count := fnd_msg_pub.count_msg;
1096 
1097           IF p_commit = 'T' THEN
1098             ROLLBACK to UPDATE_CONTRACT_IMPACT_SVPT;
1099           END IF;
1100 
1101          if l_msg_count = 1 then
1102               pa_interface_utils_pub.get_messages
1103                             (p_encoded        => fnd_api.g_false,
1104                              p_msg_index      => 1,
1105                              p_msg_count      => l_msg_count ,
1106                              p_msg_data       => l_msg_data ,
1107                              p_data           => l_data,
1108                              p_msg_index_out  => l_msg_index_out );
1109               x_msg_data  :=  l_data;
1110               x_msg_count := l_msg_count;
1111          else
1112               x_msg_count := l_msg_count;
1113          end if;
1114 
1115          --Reset the stack
1116          if l_debug_mode = 'Y' then
1117                   Pa_Debug.reset_curr_function;
1118          end if;
1119 
1120 when others then
1121 
1122          x_return_status := fnd_api.g_ret_sts_unexp_error;
1123          x_msg_data      := substr(SQLERRM,1,240);
1124          IF p_commit = FND_API.G_TRUE THEN
1125                 ROLLBACK TO UPDATE_CONTRACT_IMPACT_SVPT;
1126          END IF;
1127 
1128          fnd_msg_pub.add_exc_msg ( p_pkg_name        => 'PA_CONTROL_API_PUB',
1129                                    p_procedure_name  => 'UPDATE_CONTRACT_IMPACT',
1130                                    p_error_text      => x_msg_data);
1131         x_msg_count     := FND_MSG_PUB.count_msg;
1132         --Reset the stack
1133          if l_debug_mode = 'Y' then
1134                   Pa_Debug.reset_curr_function;
1135          end if;
1136 
1137 End Update_Contract_Impact;
1138 
1139 
1140 /*Procedure to update or implement the Other impact*/
1141 Procedure   Update_Other_Impact(
1142         p_commit               IN         VARCHAR2 := FND_API.G_FALSE,
1143         p_init_msg_list        IN         VARCHAR2 := FND_API.G_FALSE,
1144         p_api_version_number   IN         NUMBER,
1145         x_return_status        OUT NOCOPY VARCHAR2,
1146         x_msg_count            OUT NOCOPY NUMBER,
1147         x_msg_data             OUT NOCOPY VARCHAR2,
1148         p_ci_id                IN          NUMBER   := G_PA_MISS_NUM,
1149         p_impact_description   IN          VARCHAR2 := G_PA_MISS_CHAR
1150         )
1151 IS
1152  --Declaring local Variables
1153         l_impact_type_code       pa_ci_impacts.impact_type_code%TYPE:='OTHER';
1154         l_ci_impact_id           pa_ci_impacts.ci_impact_id%Type;
1155         l_msg_count                              NUMBER := 0;
1156         l_data                                   VARCHAR2(2000);
1157         l_msg_data                               VARCHAR2(2000);
1158         l_msg_index_out                          NUMBER;
1159         l_module_name             VARCHAR2(200):='PA_CONTROL_API_PUB.Update_Other_Impact';
1160 
1161 BEGIN
1162 
1163         x_return_status := FND_API.G_RET_STS_SUCCESS;
1164         x_msg_count := 0;
1165         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
1166 
1167         IF l_debug_mode = 'Y' THEN
1168                 PA_DEBUG.set_curr_function(p_function => 'Update_Other_Impact', p_debug_mode => l_debug_mode);
1169         END IF;
1170 
1171         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
1172                 FND_MSG_PUB.initialize;
1173         END IF;
1174 
1175         IF p_commit = FND_API.G_TRUE THEN
1176                 savepoint UPDATE_OTHER_IMPACT_SVPT;
1177         END IF;
1178 
1179         IF l_debug_mode = 'Y' THEN
1180                 pa_debug.write(l_module_name, 'Start of Update_Other_Impact', l_debug_level3);
1181         END IF;
1182 
1183           /*validating the CI_ID for null value*/
1184         if  p_ci_id is null or p_ci_id = G_PA_MISS_NUM then
1185                  PA_UTILS.ADD_MESSAGE(p_app_short_name  => 'PA',
1186                                       p_msg_name        => 'PA_CI_MISS_CI_ID');
1187                  if l_debug_mode = 'Y' then
1188                         pa_debug.g_err_stage:= 'The ci_id is null';
1189                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1190                  end if;
1191                  raise FND_API.G_EXC_ERROR;
1192         end if;
1193 
1194 
1195 
1196         /*Calling the private API
1197         This update_impacts will do all the necessary validations and call
1198         other procedure to insert the details*/
1199          if l_debug_mode = 'Y' then
1200                pa_debug.g_err_stage:= 'Before Calling the Private API PA_CONTROL_API_PVT.update_impacts';
1201                pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1202         end if;
1203 
1204          PA_CONTROL_API_PVT.update_impacts(
1205                 p_ci_id                   => p_ci_id       ,
1206                 p_impact_type_code        => l_impact_type_code,
1207                 p_impact_description      => p_impact_description,
1208                 p_api_version_number      => p_api_version_number ,
1209                 p_mode                    => 'UPDATE',
1210                 x_ci_impact_id            => l_ci_impact_id,
1211                 x_return_status           => x_return_status,
1212                 x_msg_count               => x_msg_count,
1213                 x_msg_data                => x_msg_data
1214                 );
1215 
1216            IF p_commit = FND_API.G_TRUE and  x_return_status = FND_API.G_RET_STS_SUCCESS THEN
1217                  COMMIT;
1218            END IF;
1219             --Reset the stack
1220          if l_debug_mode = 'Y' then
1221                   Pa_Debug.reset_curr_function;
1222          end if;
1223 
1224 Exception
1225 when FND_API.G_EXC_ERROR then
1226 
1227          x_return_status := fnd_api.g_ret_sts_error;
1228          l_msg_count := fnd_msg_pub.count_msg;
1229 
1230           IF p_commit = 'T' THEN
1231             ROLLBACK to UPDATE_OTHER_IMPACT_SVPT;
1232           END IF;
1233 
1234          if l_msg_count = 1 then
1235               pa_interface_utils_pub.get_messages
1236                             (p_encoded        => fnd_api.g_false,
1237                              p_msg_index      => 1,
1238                              p_msg_count      => l_msg_count ,
1239                              p_msg_data       => l_msg_data ,
1240                              p_data           => l_data,
1241                              p_msg_index_out  => l_msg_index_out );
1242               x_msg_data  :=  l_data;
1243               x_msg_count := l_msg_count;
1244          else
1245               x_msg_count := l_msg_count;
1246          end if;
1247 
1248          --Reset the stack
1249          if l_debug_mode = 'Y' then
1250                   Pa_Debug.reset_curr_function;
1251          end if;
1252 
1253 when others then
1254 
1255          x_return_status := fnd_api.g_ret_sts_unexp_error;
1256          x_msg_data      := substr(SQLERRM,1,240);
1257          IF p_commit = FND_API.G_TRUE THEN
1258                 ROLLBACK TO UPDATE_OTHER_IMPACT_SVPT;
1259          END IF;
1260 
1261 
1262          fnd_msg_pub.add_exc_msg ( p_pkg_name        => 'PA_CONTROL_API_PUB',
1263                                    p_procedure_name  => 'Update_Other_Impact',
1264                                    p_error_text      => x_msg_data);
1265         x_msg_count     := FND_MSG_PUB.count_msg;
1266         --Reset the stack
1267          if l_debug_mode = 'Y' then
1268                   Pa_Debug.reset_curr_function;
1269          end if;
1270 End Update_Other_Impact;
1271 
1272 Procedure  Update_Supplier_Impact (
1273         p_commit               IN         VARCHAR2 := FND_API.G_FALSE,
1274         p_init_msg_list        IN         VARCHAR2 := FND_API.G_FALSE,
1275         p_api_version_number   IN         NUMBER,
1276         x_return_status        OUT NOCOPY VARCHAR2,
1277         x_msg_count            OUT NOCOPY NUMBER,
1278         x_msg_data             OUT NOCOPY VARCHAR2,
1279         p_ci_id                IN          NUMBER   := G_PA_MISS_NUM,
1280         p_impact_description   IN          VARCHAR2 := G_PA_MISS_CHAR
1281         )
1282 IS
1283         --Declaring local Variables
1284         l_impact_type_code        pa_ci_impacts.impact_type_code%TYPE:='SUPPLIER';
1285         l_ci_impact_id            pa_ci_impacts.ci_impact_id%Type;
1286         l_msg_count                              NUMBER := 0;
1287         l_data                                   VARCHAR2(2000);
1288         l_msg_data                               VARCHAR2(2000);
1289         l_msg_index_out                          NUMBER;
1290         l_module_name             VARCHAR2(200):='PA_CONTROL_API_PUB.Update_Supplier_Impact';
1291 
1292 BEGIN
1293 
1294         x_return_status := FND_API.G_RET_STS_SUCCESS;
1295         x_msg_count := 0;
1296         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
1297 
1298         IF l_debug_mode = 'Y' THEN
1299                 PA_DEBUG.set_curr_function(p_function => 'Update_Supplier_Impact', p_debug_mode => l_debug_mode);
1300         END IF;
1301 
1302         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
1303                 FND_MSG_PUB.initialize;
1304         END IF;
1305 
1306         IF p_commit = FND_API.G_TRUE THEN
1307                 savepoint UPDATE_SUPPLIER_IMPACT_SVPT;
1308         END IF;
1309 
1310         IF l_debug_mode = 'Y' THEN
1311                 pa_debug.write(l_module_name, 'Start of Update_Supplier_Impact', l_debug_level3);
1312         END IF;
1313 
1314           /*validating the CI_ID for null value*/
1315         if  p_ci_id is null or p_ci_id = G_PA_MISS_NUM then
1316                  PA_UTILS.ADD_MESSAGE(p_app_short_name  => 'PA',
1317                                       p_msg_name        => 'PA_CI_MISS_CI_ID');
1318                  if l_debug_mode = 'Y' then
1319                         pa_debug.g_err_stage:= 'The ci_id is null';
1320                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1321                  end if;
1322                  raise FND_API.G_EXC_ERROR;
1323         end if;
1324 
1325 
1326         /*Calling the private API
1327         This update_impacts will do all the necessary validations and call
1328         other procedure to insert the details*/
1329          if l_debug_mode = 'Y' then
1330                pa_debug.g_err_stage:= 'Before Calling the Private API PA_CONTROL_API_PVT.update_impacts';
1331                pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1332         end if;
1333          PA_CONTROL_API_PVT.update_impacts(
1334                 p_ci_id                   => p_ci_id       ,
1335                 p_impact_type_code        => l_impact_type_code,
1336                 p_impact_description      => p_impact_description,
1337                 p_api_version_number      => p_api_version_number ,
1338                 p_mode                    => 'UPDATE',
1339                 x_ci_impact_id            => l_ci_impact_id,
1340                 x_return_status           => x_return_status,
1341                 x_msg_count               => x_msg_count,
1342                 x_msg_data                => x_msg_data
1343                 );
1344 
1345            IF p_commit = FND_API.G_TRUE and  x_return_status = FND_API.G_RET_STS_SUCCESS THEN
1346                  COMMIT;
1347            END IF;
1348             --Reset the stack
1349          if l_debug_mode = 'Y' then
1350                   Pa_Debug.reset_curr_function;
1351          end if;
1352 
1353 Exception
1354 when FND_API.G_EXC_ERROR then
1355 
1356          x_return_status := fnd_api.g_ret_sts_error;
1357          l_msg_count := fnd_msg_pub.count_msg;
1358 
1359           IF p_commit = 'T' THEN
1360             ROLLBACK to UPDATE_SUPPLIER_IMPACT_SVPT;
1361           END IF;
1362 
1363          if l_msg_count = 1 then
1364               pa_interface_utils_pub.get_messages
1365                             (p_encoded        => fnd_api.g_false,
1366                              p_msg_index      => 1,
1367                              p_msg_count      => l_msg_count ,
1368                              p_msg_data       => l_msg_data ,
1369                              p_data           => l_data,
1370                              p_msg_index_out  => l_msg_index_out );
1371               x_msg_data  :=  l_data;
1372               x_msg_count := l_msg_count;
1373          else
1374               x_msg_count := l_msg_count;
1375          end if;
1376 
1377          --Reset the stack
1378          if l_debug_mode = 'Y' then
1379                   Pa_Debug.reset_curr_function;
1380          end if;
1381 
1382 when others then
1383 
1384          x_return_status := fnd_api.g_ret_sts_unexp_error;
1385          x_msg_data      := substr(SQLERRM,1,240);
1386          IF p_commit = FND_API.G_TRUE THEN
1387                 ROLLBACK TO UPDATE_SUPPLIER_IMPACT_SVPT;
1388          END IF;
1389 
1390          fnd_msg_pub.add_exc_msg ( p_pkg_name        => 'PA_CONTROL_API_PUB',
1391                                    p_procedure_name  => 'Update_Supplier_Impact',
1392                                    p_error_text      => x_msg_data);
1393         x_msg_count     := FND_MSG_PUB.count_msg;
1394         --Reset the stack
1395          if l_debug_mode = 'Y' then
1396                   Pa_Debug.reset_curr_function;
1397          end if;
1398 
1399 END Update_Supplier_Impact;
1400 
1401 
1402 
1403 
1404 Procedure Delete_Supplier_Impact_Details
1405 		(
1406 		P_COMMIT              IN      VARCHAR2  := FND_API.G_FALSE,
1407 		P_INIT_MSG_LIST       IN      VARCHAR2  := FND_API.G_FALSE,
1408 		P_API_VERSION_NUMBER  IN      NUMBER,
1409 		X_RETURN_STATUS	      OUT  NOCOPY  VARCHAR2,
1410 		X_MSG_COUNT	      OUT  NOCOPY  NUMBER,
1411 		X_MSG_DATA 	      OUT  NOCOPY  VARCHAR2,
1412 		P_CI_TRANSACTION_ID   IN      NUMBER)
1413 
1414 IS
1415     -- Local Variables.
1416         l_Msg_Count             NUMBER := 0;
1417         l_Data                  VARCHAR2(2000);
1418         l_Msg_Data              VARCHAR2(2000);
1419         l_Msg_Index_Out         NUMBER;
1420 	l_module_name           VARCHAR2(200):='PA_CONTROL_API_PUB.Delete_Supplier_Impact_Details';
1421         -- End: Local Variables.
1422 
1423         l_chk_status_ctrl       VARCHAR2(1);
1424 	l_ci_id                 pa_control_items.ci_id%type;
1425 	l_transaction_id        pa_ci_supplier_details.ci_transaction_id%type;
1426         l_status_code           pa_control_items.status_code%type;
1427 
1428 	CURSOR Check_Valid_CI_TRANS_ID  IS
1429         SELECT ci_transaction_id ,ci_id
1430         FROM pa_ci_supplier_details
1431         WHERE ci_transaction_id = P_CI_TRANSACTION_ID;
1432 
1433         CURSOR c_get_status(c_ci_id NUMBER)  IS
1434 	SELECT status_code
1435 	FROM pa_control_items
1436 	WHERE ci_id = c_ci_id;
1437 
1438 BEGIN
1439         -- Initialize the Error Stack.
1440         PA_DEBUG.Init_Err_Stack ('PA_CONTROL_API_PUB.Delete_Supplier_Impact_Details');
1441 
1442         -- Initialize the Return Status to Success.
1443         x_Return_Status := FND_API.G_RET_STS_SUCCESS;
1444         x_Msg_Count := 0;
1445 
1446         -- Clear the Global PL/SQL Message table.
1447         IF (FND_API.To_Boolean (p_Init_Msg_List)) THEN
1448                 FND_MSG_PUB.Initialize;
1449         END IF;
1450 
1451 	 IF p_commit = FND_API.G_TRUE THEN
1452                 savepoint DELETE_SUPP_DETAIL_SVPT;
1453         END IF;
1454 
1455         -- Check for the null p_ci_transaction_id value.
1456         -- report Error.
1457         IF P_CI_TRANSACTION_ID IS NULL  THEN
1458                 -- Add message to the Error Stack that Ci_Id is NULL.
1459                 PA_UTILS.Add_Message (p_App_Short_Name => 'PA'
1460                         , p_Msg_Name => 'PA_CI_MISS_TRANS_ID'
1461                         );
1462 		X_RETURN_STATUS := FND_API.G_RET_STS_ERROR;
1463                 -- Raise the Invalid Argument exception.
1464                 RAISE FND_API.G_EXC_ERROR;
1465         else
1466 		open Check_Valid_CI_TRANS_ID;
1467 		fetch Check_Valid_CI_TRANS_ID into l_transaction_id,l_ci_id;
1468 		if Check_Valid_CI_TRANS_ID%notfound then
1469 			 -- Add message to the Error Stack that Ci_Id is NULL.
1470 			PA_UTILS.Add_Message (p_App_Short_Name => 'PA'
1471 					    , p_Msg_Name => 'PA_CI_INV_TRANS_ID'
1472 					      );
1473 			close Check_Valid_CI_TRANS_ID;
1474 			X_RETURN_STATUS := FND_API.G_RET_STS_ERROR;
1475 		        -- Raise the Invalid Argument exception.
1476 	                RAISE FND_API.G_EXC_ERROR;
1477 		end if;
1478 		close Check_Valid_CI_TRANS_ID;
1479 	END IF;
1480 
1481 	    /*Security check for the CI_ID UpdateAccess*/
1482        if 'T' <> Pa_ci_security_pkg.check_update_access (l_ci_id) then
1483              PA_UTILS.add_Message( p_app_short_name => 'PA'
1484                                   ,p_msg_name       => 'PA_CI_NO_UPDATE_ACCESS');
1485              x_return_status := FND_API.G_RET_STS_ERROR;
1486              if l_debug_mode = 'Y' then
1487                     pa_debug.g_err_stage:= 'the CI_ID does not have the update access';
1488                     pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1489              end if;
1490               raise FND_API.G_EXC_ERROR ;
1491        end if;
1492 
1493  /* Check for the status control: check whether the action  CONTROL_ITEM_ALLOW_UPDATE is allowed on the current status of the issue. */
1494         open c_get_status(l_ci_id);
1495 	fetch c_get_status into l_status_code;
1496 	if c_get_status%notfound then
1497 		 PA_UTILS.Add_Message( p_app_short_name => 'PA'
1498                                       ,p_msg_name       =>'PA_CI_INV_CI_ID');
1499                  if l_debug_mode = 'Y' then
1500                           pa_debug.g_err_stage:= 'the ci_id is invalid';
1501                           pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1502                  end if;
1503                  x_return_status := FND_API.G_RET_STS_ERROR;
1504 		 close c_get_status;
1505 		 raise  FND_API.G_EXC_ERROR ;
1506 	end if;
1507 	close c_get_status;
1508 
1509 	  l_chk_status_ctrl :=  pa_control_items_utils.CheckCIActionAllowed('CONTROL_ITEM', l_status_code, 'CONTROL_ITEM_ALLOW_UPDATE');
1510 	  IF (l_chk_status_ctrl = 'N') THEN
1511 		       PA_UTILS.ADD_MESSAGE('PA', 'PA_CI_NO_ALLOW_UPDATE');
1512 	              RAISE FND_API.G_EXC_ERROR;
1513 	  END IF;
1514 
1515 
1516   IF l_debug_mode = 'Y' THEN
1517         pa_debug.write(l_module_name, 'After call to pa_control_items_utils.CheckCIActionAllowed', l_debug_level3);
1518   END IF;
1519 
1520 
1521 	if X_RETURN_STATUS = FND_API.g_Ret_Sts_Success then
1522 		--Calling the api to delete the supplier details
1523 		PA_CI_SUPPLIER_PKG.delete_row (p_ci_transaction_id => P_CI_TRANSACTION_ID);
1524 	end if;
1525 
1526 	 IF p_commit = FND_API.G_TRUE and  x_return_status = FND_API.G_RET_STS_SUCCESS THEN
1527                  COMMIT;
1528         END IF;
1529          --Reset the stack
1530          if l_debug_mode = 'Y' then
1531                   Pa_Debug.reset_curr_function;
1532          end if;
1533 Exception
1534 when FND_API.G_EXC_ERROR then
1535 
1536         x_return_status := FND_API.G_RET_STS_ERROR;
1537         l_msg_count := FND_MSG_PUB.count_msg;
1538 
1539         IF p_commit = FND_API.G_TRUE THEN
1540                 ROLLBACK TO DELETE_SUPP_DETAIL_SVPT;
1541         END IF;
1542         if l_msg_count = 1 then
1543               pa_interface_utils_pub.get_messages
1544                             (p_encoded        => fnd_api.g_false,
1545                              p_msg_index      => 1,
1546                              p_msg_count      => l_msg_count ,
1547                              p_msg_data       => l_msg_data ,
1548                              p_data           => l_data,
1549                              p_msg_index_out  => l_msg_index_out );
1550               x_msg_data  := l_data;
1551               x_msg_count := l_msg_count;
1552         else
1553               x_msg_count := l_msg_count;
1554         end if;
1555         --Reset the stack
1556         if l_debug_mode = 'Y' then
1557                  Pa_Debug.reset_curr_function;
1558         end if;
1559 
1560 when others then
1561         x_return_status := fnd_api.g_ret_sts_unexp_error;
1562         x_msg_data      := substr(SQLERRM,1,240);
1563 
1564         IF p_commit = FND_API.G_TRUE THEN
1565                ROLLBACK TO ADD_CONTRACT_IMPACT_SVPT;
1566         END IF;
1567         fnd_msg_pub.add_exc_msg ( p_pkg_name        => 'PA_CONTROL_API_PUB',
1568                                    p_procedure_name  => 'Delete_Supplier_Impact_Details',
1569                                    p_error_text      => x_msg_data);
1570         x_msg_count     := FND_MSG_PUB.count_msg;
1571         if l_debug_mode = 'Y' then
1572                  pa_debug.reset_err_stack;
1573          end if;
1574 End Delete_Supplier_Impact_Details;
1575 
1576 
1577 
1578 /* Update Progress API to update the progress and resolution details are also included
1579    to add the resolution*/
1580 Procedure Update_Progress(
1581                         p_commit                IN    VARCHAR2 := FND_API.G_FALSE,
1582                         p_init_msg_list         IN    VARCHAR2 := FND_API.G_FALSE,
1583                         p_api_version_number    IN    NUMBER,
1584                         x_return_status         OUT NOCOPY  VARCHAR2,
1585                         x_msg_count             OUT NOCOPY  NUMBER,
1586                         x_msg_data              OUT NOCOPY  VARCHAR2,
1587                         p_ci_id                 IN    NUMBER   := G_PA_MISS_NUM,
1588                         p_ci_status_code        IN    VARCHAR2 := G_PA_MISS_CHAR,
1589   		        p_status_comment        IN    VARCHAR2 := G_PA_MISS_CHAR,
1590                         p_as_of_date            IN    DATE     := G_PA_MISS_DATE,
1591                         p_progress_status_code  IN    VARCHAR2 := G_PA_MISS_CHAR,
1592                         p_progress_overview     IN    VARCHAR2 := G_PA_MISS_CHAR,
1593                         p_resolution_code       IN    VARCHAR2 := G_PA_MISS_CHAR,
1594                         p_resolution_comment    IN    VARCHAR2 := G_PA_MISS_CHAR
1595                         )
1596 IS
1597 
1598 /* Cursor to get the control item data*/
1599 cursor c_get_control_item_data
1600 is
1601     select *
1602     from pa_control_items
1603     where ci_id = p_ci_id;
1604 
1605 /*cursor to check the progress code is valid or not*/
1606 cursor c_check_Progress_code
1607 is
1608     Select project_status_code,
1609     project_status_name
1610     From   pa_project_statuses
1611     where (trunc(sysdate) between nvl(start_date_active, trunc(sysdate))
1612     and nvl(end_date_active, trunc(sysdate))
1613     and status_type = 'PROGRESS')
1614     and project_status_code = p_progress_status_code;  --need to clarify whether this is a name or code
1615 
1616 /*cursor to check the resolution code is valid or not*/
1617 cursor c_get_resolution_codes(c_ci_type_id pa_control_items.ci_type_id%type)
1618 is
1619    select
1620    cat.class_category class_category,
1621    cat.class_code description,
1622    cat.class_code_id code
1623    from pa_class_codes cat,
1624    pa_ci_types_b typ
1625    where trunc(sysdate) between cat.start_date_active and
1626    nvl(cat.end_date_active,trunc(sysdate))
1627    and typ.ci_type_id=c_ci_type_id
1628    and cat.class_category=typ.resolution_category
1629    and cat.class_code_id = p_resolution_code;
1630 
1631 
1632 CURSOR c_info IS
1633     SELECT cit.ci_type_class_code,
1634            cit.approval_required_flag,
1635              s.next_allowable_status_flag
1636       FROM pa_control_items c,
1637            pa_ci_types_b cit,
1638            pa_project_statuses s
1639      WHERE c.ci_id = p_ci_id
1640        AND c.status_code = s.project_status_code
1641        AND c.ci_type_id =cit.ci_type_id
1642        AND s.status_type = 'CONTROL_ITEM';
1643 
1644 
1645 
1646  l_data              VARCHAR2(2000);
1647  l_msg_data          VARCHAR2(2000);
1648  l_msg_index_out     NUMBER;
1649  l_module_name       VARCHAR2(200):='PA_CONTROL_API_PUB.Update_Progress';
1650  l_msg_count         NUMBER := 0;
1651 
1652  l_stmnt             VARCHAR2(5000);
1653  l_sel_clause        VARCHAR2(300);
1654  l_from_clause       VARCHAR2(300);
1655  l_where             VARCHAR2(4000);
1656  l_where1            VARCHAR2(2000);
1657  l_cursor            NUMBER;
1658  l_rows              NUMBER;
1659  l_rows1             NUMBER;
1660  l_ci_status_code_1                  pa_project_statuses.project_status_code%TYPE;
1661 
1662  cp    c_get_control_item_data%ROWTYPE;
1663  c_get_resolution_codes_rec   c_get_resolution_codes%ROWTYPE;
1664  c_check_Progress_code_rec    c_check_Progress_code%ROWTYPE;
1665 
1666  check_s   VARCHAR2(1);  --For security checks.
1667 
1668 --declaring pa_control_item local variables
1669  l_last_modified_by_id          pa_control_items.last_modified_by_id%TYPE;
1670  l_curr_status_code             pa_control_items.status_code%TYPE;
1671  l_ci_status_code               pa_control_items.status_code%TYPE;
1672  l_record_version_number        pa_control_items.record_version_number%TYPE;
1673  l_summary                      pa_control_items.summary%TYPE;
1674  l_description                  pa_control_items.description%TYPE;
1675  l_owner_id                     pa_control_items.owner_id%TYPE;
1676  l_classification_code_id       pa_control_items.classification_code_id%TYPE;
1677  l_reason_code_id               pa_control_items.reason_code_id%TYPE;
1678  l_object_id                    pa_control_items.object_id%TYPE;
1679  l_object_type                  pa_control_items.object_type%TYPE;
1680  l_date_required                pa_control_items.date_required%TYPE;
1681  l_priority_code                pa_control_items.priority_code%TYPE;
1682  l_effort_level_code            pa_control_items.effort_level_code%TYPE;
1683  l_price                        pa_control_items.price%TYPE;
1684  l_price_currency_code          pa_control_items.price_currency_code%TYPE;
1685  l_source_type_code             pa_control_items.source_type_code%TYPE;
1686  l_source_comment               pa_control_items.source_comment%TYPE;
1687  l_source_number                pa_control_items.source_number%TYPE;
1688  l_source_date_received         pa_control_items.source_date_received%TYPE;
1689  l_source_organization          pa_control_items.source_organization%TYPE;
1690  l_source_person                pa_control_items.source_person%TYPE;
1691  l_as_of_date                   pa_control_items.progress_as_of_date%TYPE;
1692  l_ci_number                    pa_control_items.ci_number%TYPE;
1693  l_progress_status_code         pa_control_items.progress_status_code%TYPE;
1694  l_progress_overview            pa_control_items.status_overview%TYPE;
1695  l_resolution_code_id           pa_control_items.resolution_code_id%TYPE;
1696  l_resolution_comment           pa_control_items.resolution%TYPE;
1697  l_date_closed                  pa_control_items.date_closed%TYPE;
1698  l_closed_by_id                 pa_control_items.closed_by_id%TYPE;
1699  l_project_id                   pa_control_items.project_id%TYPE;
1700  l_ci_type_id                   pa_control_items.ci_type_id%TYPE;
1701  l_attribute_category           pa_control_items.attribute_category%TYPE;
1702  l_attribute1                   pa_control_items.attribute1%TYPE;
1703  l_attribute2                   pa_control_items.attribute2%TYPE;
1704  l_attribute3                   pa_control_items.attribute3%TYPE;
1705  l_attribute4                   pa_control_items.attribute4%TYPE;
1706  l_attribute5                   pa_control_items.attribute5%TYPE;
1707  l_attribute6                   pa_control_items.attribute6%TYPE;
1708  l_attribute7                   pa_control_items.attribute7%TYPE;
1709  l_attribute8                   pa_control_items.attribute8%TYPE;
1710  l_attribute9                   pa_control_items.attribute9%TYPE;
1711  l_attribute10                  pa_control_items.attribute10%TYPE;
1712  l_attribute11                  pa_control_items.attribute11%TYPE;
1713  l_attribute12                  pa_control_items.attribute12%TYPE;
1714  l_attribute13                  pa_control_items.attribute13%TYPE;
1715  l_attribute14                  pa_control_items.attribute14%TYPE;
1716  l_attribute15                  pa_control_items.attribute15%TYPE;
1717 
1718  l_projectid                 pa_control_items.project_id%TYPE;
1719  l_proj_status_code          pa_project_statuses.project_system_status_code%TYPE;
1720  l_citypeclasscode           pa_ci_types_b.ci_type_class_Code%TYPE;
1721 
1722  l_curr_system_status        pa_project_statuses.project_system_status_code%TYPE;
1723  l_next_allow_status_flag    pa_project_statuses.next_allowable_status_flag%TYPE;
1724  l_ci_type_class_code        pa_ci_types_b.ci_type_class_code%TYPE;
1725  l_approval_required_flag    pa_ci_types_b.approval_required_flag%TYPE;
1726 
1727  l_enforce_security          VARCHAR2(1) := 'Y';
1728  l_start_wf                  VARCHAR2(1) := 'Y';
1729  l_num_of_actions            NUMBER;
1730  l_max_msg_count             NUMBER := FND_API.G_MISS_NUM;
1731  l_status_change_flag        VARCHAR2(1) := 'N';
1732  l_validate_only             VARCHAR2(1) := FND_API.g_false;
1733  l_recordversionnumber       NUMBER(15);
1734  l_ci_id_error_flag          VARCHAR2(1) := null;
1735  l_resolution_check          VARCHAR2(10) := 'AMG';
1736  l_resolution_req            VARCHAR2(10) := 'N';
1737  l_resolution_req_cls        VARCHAR2(10) := 'N';
1738  l_to_status_flag            VARCHAR2(10) := 'Y';
1739 
1740 
1741 Begin
1742         x_return_status := FND_API.G_RET_STS_SUCCESS;
1743         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
1744         IF l_debug_mode = 'Y' THEN
1745               PA_DEBUG.set_curr_function(p_function => 'UPDATE_PROGRESS', p_debug_mode => l_debug_mode);
1746         END IF;
1747 
1748         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
1749                 FND_MSG_PUB.initialize;
1750         END IF;
1751 
1752         IF p_commit = FND_API.G_TRUE THEN
1753                  savepoint UPDATE_PROGRESS_SVPT;
1754         END IF;
1755 
1756         IF l_debug_mode = 'Y' THEN
1757                 pa_debug.write(l_module_name, 'Start of Update Progress ', l_debug_level3);
1758         END IF;
1759 
1760         x_msg_count := 0;
1761 
1762         if p_ci_id is null or p_ci_id = G_PA_MISS_NUM then
1763                 PA_UTILS.Add_Message( p_app_short_name => 'PA'
1764                                      ,p_msg_name       => 'PA_CI_MISS_CI_ID');
1765                 if l_debug_mode = 'Y' then
1766                        pa_debug.g_err_stage:= 'the ci_id is null';
1767                        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1768                 end if;
1769                 x_return_status := FND_API.G_RET_STS_ERROR;
1770                 --raise FND_API.G_EXC_ERROR;
1771                 l_ci_id_error_flag := 'Y';
1772         else
1773                 open c_get_control_item_data;
1774                 fetch c_get_control_item_data into cp;
1775                 if c_get_control_item_data%NOTFOUND then
1776 
1777                         PA_UTILS.Add_Message( p_app_short_name => 'PA'
1778                                              ,p_msg_name       => 'PA_CI_INV_CI_ID');
1779                         if l_debug_mode = 'Y' then
1780                                pa_debug.g_err_stage:= 'the ci_id is invalid';
1781                                pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1782                         end if;
1783                         x_return_status := FND_API.G_RET_STS_ERROR;
1784                         close c_get_control_item_data;
1785                         --raise FND_API.G_EXC_ERROR;
1786                         l_ci_id_error_flag := 'Y';
1787                 else
1788 
1789                       l_curr_status_code        := cp.status_code;
1790                       l_record_version_number   := cp.record_version_number;
1791                       l_summary                 := cp.summary;
1792                       l_description             := cp.description;
1793                       l_owner_id                := cp.owner_id;
1794                       l_classification_code_id  := cp.classification_code_id;
1795                       l_reason_code_id          := cp.reason_code_id;
1796                       l_object_id               := cp.object_id;
1797                       l_object_type             := cp.object_type;
1798                       l_date_required           := cp.date_required;
1799                       l_priority_code           := cp.priority_code;
1800                       l_effort_level_code       := cp.effort_level_code;
1801                       l_price                   := cp.price;
1802                       l_price_currency_code     := cp.price_currency_code;
1803                       l_source_type_code        := cp.source_type_code;
1804                       l_source_comment          := cp.source_comment;
1805                       l_source_number           := cp.source_number;
1806                       l_source_date_received    := cp.source_date_received;
1807                       l_source_organization     := cp.source_organization;
1808                       l_source_person           := cp.source_person;
1809                       l_as_of_date              := cp.progress_as_of_date;
1810                       l_ci_number               := cp.ci_number;
1811                       l_progress_status_code    := cp.progress_status_code;
1812                       l_progress_overview       := cp.status_overview;
1813                       l_resolution_code_id      := cp.resolution_code_id;
1814                       l_resolution_comment      := cp.resolution;
1815                       l_date_closed             := cp.date_closed;
1816                       l_closed_by_id            := cp.closed_by_id;
1817                       l_project_id              := cp.project_id;
1818                       l_ci_type_id              := cp.ci_type_id;
1819                       l_attribute_category      := cp.attribute_category;
1820                       l_attribute1              := cp.attribute1;
1821                       l_attribute2              := cp.attribute2;
1822                       l_attribute3              := cp.attribute3;
1823                       l_attribute4              := cp.attribute4;
1824                       l_attribute5              := cp.attribute5;
1825                       l_attribute6              := cp.attribute6;
1826                       l_attribute7              := cp.attribute7;
1827                       l_attribute8              := cp.attribute8;
1828                       l_attribute9              := cp.attribute9;
1829                       l_attribute10             := cp.attribute10;
1830                       l_attribute11             := cp.attribute11;
1831                       l_attribute12             := cp.attribute12;
1832                       l_attribute13             := cp.attribute13;
1833                       l_attribute14             := cp.attribute14;
1834                       l_attribute15             := cp.attribute15;
1835                         close c_get_control_item_data;
1836                 end if;
1837         end if;
1838 
1839 
1840 
1841         /*check the security access only when ci_id is not invalid bcoz we need to
1842         validate other parameters as we are not raising any exceptions (All the
1843         conditions depending on the ci_id will be checked only when ci_id is valid.)*/
1844 
1845       if l_ci_id_error_flag is null then
1846 
1847         /*Check if the user can update the item. This requires the user to be owner or
1848         to have project authority or to have open actions and status controls are satisfied.
1849         The page will not be updateable when the current status has approval workflow attached*/
1850 
1851          /*Security check for the CI_ID UpdateAccess*/
1852           check_s  := pa_ci_security_pkg.check_update_access(p_ci_id);
1853 
1854         if 'T' <> check_s then
1855                PA_UTILS.add_Message( p_app_short_name => 'PA'
1856                                     ,p_msg_name       => 'PA_CI_NO_UPDATE_ACCESS');
1857                x_return_status := FND_API.G_RET_STS_ERROR;
1858                if l_debug_mode = 'Y' then
1859                       pa_debug.g_err_stage:= 'the CI_ID does not have the update access';
1860                       pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1861                end if;
1862                --raise FND_API.G_EXC_ERROR ;
1863 
1864         end if;
1865 
1866 
1867 
1868         /* cursor to get the project system status code to pass the value in checkciActionallowed as
1869         user statuses are not considered in pa_control_items status code*/
1870           -- Open Cursor Get_CI_Data and fetch the data into out local variables.
1871         OPEN get_ci_data (p_ci_id);
1872         FETCH Get_CI_Data INTO l_projectid, l_proj_status_code, l_citypeclasscode, l_recordversionnumber;
1873         -- If NO_DATA_FOUND then report Error.
1874         IF (Get_CI_Data%NOTFOUND) THEN
1875                 -- Code to Report Error and Return.
1876                 x_return_status := FND_API.G_RET_STS_ERROR;
1877 --                RAISE FND_API.G_EXC_ERROR;
1878         END IF;
1879         CLOSE Get_CI_Data;
1880 
1881 
1882 
1883          /* Check for the status control: check whether the action CONTROL_ITEM_ALLOW_UPDST is allowed on the current status of the issue. */
1884 
1885        check_s   :=  PA_CONTROL_ITEMS_UTILS.CheckCIActionAllowed ('CONTROL_ITEM', l_curr_status_code , 'CONTROL_ITEM_ALLOW_UPDATE');
1886 
1887        if check_s <> 'Y' then
1888                 PA_UTILS.add_Message( p_app_short_name => 'PA'
1889                                      ,p_msg_name       => 'PA_CI_NO_ALLOW_UPDATE');
1890                 x_return_status := FND_API.G_RET_STS_ERROR;
1891                 if l_debug_mode = 'Y' then
1892                        pa_debug.g_err_stage:= 'the CI_ID does not have the update access for the current status';
1893                        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1894                 end if;
1895                -- raise FND_API.G_EXC_ERROR ;
1896        end if;
1897 
1898 
1899   end if; -- end for if l_ci_id_error_flag is null then
1900 
1901 
1902 
1903 /*Validating the p_ci_status_code -
1904   This is taken from Update_issue procedure. So If any changes happen in update_issue then this code needs to
1905   be looked in to*/
1906 
1907  l_curr_system_status :=  PA_CONTROL_ITEMS_UTILS.getSystemStatus(l_curr_status_code);
1908 
1909  IF p_ci_status_code = G_PA_MISS_CHAR THEN
1910        l_ci_status_code := l_curr_status_code;
1911   ELSIF p_ci_status_code IS NOT NULL THEN
1912           l_ci_status_code := p_ci_status_code;
1913 
1914           OPEN c_info;
1915           FETCH c_info INTO l_ci_type_class_code, l_approval_required_flag, l_next_allow_status_flag;
1916           CLOSE c_info;
1917 
1918           l_sel_clause  := ' SELECT ps.project_status_code ';
1919           l_from_clause := ' FROM pa_obj_status_lists osl, pa_status_list_items sli, pa_project_statuses ps ';
1920           l_where       := ' WHERE osl.status_type = '||'''CONTROL_ITEM'''||
1921                              ' AND osl.object_type = '||'''PA_CI_TYPES'''||
1922                              ' AND osl.object_id = '||l_ci_type_id||
1923                              ' AND osl.status_list_id = sli.status_list_id'||
1924                              ' AND sli.project_status_code = ps.project_status_code'||
1925                              ' AND ps.project_status_code <> '||''''||l_curr_status_code||''''||
1926                              ' AND ps.status_type = osl.status_type'||
1927                              ' AND trunc(sysdate) between nvl(ps.start_date_active, trunc(sysdate)) and nvl(ps.end_date_active, trunc(sysdate))'||
1928                              ' AND (('||''''||l_next_allow_status_flag||''''||' = '||'''N'''||' and 1=2)'||
1929                                   ' OR '||
1930                                   ' ('||''''||l_next_allow_status_flag||''''||' = '||'''S'''||
1931                                   ' and ps.project_status_code in (select project_status_code from pa_project_statuses where status_type = '||'''CONTROL_ITEM'''||
1932                                   ' and project_system_status_code in ( select next_allowable_status_code from pa_next_allow_statuses where status_code = '||
1933                                   ''''||l_curr_status_code||''''||')))'||
1934                                   ' OR '||
1935                                   ' ('||''''||l_next_allow_status_flag||''''||' = '||'''U'''||
1936                                   ' and ps.project_status_code in (select next_allowable_status_code from pa_next_allow_statuses where status_code = '||''''||
1937                                   l_curr_status_code||''''||'))'||
1938                                   ' OR '||
1939                                   ' ('||''''||l_next_allow_status_flag||''''||' = '||'''A'''||
1940                                   ' and ps.project_status_code in (select project_status_code from pa_project_statuses where status_type = '||'''CONTROL_ITEM'''||
1941                                   ' and project_system_status_code in (select next_allowable_status_code from pa_next_allow_statuses where status_code = '||
1942                                   ''''||l_curr_system_status||''''||'))))'||
1943                               ' AND ps.project_status_code not in (select wf_success_status_code from pa_project_statuses where status_type = '||
1944                               '''CONTROL_ITEM'''||' and wf_success_status_code is not null and wf_failure_status_code is not null)'||
1945                               ' AND ps.project_status_code not in (select wf_failure_status_code from pa_project_statuses where status_type = '||
1946                               '''CONTROL_ITEM'''||' and wf_success_status_code is not null and wf_failure_status_code is not null)'||
1947                               ' AND decode(ps.project_system_status_code, '||'''CI_CANCELED'''||
1948                               ', nvl(pa_control_items_utils.CheckCIActionAllowed('||'''CONTROL_ITEM'''||', '||''''||l_curr_status_code||''''||', '||
1949                               '''CONTROL_ITEM_ALLOW_CANCEL'''||', null),'||'''N'''||' ),'||'''Y'''||' ) = '||'''Y'''||
1950                               ' AND decode(ps.project_system_status_code,'||'''CI_WORKING'''||
1951                               ' ,nvl(pa_control_items_utils.CheckCIActionAllowed('||'''CONTROL_ITEM'''||', '||''''||l_curr_status_code||''''||', '||
1952                               '''CONTROL_ITEM_ALLOW_REWORK'''||' ,null),'||'''N'''||' ),'||'''Y'''||' ) = '||'''Y'''||
1953                               ' AND nvl(pa_control_items_utils.CheckCIActionAllowed('||'''CONTROL_ITEM'''||', '||''''||l_curr_status_code||''''||', '||
1954                               '''CONTROL_ITEM_ALLOW_UPDST'''||' ,null),'||'''N'''||' ) = '||'''Y'''||
1955                               ' AND decode(ps.project_system_status_code,'||'''CI_DRAFT'''||
1956                               ' ,decode('||''''||l_curr_system_status||''''||', '||'''CI_DRAFT'''||', '||
1957                               '''Y'''||' ,'||'''N'''||' ),'||'''Y'''||' ) = '||'''Y'''||
1958                               ' AND ps.project_status_code = '||''''||p_ci_status_code||'''';
1959 
1960           IF (l_ci_type_class_code = 'ISSUE' AND l_approval_required_flag = 'N') THEN
1961                 l_where1 := ' AND  ps.project_status_code not in (select project_status_code from pa_project_statuses where status_type = '||
1962                            '''CONTROL_ITEM'''||' and enable_wf_flag = '||'''Y'''||
1963                            ' and wf_success_status_code is not null and wf_failure_status_code is not null) ';
1964           END IF;
1965 
1966           IF (l_ci_type_class_code = 'ISSUE' AND l_approval_required_flag = 'Y' AND l_curr_system_status = 'CI_WORKING') THEN
1967                 l_where1 := ' AND  ps.project_system_status_code <> '||'''CI_CLOSED''';
1968           END IF;
1969 
1970           IF (l_ci_type_class_code = 'CHANGE_REQUEST') THEN
1971                 l_where1 := ' AND  ps.project_system_status_code <> '||'''CI_CLOSED''';
1972           END IF;
1973 
1974           IF (l_ci_type_class_code = 'CHANGE_ORDER' AND l_curr_system_status = 'CI_WORKING') THEN
1975                 l_where1 := ' AND ps.project_system_status_code <> '||'''CI_CLOSED''';
1976           END IF;
1977 
1978           l_stmnt := l_sel_clause || l_from_clause || l_where || l_where1;
1979 
1980           IF l_debug_mode = 'Y' THEN
1981                pa_debug.write(l_module_name, l_stmnt, l_debug_level3);
1982           END IF;
1983 
1984     l_cursor := dbms_sql.open_cursor;
1985 
1986     DBMS_SQL.PARSE(l_cursor, l_stmnt, DBMS_SQL.v7);
1987     DBMS_SQL.DEFINE_COLUMN(l_cursor, 1, l_ci_status_code_1, 30);
1988 
1989     l_rows := DBMS_SQL.EXECUTE(l_cursor);
1990 
1991     IF (l_rows < 0) THEN
1992                PA_UTILS.Add_Message( p_app_short_name => 'PA'
1993                                     ,p_msg_name       => 'PA_TO_STATUS_INVALID');
1994                x_return_status := FND_API.G_RET_STS_ERROR;
1995                l_to_status_flag := 'N';
1996     ELSE
1997        l_rows1 := DBMS_SQL.FETCH_ROWS(l_cursor);
1998 
1999        if l_rows1 > 0 THEN
2000             DBMS_SQL.COLUMN_VALUE(l_cursor, 1, l_ci_status_code_1);
2001             l_ci_status_code := l_ci_status_code_1;
2002        else
2003 	     PA_UTILS.Add_Message( p_app_short_name => 'PA'
2004                                   ,p_msg_name       => 'PA_TO_STATUS_INVALID');
2005              x_return_status := FND_API.G_RET_STS_ERROR;
2006              l_to_status_flag := 'N';
2007        end if;
2008 
2009     END IF;
2010     IF dbms_sql.is_open(l_cursor) THEN
2011          dbms_sql.close_cursor(l_cursor);
2012     END IF;
2013   ELSIF p_ci_status_code IS NULL THEN
2014           l_ci_status_code := p_ci_status_code;
2015           PA_UTILS.ADD_MESSAGE('PA', 'PA_CI_NULL_STATUS');
2016           x_return_status := FND_API.G_RET_STS_ERROR;
2017 	  l_to_status_flag := 'N';
2018   END IF;
2019 
2020 /*end of status_code validation*/
2021 
2022 
2023         --get hz_parties.party_id of the logged in user
2024         l_last_modified_by_id := PA_CONTROL_ITEMS_UTILS.GetPartyId(fnd_global.user_id );
2025 
2026          if p_as_of_date <> G_PA_MISS_DATE and p_as_of_date is not null then
2027                 l_as_of_date := p_as_of_date;
2028          else
2029                 l_as_of_date := SYSDATE;
2030          end if;
2031 
2032         if  p_progress_status_code <> G_PA_MISS_CHAR and p_progress_status_code is not null then
2033                 open c_check_Progress_code;
2034                 fetch c_check_Progress_code into c_check_Progress_code_rec;
2035                 if c_check_Progress_code%notfound then
2036                         PA_UTILS.add_Message( p_app_short_name => 'PA'
2037                                             ,p_msg_name       => 'PA_CI_INV_PRG_CODE');
2038                         x_return_status := FND_API.G_RET_STS_ERROR;
2039                         if l_debug_mode = 'Y' then
2040                               pa_debug.g_err_stage:= 'Invalid progress Code is passed';
2041                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2042                         end if;
2043                         close c_check_Progress_code;
2044                 else
2045                         l_progress_status_code := p_progress_status_code;
2046                         close c_check_Progress_code;
2047                 end if;
2048         elsif p_progress_status_code is null then
2049                  PA_UTILS.add_Message( p_app_short_name => 'PA'
2050                                     ,p_msg_name       => 'PA_PROGRESS_STATUS_NULL');
2051                  if l_debug_mode = 'Y' then
2052                          pa_debug.g_err_stage:= 'Progress Code is null';
2053                          pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2054                  end if;
2055                  x_return_status := FND_API.G_RET_STS_ERROR;
2056         end if;
2057 
2058         if p_resolution_code <> G_PA_MISS_CHAR and p_resolution_code is not null then
2059                 open c_get_resolution_codes(l_ci_type_id);
2060                 fetch c_get_resolution_codes into c_get_resolution_codes_rec;
2061                         if c_get_resolution_codes%notfound then
2062                                 PA_UTILS.add_Message( p_app_short_name => 'PA'
2063                                                      ,p_msg_name       => 'PA_CI_RESOLUTION_INV');
2064                                 x_return_status := FND_API.G_RET_STS_ERROR;
2065                                 if l_debug_mode = 'Y' then
2066                                       pa_debug.g_err_stage:= 'the Resolution Code is invalid';
2067                                       pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2068                                 end if;
2069                                 close c_get_resolution_codes;
2070                                 --raise FND_API.G_EXC_ERROR ;
2071                         else
2072                                 l_resolution_code_id := p_resolution_code;
2073                                 close c_get_resolution_codes;
2074                         end if;
2075         elsif p_resolution_code is null then
2076                 l_resolution_code_id := null;
2077         end if;
2078 
2079         if p_progress_overview <> G_PA_MISS_CHAR and p_progress_overview is not null then
2080                 l_progress_overview := p_progress_overview;
2081         elsif p_progress_overview is null then
2082                 l_progress_overview := null;
2083         end if;
2084 
2085 
2086         if p_resolution_comment <> G_PA_MISS_CHAR and p_resolution_comment is not null then
2087                 l_resolution_comment:=p_resolution_comment;
2088         elsif p_resolution_comment is null then
2089                 l_resolution_comment := null;
2090         end if;
2091 
2092 IF (l_curr_status_code is NOT NULL AND
2093       l_ci_status_code   is NOT NULL AND
2094       l_curr_status_code <> l_ci_status_code AND
2095       l_to_status_flag = 'Y' and x_return_status = FND_API.G_RET_STS_SUCCESS ) THEN
2096 
2097 	 IF l_debug_mode = 'Y' THEN
2098    	      pa_debug.write(l_module_name, 'Before call to PA_CONTROL_ITEMS_UTILS.ChangeCIStatusValidate', l_debug_level3);
2099          END IF;
2100 
2101          PA_CONTROL_ITEMS_UTILS.ChangeCIStatusValidate (
2102                                   p_init_msg_list      => p_init_msg_list
2103                                  ,p_commit             => p_commit
2104                                  ,p_validate_only      => l_validate_only
2105                                  ,p_max_msg_count      => l_max_msg_count
2106                                  ,p_ci_id              => p_ci_id
2107                                  ,p_status             => p_ci_status_code
2108                                  ,p_enforce_security   => l_enforce_security
2109                                  ,p_resolution_check   => l_resolution_check
2110                                  ,x_resolution_req     => l_resolution_req
2111                                  ,x_resolution_req_cls => l_resolution_req_cls
2112                                  ,x_start_wf           => l_start_wf
2113                                  ,x_new_status         => l_ci_status_code
2114                                  ,x_num_of_actions     => l_num_of_actions
2115                                  ,x_return_status      => x_return_status
2116                                  ,x_msg_count          => x_msg_count
2117                                  ,x_msg_data           => x_msg_data);
2118 
2119        /* l_ci_status_code gets the new status from ChangeCIStatusValidate.
2120           In case of CR/CO, if Auto Approve on Submission is enabled and while changing the status to submitted,
2121           then the new status would be the success status code defined for the workflow */
2122 
2123 	IF l_debug_mode = 'Y' THEN
2124    	     pa_debug.write(l_module_name, 'after call to PA_CONTROL_ITEMS_UTILS.ChangeCIStatusValidate: x_return_status = '||x_return_status, l_debug_level3);
2125    	     pa_debug.write(l_module_name, 'after call to PA_CONTROL_ITEMS_UTILS.ChangeCIStatusValidate: l_ci_status_code = '||l_ci_status_code, l_debug_level3);
2126         END IF;
2127 
2128         IF x_return_status = 'S' THEN
2129              l_status_change_flag := 'Y';
2130         END IF;
2131 
2132 	IF l_debug_mode = 'Y' THEN
2133    	     pa_debug.write(l_module_name, 'after call to PA_CONTROL_ITEMS_UTILS.ChangeCIStatusValidate: l_status_change_flag = '||l_status_change_flag, l_debug_level3);
2134         END IF;
2135 
2136 
2137 
2138         IF (l_resolution_req IS NOT NULL AND  l_resolution_req = 'Y') THEN
2139               IF (PA_CONTROL_ITEMS_UTILS.checkhasresolution(p_ci_id) <> 'Y'  ) THEN
2140                   IF (l_resolution_code_id IS NULL) THEN
2141                       PA_UTILS.Add_Message( p_app_short_name => 'PA'
2142                                            ,p_msg_name       => 'PA_CI_RESOLUTION_OPEN');
2143                       x_return_status := FND_API.G_RET_STS_ERROR;
2144                   END IF;
2145               ELSE
2146                   IF (l_resolution_code_id IS NULL) THEN
2147                       PA_UTILS.Add_Message( p_app_short_name => 'PA'
2148                                            ,p_msg_name       => 'PA_CI_RESOLUTION_OPEN');
2149                       x_return_status := FND_API.G_RET_STS_ERROR;
2150                   END IF;
2151               END IF;
2152         END IF;
2153 
2154         IF (l_resolution_req_cls IS NOT NULL AND  l_resolution_req_cls = 'Y') THEN
2155               IF (PA_CONTROL_ITEMS_UTILS.checkhasresolution(p_ci_id) <> 'Y'  ) THEN
2156                   IF (l_resolution_code_id IS NULL) THEN
2157                       PA_UTILS.Add_Message( p_app_short_name => 'PA'
2158                                            ,p_msg_name       => 'PA_CI_CLOSE_INV_RES');
2159                       x_return_status := FND_API.G_RET_STS_ERROR;
2160                   END IF;
2161               ELSE
2162                   IF (l_resolution_code_id IS NULL) THEN
2163                       PA_UTILS.Add_Message( p_app_short_name => 'PA'
2164                                            ,p_msg_name       => 'PA_CI_CLOSE_INV_RES');
2165                       x_return_status := FND_API.G_RET_STS_ERROR;
2166                   END IF;
2167               END IF;
2168         END IF;
2169 
2170    END IF;
2171 
2172         if l_debug_mode = 'Y' then
2173                 pa_debug.g_err_stage:= 'Before caliing the PA_CONTROL_ITEMS_PKG.UPDATE_ROW procedure';
2174                 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2175         end if;
2176 
2177 
2178          if x_return_status = FND_API.G_RET_STS_SUCCESS then
2179           PA_CONTROL_ITEMS_PKG.UPDATE_ROW(
2180                          p_ci_id                 => p_ci_id
2181                         ,p_ci_type_id            => l_ci_type_id
2182                         ,p_summary               => l_summary
2183                         ,p_status_code           => l_ci_status_code
2184                         ,p_owner_id              => l_owner_id
2185                         ,p_highlighted_flag      => null
2186                         ,p_progress_status_code  => l_progress_status_code
2187                         ,p_progress_as_of_date   => l_as_of_date
2188                         ,p_classification_code   => l_classification_code_id
2189                         ,p_reason_code           => l_reason_code_id
2190                         ,p_record_version_number => l_record_version_number
2191 
2192                         ,p_project_id            => l_project_id
2193                         ,p_last_modified_by_id   => l_last_modified_by_id
2194                         ,p_object_type           => l_object_type
2195                         ,p_object_id             => l_object_id
2196                         ,p_ci_number             => l_ci_number
2197                         ,p_date_required         => l_date_required
2198                         ,p_date_closed           => l_date_closed
2199                         ,p_closed_by_id          => l_closed_by_id
2200                         ,p_description           => l_description
2201                         ,p_status_overview       => l_progress_overview
2202                         ,p_resolution            => l_resolution_comment
2203                         ,p_resolution_code       => l_resolution_code_id
2204                         ,p_priority_code         => l_priority_code
2205                         ,p_effort_level_code     => l_effort_level_code
2206                         ,p_open_action_num       => null
2207                         ,p_price                 => l_price
2208                         ,p_price_currency_code   => l_price_currency_code
2209                         ,p_source_type_code      => l_source_type_code
2210                         ,p_source_comment        => l_source_comment
2211                         ,p_source_number         => l_source_number
2212                         ,p_source_date_received  => l_source_date_received
2213                         ,p_source_organization   => l_source_organization
2214                         ,p_source_person         => l_source_person
2215                         ,p_attribute_category    => l_attribute_category
2216                         ,p_attribute1            => l_attribute1
2217                         ,p_attribute2            => l_attribute2
2218                         ,p_attribute3            => l_attribute3
2219                         ,p_attribute4            => l_attribute4
2220                         ,p_attribute5            => l_attribute5
2221                         ,p_attribute6            => l_attribute6
2222                         ,p_attribute7            => l_attribute7
2223                         ,p_attribute8            => l_attribute8
2224                         ,p_attribute9            => l_attribute9
2225                         ,p_attribute10           => l_attribute10
2226                         ,p_attribute11           => l_attribute11
2227                         ,p_attribute12           => l_attribute12
2228                         ,p_attribute13           => l_attribute13
2229                         ,p_attribute14           => l_attribute14
2230                         ,p_attribute15           => l_attribute15
2231                         ,x_return_status         => x_return_status
2232                         ,x_msg_count             => x_msg_count
2233                         ,x_msg_data              => x_msg_data
2234                          );
2235         else
2236                 raise FND_API.G_EXC_ERROR;
2237         end if;
2238 
2239  IF (l_status_change_flag = 'Y' AND l_validate_only <> fnd_api.g_true AND x_return_status = 'S') THEN
2240 
2241 	   IF l_debug_mode = 'Y' THEN
2242    	        pa_debug.write(l_module_name, 'before call to PA_CONTROL_ITEMS_UTILS.ADD_STATUS_CHANGE_COMMENT', l_debug_level3);
2243            END IF;
2244 
2245            /* call the insert table handlers of pa_obj_status_changes and pa_ci_comments here */
2246 
2247            PA_CONTROL_ITEMS_UTILS.ADD_STATUS_CHANGE_COMMENT( p_object_type        => 'PA_CI_TYPES'
2248                                                             ,p_object_id          => p_ci_id
2249                                                             ,p_type_code          => 'CHANGE_STATUS'
2250                                                             ,p_status_type        => 'CONTROL_ITEM'
2251                                                             ,p_new_project_status => l_ci_status_code
2252                                                             ,p_old_project_status => l_curr_status_code
2253                                                             ,p_comment            => p_status_comment
2254                                                             ,x_return_status      => x_return_status
2255                                                             ,x_msg_count          => x_msg_count
2256                                                             ,x_msg_data           => x_msg_data );
2257 
2258 	   IF l_debug_mode = 'Y' THEN
2259    	        pa_debug.write(l_module_name, 'after call to PA_CONTROL_ITEMS_UTILS.ADD_STATUS_CHANGE_COMMENT', l_debug_level3);
2260            END IF;
2261 
2262            PA_CONTROL_ITEMS_UTILS.PostChangeCIStatus (
2263                                                           p_init_msg_list
2264                                                          ,p_commit
2265                                                          ,l_validate_only
2266                                                          ,l_max_msg_count
2267                                                          ,p_ci_id
2268                                                          ,l_curr_status_code
2269                                                          ,l_ci_status_code
2270                                                          ,l_start_wf
2271                                                          ,l_enforce_security
2272                                                          ,l_num_of_actions
2273                                                          ,x_return_status
2274                                                          ,x_msg_count
2275                                                          ,x_msg_data    );
2276 
2277 
2278            IF l_debug_mode = 'Y' THEN
2279                 pa_debug.write(l_module_name, 'after call to PA_CONTROL_ITEMS_UTILS.PostChangeCIStatus', l_debug_level3);
2280            END IF;
2281 
2282   END IF;
2283 
2284 
2285 
2286 
2287          IF p_commit = FND_API.G_TRUE and x_return_status = FND_API.G_RET_STS_SUCCESS THEN
2288                  COMMIT;
2289          elsif x_return_status <> FND_API.G_RET_STS_SUCCESS then
2290                 raise FND_API.G_EXC_ERROR;
2291          END IF;
2292             --Reset the stack
2293          if l_debug_mode = 'Y' then
2294                   Pa_Debug.reset_curr_function;
2295          end if;
2296 
2297 Exception
2298 when FND_API.G_EXC_ERROR then
2299 
2300          x_return_status := FND_API.G_RET_STS_ERROR;
2301          l_msg_count := fnd_msg_pub.count_msg;
2302           IF p_commit = 'T' THEN
2303             ROLLBACK to UPDATE_PROGRESS_SVPT;
2304           END IF;
2305 
2306          if l_msg_count = 1 then
2307               pa_interface_utils_pub.get_messages
2308                             (p_encoded        => fnd_api.g_false,
2309                              p_msg_index      => 1,
2310                              p_msg_count      => l_msg_count ,
2311                              p_msg_data       => l_msg_data ,
2312                              p_data           => l_data,
2313                              p_msg_index_out  => l_msg_index_out );
2314               x_msg_data  :=  l_data;
2315               x_msg_count := l_msg_count;
2316          else
2317               x_msg_count := l_msg_count;
2318          end if;
2319 
2320          --Reset the stack
2321          if l_debug_mode = 'Y' then
2322                   Pa_Debug.reset_curr_function;
2323          end if;
2324 
2325 when others then
2326          x_return_status := fnd_api.g_ret_sts_unexp_error;
2327          x_msg_data      := substr(SQLERRM,1,240);
2328          IF p_commit = FND_API.G_TRUE THEN
2329                 ROLLBACK TO UPDATE_PROGRESS_SVPT;
2330          END IF;
2331          fnd_msg_pub.add_exc_msg ( p_pkg_name        => 'PA_CONTROL_API_PUB',
2332                                    p_procedure_name  => 'Update_Progress',
2333                                    p_error_text      => x_msg_data);
2334          x_msg_count     := FND_MSG_PUB.count_msg;
2335         --Reset the stack
2336          if l_debug_mode = 'Y' then
2337                   Pa_Debug.reset_curr_function;
2338          end if;
2339 
2340 end Update_Progress;
2341 
2342 
2343 
2344 
2345 PROCEDURE CREATE_ISSUE
2346 (
2347 p_commit                                        IN VARCHAR2 := FND_API.G_FALSE,
2348 p_init_msg_list                                 IN VARCHAR2 := FND_API.G_FALSE,
2349 p_api_version_number                            IN NUMBER   := G_PA_MISS_NUM,
2350 p_orig_system_code                              IN VARCHAR2 := null,
2351 p_orig_system_reference                         IN VARCHAR2 := null,
2352 x_return_status                                 OUT NOCOPY VARCHAR2,
2353 x_msg_count                                     OUT NOCOPY NUMBER,
2354 x_msg_data                                      OUT NOCOPY VARCHAR2,
2355 x_ci_id                                         OUT NOCOPY NUMBER,
2356 x_ci_number                                     OUT NOCOPY NUMBER,
2357 p_project_id                                    IN NUMBER   := G_PA_MISS_NUM,
2358 p_project_name                                  IN VARCHAR2 := G_PA_MISS_CHAR,
2359 p_project_number                                IN VARCHAR2 := G_PA_MISS_CHAR,
2360 p_ci_type_id                                    IN NUMBER   := G_PA_MISS_NUM,
2361 p_summary                                       IN VARCHAR2,
2362 p_ci_number                                     IN VARCHAR2 := G_PA_MISS_CHAR,
2363 p_description                                   IN VARCHAR2 := G_PA_MISS_CHAR,
2364 p_status_code                                   IN VARCHAR2 := G_PA_MISS_CHAR,
2365 p_status                                        IN VARCHAR2 := G_PA_MISS_CHAR,
2366 p_owner_id                                      IN NUMBER   := G_PA_MISS_NUM,
2367 p_progress_status_code                          IN VARCHAR2 := G_PA_MISS_CHAR,
2368 p_progress_as_of_date                           IN DATE     := G_PA_MISS_DATE,
2369 p_status_overview                               IN VARCHAR2 := G_PA_MISS_CHAR,
2370 p_classification_code                           IN NUMBER,
2371 p_reason_code                                   IN NUMBER,
2372 p_object_id                                     IN NUMBER   := G_PA_MISS_NUM,
2373 p_object_type                                   IN VARCHAR2 := G_PA_MISS_CHAR,
2374 p_date_required                                 IN DATE     := G_PA_MISS_DATE,
2375 p_date_closed                                   IN DATE     := G_PA_MISS_DATE,
2376 p_closed_by_id                                  IN NUMBER   := G_PA_MISS_NUM,
2377 p_resolution                                    IN VARCHAR2 := G_PA_MISS_CHAR,
2378 p_resolution_code                               IN NUMBER   := G_PA_MISS_NUM,
2379 p_priority_code                                 IN VARCHAR2 := G_PA_MISS_CHAR,
2380 p_effort_level_code                             IN VARCHAR2 := G_PA_MISS_CHAR,
2381 p_price                                         IN NUMBER   := G_PA_MISS_NUM,
2382 p_price_currency_code                           IN VARCHAR2 := G_PA_MISS_CHAR,
2383 p_source_type_name                              IN VARCHAR2 := G_PA_MISS_CHAR,
2384 p_source_type_code                              IN VARCHAR2 := G_PA_MISS_CHAR,
2385 p_source_number                                 IN VARCHAR2 := G_PA_MISS_CHAR,
2386 p_source_comment                                IN VARCHAR2 := G_PA_MISS_CHAR,
2387 p_source_date_received                          IN DATE     := G_PA_MISS_DATE,
2388 p_source_organization                           IN VARCHAR2 := G_PA_MISS_CHAR,
2389 p_source_person                                 IN VARCHAR2 := G_PA_MISS_CHAR,
2390 p_attribute_category                            IN VARCHAR2 := G_PA_MISS_CHAR,
2391 p_attribute1                                    IN VARCHAR2 := G_PA_MISS_CHAR,
2392 p_attribute2                                    IN VARCHAR2 := G_PA_MISS_CHAR,
2393 p_attribute3                                    IN VARCHAR2 := G_PA_MISS_CHAR,
2394 p_attribute4                                    IN VARCHAR2 := G_PA_MISS_CHAR,
2395 p_attribute5                                    IN VARCHAR2 := G_PA_MISS_CHAR,
2396 p_attribute6                                    IN VARCHAR2 := G_PA_MISS_CHAR,
2397 p_attribute7                                    IN VARCHAR2 := G_PA_MISS_CHAR,
2398 p_attribute8                                    IN VARCHAR2 := G_PA_MISS_CHAR,
2399 p_attribute9                                    IN VARCHAR2 := G_PA_MISS_CHAR,
2400 p_attribute10                                   IN VARCHAR2 := G_PA_MISS_CHAR,
2401 p_attribute11                                   IN VARCHAR2 := G_PA_MISS_CHAR,
2402 p_attribute12                                   IN VARCHAR2 := G_PA_MISS_CHAR,
2403 p_attribute13                                   IN VARCHAR2 := G_PA_MISS_CHAR,
2404 p_attribute14                                   IN VARCHAR2 := G_PA_MISS_CHAR,
2405 p_attribute15                                   IN VARCHAR2 := G_PA_MISS_CHAR
2406 )
2407 IS
2408 
2409   l_module_name                            VARCHAR2(200);
2410 
2411 
2412   l_ci_type_class_code                     pa_ci_types_b.ci_type_class_code%type;
2413   l_auto_number_flag                       pa_ci_types_b.auto_number_flag%type;
2414   l_source_attrs_enabled_flag              pa_ci_types_b.source_attrs_enabled_flag%type;
2415 
2416   l_msg_count                              NUMBER := 0;
2417   l_data                                   VARCHAR2(2000);
2418   l_msg_data                               VARCHAR2(2000);
2419   l_msg_index_out                          NUMBER;
2420 
2421   l_project_id                             pa_projects_all.project_id%type;
2422   l_project_name                           pa_projects_all.name%type;
2423   l_project_number                         pa_projects_all.segment1%type;
2424   l_ci_type_id                             pa_ci_types_b.ci_type_id%type;
2425   l_summary                                pa_control_items.summary%type;
2426   l_ci_number                              pa_control_items.ci_number%type;
2427   l_description                            pa_control_items.description%type;
2428   l_status_code                            pa_project_statuses.project_status_code%type;
2429   l_status                                 pa_project_statuses.project_status_name%type;
2430   l_owner_id                               pa_control_items.owner_id%type;
2431   l_progress_status_code                   pa_control_items.progress_status_code%type;
2432   l_progress_as_of_date                    pa_control_items.progress_as_of_date%type;
2433   l_status_overview                        pa_control_items.status_overview%type;
2434   l_classification_code                    pa_control_items.classification_code_id%type;
2435   l_reason_code                            pa_control_items.reason_code_id%type;
2436   l_object_id                              pa_control_items.object_id%type;
2437   l_object_type                            pa_control_items.object_type%type;
2438   l_date_required                          pa_control_items.date_required%type;
2439   l_date_closed                            pa_control_items.date_closed%type;
2440   l_closed_by_id                           pa_control_items.closed_by_id%type;
2441   l_resolution                             pa_control_items.resolution%type;
2442   l_resolution_code                        pa_control_items.resolution_code_id%type;
2443   l_priority_code                          pa_control_items.priority_code%type;
2444   l_effort_level_code                      pa_control_items.effort_level_code%type;
2445   l_price                                  pa_control_items.price%type;
2446   l_price_currency_code                    pa_control_items.price_currency_code%type;
2447   l_source_type_name                       pa_lookups.meaning%type;
2448   l_source_type_code                       pa_control_items.source_type_code%type;
2449   l_source_number                          pa_control_items.source_number%type;
2450   l_source_comment                         pa_control_items.source_comment%type;
2451   l_source_date_received                   pa_control_items.source_date_received%type;
2452   l_source_organization                    pa_control_items.source_organization%type;
2453   l_source_person                          pa_control_items.source_person%type;
2454   l_attribute_category                     pa_control_items.attribute_category%type;
2455   l_attribute1                             pa_control_items.attribute1%type;
2456   l_attribute2                             pa_control_items.attribute1%type;
2457   l_attribute3                             pa_control_items.attribute1%type;
2458   l_attribute4                             pa_control_items.attribute1%type;
2459   l_attribute5                             pa_control_items.attribute1%type;
2460   l_attribute6                             pa_control_items.attribute1%type;
2461   l_attribute7                             pa_control_items.attribute1%type;
2462   l_attribute8                             pa_control_items.attribute1%type;
2463   l_attribute9                             pa_control_items.attribute1%type;
2464   l_attribute10                            pa_control_items.attribute1%type;
2465   l_attribute11                            pa_control_items.attribute1%type;
2466   l_attribute12                            pa_control_items.attribute1%type;
2467   l_attribute13                            pa_control_items.attribute1%type;
2468   l_attribute14                            pa_control_items.attribute1%type;
2469   l_attribute15                            pa_control_items.attribute1%type;
2470   l_class_code                             constant varchar2(20) := 'ISSUE';
2471 
2472 BEGIN
2473 
2474   -- initialize the return status to success
2475   x_return_status := fnd_api.g_ret_sts_success;
2476   x_msg_count := 0;
2477 
2478   l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
2479   l_module_name :=  'create_issue' || g_module_name;
2480 
2481   if l_debug_mode = 'Y' then
2482           pa_debug.set_curr_function(p_function => 'pa_control_api_pub.create_issue', p_debug_mode => l_debug_mode);
2483   end if;
2484 
2485   if fnd_api.to_boolean(nvl(p_init_msg_list, fnd_api.g_true)) then
2486           fnd_msg_pub.initialize;
2487   end if;
2488 
2489   if p_commit = fnd_api.g_true then
2490           savepoint create_issue;
2491   end if;
2492 
2493   if l_debug_mode = 'Y' then
2494           pa_debug.write(l_module_name, 'start of create_issue', l_debug_level3);
2495   end if;
2496 
2497   --handle the miss_char and null values
2498   if(p_project_id is null or p_project_id = G_PA_MISS_NUM) then
2499      l_project_id := null;
2500   else
2501      l_project_id := p_project_id;
2502   end if;
2503 
2504     if(p_project_name is null or p_project_name = G_PA_MISS_CHAR) then
2505      l_project_name := null;
2506   else
2507      l_project_name := p_project_name;
2508   end if;
2509 
2510   if(p_project_number is null or p_project_number = G_PA_MISS_CHAR) then
2511      l_project_number := null;
2512   else
2513      l_project_number := p_project_number;
2514   end if;
2515 
2516   if(p_ci_type_id is null or p_ci_type_id = G_PA_MISS_NUM) then
2517      l_ci_type_id := null;
2518   else
2519      l_ci_type_id := p_ci_type_id;
2520   end if;
2521 
2522   if(p_summary is null) then
2523      l_summary := null;
2524   else
2525      l_summary := p_summary;
2526   end if;
2527 
2528   if(p_ci_number is null or p_ci_number = G_PA_MISS_CHAR) then
2529      l_ci_number := null;
2530   else
2531      l_ci_number := p_ci_number;
2532   end if;
2533 
2534   if(p_description is null or p_description = G_PA_MISS_CHAR) then
2535      l_description := null;
2536   else
2537      l_description := p_description;
2538   end if;
2539 
2540   if(p_status_code is null or p_status_code = G_PA_MISS_CHAR) then
2541      l_status_code := null;
2542   else
2543      l_status_code := p_status_code;
2544   end if;
2545 
2546   if(p_status is null or p_status = G_PA_MISS_CHAR) then
2547      l_status := null;
2548   else
2549      l_status := p_status;
2550   end if;
2551 
2552   if(p_owner_id is null or p_owner_id = G_PA_MISS_NUM) then
2553      l_owner_id := null;
2554   else
2555      l_owner_id := p_owner_id;
2556   end if;
2557 
2558   if(p_progress_status_code is null or p_progress_status_code = G_PA_MISS_CHAR) then
2559      l_progress_status_code := null;
2560   else
2561      l_progress_status_code := p_progress_status_code;
2562   end if;
2563 
2564   if(p_progress_as_of_date is null or p_progress_as_of_date = G_PA_MISS_DATE) then
2565      l_progress_as_of_date := null;
2566   else
2567      l_progress_as_of_date := p_progress_as_of_date;
2568   end if;
2569 
2570   if(p_status_overview is null or p_status_overview = G_PA_MISS_CHAR) then
2571      l_status_overview := null;
2572   else
2573      l_status_overview := p_status_overview;
2574   end if;
2575 
2576   if(p_classification_code is null) then
2577      l_classification_code := null;
2578   else
2579      l_classification_code := p_classification_code;
2580   end if;
2581 
2582   if(p_reason_code is null) then
2583      l_reason_code := null;
2584   else
2585      l_reason_code := p_reason_code;
2586   end if;
2587 
2588   if(p_object_id is null or p_object_id = G_PA_MISS_NUM) then
2589      l_object_id := null;
2590   else
2591      l_object_id := p_object_id;
2592   end if;
2593 
2594   if(p_object_type is null or p_object_type = G_PA_MISS_CHAR) then
2595      l_object_type := null;
2596   else
2597      l_object_type := p_object_type;
2598   end if;
2599 
2600   if(p_date_required is null or p_date_required = G_PA_MISS_DATE) then
2601      l_date_required := null;
2602   else
2603      l_date_required := p_date_required;
2604   end if;
2605 
2606   if(p_date_closed is null or p_date_closed = G_PA_MISS_DATE) then
2607      l_date_closed := null;
2608   else
2609      l_date_closed := p_date_closed;
2610   end if;
2611 
2612   if(p_closed_by_id is null or p_closed_by_id = G_PA_MISS_NUM) then
2613      l_closed_by_id := null;
2614   else
2615      l_closed_by_id := p_closed_by_id;
2616   end if;
2617 
2618   if(p_resolution is null or p_resolution = G_PA_MISS_CHAR) then
2619      l_resolution := null;
2620   else
2621      l_resolution := p_resolution;
2622   end if;
2623 
2624   if(p_resolution_code is null or p_resolution_code = G_PA_MISS_NUM) then
2625      l_resolution_code := null;
2626   else
2627      l_resolution_code := p_resolution_code;
2628   end if;
2629 
2630   if(p_priority_code is null or p_priority_code = G_PA_MISS_CHAR) then
2631      l_priority_code := null;
2632   else
2633      l_priority_code := p_priority_code;
2634   end if;
2635 
2636   if(p_effort_level_code is null or p_effort_level_code = G_PA_MISS_CHAR) then
2637      l_effort_level_code := null;
2638   else
2639      l_effort_level_code := p_effort_level_code;
2640   end if;
2641 
2642   if(p_price is null or p_price = G_PA_MISS_NUM) then
2643      l_price := null;
2644   else
2645      l_price := p_price;
2646   end if;
2647 
2648   if(p_price_currency_code is null or p_price_currency_code = G_PA_MISS_CHAR) then
2649      l_price_currency_code := null;
2650   else
2651      l_price_currency_code := p_price_currency_code;
2652   end if;
2653 
2654   if(p_source_type_name is null or p_source_type_name = G_PA_MISS_CHAR) then
2655      l_source_type_name := null;
2656   else
2657      l_source_type_name := p_source_type_name;
2658   end if;
2659 
2660   if(p_source_type_code is null or p_source_type_code = G_PA_MISS_CHAR) then
2661      l_source_type_code := null;
2662   else
2663      l_source_type_code := p_source_type_code;
2664   end if;
2665 
2666   if(p_source_number is null or p_source_number = G_PA_MISS_CHAR) then
2667      l_source_number := null;
2668   else
2669      l_source_number := p_source_number;
2670   end if;
2671 
2672   if(p_source_comment is null or p_source_comment = G_PA_MISS_CHAR) then
2673      l_source_comment := null;
2674   else
2675      l_source_comment := p_source_comment;
2676   end if;
2677 
2678   if(p_source_date_received is null or p_source_date_received = G_PA_MISS_DATE) then
2679      l_source_date_received := null;
2680   else
2681      l_source_date_received := p_source_date_received;
2682   end if;
2683 
2684   if(p_source_organization is null or p_source_organization = G_PA_MISS_CHAR) then
2685      l_source_organization := null;
2686   else
2687      l_source_organization := p_source_organization;
2688   end if;
2689 
2690   if(p_source_person is null or p_source_person = G_PA_MISS_CHAR) then
2691      l_source_person := null;
2692   else
2693      l_source_person := p_source_person;
2694   end if;
2695 
2696   if(p_attribute_category is null or p_attribute_category = G_PA_MISS_CHAR) then
2697      l_attribute_category := null;
2698   else
2699      l_attribute_category := p_attribute_category;
2700   end if;
2701 
2702   if(p_attribute1 is null or p_attribute1 = G_PA_MISS_CHAR) then
2703      l_attribute1 := null;
2704   else
2705      l_attribute1 := p_attribute1;
2706   end if;
2707 
2708   if(p_attribute2 is null or p_attribute2 = G_PA_MISS_CHAR) then
2709      l_attribute2 := null;
2710   else
2711      l_attribute2 := p_attribute2;
2712   end if;
2713 
2714   if(p_attribute3 is null or p_attribute3 = G_PA_MISS_CHAR) then
2715      l_attribute3 := null;
2716   else
2717      l_attribute3 := p_attribute3;
2718   end if;
2719 
2720   if(p_attribute4 is null or p_attribute4 = G_PA_MISS_CHAR) then
2721      l_attribute4 := null;
2722   else
2723      l_attribute4 := p_attribute4;
2724   end if;
2725 
2726   if(p_attribute5 is null or p_attribute5 = G_PA_MISS_CHAR) then
2727      l_attribute5 := null;
2728   else
2729      l_attribute5 := p_attribute5;
2730   end if;
2731 
2732   if(p_attribute6 is null or p_attribute6 = G_PA_MISS_CHAR) then
2733      l_attribute6 := null;
2734   else
2735      l_attribute6 := p_attribute6;
2736   end if;
2737 
2738   if(p_attribute7 is null or p_attribute7 = G_PA_MISS_CHAR) then
2739      l_attribute7 := null;
2740   else
2741      l_attribute7 := p_attribute7;
2742   end if;
2743 
2744   if(p_attribute8 is null or p_attribute8 = G_PA_MISS_CHAR) then
2745      l_attribute8 := null;
2746   else
2747      l_attribute8 := p_attribute8;
2748   end if;
2749 
2750   if(p_attribute9 is null or p_attribute9 = G_PA_MISS_CHAR) then
2751      l_attribute9 := null;
2752   else
2753      l_attribute9 := p_attribute9;
2754   end if;
2755 
2756   if(p_attribute10 is null or p_attribute10 = G_PA_MISS_CHAR) then
2757      l_attribute10 := null;
2758   else
2759      l_attribute10 := p_attribute10;
2760   end if;
2761 
2762   if(p_attribute11 is null or p_attribute11 = G_PA_MISS_CHAR) then
2763      l_attribute11 := null;
2764   else
2765      l_attribute11 := p_attribute11;
2766   end if;
2767 
2768   if(p_attribute12 is null or p_attribute12 = G_PA_MISS_CHAR) then
2769      l_attribute12 := null;
2770   else
2771      l_attribute12 := p_attribute12;
2772   end if;
2773 
2774   if(p_attribute13 is null or p_attribute13 = G_PA_MISS_CHAR) then
2775      l_attribute13 := null;
2776   else
2777      l_attribute13 := p_attribute13;
2778   end if;
2779 
2780   if(p_attribute14 is null or p_attribute14 = G_PA_MISS_CHAR) then
2781      l_attribute14 := null;
2782   else
2783      l_attribute14 := p_attribute14;
2784   end if;
2785 
2786   if(p_attribute15 is null or p_attribute15 = G_PA_MISS_CHAR) then
2787      l_attribute15 := null;
2788   else
2789      l_attribute15 := p_attribute15;
2790   end if;
2791 
2792 
2793   if l_debug_mode = 'Y' then
2794       pa_debug.g_err_stage:= 'calling check_create_ci_allowed';
2795       pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2796   end if;
2797 
2798   PA_CONTROL_API_PVT.check_create_ci_allowed(
2799                                               p_project_id                      =>  l_project_id
2800                                              ,p_project_name                    =>  l_project_name
2801                                              ,p_project_number                  =>  l_project_number
2802                                              ,p_ci_type_class_code              =>  l_class_code
2803                                              ,p_ci_type_id                      =>  l_ci_type_id
2804                                              ,x_ci_type_class_code              =>  l_ci_type_class_code
2805                                              ,x_auto_number_flag                =>  l_auto_number_flag
2806                                              ,x_source_attrs_enabled_flag       =>  l_source_attrs_enabled_flag
2807                                              ,x_return_status                   =>  x_return_status
2808                                              ,x_msg_count                       =>  x_msg_count
2809                                              ,x_msg_data                        =>  x_msg_data
2810                                              );
2811 
2812   if l_debug_mode = 'Y' then
2813       pa_debug.g_err_stage:= 'After calling check_create_ciallowed';
2814       pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2815   end if;
2816 /*Need to get the details on p_api_version_number, p_orig_system_code and p_orig_system_code and write the code which uses these */
2817 /*p_orig_system_code and p_orig_system_reference will be passsed by users
2818  and What ever user gives those will get inserted in the table as it is. */
2819   if l_debug_mode = 'Y' then
2820       pa_debug.g_err_stage:= 'about to call validate_param_and_create';
2821       pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2822   end if;
2823 
2824   PA_CONTROL_API_PVT.validate_param_and_create(
2825                                                 p_orig_system_code              =>    p_orig_system_code
2826                                                ,p_orig_system_reference         =>    p_orig_system_reference
2827                                                ,p_project_id                    =>    l_project_id
2828                                                ,p_ci_type_id                    =>    l_ci_type_id
2829                                                ,p_auto_number_flag              =>    l_auto_number_flag
2830                                                ,p_source_attrs_enabled_flag     =>    l_source_attrs_enabled_flag
2831                                                ,p_ci_type_class_code            =>    l_ci_type_class_code
2832                                                ,p_summary                       =>    l_summary
2833                                                ,p_ci_number                     =>    l_ci_number
2834                                                ,p_description                   =>    l_description
2835                                                ,p_status_code                   =>    l_status_code
2836                                                ,p_status                        =>    l_status
2837                                                ,p_owner_id                      =>    l_owner_id
2838                                                ,p_progress_status_code          =>    l_progress_status_code
2839                                                ,p_progress_as_of_date           =>    l_progress_as_of_date
2840                                                ,p_status_overview               =>    l_status_overview
2841                                                ,p_classification_code           =>    l_classification_code
2842                                                ,p_reason_code                   =>    l_reason_code
2843                                                ,p_object_id                     =>    l_object_id
2844                                                ,p_object_type                   =>    l_object_type
2845                                                ,p_date_required                 =>    l_date_required
2846                                                ,p_date_closed                   =>    l_date_closed
2847                                                ,p_closed_by_id                  =>    l_closed_by_id
2848                                                ,p_resolution                    =>    l_resolution
2849                                                ,p_resolution_code               =>    l_resolution_code
2850                                                ,p_priority_code                 =>    l_priority_code
2851                                                ,p_effort_level_code             =>    l_effort_level_code
2852                                                ,p_price                         =>    l_price
2853                                                ,p_price_currency_code           =>    l_price_currency_code
2854                                                ,p_source_type_name              =>    l_source_type_name
2855                                                ,p_source_type_code              =>    l_source_type_code
2856                                                ,p_source_number                 =>    l_source_number
2857                                                ,p_source_comment                =>    l_source_comment
2858                                                ,p_source_date_received          =>    l_source_date_received
2859                                                ,p_source_organization           =>    l_source_organization
2860                                                ,p_source_person                 =>    l_source_person
2861                                                ,p_attribute_category            =>    l_attribute_category
2862                                                ,p_attribute1                    =>    l_attribute1
2863                                                ,p_attribute2                    =>    l_attribute2
2864                                                ,p_attribute3                    =>    l_attribute3
2865                                                ,p_attribute4                    =>    l_attribute4
2866                                                ,p_attribute5                    =>    l_attribute5
2867                                                ,p_attribute6                    =>    l_attribute6
2868                                                ,p_attribute7                    =>    l_attribute7
2869                                                ,p_attribute8                    =>    l_attribute8
2870                                                ,p_attribute9                    =>    l_attribute9
2871                                                ,p_attribute10                   =>    l_attribute10
2872                                                ,p_attribute11                   =>    l_attribute11
2873                                                ,p_attribute12                   =>    l_attribute12
2874                                                ,p_attribute13                   =>    l_attribute13
2875                                                ,p_attribute14                   =>    l_attribute14
2876                                                ,p_attribute15                   =>    l_attribute15
2877                                                ,x_ci_id                         =>    x_ci_id
2878                                                ,x_ci_number                     =>    x_ci_number
2879                                                ,x_return_status                 =>    x_return_status
2880                                                ,x_msg_count                     =>    x_msg_count
2881                                                ,x_msg_data                      =>    x_msg_data
2882                                                );
2883 
2884   if l_debug_mode = 'Y' then
2885       pa_debug.g_err_stage:= 'after calling validate_param_and_create';
2886       pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2887   end if;
2888 
2889   if (p_commit = fnd_api.g_true and x_return_status = fnd_api.g_ret_sts_success)
2890   then
2891         if l_debug_mode = 'Y' then
2892               pa_debug.g_err_stage := 'about to do a commit';
2893               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2894         end if;
2895         commit;
2896   end if;
2897 
2898   --rest the stack;
2899   if l_debug_mode = 'Y' then
2900            pa_debug.reset_curr_function;
2901   end if;
2902 
2903 EXCEPTION
2904   when fnd_api.g_exc_unexpected_error then
2905 
2906             x_return_status := fnd_api.g_ret_sts_unexp_error;
2907             --do a rollback;
2908             if p_commit = fnd_api.g_true then
2909                  rollback to  create_issue;
2910             end if;
2911             FND_MSG_PUB.Count_And_Get(
2912                                       p_count     =>  x_msg_count ,
2913                                       p_data      =>  x_msg_data  );
2914 
2915          /*Initialize the out variables back to null*/
2916          x_ci_id         := null;
2917          x_ci_number     := null;
2918 
2919          --rest the stack;
2920          if l_debug_mode = 'Y' then
2921                pa_debug.reset_curr_function;
2922          end if;
2923 
2924 
2925   when fnd_api.g_exc_error then
2926 
2927          x_return_status := fnd_api.g_ret_sts_error;
2928          --do a rollback;
2929             if p_commit = fnd_api.g_true then
2930                  rollback to  create_issue;
2931             end if;
2932          l_msg_count := fnd_msg_pub.count_msg;
2933          if l_msg_count = 1 then
2934               pa_interface_utils_pub.get_messages
2935                                    (p_encoded        => fnd_api.g_false,
2936                                     p_msg_index      => 1,
2937                                     p_msg_count      => l_msg_count ,
2938                                     p_msg_data       => l_msg_data ,
2939                                     p_data           => l_data,
2940                                     p_msg_index_out  => l_msg_index_out );
2941               x_msg_data  := l_data;
2942               x_msg_count := l_msg_count;
2943          else
2944               x_msg_count := l_msg_count;
2945          end if;
2946 
2947          /*Initialize the out variables back to null*/
2948          x_ci_id         := null;
2949          x_ci_number     := null;
2950 
2951          --Reset the stack
2952          if l_debug_mode = 'Y' then
2953                pa_debug.reset_curr_function;
2954          end if;
2955 
2956   when others then
2957 
2958          x_return_status := fnd_api.g_ret_sts_unexp_error;
2959          --do a rollback;
2960             if p_commit = fnd_api.g_true then
2961                  rollback to  create_issue;
2962             end if;
2963          fnd_msg_pub.add_exc_msg(p_pkg_name       => 'PA_CONTROL_API_PUB',
2964                                  p_procedure_name => 'create_issue',
2965                                  p_error_text     => substrb(sqlerrm,1,240));
2966          fnd_msg_pub.count_and_get(p_count => x_msg_count,
2967                                    p_data  => x_msg_data);
2968 
2969          /*Initialize the out variables back to null*/
2970          x_ci_id         := null;
2971          x_ci_number     := null;
2972 
2973          --Reset the stack
2974          if l_debug_mode = 'Y' then
2975                pa_debug.reset_curr_function;
2976          end if;
2977 
2978 END CREATE_ISSUE;
2979 
2980 PROCEDURE CREATE_CHANGE_REQUEST
2981 (
2982 p_commit                                        IN VARCHAR2 := FND_API.G_FALSE,
2983 p_init_msg_list                                 IN VARCHAR2 := FND_API.G_FALSE,
2984 p_api_version_number                            IN NUMBER   := G_PA_MISS_NUM,
2985 p_orig_system_code                              IN VARCHAR2 := null,
2986 p_orig_system_reference                         IN VARCHAR2 := null,
2987 x_return_status                                 OUT NOCOPY VARCHAR2,
2988 x_msg_count                                     OUT NOCOPY NUMBER,
2989 x_msg_data                                      OUT NOCOPY VARCHAR2,
2990 x_ci_id                                         OUT NOCOPY NUMBER,
2991 x_ci_number                                     OUT NOCOPY NUMBER,
2992 p_project_id                                    IN NUMBER   := G_PA_MISS_NUM,
2993 p_project_name                                  IN VARCHAR2 := G_PA_MISS_CHAR,
2994 p_project_number                                IN VARCHAR2 := G_PA_MISS_CHAR,
2995 p_ci_type_id                                    IN NUMBER   := G_PA_MISS_NUM,
2996 p_summary                                       IN VARCHAR2,
2997 p_ci_number                                     IN VARCHAR2 := G_PA_MISS_CHAR,
2998 p_description                                   IN VARCHAR2 := G_PA_MISS_CHAR,
2999 p_status_code                                   IN VARCHAR2 := G_PA_MISS_CHAR,
3000 p_status                                        IN VARCHAR2 := G_PA_MISS_CHAR,
3001 p_owner_id                                      IN NUMBER   := G_PA_MISS_NUM,
3002 p_progress_status_code                          IN VARCHAR2 := G_PA_MISS_CHAR,
3003 p_progress_as_of_date                           IN DATE     := G_PA_MISS_DATE,
3004 p_status_overview                               IN VARCHAR2 := G_PA_MISS_CHAR,
3005 p_classification_code                           IN NUMBER,
3006 p_reason_code                                   IN NUMBER,
3007 p_object_id                                     IN NUMBER   := G_PA_MISS_NUM,
3008 p_object_type                                   IN VARCHAR2 := G_PA_MISS_CHAR,
3009 p_date_required                                 IN DATE     := G_PA_MISS_DATE,
3010 p_date_closed                                   IN DATE     := G_PA_MISS_DATE,
3011 p_closed_by_id                                  IN NUMBER   := G_PA_MISS_NUM,
3012 p_resolution                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3013 p_resolution_code                               IN NUMBER   := G_PA_MISS_NUM,
3014 p_priority_code                                 IN VARCHAR2 := G_PA_MISS_CHAR,
3015 p_effort_level_code                             IN VARCHAR2 := G_PA_MISS_CHAR,
3016 p_price                                         IN NUMBER   := G_PA_MISS_NUM,
3017 p_price_currency_code                           IN VARCHAR2 := G_PA_MISS_CHAR,
3018 p_source_type_name                              IN VARCHAR2 := G_PA_MISS_CHAR,
3019 p_source_type_code                              IN VARCHAR2 := G_PA_MISS_CHAR,
3020 p_source_number                                 IN VARCHAR2 := G_PA_MISS_CHAR,
3021 p_source_comment                                IN VARCHAR2 := G_PA_MISS_CHAR,
3022 p_source_date_received                          IN DATE     := G_PA_MISS_DATE,
3023 p_source_organization                           IN VARCHAR2 := G_PA_MISS_CHAR,
3024 p_source_person                                 IN VARCHAR2 := G_PA_MISS_CHAR,
3025 p_attribute_category                            IN VARCHAR2 := G_PA_MISS_CHAR,
3026 p_attribute1                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3027 p_attribute2                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3028 p_attribute3                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3029 p_attribute4                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3030 p_attribute5                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3031 p_attribute6                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3032 p_attribute7                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3033 p_attribute8                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3034 p_attribute9                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3035 p_attribute10                                   IN VARCHAR2 := G_PA_MISS_CHAR,
3036 p_attribute11                                   IN VARCHAR2 := G_PA_MISS_CHAR,
3037 p_attribute12                                   IN VARCHAR2 := G_PA_MISS_CHAR,
3038 p_attribute13                                   IN VARCHAR2 := G_PA_MISS_CHAR,
3039 p_attribute14                                   IN VARCHAR2 := G_PA_MISS_CHAR,
3040 p_attribute15                                   IN VARCHAR2 := G_PA_MISS_CHAR
3041 )
3042 IS
3043 
3044   l_module_name                            VARCHAR2(200);
3045 
3046 
3047   l_ci_type_class_code                     pa_ci_types_b.ci_type_class_code%type;
3048   l_auto_number_flag                       pa_ci_types_b.auto_number_flag%type;
3049   l_source_attrs_enabled_flag              pa_ci_types_b.source_attrs_enabled_flag%type;
3050 
3051   l_msg_count                              NUMBER := 0;
3052   l_data                                   VARCHAR2(2000);
3053   l_msg_data                               VARCHAR2(2000);
3054   l_msg_index_out                          NUMBER;
3055 
3056   l_project_id                             pa_projects_all.project_id%type;
3057   l_project_name                           pa_projects_all.name%type;
3058   l_project_number                         pa_projects_all.segment1%type;
3059   l_ci_type_id                             pa_ci_types_b.ci_type_id%type;
3060   l_summary                                pa_control_items.summary%type;
3061   l_ci_number                              pa_control_items.ci_number%type;
3062   l_description                            pa_control_items.description%type;
3063   l_status_code                            pa_project_statuses.project_status_code%type;
3064   l_status                                 pa_project_statuses.project_status_name%type;
3065   l_owner_id                               pa_control_items.owner_id%type;
3066   l_progress_status_code                   pa_control_items.progress_status_code%type;
3067   l_progress_as_of_date                    pa_control_items.progress_as_of_date%type;
3068   l_status_overview                        pa_control_items.status_overview%type;
3069   l_classification_code                    pa_control_items.classification_code_id%type;
3070   l_reason_code                            pa_control_items.reason_code_id%type;
3071   l_object_id                              pa_control_items.object_id%type;
3072   l_object_type                            pa_control_items.object_type%type;
3073   l_date_required                          pa_control_items.date_required%type;
3074   l_date_closed                            pa_control_items.date_closed%type;
3075   l_closed_by_id                           pa_control_items.closed_by_id%type;
3076   l_resolution                             pa_control_items.resolution%type;
3077   l_resolution_code                        pa_control_items.resolution_code_id%type;
3078   l_priority_code                          pa_control_items.priority_code%type;
3079   l_effort_level_code                      pa_control_items.effort_level_code%type;
3080   l_price                                  pa_control_items.price%type;
3081   l_price_currency_code                    pa_control_items.price_currency_code%type;
3082   l_source_type_name                       pa_lookups.meaning%type;
3083   l_source_type_code                       pa_control_items.source_type_code%type;
3084   l_source_number                          pa_control_items.source_number%type;
3085   l_source_comment                         pa_control_items.source_comment%type;
3086   l_source_date_received                   pa_control_items.source_date_received%type;
3087   l_source_organization                    pa_control_items.source_organization%type;
3088   l_source_person                          pa_control_items.source_person%type;
3089   l_attribute_category                     pa_control_items.attribute_category%type;
3090   l_attribute1                             pa_control_items.attribute1%type;
3091   l_attribute2                             pa_control_items.attribute1%type;
3092   l_attribute3                             pa_control_items.attribute1%type;
3093   l_attribute4                             pa_control_items.attribute1%type;
3094   l_attribute5                             pa_control_items.attribute1%type;
3095   l_attribute6                             pa_control_items.attribute1%type;
3096   l_attribute7                             pa_control_items.attribute1%type;
3097   l_attribute8                             pa_control_items.attribute1%type;
3098   l_attribute9                             pa_control_items.attribute1%type;
3099   l_attribute10                            pa_control_items.attribute1%type;
3100   l_attribute11                            pa_control_items.attribute1%type;
3101   l_attribute12                            pa_control_items.attribute1%type;
3102   l_attribute13                            pa_control_items.attribute1%type;
3103   l_attribute14                            pa_control_items.attribute1%type;
3104   l_attribute15                            pa_control_items.attribute1%type;
3105   l_class_code                             constant varchar2(20) := 'CHANGE_REQUEST';
3106 
3107 BEGIN
3108 
3109   -- initialize the return status to success
3110   x_return_status := fnd_api.g_ret_sts_success;
3111   x_msg_count := 0;
3112 
3113   l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
3114   l_module_name :=  'create_change_request' || g_module_name;
3115 
3116   if l_debug_mode = 'Y' then
3117           pa_debug.set_curr_function(p_function => 'pa_control_api_pub.create_change_request', p_debug_mode => l_debug_mode);
3118   end if;
3119 
3120   if fnd_api.to_boolean(nvl(p_init_msg_list, fnd_api.g_true)) then
3121           fnd_msg_pub.initialize;
3122   end if;
3123 
3124   if p_commit = fnd_api.g_true then
3125           savepoint create_change_request;
3126   end if;
3127 
3128   if l_debug_mode = 'Y' then
3129           pa_debug.write(l_module_name, 'start of create_change_request', l_debug_level3);
3130   end if;
3131 
3132   --handle the miss_char and null values
3133   if(p_project_id is null or p_project_id = G_PA_MISS_NUM) then
3134      l_project_id := null;
3135   else
3136      l_project_id := p_project_id;
3137   end if;
3138 
3139     if(p_project_name is null or p_project_name = G_PA_MISS_CHAR) then
3140      l_project_name := null;
3141   else
3142      l_project_name := p_project_name;
3143   end if;
3144 
3145   if(p_project_number is null or p_project_number = G_PA_MISS_CHAR) then
3146      l_project_number := null;
3147   else
3148      l_project_number := p_project_number;
3149   end if;
3150 
3151   if(p_ci_type_id is null or p_ci_type_id = G_PA_MISS_NUM) then
3152      l_ci_type_id := null;
3153   else
3154      l_ci_type_id := p_ci_type_id;
3155   end if;
3156 
3157   if(p_summary is null) then
3158      l_summary := null;
3159   else
3160      l_summary := p_summary;
3161   end if;
3162 
3163   if(p_ci_number is null or p_ci_number = G_PA_MISS_CHAR) then
3164      l_ci_number := null;
3165   else
3166      l_ci_number := p_ci_number;
3167   end if;
3168 
3169   if(p_description is null or p_description = G_PA_MISS_CHAR) then
3170      l_description := null;
3171   else
3172      l_description := p_description;
3173   end if;
3174 
3175   if(p_status_code is null or p_status_code = G_PA_MISS_CHAR) then
3176      l_status_code := null;
3177   else
3178      l_status_code := p_status_code;
3179   end if;
3180 
3181   if(p_status is null or p_status = G_PA_MISS_CHAR) then
3182      l_status := null;
3183   else
3184      l_status := p_status;
3185   end if;
3186 
3187   if(p_owner_id is null or p_owner_id = G_PA_MISS_NUM) then
3188      l_owner_id := null;
3189   else
3190      l_owner_id := p_owner_id;
3191   end if;
3192 
3193   if(p_progress_status_code is null or p_progress_status_code = G_PA_MISS_CHAR) then
3194      l_progress_status_code := null;
3195   else
3196      l_progress_status_code := p_progress_status_code;
3197   end if;
3198 
3199   if(p_progress_as_of_date is null or p_progress_as_of_date = G_PA_MISS_DATE) then
3200      l_progress_as_of_date := null;
3201   else
3202      l_progress_as_of_date := p_progress_as_of_date;
3203   end if;
3204 
3205   if(p_status_overview is null or p_status_overview = G_PA_MISS_CHAR) then
3206      l_status_overview := null;
3207   else
3208      l_status_overview := p_status_overview;
3209   end if;
3210 
3211   if(p_classification_code is null) then
3212      l_classification_code := null;
3213   else
3214      l_classification_code := p_classification_code;
3215   end if;
3216 
3217   if(p_reason_code is null) then
3218      l_reason_code := null;
3219   else
3220      l_reason_code := p_reason_code;
3221   end if;
3222 
3223   if(p_object_id is null or p_object_id = G_PA_MISS_NUM) then
3224      l_object_id := null;
3225   else
3226      l_object_id := p_object_id;
3227   end if;
3228 
3229   if(p_object_type is null or p_object_type = G_PA_MISS_CHAR) then
3230      l_object_type := null;
3231   else
3232      l_object_type := p_object_type;
3233   end if;
3234 
3235   if(p_date_required is null or p_date_required = G_PA_MISS_DATE) then
3236      l_date_required := null;
3237   else
3238      l_date_required := p_date_required;
3239   end if;
3240 
3241   if(p_date_closed is null or p_date_closed = G_PA_MISS_DATE) then
3242      l_date_closed := null;
3243   else
3244      l_date_closed := p_date_closed;
3245   end if;
3246 
3247   if(p_closed_by_id is null or p_closed_by_id = G_PA_MISS_NUM) then
3248      l_closed_by_id := null;
3249   else
3250      l_closed_by_id := p_closed_by_id;
3251   end if;
3252 
3253   if(p_resolution is null or p_resolution = G_PA_MISS_CHAR) then
3254      l_resolution := null;
3255   else
3256      l_resolution := p_resolution;
3257   end if;
3258 
3259   if(p_resolution_code is null or p_resolution_code = G_PA_MISS_NUM) then
3260      l_resolution_code := null;
3261   else
3262      l_resolution_code := p_resolution_code;
3263   end if;
3264 
3265   if(p_priority_code is null or p_priority_code = G_PA_MISS_CHAR) then
3266      l_priority_code := null;
3267   else
3268      l_priority_code := p_priority_code;
3269   end if;
3270 
3271   if(p_effort_level_code is null or p_effort_level_code = G_PA_MISS_CHAR) then
3272      l_effort_level_code := null;
3273   else
3274      l_effort_level_code := p_effort_level_code;
3275   end if;
3276 
3277   if(p_price is null or p_price = G_PA_MISS_NUM) then
3278      l_price := null;
3279   else
3280      l_price := p_price;
3281   end if;
3282 
3283   if(p_price_currency_code is null or p_price_currency_code = G_PA_MISS_CHAR) then
3284      l_price_currency_code := null;
3285   else
3286      l_price_currency_code := p_price_currency_code;
3287   end if;
3288 
3289   if(p_source_type_name is null or p_source_type_name = G_PA_MISS_CHAR) then
3290      l_source_type_name := null;
3291   else
3292      l_source_type_name := p_source_type_name;
3293   end if;
3294 
3295   if(p_source_type_code is null or p_source_type_code = G_PA_MISS_CHAR) then
3296      l_source_type_code := null;
3297   else
3298      l_source_type_code := p_source_type_code;
3299   end if;
3300 
3301   if(p_source_number is null or p_source_number = G_PA_MISS_CHAR) then
3302      l_source_number := null;
3303   else
3304      l_source_number := p_source_number;
3305   end if;
3306 
3307   if(p_source_comment is null or p_source_comment = G_PA_MISS_CHAR) then
3308      l_source_comment := null;
3309   else
3310      l_source_comment := p_source_comment;
3311   end if;
3312 
3313   if(p_source_date_received is null or p_source_date_received = G_PA_MISS_DATE) then
3314      l_source_date_received := null;
3315   else
3316      l_source_date_received := p_source_date_received;
3317   end if;
3318 
3319   if(p_source_organization is null or p_source_organization = G_PA_MISS_CHAR) then
3320      l_source_organization := null;
3321   else
3322      l_source_organization := p_source_organization;
3323   end if;
3324 
3325   if(p_source_person is null or p_source_person = G_PA_MISS_CHAR) then
3326      l_source_person := null;
3327   else
3328      l_source_person := p_source_person;
3329   end if;
3330 
3331   if(p_attribute_category is null or p_attribute_category = G_PA_MISS_CHAR) then
3332      l_attribute_category := null;
3333   else
3334      l_attribute_category := p_attribute_category;
3335   end if;
3336 
3337   if(p_attribute1 is null or p_attribute1 = G_PA_MISS_CHAR) then
3338      l_attribute1 := null;
3339   else
3340      l_attribute1 := p_attribute1;
3341   end if;
3342 
3343   if(p_attribute2 is null or p_attribute2 = G_PA_MISS_CHAR) then
3344      l_attribute2 := null;
3345   else
3346      l_attribute2 := p_attribute2;
3347   end if;
3348 
3349   if(p_attribute3 is null or p_attribute3 = G_PA_MISS_CHAR) then
3350      l_attribute3 := null;
3351   else
3352      l_attribute3 := p_attribute3;
3353   end if;
3354 
3355   if(p_attribute4 is null or p_attribute4 = G_PA_MISS_CHAR) then
3356      l_attribute4 := null;
3357   else
3358      l_attribute4 := p_attribute4;
3359   end if;
3360 
3361   if(p_attribute5 is null or p_attribute5 = G_PA_MISS_CHAR) then
3362      l_attribute5 := null;
3363   else
3364      l_attribute5 := p_attribute5;
3365   end if;
3366 
3367   if(p_attribute6 is null or p_attribute6 = G_PA_MISS_CHAR) then
3368      l_attribute6 := null;
3369   else
3370      l_attribute6 := p_attribute6;
3371   end if;
3372 
3373   if(p_attribute7 is null or p_attribute7 = G_PA_MISS_CHAR) then
3374      l_attribute7 := null;
3375   else
3376      l_attribute7 := p_attribute7;
3377   end if;
3378 
3379   if(p_attribute8 is null or p_attribute8 = G_PA_MISS_CHAR) then
3380      l_attribute8 := null;
3381   else
3382      l_attribute8 := p_attribute8;
3383   end if;
3384 
3385   if(p_attribute9 is null or p_attribute9 = G_PA_MISS_CHAR) then
3386      l_attribute9 := null;
3387   else
3388      l_attribute9 := p_attribute9;
3389   end if;
3390 
3391   if(p_attribute10 is null or p_attribute10 = G_PA_MISS_CHAR) then
3392      l_attribute10 := null;
3393   else
3394      l_attribute10 := p_attribute10;
3395   end if;
3396 
3397   if(p_attribute11 is null or p_attribute11 = G_PA_MISS_CHAR) then
3398      l_attribute11 := null;
3399   else
3400      l_attribute11 := p_attribute11;
3401   end if;
3402 
3403   if(p_attribute12 is null or p_attribute12 = G_PA_MISS_CHAR) then
3404      l_attribute12 := null;
3405   else
3406      l_attribute12 := p_attribute12;
3407   end if;
3408 
3409   if(p_attribute13 is null or p_attribute13 = G_PA_MISS_CHAR) then
3410      l_attribute13 := null;
3411   else
3412      l_attribute13 := p_attribute13;
3413   end if;
3414 
3415   if(p_attribute14 is null or p_attribute14 = G_PA_MISS_CHAR) then
3416      l_attribute14 := null;
3417   else
3418      l_attribute14 := p_attribute14;
3419   end if;
3420 
3421   if(p_attribute15 is null or p_attribute15 = G_PA_MISS_CHAR) then
3422      l_attribute15 := null;
3423   else
3424      l_attribute15 := p_attribute15;
3425   end if;
3426 
3427 
3428   if l_debug_mode = 'Y' then
3429       pa_debug.g_err_stage:= 'calling check_create_ci_allowed';
3430       pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
3431   end if;
3432 
3433   PA_CONTROL_API_PVT.check_create_ci_allowed(
3434                                               p_project_id                      =>  l_project_id
3435                                              ,p_project_name                    =>  l_project_name
3436                                              ,p_project_number                  =>  l_project_number
3437                                              ,p_ci_type_class_code              =>  l_class_code
3438                                              ,p_ci_type_id                      =>  l_ci_type_id
3439                                              ,x_ci_type_class_code              =>  l_ci_type_class_code
3440                                              ,x_auto_number_flag                =>  l_auto_number_flag
3441                                              ,x_source_attrs_enabled_flag       =>  l_source_attrs_enabled_flag
3442                                              ,x_return_status                   =>  x_return_status
3443                                              ,x_msg_count                       =>  x_msg_count
3444                                              ,x_msg_data                        =>  x_msg_data
3445                                              );
3446 
3447   if l_debug_mode = 'Y' then
3448       pa_debug.g_err_stage:= 'After calling check_create_ci_allowed';
3449       pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
3450   end if;
3451 /*Need to get the details on p_api_version_number, p_orig_system_code and p_orig_system_code and write the code which uses these */
3452 /*p_orig_system_code and p_orig_system_reference will be passsed by users
3453  and What ever user gives those will get inserted in the table as it is. */
3454   if l_debug_mode = 'Y' then
3455       pa_debug.g_err_stage:= 'about to call validate_param_and_create';
3456       pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
3457   end if;
3458 
3459   PA_CONTROL_API_PVT.validate_param_and_create(
3460                                                 p_orig_system_code              =>    p_orig_system_code
3461                                                ,p_orig_system_reference         =>    p_orig_system_reference
3462                                                ,p_project_id                    =>    l_project_id
3463                                                ,p_ci_type_id                    =>    l_ci_type_id
3464                                                ,p_auto_number_flag              =>    l_auto_number_flag
3465                                                ,p_source_attrs_enabled_flag     =>    l_source_attrs_enabled_flag
3466                                                ,p_ci_type_class_code            =>    l_ci_type_class_code
3467                                                ,p_summary                       =>    l_summary
3468                                                ,p_ci_number                     =>    l_ci_number
3469                                                ,p_description                   =>    l_description
3470                                                ,p_status_code                   =>    l_status_code
3471                                                ,p_status                        =>    l_status
3472                                                ,p_owner_id                      =>    l_owner_id
3473                                                ,p_progress_status_code          =>    l_progress_status_code
3474                                                ,p_progress_as_of_date           =>    l_progress_as_of_date
3475                                                ,p_status_overview               =>    l_status_overview
3476                                                ,p_classification_code           =>    l_classification_code
3477                                                ,p_reason_code                   =>    l_reason_code
3478                                                ,p_object_id                     =>    l_object_id
3479                                                ,p_object_type                   =>    l_object_type
3480                                                ,p_date_required                 =>    l_date_required
3481                                                ,p_date_closed                   =>    l_date_closed
3482                                                ,p_closed_by_id                  =>    l_closed_by_id
3483                                                ,p_resolution                    =>    l_resolution
3484                                                ,p_resolution_code               =>    l_resolution_code
3485                                                ,p_priority_code                 =>    l_priority_code
3486                                                ,p_effort_level_code             =>    l_effort_level_code
3487                                                ,p_price                         =>    l_price
3488                                                ,p_price_currency_code           =>    l_price_currency_code
3489                                                ,p_source_type_name              =>    l_source_type_name
3490                                                ,p_source_type_code              =>    l_source_type_code
3491                                                ,p_source_number                 =>    l_source_number
3492                                                ,p_source_comment                =>    l_source_comment
3493                                                ,p_source_date_received          =>    l_source_date_received
3494                                                ,p_source_organization           =>    l_source_organization
3495                                                ,p_source_person                 =>    l_source_person
3496                                                ,p_attribute_category            =>    l_attribute_category
3497                                                ,p_attribute1                    =>    l_attribute1
3498                                                ,p_attribute2                    =>    l_attribute2
3499                                                ,p_attribute3                    =>    l_attribute3
3500                                                ,p_attribute4                    =>    l_attribute4
3501                                                ,p_attribute5                    =>    l_attribute5
3502                                                ,p_attribute6                    =>    l_attribute6
3503                                                ,p_attribute7                    =>    l_attribute7
3504                                                ,p_attribute8                    =>    l_attribute8
3505                                                ,p_attribute9                    =>    l_attribute9
3506                                                ,p_attribute10                   =>    l_attribute10
3507                                                ,p_attribute11                   =>    l_attribute11
3508                                                ,p_attribute12                   =>    l_attribute12
3509                                                ,p_attribute13                   =>    l_attribute13
3510                                                ,p_attribute14                   =>    l_attribute14
3511                                                ,p_attribute15                   =>    l_attribute15
3512                                                ,x_ci_id                         =>    x_ci_id
3513                                                ,x_ci_number                     =>    x_ci_number
3514                                                ,x_return_status                 =>    x_return_status
3515                                                ,x_msg_count                     =>    x_msg_count
3516                                                ,x_msg_data                      =>    x_msg_data
3517                                                );
3518 
3519   if l_debug_mode = 'Y' then
3520       pa_debug.g_err_stage:= 'after calling validate_param_and_create';
3521       pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
3522   end if;
3523 
3524   if (p_commit = fnd_api.g_true and x_return_status = fnd_api.g_ret_sts_success)
3525   then
3526         if l_debug_mode = 'Y' then
3527               pa_debug.g_err_stage := 'about to do a commit';
3528               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
3529         end if;
3530         commit;
3531   end if;
3532 
3533   --rest the stack;
3534   if l_debug_mode = 'Y' then
3535            pa_debug.reset_curr_function;
3536   end if;
3537 
3538 EXCEPTION
3539   when fnd_api.g_exc_unexpected_error then
3540 
3541             x_return_status := fnd_api.g_ret_sts_unexp_error;
3542             --do a rollback;
3543             if p_commit = fnd_api.g_true then
3544                  rollback to  create_change_request;
3545             end if;
3546             FND_MSG_PUB.Count_And_Get(
3547                                       p_count     =>  x_msg_count ,
3548                                       p_data      =>  x_msg_data  );
3549 
3550          /*Initialize the out variables back to null*/
3551          x_ci_id         := null;
3552          x_ci_number     := null;
3553 
3554          --rest the stack;
3555          if l_debug_mode = 'Y' then
3556                pa_debug.reset_curr_function;
3557          end if;
3558 
3559 
3560   when fnd_api.g_exc_error then
3561 
3562          x_return_status := fnd_api.g_ret_sts_error;
3563          --do a rollback;
3564             if p_commit = fnd_api.g_true then
3565                  rollback to  create_change_request;
3566             end if;
3567          l_msg_count := fnd_msg_pub.count_msg;
3568          if l_msg_count = 1 then
3569               pa_interface_utils_pub.get_messages
3570                                    (p_encoded        => fnd_api.g_false,
3571                                     p_msg_index      => 1,
3572                                     p_msg_count      => l_msg_count ,
3573                                     p_msg_data       => l_msg_data ,
3574                                     p_data           => l_data,
3575                                     p_msg_index_out  => l_msg_index_out );
3576               x_msg_data  := l_data;
3577               x_msg_count := l_msg_count;
3578          else
3579               x_msg_count := l_msg_count;
3580          end if;
3581 
3582          /*Initialize the out variables back to null*/
3583          x_ci_id         := null;
3584          x_ci_number     := null;
3585 
3586          --Reset the stack
3587          if l_debug_mode = 'Y' then
3588                pa_debug.reset_curr_function;
3589          end if;
3590 
3591   when others then
3592 
3593          x_return_status := fnd_api.g_ret_sts_unexp_error;
3594          --do a rollback;
3595             if p_commit = fnd_api.g_true then
3596                  rollback to  create_change_request;
3597             end if;
3598          fnd_msg_pub.add_exc_msg(p_pkg_name       => 'PA_CONTROL_API_PUB',
3599                                  p_procedure_name => 'create_change_request',
3600                                  p_error_text     => substrb(sqlerrm,1,240));
3601          fnd_msg_pub.count_and_get(p_count => x_msg_count,
3602                                    p_data  => x_msg_data);
3603 
3604          /*Initialize the out variables back to null*/
3605          x_ci_id         := null;
3606          x_ci_number     := null;
3607 
3608          --Reset the stack
3609          if l_debug_mode = 'Y' then
3610                pa_debug.reset_curr_function;
3611          end if;
3612 
3613 END CREATE_CHANGE_REQUEST;
3614 
3615 PROCEDURE CREATE_CHANGE_ORDER
3616 (
3617 p_commit                                        IN VARCHAR2 := FND_API.G_FALSE,
3618 p_init_msg_list                                 IN VARCHAR2 := FND_API.G_FALSE,
3619 p_api_version_number                            IN NUMBER   := G_PA_MISS_NUM,
3620 p_orig_system_code                              IN VARCHAR2 := null,
3621 p_orig_system_reference                         IN VARCHAR2 := null,
3622 x_return_status                                 OUT NOCOPY VARCHAR2,
3623 x_msg_count                                     OUT NOCOPY NUMBER,
3624 x_msg_data                                      OUT NOCOPY VARCHAR2,
3625 x_ci_id                                         OUT NOCOPY NUMBER,
3626 x_ci_number                                     OUT NOCOPY NUMBER,
3627 p_project_id                                    IN NUMBER   := G_PA_MISS_NUM,
3628 p_project_name                                  IN VARCHAR2 := G_PA_MISS_CHAR,
3629 p_project_number                                IN VARCHAR2 := G_PA_MISS_CHAR,
3630 p_ci_type_id                                    IN NUMBER   := G_PA_MISS_NUM,
3631 p_summary                                       IN VARCHAR2,
3632 p_ci_number                                     IN VARCHAR2 := G_PA_MISS_CHAR,
3633 p_description                                   IN VARCHAR2 := G_PA_MISS_CHAR,
3634 p_status_code                                   IN VARCHAR2 := G_PA_MISS_CHAR,
3635 p_status                                        IN VARCHAR2 := G_PA_MISS_CHAR,
3636 p_owner_id                                      IN NUMBER   := G_PA_MISS_NUM,
3637 p_progress_status_code                          IN VARCHAR2 := G_PA_MISS_CHAR,
3638 p_progress_as_of_date                           IN DATE     := G_PA_MISS_DATE,
3639 p_status_overview                               IN VARCHAR2 := G_PA_MISS_CHAR,
3640 p_classification_code                           IN NUMBER,
3641 p_reason_code                                   IN NUMBER,
3642 p_object_id                                     IN NUMBER   := G_PA_MISS_NUM,
3643 p_object_type                                   IN VARCHAR2 := G_PA_MISS_CHAR,
3644 p_date_required                                 IN DATE     := G_PA_MISS_DATE,
3645 p_date_closed                                   IN DATE     := G_PA_MISS_DATE,
3646 p_closed_by_id                                  IN NUMBER   := G_PA_MISS_NUM,
3647 p_resolution                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3648 p_resolution_code                               IN NUMBER   := G_PA_MISS_NUM,
3649 p_priority_code                                 IN VARCHAR2 := G_PA_MISS_CHAR,
3650 p_effort_level_code                             IN VARCHAR2 := G_PA_MISS_CHAR,
3651 p_price                                         IN NUMBER   := G_PA_MISS_NUM,
3652 p_price_currency_code                           IN VARCHAR2 := G_PA_MISS_CHAR,
3653 p_source_type_name                              IN VARCHAR2 := G_PA_MISS_CHAR,
3654 p_source_type_code                              IN VARCHAR2 := G_PA_MISS_CHAR,
3655 p_source_number                                 IN VARCHAR2 := G_PA_MISS_CHAR,
3656 p_source_comment                                IN VARCHAR2 := G_PA_MISS_CHAR,
3657 p_source_date_received                          IN DATE     := G_PA_MISS_DATE,
3658 p_source_organization                           IN VARCHAR2 := G_PA_MISS_CHAR,
3659 p_source_person                                 IN VARCHAR2 := G_PA_MISS_CHAR,
3660 p_attribute_category                            IN VARCHAR2 := G_PA_MISS_CHAR,
3661 p_attribute1                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3662 p_attribute2                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3663 p_attribute3                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3664 p_attribute4                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3665 p_attribute5                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3666 p_attribute6                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3667 p_attribute7                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3668 p_attribute8                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3669 p_attribute9                                    IN VARCHAR2 := G_PA_MISS_CHAR,
3670 p_attribute10                                   IN VARCHAR2 := G_PA_MISS_CHAR,
3671 p_attribute11                                   IN VARCHAR2 := G_PA_MISS_CHAR,
3672 p_attribute12                                   IN VARCHAR2 := G_PA_MISS_CHAR,
3673 p_attribute13                                   IN VARCHAR2 := G_PA_MISS_CHAR,
3674 p_attribute14                                   IN VARCHAR2 := G_PA_MISS_CHAR,
3675 p_attribute15                                   IN VARCHAR2 := G_PA_MISS_CHAR
3676 )
3677 IS
3678 
3679   l_module_name                            VARCHAR2(200);
3680 
3681 
3682   l_ci_type_class_code                     pa_ci_types_b.ci_type_class_code%type;
3683   l_auto_number_flag                       pa_ci_types_b.auto_number_flag%type;
3684   l_source_attrs_enabled_flag              pa_ci_types_b.source_attrs_enabled_flag%type;
3685 
3686   l_msg_count                              NUMBER := 0;
3687   l_data                                   VARCHAR2(2000);
3688   l_msg_data                               VARCHAR2(2000);
3689   l_msg_index_out                          NUMBER;
3690 
3691   l_project_id                             pa_projects_all.project_id%type;
3692   l_project_name                           pa_projects_all.name%type;
3693   l_project_number                         pa_projects_all.segment1%type;
3694   l_ci_type_id                             pa_ci_types_b.ci_type_id%type;
3695   l_summary                                pa_control_items.summary%type;
3696   l_ci_number                              pa_control_items.ci_number%type;
3697   l_description                            pa_control_items.description%type;
3698   l_status_code                            pa_project_statuses.project_status_code%type;
3699   l_status                                 pa_project_statuses.project_status_name%type;
3700   l_owner_id                               pa_control_items.owner_id%type;
3701   l_progress_status_code                   pa_control_items.progress_status_code%type;
3702   l_progress_as_of_date                    pa_control_items.progress_as_of_date%type;
3703   l_status_overview                        pa_control_items.status_overview%type;
3704   l_classification_code                    pa_control_items.classification_code_id%type;
3705   l_reason_code                            pa_control_items.reason_code_id%type;
3706   l_object_id                              pa_control_items.object_id%type;
3707   l_object_type                            pa_control_items.object_type%type;
3708   l_date_required                          pa_control_items.date_required%type;
3709   l_date_closed                            pa_control_items.date_closed%type;
3710   l_closed_by_id                           pa_control_items.closed_by_id%type;
3711   l_resolution                             pa_control_items.resolution%type;
3712   l_resolution_code                        pa_control_items.resolution_code_id%type;
3713   l_priority_code                          pa_control_items.priority_code%type;
3714   l_effort_level_code                      pa_control_items.effort_level_code%type;
3715   l_price                                  pa_control_items.price%type;
3716   l_price_currency_code                    pa_control_items.price_currency_code%type;
3717   l_source_type_name                       pa_lookups.meaning%type;
3718   l_source_type_code                       pa_control_items.source_type_code%type;
3719   l_source_number                          pa_control_items.source_number%type;
3720   l_source_comment                         pa_control_items.source_comment%type;
3721   l_source_date_received                   pa_control_items.source_date_received%type;
3722   l_source_organization                    pa_control_items.source_organization%type;
3723   l_source_person                          pa_control_items.source_person%type;
3724   l_attribute_category                     pa_control_items.attribute_category%type;
3725   l_attribute1                             pa_control_items.attribute1%type;
3726   l_attribute2                             pa_control_items.attribute1%type;
3727   l_attribute3                             pa_control_items.attribute1%type;
3728   l_attribute4                             pa_control_items.attribute1%type;
3729   l_attribute5                             pa_control_items.attribute1%type;
3730   l_attribute6                             pa_control_items.attribute1%type;
3731   l_attribute7                             pa_control_items.attribute1%type;
3732   l_attribute8                             pa_control_items.attribute1%type;
3733   l_attribute9                             pa_control_items.attribute1%type;
3734   l_attribute10                            pa_control_items.attribute1%type;
3735   l_attribute11                            pa_control_items.attribute1%type;
3736   l_attribute12                            pa_control_items.attribute1%type;
3737   l_attribute13                            pa_control_items.attribute1%type;
3738   l_attribute14                            pa_control_items.attribute1%type;
3739   l_attribute15                            pa_control_items.attribute1%type;
3740   l_class_code                             constant varchar2(20) := 'CHANGE_ORDER';
3741 
3742 BEGIN
3743 
3744   -- initialize the return status to success
3745   x_return_status := fnd_api.g_ret_sts_success;
3746   x_msg_count := 0;
3747 
3748   l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
3749   l_module_name :=  'create_change_order' || g_module_name;
3750 
3751   if l_debug_mode = 'Y' then
3752           pa_debug.set_curr_function(p_function => 'pa_control_api_pub.create_change_order', p_debug_mode => l_debug_mode);
3753   end if;
3754 
3755   if fnd_api.to_boolean(nvl(p_init_msg_list, fnd_api.g_true)) then
3756           fnd_msg_pub.initialize;
3757   end if;
3758 
3759   if p_commit = fnd_api.g_true then
3760           savepoint create_change_order;
3761   end if;
3762 
3763   if l_debug_mode = 'Y' then
3764           pa_debug.write(l_module_name, 'start of create_change_order', l_debug_level3);
3765   end if;
3766 
3767   --handle the miss_char and null values
3768   if(p_project_id is null or p_project_id = G_PA_MISS_NUM) then
3769      l_project_id := null;
3770   else
3771      l_project_id := p_project_id;
3772   end if;
3773 
3774     if(p_project_name is null or p_project_name = G_PA_MISS_CHAR) then
3775      l_project_name := null;
3776   else
3777      l_project_name := p_project_name;
3778   end if;
3779 
3780   if(p_project_number is null or p_project_number = G_PA_MISS_CHAR) then
3781      l_project_number := null;
3782   else
3783      l_project_number := p_project_number;
3784   end if;
3785 
3786   if(p_ci_type_id is null or p_ci_type_id = G_PA_MISS_NUM) then
3787      l_ci_type_id := null;
3788   else
3789      l_ci_type_id := p_ci_type_id;
3790   end if;
3791 
3792   if(p_summary is null) then
3793      l_summary := null;
3794   else
3795      l_summary := p_summary;
3796   end if;
3797 
3798   if(p_ci_number is null or p_ci_number = G_PA_MISS_CHAR) then
3799      l_ci_number := null;
3800   else
3801      l_ci_number := p_ci_number;
3802   end if;
3803 
3804   if(p_description is null or p_description = G_PA_MISS_CHAR) then
3805      l_description := null;
3806   else
3807      l_description := p_description;
3808   end if;
3809 
3810   if(p_status_code is null or p_status_code = G_PA_MISS_CHAR) then
3811      l_status_code := null;
3812   else
3813      l_status_code := p_status_code;
3814   end if;
3815 
3816   if(p_status is null or p_status = G_PA_MISS_CHAR) then
3817      l_status := null;
3818   else
3819      l_status := p_status;
3820   end if;
3821 
3822   if(p_owner_id is null or p_owner_id = G_PA_MISS_NUM) then
3823      l_owner_id := null;
3824   else
3825      l_owner_id := p_owner_id;
3826   end if;
3827 
3828   if(p_progress_status_code is null or p_progress_status_code = G_PA_MISS_CHAR) then
3829      l_progress_status_code := null;
3830   else
3831      l_progress_status_code := p_progress_status_code;
3832   end if;
3833 
3834   if(p_progress_as_of_date is null or p_progress_as_of_date = G_PA_MISS_DATE) then
3835      l_progress_as_of_date := null;
3836   else
3837      l_progress_as_of_date := p_progress_as_of_date;
3838   end if;
3839 
3840   if(p_status_overview is null or p_status_overview = G_PA_MISS_CHAR) then
3841      l_status_overview := null;
3842   else
3843      l_status_overview := p_status_overview;
3844   end if;
3845 
3846   if(p_classification_code is null) then
3847      l_classification_code := null;
3848   else
3849      l_classification_code := p_classification_code;
3850   end if;
3851 
3852   if(p_reason_code is null) then
3853      l_reason_code := null;
3854   else
3855      l_reason_code := p_reason_code;
3856   end if;
3857 
3858   if(p_object_id is null or p_object_id = G_PA_MISS_NUM) then
3859      l_object_id := null;
3860   else
3861      l_object_id := p_object_id;
3862   end if;
3863 
3864   if(p_object_type is null or p_object_type = G_PA_MISS_CHAR) then
3865      l_object_type := null;
3866   else
3867      l_object_type := p_object_type;
3868   end if;
3869 
3870   if(p_date_required is null or p_date_required = G_PA_MISS_DATE) then
3871      l_date_required := null;
3872   else
3873      l_date_required := p_date_required;
3874   end if;
3875 
3876   if(p_date_closed is null or p_date_closed = G_PA_MISS_DATE) then
3877      l_date_closed := null;
3878   else
3879      l_date_closed := p_date_closed;
3880   end if;
3881 
3882   if(p_closed_by_id is null or p_closed_by_id = G_PA_MISS_NUM) then
3883      l_closed_by_id := null;
3884   else
3885      l_closed_by_id := p_closed_by_id;
3886   end if;
3887 
3888   if(p_resolution is null or p_resolution = G_PA_MISS_CHAR) then
3889      l_resolution := null;
3890   else
3891      l_resolution := p_resolution;
3892   end if;
3893 
3894   if(p_resolution_code is null or p_resolution_code = G_PA_MISS_NUM) then
3895      l_resolution_code := null;
3896   else
3897      l_resolution_code := p_resolution_code;
3898   end if;
3899 
3900   if(p_priority_code is null or p_priority_code = G_PA_MISS_CHAR) then
3901      l_priority_code := null;
3902   else
3903      l_priority_code := p_priority_code;
3904   end if;
3905 
3906   if(p_effort_level_code is null or p_effort_level_code = G_PA_MISS_CHAR) then
3907      l_effort_level_code := null;
3908   else
3909      l_effort_level_code := p_effort_level_code;
3910   end if;
3911 
3912   if(p_price is null or p_price = G_PA_MISS_NUM) then
3913      l_price := null;
3914   else
3915      l_price := p_price;
3916   end if;
3917 
3918   if(p_price_currency_code is null or p_price_currency_code = G_PA_MISS_CHAR) then
3919      l_price_currency_code := null;
3920   else
3921      l_price_currency_code := p_price_currency_code;
3922   end if;
3923 
3924   if(p_source_type_name is null or p_source_type_name = G_PA_MISS_CHAR) then
3925      l_source_type_name := null;
3926   else
3927      l_source_type_name := p_source_type_name;
3928   end if;
3929 
3930   if(p_source_type_code is null or p_source_type_code = G_PA_MISS_CHAR) then
3931      l_source_type_code := null;
3932   else
3933      l_source_type_code := p_source_type_code;
3934   end if;
3935 
3936   if(p_source_number is null or p_source_number = G_PA_MISS_CHAR) then
3937      l_source_number := null;
3938   else
3939      l_source_number := p_source_number;
3940   end if;
3941 
3942   if(p_source_comment is null or p_source_comment = G_PA_MISS_CHAR) then
3943      l_source_comment := null;
3944   else
3945      l_source_comment := p_source_comment;
3946   end if;
3947 
3948   if(p_source_date_received is null or p_source_date_received = G_PA_MISS_DATE) then
3949      l_source_date_received := null;
3950   else
3951      l_source_date_received := p_source_date_received;
3952   end if;
3953 
3954   if(p_source_organization is null or p_source_organization = G_PA_MISS_CHAR) then
3955      l_source_organization := null;
3956   else
3957      l_source_organization := p_source_organization;
3958   end if;
3959 
3960   if(p_source_person is null or p_source_person = G_PA_MISS_CHAR) then
3961      l_source_person := null;
3962   else
3963      l_source_person := p_source_person;
3964   end if;
3965 
3966   if(p_attribute_category is null or p_attribute_category = G_PA_MISS_CHAR) then
3967      l_attribute_category := null;
3968   else
3969      l_attribute_category := p_attribute_category;
3970   end if;
3971 
3972   if(p_attribute1 is null or p_attribute1 = G_PA_MISS_CHAR) then
3973      l_attribute1 := null;
3974   else
3975      l_attribute1 := p_attribute1;
3976   end if;
3977 
3978   if(p_attribute2 is null or p_attribute2 = G_PA_MISS_CHAR) then
3979      l_attribute2 := null;
3980   else
3981      l_attribute2 := p_attribute2;
3982   end if;
3983 
3984   if(p_attribute3 is null or p_attribute3 = G_PA_MISS_CHAR) then
3985      l_attribute3 := null;
3986   else
3987      l_attribute3 := p_attribute3;
3988   end if;
3989 
3990   if(p_attribute4 is null or p_attribute4 = G_PA_MISS_CHAR) then
3991      l_attribute4 := null;
3992   else
3993      l_attribute4 := p_attribute4;
3994   end if;
3995 
3996   if(p_attribute5 is null or p_attribute5 = G_PA_MISS_CHAR) then
3997      l_attribute5 := null;
3998   else
3999      l_attribute5 := p_attribute5;
4000   end if;
4001 
4002   if(p_attribute6 is null or p_attribute6 = G_PA_MISS_CHAR) then
4003      l_attribute6 := null;
4004   else
4005      l_attribute6 := p_attribute6;
4006   end if;
4007 
4008   if(p_attribute7 is null or p_attribute7 = G_PA_MISS_CHAR) then
4009      l_attribute7 := null;
4010   else
4011      l_attribute7 := p_attribute7;
4012   end if;
4013 
4014   if(p_attribute8 is null or p_attribute8 = G_PA_MISS_CHAR) then
4015      l_attribute8 := null;
4016   else
4017      l_attribute8 := p_attribute8;
4018   end if;
4019 
4020   if(p_attribute9 is null or p_attribute9 = G_PA_MISS_CHAR) then
4021      l_attribute9 := null;
4022   else
4023      l_attribute9 := p_attribute9;
4024   end if;
4025 
4026   if(p_attribute10 is null or p_attribute10 = G_PA_MISS_CHAR) then
4027      l_attribute10 := null;
4028   else
4029      l_attribute10 := p_attribute10;
4030   end if;
4031 
4032   if(p_attribute11 is null or p_attribute11 = G_PA_MISS_CHAR) then
4033      l_attribute11 := null;
4034   else
4035      l_attribute11 := p_attribute11;
4036   end if;
4037 
4038   if(p_attribute12 is null or p_attribute12 = G_PA_MISS_CHAR) then
4039      l_attribute12 := null;
4040   else
4041      l_attribute12 := p_attribute12;
4042   end if;
4043 
4044   if(p_attribute13 is null or p_attribute13 = G_PA_MISS_CHAR) then
4045      l_attribute13 := null;
4046   else
4047      l_attribute13 := p_attribute13;
4048   end if;
4049 
4050   if(p_attribute14 is null or p_attribute14 = G_PA_MISS_CHAR) then
4051      l_attribute14 := null;
4052   else
4053      l_attribute14 := p_attribute14;
4054   end if;
4055 
4056   if(p_attribute15 is null or p_attribute15 = G_PA_MISS_CHAR) then
4057      l_attribute15 := null;
4058   else
4059      l_attribute15 := p_attribute15;
4060   end if;
4061 
4062 
4063   if l_debug_mode = 'Y' then
4064       pa_debug.g_err_stage:= 'calling check_create_ci_allowed';
4065       pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4066   end if;
4067 
4068   PA_CONTROL_API_PVT.check_create_ci_allowed(
4069                                               p_project_id                      =>  l_project_id
4070                                              ,p_project_name                    =>  l_project_name
4071                                              ,p_project_number                  =>  l_project_number
4072                                              ,p_ci_type_class_code              =>  l_class_code
4073                                              ,p_ci_type_id                      =>  l_ci_type_id
4074                                              ,x_ci_type_class_code              =>  l_ci_type_class_code
4075                                              ,x_auto_number_flag                =>  l_auto_number_flag
4076                                              ,x_source_attrs_enabled_flag       =>  l_source_attrs_enabled_flag
4077                                              ,x_return_status                   =>  x_return_status
4078                                              ,x_msg_count                       =>  x_msg_count
4079                                              ,x_msg_data                        =>  x_msg_data
4080                                              );
4081 
4082   if l_debug_mode = 'Y' then
4083       pa_debug.g_err_stage:= 'After calling check_create_ci_allowed';
4084       pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4085   end if;
4086 /*p_orig_system_code and p_orig_system_reference will be passsed by users
4087  and What ever user gives those will get inserted in the table as it is. */
4088 
4089   if l_debug_mode = 'Y' then
4090       pa_debug.g_err_stage:= 'about to call validate_param_and_create';
4091       pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4092   end if;
4093 
4094   PA_CONTROL_API_PVT.validate_param_and_create(
4095                                                 p_orig_system_code              =>    p_orig_system_code
4096                                                ,p_orig_system_reference         =>    p_orig_system_reference
4097                                                ,p_project_id                    =>    l_project_id
4098                                                ,p_ci_type_id                    =>    l_ci_type_id
4099                                                ,p_auto_number_flag              =>    l_auto_number_flag
4100                                                ,p_source_attrs_enabled_flag     =>    l_source_attrs_enabled_flag
4101                                                ,p_ci_type_class_code            =>    l_ci_type_class_code
4102                                                ,p_summary                       =>    l_summary
4103                                                ,p_ci_number                     =>    l_ci_number
4104                                                ,p_description                   =>    l_description
4105                                                ,p_status_code                   =>    l_status_code
4106                                                ,p_status                        =>    l_status
4107                                                ,p_owner_id                      =>    l_owner_id
4108                                                ,p_progress_status_code          =>    l_progress_status_code
4109                                                ,p_progress_as_of_date           =>    l_progress_as_of_date
4110                                                ,p_status_overview               =>    l_status_overview
4111                                                ,p_classification_code           =>    l_classification_code
4112                                                ,p_reason_code                   =>    l_reason_code
4113                                                ,p_object_id                     =>    l_object_id
4114                                                ,p_object_type                   =>    l_object_type
4115                                                ,p_date_required                 =>    l_date_required
4116                                                ,p_date_closed                   =>    l_date_closed
4117                                                ,p_closed_by_id                  =>    l_closed_by_id
4118                                                ,p_resolution                    =>    l_resolution
4119                                                ,p_resolution_code               =>    l_resolution_code
4120                                                ,p_priority_code                 =>    l_priority_code
4121                                                ,p_effort_level_code             =>    l_effort_level_code
4122                                                ,p_price                         =>    l_price
4123                                                ,p_price_currency_code           =>    l_price_currency_code
4124                                                ,p_source_type_name              =>    l_source_type_name
4125                                                ,p_source_type_code              =>    l_source_type_code
4126                                                ,p_source_number                 =>    l_source_number
4127                                                ,p_source_comment                =>    l_source_comment
4128                                                ,p_source_date_received          =>    l_source_date_received
4129                                                ,p_source_organization           =>    l_source_organization
4130                                                ,p_source_person                 =>    l_source_person
4131                                                ,p_attribute_category            =>    l_attribute_category
4132                                                ,p_attribute1                    =>    l_attribute1
4133                                                ,p_attribute2                    =>    l_attribute2
4134                                                ,p_attribute3                    =>    l_attribute3
4135                                                ,p_attribute4                    =>    l_attribute4
4136                                                ,p_attribute5                    =>    l_attribute5
4137                                                ,p_attribute6                    =>    l_attribute6
4138                                                ,p_attribute7                    =>    l_attribute7
4139                                                ,p_attribute8                    =>    l_attribute8
4140                                                ,p_attribute9                    =>    l_attribute9
4141                                                ,p_attribute10                   =>    l_attribute10
4142                                                ,p_attribute11                   =>    l_attribute11
4143                                                ,p_attribute12                   =>    l_attribute12
4144                                                ,p_attribute13                   =>    l_attribute13
4145                                                ,p_attribute14                   =>    l_attribute14
4146                                                ,p_attribute15                   =>    l_attribute15
4147                                                ,x_ci_id                         =>    x_ci_id
4148                                                ,x_ci_number                     =>    x_ci_number
4149                                                ,x_return_status                 =>    x_return_status
4150                                                ,x_msg_count                     =>    x_msg_count
4151                                                ,x_msg_data                      =>    x_msg_data
4152                                                );
4153 
4154   if l_debug_mode = 'Y' then
4155       pa_debug.g_err_stage:= 'after calling validate_param_and_create';
4156       pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4157   end if;
4158 
4159   if (p_commit = fnd_api.g_true and x_return_status = fnd_api.g_ret_sts_success)
4160   then
4161         if l_debug_mode = 'Y' then
4162               pa_debug.g_err_stage := 'about to do a commit';
4163               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4164         end if;
4165         commit;
4166   end if;
4167 
4168   --rest the stack;
4169   if l_debug_mode = 'Y' then
4170            pa_debug.reset_curr_function;
4171   end if;
4172 
4173 EXCEPTION
4174   when fnd_api.g_exc_unexpected_error then
4175 
4176             x_return_status := fnd_api.g_ret_sts_unexp_error;
4177             --do a rollback;
4178             if p_commit = fnd_api.g_true then
4179                  rollback to  create_change_order;
4180             end if;
4181             FND_MSG_PUB.Count_And_Get(
4182                                       p_count     =>  x_msg_count ,
4183                                       p_data      =>  x_msg_data  );
4184 
4185          /*Initialize the out variables back to null*/
4186          x_ci_id         := null;
4187          x_ci_number     := null;
4188 
4189          --rest the stack;
4190          if l_debug_mode = 'Y' then
4191                pa_debug.reset_curr_function;
4192          end if;
4193 
4194 
4195   when fnd_api.g_exc_error then
4196 
4197          x_return_status := fnd_api.g_ret_sts_error;
4198          --do a rollback;
4199             if p_commit = fnd_api.g_true then
4200                  rollback to  create_change_order;
4201             end if;
4202          l_msg_count := fnd_msg_pub.count_msg;
4203          if l_msg_count = 1 then
4204               pa_interface_utils_pub.get_messages
4205                                    (p_encoded        => fnd_api.g_false,
4206                                     p_msg_index      => 1,
4207                                     p_msg_count      => l_msg_count ,
4208                                     p_msg_data       => l_msg_data ,
4209                                     p_data           => l_data,
4210                                     p_msg_index_out  => l_msg_index_out );
4211               x_msg_data  := l_data;
4212               x_msg_count := l_msg_count;
4213          else
4214               x_msg_count := l_msg_count;
4215          end if;
4216 
4217          /*Initialize the out variables back to null*/
4218          x_ci_id         := null;
4219          x_ci_number     := null;
4220 
4221          --Reset the stack
4222          if l_debug_mode = 'Y' then
4223                pa_debug.reset_curr_function;
4224          end if;
4225 
4226   when others then
4227 
4228          x_return_status := fnd_api.g_ret_sts_unexp_error;
4229          --do a rollback;
4230             if p_commit = fnd_api.g_true then
4231                  rollback to  create_change_order;
4232             end if;
4233          fnd_msg_pub.add_exc_msg(p_pkg_name       => 'PA_CONTROL_API_PUB',
4234                                  p_procedure_name => 'create_change_order',
4235                                  p_error_text     => substrb(sqlerrm,1,240));
4236          fnd_msg_pub.count_and_get(p_count => x_msg_count,
4237                                    p_data  => x_msg_data);
4238 
4239          /*Initialize the out variables back to null*/
4240          x_ci_id         := null;
4241          x_ci_number     := null;
4242 
4243          --Reset the stack
4244          if l_debug_mode = 'Y' then
4245                pa_debug.reset_curr_function;
4246          end if;
4247 
4248 END CREATE_CHANGE_ORDER;
4249 
4250 PROCEDURE CREATE_ACTION
4251 (
4252 p_commit                                        IN VARCHAR2 := FND_API.G_FALSE,
4253 p_init_msg_list                                 IN VARCHAR2 := FND_API.G_FALSE,
4254 p_api_version_number                            IN NUMBER   := G_PA_MISS_NUM,
4255 x_return_status                                 OUT NOCOPY VARCHAR2,
4256 x_msg_count                                     OUT NOCOPY NUMBER,
4257 x_msg_data                                      OUT NOCOPY VARCHAR2,
4258 p_ci_id                                         IN NUMBER := G_PA_MISS_NUM,
4259 p_action_tbl                                    IN ci_actions_in_tbl_type,
4260 x_action_tbl                                    OUT NOCOPY ci_actions_out_tbl_type
4261 )
4262 IS
4263 
4264 
4265 
4266   l_msg_count                              NUMBER := 0;
4267   l_data                                   VARCHAR2(2000);
4268   l_msg_data                               VARCHAR2(2000);
4269   l_msg_index_out                          NUMBER;
4270   l_module_name                            VARCHAR2(200);
4271   l_action_tbl                             ci_actions_in_tbl_type;
4272   l_ci_id                                  pa_control_items.ci_id%type;
4273   l_project_id                             pa_control_items.project_id%type;
4274 BEGIN
4275 
4276   -- initialize the return status to success
4277   x_return_status := fnd_api.g_ret_sts_success;
4278   x_msg_count := 0;
4279 
4280   l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
4281   l_module_name :=  'create_action' || g_module_name;
4282 
4283   if l_debug_mode = 'Y' then
4284           pa_debug.set_curr_function(p_function => 'pa_control_api_pub.create_action', p_debug_mode => l_debug_mode);
4285   end if;
4286 
4287   if fnd_api.to_boolean(nvl(p_init_msg_list, fnd_api.g_true)) then
4288           fnd_msg_pub.initialize;
4289   end if;
4290 
4291   if p_commit = fnd_api.g_true then
4292           savepoint create_action;
4293   end if;
4294 
4295   if l_debug_mode = 'Y' then
4296           pa_debug.write(l_module_name, 'start of create_action', l_debug_level3);
4297   end if;
4298 
4299  --handling the g_pa_miss_xxx for p_ci_id
4300   if(p_ci_id is null or p_ci_id = G_PA_MISS_NUM) then
4301      l_ci_id := null;
4302   else
4303      l_ci_id := p_ci_id;
4304   end if;
4305 
4306   if l_debug_mode = 'Y' then
4307       pa_debug.g_err_stage:= 'Calling check_create_action_allow';
4308       pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4309   end if;
4310 
4311   PA_CONTROL_API_PVT.check_create_action_allow(
4312                                                 p_ci_id                   =>  l_ci_id
4313                                                ,x_project_id              =>  l_project_id
4314                                                ,x_return_status           =>  x_return_status
4315                                                ,x_msg_count               =>  x_msg_count
4316                                                ,x_msg_data                =>  x_msg_data
4317                                                );
4318 
4319   if l_debug_mode = 'Y' then
4320       pa_debug.g_err_stage:= 'Calling validate_action_attributes';
4321       pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4322   end if;
4323 
4324   /*Passing the l_ci_id here which was validated in check_create_action_allow*/
4325   PA_CONTROL_API_PVT.validate_action_attributes(
4326                                                 p_ci_id                   =>  l_ci_id
4327                                                ,p_project_id              =>  l_project_id
4328                                                ,p_action_tbl              =>  p_action_tbl
4329                                                ,x_action_tbl              =>  l_action_tbl
4330                                                ,x_return_status           =>  x_return_status
4331                                                ,x_msg_count               =>  x_msg_count
4332                                                ,x_msg_data                =>  x_msg_data
4333                                                 );
4334 
4335   if l_debug_mode = 'Y' then
4336       pa_debug.g_err_stage:= 'Calling PA_CONTROL_API_PVT.create_action';
4337       pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4338   end if;
4339 
4340   /*Passing the l_ci_id here which was validated in check_create_action_allow*/
4341   PA_CONTROL_API_PVT.create_action(
4342                                     p_action_tbl              =>  l_action_tbl
4343                                    ,p_ci_id                   =>  l_ci_id
4344                                    ,x_action_tbl              =>  x_action_tbl
4345                                    ,x_return_status           =>  x_return_status
4346                                    ,x_msg_count               =>  x_msg_count
4347                                    ,x_msg_data                =>  x_msg_data
4348                                    );
4349 
4350   if (p_commit = fnd_api.g_true and x_return_status = fnd_api.g_ret_sts_success)
4351   then
4352         if l_debug_mode = 'Y' then
4353               pa_debug.g_err_stage := 'about to do a commit';
4354               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4355         end if;
4356         commit;
4357   end if;
4358 
4359   --rest the stack;
4360   if l_debug_mode = 'Y' then
4361            pa_debug.reset_curr_function;
4362   end if;
4363 
4364 Exception
4365   when fnd_api.g_exc_error then
4366 
4367          x_return_status := fnd_api.g_ret_sts_error;
4368 
4369          --do a rollback;
4370          if p_commit = fnd_api.g_true then
4371               rollback to  create_action;
4372          end if;
4373 
4374          l_msg_count := fnd_msg_pub.count_msg;
4375          if l_msg_count = 1 then
4376               pa_interface_utils_pub.get_messages
4377                                    (p_encoded        => fnd_api.g_false,
4378                                     p_msg_index      => 1,
4379                                     p_msg_count      => l_msg_count ,
4380                                     p_msg_data       => l_msg_data ,
4381                                     p_data           => l_data,
4382                                     p_msg_index_out  => l_msg_index_out );
4383               x_msg_data  := l_data;
4384               x_msg_count := l_msg_count;
4385          else
4386               x_msg_count := l_msg_count;
4387          end if;
4388 
4389          /*Initialize the out variables back to null*/
4390          /*set the elements in the out table to null here*/
4391          for i in 1..x_action_tbl.count
4392          loop
4393          x_action_tbl(i).action_id     := null;
4394          x_action_tbl(i).action_number := null;
4395          end loop;
4396 
4397 
4398          --rest the stack;
4399          if l_debug_mode = 'Y' then
4400               pa_debug.reset_curr_function;
4401          end if;
4402   when others then
4403 
4404          x_return_status := fnd_api.g_ret_sts_unexp_error;
4405          --do a rollback;
4406          if p_commit = fnd_api.g_true then
4407               rollback to  create_action;
4408 
4409          end if;
4410 
4411          fnd_msg_pub.add_exc_msg(p_pkg_name       => 'pa_control_api_pub',
4412                                  p_procedure_name => 'create_action',
4413                                  p_error_text     => substrb(sqlerrm,1,240));
4414          fnd_msg_pub.count_and_get(p_count => x_msg_count,
4415                                    p_data  => x_msg_data);
4416 
4417          /*Initialize the out variables back to null*/
4418          /*set the elements in the out table to null here*/
4419          for i in 1..x_action_tbl.count
4420          loop
4421          x_action_tbl(i).action_id     := null;
4422          x_action_tbl(i).action_number := null;
4423          end loop;
4424          --rest the stack;
4425          if l_debug_mode = 'Y' then
4426               pa_debug.reset_curr_function;
4427          end if;
4428 END CREATE_ACTION;
4429 
4430 
4431 PROCEDURE TAKE_ACTION
4432 (
4433 p_commit                                        IN VARCHAR2 := FND_API.G_FALSE,
4434 p_init_msg_list                                 IN VARCHAR2 := FND_API.G_FALSE,
4435 p_api_version_number                            IN NUMBER   := G_PA_MISS_NUM,
4436 x_return_status                                 OUT NOCOPY VARCHAR2,
4437 x_msg_count                                     OUT NOCOPY NUMBER,
4438 x_msg_data                                      OUT NOCOPY VARCHAR2,
4439 p_ci_id                                         IN NUMBER := G_PA_MISS_NUM,
4440 p_action_id                                     IN NUMBER := G_PA_MISS_NUM,
4441 p_action_number                                 IN NUMBER := G_PA_MISS_NUM,
4442 p_close_action_flag                             IN VARCHAR2 := 'N',
4443 p_response_text                                 IN VARCHAR2 := G_PA_MISS_CHAR,
4444 p_sign_off_flag                                 IN VARCHAR2 := 'N',
4445 p_reassign_action_flag                          IN VARCHAR2 := 'N',
4446 p_reassign_to_id                                IN NUMBER := G_PA_MISS_NUM,
4447 p_reassign_request_text                         IN VARCHAR2 := G_PA_MISS_CHAR,
4448 p_required_by_date                              IN DATE := G_PA_MISS_DATE
4449 )
4450 is
4451 
4452 
4453 cursor get_action_attrs(p_action_id number)
4454 is
4455 select sign_off_required_flag, record_version_number, date_required, ci_id, status_code
4456 from pa_ci_actions
4457 where ci_action_id = p_action_id;
4458 
4459 cursor close_notification(p_action_id number)
4460 is
4461 select wfi.notification_id,
4462 wfi.item_type,
4463 wfi.item_key
4464 from pa_wf_processes pwp,
4465 wf_item_activity_statuses_v wfi
4466 where pwp.entity_key2 = p_action_id
4467 and pwp.item_type ='PAWFCIAC'
4468 and wfi.item_type = pwp.item_type
4469 and wfi.item_key = pwp.item_key
4470 and wfi.activity_type_code ='NOTICE'
4471 and wfi.activity_status_code ='NOTIFIED';
4472 
4473   close_notification_rec                  close_notification%rowtype;
4474   get_action_attrs_rec                    get_action_attrs%rowtype;
4475 
4476 
4477 
4478   l_msg_count                              NUMBER := 0;
4479   l_data                                   VARCHAR2(2000);
4480   l_msg_data                               VARCHAR2(2000);
4481   l_msg_index_out                          NUMBER;
4482   l_module_name                            VARCHAR2(200);
4483   l_action_id                              pa_ci_actions.ci_action_id%type;
4484   l_party_id                               NUMBER := 0;
4485   l_user_id                                NUMBER := 0;
4486   l_assignee_id                            NUMBER := null;
4487   l_perform_action                         VARCHAR2(1) := null;
4488   l_ci_comment_id                          pa_ci_comments.ci_comment_id%type;
4489   l_sign_off_flag                          VARCHAR2(1);
4490   l_response_text                          pa_ci_comments.comment_text%type;
4491   l_reassign_request_text                  pa_ci_comments.comment_text%type;
4492   l_required_by_date                       pa_ci_actions.date_required%type;
4493   l_reassign_to_id                         pa_ci_actions.assigned_to%type;
4494   l_project_id                             pa_control_items.project_id%TYPE;
4495 
4496 begin
4497 
4498   -- initialize the return status to success
4499   x_return_status := fnd_api.g_ret_sts_success;
4500   x_msg_count := 0;
4501 
4502   l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
4503   l_module_name :=  'take_action' || g_module_name;
4504 
4505   if l_debug_mode = 'Y' then
4506           pa_debug.set_curr_function(p_function => 'pa_control_api_pub.take_action', p_debug_mode => l_debug_mode);
4507   end if;
4508 
4509   if fnd_api.to_boolean(nvl(p_init_msg_list, fnd_api.g_true)) then
4510           fnd_msg_pub.initialize;
4511   end if;
4512 
4513   if p_commit = fnd_api.g_true then
4514           savepoint take_action;
4515   end if;
4516 
4517   if l_debug_mode = 'Y' then
4518           pa_debug.write(l_module_name, 'start of take_action', l_debug_level3);
4519   end if;
4520 
4521   --Get the party_id for the logged in user
4522   l_user_id  := fnd_global.user_id;
4523   l_party_id := pa_control_items_utils.getpartyid(l_user_id);
4524 
4525   /*Check whether the user has privilige to update this action or not and whether the passed action is valid or not*/
4526   /*for checking the privilege check the party id of the logged in user with party id of person to whom the action is assigned*/
4527   PA_CONTROL_API_PVT.validate_priv_and_action(
4528                                                 p_ci_id                   =>  p_ci_id
4529                                                ,p_action_id               =>  p_action_id
4530                                                ,p_action_number           =>  p_action_number
4531                                                ,x_action_id               =>  l_action_id
4532                                                ,x_assignee_id             =>  l_assignee_id
4533                                                ,x_project_id              =>  l_project_id
4534                                                ,x_return_status           =>  x_return_status
4535                                                ,x_msg_count               =>  x_msg_count
4536                                                ,x_msg_data                =>  x_msg_data
4537                                               );
4538   /* at this point in code action_id and assignee id would have been dervied if code reaches here*/
4539   /* compare the assignee_id for this action with the party id of the logged inuser to determine the priv
4540      to take action*/
4541   if l_party_id is null then
4542         pa_utils.add_message(p_app_short_name    => 'PA',
4543                              p_msg_name          => 'PA_CI_ACTION_NO_ACCESS');
4544         if (l_debug_mode = 'Y') then
4545              pa_debug.g_err_stage := 'Apps Initialization is not been done';
4546              pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4547         end if;
4548         raise fnd_api.g_exc_error;
4549   elsif( l_assignee_id is not null and (l_assignee_id <> l_party_id) ) then
4550     /*user doesnt have privilige to update the action*/
4551         pa_utils.add_message(p_app_short_name    => 'PA',
4552                              p_msg_name          => 'PA_CI_ACTION_NO_ACCESS');
4553         if (l_debug_mode = 'Y') then
4554              pa_debug.g_err_stage := 'user doesnt have access to update the action';
4555              pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4556         end if;
4557         raise fnd_api.g_exc_error;
4558   end if;
4559 
4560   if( p_close_action_flag = 'Y' and p_reassign_action_flag = 'Y') then
4561         pa_utils.add_message(p_app_short_name    => 'PA',
4562                              p_msg_name          => 'PA_CI_BOTH_REASSGN_CLSE');
4563         if (l_debug_mode = 'Y') then
4564              pa_debug.g_err_stage := 'you cannot both close and reassign the action.';
4565              pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4566         end if;
4567         raise fnd_api.g_exc_error;
4568   end if;--  if( p_close_action_flag := 'Y' and p_reassign_action_flag := 'Y') then
4569 
4570   /*validathe value for the close action flg. It can be either Y, N or G_PA_MISS_CHAR*/
4571   if (p_close_action_flag <> 'N' and p_close_action_flag <> 'Y' and p_close_action_flag <> G_PA_MISS_CHAR) then
4572         pa_utils.add_message(p_app_short_name    => 'PA',
4573                              p_msg_name          => 'PA_CI_INV_CLS_ACT_FLG');
4574         if (l_debug_mode = 'Y') then
4575              pa_debug.g_err_stage := 'Invalid value for close action flag';
4576              pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4577         end if;
4578         raise fnd_api.g_exc_error;
4579   end if;
4580 
4581   /*validathe value for the reassign action flg. It can be either Y, N or G_PA_MISS_CHAR*/
4582   if (p_reassign_action_flag <> 'N' and p_reassign_action_flag <> 'Y' and
4583       p_reassign_action_flag <> G_PA_MISS_CHAR ) then
4584         pa_utils.add_message(p_app_short_name    => 'PA',
4585                              p_msg_name          => 'PA_CI_INV_REASSGN_ACT_FLG');
4586         if (l_debug_mode = 'Y') then
4587              pa_debug.g_err_stage := 'Invalid value for reassign action flag';
4588              pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4589         end if;
4590         raise fnd_api.g_exc_error;
4591   end if;
4592 
4593   /*now check which action of three close/reassign or keep open has to be performed*/
4594   if( p_close_action_flag = 'Y' and
4595       (p_reassign_action_flag = 'N' or p_reassign_action_flag = G_PA_MISS_CHAR) ) then
4596       l_perform_action := 'C';
4597   elsif(p_reassign_action_flag = 'Y' and
4598       (p_close_action_flag = 'N' or p_close_action_flag = G_PA_MISS_CHAR) )  then
4599       l_perform_action := 'R';
4600   else
4601       l_perform_action := 'O';
4602   end if;
4603 
4604   if(l_perform_action is not null and l_perform_action = 'C') then
4605 
4606        open get_action_attrs(l_action_id);
4607        fetch get_action_attrs into get_action_attrs_rec;
4608        close get_action_attrs;
4609 
4610        /*Only open actions can be closed*/
4611        if get_action_attrs_rec.status_code <> 'CI_ACTION_OPEN' then
4612               pa_utils.add_message(p_app_short_name    => 'PA',
4613                                    p_msg_name          => 'PA_CI_CLS_OPEN_ACT');
4614               if (l_debug_mode = 'Y') then
4615 		    pa_debug.g_err_stage := 'only open actions can be closed';
4616                     pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4617               end if;
4618               x_return_status := FND_API.G_RET_STS_ERROR;
4619               raise FND_API.G_EXC_ERROR;
4620        end if;
4621 
4622        if(get_action_attrs_rec.sign_off_required_flag = 'Y') then
4623            /*sign off flag is acknowledged only when sign_off_required_flag is Y*/
4624            /*although sign off is optional but if a value is supplied then it should be either Y or N*/
4625            if(p_sign_off_flag <> 'N' and p_sign_off_flag <> 'Y') then
4626                 pa_utils.add_message(p_app_short_name    => 'PA',
4627                                      p_msg_name          => 'PA_CI_INV_SIGN_OFF_FLAG');
4628                 if (l_debug_mode = 'Y') then
4629                      pa_debug.g_err_stage := 'sign off flag can either be Y or N';
4630                      pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4631                 end if;
4632            else
4633                l_sign_off_flag := p_sign_off_flag;
4634            end if;
4635        else--       if(get_action_attrs_rec.sign_off_required_flag = 'Y') then
4636            /*if sign_off_required_flag is not Y then sign_off flag would be N*/
4637            l_sign_off_flag := 'N';
4638        end if;  --     if(get_action_attrs_rec.sign_off_required_flag = 'Y') then
4639 
4640        --a new record gets created in pa_ci_comments with response text if response text is passed.
4641        if (p_response_text = G_PA_MISS_CHAR or p_response_text is null ) then
4642             l_response_text := null;
4643        else
4644             l_response_text := p_response_text;
4645        end if;--if (p_response_text = G_PA_MISS_CHAR) then
4646 
4647             pa_ci_actions_pvt.close_ci_action(
4648                                               p_validate_only          => fnd_api.g_false,
4649                                               p_ci_action_id           => l_action_id,
4650                                               p_sign_off_flag          => l_sign_off_flag,
4651                                               p_record_version_number  => get_action_attrs_rec.record_version_number,
4652                                               p_comment_text           => l_response_text,
4653                                               p_last_updated_by        => fnd_global.user_id,
4654                                               p_last_update_date       => sysdate,
4655                                               p_last_update_login      => fnd_global.login_id,
4656                                               x_return_status          => x_return_status,
4657                                               x_msg_count              => x_msg_count,
4658                                               x_msg_data               => x_msg_data
4659                                              );
4660 
4661        if(x_return_status <> FND_API.G_RET_STS_SUCCESS) then
4662            if (l_debug_mode = 'Y') then
4663                 pa_debug.g_err_stage := 'error occured while closing the action';
4664                 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4665            end if;
4666            raise fnd_api.g_exc_unexpected_error;
4667        end if;
4668 
4669       /*check for open notifications for this action which is being closed. Close the open notification for this action*/
4670       open close_notification(l_action_id);
4671       fetch close_notification into close_notification_rec;
4672       if(close_notification%notfound) then
4673              null;
4674       else
4675              pa_control_items_workflow.close_notification(
4676                                                               p_item_type       =>  close_notification_rec.item_type,
4677                                                               p_item_key        =>  close_notification_rec.item_key,
4678                                                               p_nid             =>  close_notification_rec.notification_id,
4679                                                               p_action          =>  l_perform_action,
4680                                                               p_sign_off_flag   =>  l_sign_off_flag,
4681                                                               p_response        =>  l_response_text,
4682                                                               x_msg_count       =>  x_msg_count,
4683                                                               x_msg_data        =>  x_msg_data,
4684                                                               x_return_status   =>  x_return_status
4685                                                          );
4686       end if;
4687 
4688       if(x_return_status <> FND_API.G_RET_STS_SUCCESS) then
4689           if (l_debug_mode = 'Y') then
4690                pa_debug.g_err_stage := 'error occurred while closing the notification';
4691                pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4692           end if;
4693           raise fnd_api.g_exc_unexpected_error;
4694      end if;
4695 
4696   end if;--  if(l_perform_action is not null and l_perform_action = 'C') then
4697 
4698   if(l_perform_action is not null and l_perform_action = 'R') then
4699 
4700        open get_action_attrs(l_action_id);
4701        fetch get_action_attrs into get_action_attrs_rec;
4702        close get_action_attrs;
4703 
4704         /*only open actions can be reassigned.*/
4705         if get_action_attrs_rec.status_code <> 'CI_ACTION_OPEN' then
4706               pa_utils.add_message(p_app_short_name    => 'PA',
4707                                    p_msg_name          => 'PA_CI_REASSGN_OPEN_ACT');
4708               if (l_debug_mode = 'Y') then
4709 		    pa_debug.g_err_stage := 'only open actions can be reassigned';
4710                     pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4711               end if;
4712               x_return_status := FND_API.G_RET_STS_ERROR;
4713               raise FND_API.G_EXC_ERROR;
4714        end if;
4715 
4716 
4717        if(get_action_attrs_rec.sign_off_required_flag = 'Y') then
4718            /*sign off flag is acknowledged only when sign_off_required_flag is Y*/
4719            /*although sign off is optional but if a value is supplied then it should be either Y or N*/
4720            if(p_sign_off_flag <> 'N' and p_sign_off_flag <> 'Y') then
4721                 pa_utils.add_message(p_app_short_name    => 'PA',
4722                                      p_msg_name          => 'PA_CI_INV_SIGN_OFF_FLAG');
4723                 if (l_debug_mode = 'Y') then
4724                      pa_debug.g_err_stage := 'sign off flag can either be Y or N';
4725                      pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4726                 end if;
4727            else
4728                l_sign_off_flag := p_sign_off_flag;
4729            end if;
4730        else--       if(get_action_attrs_rec.sign_off_required_flag = 'Y') then
4731            /*if sign_off_required_flag is not Y then sign_off flag would be N*/
4732            l_sign_off_flag := 'N';
4733        end if;  --     if(get_action_attrs_rec.sign_off_required_flag = 'Y') then
4734 
4735        if (p_response_text = G_PA_MISS_CHAR or p_response_text is null) then
4736             l_response_text := null;
4737        else
4738             l_response_text := p_response_text;
4739        end if;--if (p_response_text = G_PA_MISS_CHAR) then
4740 
4741        if (p_reassign_request_text = G_PA_MISS_CHAR or p_reassign_request_text is null) then
4742             l_reassign_request_text := null;
4743        else
4744             l_reassign_request_text := p_reassign_request_text;
4745        end if;--if (p_reassign_request_text = G_PA_MISS_CHAR) then
4746 
4747       if(p_required_by_date = G_PA_MISS_DATE or p_required_by_date is null) then
4748             l_required_by_date := null;
4749        else
4750             l_required_by_date := p_required_by_date;
4751       end if;
4752 
4753        if(get_action_attrs_rec.date_required <> null) then
4754           /*defaulting the required by date while reassigning with the action required by date if this was given while
4755             creating the action*/
4756           if( l_required_by_date is null) then
4757               l_required_by_date := get_action_attrs_rec.date_required;
4758           else
4759               l_required_by_date := l_required_by_date;
4760           end if;
4761        else
4762           l_required_by_date := l_required_by_date;
4763        end if;
4764 
4765        /*Validate the reassignee for the action*/
4766        pa_control_api_pvt.validate_assignee_id(
4767                                                  p_assignee_id           => p_reassign_to_id
4768                                                 ,p_project_id            => l_project_id
4769                                                 ,p_msg_token_num         => null  --Need to pass this parameter null here for non tokenized messages.
4770                                                 ,x_assignee_id           => l_reassign_to_id
4771                                                 ,x_return_status         => x_return_status
4772                                                 ,x_msg_count             => x_msg_count
4773                                                 ,x_msg_data              => x_msg_data
4774                                              );
4775 
4776       if(x_return_status <> fnd_api.g_ret_sts_success) then
4777           if (l_debug_mode = 'Y') then
4778               pa_debug.g_err_stage := 'error occured while validating the assignee id';
4779               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4780           end if;
4781           raise fnd_api.g_exc_error;
4782        end if;
4783 
4784           /*need to add a context in the pa_ci_actions_pvt.reassign_ci_action so tht we dont perform the check that
4785             required by date cannot be before the system date*/
4786                     pa_ci_actions_pvt.reassign_ci_action(
4787                                                         p_validate_only          =>  fnd_api.g_false,
4788                                                         p_ci_action_id           =>  l_action_id,
4789                                                         p_sign_off_flag          =>  l_sign_off_flag,
4790                                                         p_record_version_number  =>  get_action_attrs_rec.record_version_number,
4791                                                         p_assigned_to            =>  l_reassign_to_id,
4792                                                         p_date_required          =>  l_required_by_date,
4793                                                         p_comment_text           =>  l_reassign_request_text,
4794                                                         p_closure_comment        =>  l_response_text,
4795                                                         p_created_by             =>  fnd_global.user_id,
4796                                                         p_creation_date          =>  sysdate,
4797                                                         p_last_updated_by        =>  fnd_global.user_id,
4798                                                         p_last_update_date       =>  sysdate,
4799                                                         p_last_update_login      =>  fnd_global.login_id,
4800                                                         x_return_status          =>  x_return_status,
4801                                                         x_msg_count              =>  x_msg_count,
4802                                                         x_msg_data               =>  x_msg_data
4803                                                         );
4804 
4805        if(x_return_status <> FND_API.G_RET_STS_SUCCESS) then
4806            if (l_debug_mode = 'Y') then
4807                 pa_debug.g_err_stage := 'error occured while reassigning the action';
4808                 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4809            end if;
4810            raise fnd_api.g_exc_unexpected_error;
4811        end if;
4812 
4813       /*check for open notifications for this action which is being closed. Close the open notification for this action*/
4814       open close_notification(l_action_id);
4815       fetch close_notification into close_notification_rec;
4816       if(close_notification%notfound) then
4817              null;
4818       else
4819              pa_control_items_workflow.close_notification(
4820                                                               p_item_type       =>  close_notification_rec.item_type,
4821                                                               p_item_key        =>  close_notification_rec.item_key,
4822                                                               p_nid             =>  close_notification_rec.notification_id,
4823                                                               p_action          =>  l_perform_action,
4824                                                               p_sign_off_flag   =>  l_sign_off_flag,
4825                                                               p_response        =>  l_response_text,
4826                                                               x_msg_count       =>  x_msg_count,
4827                                                               x_msg_data        =>  x_msg_data,
4828                                                               x_return_status   =>  x_return_status
4829                                                          );
4830       end if;
4831 
4832       if(x_return_status <> FND_API.G_RET_STS_SUCCESS) then
4833           if (l_debug_mode = 'Y') then
4834                pa_debug.g_err_stage := 'error occurred while closing the notification';
4835                pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4836           end if;
4837           raise fnd_api.g_exc_unexpected_error;
4838      end if;
4839 
4840   end if;--    if(l_perform_action is not null and l_perform_action = 'R') then
4841 
4842   if(l_perform_action is not null and l_perform_action = 'O') then
4843 
4844        open get_action_attrs(l_action_id);
4845        fetch get_action_attrs into get_action_attrs_rec;
4846        close get_action_attrs;
4847 
4848        if (p_response_text = G_PA_MISS_CHAR or p_response_text is null ) then
4849             l_response_text := null;
4850        else
4851             l_response_text := p_response_text;
4852        end if;--if (p_response_text = G_PA_MISS_CHAR) then
4853 
4854                 pa_ci_actions_pvt.add_ci_comment(
4855                                                   p_validate_only         => fnd_api.g_false,
4856                                                   p_ci_comment_id         => l_ci_comment_id,
4857                                                   p_ci_id                 => get_action_attrs_rec.ci_id,
4858                                                   p_type_code             => 'UNSOLICITED',
4859                                                   p_comment_text          => l_response_text,
4860                                                   p_ci_action_id          => l_action_id,
4861                                                   p_created_by            => fnd_global.user_id,
4862                                                   p_creation_date         => sysdate,
4863                                                   p_last_updated_by       => fnd_global.user_id,
4864                                                   p_last_update_date      => sysdate,
4865                                                   p_last_update_login     => fnd_global.login_id,
4866                                                   x_return_status         => x_return_status,
4867                                                   x_msg_count             => x_msg_count,
4868                                                   x_msg_data              => x_msg_data
4869                                                 );
4870 
4871        if(x_return_status <> FND_API.G_RET_STS_SUCCESS) then
4872            if (l_debug_mode = 'Y') then
4873                 pa_debug.g_err_stage := 'error occured while adding the response';
4874                 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4875            end if;
4876            raise fnd_api.g_exc_unexpected_error;
4877        end if;
4878 
4879       /*check for open notifications for this action which is being closed. Close the open notification for this action*/
4880       open close_notification(l_action_id);
4881       fetch close_notification into close_notification_rec;
4882       if(close_notification%notfound) then
4883              null;
4884       else
4885              pa_control_items_workflow.close_notification(
4886                                                               p_item_type       =>  close_notification_rec.item_type,
4887                                                               p_item_key        =>  close_notification_rec.item_key,
4888                                                               p_nid             =>  close_notification_rec.notification_id,
4889                                                               p_action          =>  l_perform_action,
4890                                                               p_sign_off_flag   =>  l_sign_off_flag,
4891                                                               p_response        =>  l_response_text,
4892                                                               x_msg_count       =>  x_msg_count,
4893                                                               x_msg_data        =>  x_msg_data,
4894                                                               x_return_status   =>  x_return_status
4895                                                          );
4896       end if;
4897 
4898       if(x_return_status <> FND_API.G_RET_STS_SUCCESS) then
4899           if (l_debug_mode = 'Y') then
4900                pa_debug.g_err_stage := 'error occurred while closing the notification';
4901                pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4902           end if;
4903           raise fnd_api.g_exc_unexpected_error;
4904      end if;
4905   end if;--  if(l_perform_action is not null and l_perform_action = 'O') then
4906 
4907 --handle this exception here
4908 --  raise fnd_api.g_exc_error;
4909 --raise fnd_api.g_exc_unexpected_error;
4910 
4911   if (p_commit = fnd_api.g_true and x_return_status = fnd_api.g_ret_sts_success)
4912   then
4913         if l_debug_mode = 'Y' then
4914               pa_debug.g_err_stage := 'about to do a commit';
4915               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4916         end if;
4917         commit;
4918   end if;
4919 
4920   --rest the stack;
4921   if l_debug_mode = 'Y' then
4922            pa_debug.reset_curr_function;
4923   end if;
4924 
4925 
4926 Exception
4927   when fnd_api.g_exc_error then
4928 
4929          --do a rollback;
4930          if p_commit = fnd_api.g_true then
4931               rollback to  take_action;
4932          end if;
4933 
4934          x_return_status := fnd_api.g_ret_sts_error;
4935          l_msg_count := fnd_msg_pub.count_msg;
4936          if l_msg_count = 1 then
4937               pa_interface_utils_pub.get_messages
4938                                    (p_encoded        => fnd_api.g_false,
4939                                     p_msg_index      => 1,
4940                                     p_msg_count      => l_msg_count ,
4941                                     p_msg_data       => l_msg_data ,
4942                                     p_data           => l_data,
4943                                     p_msg_index_out  => l_msg_index_out );
4944               x_msg_data  := l_data;
4945               x_msg_count := l_msg_count;
4946          else
4947               x_msg_count := l_msg_count;
4948          end if;
4949 
4950            /*no out variables to intialise back to null*/
4951            /*no inout variables to initialize to their initial values*/
4952 
4953          --reset the error stack;
4954          if l_debug_mode = 'Y' then
4955               pa_debug.reset_curr_function;
4956          end if;
4957 
4958   when fnd_api.g_exc_unexpected_error then
4959          --do a rollback;
4960          if p_commit = fnd_api.g_true then
4961               rollback to  take_action;
4962          end if;
4963 
4964          x_return_status := fnd_api.g_ret_sts_unexp_error;
4965          fnd_msg_pub.add_exc_msg(p_pkg_name       => 'PA_CONTROL_API_PUB',
4966                                  p_procedure_name => 'take_action',
4967                                  p_error_text     => substrb(sqlerrm,1,240));
4968          fnd_msg_pub.count_and_get(p_count => x_msg_count,
4969                                    p_data  => x_msg_data);
4970 
4971            /*no out variables to intialise back to null*/
4972            /*no inout variables to initialize to their initial values*/
4973 
4974          --reset the error stack;
4975          if l_debug_mode = 'Y' then
4976               pa_debug.reset_curr_function;
4977          end if;
4978 
4979   when others then
4980          --do a rollback;
4981          if p_commit = fnd_api.g_true then
4982               rollback to  take_action;
4983          end if;
4984 
4985          x_return_status := fnd_api.g_ret_sts_unexp_error;
4986          fnd_msg_pub.add_exc_msg(p_pkg_name       => 'PA_CONTROL_API_PUB',
4987                                  p_procedure_name => 'take_action',
4988                                  p_error_text     => substrb(sqlerrm,1,240));
4989          fnd_msg_pub.count_and_get(p_count => x_msg_count,
4990                                    p_data  => x_msg_data);
4991 
4992            /*no out variables to intialise back to null*/
4993            /*no inout variables to initialize to their initial values*/
4994 
4995          --reset the error stack;
4996          if l_debug_mode = 'Y' then
4997               pa_debug.reset_curr_function;
4998          end if;
4999 
5000 end TAKE_ACTION;
5001 
5002 
5003 Procedure Cancel_Action(
5004                         p_commit              IN    VARCHAR2 := FND_API.G_FALSE,
5005                         p_init_msg_list       IN    VARCHAR2 := FND_API.G_FALSE,
5006                         p_api_version_number  IN    NUMBER,
5007                         x_return_status       OUT NOCOPY  VARCHAR2,
5008                         x_msg_count           OUT NOCOPY  NUMBER,
5009                         x_msg_data            OUT NOCOPY  VARCHAR2,
5010                         p_ci_id               IN    NUMBER := G_PA_MISS_NUM,
5011                         p_action_id           IN    NUMBER := G_PA_MISS_NUM,
5012                         p_action_number       IN    NUMBER := G_PA_MISS_NUM,
5013                         p_cancel_comment      IN    VARCHAR2 := G_PA_MISS_CHAR
5014                         )
5015 IS
5016 
5017 cursor c_get_ci_id (c_action_id number)
5018 is                    --status_code is added to check only open action can be closed
5019    select ci_id , record_version_number, created_by , status_code
5020    from pa_ci_actions
5021    where ci_action_id = c_action_id;
5022 
5023 
5024 
5025   l_msg_count                              NUMBER := 0;
5026   l_data                                   VARCHAR2(2000);
5027   l_msg_data                               VARCHAR2(2000);
5028   l_msg_index_out                          NUMBER;
5029   l_module_name                            VARCHAR2(200):= 'PA_CONTROL_API_PUB.Cancel_Action';
5030   l_assignee_id                            NUMBER := null;
5031   l_user_id                                NUMBER := 0;
5032   l_action_id                             pa_ci_actions.ci_action_id%type;
5033   l_ci_id                                 pa_control_items.ci_id%type;
5034   l_record_version_number                 pa_ci_actions.record_version_number%type;
5035   l_status_code                           pa_ci_actions.status_code%type;
5036   check_s                                  VARCHAR2(1);
5037   l_created_by                             NUMBER;
5038   l_project_id                             pa_control_items.project_id%TYPE;
5039 
5040 begin
5041 
5042         x_return_status := FND_API.G_RET_STS_SUCCESS;
5043         x_msg_count := 0;
5044 
5045         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
5046 
5047         IF l_debug_mode = 'Y' THEN
5048                 PA_DEBUG.set_curr_function(p_function => 'Cancel_Action', p_debug_mode => l_debug_mode);
5049         END IF;
5050 
5051         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
5052                 FND_MSG_PUB.initialize;
5053         END IF;
5054 
5055         IF p_commit = FND_API.G_TRUE THEN
5056                 savepoint CANCEL_ACTION_SVPT;
5057         END IF;
5058 
5059         IF l_debug_mode = 'Y' THEN
5060                 pa_debug.write(l_module_name, 'Start of Cancel_Action', l_debug_level3);
5061         END IF;
5062 
5063   --Get the user_id for the logged in user
5064   l_user_id  := fnd_global.user_id;
5065 
5066 
5067    /*Calling the procedure in PA_CONTROL_API_PVT.validate_priv_and_action to validate the
5068     P_ci_id and action_id and action number. and it returns the action_id*/
5069      if (l_debug_mode = 'Y') then
5070              pa_debug.g_err_stage := 'Before calling the PA_CONTROL_API_PVT.validate_priv_and_action';
5071              pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5072      end if;
5073      PA_CONTROL_API_PVT.validate_priv_and_action(
5074                                                 p_ci_id                   =>  p_ci_id
5075                                                ,p_action_id               =>  p_action_id
5076                                                ,p_action_number           =>  p_action_number
5077                                                ,x_action_id               =>  l_action_id
5078                                                ,x_assignee_id             =>  l_assignee_id
5079                                                ,x_project_id              =>  l_project_id
5080                                                ,x_return_status           =>  x_return_status
5081                                                ,x_msg_count               =>  x_msg_count
5082                                                ,x_msg_data                =>  x_msg_data
5083                                               );
5084 
5085    /* Get the control item id(if it is passed also with action_id) to check the security */
5086    if x_return_status = FND_API.G_RET_STS_SUCCESS then
5087                 open c_get_ci_id(l_action_id);
5088                 fetch c_get_ci_id into l_ci_id,l_record_version_number,l_created_by, l_status_code;
5089                 if c_get_ci_id%notfound then
5090                         pa_utils.add_message(p_app_short_name    => 'PA',
5091                                               p_msg_name          => 'PA_CI_INV_ACT_ID');
5092                         if (l_debug_mode = 'Y') then
5093                                 pa_debug.g_err_stage := 'invalid action_id passed';
5094                                 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5095                         end if;
5096 			x_return_status := FND_API.G_RET_STS_ERROR;
5097                         close c_get_ci_id;
5098                         raise FND_API.G_EXC_ERROR;
5099                 else
5100 		/*User can only delete the actions, which are created by him*/
5101 		close c_get_ci_id;
5102 			if l_created_by <> l_user_id then
5103 				pa_utils.add_message(p_app_short_name    => 'PA',
5104 					             p_msg_name          => 'PA_CI_ACTION_NO_ACCESS');
5105 				if (l_debug_mode = 'Y') then
5106 					pa_debug.g_err_stage := 'invalid action_id passed';
5107 					pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5108 				end if;
5109 				x_return_status := FND_API.G_RET_STS_ERROR;
5110 
5111 				raise FND_API.G_EXC_ERROR;
5112 			end if;
5113 			if l_status_code <> 'CI_ACTION_OPEN' then
5114 				pa_utils.add_message(p_app_short_name    => 'PA',
5115 					             p_msg_name          => 'PA_CI_CANCEL_OPEN_ACTION');
5116 				if (l_debug_mode = 'Y') then
5117 					pa_debug.g_err_stage := 'Only open actions can be cancelled';
5118 					pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5119 				end if;
5120 				x_return_status := FND_API.G_RET_STS_ERROR;
5121 				raise FND_API.G_EXC_ERROR;
5122 			end if;
5123 
5124                end if;
5125    end if;
5126 
5127 
5128    /*Security check  - whether the cancel button is existing in the UI*/
5129    check_s := pa_ci_security_pkg.check_item_owner_project_auth(l_ci_id);
5130 
5131    if check_s <> 'T' then
5132          PA_UTILS.add_Message( p_app_short_name => 'PA'
5133                               ,p_msg_name       => 'PA_CI_NO_UPDATE_ACCESS');
5134          x_return_status := FND_API.G_RET_STS_ERROR;
5135          if l_debug_mode = 'Y' then
5136                pa_debug.g_err_stage:= 'Does not have the update access';
5137                pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5138          end if;
5139          raise FND_API.G_EXC_ERROR;
5140    end if;
5141 
5142   --------------------------------------------------------------
5143    /*Need to chck for the open notification details cancelling*/
5144    -------------------------------------------------------------
5145         if l_debug_mode = 'Y' then
5146                pa_debug.g_err_stage:= 'Before calling the pa_ci_actions_pvt.cancel_ci_action';
5147                pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5148         end if;
5149 
5150 	if x_return_status = FND_API.G_RET_STS_SUCCESS THEN
5151 
5152 	    pa_ci_actions_pvt.cancel_ci_action(
5153                                p_api_version           => 1.0,
5154                                p_init_msg_list         => FND_API.G_FALSE,
5155                                p_commit                => p_commit,
5156                                p_validate_only         => 'F',
5157                                p_ci_action_id          => l_action_id,
5158                                p_record_version_number => l_record_version_number,
5159                                p_cancel_comment        => p_cancel_comment,
5160                                x_return_status         => x_return_status,
5161                                x_msg_count             => x_msg_count,
5162                                x_msg_data              => x_msg_data
5163                               );
5164           end if;
5165 
5166           IF p_commit = FND_API.G_TRUE and x_return_status = FND_API.G_RET_STS_SUCCESS THEN
5167                 COMMIT;
5168           elsif  x_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
5169                 raise FND_API.G_EXC_ERROR;
5170           END IF;
5171            --Reset the stack
5172          if l_debug_mode = 'Y' then
5173                   Pa_Debug.reset_curr_function;
5174          end if;
5175 
5176 EXCEPTION
5177 WHEN FND_API.G_EXC_ERROR THEN
5178          x_return_status := FND_API.G_RET_STS_ERROR;
5179          l_msg_count := FND_MSG_PUB.COUNT_MSG;
5180 
5181           IF p_commit = 'T' THEN
5182             ROLLBACK to CANCEL_ACTION_SVPT;
5183           END IF;
5184 
5185          if l_msg_count = 1 then
5186               pa_interface_utils_pub.get_messages
5187                             (p_encoded        => fnd_api.g_false,
5188                              p_msg_index      => 1,
5189                              p_msg_count      => l_msg_count ,
5190                              p_msg_data       => l_msg_data ,
5191                              p_data           => l_data,
5192                              p_msg_index_out  => l_msg_index_out );
5193               x_msg_data  :=  l_data;
5194               x_msg_count := l_msg_count;
5195          else
5196               x_msg_count := l_msg_count;
5197          end if;
5198 
5199          --Reset the stack
5200          if l_debug_mode = 'Y' then
5201                   Pa_Debug.reset_curr_function;
5202          end if;
5203 
5204 when others then
5205 
5206          x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5207          x_msg_data      := substr(SQLERRM,1,240);
5208 
5209          IF p_commit = FND_API.G_TRUE THEN
5210                 ROLLBACK TO CANCEL_ACTION_SVPT;
5211          END IF;
5212 
5213 
5214          fnd_msg_pub.add_exc_msg ( p_pkg_name        => 'PA_CONTROL_API_PUB',
5215                                    p_procedure_name  => 'CANCEL_ACTION',
5216                                    p_error_text      => x_msg_data);
5217         x_msg_count     := FND_MSG_PUB.count_msg;
5218         --Reset the stack
5219          if l_debug_mode = 'Y' then
5220                   Pa_Debug.reset_curr_function;
5221          end if;
5222 
5223 end Cancel_Action;
5224 
5225 
5226 
5227 /*
5228         Procedure Delete_Issue.
5229         Internally calls the procedure PA_CONTROL_API_PVT.Delete_CI
5230         to delete the Issue. The internal procedure is responsible
5231         for all validations.
5232 */
5233 Procedure Delete_Issue (
5234                         p_Commit                IN VARCHAR2 DEFAULT FND_API.G_FALSE
5235                         , p_Init_Msg_List       IN VARCHAR2 DEFAULT FND_API.G_FALSE
5236                         , p_Api_Version_Number  IN NUMBER
5237                         , p_Ci_Id               IN NUMBER
5238                         , x_Return_Status       OUT NOCOPY VARCHAR2
5239                         , x_Msg_Count           OUT NOCOPY NUMBER
5240                         , x_Msg_Data            OUT NOCOPY VARCHAR2
5241                         )
5242 IS
5243         -- Local Variables.
5244         l_Msg_Count             NUMBER := 0;
5245         l_Data                  VARCHAR2(2000);
5246         l_Msg_Data              VARCHAR2(2000);
5247         l_Msg_Index_Out         NUMBER;
5248         l_module_name           VARCHAR2(200):= 'PA_CONTROL_API_PUB.Delete_Issue';
5249 	l_CiTypeClassCode	VARCHAR2(30);
5250 	l_Issue			VARCHAR2(30) := 'ISSUE';
5251         -- End: Local Variables.
5252 BEGIN
5253 
5254 	l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
5255 
5256         IF l_debug_mode = 'Y' THEN
5257                 PA_DEBUG.set_curr_function(p_function => 'Delete_Issue', p_debug_mode => l_debug_mode);
5258         END IF;
5259 
5260 	-- Clear the Global PL/SQL Message table.
5261         IF FND_API.TO_BOOLEAN(nvl(p_Init_Msg_List, FND_API.G_TRUE)) THEN
5262                 FND_MSG_PUB.initialize;
5263         END IF;
5264 
5265         IF p_commit = FND_API.G_TRUE THEN
5266                 savepoint DELETE_ISSUE_SVPT;
5267         END IF;
5268 
5269         IF l_debug_mode = 'Y' THEN
5270                 pa_debug.write(l_module_name, 'Start of Delete_Issue', l_debug_level3);
5271         END IF;
5272         -- Initialize the Error Stack.
5273       --  PA_DEBUG.Init_Err_Stack ('PA_CONTROL_API_PUB.Delete_Issue');
5274 
5275         -- Initialize the Return Status to Success.
5276         x_Return_Status := FND_API.g_Ret_Sts_Success;
5277         x_Msg_Count := 0;
5278 
5279 
5280 
5281 	-- Check whether the Ci_Id that is passed in is for an Issue or not.
5282 	OPEN Get_CI_Type_Class_Code (p_Ci_Id);
5283 	FETCH Get_CI_Type_Class_Code INTO l_CiTypeClassCode;
5284 	IF (Get_CI_Type_Class_Code%FOUND AND l_CiTypeClassCode <> l_Issue) THEN
5285 		-- Close the Cursor.
5286 		CLOSE Get_CI_Type_Class_Code;
5287 
5288 		-- Add the Error Message to the Stack.
5289 		PA_UTILS.Add_Message (
5290 			p_App_Short_Name	=> 'PA'
5291 			, p_Msg_Name		=> 'PA_CI_INV_CI_ID');
5292 		-- Raise the Error.
5293 	       if l_debug_mode = 'Y' then
5294 			pa_debug.g_err_stage:= 'Invalid API Use';
5295 		        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5296 	       end if;
5297 		RAISE FND_API.G_EXC_ERROR;
5298 	END IF;
5299 	CLOSE Get_CI_Type_Class_Code;
5300 
5301         -- Call the procedure Delete_CI to delete the Control Item.
5302         PA_CONTROL_API_PVT.Delete_CI (
5303                         p_Commit                => p_Commit
5304                         , p_Init_Msg_List       => 'F'
5305                         , p_Api_Version_Number  => p_Api_Version_Number
5306                         , p_Ci_Id               => p_Ci_Id
5307                         , x_Return_Status       => x_Return_Status
5308                         , x_Msg_Count           => x_Msg_Count
5309                         , x_Msg_Data            => x_Msg_Data
5310                   );
5311 
5312 	 IF p_commit = FND_API.G_TRUE and x_return_status = FND_API.G_RET_STS_SUCCESS THEN
5313                 COMMIT;
5314          elsif  x_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
5315                 raise FND_API.G_EXC_ERROR;
5316          END IF;
5317 
5318         -- Reset the Error Stack.
5319          if l_debug_mode = 'Y' then
5320                   Pa_Debug.reset_curr_function;
5321          end if;
5322 
5323         -- If any Exception then catch it.
5324         EXCEPTION
5325         WHEN FND_API.G_EXC_ERROR THEN
5326                 -- Set the Return Status as Error.
5327                 x_Return_Status := FND_API.g_Ret_Sts_Error;
5328                 -- Get the Message Count.
5329                 l_Msg_Count := FND_MSG_PUB.Count_Msg;
5330 		--Roll back
5331 		IF p_commit = FND_API.G_TRUE THEN
5332 		        ROLLBACK TO DELETE_ISSUE_SVPT;
5333 	        END IF;
5334                 IF (l_Msg_Count = 1) THEN
5335                         PA_INTERFACE_UTILS_PUB.Get_Messages (
5336                                 p_Encoded               => FND_API.g_False
5337                                 , p_Msg_Index           => 1
5338                                 , p_Msg_Count           => l_Msg_Count
5339                                 , p_Msg_Data            => l_Msg_Data
5340                                 , p_Data                => l_Data
5341                                 , p_Msg_Index_Out       => l_Msg_Index_Out
5342                                 );
5343                         x_Msg_Data := l_Data;
5344                         x_Msg_Count := l_Msg_Count;
5345                 ELSE
5346                         x_Msg_Count := l_Msg_Count;
5347                 END IF;
5348 
5349                --Reset the stack
5350 		 if l_debug_mode = 'Y' then
5351 			  Pa_Debug.reset_curr_function;
5352 		 end if;
5353 
5354         WHEN OTHERS THEN
5355                 -- Set the Return Status as Error.
5356                 x_Return_Status := FND_API.g_Ret_Sts_Unexp_Error;
5357 		--Roll back the changes.
5358 		IF p_commit = FND_API.G_TRUE THEN
5359 		        ROLLBACK TO DELETE_ISSUE_SVPT;
5360 	        END IF;
5361 
5362                 -- Add the message that is reported in SQL Error.
5363                 FND_MSG_PUB.Add_Exc_Msg (
5364                         p_Pkg_Name       => 'PA_CONTROL_API_PUB',
5365                         p_Procedure_Name => 'Delete_Issue',
5366                         p_Error_Text     => SUBSTRB (sqlerrm, 1, 240)
5367                         );
5368 
5369                 FND_MSG_PUB.Count_And_Get (
5370                         p_Count => x_Msg_Count,
5371                         p_Data  => x_Msg_Data
5372                         );
5373 
5374                --Reset the stack
5375 		  if l_debug_mode = 'Y' then
5376 			 Pa_Debug.reset_curr_function;
5377 		  end if;
5378 END Delete_Issue;
5379 
5380 /*
5381         Procedure Delete_Change_Request.
5382         Internally calls the procedure PA_CONTROL_API_PVT.Delete_CI
5383         to delete the Issue. The internal procedure is responsible
5384         for all validations.
5385 */
5386 Procedure Delete_Change_Request (
5387                         p_Commit                IN VARCHAR2 DEFAULT FND_API.G_FALSE
5388                         , p_Init_Msg_List       IN VARCHAR2 DEFAULT FND_API.G_FALSE
5389                         , p_Api_Version_Number  IN NUMBER
5390                         , p_Ci_Id               IN NUMBER
5391                         , x_Return_Status       OUT NOCOPY VARCHAR2
5392                         , x_Msg_Count           OUT NOCOPY NUMBER
5393                         , x_Msg_Data            OUT NOCOPY VARCHAR2
5394                         )
5395 IS
5396         -- Local Variables.
5397         l_Msg_Count             NUMBER := 0;
5398         l_Data                  VARCHAR2(2000);
5399         l_Msg_Data              VARCHAR2(2000);
5400         l_Msg_Index_Out         NUMBER;
5401         l_module_name           VARCHAR2(200):= 'PA_CONTROL_API_PUB.Delete_Change_Request';
5402 	l_CiTypeClassCode	VARCHAR2(30);
5403 	l_ChangeRequest		VARCHAR2(30) := 'CHANGE_REQUEST';
5404         -- End: Local Variables.
5405 BEGIN
5406 	l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
5407 
5408         IF l_debug_mode = 'Y' THEN
5409                 PA_DEBUG.set_curr_function(p_function => 'Delete_Change_Request', p_debug_mode => l_debug_mode);
5410         END IF;
5411 
5412 	-- Clear the Global PL/SQL Message table.
5413         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
5414                 FND_MSG_PUB.initialize;
5415         END IF;
5416 
5417         IF p_commit = FND_API.G_TRUE THEN
5418                 savepoint DELETE_CR_SVPT;
5419         END IF;
5420 
5421         IF l_debug_mode = 'Y' THEN
5422                 pa_debug.write(l_module_name, 'Start of Delete_Change_Request', l_debug_level3);
5423         END IF;
5424 
5425         -- Initialize the Error Stack.
5426         --PA_DEBUG.Init_Err_Stack ('PA_CONTROL_API_PUB.Delete_Change_Request');
5427 
5428         -- Initialize the Return Status to Success.
5429         x_Return_Status := FND_API.g_Ret_Sts_Success;
5430         x_Msg_Count := 0;
5431 
5432 
5433 
5434 	-- Check whether the Ci_Id that is passed in is for a CR or not.
5435 	OPEN Get_CI_Type_Class_Code (p_Ci_Id);
5436 	FETCH Get_CI_Type_Class_Code INTO l_CiTypeClassCode;
5437 	IF (Get_CI_Type_Class_Code%FOUND AND l_CiTypeClassCode <> l_ChangeRequest) THEN
5438 		-- Close the Cursor.
5439 		CLOSE Get_CI_Type_Class_Code;
5440 
5441 		-- Add the Error Message to the Stack.
5442 		PA_UTILS.Add_Message (
5443 			p_App_Short_Name	=> 'PA'
5444 			, p_Msg_Name		=> 'PA_CI_INV_CI_ID');
5445 		if l_debug_mode = 'Y' then
5446 			pa_debug.g_err_stage:= 'Invalid API Use';
5447 		        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5448 	        end if;
5449 		-- Raise the Error.
5450 		RAISE FND_API.G_EXC_ERROR;
5451 	END IF;
5452 	CLOSE Get_CI_Type_Class_Code;
5453 
5454         -- Call the procedure Delete_CI to delete the Control Item.
5455         PA_CONTROL_API_PVT.Delete_CI (
5456                         p_Commit                => p_Commit
5457                         , p_Init_Msg_List       => 'F'
5458                         , p_Api_Version_Number  => p_Api_Version_Number
5459                         , p_Ci_Id               => p_Ci_Id
5460                         , x_Return_Status       => x_Return_Status
5461                         , x_Msg_Count           => x_Msg_Count
5462                         , x_Msg_Data            => x_Msg_Data
5463                   );
5464 
5465 
5466 	 IF p_commit = FND_API.G_TRUE and x_return_status = FND_API.G_RET_STS_SUCCESS THEN
5467                 COMMIT;
5468          elsif  x_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
5469                 raise FND_API.G_EXC_ERROR;
5470          END IF;
5471 
5472 
5473         --Reset the stack
5474 	 if l_debug_mode = 'Y' then
5475 		 Pa_Debug.reset_curr_function;
5476 	  end if;
5477 
5478         -- If any Exception then catch it.
5479         EXCEPTION
5480         WHEN FND_API.G_EXC_ERROR THEN
5481                 -- Set the Return Status as Error.
5482                 x_Return_Status := FND_API.g_Ret_Sts_Error;
5483                 -- Get the Message Count.
5484                 l_Msg_Count := FND_MSG_PUB.Count_Msg;
5485 
5486 		IF p_commit = FND_API.G_TRUE THEN
5487 		        ROLLBACK TO DELETE_CR_SVPT;
5488 	        END IF;
5489 
5490                 IF (l_Msg_Count = 1) THEN
5491                         PA_INTERFACE_UTILS_PUB.Get_Messages (
5492                                 p_Encoded               => FND_API.g_False
5493                                 , p_Msg_Index           => 1
5494                                 , p_Msg_Count           => l_Msg_Count
5495                                 , p_Msg_Data            => l_Msg_Data
5496                                 , p_Data                => l_Data
5497                                 , p_Msg_Index_Out       => l_Msg_Index_Out
5498                                 );
5499                         x_Msg_Data := l_Data;
5500                         x_Msg_Count := l_Msg_Count;
5501                 ELSE
5502                         x_Msg_Count := l_Msg_Count;
5503                 END IF;
5504 
5505 
5506                 --Reset the stack
5507 		  if l_debug_mode = 'Y' then
5508 			 Pa_Debug.reset_curr_function;
5509 		  end if;
5510 
5511         WHEN OTHERS THEN
5512                 -- Set the Return Status as Error.
5513                 x_Return_Status := FND_API.g_Ret_Sts_Unexp_Error;
5514 
5515 		IF p_commit = FND_API.G_TRUE THEN
5516 		        ROLLBACK TO DELETE_CR_SVPT;
5517 	        END IF;
5518 
5519                 -- Add the message that is reported in SQL Error.
5520                 FND_MSG_PUB.Add_Exc_Msg (
5521                         p_Pkg_Name       => 'PA_CONTROL_API_PUB',
5522                         p_Procedure_Name => 'Delete_Change_Request',
5523                         p_Error_Text     => SUBSTRB (sqlerrm, 1, 240)
5524                         );
5525 
5526                 FND_MSG_PUB.Count_And_Get (
5527                         p_Count => x_Msg_Count,
5528                         p_Data  => x_Msg_Data
5529                         );
5530 
5531                 -- Reset the Error Stack.
5532                   if l_debug_mode = 'Y' then
5533 			 Pa_Debug.reset_curr_function;
5534 		  end if;
5535 END Delete_Change_Request;
5536 
5537 /*
5538         Procedure Delete_Change_Order.
5539         Internally calls the procedure PA_CONTROL_API_PVT.Delete_CI
5540         to delete the Issue. The internal procedure is responsible
5541         for all validations.
5542 */
5543 Procedure Delete_Change_Order (
5544                         p_Commit                IN VARCHAR2 DEFAULT FND_API.G_FALSE
5545                         , p_Init_Msg_List       IN VARCHAR2 DEFAULT FND_API.G_FALSE
5546                         , p_Api_Version_Number  IN NUMBER
5547                         , p_Ci_Id               IN NUMBER
5548                         , x_Return_Status       OUT NOCOPY VARCHAR2
5549                         , x_Msg_Count           OUT NOCOPY NUMBER
5550                         , x_Msg_Data            OUT NOCOPY VARCHAR2
5551                         )
5552 IS
5553         -- Local Variables.
5554         l_Msg_Count             NUMBER := 0;
5555         l_Data                  VARCHAR2(2000);
5556         l_Msg_Data              VARCHAR2(2000);
5557         l_Msg_Index_Out         NUMBER;
5558         l_module_name           VARCHAR2(200):= 'PA_CONTROL_API_PUB.Delete_Change_Order';
5559 	l_CiTypeClassCode	VARCHAR2(30);
5560 	l_ChangeOrder		VARCHAR2(30) := 'CHANGE_ORDER';
5561         -- End: Local Variables.
5562 BEGIN
5563 	l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
5564 
5565         IF l_debug_mode = 'Y' THEN
5566                 PA_DEBUG.set_curr_function(p_function => 'Delete_Change_Order', p_debug_mode => l_debug_mode);
5567         END IF;
5568 
5569 	-- Clear the Global PL/SQL Message table.
5570         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
5571                 FND_MSG_PUB.initialize;
5572         END IF;
5573 
5574         IF p_commit = FND_API.G_TRUE THEN
5575                 savepoint DELETE_CO_SVPT;
5576         END IF;
5577 
5578         IF l_debug_mode = 'Y' THEN
5579                 pa_debug.write(l_module_name, 'Start of Delete_Change_Order', l_debug_level3);
5580         END IF;
5581         -- Initialize the Error Stack.
5582         --PA_DEBUG.Init_Err_Stack ('PA_CONTROL_API_PUB.Delete_Change_Order');
5583 
5584         -- Initialize the Return Status to Success.
5585         x_Return_Status := FND_API.g_Ret_Sts_Success;
5586         x_Msg_Count := 0;
5587 
5588 
5589 	-- Check whether the Ci_Id that is passed in is for a CO or not.
5590 	OPEN Get_CI_Type_Class_Code (p_Ci_Id);
5591 	FETCH Get_CI_Type_Class_Code INTO l_CiTypeClassCode;
5592 	IF (Get_CI_Type_Class_Code%FOUND AND l_CiTypeClassCode <> l_ChangeOrder) THEN
5593 		-- Close the Cursor.
5594 		CLOSE Get_CI_Type_Class_Code;
5595 
5596 		-- Add the Error Message to the Stack.
5597 		PA_UTILS.Add_Message (
5598 			p_App_Short_Name	=> 'PA'
5599 			, p_Msg_Name		=> 'PA_CI_INV_CI_ID');
5600 		if l_debug_mode = 'Y' then
5601 			pa_debug.g_err_stage:= 'Invalid API Use';
5602 		        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5603 	        end if;
5604 		-- Raise an Error.
5605 		RAISE FND_API.G_EXC_ERROR;
5606 	END IF;
5607 	CLOSE Get_CI_Type_Class_Code;
5608 
5609         -- Call the procedure Delete_CI to delete the Control Item.
5610         PA_CONTROL_API_PVT.Delete_CI (
5611                         p_Commit                => p_Commit
5612                         , p_Init_Msg_List       => 'F'
5613                         , p_Api_Version_Number  => p_Api_Version_Number
5614                         , p_Ci_Id               => p_Ci_Id
5615                         , x_Return_Status       => x_Return_Status
5616                         , x_Msg_Count           => x_Msg_Count
5617                         , x_Msg_Data            => x_Msg_Data
5618                   );
5619 
5620 	 IF p_commit = FND_API.G_TRUE and x_return_status = FND_API.G_RET_STS_SUCCESS THEN
5621                 COMMIT;
5622          elsif  x_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
5623                 raise FND_API.G_EXC_ERROR;
5624          END IF;
5625 
5626         -- Reset the Error Stack.
5627         if l_debug_mode = 'Y' then
5628 		 Pa_Debug.reset_curr_function;
5629 	end if;
5630 
5631         -- If any Exception then catch it.
5632         EXCEPTION
5633         WHEN FND_API.G_EXC_ERROR THEN
5634                 -- Set the Return Status as Error.
5635                 x_Return_Status := FND_API.g_Ret_Sts_Error;
5636                 -- Get the Message Count.
5637                 l_Msg_Count := FND_MSG_PUB.Count_Msg;
5638 
5639 		IF p_commit = FND_API.G_TRUE THEN
5640 		        ROLLBACK TO DELETE_CO_SVPT;
5641 	        END IF;
5642 
5643                 IF (l_Msg_Count = 1) THEN
5644                         PA_INTERFACE_UTILS_PUB.Get_Messages (
5645                                 p_Encoded               => FND_API.g_False
5646                                 , p_Msg_Index           => 1
5647                                 , p_Msg_Count           => l_Msg_Count
5648                                 , p_Msg_Data            => l_Msg_Data
5649                                 , p_Data                => l_Data
5650                                 , p_Msg_Index_Out       => l_Msg_Index_Out
5651                                 );
5652                         x_Msg_Data := l_Data;
5653                         x_Msg_Count := l_Msg_Count;
5654                 ELSE
5655                         x_Msg_Count := l_Msg_Count;
5656                 END IF;
5657 
5658 		 -- Reset the Error Stack.
5659 	        if l_debug_mode = 'Y' then
5660 			 Pa_Debug.reset_curr_function;
5661 		end if;
5662 
5663         WHEN OTHERS THEN
5664                 -- Set the Return Status as Error.
5665                 x_Return_Status := FND_API.g_Ret_Sts_Unexp_Error;
5666 
5667 		IF p_commit = FND_API.G_TRUE THEN
5668 		        ROLLBACK TO DELETE_CO_SVPT;
5669 	        END IF;
5670 
5671                 -- Add the message that is reported in SQL Error.
5672                 FND_MSG_PUB.Add_Exc_Msg (
5673                         p_Pkg_Name       => 'PA_CONTROL_API_PUB',
5674                         p_Procedure_Name => 'Delete_Change_Order',
5675                         p_Error_Text     => SUBSTRB (sqlerrm, 1, 240)
5676                         );
5677 
5678                 FND_MSG_PUB.Count_And_Get (
5679                         p_Count => x_Msg_Count,
5680                         p_Data  => x_Msg_Data
5681                         );
5682 
5683                 -- Reset the Error Stack.
5684 		if l_debug_mode = 'Y' then
5685 			Pa_Debug.reset_curr_function;
5686 		end if;
5687 END Delete_Change_Order;
5688 
5689 
5690 
5691 /*
5692         Procedure Add_Comments.
5693         Procedure for adding Comments to a particular Control Item.
5694         Validations done before initiating Add:
5695         1. Check whether the Control Item is valid or not.
5696         2. Check whether the logged in user has View acceess on
5697            the Control Item or not.
5698 */
5699 Procedure Add_Comments (
5700                         p_Commit                IN VARCHAR2 DEFAULT FND_API.G_FALSE
5701                         , p_Init_Msg_List       IN VARCHAR2 DEFAULT FND_API.G_FALSE
5702                         , p_Api_Version_Number  IN NUMBER
5703                         , p_Ci_Id               IN NUMBER
5704                         , p_Comments_Tbl        IN CI_COMMENTS_TBL_TYPE
5705                         , x_Return_Status       OUT NOCOPY VARCHAR2
5706                         , x_Msg_Count           OUT NOCOPY NUMBER
5707                         , x_Msg_Data            OUT NOCOPY VARCHAR2
5708                         )
5709 IS
5710         -- Local Variables.
5711         l_CiId                  NUMBER(15);
5712         l_CiCommentId           NUMBER(15);
5713         l_StatusCode            VARCHAR2(30);
5714         l_ProjectId             NUMBER(15);
5715         l_CiTypeClassCode       VARCHAR2(30);
5716         l_RecordVersionNumber   NUMBER(15);
5717 
5718 	l_module_name           VARCHAR2(200):= 'PA_CONTROL_API_PUB.Add_Comments';
5719         l_Msg_Count             NUMBER := 0;
5720         l_Data                  VARCHAR2(2000);
5721         l_Msg_Data              VARCHAR2(2000);
5722         l_Msg_Index_Out         NUMBER;
5723         -- End: Local Variables.
5724 BEGIN
5725 	l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
5726 
5727         IF l_debug_mode = 'Y' THEN
5728                 PA_DEBUG.set_curr_function(p_function => 'Add_Comments', p_debug_mode => l_debug_mode);
5729         END IF;
5730 
5731 	-- Clear the Global PL/SQL Message table.
5732         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
5733                 FND_MSG_PUB.initialize;
5734         END IF;
5735 
5736         IF l_debug_mode = 'Y' THEN
5737                 pa_debug.write(l_module_name, 'Start of Add_Comments', l_debug_level3);
5738         END IF;
5739 
5740         -- Set the SavePoint if we have been requested to Commit the Data.
5741         IF (p_Commit = FND_API.G_TRUE) THEN
5742             SAVEPOINT ADD_COMMENTS_SVPT;
5743         END IF;
5744 
5745         -- Initialize the Return Status to Success.
5746         x_Return_Status := FND_API.g_Ret_Sts_Success;
5747         x_Msg_Count := 0;
5748 
5749 
5750         -- If the Ci_Id that is passed in is NULL then report
5751         -- Error.
5752         IF (p_Ci_Id IS NULL) THEN
5753                 -- Add message to the Error Stack that Ci_Id is NULL.
5754                 PA_UTILS.Add_Message (
5755                         p_App_Short_Name => 'PA'
5756                         , p_Msg_Name => 'PA_CI_MISS_CI_ID'
5757                         );
5758 		if l_debug_mode = 'Y' then
5759 			pa_debug.g_err_stage:= 'CI_ID is not passed';
5760 		        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5761 	        end if;
5762                 -- Raise the Invalid Argument exception.
5763                 RAISE FND_API.G_EXC_ERROR;
5764         END IF;
5765 
5766         -- If the Ci_Id that is passed in does not exist then
5767         -- report Error.
5768         OPEN Check_Valid_CI (p_Ci_Id);
5769         FETCH Check_Valid_CI INTO l_CiId;
5770         IF (Check_Valid_CI%NOTFOUND) THEN
5771                 -- Close the Cursor.
5772                 CLOSE Check_Valid_CI;
5773 
5774                 -- Add message to the Error Stack that this Ci_Id is Invalid.
5775                 PA_UTILS.Add_Message (
5776                         p_App_Short_Name => 'PA'
5777                         , p_Msg_Name => 'PA_CI_INV_CI_ID'
5778                         );
5779 		if l_debug_mode = 'Y' then
5780 			pa_debug.g_err_stage:= 'CI_ID is invalid';
5781 		        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5782 	        end if;
5783                 -- Raise the Invalid Argument exception.
5784                 RAISE FND_API.G_EXC_ERROR;
5785         END IF;
5786         CLOSE Check_Valid_CI;
5787 
5788         -- Open Cursor Get_CI_Data and fetch the data into out local variables.
5789         OPEN Get_CI_Data (p_Ci_Id);
5790         FETCH Get_CI_Data INTO l_ProjectId, l_StatusCode, l_CiTypeClassCode, l_RecordVersionNumber;
5791         -- If NO_DATA_FOUND then report Error.
5792         IF (Get_CI_Data%NOTFOUND) THEN
5793                 -- Code to Report Error and Return.
5794 		if l_debug_mode = 'Y' then
5795 			pa_debug.g_err_stage:= 'CI_ID is invalid, No data founc in Get_CI_Data Cursor';
5796 		        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5797 	        end if;
5798                 CLOSE Get_CI_Data;
5799                 RAISE FND_API.G_EXC_ERROR;
5800         END IF;
5801         CLOSE Get_CI_Data;
5802 
5803 
5804 
5805         -- Adding of Comments is only allowed on a Control Item if
5806         --      1. The User has View access on the Control Item, ie
5807         --         he would be able to see the Control Item on the UI.
5808         IF (PA_CI_SECURITY_PKG.Check_View_Access (p_Ci_Id, l_ProjectId, l_StatusCode, l_CiTypeClassCode) = 'T') THEN
5809                 -- For each Comment in the passed in array, insert it.
5810 		if l_debug_mode = 'Y' then
5811 			pa_debug.g_err_stage:= 'Before Calling PA_CI_ACTIONS_PUB.Add_CI_Comment in a for loop';
5812 		        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5813 	        end if;
5814                 FOR i IN 1..p_Comments_Tbl.COUNT LOOP
5815                         PA_CI_ACTIONS_PUB.Add_CI_Comment (
5816                                 p_Api_Version           => p_Api_Version_Number
5817                                 , p_Init_Msg_List       => 'F'
5818                                 , p_Commit              => 'F'
5819                                 , p_Validate_Only       => 'F'
5820                                 , x_Ci_Comment_Id       => l_CiCommentId
5821                                 , p_Ci_Id               => p_Ci_Id
5822                                 , p_Type_Code           => 'UNSOLICITED'
5823                                 , p_Comment_Text        => p_Comments_Tbl(i)
5824                                 , p_Ci_Action_Id        => NULL
5825                                 , x_Return_Status       => x_Return_Status
5826                                 , x_Msg_Count           => x_Msg_Count
5827                                 , x_Msg_Data            => x_Msg_Data
5828                                 );
5829 
5830                         -- If at any time, the Return Status is not success
5831                         -- then raise exception to rollbakc all changes.
5832                         IF (x_Return_Status <> FND_API.G_RET_STS_SUCCESS) THEN
5833                                 RAISE FND_API.G_EXC_ERROR;
5834                         END IF;
5835                 END LOOP;
5836         ELSE -- If View access is denied to the User for this Control Item.
5837                 -- Add message to the Error Stack that the user does not
5838                 -- have the privilege to update this Control Item.
5839                 PA_UTILS.Add_Message (
5840                         p_App_Short_Name => 'PA'
5841                         , p_Msg_Name => 'PA_CI_NO_ALLOW_UPDATE'
5842                         );
5843 
5844                 -- Raise exception.
5845                 RAISE FND_API.G_EXC_ERROR;
5846         END IF;
5847 
5848         -- Commit the data to the Database if p_Commit is True
5849         -- and there are no Errors.
5850         IF (p_Commit = FND_API.G_TRUE AND x_Return_Status = FND_API.G_RET_STS_SUCCESS) THEN
5851                 COMMIT;
5852         END IF;
5853 
5854         -- Reset the Error Stack.
5855 	if l_debug_mode = 'Y' then
5856 		Pa_Debug.reset_curr_function;
5857 	end if;
5858 
5859 	-- If any Exception then catch it.
5860         EXCEPTION
5861         WHEN FND_API.G_EXC_ERROR THEN
5862                 -- Rollback.
5863                 IF (p_Commit = FND_API.G_TRUE) THEN
5864                         ROLLBACK TO ADD_COMMENTS_SVPT;
5865                 END IF;
5866 
5867                 -- Set the Return Status as Error.
5868                 x_Return_Status := FND_API.g_Ret_Sts_Error;
5869                 -- Get the Message Count.
5870                 l_Msg_Count := FND_MSG_PUB.Count_Msg;
5871 
5872                 IF (l_Msg_Count = 1) THEN
5873                         PA_INTERFACE_UTILS_PUB.Get_Messages (
5874                                 p_Encoded               => FND_API.g_False
5875                                 , p_Msg_Index           => 1
5876                                 , p_Msg_Count           => l_Msg_Count
5877                                 , p_Msg_Data            => l_Msg_Data
5878                                 , p_Data                => l_Data
5879                                 , p_Msg_Index_Out       => l_Msg_Index_Out
5880                                 );
5881                         x_Msg_Data := l_Data;
5882                         x_Msg_Count := l_Msg_Count;
5883                 ELSE
5884                         x_Msg_Count := l_Msg_Count;
5885                 END IF;
5886 
5887                 -- Reset the Error Stack.
5888 		if l_debug_mode = 'Y' then
5889 			Pa_Debug.reset_curr_function;
5890 		end if;
5891 
5892         WHEN OTHERS THEN
5893                 -- Rollback.
5894                 IF (p_Commit = FND_API.G_TRUE) THEN
5895                         ROLLBACK TO ADD_COMMENTS_SVPT;
5896                 END IF;
5897 
5898                 -- Set the Return Status as Error.
5899                 x_Return_Status := FND_API.g_Ret_Sts_Unexp_Error;
5900 
5901                 -- Add the message that is reported in SQL Error.
5902                 FND_MSG_PUB.Add_Exc_Msg (
5903                         p_Pkg_Name       => 'PA_CONTROL_API_PUB',
5904                         p_Procedure_Name => 'Add_Comments',
5905                         p_Error_Text     => SUBSTRB (sqlerrm, 1, 240)
5906                         );
5907 
5908                 FND_MSG_PUB.Count_And_Get (
5909                         p_Count => x_Msg_Count,
5910                         p_Data  => x_Msg_Data
5911                         );
5912 
5913                 -- Reset the Error Stack.
5914 		if l_debug_mode = 'Y' then
5915 			Pa_Debug.reset_curr_function;
5916 		end if;
5917 END Add_Comments;
5918 
5919 
5920 
5921 /*
5922         Procedure Add_Related_Items.
5923         Procedure for adding Related Items to a particular Control Item.
5924         Validations done before initiating Add:
5925         1. Check whether the Control Item is valid or not.
5926         2. Check whether the logged in user has update access on the
5927            Control Item and whether the Control Item in question can
5928            be updated or not based on its current status.
5929 */
5930 Procedure Add_Related_Items (
5931                         p_Commit                IN VARCHAR2 DEFAULT FND_API.G_FALSE
5932                         , p_Init_Msg_List       IN VARCHAR2 DEFAULT FND_API.G_FALSE
5933                         , p_Api_Version_Number  IN NUMBER
5934                         , p_Ci_Id               IN NUMBER
5935                         , p_Related_Items_Tbl   IN REL_ITEM_IN_TABLE_TYPE
5936                         , x_Return_Status       OUT NOCOPY VARCHAR2
5937                         , x_Msg_Count           OUT NOCOPY NUMBER
5938                         , x_Msg_Data            OUT NOCOPY VARCHAR2
5939                         )
5940 IS
5941         -- Local Variables.
5942         l_CiId                  NUMBER(15);
5943         l_StatusCode            VARCHAR2(30);
5944         l_ProjectId             NUMBER(15);
5945         l_CiTypeClassCode       VARCHAR2(30);
5946         l_RecordVersionNumber   NUMBER(15);
5947 
5948 	l_module_name           VARCHAR2(200):= 'PA_CONTROL_API_PUB.Add_Related_Items';
5949         l_AnyError              VARCHAR2(1) := 'N';
5950         l_Msg_Count             NUMBER := 0;
5951         l_Data                  VARCHAR2(2000);
5952         l_Msg_Data              VARCHAR2(2000);
5953         l_Msg_Index_Out         NUMBER;
5954 
5955 	l_UpdateAccess          VARCHAR2(1);
5956         l_UpdateAllowed         VARCHAR2(1);
5957         -- End: Local Variables.
5958 BEGIN
5959 	l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
5960 
5961         IF l_debug_mode = 'Y' THEN
5962                 PA_DEBUG.set_curr_function(p_function => 'Add_Related_Items', p_debug_mode => l_debug_mode);
5963         END IF;
5964 
5965 	-- Clear the Global PL/SQL Message table.
5966         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
5967                 FND_MSG_PUB.initialize;
5968         END IF;
5969 
5970         IF l_debug_mode = 'Y' THEN
5971                 pa_debug.write(l_module_name, 'Start of Add_Related_Items', l_debug_level3);
5972         END IF;
5973         -- Initialize the Error Stack.
5974         --PA_DEBUG.Init_Err_Stack ('PA_CONTROL_API_PUB.Add_Related_Items');
5975 
5976         -- Set the SavePoint if we have been requested to Commit the Data.
5977         IF (p_Commit = FND_API.G_TRUE) THEN
5978             SAVEPOINT ADD_RELATED_ITEMS_SVPT;
5979         END IF;
5980 
5981         -- Initialize the Return Status to Success.
5982         x_Return_Status := FND_API.g_Ret_Sts_Success;
5983         x_Msg_Count := 0;
5984 
5985 
5986 
5987         -- If the Ci_Id that is passed in is NULL then report
5988         -- Error.
5989         IF (p_Ci_Id IS NULL) THEN
5990                 -- Add message to the Error Stack that Ci_Id is NULL.
5991                 PA_UTILS.Add_Message (
5992                         p_App_Short_Name => 'PA'
5993                         , p_Msg_Name => 'PA_CI_MISS_CI_ID'
5994                         );
5995 		if l_debug_mode = 'Y' then
5996 			pa_debug.g_err_stage:= 'CI_ID is not passed';
5997 		        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5998 	        end if;
5999                 -- Raise the Invalid Argument exception.
6000                 RAISE FND_API.G_EXC_ERROR;
6001         END IF;
6002 
6003         -- If the Ci_Id that is passed in does not exist then
6004         -- report Error.
6005         OPEN Check_Valid_CI (p_Ci_Id);
6006         FETCH Check_Valid_CI INTO l_CiId;
6007         IF (Check_Valid_CI%NOTFOUND) THEN
6008                 -- Close the Cursor.
6009                 CLOSE Check_Valid_CI;
6010 
6011                 -- Add message to the Error Stack that this Ci_Id is Invalid.
6012                 PA_UTILS.Add_Message (
6013                         p_App_Short_Name => 'PA'
6014                         , p_Msg_Name => 'PA_CI_INV_CI_ID'
6015                         );
6016 		if l_debug_mode = 'Y' then
6017 			pa_debug.g_err_stage:= 'CI_ID is Invalid';
6018 		        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6019 	        end if;
6020                 -- Raise the Invalid Argument exception.
6021                 RAISE FND_API.G_EXC_ERROR;
6022         END IF;
6023         CLOSE Check_Valid_CI;
6024 
6025         -- Open Cursor Get_CI_Data and fetch the data into our local variables.
6026         OPEN Get_CI_Data (p_Ci_Id);
6027         FETCH Get_CI_Data INTO l_ProjectId, l_StatusCode, l_CiTypeClassCode, l_RecordVersionNumber;
6028         -- If NO_DATA_FOUND then report Error.
6029         IF (Get_CI_Data%NOTFOUND) THEN
6030                 -- Code to Report Error and Return.
6031                 CLOSE Get_CI_Data;
6032                 RAISE FND_API.G_EXC_ERROR;
6033         END IF;
6034         CLOSE Get_CI_Data;
6035 
6036         -- Check whether Workflow is running on this Control Item or not.
6037         OPEN Check_Workflow_On_CI (p_Ci_Id);
6038         FETCH Check_Workflow_On_CI INTO l_CiId;
6039 
6040         -- If Workflow is not running on this Control Item then proceed,
6041         -- else report Error.
6042         IF (Check_Workflow_On_CI%NOTFOUND) THEN
6043                 CLOSE Check_Workflow_On_CI;
6044                 -- Adding of Related Items is only allowed on a Control Item if
6045                 --      1. The User has Update access on the Control Item.
6046                 --      2. Update is allowed on the Control Item in this particular
6047                 --         status.
6048 		l_UpdateAccess := PA_CI_SECURITY_PKG.Check_Update_Access (p_Ci_Id);
6049 		l_UpdateAllowed := PA_CONTROL_ITEMS_UTILS.CheckCIActionAllowed ('CONTROL_ITEM', l_StatusCode, 'CONTROL_ITEM_ALLOW_UPDATE', p_Ci_Id);
6050                 IF (l_UpdateAllowed = 'Y' AND l_UpdateAccess = 'T') THEN
6051                         -- For each Related Item in the passed in array, insert it.
6052                         FOR i IN 1..p_Related_Items_Tbl.COUNT LOOP
6053                                 -- If the Related Ci_Id that is passed in does not
6054                                 -- exist then report Error to rollback changes made
6055                                 -- till now.
6056                                 OPEN Check_Valid_CI (p_Related_Items_Tbl(i));
6057                                 FETCH Check_Valid_CI INTO l_CiId;
6058                                 IF (Check_Valid_CI%NOTFOUND OR p_Related_Items_Tbl(i) = p_Ci_Id) THEN
6059                                         -- Close the Cursor.
6060                                         CLOSE Check_Valid_CI;
6061 
6062                                         -- Add message to the Error Stack that this Ci_Id is Invalid.
6063                                         PA_UTILS.Add_Message (
6064                                                 p_App_Short_Name => 'PA'
6065                                                 , p_Msg_Name => 'PA_CI_RELATED_ITEM_INVALID'
6066                                                 , p_Token1 => 'NUMBER'
6067                                                 , p_Value1 => i
6068                                                 );
6069 					if l_debug_mode = 'Y' then
6070 						pa_debug.g_err_stage:= 'Invalid Related_Item ['||i||']';
6071 					        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6072 				        end if;
6073                                         -- Set the Error Occured flag.
6074                                         l_AnyError := 'Y';
6075                                 ELSE
6076                                         -- Close the Cursor.
6077                                         CLOSE Check_Valid_CI;
6078 					if l_debug_mode = 'Y' then
6079 						pa_debug.g_err_stage:= 'Before Calling PA_CONTROL_ITEMS_PVT.Add_Related_Item for the related item ['||i||']';
6080 					        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6081 				        end if;
6082                                         -- Call our API for insertion.
6083                                         PA_CONTROL_ITEMS_PVT.Add_Related_Item (
6084                                                 p_Api_Version           => p_Api_Version_Number
6085                                                 , p_Init_Msg_List       => 'F'
6086                                                 , p_Commit              => 'F'
6087                                                 , p_Validate_Only       => 'F'
6088                                                 , p_Ci_Id               => p_Ci_Id
6089                                                 , p_Related_Ci_Id       => p_Related_Items_Tbl(i)
6090                                                 , x_Return_Status       => x_Return_Status
6091                                                 , x_Msg_Count           => x_Msg_Count
6092                                                 , x_Msg_Data            => x_Msg_Data
6093                                                 );
6094 
6095                                         -- If at any time, the Return Status is not success
6096                                         -- then Raise Exception to Rollback all changes.
6097                                         IF (x_Return_Status <> FND_API.G_RET_STS_SUCCESS) THEN
6098                                                 RAISE FND_API.G_EXC_ERROR;
6099                                         END IF;
6100                                 END IF;
6101                         END LOOP;
6102 
6103                         -- Check for errors. If any related item was invalid,
6104                         -- then report Error and rollback all changes.
6105                         IF (l_AnyError = 'Y') THEN
6106                                 RAISE FND_API.G_EXC_ERROR;
6107                         END IF;
6108 		ELSE
6109 			-- Check if Update Access was denied or not.
6110                         IF (l_UpdateAccess <> 'T') THEN
6111                                 -- Add message to the Error Stack that the user does not
6112                                 -- have the privilege to update this Control Item.
6113                                 PA_UTILS.Add_Message (
6114                                         p_App_Short_Name => 'PA'
6115                                         , p_Msg_Name => 'PA_CI_UPDATE_NOT_ALLOWED'
6116                                         );
6117 				if l_debug_mode = 'Y' then
6118 					pa_debug.g_err_stage:= 'User does not have the privilege to update this Control Item.';
6119 				        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6120 				end if;
6121                         END IF;
6122 
6123                         -- Check if update was denied by Status Control or not.
6124                         IF (l_UpdateAllowed <> 'Y') THEN
6125                                 -- Add message to the Error Stack that this Control Item
6126                                 -- cannot be updated in its present status.
6127                                 PA_UTILS.Add_Message (
6128                                         p_App_Short_Name => 'PA'
6129                                         , p_Msg_Name => 'PA_CI_NO_ALLOW_UPDATE'
6130                                         );
6131 				if l_debug_mode = 'Y' then
6132 					pa_debug.g_err_stage:= 'This Control Item cannot be updated in its present status.';
6133 				        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6134 				end if;
6135                         END IF;
6136 
6137                         -- Raise the Invalid Argument exception.
6138                         RAISE FND_API.G_EXC_ERROR;
6139                 END IF;
6140         ELSE
6141                 -- Close the Cursor.
6142                 CLOSE Check_Workflow_On_CI;
6143 
6144                 -- Add message to the Error Stack that this Ci_Id has Workflow
6145                 -- attached.
6146                 PA_UTILS.Add_Message (
6147                         p_App_Short_Name => 'PA'
6148                         , p_Msg_Name => 'PA_CI_APPROVAL_WORKFLOW'
6149                         );
6150 		if l_debug_mode = 'Y' then
6151 			pa_debug.g_err_stage:= 'Ci_Id has Workflow attached.';
6152 			pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6153 		end if;
6154                 -- Raise the Invalid Argument exception.
6155                 RAISE FND_API.G_EXC_ERROR;
6156         END IF;
6157 
6158         -- Commit the data to the Database if p_Commit is True
6159         -- and there are no Errors.
6160         IF (p_Commit = FND_API.G_TRUE AND x_Return_Status = FND_API.G_RET_STS_SUCCESS) THEN
6161                 COMMIT;
6162         END IF;
6163 
6164            -- Reset the Error Stack.
6165 	if l_debug_mode = 'Y' then
6166 		Pa_Debug.reset_curr_function;
6167 	end if;
6168 
6169         -- If any Exception then catch it.
6170         EXCEPTION
6171         WHEN FND_API.G_EXC_ERROR THEN
6172                 -- Rollback.
6173                 IF (p_Commit = FND_API.G_TRUE) THEN
6174                         ROLLBACK TO ADD_RELATED_ITEMS_SVPT;
6175                 END IF;
6176 
6177                 -- Set the Return Status as Error.
6178                 x_Return_Status := FND_API.g_Ret_Sts_Error;
6179                 -- Get the Message Count.
6180                 l_Msg_Count := FND_MSG_PUB.Count_Msg;
6181 
6182                 IF (l_Msg_Count = 1) THEN
6183                         PA_INTERFACE_UTILS_PUB.Get_Messages (
6184                                 p_Encoded               => FND_API.g_False
6185                                 , p_Msg_Index           => 1
6186                                 , p_Msg_Count           => l_Msg_Count
6187                                 , p_Msg_Data            => l_Msg_Data
6188                                 , p_Data                => l_Data
6189                                 , p_Msg_Index_Out       => l_Msg_Index_Out
6190                                 );
6191                         x_Msg_Data := l_Data;
6192                         x_Msg_Count := l_Msg_Count;
6193                 ELSE
6194                         x_Msg_Count := l_Msg_Count;
6195                 END IF;
6196 
6197                    -- Reset the Error Stack.
6198 		if l_debug_mode = 'Y' then
6199 			Pa_Debug.reset_curr_function;
6200 		end if;
6201 
6202         WHEN OTHERS THEN
6203                 -- Rollback.
6204                 IF (p_Commit = FND_API.G_TRUE) THEN
6205                         ROLLBACK TO ADD_RELATED_ITEMS_SVPT;
6206                 END IF;
6207 
6208                 -- Set the Return Status as Error.
6209                 x_Return_Status := FND_API.g_Ret_Sts_Unexp_Error;
6210 
6211                 -- Add the message that is reported in SQL Error.
6212                 FND_MSG_PUB.Add_Exc_Msg (
6213                         p_Pkg_Name       => 'PA_CONTROL_API_PUB',
6214                         p_Procedure_Name => 'Add_Related_Items',
6215                         p_Error_Text     => SUBSTRB (sqlerrm, 1, 240)
6216                         );
6217 
6218                 FND_MSG_PUB.Count_And_Get (
6219                         p_Count => x_Msg_Count,
6220                         p_Data  => x_Msg_Data
6221                         );
6222 
6223                    -- Reset the Error Stack.
6224 		if l_debug_mode = 'Y' then
6225 			Pa_Debug.reset_curr_function;
6226 		end if;
6227 END Add_Related_Items;
6228 
6229 /*
6230         Procedure Delete_Related_Item.
6231         Procedure for deleting Related Items to a particular Control Item.
6232         Validations done before initiating Delete:
6233         1. Check whether the Control Item is valid or not.
6234         2. Check whether the logged in user has update access on the
6235            Control Item and whether the Control Item in question can
6236            be updated or not based on its current status.
6237 */
6238 Procedure Delete_Related_Item (
6239                         p_Commit                IN VARCHAR2 DEFAULT FND_API.G_FALSE
6240                         , p_Init_Msg_List       IN VARCHAR2 DEFAULT FND_API.G_FALSE
6241                         , p_Api_Version_Number  IN NUMBER
6242                         , p_Ci_Id               IN NUMBER
6243                         , p_To_Ci_Id            IN NUMBER
6244                         , x_Return_Status       OUT NOCOPY VARCHAR2
6245                         , x_Msg_Count           OUT NOCOPY NUMBER
6246                         , x_Msg_Data            OUT NOCOPY VARCHAR2
6247                         )
6248 IS
6249         -- Local Variables.
6250         l_CiId                  NUMBER(15);
6251         l_StatusCode            VARCHAR2(30);
6252         l_ProjectId             NUMBER(15);
6253         l_CiTypeClassCode       VARCHAR2(30);
6254         l_RecordVersionNumber   NUMBER(15);
6255 
6256         l_UpdateAccess          VARCHAR2(1);
6257         l_UpdateAllowed         VARCHAR2(1);
6258 	l_module_name           VARCHAR2(200):= 'PA_CONTROL_API_PUB.Delete_Related_Item';
6259         l_Msg_Count             NUMBER := 0;
6260         l_Data                  VARCHAR2(2000);
6261         l_Msg_Data              VARCHAR2(2000);
6262         l_Msg_Index_Out         NUMBER;
6263         -- End: Local Variables.
6264 BEGIN
6265 	l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.resp_id, 275, null, null), 'N');
6266 
6267         IF l_debug_mode = 'Y' THEN
6268                 PA_DEBUG.set_curr_function(p_function => 'Delete_Related_Item', p_debug_mode => l_debug_mode);
6269         END IF;
6270 
6271 	-- Clear the Global PL/SQL Message table.
6272         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
6273                 FND_MSG_PUB.initialize;
6274         END IF;
6275 
6276 	-- Set the SavePoint if we have been requested to Commit the Data.
6277         IF (p_Commit = FND_API.G_TRUE) THEN
6278             SAVEPOINT DELETE_RELATED_ITEMS_SVPT;
6279         END IF;
6280 
6281 
6282         IF l_debug_mode = 'Y' THEN
6283                 pa_debug.write(l_module_name, 'Start of Delete_Related_Item', l_debug_level3);
6284         END IF;
6285         -- Initialize the Error Stack.
6286         --PA_DEBUG.Init_Err_Stack ('PA_CONTROL_API_PUB.Delete_Related_Item');
6287 
6288         -- Initialize the Return Status to Success.
6289         x_Return_Status := FND_API.g_Ret_Sts_Success;
6290         x_Msg_Count := 0;
6291 
6292 
6293         -- If any of the Ci_Ids that are passed in is NULL then
6294         -- report Error.
6295         IF (p_Ci_Id IS NULL OR p_To_Ci_Id IS NULL) THEN
6296                 -- Add message to the Error Stack that Ci_Id is NULL.
6297                 PA_UTILS.Add_Message (
6298                         p_App_Short_Name => 'PA'
6299                         , p_Msg_Name => 'PA_CI_MISS_CI_ID'
6300                         );
6301 		if l_debug_mode = 'Y' then
6302 			pa_debug.g_err_stage:= 'CI_ID or TO_CI_ID is not passed';
6303 		        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6304 	        end if;
6305                 -- Raise the Invalid Argument exception.
6306                 RAISE FND_API.G_EXC_ERROR;
6307         END IF;
6308 
6309         -- If the Ci_Id that is passed in does not exist then
6310         -- report Error.
6311         OPEN Check_Valid_CI (p_Ci_Id);
6312         FETCH Check_Valid_CI INTO l_CiId;
6313         IF (Check_Valid_CI%NOTFOUND) THEN
6314                 -- Close the Cursor.
6315                 CLOSE Check_Valid_CI;
6316 
6317                 -- Add message to the Error Stack that this Ci_Id is Invalid.
6318                 PA_UTILS.Add_Message (
6319                         p_App_Short_Name => 'PA'
6320                         , p_Msg_Name => 'PA_CI_INV_CI_ID'
6321                         );
6322 		if l_debug_mode = 'Y' then
6323 			pa_debug.g_err_stage:= 'CI_ID is Invalid';
6324 		        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6325 	        end if;
6326                 -- Raise the Invalid Argument exception.
6327                 RAISE FND_API.G_EXC_ERROR;
6328         END IF;
6329         CLOSE Check_Valid_CI;
6330 
6331 	-- If the To_Ci_Id that is passed in does not exist then
6332         -- report Error.
6333         OPEN Check_Valid_CI (p_To_Ci_Id);
6334         FETCH Check_Valid_CI INTO l_CiId;
6335         IF (Check_Valid_CI%NOTFOUND) THEN
6336                 -- Close the Cursor.
6337                 CLOSE Check_Valid_CI;
6338 
6339                 -- Add message to the Error Stack that this Ci_Id is Invalid.
6340                 PA_UTILS.Add_Message (
6341                         p_App_Short_Name => 'PA'
6342                         , p_Msg_Name => 'PA_CI_INV_CI_ID'
6343                         );
6344 		if l_debug_mode = 'Y' then
6345 			pa_debug.g_err_stage:= 'TO_CI_ID is Invalid';
6346 		        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6347 	        end if;
6348                 -- Raise the Invalid Argument exception.
6349                 RAISE FND_API.G_EXC_ERROR;
6350         END IF;
6351         CLOSE Check_Valid_CI;
6352 
6353         -- Open Cursor Get_CI_Data and fetch the data into our local variables.
6354         OPEN Get_CI_Data (p_Ci_Id);
6355         FETCH Get_CI_Data INTO l_ProjectId, l_StatusCode, l_CiTypeClassCode, l_RecordVersionNumber;
6356         -- If NO_DATA_FOUND then report Error.
6357         IF (Get_CI_Data%NOTFOUND) THEN
6358                 -- Code to Report Error and Return.
6359                 CLOSE Get_CI_Data;
6360                 RAISE FND_API.G_EXC_ERROR;
6361         END IF;
6362         CLOSE Get_CI_Data;
6363 
6364         -- Check whether Workflow is running on this Control Item or not.
6365         OPEN Check_Workflow_On_CI (p_Ci_Id);
6366         FETCH Check_Workflow_On_CI INTO l_CiId;
6367 
6368         -- If Workflow is not running on this Control Item then proceed,
6369         -- else report Error.
6370         IF (Check_Workflow_On_CI%NOTFOUND) THEN
6371                 CLOSE Check_Workflow_On_CI;
6372                 -- Deleting of Related Items is only allowed on a Control Item if
6373                 --      1. The User has Update access on the Control Item.
6374                 --      2. Update is allowed on the Control Item in this particular
6375                 --         status.
6376                 l_UpdateAllowed := PA_CONTROL_ITEMS_UTILS.CheckCIActionAllowed ('CONTROL_ITEM', l_StatusCode, 'CONTROL_ITEM_ALLOW_UPDATE', p_Ci_Id);
6377                 l_UpdateAccess := PA_CI_SECURITY_PKG.Check_Update_Access (p_Ci_Id);
6378                 IF (l_UpdateAllowed = 'Y' AND l_UpdateAccess = 'T') THEN
6379 			if l_debug_mode = 'Y' then
6380 				pa_debug.g_err_stage:= 'Before Calling PA_CONTROL_ITEMS_PVT.Delete_Related_Item';
6381 			        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6382 		        end if;
6383                         -- Call our procedure to Delete the Item.
6384                         PA_CONTROL_ITEMS_PVT.Delete_Related_Item (
6385                                 p_Api_Version           => p_Api_Version_Number
6386                                 , p_Init_Msg_List       => 'F'
6387                                 , p_Commit              => p_Commit
6388                                 , p_Validate_Only       => 'F'
6389                                 , p_Ci_Id               => p_Ci_Id
6390                                 , p_Related_Ci_Id       => p_To_Ci_Id
6391                                 , x_Return_Status       => x_Return_Status
6392                                 , x_Msg_Count           => x_Msg_Count
6393                                 , x_Msg_Data            => x_Msg_Data
6394                                 );
6395                 ELSE
6396                         -- Check if Update Access was denied or not.
6397                         IF (l_UpdateAccess <> 'T') THEN
6398                                 -- Add message to the Error Stack that the user does not
6399                                 -- have the privilege to update this Control Item.
6400                                 PA_UTILS.Add_Message (
6401                                         p_App_Short_Name => 'PA'
6402                                         , p_Msg_Name => 'PA_CI_UPDATE_NOT_ALLOWED'
6403                                         );
6404 				if l_debug_mode = 'Y' then
6405 					pa_debug.g_err_stage:= 'User does not have the privilege to update this Control Item.';
6406 				        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6407 				end if;
6408                         END IF;
6409 
6410                         -- Check if update was denied by Status Control or not.
6411                         IF (l_UpdateAllowed <> 'Y') THEN
6412                                 -- Add message to the Error Stack that this Control Item
6413                                 -- cannot be updated in its present status.
6414                                 PA_UTILS.Add_Message (
6415                                         p_App_Short_Name => 'PA'
6416                                         , p_Msg_Name => 'PA_CI_NO_ALLOW_UPDATE'
6417                                         );
6418 				if l_debug_mode = 'Y' then
6419 					pa_debug.g_err_stage:= 'This Control Item cannot be updated in its present status.';
6420 				        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6421 				end if;
6422                         END IF;
6423 
6424                         -- Raise the Invalid Argument exception.
6425                         RAISE FND_API.G_EXC_ERROR;
6426                 END IF;
6427         ELSE
6428                 -- Close the Cursor.
6429                 CLOSE Check_Workflow_On_CI;
6430 
6431                 -- Add message to the Error Stack that this Ci_Id has Workflow
6432                 -- attached.
6433                 PA_UTILS.Add_Message (
6434                         p_App_Short_Name => 'PA'
6435                         , p_Msg_Name => 'PA_CI_APPROVAL_WORKFLOW'
6436                         );
6437 		if l_debug_mode = 'Y' then
6438 			pa_debug.g_err_stage:= 'CI_ID has WorkFlow Attached';
6439 			pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6440 		end if;
6441                 -- Raise the Invalid Argument exception.
6442                 RAISE FND_API.G_EXC_ERROR;
6443         END IF;
6444 
6445 	 IF p_commit = FND_API.G_TRUE and x_return_status = FND_API.G_RET_STS_SUCCESS THEN
6446                 COMMIT;
6447          elsif  x_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
6448                 raise FND_API.G_EXC_ERROR;
6449          END IF;
6450 
6451            -- Reset the Error Stack.
6452 		if l_debug_mode = 'Y' then
6453 			Pa_Debug.reset_curr_function;
6454 		end if;
6455 
6456         -- If any Exception then catch it.
6457         EXCEPTION
6458         WHEN FND_API.G_EXC_ERROR THEN
6459                 -- Set the Return Status as Error.
6460                 x_Return_Status := FND_API.g_Ret_Sts_Error;
6461                 -- Get the Message Count.
6462                 l_Msg_Count := FND_MSG_PUB.Count_Msg;
6463 
6464 		-- Rollback.
6465                 IF (p_Commit = FND_API.G_TRUE) THEN
6466                         ROLLBACK TO DELETE_RELATED_ITEMS_SVPT;
6467                 END IF;
6468 
6469                 IF (l_Msg_Count = 1) THEN
6470                         PA_INTERFACE_UTILS_PUB.Get_Messages (
6471                                 p_Encoded               => FND_API.g_False
6472                                 , p_Msg_Index           => 1
6473                                 , p_Msg_Count           => l_Msg_Count
6474                                 , p_Msg_Data            => l_Msg_Data
6475                                 , p_Data                => l_Data
6476                                 , p_Msg_Index_Out       => l_Msg_Index_Out
6477                                 );
6478                         x_Msg_Data := l_Data;
6479                         x_Msg_Count := l_Msg_Count;
6480                 ELSE
6481                         x_Msg_Count := l_Msg_Count;
6482                 END IF;
6483 
6484                    -- Reset the Error Stack.
6485 		if l_debug_mode = 'Y' then
6486 			Pa_Debug.reset_curr_function;
6487 		end if;
6488 
6489         WHEN OTHERS THEN
6490                 -- Set the Return Status as Error.
6491                 x_Return_Status := FND_API.g_Ret_Sts_Unexp_Error;
6492 
6493 		-- Rollback.
6494                 IF (p_Commit = FND_API.G_TRUE) THEN
6495                         ROLLBACK TO DELETE_RELATED_ITEMS_SVPT;
6496                 END IF;
6497 
6498                 -- Add the message that is reported in SQL Error.
6499                 FND_MSG_PUB.Add_Exc_Msg (
6500                         p_Pkg_Name       => 'PA_CONTROL_API_PUB',
6501                         p_Procedure_Name => 'Delete_Related_Item',
6502                         p_Error_Text     => SUBSTRB (sqlerrm, 1, 240)
6503                         );
6504 
6505                 FND_MSG_PUB.Count_And_Get (
6506                         p_Count => x_Msg_Count,
6507                         p_Data  => x_Msg_Data
6508                         );
6509 
6510                    -- Reset the Error Stack.
6511 		if l_debug_mode = 'Y' then
6512 			Pa_Debug.reset_curr_function;
6513 		end if;
6514 END Delete_Related_Item;
6515 
6516 
6517 PROCEDURE UPDATE_ISSUE (
6518                         p_commit                IN      VARCHAR2 := FND_API.G_FALSE,
6519                         p_init_msg_list         IN      VARCHAR2 := FND_API.G_FALSE,
6520                         p_api_version_number    IN      NUMBER,
6521                         x_return_status         OUT  NOCOPY   VARCHAR2,
6522                         x_msg_count             OUT  NOCOPY   NUMBER,
6523                         x_msg_data              OUT  NOCOPY   VARCHAR2,
6524                         p_ci_id                 IN      NUMBER,
6525                         P_RECORD_VERSION_NUMBER IN      NUMBER   := G_PA_MISS_NUM,
6526                         P_SUMMARY               IN      VARCHAR2 := G_PA_MISS_CHAR,
6527                         P_DESCRIPTION           IN      VARCHAR2 := G_PA_MISS_CHAR,
6528                         P_OWNER_ID              IN      NUMBER   := G_PA_MISS_NUM,
6529                         P_OWNER_COMMENT         IN      VARCHAR2 := G_PA_MISS_CHAR,
6530                         P_CLASSIFICATION_CODE   IN      NUMBER   := G_PA_MISS_NUM,
6531                         P_REASON_CODE           IN      NUMBER   := G_PA_MISS_NUM,
6532                         P_OBJECT_ID             IN      NUMBER   := G_PA_MISS_NUM,
6533                         P_OBJECT_TYPE           IN      VARCHAR2 := G_PA_MISS_CHAR,
6534                         P_CI_NUMBER             IN      VARCHAR2 := G_PA_MISS_CHAR,
6535                         P_DATE_REQUIRED         IN      DATE     := G_PA_MISS_DATE,
6536                         P_PRIORITY_CODE         IN      VARCHAR2 := G_PA_MISS_CHAR,
6537                         P_EFFORT_LEVEL_CODE     IN      VARCHAR2 := G_PA_MISS_CHAR,
6538                         P_PRICE                 IN      NUMBER   := G_PA_MISS_NUM,
6539                         P_PRICE_CURRENCY_CODE   IN      VARCHAR2 := G_PA_MISS_CHAR,
6540                         P_SOURCE_TYPE_CODE      IN      VARCHAR2 := G_PA_MISS_CHAR,
6541                         P_SOURCE_NUMBER         IN      VARCHAR2 := G_PA_MISS_CHAR,
6542                         P_SOURCE_COMMENT        IN      VARCHAR2 := G_PA_MISS_CHAR,
6543                         P_SOURCE_DATE_RECEIVED  IN      DATE     := G_PA_MISS_DATE,
6544                         P_SOURCE_ORGANIZATION   IN      VARCHAR2 := G_PA_MISS_CHAR,
6545                         P_SOURCE_PERSON         IN      VARCHAR2 := G_PA_MISS_CHAR,
6546                         P_CI_STATUS_CODE        IN      VARCHAR2 := G_PA_MISS_CHAR,
6547                         P_STATUS_COMMENT        IN      VARCHAR2 := G_PA_MISS_CHAR,
6548                         P_PROGRESS_AS_OF_DATE   IN      DATE     := G_PA_MISS_DATE,
6549                         P_PROGRESS_STATUS_CODE  IN      VARCHAR2 := G_PA_MISS_CHAR,
6550                         P_PROGRESS_OVERVIEW     IN      VARCHAR2 := G_PA_MISS_CHAR,
6551                         P_RESOLUTION_CODE       IN      VARCHAR2 := G_PA_MISS_CHAR,
6552                         P_RESOLUTION_COMMENT    IN      VARCHAR2 := G_PA_MISS_CHAR,
6553                         P_ATTRIBUTE_CATEGORY    IN      VARCHAR2 := G_PA_MISS_CHAR,
6554                         P_ATTRIBUTE1            IN      VARCHAR2 := G_PA_MISS_CHAR,
6555                         P_ATTRIBUTE2            IN      VARCHAR2 := G_PA_MISS_CHAR,
6556                         P_ATTRIBUTE3            IN      VARCHAR2 := G_PA_MISS_CHAR,
6557                         P_ATTRIBUTE4            IN      VARCHAR2 := G_PA_MISS_CHAR,
6558                         P_ATTRIBUTE5            IN      VARCHAR2 := G_PA_MISS_CHAR,
6559                         P_ATTRIBUTE6            IN      VARCHAR2 := G_PA_MISS_CHAR,
6560                         P_ATTRIBUTE7            IN      VARCHAR2 := G_PA_MISS_CHAR,
6561                         P_ATTRIBUTE8            IN      VARCHAR2 := G_PA_MISS_CHAR,
6562                         P_ATTRIBUTE9            IN      VARCHAR2 := G_PA_MISS_CHAR,
6563                         P_ATTRIBUTE10           IN      VARCHAR2 := G_PA_MISS_CHAR,
6564                         P_ATTRIBUTE11           IN      VARCHAR2 := G_PA_MISS_CHAR,
6565                         P_ATTRIBUTE12           IN      VARCHAR2 := G_PA_MISS_CHAR,
6566                         P_ATTRIBUTE13           IN      VARCHAR2 := G_PA_MISS_CHAR,
6567                         P_ATTRIBUTE14           IN      VARCHAR2 := G_PA_MISS_CHAR,
6568                         P_ATTRIBUTE15           IN      VARCHAR2 := G_PA_MISS_CHAR
6569                         )
6570 IS
6571 
6572 
6573 
6574 
6575 
6576 
6577  l_data                       VARCHAR2(2000);
6578  l_msg_data                   VARCHAR2(2000);
6579  l_msg_index_out              NUMBER;
6580  l_msg_count                  NUMBER := 0;
6581 
6582  l_check_update_access        VARCHAR2(1) := 'F';
6583  l_chk_status_ctrl            VARCHAR2(1) := 'N';
6584  l_module                     VARCHAR2(100) := 'PA_CONTROL_API_PUB.UPDATE_ISSUE';
6585 
6586 
6587  l_curr_status_code                   pa_control_items.status_code%TYPE;
6588  l_ci_status_code                     pa_control_items.status_code%TYPE;
6589  l_record_version_number              pa_control_items.record_version_number%TYPE;
6590  l_summary                            pa_control_items.summary%TYPE;
6591  l_description                        pa_control_items.description%TYPE;
6592  l_curr_owner_id                      pa_control_items.owner_id%TYPE;
6593  l_owner_id                           pa_control_items.owner_id%TYPE;
6594  l_classification_code_id             pa_control_items.classification_code_id%TYPE;
6595  l_reason_code_id                     pa_control_items.reason_code_id%TYPE;
6596  l_object_id                          pa_control_items.object_id%TYPE;
6597  l_object_type                        pa_control_items.object_type%TYPE;
6598  l_ci_number                          pa_control_items.ci_number%TYPE;
6599  l_date_required                      pa_control_items.date_required%TYPE;
6600  l_priority_code                      pa_control_items.priority_code%TYPE;
6601  l_effort_level_code                  pa_control_items.effort_level_code%TYPE;
6602  l_price                              pa_control_items.price%TYPE;
6603  l_price_currency_code                pa_control_items.price_currency_code%TYPE;
6604  l_source_type_code                   pa_control_items.source_type_code%TYPE;
6605  l_source_comment                     pa_control_items.source_comment%TYPE;
6606  l_source_number                      pa_control_items.source_number%TYPE;
6607  l_source_date_received               pa_control_items.source_date_received%TYPE;
6608  l_source_organization                pa_control_items.source_organization%TYPE;
6609  l_source_person                      pa_control_items.source_person%TYPE;
6610  l_progress_as_of_date                pa_control_items.progress_as_of_date%TYPE;
6611  l_progress_status_code               pa_control_items.progress_status_code%TYPE;
6612  l_progress_overview                  pa_control_items.status_overview%TYPE;
6613  l_resolution_code_id                 pa_control_items.resolution_code_id%TYPE;
6614  l_resolution_comment                 pa_control_items.resolution%TYPE;
6615  l_date_closed                        pa_control_items.date_closed%TYPE;
6616  l_closed_by_id                       pa_control_items.closed_by_id%TYPE;
6617  l_project_id                         pa_control_items.project_id%TYPE;
6618  l_ci_type_id                         pa_control_items.ci_type_id%TYPE;
6619  l_attribute_category                 pa_control_items.attribute_category%TYPE;
6620  l_attribute1                         pa_control_items.attribute1%TYPE;
6621  l_attribute2                         pa_control_items.attribute2%TYPE;
6622  l_attribute3                         pa_control_items.attribute3%TYPE;
6623  l_attribute4                         pa_control_items.attribute4%TYPE;
6624  l_attribute5                         pa_control_items.attribute5%TYPE;
6625  l_attribute6                         pa_control_items.attribute6%TYPE;
6626  l_attribute7                         pa_control_items.attribute7%TYPE;
6627  l_attribute8                         pa_control_items.attribute8%TYPE;
6628  l_attribute9                         pa_control_items.attribute9%TYPE;
6629  l_attribute10                        pa_control_items.attribute10%TYPE;
6630  l_attribute11                        pa_control_items.attribute11%TYPE;
6631  l_attribute12                        pa_control_items.attribute12%TYPE;
6632  l_attribute13                        pa_control_items.attribute13%TYPE;
6633  l_attribute14                        pa_control_items.attribute14%TYPE;
6634  l_attribute15                        pa_control_items.attribute15%TYPE;
6635  l_class_code                         constant varchar2(20) := 'ISSUE';
6636 
6637  CURSOR curr_row is
6638     SELECT *
6639       FROM pa_control_items
6640      WHERE ci_id = p_ci_id;
6641 
6642  cp    curr_row%rowtype;
6643 
6644  CURSOR c_submit_status (p_curr_status_code VARCHAR2) IS
6645     SELECT enable_wf_flag, wf_success_status_code, wf_failure_status_code
6646       FROM pa_project_statuses
6647      WHERE project_status_code = p_curr_status_code;
6648 
6649  CURSOR c_lkup (p_lookup_type VARCHAR2, p_lookup_code VARCHAR2) IS
6650     SELECT lookup_code
6651       FROM pa_lookups
6652      WHERE lookup_type = p_lookup_type
6653        AND trunc(sysdate) BETWEEN start_date_active AND nvl(end_date_active, trunc(sysdate))
6654        AND enabled_flag = 'Y'
6655        AND lookup_code = p_lookup_code;
6656 
6657  CURSOR c_statuses (p_status_type VARCHAR2, p_project_status_code VARCHAR2) IS
6658     SELECT project_status_code
6659       FROM pa_project_statuses
6660      WHERE status_type = p_status_type
6661        AND project_status_code = p_project_status_code
6662        AND trunc(sysdate) BETWEEN start_date_active AND nvl(end_date_active, trunc(sysdate));
6663 
6664  CURSOR c_classification (p_ci_type_id NUMBER, p_class_code_id NUMBER) IS
6665     SELECT cat.class_code_id
6666       FROM pa_class_codes cat,
6667            pa_ci_types_b typ
6668      WHERE trunc(sysdate) between cat.start_date_active and nvl(cat.end_date_active,trunc(sysdate))
6669        AND typ.ci_type_id = p_ci_type_id
6670        AND cat.class_category = typ.classification_category
6671        AND cat.class_code_id = p_class_code_id;
6672 
6673  CURSOR c_reason (p_ci_type_id NUMBER, p_reason_code_id NUMBER) IS
6674     SELECT cat.class_code_id
6675       FROM pa_class_codes cat,
6676            pa_ci_types_b typ
6677      WHERE trunc(sysdate) between cat.start_date_active and nvl(cat.end_date_active,trunc(sysdate))
6678        AND typ.ci_type_id = p_ci_type_id
6679        AND cat.class_category = typ.reason_category
6680        AND cat.class_code_id = p_reason_code_id;
6681 
6682  CURSOR c_resolution (p_ci_type_id NUMBER, p_resolution_code_id NUMBER) IS
6683     SELECT cat.class_code_id
6684       FROM pa_class_codes cat,
6685            pa_ci_types_b typ
6686      WHERE trunc(sysdate) between cat.start_date_active and nvl(cat.end_date_active,trunc(sysdate))
6687        AND typ.ci_type_id = p_ci_type_id
6688        AND cat.class_category = typ.resolution_category
6689        AND cat.class_code_id = p_resolution_code_id;
6690 
6691  CURSOR c_auto_num IS
6692     SELECT type.auto_number_flag
6693       FROM pa_ci_types_b type,
6694            pa_control_items ci
6695      WHERE ci.ci_id = p_ci_id
6696        AND ci.ci_type_id = type.ci_type_id;
6697 
6698  CURSOR c_ci_number (p_project_id NUMBER, p_ci_type_id NUMBER) IS
6699     SELECT ROWID
6700       FROM pa_control_items
6701      WHERE project_id = p_project_id
6702        AND ci_number = p_ci_number
6703        AND ci_id <> p_ci_id
6704        AND ci_type_id = p_ci_type_id;
6705 
6706  CURSOR c_info IS
6707     SELECT cit.ci_type_class_code,
6708            cit.approval_required_flag,
6709              s.next_allowable_status_flag
6710       FROM pa_control_items c,
6711            pa_ci_types_b cit,
6712            pa_project_statuses s
6713      WHERE c.ci_id = p_ci_id
6714        AND c.status_code = s.project_status_code
6715        AND c.ci_type_id =cit.ci_type_id
6716        AND s.status_type = 'CONTROL_ITEM';
6717 
6718 --added to get the owner name to include in the log message
6719  CURSOR c_get_owner(c_owner_id NUMBER,c_project_id NUMBER)  IS
6720      select distinct resource_source_name party_name
6721 	 from PA_PROJECT_PARTIES_V
6722 	 where party_type <> 'ORGANIZATION'
6723 	 and resource_party_id = c_owner_id
6724          and project_id = c_project_id;
6725 
6726  l_stmnt                             VARCHAR2(5000);
6727  l_sel_clause                        VARCHAR2(300);
6728  l_from_clause                       VARCHAR2(300);
6729  l_where                             VARCHAR2(4000);
6730  l_where1                            VARCHAR2(2000);
6731  l_cursor                            NUMBER;
6732  l_rows                              NUMBER;
6733  l_rows1                             NUMBER;
6734  l_ci_status_code_1                  pa_project_statuses.project_status_code%TYPE;
6735 
6736  l_ROWID                             ROWID;
6737 
6738  l_enable_wf_flag                     pa_project_statuses.enable_wf_flag%TYPE;
6739  l_wf_success_status_code             pa_project_statuses.wf_success_status_code%TYPE;
6740  l_wf_failure_status_code             pa_project_statuses.wf_failure_status_code%TYPE;
6741  l_status_change_flag                 VARCHAR2(1) := 'N';
6742  l_start_wf                           VARCHAR2(1) := 'Y';
6743  l_validate_only                      VARCHAR2(1) := FND_API.g_false;
6744  l_max_msg_count                      NUMBER := FND_API.G_MISS_NUM;
6745  l_enforce_security                   VARCHAR2(1) := 'Y';
6746  l_num_of_actions                     NUMBER;
6747  l_priority_type                      VARCHAR2(30) := 'PA_TASK_PRIORITY_CODE';
6748  l_effort_type                        VARCHAR2(30) := 'PA_CI_EFFORT_LEVELS';
6749  l_source_type                        VARCHAR2(30) := 'PA_CI_SOURCE_TYPES';
6750  l_progress_type                      VARCHAR2(30) := 'PROGRESS';
6751  l_auto_numbers                       VARCHAR2(1);
6752  l_curr_system_status                 pa_project_statuses.project_system_status_code%TYPE;
6753  l_new_system_status                  pa_project_statuses.project_system_status_code%TYPE;
6754  l_next_allow_status_flag             pa_project_statuses.next_allowable_status_flag%TYPE;
6755  l_ci_type_class_code                 pa_ci_types_b.ci_type_class_code%TYPE;
6756  l_approval_required_flag             pa_ci_types_b.approval_required_flag%TYPE;
6757  l_resolution_check                   VARCHAR2(10) := 'AMG';
6758  l_resolution_req                     VARCHAR2(10) := 'N';
6759  l_resolution_req_cls                 VARCHAR2(10) := 'N';
6760  l_to_status_flag                     VARCHAR2(10) := 'Y';
6761 
6762  l_ci_comment_id                      pa_ci_comments.ci_comment_id%TYPE;
6763  l_comment_text                       pa_ci_comments.comment_text%TYPE;
6764  l_owner_name                         per_all_people_f.full_name%TYPE;
6765  l_curr_owner_name                    per_all_people_f.full_name%TYPE;
6766  l_chgowner_allowed                   VARCHAR2(1);
6767  l_to_owner_allowed                   VARCHAR2(1);
6768 
6769 
6770 BEGIN
6771 
6772   x_return_status := FND_API.G_RET_STS_SUCCESS;
6773 
6774   l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.login_id, 275, null, null), 'N');
6775 
6776   IF l_debug_mode = 'Y' THEN
6777         PA_DEBUG.set_curr_function(p_function => 'UPDATE_ISSUE', p_debug_mode => l_debug_mode);
6778   END IF;
6779 
6780   IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
6781         FND_MSG_PUB.initialize;
6782   END IF;
6783 
6784   IF p_commit = FND_API.G_TRUE THEN
6785         savepoint UPDATE_ISSUE_SVPT;
6786   END IF;
6787 
6788   IF l_debug_mode = 'Y' THEN
6789         pa_debug.write(l_module, 'Start of Update Issue', l_debug_level3);
6790   END IF;
6791 
6792   OPEN curr_row;
6793   FETCH curr_row INTO cp;
6794   IF curr_row%NOTFOUND then
6795       close curr_row;
6796       PA_UTILS.Add_Message( p_app_short_name => 'PA'
6797                            ,p_msg_name       => 'PA_CI_INVALID_ITEM');   /* Change this message */
6798       RAISE  FND_API.G_EXC_ERROR;
6799   ELSE
6800 
6801       l_curr_status_code        := cp.status_code;
6802       l_record_version_number   := cp.record_version_number;
6803       l_summary                 := cp.summary;
6804       l_description             := cp.description;
6805       l_curr_owner_id           := cp.owner_id;
6806       l_classification_code_id  := cp.classification_code_id;
6807       l_reason_code_id          := cp.reason_code_id;
6808       l_object_id               := cp.object_id;
6809       l_object_type             := cp.object_type;
6810       l_ci_number               := cp.ci_number;
6811       l_date_required           := cp.date_required;
6812       l_priority_code           := cp.priority_code;
6813       l_effort_level_code       := cp.effort_level_code;
6814       l_price                   := cp.price;
6815       l_price_currency_code     := cp.price_currency_code;
6816       l_source_type_code        := cp.source_type_code;
6817       l_source_comment          := cp.source_comment;
6818       l_source_number           := cp.source_number;
6819       l_source_date_received    := cp.source_date_received;
6820       l_source_organization     := cp.source_organization;
6821       l_source_person           := cp.source_person;
6822       l_progress_as_of_date     := cp.progress_as_of_date;
6823       l_progress_status_code    := cp.progress_status_code;
6824       l_progress_overview       := cp.status_overview;
6825       l_resolution_code_id      := cp.resolution_code_id;
6826       l_resolution_comment      := cp.resolution;
6827       l_date_closed             := cp.date_closed;
6828       l_closed_by_id            := cp.closed_by_id;
6829       l_project_id              := cp.project_id;
6830       l_ci_type_id              := cp.ci_type_id;
6831       l_attribute_category      := cp.attribute_category;
6832       l_attribute1              := cp.attribute1;
6833       l_attribute2              := cp.attribute2;
6834       l_attribute3              := cp.attribute3;
6835       l_attribute4              := cp.attribute4;
6836       l_attribute5              := cp.attribute5;
6837       l_attribute6              := cp.attribute6;
6838       l_attribute7              := cp.attribute7;
6839       l_attribute8              := cp.attribute8;
6840       l_attribute9              := cp.attribute9;
6841       l_attribute10             := cp.attribute10;
6842       l_attribute11             := cp.attribute11;
6843       l_attribute12             := cp.attribute12;
6844       l_attribute13             := cp.attribute13;
6845       l_attribute14             := cp.attribute14;
6846       l_attribute15             := cp.attribute15;
6847 
6848       close curr_row;
6849 
6850   END IF;
6851 
6852      OPEN c_info;
6853      FETCH c_info INTO l_ci_type_class_code, l_approval_required_flag, l_next_allow_status_flag;
6854      CLOSE c_info;
6855 
6856     /* Added to check invalid API usage*/
6857     if l_ci_type_class_code <> l_class_code then
6858  	  PA_UTILS.ADD_MESSAGE(p_app_short_name  => 'PA',
6859                                p_msg_name        => 'PA_CI_INV_API_USE');
6860            if l_debug_mode = 'Y' then
6861                 pa_debug.g_err_stage:= 'wrong usage of the api for the control item type';
6862                 pa_debug.write(l_module,pa_debug.g_err_stage,l_debug_level3);
6863            end if;
6864 	   RAISE FND_API.G_EXC_ERROR;
6865      end if;
6866 
6867 
6868 
6869   l_curr_system_status :=  PA_CONTROL_ITEMS_UTILS.getSystemStatus(l_curr_status_code);
6870 
6871   /*  Check if the user can update the item. This requires the user to be owner or to have project authority or
6872       to have open UPDATE actions and status controls are satisfied.  */
6873 
6874   l_check_update_access := pa_ci_security_pkg.check_update_access(p_ci_id);
6875 
6876   IF (l_check_update_access = 'F') THEN
6877 
6878        PA_UTILS.ADD_MESSAGE('PA', 'PA_CI_NO_UPDATE_ACCESS');
6879        RAISE FND_API.G_EXC_ERROR;
6880 
6881   END IF;
6882 
6883   IF l_debug_mode = 'Y' THEN
6884         pa_debug.write(l_module, 'After call to pa_ci_security_pkg.check_update_access', l_debug_level3);
6885   END IF;
6886 
6887   /* Check for the status control: check whether the action CONTROL_ITEM_ALLOW_UPDATE is allowed on the current status of the issue. */
6888 
6889   l_chk_status_ctrl := pa_control_items_utils.CheckCIActionAllowed('CONTROL_ITEM', l_curr_status_code, 'CONTROL_ITEM_ALLOW_UPDATE');
6890 
6891   IF (l_chk_status_ctrl = 'N') THEN
6892 
6893        PA_UTILS.ADD_MESSAGE('PA', 'PA_CI_NO_ALLOW_UPDATE');
6894        RAISE FND_API.G_EXC_ERROR;
6895 
6896   END IF;
6897 
6898 
6899   IF l_debug_mode = 'Y' THEN
6900         pa_debug.write(l_module, 'After call to pa_control_items_utils.CheckCIActionAllowed', l_debug_level3);
6901   END IF;
6902 
6903   /*  The control item will not be updateable if the current status has approval workflow attached. */
6904 
6905   OPEN c_submit_status(l_curr_status_code);
6906   FETCH c_submit_status INTO l_enable_wf_flag, l_wf_success_status_code, l_wf_failure_status_code;
6907   CLOSE c_submit_status;
6908   IF (l_enable_wf_flag = 'Y' AND l_wf_success_status_code IS NOT NULL AND l_wf_failure_status_code IS NOT NULL) THEN
6909 
6910        PA_UTILS.ADD_MESSAGE('PA', 'PA_CI_APPROVAL_WORKFLOW');
6911        RAISE FND_API.G_EXC_ERROR;
6912 
6913   END IF;
6914 
6915   IF l_debug_mode = 'Y' THEN
6916         pa_debug.write(l_module, 'After checking for submitted status', l_debug_level3);
6917   END IF;
6918 
6919 
6920   IF p_ci_status_code = G_PA_MISS_CHAR THEN
6921        l_ci_status_code := l_curr_status_code;
6922   ELSIF p_ci_status_code IS NOT NULL THEN
6923           l_ci_status_code := p_ci_status_code;
6924 
6925           l_sel_clause  := ' SELECT ps.project_status_code ';
6926           l_from_clause := ' FROM pa_obj_status_lists osl, pa_status_list_items sli, pa_project_statuses ps ';
6927           l_where       := ' WHERE osl.status_type = '||'''CONTROL_ITEM'''||
6928                              ' AND osl.object_type = '||'''PA_CI_TYPES'''||
6929                              ' AND osl.object_id = '||l_ci_type_id||
6930                              ' AND osl.status_list_id = sli.status_list_id'||
6931                              ' AND sli.project_status_code = ps.project_status_code'||
6932                              ' AND ps.project_status_code <> '||''''||l_curr_status_code||''''||
6933                              ' AND ps.status_type = osl.status_type'||
6934                              ' AND trunc(sysdate) between nvl(ps.start_date_active, trunc(sysdate)) and nvl(ps.end_date_active, trunc(sysdate))'||
6935                              ' AND (('||''''||l_next_allow_status_flag||''''||' = '||'''N'''||' and 1=2)'||
6936                                   ' OR '||
6937                                   ' ('||''''||l_next_allow_status_flag||''''||' = '||'''S'''||
6938                                   ' and ps.project_status_code in (select project_status_code from pa_project_statuses where status_type = '||'''CONTROL_ITEM'''||
6939                                   ' and project_system_status_code in ( select next_allowable_status_code from pa_next_allow_statuses where status_code = '||
6940 				  ''''||l_curr_status_code||''''||')))'||
6941                                   ' OR '||
6942                                   ' ('||''''||l_next_allow_status_flag||''''||' = '||'''U'''||
6943                                   ' and ps.project_status_code in (select next_allowable_status_code from pa_next_allow_statuses where status_code = '||''''||
6944 				  l_curr_status_code||''''||'))'||
6945                                   ' OR '||
6946                                   ' ('||''''||l_next_allow_status_flag||''''||' = '||'''A'''||
6947 				  ' and ps.project_status_code in (select project_status_code from pa_project_statuses where status_type = '||'''CONTROL_ITEM'''||
6948 				  ' and project_system_status_code in (select next_allowable_status_code from pa_next_allow_statuses where status_code = '||
6949 				  ''''||l_curr_system_status||''''||'))))'||
6950                               ' AND ps.project_status_code not in (select wf_success_status_code from pa_project_statuses where status_type = '||
6951                               '''CONTROL_ITEM'''||' and wf_success_status_code is not null and wf_failure_status_code is not null)'||
6952                               ' AND ps.project_status_code not in (select wf_failure_status_code from pa_project_statuses where status_type = '||
6953                               '''CONTROL_ITEM'''||' and wf_success_status_code is not null and wf_failure_status_code is not null)'||
6954                               ' AND decode(ps.project_system_status_code, '||'''CI_CANCELED'''||
6955                               ', nvl(pa_control_items_utils.CheckCIActionAllowed('||'''CONTROL_ITEM'''||', '||''''||l_curr_status_code||''''||', '||
6956 			      '''CONTROL_ITEM_ALLOW_CANCEL'''||', null),'||'''N'''||' ),'||'''Y'''||' ) = '||'''Y'''||
6957                               ' AND decode(ps.project_system_status_code,'||'''CI_WORKING'''||
6958                               ' ,nvl(pa_control_items_utils.CheckCIActionAllowed('||'''CONTROL_ITEM'''||', '||''''||l_curr_status_code||''''||', '||
6959 			      '''CONTROL_ITEM_ALLOW_REWORK'''||' ,null),'||'''N'''||' ),'||'''Y'''||' ) = '||'''Y'''||
6960                               ' AND nvl(pa_control_items_utils.CheckCIActionAllowed('||'''CONTROL_ITEM'''||', '||''''||l_curr_status_code||''''||', '||
6961 			      '''CONTROL_ITEM_ALLOW_UPDST'''||' ,null),'||'''N'''||' ) = '||'''Y'''||
6962                               ' AND decode(ps.project_system_status_code,'||'''CI_DRAFT'''||
6963 		   	      ' ,decode('||''''||l_curr_system_status||''''||', '||'''CI_DRAFT'''||', '||
6964 			      '''Y'''||' ,'||'''N'''||' ),'||'''Y'''||' ) = '||'''Y'''||
6965                               ' AND ps.project_status_code = '||''''||p_ci_status_code||'''';
6966 
6967 
6968           IF (l_ci_type_class_code = 'ISSUE' AND l_approval_required_flag = 'N') THEN
6969                 l_where1 := ' AND  ps.project_status_code not in (select project_status_code from pa_project_statuses where status_type = '||
6970                            '''CONTROL_ITEM'''||' and enable_wf_flag = '||'''Y'''||
6971                            ' and wf_success_status_code is not null and wf_failure_status_code is not null) ';
6972           END IF;
6973 
6974           IF (l_ci_type_class_code = 'ISSUE' AND l_approval_required_flag = 'Y' AND l_curr_system_status = 'CI_WORKING') THEN
6975                 l_where1 := ' AND  ps.project_system_status_code <> '||'''CI_CLOSED''';
6976           END IF;
6977 
6978           l_stmnt := l_sel_clause || l_from_clause || l_where || l_where1;
6979 
6980           IF l_debug_mode = 'Y' THEN
6981                pa_debug.write(l_module, l_stmnt , l_debug_level3);
6982           END IF;
6983 
6984     l_cursor := dbms_sql.open_cursor;
6985 
6986     DBMS_SQL.PARSE(l_cursor, l_stmnt, DBMS_SQL.v7);
6987     DBMS_SQL.DEFINE_COLUMN(l_cursor, 1, l_ci_status_code_1, 30);
6988 
6989     l_rows := DBMS_SQL.EXECUTE(l_cursor);
6990 
6991     IF (l_rows < 0) THEN
6992                PA_UTILS.Add_Message( p_app_short_name => 'PA'
6993                                     ,p_msg_name       => 'PA_TO_STATUS_INVALID');
6994                x_return_status := FND_API.G_RET_STS_ERROR;
6995 	       l_to_status_flag := 'N';
6996     ELSE
6997        l_rows1 := DBMS_SQL.FETCH_ROWS(l_cursor);
6998 
6999        if l_rows1 > 0 THEN
7000             DBMS_SQL.COLUMN_VALUE(l_cursor, 1, l_ci_status_code_1);
7001             l_ci_status_code := l_ci_status_code_1;
7002        else
7003 	     PA_UTILS.Add_Message( p_app_short_name => 'PA'
7004                                   ,p_msg_name       => 'PA_TO_STATUS_INVALID');
7005              x_return_status := FND_API.G_RET_STS_ERROR;
7006              l_to_status_flag := 'N';
7007        end if;
7008     END IF;
7009 
7010     IF l_debug_mode = 'Y' THEN
7011          pa_debug.write(l_module, 'After validating p_ci_status_code', l_debug_level3);
7012     END IF;
7013 
7014     IF dbms_sql.is_open(l_cursor)   THEN
7015          dbms_sql.close_cursor(l_cursor);
7016     END IF;
7017   ELSIF p_ci_status_code IS NULL THEN
7018           l_ci_status_code := p_ci_status_code;
7019           PA_UTILS.Add_Message( p_app_short_name => 'PA'
7020                                ,p_msg_name       => 'PA_CI_NULL_STATUS');
7021           x_return_status := FND_API.G_RET_STS_ERROR;
7022 	  l_to_status_flag := 'N';
7023   END IF;
7024 
7025   IF p_record_version_number = G_PA_MISS_NUM THEN
7026        NULL;
7027   ELSE
7028        l_record_version_number := p_record_version_number;
7029   END IF;
7030 
7031   IF p_summary = G_PA_MISS_CHAR THEN
7032        NULL;
7033   ELSIF p_summary IS NOT NULL THEN
7034           l_summary := p_summary;
7035   ELSIF p_summary IS NULL THEN
7036           PA_UTILS.ADD_MESSAGE('PA', 'PA_CI_NULL_SUMMARY');
7037           x_return_status := FND_API.G_RET_STS_ERROR;
7038   END IF;
7039 
7040   IF p_description = G_PA_MISS_CHAR THEN
7041        NULL;
7042   ELSIF p_description IS NOT NULL THEN
7043           l_description := p_description;
7044   ELSIF p_description IS NULL THEN
7045           l_description := p_description;
7046   END IF;
7047 
7048 
7049 /*Adding the comment after validating the Owner id*/
7050   IF p_owner_id = G_PA_MISS_NUM THEN
7051        l_owner_id := l_curr_owner_id;
7052   ELSIF p_owner_id IS NOT NULL THEN
7053           l_owner_id := p_owner_id;
7054           IF (l_owner_id = l_curr_owner_id) then
7055                  PA_UTILS.Add_Message( p_app_short_name => 'PA'
7056                                       ,p_msg_name       => 'PA_CI_CHANGE_OWNER_INVALID');
7057                  x_return_status := 'E';
7058 
7059 	  ELSIF (l_owner_id <> l_curr_owner_id) then
7060 		l_chgowner_allowed := pa_ci_security_pkg.check_change_owner_access(p_ci_id);
7061 		IF (l_chgowner_allowed <> 'T') then
7062 		         PA_UTILS.Add_Message( p_app_short_name => 'PA'
7063 				              ,p_msg_name       => 'PA_CI_OWNER_CHG_NOT_ALLOWED');
7064 			 x_return_status := 'E';
7065 	        else
7066 		         l_to_owner_allowed := pa_ci_security_pkg.is_to_owner_allowed(p_ci_id, l_owner_id);
7067 		         if (l_to_owner_allowed <> 'T') then
7068 				 PA_UTILS.Add_Message( p_app_short_name => 'PA'
7069 					              ,p_msg_name       => 'PA_CI_TO_OWNER_NOT_ALLOWED');
7070 		         x_return_status := 'E';
7071 		         else
7072 
7073 				/*get the Passed owner name*/
7074 				OPEN c_get_owner(l_owner_id,l_project_id);
7075 				FETCH c_get_owner into l_owner_name;
7076 				if (c_get_owner%notfound) then
7077 					PA_UTILS.Add_Message( p_app_short_name => 'PA'
7078 					      ,p_msg_name       => 'PA_CI_CHANGE_OWNER_INVALID');
7079 					x_return_status := 'E';
7080 				end if;
7081 				close 	c_get_owner;
7082 
7083 				/*Get the Current Owner name*/
7084 				OPEN c_get_owner(l_curr_owner_id,l_project_id);
7085 				FETCH c_get_owner into l_curr_owner_name;
7086 				if (c_get_owner%notfound) then
7087 					PA_UTILS.Add_Message( p_app_short_name => 'PA'
7088 					      ,p_msg_name       => 'PA_CI_CHANGE_OWNER_INVALID');
7089 					x_return_status := 'E';
7090 				end if;
7091 				close 	c_get_owner;
7092 
7093 					fnd_message.set_name('PA', 'PA_CI_LOG_OWNER_CHANGE');
7094 					fnd_message.set_token('PREV_OWNER', l_curr_owner_name);
7095 					fnd_message.set_token('NEXT_OWNER', l_owner_name);
7096 					fnd_message.set_token('COMMENT', p_owner_comment);
7097 					l_comment_text := fnd_message.get;
7098 
7099 					 pa_ci_comments_pkg.insert_row(
7100 						p_ci_comment_id             => l_ci_comment_id,
7101 						p_ci_id                     => p_ci_id,
7102 						p_type_code                 => 'CHANGE_OWNER',
7103 						p_comment_text              => l_comment_text,
7104 						p_last_updated_by           => fnd_global.user_id,
7105 						p_created_by                => fnd_global.user_id,
7106 						p_creation_date             => sysdate,
7107 						p_last_update_date          => sysdate,
7108 						p_last_update_login         => fnd_global.login_id,
7109 						p_ci_action_id              => null);
7110 			end if;
7111 	        end if;
7112 	end if;
7113   ELSIF p_owner_id IS NULL THEN
7114           PA_UTILS.Add_Message( p_app_short_name => 'PA'
7115                                ,p_msg_name       => 'PA_CI_OWNER_NULL');
7116           x_return_status := FND_API.G_RET_STS_ERROR;
7117   END IF;
7118 
7119   IF p_classification_code = G_PA_MISS_NUM THEN
7120        NULL;
7121   ELSIF p_classification_code IS NOT NULL THEN
7122           OPEN c_classification (l_ci_type_id, p_classification_code);
7123           FETCH c_classification INTO l_classification_code_id;
7124           IF c_classification%NOTFOUND then
7125               -- close c_classification;
7126                PA_UTILS.Add_Message( p_app_short_name => 'PA'
7127                                     ,p_msg_name       => 'PA_CI_CLASSIFICATION_INV');
7128                x_return_status := FND_API.G_RET_STS_ERROR;
7129           END IF;
7130           close c_classification;
7131   ELSIF p_classification_code IS NULL THEN
7132           PA_UTILS.Add_Message( p_app_short_name => 'PA'
7133                                ,p_msg_name       => 'PA_CI_CLASSIFICATION_NULL');
7134           x_return_status := FND_API.G_RET_STS_ERROR;
7135   END IF;
7136 
7137   IF p_reason_code = G_PA_MISS_NUM THEN
7138        NULL;
7139   ELSIF p_reason_code IS NOT NULL THEN
7140           OPEN c_reason (l_ci_type_id, p_reason_code);
7141           FETCH c_reason INTO l_reason_code_id;
7142           IF c_reason%NOTFOUND then
7143               -- close c_reason;
7144                PA_UTILS.Add_Message( p_app_short_name => 'PA'
7145                                     ,p_msg_name       => 'PA_CI_REASON_INV');
7146                x_return_status := FND_API.G_RET_STS_ERROR;
7147           END IF;
7148           close c_reason;
7149   ELSIF p_reason_code IS NULL THEN
7150           PA_UTILS.Add_Message( p_app_short_name => 'PA'
7151                                ,p_msg_name       => 'PA_CI_REASON_NULL');
7152           x_return_status := FND_API.G_RET_STS_ERROR;
7153   END IF;
7154 
7155   IF p_object_id = G_PA_MISS_NUM THEN
7156        NULL;
7157   ELSIF p_object_id IS NOT NULL THEN
7158        /* As of now we're only handling PA_TASKS objects */
7159        BEGIN
7160                SELECT proj_element_id
7161                  INTO l_object_id
7162                  FROM PA_FIN_LATEST_PUB_TASKS_V
7163                 WHERE project_id     = l_project_id
7164                   AND proj_element_id = p_object_id;
7165 
7166         EXCEPTION WHEN TOO_MANY_ROWS THEN
7167            PA_UTILS.Add_Message( p_app_short_name => 'PA'
7168                                 ,p_msg_name       => 'PA_OBJECT_NAME_MULTIPLE');
7169            x_return_status := FND_API.G_RET_STS_ERROR;
7170 
7171         WHEN OTHERS THEN
7172            PA_UTILS.Add_Message( p_app_short_name => 'PA'
7173                                 ,p_msg_name       => 'PA_OBJECT_NAME_INV');
7174            x_return_status := FND_API.G_RET_STS_ERROR;
7175         END;
7176   ELSIF p_object_id IS NULL THEN
7177           l_object_id := p_object_id;
7178   END IF;
7179 
7180   IF p_object_type = G_PA_MISS_CHAR THEN
7181        NULL;
7182   ELSIF p_object_type IS NOT NULL THEN
7183          IF p_object_type = 'PA_TASKS' THEN
7184               l_object_type := p_object_type;
7185          ELSE
7186            PA_UTILS.Add_Message( p_app_short_name => 'PA'
7187                                 ,p_msg_name       => 'PA_OBJECT_TYPE_INV');
7188            x_return_status := FND_API.G_RET_STS_ERROR;
7189          END IF;
7190   ELSIF p_object_type IS NULL THEN
7191        l_object_type := p_object_type;
7192   END IF;
7193 
7194   IF p_date_required = G_PA_MISS_DATE THEN
7195        NULL;
7196   ELSIF p_date_required IS NOT NULL THEN
7197           l_date_required := p_date_required;
7198   ELSIF p_date_required IS NULL THEN
7199           l_date_required := p_date_required;
7200   END IF;
7201 
7202   IF p_priority_code = G_PA_MISS_CHAR THEN
7203        NULL;
7204   ELSIF p_priority_code IS NOT NULL THEN
7205           OPEN c_lkup(l_priority_type, p_priority_code);
7206           FETCH c_lkup INTO l_priority_code;
7207           IF c_lkup%NOTFOUND then
7208           -- close c_lkup;
7209                PA_UTILS.Add_Message( p_app_short_name => 'PA'
7210                                     ,p_msg_name       => 'PA_CI_PRIORITY_INV');
7211                x_return_status := FND_API.G_RET_STS_ERROR;
7212           END IF;
7213           close c_lkup;
7214   ELSIF p_priority_code IS NULL THEN
7215           l_priority_code := p_priority_code;
7216   END IF;
7217 
7218   IF p_effort_level_code = G_PA_MISS_CHAR THEN
7219        l_effort_level_code := null;
7220   ELSIF p_effort_level_code IS NOT NULL THEN
7221           OPEN c_lkup(l_effort_type, p_effort_level_code);
7222           FETCH c_lkup INTO l_effort_level_code;
7223           IF c_lkup%NOTFOUND then
7224           --  close c_lkup;
7225                PA_UTILS.Add_Message( p_app_short_name => 'PA'
7226                                     ,p_msg_name       => 'PA_CI_EFFORT_INV');
7227                x_return_status := FND_API.G_RET_STS_ERROR;
7228           END IF;
7229           close c_lkup;
7230   ELSIF p_effort_level_code IS NULL THEN
7231           l_effort_level_code := p_effort_level_code;
7232   END IF;
7233 
7234   IF p_price = G_PA_MISS_NUM THEN
7235        l_price := null;
7236   ELSIF p_price IS NOT NULL THEN
7237           l_price := p_price;
7238   ELSIF p_price IS NULL THEN
7239           l_price := p_price;
7240   END IF;
7241 
7242   IF p_price_currency_code = G_PA_MISS_CHAR THEN
7243        NULL;
7244   ELSIF p_price_currency_code IS NOT NULL THEN
7245           l_price_currency_code := p_price_currency_code;
7246           /* Getting validated in pa_control_items_pvt.update_control_item API. */
7247   ELSIF p_price_currency_code IS NULL THEN
7248           l_price_currency_code := p_price_currency_code;
7249   END IF;
7250 
7251   IF p_source_type_code = G_PA_MISS_CHAR THEN
7252        NULL;
7253   ELSIF p_source_type_code IS NOT NULL THEN
7254           OPEN c_lkup(l_source_type, p_source_type_code);
7255           FETCH c_lkup INTO l_source_type_code;
7256           IF c_lkup%NOTFOUND then
7257             -- close c_lkup;
7258                PA_UTILS.Add_Message( p_app_short_name => 'PA'
7259                                     ,p_msg_name       => 'PA_CI_SOURCE_TYPE_INV');
7260                x_return_status := FND_API.G_RET_STS_ERROR;
7261           END IF;
7262           close c_lkup;
7263   ELSIF p_source_type_code IS NULL THEN
7264           l_source_type_code := p_source_type_code;
7265   END IF;
7266 
7267   IF p_source_comment = G_PA_MISS_CHAR THEN
7268        NULL;
7269   ELSE
7270           l_source_comment := p_source_comment;
7271   END IF;
7272 
7273   IF p_source_number = G_PA_MISS_CHAR THEN
7274        NULL;
7275   ELSE
7276           l_source_number := p_source_number;
7277   END IF;
7278 
7279   IF p_source_date_received = G_PA_MISS_DATE THEN
7280        NULL;
7281   ELSE
7282           l_source_date_received := p_source_date_received;
7283   END IF;
7284 
7285   IF p_source_organization = G_PA_MISS_CHAR THEN
7286        NULL;
7287   ELSE
7288           l_source_organization := p_source_organization;
7289   END IF;
7290 
7291   IF p_source_person = G_PA_MISS_CHAR THEN
7292        NULL;
7293   ELSE
7294           l_source_person := p_source_person;
7295   END IF;
7296 
7297   IF p_progress_as_of_date = G_PA_MISS_DATE THEN
7298        NULL;
7299   ELSIF p_progress_as_of_date IS NOT NULL THEN
7300           l_progress_as_of_date := p_progress_as_of_date;
7301   ELSIF p_progress_as_of_date IS NULL THEN
7302           PA_UTILS.Add_Message( p_app_short_name => 'PA'
7303                                ,p_msg_name       => 'PA_AS_OF_DATE_NULL');
7304           x_return_status := FND_API.G_RET_STS_ERROR;
7305   END IF;
7306 
7307   OPEN c_auto_num;
7308   FETCH c_auto_num INTO l_auto_numbers;
7309   close c_auto_num;
7310 
7311   IF l_auto_numbers is NOT NULL and l_auto_numbers <> 'Y' then
7312 
7313        IF (p_ci_number = G_PA_MISS_CHAR OR p_ci_number IS NULL) THEN
7314 
7315               IF l_ci_status_code IS NOT NULL THEN
7316                     l_new_system_status :=  PA_CONTROL_ITEMS_UTILS.getSystemStatus(l_ci_status_code);
7317               END IF;
7318 
7319               IF p_ci_number = G_PA_MISS_CHAR THEN
7320                    IF l_ci_number IS NULL THEN
7321                         IF (l_curr_system_status = 'CI_DRAFT' AND (l_new_system_status IS NOT NULL AND l_new_system_status <> 'CI_DRAFT')) THEN
7322                               PA_UTILS.Add_Message( p_app_short_name => 'PA'
7323                                                    ,p_msg_name       => 'PA_CI_NO_CI_NUMBER');
7324                               x_return_status := FND_API.G_RET_STS_ERROR;
7325                         ELSIF l_curr_system_status <> 'CI_DRAFT' THEN
7326                                 PA_UTILS.Add_Message( p_app_short_name => 'PA'
7327                                                      ,p_msg_name       => 'PA_CI_NO_CI_NUMBER');
7328                                 x_return_status := FND_API.G_RET_STS_ERROR;
7329                         END IF;
7330                    END IF;
7331               ELSIF p_ci_number IS NULL THEN
7332                  IF (l_curr_system_status = 'CI_DRAFT' AND (l_new_system_status IS NOT NULL AND l_new_system_status <> 'CI_DRAFT')) THEN
7333                        PA_UTILS.Add_Message( p_app_short_name => 'PA'
7334                                             ,p_msg_name       => 'PA_CI_NO_CI_NUMBER');
7335                        x_return_status := FND_API.G_RET_STS_ERROR;
7336                  ELSIF l_curr_system_status <> 'CI_DRAFT' THEN
7337                        PA_UTILS.Add_Message( p_app_short_name => 'PA'
7338                                             ,p_msg_name       => 'PA_CI_NO_CI_NUMBER');
7339                        x_return_status := FND_API.G_RET_STS_ERROR;
7340                  END IF;
7341               END IF;
7342 
7343        ELSIF p_ci_number IS NOT NULL THEN
7344                l_ci_number := p_ci_number;
7345 
7346                OPEN c_ci_number(l_project_id, l_ci_type_id);
7347                FETCH c_ci_number into l_ROWID;
7348                IF (c_ci_number%NOTFOUND) then
7349                     CLOSE c_ci_number;
7350                ELSE
7351                     CLOSE c_ci_number;
7352                     PA_UTILS.Add_Message( p_app_short_name => 'PA'
7353                                          ,p_msg_name       => 'PA_CI_DUPLICATE_CI_NUMBER');
7354                     x_return_status := FND_API.G_RET_STS_ERROR;
7355                END IF;
7356        END IF;
7357 
7358   END IF;
7359 
7360 
7361   IF p_progress_status_code = G_PA_MISS_CHAR THEN
7362        NULL;
7363   ELSIF p_progress_status_code IS NOT NULL THEN
7364           OPEN c_statuses(l_progress_type, p_progress_status_code);
7365           FETCH c_statuses INTO l_progress_status_code;
7366           IF c_statuses%NOTFOUND then
7367                close c_statuses;
7368                PA_UTILS.Add_Message( p_app_short_name => 'PA'
7369                                     ,p_msg_name       => 'PA_PROGRESS_STATUS_INV');
7370                x_return_status := FND_API.G_RET_STS_ERROR;
7371           END IF;
7372           close c_statuses;
7373   ELSIF p_progress_status_code IS NULL THEN
7374           PA_UTILS.Add_Message( p_app_short_name => 'PA'
7375                                ,p_msg_name       => 'PA_PROGRESS_STATUS_NULL');
7376           x_return_status := FND_API.G_RET_STS_ERROR;
7377   END IF;
7378 
7379   IF p_progress_overview = G_PA_MISS_CHAR THEN
7380        NULL;
7381   ELSE
7382           l_progress_overview := p_progress_overview;
7383   END IF;
7384 
7385   IF p_resolution_code = G_PA_MISS_CHAR THEN
7386        NULL;
7387   ELSIF p_resolution_code IS NOT NULL THEN
7388           OPEN c_resolution (l_ci_type_id, p_resolution_code);
7389           FETCH c_resolution INTO l_resolution_code_id;
7390           IF c_resolution%NOTFOUND then
7391                close c_resolution;
7392                PA_UTILS.Add_Message( p_app_short_name => 'PA'
7393                                     ,p_msg_name       => 'PA_CI_RESOLUTION_INV');
7394                x_return_status := FND_API.G_RET_STS_ERROR;
7395           END IF;
7396           close c_resolution;
7397   ELSIF p_resolution_code IS NULL THEN
7398           l_resolution_code_id := p_resolution_code;
7399   END IF;
7400 
7401   IF p_resolution_comment = G_PA_MISS_CHAR THEN
7402        NULL;
7403   ELSE
7404        l_resolution_comment := p_resolution_comment;
7405   END IF;
7406 
7407   IF p_attribute_category = G_PA_MISS_CHAR THEN
7408        NULL;
7409   ELSE
7410        l_attribute_category := p_attribute_category;
7411   END IF;
7412 
7413   IF p_attribute1 = G_PA_MISS_CHAR THEN
7414        NULL;
7415   ELSE
7416        l_attribute1 := p_attribute1;
7417   END IF;
7418 
7419   IF p_attribute2 = G_PA_MISS_CHAR THEN
7420        NULL;
7421   ELSE
7422        l_attribute2 := p_attribute2;
7423   END IF;
7424 
7425   IF p_attribute3 = G_PA_MISS_CHAR THEN
7426        NULL;
7427   ELSE
7428        l_attribute3 := p_attribute3;
7429   END IF;
7430 
7431   IF p_attribute4 = G_PA_MISS_CHAR THEN
7432        NULL;
7433   ELSE
7434        l_attribute4 := p_attribute4;
7435   END IF;
7436 
7437   IF p_attribute5 = G_PA_MISS_CHAR THEN
7438        NULL;
7439   ELSE
7440        l_attribute5 := p_attribute5;
7441   END IF;
7442 
7443   IF p_attribute6 = G_PA_MISS_CHAR THEN
7444        NULL;
7445   ELSE
7446        l_attribute6 := p_attribute6;
7447   END IF;
7448 
7449   IF p_attribute7 = G_PA_MISS_CHAR THEN
7450        NULL;
7451   ELSE
7452        l_attribute7 := p_attribute7;
7453   END IF;
7454 
7455   IF p_attribute8 = G_PA_MISS_CHAR THEN
7456        NULL;
7457   ELSE
7458        l_attribute8 := p_attribute8;
7459   END IF;
7460 
7461   IF p_attribute9 = G_PA_MISS_CHAR THEN
7462        NULL;
7463   ELSE
7464        l_attribute9 := p_attribute9;
7465   END IF;
7466 
7467   IF p_attribute10 = G_PA_MISS_CHAR THEN
7468        NULL;
7469   ELSE
7470        l_attribute10 := p_attribute10;
7471   END IF;
7472 
7473   IF p_attribute11 = G_PA_MISS_CHAR THEN
7474        NULL;
7475   ELSE
7476        l_attribute11 := p_attribute11;
7477   END IF;
7478 
7479   IF p_attribute12 = G_PA_MISS_CHAR THEN
7480        NULL;
7481   ELSE
7482        l_attribute12 := p_attribute12;
7483   END IF;
7484 
7485   IF p_attribute13 = G_PA_MISS_CHAR THEN
7486        NULL;
7487   ELSE
7488        l_attribute13 := p_attribute13;
7489   END IF;
7490 
7491   IF p_attribute14 = G_PA_MISS_CHAR THEN
7492        NULL;
7493   ELSE
7494        l_attribute14 := p_attribute14;
7495   END IF;
7496 
7497   IF p_attribute15 = G_PA_MISS_CHAR THEN
7498        NULL;
7499   ELSE
7500        l_attribute15 := p_attribute15;
7501   END IF;
7502 
7503 
7504   IF (l_curr_status_code is NOT NULL AND
7505       l_ci_status_code   is NOT NULL AND
7506       l_curr_status_code <> l_ci_status_code AND
7507       l_to_status_flag = 'Y') THEN
7508 
7509 	 IF l_debug_mode = 'Y' THEN
7510    	      pa_debug.write(l_module, 'Before call to PA_CONTROL_ITEMS_UTILS.ChangeCIStatusValidate', l_debug_level3);
7511          END IF;
7512 
7513          PA_CONTROL_ITEMS_UTILS.ChangeCIStatusValidate (
7514                                   p_init_msg_list      => p_init_msg_list
7515                                  ,p_commit             => p_commit
7516                                  ,p_validate_only      => l_validate_only
7517                                  ,p_max_msg_count      => l_max_msg_count
7518                                  ,p_ci_id              => p_ci_id
7519                                  ,p_status             => p_ci_status_code
7520                                  ,p_enforce_security   => l_enforce_security
7521                                  ,p_resolution_check   => l_resolution_check
7522                                  ,x_resolution_req     => l_resolution_req
7523                                  ,x_resolution_req_cls => l_resolution_req_cls
7524                                  ,x_start_wf           => l_start_wf
7525                                  ,x_new_status         => l_ci_status_code
7526                                  ,x_num_of_actions     => l_num_of_actions
7527                                  ,x_return_status      => x_return_status
7528                                  ,x_msg_count          => x_msg_count
7529                                  ,x_msg_data           => x_msg_data);
7530 
7531        /* l_ci_status_code gets the new status from ChangeCIStatusValidate.
7532           In case of CR/CO, if Auto Approve on Submission is enabled and while changing the status to submitted,
7533           then the new status would be the success status code defined for the workflow */
7534 
7535 	IF l_debug_mode = 'Y' THEN
7536    	     pa_debug.write(l_module, 'after call to PA_CONTROL_ITEMS_UTILS.ChangeCIStatusValidate: x_return_status = '||x_return_status, l_debug_level3);
7537    	     pa_debug.write(l_module, 'after call to PA_CONTROL_ITEMS_UTILS.ChangeCIStatusValidate: l_ci_status_code = '||l_ci_status_code, l_debug_level3);
7538         END IF;
7539 
7540         IF x_return_status = 'S' THEN
7541              l_status_change_flag := 'Y';
7542         END IF;
7543 
7544 	IF l_debug_mode = 'Y' THEN
7545    	     pa_debug.write(l_module, 'after call to PA_CONTROL_ITEMS_UTILS.ChangeCIStatusValidate: l_status_change_flag = '||l_status_change_flag, l_debug_level3);
7546         END IF;
7547 
7548         IF (l_resolution_req IS NOT NULL AND  l_resolution_req = 'Y') THEN
7549               IF (PA_CONTROL_ITEMS_UTILS.checkhasresolution(p_ci_id) <> 'Y'  ) THEN
7550                   IF (l_resolution_code_id IS NULL) THEN
7551                       PA_UTILS.Add_Message( p_app_short_name => 'PA'
7552                                            ,p_msg_name       => 'PA_CI_RESOLUTION_OPEN');
7553                       x_return_status := FND_API.G_RET_STS_ERROR;
7554                   END IF;
7555               ELSE
7556                   IF (l_resolution_code_id IS NULL) THEN
7557                       PA_UTILS.Add_Message( p_app_short_name => 'PA'
7558                                            ,p_msg_name       => 'PA_CI_RESOLUTION_OPEN');
7559                       x_return_status := FND_API.G_RET_STS_ERROR;
7560                   END IF;
7561               END IF;
7562         END IF;
7563 
7564         IF (l_resolution_req_cls IS NOT NULL AND  l_resolution_req_cls = 'Y') THEN
7565               IF (PA_CONTROL_ITEMS_UTILS.checkhasresolution(p_ci_id) <> 'Y'  ) THEN
7566                   IF (l_resolution_code_id IS NULL) THEN
7567                       PA_UTILS.Add_Message( p_app_short_name => 'PA'
7568                                            ,p_msg_name       => 'PA_CI_CLOSE_INV_RES');
7569                       x_return_status := FND_API.G_RET_STS_ERROR;
7570                   END IF;
7571               ELSE
7572                   IF (l_resolution_code_id IS NULL) THEN
7573                       PA_UTILS.Add_Message( p_app_short_name => 'PA'
7574                                            ,p_msg_name       => 'PA_CI_CLOSE_INV_RES');
7575                       x_return_status := FND_API.G_RET_STS_ERROR;
7576                   END IF;
7577               END IF;
7578         END IF;
7579 
7580   END IF;
7581 
7582 
7583   IF (l_validate_only <> fnd_api.g_true AND x_return_status = 'S') THEN
7584 
7585 	  IF l_debug_mode = 'Y' THEN
7586    	       pa_debug.write(l_module, 'before call to PA_CONTROL_ITEMS_PUB.UPDATE_CONTROL_ITEM', l_debug_level3);
7587           END IF;
7588 
7589           PA_CONTROL_ITEMS_PUB.UPDATE_CONTROL_ITEM (
7590                                  p_api_version           =>  1.0
7591                                 ,p_init_msg_list         => fnd_api.g_false
7592                                 ,p_commit                => FND_API.g_false
7593                                 ,p_validate_only         => FND_API.g_false
7594                                 ,p_max_msg_count         => FND_API.g_miss_num
7595                                 ,p_ci_id                 => p_ci_id
7596                                 ,p_ci_type_id            => l_ci_type_id
7597                                 ,p_summary               => l_summary
7598                                 ,p_status_code           => l_ci_status_code
7599                                 ,p_owner_id              => l_owner_id
7600                                 ,p_owner_name            => null
7601                                 ,p_highlighted_flag      => null
7602                                 ,p_progress_status_code  => l_progress_status_code
7603                                 ,p_progress_as_of_date   => l_progress_as_of_date
7604                                 ,p_classification_code   => l_classification_code_id
7605                                 ,p_reason_code           => l_reason_code_id
7606                                 ,p_record_version_number => l_record_version_number
7607                                 ,p_project_id            => l_project_id
7608                                 ,p_object_type           => l_object_type
7609                                 ,p_object_id             => l_object_id
7610                                 ,p_object_name           => null
7611                                 ,p_ci_number             => l_ci_number
7612                                 ,p_date_required         => l_date_required
7613                                 ,p_date_closed           => l_date_closed
7614                                 ,p_closed_by_id          => l_closed_by_id
7615                                 ,p_description           => l_description
7616                                 ,p_status_overview       => l_progress_overview
7617                                 ,p_resolution            => l_resolution_comment
7618                                 ,p_resolution_code       => l_resolution_code_id
7619                                 ,p_priority_code         => l_priority_code
7620                                 ,p_effort_level_code     => l_effort_level_code
7621                                 ,p_open_action_num       => null
7622                                 ,p_price                 => l_price
7623                                 ,p_price_currency_code   => l_price_currency_code
7624                                 ,p_source_type_code      => l_source_type_code
7625                                 ,p_source_comment        => l_source_comment
7626                                 ,p_source_number         => l_source_number
7627                                 ,p_source_date_received  => l_source_date_received
7628                                 ,p_source_organization   => l_source_organization
7629                                 ,p_source_person         => l_source_person
7630                                 ,p_attribute_category    => l_attribute_category
7631                                 ,p_attribute1            => l_attribute1
7632                                 ,p_attribute2            => l_attribute2
7633                                 ,p_attribute3            => l_attribute3
7634                                 ,p_attribute4            => l_attribute4
7635                                 ,p_attribute5            => l_attribute5
7636                                 ,p_attribute6            => l_attribute6
7637                                 ,p_attribute7            => l_attribute7
7638                                 ,p_attribute8            => l_attribute8
7639                                 ,p_attribute9            => l_attribute9
7640                                 ,p_attribute10           => l_attribute10
7641                                 ,p_attribute11           => l_attribute11
7642                                 ,p_attribute12           => l_attribute12
7643                                 ,p_attribute13           => l_attribute13
7644                                 ,p_attribute14           => l_attribute14
7645                                 ,p_attribute15           => l_attribute15
7646                                 ,x_return_status         => x_return_status
7647                                 ,x_msg_count             => x_msg_count
7648                                 ,x_msg_data              => x_msg_data
7649                         );
7650 
7651 	  IF l_debug_mode = 'Y' THEN
7652    	       pa_debug.write(l_module, 'after call to PA_CONTROL_ITEMS_PUB.UPDATE_CONTROL_ITEM : x_return_status = '||x_return_status, l_debug_level3);
7653           END IF;
7654 
7655   END IF;
7656 
7657   IF (l_status_change_flag = 'Y' AND l_validate_only <> fnd_api.g_true AND x_return_status = 'S') THEN
7658 
7659 	   IF l_debug_mode = 'Y' THEN
7660    	        pa_debug.write(l_module, 'before call to PA_CONTROL_ITEMS_UTILS.ADD_STATUS_CHANGE_COMMENT', l_debug_level3);
7661            END IF;
7662 
7663            /* call the insert table handlers of pa_obj_status_changes and pa_ci_comments here */
7664 
7665            PA_CONTROL_ITEMS_UTILS.ADD_STATUS_CHANGE_COMMENT( p_object_type        => 'PA_CI_TYPES'
7666                                                             ,p_object_id          => p_ci_id
7667                                                             ,p_type_code          => 'CHANGE_STATUS'
7668                                                             ,p_status_type        => 'CONTROL_ITEM'
7669                                                             ,p_new_project_status => l_ci_status_code
7670                                                             ,p_old_project_status => l_curr_status_code
7671                                                             ,p_comment            => p_status_comment
7672                                                             ,x_return_status      => x_return_status
7673                                                             ,x_msg_count          => x_msg_count
7674                                                             ,x_msg_data           => x_msg_data );
7675 
7676 	   IF l_debug_mode = 'Y' THEN
7677    	        pa_debug.write(l_module, 'after call to PA_CONTROL_ITEMS_UTILS.ADD_STATUS_CHANGE_COMMENT', l_debug_level3);
7678            END IF;
7679 
7680            PA_CONTROL_ITEMS_UTILS.PostChangeCIStatus (
7681                                                           p_init_msg_list
7682                                                          ,p_commit
7683                                                          ,l_validate_only
7684                                                          ,l_max_msg_count
7685                                                          ,p_ci_id
7686                                                          ,l_curr_status_code
7687                                                          ,l_ci_status_code
7688                                                          ,l_start_wf
7689                                                          ,l_enforce_security
7690                                                          ,l_num_of_actions
7691                                                          ,x_return_status
7692                                                          ,x_msg_count
7693                                                          ,x_msg_data    );
7694 
7695 
7696            IF l_debug_mode = 'Y' THEN
7697                 pa_debug.write(l_module, 'after call to PA_CONTROL_ITEMS_UTILS.PostChangeCIStatus', l_debug_level3);
7698            END IF;
7699 
7700   END IF;
7701 
7702 
7703   IF (p_commit = FND_API.G_TRUE AND x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
7704 
7705         IF l_debug_mode = 'Y' THEN
7706              pa_debug.write(l_module, 'Before Commit', l_debug_level3);
7707         END IF;
7708 
7709         COMMIT;
7710 
7711   END IF;
7712 
7713    --Reset the stack
7714          if l_debug_mode = 'Y' then
7715                   Pa_Debug.reset_curr_function;
7716          end if;
7717 
7718 
7719 EXCEPTION
7720 
7721    WHEN FND_API.G_EXC_ERROR THEN
7722         IF l_debug_mode = 'Y' THEN
7723              pa_debug.write(l_module, 'in FND_API.G_EXC_ERROR exception', l_debug_level3);
7724         END IF;
7725         x_return_status := FND_API.G_RET_STS_ERROR;
7726         l_msg_count := FND_MSG_PUB.count_msg;
7727 
7728         IF p_commit = FND_API.G_TRUE THEN
7729                 ROLLBACK TO UPDATE_ISSUE_SVPT;
7730         END IF;
7731 
7732         IF l_msg_count = 1 AND x_msg_data IS NULL THEN
7733                 PA_INTERFACE_UTILS_PUB.get_messages
7734                 ( p_encoded        => FND_API.G_FALSE
7735                 , p_msg_index      => 1
7736                 , p_msg_count      => l_msg_count
7737                 , p_msg_data       => l_msg_data
7738                 , p_data           => l_data
7739                 , p_msg_index_out  => l_msg_index_out);
7740 
7741                 x_msg_data := l_data;
7742                 x_msg_count := l_msg_count;
7743         ELSE
7744                 x_msg_count := l_msg_count;
7745         END IF;
7746 
7747         IF l_debug_mode = 'Y' THEN
7748                 Pa_Debug.reset_curr_function;
7749         END IF;
7750 
7751 
7752    WHEN OTHERS THEN
7753         IF l_debug_mode = 'Y' THEN
7754              pa_debug.write(l_module, 'in OTHERS exception', l_debug_level3);
7755         END IF;
7756         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7757         x_msg_data      := substr(SQLERRM,1,240);
7758 
7759         IF p_commit = FND_API.G_TRUE THEN
7760                 ROLLBACK TO UPDATE_ISSUE_SVPT;
7761         END IF;
7762 
7763         FND_MSG_PUB.add_exc_msg
7764         ( p_pkg_name            => 'PA_CONTROL_API_PUB'
7765         , p_procedure_name      => 'UPDATE_ISSUE'
7766         , p_error_text          => x_msg_data);
7767 
7768         x_msg_count     := FND_MSG_PUB.count_msg;
7769 
7770         IF l_debug_mode = 'Y' THEN
7771                 PA_DEBUG.reset_curr_function;
7772         END IF;
7773 
7774 --        RAISE;
7775 
7776 END UPDATE_ISSUE;
7777 
7778 
7779 PROCEDURE UPDATE_CHANGE_REQUEST (
7780                         p_commit                IN      VARCHAR2 := FND_API.G_FALSE,
7781                         p_init_msg_list         IN      VARCHAR2 := FND_API.G_FALSE,
7782                         p_api_version_number    IN      NUMBER,
7783                         x_return_status         OUT NOCOPY    VARCHAR2,
7784                         x_msg_count             OUT NOCOPY    NUMBER,
7785                         x_msg_data              OUT NOCOPY    VARCHAR2,
7786                         p_ci_id                 IN      NUMBER,
7787                         P_RECORD_VERSION_NUMBER IN      NUMBER   := G_PA_MISS_NUM,
7788                         P_SUMMARY               IN      VARCHAR2 := G_PA_MISS_CHAR,
7789                         P_DESCRIPTION           IN      VARCHAR2 := G_PA_MISS_CHAR,
7790                         P_OWNER_ID              IN      NUMBER   := G_PA_MISS_NUM,
7791                         P_OWNER_COMMENT         IN      VARCHAR2 := G_PA_MISS_CHAR,
7792                         P_CLASSIFICATION_CODE   IN      NUMBER   := G_PA_MISS_NUM,
7793                         P_REASON_CODE           IN      NUMBER   := G_PA_MISS_NUM,
7794                         P_OBJECT_ID             IN      NUMBER   := G_PA_MISS_NUM,
7795                         P_OBJECT_TYPE           IN      VARCHAR2 := G_PA_MISS_CHAR,
7796                         P_CI_NUMBER             IN      VARCHAR2 := G_PA_MISS_CHAR,
7797                         P_DATE_REQUIRED         IN      DATE     := G_PA_MISS_DATE,
7798                         P_PRIORITY_CODE         IN      VARCHAR2 := G_PA_MISS_CHAR,
7799                         P_EFFORT_LEVEL_CODE     IN      VARCHAR2 := G_PA_MISS_CHAR,
7800                         P_PRICE                 IN      NUMBER   := G_PA_MISS_NUM,
7801                         P_PRICE_CURRENCY_CODE   IN      VARCHAR2 := G_PA_MISS_CHAR,
7802                         P_SOURCE_TYPE_CODE      IN      VARCHAR2 := G_PA_MISS_CHAR,
7803                         P_SOURCE_NUMBER         IN      VARCHAR2 := G_PA_MISS_CHAR,
7804                         P_SOURCE_COMMENT        IN      VARCHAR2 := G_PA_MISS_CHAR,
7805                         P_SOURCE_DATE_RECEIVED  IN      DATE     := G_PA_MISS_DATE,
7806                         P_SOURCE_ORGANIZATION   IN      VARCHAR2 := G_PA_MISS_CHAR,
7807                         P_SOURCE_PERSON         IN      VARCHAR2 := G_PA_MISS_CHAR,
7808                         P_CI_STATUS_CODE        IN      VARCHAR2 := G_PA_MISS_CHAR,
7809                         P_STATUS_COMMENT        IN      VARCHAR2 := G_PA_MISS_CHAR,
7810                         P_PROGRESS_AS_OF_DATE   IN      DATE     := G_PA_MISS_DATE,
7811                         P_PROGRESS_STATUS_CODE  IN      VARCHAR2 := G_PA_MISS_CHAR,
7812                         P_PROGRESS_OVERVIEW     IN      VARCHAR2 := G_PA_MISS_CHAR,
7813                         P_RESOLUTION_CODE       IN      VARCHAR2 := G_PA_MISS_CHAR,
7814                         P_RESOLUTION_COMMENT    IN      VARCHAR2 := G_PA_MISS_CHAR,
7815                         P_ATTRIBUTE_CATEGORY    IN      VARCHAR2 := G_PA_MISS_CHAR,
7816                         P_ATTRIBUTE1            IN      VARCHAR2 := G_PA_MISS_CHAR,
7817                         P_ATTRIBUTE2            IN      VARCHAR2 := G_PA_MISS_CHAR,
7818                         P_ATTRIBUTE3            IN      VARCHAR2 := G_PA_MISS_CHAR,
7819                         P_ATTRIBUTE4            IN      VARCHAR2 := G_PA_MISS_CHAR,
7820                         P_ATTRIBUTE5            IN      VARCHAR2 := G_PA_MISS_CHAR,
7821                         P_ATTRIBUTE6            IN      VARCHAR2 := G_PA_MISS_CHAR,
7822                         P_ATTRIBUTE7            IN      VARCHAR2 := G_PA_MISS_CHAR,
7823                         P_ATTRIBUTE8            IN      VARCHAR2 := G_PA_MISS_CHAR,
7824                         P_ATTRIBUTE9            IN      VARCHAR2 := G_PA_MISS_CHAR,
7825                         P_ATTRIBUTE10           IN      VARCHAR2 := G_PA_MISS_CHAR,
7826                         P_ATTRIBUTE11           IN      VARCHAR2 := G_PA_MISS_CHAR,
7827                         P_ATTRIBUTE12           IN      VARCHAR2 := G_PA_MISS_CHAR,
7828                         P_ATTRIBUTE13           IN      VARCHAR2 := G_PA_MISS_CHAR,
7829                         P_ATTRIBUTE14           IN      VARCHAR2 := G_PA_MISS_CHAR,
7830                         P_ATTRIBUTE15           IN      VARCHAR2 := G_PA_MISS_CHAR
7831                         )
7832 IS
7833 
7834 
7835 
7836 
7837  l_data                       VARCHAR2(2000);
7838  l_msg_data                   VARCHAR2(2000);
7839  l_msg_index_out              NUMBER;
7840  l_msg_count                  NUMBER := 0;
7841 
7842  l_check_update_access        VARCHAR2(1) := 'F';
7843  l_chk_status_ctrl            VARCHAR2(1) := 'N';
7844  l_module                     VARCHAR2(100) := 'PA_CONTROL_API_PUB.UPDATE_CHANGE_REQUEST';
7845 
7846 
7847  l_curr_status_code                   pa_control_items.status_code%TYPE;
7848  l_ci_status_code                     pa_control_items.status_code%TYPE;
7849  l_record_version_number              pa_control_items.record_version_number%TYPE;
7850  l_summary                            pa_control_items.summary%TYPE;
7851  l_description                        pa_control_items.description%TYPE;
7852  l_curr_owner_id                      pa_control_items.owner_id%TYPE;
7853  l_owner_id                           pa_control_items.owner_id%TYPE;
7854  l_classification_code_id             pa_control_items.classification_code_id%TYPE;
7855  l_reason_code_id                     pa_control_items.reason_code_id%TYPE;
7856  l_object_id                          pa_control_items.object_id%TYPE;
7857  l_object_type                        pa_control_items.object_type%TYPE;
7858  l_ci_number                          pa_control_items.ci_number%TYPE;
7859  l_date_required                      pa_control_items.date_required%TYPE;
7860  l_priority_code                      pa_control_items.priority_code%TYPE;
7861  l_effort_level_code                  pa_control_items.effort_level_code%TYPE;
7862  l_price                              pa_control_items.price%TYPE;
7863  l_price_currency_code                pa_control_items.price_currency_code%TYPE;
7864  l_source_type_code                   pa_control_items.source_type_code%TYPE;
7865  l_source_comment                     pa_control_items.source_comment%TYPE;
7866  l_source_number                      pa_control_items.source_number%TYPE;
7867  l_source_date_received               pa_control_items.source_date_received%TYPE;
7868  l_source_organization                pa_control_items.source_organization%TYPE;
7869  l_source_person                      pa_control_items.source_person%TYPE;
7870  l_progress_as_of_date                pa_control_items.progress_as_of_date%TYPE;
7871  l_progress_status_code               pa_control_items.progress_status_code%TYPE;
7872  l_progress_overview                  pa_control_items.status_overview%TYPE;
7873  l_resolution_code_id                 pa_control_items.resolution_code_id%TYPE;
7874  l_resolution_comment                 pa_control_items.resolution%TYPE;
7875  l_date_closed                        pa_control_items.date_closed%TYPE;
7876  l_closed_by_id                       pa_control_items.closed_by_id%TYPE;
7877  l_project_id                         pa_control_items.project_id%TYPE;
7878  l_ci_type_id                         pa_control_items.ci_type_id%TYPE;
7879  l_attribute_category                 pa_control_items.attribute_category%TYPE;
7880  l_attribute1                         pa_control_items.attribute1%TYPE;
7881  l_attribute2                         pa_control_items.attribute2%TYPE;
7882  l_attribute3                         pa_control_items.attribute3%TYPE;
7883  l_attribute4                         pa_control_items.attribute4%TYPE;
7884  l_attribute5                         pa_control_items.attribute5%TYPE;
7885  l_attribute6                         pa_control_items.attribute6%TYPE;
7886  l_attribute7                         pa_control_items.attribute7%TYPE;
7887  l_attribute8                         pa_control_items.attribute8%TYPE;
7888  l_attribute9                         pa_control_items.attribute9%TYPE;
7889  l_attribute10                        pa_control_items.attribute10%TYPE;
7890  l_attribute11                        pa_control_items.attribute11%TYPE;
7891  l_attribute12                        pa_control_items.attribute12%TYPE;
7892  l_attribute13                        pa_control_items.attribute13%TYPE;
7893  l_attribute14                        pa_control_items.attribute14%TYPE;
7894  l_attribute15                        pa_control_items.attribute15%TYPE;
7895   l_class_code                         constant varchar2(20) := 'CHANGE_REQUEST';
7896 
7897  CURSOR curr_row is
7898     SELECT *
7899       FROM pa_control_items
7900      WHERE ci_id = p_ci_id;
7901 
7902  cp    curr_row%rowtype;
7903 
7904  CURSOR c_submit_status (p_curr_status_code VARCHAR2) IS
7905     SELECT enable_wf_flag, wf_success_status_code, wf_failure_status_code
7906       FROM pa_project_statuses
7907      WHERE project_status_code = p_curr_status_code;
7908 
7909  CURSOR c_lkup (p_lookup_type VARCHAR2, p_lookup_code VARCHAR2) IS
7910     SELECT lookup_code
7911       FROM pa_lookups
7912      WHERE lookup_type = p_lookup_type
7913        AND trunc(sysdate) BETWEEN start_date_active AND nvl(end_date_active, trunc(sysdate))
7914        AND enabled_flag = 'Y'
7915        AND lookup_code = p_lookup_code;
7916 
7917  CURSOR c_statuses (p_status_type VARCHAR2, p_project_status_code VARCHAR2) IS
7918     SELECT project_status_code
7919       FROM pa_project_statuses
7920      WHERE status_type = p_status_type
7921        AND project_status_code = p_project_status_code
7922        AND trunc(sysdate) BETWEEN start_date_active AND nvl(end_date_active, trunc(sysdate));
7923 
7924  CURSOR c_classification (p_ci_type_id NUMBER, p_class_code_id NUMBER) IS
7925     SELECT cat.class_code_id
7926       FROM pa_class_codes cat,
7927            pa_ci_types_b typ
7928      WHERE trunc(sysdate) between cat.start_date_active and nvl(cat.end_date_active,trunc(sysdate))
7929        AND typ.ci_type_id = p_ci_type_id
7930        AND cat.class_category = typ.classification_category
7931        AND cat.class_code_id = p_class_code_id;
7932 
7933  CURSOR c_reason (p_ci_type_id NUMBER, p_reason_code_id NUMBER) IS
7934     SELECT cat.class_code_id
7935       FROM pa_class_codes cat,
7936            pa_ci_types_b typ
7937      WHERE trunc(sysdate) between cat.start_date_active and nvl(cat.end_date_active,trunc(sysdate))
7938        AND typ.ci_type_id = p_ci_type_id
7939        AND cat.class_category = typ.reason_category
7940        AND cat.class_code_id = p_reason_code_id;
7941 
7942  CURSOR c_resolution (p_ci_type_id NUMBER, p_resolution_code_id NUMBER) IS
7943     SELECT cat.class_code_id
7944       FROM pa_class_codes cat,
7945            pa_ci_types_b typ
7946      WHERE trunc(sysdate) between cat.start_date_active and nvl(cat.end_date_active,trunc(sysdate))
7947        AND typ.ci_type_id = p_ci_type_id
7948        AND cat.class_category = typ.resolution_category
7949        AND cat.class_code_id = p_resolution_code_id;
7950 
7951  CURSOR c_auto_num IS
7952     SELECT type.auto_number_flag
7953       FROM pa_ci_types_b type,
7954            pa_control_items ci
7955      WHERE ci.ci_id = p_ci_id
7956        AND ci.ci_type_id = type.ci_type_id;
7957 
7958  CURSOR c_ci_number (p_project_id NUMBER, p_ci_type_id NUMBER) IS
7959     SELECT ROWID
7960       FROM pa_control_items
7961      WHERE project_id = p_project_id
7962        AND ci_number = p_ci_number
7963        AND ci_id <> p_ci_id
7964        AND ci_type_id = p_ci_type_id;
7965 
7966  CURSOR c_info IS
7967     SELECT cit.ci_type_class_code,
7968            cit.approval_required_flag,
7969              s.next_allowable_status_flag
7970       FROM pa_control_items c,
7971            pa_ci_types_b cit,
7972            pa_project_statuses s
7973      WHERE c.ci_id = p_ci_id
7974        AND c.status_code = s.project_status_code
7975        AND c.ci_type_id =cit.ci_type_id
7976        AND s.status_type = 'CONTROL_ITEM';
7977 
7978 --added to get the owner name to include in the log message
7979  CURSOR c_get_owner(c_owner_id NUMBER,c_project_id NUMBER)  IS
7980      select distinct resource_source_name party_name
7981 	 from PA_PROJECT_PARTIES_V
7982 	 where party_type <> 'ORGANIZATION'
7983 	 and resource_party_id = c_owner_id
7984          and project_id = c_project_id;
7985 
7986  l_stmnt                             VARCHAR2(5000);
7987  l_sel_clause                        VARCHAR2(300);
7988  l_from_clause                       VARCHAR2(300);
7989  l_where                             VARCHAR2(4000);
7990  l_where1                            VARCHAR2(2000);
7991  l_cursor                            NUMBER;
7992  l_rows                              NUMBER;
7993  l_rows1                             NUMBER;
7994  l_ci_status_code_1                  pa_project_statuses.project_status_code%TYPE;
7995 
7996  l_ROWID                             ROWID;
7997 
7998  l_enable_wf_flag                     pa_project_statuses.enable_wf_flag%TYPE;
7999  l_wf_success_status_code             pa_project_statuses.wf_success_status_code%TYPE;
8000  l_wf_failure_status_code             pa_project_statuses.wf_failure_status_code%TYPE;
8001  l_status_change_flag                 VARCHAR2(1) := 'N';
8002  l_start_wf                           VARCHAR2(1) := 'Y';
8003  l_validate_only                      VARCHAR2(1) := FND_API.g_false;
8004  l_max_msg_count                      NUMBER := FND_API.G_MISS_NUM;
8005  l_enforce_security                   VARCHAR2(1) := 'Y';
8006  l_num_of_actions                     NUMBER;
8007  l_priority_type                      VARCHAR2(30) := 'PA_TASK_PRIORITY_CODE';
8008  l_effort_type                        VARCHAR2(30) := 'PA_CI_EFFORT_LEVELS';
8009  l_source_type                        VARCHAR2(30) := 'PA_CI_SOURCE_TYPES';
8010  l_progress_type                      VARCHAR2(30) := 'PROGRESS';
8011  l_auto_numbers                       VARCHAR2(1);
8012  l_curr_system_status                 pa_project_statuses.project_system_status_code%TYPE;
8013  l_new_system_status                  pa_project_statuses.project_system_status_code%TYPE;
8014  l_next_allow_status_flag             pa_project_statuses.next_allowable_status_flag%TYPE;
8015  l_ci_type_class_code                 pa_ci_types_b.ci_type_class_code%TYPE;
8016  l_approval_required_flag             pa_ci_types_b.approval_required_flag%TYPE;
8017  l_resolution_check                   VARCHAR2(10) := 'AMG';
8018  l_resolution_req                     VARCHAR2(10) := 'N';
8019  l_resolution_req_cls                 VARCHAR2(10) := 'N';
8020  l_to_status_flag                     VARCHAR2(10) := 'Y';
8021 
8022  l_ci_comment_id                      pa_ci_comments.ci_comment_id%TYPE;
8023  l_comment_text                       pa_ci_comments.comment_text%TYPE;
8024  l_owner_name                         per_all_people_f.full_name%TYPE;
8025  l_curr_owner_name                    per_all_people_f.full_name%TYPE;
8026  l_chgowner_allowed                   VARCHAR2(1);
8027  l_to_owner_allowed                   VARCHAR2(1);
8028 
8029 
8030 BEGIN
8031 
8032   x_return_status := FND_API.G_RET_STS_SUCCESS;
8033 
8034   l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.login_id, 275, null, null), 'N');
8035 
8036   IF l_debug_mode = 'Y' THEN
8037         PA_DEBUG.set_curr_function(p_function => 'UPDATE_CHANGE_REQUEST', p_debug_mode => l_debug_mode);
8038   END IF;
8039 
8040   IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
8041         FND_MSG_PUB.initialize;
8042   END IF;
8043 
8044   IF p_commit = FND_API.G_TRUE THEN
8045         savepoint UPDATE_CR_SVPT;
8046   END IF;
8047 
8048   IF l_debug_mode = 'Y' THEN
8049         pa_debug.write(l_module, 'Start of Update Change Request', l_debug_level3);
8050   END IF;
8051 
8052   OPEN curr_row;
8053   FETCH curr_row INTO cp;
8054   IF curr_row%NOTFOUND then
8055       close curr_row;
8056       PA_UTILS.Add_Message( p_app_short_name => 'PA'
8057                            ,p_msg_name       => 'PA_CI_INVALID_ITEM');   /* Change this message */
8058       RAISE  FND_API.G_EXC_ERROR;
8059   ELSE
8060 
8061       l_curr_status_code        := cp.status_code;
8062       l_record_version_number   := cp.record_version_number;
8063       l_summary                 := cp.summary;
8064       l_description             := cp.description;
8065       l_curr_owner_id           := cp.owner_id;
8066       l_classification_code_id  := cp.classification_code_id;
8067       l_reason_code_id          := cp.reason_code_id;
8068       l_object_id               := cp.object_id;
8069       l_object_type             := cp.object_type;
8070       l_ci_number               := cp.ci_number;
8071       l_date_required           := cp.date_required;
8072       l_priority_code           := cp.priority_code;
8073       l_effort_level_code       := cp.effort_level_code;
8074       l_price                   := cp.price;
8075       l_price_currency_code     := cp.price_currency_code;
8076       l_source_type_code        := cp.source_type_code;
8077       l_source_comment          := cp.source_comment;
8078       l_source_number           := cp.source_number;
8079       l_source_date_received    := cp.source_date_received;
8080       l_source_organization     := cp.source_organization;
8081       l_source_person           := cp.source_person;
8082       l_progress_as_of_date     := cp.progress_as_of_date;
8083       l_progress_status_code    := cp.progress_status_code;
8084       l_progress_overview       := cp.status_overview;
8085       l_resolution_code_id      := cp.resolution_code_id;
8086       l_resolution_comment      := cp.resolution;
8087       l_date_closed             := cp.date_closed;
8088       l_closed_by_id            := cp.closed_by_id;
8089       l_project_id              := cp.project_id;
8090       l_ci_type_id              := cp.ci_type_id;
8091       l_attribute_category      := cp.attribute_category;
8092       l_attribute1              := cp.attribute1;
8093       l_attribute2              := cp.attribute2;
8094       l_attribute3              := cp.attribute3;
8095       l_attribute4              := cp.attribute4;
8096       l_attribute5              := cp.attribute5;
8097       l_attribute6              := cp.attribute6;
8098       l_attribute7              := cp.attribute7;
8099       l_attribute8              := cp.attribute8;
8100       l_attribute9              := cp.attribute9;
8101       l_attribute10             := cp.attribute10;
8102       l_attribute11             := cp.attribute11;
8103       l_attribute12             := cp.attribute12;
8104       l_attribute13             := cp.attribute13;
8105       l_attribute14             := cp.attribute14;
8106       l_attribute15             := cp.attribute15;
8107 
8108       close curr_row;
8109 
8110   END IF;
8111 
8112 
8113   OPEN c_info;
8114   FETCH c_info INTO l_ci_type_class_code, l_approval_required_flag, l_next_allow_status_flag;
8115   CLOSE c_info;
8116 
8117   /* Added to check invalid API usage*/
8118    if l_ci_type_class_code <> l_class_code then
8119 	PA_UTILS.ADD_MESSAGE(p_app_short_name  => 'PA',
8120                              p_msg_name        => 'PA_CI_INV_API_USE');
8121         if l_debug_mode = 'Y' then
8122                pa_debug.g_err_stage:= 'wrong usage of the api for the control item type';
8123                pa_debug.write(l_module,pa_debug.g_err_stage,l_debug_level3);
8124         end if;
8125 	RAISE FND_API.G_EXC_ERROR;
8126    end if;
8127 
8128 
8129 
8130   l_curr_system_status :=  PA_CONTROL_ITEMS_UTILS.getSystemStatus(l_curr_status_code);
8131 
8132   /*  Check if the user can update the item. This requires the user to be owner or to have project authority or
8133       to have open UPDATE actions and status controls are satisfied.  */
8134 
8135   l_check_update_access := pa_ci_security_pkg.check_update_access(p_ci_id);
8136 
8137   IF (l_check_update_access = 'F') THEN
8138 
8139        PA_UTILS.ADD_MESSAGE('PA', 'PA_CI_NO_UPDATE_ACCESS');
8140        RAISE FND_API.G_EXC_ERROR;
8141 
8142   END IF;
8143 
8144   IF l_debug_mode = 'Y' THEN
8145         pa_debug.write(l_module, 'After call to pa_ci_security_pkg.check_update_access', l_debug_level3);
8146   END IF;
8147 
8148   /* Check for the status control: check whether the action CONTROL_ITEM_ALLOW_UPDATE is allowed on the current status of the issue. */
8149 
8150   l_chk_status_ctrl := pa_control_items_utils.CheckCIActionAllowed('CONTROL_ITEM', l_curr_status_code, 'CONTROL_ITEM_ALLOW_UPDATE');
8151 
8152   IF (l_chk_status_ctrl = 'N') THEN
8153 
8154        PA_UTILS.ADD_MESSAGE('PA', 'PA_CI_NO_ALLOW_UPDATE');
8155        RAISE FND_API.G_EXC_ERROR;
8156 
8157   END IF;
8158 
8159 
8160   IF l_debug_mode = 'Y' THEN
8161         pa_debug.write(l_module, 'After call to pa_control_items_utils.CheckCIActionAllowed', l_debug_level3);
8162   END IF;
8163 
8164   /*  The control item will not be updateable if the current status has approval workflow attached. */
8165 
8166   OPEN c_submit_status(l_curr_status_code);
8167   FETCH c_submit_status INTO l_enable_wf_flag, l_wf_success_status_code, l_wf_failure_status_code;
8168   CLOSE c_submit_status;
8169 
8170   IF (l_enable_wf_flag = 'Y' AND l_wf_success_status_code IS NOT NULL AND l_wf_failure_status_code IS NOT NULL) THEN
8171 
8172        PA_UTILS.ADD_MESSAGE('PA', 'PA_CI_APPROVAL_WORKFLOW');
8173        RAISE FND_API.G_EXC_ERROR;
8174 
8175   END IF;
8176 
8177   IF l_debug_mode = 'Y' THEN
8178         pa_debug.write(l_module, 'After checking for submitted status', l_debug_level3);
8179   END IF;
8180 
8181 
8182   IF p_ci_status_code = G_PA_MISS_CHAR THEN
8183        l_ci_status_code := l_curr_status_code;
8184   ELSIF p_ci_status_code IS NOT NULL THEN
8185           l_ci_status_code := p_ci_status_code;
8186 
8187           l_sel_clause  := ' SELECT ps.project_status_code ';
8188           l_from_clause := ' FROM pa_obj_status_lists osl, pa_status_list_items sli, pa_project_statuses ps ';
8189           l_where       := ' WHERE osl.status_type = '||'''CONTROL_ITEM'''||
8190                              ' AND osl.object_type = '||'''PA_CI_TYPES'''||
8191                              ' AND osl.object_id = '||l_ci_type_id||
8192                              ' AND osl.status_list_id = sli.status_list_id'||
8193                              ' AND sli.project_status_code = ps.project_status_code'||
8194                              ' AND ps.project_status_code <> '||''''||l_curr_status_code||''''||
8195                              ' AND ps.status_type = osl.status_type'||
8196                              ' AND trunc(sysdate) between nvl(ps.start_date_active, trunc(sysdate)) and nvl(ps.end_date_active, trunc(sysdate))'||
8197                              ' AND (('||''''||l_next_allow_status_flag||''''||' = '||'''N'''||' and 1=2)'||
8198                                   ' OR '||
8199                                   ' ('||''''||l_next_allow_status_flag||''''||' = '||'''S'''||
8200                                   ' and ps.project_status_code in (select project_status_code from pa_project_statuses where status_type = '||'''CONTROL_ITEM'''||
8201                                   ' and project_system_status_code in ( select next_allowable_status_code from pa_next_allow_statuses where status_code = '||
8202                                   ''''||l_curr_status_code||''''||')))'||
8203                                   ' OR '||
8204                                   ' ('||''''||l_next_allow_status_flag||''''||' = '||'''U'''||
8205                                   ' and ps.project_status_code in (select next_allowable_status_code from pa_next_allow_statuses where status_code = '||''''||
8206                                   l_curr_status_code||''''||'))'||
8207                                   ' OR '||
8208                                   ' ('||''''||l_next_allow_status_flag||''''||' = '||'''A'''||
8209                                   ' and ps.project_status_code in (select project_status_code from pa_project_statuses where status_type = '||'''CONTROL_ITEM'''||
8210                                   ' and project_system_status_code in (select next_allowable_status_code from pa_next_allow_statuses where status_code = '||
8211                                   ''''||l_curr_system_status||''''||'))))'||
8212                               ' AND ps.project_status_code not in (select wf_success_status_code from pa_project_statuses where status_type = '||
8213                               '''CONTROL_ITEM'''||' and wf_success_status_code is not null and wf_failure_status_code is not null)'||
8214                               ' AND ps.project_status_code not in (select wf_failure_status_code from pa_project_statuses where status_type = '||
8215                               '''CONTROL_ITEM'''||' and wf_success_status_code is not null and wf_failure_status_code is not null)'||
8216                               ' AND decode(ps.project_system_status_code, '||'''CI_CANCELED'''||
8217                               ', nvl(pa_control_items_utils.CheckCIActionAllowed('||'''CONTROL_ITEM'''||', '||''''||l_curr_status_code||''''||', '||
8218                               '''CONTROL_ITEM_ALLOW_CANCEL'''||', null),'||'''N'''||' ),'||'''Y'''||' ) = '||'''Y'''||
8219                               ' AND decode(ps.project_system_status_code,'||'''CI_WORKING'''||
8220                               ' ,nvl(pa_control_items_utils.CheckCIActionAllowed('||'''CONTROL_ITEM'''||', '||''''||l_curr_status_code||''''||', '||
8221                               '''CONTROL_ITEM_ALLOW_REWORK'''||' ,null),'||'''N'''||' ),'||'''Y'''||' ) = '||'''Y'''||
8222                               ' AND nvl(pa_control_items_utils.CheckCIActionAllowed('||'''CONTROL_ITEM'''||', '||''''||l_curr_status_code||''''||', '||
8223                               '''CONTROL_ITEM_ALLOW_UPDST'''||' ,null),'||'''N'''||' ) = '||'''Y'''||
8224                               ' AND decode(ps.project_system_status_code,'||'''CI_DRAFT'''||
8225                               ' ,decode('||''''||l_curr_system_status||''''||', '||'''CI_DRAFT'''||', '||
8226                               '''Y'''||' ,'||'''N'''||' ),'||'''Y'''||' ) = '||'''Y'''||
8227                               ' AND ps.project_status_code = '||''''||p_ci_status_code||'''';
8228 
8229           IF (l_ci_type_class_code = 'CHANGE_REQUEST') THEN
8230                 l_where1 := ' AND  ps.project_system_status_code <> '||'''CI_CLOSED''';
8231           END IF;
8232 
8233           l_stmnt := l_sel_clause || l_from_clause || l_where || l_where1;
8234 
8235           IF l_debug_mode = 'Y' THEN
8236                pa_debug.write(l_module, l_stmnt, l_debug_level3);
8237           END IF;
8238 
8239     l_cursor := dbms_sql.open_cursor;
8240 
8241     DBMS_SQL.PARSE(l_cursor, l_stmnt, DBMS_SQL.v7);
8242     DBMS_SQL.DEFINE_COLUMN(l_cursor, 1, l_ci_status_code_1, 30);
8243 
8244     l_rows := DBMS_SQL.EXECUTE(l_cursor);
8245 
8246     IF (l_rows < 0) THEN
8247                PA_UTILS.Add_Message( p_app_short_name => 'PA'
8248                                     ,p_msg_name       => 'PA_TO_STATUS_INVALID');
8249                x_return_status := FND_API.G_RET_STS_ERROR;
8250                l_to_status_flag := 'N';
8251     ELSE
8252        l_rows1 := DBMS_SQL.FETCH_ROWS(l_cursor);
8253 
8254        if l_rows1 > 0 THEN
8255             DBMS_SQL.COLUMN_VALUE(l_cursor, 1, l_ci_status_code_1);
8256             l_ci_status_code := l_ci_status_code_1;
8257        else
8258 	     PA_UTILS.Add_Message( p_app_short_name => 'PA'
8259                                   ,p_msg_name       => 'PA_TO_STATUS_INVALID');
8260              x_return_status := FND_API.G_RET_STS_ERROR;
8261              l_to_status_flag := 'N';
8262        end if;
8263 
8264     END IF;
8265     IF dbms_sql.is_open(l_cursor) THEN
8266          dbms_sql.close_cursor(l_cursor);
8267     END IF;
8268   ELSIF p_ci_status_code IS NULL THEN
8269           l_ci_status_code := p_ci_status_code;
8270           PA_UTILS.ADD_MESSAGE('PA', 'PA_CI_NULL_STATUS');
8271           x_return_status := FND_API.G_RET_STS_ERROR;
8272 	  l_to_status_flag := 'N';
8273   END IF;
8274 
8275   IF p_record_version_number = G_PA_MISS_NUM THEN
8276        NULL;
8277   ELSE
8278        l_record_version_number := p_record_version_number;
8279   END IF;
8280 
8281   IF p_summary = G_PA_MISS_CHAR THEN
8282        NULL;
8283   ELSIF p_summary IS NOT NULL THEN
8284           l_summary := p_summary;
8285   ELSIF p_summary IS NULL THEN
8286           PA_UTILS.ADD_MESSAGE('PA', 'PA_CI_NULL_SUMMARY');
8287           x_return_status := FND_API.G_RET_STS_ERROR;
8288   END IF;
8289 
8290   IF p_description = G_PA_MISS_CHAR THEN
8291        NULL;
8292   ELSIF p_description IS NOT NULL THEN
8293           l_description := p_description;
8294   ELSIF p_description IS NULL THEN
8295           l_description := p_description;
8296   END IF;
8297 
8298   /*Adding the comment after validating the Owner id*/
8299   IF p_owner_id = G_PA_MISS_NUM THEN
8300        l_owner_id := l_curr_owner_id;
8301   ELSIF p_owner_id IS NOT NULL THEN
8302           l_owner_id := p_owner_id;
8303           IF (l_owner_id = l_curr_owner_id) then
8304                  PA_UTILS.Add_Message( p_app_short_name => 'PA'
8305                                       ,p_msg_name       => 'PA_CI_CHANGE_OWNER_INVALID');
8306                  x_return_status := 'E';
8307 
8308 	  ELSIF (l_owner_id <> l_curr_owner_id) then
8309 		l_chgowner_allowed := pa_ci_security_pkg.check_change_owner_access(p_ci_id);
8310 		IF (l_chgowner_allowed <> 'T') then
8311 		         PA_UTILS.Add_Message( p_app_short_name => 'PA'
8312 				              ,p_msg_name       => 'PA_CI_OWNER_CHG_NOT_ALLOWED');
8313 			 x_return_status := 'E';
8314 	        else
8315 		         l_to_owner_allowed := pa_ci_security_pkg.is_to_owner_allowed(p_ci_id, l_owner_id);
8316 		         if (l_to_owner_allowed <> 'T') then
8317 				 PA_UTILS.Add_Message( p_app_short_name => 'PA'
8318 					              ,p_msg_name       => 'PA_CI_TO_OWNER_NOT_ALLOWED');
8319 		         x_return_status := 'E';
8320 		         else
8321 
8322 				/*get the Passed owner names*/
8323 				OPEN c_get_owner(l_owner_id,l_project_id);
8324 				FETCH c_get_owner into l_owner_name;
8325 				if (c_get_owner%notfound) then
8326 					PA_UTILS.Add_Message( p_app_short_name => 'PA'
8327 					      ,p_msg_name       => 'PA_CI_CHANGE_OWNER_INVALID');
8328 					x_return_status := 'E';
8329 				end if;
8330 				close 	c_get_owner;
8331 
8332 				/*Get the Current Owner name*/
8333 				OPEN c_get_owner(l_curr_owner_id,l_project_id);
8334 				FETCH c_get_owner into l_curr_owner_name;
8335 				if (c_get_owner%notfound) then
8336 					PA_UTILS.Add_Message( p_app_short_name => 'PA'
8337 					      ,p_msg_name       => 'PA_CI_CHANGE_OWNER_INVALID');
8338 					x_return_status := 'E';
8339 				end if;
8340 				close 	c_get_owner;
8341 
8342 					fnd_message.set_name('PA', 'PA_CI_LOG_OWNER_CHANGE');
8343 					fnd_message.set_token('PREV_OWNER', l_curr_owner_name);
8344 					fnd_message.set_token('NEXT_OWNER', l_owner_name);
8345 					fnd_message.set_token('COMMENT', p_owner_comment);
8346 					l_comment_text := fnd_message.get;
8347 
8348 					 pa_ci_comments_pkg.insert_row(
8349 						p_ci_comment_id             => l_ci_comment_id,
8350 						p_ci_id                     => p_ci_id,
8351 						p_type_code                 => 'CHANGE_OWNER',
8352 						p_comment_text              => l_comment_text,
8353 						p_last_updated_by           => fnd_global.user_id,
8354 						p_created_by                => fnd_global.user_id,
8355 						p_creation_date             => sysdate,
8356 						p_last_update_date          => sysdate,
8357 						p_last_update_login         => fnd_global.login_id,
8358 						p_ci_action_id              => null);
8359 			end if;
8360 	        end if;
8361 	end if;
8362   ELSIF p_owner_id IS NOT NULL THEN
8363           l_owner_id := p_owner_id;
8364           IF (l_owner_id = l_curr_owner_id) then
8365                  PA_UTILS.Add_Message( p_app_short_name => 'PA'
8366                                       ,p_msg_name       => 'PA_CI_CHANGE_OWNER_INVALID');
8367                  x_return_status := 'E';
8368           END IF;
8369           /* Getting validated in pa_control_items_pub.update_control_item API. */
8370   ELSIF p_owner_id IS NULL THEN
8371           PA_UTILS.Add_Message( p_app_short_name => 'PA'
8372                                ,p_msg_name       => 'PA_CI_OWNER_NULL');
8373           x_return_status := FND_API.G_RET_STS_ERROR;
8374   END IF;
8375 
8376   IF p_classification_code = G_PA_MISS_NUM THEN
8377        NULL;
8378   ELSIF p_classification_code IS NOT NULL THEN
8379           OPEN c_classification (l_ci_type_id, p_classification_code);
8380           FETCH c_classification INTO l_classification_code_id;
8381           IF c_classification%NOTFOUND then
8382               -- close c_classification;
8383                PA_UTILS.Add_Message( p_app_short_name => 'PA'
8384                                     ,p_msg_name       => 'PA_CI_CLASSIFICATION_INV');
8385                x_return_status := FND_API.G_RET_STS_ERROR;
8386           END IF;
8387           close c_classification;
8388   ELSIF p_classification_code IS NULL THEN
8389           PA_UTILS.Add_Message( p_app_short_name => 'PA'
8390                                ,p_msg_name       => 'PA_CI_CLASSIFICATION_NULL');
8391           x_return_status := FND_API.G_RET_STS_ERROR;
8392   END IF;
8393 
8394   IF p_reason_code = G_PA_MISS_NUM THEN
8395        NULL;
8396   ELSIF p_reason_code IS NOT NULL THEN
8397           OPEN c_reason (l_ci_type_id, p_reason_code);
8398           FETCH c_reason INTO l_reason_code_id;
8399           IF c_reason%NOTFOUND then
8400              --  close c_reason;
8401                PA_UTILS.Add_Message( p_app_short_name => 'PA'
8402                                     ,p_msg_name       => 'PA_CI_REASON_INV');
8403                x_return_status := FND_API.G_RET_STS_ERROR;
8404           END IF;
8405           close c_reason;
8406   ELSIF p_reason_code IS NULL THEN
8407           PA_UTILS.Add_Message( p_app_short_name => 'PA'
8408                                ,p_msg_name       => 'PA_CI_REASON_NULL');
8409           x_return_status := FND_API.G_RET_STS_ERROR;
8410   END IF;
8411 
8412   IF p_object_id = G_PA_MISS_NUM THEN
8413        NULL;
8414   ELSIF p_object_id IS NOT NULL THEN
8415        /* As of now we're only handling PA_TASKS objects */
8416        BEGIN
8417                SELECT proj_element_id
8418                  INTO l_object_id
8419                  FROM PA_FIN_LATEST_PUB_TASKS_V
8420                 WHERE project_id     = l_project_id
8421                   AND proj_element_id = p_object_id;
8422 
8423         EXCEPTION WHEN TOO_MANY_ROWS THEN
8424            PA_UTILS.Add_Message( p_app_short_name => 'PA'
8425                                 ,p_msg_name       => 'PA_OBJECT_NAME_MULTIPLE');
8426            x_return_status := FND_API.G_RET_STS_ERROR;
8427 
8428         WHEN OTHERS THEN
8429            PA_UTILS.Add_Message( p_app_short_name => 'PA'
8430                                 ,p_msg_name       => 'PA_OBJECT_NAME_INV');
8431            x_return_status := FND_API.G_RET_STS_ERROR;
8432         END;
8433   ELSIF p_object_id IS NULL THEN
8434           l_object_id := p_object_id;
8435   END IF;
8436 
8437   IF p_object_type = G_PA_MISS_CHAR THEN
8438        NULL;
8439   ELSIF p_object_type IS NOT NULL THEN
8440          IF p_object_type = 'PA_TASKS' THEN
8441               l_object_type := p_object_type;
8442          ELSE
8443            PA_UTILS.Add_Message( p_app_short_name => 'PA'
8444                                 ,p_msg_name       => 'PA_OBJECT_TYPE_INV');
8445            x_return_status := FND_API.G_RET_STS_ERROR;
8446          END IF;
8447   ELSIF p_object_type IS NULL THEN
8448        l_object_type := p_object_type;
8449   END IF;
8450 
8451   IF p_date_required = G_PA_MISS_DATE THEN
8452        NULL;
8453   ELSIF p_date_required IS NOT NULL THEN
8454           l_date_required := p_date_required;
8455   ELSIF p_date_required IS NULL THEN
8456           l_date_required := p_date_required;
8457   END IF;
8458 
8459   IF p_priority_code = G_PA_MISS_CHAR THEN
8460        NULL;
8461   ELSIF p_priority_code IS NOT NULL THEN
8462           OPEN c_lkup(l_priority_type, p_priority_code);
8463           FETCH c_lkup INTO l_priority_code;
8464           IF c_lkup%NOTFOUND then
8465             --  close c_lkup;
8466                PA_UTILS.Add_Message( p_app_short_name => 'PA'
8467                                     ,p_msg_name       => 'PA_CI_PRIORITY_INV');
8468                x_return_status := FND_API.G_RET_STS_ERROR;
8469           END IF;
8470           close c_lkup;
8471   ELSIF p_priority_code IS NULL THEN
8472           l_priority_code := p_priority_code;
8473   END IF;
8474 
8475   IF p_effort_level_code = G_PA_MISS_CHAR THEN
8476        l_effort_level_code := null;
8477   ELSIF p_effort_level_code IS NOT NULL THEN
8478           OPEN c_lkup(l_effort_type, p_effort_level_code);
8479           FETCH c_lkup INTO l_effort_level_code;
8480           IF c_lkup%NOTFOUND then
8481            --    close c_lkup;
8482                PA_UTILS.Add_Message( p_app_short_name => 'PA'
8483                                     ,p_msg_name       => 'PA_CI_EFFORT_INV');
8484                x_return_status := FND_API.G_RET_STS_ERROR;
8485           END IF;
8486           close c_lkup;
8487   ELSIF p_effort_level_code IS NULL THEN
8488           l_effort_level_code := p_effort_level_code;
8489   END IF;
8490 
8491   IF p_price = G_PA_MISS_NUM THEN
8492        l_price := null;
8493   ELSIF p_price IS NOT NULL THEN
8494           l_price := p_price;
8495   ELSIF p_price IS NULL THEN
8496           l_price := p_price;
8497   END IF;
8498 
8499   IF p_price_currency_code = G_PA_MISS_CHAR THEN
8500        NULL;
8501   ELSIF p_price_currency_code IS NOT NULL THEN
8502           l_price_currency_code := p_price_currency_code;
8503           /* Getting validated in pa_control_items_pvt.update_control_item API. */
8504   ELSIF p_price_currency_code IS NULL THEN
8505           l_price_currency_code := p_price_currency_code;
8506   END IF;
8507 
8508   IF p_source_type_code = G_PA_MISS_CHAR THEN
8509        NULL;
8510   ELSIF p_source_type_code IS NOT NULL THEN
8511           OPEN c_lkup(l_source_type, p_source_type_code);
8512           FETCH c_lkup INTO l_source_type_code;
8513           IF c_lkup%NOTFOUND then
8514               -- close c_lkup;
8515                PA_UTILS.Add_Message( p_app_short_name => 'PA'
8516                                     ,p_msg_name       => 'PA_CI_SOURCE_TYPE_INV');
8517                x_return_status := FND_API.G_RET_STS_ERROR;
8518           END IF;
8519           close c_lkup;
8520   ELSIF p_source_type_code IS NULL THEN
8521           l_source_type_code := p_source_type_code;
8522   END IF;
8523 
8524   IF p_source_comment = G_PA_MISS_CHAR THEN
8525        NULL;
8526   ELSE
8527           l_source_comment := p_source_comment;
8528   END IF;
8529 
8530   IF p_source_number = G_PA_MISS_CHAR THEN
8531        NULL;
8532   ELSE
8533           l_source_number := p_source_number;
8534   END IF;
8535 
8536   IF p_source_date_received = G_PA_MISS_DATE THEN
8537        NULL;
8538   ELSE
8539           l_source_date_received := p_source_date_received;
8540   END IF;
8541 
8542   IF p_source_organization = G_PA_MISS_CHAR THEN
8543        NULL;
8544   ELSE
8545           l_source_organization := p_source_organization;
8546   END IF;
8547 
8548   IF p_source_person = G_PA_MISS_CHAR THEN
8549        NULL;
8550   ELSE
8551           l_source_person := p_source_person;
8552   END IF;
8553 
8554   IF p_progress_as_of_date = G_PA_MISS_DATE THEN
8555        NULL;
8556   ELSIF p_progress_as_of_date IS NOT NULL THEN
8557           l_progress_as_of_date := p_progress_as_of_date;
8558   ELSIF p_progress_as_of_date IS NULL THEN
8559           PA_UTILS.Add_Message( p_app_short_name => 'PA'
8560                                ,p_msg_name       => 'PA_AS_OF_DATE_NULL');
8561           x_return_status := FND_API.G_RET_STS_ERROR;
8562   END IF;
8563 
8564   OPEN c_auto_num;
8565   FETCH c_auto_num INTO l_auto_numbers;
8566   close c_auto_num;
8567 
8568   IF l_auto_numbers is NOT NULL and l_auto_numbers <> 'Y' then
8569 
8570        IF (p_ci_number = G_PA_MISS_CHAR OR p_ci_number IS NULL) THEN
8571 
8572               IF l_ci_status_code IS NOT NULL THEN
8573                     l_new_system_status :=  PA_CONTROL_ITEMS_UTILS.getSystemStatus(l_ci_status_code);
8574               END IF;
8575 
8576               IF p_ci_number = G_PA_MISS_CHAR THEN
8577                    IF l_ci_number IS NULL THEN
8578                         IF (l_curr_system_status = 'CI_DRAFT' AND (l_new_system_status IS NOT NULL AND l_new_system_status <> 'CI_DRAFT')) THEN
8579                               PA_UTILS.Add_Message( p_app_short_name => 'PA'
8580                                                    ,p_msg_name       => 'PA_CI_NO_CI_NUMBER');
8581                               x_return_status := FND_API.G_RET_STS_ERROR;
8582                         ELSIF l_curr_system_status <> 'CI_DRAFT' THEN
8583                                 PA_UTILS.Add_Message( p_app_short_name => 'PA'
8584                                                      ,p_msg_name       => 'PA_CI_NO_CI_NUMBER');
8585                                 x_return_status := FND_API.G_RET_STS_ERROR;
8586                         END IF;
8587                    END IF;
8588               ELSIF p_ci_number IS NULL THEN
8589                  IF (l_curr_system_status = 'CI_DRAFT' AND (l_new_system_status IS NOT NULL AND l_new_system_status <> 'CI_DRAFT')) THEN
8590                        PA_UTILS.Add_Message( p_app_short_name => 'PA'
8591                                             ,p_msg_name       => 'PA_CI_NO_CI_NUMBER');
8592                        x_return_status := FND_API.G_RET_STS_ERROR;
8593                  ELSIF l_curr_system_status <> 'CI_DRAFT' THEN
8594                        PA_UTILS.Add_Message( p_app_short_name => 'PA'
8595                                             ,p_msg_name       => 'PA_CI_NO_CI_NUMBER');
8596                        x_return_status := FND_API.G_RET_STS_ERROR;
8597                  END IF;
8598               END IF;
8599 
8600        ELSIF p_ci_number IS NOT NULL THEN
8601                l_ci_number := p_ci_number;
8602 
8603                OPEN c_ci_number(l_project_id, l_ci_type_id);
8604                FETCH c_ci_number into l_ROWID;
8605                IF (c_ci_number%NOTFOUND) then
8606                     CLOSE c_ci_number;
8607                ELSE
8608                     CLOSE c_ci_number;
8609                     PA_UTILS.Add_Message( p_app_short_name => 'PA'
8610                                          ,p_msg_name       => 'PA_CI_DUPLICATE_CI_NUMBER');
8611                     x_return_status := FND_API.G_RET_STS_ERROR;
8612                END IF;
8613        END IF;
8614 
8615   END IF;
8616 
8617 
8618   IF p_progress_status_code = G_PA_MISS_CHAR THEN
8619        NULL;
8620   ELSIF p_progress_status_code IS NOT NULL THEN
8621           OPEN c_statuses(l_progress_type, p_progress_status_code);
8622           FETCH c_statuses INTO l_progress_status_code;
8623           IF c_statuses%NOTFOUND then
8624                close c_statuses;
8625                PA_UTILS.Add_Message( p_app_short_name => 'PA'
8626                                     ,p_msg_name       => 'PA_PROGRESS_STATUS_INV');
8627                x_return_status := FND_API.G_RET_STS_ERROR;
8628           END IF;
8629           close c_statuses;
8630   ELSIF p_progress_status_code IS NULL THEN
8631           PA_UTILS.Add_Message( p_app_short_name => 'PA'
8632                                ,p_msg_name       => 'PA_PROGRESS_STATUS_NULL');
8633           x_return_status := FND_API.G_RET_STS_ERROR;
8634   END IF;
8635 
8636   IF p_progress_overview = G_PA_MISS_CHAR THEN
8637        NULL;
8638   ELSE
8639           l_progress_overview := p_progress_overview;
8640   END IF;
8641 
8642   IF p_resolution_code = G_PA_MISS_CHAR THEN
8643        NULL;
8644   ELSIF p_resolution_code IS NOT NULL THEN
8645           OPEN c_resolution (l_ci_type_id, p_resolution_code);
8646           FETCH c_resolution INTO l_resolution_code_id;
8647           IF c_resolution%NOTFOUND then
8648                close c_resolution;
8649                PA_UTILS.Add_Message( p_app_short_name => 'PA'
8650                                     ,p_msg_name       => 'PA_CI_RESOLUTION_INV');
8651                x_return_status := FND_API.G_RET_STS_ERROR;
8652           END IF;
8653           close c_resolution;
8654   ELSIF p_resolution_code IS NULL THEN
8655           l_resolution_code_id := p_resolution_code;
8656   END IF;
8657 
8658   IF p_resolution_comment = G_PA_MISS_CHAR THEN
8659        NULL;
8660   ELSE
8661        l_resolution_comment := p_resolution_comment;
8662   END IF;
8663 
8664   IF p_attribute_category = G_PA_MISS_CHAR THEN
8665        NULL;
8666   ELSE
8667        l_attribute_category := p_attribute_category;
8668   END IF;
8669 
8670   IF p_attribute1 = G_PA_MISS_CHAR THEN
8671        NULL;
8672   ELSE
8673        l_attribute1 := p_attribute1;
8674   END IF;
8675 
8676   IF p_attribute2 = G_PA_MISS_CHAR THEN
8677        NULL;
8678   ELSE
8679        l_attribute2 := p_attribute2;
8680   END IF;
8681 
8682   IF p_attribute3 = G_PA_MISS_CHAR THEN
8683        NULL;
8684   ELSE
8685        l_attribute3 := p_attribute3;
8686   END IF;
8687 
8688   IF p_attribute4 = G_PA_MISS_CHAR THEN
8689        NULL;
8690   ELSE
8691        l_attribute4 := p_attribute4;
8692   END IF;
8693 
8694   IF p_attribute5 = G_PA_MISS_CHAR THEN
8695        NULL;
8696   ELSE
8697        l_attribute5 := p_attribute5;
8698   END IF;
8699 
8700   IF p_attribute6 = G_PA_MISS_CHAR THEN
8701        NULL;
8702   ELSE
8703        l_attribute6 := p_attribute6;
8704   END IF;
8705 
8706   IF p_attribute7 = G_PA_MISS_CHAR THEN
8707        NULL;
8708   ELSE
8709        l_attribute7 := p_attribute7;
8710   END IF;
8711 
8712   IF p_attribute8 = G_PA_MISS_CHAR THEN
8713        NULL;
8714   ELSE
8715        l_attribute8 := p_attribute8;
8716   END IF;
8717 
8718   IF p_attribute9 = G_PA_MISS_CHAR THEN
8719        NULL;
8720   ELSE
8721        l_attribute9 := p_attribute9;
8722   END IF;
8723 
8724   IF p_attribute10 = G_PA_MISS_CHAR THEN
8725        NULL;
8726   ELSE
8727        l_attribute10 := p_attribute10;
8728   END IF;
8729 
8730   IF p_attribute11 = G_PA_MISS_CHAR THEN
8731        NULL;
8732   ELSE
8733        l_attribute11 := p_attribute11;
8734   END IF;
8735 
8736   IF p_attribute12 = G_PA_MISS_CHAR THEN
8737        NULL;
8738   ELSE
8739        l_attribute12 := p_attribute12;
8740   END IF;
8741 
8742   IF p_attribute13 = G_PA_MISS_CHAR THEN
8743        NULL;
8744   ELSE
8745        l_attribute13 := p_attribute13;
8746   END IF;
8747 
8748   IF p_attribute14 = G_PA_MISS_CHAR THEN
8749        NULL;
8750   ELSE
8751        l_attribute14 := p_attribute14;
8752   END IF;
8753 
8754   IF p_attribute15 = G_PA_MISS_CHAR THEN
8755        NULL;
8756   ELSE
8757        l_attribute15 := p_attribute15;
8758   END IF;
8759 
8760 
8761   IF (l_curr_status_code is NOT NULL AND
8762       l_ci_status_code   is NOT NULL AND
8763       l_curr_status_code <> l_ci_status_code AND
8764       l_to_status_flag = 'Y') THEN
8765 
8766          IF l_debug_mode = 'Y' THEN
8767               pa_debug.write(l_module, 'before call to ChangeCIStatusValidate', l_debug_level3);
8768          END IF;
8769 
8770          PA_CONTROL_ITEMS_UTILS.ChangeCIStatusValidate (
8771                                   p_init_msg_list      => p_init_msg_list
8772                                  ,p_commit             => p_commit
8773                                  ,p_validate_only      => l_validate_only
8774                                  ,p_max_msg_count      => l_max_msg_count
8775                                  ,p_ci_id              => p_ci_id
8776                                  ,p_status             => p_ci_status_code
8777                                  ,p_enforce_security   => l_enforce_security
8778                                  ,p_resolution_check   => l_resolution_check
8779                                  ,x_resolution_req     => l_resolution_req
8780                                  ,x_resolution_req_cls => l_resolution_req_cls
8781                                  ,x_start_wf           => l_start_wf
8782                                  ,x_new_status         => l_ci_status_code
8783                                  ,x_num_of_actions     => l_num_of_actions
8784                                  ,x_return_status      => x_return_status
8785                                  ,x_msg_count          => x_msg_count
8786                                  ,x_msg_data           => x_msg_data);
8787 
8788        /* l_ci_status_code gets the new status from ChangeCIStatusValidate.
8789           In case of CR/CO, if Auto Approve on Submission is enabled and while changing the status to submitted,
8790           then the new status would be the success status code defined for the workflow */
8791 
8792         IF l_debug_mode = 'Y' THEN
8793              pa_debug.write(l_module, 'After call to ChangeCIStatusValidate : x_return_status = '||x_return_status, l_debug_level3);
8794              pa_debug.write(l_module, 'After call to ChangeCIStatusValidate : l_ci_status_code = '||l_ci_status_code, l_debug_level3);
8795         END IF;
8796 
8797         IF x_return_status = 'S' THEN
8798              l_status_change_flag := 'Y';
8799         END IF;
8800 
8801         IF l_debug_mode = 'Y' THEN
8802              pa_debug.write(l_module, 'After call to ChangeCIStatusValidate :l_status_change_flag = '||l_status_change_flag, l_debug_level3);
8803         END IF;
8804 
8805         IF (l_resolution_req IS NOT NULL AND  l_resolution_req = 'Y') THEN
8806               IF (PA_CONTROL_ITEMS_UTILS.checkhasresolution(p_ci_id) <> 'Y'  ) THEN
8807                   IF (l_resolution_code_id IS NULL) THEN
8808                       PA_UTILS.Add_Message( p_app_short_name => 'PA'
8809                                            ,p_msg_name       => 'PA_CI_RESOLUTION_OPEN');
8810                       x_return_status := FND_API.G_RET_STS_ERROR;
8811                   END IF;
8812               ELSE
8813                   IF (l_resolution_code_id IS NULL) THEN
8814                       PA_UTILS.Add_Message( p_app_short_name => 'PA'
8815                                            ,p_msg_name       => 'PA_CI_RESOLUTION_OPEN');
8816                       x_return_status := FND_API.G_RET_STS_ERROR;
8817                   END IF;
8818               END IF;
8819         END IF;
8820 
8821         IF (l_resolution_req_cls IS NOT NULL AND  l_resolution_req_cls = 'Y') THEN
8822               IF (PA_CONTROL_ITEMS_UTILS.checkhasresolution(p_ci_id) <> 'Y'  ) THEN
8823                   IF (l_resolution_code_id IS NULL) THEN
8824                       PA_UTILS.Add_Message( p_app_short_name => 'PA'
8825                                            ,p_msg_name       => 'PA_CI_CLOSE_INV_RES');
8826                       x_return_status := FND_API.G_RET_STS_ERROR;
8827                   END IF;
8828               ELSE
8829                   IF (l_resolution_code_id IS NULL) THEN
8830                       PA_UTILS.Add_Message( p_app_short_name => 'PA'
8831                                            ,p_msg_name       => 'PA_CI_CLOSE_INV_RES');
8832                       x_return_status := FND_API.G_RET_STS_ERROR;
8833                   END IF;
8834               END IF;
8835         END IF;
8836 
8837   END IF;
8838 
8839 
8840   IF (l_validate_only <> fnd_api.g_true AND x_return_status = 'S') THEN
8841 
8842           IF l_debug_mode = 'Y' THEN
8843                pa_debug.write(l_module, 'before call to PA_CONTROL_ITEMS_PUB.UPDATE_CONTROL_ITEM', l_debug_level3);
8844           END IF;
8845 
8846           PA_CONTROL_ITEMS_PUB.UPDATE_CONTROL_ITEM (
8847                                  p_api_version           =>  1.0
8848                                 ,p_init_msg_list         => fnd_api.g_false
8849                                 ,p_commit                => FND_API.g_false
8850                                 ,p_validate_only         => FND_API.g_false
8851                                 ,p_max_msg_count         => FND_API.g_miss_num
8852                                 ,p_ci_id                 => p_ci_id
8853                                 ,p_ci_type_id            => l_ci_type_id
8854                                 ,p_summary               => l_summary
8855                                 ,p_status_code           => l_ci_status_code
8856                                 ,p_owner_id              => l_owner_id
8857                                 ,p_owner_name            => null
8858                                 ,p_highlighted_flag      => null
8859                                 ,p_progress_status_code  => l_progress_status_code
8860                                 ,p_progress_as_of_date   => l_progress_as_of_date
8861                                 ,p_classification_code   => l_classification_code_id
8862                                 ,p_reason_code           => l_reason_code_id
8863                                 ,p_record_version_number => l_record_version_number
8864                                 ,p_project_id            => l_project_id
8865                                 ,p_object_type           => l_object_type
8866                                 ,p_object_id             => l_object_id
8867                                 ,p_object_name           => null
8868                                 ,p_ci_number             => l_ci_number
8869                                 ,p_date_required         => l_date_required
8870                                 ,p_date_closed           => l_date_closed
8871                                 ,p_closed_by_id          => l_closed_by_id
8872                                 ,p_description           => l_description
8873                                 ,p_status_overview       => l_progress_overview
8874                                 ,p_resolution            => l_resolution_comment
8875                                 ,p_resolution_code       => l_resolution_code_id
8876                                 ,p_priority_code         => l_priority_code
8877                                 ,p_effort_level_code     => l_effort_level_code
8878                                 ,p_open_action_num       => null
8879                                 ,p_price                 => l_price
8880                                 ,p_price_currency_code   => l_price_currency_code
8881                                 ,p_source_type_code      => l_source_type_code
8882                                 ,p_source_comment        => l_source_comment
8883                                 ,p_source_number         => l_source_number
8884                                 ,p_source_date_received  => l_source_date_received
8885                                 ,p_source_organization   => l_source_organization
8886                                 ,p_source_person         => l_source_person
8887                                 ,p_attribute_category    => l_attribute_category
8888                                 ,p_attribute1            => l_attribute1
8889                                 ,p_attribute2            => l_attribute2
8890                                 ,p_attribute3            => l_attribute3
8891                                 ,p_attribute4            => l_attribute4
8892                                 ,p_attribute5            => l_attribute5
8893                                 ,p_attribute6            => l_attribute6
8894                                 ,p_attribute7            => l_attribute7
8895                                 ,p_attribute8            => l_attribute8
8896                                 ,p_attribute9            => l_attribute9
8897                                 ,p_attribute10           => l_attribute10
8898                                 ,p_attribute11           => l_attribute11
8899                                 ,p_attribute12           => l_attribute12
8900                                 ,p_attribute13           => l_attribute13
8901                                 ,p_attribute14           => l_attribute14
8902                                 ,p_attribute15           => l_attribute15
8903                                 ,x_return_status         => x_return_status
8904                                 ,x_msg_count             => x_msg_count
8905                                 ,x_msg_data              => x_msg_data
8906                         );
8907 
8908           IF l_debug_mode = 'Y' THEN
8909                pa_debug.write(l_module, 'after call to PA_CONTROL_ITEMS_PUB.UPDATE_CONTROL_ITEM : x_return_status = '||x_return_status, l_debug_level3);
8910           END IF;
8911 
8912   END IF;
8913 
8914   IF (l_status_change_flag = 'Y' AND l_validate_only <> fnd_api.g_true AND x_return_status = 'S') THEN
8915 
8916            /* call the insert table handlers of pa_obj_status_changes and pa_ci_comments here */
8917 
8918            IF l_debug_mode = 'Y' THEN
8919                 pa_debug.write(l_module, 'before call to PA_CONTROL_ITEMS_UTILS.ADD_STATUS_CHANGE_COMMENT', l_debug_level3);
8920            END IF;
8921 
8922            PA_CONTROL_ITEMS_UTILS.ADD_STATUS_CHANGE_COMMENT( p_object_type        => 'PA_CI_TYPES'
8923                                                             ,p_object_id          => p_ci_id
8924                                                             ,p_type_code          => 'CHANGE_STATUS'
8925                                                             ,p_status_type        => 'CONTROL_ITEM'
8926                                                             ,p_new_project_status => l_ci_status_code
8927                                                             ,p_old_project_status => l_curr_status_code
8928                                                             ,p_comment            => p_status_comment
8929                                                             ,x_return_status      => x_return_status
8930                                                             ,x_msg_count          => x_msg_count
8931                                                             ,x_msg_data           => x_msg_data );
8932 
8933 
8934            IF l_debug_mode = 'Y' THEN
8935                 pa_debug.write(l_module, 'After call to PA_CONTROL_ITEMS_UTILS.ADD_STATUS_CHANGE_COMMENT', l_debug_level3);
8936            END IF;
8937 
8938            PA_CONTROL_ITEMS_UTILS.PostChangeCIStatus (
8939                                                           p_init_msg_list
8940                                                          ,p_commit
8941                                                          ,l_validate_only
8942                                                          ,l_max_msg_count
8943                                                          ,p_ci_id
8944                                                          ,l_curr_status_code
8945                                                          ,l_ci_status_code
8946                                                          ,l_start_wf
8947                                                          ,l_enforce_security
8948                                                          ,l_num_of_actions
8949                                                          ,x_return_status
8950                                                          ,x_msg_count
8951                                                          ,x_msg_data    );
8952 
8953 
8954            IF l_debug_mode = 'Y' THEN
8955                 pa_debug.write(l_module, 'After call to PA_CONTROL_ITEMS_UTILS.PostChangeCIStatus', l_debug_level3);
8956            END IF;
8957 
8958   END IF;
8959 
8960 
8961   IF (p_commit = FND_API.G_TRUE AND x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
8962 
8963         IF l_debug_mode = 'Y' THEN
8964              pa_debug.write(l_module, 'Before Commit', l_debug_level3);
8965         END IF;
8966 
8967         COMMIT;
8968 
8969   END IF;
8970 
8971    --Reset the stack
8972          if l_debug_mode = 'Y' then
8973                   Pa_Debug.reset_curr_function;
8974          end if;
8975 
8976 EXCEPTION
8977 
8978    WHEN FND_API.G_EXC_ERROR THEN
8979         IF l_debug_mode = 'Y' THEN
8980              pa_debug.write(l_module, 'in FND_API.G_EXC_ERROR exception', l_debug_level3);
8981         END IF;
8982         x_return_status := FND_API.G_RET_STS_ERROR;
8983         l_msg_count := FND_MSG_PUB.count_msg;
8984 
8985         IF p_commit = FND_API.G_TRUE THEN
8986                 ROLLBACK TO UPDATE_CR_SVPT;
8987         END IF;
8988 
8989         IF l_msg_count = 1 AND x_msg_data IS NULL THEN
8990                 PA_INTERFACE_UTILS_PUB.get_messages
8991                 ( p_encoded        => FND_API.G_FALSE
8992                 , p_msg_index      => 1
8993                 , p_msg_count      => l_msg_count
8994                 , p_msg_data       => l_msg_data
8995                 , p_data           => l_data
8996                 , p_msg_index_out  => l_msg_index_out);
8997 
8998                 x_msg_data := l_data;
8999                 x_msg_count := l_msg_count;
9000         ELSE
9001                 x_msg_count := l_msg_count;
9002         END IF;
9003 
9004         IF l_debug_mode = 'Y' THEN
9005                 Pa_Debug.reset_curr_function;
9006         END IF;
9007 
9008 
9009    WHEN OTHERS THEN
9010         IF l_debug_mode = 'Y' THEN
9011              pa_debug.write(l_module, 'in OTHERS exception', l_debug_level3);
9012         END IF;
9013         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9014         x_msg_data      := substr(SQLERRM,1,240);
9015 
9016         IF p_commit = FND_API.G_TRUE THEN
9017                 ROLLBACK TO UPDATE_CR_SVPT;
9018         END IF;
9019 
9020         FND_MSG_PUB.add_exc_msg
9021         ( p_pkg_name            => 'PA_CONTROL_API_PUB'
9022         , p_procedure_name      => 'UPDATE_CHANGE_REQUEST'
9023         , p_error_text          => x_msg_data);
9024 
9025         x_msg_count     := FND_MSG_PUB.count_msg;
9026 
9027         IF l_debug_mode = 'Y' THEN
9028                 PA_DEBUG.reset_curr_function;
9029         END IF;
9030 
9031 --        RAISE;
9032 
9033 END UPDATE_CHANGE_REQUEST;
9034 
9035 
9036 PROCEDURE UPDATE_CHANGE_ORDER (
9037                         p_commit                IN      VARCHAR2 := FND_API.G_FALSE,
9038                         p_init_msg_list         IN      VARCHAR2 := FND_API.G_FALSE,
9039                         p_api_version_number    IN      NUMBER,
9040                         x_return_status         OUT NOCOPY    VARCHAR2,
9041                         x_msg_count             OUT NOCOPY    NUMBER,
9042                         x_msg_data              OUT NOCOPY    VARCHAR2,
9043                         p_ci_id                 IN      NUMBER,
9044                         P_RECORD_VERSION_NUMBER IN      NUMBER   := G_PA_MISS_NUM,
9045                         P_SUMMARY               IN      VARCHAR2 := G_PA_MISS_CHAR,
9046                         P_DESCRIPTION           IN      VARCHAR2 := G_PA_MISS_CHAR,
9047                         P_OWNER_ID              IN      NUMBER   := G_PA_MISS_NUM,
9048                         P_OWNER_COMMENT         IN      VARCHAR2 := G_PA_MISS_CHAR,
9049                         P_CLASSIFICATION_CODE   IN      NUMBER   := G_PA_MISS_NUM,
9050                         P_REASON_CODE           IN      NUMBER   := G_PA_MISS_NUM,
9051                         P_OBJECT_ID             IN      NUMBER   := G_PA_MISS_NUM,
9052                         P_OBJECT_TYPE           IN      VARCHAR2 := G_PA_MISS_CHAR,
9053                         P_CI_NUMBER             IN      VARCHAR2 := G_PA_MISS_CHAR,
9054                         P_DATE_REQUIRED         IN      DATE     := G_PA_MISS_DATE,
9055                         P_PRIORITY_CODE         IN      VARCHAR2 := G_PA_MISS_CHAR,
9056                         P_EFFORT_LEVEL_CODE     IN      VARCHAR2 := G_PA_MISS_CHAR,
9057                         P_PRICE                 IN      NUMBER   := G_PA_MISS_NUM,
9058                         P_PRICE_CURRENCY_CODE   IN      VARCHAR2 := G_PA_MISS_CHAR,
9059                         P_SOURCE_TYPE_CODE      IN      VARCHAR2 := G_PA_MISS_CHAR,
9060                         P_SOURCE_NUMBER         IN      VARCHAR2 := G_PA_MISS_CHAR,
9061                         P_SOURCE_COMMENT        IN      VARCHAR2 := G_PA_MISS_CHAR,
9062                         P_SOURCE_DATE_RECEIVED  IN      DATE     := G_PA_MISS_DATE,
9063                         P_SOURCE_ORGANIZATION   IN      VARCHAR2 := G_PA_MISS_CHAR,
9064                         P_SOURCE_PERSON         IN      VARCHAR2 := G_PA_MISS_CHAR,
9065                         P_CI_STATUS_CODE        IN      VARCHAR2 := G_PA_MISS_CHAR,
9066                         P_STATUS_COMMENT        IN      VARCHAR2 := G_PA_MISS_CHAR,
9067                         P_PROGRESS_AS_OF_DATE   IN      DATE     := G_PA_MISS_DATE,
9068                         P_PROGRESS_STATUS_CODE  IN      VARCHAR2 := G_PA_MISS_CHAR,
9069                         P_PROGRESS_OVERVIEW     IN      VARCHAR2 := G_PA_MISS_CHAR,
9070                         P_RESOLUTION_CODE       IN      VARCHAR2 := G_PA_MISS_CHAR,
9071                         P_RESOLUTION_COMMENT    IN      VARCHAR2 := G_PA_MISS_CHAR,
9072                         P_ATTRIBUTE_CATEGORY    IN      VARCHAR2 := G_PA_MISS_CHAR,
9073                         P_ATTRIBUTE1            IN      VARCHAR2 := G_PA_MISS_CHAR,
9074                         P_ATTRIBUTE2            IN      VARCHAR2 := G_PA_MISS_CHAR,
9075                         P_ATTRIBUTE3            IN      VARCHAR2 := G_PA_MISS_CHAR,
9076                         P_ATTRIBUTE4            IN      VARCHAR2 := G_PA_MISS_CHAR,
9077                         P_ATTRIBUTE5            IN      VARCHAR2 := G_PA_MISS_CHAR,
9078                         P_ATTRIBUTE6            IN      VARCHAR2 := G_PA_MISS_CHAR,
9079                         P_ATTRIBUTE7            IN      VARCHAR2 := G_PA_MISS_CHAR,
9080                         P_ATTRIBUTE8            IN      VARCHAR2 := G_PA_MISS_CHAR,
9081                         P_ATTRIBUTE9            IN      VARCHAR2 := G_PA_MISS_CHAR,
9082                         P_ATTRIBUTE10           IN      VARCHAR2 := G_PA_MISS_CHAR,
9083                         P_ATTRIBUTE11           IN      VARCHAR2 := G_PA_MISS_CHAR,
9084                         P_ATTRIBUTE12           IN      VARCHAR2 := G_PA_MISS_CHAR,
9085                         P_ATTRIBUTE13           IN      VARCHAR2 := G_PA_MISS_CHAR,
9086                         P_ATTRIBUTE14           IN      VARCHAR2 := G_PA_MISS_CHAR,
9087                         P_ATTRIBUTE15           IN      VARCHAR2 := G_PA_MISS_CHAR
9088                         )
9089 IS
9090 
9091 
9092 
9093 
9094 
9095  l_data                       VARCHAR2(2000);
9096  l_msg_data                   VARCHAR2(2000);
9097  l_msg_index_out              NUMBER;
9098  l_msg_count                  NUMBER := 0;
9099 
9100  l_check_update_access        VARCHAR2(1) := 'F';
9101  l_chk_status_ctrl            VARCHAR2(1) := 'N';
9102  l_module                     VARCHAR2(100) := 'PA_CONTROL_API_PUB.UPDATE_CHANGE_ORDER';
9103 
9104 
9105  l_curr_status_code                   pa_control_items.status_code%TYPE;
9106  l_ci_status_code                     pa_control_items.status_code%TYPE;
9107  l_record_version_number              pa_control_items.record_version_number%TYPE;
9108  l_summary                            pa_control_items.summary%TYPE;
9109  l_description                        pa_control_items.description%TYPE;
9110  l_curr_owner_id                      pa_control_items.owner_id%TYPE;
9111  l_owner_id                           pa_control_items.owner_id%TYPE;
9112  l_classification_code_id             pa_control_items.classification_code_id%TYPE;
9113  l_reason_code_id                     pa_control_items.reason_code_id%TYPE;
9114  l_object_id                          pa_control_items.object_id%TYPE;
9115  l_object_type                        pa_control_items.object_type%TYPE;
9116  l_ci_number                          pa_control_items.ci_number%TYPE;
9117  l_date_required                      pa_control_items.date_required%TYPE;
9118  l_priority_code                      pa_control_items.priority_code%TYPE;
9119  l_effort_level_code                  pa_control_items.effort_level_code%TYPE;
9120  l_price                              pa_control_items.price%TYPE;
9121  l_price_currency_code                pa_control_items.price_currency_code%TYPE;
9122  l_source_type_code                   pa_control_items.source_type_code%TYPE;
9123  l_source_comment                     pa_control_items.source_comment%TYPE;
9124  l_source_number                      pa_control_items.source_number%TYPE;
9125  l_source_date_received               pa_control_items.source_date_received%TYPE;
9126  l_source_organization                pa_control_items.source_organization%TYPE;
9127  l_source_person                      pa_control_items.source_person%TYPE;
9128  l_progress_as_of_date                pa_control_items.progress_as_of_date%TYPE;
9129  l_progress_status_code               pa_control_items.progress_status_code%TYPE;
9130  l_progress_overview                  pa_control_items.status_overview%TYPE;
9131  l_resolution_code_id                 pa_control_items.resolution_code_id%TYPE;
9132  l_resolution_comment                 pa_control_items.resolution%TYPE;
9133  l_date_closed                        pa_control_items.date_closed%TYPE;
9134  l_closed_by_id                       pa_control_items.closed_by_id%TYPE;
9135  l_project_id                         pa_control_items.project_id%TYPE;
9136  l_ci_type_id                         pa_control_items.ci_type_id%TYPE;
9137  l_attribute_category                 pa_control_items.attribute_category%TYPE;
9138  l_attribute1                         pa_control_items.attribute1%TYPE;
9139  l_attribute2                         pa_control_items.attribute2%TYPE;
9140  l_attribute3                         pa_control_items.attribute3%TYPE;
9141  l_attribute4                         pa_control_items.attribute4%TYPE;
9142  l_attribute5                         pa_control_items.attribute5%TYPE;
9143  l_attribute6                         pa_control_items.attribute6%TYPE;
9144  l_attribute7                         pa_control_items.attribute7%TYPE;
9145  l_attribute8                         pa_control_items.attribute8%TYPE;
9146  l_attribute9                         pa_control_items.attribute9%TYPE;
9147  l_attribute10                        pa_control_items.attribute10%TYPE;
9148  l_attribute11                        pa_control_items.attribute11%TYPE;
9149  l_attribute12                        pa_control_items.attribute12%TYPE;
9150  l_attribute13                        pa_control_items.attribute13%TYPE;
9151  l_attribute14                        pa_control_items.attribute14%TYPE;
9152  l_attribute15                        pa_control_items.attribute15%TYPE;
9153  l_class_code                         constant varchar2(20) := 'CHANGE_ORDER';
9154  CURSOR curr_row is
9155     SELECT *
9156       FROM pa_control_items
9157      WHERE ci_id = p_ci_id;
9158 
9159  cp    curr_row%rowtype;
9160 
9161  CURSOR c_submit_status (p_curr_status_code VARCHAR2) IS
9162     SELECT enable_wf_flag, wf_success_status_code, wf_failure_status_code
9163       FROM pa_project_statuses
9164      WHERE project_status_code = p_curr_status_code;
9165 
9166  CURSOR c_lkup (p_lookup_type VARCHAR2, p_lookup_code VARCHAR2) IS
9167     SELECT lookup_code
9168       FROM pa_lookups
9169      WHERE lookup_type = p_lookup_type
9170        AND trunc(sysdate) BETWEEN start_date_active AND nvl(end_date_active, trunc(sysdate))
9171        AND enabled_flag = 'Y'
9172        AND lookup_code = p_lookup_code;
9173 
9174  CURSOR c_statuses (p_status_type VARCHAR2, p_project_status_code VARCHAR2) IS
9175     SELECT project_status_code
9176       FROM pa_project_statuses
9177      WHERE status_type = p_status_type
9178        AND project_status_code = p_project_status_code
9179        AND trunc(sysdate) BETWEEN start_date_active AND nvl(end_date_active, trunc(sysdate));
9180 
9181  CURSOR c_classification (p_ci_type_id NUMBER, p_class_code_id NUMBER) IS
9182     SELECT cat.class_code_id
9183       FROM pa_class_codes cat,
9184            pa_ci_types_b typ
9185      WHERE trunc(sysdate) between cat.start_date_active and nvl(cat.end_date_active,trunc(sysdate))
9186        AND typ.ci_type_id = p_ci_type_id
9187        AND cat.class_category = typ.classification_category
9188        AND cat.class_code_id = p_class_code_id;
9189 
9190  CURSOR c_reason (p_ci_type_id NUMBER, p_reason_code_id NUMBER) IS
9191     SELECT cat.class_code_id
9192       FROM pa_class_codes cat,
9193            pa_ci_types_b typ
9194      WHERE trunc(sysdate) between cat.start_date_active and nvl(cat.end_date_active,trunc(sysdate))
9195        AND typ.ci_type_id = p_ci_type_id
9196        AND cat.class_category = typ.reason_category
9197        AND cat.class_code_id = p_reason_code_id;
9198 
9199  CURSOR c_resolution (p_ci_type_id NUMBER, p_resolution_code_id NUMBER) IS
9200     SELECT cat.class_code_id
9201       FROM pa_class_codes cat,
9202            pa_ci_types_b typ
9203      WHERE trunc(sysdate) between cat.start_date_active and nvl(cat.end_date_active,trunc(sysdate))
9204        AND typ.ci_type_id = p_ci_type_id
9205        AND cat.class_category = typ.resolution_category
9206        AND cat.class_code_id = p_resolution_code_id;
9207 
9208  CURSOR c_auto_num IS
9209     SELECT type.auto_number_flag
9210       FROM pa_ci_types_b type,
9211            pa_control_items ci
9212      WHERE ci.ci_id = p_ci_id
9213        AND ci.ci_type_id = type.ci_type_id;
9214 
9215  CURSOR c_ci_number (p_project_id NUMBER, p_ci_type_id NUMBER) IS
9216     SELECT ROWID
9217       FROM pa_control_items
9218      WHERE project_id = p_project_id
9219        AND ci_number = p_ci_number
9220        AND ci_id <> p_ci_id
9221        AND ci_type_id = p_ci_type_id;
9222 
9223  CURSOR c_info IS
9224     SELECT cit.ci_type_class_code,
9225            cit.approval_required_flag,
9226              s.next_allowable_status_flag
9227       FROM pa_control_items c,
9228            pa_ci_types_b cit,
9229            pa_project_statuses s
9230      WHERE c.ci_id = p_ci_id
9231        AND c.status_code = s.project_status_code
9232        AND c.ci_type_id =cit.ci_type_id
9233        AND s.status_type = 'CONTROL_ITEM';
9234 
9235 --added to get the owner name to include in the log message
9236  CURSOR c_get_owner(c_owner_id NUMBER,c_project_id NUMBER)  IS
9237      select distinct resource_source_name party_name
9238 	 from PA_PROJECT_PARTIES_V
9239 	 where party_type <> 'ORGANIZATION'
9240 	 and resource_party_id = c_owner_id
9241          and project_id = c_project_id;
9242 
9243  l_stmnt                             VARCHAR2(5000);
9244  l_sel_clause                        VARCHAR2(300);
9245  l_from_clause                       VARCHAR2(300);
9246  l_where                             VARCHAR2(4000);
9247  l_where1                            VARCHAR2(2000);
9248  l_cursor                            NUMBER;
9249  l_rows                              NUMBER;
9250  l_rows1                             NUMBER;
9251  l_ci_status_code_1                  pa_project_statuses.project_status_code%TYPE;
9252 
9253  l_ROWID                             ROWID;
9254 
9255  l_enable_wf_flag                     pa_project_statuses.enable_wf_flag%TYPE;
9256  l_wf_success_status_code             pa_project_statuses.wf_success_status_code%TYPE;
9257  l_wf_failure_status_code             pa_project_statuses.wf_failure_status_code%TYPE;
9258  l_status_change_flag                 VARCHAR2(1) := 'N';
9259  l_start_wf                           VARCHAR2(1) := 'Y';
9260  l_validate_only                      VARCHAR2(1) := FND_API.g_false;
9261  l_max_msg_count                      NUMBER := FND_API.G_MISS_NUM;
9262  l_enforce_security                   VARCHAR2(1) := 'Y';
9263  l_num_of_actions                     NUMBER;
9264  l_priority_type                      VARCHAR2(30) := 'PA_TASK_PRIORITY_CODE';
9265  l_effort_type                        VARCHAR2(30) := 'PA_CI_EFFORT_LEVELS';
9266  l_source_type                        VARCHAR2(30) := 'PA_CI_SOURCE_TYPES';
9267  l_progress_type                      VARCHAR2(30) := 'PROGRESS';
9268  l_auto_numbers                       VARCHAR2(1);
9269  l_curr_system_status                 pa_project_statuses.project_system_status_code%TYPE;
9270  l_new_system_status                  pa_project_statuses.project_system_status_code%TYPE;
9271  l_next_allow_status_flag             pa_project_statuses.next_allowable_status_flag%TYPE;
9272  l_ci_type_class_code                 pa_ci_types_b.ci_type_class_code%TYPE;
9273  l_approval_required_flag             pa_ci_types_b.approval_required_flag%TYPE;
9274  l_resolution_check                   VARCHAR2(10) := 'AMG';
9275  l_resolution_req                     VARCHAR2(10) := 'N';
9276  l_resolution_req_cls                 VARCHAR2(10) := 'N';
9277  l_to_status_flag                     VARCHAR2(10) := 'Y';
9278 
9279  l_ci_comment_id                      pa_ci_comments.ci_comment_id%TYPE;
9280  l_comment_text                       pa_ci_comments.comment_text%TYPE;
9281  l_owner_name                         per_all_people_f.full_name%TYPE;
9282  l_curr_owner_name                    per_all_people_f.full_name%TYPE;
9283  l_chgowner_allowed                   VARCHAR2(1);
9284  l_to_owner_allowed                   VARCHAR2(1);
9285 
9286 
9287 BEGIN
9288 
9289   x_return_status := FND_API.G_RET_STS_SUCCESS;
9290 
9291   l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.login_id, 275, null, null), 'N');
9292 
9293   IF l_debug_mode = 'Y' THEN
9294         PA_DEBUG.set_curr_function(p_function => 'UPDATE_CHANGE_ORDER', p_debug_mode => l_debug_mode);
9295   END IF;
9296 
9297   IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
9298         FND_MSG_PUB.initialize;
9299   END IF;
9300 
9301   IF p_commit = FND_API.G_TRUE THEN
9302         savepoint UPDATE_CO_SVPT;
9303   END IF;
9304 
9305   IF l_debug_mode = 'Y' THEN
9306         pa_debug.write(l_module, 'Start of Update Chaneg Order', l_debug_level3);
9307   END IF;
9308 
9309   OPEN curr_row;
9310   FETCH curr_row INTO cp;
9311   IF curr_row%NOTFOUND then
9312       close curr_row;
9313       PA_UTILS.Add_Message( p_app_short_name => 'PA'
9314                            ,p_msg_name       => 'PA_CI_INVALID_ITEM');   /* Change this message */
9315       RAISE  FND_API.G_EXC_ERROR;
9316   ELSE
9317 
9318       l_curr_status_code        := cp.status_code;
9319       l_record_version_number   := cp.record_version_number;
9320       l_summary                 := cp.summary;
9321       l_description             := cp.description;
9322       l_curr_owner_id           := cp.owner_id;
9323       l_classification_code_id  := cp.classification_code_id;
9324       l_reason_code_id          := cp.reason_code_id;
9325       l_object_id               := cp.object_id;
9326       l_object_type             := cp.object_type;
9327       l_ci_number               := cp.ci_number;
9328       l_date_required           := cp.date_required;
9329       l_priority_code           := cp.priority_code;
9330       l_effort_level_code       := cp.effort_level_code;
9331       l_price                   := cp.price;
9332       l_price_currency_code     := cp.price_currency_code;
9333       l_source_type_code        := cp.source_type_code;
9334       l_source_comment          := cp.source_comment;
9335       l_source_number           := cp.source_number;
9336       l_source_date_received    := cp.source_date_received;
9337       l_source_organization     := cp.source_organization;
9338       l_source_person           := cp.source_person;
9339       l_progress_as_of_date     := cp.progress_as_of_date;
9340       l_progress_status_code    := cp.progress_status_code;
9341       l_progress_overview       := cp.status_overview;
9342       l_resolution_code_id      := cp.resolution_code_id;
9343       l_resolution_comment      := cp.resolution;
9344       l_date_closed             := cp.date_closed;
9345       l_closed_by_id            := cp.closed_by_id;
9346       l_project_id              := cp.project_id;
9347       l_ci_type_id              := cp.ci_type_id;
9348       l_attribute_category      := cp.attribute_category;
9349       l_attribute1              := cp.attribute1;
9350       l_attribute2              := cp.attribute2;
9351       l_attribute3              := cp.attribute3;
9352       l_attribute4              := cp.attribute4;
9353       l_attribute5              := cp.attribute5;
9354       l_attribute6              := cp.attribute6;
9355       l_attribute7              := cp.attribute7;
9356       l_attribute8              := cp.attribute8;
9357       l_attribute9              := cp.attribute9;
9358       l_attribute10             := cp.attribute10;
9359       l_attribute11             := cp.attribute11;
9360       l_attribute12             := cp.attribute12;
9361       l_attribute13             := cp.attribute13;
9362       l_attribute14             := cp.attribute14;
9363       l_attribute15             := cp.attribute15;
9364 
9365       close curr_row;
9366 
9367   END IF;
9368 
9369   OPEN c_info;
9370   FETCH c_info INTO l_ci_type_class_code, l_approval_required_flag, l_next_allow_status_flag;
9371   CLOSE c_info;
9372 
9373 
9374    /* Added to check invalid API usage*/
9375    if l_ci_type_class_code <> l_class_code then
9376 	PA_UTILS.ADD_MESSAGE(p_app_short_name  => 'PA',
9377                              p_msg_name        => 'PA_CI_INV_API_USE');
9378         if l_debug_mode = 'Y' then
9379                pa_debug.g_err_stage:= 'wrong usage of the api for the control item type';
9380                pa_debug.write(l_module,pa_debug.g_err_stage,l_debug_level3);
9381         end if;
9382 	RAISE FND_API.G_EXC_ERROR;
9383    end if;
9384 
9385 
9386   l_curr_system_status :=  PA_CONTROL_ITEMS_UTILS.getSystemStatus(l_curr_status_code);
9387 
9388   /*  Check if the user can update the item. This requires the user to be owner or to have project authority or
9389       to have open UPDATE actions and status controls are satisfied.  */
9390 
9391   l_check_update_access := pa_ci_security_pkg.check_update_access(p_ci_id);
9392 
9393   IF (l_check_update_access = 'F') THEN
9394 
9395        PA_UTILS.ADD_MESSAGE('PA', 'PA_CI_NO_UPDATE_ACCESS');
9396        RAISE FND_API.G_EXC_ERROR;
9397 
9398   END IF;
9399 
9400   IF l_debug_mode = 'Y' THEN
9401         pa_debug.write(l_module, 'After call to pa_ci_security_pkg.check_update_access', l_debug_level3);
9402   END IF;
9403 
9404   /* Check for the status control: check whether the action CONTROL_ITEM_ALLOW_UPDATE is allowed on the current status of the issue. */
9405 
9406   l_chk_status_ctrl := pa_control_items_utils.CheckCIActionAllowed('CONTROL_ITEM', l_curr_status_code, 'CONTROL_ITEM_ALLOW_UPDATE');
9407 
9408   IF (l_chk_status_ctrl = 'N') THEN
9409 
9410        PA_UTILS.ADD_MESSAGE('PA', 'PA_CI_NO_ALLOW_UPDATE');
9411        RAISE FND_API.G_EXC_ERROR;
9412 
9413   END IF;
9414 
9415 
9416   IF l_debug_mode = 'Y' THEN
9417         pa_debug.write(l_module, 'After call to pa_control_items_utils.CheckCIActionAllowed', l_debug_level3);
9418   END IF;
9419 
9420   /*  The control item will not be updateable if the current status has approval workflow attached. */
9421 
9422   OPEN c_submit_status(l_curr_status_code);
9423   FETCH c_submit_status INTO l_enable_wf_flag, l_wf_success_status_code, l_wf_failure_status_code;
9424   CLOSE c_submit_status;
9425 
9426   IF (l_enable_wf_flag = 'Y' AND l_wf_success_status_code IS NOT NULL AND l_wf_failure_status_code IS NOT NULL) THEN
9427 
9428        PA_UTILS.ADD_MESSAGE('PA', 'PA_CI_APPROVAL_WORKFLOW');
9429        RAISE FND_API.G_EXC_ERROR;
9430 
9431   END IF;
9432 
9433   IF l_debug_mode = 'Y' THEN
9434         pa_debug.write(l_module, 'After checking for submitted status', l_debug_level3);
9435   END IF;
9436 
9437 
9438   IF p_ci_status_code = G_PA_MISS_CHAR THEN
9439        l_ci_status_code := l_curr_status_code;
9440   ELSIF p_ci_status_code IS NOT NULL THEN
9441           l_ci_status_code := p_ci_status_code;
9442 
9443 
9444           l_sel_clause  := ' SELECT ps.project_status_code ';
9445           l_from_clause := ' FROM pa_obj_status_lists osl, pa_status_list_items sli, pa_project_statuses ps ';
9446           l_where       := ' WHERE osl.status_type = '||'''CONTROL_ITEM'''||
9447                              ' AND osl.object_type = '||'''PA_CI_TYPES'''||
9448                              ' AND osl.object_id = '||l_ci_type_id||
9449                              ' AND osl.status_list_id = sli.status_list_id'||
9450                              ' AND sli.project_status_code = ps.project_status_code'||
9451                              ' AND ps.project_status_code <> '||''''||l_curr_status_code||''''||
9452                              ' AND ps.status_type = osl.status_type'||
9453                              ' AND trunc(sysdate) between nvl(ps.start_date_active, trunc(sysdate)) and nvl(ps.end_date_active, trunc(sysdate))'||
9454                              ' AND (('||''''||l_next_allow_status_flag||''''||' = '||'''N'''||' and 1=2)'||
9455                                   ' OR '||
9456                                   ' ('||''''||l_next_allow_status_flag||''''||' = '||'''S'''||
9457                                   ' and ps.project_status_code in (select project_status_code from pa_project_statuses where status_type = '||'''CONTROL_ITEM'''||
9458                                   ' and project_system_status_code in ( select next_allowable_status_code from pa_next_allow_statuses where status_code = '||
9459                                   ''''||l_curr_status_code||''''||')))'||
9460                                   ' OR '||
9461                                   ' ('||''''||l_next_allow_status_flag||''''||' = '||'''U'''||
9462                                   ' and ps.project_status_code in (select next_allowable_status_code from pa_next_allow_statuses where status_code = '||''''||
9463                                   l_curr_status_code||''''||'))'||
9464                                   ' OR '||
9465                                   ' ('||''''||l_next_allow_status_flag||''''||' = '||'''A'''||
9466                                   ' and ps.project_status_code in (select project_status_code from pa_project_statuses where status_type = '||'''CONTROL_ITEM'''||
9467                                   ' and project_system_status_code in (select next_allowable_status_code from pa_next_allow_statuses where status_code = '||
9468                                   ''''||l_curr_system_status||''''||'))))'||
9469                               ' AND ps.project_status_code not in (select wf_success_status_code from pa_project_statuses where status_type = '||
9470                               '''CONTROL_ITEM'''||' and wf_success_status_code is not null and wf_failure_status_code is not null)'||
9471                               ' AND ps.project_status_code not in (select wf_failure_status_code from pa_project_statuses where status_type = '||
9472                               '''CONTROL_ITEM'''||' and wf_success_status_code is not null and wf_failure_status_code is not null)'||
9473                               ' AND decode(ps.project_system_status_code, '||'''CI_CANCELED'''||
9474                               ', nvl(pa_control_items_utils.CheckCIActionAllowed('||'''CONTROL_ITEM'''||', '||''''||l_curr_status_code||''''||', '||
9475                               '''CONTROL_ITEM_ALLOW_CANCEL'''||', null),'||'''N'''||' ),'||'''Y'''||' ) = '||'''Y'''||
9476                               ' AND decode(ps.project_system_status_code,'||'''CI_WORKING'''||
9477                               ' ,nvl(pa_control_items_utils.CheckCIActionAllowed('||'''CONTROL_ITEM'''||', '||''''||l_curr_status_code||''''||', '||
9478                               '''CONTROL_ITEM_ALLOW_REWORK'''||' ,null),'||'''N'''||' ),'||'''Y'''||' ) = '||'''Y'''||
9479                               ' AND nvl(pa_control_items_utils.CheckCIActionAllowed('||'''CONTROL_ITEM'''||', '||''''||l_curr_status_code||''''||', '||
9480                               '''CONTROL_ITEM_ALLOW_UPDST'''||' ,null),'||'''N'''||' ) = '||'''Y'''||
9481                               ' AND decode(ps.project_system_status_code,'||'''CI_DRAFT'''||
9482                               ' ,decode('||''''||l_curr_system_status||''''||', '||'''CI_DRAFT'''||', '||
9483                               '''Y'''||' ,'||'''N'''||' ),'||'''Y'''||' ) = '||'''Y'''||
9484                               ' AND ps.project_status_code = '||''''||p_ci_status_code||'''';
9485 
9486           IF (l_ci_type_class_code = 'CHANGE_ORDER' AND l_curr_system_status = 'CI_WORKING') THEN
9487                 l_where1 := ' AND ps.project_system_status_code <> '||'''CI_CLOSED''';
9488           END IF;
9489 
9490           l_stmnt := l_sel_clause || l_from_clause || l_where || l_where1;
9491 
9492           IF l_debug_mode = 'Y' THEN
9493                pa_debug.write(l_module, l_stmnt, l_debug_level3);
9494           END IF;
9495 
9496     l_cursor := dbms_sql.open_cursor;
9497 
9498     DBMS_SQL.PARSE(l_cursor, l_stmnt, DBMS_SQL.v7);
9499     DBMS_SQL.DEFINE_COLUMN(l_cursor, 1, l_ci_status_code_1, 30);
9500 
9501     l_rows := DBMS_SQL.EXECUTE(l_cursor);
9502 
9503     IF (l_rows < 0) THEN
9504                PA_UTILS.Add_Message( p_app_short_name => 'PA'
9505                                     ,p_msg_name       => 'PA_TO_STATUS_INVALID');
9506                x_return_status := FND_API.G_RET_STS_ERROR;
9507                l_to_status_flag := 'N';
9508     ELSE
9509        l_rows1 := DBMS_SQL.FETCH_ROWS(l_cursor);
9510 
9511        if l_rows1 > 0 THEN
9512             DBMS_SQL.COLUMN_VALUE(l_cursor, 1, l_ci_status_code_1);
9513             l_ci_status_code := l_ci_status_code_1;
9514        else
9515 	     PA_UTILS.Add_Message( p_app_short_name => 'PA'
9516                                   ,p_msg_name       => 'PA_TO_STATUS_INVALID');
9517              x_return_status := FND_API.G_RET_STS_ERROR;
9518              l_to_status_flag := 'N';
9519        end if;
9520 
9521     END IF;
9522     IF dbms_sql.is_open(l_cursor) THEN
9523          dbms_sql.close_cursor(l_cursor);
9524     END IF;
9525   ELSIF p_ci_status_code IS NULL THEN
9526           l_ci_status_code := p_ci_status_code;
9527           PA_UTILS.ADD_MESSAGE('PA', 'PA_CI_NULL_STATUS');
9528           x_return_status := FND_API.G_RET_STS_ERROR;
9529 	  l_to_status_flag := 'N';
9530   END IF;
9531 
9532   IF p_record_version_number = G_PA_MISS_NUM THEN
9533        NULL;
9534   ELSE
9535        l_record_version_number := p_record_version_number;
9536   END IF;
9537 
9538   IF p_summary = G_PA_MISS_CHAR THEN
9539        NULL;
9540   ELSIF p_summary IS NOT NULL THEN
9541           l_summary := p_summary;
9542   ELSIF p_summary IS NULL THEN
9543           PA_UTILS.ADD_MESSAGE('PA', 'PA_CI_NULL_SUMMARY');
9544           x_return_status := FND_API.G_RET_STS_ERROR;
9545   END IF;
9546 
9547   IF p_description = G_PA_MISS_CHAR THEN
9548        NULL;
9549   ELSIF p_description IS NOT NULL THEN
9550           l_description := p_description;
9551   ELSIF p_description IS NULL THEN
9552           l_description := p_description;
9553   END IF;
9554 
9555  /*Adding the comment after validating the Owner id*/
9556   IF p_owner_id = G_PA_MISS_NUM THEN
9557        l_owner_id := l_curr_owner_id;
9558   ELSIF p_owner_id IS NOT NULL THEN
9559           l_owner_id := p_owner_id;
9560           IF (l_owner_id = l_curr_owner_id) then
9561                  PA_UTILS.Add_Message( p_app_short_name => 'PA'
9562                                       ,p_msg_name       => 'PA_CI_CHANGE_OWNER_INVALID');
9563                  x_return_status := 'E';
9564 
9565 	  ELSIF (l_owner_id <> l_curr_owner_id) then
9566 		l_chgowner_allowed := pa_ci_security_pkg.check_change_owner_access(p_ci_id);
9567 		IF (l_chgowner_allowed <> 'T') then
9568 		         PA_UTILS.Add_Message( p_app_short_name => 'PA'
9569 				              ,p_msg_name       => 'PA_CI_OWNER_CHG_NOT_ALLOWED');
9570 			 x_return_status := 'E';
9571 	        else
9572 		         l_to_owner_allowed := pa_ci_security_pkg.is_to_owner_allowed(p_ci_id, l_owner_id);
9573 		         if (l_to_owner_allowed <> 'T') then
9574 				 PA_UTILS.Add_Message( p_app_short_name => 'PA'
9575 					              ,p_msg_name       => 'PA_CI_TO_OWNER_NOT_ALLOWED');
9576 		         x_return_status := 'E';
9577 		         else
9578 
9579 				/*get the Passed owner names*/
9580 				OPEN c_get_owner(l_owner_id,l_project_id);
9581 				FETCH c_get_owner into l_owner_name;
9582 				if (c_get_owner%notfound) then
9583 					PA_UTILS.Add_Message( p_app_short_name => 'PA'
9584 					      ,p_msg_name       => 'PA_CI_CHANGE_OWNER_INVALID');
9585 					x_return_status := 'E';
9586 				end if;
9587 				close 	c_get_owner;
9588 
9589 				/*Get the Current Owner name*/
9590 				OPEN c_get_owner(l_curr_owner_id,l_project_id);
9591 				FETCH c_get_owner into l_curr_owner_name;
9592 				if (c_get_owner%notfound) then
9593 					PA_UTILS.Add_Message( p_app_short_name => 'PA'
9594 					      ,p_msg_name       => 'PA_CI_CHANGE_OWNER_INVALID');
9595 					x_return_status := 'E';
9596 				end if;
9597 				close 	c_get_owner;
9598 
9599 					fnd_message.set_name('PA', 'PA_CI_LOG_OWNER_CHANGE');
9600 					fnd_message.set_token('PREV_OWNER', l_curr_owner_name);
9601 					fnd_message.set_token('NEXT_OWNER', l_owner_name);
9602 					fnd_message.set_token('COMMENT', p_owner_comment);
9603 					l_comment_text := fnd_message.get;
9604 
9605 					 pa_ci_comments_pkg.insert_row(
9606 						p_ci_comment_id             => l_ci_comment_id,
9607 						p_ci_id                     => p_ci_id,
9608 						p_type_code                 => 'CHANGE_OWNER',
9609 						p_comment_text              => l_comment_text,
9610 						p_last_updated_by           => fnd_global.user_id,
9611 						p_created_by                => fnd_global.user_id,
9612 						p_creation_date             => sysdate,
9613 						p_last_update_date          => sysdate,
9614 						p_last_update_login         => fnd_global.login_id,
9615 						p_ci_action_id              => null);
9616 
9617 			end if;
9618 	        end if;
9619 	end if;
9620   ELSIF p_owner_id IS NOT NULL THEN
9621           l_owner_id := p_owner_id;
9622           IF (l_owner_id = l_curr_owner_id) then
9623                  PA_UTILS.Add_Message( p_app_short_name => 'PA'
9624                                       ,p_msg_name       => 'PA_CI_CHANGE_OWNER_INVALID');
9625                  x_return_status := 'E';
9626           END IF;
9627           /* Getting validated in pa_control_items_pub.update_control_item API. */
9628   ELSIF p_owner_id IS NULL THEN
9629           PA_UTILS.Add_Message( p_app_short_name => 'PA'
9630                                ,p_msg_name       => 'PA_CI_OWNER_NULL');
9631           x_return_status := FND_API.G_RET_STS_ERROR;
9632   END IF;
9633 
9634   IF p_classification_code = G_PA_MISS_NUM THEN
9635        NULL;
9636   ELSIF p_classification_code IS NOT NULL THEN
9637           OPEN c_classification (l_ci_type_id, p_classification_code);
9638           FETCH c_classification INTO l_classification_code_id;
9639           IF c_classification%NOTFOUND then
9640               -- close c_classification;
9641                PA_UTILS.Add_Message( p_app_short_name => 'PA'
9642                                     ,p_msg_name       => 'PA_CI_CLASSIFICATION_INV');
9643                x_return_status := FND_API.G_RET_STS_ERROR;
9644           END IF;
9645           close c_classification;
9646   ELSIF p_classification_code IS NULL THEN
9647           PA_UTILS.Add_Message( p_app_short_name => 'PA'
9648                                ,p_msg_name       => 'PA_CI_CLASSIFICATION_NULL');
9649           x_return_status := FND_API.G_RET_STS_ERROR;
9650   END IF;
9651 
9652   IF p_reason_code = G_PA_MISS_NUM THEN
9653        NULL;
9654   ELSIF p_reason_code IS NOT NULL THEN
9655           OPEN c_reason (l_ci_type_id, p_reason_code);
9656           FETCH c_reason INTO l_reason_code_id;
9657           IF c_reason%NOTFOUND then
9658               -- close c_reason;
9659                PA_UTILS.Add_Message( p_app_short_name => 'PA'
9660                                     ,p_msg_name       => 'PA_CI_REASON_INV');
9661                x_return_status := FND_API.G_RET_STS_ERROR;
9662           END IF;
9663           close c_reason;
9664   ELSIF p_reason_code IS NULL THEN
9665           PA_UTILS.Add_Message( p_app_short_name => 'PA'
9666                                ,p_msg_name       => 'PA_CI_REASON_NULL');
9667           x_return_status := FND_API.G_RET_STS_ERROR;
9668   END IF;
9669 
9670   IF p_object_id = G_PA_MISS_NUM THEN
9671        NULL;
9672   ELSIF p_object_id IS NOT NULL THEN
9673        /* As of now we're only handling PA_TASKS objects */
9674        BEGIN
9675                SELECT proj_element_id
9676                  INTO l_object_id
9677                  FROM PA_FIN_LATEST_PUB_TASKS_V
9678                 WHERE project_id     = l_project_id
9679                   AND proj_element_id = p_object_id;
9680 
9681         EXCEPTION WHEN TOO_MANY_ROWS THEN
9682            PA_UTILS.Add_Message( p_app_short_name => 'PA'
9683                                 ,p_msg_name       => 'PA_OBJECT_NAME_MULTIPLE');
9684            x_return_status := FND_API.G_RET_STS_ERROR;
9685 
9686         WHEN OTHERS THEN
9687            PA_UTILS.Add_Message( p_app_short_name => 'PA'
9688                                 ,p_msg_name       => 'PA_OBJECT_NAME_INV');
9689            x_return_status := FND_API.G_RET_STS_ERROR;
9690         END;
9691   ELSIF p_object_id IS NULL THEN
9692           l_object_id := p_object_id;
9693   END IF;
9694 
9695   IF p_object_type = G_PA_MISS_CHAR THEN
9696        NULL;
9697   ELSIF p_object_type IS NOT NULL THEN
9698          IF p_object_type = 'PA_TASKS' THEN
9699               l_object_type := p_object_type;
9700          ELSE
9701            PA_UTILS.Add_Message( p_app_short_name => 'PA'
9702                                 ,p_msg_name       => 'PA_OBJECT_TYPE_INV');
9703            x_return_status := FND_API.G_RET_STS_ERROR;
9704          END IF;
9705   ELSIF p_object_type IS NULL THEN
9706        l_object_type := p_object_type;
9707   END IF;
9708 
9709   IF p_date_required = G_PA_MISS_DATE THEN
9710        NULL;
9711   ELSIF p_date_required IS NOT NULL THEN
9712           l_date_required := p_date_required;
9713   ELSIF p_date_required IS NULL THEN
9714           l_date_required := p_date_required;
9715   END IF;
9716 
9717   IF p_priority_code = G_PA_MISS_CHAR THEN
9718        NULL;
9719   ELSIF p_priority_code IS NOT NULL THEN
9720           OPEN c_lkup(l_priority_type, p_priority_code);
9721           FETCH c_lkup INTO l_priority_code;
9722           IF c_lkup%NOTFOUND then
9723              --  close c_lkup;
9724                PA_UTILS.Add_Message( p_app_short_name => 'PA'
9725                                     ,p_msg_name       => 'PA_CI_PRIORITY_INV');
9726                x_return_status := FND_API.G_RET_STS_ERROR;
9727           END IF;
9728           close c_lkup;
9729   ELSIF p_priority_code IS NULL THEN
9730           l_priority_code := p_priority_code;
9731   END IF;
9732 
9733   IF p_effort_level_code = G_PA_MISS_CHAR THEN
9734        l_effort_level_code := null;
9735   ELSIF p_effort_level_code IS NOT NULL THEN
9736           OPEN c_lkup(l_effort_type, p_effort_level_code);
9737           FETCH c_lkup INTO l_effort_level_code;
9738           IF c_lkup%NOTFOUND then
9739              --  close c_lkup;
9740                PA_UTILS.Add_Message( p_app_short_name => 'PA'
9741                                     ,p_msg_name       => 'PA_CI_EFFORT_INV');
9742                x_return_status := FND_API.G_RET_STS_ERROR;
9743           END IF;
9744           close c_lkup;
9745   ELSIF p_effort_level_code IS NULL THEN
9746           l_effort_level_code := p_effort_level_code;
9747   END IF;
9748 
9749   IF p_price = G_PA_MISS_NUM THEN
9750        l_price := null;
9751   ELSIF p_price IS NOT NULL THEN
9752           l_price := p_price;
9753   ELSIF p_price IS NULL THEN
9754           l_price := p_price;
9755   END IF;
9756 
9757   IF p_price_currency_code = G_PA_MISS_CHAR THEN
9758        NULL;
9759   ELSIF p_price_currency_code IS NOT NULL THEN
9760           l_price_currency_code := p_price_currency_code;
9761           /* Getting validated in pa_control_items_pvt.update_control_item API. */
9762   ELSIF p_price_currency_code IS NULL THEN
9763           l_price_currency_code := p_price_currency_code;
9764   END IF;
9765 
9766   IF p_source_type_code = G_PA_MISS_CHAR THEN
9767        NULL;
9768   ELSIF p_source_type_code IS NOT NULL THEN
9769           OPEN c_lkup(l_source_type, p_source_type_code);
9770           FETCH c_lkup INTO l_source_type_code;
9771           IF c_lkup%NOTFOUND then
9772              --  close c_lkup;
9773                PA_UTILS.Add_Message( p_app_short_name => 'PA'
9774                                     ,p_msg_name       => 'PA_CI_SOURCE_TYPE_INV');
9775                x_return_status := FND_API.G_RET_STS_ERROR;
9776           END IF;
9777           close c_lkup;
9778   ELSIF p_source_type_code IS NULL THEN
9779           l_source_type_code := p_source_type_code;
9780   END IF;
9781 
9782   IF p_source_comment = G_PA_MISS_CHAR THEN
9783        NULL;
9784   ELSE
9785           l_source_comment := p_source_comment;
9786   END IF;
9787 
9788   IF p_source_number = G_PA_MISS_CHAR THEN
9789        NULL;
9790   ELSE
9791           l_source_number := p_source_number;
9792   END IF;
9793 
9794   IF p_source_date_received = G_PA_MISS_DATE THEN
9795        NULL;
9796   ELSE
9797           l_source_date_received := p_source_date_received;
9798   END IF;
9799 
9800   IF p_source_organization = G_PA_MISS_CHAR THEN
9801        NULL;
9802   ELSE
9803           l_source_organization := p_source_organization;
9804   END IF;
9805 
9806   IF p_source_person = G_PA_MISS_CHAR THEN
9807        NULL;
9808   ELSE
9809           l_source_person := p_source_person;
9810   END IF;
9811 
9812   IF p_progress_as_of_date = G_PA_MISS_DATE THEN
9813        NULL;
9814   ELSIF p_progress_as_of_date IS NOT NULL THEN
9815           l_progress_as_of_date := p_progress_as_of_date;
9816   ELSIF p_progress_as_of_date IS NULL THEN
9817           PA_UTILS.Add_Message( p_app_short_name => 'PA'
9818                                ,p_msg_name       => 'PA_AS_OF_DATE_NULL');
9819           x_return_status := FND_API.G_RET_STS_ERROR;
9820   END IF;
9821 
9822   OPEN c_auto_num;
9823   FETCH c_auto_num INTO l_auto_numbers;
9824   close c_auto_num;
9825 
9826   IF l_auto_numbers is NOT NULL and l_auto_numbers <> 'Y' then
9827 
9828        IF (p_ci_number = G_PA_MISS_CHAR OR p_ci_number IS NULL) THEN
9829 
9830               IF l_ci_status_code IS NOT NULL THEN
9831                     l_new_system_status :=  PA_CONTROL_ITEMS_UTILS.getSystemStatus(l_ci_status_code);
9832               END IF;
9833 
9834               IF p_ci_number = G_PA_MISS_CHAR THEN
9835                    IF l_ci_number IS NULL THEN
9836                         IF (l_curr_system_status = 'CI_DRAFT' AND (l_new_system_status IS NOT NULL AND l_new_system_status <> 'CI_DRAFT')) THEN
9837                               PA_UTILS.Add_Message( p_app_short_name => 'PA'
9838                                                    ,p_msg_name       => 'PA_CI_NO_CI_NUMBER');
9839                               x_return_status := FND_API.G_RET_STS_ERROR;
9840                         ELSIF l_curr_system_status <> 'CI_DRAFT' THEN
9841                                 PA_UTILS.Add_Message( p_app_short_name => 'PA'
9842                                                      ,p_msg_name       => 'PA_CI_NO_CI_NUMBER');
9843                                 x_return_status := FND_API.G_RET_STS_ERROR;
9844                         END IF;
9845                    END IF;
9846               ELSIF p_ci_number IS NULL THEN
9847                  IF (l_curr_system_status = 'CI_DRAFT' AND (l_new_system_status IS NOT NULL AND l_new_system_status <> 'CI_DRAFT')) THEN
9848                        PA_UTILS.Add_Message( p_app_short_name => 'PA'
9849                                             ,p_msg_name       => 'PA_CI_NO_CI_NUMBER');
9850                        x_return_status := FND_API.G_RET_STS_ERROR;
9851                  ELSIF l_curr_system_status <> 'CI_DRAFT' THEN
9852                        PA_UTILS.Add_Message( p_app_short_name => 'PA'
9853                                             ,p_msg_name       => 'PA_CI_NO_CI_NUMBER');
9854                        x_return_status := FND_API.G_RET_STS_ERROR;
9855                  END IF;
9856               END IF;
9857 
9858        ELSIF p_ci_number IS NOT NULL THEN
9859                l_ci_number := p_ci_number;
9860 
9861                OPEN c_ci_number(l_project_id, l_ci_type_id);
9862                FETCH c_ci_number into l_ROWID;
9863                IF (c_ci_number%NOTFOUND) then
9864                     CLOSE c_ci_number;
9865                ELSE
9866                     CLOSE c_ci_number;
9867                     PA_UTILS.Add_Message( p_app_short_name => 'PA'
9868                                          ,p_msg_name       => 'PA_CI_DUPLICATE_CI_NUMBER');
9869                     x_return_status := FND_API.G_RET_STS_ERROR;
9870                END IF;
9871        END IF;
9872 
9873   END IF;
9874 
9875 
9876   IF p_progress_status_code = G_PA_MISS_CHAR THEN
9877        NULL;
9878   ELSIF p_progress_status_code IS NOT NULL THEN
9879           OPEN c_statuses(l_progress_type, p_progress_status_code);
9880           FETCH c_statuses INTO l_progress_status_code;
9881           IF c_statuses%NOTFOUND then
9882                close c_statuses;
9883                PA_UTILS.Add_Message( p_app_short_name => 'PA'
9884                                     ,p_msg_name       => 'PA_PROGRESS_STATUS_INV');
9885                x_return_status := FND_API.G_RET_STS_ERROR;
9886           END IF;
9887           close c_statuses;
9888   ELSIF p_progress_status_code IS NULL THEN
9889           PA_UTILS.Add_Message( p_app_short_name => 'PA'
9890                                ,p_msg_name       => 'PA_PROGRESS_STATUS_NULL');
9891           x_return_status := FND_API.G_RET_STS_ERROR;
9892   END IF;
9893 
9894   IF p_progress_overview = G_PA_MISS_CHAR THEN
9895        NULL;
9896   ELSE
9897           l_progress_overview := p_progress_overview;
9898   END IF;
9899 
9900   IF p_resolution_code = G_PA_MISS_CHAR THEN
9901        NULL;
9902   ELSIF p_resolution_code IS NOT NULL THEN
9903           OPEN c_resolution (l_ci_type_id, p_resolution_code);
9904           FETCH c_resolution INTO l_resolution_code_id;
9905           IF c_resolution%NOTFOUND then
9906                close c_resolution;
9907                PA_UTILS.Add_Message( p_app_short_name => 'PA'
9908                                     ,p_msg_name       => 'PA_CI_RESOLUTION_INV');
9909                x_return_status := FND_API.G_RET_STS_ERROR;
9910           END IF;
9911           close c_resolution;
9912   ELSIF p_resolution_code IS NULL THEN
9913           l_resolution_code_id := p_resolution_code;
9914   END IF;
9915 
9916   IF p_resolution_comment = G_PA_MISS_CHAR THEN
9917        NULL;
9918   ELSE
9919        l_resolution_comment := p_resolution_comment;
9920   END IF;
9921 
9922   IF p_attribute_category = G_PA_MISS_CHAR THEN
9923        NULL;
9924   ELSE
9925        l_attribute_category := p_attribute_category;
9926   END IF;
9927 
9928   IF p_attribute1 = G_PA_MISS_CHAR THEN
9929        NULL;
9930   ELSE
9931        l_attribute1 := p_attribute1;
9932   END IF;
9933 
9934   IF p_attribute2 = G_PA_MISS_CHAR THEN
9935        NULL;
9936   ELSE
9937        l_attribute2 := p_attribute2;
9938   END IF;
9939 
9940   IF p_attribute3 = G_PA_MISS_CHAR THEN
9941        NULL;
9942   ELSE
9943        l_attribute3 := p_attribute3;
9944   END IF;
9945 
9946   IF p_attribute4 = G_PA_MISS_CHAR THEN
9947        NULL;
9948   ELSE
9949        l_attribute4 := p_attribute4;
9950   END IF;
9951 
9952   IF p_attribute5 = G_PA_MISS_CHAR THEN
9953        NULL;
9954   ELSE
9955        l_attribute5 := p_attribute5;
9956   END IF;
9957 
9958   IF p_attribute6 = G_PA_MISS_CHAR THEN
9959        NULL;
9960   ELSE
9961        l_attribute6 := p_attribute6;
9962   END IF;
9963 
9964   IF p_attribute7 = G_PA_MISS_CHAR THEN
9965        NULL;
9966   ELSE
9967        l_attribute7 := p_attribute7;
9968   END IF;
9969 
9970   IF p_attribute8 = G_PA_MISS_CHAR THEN
9971        NULL;
9972   ELSE
9973        l_attribute8 := p_attribute8;
9974   END IF;
9975 
9976   IF p_attribute9 = G_PA_MISS_CHAR THEN
9977        NULL;
9978   ELSE
9979        l_attribute9 := p_attribute9;
9980   END IF;
9981 
9982   IF p_attribute10 = G_PA_MISS_CHAR THEN
9983        NULL;
9984   ELSE
9985        l_attribute10 := p_attribute10;
9986   END IF;
9987 
9988   IF p_attribute11 = G_PA_MISS_CHAR THEN
9989        NULL;
9990   ELSE
9991        l_attribute11 := p_attribute11;
9992   END IF;
9993 
9994   IF p_attribute12 = G_PA_MISS_CHAR THEN
9995        NULL;
9996   ELSE
9997        l_attribute12 := p_attribute12;
9998   END IF;
9999 
10000   IF p_attribute13 = G_PA_MISS_CHAR THEN
10001        NULL;
10002   ELSE
10003        l_attribute13 := p_attribute13;
10004   END IF;
10005 
10006   IF p_attribute14 = G_PA_MISS_CHAR THEN
10007        NULL;
10008   ELSE
10009        l_attribute14 := p_attribute14;
10010   END IF;
10011 
10012   IF p_attribute15 = G_PA_MISS_CHAR THEN
10013        NULL;
10014   ELSE
10015        l_attribute15 := p_attribute15;
10016   END IF;
10017 
10018 
10019   IF (l_curr_status_code is NOT NULL AND
10020       l_ci_status_code   is NOT NULL AND
10021       l_curr_status_code <> l_ci_status_code AND
10022       l_to_status_flag = 'Y') THEN
10023 
10024          IF l_debug_mode = 'Y' THEN
10025               pa_debug.write(l_module, 'before call to ChangeCIStatusValidate', l_debug_level3);
10026          END IF;
10027 
10028          PA_CONTROL_ITEMS_UTILS.ChangeCIStatusValidate (
10029                                   p_init_msg_list      => p_init_msg_list
10030                                  ,p_commit             => p_commit
10031                                  ,p_validate_only      => l_validate_only
10032                                  ,p_max_msg_count      => l_max_msg_count
10033                                  ,p_ci_id              => p_ci_id
10034                                  ,p_status             => p_ci_status_code
10035                                  ,p_enforce_security   => l_enforce_security
10036                                  ,p_resolution_check   => l_resolution_check
10037                                  ,x_resolution_req     => l_resolution_req
10038                                  ,x_resolution_req_cls => l_resolution_req_cls
10039                                  ,x_start_wf           => l_start_wf
10040                                  ,x_new_status         => l_ci_status_code
10041                                  ,x_num_of_actions     => l_num_of_actions
10042                                  ,x_return_status      => x_return_status
10043                                  ,x_msg_count          => x_msg_count
10044                                  ,x_msg_data           => x_msg_data);
10045 
10046        /* l_ci_status_code gets the new status from ChangeCIStatusValidate.
10047           In case of CR/CO, if Auto Approve on Submission is enabled and while changing the status to submitted,
10048           then the new status would be the success status code defined for the workflow */
10049 
10050         IF l_debug_mode = 'Y' THEN
10051              pa_debug.write(l_module, 'After call to ChangeCIStatusValidate : x_return_status = '||x_return_status, l_debug_level3);
10052              pa_debug.write(l_module, 'After call to ChangeCIStatusValidate : l_ci_status_code = '||l_ci_status_code, l_debug_level3);
10053         END IF;
10054 
10055         IF x_return_status = 'S' THEN
10056              l_status_change_flag := 'Y';
10057         END IF;
10058 
10059         IF l_debug_mode = 'Y' THEN
10060              pa_debug.write(l_module, 'After call to ChangeCIStatusValidate : l_status_change_flag = '||l_status_change_flag, l_debug_level3);
10061         END IF;
10062 
10063         IF (l_resolution_req IS NOT NULL AND  l_resolution_req = 'Y') THEN
10064               IF (PA_CONTROL_ITEMS_UTILS.checkhasresolution(p_ci_id) <> 'Y'  ) THEN
10065                   IF (l_resolution_code_id IS NULL) THEN
10066                       PA_UTILS.Add_Message( p_app_short_name => 'PA'
10067                                            ,p_msg_name       => 'PA_CI_RESOLUTION_OPEN');
10068                       x_return_status := FND_API.G_RET_STS_ERROR;
10069                   END IF;
10070               ELSE
10071                   IF (l_resolution_code_id IS NULL) THEN
10072                       PA_UTILS.Add_Message( p_app_short_name => 'PA'
10073                                            ,p_msg_name       => 'PA_CI_RESOLUTION_OPEN');
10074                       x_return_status := FND_API.G_RET_STS_ERROR;
10075                   END IF;
10076               END IF;
10077         END IF;
10078 
10079         IF (l_resolution_req_cls IS NOT NULL AND  l_resolution_req_cls = 'Y') THEN
10080               IF (PA_CONTROL_ITEMS_UTILS.checkhasresolution(p_ci_id) <> 'Y'  ) THEN
10081                   IF (l_resolution_code_id IS NULL) THEN
10082                       PA_UTILS.Add_Message( p_app_short_name => 'PA'
10083                                            ,p_msg_name       => 'PA_CI_CLOSE_INV_RES');
10084                       x_return_status := FND_API.G_RET_STS_ERROR;
10085                   END IF;
10086               ELSE
10087                   IF (l_resolution_code_id IS NULL) THEN
10088                       PA_UTILS.Add_Message( p_app_short_name => 'PA'
10089                                            ,p_msg_name       => 'PA_CI_CLOSE_INV_RES');
10090                       x_return_status := FND_API.G_RET_STS_ERROR;
10091                   END IF;
10092               END IF;
10093         END IF;
10094 
10095   END IF;
10096 
10097 
10098   IF (l_validate_only <> fnd_api.g_true AND x_return_status = 'S') THEN
10099 
10100           IF l_debug_mode = 'Y' THEN
10101                pa_debug.write(l_module, 'before call to PA_CONTROL_ITEMS_PUB.UPDATE_CONTROL_ITEM', l_debug_level3);
10102           END IF;
10103 
10104           PA_CONTROL_ITEMS_PUB.UPDATE_CONTROL_ITEM (
10105                                  p_api_version           =>  1.0
10106                                 ,p_init_msg_list         => fnd_api.g_false
10107                                 ,p_commit                => FND_API.g_false
10108                                 ,p_validate_only         => FND_API.g_false
10109                                 ,p_max_msg_count         => FND_API.g_miss_num
10110                                 ,p_ci_id                 => p_ci_id
10111                                 ,p_ci_type_id            => l_ci_type_id
10112                                 ,p_summary               => l_summary
10113                                 ,p_status_code           => l_ci_status_code
10114                                 ,p_owner_id              => l_owner_id
10115                                 ,p_owner_name            => null
10116                                 ,p_highlighted_flag      => null
10117                                 ,p_progress_status_code  => l_progress_status_code
10118                                 ,p_progress_as_of_date   => l_progress_as_of_date
10119                                 ,p_classification_code   => l_classification_code_id
10120                                 ,p_reason_code           => l_reason_code_id
10121                                 ,p_record_version_number => l_record_version_number
10122                                 ,p_project_id            => l_project_id
10123                                 ,p_object_type           => l_object_type
10124                                 ,p_object_id             => l_object_id
10125                                 ,p_object_name           => null
10126                                 ,p_ci_number             => l_ci_number
10127                                 ,p_date_required         => l_date_required
10128                                 ,p_date_closed           => l_date_closed
10129                                 ,p_closed_by_id          => l_closed_by_id
10130                                 ,p_description           => l_description
10131                                 ,p_status_overview       => l_progress_overview
10132                                 ,p_resolution            => l_resolution_comment
10133                                 ,p_resolution_code       => l_resolution_code_id
10134                                 ,p_priority_code         => l_priority_code
10135                                 ,p_effort_level_code     => l_effort_level_code
10136                                 ,p_open_action_num       => null
10137                                 ,p_price                 => l_price
10138                                 ,p_price_currency_code   => l_price_currency_code
10139                                 ,p_source_type_code      => l_source_type_code
10140                                 ,p_source_comment        => l_source_comment
10141                                 ,p_source_number         => l_source_number
10142                                 ,p_source_date_received  => l_source_date_received
10143                                 ,p_source_organization   => l_source_organization
10144                                 ,p_source_person         => l_source_person
10145                                 ,p_attribute_category    => l_attribute_category
10146                                 ,p_attribute1            => l_attribute1
10147                                 ,p_attribute2            => l_attribute2
10148                                 ,p_attribute3            => l_attribute3
10149                                 ,p_attribute4            => l_attribute4
10150                                 ,p_attribute5            => l_attribute5
10151                                 ,p_attribute6            => l_attribute6
10152                                 ,p_attribute7            => l_attribute7
10153                                 ,p_attribute8            => l_attribute8
10154                                 ,p_attribute9            => l_attribute9
10155                                 ,p_attribute10           => l_attribute10
10156                                 ,p_attribute11           => l_attribute11
10157                                 ,p_attribute12           => l_attribute12
10158                                 ,p_attribute13           => l_attribute13
10159                                 ,p_attribute14           => l_attribute14
10160                                 ,p_attribute15           => l_attribute15
10161                                 ,x_return_status         => x_return_status
10162                                 ,x_msg_count             => x_msg_count
10163                                 ,x_msg_data              => x_msg_data
10164                         );
10165 
10166           IF l_debug_mode = 'Y' THEN
10167                pa_debug.write(l_module, 'after call to PA_CONTROL_ITEMS_PUB.UPDATE_CONTROL_ITEM : x_return_status = '||x_return_status, l_debug_level3);
10168           END IF;
10169 
10170   END IF;
10171 
10172   IF (l_status_change_flag = 'Y' AND l_validate_only <> fnd_api.g_true AND x_return_status = 'S') THEN
10173 
10174            /* call the insert table handlers of pa_obj_status_changes and pa_ci_comments here */
10175 
10176            IF l_debug_mode = 'Y' THEN
10177                 pa_debug.write(l_module, 'before call to PA_CONTROL_ITEMS_UTILS.ADD_STATUS_CHANGE_COMMENT', l_debug_level3);
10178            END IF;
10179 
10180            PA_CONTROL_ITEMS_UTILS.ADD_STATUS_CHANGE_COMMENT( p_object_type        => 'PA_CI_TYPES'
10181                                                             ,p_object_id          => p_ci_id
10182                                                             ,p_type_code          => 'CHANGE_STATUS'
10183                                                             ,p_status_type        => 'CONTROL_ITEM'
10184                                                             ,p_new_project_status => l_ci_status_code
10185                                                             ,p_old_project_status => l_curr_status_code
10186                                                             ,p_comment            => p_status_comment
10187                                                             ,x_return_status      => x_return_status
10188                                                             ,x_msg_count          => x_msg_count
10189                                                             ,x_msg_data           => x_msg_data );
10190 
10191 
10192            IF l_debug_mode = 'Y' THEN
10193                 pa_debug.write(l_module, 'After call to PA_CONTROL_ITEMS_UTILS.ADD_STATUS_CHANGE_COMMENT', l_debug_level3);
10194            END IF;
10195 
10196            PA_CONTROL_ITEMS_UTILS.PostChangeCIStatus (
10197                                                           p_init_msg_list
10198                                                          ,p_commit
10199                                                          ,l_validate_only
10200                                                          ,l_max_msg_count
10201                                                          ,p_ci_id
10202                                                          ,l_curr_status_code
10203                                                          ,l_ci_status_code
10204                                                          ,l_start_wf
10205                                                          ,l_enforce_security
10206                                                          ,l_num_of_actions
10207                                                          ,x_return_status
10208                                                          ,x_msg_count
10209                                                          ,x_msg_data    );
10210 
10211 
10212            IF l_debug_mode = 'Y' THEN
10213                 pa_debug.write(l_module, 'After call to PA_CONTROL_ITEMS_UTILS.PostChangeCIStatus', l_debug_level3);
10214            END IF;
10215 
10216   END IF;
10217 
10218 
10219   IF (p_commit = FND_API.G_TRUE AND x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
10220 
10221         IF l_debug_mode = 'Y' THEN
10222              pa_debug.write(l_module, 'Before Commit', l_debug_level3);
10223         END IF;
10224 
10225         COMMIT;
10226 
10227   END IF;
10228 
10229    --Reset the stack
10230          if l_debug_mode = 'Y' then
10231                   Pa_Debug.reset_curr_function;
10232          end if;
10233 
10234 
10235 EXCEPTION
10236 
10237    WHEN FND_API.G_EXC_ERROR THEN
10238         IF l_debug_mode = 'Y' THEN
10239              pa_debug.write(l_module, 'in FND_API.G_EXC_ERROR exception', l_debug_level3);
10240         END IF;
10241         x_return_status := FND_API.G_RET_STS_ERROR;
10242         l_msg_count := FND_MSG_PUB.count_msg;
10243 
10244         IF p_commit = FND_API.G_TRUE THEN
10245                 ROLLBACK TO UPDATE_CO_SVPT;
10246         END IF;
10247 
10248         IF l_msg_count = 1 AND x_msg_data IS NULL THEN
10249                 PA_INTERFACE_UTILS_PUB.get_messages
10250                 ( p_encoded        => FND_API.G_FALSE
10251                 , p_msg_index      => 1
10252                 , p_msg_count      => l_msg_count
10253                 , p_msg_data       => l_msg_data
10254                 , p_data           => l_data
10255                 , p_msg_index_out  => l_msg_index_out);
10256 
10257                 x_msg_data := l_data;
10258                 x_msg_count := l_msg_count;
10259         ELSE
10260                 x_msg_count := l_msg_count;
10261         END IF;
10262 
10263         IF l_debug_mode = 'Y' THEN
10264                 Pa_Debug.reset_curr_function;
10265         END IF;
10266 
10267 
10268    WHEN OTHERS THEN
10269         IF l_debug_mode = 'Y' THEN
10270              pa_debug.write(l_module, 'in OTHERS exception', l_debug_level3);
10271         END IF;
10272         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10273         x_msg_data      := substr(SQLERRM,1,240);
10274 
10275         IF p_commit = FND_API.G_TRUE THEN
10276                 ROLLBACK TO UPDATE_CO_SVPT;
10277         END IF;
10278 
10279         FND_MSG_PUB.add_exc_msg
10280         ( p_pkg_name            => 'PA_CONTROL_API_PUB'
10281         , p_procedure_name      => 'UPDATE_CHANGE_ORDER'
10282         , p_error_text          => x_msg_data);
10283 
10284         x_msg_count     := FND_MSG_PUB.count_msg;
10285 
10286         IF l_debug_mode = 'Y' THEN
10287                 PA_DEBUG.reset_curr_function;
10288         END IF;
10289 
10290 --        RAISE;
10291 
10292 END UPDATE_CHANGE_ORDER;
10293 
10294 
10295 END PA_CONTROL_API_PUB;