DBA Data[Home] [Help]

PACKAGE BODY: APPS.CSD_PROCESS_PVT

Source


1 Package BODY Csd_Process_Pvt AS
2     /* $Header: csdvintb.pls 120.39.12010000.3 2008/12/10 22:40:42 swai ship $ */
3 
4     -- ---------------------------------------------------------
5     -- Define global variables
6     -- ---------------------------------------------------------
7 
8     G_PKG_NAME  CONSTANT VARCHAR2(30) := 'CSD_PROCESS_PVT';
9     G_FILE_NAME CONSTANT VARCHAR2(12) := 'csdvintb.pls';
10     g_debug NUMBER := Csd_Gen_Utility_Pvt.g_debug_level;
11 
12     /* R12 Srl reservation changes, begin */
13     C_RESERVABLE  CONSTANT NUMBER := 1;
14     C_SERIAL_CONTROL_AT_RECEIPT  CONSTANT NUMBER := 5;
15     C_SERIAL_CONTROL_PREDEFINED CONSTANT NUMBER := 2;
16     /* R12 Srl reservation changes, end */
17 
18 
19     -- Global variable for storing the debug level
20     G_debug_level NUMBER := Fnd_Log.G_CURRENT_RUNTIME_LEVEL;
21 
22     /*-------------------------------------------------------------------------------------*/
23     /* Function  name: DEBUG                                                               */
24     /* Description   : Logs the debug message                                              */
25     /* Called from   : Called from Update API                                              */
26     /*                                                                                     */
27     /* STANDARD PARAMETERS                                                                 */
28     /*   In Parameters :                                                                   */
29     /*      p_message        Required    Debug message that needs to be logged             */
30     /*      p_mod_name       Required    Module name                                       */
31     /*      p_severity_level Required    Severity level                                    */
32     /*   Output Parameters:                                                                */
33     /* NON-STANDARD PARAMETERS                                                             */
34     /*   In Parameters                                                                     */
35     /*   Out parameters                                                                    */
36     /* Change Hist :                                                                       */
37     /*   09/20/03  vlakaman  Initial Creation.                                             */
38     /*-------------------------------------------------------------------------------------*/
39 
40     PROCEDURE DEBUG(p_message        IN VARCHAR2,
41                     p_mod_name       IN VARCHAR2,
42                     p_severity_level IN NUMBER) IS
43 
44         -- Variables used in FND Log
45         l_stat_level  NUMBER := Fnd_Log.LEVEL_STATEMENT;
46         l_proc_level  NUMBER := Fnd_Log.LEVEL_PROCEDURE;
47         l_event_level NUMBER := Fnd_Log.LEVEL_EVENT;
48         l_excep_level NUMBER := Fnd_Log.LEVEL_EXCEPTION;
49         l_error_level NUMBER := Fnd_Log.LEVEL_ERROR;
50         l_unexp_level NUMBER := Fnd_Log.LEVEL_UNEXPECTED;
51 
52     BEGIN
53 
54         IF p_severity_level = 1
55         THEN
56             IF (l_stat_level >= G_debug_level)
57             THEN
58                 Fnd_Log.STRING(l_stat_level, p_mod_name, p_message);
59             END IF;
60         ELSIF p_severity_level = 2
61         THEN
62             IF (l_proc_level >= G_debug_level)
63             THEN
64                 Fnd_Log.STRING(l_proc_level, p_mod_name, p_message);
65             END IF;
66         ELSIF p_severity_level = 3
67         THEN
68             IF (l_event_level >= G_debug_level)
69             THEN
70                 Fnd_Log.STRING(l_event_level, p_mod_name, p_message);
71             END IF;
72         ELSIF p_severity_level = 4
73         THEN
74             IF (l_excep_level >= G_debug_level)
75             THEN
76                 Fnd_Log.STRING(l_excep_level, p_mod_name, p_message);
77             END IF;
78         ELSIF p_severity_level = 5
79         THEN
80             IF (l_error_level >= G_debug_level)
81             THEN
82                 Fnd_Log.STRING(l_error_level, p_mod_name, p_message);
83             END IF;
84         ELSIF p_severity_level = 6
85         THEN
86             IF (l_unexp_level >= G_debug_level)
87             THEN
88                 Fnd_Log.STRING(l_unexp_level, p_mod_name, p_message);
89             END IF;
90         END IF;
91 
92 			Csd_Gen_Utility_Pvt.add(p_message);
93 
94     END DEBUG;
95     /*--------------------------------------------------*/
96     /* procedure name: process_service_request          */
97     /* description   : procedure used to create         */
98     /*                 service requests                 */
99     /*--------------------------------------------------*/
100 
101     PROCEDURE process_service_request(p_api_version         IN NUMBER,
102                                       p_commit              IN VARCHAR2 := Fnd_Api.g_false,
103                                       p_init_msg_list       IN VARCHAR2 := Fnd_Api.g_false,
104                                       p_validation_level    IN NUMBER := Fnd_Api.g_valid_level_full,
105                                       p_action              IN VARCHAR2,
106                                       p_incident_id         IN NUMBER := NULL,
107                                       p_service_request_rec IN Csd_Process_Pvt.SERVICE_REQUEST_REC,
108                                       x_incident_id         OUT NOCOPY NUMBER,
109                                       x_incident_number     OUT NOCOPY VARCHAR2,
110                                       x_return_status       OUT NOCOPY VARCHAR2,
111                                       x_msg_count           OUT NOCOPY NUMBER,
112                                       x_msg_data            OUT NOCOPY VARCHAR2) IS
113 
114       l_notes_tbl     Cs_Servicerequest_Pub.NOTES_TABLE;
115 
116     BEGIN
117 
118        process_service_request(p_api_version         => p_api_version,
119                                p_commit              => p_commit,
120                                p_init_msg_list       => p_init_msg_list,
121                                p_validation_level    => p_validation_level,
122                                p_action              => p_action,
123                                p_incident_id         => p_incident_id,
124                                p_service_request_rec => p_service_request_rec,
125                                p_notes_tbl           => l_notes_tbl,
126                                x_incident_id         => x_incident_id,
127                                x_incident_number     => x_incident_number,
128                                x_return_status       => x_return_status,
129                                x_msg_count           => x_msg_count,
130                                x_msg_data            => x_msg_data );
131 
132     END process_Service_request;
133 
134     /*--------------------------------------------------*/
135     /* procedure name: process_service_request          */
136     /* description   : procedure used to create         */
137     /*                 service requests                 */
138     /*--------------------------------------------------*/
139 
140     PROCEDURE process_service_request(p_api_version         IN  NUMBER,
141                                       p_commit              IN  VARCHAR2 := Fnd_Api.g_false,
142                                       p_init_msg_list       IN  VARCHAR2 := Fnd_Api.g_false,
143                                       p_validation_level    IN  NUMBER := Fnd_Api.g_valid_level_full,
144                                       p_action              IN  VARCHAR2,
145                                       p_incident_id         IN  NUMBER := NULL,
146                                       p_service_request_rec IN  Csd_Process_Pvt.SERVICE_REQUEST_REC,
147                                       p_notes_tbl           IN  Cs_Servicerequest_Pub.NOTES_TABLE,
148                                       x_incident_id         OUT NOCOPY NUMBER,
149                                       x_incident_number     OUT NOCOPY VARCHAR2,
150                                       x_return_status       OUT NOCOPY VARCHAR2,
151                                       x_msg_count           OUT NOCOPY NUMBER,
152                                       x_msg_data            OUT NOCOPY VARCHAR2) IS
153 
154         l_api_name    CONSTANT VARCHAR2(30) := 'PROCESS_SERVICE_REQUEST';
155         l_api_version CONSTANT NUMBER := 1.0;
156         l_msg_count           NUMBER;
157         l_msg_data            VARCHAR2(2000);
158         l_msg_index           NUMBER;
159         r_service_request_rec Cs_Servicerequest_Pub.service_request_rec_type;
160         t_contacts_table      Cs_Servicerequest_Pub.contacts_table;
161         ln_interaction_id     NUMBER;
162         ln_workflow_id        NUMBER;
163         ln_individual_owner   NUMBER;
164         ln_group_owner        NUMBER;
165         ln_individual_type    VARCHAR2(100);
166 
167         CURSOR c_party_site_id(p_party_site_use_id IN NUMBER) IS
168             SELECT party_site_id
169               FROM hz_party_site_uses
170              WHERE party_site_use_id = p_party_site_use_id;
171 
172         CURSOR c_party_id(p_party_site_id IN NUMBER) IS
173             SELECT party_id
174               FROM hz_party_sites
175              WHERE party_site_id = p_party_site_id;
176 
177     BEGIN
178         -- Standard Start of API savepoint
179         SAVEPOINT process_service_request;
180 
181         -- Standard call to check for call compatibility.
182         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
183                                            p_api_version,
184                                            l_api_name,
185                                            G_PKG_NAME)
186         THEN
187             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
188         END IF;
189 
190         -- Initialize message list if p_init_msg_list is set to TRUE.
191         IF Fnd_Api.to_Boolean(p_init_msg_list)
192         THEN
193             Fnd_Msg_Pub.initialize;
194         END IF;
195 
196         -- Initialize API return status to success
197         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
198 
199         IF (g_debug > 5)
200         THEN
201             Csd_Gen_Utility_Pvt.ADD('dump_sr_rec');
202             Csd_Gen_Utility_Pvt.dump_sr_rec(p_sr_rec => p_service_request_rec);
203         END IF;
204 
205         -- Assign the SR rec values
206         Cs_Servicerequest_Pub.initialize_rec(r_service_request_rec);
207         r_service_request_rec.request_date  := p_service_request_rec.request_date;
208         r_service_request_rec.type_id       := p_service_request_rec.type_id;
209         r_service_request_rec.type_name     := p_service_request_rec.type_name;
210         r_service_request_rec.status_id     := p_service_request_rec.status_id;
211         r_service_request_rec.status_name   := p_service_request_rec.status_name;
212         r_service_request_rec.severity_id   := p_service_request_rec.severity_id;
213         r_service_request_rec.severity_name := p_service_request_rec.severity_name;
214         r_service_request_rec.urgency_id    := p_service_request_rec.urgency_id;
215         r_service_request_rec.urgency_name  := p_service_request_rec.urgency_name;
216         r_service_request_rec.closed_date   := p_service_request_rec.closed_date;
217         r_service_request_rec.owner_id      := p_service_request_rec.owner_id;
218 
219         -- swai: 02-07-03
220         -- do not pass owner_group_id since group_type is not available
221         -- passing owner_group_id without group_type may cause SR validation
222         -- errors
223         -- r_service_request_rec.owner_group_id        := p_service_request_rec.owner_group_id;
224         r_service_request_rec.publish_flag             := p_service_request_rec.publish_flag;
225         r_service_request_rec.summary                  := p_service_request_rec.summary;
226         r_service_request_rec.caller_type              := p_service_request_rec.caller_type;
227         r_service_request_rec.customer_id              := p_service_request_rec.customer_id;
228         r_service_request_rec.customer_number          := p_service_request_rec.customer_number;
229         r_service_request_rec.employee_id              := p_service_request_rec.employee_id;
230         r_service_request_rec.employee_number          := p_service_request_rec.employee_number;
231         r_service_request_rec.customer_product_id      := p_service_request_rec.customer_product_id;
232         r_service_request_rec.cp_ref_number            := p_service_request_rec.cp_ref_number;
233         r_service_request_rec.inventory_item_id        := p_service_request_rec.inventory_item_id;
234         r_service_request_rec.inventory_org_id         := p_service_request_rec.inventory_org_id;
235         r_service_request_rec.current_serial_number    := p_service_request_rec.current_serial_number;
236         r_service_request_rec.original_order_number    := p_service_request_rec.original_order_number;
237         r_service_request_rec.purchase_order_num       := p_service_request_rec.purchase_order_num;
238         r_service_request_rec.problem_code             := p_service_request_rec.problem_code;
239         r_service_request_rec.exp_resolution_date      := p_service_request_rec.exp_resolution_date;
240         r_service_request_rec.bill_to_site_use_id      := p_service_request_rec.bill_to_site_use_id;
241         r_service_request_rec.ship_to_site_use_id      := p_service_request_rec.ship_to_site_use_id;
242         r_service_request_rec.contract_id              := p_service_request_rec.contract_id;
243         r_service_request_rec.account_id               := p_service_request_rec.account_id;
244         r_service_request_rec.resource_type            := p_service_request_rec.resource_type;
245         r_service_request_rec.cust_po_number           := p_service_request_rec.cust_po_number;
246         r_service_request_rec.cp_revision_id           := p_service_request_rec.cp_revision_id;
247         r_service_request_rec.inv_item_revision        := p_service_request_rec.inv_item_revision;
248         r_service_request_rec.sr_creation_channel      := p_service_request_rec.sr_creation_channel;
249         r_service_request_rec.creation_program_code    := 'CSD_REPAIR_ORDER_FORM';
250         r_service_request_rec.last_update_program_code := 'CSD_REPAIR_ORDER_FORM';
251         r_service_request_rec.group_type               := 'RS_GROUP';
252 
253        /*Fixed for bug#5589395
254 	    Pass the DFF value to Service API.
255 	  */
256         r_service_request_rec.external_context        := p_service_request_rec.external_context;
257         r_service_request_rec.external_attribute_1    := p_service_request_rec.external_attribute_1;
258         r_service_request_rec.external_attribute_2    := p_service_request_rec.external_attribute_2;
259         r_service_request_rec.external_attribute_3    := p_service_request_rec.external_attribute_3;
260         r_service_request_rec.external_attribute_4    := p_service_request_rec.external_attribute_4;
261         r_service_request_rec.external_attribute_5    := p_service_request_rec.external_attribute_5;
262         r_service_request_rec.external_attribute_6    := p_service_request_rec.external_attribute_6;
263         r_service_request_rec.external_attribute_7    := p_service_request_rec.external_attribute_7;
264         r_service_request_rec.external_attribute_8    := p_service_request_rec.external_attribute_8;
265         r_service_request_rec.external_attribute_9    := p_service_request_rec.external_attribute_9;
266         r_service_request_rec.external_attribute_10   := p_service_request_rec.external_attribute_10;
267         r_service_request_rec.external_attribute_11   := p_service_request_rec.external_attribute_11;
268         r_service_request_rec.external_attribute_12   := p_service_request_rec.external_attribute_12;
269         r_service_request_rec.external_attribute_13   := p_service_request_rec.external_attribute_13;
270         r_service_request_rec.external_attribute_14   := p_service_request_rec.external_attribute_14;
271         r_service_request_rec.external_attribute_15   := p_service_request_rec.external_attribute_15;
272 
273 
274         -- Contacts
275         -- swai - forward port bug 2767101
276         -- Do not set the contact record if no contact was specified.
277         -- setting these fields to null may cause SR API to fail
278         IF (p_service_request_rec.party_id IS NOT NULL)
279         THEN
280             t_contacts_table(1).sr_contact_point_id := p_service_request_rec.sr_contact_point_id;
281             t_contacts_table(1).party_id            := p_service_request_rec.party_id;
282             t_contacts_table(1).contact_type        := p_service_request_rec.contact_type;
283             t_contacts_table(1).contact_point_id    := p_service_request_rec.contact_point_id;
284             t_contacts_table(1).contact_point_type  := p_service_request_rec.contact_point_type;
285             t_contacts_table(1).primary_flag        := p_service_request_rec.primary_flag;
286         END IF;
287 
288         Csd_Gen_Utility_Pvt.ADD('GETTING BILL-TO FIELDS');
289         -- Bill-To fields
290         IF (NVL(p_service_request_rec.bill_to_site_use_id,
291                 Fnd_Api.G_MISS_NUM) <> Fnd_Api.G_MISS_NUM)
292         THEN
293             OPEN c_party_site_id(p_service_request_rec.bill_to_site_use_id);
294             FETCH c_party_site_id
295                 INTO r_service_request_rec.bill_to_site_id;
296             CLOSE c_party_site_id;
297             Csd_Gen_Utility_Pvt.ADD('r_service_request_rec.bill_to_site_id ' ||
298                                     r_service_request_rec.bill_to_site_id);
299             IF (NVL(r_service_request_rec.bill_to_site_id,
300                     Fnd_Api.G_MISS_NUM) <> Fnd_Api.G_MISS_NUM)
301             THEN
302                 OPEN c_party_id(r_service_request_rec.bill_to_site_id);
303                 FETCH c_party_id
304                     INTO r_service_request_rec.bill_to_party_id;
305                 CLOSE c_party_id;
306                 Csd_Gen_Utility_Pvt.ADD('r_service_request_rec.bill_to_party_id ' ||
307                                         r_service_request_rec.bill_to_party_id);
308             END IF;
309         END IF;
310 
311         -- Ship-To fields
312         Csd_Gen_Utility_Pvt.ADD('GETTING SHIP-TO FIELDS');
313         IF (NVL(p_service_request_rec.ship_to_site_use_id,
314                 Fnd_Api.G_MISS_NUM) <> Fnd_Api.G_MISS_NUM)
315         THEN
316             OPEN c_party_site_id(p_service_request_rec.ship_to_site_use_id);
317             FETCH c_party_site_id
318                 INTO r_service_request_rec.ship_to_site_id;
319             CLOSE c_party_site_id;
320             Csd_Gen_Utility_Pvt.ADD('r_service_request_rec.ship_to_site_id ' ||
321                                     r_service_request_rec.ship_to_site_id);
322             IF (NVL(r_service_request_rec.ship_to_site_id,
323                     Fnd_Api.G_MISS_NUM) <> Fnd_Api.G_MISS_NUM)
324             THEN
325                 OPEN c_party_id(r_service_request_rec.ship_to_site_id);
326                 FETCH c_party_id
327                     INTO r_service_request_rec.ship_to_party_id;
328                 CLOSE c_party_id;
329                 Csd_Gen_Utility_Pvt.ADD('r_service_request_rec.ship_to_party_id ' ||
330                                         r_service_request_rec.ship_to_party_id);
331             END IF;
332         END IF;
333 
334         -- Call to Service Request API
335         IF (UPPER(p_action) = 'CREATE')
336         THEN
337             Cs_Servicerequest_Pub.Create_ServiceRequest(p_api_version         => 3.0,
338                                                         p_init_msg_list       => Fnd_Api.G_FALSE,
339                                                         p_commit              => Fnd_Api.G_FALSE,
340                                                         x_return_status       => x_return_status,
341                                                         x_msg_count           => x_msg_count,
342                                                         x_msg_data            => x_msg_data,
343                                                         p_resp_appl_id        => NULL,
344                                                         p_resp_id             => NULL,
345                                                         p_user_id             => Fnd_Global.user_id,
346                                                         p_login_id            => Fnd_Global.conc_login_id,
347                                                         p_org_id              => NULL,
348                                                         p_request_id          => p_incident_id,
349                                                         p_request_number      => p_service_request_rec.incident_number, -- swai: FP 5157216,
350                                                         p_service_request_rec => r_service_request_rec,
351                                                         p_notes               => p_notes_tbl,
352                                                         p_contacts            => t_contacts_table,
353                                                         x_request_id          => x_incident_id,
354                                                         x_request_number      => x_incident_number,
355                                                         x_interaction_id      => ln_interaction_id,
356                                                         x_workflow_process_id => ln_workflow_id,
357                                                         x_individual_owner    => ln_individual_owner,
358                                                         x_group_owner         => ln_group_owner,
359                                                         x_individual_type     => ln_individual_type);
360 
361         END IF;
362 
363         -- Api body ends here
364 
365         -- Standard check of p_commit.
366         IF Fnd_Api.To_Boolean(p_commit)
367         THEN
368             COMMIT WORK;
369         END IF;
370 
371         -- Standard call to get message count and IF count is  get message info.
372         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
373                                   p_data  => x_msg_data);
374     EXCEPTION
375         WHEN Fnd_Api.G_EXC_ERROR THEN
376             ROLLBACK TO process_service_request;
377             x_return_status := Fnd_Api.G_RET_STS_ERROR;
378             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
379                                       p_data  => x_msg_data);
380         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
381             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
382             ROLLBACK TO process_service_request;
383             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
384                                       p_data  => x_msg_data);
385         WHEN OTHERS THEN
386             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
387             ROLLBACK TO process_service_request;
388             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
389             THEN
390                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
391             END IF;
392             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
393                                       p_data  => x_msg_data);
394     END process_service_request;
395 
396     /*--------------------------------------------------*/
397     /* procedure name: process_charge_lines             */
398     /* description   : procedure used to create/update  */
399     /*                 delete charge lines              */
400     /*                                                  */
401     /*--------------------------------------------------*/
402 
403     PROCEDURE process_charge_lines(p_api_version        IN NUMBER,
404                                    p_commit             IN VARCHAR2 := Fnd_Api.g_false,
405                                    p_init_msg_list      IN VARCHAR2 := Fnd_Api.g_false,
406                                    p_validation_level   IN NUMBER := Fnd_Api.g_valid_level_full,
407                                    p_action             IN VARCHAR2,
408                                    p_Charges_Rec        IN Cs_Charge_Details_Pub.Charges_Rec_Type,
409                                    x_estimate_detail_id OUT NOCOPY NUMBER,
410                                    x_return_status      OUT NOCOPY VARCHAR2,
411                                    x_msg_count          OUT NOCOPY NUMBER,
412                                    x_msg_data           OUT NOCOPY VARCHAR2) IS
413         l_api_name    CONSTANT VARCHAR2(30) := 'PROCESS_CHARGE_LINES';
414         l_api_version CONSTANT NUMBER := 1.0;
415         l_msg_count             NUMBER;
416         l_msg_data              VARCHAR2(2000);
417         l_msg_index             NUMBER;
418         l_estimate_detail_id    NUMBER;
419         l_charges_rec           Cs_Charge_Details_Pub.Charges_Rec_Type;
420         x_object_version_number NUMBER;
421         x_line_number           NUMBER;
422 
423         -- Variables used in FND Log
424         l_error_level NUMBER := Fnd_Log.LEVEL_ERROR;
425         l_mod_name    VARCHAR2(2000) := 'csd.plsql.csd_process_pvt.process_charge_lines';
426 
427     BEGIN
428         Debug('At the Beginning of process_charge_lines', l_mod_name, 1);
429 
430         -- Standard Start of API savepoint
431         SAVEPOINT process_charge_lines;
432 
433         -- Standard call to check for call compatibility.
434         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
435                                            p_api_version,
436                                            l_api_name,
437                                            G_PKG_NAME)
438         THEN
439             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
440         END IF;
441 
442         -- Initialize message list if p_init_msg_list is set to TRUE.
443         IF Fnd_Api.to_Boolean(p_init_msg_list)
444         THEN
445             Fnd_Msg_Pub.initialize;
446         END IF;
447 
448         -- Initialize API return status to success
449         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
450 
451         -- Api body starts
452 
453         Debug('Validate the action', l_mod_name, 1);
454 
455         -- Validate the action code
456         IF NOT (Csd_Process_Util.VALIDATE_ACTION(p_action, l_api_name))
457         THEN
458             RAISE Fnd_Api.G_EXC_ERROR;
459         END IF;
460 
461         l_charges_rec := p_charges_rec;
462 
463         /* Fixed for forward port bug#4214359.
464            Whenever we pass the invoice_to_org_id corresponding bill_to_party_id should be passed
465            otherwise charges API will validate the bill_to_org_id against the party_id at
466            Service Request level and it would error out if the bill to address selected at product
467            line level is of related party.
468         */
469         IF (l_Charges_Rec.invoice_to_org_id IS NOT NULL AND
470            l_Charges_Rec.invoice_to_org_id <> Fnd_Api.G_MISS_NUM)
471         THEN
472             BEGIN
473                 SELECT party_id
474                   INTO l_Charges_Rec.bill_to_party_id
475                   FROM hz_party_sites
476                  WHERE party_site_id = l_Charges_Rec.invoice_to_org_id;
477             EXCEPTION
478                 WHEN NO_DATA_FOUND THEN
479                     debug('No Bill to Party Id', l_mod_name, 1);
480                     RAISE Fnd_Api.G_EXC_ERROR;
481                 WHEN TOO_MANY_ROWS THEN
482                     debug('Too many Bill to Party Id', l_mod_name, 1);
483                     RAISE Fnd_Api.G_EXC_ERROR;
484             END;
485         END IF;
486 
487         /* Fixed for forward port bug#4214359.
488            Whenever we pass the ship_to_org_id corresponding ship_to_party_id should be passed
489            otherwise charges API will validate the ship_to_org_id against the party_id at
490            Service Request level and it would error out if the ship to address selected at product
491            line level is of related party.
492         */
493         IF (l_Charges_Rec.ship_to_org_id IS NOT NULL AND
494            l_Charges_Rec.ship_to_org_id <> Fnd_Api.G_MISS_NUM)
495         THEN
496             BEGIN
497                 SELECT party_id
498                   INTO l_Charges_Rec.ship_to_party_id
499                   FROM hz_party_sites
500                  WHERE party_site_id = l_Charges_Rec.ship_to_org_id;
501             EXCEPTION
502                 WHEN NO_DATA_FOUND THEN
503                     debug('No Ship to Party Id', l_mod_name, 1);
504                     RAISE Fnd_Api.G_EXC_ERROR;
505                 WHEN TOO_MANY_ROWS THEN
506                     debug('Too many Ship to Party Id', l_mod_name, 1);
507                     RAISE Fnd_Api.G_EXC_ERROR;
508             END;
509         END IF;
510 
511         -- Based on the action, call the respective charges public api to
512         -- to create/update/delete the charge lines.
513         IF p_action = 'CREATE'
514         THEN
515 
516             Debug('Creating the charge lines ', l_mod_name, 1);
517             Debug('l_charges_rec.transaction_type_id :' ||
518                   TO_CHAR(l_charges_rec.transaction_type_id),
519                   l_mod_name,
520                   1);
521 
522             Cs_Charge_Details_Pub.Create_Charge_Details(p_api_version           => p_api_version,
523                                                         p_init_msg_list         => p_init_msg_list,
524                                                         p_commit                => p_commit,
525                                                         p_validation_level      => p_validation_level,
526                                                         p_transaction_control   => Fnd_Api.G_TRUE,
527                                                         p_Charges_Rec           => l_charges_rec,
528                                                         x_object_version_number => x_object_version_number,
529                                                         x_estimate_detail_id    => x_estimate_detail_id,
530                                                         x_line_number           => x_line_number,
531                                                         x_return_status         => x_return_status,
532                                                         x_msg_count             => x_msg_count,
533                                                         x_msg_data              => x_msg_data);
534 
535             Debug('Return Status from Create_Charge_Details' ||
536                   x_return_status,
537                   l_mod_name,
538                   1);
539 
540             IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
541             THEN
542                 Debug('Create_Charge_Details failed ', l_mod_name, 1);
543                 RAISE Fnd_Api.G_EXC_ERROR;
544             END IF;
545 
546         ELSIF p_action = 'UPDATE'
547         THEN
548 
549             Debug('Creating the charge lines ', l_mod_name, 1);
550             Debug('Estimate Detail Id = ' ||
551                   l_Charges_Rec.estimate_detail_id,
552                   l_mod_name,
553                   1);
554             Debug('l_Charges_Rec.business_process_id=' ||
555                   l_Charges_Rec.business_process_id,
556                   l_mod_name,
557                   1);
558 
559             IF ((NVL(l_Charges_Rec.business_process_id, Fnd_Api.G_MISS_NUM) =
560                Fnd_Api.G_MISS_NUM) AND
561                l_Charges_Rec.estimate_detail_id IS NOT NULL)
562             THEN
563                 BEGIN
564                     SELECT business_process_id
565                       INTO l_Charges_Rec.business_process_id
566                       FROM cs_estimate_details
567                      WHERE estimate_detail_id =
568                            l_Charges_Rec.estimate_detail_id;
569                 EXCEPTION
570                     WHEN NO_DATA_FOUND THEN
571                         Debug('No Business business_process_id',
572                               l_mod_name,
573                               1);
574                         RAISE Fnd_Api.G_EXC_ERROR;
575                     WHEN TOO_MANY_ROWS THEN
576                         Debug('Too many business_process_id',
577                               l_mod_name,
578                               1);
579                         RAISE Fnd_Api.G_EXC_ERROR;
580                 END;
581             END IF;
582 
583             Debug('l_Charges_Rec.business_process_id=' ||
584                   l_Charges_Rec.business_process_id,
585                   l_mod_name,
586                   1);
587 
588             Cs_Charge_Details_Pub.Update_Charge_Details(p_api_version           => p_api_version,
589                                                         p_init_msg_list         => p_init_msg_list,
590                                                         p_commit                => p_commit,
591                                                         p_validation_level      => p_validation_level,
592                                                         p_transaction_control   => Fnd_Api.G_TRUE,
593                                                         p_Charges_Rec           => l_Charges_Rec,
594                                                         x_object_version_number => x_object_version_number,
595                                                         x_return_status         => x_return_status,
596                                                         x_msg_count             => x_msg_count,
597                                                         x_msg_data              => x_msg_data);
598 
599             Debug('Return Status from Update_Charge_Details' ||
600                   x_return_status,
601                   l_mod_name,
602                   1);
603 
604             IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
605             THEN
606                 Debug('update_charge_details failed', l_mod_name, 1);
607                 RAISE Fnd_Api.G_EXC_ERROR;
608             END IF;
609 
610         ELSIF p_action = 'DELETE'
611         THEN
612 
613             Debug('l_estimate_detail_id =' || l_estimate_detail_id,
614                   l_mod_name,
615                   1);
616             Debug('Deleting the charge lines ', l_mod_name, 1);
617 
618             l_estimate_detail_id := l_charges_rec.estimate_detail_id;
619 
620             Cs_Charge_Details_Pub.Delete_Charge_Details(p_api_version         => p_api_version,
621                                                         p_init_msg_list       => p_init_msg_list,
622                                                         p_commit              => p_commit,
623                                                         p_validation_level    => p_validation_level,
624                                                         p_transaction_control => Fnd_Api.G_TRUE,
625                                                         p_estimate_detail_id  => l_estimate_detail_id,
626                                                         x_return_status       => x_return_status,
627                                                         x_msg_count           => x_msg_count,
628                                                         x_msg_data            => x_msg_data);
629 
630             Debug('Return Status from Delete_Charge_Details' ||
631                   x_return_status,
632                   l_mod_name,
633                   1);
634 
635             IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
636             THEN
637                 Debug('Delete_Charge_Details failed ', l_mod_name, 1);
638                 RAISE Fnd_Api.G_EXC_ERROR;
639             END IF;
640         END IF;
641 
642         -- Api body ends here
643 
644         -- Standard check of p_commit.
645         IF Fnd_Api.To_Boolean(p_commit)
646         THEN
647             COMMIT WORK;
648         END IF;
649 
650         -- Standard call to get message count and IF count is  get message info.
651         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
652                                   p_data  => x_msg_data);
653     EXCEPTION
654         WHEN Fnd_Api.G_EXC_ERROR THEN
655             ROLLBACK TO process_charge_lines;
656             x_return_status := Fnd_Api.G_RET_STS_ERROR;
657             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
658                                       p_data  => x_msg_data);
659         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
660             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
661             ROLLBACK TO process_charge_lines;
662             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
663                                       p_data  => x_msg_data);
664         WHEN OTHERS THEN
665             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
666             ROLLBACK TO process_charge_lines;
667             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
668             THEN
669                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
670             END IF;
671             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
672                                       p_data  => x_msg_data);
673     END process_charge_lines;
674 
675     /*--------------------------------------------------*/
676     /* procedure name: apply_contract                   */
677     /* description   : procedure used to apply contract */
678     /*                                                  */
679     /*--------------------------------------------------*/
680 
681     PROCEDURE apply_contract(p_api_version      IN NUMBER,
682                              p_commit           IN VARCHAR2 := Fnd_Api.g_false,
683                              p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
684                              p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
685                              p_incident_id      IN NUMBER,
686                              x_return_status    OUT NOCOPY VARCHAR2,
687                              x_msg_count        OUT NOCOPY NUMBER,
688                              x_msg_data         OUT NOCOPY VARCHAR2) IS
689 
690         l_api_name    CONSTANT VARCHAR2(30) := 'APPLY_CONTRACT';
691         l_api_version CONSTANT NUMBER := 1.0;
692         l_msg_count NUMBER;
693         l_msg_data  VARCHAR2(2000);
694         l_msg_index NUMBER;
695 
696     BEGIN
697         -- Standard Start of API savepoint
698         SAVEPOINT apply_contract;
699 
700         -- Standard call to check for call compatibility.
701         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
702                                            p_api_version,
703                                            l_api_name,
704                                            G_PKG_NAME)
705         THEN
706             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
707         END IF;
708 
709         -- Initialize message list if p_init_msg_list is set to TRUE.
710         IF Fnd_Api.to_Boolean(p_init_msg_list)
711         THEN
712             Fnd_Msg_Pub.initialize;
713         END IF;
714 
715         -- Initialize API return status to success
716         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
717 
718         -- Api body starts
719         IF (g_debug > 0)
720         THEN
721             Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
722                                               p_api_name => l_api_name);
723         END IF;
724 
725         IF (g_debug > 0)
726         THEN
727             Csd_Gen_Utility_Pvt.ADD('Validate the incident id');
728             Csd_Gen_Utility_Pvt.ADD('p_incident_id  =' || p_incident_id);
729         END IF;
730 
731         IF NOT (Csd_Process_Util.VALIDATE_INCIDENT_ID(p_incident_id))
732         THEN
733             RAISE Fnd_Api.G_EXC_ERROR;
734         END IF;
735 
736         IF (g_debug > 0)
737         THEN
738             Csd_Gen_Utility_Pvt.ADD('Applying contract on charge lines');
739         END IF;
740 
741         -- Commented
742         -- signature change to be discussed.
743         --       CS_EST_APPLY_CONTRACT_PKG.APPLY_CONTRACT
744         --                  (p_incident_id    =>   p_incident_id ) ;
745 
746         -- Api body ends here
747 
748         -- Standard check of p_commit.
749         IF Fnd_Api.To_Boolean(p_commit)
750         THEN
751             COMMIT WORK;
752         END IF;
753 
754         -- Standard call to get message count and IF count is  get message info.
755         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
756                                   p_data  => x_msg_data);
757     EXCEPTION
758         WHEN Fnd_Api.G_EXC_ERROR THEN
759             ROLLBACK TO apply_contract;
760             x_return_status := Fnd_Api.G_RET_STS_ERROR;
761             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
762                                       p_data  => x_msg_data);
763         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
764             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
765             ROLLBACK TO apply_contract;
766             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
767                                       p_data  => x_msg_data);
768         WHEN OTHERS THEN
769             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
770             ROLLBACK TO apply_contract;
771             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
772             THEN
773                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
774             END IF;
775             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
776                                       p_data  => x_msg_data);
777     END apply_contract;
778 
779     /*--------------------------------------------------*/
780     /* procedure name: ship_sales_order                 */
781     /* description   : procedure used to ship           */
782     /*                 sales Order                      */
783     /*                                                  */
784     /*--------------------------------------------------*/
785 
786     PROCEDURE ship_sales_order(p_api_version      IN NUMBER,
787                                p_commit           IN VARCHAR2 := Fnd_Api.g_false,
788                                p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
789                                p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
790                                p_delivery_id      IN OUT NOCOPY NUMBER,
791                                x_return_status    OUT NOCOPY VARCHAR2,
792                                x_msg_count        OUT NOCOPY NUMBER,
793                                x_msg_data         OUT NOCOPY VARCHAR2) IS
794         l_api_name    CONSTANT VARCHAR2(30) := 'SHIP_SALES_ORDER';
795         l_api_version CONSTANT NUMBER := 1.0;
796         l_msg_count          NUMBER;
797         l_msg_data           VARCHAR2(2000);
798         l_msg_index          NUMBER;
799         l_dummy              VARCHAR2(1);
800         l_header_rec         Aso_Quote_Pub.Qte_Header_Rec_Type;
801         l_line_tbl           Aso_Quote_Pub.Qte_Line_Tbl_Type;
802         l_Line_dtl_tbl       Aso_Quote_Pub.Qte_Line_Dtl_Tbl_Type;
803         l_hd_shipment_rec    Aso_Quote_Pub.Shipment_rec_Type;
804         l_hd_shipment_tbl    Aso_Quote_Pub.Shipment_tbl_Type;
805         l_ln_shipment_tbl    Aso_Quote_Pub.Shipment_Tbl_Type;
806         l_hd_payment_tbl     Aso_Quote_Pub.Payment_Tbl_Type; -- added by cnemalik
807         l_line_price_adj_tbl Aso_Quote_Pub.Price_Adj_Tbl_Type;
808         x_order_header_rec   Aso_Order_Int.Order_Header_rec_type;
809         x_order_line_tbl     Aso_Order_Int.Order_Line_tbl_type;
810         x_order_header_id    NUMBER;
811         l_control_rec        Aso_Order_Int.control_rec_type;
812         -- Following two variables are defined to fix bug 3437177
813         l_Serial_number_control_code NUMBER;
814         C_SRL_NUM_Cnt_Code_SO_ISSUE CONSTANT NUMBER := 6;
815 
816         -- Parameters for WSH_DELIVERIES_PUB.Delivery_Action.
817         --p_delivery_id   NUMBER;
818         p_action_code             VARCHAR2(15);
819         p_delivery_name           VARCHAR2(30);
820         p_asg_trip_id             NUMBER;
821         p_asg_trip_name           VARCHAR2(30);
822         p_asg_pickup_stop_id      NUMBER;
823         p_asg_pickup_loc_id       NUMBER;
824         p_asg_pickup_loc_code     VARCHAR2(30);
825         p_asg_pickup_arr_date     DATE;
826         p_asg_pickup_dep_date     DATE;
827         p_asg_dropoff_stop_id     NUMBER;
828         p_asg_dropoff_loc_id      NUMBER;
829         p_asg_dropoff_loc_code    VARCHAR2(30);
830         p_asg_dropoff_arr_date    DATE;
831         p_asg_dropoff_dep_date    DATE;
832         p_sc_action_flag          VARCHAR2(10);
833         p_sc_intransit_flag       VARCHAR2(10);
834         p_sc_close_trip_flag      VARCHAR2(10);
835         p_sc_create_bol_flag      VARCHAR2(10);
836         p_sc_stage_del_flag       VARCHAR2(10);
837         p_sc_trip_ship_method     VARCHAR2(30);
838         p_sc_actual_dep_date      VARCHAR2(30);
839         p_sc_defer_interface_flag VARCHAR2(1);
840         p_sc_report_set_id        NUMBER;
841         p_sc_report_set_name      VARCHAR2(60);
842         p_wv_override_flag        VARCHAR2(10);
843         x_trip_id                 VARCHAR2(30);
844         x_trip_name               VARCHAR2(30);
845         x_msg_details             VARCHAR2(3000);
846         x_msg_summary             VARCHAR2(3000);
847         l_customer_id             NUMBER := NULL;
848         l_order_type_id           NUMBER := NULL;
849         l_document_set_id         NUMBER := NULL;
850         l_sub_inventory           VARCHAR2(30) := '';
851 
852         --Parameters for WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes.
853         source_code        VARCHAR2(15);
854         changed_attributes Wsh_Delivery_Details_Pub.ChangedAttributeTabType;
855 
856         /* Handle exceptions */
857         fail_api EXCEPTION;
858         -- Added Mtl_Sytem_items_B to get serial_number_control_Code for the item that is being
859         -- shipped. This is to fix bug 3437177 saupadhy
860         -- Added condition that release status should be 'Y' which 'Staged/Pick Confirmed'
861 
862         CURSOR delivery(p_del_id IN NUMBER) IS
863             SELECT cr.serial_number,
864                    wdd.delivery_detail_id,
865                    wdd.requested_quantity,
866                    mtl.serial_number_control_code
867               FROM csd_repairs              cr,
868                    mtl_system_items_b       mtl,
869                    cs_estimate_details      ced,
870                    wsh_delivery_details     wdd,
871 			    --Changed to view from table, bug:  4341784
872                    wsh_delivery_assignments_v wda
873              WHERE cr.repair_line_id = ced.original_source_id
874                AND ced.original_source_code = 'DR'
875                AND ced.order_line_id = wdd.source_line_id
876 	       AND  wdd.SOURCE_CODE = 'OE' /*Fixed for bug#5846054*/
877                AND wdd.delivery_detail_id = wda.delivery_detail_id
878                AND wdd.released_status = 'Y'
879                AND wda.delivery_id = p_del_id
880                AND wdd.inventory_item_id = mtl.inventory_item_id
881                AND wdd.ship_from_location_id = mtl.organization_id;
882 
883     BEGIN
884         -- Standard Start of API savepoint
885         SAVEPOINT ship_sales_order;
886 
887         -- Standard call to check for call compatibility.
888         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
889                                            p_api_version,
890                                            l_api_name,
891                                            G_PKG_NAME)
892         THEN
893             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
894         END IF;
895 
896         -- Initialize message list if p_init_msg_list is set to TRUE.
897         IF Fnd_Api.to_Boolean(p_init_msg_list)
898         THEN
899             Fnd_Msg_Pub.initialize;
900         END IF;
901 
902         -- Initialize API return status to success
903         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
904 
905         -- Api body starts
906 
907         -- dbms_application_info.set_client_info('204');
908         -- fnd_global.apps_initialize(1000200,52284,512,0);
909 
910         IF (g_debug > 0)
911         THEN
912             Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
913                                               p_api_name => l_api_name);
914         END IF;
915         -- If action is SHIP, then call shipping api to
916         -- ship the sales order
917         IF (g_debug > 0)
918         THEN
919             Csd_Gen_Utility_Pvt.ADD('Shipping the Sales Order');
920             Csd_Gen_Utility_Pvt.ADD('p_delivery_id =' || p_delivery_id);
921         END IF;
922 
923         IF NVL(p_delivery_id, Fnd_Api.G_MISS_NUM) = Fnd_Api.G_MISS_NUM
924         THEN
925             Fnd_Message.SET_NAME('CSD', 'CSD_INV_DELIVERY_ID');
926             Fnd_Message.SET_TOKEN('DELIVERY_ID', p_delivery_id);
927             Fnd_Msg_Pub.ADD;
928             IF (g_debug > 0)
929             THEN
930                 Csd_Gen_Utility_Pvt.ADD('Delivery_id is invalid');
931             END IF;
932             RAISE Fnd_Api.G_EXC_ERROR;
933         ELSE
934 
935             BEGIN
936                 SELECT '*'
937                   INTO l_dummy
938                   FROM wsh_new_deliveries
939                  WHERE delivery_id = p_delivery_id;
940             EXCEPTION
941                 WHEN NO_DATA_FOUND THEN
942                     Fnd_Message.SET_NAME('CSD', 'CSD_INV_DELIVERY_ID');
943                     Fnd_Message.SET_TOKEN('DELIVERY_ID', p_delivery_id);
944                     Fnd_Msg_Pub.ADD;
945                     IF (g_debug > 0)
946                     THEN
947                         Csd_Gen_Utility_Pvt.ADD('Delivery_id is invalid');
948                     END IF;
949                     RAISE Fnd_Api.G_EXC_ERROR;
950             END;
951         END IF;
952 
953         FOR i IN delivery(p_delivery_id)
954         LOOP
955 
956             -- In case of serial controlled at SO issue item, update the serial number on the
957             -- delivery line details
958             -- This change was made to fix bug 3437177
959 
960             -- IF NVL(i.serial_number, FND_API.G_MISS_CHAR) <> FND_API.G_MISS_CHAR THEN
961             IF i.Serial_number_control_code = C_SRL_NUM_Cnt_Code_SO_ISSUE AND
962                NVL(i.serial_number, Fnd_Api.G_MISS_CHAR) <>
963                Fnd_Api.G_MISS_CHAR
964             THEN
965                 BEGIN
966                     source_code := 'OE'; -- The only source code that should be used by the API
967                     changed_attributes(1).delivery_detail_id := i.delivery_detail_id;
968                     changed_attributes(1).serial_number := i.serial_number;
969                     changed_attributes(1).shipped_quantity := i.requested_quantity;
970                     IF (g_debug > 0)
971                     THEN
972                         Csd_Gen_Utility_Pvt.ADD('delivery_detail_id =' ||
973                                                 changed_attributes(1)
974                                                 .delivery_detail_id);
975                         Csd_Gen_Utility_Pvt.ADD('serial_number      =' ||
976                                                 changed_attributes(1)
977                                                 .serial_number);
978                         Csd_Gen_Utility_Pvt.ADD('shipped_quantity   =' ||
979                                                 changed_attributes(1)
980                                                 .shipped_quantity);
981                         Csd_Gen_Utility_Pvt.ADD('Calling Update_Shipping_Attributes');
982                     END IF;
983                     --Call to WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes.
984                     Wsh_Delivery_Details_Pub.Update_Shipping_Attributes(p_api_version_number => 1.0,
985                                                                         p_init_msg_list      => p_init_msg_list,
986                                                                         p_commit             => p_commit,
987                                                                         x_return_status      => x_return_status,
988                                                                         x_msg_count          => x_msg_count,
989                                                                         x_msg_data           => x_msg_data,
990                                                                         p_changed_attributes => changed_attributes,
991                                                                         p_source_code        => source_code);
992                     IF (g_debug > 0)
993                     THEN
994                         Csd_Gen_Utility_Pvt.ADD('x_return_status(Update_Shipping_Attributes )=' ||
995                                                 x_return_status);
996                     END IF;
997                     IF (x_return_status <> Wsh_Util_Core.G_RET_STS_SUCCESS)
998                     THEN
999                         IF (g_debug > 0)
1000                         THEN
1001                             Csd_Gen_Utility_Pvt.ADD('Update_Shipping_Attributes failed');
1002                         END IF;
1003                         RAISE fail_api;
1004                     END IF;
1005                 EXCEPTION
1006                     WHEN fail_api THEN
1007                         Wsh_Util_Core.get_messages('Y',
1008                                                    x_msg_summary,
1009                                                    x_msg_details,
1010                                                    x_msg_count);
1011                         IF x_msg_count > 1
1012                         THEN
1013                             x_msg_data := x_msg_summary || x_msg_details;
1014                         ELSE
1015                             x_msg_data := x_msg_summary;
1016                         END IF;
1017                         IF (g_debug > 0)
1018                         THEN
1019                             Csd_Gen_Utility_Pvt.ADD('Error Msg from Update_Shipping_Attributes');
1020                             Csd_Gen_Utility_Pvt.ADD('x_msg_data = ' ||
1021                                                     x_msg_data);
1022                         END IF;
1023                         Fnd_Message.SET_NAME('CSD',
1024                                              'CSD_UPDATE_SHIPPING_FAILED');
1025                         Fnd_Message.SET_TOKEN('ERR_MSG', x_msg_data);
1026                         Fnd_Msg_Pub.ADD;
1027                         RAISE Fnd_Api.G_EXC_ERROR;
1028                 END;
1029 
1030             END IF; --end of update_shipping_attributes
1031 
1032         END LOOP;
1033 
1034         BEGIN
1035 
1036             IF (g_debug > 0)
1037             THEN
1038                 Csd_Gen_Utility_Pvt.ADD('p_delivery_id=' || p_delivery_id);
1039             END IF;
1040 
1041             -- Values for Ship Confirming the delivery.
1042             p_action_code    := 'CONFIRM'; -- The action code for ship confirm
1043             p_delivery_id    := p_delivery_id; -- The delivery that needs to be confirmed
1044             p_delivery_name  := TO_CHAR(p_delivery_id); -- The delivery name,
1045             p_sc_action_flag := 'S'; -- Ship entered quantity.
1046             -- p_Sc_Intransit_flag needs to be set to 'Y' this as per bug 3676488 (Shipping)
1047             -- This fix for bug# 3665544
1048             p_sc_intransit_flag := 'Y'; -- In transit flag is set to 'Y' closes the
1049             -- pickup stop and sets the delivery in transit.
1050             p_sc_close_trip_flag := 'Y'; -- Close the trip after ship confirm
1051             --        p_sc_trip_ship_method := ''; -- The ship method code
1052             p_sc_defer_interface_flag := 'N'; -- defer interface
1053             --        p_sc_report_set_id    := 6; -- check if it is seeded
1054 
1055             IF (g_debug > 0)
1056             THEN
1057                 Csd_Gen_Utility_Pvt.ADD('Calling Delivery_Action ');
1058             END IF;
1059 
1060             -- Call to WSH_DELIVERIES_PUB.Delivery_Action.
1061             Wsh_Deliveries_Pub.Delivery_Action(p_api_version_number      => 1.0,
1062                                                p_init_msg_list           => p_init_msg_list,
1063                                                x_return_status           => x_return_status,
1064                                                x_msg_count               => x_msg_count,
1065                                                x_msg_data                => x_msg_data,
1066                                                p_action_code             => p_action_code,
1067                                                p_delivery_id             => p_delivery_id,
1068                                                p_delivery_name           => p_delivery_name,
1069                                                p_asg_trip_id             => p_asg_trip_id,
1070                                                p_asg_trip_name           => p_asg_trip_name,
1071                                                p_asg_pickup_stop_id      => p_asg_pickup_stop_id,
1072                                                p_asg_pickup_loc_id       => p_asg_pickup_loc_id,
1073                                                p_asg_pickup_loc_code     => p_asg_pickup_loc_code,
1074                                                p_asg_pickup_arr_date     => p_asg_pickup_arr_date,
1075                                                p_asg_pickup_dep_date     => p_asg_pickup_dep_date,
1076                                                p_asg_dropoff_stop_id     => p_asg_dropoff_stop_id,
1077                                                p_asg_dropoff_loc_id      => p_asg_dropoff_loc_id,
1078                                                p_asg_dropoff_loc_code    => p_asg_dropoff_loc_code,
1079                                                p_asg_dropoff_arr_date    => p_asg_dropoff_arr_date,
1080                                                p_asg_dropoff_dep_date    => p_asg_dropoff_dep_date,
1081                                                p_sc_action_flag          => p_sc_action_flag,
1082                                                p_sc_intransit_flag       => p_sc_intransit_flag,
1083                                                p_sc_close_trip_flag      => p_sc_close_trip_flag,
1084                                                p_sc_create_bol_flag      => p_sc_create_bol_flag,
1085                                                p_sc_stage_del_flag       => p_sc_stage_del_flag,
1086                                                p_sc_trip_ship_method     => p_sc_trip_ship_method,
1087                                                p_sc_actual_dep_date      => p_sc_actual_dep_date,
1088                                                p_sc_report_set_id        => p_sc_report_set_id,
1089                                                p_sc_report_set_name      => p_sc_report_set_name,
1090                                                p_sc_defer_interface_flag => p_sc_defer_interface_flag,
1091                                                p_wv_override_flag        => p_wv_override_flag,
1092                                                x_trip_id                 => x_trip_id,
1093                                                x_trip_name               => x_trip_name);
1094 
1095             IF (g_debug > 0)
1096             THEN
1097                 Csd_Gen_Utility_Pvt.ADD('x_return_status(Delivery_Action )=' ||
1098                                         x_return_status);
1099             END IF;
1100 
1101             IF (x_return_status <> Wsh_Util_Core.G_RET_STS_SUCCESS)
1102             THEN
1103                 IF (g_debug > 0)
1104                 THEN
1105                     Csd_Gen_Utility_Pvt.ADD('Delivery_Action failed');
1106                 END IF;
1107                 RAISE fail_api;
1108             END IF;
1109         EXCEPTION
1110             WHEN fail_api THEN
1111                 Wsh_Util_Core.get_messages('Y',
1112                                            x_msg_summary,
1113                                            x_msg_details,
1114                                            x_msg_count);
1115                 IF x_msg_count > 1
1116                 THEN
1117                     x_msg_data := x_msg_summary || x_msg_details;
1118                 ELSE
1119                     x_msg_data := x_msg_summary;
1120                 END IF;
1121                 IF (g_debug > 0)
1122                 THEN
1123                     Csd_Gen_Utility_Pvt.ADD('Error Msg from Delivery_Action');
1124                     Csd_Gen_Utility_Pvt.ADD('x_msg_data = ' || x_msg_data);
1125                 END IF;
1126 
1127                 -- Ignore if it is a warning
1128                 IF (x_return_status <> Wsh_Util_Core.G_RET_STS_WARNING)
1129                 THEN
1130                     Fnd_Message.SET_NAME('CSD', 'CSD_SHIP_CONFIRM_FAILED');
1131                     Fnd_Message.SET_TOKEN('ERR_MSG', x_msg_data);
1132                     Fnd_Msg_Pub.ADD;
1133                     RAISE Fnd_Api.G_EXC_ERROR;
1134                 END IF;
1135 
1136         END; -- end of delivery action
1137 
1138         -- Api body ends here
1139 
1140         -- Standard check of p_commit.
1141         IF Fnd_Api.To_Boolean(p_commit)
1142         THEN
1143             COMMIT WORK;
1144         END IF;
1145 
1146         -- Standard call to get message count and IF count is  get message info.
1147         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1148                                   p_data  => x_msg_data);
1149 
1150     EXCEPTION
1151         WHEN Fnd_Api.G_EXC_ERROR THEN
1152             ROLLBACK TO ship_sales_order;
1153             x_return_status := Fnd_Api.G_RET_STS_ERROR;
1154             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1155                                       p_data  => x_msg_data);
1156         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
1157             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
1158             ROLLBACK TO ship_sales_order;
1159             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1160                                       p_data  => x_msg_data);
1161         WHEN OTHERS THEN
1162             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
1163             ROLLBACK TO ship_sales_order;
1164             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
1165             THEN
1166                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
1167             END IF;
1168             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1169                                       p_data  => x_msg_data);
1170     END ship_sales_order;
1171 
1172 
1173 /********************************************************
1174 	procedure dbg_print_stack(p_msg_count number, p_mod_name varchar2) is
1175 	l_msg varchar2(2000);
1176      l_stat_level  NUMBER := Fnd_Log.LEVEL_STATEMENT;
1177 
1178 	begin
1179 	  IF p_MSG_COUNT > 1 THEN
1180 	    FOR i IN 1..p_MSG_COUNT LOOP
1181 	     l_msg := apps.FND_MSG_PUB.Get(i,apps.FND_API.G_FALSE) ;
1182           Fnd_Log.STRING(l_stat_level, p_mod_name, l_msg);
1183 	    END LOOP ;
1184 	  ELSE
1185 	     l_msg := apps.FND_MSG_PUB.Get(1,apps.FND_API.G_FALSE) ;
1186           Fnd_Log.STRING(l_stat_level, p_mod_name, l_msg);
1187 	  END IF ;
1188 
1189 	end dbg_print_stack;
1190 ************************************************************/
1191 
1192     /*--------------------------------------------------*/
1193     /* procedure name: process_sales_order              */
1194     /* description   : procedure used to create/book    */
1195     /*                 release and ship sales Order     */
1196     /*                                                  */
1197     /*--------------------------------------------------*/
1198 
1199     PROCEDURE process_sales_order(p_api_version      IN NUMBER,
1200                                   p_commit           IN VARCHAR2 := Fnd_Api.g_false,
1201                                   p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
1202                                   p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
1203                                   p_action           IN VARCHAR2,
1204                                   /*Fixed for bug#4433942 added product
1205                                   txn record as in parameter
1206                                   */
1207                                   p_product_txn_rec  IN  PRODUCT_TXN_REC default null,
1208                                   p_order_rec        IN OUT NOCOPY OM_INTERFACE_REC,
1209                                   x_return_status    OUT NOCOPY VARCHAR2,
1210                                   x_msg_count        OUT NOCOPY NUMBER,
1211                                   x_msg_data         OUT NOCOPY VARCHAR2) IS
1212         l_api_name    CONSTANT VARCHAR2(30) := 'PROCESS_SALES_ORDER';
1213         l_api_version CONSTANT NUMBER := 1.0;
1214         l_msg_count       NUMBER;
1215         l_msg_data        VARCHAR2(2000);
1216         l_msg_index       NUMBER;
1217         p_rule_id         NUMBER := p_order_rec.picking_rule_id;
1218         l_batch_name      VARCHAR2(30);
1219         l_batch_id        NUMBER;
1220         l_temp            NUMBER;
1221         l_user_id         NUMBER;
1222         l_login_id        NUMBER;
1223         l_dummy1          VARCHAR2(2000);
1224         l_dummy2          VARCHAR2(10);
1225         l_ret_code        BOOLEAN;
1226         p_batch_prefix    VARCHAR2(10) := 'DR';
1227         x_order_header_id NUMBER;
1228 
1229         l_header_rec         Aso_Quote_Pub.Qte_Header_Rec_Type;
1230         l_line_tbl           Aso_Quote_Pub.Qte_Line_Tbl_Type;
1231         l_Line_dtl_tbl       Aso_Quote_Pub.Qte_Line_Dtl_Tbl_Type;
1232         l_hd_shipment_rec    Aso_Quote_Pub.Shipment_rec_Type;
1233         l_hd_shipment_tbl    Aso_Quote_Pub.Shipment_tbl_Type;
1234         l_ln_shipment_tbl    Aso_Quote_Pub.Shipment_Tbl_Type;
1235         l_hd_payment_tbl     Aso_Quote_Pub.Payment_Tbl_Type;
1236         l_line_price_adj_tbl Aso_Quote_Pub.Price_Adj_Tbl_Type;
1237         x_order_header_rec   Aso_Order_Int.Order_Header_rec_type;
1238         x_order_line_tbl     Aso_Order_Int.Order_Line_tbl_type;
1239         l_control_rec        Aso_Order_Int.control_rec_type;
1240 
1241         -- Parameters for WSH_DELIVERIES_PUB.Delivery_Action.
1242         p_delivery_id             NUMBER;
1243         p_action_code             VARCHAR2(15);
1244         p_delivery_name           VARCHAR2(30);
1245         p_asg_trip_id             NUMBER;
1246         p_asg_trip_name           VARCHAR2(30);
1247         p_asg_pickup_stop_id      NUMBER;
1248         p_asg_pickup_loc_id       NUMBER;
1249         p_asg_pickup_loc_code     VARCHAR2(30);
1250         p_asg_pickup_arr_date     DATE;
1251         p_asg_pickup_dep_date     DATE;
1252         p_asg_dropoff_stop_id     NUMBER;
1253         p_asg_dropoff_loc_id      NUMBER;
1254         p_asg_dropoff_loc_code    VARCHAR2(30);
1255         p_asg_dropoff_arr_date    DATE;
1256         p_asg_dropoff_dep_date    DATE;
1257         p_sc_action_flag          VARCHAR2(10);
1258         p_sc_intransit_flag       VARCHAR2(10);
1259         p_sc_close_trip_flag      VARCHAR2(10);
1260         p_sc_create_bol_flag      VARCHAR2(10);
1261         p_sc_stage_del_flag       VARCHAR2(10);
1262         p_sc_trip_ship_method     VARCHAR2(30);
1263         p_sc_actual_dep_date      VARCHAR2(30);
1264         p_sc_defer_interface_flag VARCHAR2(1);
1265         p_sc_report_set_id        NUMBER;
1266         p_sc_report_set_name      VARCHAR2(60);
1267         p_wv_override_flag        VARCHAR2(10);
1268         x_trip_id                 VARCHAR2(30);
1269         x_trip_name               VARCHAR2(30);
1270         x_msg_details             VARCHAR2(3000);
1271         x_msg_summary             VARCHAR2(3000);
1272         l_customer_id             NUMBER := NULL;
1273         l_order_type_id           NUMBER := NULL;
1274         l_document_set_id         NUMBER := NULL;
1275         l_sub_inventory           VARCHAR2(30) := '';
1276         l_Organization_Id         NUMBER := NULL;
1277         l_org_id                  NUMBER;
1278         l_locator_id              NUMBER;
1279 	lx_Request_ID             Number ; -- R12 : SU
1280 
1281 	    --bug#6071005
1282 		l_delivery_detail_id	  NUMBER := NULL;
1283 
1284         /*Fixed bug#4433942 following variable has been defined */
1285         C_SRL_NUM_Cnt_Code_SO_ISSUE Constant Number := 6 ;
1286         l_revision                   VARCHAR2(10);
1287         l_shipped_serial_number      VARCHAR2(30);
1288         l_lot_number                 VARCHAR2(80); -- fix for bug#4625226
1289         l_SN_at_SO_new_SN_number     BOOLEAN; /*This flag is true when user provide new SN for serialized item at SO */
1290 
1291         --Parameters for WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes.
1292         source_code        VARCHAR2(15);
1293         changed_attributes Wsh_Delivery_Details_Pub.ChangedAttributeTabType;
1294 
1295         /*Handle exceptions*/
1296         fail_api EXCEPTION;
1297 
1298         CURSOR pick_rule(x_rule_id IN NUMBER) IS
1299             SELECT PICKING_RULE_ID
1300               FROM WSH_PICKING_RULES
1301              WHERE PICKING_RULE_ID = x_rule_id
1302                AND SYSDATE BETWEEN NVL(START_DATE_ACTIVE, SYSDATE) AND
1303                    NVL(END_DATE_ACTIVE, SYSDATE + 1);
1304 
1305         CURSOR batch(x_batch_name IN VARCHAR2) IS
1306             SELECT batch_id
1307               FROM WSH_PICKING_BATCHES
1308              WHERE NAME = x_batch_name;
1309 
1310         CURSOR move_order(x_batch_name IN VARCHAR2) IS
1311             SELECT header_id
1312               FROM MTL_TXN_REQUEST_HEADERS
1313              WHERE request_number = x_batch_name;
1314 
1315         CURSOR customer(p_ord_header_id IN NUMBER) IS
1316             SELECT a.sold_to_org_id,
1317                    a.order_type_id,
1318                    a.source_document_type_id
1319               FROM oe_order_headers_all a
1320              WHERE a.header_id = p_ord_header_id;
1321 
1322         CURSOR delivery(p_ord_header_id IN NUMBER, p_ord_line_id IN NUMBER) IS
1323             SELECT b.delivery_id,
1324                    a.delivery_detail_id,
1325                    c.serial_number_control_code,
1326              /* Fix for bug# 4433942 */
1327                    c.lot_control_code,
1328                    c.revision_qty_control_code,
1329                    c.reservable_type,
1330                    a.organization_id,
1331                    a.inventory_item_id,
1332                    c.segment1 item_name,
1333                    p.organization_code
1334               FROM wsh_delivery_details     a,
1335 			    --Changed to view from table, bug:  4341784
1336                    wsh_delivery_assignments_v b,
1337                    mtl_system_items         c,
1338                    mtl_parameters  p
1339              WHERE a.delivery_detail_id = b.delivery_detail_id
1340                AND a.inventory_item_id = c.inventory_item_id
1341                AND a.organization_id = c.organization_id
1342                AND a.released_status = 'Y'
1343 	       AND  a.SOURCE_CODE = 'OE' /*Fixed for bug#5846054*/
1344                AND a.source_header_id = p_ord_header_id
1345                AND a.source_line_id = p_ord_line_id
1346                AND a.organization_id = p.organization_id;
1347 
1348        CURSOR c_get_org_id (p_header_id IN NUMBER) IS
1349           SELECT org_id
1350           FROM oe_order_headers_all
1351           WHERE header_id = p_header_id;
1352 
1353         -- Variables used in FND Log
1354         l_error_level NUMBER := Fnd_Log.LEVEL_ERROR;
1355         l_mod_name    VARCHAR2(2000) := 'csd.plsql.csd_process_pvt.process_sales_order';
1356 
1357 	   /* pick release rule api changes/srl reservations changes *
1358 	   */
1359 	  l_batch_rec   WSH_PICKING_BATCHES_PUB.Batch_Info_Rec ;
1360 	  l_ret_status varchar2(1);
1361 	  l_reservation_id number;
1362 
1363 	  cursor c_srl_reservation(p_srl_num varchar2, p_item_id number) is
1364 	  select reservation_id from mtl_Serial_numbers
1365 	  where serial_number = p_srl_num
1366 	  and inventory_item_Id = p_item_id;
1367 
1368       --bug#6071005
1369 	  cursor get_delivery_detail_id(p_order_header_id IN NUMBER, p_order_line_id IN NUMBER) IS
1370 	  select delivery_detail_id
1371 	  from wsh_Delivery_Details
1372 	  where source_header_id = p_order_header_id and source_line_id = p_order_line_id;
1373 
1374 
1375     BEGIN
1376         -- Debug message
1377         Debug('At the Beginning of process_sales_order', l_mod_name, 1);
1378 
1379         -- Standard Start of API savepoint
1380         SAVEPOINT process_sales_order;
1381 
1382         -- Standard call to check for call compatibility.
1383         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
1384                                            p_api_version,
1385                                            l_api_name,
1386                                            G_PKG_NAME)
1387         THEN
1388             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
1389         END IF;
1390 
1391         -- Initialize message list if p_init_msg_list is set to TRUE.
1392         IF Fnd_Api.to_Boolean(p_init_msg_list)
1393         THEN
1394             Fnd_Msg_Pub.initialize;
1395         END IF;
1396 
1397         -- Initialize API return status to success
1398         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
1399 
1400         -- Api body starts
1401 
1402         -- dbms_application_info.set_client_info('204');
1403         -- fnd_global.apps_initialize(1000200,52284,512,0);
1404 
1405         Debug('Validate the action code', l_mod_name, 1);
1406 
1407         -- Validate the action code
1408         IF NOT (Csd_Process_Util.VALIDATE_ACTION(p_action, l_api_name))
1409         THEN
1410             RAISE Fnd_Api.G_EXC_ERROR;
1411         END IF;
1412 
1413         IF p_action = 'CREATE'
1414         THEN
1415 
1416             -- If action is CREATE, then call charges private api to
1417             -- create sales order
1418             Debug('Creating the Sales Order', l_mod_name, 1);
1419             Debug('p_order_rec.incident_id =' || p_order_rec.incident_id,
1420                   l_mod_name,
1421                   1);
1422             Debug('p_order_rec.party_id    =' || p_order_rec.party_id,
1423                   l_mod_name,
1424                   1);
1425             Debug('p_order_rec.account_id  =' || p_order_rec.account_id,
1426                   l_mod_name,
1427                   1);
1428 
1429             Cs_Charge_Create_Order_Pub.Submit_Order(p_api_version      => 1.0,
1430                                                     p_init_msg_list    => p_init_msg_list,
1431                                                     p_commit           => p_commit,
1432                                                     p_validation_level => p_validation_level,
1433                                                     p_incident_id      => p_order_rec.incident_id,
1434                                                     p_party_id         => p_order_rec.party_id,
1435                                                     p_account_id       => p_order_rec.account_id,
1436                                                     p_book_order_flag  => 'N',
1437                                                     x_return_status    => x_return_status,
1438                                                     x_msg_count        => x_msg_count,
1439                                                     x_msg_data         => x_msg_data);
1440 
1441             Debug('Return Status from Submit_Order' || x_return_status,
1442                   l_mod_name,
1443                   1);
1444 
1445             IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
1446             THEN
1447                 Debug('Submit_Order API failed ', l_mod_name, 1);
1448                 RAISE Fnd_Api.G_EXC_ERROR;
1449             END IF;
1450 
1451         ELSIF p_action = 'BOOK'
1452         THEN
1453 
1454             -- If action is BOOK, then call charges private api to
1455             -- book the sales order
1456             Debug('Booking the Sales Order', l_mod_name, 1);
1457             Debug('p_order_rec.order_header_id =' ||
1458                   p_order_rec.order_header_id,
1459                   l_mod_name,
1460                   1);
1461             Debug('p_order_rec.org_id          =' || p_order_rec.org_id,
1462                   l_mod_name,
1463                   1);
1464 
1465             l_header_rec.org_id           := p_order_rec.org_id;
1466             l_header_rec.order_id         := p_order_rec.order_header_id;
1467             l_control_rec.book_flag       := Fnd_Api.G_TRUE;
1468             l_control_rec.calculate_price := Fnd_Api.G_FALSE;
1469 
1470      	    open  c_get_org_id(p_order_rec.order_header_id);
1471 	    fetch c_get_org_id into l_org_id;
1472 	    close c_get_org_id;
1473 
1474 
1475             -- Set the Policy context as required for MOAC Uptake, Bug#4421242
1476             mo_global.set_policy_context('S',l_org_id);
1477 
1478 
1479             Aso_Order_Int.Update_order(P_Api_Version_Number => 1.0,
1480                                        P_Init_Msg_List      => Fnd_Api.G_TRUE,
1481                                        P_Commit             => Fnd_Api.G_FALSE,
1482                                        P_Qte_Rec            => l_header_rec,
1483                                        P_Qte_Line_Tbl       => l_line_tbl,
1484                                        P_Qte_Line_Dtl_Tbl   => l_line_dtl_tbl,
1485                                        P_Line_Shipment_Tbl  => l_ln_shipment_tbl,
1486                                        P_Header_Payment_Tbl => l_hd_payment_tbl,
1487                                        P_Line_Price_Adj_Tbl => l_line_price_adj_tbl,
1488                                        P_Control_Rec        => l_control_rec,
1489                                        X_Order_Header_Rec   => x_order_header_rec,
1490                                        X_Order_Line_Tbl     => x_order_line_tbl,
1491                                        X_Return_Status      => x_return_status,
1492                                        X_Msg_Count          => x_msg_count,
1493                                        X_Msg_Data           => x_msg_data);
1494 
1495            -- Change the Policy context back to multiple
1496            mo_global.set_policy_context('M',null);
1497 
1498            Debug('Return Status from Update_order' || x_return_status,
1499                   l_mod_name,
1500                   1);
1501 
1502            IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
1503            THEN
1504              Debug('ASO_ORDER_INT.UPDATE_ORDER failed', l_mod_name, 1);
1505              RAISE Fnd_Api.G_EXC_ERROR;
1506            END IF;
1507 
1508         ELSIF p_action = 'PICK-RELEASE'
1509         THEN
1510 
1511             Debug('Releasing Sales Order', l_mod_name, 1);
1512             Debug('p_order_rec.order_header_id =' ||
1513                   p_order_rec.order_header_id,
1514                   l_mod_name,
1515                   1);
1516 
1517             -- If action is BOOK, then call charges private api to
1518             -- book the sales order
1519 
1520             IF NVL(p_order_rec.order_header_id, Fnd_Api.G_MISS_NUM) =
1521                Fnd_Api.G_MISS_NUM
1522             THEN
1523                 Fnd_Message.SET_NAME('CSD', 'CSD_INV_ORDER_HEADER_ID');
1524                 Fnd_Message.SET_TOKEN('ORDER_HEADER_ID',
1525                                       p_order_rec.order_header_id);
1526                 Fnd_Msg_Pub.ADD;
1527                 Debug('Invalid Order header Id is passed ', l_mod_name, 1);
1528                 RAISE Fnd_Api.G_EXC_ERROR;
1529             END IF;
1530 
1531             IF NVL(p_order_rec.PICKING_RULE_ID, Fnd_Api.G_MISS_NUM) =
1532                Fnd_Api.G_MISS_NUM
1533             THEN
1534                 Fnd_Message.SET_NAME('CSD', 'CSD_INV_PICKING_RULE_ID');
1535                 Fnd_Message.SET_TOKEN('PICKING_RULE_ID',
1536                                       p_order_rec.PICKING_RULE_ID);
1537                 Fnd_Msg_Pub.ADD;
1538                 Debug('Invalid Picking rule Id is passed ', l_mod_name, 1);
1539                 RAISE Fnd_Api.G_EXC_ERROR;
1540             END IF;
1541 
1542             -- Fetch user and login information
1543             l_user_id  := Fnd_Global.USER_ID;
1544             l_login_id := Fnd_Global.CONC_LOGIN_ID;
1545 
1546             -- Validate Picking Rule
1547             OPEN pick_rule(p_order_rec.PICKING_RULE_ID);
1548             FETCH pick_rule
1549                 INTO l_temp;
1550             IF pick_rule%NOTFOUND
1551             THEN
1552                 Debug('The picking rule ' || p_order_rec.PICKING_RULE_ID ||
1553                       'does not exist or has expired',
1554                       l_mod_name,
1555                       1);
1556                 CLOSE pick_rule;
1557                 RAISE Fnd_Api.G_EXC_ERROR;
1558             END IF;
1559             IF pick_rule%ISOPEN
1560             THEN
1561                 CLOSE pick_rule;
1562             END IF;
1563 
1564             -- Get the customer/order details
1565             OPEN customer(p_order_rec.order_header_id);
1566             FETCH customer
1567                 INTO l_customer_id, l_order_type_id, l_document_set_id;
1568 
1569             IF customer%NOTFOUND
1570             THEN
1571                 Debug('invalid order header id ', l_mod_name, 1);
1572                 CLOSE customer;
1573                 RAISE Fnd_Api.G_EXC_ERROR;
1574             END IF;
1575 
1576             IF customer%ISOPEN
1577             THEN
1578                 CLOSE customer;
1579             END IF;
1580 
1581             IF NVL(p_order_rec.org_id, Fnd_Api.G_MISS_NUM) =
1582                Fnd_Api.G_MISS_NUM
1583             THEN
1584                 l_Organization_Id := NULL;
1585             ELSIF p_Order_Rec.Org_Id IS NULL
1586             THEN
1587                 l_Organization_Id := NULL;
1588             ELSE
1589                 l_Organization_Id := p_order_rec.org_id;
1590             END IF;
1591 
1592             IF NVL(p_order_rec.pick_from_subinventory, Fnd_Api.G_MISS_CHAR) =
1593                Fnd_Api.G_MISS_CHAR
1594             THEN
1595                 l_sub_inventory := '';
1596             ELSIF p_Order_Rec.Pick_From_Subinventory IS NULL
1597             THEN
1598                 l_Sub_Inventory := '';
1599             ELSE
1600                 l_sub_inventory := p_order_rec.pick_from_subinventory;
1601             END IF;
1602 
1603             -- Fix for Enh Req#3948563
1604             IF ((p_order_rec.locator_id is null) or (p_order_rec.locator_id = FND_API.G_MISS_NUM)) THEN
1605               l_locator_id := null;
1606             ELSE
1607               l_locator_id := p_order_rec.locator_id;
1608             END IF;
1609 
1610 			--bug#6071005
1611 			--'A' means "All ship lines in an order",
1612 			--'S' menas "Selected ship line only"
1613 			--if the profile value set to "Selected ship line only", then pass the delivery_detail_id
1614 			--else it will pass null value to delivery_detail_id.
1615 			If (fnd_profile.value('CSD_PROCESS_AUTO_PICK_RELEASE') = 'S') then
1616      			open  get_delivery_detail_id(p_order_rec.order_header_id, p_order_rec.order_line_id);
1617 				fetch get_delivery_detail_id into l_delivery_detail_id;
1618 				close get_delivery_detail_id;
1619 			End if;
1620 
1621 		  --R12 : SU Putting Insert statement in Begin and End Block
1622 
1623       Begin
1624        SELECT 	NVL(DOCUMENT_SET_ID, l_document_set_id),
1625            'I', -- Include backorders also 11.5.10 saupadhy: BACKORDERS_ONLY_FLAG,
1626             NVL(EXISTING_RSVS_ONLY_FLAG, 'N'),
1627             SHIPMENT_PRIORITY_CODE,
1628             p_order_rec.order_header_id,
1629 			l_delivery_detail_id,					--bug#6071005
1630             l_order_type_id,
1631             NULL, --SHIP_FROM_LOCATION_ID,
1632             l_customer_id,
1633             NULL, --SHIP_TO_LOCATION_ID,
1634             SHIP_METHOD_CODE,
1635             NVL(l_Sub_Inventory, PICK_FROM_SUBINVENTORY),
1636             NVL(l_locator_id,PICK_FROM_LOCATOR_ID), -- Fix for Enh Req#3948563 NULL, --PICK_FROM_LOCATOR_ID,
1637             DEFAULT_STAGE_SUBINVENTORY,
1638             DEFAULT_STAGE_LOCATOR_ID,
1639             AUTODETAIL_PR_FLAG,
1640             AUTO_PICK_CONFIRM_FLAG,
1641             SHIP_SET_NUMBER,
1642             NULL, --INVENTORY_ITEM_ID,
1643             NULL,
1644             NULL,
1645             NULL,
1646             NULL,
1647             PICK_GROUPING_RULE_ID,
1648             PICK_SEQUENCE_RULE_ID,
1649             NVL(l_Organization_Id, ORGANIZATION_ID),
1650             PROJECT_ID,
1651             TASK_ID,
1652             INCLUDE_PLANNED_LINES,
1653             AUTOCREATE_DELIVERY_FLAG
1654 	INTO
1655             l_batch_rec.Document_set_id,
1656             l_batch_Rec.Backorders_only_flag,
1657             l_batch_rec.Existing_Rsvs_Only_Flag,
1658 		  l_batch_rec.Shipment_Priority_Code,
1659             l_batch_rec.order_header_id,
1660 			l_batch_rec.delivery_detail_id,			--bug#6071005
1661             l_batch_rec.order_type_id,
1662             l_batch_rec.ship_from_location_id,
1663             l_batch_rec.customer_id,
1664             l_batch_rec.ship_to_location_id,
1665             l_batch_rec.ship_method_code,
1666             l_batch_rec.pick_from_subinventory,
1667             l_batch_rec.pick_from_locator_id,
1668             l_batch_rec.default_stage_subinventory,
1669             l_batch_rec.default_stage_locator_id,
1670              l_batch_rec.autodetail_pr_flag,
1671              l_batch_rec.auto_pick_confirm_flag,
1672             l_batch_rec.ship_set_number,
1673             l_batch_rec.inventory_item_id,
1674             l_batch_rec.From_requested_date,
1675             l_batch_rec.to_Requested_date,
1676             l_batch_rec.from_scheduled_ship_date,
1677             l_batch_Rec.to_scheduled_ship_date,
1678             l_batch_Rec.pick_grouping_rule_id,
1679             l_batch_rec.pick_sequence_rule_id,
1680             l_batch_rec.organization_id,
1681             l_batch_rec.project_id,
1682             l_batch_rec.task_id,
1683             l_batch_rec.Include_Planned_Lines,
1684             l_batch_rec.Autocreate_Delivery_Flag
1685 	FROM WSH_PICKING_RULES
1686 	WHERE PICKING_RULE_ID = p_order_rec.PICKING_RULE_ID;
1687 
1688 
1689           Exception
1690                WHEN OTHERS THEN
1691                   Fnd_Message.SET_NAME('CSD', 'CSD_PICK_RELEASE_FAIL');
1692                   Fnd_Message.SET_TOKEN('BATCH_NAME', l_batch_name);
1693                   Fnd_Msg_Pub.ADD;
1694                   Debug(' Picking rules insert failed ',l_mod_name, 1);
1695                   RAISE Fnd_Api.G_EXC_ERROR;
1696 	  End ;
1697 
1698       /* override the auto pick confirm flag if the serial_number is reserved. */
1699       Debug(' serial_number['||p_product_txn_rec.source_serial_number||']',l_mod_name, 1);
1700       Debug(' item['||to_char(p_product_txn_rec.inventory_item_id)||']',l_mod_name, 1);
1701 	 if(nvl(p_product_txn_rec.source_serial_number,FND_API.G_MISS_CHAR) <> FND_API.G_MISS_CHAR) then
1702      	 Open c_srl_reservation(p_product_txn_rec.source_serial_number, p_product_txn_rec.inventory_item_Id);
1703      	 FETCH c_Srl_reservation into l_reservation_Id;
1704      	 if(c_Srl_reservation%notfound)then
1705      	     l_reservation_id := null;
1706      	 end if;
1707      	 Close c_srl_reservation;
1708            Debug(' rsv_id['||to_char(nvl(l_reservation_id,0))||']',l_mod_name, 1);
1709      	 if(l_reservation_Id is not null) then
1710                l_batch_rec.auto_pick_confirm_flag := 'Y';
1711      	 end if;
1712 	 end if;
1713       Debug(' pick_confirm_flag['||l_batch_Rec.auto_pick_confirm_flag||']',l_mod_name, 1);
1714 
1715         WSH_PICKING_BATCHES_GRP.Create_Batch(
1716 	    p_api_version_number     => 1.0,
1717 	    p_init_msg_list	     => FND_API.G_FALSE,
1718 	    p_commit		     => FND_API.G_FALSE,
1719 	    x_return_status	     => l_ret_status,
1720 	    x_msg_count		     => l_msg_count,
1721 	    x_msg_data		     => l_msg_data,
1722 	    p_rule_id		     => p_order_rec.PICKING_RULE_ID,
1723 	    p_rule_name		     => null,
1724 	    p_batch_rec		     => l_batch_rec,
1725 	    p_batch_prefix	     => p_batch_prefix,
1726 	    x_batch_id		     => l_batch_id);
1727 
1728         IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
1729            THEN
1730              Debug('WSH_PICKINGBATCHES_GRP.Create_batch failed', l_mod_name, 1);
1731              RAISE Fnd_Api.G_EXC_ERROR;
1732         END IF;
1733 	   Debug('Batch created batch_id=['||l_batch_id||']',l_mod_name,1);
1734 
1735 	   wsh_picking_batches_pub.Release_Batch (
1736 		   -- Standard parameters
1737 		   p_api_version     => 1.0,
1738 		   p_init_msg_list   => Fnd_API.G_False,
1739 		   p_commit          => Fnd_API.G_False,
1740 		   x_return_status   => x_Return_Status,
1741 		   x_msg_count       => x_Msg_Count,
1742 		   x_msg_data        => x_Msg_Data,
1743 		   -- program specific paramters.
1744 		   p_batch_id       => l_Batch_ID,
1745              p_batch_name     => l_Batch_Name,
1746 		   p_log_level      => NULL,
1747              p_release_mode   => 'ONLINE',
1748              x_request_id     => lx_Request_ID ) ;
1749 
1750 	  Debug('After release Batch, msg_data['||x_msg_data||']' ||
1751 	         'x_return_status=['||x_return_status||']', l_mod_name,1);
1752 	  --dbg_print_stack(x_msg_count, l_mod_name);
1753 
1754 	  IF (x_return_status = Fnd_Api.G_RET_STS_ERROR)
1755 	  THEN
1756 	     Fnd_Message.SET_NAME('CSD', 'CSD_PICK_RELEASE_FAIL');
1757 	     Fnd_Message.SET_TOKEN('BATCH_NAME', l_batch_name);
1758 	     Fnd_Msg_Pub.ADD;
1759 	     Debug('WSH_PICK_LIST.RELEASE_BATCH failed for batch : ' ||
1760 		  l_batch_name,
1761 		  l_mod_name,1) ;
1762 	     RAISE Fnd_Api.G_EXC_ERROR;
1763 	   END IF;
1764 	   Debug('Batch processed, req_id=['||lx_request_id||']',l_mod_name,1);
1765 
1766         ELSIF p_action = 'SHIP'
1767         THEN
1768 
1769             -- If action is SHIP, then call shipping api to ship the sales order
1770             Debug('Shipping the Sales Order', l_mod_name, 1);
1771             Debug('p_order_rec.order_header_id =' ||
1772                   p_order_rec.order_header_id,
1773                   l_mod_name,
1774                   1);
1775 
1776             IF NVL(p_order_rec.order_header_id, Fnd_Api.G_MISS_NUM) =
1777                Fnd_Api.G_MISS_NUM
1778             THEN
1779                 Fnd_Message.SET_NAME('CSD', 'CSD_INV_ORDER_HEADER_ID');
1780                 Fnd_Message.SET_TOKEN('ORDER_HEADER_ID',
1781                                       p_order_rec.order_header_id);
1782                 Fnd_Msg_Pub.ADD;
1783                 Debug('Order_header_id is invalid', l_mod_name, 1);
1784                 RAISE Fnd_Api.G_EXC_ERROR;
1785             END IF;
1786 
1787             FOR i IN delivery(p_order_rec.order_header_id,
1788                               p_order_rec.order_line_id)
1789             LOOP
1790 
1791                 /* Fix for bug#4433942 -- Code Commented
1792                 -- In case of serialized item, update the serial number on the
1793                 -- delivery line details
1794                 -- Update the serial number on the delivery lines only if the item
1795                 -- is serialized at SO issue
1796                 IF i.serial_number_control_code = 6 AND
1797                    NVL(p_order_rec.serial_number, Fnd_Api.G_MISS_CHAR) <>
1798                    Fnd_Api.G_MISS_CHAR
1799                 THEN
1800 
1801                     BEGIN
1802                         source_code := 'OE'; -- The only source code that should be used by the API
1803                         changed_attributes(1).delivery_detail_id := i.delivery_detail_id;
1804                         changed_attributes(1).serial_number := p_order_rec.serial_number;
1805                         changed_attributes(1).shipped_quantity := p_order_rec.shipped_quantity;
1806 
1807                         Debug('delivery_detail_id =' ||
1808                               changed_attributes(1).delivery_detail_id,
1809                               l_mod_name,
1810                               1);
1811                         Debug('serial_number      =' ||
1812                               changed_attributes(1).serial_number,
1813                               l_mod_name,
1814                               1);
1815                         Debug('shipped_quantity   =' ||
1816                               changed_attributes(1).shipped_quantity,
1817                               l_mod_name,
1818                               1);
1819                         Debug('Calling Update_Shipping_Attributes',
1820                               l_mod_name,
1821                               1);
1822 
1823                         --Call to WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes.
1824                         Wsh_Delivery_Details_Pub.Update_Shipping_Attributes(p_api_version_number => 1.0,
1825                                                                             p_init_msg_list      => p_init_msg_list,
1826                                                                             p_commit             => p_commit,
1827                                                                             x_return_status      => x_return_status,
1828                                                                             x_msg_count          => x_msg_count,
1829                                                                             x_msg_data           => x_msg_data,
1830                                                                             p_changed_attributes => changed_attributes,
1831                                                                             p_source_code        => source_code);
1832 
1833                         Debug('x_return_status(Update_Shipping_Attributes )=' ||
1834                               x_return_status,
1835                               l_mod_name,
1836                               1);
1837 
1838                         IF (x_return_status <>
1839                            Wsh_Util_Core.G_RET_STS_SUCCESS)
1840                         THEN
1841                             Debug('Update_Shipping_Attributes failed',
1842                                   l_mod_name,
1843                                   1);
1844                             RAISE fail_api;
1845                         END IF; */
1846 
1847                 /*Fixed for bug#4433942
1848                 Psuedo code for new solution is as follows:
1849                 If Item is Reservable then
1850                   Check if item is Serial Controlled @ SO Issue
1851                   ( This is existing solution and it will continue to stay
1852                   If item is serial controlled at Sales Order issue then
1853                     Call API WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes
1854                     and update with serial_number and quantity.
1855                     End If;
1856                   Else If Item is Non-Reservable
1857                     If Item is serial Controlled then
1858                       Get Lot_Number, Revision, Sub Inventory Information from
1859                       Mtl_Serial_numbers for a given serial_number, item_id,organization_id
1860 
1861                       Call API WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes and
1862                       Update Serial_Number, Quantity ( will be 1 for serial controlled
1863                       items), lot_number, Revision and subinventory
1864                     Else if item is non serial controlled then
1865                       Call API WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes
1866                       Values for Quantity, Lot_Number, Revision and Sub Inventory
1867                       should be pulled from UI.
1868                       Update Quantity, Lot_Number, Revision and Sub-Inventory
1869                   End If ;
1870                 End If;
1871                 */
1872                 /* Fixed for bug#3438685
1873                 In case of serial controlled at SO issue item, update the serial number on the
1874                 delivery line details
1875                 */
1876 
1877                 BEGIN
1878 
1879                   IF( i.RESERVABLE_TYPE = 1) Then /*Item is reservable */
1880                     IF i.serial_number_control_code = C_SRL_NUM_Cnt_Code_SO_Issue Then
1881 
1882                       source_code := 'OE'; -- The only source code that should be used by the API
1883                       changed_attributes(1).delivery_detail_id := i.delivery_detail_id;
1884                       changed_attributes(1).serial_number      := p_order_rec.serial_number;
1885                       changed_attributes(1).shipped_quantity   := p_order_rec.shipped_quantity;
1886 
1887                       IF (g_debug > 0 ) THEN
1888                         csd_gen_utility_pvt.ADD('delivery_detail_id ='||changed_attributes(1).delivery_detail_id);
1889                         csd_gen_utility_pvt.ADD('serial_number      ='||changed_attributes(1).serial_number );
1890                         csd_gen_utility_pvt.ADD('shipped_quantity   ='||changed_attributes(1).shipped_quantity );
1891                         csd_gen_utility_pvt.ADD('Calling Update_Shipping_Attributes');
1892                       END IF;
1893 
1894 
1895                       --Call to WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes.
1896                       WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes(
1897                         p_api_version_number => 1.0,
1898                         p_init_msg_list      => p_init_msg_list,
1899                         p_commit             => p_commit,
1900                         x_return_status      => x_return_status,
1901                         x_msg_count          => x_msg_count,
1902                         x_msg_data           => x_msg_data,
1903                         p_changed_attributes => changed_attributes,
1904                         p_source_code        => source_code);
1905 
1906                       IF (g_debug > 0 ) THEN
1907                         csd_gen_utility_pvt.ADD('x_return_status(Update_Shipping_Attributes )='||x_return_status);
1908                       END IF;
1909 
1910                       IF (x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
1911                         IF (g_debug > 0 ) THEN
1912                           csd_gen_utility_pvt.ADD('Update_Shipping_Attributes failed');
1913                         END IF;
1914                         RAISE fail_api;
1915                       END IF;
1916                     END IF; /* end if of Serial control at sales order and reservable item */
1917 
1918                   Elsif (i.RESERVABLE_TYPE = 2 ) then   /* else of reservable type */
1919 
1920                     /*Bug#4433942 Validations for non reservable item
1921                     1) If item is serialized make sure that Serial Number resides in the warehouse specified on
1922                        Ship line,if not raise error. for serial control at receipt/pre-defined.
1923                     2) If item is non-serialized make sure that sub inventory entered on DWB belongs to warehouse
1924                        specified on ship line, if not raise error.
1925                     3) If item is serialized make sure that user passes serial number information,
1926                        if not raise error.
1927                     4) If item is non-serialized  make sure that user passes Sub inventory information
1928                        else raise error.
1929                     5) If item is non-serialized and lot controlled make sure user passes
1930                        lot_number information else raise error.
1931                     6) If item is non-serialized and  revision controlled make sure user passes revision
1932                        information else raise error.
1933                     */
1934                     l_revision:=null;
1935                     l_shipped_serial_number  :=NULL;
1936                     l_lot_number             :=NULL;
1937                     l_sub_inventory          :=NULL;
1938                     l_SN_at_SO_new_SN_number :=FALSE;
1939 
1940                     if i.serial_number_control_code in (2,5,6) then
1941 
1942                       if nvl(p_product_txn_rec.source_serial_number,FND_API.G_MISS_CHAR)=FND_API.G_MISS_CHAR then
1943                         /* Validation 3 */
1944                         FND_MESSAGE.SET_NAME('CSD','CSD_API_SERIAL_NUM_REQD');
1945                         FND_MSG_PUB.ADD;
1946                         RAISE FND_API.G_EXC_ERROR;
1947                       else
1948                         l_shipped_serial_number := p_product_txn_rec.source_serial_number;
1949                       end if;
1950 
1951                       begin
1952                         select Lot_Number, Revision, current_SubInventory_code
1953                         into   l_lot_number ,l_revision ,l_sub_inventory
1954                         from mtl_serial_numbers
1955                         where serial_number         = l_shipped_serial_number
1956                         AND inventory_item_id       = i.inventory_item_id
1957                         AND current_organization_id = i.organization_id;
1958                       exception
1959                         when no_data_found then
1960                           if (i.serial_number_control_code in (2,5)) then
1961                             /*Validation 1 */
1962                             FND_MESSAGE.SET_NAME('CSD','CSD_SERIAL_NUM_NOT_IN_INVORG');
1963                             FND_MESSAGE.SET_TOKEN('SERIAL_NUMBER',l_shipped_serial_number);
1964                             FND_MESSAGE.SET_TOKEN('INV_ORG',i.organization_code);
1965                             FND_MSG_PUB.ADD;
1966                             RAISE FND_API.G_EXC_ERROR;
1967                           else /*if Item is Serialied at SO then user may pass SN that does not resides in any warehouse */
1968                             l_SN_at_SO_new_SN_number :=TRUE;
1969                           end if;
1970                       end;
1971                     end if;  /*end if of serialized item */
1972 
1973                     if ( i.serial_number_control_code =1 or (i.serial_number_control_code=6 and l_SN_at_SO_new_SN_number=TRUE ) ) then
1974                       if nvl(p_product_txn_rec.sub_inventory ,FND_API.G_MISS_CHAR)=FND_API.G_MISS_CHAR then
1975                         /*Validation 4 */
1976                         FND_MESSAGE.SET_NAME('CSD','CSD_SUBINV_IS_REQD');
1977                         FND_MSG_PUB.ADD;
1978                         RAISE FND_API.G_EXC_ERROR;
1979                       end if;
1980 
1981                       begin
1982                         SELECT msi.secondary_inventory_name
1983                         into   l_sub_inventory
1984                         FROM  mtl_secondary_inventories msi
1985                         where msi.organization_id = i.organization_id
1986                         AND  msi.secondary_inventory_name = p_product_txn_rec.sub_inventory
1987                         AND  NVL(msi.DISABLE_DATE,SYSDATE+1) > SYSDATE
1988                         AND  msi.QUANTITY_TRACKED = 1;
1989 
1990                       exception
1991                       When no_data_found then
1992                         /*Validation 2 */
1993                         FND_MESSAGE.SET_NAME('CSD','CSD_SUBINV_NOT_IN_INVORG');
1994                         FND_MESSAGE.SET_TOKEN('SUB_INV',p_product_txn_rec.sub_inventory);
1995                         FND_MESSAGE.SET_TOKEN('INV_ORG',i.organization_code);
1996                         FND_MSG_PUB.ADD;
1997                         RAISE FND_API.G_EXC_ERROR;
1998                       end;
1999 
2000                       if i.LOT_CONTROL_CODE =2 then
2001                         if nvl(p_product_txn_rec.lot_number,FND_API.G_MISS_CHAR)=FND_API.G_MISS_CHAR then
2002                           /*Validation 5 */
2003                           FND_MESSAGE.SET_NAME('CSD','CSD_LOT_NUMBER_REQD');
2004                           FND_MESSAGE.SET_TOKEN('ITEM',i.item_name);
2005                           FND_MSG_PUB.ADD;
2006                           RAISE FND_API.G_EXC_ERROR;
2007                         else
2008                           l_lot_number:= p_product_txn_rec.lot_number;
2009                         end if;
2010                       end if;
2011 
2012                       if i.REVISION_QTY_CONTROL_CODE =2 then
2013                         if  nvl(p_product_txn_rec.revision,FND_API.G_MISS_CHAR)=FND_API.G_MISS_CHAR then
2014                           FND_MESSAGE.SET_NAME('CSD','CSD_ITEM_REVISION_REQD');
2015                           FND_MESSAGE.SET_TOKEN('ITEM',i.item_name);
2016                           FND_MSG_PUB.ADD;
2017                           RAISE FND_API.G_EXC_ERROR;
2018                         else
2019                           l_revision:=p_product_txn_rec.revision;
2020                         end if;
2021                       end if;
2022                     end if; /* end of non serialized item */
2023 
2024                     /* Till here all the validations are done now we can call update attribute API */
2025                     source_code := 'OE'; /*The only source code that should be used by the API */
2026                     changed_attributes(1).delivery_detail_id := i.delivery_detail_id;
2027                     changed_attributes(1).serial_number      := l_shipped_serial_number;
2028                     changed_attributes(1).revision           := l_revision ;
2029                     changed_attributes(1).lot_number         := l_lot_number;
2030                     changed_attributes(1).subinventory       := l_sub_inventory;
2031                     changed_attributes(1).shipped_quantity   := p_order_rec.shipped_quantity;
2032 
2033                     IF (g_debug > 0 ) THEN
2034                       csd_gen_utility_pvt.ADD('delivery_detail_id ='||changed_attributes(1).delivery_detail_id);
2035                       csd_gen_utility_pvt.ADD('serial_number      ='||changed_attributes(1).serial_number );
2036                       csd_gen_utility_pvt.ADD('Revision           ='||changed_attributes(1).revision );
2037                       csd_gen_utility_pvt.ADD('Lot number         ='||changed_attributes(1).lot_number );
2038                       csd_gen_utility_pvt.ADD('sub_inventory      ='||changed_attributes(1).subinventory );
2039                       csd_gen_utility_pvt.ADD('shipped_quantity   ='||changed_attributes(1).shipped_quantity );
2040                       csd_gen_utility_pvt.ADD('Calling Update_Shipping_Attributes');
2041                     END IF;
2042 
2043                     WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes(
2044                       p_api_version_number => 1.0,
2045                       p_init_msg_list      => p_init_msg_list,
2046                       p_commit             => p_commit,
2047                       x_return_status      => x_return_status,
2048                       x_msg_count          => x_msg_count,
2049                       x_msg_data           => x_msg_data,
2050                       p_changed_attributes => changed_attributes,
2051                       p_source_code        => source_code);
2052 
2053                       IF (g_debug > 0 ) THEN
2054                         csd_gen_utility_pvt.ADD('x_return_status(Update_Shipping_Attributes )='||x_return_status);
2055                       END IF;
2056 
2057                       IF (x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
2058                         IF (g_debug > 0 ) THEN
2059                           csd_gen_utility_pvt.ADD('Update_Shipping_Attributes failed');
2060                         END IF;
2061                         RAISE fail_api;
2062                       END IF;
2063 
2064                   END IF;  /* end if of reservable type */
2065 
2066                 EXCEPTION
2067                 WHEN fail_api THEN
2068                   Wsh_Util_Core.get_messages('Y',
2069                                               x_msg_summary,
2070                                               x_msg_details,
2071                                               x_msg_count);
2072                   IF x_msg_count > 1 THEN
2073                     x_msg_data := x_msg_summary ||
2074                                   x_msg_details;
2075                   ELSE
2076                     x_msg_data := x_msg_summary;
2077                   END IF;
2078 
2079                   Debug('Error Msg from Update_Shipping_Attributes',
2080                     l_mod_name,
2081                     1);
2082                   Debug('x_msg_data = ' || x_msg_data,
2083                     l_mod_name,
2084                     1);
2085                   Fnd_Message.SET_NAME('CSD','CSD_UPDATE_SHIPPING_FAILED');
2086                   Fnd_Message.SET_TOKEN('ERR_MSG', x_msg_data);
2087                   Fnd_Msg_Pub.ADD;
2088                   RAISE Fnd_Api.G_EXC_ERROR;
2089                 END;
2090 
2091 --              END IF; --end of update_shipping_attributes
2092 
2093                 BEGIN
2094                     Debug('i.delivery_id=' || i.delivery_id, l_mod_name, 1);
2095 
2096                     -- Values for Ship Confirming the delivery.
2097                     p_action_code             := 'CONFIRM'; -- The action code for ship confirm
2098                     p_delivery_id             := i.delivery_id; -- The delivery that needs to be confirmed
2099                     p_delivery_name           := TO_CHAR(i.delivery_id); -- The delivery name,
2100                     p_sc_action_flag          := 'S'; -- Ship entered quantity.
2101 
2102                     -- p_Sc_Intransit_flag needs to be set to 'Y' this as per bug 3676488 (Shipping)
2103                     -- This fix for bug# 3665544
2104                     p_sc_intransit_flag       := 'Y'; -- In transit flag is set to 'Y' closes the
2105 
2106                     -- pickup stop and sets the delivery in transit.
2107                     p_sc_close_trip_flag      := 'Y'; -- Close the trip after ship confirm
2108 
2109                     -- p_sc_trip_ship_method := ''; -- The ship method code
2110                     p_sc_defer_interface_flag := 'N'; -- defer interface
2111 
2112                     -- p_sc_report_set_id    := 6; -- check if it is seeded
2113 
2114                     Debug('Calling Delivery_Action ', l_mod_name, 1);
2115 
2116                     -- Call to WSH_DELIVERIES_PUB.Delivery_Action.
2117                     Wsh_Deliveries_Pub.Delivery_Action(p_api_version_number      => 1.0,
2118                                                        p_init_msg_list           => p_init_msg_list,
2119                                                        x_return_status           => x_return_status,
2120                                                        x_msg_count               => x_msg_count,
2121                                                        x_msg_data                => x_msg_data,
2122                                                        p_action_code             => p_action_code,
2123                                                        p_delivery_id             => p_delivery_id,
2124                                                        p_delivery_name           => p_delivery_name,
2125                                                        p_asg_trip_id             => p_asg_trip_id,
2126                                                        p_asg_trip_name           => p_asg_trip_name,
2127                                                        p_asg_pickup_stop_id      => p_asg_pickup_stop_id,
2128                                                        p_asg_pickup_loc_id       => p_asg_pickup_loc_id,
2129                                                        p_asg_pickup_loc_code     => p_asg_pickup_loc_code,
2130                                                        p_asg_pickup_arr_date     => p_asg_pickup_arr_date,
2131                                                        p_asg_pickup_dep_date     => p_asg_pickup_dep_date,
2132                                                        p_asg_dropoff_stop_id     => p_asg_dropoff_stop_id,
2133                                                        p_asg_dropoff_loc_id      => p_asg_dropoff_loc_id,
2134                                                        p_asg_dropoff_loc_code    => p_asg_dropoff_loc_code,
2135                                                        p_asg_dropoff_arr_date    => p_asg_dropoff_arr_date,
2136                                                        p_asg_dropoff_dep_date    => p_asg_dropoff_dep_date,
2137                                                        p_sc_action_flag          => p_sc_action_flag,
2138                                                        p_sc_intransit_flag       => p_sc_intransit_flag,
2139                                                        p_sc_close_trip_flag      => p_sc_close_trip_flag,
2140                                                        p_sc_create_bol_flag      => p_sc_create_bol_flag,
2141                                                        p_sc_stage_del_flag       => p_sc_stage_del_flag,
2142                                                        p_sc_trip_ship_method     => p_sc_trip_ship_method,
2143                                                        p_sc_actual_dep_date      => p_sc_actual_dep_date,
2144                                                        p_sc_report_set_id        => p_sc_report_set_id,
2145                                                        p_sc_report_set_name      => p_sc_report_set_name,
2146                                                        p_sc_defer_interface_flag => p_sc_defer_interface_flag,
2147                                                        p_wv_override_flag        => p_wv_override_flag,
2148                                                        x_trip_id                 => x_trip_id,
2149                                                        x_trip_name               => x_trip_name);
2150 
2151                     Debug('x_return_status(Delivery_Action )=' ||
2152                           x_return_status,
2153                           l_mod_name,
2154                           1);
2155 
2156                     IF (x_return_status <> Wsh_Util_Core.G_RET_STS_SUCCESS)
2157                     THEN
2158                         Debug('Delivery_Action failed', l_mod_name, 1);
2159                         RAISE fail_api;
2160                     END IF;
2161                 EXCEPTION
2162                     WHEN fail_api THEN
2163                         Wsh_Util_Core.get_messages('Y',
2164                                                    x_msg_summary,
2165                                                    x_msg_details,
2166                                                    x_msg_count);
2167                         IF x_msg_count > 1
2168                         THEN
2169                             x_msg_data := x_msg_summary || x_msg_details;
2170                         ELSE
2171                             x_msg_data := x_msg_summary;
2172                         END IF;
2173                         Debug('Error Msg from Delivery_Action',
2174                               l_mod_name,
2175                               1);
2176                         Debug('x_msg_data = ' || x_msg_data, l_mod_name, 1);
2177                         -- Ignore if it is a warning
2178                         IF (x_return_status <>
2179                            Wsh_Util_Core.G_RET_STS_WARNING)
2180                         THEN
2181                             Fnd_Message.SET_NAME('CSD',
2182                                                  'CSD_SHIP_CONFIRM_FAILED');
2183                             Fnd_Message.SET_TOKEN('ERR_MSG', x_msg_data);
2184                             Fnd_Msg_Pub.ADD;
2185                             RAISE Fnd_Api.G_EXC_ERROR;
2186                         END IF;
2187                         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
2188                 END; -- end of delivery action
2189 
2190             END LOOP; -- At the end of processing all the delivery id for an Order
2191         END IF; -- end of all actions
2192 
2193         -- Api body ends here
2194 
2195         -- Standard check of p_commit.
2196         IF Fnd_Api.To_Boolean(p_commit)
2197         THEN
2198             COMMIT WORK;
2199         END IF;
2200 
2201         -- Standard call to get message count and IF count is  get message info.
2202         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2203                                   p_data  => x_msg_data);
2204 
2205     EXCEPTION
2206         WHEN Fnd_Api.G_EXC_ERROR THEN
2207 		  Debug('In EXC_ERROR in process_sales_order', l_mod_name, 1);
2208             ROLLBACK TO process_sales_order;
2209 
2210             x_return_status := Fnd_Api.G_RET_STS_ERROR;
2211             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2212                                       p_data  => x_msg_data);
2213 
2214         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
2215 		  Debug('In EXC_UNEXP_ERROR in process_sales_order', l_mod_name, 1);
2216             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
2217             ROLLBACK TO process_sales_order;
2218             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2219                                       p_data  => x_msg_data);
2220         WHEN OTHERS THEN
2221             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
2222 		  Debug('In OTHERS in process_sales_order' || sqlerrm, l_mod_name, 1);
2223             ROLLBACK TO process_sales_order;
2224             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
2225             THEN
2226                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
2227             END IF;
2228             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2229                                       p_data  => x_msg_data);
2230     END process_sales_order;
2231 
2232     /*------------------------------------------------------------------*/
2233     /* Procedure name: Create_product_txn                               */
2234     /* Description   : Procedure to create product transaction lines    */
2235     /*               1. It may from the ON-INSERT trigger in repair     */
2236     /*                  order form for creating ptoduct txn manually.   */
2237     /*               2. It may be also called from create_default_txn   */
2238     /*                  API to create product txn at the time creating  */
2239     /*                  repair orders                                   */
2240     /*------------------------------------------------------------------*/
2241 
2242     PROCEDURE create_product_txn(p_api_version      IN NUMBER,
2243                                  p_commit           IN VARCHAR2 := Fnd_Api.g_false,
2244                                  p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
2245                                  p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
2246                                  x_product_txn_rec  IN OUT NOCOPY PRODUCT_TXN_REC,
2247                                  x_return_status    OUT NOCOPY VARCHAR2,
2248                                  x_msg_count        OUT NOCOPY NUMBER,
2249                                  x_msg_data         OUT NOCOPY VARCHAR2) IS
2250 
2251         l_api_name    CONSTANT VARCHAR2(30) := 'CREATE_PRODUCT_TXN';
2252         l_api_version CONSTANT NUMBER := 1.0;
2253         l_msg_count              NUMBER;
2254         l_msg_data               VARCHAR2(2000);
2255         l_msg_index              NUMBER;
2256         l_product_transaction_id NUMBER := NULL;
2257         l_serial_flag            BOOLEAN := FALSE;
2258         l_dummy                  VARCHAR2(1);
2259         l_check                  VARCHAR2(1);
2260         l_Charges_Rec            Cs_Charge_Details_Pub.Charges_Rec_type;
2261         l_estimate_Rec           Cs_Charge_Details_Pub.Charges_Rec_type;
2262         l_estimate_detail_id     NUMBER := NULL;
2263         x_estimate_detail_id     NUMBER := NULL;
2264         l_incident_id            NUMBER := NULL;
2265         l_order_rec              OM_INTERFACE_REC;
2266         l_reference_number       VARCHAR2(30) := '';
2267         l_contract_number        VARCHAR2(120) := '';
2268         l_bus_process_id         NUMBER := NULL;
2269         l_repair_type_ref        VARCHAR2(3) := '';
2270         l_line_type_id           NUMBER := NULL;
2271         l_txn_billing_type_id    NUMBER := NULL;
2272         l_party_id               NUMBER := NULL;
2273         l_account_id             NUMBER := NULL;
2274         l_order_header_id        NUMBER := NULL;
2275         l_release_status         VARCHAR2(10) := '';
2276         l_curr_code              VARCHAR2(10) := '';
2277         l_picking_rule_id        NUMBER := NULL;
2278         l_ship_qty               NUMBER := NULL;
2279         l_line_category_code     VARCHAR2(30) := '';
2280         l_ship_from_org_id       NUMBER := NULL;
2281         l_order_line_id          NUMBER := NULL;
2282         l_coverage_id            NUMBER := NULL;
2283         -- Bugfix 3617932, vkjain.
2284         -- Increasing the column length to 150
2285         -- l_coverage_name          VARCHAR2(150) := ''; -- Commented for bugfix 3617932
2286         l_txn_group_id        NUMBER := NULL;
2287         l_unit_selling_price  NUMBER := NULL;
2288         l_transaction_type_id NUMBER := NULL;
2289         l_order_category_code VARCHAR2(30);
2290         l_add_to_same_order   BOOLEAN;
2291         l_orig_src_reference  VARCHAR2(30);
2292         l_orig_src_header_id  NUMBER;
2293         l_orig_src_line_id    NUMBER;
2294         l_orig_po_num         VARCHAR2(50);
2295         l_rev_ctl_code        mtl_system_items.revision_qty_control_code%TYPE;
2296         l_booked_flag         oe_order_headers_all.booked_flag%TYPE;
2297 
2298         --taklam
2299         l_Line_Tbl_Type         OE_ORDER_PUB.Line_Tbl_Type;
2300         x_Line_Tbl_Type         OE_ORDER_PUB.Line_Tbl_Type;
2301         l_p_ship_from_org_id     NUMBER;
2302         l_project_count          NUMBER;
2303 
2304         l_sr_account_id        NUMBER; -- swai: bug 6001057
2305 
2306         create_order EXCEPTION;
2307         book_order EXCEPTION;
2308         release_order EXCEPTION;
2309         ship_order EXCEPTION;
2310 
2311         --Bug fix for 3399883 [
2312         l_no_contract_bp_vldn VARCHAR2(10);
2313         --]
2314 
2315         CURSOR order_rec(p_incident_id IN NUMBER) IS
2316             SELECT customer_id, account_id
2317               FROM cs_incidents_all_b
2318              WHERE incident_id = p_incident_id;
2319 
2320         CURSOR estimate(p_rep_line_id IN NUMBER) IS
2321             SELECT estimate_detail_id, object_version_number
2322               FROM cs_estimate_details
2323              WHERE source_id = p_rep_line_id
2324                AND source_code = 'DR'
2325                AND interface_to_oe_flag = 'N'
2326                AND order_header_id IS NULL
2327                AND order_line_id IS NULL;
2328 
2329         --taklam
2330         CURSOR project_cu(l_project_id NUMBER, l_p_ship_from_org_id NUMBER) IS
2331         SELECT COUNT(*) p_count
2332         FROM PJM_PROJECTS_ORG_V
2333         WHERE project_id = l_project_id and inventory_organization_id = l_p_ship_from_org_id;
2334 
2335         CURSOR order_line_cu(l_est_detail_id NUMBER) is
2336         SELECT b.order_line_id, a.ship_from_org_id
2337         FROM oe_order_lines_all a, cs_estimate_details b
2338         WHERE a.line_id = b.order_line_id
2339         AND  b.estimate_detail_id = l_est_detail_id;
2340 
2341         -- swai: bug 6001057
2342         CURSOR sr_account_cu (l_repair_line_id NUMBER) is
2343         SELECT account_id
2344         FROM cs_incidents_all_b cs, csd_repairs csd
2345         WHERE cs.incident_id = csd.incident_id
2346           AND repair_line_id = l_repair_line_id;
2347 
2348         --R12 Development Changes Begin
2349         CURSOR cur_pick_rules(p_pick_rule_id NUMBER) IS
2350             SELECT 'x'
2351               FROM wsh_picking_rules
2352              WHERE picking_rule_id = p_pick_rule_id
2353                AND SYSDATE BETWEEN NVL(start_Date_Active, SYSDATE) AND
2354                    NVL(end_Date_active, SYSDATE + 1);
2355         --R12 Development Changes End
2356 
2357         -- Variables used in FND Log
2358         l_error_level NUMBER := Fnd_Log.LEVEL_ERROR;
2359         l_mod_name    VARCHAR2(2000) := 'csd.plsql.csd_process_pvt.create_product_txn';
2360         l_tmp_char    VARCHAR2(1); --R12 Development Changes
2361       /* R12 SN reservations integration change Begin */
2362       l_ItemAttributes Csd_Logistics_Util.ItemAttributes_Rec_Type;
2363       l_auto_reserve_profile  VARCHAR2(10);
2364       l_srl_reservation_id NUMBER;
2365       l_serial_rsv_rec CSD_LOGISTICS_UTIL.CSD_SERIAL_RESERVE_REC_TYPE ;
2366       /* R12 SN reservations integration change End */
2367 
2368       -- swai bug 7572247/7628204: cursor to default account address for SR account
2369       CURSOR c_sr_primary_account_address(p_incident_id NUMBER, p_site_use_type VARCHAR2)
2370       IS
2371             select distinct
2372                    hp.party_site_id
2373               from hz_party_sites_v hp,
2374                    hz_parties hz,
2375                    hz_cust_acct_sites_all hca,
2376                    hz_cust_site_uses_all hcsu,
2377                    cs_incidents_all_b cs
2378              where hcsu.site_use_code = p_site_use_type
2379               and  cs.incident_id = p_incident_id
2380               and  hp.status = 'A'
2381               and  hcsu.status = 'A'
2382               and  hp.party_id = hz.party_id
2383               and  hca.party_site_id = hp.party_site_id
2384               and  hca.cust_account_id = cs.account_id
2385               and  hcsu.cust_acct_site_id = hca.cust_acct_site_id
2386               and  hca.org_id = cs.org_id
2387               and  hcsu.primary_flag = 'Y'
2388               and rownum = 1;
2389 
2390     BEGIN
2391         -- Debug message
2392         Debug('At the Beginning of create_product_txn', l_mod_name, 1);
2393 
2394         -- Standard Start of API savepoint
2395         SAVEPOINT create_product_txn;
2396 
2397         -- Initialize API return status to success
2398         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
2399 
2400         -- Standard call to check for call compatibility.
2401         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
2402                                            p_api_version,
2403                                            l_api_name,
2404                                            G_PKG_NAME)
2405         THEN
2406             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
2407         END IF;
2408 
2409         -- Initialize message list if p_init_msg_list is set to TRUE.
2410         IF Fnd_Api.to_Boolean(p_init_msg_list)
2411         THEN
2412             Fnd_Msg_Pub.initialize;
2413         END IF;
2414 
2415         -- Api body starts
2416 
2417         -- Dump the IN parameters in the log file
2418         -- if the debug level > 5
2419         IF (g_debug > 5)
2420         THEN
2421             Csd_Gen_Utility_Pvt.dump_prod_txn_rec(p_prod_txn_rec => x_product_txn_rec);
2422         END IF;
2423 
2424         Debug('********* Check reqd parameter ***************',
2425               l_mod_name,
2426               1);
2427         Debug('Repair Line ID      =' || x_product_txn_rec.repair_line_id,
2428               l_mod_name,
2429               1);
2430         Debug('Action Code         =' || x_product_txn_rec.action_code,
2431               l_mod_name,
2432               1);
2433         Debug('Action Type         =' || x_product_txn_rec.action_type,
2434               l_mod_name,
2435               1);
2436         Debug('Txn_billing_type_id =' ||
2437               x_product_txn_rec.txn_billing_type_id,
2438               l_mod_name,
2439               1);
2440 
2441         -- Check the required parameter(txn_billing_type_id)
2442         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.txn_billing_type_id,
2443                                           p_param_name  => 'TXN_BILLING_TYPE_ID',
2444                                           p_api_name    => l_api_name);
2445 
2446         -- Check the required parameter(inventory_item_id)
2447         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.inventory_item_id,
2448                                           p_param_name  => 'INVENTORY_ITEM_ID',
2449                                           p_api_name    => l_api_name);
2450 
2451         -- Check the required parameter(unit_of_measure_code)
2452         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.unit_of_measure_code,
2453                                           p_param_name  => 'UNIT_OF_MEASURE_CODE',
2454                                           p_api_name    => l_api_name);
2455 
2456         -- Check the required parameter(quantity)
2457         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.quantity,
2458                                           p_param_name  => 'QUANTITY',
2459                                           p_api_name    => l_api_name);
2460 
2461         -- Check the required parameter(price_list_id)
2462         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.price_list_id,
2463                                           p_param_name  => 'PRICE_LIST_ID',
2464                                           p_api_name    => l_api_name);
2465 
2466         Debug('Validate repair line id', l_mod_name, 1);
2467 
2468         -- Validate the repair line ID if it exists in csd_repairs
2469         IF NOT
2470             (Csd_Process_Util.Validate_rep_line_id(p_repair_line_id => x_product_txn_rec.repair_line_id))
2471         THEN
2472             RAISE Fnd_Api.G_EXC_ERROR;
2473         END IF;
2474 
2475         Debug('Validate action type', l_mod_name, 1);
2476 
2477         -- Validate the Action Type if it exists in fnd_lookups
2478         IF NOT
2479             (Csd_Process_Util.Validate_action_type(p_action_type => x_product_txn_rec.action_type))
2480         THEN
2481             RAISE Fnd_Api.G_EXC_ERROR;
2482         END IF;
2483 
2484         Debug('Validate action code', l_mod_name, 1);
2485 
2486         -- Validate the repair line ID if it exists in fnd_lookups
2487         IF NOT
2488             (Csd_Process_Util.Validate_action_code(p_action_code => x_product_txn_rec.action_code))
2489         THEN
2490             RAISE Fnd_Api.G_EXC_ERROR;
2491         END IF;
2492 
2493         --R12 Development changes begin
2494         Debug('Validating picking rule if passed[' ||
2495               x_producT_txn_rec.picking_rule_id || ']',
2496               l_mod_name,
2497               1);
2498         IF (x_producT_txn_rec.picking_rule_id <> NULL)
2499         THEN
2500             OPEN cur_pick_rules(x_producT_txn_rec.picking_rule_id);
2501             FETCH cur_pick_rules
2502                 INTO l_tmp_char;
2503             IF (cur_pick_rules%NOTFOUND)
2504             THEN
2505                 Fnd_Message.SET_NAME('CSD', 'CSD_INV_PICK_RULE');
2506                 Fnd_Msg_Pub.ADD;
2507                 RAISE Fnd_Api.G_EXC_ERROR;
2508             END IF;
2509         END IF;
2510         --R12 Development changes End
2511 
2512         Debug('Validate product txn qty', l_mod_name, 1);
2513         Debug('x_product_txn_rec.quantity =' || x_product_txn_rec.quantity,
2514               l_mod_name,
2515               1);
2516 
2517         -- Validate if the product txn quantity (customer product only)
2518         -- is not exceeding the repair order quantity
2519         -- swai: bug 5931926 - 12.0.2 do not validate quantity for third party lines
2520         -- since multiple parts can be shipped out.
2521         IF x_product_txn_rec.action_code = 'CUST_PROD' AND
2522            x_product_txn_rec.action_type not in ('RMA_THIRD_PTY', 'SHIP_THIRD_PTY')
2523         THEN
2524             Csd_Process_Util.Validate_quantity(p_action_type    => x_product_txn_rec.action_type,
2525                                                p_repair_line_id => x_product_txn_rec.repair_line_id,
2526                                                p_prod_txn_qty   => x_product_txn_rec.quantity,
2527                                                x_return_status  => x_return_status);
2528             IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
2529             THEN
2530                 Debug('Validate_Quantity failed ', l_mod_name, 1);
2531                 RAISE Fnd_Api.G_EXC_ERROR;
2532             END IF;
2533         END IF;
2534 
2535         Debug('Validate product txn status', l_mod_name, 1);
2536         Debug('x_product_txn_rec.PROD_TXN_STATUS =' ||
2537               x_product_txn_rec.PROD_TXN_STATUS,
2538               l_mod_name,
2539               1);
2540 
2541         -- Validate the PROD_TXN_STATUS if it exists in fnd_lookups
2542         IF (x_product_txn_rec.PROD_TXN_STATUS IS NOT NULL) AND
2543            (x_product_txn_rec.PROD_TXN_STATUS <> Fnd_Api.G_MISS_CHAR)
2544         THEN
2545             BEGIN
2546                 SELECT 'X'
2547                   INTO l_check
2548                   FROM fnd_lookups
2549                  WHERE lookup_type = 'CSD_PRODUCT_TXN_STATUS'
2550                    AND lookup_code = x_product_txn_rec.PROD_TXN_STATUS;
2551             EXCEPTION
2552                 WHEN OTHERS THEN
2553                     Fnd_Message.SET_NAME('CSD', 'CSD_ERR_PROD_TXN_STATUS');
2554                     Fnd_Msg_Pub.ADD;
2555                     RAISE Fnd_Api.G_EXC_ERROR;
2556             END;
2557         END IF;
2558 
2559         -- Get service request from csd_repairs table
2560         -- using repair order
2561         BEGIN
2562             SELECT incident_id,
2563                    original_source_reference,
2564                    original_source_header_id,
2565                    original_source_line_id
2566               INTO l_incident_id,
2567                    l_orig_src_reference,
2568                    l_orig_src_header_id,
2569                    l_orig_src_line_id
2570               FROM csd_repairs
2571              WHERE repair_line_id = x_product_txn_rec.repair_line_id;
2572         EXCEPTION
2573             WHEN OTHERS THEN
2574                 Fnd_Message.SET_NAME('CSD', 'CSD_API_INV_REP_LINE_ID');
2575                 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
2576                                       x_product_txn_rec.repair_line_id);
2577                 Fnd_Msg_Pub.ADD;
2578                 RAISE Fnd_Api.G_EXC_ERROR;
2579         END;
2580 
2581         Debug('l_incident_id    =' || l_incident_id, l_mod_name, 1);
2582 
2583         -- Get the business process id
2584         -- Forward bug fix # 2756313
2585         -- l_bus_process_id := CSD_PROCESS_UTIL.GET_BUS_PROCESS(l_incident_id);
2586 
2587         l_bus_process_id := Csd_Process_Util.GET_BUS_PROCESS(x_product_txn_rec.repair_line_id);
2588 
2589         Debug('l_bus_process_id =' || l_bus_process_id, l_mod_name, 1);
2590 
2591         IF l_bus_process_id < 0
2592         THEN
2593             IF NVL(x_product_txn_rec.business_process_id,
2594                    Fnd_Api.G_MISS_NUM) <> Fnd_Api.G_MISS_NUM
2595             THEN
2596                 l_bus_process_id := x_product_txn_rec.business_process_id;
2597             ELSE
2598                 Debug('Business process Id does not exist ', l_mod_name, 1);
2599                 RAISE Fnd_Api.G_EXC_ERROR;
2600             END IF;
2601         END IF;
2602 
2603         Debug('Getting the Coverage and txn Group Id', l_mod_name, 1);
2604         Debug('contract_line_id =' || x_product_txn_rec.contract_id,
2605               l_mod_name,
2606               1);
2607 
2608         IF (x_product_txn_rec.transaction_type_id IS NULL) OR
2609            (x_product_txn_rec.transaction_type_id = Fnd_Api.G_MISS_NUM)
2610         THEN
2611             BEGIN
2612                 SELECT transaction_type_id
2613                   INTO l_transaction_type_id
2614                   FROM cs_txn_billing_types
2615                  WHERE txn_billing_type_id =
2616                        x_product_txn_rec.txn_billing_type_id;
2617             EXCEPTION
2618                 WHEN NO_DATA_FOUND THEN
2619                     Debug('No Row found for the txn_billing_type_id=' ||
2620                           TO_CHAR(l_txn_billing_type_id),
2621                           l_mod_name,
2622                           1);
2623                 WHEN OTHERS THEN
2624                     Debug('When others exception at - Transaction type id',
2625                           l_mod_name,
2626                           1);
2627             END;
2628             x_product_txn_rec.transaction_type_id := l_transaction_type_id;
2629             Debug('x_product_txn_rec.transaction_type_id :' ||
2630                   TO_CHAR(x_product_txn_rec.transaction_type_id),
2631                   l_mod_name,
2632                   1);
2633         END IF;
2634 
2635         -- Get the coverage details from the contract
2636 		/******************************contract changes
2637         IF NVL(x_product_txn_rec.contract_id, Fnd_Api.G_MISS_NUM) <>
2638            Fnd_Api.G_MISS_NUM
2639         THEN
2640             BEGIN
2641                 --Bug fix for 3399883 [
2642                 l_no_contract_bp_vldn := NVL(Fnd_Profile.value('CSD_NO_CONTRACT_BP_VLDN'),
2643                                              'N');
2644 
2645                 IF (l_no_contract_bp_vldn = 'Y')
2646                 THEN
2647 
2648                     SELECT cov.actual_coverage_id,
2649                            -- cov.coverage_name, -- Commented for bugfix 3617932
2650                            ent.txn_group_id
2651                       INTO l_coverage_id,
2652                            -- l_coverage_name, -- Commented for bugfix 3617932
2653                            l_txn_group_id
2654                       FROM oks_ent_coverages_v  cov,
2655                            oks_ent_txn_groups_v ent
2656                      WHERE cov.contract_line_id =
2657                            x_product_txn_rec.contract_id
2658                        AND cov.actual_coverage_id = ent.coverage_id;
2659                 ELSE
2660                     --]
2661 
2662                     SELECT cov.actual_coverage_id,
2663                            -- cov.coverage_name,  -- Commented for bugfix 3617932
2664                            ent.txn_group_id
2665                       INTO l_coverage_id,
2666                            -- l_coverage_name, -- Commented for bugfix 3617932
2667                            l_txn_group_id
2668                       FROM oks_ent_coverages_v  cov,
2669                            oks_ent_txn_groups_v ent
2670                      WHERE cov.contract_line_id =
2671                            x_product_txn_rec.contract_id
2672                        AND cov.actual_coverage_id = ent.coverage_id
2673                        AND ent.business_process_id = l_bus_process_id;
2674                     --Bug fix for 3399883 [
2675                 END IF;
2676                 --]
2677             EXCEPTION
2678                 WHEN NO_DATA_FOUND THEN
2679                     Fnd_Message.SET_NAME('CSD', 'CSD_API_CONTRACT_MISSING');
2680                     Fnd_Message.SET_TOKEN('CONTRACT_LINE_ID',
2681                                           x_product_txn_rec.contract_id);
2682                     Fnd_Msg_Pub.ADD;
2683                     Debug('Contract Line Id missing', l_mod_name, 1);
2684                     RAISE Fnd_Api.G_EXC_ERROR;
2685                 WHEN TOO_MANY_ROWS THEN
2686                     Debug('Too many Contract Line', l_mod_name, 1);
2687             END;
2688             x_product_txn_rec.coverage_id           := l_coverage_id;
2689             x_product_txn_rec.coverage_txn_group_id := l_txn_group_id;
2690 
2691             Debug('l_coverage_id  =' || l_coverage_id, l_mod_name, 1);
2692             Debug('l_txn_group_id =' || l_txn_group_id, l_mod_name, 1);
2693         END IF;
2694 		*******************************/
2695 
2696         IF l_incident_id IS NOT NULL
2697         THEN
2698             -- swai: bug 5931926 - 12.0.2 3rd party logistics
2699             -- only set order header info to SR party and account
2700             -- if it is not specified on the bill-to for the txn line.
2701             IF (nvl(l_Charges_Rec.bill_to_account_id, FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM) OR
2702                (nvl(l_Charges_Rec.bill_to_party_id, FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM) THEN
2703                OPEN order_rec(l_incident_id);
2704                FETCH order_rec
2705                    INTO l_party_id, l_account_id;
2706                IF (order_rec%NOTFOUND OR l_party_id IS NULL)
2707                THEN
2708                    Fnd_Message.SET_NAME('CSD', 'CSD_API_PARTY_MISSING');
2709                    Fnd_Message.SET_TOKEN('INCIDENT_ID', l_incident_id);
2710                    Fnd_Msg_Pub.ADD;
2711                    RAISE Fnd_Api.G_EXC_ERROR;
2712                END IF;
2713                IF order_rec%ISOPEN
2714                THEN
2715                    CLOSE order_rec;
2716                END IF;
2717             ELSE
2718                l_party_id := l_Charges_Rec.bill_to_party_id;
2719                l_account_id := l_Charges_Rec.bill_to_account_id;
2720             END IF;
2721         END IF;
2722 
2723         Debug('l_party_id                            =' || l_party_id,
2724               l_mod_name,
2725               1);
2726         Debug('l_account_id                          =' || l_account_id,
2727               l_mod_name,
2728               1);
2729         Debug('x_product_txn_rec.txn_billing_type_id =' ||
2730               x_product_txn_rec.txn_billing_type_id,
2731               l_mod_name,
2732               1);
2733         Debug('x_product_txn_rec.organization_id     =' ||
2734               x_product_txn_rec.organization_id,
2735               l_mod_name,
2736               1);
2737 
2738         -- Derive the line type and line category code
2739         -- from the transaction billing type
2740         Csd_Process_Util.GET_LINE_TYPE(p_txn_billing_type_id => x_product_txn_rec.txn_billing_type_id,
2741                                        p_org_id              => x_product_txn_rec.organization_id,
2742                                        x_line_type_id        => l_line_type_id,
2743                                        x_line_category_code  => l_line_category_code,
2744                                        x_return_status       => x_return_status);
2745 
2746         IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
2747         THEN
2748             RAISE Fnd_Api.G_EXC_ERROR;
2749         END IF;
2750 
2751         Debug('l_line_type_id                  =' || l_line_type_id,
2752               l_mod_name,
2753               1);
2754         Debug('l_line_category_code            =' || l_line_category_code,
2755               l_mod_name,
2756               1);
2757         Debug('x_product_txn_rec.price_list_id =' ||
2758               x_product_txn_rec.price_list_id,
2759               l_mod_name,
2760               1);
2761 
2762         -- If line_type_id Or line_category_code is null
2763         -- then raise error
2764         IF (l_line_type_id IS NULL OR l_line_category_code IS NULL)
2765         THEN
2766             Fnd_Message.SET_NAME('CSD', 'CSD_API_LINE_TYPE_MISSING');
2767             Fnd_Message.SET_TOKEN('TXN_BILLING_TYPE_ID',
2768                                   x_product_txn_rec.txn_billing_type_id);
2769             Fnd_Msg_Pub.ADD;
2770             RAISE Fnd_Api.G_EXC_ERROR;
2771         END IF;
2772 
2773         -- Get the currency code from the price list if it is null or g_miss
2774         IF NVL(x_product_txn_rec.price_list_id, Fnd_Api.G_MISS_NUM) <>
2775            Fnd_Api.G_MISS_NUM
2776         THEN
2777             BEGIN
2778                 SELECT currency_code
2779                   INTO l_curr_code
2780                   FROM oe_price_lists
2781                  WHERE price_list_id = x_product_txn_rec.price_list_id;
2782             EXCEPTION
2783                 WHEN NO_DATA_FOUND THEN
2784                     Fnd_Message.SET_NAME('CSD',
2785                                          'CSD_API_INV_PRICE_LIST_ID');
2786                     Fnd_Message.SET_TOKEN('PRICE_LIST_ID',
2787                                           x_product_txn_rec.price_list_id);
2788                     Fnd_Msg_Pub.ADD;
2789                     RAISE Fnd_Api.G_EXC_ERROR;
2790                 WHEN TOO_MANY_ROWS THEN
2791                     Debug('Too many currency_codes', l_mod_name, 1);
2792             END;
2793         END IF;
2794 
2795         Debug('l_curr_code          =' || l_curr_code, l_mod_name, 1);
2796 
2797         -- If l_curr_code is null then raise error
2798         IF l_curr_code IS NULL
2799         THEN
2800             Fnd_Message.SET_NAME('CSD', 'CSD_API_INV_CURR_CODE');
2801             Fnd_Message.SET_TOKEN('PRICE_LIST_ID',
2802                                   x_product_txn_rec.price_list_id);
2803             Fnd_Msg_Pub.ADD;
2804             RAISE Fnd_Api.G_EXC_ERROR;
2805         END IF;
2806 
2807         l_serial_flag := Csd_Process_Util.Is_item_serialized(x_product_txn_rec.inventory_item_id);
2808 
2809         -- swai: bug 5931926 - 12.0.2 3rd party logistics
2810         -- Instead of adding 3rd party action types to if-then statement,
2811         -- we are commenting the code out altogether.  Currently,
2812         -- if conditions do not allow any product transaction lines
2813         -- through except walk-in-receipt which is no longer supported.
2814         -- We should allow RMA line creation without Serial number for
2815         -- all action types.
2816         /*****
2817         -- Serial Number required if the item is serialized
2818         IF l_serial_flag AND
2819           -- changing from serial_number to source_serial_number 11.5.10
2820            NVL(x_product_txn_rec.source_serial_number, Fnd_Api.G_MISS_CHAR) =
2821            Fnd_Api.G_MISS_CHAR AND
2822            x_product_txn_rec.action_type NOT IN ('SHIP', 'WALK_IN_ISSUE') AND
2823            (x_product_txn_rec.action_code <> 'LOANER' AND
2824            x_product_txn_rec.action_type <> 'RMA')
2825         THEN
2826             Fnd_Message.SET_NAME('CSD', 'CSD_API_SERIAL_NUM_MISSING');
2827             Fnd_Message.SET_TOKEN('INVENTORY_ITEM_ID',
2828                                   x_product_txn_rec.inventory_item_id);
2829             Fnd_Msg_Pub.ADD;
2830             Debug('Serial Number missing for inventory_item_id =' ||
2831                   x_product_txn_rec.inventory_item_id,
2832                   l_mod_name,
2833                   1);
2834             RAISE Fnd_Api.G_EXC_ERROR;
2835         END IF;
2836         *****/
2837 
2838         IF (x_product_txn_rec.new_order_flag = 'N')
2839         THEN
2840           -- Fix for bug# 4913791
2841           IF ( x_product_txn_rec.interface_to_om_flag = 'Y' ) THEN
2842             x_product_txn_rec.add_to_order_flag := 'Y';
2843             x_product_txn_rec.order_header_id   := x_product_txn_rec.add_to_order_id;
2844           ELSE
2845             x_product_txn_rec.add_to_order_flag := 'F';
2846             x_product_txn_rec.order_header_id := FND_API.G_MISS_NUM;
2847           END IF;
2848 
2849         ELSIF (x_product_txn_rec.new_order_flag = 'Y')
2850         THEN
2851             x_product_txn_rec.add_to_order_flag := 'F';
2852             x_product_txn_rec.order_header_id   := Fnd_Api.G_MISS_NUM;
2853         END IF;
2854 
2855         Debug('x_product_txn_rec.new_order_flag =' ||
2856               x_product_txn_rec.new_order_flag,
2857               l_mod_name,
2858               1);
2859         Debug('x_product_txn_rec.add_to_order_flag =' ||
2860               x_product_txn_rec.add_to_order_flag,
2861               l_mod_name,
2862               1);
2863         Debug('x_product_txn_rec.order_header_id =' ||
2864               x_product_txn_rec.order_header_id,
2865               l_mod_name,
2866               1);
2867 
2868         -- assigning values for the charge record
2869         x_product_txn_rec.incident_id         := l_incident_id;
2870         x_product_txn_rec.business_process_id := l_bus_process_id;
2871         x_product_txn_rec.line_type_id        := l_line_type_id;
2872         x_product_txn_rec.currency_code       := l_curr_code;
2873         x_product_txn_rec.line_category_code  := l_line_category_code;
2874 
2875         -- swai bug 7572247/7628204: default account primary bill-to and ship to
2876         IF ((l_incident_id is not NULL) AND
2877             (nvl(fnd_profile.value('CSD_DEFAULT_SR_ACCT_ADDR_FOR_LOGISTICS'), 'N') = 'Y'))
2878         THEN
2879 
2880             IF ((nvl(x_product_txn_rec.bill_to_account_id, FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM) AND
2881                 (nvl(x_product_txn_rec.invoice_to_org_id, FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM))
2882             THEN
2883                 OPEN c_sr_primary_account_address (l_incident_id, 'BILL_TO');
2884                 FETCH c_sr_primary_account_address INTO x_product_txn_rec.invoice_to_org_id;
2885                 IF c_sr_primary_account_address%ISOPEN THEN
2886                     CLOSE c_sr_primary_account_address;
2887                 END IF;
2888             END IF;
2889 
2890             IF ((nvl(x_product_txn_rec.ship_to_account_id, FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM) AND
2891                 (nvl(x_product_txn_rec.ship_to_org_id, FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM))
2892             THEN
2893                 OPEN c_sr_primary_account_address (l_incident_id, 'SHIP_TO');
2894                 FETCH c_sr_primary_account_address INTO x_product_txn_rec.ship_to_org_id;
2895                 IF c_sr_primary_account_address%ISOPEN THEN
2896                     CLOSE c_sr_primary_account_address;
2897                 END IF;
2898             END IF;
2899         END IF;
2900         -- end swai: bug 7572247/7628204
2901 
2902         Debug('Convert product txn rec to charges rec', l_mod_name, 1);
2903 
2904         -- Convert the product txn record to
2905         -- charge record
2906         Csd_Process_Util.CONVERT_TO_CHG_REC(p_prod_txn_rec  => x_product_txn_rec,
2907                                             x_charges_rec   => l_Charges_Rec,
2908                                             x_return_status => x_return_status);
2909 
2910         IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
2911         THEN
2912             RAISE Fnd_Api.G_EXC_ERROR;
2913         END IF;
2914 
2915         Debug('Call process_charge_lines to create charge lines ',
2916               l_mod_name,
2917               1);
2918         Debug('x_product_txn_rec.transaction_type_id :' ||
2919               TO_CHAR(x_product_txn_rec.transaction_type_id),
2920               l_mod_name,
2921               1);
2922         Debug('l_Charges_Rec.transaction_type_id :' ||
2923               TO_CHAR(l_Charges_Rec.transaction_type_id),
2924               l_mod_name,
2925               1);
2926 
2927         PROCESS_CHARGE_LINES(p_api_version        => 1.0,
2928                              p_commit             => Fnd_Api.g_false,
2929                              p_init_msg_list      => Fnd_Api.g_true,
2930                              p_validation_level   => Fnd_Api.g_valid_level_full,
2931                              p_action             => 'CREATE',
2932                              p_Charges_Rec        => l_Charges_Rec,
2933                              x_estimate_detail_id => x_estimate_detail_id,
2934                              x_return_status      => x_return_status,
2935                              x_msg_count          => x_msg_count,
2936                              x_msg_data           => x_msg_data);
2937 
2938         IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
2939         THEN
2940             RAISE Fnd_Api.G_EXC_ERROR;
2941         END IF;
2942 
2943         Debug('NEW ESTIMATE DETAIL ID    =' || x_estimate_detail_id,
2944               l_mod_name,
2945               1);
2946         Debug('Call csd_product_transactions_pkg.insert_row to insert prod txns',
2947               l_mod_name,
2948               1);
2949 
2950         -- Note (TTRV) at this point I would like to derive values for the new columns, every column is not
2951         -- use full for regular repair orders, some of the columns are used by regurlar repair orders but
2952         -- they need not be filled at the time of creation of product transaction record. Some of the columns
2953         -- are updated by update programs.
2954         -- Please come back and verify that for repair types, Exchange, Advance Exchange, Replacement
2955         -- non-source columns are picked from UI. These comments are added by saupadhy TTRV
2956         Csd_Product_Transactions_Pkg.INSERT_ROW(px_PRODUCT_TRANSACTION_ID  => x_product_txn_rec.PRODUCT_TRANSACTION_ID,
2957                                                 p_REPAIR_LINE_ID           => x_product_txn_rec.REPAIR_LINE_ID,
2958                                                 p_ESTIMATE_DETAIL_ID       => x_estimate_detail_id,
2959                                                 p_ACTION_TYPE              => x_product_txn_rec.ACTION_TYPE,
2960                                                 p_ACTION_CODE              => x_product_txn_rec.ACTION_CODE,
2961                                                 p_LOT_NUMBER               => x_product_txn_rec.LOT_NUMBER,
2962                                                 p_SUB_INVENTORY            => x_product_txn_rec.SUB_INVENTORY,
2963                                                 p_INTERFACE_TO_OM_FLAG     => 'N',
2964                                                 p_BOOK_SALES_ORDER_FLAG    => 'N',
2965                                                 p_RELEASE_SALES_ORDER_FLAG => 'N',
2966                                                 p_SHIP_SALES_ORDER_FLAG    => 'N',
2967                                                 p_PROD_TXN_STATUS          => 'ENTERED',
2968                                                 p_PROD_TXN_CODE            => x_product_txn_rec.PROD_TXN_CODE,
2969                                                 p_LAST_UPDATE_DATE         => SYSDATE,
2970                                                 p_CREATION_DATE            => SYSDATE,
2971                                                 p_LAST_UPDATED_BY          => Fnd_Global.USER_ID,
2972                                                 p_CREATED_BY               => Fnd_Global.USER_ID,
2973                                                 p_LAST_UPDATE_LOGIN        => Fnd_Global.USER_ID,
2974                                                 p_ATTRIBUTE1               => x_product_txn_rec.ATTRIBUTE1,
2975                                                 p_ATTRIBUTE2               => x_product_txn_rec.ATTRIBUTE2,
2976                                                 p_ATTRIBUTE3               => x_product_txn_rec.ATTRIBUTE3,
2977                                                 p_ATTRIBUTE4               => x_product_txn_rec.ATTRIBUTE4,
2978                                                 p_ATTRIBUTE5               => x_product_txn_rec.ATTRIBUTE5,
2979                                                 p_ATTRIBUTE6               => x_product_txn_rec.ATTRIBUTE6,
2980                                                 p_ATTRIBUTE7               => x_product_txn_rec.ATTRIBUTE7,
2981                                                 p_ATTRIBUTE8               => x_product_txn_rec.ATTRIBUTE8,
2982                                                 p_ATTRIBUTE9               => x_product_txn_rec.ATTRIBUTE9,
2983                                                 p_ATTRIBUTE10              => x_product_txn_rec.ATTRIBUTE10,
2984                                                 p_ATTRIBUTE11              => x_product_txn_rec.ATTRIBUTE11,
2985                                                 p_ATTRIBUTE12              => x_product_txn_rec.ATTRIBUTE12,
2986                                                 p_ATTRIBUTE13              => x_product_txn_rec.ATTRIBUTE13,
2987                                                 p_ATTRIBUTE14              => x_product_txn_rec.ATTRIBUTE14,
2988                                                 p_ATTRIBUTE15              => x_product_txn_rec.ATTRIBUTE15,
2989                                                 p_CONTEXT                  => x_product_txn_rec.CONTEXT,
2990                                                 p_OBJECT_VERSION_NUMBER    => 1,
2991                                                 P_SOURCE_SERIAL_NUMBER     => x_product_txn_rec.source_serial_number,
2992                                                 P_SOURCE_INSTANCE_ID       => x_product_txn_rec.source_instance_Id,
2993                                                 P_NON_SOURCE_SERIAL_NUMBER => x_product_txn_rec.non_source_serial_number,
2994                                                 P_NON_SOURCE_INSTANCE_ID   => x_product_txn_rec.non_source_instance_id,
2995                                                 P_REQ_HEADER_ID            => x_product_txn_rec.Req_Header_Id,
2996                                                 P_REQ_LINE_ID              => x_product_txn_rec.Req_Line_Id,
2997                                                 P_ORDER_HEADER_ID          => x_Product_Txn_Rec.Order_Header_Id,
2998                                                 P_ORDER_LINE_ID            => x_Product_Txn_Rec.Order_Line_Id,
2999                                                 P_PRD_TXN_QTY_RECEIVED     => x_product_txn_rec.Prd_Txn_Qty_Received,
3000                                                 P_PRD_TXN_QTY_SHIPPED      => x_product_txn_rec.Prd_Txn_Qty_Shipped,
3001                                                 P_SUB_INVENTORY_RCVD       => x_product_txn_rec.Sub_Inventory_Rcvd,
3002                                                 P_LOT_NUMBER_RCVD          => x_product_txn_rec.Lot_Number_Rcvd,
3003                                                 P_LOCATOR_ID               => x_product_txn_rec.Locator_Id,
3004                                                 --R12 Development Changes
3005                                                 p_picking_rule_id => x_product_txn_rec.picking_rule_id,
3006                                                 P_PROJECT_ID               => x_product_txn_rec.project_id,
3007                                                 P_TASK_ID                  => x_product_txn_rec.task_id,
3008                                                 P_UNIT_NUMBER              => x_product_txn_rec.unit_number,
3009                                                 P_INTERNAL_PO_HEADER_ID    => x_product_txn_rec.internal_po_header_id);  -- swai: bug 6148019
3010 
3011 
3012         Debug('NEW PRODUCT TXN ID = ' ||
3013               x_product_txn_rec.PRODUCT_TRANSACTION_ID,
3014               l_mod_name,
3015               1);
3016 
3017         UPDATE csd_repairs
3018            SET ro_txn_status = 'CHARGE_ENTERED'
3019          WHERE repair_line_id = x_product_txn_rec.REPAIR_LINE_ID;
3020         IF SQL%NOTFOUND
3021         THEN
3022             Fnd_Message.SET_NAME('CSD', 'CSD_ERR_REPAIRS_UPDATE');
3023             Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
3024                                   x_product_txn_rec.repair_line_id);
3025             Fnd_Msg_Pub.ADD;
3026             RAISE Fnd_Api.G_EXC_ERROR;
3027         END IF;
3028 
3029         -- Process the product txn only if the process_flag = 'Y'
3030         -- Else skip to the end and return the control to calling program
3031         IF x_product_txn_rec.process_txn_flag = 'Y'
3032         THEN
3033 
3034             -- Assigning values for the order record
3035             l_order_rec.incident_id := l_incident_id;
3036             l_order_rec.party_id    := l_party_id;
3037             l_order_rec.account_id  := l_account_id;
3038             l_order_rec.org_id      := Cs_Std.get_item_valdn_orgzn_id;
3039 
3040             -- Interface the charge line to OM if the flag is checked
3041             IF x_product_txn_rec.interface_to_om_flag = 'Y'
3042             THEN
3043 
3044                 BEGIN
3045 
3046                     -- Define savepoint
3047                     SAVEPOINT create_sales_order;
3048 
3049                     BEGIN
3050                         SELECT revision_qty_control_code
3051                           INTO l_rev_ctl_code
3052                           FROM mtl_system_items
3053                          WHERE organization_id =
3054                                Cs_Std.get_item_valdn_orgzn_id
3055                            AND inventory_item_id =
3056                                x_product_txn_rec.inventory_item_id;
3057                     EXCEPTION
3058                         WHEN NO_DATA_FOUND THEN
3059                             Fnd_Message.SET_NAME('CSD',
3060                                                  'CSD_INVALID_INVENTORY_ITEM');
3061                             Fnd_Msg_Pub.ADD;
3062                             RAISE CREATE_ORDER;
3063                     END;
3064 
3065                     IF l_rev_ctl_code = 2
3066                     THEN
3067                         BEGIN
3068                             SELECT 'x'
3069                               INTO l_dummy
3070                               FROM mtl_item_revisions
3071                              WHERE inventory_item_id =
3072                                    x_product_txn_rec.inventory_item_id
3073                                AND organization_id =
3074                                    Cs_Std.get_item_valdn_orgzn_id
3075                                AND revision = x_product_txn_rec.revision;
3076                         EXCEPTION
3077                             WHEN NO_DATA_FOUND THEN
3078                                 Fnd_Message.SET_NAME('CSD',
3079                                                      'CSD_INVALID_REVISION');
3080                                 Fnd_Msg_Pub.ADD;
3081                                 RAISE CREATE_ORDER;
3082                         END;
3083                     END IF;
3084 
3085                     Debug('Call process_sales_order to create SO',
3086                           l_mod_name,
3087                           1);
3088                     Debug('l_order_rec.incident_id =' ||
3089                           l_order_rec.incident_id,
3090                           l_mod_name,
3091                           1);
3092                     Debug('l_order_rec.party_id    =' ||
3093                           l_order_rec.party_id,
3094                           l_mod_name,
3095                           1);
3096                     Debug('l_order_rec.account_id  =' ||
3097                           l_order_rec.account_id,
3098                           l_mod_name,
3099                           1);
3100 
3101                   --taklam
3102                      if (x_product_txn_rec.unit_number) is not null then
3103                         FND_PROFILE.PUT('CSD_UNIT_NUMBER', x_product_txn_rec.unit_number);
3104                      end if;
3105 
3106                     PROCESS_SALES_ORDER(p_api_version      => 1.0,
3107                                         p_commit           => Fnd_Api.g_false,
3108                                         p_init_msg_list    => Fnd_Api.g_true,
3109                                         p_validation_level => Fnd_Api.g_valid_level_full,
3110                                         p_action           => 'CREATE',
3111                                         p_order_rec        => l_order_rec,
3112                                         x_return_status    => x_return_status,
3113                                         x_msg_count        => x_msg_count,
3114                                         x_msg_data         => x_msg_data);
3115 
3116                      if (x_product_txn_rec.unit_number) is not null then
3117                         FND_PROFILE.PUT('CSD_UNIT_NUMBER', null);
3118                      end if;
3119 
3120                     Debug('x_return_status from process_sales_order =' ||
3121                           x_return_status,
3122                           l_mod_name,
3123                           1);
3124 
3125                     IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
3126                     THEN
3127                         Debug('process_sales_order failed', l_mod_name, 1);
3128                         RAISE CREATE_ORDER;
3129                     END IF;
3130 
3131                     UPDATE csd_product_transactions
3132                        SET prod_txn_status      = 'SUBMITTED',
3133                            interface_to_om_flag = 'Y'
3134                      WHERE product_transaction_id =
3135                            x_product_txn_rec.PRODUCT_TRANSACTION_ID;
3136                     IF SQL%NOTFOUND
3137                     THEN
3138                         Fnd_Message.SET_NAME('CSD',
3139                                              'CSD_ERR_PRD_TXN_UPDATE');
3140                         Fnd_Message.SET_TOKEN('PRODUCT_TRANSACTION_ID',
3141                                               x_product_txn_rec.PRODUCT_TRANSACTION_ID);
3142                         Fnd_Msg_Pub.ADD;
3143                         RAISE CREATE_ORDER;
3144                     END IF;
3145 
3146                     UPDATE csd_repairs
3147                        SET ro_txn_status = 'OM_SUBMITTED'
3148                      WHERE repair_line_id =
3149                            x_product_txn_rec.REPAIR_LINE_ID;
3150                     IF SQL%NOTFOUND
3151                     THEN
3152                         Fnd_Message.SET_NAME('CSD',
3153                                              'CSD_ERR_REPAIRS_UPDATE');
3154                         Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
3155                                               x_product_txn_rec.repair_line_id);
3156                         Fnd_Msg_Pub.ADD;
3157                         RAISE CREATE_ORDER;
3158                     END IF;
3159 
3160                     -- swai: bug 6001057
3161                     -- rearranged code so that call to OM API can be used to update
3162                     -- project, unit number, or 3rd party end_customer
3163                     if (((x_product_txn_rec.project_id is not null)
3164                        OR (x_product_txn_rec.unit_number is not null)
3165                        OR (x_product_txn_rec.action_type in ('RMA_THIRD_PTY', 'SHIP_THIRD_PTY')))
3166 					   and (x_product_txn_rec.project_id <> FND_API.G_MISS_NUM)) then   --bug#6075825
3167 
3168                        OPEN order_line_cu(x_estimate_detail_id);
3169                        FETCH order_line_cu into l_order_line_id, l_p_ship_from_org_id;
3170                        CLOSE order_line_cu;
3171 
3172                        if (l_order_line_id) is not null then
3173                           l_Line_Tbl_Type(1)           := OE_Order_PUB.G_MISS_LINE_REC;
3174                           l_Line_Tbl_Type(1).line_id   := l_order_line_id;
3175                           l_Line_Tbl_Type(1).operation := OE_GLOBALS.G_OPR_UPDATE;
3176 
3177                           -- taklam: update project and unit number fields
3178                           if ((x_product_txn_rec.project_id is not null) or (x_product_txn_rec.unit_number is not null)) then
3179 
3180                               l_Line_Tbl_Type(1).end_item_unit_number   := x_product_txn_rec.unit_number;
3181 
3182                               if (x_product_txn_rec.project_id is not null) then
3183                                  OPEN project_cu(x_product_txn_rec.project_id,l_p_ship_from_org_id);
3184                                  FETCH project_cu into l_project_count;
3185                                  CLOSE project_cu;
3186 
3187                                  if (l_project_count >= 1) then
3188                                     l_Line_Tbl_Type(1).project_id             := x_product_txn_rec.project_id;
3189                                     l_Line_Tbl_Type(1).task_id                := x_product_txn_rec.task_id;
3190                                  else
3191                                     FND_MESSAGE.SET_NAME('CSD','CSD_ERR_PROJECT_UPDATE');
3192                                     FND_MESSAGE.SET_TOKEN('project_id',x_product_txn_rec.project_id);
3193                                     FND_MESSAGE.SET_TOKEN('ship_from_org_id',l_p_ship_from_org_id);
3194                                     FND_MSG_PUB.ADD;
3195                                     RAISE CREATE_ORDER;
3196                                  end if;
3197                               end if;
3198                           end if; -- end update project and unit number fields
3199 
3200                           -- swai: update 3rd party fields.
3201                           -- IB Owner must be set to END_CUSTOMER and end_custoemr_id mustbe
3202                           -- set to the SR customer account id in order for 3rd party lines to
3203                           -- avoid changing IB ownership during material transactions.
3204                           if (x_product_txn_rec.action_type in ('RMA_THIRD_PTY', 'SHIP_THIRD_PTY')) then
3205                              -- get SR customer account
3206                              OPEN sr_account_cu (x_product_txn_rec.repair_line_id);
3207                              FETCH sr_account_cu into l_sr_account_id;
3208                              CLOSE sr_account_cu;
3209                              if (l_sr_account_id) is not null then
3210                                 l_Line_Tbl_Type(1).ib_owner        := 'END_CUSTOMER';
3211                                 l_Line_Tbl_Type(1).end_customer_id := l_sr_account_id;
3212                              end if;
3213                           end if; -- end update 3rd party fields
3214 
3215                           OE_ORDER_PUB.Process_Line(
3216                                    p_line_tbl        => l_Line_Tbl_Type,
3217                                    x_line_out_tbl    => x_Line_Tbl_Type,
3218                                    x_return_status   => x_return_status,
3219                                    x_msg_count       => x_msg_count,
3220                                    x_msg_data        => x_msg_data
3221                           );
3222 
3223                           IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
3224                              FND_MESSAGE.SET_NAME('CSD','CSD_ERR_OM_PROCESS_LINE');
3225                              FND_MSG_PUB.ADD;
3226                              RAISE CREATE_ORDER;
3227                           END IF;
3228                        end if;  -- order line is not null
3229                     end if;
3230                     -- end swai: bug 6001057
3231 
3232 
3233                 EXCEPTION
3234                     WHEN CREATE_ORDER THEN
3235                         Debug('In CREATE_ORDER exception', l_mod_name, 1);
3236                         RAISE CREATE_ORDER;
3237                     WHEN OTHERS THEN
3238                         Debug('In OTHERS exception', l_mod_name, 1);
3239                         RAISE CREATE_ORDER;
3240                 END;
3241             END IF; -- end of create sales order
3242 
3243             -- Book the Sales Order if the book_sales_order_flag is checked
3244             IF x_product_txn_rec.book_sales_order_flag = 'Y'
3245             THEN
3246 
3247                 BEGIN
3248 
3249                     -- Define Savepoint
3250                     SAVEPOINT book_sales_order;
3251 
3252                     Debug('x_estimate_detail_id =' || x_estimate_detail_id,
3253                           l_mod_name,
3254                           1);
3255 
3256                     BEGIN
3257                         -- Get the order header id from the charge line
3258                         SELECT a.order_header_id, a.order_line_id
3259                           INTO l_order_header_id, l_order_line_id
3260                           FROM cs_estimate_details a
3261                          WHERE a.estimate_detail_id = x_estimate_detail_id
3262                            AND a.order_header_id IS NOT NULL
3263                            AND a.order_line_id IS NOT NULL;
3264 
3265                         --assign the order header id
3266                         l_order_rec.order_header_id := l_order_header_id;
3267                         l_order_rec.order_line_id   := l_order_line_id;
3268 
3269                     EXCEPTION
3270                         WHEN NO_DATA_FOUND THEN
3271                             FND_MESSAGE.SET_NAME('CSD','CSD_API_BOOKING_FAILED'); /*FP Fixed for bug#5147030 message changed*/
3272                             /*
3273                             Fnd_Message.SET_NAME('CSD',
3274                                                  'CSD_API_INV_EST_DETAIL_ID');
3275                             Fnd_Message.SET_TOKEN('ESTIMATE_DETAIL_ID',
3276                                                   x_estimate_detail_id);  */
3277                             Fnd_Msg_Pub.ADD;
3278                             Debug('Sales Order missing for estimate_detail_id =' ||
3279                                   x_estimate_detail_id,
3280                                   l_mod_name,
3281                                   1);
3282                             RAISE BOOK_ORDER;
3283                         WHEN TOO_MANY_ROWS THEN
3284                             Debug('Too many order header id',
3285                                   l_mod_name,
3286                                   1);
3287                             RAISE BOOK_ORDER;
3288                     END;
3289 
3290                     BEGIN
3291                         -- To Book an Order Sales Rep and ship_from_org_id is reqd
3292                         -- so check if the Order header has it
3293                         SELECT ship_from_org_id, unit_selling_price, org_id
3294                           INTO l_ship_from_org_id,
3295                                l_unit_selling_price,
3296                                l_order_rec.org_id
3297                           FROM oe_order_lines_all
3298                          WHERE line_id = l_order_line_id;
3299                            /*Fixed for bug#5368306
3300 			                    OM does not require sales rep at line to book it.
3301 			                    Depot should not check sales rep at line since oe
3302 			                    allows to book an order without a sales rep at
3303 			                    the line.
3304 			                    Following condition which checks sales rep at
3305 			                    order line has been commented.
3306 			                  */
3307                           /* AND salesrep_id IS NOT NULL; */
3308                     EXCEPTION
3309                         WHEN NO_DATA_FOUND THEN
3310                             Fnd_Message.SET_NAME('CSD',
3311                                                  'CSD_API_SALES_REP_MISSING');
3312                             Fnd_Message.SET_TOKEN('ORDER_LINE_ID',
3313                                                   l_order_line_id);
3314                             Fnd_Msg_Pub.ADD;
3315                             Debug('Sales rep missing for Line_id=' ||
3316                                   l_order_line_id,
3317                                   l_mod_name,
3318                                   1);
3319                             RAISE BOOK_ORDER;
3320                         WHEN TOO_MANY_ROWS THEN
3321                             Debug('Too many order ship_from_org_id',
3322                                   l_mod_name,
3323                                   1);
3324                     END;
3325 
3326                     IF l_ship_from_org_id IS NULL
3327                     THEN
3328                         Fnd_Message.SET_NAME('CSD',
3329                                              'CSD_API_SHIP_FROM_ORG_MISSING');
3330                         Fnd_Message.SET_TOKEN('ORDER_LINE_ID',
3331                                               l_order_line_id);
3332                         Fnd_Msg_Pub.ADD;
3333                         Debug('Ship from Org Id missing for Line_id=' ||
3334                               l_order_line_id,
3335                               l_mod_name,
3336                               1);
3337                         RAISE BOOK_ORDER;
3338                     END IF;
3339 
3340                     IF l_unit_selling_price IS NULL
3341                     THEN
3342                         Fnd_Message.SET_NAME('CSD',
3343                                              'CSD_API_PRICE_MISSING');
3344                         Fnd_Message.SET_TOKEN('ORDER_LINE_ID',
3345                                               l_order_line_id);
3346                         Fnd_Msg_Pub.ADD;
3347                         Debug('Unit Selling price missing for Line_id=' ||
3348                               l_order_line_id,
3349                               l_mod_name,
3350                               1);
3351                         RAISE BOOK_ORDER;
3352                     END IF;
3353 
3354                     Debug('l_order_rec.order_header_id =' ||
3355                           l_order_rec.order_header_id,
3356                           l_mod_name,
3357                           1);
3358 
3359                     BEGIN
3360                         SELECT booked_flag
3361                           INTO l_booked_flag
3362                           FROM oe_order_headers_all
3363                          WHERE header_id = l_order_rec.order_header_id;
3364                     EXCEPTION
3365                         WHEN NO_DATA_FOUND THEN
3366                             Debug('The Sales Order is booked OR does not exist',
3367                                   l_mod_name,
3368                                   1);
3369                             RAISE BOOK_ORDER;
3370                     END;
3371 
3372                     Debug('l_order_rec.org_id' || l_order_rec.org_id,
3373                           l_mod_name,
3374                           1);
3375 
3376                     IF NVL(l_booked_flag, 'N') = 'N'
3377                     THEN
3378                         -- swai: bug 6001057
3379                         -- rearranged code so that call to OM API can be used to update
3380                         -- project, unit number, or 3rd party end_customer
3381                         if (((x_product_txn_rec.project_id is not null)
3382                            OR (x_product_txn_rec.unit_number is not null)
3383                            OR (x_product_txn_rec.action_type in ('RMA_THIRD_PTY', 'SHIP_THIRD_PTY')))
3384 						   and (x_product_txn_rec.project_id <> FND_API.G_MISS_NUM)) then   --bug#6075825
3385 
3386                             if (l_order_line_id) is not null then
3387                                 l_Line_Tbl_Type(1)           := OE_Order_PUB.G_MISS_LINE_REC;
3388                                 l_Line_Tbl_Type(1).line_id   := l_order_line_id;
3389                                 l_Line_Tbl_Type(1).operation := OE_GLOBALS.G_OPR_UPDATE;
3390 
3391                                 -- taklam: update project and unit number fields
3392                                 if ((x_product_txn_rec.project_id is not null) or (x_product_txn_rec.unit_number is not null)) then
3393 
3394                                   l_Line_Tbl_Type(1).end_item_unit_number   := x_product_txn_rec.unit_number;
3395 
3396                                   if (x_product_txn_rec.project_id is not null) then
3397                                      OPEN project_cu(x_product_txn_rec.project_id,l_ship_from_org_id);
3398                                      FETCH project_cu into l_project_count;
3399                                      CLOSE project_cu;
3400 
3401                                      if (l_project_count >= 1) then
3402                                         l_Line_Tbl_Type(1).project_id             := x_product_txn_rec.project_id;
3403                                         l_Line_Tbl_Type(1).task_id                := x_product_txn_rec.task_id;
3404                                      else
3405                                         FND_MESSAGE.SET_NAME('CSD','CSD_ERR_PROJECT_UPDATE');
3406                                         FND_MESSAGE.SET_TOKEN('project_id',x_product_txn_rec.project_id);
3407                                         FND_MESSAGE.SET_TOKEN('ship_from_org_id',l_ship_from_org_id);
3408                                         FND_MSG_PUB.ADD;
3409                                         RAISE BOOK_ORDER;
3410                                      end if;
3411                                   end if;
3412                                 end if;
3413 
3414                                 -- swai: update 3rd party fields.
3415                                 -- IB Owner must be set to END_CUSTOMER and end_custoemr_id mustbe
3416                                 -- set to the SR customer account id in order for 3rd party lines to
3417                                 -- avoid changing IB ownership during material transactions.
3418                                 if (x_product_txn_rec.action_type in ('RMA_THIRD_PTY', 'SHIP_THIRD_PTY')) then
3419                                  -- get SR customer account
3420                                  OPEN sr_account_cu (x_product_txn_rec.repair_line_id);
3421                                  FETCH sr_account_cu into l_sr_account_id;
3422                                  CLOSE sr_account_cu;
3423                                  if (l_sr_account_id) is not null then
3424                                     l_Line_Tbl_Type(1).ib_owner        := 'END_CUSTOMER';
3425                                     l_Line_Tbl_Type(1).end_customer_id := l_sr_account_id;
3426                                  end if;
3427                                 end if; -- end update 3rd party fields
3428 
3429                                 OE_ORDER_PUB.Process_Line(
3430                                       p_line_tbl        => l_Line_Tbl_Type,
3431                                       x_line_out_tbl    => x_Line_Tbl_Type,
3432                                       x_return_status   => x_return_status,
3433                                       x_msg_count       => x_msg_count,
3434                                       x_msg_data        => x_msg_data
3435                                 );
3436 
3437                                 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
3438                                     FND_MESSAGE.SET_NAME('CSD','CSD_ERR_OM_PROCESS_LINE');
3439                                     FND_MSG_PUB.ADD;
3440                                     RAISE BOOK_ORDER;
3441                                 END IF;
3442                             end if;  -- order line is not null
3443                         end if;
3444                         -- end swai: bug 6001057
3445 
3446                         Debug('Call process_sales_order to book SO',
3447                               l_mod_name,
3448                               1);
3449                         PROCESS_SALES_ORDER(p_api_version      => 1.0,
3450                                             p_commit           => Fnd_Api.g_false,
3451                                             p_init_msg_list    => Fnd_Api.g_true,
3452                                             p_validation_level => Fnd_Api.g_valid_level_full,
3453                                             p_action           => 'BOOK',
3454                                             p_order_rec        => l_order_rec,
3455                                             x_return_status    => x_return_status,
3456                                             x_msg_count        => x_msg_count,
3457                                             x_msg_data         => x_msg_data);
3458 
3459                         IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
3460                         THEN
3461                             Debug('process_sales_order failed to book Sales order',
3462                                   l_mod_name,
3463                                   1);
3464                             RAISE BOOK_ORDER;
3465                         END IF;
3466                     END IF;
3467 
3468                     --            -- Update product txn with the status
3469                     --            UPDATE csd_product_transactions
3470                     --            SET prod_txn_status = 'BOOKED',
3471                     --                book_sales_order_flag = 'Y'
3472                     --            WHERE product_transaction_id = x_product_txn_rec.PRODUCT_TRANSACTION_ID;
3473                     --            IF SQL%NOTFOUND then
3474                     --                FND_MESSAGE.SET_NAME('CSD','CSD_ERR_PRD_TXN_UPDATE');
3475                     --                FND_MESSAGE.SET_TOKEN('PRODUCT_TRANSACTION_ID',x_product_txn_rec.PRODUCT_TRANSACTION_ID);
3476                     --                FND_MSG_PUB.ADD;
3477                     --                RAISE BOOK_ORDER;
3478                     --            END IF;
3479 
3480                     --            Fix for bug#4020651
3481                     Csd_Update_Programs_Pvt.prod_txn_status_upd(p_repair_line_id => x_product_txn_rec.repair_line_id,
3482                                                                 p_commit         => Fnd_Api.g_false);
3483 
3484                     --Update csd_repairs with status
3485                     UPDATE csd_repairs
3486                        SET ro_txn_status = 'OM_BOOKED'
3487                      WHERE repair_line_id =
3488                            x_product_txn_rec.REPAIR_LINE_ID;
3489                     IF SQL%NOTFOUND
3490                     THEN
3491                         Fnd_Message.SET_NAME('CSD',
3492                                              'CSD_ERR_REPAIRS_UPDATE');
3493                         Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
3494                                               x_product_txn_rec.repair_line_id);
3495                         Fnd_Msg_Pub.ADD;
3496                         RAISE BOOK_ORDER;
3497                     END IF;
3498 
3499                 EXCEPTION
3500                     WHEN BOOK_ORDER THEN
3501                         Debug('In BOOK_ORDER Exception while booking SO',
3502                               l_mod_name,
3503                               1);
3504                         RAISE BOOK_ORDER;
3505                     WHEN OTHERS THEN
3506                         Debug('In OTHERS Exception while booking SO',
3507                               l_mod_name,
3508                               1);
3509                         RAISE BOOK_ORDER;
3510                 END;
3511             END IF; --end of Book Sales Order
3512 
3513             -- Release Sales Order if the flag is checked
3514             IF x_product_txn_rec.release_sales_order_flag = 'Y'
3515             THEN
3516                 BEGIN
3517 
3518                     -- Define savepoint
3519                     SAVEPOINT release_sales_order;
3520 
3521                     Debug('x_product_txn_rec.sub_inventory =' ||
3522                           x_product_txn_rec.sub_inventory,
3523                           l_mod_name,
3524                           1);
3525 
3526                     IF NVL(x_product_txn_rec.sub_inventory,
3527                            Fnd_Api.G_MISS_CHAR) <> Fnd_Api.G_MISS_CHAR
3528                     THEN
3529                         BEGIN
3530                             SELECT 'x'
3531                               INTO l_dummy
3532                               FROM mtl_secondary_inventories
3533                              WHERE secondary_inventory_name =
3534                                    x_product_txn_rec.sub_inventory
3535                                AND organization_id = l_ship_from_org_id;
3536                         EXCEPTION
3537                             WHEN NO_DATA_FOUND THEN
3538                                 Fnd_Message.SET_NAME('CSD',
3539                                                      'CSD_API_SUB_INV_MISSING');
3540                                 Fnd_Message.SET_TOKEN('SUB_INVENTORY',
3541                                                       x_product_txn_rec.sub_inventory);
3542                                 Fnd_Msg_Pub.ADD;
3543                                 Debug(x_product_txn_rec.sub_inventory ||
3544                                       ':Subinventory does not exist',
3545                                       l_mod_name,
3546                                       1);
3547                                 RAISE RELEASE_ORDER;
3548                             WHEN OTHERS THEN
3549                                 Debug('More than one Subinventory does exist with same name',
3550                                       l_mod_name,
3551                                       1);
3552                                 RAISE RELEASE_ORDER;
3553                         END;
3554                         l_order_rec.PICK_FROM_SUBINVENTORY := x_product_txn_rec.sub_inventory;
3555                     END IF;
3556         /* R12 SN reservations change Begin */
3557         -- Get Item attributes in local variable
3558                    CSD_LOGISTICS_UTIL.Get_ItemAttributes(p_Inventory_Item_Id => x_Product_Txn_Rec.Inventory_Item_Id,
3559         		                        p_inv_org_id        => x_Product_Txn_Rec.inventory_org_id,
3560                            x_ItemAttributes    => l_ItemAttributes);
3561 	              -- Get the default pick rule id
3562                    Fnd_Profile.Get('CSD_AUTO_SRL_RESERVE', l_auto_reserve_profile);
3563                    if(l_auto_reserve_profile is null) then
3564                        l_auto_reserve_profile := 'N';
3565                    end if;
3566 
3567 				   Debug('Going to process reservation..', l_mod_name, 1);
3568 				   Debug(l_auto_reserve_profile, l_mod_name,1);
3569 				   Debug(x_Product_Txn_Rec.source_Serial_number, l_mod_name,1);
3570 				   Debug(x_Product_Txn_Rec.sub_inventory, l_mod_name,1);
3571 				   Debug(x_Product_Txn_Rec.action_type, l_mod_name,1);
3572 				   Debug(to_char(l_itemAttributes.reservable_type), l_mod_name,1);
3573 				   Debug(to_char(l_itemAttributes.serial_Code), l_mod_name,1);
3574 
3575 
3576                    -- swai: bug 5931926 - 12.0.2 added 3rd party action type
3577                    IF( l_auto_reserve_profile = 'Y'
3578                         AND x_Product_Txn_Rec.source_Serial_number is not null
3579                         AND x_Product_Txn_Rec.sub_inventory is not null
3580                         AND x_product_txn_rec.action_type IN ('SHIP', 'WALK_IN_ISSUE', 'SHIP_THIRD_PTY')
3581                         AND l_ItemAttributes.reservable_type = C_RESERVABLE
3582                         AND (l_ItemAttributes.serial_code = C_SERIAL_CONTROL_AT_RECEIPT
3583                               OR
3584                              l_ItemAttributes.serial_code = C_SERIAL_CONTROL_PREDEFINED) ) THEN
3585 
3586 		             Debug('Checking reservation id for serial number..['
3587 		                         ||x_Product_Txn_Rec.source_Serial_number||']', l_mod_name, 1);
3588 
3589 		            l_serial_rsv_rec.inventory_item_id    := x_Product_Txn_Rec.inventory_item_id;
3590 		            l_serial_rsv_rec.inv_organization_id  := x_Product_Txn_Rec.inventory_org_id;
3591 		            l_serial_rsv_rec.order_header_id      := l_order_header_id;
3592 		            l_serial_rsv_rec.order_line_id        := l_order_line_Id;
3593 		            l_serial_rsv_rec.order_schedule_date  := sysdate;
3594 		            l_serial_rsv_rec.serial_number        := x_Product_Txn_Rec.source_serial_number;
3595 		            l_serial_rsv_rec.locator_id           := x_Product_Txn_Rec.locator_id;
3596 		            l_serial_rsv_rec.revision             := x_Product_Txn_Rec.revision;
3597 		            l_serial_rsv_rec.lot_number           := x_Product_Txn_Rec.lot_number;
3598 		            l_serial_rsv_rec.subinventory_code    := x_Product_Txn_Rec.sub_inventory;
3599 		            l_serial_rsv_rec.reservation_uom_code := x_Product_Txn_Rec.Unit_Of_Measure_Code;
3600 
3601 		            Debug('Calling reserve serial..', l_mod_name, 1);
3602 		            CSD_LOGISTICS_UTIL.Reserve_serial_number(l_serial_rsv_rec, x_return_status);
3603 
3604 		            if(x_return_status = FND_API.G_RET_STS_ERROR) THEN
3605 			            Fnd_Message.SET_NAME('CSD', 'CSD_SRL_RESERVE_FAILED');
3606 			            Fnd_Msg_Pub.ADD;
3607 			            RAISE RELEASE_ORDER;
3608 		            END IF;
3609 
3610                  END IF;
3611 
3612         /* R12 SN reservations change End   */
3613 
3614 
3615 
3616                     -- R12 development changes
3617                     -- Added the code to get the picking rule from profile only if the product_txn_rec does
3618                     -- not have it.
3619                     IF (x_product_txn_rec.picking_rule_id IS NULL)
3620                     THEN
3621                         -- Get the default pick rule id
3622                         Fnd_Profile.Get('CSD_DEF_PICK_RELEASE_RULE',
3623                                         l_picking_rule_id);
3624 
3625                     ELSE
3626 
3627                         l_picking_rule_id := x_product_txn_rec.picking_rule_id;
3628 
3629                     END IF; -- End of if for input pick_rule_id check.
3630 
3631                     -- Get the Picking Rule Id
3632                     BEGIN
3633                         SELECT picking_rule_id
3634                           INTO l_picking_rule_id
3635                           FROM wsh_picking_rules
3636                          WHERE picking_rule_id = l_picking_rule_id;
3637                     EXCEPTION
3638                         WHEN NO_DATA_FOUND THEN
3639                             Fnd_Message.SET_NAME('CSD',
3640                                                  'CSD_API_INV_PICKING_RULE_ID');
3641                             Fnd_Message.SET_TOKEN('PICKING_RULE_ID',
3642                                                   l_picking_rule_id);
3643                             Fnd_Msg_Pub.ADD;
3644                             Debug(l_picking_rule_id ||
3645                                   ':Picking Rule does not exist ',
3646                                   l_mod_name,
3647                                   1);
3648                             RAISE RELEASE_ORDER;
3649                         WHEN OTHERS THEN
3650                             Debug('More than one Picking Rule exist with same name',
3651                                   l_mod_name,
3652                                   1);
3653                             RAISE RELEASE_ORDER;
3654                     END;
3655 
3656                     l_order_rec.picking_rule_id := l_picking_rule_id;
3657                     l_order_rec.org_id          := l_ship_from_org_id;
3658 
3659                     BEGIN
3660                         SELECT released_status
3661                           INTO l_release_status
3662                           FROM wsh_delivery_details
3663                          WHERE source_line_id = l_order_line_id
3664 			 AND    SOURCE_CODE = 'OE'; /*Fixed for bug#5846054 */
3665                     EXCEPTION
3666                         WHEN NO_DATA_FOUND THEN
3667                             Debug('No Delivery lines found', l_mod_name, 1);
3668                             RAISE RELEASE_ORDER;
3669                         WHEN TOO_MANY_ROWS THEN
3670                             Debug('Too Delivery lines found for the order line',
3671                                   l_mod_name,
3672                                   1);
3673                             RAISE RELEASE_ORDER;
3674                     END;
3675 
3676                     IF l_release_status IN ('R', 'B')
3677                     THEN
3678                         Debug('Call process_sales_order to pick release sales order',
3679                               l_mod_name,
3680                               1);
3681                         PROCESS_SALES_ORDER(p_api_version      => 1.0,
3682                                             p_commit           => Fnd_Api.g_false,
3683                                             p_init_msg_list    => Fnd_Api.g_true,
3684                                             p_validation_level => Fnd_Api.g_valid_level_full,
3685                                             p_action           => 'PICK-RELEASE',
3686                                             p_order_rec        => l_order_rec,
3687                                             x_return_status    => x_return_status,
3688                                             x_msg_count        => x_msg_count,
3689                                             x_msg_data         => x_msg_data);
3690 
3691                         IF (x_return_status = Fnd_Api.G_RET_STS_ERROR)
3692                         THEN
3693                             Debug('process_sales_order failed',
3694                                   l_mod_name,
3695                                   1);
3696                             RAISE RELEASE_ORDER;
3697                         END IF;
3698                     END IF;
3699 
3700                     BEGIN
3701                         SELECT released_status
3702                           INTO l_release_status
3703                           FROM wsh_delivery_details
3704                          WHERE source_line_id = l_order_line_id
3705 			 AND    SOURCE_CODE = 'OE'; /*Fixed for bug#5846054 */
3706                     EXCEPTION
3707                         WHEN NO_DATA_FOUND THEN
3708                             Debug('No Delivery lines found', l_mod_name, 1);
3709                             RAISE RELEASE_ORDER;
3710                         WHEN TOO_MANY_ROWS THEN
3711                             Debug('Too Delivery lines found for the order line',
3712                                   l_mod_name,
3713                                   1);
3714                             RAISE RELEASE_ORDER;
3715                     END;
3716 
3717                     IF l_release_status = 'Y'
3718                     THEN
3719                         -- swai: bug 5931926 - 12.0.2 added 3rd party action type
3720                         IF (x_product_txn_rec.ACTION_TYPE IN
3721                            ('SHIP', 'WALK_IN_ISSUE', 'SHIP_THIRD_PTY'))
3722                         THEN
3723                             UPDATE csd_product_transactions
3724                                SET prod_txn_status          = 'RELEASED',
3725                                    release_sales_order_flag = 'Y'
3726                              WHERE product_transaction_id =
3727                                    x_product_txn_rec.PRODUCT_TRANSACTION_ID;
3728                             IF SQL%NOTFOUND
3729                             THEN
3730                                 Fnd_Message.SET_NAME('CSD',
3731                                                      'CSD_ERR_PRD_TXN_UPDATE');
3732                                 Fnd_Message.SET_TOKEN('PRODUCT_TRANSACTION_ID',
3733                                                       x_product_txn_rec.PRODUCT_TRANSACTION_ID);
3734                                 Fnd_Msg_Pub.ADD;
3735                                 RAISE RELEASE_ORDER;
3736                             END IF;
3737                         END IF;
3738 
3739                         UPDATE csd_repairs
3740                            SET ro_txn_status = 'OM_RELEASED'
3741                          WHERE repair_line_id =
3742                                x_product_txn_rec.REPAIR_LINE_ID;
3743                         IF SQL%NOTFOUND
3744                         THEN
3745                             Fnd_Message.SET_NAME('CSD',
3746                                                  'CSD_ERR_REPAIRS_UPDATE');
3747                             Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
3748                                                   x_product_txn_rec.repair_line_id);
3749                             Fnd_Msg_Pub.ADD;
3750                             RAISE RELEASE_ORDER;
3751                         END IF;
3752 
3753                     ELSIF l_release_status IN ('S', 'B')
3754                     THEN
3755                         -- swai: bug 5931926 - 12.0.2 added 3rd party action type
3756                         IF (x_product_txn_rec.ACTION_TYPE IN
3757                            ('SHIP', 'WALK_IN_ISSUE', 'SHIP_THIRD_PTY'))
3758                         THEN
3759                             UPDATE csd_product_transactions
3760                                SET prod_txn_status = 'BOOKED'
3761                              WHERE product_transaction_id =
3762                                    x_product_txn_rec.PRODUCT_TRANSACTION_ID;
3763                             IF SQL%NOTFOUND
3764                             THEN
3765                                 Fnd_Message.SET_NAME('CSD',
3766                                                      'CSD_ERR_PRD_TXN_UPDATE');
3767                                 Fnd_Message.SET_TOKEN('PRODUCT_TRANSACTION_ID',
3768                                                       x_product_txn_rec.PRODUCT_TRANSACTION_ID);
3769                                 Fnd_Msg_Pub.ADD;
3770                                 RAISE RELEASE_ORDER;
3771                             END IF;
3772                         END IF;
3773 
3774                         UPDATE csd_repairs
3775                            SET ro_txn_status = 'OM_BOOKED'
3776                          WHERE repair_line_id =
3777                                x_product_txn_rec.REPAIR_LINE_ID;
3778                         IF SQL%NOTFOUND
3779                         THEN
3780                             Fnd_Message.SET_NAME('CSD',
3781                                                  'CSD_ERR_REPAIRS_UPDATE');
3782                             Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
3783                                                   x_product_txn_rec.repair_line_id);
3784                             Fnd_Msg_Pub.ADD;
3785                             RAISE RELEASE_ORDER;
3786                         END IF;
3787 
3788                     END IF;
3789 
3790                 EXCEPTION
3791                     WHEN RELEASE_ORDER THEN
3792                         Debug('In RELEASE_ORDER Exception while releasing SO',
3793                               l_mod_name,
3794                               1);
3795                         RAISE RELEASE_ORDER;
3796                     WHEN OTHERS THEN
3797                         Debug('In OTHERS Exception while releasing SO',
3798                               l_mod_name,
3799                               1);
3800                         RAISE RELEASE_ORDER;
3801                 END;
3802             END IF; -- end of Release Sales Order
3803 
3804             -- Ship the sales order if the flag is checked
3805             IF x_product_txn_rec.ship_sales_order_flag = 'Y'
3806             THEN
3807 
3808                 BEGIN
3809 
3810                     -- Define savepoint
3811                     SAVEPOINT ship_sales_order;
3812 
3813                     BEGIN
3814                         SELECT requested_quantity, released_status
3815                           INTO l_ship_qty, l_release_status
3816                           FROM wsh_delivery_details
3817                          WHERE source_header_id =
3818                                l_order_rec.order_header_id
3819                            AND source_line_id = l_order_rec.order_line_id
3820 			   AND SOURCE_CODE = 'OE'; /*Fixed for bug#5685341*/
3821                     EXCEPTION
3822                         WHEN NO_DATA_FOUND THEN
3823                             Debug('No Delivery Lines found', l_mod_name, 1);
3824                             RAISE SHIP_ORDER;
3825                         WHEN TOO_MANY_ROWS THEN
3826                             Debug('Many Delivery lines found',
3827                                   l_mod_name,
3828                                   1);
3829                             RAISE SHIP_ORDER;
3830                     END;
3831 
3832                     l_order_rec.shipped_quantity := l_ship_qty;
3833                     l_order_rec.serial_number    := x_product_txn_rec.source_serial_number;
3834 
3835                     IF l_release_status = 'Y'
3836                     THEN
3837                         Debug('Call process_sales_order to ship SO',
3838                               l_mod_name,
3839                               1);
3840                         PROCESS_SALES_ORDER(p_api_version      => 1.0,
3841                                             p_commit           => Fnd_Api.g_false,
3842                                             p_init_msg_list    => Fnd_Api.g_true,
3843                                             p_validation_level => Fnd_Api.g_valid_level_full,
3844                                             p_action           => 'SHIP',
3845                                             /*Fixed for bug#4433942 passing product
3846 					      txn record as in parameter*/
3847                                             p_product_txn_rec  =>  x_product_txn_rec,
3848                                             p_order_rec        => l_order_rec,
3849                                             x_return_status    => x_return_status,
3850                                             x_msg_count        => x_msg_count,
3851                                             x_msg_data         => x_msg_data);
3852 
3853                         IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
3854                         THEN
3855                             Debug('process_sales_order failed to ship sales order',
3856                                   l_mod_name,
3857                                   1);
3858                             RAISE SHIP_ORDER;
3859                         END IF;
3860                         -- swai: bug 5931926 - 12.0.2 added 3rd party action type
3861                         IF (x_product_txn_rec.ACTION_TYPE IN
3862                            ('SHIP', 'WALK_IN_ISSUE', 'SHIP_THIRD_PTY'))
3863                         THEN
3864                             UPDATE csd_product_transactions
3865                                SET prod_txn_status       = 'SHIPPED',
3866                                    ship_sales_order_flag = 'Y'
3867                              WHERE product_transaction_id =
3868                                    x_product_txn_rec.PRODUCT_TRANSACTION_ID;
3869                             IF SQL%NOTFOUND
3870                             THEN
3871                                 Fnd_Message.SET_NAME('CSD',
3872                                                      'CSD_ERR_PRD_TXN_UPDATE');
3873                                 Fnd_Message.SET_TOKEN('PRODUCT_TRANSACTION_ID',
3874                                                       x_product_txn_rec.PRODUCT_TRANSACTION_ID);
3875                                 Fnd_Msg_Pub.ADD;
3876                                 RAISE SHIP_ORDER;
3877                             END IF;
3878                         END IF;
3879 
3880                         UPDATE csd_repairs
3881                            SET ro_txn_status = 'OM_SHIPPED'
3882                          WHERE repair_line_id =
3883                                x_product_txn_rec.REPAIR_LINE_ID;
3884                         IF SQL%NOTFOUND
3885                         THEN
3886                             Fnd_Message.SET_NAME('CSD',
3887                                                  'CSD_ERR_REPAIRS_UPDATE');
3888                             Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
3889                                                   x_product_txn_rec.repair_line_id);
3890                             Fnd_Msg_Pub.ADD;
3891                             RAISE SHIP_ORDER;
3892                         END IF;
3893 
3894                     END IF;
3895 
3896                 EXCEPTION
3897                     WHEN SHIP_ORDER THEN
3898                         Debug('In SHIP_ORDER Exception', l_mod_name, 1);
3899                         RAISE SHIP_ORDER;
3900                     WHEN OTHERS THEN
3901                         Debug('In OTHERS Exception', l_mod_name, 1);
3902                         RAISE SHIP_ORDER;
3903                 END;
3904             END IF; -- end of ship sales order
3905 
3906         END IF; --end of all process
3907 
3908         -- Api body ends here
3909 
3910         -- Standard check of p_commit.
3911         IF Fnd_Api.To_Boolean(p_commit)
3912         THEN
3913             COMMIT WORK;
3914         END IF;
3915 
3916         -- Standard call to get message count and IF count is  get message info.
3917         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
3918                                   p_data  => x_msg_data);
3919     EXCEPTION
3920         WHEN CREATE_ORDER THEN
3921             x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
3922             ROLLBACK TO create_sales_order;
3923             -- update the prod txn as the charge
3924             -- line was not interfaced
3925             UPDATE csd_product_transactions
3926                SET interface_to_om_flag     = 'N',
3927                    book_sales_order_flag    = 'N',
3928                    release_sales_order_flag = 'N',
3929                    ship_sales_order_flag    = 'N'
3930              WHERE product_transaction_id =
3931                    x_product_txn_rec.PRODUCT_TRANSACTION_ID;
3932             -- Update auto_process_rma if OM fails
3933             -- swai: bug 5931926 - 12.0.2 added 3rd party action type
3934             IF (x_product_txn_rec.action_type IN ('RMA', 'WALK_IN_RECEIPT', 'RMA_THIRD_PTY')) AND
3935                (x_product_txn_rec.action_code = 'CUST_PROD')
3936             THEN
3937                 UPDATE csd_repairs
3938                    SET auto_process_rma = 'N'
3939                  WHERE repair_line_id = x_product_txn_rec.repair_line_id;
3940             END IF;
3941             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
3942                                       p_data  => x_msg_data);
3943         WHEN BOOK_ORDER THEN
3944             x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
3945             ROLLBACK TO book_sales_order;
3946             -- update the prod txn as the order
3947             -- line was not booked
3948             UPDATE csd_product_transactions
3949                SET book_sales_order_flag    = 'N',
3950                    release_sales_order_flag = 'N',
3951                    ship_sales_order_flag    = 'N'
3952              WHERE product_transaction_id =
3953                    x_product_txn_rec.PRODUCT_TRANSACTION_ID;
3954             -- Update auto_process_rma if OM fails
3955             -- swai: bug 5931926 - 12.0.2 added 3rd party action type
3956             IF (x_product_txn_rec.action_type IN ('RMA', 'WALK_IN_RECEIPT', 'RMA_THIRD_PTY')) AND
3957                (x_product_txn_rec.action_code = 'CUST_PROD')
3958             THEN
3959                 UPDATE csd_repairs
3960                    SET auto_process_rma = 'N'
3961                  WHERE repair_line_id = x_product_txn_rec.repair_line_id;
3962             END IF;
3963             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
3964                                       p_data  => x_msg_data);
3965         WHEN RELEASE_ORDER THEN
3966             x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
3967             ROLLBACK TO release_sales_order;
3968             -- update the prod txn as the order
3969             -- line was not booked
3970             UPDATE csd_product_transactions
3971                SET release_sales_order_flag = 'N',
3972                    ship_sales_order_flag    = 'N'
3973              WHERE product_transaction_id =
3974                    x_product_txn_rec.PRODUCT_TRANSACTION_ID;
3975             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
3976                                       p_data  => x_msg_data);
3977         WHEN SHIP_ORDER THEN
3978             x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
3979             ROLLBACK TO ship_sales_order;
3980             -- update the prod txn as the order
3981             -- line was not booked
3982             UPDATE csd_product_transactions
3983                SET ship_sales_order_flag = 'N'
3984              WHERE product_transaction_id =
3985                    x_product_txn_rec.PRODUCT_TRANSACTION_ID;
3986             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
3987                                       p_data  => x_msg_data);
3988         WHEN Fnd_Api.G_EXC_ERROR THEN
3989             x_return_status := Fnd_Api.G_RET_STS_ERROR;
3990             ROLLBACK TO create_product_txn;
3991             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
3992                                       p_data  => x_msg_data);
3993         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
3994             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
3995             ROLLBACK TO create_product_txn;
3996             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
3997                                       p_data  => x_msg_data);
3998         WHEN OTHERS THEN
3999             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
4000             ROLLBACK TO create_product_txn;
4001             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
4002             THEN
4003                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
4004             END IF;
4005             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4006                                       p_data  => x_msg_data);
4007     END create_product_txn;
4008 
4009     /*-----------------------------------------------------------------*/
4010     /* Procedure Name: Create_ext_prod_txn                             */
4011     /* description : This procedure will create a product transaction  */
4012     /*               without creating charge line                      */
4013     /*-----------------------------------------------------------------*/
4014     PROCEDURE CREATE_EXT_PROD_TXN(p_api_version         IN NUMBER,
4015                                   p_commit              IN VARCHAR2,
4016                                   p_init_msg_list       IN VARCHAR2,
4017                                   p_validation_level    IN NUMBER,
4018                                   p_create_charge_lines IN VARCHAR2,
4019                                   x_product_txn_rec     IN OUT NOCOPY PRODUCT_TXN_REC,
4020                                   x_return_status       OUT NOCOPY VARCHAR2,
4021                                   x_msg_count           OUT NOCOPY NUMBER,
4022                                   x_msg_data            OUT NOCOPY VARCHAR2
4023 
4024                                   ) IS
4025         l_api_name    CONSTANT VARCHAR2(30) := 'CREATE_EXT_PRODUCT_TXN';
4026         l_api_version CONSTANT NUMBER := 1.0;
4027         l_msg_count              NUMBER;
4028         l_msg_data               VARCHAR2(2000);
4029         l_msg_index              NUMBER;
4030         l_product_transaction_id NUMBER := NULL;
4031         l_serial_flag            BOOLEAN := FALSE;
4032         l_dummy                  VARCHAR2(1);
4033         l_check                  VARCHAR2(1);
4034         l_Charges_Rec            Cs_Charge_Details_Pub.Charges_Rec_type;
4035         l_estimate_Rec           Cs_Charge_Details_Pub.Charges_Rec_type;
4036         l_estimate_detail_id     NUMBER := NULL;
4037         x_estimate_detail_id     NUMBER := NULL;
4038         l_incident_id            NUMBER := NULL;
4039         l_order_rec              OM_INTERFACE_REC;
4040         l_reference_number       VARCHAR2(30) := '';
4041         l_contract_number        VARCHAR2(120) := '';
4042         l_bus_process_id         NUMBER := NULL;
4043         l_repair_type_ref        VARCHAR2(3) := '';
4044         l_line_type_id           NUMBER := NULL;
4045         l_txn_billing_type_id    NUMBER := NULL;
4046         l_party_id               NUMBER := NULL;
4047         l_account_id             NUMBER := NULL;
4048         l_order_header_id        NUMBER := NULL;
4049         l_release_status         VARCHAR2(10) := '';
4050         l_curr_code              VARCHAR2(10) := '';
4051         l_picking_rule_id        NUMBER := NULL;
4052         l_ship_qty               NUMBER := NULL;
4053         l_line_category_code     VARCHAR2(30) := '';
4054         l_ship_from_org_id       NUMBER := NULL;
4055         l_order_line_id          NUMBER := NULL;
4056         l_coverage_id            NUMBER := NULL;
4057         -- Bugfix 3617932, vkjain.
4058         -- Increasing the column length to 150
4059         -- l_coverage_name          VARCHAR2(150) := ''; -- Commented for bugfix 3617932
4060         l_txn_group_id       NUMBER := NULL;
4061         l_unit_selling_price NUMBER := NULL;
4062 
4063         create_order EXCEPTION;
4064         book_order EXCEPTION;
4065         release_order EXCEPTION;
4066         ship_order EXCEPTION;
4067 
4068         CURSOR get_account_details(p_incident_id IN NUMBER) IS
4069             SELECT customer_id, account_id
4070               FROM cs_incidents_all_b
4071              WHERE incident_id = p_incident_id;
4072 
4073         CURSOR estimate(p_rep_line_id IN NUMBER) IS
4074             SELECT estimate_detail_id, object_version_number
4075               FROM cs_estimate_details
4076              WHERE source_id = p_rep_line_id
4077                AND source_code = 'DR'
4078                AND interface_to_oe_flag = 'N'
4079                AND order_header_id IS NULL
4080                AND order_line_id IS NULL
4081                AND line_category_code = 'ORDER';
4082 
4083     BEGIN
4084         -- Standard Start of API savepoint
4085         SAVEPOINT create_product_txn;
4086 
4087         -- Standard call to check for call compatibility.
4088         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
4089                                            p_api_version,
4090                                            l_api_name,
4091                                            G_PKG_NAME)
4092         THEN
4093             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
4094         END IF;
4095 
4096         -- Initialize message list if p_init_msg_list is set to TRUE.
4097         IF Fnd_Api.to_Boolean(p_init_msg_list)
4098         THEN
4099             Fnd_Msg_Pub.initialize;
4100         END IF;
4101 
4102         -- Initialize API return status to success
4103         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4104 
4105         -- Api body starts
4106 
4107         -- Dump the API  in the log file
4108         Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
4109                                           p_api_name => l_api_name);
4110 
4111         -- Dump the IN parameters in the log file
4112         -- if the debug level > 5
4113         IF Fnd_Profile.value('CSD_DEBUG_LEVEL') > 5
4114         THEN
4115             Csd_Gen_Utility_Pvt.dump_prod_txn_rec(p_prod_txn_rec => x_product_txn_rec);
4116         END IF;
4117 
4118         IF (g_debug > 0)
4119         THEN
4120             Csd_Gen_Utility_Pvt.ADD('********* Check reqd parameter ***************');
4121             Csd_Gen_Utility_Pvt.ADD('Repair Line ID      =' ||
4122                                     x_product_txn_rec.repair_line_id);
4123             Csd_Gen_Utility_Pvt.ADD('Action Code         =' ||
4124                                     x_product_txn_rec.action_code);
4125             Csd_Gen_Utility_Pvt.ADD('Action Type         =' ||
4126                                     x_product_txn_rec.action_type);
4127             Csd_Gen_Utility_Pvt.ADD('Txn_billing_type_id =' ||
4128                                     x_product_txn_rec.txn_billing_type_id);
4129         END IF;
4130 
4131         -- Check the required parameter(txn_billing_type_id)
4132         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.txn_billing_type_id,
4133                                           p_param_name  => 'TXN_BILLING_TYPE_ID',
4134                                           p_api_name    => l_api_name);
4135 
4136         -- Check the required parameter(inventory_item_id)
4137         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.inventory_item_id,
4138                                           p_param_name  => 'INVENTORY_ITEM_ID',
4139                                           p_api_name    => l_api_name);
4140 
4141         -- Check the required parameter(unit_of_measure_code)
4142         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.unit_of_measure_code,
4143                                           p_param_name  => 'UNIT_OF_MEASURE_CODE',
4144                                           p_api_name    => l_api_name);
4145 
4146         -- Check the required parameter(quantity)
4147         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.quantity,
4148                                           p_param_name  => 'QUANTITY',
4149                                           p_api_name    => l_api_name);
4150 
4151         -- Check the required parameter(price_list_id)
4152         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.price_list_id,
4153                                           p_param_name  => 'PRICE_LIST_ID',
4154                                           p_api_name    => l_api_name);
4155 
4156         IF (g_debug > 0)
4157         THEN
4158             Csd_Gen_Utility_Pvt.ADD('Validate repair line id');
4159         END IF;
4160 
4161         -- Validate the repair line ID if it exists in csd_repairs
4162         IF NOT
4163             (Csd_Process_Util.Validate_rep_line_id(p_repair_line_id => x_product_txn_rec.repair_line_id))
4164         THEN
4165             RAISE Fnd_Api.G_EXC_ERROR;
4166         END IF;
4167 
4168         IF (g_debug > 0)
4169         THEN
4170             Csd_Gen_Utility_Pvt.ADD('Validate action type');
4171         END IF;
4172 
4173         -- Validate the Action Type if it exists in fnd_lookups
4174         IF NOT
4175             (Csd_Process_Util.Validate_action_type(p_action_type => x_product_txn_rec.action_type))
4176         THEN
4177             RAISE Fnd_Api.G_EXC_ERROR;
4178         END IF;
4179 
4180         IF (g_debug > 0)
4181         THEN
4182             Csd_Gen_Utility_Pvt.ADD('Validate action code');
4183         END IF;
4184 
4185         -- Validate the repair line ID if it exists in fnd_lookups
4186         IF NOT
4187             (Csd_Process_Util.Validate_action_code(p_action_code => x_product_txn_rec.action_code))
4188         THEN
4189             RAISE Fnd_Api.G_EXC_ERROR;
4190         END IF;
4191 
4192         IF (g_debug > 0)
4193         THEN
4194             Csd_Gen_Utility_Pvt.ADD('Validate product txn qty');
4195             Csd_Gen_Utility_Pvt.ADD('x_product_txn_rec.quantity =' ||
4196                                     x_product_txn_rec.quantity);
4197         END IF;
4198 
4199         -- Validate if the product txn quantity (customer product only)
4200         -- is not exceeding the repair order quantity
4201         -- swai: bug 5931926 - 12.0.2 do not validate quantity for third party lines
4202         -- since multiple parts can be shipped out.
4203         IF x_product_txn_rec.action_code = 'CUST_PROD' AND
4204            x_product_txn_rec.action_type not in ('RMA_THIRD_PTY', 'SHIP_THIRD_PTY')
4205         THEN
4206             Csd_Process_Util.Validate_quantity(p_action_type    => x_product_txn_rec.action_type,
4207                                                p_repair_line_id => x_product_txn_rec.repair_line_id,
4208                                                p_prod_txn_qty   => x_product_txn_rec.quantity,
4209                                                x_return_status  => x_return_status);
4210 
4211             IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
4212             THEN
4213                 IF (g_debug > 0)
4214                 THEN
4215                     Csd_Gen_Utility_Pvt.ADD('Validate_Quantity failed ');
4216                 END IF;
4217                 RAISE Fnd_Api.G_EXC_ERROR;
4218             END IF;
4219         END IF;
4220 
4221         IF (g_debug > 0)
4222         THEN
4223             Csd_Gen_Utility_Pvt.ADD('Validate product txn status');
4224             Csd_Gen_Utility_Pvt.ADD('x_product_txn_rec.PROD_TXN_STATUS =' ||
4225                                     x_product_txn_rec.PROD_TXN_STATUS);
4226         END IF;
4227 
4228         -- Validate the PROD_TXN_STATUS if it exists in fnd_lookups
4229         IF (x_product_txn_rec.PROD_TXN_STATUS IS NOT NULL) AND
4230            (x_product_txn_rec.PROD_TXN_STATUS <> Fnd_Api.G_MISS_CHAR)
4231         THEN
4232             BEGIN
4233                 SELECT 'X'
4234                   INTO l_check
4235                   FROM fnd_lookups
4236                  WHERE lookup_type = 'CSD_PRODUCT_TXN_STATUS'
4237                    AND lookup_code = x_product_txn_rec.PROD_TXN_STATUS;
4238             EXCEPTION
4239                 WHEN OTHERS THEN
4240                     Fnd_Message.SET_NAME('CSD', 'CSD_ERR_PROD_TXN_STATUS');
4241                     Fnd_Msg_Pub.ADD;
4242                     RAISE Fnd_Api.G_EXC_ERROR;
4243             END;
4244         END IF;
4245 
4246         -- Get service request id from csd_repairs table
4247         -- using repair order
4248         BEGIN
4249             SELECT incident_id
4250               INTO l_incident_id
4251               FROM csd_repairs
4252              WHERE repair_line_id = x_product_txn_rec.repair_line_id;
4253         EXCEPTION
4254             WHEN OTHERS THEN
4255                 Fnd_Message.SET_NAME('CSD', 'CSD_API_INV_REP_LINE_ID');
4256                 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
4257                                       x_product_txn_rec.repair_line_id);
4258                 Fnd_Msg_Pub.ADD;
4259                 RAISE Fnd_Api.G_EXC_ERROR;
4260         END;
4261 
4262         IF (g_debug > 0)
4263         THEN
4264             Csd_Gen_Utility_Pvt.ADD('l_incident_id    =' || l_incident_id);
4265         END IF;
4266 
4267         -- Get the business process id
4268         -- Forward port bug fix# 2756313
4269         --l_bus_process_id := CSD_PROCESS_UTIL.GET_BUS_PROCESS(l_incident_id);
4270 
4271         l_bus_process_id := Csd_Process_Util.GET_BUS_PROCESS(x_product_txn_rec.repair_line_id);
4272 
4273         IF (g_debug > 0)
4274         THEN
4275             Csd_Gen_Utility_Pvt.ADD('l_bus_process_id =' ||
4276                                     l_bus_process_id);
4277         END IF;
4278 
4279         IF l_bus_process_id < 0
4280         THEN
4281             IF NVL(x_product_txn_rec.business_process_id,
4282                    Fnd_Api.G_MISS_NUM) <> Fnd_Api.G_MISS_NUM
4283             THEN
4284                 l_bus_process_id := x_product_txn_rec.business_process_id;
4285             ELSE
4286                 IF (g_debug > 0)
4287                 THEN
4288                     Csd_Gen_Utility_Pvt.ADD('Business process Id does not exist ');
4289                 END IF;
4290                 RAISE Fnd_Api.G_EXC_ERROR;
4291             END IF;
4292         END IF;
4293 
4294         IF (g_debug > 0)
4295         THEN
4296             Csd_Gen_Utility_Pvt.ADD('Getting the Coverage and txn Group Id');
4297             Csd_Gen_Utility_Pvt.ADD('contract_line_id =' ||
4298                                     x_product_txn_rec.contract_id);
4299         END IF;
4300 
4301         IF l_incident_id IS NOT NULL
4302         THEN
4303             OPEN get_account_details(l_incident_id);
4304             FETCH get_account_details
4305                 INTO l_party_id, l_account_id;
4306             IF (get_account_details%NOTFOUND OR l_party_id IS NULL)
4307             THEN
4308                 Fnd_Message.SET_NAME('CSD', 'CSD_API_PARTY_MISSING');
4309                 Fnd_Message.SET_TOKEN('INCIDENT_ID', l_incident_id);
4310                 Fnd_Msg_Pub.ADD;
4311                 RAISE Fnd_Api.G_EXC_ERROR;
4312             END IF;
4313             IF get_account_details%ISOPEN
4314             THEN
4315                 CLOSE get_account_details;
4316             END IF;
4317         END IF;
4318 
4319         IF (g_debug > 0)
4320         THEN
4321             Csd_Gen_Utility_Pvt.ADD('l_party_id                            =' ||
4322                                     l_party_id);
4323             Csd_Gen_Utility_Pvt.ADD('l_account_id                          =' ||
4324                                     l_account_id);
4325             Csd_Gen_Utility_Pvt.ADD('x_product_txn_rec.txn_billing_type_id =' ||
4326                                     x_product_txn_rec.txn_billing_type_id);
4327             Csd_Gen_Utility_Pvt.ADD('x_product_txn_rec.organization_id     =' ||
4328                                     x_product_txn_rec.organization_id);
4329         END IF;
4330 
4331         -- Derive the line type and line category code
4332         -- from the transaction billing type
4333         Csd_Process_Util.GET_LINE_TYPE(p_txn_billing_type_id => x_product_txn_rec.txn_billing_type_id,
4334                                        p_org_id              => x_product_txn_rec.organization_id,
4335                                        x_line_type_id        => l_line_type_id,
4336                                        x_line_category_code  => l_line_category_code,
4337                                        x_return_status       => x_return_status);
4338 
4339         IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
4340         THEN
4341             RAISE Fnd_Api.G_EXC_ERROR;
4342         END IF;
4343 
4344         IF (g_debug > 0)
4345         THEN
4346             Csd_Gen_Utility_Pvt.ADD('l_line_type_id                  =' ||
4347                                     l_line_type_id);
4348             Csd_Gen_Utility_Pvt.ADD('l_line_category_code            =' ||
4349                                     l_line_category_code);
4350             Csd_Gen_Utility_Pvt.ADD('x_product_txn_rec.price_list_id =' ||
4351                                     x_product_txn_rec.price_list_id);
4352         END IF;
4353 
4354         -- If line_type_id Or line_category_code is null
4355         -- then raise error
4356         IF (l_line_type_id IS NULL OR l_line_category_code IS NULL)
4357         THEN
4358             Fnd_Message.SET_NAME('CSD', 'CSD_API_LINE_TYPE_MISSING');
4359             Fnd_Message.SET_TOKEN('TXN_BILLING_TYPE_ID',
4360                                   x_product_txn_rec.txn_billing_type_id);
4361             Fnd_Msg_Pub.ADD;
4362             RAISE Fnd_Api.G_EXC_ERROR;
4363         END IF;
4364 
4365         -- Get the currency code from the price list if it is null or g_miss
4366         IF NVL(x_product_txn_rec.price_list_id, Fnd_Api.G_MISS_NUM) <>
4367            Fnd_Api.G_MISS_NUM
4368         THEN
4369             BEGIN
4370                 SELECT currency_code
4371                   INTO l_curr_code
4372                   FROM oe_price_lists
4373                  WHERE price_list_id = x_product_txn_rec.price_list_id;
4374             EXCEPTION
4375                 WHEN NO_DATA_FOUND THEN
4376                     Fnd_Message.SET_NAME('CSD',
4377                                          'CSD_API_INV_PRICE_LIST_ID');
4378                     Fnd_Message.SET_TOKEN('PRICE_LIST_ID',
4379                                           x_product_txn_rec.price_list_id);
4380                     Fnd_Msg_Pub.ADD;
4381                     RAISE Fnd_Api.G_EXC_ERROR;
4382                 WHEN TOO_MANY_ROWS THEN
4383                     IF (g_debug > 0)
4384                     THEN
4385                         Csd_Gen_Utility_Pvt.ADD('Too many currency_codes');
4386                     END IF;
4387             END;
4388         END IF;
4389 
4390         IF (g_debug > 0)
4391         THEN
4392             Csd_Gen_Utility_Pvt.ADD('l_curr_code          =' ||
4393                                     l_curr_code);
4394         END IF;
4395 
4396         -- If l_curr_code is null then raise error
4397         IF l_curr_code IS NULL
4398         THEN
4399             Fnd_Message.SET_NAME('CSD', 'CSD_API_INV_CURR_CODE');
4400             Fnd_Message.SET_TOKEN('PRICE_LIST_ID',
4401                                   x_product_txn_rec.price_list_id);
4402             Fnd_Msg_Pub.ADD;
4403             RAISE Fnd_Api.G_EXC_ERROR;
4404         END IF;
4405 
4406         l_serial_flag := Csd_Process_Util.Is_item_serialized(x_product_txn_rec.inventory_item_id);
4407 
4408 
4409         -- swai: bug 5931926 - 12.0.2 3rd party logistics
4410         -- Instead of adding 3rd party action types to if-then statement,
4411         -- we are commenting the code out altogether.  Currently, the
4412         -- if conditions do not allow any product transaction lines
4413         -- through except walk-in-receipt, which is no longer supported.
4414         -- We should allow RMA line creation without Serial number for
4415         -- all action types.
4416         /*****
4417         -- Serial Number required if the item is serialized
4418         -- changing it from serial_number to source_serial_number 11.5.10
4419         IF l_serial_flag AND x_product_txn_rec.source_serial_number IS NULL AND
4420            x_product_txn_rec.action_type NOT IN ('SHIP') AND
4421            (x_product_txn_rec.action_code <> 'LOANER' AND
4422            x_product_txn_rec.action_type <>'RMA')
4423         THEN
4424             Fnd_Message.SET_NAME('CSD', 'CSD_API_SERIAL_NUM_MISSING');
4425             Fnd_Message.SET_TOKEN('INVENTORY_ITEM_ID',
4426                                   x_product_txn_rec.inventory_item_id);
4427             Fnd_Msg_Pub.ADD;
4428             IF (g_debug > 0)
4429             THEN
4430                 Csd_Gen_Utility_Pvt.ADD('Serial Number missing for inventory_item_id =' ||
4431                                         x_product_txn_rec.inventory_item_id);
4432             END IF;
4433             RAISE Fnd_Api.G_EXC_ERROR;
4434         END IF;
4435         *****/
4436 
4437         -- assigning values for the charge record
4438         x_product_txn_rec.incident_id         := l_incident_id;
4439         x_product_txn_rec.business_process_id := l_bus_process_id;
4440         x_product_txn_rec.line_type_id        := l_line_type_id;
4441         x_product_txn_rec.currency_code       := l_curr_code;
4442         x_product_txn_rec.line_category_code  := l_line_category_code;
4443         x_estimate_detail_id                  := x_product_txn_rec.estimate_detail_id;
4444 
4445         Csd_Gen_Utility_Pvt.ADD('Call csd_product_transactions_pkg.insert_row to insert prod txns');
4446 
4447         Csd_Product_Transactions_Pkg.INSERT_ROW(px_PRODUCT_TRANSACTION_ID  => x_product_txn_rec.PRODUCT_TRANSACTION_ID,
4448                                                 p_REPAIR_LINE_ID           => x_product_txn_rec.REPAIR_LINE_ID,
4449                                                 p_ESTIMATE_DETAIL_ID       => x_estimate_detail_id,
4450                                                 p_ACTION_TYPE              => x_product_txn_rec.ACTION_TYPE,
4451                                                 p_ACTION_CODE              => x_product_txn_rec.ACTION_CODE,
4452                                                 p_LOT_NUMBER               => x_product_txn_rec.LOT_NUMBER,
4453                                                 p_SUB_INVENTORY            => x_product_txn_rec.SUB_INVENTORY,
4454                                                 p_INTERFACE_TO_OM_FLAG     => x_product_txn_rec.INTERFACE_TO_OM_FLAG,
4455                                                 p_BOOK_SALES_ORDER_FLAG    => x_product_txn_rec.BOOK_SALES_ORDER_FLAG,
4456                                                 p_RELEASE_SALES_ORDER_FLAG => x_product_txn_rec.RELEASE_SALES_ORDER_FLAG,
4457                                                 p_SHIP_SALES_ORDER_FLAG    => x_product_txn_rec.SHIP_SALES_ORDER_FLAG,
4458                                                 p_PROD_TXN_STATUS          => 'SUBMITTED',
4459                                                 p_PROD_TXN_CODE            => x_product_txn_rec.PROD_TXN_CODE,
4460                                                 p_LAST_UPDATE_DATE         => SYSDATE,
4461                                                 p_CREATION_DATE            => SYSDATE,
4462                                                 p_LAST_UPDATED_BY          => Fnd_Global.USER_ID,
4463                                                 p_CREATED_BY               => Fnd_Global.USER_ID,
4464                                                 p_LAST_UPDATE_LOGIN        => Fnd_Global.USER_ID,
4465                                                 p_ATTRIBUTE1               => x_product_txn_rec.ATTRIBUTE1,
4466                                                 p_ATTRIBUTE2               => x_product_txn_rec.ATTRIBUTE2,
4467                                                 p_ATTRIBUTE3               => x_product_txn_rec.ATTRIBUTE3,
4468                                                 p_ATTRIBUTE4               => x_product_txn_rec.ATTRIBUTE4,
4469                                                 p_ATTRIBUTE5               => x_product_txn_rec.ATTRIBUTE5,
4470                                                 p_ATTRIBUTE6               => x_product_txn_rec.ATTRIBUTE6,
4471                                                 p_ATTRIBUTE7               => x_product_txn_rec.ATTRIBUTE7,
4472                                                 p_ATTRIBUTE8               => x_product_txn_rec.ATTRIBUTE8,
4473                                                 p_ATTRIBUTE9               => x_product_txn_rec.ATTRIBUTE9,
4474                                                 p_ATTRIBUTE10              => x_product_txn_rec.ATTRIBUTE10,
4475                                                 p_ATTRIBUTE11              => x_product_txn_rec.ATTRIBUTE11,
4476                                                 p_ATTRIBUTE12              => x_product_txn_rec.ATTRIBUTE12,
4477                                                 p_ATTRIBUTE13              => x_product_txn_rec.ATTRIBUTE13,
4478                                                 p_ATTRIBUTE14              => x_product_txn_rec.ATTRIBUTE14,
4479                                                 p_ATTRIBUTE15              => x_product_txn_rec.ATTRIBUTE15,
4480                                                 p_CONTEXT                  => x_product_txn_rec.CONTEXT,
4481                                                 p_OBJECT_VERSION_NUMBER    => 1,
4482                                                 P_SOURCE_SERIAL_NUMBER     => x_product_txn_rec.source_serial_number,
4483                                                 P_SOURCE_INSTANCE_ID       => x_product_txn_rec.source_instance_Id,
4484                                                 P_NON_SOURCE_SERIAL_NUMBER => x_product_txn_rec.non_source_serial_number,
4485                                                 P_NON_SOURCE_INSTANCE_ID   => x_product_txn_rec.non_source_instance_id,
4486                                                 P_REQ_HEADER_ID            => x_product_txn_rec.Req_Header_Id,
4487                                                 P_REQ_LINE_ID              => x_product_txn_rec.Req_Line_Id,
4488                                                 P_ORDER_HEADER_ID          => x_Product_Txn_Rec.Order_Header_Id,
4489                                                 P_ORDER_LINE_ID            => x_Product_Txn_Rec.Order_Line_Id,
4490                                                 P_PRD_TXN_QTY_RECEIVED     => x_product_txn_rec.Prd_Txn_Qty_Received,
4491                                                 P_PRD_TXN_QTY_SHIPPED      => x_product_txn_rec.Prd_Txn_Qty_Shipped,
4492                                                 P_SUB_INVENTORY_RCVD       => x_product_txn_rec.Sub_Inventory_Rcvd,
4493                                                 P_LOT_NUMBER_RCVD          => x_product_txn_rec.Lot_Number_Rcvd,
4494                                                 P_LOCATOR_ID               => x_product_txn_rec.Locator_Id,
4495                                                 p_picking_rule_id          => x_product_txn_rec.picking_rule_id, --R12 development changes
4496                                                 P_PROJECT_ID               => x_product_txn_rec.project_id,
4497                                                 P_TASK_ID                  => x_product_txn_rec.task_id,
4498                                                 P_UNIT_NUMBER              => x_product_txn_rec.unit_number,
4499                                                 P_INTERNAL_PO_HEADER_ID    => x_product_txn_rec.internal_po_header_id);  -- swai: bug 6148019
4500 
4501 
4502         Csd_Gen_Utility_Pvt.ADD('PRODUCT_TRANSACTION_ID    =' ||
4503                                 x_product_txn_rec.PRODUCT_TRANSACTION_ID);
4504         Csd_Gen_Utility_Pvt.ADD('REPAIR_ORDER_ID    =' ||
4505                                 x_product_txn_rec.repair_line_id);
4506 
4507         UPDATE csd_repairs
4508            SET ro_txn_status = 'OM_SUBMITTED'
4509          WHERE repair_line_id = x_product_txn_rec.REPAIR_LINE_ID;
4510         IF SQL%NOTFOUND
4511         THEN
4512             Fnd_Message.SET_NAME('CSD', 'CSD_ERR_REPAIRS_UPDATE');
4513             Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
4514                                   x_product_txn_rec.repair_line_id);
4515             Fnd_Msg_Pub.ADD;
4516             RAISE Fnd_Api.G_EXC_ERROR;
4517         END IF;
4518 
4519         -- Api body ends here
4520 
4521         -- Standard check of p_commit.
4522         IF Fnd_Api.To_Boolean(p_commit)
4523         THEN
4524             COMMIT WORK;
4525         END IF;
4526 
4527         -- Standard call to get message count and IF count is  get message info.
4528         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4529                                   p_data  => x_msg_data);
4530     EXCEPTION
4531         WHEN Fnd_Api.G_EXC_ERROR THEN
4532             x_return_status := Fnd_Api.G_RET_STS_ERROR;
4533             ROLLBACK TO create_product_txn;
4534             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4535                                       p_data  => x_msg_data);
4536         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
4537             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
4538             ROLLBACK TO create_product_txn;
4539             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4540                                       p_data  => x_msg_data);
4541         WHEN OTHERS THEN
4542             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
4543             ROLLBACK TO create_product_txn;
4544             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
4545             THEN
4546                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
4547             END IF;
4548             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4549                                       p_data  => x_msg_data);
4550     END create_ext_prod_txn;
4551 
4552     /*----------------------------------------------------------------*/
4553     /* procedure name: update_product_txn                             */
4554     /* description   : procedure to update product txn lines.It is    */
4555     /*                 called from ON-UPDATE trigger in the repair    */
4556     /*                 order form                                     */
4557     /*----------------------------------------------------------------*/
4558 
4559     PROCEDURE update_product_txn(p_api_version      IN NUMBER,
4560                                  p_commit           IN VARCHAR2 := Fnd_Api.g_false,
4561                                  p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
4562                                  p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
4563                                  x_product_txn_rec  IN OUT NOCOPY PRODUCT_TXN_REC,
4564                                  x_return_status    OUT NOCOPY VARCHAR2,
4565                                  x_msg_count        OUT NOCOPY NUMBER,
4566                                  x_msg_data         OUT NOCOPY VARCHAR2) IS
4567 
4568         l_api_name    CONSTANT VARCHAR2(30) := 'UPDATE_PRODUCT_TXN';
4569         l_api_version CONSTANT NUMBER := 1.0;
4570         l_msg_count          NUMBER;
4571         l_msg_data           VARCHAR2(2000);
4572         l_msg_index          NUMBER;
4573 	   l_return_status      VARCHAR2(1);
4574         l_estimate_Rec       Cs_Charge_Details_Pub.charges_rec_type;
4575         l_prodtxn_db_attr    Csd_Logistics_Util.PRODTXN_DB_ATTR_REC;
4576 		l_order_Rec          Csd_Process_Pvt.om_interface_rec;
4577 		l_est_detail_id      NUMBER;
4578 		l_add_to_order_id    NUMBER;
4579 		l_add_to_order_flag  VARCHAR2(1);
4580 		l_transaction_type_id  NUMBER;
4581 		l_repair_line_id     NUMBER;
4582 
4583 	   create_order EXCEPTION;
4584         book_order EXCEPTION;
4585         release_order EXCEPTION;
4586         ship_order EXCEPTION;
4587 
4588 
4589         CURSOR estimate(p_rep_line_id IN NUMBER) IS
4590             SELECT estimate_detail_id, object_version_number
4591               FROM cs_estimate_details
4592              WHERE source_id = p_rep_line_id
4593                AND source_code = 'DR'
4594                AND interface_to_oe_flag = 'N'
4595                AND order_header_id IS NULL
4596                AND order_line_id IS NULL;
4597 
4598 
4599         -- Variables used in FND Log
4600         l_error_level NUMBER := Fnd_Log.LEVEL_ERROR;
4601         l_excep_level NUMBER := Fnd_Log.LEVEL_EXCEPTION;
4602         l_statement_level  NUMBER := Fnd_Log.LEVEL_STATEMENT;
4603 
4604 
4605         l_mod_name    VARCHAR2(2000) := 'csd.plsql.csd_process_pvt.update_product_txn';
4606 
4607     BEGIN
4608 
4609 
4610         SAVEPOINT UPDATE_PRODUCT_TXN_PVT;
4611 
4612         -- Initialize API return status to success
4613         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4614 
4615         -- Fix for bug#6210765
4616         -- Initialize message list if p_init_msg_list is set to TRUE.
4617 	IF Fnd_Api.to_Boolean(p_init_msg_list)
4618 	THEN
4619 	  Fnd_Msg_Pub.initialize;
4620 	END IF;
4621 
4622 
4623         l_prodtxn_db_attr := Csd_Logistics_Util.get_prodtxn_db_attr(x_product_txn_rec.product_transaction_id);
4624 
4625         -- Debug message
4626         -----------------------------------------------------------------------------
4627         /*********************************************************************
4628         /* Code here got moved to CSD_LOGISTICS_UTIL.upd_prodtxn_n_chrgline
4629         **********************************************************************/
4630         -----------------------------------------------------------------------------
4631         Csd_Logistics_Util.upd_prodtxn_n_chrgline(x_product_txn_rec ,
4632 				                  l_prodtxn_db_attr,
4633 				                  l_est_detail_id,
4634 						  l_repair_line_id,
4635 						  l_add_to_order_flag,
4636 						  l_add_to_order_id,
4637 						  l_transaction_type_id);
4638 
4639 	x_product_txn_Rec.estimate_detail_id  := l_est_detail_id;
4640 	x_product_txn_Rec.repair_line_id      := l_repair_line_id;
4641 	x_product_txn_Rec.add_to_order_flag   := l_add_to_order_flag;
4642 	x_product_txn_Rec.order_header_id     := l_add_to_order_id;
4643         x_product_txn_rec.transaction_type_id := l_transaction_type_id;
4644 
4645 
4646         Debug('process_txn_flag      =' ||
4647               x_product_txn_rec.process_txn_flag,
4648               l_mod_name,
4649               l_statement_level);
4650         Debug('interface_to_om_flag  =' ||
4651               x_product_txn_rec.interface_to_om_flag,
4652               l_mod_name,
4653               l_statement_level);
4654         Debug('book_sales_order_flag =' ||
4655               x_product_txn_rec.book_sales_order_flag,
4656               l_mod_name,
4657               l_statement_level);
4658         Debug('release_sales_order_flag =' ||
4659               x_product_txn_rec.release_sales_order_flag,
4660               l_mod_name,
4661               l_statement_level);
4662         Debug('ship_sales_order_flag =' ||
4663               x_product_txn_rec.ship_sales_order_flag,
4664               l_mod_name,
4665               l_statement_level);
4666 
4667 
4668         IF x_product_txn_rec.process_txn_flag = 'Y'
4669         THEN
4670 
4671              -- Define savepoint
4672              SAVEPOINT create_sales_order;
4673 
4674         /*******************************************************************
4675         Code here has been moved to CSD_LOGISTICS_UTIL.interface_prodtxn
4676         ********************************************************************/
4677 
4678 		  l_order_Rec := Csd_Logistics_Util.get_order_rec(x_product_txn_rec.repair_line_id);
4679 
4680 		  --bug#6071005
4681 		  if (x_product_txn_rec.order_line_id is not null) THEN
4682 		      l_order_Rec.order_line_id := x_product_txn_rec.order_line_id;
4683 		  End If;
4684 
4685         -- swai: bug 5931926 - 12.0.2 3rd party logistics.  If the bill to party
4686         -- and account have been specified, then this is a 3rd party logistics line,
4687         -- and we need to override the SR party and account from get_order_rec with
4688         -- the thrid party info
4689         /*IF (nvl(x_product_txn_rec.bill_to_account_id, FND_API.GMISS_NUM) <> FND_API.GMISS_NUM) AND
4690            (nvl(x_product_txn_rec.bill_to_party_id, FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM) THEN          */
4691         IF (x_product_txn_rec.bill_to_party_id is not null) and
4692            (x_product_txn_rec.bill_to_account_id is not null) THEN
4693            l_order_Rec.party_id := x_product_txn_rec.bill_to_party_id;
4694            l_order_Rec.account_id := x_product_txn_rec.bill_to_account_id;
4695         END IF;
4696 
4697             Csd_Logistics_Util.interface_prodtxn(  x_return_status  =>   l_return_status,
4698 		                                         p_product_txn_rec => x_product_txn_rec,
4699                         						 p_prodtxn_db_attr     => l_prodtxn_db_attr,
4700                         						 px_order_rec          => l_order_rec);
4701 
4702 		  IF NOT (l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
4703 		      RAISE Create_ORDER;
4704 		  END IF;
4705             IF l_prodtxn_db_attr.curr_book_order_flag <>
4706                x_product_txn_rec.book_sales_order_flag AND
4707                x_product_txn_rec.book_sales_order_flag = 'Y'
4708             THEN
4709                 -- Define savepoint
4710                 SAVEPOINT book_sales_order;
4711                 /***************************************************
4712                 Code here has been moved to the api book_prodtxn
4713                 ****************************************************/
4714                 Csd_Logistics_Util.book_prodtxn(  x_return_status  =>   l_return_status,
4715 			                                   p_product_txn_rec => x_product_txn_rec,
4716                         						 p_prodtxn_db_attr     => l_prodtxn_db_attr,
4717                         						 px_order_rec          => l_order_rec);
4718 			  IF NOT (l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
4719 				 RAISE BOOK_ORDER;
4720 			  END IF;
4721 
4722 
4723             END IF; -- end of book order
4724 
4725             IF l_prodtxn_db_attr.curr_release_order_flag <>
4726                x_product_txn_rec.release_sales_order_flag AND
4727                x_product_txn_rec.release_sales_order_flag = 'Y'
4728             THEN
4729                     -- Define savepoint
4730                     SAVEPOINT release_sales_order;
4731                     /*******************************************************************
4732                     Code here has been moved to CSD_LOGISTICS_UTIL.pickrelease_prodtxn
4733                     ********************************************************************/
4734                     Csd_Logistics_Util.pickrelease_prodtxn(x_return_status  =>   l_return_status,
4735 				                 p_product_txn_rec => x_product_txn_rec,
4736                         			  p_prodtxn_db_attr     => l_prodtxn_db_attr,
4737                         			  px_order_rec          => l_order_rec);
4738 				IF NOT (l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
4739 				  RAISE RELEASE_ORDER;
4740 			     END IF;
4741             END IF; --end of pick-release sales order
4742 
4743             IF l_prodtxn_db_attr.curr_ship_order_flag <>
4744                x_product_txn_rec.ship_sales_order_flag AND
4745                x_product_txn_rec.ship_sales_order_flag = 'Y'
4746             THEN
4747                     -- Define savepoint
4748                     SAVEPOINT ship_sales_order;
4749                     /*******************************************************************
4750                     Code here has been moved to CSD_LOGISTICS_UTIL.ship_prodtxn
4751                     ********************************************************************/
4752                     Csd_Logistics_Util.ship_prodtxn( x_return_status  =>   l_return_status,
4753 				           p_product_txn_rec => x_product_txn_rec,
4754                         		 p_prodtxn_db_attr     => l_prodtxn_db_attr,
4755                         		 px_order_rec          => l_order_rec);
4756 
4757 				IF NOT (l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
4758 				   RAISE SHIP_ORDER;
4759 				END IF;
4760 
4761             END IF; -- end of ship sales order
4762 
4763         END IF; --end of process txn
4764 
4765         -- Api body ends here
4766 
4767         -- Standard check of p_commit.
4768         IF Fnd_Api.To_Boolean(p_commit)
4769         THEN
4770             COMMIT WORK;
4771         END IF;
4772 
4773         -- Standard call to get message count and IF count is  get message info.
4774         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4775                                   p_data  => x_msg_data);
4776     EXCEPTION
4777         WHEN CREATE_ORDER THEN
4778             x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4779 
4780 		       /*FP Fixed for bug#4526773
4781 		         When error occurred then complete rollback should be
4782 		         done so that sanity of charge line and product line
4783 		         remain intact.
4784 		       */
4785             --ROLLBACK TO create_sales_order;
4786 
4787       		 ROLLBACK TO UPDATE_PRODUCT_TXN_PVT;
4788 
4789             -- update the prod txn as the charge
4790             -- line was not interfaced
4791             UPDATE csd_product_transactions
4792                SET interface_to_om_flag     = 'N',
4793                    book_sales_order_flag    = 'N',
4794                    release_sales_order_flag = 'N',
4795                    ship_sales_order_flag    = 'N'
4796              WHERE product_transaction_id =
4797                    x_product_txn_rec.PRODUCT_TRANSACTION_ID;
4798             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4799                                       p_data  => x_msg_data);
4800         WHEN BOOK_ORDER THEN
4801             x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4802             ROLLBACK TO book_sales_order;
4803             -- update the prod txn as the order
4804             -- line was not booked
4805             UPDATE csd_product_transactions
4806                SET book_sales_order_flag    = 'N',
4807                    release_sales_order_flag = 'N',
4808                    ship_sales_order_flag    = 'N'
4809              WHERE product_transaction_id =
4810                    x_product_txn_rec.PRODUCT_TRANSACTION_ID;
4811             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4812                                       p_data  => x_msg_data);
4813         WHEN RELEASE_ORDER THEN
4814             x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4815             ROLLBACK TO release_sales_order;
4816             -- update the prod txn as the order
4817             -- line was not booked
4818             UPDATE csd_product_transactions
4819                SET release_sales_order_flag = 'N',
4820                    ship_sales_order_flag    = 'N'
4821              WHERE product_transaction_id =
4822                    x_product_txn_rec.PRODUCT_TRANSACTION_ID;
4823             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4824                                       p_data  => x_msg_data);
4825         WHEN SHIP_ORDER THEN
4826             x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4827             ROLLBACK TO ship_sales_order;
4828             -- update the prod txn as the order
4829             -- line was not booked
4830             UPDATE csd_product_transactions
4831                SET ship_sales_order_flag = 'N'
4832              WHERE product_transaction_id =
4833                    x_product_txn_rec.PRODUCT_TRANSACTION_ID;
4834             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4835                                       p_data  => x_msg_data);
4836         WHEN Fnd_Api.G_EXC_ERROR THEN
4837             x_return_status := Fnd_Api.G_RET_STS_ERROR;
4838             ROLLBACK TO UPDATE_PRODUCT_TXN_PVT;
4839             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4840                                       p_data  => x_msg_data);
4841              Debug('in exc_error, x_msg_data,count[' || x_msg_data|| ','||to_char(x_msg_count)||']',
4842 			    l_mod_name,
4843 			    l_statement_level);
4844 		   IF x_msg_count > 1 THEN
4845 			  FOR i IN 1..x_msg_count LOOP
4846 				l_msg_data := apps.FND_MSG_PUB.Get(i,FND_API.G_TRUE) ;
4847 				Debug('in exc_error, l_msg_data[' || l_msg_data||']',
4848 					    l_mod_name,
4849 					    l_statement_level);
4850 			  END LOOP ;
4851 		   END IF ;
4852         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
4853             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
4854             ROLLBACK TO UPDATE_PRODUCT_TXN_PVT;
4855             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4856                                       p_data  => x_msg_data);
4857              Debug('in unexp_Error, x_msg_data[' || x_msg_data||']',
4858               l_mod_name,
4859               l_statement_level);
4860 		   IF x_msg_count > 1 THEN
4861 			  FOR i IN 1..x_msg_count LOOP
4862 				l_msg_data := apps.FND_MSG_PUB.Get(i,apps.FND_API.G_FALSE) ;
4863 				Debug('in exc_error, l_msg_data[' || l_msg_data||']',
4864 					    l_mod_name,
4865 					    l_statement_level);
4866 			  END LOOP ;
4867 		   END IF ;
4868         WHEN OTHERS THEN
4869             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
4870             ROLLBACK TO UPDATE_PRODUCT_TXN_PVT;
4871             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
4872             THEN
4873                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
4874             END IF;
4875             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4876                                       p_data  => x_msg_data);
4877              Debug('in others, x_msg_data[' || x_msg_data||']',
4878               l_mod_name,
4879               l_statement_level);
4880 		   IF x_msg_count > 1 THEN
4881 			  FOR i IN 1..x_msg_count LOOP
4882 				l_msg_data := apps.FND_MSG_PUB.Get(i,apps.FND_API.G_FALSE) ;
4883 				Debug('in exc_error, l_msg_data[' || l_msg_data||']',
4884 					    l_mod_name,
4885 					    l_statement_level);
4886 			  END LOOP ;
4887 		   END IF ;
4888     END update_product_txn;
4889 
4890     /*--------------------------------------------------*/
4891     /* procedure name: delete_product_txn               */
4892     /* description   : procedure used to delete         */
4893     /*                 product transaction lines        */
4894     /*                                                  */
4895     /*--------------------------------------------------*/
4896 
4897     PROCEDURE delete_product_txn(p_api_version      IN NUMBER,
4898                                  p_commit           IN VARCHAR2 := Fnd_Api.g_false,
4899                                  p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
4900                                  p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
4901                                  p_product_txn_id   IN NUMBER,
4902                                  x_return_status    OUT NOCOPY VARCHAR2,
4903                                  x_msg_count        OUT NOCOPY NUMBER,
4904                                  x_msg_data         OUT NOCOPY VARCHAR2) IS
4905         l_api_name    CONSTANT VARCHAR2(30) := 'DELETE_PRODUCT_TXN';
4906         l_api_version CONSTANT NUMBER := 1.0;
4907         l_msg_count          NUMBER;
4908         l_msg_data           VARCHAR2(2000);
4909         l_msg_index          NUMBER;
4910         l_Charges_Rec        Cs_Charge_Details_Pub.charges_rec_type;
4911         x_estimate_detail_id NUMBER;
4912         l_est_detail_id      NUMBER;
4913         l_delete_allow       VARCHAR2(1);
4914 
4915     BEGIN
4916         -- Standard Start of API savepoint
4917         SAVEPOINT delete_product_txn;
4918 
4919         -- Standard call to check for call compatibility.
4920         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
4921                                            p_api_version,
4922                                            l_api_name,
4923                                            G_PKG_NAME)
4924         THEN
4925             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
4926         END IF;
4927 
4928         -- Initialize message list if p_init_msg_list is set to TRUE.
4929         IF Fnd_Api.to_Boolean(p_init_msg_list)
4930         THEN
4931             Fnd_Msg_Pub.initialize;
4932         END IF;
4933 
4934         -- Initialize API return status to success
4935         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4936 
4937         -- Api body starts
4938         IF (g_debug > 0)
4939         THEN
4940             Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
4941                                               p_api_name => l_api_name);
4942         END IF;
4943         IF (g_debug > 0)
4944         THEN
4945             Csd_Gen_Utility_Pvt.ADD('Check reqd parameter :prod txn Id ');
4946             Csd_Gen_Utility_Pvt.ADD('product txn Id  = ' ||
4947                                     p_product_txn_id);
4948         END IF;
4949 
4950         -- Check the required parameter
4951         Csd_Process_Util.Check_Reqd_Param(p_param_value => p_product_txn_id,
4952                                           p_param_name  => 'PRODUCT_TRANSACTION_ID',
4953                                           p_api_name    => l_api_name);
4954 
4955         IF (g_debug > 0)
4956         THEN
4957             Csd_Gen_Utility_Pvt.ADD('Validate product txn id');
4958         END IF;
4959 
4960         -- Validate the repair line ID
4961         IF NOT
4962             (Csd_Process_Util.Validate_prod_txn_id(p_prod_txn_id => p_product_txn_id))
4963         THEN
4964             RAISE Fnd_Api.G_EXC_ERROR;
4965         END IF;
4966 
4967         -- The Product txn line is allowed to delete
4968         -- only if it is not interfaced
4969         BEGIN
4970             SELECT a.estimate_detail_id
4971               INTO l_est_detail_id
4972               FROM csd_product_transactions a, cs_estimate_details b
4973              WHERE a.estimate_detail_id = b.estimate_detail_id
4974                AND a.product_transaction_id = p_product_txn_id
4975                AND b.order_header_id IS NULL;
4976 
4977             l_delete_allow := 'Y';
4978         EXCEPTION
4979             WHEN NO_DATA_FOUND THEN
4980                 l_delete_allow := 'N';
4981                 Fnd_Message.SET_NAME('CSD', 'CSD_API_DELETE_NOT_ALLOWED');
4982                 --FND_MESSAGE.SET_TOKEN('PRODUCT_TXN_ID',p_product_txn_id);
4983                 Fnd_Msg_Pub.ADD;
4984                 IF (g_debug > 0)
4985                 THEN
4986                     Csd_Gen_Utility_Pvt.ADD('Product txn is interfaced,so it cannot be deleted');
4987                 END IF;
4988                 RAISE Fnd_Api.G_EXC_ERROR;
4989             WHEN TOO_MANY_ROWS THEN
4990                 IF (g_debug > 0)
4991                 THEN
4992                     Csd_Gen_Utility_Pvt.ADD('Too many from Product txn line is allowed to delete');
4993                 END IF;
4994         END;
4995 
4996         IF (g_debug > 0)
4997         THEN
4998             Csd_Gen_Utility_Pvt.ADD('l_delete_allow     =' ||
4999                                     l_delete_allow);
5000             Csd_Gen_Utility_Pvt.ADD('Estimate Detail Id =' ||
5001                                     l_est_detail_id);
5002         END IF;
5003 
5004         IF l_delete_allow = 'Y'
5005         THEN
5006             l_Charges_Rec.estimate_detail_id := l_est_detail_id;
5007             IF (g_debug > 0)
5008             THEN
5009                 Csd_Gen_Utility_Pvt.ADD('Call process_charge_lines to delete');
5010             END IF;
5011 
5012             PROCESS_CHARGE_LINES(p_api_version        => 1.0,
5013                                  p_commit             => Fnd_Api.g_false,
5014                                  p_init_msg_list      => Fnd_Api.g_true,
5015                                  p_validation_level   => Fnd_Api.g_valid_level_full,
5016                                  p_action             => 'DELETE',
5017                                  p_Charges_Rec        => l_Charges_Rec,
5018                                  x_estimate_detail_id => x_estimate_detail_id,
5019                                  x_return_status      => x_return_status,
5020                                  x_msg_count          => x_msg_count,
5021                                  x_msg_data           => x_msg_data);
5022 
5023             IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
5024             THEN
5025                 RAISE Fnd_Api.G_EXC_ERROR;
5026             END IF;
5027 
5028             IF (g_debug > 0)
5029             THEN
5030                 Csd_Gen_Utility_Pvt.ADD('Call csd_product_transactions_pkg.Delete_Row');
5031             END IF;
5032 
5033             Csd_Product_Transactions_Pkg.Delete_Row(p_PRODUCT_TRANSACTION_ID => p_product_txn_id);
5034         END IF; --end of delete
5035 
5036         -- Api body ends here
5037 
5038         -- Standard check of p_commit.
5039         IF Fnd_Api.To_Boolean(p_commit)
5040         THEN
5041             COMMIT WORK;
5042         END IF;
5043 
5044         -- Standard call to get message count and IF count is  get message info.
5045         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5046                                   p_data  => x_msg_data);
5047     EXCEPTION
5048         WHEN Fnd_Api.G_EXC_ERROR THEN
5049             x_return_status := Fnd_Api.G_RET_STS_ERROR;
5050             ROLLBACK TO delete_product_txn;
5051             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5052                                       p_data  => x_msg_data);
5053         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
5054             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5055             ROLLBACK TO delete_product_txn;
5056             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5057                                       p_data  => x_msg_data);
5058         WHEN OTHERS THEN
5059             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5060             ROLLBACK TO delete_product_txn;
5061             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
5062             THEN
5063                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
5064             END IF;
5065             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5066                                       p_data  => x_msg_data);
5067     END delete_product_txn;
5068 
5069     /*--------------------------------------------------*/
5070     /* procedure name: create_default_prod_txn          */
5071     /* description   : procedure used to create         */
5072     /*         default product transaction lines        */
5073     /*                                                  */
5074     /*--------------------------------------------------*/
5075 
5076     PROCEDURE create_default_prod_txn(p_api_version      IN NUMBER,
5077                                       p_commit           IN VARCHAR2 := Fnd_Api.g_false,
5078                                       p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
5079                                       p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
5080                                       p_repair_line_id   IN NUMBER,
5081                                       x_return_status    OUT NOCOPY VARCHAR2,
5082                                       x_msg_count        OUT NOCOPY NUMBER,
5083                                       x_msg_data         OUT NOCOPY VARCHAR2) IS
5084 
5085         l_api_name    CONSTANT VARCHAR2(30) := 'CREATE_DEFAULT_PROD_TXN';
5086         l_api_version CONSTANT NUMBER := 1.0;
5087         l_msg_count       NUMBER;
5088         l_msg_data        VARCHAR2(2000);
5089         l_msg_index       NUMBER;
5090         l_product_txn_rec product_txn_rec;
5091         x_prod_txn_tbl    product_txn_tbl;
5092         x_msg_index_out   NUMBER;
5093         l_msg_text        VARCHAR2(2000) := '';
5094 
5095         l_sr_add_to_order_flag  VARCHAR2(10);
5096         l_ro_add_to_order_flag  VARCHAR2(10);
5097         l_add_rma_to_id       NUMBER;
5098         l_add_ship_to_id      NUMBER;
5099 
5100 
5101     BEGIN
5102         -- Standard Start of API savepoint
5103         SAVEPOINT create_default_prod_txn;
5104 
5105         -- Standard call to check for call compatibility.
5106         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
5107                                            p_api_version,
5108                                            l_api_name,
5109                                            G_PKG_NAME)
5110         THEN
5111             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
5112         END IF;
5113 
5114         -- Initialize message list if p_init_msg_list is set to TRUE.
5115         IF Fnd_Api.to_Boolean(p_init_msg_list)
5116         THEN
5117             Fnd_Msg_Pub.initialize;
5118         END IF;
5119 
5120         -- Initialize API return status to success
5121         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
5122 
5123         -- Api body starts
5124         IF (g_debug > 0)
5125         THEN
5126             Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
5127                                               p_api_name => l_api_name);
5128         END IF;
5129         IF (g_debug > 0)
5130         THEN
5131             Csd_Gen_Utility_Pvt.ADD('Check the required parameter:(repair_line_id)');
5132             Csd_Gen_Utility_Pvt.ADD('Repair line id =' || p_repair_line_id);
5133         END IF;
5134 
5135         -- Check the required parameter
5136         Csd_Process_Util.Check_Reqd_Param(p_param_value => p_repair_line_id,
5137                                           p_param_name  => 'REPAIR_LINE_ID',
5138                                           p_api_name    => l_api_name);
5139 
5140         IF (g_debug > 0)
5141         THEN
5142             Csd_Gen_Utility_Pvt.ADD('Validate repair line id');
5143         END IF;
5144 
5145         -- Validate the repair line ID
5146         IF NOT
5147             (Csd_Process_Util.Validate_rep_line_id(p_repair_line_id => p_repair_line_id))
5148         THEN
5149             RAISE Fnd_Api.G_EXC_ERROR;
5150         END IF;
5151 
5152         IF (g_debug > 0)
5153         THEN
5154             Csd_Gen_Utility_Pvt.ADD('Build the product txn table');
5155         END IF;
5156 
5157         l_sr_add_to_order_flag := fnd_profile.value('CSD_ADD_TO_SO_WITHIN_SR');
5158         l_sr_add_to_order_flag := nvl(l_sr_Add_to_order_flag, 'N');
5159 
5160         l_ro_add_to_order_flag := fnd_profile.value('CSD_ADD_TO_SO_WITHIN_RO');
5161         l_ro_add_to_order_flag := nvl(l_ro_add_to_order_flag, 'N');
5162 
5163         Csd_Process_Util.BUILD_PROD_TXN_TBL(p_repair_line_id => p_repair_line_id,
5164                                             x_prod_txn_tbl   => x_prod_txn_tbl,
5165                                             x_return_status  => x_return_status);
5166 
5167         IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
5168         THEN
5169             RAISE Fnd_Api.G_EXC_ERROR;
5170         END IF;
5171 
5172         IF (g_debug > 0)
5173         THEN
5174             Csd_Gen_Utility_Pvt.ADD('x_prod_txn_tbl.count =' ||
5175                                     x_prod_txn_tbl.COUNT);
5176         END IF;
5177 
5178         IF x_prod_txn_tbl.COUNT > 0 THEN
5179           FOR i IN x_prod_txn_tbl.first..1
5180           LOOP
5181 
5182              IF (g_debug > 0 ) THEN
5183                 csd_gen_utility_pvt.ADD('Call create_product_txn in a loop');
5184              END IF;
5185 
5186              CREATE_PRODUCT_TXN
5187              (p_api_version           =>  1.0 ,
5188               p_commit                =>  fnd_api.g_false,
5189               p_init_msg_list         =>  'F',
5190               p_validation_level      =>  fnd_api.g_valid_level_full,
5191               x_product_txn_rec       =>  x_prod_txn_tbl(i),
5192               x_return_status         =>  x_return_status,
5193               x_msg_count             =>  x_msg_count,
5194               x_msg_data              =>  x_msg_data  );
5195 
5196               IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
5197                  RAISE FND_API.G_EXC_ERROR;
5198               END IF;
5199               -- Log the message after processing
5200               -- each prod txn
5201               FOR i in 1..x_msg_Count LOOP
5202                    FND_MSG_PUB.Get
5203                            (p_msg_index     => i,
5204                             p_encoded       => 'F',
5205                             p_data          => x_msg_data,
5206                             p_msg_index_out => x_msg_index_out );
5207                    l_msg_text := x_msg_data;
5208                    IF (g_debug > 0 ) THEN
5209                       csd_gen_utility_pvt.ADD('message data after create_prod_txn ='||x_msg_data);
5210                    END IF;
5211               End LOOP;
5212           END LOOP;
5213 
5214           FOR i IN 2..x_prod_txn_tbl.last
5215           LOOP
5216 
5217              IF (g_debug > 0 ) THEN
5218                 csd_gen_utility_pvt.ADD('Call create_product_txn in a loop 2');
5219              END IF;
5220 
5221              If ((i = 2) and (x_prod_txn_tbl(i).interface_to_om_flag = 'Y') and
5222                  (x_prod_txn_tbl(i).new_order_flag = 'Y' or x_prod_txn_tbl(i).new_order_flag is null) and
5223                  ((l_sr_add_to_order_flag = 'Y') or (l_ro_add_to_order_flag = 'Y'))) Then
5224 
5225                   l_add_rma_to_id := CSD_PROCESS_UTIL.get_sr_add_to_order(p_repair_line_Id, 'RMA');
5226                   l_add_ship_to_id := CSD_PROCESS_UTIL.get_sr_add_to_order(p_repair_line_Id, 'SHIP');
5227                   If (x_prod_txn_tbl(i).action_type = 'SHIP' and (l_add_ship_to_id is not null)) Then
5228 	                   x_prod_txn_tbl(i).new_order_flag := 'N';
5229 	                   x_prod_txn_tbl(i).add_to_order_flag := 'Y';
5230 	                   x_prod_txn_tbl(i).add_to_order_id := l_add_ship_to_id;
5231                   elsif (x_prod_txn_tbl(i).action_type = 'RMA' and (l_add_rma_to_id is not null)) Then
5232 	                   x_prod_txn_tbl(i).new_order_flag := 'N';
5233 	                   x_prod_txn_tbl(i).add_to_order_flag := 'Y';
5234 	                   x_prod_txn_tbl(i).add_to_order_id := l_add_rma_to_id;
5235                   End If;
5236 
5237                   --special case
5238                   If ((NVL(x_prod_txn_tbl(1).interface_to_om_flag, 'N') = 'N') and (l_sr_add_to_order_flag = 'N')
5239                      and (l_ro_add_to_order_flag = 'Y')) Then
5240                         x_prod_txn_tbl(i).new_order_flag := 'Y';
5241                         x_prod_txn_tbl(i).add_to_order_flag := 'N';
5242                         x_prod_txn_tbl(i).add_to_order_id := null;
5243                   End if;
5244 
5245              END IF;
5246 
5247              CREATE_PRODUCT_TXN
5248              (p_api_version           =>  1.0 ,
5249               p_commit                =>  fnd_api.g_false,
5250               p_init_msg_list         =>  'F',
5251               p_validation_level      =>  fnd_api.g_valid_level_full,
5252               x_product_txn_rec       =>  x_prod_txn_tbl(i),
5253               x_return_status         =>  x_return_status,
5254               x_msg_count             =>  x_msg_count,
5255               x_msg_data              =>  x_msg_data  );
5256 
5257               IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
5258                  RAISE FND_API.G_EXC_ERROR;
5259               END IF;
5260               -- Log the message after processing
5261               -- each prod txn
5262               FOR i in 1..x_msg_Count LOOP
5263                    FND_MSG_PUB.Get
5264                            (p_msg_index     => i,
5265                             p_encoded       => 'F',
5266                             p_data          => x_msg_data,
5267                             p_msg_index_out => x_msg_index_out );
5268                    l_msg_text := x_msg_data;
5269                    IF (g_debug > 0 ) THEN
5270                       csd_gen_utility_pvt.ADD('message data after create_prod_txn ='||x_msg_data);
5271                    END IF;
5272               End LOOP;
5273           END LOOP;
5274        END IF;
5275 
5276         -- Api body ends here
5277         IF l_msg_text IS NOT NULL
5278         THEN
5279             Fnd_Message.SET_NAME('CSD', 'CSD_API_OM_ERR_MSG');
5280             Fnd_Message.SET_TOKEN('MSG_DATA', l_msg_text);
5281             Fnd_Msg_Pub.ADD;
5282         END IF;
5283 
5284         -- Standard check of p_commit.
5285         IF Fnd_Api.To_Boolean(p_commit)
5286         THEN
5287             COMMIT WORK;
5288         END IF;
5289 
5290         -- Standard call to get message count and IF count is  get message info.
5291         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5292                                   p_data  => x_msg_data);
5293 
5294     EXCEPTION
5295         WHEN Fnd_Api.G_EXC_ERROR THEN
5296             ROLLBACK TO create_default_prod_txn;
5297             x_return_status := Fnd_Api.G_RET_STS_ERROR;
5298             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5299                                       p_data  => x_msg_data);
5300         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
5301             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5302             ROLLBACK TO create_default_prod_txn;
5303             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5304                                       p_data  => x_msg_data);
5305         WHEN OTHERS THEN
5306             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5307             ROLLBACK TO create_default_prod_txn;
5308             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
5309             THEN
5310                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
5311             END IF;
5312             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5313                                       p_data  => x_msg_data);
5314     END create_default_prod_txn;
5315 
5316     --------------------- travi changes---------------
5317 
5318     FUNCTION GET_ORG_REC_TYPE RETURN HZ_PARTY_V2PUB.ORGANIZATION_REC_TYPE IS
5319         TMP_ORG_REC_TYPE HZ_PARTY_V2PUB.ORGANIZATION_REC_TYPE;
5320     BEGIN
5321         RETURN TMP_ORG_REC_TYPE;
5322     END GET_ORG_REC_TYPE;
5323     FUNCTION GET_GROUP_REC_TYPE RETURN HZ_PARTY_V2PUB.GROUP_REC_TYPE IS
5324         TMP_GROUP_REC_TYPE HZ_PARTY_V2PUB.GROUP_REC_TYPE;
5325     BEGIN
5326         RETURN TMP_GROUP_REC_TYPE;
5327     END GET_GROUP_REC_TYPE;
5328     FUNCTION GET_PARTY_REC_TYPE RETURN HZ_PARTY_V2PUB.PARTY_REC_TYPE IS
5329         TMP_PARTY_REC_TYPE HZ_PARTY_V2PUB.PARTY_REC_TYPE;
5330     BEGIN
5331         RETURN TMP_PARTY_REC_TYPE;
5332     END GET_PARTY_REC_TYPE;
5333     FUNCTION GET_PERSON_REC_TYPE RETURN HZ_PARTY_V2PUB.PERSON_REC_TYPE IS
5334         TMP_PERSON_REC_TYPE HZ_PARTY_V2PUB.PERSON_REC_TYPE;
5335     BEGIN
5336         RETURN TMP_PERSON_REC_TYPE;
5337     END GET_PERSON_REC_TYPE;
5338     FUNCTION GET_CONTACT_POINTS_REC_TYPE
5339         RETURN HZ_CONTACT_POINT_V2PUB.CONTACT_POINT_REC_TYPE IS
5340         TMP_CONTACT_POINTS_REC_TYPE HZ_CONTACT_POINT_V2PUB.CONTACT_POINT_REC_TYPE;
5341     BEGIN
5342         RETURN TMP_CONTACT_POINTS_REC_TYPE;
5343     END GET_CONTACT_POINTS_REC_TYPE;
5344     FUNCTION GET_EDI_REC_TYPE RETURN HZ_CONTACT_POINT_V2PUB.EDI_REC_TYPE IS
5345         TMP_EDI_REC_TYPE HZ_CONTACT_POINT_V2PUB.EDI_REC_TYPE;
5346     BEGIN
5347         RETURN TMP_EDI_REC_TYPE;
5348     END GET_EDI_REC_TYPE;
5349     FUNCTION GET_PHONE_REC_TYPE RETURN HZ_CONTACT_POINT_V2PUB.PHONE_REC_TYPE IS
5350         TMP_PHONE_REC_TYPE HZ_CONTACT_POINT_V2PUB.PHONE_REC_TYPE;
5351     BEGIN
5352         RETURN TMP_PHONE_REC_TYPE;
5353     END GET_PHONE_REC_TYPE;
5354     FUNCTION GET_EMAIL_REC_TYPE RETURN HZ_CONTACT_POINT_V2PUB.EMAIL_REC_TYPE IS
5355         TMP_EMAIL_REC_TYPE HZ_CONTACT_POINT_V2PUB.EMAIL_REC_TYPE;
5356     BEGIN
5357         RETURN TMP_EMAIL_REC_TYPE;
5358     END GET_EMAIL_REC_TYPE;
5359     FUNCTION GET_TELEX_REC_TYPE RETURN HZ_CONTACT_POINT_V2PUB.TELEX_REC_TYPE IS
5360         TMP_TELEX_REC_TYPE HZ_CONTACT_POINT_V2PUB.TELEX_REC_TYPE;
5361     BEGIN
5362         RETURN TMP_TELEX_REC_TYPE;
5363     END GET_TELEX_REC_TYPE;
5364     FUNCTION GET_WEB_REC_TYPE RETURN HZ_CONTACT_POINT_V2PUB.WEB_REC_TYPE IS
5365         TMP_WEB_REC_TYPE HZ_CONTACT_POINT_V2PUB.WEB_REC_TYPE;
5366     BEGIN
5367         RETURN TMP_WEB_REC_TYPE;
5368     END GET_WEB_REC_TYPE;
5369     FUNCTION GET_ACCOUNT_REC_TYPE
5370         RETURN HZ_CUST_ACCOUNT_V2PUB.CUST_ACCOUNT_REC_TYPE IS
5371         TMP_ACCOUNT_REC_TYPE HZ_CUST_ACCOUNT_V2PUB.CUST_ACCOUNT_REC_TYPE;
5372     BEGIN
5373         RETURN TMP_ACCOUNT_REC_TYPE;
5374     END GET_ACCOUNT_REC_TYPE;
5375     FUNCTION GET_PARTY_REL_REC_TYPE RETURN HZ_RELATIONSHIP_V2PUB.RELATIONSHIP_REC_TYPE IS
5376         TMP_PARTY_REL_REC_TYPE HZ_RELATIONSHIP_V2PUB.RELATIONSHIP_REC_TYPE;
5377     BEGIN
5378         RETURN TMP_PARTY_REL_REC_TYPE;
5379     END GET_PARTY_REL_REC_TYPE;
5380     FUNCTION GET_ORG_CONTACT_REC_TYPE RETURN HZ_PARTY_CONTACT_V2PUB.ORG_CONTACT_REC_TYPE IS
5381         TMP_ORG_CONTACT_REC_TYPE HZ_PARTY_CONTACT_V2PUB.ORG_CONTACT_REC_TYPE;
5382     BEGIN
5383         RETURN TMP_ORG_CONTACT_REC_TYPE;
5384     END GET_ORG_CONTACT_REC_TYPE;
5385     FUNCTION GET_PARTY_SITE_REC_TYPE RETURN HZ_PARTY_SITE_V2PUB.PARTY_SITE_REC_TYPE IS
5386         TMP_PARTY_SITE_REC_TYPE HZ_PARTY_SITE_V2PUB.PARTY_SITE_REC_TYPE;
5387     BEGIN
5388         RETURN TMP_PARTY_SITE_REC_TYPE;
5389     END GET_PARTY_SITE_REC_TYPE;
5390     FUNCTION GET_PARTY_SITE_USE_REC_TYPE
5391         RETURN HZ_PARTY_SITE_V2PUB.PARTY_SITE_USE_REC_TYPE IS
5392         TMP_PARTY_SITE_USE_REC_TYPE HZ_PARTY_SITE_V2PUB.PARTY_SITE_USE_REC_TYPE;
5393     BEGIN
5394         RETURN TMP_PARTY_SITE_USE_REC_TYPE;
5395     END GET_PARTY_SITE_USE_REC_TYPE;
5396     FUNCTION GET_CUST_PROFILE_REC_TYPE
5397         RETURN HZ_CUSTOMER_PROFILE_V2PUB.CUSTOMER_PROFILE_REC_TYPE IS
5398         TMP_CUST_PROFILE_REC_TYPE HZ_CUSTOMER_PROFILE_V2PUB.CUSTOMER_PROFILE_REC_TYPE;
5399     BEGIN
5400         RETURN TMP_CUST_PROFILE_REC_TYPE;
5401     END GET_CUST_PROFILE_REC_TYPE;
5402     FUNCTION GET_CREATE_TASK_REC_TYPE
5403         RETURN Csd_Process_Pvt.CREATE_TASK_REC_TYPE IS
5404         TMP_CREATE_TASK_REC_TYPE Csd_Process_Pvt.CREATE_TASK_REC_TYPE;
5405     BEGIN
5406         RETURN TMP_CREATE_TASK_REC_TYPE;
5407     END GET_CREATE_TASK_REC_TYPE;
5408 
5409     /*-----------------------------------------------------------------------------------------------------------*/
5410     /* procedure name: create_task                                                                               */
5411     /* description   : procedure used to create task                                                             */
5412     /* Called from   : Depot Repair Form to Create Task                                                          */
5413     /* Input Parm    : p_api_version         NUMBER      Required Api Version number                             */
5414     /*                 p_init_msg_list       VARCHAR2    Optional Initializes message stack if fnd_api.g_true,   */
5415     /*                                                            default value is fnd_api.g_false               */
5416     /*                 p_commit              VARCHAR2    Optional Commits in API if fnd_api.g_true, default      */
5417     /*                                                            fnd_api.g_false                                */
5418     /*                 p_validation_level    NUMBER      Optional API uses this parameter to determine which     */
5419     /*                                                            validation steps must be done and which steps  */
5420     /*                                                            should be skipped.                             */
5421     /*                 CREATE_TASK_REC_TYPE  RECORD      Required Columns are in the Record CREATE_TASK_REC_TYPE */
5422     /* Output Parm   : x_return_status       VARCHAR2             Return status after the call. The status can be*/
5423     /*                                                            fnd_api.g_ret_sts_success (success)            */
5424     /*                                                            fnd_api.g_ret_sts_error (error)                */
5425     /*                                                            fnd_api.g_ret_sts_unexp_error (unexpected)     */
5426     /*                 x_msg_count           NUMBER               Number of messages in the message stack        */
5427     /*                 x_msg_data            VARCHAR2             Message text if x_msg_count >= 1               */
5428     /*                 x_task_id             NUMBER               Task Id of the created Task                    */
5429     /*-----------------------------------------------------------------------------------------------------------*/
5430 
5431     PROCEDURE create_task(p_api_version      IN NUMBER,
5432                           p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
5433                           p_commit           IN VARCHAR2 := Fnd_Api.g_false,
5434                           p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
5435                           p_create_task_rec  IN CREATE_TASK_REC_TYPE,
5436                           x_return_status    OUT NOCOPY VARCHAR2,
5437                           x_msg_count        OUT NOCOPY NUMBER,
5438                           x_msg_data         OUT NOCOPY VARCHAR2,
5439                           x_task_id          OUT NOCOPY NUMBER) IS
5440         l_api_name    CONSTANT VARCHAR2(30) := 'CREATE_TASK';
5441         l_api_version CONSTANT NUMBER := 1.0;
5442         l_msg_count     NUMBER;
5443         l_msg_data      VARCHAR2(2000);
5444         l_msg_index     NUMBER;
5445         l_return_status VARCHAR2(1);
5446         l_task_id       NUMBER;
5447         -- Task record
5448         l_create_task_rec Csd_Process_Pvt.CREATE_TASK_REC_TYPE := p_create_task_rec;
5449     BEGIN
5450         -- -----------------
5451         -- Begin create task
5452         -- -----------------
5453         -- Standard Start of API savepoint
5454         SAVEPOINT create_task;
5455         -- Standard call to check for call compatibility.
5456         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
5457                                            p_api_version,
5458                                            l_api_name,
5459                                            G_PKG_NAME)
5460         THEN
5461             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
5462         END IF;
5463         -- Initialize message list if p_init_msg_list is set to TRUE.
5464         IF Fnd_Api.to_Boolean(p_init_msg_list)
5465         THEN
5466             Fnd_Msg_Pub.initialize;
5467         END IF;
5468         -- Initialize API return status to success
5469         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
5470         -- ---------------
5471         -- Api body starts
5472         -- ---------------
5473         IF (g_debug > 0)
5474         THEN
5475             Csd_Gen_Utility_Pvt.ADD('CSD_PROCESS_PVT.create_task before jtf_tasks_pub.CREATE_TASK');
5476         END IF;
5477 
5478         -- ----------------------------------------
5479         -- Calling Public JTF API to create a Task
5480         -- ----------------------------------------
5481         Jtf_Tasks_Pub.CREATE_TASK(P_API_VERSION             => 1.0,
5482                                   P_INIT_MSG_LIST           => Fnd_Api.g_true,
5483                                   P_COMMIT                  => Fnd_Api.g_false,
5484                                   P_TASK_ID                 => l_create_task_rec.task_id,
5485                                   P_TASK_NAME               => l_create_task_rec.TASK_NAME,
5486                                   P_TASK_TYPE_ID            => l_create_task_rec.TASK_TYPE_ID,
5487                                   P_DESCRIPTION             => l_create_task_rec.DESCRIPTION,
5488                                   P_TASK_STATUS_ID          => l_create_task_rec.TASK_STATUS_ID,
5489                                   P_TASK_PRIORITY_ID        => l_create_task_rec.TASK_PRIORITY_ID,
5490                                   P_OWNER_TYPE_CODE         => l_create_task_rec.OWNER_TYPE_CODE,
5491                                   P_OWNER_ID                => l_create_task_rec.OWNER_ID,
5492                                   P_OWNER_TERRITORY_ID      => l_create_task_rec.OWNER_TERRITORY_ID,
5493                                   P_ASSIGNED_BY_ID          => l_create_task_rec.ASSIGNED_BY_ID,
5494                                   P_CUSTOMER_ID             => l_create_task_rec.CUSTOMER_ID,
5495                                   P_CUST_ACCOUNT_ID         => l_create_task_rec.CUST_ACCOUNT_ID,
5496                                   P_ADDRESS_ID              => l_create_task_rec.ADDRESS_ID,
5497                                   P_PLANNED_START_DATE      => l_create_task_rec.planned_start_date,
5498                                   P_PLANNED_END_DATE        => l_create_task_rec.planned_end_date,
5499                                   P_SCHEDULED_START_DATE    => l_create_task_rec.scheduled_start_date,
5500                                   P_SCHEDULED_END_DATE      => l_create_task_rec.scheduled_end_date,
5501                                   P_ACTUAL_START_DATE       => l_create_task_rec.actual_start_date,
5502                                   P_ACTUAL_END_DATE         => l_create_task_rec.actual_end_date,
5503                                   P_TIMEZONE_ID             => l_create_task_rec.TIMEZONE_ID,
5504                                   P_SOURCE_OBJECT_TYPE_CODE => l_create_task_rec.SOURCE_OBJECT_TYPE_CODE,
5505                                   P_SOURCE_OBJECT_ID        => l_create_task_rec.SOURCE_OBJECT_ID,
5506                                   P_SOURCE_OBJECT_NAME      => l_create_task_rec.SOURCE_OBJECT_NAME,
5507                                   P_DURATION                => l_create_task_rec.DURATION,
5508                                   P_DURATION_UOM            => l_create_task_rec.DURATION_UOM,
5509                                   P_PLANNED_EFFORT          => l_create_task_rec.PLANNED_EFFORT,
5510                                   P_PLANNED_EFFORT_UOM      => l_create_task_rec.PLANNED_EFFORT_UOM,
5511                                   P_ACTUAL_EFFORT           => l_create_task_rec.ACTUAL_EFFORT,
5512                                   P_ACTUAL_EFFORT_UOM       => l_create_task_rec.ACTUAL_EFFORT_UOM,
5513                                   P_PRIVATE_FLAG            => l_create_task_rec.PRIVATE_FLAG,
5514                                   P_PUBLISH_FLAG            => l_create_task_rec.PUBLISH_FLAG,
5515                                   P_RESTRICT_CLOSURE_FLAG   => l_create_task_rec.RESTRICT_CLOSURE_FLAG,
5516                                   P_ATTRIBUTE1              => l_create_task_rec.ATTRIBUTE1,
5517                                   P_ATTRIBUTE2              => l_create_task_rec.ATTRIBUTE2,
5518                                   P_ATTRIBUTE3              => l_create_task_rec.ATTRIBUTE3,
5519                                   P_ATTRIBUTE4              => l_create_task_rec.ATTRIBUTE4,
5520                                   P_ATTRIBUTE5              => l_create_task_rec.ATTRIBUTE5,
5521                                   P_ATTRIBUTE6              => l_create_task_rec.ATTRIBUTE6,
5522                                   P_ATTRIBUTE7              => l_create_task_rec.ATTRIBUTE7,
5523                                   P_ATTRIBUTE8              => l_create_task_rec.ATTRIBUTE8,
5524                                   P_ATTRIBUTE9              => l_create_task_rec.ATTRIBUTE9,
5525                                   P_ATTRIBUTE10             => l_create_task_rec.ATTRIBUTE10,
5526                                   P_ATTRIBUTE11             => l_create_task_rec.ATTRIBUTE11,
5527                                   P_ATTRIBUTE12             => l_create_task_rec.ATTRIBUTE12,
5528                                   P_ATTRIBUTE13             => l_create_task_rec.ATTRIBUTE13,
5529                                   P_ATTRIBUTE14             => l_create_task_rec.ATTRIBUTE14,
5530                                   P_ATTRIBUTE15             => l_create_task_rec.ATTRIBUTE15,
5531                                   P_ATTRIBUTE_CATEGORY      => l_create_task_rec.ATTRIBUTE_CATEGORY,
5532                                   P_BOUND_MODE_CODE         => l_create_task_rec.bound_mode_code,
5533                                   P_SOFT_BOUND_FLAG         => l_create_task_rec.soft_bound_flag,
5534                                   P_PARENT_TASK_ID          => l_create_task_rec.PARENT_TASK_ID,
5535                                   P_ESCALATION_LEVEL        => l_create_task_rec.ESCALATION_LEVEL,
5536                                   X_RETURN_STATUS           => x_return_status,
5537                                   X_MSG_COUNT               => x_msg_count,
5538                                   X_MSG_DATA                => x_msg_data,
5539                                   X_TASK_ID                 => x_task_id);
5540 
5541         IF (g_debug > 0)
5542         THEN
5543             Csd_Gen_Utility_Pvt.ADD('CSD_PROCESS_PVT.create_task after jtf_tasks_pub.CREATE_TASK x_return_status' ||
5544                                     x_return_status);
5545         END IF;
5546 
5547         -- -------------------
5548         -- Api body ends here
5549         -- -------------------
5550         -- Standard check of p_commit.
5551         IF Fnd_Api.To_Boolean(p_commit)
5552         THEN
5553             COMMIT WORK;
5554         END IF;
5555         -- Standard call to get message count and IF count is  get message info.
5556         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5557                                   p_data  => x_msg_data);
5558     EXCEPTION
5559         WHEN Fnd_Api.G_EXC_ERROR THEN
5560             ROLLBACK TO create_task;
5561             x_return_status := Fnd_Api.G_RET_STS_ERROR;
5562             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5563                                       p_data  => x_msg_data);
5564         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
5565             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5566             ROLLBACK TO create_task;
5567             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5568                                       p_data  => x_msg_data);
5569         WHEN OTHERS THEN
5570             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5571             ROLLBACK TO create_task;
5572             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
5573             THEN
5574                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
5575             END IF;
5576             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5577                                       p_data  => x_msg_data);
5578     END create_task;
5579 
5580     /*-----------------------------------------------------------------------------------------------------------*/
5581     /* procedure name: update_task                                                                               */
5582     /* description   : procedure used to update task                                                             */
5583     /* Called from   : Depot Repair Form to Create Task                                                          */
5584     /* Input Parm    : p_api_version         NUMBER      Required Api Version number                             */
5585     /*                 p_init_msg_list       VARCHAR2    Optional Initializes message stack if fnd_api.g_true,   */
5586     /*                                                            default value is fnd_api.g_false               */
5587     /*                 p_commit              VARCHAR2    Optional Commits in API if fnd_api.g_true, default      */
5588     /*                                                            fnd_api.g_false                                */
5589     /*                 p_validation_level    NUMBER      Optional API uses this parameter to determine which     */
5590     /*                                                            validation steps must be done and which steps  */
5591     /*                                                            should be skipped.                             */
5592     /*                 CREATE_TASK_REC_TYPE  RECORD      Required Columns are in the Record CREATE_TASK_REC_TYPE */
5593     /* Output Parm   : x_return_status       VARCHAR2             Return status after the call. The status can be*/
5594     /*                                                            fnd_api.g_ret_sts_success (success)            */
5595     /*                                                            fnd_api.g_ret_sts_error (error)                */
5596     /*                                                            fnd_api.g_ret_sts_unexp_error (unexpected)     */
5597     /*                 x_msg_count           NUMBER               Number of messages in the message stack        */
5598     /*                 x_msg_data            VARCHAR2             Message text if x_msg_count >= 1               */
5599     /*-----------------------------------------------------------------------------------------------------------*/
5600 
5601     PROCEDURE update_task(p_api_version      IN NUMBER,
5602                           p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
5603                           p_commit           IN VARCHAR2 := Fnd_Api.g_false,
5604                           p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
5605                           p_create_task_rec  IN CREATE_TASK_REC_TYPE,
5606                           x_return_status    OUT NOCOPY VARCHAR2,
5607                           x_msg_count        OUT NOCOPY NUMBER,
5608                           x_msg_data         OUT NOCOPY VARCHAR2) IS
5609         l_api_name    CONSTANT VARCHAR2(30) := 'UPDATE_TASK';
5610         l_api_version CONSTANT NUMBER := 1.0;
5611         l_msg_count     NUMBER;
5612         l_msg_data      VARCHAR2(2000);
5613         l_msg_index     NUMBER;
5614         l_return_status VARCHAR2(1);
5615         l_task_id       NUMBER;
5616         -- Task record
5617         l_create_task_rec Csd_Process_Pvt.CREATE_TASK_REC_TYPE := p_create_task_rec;
5618     BEGIN
5619         -- -----------------
5620         -- Begin update task
5621         -- -----------------
5622         -- Standard Start of API savepoint
5623         SAVEPOINT update_task;
5624         -- Standard call to check for call compatibility.
5625         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
5626                                            p_api_version,
5627                                            l_api_name,
5628                                            G_PKG_NAME)
5629         THEN
5630             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
5631         END IF;
5632         -- Initialize message list if p_init_msg_list is set to TRUE.
5633         IF Fnd_Api.to_Boolean(p_init_msg_list)
5634         THEN
5635             Fnd_Msg_Pub.initialize;
5636         END IF;
5637         -- Initialize API return status to success
5638         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
5639         -- ---------------
5640         -- Api body starts
5641         -- ---------------
5642         IF (g_debug > 0)
5643         THEN
5644             Csd_Gen_Utility_Pvt.ADD('CSD_PROCESS_PVT.update_task before jtf_tasks_pub.UPDATE_TASK');
5645         END IF;
5646 
5647         -- ----------------------------------------
5648         -- Calling Public JTF API to Update a Task
5649         -- ----------------------------------------
5650         Jtf_Tasks_Pub.UPDATE_TASK(P_API_VERSION             => 1.0,
5651                                   P_INIT_MSG_LIST           => Fnd_Api.g_true,
5652                                   P_COMMIT                  => Fnd_Api.g_false,
5653                                   P_TASK_ID                 => l_create_task_rec.task_id,
5654                                   P_TASK_NAME               => l_create_task_rec.TASK_NAME,
5655                                   P_TASK_TYPE_ID            => l_create_task_rec.TASK_TYPE_ID,
5656                                   P_DESCRIPTION             => l_create_task_rec.DESCRIPTION,
5657                                   P_TASK_STATUS_ID          => l_create_task_rec.TASK_STATUS_ID,
5658                                   P_TASK_PRIORITY_NAME      => l_create_task_rec.TASK_PRIORITY_NAME,
5659                                   P_TASK_PRIORITY_ID        => l_create_task_rec.TASK_PRIORITY_ID,
5660                                   P_OWNER_TYPE_CODE         => l_create_task_rec.OWNER_TYPE_CODE,
5661                                   P_OWNER_ID                => l_create_task_rec.OWNER_ID,
5662                                   P_OWNER_TERRITORY_ID      => l_create_task_rec.OWNER_TERRITORY_ID,
5663                                   P_ASSIGNED_BY_ID          => l_create_task_rec.ASSIGNED_BY_ID,
5664                                   P_CUSTOMER_ID             => l_create_task_rec.CUSTOMER_ID,
5665                                   P_CUST_ACCOUNT_ID         => l_create_task_rec.CUST_ACCOUNT_ID,
5666                                   P_ADDRESS_ID              => l_create_task_rec.ADDRESS_ID,
5667                                   P_PLANNED_START_DATE      => l_create_task_rec.planned_start_date,
5668                                   P_PLANNED_END_DATE        => l_create_task_rec.planned_end_date,
5669                                   P_SCHEDULED_START_DATE    => l_create_task_rec.scheduled_start_date,
5670                                   P_SCHEDULED_END_DATE      => l_create_task_rec.scheduled_end_date,
5671                                   P_ACTUAL_START_DATE       => l_create_task_rec.actual_start_date,
5672                                   P_ACTUAL_END_DATE         => l_create_task_rec.actual_end_date,
5673                                   P_TIMEZONE_ID             => l_create_task_rec.TIMEZONE_ID,
5674                                   P_SOURCE_OBJECT_TYPE_CODE => l_create_task_rec.SOURCE_OBJECT_TYPE_CODE,
5675                                   P_SOURCE_OBJECT_ID        => l_create_task_rec.SOURCE_OBJECT_ID,
5676                                   P_SOURCE_OBJECT_NAME      => l_create_task_rec.SOURCE_OBJECT_NAME,
5677                                   P_DURATION                => l_create_task_rec.DURATION,
5678                                   P_DURATION_UOM            => l_create_task_rec.DURATION_UOM,
5679                                   P_PLANNED_EFFORT          => l_create_task_rec.PLANNED_EFFORT,
5680                                   P_PLANNED_EFFORT_UOM      => l_create_task_rec.PLANNED_EFFORT_UOM,
5681                                   P_ACTUAL_EFFORT           => l_create_task_rec.ACTUAL_EFFORT,
5682                                   P_ACTUAL_EFFORT_UOM       => l_create_task_rec.ACTUAL_EFFORT_UOM,
5683                                   P_PRIVATE_FLAG            => l_create_task_rec.PRIVATE_FLAG,
5684                                   P_PUBLISH_FLAG            => l_create_task_rec.PUBLISH_FLAG,
5685                                   P_RESTRICT_CLOSURE_FLAG   => l_create_task_rec.RESTRICT_CLOSURE_FLAG,
5686                                   P_ATTRIBUTE1              => l_create_task_rec.ATTRIBUTE1,
5687                                   P_ATTRIBUTE2              => l_create_task_rec.ATTRIBUTE2,
5688                                   P_ATTRIBUTE3              => l_create_task_rec.ATTRIBUTE3,
5689                                   P_ATTRIBUTE4              => l_create_task_rec.ATTRIBUTE4,
5690                                   P_ATTRIBUTE5              => l_create_task_rec.ATTRIBUTE5,
5691                                   P_ATTRIBUTE6              => l_create_task_rec.ATTRIBUTE6,
5692                                   P_ATTRIBUTE7              => l_create_task_rec.ATTRIBUTE7,
5693                                   P_ATTRIBUTE8              => l_create_task_rec.ATTRIBUTE8,
5694                                   P_ATTRIBUTE9              => l_create_task_rec.ATTRIBUTE9,
5695                                   P_ATTRIBUTE10             => l_create_task_rec.ATTRIBUTE10,
5696                                   P_ATTRIBUTE11             => l_create_task_rec.ATTRIBUTE11,
5697                                   P_ATTRIBUTE12             => l_create_task_rec.ATTRIBUTE12,
5698                                   P_ATTRIBUTE13             => l_create_task_rec.ATTRIBUTE13,
5699                                   P_ATTRIBUTE14             => l_create_task_rec.ATTRIBUTE14,
5700                                   P_ATTRIBUTE15             => l_create_task_rec.ATTRIBUTE15,
5701                                   P_ATTRIBUTE_CATEGORY      => l_create_task_rec.ATTRIBUTE_CATEGORY,
5702                                   P_BOUND_MODE_CODE         => l_create_task_rec.bound_mode_code,
5703                                   P_SOFT_BOUND_FLAG         => l_create_task_rec.soft_bound_flag,
5704                                   P_PARENT_TASK_ID          => l_create_task_rec.PARENT_TASK_ID,
5705                                   P_ESCALATION_LEVEL        => l_create_task_rec.ESCALATION_LEVEL,
5706                                   P_OBJECT_VERSION_NUMBER   => l_create_task_rec.OBJECT_VERSION_NUMBER,
5707                                   X_RETURN_STATUS           => x_return_status,
5708                                   X_MSG_COUNT               => x_msg_count,
5709                                   X_MSG_DATA                => x_msg_data);
5710 
5711         IF (g_debug > 0)
5712         THEN
5713             Csd_Gen_Utility_Pvt.ADD('CSD_PROCESS_PVT.update_task after jtf_tasks_pub.UPDATE_TASK x_return_status' ||
5714                                     x_return_status);
5715         END IF;
5716 
5717         -- -------------------
5718         -- Api body ends here
5719         -- -------------------
5720         -- Standard check of p_commit.
5721         IF Fnd_Api.To_Boolean(p_commit)
5722         THEN
5723             COMMIT WORK;
5724         END IF;
5725         -- Standard call to get message count and IF count is  get message info.
5726         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5727                                   p_data  => x_msg_data);
5728     EXCEPTION
5729         WHEN Fnd_Api.G_EXC_ERROR THEN
5730             ROLLBACK TO update_task;
5731             x_return_status := Fnd_Api.G_RET_STS_ERROR;
5732             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5733                                       p_data  => x_msg_data);
5734         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
5735             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5736             ROLLBACK TO update_task;
5737             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5738                                       p_data  => x_msg_data);
5739         WHEN OTHERS THEN
5740             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5741             ROLLBACK TO update_task;
5742             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
5743             THEN
5744                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
5745             END IF;
5746             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5747                                       p_data  => x_msg_data);
5748     END update_task;
5749     FUNCTION GET_ADDRESS_REC_TYPE RETURN Csd_Process_Pvt.ADDRESS_REC_TYPE IS
5750         TMP_ADDRESS_REC_TYPE Csd_Process_Pvt.ADDRESS_REC_TYPE;
5751     BEGIN
5752         RETURN TMP_ADDRESS_REC_TYPE;
5753     END GET_ADDRESS_REC_TYPE;
5754 
5755     /*-----------------------------------------------------------------------------------------------------------*/
5756     /* procedure name: create_address                                                                            */
5757     /* description   : procedure to create Address for the Contact                                               */
5758     /* Called from   : Depot Repair Form to Create Address                                                       */
5759     /* Input Parm    : p_address_rec         RECORD      Required Record ADDRESS_REC_TYPE                        */
5760     /* Output Parm   : x_return_status       VARCHAR2             Return status after the call. The status can be*/
5761     /*                                                            fnd_api.g_ret_sts_success (success)            */
5762     /*                                                            fnd_api.g_ret_sts_error (error)                */
5763     /*                                                            fnd_api.g_ret_sts_unexp_error (unexpected)     */
5764     /*                 x_msg_count           NUMBER               Number of messages in the message stack        */
5765     /*                 x_msg_data            VARCHAR2             Message text if x_msg_count >= 1               */
5766     /*                 x_location_id         NUMBER               Location ID of the Contacts address created    */
5767     /*-----------------------------------------------------------------------------------------------------------*/
5768 
5769     PROCEDURE Create_Address(p_address_rec   IN ADDRESS_REC_TYPE,
5770                              x_msg_count     OUT NOCOPY NUMBER,
5771                              x_msg_data      OUT NOCOPY VARCHAR2,
5772                              x_return_status OUT NOCOPY VARCHAR2,
5773                              x_location_id   OUT NOCOPY NUMBER) IS
5774         l_location_rec  HZ_LOCATION_V2PUB.LOCATION_REC_TYPE;
5775         l_return_status VARCHAR2(1);
5776         l_msg_count     NUMBER;
5777         l_msg_data      VARCHAR2(2000);
5778         l_location_id   NUMBER;
5779     BEGIN
5780         l_location_rec.address1                     := p_address_rec.address1;
5781         l_location_rec.address2                     := p_address_rec.address2;
5782         l_location_rec.address3                     := p_address_rec.address3;
5783         l_location_rec.address4                     := p_address_rec.address4;
5784         l_location_rec.city                         := p_address_rec.city;
5785         l_location_rec.state                        := p_address_rec.state;
5786         l_location_rec.county                       := p_address_rec.county;
5787         l_location_rec.country                      := p_address_rec.country;
5788         l_location_rec.postal_code                  := p_address_rec.postal_code;
5789         l_location_rec.province                     := p_address_rec.province;
5790         l_location_rec.county                       := p_address_rec.county;
5791         l_location_rec.LANGUAGE                     := p_address_rec.LANGUAGE;
5792         l_location_rec.position                     := p_address_rec.position;
5793         l_location_rec.address_key                  := p_address_rec.address_key;
5794         l_location_rec.postal_plus4_code            := p_address_rec.postal_plus4_code;
5795         l_location_rec.position                     := p_address_rec.position;
5796         l_location_rec.delivery_point_code          := p_address_rec.delivery_point_code;
5797         l_location_rec.location_directions          := p_address_rec.location_directions;
5798         -- l_location_rec.address_error_code           := p_address_rec.address_error_code;
5799         l_location_rec.clli_code                    := p_address_rec.clli_code;
5800         l_location_rec.short_description            := p_address_rec.short_description;
5801         l_location_rec.description                  := p_address_rec.description;
5802         l_location_rec.sales_tax_geocode            := p_address_rec.sales_tax_geocode;
5803         l_location_rec.sales_tax_inside_city_limits := p_address_rec.sales_tax_inside_city_limits;
5804         -- swai: new TCA v2 fields
5805         l_location_rec.timezone_id                  := p_address_rec.timezone_id;
5806         l_location_rec.created_by_module            := p_address_rec.created_by_module;
5807         l_location_rec.application_id               := p_address_rec.application_id;
5808         l_location_rec.actual_content_source        := p_address_rec.actual_content_source;
5809         -- swai: unused fields in TCA, but still avail in v2 (per bug #2863096)
5810         l_location_rec.po_box_number                := p_address_rec.po_box_number;
5811         l_location_rec.street                       := p_address_rec.street;
5812         l_location_rec.house_number                 := p_address_rec.house_number;
5813         l_location_rec.street_suffix                := p_address_rec.street_suffix;
5814         l_location_rec.street_number                := p_address_rec.street_number;
5815         l_location_rec.floor                        := p_address_rec.floor;
5816         l_location_rec.suite                        := p_address_rec.suite;
5817         -- swai: obsoleted v1 fields
5818         -- l_location_rec.apartment_number             := p_address_rec.apartment_number;
5819         -- l_location_rec.building                     := p_address_rec.building;
5820         -- l_location_rec.apartment_flag               := p_address_rec.apartment_flag;
5821         -- l_location_rec.secondary_suffix_element     := p_address_rec.secondary_suffix_element;
5822         -- l_location_rec.rural_route_type             := p_address_rec.rural_route_type;
5823         -- l_location_rec.rural_route_number           := p_address_rec.rural_route_number;
5824         -- l_location_rec.room                         := p_address_rec.room;
5825         -- l_location_rec.time_zone                    := p_address_rec.time_zone;
5826         -- l_location_rec.post_office                  := p_address_rec.post_office;
5827         -- l_location_rec.dodaac                       := p_address_rec.dodaac;
5828         -- l_location_rec.trailing_directory_code      := p_address_rec.trailing_directory_code;
5829         -- l_location_rec.life_cycle_status            := p_address_rec.life_cycle_status;
5830         -- l_location_rec.wh_update_date               := p_address_rec.wh_update_date;
5831 
5832 
5833         /*-----------------------------------------------------------------------------------------------------------*/
5834         /*   Calling HZ Public API to create location                                                                */
5835         /*   Description : Creates location.                                                                         */
5836         /*   Input Parm    :                                                                                         */
5837         /*                 p_api_version                                                                             */
5838         /*                 p_init_msg_list                                                                           */
5839         /*                 p_commit                                                                                  */
5840         /*                 p_location_rec                                                                            */
5841         /*                 p_validation_level                                                                        */
5842         /*   Output Parm   :                                                                                         */
5843         /*                 x_return_status                                                                           */
5844         /*                 x_msg_count                                                                               */
5845         /*                 x_msg_data                                                                                */
5846         /*                 x_location_id                                                                             */
5847         /*-----------------------------------------------------------------------------------------------------------*/
5848         HZ_LOCATION_V2PUB.create_location(p_init_msg_list    => Fnd_Api.G_FALSE,
5849                                         p_location_rec     => l_location_rec,
5850                                         x_location_id      => l_location_id,
5851                                         x_return_status    => l_return_status,
5852                                         x_msg_count        => l_msg_count,
5853                                         x_msg_data         => l_msg_data
5854                                         );
5855         x_return_status := l_return_status;
5856         x_msg_count     := l_msg_count;
5857         x_msg_data      := l_msg_data;
5858         IF x_return_status = Csc_Core_Utils_Pvt.G_RET_STS_SUCCESS
5859         THEN
5860             x_location_id := l_location_id;
5861         END IF;
5862     END Create_Address;
5863 
5864     /*-----------------------------------------------------------------------------------------------------------*/
5865     /* procedure name: Create_repair_task_hist                                                                   */
5866     /* description   : procedure used to create Repair Order history for task creation                           */
5867     /* Called from   : Depot Repair Form to Create Address                                                       */
5868     /* Input Parm    : p_api_version         NUMBER      Required Api Version number                             */
5869     /*                 p_init_msg_list       VARCHAR2    Optional Initializes message stack if fnd_api.g_true,   */
5870     /*                                                            default value is fnd_api.g_false               */
5871     /*                 p_commit              VARCHAR2    Optional Commits in API if fnd_api.g_true, default      */
5872     /*                                                            fnd_api.g_false                                */
5873     /*                 p_validation_level    NUMBER      Optional API uses this parameter to determine which     */
5874     /*                                                            validation steps must be done and which steps  */
5875     /*                                                            should be skipped.                             */
5876     /*                 p_task_id             NUMBER      Required Task Id                                        */
5877     /*                 p_repair_line_id      NUMBER      Required Repair_line_id                                 */
5878     /* Output Parm   : x_return_status       VARCHAR2             Return status after the call. The status can be*/
5879     /*                                                            fnd_api.g_ret_sts_success (success)            */
5880     /*                                                            fnd_api.g_ret_sts_error (error)                */
5881     /*                                                            fnd_api.g_ret_sts_unexp_error (unexpected)     */
5882     /*                 x_msg_count           NUMBER               Number of messages in the message stack        */
5883     /*                 x_msg_data            VARCHAR2             Message text if x_msg_count >= 1               */
5884     /*-----------------------------------------------------------------------------------------------------------*/
5885 
5886     PROCEDURE Create_repair_task_hist(p_api_version      IN NUMBER,
5887                                       p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
5888                                       p_commit           IN VARCHAR2 := Fnd_Api.g_false,
5889                                       p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
5890                                       p_task_id          IN NUMBER,
5891                                       p_repair_line_id   IN NUMBER,
5892                                       x_return_status    OUT NOCOPY VARCHAR2,
5893                                       x_msg_count        OUT NOCOPY NUMBER,
5894                                       x_msg_data         OUT NOCOPY VARCHAR2) IS
5895         l_api_name    CONSTANT VARCHAR2(30) := 'VALIDATE_AND_WRITE';
5896         l_api_version CONSTANT NUMBER := 1.0;
5897         l_msg_count         NUMBER;
5898         l_msg_data          VARCHAR2(2000);
5899         l_msg_index         NUMBER;
5900         l_return_status     VARCHAR2(1);
5901         l_repair_history_id NUMBER;
5902         l_paramn1           NUMBER;
5903         l_paramn2           NUMBER;
5904         l_paramn3           NUMBER;
5905         l_paramn4           NUMBER;
5906         l_paramn5           NUMBER;
5907         l_paramc1           VARCHAR2(240);
5908         l_paramc2           VARCHAR2(240);
5909         l_paramc3           VARCHAR2(240);
5910         l_paramc4           VARCHAR2(240);
5911         l_paramc5           VARCHAR2(240);
5912         l_paramc6           VARCHAR2(240);
5913         l_paramd1           DATE;
5914         l_paramd2           DATE;
5915         l_paramd3           DATE;
5916         l_paramd4           DATE;
5917         l_event_code        VARCHAR2(30) := 'TC'; -- Task Created
5918         l_check_task        NUMBER;
5919         CURSOR c_task(p_task_id NUMBER, p_repair_line_id NUMBER) IS
5920             SELECT tsk.task_id, -- hist.paramn1
5921                    tsk.last_updated_by, -- hist.paramn2
5922                    tsk.owner_id, -- hist.paramn3
5923                    tsk.assigned_by_id, -- hist.paramn4
5924                    tsk.task_status_id, -- hist.paramn5
5925                    tsk.task_number, -- hist.paramc1
5926                    tsk.owner_type, -- hist.paramc2
5927                    tsk.owner, -- hist.paramc3
5928                    NULL assignee_type, -- hist.paramc4
5929                    NULL assignee_name, -- hist.paramc5
5930                    tsk.task_status, -- hist.paramc6
5931                    tsk.planned_start_date, -- hist.paramd1
5932                    tsk.actual_start_date, -- hist.paramd2
5933                    tsk.actual_end_date, -- hist.paramd3
5934                    tsk.last_update_date -- hist.paramd4
5935               FROM CSD_REPAIR_TASKS_V tsk
5936              WHERE tsk.source_object_type_code = 'DR'
5937                AND tsk.source_object_id = p_repair_line_id
5938                AND tsk.task_id = p_task_id;
5939     BEGIN
5940 
5941         -- check if this task is saved in the repair history
5942         SELECT COUNT(*)
5943           INTO l_check_task
5944           FROM CSD_REPAIR_TASKS_V tsk, CSD_REPAIR_HISTORY hist
5945          WHERE tsk.source_object_id = hist.repair_line_id
5946            AND hist.paramn1 = p_task_id
5947            AND tsk.source_object_type_code = 'DR'
5948            AND hist.event_code = 'TC';
5949 
5950         IF (l_check_task > 0)
5951         THEN
5952             IF (g_debug > 0)
5953             THEN
5954                 Csd_Gen_Utility_Pvt.ADD('Task Exists in Repair History');
5955             END IF;
5956 
5957         ELSE
5958             -- call the pub after assigning the required variable values
5959             OPEN c_task(p_task_id, p_repair_line_id);
5960 
5961             --      dbms_output.put_line('Task Cursor fetches data');
5962             FETCH c_task
5963                 INTO l_paramn1, -- task id
5964             l_paramn2, -- last updated by
5965             l_paramn3, -- owner id
5966             l_paramn4, -- assigned by id
5967             l_paramn5, -- status id
5968             l_paramc1, -- task number
5969             l_paramc2, -- owner type
5970             l_paramc3, -- owner name
5971             l_paramc4, -- null assignee type
5972             l_paramc5, -- null assignee name
5973             l_paramc6, -- status
5974             l_paramd1, -- planned start date
5975             l_paramd2, -- actual start date
5976             l_paramd3, -- actual end date
5977             l_paramd4; -- last updated date
5978             --       dbms_output.put_line('Task Cursor has no data');
5979 
5980             CLOSE c_task;
5981             -- --------------------------------
5982             -- Begin create repair task history
5983             -- --------------------------------
5984             -- History       : assignee_id   --> assigned_by_id
5985             --                 assignee_type --> null
5986             --                 assignee_name --> null
5987 
5988             -- Standard Start of API savepoint
5989             SAVEPOINT Create_repair_task_hist;
5990             -- Standard call to check for call compatibility.
5991             IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
5992                                                p_api_version,
5993                                                l_api_name,
5994                                                G_PKG_NAME)
5995             THEN
5996                 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
5997             END IF;
5998             -- Initialize message list if p_init_msg_list is set to TRUE.
5999             IF Fnd_Api.to_Boolean(p_init_msg_list)
6000             THEN
6001                 Fnd_Msg_Pub.initialize;
6002             END IF;
6003             -- Initialize API return status to success
6004             x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
6005             -- ---------------
6006             -- Api body starts
6007             -- ---------------
6008             IF (g_debug > 0)
6009             THEN
6010                 Csd_Gen_Utility_Pvt.ADD('Before Task to Repair History API call');
6011             END IF;
6012 
6013             -- travi 020502 OBJECT_VERSION_NUMBER validation
6014 
6015             -- ------------------------------------------------------
6016             -- Internal Private API call to write to Repair History
6017             -- ------------------------------------------------------
6018             Csd_To_Form_Repair_History.Validate_And_Write(p_Api_Version_Number     => 1.0,
6019                                                           p_init_msg_list          => 'F',
6020                                                           p_commit                 => 'F',
6021                                                           p_validation_level       => NULL,
6022                                                           p_action_code            => 0,
6023                                                           px_REPAIR_HISTORY_ID     => l_repair_history_id,
6024                                                           p_OBJECT_VERSION_NUMBER  => NULL,
6025                                                           p_REQUEST_ID             => NULL,
6026                                                           p_PROGRAM_ID             => NULL,
6027                                                           p_PROGRAM_APPLICATION_ID => NULL,
6028                                                           p_PROGRAM_UPDATE_DATE    => NULL,
6029                                                           p_CREATED_BY             => Fnd_Global.USER_ID,
6030                                                           p_CREATION_DATE          => SYSDATE,
6031                                                           p_LAST_UPDATED_BY        => Fnd_Global.USER_ID,
6032                                                           p_LAST_UPDATE_DATE       => SYSDATE,
6033                                                           p_repair_line_id         => p_repair_line_id,
6034                                                           p_EVENT_CODE             => l_event_code,
6035                                                           p_EVENT_DATE             => SYSDATE,
6036                                                           p_QUANTITY               => NULL,
6037                                                           p_PARAMN1                => l_paramn1,
6038                                                           p_PARAMN2                => l_paramn2,
6039                                                           p_PARAMN3                => l_paramn3,
6040                                                           p_PARAMN4                => l_paramn4,
6041                                                           p_PARAMN5                => l_paramn5,
6042                                                           p_PARAMN6                => NULL,
6043                                                           p_PARAMN7                => NULL,
6044                                                           p_PARAMN8                => NULL,
6045                                                           p_PARAMN9                => NULL,
6046                                                           p_PARAMN10               => Fnd_Global.USER_ID,
6047                                                           p_PARAMC1                => l_paramc1,
6048                                                           p_PARAMC2                => l_paramc2,
6049                                                           p_PARAMC3                => l_paramc3,
6050                                                           p_PARAMC4                => l_paramc4,
6051                                                           p_PARAMC5                => l_paramc5,
6052                                                           p_PARAMC6                => l_paramc6,
6053                                                           p_PARAMC7                => NULL,
6054                                                           p_PARAMC8                => NULL,
6055                                                           p_PARAMC9                => NULL,
6056                                                           p_PARAMC10               => NULL,
6057                                                           p_PARAMD1                => l_paramd1,
6058                                                           p_PARAMD2                => l_paramd1,
6059                                                           p_PARAMD3                => l_paramd1,
6060                                                           p_PARAMD4                => l_paramd1,
6061                                                           p_PARAMD5                => NULL,
6062                                                           p_PARAMD6                => NULL,
6063                                                           p_PARAMD7                => NULL,
6064                                                           p_PARAMD8                => NULL,
6065                                                           p_PARAMD9                => NULL,
6066                                                           p_PARAMD10               => NULL,
6067                                                           p_ATTRIBUTE_CATEGORY     => NULL,
6068                                                           p_ATTRIBUTE1             => NULL,
6069                                                           p_ATTRIBUTE2             => NULL,
6070                                                           p_ATTRIBUTE3             => NULL,
6071                                                           p_ATTRIBUTE4             => NULL,
6072                                                           p_ATTRIBUTE5             => NULL,
6073                                                           p_ATTRIBUTE6             => NULL,
6074                                                           p_ATTRIBUTE7             => NULL,
6075                                                           p_ATTRIBUTE8             => NULL,
6076                                                           p_ATTRIBUTE9             => NULL,
6077                                                           p_ATTRIBUTE10            => NULL,
6078                                                           p_ATTRIBUTE11            => NULL,
6079                                                           p_ATTRIBUTE12            => NULL,
6080                                                           p_ATTRIBUTE13            => NULL,
6081                                                           p_ATTRIBUTE14            => NULL,
6082                                                           p_ATTRIBUTE15            => NULL,
6083                                                           p_LAST_UPDATE_LOGIN      => Fnd_Global.CONC_LOGIN_ID,
6084                                                           X_Return_Status          => x_return_status,
6085                                                           X_Msg_Count              => x_msg_count,
6086                                                           X_Msg_Data               => x_msg_data);
6087             --
6088             IF (g_debug > 0)
6089             THEN
6090                 Csd_Gen_Utility_Pvt.ADD('After Task to Repair History : ' ||
6091                                         x_return_status);
6092             END IF;
6093 
6094             -- -------------------
6095             -- Api body ends here
6096             -- -------------------
6097             -- Standard check of p_commit.
6098             IF Fnd_Api.To_Boolean(p_commit)
6099             THEN
6100                 COMMIT WORK;
6101             END IF;
6102 
6103             -- Standard call to get message count and IF count is  get message info.
6104             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6105                                       p_data  => x_msg_data);
6106         END IF;
6107     EXCEPTION
6108         WHEN Fnd_Api.G_EXC_ERROR THEN
6109             ROLLBACK TO Create_repair_task_hist;
6110             x_return_status := Fnd_Api.G_RET_STS_ERROR;
6111             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6112                                       p_data  => x_msg_data);
6113         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
6114             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
6115             ROLLBACK TO Create_repair_task_hist;
6116             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6117                                       p_data  => x_msg_data);
6118         WHEN OTHERS THEN
6119             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
6120             ROLLBACK TO Create_repair_task_hist;
6121             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
6122             THEN
6123                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
6124             END IF;
6125             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6126                                       p_data  => x_msg_data);
6127     END Create_repair_task_hist;
6128 
6129     /*-----------------------------------------------------------------------------------------------------------*/
6130     /* procedure name: Update_repair_task_hist                                                                   */
6131     /* description   : procedure used to Update Repair Order history                                             */
6132     /*                 for task creation                                                                         */
6133     /* Called from   : Depot Repair Form to update to Repair history                                             */
6134     /* Input Parm    : p_api_version         NUMBER      Required Api Version number                             */
6135     /*                 p_init_msg_list       VARCHAR2    Optional Initializes message stack if fnd_api.g_true,   */
6136     /*                                                            default value is fnd_api.g_false               */
6137     /*                 p_commit              VARCHAR2    Optional Commits in API if fnd_api.g_true, default      */
6138     /*                                                            fnd_api.g_false                                */
6139     /*                 p_validation_level    NUMBER      Optional API uses this parameter to determine which     */
6140     /*                                                            validation steps must be done and which steps  */
6141     /*                                                            should be skipped.                             */
6142     /*                 p_task_id             NUMBER      Required Task Id                                        */
6143     /*                 p_repair_line_id      NUMBER      Required Repair_line_id                                 */
6144     /* Output Parm   : x_return_status       VARCHAR2             Return status after the call. The status can be*/
6145     /*                                                            fnd_api.g_ret_sts_success (success)            */
6146     /*                                                            fnd_api.g_ret_sts_error (error)                */
6147     /*                                                            fnd_api.g_ret_sts_unexp_error (unexpected)     */
6148     /*                 x_msg_count           NUMBER               Number of messages in the message stack        */
6149     /*                 x_msg_data            VARCHAR2             Message text if x_msg_count >= 1               */
6150     /*-----------------------------------------------------------------------------------------------------------*/
6151     /*
6152     PROCEDURE Update_repair_task_hist
6153     ( p_api_version           IN     NUMBER,
6154       p_init_msg_list         IN     VARCHAR2             := fnd_api.g_true,
6155       p_commit                IN     VARCHAR2             := fnd_api.g_false,
6156       p_validation_level      IN     NUMBER               := fnd_api.g_valid_level_full,
6157       p_task_id               IN     NUMBER,
6158       p_repair_line_id        IN     NUMBER,
6159       x_return_status         OUT NOCOPY    VARCHAR2,
6160       x_msg_count             OUT NOCOPY    NUMBER,
6161       x_msg_data              OUT NOCOPY    VARCHAR2
6162     )
6163         IS
6164         l_api_name               CONSTANT VARCHAR2(30)   := 'VALIDATE_AND_WRITE';
6165         l_api_version            CONSTANT NUMBER         := 1.0;
6166         l_msg_count              NUMBER;
6167         l_msg_data               VARCHAR2(2000);
6168         l_msg_index              NUMBER;
6169         l_return_status          VARCHAR2(1);
6170         l_repair_history_id      NUMBER;
6171         l_paramn1                NUMBER;
6172         l_paramn2                NUMBER;
6173         l_paramn3                NUMBER;
6174         l_paramn4                NUMBER;
6175         l_paramn5                NUMBER;
6176         l_paramc1                VARCHAR2(240);
6177         l_paramc2                VARCHAR2(240);
6178         l_paramc3                VARCHAR2(240);
6179         l_paramc4                VARCHAR2(240);
6180         l_paramc5                VARCHAR2(240);
6181         l_paramc6                VARCHAR2(240);
6182         l_paramd1                DATE;
6183         l_paramd2                DATE;
6184         l_paramd3                DATE;
6185         l_paramd4                DATE;
6186         l_event_code             VARCHAR2(30)   := '';
6187         l_hist_ec                VARCHAR2(30);
6188         l_owner_type             VARCHAR2(240);
6189         l_owner                  VARCHAR2(240);
6190         l_assignee_type          VARCHAR2(240);
6191         l_assignee_name          VARCHAR2(240);
6192         l_task_status            VARCHAR2(240);
6193         l_check_id               NUMBER;
6194         l_check_code             VARCHAR2(30);
6195 
6196         CURSOR c_task_hist(p_task_id NUMBER, p_repair_line_id NUMBER) IS
6197           SELECT hist.event_code,
6198                  hist.paramc2,      -- tsk.owner_type
6199                  hist.paramc3,      -- tsk.owner
6200                  null paramc4,      -- tsk.assignee_type
6201                  null paramc5,      -- tsk.assignee_name
6202                  hist.paramc6       -- tsk.task_status
6203             FROM CSD_REPAIR_HISTORY hist
6204            WHERE hist.paramn1                = p_task_id
6205              AND hist.repair_line_id         = p_repair_line_id
6206          --and hist.event_code             = 'TC'
6207         ORDER BY hist.repair_history_id DESC;
6208 
6209         CURSOR c_task(p_task_id NUMBER, p_repair_line_id NUMBER) IS
6210           SELECT tsk.task_id,            -- hist.paramn1
6211                  tsk.last_updated_by,    -- hist.paramn2
6212                  tsk.owner_id,           -- hist.paramn3
6213                  tsk.assigned_by_id,        -- hist.paramn4
6214                  tsk.task_status_id,     -- hist.paramn5
6215                  tsk.task_number,        -- hist.paramc1
6216                  tsk.owner_type,         -- hist.paramc2
6217                  tsk.owner,              -- hist.paramc3
6218                  null assignee_type,      -- hist.paramc4
6219                  null assignee_name,      -- hist.paramc5
6220                  tsk.task_status,        -- hist.paramc6
6221                  tsk.planned_start_date, -- hist.paramd1
6222                  tsk.actual_start_date,  -- hist.paramd2
6223                  tsk.actual_end_date,    -- hist.paramd3
6224                  tsk.last_update_date    -- hist.paramd4
6225           FROM  CSD_REPAIR_TASKS_V tsk
6226          WHERE  tsk.source_object_type_code = 'DR'
6227            AND  tsk.source_object_id        = p_repair_line_id
6228            AND  tsk.task_id                 = p_task_id;
6229 
6230       BEGIN
6231           -- History       : assignee_id   --> assigned_by_id
6232           --                 assignee_type --> null
6233           --                 assignee_name --> null
6234           -- check if this task creation / update is saved in the repair history
6235           SELECT COUNT(*)
6236             INTO l_check_id
6237             FROM CSD_REPAIR_TASKS_V tsk,
6238              CSD_REPAIR_HISTORY hist
6239            WHERE tsk.source_object_id        = p_repair_line_id
6240          AND hist.paramn1                = p_task_id
6241              AND tsk.task_id                 = hist.paramn1
6242              AND tsk.source_object_id        = hist.repair_line_id
6243          AND tsk.source_object_type_code = 'DR';
6244 
6245            OPEN c_task(p_task_id, p_repair_line_id);
6246 
6247            FETCH c_task
6248            INTO  l_paramn1, -- task id
6249                  l_paramn2, -- last updated by
6250                  l_paramn3, -- owner id
6251                  l_paramn4, -- assigned by id
6252                  l_paramn5, -- status id
6253                  l_paramc1, -- task number
6254                  l_paramc2, -- owner type
6255                  l_paramc3, -- owner name
6256                  l_paramc4, -- null assignee type
6257                  l_paramc5, -- null assignee name
6258                  l_paramc6, -- status
6259                  l_paramd1, -- planned start date
6260                  l_paramd2, -- actual start date
6261                  l_paramd3, -- actual end date
6262                  l_paramd4; -- last updated date
6263            CLOSE c_task;
6264              -- TC Exists in Repair History
6265              -- add the update TOC/TSC line to Repair history
6266              -- ----------------------------------------------
6267              IF (l_check_id >= 1) THEN
6268                IF (g_debug > 0 ) THEN
6269                  csd_gen_utility_pvt.ADD('TC and/or TOC/TSC Exists in Repair History');
6270                END IF;
6271 
6272                -- pick latest row from Repair history
6273                OPEN c_task_hist(p_task_id, p_repair_line_id);
6274 
6275                FETCH c_task_hist
6276                 INTO l_hist_ec,
6277                      l_owner_type,
6278                      l_owner,
6279                      l_assignee_type,
6280                      l_assignee_name,
6281                      l_task_status;
6282 
6283               CLOSE c_task_hist;
6284                -- check the row in history against the row in tasks
6285                -- for updates to Owner or Status
6286                -- check if Status has changed
6287                IF (l_task_status <> l_paramc6) THEN
6288                   -- insert Status change into Repair history
6289                   l_event_code := 'TSC';
6290                -- check if Owner has changed
6291                ELSIF (l_owner <> l_paramc3) THEN
6292                    -- insert Owner change into Repair history
6293                    l_event_code := 'TOC';
6294                ELSE
6295                    -- NO insert for this change into Repair history
6296                    l_event_code := '';
6297                END IF;
6298              END IF; -- check for l_check_id
6299              -- ----------------------------------------------
6300        -- ---------------------------------------------------------
6301        -- Repair history row inserted for TOC or TSC only
6302        -- ---------------------------------------------------------
6303        IF (l_event_code IN ('TOC', 'TSC')) THEN
6304           -- --------------------------------
6305           -- Begin create repair task history
6306           -- --------------------------------
6307           -- Standard Start of API savepoint
6308              SAVEPOINT  Update_repair_task_hist;
6309           -- Standard call to check for call compatibility.
6310              IF NOT FND_API.Compatible_API_Call (l_api_version,
6311                                                  p_api_version,
6312                                                  l_api_name   ,
6313                                                  G_PKG_NAME    )
6314              THEN
6315                    RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6316              END IF;
6317           -- Initialize message list if p_init_msg_list is set to TRUE.
6318              IF FND_API.to_Boolean( p_init_msg_list ) THEN
6319                    FND_MSG_PUB.initialize;
6320              END IF;
6321           -- Initialize API return status to success
6322              x_return_status := FND_API.G_RET_STS_SUCCESS;
6323           -- ---------------
6324           -- Api body starts
6325           -- ---------------
6326           IF (g_debug > 0 ) THEN
6327             csd_gen_utility_pvt.ADD('Before Task to Update Repair History');
6328           END IF;
6329 
6330 
6331           -- travi 020502 OBJECT_VERSION_NUMBER validation
6332 
6333            -- ------------------------------------------------------
6334            -- Internal Private API call to write to Repair History
6335            -- ------------------------------------------------------
6336           CSD_TO_FORM_REPAIR_HISTORY.Validate_And_Write
6337           (p_Api_Version_Number       => 1.0 ,
6338            p_init_msg_list            => 'F',
6339            p_commit                   => 'F',
6340            p_validation_level         => NULL,
6341            p_action_code              => 0,
6342            px_REPAIR_HISTORY_ID       => l_repair_history_id,
6343            p_OBJECT_VERSION_NUMBER    => NULL,
6344            p_REQUEST_ID               => NULL,
6345            p_PROGRAM_ID               => NULL,
6346            p_PROGRAM_APPLICATION_ID   => NULL,
6347            p_PROGRAM_UPDATE_DATE      => NULL,
6348            p_CREATED_BY               => FND_GLOBAL.USER_ID,
6349            p_CREATION_DATE            => SYSDATE,
6350            p_LAST_UPDATED_BY          => FND_GLOBAL.USER_ID,
6351            p_LAST_UPDATE_DATE         => SYSDATE,
6352            p_repair_line_id           => p_repair_line_id,
6353            p_EVENT_CODE               => l_event_code,
6354            p_EVENT_DATE               => SYSDATE,
6355            p_QUANTITY                 => NULL,
6356            p_PARAMN1                  => l_paramn1,
6357            p_PARAMN2                  => l_paramn2,
6358            p_PARAMN3                  => l_paramn3,
6359            p_PARAMN4                  => l_paramn4,
6360            p_PARAMN5                  => l_paramn5,
6361            p_PARAMN6                  => NULL,
6362            p_PARAMN7                  => NULL,
6363            p_PARAMN8                  => NULL,
6364            p_PARAMN9                  => NULL,
6365            p_PARAMN10                 => FND_GLOBAL.USER_ID,
6366            p_PARAMC1                  => l_paramc1,
6367            p_PARAMC2                  => l_paramc2,
6368            p_PARAMC3                  => l_paramc3,
6369            p_PARAMC4                  => l_paramc4,
6370            p_PARAMC5                  => l_paramc5,
6371            p_PARAMC6                  => l_paramc6,
6372            p_PARAMC7                  => NULL,
6373            p_PARAMC8                  => NULL,
6374            p_PARAMC9                  => NULL,
6375            p_PARAMC10                 => NULL,
6376            p_PARAMD1                  => l_paramd1,
6377            p_PARAMD2                  => l_paramd1,
6378            p_PARAMD3                  => l_paramd1,
6379            p_PARAMD4                  => l_paramd1,
6380            p_PARAMD5                  => NULL,
6381            p_PARAMD6                  => NULL,
6382            p_PARAMD7                  => NULL,
6383            p_PARAMD8                  => NULL,
6384            p_PARAMD9                  => NULL,
6385            p_PARAMD10                 => NULL,
6386            p_ATTRIBUTE_CATEGORY       => NULL,
6387            p_ATTRIBUTE1               => NULL,
6388            p_ATTRIBUTE2               => NULL,
6389            p_ATTRIBUTE3               => NULL,
6390            p_ATTRIBUTE4               => NULL,
6391            p_ATTRIBUTE5               => NULL,
6392            p_ATTRIBUTE6               => NULL,
6393            p_ATTRIBUTE7               => NULL,
6394            p_ATTRIBUTE8               => NULL,
6395            p_ATTRIBUTE9               => NULL,
6396            p_ATTRIBUTE10              => NULL,
6397            p_ATTRIBUTE11              => NULL,
6398            p_ATTRIBUTE12              => NULL,
6399            p_ATTRIBUTE13              => NULL,
6400            p_ATTRIBUTE14              => NULL,
6401            p_ATTRIBUTE15              => NULL,
6402            p_LAST_UPDATE_LOGIN        => FND_GLOBAL.CONC_LOGIN_ID,
6403            X_Return_Status            => x_return_status,
6404            X_Msg_Count                => x_msg_count,
6405            X_Msg_Data                 => x_msg_data
6406           );
6407         --
6408           IF (g_debug > 0 ) THEN
6409             csd_gen_utility_pvt.ADD('After Task to Update Repair History : '||x_return_status);
6410           END IF;
6411 
6412           -- -------------------
6413           -- Api body ends here
6414           -- -------------------
6415           -- Standard check of p_commit.
6416             IF FND_API.To_Boolean( p_commit ) THEN
6417                  COMMIT WORK;
6418             END IF;
6419           -- Standard call to get message count and IF count is  get message info.
6420             FND_MSG_PUB.Count_And_Get
6421                  (p_count  =>  x_msg_count,
6422                   p_data   =>  x_msg_data );
6423        END IF;
6424        -- ---------------------------------------------------------
6425        EXCEPTION
6426           WHEN FND_API.G_EXC_ERROR THEN
6427               ROLLBACK TO Update_repair_task_hist;
6428                 x_return_status := FND_API.G_RET_STS_ERROR ;
6429                 FND_MSG_PUB.Count_And_Get
6430                     (p_count  =>  x_msg_count,
6431                      p_data   =>  x_msg_data
6432                     );
6433           WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6434               x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6435               ROLLBACK TO Update_repair_task_hist;
6436               FND_MSG_PUB.Count_And_Get
6437                     ( p_count  =>  x_msg_count,
6438                       p_data   =>  x_msg_data
6439                     );
6440           WHEN OTHERS THEN
6441               x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6442               ROLLBACK TO Update_repair_task_hist;
6443                   IF  FND_MSG_PUB.Check_Msg_Level
6444                       (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6445                   THEN
6446                       FND_MSG_PUB.Add_Exc_Msg
6447                       (G_PKG_NAME ,
6448                        l_api_name  );
6449                   END IF;
6450                       FND_MSG_PUB.Count_And_Get
6451                       (p_count  =>  x_msg_count,
6452                        p_data   =>  x_msg_data );
6453       END Update_repair_task_hist;
6454     */
6455     -------------------- travi changes-------------
6456 
6457     PROCEDURE Create_repair_task_hist(p_api_version       IN NUMBER,
6458                                       p_init_msg_list     IN VARCHAR2 := Fnd_Api.g_true,
6459                                       p_commit            IN VARCHAR2 := Fnd_Api.g_false,
6460                                       p_validation_level  IN NUMBER := Fnd_Api.g_valid_level_full,
6461                                       p_task_activity_rec IN Csd_Process_Pvt.TASK_ACTIVITY_REC,
6462                                       x_return_status     OUT NOCOPY VARCHAR2,
6463                                       x_msg_count         OUT NOCOPY NUMBER,
6464                                       x_msg_data          OUT NOCOPY VARCHAR2)
6465 
6466      IS
6467         l_api_name    CONSTANT VARCHAR2(30) := 'VALIDATE_AND_WRITE';
6468         l_api_version CONSTANT NUMBER := 1.0;
6469         l_msg_count          NUMBER;
6470         l_msg_data           VARCHAR2(2000);
6471         l_msg_index          NUMBER;
6472         l_return_status      VARCHAR2(1);
6473         l_repair_history_id  NUMBER;
6474         l_owner_type         VARCHAR2(240);
6475         l_owner              VARCHAR2(240);
6476         l_assignee_type      VARCHAR2(240);
6477         l_assignee_name      VARCHAR2(240);
6478         l_task_status        VARCHAR2(240);
6479         l_last_updated_by    NUMBER;
6480         l_assigned_by_id     NUMBER;
6481         l_task_number        VARCHAR2(240);
6482         l_task_name          VARCHAR2(240);
6483         l_planned_start_Date DATE;
6484         l_actual_start_Date  DATE;
6485         l_actual_end_Date    DATE;
6486         l_last_update_date   DATE;
6487         l_event_code         VARCHAR2(30) := 'TC'; -- Task Created
6488         l_check_task         NUMBER;
6489 
6490         /*CURSOR c_task(p_task_id NUMBER, p_repair_line_id NUMBER) IS
6491          SELECT tsk.task_id,            -- hist.paramn1
6492                 tsk.last_updated_by,    -- hist.paramn2
6493                 tsk.owner_id,           -- hist.paramn3
6494                 tsk.assigned_by_id,     -- hist.paramn4
6495                 tsk.task_status_id,     -- hist.paramn5
6496                 tsk.task_number,        -- hist.paramc1
6497                 tsk.owner_type,         -- hist.paramc2
6498                 tsk.owner,              -- hist.paramc3
6499                 --null assignee_type,   -- hist.paramc4
6500                 --null assignee_name,   -- hist.paramc5
6501                 tsk.task_status,        -- hist.paramc6
6502                 tsk.task_name,          -- hist.paramc7
6503                 tsk.planned_start_date, -- hist.paramd1
6504                 tsk.actual_start_date,  -- hist.paramd2
6505                 tsk.actual_end_date,    -- hist.paramd3
6506                 tsk.last_update_date    -- hist.paramd4
6507 
6508          FROM  CSD_REPAIR_TASKS_V tsk
6509         WHERE  tsk.source_object_type_code = 'DR'
6510           AND  tsk.source_object_id        = p_repair_line_id
6511           AND  tsk.task_id                 = p_task_id;*/
6512 
6513         CURSOR c_task(p_task_id NUMBER, p_repair_line_id NUMBER) IS
6514             SELECT
6515 
6516              tsk.last_updated_by, -- hist.paramn2
6517 
6518              tsk.assigned_by_id, -- hist.paramn4
6519 
6520              tsk.task_number, -- hist.paramc1
6521              tsk.task_name,
6522 
6523              tsk.planned_start_date, -- hist.paramd1
6524              tsk.actual_start_date, -- hist.paramd2
6525              tsk.actual_end_date, -- hist.paramd3
6526              tsk.last_update_date -- hist.paramd4
6527               FROM CSD_REPAIR_TASKS_V tsk
6528              WHERE tsk.source_object_type_code = 'DR'
6529                AND tsk.source_object_id = p_repair_line_id
6530                AND tsk.task_id = p_task_id;
6531 
6532     BEGIN
6533 
6534         -- check if this task is saved in the repair history
6535         SELECT COUNT(*)
6536           INTO l_check_task
6537           FROM CSD_REPAIR_TASKS_V tsk, CSD_REPAIR_HISTORY hist
6538          WHERE tsk.source_object_id = hist.repair_line_id
6539            AND hist.paramn1 = p_task_activity_rec.task_id
6540            AND tsk.source_object_type_code = 'DR'
6541            AND hist.event_code = 'TC';
6542 
6543         IF (l_check_task > 0)
6544         THEN
6545             IF (g_debug > 0)
6546             THEN
6547                 Csd_Gen_Utility_Pvt.ADD('Task Exists in Repair History');
6548             END IF;
6549 
6550         ELSE
6551             -- call the pub after assigning the required variable values
6552             OPEN c_task(p_task_activity_rec.task_id,
6553                         p_task_activity_rec.repair_line_id);
6554 
6555             --      dbms_output.put_line('Task Cursor fetches data');
6556             FETCH c_task
6557                 INTO
6558 
6559             l_last_updated_by, -- last updated by
6560             l_assigned_by_id, -- assigned by id
6561             l_task_number, -- task number
6562             l_task_name, -- task name
6563             l_planned_start_Date, -- planned start date
6564             l_actual_start_Date, -- actual start date
6565             l_actual_end_Date, -- actual end date
6566             l_last_update_date; -- last updated date
6567 
6568             /*  l_paramn1, -- task id
6569              l_paramn2, -- last updated by
6570              l_paramn3, -- owner id
6571              l_paramn4, -- assigned by id
6572              l_paramn5, -- status id
6573              l_paramc1, -- task number
6574              l_paramc2, -- owner type sangiguptask
6575              l_paramc3, -- owner name
6576              --l_paramc4, -- null assignee type
6577             -- l_paramc5, -- null assignee name
6578              l_paramc6, -- status
6579              l_paramc7, -- task name
6580              l_paramd1, -- planned start date
6581              l_paramd2, -- actual start date
6582              l_paramd3, -- actual end date
6583              l_paramd4-- last updated date;*/
6584 
6585             --       dbms_output.put_line('Task Cursor has no data');
6586 
6587             CLOSE c_task;
6588 
6589             -- --------------------------------
6590             -- Begin create repair task history
6591             -- --------------------------------
6592 
6593             -- Standard Start of API savepoint
6594             SAVEPOINT Create_repair_task_hist;
6595             -- Standard call to check for call compatibility.
6596             IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
6597                                                p_api_version,
6598                                                l_api_name,
6599                                                G_PKG_NAME)
6600             THEN
6601                 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
6602             END IF;
6603             -- Initialize message list if p_init_msg_list is set to TRUE.
6604             IF Fnd_Api.to_Boolean(p_init_msg_list)
6605             THEN
6606                 Fnd_Msg_Pub.initialize;
6607             END IF;
6608             -- Initialize API return status to success
6609             x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
6610             -- ---------------
6611             -- Api body starts
6612             -- ---------------
6613             IF (g_debug > 0)
6614             THEN
6615                 Csd_Gen_Utility_Pvt.ADD('Before Task to Repair History API call');
6616             END IF;
6617 
6618             -- travi 020502 OBJECT_VERSION_NUMBER validation
6619 
6620             -- ------------------------------------------------------
6621             -- Internal Private API call to write to Repair History
6622             -- ------------------------------------------------------
6623             Csd_To_Form_Repair_History.Validate_And_Write(p_Api_Version_Number     => 1.0,
6624                                                           p_init_msg_list          => 'F',
6625                                                           p_commit                 => 'F',
6626                                                           p_validation_level       => NULL,
6627                                                           p_action_code            => 0,
6628                                                           px_REPAIR_HISTORY_ID     => l_repair_history_id,
6629                                                           p_OBJECT_VERSION_NUMBER  => NULL,
6630                                                           p_REQUEST_ID             => NULL,
6631                                                           p_PROGRAM_ID             => NULL,
6632                                                           p_PROGRAM_APPLICATION_ID => NULL,
6633                                                           p_PROGRAM_UPDATE_DATE    => NULL,
6634                                                           p_CREATED_BY             => Fnd_Global.USER_ID,
6635                                                           p_CREATION_DATE          => SYSDATE,
6636                                                           p_LAST_UPDATED_BY        => Fnd_Global.USER_ID,
6637                                                           p_LAST_UPDATE_DATE       => SYSDATE,
6638                                                           p_repair_line_id         => p_task_activity_rec.repair_line_id,
6639                                                           p_EVENT_CODE             => l_event_code,
6640                                                           p_EVENT_DATE             => SYSDATE,
6641                                                           p_QUANTITY               => NULL,
6642                                                           p_PARAMN1                => p_task_activity_rec.task_id, --task id,
6643                                                           p_PARAMN2                => l_last_updated_by, --l_paramn2,
6644                                                           p_PARAMN3                => p_task_activity_rec.new_owner_id, --l_paramn3,
6645                                                           p_PARAMN4                => l_assigned_by_id, --l_paramn4,
6646                                                           p_PARAMN5                => p_task_activity_rec.new_status_id, --l_paramn5,
6647                                                           p_PARAMN6                => p_task_activity_rec.new_resource_id, --l_paramn6,--assignee_id
6648                                                           p_PARAMN7                => NULL,
6649                                                           p_PARAMN8                => NULL,
6650                                                           p_PARAMN9                => NULL,
6651                                                           p_PARAMN10               => Fnd_Global.USER_ID,
6652                                                           p_PARAMC1                => l_task_number,
6653                                                           p_PARAMC2                => p_task_activity_rec.new_owner_type_code,
6654                                                           p_PARAMC3                => p_task_activity_rec.new_owner_name,
6655                                                           p_PARAMC4                => p_task_activity_rec.new_resource_type_code, --resource_type_code sangiguptask
6656                                                           p_PARAMC5                => p_task_activity_rec.new_resource_name, --assignee_name sangiguptask
6657                                                           p_PARAMC6                => p_task_activity_rec.new_status, --task status
6658                                                           p_PARAMC7                => l_task_name, --task name sangiguptask
6659                                                           p_PARAMC8                => NULL,
6660                                                           p_PARAMC9                => NULL,
6661                                                           p_PARAMC10               => NULL, -- split from rep line number sangiguptask
6662                                                           p_PARAMD1                => l_planned_start_Date, -- planned start date
6663                                                           p_PARAMD2                => l_actual_start_Date,
6664                                                           p_PARAMD3                => l_actual_end_Date,
6665                                                           p_PARAMD4                => l_last_update_date,
6666                                                           p_PARAMD5                => NULL,
6667                                                           p_PARAMD6                => NULL,
6668                                                           p_PARAMD7                => NULL,
6669                                                           p_PARAMD8                => NULL,
6670                                                           p_PARAMD9                => NULL,
6671                                                           p_PARAMD10               => NULL,
6672                                                           p_ATTRIBUTE_CATEGORY     => NULL,
6673                                                           p_ATTRIBUTE1             => NULL,
6674                                                           p_ATTRIBUTE2             => NULL,
6675                                                           p_ATTRIBUTE3             => NULL,
6676                                                           p_ATTRIBUTE4             => NULL,
6677                                                           p_ATTRIBUTE5             => NULL,
6678                                                           p_ATTRIBUTE6             => NULL,
6679                                                           p_ATTRIBUTE7             => NULL,
6680                                                           p_ATTRIBUTE8             => NULL,
6681                                                           p_ATTRIBUTE9             => NULL,
6682                                                           p_ATTRIBUTE10            => NULL,
6683                                                           p_ATTRIBUTE11            => NULL,
6684                                                           p_ATTRIBUTE12            => NULL,
6685                                                           p_ATTRIBUTE13            => NULL,
6686                                                           p_ATTRIBUTE14            => NULL,
6687                                                           p_ATTRIBUTE15            => NULL,
6688                                                           p_LAST_UPDATE_LOGIN      => Fnd_Global.CONC_LOGIN_ID,
6689                                                           X_Return_Status          => x_return_status,
6690                                                           X_Msg_Count              => x_msg_count,
6691                                                           X_Msg_Data               => x_msg_data);
6692             --
6693             IF (g_debug > 0)
6694             THEN
6695                 Csd_Gen_Utility_Pvt.ADD('After Task to Repair History : ' ||
6696                                         x_return_status);
6697             END IF;
6698 
6699             -- -------------------
6700             -- Api body ends here
6701             -- -------------------
6702             -- Standard check of p_commit.
6703             IF Fnd_Api.To_Boolean(p_commit)
6704             THEN
6705                 COMMIT WORK;
6706             END IF;
6707 
6708             -- Standard call to get message count and IF count is  get message info.
6709             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6710                                       p_data  => x_msg_data);
6711         END IF;
6712     EXCEPTION
6713         WHEN Fnd_Api.G_EXC_ERROR THEN
6714             ROLLBACK TO Create_repair_task_hist;
6715             x_return_status := Fnd_Api.G_RET_STS_ERROR;
6716             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6717                                       p_data  => x_msg_data);
6718         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
6719             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
6720             ROLLBACK TO Create_repair_task_hist;
6721             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6722                                       p_data  => x_msg_data);
6723         WHEN OTHERS THEN
6724             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
6725             ROLLBACK TO Create_repair_task_hist;
6726             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
6727             THEN
6728                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
6729             END IF;
6730             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6731                                       p_data  => x_msg_data);
6732     END Create_repair_task_hist;
6733 
6734     /*-----------------------------------------------------------------------------------------------------------*/
6735     /* procedure name: Update_repair_task_hist                                                                   */
6736     /* description   : procedure used to Update Repair Order history                                             */
6737     /*                 for task creation                                                                         */
6738     /* Called from   : Depot Repair Form to update to Repair history                                             */
6739     /* Input Parm    : p_api_version         NUMBER      Required Api Version number                             */
6740     /*                 p_init_msg_list       VARCHAR2    Optional Initializes message stack if fnd_api.g_true,   */
6741     /*                                                            default value is fnd_api.g_false               */
6742     /*                 p_commit              VARCHAR2    Optional Commits in API if fnd_api.g_true, default      */
6743     /*                                                            fnd_api.g_false                                */
6744     /*                 p_validation_level    NUMBER      Optional API uses this parameter to determine which     */
6745     /*                                                            validation steps must be done and which steps  */
6746     /*                                                            should be skipped.                             */
6747     /*                 p_task_id             NUMBER      Required Task Id                                        */
6748     /*                 p_repair_line_id      NUMBER      Required Repair_line_id                                 */
6749     /* Output Parm   : x_return_status       VARCHAR2             Return status after the call. The status can be*/
6750     /*                                                            fnd_api.g_ret_sts_success (success)            */
6751     /*                                                            fnd_api.g_ret_sts_error (error)                */
6752     /*                                                            fnd_api.g_ret_sts_unexp_error (unexpected)     */
6753     /*                 x_msg_count           NUMBER               Number of messages in the message stack        */
6754     /*                 x_msg_data            VARCHAR2             Message text if x_msg_count >= 1               */
6755     /*-----------------------------------------------------------------------------------------------------------*/
6756 
6757     PROCEDURE Update_repair_task_hist(p_api_version       IN NUMBER,
6758                                       p_init_msg_list     IN VARCHAR2 := Fnd_Api.g_true,
6759                                       p_commit            IN VARCHAR2 := Fnd_Api.g_false,
6760                                       p_validation_level  IN NUMBER := Fnd_Api.g_valid_level_full,
6761                                       p_task_activity_rec IN Csd_Process_Pvt.TASK_ACTIVITY_REC,
6762                                       x_return_status     OUT NOCOPY VARCHAR2,
6763                                       x_msg_count         OUT NOCOPY NUMBER,
6764                                       x_msg_data          OUT NOCOPY VARCHAR2) IS
6765         l_api_name    CONSTANT VARCHAR2(30) := 'VALIDATE_AND_WRITE';
6766         l_api_version CONSTANT NUMBER := 1.0;
6767         l_msg_count          NUMBER;
6768         l_msg_data           VARCHAR2(2000);
6769         l_msg_index          NUMBER;
6770         l_return_status      VARCHAR2(1);
6771         l_repair_history_id  NUMBER;
6772         l_event_code         VARCHAR2(30);
6773         l_hist_ec            VARCHAR2(30);
6774         l_owner_type         VARCHAR2(240);
6775         l_owner              VARCHAR2(240);
6776         l_assignee_type      VARCHAR2(240);
6777         l_assignee_name      VARCHAR2(240);
6778         l_task_status        VARCHAR2(240);
6779         l_last_updated_by    NUMBER;
6780         l_assigned_by_id     NUMBER;
6781         l_task_number        VARCHAR2(240);
6782         l_task_name          VARCHAR2(240);
6783         l_planned_start_Date DATE;
6784         l_actual_start_Date  DATE;
6785         l_actual_end_Date    DATE;
6786         l_last_update_date   DATE;
6787 
6788         CURSOR c_task_hist(p_task_id NUMBER, p_repair_line_id NUMBER) IS
6789             SELECT hist.event_code,
6790                    hist.paramc2, -- owner type/assignee type(TAC)
6791                    hist.paramc3, -- tsk.owner name/assignee name (TAC)
6792                    hist.paramc4, -- assignee_type/previous assignee type (TAC)
6793                    hist.paramc5, -- tsk.assignee_name/prev task assignee name (TAC)
6794                    hist.paramc6, -- task status/null (TAC)
6795                    hist.paramn3, -- task owner id/assignee isd (TAC)
6796                    hist.paramn5, --status id/null (TAC)
6797                    hist.paramn6 -- tsk.assignee_id (TAC)
6798               FROM CSD_REPAIR_HISTORY hist
6799              WHERE hist.paramn1 = p_task_id
6800                AND hist.repair_line_id = p_repair_line_id
6801             --and hist.event_code             = 'TC'
6802              ORDER BY hist.repair_history_id DESC;
6803 
6804         CURSOR c_task(p_task_id NUMBER, p_repair_line_id NUMBER) IS
6805             SELECT
6806 
6807              tsk.last_updated_by, -- hist.paramn2
6808 
6809              tsk.assigned_by_id, -- hist.paramn4
6810 
6811              tsk.task_number, -- hist.paramc1
6812              tsk.task_name,
6813 
6814              tsk.planned_start_date, -- hist.paramd1
6815              tsk.actual_start_date, -- hist.paramd2
6816              tsk.actual_end_date, -- hist.paramd3
6817              tsk.last_update_date -- hist.paramd4
6818               FROM CSD_REPAIR_TASKS_V tsk
6819              WHERE tsk.source_object_type_code = 'DR'
6820                AND tsk.source_object_id = p_repair_line_id
6821                AND tsk.task_id = p_task_id;
6822 
6823     BEGIN
6824         -- --------------------------------
6825         -- Begin create repair task history
6826         -- --------------------------------
6827         -- Standard Start of API savepoint
6828         SAVEPOINT Update_repair_task_hist;
6829         -- Standard call to check for call compatibility.
6830         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
6831                                            p_api_version,
6832                                            l_api_name,
6833                                            G_PKG_NAME)
6834         THEN
6835             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
6836         END IF;
6837         -- Initialize message list if p_init_msg_list is set to TRUE.
6838         IF Fnd_Api.to_Boolean(p_init_msg_list)
6839         THEN
6840             Fnd_Msg_Pub.initialize;
6841         END IF;
6842         -- Initialize API return status to success
6843         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
6844         -- ---------------
6845         -- Api body starts
6846         -- ---------------
6847         -- if any of the values (Assignee, owner,status) have chnaged then proceed else get out
6848         IF (p_task_activity_rec.old_status_id <>
6849            p_task_activity_rec.new_status_id OR
6850            p_task_activity_rec.old_resource_id <>
6851            p_task_activity_rec.new_resource_id OR
6852            p_task_activity_rec.old_owner_id <>
6853            p_task_activity_rec.new_owner_id)
6854         THEN
6855             --fetch the cursor in local variables
6856             OPEN c_task(p_task_activity_rec.task_id,
6857                         p_task_activity_rec.repair_line_id);
6858 
6859             FETCH c_task
6860                 INTO l_last_updated_by, -- last updated by
6861             l_assigned_by_id, -- assigned by id
6862             l_task_number, -- task number
6863             l_task_name, -- task name
6864             l_planned_start_Date, -- planned start date
6865             l_actual_start_Date, -- actual start date
6866             l_actual_end_Date, -- actual end date
6867             l_last_update_date; -- last updated date
6868             CLOSE c_task;
6869             -- find out the events that need to be logged.
6870             --If old owner name is not the same as the new owner name, log the event TOC
6871             IF (p_task_activity_rec.new_owner_id <>
6872                p_task_activity_rec.old_owner_id)
6873             THEN
6874                 l_event_Code := 'TOC';
6875                 --log the activity
6876                 -- ------------------------------------------------------
6877                 -- Internal Private API call to write to Repair History
6878                 -- ------------------------------------------------------
6879                 Csd_To_Form_Repair_History.Validate_And_Write(p_Api_Version_Number     => 1.0,
6880                                                               p_init_msg_list          => 'F',
6881                                                               p_commit                 => 'F',
6882                                                               p_validation_level       => NULL,
6883                                                               p_action_code            => 0,
6884                                                               px_REPAIR_HISTORY_ID     => l_repair_history_id,
6885                                                               p_OBJECT_VERSION_NUMBER  => NULL,
6886                                                               p_REQUEST_ID             => NULL,
6887                                                               p_PROGRAM_ID             => NULL,
6888                                                               p_PROGRAM_APPLICATION_ID => NULL,
6889                                                               p_PROGRAM_UPDATE_DATE    => NULL,
6890                                                               p_CREATED_BY             => Fnd_Global.USER_ID,
6891                                                               p_CREATION_DATE          => SYSDATE,
6892                                                               p_LAST_UPDATED_BY        => Fnd_Global.USER_ID,
6893                                                               p_LAST_UPDATE_DATE       => SYSDATE,
6894                                                               p_repair_line_id         => p_task_activity_rec.repair_line_id,
6895                                                               p_EVENT_CODE             => l_event_code,
6896                                                               p_EVENT_DATE             => SYSDATE,
6897                                                               p_QUANTITY               => NULL,
6898                                                               p_PARAMN1                => p_task_activity_rec.task_id, -- task_id
6899                                                               p_PARAMN2                => l_last_updated_by, -- last_updated_by
6900                                                               p_PARAMN3                => p_task_Activity_rec.new_owner_id, -- owner_id
6901                                                               p_PARAMN4                => l_assigned_by_id, -- assigned_by_id
6902                                                               p_PARAMN5                => p_task_Activity_rec.new_status_id, --l_paramn5, -- status_id
6903                                                               p_PARAMN6                => p_task_activity_rec.old_owner_id, -- assignee_id sangiguptask
6904                                                               p_PARAMN7                => NULL,
6905                                                               p_PARAMN8                => NULL,
6906                                                               p_PARAMN9                => NULL,
6907                                                               p_PARAMN10               => Fnd_Global.USER_ID,
6908                                                               p_PARAMC1                => l_task_number, -- l_paramc1,-- task number
6909                                                               p_PARAMC2                => p_task_activity_rec.new_owner_type_code, -- new owner type code
6910                                                               p_PARAMC3                => p_task_activity_rec.new_owner_name, -- task owner name
6911                                                               p_PARAMC4                => NULL, -- l_paramc4,-- asisgnee type
6912                                                               p_PARAMC5                => NULL, -- assignee name
6913                                                               p_PARAMC6                => p_task_activity_rec.new_status, -- task status
6914                                                               p_PARAMC7                => l_task_name,
6915                                                               p_PARAMC8                => p_task_activity_rec.old_owner_type_code, --prev owner type code
6916                                                               p_PARAMC9                => p_task_activity_Rec.old_owner_name, -- prev task owner name
6917                                                               p_PARAMC10               => NULL,
6918                                                               p_PARAMD1                => l_planned_start_Date,
6919                                                               p_PARAMD2                => l_actual_start_date,
6920                                                               p_PARAMD3                => l_actual_end_date,
6921                                                               p_PARAMD4                => l_last_update_Date,
6922                                                               p_PARAMD5                => NULL,
6923                                                               p_PARAMD6                => NULL,
6924                                                               p_PARAMD7                => NULL,
6925                                                               p_PARAMD8                => NULL,
6926                                                               p_PARAMD9                => NULL,
6927                                                               p_PARAMD10               => NULL,
6928                                                               p_ATTRIBUTE_CATEGORY     => NULL,
6929                                                               p_ATTRIBUTE1             => NULL,
6930                                                               p_ATTRIBUTE2             => NULL,
6931                                                               p_ATTRIBUTE3             => NULL,
6932                                                               p_ATTRIBUTE4             => NULL,
6933                                                               p_ATTRIBUTE5             => NULL,
6934                                                               p_ATTRIBUTE6             => NULL,
6935                                                               p_ATTRIBUTE7             => NULL,
6936                                                               p_ATTRIBUTE8             => NULL,
6937                                                               p_ATTRIBUTE9             => NULL,
6938                                                               p_ATTRIBUTE10            => NULL,
6939                                                               p_ATTRIBUTE11            => NULL,
6940                                                               p_ATTRIBUTE12            => NULL,
6941                                                               p_ATTRIBUTE13            => NULL,
6942                                                               p_ATTRIBUTE14            => NULL,
6943                                                               p_ATTRIBUTE15            => NULL,
6944                                                               p_LAST_UPDATE_LOGIN      => Fnd_Global.CONC_LOGIN_ID,
6945                                                               X_Return_Status          => x_return_status,
6946                                                               X_Msg_Count              => x_msg_count,
6947                                                               X_Msg_Data               => x_msg_data);
6948 
6949             END IF;
6950             --If old task status is not the same as the new task status , log the event TSC
6951             IF (p_task_activity_rec.new_status_id <>
6952                p_task_activity_rec.old_status_id)
6953             THEN
6954                 l_event_Code := 'TSC';
6955                 --log the activity
6956                 -- ------------------------------------------------------
6957                 -- Internal Private API call to write to Repair History
6958                 -- ------------------------------------------------------
6959                 Csd_To_Form_Repair_History.Validate_And_Write(p_Api_Version_Number     => 1.0,
6960                                                               p_init_msg_list          => 'F',
6961                                                               p_commit                 => 'F',
6962                                                               p_validation_level       => NULL,
6963                                                               p_action_code            => 0,
6964                                                               px_REPAIR_HISTORY_ID     => l_repair_history_id,
6965                                                               p_OBJECT_VERSION_NUMBER  => NULL,
6966                                                               p_REQUEST_ID             => NULL,
6967                                                               p_PROGRAM_ID             => NULL,
6968                                                               p_PROGRAM_APPLICATION_ID => NULL,
6969                                                               p_PROGRAM_UPDATE_DATE    => NULL,
6970                                                               p_CREATED_BY             => Fnd_Global.USER_ID,
6971                                                               p_CREATION_DATE          => SYSDATE,
6972                                                               p_LAST_UPDATED_BY        => Fnd_Global.USER_ID,
6973                                                               p_LAST_UPDATE_DATE       => SYSDATE,
6974                                                               p_repair_line_id         => p_task_activity_rec.repair_line_id,
6975                                                               p_EVENT_CODE             => l_event_code,
6976                                                               p_EVENT_DATE             => SYSDATE,
6977                                                               p_QUANTITY               => NULL,
6978                                                               p_PARAMN1                => p_task_activity_rec.task_id, -- task_id
6979                                                               p_PARAMN2                => l_last_updated_by, -- last_updated_by
6980                                                               p_PARAMN3                => p_task_Activity_rec.new_owner_id, -- owner_id
6981                                                               p_PARAMN4                => l_assigned_by_id, -- assigned_by_id
6982                                                               p_PARAMN5                => p_task_Activity_rec.new_status_id, --l_paramn5, -- status_id
6983                                                               p_PARAMN6                => p_task_activity_rec.old_status_id,
6984                                                               p_PARAMN7                => NULL,
6985                                                               p_PARAMN8                => NULL,
6986                                                               p_PARAMN9                => NULL,
6987                                                               p_PARAMN10               => Fnd_Global.USER_ID,
6988                                                               p_PARAMC1                => l_task_number, -- task number
6989                                                               p_PARAMC2                => p_task_activity_rec.new_owner_type_code, -- new owner type code
6990                                                               p_PARAMC3                => p_task_activity_rec.new_owner_name, -- task owner name
6991                                                               p_PARAMC4                => NULL, -- asisgnee type
6992                                                               p_PARAMC5                => NULL, -- assignee name
6993                                                               p_PARAMC6                => p_task_activity_rec.new_status, -- task status
6994                                                               p_PARAMC7                => l_task_name,
6995                                                               p_PARAMC8                => p_task_activity_rec.old_status, -- prev task status
6996                                                               p_PARAMC9                => NULL,
6997                                                               p_PARAMC10               => NULL,
6998                                                               p_PARAMD1                => l_planned_start_Date,
6999                                                               p_PARAMD2                => l_actual_start_date,
7000                                                               p_PARAMD3                => l_actual_end_date,
7001                                                               p_PARAMD4                => l_last_update_Date,
7002                                                               p_PARAMD5                => NULL,
7003                                                               p_PARAMD6                => NULL,
7004                                                               p_PARAMD7                => NULL,
7005                                                               p_PARAMD8                => NULL,
7006                                                               p_PARAMD9                => NULL,
7007                                                               p_PARAMD10               => NULL,
7008                                                               p_ATTRIBUTE_CATEGORY     => NULL,
7009                                                               p_ATTRIBUTE1             => NULL,
7010                                                               p_ATTRIBUTE2             => NULL,
7011                                                               p_ATTRIBUTE3             => NULL,
7012                                                               p_ATTRIBUTE4             => NULL,
7013                                                               p_ATTRIBUTE5             => NULL,
7014                                                               p_ATTRIBUTE6             => NULL,
7015                                                               p_ATTRIBUTE7             => NULL,
7016                                                               p_ATTRIBUTE8             => NULL,
7017                                                               p_ATTRIBUTE9             => NULL,
7018                                                               p_ATTRIBUTE10            => NULL,
7019                                                               p_ATTRIBUTE11            => NULL,
7020                                                               p_ATTRIBUTE12            => NULL,
7021                                                               p_ATTRIBUTE13            => NULL,
7022                                                               p_ATTRIBUTE14            => NULL,
7023                                                               p_ATTRIBUTE15            => NULL,
7024                                                               p_LAST_UPDATE_LOGIN      => Fnd_Global.CONC_LOGIN_ID,
7025                                                               X_Return_Status          => x_return_status,
7026                                                               X_Msg_Count              => x_msg_count,
7027                                                               X_Msg_Data               => x_msg_data);
7028 
7029             END IF;
7030             --If old task assignee id is not the same as the new task assignee id,log the event TSC
7031             IF (p_task_activity_rec.new_resource_id <>
7032                p_task_activity_rec.old_resource_id)
7033             THEN
7034                 l_event_Code := 'TAC';
7035                 --log the activity
7036                 -- ------------------------------------------------------
7037                 -- Internal Private API call to write to Repair History
7038                 -- ------------------------------------------------------
7039                 Csd_To_Form_Repair_History.Validate_And_Write(p_Api_Version_Number     => 1.0,
7040                                                               p_init_msg_list          => 'F',
7041                                                               p_commit                 => 'F',
7042                                                               p_validation_level       => NULL,
7043                                                               p_action_code            => 0,
7044                                                               px_REPAIR_HISTORY_ID     => l_repair_history_id,
7045                                                               p_OBJECT_VERSION_NUMBER  => NULL,
7046                                                               p_REQUEST_ID             => NULL,
7047                                                               p_PROGRAM_ID             => NULL,
7048                                                               p_PROGRAM_APPLICATION_ID => NULL,
7049                                                               p_PROGRAM_UPDATE_DATE    => NULL,
7050                                                               p_CREATED_BY             => Fnd_Global.USER_ID,
7051                                                               p_CREATION_DATE          => SYSDATE,
7052                                                               p_LAST_UPDATED_BY        => Fnd_Global.USER_ID,
7053                                                               p_LAST_UPDATE_DATE       => SYSDATE,
7054                                                               p_repair_line_id         => p_task_activity_rec.repair_line_id,
7055                                                               p_EVENT_CODE             => l_event_code,
7056                                                               p_EVENT_DATE             => SYSDATE,
7057                                                               p_QUANTITY               => NULL,
7058                                                               p_PARAMN1                => p_task_activity_rec.task_id, -- task_id
7059                                                               p_PARAMN2                => l_last_updated_by, -- last_updated_by
7060                                                               p_PARAMN3                => p_task_Activity_rec.new_resource_id, -- new assignee id
7061                                                               p_PARAMN4                => p_task_Activity_rec.old_resource_id, -- prev assignee id
7062                                                               p_PARAMN5                => NULL,
7063                                                               p_PARAMN6                => NULL,
7064                                                               p_PARAMN7                => NULL,
7065                                                               p_PARAMN8                => NULL,
7066                                                               p_PARAMN9                => NULL,
7067                                                               p_PARAMN10               => Fnd_Global.USER_ID,
7068                                                               p_PARAMC1                => l_task_number, -- task number
7069                                                               p_PARAMC2                => NULL,
7070                                                               p_PARAMC3                => NULL,
7071                                                               p_PARAMC4                => p_task_activity_rec.new_resource_type_code, -- new assignee type code
7072                                                               p_PARAMC5                => p_task_activity_rec.new_resource_name, -- new task assignee name
7073                                                               p_PARAMC6                => NULL,
7074                                                               p_PARAMC7                => l_task_name,
7075                                                               p_PARAMC8                => p_task_activity_rec.old_resource_type_code, -- old assignee type code
7076                                                               p_PARAMC9                => p_task_activity_rec.old_resource_name, -- old task assignee name
7077                                                               p_PARAMC10               => NULL,
7078                                                               p_PARAMD1                => NULL,
7079                                                               p_PARAMD2                => NULL,
7080                                                               p_PARAMD3                => NULL,
7081                                                               p_PARAMD4                => NULL,
7082                                                               p_PARAMD5                => NULL,
7083                                                               p_PARAMD6                => NULL,
7084                                                               p_PARAMD7                => NULL,
7085                                                               p_PARAMD8                => NULL,
7086                                                               p_PARAMD9                => NULL,
7087                                                               p_PARAMD10               => NULL,
7088                                                               p_ATTRIBUTE_CATEGORY     => NULL,
7089                                                               p_ATTRIBUTE1             => NULL,
7090                                                               p_ATTRIBUTE2             => NULL,
7091                                                               p_ATTRIBUTE3             => NULL,
7092                                                               p_ATTRIBUTE4             => NULL,
7093                                                               p_ATTRIBUTE5             => NULL,
7094                                                               p_ATTRIBUTE6             => NULL,
7095                                                               p_ATTRIBUTE7             => NULL,
7096                                                               p_ATTRIBUTE8             => NULL,
7097                                                               p_ATTRIBUTE9             => NULL,
7098                                                               p_ATTRIBUTE10            => NULL,
7099                                                               p_ATTRIBUTE11            => NULL,
7100                                                               p_ATTRIBUTE12            => NULL,
7101                                                               p_ATTRIBUTE13            => NULL,
7102                                                               p_ATTRIBUTE14            => NULL,
7103                                                               p_ATTRIBUTE15            => NULL,
7104                                                               p_LAST_UPDATE_LOGIN      => Fnd_Global.CONC_LOGIN_ID,
7105                                                               X_Return_Status          => x_return_status,
7106                                                               X_Msg_Count              => x_msg_count,
7107                                                               X_Msg_Data               => x_msg_data);
7108 
7109             END IF;
7110 
7111         END IF; -- most outer if
7112         --
7113         IF (g_debug > 0)
7114         THEN
7115             Csd_Gen_Utility_Pvt.ADD('After Task to Update Repair History : ' ||
7116                                     x_return_status);
7117         END IF;
7118 
7119         -- -------------------
7120         -- Api body ends here
7121         -- -------------------
7122         -- Standard check of p_commit.
7123         IF Fnd_Api.To_Boolean(p_commit)
7124         THEN
7125             COMMIT WORK;
7126         END IF;
7127         -- Standard call to get message count and IF count is  get message info.
7128         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7129                                   p_data  => x_msg_data);
7130         --END IF;
7131         -- ---------------------------------------------------------
7132     EXCEPTION
7133         WHEN Fnd_Api.G_EXC_ERROR THEN
7134             ROLLBACK TO Update_repair_task_hist;
7135             x_return_status := Fnd_Api.G_RET_STS_ERROR;
7136             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7137                                       p_data  => x_msg_data);
7138         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
7139             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
7140             ROLLBACK TO Update_repair_task_hist;
7141             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7142                                       p_data  => x_msg_data);
7143         WHEN OTHERS THEN
7144             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
7145             ROLLBACK TO Update_repair_task_hist;
7146             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
7147             THEN
7148                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
7149             END IF;
7150             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7151                                       p_data  => x_msg_data);
7152     END Update_repair_task_hist;
7153 
7154     /*----------------------------------------------------------------*/
7155     /* procedure name: Close_Status                                   */
7156     /* description   : procedure used to Close RO / Group RO and then */
7157     /*                 Close Service Request                          */
7158     /*----------------------------------------------------------------*/
7159 
7160     PROCEDURE Close_status(p_api_version      IN NUMBER,
7161                            p_commit           IN VARCHAR2 := Fnd_Api.g_false,
7162                            p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
7163                            p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
7164                            p_incident_id      IN NUMBER,
7165                            p_repair_line_id   IN NUMBER,
7166                            x_return_status    OUT NOCOPY VARCHAR2,
7167                            x_msg_count        OUT NOCOPY NUMBER,
7168                            x_msg_data         OUT NOCOPY VARCHAR2) IS
7169 
7170         l_api_name    CONSTANT VARCHAR2(30) := 'Status_Close';
7171         l_api_version CONSTANT NUMBER := 1.0;
7172         l_msg_count              NUMBER;
7173         l_msg_data               VARCHAR2(2000);
7174         l_msg_index              NUMBER;
7175         l_return_status          VARCHAR2(3);
7176         l_validate_flag          BOOLEAN;
7177         l_grp_rec                Csd_Repair_Groups_Pvt.REPAIR_ORDER_GROUP_REC;
7178         l_ro_rec                 Csd_Repairs_Pub.REPLN_Rec_Type;
7179         l_open_ro_cnt            NUMBER;
7180         l_repair_group_id        NUMBER;
7181         l_grp_count              NUMBER;
7182         l_status                 VARCHAR2(10) := 'CLOSED';
7183         l_ro_obj_version_number  NUMBER;
7184         l_grp_obj_version_number NUMBER;
7185         l_interaction_id         NUMBER;
7186         l_incident_id            NUMBER;
7187         l_inc_obj_version_number NUMBER;
7188         l_prof_value             VARCHAR2(1) := '';
7189 
7190         /* Fixed for bug#3416001
7191            Variable l_sr_status has been declared to get the
7192            status of service request which is equivalent of
7193            status 'Close' in local language.
7194         */
7195         l_sr_status VARCHAR2(30);
7196 
7197         CURSOR get_rep_group(p_incident_id IN NUMBER) IS
7198             SELECT crog.repair_group_id,
7199                    crt.repair_type_ref,
7200                    crog.group_txn_status
7201               FROM csd_repair_order_groups crog, csd_repair_types_vl crt
7202              WHERE crog.repair_type_id = crt.repair_type_id
7203                AND crog.incident_id = p_incident_id;
7204 
7205         CURSOR get_ro_order(p_repair_group_id IN NUMBER) IS
7206             SELECT repair_line_id
7207               FROM csd_repairs
7208              WHERE repair_group_id = p_repair_group_id;
7209 
7210     BEGIN
7211         --------------------------------------
7212         -- Standard Start of API savepoint
7213         --------------------------------------
7214         SAVEPOINT Close_Status;
7215 
7216         -- Standard call to check for call compatibility.
7217         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
7218                                            p_api_version,
7219                                            l_api_name,
7220                                            G_PKG_NAME)
7221         THEN
7222             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
7223         END IF;
7224         ------------------------------------------------------------
7225         -- Initialize message list if p_init_msg_list is set to TRUE.
7226         ------------------------------------------------------------
7227         IF Fnd_Api.to_Boolean(p_init_msg_list)
7228         THEN
7229             Fnd_Msg_Pub.initialize;
7230         END IF;
7231 
7232         ---------------------------------------------
7233         -- Initialize API return status to success
7234         ---------------------------------------------
7235         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
7236 
7237         --------------------
7238         -- Api body starts
7239         --------------------
7240         IF (g_debug > 0)
7241         THEN
7242             Csd_Gen_Utility_Pvt.dump_api_info
7243 
7244             (p_pkg_name => G_PKG_NAME, p_api_name => l_api_name);
7245         END IF;
7246 
7247         l_prof_value := NVL(Fnd_Profile.value('CSD_CLOSE_SR'), 'N');
7248         --------------------------------------------
7249         -- Check whether status has to updated for
7250         -- a group / Repair Order
7251         --------------------------------------------
7252 
7253         IF (p_incident_id IS NOT NULL)
7254         THEN
7255 
7256             -- Validate the incident_id
7257 
7258             IF (g_debug > 0)
7259             THEN
7260                 Csd_Gen_Utility_Pvt.ADD('Incident Id =' || p_incident_id);
7261             END IF;
7262 
7263             l_validate_flag := Csd_Process_Util.validate_incident_id(p_incident_id);
7264 
7265             IF NOT (l_validate_flag)
7266             THEN
7267                 IF (g_debug > 0)
7268                 THEN
7269                     Csd_Gen_Utility_Pvt.ADD('The Incident Id is invalid ');
7270                 END IF;
7271 
7272                 RAISE Fnd_Api.G_EXC_ERROR;
7273             END IF;
7274 
7275             -- For all the groups within SR
7276 
7277             FOR grp IN get_rep_group(p_incident_id)
7278             LOOP
7279 
7280                 IF (g_debug > 0)
7281                 THEN
7282                     Csd_Gen_Utility_Pvt.ADD('grp.repair_type_ref  =' ||
7283                                             grp.repair_type_ref);
7284                 END IF;
7285 
7286                 IF grp.repair_type_ref IN ('AE', 'AL')
7287                 THEN
7288 
7289                     IF grp.group_txn_status = 'OM_RECEIVED'
7290                     THEN
7291 
7292                         -- Update for all the Repair Orders within Group
7293                         FOR ro IN get_ro_order(grp.repair_group_id)
7294                         LOOP
7295 
7296                             BEGIN
7297                                 SELECT object_version_number
7298                                   INTO l_ro_obj_version_number
7299                                   FROM csd_repairs
7300                                  WHERE repair_line_id = ro.repair_line_id;
7301                             EXCEPTION
7302                                 WHEN OTHERS THEN
7303                                     RAISE Fnd_Api.G_EXC_ERROR;
7304                             END;
7305 
7306                             l_ro_rec.object_version_number := l_ro_obj_version_number;
7307                             l_ro_rec.status                := 'C';
7308 
7309                             IF (g_debug > 0)
7310                             THEN
7311                                 Csd_Gen_Utility_Pvt.ADD('Update Repair Line Id =' ||
7312                                                         ro.repair_line_id);
7313                             END IF;
7314 
7315                             Csd_Repairs_Pub.Update_Repair_Order(P_Api_Version_Number => 1.0,
7316                                                                 P_Init_Msg_List      => 'T',
7317                                                                 P_Commit             => 'F',
7318                                                                 p_validation_level   => 0,
7319                                                                 p_REPAIR_LINE_ID     => ro.repair_line_id,
7320                                                                 P_REPLN_Rec          => l_ro_rec,
7321                                                                 X_Return_Status      => l_return_status,
7322                                                                 X_Msg_Count          => l_msg_count,
7323                                                                 X_Msg_Data           => l_msg_data);
7324 
7325                             IF (l_return_status <> 'S')
7326                             THEN
7327                                 Fnd_Message.SET_NAME('CSD',
7328                                                      'CSD_API_RO_STAT_UPD_FAIL');
7329                                 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
7330                                                       ro.repair_line_id);
7331                                 Fnd_Msg_Pub.ADD;
7332                                 RAISE Fnd_Api.G_EXC_ERROR;
7333                             END IF;
7334 
7335                         END LOOP;
7336 
7337                         BEGIN
7338                             SELECT object_version_number
7339                               INTO l_grp_obj_version_number
7340                               FROM csd_repair_order_groups
7341                              WHERE repair_group_id = grp.repair_group_id;
7342                         EXCEPTION
7343                             WHEN OTHERS THEN
7344                                 RAISE Fnd_Api.G_EXC_ERROR;
7345                         END;
7346 
7347                         l_grp_rec.object_version_number := l_grp_obj_version_number;
7348                         l_grp_rec.group_txn_status      := 'CLOSED';
7349                         l_grp_rec.repair_group_id       := grp.repair_group_id;
7350 
7351                         IF (g_debug > 0)
7352                         THEN
7353                             Csd_Gen_Utility_Pvt.ADD('Update Repair Group Id =' ||
7354                                                     grp.repair_group_id);
7355                         END IF;
7356 
7357                         -- Update Group
7358                         Csd_Repair_Groups_Pvt.UPDATE_REPAIR_GROUPS(p_api_version            => 1.0,
7359                                                                    p_commit                 => 'F',
7360                                                                    p_init_msg_list          => 'T',
7361                                                                    p_validation_level       => 0,
7362                                                                    x_repair_order_group_rec => l_grp_rec,
7363                                                                    x_return_status          => l_return_status,
7364                                                                    x_msg_count              => l_msg_count,
7365                                                                    x_msg_data               => l_msg_data);
7366 
7367                         IF (l_return_status <> 'S')
7368                         THEN
7369                             Fnd_Message.SET_NAME('CSD',
7370                                                  'CSD_API_GRP_STAT_UPD_FAIL');
7371                             Fnd_Message.SET_TOKEN('REPAIR_GROUP_ID',
7372                                                   grp.repair_group_id);
7373                             Fnd_Msg_Pub.ADD;
7374                             RAISE Fnd_Api.G_EXC_ERROR;
7375                         END IF;
7376 
7377                     END IF;
7378 
7379                 ELSIF grp.repair_type_ref IN ('RR', 'E', 'WR')
7380                 THEN
7381 
7382                     IF grp.group_txn_status = 'OM_SHIPPED'
7383                     THEN
7384 
7385                         -- Update all the repair orders within group
7386 
7387                         FOR ro IN get_ro_order(grp.repair_group_id)
7388                         LOOP
7389 
7390                             BEGIN
7391                                 SELECT object_version_number
7392                                   INTO l_ro_obj_version_number
7393                                   FROM csd_repairs
7394                                  WHERE repair_line_id = ro.repair_line_id;
7395                             EXCEPTION
7396                                 WHEN OTHERS THEN
7397                                     RAISE Fnd_Api.G_EXC_ERROR;
7398                             END;
7399 
7400                             l_ro_rec.object_version_number := l_ro_obj_version_number;
7401                             l_ro_rec.status                := 'C';
7402 
7403                             IF (g_debug > 0)
7404                             THEN
7405                                 Csd_Gen_Utility_Pvt.ADD('Update Repair Line Id =' ||
7406                                                         ro.repair_line_id);
7407                             END IF;
7408 
7409                             Csd_Repairs_Pub.Update_Repair_Order(P_Api_Version_Number => 1.0,
7410                                                                 P_Init_Msg_List      => 'T',
7411                                                                 P_Commit             => 'F',
7412                                                                 p_validation_level   => 0,
7413                                                                 p_REPAIR_LINE_ID     => ro.repair_line_id,
7414                                                                 P_REPLN_Rec          => l_ro_rec,
7415                                                                 X_Return_Status      => l_return_status,
7416                                                                 X_Msg_Count          => l_msg_count,
7417                                                                 X_Msg_Data           => l_msg_data);
7418 
7419                             IF (l_return_status <> 'S')
7420                             THEN
7421                                 Fnd_Message.SET_NAME('CSD',
7422                                                      'CSD_API_RO_STAT_UPD_FAIL');
7423                                 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
7424                                                       ro.repair_line_id);
7425                                 Fnd_Msg_Pub.ADD;
7426                                 RAISE Fnd_Api.G_EXC_ERROR;
7427                             END IF;
7428 
7429                         END LOOP;
7430 
7431                         BEGIN
7432                             SELECT object_version_number
7433                               INTO l_grp_obj_version_number
7434                               FROM csd_repair_order_groups
7435                              WHERE repair_group_id = grp.repair_group_id;
7436                         EXCEPTION
7437                             WHEN OTHERS THEN
7438                                 RAISE Fnd_Api.G_EXC_ERROR;
7439                         END;
7440 
7441                         l_grp_rec.object_version_number := l_grp_obj_version_number;
7442                         l_grp_rec.group_txn_status      := 'CLOSED';
7443                         l_grp_rec.repair_group_id       := grp.repair_group_id;
7444 
7445                         IF (g_debug > 0)
7446                         THEN
7447                             Csd_Gen_Utility_Pvt.ADD('Update Repair Group Id =' ||
7448                                                     grp.repair_group_id);
7449                         END IF;
7450 
7451                         -- Update the Group
7452 
7453                         Csd_Repair_Groups_Pvt.UPDATE_REPAIR_GROUPS(p_api_version            => 1.0,
7454                                                                    p_commit                 => 'F',
7455                                                                    p_init_msg_list          => 'T',
7456                                                                    p_validation_level       => 0,
7457                                                                    x_repair_order_group_rec => l_grp_rec,
7458                                                                    x_return_status          => l_return_status,
7459                                                                    x_msg_count              => l_msg_count,
7460                                                                    x_msg_data               => l_msg_data);
7461 
7462                         IF (l_return_status <> 'S')
7463                         THEN
7464                             Fnd_Message.SET_NAME('CSD',
7465                                                  'CSD_API_GRP_STAT_UPD_FAIL');
7466                             Fnd_Message.SET_TOKEN('REPAIR_GROUP_ID',
7467                                                   grp.repair_group_id);
7468                             Fnd_Msg_Pub.ADD;
7469                             RAISE Fnd_Api.G_EXC_ERROR;
7470                         END IF;
7471 
7472                     END IF; -- grp_txn_status
7473 
7474                 END IF; -- rep_typ_ref
7475 
7476             END LOOP; -- end of all groups
7477 
7478             BEGIN
7479 
7480                 SELECT COUNT(*)
7481                   INTO l_open_ro_cnt
7482                   FROM csd_repairs
7483                  WHERE incident_id = p_incident_id
7484                    AND status <> 'C';
7485 
7486             EXCEPTION
7487                 WHEN OTHERS THEN
7488                     l_open_ro_cnt := -1;
7489             END;
7490 
7491             IF l_open_ro_cnt = 0
7492             THEN
7493 
7494                 IF (g_debug > 0)
7495                 THEN
7496                     Csd_Gen_Utility_Pvt.ADD('Update Incident Id =' ||
7497                                             p_incident_id);
7498                 END IF;
7499 
7500                 BEGIN
7501                     SELECT object_version_number
7502                       INTO l_inc_obj_version_number
7503                       FROM cs_incidents_all_b
7504                      WHERE incident_id = p_incident_id;
7505                 EXCEPTION
7506                     WHEN OTHERS THEN
7507                         l_inc_obj_version_number := -1;
7508                 END;
7509 
7510                 -- swai bug fix 3376564
7511                 -- (1) Close the SR using the seeded 'Closed' status if it is valid
7512                 -- (2) If the seeded status is not valid, then close the SR using the
7513                 --     first valid closed status.
7514                 BEGIN
7515                     SELECT name
7516                       INTO l_sr_status
7517                       FROM cs_incident_statuses_vl
7518                      WHERE incident_subtype = 'INC'
7519                        AND CLOSE_FLAG = 'Y'
7520                        AND TRUNC(SYSDATE) BETWEEN
7521                            TRUNC(NVL(start_date_active, SYSDATE)) AND
7522                            TRUNC(NVL(end_date_active, SYSDATE))
7523                        AND status_code = 'CLOSED';
7524                 EXCEPTION
7525                     WHEN OTHERS THEN
7526                         l_sr_status := NULL;
7527                 END;
7528 
7529                 IF (l_sr_status IS NULL)
7530                 THEN
7531                     /* Fixed for bug#3416001
7532                        Following query has been added to get the
7533                        status of service request which is equivalent of
7534                        status 'Close' in local language.
7535                     */
7536                     SELECT name
7537                       INTO l_sr_status
7538                       FROM cs_incident_statuses_vl
7539                      WHERE incident_subtype = 'INC'
7540                        AND CLOSE_FLAG = 'Y'
7541                        AND TRUNC(SYSDATE) BETWEEN
7542                            TRUNC(NVL(start_date_active, SYSDATE)) AND
7543                            TRUNC(NVL(end_date_active, SYSDATE))
7544                        AND ROWNUM < 2;
7545                 END IF;
7546 
7547                 IF l_prof_value = 'Y'
7548                 THEN
7549                     -- Update the Service Request
7550                     Cs_Servicerequest_Pub.Update_Status(p_api_version           => 2.0,
7551                                                         p_init_msg_list         => 'T',
7552                                                         p_commit                => 'F',
7553                                                         x_return_status         => l_return_status,
7554                                                         x_msg_count             => l_msg_count,
7555                                                         x_msg_data              => l_msg_data,
7556                                                         p_resp_appl_id          => Fnd_Global.RESP_APPL_ID,
7557                                                         p_resp_id               => Fnd_Global.RESP_ID,
7558                                                         p_user_id               => Fnd_Global.USER_ID,
7559                                                         p_login_id              => Fnd_Global.LOGIN_ID,
7560                                                         p_request_id            => p_incident_id,
7561                                                         p_request_number        => NULL,
7562                                                         p_object_version_number => l_inc_obj_version_number,
7563                                                         p_status_id             => NULL,
7564                                                         --            p_status            => 'CLOSED',
7565                                                         /* Fixed for bug#3416001
7566                                                                        Hardcoding for parameter p_status has been removed.
7567                                                                     */
7568                                                         p_status              => l_sr_status,
7569                                                         p_closed_date         => SYSDATE,
7570                                                         p_audit_comments      => NULL,
7571                                                         p_called_by_workflow  => 'F',
7572                                                         p_workflow_process_id => NULL,
7573                                                         p_comments            => NULL,
7574                                                         p_public_comment_flag => 'F',
7575                                                         x_interaction_id      => l_interaction_id);
7576 
7577                     IF (l_return_status <> 'S')
7578                     THEN
7579                         Fnd_Message.SET_NAME('CSD',
7580                                              'CSD_API_SR_STAT_UPD_FAIL');
7581                         Fnd_Message.SET_TOKEN('INCIDENT_ID', p_incident_id);
7582                         Fnd_Msg_Pub.ADD;
7583                         RAISE Fnd_Api.G_EXC_ERROR;
7584                     END IF;
7585 
7586                 END IF;
7587 
7588             END IF;
7589 
7590         ELSIF (p_repair_line_id IS NOT NULL)
7591         THEN
7592 
7593             -- Validate the repair_line_id
7594 
7595             IF (g_debug > 0)
7596             THEN
7597                 Csd_Gen_Utility_Pvt.ADD('Update Repair Line ID =' ||
7598                                         p_repair_line_id);
7599             END IF;
7600 
7601             l_validate_flag := Csd_Process_Util.validate_rep_line_id(p_repair_line_id);
7602 
7603             IF NOT (l_validate_flag)
7604             THEN
7605                 IF (g_debug > 0)
7606                 THEN
7607                     Csd_Gen_Utility_Pvt.ADD('Repair Line Id is invalid ');
7608                 END IF;
7609 
7610                 RAISE Fnd_Api.G_EXC_ERROR;
7611             END IF;
7612 
7613             BEGIN
7614                 SELECT object_version_number
7615                   INTO l_ro_obj_version_number
7616                   FROM csd_repairs
7617                  WHERE repair_line_id = p_repair_line_id;
7618             EXCEPTION
7619                 WHEN OTHERS THEN
7620                     RAISE Fnd_Api.G_EXC_ERROR;
7621             END;
7622 
7623             l_ro_rec.object_version_number := l_ro_obj_version_number;
7624             l_ro_rec.status                := 'C';
7625 
7626             -- Update the Repair Order
7627             Csd_Repairs_Pub.Update_Repair_Order(P_Api_Version_Number => 1.0,
7628                                                 P_Init_Msg_List      => 'T',
7629                                                 P_Commit             => 'F',
7630                                                 p_validation_level   => 0,
7631                                                 p_REPAIR_LINE_ID     => p_repair_line_id,
7632                                                 P_REPLN_Rec          => l_ro_rec,
7633                                                 X_Return_Status      => l_return_status,
7634                                                 X_Msg_Count          => l_msg_count,
7635                                                 X_Msg_Data           => l_msg_data);
7636 
7637             IF (l_return_status <> 'S')
7638             THEN
7639                 Fnd_Message.SET_NAME('CSD', 'CSD_API_RO_STAT_UPD_FAIL');
7640                 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID', p_repair_line_id);
7641                 Fnd_Msg_Pub.ADD;
7642                 RAISE Fnd_Api.G_EXC_ERROR;
7643             END IF;
7644 
7645             BEGIN
7646 
7647                 SELECT repair_group_id, incident_id
7648                   INTO l_repair_group_id, l_incident_id
7649                   FROM csd_repairs
7650                  WHERE repair_line_id = p_repair_line_id;
7651 
7652                 IF (l_repair_group_id IS NOT NULL)
7653                 THEN
7654                     SELECT COUNT(*)
7655                       INTO l_grp_count
7656                       FROM csd_repairs
7657                      WHERE status = 'C'
7658                        AND repair_group_id = l_repair_group_id;
7659                 END IF;
7660 
7661             EXCEPTION
7662                 WHEN NO_DATA_FOUND THEN
7663                     l_grp_count := -1;
7664             END;
7665 
7666             -- Update the Group only if its exists
7667 
7668             IF (l_grp_count = 0 AND l_repair_group_id IS NOT NULL)
7669             THEN
7670 
7671                 IF (g_debug > 0)
7672                 THEN
7673                     Csd_Gen_Utility_Pvt.ADD('Update Repair Group Id =' ||
7674                                             l_repair_group_id);
7675                 END IF;
7676 
7677                 BEGIN
7678                     SELECT object_version_number
7679                       INTO l_grp_obj_version_number
7680                       FROM csd_repair_order_groups
7681                      WHERE repair_group_id = l_repair_group_id;
7682                 EXCEPTION
7683                     WHEN OTHERS THEN
7684                         RAISE Fnd_Api.G_EXC_ERROR;
7685                 END;
7686 
7687                 l_grp_rec.object_version_number := l_grp_obj_version_number;
7688                 l_grp_rec.group_txn_status      := 'CLOSED';
7689                 l_grp_rec.repair_group_id       := l_repair_group_id;
7690 
7691                 Csd_Repair_Groups_Pvt.UPDATE_REPAIR_GROUPS(p_api_version            => 1.0,
7692                                                            p_commit                 => 'F',
7693                                                            p_init_msg_list          => 'T',
7694                                                            p_validation_level       => 0,
7695                                                            x_repair_order_group_rec => l_grp_rec,
7696                                                            x_return_status          => l_return_status,
7697                                                            x_msg_count              => l_msg_count,
7698                                                            x_msg_data               => l_msg_data);
7699 
7700                 IF (l_return_status <> 'S')
7701                 THEN
7702                     Fnd_Message.SET_NAME('CSD',
7703                                          'CSD_API_GRP_STAT_UPD_FAIL');
7704                     Fnd_Message.SET_TOKEN('REPAIR_GROUP_ID',
7705                                           l_repair_group_id);
7706                     Fnd_Msg_Pub.ADD;
7707                     RAISE Fnd_Api.G_EXC_ERROR;
7708                 END IF;
7709 
7710             END IF;
7711 
7712             BEGIN
7713 
7714                 SELECT COUNT(*)
7715                   INTO l_open_ro_cnt
7716                   FROM csd_repairs
7717                  WHERE incident_id = l_incident_id
7718                    AND status <> 'C';
7719 
7720             EXCEPTION
7721                 WHEN OTHERS THEN
7722                     l_open_ro_cnt := -1;
7723             END;
7724 
7725             IF l_open_ro_cnt = 0
7726             THEN
7727 
7728                 IF (g_debug > 0)
7729                 THEN
7730                     Csd_Gen_Utility_Pvt.ADD('Update Service Request = ' ||
7731                                             l_incident_id);
7732                 END IF;
7733 
7734                 -- Update the Service Request
7735 
7736                 BEGIN
7737                     SELECT object_version_number
7738                       INTO l_inc_obj_version_number
7739                       FROM cs_incidents_all_b
7740                      WHERE incident_id = l_incident_id;
7741                 EXCEPTION
7742                     WHEN OTHERS THEN
7743                         l_inc_obj_version_number := -1;
7744                 END;
7745 
7746                 -- swai bug fix 3376564
7747                 -- (1) Close the SR using the seeded 'Closed' status if it is valid
7748                 -- (2) If the seeded status is not valid, then close the SR using the
7749                 --     first valid closed status.
7750                 BEGIN
7751                     SELECT name
7752                       INTO l_sr_status
7753                       FROM cs_incident_statuses_vl
7754                      WHERE incident_subtype = 'INC'
7755                        AND CLOSE_FLAG = 'Y'
7756                        AND TRUNC(SYSDATE) BETWEEN
7757                            TRUNC(NVL(start_date_active, SYSDATE)) AND
7758                            TRUNC(NVL(end_date_active, SYSDATE))
7759                        AND status_code = 'CLOSED';
7760                 EXCEPTION
7761                     WHEN OTHERS THEN
7762                         l_sr_status := NULL;
7763                 END;
7764 
7765                 IF (l_sr_status IS NULL)
7766                 THEN
7767                     /* Fixed for bug#3416001
7768                      Following query has been added to get the
7769                      status of service request which is equivalent of
7770                      status 'Close' in local language.
7771                     */
7772                     SELECT name
7773                       INTO l_sr_status
7774                       FROM cs_incident_statuses_vl
7775                      WHERE incident_subtype = 'INC'
7776                        AND CLOSE_FLAG = 'Y'
7777                        AND TRUNC(SYSDATE) BETWEEN
7778                            TRUNC(NVL(start_date_active, SYSDATE)) AND
7779                            TRUNC(NVL(end_date_active, SYSDATE))
7780                        AND ROWNUM < 2;
7781                 END IF;
7782 
7783                 IF l_prof_value = 'Y'
7784                 THEN
7785                     -- Update the Service Request
7786                     Cs_Servicerequest_Pub.Update_Status(p_api_version           => 2.0,
7787                                                         p_init_msg_list         => 'T',
7788                                                         p_commit                => 'F',
7789                                                         x_return_status         => l_return_status,
7790                                                         x_msg_count             => l_msg_count,
7791                                                         x_msg_data              => l_msg_data,
7792                                                         p_resp_appl_id          => Fnd_Global.RESP_APPL_ID,
7793                                                         p_resp_id               => Fnd_Global.RESP_ID,
7794                                                         p_user_id               => Fnd_Global.USER_ID,
7795                                                         p_login_id              => Fnd_Global.LOGIN_ID,
7796                                                         p_request_id            => l_incident_id,
7797                                                         p_request_number        => NULL,
7798                                                         p_object_version_number => l_inc_obj_version_number,
7799                                                         p_status_id             => NULL,
7800                                                         --            p_status            => 'CLOSED',
7801                                                         /* Fixed for bug#3416001
7802                                                                        Hardcoding for parameter p_status has been removed.
7803                                                                     */
7804                                                         p_status              => l_sr_status,
7805                                                         p_closed_date         => SYSDATE,
7806                                                         p_audit_comments      => NULL,
7807                                                         p_called_by_workflow  => 'F',
7808                                                         p_workflow_process_id => NULL,
7809                                                         p_comments            => NULL,
7810                                                         p_public_comment_flag => 'F',
7811                                                         x_interaction_id      => l_interaction_id);
7812 
7813                     IF (l_return_status <> 'S')
7814                     THEN
7815                         Fnd_Message.SET_NAME('CSD',
7816                                              'CSD_API_SR_STAT_UPD_FAIL');
7817                         Fnd_Message.SET_TOKEN('INCIDENT_ID', l_incident_id);
7818                         Fnd_Msg_Pub.ADD;
7819                         --Bug fix for 3555256 Begin
7820                         --RAISE FND_API.G_EXC_ERROR;
7821                         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7822                                                   p_data  => x_msg_data);
7823                         --Bug fix for 3555256 End
7824 
7825                     END IF;
7826                 END IF;
7827             END IF;
7828 
7829         END IF;
7830 
7831     EXCEPTION
7832         WHEN Fnd_Api.G_EXC_ERROR THEN
7833             ROLLBACK TO Close_Status;
7834             x_return_status := Fnd_Api.G_RET_STS_ERROR;
7835             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7836                                       p_data  => x_msg_data);
7837         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
7838             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
7839             ROLLBACK TO status_close;
7840             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7841                                       p_data  => x_msg_data);
7842         WHEN OTHERS THEN
7843             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
7844             ROLLBACK TO status_close;
7845             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
7846             THEN
7847                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
7848             END IF;
7849             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7850                                       p_data  => x_msg_data);
7851     END Close_Status;
7852 
7853     /*---------------------------------------------------------------*/
7854     /* procedure name: Check_Service_Request                         */
7855     /* Description:  procedure used to find if there are unasigned   */
7856     /*               RMA/SO lines for the given service request      */
7857     /* Parameters    x_link_mode  determines the way the screen flow */
7858     /*               will happen. The valid values are               */
7859     /*               1: Only unlinked RMA's exist                    */
7860     /*               2: Both unlinked RMA's and unlinked SO's exist  */
7861     /*               3: Only unlinked SO's with atleast 1 repair     */
7862     /*                   for the service request                     */
7863     /*               4: Only unlinked SO without any repair order    */
7864     /*                   for the service request                     */
7865     /*               5: No unlinked RMA or SO                        */
7866     /*---------------------------------------------------------------*/
7867 
7868     PROCEDURE Check_Service_Request(p_api_version      IN NUMBER,
7869                                     p_commit           IN VARCHAR2 := Fnd_Api.g_false,
7870                                     p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
7871                                     p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
7872                                     p_incident_id      IN NUMBER,
7873                                     x_link_mode        OUT NOCOPY NUMBER,
7874                                     x_return_status    OUT NOCOPY VARCHAR2,
7875                                     x_msg_count        OUT NOCOPY NUMBER,
7876                                     x_msg_data         OUT NOCOPY VARCHAR2) IS
7877         l_api_name CONSTANT VARCHAR2(30) := 'Check_Service_Request';
7878         l_rma_count NUMBER;
7879         l_so_count  NUMBER;
7880         l_ro_count  NUMBER;
7881 
7882         --Cursor for selecting count of RMA/SO
7883         CURSOR RMA_SO_CUR(p_incident_Id NUMBER) IS
7884             SELECT Line_Category_code, COUNT(*) line_count
7885               FROM CSD_ESTIMATE_DETAILS_EXT_V
7886              WHERE INCIDENT_ID = p_incident_Id
7887                AND Line_Category_Code IN ('RETURN', 'ORDER')
7888              GROUP BY Line_Category_Code;
7889 
7890         --Cursor to get the count of repair orders for the given SR
7891         CURSOR RO_CUR(p_incident_Id NUMBER) IS
7892             SELECT COUNT(*) ro_count
7893               FROM CSD_REPAIRS
7894              WHERE INCIDENT_ID = p_incident_Id;
7895 
7896     BEGIN
7897 
7898         IF (g_debug > 0)
7899         THEN
7900             Csd_Gen_Utility_Pvt.ADD('In Check_Service_Request API');
7901         END IF;
7902 
7903         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
7904 
7905         -- Initialize the count vars
7906         l_rma_count := 0;
7907         l_so_count  := 0;
7908         --Get the count for RMA and SO
7909         FOR rma_so_rec IN RMA_SO_CUR(p_incident_Id)
7910         LOOP
7911             IF (g_debug > 0)
7912             THEN
7913                 Csd_Gen_Utility_Pvt.ADD('Unlinked RMA/SO found ');
7914                 Csd_Gen_Utility_Pvt.ADD('Category[' ||
7915                                         rma_so_Rec.Line_Category_Code || ']');
7916                 Csd_Gen_Utility_Pvt.ADD('count[' || rma_so_Rec.line_Count || ']');
7917             END IF;
7918 
7919             IF (rma_so_Rec.Line_Category_Code = 'RETURN')
7920             THEN
7921                 l_rma_Count := rma_so_Rec.line_Count;
7922             END IF;
7923             IF (rma_so_Rec.Line_Category_Code = 'ORDER')
7924             THEN
7925                 l_so_Count := rma_so_Rec.line_Count;
7926             END IF;
7927         END LOOP;
7928 
7929         --Determine the mode
7930         IF (l_rma_count > 0 AND l_so_Count > 0)
7931         THEN
7932             x_link_mode := 2;
7933         ELSIF (l_rma_count = 0 AND l_so_count = 0)
7934         THEN
7935             x_link_mode := 5;
7936         ELSIF (l_so_count = 0 AND l_rma_count > 0)
7937         THEN
7938             x_link_mode := 1;
7939         ELSIF (l_rma_count = 0 AND l_so_count > 0)
7940         THEN
7941             -- get the count of repair orders and
7942             -- set the mode to 3 if there are repair orders
7943             -- or to 4 if there are no reapair orders.
7944             l_ro_count := 0;
7945             OPEN RO_CUR(p_incident_Id);
7946             FETCH RO_CUR
7947                 INTO l_ro_count;
7948             CLOSE RO_CUR;
7949 
7950             IF (l_ro_Count > 0)
7951             THEN
7952                 x_link_mode := 3;
7953             ELSE
7954                 x_link_mode := 4;
7955             END IF;
7956 
7957         END IF;
7958 
7959         IF (g_debug > 0)
7960         THEN
7961             Csd_Gen_Utility_Pvt.ADD('Leaving checkService_Request link mode[' ||
7962                                     TO_CHAR(x_link_mode) || ']');
7963         END IF;
7964 
7965     EXCEPTION
7966         WHEN OTHERS THEN
7967             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
7968             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
7969             THEN
7970                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
7971             END IF;
7972             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7973                                       p_data  => x_msg_data);
7974 
7975     END Check_Service_Request;
7976 
7977     /*---------------------------------------------------------------*/
7978     /* procedure name: Update_Line_Txn_Source                        */
7979     /* Description:  procedure used to update the source_code and    */
7980     /*               source_id of the line transaction               */
7981     /*---------------------------------------------------------------*/
7982     PROCEDURE Update_Line_Txn_Source(p_api_version             IN NUMBER,
7983                                      p_commit                  IN VARCHAR2,
7984                                      p_init_msg_list           IN VARCHAR2,
7985                                      p_validation_level        IN NUMBER,
7986                                      p_incident_id             IN NUMBER,
7987                                      p_estimate_detail_line_id IN NUMBER,
7988                                      p_repair_line_id          IN NUMBER,
7989                                      x_return_status           OUT NOCOPY VARCHAR2,
7990                                      x_msg_count               OUT NOCOPY NUMBER,
7991                                      x_msg_data                OUT NOCOPY VARCHAR2) IS
7992     BEGIN
7993 
7994         UPDATE CS_ESTIMATE_DETAILS
7995            SET SOURCE_CODE = 'DR', SOURCE_ID = p_repair_line_id
7996          WHERE INCIDENT_ID = p_incident_id
7997            AND ESTIMATE_DETAIL_ID = p_estimate_detail_line_id;
7998 
7999     END Update_Line_Txn_Source;
8000 
8001     /*---------------------------------------------------------------------------------*/
8002     /* procedure name: Update_iro_product_txn                                          */
8003     /* Description:  procedure used to update the product transaction                  */
8004     /*               table and process pick release and shipping                       */
8005     /*               transactions for internal ROs.                                    */
8006     /*   p_api_version         Standard in parameter                                   */
8007     /*   p_commit              Standard in parameter                                   */
8008     /*   p_init_msg_list       Standard in parameter                                   */
8009     /*   p_validation_level    Standard in parameter                                   */
8010     /*   x_return_status       Standard Out parameter                                  */
8011     /*   x_msg_count           Standard in parameter                                   */
8012     /*   x_msg_data            Standard in parameter ,                                 */
8013     /*   x_product_txn_rec     in out record variable of type                          */
8014     /*                         csd_process_pvt.product_txn_rec ) ;                     */
8015     /*---------------------------------------------------------------------------------*/
8016     PROCEDURE update_iro_product_txn(p_api_version      IN NUMBER,
8017                                      p_commit           IN VARCHAR2,
8018                                      p_init_msg_list    IN VARCHAR2,
8019                                      p_validation_level IN NUMBER,
8020                                      x_product_txn_rec  IN OUT nocopy Csd_Process_Pvt.product_txn_rec,
8021                                      x_return_status    OUT nocopy VARCHAR2,
8022                                      x_msg_count        OUT nocopy NUMBER,
8023                                      x_msg_data         OUT nocopy VARCHAR2) IS
8024 
8025         l_api_name    CONSTANT VARCHAR2(30) := 'update_iro_product_txn';
8026         l_api_version CONSTANT NUMBER := 1.0;
8027         l_msg_count               NUMBER;
8028         l_msg_data                VARCHAR2(2000);
8029         l_msg_index               NUMBER;
8030         l_check                   VARCHAR2(1);
8031         l_order_rec               Csd_Process_Pvt.om_interface_rec;
8032         l_est_detail_id           NUMBER := NULL;
8033         l_incident_id             NUMBER := NULL;
8034         l_party_id                NUMBER := NULL;
8035         l_account_id              NUMBER := NULL;
8036         l_order_header_id         NUMBER := NULL;
8037         l_released_status         VARCHAR2(1) := '';
8038         l_picking_rule_id         NUMBER := NULL;
8039         l_repair_line_id          NUMBER := NULL;
8040         l_curr_submit_order_flag  VARCHAR2(1) := '';
8041         l_curr_book_order_flag    VARCHAR2(1) := '';
8042         l_curr_release_order_flag VARCHAR2(1) := '';
8043         l_curr_ship_order_flag    VARCHAR2(1) := '';
8044         l_booked_flag             VARCHAR2(1) := '';
8045         l_allow_ship              VARCHAR2(1) := '';
8046         l_object_version_num      NUMBER := NULL;
8047         l_ship_from_org_id        NUMBER := NULL;
8048         l_order_line_id           NUMBER := NULL;
8049         l_bus_process_id          NUMBER := NULL;
8050         l_unit_selling_price      NUMBER := NULL;
8051         l_serial_flag             BOOLEAN := FALSE;
8052         l_order_category_code     VARCHAR2(30);
8053         l_orig_src_reference      VARCHAR2(30);
8054         l_orig_src_header_id      NUMBER;
8055         l_orig_src_line_id        NUMBER;
8056         l_orig_po_num             VARCHAR2(50);
8057 
8058         -- travi fix
8059         l_repair_mode     VARCHAR2(30) := NULL;
8060         l_count_est       NUMBER := 0;
8061         l_count_iface_est NUMBER := 0;
8062         l_count_task      NUMBER := 0;
8063         l_count_wip       NUMBER := 0;
8064 
8065         C_Yes  CONSTANT VARCHAR2(1) := 'Y';
8066         C_No   CONSTANT VARCHAR2(1) := 'N';
8067         C_Zero CONSTANT NUMBER := 0;
8068 
8069         -- define variables to define fnd_log debug levels
8070         l_debug_level NUMBER := Fnd_Log.g_current_runtime_level;
8071         -- examples : 1- copying buffer x to y : low level detailed messages
8072         l_statement_level NUMBER := Fnd_Log.level_statement;
8073         -- examples : 2- key progress events : starting business transactions
8074         l_procedure_level NUMBER := Fnd_Log.level_procedure;
8075         -- examples : 3- event  : calling an api, key progress events
8076         l_event_level NUMBER := Fnd_Log.level_event;
8077         -- examples : 4- exception  internal software failure condition
8078         l_exception_level NUMBER := Fnd_Log.level_exception;
8079         -- examples : 5- error  end user erros
8080         l_error_level NUMBER := Fnd_Log.level_error;
8081         l_module_name VARCHAR2(240) := 'csd.plsql.csd_process_pvt.update_iro_product_txn';
8082 
8083         -- a variable whose value tells us whether order header can be pick released or not.
8084         l_order_to_be_pickreleased VARCHAR2(1) := C_NO;
8085         -- a variable whose value tells us whether order header can be shipped or not.
8086         l_order_to_be_shipped VARCHAR2(1) := C_No;
8087 
8088         -- constants to define delivery line release statuses
8089         c_ready_for_release    CONSTANT VARCHAR2(1) := 'R';
8090         c_backordered          CONSTANT VARCHAR2(1) := 'B';
8091         c_staged_pickconfirmed CONSTANT VARCHAR2(1) := 'Y';
8092         c_shipped              CONSTANT VARCHAR2(1) := 'C';
8093         c_cancelled            CONSTANT VARCHAR2(1) := 'D';
8094         c_release_to_warehouse CONSTANT VARCHAR2(1) := 'S';
8095         ----- End of definition of release statuses
8096 
8097         -- Define variable for action type values
8098         C_Action_Type_Move_Out CONSTANT VARCHAR2(30) := 'MOVE_OUT';
8099         C_Action_Type_Move_In  CONSTANT VARCHAR2(30) := 'MOVE_IN';
8100 
8101         -- Define varialbes for Action variable in  process_sales_order API
8102         C_Action_Pick_Release CONSTANT VARCHAR2(30) := 'PICK-RELEASE';
8103         C_Action_Ship         CONSTANT VARCHAR2(30) := 'SHIP';
8104 
8105         -- Define constants to hold product txn status values
8106         C_Status_Released CONSTANT VARCHAR2(30) := 'RELEASED';
8107         C_Status_Shipped  CONSTANT VARCHAR2(30) := 'SHIPPED';
8108 
8109         release_order_excep EXCEPTION;
8110         ship_order_excep EXCEPTION;
8111 
8112         CURSOR sr_rec(p_incident_id IN NUMBER) IS
8113             SELECT customer_id, account_id
8114               FROM cs_incidents_all_b
8115              WHERE incident_id = p_incident_id;
8116 
8117         CURSOR prod_txn(p_prod_txn_id IN NUMBER) IS
8118             SELECT estimate_detail_id,
8119                    repair_line_id,
8120                    interface_to_om_flag,
8121                    book_sales_order_flag,
8122                    release_sales_order_flag,
8123                    ship_sales_order_flag,
8124                    object_version_number
8125               FROM csd_product_transactions
8126              WHERE product_transaction_id = p_prod_txn_id;
8127 
8128         CURSOR released_lines_cur(p_order_header_id IN NUMBER, p_Order_Line_id IN NUMBER) IS
8129             SELECT source_header_id, source_line_id, released_status
8130               FROM wsh_delivery_details
8131              WHERE source_header_id = p_order_header_id
8132                AND Source_line_id = p_Order_line_id
8133 	       AND SOURCE_CODE = 'OE' /*Fixed for bug#5846054*/
8134                AND released_status = C_Staged_PickConfirmed;
8135 
8136         CURSOR shipped_lines_cur(p_order_header_id IN NUMBER, p_Order_Line_Id IN NUMBER) IS
8137             SELECT source_header_id, source_line_id, released_status
8138               FROM wsh_delivery_details
8139              WHERE source_header_id = p_order_header_id
8140                AND Source_line_id = p_Order_line_id
8141 	       AND SOURCE_CODE = 'OE' /*Fixed for bug#5846054*/
8142                AND released_status = C_Shipped;
8143 
8144     BEGIN
8145         IF l_statement_level >= l_debug_level
8146         THEN
8147             Fnd_Log.string(l_statement_level, l_module_name, 'begin');
8148         END IF;
8149         -- standard start of api savepoint
8150         SAVEPOINT update_iro_product_txn;
8151         IF l_statement_level >= l_debug_level
8152         THEN
8153             Fnd_Log.string(l_statement_level,
8154                            l_module_name,
8155                            'checking api compatibility');
8156         END IF;
8157         -- standard call to check for call compatibility.
8158         IF NOT Fnd_Api.compatible_api_call(l_api_version,
8159                                            p_api_version,
8160                                            l_api_name,
8161                                            g_pkg_name)
8162         THEN
8163             IF l_exception_level >= l_debug_level
8164             THEN
8165                 Fnd_Log.string(l_exception_level,
8166                                l_module_name,
8167                                'checking api compatibility, was unsuccessful');
8168             END IF;
8169             RAISE Fnd_Api.g_exc_unexpected_error;
8170         END IF;
8171         IF l_statement_level >= l_debug_level
8172         THEN
8173             Fnd_Log.string(l_statement_level,
8174                            l_module_name,
8175                            'checking api compatibility, was successful');
8176         END IF;
8177 
8178         -- initialize message list if p_init_msg_list is set to true.
8179         IF Fnd_Api.to_boolean(p_init_msg_list)
8180         THEN
8181             Fnd_Msg_Pub.initialize;
8182         END IF;
8183 
8184         -- initialize api return status to success
8185         x_return_status := Fnd_Api.g_ret_sts_success;
8186 
8187         IF l_statement_level >= l_debug_level
8188         THEN
8189             Fnd_Log.String(l_Statement_Level,
8190                            l_Module_Name,
8191                            'Product Transaction Record Values:');
8192             Fnd_Log.String(l_Statement_Level,
8193                            l_Module_Name,
8194                            'Product Transaction Id   :' ||
8195                            x_product_txn_rec.Product_Transaction_Id);
8196             Fnd_Log.String(l_Statement_Level,
8197                            l_Module_Name,
8198                            'Repair_line_id           :' ||
8199                            x_product_txn_rec.repair_line_id);
8200             Fnd_Log.String(l_Statement_Level,
8201                            l_Module_Name,
8202                            'Action_type              :' ||
8203                            x_product_txn_rec.action_type);
8204             Fnd_Log.String(l_Statement_Level,
8205                            l_Module_Name,
8206                            'Action_code              :' ||
8207                            x_product_txn_rec.action_code);
8208             Fnd_Log.String(l_Statement_Level,
8209                            l_Module_Name,
8210                            'Incident_id              :' ||
8211                            x_product_txn_rec.incident_id);
8212             Fnd_Log.String(l_Statement_Level,
8213                            l_Module_Name,
8214                            'line_type_id             :' ||
8215                            x_product_txn_rec.line_type_id);
8216             Fnd_Log.String(l_Statement_Level,
8217                            l_Module_Name,
8218                            'Order_number             :' ||
8219                            x_product_txn_rec.order_number);
8220             Fnd_Log.String(l_Statement_Level,
8221                            l_Module_Name,
8222                            'Status                   :' ||
8223                            x_product_txn_rec.status);
8224             Fnd_Log.String(l_Statement_Level,
8225                            l_Module_Name,
8226                            'Currency_code            :' ||
8227                            x_product_txn_rec.currency_code);
8228             Fnd_Log.String(l_Statement_Level,
8229                            l_Module_Name,
8230                            'Unit_of_measure_code     :' ||
8231                            x_product_txn_rec.unit_of_measure_code);
8232             Fnd_Log.String(l_Statement_Level,
8233                            l_Module_Name,
8234                            'Inventory_item_id        :' ||
8235                            x_product_txn_rec.inventory_item_id);
8236             Fnd_Log.String(l_Statement_Level,
8237                            l_Module_Name,
8238                            'Revision                 :' ||
8239                            x_product_txn_rec.revision);
8240             Fnd_Log.String(l_Statement_Level,
8241                            l_Module_Name,
8242                            'Quantity                 :' ||
8243                            x_product_txn_rec.quantity);
8244             Fnd_Log.String(l_Statement_Level,
8245                            l_Module_Name,
8246                            'Price_list_id            :' ||
8247                            x_product_txn_rec.price_list_id);
8248             Fnd_Log.String(l_Statement_Level,
8249                            l_Module_Name,
8250                            'Source Organization_id   :' ||
8251                            x_product_txn_rec.organization_id);
8252             Fnd_Log.String(l_Statement_Level,
8253                            l_Module_Name,
8254                            'Interface_to_om_flag     :' ||
8255                            x_product_txn_rec.interface_to_om_flag);
8256             Fnd_Log.String(l_Statement_Level,
8257                            l_Module_Name,
8258                            'Book_sales_order_flag    :' ||
8259                            x_product_txn_rec.book_sales_order_flag);
8260             Fnd_Log.String(l_Statement_Level,
8261                            l_Module_Name,
8262                            'Release_sales_order_flag :' ||
8263                            x_product_txn_rec.release_sales_order_flag);
8264             Fnd_Log.String(l_Statement_Level,
8265                            l_Module_Name,
8266                            'Ship_sales_order_flag    :' ||
8267                            x_product_txn_rec.ship_sales_order_flag);
8268             Fnd_Log.String(l_Statement_Level,
8269                            l_Module_Name,
8270                            'Process_txn_flag         :' ||
8271                            x_product_txn_rec.process_txn_flag);
8272             Fnd_Log.String(l_Statement_Level,
8273                            l_Module_Name,
8274                            'Object_version_number    :' ||
8275                            x_product_txn_rec.object_version_number);
8276         END IF;
8277 
8278         IF l_statement_level >= l_debug_level
8279         THEN
8280             Fnd_Log.string(l_statement_level,
8281                            l_module_name || '.check_in_parameters',
8282                            'product txn id is:' ||
8283                            x_product_txn_rec.product_transaction_id);
8284         END IF;
8285 
8286         -- check the required parameter
8287         Csd_Process_Util.check_reqd_param(p_param_value => x_product_txn_rec.product_transaction_id,
8288                                           p_param_name  => 'product_transaction_id',
8289                                           p_api_name    => l_api_name);
8290 
8291         IF l_statement_level >= l_debug_level
8292         THEN
8293             Fnd_Log.string(l_statement_level,
8294                            l_module_name || '.check_in_parameters',
8295                            'product txn id is valid');
8296         END IF;
8297 
8298         -- validate the prod_txn_id if it exists in csd_product_transactions
8299         IF NOT
8300             (Csd_Process_Util.validate_prod_txn_id(p_prod_txn_id => x_product_txn_rec.product_transaction_id))
8301         THEN
8302             IF l_exception_level >= l_debug_level
8303             THEN
8304                 Fnd_Log.string(l_exception_level,
8305                                l_module_name || '.check_in_parameters',
8306                                'product txn id is not valid ');
8307             END IF;
8308             RAISE Fnd_Api.g_exc_error;
8309         END IF;
8310         IF l_statement_level >= l_debug_level
8311         THEN
8312             Fnd_Log.string(l_statement_level,
8313                            l_module_name || '.check_in_parameters',
8314                            'product txn id is valid ');
8315         END IF;
8316 
8317         -- validate the prod_txn_status
8318         IF NVL(x_product_txn_rec.prod_txn_status, Fnd_Api.g_miss_char) <>
8319            Fnd_Api.g_miss_char
8320         THEN
8321             BEGIN
8322                 SELECT 'x'
8323                   INTO l_check
8324                   FROM fnd_lookups
8325                  WHERE lookup_type = 'CSD_PRODUCT_TXN_STATUS'
8326                    AND lookup_code = x_product_txn_rec.prod_txn_status;
8327                 IF l_statement_level >= l_debug_level
8328                 THEN
8329                     Fnd_Log.string(l_statement_level,
8330                                    l_module_name || '.check_in_parameters',
8331                                    'Product txn status is valid : ' ||
8332                                    x_product_txn_rec.prod_txn_status);
8333                 END IF;
8334             EXCEPTION
8335                 WHEN NO_DATA_FOUND THEN
8336                     Fnd_Message.set_name('CSD', 'CSD_ERR_PROD_TXN_STATUS');
8337                     IF l_exception_level >= l_debug_level
8338                     THEN
8339                         Fnd_Log.string(l_exception_level,
8340                                        l_module_name ||
8341                                        '.check_in_parameters',
8342                                        'Product txn status is invalid : ' ||
8343                                        x_product_txn_rec.prod_txn_status);
8344                     END IF;
8345                     Fnd_Msg_Pub.ADD;
8346                     RAISE Fnd_Api.g_exc_error;
8347             END;
8348         END IF;
8349 
8350         IF NVL(x_product_txn_rec.action_type, Fnd_Api.g_miss_char) <>
8351            Fnd_Api.g_miss_char
8352         THEN
8353             -- validate the action type
8354             IF NOT
8355                 (Csd_Process_Util.validate_action_type(p_action_type => x_product_txn_rec.action_type))
8356             THEN
8357                 IF l_exception_level >= l_debug_level
8358                 THEN
8359                     Fnd_Log.string(l_exception_level,
8360                                    l_module_name || '.check_in_parameters',
8361                                    'Action Type s invalid : ' ||
8362                                    x_product_txn_rec.Action_Type);
8363                 END IF;
8364                 RAISE Fnd_Api.g_exc_error;
8365             END IF;
8366         END IF;
8367 
8368         IF NVL(x_product_txn_rec.action_code, Fnd_Api.g_miss_char) <>
8369            Fnd_Api.g_miss_char
8370         THEN
8371             -- validate the action code
8372             IF NOT
8373                 (Csd_Process_Util.validate_action_code(p_action_code => x_product_txn_rec.action_code))
8374             THEN
8375                 IF l_exception_level >= l_debug_level
8376                 THEN
8377                     Fnd_Log.string(l_exception_level,
8378                                    l_module_name || '.check_in_parameters',
8379                                    'Action Code is invalid : ' ||
8380                                    x_product_txn_rec.Action_Code);
8381                 END IF;
8382                 RAISE Fnd_Api.g_exc_error;
8383             END IF;
8384         END IF;
8385         -- Get Current submit_order_flag, book_order_flag, release_order_flag and Ship_Order_Flag
8386         -- statuses and Object_Version_Number values from database
8387         IF NVL(x_product_txn_rec.product_transaction_id, Fnd_Api.g_miss_num) <>
8388            Fnd_Api.g_miss_num
8389         THEN
8390             OPEN prod_txn(x_product_txn_rec.product_transaction_id);
8391             FETCH prod_txn
8392                 INTO l_est_detail_id, l_repair_line_id, l_curr_submit_order_flag, l_curr_book_order_flag, l_curr_release_order_flag, l_curr_ship_order_flag, l_object_version_num;
8393             CLOSE prod_txn;
8394         END IF;
8395 
8396         IF NVL(x_product_txn_rec.repair_line_id, Fnd_Api.g_miss_num) <>
8397            Fnd_Api.g_miss_num
8398         THEN
8399             IF x_product_txn_rec.repair_line_id <> l_repair_line_id
8400             THEN
8401                 IF l_exception_level >= l_debug_level
8402                 THEN
8403                     Fnd_Log.string(l_exception_level,
8404                                    l_module_name || '.check_in_parameters',
8405                                    'Repair Line id can not be changed');
8406                 END IF;
8407                 RAISE Fnd_Api.g_exc_error;
8408             END IF;
8409         ELSE
8410             x_product_txn_rec.repair_line_id := l_repair_line_id;
8411         END IF;
8412 
8413         IF x_product_txn_rec.action_type IN
8414            (C_Action_Type_Move_Out, C_Action_Type_Move_In)
8415         THEN
8416             -- get the incident id for the repair line
8417             BEGIN
8418                 SELECT incident_id
8419                   INTO l_incident_id
8420                   FROM csd_repairs
8421                  WHERE repair_line_id = l_repair_line_id;
8422             EXCEPTION
8423                 WHEN NO_DATA_FOUND THEN
8424                     Fnd_Message.set_name('CSD', 'CSD_API_INV_REP_LINE_ID');
8425                     Fnd_Message.set_token('REPAIR_LINE_ID',
8426                                           l_repair_line_id);
8427                     Fnd_Msg_Pub.ADD;
8428                     IF l_statement_level >= l_debug_level
8429                     THEN
8430                         Fnd_Log.string(l_statement_level,
8431                                        l_module_name ||
8432                                        '.check_in_parameters',
8433                                        'Invalid repair line id ' ||
8434                                        x_product_txn_rec.repair_line_id);
8435                     END IF;
8436                     RAISE Fnd_Api.g_exc_error;
8437             END;
8438             IF l_incident_id IS NOT NULL
8439             THEN
8440                 OPEN sr_rec(l_incident_id);
8441                 FETCH sr_rec
8442                     INTO l_party_id, l_account_id;
8443                 CLOSE sr_rec;
8444             ELSE
8445                 Fnd_Message.set_name('CSD', 'CSD_API_INV_SR_ID');
8446                 Fnd_Message.set_token('INCIDENT_ID', l_incident_id);
8447                 Fnd_Msg_Pub.ADD;
8448                 IF (g_debug > 0)
8449                 THEN
8450                     Csd_Gen_Utility_Pvt.ADD('incident id  missing ');
8451                 END IF;
8452                 RAISE Fnd_Api.g_exc_error;
8453             END IF;
8454 
8455             -- assigning values for the order record
8456             l_order_rec.incident_id := l_incident_id;
8457             l_order_rec.party_id    := l_party_id;
8458             l_order_rec.account_id  := l_account_id;
8459             l_order_rec.org_id      := x_Product_Txn_Rec.Organization_Id;
8460             -- Do further processing only when process transaction flag is 'Y'
8461             IF x_product_txn_rec.process_txn_flag = C_Yes
8462             THEN
8463                 SAVEPOINT release_sales_order;
8464                 -- Do further processing only when process transaction flag values for UI and database
8465                 -- are different and release sales order flag at UI should be checked.
8466                 IF NVL(l_curr_release_order_flag, 'N') <>
8467                    x_product_txn_rec.release_sales_order_flag AND
8468                    x_product_txn_rec.release_sales_order_flag = C_Yes
8469                 THEN
8470                     -- Sub Inventory column will have value if internal requisition has source sub inventory
8471                     -- value else it will have null values.
8472                     IF NVL(x_product_txn_rec.sub_inventory,
8473                            Fnd_Api.g_miss_char) <> Fnd_Api.g_miss_char
8474                     THEN
8475                         l_order_rec.pick_from_subinventory   := x_product_txn_rec.sub_inventory;
8476                         l_order_rec.def_staging_subinventory := x_product_txn_rec.sub_inventory;
8477                     END IF;
8478                     -- get the default pick rule id
8479                     -- Check Action Type and get appropriate picking rule definition
8480                     --R12 Development Changes
8481                     -- Changed code to take the profile value onlyif the input record
8482                     -- picking_rule is null
8483                     IF (x_product_txn_rec.picking_rule_id IS NULL)
8484                     THEN
8485                         IF x_product_txn_rec.Action_Type =
8486                            C_ACTION_TYPE_MOVE_IN
8487                         THEN
8488                             Fnd_Profile.get('csd_pick_release_rule_defect_subinv',
8489                                             l_picking_rule_id);
8490                         ELSIF x_product_txn_rec.Action_Type =
8491                               C_ACTION_TYPE_MOVE_OUT
8492                         THEN
8493                             Fnd_Profile.get('csd_pick_release_rule_usable_subinv',
8494                                             l_picking_rule_id);
8495                         END IF;
8496                     ELSE
8497                         l_picking_rule_id := x_product_txn_rec.picking_rule_id;
8498                     END IF;
8499                     -- fnd_profile.get('csd_def_pick_release_rule',l_picking_rule_id);
8500                     IF l_Statement_level >= l_debug_level
8501                     THEN
8502                         Fnd_Log.string(l_Statement_level,
8503                                        l_module_name,
8504                                        'Default picking rule id :' ||
8505                                        l_Picking_Rule_Id);
8506                     END IF;
8507                     BEGIN
8508                         SELECT picking_rule_id
8509                           INTO l_picking_rule_id
8510                           FROM wsh_picking_rules
8511                          WHERE picking_rule_id = l_picking_rule_id
8512                            AND SYSDATE BETWEEN
8513                                NVL(start_date_active, SYSDATE) AND
8514                                NVL(end_date_active, SYSDATE + 1);
8515                         l_order_rec.picking_rule_id := l_picking_rule_id;
8516                     EXCEPTION
8517                         WHEN NO_DATA_FOUND THEN
8518                             Fnd_Message.set_name('CSD',
8519                                                  'CSD_API_INV_PICKING_RULE_ID');
8520                             Fnd_Message.set_token('PICKING_RULE_ID',
8521                                                   l_picking_rule_id);
8522                             Fnd_Msg_Pub.ADD;
8523                             IF l_exception_level >= l_debug_level
8524                             THEN
8525                                 Fnd_Log.string(l_exception_level,
8526                                                l_module_name,
8527                                                ' Default picking rule id not found');
8528                             END IF;
8529                             RAISE release_order_excep;
8530                     END;
8531                     BEGIN
8532                         -- check released_status column value for the delivery line, if even one record is found
8533                         -- with status ready_for_release or backordered then whole order header needs to be pick released
8534                         SELECT 'Y'
8535                           INTO l_order_to_be_pickreleased
8536                           FROM wsh_delivery_details a
8537                          WHERE a.source_header_id =
8538                                x_product_txn_rec.order_header_id
8539                            AND a.source_line_id =
8540                                x_product_txn_rec.order_line_id
8541                            AND a.released_status IN
8542                                (c_ready_for_release, c_backordered)
8543                            AND ROWNUM < 2;
8544                         IF l_statement_level >= l_debug_level
8545                         THEN
8546                             Fnd_Log.string(l_statement_level,
8547                                            l_module_name,
8548                                            'There are lines eligible for pick release');
8549                         END IF;
8550                     EXCEPTION
8551                         WHEN NO_DATA_FOUND THEN
8552                             -- there are no records to be pick released using public api
8553                             l_order_to_be_pickreleased := C_No;
8554                             IF l_statement_level >= l_debug_level
8555                             THEN
8556                                 Fnd_Log.string(l_statement_level,
8557                                                l_module_name,
8558                                                'There are no lines eligible for pick releas');
8559                             END IF;
8560                     END;
8561                     l_order_rec.order_header_id := x_product_txn_rec.order_header_id;
8562                     IF l_order_to_be_pickreleased = C_Yes
8563                     THEN
8564                         IF l_statement_level >= l_debug_level
8565                         THEN
8566                             Fnd_Log.string(l_statement_level,
8567                                            l_module_name,
8568                                            'Calling process_sales_order to release so');
8569                         END IF;
8570                         Csd_Process_Pvt.process_sales_order(p_api_version      => 1.0,
8571                                                             p_commit           => Fnd_Api.g_false,
8572                                                             p_init_msg_list    => Fnd_Api.g_true,
8573                                                             p_validation_level => Fnd_Api.g_valid_level_full,
8574                                                             p_action           => C_Action_Pick_Release,
8575                                                             p_order_rec        => l_order_rec,
8576                                                             x_return_status    => x_return_status,
8577                                                             x_msg_count        => x_msg_count,
8578                                                             x_msg_data         => x_msg_data);
8579                         IF (x_return_status = Fnd_Api.g_ret_sts_error)
8580                         THEN
8581                             IF l_exception_level >= l_debug_level
8582                             THEN
8583                                 Fnd_Log.string(l_exception_level,
8584                                                l_module_name,
8585                                                'csd_process_pvt.process_sales_order failed');
8586                             END IF;
8587                             RAISE release_order_excep;
8588                         ELSE
8589                             IF l_statement_level >= l_debug_level
8590                             THEN
8591                                 Fnd_Log.string(l_statement_level,
8592                                                l_module_name,
8593                                                'process_sales_order was successful');
8594                             END IF;
8595                         END IF; -- X_Return_Status is Error
8596                     END IF; --l_order_to_be_pickreleased = 'y' then
8597                     -- Check if there are any delivery lines in status in 'Ready To Releas',
8598                     -- Released To WareHouse', 'Back ORdered' for a given order header id and
8599                     -- order line id, if so line is not eligible to stamp for 'Released' status.
8600                     BEGIN
8601                         SELECT 'Y'
8602                           INTO l_order_to_Be_PickReleased
8603                           FROM wsh_Delivery_Details
8604                          WHERE source_header_id =
8605                                x_product_txn_rec.order_header_id
8606                            AND source_line_id =
8607                                x_product_txn_Rec.Order_line_id
8608 			   AND SOURCE_CODE = 'OE' /*Fixed for bug#5846054*/
8609                            AND released_Status IN
8610                                (c_ready_for_release, c_backordered,
8611                                 c_release_to_warehouse);
8612                         IF l_statement_level >= l_debug_level
8613                         THEN
8614                             Fnd_Log.string(l_statement_level,
8615                                            l_module_name,
8616                                            'Still there are some lines to be pick released');
8617                         END IF;
8618                     EXCEPTION
8619                         WHEN NO_DATA_FOUND THEN
8620                             l_order_to_Be_PickReleased := 'N';
8621                             IF l_statement_level >= l_debug_level
8622                             THEN
8623                                 Fnd_Log.string(l_statement_level,
8624                                                l_module_name,
8625                                                'There are no lines to be pick released');
8626                             END IF;
8627                         WHEN TOO_MANY_ROWS THEN
8628                             IF l_statement_level >= l_debug_level
8629                             THEN
8630                                 Fnd_Log.string(l_statement_level,
8631                                                l_module_name,
8632                                                'More then one line to be pick released');
8633                             END IF;
8634                             l_order_to_Be_PickReleased := 'Y';
8635                     END;
8636                     IF l_order_TO_Be_PickReleased = 'N'
8637                     THEN
8638                         -- since pick release process is complete update product transaction lines
8639                         FOR released_line_rec IN released_lines_cur(x_product_txn_rec.order_header_id,
8640                                                                     x_product_txn_rec.order_line_id)
8641                         LOOP
8642                             -- update product transaction tables
8643                             UPDATE csd_product_transactions
8644                                SET prod_txn_status          = C_Status_Released,
8645                                    release_sales_order_flag = C_Yes,
8646                                    object_version_number    = Object_Version_Number + 1,
8647                                    Last_Update_Date         = SYSDATE,
8648                                    Last_Updated_By          = Fnd_Global.User_Id,
8649                                    Last_Update_login        = Fnd_Global.Login_Id
8650                              WHERE order_header_id =
8651                                    released_line_rec.source_header_id
8652                                AND order_line_id =
8653                                    released_line_rec.source_line_id
8654                                AND NVL(release_sales_order_flag, C_No) = C_No;
8655                             --
8656                             IF SQL%FOUND
8657                             THEN
8658                                 -- Product Transaction records are updated.
8659                                 IF l_statement_level >= l_debug_level
8660                                 THEN
8661                                     Fnd_Log.string(l_statement_level,
8662                                                    l_module_name,
8663                                                    'Product transaction records are updated with Released Status');
8664                                     Fnd_Log.string(l_statement_level,
8665                                                    l_module_name,
8666                                                    'Internal Order header id :' ||
8667                                                    x_product_txn_rec.order_header_id);
8668                                     Fnd_Log.string(l_statement_level,
8669                                                    l_module_name,
8670                                                    'Internal Order Line id :' ||
8671                                                    x_product_txn_rec.order_Line_id);
8672                                 END IF;
8673                                 /****************************
8674                                 RO is not udpated as it is does not make sense to update RO record
8675                                 when ever its product transactions are released. Not applicable to internal ROs.
8676                                     update csd_repairs
8677                                     set ro_txn_status            = 'OM_RELEASED' ,
8678                                        object_version_number    = Object_Version_Number + 1,
8679                                        Last_Update_Date         = Sysdate,
8680                                        Last_Updated_By          = Fnd_Global.User_Id,
8681                                        Last_Update_login        = Fnd_Global.Login_Id
8682                                     where repair_line_id = x_product_txn_rec.repair_line_id;
8683                                     if sql%notfound then
8684                                        fnd_message.set_name('CSD','CSD_ERR_REPAIRS_UPDATE');
8685                                        fnd_message.set_token('REPAIR_LINE_ID',x_product_txn_rec.repair_line_id);
8686                                        fnd_msg_pub.add;
8687                                        raise release_order_excep;
8688                                     end if;
8689                                 ********************************/
8690                             ELSE
8691                                 -- No Product Transaction records are updated.
8692                                 IF l_statement_level >= l_debug_level
8693                                 THEN
8694                                     Fnd_Log.string(l_statement_level,
8695                                                    l_module_name,
8696                                                    'No valid product transaction record found to update release status');
8697                                     Fnd_Log.string(l_statement_level,
8698                                                    l_module_name,
8699                                                    'Internal Order header id :' ||
8700                                                    x_product_txn_rec.order_header_id);
8701                                     Fnd_Log.string(l_statement_level,
8702                                                    l_module_name,
8703                                                    'Internal Order Line id :' ||
8704                                                    x_product_txn_rec.order_Line_id);
8705                                 END IF;
8706                             END IF; --if sql%found then
8707                         END LOOP; --released_line_rec in
8708                     END IF; -- l_order_to_be_PickReleased
8709                 END IF; --end of pick-release sales order
8710 
8711                 -- Allow auto shipping only when ship_order_flag has different values for UI and database values.
8712                 -- and ship_sales_order_flag is checked in UI.
8713                 -- Ship-Confirm radio button in UI is disabled for items that are serial controlled at SO issue.
8714                 -- Ship-Confirm radio button is disabled in UIwhen more then one delivery lines exist for a
8715                 -- given order line.
8716                 IF NVL(l_curr_ship_order_flag, 'N') <>
8717                    x_product_txn_rec.ship_sales_order_flag AND
8718                    x_product_txn_rec.ship_sales_order_flag = C_Yes
8719                 THEN
8720                     SAVEPOINT ship_sales_order;
8721                     l_order_rec.order_header_id := x_product_txn_rec.order_header_id;
8722                     l_order_rec.order_line_id   := x_product_txn_rec.order_line_id;
8723                     l_order_rec.serial_number   := x_product_txn_rec.source_serial_number; -- from 11.5.10 release
8724                     -- Check if there is a delivery line eligible for shipping for a given order line id
8725                     --Initialize l_Released_Status to NULL
8726                     l_Released_Status := NULL;
8727                     BEGIN
8728                         -- select C_Yes
8729                         -- into  l_allow_ship
8730                         SELECT Released_Status
8731                           INTO l_Released_Status
8732                           FROM wsh_delivery_details
8733                          WHERE source_header_id =
8734                                l_order_rec.order_header_id
8735                            AND source_line_id = l_order_rec.order_line_id
8736                            AND released_status IN (C_Staged_PickConfirmed,
8737                                 C_Release_to_warehouse)
8738 			   AND    SOURCE_CODE = 'OE'; /*Fixed for bug#5840654 */
8739                     EXCEPTION
8740                         WHEN NO_DATA_FOUND THEN
8741                             l_allow_ship := C_No;
8742                             -- fnd_message.set_name('csd','csd_release_failed');
8743                             Fnd_Message.set_name('CSD',
8744                                                  'CSD_ORDER_LINE_NOT_SHIPABLE');
8745                             Fnd_Message.set_token('ORDER_LINE_ID',
8746                                                   l_order_rec.order_line_id);
8747                             Fnd_Msg_Pub.ADD;
8748                             IF l_statement_level >= l_debug_level
8749                             THEN
8750                                 Fnd_Log.string(l_statement_level,
8751                                                l_module_name,
8752                                                'Order line id  ' ||
8753                                                l_Order_rec.Order_Line_id ||
8754                                                ' is not eligible for shipping.');
8755                             END IF;
8756                             RAISE ship_order_excep;
8757                         WHEN TOO_MANY_ROWS THEN
8758                             Fnd_Message.set_name('CSD',
8759                                                  'CSD_TOO_MANY_ROWS_SHIPABLE');
8760                             Fnd_Message.set_token('ORDER_LINE_ID',
8761                                                   l_order_rec.order_line_id);
8762                             Fnd_Msg_Pub.ADD;
8763                             IF l_statement_level >= l_debug_level
8764                             THEN
8765                                 Fnd_Log.string(l_statement_level,
8766                                                l_module_name,
8767                                                'Order line id  ' ||
8768                                                l_Order_rec.Order_Line_id ||
8769                                                ' has more then one delivery lines.');
8770                             END IF;
8771                     END;
8772                     -- if l_allow_ship = C_Yes then
8773                     IF l_Released_Status = C_Staged_PickConfirmed
8774                     THEN
8775                         IF l_statement_level >= l_debug_level
8776                         THEN
8777                             Fnd_Log.string(l_statement_level,
8778                                            l_module_name,
8779                                            'Calling Process Sales Order API');
8780                         END IF;
8781                         Csd_Process_Pvt.process_sales_order(p_api_version      => 1.0,
8782                                                             p_commit           => Fnd_Api.g_false,
8783                                                             p_init_msg_list    => Fnd_Api.g_true,
8784                                                             p_validation_level => Fnd_Api.g_valid_level_full,
8785                                                             p_action           => C_Action_Ship,
8786                                                             p_order_rec        => l_order_rec,
8787                                                             x_return_status    => x_return_status,
8788                                                             x_msg_count        => x_msg_count,
8789                                                             x_msg_data         => x_msg_data);
8790                         IF NOT (x_return_status = Fnd_Api.g_ret_sts_success)
8791                         THEN
8792                             IF l_statement_level >= l_debug_level
8793                             THEN
8794                                 Fnd_Log.string(l_statement_level,
8795                                                l_module_name,
8796                                                ' process sales order failed');
8797                             END IF;
8798                             RAISE ship_order_excep;
8799                         END IF; -- If x_return_status <> fnd_api.g_ret_sts_success
8800                     END IF; -- l_allow_ship = C_Yes
8801                     -- Check if any of the delivery lines status are less then 'Shipped'
8802                     --  for a given order header id and order line id , if so do not update
8803                     -- product txn lines with Shipped status, if not then update product txn table
8804                     BEGIN
8805                         SELECT 'Y'
8806                           INTO l_order_to_Be_Shipped
8807                           FROM wsh_Delivery_Details
8808                          WHERE source_header_id =
8809                                x_product_txn_rec.order_header_id
8810                            AND source_line_id =
8811                                x_product_txn_Rec.Order_line_id
8812 			   AND SOURCE_CODE = 'OE' /*Fixed for bug#5846054*/
8813                            AND released_Status IN
8814                                (c_ready_for_release, c_backordered,
8815                                 c_release_to_warehouse,
8816                                 c_staged_pickconfirmed);
8817                     EXCEPTION
8818                         WHEN NO_DATA_FOUND THEN
8819                             l_order_to_Be_shipped := 'N';
8820                     END;
8821 
8822                     IF l_order_to_Be_Shipped = 'N'
8823                     THEN
8824                         -- since there are no records to be shipped
8825                         -- shipping process is complete update product transaction lines
8826                         FOR Shipped_line_rec IN Shipped_lines_cur(x_product_txn_rec.order_header_id,
8827                                                                   x_product_txn_rec.Order_line_id)
8828                         LOOP
8829                             -- update product transaction tables
8830                             UPDATE csd_product_transactions
8831                                SET -- prod_txn_status          = C_Status_Shipped ,
8832                                    release_sales_order_flag = C_Yes,
8833                                    ship_sales_order_flag    = C_Yes,
8834                                    object_version_number    = Object_Version_Number + 1,
8835                                    Last_Update_Date         = SYSDATE,
8836                                    Last_Updated_By          = Fnd_Global.User_Id,
8837                                    Last_Update_login        = Fnd_Global.Login_Id
8838                              WHERE order_header_id =
8839                                    shipped_line_rec.source_header_id
8840                                AND order_line_id =
8841                                    shipped_line_rec.source_line_id
8842                                AND NVL(ship_sales_order_flag, C_No) = C_No;
8843                             --
8844                             IF SQL%FOUND
8845                             THEN
8846                                 -- Product Transaction records are updated.
8847                                 IF l_statement_level >= l_debug_level
8848                                 THEN
8849                                     Fnd_Log.string(l_statement_level,
8850                                                    l_module_name,
8851                                                    'Product transaction records are updated with Shipped Status');
8852                                     Fnd_Log.string(l_statement_level,
8853                                                    l_module_name,
8854                                                    'Internal Order header id :' ||
8855                                                    x_product_txn_rec.order_header_id);
8856                                     Fnd_Log.string(l_statement_level,
8857                                                    l_module_name,
8858                                                    'Internal Order Line id :' ||
8859                                                    x_product_txn_rec.order_Line_id);
8860                                 END IF;
8861                                 /*****************
8862                                 No need to update repairs block when ever its product transaction
8863                                 line is shipped. One repair order line can have more then one product
8864                                 transaction line and if we update RO when ever it is released or
8865                                 shipped then ro_txn_Status will not be of much use.
8866                                     Update csd_repairs
8867                                        Set ro_txn_status = 'OM_SHIPPED' ,
8868                                           object_version_number    = Object_Version_Number + 1,
8869                                           Last_Update_Date         = Sysdate,
8870                                           Last_Updated_By          = Fnd_Global.User_Id,
8871                                           Last_Update_login        = Fnd_Global.Login_Id
8872                                     Where repair_line_id = x_product_txn_rec.repair_line_id;
8873                                     If sql%notfound then
8874                                        fnd_message.set_name('CSD','CSD_ERR_REPAIRS_UPDATE');
8875                                        fnd_message.set_token('REPAIR_LINE_ID',x_product_txn_rec.repair_line_id);
8876                                        fnd_msg_pub.add;
8877                                        Raise release_order_excep;
8878                                     End if;
8879                                 *****************/
8880                             ELSE
8881                                 -- No Product Transaction records are updated.
8882                                 IF l_statement_level >= l_debug_level
8883                                 THEN
8884                                     Fnd_Log.string(l_statement_level,
8885                                                    l_module_name,
8886                                                    'No valid product transaction record found to update to shipped status');
8887                                     Fnd_Log.string(l_statement_level,
8888                                                    l_module_name,
8889                                                    'Internal Order header id :' ||
8890                                                    x_product_txn_rec.order_header_id);
8891                                     Fnd_Log.string(l_statement_level,
8892                                                    l_module_name,
8893                                                    'Internal Order Line id :' ||
8894                                                    x_product_txn_rec.order_Line_id);
8895                                 END IF;
8896                             END IF; --if sql%found then
8897                         END LOOP; --shipped_line_rec in
8898                     END IF; -- if l_order_to_be_shipped
8899                 END IF; -- end of ship sales order
8900             END IF; --end of process txn
8901         END IF; -- Action Type = MOVE_OUt
8902         -- standard check of p_commit.
8903         IF Fnd_Api.to_boolean(p_commit)
8904         THEN
8905             COMMIT WORK;
8906         END IF;
8907     EXCEPTION
8908         WHEN release_order_excep THEN
8909             -- Set return status to unexpected error
8910             x_return_status := Fnd_Api.g_ret_sts_success;
8911             -- If there is any error  then rollback
8912             ROLLBACK TO release_sales_order;
8913             -- Standard procedure to get error message count and error message is also returned
8914             -- if error message count is 1
8915             Fnd_Msg_Pub.count_and_get(p_count => x_msg_count,
8916                                       p_data  => x_msg_data);
8917         WHEN ship_order_excep THEN
8918             -- Set return status to unexpected error
8919             x_return_status := Fnd_Api.g_ret_sts_success;
8920             -- If there is any error  then rollback
8921             ROLLBACK TO ship_sales_order;
8922             -- Standard procedure to get error message count and error message is also returned
8923             -- if error message count is 1
8924             Fnd_Msg_Pub.count_and_get(p_count => x_msg_count,
8925                                       p_data  => x_msg_data);
8926         WHEN Fnd_Api.g_exc_error THEN
8927             -- Set return status to unexpected error
8928             x_return_status := Fnd_Api.g_ret_sts_error;
8929             -- If there is any error  then rollback
8930             ROLLBACK TO update_iro_product_txn;
8931             -- Standard procedure to get error message count and error message is also returned
8932             -- if error message count is 1
8933             Fnd_Msg_Pub.count_and_get(p_count => x_msg_count,
8934                                       p_data  => x_msg_data);
8935         WHEN Fnd_Api.g_exc_unexpected_error THEN
8936             -- Set return status to unexpected error
8937             x_return_status := Fnd_Api.g_ret_sts_unexp_error;
8938             -- If there is any error  then rollback
8939             ROLLBACK TO update_iro_product_txn;
8940             -- Standard procedure to get error message count and error message is also returned
8941             -- if error message count is 1
8942             Fnd_Msg_Pub.count_and_get(p_count => x_msg_count,
8943                                       p_data  => x_msg_data);
8944         WHEN OTHERS THEN
8945             -- Set return status to unexpected error
8946             x_return_status := Fnd_Api.g_ret_sts_unexp_error;
8947             -- If there is any error  then rollback
8948             ROLLBACK TO update_iro_product_txn;
8949             IF Fnd_Msg_Pub.check_msg_level(Fnd_Msg_Pub.g_msg_lvl_unexp_error)
8950             THEN
8951                 -- Standard way to add sql error message to stack
8952                 Fnd_Msg_Pub.add_exc_msg(g_pkg_name, l_api_name);
8953             END IF;
8954             -- Standard procedure to get error message count and error message is also returned
8955             -- if error message count is 1
8956             Fnd_Msg_Pub.count_and_get(p_count => x_msg_count,
8957                                       p_data  => x_msg_data);
8958     END update_iro_product_txn;
8959 
8960 
8961     /*----------------------------------------------------------------------*/
8962     /*** Forward porting bug# 3877328  */
8963     /*----------------------------------------------------------------------*/
8964     /* procedure name: create_default_prod_txn_wrapr                        */
8965     /* description   : Is a wrapper procedure which does validations before */
8966     /*                 calling procedure create_default_prod_txn.           */
8967     /*                 This API will have same parameters as procedure      */
8968     /*                 create_default_prod_txn. After successful validation */
8969     /*                 wrapper API will pass same input parameters.         */
8970     /*----------------------------------------------------------------------*/
8971 
8972     PROCEDURE Create_Default_Prod_Txn_wrapr(p_api_version           IN NUMBER,
8973                                             p_commit                IN VARCHAR2,
8974                                             p_init_msg_list         IN VARCHAR2,
8975                                             p_validation_level      IN NUMBER,
8976                                             p_repair_line_id        IN NUMBER,
8977                                             x_return_status         OUT NOCOPY VARCHAR2,
8978                                             x_msg_count             OUT NOCOPY NUMBER,
8979                                             x_msg_data              OUT NOCOPY VARCHAR2,
8980                                             x_Logistics_KeyAttr_Tbl OUT NOCOPY Csd_Process_Pvt.Logistics_KeyAttr_Tbl_Type) IS
8981         l_api_name    CONSTANT VARCHAR2(30) := 'Create_Default_Prod_Txn_Wrapr';
8982         l_api_version CONSTANT NUMBER := 1.0;
8983         l_msg_count               NUMBER;
8984         l_msg_data                VARCHAR2(2000);
8985         l_Serial_num_Control_Code NUMBER;
8986         l_RO_Status               VARCHAR2(30);
8987         l_RO_Status_Meaning       VARCHAR2(80);
8988         l_RO_Quantity             NUMBER;
8989         l_Inventory_Item_id       NUMBER;
8990         l_RO_Repair_Type_Ref      VARCHAR2(30);
8991         l_Prod_Txn_Lines_Count    NUMBER;
8992         l_RO_Number               NUMBER;
8993         l_Service_Valdn_Org_Name  VARCHAR2(240);
8994         l_Item_Name               VARCHAR2(240);
8995         -- Define Constants here
8996         C_RO_Status_Open           VARCHAR2(30) := 'O';
8997         C_Repair_Type_Ref_Standard VARCHAR2(10) := 'SR';
8998 
8999         i BINARY_INTEGER; -- loop variable
9000 
9001         -- Define Cursor to get all product transaction lines rec information for a repair order
9002         CURSOR Logistic_KeyAttr_Cur_Type(p_Repair_Line_Id IN NUMBER) IS
9003             SELECT cpt.product_Transaction_Id,
9004                    ced.Estimate_Detail_Id,
9005                    ced.order_header_Id,
9006                    ced.order_Line_Id
9007               FROM csd_product_Transactions cpt, cs_estimate_Details ced
9008              WHERE cpt.repair_line_id = p_Repair_Line_Id
9009                AND cpt.estimate_detail_id = ced.estimate_detail_id;
9010     BEGIN
9011         -- Standard call to check for call compatibility.
9012         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
9013                                            p_api_version,
9014                                            l_api_name,
9015                                            G_PKG_NAME)
9016         THEN
9017             RAISE Fnd_Api.G_Exc_UnExpected_Error;
9018         END IF;
9019 
9020         -- Initialize message list if p_init_msg_list is set to TRUE.
9021         IF Fnd_Api.to_Boolean(p_init_msg_list)
9022         THEN
9023             Fnd_Msg_Pub.initialize;
9024         END IF;
9025 
9026         -- Initialize API return status to success
9027         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
9028 
9029         -- Api body starts
9030         IF (g_debug > 0)
9031         THEN
9032             Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
9033                                               p_api_name => l_api_name);
9034         END IF;
9035         IF (g_debug > 0)
9036         THEN
9037             Csd_Gen_Utility_Pvt.ADD('Checking required parameter:(repair_line_id)');
9038         END IF;
9039         -- Check the required parameter
9040         Csd_Process_Util.Check_Reqd_Param(p_param_value => p_Repair_Line_id,
9041                                           p_param_name  => 'Repair_Line_Id',
9042                                           p_api_name    => l_api_name);
9043         -- Validate Repair_Line_id and check RO status
9044         IF (g_debug > 0)
9045         THEN
9046             Csd_Gen_Utility_Pvt.ADD('Required parameter:(repair_line_id) has value' ||
9047                                     p_Repair_Line_id);
9048         END IF;
9049         BEGIN
9050             IF (g_debug > 0)
9051             THEN
9052                 Csd_Gen_Utility_Pvt.ADD('Querying csd_repairs_v view');
9053             END IF;
9054             SELECT dra.status,
9055                    dra.Quantity,
9056                    dra.Inventory_Item_Id,
9057                    drtvl.Repair_Type_Ref,
9058                    dra.Repair_Number,
9059                    fndl2.meaning
9060               INTO l_RO_Status,
9061                    l_RO_Quantity,
9062                    l_Inventory_Item_id,
9063                    l_RO_Repair_Type_Ref,
9064                    l_RO_Number,
9065                    l_RO_Status_Meaning
9066               FROM csd_repairs dra, fnd_lookups fndl2, csd_repair_types_vl drtvl
9067              WHERE repair_line_id = p_Repair_line_id
9068 		       and dra.repair_type_id = drtvl.repair_type_id
9069 			  and dra.status = fndl2.lookup_code
9070                  and fndl2.lookup_type = 'CSD_REPAIR_STATUS';
9071             -- If Repair Number is Null then Repair_line_id is invalid
9072             -- Now Check RO_Status , if RO_Status is not Open then raise error
9073             IF l_RO_Status <> C_RO_Status_Open
9074             THEN
9075                 -- Display message: Repair Order is in status || l_RO_Status. Default product transaction lines are
9076                 -- not created.
9077                 -- Message Code CSD_RO_NOT_OPEN_NO_PRODTXN_LINES
9078                 -- Raise Error message
9079                 Fnd_Message.SET_NAME('CSD',
9080                                      'CSD_RO_NOT_OPEN_NO_PRODTXN_LNS');
9081                 Fnd_Message.SET_TOKEN('RO_NUMBER', l_RO_Number);
9082                 Fnd_Message.SET_TOKEN('RO_STATUS', l_RO_Status_Meaning);
9083                 Fnd_Msg_Pub.ADD;
9084                 RAISE Fnd_Api.G_EXC_ERROR;
9085             END IF;
9086             -- Check if repair Type Ref is Standard
9087             IF l_RO_Repair_Type_Ref = C_Repair_TYpe_Ref_Standard
9088             THEN
9089                 -- Display message: Default product transaction lines are not created for standard repair type ref
9090                 -- CSD_STD_REP_TYPE_NO_PRODUCTXN_LINES
9091                 Fnd_Message.SET_NAME('CSD',
9092                                      'CSD_STD_REPTYPE_NO_PRODTXN_LNS');
9093                 Fnd_Message.SET_TOKEN('RO_NUMBER', l_RO_Number);
9094                 Fnd_Msg_Pub.ADD;
9095                 RAISE Fnd_Api.G_EXC_ERROR;
9096             END IF;
9097             -- Check Serial control code if quantity is greater then 1
9098             IF l_RO_Quantity > 1
9099             THEN
9100                 BEGIN
9101                     SELECT Serial_Number_Control_COde
9102                       INTO l_Serial_num_COntrol_Code
9103                       FROM Mtl_System_Items_B
9104                      WHERE Inventory_Item_Id = l_Inventory_Item_Id
9105                        AND Organization_id = Cs_Std.Get_Item_Valdn_Orgzn_Id;
9106                     -- If item is serial controlled then raise error
9107                     IF l_Serial_num_COntrol_Code > 1
9108                     THEN
9109                         -- Display Message: RO quantity can not be greater then for serial controlled items.
9110                         -- CSD_RO_QTY_MORE_FOR_SERIAL_ITEM
9111                         -- Raise G_Exc_Error,
9112                         Fnd_Message.SET_NAME('CSD',
9113                                              'CSD_RO_QTY_MORE_FOR_SRLCT_ITEM');
9114                         Fnd_Msg_Pub.ADD;
9115                         RAISE Fnd_Api.G_EXC_ERROR;
9116                     END IF;
9117                 EXCEPTION
9118                     WHEN NO_DATA_FOUND THEN
9119                         -- Get Item Name
9120                         SELECT items.concatenated_segments
9121                           INTO l_Item_Name
9122                           FROM mtl_system_items_vl items, csd_repairs dra
9123                          WHERE dra.repair_line_id = p_Repair_Line_Id
9124                              and dra.inventory_item_id = items.inventory_item_id
9125 					    and items.organization_id = cs_std.get_item_valdn_orgzn_id;
9126 
9127                         -- Get Service Validation Org name
9128                         SELECT Name
9129                           INTO l_Service_Valdn_Org_Name
9130                           FROM Hr_Organization_Units
9131                          WHERE Organization_id =
9132                                Cs_Std.Get_Item_Valdn_Orgzn_Id;
9133 
9134                         Fnd_Message.SET_NAME('CSD',
9135                                              'CSD_NO_ITEM_FOR_SRV_VALDN_ORG');
9136                         Fnd_Message.Set_Token('ITEM', l_Item_Name);
9137                         Fnd_Message.Set_Token('ORG_NAME',
9138                                               l_Service_Valdn_Org_Name);
9139                         Fnd_Msg_Pub.ADD;
9140                         RAISE Fnd_Api.G_EXC_ERROR;
9141 
9142                 END;
9143             END IF;
9144             -- CHeck if there are any product txn lines for a given repair line id
9145             BEGIN
9146                 SELECT COUNT(Product_Transaction_Id)
9147                   INTO l_Prod_Txn_Lines_Count
9148                   FROM csd_product_Transactions
9149                  WHERE Repair_Line_id = p_Repair_Line_Id;
9150                 IF l_Prod_Txn_Lines_Count > 0
9151                 THEN
9152                     -- Default product transaction lines are not created as product transaction lines exist
9153                     -- for Repair Order : l_RO_number
9154                     -- CSD_RO_HAS_PRODTXN_LINES
9155                     -- RAise G_Exc_Error
9156                     Fnd_Message.SET_NAME('CSD',
9157                                          'CSD_RO_HAS_PRODUCT_TXN_LINES');
9158                     Fnd_Message.SET_TOKEN('RO_NUMBER', l_RO_Number);
9159                     Fnd_Msg_Pub.ADD;
9160                     RAISE Fnd_Api.G_EXC_ERROR;
9161                 END IF;
9162             END;
9163         EXCEPTION
9164             WHEN NO_DATA_FOUND THEN
9165                 -- Message Code CSD_REPAIR_LINE_ID_INVALID
9166                 -- Display message; Invalid repair line id is passed
9167                 Fnd_Message.SET_NAME('CSD', 'CSD_API_INV_REP_LINE_ID');
9168                 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID', P_Repair_Line_ID);
9169                 Fnd_Msg_Pub.ADD;
9170                 RAISE Fnd_Api.G_EXC_ERROR;
9171         END;
9172         -- Now call Default Product Txn lines API
9173 
9174         create_default_prod_txn(p_api_version,
9175                                 p_commit,
9176                                 p_init_msg_list,
9177                                 p_validation_level,
9178                                 p_repair_line_id,
9179                                 x_return_status,
9180                                 x_msg_count,
9181                                 x_msg_Data);
9182 
9183         -- Once default product transaction lines are created successfully,
9184         -- assign new entities to new out variable x_Logistics_KeyAttr_Tbl.
9185         IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
9186         THEN
9187             RAISE Fnd_Api.G_EXC_ERROR;
9188         ELSE
9189             --  New code added here
9190             i := 0; -- Initialize loop variable to zero
9191             FOR Logistic_KeyAttr_Rec IN Logistic_KeyAttr_Cur_Type(p_Repair_line_id)
9192             LOOP
9193                 i := i + 1;
9194                 x_Logistics_KeyAttr_Tbl(i).Product_Transaction_Id := Logistic_KeyAttr_Rec.Product_Transaction_Id;
9195                 x_Logistics_KeyAttr_Tbl(i).Estimate_Detail_Id := Logistic_KeyAttr_Rec.Estimate_Detail_Id;
9196                 x_Logistics_KeyAttr_Tbl(i).Order_Header_Id := Logistic_KeyAttr_Rec.Order_Header_Id;
9197                 x_Logistics_KeyAttr_Tbl(i).Order_Line_Id := Logistic_KeyAttr_Rec.Order_Line_Id;
9198             END LOOP;
9199         END IF;
9200 
9201     EXCEPTION
9202         WHEN Fnd_Api.G_EXC_ERROR THEN
9203             x_return_status := Fnd_Api.G_RET_STS_ERROR;
9204             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9205                                       p_data  => x_msg_data);
9206         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
9207             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
9208             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9209                                       p_data  => x_msg_data);
9210         WHEN OTHERS THEN
9211             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
9212             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
9213             THEN
9214                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
9215             END IF;
9216             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9217                                       p_data  => x_msg_data);
9218     END Create_Default_Prod_Txn_Wrapr;
9219 
9220     /*-----------------------------------------------------------------------------------------------------------*/
9221     /* R12 Quality Integration */
9222     /* procedure name: create_repair_task                                                                               */
9223     /* description   : procedure used to create DR specific tasks in Depot tables                                                            */
9224     /* Called from   : Depot Repair Form to Create Task                                                          */
9225     /* Input Parm    : p_api_version         NUMBER      Required Api Version number                             */
9226     /*                 p_init_msg_list       VARCHAR2    Optional Initializes message stack if fnd_api.g_true,   */
9227     /*                                                            default value is fnd_api.g_false               */
9228     /*                 p_commit              VARCHAR2    Optional Commits in API if fnd_api.g_true, default      */
9229     /*                                                            fnd_api.g_false                                */
9230     /*                 p_validation_level    NUMBER      Optional API uses this parameter to determine which     */
9231     /*                                                            validation steps must be done and which steps  */
9232     /*                                                            should be skipped.                             */
9233     /*                 p_CREATE_REPAIR_TASK_REC  RECORD      Required Columns are in the Record REPAIR_TASK_REC_TYPE */
9234     /* Output Parm   : x_return_status       VARCHAR2             Return status after the call. The status can be*/
9235     /*                                                            fnd_api.g_ret_sts_success (success)            */
9236     /*                                                            fnd_api.g_ret_sts_error (error)                */
9237     /*                                                            fnd_api.g_ret_sts_unexp_error (unexpected)     */
9238     /*                 x_msg_count           NUMBER               Number of messages in the message stack        */
9239     /*                 x_msg_data            VARCHAR2             Message text if x_msg_count >= 1               */
9240     /*                 x_task_id             NUMBER               Task Id of the created Task                    */
9241     /*-----------------------------------------------------------------------------------------------------------*/
9242     PROCEDURE CREATE_REPAIR_TASK(p_api_version            IN NUMBER,
9243                                  p_init_msg_list          IN VARCHAR2 := Fnd_Api.g_false,
9244                                  p_commit                 IN VARCHAR2 := Fnd_Api.g_false,
9245                                  p_validation_level       IN NUMBER := Fnd_Api.g_valid_level_full,
9246                                  p_create_repair_task_rec IN REPAIR_TASK_REC,
9247                                  x_return_status          OUT NOCOPY VARCHAR2,
9248                                  x_msg_count              OUT NOCOPY NUMBER,
9249                                  x_msg_data               OUT NOCOPY VARCHAR2,
9250                                  x_repair_task_id         OUT NOCOPY NUMBER) IS
9251 
9252         l_api_name    CONSTANT VARCHAR2(30) := 'CREATE_REPAIR_TASK';
9253         l_api_version CONSTANT NUMBER := 1.0;
9254         l_msg_count     NUMBER;
9255         l_msg_data      VARCHAR2(2000);
9256         l_msg_index     NUMBER;
9257         l_return_status VARCHAR2(1);
9258 
9259         -- Task record
9260         l_create_task_rec     Csd_Process_Pvt.REPAIR_TASK_REC := p_create_repair_task_rec;
9261         l_applicable_qa_plans VARCHAR2(1);
9262         l_plan_txn_ids        VARCHAR2(5000);
9263         l_dummy_char          VARCHAR2(32000);
9264 
9265         -- define variables to define fnd_log debug levels
9266         l_debug_level NUMBER := Fnd_Log.g_current_runtime_level;
9267         -- examples : 1- copying buffer x to y : low level detailed messages
9268         l_statement_level NUMBER := Fnd_Log.level_statement;
9269         -- examples : 2- key progress events : starting business transactions
9270         l_procedure_level NUMBER := Fnd_Log.level_procedure;
9271         -- examples : 3- event  : calling an api, key progress events
9272         l_event_level NUMBER := Fnd_Log.level_event;
9273         -- examples : 4- exception  internal software failure condition
9274         l_exception_level NUMBER := Fnd_Log.level_exception;
9275         -- examples : 5- error  end user erros
9276         l_error_level NUMBER := Fnd_Log.level_error;
9277         l_module_name VARCHAR2(240) := 'csd.plsql.csd_process_pvt.create_repair_task';
9278 
9279     BEGIN
9280         -- -----------------
9281         -- Begin create repair task
9282         -- -----------------
9283 
9284         -- Standard Start of API savepoint
9285         IF l_statement_level >= l_debug_level
9286         THEN
9287             Fnd_Log.string(l_statement_level, l_module_name, 'begin');
9288         END IF;
9289         SAVEPOINT create_repair_task;
9290 
9291         -- Standard call to check for call compatibility.
9292         IF l_statement_level >= l_debug_level
9293         THEN
9294             Fnd_Log.string(l_statement_level,
9295                            l_module_name,
9296                            'checking api compatibility');
9297         END IF;
9298         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
9299                                            p_api_version,
9300                                            l_api_name,
9301                                            G_PKG_NAME)
9302         THEN
9303             IF l_exception_level >= l_debug_level
9304             THEN
9305                 Fnd_Log.string(l_exception_level,
9306                                l_module_name,
9307                                'checking api compatibility, was unsuccessful');
9308             END IF;
9309             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
9310         END IF;
9311 
9312         IF l_statement_level >= l_debug_level
9313         THEN
9314             Fnd_Log.string(l_statement_level,
9315                            l_module_name,
9316                            'checking api compatibility, was successful');
9317         END IF;
9318 
9319         -- Initialize message list if p_init_msg_list is set to TRUE.
9320         IF Fnd_Api.to_Boolean(p_init_msg_list)
9321         THEN
9322             Fnd_Msg_Pub.initialize;
9323         END IF;
9324         -- Initialize API return status to success
9325         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
9326         -- ---------------
9327         -- Api body starts
9328         -- ---------------
9329         IF l_statement_level >= l_debug_level
9330         THEN
9331             Fnd_Log.String(l_Statement_Level,
9332                            l_Module_Name,
9333                            'Task Record Values:');
9334             Fnd_Log.String(l_Statement_Level,
9335                            l_Module_Name,
9336                            'Task Id   :' ||
9337                            p_create_repair_task_rec.task_Id);
9338             Fnd_Log.String(l_Statement_Level,
9339                            l_Module_Name,
9340                            'Repair_line_id           :' ||
9341                            p_create_repair_task_rec.repair_line_id);
9342             Fnd_Log.String(l_Statement_Level,
9343                            l_Module_Name,
9344                            'context values              :' ||
9345                            p_create_repair_task_rec.context_values);
9346         END IF;
9347 
9348         -- check the required parameter
9349 
9350         Csd_Process_Util.check_reqd_param(p_param_value => p_create_repair_task_rec.task_Id,
9351                                           p_param_name  => 'Task Id',
9352                                           p_api_name    => l_api_name);
9353 
9354         IF l_statement_level >= l_debug_level
9355         THEN
9356             Fnd_Log.string(l_statement_level,
9357                            l_module_name || '.check_in_parameters',
9358                            'Task id is valid');
9359         END IF;
9360 
9361         Csd_Process_Util.check_reqd_param(p_param_value => p_create_repair_task_rec.repair_line_Id,
9362                                           p_param_name  => 'Repair Line Id',
9363                                           p_api_name    => l_api_name);
9364 
9365         IF l_statement_level >= l_debug_level
9366         THEN
9367             Fnd_Log.string(l_statement_level,
9368                            l_module_name || '.check_in_parameters',
9369                            'Repair Line id is valid');
9370         END IF;
9371 
9372         -- Determine if any plans are applicable for this task.
9373         l_dummy_char := Qa_Txn_Grp.evaluate_triggers(p_txn_number     => G_DEPOT_REPAIR_TXN_NUMBER,
9374                                                      p_org_id         => p_create_repair_task_rec.org_id,
9375                                                      p_context_values => p_create_repair_task_rec.context_values,
9376                                                      x_plan_txn_ids   => l_plan_txn_ids);
9377 
9378         IF l_plan_txn_ids IS NOT NULL
9379         THEN
9380             l_applicable_qa_plans := 'Y';
9381         ELSE
9382             l_applicable_qa_plans := 'N';
9383         END IF;
9384 
9385         -- Insert into CSD_TASKS table
9386         Csd_Tasks_Pkg.INSERT_ROW(px_repair_task_id       => x_repair_task_id,
9387                                  p_TASK_ID               => p_create_repair_task_rec.task_id,
9388                                  p_OBJECT_VERSION_NUMBER => 1,
9389                                  p_REPAIR_LINE_ID        => p_create_repair_task_rec.repair_line_id,
9390                                  p_APPLICABLE_QA_PLANS   => l_applicable_qa_plans,
9391                                  p_CREATED_BY            => Fnd_Global.USER_ID,
9392                                  p_CREATION_DATE         => SYSDATE,
9393                                  p_LAST_UPDATED_BY       => Fnd_Global.USER_ID,
9394                                  p_LAST_UPDATE_DATE      => SYSDATE,
9395                                  p_LAST_UPDATE_LOGIN     => Fnd_Global.USER_ID);
9396 
9397         -- -------------------
9398         -- Api body ends here
9399         -- -------------------
9400         -- Standard check of p_commit.
9401         IF Fnd_Api.To_Boolean(p_commit)
9402         THEN
9403             COMMIT WORK;
9404         END IF;
9405         -- Standard call to get message count and IF count is  get message info.
9406         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9407                                   p_data  => x_msg_data);
9408     EXCEPTION
9409         WHEN Fnd_Api.G_EXC_ERROR THEN
9410             ROLLBACK TO create_task;
9411             x_return_status := Fnd_Api.G_RET_STS_ERROR;
9412             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9413                                       p_data  => x_msg_data);
9414         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
9415             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
9416             ROLLBACK TO create_task;
9417             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9418                                       p_data  => x_msg_data);
9419         WHEN OTHERS THEN
9420             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
9421             ROLLBACK TO create_task;
9422             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
9423             THEN
9424                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
9425             END IF;
9426             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9427                                       p_data  => x_msg_data);
9428 
9429     END CREATE_REPAIR_TASK;
9430 
9431     /*-----------------------------------------------------------------------------------------------------------*/
9432     /* R12 Quality Integration */
9433     /* procedure name: update_repair_task                                                                               */
9434     /* description   : procedure used to update DR specifc task in Depot tables                                                             */
9435     /* Called from   : Depot Repair Form to Update DR specifc Task                                                          */
9436     /* Input Parm    : p_api_version         NUMBER      Required Api Version number                             */
9437     /*                 p_init_msg_list       VARCHAR2    Optional Initializes message stack if fnd_api.g_true,   */
9438     /*                                                            default value is fnd_api.g_false               */
9439     /*                 p_commit              VARCHAR2    Optional Commits in API if fnd_api.g_true, default      */
9440     /*                                                            fnd_api.g_false                                */
9441     /*                 p_validation_level    NUMBER      Optional API uses this parameter to determine which     */
9442     /*                                                            validation steps must be done and which steps  */
9443     /*                                                            should be skipped.                             */
9444     /*                 CREATE_REPAIR_TASK_REC RECORD      Required Columns are in the Record CREATE_REPAIR_TASK_REC_TYPE */
9445     /* Output Parm   : x_return_status       VARCHAR2             Return status after the call. The status can be*/
9446     /*                                                            fnd_api.g_ret_sts_success (success)            */
9447     /*                                                            fnd_api.g_ret_sts_error (error)                */
9448     /*                                                            fnd_api.g_ret_sts_unexp_error (unexpected)     */
9449     /*                 x_msg_count           NUMBER               Number of messages in the message stack        */
9450     /*                 x_msg_data            VARCHAR2             Message text if x_msg_count >= 1               */
9451     /*-----------------------------------------------------------------------------------------------------------*/
9452 
9453     PROCEDURE UPDATE_REPAIR_TASK(p_api_version            IN NUMBER,
9454                                  p_init_msg_list          IN VARCHAR2 := Fnd_Api.g_false,
9455                                  p_commit                 IN VARCHAR2 := Fnd_Api.g_false,
9456                                  p_validation_level       IN NUMBER := Fnd_Api.g_valid_level_full,
9457                                  p_update_repair_task_rec IN REPAIR_TASK_REC,
9458                                  x_return_status          OUT NOCOPY VARCHAR2,
9459                                  x_msg_count              OUT NOCOPY NUMBER,
9460                                  x_msg_data               OUT NOCOPY VARCHAR2) IS
9461 
9462         l_api_name    CONSTANT VARCHAR2(30) := 'update_REPAIR_TASK';
9463         l_api_version CONSTANT NUMBER := 1.0;
9464         l_msg_count     NUMBER;
9465         l_msg_data      VARCHAR2(2000);
9466         l_msg_index     NUMBER;
9467         l_return_status VARCHAR2(1);
9468 
9469         -- Task record
9470         l_update_task_rec     Csd_Process_Pvt.REPAIR_TASK_REC := p_update_repair_task_rec;
9471         l_applicable_qa_plans VARCHAR2(1);
9472         l_dummy_char          VARCHAR2(32000);
9473         l_plan_txn_ids        VARCHAR2(5000);
9474 
9475         -- define variables to define fnd_log debug levels
9476         l_debug_level NUMBER := Fnd_Log.g_current_runtime_level;
9477         -- examples : 1- copying buffer x to y : low level detailed messages
9478         l_statement_level NUMBER := Fnd_Log.level_statement;
9479         -- examples : 2- key progress events : starting business transactions
9480         l_procedure_level NUMBER := Fnd_Log.level_procedure;
9481         -- examples : 3- event  : calling an api, key progress events
9482         l_event_level NUMBER := Fnd_Log.level_event;
9483         -- examples : 4- exception  internal software failure condition
9484         l_exception_level NUMBER := Fnd_Log.level_exception;
9485         -- examples : 5- error  end user erros
9486         l_error_level NUMBER := Fnd_Log.level_error;
9487         l_module_name VARCHAR2(240) := 'csd.plsql.csd_process_pvt.update_repair_task';
9488 
9489     BEGIN
9490         -- -----------------
9491         -- Begin update repair task
9492         -- -----------------
9493 
9494         -- Standard Start of API savepoint
9495         IF l_statement_level >= l_debug_level
9496         THEN
9497             Fnd_Log.string(l_statement_level, l_module_name, 'begin');
9498         END IF;
9499         SAVEPOINT update_repair_task;
9500 
9501         -- Standard call to check for call compatibility.
9502         IF l_statement_level >= l_debug_level
9503         THEN
9504             Fnd_Log.string(l_statement_level,
9505                            l_module_name,
9506                            'checking api compatibility');
9507         END IF;
9508         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
9509                                            p_api_version,
9510                                            l_api_name,
9511                                            G_PKG_NAME)
9512         THEN
9513             IF l_exception_level >= l_debug_level
9514             THEN
9515                 Fnd_Log.string(l_exception_level,
9516                                l_module_name,
9517                                'checking api compatibility, was unsuccessful');
9518             END IF;
9519             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
9520         END IF;
9521 
9522         IF l_statement_level >= l_debug_level
9523         THEN
9524             Fnd_Log.string(l_statement_level,
9525                            l_module_name,
9526                            'checking api compatibility, was successful');
9527         END IF;
9528 
9529         -- Initialize message list if p_init_msg_list is set to TRUE.
9530         IF Fnd_Api.to_Boolean(p_init_msg_list)
9531         THEN
9532             Fnd_Msg_Pub.initialize;
9533         END IF;
9534         -- Initialize API return status to success
9535         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
9536         -- ---------------
9537         -- Api body starts
9538         -- ---------------
9539         IF l_statement_level >= l_debug_level
9540         THEN
9541             Fnd_Log.String(l_Statement_Level,
9542                            l_Module_Name,
9543                            'Task Record Values:');
9544             Fnd_Log.String(l_Statement_Level,
9545                            l_Module_Name,
9546                            'Task Id   :' ||
9547                            p_update_repair_task_rec.task_Id);
9548             Fnd_Log.String(l_Statement_Level,
9549                            l_Module_Name,
9550                            'Repair_line_id           :' ||
9551                            p_update_repair_task_rec.repair_line_id);
9552             -- fnd_log.String(l_Statement_Level,l_Module_Name,'Applicable QA Plans              :'||  p_update_repair_task_rec.applicable_qa_plans );
9553         END IF;
9554 
9555         -- check the required parameter
9556         Csd_Process_Util.check_reqd_param(p_param_value => p_update_repair_task_rec.repair_task_Id,
9557                                           p_param_name  => 'Task Id',
9558                                           p_api_name    => l_api_name);
9559 
9560         IF l_statement_level >= l_debug_level
9561         THEN
9562             Fnd_Log.string(l_statement_level,
9563                            l_module_name || '.check_in_parameters',
9564                            'Repair Task id is valid');
9565         END IF;
9566 
9567         Csd_Process_Util.check_reqd_param(p_param_value => p_update_repair_task_rec.task_Id,
9568                                           p_param_name  => 'Task Id',
9569                                           p_api_name    => l_api_name);
9570 
9571         IF l_statement_level >= l_debug_level
9572         THEN
9573             Fnd_Log.string(l_statement_level,
9574                            l_module_name || '.check_in_parameters',
9575                            'Task id is valid');
9576         END IF;
9577 
9578         Csd_Process_Util.check_reqd_param(p_param_value => p_update_repair_task_rec.repair_line_Id,
9579                                           p_param_name  => 'Repair Line Id',
9580                                           p_api_name    => l_api_name);
9581 
9582         IF l_statement_level >= l_debug_level
9583         THEN
9584             Fnd_Log.string(l_statement_level,
9585                            l_module_name || '.check_in_parameters',
9586                            'Repair Line id is valid');
9587         END IF;
9588 
9589         -- Determine if any plans are applicable for this task.
9590         l_dummy_char := Qa_Txn_Grp.evaluate_triggers(p_txn_number     => G_DEPOT_REPAIR_TXN_NUMBER,
9591                                                      p_org_id         => p_update_repair_task_rec.org_id,
9592                                                      p_context_values => p_update_repair_task_rec.context_values,
9593                                                      x_plan_txn_ids   => l_plan_txn_ids);
9594 
9595         IF l_plan_txn_ids IS NOT NULL
9596         THEN
9597             l_applicable_qa_plans := 'Y';
9598         ELSE
9599             l_applicable_qa_plans := 'N';
9600         END IF;
9601 
9602         -- Update CSD_TASKS table
9603         Csd_Tasks_Pkg.UPDATE_ROW(px_REPAIR_TASK_ID       => p_update_repair_task_rec.repair_task_id,
9604                                  p_task_id               => p_update_repair_task_rec.task_id,
9605                                  p_OBJECT_VERSION_NUMBER => p_update_repair_task_rec.object_version_number,
9606                                  p_REPAIR_LINE_ID        => p_update_repair_task_rec.repair_line_id,
9607                                  p_APPLICABLE_QA_PLANS   => l_applicable_qa_plans,
9608                                  p_CREATED_BY            => Fnd_Global.USER_ID,
9609                                  p_CREATION_DATE         => SYSDATE,
9610                                  p_LAST_UPDATED_BY       => Fnd_Global.USER_ID,
9611                                  p_LAST_UPDATE_DATE      => SYSDATE,
9612                                  p_LAST_UPDATE_LOGIN     => Fnd_Global.USER_ID);
9613 
9614         -- -------------------
9615         -- Api body ends here
9616         -- -------------------
9617         -- Standard check of p_commit.
9618         IF Fnd_Api.To_Boolean(p_commit)
9619         THEN
9620             COMMIT WORK;
9621         END IF;
9622         -- Standard call to get message count and IF count is  get message info.
9623         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9624                                   p_data  => x_msg_data);
9625     EXCEPTION
9626         WHEN Fnd_Api.G_EXC_ERROR THEN
9627             ROLLBACK TO update_repair_task;
9628             x_return_status := Fnd_Api.G_RET_STS_ERROR;
9629             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9630                                       p_data  => x_msg_data);
9631         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
9632             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
9633             ROLLBACK TO update_repair_task;
9634             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9635                                       p_data  => x_msg_data);
9636         WHEN OTHERS THEN
9637             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
9638             ROLLBACK TO update_repair_task;
9639             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
9640             THEN
9641                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
9642             END IF;
9643             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9644                                       p_data  => x_msg_data);
9645 
9646     END UPDATE_REPAIR_TASK;
9647 
9648     FUNCTION GET_REPAIR_TASK_REC RETURN Csd_Process_Pvt.REPAIR_TASK_REC IS
9649         TMP_REPAIR_TASK_REC Csd_Process_Pvt.REPAIR_TASK_REC;
9650     BEGIN
9651         RETURN TMP_REPAIR_TASK_REC;
9652     END GET_REPAIR_TASK_REC;
9653 END Csd_Process_Pvt;